ipw2100.c 223 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680
  1. /******************************************************************************
  2. Copyright(c) 2003 - 2005 Intel Corporation. All rights reserved.
  3. This program is free software; you can redistribute it and/or modify it
  4. under the terms of version 2 of the GNU General Public License as
  5. published by the Free Software Foundation.
  6. This program is distributed in the hope that it will be useful, but WITHOUT
  7. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  8. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  9. more details.
  10. You should have received a copy of the GNU General Public License along with
  11. this program; if not, write to the Free Software Foundation, Inc., 59
  12. Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  13. The full GNU General Public License is included in this distribution in the
  14. file called LICENSE.
  15. Contact Information:
  16. James P. Ketrenos <ipw2100-admin@linux.intel.com>
  17. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  18. Portions of this file are based on the sample_* files provided by Wireless
  19. Extensions 0.26 package and copyright (c) 1997-2003 Jean Tourrilhes
  20. <jt@hpl.hp.com>
  21. Portions of this file are based on the Host AP project,
  22. Copyright (c) 2001-2002, SSH Communications Security Corp and Jouni Malinen
  23. <jkmaline@cc.hut.fi>
  24. Copyright (c) 2002-2003, Jouni Malinen <jkmaline@cc.hut.fi>
  25. Portions of ipw2100_mod_firmware_load, ipw2100_do_mod_firmware_load, and
  26. ipw2100_fw_load are loosely based on drivers/sound/sound_firmware.c
  27. available in the 2.4.25 kernel sources, and are copyright (c) Alan Cox
  28. ******************************************************************************/
  29. /*
  30. Initial driver on which this is based was developed by Janusz Gorycki,
  31. Maciej Urbaniak, and Maciej Sosnowski.
  32. Promiscuous mode support added by Jacek Wysoczynski and Maciej Urbaniak.
  33. Theory of Operation
  34. Tx - Commands and Data
  35. Firmware and host share a circular queue of Transmit Buffer Descriptors (TBDs)
  36. Each TBD contains a pointer to the physical (dma_addr_t) address of data being
  37. sent to the firmware as well as the length of the data.
  38. The host writes to the TBD queue at the WRITE index. The WRITE index points
  39. to the _next_ packet to be written and is advanced when after the TBD has been
  40. filled.
  41. The firmware pulls from the TBD queue at the READ index. The READ index points
  42. to the currently being read entry, and is advanced once the firmware is
  43. done with a packet.
  44. When data is sent to the firmware, the first TBD is used to indicate to the
  45. firmware if a Command or Data is being sent. If it is Command, all of the
  46. command information is contained within the physical address referred to by the
  47. TBD. If it is Data, the first TBD indicates the type of data packet, number
  48. of fragments, etc. The next TBD then referrs to the actual packet location.
  49. The Tx flow cycle is as follows:
  50. 1) ipw2100_tx() is called by kernel with SKB to transmit
  51. 2) Packet is move from the tx_free_list and appended to the transmit pending
  52. list (tx_pend_list)
  53. 3) work is scheduled to move pending packets into the shared circular queue.
  54. 4) when placing packet in the circular queue, the incoming SKB is DMA mapped
  55. to a physical address. That address is entered into a TBD. Two TBDs are
  56. filled out. The first indicating a data packet, the second referring to the
  57. actual payload data.
  58. 5) the packet is removed from tx_pend_list and placed on the end of the
  59. firmware pending list (fw_pend_list)
  60. 6) firmware is notified that the WRITE index has
  61. 7) Once the firmware has processed the TBD, INTA is triggered.
  62. 8) For each Tx interrupt received from the firmware, the READ index is checked
  63. to see which TBDs are done being processed.
  64. 9) For each TBD that has been processed, the ISR pulls the oldest packet
  65. from the fw_pend_list.
  66. 10)The packet structure contained in the fw_pend_list is then used
  67. to unmap the DMA address and to free the SKB originally passed to the driver
  68. from the kernel.
  69. 11)The packet structure is placed onto the tx_free_list
  70. The above steps are the same for commands, only the msg_free_list/msg_pend_list
  71. are used instead of tx_free_list/tx_pend_list
  72. ...
  73. Critical Sections / Locking :
  74. There are two locks utilized. The first is the low level lock (priv->low_lock)
  75. that protects the following:
  76. - Access to the Tx/Rx queue lists via priv->low_lock. The lists are as follows:
  77. tx_free_list : Holds pre-allocated Tx buffers.
  78. TAIL modified in __ipw2100_tx_process()
  79. HEAD modified in ipw2100_tx()
  80. tx_pend_list : Holds used Tx buffers waiting to go into the TBD ring
  81. TAIL modified ipw2100_tx()
  82. HEAD modified by ipw2100_tx_send_data()
  83. msg_free_list : Holds pre-allocated Msg (Command) buffers
  84. TAIL modified in __ipw2100_tx_process()
  85. HEAD modified in ipw2100_hw_send_command()
  86. msg_pend_list : Holds used Msg buffers waiting to go into the TBD ring
  87. TAIL modified in ipw2100_hw_send_command()
  88. HEAD modified in ipw2100_tx_send_commands()
  89. The flow of data on the TX side is as follows:
  90. MSG_FREE_LIST + COMMAND => MSG_PEND_LIST => TBD => MSG_FREE_LIST
  91. TX_FREE_LIST + DATA => TX_PEND_LIST => TBD => TX_FREE_LIST
  92. The methods that work on the TBD ring are protected via priv->low_lock.
  93. - The internal data state of the device itself
  94. - Access to the firmware read/write indexes for the BD queues
  95. and associated logic
  96. All external entry functions are locked with the priv->action_lock to ensure
  97. that only one external action is invoked at a time.
  98. */
  99. #include <linux/compiler.h>
  100. #include <linux/config.h>
  101. #include <linux/errno.h>
  102. #include <linux/if_arp.h>
  103. #include <linux/in6.h>
  104. #include <linux/in.h>
  105. #include <linux/ip.h>
  106. #include <linux/kernel.h>
  107. #include <linux/kmod.h>
  108. #include <linux/module.h>
  109. #include <linux/netdevice.h>
  110. #include <linux/ethtool.h>
  111. #include <linux/pci.h>
  112. #include <linux/dma-mapping.h>
  113. #include <linux/proc_fs.h>
  114. #include <linux/skbuff.h>
  115. #include <asm/uaccess.h>
  116. #include <asm/io.h>
  117. #define __KERNEL_SYSCALLS__
  118. #include <linux/fs.h>
  119. #include <linux/mm.h>
  120. #include <linux/slab.h>
  121. #include <linux/unistd.h>
  122. #include <linux/stringify.h>
  123. #include <linux/tcp.h>
  124. #include <linux/types.h>
  125. #include <linux/version.h>
  126. #include <linux/time.h>
  127. #include <linux/firmware.h>
  128. #include <linux/acpi.h>
  129. #include <linux/ctype.h>
  130. #include "ipw2100.h"
  131. #define IPW2100_VERSION "1.1.0"
  132. #define DRV_NAME "ipw2100"
  133. #define DRV_VERSION IPW2100_VERSION
  134. #define DRV_DESCRIPTION "Intel(R) PRO/Wireless 2100 Network Driver"
  135. #define DRV_COPYRIGHT "Copyright(c) 2003-2004 Intel Corporation"
  136. /* Debugging stuff */
  137. #ifdef CONFIG_IPW_DEBUG
  138. #define CONFIG_IPW2100_RX_DEBUG /* Reception debugging */
  139. #endif
  140. MODULE_DESCRIPTION(DRV_DESCRIPTION);
  141. MODULE_VERSION(DRV_VERSION);
  142. MODULE_AUTHOR(DRV_COPYRIGHT);
  143. MODULE_LICENSE("GPL");
  144. static int debug = 0;
  145. static int mode = 0;
  146. static int channel = 0;
  147. static int associate = 1;
  148. static int disable = 0;
  149. #ifdef CONFIG_PM
  150. static struct ipw2100_fw ipw2100_firmware;
  151. #endif
  152. #include <linux/moduleparam.h>
  153. module_param(debug, int, 0444);
  154. module_param(mode, int, 0444);
  155. module_param(channel, int, 0444);
  156. module_param(associate, int, 0444);
  157. module_param(disable, int, 0444);
  158. MODULE_PARM_DESC(debug, "debug level");
  159. MODULE_PARM_DESC(mode, "network mode (0=BSS,1=IBSS,2=Monitor)");
  160. MODULE_PARM_DESC(channel, "channel");
  161. MODULE_PARM_DESC(associate, "auto associate when scanning (default on)");
  162. MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
  163. static u32 ipw2100_debug_level = IPW_DL_NONE;
  164. #ifdef CONFIG_IPW_DEBUG
  165. #define IPW_DEBUG(level, message...) \
  166. do { \
  167. if (ipw2100_debug_level & (level)) { \
  168. printk(KERN_DEBUG "ipw2100: %c %s ", \
  169. in_interrupt() ? 'I' : 'U', __FUNCTION__); \
  170. printk(message); \
  171. } \
  172. } while (0)
  173. #else
  174. #define IPW_DEBUG(level, message...) do {} while (0)
  175. #endif /* CONFIG_IPW_DEBUG */
  176. #ifdef CONFIG_IPW_DEBUG
  177. static const char *command_types[] = {
  178. "undefined",
  179. "unused", /* HOST_ATTENTION */
  180. "HOST_COMPLETE",
  181. "unused", /* SLEEP */
  182. "unused", /* HOST_POWER_DOWN */
  183. "unused",
  184. "SYSTEM_CONFIG",
  185. "unused", /* SET_IMR */
  186. "SSID",
  187. "MANDATORY_BSSID",
  188. "AUTHENTICATION_TYPE",
  189. "ADAPTER_ADDRESS",
  190. "PORT_TYPE",
  191. "INTERNATIONAL_MODE",
  192. "CHANNEL",
  193. "RTS_THRESHOLD",
  194. "FRAG_THRESHOLD",
  195. "POWER_MODE",
  196. "TX_RATES",
  197. "BASIC_TX_RATES",
  198. "WEP_KEY_INFO",
  199. "unused",
  200. "unused",
  201. "unused",
  202. "unused",
  203. "WEP_KEY_INDEX",
  204. "WEP_FLAGS",
  205. "ADD_MULTICAST",
  206. "CLEAR_ALL_MULTICAST",
  207. "BEACON_INTERVAL",
  208. "ATIM_WINDOW",
  209. "CLEAR_STATISTICS",
  210. "undefined",
  211. "undefined",
  212. "undefined",
  213. "undefined",
  214. "TX_POWER_INDEX",
  215. "undefined",
  216. "undefined",
  217. "undefined",
  218. "undefined",
  219. "undefined",
  220. "undefined",
  221. "BROADCAST_SCAN",
  222. "CARD_DISABLE",
  223. "PREFERRED_BSSID",
  224. "SET_SCAN_OPTIONS",
  225. "SCAN_DWELL_TIME",
  226. "SWEEP_TABLE",
  227. "AP_OR_STATION_TABLE",
  228. "GROUP_ORDINALS",
  229. "SHORT_RETRY_LIMIT",
  230. "LONG_RETRY_LIMIT",
  231. "unused", /* SAVE_CALIBRATION */
  232. "unused", /* RESTORE_CALIBRATION */
  233. "undefined",
  234. "undefined",
  235. "undefined",
  236. "HOST_PRE_POWER_DOWN",
  237. "unused", /* HOST_INTERRUPT_COALESCING */
  238. "undefined",
  239. "CARD_DISABLE_PHY_OFF",
  240. "MSDU_TX_RATES"
  241. "undefined",
  242. "undefined",
  243. "SET_STATION_STAT_BITS",
  244. "CLEAR_STATIONS_STAT_BITS",
  245. "LEAP_ROGUE_MODE",
  246. "SET_SECURITY_INFORMATION",
  247. "DISASSOCIATION_BSSID",
  248. "SET_WPA_ASS_IE"
  249. };
  250. #endif
  251. /* Pre-decl until we get the code solid and then we can clean it up */
  252. static void ipw2100_tx_send_commands(struct ipw2100_priv *priv);
  253. static void ipw2100_tx_send_data(struct ipw2100_priv *priv);
  254. static int ipw2100_adapter_setup(struct ipw2100_priv *priv);
  255. static void ipw2100_queues_initialize(struct ipw2100_priv *priv);
  256. static void ipw2100_queues_free(struct ipw2100_priv *priv);
  257. static int ipw2100_queues_allocate(struct ipw2100_priv *priv);
  258. static int ipw2100_fw_download(struct ipw2100_priv *priv,
  259. struct ipw2100_fw *fw);
  260. static int ipw2100_get_firmware(struct ipw2100_priv *priv,
  261. struct ipw2100_fw *fw);
  262. static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
  263. size_t max);
  264. static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf,
  265. size_t max);
  266. static void ipw2100_release_firmware(struct ipw2100_priv *priv,
  267. struct ipw2100_fw *fw);
  268. static int ipw2100_ucode_download(struct ipw2100_priv *priv,
  269. struct ipw2100_fw *fw);
  270. static void ipw2100_wx_event_work(struct ipw2100_priv *priv);
  271. static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device * dev);
  272. static struct iw_handler_def ipw2100_wx_handler_def;
  273. static inline void read_register(struct net_device *dev, u32 reg, u32 *val)
  274. {
  275. *val = readl((void __iomem *)(dev->base_addr + reg));
  276. IPW_DEBUG_IO("r: 0x%08X => 0x%08X\n", reg, *val);
  277. }
  278. static inline void write_register(struct net_device *dev, u32 reg, u32 val)
  279. {
  280. writel(val, (void __iomem *)(dev->base_addr + reg));
  281. IPW_DEBUG_IO("w: 0x%08X <= 0x%08X\n", reg, val);
  282. }
  283. static inline void read_register_word(struct net_device *dev, u32 reg, u16 *val)
  284. {
  285. *val = readw((void __iomem *)(dev->base_addr + reg));
  286. IPW_DEBUG_IO("r: 0x%08X => %04X\n", reg, *val);
  287. }
  288. static inline void read_register_byte(struct net_device *dev, u32 reg, u8 *val)
  289. {
  290. *val = readb((void __iomem *)(dev->base_addr + reg));
  291. IPW_DEBUG_IO("r: 0x%08X => %02X\n", reg, *val);
  292. }
  293. static inline void write_register_word(struct net_device *dev, u32 reg, u16 val)
  294. {
  295. writew(val, (void __iomem *)(dev->base_addr + reg));
  296. IPW_DEBUG_IO("w: 0x%08X <= %04X\n", reg, val);
  297. }
  298. static inline void write_register_byte(struct net_device *dev, u32 reg, u8 val)
  299. {
  300. writeb(val, (void __iomem *)(dev->base_addr + reg));
  301. IPW_DEBUG_IO("w: 0x%08X =< %02X\n", reg, val);
  302. }
  303. static inline void read_nic_dword(struct net_device *dev, u32 addr, u32 *val)
  304. {
  305. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
  306. addr & IPW_REG_INDIRECT_ADDR_MASK);
  307. read_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
  308. }
  309. static inline void write_nic_dword(struct net_device *dev, u32 addr, u32 val)
  310. {
  311. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
  312. addr & IPW_REG_INDIRECT_ADDR_MASK);
  313. write_register(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
  314. }
  315. static inline void read_nic_word(struct net_device *dev, u32 addr, u16 *val)
  316. {
  317. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
  318. addr & IPW_REG_INDIRECT_ADDR_MASK);
  319. read_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
  320. }
  321. static inline void write_nic_word(struct net_device *dev, u32 addr, u16 val)
  322. {
  323. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
  324. addr & IPW_REG_INDIRECT_ADDR_MASK);
  325. write_register_word(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
  326. }
  327. static inline void read_nic_byte(struct net_device *dev, u32 addr, u8 *val)
  328. {
  329. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
  330. addr & IPW_REG_INDIRECT_ADDR_MASK);
  331. read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
  332. }
  333. static inline void write_nic_byte(struct net_device *dev, u32 addr, u8 val)
  334. {
  335. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
  336. addr & IPW_REG_INDIRECT_ADDR_MASK);
  337. write_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA, val);
  338. }
  339. static inline void write_nic_auto_inc_address(struct net_device *dev, u32 addr)
  340. {
  341. write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
  342. addr & IPW_REG_INDIRECT_ADDR_MASK);
  343. }
  344. static inline void write_nic_dword_auto_inc(struct net_device *dev, u32 val)
  345. {
  346. write_register(dev, IPW_REG_AUTOINCREMENT_DATA, val);
  347. }
  348. static inline void write_nic_memory(struct net_device *dev, u32 addr, u32 len,
  349. const u8 *buf)
  350. {
  351. u32 aligned_addr;
  352. u32 aligned_len;
  353. u32 dif_len;
  354. u32 i;
  355. /* read first nibble byte by byte */
  356. aligned_addr = addr & (~0x3);
  357. dif_len = addr - aligned_addr;
  358. if (dif_len) {
  359. /* Start reading at aligned_addr + dif_len */
  360. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
  361. aligned_addr);
  362. for (i = dif_len; i < 4; i++, buf++)
  363. write_register_byte(
  364. dev, IPW_REG_INDIRECT_ACCESS_DATA + i,
  365. *buf);
  366. len -= dif_len;
  367. aligned_addr += 4;
  368. }
  369. /* read DWs through autoincrement registers */
  370. write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
  371. aligned_addr);
  372. aligned_len = len & (~0x3);
  373. for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
  374. write_register(
  375. dev, IPW_REG_AUTOINCREMENT_DATA, *(u32 *)buf);
  376. /* copy the last nibble */
  377. dif_len = len - aligned_len;
  378. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS, aligned_addr);
  379. for (i = 0; i < dif_len; i++, buf++)
  380. write_register_byte(
  381. dev, IPW_REG_INDIRECT_ACCESS_DATA + i, *buf);
  382. }
  383. static inline void read_nic_memory(struct net_device *dev, u32 addr, u32 len,
  384. u8 *buf)
  385. {
  386. u32 aligned_addr;
  387. u32 aligned_len;
  388. u32 dif_len;
  389. u32 i;
  390. /* read first nibble byte by byte */
  391. aligned_addr = addr & (~0x3);
  392. dif_len = addr - aligned_addr;
  393. if (dif_len) {
  394. /* Start reading at aligned_addr + dif_len */
  395. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
  396. aligned_addr);
  397. for (i = dif_len; i < 4; i++, buf++)
  398. read_register_byte(
  399. dev, IPW_REG_INDIRECT_ACCESS_DATA + i, buf);
  400. len -= dif_len;
  401. aligned_addr += 4;
  402. }
  403. /* read DWs through autoincrement registers */
  404. write_register(dev, IPW_REG_AUTOINCREMENT_ADDRESS,
  405. aligned_addr);
  406. aligned_len = len & (~0x3);
  407. for (i = 0; i < aligned_len; i += 4, buf += 4, aligned_addr += 4)
  408. read_register(dev, IPW_REG_AUTOINCREMENT_DATA,
  409. (u32 *)buf);
  410. /* copy the last nibble */
  411. dif_len = len - aligned_len;
  412. write_register(dev, IPW_REG_INDIRECT_ACCESS_ADDRESS,
  413. aligned_addr);
  414. for (i = 0; i < dif_len; i++, buf++)
  415. read_register_byte(dev, IPW_REG_INDIRECT_ACCESS_DATA +
  416. i, buf);
  417. }
  418. static inline int ipw2100_hw_is_adapter_in_system(struct net_device *dev)
  419. {
  420. return (dev->base_addr &&
  421. (readl((void __iomem *)(dev->base_addr + IPW_REG_DOA_DEBUG_AREA_START))
  422. == IPW_DATA_DOA_DEBUG_VALUE));
  423. }
  424. static int ipw2100_get_ordinal(struct ipw2100_priv *priv, u32 ord,
  425. void *val, u32 *len)
  426. {
  427. struct ipw2100_ordinals *ordinals = &priv->ordinals;
  428. u32 addr;
  429. u32 field_info;
  430. u16 field_len;
  431. u16 field_count;
  432. u32 total_length;
  433. if (ordinals->table1_addr == 0) {
  434. printk(KERN_WARNING DRV_NAME ": attempt to use fw ordinals "
  435. "before they have been loaded.\n");
  436. return -EINVAL;
  437. }
  438. if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
  439. if (*len < IPW_ORD_TAB_1_ENTRY_SIZE) {
  440. *len = IPW_ORD_TAB_1_ENTRY_SIZE;
  441. printk(KERN_WARNING DRV_NAME
  442. ": ordinal buffer length too small, need %zd\n",
  443. IPW_ORD_TAB_1_ENTRY_SIZE);
  444. return -EINVAL;
  445. }
  446. read_nic_dword(priv->net_dev, ordinals->table1_addr + (ord << 2),
  447. &addr);
  448. read_nic_dword(priv->net_dev, addr, val);
  449. *len = IPW_ORD_TAB_1_ENTRY_SIZE;
  450. return 0;
  451. }
  452. if (IS_ORDINAL_TABLE_TWO(ordinals, ord)) {
  453. ord -= IPW_START_ORD_TAB_2;
  454. /* get the address of statistic */
  455. read_nic_dword(priv->net_dev, ordinals->table2_addr + (ord << 3),
  456. &addr);
  457. /* get the second DW of statistics ;
  458. * two 16-bit words - first is length, second is count */
  459. read_nic_dword(priv->net_dev,
  460. ordinals->table2_addr + (ord << 3) + sizeof(u32),
  461. &field_info);
  462. /* get each entry length */
  463. field_len = *((u16 *)&field_info);
  464. /* get number of entries */
  465. field_count = *(((u16 *)&field_info) + 1);
  466. /* abort if no enought memory */
  467. total_length = field_len * field_count;
  468. if (total_length > *len) {
  469. *len = total_length;
  470. return -EINVAL;
  471. }
  472. *len = total_length;
  473. if (!total_length)
  474. return 0;
  475. /* read the ordinal data from the SRAM */
  476. read_nic_memory(priv->net_dev, addr, total_length, val);
  477. return 0;
  478. }
  479. printk(KERN_WARNING DRV_NAME ": ordinal %d neither in table 1 nor "
  480. "in table 2\n", ord);
  481. return -EINVAL;
  482. }
  483. static int ipw2100_set_ordinal(struct ipw2100_priv *priv, u32 ord, u32 *val,
  484. u32 *len)
  485. {
  486. struct ipw2100_ordinals *ordinals = &priv->ordinals;
  487. u32 addr;
  488. if (IS_ORDINAL_TABLE_ONE(ordinals, ord)) {
  489. if (*len != IPW_ORD_TAB_1_ENTRY_SIZE) {
  490. *len = IPW_ORD_TAB_1_ENTRY_SIZE;
  491. IPW_DEBUG_INFO("wrong size\n");
  492. return -EINVAL;
  493. }
  494. read_nic_dword(priv->net_dev, ordinals->table1_addr + (ord << 2),
  495. &addr);
  496. write_nic_dword(priv->net_dev, addr, *val);
  497. *len = IPW_ORD_TAB_1_ENTRY_SIZE;
  498. return 0;
  499. }
  500. IPW_DEBUG_INFO("wrong table\n");
  501. if (IS_ORDINAL_TABLE_TWO(ordinals, ord))
  502. return -EINVAL;
  503. return -EINVAL;
  504. }
  505. static char *snprint_line(char *buf, size_t count,
  506. const u8 *data, u32 len, u32 ofs)
  507. {
  508. int out, i, j, l;
  509. char c;
  510. out = snprintf(buf, count, "%08X", ofs);
  511. for (l = 0, i = 0; i < 2; i++) {
  512. out += snprintf(buf + out, count - out, " ");
  513. for (j = 0; j < 8 && l < len; j++, l++)
  514. out += snprintf(buf + out, count - out, "%02X ",
  515. data[(i * 8 + j)]);
  516. for (; j < 8; j++)
  517. out += snprintf(buf + out, count - out, " ");
  518. }
  519. out += snprintf(buf + out, count - out, " ");
  520. for (l = 0, i = 0; i < 2; i++) {
  521. out += snprintf(buf + out, count - out, " ");
  522. for (j = 0; j < 8 && l < len; j++, l++) {
  523. c = data[(i * 8 + j)];
  524. if (!isascii(c) || !isprint(c))
  525. c = '.';
  526. out += snprintf(buf + out, count - out, "%c", c);
  527. }
  528. for (; j < 8; j++)
  529. out += snprintf(buf + out, count - out, " ");
  530. }
  531. return buf;
  532. }
  533. static void printk_buf(int level, const u8 *data, u32 len)
  534. {
  535. char line[81];
  536. u32 ofs = 0;
  537. if (!(ipw2100_debug_level & level))
  538. return;
  539. while (len) {
  540. printk(KERN_DEBUG "%s\n",
  541. snprint_line(line, sizeof(line), &data[ofs],
  542. min(len, 16U), ofs));
  543. ofs += 16;
  544. len -= min(len, 16U);
  545. }
  546. }
  547. #define MAX_RESET_BACKOFF 10
  548. static inline void schedule_reset(struct ipw2100_priv *priv)
  549. {
  550. unsigned long now = get_seconds();
  551. /* If we haven't received a reset request within the backoff period,
  552. * then we can reset the backoff interval so this reset occurs
  553. * immediately */
  554. if (priv->reset_backoff &&
  555. (now - priv->last_reset > priv->reset_backoff))
  556. priv->reset_backoff = 0;
  557. priv->last_reset = get_seconds();
  558. if (!(priv->status & STATUS_RESET_PENDING)) {
  559. IPW_DEBUG_INFO("%s: Scheduling firmware restart (%ds).\n",
  560. priv->net_dev->name, priv->reset_backoff);
  561. netif_carrier_off(priv->net_dev);
  562. netif_stop_queue(priv->net_dev);
  563. priv->status |= STATUS_RESET_PENDING;
  564. if (priv->reset_backoff)
  565. queue_delayed_work(priv->workqueue, &priv->reset_work,
  566. priv->reset_backoff * HZ);
  567. else
  568. queue_work(priv->workqueue, &priv->reset_work);
  569. if (priv->reset_backoff < MAX_RESET_BACKOFF)
  570. priv->reset_backoff++;
  571. wake_up_interruptible(&priv->wait_command_queue);
  572. } else
  573. IPW_DEBUG_INFO("%s: Firmware restart already in progress.\n",
  574. priv->net_dev->name);
  575. }
  576. #define HOST_COMPLETE_TIMEOUT (2 * HZ)
  577. static int ipw2100_hw_send_command(struct ipw2100_priv *priv,
  578. struct host_command * cmd)
  579. {
  580. struct list_head *element;
  581. struct ipw2100_tx_packet *packet;
  582. unsigned long flags;
  583. int err = 0;
  584. IPW_DEBUG_HC("Sending %s command (#%d), %d bytes\n",
  585. command_types[cmd->host_command], cmd->host_command,
  586. cmd->host_command_length);
  587. printk_buf(IPW_DL_HC, (u8*)cmd->host_command_parameters,
  588. cmd->host_command_length);
  589. spin_lock_irqsave(&priv->low_lock, flags);
  590. if (priv->fatal_error) {
  591. IPW_DEBUG_INFO("Attempt to send command while hardware in fatal error condition.\n");
  592. err = -EIO;
  593. goto fail_unlock;
  594. }
  595. if (!(priv->status & STATUS_RUNNING)) {
  596. IPW_DEBUG_INFO("Attempt to send command while hardware is not running.\n");
  597. err = -EIO;
  598. goto fail_unlock;
  599. }
  600. if (priv->status & STATUS_CMD_ACTIVE) {
  601. IPW_DEBUG_INFO("Attempt to send command while another command is pending.\n");
  602. err = -EBUSY;
  603. goto fail_unlock;
  604. }
  605. if (list_empty(&priv->msg_free_list)) {
  606. IPW_DEBUG_INFO("no available msg buffers\n");
  607. goto fail_unlock;
  608. }
  609. priv->status |= STATUS_CMD_ACTIVE;
  610. priv->messages_sent++;
  611. element = priv->msg_free_list.next;
  612. packet = list_entry(element, struct ipw2100_tx_packet, list);
  613. packet->jiffy_start = jiffies;
  614. /* initialize the firmware command packet */
  615. packet->info.c_struct.cmd->host_command_reg = cmd->host_command;
  616. packet->info.c_struct.cmd->host_command_reg1 = cmd->host_command1;
  617. packet->info.c_struct.cmd->host_command_len_reg = cmd->host_command_length;
  618. packet->info.c_struct.cmd->sequence = cmd->host_command_sequence;
  619. memcpy(packet->info.c_struct.cmd->host_command_params_reg,
  620. cmd->host_command_parameters,
  621. sizeof(packet->info.c_struct.cmd->host_command_params_reg));
  622. list_del(element);
  623. DEC_STAT(&priv->msg_free_stat);
  624. list_add_tail(element, &priv->msg_pend_list);
  625. INC_STAT(&priv->msg_pend_stat);
  626. ipw2100_tx_send_commands(priv);
  627. ipw2100_tx_send_data(priv);
  628. spin_unlock_irqrestore(&priv->low_lock, flags);
  629. /*
  630. * We must wait for this command to complete before another
  631. * command can be sent... but if we wait more than 3 seconds
  632. * then there is a problem.
  633. */
  634. err = wait_event_interruptible_timeout(
  635. priv->wait_command_queue, !(priv->status & STATUS_CMD_ACTIVE),
  636. HOST_COMPLETE_TIMEOUT);
  637. if (err == 0) {
  638. IPW_DEBUG_INFO("Command completion failed out after %dms.\n",
  639. HOST_COMPLETE_TIMEOUT / (HZ / 100));
  640. priv->fatal_error = IPW2100_ERR_MSG_TIMEOUT;
  641. priv->status &= ~STATUS_CMD_ACTIVE;
  642. schedule_reset(priv);
  643. return -EIO;
  644. }
  645. if (priv->fatal_error) {
  646. printk(KERN_WARNING DRV_NAME ": %s: firmware fatal error\n",
  647. priv->net_dev->name);
  648. return -EIO;
  649. }
  650. /* !!!!! HACK TEST !!!!!
  651. * When lots of debug trace statements are enabled, the driver
  652. * doesn't seem to have as many firmware restart cycles...
  653. *
  654. * As a test, we're sticking in a 1/100s delay here */
  655. set_current_state(TASK_UNINTERRUPTIBLE);
  656. schedule_timeout(HZ / 100);
  657. return 0;
  658. fail_unlock:
  659. spin_unlock_irqrestore(&priv->low_lock, flags);
  660. return err;
  661. }
  662. /*
  663. * Verify the values and data access of the hardware
  664. * No locks needed or used. No functions called.
  665. */
  666. static int ipw2100_verify(struct ipw2100_priv *priv)
  667. {
  668. u32 data1, data2;
  669. u32 address;
  670. u32 val1 = 0x76543210;
  671. u32 val2 = 0xFEDCBA98;
  672. /* Domain 0 check - all values should be DOA_DEBUG */
  673. for (address = IPW_REG_DOA_DEBUG_AREA_START;
  674. address < IPW_REG_DOA_DEBUG_AREA_END;
  675. address += sizeof(u32)) {
  676. read_register(priv->net_dev, address, &data1);
  677. if (data1 != IPW_DATA_DOA_DEBUG_VALUE)
  678. return -EIO;
  679. }
  680. /* Domain 1 check - use arbitrary read/write compare */
  681. for (address = 0; address < 5; address++) {
  682. /* The memory area is not used now */
  683. write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
  684. val1);
  685. write_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
  686. val2);
  687. read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x32,
  688. &data1);
  689. read_register(priv->net_dev, IPW_REG_DOMAIN_1_OFFSET + 0x36,
  690. &data2);
  691. if (val1 == data1 && val2 == data2)
  692. return 0;
  693. }
  694. return -EIO;
  695. }
  696. /*
  697. *
  698. * Loop until the CARD_DISABLED bit is the same value as the
  699. * supplied parameter
  700. *
  701. * TODO: See if it would be more efficient to do a wait/wake
  702. * cycle and have the completion event trigger the wakeup
  703. *
  704. */
  705. #define IPW_CARD_DISABLE_COMPLETE_WAIT 100 // 100 milli
  706. static int ipw2100_wait_for_card_state(struct ipw2100_priv *priv, int state)
  707. {
  708. int i;
  709. u32 card_state;
  710. u32 len = sizeof(card_state);
  711. int err;
  712. for (i = 0; i <= IPW_CARD_DISABLE_COMPLETE_WAIT * 1000; i += 50) {
  713. err = ipw2100_get_ordinal(priv, IPW_ORD_CARD_DISABLED,
  714. &card_state, &len);
  715. if (err) {
  716. IPW_DEBUG_INFO("Query of CARD_DISABLED ordinal "
  717. "failed.\n");
  718. return 0;
  719. }
  720. /* We'll break out if either the HW state says it is
  721. * in the state we want, or if HOST_COMPLETE command
  722. * finishes */
  723. if ((card_state == state) ||
  724. ((priv->status & STATUS_ENABLED) ?
  725. IPW_HW_STATE_ENABLED : IPW_HW_STATE_DISABLED) == state) {
  726. if (state == IPW_HW_STATE_ENABLED)
  727. priv->status |= STATUS_ENABLED;
  728. else
  729. priv->status &= ~STATUS_ENABLED;
  730. return 0;
  731. }
  732. udelay(50);
  733. }
  734. IPW_DEBUG_INFO("ipw2100_wait_for_card_state to %s state timed out\n",
  735. state ? "DISABLED" : "ENABLED");
  736. return -EIO;
  737. }
  738. /*********************************************************************
  739. Procedure : sw_reset_and_clock
  740. Purpose : Asserts s/w reset, asserts clock initialization
  741. and waits for clock stabilization
  742. ********************************************************************/
  743. static int sw_reset_and_clock(struct ipw2100_priv *priv)
  744. {
  745. int i;
  746. u32 r;
  747. // assert s/w reset
  748. write_register(priv->net_dev, IPW_REG_RESET_REG,
  749. IPW_AUX_HOST_RESET_REG_SW_RESET);
  750. // wait for clock stabilization
  751. for (i = 0; i < 1000; i++) {
  752. udelay(IPW_WAIT_RESET_ARC_COMPLETE_DELAY);
  753. // check clock ready bit
  754. read_register(priv->net_dev, IPW_REG_RESET_REG, &r);
  755. if (r & IPW_AUX_HOST_RESET_REG_PRINCETON_RESET)
  756. break;
  757. }
  758. if (i == 1000)
  759. return -EIO; // TODO: better error value
  760. /* set "initialization complete" bit to move adapter to
  761. * D0 state */
  762. write_register(priv->net_dev, IPW_REG_GP_CNTRL,
  763. IPW_AUX_HOST_GP_CNTRL_BIT_INIT_DONE);
  764. /* wait for clock stabilization */
  765. for (i = 0; i < 10000; i++) {
  766. udelay(IPW_WAIT_CLOCK_STABILIZATION_DELAY * 4);
  767. /* check clock ready bit */
  768. read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
  769. if (r & IPW_AUX_HOST_GP_CNTRL_BIT_CLOCK_READY)
  770. break;
  771. }
  772. if (i == 10000)
  773. return -EIO; /* TODO: better error value */
  774. /* set D0 standby bit */
  775. read_register(priv->net_dev, IPW_REG_GP_CNTRL, &r);
  776. write_register(priv->net_dev, IPW_REG_GP_CNTRL,
  777. r | IPW_AUX_HOST_GP_CNTRL_BIT_HOST_ALLOWS_STANDBY);
  778. return 0;
  779. }
  780. /*********************************************************************
  781. Procedure : ipw2100_download_firmware
  782. Purpose : Initiaze adapter after power on.
  783. The sequence is:
  784. 1. assert s/w reset first!
  785. 2. awake clocks & wait for clock stabilization
  786. 3. hold ARC (don't ask me why...)
  787. 4. load Dino ucode and reset/clock init again
  788. 5. zero-out shared mem
  789. 6. download f/w
  790. *******************************************************************/
  791. static int ipw2100_download_firmware(struct ipw2100_priv *priv)
  792. {
  793. u32 address;
  794. int err;
  795. #ifndef CONFIG_PM
  796. /* Fetch the firmware and microcode */
  797. struct ipw2100_fw ipw2100_firmware;
  798. #endif
  799. if (priv->fatal_error) {
  800. IPW_DEBUG_ERROR("%s: ipw2100_download_firmware called after "
  801. "fatal error %d. Interface must be brought down.\n",
  802. priv->net_dev->name, priv->fatal_error);
  803. return -EINVAL;
  804. }
  805. #ifdef CONFIG_PM
  806. if (!ipw2100_firmware.version) {
  807. err = ipw2100_get_firmware(priv, &ipw2100_firmware);
  808. if (err) {
  809. IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
  810. priv->net_dev->name, err);
  811. priv->fatal_error = IPW2100_ERR_FW_LOAD;
  812. goto fail;
  813. }
  814. }
  815. #else
  816. err = ipw2100_get_firmware(priv, &ipw2100_firmware);
  817. if (err) {
  818. IPW_DEBUG_ERROR("%s: ipw2100_get_firmware failed: %d\n",
  819. priv->net_dev->name, err);
  820. priv->fatal_error = IPW2100_ERR_FW_LOAD;
  821. goto fail;
  822. }
  823. #endif
  824. priv->firmware_version = ipw2100_firmware.version;
  825. /* s/w reset and clock stabilization */
  826. err = sw_reset_and_clock(priv);
  827. if (err) {
  828. IPW_DEBUG_ERROR("%s: sw_reset_and_clock failed: %d\n",
  829. priv->net_dev->name, err);
  830. goto fail;
  831. }
  832. err = ipw2100_verify(priv);
  833. if (err) {
  834. IPW_DEBUG_ERROR("%s: ipw2100_verify failed: %d\n",
  835. priv->net_dev->name, err);
  836. goto fail;
  837. }
  838. /* Hold ARC */
  839. write_nic_dword(priv->net_dev,
  840. IPW_INTERNAL_REGISTER_HALT_AND_RESET,
  841. 0x80000000);
  842. /* allow ARC to run */
  843. write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
  844. /* load microcode */
  845. err = ipw2100_ucode_download(priv, &ipw2100_firmware);
  846. if (err) {
  847. printk(KERN_ERR DRV_NAME ": %s: Error loading microcode: %d\n",
  848. priv->net_dev->name, err);
  849. goto fail;
  850. }
  851. /* release ARC */
  852. write_nic_dword(priv->net_dev,
  853. IPW_INTERNAL_REGISTER_HALT_AND_RESET,
  854. 0x00000000);
  855. /* s/w reset and clock stabilization (again!!!) */
  856. err = sw_reset_and_clock(priv);
  857. if (err) {
  858. printk(KERN_ERR DRV_NAME ": %s: sw_reset_and_clock failed: %d\n",
  859. priv->net_dev->name, err);
  860. goto fail;
  861. }
  862. /* load f/w */
  863. err = ipw2100_fw_download(priv, &ipw2100_firmware);
  864. if (err) {
  865. IPW_DEBUG_ERROR("%s: Error loading firmware: %d\n",
  866. priv->net_dev->name, err);
  867. goto fail;
  868. }
  869. #ifndef CONFIG_PM
  870. /*
  871. * When the .resume method of the driver is called, the other
  872. * part of the system, i.e. the ide driver could still stay in
  873. * the suspend stage. This prevents us from loading the firmware
  874. * from the disk. --YZ
  875. */
  876. /* free any storage allocated for firmware image */
  877. ipw2100_release_firmware(priv, &ipw2100_firmware);
  878. #endif
  879. /* zero out Domain 1 area indirectly (Si requirement) */
  880. for (address = IPW_HOST_FW_SHARED_AREA0;
  881. address < IPW_HOST_FW_SHARED_AREA0_END; address += 4)
  882. write_nic_dword(priv->net_dev, address, 0);
  883. for (address = IPW_HOST_FW_SHARED_AREA1;
  884. address < IPW_HOST_FW_SHARED_AREA1_END; address += 4)
  885. write_nic_dword(priv->net_dev, address, 0);
  886. for (address = IPW_HOST_FW_SHARED_AREA2;
  887. address < IPW_HOST_FW_SHARED_AREA2_END; address += 4)
  888. write_nic_dword(priv->net_dev, address, 0);
  889. for (address = IPW_HOST_FW_SHARED_AREA3;
  890. address < IPW_HOST_FW_SHARED_AREA3_END; address += 4)
  891. write_nic_dword(priv->net_dev, address, 0);
  892. for (address = IPW_HOST_FW_INTERRUPT_AREA;
  893. address < IPW_HOST_FW_INTERRUPT_AREA_END; address += 4)
  894. write_nic_dword(priv->net_dev, address, 0);
  895. return 0;
  896. fail:
  897. ipw2100_release_firmware(priv, &ipw2100_firmware);
  898. return err;
  899. }
  900. static inline void ipw2100_enable_interrupts(struct ipw2100_priv *priv)
  901. {
  902. if (priv->status & STATUS_INT_ENABLED)
  903. return;
  904. priv->status |= STATUS_INT_ENABLED;
  905. write_register(priv->net_dev, IPW_REG_INTA_MASK, IPW_INTERRUPT_MASK);
  906. }
  907. static inline void ipw2100_disable_interrupts(struct ipw2100_priv *priv)
  908. {
  909. if (!(priv->status & STATUS_INT_ENABLED))
  910. return;
  911. priv->status &= ~STATUS_INT_ENABLED;
  912. write_register(priv->net_dev, IPW_REG_INTA_MASK, 0x0);
  913. }
  914. static void ipw2100_initialize_ordinals(struct ipw2100_priv *priv)
  915. {
  916. struct ipw2100_ordinals *ord = &priv->ordinals;
  917. IPW_DEBUG_INFO("enter\n");
  918. read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_1,
  919. &ord->table1_addr);
  920. read_register(priv->net_dev, IPW_MEM_HOST_SHARED_ORDINALS_TABLE_2,
  921. &ord->table2_addr);
  922. read_nic_dword(priv->net_dev, ord->table1_addr, &ord->table1_size);
  923. read_nic_dword(priv->net_dev, ord->table2_addr, &ord->table2_size);
  924. ord->table2_size &= 0x0000FFFF;
  925. IPW_DEBUG_INFO("table 1 size: %d\n", ord->table1_size);
  926. IPW_DEBUG_INFO("table 2 size: %d\n", ord->table2_size);
  927. IPW_DEBUG_INFO("exit\n");
  928. }
  929. static inline void ipw2100_hw_set_gpio(struct ipw2100_priv *priv)
  930. {
  931. u32 reg = 0;
  932. /*
  933. * Set GPIO 3 writable by FW; GPIO 1 writable
  934. * by driver and enable clock
  935. */
  936. reg = (IPW_BIT_GPIO_GPIO3_MASK | IPW_BIT_GPIO_GPIO1_ENABLE |
  937. IPW_BIT_GPIO_LED_OFF);
  938. write_register(priv->net_dev, IPW_REG_GPIO, reg);
  939. }
  940. static inline int rf_kill_active(struct ipw2100_priv *priv)
  941. {
  942. #define MAX_RF_KILL_CHECKS 5
  943. #define RF_KILL_CHECK_DELAY 40
  944. unsigned short value = 0;
  945. u32 reg = 0;
  946. int i;
  947. if (!(priv->hw_features & HW_FEATURE_RFKILL)) {
  948. priv->status &= ~STATUS_RF_KILL_HW;
  949. return 0;
  950. }
  951. for (i = 0; i < MAX_RF_KILL_CHECKS; i++) {
  952. udelay(RF_KILL_CHECK_DELAY);
  953. read_register(priv->net_dev, IPW_REG_GPIO, &reg);
  954. value = (value << 1) | ((reg & IPW_BIT_GPIO_RF_KILL) ? 0 : 1);
  955. }
  956. if (value == 0)
  957. priv->status |= STATUS_RF_KILL_HW;
  958. else
  959. priv->status &= ~STATUS_RF_KILL_HW;
  960. return (value == 0);
  961. }
  962. static int ipw2100_get_hw_features(struct ipw2100_priv *priv)
  963. {
  964. u32 addr, len;
  965. u32 val;
  966. /*
  967. * EEPROM_SRAM_DB_START_ADDRESS using ordinal in ordinal table 1
  968. */
  969. len = sizeof(addr);
  970. if (ipw2100_get_ordinal(
  971. priv, IPW_ORD_EEPROM_SRAM_DB_BLOCK_START_ADDRESS,
  972. &addr, &len)) {
  973. IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
  974. __LINE__);
  975. return -EIO;
  976. }
  977. IPW_DEBUG_INFO("EEPROM address: %08X\n", addr);
  978. /*
  979. * EEPROM version is the byte at offset 0xfd in firmware
  980. * We read 4 bytes, then shift out the byte we actually want */
  981. read_nic_dword(priv->net_dev, addr + 0xFC, &val);
  982. priv->eeprom_version = (val >> 24) & 0xFF;
  983. IPW_DEBUG_INFO("EEPROM version: %d\n", priv->eeprom_version);
  984. /*
  985. * HW RF Kill enable is bit 0 in byte at offset 0x21 in firmware
  986. *
  987. * notice that the EEPROM bit is reverse polarity, i.e.
  988. * bit = 0 signifies HW RF kill switch is supported
  989. * bit = 1 signifies HW RF kill switch is NOT supported
  990. */
  991. read_nic_dword(priv->net_dev, addr + 0x20, &val);
  992. if (!((val >> 24) & 0x01))
  993. priv->hw_features |= HW_FEATURE_RFKILL;
  994. IPW_DEBUG_INFO("HW RF Kill: %ssupported.\n",
  995. (priv->hw_features & HW_FEATURE_RFKILL) ?
  996. "" : "not ");
  997. return 0;
  998. }
  999. /*
  1000. * Start firmware execution after power on and intialization
  1001. * The sequence is:
  1002. * 1. Release ARC
  1003. * 2. Wait for f/w initialization completes;
  1004. */
  1005. static int ipw2100_start_adapter(struct ipw2100_priv *priv)
  1006. {
  1007. int i;
  1008. u32 inta, inta_mask, gpio;
  1009. IPW_DEBUG_INFO("enter\n");
  1010. if (priv->status & STATUS_RUNNING)
  1011. return 0;
  1012. /*
  1013. * Initialize the hw - drive adapter to DO state by setting
  1014. * init_done bit. Wait for clk_ready bit and Download
  1015. * fw & dino ucode
  1016. */
  1017. if (ipw2100_download_firmware(priv)) {
  1018. printk(KERN_ERR DRV_NAME ": %s: Failed to power on the adapter.\n",
  1019. priv->net_dev->name);
  1020. return -EIO;
  1021. }
  1022. /* Clear the Tx, Rx and Msg queues and the r/w indexes
  1023. * in the firmware RBD and TBD ring queue */
  1024. ipw2100_queues_initialize(priv);
  1025. ipw2100_hw_set_gpio(priv);
  1026. /* TODO -- Look at disabling interrupts here to make sure none
  1027. * get fired during FW initialization */
  1028. /* Release ARC - clear reset bit */
  1029. write_register(priv->net_dev, IPW_REG_RESET_REG, 0);
  1030. /* wait for f/w intialization complete */
  1031. IPW_DEBUG_FW("Waiting for f/w initialization to complete...\n");
  1032. i = 5000;
  1033. do {
  1034. set_current_state(TASK_UNINTERRUPTIBLE);
  1035. schedule_timeout(40 * HZ / 1000);
  1036. /* Todo... wait for sync command ... */
  1037. read_register(priv->net_dev, IPW_REG_INTA, &inta);
  1038. /* check "init done" bit */
  1039. if (inta & IPW2100_INTA_FW_INIT_DONE) {
  1040. /* reset "init done" bit */
  1041. write_register(priv->net_dev, IPW_REG_INTA,
  1042. IPW2100_INTA_FW_INIT_DONE);
  1043. break;
  1044. }
  1045. /* check error conditions : we check these after the firmware
  1046. * check so that if there is an error, the interrupt handler
  1047. * will see it and the adapter will be reset */
  1048. if (inta &
  1049. (IPW2100_INTA_FATAL_ERROR | IPW2100_INTA_PARITY_ERROR)) {
  1050. /* clear error conditions */
  1051. write_register(priv->net_dev, IPW_REG_INTA,
  1052. IPW2100_INTA_FATAL_ERROR |
  1053. IPW2100_INTA_PARITY_ERROR);
  1054. }
  1055. } while (i--);
  1056. /* Clear out any pending INTAs since we aren't supposed to have
  1057. * interrupts enabled at this point... */
  1058. read_register(priv->net_dev, IPW_REG_INTA, &inta);
  1059. read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
  1060. inta &= IPW_INTERRUPT_MASK;
  1061. /* Clear out any pending interrupts */
  1062. if (inta & inta_mask)
  1063. write_register(priv->net_dev, IPW_REG_INTA, inta);
  1064. IPW_DEBUG_FW("f/w initialization complete: %s\n",
  1065. i ? "SUCCESS" : "FAILED");
  1066. if (!i) {
  1067. printk(KERN_WARNING DRV_NAME ": %s: Firmware did not initialize.\n",
  1068. priv->net_dev->name);
  1069. return -EIO;
  1070. }
  1071. /* allow firmware to write to GPIO1 & GPIO3 */
  1072. read_register(priv->net_dev, IPW_REG_GPIO, &gpio);
  1073. gpio |= (IPW_BIT_GPIO_GPIO1_MASK | IPW_BIT_GPIO_GPIO3_MASK);
  1074. write_register(priv->net_dev, IPW_REG_GPIO, gpio);
  1075. /* Ready to receive commands */
  1076. priv->status |= STATUS_RUNNING;
  1077. /* The adapter has been reset; we are not associated */
  1078. priv->status &= ~(STATUS_ASSOCIATING | STATUS_ASSOCIATED);
  1079. IPW_DEBUG_INFO("exit\n");
  1080. return 0;
  1081. }
  1082. static inline void ipw2100_reset_fatalerror(struct ipw2100_priv *priv)
  1083. {
  1084. if (!priv->fatal_error)
  1085. return;
  1086. priv->fatal_errors[priv->fatal_index++] = priv->fatal_error;
  1087. priv->fatal_index %= IPW2100_ERROR_QUEUE;
  1088. priv->fatal_error = 0;
  1089. }
  1090. /* NOTE: Our interrupt is disabled when this method is called */
  1091. static int ipw2100_power_cycle_adapter(struct ipw2100_priv *priv)
  1092. {
  1093. u32 reg;
  1094. int i;
  1095. IPW_DEBUG_INFO("Power cycling the hardware.\n");
  1096. ipw2100_hw_set_gpio(priv);
  1097. /* Step 1. Stop Master Assert */
  1098. write_register(priv->net_dev, IPW_REG_RESET_REG,
  1099. IPW_AUX_HOST_RESET_REG_STOP_MASTER);
  1100. /* Step 2. Wait for stop Master Assert
  1101. * (not more then 50us, otherwise ret error */
  1102. i = 5;
  1103. do {
  1104. udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
  1105. read_register(priv->net_dev, IPW_REG_RESET_REG, &reg);
  1106. if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
  1107. break;
  1108. } while(i--);
  1109. priv->status &= ~STATUS_RESET_PENDING;
  1110. if (!i) {
  1111. IPW_DEBUG_INFO("exit - waited too long for master assert stop\n");
  1112. return -EIO;
  1113. }
  1114. write_register(priv->net_dev, IPW_REG_RESET_REG,
  1115. IPW_AUX_HOST_RESET_REG_SW_RESET);
  1116. /* Reset any fatal_error conditions */
  1117. ipw2100_reset_fatalerror(priv);
  1118. /* At this point, the adapter is now stopped and disabled */
  1119. priv->status &= ~(STATUS_RUNNING | STATUS_ASSOCIATING |
  1120. STATUS_ASSOCIATED | STATUS_ENABLED);
  1121. return 0;
  1122. }
  1123. /*
  1124. * Send the CARD_DISABLE_PHY_OFF comamnd to the card to disable it
  1125. *
  1126. * After disabling, if the card was associated, a STATUS_ASSN_LOST will be sent.
  1127. *
  1128. * STATUS_CARD_DISABLE_NOTIFICATION will be sent regardless of
  1129. * if STATUS_ASSN_LOST is sent.
  1130. */
  1131. static int ipw2100_hw_phy_off(struct ipw2100_priv *priv)
  1132. {
  1133. #define HW_PHY_OFF_LOOP_DELAY (HZ / 5000)
  1134. struct host_command cmd = {
  1135. .host_command = CARD_DISABLE_PHY_OFF,
  1136. .host_command_sequence = 0,
  1137. .host_command_length = 0,
  1138. };
  1139. int err, i;
  1140. u32 val1, val2;
  1141. IPW_DEBUG_HC("CARD_DISABLE_PHY_OFF\n");
  1142. /* Turn off the radio */
  1143. err = ipw2100_hw_send_command(priv, &cmd);
  1144. if (err)
  1145. return err;
  1146. for (i = 0; i < 2500; i++) {
  1147. read_nic_dword(priv->net_dev, IPW2100_CONTROL_REG, &val1);
  1148. read_nic_dword(priv->net_dev, IPW2100_COMMAND, &val2);
  1149. if ((val1 & IPW2100_CONTROL_PHY_OFF) &&
  1150. (val2 & IPW2100_COMMAND_PHY_OFF))
  1151. return 0;
  1152. set_current_state(TASK_UNINTERRUPTIBLE);
  1153. schedule_timeout(HW_PHY_OFF_LOOP_DELAY);
  1154. }
  1155. return -EIO;
  1156. }
  1157. static int ipw2100_enable_adapter(struct ipw2100_priv *priv)
  1158. {
  1159. struct host_command cmd = {
  1160. .host_command = HOST_COMPLETE,
  1161. .host_command_sequence = 0,
  1162. .host_command_length = 0
  1163. };
  1164. int err = 0;
  1165. IPW_DEBUG_HC("HOST_COMPLETE\n");
  1166. if (priv->status & STATUS_ENABLED)
  1167. return 0;
  1168. down(&priv->adapter_sem);
  1169. if (rf_kill_active(priv)) {
  1170. IPW_DEBUG_HC("Command aborted due to RF kill active.\n");
  1171. goto fail_up;
  1172. }
  1173. err = ipw2100_hw_send_command(priv, &cmd);
  1174. if (err) {
  1175. IPW_DEBUG_INFO("Failed to send HOST_COMPLETE command\n");
  1176. goto fail_up;
  1177. }
  1178. err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_ENABLED);
  1179. if (err) {
  1180. IPW_DEBUG_INFO(
  1181. "%s: card not responding to init command.\n",
  1182. priv->net_dev->name);
  1183. goto fail_up;
  1184. }
  1185. if (priv->stop_hang_check) {
  1186. priv->stop_hang_check = 0;
  1187. queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
  1188. }
  1189. fail_up:
  1190. up(&priv->adapter_sem);
  1191. return err;
  1192. }
  1193. static int ipw2100_hw_stop_adapter(struct ipw2100_priv *priv)
  1194. {
  1195. #define HW_POWER_DOWN_DELAY (HZ / 10)
  1196. struct host_command cmd = {
  1197. .host_command = HOST_PRE_POWER_DOWN,
  1198. .host_command_sequence = 0,
  1199. .host_command_length = 0,
  1200. };
  1201. int err, i;
  1202. u32 reg;
  1203. if (!(priv->status & STATUS_RUNNING))
  1204. return 0;
  1205. priv->status |= STATUS_STOPPING;
  1206. /* We can only shut down the card if the firmware is operational. So,
  1207. * if we haven't reset since a fatal_error, then we can not send the
  1208. * shutdown commands. */
  1209. if (!priv->fatal_error) {
  1210. /* First, make sure the adapter is enabled so that the PHY_OFF
  1211. * command can shut it down */
  1212. ipw2100_enable_adapter(priv);
  1213. err = ipw2100_hw_phy_off(priv);
  1214. if (err)
  1215. printk(KERN_WARNING DRV_NAME ": Error disabling radio %d\n", err);
  1216. /*
  1217. * If in D0-standby mode going directly to D3 may cause a
  1218. * PCI bus violation. Therefore we must change out of the D0
  1219. * state.
  1220. *
  1221. * Sending the PREPARE_FOR_POWER_DOWN will restrict the
  1222. * hardware from going into standby mode and will transition
  1223. * out of D0-standy if it is already in that state.
  1224. *
  1225. * STATUS_PREPARE_POWER_DOWN_COMPLETE will be sent by the
  1226. * driver upon completion. Once received, the driver can
  1227. * proceed to the D3 state.
  1228. *
  1229. * Prepare for power down command to fw. This command would
  1230. * take HW out of D0-standby and prepare it for D3 state.
  1231. *
  1232. * Currently FW does not support event notification for this
  1233. * event. Therefore, skip waiting for it. Just wait a fixed
  1234. * 100ms
  1235. */
  1236. IPW_DEBUG_HC("HOST_PRE_POWER_DOWN\n");
  1237. err = ipw2100_hw_send_command(priv, &cmd);
  1238. if (err)
  1239. printk(KERN_WARNING DRV_NAME ": "
  1240. "%s: Power down command failed: Error %d\n",
  1241. priv->net_dev->name, err);
  1242. else {
  1243. set_current_state(TASK_UNINTERRUPTIBLE);
  1244. schedule_timeout(HW_POWER_DOWN_DELAY);
  1245. }
  1246. }
  1247. priv->status &= ~STATUS_ENABLED;
  1248. /*
  1249. * Set GPIO 3 writable by FW; GPIO 1 writable
  1250. * by driver and enable clock
  1251. */
  1252. ipw2100_hw_set_gpio(priv);
  1253. /*
  1254. * Power down adapter. Sequence:
  1255. * 1. Stop master assert (RESET_REG[9]=1)
  1256. * 2. Wait for stop master (RESET_REG[8]==1)
  1257. * 3. S/w reset assert (RESET_REG[7] = 1)
  1258. */
  1259. /* Stop master assert */
  1260. write_register(priv->net_dev, IPW_REG_RESET_REG,
  1261. IPW_AUX_HOST_RESET_REG_STOP_MASTER);
  1262. /* wait stop master not more than 50 usec.
  1263. * Otherwise return error. */
  1264. for (i = 5; i > 0; i--) {
  1265. udelay(10);
  1266. /* Check master stop bit */
  1267. read_register(priv->net_dev, IPW_REG_RESET_REG, &reg);
  1268. if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
  1269. break;
  1270. }
  1271. if (i == 0)
  1272. printk(KERN_WARNING DRV_NAME
  1273. ": %s: Could now power down adapter.\n",
  1274. priv->net_dev->name);
  1275. /* assert s/w reset */
  1276. write_register(priv->net_dev, IPW_REG_RESET_REG,
  1277. IPW_AUX_HOST_RESET_REG_SW_RESET);
  1278. priv->status &= ~(STATUS_RUNNING | STATUS_STOPPING);
  1279. return 0;
  1280. }
  1281. static int ipw2100_disable_adapter(struct ipw2100_priv *priv)
  1282. {
  1283. struct host_command cmd = {
  1284. .host_command = CARD_DISABLE,
  1285. .host_command_sequence = 0,
  1286. .host_command_length = 0
  1287. };
  1288. int err = 0;
  1289. IPW_DEBUG_HC("CARD_DISABLE\n");
  1290. if (!(priv->status & STATUS_ENABLED))
  1291. return 0;
  1292. /* Make sure we clear the associated state */
  1293. priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
  1294. if (!priv->stop_hang_check) {
  1295. priv->stop_hang_check = 1;
  1296. cancel_delayed_work(&priv->hang_check);
  1297. }
  1298. down(&priv->adapter_sem);
  1299. err = ipw2100_hw_send_command(priv, &cmd);
  1300. if (err) {
  1301. printk(KERN_WARNING DRV_NAME ": exit - failed to send CARD_DISABLE command\n");
  1302. goto fail_up;
  1303. }
  1304. err = ipw2100_wait_for_card_state(priv, IPW_HW_STATE_DISABLED);
  1305. if (err) {
  1306. printk(KERN_WARNING DRV_NAME ": exit - card failed to change to DISABLED\n");
  1307. goto fail_up;
  1308. }
  1309. IPW_DEBUG_INFO("TODO: implement scan state machine\n");
  1310. fail_up:
  1311. up(&priv->adapter_sem);
  1312. return err;
  1313. }
  1314. static int ipw2100_set_scan_options(struct ipw2100_priv *priv)
  1315. {
  1316. struct host_command cmd = {
  1317. .host_command = SET_SCAN_OPTIONS,
  1318. .host_command_sequence = 0,
  1319. .host_command_length = 8
  1320. };
  1321. int err;
  1322. IPW_DEBUG_INFO("enter\n");
  1323. IPW_DEBUG_SCAN("setting scan options\n");
  1324. cmd.host_command_parameters[0] = 0;
  1325. if (!(priv->config & CFG_ASSOCIATE))
  1326. cmd.host_command_parameters[0] |= IPW_SCAN_NOASSOCIATE;
  1327. if ((priv->sec.flags & SEC_ENABLED) && priv->sec.enabled)
  1328. cmd.host_command_parameters[0] |= IPW_SCAN_MIXED_CELL;
  1329. if (priv->config & CFG_PASSIVE_SCAN)
  1330. cmd.host_command_parameters[0] |= IPW_SCAN_PASSIVE;
  1331. cmd.host_command_parameters[1] = priv->channel_mask;
  1332. err = ipw2100_hw_send_command(priv, &cmd);
  1333. IPW_DEBUG_HC("SET_SCAN_OPTIONS 0x%04X\n",
  1334. cmd.host_command_parameters[0]);
  1335. return err;
  1336. }
  1337. static int ipw2100_start_scan(struct ipw2100_priv *priv)
  1338. {
  1339. struct host_command cmd = {
  1340. .host_command = BROADCAST_SCAN,
  1341. .host_command_sequence = 0,
  1342. .host_command_length = 4
  1343. };
  1344. int err;
  1345. IPW_DEBUG_HC("START_SCAN\n");
  1346. cmd.host_command_parameters[0] = 0;
  1347. /* No scanning if in monitor mode */
  1348. if (priv->ieee->iw_mode == IW_MODE_MONITOR)
  1349. return 1;
  1350. if (priv->status & STATUS_SCANNING) {
  1351. IPW_DEBUG_SCAN("Scan requested while already in scan...\n");
  1352. return 0;
  1353. }
  1354. IPW_DEBUG_INFO("enter\n");
  1355. /* Not clearing here; doing so makes iwlist always return nothing...
  1356. *
  1357. * We should modify the table logic to use aging tables vs. clearing
  1358. * the table on each scan start.
  1359. */
  1360. IPW_DEBUG_SCAN("starting scan\n");
  1361. priv->status |= STATUS_SCANNING;
  1362. err = ipw2100_hw_send_command(priv, &cmd);
  1363. if (err)
  1364. priv->status &= ~STATUS_SCANNING;
  1365. IPW_DEBUG_INFO("exit\n");
  1366. return err;
  1367. }
  1368. static int ipw2100_up(struct ipw2100_priv *priv, int deferred)
  1369. {
  1370. unsigned long flags;
  1371. int rc = 0;
  1372. u32 lock;
  1373. u32 ord_len = sizeof(lock);
  1374. /* Quite if manually disabled. */
  1375. if (priv->status & STATUS_RF_KILL_SW) {
  1376. IPW_DEBUG_INFO("%s: Radio is disabled by Manual Disable "
  1377. "switch\n", priv->net_dev->name);
  1378. return 0;
  1379. }
  1380. /* If the interrupt is enabled, turn it off... */
  1381. spin_lock_irqsave(&priv->low_lock, flags);
  1382. ipw2100_disable_interrupts(priv);
  1383. /* Reset any fatal_error conditions */
  1384. ipw2100_reset_fatalerror(priv);
  1385. spin_unlock_irqrestore(&priv->low_lock, flags);
  1386. if (priv->status & STATUS_POWERED ||
  1387. (priv->status & STATUS_RESET_PENDING)) {
  1388. /* Power cycle the card ... */
  1389. if (ipw2100_power_cycle_adapter(priv)) {
  1390. printk(KERN_WARNING DRV_NAME ": %s: Could not cycle adapter.\n",
  1391. priv->net_dev->name);
  1392. rc = 1;
  1393. goto exit;
  1394. }
  1395. } else
  1396. priv->status |= STATUS_POWERED;
  1397. /* Load the firmware, start the clocks, etc. */
  1398. if (ipw2100_start_adapter(priv)) {
  1399. printk(KERN_ERR DRV_NAME ": %s: Failed to start the firmware.\n",
  1400. priv->net_dev->name);
  1401. rc = 1;
  1402. goto exit;
  1403. }
  1404. ipw2100_initialize_ordinals(priv);
  1405. /* Determine capabilities of this particular HW configuration */
  1406. if (ipw2100_get_hw_features(priv)) {
  1407. printk(KERN_ERR DRV_NAME ": %s: Failed to determine HW features.\n",
  1408. priv->net_dev->name);
  1409. rc = 1;
  1410. goto exit;
  1411. }
  1412. lock = LOCK_NONE;
  1413. if (ipw2100_set_ordinal(priv, IPW_ORD_PERS_DB_LOCK, &lock, &ord_len)) {
  1414. printk(KERN_ERR DRV_NAME ": %s: Failed to clear ordinal lock.\n",
  1415. priv->net_dev->name);
  1416. rc = 1;
  1417. goto exit;
  1418. }
  1419. priv->status &= ~STATUS_SCANNING;
  1420. if (rf_kill_active(priv)) {
  1421. printk(KERN_INFO "%s: Radio is disabled by RF switch.\n",
  1422. priv->net_dev->name);
  1423. if (priv->stop_rf_kill) {
  1424. priv->stop_rf_kill = 0;
  1425. queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
  1426. }
  1427. deferred = 1;
  1428. }
  1429. /* Turn on the interrupt so that commands can be processed */
  1430. ipw2100_enable_interrupts(priv);
  1431. /* Send all of the commands that must be sent prior to
  1432. * HOST_COMPLETE */
  1433. if (ipw2100_adapter_setup(priv)) {
  1434. printk(KERN_ERR DRV_NAME ": %s: Failed to start the card.\n",
  1435. priv->net_dev->name);
  1436. rc = 1;
  1437. goto exit;
  1438. }
  1439. if (!deferred) {
  1440. /* Enable the adapter - sends HOST_COMPLETE */
  1441. if (ipw2100_enable_adapter(priv)) {
  1442. printk(KERN_ERR DRV_NAME ": "
  1443. "%s: failed in call to enable adapter.\n",
  1444. priv->net_dev->name);
  1445. ipw2100_hw_stop_adapter(priv);
  1446. rc = 1;
  1447. goto exit;
  1448. }
  1449. /* Start a scan . . . */
  1450. ipw2100_set_scan_options(priv);
  1451. ipw2100_start_scan(priv);
  1452. }
  1453. exit:
  1454. return rc;
  1455. }
  1456. /* Called by register_netdev() */
  1457. static int ipw2100_net_init(struct net_device *dev)
  1458. {
  1459. struct ipw2100_priv *priv = ieee80211_priv(dev);
  1460. return ipw2100_up(priv, 1);
  1461. }
  1462. static void ipw2100_down(struct ipw2100_priv *priv)
  1463. {
  1464. unsigned long flags;
  1465. union iwreq_data wrqu = {
  1466. .ap_addr = {
  1467. .sa_family = ARPHRD_ETHER
  1468. }
  1469. };
  1470. int associated = priv->status & STATUS_ASSOCIATED;
  1471. /* Kill the RF switch timer */
  1472. if (!priv->stop_rf_kill) {
  1473. priv->stop_rf_kill = 1;
  1474. cancel_delayed_work(&priv->rf_kill);
  1475. }
  1476. /* Kill the firmare hang check timer */
  1477. if (!priv->stop_hang_check) {
  1478. priv->stop_hang_check = 1;
  1479. cancel_delayed_work(&priv->hang_check);
  1480. }
  1481. /* Kill any pending resets */
  1482. if (priv->status & STATUS_RESET_PENDING)
  1483. cancel_delayed_work(&priv->reset_work);
  1484. /* Make sure the interrupt is on so that FW commands will be
  1485. * processed correctly */
  1486. spin_lock_irqsave(&priv->low_lock, flags);
  1487. ipw2100_enable_interrupts(priv);
  1488. spin_unlock_irqrestore(&priv->low_lock, flags);
  1489. if (ipw2100_hw_stop_adapter(priv))
  1490. printk(KERN_ERR DRV_NAME ": %s: Error stopping adapter.\n",
  1491. priv->net_dev->name);
  1492. /* Do not disable the interrupt until _after_ we disable
  1493. * the adaptor. Otherwise the CARD_DISABLE command will never
  1494. * be ack'd by the firmware */
  1495. spin_lock_irqsave(&priv->low_lock, flags);
  1496. ipw2100_disable_interrupts(priv);
  1497. spin_unlock_irqrestore(&priv->low_lock, flags);
  1498. #ifdef ACPI_CSTATE_LIMIT_DEFINED
  1499. if (priv->config & CFG_C3_DISABLED) {
  1500. IPW_DEBUG_INFO(DRV_NAME ": Resetting C3 transitions.\n");
  1501. acpi_set_cstate_limit(priv->cstate_limit);
  1502. priv->config &= ~CFG_C3_DISABLED;
  1503. }
  1504. #endif
  1505. /* We have to signal any supplicant if we are disassociating */
  1506. if (associated)
  1507. wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
  1508. priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
  1509. netif_carrier_off(priv->net_dev);
  1510. netif_stop_queue(priv->net_dev);
  1511. }
  1512. static void ipw2100_reset_adapter(struct ipw2100_priv *priv)
  1513. {
  1514. unsigned long flags;
  1515. union iwreq_data wrqu = {
  1516. .ap_addr = {
  1517. .sa_family = ARPHRD_ETHER
  1518. }
  1519. };
  1520. int associated = priv->status & STATUS_ASSOCIATED;
  1521. spin_lock_irqsave(&priv->low_lock, flags);
  1522. IPW_DEBUG_INFO(DRV_NAME ": %s: Restarting adapter.\n",
  1523. priv->net_dev->name);
  1524. priv->resets++;
  1525. priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
  1526. priv->status |= STATUS_SECURITY_UPDATED;
  1527. /* Force a power cycle even if interface hasn't been opened
  1528. * yet */
  1529. cancel_delayed_work(&priv->reset_work);
  1530. priv->status |= STATUS_RESET_PENDING;
  1531. spin_unlock_irqrestore(&priv->low_lock, flags);
  1532. down(&priv->action_sem);
  1533. /* stop timed checks so that they don't interfere with reset */
  1534. priv->stop_hang_check = 1;
  1535. cancel_delayed_work(&priv->hang_check);
  1536. /* We have to signal any supplicant if we are disassociating */
  1537. if (associated)
  1538. wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
  1539. ipw2100_up(priv, 0);
  1540. up(&priv->action_sem);
  1541. }
  1542. static void isr_indicate_associated(struct ipw2100_priv *priv, u32 status)
  1543. {
  1544. #define MAC_ASSOCIATION_READ_DELAY (HZ)
  1545. int ret, len, essid_len;
  1546. char essid[IW_ESSID_MAX_SIZE];
  1547. u32 txrate;
  1548. u32 chan;
  1549. char *txratename;
  1550. u8 bssid[ETH_ALEN];
  1551. /*
  1552. * TBD: BSSID is usually 00:00:00:00:00:00 here and not
  1553. * an actual MAC of the AP. Seems like FW sets this
  1554. * address too late. Read it later and expose through
  1555. * /proc or schedule a later task to query and update
  1556. */
  1557. essid_len = IW_ESSID_MAX_SIZE;
  1558. ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID,
  1559. essid, &essid_len);
  1560. if (ret) {
  1561. IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
  1562. __LINE__);
  1563. return;
  1564. }
  1565. len = sizeof(u32);
  1566. ret = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE,
  1567. &txrate, &len);
  1568. if (ret) {
  1569. IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
  1570. __LINE__);
  1571. return;
  1572. }
  1573. len = sizeof(u32);
  1574. ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &len);
  1575. if (ret) {
  1576. IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
  1577. __LINE__);
  1578. return;
  1579. }
  1580. len = ETH_ALEN;
  1581. ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID, &bssid, &len);
  1582. if (ret) {
  1583. IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
  1584. __LINE__);
  1585. return;
  1586. }
  1587. memcpy(priv->ieee->bssid, bssid, ETH_ALEN);
  1588. switch (txrate) {
  1589. case TX_RATE_1_MBIT:
  1590. txratename = "1Mbps";
  1591. break;
  1592. case TX_RATE_2_MBIT:
  1593. txratename = "2Mbsp";
  1594. break;
  1595. case TX_RATE_5_5_MBIT:
  1596. txratename = "5.5Mbps";
  1597. break;
  1598. case TX_RATE_11_MBIT:
  1599. txratename = "11Mbps";
  1600. break;
  1601. default:
  1602. IPW_DEBUG_INFO("Unknown rate: %d\n", txrate);
  1603. txratename = "unknown rate";
  1604. break;
  1605. }
  1606. IPW_DEBUG_INFO("%s: Associated with '%s' at %s, channel %d (BSSID="
  1607. MAC_FMT ")\n",
  1608. priv->net_dev->name, escape_essid(essid, essid_len),
  1609. txratename, chan, MAC_ARG(bssid));
  1610. /* now we copy read ssid into dev */
  1611. if (!(priv->config & CFG_STATIC_ESSID)) {
  1612. priv->essid_len = min((u8)essid_len, (u8)IW_ESSID_MAX_SIZE);
  1613. memcpy(priv->essid, essid, priv->essid_len);
  1614. }
  1615. priv->channel = chan;
  1616. memcpy(priv->bssid, bssid, ETH_ALEN);
  1617. priv->status |= STATUS_ASSOCIATING;
  1618. priv->connect_start = get_seconds();
  1619. queue_delayed_work(priv->workqueue, &priv->wx_event_work, HZ / 10);
  1620. }
  1621. static int ipw2100_set_essid(struct ipw2100_priv *priv, char *essid,
  1622. int length, int batch_mode)
  1623. {
  1624. int ssid_len = min(length, IW_ESSID_MAX_SIZE);
  1625. struct host_command cmd = {
  1626. .host_command = SSID,
  1627. .host_command_sequence = 0,
  1628. .host_command_length = ssid_len
  1629. };
  1630. int err;
  1631. IPW_DEBUG_HC("SSID: '%s'\n", escape_essid(essid, ssid_len));
  1632. if (ssid_len)
  1633. memcpy((char*)cmd.host_command_parameters,
  1634. essid, ssid_len);
  1635. if (!batch_mode) {
  1636. err = ipw2100_disable_adapter(priv);
  1637. if (err)
  1638. return err;
  1639. }
  1640. /* Bug in FW currently doesn't honor bit 0 in SET_SCAN_OPTIONS to
  1641. * disable auto association -- so we cheat by setting a bogus SSID */
  1642. if (!ssid_len && !(priv->config & CFG_ASSOCIATE)) {
  1643. int i;
  1644. u8 *bogus = (u8*)cmd.host_command_parameters;
  1645. for (i = 0; i < IW_ESSID_MAX_SIZE; i++)
  1646. bogus[i] = 0x18 + i;
  1647. cmd.host_command_length = IW_ESSID_MAX_SIZE;
  1648. }
  1649. /* NOTE: We always send the SSID command even if the provided ESSID is
  1650. * the same as what we currently think is set. */
  1651. err = ipw2100_hw_send_command(priv, &cmd);
  1652. if (!err) {
  1653. memset(priv->essid + ssid_len, 0,
  1654. IW_ESSID_MAX_SIZE - ssid_len);
  1655. memcpy(priv->essid, essid, ssid_len);
  1656. priv->essid_len = ssid_len;
  1657. }
  1658. if (!batch_mode) {
  1659. if (ipw2100_enable_adapter(priv))
  1660. err = -EIO;
  1661. }
  1662. return err;
  1663. }
  1664. static void isr_indicate_association_lost(struct ipw2100_priv *priv, u32 status)
  1665. {
  1666. IPW_DEBUG(IPW_DL_NOTIF | IPW_DL_STATE | IPW_DL_ASSOC,
  1667. "disassociated: '%s' " MAC_FMT " \n",
  1668. escape_essid(priv->essid, priv->essid_len),
  1669. MAC_ARG(priv->bssid));
  1670. priv->status &= ~(STATUS_ASSOCIATED | STATUS_ASSOCIATING);
  1671. if (priv->status & STATUS_STOPPING) {
  1672. IPW_DEBUG_INFO("Card is stopping itself, discard ASSN_LOST.\n");
  1673. return;
  1674. }
  1675. memset(priv->bssid, 0, ETH_ALEN);
  1676. memset(priv->ieee->bssid, 0, ETH_ALEN);
  1677. netif_carrier_off(priv->net_dev);
  1678. netif_stop_queue(priv->net_dev);
  1679. if (!(priv->status & STATUS_RUNNING))
  1680. return;
  1681. if (priv->status & STATUS_SECURITY_UPDATED)
  1682. queue_work(priv->workqueue, &priv->security_work);
  1683. queue_work(priv->workqueue, &priv->wx_event_work);
  1684. }
  1685. static void isr_indicate_rf_kill(struct ipw2100_priv *priv, u32 status)
  1686. {
  1687. IPW_DEBUG_INFO("%s: RF Kill state changed to radio OFF.\n",
  1688. priv->net_dev->name);
  1689. /* RF_KILL is now enabled (else we wouldn't be here) */
  1690. priv->status |= STATUS_RF_KILL_HW;
  1691. #ifdef ACPI_CSTATE_LIMIT_DEFINED
  1692. if (priv->config & CFG_C3_DISABLED) {
  1693. IPW_DEBUG_INFO(DRV_NAME ": Resetting C3 transitions.\n");
  1694. acpi_set_cstate_limit(priv->cstate_limit);
  1695. priv->config &= ~CFG_C3_DISABLED;
  1696. }
  1697. #endif
  1698. /* Make sure the RF Kill check timer is running */
  1699. priv->stop_rf_kill = 0;
  1700. cancel_delayed_work(&priv->rf_kill);
  1701. queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
  1702. }
  1703. static void isr_scan_complete(struct ipw2100_priv *priv, u32 status)
  1704. {
  1705. IPW_DEBUG_SCAN("scan complete\n");
  1706. /* Age the scan results... */
  1707. priv->ieee->scans++;
  1708. priv->status &= ~STATUS_SCANNING;
  1709. }
  1710. #ifdef CONFIG_IPW_DEBUG
  1711. #define IPW2100_HANDLER(v, f) { v, f, # v }
  1712. struct ipw2100_status_indicator {
  1713. int status;
  1714. void (*cb)(struct ipw2100_priv *priv, u32 status);
  1715. char *name;
  1716. };
  1717. #else
  1718. #define IPW2100_HANDLER(v, f) { v, f }
  1719. struct ipw2100_status_indicator {
  1720. int status;
  1721. void (*cb)(struct ipw2100_priv *priv, u32 status);
  1722. };
  1723. #endif /* CONFIG_IPW_DEBUG */
  1724. static void isr_indicate_scanning(struct ipw2100_priv *priv, u32 status)
  1725. {
  1726. IPW_DEBUG_SCAN("Scanning...\n");
  1727. priv->status |= STATUS_SCANNING;
  1728. }
  1729. static const struct ipw2100_status_indicator status_handlers[] = {
  1730. IPW2100_HANDLER(IPW_STATE_INITIALIZED, NULL),
  1731. IPW2100_HANDLER(IPW_STATE_COUNTRY_FOUND, NULL),
  1732. IPW2100_HANDLER(IPW_STATE_ASSOCIATED, isr_indicate_associated),
  1733. IPW2100_HANDLER(IPW_STATE_ASSN_LOST, isr_indicate_association_lost),
  1734. IPW2100_HANDLER(IPW_STATE_ASSN_CHANGED, NULL),
  1735. IPW2100_HANDLER(IPW_STATE_SCAN_COMPLETE, isr_scan_complete),
  1736. IPW2100_HANDLER(IPW_STATE_ENTERED_PSP, NULL),
  1737. IPW2100_HANDLER(IPW_STATE_LEFT_PSP, NULL),
  1738. IPW2100_HANDLER(IPW_STATE_RF_KILL, isr_indicate_rf_kill),
  1739. IPW2100_HANDLER(IPW_STATE_DISABLED, NULL),
  1740. IPW2100_HANDLER(IPW_STATE_POWER_DOWN, NULL),
  1741. IPW2100_HANDLER(IPW_STATE_SCANNING, isr_indicate_scanning),
  1742. IPW2100_HANDLER(-1, NULL)
  1743. };
  1744. static void isr_status_change(struct ipw2100_priv *priv, int status)
  1745. {
  1746. int i;
  1747. if (status == IPW_STATE_SCANNING &&
  1748. priv->status & STATUS_ASSOCIATED &&
  1749. !(priv->status & STATUS_SCANNING)) {
  1750. IPW_DEBUG_INFO("Scan detected while associated, with "
  1751. "no scan request. Restarting firmware.\n");
  1752. /* Wake up any sleeping jobs */
  1753. schedule_reset(priv);
  1754. }
  1755. for (i = 0; status_handlers[i].status != -1; i++) {
  1756. if (status == status_handlers[i].status) {
  1757. IPW_DEBUG_NOTIF("Status change: %s\n",
  1758. status_handlers[i].name);
  1759. if (status_handlers[i].cb)
  1760. status_handlers[i].cb(priv, status);
  1761. priv->wstats.status = status;
  1762. return;
  1763. }
  1764. }
  1765. IPW_DEBUG_NOTIF("unknown status received: %04x\n", status);
  1766. }
  1767. static void isr_rx_complete_command(
  1768. struct ipw2100_priv *priv,
  1769. struct ipw2100_cmd_header *cmd)
  1770. {
  1771. #ifdef CONFIG_IPW_DEBUG
  1772. if (cmd->host_command_reg < ARRAY_SIZE(command_types)) {
  1773. IPW_DEBUG_HC("Command completed '%s (%d)'\n",
  1774. command_types[cmd->host_command_reg],
  1775. cmd->host_command_reg);
  1776. }
  1777. #endif
  1778. if (cmd->host_command_reg == HOST_COMPLETE)
  1779. priv->status |= STATUS_ENABLED;
  1780. if (cmd->host_command_reg == CARD_DISABLE)
  1781. priv->status &= ~STATUS_ENABLED;
  1782. priv->status &= ~STATUS_CMD_ACTIVE;
  1783. wake_up_interruptible(&priv->wait_command_queue);
  1784. }
  1785. #ifdef CONFIG_IPW_DEBUG
  1786. static const char *frame_types[] = {
  1787. "COMMAND_STATUS_VAL",
  1788. "STATUS_CHANGE_VAL",
  1789. "P80211_DATA_VAL",
  1790. "P8023_DATA_VAL",
  1791. "HOST_NOTIFICATION_VAL"
  1792. };
  1793. #endif
  1794. static inline int ipw2100_alloc_skb(
  1795. struct ipw2100_priv *priv,
  1796. struct ipw2100_rx_packet *packet)
  1797. {
  1798. packet->skb = dev_alloc_skb(sizeof(struct ipw2100_rx));
  1799. if (!packet->skb)
  1800. return -ENOMEM;
  1801. packet->rxp = (struct ipw2100_rx *)packet->skb->data;
  1802. packet->dma_addr = pci_map_single(priv->pci_dev, packet->skb->data,
  1803. sizeof(struct ipw2100_rx),
  1804. PCI_DMA_FROMDEVICE);
  1805. /* NOTE: pci_map_single does not return an error code, and 0 is a valid
  1806. * dma_addr */
  1807. return 0;
  1808. }
  1809. #define SEARCH_ERROR 0xffffffff
  1810. #define SEARCH_FAIL 0xfffffffe
  1811. #define SEARCH_SUCCESS 0xfffffff0
  1812. #define SEARCH_DISCARD 0
  1813. #define SEARCH_SNAPSHOT 1
  1814. #define SNAPSHOT_ADDR(ofs) (priv->snapshot[((ofs) >> 12) & 0xff] + ((ofs) & 0xfff))
  1815. static inline int ipw2100_snapshot_alloc(struct ipw2100_priv *priv)
  1816. {
  1817. int i;
  1818. if (priv->snapshot[0])
  1819. return 1;
  1820. for (i = 0; i < 0x30; i++) {
  1821. priv->snapshot[i] = (u8*)kmalloc(0x1000, GFP_ATOMIC);
  1822. if (!priv->snapshot[i]) {
  1823. IPW_DEBUG_INFO("%s: Error allocating snapshot "
  1824. "buffer %d\n", priv->net_dev->name, i);
  1825. while (i > 0)
  1826. kfree(priv->snapshot[--i]);
  1827. priv->snapshot[0] = NULL;
  1828. return 0;
  1829. }
  1830. }
  1831. return 1;
  1832. }
  1833. static inline void ipw2100_snapshot_free(struct ipw2100_priv *priv)
  1834. {
  1835. int i;
  1836. if (!priv->snapshot[0])
  1837. return;
  1838. for (i = 0; i < 0x30; i++)
  1839. kfree(priv->snapshot[i]);
  1840. priv->snapshot[0] = NULL;
  1841. }
  1842. static inline u32 ipw2100_match_buf(struct ipw2100_priv *priv, u8 *in_buf,
  1843. size_t len, int mode)
  1844. {
  1845. u32 i, j;
  1846. u32 tmp;
  1847. u8 *s, *d;
  1848. u32 ret;
  1849. s = in_buf;
  1850. if (mode == SEARCH_SNAPSHOT) {
  1851. if (!ipw2100_snapshot_alloc(priv))
  1852. mode = SEARCH_DISCARD;
  1853. }
  1854. for (ret = SEARCH_FAIL, i = 0; i < 0x30000; i += 4) {
  1855. read_nic_dword(priv->net_dev, i, &tmp);
  1856. if (mode == SEARCH_SNAPSHOT)
  1857. *(u32 *)SNAPSHOT_ADDR(i) = tmp;
  1858. if (ret == SEARCH_FAIL) {
  1859. d = (u8*)&tmp;
  1860. for (j = 0; j < 4; j++) {
  1861. if (*s != *d) {
  1862. s = in_buf;
  1863. continue;
  1864. }
  1865. s++;
  1866. d++;
  1867. if ((s - in_buf) == len)
  1868. ret = (i + j) - len + 1;
  1869. }
  1870. } else if (mode == SEARCH_DISCARD)
  1871. return ret;
  1872. }
  1873. return ret;
  1874. }
  1875. /*
  1876. *
  1877. * 0) Disconnect the SKB from the firmware (just unmap)
  1878. * 1) Pack the ETH header into the SKB
  1879. * 2) Pass the SKB to the network stack
  1880. *
  1881. * When packet is provided by the firmware, it contains the following:
  1882. *
  1883. * . ieee80211_hdr
  1884. * . ieee80211_snap_hdr
  1885. *
  1886. * The size of the constructed ethernet
  1887. *
  1888. */
  1889. #ifdef CONFIG_IPW2100_RX_DEBUG
  1890. static u8 packet_data[IPW_RX_NIC_BUFFER_LENGTH];
  1891. #endif
  1892. static inline void ipw2100_corruption_detected(struct ipw2100_priv *priv,
  1893. int i)
  1894. {
  1895. #ifdef CONFIG_IPW_DEBUG_C3
  1896. struct ipw2100_status *status = &priv->status_queue.drv[i];
  1897. u32 match, reg;
  1898. int j;
  1899. #endif
  1900. #ifdef ACPI_CSTATE_LIMIT_DEFINED
  1901. int limit;
  1902. #endif
  1903. IPW_DEBUG_INFO(DRV_NAME ": PCI latency error detected at "
  1904. "0x%04zX.\n", i * sizeof(struct ipw2100_status));
  1905. #ifdef ACPI_CSTATE_LIMIT_DEFINED
  1906. IPW_DEBUG_INFO(DRV_NAME ": Disabling C3 transitions.\n");
  1907. limit = acpi_get_cstate_limit();
  1908. if (limit > 2) {
  1909. priv->cstate_limit = limit;
  1910. acpi_set_cstate_limit(2);
  1911. priv->config |= CFG_C3_DISABLED;
  1912. }
  1913. #endif
  1914. #ifdef CONFIG_IPW_DEBUG_C3
  1915. /* Halt the fimrware so we can get a good image */
  1916. write_register(priv->net_dev, IPW_REG_RESET_REG,
  1917. IPW_AUX_HOST_RESET_REG_STOP_MASTER);
  1918. j = 5;
  1919. do {
  1920. udelay(IPW_WAIT_RESET_MASTER_ASSERT_COMPLETE_DELAY);
  1921. read_register(priv->net_dev, IPW_REG_RESET_REG, &reg);
  1922. if (reg & IPW_AUX_HOST_RESET_REG_MASTER_DISABLED)
  1923. break;
  1924. } while (j--);
  1925. match = ipw2100_match_buf(priv, (u8*)status,
  1926. sizeof(struct ipw2100_status),
  1927. SEARCH_SNAPSHOT);
  1928. if (match < SEARCH_SUCCESS)
  1929. IPW_DEBUG_INFO("%s: DMA status match in Firmware at "
  1930. "offset 0x%06X, length %d:\n",
  1931. priv->net_dev->name, match,
  1932. sizeof(struct ipw2100_status));
  1933. else
  1934. IPW_DEBUG_INFO("%s: No DMA status match in "
  1935. "Firmware.\n", priv->net_dev->name);
  1936. printk_buf((u8*)priv->status_queue.drv,
  1937. sizeof(struct ipw2100_status) * RX_QUEUE_LENGTH);
  1938. #endif
  1939. priv->fatal_error = IPW2100_ERR_C3_CORRUPTION;
  1940. priv->ieee->stats.rx_errors++;
  1941. schedule_reset(priv);
  1942. }
  1943. static inline void isr_rx(struct ipw2100_priv *priv, int i,
  1944. struct ieee80211_rx_stats *stats)
  1945. {
  1946. struct ipw2100_status *status = &priv->status_queue.drv[i];
  1947. struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
  1948. IPW_DEBUG_RX("Handler...\n");
  1949. if (unlikely(status->frame_size > skb_tailroom(packet->skb))) {
  1950. IPW_DEBUG_INFO("%s: frame_size (%u) > skb_tailroom (%u)!"
  1951. " Dropping.\n",
  1952. priv->net_dev->name,
  1953. status->frame_size, skb_tailroom(packet->skb));
  1954. priv->ieee->stats.rx_errors++;
  1955. return;
  1956. }
  1957. if (unlikely(!netif_running(priv->net_dev))) {
  1958. priv->ieee->stats.rx_errors++;
  1959. priv->wstats.discard.misc++;
  1960. IPW_DEBUG_DROP("Dropping packet while interface is not up.\n");
  1961. return;
  1962. }
  1963. if (unlikely(priv->ieee->iw_mode == IW_MODE_MONITOR &&
  1964. status->flags & IPW_STATUS_FLAG_CRC_ERROR)) {
  1965. IPW_DEBUG_RX("CRC error in packet. Dropping.\n");
  1966. priv->ieee->stats.rx_errors++;
  1967. return;
  1968. }
  1969. if (unlikely(priv->ieee->iw_mode != IW_MODE_MONITOR &&
  1970. !(priv->status & STATUS_ASSOCIATED))) {
  1971. IPW_DEBUG_DROP("Dropping packet while not associated.\n");
  1972. priv->wstats.discard.misc++;
  1973. return;
  1974. }
  1975. pci_unmap_single(priv->pci_dev,
  1976. packet->dma_addr,
  1977. sizeof(struct ipw2100_rx),
  1978. PCI_DMA_FROMDEVICE);
  1979. skb_put(packet->skb, status->frame_size);
  1980. #ifdef CONFIG_IPW2100_RX_DEBUG
  1981. /* Make a copy of the frame so we can dump it to the logs if
  1982. * ieee80211_rx fails */
  1983. memcpy(packet_data, packet->skb->data,
  1984. min_t(u32, status->frame_size, IPW_RX_NIC_BUFFER_LENGTH));
  1985. #endif
  1986. if (!ieee80211_rx(priv->ieee, packet->skb, stats)) {
  1987. #ifdef CONFIG_IPW2100_RX_DEBUG
  1988. IPW_DEBUG_DROP("%s: Non consumed packet:\n",
  1989. priv->net_dev->name);
  1990. printk_buf(IPW_DL_DROP, packet_data, status->frame_size);
  1991. #endif
  1992. priv->ieee->stats.rx_errors++;
  1993. /* ieee80211_rx failed, so it didn't free the SKB */
  1994. dev_kfree_skb_any(packet->skb);
  1995. packet->skb = NULL;
  1996. }
  1997. /* We need to allocate a new SKB and attach it to the RDB. */
  1998. if (unlikely(ipw2100_alloc_skb(priv, packet))) {
  1999. printk(KERN_WARNING DRV_NAME ": "
  2000. "%s: Unable to allocate SKB onto RBD ring - disabling "
  2001. "adapter.\n", priv->net_dev->name);
  2002. /* TODO: schedule adapter shutdown */
  2003. IPW_DEBUG_INFO("TODO: Shutdown adapter...\n");
  2004. }
  2005. /* Update the RDB entry */
  2006. priv->rx_queue.drv[i].host_addr = packet->dma_addr;
  2007. }
  2008. static inline int ipw2100_corruption_check(struct ipw2100_priv *priv, int i)
  2009. {
  2010. struct ipw2100_status *status = &priv->status_queue.drv[i];
  2011. struct ipw2100_rx *u = priv->rx_buffers[i].rxp;
  2012. u16 frame_type = status->status_fields & STATUS_TYPE_MASK;
  2013. switch (frame_type) {
  2014. case COMMAND_STATUS_VAL:
  2015. return (status->frame_size != sizeof(u->rx_data.command));
  2016. case STATUS_CHANGE_VAL:
  2017. return (status->frame_size != sizeof(u->rx_data.status));
  2018. case HOST_NOTIFICATION_VAL:
  2019. return (status->frame_size < sizeof(u->rx_data.notification));
  2020. case P80211_DATA_VAL:
  2021. case P8023_DATA_VAL:
  2022. #ifdef CONFIG_IPW2100_MONITOR
  2023. return 0;
  2024. #else
  2025. switch (WLAN_FC_GET_TYPE(u->rx_data.header.frame_ctl)) {
  2026. case IEEE80211_FTYPE_MGMT:
  2027. case IEEE80211_FTYPE_CTL:
  2028. return 0;
  2029. case IEEE80211_FTYPE_DATA:
  2030. return (status->frame_size >
  2031. IPW_MAX_802_11_PAYLOAD_LENGTH);
  2032. }
  2033. #endif
  2034. }
  2035. return 1;
  2036. }
  2037. /*
  2038. * ipw2100 interrupts are disabled at this point, and the ISR
  2039. * is the only code that calls this method. So, we do not need
  2040. * to play with any locks.
  2041. *
  2042. * RX Queue works as follows:
  2043. *
  2044. * Read index - firmware places packet in entry identified by the
  2045. * Read index and advances Read index. In this manner,
  2046. * Read index will always point to the next packet to
  2047. * be filled--but not yet valid.
  2048. *
  2049. * Write index - driver fills this entry with an unused RBD entry.
  2050. * This entry has not filled by the firmware yet.
  2051. *
  2052. * In between the W and R indexes are the RBDs that have been received
  2053. * but not yet processed.
  2054. *
  2055. * The process of handling packets will start at WRITE + 1 and advance
  2056. * until it reaches the READ index.
  2057. *
  2058. * The WRITE index is cached in the variable 'priv->rx_queue.next'.
  2059. *
  2060. */
  2061. static inline void __ipw2100_rx_process(struct ipw2100_priv *priv)
  2062. {
  2063. struct ipw2100_bd_queue *rxq = &priv->rx_queue;
  2064. struct ipw2100_status_queue *sq = &priv->status_queue;
  2065. struct ipw2100_rx_packet *packet;
  2066. u16 frame_type;
  2067. u32 r, w, i, s;
  2068. struct ipw2100_rx *u;
  2069. struct ieee80211_rx_stats stats = {
  2070. .mac_time = jiffies,
  2071. };
  2072. read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_READ_INDEX, &r);
  2073. read_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_WRITE_INDEX, &w);
  2074. if (r >= rxq->entries) {
  2075. IPW_DEBUG_RX("exit - bad read index\n");
  2076. return;
  2077. }
  2078. i = (rxq->next + 1) % rxq->entries;
  2079. s = i;
  2080. while (i != r) {
  2081. /* IPW_DEBUG_RX("r = %d : w = %d : processing = %d\n",
  2082. r, rxq->next, i); */
  2083. packet = &priv->rx_buffers[i];
  2084. /* Sync the DMA for the STATUS buffer so CPU is sure to get
  2085. * the correct values */
  2086. pci_dma_sync_single_for_cpu(
  2087. priv->pci_dev,
  2088. sq->nic + sizeof(struct ipw2100_status) * i,
  2089. sizeof(struct ipw2100_status),
  2090. PCI_DMA_FROMDEVICE);
  2091. /* Sync the DMA for the RX buffer so CPU is sure to get
  2092. * the correct values */
  2093. pci_dma_sync_single_for_cpu(priv->pci_dev, packet->dma_addr,
  2094. sizeof(struct ipw2100_rx),
  2095. PCI_DMA_FROMDEVICE);
  2096. if (unlikely(ipw2100_corruption_check(priv, i))) {
  2097. ipw2100_corruption_detected(priv, i);
  2098. goto increment;
  2099. }
  2100. u = packet->rxp;
  2101. frame_type = sq->drv[i].status_fields &
  2102. STATUS_TYPE_MASK;
  2103. stats.rssi = sq->drv[i].rssi + IPW2100_RSSI_TO_DBM;
  2104. stats.len = sq->drv[i].frame_size;
  2105. stats.mask = 0;
  2106. if (stats.rssi != 0)
  2107. stats.mask |= IEEE80211_STATMASK_RSSI;
  2108. stats.freq = IEEE80211_24GHZ_BAND;
  2109. IPW_DEBUG_RX(
  2110. "%s: '%s' frame type received (%d).\n",
  2111. priv->net_dev->name, frame_types[frame_type],
  2112. stats.len);
  2113. switch (frame_type) {
  2114. case COMMAND_STATUS_VAL:
  2115. /* Reset Rx watchdog */
  2116. isr_rx_complete_command(
  2117. priv, &u->rx_data.command);
  2118. break;
  2119. case STATUS_CHANGE_VAL:
  2120. isr_status_change(priv, u->rx_data.status);
  2121. break;
  2122. case P80211_DATA_VAL:
  2123. case P8023_DATA_VAL:
  2124. #ifdef CONFIG_IPW2100_MONITOR
  2125. if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
  2126. isr_rx(priv, i, &stats);
  2127. break;
  2128. }
  2129. #endif
  2130. if (stats.len < sizeof(u->rx_data.header))
  2131. break;
  2132. switch (WLAN_FC_GET_TYPE(u->rx_data.header.
  2133. frame_ctl)) {
  2134. case IEEE80211_FTYPE_MGMT:
  2135. ieee80211_rx_mgt(priv->ieee,
  2136. &u->rx_data.header,
  2137. &stats);
  2138. break;
  2139. case IEEE80211_FTYPE_CTL:
  2140. break;
  2141. case IEEE80211_FTYPE_DATA:
  2142. isr_rx(priv, i, &stats);
  2143. break;
  2144. }
  2145. break;
  2146. }
  2147. increment:
  2148. /* clear status field associated with this RBD */
  2149. rxq->drv[i].status.info.field = 0;
  2150. i = (i + 1) % rxq->entries;
  2151. }
  2152. if (i != s) {
  2153. /* backtrack one entry, wrapping to end if at 0 */
  2154. rxq->next = (i ? i : rxq->entries) - 1;
  2155. write_register(priv->net_dev,
  2156. IPW_MEM_HOST_SHARED_RX_WRITE_INDEX,
  2157. rxq->next);
  2158. }
  2159. }
  2160. /*
  2161. * __ipw2100_tx_process
  2162. *
  2163. * This routine will determine whether the next packet on
  2164. * the fw_pend_list has been processed by the firmware yet.
  2165. *
  2166. * If not, then it does nothing and returns.
  2167. *
  2168. * If so, then it removes the item from the fw_pend_list, frees
  2169. * any associated storage, and places the item back on the
  2170. * free list of its source (either msg_free_list or tx_free_list)
  2171. *
  2172. * TX Queue works as follows:
  2173. *
  2174. * Read index - points to the next TBD that the firmware will
  2175. * process. The firmware will read the data, and once
  2176. * done processing, it will advance the Read index.
  2177. *
  2178. * Write index - driver fills this entry with an constructed TBD
  2179. * entry. The Write index is not advanced until the
  2180. * packet has been configured.
  2181. *
  2182. * In between the W and R indexes are the TBDs that have NOT been
  2183. * processed. Lagging behind the R index are packets that have
  2184. * been processed but have not been freed by the driver.
  2185. *
  2186. * In order to free old storage, an internal index will be maintained
  2187. * that points to the next packet to be freed. When all used
  2188. * packets have been freed, the oldest index will be the same as the
  2189. * firmware's read index.
  2190. *
  2191. * The OLDEST index is cached in the variable 'priv->tx_queue.oldest'
  2192. *
  2193. * Because the TBD structure can not contain arbitrary data, the
  2194. * driver must keep an internal queue of cached allocations such that
  2195. * it can put that data back into the tx_free_list and msg_free_list
  2196. * for use by future command and data packets.
  2197. *
  2198. */
  2199. static inline int __ipw2100_tx_process(struct ipw2100_priv *priv)
  2200. {
  2201. struct ipw2100_bd_queue *txq = &priv->tx_queue;
  2202. struct ipw2100_bd *tbd;
  2203. struct list_head *element;
  2204. struct ipw2100_tx_packet *packet;
  2205. int descriptors_used;
  2206. int e, i;
  2207. u32 r, w, frag_num = 0;
  2208. if (list_empty(&priv->fw_pend_list))
  2209. return 0;
  2210. element = priv->fw_pend_list.next;
  2211. packet = list_entry(element, struct ipw2100_tx_packet, list);
  2212. tbd = &txq->drv[packet->index];
  2213. /* Determine how many TBD entries must be finished... */
  2214. switch (packet->type) {
  2215. case COMMAND:
  2216. /* COMMAND uses only one slot; don't advance */
  2217. descriptors_used = 1;
  2218. e = txq->oldest;
  2219. break;
  2220. case DATA:
  2221. /* DATA uses two slots; advance and loop position. */
  2222. descriptors_used = tbd->num_fragments;
  2223. frag_num = tbd->num_fragments - 1;
  2224. e = txq->oldest + frag_num;
  2225. e %= txq->entries;
  2226. break;
  2227. default:
  2228. printk(KERN_WARNING DRV_NAME ": %s: Bad fw_pend_list entry!\n",
  2229. priv->net_dev->name);
  2230. return 0;
  2231. }
  2232. /* if the last TBD is not done by NIC yet, then packet is
  2233. * not ready to be released.
  2234. *
  2235. */
  2236. read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
  2237. &r);
  2238. read_register(priv->net_dev, IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
  2239. &w);
  2240. if (w != txq->next)
  2241. printk(KERN_WARNING DRV_NAME ": %s: write index mismatch\n",
  2242. priv->net_dev->name);
  2243. /*
  2244. * txq->next is the index of the last packet written txq->oldest is
  2245. * the index of the r is the index of the next packet to be read by
  2246. * firmware
  2247. */
  2248. /*
  2249. * Quick graphic to help you visualize the following
  2250. * if / else statement
  2251. *
  2252. * ===>| s---->|===============
  2253. * e>|
  2254. * | a | b | c | d | e | f | g | h | i | j | k | l
  2255. * r---->|
  2256. * w
  2257. *
  2258. * w - updated by driver
  2259. * r - updated by firmware
  2260. * s - start of oldest BD entry (txq->oldest)
  2261. * e - end of oldest BD entry
  2262. *
  2263. */
  2264. if (!((r <= w && (e < r || e >= w)) || (e < r && e >= w))) {
  2265. IPW_DEBUG_TX("exit - no processed packets ready to release.\n");
  2266. return 0;
  2267. }
  2268. list_del(element);
  2269. DEC_STAT(&priv->fw_pend_stat);
  2270. #ifdef CONFIG_IPW_DEBUG
  2271. {
  2272. int i = txq->oldest;
  2273. IPW_DEBUG_TX(
  2274. "TX%d V=%p P=%04X T=%04X L=%d\n", i,
  2275. &txq->drv[i],
  2276. (u32)(txq->nic + i * sizeof(struct ipw2100_bd)),
  2277. txq->drv[i].host_addr,
  2278. txq->drv[i].buf_length);
  2279. if (packet->type == DATA) {
  2280. i = (i + 1) % txq->entries;
  2281. IPW_DEBUG_TX(
  2282. "TX%d V=%p P=%04X T=%04X L=%d\n", i,
  2283. &txq->drv[i],
  2284. (u32)(txq->nic + i *
  2285. sizeof(struct ipw2100_bd)),
  2286. (u32)txq->drv[i].host_addr,
  2287. txq->drv[i].buf_length);
  2288. }
  2289. }
  2290. #endif
  2291. switch (packet->type) {
  2292. case DATA:
  2293. if (txq->drv[txq->oldest].status.info.fields.txType != 0)
  2294. printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. "
  2295. "Expecting DATA TBD but pulled "
  2296. "something else: ids %d=%d.\n",
  2297. priv->net_dev->name, txq->oldest, packet->index);
  2298. /* DATA packet; we have to unmap and free the SKB */
  2299. priv->ieee->stats.tx_packets++;
  2300. for (i = 0; i < frag_num; i++) {
  2301. tbd = &txq->drv[(packet->index + 1 + i) %
  2302. txq->entries];
  2303. IPW_DEBUG_TX(
  2304. "TX%d P=%08x L=%d\n",
  2305. (packet->index + 1 + i) % txq->entries,
  2306. tbd->host_addr, tbd->buf_length);
  2307. pci_unmap_single(priv->pci_dev,
  2308. tbd->host_addr,
  2309. tbd->buf_length,
  2310. PCI_DMA_TODEVICE);
  2311. }
  2312. priv->ieee->stats.tx_bytes += packet->info.d_struct.txb->payload_size;
  2313. ieee80211_txb_free(packet->info.d_struct.txb);
  2314. packet->info.d_struct.txb = NULL;
  2315. list_add_tail(element, &priv->tx_free_list);
  2316. INC_STAT(&priv->tx_free_stat);
  2317. /* We have a free slot in the Tx queue, so wake up the
  2318. * transmit layer if it is stopped. */
  2319. if (priv->status & STATUS_ASSOCIATED &&
  2320. netif_queue_stopped(priv->net_dev)) {
  2321. IPW_DEBUG_INFO(KERN_INFO
  2322. "%s: Waking net queue.\n",
  2323. priv->net_dev->name);
  2324. netif_wake_queue(priv->net_dev);
  2325. }
  2326. /* A packet was processed by the hardware, so update the
  2327. * watchdog */
  2328. priv->net_dev->trans_start = jiffies;
  2329. break;
  2330. case COMMAND:
  2331. if (txq->drv[txq->oldest].status.info.fields.txType != 1)
  2332. printk(KERN_WARNING DRV_NAME ": %s: Queue mismatch. "
  2333. "Expecting COMMAND TBD but pulled "
  2334. "something else: ids %d=%d.\n",
  2335. priv->net_dev->name, txq->oldest, packet->index);
  2336. #ifdef CONFIG_IPW_DEBUG
  2337. if (packet->info.c_struct.cmd->host_command_reg <
  2338. sizeof(command_types) / sizeof(*command_types))
  2339. IPW_DEBUG_TX(
  2340. "Command '%s (%d)' processed: %d.\n",
  2341. command_types[packet->info.c_struct.cmd->host_command_reg],
  2342. packet->info.c_struct.cmd->host_command_reg,
  2343. packet->info.c_struct.cmd->cmd_status_reg);
  2344. #endif
  2345. list_add_tail(element, &priv->msg_free_list);
  2346. INC_STAT(&priv->msg_free_stat);
  2347. break;
  2348. }
  2349. /* advance oldest used TBD pointer to start of next entry */
  2350. txq->oldest = (e + 1) % txq->entries;
  2351. /* increase available TBDs number */
  2352. txq->available += descriptors_used;
  2353. SET_STAT(&priv->txq_stat, txq->available);
  2354. IPW_DEBUG_TX("packet latency (send to process) %ld jiffies\n",
  2355. jiffies - packet->jiffy_start);
  2356. return (!list_empty(&priv->fw_pend_list));
  2357. }
  2358. static inline void __ipw2100_tx_complete(struct ipw2100_priv *priv)
  2359. {
  2360. int i = 0;
  2361. while (__ipw2100_tx_process(priv) && i < 200) i++;
  2362. if (i == 200) {
  2363. printk(KERN_WARNING DRV_NAME ": "
  2364. "%s: Driver is running slow (%d iters).\n",
  2365. priv->net_dev->name, i);
  2366. }
  2367. }
  2368. static void ipw2100_tx_send_commands(struct ipw2100_priv *priv)
  2369. {
  2370. struct list_head *element;
  2371. struct ipw2100_tx_packet *packet;
  2372. struct ipw2100_bd_queue *txq = &priv->tx_queue;
  2373. struct ipw2100_bd *tbd;
  2374. int next = txq->next;
  2375. while (!list_empty(&priv->msg_pend_list)) {
  2376. /* if there isn't enough space in TBD queue, then
  2377. * don't stuff a new one in.
  2378. * NOTE: 3 are needed as a command will take one,
  2379. * and there is a minimum of 2 that must be
  2380. * maintained between the r and w indexes
  2381. */
  2382. if (txq->available <= 3) {
  2383. IPW_DEBUG_TX("no room in tx_queue\n");
  2384. break;
  2385. }
  2386. element = priv->msg_pend_list.next;
  2387. list_del(element);
  2388. DEC_STAT(&priv->msg_pend_stat);
  2389. packet = list_entry(element,
  2390. struct ipw2100_tx_packet, list);
  2391. IPW_DEBUG_TX("using TBD at virt=%p, phys=%p\n",
  2392. &txq->drv[txq->next],
  2393. (void*)(txq->nic + txq->next *
  2394. sizeof(struct ipw2100_bd)));
  2395. packet->index = txq->next;
  2396. tbd = &txq->drv[txq->next];
  2397. /* initialize TBD */
  2398. tbd->host_addr = packet->info.c_struct.cmd_phys;
  2399. tbd->buf_length = sizeof(struct ipw2100_cmd_header);
  2400. /* not marking number of fragments causes problems
  2401. * with f/w debug version */
  2402. tbd->num_fragments = 1;
  2403. tbd->status.info.field =
  2404. IPW_BD_STATUS_TX_FRAME_COMMAND |
  2405. IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
  2406. /* update TBD queue counters */
  2407. txq->next++;
  2408. txq->next %= txq->entries;
  2409. txq->available--;
  2410. DEC_STAT(&priv->txq_stat);
  2411. list_add_tail(element, &priv->fw_pend_list);
  2412. INC_STAT(&priv->fw_pend_stat);
  2413. }
  2414. if (txq->next != next) {
  2415. /* kick off the DMA by notifying firmware the
  2416. * write index has moved; make sure TBD stores are sync'd */
  2417. wmb();
  2418. write_register(priv->net_dev,
  2419. IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
  2420. txq->next);
  2421. }
  2422. }
  2423. /*
  2424. * ipw2100_tx_send_data
  2425. *
  2426. */
  2427. static void ipw2100_tx_send_data(struct ipw2100_priv *priv)
  2428. {
  2429. struct list_head *element;
  2430. struct ipw2100_tx_packet *packet;
  2431. struct ipw2100_bd_queue *txq = &priv->tx_queue;
  2432. struct ipw2100_bd *tbd;
  2433. int next = txq->next;
  2434. int i = 0;
  2435. struct ipw2100_data_header *ipw_hdr;
  2436. struct ieee80211_hdr *hdr;
  2437. while (!list_empty(&priv->tx_pend_list)) {
  2438. /* if there isn't enough space in TBD queue, then
  2439. * don't stuff a new one in.
  2440. * NOTE: 4 are needed as a data will take two,
  2441. * and there is a minimum of 2 that must be
  2442. * maintained between the r and w indexes
  2443. */
  2444. element = priv->tx_pend_list.next;
  2445. packet = list_entry(element, struct ipw2100_tx_packet, list);
  2446. if (unlikely(1 + packet->info.d_struct.txb->nr_frags >
  2447. IPW_MAX_BDS)) {
  2448. /* TODO: Support merging buffers if more than
  2449. * IPW_MAX_BDS are used */
  2450. IPW_DEBUG_INFO(
  2451. "%s: Maximum BD theshold exceeded. "
  2452. "Increase fragmentation level.\n",
  2453. priv->net_dev->name);
  2454. }
  2455. if (txq->available <= 3 +
  2456. packet->info.d_struct.txb->nr_frags) {
  2457. IPW_DEBUG_TX("no room in tx_queue\n");
  2458. break;
  2459. }
  2460. list_del(element);
  2461. DEC_STAT(&priv->tx_pend_stat);
  2462. tbd = &txq->drv[txq->next];
  2463. packet->index = txq->next;
  2464. ipw_hdr = packet->info.d_struct.data;
  2465. hdr = (struct ieee80211_hdr *)packet->info.d_struct.txb->
  2466. fragments[0]->data;
  2467. if (priv->ieee->iw_mode == IW_MODE_INFRA) {
  2468. /* To DS: Addr1 = BSSID, Addr2 = SA,
  2469. Addr3 = DA */
  2470. memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
  2471. memcpy(ipw_hdr->dst_addr, hdr->addr3, ETH_ALEN);
  2472. } else if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
  2473. /* not From/To DS: Addr1 = DA, Addr2 = SA,
  2474. Addr3 = BSSID */
  2475. memcpy(ipw_hdr->src_addr, hdr->addr2, ETH_ALEN);
  2476. memcpy(ipw_hdr->dst_addr, hdr->addr1, ETH_ALEN);
  2477. }
  2478. ipw_hdr->host_command_reg = SEND;
  2479. ipw_hdr->host_command_reg1 = 0;
  2480. /* For now we only support host based encryption */
  2481. ipw_hdr->needs_encryption = 0;
  2482. ipw_hdr->encrypted = packet->info.d_struct.txb->encrypted;
  2483. if (packet->info.d_struct.txb->nr_frags > 1)
  2484. ipw_hdr->fragment_size =
  2485. packet->info.d_struct.txb->frag_size - IEEE80211_3ADDR_LEN;
  2486. else
  2487. ipw_hdr->fragment_size = 0;
  2488. tbd->host_addr = packet->info.d_struct.data_phys;
  2489. tbd->buf_length = sizeof(struct ipw2100_data_header);
  2490. tbd->num_fragments = 1 + packet->info.d_struct.txb->nr_frags;
  2491. tbd->status.info.field =
  2492. IPW_BD_STATUS_TX_FRAME_802_3 |
  2493. IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
  2494. txq->next++;
  2495. txq->next %= txq->entries;
  2496. IPW_DEBUG_TX(
  2497. "data header tbd TX%d P=%08x L=%d\n",
  2498. packet->index, tbd->host_addr,
  2499. tbd->buf_length);
  2500. #ifdef CONFIG_IPW_DEBUG
  2501. if (packet->info.d_struct.txb->nr_frags > 1)
  2502. IPW_DEBUG_FRAG("fragment Tx: %d frames\n",
  2503. packet->info.d_struct.txb->nr_frags);
  2504. #endif
  2505. for (i = 0; i < packet->info.d_struct.txb->nr_frags; i++) {
  2506. tbd = &txq->drv[txq->next];
  2507. if (i == packet->info.d_struct.txb->nr_frags - 1)
  2508. tbd->status.info.field =
  2509. IPW_BD_STATUS_TX_FRAME_802_3 |
  2510. IPW_BD_STATUS_TX_INTERRUPT_ENABLE;
  2511. else
  2512. tbd->status.info.field =
  2513. IPW_BD_STATUS_TX_FRAME_802_3 |
  2514. IPW_BD_STATUS_TX_FRAME_NOT_LAST_FRAGMENT;
  2515. tbd->buf_length = packet->info.d_struct.txb->
  2516. fragments[i]->len - IEEE80211_3ADDR_LEN;
  2517. tbd->host_addr = pci_map_single(
  2518. priv->pci_dev,
  2519. packet->info.d_struct.txb->fragments[i]->data +
  2520. IEEE80211_3ADDR_LEN,
  2521. tbd->buf_length,
  2522. PCI_DMA_TODEVICE);
  2523. IPW_DEBUG_TX(
  2524. "data frag tbd TX%d P=%08x L=%d\n",
  2525. txq->next, tbd->host_addr, tbd->buf_length);
  2526. pci_dma_sync_single_for_device(
  2527. priv->pci_dev, tbd->host_addr,
  2528. tbd->buf_length,
  2529. PCI_DMA_TODEVICE);
  2530. txq->next++;
  2531. txq->next %= txq->entries;
  2532. }
  2533. txq->available -= 1 + packet->info.d_struct.txb->nr_frags;
  2534. SET_STAT(&priv->txq_stat, txq->available);
  2535. list_add_tail(element, &priv->fw_pend_list);
  2536. INC_STAT(&priv->fw_pend_stat);
  2537. }
  2538. if (txq->next != next) {
  2539. /* kick off the DMA by notifying firmware the
  2540. * write index has moved; make sure TBD stores are sync'd */
  2541. write_register(priv->net_dev,
  2542. IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX,
  2543. txq->next);
  2544. }
  2545. return;
  2546. }
  2547. static void ipw2100_irq_tasklet(struct ipw2100_priv *priv)
  2548. {
  2549. struct net_device *dev = priv->net_dev;
  2550. unsigned long flags;
  2551. u32 inta, tmp;
  2552. spin_lock_irqsave(&priv->low_lock, flags);
  2553. ipw2100_disable_interrupts(priv);
  2554. read_register(dev, IPW_REG_INTA, &inta);
  2555. IPW_DEBUG_ISR("enter - INTA: 0x%08lX\n",
  2556. (unsigned long)inta & IPW_INTERRUPT_MASK);
  2557. priv->in_isr++;
  2558. priv->interrupts++;
  2559. /* We do not loop and keep polling for more interrupts as this
  2560. * is frowned upon and doesn't play nicely with other potentially
  2561. * chained IRQs */
  2562. IPW_DEBUG_ISR("INTA: 0x%08lX\n",
  2563. (unsigned long)inta & IPW_INTERRUPT_MASK);
  2564. if (inta & IPW2100_INTA_FATAL_ERROR) {
  2565. printk(KERN_WARNING DRV_NAME
  2566. ": Fatal interrupt. Scheduling firmware restart.\n");
  2567. priv->inta_other++;
  2568. write_register(
  2569. dev, IPW_REG_INTA,
  2570. IPW2100_INTA_FATAL_ERROR);
  2571. read_nic_dword(dev, IPW_NIC_FATAL_ERROR, &priv->fatal_error);
  2572. IPW_DEBUG_INFO("%s: Fatal error value: 0x%08X\n",
  2573. priv->net_dev->name, priv->fatal_error);
  2574. read_nic_dword(dev, IPW_ERROR_ADDR(priv->fatal_error), &tmp);
  2575. IPW_DEBUG_INFO("%s: Fatal error address value: 0x%08X\n",
  2576. priv->net_dev->name, tmp);
  2577. /* Wake up any sleeping jobs */
  2578. schedule_reset(priv);
  2579. }
  2580. if (inta & IPW2100_INTA_PARITY_ERROR) {
  2581. printk(KERN_ERR DRV_NAME ": ***** PARITY ERROR INTERRUPT !!!! \n");
  2582. priv->inta_other++;
  2583. write_register(
  2584. dev, IPW_REG_INTA,
  2585. IPW2100_INTA_PARITY_ERROR);
  2586. }
  2587. if (inta & IPW2100_INTA_RX_TRANSFER) {
  2588. IPW_DEBUG_ISR("RX interrupt\n");
  2589. priv->rx_interrupts++;
  2590. write_register(
  2591. dev, IPW_REG_INTA,
  2592. IPW2100_INTA_RX_TRANSFER);
  2593. __ipw2100_rx_process(priv);
  2594. __ipw2100_tx_complete(priv);
  2595. }
  2596. if (inta & IPW2100_INTA_TX_TRANSFER) {
  2597. IPW_DEBUG_ISR("TX interrupt\n");
  2598. priv->tx_interrupts++;
  2599. write_register(dev, IPW_REG_INTA,
  2600. IPW2100_INTA_TX_TRANSFER);
  2601. __ipw2100_tx_complete(priv);
  2602. ipw2100_tx_send_commands(priv);
  2603. ipw2100_tx_send_data(priv);
  2604. }
  2605. if (inta & IPW2100_INTA_TX_COMPLETE) {
  2606. IPW_DEBUG_ISR("TX complete\n");
  2607. priv->inta_other++;
  2608. write_register(
  2609. dev, IPW_REG_INTA,
  2610. IPW2100_INTA_TX_COMPLETE);
  2611. __ipw2100_tx_complete(priv);
  2612. }
  2613. if (inta & IPW2100_INTA_EVENT_INTERRUPT) {
  2614. /* ipw2100_handle_event(dev); */
  2615. priv->inta_other++;
  2616. write_register(
  2617. dev, IPW_REG_INTA,
  2618. IPW2100_INTA_EVENT_INTERRUPT);
  2619. }
  2620. if (inta & IPW2100_INTA_FW_INIT_DONE) {
  2621. IPW_DEBUG_ISR("FW init done interrupt\n");
  2622. priv->inta_other++;
  2623. read_register(dev, IPW_REG_INTA, &tmp);
  2624. if (tmp & (IPW2100_INTA_FATAL_ERROR |
  2625. IPW2100_INTA_PARITY_ERROR)) {
  2626. write_register(
  2627. dev, IPW_REG_INTA,
  2628. IPW2100_INTA_FATAL_ERROR |
  2629. IPW2100_INTA_PARITY_ERROR);
  2630. }
  2631. write_register(dev, IPW_REG_INTA,
  2632. IPW2100_INTA_FW_INIT_DONE);
  2633. }
  2634. if (inta & IPW2100_INTA_STATUS_CHANGE) {
  2635. IPW_DEBUG_ISR("Status change interrupt\n");
  2636. priv->inta_other++;
  2637. write_register(
  2638. dev, IPW_REG_INTA,
  2639. IPW2100_INTA_STATUS_CHANGE);
  2640. }
  2641. if (inta & IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE) {
  2642. IPW_DEBUG_ISR("slave host mode interrupt\n");
  2643. priv->inta_other++;
  2644. write_register(
  2645. dev, IPW_REG_INTA,
  2646. IPW2100_INTA_SLAVE_MODE_HOST_COMMAND_DONE);
  2647. }
  2648. priv->in_isr--;
  2649. ipw2100_enable_interrupts(priv);
  2650. spin_unlock_irqrestore(&priv->low_lock, flags);
  2651. IPW_DEBUG_ISR("exit\n");
  2652. }
  2653. static irqreturn_t ipw2100_interrupt(int irq, void *data,
  2654. struct pt_regs *regs)
  2655. {
  2656. struct ipw2100_priv *priv = data;
  2657. u32 inta, inta_mask;
  2658. if (!data)
  2659. return IRQ_NONE;
  2660. spin_lock(&priv->low_lock);
  2661. /* We check to see if we should be ignoring interrupts before
  2662. * we touch the hardware. During ucode load if we try and handle
  2663. * an interrupt we can cause keyboard problems as well as cause
  2664. * the ucode to fail to initialize */
  2665. if (!(priv->status & STATUS_INT_ENABLED)) {
  2666. /* Shared IRQ */
  2667. goto none;
  2668. }
  2669. read_register(priv->net_dev, IPW_REG_INTA_MASK, &inta_mask);
  2670. read_register(priv->net_dev, IPW_REG_INTA, &inta);
  2671. if (inta == 0xFFFFFFFF) {
  2672. /* Hardware disappeared */
  2673. printk(KERN_WARNING DRV_NAME ": IRQ INTA == 0xFFFFFFFF\n");
  2674. goto none;
  2675. }
  2676. inta &= IPW_INTERRUPT_MASK;
  2677. if (!(inta & inta_mask)) {
  2678. /* Shared interrupt */
  2679. goto none;
  2680. }
  2681. /* We disable the hardware interrupt here just to prevent unneeded
  2682. * calls to be made. We disable this again within the actual
  2683. * work tasklet, so if another part of the code re-enables the
  2684. * interrupt, that is fine */
  2685. ipw2100_disable_interrupts(priv);
  2686. tasklet_schedule(&priv->irq_tasklet);
  2687. spin_unlock(&priv->low_lock);
  2688. return IRQ_HANDLED;
  2689. none:
  2690. spin_unlock(&priv->low_lock);
  2691. return IRQ_NONE;
  2692. }
  2693. static int ipw2100_tx(struct ieee80211_txb *txb, struct net_device *dev)
  2694. {
  2695. struct ipw2100_priv *priv = ieee80211_priv(dev);
  2696. struct list_head *element;
  2697. struct ipw2100_tx_packet *packet;
  2698. unsigned long flags;
  2699. spin_lock_irqsave(&priv->low_lock, flags);
  2700. if (!(priv->status & STATUS_ASSOCIATED)) {
  2701. IPW_DEBUG_INFO("Can not transmit when not connected.\n");
  2702. priv->ieee->stats.tx_carrier_errors++;
  2703. netif_stop_queue(dev);
  2704. goto fail_unlock;
  2705. }
  2706. if (list_empty(&priv->tx_free_list))
  2707. goto fail_unlock;
  2708. element = priv->tx_free_list.next;
  2709. packet = list_entry(element, struct ipw2100_tx_packet, list);
  2710. packet->info.d_struct.txb = txb;
  2711. IPW_DEBUG_TX("Sending fragment (%d bytes):\n",
  2712. txb->fragments[0]->len);
  2713. printk_buf(IPW_DL_TX, txb->fragments[0]->data,
  2714. txb->fragments[0]->len);
  2715. packet->jiffy_start = jiffies;
  2716. list_del(element);
  2717. DEC_STAT(&priv->tx_free_stat);
  2718. list_add_tail(element, &priv->tx_pend_list);
  2719. INC_STAT(&priv->tx_pend_stat);
  2720. ipw2100_tx_send_data(priv);
  2721. spin_unlock_irqrestore(&priv->low_lock, flags);
  2722. return 0;
  2723. fail_unlock:
  2724. netif_stop_queue(dev);
  2725. spin_unlock_irqrestore(&priv->low_lock, flags);
  2726. return 1;
  2727. }
  2728. static int ipw2100_msg_allocate(struct ipw2100_priv *priv)
  2729. {
  2730. int i, j, err = -EINVAL;
  2731. void *v;
  2732. dma_addr_t p;
  2733. priv->msg_buffers = (struct ipw2100_tx_packet *)kmalloc(
  2734. IPW_COMMAND_POOL_SIZE * sizeof(struct ipw2100_tx_packet),
  2735. GFP_KERNEL);
  2736. if (!priv->msg_buffers) {
  2737. printk(KERN_ERR DRV_NAME ": %s: PCI alloc failed for msg "
  2738. "buffers.\n", priv->net_dev->name);
  2739. return -ENOMEM;
  2740. }
  2741. for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
  2742. v = pci_alloc_consistent(
  2743. priv->pci_dev,
  2744. sizeof(struct ipw2100_cmd_header),
  2745. &p);
  2746. if (!v) {
  2747. printk(KERN_ERR DRV_NAME ": "
  2748. "%s: PCI alloc failed for msg "
  2749. "buffers.\n",
  2750. priv->net_dev->name);
  2751. err = -ENOMEM;
  2752. break;
  2753. }
  2754. memset(v, 0, sizeof(struct ipw2100_cmd_header));
  2755. priv->msg_buffers[i].type = COMMAND;
  2756. priv->msg_buffers[i].info.c_struct.cmd =
  2757. (struct ipw2100_cmd_header*)v;
  2758. priv->msg_buffers[i].info.c_struct.cmd_phys = p;
  2759. }
  2760. if (i == IPW_COMMAND_POOL_SIZE)
  2761. return 0;
  2762. for (j = 0; j < i; j++) {
  2763. pci_free_consistent(
  2764. priv->pci_dev,
  2765. sizeof(struct ipw2100_cmd_header),
  2766. priv->msg_buffers[j].info.c_struct.cmd,
  2767. priv->msg_buffers[j].info.c_struct.cmd_phys);
  2768. }
  2769. kfree(priv->msg_buffers);
  2770. priv->msg_buffers = NULL;
  2771. return err;
  2772. }
  2773. static int ipw2100_msg_initialize(struct ipw2100_priv *priv)
  2774. {
  2775. int i;
  2776. INIT_LIST_HEAD(&priv->msg_free_list);
  2777. INIT_LIST_HEAD(&priv->msg_pend_list);
  2778. for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++)
  2779. list_add_tail(&priv->msg_buffers[i].list, &priv->msg_free_list);
  2780. SET_STAT(&priv->msg_free_stat, i);
  2781. return 0;
  2782. }
  2783. static void ipw2100_msg_free(struct ipw2100_priv *priv)
  2784. {
  2785. int i;
  2786. if (!priv->msg_buffers)
  2787. return;
  2788. for (i = 0; i < IPW_COMMAND_POOL_SIZE; i++) {
  2789. pci_free_consistent(priv->pci_dev,
  2790. sizeof(struct ipw2100_cmd_header),
  2791. priv->msg_buffers[i].info.c_struct.cmd,
  2792. priv->msg_buffers[i].info.c_struct.cmd_phys);
  2793. }
  2794. kfree(priv->msg_buffers);
  2795. priv->msg_buffers = NULL;
  2796. }
  2797. static ssize_t show_pci(struct device *d, struct device_attribute *attr,
  2798. char *buf)
  2799. {
  2800. struct pci_dev *pci_dev = container_of(d, struct pci_dev, dev);
  2801. char *out = buf;
  2802. int i, j;
  2803. u32 val;
  2804. for (i = 0; i < 16; i++) {
  2805. out += sprintf(out, "[%08X] ", i * 16);
  2806. for (j = 0; j < 16; j += 4) {
  2807. pci_read_config_dword(pci_dev, i * 16 + j, &val);
  2808. out += sprintf(out, "%08X ", val);
  2809. }
  2810. out += sprintf(out, "\n");
  2811. }
  2812. return out - buf;
  2813. }
  2814. static DEVICE_ATTR(pci, S_IRUGO, show_pci, NULL);
  2815. static ssize_t show_cfg(struct device *d, struct device_attribute *attr,
  2816. char *buf)
  2817. {
  2818. struct ipw2100_priv *p = d->driver_data;
  2819. return sprintf(buf, "0x%08x\n", (int)p->config);
  2820. }
  2821. static DEVICE_ATTR(cfg, S_IRUGO, show_cfg, NULL);
  2822. static ssize_t show_status(struct device *d, struct device_attribute *attr,
  2823. char *buf)
  2824. {
  2825. struct ipw2100_priv *p = d->driver_data;
  2826. return sprintf(buf, "0x%08x\n", (int)p->status);
  2827. }
  2828. static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
  2829. static ssize_t show_capability(struct device *d, struct device_attribute *attr,
  2830. char *buf)
  2831. {
  2832. struct ipw2100_priv *p = d->driver_data;
  2833. return sprintf(buf, "0x%08x\n", (int)p->capability);
  2834. }
  2835. static DEVICE_ATTR(capability, S_IRUGO, show_capability, NULL);
  2836. #define IPW2100_REG(x) { IPW_ ##x, #x }
  2837. static const struct {
  2838. u32 addr;
  2839. const char *name;
  2840. } hw_data[] = {
  2841. IPW2100_REG(REG_GP_CNTRL),
  2842. IPW2100_REG(REG_GPIO),
  2843. IPW2100_REG(REG_INTA),
  2844. IPW2100_REG(REG_INTA_MASK),
  2845. IPW2100_REG(REG_RESET_REG),
  2846. };
  2847. #define IPW2100_NIC(x, s) { x, #x, s }
  2848. static const struct {
  2849. u32 addr;
  2850. const char *name;
  2851. size_t size;
  2852. } nic_data[] = {
  2853. IPW2100_NIC(IPW2100_CONTROL_REG, 2),
  2854. IPW2100_NIC(0x210014, 1),
  2855. IPW2100_NIC(0x210000, 1),
  2856. };
  2857. #define IPW2100_ORD(x, d) { IPW_ORD_ ##x, #x, d }
  2858. static const struct {
  2859. u8 index;
  2860. const char *name;
  2861. const char *desc;
  2862. } ord_data[] = {
  2863. IPW2100_ORD(STAT_TX_HOST_REQUESTS, "requested Host Tx's (MSDU)"),
  2864. IPW2100_ORD(STAT_TX_HOST_COMPLETE, "successful Host Tx's (MSDU)"),
  2865. IPW2100_ORD(STAT_TX_DIR_DATA, "successful Directed Tx's (MSDU)"),
  2866. IPW2100_ORD(STAT_TX_DIR_DATA1, "successful Directed Tx's (MSDU) @ 1MB"),
  2867. IPW2100_ORD(STAT_TX_DIR_DATA2, "successful Directed Tx's (MSDU) @ 2MB"),
  2868. IPW2100_ORD(STAT_TX_DIR_DATA5_5, "successful Directed Tx's (MSDU) @ 5_5MB"),
  2869. IPW2100_ORD(STAT_TX_DIR_DATA11, "successful Directed Tx's (MSDU) @ 11MB"),
  2870. IPW2100_ORD(STAT_TX_NODIR_DATA1, "successful Non_Directed Tx's (MSDU) @ 1MB"),
  2871. IPW2100_ORD(STAT_TX_NODIR_DATA2, "successful Non_Directed Tx's (MSDU) @ 2MB"),
  2872. IPW2100_ORD(STAT_TX_NODIR_DATA5_5, "successful Non_Directed Tx's (MSDU) @ 5.5MB"),
  2873. IPW2100_ORD(STAT_TX_NODIR_DATA11, "successful Non_Directed Tx's (MSDU) @ 11MB"),
  2874. IPW2100_ORD(STAT_NULL_DATA, "successful NULL data Tx's"),
  2875. IPW2100_ORD(STAT_TX_RTS, "successful Tx RTS"),
  2876. IPW2100_ORD(STAT_TX_CTS, "successful Tx CTS"),
  2877. IPW2100_ORD(STAT_TX_ACK, "successful Tx ACK"),
  2878. IPW2100_ORD(STAT_TX_ASSN, "successful Association Tx's"),
  2879. IPW2100_ORD(STAT_TX_ASSN_RESP, "successful Association response Tx's"),
  2880. IPW2100_ORD(STAT_TX_REASSN, "successful Reassociation Tx's"),
  2881. IPW2100_ORD(STAT_TX_REASSN_RESP, "successful Reassociation response Tx's"),
  2882. IPW2100_ORD(STAT_TX_PROBE, "probes successfully transmitted"),
  2883. IPW2100_ORD(STAT_TX_PROBE_RESP, "probe responses successfully transmitted"),
  2884. IPW2100_ORD(STAT_TX_BEACON, "tx beacon"),
  2885. IPW2100_ORD(STAT_TX_ATIM, "Tx ATIM"),
  2886. IPW2100_ORD(STAT_TX_DISASSN, "successful Disassociation TX"),
  2887. IPW2100_ORD(STAT_TX_AUTH, "successful Authentication Tx"),
  2888. IPW2100_ORD(STAT_TX_DEAUTH, "successful Deauthentication TX"),
  2889. IPW2100_ORD(STAT_TX_TOTAL_BYTES, "Total successful Tx data bytes"),
  2890. IPW2100_ORD(STAT_TX_RETRIES, "Tx retries"),
  2891. IPW2100_ORD(STAT_TX_RETRY1, "Tx retries at 1MBPS"),
  2892. IPW2100_ORD(STAT_TX_RETRY2, "Tx retries at 2MBPS"),
  2893. IPW2100_ORD(STAT_TX_RETRY5_5, "Tx retries at 5.5MBPS"),
  2894. IPW2100_ORD(STAT_TX_RETRY11, "Tx retries at 11MBPS"),
  2895. IPW2100_ORD(STAT_TX_FAILURES, "Tx Failures"),
  2896. IPW2100_ORD(STAT_TX_MAX_TRIES_IN_HOP,"times max tries in a hop failed"),
  2897. IPW2100_ORD(STAT_TX_DISASSN_FAIL, "times disassociation failed"),
  2898. IPW2100_ORD(STAT_TX_ERR_CTS, "missed/bad CTS frames"),
  2899. IPW2100_ORD(STAT_TX_ERR_ACK, "tx err due to acks"),
  2900. IPW2100_ORD(STAT_RX_HOST, "packets passed to host"),
  2901. IPW2100_ORD(STAT_RX_DIR_DATA, "directed packets"),
  2902. IPW2100_ORD(STAT_RX_DIR_DATA1, "directed packets at 1MB"),
  2903. IPW2100_ORD(STAT_RX_DIR_DATA2, "directed packets at 2MB"),
  2904. IPW2100_ORD(STAT_RX_DIR_DATA5_5, "directed packets at 5.5MB"),
  2905. IPW2100_ORD(STAT_RX_DIR_DATA11, "directed packets at 11MB"),
  2906. IPW2100_ORD(STAT_RX_NODIR_DATA,"nondirected packets"),
  2907. IPW2100_ORD(STAT_RX_NODIR_DATA1, "nondirected packets at 1MB"),
  2908. IPW2100_ORD(STAT_RX_NODIR_DATA2, "nondirected packets at 2MB"),
  2909. IPW2100_ORD(STAT_RX_NODIR_DATA5_5, "nondirected packets at 5.5MB"),
  2910. IPW2100_ORD(STAT_RX_NODIR_DATA11, "nondirected packets at 11MB"),
  2911. IPW2100_ORD(STAT_RX_NULL_DATA, "null data rx's"),
  2912. IPW2100_ORD(STAT_RX_RTS, "Rx RTS"),
  2913. IPW2100_ORD(STAT_RX_CTS, "Rx CTS"),
  2914. IPW2100_ORD(STAT_RX_ACK, "Rx ACK"),
  2915. IPW2100_ORD(STAT_RX_CFEND, "Rx CF End"),
  2916. IPW2100_ORD(STAT_RX_CFEND_ACK, "Rx CF End + CF Ack"),
  2917. IPW2100_ORD(STAT_RX_ASSN, "Association Rx's"),
  2918. IPW2100_ORD(STAT_RX_ASSN_RESP, "Association response Rx's"),
  2919. IPW2100_ORD(STAT_RX_REASSN, "Reassociation Rx's"),
  2920. IPW2100_ORD(STAT_RX_REASSN_RESP, "Reassociation response Rx's"),
  2921. IPW2100_ORD(STAT_RX_PROBE, "probe Rx's"),
  2922. IPW2100_ORD(STAT_RX_PROBE_RESP, "probe response Rx's"),
  2923. IPW2100_ORD(STAT_RX_BEACON, "Rx beacon"),
  2924. IPW2100_ORD(STAT_RX_ATIM, "Rx ATIM"),
  2925. IPW2100_ORD(STAT_RX_DISASSN, "disassociation Rx"),
  2926. IPW2100_ORD(STAT_RX_AUTH, "authentication Rx"),
  2927. IPW2100_ORD(STAT_RX_DEAUTH, "deauthentication Rx"),
  2928. IPW2100_ORD(STAT_RX_TOTAL_BYTES,"Total rx data bytes received"),
  2929. IPW2100_ORD(STAT_RX_ERR_CRC, "packets with Rx CRC error"),
  2930. IPW2100_ORD(STAT_RX_ERR_CRC1, "Rx CRC errors at 1MB"),
  2931. IPW2100_ORD(STAT_RX_ERR_CRC2, "Rx CRC errors at 2MB"),
  2932. IPW2100_ORD(STAT_RX_ERR_CRC5_5, "Rx CRC errors at 5.5MB"),
  2933. IPW2100_ORD(STAT_RX_ERR_CRC11, "Rx CRC errors at 11MB"),
  2934. IPW2100_ORD(STAT_RX_DUPLICATE1, "duplicate rx packets at 1MB"),
  2935. IPW2100_ORD(STAT_RX_DUPLICATE2, "duplicate rx packets at 2MB"),
  2936. IPW2100_ORD(STAT_RX_DUPLICATE5_5, "duplicate rx packets at 5.5MB"),
  2937. IPW2100_ORD(STAT_RX_DUPLICATE11, "duplicate rx packets at 11MB"),
  2938. IPW2100_ORD(STAT_RX_DUPLICATE, "duplicate rx packets"),
  2939. IPW2100_ORD(PERS_DB_LOCK, "locking fw permanent db"),
  2940. IPW2100_ORD(PERS_DB_SIZE, "size of fw permanent db"),
  2941. IPW2100_ORD(PERS_DB_ADDR, "address of fw permanent db"),
  2942. IPW2100_ORD(STAT_RX_INVALID_PROTOCOL, "rx frames with invalid protocol"),
  2943. IPW2100_ORD(SYS_BOOT_TIME, "Boot time"),
  2944. IPW2100_ORD(STAT_RX_NO_BUFFER, "rx frames rejected due to no buffer"),
  2945. IPW2100_ORD(STAT_RX_MISSING_FRAG, "rx frames dropped due to missing fragment"),
  2946. IPW2100_ORD(STAT_RX_ORPHAN_FRAG, "rx frames dropped due to non-sequential fragment"),
  2947. IPW2100_ORD(STAT_RX_ORPHAN_FRAME, "rx frames dropped due to unmatched 1st frame"),
  2948. IPW2100_ORD(STAT_RX_FRAG_AGEOUT, "rx frames dropped due to uncompleted frame"),
  2949. IPW2100_ORD(STAT_RX_ICV_ERRORS, "ICV errors during decryption"),
  2950. IPW2100_ORD(STAT_PSP_SUSPENSION,"times adapter suspended"),
  2951. IPW2100_ORD(STAT_PSP_BCN_TIMEOUT, "beacon timeout"),
  2952. IPW2100_ORD(STAT_PSP_POLL_TIMEOUT, "poll response timeouts"),
  2953. IPW2100_ORD(STAT_PSP_NONDIR_TIMEOUT, "timeouts waiting for last {broad,multi}cast pkt"),
  2954. IPW2100_ORD(STAT_PSP_RX_DTIMS, "PSP DTIMs received"),
  2955. IPW2100_ORD(STAT_PSP_RX_TIMS, "PSP TIMs received"),
  2956. IPW2100_ORD(STAT_PSP_STATION_ID,"PSP Station ID"),
  2957. IPW2100_ORD(LAST_ASSN_TIME, "RTC time of last association"),
  2958. IPW2100_ORD(STAT_PERCENT_MISSED_BCNS,"current calculation of % missed beacons"),
  2959. IPW2100_ORD(STAT_PERCENT_RETRIES,"current calculation of % missed tx retries"),
  2960. IPW2100_ORD(ASSOCIATED_AP_PTR, "0 if not associated, else pointer to AP table entry"),
  2961. IPW2100_ORD(AVAILABLE_AP_CNT, "AP's decsribed in the AP table"),
  2962. IPW2100_ORD(AP_LIST_PTR, "Ptr to list of available APs"),
  2963. IPW2100_ORD(STAT_AP_ASSNS, "associations"),
  2964. IPW2100_ORD(STAT_ASSN_FAIL, "association failures"),
  2965. IPW2100_ORD(STAT_ASSN_RESP_FAIL,"failures due to response fail"),
  2966. IPW2100_ORD(STAT_FULL_SCANS, "full scans"),
  2967. IPW2100_ORD(CARD_DISABLED, "Card Disabled"),
  2968. IPW2100_ORD(STAT_ROAM_INHIBIT, "times roaming was inhibited due to activity"),
  2969. IPW2100_ORD(RSSI_AT_ASSN, "RSSI of associated AP at time of association"),
  2970. IPW2100_ORD(STAT_ASSN_CAUSE1, "reassociation: no probe response or TX on hop"),
  2971. IPW2100_ORD(STAT_ASSN_CAUSE2, "reassociation: poor tx/rx quality"),
  2972. IPW2100_ORD(STAT_ASSN_CAUSE3, "reassociation: tx/rx quality (excessive AP load"),
  2973. IPW2100_ORD(STAT_ASSN_CAUSE4, "reassociation: AP RSSI level"),
  2974. IPW2100_ORD(STAT_ASSN_CAUSE5, "reassociations due to load leveling"),
  2975. IPW2100_ORD(STAT_AUTH_FAIL, "times authentication failed"),
  2976. IPW2100_ORD(STAT_AUTH_RESP_FAIL,"times authentication response failed"),
  2977. IPW2100_ORD(STATION_TABLE_CNT, "entries in association table"),
  2978. IPW2100_ORD(RSSI_AVG_CURR, "Current avg RSSI"),
  2979. IPW2100_ORD(POWER_MGMT_MODE, "Power mode - 0=CAM, 1=PSP"),
  2980. IPW2100_ORD(COUNTRY_CODE, "IEEE country code as recv'd from beacon"),
  2981. IPW2100_ORD(COUNTRY_CHANNELS, "channels suported by country"),
  2982. IPW2100_ORD(RESET_CNT, "adapter resets (warm)"),
  2983. IPW2100_ORD(BEACON_INTERVAL, "Beacon interval"),
  2984. IPW2100_ORD(ANTENNA_DIVERSITY, "TRUE if antenna diversity is disabled"),
  2985. IPW2100_ORD(DTIM_PERIOD, "beacon intervals between DTIMs"),
  2986. IPW2100_ORD(OUR_FREQ, "current radio freq lower digits - channel ID"),
  2987. IPW2100_ORD(RTC_TIME, "current RTC time"),
  2988. IPW2100_ORD(PORT_TYPE, "operating mode"),
  2989. IPW2100_ORD(CURRENT_TX_RATE, "current tx rate"),
  2990. IPW2100_ORD(SUPPORTED_RATES, "supported tx rates"),
  2991. IPW2100_ORD(ATIM_WINDOW, "current ATIM Window"),
  2992. IPW2100_ORD(BASIC_RATES, "basic tx rates"),
  2993. IPW2100_ORD(NIC_HIGHEST_RATE, "NIC highest tx rate"),
  2994. IPW2100_ORD(AP_HIGHEST_RATE, "AP highest tx rate"),
  2995. IPW2100_ORD(CAPABILITIES, "Management frame capability field"),
  2996. IPW2100_ORD(AUTH_TYPE, "Type of authentication"),
  2997. IPW2100_ORD(RADIO_TYPE, "Adapter card platform type"),
  2998. IPW2100_ORD(RTS_THRESHOLD, "Min packet length for RTS handshaking"),
  2999. IPW2100_ORD(INT_MODE, "International mode"),
  3000. IPW2100_ORD(FRAGMENTATION_THRESHOLD, "protocol frag threshold"),
  3001. IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_START_ADDRESS, "EEPROM offset in SRAM"),
  3002. IPW2100_ORD(EEPROM_SRAM_DB_BLOCK_SIZE, "EEPROM size in SRAM"),
  3003. IPW2100_ORD(EEPROM_SKU_CAPABILITY, "EEPROM SKU Capability"),
  3004. IPW2100_ORD(EEPROM_IBSS_11B_CHANNELS, "EEPROM IBSS 11b channel set"),
  3005. IPW2100_ORD(MAC_VERSION, "MAC Version"),
  3006. IPW2100_ORD(MAC_REVISION, "MAC Revision"),
  3007. IPW2100_ORD(RADIO_VERSION, "Radio Version"),
  3008. IPW2100_ORD(NIC_MANF_DATE_TIME, "MANF Date/Time STAMP"),
  3009. IPW2100_ORD(UCODE_VERSION, "Ucode Version"),
  3010. };
  3011. static ssize_t show_registers(struct device *d, struct device_attribute *attr,
  3012. char *buf)
  3013. {
  3014. int i;
  3015. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3016. struct net_device *dev = priv->net_dev;
  3017. char * out = buf;
  3018. u32 val = 0;
  3019. out += sprintf(out, "%30s [Address ] : Hex\n", "Register");
  3020. for (i = 0; i < (sizeof(hw_data) / sizeof(*hw_data)); i++) {
  3021. read_register(dev, hw_data[i].addr, &val);
  3022. out += sprintf(out, "%30s [%08X] : %08X\n",
  3023. hw_data[i].name, hw_data[i].addr, val);
  3024. }
  3025. return out - buf;
  3026. }
  3027. static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL);
  3028. static ssize_t show_hardware(struct device *d, struct device_attribute *attr,
  3029. char *buf)
  3030. {
  3031. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3032. struct net_device *dev = priv->net_dev;
  3033. char * out = buf;
  3034. int i;
  3035. out += sprintf(out, "%30s [Address ] : Hex\n", "NIC entry");
  3036. for (i = 0; i < (sizeof(nic_data) / sizeof(*nic_data)); i++) {
  3037. u8 tmp8;
  3038. u16 tmp16;
  3039. u32 tmp32;
  3040. switch (nic_data[i].size) {
  3041. case 1:
  3042. read_nic_byte(dev, nic_data[i].addr, &tmp8);
  3043. out += sprintf(out, "%30s [%08X] : %02X\n",
  3044. nic_data[i].name, nic_data[i].addr,
  3045. tmp8);
  3046. break;
  3047. case 2:
  3048. read_nic_word(dev, nic_data[i].addr, &tmp16);
  3049. out += sprintf(out, "%30s [%08X] : %04X\n",
  3050. nic_data[i].name, nic_data[i].addr,
  3051. tmp16);
  3052. break;
  3053. case 4:
  3054. read_nic_dword(dev, nic_data[i].addr, &tmp32);
  3055. out += sprintf(out, "%30s [%08X] : %08X\n",
  3056. nic_data[i].name, nic_data[i].addr,
  3057. tmp32);
  3058. break;
  3059. }
  3060. }
  3061. return out - buf;
  3062. }
  3063. static DEVICE_ATTR(hardware, S_IRUGO, show_hardware, NULL);
  3064. static ssize_t show_memory(struct device *d, struct device_attribute *attr,
  3065. char *buf)
  3066. {
  3067. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3068. struct net_device *dev = priv->net_dev;
  3069. static unsigned long loop = 0;
  3070. int len = 0;
  3071. u32 buffer[4];
  3072. int i;
  3073. char line[81];
  3074. if (loop >= 0x30000)
  3075. loop = 0;
  3076. /* sysfs provides us PAGE_SIZE buffer */
  3077. while (len < PAGE_SIZE - 128 && loop < 0x30000) {
  3078. if (priv->snapshot[0]) for (i = 0; i < 4; i++)
  3079. buffer[i] = *(u32 *)SNAPSHOT_ADDR(loop + i * 4);
  3080. else for (i = 0; i < 4; i++)
  3081. read_nic_dword(dev, loop + i * 4, &buffer[i]);
  3082. if (priv->dump_raw)
  3083. len += sprintf(buf + len,
  3084. "%c%c%c%c"
  3085. "%c%c%c%c"
  3086. "%c%c%c%c"
  3087. "%c%c%c%c",
  3088. ((u8*)buffer)[0x0],
  3089. ((u8*)buffer)[0x1],
  3090. ((u8*)buffer)[0x2],
  3091. ((u8*)buffer)[0x3],
  3092. ((u8*)buffer)[0x4],
  3093. ((u8*)buffer)[0x5],
  3094. ((u8*)buffer)[0x6],
  3095. ((u8*)buffer)[0x7],
  3096. ((u8*)buffer)[0x8],
  3097. ((u8*)buffer)[0x9],
  3098. ((u8*)buffer)[0xa],
  3099. ((u8*)buffer)[0xb],
  3100. ((u8*)buffer)[0xc],
  3101. ((u8*)buffer)[0xd],
  3102. ((u8*)buffer)[0xe],
  3103. ((u8*)buffer)[0xf]);
  3104. else
  3105. len += sprintf(buf + len, "%s\n",
  3106. snprint_line(line, sizeof(line),
  3107. (u8*)buffer, 16, loop));
  3108. loop += 16;
  3109. }
  3110. return len;
  3111. }
  3112. static ssize_t store_memory(struct device *d, struct device_attribute *attr,
  3113. const char *buf, size_t count)
  3114. {
  3115. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3116. struct net_device *dev = priv->net_dev;
  3117. const char *p = buf;
  3118. if (count < 1)
  3119. return count;
  3120. if (p[0] == '1' ||
  3121. (count >= 2 && tolower(p[0]) == 'o' && tolower(p[1]) == 'n')) {
  3122. IPW_DEBUG_INFO("%s: Setting memory dump to RAW mode.\n",
  3123. dev->name);
  3124. priv->dump_raw = 1;
  3125. } else if (p[0] == '0' || (count >= 2 && tolower(p[0]) == 'o' &&
  3126. tolower(p[1]) == 'f')) {
  3127. IPW_DEBUG_INFO("%s: Setting memory dump to HEX mode.\n",
  3128. dev->name);
  3129. priv->dump_raw = 0;
  3130. } else if (tolower(p[0]) == 'r') {
  3131. IPW_DEBUG_INFO("%s: Resetting firmware snapshot.\n",
  3132. dev->name);
  3133. ipw2100_snapshot_free(priv);
  3134. } else
  3135. IPW_DEBUG_INFO("%s: Usage: 0|on = HEX, 1|off = RAW, "
  3136. "reset = clear memory snapshot\n",
  3137. dev->name);
  3138. return count;
  3139. }
  3140. static DEVICE_ATTR(memory, S_IWUSR|S_IRUGO, show_memory, store_memory);
  3141. static ssize_t show_ordinals(struct device *d, struct device_attribute *attr,
  3142. char *buf)
  3143. {
  3144. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3145. u32 val = 0;
  3146. int len = 0;
  3147. u32 val_len;
  3148. static int loop = 0;
  3149. if (loop >= sizeof(ord_data) / sizeof(*ord_data))
  3150. loop = 0;
  3151. /* sysfs provides us PAGE_SIZE buffer */
  3152. while (len < PAGE_SIZE - 128 &&
  3153. loop < (sizeof(ord_data) / sizeof(*ord_data))) {
  3154. val_len = sizeof(u32);
  3155. if (ipw2100_get_ordinal(priv, ord_data[loop].index, &val,
  3156. &val_len))
  3157. len += sprintf(buf + len, "[0x%02X] = ERROR %s\n",
  3158. ord_data[loop].index,
  3159. ord_data[loop].desc);
  3160. else
  3161. len += sprintf(buf + len, "[0x%02X] = 0x%08X %s\n",
  3162. ord_data[loop].index, val,
  3163. ord_data[loop].desc);
  3164. loop++;
  3165. }
  3166. return len;
  3167. }
  3168. static DEVICE_ATTR(ordinals, S_IRUGO, show_ordinals, NULL);
  3169. static ssize_t show_stats(struct device *d, struct device_attribute *attr,
  3170. char *buf)
  3171. {
  3172. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3173. char * out = buf;
  3174. out += sprintf(out, "interrupts: %d {tx: %d, rx: %d, other: %d}\n",
  3175. priv->interrupts, priv->tx_interrupts,
  3176. priv->rx_interrupts, priv->inta_other);
  3177. out += sprintf(out, "firmware resets: %d\n", priv->resets);
  3178. out += sprintf(out, "firmware hangs: %d\n", priv->hangs);
  3179. #ifdef CONFIG_IPW_DEBUG
  3180. out += sprintf(out, "packet mismatch image: %s\n",
  3181. priv->snapshot[0] ? "YES" : "NO");
  3182. #endif
  3183. return out - buf;
  3184. }
  3185. static DEVICE_ATTR(stats, S_IRUGO, show_stats, NULL);
  3186. static int ipw2100_switch_mode(struct ipw2100_priv *priv, u32 mode)
  3187. {
  3188. int err;
  3189. if (mode == priv->ieee->iw_mode)
  3190. return 0;
  3191. err = ipw2100_disable_adapter(priv);
  3192. if (err) {
  3193. printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
  3194. priv->net_dev->name, err);
  3195. return err;
  3196. }
  3197. switch (mode) {
  3198. case IW_MODE_INFRA:
  3199. priv->net_dev->type = ARPHRD_ETHER;
  3200. break;
  3201. case IW_MODE_ADHOC:
  3202. priv->net_dev->type = ARPHRD_ETHER;
  3203. break;
  3204. #ifdef CONFIG_IPW2100_MONITOR
  3205. case IW_MODE_MONITOR:
  3206. priv->last_mode = priv->ieee->iw_mode;
  3207. priv->net_dev->type = ARPHRD_IEEE80211;
  3208. break;
  3209. #endif /* CONFIG_IPW2100_MONITOR */
  3210. }
  3211. priv->ieee->iw_mode = mode;
  3212. #ifdef CONFIG_PM
  3213. /* Indicate ipw2100_download_firmware download firmware
  3214. * from disk instead of memory. */
  3215. ipw2100_firmware.version = 0;
  3216. #endif
  3217. printk(KERN_INFO "%s: Reseting on mode change.\n",
  3218. priv->net_dev->name);
  3219. priv->reset_backoff = 0;
  3220. schedule_reset(priv);
  3221. return 0;
  3222. }
  3223. static ssize_t show_internals(struct device *d, struct device_attribute *attr,
  3224. char *buf)
  3225. {
  3226. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3227. int len = 0;
  3228. #define DUMP_VAR(x,y) len += sprintf(buf + len, # x ": %" # y "\n", priv-> x)
  3229. if (priv->status & STATUS_ASSOCIATED)
  3230. len += sprintf(buf + len, "connected: %lu\n",
  3231. get_seconds() - priv->connect_start);
  3232. else
  3233. len += sprintf(buf + len, "not connected\n");
  3234. DUMP_VAR(ieee->crypt[priv->ieee->tx_keyidx], p);
  3235. DUMP_VAR(status, 08lx);
  3236. DUMP_VAR(config, 08lx);
  3237. DUMP_VAR(capability, 08lx);
  3238. len += sprintf(buf + len, "last_rtc: %lu\n", (unsigned long)priv->last_rtc);
  3239. DUMP_VAR(fatal_error, d);
  3240. DUMP_VAR(stop_hang_check, d);
  3241. DUMP_VAR(stop_rf_kill, d);
  3242. DUMP_VAR(messages_sent, d);
  3243. DUMP_VAR(tx_pend_stat.value, d);
  3244. DUMP_VAR(tx_pend_stat.hi, d);
  3245. DUMP_VAR(tx_free_stat.value, d);
  3246. DUMP_VAR(tx_free_stat.lo, d);
  3247. DUMP_VAR(msg_free_stat.value, d);
  3248. DUMP_VAR(msg_free_stat.lo, d);
  3249. DUMP_VAR(msg_pend_stat.value, d);
  3250. DUMP_VAR(msg_pend_stat.hi, d);
  3251. DUMP_VAR(fw_pend_stat.value, d);
  3252. DUMP_VAR(fw_pend_stat.hi, d);
  3253. DUMP_VAR(txq_stat.value, d);
  3254. DUMP_VAR(txq_stat.lo, d);
  3255. DUMP_VAR(ieee->scans, d);
  3256. DUMP_VAR(reset_backoff, d);
  3257. return len;
  3258. }
  3259. static DEVICE_ATTR(internals, S_IRUGO, show_internals, NULL);
  3260. static ssize_t show_bssinfo(struct device *d, struct device_attribute *attr,
  3261. char *buf)
  3262. {
  3263. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3264. char essid[IW_ESSID_MAX_SIZE + 1];
  3265. u8 bssid[ETH_ALEN];
  3266. u32 chan = 0;
  3267. char * out = buf;
  3268. int length;
  3269. int ret;
  3270. memset(essid, 0, sizeof(essid));
  3271. memset(bssid, 0, sizeof(bssid));
  3272. length = IW_ESSID_MAX_SIZE;
  3273. ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_SSID, essid, &length);
  3274. if (ret)
  3275. IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
  3276. __LINE__);
  3277. length = sizeof(bssid);
  3278. ret = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
  3279. bssid, &length);
  3280. if (ret)
  3281. IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
  3282. __LINE__);
  3283. length = sizeof(u32);
  3284. ret = ipw2100_get_ordinal(priv, IPW_ORD_OUR_FREQ, &chan, &length);
  3285. if (ret)
  3286. IPW_DEBUG_INFO("failed querying ordinals at line %d\n",
  3287. __LINE__);
  3288. out += sprintf(out, "ESSID: %s\n", essid);
  3289. out += sprintf(out, "BSSID: %02x:%02x:%02x:%02x:%02x:%02x\n",
  3290. bssid[0], bssid[1], bssid[2],
  3291. bssid[3], bssid[4], bssid[5]);
  3292. out += sprintf(out, "Channel: %d\n", chan);
  3293. return out - buf;
  3294. }
  3295. static DEVICE_ATTR(bssinfo, S_IRUGO, show_bssinfo, NULL);
  3296. #ifdef CONFIG_IPW_DEBUG
  3297. static ssize_t show_debug_level(struct device_driver *d, char *buf)
  3298. {
  3299. return sprintf(buf, "0x%08X\n", ipw2100_debug_level);
  3300. }
  3301. static ssize_t store_debug_level(struct device_driver *d, const char *buf,
  3302. size_t count)
  3303. {
  3304. char *p = (char *)buf;
  3305. u32 val;
  3306. if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
  3307. p++;
  3308. if (p[0] == 'x' || p[0] == 'X')
  3309. p++;
  3310. val = simple_strtoul(p, &p, 16);
  3311. } else
  3312. val = simple_strtoul(p, &p, 10);
  3313. if (p == buf)
  3314. IPW_DEBUG_INFO(DRV_NAME
  3315. ": %s is not in hex or decimal form.\n", buf);
  3316. else
  3317. ipw2100_debug_level = val;
  3318. return strnlen(buf, count);
  3319. }
  3320. static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, show_debug_level,
  3321. store_debug_level);
  3322. #endif /* CONFIG_IPW_DEBUG */
  3323. static ssize_t show_fatal_error(struct device *d,
  3324. struct device_attribute *attr, char *buf)
  3325. {
  3326. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3327. char *out = buf;
  3328. int i;
  3329. if (priv->fatal_error)
  3330. out += sprintf(out, "0x%08X\n",
  3331. priv->fatal_error);
  3332. else
  3333. out += sprintf(out, "0\n");
  3334. for (i = 1; i <= IPW2100_ERROR_QUEUE; i++) {
  3335. if (!priv->fatal_errors[(priv->fatal_index - i) %
  3336. IPW2100_ERROR_QUEUE])
  3337. continue;
  3338. out += sprintf(out, "%d. 0x%08X\n", i,
  3339. priv->fatal_errors[(priv->fatal_index - i) %
  3340. IPW2100_ERROR_QUEUE]);
  3341. }
  3342. return out - buf;
  3343. }
  3344. static ssize_t store_fatal_error(struct device *d,
  3345. struct device_attribute *attr, const char *buf, size_t count)
  3346. {
  3347. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3348. schedule_reset(priv);
  3349. return count;
  3350. }
  3351. static DEVICE_ATTR(fatal_error, S_IWUSR|S_IRUGO, show_fatal_error, store_fatal_error);
  3352. static ssize_t show_scan_age(struct device *d, struct device_attribute *attr,
  3353. char *buf)
  3354. {
  3355. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3356. return sprintf(buf, "%d\n", priv->ieee->scan_age);
  3357. }
  3358. static ssize_t store_scan_age(struct device *d, struct device_attribute *attr,
  3359. const char *buf, size_t count)
  3360. {
  3361. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3362. struct net_device *dev = priv->net_dev;
  3363. char buffer[] = "00000000";
  3364. unsigned long len =
  3365. (sizeof(buffer) - 1) > count ? count : sizeof(buffer) - 1;
  3366. unsigned long val;
  3367. char *p = buffer;
  3368. IPW_DEBUG_INFO("enter\n");
  3369. strncpy(buffer, buf, len);
  3370. buffer[len] = 0;
  3371. if (p[1] == 'x' || p[1] == 'X' || p[0] == 'x' || p[0] == 'X') {
  3372. p++;
  3373. if (p[0] == 'x' || p[0] == 'X')
  3374. p++;
  3375. val = simple_strtoul(p, &p, 16);
  3376. } else
  3377. val = simple_strtoul(p, &p, 10);
  3378. if (p == buffer) {
  3379. IPW_DEBUG_INFO("%s: user supplied invalid value.\n",
  3380. dev->name);
  3381. } else {
  3382. priv->ieee->scan_age = val;
  3383. IPW_DEBUG_INFO("set scan_age = %u\n", priv->ieee->scan_age);
  3384. }
  3385. IPW_DEBUG_INFO("exit\n");
  3386. return len;
  3387. }
  3388. static DEVICE_ATTR(scan_age, S_IWUSR | S_IRUGO, show_scan_age, store_scan_age);
  3389. static ssize_t show_rf_kill(struct device *d, struct device_attribute *attr,
  3390. char *buf)
  3391. {
  3392. /* 0 - RF kill not enabled
  3393. 1 - SW based RF kill active (sysfs)
  3394. 2 - HW based RF kill active
  3395. 3 - Both HW and SW baed RF kill active */
  3396. struct ipw2100_priv *priv = (struct ipw2100_priv *)d->driver_data;
  3397. int val = ((priv->status & STATUS_RF_KILL_SW) ? 0x1 : 0x0) |
  3398. (rf_kill_active(priv) ? 0x2 : 0x0);
  3399. return sprintf(buf, "%i\n", val);
  3400. }
  3401. static int ipw_radio_kill_sw(struct ipw2100_priv *priv, int disable_radio)
  3402. {
  3403. if ((disable_radio ? 1 : 0) ==
  3404. (priv->status & STATUS_RF_KILL_SW ? 1 : 0))
  3405. return 0 ;
  3406. IPW_DEBUG_RF_KILL("Manual SW RF Kill set to: RADIO %s\n",
  3407. disable_radio ? "OFF" : "ON");
  3408. down(&priv->action_sem);
  3409. if (disable_radio) {
  3410. priv->status |= STATUS_RF_KILL_SW;
  3411. ipw2100_down(priv);
  3412. } else {
  3413. priv->status &= ~STATUS_RF_KILL_SW;
  3414. if (rf_kill_active(priv)) {
  3415. IPW_DEBUG_RF_KILL("Can not turn radio back on - "
  3416. "disabled by HW switch\n");
  3417. /* Make sure the RF_KILL check timer is running */
  3418. priv->stop_rf_kill = 0;
  3419. cancel_delayed_work(&priv->rf_kill);
  3420. queue_delayed_work(priv->workqueue, &priv->rf_kill,
  3421. HZ);
  3422. } else
  3423. schedule_reset(priv);
  3424. }
  3425. up(&priv->action_sem);
  3426. return 1;
  3427. }
  3428. static ssize_t store_rf_kill(struct device *d, struct device_attribute *attr,
  3429. const char *buf, size_t count)
  3430. {
  3431. struct ipw2100_priv *priv = dev_get_drvdata(d);
  3432. ipw_radio_kill_sw(priv, buf[0] == '1');
  3433. return count;
  3434. }
  3435. static DEVICE_ATTR(rf_kill, S_IWUSR|S_IRUGO, show_rf_kill, store_rf_kill);
  3436. static struct attribute *ipw2100_sysfs_entries[] = {
  3437. &dev_attr_hardware.attr,
  3438. &dev_attr_registers.attr,
  3439. &dev_attr_ordinals.attr,
  3440. &dev_attr_pci.attr,
  3441. &dev_attr_stats.attr,
  3442. &dev_attr_internals.attr,
  3443. &dev_attr_bssinfo.attr,
  3444. &dev_attr_memory.attr,
  3445. &dev_attr_scan_age.attr,
  3446. &dev_attr_fatal_error.attr,
  3447. &dev_attr_rf_kill.attr,
  3448. &dev_attr_cfg.attr,
  3449. &dev_attr_status.attr,
  3450. &dev_attr_capability.attr,
  3451. NULL,
  3452. };
  3453. static struct attribute_group ipw2100_attribute_group = {
  3454. .attrs = ipw2100_sysfs_entries,
  3455. };
  3456. static int status_queue_allocate(struct ipw2100_priv *priv, int entries)
  3457. {
  3458. struct ipw2100_status_queue *q = &priv->status_queue;
  3459. IPW_DEBUG_INFO("enter\n");
  3460. q->size = entries * sizeof(struct ipw2100_status);
  3461. q->drv = (struct ipw2100_status *)pci_alloc_consistent(
  3462. priv->pci_dev, q->size, &q->nic);
  3463. if (!q->drv) {
  3464. IPW_DEBUG_WARNING(
  3465. "Can not allocate status queue.\n");
  3466. return -ENOMEM;
  3467. }
  3468. memset(q->drv, 0, q->size);
  3469. IPW_DEBUG_INFO("exit\n");
  3470. return 0;
  3471. }
  3472. static void status_queue_free(struct ipw2100_priv *priv)
  3473. {
  3474. IPW_DEBUG_INFO("enter\n");
  3475. if (priv->status_queue.drv) {
  3476. pci_free_consistent(
  3477. priv->pci_dev, priv->status_queue.size,
  3478. priv->status_queue.drv, priv->status_queue.nic);
  3479. priv->status_queue.drv = NULL;
  3480. }
  3481. IPW_DEBUG_INFO("exit\n");
  3482. }
  3483. static int bd_queue_allocate(struct ipw2100_priv *priv,
  3484. struct ipw2100_bd_queue *q, int entries)
  3485. {
  3486. IPW_DEBUG_INFO("enter\n");
  3487. memset(q, 0, sizeof(struct ipw2100_bd_queue));
  3488. q->entries = entries;
  3489. q->size = entries * sizeof(struct ipw2100_bd);
  3490. q->drv = pci_alloc_consistent(priv->pci_dev, q->size, &q->nic);
  3491. if (!q->drv) {
  3492. IPW_DEBUG_INFO("can't allocate shared memory for buffer descriptors\n");
  3493. return -ENOMEM;
  3494. }
  3495. memset(q->drv, 0, q->size);
  3496. IPW_DEBUG_INFO("exit\n");
  3497. return 0;
  3498. }
  3499. static void bd_queue_free(struct ipw2100_priv *priv,
  3500. struct ipw2100_bd_queue *q)
  3501. {
  3502. IPW_DEBUG_INFO("enter\n");
  3503. if (!q)
  3504. return;
  3505. if (q->drv) {
  3506. pci_free_consistent(priv->pci_dev,
  3507. q->size, q->drv, q->nic);
  3508. q->drv = NULL;
  3509. }
  3510. IPW_DEBUG_INFO("exit\n");
  3511. }
  3512. static void bd_queue_initialize(
  3513. struct ipw2100_priv *priv, struct ipw2100_bd_queue * q,
  3514. u32 base, u32 size, u32 r, u32 w)
  3515. {
  3516. IPW_DEBUG_INFO("enter\n");
  3517. IPW_DEBUG_INFO("initializing bd queue at virt=%p, phys=%08x\n", q->drv, (u32)q->nic);
  3518. write_register(priv->net_dev, base, q->nic);
  3519. write_register(priv->net_dev, size, q->entries);
  3520. write_register(priv->net_dev, r, q->oldest);
  3521. write_register(priv->net_dev, w, q->next);
  3522. IPW_DEBUG_INFO("exit\n");
  3523. }
  3524. static void ipw2100_kill_workqueue(struct ipw2100_priv *priv)
  3525. {
  3526. if (priv->workqueue) {
  3527. priv->stop_rf_kill = 1;
  3528. priv->stop_hang_check = 1;
  3529. cancel_delayed_work(&priv->reset_work);
  3530. cancel_delayed_work(&priv->security_work);
  3531. cancel_delayed_work(&priv->wx_event_work);
  3532. cancel_delayed_work(&priv->hang_check);
  3533. cancel_delayed_work(&priv->rf_kill);
  3534. destroy_workqueue(priv->workqueue);
  3535. priv->workqueue = NULL;
  3536. }
  3537. }
  3538. static int ipw2100_tx_allocate(struct ipw2100_priv *priv)
  3539. {
  3540. int i, j, err = -EINVAL;
  3541. void *v;
  3542. dma_addr_t p;
  3543. IPW_DEBUG_INFO("enter\n");
  3544. err = bd_queue_allocate(priv, &priv->tx_queue, TX_QUEUE_LENGTH);
  3545. if (err) {
  3546. IPW_DEBUG_ERROR("%s: failed bd_queue_allocate\n",
  3547. priv->net_dev->name);
  3548. return err;
  3549. }
  3550. priv->tx_buffers = (struct ipw2100_tx_packet *)kmalloc(
  3551. TX_PENDED_QUEUE_LENGTH * sizeof(struct ipw2100_tx_packet),
  3552. GFP_ATOMIC);
  3553. if (!priv->tx_buffers) {
  3554. printk(KERN_ERR DRV_NAME ": %s: alloc failed form tx buffers.\n",
  3555. priv->net_dev->name);
  3556. bd_queue_free(priv, &priv->tx_queue);
  3557. return -ENOMEM;
  3558. }
  3559. for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
  3560. v = pci_alloc_consistent(
  3561. priv->pci_dev, sizeof(struct ipw2100_data_header), &p);
  3562. if (!v) {
  3563. printk(KERN_ERR DRV_NAME ": %s: PCI alloc failed for tx "
  3564. "buffers.\n", priv->net_dev->name);
  3565. err = -ENOMEM;
  3566. break;
  3567. }
  3568. priv->tx_buffers[i].type = DATA;
  3569. priv->tx_buffers[i].info.d_struct.data = (struct ipw2100_data_header*)v;
  3570. priv->tx_buffers[i].info.d_struct.data_phys = p;
  3571. priv->tx_buffers[i].info.d_struct.txb = NULL;
  3572. }
  3573. if (i == TX_PENDED_QUEUE_LENGTH)
  3574. return 0;
  3575. for (j = 0; j < i; j++) {
  3576. pci_free_consistent(
  3577. priv->pci_dev,
  3578. sizeof(struct ipw2100_data_header),
  3579. priv->tx_buffers[j].info.d_struct.data,
  3580. priv->tx_buffers[j].info.d_struct.data_phys);
  3581. }
  3582. kfree(priv->tx_buffers);
  3583. priv->tx_buffers = NULL;
  3584. return err;
  3585. }
  3586. static void ipw2100_tx_initialize(struct ipw2100_priv *priv)
  3587. {
  3588. int i;
  3589. IPW_DEBUG_INFO("enter\n");
  3590. /*
  3591. * reinitialize packet info lists
  3592. */
  3593. INIT_LIST_HEAD(&priv->fw_pend_list);
  3594. INIT_STAT(&priv->fw_pend_stat);
  3595. /*
  3596. * reinitialize lists
  3597. */
  3598. INIT_LIST_HEAD(&priv->tx_pend_list);
  3599. INIT_LIST_HEAD(&priv->tx_free_list);
  3600. INIT_STAT(&priv->tx_pend_stat);
  3601. INIT_STAT(&priv->tx_free_stat);
  3602. for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
  3603. /* We simply drop any SKBs that have been queued for
  3604. * transmit */
  3605. if (priv->tx_buffers[i].info.d_struct.txb) {
  3606. ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.txb);
  3607. priv->tx_buffers[i].info.d_struct.txb = NULL;
  3608. }
  3609. list_add_tail(&priv->tx_buffers[i].list, &priv->tx_free_list);
  3610. }
  3611. SET_STAT(&priv->tx_free_stat, i);
  3612. priv->tx_queue.oldest = 0;
  3613. priv->tx_queue.available = priv->tx_queue.entries;
  3614. priv->tx_queue.next = 0;
  3615. INIT_STAT(&priv->txq_stat);
  3616. SET_STAT(&priv->txq_stat, priv->tx_queue.available);
  3617. bd_queue_initialize(priv, &priv->tx_queue,
  3618. IPW_MEM_HOST_SHARED_TX_QUEUE_BD_BASE,
  3619. IPW_MEM_HOST_SHARED_TX_QUEUE_BD_SIZE,
  3620. IPW_MEM_HOST_SHARED_TX_QUEUE_READ_INDEX,
  3621. IPW_MEM_HOST_SHARED_TX_QUEUE_WRITE_INDEX);
  3622. IPW_DEBUG_INFO("exit\n");
  3623. }
  3624. static void ipw2100_tx_free(struct ipw2100_priv *priv)
  3625. {
  3626. int i;
  3627. IPW_DEBUG_INFO("enter\n");
  3628. bd_queue_free(priv, &priv->tx_queue);
  3629. if (!priv->tx_buffers)
  3630. return;
  3631. for (i = 0; i < TX_PENDED_QUEUE_LENGTH; i++) {
  3632. if (priv->tx_buffers[i].info.d_struct.txb) {
  3633. ieee80211_txb_free(priv->tx_buffers[i].info.d_struct.txb);
  3634. priv->tx_buffers[i].info.d_struct.txb = NULL;
  3635. }
  3636. if (priv->tx_buffers[i].info.d_struct.data)
  3637. pci_free_consistent(
  3638. priv->pci_dev,
  3639. sizeof(struct ipw2100_data_header),
  3640. priv->tx_buffers[i].info.d_struct.data,
  3641. priv->tx_buffers[i].info.d_struct.data_phys);
  3642. }
  3643. kfree(priv->tx_buffers);
  3644. priv->tx_buffers = NULL;
  3645. IPW_DEBUG_INFO("exit\n");
  3646. }
  3647. static int ipw2100_rx_allocate(struct ipw2100_priv *priv)
  3648. {
  3649. int i, j, err = -EINVAL;
  3650. IPW_DEBUG_INFO("enter\n");
  3651. err = bd_queue_allocate(priv, &priv->rx_queue, RX_QUEUE_LENGTH);
  3652. if (err) {
  3653. IPW_DEBUG_INFO("failed bd_queue_allocate\n");
  3654. return err;
  3655. }
  3656. err = status_queue_allocate(priv, RX_QUEUE_LENGTH);
  3657. if (err) {
  3658. IPW_DEBUG_INFO("failed status_queue_allocate\n");
  3659. bd_queue_free(priv, &priv->rx_queue);
  3660. return err;
  3661. }
  3662. /*
  3663. * allocate packets
  3664. */
  3665. priv->rx_buffers = (struct ipw2100_rx_packet *)
  3666. kmalloc(RX_QUEUE_LENGTH * sizeof(struct ipw2100_rx_packet),
  3667. GFP_KERNEL);
  3668. if (!priv->rx_buffers) {
  3669. IPW_DEBUG_INFO("can't allocate rx packet buffer table\n");
  3670. bd_queue_free(priv, &priv->rx_queue);
  3671. status_queue_free(priv);
  3672. return -ENOMEM;
  3673. }
  3674. for (i = 0; i < RX_QUEUE_LENGTH; i++) {
  3675. struct ipw2100_rx_packet *packet = &priv->rx_buffers[i];
  3676. err = ipw2100_alloc_skb(priv, packet);
  3677. if (unlikely(err)) {
  3678. err = -ENOMEM;
  3679. break;
  3680. }
  3681. /* The BD holds the cache aligned address */
  3682. priv->rx_queue.drv[i].host_addr = packet->dma_addr;
  3683. priv->rx_queue.drv[i].buf_length = IPW_RX_NIC_BUFFER_LENGTH;
  3684. priv->status_queue.drv[i].status_fields = 0;
  3685. }
  3686. if (i == RX_QUEUE_LENGTH)
  3687. return 0;
  3688. for (j = 0; j < i; j++) {
  3689. pci_unmap_single(priv->pci_dev, priv->rx_buffers[j].dma_addr,
  3690. sizeof(struct ipw2100_rx_packet),
  3691. PCI_DMA_FROMDEVICE);
  3692. dev_kfree_skb(priv->rx_buffers[j].skb);
  3693. }
  3694. kfree(priv->rx_buffers);
  3695. priv->rx_buffers = NULL;
  3696. bd_queue_free(priv, &priv->rx_queue);
  3697. status_queue_free(priv);
  3698. return err;
  3699. }
  3700. static void ipw2100_rx_initialize(struct ipw2100_priv *priv)
  3701. {
  3702. IPW_DEBUG_INFO("enter\n");
  3703. priv->rx_queue.oldest = 0;
  3704. priv->rx_queue.available = priv->rx_queue.entries - 1;
  3705. priv->rx_queue.next = priv->rx_queue.entries - 1;
  3706. INIT_STAT(&priv->rxq_stat);
  3707. SET_STAT(&priv->rxq_stat, priv->rx_queue.available);
  3708. bd_queue_initialize(priv, &priv->rx_queue,
  3709. IPW_MEM_HOST_SHARED_RX_BD_BASE,
  3710. IPW_MEM_HOST_SHARED_RX_BD_SIZE,
  3711. IPW_MEM_HOST_SHARED_RX_READ_INDEX,
  3712. IPW_MEM_HOST_SHARED_RX_WRITE_INDEX);
  3713. /* set up the status queue */
  3714. write_register(priv->net_dev, IPW_MEM_HOST_SHARED_RX_STATUS_BASE,
  3715. priv->status_queue.nic);
  3716. IPW_DEBUG_INFO("exit\n");
  3717. }
  3718. static void ipw2100_rx_free(struct ipw2100_priv *priv)
  3719. {
  3720. int i;
  3721. IPW_DEBUG_INFO("enter\n");
  3722. bd_queue_free(priv, &priv->rx_queue);
  3723. status_queue_free(priv);
  3724. if (!priv->rx_buffers)
  3725. return;
  3726. for (i = 0; i < RX_QUEUE_LENGTH; i++) {
  3727. if (priv->rx_buffers[i].rxp) {
  3728. pci_unmap_single(priv->pci_dev,
  3729. priv->rx_buffers[i].dma_addr,
  3730. sizeof(struct ipw2100_rx),
  3731. PCI_DMA_FROMDEVICE);
  3732. dev_kfree_skb(priv->rx_buffers[i].skb);
  3733. }
  3734. }
  3735. kfree(priv->rx_buffers);
  3736. priv->rx_buffers = NULL;
  3737. IPW_DEBUG_INFO("exit\n");
  3738. }
  3739. static int ipw2100_read_mac_address(struct ipw2100_priv *priv)
  3740. {
  3741. u32 length = ETH_ALEN;
  3742. u8 mac[ETH_ALEN];
  3743. int err;
  3744. err = ipw2100_get_ordinal(priv, IPW_ORD_STAT_ADAPTER_MAC,
  3745. mac, &length);
  3746. if (err) {
  3747. IPW_DEBUG_INFO("MAC address read failed\n");
  3748. return -EIO;
  3749. }
  3750. IPW_DEBUG_INFO("card MAC is %02X:%02X:%02X:%02X:%02X:%02X\n",
  3751. mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  3752. memcpy(priv->net_dev->dev_addr, mac, ETH_ALEN);
  3753. return 0;
  3754. }
  3755. /********************************************************************
  3756. *
  3757. * Firmware Commands
  3758. *
  3759. ********************************************************************/
  3760. static int ipw2100_set_mac_address(struct ipw2100_priv *priv, int batch_mode)
  3761. {
  3762. struct host_command cmd = {
  3763. .host_command = ADAPTER_ADDRESS,
  3764. .host_command_sequence = 0,
  3765. .host_command_length = ETH_ALEN
  3766. };
  3767. int err;
  3768. IPW_DEBUG_HC("SET_MAC_ADDRESS\n");
  3769. IPW_DEBUG_INFO("enter\n");
  3770. if (priv->config & CFG_CUSTOM_MAC) {
  3771. memcpy(cmd.host_command_parameters, priv->mac_addr,
  3772. ETH_ALEN);
  3773. memcpy(priv->net_dev->dev_addr, priv->mac_addr, ETH_ALEN);
  3774. } else
  3775. memcpy(cmd.host_command_parameters, priv->net_dev->dev_addr,
  3776. ETH_ALEN);
  3777. err = ipw2100_hw_send_command(priv, &cmd);
  3778. IPW_DEBUG_INFO("exit\n");
  3779. return err;
  3780. }
  3781. static int ipw2100_set_port_type(struct ipw2100_priv *priv, u32 port_type,
  3782. int batch_mode)
  3783. {
  3784. struct host_command cmd = {
  3785. .host_command = PORT_TYPE,
  3786. .host_command_sequence = 0,
  3787. .host_command_length = sizeof(u32)
  3788. };
  3789. int err;
  3790. switch (port_type) {
  3791. case IW_MODE_INFRA:
  3792. cmd.host_command_parameters[0] = IPW_BSS;
  3793. break;
  3794. case IW_MODE_ADHOC:
  3795. cmd.host_command_parameters[0] = IPW_IBSS;
  3796. break;
  3797. }
  3798. IPW_DEBUG_HC("PORT_TYPE: %s\n",
  3799. port_type == IPW_IBSS ? "Ad-Hoc" : "Managed");
  3800. if (!batch_mode) {
  3801. err = ipw2100_disable_adapter(priv);
  3802. if (err) {
  3803. printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
  3804. priv->net_dev->name, err);
  3805. return err;
  3806. }
  3807. }
  3808. /* send cmd to firmware */
  3809. err = ipw2100_hw_send_command(priv, &cmd);
  3810. if (!batch_mode)
  3811. ipw2100_enable_adapter(priv);
  3812. return err;
  3813. }
  3814. static int ipw2100_set_channel(struct ipw2100_priv *priv, u32 channel,
  3815. int batch_mode)
  3816. {
  3817. struct host_command cmd = {
  3818. .host_command = CHANNEL,
  3819. .host_command_sequence = 0,
  3820. .host_command_length = sizeof(u32)
  3821. };
  3822. int err;
  3823. cmd.host_command_parameters[0] = channel;
  3824. IPW_DEBUG_HC("CHANNEL: %d\n", channel);
  3825. /* If BSS then we don't support channel selection */
  3826. if (priv->ieee->iw_mode == IW_MODE_INFRA)
  3827. return 0;
  3828. if ((channel != 0) &&
  3829. ((channel < REG_MIN_CHANNEL) || (channel > REG_MAX_CHANNEL)))
  3830. return -EINVAL;
  3831. if (!batch_mode) {
  3832. err = ipw2100_disable_adapter(priv);
  3833. if (err)
  3834. return err;
  3835. }
  3836. err = ipw2100_hw_send_command(priv, &cmd);
  3837. if (err) {
  3838. IPW_DEBUG_INFO("Failed to set channel to %d",
  3839. channel);
  3840. return err;
  3841. }
  3842. if (channel)
  3843. priv->config |= CFG_STATIC_CHANNEL;
  3844. else
  3845. priv->config &= ~CFG_STATIC_CHANNEL;
  3846. priv->channel = channel;
  3847. if (!batch_mode) {
  3848. err = ipw2100_enable_adapter(priv);
  3849. if (err)
  3850. return err;
  3851. }
  3852. return 0;
  3853. }
  3854. static int ipw2100_system_config(struct ipw2100_priv *priv, int batch_mode)
  3855. {
  3856. struct host_command cmd = {
  3857. .host_command = SYSTEM_CONFIG,
  3858. .host_command_sequence = 0,
  3859. .host_command_length = 12,
  3860. };
  3861. u32 ibss_mask, len = sizeof(u32);
  3862. int err;
  3863. /* Set system configuration */
  3864. if (!batch_mode) {
  3865. err = ipw2100_disable_adapter(priv);
  3866. if (err)
  3867. return err;
  3868. }
  3869. if (priv->ieee->iw_mode == IW_MODE_ADHOC)
  3870. cmd.host_command_parameters[0] |= IPW_CFG_IBSS_AUTO_START;
  3871. cmd.host_command_parameters[0] |= IPW_CFG_IBSS_MASK |
  3872. IPW_CFG_BSS_MASK |
  3873. IPW_CFG_802_1x_ENABLE;
  3874. if (!(priv->config & CFG_LONG_PREAMBLE))
  3875. cmd.host_command_parameters[0] |= IPW_CFG_PREAMBLE_AUTO;
  3876. err = ipw2100_get_ordinal(priv,
  3877. IPW_ORD_EEPROM_IBSS_11B_CHANNELS,
  3878. &ibss_mask, &len);
  3879. if (err)
  3880. ibss_mask = IPW_IBSS_11B_DEFAULT_MASK;
  3881. cmd.host_command_parameters[1] = REG_CHANNEL_MASK;
  3882. cmd.host_command_parameters[2] = REG_CHANNEL_MASK & ibss_mask;
  3883. /* 11b only */
  3884. /*cmd.host_command_parameters[0] |= DIVERSITY_ANTENNA_A;*/
  3885. err = ipw2100_hw_send_command(priv, &cmd);
  3886. if (err)
  3887. return err;
  3888. /* If IPv6 is configured in the kernel then we don't want to filter out all
  3889. * of the multicast packets as IPv6 needs some. */
  3890. #if !defined(CONFIG_IPV6) && !defined(CONFIG_IPV6_MODULE)
  3891. cmd.host_command = ADD_MULTICAST;
  3892. cmd.host_command_sequence = 0;
  3893. cmd.host_command_length = 0;
  3894. ipw2100_hw_send_command(priv, &cmd);
  3895. #endif
  3896. if (!batch_mode) {
  3897. err = ipw2100_enable_adapter(priv);
  3898. if (err)
  3899. return err;
  3900. }
  3901. return 0;
  3902. }
  3903. static int ipw2100_set_tx_rates(struct ipw2100_priv *priv, u32 rate,
  3904. int batch_mode)
  3905. {
  3906. struct host_command cmd = {
  3907. .host_command = BASIC_TX_RATES,
  3908. .host_command_sequence = 0,
  3909. .host_command_length = 4
  3910. };
  3911. int err;
  3912. cmd.host_command_parameters[0] = rate & TX_RATE_MASK;
  3913. if (!batch_mode) {
  3914. err = ipw2100_disable_adapter(priv);
  3915. if (err)
  3916. return err;
  3917. }
  3918. /* Set BASIC TX Rate first */
  3919. ipw2100_hw_send_command(priv, &cmd);
  3920. /* Set TX Rate */
  3921. cmd.host_command = TX_RATES;
  3922. ipw2100_hw_send_command(priv, &cmd);
  3923. /* Set MSDU TX Rate */
  3924. cmd.host_command = MSDU_TX_RATES;
  3925. ipw2100_hw_send_command(priv, &cmd);
  3926. if (!batch_mode) {
  3927. err = ipw2100_enable_adapter(priv);
  3928. if (err)
  3929. return err;
  3930. }
  3931. priv->tx_rates = rate;
  3932. return 0;
  3933. }
  3934. static int ipw2100_set_power_mode(struct ipw2100_priv *priv,
  3935. int power_level)
  3936. {
  3937. struct host_command cmd = {
  3938. .host_command = POWER_MODE,
  3939. .host_command_sequence = 0,
  3940. .host_command_length = 4
  3941. };
  3942. int err;
  3943. cmd.host_command_parameters[0] = power_level;
  3944. err = ipw2100_hw_send_command(priv, &cmd);
  3945. if (err)
  3946. return err;
  3947. if (power_level == IPW_POWER_MODE_CAM)
  3948. priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
  3949. else
  3950. priv->power_mode = IPW_POWER_ENABLED | power_level;
  3951. #ifdef CONFIG_IPW2100_TX_POWER
  3952. if (priv->port_type == IBSS &&
  3953. priv->adhoc_power != DFTL_IBSS_TX_POWER) {
  3954. /* Set beacon interval */
  3955. cmd.host_command = TX_POWER_INDEX;
  3956. cmd.host_command_parameters[0] = (u32)priv->adhoc_power;
  3957. err = ipw2100_hw_send_command(priv, &cmd);
  3958. if (err)
  3959. return err;
  3960. }
  3961. #endif
  3962. return 0;
  3963. }
  3964. static int ipw2100_set_rts_threshold(struct ipw2100_priv *priv, u32 threshold)
  3965. {
  3966. struct host_command cmd = {
  3967. .host_command = RTS_THRESHOLD,
  3968. .host_command_sequence = 0,
  3969. .host_command_length = 4
  3970. };
  3971. int err;
  3972. if (threshold & RTS_DISABLED)
  3973. cmd.host_command_parameters[0] = MAX_RTS_THRESHOLD;
  3974. else
  3975. cmd.host_command_parameters[0] = threshold & ~RTS_DISABLED;
  3976. err = ipw2100_hw_send_command(priv, &cmd);
  3977. if (err)
  3978. return err;
  3979. priv->rts_threshold = threshold;
  3980. return 0;
  3981. }
  3982. #if 0
  3983. int ipw2100_set_fragmentation_threshold(struct ipw2100_priv *priv,
  3984. u32 threshold, int batch_mode)
  3985. {
  3986. struct host_command cmd = {
  3987. .host_command = FRAG_THRESHOLD,
  3988. .host_command_sequence = 0,
  3989. .host_command_length = 4,
  3990. .host_command_parameters[0] = 0,
  3991. };
  3992. int err;
  3993. if (!batch_mode) {
  3994. err = ipw2100_disable_adapter(priv);
  3995. if (err)
  3996. return err;
  3997. }
  3998. if (threshold == 0)
  3999. threshold = DEFAULT_FRAG_THRESHOLD;
  4000. else {
  4001. threshold = max(threshold, MIN_FRAG_THRESHOLD);
  4002. threshold = min(threshold, MAX_FRAG_THRESHOLD);
  4003. }
  4004. cmd.host_command_parameters[0] = threshold;
  4005. IPW_DEBUG_HC("FRAG_THRESHOLD: %u\n", threshold);
  4006. err = ipw2100_hw_send_command(priv, &cmd);
  4007. if (!batch_mode)
  4008. ipw2100_enable_adapter(priv);
  4009. if (!err)
  4010. priv->frag_threshold = threshold;
  4011. return err;
  4012. }
  4013. #endif
  4014. static int ipw2100_set_short_retry(struct ipw2100_priv *priv, u32 retry)
  4015. {
  4016. struct host_command cmd = {
  4017. .host_command = SHORT_RETRY_LIMIT,
  4018. .host_command_sequence = 0,
  4019. .host_command_length = 4
  4020. };
  4021. int err;
  4022. cmd.host_command_parameters[0] = retry;
  4023. err = ipw2100_hw_send_command(priv, &cmd);
  4024. if (err)
  4025. return err;
  4026. priv->short_retry_limit = retry;
  4027. return 0;
  4028. }
  4029. static int ipw2100_set_long_retry(struct ipw2100_priv *priv, u32 retry)
  4030. {
  4031. struct host_command cmd = {
  4032. .host_command = LONG_RETRY_LIMIT,
  4033. .host_command_sequence = 0,
  4034. .host_command_length = 4
  4035. };
  4036. int err;
  4037. cmd.host_command_parameters[0] = retry;
  4038. err = ipw2100_hw_send_command(priv, &cmd);
  4039. if (err)
  4040. return err;
  4041. priv->long_retry_limit = retry;
  4042. return 0;
  4043. }
  4044. static int ipw2100_set_mandatory_bssid(struct ipw2100_priv *priv, u8 *bssid,
  4045. int batch_mode)
  4046. {
  4047. struct host_command cmd = {
  4048. .host_command = MANDATORY_BSSID,
  4049. .host_command_sequence = 0,
  4050. .host_command_length = (bssid == NULL) ? 0 : ETH_ALEN
  4051. };
  4052. int err;
  4053. #ifdef CONFIG_IPW_DEBUG
  4054. if (bssid != NULL)
  4055. IPW_DEBUG_HC(
  4056. "MANDATORY_BSSID: %02X:%02X:%02X:%02X:%02X:%02X\n",
  4057. bssid[0], bssid[1], bssid[2], bssid[3], bssid[4],
  4058. bssid[5]);
  4059. else
  4060. IPW_DEBUG_HC("MANDATORY_BSSID: <clear>\n");
  4061. #endif
  4062. /* if BSSID is empty then we disable mandatory bssid mode */
  4063. if (bssid != NULL)
  4064. memcpy((u8 *)cmd.host_command_parameters, bssid, ETH_ALEN);
  4065. if (!batch_mode) {
  4066. err = ipw2100_disable_adapter(priv);
  4067. if (err)
  4068. return err;
  4069. }
  4070. err = ipw2100_hw_send_command(priv, &cmd);
  4071. if (!batch_mode)
  4072. ipw2100_enable_adapter(priv);
  4073. return err;
  4074. }
  4075. #ifdef CONFIG_IEEE80211_WPA
  4076. static int ipw2100_disassociate_bssid(struct ipw2100_priv *priv)
  4077. {
  4078. struct host_command cmd = {
  4079. .host_command = DISASSOCIATION_BSSID,
  4080. .host_command_sequence = 0,
  4081. .host_command_length = ETH_ALEN
  4082. };
  4083. int err;
  4084. int len;
  4085. IPW_DEBUG_HC("DISASSOCIATION_BSSID\n");
  4086. len = ETH_ALEN;
  4087. /* The Firmware currently ignores the BSSID and just disassociates from
  4088. * the currently associated AP -- but in the off chance that a future
  4089. * firmware does use the BSSID provided here, we go ahead and try and
  4090. * set it to the currently associated AP's BSSID */
  4091. memcpy(cmd.host_command_parameters, priv->bssid, ETH_ALEN);
  4092. err = ipw2100_hw_send_command(priv, &cmd);
  4093. return err;
  4094. }
  4095. #endif
  4096. /*
  4097. * Pseudo code for setting up wpa_frame:
  4098. */
  4099. #if 0
  4100. void x(struct ieee80211_assoc_frame *wpa_assoc)
  4101. {
  4102. struct ipw2100_wpa_assoc_frame frame;
  4103. frame->fixed_ie_mask = IPW_WPA_CAPABILTIES |
  4104. IPW_WPA_LISTENINTERVAL |
  4105. IPW_WPA_AP_ADDRESS;
  4106. frame->capab_info = wpa_assoc->capab_info;
  4107. frame->lisen_interval = wpa_assoc->listent_interval;
  4108. memcpy(frame->current_ap, wpa_assoc->current_ap, ETH_ALEN);
  4109. /* UNKNOWN -- I'm not postivive about this part; don't have any WPA
  4110. * setup here to test it with.
  4111. *
  4112. * Walk the IEs in the wpa_assoc and figure out the total size of all
  4113. * that data. Stick that into frame->var_ie_len. Then memcpy() all of
  4114. * the IEs from wpa_frame into frame.
  4115. */
  4116. frame->var_ie_len = calculate_ie_len(wpa_assoc);
  4117. memcpy(frame->var_ie, wpa_assoc->variable, frame->var_ie_len);
  4118. ipw2100_set_wpa_ie(priv, &frame, 0);
  4119. }
  4120. #endif
  4121. static int ipw2100_set_wpa_ie(struct ipw2100_priv *,
  4122. struct ipw2100_wpa_assoc_frame *, int)
  4123. __attribute__ ((unused));
  4124. static int ipw2100_set_wpa_ie(struct ipw2100_priv *priv,
  4125. struct ipw2100_wpa_assoc_frame *wpa_frame,
  4126. int batch_mode)
  4127. {
  4128. struct host_command cmd = {
  4129. .host_command = SET_WPA_IE,
  4130. .host_command_sequence = 0,
  4131. .host_command_length = sizeof(struct ipw2100_wpa_assoc_frame),
  4132. };
  4133. int err;
  4134. IPW_DEBUG_HC("SET_WPA_IE\n");
  4135. if (!batch_mode) {
  4136. err = ipw2100_disable_adapter(priv);
  4137. if (err)
  4138. return err;
  4139. }
  4140. memcpy(cmd.host_command_parameters, wpa_frame,
  4141. sizeof(struct ipw2100_wpa_assoc_frame));
  4142. err = ipw2100_hw_send_command(priv, &cmd);
  4143. if (!batch_mode) {
  4144. if (ipw2100_enable_adapter(priv))
  4145. err = -EIO;
  4146. }
  4147. return err;
  4148. }
  4149. struct security_info_params {
  4150. u32 allowed_ciphers;
  4151. u16 version;
  4152. u8 auth_mode;
  4153. u8 replay_counters_number;
  4154. u8 unicast_using_group;
  4155. } __attribute__ ((packed));
  4156. static int ipw2100_set_security_information(struct ipw2100_priv *priv,
  4157. int auth_mode,
  4158. int security_level,
  4159. int unicast_using_group,
  4160. int batch_mode)
  4161. {
  4162. struct host_command cmd = {
  4163. .host_command = SET_SECURITY_INFORMATION,
  4164. .host_command_sequence = 0,
  4165. .host_command_length = sizeof(struct security_info_params)
  4166. };
  4167. struct security_info_params *security =
  4168. (struct security_info_params *)&cmd.host_command_parameters;
  4169. int err;
  4170. memset(security, 0, sizeof(*security));
  4171. /* If shared key AP authentication is turned on, then we need to
  4172. * configure the firmware to try and use it.
  4173. *
  4174. * Actual data encryption/decryption is handled by the host. */
  4175. security->auth_mode = auth_mode;
  4176. security->unicast_using_group = unicast_using_group;
  4177. switch (security_level) {
  4178. default:
  4179. case SEC_LEVEL_0:
  4180. security->allowed_ciphers = IPW_NONE_CIPHER;
  4181. break;
  4182. case SEC_LEVEL_1:
  4183. security->allowed_ciphers = IPW_WEP40_CIPHER |
  4184. IPW_WEP104_CIPHER;
  4185. break;
  4186. case SEC_LEVEL_2:
  4187. security->allowed_ciphers = IPW_WEP40_CIPHER |
  4188. IPW_WEP104_CIPHER | IPW_TKIP_CIPHER;
  4189. break;
  4190. case SEC_LEVEL_2_CKIP:
  4191. security->allowed_ciphers = IPW_WEP40_CIPHER |
  4192. IPW_WEP104_CIPHER | IPW_CKIP_CIPHER;
  4193. break;
  4194. case SEC_LEVEL_3:
  4195. security->allowed_ciphers = IPW_WEP40_CIPHER |
  4196. IPW_WEP104_CIPHER | IPW_TKIP_CIPHER | IPW_CCMP_CIPHER;
  4197. break;
  4198. }
  4199. IPW_DEBUG_HC(
  4200. "SET_SECURITY_INFORMATION: auth:%d cipher:0x%02X (level %d)\n",
  4201. security->auth_mode, security->allowed_ciphers, security_level);
  4202. security->replay_counters_number = 0;
  4203. if (!batch_mode) {
  4204. err = ipw2100_disable_adapter(priv);
  4205. if (err)
  4206. return err;
  4207. }
  4208. err = ipw2100_hw_send_command(priv, &cmd);
  4209. if (!batch_mode)
  4210. ipw2100_enable_adapter(priv);
  4211. return err;
  4212. }
  4213. static int ipw2100_set_tx_power(struct ipw2100_priv *priv,
  4214. u32 tx_power)
  4215. {
  4216. struct host_command cmd = {
  4217. .host_command = TX_POWER_INDEX,
  4218. .host_command_sequence = 0,
  4219. .host_command_length = 4
  4220. };
  4221. int err = 0;
  4222. cmd.host_command_parameters[0] = tx_power;
  4223. if (priv->ieee->iw_mode == IW_MODE_ADHOC)
  4224. err = ipw2100_hw_send_command(priv, &cmd);
  4225. if (!err)
  4226. priv->tx_power = tx_power;
  4227. return 0;
  4228. }
  4229. static int ipw2100_set_ibss_beacon_interval(struct ipw2100_priv *priv,
  4230. u32 interval, int batch_mode)
  4231. {
  4232. struct host_command cmd = {
  4233. .host_command = BEACON_INTERVAL,
  4234. .host_command_sequence = 0,
  4235. .host_command_length = 4
  4236. };
  4237. int err;
  4238. cmd.host_command_parameters[0] = interval;
  4239. IPW_DEBUG_INFO("enter\n");
  4240. if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
  4241. if (!batch_mode) {
  4242. err = ipw2100_disable_adapter(priv);
  4243. if (err)
  4244. return err;
  4245. }
  4246. ipw2100_hw_send_command(priv, &cmd);
  4247. if (!batch_mode) {
  4248. err = ipw2100_enable_adapter(priv);
  4249. if (err)
  4250. return err;
  4251. }
  4252. }
  4253. IPW_DEBUG_INFO("exit\n");
  4254. return 0;
  4255. }
  4256. void ipw2100_queues_initialize(struct ipw2100_priv *priv)
  4257. {
  4258. ipw2100_tx_initialize(priv);
  4259. ipw2100_rx_initialize(priv);
  4260. ipw2100_msg_initialize(priv);
  4261. }
  4262. void ipw2100_queues_free(struct ipw2100_priv *priv)
  4263. {
  4264. ipw2100_tx_free(priv);
  4265. ipw2100_rx_free(priv);
  4266. ipw2100_msg_free(priv);
  4267. }
  4268. int ipw2100_queues_allocate(struct ipw2100_priv *priv)
  4269. {
  4270. if (ipw2100_tx_allocate(priv) ||
  4271. ipw2100_rx_allocate(priv) ||
  4272. ipw2100_msg_allocate(priv))
  4273. goto fail;
  4274. return 0;
  4275. fail:
  4276. ipw2100_tx_free(priv);
  4277. ipw2100_rx_free(priv);
  4278. ipw2100_msg_free(priv);
  4279. return -ENOMEM;
  4280. }
  4281. #define IPW_PRIVACY_CAPABLE 0x0008
  4282. static int ipw2100_set_wep_flags(struct ipw2100_priv *priv, u32 flags,
  4283. int batch_mode)
  4284. {
  4285. struct host_command cmd = {
  4286. .host_command = WEP_FLAGS,
  4287. .host_command_sequence = 0,
  4288. .host_command_length = 4
  4289. };
  4290. int err;
  4291. cmd.host_command_parameters[0] = flags;
  4292. IPW_DEBUG_HC("WEP_FLAGS: flags = 0x%08X\n", flags);
  4293. if (!batch_mode) {
  4294. err = ipw2100_disable_adapter(priv);
  4295. if (err) {
  4296. printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
  4297. priv->net_dev->name, err);
  4298. return err;
  4299. }
  4300. }
  4301. /* send cmd to firmware */
  4302. err = ipw2100_hw_send_command(priv, &cmd);
  4303. if (!batch_mode)
  4304. ipw2100_enable_adapter(priv);
  4305. return err;
  4306. }
  4307. struct ipw2100_wep_key {
  4308. u8 idx;
  4309. u8 len;
  4310. u8 key[13];
  4311. };
  4312. /* Macros to ease up priting WEP keys */
  4313. #define WEP_FMT_64 "%02X%02X%02X%02X-%02X"
  4314. #define WEP_FMT_128 "%02X%02X%02X%02X-%02X%02X%02X%02X-%02X%02X%02X"
  4315. #define WEP_STR_64(x) x[0],x[1],x[2],x[3],x[4]
  4316. #define WEP_STR_128(x) x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9],x[10]
  4317. /**
  4318. * Set a the wep key
  4319. *
  4320. * @priv: struct to work on
  4321. * @idx: index of the key we want to set
  4322. * @key: ptr to the key data to set
  4323. * @len: length of the buffer at @key
  4324. * @batch_mode: FIXME perform the operation in batch mode, not
  4325. * disabling the device.
  4326. *
  4327. * @returns 0 if OK, < 0 errno code on error.
  4328. *
  4329. * Fill out a command structure with the new wep key, length an
  4330. * index and send it down the wire.
  4331. */
  4332. static int ipw2100_set_key(struct ipw2100_priv *priv,
  4333. int idx, char *key, int len, int batch_mode)
  4334. {
  4335. int keylen = len ? (len <= 5 ? 5 : 13) : 0;
  4336. struct host_command cmd = {
  4337. .host_command = WEP_KEY_INFO,
  4338. .host_command_sequence = 0,
  4339. .host_command_length = sizeof(struct ipw2100_wep_key),
  4340. };
  4341. struct ipw2100_wep_key *wep_key = (void*)cmd.host_command_parameters;
  4342. int err;
  4343. IPW_DEBUG_HC("WEP_KEY_INFO: index = %d, len = %d/%d\n",
  4344. idx, keylen, len);
  4345. /* NOTE: We don't check cached values in case the firmware was reset
  4346. * or some other problem is occuring. If the user is setting the key,
  4347. * then we push the change */
  4348. wep_key->idx = idx;
  4349. wep_key->len = keylen;
  4350. if (keylen) {
  4351. memcpy(wep_key->key, key, len);
  4352. memset(wep_key->key + len, 0, keylen - len);
  4353. }
  4354. /* Will be optimized out on debug not being configured in */
  4355. if (keylen == 0)
  4356. IPW_DEBUG_WEP("%s: Clearing key %d\n",
  4357. priv->net_dev->name, wep_key->idx);
  4358. else if (keylen == 5)
  4359. IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_64 "\n",
  4360. priv->net_dev->name, wep_key->idx, wep_key->len,
  4361. WEP_STR_64(wep_key->key));
  4362. else
  4363. IPW_DEBUG_WEP("%s: idx: %d, len: %d key: " WEP_FMT_128
  4364. "\n",
  4365. priv->net_dev->name, wep_key->idx, wep_key->len,
  4366. WEP_STR_128(wep_key->key));
  4367. if (!batch_mode) {
  4368. err = ipw2100_disable_adapter(priv);
  4369. /* FIXME: IPG: shouldn't this prink be in _disable_adapter()? */
  4370. if (err) {
  4371. printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
  4372. priv->net_dev->name, err);
  4373. return err;
  4374. }
  4375. }
  4376. /* send cmd to firmware */
  4377. err = ipw2100_hw_send_command(priv, &cmd);
  4378. if (!batch_mode) {
  4379. int err2 = ipw2100_enable_adapter(priv);
  4380. if (err == 0)
  4381. err = err2;
  4382. }
  4383. return err;
  4384. }
  4385. static int ipw2100_set_key_index(struct ipw2100_priv *priv,
  4386. int idx, int batch_mode)
  4387. {
  4388. struct host_command cmd = {
  4389. .host_command = WEP_KEY_INDEX,
  4390. .host_command_sequence = 0,
  4391. .host_command_length = 4,
  4392. .host_command_parameters = { idx },
  4393. };
  4394. int err;
  4395. IPW_DEBUG_HC("WEP_KEY_INDEX: index = %d\n", idx);
  4396. if (idx < 0 || idx > 3)
  4397. return -EINVAL;
  4398. if (!batch_mode) {
  4399. err = ipw2100_disable_adapter(priv);
  4400. if (err) {
  4401. printk(KERN_ERR DRV_NAME ": %s: Could not disable adapter %d\n",
  4402. priv->net_dev->name, err);
  4403. return err;
  4404. }
  4405. }
  4406. /* send cmd to firmware */
  4407. err = ipw2100_hw_send_command(priv, &cmd);
  4408. if (!batch_mode)
  4409. ipw2100_enable_adapter(priv);
  4410. return err;
  4411. }
  4412. static int ipw2100_configure_security(struct ipw2100_priv *priv,
  4413. int batch_mode)
  4414. {
  4415. int i, err, auth_mode, sec_level, use_group;
  4416. if (!(priv->status & STATUS_RUNNING))
  4417. return 0;
  4418. if (!batch_mode) {
  4419. err = ipw2100_disable_adapter(priv);
  4420. if (err)
  4421. return err;
  4422. }
  4423. if (!priv->sec.enabled) {
  4424. err = ipw2100_set_security_information(
  4425. priv, IPW_AUTH_OPEN, SEC_LEVEL_0, 0, 1);
  4426. } else {
  4427. auth_mode = IPW_AUTH_OPEN;
  4428. if ((priv->sec.flags & SEC_AUTH_MODE) &&
  4429. (priv->sec.auth_mode == WLAN_AUTH_SHARED_KEY))
  4430. auth_mode = IPW_AUTH_SHARED;
  4431. sec_level = SEC_LEVEL_0;
  4432. if (priv->sec.flags & SEC_LEVEL)
  4433. sec_level = priv->sec.level;
  4434. use_group = 0;
  4435. if (priv->sec.flags & SEC_UNICAST_GROUP)
  4436. use_group = priv->sec.unicast_uses_group;
  4437. err = ipw2100_set_security_information(
  4438. priv, auth_mode, sec_level, use_group, 1);
  4439. }
  4440. if (err)
  4441. goto exit;
  4442. if (priv->sec.enabled) {
  4443. for (i = 0; i < 4; i++) {
  4444. if (!(priv->sec.flags & (1 << i))) {
  4445. memset(priv->sec.keys[i], 0, WEP_KEY_LEN);
  4446. priv->sec.key_sizes[i] = 0;
  4447. } else {
  4448. err = ipw2100_set_key(priv, i,
  4449. priv->sec.keys[i],
  4450. priv->sec.key_sizes[i],
  4451. 1);
  4452. if (err)
  4453. goto exit;
  4454. }
  4455. }
  4456. ipw2100_set_key_index(priv, priv->ieee->tx_keyidx, 1);
  4457. }
  4458. /* Always enable privacy so the Host can filter WEP packets if
  4459. * encrypted data is sent up */
  4460. err = ipw2100_set_wep_flags(
  4461. priv, priv->sec.enabled ? IPW_PRIVACY_CAPABLE : 0, 1);
  4462. if (err)
  4463. goto exit;
  4464. priv->status &= ~STATUS_SECURITY_UPDATED;
  4465. exit:
  4466. if (!batch_mode)
  4467. ipw2100_enable_adapter(priv);
  4468. return err;
  4469. }
  4470. static void ipw2100_security_work(struct ipw2100_priv *priv)
  4471. {
  4472. /* If we happen to have reconnected before we get a chance to
  4473. * process this, then update the security settings--which causes
  4474. * a disassociation to occur */
  4475. if (!(priv->status & STATUS_ASSOCIATED) &&
  4476. priv->status & STATUS_SECURITY_UPDATED)
  4477. ipw2100_configure_security(priv, 0);
  4478. }
  4479. static void shim__set_security(struct net_device *dev,
  4480. struct ieee80211_security *sec)
  4481. {
  4482. struct ipw2100_priv *priv = ieee80211_priv(dev);
  4483. int i, force_update = 0;
  4484. down(&priv->action_sem);
  4485. if (!(priv->status & STATUS_INITIALIZED))
  4486. goto done;
  4487. for (i = 0; i < 4; i++) {
  4488. if (sec->flags & (1 << i)) {
  4489. priv->sec.key_sizes[i] = sec->key_sizes[i];
  4490. if (sec->key_sizes[i] == 0)
  4491. priv->sec.flags &= ~(1 << i);
  4492. else
  4493. memcpy(priv->sec.keys[i], sec->keys[i],
  4494. sec->key_sizes[i]);
  4495. priv->sec.flags |= (1 << i);
  4496. priv->status |= STATUS_SECURITY_UPDATED;
  4497. }
  4498. }
  4499. if ((sec->flags & SEC_ACTIVE_KEY) &&
  4500. priv->sec.active_key != sec->active_key) {
  4501. if (sec->active_key <= 3) {
  4502. priv->sec.active_key = sec->active_key;
  4503. priv->sec.flags |= SEC_ACTIVE_KEY;
  4504. } else
  4505. priv->sec.flags &= ~SEC_ACTIVE_KEY;
  4506. priv->status |= STATUS_SECURITY_UPDATED;
  4507. }
  4508. if ((sec->flags & SEC_AUTH_MODE) &&
  4509. (priv->sec.auth_mode != sec->auth_mode)) {
  4510. priv->sec.auth_mode = sec->auth_mode;
  4511. priv->sec.flags |= SEC_AUTH_MODE;
  4512. priv->status |= STATUS_SECURITY_UPDATED;
  4513. }
  4514. if (sec->flags & SEC_ENABLED &&
  4515. priv->sec.enabled != sec->enabled) {
  4516. priv->sec.flags |= SEC_ENABLED;
  4517. priv->sec.enabled = sec->enabled;
  4518. priv->status |= STATUS_SECURITY_UPDATED;
  4519. force_update = 1;
  4520. }
  4521. if (sec->flags & SEC_LEVEL &&
  4522. priv->sec.level != sec->level) {
  4523. priv->sec.level = sec->level;
  4524. priv->sec.flags |= SEC_LEVEL;
  4525. priv->status |= STATUS_SECURITY_UPDATED;
  4526. }
  4527. IPW_DEBUG_WEP("Security flags: %c %c%c%c%c %c%c%c%c\n",
  4528. priv->sec.flags & (1<<8) ? '1' : '0',
  4529. priv->sec.flags & (1<<7) ? '1' : '0',
  4530. priv->sec.flags & (1<<6) ? '1' : '0',
  4531. priv->sec.flags & (1<<5) ? '1' : '0',
  4532. priv->sec.flags & (1<<4) ? '1' : '0',
  4533. priv->sec.flags & (1<<3) ? '1' : '0',
  4534. priv->sec.flags & (1<<2) ? '1' : '0',
  4535. priv->sec.flags & (1<<1) ? '1' : '0',
  4536. priv->sec.flags & (1<<0) ? '1' : '0');
  4537. /* As a temporary work around to enable WPA until we figure out why
  4538. * wpa_supplicant toggles the security capability of the driver, which
  4539. * forces a disassocation with force_update...
  4540. *
  4541. * if (force_update || !(priv->status & STATUS_ASSOCIATED))*/
  4542. if (!(priv->status & (STATUS_ASSOCIATED | STATUS_ASSOCIATING)))
  4543. ipw2100_configure_security(priv, 0);
  4544. done:
  4545. up(&priv->action_sem);
  4546. }
  4547. static int ipw2100_adapter_setup(struct ipw2100_priv *priv)
  4548. {
  4549. int err;
  4550. int batch_mode = 1;
  4551. u8 *bssid;
  4552. IPW_DEBUG_INFO("enter\n");
  4553. err = ipw2100_disable_adapter(priv);
  4554. if (err)
  4555. return err;
  4556. #ifdef CONFIG_IPW2100_MONITOR
  4557. if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
  4558. err = ipw2100_set_channel(priv, priv->channel, batch_mode);
  4559. if (err)
  4560. return err;
  4561. IPW_DEBUG_INFO("exit\n");
  4562. return 0;
  4563. }
  4564. #endif /* CONFIG_IPW2100_MONITOR */
  4565. err = ipw2100_read_mac_address(priv);
  4566. if (err)
  4567. return -EIO;
  4568. err = ipw2100_set_mac_address(priv, batch_mode);
  4569. if (err)
  4570. return err;
  4571. err = ipw2100_set_port_type(priv, priv->ieee->iw_mode, batch_mode);
  4572. if (err)
  4573. return err;
  4574. if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
  4575. err = ipw2100_set_channel(priv, priv->channel, batch_mode);
  4576. if (err)
  4577. return err;
  4578. }
  4579. err = ipw2100_system_config(priv, batch_mode);
  4580. if (err)
  4581. return err;
  4582. err = ipw2100_set_tx_rates(priv, priv->tx_rates, batch_mode);
  4583. if (err)
  4584. return err;
  4585. /* Default to power mode OFF */
  4586. err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
  4587. if (err)
  4588. return err;
  4589. err = ipw2100_set_rts_threshold(priv, priv->rts_threshold);
  4590. if (err)
  4591. return err;
  4592. if (priv->config & CFG_STATIC_BSSID)
  4593. bssid = priv->bssid;
  4594. else
  4595. bssid = NULL;
  4596. err = ipw2100_set_mandatory_bssid(priv, bssid, batch_mode);
  4597. if (err)
  4598. return err;
  4599. if (priv->config & CFG_STATIC_ESSID)
  4600. err = ipw2100_set_essid(priv, priv->essid, priv->essid_len,
  4601. batch_mode);
  4602. else
  4603. err = ipw2100_set_essid(priv, NULL, 0, batch_mode);
  4604. if (err)
  4605. return err;
  4606. err = ipw2100_configure_security(priv, batch_mode);
  4607. if (err)
  4608. return err;
  4609. if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
  4610. err = ipw2100_set_ibss_beacon_interval(
  4611. priv, priv->beacon_interval, batch_mode);
  4612. if (err)
  4613. return err;
  4614. err = ipw2100_set_tx_power(priv, priv->tx_power);
  4615. if (err)
  4616. return err;
  4617. }
  4618. /*
  4619. err = ipw2100_set_fragmentation_threshold(
  4620. priv, priv->frag_threshold, batch_mode);
  4621. if (err)
  4622. return err;
  4623. */
  4624. IPW_DEBUG_INFO("exit\n");
  4625. return 0;
  4626. }
  4627. /*************************************************************************
  4628. *
  4629. * EXTERNALLY CALLED METHODS
  4630. *
  4631. *************************************************************************/
  4632. /* This method is called by the network layer -- not to be confused with
  4633. * ipw2100_set_mac_address() declared above called by this driver (and this
  4634. * method as well) to talk to the firmware */
  4635. static int ipw2100_set_address(struct net_device *dev, void *p)
  4636. {
  4637. struct ipw2100_priv *priv = ieee80211_priv(dev);
  4638. struct sockaddr *addr = p;
  4639. int err = 0;
  4640. if (!is_valid_ether_addr(addr->sa_data))
  4641. return -EADDRNOTAVAIL;
  4642. down(&priv->action_sem);
  4643. priv->config |= CFG_CUSTOM_MAC;
  4644. memcpy(priv->mac_addr, addr->sa_data, ETH_ALEN);
  4645. err = ipw2100_set_mac_address(priv, 0);
  4646. if (err)
  4647. goto done;
  4648. priv->reset_backoff = 0;
  4649. up(&priv->action_sem);
  4650. ipw2100_reset_adapter(priv);
  4651. return 0;
  4652. done:
  4653. up(&priv->action_sem);
  4654. return err;
  4655. }
  4656. static int ipw2100_open(struct net_device *dev)
  4657. {
  4658. struct ipw2100_priv *priv = ieee80211_priv(dev);
  4659. unsigned long flags;
  4660. IPW_DEBUG_INFO("dev->open\n");
  4661. spin_lock_irqsave(&priv->low_lock, flags);
  4662. if (priv->status & STATUS_ASSOCIATED) {
  4663. netif_carrier_on(dev);
  4664. netif_start_queue(dev);
  4665. }
  4666. spin_unlock_irqrestore(&priv->low_lock, flags);
  4667. return 0;
  4668. }
  4669. static int ipw2100_close(struct net_device *dev)
  4670. {
  4671. struct ipw2100_priv *priv = ieee80211_priv(dev);
  4672. unsigned long flags;
  4673. struct list_head *element;
  4674. struct ipw2100_tx_packet *packet;
  4675. IPW_DEBUG_INFO("enter\n");
  4676. spin_lock_irqsave(&priv->low_lock, flags);
  4677. if (priv->status & STATUS_ASSOCIATED)
  4678. netif_carrier_off(dev);
  4679. netif_stop_queue(dev);
  4680. /* Flush the TX queue ... */
  4681. while (!list_empty(&priv->tx_pend_list)) {
  4682. element = priv->tx_pend_list.next;
  4683. packet = list_entry(element, struct ipw2100_tx_packet, list);
  4684. list_del(element);
  4685. DEC_STAT(&priv->tx_pend_stat);
  4686. ieee80211_txb_free(packet->info.d_struct.txb);
  4687. packet->info.d_struct.txb = NULL;
  4688. list_add_tail(element, &priv->tx_free_list);
  4689. INC_STAT(&priv->tx_free_stat);
  4690. }
  4691. spin_unlock_irqrestore(&priv->low_lock, flags);
  4692. IPW_DEBUG_INFO("exit\n");
  4693. return 0;
  4694. }
  4695. /*
  4696. * TODO: Fix this function... its just wrong
  4697. */
  4698. static void ipw2100_tx_timeout(struct net_device *dev)
  4699. {
  4700. struct ipw2100_priv *priv = ieee80211_priv(dev);
  4701. priv->ieee->stats.tx_errors++;
  4702. #ifdef CONFIG_IPW2100_MONITOR
  4703. if (priv->ieee->iw_mode == IW_MODE_MONITOR)
  4704. return;
  4705. #endif
  4706. IPW_DEBUG_INFO("%s: TX timed out. Scheduling firmware restart.\n",
  4707. dev->name);
  4708. schedule_reset(priv);
  4709. }
  4710. /*
  4711. * TODO: reimplement it so that it reads statistics
  4712. * from the adapter using ordinal tables
  4713. * instead of/in addition to collecting them
  4714. * in the driver
  4715. */
  4716. static struct net_device_stats *ipw2100_stats(struct net_device *dev)
  4717. {
  4718. struct ipw2100_priv *priv = ieee80211_priv(dev);
  4719. return &priv->ieee->stats;
  4720. }
  4721. /* Support for wpa_supplicant. Will be replaced with WEXT once
  4722. * they get WPA support. */
  4723. #ifdef CONFIG_IEEE80211_WPA
  4724. /* following definitions must match definitions in driver_ipw2100.c */
  4725. #define IPW2100_IOCTL_WPA_SUPPLICANT SIOCIWFIRSTPRIV+30
  4726. #define IPW2100_CMD_SET_WPA_PARAM 1
  4727. #define IPW2100_CMD_SET_WPA_IE 2
  4728. #define IPW2100_CMD_SET_ENCRYPTION 3
  4729. #define IPW2100_CMD_MLME 4
  4730. #define IPW2100_PARAM_WPA_ENABLED 1
  4731. #define IPW2100_PARAM_TKIP_COUNTERMEASURES 2
  4732. #define IPW2100_PARAM_DROP_UNENCRYPTED 3
  4733. #define IPW2100_PARAM_PRIVACY_INVOKED 4
  4734. #define IPW2100_PARAM_AUTH_ALGS 5
  4735. #define IPW2100_PARAM_IEEE_802_1X 6
  4736. #define IPW2100_MLME_STA_DEAUTH 1
  4737. #define IPW2100_MLME_STA_DISASSOC 2
  4738. #define IPW2100_CRYPT_ERR_UNKNOWN_ALG 2
  4739. #define IPW2100_CRYPT_ERR_UNKNOWN_ADDR 3
  4740. #define IPW2100_CRYPT_ERR_CRYPT_INIT_FAILED 4
  4741. #define IPW2100_CRYPT_ERR_KEY_SET_FAILED 5
  4742. #define IPW2100_CRYPT_ERR_TX_KEY_SET_FAILED 6
  4743. #define IPW2100_CRYPT_ERR_CARD_CONF_FAILED 7
  4744. #define IPW2100_CRYPT_ALG_NAME_LEN 16
  4745. struct ipw2100_param {
  4746. u32 cmd;
  4747. u8 sta_addr[ETH_ALEN];
  4748. union {
  4749. struct {
  4750. u8 name;
  4751. u32 value;
  4752. } wpa_param;
  4753. struct {
  4754. u32 len;
  4755. u8 *data;
  4756. } wpa_ie;
  4757. struct{
  4758. int command;
  4759. int reason_code;
  4760. } mlme;
  4761. struct {
  4762. u8 alg[IPW2100_CRYPT_ALG_NAME_LEN];
  4763. u8 set_tx;
  4764. u32 err;
  4765. u8 idx;
  4766. u8 seq[8]; /* sequence counter (set: RX, get: TX) */
  4767. u16 key_len;
  4768. u8 key[0];
  4769. } crypt;
  4770. } u;
  4771. };
  4772. /* end of driver_ipw2100.c code */
  4773. static int ipw2100_wpa_enable(struct ipw2100_priv *priv, int value){
  4774. struct ieee80211_device *ieee = priv->ieee;
  4775. struct ieee80211_security sec = {
  4776. .flags = SEC_LEVEL | SEC_ENABLED,
  4777. };
  4778. int ret = 0;
  4779. ieee->wpa_enabled = value;
  4780. if (value){
  4781. sec.level = SEC_LEVEL_3;
  4782. sec.enabled = 1;
  4783. } else {
  4784. sec.level = SEC_LEVEL_0;
  4785. sec.enabled = 0;
  4786. }
  4787. if (ieee->set_security)
  4788. ieee->set_security(ieee->dev, &sec);
  4789. else
  4790. ret = -EOPNOTSUPP;
  4791. return ret;
  4792. }
  4793. #define AUTH_ALG_OPEN_SYSTEM 0x1
  4794. #define AUTH_ALG_SHARED_KEY 0x2
  4795. static int ipw2100_wpa_set_auth_algs(struct ipw2100_priv *priv, int value){
  4796. struct ieee80211_device *ieee = priv->ieee;
  4797. struct ieee80211_security sec = {
  4798. .flags = SEC_AUTH_MODE,
  4799. };
  4800. int ret = 0;
  4801. if (value & AUTH_ALG_SHARED_KEY){
  4802. sec.auth_mode = WLAN_AUTH_SHARED_KEY;
  4803. ieee->open_wep = 0;
  4804. } else {
  4805. sec.auth_mode = WLAN_AUTH_OPEN;
  4806. ieee->open_wep = 1;
  4807. }
  4808. if (ieee->set_security)
  4809. ieee->set_security(ieee->dev, &sec);
  4810. else
  4811. ret = -EOPNOTSUPP;
  4812. return ret;
  4813. }
  4814. static int ipw2100_wpa_set_param(struct net_device *dev, u8 name, u32 value){
  4815. struct ipw2100_priv *priv = ieee80211_priv(dev);
  4816. int ret=0;
  4817. switch(name){
  4818. case IPW2100_PARAM_WPA_ENABLED:
  4819. ret = ipw2100_wpa_enable(priv, value);
  4820. break;
  4821. case IPW2100_PARAM_TKIP_COUNTERMEASURES:
  4822. priv->ieee->tkip_countermeasures=value;
  4823. break;
  4824. case IPW2100_PARAM_DROP_UNENCRYPTED:
  4825. priv->ieee->drop_unencrypted=value;
  4826. break;
  4827. case IPW2100_PARAM_PRIVACY_INVOKED:
  4828. priv->ieee->privacy_invoked=value;
  4829. break;
  4830. case IPW2100_PARAM_AUTH_ALGS:
  4831. ret = ipw2100_wpa_set_auth_algs(priv, value);
  4832. break;
  4833. case IPW2100_PARAM_IEEE_802_1X:
  4834. priv->ieee->ieee802_1x=value;
  4835. break;
  4836. default:
  4837. printk(KERN_ERR DRV_NAME ": %s: Unknown WPA param: %d\n",
  4838. dev->name, name);
  4839. ret = -EOPNOTSUPP;
  4840. }
  4841. return ret;
  4842. }
  4843. static int ipw2100_wpa_mlme(struct net_device *dev, int command, int reason){
  4844. struct ipw2100_priv *priv = ieee80211_priv(dev);
  4845. int ret=0;
  4846. switch(command){
  4847. case IPW2100_MLME_STA_DEAUTH:
  4848. // silently ignore
  4849. break;
  4850. case IPW2100_MLME_STA_DISASSOC:
  4851. ipw2100_disassociate_bssid(priv);
  4852. break;
  4853. default:
  4854. printk(KERN_ERR DRV_NAME ": %s: Unknown MLME request: %d\n",
  4855. dev->name, command);
  4856. ret = -EOPNOTSUPP;
  4857. }
  4858. return ret;
  4859. }
  4860. void ipw2100_wpa_assoc_frame(struct ipw2100_priv *priv,
  4861. char *wpa_ie, int wpa_ie_len){
  4862. struct ipw2100_wpa_assoc_frame frame;
  4863. frame.fixed_ie_mask = 0;
  4864. /* copy WPA IE */
  4865. memcpy(frame.var_ie, wpa_ie, wpa_ie_len);
  4866. frame.var_ie_len = wpa_ie_len;
  4867. /* make sure WPA is enabled */
  4868. ipw2100_wpa_enable(priv, 1);
  4869. ipw2100_set_wpa_ie(priv, &frame, 0);
  4870. }
  4871. static int ipw2100_wpa_set_wpa_ie(struct net_device *dev,
  4872. struct ipw2100_param *param, int plen){
  4873. struct ipw2100_priv *priv = ieee80211_priv(dev);
  4874. struct ieee80211_device *ieee = priv->ieee;
  4875. u8 *buf;
  4876. if (! ieee->wpa_enabled)
  4877. return -EOPNOTSUPP;
  4878. if (param->u.wpa_ie.len > MAX_WPA_IE_LEN ||
  4879. (param->u.wpa_ie.len &&
  4880. param->u.wpa_ie.data==NULL))
  4881. return -EINVAL;
  4882. if (param->u.wpa_ie.len){
  4883. buf = kmalloc(param->u.wpa_ie.len, GFP_KERNEL);
  4884. if (buf == NULL)
  4885. return -ENOMEM;
  4886. memcpy(buf, param->u.wpa_ie.data, param->u.wpa_ie.len);
  4887. kfree(ieee->wpa_ie);
  4888. ieee->wpa_ie = buf;
  4889. ieee->wpa_ie_len = param->u.wpa_ie.len;
  4890. } else {
  4891. kfree(ieee->wpa_ie);
  4892. ieee->wpa_ie = NULL;
  4893. ieee->wpa_ie_len = 0;
  4894. }
  4895. ipw2100_wpa_assoc_frame(priv, ieee->wpa_ie, ieee->wpa_ie_len);
  4896. return 0;
  4897. }
  4898. /* implementation borrowed from hostap driver */
  4899. static int ipw2100_wpa_set_encryption(struct net_device *dev,
  4900. struct ipw2100_param *param, int param_len){
  4901. int ret = 0;
  4902. struct ipw2100_priv *priv = ieee80211_priv(dev);
  4903. struct ieee80211_device *ieee = priv->ieee;
  4904. struct ieee80211_crypto_ops *ops;
  4905. struct ieee80211_crypt_data **crypt;
  4906. struct ieee80211_security sec = {
  4907. .flags = 0,
  4908. };
  4909. param->u.crypt.err = 0;
  4910. param->u.crypt.alg[IPW2100_CRYPT_ALG_NAME_LEN - 1] = '\0';
  4911. if (param_len !=
  4912. (int) ((char *) param->u.crypt.key - (char *) param) +
  4913. param->u.crypt.key_len){
  4914. IPW_DEBUG_INFO("Len mismatch %d, %d\n", param_len, param->u.crypt.key_len);
  4915. return -EINVAL;
  4916. }
  4917. if (param->sta_addr[0] == 0xff && param->sta_addr[1] == 0xff &&
  4918. param->sta_addr[2] == 0xff && param->sta_addr[3] == 0xff &&
  4919. param->sta_addr[4] == 0xff && param->sta_addr[5] == 0xff) {
  4920. if (param->u.crypt.idx >= WEP_KEYS)
  4921. return -EINVAL;
  4922. crypt = &ieee->crypt[param->u.crypt.idx];
  4923. } else {
  4924. return -EINVAL;
  4925. }
  4926. if (strcmp(param->u.crypt.alg, "none") == 0) {
  4927. if (crypt){
  4928. sec.enabled = 0;
  4929. sec.level = SEC_LEVEL_0;
  4930. sec.flags |= SEC_ENABLED | SEC_LEVEL;
  4931. ieee80211_crypt_delayed_deinit(ieee, crypt);
  4932. }
  4933. goto done;
  4934. }
  4935. sec.enabled = 1;
  4936. sec.flags |= SEC_ENABLED;
  4937. ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
  4938. if (ops == NULL && strcmp(param->u.crypt.alg, "WEP") == 0) {
  4939. request_module("ieee80211_crypt_wep");
  4940. ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
  4941. } else if (ops == NULL && strcmp(param->u.crypt.alg, "TKIP") == 0) {
  4942. request_module("ieee80211_crypt_tkip");
  4943. ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
  4944. } else if (ops == NULL && strcmp(param->u.crypt.alg, "CCMP") == 0) {
  4945. request_module("ieee80211_crypt_ccmp");
  4946. ops = ieee80211_get_crypto_ops(param->u.crypt.alg);
  4947. }
  4948. if (ops == NULL) {
  4949. IPW_DEBUG_INFO("%s: unknown crypto alg '%s'\n",
  4950. dev->name, param->u.crypt.alg);
  4951. param->u.crypt.err = IPW2100_CRYPT_ERR_UNKNOWN_ALG;
  4952. ret = -EINVAL;
  4953. goto done;
  4954. }
  4955. if (*crypt == NULL || (*crypt)->ops != ops) {
  4956. struct ieee80211_crypt_data *new_crypt;
  4957. ieee80211_crypt_delayed_deinit(ieee, crypt);
  4958. new_crypt = (struct ieee80211_crypt_data *)
  4959. kmalloc(sizeof(struct ieee80211_crypt_data), GFP_KERNEL);
  4960. if (new_crypt == NULL) {
  4961. ret = -ENOMEM;
  4962. goto done;
  4963. }
  4964. memset(new_crypt, 0, sizeof(struct ieee80211_crypt_data));
  4965. new_crypt->ops = ops;
  4966. if (new_crypt->ops && try_module_get(new_crypt->ops->owner))
  4967. new_crypt->priv = new_crypt->ops->init(param->u.crypt.idx);
  4968. if (new_crypt->priv == NULL) {
  4969. kfree(new_crypt);
  4970. param->u.crypt.err =
  4971. IPW2100_CRYPT_ERR_CRYPT_INIT_FAILED;
  4972. ret = -EINVAL;
  4973. goto done;
  4974. }
  4975. *crypt = new_crypt;
  4976. }
  4977. if (param->u.crypt.key_len > 0 && (*crypt)->ops->set_key &&
  4978. (*crypt)->ops->set_key(param->u.crypt.key,
  4979. param->u.crypt.key_len, param->u.crypt.seq,
  4980. (*crypt)->priv) < 0) {
  4981. IPW_DEBUG_INFO("%s: key setting failed\n",
  4982. dev->name);
  4983. param->u.crypt.err = IPW2100_CRYPT_ERR_KEY_SET_FAILED;
  4984. ret = -EINVAL;
  4985. goto done;
  4986. }
  4987. if (param->u.crypt.set_tx){
  4988. ieee->tx_keyidx = param->u.crypt.idx;
  4989. sec.active_key = param->u.crypt.idx;
  4990. sec.flags |= SEC_ACTIVE_KEY;
  4991. }
  4992. if (ops->name != NULL){
  4993. if (strcmp(ops->name, "WEP") == 0) {
  4994. memcpy(sec.keys[param->u.crypt.idx], param->u.crypt.key, param->u.crypt.key_len);
  4995. sec.key_sizes[param->u.crypt.idx] = param->u.crypt.key_len;
  4996. sec.flags |= (1 << param->u.crypt.idx);
  4997. sec.flags |= SEC_LEVEL;
  4998. sec.level = SEC_LEVEL_1;
  4999. } else if (strcmp(ops->name, "TKIP") == 0) {
  5000. sec.flags |= SEC_LEVEL;
  5001. sec.level = SEC_LEVEL_2;
  5002. } else if (strcmp(ops->name, "CCMP") == 0) {
  5003. sec.flags |= SEC_LEVEL;
  5004. sec.level = SEC_LEVEL_3;
  5005. }
  5006. }
  5007. done:
  5008. if (ieee->set_security)
  5009. ieee->set_security(ieee->dev, &sec);
  5010. /* Do not reset port if card is in Managed mode since resetting will
  5011. * generate new IEEE 802.11 authentication which may end up in looping
  5012. * with IEEE 802.1X. If your hardware requires a reset after WEP
  5013. * configuration (for example... Prism2), implement the reset_port in
  5014. * the callbacks structures used to initialize the 802.11 stack. */
  5015. if (ieee->reset_on_keychange &&
  5016. ieee->iw_mode != IW_MODE_INFRA &&
  5017. ieee->reset_port &&
  5018. ieee->reset_port(dev)) {
  5019. IPW_DEBUG_INFO("%s: reset_port failed\n", dev->name);
  5020. param->u.crypt.err = IPW2100_CRYPT_ERR_CARD_CONF_FAILED;
  5021. return -EINVAL;
  5022. }
  5023. return ret;
  5024. }
  5025. static int ipw2100_wpa_supplicant(struct net_device *dev, struct iw_point *p){
  5026. struct ipw2100_param *param;
  5027. int ret=0;
  5028. IPW_DEBUG_IOCTL("wpa_supplicant: len=%d\n", p->length);
  5029. if (p->length < sizeof(struct ipw2100_param) || !p->pointer)
  5030. return -EINVAL;
  5031. param = (struct ipw2100_param *)kmalloc(p->length, GFP_KERNEL);
  5032. if (param == NULL)
  5033. return -ENOMEM;
  5034. if (copy_from_user(param, p->pointer, p->length)){
  5035. kfree(param);
  5036. return -EFAULT;
  5037. }
  5038. switch (param->cmd){
  5039. case IPW2100_CMD_SET_WPA_PARAM:
  5040. ret = ipw2100_wpa_set_param(dev, param->u.wpa_param.name,
  5041. param->u.wpa_param.value);
  5042. break;
  5043. case IPW2100_CMD_SET_WPA_IE:
  5044. ret = ipw2100_wpa_set_wpa_ie(dev, param, p->length);
  5045. break;
  5046. case IPW2100_CMD_SET_ENCRYPTION:
  5047. ret = ipw2100_wpa_set_encryption(dev, param, p->length);
  5048. break;
  5049. case IPW2100_CMD_MLME:
  5050. ret = ipw2100_wpa_mlme(dev, param->u.mlme.command,
  5051. param->u.mlme.reason_code);
  5052. break;
  5053. default:
  5054. printk(KERN_ERR DRV_NAME ": %s: Unknown WPA supplicant request: %d\n",
  5055. dev->name, param->cmd);
  5056. ret = -EOPNOTSUPP;
  5057. }
  5058. if (ret == 0 && copy_to_user(p->pointer, param, p->length))
  5059. ret = -EFAULT;
  5060. kfree(param);
  5061. return ret;
  5062. }
  5063. #endif /* CONFIG_IEEE80211_WPA */
  5064. static int ipw2100_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  5065. {
  5066. #ifdef CONFIG_IEEE80211_WPA
  5067. struct iwreq *wrq = (struct iwreq *) rq;
  5068. int ret=-1;
  5069. switch (cmd){
  5070. case IPW2100_IOCTL_WPA_SUPPLICANT:
  5071. ret = ipw2100_wpa_supplicant(dev, &wrq->u.data);
  5072. return ret;
  5073. default:
  5074. return -EOPNOTSUPP;
  5075. }
  5076. #endif /* CONFIG_IEEE80211_WPA */
  5077. return -EOPNOTSUPP;
  5078. }
  5079. static void ipw_ethtool_get_drvinfo(struct net_device *dev,
  5080. struct ethtool_drvinfo *info)
  5081. {
  5082. struct ipw2100_priv *priv = ieee80211_priv(dev);
  5083. char fw_ver[64], ucode_ver[64];
  5084. strcpy(info->driver, DRV_NAME);
  5085. strcpy(info->version, DRV_VERSION);
  5086. ipw2100_get_fwversion(priv, fw_ver, sizeof(fw_ver));
  5087. ipw2100_get_ucodeversion(priv, ucode_ver, sizeof(ucode_ver));
  5088. snprintf(info->fw_version, sizeof(info->fw_version), "%s:%d:%s",
  5089. fw_ver, priv->eeprom_version, ucode_ver);
  5090. strcpy(info->bus_info, pci_name(priv->pci_dev));
  5091. }
  5092. static u32 ipw2100_ethtool_get_link(struct net_device *dev)
  5093. {
  5094. struct ipw2100_priv *priv = ieee80211_priv(dev);
  5095. return (priv->status & STATUS_ASSOCIATED) ? 1 : 0;
  5096. }
  5097. static struct ethtool_ops ipw2100_ethtool_ops = {
  5098. .get_link = ipw2100_ethtool_get_link,
  5099. .get_drvinfo = ipw_ethtool_get_drvinfo,
  5100. };
  5101. static void ipw2100_hang_check(void *adapter)
  5102. {
  5103. struct ipw2100_priv *priv = adapter;
  5104. unsigned long flags;
  5105. u32 rtc = 0xa5a5a5a5;
  5106. u32 len = sizeof(rtc);
  5107. int restart = 0;
  5108. spin_lock_irqsave(&priv->low_lock, flags);
  5109. if (priv->fatal_error != 0) {
  5110. /* If fatal_error is set then we need to restart */
  5111. IPW_DEBUG_INFO("%s: Hardware fatal error detected.\n",
  5112. priv->net_dev->name);
  5113. restart = 1;
  5114. } else if (ipw2100_get_ordinal(priv, IPW_ORD_RTC_TIME, &rtc, &len) ||
  5115. (rtc == priv->last_rtc)) {
  5116. /* Check if firmware is hung */
  5117. IPW_DEBUG_INFO("%s: Firmware RTC stalled.\n",
  5118. priv->net_dev->name);
  5119. restart = 1;
  5120. }
  5121. if (restart) {
  5122. /* Kill timer */
  5123. priv->stop_hang_check = 1;
  5124. priv->hangs++;
  5125. /* Restart the NIC */
  5126. schedule_reset(priv);
  5127. }
  5128. priv->last_rtc = rtc;
  5129. if (!priv->stop_hang_check)
  5130. queue_delayed_work(priv->workqueue, &priv->hang_check, HZ / 2);
  5131. spin_unlock_irqrestore(&priv->low_lock, flags);
  5132. }
  5133. static void ipw2100_rf_kill(void *adapter)
  5134. {
  5135. struct ipw2100_priv *priv = adapter;
  5136. unsigned long flags;
  5137. spin_lock_irqsave(&priv->low_lock, flags);
  5138. if (rf_kill_active(priv)) {
  5139. IPW_DEBUG_RF_KILL("RF Kill active, rescheduling GPIO check\n");
  5140. if (!priv->stop_rf_kill)
  5141. queue_delayed_work(priv->workqueue, &priv->rf_kill, HZ);
  5142. goto exit_unlock;
  5143. }
  5144. /* RF Kill is now disabled, so bring the device back up */
  5145. if (!(priv->status & STATUS_RF_KILL_MASK)) {
  5146. IPW_DEBUG_RF_KILL("HW RF Kill no longer active, restarting "
  5147. "device\n");
  5148. schedule_reset(priv);
  5149. } else
  5150. IPW_DEBUG_RF_KILL("HW RF Kill deactivated. SW RF Kill still "
  5151. "enabled\n");
  5152. exit_unlock:
  5153. spin_unlock_irqrestore(&priv->low_lock, flags);
  5154. }
  5155. static void ipw2100_irq_tasklet(struct ipw2100_priv *priv);
  5156. /* Look into using netdev destructor to shutdown ieee80211? */
  5157. static struct net_device *ipw2100_alloc_device(
  5158. struct pci_dev *pci_dev,
  5159. void __iomem *base_addr,
  5160. unsigned long mem_start,
  5161. unsigned long mem_len)
  5162. {
  5163. struct ipw2100_priv *priv;
  5164. struct net_device *dev;
  5165. dev = alloc_ieee80211(sizeof(struct ipw2100_priv));
  5166. if (!dev)
  5167. return NULL;
  5168. priv = ieee80211_priv(dev);
  5169. priv->ieee = netdev_priv(dev);
  5170. priv->pci_dev = pci_dev;
  5171. priv->net_dev = dev;
  5172. priv->ieee->hard_start_xmit = ipw2100_tx;
  5173. priv->ieee->set_security = shim__set_security;
  5174. dev->open = ipw2100_open;
  5175. dev->stop = ipw2100_close;
  5176. dev->init = ipw2100_net_init;
  5177. dev->do_ioctl = ipw2100_ioctl;
  5178. dev->get_stats = ipw2100_stats;
  5179. dev->ethtool_ops = &ipw2100_ethtool_ops;
  5180. dev->tx_timeout = ipw2100_tx_timeout;
  5181. dev->wireless_handlers = &ipw2100_wx_handler_def;
  5182. dev->get_wireless_stats = ipw2100_wx_wireless_stats;
  5183. dev->set_mac_address = ipw2100_set_address;
  5184. dev->watchdog_timeo = 3*HZ;
  5185. dev->irq = 0;
  5186. dev->base_addr = (unsigned long)base_addr;
  5187. dev->mem_start = mem_start;
  5188. dev->mem_end = dev->mem_start + mem_len - 1;
  5189. /* NOTE: We don't use the wireless_handlers hook
  5190. * in dev as the system will start throwing WX requests
  5191. * to us before we're actually initialized and it just
  5192. * ends up causing problems. So, we just handle
  5193. * the WX extensions through the ipw2100_ioctl interface */
  5194. /* memset() puts everything to 0, so we only have explicitely set
  5195. * those values that need to be something else */
  5196. /* If power management is turned on, default to AUTO mode */
  5197. priv->power_mode = IPW_POWER_AUTO;
  5198. #ifdef CONFIG_IEEE80211_WPA
  5199. priv->ieee->wpa_enabled = 0;
  5200. priv->ieee->tkip_countermeasures = 0;
  5201. priv->ieee->drop_unencrypted = 0;
  5202. priv->ieee->privacy_invoked = 0;
  5203. priv->ieee->ieee802_1x = 1;
  5204. #endif /* CONFIG_IEEE80211_WPA */
  5205. /* Set module parameters */
  5206. switch (mode) {
  5207. case 1:
  5208. priv->ieee->iw_mode = IW_MODE_ADHOC;
  5209. break;
  5210. #ifdef CONFIG_IPW2100_MONITOR
  5211. case 2:
  5212. priv->ieee->iw_mode = IW_MODE_MONITOR;
  5213. break;
  5214. #endif
  5215. default:
  5216. case 0:
  5217. priv->ieee->iw_mode = IW_MODE_INFRA;
  5218. break;
  5219. }
  5220. if (disable == 1)
  5221. priv->status |= STATUS_RF_KILL_SW;
  5222. if (channel != 0 &&
  5223. ((channel >= REG_MIN_CHANNEL) &&
  5224. (channel <= REG_MAX_CHANNEL))) {
  5225. priv->config |= CFG_STATIC_CHANNEL;
  5226. priv->channel = channel;
  5227. }
  5228. if (associate)
  5229. priv->config |= CFG_ASSOCIATE;
  5230. priv->beacon_interval = DEFAULT_BEACON_INTERVAL;
  5231. priv->short_retry_limit = DEFAULT_SHORT_RETRY_LIMIT;
  5232. priv->long_retry_limit = DEFAULT_LONG_RETRY_LIMIT;
  5233. priv->rts_threshold = DEFAULT_RTS_THRESHOLD | RTS_DISABLED;
  5234. priv->frag_threshold = DEFAULT_FTS | FRAG_DISABLED;
  5235. priv->tx_power = IPW_TX_POWER_DEFAULT;
  5236. priv->tx_rates = DEFAULT_TX_RATES;
  5237. strcpy(priv->nick, "ipw2100");
  5238. spin_lock_init(&priv->low_lock);
  5239. sema_init(&priv->action_sem, 1);
  5240. sema_init(&priv->adapter_sem, 1);
  5241. init_waitqueue_head(&priv->wait_command_queue);
  5242. netif_carrier_off(dev);
  5243. INIT_LIST_HEAD(&priv->msg_free_list);
  5244. INIT_LIST_HEAD(&priv->msg_pend_list);
  5245. INIT_STAT(&priv->msg_free_stat);
  5246. INIT_STAT(&priv->msg_pend_stat);
  5247. INIT_LIST_HEAD(&priv->tx_free_list);
  5248. INIT_LIST_HEAD(&priv->tx_pend_list);
  5249. INIT_STAT(&priv->tx_free_stat);
  5250. INIT_STAT(&priv->tx_pend_stat);
  5251. INIT_LIST_HEAD(&priv->fw_pend_list);
  5252. INIT_STAT(&priv->fw_pend_stat);
  5253. #ifdef CONFIG_SOFTWARE_SUSPEND2
  5254. priv->workqueue = create_workqueue(DRV_NAME, 0);
  5255. #else
  5256. priv->workqueue = create_workqueue(DRV_NAME);
  5257. #endif
  5258. INIT_WORK(&priv->reset_work,
  5259. (void (*)(void *))ipw2100_reset_adapter, priv);
  5260. INIT_WORK(&priv->security_work,
  5261. (void (*)(void *))ipw2100_security_work, priv);
  5262. INIT_WORK(&priv->wx_event_work,
  5263. (void (*)(void *))ipw2100_wx_event_work, priv);
  5264. INIT_WORK(&priv->hang_check, ipw2100_hang_check, priv);
  5265. INIT_WORK(&priv->rf_kill, ipw2100_rf_kill, priv);
  5266. tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
  5267. ipw2100_irq_tasklet, (unsigned long)priv);
  5268. /* NOTE: We do not start the deferred work for status checks yet */
  5269. priv->stop_rf_kill = 1;
  5270. priv->stop_hang_check = 1;
  5271. return dev;
  5272. }
  5273. static int ipw2100_pci_init_one(struct pci_dev *pci_dev,
  5274. const struct pci_device_id *ent)
  5275. {
  5276. unsigned long mem_start, mem_len, mem_flags;
  5277. void __iomem *base_addr = NULL;
  5278. struct net_device *dev = NULL;
  5279. struct ipw2100_priv *priv = NULL;
  5280. int err = 0;
  5281. int registered = 0;
  5282. u32 val;
  5283. IPW_DEBUG_INFO("enter\n");
  5284. mem_start = pci_resource_start(pci_dev, 0);
  5285. mem_len = pci_resource_len(pci_dev, 0);
  5286. mem_flags = pci_resource_flags(pci_dev, 0);
  5287. if ((mem_flags & IORESOURCE_MEM) != IORESOURCE_MEM) {
  5288. IPW_DEBUG_INFO("weird - resource type is not memory\n");
  5289. err = -ENODEV;
  5290. goto fail;
  5291. }
  5292. base_addr = ioremap_nocache(mem_start, mem_len);
  5293. if (!base_addr) {
  5294. printk(KERN_WARNING DRV_NAME
  5295. "Error calling ioremap_nocache.\n");
  5296. err = -EIO;
  5297. goto fail;
  5298. }
  5299. /* allocate and initialize our net_device */
  5300. dev = ipw2100_alloc_device(pci_dev, base_addr, mem_start, mem_len);
  5301. if (!dev) {
  5302. printk(KERN_WARNING DRV_NAME
  5303. "Error calling ipw2100_alloc_device.\n");
  5304. err = -ENOMEM;
  5305. goto fail;
  5306. }
  5307. /* set up PCI mappings for device */
  5308. err = pci_enable_device(pci_dev);
  5309. if (err) {
  5310. printk(KERN_WARNING DRV_NAME
  5311. "Error calling pci_enable_device.\n");
  5312. return err;
  5313. }
  5314. priv = ieee80211_priv(dev);
  5315. pci_set_master(pci_dev);
  5316. pci_set_drvdata(pci_dev, priv);
  5317. err = pci_set_dma_mask(pci_dev, DMA_32BIT_MASK);
  5318. if (err) {
  5319. printk(KERN_WARNING DRV_NAME
  5320. "Error calling pci_set_dma_mask.\n");
  5321. pci_disable_device(pci_dev);
  5322. return err;
  5323. }
  5324. err = pci_request_regions(pci_dev, DRV_NAME);
  5325. if (err) {
  5326. printk(KERN_WARNING DRV_NAME
  5327. "Error calling pci_request_regions.\n");
  5328. pci_disable_device(pci_dev);
  5329. return err;
  5330. }
  5331. /* We disable the RETRY_TIMEOUT register (0x41) to keep
  5332. * PCI Tx retries from interfering with C3 CPU state */
  5333. pci_read_config_dword(pci_dev, 0x40, &val);
  5334. if ((val & 0x0000ff00) != 0)
  5335. pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
  5336. pci_set_power_state(pci_dev, PCI_D0);
  5337. if (!ipw2100_hw_is_adapter_in_system(dev)) {
  5338. printk(KERN_WARNING DRV_NAME
  5339. "Device not found via register read.\n");
  5340. err = -ENODEV;
  5341. goto fail;
  5342. }
  5343. SET_NETDEV_DEV(dev, &pci_dev->dev);
  5344. /* Force interrupts to be shut off on the device */
  5345. priv->status |= STATUS_INT_ENABLED;
  5346. ipw2100_disable_interrupts(priv);
  5347. /* Allocate and initialize the Tx/Rx queues and lists */
  5348. if (ipw2100_queues_allocate(priv)) {
  5349. printk(KERN_WARNING DRV_NAME
  5350. "Error calilng ipw2100_queues_allocate.\n");
  5351. err = -ENOMEM;
  5352. goto fail;
  5353. }
  5354. ipw2100_queues_initialize(priv);
  5355. err = request_irq(pci_dev->irq,
  5356. ipw2100_interrupt, SA_SHIRQ,
  5357. dev->name, priv);
  5358. if (err) {
  5359. printk(KERN_WARNING DRV_NAME
  5360. "Error calling request_irq: %d.\n",
  5361. pci_dev->irq);
  5362. goto fail;
  5363. }
  5364. dev->irq = pci_dev->irq;
  5365. IPW_DEBUG_INFO("Attempting to register device...\n");
  5366. SET_MODULE_OWNER(dev);
  5367. printk(KERN_INFO DRV_NAME
  5368. ": Detected Intel PRO/Wireless 2100 Network Connection\n");
  5369. /* Bring up the interface. Pre 0.46, after we registered the
  5370. * network device we would call ipw2100_up. This introduced a race
  5371. * condition with newer hotplug configurations (network was coming
  5372. * up and making calls before the device was initialized).
  5373. *
  5374. * If we called ipw2100_up before we registered the device, then the
  5375. * device name wasn't registered. So, we instead use the net_dev->init
  5376. * member to call a function that then just turns and calls ipw2100_up.
  5377. * net_dev->init is called after name allocation but before the
  5378. * notifier chain is called */
  5379. down(&priv->action_sem);
  5380. err = register_netdev(dev);
  5381. if (err) {
  5382. printk(KERN_WARNING DRV_NAME
  5383. "Error calling register_netdev.\n");
  5384. goto fail_unlock;
  5385. }
  5386. registered = 1;
  5387. IPW_DEBUG_INFO("%s: Bound to %s\n", dev->name, pci_name(pci_dev));
  5388. /* perform this after register_netdev so that dev->name is set */
  5389. sysfs_create_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
  5390. netif_carrier_off(dev);
  5391. /* If the RF Kill switch is disabled, go ahead and complete the
  5392. * startup sequence */
  5393. if (!(priv->status & STATUS_RF_KILL_MASK)) {
  5394. /* Enable the adapter - sends HOST_COMPLETE */
  5395. if (ipw2100_enable_adapter(priv)) {
  5396. printk(KERN_WARNING DRV_NAME
  5397. ": %s: failed in call to enable adapter.\n",
  5398. priv->net_dev->name);
  5399. ipw2100_hw_stop_adapter(priv);
  5400. err = -EIO;
  5401. goto fail_unlock;
  5402. }
  5403. /* Start a scan . . . */
  5404. ipw2100_set_scan_options(priv);
  5405. ipw2100_start_scan(priv);
  5406. }
  5407. IPW_DEBUG_INFO("exit\n");
  5408. priv->status |= STATUS_INITIALIZED;
  5409. up(&priv->action_sem);
  5410. return 0;
  5411. fail_unlock:
  5412. up(&priv->action_sem);
  5413. fail:
  5414. if (dev) {
  5415. if (registered)
  5416. unregister_netdev(dev);
  5417. ipw2100_hw_stop_adapter(priv);
  5418. ipw2100_disable_interrupts(priv);
  5419. if (dev->irq)
  5420. free_irq(dev->irq, priv);
  5421. ipw2100_kill_workqueue(priv);
  5422. /* These are safe to call even if they weren't allocated */
  5423. ipw2100_queues_free(priv);
  5424. sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
  5425. free_ieee80211(dev);
  5426. pci_set_drvdata(pci_dev, NULL);
  5427. }
  5428. if (base_addr)
  5429. iounmap(base_addr);
  5430. pci_release_regions(pci_dev);
  5431. pci_disable_device(pci_dev);
  5432. return err;
  5433. }
  5434. static void __devexit ipw2100_pci_remove_one(struct pci_dev *pci_dev)
  5435. {
  5436. struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
  5437. struct net_device *dev;
  5438. if (priv) {
  5439. down(&priv->action_sem);
  5440. priv->status &= ~STATUS_INITIALIZED;
  5441. dev = priv->net_dev;
  5442. sysfs_remove_group(&pci_dev->dev.kobj, &ipw2100_attribute_group);
  5443. #ifdef CONFIG_PM
  5444. if (ipw2100_firmware.version)
  5445. ipw2100_release_firmware(priv, &ipw2100_firmware);
  5446. #endif
  5447. /* Take down the hardware */
  5448. ipw2100_down(priv);
  5449. /* Release the semaphore so that the network subsystem can
  5450. * complete any needed calls into the driver... */
  5451. up(&priv->action_sem);
  5452. /* Unregister the device first - this results in close()
  5453. * being called if the device is open. If we free storage
  5454. * first, then close() will crash. */
  5455. unregister_netdev(dev);
  5456. /* ipw2100_down will ensure that there is no more pending work
  5457. * in the workqueue's, so we can safely remove them now. */
  5458. ipw2100_kill_workqueue(priv);
  5459. ipw2100_queues_free(priv);
  5460. /* Free potential debugging firmware snapshot */
  5461. ipw2100_snapshot_free(priv);
  5462. if (dev->irq)
  5463. free_irq(dev->irq, priv);
  5464. if (dev->base_addr)
  5465. iounmap((void __iomem *)dev->base_addr);
  5466. free_ieee80211(dev);
  5467. }
  5468. pci_release_regions(pci_dev);
  5469. pci_disable_device(pci_dev);
  5470. IPW_DEBUG_INFO("exit\n");
  5471. }
  5472. #ifdef CONFIG_PM
  5473. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11)
  5474. static int ipw2100_suspend(struct pci_dev *pci_dev, u32 state)
  5475. #else
  5476. static int ipw2100_suspend(struct pci_dev *pci_dev, pm_message_t state)
  5477. #endif
  5478. {
  5479. struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
  5480. struct net_device *dev = priv->net_dev;
  5481. IPW_DEBUG_INFO("%s: Going into suspend...\n",
  5482. dev->name);
  5483. down(&priv->action_sem);
  5484. if (priv->status & STATUS_INITIALIZED) {
  5485. /* Take down the device; powers it off, etc. */
  5486. ipw2100_down(priv);
  5487. }
  5488. /* Remove the PRESENT state of the device */
  5489. netif_device_detach(dev);
  5490. pci_save_state(pci_dev);
  5491. pci_disable_device (pci_dev);
  5492. pci_set_power_state(pci_dev, PCI_D3hot);
  5493. up(&priv->action_sem);
  5494. return 0;
  5495. }
  5496. static int ipw2100_resume(struct pci_dev *pci_dev)
  5497. {
  5498. struct ipw2100_priv *priv = pci_get_drvdata(pci_dev);
  5499. struct net_device *dev = priv->net_dev;
  5500. u32 val;
  5501. if (IPW2100_PM_DISABLED)
  5502. return 0;
  5503. down(&priv->action_sem);
  5504. IPW_DEBUG_INFO("%s: Coming out of suspend...\n",
  5505. dev->name);
  5506. pci_set_power_state(pci_dev, PCI_D0);
  5507. pci_enable_device(pci_dev);
  5508. pci_restore_state(pci_dev);
  5509. /*
  5510. * Suspend/Resume resets the PCI configuration space, so we have to
  5511. * re-disable the RETRY_TIMEOUT register (0x41) to keep PCI Tx retries
  5512. * from interfering with C3 CPU state. pci_restore_state won't help
  5513. * here since it only restores the first 64 bytes pci config header.
  5514. */
  5515. pci_read_config_dword(pci_dev, 0x40, &val);
  5516. if ((val & 0x0000ff00) != 0)
  5517. pci_write_config_dword(pci_dev, 0x40, val & 0xffff00ff);
  5518. /* Set the device back into the PRESENT state; this will also wake
  5519. * the queue of needed */
  5520. netif_device_attach(dev);
  5521. /* Bring the device back up */
  5522. if (!(priv->status & STATUS_RF_KILL_SW))
  5523. ipw2100_up(priv, 0);
  5524. up(&priv->action_sem);
  5525. return 0;
  5526. }
  5527. #endif
  5528. #define IPW2100_DEV_ID(x) { PCI_VENDOR_ID_INTEL, 0x1043, 0x8086, x }
  5529. static struct pci_device_id ipw2100_pci_id_table[] __devinitdata = {
  5530. IPW2100_DEV_ID(0x2520), /* IN 2100A mPCI 3A */
  5531. IPW2100_DEV_ID(0x2521), /* IN 2100A mPCI 3B */
  5532. IPW2100_DEV_ID(0x2524), /* IN 2100A mPCI 3B */
  5533. IPW2100_DEV_ID(0x2525), /* IN 2100A mPCI 3B */
  5534. IPW2100_DEV_ID(0x2526), /* IN 2100A mPCI Gen A3 */
  5535. IPW2100_DEV_ID(0x2522), /* IN 2100 mPCI 3B */
  5536. IPW2100_DEV_ID(0x2523), /* IN 2100 mPCI 3A */
  5537. IPW2100_DEV_ID(0x2527), /* IN 2100 mPCI 3B */
  5538. IPW2100_DEV_ID(0x2528), /* IN 2100 mPCI 3B */
  5539. IPW2100_DEV_ID(0x2529), /* IN 2100 mPCI 3B */
  5540. IPW2100_DEV_ID(0x252B), /* IN 2100 mPCI 3A */
  5541. IPW2100_DEV_ID(0x252C), /* IN 2100 mPCI 3A */
  5542. IPW2100_DEV_ID(0x252D), /* IN 2100 mPCI 3A */
  5543. IPW2100_DEV_ID(0x2550), /* IB 2100A mPCI 3B */
  5544. IPW2100_DEV_ID(0x2551), /* IB 2100 mPCI 3B */
  5545. IPW2100_DEV_ID(0x2553), /* IB 2100 mPCI 3B */
  5546. IPW2100_DEV_ID(0x2554), /* IB 2100 mPCI 3B */
  5547. IPW2100_DEV_ID(0x2555), /* IB 2100 mPCI 3B */
  5548. IPW2100_DEV_ID(0x2560), /* DE 2100A mPCI 3A */
  5549. IPW2100_DEV_ID(0x2562), /* DE 2100A mPCI 3A */
  5550. IPW2100_DEV_ID(0x2563), /* DE 2100A mPCI 3A */
  5551. IPW2100_DEV_ID(0x2561), /* DE 2100 mPCI 3A */
  5552. IPW2100_DEV_ID(0x2565), /* DE 2100 mPCI 3A */
  5553. IPW2100_DEV_ID(0x2566), /* DE 2100 mPCI 3A */
  5554. IPW2100_DEV_ID(0x2567), /* DE 2100 mPCI 3A */
  5555. IPW2100_DEV_ID(0x2570), /* GA 2100 mPCI 3B */
  5556. IPW2100_DEV_ID(0x2580), /* TO 2100A mPCI 3B */
  5557. IPW2100_DEV_ID(0x2582), /* TO 2100A mPCI 3B */
  5558. IPW2100_DEV_ID(0x2583), /* TO 2100A mPCI 3B */
  5559. IPW2100_DEV_ID(0x2581), /* TO 2100 mPCI 3B */
  5560. IPW2100_DEV_ID(0x2585), /* TO 2100 mPCI 3B */
  5561. IPW2100_DEV_ID(0x2586), /* TO 2100 mPCI 3B */
  5562. IPW2100_DEV_ID(0x2587), /* TO 2100 mPCI 3B */
  5563. IPW2100_DEV_ID(0x2590), /* SO 2100A mPCI 3B */
  5564. IPW2100_DEV_ID(0x2592), /* SO 2100A mPCI 3B */
  5565. IPW2100_DEV_ID(0x2591), /* SO 2100 mPCI 3B */
  5566. IPW2100_DEV_ID(0x2593), /* SO 2100 mPCI 3B */
  5567. IPW2100_DEV_ID(0x2596), /* SO 2100 mPCI 3B */
  5568. IPW2100_DEV_ID(0x2598), /* SO 2100 mPCI 3B */
  5569. IPW2100_DEV_ID(0x25A0), /* HP 2100 mPCI 3B */
  5570. {0,},
  5571. };
  5572. MODULE_DEVICE_TABLE(pci, ipw2100_pci_id_table);
  5573. static struct pci_driver ipw2100_pci_driver = {
  5574. .name = DRV_NAME,
  5575. .id_table = ipw2100_pci_id_table,
  5576. .probe = ipw2100_pci_init_one,
  5577. .remove = __devexit_p(ipw2100_pci_remove_one),
  5578. #ifdef CONFIG_PM
  5579. .suspend = ipw2100_suspend,
  5580. .resume = ipw2100_resume,
  5581. #endif
  5582. };
  5583. /**
  5584. * Initialize the ipw2100 driver/module
  5585. *
  5586. * @returns 0 if ok, < 0 errno node con error.
  5587. *
  5588. * Note: we cannot init the /proc stuff until the PCI driver is there,
  5589. * or we risk an unlikely race condition on someone accessing
  5590. * uninitialized data in the PCI dev struct through /proc.
  5591. */
  5592. static int __init ipw2100_init(void)
  5593. {
  5594. int ret;
  5595. printk(KERN_INFO DRV_NAME ": %s, %s\n", DRV_DESCRIPTION, DRV_VERSION);
  5596. printk(KERN_INFO DRV_NAME ": %s\n", DRV_COPYRIGHT);
  5597. #ifdef CONFIG_IEEE80211_NOWEP
  5598. IPW_DEBUG_INFO(DRV_NAME ": Compiled with WEP disabled.\n");
  5599. #endif
  5600. ret = pci_module_init(&ipw2100_pci_driver);
  5601. #ifdef CONFIG_IPW_DEBUG
  5602. ipw2100_debug_level = debug;
  5603. driver_create_file(&ipw2100_pci_driver.driver,
  5604. &driver_attr_debug_level);
  5605. #endif
  5606. return ret;
  5607. }
  5608. /**
  5609. * Cleanup ipw2100 driver registration
  5610. */
  5611. static void __exit ipw2100_exit(void)
  5612. {
  5613. /* FIXME: IPG: check that we have no instances of the devices open */
  5614. #ifdef CONFIG_IPW_DEBUG
  5615. driver_remove_file(&ipw2100_pci_driver.driver,
  5616. &driver_attr_debug_level);
  5617. #endif
  5618. pci_unregister_driver(&ipw2100_pci_driver);
  5619. }
  5620. module_init(ipw2100_init);
  5621. module_exit(ipw2100_exit);
  5622. #define WEXT_USECHANNELS 1
  5623. static const long ipw2100_frequencies[] = {
  5624. 2412, 2417, 2422, 2427,
  5625. 2432, 2437, 2442, 2447,
  5626. 2452, 2457, 2462, 2467,
  5627. 2472, 2484
  5628. };
  5629. #define FREQ_COUNT (sizeof(ipw2100_frequencies) / \
  5630. sizeof(ipw2100_frequencies[0]))
  5631. static const long ipw2100_rates_11b[] = {
  5632. 1000000,
  5633. 2000000,
  5634. 5500000,
  5635. 11000000
  5636. };
  5637. #define RATE_COUNT (sizeof(ipw2100_rates_11b) / sizeof(ipw2100_rates_11b[0]))
  5638. static int ipw2100_wx_get_name(struct net_device *dev,
  5639. struct iw_request_info *info,
  5640. union iwreq_data *wrqu, char *extra)
  5641. {
  5642. /*
  5643. * This can be called at any time. No action lock required
  5644. */
  5645. struct ipw2100_priv *priv = ieee80211_priv(dev);
  5646. if (!(priv->status & STATUS_ASSOCIATED))
  5647. strcpy(wrqu->name, "unassociated");
  5648. else
  5649. snprintf(wrqu->name, IFNAMSIZ, "IEEE 802.11b");
  5650. IPW_DEBUG_WX("Name: %s\n", wrqu->name);
  5651. return 0;
  5652. }
  5653. static int ipw2100_wx_set_freq(struct net_device *dev,
  5654. struct iw_request_info *info,
  5655. union iwreq_data *wrqu, char *extra)
  5656. {
  5657. struct ipw2100_priv *priv = ieee80211_priv(dev);
  5658. struct iw_freq *fwrq = &wrqu->freq;
  5659. int err = 0;
  5660. if (priv->ieee->iw_mode == IW_MODE_INFRA)
  5661. return -EOPNOTSUPP;
  5662. down(&priv->action_sem);
  5663. if (!(priv->status & STATUS_INITIALIZED)) {
  5664. err = -EIO;
  5665. goto done;
  5666. }
  5667. /* if setting by freq convert to channel */
  5668. if (fwrq->e == 1) {
  5669. if ((fwrq->m >= (int) 2.412e8 &&
  5670. fwrq->m <= (int) 2.487e8)) {
  5671. int f = fwrq->m / 100000;
  5672. int c = 0;
  5673. while ((c < REG_MAX_CHANNEL) &&
  5674. (f != ipw2100_frequencies[c]))
  5675. c++;
  5676. /* hack to fall through */
  5677. fwrq->e = 0;
  5678. fwrq->m = c + 1;
  5679. }
  5680. }
  5681. if (fwrq->e > 0 || fwrq->m > 1000)
  5682. return -EOPNOTSUPP;
  5683. else { /* Set the channel */
  5684. IPW_DEBUG_WX("SET Freq/Channel -> %d \n", fwrq->m);
  5685. err = ipw2100_set_channel(priv, fwrq->m, 0);
  5686. }
  5687. done:
  5688. up(&priv->action_sem);
  5689. return err;
  5690. }
  5691. static int ipw2100_wx_get_freq(struct net_device *dev,
  5692. struct iw_request_info *info,
  5693. union iwreq_data *wrqu, char *extra)
  5694. {
  5695. /*
  5696. * This can be called at any time. No action lock required
  5697. */
  5698. struct ipw2100_priv *priv = ieee80211_priv(dev);
  5699. wrqu->freq.e = 0;
  5700. /* If we are associated, trying to associate, or have a statically
  5701. * configured CHANNEL then return that; otherwise return ANY */
  5702. if (priv->config & CFG_STATIC_CHANNEL ||
  5703. priv->status & STATUS_ASSOCIATED)
  5704. wrqu->freq.m = priv->channel;
  5705. else
  5706. wrqu->freq.m = 0;
  5707. IPW_DEBUG_WX("GET Freq/Channel -> %d \n", priv->channel);
  5708. return 0;
  5709. }
  5710. static int ipw2100_wx_set_mode(struct net_device *dev,
  5711. struct iw_request_info *info,
  5712. union iwreq_data *wrqu, char *extra)
  5713. {
  5714. struct ipw2100_priv *priv = ieee80211_priv(dev);
  5715. int err = 0;
  5716. IPW_DEBUG_WX("SET Mode -> %d \n", wrqu->mode);
  5717. if (wrqu->mode == priv->ieee->iw_mode)
  5718. return 0;
  5719. down(&priv->action_sem);
  5720. if (!(priv->status & STATUS_INITIALIZED)) {
  5721. err = -EIO;
  5722. goto done;
  5723. }
  5724. switch (wrqu->mode) {
  5725. #ifdef CONFIG_IPW2100_MONITOR
  5726. case IW_MODE_MONITOR:
  5727. err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
  5728. break;
  5729. #endif /* CONFIG_IPW2100_MONITOR */
  5730. case IW_MODE_ADHOC:
  5731. err = ipw2100_switch_mode(priv, IW_MODE_ADHOC);
  5732. break;
  5733. case IW_MODE_INFRA:
  5734. case IW_MODE_AUTO:
  5735. default:
  5736. err = ipw2100_switch_mode(priv, IW_MODE_INFRA);
  5737. break;
  5738. }
  5739. done:
  5740. up(&priv->action_sem);
  5741. return err;
  5742. }
  5743. static int ipw2100_wx_get_mode(struct net_device *dev,
  5744. struct iw_request_info *info,
  5745. union iwreq_data *wrqu, char *extra)
  5746. {
  5747. /*
  5748. * This can be called at any time. No action lock required
  5749. */
  5750. struct ipw2100_priv *priv = ieee80211_priv(dev);
  5751. wrqu->mode = priv->ieee->iw_mode;
  5752. IPW_DEBUG_WX("GET Mode -> %d\n", wrqu->mode);
  5753. return 0;
  5754. }
  5755. #define POWER_MODES 5
  5756. /* Values are in microsecond */
  5757. static const s32 timeout_duration[POWER_MODES] = {
  5758. 350000,
  5759. 250000,
  5760. 75000,
  5761. 37000,
  5762. 25000,
  5763. };
  5764. static const s32 period_duration[POWER_MODES] = {
  5765. 400000,
  5766. 700000,
  5767. 1000000,
  5768. 1000000,
  5769. 1000000
  5770. };
  5771. static int ipw2100_wx_get_range(struct net_device *dev,
  5772. struct iw_request_info *info,
  5773. union iwreq_data *wrqu, char *extra)
  5774. {
  5775. /*
  5776. * This can be called at any time. No action lock required
  5777. */
  5778. struct ipw2100_priv *priv = ieee80211_priv(dev);
  5779. struct iw_range *range = (struct iw_range *)extra;
  5780. u16 val;
  5781. int i, level;
  5782. wrqu->data.length = sizeof(*range);
  5783. memset(range, 0, sizeof(*range));
  5784. /* Let's try to keep this struct in the same order as in
  5785. * linux/include/wireless.h
  5786. */
  5787. /* TODO: See what values we can set, and remove the ones we can't
  5788. * set, or fill them with some default data.
  5789. */
  5790. /* ~5 Mb/s real (802.11b) */
  5791. range->throughput = 5 * 1000 * 1000;
  5792. // range->sensitivity; /* signal level threshold range */
  5793. range->max_qual.qual = 100;
  5794. /* TODO: Find real max RSSI and stick here */
  5795. range->max_qual.level = 0;
  5796. range->max_qual.noise = 0;
  5797. range->max_qual.updated = 7; /* Updated all three */
  5798. range->avg_qual.qual = 70; /* > 8% missed beacons is 'bad' */
  5799. /* TODO: Find real 'good' to 'bad' threshol value for RSSI */
  5800. range->avg_qual.level = 20 + IPW2100_RSSI_TO_DBM;
  5801. range->avg_qual.noise = 0;
  5802. range->avg_qual.updated = 7; /* Updated all three */
  5803. range->num_bitrates = RATE_COUNT;
  5804. for (i = 0; i < RATE_COUNT && i < IW_MAX_BITRATES; i++) {
  5805. range->bitrate[i] = ipw2100_rates_11b[i];
  5806. }
  5807. range->min_rts = MIN_RTS_THRESHOLD;
  5808. range->max_rts = MAX_RTS_THRESHOLD;
  5809. range->min_frag = MIN_FRAG_THRESHOLD;
  5810. range->max_frag = MAX_FRAG_THRESHOLD;
  5811. range->min_pmp = period_duration[0]; /* Minimal PM period */
  5812. range->max_pmp = period_duration[POWER_MODES-1];/* Maximal PM period */
  5813. range->min_pmt = timeout_duration[POWER_MODES-1]; /* Minimal PM timeout */
  5814. range->max_pmt = timeout_duration[0];/* Maximal PM timeout */
  5815. /* How to decode max/min PM period */
  5816. range->pmp_flags = IW_POWER_PERIOD;
  5817. /* How to decode max/min PM period */
  5818. range->pmt_flags = IW_POWER_TIMEOUT;
  5819. /* What PM options are supported */
  5820. range->pm_capa = IW_POWER_TIMEOUT | IW_POWER_PERIOD;
  5821. range->encoding_size[0] = 5;
  5822. range->encoding_size[1] = 13; /* Different token sizes */
  5823. range->num_encoding_sizes = 2; /* Number of entry in the list */
  5824. range->max_encoding_tokens = WEP_KEYS; /* Max number of tokens */
  5825. // range->encoding_login_index; /* token index for login token */
  5826. if (priv->ieee->iw_mode == IW_MODE_ADHOC) {
  5827. range->txpower_capa = IW_TXPOW_DBM;
  5828. range->num_txpower = IW_MAX_TXPOWER;
  5829. for (i = 0, level = (IPW_TX_POWER_MAX_DBM * 16); i < IW_MAX_TXPOWER;
  5830. i++, level -= ((IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM) * 16) /
  5831. (IW_MAX_TXPOWER - 1))
  5832. range->txpower[i] = level / 16;
  5833. } else {
  5834. range->txpower_capa = 0;
  5835. range->num_txpower = 0;
  5836. }
  5837. /* Set the Wireless Extension versions */
  5838. range->we_version_compiled = WIRELESS_EXT;
  5839. range->we_version_source = 16;
  5840. // range->retry_capa; /* What retry options are supported */
  5841. // range->retry_flags; /* How to decode max/min retry limit */
  5842. // range->r_time_flags; /* How to decode max/min retry life */
  5843. // range->min_retry; /* Minimal number of retries */
  5844. // range->max_retry; /* Maximal number of retries */
  5845. // range->min_r_time; /* Minimal retry lifetime */
  5846. // range->max_r_time; /* Maximal retry lifetime */
  5847. range->num_channels = FREQ_COUNT;
  5848. val = 0;
  5849. for (i = 0; i < FREQ_COUNT; i++) {
  5850. // TODO: Include only legal frequencies for some countries
  5851. // if (local->channel_mask & (1 << i)) {
  5852. range->freq[val].i = i + 1;
  5853. range->freq[val].m = ipw2100_frequencies[i] * 100000;
  5854. range->freq[val].e = 1;
  5855. val++;
  5856. // }
  5857. if (val == IW_MAX_FREQUENCIES)
  5858. break;
  5859. }
  5860. range->num_frequency = val;
  5861. IPW_DEBUG_WX("GET Range\n");
  5862. return 0;
  5863. }
  5864. static int ipw2100_wx_set_wap(struct net_device *dev,
  5865. struct iw_request_info *info,
  5866. union iwreq_data *wrqu, char *extra)
  5867. {
  5868. struct ipw2100_priv *priv = ieee80211_priv(dev);
  5869. int err = 0;
  5870. static const unsigned char any[] = {
  5871. 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
  5872. };
  5873. static const unsigned char off[] = {
  5874. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
  5875. };
  5876. // sanity checks
  5877. if (wrqu->ap_addr.sa_family != ARPHRD_ETHER)
  5878. return -EINVAL;
  5879. down(&priv->action_sem);
  5880. if (!(priv->status & STATUS_INITIALIZED)) {
  5881. err = -EIO;
  5882. goto done;
  5883. }
  5884. if (!memcmp(any, wrqu->ap_addr.sa_data, ETH_ALEN) ||
  5885. !memcmp(off, wrqu->ap_addr.sa_data, ETH_ALEN)) {
  5886. /* we disable mandatory BSSID association */
  5887. IPW_DEBUG_WX("exit - disable mandatory BSSID\n");
  5888. priv->config &= ~CFG_STATIC_BSSID;
  5889. err = ipw2100_set_mandatory_bssid(priv, NULL, 0);
  5890. goto done;
  5891. }
  5892. priv->config |= CFG_STATIC_BSSID;
  5893. memcpy(priv->mandatory_bssid_mac, wrqu->ap_addr.sa_data, ETH_ALEN);
  5894. err = ipw2100_set_mandatory_bssid(priv, wrqu->ap_addr.sa_data, 0);
  5895. IPW_DEBUG_WX("SET BSSID -> %02X:%02X:%02X:%02X:%02X:%02X\n",
  5896. wrqu->ap_addr.sa_data[0] & 0xff,
  5897. wrqu->ap_addr.sa_data[1] & 0xff,
  5898. wrqu->ap_addr.sa_data[2] & 0xff,
  5899. wrqu->ap_addr.sa_data[3] & 0xff,
  5900. wrqu->ap_addr.sa_data[4] & 0xff,
  5901. wrqu->ap_addr.sa_data[5] & 0xff);
  5902. done:
  5903. up(&priv->action_sem);
  5904. return err;
  5905. }
  5906. static int ipw2100_wx_get_wap(struct net_device *dev,
  5907. struct iw_request_info *info,
  5908. union iwreq_data *wrqu, char *extra)
  5909. {
  5910. /*
  5911. * This can be called at any time. No action lock required
  5912. */
  5913. struct ipw2100_priv *priv = ieee80211_priv(dev);
  5914. /* If we are associated, trying to associate, or have a statically
  5915. * configured BSSID then return that; otherwise return ANY */
  5916. if (priv->config & CFG_STATIC_BSSID ||
  5917. priv->status & STATUS_ASSOCIATED) {
  5918. wrqu->ap_addr.sa_family = ARPHRD_ETHER;
  5919. memcpy(wrqu->ap_addr.sa_data, &priv->bssid, ETH_ALEN);
  5920. } else
  5921. memset(wrqu->ap_addr.sa_data, 0, ETH_ALEN);
  5922. IPW_DEBUG_WX("Getting WAP BSSID: " MAC_FMT "\n",
  5923. MAC_ARG(wrqu->ap_addr.sa_data));
  5924. return 0;
  5925. }
  5926. static int ipw2100_wx_set_essid(struct net_device *dev,
  5927. struct iw_request_info *info,
  5928. union iwreq_data *wrqu, char *extra)
  5929. {
  5930. struct ipw2100_priv *priv = ieee80211_priv(dev);
  5931. char *essid = ""; /* ANY */
  5932. int length = 0;
  5933. int err = 0;
  5934. down(&priv->action_sem);
  5935. if (!(priv->status & STATUS_INITIALIZED)) {
  5936. err = -EIO;
  5937. goto done;
  5938. }
  5939. if (wrqu->essid.flags && wrqu->essid.length) {
  5940. length = wrqu->essid.length - 1;
  5941. essid = extra;
  5942. }
  5943. if (length == 0) {
  5944. IPW_DEBUG_WX("Setting ESSID to ANY\n");
  5945. priv->config &= ~CFG_STATIC_ESSID;
  5946. err = ipw2100_set_essid(priv, NULL, 0, 0);
  5947. goto done;
  5948. }
  5949. length = min(length, IW_ESSID_MAX_SIZE);
  5950. priv->config |= CFG_STATIC_ESSID;
  5951. if (priv->essid_len == length && !memcmp(priv->essid, extra, length)) {
  5952. IPW_DEBUG_WX("ESSID set to current ESSID.\n");
  5953. err = 0;
  5954. goto done;
  5955. }
  5956. IPW_DEBUG_WX("Setting ESSID: '%s' (%d)\n", escape_essid(essid, length),
  5957. length);
  5958. priv->essid_len = length;
  5959. memcpy(priv->essid, essid, priv->essid_len);
  5960. err = ipw2100_set_essid(priv, essid, length, 0);
  5961. done:
  5962. up(&priv->action_sem);
  5963. return err;
  5964. }
  5965. static int ipw2100_wx_get_essid(struct net_device *dev,
  5966. struct iw_request_info *info,
  5967. union iwreq_data *wrqu, char *extra)
  5968. {
  5969. /*
  5970. * This can be called at any time. No action lock required
  5971. */
  5972. struct ipw2100_priv *priv = ieee80211_priv(dev);
  5973. /* If we are associated, trying to associate, or have a statically
  5974. * configured ESSID then return that; otherwise return ANY */
  5975. if (priv->config & CFG_STATIC_ESSID ||
  5976. priv->status & STATUS_ASSOCIATED) {
  5977. IPW_DEBUG_WX("Getting essid: '%s'\n",
  5978. escape_essid(priv->essid, priv->essid_len));
  5979. memcpy(extra, priv->essid, priv->essid_len);
  5980. wrqu->essid.length = priv->essid_len;
  5981. wrqu->essid.flags = 1; /* active */
  5982. } else {
  5983. IPW_DEBUG_WX("Getting essid: ANY\n");
  5984. wrqu->essid.length = 0;
  5985. wrqu->essid.flags = 0; /* active */
  5986. }
  5987. return 0;
  5988. }
  5989. static int ipw2100_wx_set_nick(struct net_device *dev,
  5990. struct iw_request_info *info,
  5991. union iwreq_data *wrqu, char *extra)
  5992. {
  5993. /*
  5994. * This can be called at any time. No action lock required
  5995. */
  5996. struct ipw2100_priv *priv = ieee80211_priv(dev);
  5997. if (wrqu->data.length > IW_ESSID_MAX_SIZE)
  5998. return -E2BIG;
  5999. wrqu->data.length = min((size_t)wrqu->data.length, sizeof(priv->nick));
  6000. memset(priv->nick, 0, sizeof(priv->nick));
  6001. memcpy(priv->nick, extra, wrqu->data.length);
  6002. IPW_DEBUG_WX("SET Nickname -> %s \n", priv->nick);
  6003. return 0;
  6004. }
  6005. static int ipw2100_wx_get_nick(struct net_device *dev,
  6006. struct iw_request_info *info,
  6007. union iwreq_data *wrqu, char *extra)
  6008. {
  6009. /*
  6010. * This can be called at any time. No action lock required
  6011. */
  6012. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6013. wrqu->data.length = strlen(priv->nick) + 1;
  6014. memcpy(extra, priv->nick, wrqu->data.length);
  6015. wrqu->data.flags = 1; /* active */
  6016. IPW_DEBUG_WX("GET Nickname -> %s \n", extra);
  6017. return 0;
  6018. }
  6019. static int ipw2100_wx_set_rate(struct net_device *dev,
  6020. struct iw_request_info *info,
  6021. union iwreq_data *wrqu, char *extra)
  6022. {
  6023. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6024. u32 target_rate = wrqu->bitrate.value;
  6025. u32 rate;
  6026. int err = 0;
  6027. down(&priv->action_sem);
  6028. if (!(priv->status & STATUS_INITIALIZED)) {
  6029. err = -EIO;
  6030. goto done;
  6031. }
  6032. rate = 0;
  6033. if (target_rate == 1000000 ||
  6034. (!wrqu->bitrate.fixed && target_rate > 1000000))
  6035. rate |= TX_RATE_1_MBIT;
  6036. if (target_rate == 2000000 ||
  6037. (!wrqu->bitrate.fixed && target_rate > 2000000))
  6038. rate |= TX_RATE_2_MBIT;
  6039. if (target_rate == 5500000 ||
  6040. (!wrqu->bitrate.fixed && target_rate > 5500000))
  6041. rate |= TX_RATE_5_5_MBIT;
  6042. if (target_rate == 11000000 ||
  6043. (!wrqu->bitrate.fixed && target_rate > 11000000))
  6044. rate |= TX_RATE_11_MBIT;
  6045. if (rate == 0)
  6046. rate = DEFAULT_TX_RATES;
  6047. err = ipw2100_set_tx_rates(priv, rate, 0);
  6048. IPW_DEBUG_WX("SET Rate -> %04X \n", rate);
  6049. done:
  6050. up(&priv->action_sem);
  6051. return err;
  6052. }
  6053. static int ipw2100_wx_get_rate(struct net_device *dev,
  6054. struct iw_request_info *info,
  6055. union iwreq_data *wrqu, char *extra)
  6056. {
  6057. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6058. int val;
  6059. int len = sizeof(val);
  6060. int err = 0;
  6061. if (!(priv->status & STATUS_ENABLED) ||
  6062. priv->status & STATUS_RF_KILL_MASK ||
  6063. !(priv->status & STATUS_ASSOCIATED)) {
  6064. wrqu->bitrate.value = 0;
  6065. return 0;
  6066. }
  6067. down(&priv->action_sem);
  6068. if (!(priv->status & STATUS_INITIALIZED)) {
  6069. err = -EIO;
  6070. goto done;
  6071. }
  6072. err = ipw2100_get_ordinal(priv, IPW_ORD_CURRENT_TX_RATE, &val, &len);
  6073. if (err) {
  6074. IPW_DEBUG_WX("failed querying ordinals.\n");
  6075. return err;
  6076. }
  6077. switch (val & TX_RATE_MASK) {
  6078. case TX_RATE_1_MBIT:
  6079. wrqu->bitrate.value = 1000000;
  6080. break;
  6081. case TX_RATE_2_MBIT:
  6082. wrqu->bitrate.value = 2000000;
  6083. break;
  6084. case TX_RATE_5_5_MBIT:
  6085. wrqu->bitrate.value = 5500000;
  6086. break;
  6087. case TX_RATE_11_MBIT:
  6088. wrqu->bitrate.value = 11000000;
  6089. break;
  6090. default:
  6091. wrqu->bitrate.value = 0;
  6092. }
  6093. IPW_DEBUG_WX("GET Rate -> %d \n", wrqu->bitrate.value);
  6094. done:
  6095. up(&priv->action_sem);
  6096. return err;
  6097. }
  6098. static int ipw2100_wx_set_rts(struct net_device *dev,
  6099. struct iw_request_info *info,
  6100. union iwreq_data *wrqu, char *extra)
  6101. {
  6102. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6103. int value, err;
  6104. /* Auto RTS not yet supported */
  6105. if (wrqu->rts.fixed == 0)
  6106. return -EINVAL;
  6107. down(&priv->action_sem);
  6108. if (!(priv->status & STATUS_INITIALIZED)) {
  6109. err = -EIO;
  6110. goto done;
  6111. }
  6112. if (wrqu->rts.disabled)
  6113. value = priv->rts_threshold | RTS_DISABLED;
  6114. else {
  6115. if (wrqu->rts.value < 1 ||
  6116. wrqu->rts.value > 2304) {
  6117. err = -EINVAL;
  6118. goto done;
  6119. }
  6120. value = wrqu->rts.value;
  6121. }
  6122. err = ipw2100_set_rts_threshold(priv, value);
  6123. IPW_DEBUG_WX("SET RTS Threshold -> 0x%08X \n", value);
  6124. done:
  6125. up(&priv->action_sem);
  6126. return err;
  6127. }
  6128. static int ipw2100_wx_get_rts(struct net_device *dev,
  6129. struct iw_request_info *info,
  6130. union iwreq_data *wrqu, char *extra)
  6131. {
  6132. /*
  6133. * This can be called at any time. No action lock required
  6134. */
  6135. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6136. wrqu->rts.value = priv->rts_threshold & ~RTS_DISABLED;
  6137. wrqu->rts.fixed = 1; /* no auto select */
  6138. /* If RTS is set to the default value, then it is disabled */
  6139. wrqu->rts.disabled = (priv->rts_threshold & RTS_DISABLED) ? 1 : 0;
  6140. IPW_DEBUG_WX("GET RTS Threshold -> 0x%08X \n", wrqu->rts.value);
  6141. return 0;
  6142. }
  6143. static int ipw2100_wx_set_txpow(struct net_device *dev,
  6144. struct iw_request_info *info,
  6145. union iwreq_data *wrqu, char *extra)
  6146. {
  6147. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6148. int err = 0, value;
  6149. if (priv->ieee->iw_mode != IW_MODE_ADHOC)
  6150. return -EINVAL;
  6151. if (wrqu->txpower.disabled == 1 || wrqu->txpower.fixed == 0)
  6152. value = IPW_TX_POWER_DEFAULT;
  6153. else {
  6154. if (wrqu->txpower.value < IPW_TX_POWER_MIN_DBM ||
  6155. wrqu->txpower.value > IPW_TX_POWER_MAX_DBM)
  6156. return -EINVAL;
  6157. value = (wrqu->txpower.value - IPW_TX_POWER_MIN_DBM) * 16 /
  6158. (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM);
  6159. }
  6160. down(&priv->action_sem);
  6161. if (!(priv->status & STATUS_INITIALIZED)) {
  6162. err = -EIO;
  6163. goto done;
  6164. }
  6165. err = ipw2100_set_tx_power(priv, value);
  6166. IPW_DEBUG_WX("SET TX Power -> %d \n", value);
  6167. done:
  6168. up(&priv->action_sem);
  6169. return err;
  6170. }
  6171. static int ipw2100_wx_get_txpow(struct net_device *dev,
  6172. struct iw_request_info *info,
  6173. union iwreq_data *wrqu, char *extra)
  6174. {
  6175. /*
  6176. * This can be called at any time. No action lock required
  6177. */
  6178. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6179. if (priv->ieee->iw_mode != IW_MODE_ADHOC) {
  6180. wrqu->power.disabled = 1;
  6181. return 0;
  6182. }
  6183. if (priv->tx_power == IPW_TX_POWER_DEFAULT) {
  6184. wrqu->power.fixed = 0;
  6185. wrqu->power.value = IPW_TX_POWER_MAX_DBM;
  6186. wrqu->power.disabled = 1;
  6187. } else {
  6188. wrqu->power.disabled = 0;
  6189. wrqu->power.fixed = 1;
  6190. wrqu->power.value =
  6191. (priv->tx_power *
  6192. (IPW_TX_POWER_MAX_DBM - IPW_TX_POWER_MIN_DBM)) /
  6193. (IPW_TX_POWER_MAX - IPW_TX_POWER_MIN) +
  6194. IPW_TX_POWER_MIN_DBM;
  6195. }
  6196. wrqu->power.flags = IW_TXPOW_DBM;
  6197. IPW_DEBUG_WX("GET TX Power -> %d \n", wrqu->power.value);
  6198. return 0;
  6199. }
  6200. static int ipw2100_wx_set_frag(struct net_device *dev,
  6201. struct iw_request_info *info,
  6202. union iwreq_data *wrqu, char *extra)
  6203. {
  6204. /*
  6205. * This can be called at any time. No action lock required
  6206. */
  6207. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6208. if (!wrqu->frag.fixed)
  6209. return -EINVAL;
  6210. if (wrqu->frag.disabled) {
  6211. priv->frag_threshold |= FRAG_DISABLED;
  6212. priv->ieee->fts = DEFAULT_FTS;
  6213. } else {
  6214. if (wrqu->frag.value < MIN_FRAG_THRESHOLD ||
  6215. wrqu->frag.value > MAX_FRAG_THRESHOLD)
  6216. return -EINVAL;
  6217. priv->ieee->fts = wrqu->frag.value & ~0x1;
  6218. priv->frag_threshold = priv->ieee->fts;
  6219. }
  6220. IPW_DEBUG_WX("SET Frag Threshold -> %d \n", priv->ieee->fts);
  6221. return 0;
  6222. }
  6223. static int ipw2100_wx_get_frag(struct net_device *dev,
  6224. struct iw_request_info *info,
  6225. union iwreq_data *wrqu, char *extra)
  6226. {
  6227. /*
  6228. * This can be called at any time. No action lock required
  6229. */
  6230. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6231. wrqu->frag.value = priv->frag_threshold & ~FRAG_DISABLED;
  6232. wrqu->frag.fixed = 0; /* no auto select */
  6233. wrqu->frag.disabled = (priv->frag_threshold & FRAG_DISABLED) ? 1 : 0;
  6234. IPW_DEBUG_WX("GET Frag Threshold -> %d \n", wrqu->frag.value);
  6235. return 0;
  6236. }
  6237. static int ipw2100_wx_set_retry(struct net_device *dev,
  6238. struct iw_request_info *info,
  6239. union iwreq_data *wrqu, char *extra)
  6240. {
  6241. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6242. int err = 0;
  6243. if (wrqu->retry.flags & IW_RETRY_LIFETIME ||
  6244. wrqu->retry.disabled)
  6245. return -EINVAL;
  6246. if (!(wrqu->retry.flags & IW_RETRY_LIMIT))
  6247. return 0;
  6248. down(&priv->action_sem);
  6249. if (!(priv->status & STATUS_INITIALIZED)) {
  6250. err = -EIO;
  6251. goto done;
  6252. }
  6253. if (wrqu->retry.flags & IW_RETRY_MIN) {
  6254. err = ipw2100_set_short_retry(priv, wrqu->retry.value);
  6255. IPW_DEBUG_WX("SET Short Retry Limit -> %d \n",
  6256. wrqu->retry.value);
  6257. goto done;
  6258. }
  6259. if (wrqu->retry.flags & IW_RETRY_MAX) {
  6260. err = ipw2100_set_long_retry(priv, wrqu->retry.value);
  6261. IPW_DEBUG_WX("SET Long Retry Limit -> %d \n",
  6262. wrqu->retry.value);
  6263. goto done;
  6264. }
  6265. err = ipw2100_set_short_retry(priv, wrqu->retry.value);
  6266. if (!err)
  6267. err = ipw2100_set_long_retry(priv, wrqu->retry.value);
  6268. IPW_DEBUG_WX("SET Both Retry Limits -> %d \n", wrqu->retry.value);
  6269. done:
  6270. up(&priv->action_sem);
  6271. return err;
  6272. }
  6273. static int ipw2100_wx_get_retry(struct net_device *dev,
  6274. struct iw_request_info *info,
  6275. union iwreq_data *wrqu, char *extra)
  6276. {
  6277. /*
  6278. * This can be called at any time. No action lock required
  6279. */
  6280. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6281. wrqu->retry.disabled = 0; /* can't be disabled */
  6282. if ((wrqu->retry.flags & IW_RETRY_TYPE) ==
  6283. IW_RETRY_LIFETIME)
  6284. return -EINVAL;
  6285. if (wrqu->retry.flags & IW_RETRY_MAX) {
  6286. wrqu->retry.flags = IW_RETRY_LIMIT & IW_RETRY_MAX;
  6287. wrqu->retry.value = priv->long_retry_limit;
  6288. } else {
  6289. wrqu->retry.flags =
  6290. (priv->short_retry_limit !=
  6291. priv->long_retry_limit) ?
  6292. IW_RETRY_LIMIT & IW_RETRY_MIN : IW_RETRY_LIMIT;
  6293. wrqu->retry.value = priv->short_retry_limit;
  6294. }
  6295. IPW_DEBUG_WX("GET Retry -> %d \n", wrqu->retry.value);
  6296. return 0;
  6297. }
  6298. static int ipw2100_wx_set_scan(struct net_device *dev,
  6299. struct iw_request_info *info,
  6300. union iwreq_data *wrqu, char *extra)
  6301. {
  6302. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6303. int err = 0;
  6304. down(&priv->action_sem);
  6305. if (!(priv->status & STATUS_INITIALIZED)) {
  6306. err = -EIO;
  6307. goto done;
  6308. }
  6309. IPW_DEBUG_WX("Initiating scan...\n");
  6310. if (ipw2100_set_scan_options(priv) ||
  6311. ipw2100_start_scan(priv)) {
  6312. IPW_DEBUG_WX("Start scan failed.\n");
  6313. /* TODO: Mark a scan as pending so when hardware initialized
  6314. * a scan starts */
  6315. }
  6316. done:
  6317. up(&priv->action_sem);
  6318. return err;
  6319. }
  6320. static int ipw2100_wx_get_scan(struct net_device *dev,
  6321. struct iw_request_info *info,
  6322. union iwreq_data *wrqu, char *extra)
  6323. {
  6324. /*
  6325. * This can be called at any time. No action lock required
  6326. */
  6327. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6328. return ieee80211_wx_get_scan(priv->ieee, info, wrqu, extra);
  6329. }
  6330. /*
  6331. * Implementation based on code in hostap-driver v0.1.3 hostap_ioctl.c
  6332. */
  6333. static int ipw2100_wx_set_encode(struct net_device *dev,
  6334. struct iw_request_info *info,
  6335. union iwreq_data *wrqu, char *key)
  6336. {
  6337. /*
  6338. * No check of STATUS_INITIALIZED required
  6339. */
  6340. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6341. return ieee80211_wx_set_encode(priv->ieee, info, wrqu, key);
  6342. }
  6343. static int ipw2100_wx_get_encode(struct net_device *dev,
  6344. struct iw_request_info *info,
  6345. union iwreq_data *wrqu, char *key)
  6346. {
  6347. /*
  6348. * This can be called at any time. No action lock required
  6349. */
  6350. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6351. return ieee80211_wx_get_encode(priv->ieee, info, wrqu, key);
  6352. }
  6353. static int ipw2100_wx_set_power(struct net_device *dev,
  6354. struct iw_request_info *info,
  6355. union iwreq_data *wrqu, char *extra)
  6356. {
  6357. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6358. int err = 0;
  6359. down(&priv->action_sem);
  6360. if (!(priv->status & STATUS_INITIALIZED)) {
  6361. err = -EIO;
  6362. goto done;
  6363. }
  6364. if (wrqu->power.disabled) {
  6365. priv->power_mode = IPW_POWER_LEVEL(priv->power_mode);
  6366. err = ipw2100_set_power_mode(priv, IPW_POWER_MODE_CAM);
  6367. IPW_DEBUG_WX("SET Power Management Mode -> off\n");
  6368. goto done;
  6369. }
  6370. switch (wrqu->power.flags & IW_POWER_MODE) {
  6371. case IW_POWER_ON: /* If not specified */
  6372. case IW_POWER_MODE: /* If set all mask */
  6373. case IW_POWER_ALL_R: /* If explicitely state all */
  6374. break;
  6375. default: /* Otherwise we don't support it */
  6376. IPW_DEBUG_WX("SET PM Mode: %X not supported.\n",
  6377. wrqu->power.flags);
  6378. err = -EOPNOTSUPP;
  6379. goto done;
  6380. }
  6381. /* If the user hasn't specified a power management mode yet, default
  6382. * to BATTERY */
  6383. priv->power_mode = IPW_POWER_ENABLED | priv->power_mode;
  6384. err = ipw2100_set_power_mode(priv, IPW_POWER_LEVEL(priv->power_mode));
  6385. IPW_DEBUG_WX("SET Power Management Mode -> 0x%02X\n",
  6386. priv->power_mode);
  6387. done:
  6388. up(&priv->action_sem);
  6389. return err;
  6390. }
  6391. static int ipw2100_wx_get_power(struct net_device *dev,
  6392. struct iw_request_info *info,
  6393. union iwreq_data *wrqu, char *extra)
  6394. {
  6395. /*
  6396. * This can be called at any time. No action lock required
  6397. */
  6398. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6399. if (!(priv->power_mode & IPW_POWER_ENABLED)) {
  6400. wrqu->power.disabled = 1;
  6401. } else {
  6402. wrqu->power.disabled = 0;
  6403. wrqu->power.flags = 0;
  6404. }
  6405. IPW_DEBUG_WX("GET Power Management Mode -> %02X\n", priv->power_mode);
  6406. return 0;
  6407. }
  6408. /*
  6409. *
  6410. * IWPRIV handlers
  6411. *
  6412. */
  6413. #ifdef CONFIG_IPW2100_MONITOR
  6414. static int ipw2100_wx_set_promisc(struct net_device *dev,
  6415. struct iw_request_info *info,
  6416. union iwreq_data *wrqu, char *extra)
  6417. {
  6418. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6419. int *parms = (int *)extra;
  6420. int enable = (parms[0] > 0);
  6421. int err = 0;
  6422. down(&priv->action_sem);
  6423. if (!(priv->status & STATUS_INITIALIZED)) {
  6424. err = -EIO;
  6425. goto done;
  6426. }
  6427. if (enable) {
  6428. if (priv->ieee->iw_mode == IW_MODE_MONITOR) {
  6429. err = ipw2100_set_channel(priv, parms[1], 0);
  6430. goto done;
  6431. }
  6432. priv->channel = parms[1];
  6433. err = ipw2100_switch_mode(priv, IW_MODE_MONITOR);
  6434. } else {
  6435. if (priv->ieee->iw_mode == IW_MODE_MONITOR)
  6436. err = ipw2100_switch_mode(priv, priv->last_mode);
  6437. }
  6438. done:
  6439. up(&priv->action_sem);
  6440. return err;
  6441. }
  6442. static int ipw2100_wx_reset(struct net_device *dev,
  6443. struct iw_request_info *info,
  6444. union iwreq_data *wrqu, char *extra)
  6445. {
  6446. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6447. if (priv->status & STATUS_INITIALIZED)
  6448. schedule_reset(priv);
  6449. return 0;
  6450. }
  6451. #endif
  6452. static int ipw2100_wx_set_powermode(struct net_device *dev,
  6453. struct iw_request_info *info,
  6454. union iwreq_data *wrqu, char *extra)
  6455. {
  6456. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6457. int err = 0, mode = *(int *)extra;
  6458. down(&priv->action_sem);
  6459. if (!(priv->status & STATUS_INITIALIZED)) {
  6460. err = -EIO;
  6461. goto done;
  6462. }
  6463. if ((mode < 1) || (mode > POWER_MODES))
  6464. mode = IPW_POWER_AUTO;
  6465. if (priv->power_mode != mode)
  6466. err = ipw2100_set_power_mode(priv, mode);
  6467. done:
  6468. up(&priv->action_sem);
  6469. return err;
  6470. }
  6471. #define MAX_POWER_STRING 80
  6472. static int ipw2100_wx_get_powermode(struct net_device *dev,
  6473. struct iw_request_info *info,
  6474. union iwreq_data *wrqu, char *extra)
  6475. {
  6476. /*
  6477. * This can be called at any time. No action lock required
  6478. */
  6479. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6480. int level = IPW_POWER_LEVEL(priv->power_mode);
  6481. s32 timeout, period;
  6482. if (!(priv->power_mode & IPW_POWER_ENABLED)) {
  6483. snprintf(extra, MAX_POWER_STRING,
  6484. "Power save level: %d (Off)", level);
  6485. } else {
  6486. switch (level) {
  6487. case IPW_POWER_MODE_CAM:
  6488. snprintf(extra, MAX_POWER_STRING,
  6489. "Power save level: %d (None)", level);
  6490. break;
  6491. case IPW_POWER_AUTO:
  6492. snprintf(extra, MAX_POWER_STRING,
  6493. "Power save level: %d (Auto)", 0);
  6494. break;
  6495. default:
  6496. timeout = timeout_duration[level - 1] / 1000;
  6497. period = period_duration[level - 1] / 1000;
  6498. snprintf(extra, MAX_POWER_STRING,
  6499. "Power save level: %d "
  6500. "(Timeout %dms, Period %dms)",
  6501. level, timeout, period);
  6502. }
  6503. }
  6504. wrqu->data.length = strlen(extra) + 1;
  6505. return 0;
  6506. }
  6507. static int ipw2100_wx_set_preamble(struct net_device *dev,
  6508. struct iw_request_info *info,
  6509. union iwreq_data *wrqu, char *extra)
  6510. {
  6511. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6512. int err, mode = *(int *)extra;
  6513. down(&priv->action_sem);
  6514. if (!(priv->status & STATUS_INITIALIZED)) {
  6515. err = -EIO;
  6516. goto done;
  6517. }
  6518. if (mode == 1)
  6519. priv->config |= CFG_LONG_PREAMBLE;
  6520. else if (mode == 0)
  6521. priv->config &= ~CFG_LONG_PREAMBLE;
  6522. else {
  6523. err = -EINVAL;
  6524. goto done;
  6525. }
  6526. err = ipw2100_system_config(priv, 0);
  6527. done:
  6528. up(&priv->action_sem);
  6529. return err;
  6530. }
  6531. static int ipw2100_wx_get_preamble(struct net_device *dev,
  6532. struct iw_request_info *info,
  6533. union iwreq_data *wrqu, char *extra)
  6534. {
  6535. /*
  6536. * This can be called at any time. No action lock required
  6537. */
  6538. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6539. if (priv->config & CFG_LONG_PREAMBLE)
  6540. snprintf(wrqu->name, IFNAMSIZ, "long (1)");
  6541. else
  6542. snprintf(wrqu->name, IFNAMSIZ, "auto (0)");
  6543. return 0;
  6544. }
  6545. static iw_handler ipw2100_wx_handlers[] =
  6546. {
  6547. NULL, /* SIOCSIWCOMMIT */
  6548. ipw2100_wx_get_name, /* SIOCGIWNAME */
  6549. NULL, /* SIOCSIWNWID */
  6550. NULL, /* SIOCGIWNWID */
  6551. ipw2100_wx_set_freq, /* SIOCSIWFREQ */
  6552. ipw2100_wx_get_freq, /* SIOCGIWFREQ */
  6553. ipw2100_wx_set_mode, /* SIOCSIWMODE */
  6554. ipw2100_wx_get_mode, /* SIOCGIWMODE */
  6555. NULL, /* SIOCSIWSENS */
  6556. NULL, /* SIOCGIWSENS */
  6557. NULL, /* SIOCSIWRANGE */
  6558. ipw2100_wx_get_range, /* SIOCGIWRANGE */
  6559. NULL, /* SIOCSIWPRIV */
  6560. NULL, /* SIOCGIWPRIV */
  6561. NULL, /* SIOCSIWSTATS */
  6562. NULL, /* SIOCGIWSTATS */
  6563. NULL, /* SIOCSIWSPY */
  6564. NULL, /* SIOCGIWSPY */
  6565. NULL, /* SIOCGIWTHRSPY */
  6566. NULL, /* SIOCWIWTHRSPY */
  6567. ipw2100_wx_set_wap, /* SIOCSIWAP */
  6568. ipw2100_wx_get_wap, /* SIOCGIWAP */
  6569. NULL, /* -- hole -- */
  6570. NULL, /* SIOCGIWAPLIST -- deprecated */
  6571. ipw2100_wx_set_scan, /* SIOCSIWSCAN */
  6572. ipw2100_wx_get_scan, /* SIOCGIWSCAN */
  6573. ipw2100_wx_set_essid, /* SIOCSIWESSID */
  6574. ipw2100_wx_get_essid, /* SIOCGIWESSID */
  6575. ipw2100_wx_set_nick, /* SIOCSIWNICKN */
  6576. ipw2100_wx_get_nick, /* SIOCGIWNICKN */
  6577. NULL, /* -- hole -- */
  6578. NULL, /* -- hole -- */
  6579. ipw2100_wx_set_rate, /* SIOCSIWRATE */
  6580. ipw2100_wx_get_rate, /* SIOCGIWRATE */
  6581. ipw2100_wx_set_rts, /* SIOCSIWRTS */
  6582. ipw2100_wx_get_rts, /* SIOCGIWRTS */
  6583. ipw2100_wx_set_frag, /* SIOCSIWFRAG */
  6584. ipw2100_wx_get_frag, /* SIOCGIWFRAG */
  6585. ipw2100_wx_set_txpow, /* SIOCSIWTXPOW */
  6586. ipw2100_wx_get_txpow, /* SIOCGIWTXPOW */
  6587. ipw2100_wx_set_retry, /* SIOCSIWRETRY */
  6588. ipw2100_wx_get_retry, /* SIOCGIWRETRY */
  6589. ipw2100_wx_set_encode, /* SIOCSIWENCODE */
  6590. ipw2100_wx_get_encode, /* SIOCGIWENCODE */
  6591. ipw2100_wx_set_power, /* SIOCSIWPOWER */
  6592. ipw2100_wx_get_power, /* SIOCGIWPOWER */
  6593. };
  6594. #define IPW2100_PRIV_SET_MONITOR SIOCIWFIRSTPRIV
  6595. #define IPW2100_PRIV_RESET SIOCIWFIRSTPRIV+1
  6596. #define IPW2100_PRIV_SET_POWER SIOCIWFIRSTPRIV+2
  6597. #define IPW2100_PRIV_GET_POWER SIOCIWFIRSTPRIV+3
  6598. #define IPW2100_PRIV_SET_LONGPREAMBLE SIOCIWFIRSTPRIV+4
  6599. #define IPW2100_PRIV_GET_LONGPREAMBLE SIOCIWFIRSTPRIV+5
  6600. static const struct iw_priv_args ipw2100_private_args[] = {
  6601. #ifdef CONFIG_IPW2100_MONITOR
  6602. {
  6603. IPW2100_PRIV_SET_MONITOR,
  6604. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 2, 0, "monitor"
  6605. },
  6606. {
  6607. IPW2100_PRIV_RESET,
  6608. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 0, 0, "reset"
  6609. },
  6610. #endif /* CONFIG_IPW2100_MONITOR */
  6611. {
  6612. IPW2100_PRIV_SET_POWER,
  6613. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_power"
  6614. },
  6615. {
  6616. IPW2100_PRIV_GET_POWER,
  6617. 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | MAX_POWER_STRING, "get_power"
  6618. },
  6619. {
  6620. IPW2100_PRIV_SET_LONGPREAMBLE,
  6621. IW_PRIV_TYPE_INT | IW_PRIV_SIZE_FIXED | 1, 0, "set_preamble"
  6622. },
  6623. {
  6624. IPW2100_PRIV_GET_LONGPREAMBLE,
  6625. 0, IW_PRIV_TYPE_CHAR | IW_PRIV_SIZE_FIXED | IFNAMSIZ, "get_preamble"
  6626. },
  6627. };
  6628. static iw_handler ipw2100_private_handler[] = {
  6629. #ifdef CONFIG_IPW2100_MONITOR
  6630. ipw2100_wx_set_promisc,
  6631. ipw2100_wx_reset,
  6632. #else /* CONFIG_IPW2100_MONITOR */
  6633. NULL,
  6634. NULL,
  6635. #endif /* CONFIG_IPW2100_MONITOR */
  6636. ipw2100_wx_set_powermode,
  6637. ipw2100_wx_get_powermode,
  6638. ipw2100_wx_set_preamble,
  6639. ipw2100_wx_get_preamble,
  6640. };
  6641. static struct iw_handler_def ipw2100_wx_handler_def =
  6642. {
  6643. .standard = ipw2100_wx_handlers,
  6644. .num_standard = sizeof(ipw2100_wx_handlers) / sizeof(iw_handler),
  6645. .num_private = sizeof(ipw2100_private_handler) / sizeof(iw_handler),
  6646. .num_private_args = sizeof(ipw2100_private_args) /
  6647. sizeof(struct iw_priv_args),
  6648. .private = (iw_handler *)ipw2100_private_handler,
  6649. .private_args = (struct iw_priv_args *)ipw2100_private_args,
  6650. };
  6651. /*
  6652. * Get wireless statistics.
  6653. * Called by /proc/net/wireless
  6654. * Also called by SIOCGIWSTATS
  6655. */
  6656. static struct iw_statistics *ipw2100_wx_wireless_stats(struct net_device * dev)
  6657. {
  6658. enum {
  6659. POOR = 30,
  6660. FAIR = 60,
  6661. GOOD = 80,
  6662. VERY_GOOD = 90,
  6663. EXCELLENT = 95,
  6664. PERFECT = 100
  6665. };
  6666. int rssi_qual;
  6667. int tx_qual;
  6668. int beacon_qual;
  6669. struct ipw2100_priv *priv = ieee80211_priv(dev);
  6670. struct iw_statistics *wstats;
  6671. u32 rssi, quality, tx_retries, missed_beacons, tx_failures;
  6672. u32 ord_len = sizeof(u32);
  6673. if (!priv)
  6674. return (struct iw_statistics *) NULL;
  6675. wstats = &priv->wstats;
  6676. /* if hw is disabled, then ipw2100_get_ordinal() can't be called.
  6677. * ipw2100_wx_wireless_stats seems to be called before fw is
  6678. * initialized. STATUS_ASSOCIATED will only be set if the hw is up
  6679. * and associated; if not associcated, the values are all meaningless
  6680. * anyway, so set them all to NULL and INVALID */
  6681. if (!(priv->status & STATUS_ASSOCIATED)) {
  6682. wstats->miss.beacon = 0;
  6683. wstats->discard.retries = 0;
  6684. wstats->qual.qual = 0;
  6685. wstats->qual.level = 0;
  6686. wstats->qual.noise = 0;
  6687. wstats->qual.updated = 7;
  6688. wstats->qual.updated |= IW_QUAL_NOISE_INVALID |
  6689. IW_QUAL_QUAL_INVALID | IW_QUAL_LEVEL_INVALID;
  6690. return wstats;
  6691. }
  6692. if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_MISSED_BCNS,
  6693. &missed_beacons, &ord_len))
  6694. goto fail_get_ordinal;
  6695. /* If we don't have a connection the quality and level is 0*/
  6696. if (!(priv->status & STATUS_ASSOCIATED)) {
  6697. wstats->qual.qual = 0;
  6698. wstats->qual.level = 0;
  6699. } else {
  6700. if (ipw2100_get_ordinal(priv, IPW_ORD_RSSI_AVG_CURR,
  6701. &rssi, &ord_len))
  6702. goto fail_get_ordinal;
  6703. wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
  6704. if (rssi < 10)
  6705. rssi_qual = rssi * POOR / 10;
  6706. else if (rssi < 15)
  6707. rssi_qual = (rssi - 10) * (FAIR - POOR) / 5 + POOR;
  6708. else if (rssi < 20)
  6709. rssi_qual = (rssi - 15) * (GOOD - FAIR) / 5 + FAIR;
  6710. else if (rssi < 30)
  6711. rssi_qual = (rssi - 20) * (VERY_GOOD - GOOD) /
  6712. 10 + GOOD;
  6713. else
  6714. rssi_qual = (rssi - 30) * (PERFECT - VERY_GOOD) /
  6715. 10 + VERY_GOOD;
  6716. if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_PERCENT_RETRIES,
  6717. &tx_retries, &ord_len))
  6718. goto fail_get_ordinal;
  6719. if (tx_retries > 75)
  6720. tx_qual = (90 - tx_retries) * POOR / 15;
  6721. else if (tx_retries > 70)
  6722. tx_qual = (75 - tx_retries) * (FAIR - POOR) / 5 + POOR;
  6723. else if (tx_retries > 65)
  6724. tx_qual = (70 - tx_retries) * (GOOD - FAIR) / 5 + FAIR;
  6725. else if (tx_retries > 50)
  6726. tx_qual = (65 - tx_retries) * (VERY_GOOD - GOOD) /
  6727. 15 + GOOD;
  6728. else
  6729. tx_qual = (50 - tx_retries) *
  6730. (PERFECT - VERY_GOOD) / 50 + VERY_GOOD;
  6731. if (missed_beacons > 50)
  6732. beacon_qual = (60 - missed_beacons) * POOR / 10;
  6733. else if (missed_beacons > 40)
  6734. beacon_qual = (50 - missed_beacons) * (FAIR - POOR) /
  6735. 10 + POOR;
  6736. else if (missed_beacons > 32)
  6737. beacon_qual = (40 - missed_beacons) * (GOOD - FAIR) /
  6738. 18 + FAIR;
  6739. else if (missed_beacons > 20)
  6740. beacon_qual = (32 - missed_beacons) *
  6741. (VERY_GOOD - GOOD) / 20 + GOOD;
  6742. else
  6743. beacon_qual = (20 - missed_beacons) *
  6744. (PERFECT - VERY_GOOD) / 20 + VERY_GOOD;
  6745. quality = min(beacon_qual, min(tx_qual, rssi_qual));
  6746. #ifdef CONFIG_IPW_DEBUG
  6747. if (beacon_qual == quality)
  6748. IPW_DEBUG_WX("Quality clamped by Missed Beacons\n");
  6749. else if (tx_qual == quality)
  6750. IPW_DEBUG_WX("Quality clamped by Tx Retries\n");
  6751. else if (quality != 100)
  6752. IPW_DEBUG_WX("Quality clamped by Signal Strength\n");
  6753. else
  6754. IPW_DEBUG_WX("Quality not clamped.\n");
  6755. #endif
  6756. wstats->qual.qual = quality;
  6757. wstats->qual.level = rssi + IPW2100_RSSI_TO_DBM;
  6758. }
  6759. wstats->qual.noise = 0;
  6760. wstats->qual.updated = 7;
  6761. wstats->qual.updated |= IW_QUAL_NOISE_INVALID;
  6762. /* FIXME: this is percent and not a # */
  6763. wstats->miss.beacon = missed_beacons;
  6764. if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_TX_FAILURES,
  6765. &tx_failures, &ord_len))
  6766. goto fail_get_ordinal;
  6767. wstats->discard.retries = tx_failures;
  6768. return wstats;
  6769. fail_get_ordinal:
  6770. IPW_DEBUG_WX("failed querying ordinals.\n");
  6771. return (struct iw_statistics *) NULL;
  6772. }
  6773. static void ipw2100_wx_event_work(struct ipw2100_priv *priv)
  6774. {
  6775. union iwreq_data wrqu;
  6776. int len = ETH_ALEN;
  6777. if (priv->status & STATUS_STOPPING)
  6778. return;
  6779. down(&priv->action_sem);
  6780. IPW_DEBUG_WX("enter\n");
  6781. up(&priv->action_sem);
  6782. wrqu.ap_addr.sa_family = ARPHRD_ETHER;
  6783. /* Fetch BSSID from the hardware */
  6784. if (!(priv->status & (STATUS_ASSOCIATING | STATUS_ASSOCIATED)) ||
  6785. priv->status & STATUS_RF_KILL_MASK ||
  6786. ipw2100_get_ordinal(priv, IPW_ORD_STAT_ASSN_AP_BSSID,
  6787. &priv->bssid, &len)) {
  6788. memset(wrqu.ap_addr.sa_data, 0, ETH_ALEN);
  6789. } else {
  6790. /* We now have the BSSID, so can finish setting to the full
  6791. * associated state */
  6792. memcpy(wrqu.ap_addr.sa_data, priv->bssid, ETH_ALEN);
  6793. memcpy(&priv->ieee->bssid, priv->bssid, ETH_ALEN);
  6794. priv->status &= ~STATUS_ASSOCIATING;
  6795. priv->status |= STATUS_ASSOCIATED;
  6796. netif_carrier_on(priv->net_dev);
  6797. if (netif_queue_stopped(priv->net_dev)) {
  6798. IPW_DEBUG_INFO("Waking net queue.\n");
  6799. netif_wake_queue(priv->net_dev);
  6800. } else {
  6801. IPW_DEBUG_INFO("Starting net queue.\n");
  6802. netif_start_queue(priv->net_dev);
  6803. }
  6804. }
  6805. if (!(priv->status & STATUS_ASSOCIATED)) {
  6806. IPW_DEBUG_WX("Configuring ESSID\n");
  6807. down(&priv->action_sem);
  6808. /* This is a disassociation event, so kick the firmware to
  6809. * look for another AP */
  6810. if (priv->config & CFG_STATIC_ESSID)
  6811. ipw2100_set_essid(priv, priv->essid, priv->essid_len, 0);
  6812. else
  6813. ipw2100_set_essid(priv, NULL, 0, 0);
  6814. up(&priv->action_sem);
  6815. }
  6816. wireless_send_event(priv->net_dev, SIOCGIWAP, &wrqu, NULL);
  6817. }
  6818. #define IPW2100_FW_MAJOR_VERSION 1
  6819. #define IPW2100_FW_MINOR_VERSION 3
  6820. #define IPW2100_FW_MINOR(x) ((x & 0xff) >> 8)
  6821. #define IPW2100_FW_MAJOR(x) (x & 0xff)
  6822. #define IPW2100_FW_VERSION ((IPW2100_FW_MINOR_VERSION << 8) | \
  6823. IPW2100_FW_MAJOR_VERSION)
  6824. #define IPW2100_FW_PREFIX "ipw2100-" __stringify(IPW2100_FW_MAJOR_VERSION) \
  6825. "." __stringify(IPW2100_FW_MINOR_VERSION)
  6826. #define IPW2100_FW_NAME(x) IPW2100_FW_PREFIX "" x ".fw"
  6827. /*
  6828. BINARY FIRMWARE HEADER FORMAT
  6829. offset length desc
  6830. 0 2 version
  6831. 2 2 mode == 0:BSS,1:IBSS,2:MONITOR
  6832. 4 4 fw_len
  6833. 8 4 uc_len
  6834. C fw_len firmware data
  6835. 12 + fw_len uc_len microcode data
  6836. */
  6837. struct ipw2100_fw_header {
  6838. short version;
  6839. short mode;
  6840. unsigned int fw_size;
  6841. unsigned int uc_size;
  6842. } __attribute__ ((packed));
  6843. static int ipw2100_mod_firmware_load(struct ipw2100_fw *fw)
  6844. {
  6845. struct ipw2100_fw_header *h =
  6846. (struct ipw2100_fw_header *)fw->fw_entry->data;
  6847. if (IPW2100_FW_MAJOR(h->version) != IPW2100_FW_MAJOR_VERSION) {
  6848. printk(KERN_WARNING DRV_NAME ": Firmware image not compatible "
  6849. "(detected version id of %u). "
  6850. "See Documentation/networking/README.ipw2100\n",
  6851. h->version);
  6852. return 1;
  6853. }
  6854. fw->version = h->version;
  6855. fw->fw.data = fw->fw_entry->data + sizeof(struct ipw2100_fw_header);
  6856. fw->fw.size = h->fw_size;
  6857. fw->uc.data = fw->fw.data + h->fw_size;
  6858. fw->uc.size = h->uc_size;
  6859. return 0;
  6860. }
  6861. static int ipw2100_get_firmware(struct ipw2100_priv *priv,
  6862. struct ipw2100_fw *fw)
  6863. {
  6864. char *fw_name;
  6865. int rc;
  6866. IPW_DEBUG_INFO("%s: Using hotplug firmware load.\n",
  6867. priv->net_dev->name);
  6868. switch (priv->ieee->iw_mode) {
  6869. case IW_MODE_ADHOC:
  6870. fw_name = IPW2100_FW_NAME("-i");
  6871. break;
  6872. #ifdef CONFIG_IPW2100_MONITOR
  6873. case IW_MODE_MONITOR:
  6874. fw_name = IPW2100_FW_NAME("-p");
  6875. break;
  6876. #endif
  6877. case IW_MODE_INFRA:
  6878. default:
  6879. fw_name = IPW2100_FW_NAME("");
  6880. break;
  6881. }
  6882. rc = request_firmware(&fw->fw_entry, fw_name, &priv->pci_dev->dev);
  6883. if (rc < 0) {
  6884. printk(KERN_ERR DRV_NAME ": "
  6885. "%s: Firmware '%s' not available or load failed.\n",
  6886. priv->net_dev->name, fw_name);
  6887. return rc;
  6888. }
  6889. IPW_DEBUG_INFO("firmware data %p size %zd\n", fw->fw_entry->data,
  6890. fw->fw_entry->size);
  6891. ipw2100_mod_firmware_load(fw);
  6892. return 0;
  6893. }
  6894. static void ipw2100_release_firmware(struct ipw2100_priv *priv,
  6895. struct ipw2100_fw *fw)
  6896. {
  6897. fw->version = 0;
  6898. if (fw->fw_entry)
  6899. release_firmware(fw->fw_entry);
  6900. fw->fw_entry = NULL;
  6901. }
  6902. static int ipw2100_get_fwversion(struct ipw2100_priv *priv, char *buf,
  6903. size_t max)
  6904. {
  6905. char ver[MAX_FW_VERSION_LEN];
  6906. u32 len = MAX_FW_VERSION_LEN;
  6907. u32 tmp;
  6908. int i;
  6909. /* firmware version is an ascii string (max len of 14) */
  6910. if (ipw2100_get_ordinal(priv, IPW_ORD_STAT_FW_VER_NUM,
  6911. ver, &len))
  6912. return -EIO;
  6913. tmp = max;
  6914. if (len >= max)
  6915. len = max - 1;
  6916. for (i = 0; i < len; i++)
  6917. buf[i] = ver[i];
  6918. buf[i] = '\0';
  6919. return tmp;
  6920. }
  6921. static int ipw2100_get_ucodeversion(struct ipw2100_priv *priv, char *buf,
  6922. size_t max)
  6923. {
  6924. u32 ver;
  6925. u32 len = sizeof(ver);
  6926. /* microcode version is a 32 bit integer */
  6927. if (ipw2100_get_ordinal(priv, IPW_ORD_UCODE_VERSION,
  6928. &ver, &len))
  6929. return -EIO;
  6930. return snprintf(buf, max, "%08X", ver);
  6931. }
  6932. /*
  6933. * On exit, the firmware will have been freed from the fw list
  6934. */
  6935. static int ipw2100_fw_download(struct ipw2100_priv *priv,
  6936. struct ipw2100_fw *fw)
  6937. {
  6938. /* firmware is constructed of N contiguous entries, each entry is
  6939. * structured as:
  6940. *
  6941. * offset sie desc
  6942. * 0 4 address to write to
  6943. * 4 2 length of data run
  6944. * 6 length data
  6945. */
  6946. unsigned int addr;
  6947. unsigned short len;
  6948. const unsigned char *firmware_data = fw->fw.data;
  6949. unsigned int firmware_data_left = fw->fw.size;
  6950. while (firmware_data_left > 0) {
  6951. addr = *(u32 *)(firmware_data);
  6952. firmware_data += 4;
  6953. firmware_data_left -= 4;
  6954. len = *(u16 *)(firmware_data);
  6955. firmware_data += 2;
  6956. firmware_data_left -= 2;
  6957. if (len > 32) {
  6958. printk(KERN_ERR DRV_NAME ": "
  6959. "Invalid firmware run-length of %d bytes\n",
  6960. len);
  6961. return -EINVAL;
  6962. }
  6963. write_nic_memory(priv->net_dev, addr, len, firmware_data);
  6964. firmware_data += len;
  6965. firmware_data_left -= len;
  6966. }
  6967. return 0;
  6968. }
  6969. struct symbol_alive_response {
  6970. u8 cmd_id;
  6971. u8 seq_num;
  6972. u8 ucode_rev;
  6973. u8 eeprom_valid;
  6974. u16 valid_flags;
  6975. u8 IEEE_addr[6];
  6976. u16 flags;
  6977. u16 pcb_rev;
  6978. u16 clock_settle_time; // 1us LSB
  6979. u16 powerup_settle_time; // 1us LSB
  6980. u16 hop_settle_time; // 1us LSB
  6981. u8 date[3]; // month, day, year
  6982. u8 time[2]; // hours, minutes
  6983. u8 ucode_valid;
  6984. };
  6985. static int ipw2100_ucode_download(struct ipw2100_priv *priv,
  6986. struct ipw2100_fw *fw)
  6987. {
  6988. struct net_device *dev = priv->net_dev;
  6989. const unsigned char *microcode_data = fw->uc.data;
  6990. unsigned int microcode_data_left = fw->uc.size;
  6991. void __iomem *reg = (void __iomem *)dev->base_addr;
  6992. struct symbol_alive_response response;
  6993. int i, j;
  6994. u8 data;
  6995. /* Symbol control */
  6996. write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
  6997. readl(reg);
  6998. write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
  6999. readl(reg);
  7000. /* HW config */
  7001. write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
  7002. readl(reg);
  7003. write_nic_byte(dev, 0x210014, 0x72); /* fifo width =16 */
  7004. readl(reg);
  7005. /* EN_CS_ACCESS bit to reset control store pointer */
  7006. write_nic_byte(dev, 0x210000, 0x40);
  7007. readl(reg);
  7008. write_nic_byte(dev, 0x210000, 0x0);
  7009. readl(reg);
  7010. write_nic_byte(dev, 0x210000, 0x40);
  7011. readl(reg);
  7012. /* copy microcode from buffer into Symbol */
  7013. while (microcode_data_left > 0) {
  7014. write_nic_byte(dev, 0x210010, *microcode_data++);
  7015. write_nic_byte(dev, 0x210010, *microcode_data++);
  7016. microcode_data_left -= 2;
  7017. }
  7018. /* EN_CS_ACCESS bit to reset the control store pointer */
  7019. write_nic_byte(dev, 0x210000, 0x0);
  7020. readl(reg);
  7021. /* Enable System (Reg 0)
  7022. * first enable causes garbage in RX FIFO */
  7023. write_nic_byte(dev, 0x210000, 0x0);
  7024. readl(reg);
  7025. write_nic_byte(dev, 0x210000, 0x80);
  7026. readl(reg);
  7027. /* Reset External Baseband Reg */
  7028. write_nic_word(dev, IPW2100_CONTROL_REG, 0x703);
  7029. readl(reg);
  7030. write_nic_word(dev, IPW2100_CONTROL_REG, 0x707);
  7031. readl(reg);
  7032. /* HW Config (Reg 5) */
  7033. write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
  7034. readl(reg);
  7035. write_nic_byte(dev, 0x210014, 0x72); // fifo width =16
  7036. readl(reg);
  7037. /* Enable System (Reg 0)
  7038. * second enable should be OK */
  7039. write_nic_byte(dev, 0x210000, 0x00); // clear enable system
  7040. readl(reg);
  7041. write_nic_byte(dev, 0x210000, 0x80); // set enable system
  7042. /* check Symbol is enabled - upped this from 5 as it wasn't always
  7043. * catching the update */
  7044. for (i = 0; i < 10; i++) {
  7045. udelay(10);
  7046. /* check Dino is enabled bit */
  7047. read_nic_byte(dev, 0x210000, &data);
  7048. if (data & 0x1)
  7049. break;
  7050. }
  7051. if (i == 10) {
  7052. printk(KERN_ERR DRV_NAME ": %s: Error initializing Symbol\n",
  7053. dev->name);
  7054. return -EIO;
  7055. }
  7056. /* Get Symbol alive response */
  7057. for (i = 0; i < 30; i++) {
  7058. /* Read alive response structure */
  7059. for (j = 0;
  7060. j < (sizeof(struct symbol_alive_response) >> 1);
  7061. j++)
  7062. read_nic_word(dev, 0x210004,
  7063. ((u16 *)&response) + j);
  7064. if ((response.cmd_id == 1) &&
  7065. (response.ucode_valid == 0x1))
  7066. break;
  7067. udelay(10);
  7068. }
  7069. if (i == 30) {
  7070. printk(KERN_ERR DRV_NAME ": %s: No response from Symbol - hw not alive\n",
  7071. dev->name);
  7072. printk_buf(IPW_DL_ERROR, (u8*)&response, sizeof(response));
  7073. return -EIO;
  7074. }
  7075. return 0;
  7076. }