ipw2200.c 299 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306
  1. /******************************************************************************
  2. Copyright(c) 2003 - 2005 Intel Corporation. All rights reserved.
  3. 802.11 status code portion of this file from ethereal-0.10.6:
  4. Copyright 2000, Axis Communications AB
  5. Ethereal - Network traffic analyzer
  6. By Gerald Combs <gerald@ethereal.com>
  7. Copyright 1998 Gerald Combs
  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. This program is distributed in the hope that it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. more details.
  15. You should have received a copy of the GNU General Public License along with
  16. this program; if not, write to the Free Software Foundation, Inc., 59
  17. Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. The full GNU General Public License is included in this distribution in the
  19. file called LICENSE.
  20. Contact Information:
  21. James P. Ketrenos <ipw2100-admin@linux.intel.com>
  22. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  23. ******************************************************************************/
  24. #include "ipw2200.h"
  25. #define IPW2200_VERSION "1.0.5"
  26. #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2200/2915 Network Driver"
  27. #define DRV_COPYRIGHT "Copyright(c) 2003-2005 Intel Corporation"
  28. #define DRV_VERSION IPW2200_VERSION
  29. #define ETH_P_80211_STATS (ETH_P_80211_RAW + 1)
  30. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  31. MODULE_VERSION(DRV_VERSION);
  32. MODULE_AUTHOR(DRV_COPYRIGHT);
  33. MODULE_LICENSE("GPL");
  34. static int debug = 0;
  35. static int channel = 0;
  36. static int mode = 0;
  37. static u32 ipw_debug_level;
  38. static int associate = 1;
  39. static int auto_create = 1;
  40. static int led = 0;
  41. static int disable = 0;
  42. static int hwcrypto = 1;
  43. static const char ipw_modes[] = {
  44. 'a', 'b', 'g', '?'
  45. };
  46. #ifdef CONFIG_IPW_QOS
  47. static int qos_enable = 0;
  48. static int qos_burst_enable = 0;
  49. static int qos_no_ack_mask = 0;
  50. static int burst_duration_CCK = 0;
  51. static int burst_duration_OFDM = 0;
  52. static struct ieee80211_qos_parameters def_qos_parameters_OFDM = {
  53. {QOS_TX0_CW_MIN_OFDM, QOS_TX1_CW_MIN_OFDM, QOS_TX2_CW_MIN_OFDM,
  54. QOS_TX3_CW_MIN_OFDM},
  55. {QOS_TX0_CW_MAX_OFDM, QOS_TX1_CW_MAX_OFDM, QOS_TX2_CW_MAX_OFDM,
  56. QOS_TX3_CW_MAX_OFDM},
  57. {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
  58. {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
  59. {QOS_TX0_TXOP_LIMIT_OFDM, QOS_TX1_TXOP_LIMIT_OFDM,
  60. QOS_TX2_TXOP_LIMIT_OFDM, QOS_TX3_TXOP_LIMIT_OFDM}
  61. };
  62. static struct ieee80211_qos_parameters def_qos_parameters_CCK = {
  63. {QOS_TX0_CW_MIN_CCK, QOS_TX1_CW_MIN_CCK, QOS_TX2_CW_MIN_CCK,
  64. QOS_TX3_CW_MIN_CCK},
  65. {QOS_TX0_CW_MAX_CCK, QOS_TX1_CW_MAX_CCK, QOS_TX2_CW_MAX_CCK,
  66. QOS_TX3_CW_MAX_CCK},
  67. {QOS_TX0_AIFS, QOS_TX1_AIFS, QOS_TX2_AIFS, QOS_TX3_AIFS},
  68. {QOS_TX0_ACM, QOS_TX1_ACM, QOS_TX2_ACM, QOS_TX3_ACM},
  69. {QOS_TX0_TXOP_LIMIT_CCK, QOS_TX1_TXOP_LIMIT_CCK, QOS_TX2_TXOP_LIMIT_CCK,
  70. QOS_TX3_TXOP_LIMIT_CCK}
  71. };
  72. static struct ieee80211_qos_parameters def_parameters_OFDM = {
  73. {DEF_TX0_CW_MIN_OFDM, DEF_TX1_CW_MIN_OFDM, DEF_TX2_CW_MIN_OFDM,
  74. DEF_TX3_CW_MIN_OFDM},
  75. {DEF_TX0_CW_MAX_OFDM, DEF_TX1_CW_MAX_OFDM, DEF_TX2_CW_MAX_OFDM,
  76. DEF_TX3_CW_MAX_OFDM},
  77. {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
  78. {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
  79. {DEF_TX0_TXOP_LIMIT_OFDM, DEF_TX1_TXOP_LIMIT_OFDM,
  80. DEF_TX2_TXOP_LIMIT_OFDM, DEF_TX3_TXOP_LIMIT_OFDM}
  81. };
  82. static struct ieee80211_qos_parameters def_parameters_CCK = {
  83. {DEF_TX0_CW_MIN_CCK, DEF_TX1_CW_MIN_CCK, DEF_TX2_CW_MIN_CCK,
  84. DEF_TX3_CW_MIN_CCK},
  85. {DEF_TX0_CW_MAX_CCK, DEF_TX1_CW_MAX_CCK, DEF_TX2_CW_MAX_CCK,
  86. DEF_TX3_CW_MAX_CCK},
  87. {DEF_TX0_AIFS, DEF_TX1_AIFS, DEF_TX2_AIFS, DEF_TX3_AIFS},
  88. {DEF_TX0_ACM, DEF_TX1_ACM, DEF_TX2_ACM, DEF_TX3_ACM},
  89. {DEF_TX0_TXOP_LIMIT_CCK, DEF_TX1_TXOP_LIMIT_CCK, DEF_TX2_TXOP_LIMIT_CCK,
  90. DEF_TX3_TXOP_LIMIT_CCK}
  91. };
  92. static u8 qos_oui[QOS_OUI_LEN] = { 0x00, 0x50, 0xF2 };
  93. static int from_priority_to_tx_queue[] = {
  94. IPW_TX_QUEUE_1, IPW_TX_QUEUE_2, IPW_TX_QUEUE_2, IPW_TX_QUEUE_1,
  95. IPW_TX_QUEUE_3, IPW_TX_QUEUE_3, IPW_TX_QUEUE_4, IPW_TX_QUEUE_4
  96. };
  97. static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv);
  98. static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
  99. *qos_param);
  100. static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
  101. *qos_param);
  102. #endif /* CONFIG_IPW_QOS */
  103. static void ipw_remove_current_network(struct ipw_priv *priv);
  104. static void ipw_rx(struct ipw_priv *priv);
  105. static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
  106. struct clx2_tx_queue *txq, int qindex);
  107. static int ipw_queue_reset(struct ipw_priv *priv);
  108. static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
  109. int len, int sync);
  110. static void ipw_tx_queue_free(struct ipw_priv *);
  111. static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *);
  112. static void ipw_rx_queue_free(struct ipw_priv *, struct ipw_rx_queue *);
  113. static void ipw_rx_queue_replenish(void *);
  114. static int ipw_up(struct ipw_priv *);
  115. static void ipw_bg_up(void *);
  116. static void ipw_down(struct ipw_priv *);
  117. static void ipw_bg_down(void *);
  118. static int ipw_config(struct ipw_priv *);
  119. static int init_supported_rates(struct ipw_priv *priv,
  120. struct ipw_supported_rates *prates);
  121. static void ipw_set_hwcrypto_keys(struct ipw_priv *);
  122. static void ipw_send_wep_keys(struct ipw_priv *, int);
  123. static char *snprint_line(char *buf, size_t count,
  124. const u8 * data, u32 len, u32 ofs)
  125. {
  126. int out, i, j, l;
  127. char c;
  128. out = snprintf(buf, count, "%08X", ofs);
  129. for (l = 0, i = 0; i < 2; i++) {
  130. out += snprintf(buf + out, count - out, " ");
  131. for (j = 0; j < 8 && l < len; j++, l++)
  132. out += snprintf(buf + out, count - out, "%02X ",
  133. data[(i * 8 + j)]);
  134. for (; j < 8; j++)
  135. out += snprintf(buf + out, count - out, " ");
  136. }
  137. out += snprintf(buf + out, count - out, " ");
  138. for (l = 0, i = 0; i < 2; i++) {
  139. out += snprintf(buf + out, count - out, " ");
  140. for (j = 0; j < 8 && l < len; j++, l++) {
  141. c = data[(i * 8 + j)];
  142. if (!isascii(c) || !isprint(c))
  143. c = '.';
  144. out += snprintf(buf + out, count - out, "%c", c);
  145. }
  146. for (; j < 8; j++)
  147. out += snprintf(buf + out, count - out, " ");
  148. }
  149. return buf;
  150. }
  151. static void printk_buf(int level, const u8 * data, u32 len)
  152. {
  153. char line[81];
  154. u32 ofs = 0;
  155. if (!(ipw_debug_level & level))
  156. return;
  157. while (len) {
  158. printk(KERN_DEBUG "%s\n",
  159. snprint_line(line, sizeof(line), &data[ofs],
  160. min(len, 16U), ofs));
  161. ofs += 16;
  162. len -= min(len, 16U);
  163. }
  164. }
  165. static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg);
  166. #define ipw_read_reg32(a, b) _ipw_read_reg32(a, b)
  167. static u8 _ipw_read_reg8(struct ipw_priv *ipw, u32 reg);
  168. #define ipw_read_reg8(a, b) _ipw_read_reg8(a, b)
  169. static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value);
  170. static inline void ipw_write_reg8(struct ipw_priv *a, u32 b, u8 c)
  171. {
  172. IPW_DEBUG_IO("%s %d: write_indirect8(0x%08X, 0x%08X)\n", __FILE__,
  173. __LINE__, (u32) (b), (u32) (c));
  174. _ipw_write_reg8(a, b, c);
  175. }
  176. static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value);
  177. static inline void ipw_write_reg16(struct ipw_priv *a, u32 b, u16 c)
  178. {
  179. IPW_DEBUG_IO("%s %d: write_indirect16(0x%08X, 0x%08X)\n", __FILE__,
  180. __LINE__, (u32) (b), (u32) (c));
  181. _ipw_write_reg16(a, b, c);
  182. }
  183. static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value);
  184. static inline void ipw_write_reg32(struct ipw_priv *a, u32 b, u32 c)
  185. {
  186. IPW_DEBUG_IO("%s %d: write_indirect32(0x%08X, 0x%08X)\n", __FILE__,
  187. __LINE__, (u32) (b), (u32) (c));
  188. _ipw_write_reg32(a, b, c);
  189. }
  190. #define _ipw_write8(ipw, ofs, val) writeb((val), (ipw)->hw_base + (ofs))
  191. #define ipw_write8(ipw, ofs, val) \
  192. IPW_DEBUG_IO("%s %d: write_direct8(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
  193. _ipw_write8(ipw, ofs, val)
  194. #define _ipw_write16(ipw, ofs, val) writew((val), (ipw)->hw_base + (ofs))
  195. #define ipw_write16(ipw, ofs, val) \
  196. IPW_DEBUG_IO("%s %d: write_direct16(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
  197. _ipw_write16(ipw, ofs, val)
  198. #define _ipw_write32(ipw, ofs, val) writel((val), (ipw)->hw_base + (ofs))
  199. #define ipw_write32(ipw, ofs, val) \
  200. IPW_DEBUG_IO("%s %d: write_direct32(0x%08X, 0x%08X)\n", __FILE__, __LINE__, (u32)(ofs), (u32)(val)); \
  201. _ipw_write32(ipw, ofs, val)
  202. #define _ipw_read8(ipw, ofs) readb((ipw)->hw_base + (ofs))
  203. static inline u8 __ipw_read8(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
  204. {
  205. IPW_DEBUG_IO("%s %d: read_direct8(0x%08X)\n", f, l, (u32) (ofs));
  206. return _ipw_read8(ipw, ofs);
  207. }
  208. #define ipw_read8(ipw, ofs) __ipw_read8(__FILE__, __LINE__, ipw, ofs)
  209. #define _ipw_read16(ipw, ofs) readw((ipw)->hw_base + (ofs))
  210. static inline u16 __ipw_read16(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
  211. {
  212. IPW_DEBUG_IO("%s %d: read_direct16(0x%08X)\n", f, l, (u32) (ofs));
  213. return _ipw_read16(ipw, ofs);
  214. }
  215. #define ipw_read16(ipw, ofs) __ipw_read16(__FILE__, __LINE__, ipw, ofs)
  216. #define _ipw_read32(ipw, ofs) readl((ipw)->hw_base + (ofs))
  217. static inline u32 __ipw_read32(char *f, u32 l, struct ipw_priv *ipw, u32 ofs)
  218. {
  219. IPW_DEBUG_IO("%s %d: read_direct32(0x%08X)\n", f, l, (u32) (ofs));
  220. return _ipw_read32(ipw, ofs);
  221. }
  222. #define ipw_read32(ipw, ofs) __ipw_read32(__FILE__, __LINE__, ipw, ofs)
  223. static void _ipw_read_indirect(struct ipw_priv *, u32, u8 *, int);
  224. #define ipw_read_indirect(a, b, c, d) \
  225. IPW_DEBUG_IO("%s %d: read_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
  226. _ipw_read_indirect(a, b, c, d)
  227. static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * data,
  228. int num);
  229. #define ipw_write_indirect(a, b, c, d) \
  230. IPW_DEBUG_IO("%s %d: write_indirect(0x%08X) %d bytes\n", __FILE__, __LINE__, (u32)(b), d); \
  231. _ipw_write_indirect(a, b, c, d)
  232. /* indirect write s */
  233. static void _ipw_write_reg32(struct ipw_priv *priv, u32 reg, u32 value)
  234. {
  235. IPW_DEBUG_IO(" %p : reg = 0x%8X : value = 0x%8X\n", priv, reg, value);
  236. _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
  237. _ipw_write32(priv, IPW_INDIRECT_DATA, value);
  238. }
  239. static void _ipw_write_reg8(struct ipw_priv *priv, u32 reg, u8 value)
  240. {
  241. IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
  242. _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
  243. _ipw_write8(priv, IPW_INDIRECT_DATA, value);
  244. }
  245. static void _ipw_write_reg16(struct ipw_priv *priv, u32 reg, u16 value)
  246. {
  247. IPW_DEBUG_IO(" reg = 0x%8X : value = 0x%8X\n", reg, value);
  248. _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
  249. _ipw_write16(priv, IPW_INDIRECT_DATA, value);
  250. }
  251. /* indirect read s */
  252. static u8 _ipw_read_reg8(struct ipw_priv *priv, u32 reg)
  253. {
  254. u32 word;
  255. _ipw_write32(priv, IPW_INDIRECT_ADDR, reg & IPW_INDIRECT_ADDR_MASK);
  256. IPW_DEBUG_IO(" reg = 0x%8X : \n", reg);
  257. word = _ipw_read32(priv, IPW_INDIRECT_DATA);
  258. return (word >> ((reg & 0x3) * 8)) & 0xff;
  259. }
  260. static u32 _ipw_read_reg32(struct ipw_priv *priv, u32 reg)
  261. {
  262. u32 value;
  263. IPW_DEBUG_IO("%p : reg = 0x%08x\n", priv, reg);
  264. _ipw_write32(priv, IPW_INDIRECT_ADDR, reg);
  265. value = _ipw_read32(priv, IPW_INDIRECT_DATA);
  266. IPW_DEBUG_IO(" reg = 0x%4X : value = 0x%4x \n", reg, value);
  267. return value;
  268. }
  269. /* iterative/auto-increment 32 bit reads and writes */
  270. static void _ipw_read_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
  271. int num)
  272. {
  273. u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK;
  274. u32 dif_len = addr - aligned_addr;
  275. u32 i;
  276. IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
  277. if (num <= 0) {
  278. return;
  279. }
  280. /* Read the first nibble byte by byte */
  281. if (unlikely(dif_len)) {
  282. _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
  283. /* Start reading at aligned_addr + dif_len */
  284. for (i = dif_len; ((i < 4) && (num > 0)); i++, num--)
  285. *buf++ = _ipw_read8(priv, IPW_INDIRECT_DATA + i);
  286. aligned_addr += 4;
  287. }
  288. _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
  289. for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
  290. *(u32 *) buf = _ipw_read32(priv, IPW_AUTOINC_DATA);
  291. /* Copy the last nibble */
  292. if (unlikely(num)) {
  293. _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
  294. for (i = 0; num > 0; i++, num--)
  295. *buf++ = ipw_read8(priv, IPW_INDIRECT_DATA + i);
  296. }
  297. }
  298. static void _ipw_write_indirect(struct ipw_priv *priv, u32 addr, u8 * buf,
  299. int num)
  300. {
  301. u32 aligned_addr = addr & IPW_INDIRECT_ADDR_MASK;
  302. u32 dif_len = addr - aligned_addr;
  303. u32 i;
  304. IPW_DEBUG_IO("addr = %i, buf = %p, num = %i\n", addr, buf, num);
  305. if (num <= 0) {
  306. return;
  307. }
  308. /* Write the first nibble byte by byte */
  309. if (unlikely(dif_len)) {
  310. _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
  311. /* Start reading at aligned_addr + dif_len */
  312. for (i = dif_len; ((i < 4) && (num > 0)); i++, num--, buf++)
  313. _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
  314. aligned_addr += 4;
  315. }
  316. _ipw_write32(priv, IPW_AUTOINC_ADDR, aligned_addr);
  317. for (; num >= 4; buf += 4, aligned_addr += 4, num -= 4)
  318. _ipw_write32(priv, IPW_AUTOINC_DATA, *(u32 *) buf);
  319. /* Copy the last nibble */
  320. if (unlikely(num)) {
  321. _ipw_write32(priv, IPW_INDIRECT_ADDR, aligned_addr);
  322. for (i = 0; num > 0; i++, num--, buf++)
  323. _ipw_write8(priv, IPW_INDIRECT_DATA + i, *buf);
  324. }
  325. }
  326. static void ipw_write_direct(struct ipw_priv *priv, u32 addr, void *buf,
  327. int num)
  328. {
  329. memcpy_toio((priv->hw_base + addr), buf, num);
  330. }
  331. static inline void ipw_set_bit(struct ipw_priv *priv, u32 reg, u32 mask)
  332. {
  333. ipw_write32(priv, reg, ipw_read32(priv, reg) | mask);
  334. }
  335. static inline void ipw_clear_bit(struct ipw_priv *priv, u32 reg, u32 mask)
  336. {
  337. ipw_write32(priv, reg, ipw_read32(priv, reg) & ~mask);
  338. }
  339. static inline void ipw_enable_interrupts(struct ipw_priv *priv)
  340. {
  341. if (priv->status & STATUS_INT_ENABLED)
  342. return;
  343. priv->status |= STATUS_INT_ENABLED;
  344. ipw_write32(priv, IPW_INTA_MASK_R, IPW_INTA_MASK_ALL);
  345. }
  346. static inline void ipw_disable_interrupts(struct ipw_priv *priv)
  347. {
  348. if (!(priv->status & STATUS_INT_ENABLED))
  349. return;
  350. priv->status &= ~STATUS_INT_ENABLED;
  351. ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
  352. }
  353. #ifdef CONFIG_IPW_DEBUG
  354. static char *ipw_error_desc(u32 val)
  355. {
  356. switch (val) {
  357. case IPW_FW_ERROR_OK:
  358. return "ERROR_OK";
  359. case IPW_FW_ERROR_FAIL:
  360. return "ERROR_FAIL";
  361. case IPW_FW_ERROR_MEMORY_UNDERFLOW:
  362. return "MEMORY_UNDERFLOW";
  363. case IPW_FW_ERROR_MEMORY_OVERFLOW:
  364. return "MEMORY_OVERFLOW";
  365. case IPW_FW_ERROR_BAD_PARAM:
  366. return "BAD_PARAM";
  367. case IPW_FW_ERROR_BAD_CHECKSUM:
  368. return "BAD_CHECKSUM";
  369. case IPW_FW_ERROR_NMI_INTERRUPT:
  370. return "NMI_INTERRUPT";
  371. case IPW_FW_ERROR_BAD_DATABASE:
  372. return "BAD_DATABASE";
  373. case IPW_FW_ERROR_ALLOC_FAIL:
  374. return "ALLOC_FAIL";
  375. case IPW_FW_ERROR_DMA_UNDERRUN:
  376. return "DMA_UNDERRUN";
  377. case IPW_FW_ERROR_DMA_STATUS:
  378. return "DMA_STATUS";
  379. case IPW_FW_ERROR_DINO_ERROR:
  380. return "DINO_ERROR";
  381. case IPW_FW_ERROR_EEPROM_ERROR:
  382. return "EEPROM_ERROR";
  383. case IPW_FW_ERROR_SYSASSERT:
  384. return "SYSASSERT";
  385. case IPW_FW_ERROR_FATAL_ERROR:
  386. return "FATAL_ERROR";
  387. default:
  388. return "UNKNOWN_ERROR";
  389. }
  390. }
  391. static void ipw_dump_error_log(struct ipw_priv *priv,
  392. struct ipw_fw_error *error)
  393. {
  394. u32 i;
  395. if (!error) {
  396. IPW_ERROR("Error allocating and capturing error log. "
  397. "Nothing to dump.\n");
  398. return;
  399. }
  400. IPW_ERROR("Start IPW Error Log Dump:\n");
  401. IPW_ERROR("Status: 0x%08X, Config: %08X\n",
  402. error->status, error->config);
  403. for (i = 0; i < error->elem_len; i++)
  404. IPW_ERROR("%s %i 0x%08x 0x%08x 0x%08x 0x%08x 0x%08x\n",
  405. ipw_error_desc(error->elem[i].desc),
  406. error->elem[i].time,
  407. error->elem[i].blink1,
  408. error->elem[i].blink2,
  409. error->elem[i].link1,
  410. error->elem[i].link2, error->elem[i].data);
  411. for (i = 0; i < error->log_len; i++)
  412. IPW_ERROR("%i\t0x%08x\t%i\n",
  413. error->log[i].time,
  414. error->log[i].event, error->log[i].data);
  415. }
  416. #endif
  417. static inline int ipw_is_init(struct ipw_priv *priv)
  418. {
  419. return (priv->status & STATUS_INIT) ? 1 : 0;
  420. }
  421. static int ipw_get_ordinal(struct ipw_priv *priv, u32 ord, void *val, u32 * len)
  422. {
  423. u32 addr, field_info, field_len, field_count, total_len;
  424. IPW_DEBUG_ORD("ordinal = %i\n", ord);
  425. if (!priv || !val || !len) {
  426. IPW_DEBUG_ORD("Invalid argument\n");
  427. return -EINVAL;
  428. }
  429. /* verify device ordinal tables have been initialized */
  430. if (!priv->table0_addr || !priv->table1_addr || !priv->table2_addr) {
  431. IPW_DEBUG_ORD("Access ordinals before initialization\n");
  432. return -EINVAL;
  433. }
  434. switch (IPW_ORD_TABLE_ID_MASK & ord) {
  435. case IPW_ORD_TABLE_0_MASK:
  436. /*
  437. * TABLE 0: Direct access to a table of 32 bit values
  438. *
  439. * This is a very simple table with the data directly
  440. * read from the table
  441. */
  442. /* remove the table id from the ordinal */
  443. ord &= IPW_ORD_TABLE_VALUE_MASK;
  444. /* boundary check */
  445. if (ord > priv->table0_len) {
  446. IPW_DEBUG_ORD("ordinal value (%i) longer then "
  447. "max (%i)\n", ord, priv->table0_len);
  448. return -EINVAL;
  449. }
  450. /* verify we have enough room to store the value */
  451. if (*len < sizeof(u32)) {
  452. IPW_DEBUG_ORD("ordinal buffer length too small, "
  453. "need %zd\n", sizeof(u32));
  454. return -EINVAL;
  455. }
  456. IPW_DEBUG_ORD("Reading TABLE0[%i] from offset 0x%08x\n",
  457. ord, priv->table0_addr + (ord << 2));
  458. *len = sizeof(u32);
  459. ord <<= 2;
  460. *((u32 *) val) = ipw_read32(priv, priv->table0_addr + ord);
  461. break;
  462. case IPW_ORD_TABLE_1_MASK:
  463. /*
  464. * TABLE 1: Indirect access to a table of 32 bit values
  465. *
  466. * This is a fairly large table of u32 values each
  467. * representing starting addr for the data (which is
  468. * also a u32)
  469. */
  470. /* remove the table id from the ordinal */
  471. ord &= IPW_ORD_TABLE_VALUE_MASK;
  472. /* boundary check */
  473. if (ord > priv->table1_len) {
  474. IPW_DEBUG_ORD("ordinal value too long\n");
  475. return -EINVAL;
  476. }
  477. /* verify we have enough room to store the value */
  478. if (*len < sizeof(u32)) {
  479. IPW_DEBUG_ORD("ordinal buffer length too small, "
  480. "need %zd\n", sizeof(u32));
  481. return -EINVAL;
  482. }
  483. *((u32 *) val) =
  484. ipw_read_reg32(priv, (priv->table1_addr + (ord << 2)));
  485. *len = sizeof(u32);
  486. break;
  487. case IPW_ORD_TABLE_2_MASK:
  488. /*
  489. * TABLE 2: Indirect access to a table of variable sized values
  490. *
  491. * This table consist of six values, each containing
  492. * - dword containing the starting offset of the data
  493. * - dword containing the lengh in the first 16bits
  494. * and the count in the second 16bits
  495. */
  496. /* remove the table id from the ordinal */
  497. ord &= IPW_ORD_TABLE_VALUE_MASK;
  498. /* boundary check */
  499. if (ord > priv->table2_len) {
  500. IPW_DEBUG_ORD("ordinal value too long\n");
  501. return -EINVAL;
  502. }
  503. /* get the address of statistic */
  504. addr = ipw_read_reg32(priv, priv->table2_addr + (ord << 3));
  505. /* get the second DW of statistics ;
  506. * two 16-bit words - first is length, second is count */
  507. field_info =
  508. ipw_read_reg32(priv,
  509. priv->table2_addr + (ord << 3) +
  510. sizeof(u32));
  511. /* get each entry length */
  512. field_len = *((u16 *) & field_info);
  513. /* get number of entries */
  514. field_count = *(((u16 *) & field_info) + 1);
  515. /* abort if not enought memory */
  516. total_len = field_len * field_count;
  517. if (total_len > *len) {
  518. *len = total_len;
  519. return -EINVAL;
  520. }
  521. *len = total_len;
  522. if (!total_len)
  523. return 0;
  524. IPW_DEBUG_ORD("addr = 0x%08x, total_len = %i, "
  525. "field_info = 0x%08x\n",
  526. addr, total_len, field_info);
  527. ipw_read_indirect(priv, addr, val, total_len);
  528. break;
  529. default:
  530. IPW_DEBUG_ORD("Invalid ordinal!\n");
  531. return -EINVAL;
  532. }
  533. return 0;
  534. }
  535. static void ipw_init_ordinals(struct ipw_priv *priv)
  536. {
  537. priv->table0_addr = IPW_ORDINALS_TABLE_LOWER;
  538. priv->table0_len = ipw_read32(priv, priv->table0_addr);
  539. IPW_DEBUG_ORD("table 0 offset at 0x%08x, len = %i\n",
  540. priv->table0_addr, priv->table0_len);
  541. priv->table1_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_1);
  542. priv->table1_len = ipw_read_reg32(priv, priv->table1_addr);
  543. IPW_DEBUG_ORD("table 1 offset at 0x%08x, len = %i\n",
  544. priv->table1_addr, priv->table1_len);
  545. priv->table2_addr = ipw_read32(priv, IPW_ORDINALS_TABLE_2);
  546. priv->table2_len = ipw_read_reg32(priv, priv->table2_addr);
  547. priv->table2_len &= 0x0000ffff; /* use first two bytes */
  548. IPW_DEBUG_ORD("table 2 offset at 0x%08x, len = %i\n",
  549. priv->table2_addr, priv->table2_len);
  550. }
  551. u32 ipw_register_toggle(u32 reg)
  552. {
  553. reg &= ~IPW_START_STANDBY;
  554. if (reg & IPW_GATE_ODMA)
  555. reg &= ~IPW_GATE_ODMA;
  556. if (reg & IPW_GATE_IDMA)
  557. reg &= ~IPW_GATE_IDMA;
  558. if (reg & IPW_GATE_ADMA)
  559. reg &= ~IPW_GATE_ADMA;
  560. return reg;
  561. }
  562. /*
  563. * LED behavior:
  564. * - On radio ON, turn on any LEDs that require to be on during start
  565. * - On initialization, start unassociated blink
  566. * - On association, disable unassociated blink
  567. * - On disassociation, start unassociated blink
  568. * - On radio OFF, turn off any LEDs started during radio on
  569. *
  570. */
  571. #define LD_TIME_LINK_ON 300
  572. #define LD_TIME_LINK_OFF 2700
  573. #define LD_TIME_ACT_ON 250
  574. void ipw_led_link_on(struct ipw_priv *priv)
  575. {
  576. unsigned long flags;
  577. u32 led;
  578. /* If configured to not use LEDs, or nic_type is 1,
  579. * then we don't toggle a LINK led */
  580. if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
  581. return;
  582. spin_lock_irqsave(&priv->lock, flags);
  583. if (!(priv->status & STATUS_RF_KILL_MASK) &&
  584. !(priv->status & STATUS_LED_LINK_ON)) {
  585. IPW_DEBUG_LED("Link LED On\n");
  586. led = ipw_read_reg32(priv, IPW_EVENT_REG);
  587. led |= priv->led_association_on;
  588. led = ipw_register_toggle(led);
  589. IPW_DEBUG_LED("Reg: 0x%08X\n", led);
  590. ipw_write_reg32(priv, IPW_EVENT_REG, led);
  591. priv->status |= STATUS_LED_LINK_ON;
  592. /* If we aren't associated, schedule turning the LED off */
  593. if (!(priv->status & STATUS_ASSOCIATED))
  594. queue_delayed_work(priv->workqueue,
  595. &priv->led_link_off,
  596. LD_TIME_LINK_ON);
  597. }
  598. spin_unlock_irqrestore(&priv->lock, flags);
  599. }
  600. static void ipw_bg_led_link_on(void *data)
  601. {
  602. struct ipw_priv *priv = data;
  603. down(&priv->sem);
  604. ipw_led_link_on(data);
  605. up(&priv->sem);
  606. }
  607. void ipw_led_link_off(struct ipw_priv *priv)
  608. {
  609. unsigned long flags;
  610. u32 led;
  611. /* If configured not to use LEDs, or nic type is 1,
  612. * then we don't goggle the LINK led. */
  613. if (priv->config & CFG_NO_LED || priv->nic_type == EEPROM_NIC_TYPE_1)
  614. return;
  615. spin_lock_irqsave(&priv->lock, flags);
  616. if (priv->status & STATUS_LED_LINK_ON) {
  617. led = ipw_read_reg32(priv, IPW_EVENT_REG);
  618. led &= priv->led_association_off;
  619. led = ipw_register_toggle(led);
  620. IPW_DEBUG_LED("Reg: 0x%08X\n", led);
  621. ipw_write_reg32(priv, IPW_EVENT_REG, led);
  622. IPW_DEBUG_LED("Link LED Off\n");
  623. priv->status &= ~STATUS_LED_LINK_ON;
  624. /* If we aren't associated and the radio is on, schedule
  625. * turning the LED on (blink while unassociated) */
  626. if (!(priv->status & STATUS_RF_KILL_MASK) &&
  627. !(priv->status & STATUS_ASSOCIATED))
  628. queue_delayed_work(priv->workqueue, &priv->led_link_on,
  629. LD_TIME_LINK_OFF);
  630. }
  631. spin_unlock_irqrestore(&priv->lock, flags);
  632. }
  633. static void ipw_bg_led_link_off(void *data)
  634. {
  635. struct ipw_priv *priv = data;
  636. down(&priv->sem);
  637. ipw_led_link_off(data);
  638. up(&priv->sem);
  639. }
  640. static inline void __ipw_led_activity_on(struct ipw_priv *priv)
  641. {
  642. u32 led;
  643. if (priv->config & CFG_NO_LED)
  644. return;
  645. if (priv->status & STATUS_RF_KILL_MASK)
  646. return;
  647. if (!(priv->status & STATUS_LED_ACT_ON)) {
  648. led = ipw_read_reg32(priv, IPW_EVENT_REG);
  649. led |= priv->led_activity_on;
  650. led = ipw_register_toggle(led);
  651. IPW_DEBUG_LED("Reg: 0x%08X\n", led);
  652. ipw_write_reg32(priv, IPW_EVENT_REG, led);
  653. IPW_DEBUG_LED("Activity LED On\n");
  654. priv->status |= STATUS_LED_ACT_ON;
  655. cancel_delayed_work(&priv->led_act_off);
  656. queue_delayed_work(priv->workqueue, &priv->led_act_off,
  657. LD_TIME_ACT_ON);
  658. } else {
  659. /* Reschedule LED off for full time period */
  660. cancel_delayed_work(&priv->led_act_off);
  661. queue_delayed_work(priv->workqueue, &priv->led_act_off,
  662. LD_TIME_ACT_ON);
  663. }
  664. }
  665. void ipw_led_activity_on(struct ipw_priv *priv)
  666. {
  667. unsigned long flags;
  668. spin_lock_irqsave(&priv->lock, flags);
  669. __ipw_led_activity_on(priv);
  670. spin_unlock_irqrestore(&priv->lock, flags);
  671. }
  672. void ipw_led_activity_off(struct ipw_priv *priv)
  673. {
  674. unsigned long flags;
  675. u32 led;
  676. if (priv->config & CFG_NO_LED)
  677. return;
  678. spin_lock_irqsave(&priv->lock, flags);
  679. if (priv->status & STATUS_LED_ACT_ON) {
  680. led = ipw_read_reg32(priv, IPW_EVENT_REG);
  681. led &= priv->led_activity_off;
  682. led = ipw_register_toggle(led);
  683. IPW_DEBUG_LED("Reg: 0x%08X\n", led);
  684. ipw_write_reg32(priv, IPW_EVENT_REG, led);
  685. IPW_DEBUG_LED("Activity LED Off\n");
  686. priv->status &= ~STATUS_LED_ACT_ON;
  687. }
  688. spin_unlock_irqrestore(&priv->lock, flags);
  689. }
  690. static void ipw_bg_led_activity_off(void *data)
  691. {
  692. struct ipw_priv *priv = data;
  693. down(&priv->sem);
  694. ipw_led_activity_off(data);
  695. up(&priv->sem);
  696. }
  697. void ipw_led_band_on(struct ipw_priv *priv)
  698. {
  699. unsigned long flags;
  700. u32 led;
  701. /* Only nic type 1 supports mode LEDs */
  702. if (priv->config & CFG_NO_LED ||
  703. priv->nic_type != EEPROM_NIC_TYPE_1 || !priv->assoc_network)
  704. return;
  705. spin_lock_irqsave(&priv->lock, flags);
  706. led = ipw_read_reg32(priv, IPW_EVENT_REG);
  707. if (priv->assoc_network->mode == IEEE_A) {
  708. led |= priv->led_ofdm_on;
  709. led &= priv->led_association_off;
  710. IPW_DEBUG_LED("Mode LED On: 802.11a\n");
  711. } else if (priv->assoc_network->mode == IEEE_G) {
  712. led |= priv->led_ofdm_on;
  713. led |= priv->led_association_on;
  714. IPW_DEBUG_LED("Mode LED On: 802.11g\n");
  715. } else {
  716. led &= priv->led_ofdm_off;
  717. led |= priv->led_association_on;
  718. IPW_DEBUG_LED("Mode LED On: 802.11b\n");
  719. }
  720. led = ipw_register_toggle(led);
  721. IPW_DEBUG_LED("Reg: 0x%08X\n", led);
  722. ipw_write_reg32(priv, IPW_EVENT_REG, led);
  723. spin_unlock_irqrestore(&priv->lock, flags);
  724. }
  725. void ipw_led_band_off(struct ipw_priv *priv)
  726. {
  727. unsigned long flags;
  728. u32 led;
  729. /* Only nic type 1 supports mode LEDs */
  730. if (priv->config & CFG_NO_LED || priv->nic_type != EEPROM_NIC_TYPE_1)
  731. return;
  732. spin_lock_irqsave(&priv->lock, flags);
  733. led = ipw_read_reg32(priv, IPW_EVENT_REG);
  734. led &= priv->led_ofdm_off;
  735. led &= priv->led_association_off;
  736. led = ipw_register_toggle(led);
  737. IPW_DEBUG_LED("Reg: 0x%08X\n", led);
  738. ipw_write_reg32(priv, IPW_EVENT_REG, led);
  739. spin_unlock_irqrestore(&priv->lock, flags);
  740. }
  741. void ipw_led_radio_on(struct ipw_priv *priv)
  742. {
  743. ipw_led_link_on(priv);
  744. }
  745. void ipw_led_radio_off(struct ipw_priv *priv)
  746. {
  747. ipw_led_activity_off(priv);
  748. ipw_led_link_off(priv);
  749. }
  750. void ipw_led_link_up(struct ipw_priv *priv)
  751. {
  752. /* Set the Link Led on for all nic types */
  753. ipw_led_link_on(priv);
  754. }
  755. void ipw_led_link_down(struct ipw_priv *priv)
  756. {
  757. ipw_led_activity_off(priv);
  758. ipw_led_link_off(priv);
  759. if (priv->status & STATUS_RF_KILL_MASK)
  760. ipw_led_radio_off(priv);
  761. }
  762. void ipw_led_init(struct ipw_priv *priv)
  763. {
  764. priv->nic_type = priv->eeprom[EEPROM_NIC_TYPE];
  765. /* Set the default PINs for the link and activity leds */
  766. priv->led_activity_on = IPW_ACTIVITY_LED;
  767. priv->led_activity_off = ~(IPW_ACTIVITY_LED);
  768. priv->led_association_on = IPW_ASSOCIATED_LED;
  769. priv->led_association_off = ~(IPW_ASSOCIATED_LED);
  770. /* Set the default PINs for the OFDM leds */
  771. priv->led_ofdm_on = IPW_OFDM_LED;
  772. priv->led_ofdm_off = ~(IPW_OFDM_LED);
  773. switch (priv->nic_type) {
  774. case EEPROM_NIC_TYPE_1:
  775. /* In this NIC type, the LEDs are reversed.... */
  776. priv->led_activity_on = IPW_ASSOCIATED_LED;
  777. priv->led_activity_off = ~(IPW_ASSOCIATED_LED);
  778. priv->led_association_on = IPW_ACTIVITY_LED;
  779. priv->led_association_off = ~(IPW_ACTIVITY_LED);
  780. if (!(priv->config & CFG_NO_LED))
  781. ipw_led_band_on(priv);
  782. /* And we don't blink link LEDs for this nic, so
  783. * just return here */
  784. return;
  785. case EEPROM_NIC_TYPE_3:
  786. case EEPROM_NIC_TYPE_2:
  787. case EEPROM_NIC_TYPE_4:
  788. case EEPROM_NIC_TYPE_0:
  789. break;
  790. default:
  791. IPW_DEBUG_INFO("Unknown NIC type from EEPROM: %d\n",
  792. priv->nic_type);
  793. priv->nic_type = EEPROM_NIC_TYPE_0;
  794. break;
  795. }
  796. if (!(priv->config & CFG_NO_LED)) {
  797. if (priv->status & STATUS_ASSOCIATED)
  798. ipw_led_link_on(priv);
  799. else
  800. ipw_led_link_off(priv);
  801. }
  802. }
  803. void ipw_led_shutdown(struct ipw_priv *priv)
  804. {
  805. ipw_led_activity_off(priv);
  806. ipw_led_link_off(priv);
  807. ipw_led_band_off(priv);
  808. cancel_delayed_work(&priv->led_link_on);
  809. cancel_delayed_work(&priv->led_link_off);
  810. cancel_delayed_work(&priv->led_act_off);
  811. }
  812. /*
  813. * The following adds a new attribute to the sysfs representation
  814. * of this device driver (i.e. a new file in /sys/bus/pci/drivers/ipw/)
  815. * used for controling the debug level.
  816. *
  817. * See the level definitions in ipw for details.
  818. */
  819. static ssize_t show_debug_level(struct device_driver *d, char *buf)
  820. {
  821. return sprintf(buf, "0x%08X\n", ipw_debug_level);
  822. }
  823. static ssize_t store_debug_level(struct device_driver *d, const char *buf,
  824. size_t count)
  825. {
  826. char *p = (char *)buf;
  827. u32 val;
  828. if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
  829. p++;
  830. if (p[0] == 'x' || p[0] == 'X')
  831. p++;
  832. val = simple_strtoul(p, &p, 16);
  833. } else
  834. val = simple_strtoul(p, &p, 10);
  835. if (p == buf)
  836. printk(KERN_INFO DRV_NAME
  837. ": %s is not in hex or decimal form.\n", buf);
  838. else
  839. ipw_debug_level = val;
  840. return strnlen(buf, count);
  841. }
  842. static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO,
  843. show_debug_level, store_debug_level);
  844. static inline u32 ipw_get_event_log_len(struct ipw_priv *priv)
  845. {
  846. return ipw_read_reg32(priv, ipw_read32(priv, IPW_EVENT_LOG));
  847. }
  848. static void ipw_capture_event_log(struct ipw_priv *priv,
  849. u32 log_len, struct ipw_event *log)
  850. {
  851. u32 base;
  852. if (log_len) {
  853. base = ipw_read32(priv, IPW_EVENT_LOG);
  854. ipw_read_indirect(priv, base + sizeof(base) + sizeof(u32),
  855. (u8 *) log, sizeof(*log) * log_len);
  856. }
  857. }
  858. static struct ipw_fw_error *ipw_alloc_error_log(struct ipw_priv *priv)
  859. {
  860. struct ipw_fw_error *error;
  861. u32 log_len = ipw_get_event_log_len(priv);
  862. u32 base = ipw_read32(priv, IPW_ERROR_LOG);
  863. u32 elem_len = ipw_read_reg32(priv, base);
  864. error = kmalloc(sizeof(*error) +
  865. sizeof(*error->elem) * elem_len +
  866. sizeof(*error->log) * log_len, GFP_ATOMIC);
  867. if (!error) {
  868. IPW_ERROR("Memory allocation for firmware error log "
  869. "failed.\n");
  870. return NULL;
  871. }
  872. error->status = priv->status;
  873. error->config = priv->config;
  874. error->elem_len = elem_len;
  875. error->log_len = log_len;
  876. error->elem = (struct ipw_error_elem *)error->payload;
  877. error->log = (struct ipw_event *)(error->elem +
  878. (sizeof(*error->elem) * elem_len));
  879. ipw_capture_event_log(priv, log_len, error->log);
  880. if (elem_len)
  881. ipw_read_indirect(priv, base + sizeof(base), (u8 *) error->elem,
  882. sizeof(*error->elem) * elem_len);
  883. return error;
  884. }
  885. static void ipw_free_error_log(struct ipw_fw_error *error)
  886. {
  887. if (error)
  888. kfree(error);
  889. }
  890. static ssize_t show_event_log(struct device *d,
  891. struct device_attribute *attr, char *buf)
  892. {
  893. struct ipw_priv *priv = dev_get_drvdata(d);
  894. u32 log_len = ipw_get_event_log_len(priv);
  895. struct ipw_event log[log_len];
  896. u32 len = 0, i;
  897. ipw_capture_event_log(priv, log_len, log);
  898. len += snprintf(buf + len, PAGE_SIZE - len, "%08X", log_len);
  899. for (i = 0; i < log_len; i++)
  900. len += snprintf(buf + len, PAGE_SIZE - len,
  901. "\n%08X%08X%08X",
  902. log[i].time, log[i].event, log[i].data);
  903. len += snprintf(buf + len, PAGE_SIZE - len, "\n");
  904. return len;
  905. }
  906. static DEVICE_ATTR(event_log, S_IRUGO, show_event_log, NULL);
  907. static ssize_t show_error(struct device *d,
  908. struct device_attribute *attr, char *buf)
  909. {
  910. struct ipw_priv *priv = dev_get_drvdata(d);
  911. u32 len = 0, i;
  912. if (!priv->error)
  913. return 0;
  914. len += snprintf(buf + len, PAGE_SIZE - len,
  915. "%08X%08X%08X",
  916. priv->error->status,
  917. priv->error->config, priv->error->elem_len);
  918. for (i = 0; i < priv->error->elem_len; i++)
  919. len += snprintf(buf + len, PAGE_SIZE - len,
  920. "\n%08X%08X%08X%08X%08X%08X%08X",
  921. priv->error->elem[i].time,
  922. priv->error->elem[i].desc,
  923. priv->error->elem[i].blink1,
  924. priv->error->elem[i].blink2,
  925. priv->error->elem[i].link1,
  926. priv->error->elem[i].link2,
  927. priv->error->elem[i].data);
  928. len += snprintf(buf + len, PAGE_SIZE - len,
  929. "\n%08X", priv->error->log_len);
  930. for (i = 0; i < priv->error->log_len; i++)
  931. len += snprintf(buf + len, PAGE_SIZE - len,
  932. "\n%08X%08X%08X",
  933. priv->error->log[i].time,
  934. priv->error->log[i].event,
  935. priv->error->log[i].data);
  936. len += snprintf(buf + len, PAGE_SIZE - len, "\n");
  937. return len;
  938. }
  939. static ssize_t clear_error(struct device *d,
  940. struct device_attribute *attr,
  941. const char *buf, size_t count)
  942. {
  943. struct ipw_priv *priv = dev_get_drvdata(d);
  944. if (priv->error) {
  945. ipw_free_error_log(priv->error);
  946. priv->error = NULL;
  947. }
  948. return count;
  949. }
  950. static DEVICE_ATTR(error, S_IRUGO | S_IWUSR, show_error, clear_error);
  951. static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
  952. char *buf)
  953. {
  954. struct ipw_priv *priv = dev_get_drvdata(d);
  955. return sprintf(buf, "%d\n", priv->ieee->scan_age);
  956. }
  957. static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
  958. const char *buf, size_t count)
  959. {
  960. struct ipw_priv *priv = dev_get_drvdata(d);
  961. #ifdef CONFIG_IPW_DEBUG
  962. struct net_device *dev = priv->net_dev;
  963. #endif
  964. char buffer[] = "00000000";
  965. unsigned long len =
  966. (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
  967. unsigned long val;
  968. char *p = buffer;
  969. IPW_DEBUG_INFO("enter\n");
  970. strncpy(buffer, buf, len);
  971. buffer[len] = 0;
  972. if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
  973. p++;
  974. if (p[0] == 'x' || p[0] == 'X')
  975. p++;
  976. val = simple_strtoul(p, &p, 16);
  977. } else
  978. val = simple_strtoul(p, &p, 10);
  979. if (p == buffer) {
  980. IPW_DEBUG_INFO("%s: user supplied invalid value.\n", dev->name);
  981. } else {
  982. priv->ieee->scan_age = val;
  983. IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
  984. }
  985. IPW_DEBUG_INFO("exit\n");
  986. return len;
  987. }
  988. static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
  989. static ssize_t show_led(struct device *d, struct device_attribute *attr,
  990. char *buf)
  991. {
  992. struct ipw_priv *priv = dev_get_drvdata(d);
  993. return sprintf(buf, "%d\n", (priv->config & CFG_NO_LED) ? 0 : 1);
  994. }
  995. static ssize_t store_led(struct device *d, struct device_attribute *attr,
  996. const char *buf, size_t count)
  997. {
  998. struct ipw_priv *priv = dev_get_drvdata(d);
  999. IPW_DEBUG_INFO("enter\n");
  1000. if (count == 0)
  1001. return 0;
  1002. if (*buf == 0) {
  1003. IPW_DEBUG_LED("Disabling LED control.\n");
  1004. priv->config |= CFG_NO_LED;
  1005. ipw_led_shutdown(priv);
  1006. } else {
  1007. IPW_DEBUG_LED("Enabling LED control.\n");
  1008. priv->config &= ~CFG_NO_LED;
  1009. ipw_led_init(priv);
  1010. }
  1011. IPW_DEBUG_INFO("exit\n");
  1012. return count;
  1013. }
  1014. static DEVICE_ATTR(led, S_IWUSR | S_IRUGO, show_led, store_led);
  1015. static ssize_t show_status(struct device *d,
  1016. struct device_attribute *attr, char *buf)
  1017. {
  1018. struct ipw_priv *p = d->driver_data;
  1019. return sprintf(buf, "0x%08x\n", (int)p->status);
  1020. }
  1021. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  1022. static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
  1023. char *buf)
  1024. {
  1025. struct ipw_priv *p = d->driver_data;
  1026. return sprintf(buf, "0x%08x\n", (int)p->config);
  1027. }
  1028. static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
  1029. static ssize_t show_nic_type(struct device *d,
  1030. struct device_attribute *attr, char *buf)
  1031. {
  1032. struct ipw_priv *priv = d->driver_data;
  1033. return sprintf(buf, "TYPE: %d\n", priv->nic_type);
  1034. }
  1035. static DEVICE_ATTR(nic_type, S_IRUGO, show_nic_type, NULL);
  1036. static ssize_t show_ucode_version(struct device *d,
  1037. struct device_attribute *attr, char *buf)
  1038. {
  1039. u32 len = sizeof(u32), tmp = 0;
  1040. struct ipw_priv *p = d->driver_data;
  1041. if (ipw_get_ordinal(p, IPW_ORD_STAT_UCODE_VERSION, &tmp, &len))
  1042. return 0;
  1043. return sprintf(buf, "0x%08x\n", tmp);
  1044. }
  1045. static DEVICE_ATTR(ucode_version, S_IWUSR | S_IRUGO, show_ucode_version, NULL);
  1046. static ssize_t show_rtc(struct device *d, struct device_attribute *attr,
  1047. char *buf)
  1048. {
  1049. u32 len = sizeof(u32), tmp = 0;
  1050. struct ipw_priv *p = d->driver_data;
  1051. if (ipw_get_ordinal(p, IPW_ORD_STAT_RTC, &tmp, &len))
  1052. return 0;
  1053. return sprintf(buf, "0x%08x\n", tmp);
  1054. }
  1055. static DEVICE_ATTR(rtc, S_IWUSR | S_IRUGO, show_rtc, NULL);
  1056. /*
  1057. * Add a device attribute to view/control the delay between eeprom
  1058. * operations.
  1059. */
  1060. static ssize_t show_eeprom_delay(struct device *d,
  1061. struct device_attribute *attr, char *buf)
  1062. {
  1063. int n = ((struct ipw_priv *)d->driver_data)->eeprom_delay;
  1064. return sprintf(buf, "%i\n", n);
  1065. }
  1066. static ssize_t store_eeprom_delay(struct device *d,
  1067. struct device_attribute *attr,
  1068. const char *buf, size_t count)
  1069. {
  1070. struct ipw_priv *p = d->driver_data;
  1071. sscanf(buf, "%i", &p->eeprom_delay);
  1072. return strnlen(buf, count);
  1073. }
  1074. static DEVICE_ATTR(eeprom_delay, S_IWUSR | S_IRUGO,
  1075. show_eeprom_delay, store_eeprom_delay);
  1076. static ssize_t show_command_event_reg(struct device *d,
  1077. struct device_attribute *attr, char *buf)
  1078. {
  1079. u32 reg = 0;
  1080. struct ipw_priv *p = d->driver_data;
  1081. reg = ipw_read_reg32(p, IPW_INTERNAL_CMD_EVENT);
  1082. return sprintf(buf, "0x%08x\n", reg);
  1083. }
  1084. static ssize_t store_command_event_reg(struct device *d,
  1085. struct device_attribute *attr,
  1086. const char *buf, size_t count)
  1087. {
  1088. u32 reg;
  1089. struct ipw_priv *p = d->driver_data;
  1090. sscanf(buf, "%x", &reg);
  1091. ipw_write_reg32(p, IPW_INTERNAL_CMD_EVENT, reg);
  1092. return strnlen(buf, count);
  1093. }
  1094. static DEVICE_ATTR(command_event_reg, S_IWUSR | S_IRUGO,
  1095. show_command_event_reg, store_command_event_reg);
  1096. static ssize_t show_mem_gpio_reg(struct device *d,
  1097. struct device_attribute *attr, char *buf)
  1098. {
  1099. u32 reg = 0;
  1100. struct ipw_priv *p = d->driver_data;
  1101. reg = ipw_read_reg32(p, 0x301100);
  1102. return sprintf(buf, "0x%08x\n", reg);
  1103. }
  1104. static ssize_t store_mem_gpio_reg(struct device *d,
  1105. struct device_attribute *attr,
  1106. const char *buf, size_t count)
  1107. {
  1108. u32 reg;
  1109. struct ipw_priv *p = d->driver_data;
  1110. sscanf(buf, "%x", &reg);
  1111. ipw_write_reg32(p, 0x301100, reg);
  1112. return strnlen(buf, count);
  1113. }
  1114. static DEVICE_ATTR(mem_gpio_reg, S_IWUSR | S_IRUGO,
  1115. show_mem_gpio_reg, store_mem_gpio_reg);
  1116. static ssize_t show_indirect_dword(struct device *d,
  1117. struct device_attribute *attr, char *buf)
  1118. {
  1119. u32 reg = 0;
  1120. struct ipw_priv *priv = d->driver_data;
  1121. if (priv->status & STATUS_INDIRECT_DWORD)
  1122. reg = ipw_read_reg32(priv, priv->indirect_dword);
  1123. else
  1124. reg = 0;
  1125. return sprintf(buf, "0x%08x\n", reg);
  1126. }
  1127. static ssize_t store_indirect_dword(struct device *d,
  1128. struct device_attribute *attr,
  1129. const char *buf, size_t count)
  1130. {
  1131. struct ipw_priv *priv = d->driver_data;
  1132. sscanf(buf, "%x", &priv->indirect_dword);
  1133. priv->status |= STATUS_INDIRECT_DWORD;
  1134. return strnlen(buf, count);
  1135. }
  1136. static DEVICE_ATTR(indirect_dword, S_IWUSR | S_IRUGO,
  1137. show_indirect_dword, store_indirect_dword);
  1138. static ssize_t show_indirect_byte(struct device *d,
  1139. struct device_attribute *attr, char *buf)
  1140. {
  1141. u8 reg = 0;
  1142. struct ipw_priv *priv = d->driver_data;
  1143. if (priv->status & STATUS_INDIRECT_BYTE)
  1144. reg = ipw_read_reg8(priv, priv->indirect_byte);
  1145. else
  1146. reg = 0;
  1147. return sprintf(buf, "0x%02x\n", reg);
  1148. }
  1149. static ssize_t store_indirect_byte(struct device *d,
  1150. struct device_attribute *attr,
  1151. const char *buf, size_t count)
  1152. {
  1153. struct ipw_priv *priv = d->driver_data;
  1154. sscanf(buf, "%x", &priv->indirect_byte);
  1155. priv->status |= STATUS_INDIRECT_BYTE;
  1156. return strnlen(buf, count);
  1157. }
  1158. static DEVICE_ATTR(indirect_byte, S_IWUSR | S_IRUGO,
  1159. show_indirect_byte, store_indirect_byte);
  1160. static ssize_t show_direct_dword(struct device *d,
  1161. struct device_attribute *attr, char *buf)
  1162. {
  1163. u32 reg = 0;
  1164. struct ipw_priv *priv = d->driver_data;
  1165. if (priv->status & STATUS_DIRECT_DWORD)
  1166. reg = ipw_read32(priv, priv->direct_dword);
  1167. else
  1168. reg = 0;
  1169. return sprintf(buf, "0x%08x\n", reg);
  1170. }
  1171. static ssize_t store_direct_dword(struct device *d,
  1172. struct device_attribute *attr,
  1173. const char *buf, size_t count)
  1174. {
  1175. struct ipw_priv *priv = d->driver_data;
  1176. sscanf(buf, "%x", &priv->direct_dword);
  1177. priv->status |= STATUS_DIRECT_DWORD;
  1178. return strnlen(buf, count);
  1179. }
  1180. static DEVICE_ATTR(direct_dword, S_IWUSR | S_IRUGO,
  1181. show_direct_dword, store_direct_dword);
  1182. static inline int rf_kill_active(struct ipw_priv *priv)
  1183. {
  1184. if (0 == (ipw_read32(priv, 0x30) & 0x10000))
  1185. priv->status |= STATUS_RF_KILL_HW;
  1186. else
  1187. priv->status &= ~STATUS_RF_KILL_HW;
  1188. return (priv->status & STATUS_RF_KILL_HW) ? 1 : 0;
  1189. }
  1190. static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
  1191. char *buf)
  1192. {
  1193. /* 0 - RF kill not enabled
  1194. 1 - SW based RF kill active (sysfs)
  1195. 2 - HW based RF kill active
  1196. 3 - Both HW and SW baed RF kill active */
  1197. struct ipw_priv *priv = d->driver_data;
  1198. int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
  1199. (rf_kill_active(priv) ? 0x2 : 0x0);
  1200. return sprintf(buf, "%i\n", val);
  1201. }
  1202. static int ipw_radio_kill_sw(struct ipw_priv *priv, int disable_radio)
  1203. {
  1204. if ((disable_radio ? 1 : 0) ==
  1205. ((priv->status & STATUS_RF_KILL_SW) ? 1 : 0))
  1206. return 0;
  1207. IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
  1208. disable_radio ? "OFF" : "ON");
  1209. if (disable_radio) {
  1210. priv->status |= STATUS_RF_KILL_SW;
  1211. if (priv->workqueue)
  1212. cancel_delayed_work(&priv->request_scan);
  1213. queue_work(priv->workqueue, &priv->down);
  1214. } else {
  1215. priv->status &= ~STATUS_RF_KILL_SW;
  1216. if (rf_kill_active(priv)) {
  1217. IPW_DEBUG_RF_KILL("Can not turn radio back on - "
  1218. "disabled by HW switch\n");
  1219. /* Make sure the RF_KILL check timer is running */
  1220. cancel_delayed_work(&priv->rf_kill);
  1221. queue_delayed_work(priv->workqueue, &priv->rf_kill,
  1222. 2 * HZ);
  1223. } else
  1224. queue_work(priv->workqueue, &priv->up);
  1225. }
  1226. return 1;
  1227. }
  1228. static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
  1229. const char *buf, size_t count)
  1230. {
  1231. struct ipw_priv *priv = d->driver_data;
  1232. ipw_radio_kill_sw(priv, buf[0] == '1');
  1233. return count;
  1234. }
  1235. static DEVICE_ATTR(rf_kill, S_IWUSR | S_IRUGO, show_rf_kill, store_rf_kill);
  1236. static ssize_t show_speed_scan(struct device *d, struct device_attribute *attr,
  1237. char *buf)
  1238. {
  1239. struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
  1240. int pos = 0, len = 0;
  1241. if (priv->config & CFG_SPEED_SCAN) {
  1242. while (priv->speed_scan[pos] != 0)
  1243. len += sprintf(&buf[len], "%d ",
  1244. priv->speed_scan[pos++]);
  1245. return len + sprintf(&buf[len], "\n");
  1246. }
  1247. return sprintf(buf, "0\n");
  1248. }
  1249. static ssize_t store_speed_scan(struct device *d, struct device_attribute *attr,
  1250. const char *buf, size_t count)
  1251. {
  1252. struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
  1253. int channel, pos = 0;
  1254. const char *p = buf;
  1255. /* list of space separated channels to scan, optionally ending with 0 */
  1256. while ((channel = simple_strtol(p, NULL, 0))) {
  1257. if (pos == MAX_SPEED_SCAN - 1) {
  1258. priv->speed_scan[pos] = 0;
  1259. break;
  1260. }
  1261. if (ieee80211_is_valid_channel(priv->ieee, channel))
  1262. priv->speed_scan[pos++] = channel;
  1263. else
  1264. IPW_WARNING("Skipping invalid channel request: %d\n",
  1265. channel);
  1266. p = strchr(p, ' ');
  1267. if (!p)
  1268. break;
  1269. while (*p == ' ' || *p == '\t')
  1270. p++;
  1271. }
  1272. if (pos == 0)
  1273. priv->config &= ~CFG_SPEED_SCAN;
  1274. else {
  1275. priv->speed_scan_pos = 0;
  1276. priv->config |= CFG_SPEED_SCAN;
  1277. }
  1278. return count;
  1279. }
  1280. static DEVICE_ATTR(speed_scan, S_IWUSR | S_IRUGO, show_speed_scan,
  1281. store_speed_scan);
  1282. static ssize_t show_net_stats(struct device *d, struct device_attribute *attr,
  1283. char *buf)
  1284. {
  1285. struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
  1286. return sprintf(buf, "%c\n", (priv->config & CFG_NET_STATS) ? '1' : '0');
  1287. }
  1288. static ssize_t store_net_stats(struct device *d, struct device_attribute *attr,
  1289. const char *buf, size_t count)
  1290. {
  1291. struct ipw_priv *priv = (struct ipw_priv *)d->driver_data;
  1292. if (buf[0] == '1')
  1293. priv->config |= CFG_NET_STATS;
  1294. else
  1295. priv->config &= ~CFG_NET_STATS;
  1296. return count;
  1297. }
  1298. static DEVICE_ATTR(net_stats, S_IWUSR | S_IRUGO,
  1299. show_net_stats, store_net_stats);
  1300. static void notify_wx_assoc_event(struct ipw_priv *priv)
  1301. {
  1302. union iwreq_data wrqu;
  1303. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  1304. if (priv->status & STATUS_ASSOCIATED)
  1305. memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
  1306. else
  1307. memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
  1308. wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
  1309. }
  1310. static void ipw_irq_tasklet(struct ipw_priv *priv)
  1311. {
  1312. u32 inta, inta_mask, handled = 0;
  1313. unsigned long flags;
  1314. int rc = 0;
  1315. spin_lock_irqsave(&priv->lock, flags);
  1316. inta = ipw_read32(priv, IPW_INTA_RW);
  1317. inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
  1318. inta &= (IPW_INTA_MASK_ALL & inta_mask);
  1319. /* Add any cached INTA values that need to be handled */
  1320. inta |= priv->isr_inta;
  1321. /* handle all the justifications for the interrupt */
  1322. if (inta & IPW_INTA_BIT_RX_TRANSFER) {
  1323. ipw_rx(priv);
  1324. handled |= IPW_INTA_BIT_RX_TRANSFER;
  1325. }
  1326. if (inta & IPW_INTA_BIT_TX_CMD_QUEUE) {
  1327. IPW_DEBUG_HC("Command completed.\n");
  1328. rc = ipw_queue_tx_reclaim(priv, &priv->txq_cmd, -1);
  1329. priv->status &= ~STATUS_HCMD_ACTIVE;
  1330. wake_up_interruptible(&priv->wait_command_queue);
  1331. handled |= IPW_INTA_BIT_TX_CMD_QUEUE;
  1332. }
  1333. if (inta & IPW_INTA_BIT_TX_QUEUE_1) {
  1334. IPW_DEBUG_TX("TX_QUEUE_1\n");
  1335. rc = ipw_queue_tx_reclaim(priv, &priv->txq[0], 0);
  1336. handled |= IPW_INTA_BIT_TX_QUEUE_1;
  1337. }
  1338. if (inta & IPW_INTA_BIT_TX_QUEUE_2) {
  1339. IPW_DEBUG_TX("TX_QUEUE_2\n");
  1340. rc = ipw_queue_tx_reclaim(priv, &priv->txq[1], 1);
  1341. handled |= IPW_INTA_BIT_TX_QUEUE_2;
  1342. }
  1343. if (inta & IPW_INTA_BIT_TX_QUEUE_3) {
  1344. IPW_DEBUG_TX("TX_QUEUE_3\n");
  1345. rc = ipw_queue_tx_reclaim(priv, &priv->txq[2], 2);
  1346. handled |= IPW_INTA_BIT_TX_QUEUE_3;
  1347. }
  1348. if (inta & IPW_INTA_BIT_TX_QUEUE_4) {
  1349. IPW_DEBUG_TX("TX_QUEUE_4\n");
  1350. rc = ipw_queue_tx_reclaim(priv, &priv->txq[3], 3);
  1351. handled |= IPW_INTA_BIT_TX_QUEUE_4;
  1352. }
  1353. if (inta & IPW_INTA_BIT_STATUS_CHANGE) {
  1354. IPW_WARNING("STATUS_CHANGE\n");
  1355. handled |= IPW_INTA_BIT_STATUS_CHANGE;
  1356. }
  1357. if (inta & IPW_INTA_BIT_BEACON_PERIOD_EXPIRED) {
  1358. IPW_WARNING("TX_PERIOD_EXPIRED\n");
  1359. handled |= IPW_INTA_BIT_BEACON_PERIOD_EXPIRED;
  1360. }
  1361. if (inta & IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE) {
  1362. IPW_WARNING("HOST_CMD_DONE\n");
  1363. handled |= IPW_INTA_BIT_SLAVE_MODE_HOST_CMD_DONE;
  1364. }
  1365. if (inta & IPW_INTA_BIT_FW_INITIALIZATION_DONE) {
  1366. IPW_WARNING("FW_INITIALIZATION_DONE\n");
  1367. handled |= IPW_INTA_BIT_FW_INITIALIZATION_DONE;
  1368. }
  1369. if (inta & IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE) {
  1370. IPW_WARNING("PHY_OFF_DONE\n");
  1371. handled |= IPW_INTA_BIT_FW_CARD_DISABLE_PHY_OFF_DONE;
  1372. }
  1373. if (inta & IPW_INTA_BIT_RF_KILL_DONE) {
  1374. IPW_DEBUG_RF_KILL("RF_KILL_DONE\n");
  1375. priv->status |= STATUS_RF_KILL_HW;
  1376. wake_up_interruptible(&priv->wait_command_queue);
  1377. priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
  1378. cancel_delayed_work(&priv->request_scan);
  1379. schedule_work(&priv->link_down);
  1380. queue_delayed_work(priv->workqueue, &priv->rf_kill, 2 * HZ);
  1381. handled |= IPW_INTA_BIT_RF_KILL_DONE;
  1382. }
  1383. if (inta & IPW_INTA_BIT_FATAL_ERROR) {
  1384. IPW_ERROR("Firmware error detected. Restarting.\n");
  1385. if (priv->error) {
  1386. IPW_ERROR("Sysfs 'error' log already exists.\n");
  1387. #ifdef CONFIG_IPW_DEBUG
  1388. if (ipw_debug_level & IPW_DL_FW_ERRORS) {
  1389. struct ipw_fw_error *error =
  1390. ipw_alloc_error_log(priv);
  1391. ipw_dump_error_log(priv, error);
  1392. if (error)
  1393. ipw_free_error_log(error);
  1394. }
  1395. #endif
  1396. } else {
  1397. priv->error = ipw_alloc_error_log(priv);
  1398. if (priv->error)
  1399. IPW_ERROR("Sysfs 'error' log captured.\n");
  1400. else
  1401. IPW_ERROR("Error allocating sysfs 'error' "
  1402. "log.\n");
  1403. #ifdef CONFIG_IPW_DEBUG
  1404. if (ipw_debug_level & IPW_DL_FW_ERRORS)
  1405. ipw_dump_error_log(priv, priv->error);
  1406. #endif
  1407. }
  1408. /* XXX: If hardware encryption is for WPA/WPA2,
  1409. * we have to notify the supplicant. */
  1410. if (priv->ieee->sec.encrypt) {
  1411. priv->status &= ~STATUS_ASSOCIATED;
  1412. notify_wx_assoc_event(priv);
  1413. }
  1414. /* Keep the restart process from trying to send host
  1415. * commands by clearing the INIT status bit */
  1416. priv->status &= ~STATUS_INIT;
  1417. /* Cancel currently queued command. */
  1418. priv->status &= ~STATUS_HCMD_ACTIVE;
  1419. wake_up_interruptible(&priv->wait_command_queue);
  1420. queue_work(priv->workqueue, &priv->adapter_restart);
  1421. handled |= IPW_INTA_BIT_FATAL_ERROR;
  1422. }
  1423. if (inta & IPW_INTA_BIT_PARITY_ERROR) {
  1424. IPW_ERROR("Parity error\n");
  1425. handled |= IPW_INTA_BIT_PARITY_ERROR;
  1426. }
  1427. if (handled != inta) {
  1428. IPW_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
  1429. }
  1430. /* enable all interrupts */
  1431. ipw_enable_interrupts(priv);
  1432. spin_unlock_irqrestore(&priv->lock, flags);
  1433. }
  1434. #ifdef CONFIG_IPW_DEBUG
  1435. #define IPW_CMD(x) case IPW_CMD_ ## x : return #x
  1436. static char *get_cmd_string(u8 cmd)
  1437. {
  1438. switch (cmd) {
  1439. IPW_CMD(HOST_COMPLETE);
  1440. IPW_CMD(POWER_DOWN);
  1441. IPW_CMD(SYSTEM_CONFIG);
  1442. IPW_CMD(MULTICAST_ADDRESS);
  1443. IPW_CMD(SSID);
  1444. IPW_CMD(ADAPTER_ADDRESS);
  1445. IPW_CMD(PORT_TYPE);
  1446. IPW_CMD(RTS_THRESHOLD);
  1447. IPW_CMD(FRAG_THRESHOLD);
  1448. IPW_CMD(POWER_MODE);
  1449. IPW_CMD(WEP_KEY);
  1450. IPW_CMD(TGI_TX_KEY);
  1451. IPW_CMD(SCAN_REQUEST);
  1452. IPW_CMD(SCAN_REQUEST_EXT);
  1453. IPW_CMD(ASSOCIATE);
  1454. IPW_CMD(SUPPORTED_RATES);
  1455. IPW_CMD(SCAN_ABORT);
  1456. IPW_CMD(TX_FLUSH);
  1457. IPW_CMD(QOS_PARAMETERS);
  1458. IPW_CMD(DINO_CONFIG);
  1459. IPW_CMD(RSN_CAPABILITIES);
  1460. IPW_CMD(RX_KEY);
  1461. IPW_CMD(CARD_DISABLE);
  1462. IPW_CMD(SEED_NUMBER);
  1463. IPW_CMD(TX_POWER);
  1464. IPW_CMD(COUNTRY_INFO);
  1465. IPW_CMD(AIRONET_INFO);
  1466. IPW_CMD(AP_TX_POWER);
  1467. IPW_CMD(CCKM_INFO);
  1468. IPW_CMD(CCX_VER_INFO);
  1469. IPW_CMD(SET_CALIBRATION);
  1470. IPW_CMD(SENSITIVITY_CALIB);
  1471. IPW_CMD(RETRY_LIMIT);
  1472. IPW_CMD(IPW_PRE_POWER_DOWN);
  1473. IPW_CMD(VAP_BEACON_TEMPLATE);
  1474. IPW_CMD(VAP_DTIM_PERIOD);
  1475. IPW_CMD(EXT_SUPPORTED_RATES);
  1476. IPW_CMD(VAP_LOCAL_TX_PWR_CONSTRAINT);
  1477. IPW_CMD(VAP_QUIET_INTERVALS);
  1478. IPW_CMD(VAP_CHANNEL_SWITCH);
  1479. IPW_CMD(VAP_MANDATORY_CHANNELS);
  1480. IPW_CMD(VAP_CELL_PWR_LIMIT);
  1481. IPW_CMD(VAP_CF_PARAM_SET);
  1482. IPW_CMD(VAP_SET_BEACONING_STATE);
  1483. IPW_CMD(MEASUREMENT);
  1484. IPW_CMD(POWER_CAPABILITY);
  1485. IPW_CMD(SUPPORTED_CHANNELS);
  1486. IPW_CMD(TPC_REPORT);
  1487. IPW_CMD(WME_INFO);
  1488. IPW_CMD(PRODUCTION_COMMAND);
  1489. default:
  1490. return "UNKNOWN";
  1491. }
  1492. }
  1493. #endif
  1494. #define HOST_COMPLETE_TIMEOUT HZ
  1495. static int ipw_send_cmd(struct ipw_priv *priv, struct host_cmd *cmd)
  1496. {
  1497. int rc = 0;
  1498. unsigned long flags;
  1499. spin_lock_irqsave(&priv->lock, flags);
  1500. if (priv->status & STATUS_HCMD_ACTIVE) {
  1501. IPW_ERROR("Failed to send %s: Already sending a command.\n",
  1502. get_cmd_string(cmd->cmd));
  1503. spin_unlock_irqrestore(&priv->lock, flags);
  1504. return -EAGAIN;
  1505. }
  1506. priv->status |= STATUS_HCMD_ACTIVE;
  1507. IPW_DEBUG_HC("%s command (#%d) %d bytes: 0x%08X\n",
  1508. get_cmd_string(cmd->cmd), cmd->cmd, cmd->len,
  1509. priv->status);
  1510. printk_buf(IPW_DL_HOST_COMMAND, (u8 *) cmd->param, cmd->len);
  1511. rc = ipw_queue_tx_hcmd(priv, cmd->cmd, &cmd->param, cmd->len, 0);
  1512. if (rc) {
  1513. priv->status &= ~STATUS_HCMD_ACTIVE;
  1514. IPW_ERROR("Failed to send %s: Reason %d\n",
  1515. get_cmd_string(cmd->cmd), rc);
  1516. spin_unlock_irqrestore(&priv->lock, flags);
  1517. return rc;
  1518. }
  1519. spin_unlock_irqrestore(&priv->lock, flags);
  1520. rc = wait_event_interruptible_timeout(priv->wait_command_queue,
  1521. !(priv->
  1522. status & STATUS_HCMD_ACTIVE),
  1523. HOST_COMPLETE_TIMEOUT);
  1524. if (rc == 0) {
  1525. spin_lock_irqsave(&priv->lock, flags);
  1526. if (priv->status & STATUS_HCMD_ACTIVE) {
  1527. IPW_ERROR("Failed to send %s: Command timed out.\n",
  1528. get_cmd_string(cmd->cmd));
  1529. priv->status &= ~STATUS_HCMD_ACTIVE;
  1530. spin_unlock_irqrestore(&priv->lock, flags);
  1531. return -EIO;
  1532. }
  1533. spin_unlock_irqrestore(&priv->lock, flags);
  1534. }
  1535. if (priv->status & STATUS_RF_KILL_HW) {
  1536. IPW_ERROR("Failed to send %s: Aborted due to RF kill switch.\n",
  1537. get_cmd_string(cmd->cmd));
  1538. return -EIO;
  1539. }
  1540. return 0;
  1541. }
  1542. static int ipw_send_host_complete(struct ipw_priv *priv)
  1543. {
  1544. struct host_cmd cmd = {
  1545. .cmd = IPW_CMD_HOST_COMPLETE,
  1546. .len = 0
  1547. };
  1548. if (!priv) {
  1549. IPW_ERROR("Invalid args\n");
  1550. return -1;
  1551. }
  1552. return ipw_send_cmd(priv, &cmd);
  1553. }
  1554. static int ipw_send_system_config(struct ipw_priv *priv,
  1555. struct ipw_sys_config *config)
  1556. {
  1557. struct host_cmd cmd = {
  1558. .cmd = IPW_CMD_SYSTEM_CONFIG,
  1559. .len = sizeof(*config)
  1560. };
  1561. if (!priv || !config) {
  1562. IPW_ERROR("Invalid args\n");
  1563. return -1;
  1564. }
  1565. memcpy(cmd.param, config, sizeof(*config));
  1566. return ipw_send_cmd(priv, &cmd);
  1567. }
  1568. static int ipw_send_ssid(struct ipw_priv *priv, u8 * ssid, int len)
  1569. {
  1570. struct host_cmd cmd = {
  1571. .cmd = IPW_CMD_SSID,
  1572. .len = min(len, IW_ESSID_MAX_SIZE)
  1573. };
  1574. if (!priv || !ssid) {
  1575. IPW_ERROR("Invalid args\n");
  1576. return -1;
  1577. }
  1578. memcpy(cmd.param, ssid, cmd.len);
  1579. return ipw_send_cmd(priv, &cmd);
  1580. }
  1581. static int ipw_send_adapter_address(struct ipw_priv *priv, u8 * mac)
  1582. {
  1583. struct host_cmd cmd = {
  1584. .cmd = IPW_CMD_ADAPTER_ADDRESS,
  1585. .len = ETH_ALEN
  1586. };
  1587. if (!priv || !mac) {
  1588. IPW_ERROR("Invalid args\n");
  1589. return -1;
  1590. }
  1591. IPW_DEBUG_INFO("%s: Setting MAC to " MAC_FMT "\n",
  1592. priv->net_dev->name, MAC_ARG(mac));
  1593. memcpy(cmd.param, mac, ETH_ALEN);
  1594. return ipw_send_cmd(priv, &cmd);
  1595. }
  1596. /*
  1597. * NOTE: This must be executed from our workqueue as it results in udelay
  1598. * being called which may corrupt the keyboard if executed on default
  1599. * workqueue
  1600. */
  1601. static void ipw_adapter_restart(void *adapter)
  1602. {
  1603. struct ipw_priv *priv = adapter;
  1604. if (priv->status & STATUS_RF_KILL_MASK)
  1605. return;
  1606. ipw_down(priv);
  1607. if (priv->assoc_network &&
  1608. (priv->assoc_network->capability & WLAN_CAPABILITY_IBSS))
  1609. ipw_remove_current_network(priv);
  1610. if (ipw_up(priv)) {
  1611. IPW_ERROR("Failed to up device\n");
  1612. return;
  1613. }
  1614. }
  1615. static void ipw_bg_adapter_restart(void *data)
  1616. {
  1617. struct ipw_priv *priv = data;
  1618. down(&priv->sem);
  1619. ipw_adapter_restart(data);
  1620. up(&priv->sem);
  1621. }
  1622. #define IPW_SCAN_CHECK_WATCHDOG (5 * HZ)
  1623. static void ipw_scan_check(void *data)
  1624. {
  1625. struct ipw_priv *priv = data;
  1626. if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
  1627. IPW_DEBUG_SCAN("Scan completion watchdog resetting "
  1628. "adapter (%dms).\n",
  1629. IPW_SCAN_CHECK_WATCHDOG / 100);
  1630. queue_work(priv->workqueue, &priv->adapter_restart);
  1631. }
  1632. }
  1633. static void ipw_bg_scan_check(void *data)
  1634. {
  1635. struct ipw_priv *priv = data;
  1636. down(&priv->sem);
  1637. ipw_scan_check(data);
  1638. up(&priv->sem);
  1639. }
  1640. static int ipw_send_scan_request_ext(struct ipw_priv *priv,
  1641. struct ipw_scan_request_ext *request)
  1642. {
  1643. struct host_cmd cmd = {
  1644. .cmd = IPW_CMD_SCAN_REQUEST_EXT,
  1645. .len = sizeof(*request)
  1646. };
  1647. memcpy(cmd.param, request, sizeof(*request));
  1648. return ipw_send_cmd(priv, &cmd);
  1649. }
  1650. static int ipw_send_scan_abort(struct ipw_priv *priv)
  1651. {
  1652. struct host_cmd cmd = {
  1653. .cmd = IPW_CMD_SCAN_ABORT,
  1654. .len = 0
  1655. };
  1656. if (!priv) {
  1657. IPW_ERROR("Invalid args\n");
  1658. return -1;
  1659. }
  1660. return ipw_send_cmd(priv, &cmd);
  1661. }
  1662. static int ipw_set_sensitivity(struct ipw_priv *priv, u16 sens)
  1663. {
  1664. struct host_cmd cmd = {
  1665. .cmd = IPW_CMD_SENSITIVITY_CALIB,
  1666. .len = sizeof(struct ipw_sensitivity_calib)
  1667. };
  1668. struct ipw_sensitivity_calib *calib = (struct ipw_sensitivity_calib *)
  1669. &cmd.param;
  1670. calib->beacon_rssi_raw = sens;
  1671. return ipw_send_cmd(priv, &cmd);
  1672. }
  1673. static int ipw_send_associate(struct ipw_priv *priv,
  1674. struct ipw_associate *associate)
  1675. {
  1676. struct host_cmd cmd = {
  1677. .cmd = IPW_CMD_ASSOCIATE,
  1678. .len = sizeof(*associate)
  1679. };
  1680. struct ipw_associate tmp_associate;
  1681. memcpy(&tmp_associate, associate, sizeof(*associate));
  1682. tmp_associate.policy_support =
  1683. cpu_to_le16(tmp_associate.policy_support);
  1684. tmp_associate.assoc_tsf_msw = cpu_to_le32(tmp_associate.assoc_tsf_msw);
  1685. tmp_associate.assoc_tsf_lsw = cpu_to_le32(tmp_associate.assoc_tsf_lsw);
  1686. tmp_associate.capability = cpu_to_le16(tmp_associate.capability);
  1687. tmp_associate.listen_interval =
  1688. cpu_to_le16(tmp_associate.listen_interval);
  1689. tmp_associate.beacon_interval =
  1690. cpu_to_le16(tmp_associate.beacon_interval);
  1691. tmp_associate.atim_window = cpu_to_le16(tmp_associate.atim_window);
  1692. if (!priv || !associate) {
  1693. IPW_ERROR("Invalid args\n");
  1694. return -1;
  1695. }
  1696. memcpy(cmd.param, &tmp_associate, sizeof(*associate));
  1697. return ipw_send_cmd(priv, &cmd);
  1698. }
  1699. static int ipw_send_supported_rates(struct ipw_priv *priv,
  1700. struct ipw_supported_rates *rates)
  1701. {
  1702. struct host_cmd cmd = {
  1703. .cmd = IPW_CMD_SUPPORTED_RATES,
  1704. .len = sizeof(*rates)
  1705. };
  1706. if (!priv || !rates) {
  1707. IPW_ERROR("Invalid args\n");
  1708. return -1;
  1709. }
  1710. memcpy(cmd.param, rates, sizeof(*rates));
  1711. return ipw_send_cmd(priv, &cmd);
  1712. }
  1713. static int ipw_set_random_seed(struct ipw_priv *priv)
  1714. {
  1715. struct host_cmd cmd = {
  1716. .cmd = IPW_CMD_SEED_NUMBER,
  1717. .len = sizeof(u32)
  1718. };
  1719. if (!priv) {
  1720. IPW_ERROR("Invalid args\n");
  1721. return -1;
  1722. }
  1723. get_random_bytes(&cmd.param, sizeof(u32));
  1724. return ipw_send_cmd(priv, &cmd);
  1725. }
  1726. static int ipw_send_card_disable(struct ipw_priv *priv, u32 phy_off)
  1727. {
  1728. struct host_cmd cmd = {
  1729. .cmd = IPW_CMD_CARD_DISABLE,
  1730. .len = sizeof(u32)
  1731. };
  1732. if (!priv) {
  1733. IPW_ERROR("Invalid args\n");
  1734. return -1;
  1735. }
  1736. *((u32 *) & cmd.param) = phy_off;
  1737. return ipw_send_cmd(priv, &cmd);
  1738. }
  1739. static int ipw_send_tx_power(struct ipw_priv *priv, struct ipw_tx_power *power)
  1740. {
  1741. struct host_cmd cmd = {
  1742. .cmd = IPW_CMD_TX_POWER,
  1743. .len = sizeof(*power)
  1744. };
  1745. if (!priv || !power) {
  1746. IPW_ERROR("Invalid args\n");
  1747. return -1;
  1748. }
  1749. memcpy(cmd.param, power, sizeof(*power));
  1750. return ipw_send_cmd(priv, &cmd);
  1751. }
  1752. static int ipw_set_tx_power(struct ipw_priv *priv)
  1753. {
  1754. const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
  1755. struct ipw_tx_power tx_power;
  1756. s8 max_power;
  1757. int i;
  1758. memset(&tx_power, 0, sizeof(tx_power));
  1759. /* configure device for 'G' band */
  1760. tx_power.ieee_mode = IPW_G_MODE;
  1761. tx_power.num_channels = geo->bg_channels;
  1762. for (i = 0; i < geo->bg_channels; i++) {
  1763. max_power = geo->bg[i].max_power;
  1764. tx_power.channels_tx_power[i].channel_number =
  1765. geo->bg[i].channel;
  1766. tx_power.channels_tx_power[i].tx_power = max_power ?
  1767. min(max_power, priv->tx_power) : priv->tx_power;
  1768. }
  1769. if (ipw_send_tx_power(priv, &tx_power))
  1770. return -EIO;
  1771. /* configure device to also handle 'B' band */
  1772. tx_power.ieee_mode = IPW_B_MODE;
  1773. if (ipw_send_tx_power(priv, &tx_power))
  1774. return -EIO;
  1775. /* configure device to also handle 'A' band */
  1776. if (priv->ieee->abg_true) {
  1777. tx_power.ieee_mode = IPW_A_MODE;
  1778. tx_power.num_channels = geo->a_channels;
  1779. for (i = 0; i < tx_power.num_channels; i++) {
  1780. max_power = geo->a[i].max_power;
  1781. tx_power.channels_tx_power[i].channel_number =
  1782. geo->a[i].channel;
  1783. tx_power.channels_tx_power[i].tx_power = max_power ?
  1784. min(max_power, priv->tx_power) : priv->tx_power;
  1785. }
  1786. if (ipw_send_tx_power(priv, &tx_power))
  1787. return -EIO;
  1788. }
  1789. return 0;
  1790. }
  1791. static int ipw_send_rts_threshold(struct ipw_priv *priv, u16 rts)
  1792. {
  1793. struct ipw_rts_threshold rts_threshold = {
  1794. .rts_threshold = rts,
  1795. };
  1796. struct host_cmd cmd = {
  1797. .cmd = IPW_CMD_RTS_THRESHOLD,
  1798. .len = sizeof(rts_threshold)
  1799. };
  1800. if (!priv) {
  1801. IPW_ERROR("Invalid args\n");
  1802. return -1;
  1803. }
  1804. memcpy(cmd.param, &rts_threshold, sizeof(rts_threshold));
  1805. return ipw_send_cmd(priv, &cmd);
  1806. }
  1807. static int ipw_send_frag_threshold(struct ipw_priv *priv, u16 frag)
  1808. {
  1809. struct ipw_frag_threshold frag_threshold = {
  1810. .frag_threshold = frag,
  1811. };
  1812. struct host_cmd cmd = {
  1813. .cmd = IPW_CMD_FRAG_THRESHOLD,
  1814. .len = sizeof(frag_threshold)
  1815. };
  1816. if (!priv) {
  1817. IPW_ERROR("Invalid args\n");
  1818. return -1;
  1819. }
  1820. memcpy(cmd.param, &frag_threshold, sizeof(frag_threshold));
  1821. return ipw_send_cmd(priv, &cmd);
  1822. }
  1823. static int ipw_send_power_mode(struct ipw_priv *priv, u32 mode)
  1824. {
  1825. struct host_cmd cmd = {
  1826. .cmd = IPW_CMD_POWER_MODE,
  1827. .len = sizeof(u32)
  1828. };
  1829. u32 *param = (u32 *) (&cmd.param);
  1830. if (!priv) {
  1831. IPW_ERROR("Invalid args\n");
  1832. return -1;
  1833. }
  1834. /* If on battery, set to 3, if AC set to CAM, else user
  1835. * level */
  1836. switch (mode) {
  1837. case IPW_POWER_BATTERY:
  1838. *param = IPW_POWER_INDEX_3;
  1839. break;
  1840. case IPW_POWER_AC:
  1841. *param = IPW_POWER_MODE_CAM;
  1842. break;
  1843. default:
  1844. *param = mode;
  1845. break;
  1846. }
  1847. return ipw_send_cmd(priv, &cmd);
  1848. }
  1849. static int ipw_send_retry_limit(struct ipw_priv *priv, u8 slimit, u8 llimit)
  1850. {
  1851. struct ipw_retry_limit retry_limit = {
  1852. .short_retry_limit = slimit,
  1853. .long_retry_limit = llimit
  1854. };
  1855. struct host_cmd cmd = {
  1856. .cmd = IPW_CMD_RETRY_LIMIT,
  1857. .len = sizeof(retry_limit)
  1858. };
  1859. if (!priv) {
  1860. IPW_ERROR("Invalid args\n");
  1861. return -1;
  1862. }
  1863. memcpy(cmd.param, &retry_limit, sizeof(retry_limit));
  1864. return ipw_send_cmd(priv, &cmd);
  1865. }
  1866. /*
  1867. * The IPW device contains a Microwire compatible EEPROM that stores
  1868. * various data like the MAC address. Usually the firmware has exclusive
  1869. * access to the eeprom, but during device initialization (before the
  1870. * device driver has sent the HostComplete command to the firmware) the
  1871. * device driver has read access to the EEPROM by way of indirect addressing
  1872. * through a couple of memory mapped registers.
  1873. *
  1874. * The following is a simplified implementation for pulling data out of the
  1875. * the eeprom, along with some helper functions to find information in
  1876. * the per device private data's copy of the eeprom.
  1877. *
  1878. * NOTE: To better understand how these functions work (i.e what is a chip
  1879. * select and why do have to keep driving the eeprom clock?), read
  1880. * just about any data sheet for a Microwire compatible EEPROM.
  1881. */
  1882. /* write a 32 bit value into the indirect accessor register */
  1883. static inline void eeprom_write_reg(struct ipw_priv *p, u32 data)
  1884. {
  1885. ipw_write_reg32(p, FW_MEM_REG_EEPROM_ACCESS, data);
  1886. /* the eeprom requires some time to complete the operation */
  1887. udelay(p->eeprom_delay);
  1888. return;
  1889. }
  1890. /* perform a chip select operation */
  1891. static inline void eeprom_cs(struct ipw_priv *priv)
  1892. {
  1893. eeprom_write_reg(priv, 0);
  1894. eeprom_write_reg(priv, EEPROM_BIT_CS);
  1895. eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
  1896. eeprom_write_reg(priv, EEPROM_BIT_CS);
  1897. }
  1898. /* perform a chip select operation */
  1899. static inline void eeprom_disable_cs(struct ipw_priv *priv)
  1900. {
  1901. eeprom_write_reg(priv, EEPROM_BIT_CS);
  1902. eeprom_write_reg(priv, 0);
  1903. eeprom_write_reg(priv, EEPROM_BIT_SK);
  1904. }
  1905. /* push a single bit down to the eeprom */
  1906. static inline void eeprom_write_bit(struct ipw_priv *p, u8 bit)
  1907. {
  1908. int d = (bit ? EEPROM_BIT_DI : 0);
  1909. eeprom_write_reg(p, EEPROM_BIT_CS | d);
  1910. eeprom_write_reg(p, EEPROM_BIT_CS | d | EEPROM_BIT_SK);
  1911. }
  1912. /* push an opcode followed by an address down to the eeprom */
  1913. static void eeprom_op(struct ipw_priv *priv, u8 op, u8 addr)
  1914. {
  1915. int i;
  1916. eeprom_cs(priv);
  1917. eeprom_write_bit(priv, 1);
  1918. eeprom_write_bit(priv, op & 2);
  1919. eeprom_write_bit(priv, op & 1);
  1920. for (i = 7; i >= 0; i--) {
  1921. eeprom_write_bit(priv, addr & (1 << i));
  1922. }
  1923. }
  1924. /* pull 16 bits off the eeprom, one bit at a time */
  1925. static u16 eeprom_read_u16(struct ipw_priv *priv, u8 addr)
  1926. {
  1927. int i;
  1928. u16 r = 0;
  1929. /* Send READ Opcode */
  1930. eeprom_op(priv, EEPROM_CMD_READ, addr);
  1931. /* Send dummy bit */
  1932. eeprom_write_reg(priv, EEPROM_BIT_CS);
  1933. /* Read the byte off the eeprom one bit at a time */
  1934. for (i = 0; i < 16; i++) {
  1935. u32 data = 0;
  1936. eeprom_write_reg(priv, EEPROM_BIT_CS | EEPROM_BIT_SK);
  1937. eeprom_write_reg(priv, EEPROM_BIT_CS);
  1938. data = ipw_read_reg32(priv, FW_MEM_REG_EEPROM_ACCESS);
  1939. r = (r << 1) | ((data & EEPROM_BIT_DO) ? 1 : 0);
  1940. }
  1941. /* Send another dummy bit */
  1942. eeprom_write_reg(priv, 0);
  1943. eeprom_disable_cs(priv);
  1944. return r;
  1945. }
  1946. /* helper function for pulling the mac address out of the private */
  1947. /* data's copy of the eeprom data */
  1948. static void eeprom_parse_mac(struct ipw_priv *priv, u8 * mac)
  1949. {
  1950. memcpy(mac, &priv->eeprom[EEPROM_MAC_ADDRESS], 6);
  1951. }
  1952. /*
  1953. * Either the device driver (i.e. the host) or the firmware can
  1954. * load eeprom data into the designated region in SRAM. If neither
  1955. * happens then the FW will shutdown with a fatal error.
  1956. *
  1957. * In order to signal the FW to load the EEPROM, the EEPROM_LOAD_DISABLE
  1958. * bit needs region of shared SRAM needs to be non-zero.
  1959. */
  1960. static void ipw_eeprom_init_sram(struct ipw_priv *priv)
  1961. {
  1962. int i;
  1963. u16 *eeprom = (u16 *) priv->eeprom;
  1964. IPW_DEBUG_TRACE(">>\n");
  1965. /* read entire contents of eeprom into private buffer */
  1966. for (i = 0; i < 128; i++)
  1967. eeprom[i] = le16_to_cpu(eeprom_read_u16(priv, (u8) i));
  1968. /*
  1969. If the data looks correct, then copy it to our private
  1970. copy. Otherwise let the firmware know to perform the operation
  1971. on it's own
  1972. */
  1973. if ((priv->eeprom + EEPROM_VERSION) != 0) {
  1974. IPW_DEBUG_INFO("Writing EEPROM data into SRAM\n");
  1975. /* write the eeprom data to sram */
  1976. for (i = 0; i < IPW_EEPROM_IMAGE_SIZE; i++)
  1977. ipw_write8(priv, IPW_EEPROM_DATA + i, priv->eeprom[i]);
  1978. /* Do not load eeprom data on fatal error or suspend */
  1979. ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
  1980. } else {
  1981. IPW_DEBUG_INFO("Enabling FW initializationg of SRAM\n");
  1982. /* Load eeprom data on fatal error or suspend */
  1983. ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 1);
  1984. }
  1985. IPW_DEBUG_TRACE("<<\n");
  1986. }
  1987. static inline void ipw_zero_memory(struct ipw_priv *priv, u32 start, u32 count)
  1988. {
  1989. count >>= 2;
  1990. if (!count)
  1991. return;
  1992. _ipw_write32(priv, IPW_AUTOINC_ADDR, start);
  1993. while (count--)
  1994. _ipw_write32(priv, IPW_AUTOINC_DATA, 0);
  1995. }
  1996. static inline void ipw_fw_dma_reset_command_blocks(struct ipw_priv *priv)
  1997. {
  1998. ipw_zero_memory(priv, IPW_SHARED_SRAM_DMA_CONTROL,
  1999. CB_NUMBER_OF_ELEMENTS_SMALL *
  2000. sizeof(struct command_block));
  2001. }
  2002. static int ipw_fw_dma_enable(struct ipw_priv *priv)
  2003. { /* start dma engine but no transfers yet */
  2004. IPW_DEBUG_FW(">> : \n");
  2005. /* Start the dma */
  2006. ipw_fw_dma_reset_command_blocks(priv);
  2007. /* Write CB base address */
  2008. ipw_write_reg32(priv, IPW_DMA_I_CB_BASE, IPW_SHARED_SRAM_DMA_CONTROL);
  2009. IPW_DEBUG_FW("<< : \n");
  2010. return 0;
  2011. }
  2012. static void ipw_fw_dma_abort(struct ipw_priv *priv)
  2013. {
  2014. u32 control = 0;
  2015. IPW_DEBUG_FW(">> :\n");
  2016. //set the Stop and Abort bit
  2017. control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_STOP_AND_ABORT;
  2018. ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
  2019. priv->sram_desc.last_cb_index = 0;
  2020. IPW_DEBUG_FW("<< \n");
  2021. }
  2022. static int ipw_fw_dma_write_command_block(struct ipw_priv *priv, int index,
  2023. struct command_block *cb)
  2024. {
  2025. u32 address =
  2026. IPW_SHARED_SRAM_DMA_CONTROL +
  2027. (sizeof(struct command_block) * index);
  2028. IPW_DEBUG_FW(">> :\n");
  2029. ipw_write_indirect(priv, address, (u8 *) cb,
  2030. (int)sizeof(struct command_block));
  2031. IPW_DEBUG_FW("<< :\n");
  2032. return 0;
  2033. }
  2034. static int ipw_fw_dma_kick(struct ipw_priv *priv)
  2035. {
  2036. u32 control = 0;
  2037. u32 index = 0;
  2038. IPW_DEBUG_FW(">> :\n");
  2039. for (index = 0; index < priv->sram_desc.last_cb_index; index++)
  2040. ipw_fw_dma_write_command_block(priv, index,
  2041. &priv->sram_desc.cb_list[index]);
  2042. /* Enable the DMA in the CSR register */
  2043. ipw_clear_bit(priv, IPW_RESET_REG,
  2044. IPW_RESET_REG_MASTER_DISABLED |
  2045. IPW_RESET_REG_STOP_MASTER);
  2046. /* Set the Start bit. */
  2047. control = DMA_CONTROL_SMALL_CB_CONST_VALUE | DMA_CB_START;
  2048. ipw_write_reg32(priv, IPW_DMA_I_DMA_CONTROL, control);
  2049. IPW_DEBUG_FW("<< :\n");
  2050. return 0;
  2051. }
  2052. static void ipw_fw_dma_dump_command_block(struct ipw_priv *priv)
  2053. {
  2054. u32 address;
  2055. u32 register_value = 0;
  2056. u32 cb_fields_address = 0;
  2057. IPW_DEBUG_FW(">> :\n");
  2058. address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
  2059. IPW_DEBUG_FW_INFO("Current CB is 0x%x \n", address);
  2060. /* Read the DMA Controlor register */
  2061. register_value = ipw_read_reg32(priv, IPW_DMA_I_DMA_CONTROL);
  2062. IPW_DEBUG_FW_INFO("IPW_DMA_I_DMA_CONTROL is 0x%x \n", register_value);
  2063. /* Print the CB values */
  2064. cb_fields_address = address;
  2065. register_value = ipw_read_reg32(priv, cb_fields_address);
  2066. IPW_DEBUG_FW_INFO("Current CB ControlField is 0x%x \n", register_value);
  2067. cb_fields_address += sizeof(u32);
  2068. register_value = ipw_read_reg32(priv, cb_fields_address);
  2069. IPW_DEBUG_FW_INFO("Current CB Source Field is 0x%x \n", register_value);
  2070. cb_fields_address += sizeof(u32);
  2071. register_value = ipw_read_reg32(priv, cb_fields_address);
  2072. IPW_DEBUG_FW_INFO("Current CB Destination Field is 0x%x \n",
  2073. register_value);
  2074. cb_fields_address += sizeof(u32);
  2075. register_value = ipw_read_reg32(priv, cb_fields_address);
  2076. IPW_DEBUG_FW_INFO("Current CB Status Field is 0x%x \n", register_value);
  2077. IPW_DEBUG_FW(">> :\n");
  2078. }
  2079. static int ipw_fw_dma_command_block_index(struct ipw_priv *priv)
  2080. {
  2081. u32 current_cb_address = 0;
  2082. u32 current_cb_index = 0;
  2083. IPW_DEBUG_FW("<< :\n");
  2084. current_cb_address = ipw_read_reg32(priv, IPW_DMA_I_CURRENT_CB);
  2085. current_cb_index = (current_cb_address - IPW_SHARED_SRAM_DMA_CONTROL) /
  2086. sizeof(struct command_block);
  2087. IPW_DEBUG_FW_INFO("Current CB index 0x%x address = 0x%X \n",
  2088. current_cb_index, current_cb_address);
  2089. IPW_DEBUG_FW(">> :\n");
  2090. return current_cb_index;
  2091. }
  2092. static int ipw_fw_dma_add_command_block(struct ipw_priv *priv,
  2093. u32 src_address,
  2094. u32 dest_address,
  2095. u32 length,
  2096. int interrupt_enabled, int is_last)
  2097. {
  2098. u32 control = CB_VALID | CB_SRC_LE | CB_DEST_LE | CB_SRC_AUTOINC |
  2099. CB_SRC_IO_GATED | CB_DEST_AUTOINC | CB_SRC_SIZE_LONG |
  2100. CB_DEST_SIZE_LONG;
  2101. struct command_block *cb;
  2102. u32 last_cb_element = 0;
  2103. IPW_DEBUG_FW_INFO("src_address=0x%x dest_address=0x%x length=0x%x\n",
  2104. src_address, dest_address, length);
  2105. if (priv->sram_desc.last_cb_index >= CB_NUMBER_OF_ELEMENTS_SMALL)
  2106. return -1;
  2107. last_cb_element = priv->sram_desc.last_cb_index;
  2108. cb = &priv->sram_desc.cb_list[last_cb_element];
  2109. priv->sram_desc.last_cb_index++;
  2110. /* Calculate the new CB control word */
  2111. if (interrupt_enabled)
  2112. control |= CB_INT_ENABLED;
  2113. if (is_last)
  2114. control |= CB_LAST_VALID;
  2115. control |= length;
  2116. /* Calculate the CB Element's checksum value */
  2117. cb->status = control ^ src_address ^ dest_address;
  2118. /* Copy the Source and Destination addresses */
  2119. cb->dest_addr = dest_address;
  2120. cb->source_addr = src_address;
  2121. /* Copy the Control Word last */
  2122. cb->control = control;
  2123. return 0;
  2124. }
  2125. static int ipw_fw_dma_add_buffer(struct ipw_priv *priv,
  2126. u32 src_phys, u32 dest_address, u32 length)
  2127. {
  2128. u32 bytes_left = length;
  2129. u32 src_offset = 0;
  2130. u32 dest_offset = 0;
  2131. int status = 0;
  2132. IPW_DEBUG_FW(">> \n");
  2133. IPW_DEBUG_FW_INFO("src_phys=0x%x dest_address=0x%x length=0x%x\n",
  2134. src_phys, dest_address, length);
  2135. while (bytes_left > CB_MAX_LENGTH) {
  2136. status = ipw_fw_dma_add_command_block(priv,
  2137. src_phys + src_offset,
  2138. dest_address +
  2139. dest_offset,
  2140. CB_MAX_LENGTH, 0, 0);
  2141. if (status) {
  2142. IPW_DEBUG_FW_INFO(": Failed\n");
  2143. return -1;
  2144. } else
  2145. IPW_DEBUG_FW_INFO(": Added new cb\n");
  2146. src_offset += CB_MAX_LENGTH;
  2147. dest_offset += CB_MAX_LENGTH;
  2148. bytes_left -= CB_MAX_LENGTH;
  2149. }
  2150. /* add the buffer tail */
  2151. if (bytes_left > 0) {
  2152. status =
  2153. ipw_fw_dma_add_command_block(priv, src_phys + src_offset,
  2154. dest_address + dest_offset,
  2155. bytes_left, 0, 0);
  2156. if (status) {
  2157. IPW_DEBUG_FW_INFO(": Failed on the buffer tail\n");
  2158. return -1;
  2159. } else
  2160. IPW_DEBUG_FW_INFO
  2161. (": Adding new cb - the buffer tail\n");
  2162. }
  2163. IPW_DEBUG_FW("<< \n");
  2164. return 0;
  2165. }
  2166. static int ipw_fw_dma_wait(struct ipw_priv *priv)
  2167. {
  2168. u32 current_index = 0;
  2169. u32 watchdog = 0;
  2170. IPW_DEBUG_FW(">> : \n");
  2171. current_index = ipw_fw_dma_command_block_index(priv);
  2172. IPW_DEBUG_FW_INFO("sram_desc.last_cb_index:0x%8X\n",
  2173. (int)priv->sram_desc.last_cb_index);
  2174. while (current_index < priv->sram_desc.last_cb_index) {
  2175. udelay(50);
  2176. current_index = ipw_fw_dma_command_block_index(priv);
  2177. watchdog++;
  2178. if (watchdog > 400) {
  2179. IPW_DEBUG_FW_INFO("Timeout\n");
  2180. ipw_fw_dma_dump_command_block(priv);
  2181. ipw_fw_dma_abort(priv);
  2182. return -1;
  2183. }
  2184. }
  2185. ipw_fw_dma_abort(priv);
  2186. /*Disable the DMA in the CSR register */
  2187. ipw_set_bit(priv, IPW_RESET_REG,
  2188. IPW_RESET_REG_MASTER_DISABLED | IPW_RESET_REG_STOP_MASTER);
  2189. IPW_DEBUG_FW("<< dmaWaitSync \n");
  2190. return 0;
  2191. }
  2192. static void ipw_remove_current_network(struct ipw_priv *priv)
  2193. {
  2194. struct list_head *element, *safe;
  2195. struct ieee80211_network *network = NULL;
  2196. unsigned long flags;
  2197. spin_lock_irqsave(&priv->ieee->lock, flags);
  2198. list_for_each_safe(element, safe, &priv->ieee->network_list) {
  2199. network = list_entry(element, struct ieee80211_network, list);
  2200. if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
  2201. list_del(element);
  2202. list_add_tail(&network->list,
  2203. &priv->ieee->network_free_list);
  2204. }
  2205. }
  2206. spin_unlock_irqrestore(&priv->ieee->lock, flags);
  2207. }
  2208. /**
  2209. * Check that card is still alive.
  2210. * Reads debug register from domain0.
  2211. * If card is present, pre-defined value should
  2212. * be found there.
  2213. *
  2214. * @param priv
  2215. * @return 1 if card is present, 0 otherwise
  2216. */
  2217. static inline int ipw_alive(struct ipw_priv *priv)
  2218. {
  2219. return ipw_read32(priv, 0x90) == 0xd55555d5;
  2220. }
  2221. static inline int ipw_poll_bit(struct ipw_priv *priv, u32 addr, u32 mask,
  2222. int timeout)
  2223. {
  2224. int i = 0;
  2225. do {
  2226. if ((ipw_read32(priv, addr) & mask) == mask)
  2227. return i;
  2228. mdelay(10);
  2229. i += 10;
  2230. } while (i < timeout);
  2231. return -ETIME;
  2232. }
  2233. /* These functions load the firmware and micro code for the operation of
  2234. * the ipw hardware. It assumes the buffer has all the bits for the
  2235. * image and the caller is handling the memory allocation and clean up.
  2236. */
  2237. static int ipw_stop_master(struct ipw_priv *priv)
  2238. {
  2239. int rc;
  2240. IPW_DEBUG_TRACE(">> \n");
  2241. /* stop master. typical delay - 0 */
  2242. ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
  2243. rc = ipw_poll_bit(priv, IPW_RESET_REG,
  2244. IPW_RESET_REG_MASTER_DISABLED, 100);
  2245. if (rc < 0) {
  2246. IPW_ERROR("stop master failed in 10ms\n");
  2247. return -1;
  2248. }
  2249. IPW_DEBUG_INFO("stop master %dms\n", rc);
  2250. return rc;
  2251. }
  2252. static void ipw_arc_release(struct ipw_priv *priv)
  2253. {
  2254. IPW_DEBUG_TRACE(">> \n");
  2255. mdelay(5);
  2256. ipw_clear_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
  2257. /* no one knows timing, for safety add some delay */
  2258. mdelay(5);
  2259. }
  2260. struct fw_header {
  2261. u32 version;
  2262. u32 mode;
  2263. };
  2264. struct fw_chunk {
  2265. u32 address;
  2266. u32 length;
  2267. };
  2268. #define IPW_FW_MAJOR_VERSION 2
  2269. #define IPW_FW_MINOR_VERSION 3
  2270. #define IPW_FW_MINOR(x) ((x & 0xff) >> 8)
  2271. #define IPW_FW_MAJOR(x) (x & 0xff)
  2272. #define IPW_FW_VERSION ((IPW_FW_MINOR_VERSION << 8) | IPW_FW_MAJOR_VERSION)
  2273. #define IPW_FW_PREFIX "ipw-" __stringify(IPW_FW_MAJOR_VERSION) \
  2274. "." __stringify(IPW_FW_MINOR_VERSION) "-"
  2275. #if IPW_FW_MAJOR_VERSION >= 2 && IPW_FW_MINOR_VERSION > 0
  2276. #define IPW_FW_NAME(x) IPW_FW_PREFIX "" x ".fw"
  2277. #else
  2278. #define IPW_FW_NAME(x) "ipw2200_" x ".fw"
  2279. #endif
  2280. static int ipw_load_ucode(struct ipw_priv *priv, u8 * data, size_t len)
  2281. {
  2282. int rc = 0, i, addr;
  2283. u8 cr = 0;
  2284. u16 *image;
  2285. image = (u16 *) data;
  2286. IPW_DEBUG_TRACE(">> \n");
  2287. rc = ipw_stop_master(priv);
  2288. if (rc < 0)
  2289. return rc;
  2290. // spin_lock_irqsave(&priv->lock, flags);
  2291. for (addr = IPW_SHARED_LOWER_BOUND;
  2292. addr < IPW_REGISTER_DOMAIN1_END; addr += 4) {
  2293. ipw_write32(priv, addr, 0);
  2294. }
  2295. /* no ucode (yet) */
  2296. memset(&priv->dino_alive, 0, sizeof(priv->dino_alive));
  2297. /* destroy DMA queues */
  2298. /* reset sequence */
  2299. ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_ON);
  2300. ipw_arc_release(priv);
  2301. ipw_write_reg32(priv, IPW_MEM_HALT_AND_RESET, IPW_BIT_HALT_RESET_OFF);
  2302. mdelay(1);
  2303. /* reset PHY */
  2304. ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, IPW_BASEBAND_POWER_DOWN);
  2305. mdelay(1);
  2306. ipw_write_reg32(priv, IPW_INTERNAL_CMD_EVENT, 0);
  2307. mdelay(1);
  2308. /* enable ucode store */
  2309. ipw_write_reg8(priv, DINO_CONTROL_REG, 0x0);
  2310. ipw_write_reg8(priv, DINO_CONTROL_REG, DINO_ENABLE_CS);
  2311. mdelay(1);
  2312. /* write ucode */
  2313. /**
  2314. * @bug
  2315. * Do NOT set indirect address register once and then
  2316. * store data to indirect data register in the loop.
  2317. * It seems very reasonable, but in this case DINO do not
  2318. * accept ucode. It is essential to set address each time.
  2319. */
  2320. /* load new ipw uCode */
  2321. for (i = 0; i < len / 2; i++)
  2322. ipw_write_reg16(priv, IPW_BASEBAND_CONTROL_STORE,
  2323. cpu_to_le16(image[i]));
  2324. /* enable DINO */
  2325. ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
  2326. ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, DINO_ENABLE_SYSTEM);
  2327. /* this is where the igx / win driver deveates from the VAP driver. */
  2328. /* wait for alive response */
  2329. for (i = 0; i < 100; i++) {
  2330. /* poll for incoming data */
  2331. cr = ipw_read_reg8(priv, IPW_BASEBAND_CONTROL_STATUS);
  2332. if (cr & DINO_RXFIFO_DATA)
  2333. break;
  2334. mdelay(1);
  2335. }
  2336. if (cr & DINO_RXFIFO_DATA) {
  2337. /* alive_command_responce size is NOT multiple of 4 */
  2338. u32 response_buffer[(sizeof(priv->dino_alive) + 3) / 4];
  2339. for (i = 0; i < ARRAY_SIZE(response_buffer); i++)
  2340. response_buffer[i] =
  2341. le32_to_cpu(ipw_read_reg32(priv,
  2342. IPW_BASEBAND_RX_FIFO_READ));
  2343. memcpy(&priv->dino_alive, response_buffer,
  2344. sizeof(priv->dino_alive));
  2345. if (priv->dino_alive.alive_command == 1
  2346. && priv->dino_alive.ucode_valid == 1) {
  2347. rc = 0;
  2348. IPW_DEBUG_INFO
  2349. ("Microcode OK, rev. %d (0x%x) dev. %d (0x%x) "
  2350. "of %02d/%02d/%02d %02d:%02d\n",
  2351. priv->dino_alive.software_revision,
  2352. priv->dino_alive.software_revision,
  2353. priv->dino_alive.device_identifier,
  2354. priv->dino_alive.device_identifier,
  2355. priv->dino_alive.time_stamp[0],
  2356. priv->dino_alive.time_stamp[1],
  2357. priv->dino_alive.time_stamp[2],
  2358. priv->dino_alive.time_stamp[3],
  2359. priv->dino_alive.time_stamp[4]);
  2360. } else {
  2361. IPW_DEBUG_INFO("Microcode is not alive\n");
  2362. rc = -EINVAL;
  2363. }
  2364. } else {
  2365. IPW_DEBUG_INFO("No alive response from DINO\n");
  2366. rc = -ETIME;
  2367. }
  2368. /* disable DINO, otherwise for some reason
  2369. firmware have problem getting alive resp. */
  2370. ipw_write_reg8(priv, IPW_BASEBAND_CONTROL_STATUS, 0);
  2371. // spin_unlock_irqrestore(&priv->lock, flags);
  2372. return rc;
  2373. }
  2374. static int ipw_load_firmware(struct ipw_priv *priv, u8 * data, size_t len)
  2375. {
  2376. int rc = -1;
  2377. int offset = 0;
  2378. struct fw_chunk *chunk;
  2379. dma_addr_t shared_phys;
  2380. u8 *shared_virt;
  2381. IPW_DEBUG_TRACE("<< : \n");
  2382. shared_virt = pci_alloc_consistent(priv->pci_dev, len, &shared_phys);
  2383. if (!shared_virt)
  2384. return -ENOMEM;
  2385. memmove(shared_virt, data, len);
  2386. /* Start the Dma */
  2387. rc = ipw_fw_dma_enable(priv);
  2388. if (priv->sram_desc.last_cb_index > 0) {
  2389. /* the DMA is already ready this would be a bug. */
  2390. BUG();
  2391. goto out;
  2392. }
  2393. do {
  2394. chunk = (struct fw_chunk *)(data + offset);
  2395. offset += sizeof(struct fw_chunk);
  2396. /* build DMA packet and queue up for sending */
  2397. /* dma to chunk->address, the chunk->length bytes from data +
  2398. * offeset*/
  2399. /* Dma loading */
  2400. rc = ipw_fw_dma_add_buffer(priv, shared_phys + offset,
  2401. le32_to_cpu(chunk->address),
  2402. le32_to_cpu(chunk->length));
  2403. if (rc) {
  2404. IPW_DEBUG_INFO("dmaAddBuffer Failed\n");
  2405. goto out;
  2406. }
  2407. offset += le32_to_cpu(chunk->length);
  2408. } while (offset < len);
  2409. /* Run the DMA and wait for the answer */
  2410. rc = ipw_fw_dma_kick(priv);
  2411. if (rc) {
  2412. IPW_ERROR("dmaKick Failed\n");
  2413. goto out;
  2414. }
  2415. rc = ipw_fw_dma_wait(priv);
  2416. if (rc) {
  2417. IPW_ERROR("dmaWaitSync Failed\n");
  2418. goto out;
  2419. }
  2420. out:
  2421. pci_free_consistent(priv->pci_dev, len, shared_virt, shared_phys);
  2422. return rc;
  2423. }
  2424. /* stop nic */
  2425. static int ipw_stop_nic(struct ipw_priv *priv)
  2426. {
  2427. int rc = 0;
  2428. /* stop */
  2429. ipw_write32(priv, IPW_RESET_REG, IPW_RESET_REG_STOP_MASTER);
  2430. rc = ipw_poll_bit(priv, IPW_RESET_REG,
  2431. IPW_RESET_REG_MASTER_DISABLED, 500);
  2432. if (rc < 0) {
  2433. IPW_ERROR("wait for reg master disabled failed\n");
  2434. return rc;
  2435. }
  2436. ipw_set_bit(priv, IPW_RESET_REG, CBD_RESET_REG_PRINCETON_RESET);
  2437. return rc;
  2438. }
  2439. static void ipw_start_nic(struct ipw_priv *priv)
  2440. {
  2441. IPW_DEBUG_TRACE(">>\n");
  2442. /* prvHwStartNic release ARC */
  2443. ipw_clear_bit(priv, IPW_RESET_REG,
  2444. IPW_RESET_REG_MASTER_DISABLED |
  2445. IPW_RESET_REG_STOP_MASTER |
  2446. CBD_RESET_REG_PRINCETON_RESET);
  2447. /* enable power management */
  2448. ipw_set_bit(priv, IPW_GP_CNTRL_RW,
  2449. IPW_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
  2450. IPW_DEBUG_TRACE("<<\n");
  2451. }
  2452. static int ipw_init_nic(struct ipw_priv *priv)
  2453. {
  2454. int rc;
  2455. IPW_DEBUG_TRACE(">>\n");
  2456. /* reset */
  2457. /*prvHwInitNic */
  2458. /* set "initialization complete" bit to move adapter to D0 state */
  2459. ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
  2460. /* low-level PLL activation */
  2461. ipw_write32(priv, IPW_READ_INT_REGISTER,
  2462. IPW_BIT_INT_HOST_SRAM_READ_INT_REGISTER);
  2463. /* wait for clock stabilization */
  2464. rc = ipw_poll_bit(priv, IPW_GP_CNTRL_RW,
  2465. IPW_GP_CNTRL_BIT_CLOCK_READY, 250);
  2466. if (rc < 0)
  2467. IPW_DEBUG_INFO("FAILED wait for clock stablization\n");
  2468. /* assert SW reset */
  2469. ipw_set_bit(priv, IPW_RESET_REG, IPW_RESET_REG_SW_RESET);
  2470. udelay(10);
  2471. /* set "initialization complete" bit to move adapter to D0 state */
  2472. ipw_set_bit(priv, IPW_GP_CNTRL_RW, IPW_GP_CNTRL_BIT_INIT_DONE);
  2473. IPW_DEBUG_TRACE(">>\n");
  2474. return 0;
  2475. }
  2476. /* Call this function from process context, it will sleep in request_firmware.
  2477. * Probe is an ok place to call this from.
  2478. */
  2479. static int ipw_reset_nic(struct ipw_priv *priv)
  2480. {
  2481. int rc = 0;
  2482. unsigned long flags;
  2483. IPW_DEBUG_TRACE(">>\n");
  2484. rc = ipw_init_nic(priv);
  2485. spin_lock_irqsave(&priv->lock, flags);
  2486. /* Clear the 'host command active' bit... */
  2487. priv->status &= ~STATUS_HCMD_ACTIVE;
  2488. wake_up_interruptible(&priv->wait_command_queue);
  2489. priv->status &= ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
  2490. wake_up_interruptible(&priv->wait_state);
  2491. spin_unlock_irqrestore(&priv->lock, flags);
  2492. IPW_DEBUG_TRACE("<<\n");
  2493. return rc;
  2494. }
  2495. static int ipw_get_fw(struct ipw_priv *priv,
  2496. const struct firmware **fw, const char *name)
  2497. {
  2498. struct fw_header *header;
  2499. int rc;
  2500. /* ask firmware_class module to get the boot firmware off disk */
  2501. rc = request_firmware(fw, name, &priv->pci_dev->dev);
  2502. if (rc < 0) {
  2503. IPW_ERROR("%s load failed: Reason %d\n", name, rc);
  2504. return rc;
  2505. }
  2506. header = (struct fw_header *)(*fw)->data;
  2507. if (IPW_FW_MAJOR(le32_to_cpu(header->version)) != IPW_FW_MAJOR_VERSION) {
  2508. IPW_ERROR("'%s' firmware version not compatible (%d != %d)\n",
  2509. name,
  2510. IPW_FW_MAJOR(le32_to_cpu(header->version)),
  2511. IPW_FW_MAJOR_VERSION);
  2512. return -EINVAL;
  2513. }
  2514. IPW_DEBUG_INFO("Loading firmware '%s' file v%d.%d (%zd bytes)\n",
  2515. name,
  2516. IPW_FW_MAJOR(le32_to_cpu(header->version)),
  2517. IPW_FW_MINOR(le32_to_cpu(header->version)),
  2518. (*fw)->size - sizeof(struct fw_header));
  2519. return 0;
  2520. }
  2521. #define IPW_RX_BUF_SIZE (3000)
  2522. static inline void ipw_rx_queue_reset(struct ipw_priv *priv,
  2523. struct ipw_rx_queue *rxq)
  2524. {
  2525. unsigned long flags;
  2526. int i;
  2527. spin_lock_irqsave(&rxq->lock, flags);
  2528. INIT_LIST_HEAD(&rxq->rx_free);
  2529. INIT_LIST_HEAD(&rxq->rx_used);
  2530. /* Fill the rx_used queue with _all_ of the Rx buffers */
  2531. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++) {
  2532. /* In the reset function, these buffers may have been allocated
  2533. * to an SKB, so we need to unmap and free potential storage */
  2534. if (rxq->pool[i].skb != NULL) {
  2535. pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
  2536. IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  2537. dev_kfree_skb(rxq->pool[i].skb);
  2538. rxq->pool[i].skb = NULL;
  2539. }
  2540. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  2541. }
  2542. /* Set us so that we have processed and used all buffers, but have
  2543. * not restocked the Rx queue with fresh buffers */
  2544. rxq->read = rxq->write = 0;
  2545. rxq->processed = RX_QUEUE_SIZE - 1;
  2546. rxq->free_count = 0;
  2547. spin_unlock_irqrestore(&rxq->lock, flags);
  2548. }
  2549. #ifdef CONFIG_PM
  2550. static int fw_loaded = 0;
  2551. static const struct firmware *bootfw = NULL;
  2552. static const struct firmware *firmware = NULL;
  2553. static const struct firmware *ucode = NULL;
  2554. static void free_firmware(void)
  2555. {
  2556. if (fw_loaded) {
  2557. release_firmware(bootfw);
  2558. release_firmware(ucode);
  2559. release_firmware(firmware);
  2560. bootfw = ucode = firmware = NULL;
  2561. fw_loaded = 0;
  2562. }
  2563. }
  2564. #else
  2565. #define free_firmware() do {} while (0)
  2566. #endif
  2567. static int ipw_load(struct ipw_priv *priv)
  2568. {
  2569. #ifndef CONFIG_PM
  2570. const struct firmware *bootfw = NULL;
  2571. const struct firmware *firmware = NULL;
  2572. const struct firmware *ucode = NULL;
  2573. #endif
  2574. int rc = 0, retries = 3;
  2575. #ifdef CONFIG_PM
  2576. if (!fw_loaded) {
  2577. #endif
  2578. rc = ipw_get_fw(priv, &bootfw, IPW_FW_NAME("boot"));
  2579. if (rc)
  2580. goto error;
  2581. switch (priv->ieee->iw_mode) {
  2582. case IW_MODE_ADHOC:
  2583. rc = ipw_get_fw(priv, &ucode,
  2584. IPW_FW_NAME("ibss_ucode"));
  2585. if (rc)
  2586. goto error;
  2587. rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("ibss"));
  2588. break;
  2589. #ifdef CONFIG_IPW2200_MONITOR
  2590. case IW_MODE_MONITOR:
  2591. rc = ipw_get_fw(priv, &ucode,
  2592. IPW_FW_NAME("sniffer_ucode"));
  2593. if (rc)
  2594. goto error;
  2595. rc = ipw_get_fw(priv, &firmware,
  2596. IPW_FW_NAME("sniffer"));
  2597. break;
  2598. #endif
  2599. case IW_MODE_INFRA:
  2600. rc = ipw_get_fw(priv, &ucode, IPW_FW_NAME("bss_ucode"));
  2601. if (rc)
  2602. goto error;
  2603. rc = ipw_get_fw(priv, &firmware, IPW_FW_NAME("bss"));
  2604. break;
  2605. default:
  2606. rc = -EINVAL;
  2607. }
  2608. if (rc)
  2609. goto error;
  2610. #ifdef CONFIG_PM
  2611. fw_loaded = 1;
  2612. }
  2613. #endif
  2614. if (!priv->rxq)
  2615. priv->rxq = ipw_rx_queue_alloc(priv);
  2616. else
  2617. ipw_rx_queue_reset(priv, priv->rxq);
  2618. if (!priv->rxq) {
  2619. IPW_ERROR("Unable to initialize Rx queue\n");
  2620. goto error;
  2621. }
  2622. retry:
  2623. /* Ensure interrupts are disabled */
  2624. ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
  2625. priv->status &= ~STATUS_INT_ENABLED;
  2626. /* ack pending interrupts */
  2627. ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
  2628. ipw_stop_nic(priv);
  2629. rc = ipw_reset_nic(priv);
  2630. if (rc) {
  2631. IPW_ERROR("Unable to reset NIC\n");
  2632. goto error;
  2633. }
  2634. ipw_zero_memory(priv, IPW_NIC_SRAM_LOWER_BOUND,
  2635. IPW_NIC_SRAM_UPPER_BOUND - IPW_NIC_SRAM_LOWER_BOUND);
  2636. /* DMA the initial boot firmware into the device */
  2637. rc = ipw_load_firmware(priv, bootfw->data + sizeof(struct fw_header),
  2638. bootfw->size - sizeof(struct fw_header));
  2639. if (rc < 0) {
  2640. IPW_ERROR("Unable to load boot firmware\n");
  2641. goto error;
  2642. }
  2643. /* kick start the device */
  2644. ipw_start_nic(priv);
  2645. /* wait for the device to finish it's initial startup sequence */
  2646. rc = ipw_poll_bit(priv, IPW_INTA_RW,
  2647. IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
  2648. if (rc < 0) {
  2649. IPW_ERROR("device failed to boot initial fw image\n");
  2650. goto error;
  2651. }
  2652. IPW_DEBUG_INFO("initial device response after %dms\n", rc);
  2653. /* ack fw init done interrupt */
  2654. ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
  2655. /* DMA the ucode into the device */
  2656. rc = ipw_load_ucode(priv, ucode->data + sizeof(struct fw_header),
  2657. ucode->size - sizeof(struct fw_header));
  2658. if (rc < 0) {
  2659. IPW_ERROR("Unable to load ucode\n");
  2660. goto error;
  2661. }
  2662. /* stop nic */
  2663. ipw_stop_nic(priv);
  2664. /* DMA bss firmware into the device */
  2665. rc = ipw_load_firmware(priv, firmware->data +
  2666. sizeof(struct fw_header),
  2667. firmware->size - sizeof(struct fw_header));
  2668. if (rc < 0) {
  2669. IPW_ERROR("Unable to load firmware\n");
  2670. goto error;
  2671. }
  2672. ipw_write32(priv, IPW_EEPROM_LOAD_DISABLE, 0);
  2673. rc = ipw_queue_reset(priv);
  2674. if (rc) {
  2675. IPW_ERROR("Unable to initialize queues\n");
  2676. goto error;
  2677. }
  2678. /* Ensure interrupts are disabled */
  2679. ipw_write32(priv, IPW_INTA_MASK_R, ~IPW_INTA_MASK_ALL);
  2680. /* ack pending interrupts */
  2681. ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
  2682. /* kick start the device */
  2683. ipw_start_nic(priv);
  2684. if (ipw_read32(priv, IPW_INTA_RW) & IPW_INTA_BIT_PARITY_ERROR) {
  2685. if (retries > 0) {
  2686. IPW_WARNING("Parity error. Retrying init.\n");
  2687. retries--;
  2688. goto retry;
  2689. }
  2690. IPW_ERROR("TODO: Handle parity error -- schedule restart?\n");
  2691. rc = -EIO;
  2692. goto error;
  2693. }
  2694. /* wait for the device */
  2695. rc = ipw_poll_bit(priv, IPW_INTA_RW,
  2696. IPW_INTA_BIT_FW_INITIALIZATION_DONE, 500);
  2697. if (rc < 0) {
  2698. IPW_ERROR("device failed to start after 500ms\n");
  2699. goto error;
  2700. }
  2701. IPW_DEBUG_INFO("device response after %dms\n", rc);
  2702. /* ack fw init done interrupt */
  2703. ipw_write32(priv, IPW_INTA_RW, IPW_INTA_BIT_FW_INITIALIZATION_DONE);
  2704. /* read eeprom data and initialize the eeprom region of sram */
  2705. priv->eeprom_delay = 1;
  2706. ipw_eeprom_init_sram(priv);
  2707. /* enable interrupts */
  2708. ipw_enable_interrupts(priv);
  2709. /* Ensure our queue has valid packets */
  2710. ipw_rx_queue_replenish(priv);
  2711. ipw_write32(priv, IPW_RX_READ_INDEX, priv->rxq->read);
  2712. /* ack pending interrupts */
  2713. ipw_write32(priv, IPW_INTA_RW, IPW_INTA_MASK_ALL);
  2714. #ifndef CONFIG_PM
  2715. release_firmware(bootfw);
  2716. release_firmware(ucode);
  2717. release_firmware(firmware);
  2718. #endif
  2719. return 0;
  2720. error:
  2721. if (priv->rxq) {
  2722. ipw_rx_queue_free(priv, priv->rxq);
  2723. priv->rxq = NULL;
  2724. }
  2725. ipw_tx_queue_free(priv);
  2726. if (bootfw)
  2727. release_firmware(bootfw);
  2728. if (ucode)
  2729. release_firmware(ucode);
  2730. if (firmware)
  2731. release_firmware(firmware);
  2732. #ifdef CONFIG_PM
  2733. fw_loaded = 0;
  2734. bootfw = ucode = firmware = NULL;
  2735. #endif
  2736. return rc;
  2737. }
  2738. /**
  2739. * DMA services
  2740. *
  2741. * Theory of operation
  2742. *
  2743. * A queue is a circular buffers with 'Read' and 'Write' pointers.
  2744. * 2 empty entries always kept in the buffer to protect from overflow.
  2745. *
  2746. * For Tx queue, there are low mark and high mark limits. If, after queuing
  2747. * the packet for Tx, free space become < low mark, Tx queue stopped. When
  2748. * reclaiming packets (on 'tx done IRQ), if free space become > high mark,
  2749. * Tx queue resumed.
  2750. *
  2751. * The IPW operates with six queues, one receive queue in the device's
  2752. * sram, one transmit queue for sending commands to the device firmware,
  2753. * and four transmit queues for data.
  2754. *
  2755. * The four transmit queues allow for performing quality of service (qos)
  2756. * transmissions as per the 802.11 protocol. Currently Linux does not
  2757. * provide a mechanism to the user for utilizing prioritized queues, so
  2758. * we only utilize the first data transmit queue (queue1).
  2759. */
  2760. /**
  2761. * Driver allocates buffers of this size for Rx
  2762. */
  2763. static inline int ipw_queue_space(const struct clx2_queue *q)
  2764. {
  2765. int s = q->last_used - q->first_empty;
  2766. if (s <= 0)
  2767. s += q->n_bd;
  2768. s -= 2; /* keep some reserve to not confuse empty and full situations */
  2769. if (s < 0)
  2770. s = 0;
  2771. return s;
  2772. }
  2773. static inline int ipw_queue_inc_wrap(int index, int n_bd)
  2774. {
  2775. return (++index == n_bd) ? 0 : index;
  2776. }
  2777. /**
  2778. * Initialize common DMA queue structure
  2779. *
  2780. * @param q queue to init
  2781. * @param count Number of BD's to allocate. Should be power of 2
  2782. * @param read_register Address for 'read' register
  2783. * (not offset within BAR, full address)
  2784. * @param write_register Address for 'write' register
  2785. * (not offset within BAR, full address)
  2786. * @param base_register Address for 'base' register
  2787. * (not offset within BAR, full address)
  2788. * @param size Address for 'size' register
  2789. * (not offset within BAR, full address)
  2790. */
  2791. static void ipw_queue_init(struct ipw_priv *priv, struct clx2_queue *q,
  2792. int count, u32 read, u32 write, u32 base, u32 size)
  2793. {
  2794. q->n_bd = count;
  2795. q->low_mark = q->n_bd / 4;
  2796. if (q->low_mark < 4)
  2797. q->low_mark = 4;
  2798. q->high_mark = q->n_bd / 8;
  2799. if (q->high_mark < 2)
  2800. q->high_mark = 2;
  2801. q->first_empty = q->last_used = 0;
  2802. q->reg_r = read;
  2803. q->reg_w = write;
  2804. ipw_write32(priv, base, q->dma_addr);
  2805. ipw_write32(priv, size, count);
  2806. ipw_write32(priv, read, 0);
  2807. ipw_write32(priv, write, 0);
  2808. _ipw_read32(priv, 0x90);
  2809. }
  2810. static int ipw_queue_tx_init(struct ipw_priv *priv,
  2811. struct clx2_tx_queue *q,
  2812. int count, u32 read, u32 write, u32 base, u32 size)
  2813. {
  2814. struct pci_dev *dev = priv->pci_dev;
  2815. q->txb = kmalloc(sizeof(q->txb[0]) * count, GFP_KERNEL);
  2816. if (!q->txb) {
  2817. IPW_ERROR("vmalloc for auxilary BD structures failed\n");
  2818. return -ENOMEM;
  2819. }
  2820. q->bd =
  2821. pci_alloc_consistent(dev, sizeof(q->bd[0]) * count, &q->q.dma_addr);
  2822. if (!q->bd) {
  2823. IPW_ERROR("pci_alloc_consistent(%zd) failed\n",
  2824. sizeof(q->bd[0]) * count);
  2825. kfree(q->txb);
  2826. q->txb = NULL;
  2827. return -ENOMEM;
  2828. }
  2829. ipw_queue_init(priv, &q->q, count, read, write, base, size);
  2830. return 0;
  2831. }
  2832. /**
  2833. * Free one TFD, those at index [txq->q.last_used].
  2834. * Do NOT advance any indexes
  2835. *
  2836. * @param dev
  2837. * @param txq
  2838. */
  2839. static void ipw_queue_tx_free_tfd(struct ipw_priv *priv,
  2840. struct clx2_tx_queue *txq)
  2841. {
  2842. struct tfd_frame *bd = &txq->bd[txq->q.last_used];
  2843. struct pci_dev *dev = priv->pci_dev;
  2844. int i;
  2845. /* classify bd */
  2846. if (bd->control_flags.message_type == TX_HOST_COMMAND_TYPE)
  2847. /* nothing to cleanup after for host commands */
  2848. return;
  2849. /* sanity check */
  2850. if (le32_to_cpu(bd->u.data.num_chunks) > NUM_TFD_CHUNKS) {
  2851. IPW_ERROR("Too many chunks: %i\n",
  2852. le32_to_cpu(bd->u.data.num_chunks));
  2853. /** @todo issue fatal error, it is quite serious situation */
  2854. return;
  2855. }
  2856. /* unmap chunks if any */
  2857. for (i = 0; i < le32_to_cpu(bd->u.data.num_chunks); i++) {
  2858. pci_unmap_single(dev, le32_to_cpu(bd->u.data.chunk_ptr[i]),
  2859. le16_to_cpu(bd->u.data.chunk_len[i]),
  2860. PCI_DMA_TODEVICE);
  2861. if (txq->txb[txq->q.last_used]) {
  2862. ieee80211_txb_free(txq->txb[txq->q.last_used]);
  2863. txq->txb[txq->q.last_used] = NULL;
  2864. }
  2865. }
  2866. }
  2867. /**
  2868. * Deallocate DMA queue.
  2869. *
  2870. * Empty queue by removing and destroying all BD's.
  2871. * Free all buffers.
  2872. *
  2873. * @param dev
  2874. * @param q
  2875. */
  2876. static void ipw_queue_tx_free(struct ipw_priv *priv, struct clx2_tx_queue *txq)
  2877. {
  2878. struct clx2_queue *q = &txq->q;
  2879. struct pci_dev *dev = priv->pci_dev;
  2880. if (q->n_bd == 0)
  2881. return;
  2882. /* first, empty all BD's */
  2883. for (; q->first_empty != q->last_used;
  2884. q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
  2885. ipw_queue_tx_free_tfd(priv, txq);
  2886. }
  2887. /* free buffers belonging to queue itself */
  2888. pci_free_consistent(dev, sizeof(txq->bd[0]) * q->n_bd, txq->bd,
  2889. q->dma_addr);
  2890. kfree(txq->txb);
  2891. /* 0 fill whole structure */
  2892. memset(txq, 0, sizeof(*txq));
  2893. }
  2894. /**
  2895. * Destroy all DMA queues and structures
  2896. *
  2897. * @param priv
  2898. */
  2899. static void ipw_tx_queue_free(struct ipw_priv *priv)
  2900. {
  2901. /* Tx CMD queue */
  2902. ipw_queue_tx_free(priv, &priv->txq_cmd);
  2903. /* Tx queues */
  2904. ipw_queue_tx_free(priv, &priv->txq[0]);
  2905. ipw_queue_tx_free(priv, &priv->txq[1]);
  2906. ipw_queue_tx_free(priv, &priv->txq[2]);
  2907. ipw_queue_tx_free(priv, &priv->txq[3]);
  2908. }
  2909. static inline void ipw_create_bssid(struct ipw_priv *priv, u8 * bssid)
  2910. {
  2911. /* First 3 bytes are manufacturer */
  2912. bssid[0] = priv->mac_addr[0];
  2913. bssid[1] = priv->mac_addr[1];
  2914. bssid[2] = priv->mac_addr[2];
  2915. /* Last bytes are random */
  2916. get_random_bytes(&bssid[3], ETH_ALEN - 3);
  2917. bssid[0] &= 0xfe; /* clear multicast bit */
  2918. bssid[0] |= 0x02; /* set local assignment bit (IEEE802) */
  2919. }
  2920. static inline u8 ipw_add_station(struct ipw_priv *priv, u8 * bssid)
  2921. {
  2922. struct ipw_station_entry entry;
  2923. int i;
  2924. for (i = 0; i < priv->num_stations; i++) {
  2925. if (!memcmp(priv->stations[i], bssid, ETH_ALEN)) {
  2926. /* Another node is active in network */
  2927. priv->missed_adhoc_beacons = 0;
  2928. if (!(priv->config & CFG_STATIC_CHANNEL))
  2929. /* when other nodes drop out, we drop out */
  2930. priv->config &= ~CFG_ADHOC_PERSIST;
  2931. return i;
  2932. }
  2933. }
  2934. if (i == MAX_STATIONS)
  2935. return IPW_INVALID_STATION;
  2936. IPW_DEBUG_SCAN("Adding AdHoc station: " MAC_FMT "\n", MAC_ARG(bssid));
  2937. entry.reserved = 0;
  2938. entry.support_mode = 0;
  2939. memcpy(entry.mac_addr, bssid, ETH_ALEN);
  2940. memcpy(priv->stations[i], bssid, ETH_ALEN);
  2941. ipw_write_direct(priv, IPW_STATION_TABLE_LOWER + i * sizeof(entry),
  2942. &entry, sizeof(entry));
  2943. priv->num_stations++;
  2944. return i;
  2945. }
  2946. static inline u8 ipw_find_station(struct ipw_priv *priv, u8 * bssid)
  2947. {
  2948. int i;
  2949. for (i = 0; i < priv->num_stations; i++)
  2950. if (!memcmp(priv->stations[i], bssid, ETH_ALEN))
  2951. return i;
  2952. return IPW_INVALID_STATION;
  2953. }
  2954. static void ipw_send_disassociate(struct ipw_priv *priv, int quiet)
  2955. {
  2956. int err;
  2957. if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))) {
  2958. IPW_DEBUG_ASSOC("Disassociating while not associated.\n");
  2959. return;
  2960. }
  2961. IPW_DEBUG_ASSOC("Disassocation attempt from " MAC_FMT " "
  2962. "on channel %d.\n",
  2963. MAC_ARG(priv->assoc_request.bssid),
  2964. priv->assoc_request.channel);
  2965. priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
  2966. priv->status |= STATUS_DISASSOCIATING;
  2967. if (quiet)
  2968. priv->assoc_request.assoc_type = HC_DISASSOC_QUIET;
  2969. else
  2970. priv->assoc_request.assoc_type = HC_DISASSOCIATE;
  2971. err = ipw_send_associate(priv, &priv->assoc_request);
  2972. if (err) {
  2973. IPW_DEBUG_HC("Attempt to send [dis]associate command "
  2974. "failed.\n");
  2975. return;
  2976. }
  2977. }
  2978. static int ipw_disassociate(void *data)
  2979. {
  2980. struct ipw_priv *priv = data;
  2981. if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
  2982. return 0;
  2983. ipw_send_disassociate(data, 0);
  2984. return 1;
  2985. }
  2986. static void ipw_bg_disassociate(void *data)
  2987. {
  2988. struct ipw_priv *priv = data;
  2989. down(&priv->sem);
  2990. ipw_disassociate(data);
  2991. up(&priv->sem);
  2992. }
  2993. static void ipw_system_config(void *data)
  2994. {
  2995. struct ipw_priv *priv = data;
  2996. ipw_send_system_config(priv, &priv->sys_config);
  2997. }
  2998. struct ipw_status_code {
  2999. u16 status;
  3000. const char *reason;
  3001. };
  3002. static const struct ipw_status_code ipw_status_codes[] = {
  3003. {0x00, "Successful"},
  3004. {0x01, "Unspecified failure"},
  3005. {0x0A, "Cannot support all requested capabilities in the "
  3006. "Capability information field"},
  3007. {0x0B, "Reassociation denied due to inability to confirm that "
  3008. "association exists"},
  3009. {0x0C, "Association denied due to reason outside the scope of this "
  3010. "standard"},
  3011. {0x0D,
  3012. "Responding station does not support the specified authentication "
  3013. "algorithm"},
  3014. {0x0E,
  3015. "Received an Authentication frame with authentication sequence "
  3016. "transaction sequence number out of expected sequence"},
  3017. {0x0F, "Authentication rejected because of challenge failure"},
  3018. {0x10, "Authentication rejected due to timeout waiting for next "
  3019. "frame in sequence"},
  3020. {0x11, "Association denied because AP is unable to handle additional "
  3021. "associated stations"},
  3022. {0x12,
  3023. "Association denied due to requesting station not supporting all "
  3024. "of the datarates in the BSSBasicServiceSet Parameter"},
  3025. {0x13,
  3026. "Association denied due to requesting station not supporting "
  3027. "short preamble operation"},
  3028. {0x14,
  3029. "Association denied due to requesting station not supporting "
  3030. "PBCC encoding"},
  3031. {0x15,
  3032. "Association denied due to requesting station not supporting "
  3033. "channel agility"},
  3034. {0x19,
  3035. "Association denied due to requesting station not supporting "
  3036. "short slot operation"},
  3037. {0x1A,
  3038. "Association denied due to requesting station not supporting "
  3039. "DSSS-OFDM operation"},
  3040. {0x28, "Invalid Information Element"},
  3041. {0x29, "Group Cipher is not valid"},
  3042. {0x2A, "Pairwise Cipher is not valid"},
  3043. {0x2B, "AKMP is not valid"},
  3044. {0x2C, "Unsupported RSN IE version"},
  3045. {0x2D, "Invalid RSN IE Capabilities"},
  3046. {0x2E, "Cipher suite is rejected per security policy"},
  3047. };
  3048. #ifdef CONFIG_IPW_DEBUG
  3049. static const char *ipw_get_status_code(u16 status)
  3050. {
  3051. int i;
  3052. for (i = 0; i < ARRAY_SIZE(ipw_status_codes); i++)
  3053. if (ipw_status_codes[i].status == (status & 0xff))
  3054. return ipw_status_codes[i].reason;
  3055. return "Unknown status value.";
  3056. }
  3057. #endif
  3058. static void inline average_init(struct average *avg)
  3059. {
  3060. memset(avg, 0, sizeof(*avg));
  3061. }
  3062. static void inline average_add(struct average *avg, s16 val)
  3063. {
  3064. avg->sum -= avg->entries[avg->pos];
  3065. avg->sum += val;
  3066. avg->entries[avg->pos++] = val;
  3067. if (unlikely(avg->pos == AVG_ENTRIES)) {
  3068. avg->init = 1;
  3069. avg->pos = 0;
  3070. }
  3071. }
  3072. static s16 inline average_value(struct average *avg)
  3073. {
  3074. if (!unlikely(avg->init)) {
  3075. if (avg->pos)
  3076. return avg->sum / avg->pos;
  3077. return 0;
  3078. }
  3079. return avg->sum / AVG_ENTRIES;
  3080. }
  3081. static void ipw_reset_stats(struct ipw_priv *priv)
  3082. {
  3083. u32 len = sizeof(u32);
  3084. priv->quality = 0;
  3085. average_init(&priv->average_missed_beacons);
  3086. average_init(&priv->average_rssi);
  3087. average_init(&priv->average_noise);
  3088. priv->last_rate = 0;
  3089. priv->last_missed_beacons = 0;
  3090. priv->last_rx_packets = 0;
  3091. priv->last_tx_packets = 0;
  3092. priv->last_tx_failures = 0;
  3093. /* Firmware managed, reset only when NIC is restarted, so we have to
  3094. * normalize on the current value */
  3095. ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC,
  3096. &priv->last_rx_err, &len);
  3097. ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE,
  3098. &priv->last_tx_failures, &len);
  3099. /* Driver managed, reset with each association */
  3100. priv->missed_adhoc_beacons = 0;
  3101. priv->missed_beacons = 0;
  3102. priv->tx_packets = 0;
  3103. priv->rx_packets = 0;
  3104. }
  3105. static inline u32 ipw_get_max_rate(struct ipw_priv *priv)
  3106. {
  3107. u32 i = 0x80000000;
  3108. u32 mask = priv->rates_mask;
  3109. /* If currently associated in B mode, restrict the maximum
  3110. * rate match to B rates */
  3111. if (priv->assoc_request.ieee_mode == IPW_B_MODE)
  3112. mask &= IEEE80211_CCK_RATES_MASK;
  3113. /* TODO: Verify that the rate is supported by the current rates
  3114. * list. */
  3115. while (i && !(mask & i))
  3116. i >>= 1;
  3117. switch (i) {
  3118. case IEEE80211_CCK_RATE_1MB_MASK:
  3119. return 1000000;
  3120. case IEEE80211_CCK_RATE_2MB_MASK:
  3121. return 2000000;
  3122. case IEEE80211_CCK_RATE_5MB_MASK:
  3123. return 5500000;
  3124. case IEEE80211_OFDM_RATE_6MB_MASK:
  3125. return 6000000;
  3126. case IEEE80211_OFDM_RATE_9MB_MASK:
  3127. return 9000000;
  3128. case IEEE80211_CCK_RATE_11MB_MASK:
  3129. return 11000000;
  3130. case IEEE80211_OFDM_RATE_12MB_MASK:
  3131. return 12000000;
  3132. case IEEE80211_OFDM_RATE_18MB_MASK:
  3133. return 18000000;
  3134. case IEEE80211_OFDM_RATE_24MB_MASK:
  3135. return 24000000;
  3136. case IEEE80211_OFDM_RATE_36MB_MASK:
  3137. return 36000000;
  3138. case IEEE80211_OFDM_RATE_48MB_MASK:
  3139. return 48000000;
  3140. case IEEE80211_OFDM_RATE_54MB_MASK:
  3141. return 54000000;
  3142. }
  3143. if (priv->ieee->mode == IEEE_B)
  3144. return 11000000;
  3145. else
  3146. return 54000000;
  3147. }
  3148. static u32 ipw_get_current_rate(struct ipw_priv *priv)
  3149. {
  3150. u32 rate, len = sizeof(rate);
  3151. int err;
  3152. if (!(priv->status & STATUS_ASSOCIATED))
  3153. return 0;
  3154. if (priv->tx_packets > IPW_REAL_RATE_RX_PACKET_THRESHOLD) {
  3155. err = ipw_get_ordinal(priv, IPW_ORD_STAT_TX_CURR_RATE, &rate,
  3156. &len);
  3157. if (err) {
  3158. IPW_DEBUG_INFO("failed querying ordinals.\n");
  3159. return 0;
  3160. }
  3161. } else
  3162. return ipw_get_max_rate(priv);
  3163. switch (rate) {
  3164. case IPW_TX_RATE_1MB:
  3165. return 1000000;
  3166. case IPW_TX_RATE_2MB:
  3167. return 2000000;
  3168. case IPW_TX_RATE_5MB:
  3169. return 5500000;
  3170. case IPW_TX_RATE_6MB:
  3171. return 6000000;
  3172. case IPW_TX_RATE_9MB:
  3173. return 9000000;
  3174. case IPW_TX_RATE_11MB:
  3175. return 11000000;
  3176. case IPW_TX_RATE_12MB:
  3177. return 12000000;
  3178. case IPW_TX_RATE_18MB:
  3179. return 18000000;
  3180. case IPW_TX_RATE_24MB:
  3181. return 24000000;
  3182. case IPW_TX_RATE_36MB:
  3183. return 36000000;
  3184. case IPW_TX_RATE_48MB:
  3185. return 48000000;
  3186. case IPW_TX_RATE_54MB:
  3187. return 54000000;
  3188. }
  3189. return 0;
  3190. }
  3191. #define IPW_STATS_INTERVAL (2 * HZ)
  3192. static void ipw_gather_stats(struct ipw_priv *priv)
  3193. {
  3194. u32 rx_err, rx_err_delta, rx_packets_delta;
  3195. u32 tx_failures, tx_failures_delta, tx_packets_delta;
  3196. u32 missed_beacons_percent, missed_beacons_delta;
  3197. u32 quality = 0;
  3198. u32 len = sizeof(u32);
  3199. s16 rssi;
  3200. u32 beacon_quality, signal_quality, tx_quality, rx_quality,
  3201. rate_quality;
  3202. u32 max_rate;
  3203. if (!(priv->status & STATUS_ASSOCIATED)) {
  3204. priv->quality = 0;
  3205. return;
  3206. }
  3207. /* Update the statistics */
  3208. ipw_get_ordinal(priv, IPW_ORD_STAT_MISSED_BEACONS,
  3209. &priv->missed_beacons, &len);
  3210. missed_beacons_delta = priv->missed_beacons - priv->last_missed_beacons;
  3211. priv->last_missed_beacons = priv->missed_beacons;
  3212. if (priv->assoc_request.beacon_interval) {
  3213. missed_beacons_percent = missed_beacons_delta *
  3214. (HZ * priv->assoc_request.beacon_interval) /
  3215. (IPW_STATS_INTERVAL * 10);
  3216. } else {
  3217. missed_beacons_percent = 0;
  3218. }
  3219. average_add(&priv->average_missed_beacons, missed_beacons_percent);
  3220. ipw_get_ordinal(priv, IPW_ORD_STAT_RX_ERR_CRC, &rx_err, &len);
  3221. rx_err_delta = rx_err - priv->last_rx_err;
  3222. priv->last_rx_err = rx_err;
  3223. ipw_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURE, &tx_failures, &len);
  3224. tx_failures_delta = tx_failures - priv->last_tx_failures;
  3225. priv->last_tx_failures = tx_failures;
  3226. rx_packets_delta = priv->rx_packets - priv->last_rx_packets;
  3227. priv->last_rx_packets = priv->rx_packets;
  3228. tx_packets_delta = priv->tx_packets - priv->last_tx_packets;
  3229. priv->last_tx_packets = priv->tx_packets;
  3230. /* Calculate quality based on the following:
  3231. *
  3232. * Missed beacon: 100% = 0, 0% = 70% missed
  3233. * Rate: 60% = 1Mbs, 100% = Max
  3234. * Rx and Tx errors represent a straight % of total Rx/Tx
  3235. * RSSI: 100% = > -50, 0% = < -80
  3236. * Rx errors: 100% = 0, 0% = 50% missed
  3237. *
  3238. * The lowest computed quality is used.
  3239. *
  3240. */
  3241. #define BEACON_THRESHOLD 5
  3242. beacon_quality = 100 - missed_beacons_percent;
  3243. if (beacon_quality < BEACON_THRESHOLD)
  3244. beacon_quality = 0;
  3245. else
  3246. beacon_quality = (beacon_quality - BEACON_THRESHOLD) * 100 /
  3247. (100 - BEACON_THRESHOLD);
  3248. IPW_DEBUG_STATS("Missed beacon: %3d%% (%d%%)\n",
  3249. beacon_quality, missed_beacons_percent);
  3250. priv->last_rate = ipw_get_current_rate(priv);
  3251. max_rate = ipw_get_max_rate(priv);
  3252. rate_quality = priv->last_rate * 40 / max_rate + 60;
  3253. IPW_DEBUG_STATS("Rate quality : %3d%% (%dMbs)\n",
  3254. rate_quality, priv->last_rate / 1000000);
  3255. if (rx_packets_delta > 100 && rx_packets_delta + rx_err_delta)
  3256. rx_quality = 100 - (rx_err_delta * 100) /
  3257. (rx_packets_delta + rx_err_delta);
  3258. else
  3259. rx_quality = 100;
  3260. IPW_DEBUG_STATS("Rx quality : %3d%% (%u errors, %u packets)\n",
  3261. rx_quality, rx_err_delta, rx_packets_delta);
  3262. if (tx_packets_delta > 100 && tx_packets_delta + tx_failures_delta)
  3263. tx_quality = 100 - (tx_failures_delta * 100) /
  3264. (tx_packets_delta + tx_failures_delta);
  3265. else
  3266. tx_quality = 100;
  3267. IPW_DEBUG_STATS("Tx quality : %3d%% (%u errors, %u packets)\n",
  3268. tx_quality, tx_failures_delta, tx_packets_delta);
  3269. rssi = average_value(&priv->average_rssi);
  3270. signal_quality =
  3271. (100 *
  3272. (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
  3273. (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) -
  3274. (priv->ieee->perfect_rssi - rssi) *
  3275. (15 * (priv->ieee->perfect_rssi - priv->ieee->worst_rssi) +
  3276. 62 * (priv->ieee->perfect_rssi - rssi))) /
  3277. ((priv->ieee->perfect_rssi - priv->ieee->worst_rssi) *
  3278. (priv->ieee->perfect_rssi - priv->ieee->worst_rssi));
  3279. if (signal_quality > 100)
  3280. signal_quality = 100;
  3281. else if (signal_quality < 1)
  3282. signal_quality = 0;
  3283. IPW_DEBUG_STATS("Signal level : %3d%% (%d dBm)\n",
  3284. signal_quality, rssi);
  3285. quality = min(beacon_quality,
  3286. min(rate_quality,
  3287. min(tx_quality, min(rx_quality, signal_quality))));
  3288. if (quality == beacon_quality)
  3289. IPW_DEBUG_STATS("Quality (%d%%): Clamped to missed beacons.\n",
  3290. quality);
  3291. if (quality == rate_quality)
  3292. IPW_DEBUG_STATS("Quality (%d%%): Clamped to rate quality.\n",
  3293. quality);
  3294. if (quality == tx_quality)
  3295. IPW_DEBUG_STATS("Quality (%d%%): Clamped to Tx quality.\n",
  3296. quality);
  3297. if (quality == rx_quality)
  3298. IPW_DEBUG_STATS("Quality (%d%%): Clamped to Rx quality.\n",
  3299. quality);
  3300. if (quality == signal_quality)
  3301. IPW_DEBUG_STATS("Quality (%d%%): Clamped to signal quality.\n",
  3302. quality);
  3303. priv->quality = quality;
  3304. queue_delayed_work(priv->workqueue, &priv->gather_stats,
  3305. IPW_STATS_INTERVAL);
  3306. }
  3307. static void ipw_bg_gather_stats(void *data)
  3308. {
  3309. struct ipw_priv *priv = data;
  3310. down(&priv->sem);
  3311. ipw_gather_stats(data);
  3312. up(&priv->sem);
  3313. }
  3314. static inline void ipw_handle_missed_beacon(struct ipw_priv *priv,
  3315. int missed_count)
  3316. {
  3317. priv->notif_missed_beacons = missed_count;
  3318. if (missed_count > priv->disassociate_threshold &&
  3319. priv->status & STATUS_ASSOCIATED) {
  3320. /* If associated and we've hit the missed
  3321. * beacon threshold, disassociate, turn
  3322. * off roaming, and abort any active scans */
  3323. IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
  3324. IPW_DL_STATE | IPW_DL_ASSOC,
  3325. "Missed beacon: %d - disassociate\n", missed_count);
  3326. priv->status &= ~STATUS_ROAMING;
  3327. if (priv->status & STATUS_SCANNING) {
  3328. IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
  3329. IPW_DL_STATE,
  3330. "Aborting scan with missed beacon.\n");
  3331. queue_work(priv->workqueue, &priv->abort_scan);
  3332. }
  3333. queue_work(priv->workqueue, &priv->disassociate);
  3334. return;
  3335. }
  3336. if (priv->status & STATUS_ROAMING) {
  3337. /* If we are currently roaming, then just
  3338. * print a debug statement... */
  3339. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
  3340. "Missed beacon: %d - roam in progress\n",
  3341. missed_count);
  3342. return;
  3343. }
  3344. if (missed_count > priv->roaming_threshold) {
  3345. /* If we are not already roaming, set the ROAM
  3346. * bit in the status and kick off a scan */
  3347. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
  3348. "Missed beacon: %d - initiate "
  3349. "roaming\n", missed_count);
  3350. if (!(priv->status & STATUS_ROAMING)) {
  3351. priv->status |= STATUS_ROAMING;
  3352. if (!(priv->status & STATUS_SCANNING))
  3353. queue_work(priv->workqueue,
  3354. &priv->request_scan);
  3355. }
  3356. return;
  3357. }
  3358. if (priv->status & STATUS_SCANNING) {
  3359. /* Stop scan to keep fw from getting
  3360. * stuck (only if we aren't roaming --
  3361. * otherwise we'll never scan more than 2 or 3
  3362. * channels..) */
  3363. IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF | IPW_DL_STATE,
  3364. "Aborting scan with missed beacon.\n");
  3365. queue_work(priv->workqueue, &priv->abort_scan);
  3366. }
  3367. IPW_DEBUG_NOTIF("Missed beacon: %d\n", missed_count);
  3368. }
  3369. /**
  3370. * Handle host notification packet.
  3371. * Called from interrupt routine
  3372. */
  3373. static inline void ipw_rx_notification(struct ipw_priv *priv,
  3374. struct ipw_rx_notification *notif)
  3375. {
  3376. notif->size = le16_to_cpu(notif->size);
  3377. IPW_DEBUG_NOTIF("type = %i (%d bytes)\n", notif->subtype, notif->size);
  3378. switch (notif->subtype) {
  3379. case HOST_NOTIFICATION_STATUS_ASSOCIATED:{
  3380. struct notif_association *assoc = &notif->u.assoc;
  3381. switch (assoc->state) {
  3382. case CMAS_ASSOCIATED:{
  3383. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3384. IPW_DL_ASSOC,
  3385. "associated: '%s' " MAC_FMT
  3386. " \n",
  3387. escape_essid(priv->essid,
  3388. priv->essid_len),
  3389. MAC_ARG(priv->bssid));
  3390. switch (priv->ieee->iw_mode) {
  3391. case IW_MODE_INFRA:
  3392. memcpy(priv->ieee->bssid,
  3393. priv->bssid, ETH_ALEN);
  3394. break;
  3395. case IW_MODE_ADHOC:
  3396. memcpy(priv->ieee->bssid,
  3397. priv->bssid, ETH_ALEN);
  3398. /* clear out the station table */
  3399. priv->num_stations = 0;
  3400. IPW_DEBUG_ASSOC
  3401. ("queueing adhoc check\n");
  3402. queue_delayed_work(priv->
  3403. workqueue,
  3404. &priv->
  3405. adhoc_check,
  3406. priv->
  3407. assoc_request.
  3408. beacon_interval);
  3409. break;
  3410. }
  3411. priv->status &= ~STATUS_ASSOCIATING;
  3412. priv->status |= STATUS_ASSOCIATED;
  3413. queue_work(priv->workqueue,
  3414. &priv->system_config);
  3415. #ifdef CONFIG_IPW_QOS
  3416. #define IPW_GET_PACKET_STYPE(x) WLAN_FC_GET_STYPE( \
  3417. le16_to_cpu(((struct ieee80211_hdr *)(x))->frame_ctl))
  3418. if ((priv->status & STATUS_AUTH) &&
  3419. (IPW_GET_PACKET_STYPE(&notif->u.raw)
  3420. == IEEE80211_STYPE_ASSOC_RESP)) {
  3421. if ((sizeof
  3422. (struct
  3423. ieee80211_assoc_response)
  3424. <= notif->size)
  3425. && (notif->size <= 2314)) {
  3426. struct
  3427. ieee80211_rx_stats
  3428. stats = {
  3429. .len =
  3430. notif->
  3431. size - 1,
  3432. };
  3433. IPW_DEBUG_QOS
  3434. ("QoS Associate "
  3435. "size %d\n",
  3436. notif->size);
  3437. ieee80211_rx_mgt(priv->
  3438. ieee,
  3439. (struct
  3440. ieee80211_hdr_4addr
  3441. *)
  3442. &notif->u.raw, &stats);
  3443. }
  3444. }
  3445. #endif
  3446. schedule_work(&priv->link_up);
  3447. break;
  3448. }
  3449. case CMAS_AUTHENTICATED:{
  3450. if (priv->
  3451. status & (STATUS_ASSOCIATED |
  3452. STATUS_AUTH)) {
  3453. #ifdef CONFIG_IPW_DEBUG
  3454. struct notif_authenticate *auth
  3455. = &notif->u.auth;
  3456. IPW_DEBUG(IPW_DL_NOTIF |
  3457. IPW_DL_STATE |
  3458. IPW_DL_ASSOC,
  3459. "deauthenticated: '%s' "
  3460. MAC_FMT
  3461. ": (0x%04X) - %s \n",
  3462. escape_essid(priv->
  3463. essid,
  3464. priv->
  3465. essid_len),
  3466. MAC_ARG(priv->bssid),
  3467. ntohs(auth->status),
  3468. ipw_get_status_code
  3469. (ntohs
  3470. (auth->status)));
  3471. #endif
  3472. priv->status &=
  3473. ~(STATUS_ASSOCIATING |
  3474. STATUS_AUTH |
  3475. STATUS_ASSOCIATED);
  3476. schedule_work(&priv->link_down);
  3477. break;
  3478. }
  3479. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3480. IPW_DL_ASSOC,
  3481. "authenticated: '%s' " MAC_FMT
  3482. "\n",
  3483. escape_essid(priv->essid,
  3484. priv->essid_len),
  3485. MAC_ARG(priv->bssid));
  3486. break;
  3487. }
  3488. case CMAS_INIT:{
  3489. if (priv->status & STATUS_AUTH) {
  3490. struct
  3491. ieee80211_assoc_response
  3492. *resp;
  3493. resp =
  3494. (struct
  3495. ieee80211_assoc_response
  3496. *)&notif->u.raw;
  3497. IPW_DEBUG(IPW_DL_NOTIF |
  3498. IPW_DL_STATE |
  3499. IPW_DL_ASSOC,
  3500. "association failed (0x%04X): %s\n",
  3501. ntohs(resp->status),
  3502. ipw_get_status_code
  3503. (ntohs
  3504. (resp->status)));
  3505. }
  3506. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3507. IPW_DL_ASSOC,
  3508. "disassociated: '%s' " MAC_FMT
  3509. " \n",
  3510. escape_essid(priv->essid,
  3511. priv->essid_len),
  3512. MAC_ARG(priv->bssid));
  3513. priv->status &=
  3514. ~(STATUS_DISASSOCIATING |
  3515. STATUS_ASSOCIATING |
  3516. STATUS_ASSOCIATED | STATUS_AUTH);
  3517. if (priv->assoc_network
  3518. && (priv->assoc_network->
  3519. capability &
  3520. WLAN_CAPABILITY_IBSS))
  3521. ipw_remove_current_network
  3522. (priv);
  3523. schedule_work(&priv->link_down);
  3524. break;
  3525. }
  3526. case CMAS_RX_ASSOC_RESP:
  3527. break;
  3528. default:
  3529. IPW_ERROR("assoc: unknown (%d)\n",
  3530. assoc->state);
  3531. break;
  3532. }
  3533. break;
  3534. }
  3535. case HOST_NOTIFICATION_STATUS_AUTHENTICATE:{
  3536. struct notif_authenticate *auth = &notif->u.auth;
  3537. switch (auth->state) {
  3538. case CMAS_AUTHENTICATED:
  3539. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
  3540. "authenticated: '%s' " MAC_FMT " \n",
  3541. escape_essid(priv->essid,
  3542. priv->essid_len),
  3543. MAC_ARG(priv->bssid));
  3544. priv->status |= STATUS_AUTH;
  3545. break;
  3546. case CMAS_INIT:
  3547. if (priv->status & STATUS_AUTH) {
  3548. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3549. IPW_DL_ASSOC,
  3550. "authentication failed (0x%04X): %s\n",
  3551. ntohs(auth->status),
  3552. ipw_get_status_code(ntohs
  3553. (auth->
  3554. status)));
  3555. }
  3556. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3557. IPW_DL_ASSOC,
  3558. "deauthenticated: '%s' " MAC_FMT "\n",
  3559. escape_essid(priv->essid,
  3560. priv->essid_len),
  3561. MAC_ARG(priv->bssid));
  3562. priv->status &= ~(STATUS_ASSOCIATING |
  3563. STATUS_AUTH |
  3564. STATUS_ASSOCIATED);
  3565. schedule_work(&priv->link_down);
  3566. break;
  3567. case CMAS_TX_AUTH_SEQ_1:
  3568. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3569. IPW_DL_ASSOC, "AUTH_SEQ_1\n");
  3570. break;
  3571. case CMAS_RX_AUTH_SEQ_2:
  3572. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3573. IPW_DL_ASSOC, "AUTH_SEQ_2\n");
  3574. break;
  3575. case CMAS_AUTH_SEQ_1_PASS:
  3576. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3577. IPW_DL_ASSOC, "AUTH_SEQ_1_PASS\n");
  3578. break;
  3579. case CMAS_AUTH_SEQ_1_FAIL:
  3580. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3581. IPW_DL_ASSOC, "AUTH_SEQ_1_FAIL\n");
  3582. break;
  3583. case CMAS_TX_AUTH_SEQ_3:
  3584. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3585. IPW_DL_ASSOC, "AUTH_SEQ_3\n");
  3586. break;
  3587. case CMAS_RX_AUTH_SEQ_4:
  3588. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3589. IPW_DL_ASSOC, "RX_AUTH_SEQ_4\n");
  3590. break;
  3591. case CMAS_AUTH_SEQ_2_PASS:
  3592. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3593. IPW_DL_ASSOC, "AUTH_SEQ_2_PASS\n");
  3594. break;
  3595. case CMAS_AUTH_SEQ_2_FAIL:
  3596. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3597. IPW_DL_ASSOC, "AUT_SEQ_2_FAIL\n");
  3598. break;
  3599. case CMAS_TX_ASSOC:
  3600. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3601. IPW_DL_ASSOC, "TX_ASSOC\n");
  3602. break;
  3603. case CMAS_RX_ASSOC_RESP:
  3604. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3605. IPW_DL_ASSOC, "RX_ASSOC_RESP\n");
  3606. break;
  3607. case CMAS_ASSOCIATED:
  3608. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE |
  3609. IPW_DL_ASSOC, "ASSOCIATED\n");
  3610. break;
  3611. default:
  3612. IPW_DEBUG_NOTIF("auth: failure - %d\n",
  3613. auth->state);
  3614. break;
  3615. }
  3616. break;
  3617. }
  3618. case HOST_NOTIFICATION_STATUS_SCAN_CHANNEL_RESULT:{
  3619. struct notif_channel_result *x =
  3620. &notif->u.channel_result;
  3621. if (notif->size == sizeof(*x)) {
  3622. IPW_DEBUG_SCAN("Scan result for channel %d\n",
  3623. x->channel_num);
  3624. } else {
  3625. IPW_DEBUG_SCAN("Scan result of wrong size %d "
  3626. "(should be %zd)\n",
  3627. notif->size, sizeof(*x));
  3628. }
  3629. break;
  3630. }
  3631. case HOST_NOTIFICATION_STATUS_SCAN_COMPLETED:{
  3632. struct notif_scan_complete *x = &notif->u.scan_complete;
  3633. if (notif->size == sizeof(*x)) {
  3634. IPW_DEBUG_SCAN
  3635. ("Scan completed: type %d, %d channels, "
  3636. "%d status\n", x->scan_type,
  3637. x->num_channels, x->status);
  3638. } else {
  3639. IPW_ERROR("Scan completed of wrong size %d "
  3640. "(should be %zd)\n",
  3641. notif->size, sizeof(*x));
  3642. }
  3643. priv->status &=
  3644. ~(STATUS_SCANNING | STATUS_SCAN_ABORTING);
  3645. cancel_delayed_work(&priv->scan_check);
  3646. if (priv->status & STATUS_EXIT_PENDING)
  3647. break;
  3648. priv->ieee->scans++;
  3649. #ifdef CONFIG_IPW2200_MONITOR
  3650. if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
  3651. priv->status |= STATUS_SCAN_FORCED;
  3652. queue_work(priv->workqueue,
  3653. &priv->request_scan);
  3654. break;
  3655. }
  3656. priv->status &= ~STATUS_SCAN_FORCED;
  3657. #endif /* CONFIG_IPW2200_MONITOR */
  3658. if (!(priv->status & (STATUS_ASSOCIATED |
  3659. STATUS_ASSOCIATING |
  3660. STATUS_ROAMING |
  3661. STATUS_DISASSOCIATING)))
  3662. queue_work(priv->workqueue, &priv->associate);
  3663. else if (priv->status & STATUS_ROAMING) {
  3664. /* If a scan completed and we are in roam mode, then
  3665. * the scan that completed was the one requested as a
  3666. * result of entering roam... so, schedule the
  3667. * roam work */
  3668. queue_work(priv->workqueue, &priv->roam);
  3669. } else if (priv->status & STATUS_SCAN_PENDING)
  3670. queue_work(priv->workqueue,
  3671. &priv->request_scan);
  3672. else if (priv->config & CFG_BACKGROUND_SCAN
  3673. && priv->status & STATUS_ASSOCIATED)
  3674. queue_delayed_work(priv->workqueue,
  3675. &priv->request_scan, HZ);
  3676. break;
  3677. }
  3678. case HOST_NOTIFICATION_STATUS_FRAG_LENGTH:{
  3679. struct notif_frag_length *x = &notif->u.frag_len;
  3680. if (notif->size == sizeof(*x))
  3681. IPW_ERROR("Frag length: %d\n",
  3682. le16_to_cpu(x->frag_length));
  3683. else
  3684. IPW_ERROR("Frag length of wrong size %d "
  3685. "(should be %zd)\n",
  3686. notif->size, sizeof(*x));
  3687. break;
  3688. }
  3689. case HOST_NOTIFICATION_STATUS_LINK_DETERIORATION:{
  3690. struct notif_link_deterioration *x =
  3691. &notif->u.link_deterioration;
  3692. if (notif->size == sizeof(*x)) {
  3693. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE,
  3694. "link deterioration: '%s' " MAC_FMT
  3695. " \n", escape_essid(priv->essid,
  3696. priv->essid_len),
  3697. MAC_ARG(priv->bssid));
  3698. memcpy(&priv->last_link_deterioration, x,
  3699. sizeof(*x));
  3700. } else {
  3701. IPW_ERROR("Link Deterioration of wrong size %d "
  3702. "(should be %zd)\n",
  3703. notif->size, sizeof(*x));
  3704. }
  3705. break;
  3706. }
  3707. case HOST_NOTIFICATION_DINO_CONFIG_RESPONSE:{
  3708. IPW_ERROR("Dino config\n");
  3709. if (priv->hcmd
  3710. && priv->hcmd->cmd != HOST_CMD_DINO_CONFIG)
  3711. IPW_ERROR("Unexpected DINO_CONFIG_RESPONSE\n");
  3712. break;
  3713. }
  3714. case HOST_NOTIFICATION_STATUS_BEACON_STATE:{
  3715. struct notif_beacon_state *x = &notif->u.beacon_state;
  3716. if (notif->size != sizeof(*x)) {
  3717. IPW_ERROR
  3718. ("Beacon state of wrong size %d (should "
  3719. "be %zd)\n", notif->size, sizeof(*x));
  3720. break;
  3721. }
  3722. if (le32_to_cpu(x->state) ==
  3723. HOST_NOTIFICATION_STATUS_BEACON_MISSING)
  3724. ipw_handle_missed_beacon(priv,
  3725. le32_to_cpu(x->
  3726. number));
  3727. break;
  3728. }
  3729. case HOST_NOTIFICATION_STATUS_TGI_TX_KEY:{
  3730. struct notif_tgi_tx_key *x = &notif->u.tgi_tx_key;
  3731. if (notif->size == sizeof(*x)) {
  3732. IPW_ERROR("TGi Tx Key: state 0x%02x sec type "
  3733. "0x%02x station %d\n",
  3734. x->key_state, x->security_type,
  3735. x->station_index);
  3736. break;
  3737. }
  3738. IPW_ERROR
  3739. ("TGi Tx Key of wrong size %d (should be %zd)\n",
  3740. notif->size, sizeof(*x));
  3741. break;
  3742. }
  3743. case HOST_NOTIFICATION_CALIB_KEEP_RESULTS:{
  3744. struct notif_calibration *x = &notif->u.calibration;
  3745. if (notif->size == sizeof(*x)) {
  3746. memcpy(&priv->calib, x, sizeof(*x));
  3747. IPW_DEBUG_INFO("TODO: Calibration\n");
  3748. break;
  3749. }
  3750. IPW_ERROR
  3751. ("Calibration of wrong size %d (should be %zd)\n",
  3752. notif->size, sizeof(*x));
  3753. break;
  3754. }
  3755. case HOST_NOTIFICATION_NOISE_STATS:{
  3756. if (notif->size == sizeof(u32)) {
  3757. priv->last_noise =
  3758. (u8) (le32_to_cpu(notif->u.noise.value) &
  3759. 0xff);
  3760. average_add(&priv->average_noise,
  3761. priv->last_noise);
  3762. break;
  3763. }
  3764. IPW_ERROR
  3765. ("Noise stat is wrong size %d (should be %zd)\n",
  3766. notif->size, sizeof(u32));
  3767. break;
  3768. }
  3769. default:
  3770. IPW_ERROR("Unknown notification: "
  3771. "subtype=%d,flags=0x%2x,size=%d\n",
  3772. notif->subtype, notif->flags, notif->size);
  3773. }
  3774. }
  3775. /**
  3776. * Destroys all DMA structures and initialise them again
  3777. *
  3778. * @param priv
  3779. * @return error code
  3780. */
  3781. static int ipw_queue_reset(struct ipw_priv *priv)
  3782. {
  3783. int rc = 0;
  3784. /** @todo customize queue sizes */
  3785. int nTx = 64, nTxCmd = 8;
  3786. ipw_tx_queue_free(priv);
  3787. /* Tx CMD queue */
  3788. rc = ipw_queue_tx_init(priv, &priv->txq_cmd, nTxCmd,
  3789. IPW_TX_CMD_QUEUE_READ_INDEX,
  3790. IPW_TX_CMD_QUEUE_WRITE_INDEX,
  3791. IPW_TX_CMD_QUEUE_BD_BASE,
  3792. IPW_TX_CMD_QUEUE_BD_SIZE);
  3793. if (rc) {
  3794. IPW_ERROR("Tx Cmd queue init failed\n");
  3795. goto error;
  3796. }
  3797. /* Tx queue(s) */
  3798. rc = ipw_queue_tx_init(priv, &priv->txq[0], nTx,
  3799. IPW_TX_QUEUE_0_READ_INDEX,
  3800. IPW_TX_QUEUE_0_WRITE_INDEX,
  3801. IPW_TX_QUEUE_0_BD_BASE, IPW_TX_QUEUE_0_BD_SIZE);
  3802. if (rc) {
  3803. IPW_ERROR("Tx 0 queue init failed\n");
  3804. goto error;
  3805. }
  3806. rc = ipw_queue_tx_init(priv, &priv->txq[1], nTx,
  3807. IPW_TX_QUEUE_1_READ_INDEX,
  3808. IPW_TX_QUEUE_1_WRITE_INDEX,
  3809. IPW_TX_QUEUE_1_BD_BASE, IPW_TX_QUEUE_1_BD_SIZE);
  3810. if (rc) {
  3811. IPW_ERROR("Tx 1 queue init failed\n");
  3812. goto error;
  3813. }
  3814. rc = ipw_queue_tx_init(priv, &priv->txq[2], nTx,
  3815. IPW_TX_QUEUE_2_READ_INDEX,
  3816. IPW_TX_QUEUE_2_WRITE_INDEX,
  3817. IPW_TX_QUEUE_2_BD_BASE, IPW_TX_QUEUE_2_BD_SIZE);
  3818. if (rc) {
  3819. IPW_ERROR("Tx 2 queue init failed\n");
  3820. goto error;
  3821. }
  3822. rc = ipw_queue_tx_init(priv, &priv->txq[3], nTx,
  3823. IPW_TX_QUEUE_3_READ_INDEX,
  3824. IPW_TX_QUEUE_3_WRITE_INDEX,
  3825. IPW_TX_QUEUE_3_BD_BASE, IPW_TX_QUEUE_3_BD_SIZE);
  3826. if (rc) {
  3827. IPW_ERROR("Tx 3 queue init failed\n");
  3828. goto error;
  3829. }
  3830. /* statistics */
  3831. priv->rx_bufs_min = 0;
  3832. priv->rx_pend_max = 0;
  3833. return rc;
  3834. error:
  3835. ipw_tx_queue_free(priv);
  3836. return rc;
  3837. }
  3838. /**
  3839. * Reclaim Tx queue entries no more used by NIC.
  3840. *
  3841. * When FW adwances 'R' index, all entries between old and
  3842. * new 'R' index need to be reclaimed. As result, some free space
  3843. * forms. If there is enough free space (> low mark), wake Tx queue.
  3844. *
  3845. * @note Need to protect against garbage in 'R' index
  3846. * @param priv
  3847. * @param txq
  3848. * @param qindex
  3849. * @return Number of used entries remains in the queue
  3850. */
  3851. static int ipw_queue_tx_reclaim(struct ipw_priv *priv,
  3852. struct clx2_tx_queue *txq, int qindex)
  3853. {
  3854. u32 hw_tail;
  3855. int used;
  3856. struct clx2_queue *q = &txq->q;
  3857. hw_tail = ipw_read32(priv, q->reg_r);
  3858. if (hw_tail >= q->n_bd) {
  3859. IPW_ERROR
  3860. ("Read index for DMA queue (%d) is out of range [0-%d)\n",
  3861. hw_tail, q->n_bd);
  3862. goto done;
  3863. }
  3864. for (; q->last_used != hw_tail;
  3865. q->last_used = ipw_queue_inc_wrap(q->last_used, q->n_bd)) {
  3866. ipw_queue_tx_free_tfd(priv, txq);
  3867. priv->tx_packets++;
  3868. }
  3869. done:
  3870. if ((ipw_queue_space(q) > q->low_mark) &&
  3871. (qindex >= 0) &&
  3872. (priv->status & STATUS_ASSOCIATED) && netif_running(priv->net_dev))
  3873. netif_wake_queue(priv->net_dev);
  3874. used = q->first_empty - q->last_used;
  3875. if (used < 0)
  3876. used += q->n_bd;
  3877. return used;
  3878. }
  3879. static int ipw_queue_tx_hcmd(struct ipw_priv *priv, int hcmd, void *buf,
  3880. int len, int sync)
  3881. {
  3882. struct clx2_tx_queue *txq = &priv->txq_cmd;
  3883. struct clx2_queue *q = &txq->q;
  3884. struct tfd_frame *tfd;
  3885. if (ipw_queue_space(q) < (sync ? 1 : 2)) {
  3886. IPW_ERROR("No space for Tx\n");
  3887. return -EBUSY;
  3888. }
  3889. tfd = &txq->bd[q->first_empty];
  3890. txq->txb[q->first_empty] = NULL;
  3891. memset(tfd, 0, sizeof(*tfd));
  3892. tfd->control_flags.message_type = TX_HOST_COMMAND_TYPE;
  3893. tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
  3894. priv->hcmd_seq++;
  3895. tfd->u.cmd.index = hcmd;
  3896. tfd->u.cmd.length = len;
  3897. memcpy(tfd->u.cmd.payload, buf, len);
  3898. q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
  3899. ipw_write32(priv, q->reg_w, q->first_empty);
  3900. _ipw_read32(priv, 0x90);
  3901. return 0;
  3902. }
  3903. /*
  3904. * Rx theory of operation
  3905. *
  3906. * The host allocates 32 DMA target addresses and passes the host address
  3907. * to the firmware at register IPW_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
  3908. * 0 to 31
  3909. *
  3910. * Rx Queue Indexes
  3911. * The host/firmware share two index registers for managing the Rx buffers.
  3912. *
  3913. * The READ index maps to the first position that the firmware may be writing
  3914. * to -- the driver can read up to (but not including) this position and get
  3915. * good data.
  3916. * The READ index is managed by the firmware once the card is enabled.
  3917. *
  3918. * The WRITE index maps to the last position the driver has read from -- the
  3919. * position preceding WRITE is the last slot the firmware can place a packet.
  3920. *
  3921. * The queue is empty (no good data) if WRITE = READ - 1, and is full if
  3922. * WRITE = READ.
  3923. *
  3924. * During initialization the host sets up the READ queue position to the first
  3925. * INDEX position, and WRITE to the last (READ - 1 wrapped)
  3926. *
  3927. * When the firmware places a packet in a buffer it will advance the READ index
  3928. * and fire the RX interrupt. The driver can then query the READ index and
  3929. * process as many packets as possible, moving the WRITE index forward as it
  3930. * resets the Rx queue buffers with new memory.
  3931. *
  3932. * The management in the driver is as follows:
  3933. * + A list of pre-allocated SKBs is stored in ipw->rxq->rx_free. When
  3934. * ipw->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
  3935. * to replensish the ipw->rxq->rx_free.
  3936. * + In ipw_rx_queue_replenish (scheduled) if 'processed' != 'read' then the
  3937. * ipw->rxq is replenished and the READ INDEX is updated (updating the
  3938. * 'processed' and 'read' driver indexes as well)
  3939. * + A received packet is processed and handed to the kernel network stack,
  3940. * detached from the ipw->rxq. The driver 'processed' index is updated.
  3941. * + The Host/Firmware ipw->rxq is replenished at tasklet time from the rx_free
  3942. * list. If there are no allocated buffers in ipw->rxq->rx_free, the READ
  3943. * INDEX is not incremented and ipw->status(RX_STALLED) is set. If there
  3944. * were enough free buffers and RX_STALLED is set it is cleared.
  3945. *
  3946. *
  3947. * Driver sequence:
  3948. *
  3949. * ipw_rx_queue_alloc() Allocates rx_free
  3950. * ipw_rx_queue_replenish() Replenishes rx_free list from rx_used, and calls
  3951. * ipw_rx_queue_restock
  3952. * ipw_rx_queue_restock() Moves available buffers from rx_free into Rx
  3953. * queue, updates firmware pointers, and updates
  3954. * the WRITE index. If insufficient rx_free buffers
  3955. * are available, schedules ipw_rx_queue_replenish
  3956. *
  3957. * -- enable interrupts --
  3958. * ISR - ipw_rx() Detach ipw_rx_mem_buffers from pool up to the
  3959. * READ INDEX, detaching the SKB from the pool.
  3960. * Moves the packet buffer from queue to rx_used.
  3961. * Calls ipw_rx_queue_restock to refill any empty
  3962. * slots.
  3963. * ...
  3964. *
  3965. */
  3966. /*
  3967. * If there are slots in the RX queue that need to be restocked,
  3968. * and we have free pre-allocated buffers, fill the ranks as much
  3969. * as we can pulling from rx_free.
  3970. *
  3971. * This moves the 'write' index forward to catch up with 'processed', and
  3972. * also updates the memory address in the firmware to reference the new
  3973. * target buffer.
  3974. */
  3975. static void ipw_rx_queue_restock(struct ipw_priv *priv)
  3976. {
  3977. struct ipw_rx_queue *rxq = priv->rxq;
  3978. struct list_head *element;
  3979. struct ipw_rx_mem_buffer *rxb;
  3980. unsigned long flags;
  3981. int write;
  3982. spin_lock_irqsave(&rxq->lock, flags);
  3983. write = rxq->write;
  3984. while ((rxq->write != rxq->processed) && (rxq->free_count)) {
  3985. element = rxq->rx_free.next;
  3986. rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
  3987. list_del(element);
  3988. ipw_write32(priv, IPW_RFDS_TABLE_LOWER + rxq->write * RFD_SIZE,
  3989. rxb->dma_addr);
  3990. rxq->queue[rxq->write] = rxb;
  3991. rxq->write = (rxq->write + 1) % RX_QUEUE_SIZE;
  3992. rxq->free_count--;
  3993. }
  3994. spin_unlock_irqrestore(&rxq->lock, flags);
  3995. /* If the pre-allocated buffer pool is dropping low, schedule to
  3996. * refill it */
  3997. if (rxq->free_count <= RX_LOW_WATERMARK)
  3998. queue_work(priv->workqueue, &priv->rx_replenish);
  3999. /* If we've added more space for the firmware to place data, tell it */
  4000. if (write != rxq->write)
  4001. ipw_write32(priv, IPW_RX_WRITE_INDEX, rxq->write);
  4002. }
  4003. /*
  4004. * Move all used packet from rx_used to rx_free, allocating a new SKB for each.
  4005. * Also restock the Rx queue via ipw_rx_queue_restock.
  4006. *
  4007. * This is called as a scheduled work item (except for during intialization)
  4008. */
  4009. static void ipw_rx_queue_replenish(void *data)
  4010. {
  4011. struct ipw_priv *priv = data;
  4012. struct ipw_rx_queue *rxq = priv->rxq;
  4013. struct list_head *element;
  4014. struct ipw_rx_mem_buffer *rxb;
  4015. unsigned long flags;
  4016. spin_lock_irqsave(&rxq->lock, flags);
  4017. while (!list_empty(&rxq->rx_used)) {
  4018. element = rxq->rx_used.next;
  4019. rxb = list_entry(element, struct ipw_rx_mem_buffer, list);
  4020. rxb->skb = alloc_skb(IPW_RX_BUF_SIZE, GFP_ATOMIC);
  4021. if (!rxb->skb) {
  4022. printk(KERN_CRIT "%s: Can not allocate SKB buffers.\n",
  4023. priv->net_dev->name);
  4024. /* We don't reschedule replenish work here -- we will
  4025. * call the restock method and if it still needs
  4026. * more buffers it will schedule replenish */
  4027. break;
  4028. }
  4029. list_del(element);
  4030. rxb->rxb = (struct ipw_rx_buffer *)rxb->skb->data;
  4031. rxb->dma_addr =
  4032. pci_map_single(priv->pci_dev, rxb->skb->data,
  4033. IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  4034. list_add_tail(&rxb->list, &rxq->rx_free);
  4035. rxq->free_count++;
  4036. }
  4037. spin_unlock_irqrestore(&rxq->lock, flags);
  4038. ipw_rx_queue_restock(priv);
  4039. }
  4040. static void ipw_bg_rx_queue_replenish(void *data)
  4041. {
  4042. struct ipw_priv *priv = data;
  4043. down(&priv->sem);
  4044. ipw_rx_queue_replenish(data);
  4045. up(&priv->sem);
  4046. }
  4047. /* Assumes that the skb field of the buffers in 'pool' is kept accurate.
  4048. * If an SKB has been detached, the POOL needs to have it's SKB set to NULL
  4049. * This free routine walks the list of POOL entries and if SKB is set to
  4050. * non NULL it is unmapped and freed
  4051. */
  4052. static void ipw_rx_queue_free(struct ipw_priv *priv, struct ipw_rx_queue *rxq)
  4053. {
  4054. int i;
  4055. if (!rxq)
  4056. return;
  4057. for (i = 0; i < RX_QUEUE_SIZE + RX_FREE_BUFFERS; i++) {
  4058. if (rxq->pool[i].skb != NULL) {
  4059. pci_unmap_single(priv->pci_dev, rxq->pool[i].dma_addr,
  4060. IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  4061. dev_kfree_skb(rxq->pool[i].skb);
  4062. }
  4063. }
  4064. kfree(rxq);
  4065. }
  4066. static struct ipw_rx_queue *ipw_rx_queue_alloc(struct ipw_priv *priv)
  4067. {
  4068. struct ipw_rx_queue *rxq;
  4069. int i;
  4070. rxq = (struct ipw_rx_queue *)kmalloc(sizeof(*rxq), GFP_KERNEL);
  4071. if (unlikely(!rxq)) {
  4072. IPW_ERROR("memory allocation failed\n");
  4073. return NULL;
  4074. }
  4075. memset(rxq, 0, sizeof(*rxq));
  4076. spin_lock_init(&rxq->lock);
  4077. INIT_LIST_HEAD(&rxq->rx_free);
  4078. INIT_LIST_HEAD(&rxq->rx_used);
  4079. /* Fill the rx_used queue with _all_ of the Rx buffers */
  4080. for (i = 0; i < RX_FREE_BUFFERS + RX_QUEUE_SIZE; i++)
  4081. list_add_tail(&rxq->pool[i].list, &rxq->rx_used);
  4082. /* Set us so that we have processed and used all buffers, but have
  4083. * not restocked the Rx queue with fresh buffers */
  4084. rxq->read = rxq->write = 0;
  4085. rxq->processed = RX_QUEUE_SIZE - 1;
  4086. rxq->free_count = 0;
  4087. return rxq;
  4088. }
  4089. static int ipw_is_rate_in_mask(struct ipw_priv *priv, int ieee_mode, u8 rate)
  4090. {
  4091. rate &= ~IEEE80211_BASIC_RATE_MASK;
  4092. if (ieee_mode == IEEE_A) {
  4093. switch (rate) {
  4094. case IEEE80211_OFDM_RATE_6MB:
  4095. return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ?
  4096. 1 : 0;
  4097. case IEEE80211_OFDM_RATE_9MB:
  4098. return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ?
  4099. 1 : 0;
  4100. case IEEE80211_OFDM_RATE_12MB:
  4101. return priv->
  4102. rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
  4103. case IEEE80211_OFDM_RATE_18MB:
  4104. return priv->
  4105. rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
  4106. case IEEE80211_OFDM_RATE_24MB:
  4107. return priv->
  4108. rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
  4109. case IEEE80211_OFDM_RATE_36MB:
  4110. return priv->
  4111. rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
  4112. case IEEE80211_OFDM_RATE_48MB:
  4113. return priv->
  4114. rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
  4115. case IEEE80211_OFDM_RATE_54MB:
  4116. return priv->
  4117. rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
  4118. default:
  4119. return 0;
  4120. }
  4121. }
  4122. /* B and G mixed */
  4123. switch (rate) {
  4124. case IEEE80211_CCK_RATE_1MB:
  4125. return priv->rates_mask & IEEE80211_CCK_RATE_1MB_MASK ? 1 : 0;
  4126. case IEEE80211_CCK_RATE_2MB:
  4127. return priv->rates_mask & IEEE80211_CCK_RATE_2MB_MASK ? 1 : 0;
  4128. case IEEE80211_CCK_RATE_5MB:
  4129. return priv->rates_mask & IEEE80211_CCK_RATE_5MB_MASK ? 1 : 0;
  4130. case IEEE80211_CCK_RATE_11MB:
  4131. return priv->rates_mask & IEEE80211_CCK_RATE_11MB_MASK ? 1 : 0;
  4132. }
  4133. /* If we are limited to B modulations, bail at this point */
  4134. if (ieee_mode == IEEE_B)
  4135. return 0;
  4136. /* G */
  4137. switch (rate) {
  4138. case IEEE80211_OFDM_RATE_6MB:
  4139. return priv->rates_mask & IEEE80211_OFDM_RATE_6MB_MASK ? 1 : 0;
  4140. case IEEE80211_OFDM_RATE_9MB:
  4141. return priv->rates_mask & IEEE80211_OFDM_RATE_9MB_MASK ? 1 : 0;
  4142. case IEEE80211_OFDM_RATE_12MB:
  4143. return priv->rates_mask & IEEE80211_OFDM_RATE_12MB_MASK ? 1 : 0;
  4144. case IEEE80211_OFDM_RATE_18MB:
  4145. return priv->rates_mask & IEEE80211_OFDM_RATE_18MB_MASK ? 1 : 0;
  4146. case IEEE80211_OFDM_RATE_24MB:
  4147. return priv->rates_mask & IEEE80211_OFDM_RATE_24MB_MASK ? 1 : 0;
  4148. case IEEE80211_OFDM_RATE_36MB:
  4149. return priv->rates_mask & IEEE80211_OFDM_RATE_36MB_MASK ? 1 : 0;
  4150. case IEEE80211_OFDM_RATE_48MB:
  4151. return priv->rates_mask & IEEE80211_OFDM_RATE_48MB_MASK ? 1 : 0;
  4152. case IEEE80211_OFDM_RATE_54MB:
  4153. return priv->rates_mask & IEEE80211_OFDM_RATE_54MB_MASK ? 1 : 0;
  4154. }
  4155. return 0;
  4156. }
  4157. static int ipw_compatible_rates(struct ipw_priv *priv,
  4158. const struct ieee80211_network *network,
  4159. struct ipw_supported_rates *rates)
  4160. {
  4161. int num_rates, i;
  4162. memset(rates, 0, sizeof(*rates));
  4163. num_rates = min(network->rates_len, (u8) IPW_MAX_RATES);
  4164. rates->num_rates = 0;
  4165. for (i = 0; i < num_rates; i++) {
  4166. if (!ipw_is_rate_in_mask(priv, network->mode,
  4167. network->rates[i])) {
  4168. if (network->rates[i] & IEEE80211_BASIC_RATE_MASK) {
  4169. IPW_DEBUG_SCAN("Adding masked mandatory "
  4170. "rate %02X\n",
  4171. network->rates[i]);
  4172. rates->supported_rates[rates->num_rates++] =
  4173. network->rates[i];
  4174. continue;
  4175. }
  4176. IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
  4177. network->rates[i], priv->rates_mask);
  4178. continue;
  4179. }
  4180. rates->supported_rates[rates->num_rates++] = network->rates[i];
  4181. }
  4182. num_rates = min(network->rates_ex_len,
  4183. (u8) (IPW_MAX_RATES - num_rates));
  4184. for (i = 0; i < num_rates; i++) {
  4185. if (!ipw_is_rate_in_mask(priv, network->mode,
  4186. network->rates_ex[i])) {
  4187. if (network->rates_ex[i] & IEEE80211_BASIC_RATE_MASK) {
  4188. IPW_DEBUG_SCAN("Adding masked mandatory "
  4189. "rate %02X\n",
  4190. network->rates_ex[i]);
  4191. rates->supported_rates[rates->num_rates++] =
  4192. network->rates[i];
  4193. continue;
  4194. }
  4195. IPW_DEBUG_SCAN("Rate %02X masked : 0x%08X\n",
  4196. network->rates_ex[i], priv->rates_mask);
  4197. continue;
  4198. }
  4199. rates->supported_rates[rates->num_rates++] =
  4200. network->rates_ex[i];
  4201. }
  4202. return 1;
  4203. }
  4204. static inline void ipw_copy_rates(struct ipw_supported_rates *dest,
  4205. const struct ipw_supported_rates *src)
  4206. {
  4207. u8 i;
  4208. for (i = 0; i < src->num_rates; i++)
  4209. dest->supported_rates[i] = src->supported_rates[i];
  4210. dest->num_rates = src->num_rates;
  4211. }
  4212. /* TODO: Look at sniffed packets in the air to determine if the basic rate
  4213. * mask should ever be used -- right now all callers to add the scan rates are
  4214. * set with the modulation = CCK, so BASIC_RATE_MASK is never set... */
  4215. static void ipw_add_cck_scan_rates(struct ipw_supported_rates *rates,
  4216. u8 modulation, u32 rate_mask)
  4217. {
  4218. u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
  4219. IEEE80211_BASIC_RATE_MASK : 0;
  4220. if (rate_mask & IEEE80211_CCK_RATE_1MB_MASK)
  4221. rates->supported_rates[rates->num_rates++] =
  4222. IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_1MB;
  4223. if (rate_mask & IEEE80211_CCK_RATE_2MB_MASK)
  4224. rates->supported_rates[rates->num_rates++] =
  4225. IEEE80211_BASIC_RATE_MASK | IEEE80211_CCK_RATE_2MB;
  4226. if (rate_mask & IEEE80211_CCK_RATE_5MB_MASK)
  4227. rates->supported_rates[rates->num_rates++] = basic_mask |
  4228. IEEE80211_CCK_RATE_5MB;
  4229. if (rate_mask & IEEE80211_CCK_RATE_11MB_MASK)
  4230. rates->supported_rates[rates->num_rates++] = basic_mask |
  4231. IEEE80211_CCK_RATE_11MB;
  4232. }
  4233. static void ipw_add_ofdm_scan_rates(struct ipw_supported_rates *rates,
  4234. u8 modulation, u32 rate_mask)
  4235. {
  4236. u8 basic_mask = (IEEE80211_OFDM_MODULATION == modulation) ?
  4237. IEEE80211_BASIC_RATE_MASK : 0;
  4238. if (rate_mask & IEEE80211_OFDM_RATE_6MB_MASK)
  4239. rates->supported_rates[rates->num_rates++] = basic_mask |
  4240. IEEE80211_OFDM_RATE_6MB;
  4241. if (rate_mask & IEEE80211_OFDM_RATE_9MB_MASK)
  4242. rates->supported_rates[rates->num_rates++] =
  4243. IEEE80211_OFDM_RATE_9MB;
  4244. if (rate_mask & IEEE80211_OFDM_RATE_12MB_MASK)
  4245. rates->supported_rates[rates->num_rates++] = basic_mask |
  4246. IEEE80211_OFDM_RATE_12MB;
  4247. if (rate_mask & IEEE80211_OFDM_RATE_18MB_MASK)
  4248. rates->supported_rates[rates->num_rates++] =
  4249. IEEE80211_OFDM_RATE_18MB;
  4250. if (rate_mask & IEEE80211_OFDM_RATE_24MB_MASK)
  4251. rates->supported_rates[rates->num_rates++] = basic_mask |
  4252. IEEE80211_OFDM_RATE_24MB;
  4253. if (rate_mask & IEEE80211_OFDM_RATE_36MB_MASK)
  4254. rates->supported_rates[rates->num_rates++] =
  4255. IEEE80211_OFDM_RATE_36MB;
  4256. if (rate_mask & IEEE80211_OFDM_RATE_48MB_MASK)
  4257. rates->supported_rates[rates->num_rates++] =
  4258. IEEE80211_OFDM_RATE_48MB;
  4259. if (rate_mask & IEEE80211_OFDM_RATE_54MB_MASK)
  4260. rates->supported_rates[rates->num_rates++] =
  4261. IEEE80211_OFDM_RATE_54MB;
  4262. }
  4263. struct ipw_network_match {
  4264. struct ieee80211_network *network;
  4265. struct ipw_supported_rates rates;
  4266. };
  4267. static int ipw_find_adhoc_network(struct ipw_priv *priv,
  4268. struct ipw_network_match *match,
  4269. struct ieee80211_network *network,
  4270. int roaming)
  4271. {
  4272. struct ipw_supported_rates rates;
  4273. /* Verify that this network's capability is compatible with the
  4274. * current mode (AdHoc or Infrastructure) */
  4275. if ((priv->ieee->iw_mode == IW_MODE_ADHOC &&
  4276. !(network->capability & WLAN_CAPABILITY_IBSS))) {
  4277. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded due to "
  4278. "capability mismatch.\n",
  4279. escape_essid(network->ssid, network->ssid_len),
  4280. MAC_ARG(network->bssid));
  4281. return 0;
  4282. }
  4283. /* If we do not have an ESSID for this AP, we can not associate with
  4284. * it */
  4285. if (network->flags & NETWORK_EMPTY_ESSID) {
  4286. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
  4287. "because of hidden ESSID.\n",
  4288. escape_essid(network->ssid, network->ssid_len),
  4289. MAC_ARG(network->bssid));
  4290. return 0;
  4291. }
  4292. if (unlikely(roaming)) {
  4293. /* If we are roaming, then ensure check if this is a valid
  4294. * network to try and roam to */
  4295. if ((network->ssid_len != match->network->ssid_len) ||
  4296. memcmp(network->ssid, match->network->ssid,
  4297. network->ssid_len)) {
  4298. IPW_DEBUG_MERGE("Netowrk '%s (" MAC_FMT ")' excluded "
  4299. "because of non-network ESSID.\n",
  4300. escape_essid(network->ssid,
  4301. network->ssid_len),
  4302. MAC_ARG(network->bssid));
  4303. return 0;
  4304. }
  4305. } else {
  4306. /* If an ESSID has been configured then compare the broadcast
  4307. * ESSID to ours */
  4308. if ((priv->config & CFG_STATIC_ESSID) &&
  4309. ((network->ssid_len != priv->essid_len) ||
  4310. memcmp(network->ssid, priv->essid,
  4311. min(network->ssid_len, priv->essid_len)))) {
  4312. char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
  4313. strncpy(escaped,
  4314. escape_essid(network->ssid, network->ssid_len),
  4315. sizeof(escaped));
  4316. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
  4317. "because of ESSID mismatch: '%s'.\n",
  4318. escaped, MAC_ARG(network->bssid),
  4319. escape_essid(priv->essid,
  4320. priv->essid_len));
  4321. return 0;
  4322. }
  4323. }
  4324. /* If the old network rate is better than this one, don't bother
  4325. * testing everything else. */
  4326. if (network->time_stamp[0] < match->network->time_stamp[0]) {
  4327. IPW_DEBUG_MERGE("Network '%s excluded because newer than "
  4328. "current network.\n",
  4329. escape_essid(match->network->ssid,
  4330. match->network->ssid_len));
  4331. return 0;
  4332. } else if (network->time_stamp[1] < match->network->time_stamp[1]) {
  4333. IPW_DEBUG_MERGE("Network '%s excluded because newer than "
  4334. "current network.\n",
  4335. escape_essid(match->network->ssid,
  4336. match->network->ssid_len));
  4337. return 0;
  4338. }
  4339. /* Now go through and see if the requested network is valid... */
  4340. if (priv->ieee->scan_age != 0 &&
  4341. time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
  4342. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
  4343. "because of age: %lums.\n",
  4344. escape_essid(network->ssid, network->ssid_len),
  4345. MAC_ARG(network->bssid),
  4346. 1000 * (jiffies - network->last_scanned) / HZ);
  4347. return 0;
  4348. }
  4349. if ((priv->config & CFG_STATIC_CHANNEL) &&
  4350. (network->channel != priv->channel)) {
  4351. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
  4352. "because of channel mismatch: %d != %d.\n",
  4353. escape_essid(network->ssid, network->ssid_len),
  4354. MAC_ARG(network->bssid),
  4355. network->channel, priv->channel);
  4356. return 0;
  4357. }
  4358. /* Verify privacy compatability */
  4359. if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
  4360. ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
  4361. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
  4362. "because of privacy mismatch: %s != %s.\n",
  4363. escape_essid(network->ssid, network->ssid_len),
  4364. MAC_ARG(network->bssid),
  4365. priv->
  4366. capability & CAP_PRIVACY_ON ? "on" : "off",
  4367. network->
  4368. capability & WLAN_CAPABILITY_PRIVACY ? "on" :
  4369. "off");
  4370. return 0;
  4371. }
  4372. if (!memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
  4373. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
  4374. "because of the same BSSID match: " MAC_FMT
  4375. ".\n", escape_essid(network->ssid,
  4376. network->ssid_len),
  4377. MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
  4378. return 0;
  4379. }
  4380. /* Filter out any incompatible freq / mode combinations */
  4381. if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
  4382. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
  4383. "because of invalid frequency/mode "
  4384. "combination.\n",
  4385. escape_essid(network->ssid, network->ssid_len),
  4386. MAC_ARG(network->bssid));
  4387. return 0;
  4388. }
  4389. /* Ensure that the rates supported by the driver are compatible with
  4390. * this AP, including verification of basic rates (mandatory) */
  4391. if (!ipw_compatible_rates(priv, network, &rates)) {
  4392. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
  4393. "because configured rate mask excludes "
  4394. "AP mandatory rate.\n",
  4395. escape_essid(network->ssid, network->ssid_len),
  4396. MAC_ARG(network->bssid));
  4397. return 0;
  4398. }
  4399. if (rates.num_rates == 0) {
  4400. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' excluded "
  4401. "because of no compatible rates.\n",
  4402. escape_essid(network->ssid, network->ssid_len),
  4403. MAC_ARG(network->bssid));
  4404. return 0;
  4405. }
  4406. /* TODO: Perform any further minimal comparititive tests. We do not
  4407. * want to put too much policy logic here; intelligent scan selection
  4408. * should occur within a generic IEEE 802.11 user space tool. */
  4409. /* Set up 'new' AP to this network */
  4410. ipw_copy_rates(&match->rates, &rates);
  4411. match->network = network;
  4412. IPW_DEBUG_MERGE("Network '%s (" MAC_FMT ")' is a viable match.\n",
  4413. escape_essid(network->ssid, network->ssid_len),
  4414. MAC_ARG(network->bssid));
  4415. return 1;
  4416. }
  4417. static void ipw_merge_adhoc_network(void *data)
  4418. {
  4419. struct ipw_priv *priv = data;
  4420. struct ieee80211_network *network = NULL;
  4421. struct ipw_network_match match = {
  4422. .network = priv->assoc_network
  4423. };
  4424. if ((priv->status & STATUS_ASSOCIATED) &&
  4425. (priv->ieee->iw_mode == IW_MODE_ADHOC)) {
  4426. /* First pass through ROAM process -- look for a better
  4427. * network */
  4428. unsigned long flags;
  4429. spin_lock_irqsave(&priv->ieee->lock, flags);
  4430. list_for_each_entry(network, &priv->ieee->network_list, list) {
  4431. if (network != priv->assoc_network)
  4432. ipw_find_adhoc_network(priv, &match, network,
  4433. 1);
  4434. }
  4435. spin_unlock_irqrestore(&priv->ieee->lock, flags);
  4436. if (match.network == priv->assoc_network) {
  4437. IPW_DEBUG_MERGE("No better ADHOC in this network to "
  4438. "merge to.\n");
  4439. return;
  4440. }
  4441. down(&priv->sem);
  4442. if ((priv->ieee->iw_mode == IW_MODE_ADHOC)) {
  4443. IPW_DEBUG_MERGE("remove network %s\n",
  4444. escape_essid(priv->essid,
  4445. priv->essid_len));
  4446. ipw_remove_current_network(priv);
  4447. }
  4448. ipw_disassociate(priv);
  4449. priv->assoc_network = match.network;
  4450. up(&priv->sem);
  4451. return;
  4452. }
  4453. }
  4454. static int ipw_best_network(struct ipw_priv *priv,
  4455. struct ipw_network_match *match,
  4456. struct ieee80211_network *network, int roaming)
  4457. {
  4458. struct ipw_supported_rates rates;
  4459. /* Verify that this network's capability is compatible with the
  4460. * current mode (AdHoc or Infrastructure) */
  4461. if ((priv->ieee->iw_mode == IW_MODE_INFRA &&
  4462. !(network->capability & WLAN_CAPABILITY_ESS)) ||
  4463. (priv->ieee->iw_mode == IW_MODE_ADHOC &&
  4464. !(network->capability & WLAN_CAPABILITY_IBSS))) {
  4465. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded due to "
  4466. "capability mismatch.\n",
  4467. escape_essid(network->ssid, network->ssid_len),
  4468. MAC_ARG(network->bssid));
  4469. return 0;
  4470. }
  4471. /* If we do not have an ESSID for this AP, we can not associate with
  4472. * it */
  4473. if (network->flags & NETWORK_EMPTY_ESSID) {
  4474. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4475. "because of hidden ESSID.\n",
  4476. escape_essid(network->ssid, network->ssid_len),
  4477. MAC_ARG(network->bssid));
  4478. return 0;
  4479. }
  4480. if (unlikely(roaming)) {
  4481. /* If we are roaming, then ensure check if this is a valid
  4482. * network to try and roam to */
  4483. if ((network->ssid_len != match->network->ssid_len) ||
  4484. memcmp(network->ssid, match->network->ssid,
  4485. network->ssid_len)) {
  4486. IPW_DEBUG_ASSOC("Netowrk '%s (" MAC_FMT ")' excluded "
  4487. "because of non-network ESSID.\n",
  4488. escape_essid(network->ssid,
  4489. network->ssid_len),
  4490. MAC_ARG(network->bssid));
  4491. return 0;
  4492. }
  4493. } else {
  4494. /* If an ESSID has been configured then compare the broadcast
  4495. * ESSID to ours */
  4496. if ((priv->config & CFG_STATIC_ESSID) &&
  4497. ((network->ssid_len != priv->essid_len) ||
  4498. memcmp(network->ssid, priv->essid,
  4499. min(network->ssid_len, priv->essid_len)))) {
  4500. char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
  4501. strncpy(escaped,
  4502. escape_essid(network->ssid, network->ssid_len),
  4503. sizeof(escaped));
  4504. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4505. "because of ESSID mismatch: '%s'.\n",
  4506. escaped, MAC_ARG(network->bssid),
  4507. escape_essid(priv->essid,
  4508. priv->essid_len));
  4509. return 0;
  4510. }
  4511. }
  4512. /* If the old network rate is better than this one, don't bother
  4513. * testing everything else. */
  4514. if (match->network && match->network->stats.rssi > network->stats.rssi) {
  4515. char escaped[IW_ESSID_MAX_SIZE * 2 + 1];
  4516. strncpy(escaped,
  4517. escape_essid(network->ssid, network->ssid_len),
  4518. sizeof(escaped));
  4519. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded because "
  4520. "'%s (" MAC_FMT ")' has a stronger signal.\n",
  4521. escaped, MAC_ARG(network->bssid),
  4522. escape_essid(match->network->ssid,
  4523. match->network->ssid_len),
  4524. MAC_ARG(match->network->bssid));
  4525. return 0;
  4526. }
  4527. /* If this network has already had an association attempt within the
  4528. * last 3 seconds, do not try and associate again... */
  4529. if (network->last_associate &&
  4530. time_after(network->last_associate + (HZ * 3UL), jiffies)) {
  4531. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4532. "because of storming (%lus since last "
  4533. "assoc attempt).\n",
  4534. escape_essid(network->ssid, network->ssid_len),
  4535. MAC_ARG(network->bssid),
  4536. (jiffies - network->last_associate) / HZ);
  4537. return 0;
  4538. }
  4539. /* Now go through and see if the requested network is valid... */
  4540. if (priv->ieee->scan_age != 0 &&
  4541. time_after(jiffies, network->last_scanned + priv->ieee->scan_age)) {
  4542. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4543. "because of age: %lums.\n",
  4544. escape_essid(network->ssid, network->ssid_len),
  4545. MAC_ARG(network->bssid),
  4546. 1000 * (jiffies - network->last_scanned) / HZ);
  4547. return 0;
  4548. }
  4549. if ((priv->config & CFG_STATIC_CHANNEL) &&
  4550. (network->channel != priv->channel)) {
  4551. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4552. "because of channel mismatch: %d != %d.\n",
  4553. escape_essid(network->ssid, network->ssid_len),
  4554. MAC_ARG(network->bssid),
  4555. network->channel, priv->channel);
  4556. return 0;
  4557. }
  4558. /* Verify privacy compatability */
  4559. if (((priv->capability & CAP_PRIVACY_ON) ? 1 : 0) !=
  4560. ((network->capability & WLAN_CAPABILITY_PRIVACY) ? 1 : 0)) {
  4561. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4562. "because of privacy mismatch: %s != %s.\n",
  4563. escape_essid(network->ssid, network->ssid_len),
  4564. MAC_ARG(network->bssid),
  4565. priv->capability & CAP_PRIVACY_ON ? "on" :
  4566. "off",
  4567. network->capability &
  4568. WLAN_CAPABILITY_PRIVACY ? "on" : "off");
  4569. return 0;
  4570. }
  4571. if ((priv->config & CFG_STATIC_BSSID) &&
  4572. memcmp(network->bssid, priv->bssid, ETH_ALEN)) {
  4573. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4574. "because of BSSID mismatch: " MAC_FMT ".\n",
  4575. escape_essid(network->ssid, network->ssid_len),
  4576. MAC_ARG(network->bssid), MAC_ARG(priv->bssid));
  4577. return 0;
  4578. }
  4579. /* Filter out any incompatible freq / mode combinations */
  4580. if (!ieee80211_is_valid_mode(priv->ieee, network->mode)) {
  4581. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4582. "because of invalid frequency/mode "
  4583. "combination.\n",
  4584. escape_essid(network->ssid, network->ssid_len),
  4585. MAC_ARG(network->bssid));
  4586. return 0;
  4587. }
  4588. /* Ensure that the rates supported by the driver are compatible with
  4589. * this AP, including verification of basic rates (mandatory) */
  4590. if (!ipw_compatible_rates(priv, network, &rates)) {
  4591. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4592. "because configured rate mask excludes "
  4593. "AP mandatory rate.\n",
  4594. escape_essid(network->ssid, network->ssid_len),
  4595. MAC_ARG(network->bssid));
  4596. return 0;
  4597. }
  4598. if (rates.num_rates == 0) {
  4599. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' excluded "
  4600. "because of no compatible rates.\n",
  4601. escape_essid(network->ssid, network->ssid_len),
  4602. MAC_ARG(network->bssid));
  4603. return 0;
  4604. }
  4605. /* TODO: Perform any further minimal comparititive tests. We do not
  4606. * want to put too much policy logic here; intelligent scan selection
  4607. * should occur within a generic IEEE 802.11 user space tool. */
  4608. /* Set up 'new' AP to this network */
  4609. ipw_copy_rates(&match->rates, &rates);
  4610. match->network = network;
  4611. IPW_DEBUG_ASSOC("Network '%s (" MAC_FMT ")' is a viable match.\n",
  4612. escape_essid(network->ssid, network->ssid_len),
  4613. MAC_ARG(network->bssid));
  4614. return 1;
  4615. }
  4616. static void ipw_adhoc_create(struct ipw_priv *priv,
  4617. struct ieee80211_network *network)
  4618. {
  4619. const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
  4620. int i;
  4621. /*
  4622. * For the purposes of scanning, we can set our wireless mode
  4623. * to trigger scans across combinations of bands, but when it
  4624. * comes to creating a new ad-hoc network, we have tell the FW
  4625. * exactly which band to use.
  4626. *
  4627. * We also have the possibility of an invalid channel for the
  4628. * chossen band. Attempting to create a new ad-hoc network
  4629. * with an invalid channel for wireless mode will trigger a
  4630. * FW fatal error.
  4631. *
  4632. */
  4633. switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
  4634. case IEEE80211_52GHZ_BAND:
  4635. network->mode = IEEE_A;
  4636. i = ieee80211_channel_to_index(priv->ieee, priv->channel);
  4637. if (i == -1)
  4638. BUG();
  4639. if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
  4640. IPW_WARNING("Overriding invalid channel\n");
  4641. priv->channel = geo->a[0].channel;
  4642. }
  4643. break;
  4644. case IEEE80211_24GHZ_BAND:
  4645. if (priv->ieee->mode & IEEE_G)
  4646. network->mode = IEEE_G;
  4647. else
  4648. network->mode = IEEE_B;
  4649. break;
  4650. default:
  4651. IPW_WARNING("Overriding invalid channel\n");
  4652. if (priv->ieee->mode & IEEE_A) {
  4653. network->mode = IEEE_A;
  4654. priv->channel = geo->a[0].channel;
  4655. } else if (priv->ieee->mode & IEEE_G) {
  4656. network->mode = IEEE_G;
  4657. priv->channel = geo->bg[0].channel;
  4658. } else {
  4659. network->mode = IEEE_B;
  4660. priv->channel = geo->bg[0].channel;
  4661. }
  4662. break;
  4663. }
  4664. network->channel = priv->channel;
  4665. priv->config |= CFG_ADHOC_PERSIST;
  4666. ipw_create_bssid(priv, network->bssid);
  4667. network->ssid_len = priv->essid_len;
  4668. memcpy(network->ssid, priv->essid, priv->essid_len);
  4669. memset(&network->stats, 0, sizeof(network->stats));
  4670. network->capability = WLAN_CAPABILITY_IBSS;
  4671. if (!(priv->config & CFG_PREAMBLE_LONG))
  4672. network->capability |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  4673. if (priv->capability & CAP_PRIVACY_ON)
  4674. network->capability |= WLAN_CAPABILITY_PRIVACY;
  4675. network->rates_len = min(priv->rates.num_rates, MAX_RATES_LENGTH);
  4676. memcpy(network->rates, priv->rates.supported_rates, network->rates_len);
  4677. network->rates_ex_len = priv->rates.num_rates - network->rates_len;
  4678. memcpy(network->rates_ex,
  4679. &priv->rates.supported_rates[network->rates_len],
  4680. network->rates_ex_len);
  4681. network->last_scanned = 0;
  4682. network->flags = 0;
  4683. network->last_associate = 0;
  4684. network->time_stamp[0] = 0;
  4685. network->time_stamp[1] = 0;
  4686. network->beacon_interval = 100; /* Default */
  4687. network->listen_interval = 10; /* Default */
  4688. network->atim_window = 0; /* Default */
  4689. network->wpa_ie_len = 0;
  4690. network->rsn_ie_len = 0;
  4691. }
  4692. static void ipw_send_tgi_tx_key(struct ipw_priv *priv, int type, int index)
  4693. {
  4694. struct ipw_tgi_tx_key *key;
  4695. struct host_cmd cmd = {
  4696. .cmd = IPW_CMD_TGI_TX_KEY,
  4697. .len = sizeof(*key)
  4698. };
  4699. if (!(priv->ieee->sec.flags & (1 << index)))
  4700. return;
  4701. key = (struct ipw_tgi_tx_key *)&cmd.param;
  4702. key->key_id = index;
  4703. memcpy(key->key, priv->ieee->sec.keys[index], SCM_TEMPORAL_KEY_LENGTH);
  4704. key->security_type = type;
  4705. key->station_index = 0; /* always 0 for BSS */
  4706. key->flags = 0;
  4707. /* 0 for new key; previous value of counter (after fatal error) */
  4708. key->tx_counter[0] = 0;
  4709. key->tx_counter[1] = 0;
  4710. ipw_send_cmd(priv, &cmd);
  4711. }
  4712. static void ipw_send_wep_keys(struct ipw_priv *priv, int type)
  4713. {
  4714. struct ipw_wep_key *key;
  4715. int i;
  4716. struct host_cmd cmd = {
  4717. .cmd = IPW_CMD_WEP_KEY,
  4718. .len = sizeof(*key)
  4719. };
  4720. key = (struct ipw_wep_key *)&cmd.param;
  4721. key->cmd_id = DINO_CMD_WEP_KEY;
  4722. key->seq_num = 0;
  4723. /* Note: AES keys cannot be set for multiple times.
  4724. * Only set it at the first time. */
  4725. for (i = 0; i < 4; i++) {
  4726. key->key_index = i | type;
  4727. if (!(priv->ieee->sec.flags & (1 << i))) {
  4728. key->key_size = 0;
  4729. continue;
  4730. }
  4731. key->key_size = priv->ieee->sec.key_sizes[i];
  4732. memcpy(key->key, priv->ieee->sec.keys[i], key->key_size);
  4733. ipw_send_cmd(priv, &cmd);
  4734. }
  4735. }
  4736. static void ipw_set_hw_decrypt_unicast(struct ipw_priv *priv, int level)
  4737. {
  4738. if (priv->ieee->host_encrypt)
  4739. return;
  4740. switch (level) {
  4741. case SEC_LEVEL_3:
  4742. priv->sys_config.disable_unicast_decryption = 0;
  4743. priv->ieee->host_decrypt = 0;
  4744. break;
  4745. case SEC_LEVEL_2:
  4746. priv->sys_config.disable_unicast_decryption = 1;
  4747. priv->ieee->host_decrypt = 1;
  4748. break;
  4749. case SEC_LEVEL_1:
  4750. priv->sys_config.disable_unicast_decryption = 0;
  4751. priv->ieee->host_decrypt = 0;
  4752. break;
  4753. case SEC_LEVEL_0:
  4754. priv->sys_config.disable_unicast_decryption = 1;
  4755. break;
  4756. default:
  4757. break;
  4758. }
  4759. }
  4760. static void ipw_set_hw_decrypt_multicast(struct ipw_priv *priv, int level)
  4761. {
  4762. if (priv->ieee->host_encrypt)
  4763. return;
  4764. switch (level) {
  4765. case SEC_LEVEL_3:
  4766. priv->sys_config.disable_multicast_decryption = 0;
  4767. break;
  4768. case SEC_LEVEL_2:
  4769. priv->sys_config.disable_multicast_decryption = 1;
  4770. break;
  4771. case SEC_LEVEL_1:
  4772. priv->sys_config.disable_multicast_decryption = 0;
  4773. break;
  4774. case SEC_LEVEL_0:
  4775. priv->sys_config.disable_multicast_decryption = 1;
  4776. break;
  4777. default:
  4778. break;
  4779. }
  4780. }
  4781. static void ipw_set_hwcrypto_keys(struct ipw_priv *priv)
  4782. {
  4783. switch (priv->ieee->sec.level) {
  4784. case SEC_LEVEL_3:
  4785. if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
  4786. ipw_send_tgi_tx_key(priv,
  4787. DCT_FLAG_EXT_SECURITY_CCM,
  4788. priv->ieee->sec.active_key);
  4789. ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_CCM);
  4790. break;
  4791. case SEC_LEVEL_2:
  4792. if (priv->ieee->sec.flags & SEC_ACTIVE_KEY)
  4793. ipw_send_tgi_tx_key(priv,
  4794. DCT_FLAG_EXT_SECURITY_TKIP,
  4795. priv->ieee->sec.active_key);
  4796. break;
  4797. case SEC_LEVEL_1:
  4798. ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
  4799. break;
  4800. case SEC_LEVEL_0:
  4801. default:
  4802. break;
  4803. }
  4804. ipw_set_hw_decrypt_unicast(priv, priv->ieee->sec.level);
  4805. ipw_set_hw_decrypt_multicast(priv, priv->ieee->sec.level);
  4806. }
  4807. static void ipw_adhoc_check(void *data)
  4808. {
  4809. struct ipw_priv *priv = data;
  4810. if (priv->missed_adhoc_beacons++ > priv->disassociate_threshold &&
  4811. !(priv->config & CFG_ADHOC_PERSIST)) {
  4812. IPW_DEBUG(IPW_DL_INFO | IPW_DL_NOTIF |
  4813. IPW_DL_STATE | IPW_DL_ASSOC,
  4814. "Missed beacon: %d - disassociate\n",
  4815. priv->missed_adhoc_beacons);
  4816. ipw_remove_current_network(priv);
  4817. ipw_disassociate(priv);
  4818. return;
  4819. }
  4820. queue_delayed_work(priv->workqueue, &priv->adhoc_check,
  4821. priv->assoc_request.beacon_interval);
  4822. }
  4823. static void ipw_bg_adhoc_check(void *data)
  4824. {
  4825. struct ipw_priv *priv = data;
  4826. down(&priv->sem);
  4827. ipw_adhoc_check(data);
  4828. up(&priv->sem);
  4829. }
  4830. #ifdef CONFIG_IPW_DEBUG
  4831. static void ipw_debug_config(struct ipw_priv *priv)
  4832. {
  4833. IPW_DEBUG_INFO("Scan completed, no valid APs matched "
  4834. "[CFG 0x%08X]\n", priv->config);
  4835. if (priv->config & CFG_STATIC_CHANNEL)
  4836. IPW_DEBUG_INFO("Channel locked to %d\n", priv->channel);
  4837. else
  4838. IPW_DEBUG_INFO("Channel unlocked.\n");
  4839. if (priv->config & CFG_STATIC_ESSID)
  4840. IPW_DEBUG_INFO("ESSID locked to '%s'\n",
  4841. escape_essid(priv->essid, priv->essid_len));
  4842. else
  4843. IPW_DEBUG_INFO("ESSID unlocked.\n");
  4844. if (priv->config & CFG_STATIC_BSSID)
  4845. IPW_DEBUG_INFO("BSSID locked to " MAC_FMT "\n",
  4846. MAC_ARG(priv->bssid));
  4847. else
  4848. IPW_DEBUG_INFO("BSSID unlocked.\n");
  4849. if (priv->capability & CAP_PRIVACY_ON)
  4850. IPW_DEBUG_INFO("PRIVACY on\n");
  4851. else
  4852. IPW_DEBUG_INFO("PRIVACY off\n");
  4853. IPW_DEBUG_INFO("RATE MASK: 0x%08X\n", priv->rates_mask);
  4854. }
  4855. #else
  4856. #define ipw_debug_config(x) do {} while (0)
  4857. #endif
  4858. static inline void ipw_set_fixed_rate(struct ipw_priv *priv, int mode)
  4859. {
  4860. /* TODO: Verify that this works... */
  4861. struct ipw_fixed_rate fr = {
  4862. .tx_rates = priv->rates_mask
  4863. };
  4864. u32 reg;
  4865. u16 mask = 0;
  4866. /* Identify 'current FW band' and match it with the fixed
  4867. * Tx rates */
  4868. switch (priv->ieee->freq_band) {
  4869. case IEEE80211_52GHZ_BAND: /* A only */
  4870. /* IEEE_A */
  4871. if (priv->rates_mask & ~IEEE80211_OFDM_RATES_MASK) {
  4872. /* Invalid fixed rate mask */
  4873. IPW_DEBUG_WX
  4874. ("invalid fixed rate mask in ipw_set_fixed_rate\n");
  4875. fr.tx_rates = 0;
  4876. break;
  4877. }
  4878. fr.tx_rates >>= IEEE80211_OFDM_SHIFT_MASK_A;
  4879. break;
  4880. default: /* 2.4Ghz or Mixed */
  4881. /* IEEE_B */
  4882. if (mode == IEEE_B) {
  4883. if (fr.tx_rates & ~IEEE80211_CCK_RATES_MASK) {
  4884. /* Invalid fixed rate mask */
  4885. IPW_DEBUG_WX
  4886. ("invalid fixed rate mask in ipw_set_fixed_rate\n");
  4887. fr.tx_rates = 0;
  4888. }
  4889. break;
  4890. }
  4891. /* IEEE_G */
  4892. if (fr.tx_rates & ~(IEEE80211_CCK_RATES_MASK |
  4893. IEEE80211_OFDM_RATES_MASK)) {
  4894. /* Invalid fixed rate mask */
  4895. IPW_DEBUG_WX
  4896. ("invalid fixed rate mask in ipw_set_fixed_rate\n");
  4897. fr.tx_rates = 0;
  4898. break;
  4899. }
  4900. if (IEEE80211_OFDM_RATE_6MB_MASK & fr.tx_rates) {
  4901. mask |= (IEEE80211_OFDM_RATE_6MB_MASK >> 1);
  4902. fr.tx_rates &= ~IEEE80211_OFDM_RATE_6MB_MASK;
  4903. }
  4904. if (IEEE80211_OFDM_RATE_9MB_MASK & fr.tx_rates) {
  4905. mask |= (IEEE80211_OFDM_RATE_9MB_MASK >> 1);
  4906. fr.tx_rates &= ~IEEE80211_OFDM_RATE_9MB_MASK;
  4907. }
  4908. if (IEEE80211_OFDM_RATE_12MB_MASK & fr.tx_rates) {
  4909. mask |= (IEEE80211_OFDM_RATE_12MB_MASK >> 1);
  4910. fr.tx_rates &= ~IEEE80211_OFDM_RATE_12MB_MASK;
  4911. }
  4912. fr.tx_rates |= mask;
  4913. break;
  4914. }
  4915. reg = ipw_read32(priv, IPW_MEM_FIXED_OVERRIDE);
  4916. ipw_write_reg32(priv, reg, *(u32 *) & fr);
  4917. }
  4918. static void ipw_abort_scan(struct ipw_priv *priv)
  4919. {
  4920. int err;
  4921. if (priv->status & STATUS_SCAN_ABORTING) {
  4922. IPW_DEBUG_HC("Ignoring concurrent scan abort request.\n");
  4923. return;
  4924. }
  4925. priv->status |= STATUS_SCAN_ABORTING;
  4926. err = ipw_send_scan_abort(priv);
  4927. if (err)
  4928. IPW_DEBUG_HC("Request to abort scan failed.\n");
  4929. }
  4930. static void ipw_add_scan_channels(struct ipw_priv *priv,
  4931. struct ipw_scan_request_ext *scan,
  4932. int scan_type)
  4933. {
  4934. int channel_index = 0;
  4935. const struct ieee80211_geo *geo;
  4936. int i;
  4937. geo = ieee80211_get_geo(priv->ieee);
  4938. if (priv->ieee->freq_band & IEEE80211_52GHZ_BAND) {
  4939. int start = channel_index;
  4940. for (i = 0; i < geo->a_channels; i++) {
  4941. if ((priv->status & STATUS_ASSOCIATED) &&
  4942. geo->a[i].channel == priv->channel)
  4943. continue;
  4944. channel_index++;
  4945. scan->channels_list[channel_index] = geo->a[i].channel;
  4946. ipw_set_scan_type(scan, channel_index, scan_type);
  4947. }
  4948. if (start != channel_index) {
  4949. scan->channels_list[start] = (u8) (IPW_A_MODE << 6) |
  4950. (channel_index - start);
  4951. channel_index++;
  4952. }
  4953. }
  4954. if (priv->ieee->freq_band & IEEE80211_24GHZ_BAND) {
  4955. int start = channel_index;
  4956. if (priv->config & CFG_SPEED_SCAN) {
  4957. u8 channels[IEEE80211_24GHZ_CHANNELS] = {
  4958. /* nop out the list */
  4959. [0] = 0
  4960. };
  4961. u8 channel;
  4962. while (channel_index < IPW_SCAN_CHANNELS) {
  4963. channel =
  4964. priv->speed_scan[priv->speed_scan_pos];
  4965. if (channel == 0) {
  4966. priv->speed_scan_pos = 0;
  4967. channel = priv->speed_scan[0];
  4968. }
  4969. if ((priv->status & STATUS_ASSOCIATED) &&
  4970. channel == priv->channel) {
  4971. priv->speed_scan_pos++;
  4972. continue;
  4973. }
  4974. /* If this channel has already been
  4975. * added in scan, break from loop
  4976. * and this will be the first channel
  4977. * in the next scan.
  4978. */
  4979. if (channels[channel - 1] != 0)
  4980. break;
  4981. channels[channel - 1] = 1;
  4982. priv->speed_scan_pos++;
  4983. channel_index++;
  4984. scan->channels_list[channel_index] = channel;
  4985. ipw_set_scan_type(scan, channel_index,
  4986. scan_type);
  4987. }
  4988. } else {
  4989. for (i = 0; i < geo->bg_channels; i++) {
  4990. if ((priv->status & STATUS_ASSOCIATED) &&
  4991. geo->bg[i].channel == priv->channel)
  4992. continue;
  4993. channel_index++;
  4994. scan->channels_list[channel_index] =
  4995. geo->bg[i].channel;
  4996. ipw_set_scan_type(scan, channel_index,
  4997. scan_type);
  4998. }
  4999. }
  5000. if (start != channel_index) {
  5001. scan->channels_list[start] = (u8) (IPW_B_MODE << 6) |
  5002. (channel_index - start);
  5003. }
  5004. }
  5005. }
  5006. static int ipw_request_scan(struct ipw_priv *priv)
  5007. {
  5008. struct ipw_scan_request_ext scan;
  5009. int err = 0, scan_type;
  5010. if (!(priv->status & STATUS_INIT) ||
  5011. (priv->status & STATUS_EXIT_PENDING))
  5012. return 0;
  5013. down(&priv->sem);
  5014. if (priv->status & STATUS_SCANNING) {
  5015. IPW_DEBUG_HC("Concurrent scan requested. Ignoring.\n");
  5016. priv->status |= STATUS_SCAN_PENDING;
  5017. goto done;
  5018. }
  5019. if (!(priv->status & STATUS_SCAN_FORCED) &&
  5020. priv->status & STATUS_SCAN_ABORTING) {
  5021. IPW_DEBUG_HC("Scan request while abort pending. Queuing.\n");
  5022. priv->status |= STATUS_SCAN_PENDING;
  5023. goto done;
  5024. }
  5025. if (priv->status & STATUS_RF_KILL_MASK) {
  5026. IPW_DEBUG_HC("Aborting scan due to RF Kill activation\n");
  5027. priv->status |= STATUS_SCAN_PENDING;
  5028. goto done;
  5029. }
  5030. memset(&scan, 0, sizeof(scan));
  5031. if (priv->config & CFG_SPEED_SCAN)
  5032. scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
  5033. cpu_to_le16(30);
  5034. else
  5035. scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
  5036. cpu_to_le16(20);
  5037. scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
  5038. cpu_to_le16(20);
  5039. scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(20);
  5040. scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
  5041. #ifdef CONFIG_IPW2200_MONITOR
  5042. if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
  5043. u8 channel;
  5044. u8 band = 0;
  5045. switch (ieee80211_is_valid_channel(priv->ieee, priv->channel)) {
  5046. case IEEE80211_52GHZ_BAND:
  5047. band = (u8) (IPW_A_MODE << 6) | 1;
  5048. channel = priv->channel;
  5049. break;
  5050. case IEEE80211_24GHZ_BAND:
  5051. band = (u8) (IPW_B_MODE << 6) | 1;
  5052. channel = priv->channel;
  5053. break;
  5054. default:
  5055. band = (u8) (IPW_B_MODE << 6) | 1;
  5056. channel = 9;
  5057. break;
  5058. }
  5059. scan.channels_list[0] = band;
  5060. scan.channels_list[1] = channel;
  5061. ipw_set_scan_type(&scan, 1, IPW_SCAN_PASSIVE_FULL_DWELL_SCAN);
  5062. /* NOTE: The card will sit on this channel for this time
  5063. * period. Scan aborts are timing sensitive and frequently
  5064. * result in firmware restarts. As such, it is best to
  5065. * set a small dwell_time here and just keep re-issuing
  5066. * scans. Otherwise fast channel hopping will not actually
  5067. * hop channels.
  5068. *
  5069. * TODO: Move SPEED SCAN support to all modes and bands */
  5070. scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] =
  5071. cpu_to_le16(2000);
  5072. } else {
  5073. #endif /* CONFIG_IPW2200_MONITOR */
  5074. /* If we are roaming, then make this a directed scan for the
  5075. * current network. Otherwise, ensure that every other scan
  5076. * is a fast channel hop scan */
  5077. if ((priv->status & STATUS_ROAMING)
  5078. || (!(priv->status & STATUS_ASSOCIATED)
  5079. && (priv->config & CFG_STATIC_ESSID)
  5080. && (le32_to_cpu(scan.full_scan_index) % 2))) {
  5081. err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
  5082. if (err) {
  5083. IPW_DEBUG_HC("Attempt to send SSID command "
  5084. "failed.\n");
  5085. goto done;
  5086. }
  5087. scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
  5088. } else
  5089. scan_type = IPW_SCAN_ACTIVE_BROADCAST_SCAN;
  5090. ipw_add_scan_channels(priv, &scan, scan_type);
  5091. #ifdef CONFIG_IPW2200_MONITOR
  5092. }
  5093. #endif
  5094. err = ipw_send_scan_request_ext(priv, &scan);
  5095. if (err) {
  5096. IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
  5097. goto done;
  5098. }
  5099. priv->status |= STATUS_SCANNING;
  5100. priv->status &= ~STATUS_SCAN_PENDING;
  5101. queue_delayed_work(priv->workqueue, &priv->scan_check,
  5102. IPW_SCAN_CHECK_WATCHDOG);
  5103. done:
  5104. up(&priv->sem);
  5105. return err;
  5106. }
  5107. static void ipw_bg_abort_scan(void *data)
  5108. {
  5109. struct ipw_priv *priv = data;
  5110. down(&priv->sem);
  5111. ipw_abort_scan(data);
  5112. up(&priv->sem);
  5113. }
  5114. #if WIRELESS_EXT < 18
  5115. /* Support for wpa_supplicant before WE-18, deprecated. */
  5116. /* following definitions must match definitions in driver_ipw.c */
  5117. #define IPW_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
  5118. #define IPW_CMD_SET_WPA_PARAM 1
  5119. #define IPW_CMD_SET_WPA_IE 2
  5120. #define IPW_CMD_SET_ENCRYPTION 3
  5121. #define IPW_CMD_MLME 4
  5122. #define IPW_PARAM_WPA_ENABLED 1
  5123. #define IPW_PARAM_TKIP_COUNTERMEASURES 2
  5124. #define IPW_PARAM_DROP_UNENCRYPTED 3
  5125. #define IPW_PARAM_PRIVACY_INVOKED 4
  5126. #define IPW_PARAM_AUTH_ALGS 5
  5127. #define IPW_PARAM_IEEE_802_1X 6
  5128. #define IPW_MLME_STA_DEAUTH 1
  5129. #define IPW_MLME_STA_DISASSOC 2
  5130. #define IPW_CRYPT_ERR_UNKNOWN_ALG 2
  5131. #define IPW_CRYPT_ERR_UNKNOWN_ADDR 3
  5132. #define IPW_CRYPT_ERR_CRYPT_INIT_FAILED 4
  5133. #define IPW_CRYPT_ERR_KEY_SET_FAILED 5
  5134. #define IPW_CRYPT_ERR_TX_KEY_SET_FAILED 6
  5135. #define IPW_CRYPT_ERR_CARD_CONF_FAILED 7
  5136. #define IPW_CRYPT_ALG_NAME_LEN 16
  5137. struct ipw_param {
  5138. u32 cmd;
  5139. u8 sta_addr[ETH_ALEN];
  5140. union {
  5141. struct {
  5142. u8 name;
  5143. u32 value;
  5144. } wpa_param;
  5145. struct {
  5146. u32 len;
  5147. u8 reserved[32];
  5148. u8 data[0];
  5149. } wpa_ie;
  5150. struct {
  5151. u32 command;
  5152. u32 reason_code;
  5153. } mlme;
  5154. struct {
  5155. u8 alg[IPW_CRYPT_ALG_NAME_LEN];
  5156. u8 set_tx;
  5157. u32 err;
  5158. u8 idx;
  5159. u8 seq[8]; /* sequence counter (set: RX, get: TX) */
  5160. u16 key_len;
  5161. u8 key[0];
  5162. } crypt;
  5163. } u;
  5164. };
  5165. /* end of driver_ipw.c code */
  5166. #endif
  5167. static int ipw_wpa_enable(struct ipw_priv *priv, int value)
  5168. {
  5169. /* This is called when wpa_supplicant loads and closes the driver
  5170. * interface. */
  5171. return 0;
  5172. }
  5173. #if WIRELESS_EXT < 18
  5174. #define IW_AUTH_ALG_OPEN_SYSTEM 0x1
  5175. #define IW_AUTH_ALG_SHARED_KEY 0x2
  5176. #endif
  5177. static int ipw_wpa_set_auth_algs(struct ipw_priv *priv, int value)
  5178. {
  5179. struct ieee80211_device *ieee = priv->ieee;
  5180. struct ieee80211_security sec = {
  5181. .flags = SEC_AUTH_MODE,
  5182. };
  5183. int ret = 0;
  5184. if (value & IW_AUTH_ALG_SHARED_KEY) {
  5185. sec.auth_mode = WLAN_AUTH_SHARED_KEY;
  5186. ieee->open_wep = 0;
  5187. } else if (value & IW_AUTH_ALG_OPEN_SYSTEM) {
  5188. sec.auth_mode = WLAN_AUTH_OPEN;
  5189. ieee->open_wep = 1;
  5190. } else
  5191. return -EINVAL;
  5192. if (ieee->set_security)
  5193. ieee->set_security(ieee->dev, &sec);
  5194. else
  5195. ret = -EOPNOTSUPP;
  5196. return ret;
  5197. }
  5198. void ipw_wpa_assoc_frame(struct ipw_priv *priv, char *wpa_ie, int wpa_ie_len)
  5199. {
  5200. /* make sure WPA is enabled */
  5201. ipw_wpa_enable(priv, 1);
  5202. ipw_disassociate(priv);
  5203. }
  5204. static int ipw_set_rsn_capa(struct ipw_priv *priv,
  5205. char *capabilities, int length)
  5206. {
  5207. struct host_cmd cmd = {
  5208. .cmd = IPW_CMD_RSN_CAPABILITIES,
  5209. .len = length,
  5210. };
  5211. IPW_DEBUG_HC("HOST_CMD_RSN_CAPABILITIES\n");
  5212. memcpy(cmd.param, capabilities, length);
  5213. return ipw_send_cmd(priv, &cmd);
  5214. }
  5215. #if WIRELESS_EXT < 18
  5216. static int ipw_wpa_set_param(struct net_device *dev, u8 name, u32 value)
  5217. {
  5218. struct ipw_priv *priv = ieee80211_priv(dev);
  5219. struct ieee80211_crypt_data *crypt;
  5220. unsigned long flags;
  5221. int ret = 0;
  5222. switch (name) {
  5223. case IPW_PARAM_WPA_ENABLED:
  5224. ret = ipw_wpa_enable(priv, value);
  5225. break;
  5226. case IPW_PARAM_TKIP_COUNTERMEASURES:
  5227. crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
  5228. if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) {
  5229. IPW_WARNING("Can't set TKIP countermeasures: "
  5230. "crypt not set!\n");
  5231. break;
  5232. }
  5233. flags = crypt->ops->get_flags(crypt->priv);
  5234. if (value)
  5235. flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
  5236. else
  5237. flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
  5238. crypt->ops->set_flags(flags, crypt->priv);
  5239. break;
  5240. case IPW_PARAM_DROP_UNENCRYPTED:{
  5241. /* HACK:
  5242. *
  5243. * wpa_supplicant calls set_wpa_enabled when the driver
  5244. * is loaded and unloaded, regardless of if WPA is being
  5245. * used. No other calls are made which can be used to
  5246. * determine if encryption will be used or not prior to
  5247. * association being expected. If encryption is not being
  5248. * used, drop_unencrypted is set to false, else true -- we
  5249. * can use this to determine if the CAP_PRIVACY_ON bit should
  5250. * be set.
  5251. */
  5252. struct ieee80211_security sec = {
  5253. .flags = SEC_ENABLED,
  5254. .enabled = value,
  5255. };
  5256. priv->ieee->drop_unencrypted = value;
  5257. /* We only change SEC_LEVEL for open mode. Others
  5258. * are set by ipw_wpa_set_encryption.
  5259. */
  5260. if (!value) {
  5261. sec.flags |= SEC_LEVEL;
  5262. sec.level = SEC_LEVEL_0;
  5263. } else {
  5264. sec.flags |= SEC_LEVEL;
  5265. sec.level = SEC_LEVEL_1;
  5266. }
  5267. if (priv->ieee->set_security)
  5268. priv->ieee->set_security(priv->ieee->dev, &sec);
  5269. break;
  5270. }
  5271. case IPW_PARAM_PRIVACY_INVOKED:
  5272. priv->ieee->privacy_invoked = value;
  5273. break;
  5274. case IPW_PARAM_AUTH_ALGS:
  5275. ret = ipw_wpa_set_auth_algs(priv, value);
  5276. break;
  5277. case IPW_PARAM_IEEE_802_1X:
  5278. priv->ieee->ieee802_1x = value;
  5279. break;
  5280. default:
  5281. IPW_ERROR("%s: Unknown WPA param: %d\n", dev->name, name);
  5282. ret = -EOPNOTSUPP;
  5283. }
  5284. return ret;
  5285. }
  5286. static int ipw_wpa_mlme(struct net_device *dev, int command, int reason)
  5287. {
  5288. struct ipw_priv *priv = ieee80211_priv(dev);
  5289. int ret = 0;
  5290. switch (command) {
  5291. case IPW_MLME_STA_DEAUTH:
  5292. // silently ignore
  5293. break;
  5294. case IPW_MLME_STA_DISASSOC:
  5295. ipw_disassociate(priv);
  5296. break;
  5297. default:
  5298. IPW_ERROR("%s: Unknown MLME request: %d\n", dev->name, command);
  5299. ret = -EOPNOTSUPP;
  5300. }
  5301. return ret;
  5302. }
  5303. static int ipw_wpa_ie_cipher2level(u8 cipher)
  5304. {
  5305. switch (cipher) {
  5306. case 4: /* CCMP */
  5307. return SEC_LEVEL_3;
  5308. case 2: /* TKIP */
  5309. return SEC_LEVEL_2;
  5310. case 5: /* WEP104 */
  5311. case 1: /* WEP40 */
  5312. return SEC_LEVEL_1;
  5313. case 0: /* NONE */
  5314. return SEC_LEVEL_0;
  5315. default:
  5316. return -1;
  5317. }
  5318. }
  5319. static int ipw_wpa_set_wpa_ie(struct net_device *dev,
  5320. struct ipw_param *param, int plen)
  5321. {
  5322. struct ipw_priv *priv = ieee80211_priv(dev);
  5323. struct ieee80211_device *ieee = priv->ieee;
  5324. u8 *buf;
  5325. u8 *ptk, *gtk;
  5326. int level;
  5327. if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
  5328. (param->u.wpa_ie.len && param->u.wpa_ie.data == NULL))
  5329. return -EINVAL;
  5330. if (param->u.wpa_ie.len) {
  5331. buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
  5332. if (buf == NULL)
  5333. return -ENOMEM;
  5334. memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
  5335. kfree(ieee->wpa_ie);
  5336. ieee->wpa_ie = buf;
  5337. ieee->wpa_ie_len = param->u.wpa_ie.len;
  5338. } else {
  5339. kfree(ieee->wpa_ie);
  5340. ieee->wpa_ie = NULL;
  5341. ieee->wpa_ie_len = 0;
  5342. goto done;
  5343. }
  5344. if (priv->ieee->host_encrypt)
  5345. goto done;
  5346. /* HACK: Parse wpa_ie here to get pairwise suite, otherwise
  5347. * we need to change driver_ipw.c from wpa_supplicant. This
  5348. * is OK since -Dipw is deprecated. The -Dwext driver has a
  5349. * clean way to handle this. */
  5350. gtk = ptk = (u8 *) ieee->wpa_ie;
  5351. if (ieee->wpa_ie[0] == 0x30) { /* RSN IE */
  5352. gtk += 4 + 3;
  5353. ptk += 4 + 4 + 2 + 3;
  5354. } else { /* WPA IE */
  5355. gtk += 8 + 3;
  5356. ptk += 8 + 4 + 2 + 3;
  5357. }
  5358. if (ptk - (u8 *) ieee->wpa_ie > ieee->wpa_ie_len)
  5359. return -EINVAL;
  5360. level = ipw_wpa_ie_cipher2level(*gtk);
  5361. ipw_set_hw_decrypt_multicast(priv, level);
  5362. level = ipw_wpa_ie_cipher2level(*ptk);
  5363. ipw_set_hw_decrypt_unicast(priv, level);
  5364. done:
  5365. ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
  5366. return 0;
  5367. }
  5368. /* implementation borrowed from hostap driver */
  5369. static int ipw_wpa_set_encryption(struct net_device *dev,
  5370. struct ipw_param *param, int param_len)
  5371. {
  5372. int ret = 0;
  5373. struct ipw_priv *priv = ieee80211_priv(dev);
  5374. struct ieee80211_device *ieee = priv->ieee;
  5375. struct ieee80211_crypto_ops *ops;
  5376. struct ieee80211_crypt_data **crypt;
  5377. struct ieee80211_security sec = {
  5378. .flags = 0,
  5379. };
  5380. param->u.crypt.err = 0;
  5381. param->u.crypt.alg[IPW_CRYPT_ALG_NAME_LEN - 1] = '\0';
  5382. if (param_len !=
  5383. (int)((char *)param->u.crypt.key - (char *)param) +
  5384. param->u.crypt.key_len) {
  5385. IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len,
  5386. param->u.crypt.key_len);
  5387. return -EINVAL;
  5388. }
  5389. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  5390. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  5391. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
  5392. if (param->u.crypt.idx >= WEP_KEYS)
  5393. return -EINVAL;
  5394. crypt = &ieee->crypt[param->u.crypt.idx];
  5395. } else {
  5396. return -EINVAL;
  5397. }
  5398. sec.flags |= SEC_ENABLED | SEC_ENCRYPT;
  5399. if (strcmp(param->u.crypt.alg, "none") == 0) {
  5400. if (crypt) {
  5401. sec.enabled = 0;
  5402. sec.encrypt = 0;
  5403. sec.level = SEC_LEVEL_0;
  5404. sec.flags |= SEC_LEVEL;
  5405. ieee80211_crypt_delayed_deinit(ieee, crypt);
  5406. }
  5407. goto done;
  5408. }
  5409. sec.enabled = 1;
  5410. sec.encrypt = 1;
  5411. /* IPW HW cannot build TKIP MIC, host decryption still needed. */
  5412. if (strcmp(param->u.crypt.alg, "TKIP") == 0)
  5413. ieee->host_encrypt_msdu = 1;
  5414. if (!(ieee->host_encrypt || ieee->host_encrypt_msdu ||
  5415. ieee->host_decrypt))
  5416. goto skip_host_crypt;
  5417. ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
  5418. if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
  5419. request_module("ieee80211_crypt_wep");
  5420. ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
  5421. } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
  5422. request_module("ieee80211_crypt_tkip");
  5423. ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
  5424. } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
  5425. request_module("ieee80211_crypt_ccmp");
  5426. ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
  5427. }
  5428. if (ops == NULL) {
  5429. IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n",
  5430. dev->name, param->u.crypt.alg);
  5431. param->u.crypt.err = IPW_CRYPT_ERR_UNKNOWN_ALG;
  5432. ret = -EINVAL;
  5433. goto done;
  5434. }
  5435. if (*crypt == NULL || (*crypt)->ops != ops) {
  5436. struct ieee80211_crypt_data *new_crypt;
  5437. ieee80211_crypt_delayed_deinit(ieee, crypt);
  5438. new_crypt = (struct ieee80211_crypt_data *)
  5439. kmalloc(sizeof(*new_crypt), GFP_KERNEL);
  5440. if (new_crypt == NULL) {
  5441. ret = -ENOMEM;
  5442. goto done;
  5443. }
  5444. memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
  5445. new_crypt->ops = ops;
  5446. if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
  5447. new_crypt->priv =
  5448. new_crypt->ops->init(param->u.crypt.idx);
  5449. if (new_crypt->priv == NULL) {
  5450. kfree(new_crypt);
  5451. param->u.crypt.err = IPW_CRYPT_ERR_CRYPT_INIT_FAILED;
  5452. ret = -EINVAL;
  5453. goto done;
  5454. }
  5455. *crypt = new_crypt;
  5456. }
  5457. if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
  5458. (*crypt)->ops->set_key(param->u.crypt.key,
  5459. param->u.crypt.key_len, param->u.crypt.seq,
  5460. (*crypt)->priv) < 0) {
  5461. IPW_DEBUG_INFO("%s: key setting failed\n", dev->name);
  5462. param->u.crypt.err = IPW_CRYPT_ERR_KEY_SET_FAILED;
  5463. ret = -EINVAL;
  5464. goto done;
  5465. }
  5466. skip_host_crypt:
  5467. if (param->u.crypt.set_tx) {
  5468. ieee->tx_keyidx = param->u.crypt.idx;
  5469. sec.active_key = param->u.crypt.idx;
  5470. sec.flags |= SEC_ACTIVE_KEY;
  5471. } else
  5472. sec.flags &= ~SEC_ACTIVE_KEY;
  5473. if (param->u.crypt.alg != NULL) {
  5474. memcpy(sec.keys[param->u.crypt.idx],
  5475. param->u.crypt.key, param->u.crypt.key_len);
  5476. sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
  5477. sec.flags |= (1 << param->u.crypt.idx);
  5478. if (strcmp(param->u.crypt.alg, "WEP") == 0) {
  5479. sec.flags |= SEC_LEVEL;
  5480. sec.level = SEC_LEVEL_1;
  5481. } else if (strcmp(param->u.crypt.alg, "TKIP") == 0) {
  5482. sec.flags |= SEC_LEVEL;
  5483. sec.level = SEC_LEVEL_2;
  5484. } else if (strcmp(param->u.crypt.alg, "CCMP") == 0) {
  5485. sec.flags |= SEC_LEVEL;
  5486. sec.level = SEC_LEVEL_3;
  5487. }
  5488. }
  5489. done:
  5490. if (ieee->set_security)
  5491. ieee->set_security(ieee->dev, &sec);
  5492. /* Do not reset port if card is in Managed mode since resetting will
  5493. * generate new IEEE 802.11 authentication which may end up in looping
  5494. * with IEEE 802.1X. If your hardware requires a reset after WEP
  5495. * configuration (for example... Prism2), implement the reset_port in
  5496. * the callbacks structures used to initialize the 802.11 stack. */
  5497. if (ieee->reset_on_keychange &&
  5498. ieee->iw_mode != IW_MODE_INFRA &&
  5499. ieee->reset_port && ieee->reset_port(dev)) {
  5500. IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name);
  5501. param->u.crypt.err = IPW_CRYPT_ERR_CARD_CONF_FAILED;
  5502. return -EINVAL;
  5503. }
  5504. return ret;
  5505. }
  5506. static int ipw_wpa_supplicant(struct net_device *dev, struct iw_point *p)
  5507. {
  5508. struct ipw_param *param;
  5509. struct ipw_priv *priv = ieee80211_priv(dev);
  5510. int ret = 0;
  5511. IPW_DEBUG_INFO("wpa_supplicant: len=%d\n", p->length);
  5512. if (p->length < sizeof(struct ipw_param) || !p->pointer)
  5513. return -EINVAL;
  5514. param = (struct ipw_param *)kmalloc(p->length, GFP_KERNEL);
  5515. if (param == NULL)
  5516. return -ENOMEM;
  5517. if (copy_from_user(param, p->pointer, p->length)) {
  5518. kfree(param);
  5519. return -EFAULT;
  5520. }
  5521. down(&priv->sem);
  5522. switch (param->cmd) {
  5523. case IPW_CMD_SET_WPA_PARAM:
  5524. ret = ipw_wpa_set_param(dev, param->u.wpa_param.name,
  5525. param->u.wpa_param.value);
  5526. break;
  5527. case IPW_CMD_SET_WPA_IE:
  5528. ret = ipw_wpa_set_wpa_ie(dev, param, p->length);
  5529. break;
  5530. case IPW_CMD_SET_ENCRYPTION:
  5531. ret = ipw_wpa_set_encryption(dev, param, p->length);
  5532. break;
  5533. case IPW_CMD_MLME:
  5534. ret = ipw_wpa_mlme(dev, param->u.mlme.command,
  5535. param->u.mlme.reason_code);
  5536. break;
  5537. default:
  5538. IPW_ERROR("%s: Unknown WPA supplicant request: %d\n",
  5539. dev->name, param->cmd);
  5540. ret = -EOPNOTSUPP;
  5541. }
  5542. up(&priv->sem);
  5543. if (ret == 0 && copy_to_user(p->pointer, param, p->length))
  5544. ret = -EFAULT;
  5545. kfree(param);
  5546. return ret;
  5547. }
  5548. #else
  5549. /*
  5550. * WE-18 support
  5551. */
  5552. /* SIOCSIWGENIE */
  5553. static int ipw_wx_set_genie(struct net_device *dev,
  5554. struct iw_request_info *info,
  5555. union iwreq_data *wrqu, char *extra)
  5556. {
  5557. struct ipw_priv *priv = ieee80211_priv(dev);
  5558. struct ieee80211_device *ieee = priv->ieee;
  5559. u8 *buf;
  5560. int err = 0;
  5561. if (wrqu->data.length > MAX_WPA_IE_LEN ||
  5562. (wrqu->data.length && extra == NULL))
  5563. return -EINVAL;
  5564. //down(&priv->sem);
  5565. //if (!ieee->wpa_enabled) {
  5566. // err = -EOPNOTSUPP;
  5567. // goto out;
  5568. //}
  5569. if (wrqu->data.length) {
  5570. buf = kmalloc(wrqu->data.length, GFP_KERNEL);
  5571. if (buf == NULL) {
  5572. err = -ENOMEM;
  5573. goto out;
  5574. }
  5575. memcpy(buf, extra, wrqu->data.length);
  5576. kfree(ieee->wpa_ie);
  5577. ieee->wpa_ie = buf;
  5578. ieee->wpa_ie_len = wrqu->data.length;
  5579. } else {
  5580. kfree(ieee->wpa_ie);
  5581. ieee->wpa_ie = NULL;
  5582. ieee->wpa_ie_len = 0;
  5583. }
  5584. ipw_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
  5585. out:
  5586. //up(&priv->sem);
  5587. return err;
  5588. }
  5589. /* SIOCGIWGENIE */
  5590. static int ipw_wx_get_genie(struct net_device *dev,
  5591. struct iw_request_info *info,
  5592. union iwreq_data *wrqu, char *extra)
  5593. {
  5594. struct ipw_priv *priv = ieee80211_priv(dev);
  5595. struct ieee80211_device *ieee = priv->ieee;
  5596. int err = 0;
  5597. //down(&priv->sem);
  5598. //if (!ieee->wpa_enabled) {
  5599. // err = -EOPNOTSUPP;
  5600. // goto out;
  5601. //}
  5602. if (ieee->wpa_ie_len == 0 || ieee->wpa_ie == NULL) {
  5603. wrqu->data.length = 0;
  5604. goto out;
  5605. }
  5606. if (wrqu->data.length < ieee->wpa_ie_len) {
  5607. err = -E2BIG;
  5608. goto out;
  5609. }
  5610. wrqu->data.length = ieee->wpa_ie_len;
  5611. memcpy(extra, ieee->wpa_ie, ieee->wpa_ie_len);
  5612. out:
  5613. //up(&priv->sem);
  5614. return err;
  5615. }
  5616. static int wext_cipher2level(int cipher)
  5617. {
  5618. switch (cipher) {
  5619. case IW_AUTH_CIPHER_NONE:
  5620. return SEC_LEVEL_0;
  5621. case IW_AUTH_CIPHER_WEP40:
  5622. case IW_AUTH_CIPHER_WEP104:
  5623. return SEC_LEVEL_1;
  5624. case IW_AUTH_CIPHER_TKIP:
  5625. return SEC_LEVEL_2;
  5626. case IW_AUTH_CIPHER_CCMP:
  5627. return SEC_LEVEL_3;
  5628. default:
  5629. return -1;
  5630. }
  5631. }
  5632. /* SIOCSIWAUTH */
  5633. static int ipw_wx_set_auth(struct net_device *dev,
  5634. struct iw_request_info *info,
  5635. union iwreq_data *wrqu, char *extra)
  5636. {
  5637. struct ipw_priv *priv = ieee80211_priv(dev);
  5638. struct ieee80211_device *ieee = priv->ieee;
  5639. struct iw_param *param = &wrqu->param;
  5640. struct ieee80211_crypt_data *crypt;
  5641. unsigned long flags;
  5642. int ret = 0;
  5643. switch (param->flags & IW_AUTH_INDEX) {
  5644. case IW_AUTH_WPA_VERSION:
  5645. break;
  5646. case IW_AUTH_CIPHER_PAIRWISE:
  5647. ipw_set_hw_decrypt_unicast(priv,
  5648. wext_cipher2level(param->value));
  5649. break;
  5650. case IW_AUTH_CIPHER_GROUP:
  5651. ipw_set_hw_decrypt_multicast(priv,
  5652. wext_cipher2level(param->value));
  5653. break;
  5654. case IW_AUTH_KEY_MGMT:
  5655. /*
  5656. * ipw2200 does not use these parameters
  5657. */
  5658. break;
  5659. case IW_AUTH_TKIP_COUNTERMEASURES:
  5660. crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
  5661. if (!crypt || !crypt->ops->set_flags || !crypt->ops->get_flags) {
  5662. IPW_WARNING("Can't set TKIP countermeasures: "
  5663. "crypt not set!\n");
  5664. break;
  5665. }
  5666. flags = crypt->ops->get_flags(crypt->priv);
  5667. if (param->value)
  5668. flags |= IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
  5669. else
  5670. flags &= ~IEEE80211_CRYPTO_TKIP_COUNTERMEASURES;
  5671. crypt->ops->set_flags(flags, crypt->priv);
  5672. break;
  5673. case IW_AUTH_DROP_UNENCRYPTED:{
  5674. /* HACK:
  5675. *
  5676. * wpa_supplicant calls set_wpa_enabled when the driver
  5677. * is loaded and unloaded, regardless of if WPA is being
  5678. * used. No other calls are made which can be used to
  5679. * determine if encryption will be used or not prior to
  5680. * association being expected. If encryption is not being
  5681. * used, drop_unencrypted is set to false, else true -- we
  5682. * can use this to determine if the CAP_PRIVACY_ON bit should
  5683. * be set.
  5684. */
  5685. struct ieee80211_security sec = {
  5686. .flags = SEC_ENABLED,
  5687. .enabled = param->value,
  5688. };
  5689. priv->ieee->drop_unencrypted = param->value;
  5690. /* We only change SEC_LEVEL for open mode. Others
  5691. * are set by ipw_wpa_set_encryption.
  5692. */
  5693. if (!param->value) {
  5694. sec.flags |= SEC_LEVEL;
  5695. sec.level = SEC_LEVEL_0;
  5696. } else {
  5697. sec.flags |= SEC_LEVEL;
  5698. sec.level = SEC_LEVEL_1;
  5699. }
  5700. if (priv->ieee->set_security)
  5701. priv->ieee->set_security(priv->ieee->dev, &sec);
  5702. break;
  5703. }
  5704. case IW_AUTH_80211_AUTH_ALG:
  5705. ret = ipw_wpa_set_auth_algs(priv, param->value);
  5706. break;
  5707. case IW_AUTH_WPA_ENABLED:
  5708. ret = ipw_wpa_enable(priv, param->value);
  5709. break;
  5710. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  5711. ieee->ieee802_1x = param->value;
  5712. break;
  5713. //case IW_AUTH_ROAMING_CONTROL:
  5714. case IW_AUTH_PRIVACY_INVOKED:
  5715. ieee->privacy_invoked = param->value;
  5716. break;
  5717. default:
  5718. return -EOPNOTSUPP;
  5719. }
  5720. return ret;
  5721. }
  5722. /* SIOCGIWAUTH */
  5723. static int ipw_wx_get_auth(struct net_device *dev,
  5724. struct iw_request_info *info,
  5725. union iwreq_data *wrqu, char *extra)
  5726. {
  5727. struct ipw_priv *priv = ieee80211_priv(dev);
  5728. struct ieee80211_device *ieee = priv->ieee;
  5729. struct ieee80211_crypt_data *crypt;
  5730. struct iw_param *param = &wrqu->param;
  5731. int ret = 0;
  5732. switch (param->flags & IW_AUTH_INDEX) {
  5733. case IW_AUTH_WPA_VERSION:
  5734. case IW_AUTH_CIPHER_PAIRWISE:
  5735. case IW_AUTH_CIPHER_GROUP:
  5736. case IW_AUTH_KEY_MGMT:
  5737. /*
  5738. * wpa_supplicant will control these internally
  5739. */
  5740. ret = -EOPNOTSUPP;
  5741. break;
  5742. case IW_AUTH_TKIP_COUNTERMEASURES:
  5743. crypt = priv->ieee->crypt[priv->ieee->tx_keyidx];
  5744. if (!crypt || !crypt->ops->get_flags) {
  5745. IPW_WARNING("Can't get TKIP countermeasures: "
  5746. "crypt not set!\n");
  5747. break;
  5748. }
  5749. param->value = (crypt->ops->get_flags(crypt->priv) &
  5750. IEEE80211_CRYPTO_TKIP_COUNTERMEASURES) ? 1 : 0;
  5751. break;
  5752. case IW_AUTH_DROP_UNENCRYPTED:
  5753. param->value = ieee->drop_unencrypted;
  5754. break;
  5755. case IW_AUTH_80211_AUTH_ALG:
  5756. param->value = ieee->sec.auth_mode;
  5757. break;
  5758. case IW_AUTH_WPA_ENABLED:
  5759. param->value = ieee->wpa_enabled;
  5760. break;
  5761. case IW_AUTH_RX_UNENCRYPTED_EAPOL:
  5762. param->value = ieee->ieee802_1x;
  5763. break;
  5764. case IW_AUTH_ROAMING_CONTROL:
  5765. case IW_AUTH_PRIVACY_INVOKED:
  5766. param->value = ieee->privacy_invoked;
  5767. break;
  5768. default:
  5769. return -EOPNOTSUPP;
  5770. }
  5771. return 0;
  5772. }
  5773. /* SIOCSIWENCODEEXT */
  5774. static int ipw_wx_set_encodeext(struct net_device *dev,
  5775. struct iw_request_info *info,
  5776. union iwreq_data *wrqu, char *extra)
  5777. {
  5778. struct ipw_priv *priv = ieee80211_priv(dev);
  5779. struct iw_encode_ext *ext = (struct iw_encode_ext *)extra;
  5780. if (hwcrypto) {
  5781. /* IPW HW can't build TKIP MIC, host decryption still needed */
  5782. if (ext->alg == IW_ENCODE_ALG_TKIP) {
  5783. priv->ieee->host_encrypt = 0;
  5784. priv->ieee->host_encrypt_msdu = 1;
  5785. priv->ieee->host_decrypt = 1;
  5786. } else {
  5787. priv->ieee->host_encrypt = 0;
  5788. priv->ieee->host_encrypt_msdu = 0;
  5789. priv->ieee->host_decrypt = 0;
  5790. }
  5791. }
  5792. return ieee80211_wx_set_encodeext(priv->ieee, info, wrqu, extra);
  5793. }
  5794. /* SIOCGIWENCODEEXT */
  5795. static int ipw_wx_get_encodeext(struct net_device *dev,
  5796. struct iw_request_info *info,
  5797. union iwreq_data *wrqu, char *extra)
  5798. {
  5799. struct ipw_priv *priv = ieee80211_priv(dev);
  5800. return ieee80211_wx_get_encodeext(priv->ieee, info, wrqu, extra);
  5801. }
  5802. /* SIOCSIWMLME */
  5803. static int ipw_wx_set_mlme(struct net_device *dev,
  5804. struct iw_request_info *info,
  5805. union iwreq_data *wrqu, char *extra)
  5806. {
  5807. struct ipw_priv *priv = ieee80211_priv(dev);
  5808. struct iw_mlme *mlme = (struct iw_mlme *)extra;
  5809. u16 reason;
  5810. reason = cpu_to_le16(mlme->reason_code);
  5811. switch (mlme->cmd) {
  5812. case IW_MLME_DEAUTH:
  5813. // silently ignore
  5814. break;
  5815. case IW_MLME_DISASSOC:
  5816. ipw_disassociate(priv);
  5817. break;
  5818. default:
  5819. return -EOPNOTSUPP;
  5820. }
  5821. return 0;
  5822. }
  5823. #endif
  5824. #ifdef CONFIG_IPW_QOS
  5825. /* QoS */
  5826. /*
  5827. * get the modulation type of the current network or
  5828. * the card current mode
  5829. */
  5830. u8 ipw_qos_current_mode(struct ipw_priv * priv)
  5831. {
  5832. u8 mode = 0;
  5833. if (priv->status & STATUS_ASSOCIATED) {
  5834. unsigned long flags;
  5835. spin_lock_irqsave(&priv->ieee->lock, flags);
  5836. mode = priv->assoc_network->mode;
  5837. spin_unlock_irqrestore(&priv->ieee->lock, flags);
  5838. } else {
  5839. mode = priv->ieee->mode;
  5840. }
  5841. IPW_DEBUG_QOS("QoS network/card mode %d \n", mode);
  5842. return mode;
  5843. }
  5844. /*
  5845. * Handle management frame beacon and probe response
  5846. */
  5847. static int ipw_qos_handle_probe_reponse(struct ipw_priv *priv,
  5848. int active_network,
  5849. struct ieee80211_network *network)
  5850. {
  5851. u32 size = sizeof(struct ieee80211_qos_parameters);
  5852. if (network->capability & WLAN_CAPABILITY_IBSS)
  5853. network->qos_data.active = network->qos_data.supported;
  5854. if (network->flags & NETWORK_HAS_QOS_MASK) {
  5855. if (active_network &&
  5856. (network->flags & NETWORK_HAS_QOS_PARAMETERS))
  5857. network->qos_data.active = network->qos_data.supported;
  5858. if ((network->qos_data.active == 1) && (active_network == 1) &&
  5859. (network->flags & NETWORK_HAS_QOS_PARAMETERS) &&
  5860. (network->qos_data.old_param_count !=
  5861. network->qos_data.param_count)) {
  5862. network->qos_data.old_param_count =
  5863. network->qos_data.param_count;
  5864. schedule_work(&priv->qos_activate);
  5865. IPW_DEBUG_QOS("QoS parameters change call "
  5866. "qos_activate\n");
  5867. }
  5868. } else {
  5869. if ((priv->ieee->mode == IEEE_B) || (network->mode == IEEE_B))
  5870. memcpy(&network->qos_data.parameters,
  5871. &def_parameters_CCK, size);
  5872. else
  5873. memcpy(&network->qos_data.parameters,
  5874. &def_parameters_OFDM, size);
  5875. if ((network->qos_data.active == 1) && (active_network == 1)) {
  5876. IPW_DEBUG_QOS("QoS was disabled call qos_activate \n");
  5877. schedule_work(&priv->qos_activate);
  5878. }
  5879. network->qos_data.active = 0;
  5880. network->qos_data.supported = 0;
  5881. }
  5882. if ((priv->status & STATUS_ASSOCIATED) &&
  5883. (priv->ieee->iw_mode == IW_MODE_ADHOC) && (active_network == 0)) {
  5884. if (memcmp(network->bssid, priv->bssid, ETH_ALEN))
  5885. if ((network->capability & WLAN_CAPABILITY_IBSS) &&
  5886. !(network->flags & NETWORK_EMPTY_ESSID))
  5887. if ((network->ssid_len ==
  5888. priv->assoc_network->ssid_len) &&
  5889. !memcmp(network->ssid,
  5890. priv->assoc_network->ssid,
  5891. network->ssid_len)) {
  5892. queue_work(priv->workqueue,
  5893. &priv->merge_networks);
  5894. }
  5895. }
  5896. return 0;
  5897. }
  5898. /*
  5899. * This function set up the firmware to support QoS. It sends
  5900. * IPW_CMD_QOS_PARAMETERS and IPW_CMD_WME_INFO
  5901. */
  5902. static int ipw_qos_activate(struct ipw_priv *priv,
  5903. struct ieee80211_qos_data *qos_network_data)
  5904. {
  5905. int err;
  5906. struct ieee80211_qos_parameters qos_parameters[QOS_QOS_SETS];
  5907. struct ieee80211_qos_parameters *active_one = NULL;
  5908. u32 size = sizeof(struct ieee80211_qos_parameters);
  5909. u32 burst_duration;
  5910. int i;
  5911. u8 type;
  5912. type = ipw_qos_current_mode(priv);
  5913. active_one = &(qos_parameters[QOS_PARAM_SET_DEF_CCK]);
  5914. memcpy(active_one, priv->qos_data.def_qos_parm_CCK, size);
  5915. active_one = &(qos_parameters[QOS_PARAM_SET_DEF_OFDM]);
  5916. memcpy(active_one, priv->qos_data.def_qos_parm_OFDM, size);
  5917. if (qos_network_data == NULL) {
  5918. if (type == IEEE_B) {
  5919. IPW_DEBUG_QOS("QoS activate network mode %d\n", type);
  5920. active_one = &def_parameters_CCK;
  5921. } else
  5922. active_one = &def_parameters_OFDM;
  5923. memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
  5924. burst_duration = ipw_qos_get_burst_duration(priv);
  5925. for (i = 0; i < QOS_QUEUE_NUM; i++)
  5926. qos_parameters[QOS_PARAM_SET_ACTIVE].tx_op_limit[i] =
  5927. (u16) burst_duration;
  5928. } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
  5929. if (type == IEEE_B) {
  5930. IPW_DEBUG_QOS("QoS activate IBSS nework mode %d\n",
  5931. type);
  5932. if (priv->qos_data.qos_enable == 0)
  5933. active_one = &def_parameters_CCK;
  5934. else
  5935. active_one = priv->qos_data.def_qos_parm_CCK;
  5936. } else {
  5937. if (priv->qos_data.qos_enable == 0)
  5938. active_one = &def_parameters_OFDM;
  5939. else
  5940. active_one = priv->qos_data.def_qos_parm_OFDM;
  5941. }
  5942. memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
  5943. } else {
  5944. unsigned long flags;
  5945. int active;
  5946. spin_lock_irqsave(&priv->ieee->lock, flags);
  5947. active_one = &(qos_network_data->parameters);
  5948. qos_network_data->old_param_count =
  5949. qos_network_data->param_count;
  5950. memcpy(&qos_parameters[QOS_PARAM_SET_ACTIVE], active_one, size);
  5951. active = qos_network_data->supported;
  5952. spin_unlock_irqrestore(&priv->ieee->lock, flags);
  5953. if (active == 0) {
  5954. burst_duration = ipw_qos_get_burst_duration(priv);
  5955. for (i = 0; i < QOS_QUEUE_NUM; i++)
  5956. qos_parameters[QOS_PARAM_SET_ACTIVE].
  5957. tx_op_limit[i] = (u16) burst_duration;
  5958. }
  5959. }
  5960. IPW_DEBUG_QOS("QoS sending IPW_CMD_QOS_PARAMETERS\n");
  5961. err = ipw_send_qos_params_command(priv,
  5962. (struct ieee80211_qos_parameters *)
  5963. &(qos_parameters[0]));
  5964. if (err)
  5965. IPW_DEBUG_QOS("QoS IPW_CMD_QOS_PARAMETERS failed\n");
  5966. return err;
  5967. }
  5968. /*
  5969. * send IPW_CMD_WME_INFO to the firmware
  5970. */
  5971. static int ipw_qos_set_info_element(struct ipw_priv *priv)
  5972. {
  5973. int ret = 0;
  5974. struct ieee80211_qos_information_element qos_info;
  5975. if (priv == NULL)
  5976. return -1;
  5977. qos_info.elementID = QOS_ELEMENT_ID;
  5978. qos_info.length = sizeof(struct ieee80211_qos_information_element) - 2;
  5979. qos_info.version = QOS_VERSION_1;
  5980. qos_info.ac_info = 0;
  5981. memcpy(qos_info.qui, qos_oui, QOS_OUI_LEN);
  5982. qos_info.qui_type = QOS_OUI_TYPE;
  5983. qos_info.qui_subtype = QOS_OUI_INFO_SUB_TYPE;
  5984. ret = ipw_send_qos_info_command(priv, &qos_info);
  5985. if (ret != 0) {
  5986. IPW_DEBUG_QOS("QoS error calling ipw_send_qos_info_command\n");
  5987. }
  5988. return ret;
  5989. }
  5990. /*
  5991. * Set the QoS parameter with the association request structure
  5992. */
  5993. static int ipw_qos_association(struct ipw_priv *priv,
  5994. struct ieee80211_network *network)
  5995. {
  5996. int err = 0;
  5997. struct ieee80211_qos_data *qos_data = NULL;
  5998. struct ieee80211_qos_data ibss_data = {
  5999. .supported = 1,
  6000. .active = 1,
  6001. };
  6002. switch (priv->ieee->iw_mode) {
  6003. case IW_MODE_ADHOC:
  6004. if (!(network->capability & WLAN_CAPABILITY_IBSS))
  6005. BUG();
  6006. qos_data = &ibss_data;
  6007. break;
  6008. case IW_MODE_INFRA:
  6009. qos_data = &network->qos_data;
  6010. break;
  6011. default:
  6012. BUG();
  6013. break;
  6014. }
  6015. err = ipw_qos_activate(priv, qos_data);
  6016. if (err) {
  6017. priv->assoc_request.policy_support &= ~HC_QOS_SUPPORT_ASSOC;
  6018. return err;
  6019. }
  6020. if (priv->qos_data.qos_enable && qos_data->supported) {
  6021. IPW_DEBUG_QOS("QoS will be enabled for this association\n");
  6022. priv->assoc_request.policy_support |= HC_QOS_SUPPORT_ASSOC;
  6023. return ipw_qos_set_info_element(priv);
  6024. }
  6025. return 0;
  6026. }
  6027. /*
  6028. * handling the beaconing responces. if we get different QoS setting
  6029. * of the network from the the associated setting adjust the QoS
  6030. * setting
  6031. */
  6032. static int ipw_qos_association_resp(struct ipw_priv *priv,
  6033. struct ieee80211_network *network)
  6034. {
  6035. int ret = 0;
  6036. unsigned long flags;
  6037. u32 size = sizeof(struct ieee80211_qos_parameters);
  6038. int set_qos_param = 0;
  6039. if ((priv == NULL) || (network == NULL) ||
  6040. (priv->assoc_network == NULL))
  6041. return ret;
  6042. if (!(priv->status & STATUS_ASSOCIATED))
  6043. return ret;
  6044. if ((priv->ieee->iw_mode != IW_MODE_INFRA))
  6045. return ret;
  6046. spin_lock_irqsave(&priv->ieee->lock, flags);
  6047. if (network->flags & NETWORK_HAS_QOS_PARAMETERS) {
  6048. memcpy(&priv->assoc_network->qos_data, &network->qos_data,
  6049. sizeof(struct ieee80211_qos_data));
  6050. priv->assoc_network->qos_data.active = 1;
  6051. if ((network->qos_data.old_param_count !=
  6052. network->qos_data.param_count)) {
  6053. set_qos_param = 1;
  6054. network->qos_data.old_param_count =
  6055. network->qos_data.param_count;
  6056. }
  6057. } else {
  6058. if ((network->mode == IEEE_B) || (priv->ieee->mode == IEEE_B))
  6059. memcpy(&priv->assoc_network->qos_data.parameters,
  6060. &def_parameters_CCK, size);
  6061. else
  6062. memcpy(&priv->assoc_network->qos_data.parameters,
  6063. &def_parameters_OFDM, size);
  6064. priv->assoc_network->qos_data.active = 0;
  6065. priv->assoc_network->qos_data.supported = 0;
  6066. set_qos_param = 1;
  6067. }
  6068. spin_unlock_irqrestore(&priv->ieee->lock, flags);
  6069. if (set_qos_param == 1)
  6070. schedule_work(&priv->qos_activate);
  6071. return ret;
  6072. }
  6073. static u32 ipw_qos_get_burst_duration(struct ipw_priv *priv)
  6074. {
  6075. u32 ret = 0;
  6076. if ((priv == NULL))
  6077. return 0;
  6078. if (!(priv->ieee->modulation & IEEE80211_OFDM_MODULATION))
  6079. ret = priv->qos_data.burst_duration_CCK;
  6080. else
  6081. ret = priv->qos_data.burst_duration_OFDM;
  6082. return ret;
  6083. }
  6084. /*
  6085. * Initialize the setting of QoS global
  6086. */
  6087. static void ipw_qos_init(struct ipw_priv *priv, int enable,
  6088. int burst_enable, u32 burst_duration_CCK,
  6089. u32 burst_duration_OFDM)
  6090. {
  6091. priv->qos_data.qos_enable = enable;
  6092. if (priv->qos_data.qos_enable) {
  6093. priv->qos_data.def_qos_parm_CCK = &def_qos_parameters_CCK;
  6094. priv->qos_data.def_qos_parm_OFDM = &def_qos_parameters_OFDM;
  6095. IPW_DEBUG_QOS("QoS is enabled\n");
  6096. } else {
  6097. priv->qos_data.def_qos_parm_CCK = &def_parameters_CCK;
  6098. priv->qos_data.def_qos_parm_OFDM = &def_parameters_OFDM;
  6099. IPW_DEBUG_QOS("QoS is not enabled\n");
  6100. }
  6101. priv->qos_data.burst_enable = burst_enable;
  6102. if (burst_enable) {
  6103. priv->qos_data.burst_duration_CCK = burst_duration_CCK;
  6104. priv->qos_data.burst_duration_OFDM = burst_duration_OFDM;
  6105. } else {
  6106. priv->qos_data.burst_duration_CCK = 0;
  6107. priv->qos_data.burst_duration_OFDM = 0;
  6108. }
  6109. }
  6110. /*
  6111. * map the packet priority to the right TX Queue
  6112. */
  6113. static int ipw_get_tx_queue_number(struct ipw_priv *priv, u16 priority)
  6114. {
  6115. if (priority > 7 || !priv->qos_data.qos_enable)
  6116. priority = 0;
  6117. return from_priority_to_tx_queue[priority] - 1;
  6118. }
  6119. /*
  6120. * add QoS parameter to the TX command
  6121. */
  6122. static int ipw_qos_set_tx_queue_command(struct ipw_priv *priv,
  6123. u16 priority,
  6124. struct tfd_data *tfd, u8 unicast)
  6125. {
  6126. int ret = 0;
  6127. int tx_queue_id = 0;
  6128. struct ieee80211_qos_data *qos_data = NULL;
  6129. int active, supported;
  6130. unsigned long flags;
  6131. if (!(priv->status & STATUS_ASSOCIATED))
  6132. return 0;
  6133. qos_data = &priv->assoc_network->qos_data;
  6134. spin_lock_irqsave(&priv->ieee->lock, flags);
  6135. if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
  6136. if (unicast == 0)
  6137. qos_data->active = 0;
  6138. else
  6139. qos_data->active = qos_data->supported;
  6140. }
  6141. active = qos_data->active;
  6142. supported = qos_data->supported;
  6143. spin_unlock_irqrestore(&priv->ieee->lock, flags);
  6144. IPW_DEBUG_QOS("QoS %d network is QoS active %d supported %d "
  6145. "unicast %d\n",
  6146. priv->qos_data.qos_enable, active, supported, unicast);
  6147. if (active && priv->qos_data.qos_enable) {
  6148. ret = from_priority_to_tx_queue[priority];
  6149. tx_queue_id = ret - 1;
  6150. IPW_DEBUG_QOS("QoS packet priority is %d \n", priority);
  6151. if (priority <= 7) {
  6152. tfd->tx_flags_ext |= DCT_FLAG_EXT_QOS_ENABLED;
  6153. tfd->tfd.tfd_26.mchdr.qos_ctrl = priority;
  6154. tfd->tfd.tfd_26.mchdr.frame_ctl |=
  6155. IEEE80211_STYPE_QOS_DATA;
  6156. if (priv->qos_data.qos_no_ack_mask &
  6157. (1UL << tx_queue_id)) {
  6158. tfd->tx_flags &= ~DCT_FLAG_ACK_REQD;
  6159. tfd->tfd.tfd_26.mchdr.qos_ctrl |=
  6160. CTRL_QOS_NO_ACK;
  6161. }
  6162. }
  6163. }
  6164. return ret;
  6165. }
  6166. /*
  6167. * background support to run QoS activate functionality
  6168. */
  6169. static void ipw_bg_qos_activate(void *data)
  6170. {
  6171. struct ipw_priv *priv = data;
  6172. if (priv == NULL)
  6173. return;
  6174. down(&priv->sem);
  6175. if (priv->status & STATUS_ASSOCIATED)
  6176. ipw_qos_activate(priv, &(priv->assoc_network->qos_data));
  6177. up(&priv->sem);
  6178. }
  6179. /*
  6180. * Handler for probe responce and beacon frame
  6181. */
  6182. static int ipw_handle_management(struct net_device *dev,
  6183. struct ieee80211_network *network, u16 type)
  6184. {
  6185. struct ipw_priv *priv = ieee80211_priv(dev);
  6186. int active_network;
  6187. if (priv->status & STATUS_ASSOCIATED && network == priv->assoc_network)
  6188. active_network = 1;
  6189. else
  6190. active_network = 0;
  6191. switch (type) {
  6192. case IEEE80211_STYPE_PROBE_RESP:
  6193. case IEEE80211_STYPE_BEACON:
  6194. ipw_qos_handle_probe_reponse(priv, active_network, network);
  6195. break;
  6196. case IEEE80211_STYPE_ASSOC_RESP:
  6197. ipw_qos_association_resp(priv, network);
  6198. break;
  6199. default:
  6200. break;
  6201. }
  6202. return 0;
  6203. }
  6204. static int ipw_send_qos_params_command(struct ipw_priv *priv, struct ieee80211_qos_parameters
  6205. *qos_param)
  6206. {
  6207. struct host_cmd cmd = {
  6208. .cmd = IPW_CMD_QOS_PARAMETERS,
  6209. .len = (sizeof(struct ieee80211_qos_parameters) * 3)
  6210. };
  6211. memcpy(cmd.param, qos_param, sizeof(*qos_param) * 3);
  6212. return ipw_send_cmd(priv, &cmd);
  6213. }
  6214. static int ipw_send_qos_info_command(struct ipw_priv *priv, struct ieee80211_qos_information_element
  6215. *qos_param)
  6216. {
  6217. struct host_cmd cmd = {
  6218. .cmd = IPW_CMD_WME_INFO,
  6219. .len = sizeof(*qos_param)
  6220. };
  6221. memcpy(cmd.param, qos_param, sizeof(*qos_param));
  6222. return ipw_send_cmd(priv, &cmd);
  6223. }
  6224. #endif /* CONFIG_IPW_QOS */
  6225. static int ipw_associate_network(struct ipw_priv *priv,
  6226. struct ieee80211_network *network,
  6227. struct ipw_supported_rates *rates, int roaming)
  6228. {
  6229. int err;
  6230. if (priv->config & CFG_FIXED_RATE)
  6231. ipw_set_fixed_rate(priv, network->mode);
  6232. if (!(priv->config & CFG_STATIC_ESSID)) {
  6233. priv->essid_len = min(network->ssid_len,
  6234. (u8) IW_ESSID_MAX_SIZE);
  6235. memcpy(priv->essid, network->ssid, priv->essid_len);
  6236. }
  6237. network->last_associate = jiffies;
  6238. memset(&priv->assoc_request, 0, sizeof(priv->assoc_request));
  6239. priv->assoc_request.channel = network->channel;
  6240. if ((priv->capability & CAP_PRIVACY_ON) &&
  6241. (priv->capability & CAP_SHARED_KEY)) {
  6242. priv->assoc_request.auth_type = AUTH_SHARED_KEY;
  6243. priv->assoc_request.auth_key = priv->ieee->sec.active_key;
  6244. if ((priv->capability & CAP_PRIVACY_ON) &&
  6245. (priv->ieee->sec.level == SEC_LEVEL_1) &&
  6246. !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
  6247. ipw_send_wep_keys(priv, DCW_WEP_KEY_SEC_TYPE_WEP);
  6248. } else {
  6249. priv->assoc_request.auth_type = AUTH_OPEN;
  6250. priv->assoc_request.auth_key = 0;
  6251. }
  6252. if (priv->ieee->wpa_ie_len) {
  6253. priv->assoc_request.policy_support = 0x02; /* RSN active */
  6254. ipw_set_rsn_capa(priv, priv->ieee->wpa_ie,
  6255. priv->ieee->wpa_ie_len);
  6256. }
  6257. /*
  6258. * It is valid for our ieee device to support multiple modes, but
  6259. * when it comes to associating to a given network we have to choose
  6260. * just one mode.
  6261. */
  6262. if (network->mode & priv->ieee->mode & IEEE_A)
  6263. priv->assoc_request.ieee_mode = IPW_A_MODE;
  6264. else if (network->mode & priv->ieee->mode & IEEE_G)
  6265. priv->assoc_request.ieee_mode = IPW_G_MODE;
  6266. else if (network->mode & priv->ieee->mode & IEEE_B)
  6267. priv->assoc_request.ieee_mode = IPW_B_MODE;
  6268. priv->assoc_request.capability = network->capability;
  6269. if ((network->capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
  6270. && !(priv->config & CFG_PREAMBLE_LONG)) {
  6271. priv->assoc_request.preamble_length = DCT_FLAG_SHORT_PREAMBLE;
  6272. } else {
  6273. priv->assoc_request.preamble_length = DCT_FLAG_LONG_PREAMBLE;
  6274. /* Clear the short preamble if we won't be supporting it */
  6275. priv->assoc_request.capability &=
  6276. ~WLAN_CAPABILITY_SHORT_PREAMBLE;
  6277. }
  6278. /* Clear capability bits that aren't used in Ad Hoc */
  6279. if (priv->ieee->iw_mode == IW_MODE_ADHOC)
  6280. priv->assoc_request.capability &=
  6281. ~WLAN_CAPABILITY_SHORT_SLOT_TIME;
  6282. IPW_DEBUG_ASSOC("%sssocation attempt: '%s', channel %d, "
  6283. "802.11%c [%d], %s[:%s], enc=%s%s%s%c%c\n",
  6284. roaming ? "Rea" : "A",
  6285. escape_essid(priv->essid, priv->essid_len),
  6286. network->channel,
  6287. ipw_modes[priv->assoc_request.ieee_mode],
  6288. rates->num_rates,
  6289. (priv->assoc_request.preamble_length ==
  6290. DCT_FLAG_LONG_PREAMBLE) ? "long" : "short",
  6291. network->capability &
  6292. WLAN_CAPABILITY_SHORT_PREAMBLE ? "short" : "long",
  6293. priv->capability & CAP_PRIVACY_ON ? "on " : "off",
  6294. priv->capability & CAP_PRIVACY_ON ?
  6295. (priv->capability & CAP_SHARED_KEY ? "(shared)" :
  6296. "(open)") : "",
  6297. priv->capability & CAP_PRIVACY_ON ? " key=" : "",
  6298. priv->capability & CAP_PRIVACY_ON ?
  6299. '1' + priv->ieee->sec.active_key : '.',
  6300. priv->capability & CAP_PRIVACY_ON ? '.' : ' ');
  6301. priv->assoc_request.beacon_interval = network->beacon_interval;
  6302. if ((priv->ieee->iw_mode == IW_MODE_ADHOC) &&
  6303. (network->time_stamp[0] == 0) && (network->time_stamp[1] == 0)) {
  6304. priv->assoc_request.assoc_type = HC_IBSS_START;
  6305. priv->assoc_request.assoc_tsf_msw = 0;
  6306. priv->assoc_request.assoc_tsf_lsw = 0;
  6307. } else {
  6308. if (unlikely(roaming))
  6309. priv->assoc_request.assoc_type = HC_REASSOCIATE;
  6310. else
  6311. priv->assoc_request.assoc_type = HC_ASSOCIATE;
  6312. priv->assoc_request.assoc_tsf_msw = network->time_stamp[1];
  6313. priv->assoc_request.assoc_tsf_lsw = network->time_stamp[0];
  6314. }
  6315. memcpy(priv->assoc_request.bssid, network->bssid, ETH_ALEN);
  6316. if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
  6317. memset(&priv->assoc_request.dest, 0xFF, ETH_ALEN);
  6318. priv->assoc_request.atim_window = network->atim_window;
  6319. } else {
  6320. memcpy(priv->assoc_request.dest, network->bssid, ETH_ALEN);
  6321. priv->assoc_request.atim_window = 0;
  6322. }
  6323. priv->assoc_request.listen_interval = network->listen_interval;
  6324. err = ipw_send_ssid(priv, priv->essid, priv->essid_len);
  6325. if (err) {
  6326. IPW_DEBUG_HC("Attempt to send SSID command failed.\n");
  6327. return err;
  6328. }
  6329. rates->ieee_mode = priv->assoc_request.ieee_mode;
  6330. rates->purpose = IPW_RATE_CONNECT;
  6331. ipw_send_supported_rates(priv, rates);
  6332. if (priv->assoc_request.ieee_mode == IPW_G_MODE)
  6333. priv->sys_config.dot11g_auto_detection = 1;
  6334. else
  6335. priv->sys_config.dot11g_auto_detection = 0;
  6336. if (priv->ieee->iw_mode == IW_MODE_ADHOC)
  6337. priv->sys_config.answer_broadcast_ssid_probe = 1;
  6338. else
  6339. priv->sys_config.answer_broadcast_ssid_probe = 0;
  6340. err = ipw_send_system_config(priv, &priv->sys_config);
  6341. if (err) {
  6342. IPW_DEBUG_HC("Attempt to send sys config command failed.\n");
  6343. return err;
  6344. }
  6345. IPW_DEBUG_ASSOC("Association sensitivity: %d\n", network->stats.rssi);
  6346. err = ipw_set_sensitivity(priv, network->stats.rssi + IPW_RSSI_TO_DBM);
  6347. if (err) {
  6348. IPW_DEBUG_HC("Attempt to send associate command failed.\n");
  6349. return err;
  6350. }
  6351. /*
  6352. * If preemption is enabled, it is possible for the association
  6353. * to complete before we return from ipw_send_associate. Therefore
  6354. * we have to be sure and update our priviate data first.
  6355. */
  6356. priv->channel = network->channel;
  6357. memcpy(priv->bssid, network->bssid, ETH_ALEN);
  6358. priv->status |= STATUS_ASSOCIATING;
  6359. priv->status &= ~STATUS_SECURITY_UPDATED;
  6360. priv->assoc_network = network;
  6361. #ifdef CONFIG_IPW_QOS
  6362. ipw_qos_association(priv, network);
  6363. #endif
  6364. err = ipw_send_associate(priv, &priv->assoc_request);
  6365. if (err) {
  6366. IPW_DEBUG_HC("Attempt to send associate command failed.\n");
  6367. return err;
  6368. }
  6369. IPW_DEBUG(IPW_DL_STATE, "associating: '%s' " MAC_FMT " \n",
  6370. escape_essid(priv->essid, priv->essid_len),
  6371. MAC_ARG(priv->bssid));
  6372. return 0;
  6373. }
  6374. static void ipw_roam(void *data)
  6375. {
  6376. struct ipw_priv *priv = data;
  6377. struct ieee80211_network *network = NULL;
  6378. struct ipw_network_match match = {
  6379. .network = priv->assoc_network
  6380. };
  6381. /* The roaming process is as follows:
  6382. *
  6383. * 1. Missed beacon threshold triggers the roaming process by
  6384. * setting the status ROAM bit and requesting a scan.
  6385. * 2. When the scan completes, it schedules the ROAM work
  6386. * 3. The ROAM work looks at all of the known networks for one that
  6387. * is a better network than the currently associated. If none
  6388. * found, the ROAM process is over (ROAM bit cleared)
  6389. * 4. If a better network is found, a disassociation request is
  6390. * sent.
  6391. * 5. When the disassociation completes, the roam work is again
  6392. * scheduled. The second time through, the driver is no longer
  6393. * associated, and the newly selected network is sent an
  6394. * association request.
  6395. * 6. At this point ,the roaming process is complete and the ROAM
  6396. * status bit is cleared.
  6397. */
  6398. /* If we are no longer associated, and the roaming bit is no longer
  6399. * set, then we are not actively roaming, so just return */
  6400. if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ROAMING)))
  6401. return;
  6402. if (priv->status & STATUS_ASSOCIATED) {
  6403. /* First pass through ROAM process -- look for a better
  6404. * network */
  6405. unsigned long flags;
  6406. u8 rssi = priv->assoc_network->stats.rssi;
  6407. priv->assoc_network->stats.rssi = -128;
  6408. spin_lock_irqsave(&priv->ieee->lock, flags);
  6409. list_for_each_entry(network, &priv->ieee->network_list, list) {
  6410. if (network != priv->assoc_network)
  6411. ipw_best_network(priv, &match, network, 1);
  6412. }
  6413. spin_unlock_irqrestore(&priv->ieee->lock, flags);
  6414. priv->assoc_network->stats.rssi = rssi;
  6415. if (match.network == priv->assoc_network) {
  6416. IPW_DEBUG_ASSOC("No better APs in this network to "
  6417. "roam to.\n");
  6418. priv->status &= ~STATUS_ROAMING;
  6419. ipw_debug_config(priv);
  6420. return;
  6421. }
  6422. ipw_send_disassociate(priv, 1);
  6423. priv->assoc_network = match.network;
  6424. return;
  6425. }
  6426. /* Second pass through ROAM process -- request association */
  6427. ipw_compatible_rates(priv, priv->assoc_network, &match.rates);
  6428. ipw_associate_network(priv, priv->assoc_network, &match.rates, 1);
  6429. priv->status &= ~STATUS_ROAMING;
  6430. }
  6431. static void ipw_bg_roam(void *data)
  6432. {
  6433. struct ipw_priv *priv = data;
  6434. down(&priv->sem);
  6435. ipw_roam(data);
  6436. up(&priv->sem);
  6437. }
  6438. static int ipw_associate(void *data)
  6439. {
  6440. struct ipw_priv *priv = data;
  6441. struct ieee80211_network *network = NULL;
  6442. struct ipw_network_match match = {
  6443. .network = NULL
  6444. };
  6445. struct ipw_supported_rates *rates;
  6446. struct list_head *element;
  6447. unsigned long flags;
  6448. if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
  6449. IPW_DEBUG_ASSOC("Not attempting association (monitor mode)\n");
  6450. return 0;
  6451. }
  6452. if (priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
  6453. IPW_DEBUG_ASSOC("Not attempting association (already in "
  6454. "progress)\n");
  6455. return 0;
  6456. }
  6457. if (!ipw_is_init(priv) || (priv->status & STATUS_SCANNING)) {
  6458. IPW_DEBUG_ASSOC("Not attempting association (scanning or not "
  6459. "initialized)\n");
  6460. return 0;
  6461. }
  6462. if (!(priv->config & CFG_ASSOCIATE) &&
  6463. !(priv->config & (CFG_STATIC_ESSID |
  6464. CFG_STATIC_CHANNEL | CFG_STATIC_BSSID))) {
  6465. IPW_DEBUG_ASSOC("Not attempting association (associate=0)\n");
  6466. return 0;
  6467. }
  6468. /* Protect our use of the network_list */
  6469. spin_lock_irqsave(&priv->ieee->lock, flags);
  6470. list_for_each_entry(network, &priv->ieee->network_list, list)
  6471. ipw_best_network(priv, &match, network, 0);
  6472. network = match.network;
  6473. rates = &match.rates;
  6474. if (network == NULL &&
  6475. priv->ieee->iw_mode == IW_MODE_ADHOC &&
  6476. priv->config & CFG_ADHOC_CREATE &&
  6477. priv->config & CFG_STATIC_ESSID &&
  6478. priv->config & CFG_STATIC_CHANNEL &&
  6479. !list_empty(&priv->ieee->network_free_list)) {
  6480. element = priv->ieee->network_free_list.next;
  6481. network = list_entry(element, struct ieee80211_network, list);
  6482. ipw_adhoc_create(priv, network);
  6483. rates = &priv->rates;
  6484. list_del(element);
  6485. list_add_tail(&network->list, &priv->ieee->network_list);
  6486. }
  6487. spin_unlock_irqrestore(&priv->ieee->lock, flags);
  6488. /* If we reached the end of the list, then we don't have any valid
  6489. * matching APs */
  6490. if (!network) {
  6491. ipw_debug_config(priv);
  6492. if (!(priv->status & STATUS_SCANNING)) {
  6493. if (!(priv->config & CFG_SPEED_SCAN))
  6494. queue_delayed_work(priv->workqueue,
  6495. &priv->request_scan,
  6496. SCAN_INTERVAL);
  6497. else
  6498. queue_work(priv->workqueue,
  6499. &priv->request_scan);
  6500. }
  6501. return 0;
  6502. }
  6503. ipw_associate_network(priv, network, rates, 0);
  6504. return 1;
  6505. }
  6506. static void ipw_bg_associate(void *data)
  6507. {
  6508. struct ipw_priv *priv = data;
  6509. down(&priv->sem);
  6510. ipw_associate(data);
  6511. up(&priv->sem);
  6512. }
  6513. static void ipw_rebuild_decrypted_skb(struct ipw_priv *priv,
  6514. struct sk_buff *skb)
  6515. {
  6516. struct ieee80211_hdr *hdr;
  6517. u16 fc;
  6518. hdr = (struct ieee80211_hdr *)skb->data;
  6519. fc = le16_to_cpu(hdr->frame_ctl);
  6520. if (!(fc & IEEE80211_FCTL_PROTECTED))
  6521. return;
  6522. fc &= ~IEEE80211_FCTL_PROTECTED;
  6523. hdr->frame_ctl = cpu_to_le16(fc);
  6524. switch (priv->ieee->sec.level) {
  6525. case SEC_LEVEL_3:
  6526. /* Remove CCMP HDR */
  6527. memmove(skb->data + IEEE80211_3ADDR_LEN,
  6528. skb->data + IEEE80211_3ADDR_LEN + 8,
  6529. skb->len - IEEE80211_3ADDR_LEN - 8);
  6530. if (fc & IEEE80211_FCTL_MOREFRAGS)
  6531. skb_trim(skb, skb->len - 16); /* 2*MIC */
  6532. else
  6533. skb_trim(skb, skb->len - 8); /* MIC */
  6534. break;
  6535. case SEC_LEVEL_2:
  6536. break;
  6537. case SEC_LEVEL_1:
  6538. /* Remove IV */
  6539. memmove(skb->data + IEEE80211_3ADDR_LEN,
  6540. skb->data + IEEE80211_3ADDR_LEN + 4,
  6541. skb->len - IEEE80211_3ADDR_LEN - 4);
  6542. if (fc & IEEE80211_FCTL_MOREFRAGS)
  6543. skb_trim(skb, skb->len - 8); /* 2*ICV */
  6544. else
  6545. skb_trim(skb, skb->len - 4); /* ICV */
  6546. break;
  6547. case SEC_LEVEL_0:
  6548. break;
  6549. default:
  6550. printk(KERN_ERR "Unknow security level %d\n",
  6551. priv->ieee->sec.level);
  6552. break;
  6553. }
  6554. }
  6555. static void ipw_handle_data_packet(struct ipw_priv *priv,
  6556. struct ipw_rx_mem_buffer *rxb,
  6557. struct ieee80211_rx_stats *stats)
  6558. {
  6559. struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)rxb->skb->data;
  6560. /* We received data from the HW, so stop the watchdog */
  6561. priv->net_dev->trans_start = jiffies;
  6562. /* We only process data packets if the
  6563. * interface is open */
  6564. if (unlikely((le16_to_cpu(pkt->u.frame.length) + IPW_RX_FRAME_SIZE) >
  6565. skb_tailroom(rxb->skb))) {
  6566. priv->ieee->stats.rx_errors++;
  6567. priv->wstats.discard.misc++;
  6568. IPW_DEBUG_DROP("Corruption detected! Oh no!\n");
  6569. return;
  6570. } else if (unlikely(!netif_running(priv->net_dev))) {
  6571. priv->ieee->stats.rx_dropped++;
  6572. priv->wstats.discard.misc++;
  6573. IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
  6574. return;
  6575. }
  6576. /* Advance skb->data to the start of the actual payload */
  6577. skb_reserve(rxb->skb, offsetof(struct ipw_rx_packet, u.frame.data));
  6578. /* Set the size of the skb to the size of the frame */
  6579. skb_put(rxb->skb, le16_to_cpu(pkt->u.frame.length));
  6580. IPW_DEBUG_RX("Rx packet of %d bytes.\n", rxb->skb->len);
  6581. /* HW decrypt will not clear the WEP bit, MIC, PN, etc. */
  6582. if (!priv->ieee->host_decrypt)
  6583. ipw_rebuild_decrypted_skb(priv, rxb->skb);
  6584. if (!ieee80211_rx(priv->ieee, rxb->skb, stats))
  6585. priv->ieee->stats.rx_errors++;
  6586. else { /* ieee80211_rx succeeded, so it now owns the SKB */
  6587. rxb->skb = NULL;
  6588. __ipw_led_activity_on(priv);
  6589. }
  6590. }
  6591. static inline int is_network_packet(struct ipw_priv *priv,
  6592. struct ieee80211_hdr_4addr *header)
  6593. {
  6594. /* Filter incoming packets to determine if they are targetted toward
  6595. * this network, discarding packets coming from ourselves */
  6596. switch (priv->ieee->iw_mode) {
  6597. case IW_MODE_ADHOC: /* Header: Dest. | Source | BSSID */
  6598. /* packets from our adapter are dropped (echo) */
  6599. if (!memcmp(header->addr2, priv->net_dev->dev_addr, ETH_ALEN))
  6600. return 0;
  6601. /* multicast packets to our IBSS go through */
  6602. if (is_multicast_ether_addr(header->addr1))
  6603. return !memcmp(header->addr3, priv->bssid, ETH_ALEN);
  6604. /* packets to our adapter go through */
  6605. return !memcmp(header->addr1, priv->net_dev->dev_addr,
  6606. ETH_ALEN);
  6607. case IW_MODE_INFRA: /* Header: Dest. | AP{BSSID} | Source */
  6608. /* packets from our adapter are dropped (echo) */
  6609. if (!memcmp(header->addr3, priv->net_dev->dev_addr, ETH_ALEN))
  6610. return 0;
  6611. /* {broad,multi}cast packets to our IBSS go through */
  6612. if (is_multicast_ether_addr(header->addr1))
  6613. return !memcmp(header->addr2, priv->bssid, ETH_ALEN);
  6614. /* packets to our adapter go through */
  6615. return !memcmp(header->addr1, priv->net_dev->dev_addr,
  6616. ETH_ALEN);
  6617. }
  6618. return 1;
  6619. }
  6620. #define IPW_PACKET_RETRY_TIME HZ
  6621. static inline int is_duplicate_packet(struct ipw_priv *priv,
  6622. struct ieee80211_hdr_4addr *header)
  6623. {
  6624. u16 sc = le16_to_cpu(header->seq_ctl);
  6625. u16 seq = WLAN_GET_SEQ_SEQ(sc);
  6626. u16 frag = WLAN_GET_SEQ_FRAG(sc);
  6627. u16 *last_seq, *last_frag;
  6628. unsigned long *last_time;
  6629. switch (priv->ieee->iw_mode) {
  6630. case IW_MODE_ADHOC:
  6631. {
  6632. struct list_head *p;
  6633. struct ipw_ibss_seq *entry = NULL;
  6634. u8 *mac = header->addr2;
  6635. int index = mac[5] % IPW_IBSS_MAC_HASH_SIZE;
  6636. __list_for_each(p, &priv->ibss_mac_hash[index]) {
  6637. entry =
  6638. list_entry(p, struct ipw_ibss_seq, list);
  6639. if (!memcmp(entry->mac, mac, ETH_ALEN))
  6640. break;
  6641. }
  6642. if (p == &priv->ibss_mac_hash[index]) {
  6643. entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
  6644. if (!entry) {
  6645. IPW_ERROR
  6646. ("Cannot malloc new mac entry\n");
  6647. return 0;
  6648. }
  6649. memcpy(entry->mac, mac, ETH_ALEN);
  6650. entry->seq_num = seq;
  6651. entry->frag_num = frag;
  6652. entry->packet_time = jiffies;
  6653. list_add(&entry->list,
  6654. &priv->ibss_mac_hash[index]);
  6655. return 0;
  6656. }
  6657. last_seq = &entry->seq_num;
  6658. last_frag = &entry->frag_num;
  6659. last_time = &entry->packet_time;
  6660. break;
  6661. }
  6662. case IW_MODE_INFRA:
  6663. last_seq = &priv->last_seq_num;
  6664. last_frag = &priv->last_frag_num;
  6665. last_time = &priv->last_packet_time;
  6666. break;
  6667. default:
  6668. return 0;
  6669. }
  6670. if ((*last_seq == seq) &&
  6671. time_after(*last_time + IPW_PACKET_RETRY_TIME, jiffies)) {
  6672. if (*last_frag == frag)
  6673. goto drop;
  6674. if (*last_frag + 1 != frag)
  6675. /* out-of-order fragment */
  6676. goto drop;
  6677. } else
  6678. *last_seq = seq;
  6679. *last_frag = frag;
  6680. *last_time = jiffies;
  6681. return 0;
  6682. drop:
  6683. /* Comment this line now since we observed the card receives
  6684. * duplicate packets but the FCTL_RETRY bit is not set in the
  6685. * IBSS mode with fragmentation enabled.
  6686. BUG_ON(!(le16_to_cpu(header->frame_ctl) & IEEE80211_FCTL_RETRY)); */
  6687. return 1;
  6688. }
  6689. static void ipw_handle_mgmt_packet(struct ipw_priv *priv,
  6690. struct ipw_rx_mem_buffer *rxb,
  6691. struct ieee80211_rx_stats *stats)
  6692. {
  6693. struct sk_buff *skb = rxb->skb;
  6694. struct ipw_rx_packet *pkt = (struct ipw_rx_packet *)skb->data;
  6695. struct ieee80211_hdr_4addr *header = (struct ieee80211_hdr_4addr *)
  6696. (skb->data + IPW_RX_FRAME_SIZE);
  6697. ieee80211_rx_mgt(priv->ieee, header, stats);
  6698. if (priv->ieee->iw_mode == IW_MODE_ADHOC &&
  6699. ((WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
  6700. IEEE80211_STYPE_PROBE_RESP) ||
  6701. (WLAN_FC_GET_STYPE(le16_to_cpu(header->frame_ctl)) ==
  6702. IEEE80211_STYPE_BEACON))) {
  6703. if (!memcmp(header->addr3, priv->bssid, ETH_ALEN))
  6704. ipw_add_station(priv, header->addr2);
  6705. }
  6706. if (priv->config & CFG_NET_STATS) {
  6707. IPW_DEBUG_HC("sending stat packet\n");
  6708. /* Set the size of the skb to the size of the full
  6709. * ipw header and 802.11 frame */
  6710. skb_put(skb, le16_to_cpu(pkt->u.frame.length) +
  6711. IPW_RX_FRAME_SIZE);
  6712. /* Advance past the ipw packet header to the 802.11 frame */
  6713. skb_pull(skb, IPW_RX_FRAME_SIZE);
  6714. /* Push the ieee80211_rx_stats before the 802.11 frame */
  6715. memcpy(skb_push(skb, sizeof(*stats)), stats, sizeof(*stats));
  6716. skb->dev = priv->ieee->dev;
  6717. /* Point raw at the ieee80211_stats */
  6718. skb->mac.raw = skb->data;
  6719. skb->pkt_type = PACKET_OTHERHOST;
  6720. skb->protocol = __constant_htons(ETH_P_80211_STATS);
  6721. memset(skb->cb, 0, sizeof(rxb->skb->cb));
  6722. netif_rx(skb);
  6723. rxb->skb = NULL;
  6724. }
  6725. }
  6726. /*
  6727. * Main entry function for recieving a packet with 80211 headers. This
  6728. * should be called when ever the FW has notified us that there is a new
  6729. * skb in the recieve queue.
  6730. */
  6731. static void ipw_rx(struct ipw_priv *priv)
  6732. {
  6733. struct ipw_rx_mem_buffer *rxb;
  6734. struct ipw_rx_packet *pkt;
  6735. struct ieee80211_hdr_4addr *header;
  6736. u32 r, w, i;
  6737. u8 network_packet;
  6738. r = ipw_read32(priv, IPW_RX_READ_INDEX);
  6739. w = ipw_read32(priv, IPW_RX_WRITE_INDEX);
  6740. i = (priv->rxq->processed + 1) % RX_QUEUE_SIZE;
  6741. while (i != r) {
  6742. rxb = priv->rxq->queue[i];
  6743. #ifdef CONFIG_IPW_DEBUG
  6744. if (unlikely(rxb == NULL)) {
  6745. printk(KERN_CRIT "Queue not allocated!\n");
  6746. break;
  6747. }
  6748. #endif
  6749. priv->rxq->queue[i] = NULL;
  6750. pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
  6751. IPW_RX_BUF_SIZE,
  6752. PCI_DMA_FROMDEVICE);
  6753. pkt = (struct ipw_rx_packet *)rxb->skb->data;
  6754. IPW_DEBUG_RX("Packet: type=%02X seq=%02X bits=%02X\n",
  6755. pkt->header.message_type,
  6756. pkt->header.rx_seq_num, pkt->header.control_bits);
  6757. switch (pkt->header.message_type) {
  6758. case RX_FRAME_TYPE: /* 802.11 frame */ {
  6759. struct ieee80211_rx_stats stats = {
  6760. .rssi =
  6761. le16_to_cpu(pkt->u.frame.rssi_dbm) -
  6762. IPW_RSSI_TO_DBM,
  6763. .signal =
  6764. le16_to_cpu(pkt->u.frame.signal),
  6765. .noise =
  6766. le16_to_cpu(pkt->u.frame.noise),
  6767. .rate = pkt->u.frame.rate,
  6768. .mac_time = jiffies,
  6769. .received_channel =
  6770. pkt->u.frame.received_channel,
  6771. .freq =
  6772. (pkt->u.frame.
  6773. control & (1 << 0)) ?
  6774. IEEE80211_24GHZ_BAND :
  6775. IEEE80211_52GHZ_BAND,
  6776. .len = le16_to_cpu(pkt->u.frame.length),
  6777. };
  6778. if (stats.rssi != 0)
  6779. stats.mask |= IEEE80211_STATMASK_RSSI;
  6780. if (stats.signal != 0)
  6781. stats.mask |= IEEE80211_STATMASK_SIGNAL;
  6782. if (stats.noise != 0)
  6783. stats.mask |= IEEE80211_STATMASK_NOISE;
  6784. if (stats.rate != 0)
  6785. stats.mask |= IEEE80211_STATMASK_RATE;
  6786. priv->rx_packets++;
  6787. #ifdef CONFIG_IPW2200_MONITOR
  6788. if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
  6789. ipw_handle_data_packet(priv, rxb,
  6790. &stats);
  6791. break;
  6792. }
  6793. #endif
  6794. header =
  6795. (struct ieee80211_hdr_4addr *)(rxb->skb->
  6796. data +
  6797. IPW_RX_FRAME_SIZE);
  6798. /* TODO: Check Ad-Hoc dest/source and make sure
  6799. * that we are actually parsing these packets
  6800. * correctly -- we should probably use the
  6801. * frame control of the packet and disregard
  6802. * the current iw_mode */
  6803. network_packet =
  6804. is_network_packet(priv, header);
  6805. if (network_packet && priv->assoc_network) {
  6806. priv->assoc_network->stats.rssi =
  6807. stats.rssi;
  6808. average_add(&priv->average_rssi,
  6809. stats.rssi);
  6810. priv->last_rx_rssi = stats.rssi;
  6811. }
  6812. IPW_DEBUG_RX("Frame: len=%u\n",
  6813. le16_to_cpu(pkt->u.frame.length));
  6814. if (le16_to_cpu(pkt->u.frame.length) <
  6815. frame_hdr_len(header)) {
  6816. IPW_DEBUG_DROP
  6817. ("Received packet is too small. "
  6818. "Dropping.\n");
  6819. priv->ieee->stats.rx_errors++;
  6820. priv->wstats.discard.misc++;
  6821. break;
  6822. }
  6823. switch (WLAN_FC_GET_TYPE
  6824. (le16_to_cpu(header->frame_ctl))) {
  6825. case IEEE80211_FTYPE_MGMT:
  6826. ipw_handle_mgmt_packet(priv, rxb,
  6827. &stats);
  6828. break;
  6829. case IEEE80211_FTYPE_CTL:
  6830. break;
  6831. case IEEE80211_FTYPE_DATA:
  6832. if (unlikely(!network_packet ||
  6833. is_duplicate_packet(priv,
  6834. header)))
  6835. {
  6836. IPW_DEBUG_DROP("Dropping: "
  6837. MAC_FMT ", "
  6838. MAC_FMT ", "
  6839. MAC_FMT "\n",
  6840. MAC_ARG(header->
  6841. addr1),
  6842. MAC_ARG(header->
  6843. addr2),
  6844. MAC_ARG(header->
  6845. addr3));
  6846. break;
  6847. }
  6848. ipw_handle_data_packet(priv, rxb,
  6849. &stats);
  6850. break;
  6851. }
  6852. break;
  6853. }
  6854. case RX_HOST_NOTIFICATION_TYPE:{
  6855. IPW_DEBUG_RX
  6856. ("Notification: subtype=%02X flags=%02X size=%d\n",
  6857. pkt->u.notification.subtype,
  6858. pkt->u.notification.flags,
  6859. pkt->u.notification.size);
  6860. ipw_rx_notification(priv, &pkt->u.notification);
  6861. break;
  6862. }
  6863. default:
  6864. IPW_DEBUG_RX("Bad Rx packet of type %d\n",
  6865. pkt->header.message_type);
  6866. break;
  6867. }
  6868. /* For now we just don't re-use anything. We can tweak this
  6869. * later to try and re-use notification packets and SKBs that
  6870. * fail to Rx correctly */
  6871. if (rxb->skb != NULL) {
  6872. dev_kfree_skb_any(rxb->skb);
  6873. rxb->skb = NULL;
  6874. }
  6875. pci_unmap_single(priv->pci_dev, rxb->dma_addr,
  6876. IPW_RX_BUF_SIZE, PCI_DMA_FROMDEVICE);
  6877. list_add_tail(&rxb->list, &priv->rxq->rx_used);
  6878. i = (i + 1) % RX_QUEUE_SIZE;
  6879. }
  6880. /* Backtrack one entry */
  6881. priv->rxq->processed = (i ? i : RX_QUEUE_SIZE) - 1;
  6882. ipw_rx_queue_restock(priv);
  6883. }
  6884. #define DEFAULT_RTS_THRESHOLD 2304U
  6885. #define MIN_RTS_THRESHOLD 1U
  6886. #define MAX_RTS_THRESHOLD 2304U
  6887. #define DEFAULT_BEACON_INTERVAL 100U
  6888. #define DEFAULT_SHORT_RETRY_LIMIT 7U
  6889. #define DEFAULT_LONG_RETRY_LIMIT 4U
  6890. static int ipw_sw_reset(struct ipw_priv *priv, int init)
  6891. {
  6892. int band, modulation;
  6893. int old_mode = priv->ieee->iw_mode;
  6894. /* Initialize module parameter values here */
  6895. priv->config = 0;
  6896. /* We default to disabling the LED code as right now it causes
  6897. * too many systems to lock up... */
  6898. if (!led)
  6899. priv->config |= CFG_NO_LED;
  6900. if (associate)
  6901. priv->config |= CFG_ASSOCIATE;
  6902. else
  6903. IPW_DEBUG_INFO("Auto associate disabled.\n");
  6904. if (auto_create)
  6905. priv->config |= CFG_ADHOC_CREATE;
  6906. else
  6907. IPW_DEBUG_INFO("Auto adhoc creation disabled.\n");
  6908. if (disable) {
  6909. priv->status |= STATUS_RF_KILL_SW;
  6910. IPW_DEBUG_INFO("Radio disabled.\n");
  6911. }
  6912. if (channel != 0) {
  6913. priv->config |= CFG_STATIC_CHANNEL;
  6914. priv->channel = channel;
  6915. IPW_DEBUG_INFO("Bind to static channel %d\n", channel);
  6916. /* TODO: Validate that provided channel is in range */
  6917. }
  6918. #ifdef CONFIG_IPW_QOS
  6919. ipw_qos_init(priv, qos_enable, qos_burst_enable,
  6920. burst_duration_CCK, burst_duration_OFDM);
  6921. #endif /* CONFIG_IPW_QOS */
  6922. switch (mode) {
  6923. case 1:
  6924. priv->ieee->iw_mode = IW_MODE_ADHOC;
  6925. priv->net_dev->type = ARPHRD_ETHER;
  6926. break;
  6927. #ifdef CONFIG_IPW2200_MONITOR
  6928. case 2:
  6929. priv->ieee->iw_mode = IW_MODE_MONITOR;
  6930. priv->net_dev->type = ARPHRD_IEEE80211;
  6931. break;
  6932. #endif
  6933. default:
  6934. case 0:
  6935. priv->net_dev->type = ARPHRD_ETHER;
  6936. priv->ieee->iw_mode = IW_MODE_INFRA;
  6937. break;
  6938. }
  6939. if (hwcrypto) {
  6940. priv->ieee->host_encrypt = 0;
  6941. priv->ieee->host_encrypt_msdu = 0;
  6942. priv->ieee->host_decrypt = 0;
  6943. }
  6944. IPW_DEBUG_INFO("Hardware crypto [%s]\n", hwcrypto ? "on" : "off");
  6945. /* IPW2200/2915 is abled to do hardware fragmentation. */
  6946. priv->ieee->host_open_frag = 0;
  6947. if ((priv->pci_dev->device == 0x4223) ||
  6948. (priv->pci_dev->device == 0x4224)) {
  6949. if (init)
  6950. printk(KERN_INFO DRV_NAME
  6951. ": Detected Intel PRO/Wireless 2915ABG Network "
  6952. "Connection\n");
  6953. priv->ieee->abg_true = 1;
  6954. band = IEEE80211_52GHZ_BAND | IEEE80211_24GHZ_BAND;
  6955. modulation = IEEE80211_OFDM_MODULATION |
  6956. IEEE80211_CCK_MODULATION;
  6957. priv->adapter = IPW_2915ABG;
  6958. priv->ieee->mode = IEEE_A | IEEE_G | IEEE_B;
  6959. } else {
  6960. if (init)
  6961. printk(KERN_INFO DRV_NAME
  6962. ": Detected Intel PRO/Wireless 2200BG Network "
  6963. "Connection\n");
  6964. priv->ieee->abg_true = 0;
  6965. band = IEEE80211_24GHZ_BAND;
  6966. modulation = IEEE80211_OFDM_MODULATION |
  6967. IEEE80211_CCK_MODULATION;
  6968. priv->adapter = IPW_2200BG;
  6969. priv->ieee->mode = IEEE_G | IEEE_B;
  6970. }
  6971. priv->ieee->freq_band = band;
  6972. priv->ieee->modulation = modulation;
  6973. priv->rates_mask = IEEE80211_DEFAULT_RATES_MASK;
  6974. priv->disassociate_threshold = IPW_MB_DISASSOCIATE_THRESHOLD_DEFAULT;
  6975. priv->roaming_threshold = IPW_MB_ROAMING_THRESHOLD_DEFAULT;
  6976. priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
  6977. priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
  6978. priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
  6979. /* If power management is turned on, default to AC mode */
  6980. priv->power_mode = IPW_POWER_AC;
  6981. priv->tx_power = IPW_TX_POWER_DEFAULT;
  6982. return old_mode == priv->ieee->iw_mode;
  6983. }
  6984. /*
  6985. * This file defines the Wireless Extension handlers. It does not
  6986. * define any methods of hardware manipulation and relies on the
  6987. * functions defined in ipw_main to provide the HW interaction.
  6988. *
  6989. * The exception to this is the use of the ipw_get_ordinal()
  6990. * function used to poll the hardware vs. making unecessary calls.
  6991. *
  6992. */
  6993. static int ipw_wx_get_name(struct net_device *dev,
  6994. struct iw_request_info *info,
  6995. union iwreq_data *wrqu, char *extra)
  6996. {
  6997. struct ipw_priv *priv = ieee80211_priv(dev);
  6998. down(&priv->sem);
  6999. if (priv->status & STATUS_RF_KILL_MASK)
  7000. strcpy(wrqu->name, "radio off");
  7001. else if (!(priv->status & STATUS_ASSOCIATED))
  7002. strcpy(wrqu->name, "unassociated");
  7003. else
  7004. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11%c",
  7005. ipw_modes[priv->assoc_request.ieee_mode]);
  7006. IPW_DEBUG_WX("Name: %s\n", wrqu->name);
  7007. up(&priv->sem);
  7008. return 0;
  7009. }
  7010. static int ipw_set_channel(struct ipw_priv *priv, u8 channel)
  7011. {
  7012. if (channel == 0) {
  7013. IPW_DEBUG_INFO("Setting channel to ANY (0)\n");
  7014. priv->config &= ~CFG_STATIC_CHANNEL;
  7015. IPW_DEBUG_ASSOC("Attempting to associate with new "
  7016. "parameters.\n");
  7017. ipw_associate(priv);
  7018. return 0;
  7019. }
  7020. priv->config |= CFG_STATIC_CHANNEL;
  7021. if (priv->channel == channel) {
  7022. IPW_DEBUG_INFO("Request to set channel to current value (%d)\n",
  7023. channel);
  7024. return 0;
  7025. }
  7026. IPW_DEBUG_INFO("Setting channel to %i\n", (int)channel);
  7027. priv->channel = channel;
  7028. #ifdef CONFIG_IPW2200_MONITOR
  7029. if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
  7030. int i;
  7031. if (priv->status & STATUS_SCANNING) {
  7032. IPW_DEBUG_SCAN("Scan abort triggered due to "
  7033. "channel change.\n");
  7034. ipw_abort_scan(priv);
  7035. }
  7036. for (i = 1000; i && (priv->status & STATUS_SCANNING); i--)
  7037. udelay(10);
  7038. if (priv->status & STATUS_SCANNING)
  7039. IPW_DEBUG_SCAN("Still scanning...\n");
  7040. else
  7041. IPW_DEBUG_SCAN("Took %dms to abort current scan\n",
  7042. 1000 - i);
  7043. return 0;
  7044. }
  7045. #endif /* CONFIG_IPW2200_MONITOR */
  7046. /* Network configuration changed -- force [re]association */
  7047. IPW_DEBUG_ASSOC("[re]association triggered due to channel change.\n");
  7048. if (!ipw_disassociate(priv))
  7049. ipw_associate(priv);
  7050. return 0;
  7051. }
  7052. static int ipw_wx_set_freq(struct net_device *dev,
  7053. struct iw_request_info *info,
  7054. union iwreq_data *wrqu, char *extra)
  7055. {
  7056. struct ipw_priv *priv = ieee80211_priv(dev);
  7057. const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
  7058. struct iw_freq *fwrq = &wrqu->freq;
  7059. int ret = 0, i;
  7060. u8 channel;
  7061. if (fwrq->m == 0) {
  7062. IPW_DEBUG_WX("SET Freq/Channel -> any\n");
  7063. down(&priv->sem);
  7064. ret = ipw_set_channel(priv, 0);
  7065. up(&priv->sem);
  7066. return ret;
  7067. }
  7068. /* if setting by freq convert to channel */
  7069. if (fwrq->e == 1) {
  7070. channel = ieee80211_freq_to_channel(priv->ieee, fwrq->m);
  7071. if (channel == 0)
  7072. return -EINVAL;
  7073. } else
  7074. channel = fwrq->m;
  7075. if (!ieee80211_is_valid_channel(priv->ieee, channel))
  7076. return -EINVAL;
  7077. if (priv->ieee->iw_mode == IW_MODE_ADHOC && priv->ieee->mode & IEEE_A) {
  7078. i = ieee80211_channel_to_index(priv->ieee, channel);
  7079. if (i == -1)
  7080. return -EINVAL;
  7081. if (geo->a[i].flags & IEEE80211_CH_PASSIVE_ONLY) {
  7082. IPW_DEBUG_WX("Invalid Ad-Hoc channel for 802.11a\n");
  7083. return -EINVAL;
  7084. }
  7085. }
  7086. IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
  7087. down(&priv->sem);
  7088. ret = ipw_set_channel(priv, channel);
  7089. up(&priv->sem);
  7090. return ret;
  7091. }
  7092. static int ipw_wx_get_freq(struct net_device *dev,
  7093. struct iw_request_info *info,
  7094. union iwreq_data *wrqu, char *extra)
  7095. {
  7096. struct ipw_priv *priv = ieee80211_priv(dev);
  7097. wrqu->freq.e = 0;
  7098. /* If we are associated, trying to associate, or have a statically
  7099. * configured CHANNEL then return that; otherwise return ANY */
  7100. down(&priv->sem);
  7101. if (priv->config & CFG_STATIC_CHANNEL ||
  7102. priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED))
  7103. wrqu->freq.m = priv->channel;
  7104. else
  7105. wrqu->freq.m = 0;
  7106. up(&priv->sem);
  7107. IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
  7108. return 0;
  7109. }
  7110. static int ipw_wx_set_mode(struct net_device *dev,
  7111. struct iw_request_info *info,
  7112. union iwreq_data *wrqu, char *extra)
  7113. {
  7114. struct ipw_priv *priv = ieee80211_priv(dev);
  7115. int err = 0;
  7116. IPW_DEBUG_WX("Set MODE: %d\n", wrqu->mode);
  7117. switch (wrqu->mode) {
  7118. #ifdef CONFIG_IPW2200_MONITOR
  7119. case IW_MODE_MONITOR:
  7120. #endif
  7121. case IW_MODE_ADHOC:
  7122. case IW_MODE_INFRA:
  7123. break;
  7124. case IW_MODE_AUTO:
  7125. wrqu->mode = IW_MODE_INFRA;
  7126. break;
  7127. default:
  7128. return -EINVAL;
  7129. }
  7130. if (wrqu->mode == priv->ieee->iw_mode)
  7131. return 0;
  7132. down(&priv->sem);
  7133. ipw_sw_reset(priv, 0);
  7134. #ifdef CONFIG_IPW2200_MONITOR
  7135. if (priv->ieee->iw_mode == IW_MODE_MONITOR)
  7136. priv->net_dev->type = ARPHRD_ETHER;
  7137. if (wrqu->mode == IW_MODE_MONITOR)
  7138. priv->net_dev->type = ARPHRD_IEEE80211;
  7139. #endif /* CONFIG_IPW2200_MONITOR */
  7140. /* Free the existing firmware and reset the fw_loaded
  7141. * flag so ipw_load() will bring in the new firmawre */
  7142. free_firmware();
  7143. priv->ieee->iw_mode = wrqu->mode;
  7144. queue_work(priv->workqueue, &priv->adapter_restart);
  7145. up(&priv->sem);
  7146. return err;
  7147. }
  7148. static int ipw_wx_get_mode(struct net_device *dev,
  7149. struct iw_request_info *info,
  7150. union iwreq_data *wrqu, char *extra)
  7151. {
  7152. struct ipw_priv *priv = ieee80211_priv(dev);
  7153. down(&priv->sem);
  7154. wrqu->mode = priv->ieee->iw_mode;
  7155. IPW_DEBUG_WX("Get MODE -> %d\n", wrqu->mode);
  7156. up(&priv->sem);
  7157. return 0;
  7158. }
  7159. /* Values are in microsecond */
  7160. static const s32 timeout_duration[] = {
  7161. 350000,
  7162. 250000,
  7163. 75000,
  7164. 37000,
  7165. 25000,
  7166. };
  7167. static const s32 period_duration[] = {
  7168. 400000,
  7169. 700000,
  7170. 1000000,
  7171. 1000000,
  7172. 1000000
  7173. };
  7174. static int ipw_wx_get_range(struct net_device *dev,
  7175. struct iw_request_info *info,
  7176. union iwreq_data *wrqu, char *extra)
  7177. {
  7178. struct ipw_priv *priv = ieee80211_priv(dev);
  7179. struct iw_range *range = (struct iw_range *)extra;
  7180. const struct ieee80211_geo *geo = ieee80211_get_geo(priv->ieee);
  7181. int i = 0, j;
  7182. wrqu->data.length = sizeof(*range);
  7183. memset(range, 0, sizeof(*range));
  7184. /* 54Mbs == ~27 Mb/s real (802.11g) */
  7185. range->throughput = 27 * 1000 * 1000;
  7186. range->max_qual.qual = 100;
  7187. /* TODO: Find real max RSSI and stick here */
  7188. range->max_qual.level = 0;
  7189. range->max_qual.noise = priv->ieee->worst_rssi + 0x100;
  7190. range->max_qual.updated = 7; /* Updated all three */
  7191. range->avg_qual.qual = 70;
  7192. /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
  7193. range->avg_qual.level = 0; /* FIXME to real average level */
  7194. range->avg_qual.noise = 0;
  7195. range->avg_qual.updated = 7; /* Updated all three */
  7196. down(&priv->sem);
  7197. range->num_bitrates = min(priv->rates.num_rates, (u8) IW_MAX_BITRATES);
  7198. for (i = 0; i < range->num_bitrates; i++)
  7199. range->bitrate[i] = (priv->rates.supported_rates[i] & 0x7F) *
  7200. 500000;
  7201. range->max_rts = DEFAULT_RTS_THRESHOLD;
  7202. range->min_frag = MIN_FRAG_THRESHOLD;
  7203. range->max_frag = MAX_FRAG_THRESHOLD;
  7204. range->encoding_size[0] = 5;
  7205. range->encoding_size[1] = 13;
  7206. range->num_encoding_sizes = 2;
  7207. range->max_encoding_tokens = WEP_KEYS;
  7208. /* Set the Wireless Extension versions */
  7209. range->we_version_compiled = WIRELESS_EXT;
  7210. range->we_version_source = 16;
  7211. i = 0;
  7212. if (priv->ieee->mode & (IEEE_B | IEEE_G)) {
  7213. for (j = 0; j < geo->bg_channels && i < IW_MAX_FREQUENCIES;
  7214. i++, j++) {
  7215. range->freq[i].i = geo->bg[j].channel;
  7216. range->freq[i].m = geo->bg[j].freq * 100000;
  7217. range->freq[i].e = 1;
  7218. }
  7219. }
  7220. if (priv->ieee->mode & IEEE_A) {
  7221. for (j = 0; j < geo->a_channels && i < IW_MAX_FREQUENCIES;
  7222. i++, j++) {
  7223. range->freq[i].i = geo->a[j].channel;
  7224. range->freq[i].m = geo->a[j].freq * 100000;
  7225. range->freq[i].e = 1;
  7226. }
  7227. }
  7228. range->num_channels = i;
  7229. range->num_frequency = i;
  7230. up(&priv->sem);
  7231. IPW_DEBUG_WX("GET Range\n");
  7232. return 0;
  7233. }
  7234. static int ipw_wx_set_wap(struct net_device *dev,
  7235. struct iw_request_info *info,
  7236. union iwreq_data *wrqu, char *extra)
  7237. {
  7238. struct ipw_priv *priv = ieee80211_priv(dev);
  7239. static const unsigned char any[] = {
  7240. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  7241. };
  7242. static const unsigned char off[] = {
  7243. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  7244. };
  7245. if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
  7246. return -EINVAL;
  7247. down(&priv->sem);
  7248. if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
  7249. !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
  7250. /* we disable mandatory BSSID association */
  7251. IPW_DEBUG_WX("Setting AP BSSID to ANY\n");
  7252. priv->config &= ~CFG_STATIC_BSSID;
  7253. IPW_DEBUG_ASSOC("Attempting to associate with new "
  7254. "parameters.\n");
  7255. ipw_associate(priv);
  7256. up(&priv->sem);
  7257. return 0;
  7258. }
  7259. priv->config |= CFG_STATIC_BSSID;
  7260. if (!memcmp(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN)) {
  7261. IPW_DEBUG_WX("BSSID set to current BSSID.\n");
  7262. up(&priv->sem);
  7263. return 0;
  7264. }
  7265. IPW_DEBUG_WX("Setting mandatory BSSID to " MAC_FMT "\n",
  7266. MAC_ARG(wrqu->ap_addr.sa_data));
  7267. memcpy(priv->bssid, wrqu->ap_addr.sa_data, ETH_ALEN);
  7268. /* Network configuration changed -- force [re]association */
  7269. IPW_DEBUG_ASSOC("[re]association triggered due to BSSID change.\n");
  7270. if (!ipw_disassociate(priv))
  7271. ipw_associate(priv);
  7272. up(&priv->sem);
  7273. return 0;
  7274. }
  7275. static int ipw_wx_get_wap(struct net_device *dev,
  7276. struct iw_request_info *info,
  7277. union iwreq_data *wrqu, char *extra)
  7278. {
  7279. struct ipw_priv *priv = ieee80211_priv(dev);
  7280. /* If we are associated, trying to associate, or have a statically
  7281. * configured BSSID then return that; otherwise return ANY */
  7282. down(&priv->sem);
  7283. if (priv->config & CFG_STATIC_BSSID ||
  7284. priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
  7285. wrqu->ap_addr.sa_family = ARPHRD_ETHER;
  7286. memcpy(wrqu->ap_addr.sa_data, priv->bssid, ETH_ALEN);
  7287. } else
  7288. memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
  7289. IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
  7290. MAC_ARG(wrqu->ap_addr.sa_data));
  7291. up(&priv->sem);
  7292. return 0;
  7293. }
  7294. static int ipw_wx_set_essid(struct net_device *dev,
  7295. struct iw_request_info *info,
  7296. union iwreq_data *wrqu, char *extra)
  7297. {
  7298. struct ipw_priv *priv = ieee80211_priv(dev);
  7299. char *essid = ""; /* ANY */
  7300. int length = 0;
  7301. down(&priv->sem);
  7302. if (wrqu->essid.flags && wrqu->essid.length) {
  7303. length = wrqu->essid.length - 1;
  7304. essid = extra;
  7305. }
  7306. if (length == 0) {
  7307. IPW_DEBUG_WX("Setting ESSID to ANY\n");
  7308. if ((priv->config & CFG_STATIC_ESSID) &&
  7309. !(priv->status & (STATUS_ASSOCIATED |
  7310. STATUS_ASSOCIATING))) {
  7311. IPW_DEBUG_ASSOC("Attempting to associate with new "
  7312. "parameters.\n");
  7313. priv->config &= ~CFG_STATIC_ESSID;
  7314. ipw_associate(priv);
  7315. }
  7316. up(&priv->sem);
  7317. return 0;
  7318. }
  7319. length = min(length, IW_ESSID_MAX_SIZE);
  7320. priv->config |= CFG_STATIC_ESSID;
  7321. if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
  7322. IPW_DEBUG_WX("ESSID set to current ESSID.\n");
  7323. up(&priv->sem);
  7324. return 0;
  7325. }
  7326. IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
  7327. length);
  7328. priv->essid_len = length;
  7329. memcpy(priv->essid, essid, priv->essid_len);
  7330. /* Network configuration changed -- force [re]association */
  7331. IPW_DEBUG_ASSOC("[re]association triggered due to ESSID change.\n");
  7332. if (!ipw_disassociate(priv))
  7333. ipw_associate(priv);
  7334. up(&priv->sem);
  7335. return 0;
  7336. }
  7337. static int ipw_wx_get_essid(struct net_device *dev,
  7338. struct iw_request_info *info,
  7339. union iwreq_data *wrqu, char *extra)
  7340. {
  7341. struct ipw_priv *priv = ieee80211_priv(dev);
  7342. /* If we are associated, trying to associate, or have a statically
  7343. * configured ESSID then return that; otherwise return ANY */
  7344. down(&priv->sem);
  7345. if (priv->config & CFG_STATIC_ESSID ||
  7346. priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) {
  7347. IPW_DEBUG_WX("Getting essid: '%s'\n",
  7348. escape_essid(priv->essid, priv->essid_len));
  7349. memcpy(extra, priv->essid, priv->essid_len);
  7350. wrqu->essid.length = priv->essid_len;
  7351. wrqu->essid.flags = 1; /* active */
  7352. } else {
  7353. IPW_DEBUG_WX("Getting essid: ANY\n");
  7354. wrqu->essid.length = 0;
  7355. wrqu->essid.flags = 0; /* active */
  7356. }
  7357. up(&priv->sem);
  7358. return 0;
  7359. }
  7360. static int ipw_wx_set_nick(struct net_device *dev,
  7361. struct iw_request_info *info,
  7362. union iwreq_data *wrqu, char *extra)
  7363. {
  7364. struct ipw_priv *priv = ieee80211_priv(dev);
  7365. IPW_DEBUG_WX("Setting nick to '%s'\n", extra);
  7366. if (wrqu->data.length > IW_ESSID_MAX_SIZE)
  7367. return -E2BIG;
  7368. down(&priv->sem);
  7369. wrqu->data.length = min((size_t) wrqu->data.length, sizeof(priv->nick));
  7370. memset(priv->nick, 0, sizeof(priv->nick));
  7371. memcpy(priv->nick, extra, wrqu->data.length);
  7372. IPW_DEBUG_TRACE("<<\n");
  7373. up(&priv->sem);
  7374. return 0;
  7375. }
  7376. static int ipw_wx_get_nick(struct net_device *dev,
  7377. struct iw_request_info *info,
  7378. union iwreq_data *wrqu, char *extra)
  7379. {
  7380. struct ipw_priv *priv = ieee80211_priv(dev);
  7381. IPW_DEBUG_WX("Getting nick\n");
  7382. down(&priv->sem);
  7383. wrqu->data.length = strlen(priv->nick) + 1;
  7384. memcpy(extra, priv->nick, wrqu->data.length);
  7385. wrqu->data.flags = 1; /* active */
  7386. up(&priv->sem);
  7387. return 0;
  7388. }
  7389. static int ipw_wx_set_rate(struct net_device *dev,
  7390. struct iw_request_info *info,
  7391. union iwreq_data *wrqu, char *extra)
  7392. {
  7393. /* TODO: We should use semaphores or locks for access to priv */
  7394. struct ipw_priv *priv = ieee80211_priv(dev);
  7395. u32 target_rate = wrqu->bitrate.value;
  7396. u32 fixed, mask;
  7397. /* value = -1, fixed = 0 means auto only, so we should use all rates offered by AP */
  7398. /* value = X, fixed = 1 means only rate X */
  7399. /* value = X, fixed = 0 means all rates lower equal X */
  7400. if (target_rate == -1) {
  7401. fixed = 0;
  7402. mask = IEEE80211_DEFAULT_RATES_MASK;
  7403. /* Now we should reassociate */
  7404. goto apply;
  7405. }
  7406. mask = 0;
  7407. fixed = wrqu->bitrate.fixed;
  7408. if (target_rate == 1000000 || !fixed)
  7409. mask |= IEEE80211_CCK_RATE_1MB_MASK;
  7410. if (target_rate == 1000000)
  7411. goto apply;
  7412. if (target_rate == 2000000 || !fixed)
  7413. mask |= IEEE80211_CCK_RATE_2MB_MASK;
  7414. if (target_rate == 2000000)
  7415. goto apply;
  7416. if (target_rate == 5500000 || !fixed)
  7417. mask |= IEEE80211_CCK_RATE_5MB_MASK;
  7418. if (target_rate == 5500000)
  7419. goto apply;
  7420. if (target_rate == 6000000 || !fixed)
  7421. mask |= IEEE80211_OFDM_RATE_6MB_MASK;
  7422. if (target_rate == 6000000)
  7423. goto apply;
  7424. if (target_rate == 9000000 || !fixed)
  7425. mask |= IEEE80211_OFDM_RATE_9MB_MASK;
  7426. if (target_rate == 9000000)
  7427. goto apply;
  7428. if (target_rate == 11000000 || !fixed)
  7429. mask |= IEEE80211_CCK_RATE_11MB_MASK;
  7430. if (target_rate == 11000000)
  7431. goto apply;
  7432. if (target_rate == 12000000 || !fixed)
  7433. mask |= IEEE80211_OFDM_RATE_12MB_MASK;
  7434. if (target_rate == 12000000)
  7435. goto apply;
  7436. if (target_rate == 18000000 || !fixed)
  7437. mask |= IEEE80211_OFDM_RATE_18MB_MASK;
  7438. if (target_rate == 18000000)
  7439. goto apply;
  7440. if (target_rate == 24000000 || !fixed)
  7441. mask |= IEEE80211_OFDM_RATE_24MB_MASK;
  7442. if (target_rate == 24000000)
  7443. goto apply;
  7444. if (target_rate == 36000000 || !fixed)
  7445. mask |= IEEE80211_OFDM_RATE_36MB_MASK;
  7446. if (target_rate == 36000000)
  7447. goto apply;
  7448. if (target_rate == 48000000 || !fixed)
  7449. mask |= IEEE80211_OFDM_RATE_48MB_MASK;
  7450. if (target_rate == 48000000)
  7451. goto apply;
  7452. if (target_rate == 54000000 || !fixed)
  7453. mask |= IEEE80211_OFDM_RATE_54MB_MASK;
  7454. if (target_rate == 54000000)
  7455. goto apply;
  7456. IPW_DEBUG_WX("invalid rate specified, returning error\n");
  7457. return -EINVAL;
  7458. apply:
  7459. IPW_DEBUG_WX("Setting rate mask to 0x%08X [%s]\n",
  7460. mask, fixed ? "fixed" : "sub-rates");
  7461. down(&priv->sem);
  7462. if (mask == IEEE80211_DEFAULT_RATES_MASK) {
  7463. priv->config &= ~CFG_FIXED_RATE;
  7464. ipw_set_fixed_rate(priv, priv->ieee->mode);
  7465. } else
  7466. priv->config |= CFG_FIXED_RATE;
  7467. if (priv->rates_mask == mask) {
  7468. IPW_DEBUG_WX("Mask set to current mask.\n");
  7469. up(&priv->sem);
  7470. return 0;
  7471. }
  7472. priv->rates_mask = mask;
  7473. /* Network configuration changed -- force [re]association */
  7474. IPW_DEBUG_ASSOC("[re]association triggered due to rates change.\n");
  7475. if (!ipw_disassociate(priv))
  7476. ipw_associate(priv);
  7477. up(&priv->sem);
  7478. return 0;
  7479. }
  7480. static int ipw_wx_get_rate(struct net_device *dev,
  7481. struct iw_request_info *info,
  7482. union iwreq_data *wrqu, char *extra)
  7483. {
  7484. struct ipw_priv *priv = ieee80211_priv(dev);
  7485. down(&priv->sem);
  7486. wrqu->bitrate.value = priv->last_rate;
  7487. up(&priv->sem);
  7488. IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
  7489. return 0;
  7490. }
  7491. static int ipw_wx_set_rts(struct net_device *dev,
  7492. struct iw_request_info *info,
  7493. union iwreq_data *wrqu, char *extra)
  7494. {
  7495. struct ipw_priv *priv = ieee80211_priv(dev);
  7496. down(&priv->sem);
  7497. if (wrqu->rts.disabled)
  7498. priv->rts_threshold = DEFAULT_RTS_THRESHOLD;
  7499. else {
  7500. if (wrqu->rts.value < MIN_RTS_THRESHOLD ||
  7501. wrqu->rts.value > MAX_RTS_THRESHOLD) {
  7502. up(&priv->sem);
  7503. return -EINVAL;
  7504. }
  7505. priv->rts_threshold = wrqu->rts.value;
  7506. }
  7507. ipw_send_rts_threshold(priv, priv->rts_threshold);
  7508. up(&priv->sem);
  7509. IPW_DEBUG_WX("SET RTS Threshold -> %d \n", priv->rts_threshold);
  7510. return 0;
  7511. }
  7512. static int ipw_wx_get_rts(struct net_device *dev,
  7513. struct iw_request_info *info,
  7514. union iwreq_data *wrqu, char *extra)
  7515. {
  7516. struct ipw_priv *priv = ieee80211_priv(dev);
  7517. down(&priv->sem);
  7518. wrqu->rts.value = priv->rts_threshold;
  7519. wrqu->rts.fixed = 0; /* no auto select */
  7520. wrqu->rts.disabled = (wrqu->rts.value == DEFAULT_RTS_THRESHOLD);
  7521. up(&priv->sem);
  7522. IPW_DEBUG_WX("GET RTS Threshold -> %d \n", wrqu->rts.value);
  7523. return 0;
  7524. }
  7525. static int ipw_wx_set_txpow(struct net_device *dev,
  7526. struct iw_request_info *info,
  7527. union iwreq_data *wrqu, char *extra)
  7528. {
  7529. struct ipw_priv *priv = ieee80211_priv(dev);
  7530. int err = 0;
  7531. down(&priv->sem);
  7532. if (ipw_radio_kill_sw(priv, wrqu->power.disabled)) {
  7533. err = -EINPROGRESS;
  7534. goto out;
  7535. }
  7536. if (!wrqu->power.fixed)
  7537. wrqu->power.value = IPW_TX_POWER_DEFAULT;
  7538. if (wrqu->power.flags != IW_TXPOW_DBM) {
  7539. err = -EINVAL;
  7540. goto out;
  7541. }
  7542. if ((wrqu->power.value > IPW_TX_POWER_MAX) ||
  7543. (wrqu->power.value < IPW_TX_POWER_MIN)) {
  7544. err = -EINVAL;
  7545. goto out;
  7546. }
  7547. priv->tx_power = wrqu->power.value;
  7548. err = ipw_set_tx_power(priv);
  7549. out:
  7550. up(&priv->sem);
  7551. return err;
  7552. }
  7553. static int ipw_wx_get_txpow(struct net_device *dev,
  7554. struct iw_request_info *info,
  7555. union iwreq_data *wrqu, char *extra)
  7556. {
  7557. struct ipw_priv *priv = ieee80211_priv(dev);
  7558. down(&priv->sem);
  7559. wrqu->power.value = priv->tx_power;
  7560. wrqu->power.fixed = 1;
  7561. wrqu->power.flags = IW_TXPOW_DBM;
  7562. wrqu->power.disabled = (priv->status & STATUS_RF_KILL_MASK) ? 1 : 0;
  7563. up(&priv->sem);
  7564. IPW_DEBUG_WX("GET TX Power -> %s %d \n",
  7565. wrqu->power.disabled ? "OFF" : "ON", wrqu->power.value);
  7566. return 0;
  7567. }
  7568. static int ipw_wx_set_frag(struct net_device *dev,
  7569. struct iw_request_info *info,
  7570. union iwreq_data *wrqu, char *extra)
  7571. {
  7572. struct ipw_priv *priv = ieee80211_priv(dev);
  7573. down(&priv->sem);
  7574. if (wrqu->frag.disabled)
  7575. priv->ieee->fts = DEFAULT_FTS;
  7576. else {
  7577. if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
  7578. wrqu->frag.value > MAX_FRAG_THRESHOLD) {
  7579. up(&priv->sem);
  7580. return -EINVAL;
  7581. }
  7582. priv->ieee->fts = wrqu->frag.value & ~0x1;
  7583. }
  7584. ipw_send_frag_threshold(priv, wrqu->frag.value);
  7585. up(&priv->sem);
  7586. IPW_DEBUG_WX("SET Frag Threshold -> %d \n", wrqu->frag.value);
  7587. return 0;
  7588. }
  7589. static int ipw_wx_get_frag(struct net_device *dev,
  7590. struct iw_request_info *info,
  7591. union iwreq_data *wrqu, char *extra)
  7592. {
  7593. struct ipw_priv *priv = ieee80211_priv(dev);
  7594. down(&priv->sem);
  7595. wrqu->frag.value = priv->ieee->fts;
  7596. wrqu->frag.fixed = 0; /* no auto select */
  7597. wrqu->frag.disabled = (wrqu->frag.value == DEFAULT_FTS);
  7598. up(&priv->sem);
  7599. IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
  7600. return 0;
  7601. }
  7602. static int ipw_wx_set_retry(struct net_device *dev,
  7603. struct iw_request_info *info,
  7604. union iwreq_data *wrqu, char *extra)
  7605. {
  7606. struct ipw_priv *priv = ieee80211_priv(dev);
  7607. if (wrqu->retry.flags & IW_RETRY_LIFETIME || wrqu->retry.disabled)
  7608. return -EINVAL;
  7609. if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
  7610. return 0;
  7611. if (wrqu->retry.value < 0 || wrqu->retry.value > 255)
  7612. return -EINVAL;
  7613. down(&priv->sem);
  7614. if (wrqu->retry.flags & IW_RETRY_MIN)
  7615. priv->short_retry_limit = (u8) wrqu->retry.value;
  7616. else if (wrqu->retry.flags & IW_RETRY_MAX)
  7617. priv->long_retry_limit = (u8) wrqu->retry.value;
  7618. else {
  7619. priv->short_retry_limit = (u8) wrqu->retry.value;
  7620. priv->long_retry_limit = (u8) wrqu->retry.value;
  7621. }
  7622. ipw_send_retry_limit(priv, priv->short_retry_limit,
  7623. priv->long_retry_limit);
  7624. up(&priv->sem);
  7625. IPW_DEBUG_WX("SET retry limit -> short:%d long:%d\n",
  7626. priv->short_retry_limit, priv->long_retry_limit);
  7627. return 0;
  7628. }
  7629. static int ipw_wx_get_retry(struct net_device *dev,
  7630. struct iw_request_info *info,
  7631. union iwreq_data *wrqu, char *extra)
  7632. {
  7633. struct ipw_priv *priv = ieee80211_priv(dev);
  7634. down(&priv->sem);
  7635. wrqu->retry.disabled = 0;
  7636. if ((wrqu->retry.flags & IW_RETRY_TYPE) == IW_RETRY_LIFETIME) {
  7637. up(&priv->sem);
  7638. return -EINVAL;
  7639. }
  7640. if (wrqu->retry.flags & IW_RETRY_MAX) {
  7641. wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MAX;
  7642. wrqu->retry.value = priv->long_retry_limit;
  7643. } else if (wrqu->retry.flags & IW_RETRY_MIN) {
  7644. wrqu->retry.flags = IW_RETRY_LIMIT | IW_RETRY_MIN;
  7645. wrqu->retry.value = priv->short_retry_limit;
  7646. } else {
  7647. wrqu->retry.flags = IW_RETRY_LIMIT;
  7648. wrqu->retry.value = priv->short_retry_limit;
  7649. }
  7650. up(&priv->sem);
  7651. IPW_DEBUG_WX("GET retry -> %d \n", wrqu->retry.value);
  7652. return 0;
  7653. }
  7654. #if WIRELESS_EXT > 17
  7655. static int ipw_request_direct_scan(struct ipw_priv *priv, char *essid,
  7656. int essid_len)
  7657. {
  7658. struct ipw_scan_request_ext scan;
  7659. int err = 0, scan_type;
  7660. down(&priv->sem);
  7661. if (priv->status & STATUS_RF_KILL_MASK) {
  7662. IPW_DEBUG_HC("Aborting scan due to RF kill activation\n");
  7663. priv->status |= STATUS_SCAN_PENDING;
  7664. goto done;
  7665. }
  7666. IPW_DEBUG_HC("starting request direct scan!\n");
  7667. if (priv->status & (STATUS_SCANNING | STATUS_SCAN_ABORTING)) {
  7668. err = wait_event_interruptible(priv->wait_state,
  7669. !(priv->
  7670. status & (STATUS_SCANNING |
  7671. STATUS_SCAN_ABORTING)));
  7672. if (err) {
  7673. IPW_DEBUG_HC("aborting direct scan");
  7674. goto done;
  7675. }
  7676. }
  7677. memset(&scan, 0, sizeof(scan));
  7678. if (priv->config & CFG_SPEED_SCAN)
  7679. scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
  7680. cpu_to_le16(30);
  7681. else
  7682. scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_SCAN] =
  7683. cpu_to_le16(20);
  7684. scan.dwell_time[IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN] =
  7685. cpu_to_le16(20);
  7686. scan.dwell_time[IPW_SCAN_PASSIVE_FULL_DWELL_SCAN] = cpu_to_le16(20);
  7687. scan.dwell_time[IPW_SCAN_ACTIVE_DIRECT_SCAN] = cpu_to_le16(20);
  7688. scan.full_scan_index = cpu_to_le32(ieee80211_get_scans(priv->ieee));
  7689. err = ipw_send_ssid(priv, essid, essid_len);
  7690. if (err) {
  7691. IPW_DEBUG_HC("Attempt to send SSID command failed\n");
  7692. goto done;
  7693. }
  7694. scan_type = IPW_SCAN_ACTIVE_BROADCAST_AND_DIRECT_SCAN;
  7695. ipw_add_scan_channels(priv, &scan, scan_type);
  7696. err = ipw_send_scan_request_ext(priv, &scan);
  7697. if (err) {
  7698. IPW_DEBUG_HC("Sending scan command failed: %08X\n", err);
  7699. goto done;
  7700. }
  7701. priv->status |= STATUS_SCANNING;
  7702. done:
  7703. up(&priv->sem);
  7704. return err;
  7705. }
  7706. #endif /* WIRELESS_EXT > 17 */
  7707. static int ipw_wx_set_scan(struct net_device *dev,
  7708. struct iw_request_info *info,
  7709. union iwreq_data *wrqu, char *extra)
  7710. {
  7711. struct ipw_priv *priv = ieee80211_priv(dev);
  7712. #if WIRELESS_EXT > 17
  7713. struct iw_scan_req *req = NULL;
  7714. if (wrqu->data.length
  7715. && wrqu->data.length == sizeof(struct iw_scan_req)) {
  7716. req = (struct iw_scan_req *)extra;
  7717. if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
  7718. ipw_request_direct_scan(priv, req->essid,
  7719. req->essid_len);
  7720. return 0;
  7721. }
  7722. }
  7723. #endif
  7724. IPW_DEBUG_WX("Start scan\n");
  7725. queue_work(priv->workqueue, &priv->request_scan);
  7726. return 0;
  7727. }
  7728. static int ipw_wx_get_scan(struct net_device *dev,
  7729. struct iw_request_info *info,
  7730. union iwreq_data *wrqu, char *extra)
  7731. {
  7732. struct ipw_priv *priv = ieee80211_priv(dev);
  7733. return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
  7734. }
  7735. static int ipw_wx_set_encode(struct net_device *dev,
  7736. struct iw_request_info *info,
  7737. union iwreq_data *wrqu, char *key)
  7738. {
  7739. struct ipw_priv *priv = ieee80211_priv(dev);
  7740. int ret;
  7741. u32 cap = priv->capability;
  7742. down(&priv->sem);
  7743. ret = ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
  7744. /* In IBSS mode, we need to notify the firmware to update
  7745. * the beacon info after we changed the capability. */
  7746. if (cap != priv->capability &&
  7747. priv->ieee->iw_mode == IW_MODE_ADHOC &&
  7748. priv->status & STATUS_ASSOCIATED)
  7749. ipw_disassociate(priv);
  7750. up(&priv->sem);
  7751. return ret;
  7752. }
  7753. static int ipw_wx_get_encode(struct net_device *dev,
  7754. struct iw_request_info *info,
  7755. union iwreq_data *wrqu, char *key)
  7756. {
  7757. struct ipw_priv *priv = ieee80211_priv(dev);
  7758. return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
  7759. }
  7760. static int ipw_wx_set_power(struct net_device *dev,
  7761. struct iw_request_info *info,
  7762. union iwreq_data *wrqu, char *extra)
  7763. {
  7764. struct ipw_priv *priv = ieee80211_priv(dev);
  7765. int err;
  7766. down(&priv->sem);
  7767. if (wrqu->power.disabled) {
  7768. priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
  7769. err = ipw_send_power_mode(priv, IPW_POWER_MODE_CAM);
  7770. if (err) {
  7771. IPW_DEBUG_WX("failed setting power mode.\n");
  7772. up(&priv->sem);
  7773. return err;
  7774. }
  7775. IPW_DEBUG_WX("SET Power Management Mode -> off\n");
  7776. up(&priv->sem);
  7777. return 0;
  7778. }
  7779. switch (wrqu->power.flags & IW_POWER_MODE) {
  7780. case IW_POWER_ON: /* If not specified */
  7781. case IW_POWER_MODE: /* If set all mask */
  7782. case IW_POWER_ALL_R: /* If explicitely state all */
  7783. break;
  7784. default: /* Otherwise we don't support it */
  7785. IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
  7786. wrqu->power.flags);
  7787. up(&priv->sem);
  7788. return -EOPNOTSUPP;
  7789. }
  7790. /* If the user hasn't specified a power management mode yet, default
  7791. * to BATTERY */
  7792. if (IPW_POWER_LEVEL(priv->power_mode) == IPW_POWER_AC)
  7793. priv->power_mode = IPW_POWER_ENABLED | IPW_POWER_BATTERY;
  7794. else
  7795. priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
  7796. err = ipw_send_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
  7797. if (err) {
  7798. IPW_DEBUG_WX("failed setting power mode.\n");
  7799. up(&priv->sem);
  7800. return err;
  7801. }
  7802. IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n", priv->power_mode);
  7803. up(&priv->sem);
  7804. return 0;
  7805. }
  7806. static int ipw_wx_get_power(struct net_device *dev,
  7807. struct iw_request_info *info,
  7808. union iwreq_data *wrqu, char *extra)
  7809. {
  7810. struct ipw_priv *priv = ieee80211_priv(dev);
  7811. down(&priv->sem);
  7812. if (!(priv->power_mode & IPW_POWER_ENABLED))
  7813. wrqu->power.disabled = 1;
  7814. else
  7815. wrqu->power.disabled = 0;
  7816. up(&priv->sem);
  7817. IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
  7818. return 0;
  7819. }
  7820. static int ipw_wx_set_powermode(struct net_device *dev,
  7821. struct iw_request_info *info,
  7822. union iwreq_data *wrqu, char *extra)
  7823. {
  7824. struct ipw_priv *priv = ieee80211_priv(dev);
  7825. int mode = *(int *)extra;
  7826. int err;
  7827. down(&priv->sem);
  7828. if ((mode < 1) || (mode > IPW_POWER_LIMIT)) {
  7829. mode = IPW_POWER_AC;
  7830. priv->power_mode = mode;
  7831. } else {
  7832. priv->power_mode = IPW_POWER_ENABLED | mode;
  7833. }
  7834. if (priv->power_mode != mode) {
  7835. err = ipw_send_power_mode(priv, mode);
  7836. if (err) {
  7837. IPW_DEBUG_WX("failed setting power mode.\n");
  7838. up(&priv->sem);
  7839. return err;
  7840. }
  7841. }
  7842. up(&priv->sem);
  7843. return 0;
  7844. }
  7845. #define MAX_WX_STRING 80
  7846. static int ipw_wx_get_powermode(struct net_device *dev,
  7847. struct iw_request_info *info,
  7848. union iwreq_data *wrqu, char *extra)
  7849. {
  7850. struct ipw_priv *priv = ieee80211_priv(dev);
  7851. int level = IPW_POWER_LEVEL(priv->power_mode);
  7852. char *p = extra;
  7853. p += snprintf(p, MAX_WX_STRING, "Power save level: %d ", level);
  7854. switch (level) {
  7855. case IPW_POWER_AC:
  7856. p += snprintf(p, MAX_WX_STRING - (p - extra), "(AC)");
  7857. break;
  7858. case IPW_POWER_BATTERY:
  7859. p += snprintf(p, MAX_WX_STRING - (p - extra), "(BATTERY)");
  7860. break;
  7861. default:
  7862. p += snprintf(p, MAX_WX_STRING - (p - extra),
  7863. "(Timeout %dms, Period %dms)",
  7864. timeout_duration[level - 1] / 1000,
  7865. period_duration[level - 1] / 1000);
  7866. }
  7867. if (!(priv->power_mode & IPW_POWER_ENABLED))
  7868. p += snprintf(p, MAX_WX_STRING - (p - extra), " OFF");
  7869. wrqu->data.length = p - extra + 1;
  7870. return 0;
  7871. }
  7872. static int ipw_wx_set_wireless_mode(struct net_device *dev,
  7873. struct iw_request_info *info,
  7874. union iwreq_data *wrqu, char *extra)
  7875. {
  7876. struct ipw_priv *priv = ieee80211_priv(dev);
  7877. int mode = *(int *)extra;
  7878. u8 band = 0, modulation = 0;
  7879. if (mode == 0 || mode & ~IEEE_MODE_MASK) {
  7880. IPW_WARNING("Attempt to set invalid wireless mode: %d\n", mode);
  7881. return -EINVAL;
  7882. }
  7883. down(&priv->sem);
  7884. if (priv->adapter == IPW_2915ABG) {
  7885. priv->ieee->abg_true = 1;
  7886. if (mode & IEEE_A) {
  7887. band |= IEEE80211_52GHZ_BAND;
  7888. modulation |= IEEE80211_OFDM_MODULATION;
  7889. } else
  7890. priv->ieee->abg_true = 0;
  7891. } else {
  7892. if (mode & IEEE_A) {
  7893. IPW_WARNING("Attempt to set 2200BG into "
  7894. "802.11a mode\n");
  7895. up(&priv->sem);
  7896. return -EINVAL;
  7897. }
  7898. priv->ieee->abg_true = 0;
  7899. }
  7900. if (mode & IEEE_B) {
  7901. band |= IEEE80211_24GHZ_BAND;
  7902. modulation |= IEEE80211_CCK_MODULATION;
  7903. } else
  7904. priv->ieee->abg_true = 0;
  7905. if (mode & IEEE_G) {
  7906. band |= IEEE80211_24GHZ_BAND;
  7907. modulation |= IEEE80211_OFDM_MODULATION;
  7908. } else
  7909. priv->ieee->abg_true = 0;
  7910. priv->ieee->mode = mode;
  7911. priv->ieee->freq_band = band;
  7912. priv->ieee->modulation = modulation;
  7913. init_supported_rates(priv, &priv->rates);
  7914. /* Network configuration changed -- force [re]association */
  7915. IPW_DEBUG_ASSOC("[re]association triggered due to mode change.\n");
  7916. if (!ipw_disassociate(priv)) {
  7917. ipw_send_supported_rates(priv, &priv->rates);
  7918. ipw_associate(priv);
  7919. }
  7920. /* Update the band LEDs */
  7921. ipw_led_band_on(priv);
  7922. IPW_DEBUG_WX("PRIV SET MODE: %c%c%c\n",
  7923. mode & IEEE_A ? 'a' : '.',
  7924. mode & IEEE_B ? 'b' : '.', mode & IEEE_G ? 'g' : '.');
  7925. up(&priv->sem);
  7926. return 0;
  7927. }
  7928. static int ipw_wx_get_wireless_mode(struct net_device *dev,
  7929. struct iw_request_info *info,
  7930. union iwreq_data *wrqu, char *extra)
  7931. {
  7932. struct ipw_priv *priv = ieee80211_priv(dev);
  7933. down(&priv->sem);
  7934. switch (priv->ieee->mode) {
  7935. case IEEE_A:
  7936. strncpy(extra, "802.11a (1)", MAX_WX_STRING);
  7937. break;
  7938. case IEEE_B:
  7939. strncpy(extra, "802.11b (2)", MAX_WX_STRING);
  7940. break;
  7941. case IEEE_A | IEEE_B:
  7942. strncpy(extra, "802.11ab (3)", MAX_WX_STRING);
  7943. break;
  7944. case IEEE_G:
  7945. strncpy(extra, "802.11g (4)", MAX_WX_STRING);
  7946. break;
  7947. case IEEE_A | IEEE_G:
  7948. strncpy(extra, "802.11ag (5)", MAX_WX_STRING);
  7949. break;
  7950. case IEEE_B | IEEE_G:
  7951. strncpy(extra, "802.11bg (6)", MAX_WX_STRING);
  7952. break;
  7953. case IEEE_A | IEEE_B | IEEE_G:
  7954. strncpy(extra, "802.11abg (7)", MAX_WX_STRING);
  7955. break;
  7956. default:
  7957. strncpy(extra, "unknown", MAX_WX_STRING);
  7958. break;
  7959. }
  7960. IPW_DEBUG_WX("PRIV GET MODE: %s\n", extra);
  7961. wrqu->data.length = strlen(extra) + 1;
  7962. up(&priv->sem);
  7963. return 0;
  7964. }
  7965. static int ipw_wx_set_preamble(struct net_device *dev,
  7966. struct iw_request_info *info,
  7967. union iwreq_data *wrqu, char *extra)
  7968. {
  7969. struct ipw_priv *priv = ieee80211_priv(dev);
  7970. int mode = *(int *)extra;
  7971. down(&priv->sem);
  7972. /* Switching from SHORT -> LONG requires a disassociation */
  7973. if (mode == 1) {
  7974. if (!(priv->config & CFG_PREAMBLE_LONG)) {
  7975. priv->config |= CFG_PREAMBLE_LONG;
  7976. /* Network configuration changed -- force [re]association */
  7977. IPW_DEBUG_ASSOC
  7978. ("[re]association triggered due to preamble change.\n");
  7979. if (!ipw_disassociate(priv))
  7980. ipw_associate(priv);
  7981. }
  7982. goto done;
  7983. }
  7984. if (mode == 0) {
  7985. priv->config &= ~CFG_PREAMBLE_LONG;
  7986. goto done;
  7987. }
  7988. up(&priv->sem);
  7989. return -EINVAL;
  7990. done:
  7991. up(&priv->sem);
  7992. return 0;
  7993. }
  7994. static int ipw_wx_get_preamble(struct net_device *dev,
  7995. struct iw_request_info *info,
  7996. union iwreq_data *wrqu, char *extra)
  7997. {
  7998. struct ipw_priv *priv = ieee80211_priv(dev);
  7999. down(&priv->sem);
  8000. if (priv->config & CFG_PREAMBLE_LONG)
  8001. snprintf(wrqu->name, IFNAMSIZ, "long (1)");
  8002. else
  8003. snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
  8004. up(&priv->sem);
  8005. return 0;
  8006. }
  8007. #ifdef CONFIG_IPW2200_MONITOR
  8008. static int ipw_wx_set_monitor(struct net_device *dev,
  8009. struct iw_request_info *info,
  8010. union iwreq_data *wrqu, char *extra)
  8011. {
  8012. struct ipw_priv *priv = ieee80211_priv(dev);
  8013. int *parms = (int *)extra;
  8014. int enable = (parms[0] > 0);
  8015. down(&priv->sem);
  8016. IPW_DEBUG_WX("SET MONITOR: %d %d\n", enable, parms[1]);
  8017. if (enable) {
  8018. if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
  8019. priv->net_dev->type = ARPHRD_IEEE80211;
  8020. queue_work(priv->workqueue, &priv->adapter_restart);
  8021. }
  8022. ipw_set_channel(priv, parms[1]);
  8023. } else {
  8024. if (priv->ieee->iw_mode != IW_MODE_MONITOR) {
  8025. up(&priv->sem);
  8026. return 0;
  8027. }
  8028. priv->net_dev->type = ARPHRD_ETHER;
  8029. queue_work(priv->workqueue, &priv->adapter_restart);
  8030. }
  8031. up(&priv->sem);
  8032. return 0;
  8033. }
  8034. #endif // CONFIG_IPW2200_MONITOR
  8035. static int ipw_wx_reset(struct net_device *dev,
  8036. struct iw_request_info *info,
  8037. union iwreq_data *wrqu, char *extra)
  8038. {
  8039. struct ipw_priv *priv = ieee80211_priv(dev);
  8040. IPW_DEBUG_WX("RESET\n");
  8041. queue_work(priv->workqueue, &priv->adapter_restart);
  8042. return 0;
  8043. }
  8044. static int ipw_wx_sw_reset(struct net_device *dev,
  8045. struct iw_request_info *info,
  8046. union iwreq_data *wrqu, char *extra)
  8047. {
  8048. struct ipw_priv *priv = ieee80211_priv(dev);
  8049. union iwreq_data wrqu_sec = {
  8050. .encoding = {
  8051. .flags = IW_ENCODE_DISABLED,
  8052. },
  8053. };
  8054. int ret;
  8055. IPW_DEBUG_WX("SW_RESET\n");
  8056. down(&priv->sem);
  8057. ret = ipw_sw_reset(priv, 0);
  8058. if (!ret) {
  8059. free_firmware();
  8060. ipw_adapter_restart(priv);
  8061. }
  8062. /* The SW reset bit might have been toggled on by the 'disable'
  8063. * module parameter, so take appropriate action */
  8064. ipw_radio_kill_sw(priv, priv->status & STATUS_RF_KILL_SW);
  8065. up(&priv->sem);
  8066. ieee80211_wx_set_encode(priv->ieee, info, &wrqu_sec, NULL);
  8067. down(&priv->sem);
  8068. if (!(priv->status & STATUS_RF_KILL_MASK)) {
  8069. /* Configuration likely changed -- force [re]association */
  8070. IPW_DEBUG_ASSOC("[re]association triggered due to sw "
  8071. "reset.\n");
  8072. if (!ipw_disassociate(priv))
  8073. ipw_associate(priv);
  8074. }
  8075. up(&priv->sem);
  8076. return 0;
  8077. }
  8078. /* Rebase the WE IOCTLs to zero for the handler array */
  8079. #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
  8080. static iw_handler ipw_wx_handlers[] = {
  8081. IW_IOCTL(SIOCGIWNAME) = ipw_wx_get_name,
  8082. IW_IOCTL(SIOCSIWFREQ) = ipw_wx_set_freq,
  8083. IW_IOCTL(SIOCGIWFREQ) = ipw_wx_get_freq,
  8084. IW_IOCTL(SIOCSIWMODE) = ipw_wx_set_mode,
  8085. IW_IOCTL(SIOCGIWMODE) = ipw_wx_get_mode,
  8086. IW_IOCTL(SIOCGIWRANGE) = ipw_wx_get_range,
  8087. IW_IOCTL(SIOCSIWAP) = ipw_wx_set_wap,
  8088. IW_IOCTL(SIOCGIWAP) = ipw_wx_get_wap,
  8089. IW_IOCTL(SIOCSIWSCAN) = ipw_wx_set_scan,
  8090. IW_IOCTL(SIOCGIWSCAN) = ipw_wx_get_scan,
  8091. IW_IOCTL(SIOCSIWESSID) = ipw_wx_set_essid,
  8092. IW_IOCTL(SIOCGIWESSID) = ipw_wx_get_essid,
  8093. IW_IOCTL(SIOCSIWNICKN) = ipw_wx_set_nick,
  8094. IW_IOCTL(SIOCGIWNICKN) = ipw_wx_get_nick,
  8095. IW_IOCTL(SIOCSIWRATE) = ipw_wx_set_rate,
  8096. IW_IOCTL(SIOCGIWRATE) = ipw_wx_get_rate,
  8097. IW_IOCTL(SIOCSIWRTS) = ipw_wx_set_rts,
  8098. IW_IOCTL(SIOCGIWRTS) = ipw_wx_get_rts,
  8099. IW_IOCTL(SIOCSIWFRAG) = ipw_wx_set_frag,
  8100. IW_IOCTL(SIOCGIWFRAG) = ipw_wx_get_frag,
  8101. IW_IOCTL(SIOCSIWTXPOW) = ipw_wx_set_txpow,
  8102. IW_IOCTL(SIOCGIWTXPOW) = ipw_wx_get_txpow,
  8103. IW_IOCTL(SIOCSIWRETRY) = ipw_wx_set_retry,
  8104. IW_IOCTL(SIOCGIWRETRY) = ipw_wx_get_retry,
  8105. IW_IOCTL(SIOCSIWENCODE) = ipw_wx_set_encode,
  8106. IW_IOCTL(SIOCGIWENCODE) = ipw_wx_get_encode,
  8107. IW_IOCTL(SIOCSIWPOWER) = ipw_wx_set_power,
  8108. IW_IOCTL(SIOCGIWPOWER) = ipw_wx_get_power,
  8109. IW_IOCTL(SIOCSIWSPY) = iw_handler_set_spy,
  8110. IW_IOCTL(SIOCGIWSPY) = iw_handler_get_spy,
  8111. IW_IOCTL(SIOCSIWTHRSPY) = iw_handler_set_thrspy,
  8112. IW_IOCTL(SIOCGIWTHRSPY) = iw_handler_get_thrspy,
  8113. #if WIRELESS_EXT > 17
  8114. IW_IOCTL(SIOCSIWGENIE) = ipw_wx_set_genie,
  8115. IW_IOCTL(SIOCGIWGENIE) = ipw_wx_get_genie,
  8116. IW_IOCTL(SIOCSIWMLME) = ipw_wx_set_mlme,
  8117. IW_IOCTL(SIOCSIWAUTH) = ipw_wx_set_auth,
  8118. IW_IOCTL(SIOCGIWAUTH) = ipw_wx_get_auth,
  8119. IW_IOCTL(SIOCSIWENCODEEXT) = ipw_wx_set_encodeext,
  8120. IW_IOCTL(SIOCGIWENCODEEXT) = ipw_wx_get_encodeext,
  8121. #endif
  8122. };
  8123. enum {
  8124. IPW_PRIV_SET_POWER = SIOCIWFIRSTPRIV,
  8125. IPW_PRIV_GET_POWER,
  8126. IPW_PRIV_SET_MODE,
  8127. IPW_PRIV_GET_MODE,
  8128. IPW_PRIV_SET_PREAMBLE,
  8129. IPW_PRIV_GET_PREAMBLE,
  8130. IPW_PRIV_RESET,
  8131. IPW_PRIV_SW_RESET,
  8132. #ifdef CONFIG_IPW2200_MONITOR
  8133. IPW_PRIV_SET_MONITOR,
  8134. #endif
  8135. };
  8136. static struct iw_priv_args ipw_priv_args[] = {
  8137. {
  8138. .cmd = IPW_PRIV_SET_POWER,
  8139. .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  8140. .name = "set_power"},
  8141. {
  8142. .cmd = IPW_PRIV_GET_POWER,
  8143. .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
  8144. .name = "get_power"},
  8145. {
  8146. .cmd = IPW_PRIV_SET_MODE,
  8147. .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  8148. .name = "set_mode"},
  8149. {
  8150. .cmd = IPW_PRIV_GET_MODE,
  8151. .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_WX_STRING,
  8152. .name = "get_mode"},
  8153. {
  8154. .cmd = IPW_PRIV_SET_PREAMBLE,
  8155. .set_args = IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1,
  8156. .name = "set_preamble"},
  8157. {
  8158. .cmd = IPW_PRIV_GET_PREAMBLE,
  8159. .get_args = IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ,
  8160. .name = "get_preamble"},
  8161. {
  8162. IPW_PRIV_RESET,
  8163. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"},
  8164. {
  8165. IPW_PRIV_SW_RESET,
  8166. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "sw_reset"},
  8167. #ifdef CONFIG_IPW2200_MONITOR
  8168. {
  8169. IPW_PRIV_SET_MONITOR,
  8170. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"},
  8171. #endif /* CONFIG_IPW2200_MONITOR */
  8172. };
  8173. static iw_handler ipw_priv_handler[] = {
  8174. ipw_wx_set_powermode,
  8175. ipw_wx_get_powermode,
  8176. ipw_wx_set_wireless_mode,
  8177. ipw_wx_get_wireless_mode,
  8178. ipw_wx_set_preamble,
  8179. ipw_wx_get_preamble,
  8180. ipw_wx_reset,
  8181. ipw_wx_sw_reset,
  8182. #ifdef CONFIG_IPW2200_MONITOR
  8183. ipw_wx_set_monitor,
  8184. #endif
  8185. };
  8186. static struct iw_handler_def ipw_wx_handler_def = {
  8187. .standard = ipw_wx_handlers,
  8188. .num_standard = ARRAY_SIZE(ipw_wx_handlers),
  8189. .num_private = ARRAY_SIZE(ipw_priv_handler),
  8190. .num_private_args = ARRAY_SIZE(ipw_priv_args),
  8191. .private = ipw_priv_handler,
  8192. .private_args = ipw_priv_args,
  8193. };
  8194. static struct iw_public_data ipw_wx_data;
  8195. /*
  8196. * Get wireless statistics.
  8197. * Called by /proc/net/wireless
  8198. * Also called by SIOCGIWSTATS
  8199. */
  8200. static struct iw_statistics *ipw_get_wireless_stats(struct net_device *dev)
  8201. {
  8202. struct ipw_priv *priv = ieee80211_priv(dev);
  8203. struct iw_statistics *wstats;
  8204. wstats = &priv->wstats;
  8205. /* if hw is disabled, then ipw_get_ordinal() can't be called.
  8206. * netdev->get_wireless_stats seems to be called before fw is
  8207. * initialized. STATUS_ASSOCIATED will only be set if the hw is up
  8208. * and associated; if not associcated, the values are all meaningless
  8209. * anyway, so set them all to NULL and INVALID */
  8210. if (!(priv->status & STATUS_ASSOCIATED)) {
  8211. wstats->miss.beacon = 0;
  8212. wstats->discard.retries = 0;
  8213. wstats->qual.qual = 0;
  8214. wstats->qual.level = 0;
  8215. wstats->qual.noise = 0;
  8216. wstats->qual.updated = 7;
  8217. wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
  8218. IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
  8219. return wstats;
  8220. }
  8221. wstats->qual.qual = priv->quality;
  8222. wstats->qual.level = average_value(&priv->average_rssi);
  8223. wstats->qual.noise = average_value(&priv->average_noise);
  8224. wstats->qual.updated = IW_QUAL_QUAL_UPDATED | IW_QUAL_LEVEL_UPDATED |
  8225. IW_QUAL_NOISE_UPDATED;
  8226. wstats->miss.beacon = average_value(&priv->average_missed_beacons);
  8227. wstats->discard.retries = priv->last_tx_failures;
  8228. wstats->discard.code = priv->ieee->ieee_stats.rx_discards_undecryptable;
  8229. /* if (ipw_get_ordinal(priv, IPW_ORD_STAT_TX_RETRY, &tx_retry, &len))
  8230. goto fail_get_ordinal;
  8231. wstats->discard.retries += tx_retry; */
  8232. return wstats;
  8233. }
  8234. /* net device stuff */
  8235. static inline void init_sys_config(struct ipw_sys_config *sys_config)
  8236. {
  8237. memset(sys_config, 0, sizeof(struct ipw_sys_config));
  8238. sys_config->bt_coexistence = 1; /* We may need to look into prvStaBtConfig */
  8239. sys_config->answer_broadcast_ssid_probe = 0;
  8240. sys_config->accept_all_data_frames = 0;
  8241. sys_config->accept_non_directed_frames = 1;
  8242. sys_config->exclude_unicast_unencrypted = 0;
  8243. sys_config->disable_unicast_decryption = 1;
  8244. sys_config->exclude_multicast_unencrypted = 0;
  8245. sys_config->disable_multicast_decryption = 1;
  8246. sys_config->antenna_diversity = CFG_SYS_ANTENNA_BOTH;
  8247. sys_config->pass_crc_to_host = 0; /* TODO: See if 1 gives us FCS */
  8248. sys_config->dot11g_auto_detection = 0;
  8249. sys_config->enable_cts_to_self = 0;
  8250. sys_config->bt_coexist_collision_thr = 0;
  8251. sys_config->pass_noise_stats_to_host = 1; //1 -- fix for 256
  8252. }
  8253. static int ipw_net_open(struct net_device *dev)
  8254. {
  8255. struct ipw_priv *priv = ieee80211_priv(dev);
  8256. IPW_DEBUG_INFO("dev->open\n");
  8257. /* we should be verifying the device is ready to be opened */
  8258. down(&priv->sem);
  8259. if (!(priv->status & STATUS_RF_KILL_MASK) &&
  8260. (priv->status & STATUS_ASSOCIATED))
  8261. netif_start_queue(dev);
  8262. up(&priv->sem);
  8263. return 0;
  8264. }
  8265. static int ipw_net_stop(struct net_device *dev)
  8266. {
  8267. IPW_DEBUG_INFO("dev->close\n");
  8268. netif_stop_queue(dev);
  8269. return 0;
  8270. }
  8271. /*
  8272. todo:
  8273. modify to send one tfd per fragment instead of using chunking. otherwise
  8274. we need to heavily modify the ieee80211_skb_to_txb.
  8275. */
  8276. static inline int ipw_tx_skb(struct ipw_priv *priv, struct ieee80211_txb *txb,
  8277. int pri)
  8278. {
  8279. struct ieee80211_hdr_3addr *hdr = (struct ieee80211_hdr_3addr *)
  8280. txb->fragments[0]->data;
  8281. int i = 0;
  8282. struct tfd_frame *tfd;
  8283. #ifdef CONFIG_IPW_QOS
  8284. int tx_id = ipw_get_tx_queue_number(priv, pri);
  8285. struct clx2_tx_queue *txq = &priv->txq[tx_id];
  8286. #else
  8287. struct clx2_tx_queue *txq = &priv->txq[0];
  8288. #endif
  8289. struct clx2_queue *q = &txq->q;
  8290. u8 id, hdr_len, unicast;
  8291. u16 remaining_bytes;
  8292. int fc;
  8293. /* If there isn't room in the queue, we return busy and let the
  8294. * network stack requeue the packet for us */
  8295. if (ipw_queue_space(q) < q->high_mark)
  8296. return NETDEV_TX_BUSY;
  8297. switch (priv->ieee->iw_mode) {
  8298. case IW_MODE_ADHOC:
  8299. hdr_len = IEEE80211_3ADDR_LEN;
  8300. unicast = !is_multicast_ether_addr(hdr->addr1);
  8301. id = ipw_find_station(priv, hdr->addr1);
  8302. if (id == IPW_INVALID_STATION) {
  8303. id = ipw_add_station(priv, hdr->addr1);
  8304. if (id == IPW_INVALID_STATION) {
  8305. IPW_WARNING("Attempt to send data to "
  8306. "invalid cell: " MAC_FMT "\n",
  8307. MAC_ARG(hdr->addr1));
  8308. goto drop;
  8309. }
  8310. }
  8311. break;
  8312. case IW_MODE_INFRA:
  8313. default:
  8314. unicast = !is_multicast_ether_addr(hdr->addr3);
  8315. hdr_len = IEEE80211_3ADDR_LEN;
  8316. id = 0;
  8317. break;
  8318. }
  8319. tfd = &txq->bd[q->first_empty];
  8320. txq->txb[q->first_empty] = txb;
  8321. memset(tfd, 0, sizeof(*tfd));
  8322. tfd->u.data.station_number = id;
  8323. tfd->control_flags.message_type = TX_FRAME_TYPE;
  8324. tfd->control_flags.control_bits = TFD_NEED_IRQ_MASK;
  8325. tfd->u.data.cmd_id = DINO_CMD_TX;
  8326. tfd->u.data.len = cpu_to_le16(txb->payload_size);
  8327. remaining_bytes = txb->payload_size;
  8328. if (priv->assoc_request.ieee_mode == IPW_B_MODE)
  8329. tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_CCK;
  8330. else
  8331. tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_MODE_OFDM;
  8332. if (priv->assoc_request.preamble_length == DCT_FLAG_SHORT_PREAMBLE)
  8333. tfd->u.data.tx_flags |= DCT_FLAG_SHORT_PREAMBLE;
  8334. fc = le16_to_cpu(hdr->frame_ctl);
  8335. hdr->frame_ctl = cpu_to_le16(fc & ~IEEE80211_FCTL_MOREFRAGS);
  8336. memcpy(&tfd->u.data.tfd.tfd_24.mchdr, hdr, hdr_len);
  8337. if (likely(unicast))
  8338. tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
  8339. if (txb->encrypted && !priv->ieee->host_encrypt) {
  8340. switch (priv->ieee->sec.level) {
  8341. case SEC_LEVEL_3:
  8342. tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
  8343. IEEE80211_FCTL_PROTECTED;
  8344. /* XXX: ACK flag must be set for CCMP even if it
  8345. * is a multicast/broadcast packet, because CCMP
  8346. * group communication encrypted by GTK is
  8347. * actually done by the AP. */
  8348. if (!unicast)
  8349. tfd->u.data.tx_flags |= DCT_FLAG_ACK_REQD;
  8350. tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
  8351. tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_CCM;
  8352. tfd->u.data.key_index = 0;
  8353. tfd->u.data.key_index |= DCT_WEP_INDEX_USE_IMMEDIATE;
  8354. break;
  8355. case SEC_LEVEL_2:
  8356. tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
  8357. IEEE80211_FCTL_PROTECTED;
  8358. tfd->u.data.tx_flags &= ~DCT_FLAG_NO_WEP;
  8359. tfd->u.data.tx_flags_ext |= DCT_FLAG_EXT_SECURITY_TKIP;
  8360. tfd->u.data.key_index = DCT_WEP_INDEX_USE_IMMEDIATE;
  8361. break;
  8362. case SEC_LEVEL_1:
  8363. tfd->u.data.tfd.tfd_24.mchdr.frame_ctl |=
  8364. IEEE80211_FCTL_PROTECTED;
  8365. tfd->u.data.key_index = priv->ieee->tx_keyidx;
  8366. if (priv->ieee->sec.key_sizes[priv->ieee->tx_keyidx] <=
  8367. 40)
  8368. tfd->u.data.key_index |= DCT_WEP_KEY_64Bit;
  8369. else
  8370. tfd->u.data.key_index |= DCT_WEP_KEY_128Bit;
  8371. break;
  8372. case SEC_LEVEL_0:
  8373. break;
  8374. default:
  8375. printk(KERN_ERR "Unknow security level %d\n",
  8376. priv->ieee->sec.level);
  8377. break;
  8378. }
  8379. } else
  8380. /* No hardware encryption */
  8381. tfd->u.data.tx_flags |= DCT_FLAG_NO_WEP;
  8382. #ifdef CONFIG_IPW_QOS
  8383. ipw_qos_set_tx_queue_command(priv, pri, &(tfd->u.data), unicast);
  8384. #endif /* CONFIG_IPW_QOS */
  8385. /* payload */
  8386. tfd->u.data.num_chunks = cpu_to_le32(min((u8) (NUM_TFD_CHUNKS - 2),
  8387. txb->nr_frags));
  8388. IPW_DEBUG_FRAG("%i fragments being sent as %i chunks.\n",
  8389. txb->nr_frags, le32_to_cpu(tfd->u.data.num_chunks));
  8390. for (i = 0; i < le32_to_cpu(tfd->u.data.num_chunks); i++) {
  8391. IPW_DEBUG_FRAG("Adding fragment %i of %i (%d bytes).\n",
  8392. i, le32_to_cpu(tfd->u.data.num_chunks),
  8393. txb->fragments[i]->len - hdr_len);
  8394. IPW_DEBUG_TX("Dumping TX packet frag %i of %i (%d bytes):\n",
  8395. i, tfd->u.data.num_chunks,
  8396. txb->fragments[i]->len - hdr_len);
  8397. printk_buf(IPW_DL_TX, txb->fragments[i]->data + hdr_len,
  8398. txb->fragments[i]->len - hdr_len);
  8399. tfd->u.data.chunk_ptr[i] =
  8400. cpu_to_le32(pci_map_single
  8401. (priv->pci_dev,
  8402. txb->fragments[i]->data + hdr_len,
  8403. txb->fragments[i]->len - hdr_len,
  8404. PCI_DMA_TODEVICE));
  8405. tfd->u.data.chunk_len[i] =
  8406. cpu_to_le16(txb->fragments[i]->len - hdr_len);
  8407. }
  8408. if (i != txb->nr_frags) {
  8409. struct sk_buff *skb;
  8410. u16 remaining_bytes = 0;
  8411. int j;
  8412. for (j = i; j < txb->nr_frags; j++)
  8413. remaining_bytes += txb->fragments[j]->len - hdr_len;
  8414. printk(KERN_INFO "Trying to reallocate for %d bytes\n",
  8415. remaining_bytes);
  8416. skb = alloc_skb(remaining_bytes, GFP_ATOMIC);
  8417. if (skb != NULL) {
  8418. tfd->u.data.chunk_len[i] = cpu_to_le16(remaining_bytes);
  8419. for (j = i; j < txb->nr_frags; j++) {
  8420. int size = txb->fragments[j]->len - hdr_len;
  8421. printk(KERN_INFO "Adding frag %d %d...\n",
  8422. j, size);
  8423. memcpy(skb_put(skb, size),
  8424. txb->fragments[j]->data + hdr_len, size);
  8425. }
  8426. dev_kfree_skb_any(txb->fragments[i]);
  8427. txb->fragments[i] = skb;
  8428. tfd->u.data.chunk_ptr[i] =
  8429. cpu_to_le32(pci_map_single
  8430. (priv->pci_dev, skb->data,
  8431. tfd->u.data.chunk_len[i],
  8432. PCI_DMA_TODEVICE));
  8433. tfd->u.data.num_chunks =
  8434. cpu_to_le32(le32_to_cpu(tfd->u.data.num_chunks) +
  8435. 1);
  8436. }
  8437. }
  8438. /* kick DMA */
  8439. q->first_empty = ipw_queue_inc_wrap(q->first_empty, q->n_bd);
  8440. ipw_write32(priv, q->reg_w, q->first_empty);
  8441. return NETDEV_TX_OK;
  8442. drop:
  8443. IPW_DEBUG_DROP("Silently dropping Tx packet.\n");
  8444. ieee80211_txb_free(txb);
  8445. return NETDEV_TX_OK;
  8446. }
  8447. static int ipw_net_is_queue_full(struct net_device *dev, int pri)
  8448. {
  8449. struct ipw_priv *priv = ieee80211_priv(dev);
  8450. #ifdef CONFIG_IPW_QOS
  8451. int tx_id = ipw_get_tx_queue_number(priv, pri);
  8452. struct clx2_tx_queue *txq = &priv->txq[tx_id];
  8453. #else
  8454. struct clx2_tx_queue *txq = &priv->txq[0];
  8455. #endif /* CONFIG_IPW_QOS */
  8456. if (ipw_queue_space(&txq->q) < txq->q.high_mark)
  8457. return 1;
  8458. return 0;
  8459. }
  8460. static int ipw_net_hard_start_xmit(struct ieee80211_txb *txb,
  8461. struct net_device *dev, int pri)
  8462. {
  8463. struct ipw_priv *priv = ieee80211_priv(dev);
  8464. unsigned long flags;
  8465. int ret;
  8466. IPW_DEBUG_TX("dev->xmit(%d bytes)\n", txb->payload_size);
  8467. spin_lock_irqsave(&priv->lock, flags);
  8468. if (!(priv->status & STATUS_ASSOCIATED)) {
  8469. IPW_DEBUG_INFO("Tx attempt while not associated.\n");
  8470. priv->ieee->stats.tx_carrier_errors++;
  8471. netif_stop_queue(dev);
  8472. goto fail_unlock;
  8473. }
  8474. ret = ipw_tx_skb(priv, txb, pri);
  8475. if (ret == NETDEV_TX_OK)
  8476. __ipw_led_activity_on(priv);
  8477. spin_unlock_irqrestore(&priv->lock, flags);
  8478. return ret;
  8479. fail_unlock:
  8480. spin_unlock_irqrestore(&priv->lock, flags);
  8481. return 1;
  8482. }
  8483. static struct net_device_stats *ipw_net_get_stats(struct net_device *dev)
  8484. {
  8485. struct ipw_priv *priv = ieee80211_priv(dev);
  8486. priv->ieee->stats.tx_packets = priv->tx_packets;
  8487. priv->ieee->stats.rx_packets = priv->rx_packets;
  8488. return &priv->ieee->stats;
  8489. }
  8490. static void ipw_net_set_multicast_list(struct net_device *dev)
  8491. {
  8492. }
  8493. static int ipw_net_set_mac_address(struct net_device *dev, void *p)
  8494. {
  8495. struct ipw_priv *priv = ieee80211_priv(dev);
  8496. struct sockaddr *addr = p;
  8497. if (!is_valid_ether_addr(addr->sa_data))
  8498. return -EADDRNOTAVAIL;
  8499. down(&priv->sem);
  8500. priv->config |= CFG_CUSTOM_MAC;
  8501. memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
  8502. printk(KERN_INFO "%s: Setting MAC to " MAC_FMT "\n",
  8503. priv->net_dev->name, MAC_ARG(priv->mac_addr));
  8504. queue_work(priv->workqueue, &priv->adapter_restart);
  8505. up(&priv->sem);
  8506. return 0;
  8507. }
  8508. static void ipw_ethtool_get_drvinfo(struct net_device *dev,
  8509. struct ethtool_drvinfo *info)
  8510. {
  8511. struct ipw_priv *p = ieee80211_priv(dev);
  8512. char vers[64];
  8513. char date[32];
  8514. u32 len;
  8515. strcpy(info->driver, DRV_NAME);
  8516. strcpy(info->version, DRV_VERSION);
  8517. len = sizeof(vers);
  8518. ipw_get_ordinal(p, IPW_ORD_STAT_FW_VERSION, vers, &len);
  8519. len = sizeof(date);
  8520. ipw_get_ordinal(p, IPW_ORD_STAT_FW_DATE, date, &len);
  8521. snprintf(info->fw_version, sizeof(info->fw_version), "%s (%s)",
  8522. vers, date);
  8523. strcpy(info->bus_info, pci_name(p->pci_dev));
  8524. info->eedump_len = IPW_EEPROM_IMAGE_SIZE;
  8525. }
  8526. static u32 ipw_ethtool_get_link(struct net_device *dev)
  8527. {
  8528. struct ipw_priv *priv = ieee80211_priv(dev);
  8529. return (priv->status & STATUS_ASSOCIATED) != 0;
  8530. }
  8531. static int ipw_ethtool_get_eeprom_len(struct net_device *dev)
  8532. {
  8533. return IPW_EEPROM_IMAGE_SIZE;
  8534. }
  8535. static int ipw_ethtool_get_eeprom(struct net_device *dev,
  8536. struct ethtool_eeprom *eeprom, u8 * bytes)
  8537. {
  8538. struct ipw_priv *p = ieee80211_priv(dev);
  8539. if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
  8540. return -EINVAL;
  8541. down(&p->sem);
  8542. memcpy(bytes, &p->eeprom[eeprom->offset], eeprom->len);
  8543. up(&p->sem);
  8544. return 0;
  8545. }
  8546. static int ipw_ethtool_set_eeprom(struct net_device *dev,
  8547. struct ethtool_eeprom *eeprom, u8 * bytes)
  8548. {
  8549. struct ipw_priv *p = ieee80211_priv(dev);
  8550. int i;
  8551. if (eeprom->offset + eeprom->len > IPW_EEPROM_IMAGE_SIZE)
  8552. return -EINVAL;
  8553. down(&p->sem);
  8554. memcpy(&p->eeprom[eeprom->offset], bytes, eeprom->len);
  8555. for (i = IPW_EEPROM_DATA;
  8556. i < IPW_EEPROM_DATA + IPW_EEPROM_IMAGE_SIZE; i++)
  8557. ipw_write8(p, i, p->eeprom[i]);
  8558. up(&p->sem);
  8559. return 0;
  8560. }
  8561. static struct ethtool_ops ipw_ethtool_ops = {
  8562. .get_link = ipw_ethtool_get_link,
  8563. .get_drvinfo = ipw_ethtool_get_drvinfo,
  8564. .get_eeprom_len = ipw_ethtool_get_eeprom_len,
  8565. .get_eeprom = ipw_ethtool_get_eeprom,
  8566. .set_eeprom = ipw_ethtool_set_eeprom,
  8567. };
  8568. static irqreturn_t ipw_isr(int irq, void *data, struct pt_regs *regs)
  8569. {
  8570. struct ipw_priv *priv = data;
  8571. u32 inta, inta_mask;
  8572. if (!priv)
  8573. return IRQ_NONE;
  8574. spin_lock(&priv->lock);
  8575. if (!(priv->status & STATUS_INT_ENABLED)) {
  8576. /* Shared IRQ */
  8577. goto none;
  8578. }
  8579. inta = ipw_read32(priv, IPW_INTA_RW);
  8580. inta_mask = ipw_read32(priv, IPW_INTA_MASK_R);
  8581. if (inta == 0xFFFFFFFF) {
  8582. /* Hardware disappeared */
  8583. IPW_WARNING("IRQ INTA == 0xFFFFFFFF\n");
  8584. goto none;
  8585. }
  8586. if (!(inta & (IPW_INTA_MASK_ALL & inta_mask))) {
  8587. /* Shared interrupt */
  8588. goto none;
  8589. }
  8590. /* tell the device to stop sending interrupts */
  8591. ipw_disable_interrupts(priv);
  8592. /* ack current interrupts */
  8593. inta &= (IPW_INTA_MASK_ALL & inta_mask);
  8594. ipw_write32(priv, IPW_INTA_RW, inta);
  8595. /* Cache INTA value for our tasklet */
  8596. priv->isr_inta = inta;
  8597. tasklet_schedule(&priv->irq_tasklet);
  8598. spin_unlock(&priv->lock);
  8599. return IRQ_HANDLED;
  8600. none:
  8601. spin_unlock(&priv->lock);
  8602. return IRQ_NONE;
  8603. }
  8604. static void ipw_rf_kill(void *adapter)
  8605. {
  8606. struct ipw_priv *priv = adapter;
  8607. unsigned long flags;
  8608. spin_lock_irqsave(&priv->lock, flags);
  8609. if (rf_kill_active(priv)) {
  8610. IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
  8611. if (priv->workqueue)
  8612. queue_delayed_work(priv->workqueue,
  8613. &priv->rf_kill, 2 * HZ);
  8614. goto exit_unlock;
  8615. }
  8616. /* RF Kill is now disabled, so bring the device back up */
  8617. if (!(priv->status & STATUS_RF_KILL_MASK)) {
  8618. IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
  8619. "device\n");
  8620. /* we can not do an adapter restart while inside an irq lock */
  8621. queue_work(priv->workqueue, &priv->adapter_restart);
  8622. } else
  8623. IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
  8624. "enabled\n");
  8625. exit_unlock:
  8626. spin_unlock_irqrestore(&priv->lock, flags);
  8627. }
  8628. static void ipw_bg_rf_kill(void *data)
  8629. {
  8630. struct ipw_priv *priv = data;
  8631. down(&priv->sem);
  8632. ipw_rf_kill(data);
  8633. up(&priv->sem);
  8634. }
  8635. void ipw_link_up(struct ipw_priv *priv)
  8636. {
  8637. priv->last_seq_num = -1;
  8638. priv->last_frag_num = -1;
  8639. priv->last_packet_time = 0;
  8640. netif_carrier_on(priv->net_dev);
  8641. if (netif_queue_stopped(priv->net_dev)) {
  8642. IPW_DEBUG_NOTIF("waking queue\n");
  8643. netif_wake_queue(priv->net_dev);
  8644. } else {
  8645. IPW_DEBUG_NOTIF("starting queue\n");
  8646. netif_start_queue(priv->net_dev);
  8647. }
  8648. cancel_delayed_work(&priv->request_scan);
  8649. ipw_reset_stats(priv);
  8650. /* Ensure the rate is updated immediately */
  8651. priv->last_rate = ipw_get_current_rate(priv);
  8652. ipw_gather_stats(priv);
  8653. ipw_led_link_up(priv);
  8654. notify_wx_assoc_event(priv);
  8655. if (priv->config & CFG_BACKGROUND_SCAN)
  8656. queue_delayed_work(priv->workqueue, &priv->request_scan, HZ);
  8657. }
  8658. static void ipw_bg_link_up(void *data)
  8659. {
  8660. struct ipw_priv *priv = data;
  8661. down(&priv->sem);
  8662. ipw_link_up(data);
  8663. up(&priv->sem);
  8664. }
  8665. void ipw_link_down(struct ipw_priv *priv)
  8666. {
  8667. ipw_led_link_down(priv);
  8668. netif_carrier_off(priv->net_dev);
  8669. netif_stop_queue(priv->net_dev);
  8670. notify_wx_assoc_event(priv);
  8671. /* Cancel any queued work ... */
  8672. cancel_delayed_work(&priv->request_scan);
  8673. cancel_delayed_work(&priv->adhoc_check);
  8674. cancel_delayed_work(&priv->gather_stats);
  8675. ipw_reset_stats(priv);
  8676. if (!(priv->status & STATUS_EXIT_PENDING)) {
  8677. /* Queue up another scan... */
  8678. queue_work(priv->workqueue, &priv->request_scan);
  8679. }
  8680. }
  8681. static void ipw_bg_link_down(void *data)
  8682. {
  8683. struct ipw_priv *priv = data;
  8684. down(&priv->sem);
  8685. ipw_link_down(data);
  8686. up(&priv->sem);
  8687. }
  8688. static int ipw_setup_deferred_work(struct ipw_priv *priv)
  8689. {
  8690. int ret = 0;
  8691. priv->workqueue = create_workqueue(DRV_NAME);
  8692. init_waitqueue_head(&priv->wait_command_queue);
  8693. init_waitqueue_head(&priv->wait_state);
  8694. INIT_WORK(&priv->adhoc_check, ipw_bg_adhoc_check, priv);
  8695. INIT_WORK(&priv->associate, ipw_bg_associate, priv);
  8696. INIT_WORK(&priv->disassociate, ipw_bg_disassociate, priv);
  8697. INIT_WORK(&priv->system_config, ipw_system_config, priv);
  8698. INIT_WORK(&priv->rx_replenish, ipw_bg_rx_queue_replenish, priv);
  8699. INIT_WORK(&priv->adapter_restart, ipw_bg_adapter_restart, priv);
  8700. INIT_WORK(&priv->rf_kill, ipw_bg_rf_kill, priv);
  8701. INIT_WORK(&priv->up, (void (*)(void *))ipw_bg_up, priv);
  8702. INIT_WORK(&priv->down, (void (*)(void *))ipw_bg_down, priv);
  8703. INIT_WORK(&priv->request_scan,
  8704. (void (*)(void *))ipw_request_scan, priv);
  8705. INIT_WORK(&priv->gather_stats,
  8706. (void (*)(void *))ipw_bg_gather_stats, priv);
  8707. INIT_WORK(&priv->abort_scan, (void (*)(void *))ipw_bg_abort_scan, priv);
  8708. INIT_WORK(&priv->roam, ipw_bg_roam, priv);
  8709. INIT_WORK(&priv->scan_check, ipw_bg_scan_check, priv);
  8710. INIT_WORK(&priv->link_up, (void (*)(void *))ipw_bg_link_up, priv);
  8711. INIT_WORK(&priv->link_down, (void (*)(void *))ipw_bg_link_down, priv);
  8712. INIT_WORK(&priv->led_link_on, (void (*)(void *))ipw_bg_led_link_on,
  8713. priv);
  8714. INIT_WORK(&priv->led_link_off, (void (*)(void *))ipw_bg_led_link_off,
  8715. priv);
  8716. INIT_WORK(&priv->led_act_off, (void (*)(void *))ipw_bg_led_activity_off,
  8717. priv);
  8718. INIT_WORK(&priv->merge_networks,
  8719. (void (*)(void *))ipw_merge_adhoc_network, priv);
  8720. #ifdef CONFIG_IPW_QOS
  8721. INIT_WORK(&priv->qos_activate, (void (*)(void *))ipw_bg_qos_activate,
  8722. priv);
  8723. #endif /* CONFIG_IPW_QOS */
  8724. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  8725. ipw_irq_tasklet, (unsigned long)priv);
  8726. return ret;
  8727. }
  8728. static void shim__set_security(struct net_device *dev,
  8729. struct ieee80211_security *sec)
  8730. {
  8731. struct ipw_priv *priv = ieee80211_priv(dev);
  8732. int i;
  8733. for (i = 0; i < 4; i++) {
  8734. if (sec->flags & (1 << i)) {
  8735. priv->ieee->sec.encode_alg[i] = sec->encode_alg[i];
  8736. priv->ieee->sec.key_sizes[i] = sec->key_sizes[i];
  8737. if (sec->key_sizes[i] == 0)
  8738. priv->ieee->sec.flags &= ~(1 << i);
  8739. else {
  8740. memcpy(priv->ieee->sec.keys[i], sec->keys[i],
  8741. sec->key_sizes[i]);
  8742. priv->ieee->sec.flags |= (1 << i);
  8743. }
  8744. priv->status |= STATUS_SECURITY_UPDATED;
  8745. } else if (sec->level != SEC_LEVEL_1)
  8746. priv->ieee->sec.flags &= ~(1 << i);
  8747. }
  8748. if (sec->flags & SEC_ACTIVE_KEY) {
  8749. if (sec->active_key <= 3) {
  8750. priv->ieee->sec.active_key = sec->active_key;
  8751. priv->ieee->sec.flags |= SEC_ACTIVE_KEY;
  8752. } else
  8753. priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
  8754. priv->status |= STATUS_SECURITY_UPDATED;
  8755. } else
  8756. priv->ieee->sec.flags &= ~SEC_ACTIVE_KEY;
  8757. if ((sec->flags & SEC_AUTH_MODE) &&
  8758. (priv->ieee->sec.auth_mode != sec->auth_mode)) {
  8759. priv->ieee->sec.auth_mode = sec->auth_mode;
  8760. priv->ieee->sec.flags |= SEC_AUTH_MODE;
  8761. if (sec->auth_mode == WLAN_AUTH_SHARED_KEY)
  8762. priv->capability |= CAP_SHARED_KEY;
  8763. else
  8764. priv->capability &= ~CAP_SHARED_KEY;
  8765. priv->status |= STATUS_SECURITY_UPDATED;
  8766. }
  8767. if (sec->flags & SEC_ENABLED && priv->ieee->sec.enabled != sec->enabled) {
  8768. priv->ieee->sec.flags |= SEC_ENABLED;
  8769. priv->ieee->sec.enabled = sec->enabled;
  8770. priv->status |= STATUS_SECURITY_UPDATED;
  8771. if (sec->enabled)
  8772. priv->capability |= CAP_PRIVACY_ON;
  8773. else
  8774. priv->capability &= ~CAP_PRIVACY_ON;
  8775. }
  8776. if (sec->flags & SEC_ENCRYPT)
  8777. priv->ieee->sec.encrypt = sec->encrypt;
  8778. if (sec->flags & SEC_LEVEL && priv->ieee->sec.level != sec->level) {
  8779. priv->ieee->sec.level = sec->level;
  8780. priv->ieee->sec.flags |= SEC_LEVEL;
  8781. priv->status |= STATUS_SECURITY_UPDATED;
  8782. }
  8783. if (!priv->ieee->host_encrypt && (sec->flags & SEC_ENCRYPT))
  8784. ipw_set_hwcrypto_keys(priv);
  8785. /* To match current functionality of ipw2100 (which works well w/
  8786. * various supplicants, we don't force a disassociate if the
  8787. * privacy capability changes ... */
  8788. #if 0
  8789. if ((priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)) &&
  8790. (((priv->assoc_request.capability &
  8791. WLAN_CAPABILITY_PRIVACY) && !sec->enabled) ||
  8792. (!(priv->assoc_request.capability &
  8793. WLAN_CAPABILITY_PRIVACY) && sec->enabled))) {
  8794. IPW_DEBUG_ASSOC("Disassociating due to capability "
  8795. "change.\n");
  8796. ipw_disassociate(priv);
  8797. }
  8798. #endif
  8799. }
  8800. static int init_supported_rates(struct ipw_priv *priv,
  8801. struct ipw_supported_rates *rates)
  8802. {
  8803. /* TODO: Mask out rates based on priv->rates_mask */
  8804. memset(rates, 0, sizeof(*rates));
  8805. /* configure supported rates */
  8806. switch (priv->ieee->freq_band) {
  8807. case IEEE80211_52GHZ_BAND:
  8808. rates->ieee_mode = IPW_A_MODE;
  8809. rates->purpose = IPW_RATE_CAPABILITIES;
  8810. ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
  8811. IEEE80211_OFDM_DEFAULT_RATES_MASK);
  8812. break;
  8813. default: /* Mixed or 2.4Ghz */
  8814. rates->ieee_mode = IPW_G_MODE;
  8815. rates->purpose = IPW_RATE_CAPABILITIES;
  8816. ipw_add_cck_scan_rates(rates, IEEE80211_CCK_MODULATION,
  8817. IEEE80211_CCK_DEFAULT_RATES_MASK);
  8818. if (priv->ieee->modulation & IEEE80211_OFDM_MODULATION) {
  8819. ipw_add_ofdm_scan_rates(rates, IEEE80211_CCK_MODULATION,
  8820. IEEE80211_OFDM_DEFAULT_RATES_MASK);
  8821. }
  8822. break;
  8823. }
  8824. return 0;
  8825. }
  8826. static int ipw_config(struct ipw_priv *priv)
  8827. {
  8828. /* This is only called from ipw_up, which resets/reloads the firmware
  8829. so, we don't need to first disable the card before we configure
  8830. it */
  8831. if (ipw_set_tx_power(priv))
  8832. goto error;
  8833. /* initialize adapter address */
  8834. if (ipw_send_adapter_address(priv, priv->net_dev->dev_addr))
  8835. goto error;
  8836. /* set basic system config settings */
  8837. init_sys_config(&priv->sys_config);
  8838. if (priv->ieee->iw_mode == IW_MODE_ADHOC)
  8839. priv->sys_config.answer_broadcast_ssid_probe = 1;
  8840. else
  8841. priv->sys_config.answer_broadcast_ssid_probe = 0;
  8842. if (ipw_send_system_config(priv, &priv->sys_config))
  8843. goto error;
  8844. init_supported_rates(priv, &priv->rates);
  8845. if (ipw_send_supported_rates(priv, &priv->rates))
  8846. goto error;
  8847. /* Set request-to-send threshold */
  8848. if (priv->rts_threshold) {
  8849. if (ipw_send_rts_threshold(priv, priv->rts_threshold))
  8850. goto error;
  8851. }
  8852. #ifdef CONFIG_IPW_QOS
  8853. IPW_DEBUG_QOS("QoS: call ipw_qos_activate\n");
  8854. ipw_qos_activate(priv, NULL);
  8855. #endif /* CONFIG_IPW_QOS */
  8856. if (ipw_set_random_seed(priv))
  8857. goto error;
  8858. /* final state transition to the RUN state */
  8859. if (ipw_send_host_complete(priv))
  8860. goto error;
  8861. priv->status |= STATUS_INIT;
  8862. ipw_led_init(priv);
  8863. ipw_led_radio_on(priv);
  8864. priv->notif_missed_beacons = 0;
  8865. /* Set hardware WEP key if it is configured. */
  8866. if ((priv->capability & CAP_PRIVACY_ON) &&
  8867. (priv->ieee->sec.level == SEC_LEVEL_1) &&
  8868. !(priv->ieee->host_encrypt || priv->ieee->host_decrypt))
  8869. ipw_set_hwcrypto_keys(priv);
  8870. return 0;
  8871. error:
  8872. return -EIO;
  8873. }
  8874. /*
  8875. * NOTE:
  8876. *
  8877. * These tables have been tested in conjunction with the
  8878. * Intel PRO/Wireless 2200BG and 2915ABG Network Connection Adapters.
  8879. *
  8880. * Altering this values, using it on other hardware, or in geographies
  8881. * not intended for resale of the above mentioned Intel adapters has
  8882. * not been tested.
  8883. *
  8884. */
  8885. static const struct ieee80211_geo ipw_geos[] = {
  8886. { /* Restricted */
  8887. "---",
  8888. .bg_channels = 11,
  8889. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  8890. {2427, 4}, {2432, 5}, {2437, 6},
  8891. {2442, 7}, {2447, 8}, {2452, 9},
  8892. {2457, 10}, {2462, 11}},
  8893. },
  8894. { /* Custom US/Canada */
  8895. "ZZF",
  8896. .bg_channels = 11,
  8897. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  8898. {2427, 4}, {2432, 5}, {2437, 6},
  8899. {2442, 7}, {2447, 8}, {2452, 9},
  8900. {2457, 10}, {2462, 11}},
  8901. .a_channels = 8,
  8902. .a = {{5180, 36},
  8903. {5200, 40},
  8904. {5220, 44},
  8905. {5240, 48},
  8906. {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
  8907. {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
  8908. {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
  8909. {5320, 64, IEEE80211_CH_PASSIVE_ONLY}},
  8910. },
  8911. { /* Rest of World */
  8912. "ZZD",
  8913. .bg_channels = 13,
  8914. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  8915. {2427, 4}, {2432, 5}, {2437, 6},
  8916. {2442, 7}, {2447, 8}, {2452, 9},
  8917. {2457, 10}, {2462, 11}, {2467, 12},
  8918. {2472, 13}},
  8919. },
  8920. { /* Custom USA & Europe & High */
  8921. "ZZA",
  8922. .bg_channels = 11,
  8923. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  8924. {2427, 4}, {2432, 5}, {2437, 6},
  8925. {2442, 7}, {2447, 8}, {2452, 9},
  8926. {2457, 10}, {2462, 11}},
  8927. .a_channels = 13,
  8928. .a = {{5180, 36},
  8929. {5200, 40},
  8930. {5220, 44},
  8931. {5240, 48},
  8932. {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
  8933. {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
  8934. {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
  8935. {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
  8936. {5745, 149},
  8937. {5765, 153},
  8938. {5785, 157},
  8939. {5805, 161},
  8940. {5825, 165}},
  8941. },
  8942. { /* Custom NA & Europe */
  8943. "ZZB",
  8944. .bg_channels = 11,
  8945. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  8946. {2427, 4}, {2432, 5}, {2437, 6},
  8947. {2442, 7}, {2447, 8}, {2452, 9},
  8948. {2457, 10}, {2462, 11}},
  8949. .a_channels = 13,
  8950. .a = {{5180, 36},
  8951. {5200, 40},
  8952. {5220, 44},
  8953. {5240, 48},
  8954. {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
  8955. {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
  8956. {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
  8957. {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
  8958. {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
  8959. {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
  8960. {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
  8961. {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
  8962. {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
  8963. },
  8964. { /* Custom Japan */
  8965. "ZZC",
  8966. .bg_channels = 11,
  8967. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  8968. {2427, 4}, {2432, 5}, {2437, 6},
  8969. {2442, 7}, {2447, 8}, {2452, 9},
  8970. {2457, 10}, {2462, 11}},
  8971. .a_channels = 4,
  8972. .a = {{5170, 34}, {5190, 38},
  8973. {5210, 42}, {5230, 46}},
  8974. },
  8975. { /* Custom */
  8976. "ZZM",
  8977. .bg_channels = 11,
  8978. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  8979. {2427, 4}, {2432, 5}, {2437, 6},
  8980. {2442, 7}, {2447, 8}, {2452, 9},
  8981. {2457, 10}, {2462, 11}},
  8982. },
  8983. { /* Europe */
  8984. "ZZE",
  8985. .bg_channels = 13,
  8986. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  8987. {2427, 4}, {2432, 5}, {2437, 6},
  8988. {2442, 7}, {2447, 8}, {2452, 9},
  8989. {2457, 10}, {2462, 11}, {2467, 12},
  8990. {2472, 13}},
  8991. .a_channels = 19,
  8992. .a = {{5180, 36},
  8993. {5200, 40},
  8994. {5220, 44},
  8995. {5240, 48},
  8996. {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
  8997. {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
  8998. {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
  8999. {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
  9000. {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
  9001. {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
  9002. {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
  9003. {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
  9004. {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
  9005. {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
  9006. {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
  9007. {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
  9008. {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
  9009. {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
  9010. {5700, 140, IEEE80211_CH_PASSIVE_ONLY}},
  9011. },
  9012. { /* Custom Japan */
  9013. "ZZJ",
  9014. .bg_channels = 14,
  9015. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  9016. {2427, 4}, {2432, 5}, {2437, 6},
  9017. {2442, 7}, {2447, 8}, {2452, 9},
  9018. {2457, 10}, {2462, 11}, {2467, 12},
  9019. {2472, 13}, {2484, 14, IEEE80211_CH_B_ONLY}},
  9020. .a_channels = 4,
  9021. .a = {{5170, 34}, {5190, 38},
  9022. {5210, 42}, {5230, 46}},
  9023. },
  9024. { /* High Band */
  9025. "ZZH",
  9026. .bg_channels = 13,
  9027. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  9028. {2427, 4}, {2432, 5}, {2437, 6},
  9029. {2442, 7}, {2447, 8}, {2452, 9},
  9030. {2457, 10}, {2462, 11},
  9031. {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
  9032. {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
  9033. .a_channels = 4,
  9034. .a = {{5745, 149}, {5765, 153},
  9035. {5785, 157}, {5805, 161}},
  9036. },
  9037. { /* Custom Europe */
  9038. "ZZG",
  9039. .bg_channels = 13,
  9040. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  9041. {2427, 4}, {2432, 5}, {2437, 6},
  9042. {2442, 7}, {2447, 8}, {2452, 9},
  9043. {2457, 10}, {2462, 11},
  9044. {2467, 12}, {2472, 13}},
  9045. .a_channels = 4,
  9046. .a = {{5180, 36}, {5200, 40},
  9047. {5220, 44}, {5240, 48}},
  9048. },
  9049. { /* Europe */
  9050. "ZZK",
  9051. .bg_channels = 13,
  9052. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  9053. {2427, 4}, {2432, 5}, {2437, 6},
  9054. {2442, 7}, {2447, 8}, {2452, 9},
  9055. {2457, 10}, {2462, 11},
  9056. {2467, 12, IEEE80211_CH_PASSIVE_ONLY},
  9057. {2472, 13, IEEE80211_CH_PASSIVE_ONLY}},
  9058. .a_channels = 24,
  9059. .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
  9060. {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
  9061. {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
  9062. {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
  9063. {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
  9064. {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
  9065. {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
  9066. {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
  9067. {5500, 100, IEEE80211_CH_PASSIVE_ONLY},
  9068. {5520, 104, IEEE80211_CH_PASSIVE_ONLY},
  9069. {5540, 108, IEEE80211_CH_PASSIVE_ONLY},
  9070. {5560, 112, IEEE80211_CH_PASSIVE_ONLY},
  9071. {5580, 116, IEEE80211_CH_PASSIVE_ONLY},
  9072. {5600, 120, IEEE80211_CH_PASSIVE_ONLY},
  9073. {5620, 124, IEEE80211_CH_PASSIVE_ONLY},
  9074. {5640, 128, IEEE80211_CH_PASSIVE_ONLY},
  9075. {5660, 132, IEEE80211_CH_PASSIVE_ONLY},
  9076. {5680, 136, IEEE80211_CH_PASSIVE_ONLY},
  9077. {5700, 140, IEEE80211_CH_PASSIVE_ONLY},
  9078. {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
  9079. {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
  9080. {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
  9081. {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
  9082. {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
  9083. },
  9084. { /* Europe */
  9085. "ZZL",
  9086. .bg_channels = 11,
  9087. .bg = {{2412, 1}, {2417, 2}, {2422, 3},
  9088. {2427, 4}, {2432, 5}, {2437, 6},
  9089. {2442, 7}, {2447, 8}, {2452, 9},
  9090. {2457, 10}, {2462, 11}},
  9091. .a_channels = 13,
  9092. .a = {{5180, 36, IEEE80211_CH_PASSIVE_ONLY},
  9093. {5200, 40, IEEE80211_CH_PASSIVE_ONLY},
  9094. {5220, 44, IEEE80211_CH_PASSIVE_ONLY},
  9095. {5240, 48, IEEE80211_CH_PASSIVE_ONLY},
  9096. {5260, 52, IEEE80211_CH_PASSIVE_ONLY},
  9097. {5280, 56, IEEE80211_CH_PASSIVE_ONLY},
  9098. {5300, 60, IEEE80211_CH_PASSIVE_ONLY},
  9099. {5320, 64, IEEE80211_CH_PASSIVE_ONLY},
  9100. {5745, 149, IEEE80211_CH_PASSIVE_ONLY},
  9101. {5765, 153, IEEE80211_CH_PASSIVE_ONLY},
  9102. {5785, 157, IEEE80211_CH_PASSIVE_ONLY},
  9103. {5805, 161, IEEE80211_CH_PASSIVE_ONLY},
  9104. {5825, 165, IEEE80211_CH_PASSIVE_ONLY}},
  9105. }
  9106. };
  9107. #define MAX_HW_RESTARTS 5
  9108. static int ipw_up(struct ipw_priv *priv)
  9109. {
  9110. int rc, i, j;
  9111. if (priv->status & STATUS_EXIT_PENDING)
  9112. return -EIO;
  9113. for (i = 0; i < MAX_HW_RESTARTS; i++) {
  9114. /* Load the microcode, firmware, and eeprom.
  9115. * Also start the clocks. */
  9116. rc = ipw_load(priv);
  9117. if (rc) {
  9118. IPW_ERROR("Unable to load firmware: 0x%08X\n", rc);
  9119. return rc;
  9120. }
  9121. ipw_init_ordinals(priv);
  9122. if (!(priv->config & CFG_CUSTOM_MAC))
  9123. eeprom_parse_mac(priv, priv->mac_addr);
  9124. memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
  9125. for (j = 0; j < ARRAY_SIZE(ipw_geos); j++) {
  9126. if (!memcmp(&priv->eeprom[EEPROM_COUNTRY_CODE],
  9127. ipw_geos[j].name, 3))
  9128. break;
  9129. }
  9130. if (j == ARRAY_SIZE(ipw_geos))
  9131. j = 0;
  9132. if (ieee80211_set_geo(priv->ieee, &ipw_geos[j])) {
  9133. IPW_WARNING("Could not set geography.");
  9134. return 0;
  9135. }
  9136. IPW_DEBUG_INFO("Geography %03d [%s] detected.\n",
  9137. j, priv->ieee->geo.name);
  9138. if (priv->status & STATUS_RF_KILL_SW) {
  9139. IPW_WARNING("Radio disabled by module parameter.\n");
  9140. return 0;
  9141. } else if (rf_kill_active(priv)) {
  9142. IPW_WARNING("Radio Frequency Kill Switch is On:\n"
  9143. "Kill switch must be turned off for "
  9144. "wireless networking to work.\n");
  9145. queue_delayed_work(priv->workqueue, &priv->rf_kill,
  9146. 2 * HZ);
  9147. return 0;
  9148. }
  9149. rc = ipw_config(priv);
  9150. if (!rc) {
  9151. IPW_DEBUG_INFO("Configured device on count %i\n", i);
  9152. /* If configure to try and auto-associate, kick
  9153. * off a scan. */
  9154. queue_work(priv->workqueue, &priv->request_scan);
  9155. return 0;
  9156. }
  9157. IPW_DEBUG_INFO("Device configuration failed: 0x%08X\n", rc);
  9158. IPW_DEBUG_INFO("Failed to config device on retry %d of %d\n",
  9159. i, MAX_HW_RESTARTS);
  9160. /* We had an error bringing up the hardware, so take it
  9161. * all the way back down so we can try again */
  9162. ipw_down(priv);
  9163. }
  9164. /* tried to restart and config the device for as long as our
  9165. * patience could withstand */
  9166. IPW_ERROR("Unable to initialize device after %d attempts.\n", i);
  9167. return -EIO;
  9168. }
  9169. static void ipw_bg_up(void *data)
  9170. {
  9171. struct ipw_priv *priv = data;
  9172. down(&priv->sem);
  9173. ipw_up(data);
  9174. up(&priv->sem);
  9175. }
  9176. static void ipw_deinit(struct ipw_priv *priv)
  9177. {
  9178. int i;
  9179. if (priv->status & STATUS_SCANNING) {
  9180. IPW_DEBUG_INFO("Aborting scan during shutdown.\n");
  9181. ipw_abort_scan(priv);
  9182. }
  9183. if (priv->status & STATUS_ASSOCIATED) {
  9184. IPW_DEBUG_INFO("Disassociating during shutdown.\n");
  9185. ipw_disassociate(priv);
  9186. }
  9187. ipw_led_shutdown(priv);
  9188. /* Wait up to 1s for status to change to not scanning and not
  9189. * associated (disassociation can take a while for a ful 802.11
  9190. * exchange */
  9191. for (i = 1000; i && (priv->status &
  9192. (STATUS_DISASSOCIATING |
  9193. STATUS_ASSOCIATED | STATUS_SCANNING)); i--)
  9194. udelay(10);
  9195. if (priv->status & (STATUS_DISASSOCIATING |
  9196. STATUS_ASSOCIATED | STATUS_SCANNING))
  9197. IPW_DEBUG_INFO("Still associated or scanning...\n");
  9198. else
  9199. IPW_DEBUG_INFO("Took %dms to de-init\n", 1000 - i);
  9200. /* Attempt to disable the card */
  9201. ipw_send_card_disable(priv, 0);
  9202. priv->status &= ~STATUS_INIT;
  9203. }
  9204. static void ipw_down(struct ipw_priv *priv)
  9205. {
  9206. int exit_pending = priv->status & STATUS_EXIT_PENDING;
  9207. priv->status |= STATUS_EXIT_PENDING;
  9208. if (ipw_is_init(priv))
  9209. ipw_deinit(priv);
  9210. /* Wipe out the EXIT_PENDING status bit if we are not actually
  9211. * exiting the module */
  9212. if (!exit_pending)
  9213. priv->status &= ~STATUS_EXIT_PENDING;
  9214. /* tell the device to stop sending interrupts */
  9215. ipw_disable_interrupts(priv);
  9216. /* Clear all bits but the RF Kill */
  9217. priv->status &= STATUS_RF_KILL_MASK | STATUS_EXIT_PENDING;
  9218. netif_carrier_off(priv->net_dev);
  9219. netif_stop_queue(priv->net_dev);
  9220. ipw_stop_nic(priv);
  9221. ipw_led_radio_off(priv);
  9222. }
  9223. static void ipw_bg_down(void *data)
  9224. {
  9225. struct ipw_priv *priv = data;
  9226. down(&priv->sem);
  9227. ipw_down(data);
  9228. up(&priv->sem);
  9229. }
  9230. #if WIRELESS_EXT < 18
  9231. static int ipw_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  9232. {
  9233. struct iwreq *wrq = (struct iwreq *)rq;
  9234. int ret = -1;
  9235. switch (cmd) {
  9236. case IPW_IOCTL_WPA_SUPPLICANT:
  9237. ret = ipw_wpa_supplicant(dev, &wrq->u.data);
  9238. return ret;
  9239. default:
  9240. return -EOPNOTSUPP;
  9241. }
  9242. return -EOPNOTSUPP;
  9243. }
  9244. #endif
  9245. /* Called by register_netdev() */
  9246. static int ipw_net_init(struct net_device *dev)
  9247. {
  9248. struct ipw_priv *priv = ieee80211_priv(dev);
  9249. down(&priv->sem);
  9250. if (ipw_up(priv)) {
  9251. up(&priv->sem);
  9252. return -EIO;
  9253. }
  9254. up(&priv->sem);
  9255. return 0;
  9256. }
  9257. /* PCI driver stuff */
  9258. static struct pci_device_id card_ids[] = {
  9259. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2701, 0, 0, 0},
  9260. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2702, 0, 0, 0},
  9261. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2711, 0, 0, 0},
  9262. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2712, 0, 0, 0},
  9263. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2721, 0, 0, 0},
  9264. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2722, 0, 0, 0},
  9265. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2731, 0, 0, 0},
  9266. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2732, 0, 0, 0},
  9267. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2741, 0, 0, 0},
  9268. {PCI_VENDOR_ID_INTEL, 0x1043, 0x103c, 0x2741, 0, 0, 0},
  9269. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2742, 0, 0, 0},
  9270. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2751, 0, 0, 0},
  9271. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2752, 0, 0, 0},
  9272. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2753, 0, 0, 0},
  9273. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2754, 0, 0, 0},
  9274. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2761, 0, 0, 0},
  9275. {PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, 0x2762, 0, 0, 0},
  9276. {PCI_VENDOR_ID_INTEL, 0x104f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
  9277. {PCI_VENDOR_ID_INTEL, 0x4220, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
  9278. {PCI_VENDOR_ID_INTEL, 0x4221, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* BG */
  9279. {PCI_VENDOR_ID_INTEL, 0x4223, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
  9280. {PCI_VENDOR_ID_INTEL, 0x4224, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0}, /* ABG */
  9281. /* required last entry */
  9282. {0,}
  9283. };
  9284. MODULE_DEVICE_TABLE(pci, card_ids);
  9285. static struct attribute *ipw_sysfs_entries[] = {
  9286. &dev_attr_rf_kill.attr,
  9287. &dev_attr_direct_dword.attr,
  9288. &dev_attr_indirect_byte.attr,
  9289. &dev_attr_indirect_dword.attr,
  9290. &dev_attr_mem_gpio_reg.attr,
  9291. &dev_attr_command_event_reg.attr,
  9292. &dev_attr_nic_type.attr,
  9293. &dev_attr_status.attr,
  9294. &dev_attr_cfg.attr,
  9295. &dev_attr_error.attr,
  9296. &dev_attr_event_log.attr,
  9297. &dev_attr_eeprom_delay.attr,
  9298. &dev_attr_ucode_version.attr,
  9299. &dev_attr_rtc.attr,
  9300. &dev_attr_scan_age.attr,
  9301. &dev_attr_led.attr,
  9302. &dev_attr_speed_scan.attr,
  9303. &dev_attr_net_stats.attr,
  9304. NULL
  9305. };
  9306. static struct attribute_group ipw_attribute_group = {
  9307. .name = NULL, /* put in device directory */
  9308. .attrs = ipw_sysfs_entries,
  9309. };
  9310. static int ipw_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  9311. {
  9312. int err = 0;
  9313. struct net_device *net_dev;
  9314. void __iomem *base;
  9315. u32 length, val;
  9316. struct ipw_priv *priv;
  9317. int i;
  9318. net_dev = alloc_ieee80211(sizeof(struct ipw_priv));
  9319. if (net_dev == NULL) {
  9320. err = -ENOMEM;
  9321. goto out;
  9322. }
  9323. priv = ieee80211_priv(net_dev);
  9324. priv->ieee = netdev_priv(net_dev);
  9325. priv->net_dev = net_dev;
  9326. priv->pci_dev = pdev;
  9327. #ifdef CONFIG_IPW_DEBUG
  9328. ipw_debug_level = debug;
  9329. #endif
  9330. spin_lock_init(&priv->lock);
  9331. for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++)
  9332. INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
  9333. init_MUTEX(&priv->sem);
  9334. if (pci_enable_device(pdev)) {
  9335. err = -ENODEV;
  9336. goto out_free_ieee80211;
  9337. }
  9338. pci_set_master(pdev);
  9339. err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
  9340. if (!err)
  9341. err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
  9342. if (err) {
  9343. printk(KERN_WARNING DRV_NAME ": No suitable DMA available.\n");
  9344. goto out_pci_disable_device;
  9345. }
  9346. pci_set_drvdata(pdev, priv);
  9347. err = pci_request_regions(pdev, DRV_NAME);
  9348. if (err)
  9349. goto out_pci_disable_device;
  9350. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  9351. * PCI Tx retries from interfering with C3 CPU state */
  9352. pci_read_config_dword(pdev, 0x40, &val);
  9353. if ((val & 0x0000ff00) != 0)
  9354. pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
  9355. length = pci_resource_len(pdev, 0);
  9356. priv->hw_len = length;
  9357. base = ioremap_nocache(pci_resource_start(pdev, 0), length);
  9358. if (!base) {
  9359. err = -ENODEV;
  9360. goto out_pci_release_regions;
  9361. }
  9362. priv->hw_base = base;
  9363. IPW_DEBUG_INFO("pci_resource_len = 0x%08x\n", length);
  9364. IPW_DEBUG_INFO("pci_resource_base = %p\n", base);
  9365. err = ipw_setup_deferred_work(priv);
  9366. if (err) {
  9367. IPW_ERROR("Unable to setup deferred work\n");
  9368. goto out_iounmap;
  9369. }
  9370. ipw_sw_reset(priv, 1);
  9371. err = request_irq(pdev->irq, ipw_isr, SA_SHIRQ, DRV_NAME, priv);
  9372. if (err) {
  9373. IPW_ERROR("Error allocating IRQ %d\n", pdev->irq);
  9374. goto out_destroy_workqueue;
  9375. }
  9376. SET_MODULE_OWNER(net_dev);
  9377. SET_NETDEV_DEV(net_dev, &pdev->dev);
  9378. ipw_wx_data.spy_data = &priv->ieee->spy_data;
  9379. ipw_wx_data.ieee80211 = priv->ieee;
  9380. down(&priv->sem);
  9381. priv->ieee->hard_start_xmit = ipw_net_hard_start_xmit;
  9382. priv->ieee->set_security = shim__set_security;
  9383. priv->ieee->is_queue_full = ipw_net_is_queue_full;
  9384. #ifdef CONFIG_IPW_QOS
  9385. priv->ieee->handle_management = ipw_handle_management;
  9386. #endif /* CONFIG_IPW_QOS */
  9387. priv->ieee->perfect_rssi = -20;
  9388. priv->ieee->worst_rssi = -85;
  9389. net_dev->open = ipw_net_open;
  9390. net_dev->stop = ipw_net_stop;
  9391. net_dev->init = ipw_net_init;
  9392. #if WIRELESS_EXT < 18
  9393. net_dev->do_ioctl = ipw_ioctl;
  9394. #endif
  9395. net_dev->get_stats = ipw_net_get_stats;
  9396. net_dev->set_multicast_list = ipw_net_set_multicast_list;
  9397. net_dev->set_mac_address = ipw_net_set_mac_address;
  9398. net_dev->get_wireless_stats = ipw_get_wireless_stats;
  9399. net_dev->wireless_data = &ipw_wx_data;
  9400. net_dev->wireless_handlers = &ipw_wx_handler_def;
  9401. net_dev->ethtool_ops = &ipw_ethtool_ops;
  9402. net_dev->irq = pdev->irq;
  9403. net_dev->base_addr = (unsigned long)priv->hw_base;
  9404. net_dev->mem_start = pci_resource_start(pdev, 0);
  9405. net_dev->mem_end = net_dev->mem_start + pci_resource_len(pdev, 0) - 1;
  9406. err = sysfs_create_group(&pdev->dev.kobj, &ipw_attribute_group);
  9407. if (err) {
  9408. IPW_ERROR("failed to create sysfs device attributes\n");
  9409. up(&priv->sem);
  9410. goto out_release_irq;
  9411. }
  9412. up(&priv->sem);
  9413. err = register_netdev(net_dev);
  9414. if (err) {
  9415. IPW_ERROR("failed to register network device\n");
  9416. goto out_remove_sysfs;
  9417. }
  9418. return 0;
  9419. out_remove_sysfs:
  9420. sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
  9421. out_release_irq:
  9422. free_irq(pdev->irq, priv);
  9423. out_destroy_workqueue:
  9424. destroy_workqueue(priv->workqueue);
  9425. priv->workqueue = NULL;
  9426. out_iounmap:
  9427. iounmap(priv->hw_base);
  9428. out_pci_release_regions:
  9429. pci_release_regions(pdev);
  9430. out_pci_disable_device:
  9431. pci_disable_device(pdev);
  9432. pci_set_drvdata(pdev, NULL);
  9433. out_free_ieee80211:
  9434. free_ieee80211(priv->net_dev);
  9435. out:
  9436. return err;
  9437. }
  9438. static void ipw_pci_remove(struct pci_dev *pdev)
  9439. {
  9440. struct ipw_priv *priv = pci_get_drvdata(pdev);
  9441. struct list_head *p, *q;
  9442. int i;
  9443. if (!priv)
  9444. return;
  9445. down(&priv->sem);
  9446. priv->status |= STATUS_EXIT_PENDING;
  9447. ipw_down(priv);
  9448. sysfs_remove_group(&pdev->dev.kobj, &ipw_attribute_group);
  9449. up(&priv->sem);
  9450. unregister_netdev(priv->net_dev);
  9451. if (priv->rxq) {
  9452. ipw_rx_queue_free(priv, priv->rxq);
  9453. priv->rxq = NULL;
  9454. }
  9455. ipw_tx_queue_free(priv);
  9456. /* ipw_down will ensure that there is no more pending work
  9457. * in the workqueue's, so we can safely remove them now. */
  9458. cancel_delayed_work(&priv->adhoc_check);
  9459. cancel_delayed_work(&priv->gather_stats);
  9460. cancel_delayed_work(&priv->request_scan);
  9461. cancel_delayed_work(&priv->rf_kill);
  9462. cancel_delayed_work(&priv->scan_check);
  9463. destroy_workqueue(priv->workqueue);
  9464. priv->workqueue = NULL;
  9465. /* Free MAC hash list for ADHOC */
  9466. for (i = 0; i < IPW_IBSS_MAC_HASH_SIZE; i++) {
  9467. list_for_each_safe(p, q, &priv->ibss_mac_hash[i]) {
  9468. kfree(list_entry(p, struct ipw_ibss_seq, list));
  9469. list_del(p);
  9470. }
  9471. }
  9472. if (priv->error) {
  9473. ipw_free_error_log(priv->error);
  9474. priv->error = NULL;
  9475. }
  9476. free_irq(pdev->irq, priv);
  9477. iounmap(priv->hw_base);
  9478. pci_release_regions(pdev);
  9479. pci_disable_device(pdev);
  9480. pci_set_drvdata(pdev, NULL);
  9481. free_ieee80211(priv->net_dev);
  9482. free_firmware();
  9483. }
  9484. #ifdef CONFIG_PM
  9485. static int ipw_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  9486. {
  9487. struct ipw_priv *priv = pci_get_drvdata(pdev);
  9488. struct net_device *dev = priv->net_dev;
  9489. printk(KERN_INFO "%s: Going into suspend...\n", dev->name);
  9490. /* Take down the device; powers it off, etc. */
  9491. ipw_down(priv);
  9492. /* Remove the PRESENT state of the device */
  9493. netif_device_detach(dev);
  9494. pci_save_state(pdev);
  9495. pci_disable_device(pdev);
  9496. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  9497. return 0;
  9498. }
  9499. static int ipw_pci_resume(struct pci_dev *pdev)
  9500. {
  9501. struct ipw_priv *priv = pci_get_drvdata(pdev);
  9502. struct net_device *dev = priv->net_dev;
  9503. u32 val;
  9504. printk(KERN_INFO "%s: Coming out of suspend...\n", dev->name);
  9505. pci_set_power_state(pdev, PCI_D0);
  9506. pci_enable_device(pdev);
  9507. pci_restore_state(pdev);
  9508. /*
  9509. * Suspend/Resume resets the PCI configuration space, so we have to
  9510. * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
  9511. * from interfering with C3 CPU state. pci_restore_state won't help
  9512. * here since it only restores the first 64 bytes pci config header.
  9513. */
  9514. pci_read_config_dword(pdev, 0x40, &val);
  9515. if ((val & 0x0000ff00) != 0)
  9516. pci_write_config_dword(pdev, 0x40, val & 0xffff00ff);
  9517. /* Set the device back into the PRESENT state; this will also wake
  9518. * the queue of needed */
  9519. netif_device_attach(dev);
  9520. /* Bring the device back up */
  9521. queue_work(priv->workqueue, &priv->up);
  9522. return 0;
  9523. }
  9524. #endif
  9525. /* driver initialization stuff */
  9526. static struct pci_driver ipw_driver = {
  9527. .name = DRV_NAME,
  9528. .id_table = card_ids,
  9529. .probe = ipw_pci_probe,
  9530. .remove = __devexit_p(ipw_pci_remove),
  9531. #ifdef CONFIG_PM
  9532. .suspend = ipw_pci_suspend,
  9533. .resume = ipw_pci_resume,
  9534. #endif
  9535. };
  9536. static int __init ipw_init(void)
  9537. {
  9538. int ret;
  9539. printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
  9540. printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
  9541. ret = pci_module_init(&ipw_driver);
  9542. if (ret) {
  9543. IPW_ERROR("Unable to initialize PCI module\n");
  9544. return ret;
  9545. }
  9546. ret = driver_create_file(&ipw_driver.driver, &driver_attr_debug_level);
  9547. if (ret) {
  9548. IPW_ERROR("Unable to create driver sysfs file\n");
  9549. pci_unregister_driver(&ipw_driver);
  9550. return ret;
  9551. }
  9552. return ret;
  9553. }
  9554. static void __exit ipw_exit(void)
  9555. {
  9556. driver_remove_file(&ipw_driver.driver, &driver_attr_debug_level);
  9557. pci_unregister_driver(&ipw_driver);
  9558. }
  9559. module_param(disable, int, 0444);
  9560. MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
  9561. module_param(associate, int, 0444);
  9562. MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
  9563. module_param(auto_create, int, 0444);
  9564. MODULE_PARM_DESC(auto_create, "auto create adhoc network (default on)");
  9565. module_param(led, int, 0444);
  9566. MODULE_PARM_DESC(led, "enable led control on some systems (default 0 off)\n");
  9567. module_param(debug, int, 0444);
  9568. MODULE_PARM_DESC(debug, "debug output mask");
  9569. module_param(channel, int, 0444);
  9570. MODULE_PARM_DESC(channel, "channel to limit associate to (default 0 [ANY])");
  9571. #ifdef CONFIG_IPW_QOS
  9572. module_param(qos_enable, int, 0444);
  9573. MODULE_PARM_DESC(qos_enable, "enable all QoS functionalitis");
  9574. module_param(qos_burst_enable, int, 0444);
  9575. MODULE_PARM_DESC(qos_burst_enable, "enable QoS burst mode");
  9576. module_param(qos_no_ack_mask, int, 0444);
  9577. MODULE_PARM_DESC(qos_no_ack_mask, "mask Tx_Queue to no ack");
  9578. module_param(burst_duration_CCK, int, 0444);
  9579. MODULE_PARM_DESC(burst_duration_CCK, "set CCK burst value");
  9580. module_param(burst_duration_OFDM, int, 0444);
  9581. MODULE_PARM_DESC(burst_duration_OFDM, "set OFDM burst value");
  9582. #endif /* CONFIG_IPW_QOS */
  9583. #ifdef CONFIG_IPW2200_MONITOR
  9584. module_param(mode, int, 0444);
  9585. MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
  9586. #else
  9587. module_param(mode, int, 0444);
  9588. MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS)");
  9589. #endif
  9590. module_param(hwcrypto, int, 0444);
  9591. MODULE_PARM_DESC(hwcrypto, "enable hardware crypto (default on)");
  9592. module_exit(ipw_exit);
  9593. module_init(ipw_init);