wavelan_cs.c 134 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776
  1. /*
  2. * Wavelan Pcmcia driver
  3. *
  4. * Jean II - HPLB '96
  5. *
  6. * Reorganisation and extension of the driver.
  7. * Original copyright follow. See wavelan_cs.p.h for details.
  8. *
  9. * This code is derived from Anthony D. Joseph's code and all the changes here
  10. * are also under the original copyright below.
  11. *
  12. * This code supports version 2.00 of WaveLAN/PCMCIA cards (2.4GHz), and
  13. * can work on Linux 2.0.36 with support of David Hinds' PCMCIA Card Services
  14. *
  15. * Joe Finney (joe@comp.lancs.ac.uk) at Lancaster University in UK added
  16. * critical code in the routine to initialize the Modem Management Controller.
  17. *
  18. * Thanks to Alan Cox and Bruce Janson for their advice.
  19. *
  20. * -- Yunzhou Li (scip4166@nus.sg)
  21. *
  22. #ifdef WAVELAN_ROAMING
  23. * Roaming support added 07/22/98 by Justin Seger (jseger@media.mit.edu)
  24. * based on patch by Joe Finney from Lancaster University.
  25. #endif
  26. *
  27. * Lucent (formerly AT&T GIS, formerly NCR) WaveLAN PCMCIA card: An
  28. * Ethernet-like radio transceiver controlled by an Intel 82593 coprocessor.
  29. *
  30. * A non-shared memory PCMCIA ethernet driver for linux
  31. *
  32. * ISA version modified to support PCMCIA by Anthony Joseph (adj@lcs.mit.edu)
  33. *
  34. *
  35. * Joseph O'Sullivan & John Langford (josullvn@cs.cmu.edu & jcl@cs.cmu.edu)
  36. *
  37. * Apr 2 '98 made changes to bring the i82593 control/int handling in line
  38. * with offical specs...
  39. *
  40. ****************************************************************************
  41. * Copyright 1995
  42. * Anthony D. Joseph
  43. * Massachusetts Institute of Technology
  44. *
  45. * Permission to use, copy, modify, and distribute this program
  46. * for any purpose and without fee is hereby granted, provided
  47. * that this copyright and permission notice appear on all copies
  48. * and supporting documentation, the name of M.I.T. not be used
  49. * in advertising or publicity pertaining to distribution of the
  50. * program without specific prior permission, and notice be given
  51. * in supporting documentation that copying and distribution is
  52. * by permission of M.I.T. M.I.T. makes no representations about
  53. * the suitability of this software for any purpose. It is pro-
  54. * vided "as is" without express or implied warranty.
  55. ****************************************************************************
  56. *
  57. */
  58. /* Do *NOT* add other headers here, you are guaranteed to be wrong - Jean II */
  59. #include "wavelan_cs.p.h" /* Private header */
  60. #ifdef WAVELAN_ROAMING
  61. static void wl_cell_expiry(unsigned long data);
  62. static void wl_del_wavepoint(wavepoint_history *wavepoint, struct net_local *lp);
  63. static void wv_nwid_filter(unsigned char mode, net_local *lp);
  64. #endif /* WAVELAN_ROAMING */
  65. /************************* MISC SUBROUTINES **************************/
  66. /*
  67. * Subroutines which won't fit in one of the following category
  68. * (wavelan modem or i82593)
  69. */
  70. #ifdef STRUCT_CHECK
  71. /*------------------------------------------------------------------*/
  72. /*
  73. * Sanity routine to verify the sizes of the various WaveLAN interface
  74. * structures.
  75. */
  76. static char *
  77. wv_structuct_check(void)
  78. {
  79. #define SC(t,s,n) if (sizeof(t) != s) return(n);
  80. SC(psa_t, PSA_SIZE, "psa_t");
  81. SC(mmw_t, MMW_SIZE, "mmw_t");
  82. SC(mmr_t, MMR_SIZE, "mmr_t");
  83. #undef SC
  84. return((char *) NULL);
  85. } /* wv_structuct_check */
  86. #endif /* STRUCT_CHECK */
  87. /******************* MODEM MANAGEMENT SUBROUTINES *******************/
  88. /*
  89. * Useful subroutines to manage the modem of the wavelan
  90. */
  91. /*------------------------------------------------------------------*/
  92. /*
  93. * Read from card's Host Adaptor Status Register.
  94. */
  95. static inline u_char
  96. hasr_read(u_long base)
  97. {
  98. return(inb(HASR(base)));
  99. } /* hasr_read */
  100. /*------------------------------------------------------------------*/
  101. /*
  102. * Write to card's Host Adapter Command Register.
  103. */
  104. static inline void
  105. hacr_write(u_long base,
  106. u_char hacr)
  107. {
  108. outb(hacr, HACR(base));
  109. } /* hacr_write */
  110. /*------------------------------------------------------------------*/
  111. /*
  112. * Write to card's Host Adapter Command Register. Include a delay for
  113. * those times when it is needed.
  114. */
  115. static inline void
  116. hacr_write_slow(u_long base,
  117. u_char hacr)
  118. {
  119. hacr_write(base, hacr);
  120. /* delay might only be needed sometimes */
  121. mdelay(1);
  122. } /* hacr_write_slow */
  123. /*------------------------------------------------------------------*/
  124. /*
  125. * Read the Parameter Storage Area from the WaveLAN card's memory
  126. */
  127. static void
  128. psa_read(struct net_device * dev,
  129. int o, /* offset in PSA */
  130. u_char * b, /* buffer to fill */
  131. int n) /* size to read */
  132. {
  133. net_local *lp = netdev_priv(dev);
  134. u_char __iomem *ptr = lp->mem + PSA_ADDR + (o << 1);
  135. while(n-- > 0)
  136. {
  137. *b++ = readb(ptr);
  138. /* Due to a lack of address decode pins, the WaveLAN PCMCIA card
  139. * only supports reading even memory addresses. That means the
  140. * increment here MUST be two.
  141. * Because of that, we can't use memcpy_fromio()...
  142. */
  143. ptr += 2;
  144. }
  145. } /* psa_read */
  146. /*------------------------------------------------------------------*/
  147. /*
  148. * Write the Paramter Storage Area to the WaveLAN card's memory
  149. */
  150. static void
  151. psa_write(struct net_device * dev,
  152. int o, /* Offset in psa */
  153. u_char * b, /* Buffer in memory */
  154. int n) /* Length of buffer */
  155. {
  156. net_local *lp = netdev_priv(dev);
  157. u_char __iomem *ptr = lp->mem + PSA_ADDR + (o << 1);
  158. int count = 0;
  159. kio_addr_t base = dev->base_addr;
  160. /* As there seem to have no flag PSA_BUSY as in the ISA model, we are
  161. * oblige to verify this address to know when the PSA is ready... */
  162. volatile u_char __iomem *verify = lp->mem + PSA_ADDR +
  163. (psaoff(0, psa_comp_number) << 1);
  164. /* Authorize writting to PSA */
  165. hacr_write(base, HACR_PWR_STAT | HACR_ROM_WEN);
  166. while(n-- > 0)
  167. {
  168. /* write to PSA */
  169. writeb(*b++, ptr);
  170. ptr += 2;
  171. /* I don't have the spec, so I don't know what the correct
  172. * sequence to write is. This hack seem to work for me... */
  173. count = 0;
  174. while((readb(verify) != PSA_COMP_PCMCIA_915) && (count++ < 100))
  175. mdelay(1);
  176. }
  177. /* Put the host interface back in standard state */
  178. hacr_write(base, HACR_DEFAULT);
  179. } /* psa_write */
  180. #ifdef SET_PSA_CRC
  181. /*------------------------------------------------------------------*/
  182. /*
  183. * Calculate the PSA CRC
  184. * Thanks to Valster, Nico <NVALSTER@wcnd.nl.lucent.com> for the code
  185. * NOTE: By specifying a length including the CRC position the
  186. * returned value should be zero. (i.e. a correct checksum in the PSA)
  187. *
  188. * The Windows drivers don't use the CRC, but the AP and the PtP tool
  189. * depend on it.
  190. */
  191. static u_short
  192. psa_crc(unsigned char * psa, /* The PSA */
  193. int size) /* Number of short for CRC */
  194. {
  195. int byte_cnt; /* Loop on the PSA */
  196. u_short crc_bytes = 0; /* Data in the PSA */
  197. int bit_cnt; /* Loop on the bits of the short */
  198. for(byte_cnt = 0; byte_cnt < size; byte_cnt++ )
  199. {
  200. crc_bytes ^= psa[byte_cnt]; /* Its an xor */
  201. for(bit_cnt = 1; bit_cnt < 9; bit_cnt++ )
  202. {
  203. if(crc_bytes & 0x0001)
  204. crc_bytes = (crc_bytes >> 1) ^ 0xA001;
  205. else
  206. crc_bytes >>= 1 ;
  207. }
  208. }
  209. return crc_bytes;
  210. } /* psa_crc */
  211. #endif /* SET_PSA_CRC */
  212. /*------------------------------------------------------------------*/
  213. /*
  214. * update the checksum field in the Wavelan's PSA
  215. */
  216. static void
  217. update_psa_checksum(struct net_device * dev)
  218. {
  219. #ifdef SET_PSA_CRC
  220. psa_t psa;
  221. u_short crc;
  222. /* read the parameter storage area */
  223. psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
  224. /* update the checksum */
  225. crc = psa_crc((unsigned char *) &psa,
  226. sizeof(psa) - sizeof(psa.psa_crc[0]) - sizeof(psa.psa_crc[1])
  227. - sizeof(psa.psa_crc_status));
  228. psa.psa_crc[0] = crc & 0xFF;
  229. psa.psa_crc[1] = (crc & 0xFF00) >> 8;
  230. /* Write it ! */
  231. psa_write(dev, (char *)&psa.psa_crc - (char *)&psa,
  232. (unsigned char *)&psa.psa_crc, 2);
  233. #ifdef DEBUG_IOCTL_INFO
  234. printk (KERN_DEBUG "%s: update_psa_checksum(): crc = 0x%02x%02x\n",
  235. dev->name, psa.psa_crc[0], psa.psa_crc[1]);
  236. /* Check again (luxury !) */
  237. crc = psa_crc((unsigned char *) &psa,
  238. sizeof(psa) - sizeof(psa.psa_crc_status));
  239. if(crc != 0)
  240. printk(KERN_WARNING "%s: update_psa_checksum(): CRC does not agree with PSA data (even after recalculating)\n", dev->name);
  241. #endif /* DEBUG_IOCTL_INFO */
  242. #endif /* SET_PSA_CRC */
  243. } /* update_psa_checksum */
  244. /*------------------------------------------------------------------*/
  245. /*
  246. * Write 1 byte to the MMC.
  247. */
  248. static inline void
  249. mmc_out(u_long base,
  250. u_short o,
  251. u_char d)
  252. {
  253. int count = 0;
  254. /* Wait for MMC to go idle */
  255. while((count++ < 100) && (inb(HASR(base)) & HASR_MMI_BUSY))
  256. udelay(10);
  257. outb((u_char)((o << 1) | MMR_MMI_WR), MMR(base));
  258. outb(d, MMD(base));
  259. }
  260. /*------------------------------------------------------------------*/
  261. /*
  262. * Routine to write bytes to the Modem Management Controller.
  263. * We start by the end because it is the way it should be !
  264. */
  265. static inline void
  266. mmc_write(u_long base,
  267. u_char o,
  268. u_char * b,
  269. int n)
  270. {
  271. o += n;
  272. b += n;
  273. while(n-- > 0 )
  274. mmc_out(base, --o, *(--b));
  275. } /* mmc_write */
  276. /*------------------------------------------------------------------*/
  277. /*
  278. * Read 1 byte from the MMC.
  279. * Optimised version for 1 byte, avoid using memory...
  280. */
  281. static inline u_char
  282. mmc_in(u_long base,
  283. u_short o)
  284. {
  285. int count = 0;
  286. while((count++ < 100) && (inb(HASR(base)) & HASR_MMI_BUSY))
  287. udelay(10);
  288. outb(o << 1, MMR(base)); /* Set the read address */
  289. outb(0, MMD(base)); /* Required dummy write */
  290. while((count++ < 100) && (inb(HASR(base)) & HASR_MMI_BUSY))
  291. udelay(10);
  292. return (u_char) (inb(MMD(base))); /* Now do the actual read */
  293. }
  294. /*------------------------------------------------------------------*/
  295. /*
  296. * Routine to read bytes from the Modem Management Controller.
  297. * The implementation is complicated by a lack of address lines,
  298. * which prevents decoding of the low-order bit.
  299. * (code has just been moved in the above function)
  300. * We start by the end because it is the way it should be !
  301. */
  302. static inline void
  303. mmc_read(u_long base,
  304. u_char o,
  305. u_char * b,
  306. int n)
  307. {
  308. o += n;
  309. b += n;
  310. while(n-- > 0)
  311. *(--b) = mmc_in(base, --o);
  312. } /* mmc_read */
  313. /*------------------------------------------------------------------*/
  314. /*
  315. * Get the type of encryption available...
  316. */
  317. static inline int
  318. mmc_encr(u_long base) /* i/o port of the card */
  319. {
  320. int temp;
  321. temp = mmc_in(base, mmroff(0, mmr_des_avail));
  322. if((temp != MMR_DES_AVAIL_DES) && (temp != MMR_DES_AVAIL_AES))
  323. return 0;
  324. else
  325. return temp;
  326. }
  327. /*------------------------------------------------------------------*/
  328. /*
  329. * Wait for the frequency EEprom to complete a command...
  330. * I hope this one will be optimally inlined...
  331. */
  332. static inline void
  333. fee_wait(u_long base, /* i/o port of the card */
  334. int delay, /* Base delay to wait for */
  335. int number) /* Number of time to wait */
  336. {
  337. int count = 0; /* Wait only a limited time */
  338. while((count++ < number) &&
  339. (mmc_in(base, mmroff(0, mmr_fee_status)) & MMR_FEE_STATUS_BUSY))
  340. udelay(delay);
  341. }
  342. /*------------------------------------------------------------------*/
  343. /*
  344. * Read bytes from the Frequency EEprom (frequency select cards).
  345. */
  346. static void
  347. fee_read(u_long base, /* i/o port of the card */
  348. u_short o, /* destination offset */
  349. u_short * b, /* data buffer */
  350. int n) /* number of registers */
  351. {
  352. b += n; /* Position at the end of the area */
  353. /* Write the address */
  354. mmc_out(base, mmwoff(0, mmw_fee_addr), o + n - 1);
  355. /* Loop on all buffer */
  356. while(n-- > 0)
  357. {
  358. /* Write the read command */
  359. mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_READ);
  360. /* Wait until EEprom is ready (should be quick !) */
  361. fee_wait(base, 10, 100);
  362. /* Read the value */
  363. *--b = ((mmc_in(base, mmroff(0, mmr_fee_data_h)) << 8) |
  364. mmc_in(base, mmroff(0, mmr_fee_data_l)));
  365. }
  366. }
  367. /*------------------------------------------------------------------*/
  368. /*
  369. * Write bytes from the Frequency EEprom (frequency select cards).
  370. * This is a bit complicated, because the frequency eeprom has to
  371. * be unprotected and the write enabled.
  372. * Jean II
  373. */
  374. static void
  375. fee_write(u_long base, /* i/o port of the card */
  376. u_short o, /* destination offset */
  377. u_short * b, /* data buffer */
  378. int n) /* number of registers */
  379. {
  380. b += n; /* Position at the end of the area */
  381. #ifdef EEPROM_IS_PROTECTED /* disabled */
  382. #ifdef DOESNT_SEEM_TO_WORK /* disabled */
  383. /* Ask to read the protected register */
  384. mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRREAD);
  385. fee_wait(base, 10, 100);
  386. /* Read the protected register */
  387. printk("Protected 2 : %02X-%02X\n",
  388. mmc_in(base, mmroff(0, mmr_fee_data_h)),
  389. mmc_in(base, mmroff(0, mmr_fee_data_l)));
  390. #endif /* DOESNT_SEEM_TO_WORK */
  391. /* Enable protected register */
  392. mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
  393. mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PREN);
  394. fee_wait(base, 10, 100);
  395. /* Unprotect area */
  396. mmc_out(base, mmwoff(0, mmw_fee_addr), o + n);
  397. mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
  398. #ifdef DOESNT_SEEM_TO_WORK /* disabled */
  399. /* Or use : */
  400. mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRCLEAR);
  401. #endif /* DOESNT_SEEM_TO_WORK */
  402. fee_wait(base, 10, 100);
  403. #endif /* EEPROM_IS_PROTECTED */
  404. /* Write enable */
  405. mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
  406. mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WREN);
  407. fee_wait(base, 10, 100);
  408. /* Write the EEprom address */
  409. mmc_out(base, mmwoff(0, mmw_fee_addr), o + n - 1);
  410. /* Loop on all buffer */
  411. while(n-- > 0)
  412. {
  413. /* Write the value */
  414. mmc_out(base, mmwoff(0, mmw_fee_data_h), (*--b) >> 8);
  415. mmc_out(base, mmwoff(0, mmw_fee_data_l), *b & 0xFF);
  416. /* Write the write command */
  417. mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WRITE);
  418. /* Wavelan doc says : wait at least 10 ms for EEBUSY = 0 */
  419. mdelay(10);
  420. fee_wait(base, 10, 100);
  421. }
  422. /* Write disable */
  423. mmc_out(base, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_DS);
  424. mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WDS);
  425. fee_wait(base, 10, 100);
  426. #ifdef EEPROM_IS_PROTECTED /* disabled */
  427. /* Reprotect EEprom */
  428. mmc_out(base, mmwoff(0, mmw_fee_addr), 0x00);
  429. mmc_out(base, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
  430. fee_wait(base, 10, 100);
  431. #endif /* EEPROM_IS_PROTECTED */
  432. }
  433. /******************* WaveLAN Roaming routines... ********************/
  434. #ifdef WAVELAN_ROAMING /* Conditional compile, see wavelan_cs.h */
  435. static unsigned char WAVELAN_BEACON_ADDRESS[] = {0x09,0x00,0x0e,0x20,0x03,0x00};
  436. static void wv_roam_init(struct net_device *dev)
  437. {
  438. net_local *lp= netdev_priv(dev);
  439. /* Do not remove this unless you have a good reason */
  440. printk(KERN_NOTICE "%s: Warning, you have enabled roaming on"
  441. " device %s !\n", dev->name, dev->name);
  442. printk(KERN_NOTICE "Roaming is currently an experimental unsupported feature"
  443. " of the Wavelan driver.\n");
  444. printk(KERN_NOTICE "It may work, but may also make the driver behave in"
  445. " erratic ways or crash.\n");
  446. lp->wavepoint_table.head=NULL; /* Initialise WavePoint table */
  447. lp->wavepoint_table.num_wavepoints=0;
  448. lp->wavepoint_table.locked=0;
  449. lp->curr_point=NULL; /* No default WavePoint */
  450. lp->cell_search=0;
  451. lp->cell_timer.data=(long)lp; /* Start cell expiry timer */
  452. lp->cell_timer.function=wl_cell_expiry;
  453. lp->cell_timer.expires=jiffies+CELL_TIMEOUT;
  454. add_timer(&lp->cell_timer);
  455. wv_nwid_filter(NWID_PROMISC,lp) ; /* Enter NWID promiscuous mode */
  456. /* to build up a good WavePoint */
  457. /* table... */
  458. printk(KERN_DEBUG "WaveLAN: Roaming enabled on device %s\n",dev->name);
  459. }
  460. static void wv_roam_cleanup(struct net_device *dev)
  461. {
  462. wavepoint_history *ptr,*old_ptr;
  463. net_local *lp= netdev_priv(dev);
  464. printk(KERN_DEBUG "WaveLAN: Roaming Disabled on device %s\n",dev->name);
  465. /* Fixme : maybe we should check that the timer exist before deleting it */
  466. del_timer(&lp->cell_timer); /* Remove cell expiry timer */
  467. ptr=lp->wavepoint_table.head; /* Clear device's WavePoint table */
  468. while(ptr!=NULL)
  469. {
  470. old_ptr=ptr;
  471. ptr=ptr->next;
  472. wl_del_wavepoint(old_ptr,lp);
  473. }
  474. }
  475. /* Enable/Disable NWID promiscuous mode on a given device */
  476. static void wv_nwid_filter(unsigned char mode, net_local *lp)
  477. {
  478. mm_t m;
  479. unsigned long flags;
  480. #ifdef WAVELAN_ROAMING_DEBUG
  481. printk(KERN_DEBUG "WaveLAN: NWID promisc %s, device %s\n",(mode==NWID_PROMISC) ? "on" : "off", lp->dev->name);
  482. #endif
  483. /* Disable interrupts & save flags */
  484. spin_lock_irqsave(&lp->spinlock, flags);
  485. m.w.mmw_loopt_sel = (mode==NWID_PROMISC) ? MMW_LOOPT_SEL_DIS_NWID : 0x00;
  486. mmc_write(lp->dev->base_addr, (char *)&m.w.mmw_loopt_sel - (char *)&m, (unsigned char *)&m.w.mmw_loopt_sel, 1);
  487. if(mode==NWID_PROMISC)
  488. lp->cell_search=1;
  489. else
  490. lp->cell_search=0;
  491. /* ReEnable interrupts & restore flags */
  492. spin_unlock_irqrestore(&lp->spinlock, flags);
  493. }
  494. /* Find a record in the WavePoint table matching a given NWID */
  495. static wavepoint_history *wl_roam_check(unsigned short nwid, net_local *lp)
  496. {
  497. wavepoint_history *ptr=lp->wavepoint_table.head;
  498. while(ptr!=NULL){
  499. if(ptr->nwid==nwid)
  500. return ptr;
  501. ptr=ptr->next;
  502. }
  503. return NULL;
  504. }
  505. /* Create a new wavepoint table entry */
  506. static wavepoint_history *wl_new_wavepoint(unsigned short nwid, unsigned char seq, net_local* lp)
  507. {
  508. wavepoint_history *new_wavepoint;
  509. #ifdef WAVELAN_ROAMING_DEBUG
  510. printk(KERN_DEBUG "WaveLAN: New Wavepoint, NWID:%.4X\n",nwid);
  511. #endif
  512. if(lp->wavepoint_table.num_wavepoints==MAX_WAVEPOINTS)
  513. return NULL;
  514. new_wavepoint=(wavepoint_history *) kmalloc(sizeof(wavepoint_history),GFP_ATOMIC);
  515. if(new_wavepoint==NULL)
  516. return NULL;
  517. new_wavepoint->nwid=nwid; /* New WavePoints NWID */
  518. new_wavepoint->average_fast=0; /* Running Averages..*/
  519. new_wavepoint->average_slow=0;
  520. new_wavepoint->qualptr=0; /* Start of ringbuffer */
  521. new_wavepoint->last_seq=seq-1; /* Last sequence no.seen */
  522. memset(new_wavepoint->sigqual,0,WAVEPOINT_HISTORY);/* Empty ringbuffer */
  523. new_wavepoint->next=lp->wavepoint_table.head;/* Add to wavepoint table */
  524. new_wavepoint->prev=NULL;
  525. if(lp->wavepoint_table.head!=NULL)
  526. lp->wavepoint_table.head->prev=new_wavepoint;
  527. lp->wavepoint_table.head=new_wavepoint;
  528. lp->wavepoint_table.num_wavepoints++; /* no. of visible wavepoints */
  529. return new_wavepoint;
  530. }
  531. /* Remove a wavepoint entry from WavePoint table */
  532. static void wl_del_wavepoint(wavepoint_history *wavepoint, struct net_local *lp)
  533. {
  534. if(wavepoint==NULL)
  535. return;
  536. if(lp->curr_point==wavepoint)
  537. lp->curr_point=NULL;
  538. if(wavepoint->prev!=NULL)
  539. wavepoint->prev->next=wavepoint->next;
  540. if(wavepoint->next!=NULL)
  541. wavepoint->next->prev=wavepoint->prev;
  542. if(lp->wavepoint_table.head==wavepoint)
  543. lp->wavepoint_table.head=wavepoint->next;
  544. lp->wavepoint_table.num_wavepoints--;
  545. kfree(wavepoint);
  546. }
  547. /* Timer callback function - checks WavePoint table for stale entries */
  548. static void wl_cell_expiry(unsigned long data)
  549. {
  550. net_local *lp=(net_local *)data;
  551. wavepoint_history *wavepoint=lp->wavepoint_table.head,*old_point;
  552. #if WAVELAN_ROAMING_DEBUG > 1
  553. printk(KERN_DEBUG "WaveLAN: Wavepoint timeout, dev %s\n",lp->dev->name);
  554. #endif
  555. if(lp->wavepoint_table.locked)
  556. {
  557. #if WAVELAN_ROAMING_DEBUG > 1
  558. printk(KERN_DEBUG "WaveLAN: Wavepoint table locked...\n");
  559. #endif
  560. lp->cell_timer.expires=jiffies+1; /* If table in use, come back later */
  561. add_timer(&lp->cell_timer);
  562. return;
  563. }
  564. while(wavepoint!=NULL)
  565. {
  566. if(time_after(jiffies, wavepoint->last_seen + CELL_TIMEOUT))
  567. {
  568. #ifdef WAVELAN_ROAMING_DEBUG
  569. printk(KERN_DEBUG "WaveLAN: Bye bye %.4X\n",wavepoint->nwid);
  570. #endif
  571. old_point=wavepoint;
  572. wavepoint=wavepoint->next;
  573. wl_del_wavepoint(old_point,lp);
  574. }
  575. else
  576. wavepoint=wavepoint->next;
  577. }
  578. lp->cell_timer.expires=jiffies+CELL_TIMEOUT;
  579. add_timer(&lp->cell_timer);
  580. }
  581. /* Update SNR history of a wavepoint */
  582. static void wl_update_history(wavepoint_history *wavepoint, unsigned char sigqual, unsigned char seq)
  583. {
  584. int i=0,num_missed=0,ptr=0;
  585. int average_fast=0,average_slow=0;
  586. num_missed=(seq-wavepoint->last_seq)%WAVEPOINT_HISTORY;/* Have we missed
  587. any beacons? */
  588. if(num_missed)
  589. for(i=0;i<num_missed;i++)
  590. {
  591. wavepoint->sigqual[wavepoint->qualptr++]=0; /* If so, enter them as 0's */
  592. wavepoint->qualptr %=WAVEPOINT_HISTORY; /* in the ringbuffer. */
  593. }
  594. wavepoint->last_seen=jiffies; /* Add beacon to history */
  595. wavepoint->last_seq=seq;
  596. wavepoint->sigqual[wavepoint->qualptr++]=sigqual;
  597. wavepoint->qualptr %=WAVEPOINT_HISTORY;
  598. ptr=(wavepoint->qualptr-WAVEPOINT_FAST_HISTORY+WAVEPOINT_HISTORY)%WAVEPOINT_HISTORY;
  599. for(i=0;i<WAVEPOINT_FAST_HISTORY;i++) /* Update running averages */
  600. {
  601. average_fast+=wavepoint->sigqual[ptr++];
  602. ptr %=WAVEPOINT_HISTORY;
  603. }
  604. average_slow=average_fast;
  605. for(i=WAVEPOINT_FAST_HISTORY;i<WAVEPOINT_HISTORY;i++)
  606. {
  607. average_slow+=wavepoint->sigqual[ptr++];
  608. ptr %=WAVEPOINT_HISTORY;
  609. }
  610. wavepoint->average_fast=average_fast/WAVEPOINT_FAST_HISTORY;
  611. wavepoint->average_slow=average_slow/WAVEPOINT_HISTORY;
  612. }
  613. /* Perform a handover to a new WavePoint */
  614. static void wv_roam_handover(wavepoint_history *wavepoint, net_local *lp)
  615. {
  616. kio_addr_t base = lp->dev->base_addr;
  617. mm_t m;
  618. unsigned long flags;
  619. if(wavepoint==lp->curr_point) /* Sanity check... */
  620. {
  621. wv_nwid_filter(!NWID_PROMISC,lp);
  622. return;
  623. }
  624. #ifdef WAVELAN_ROAMING_DEBUG
  625. printk(KERN_DEBUG "WaveLAN: Doing handover to %.4X, dev %s\n",wavepoint->nwid,lp->dev->name);
  626. #endif
  627. /* Disable interrupts & save flags */
  628. spin_lock_irqsave(&lp->spinlock, flags);
  629. m.w.mmw_netw_id_l = wavepoint->nwid & 0xFF;
  630. m.w.mmw_netw_id_h = (wavepoint->nwid & 0xFF00) >> 8;
  631. mmc_write(base, (char *)&m.w.mmw_netw_id_l - (char *)&m, (unsigned char *)&m.w.mmw_netw_id_l, 2);
  632. /* ReEnable interrupts & restore flags */
  633. spin_unlock_irqrestore(&lp->spinlock, flags);
  634. wv_nwid_filter(!NWID_PROMISC,lp);
  635. lp->curr_point=wavepoint;
  636. }
  637. /* Called when a WavePoint beacon is received */
  638. static inline void wl_roam_gather(struct net_device * dev,
  639. u_char * hdr, /* Beacon header */
  640. u_char * stats) /* SNR, Signal quality
  641. of packet */
  642. {
  643. wavepoint_beacon *beacon= (wavepoint_beacon *)hdr; /* Rcvd. Beacon */
  644. unsigned short nwid=ntohs(beacon->nwid);
  645. unsigned short sigqual=stats[2] & MMR_SGNL_QUAL; /* SNR of beacon */
  646. wavepoint_history *wavepoint=NULL; /* WavePoint table entry */
  647. net_local *lp = netdev_priv(dev); /* Device info */
  648. #ifdef I_NEED_THIS_FEATURE
  649. /* Some people don't need this, some other may need it */
  650. nwid=nwid^ntohs(beacon->domain_id);
  651. #endif
  652. #if WAVELAN_ROAMING_DEBUG > 1
  653. printk(KERN_DEBUG "WaveLAN: beacon, dev %s:\n",dev->name);
  654. printk(KERN_DEBUG "Domain: %.4X NWID: %.4X SigQual=%d\n",ntohs(beacon->domain_id),nwid,sigqual);
  655. #endif
  656. lp->wavepoint_table.locked=1; /* <Mutex> */
  657. wavepoint=wl_roam_check(nwid,lp); /* Find WavePoint table entry */
  658. if(wavepoint==NULL) /* If no entry, Create a new one... */
  659. {
  660. wavepoint=wl_new_wavepoint(nwid,beacon->seq,lp);
  661. if(wavepoint==NULL)
  662. goto out;
  663. }
  664. if(lp->curr_point==NULL) /* If this is the only WavePoint, */
  665. wv_roam_handover(wavepoint, lp); /* Jump on it! */
  666. wl_update_history(wavepoint, sigqual, beacon->seq); /* Update SNR history
  667. stats. */
  668. if(lp->curr_point->average_slow < SEARCH_THRESH_LOW) /* If our current */
  669. if(!lp->cell_search) /* WavePoint is getting faint, */
  670. wv_nwid_filter(NWID_PROMISC,lp); /* start looking for a new one */
  671. if(wavepoint->average_slow >
  672. lp->curr_point->average_slow + WAVELAN_ROAMING_DELTA)
  673. wv_roam_handover(wavepoint, lp); /* Handover to a better WavePoint */
  674. if(lp->curr_point->average_slow > SEARCH_THRESH_HIGH) /* If our SNR is */
  675. if(lp->cell_search) /* getting better, drop out of cell search mode */
  676. wv_nwid_filter(!NWID_PROMISC,lp);
  677. out:
  678. lp->wavepoint_table.locked=0; /* </MUTEX> :-) */
  679. }
  680. /* Test this MAC frame a WavePoint beacon */
  681. static inline int WAVELAN_BEACON(unsigned char *data)
  682. {
  683. wavepoint_beacon *beacon= (wavepoint_beacon *)data;
  684. static wavepoint_beacon beacon_template={0xaa,0xaa,0x03,0x08,0x00,0x0e,0x20,0x03,0x00};
  685. if(memcmp(beacon,&beacon_template,9)==0)
  686. return 1;
  687. else
  688. return 0;
  689. }
  690. #endif /* WAVELAN_ROAMING */
  691. /************************ I82593 SUBROUTINES *************************/
  692. /*
  693. * Useful subroutines to manage the Ethernet controller
  694. */
  695. /*------------------------------------------------------------------*/
  696. /*
  697. * Routine to synchronously send a command to the i82593 chip.
  698. * Should be called with interrupts disabled.
  699. * (called by wv_packet_write(), wv_ru_stop(), wv_ru_start(),
  700. * wv_82593_config() & wv_diag())
  701. */
  702. static int
  703. wv_82593_cmd(struct net_device * dev,
  704. char * str,
  705. int cmd,
  706. int result)
  707. {
  708. kio_addr_t base = dev->base_addr;
  709. int status;
  710. int wait_completed;
  711. long spin;
  712. /* Spin until the chip finishes executing its current command (if any) */
  713. spin = 1000;
  714. do
  715. {
  716. /* Time calibration of the loop */
  717. udelay(10);
  718. /* Read the interrupt register */
  719. outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
  720. status = inb(LCSR(base));
  721. }
  722. while(((status & SR3_EXEC_STATE_MASK) != SR3_EXEC_IDLE) && (spin-- > 0));
  723. /* If the interrupt hasn't be posted */
  724. if(spin <= 0)
  725. {
  726. #ifdef DEBUG_INTERRUPT_ERROR
  727. printk(KERN_INFO "wv_82593_cmd: %s timeout (previous command), status 0x%02x\n",
  728. str, status);
  729. #endif
  730. return(FALSE);
  731. }
  732. /* Issue the command to the controller */
  733. outb(cmd, LCCR(base));
  734. /* If we don't have to check the result of the command
  735. * Note : this mean that the irq handler will deal with that */
  736. if(result == SR0_NO_RESULT)
  737. return(TRUE);
  738. /* We are waiting for command completion */
  739. wait_completed = TRUE;
  740. /* Busy wait while the LAN controller executes the command. */
  741. spin = 1000;
  742. do
  743. {
  744. /* Time calibration of the loop */
  745. udelay(10);
  746. /* Read the interrupt register */
  747. outb(CR0_STATUS_0 | OP0_NOP, LCCR(base));
  748. status = inb(LCSR(base));
  749. /* Check if there was an interrupt posted */
  750. if((status & SR0_INTERRUPT))
  751. {
  752. /* Acknowledge the interrupt */
  753. outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
  754. /* Check if interrupt is a command completion */
  755. if(((status & SR0_BOTH_RX_TX) != SR0_BOTH_RX_TX) &&
  756. ((status & SR0_BOTH_RX_TX) != 0x0) &&
  757. !(status & SR0_RECEPTION))
  758. {
  759. /* Signal command completion */
  760. wait_completed = FALSE;
  761. }
  762. else
  763. {
  764. /* Note : Rx interrupts will be handled later, because we can
  765. * handle multiple Rx packets at once */
  766. #ifdef DEBUG_INTERRUPT_INFO
  767. printk(KERN_INFO "wv_82593_cmd: not our interrupt\n");
  768. #endif
  769. }
  770. }
  771. }
  772. while(wait_completed && (spin-- > 0));
  773. /* If the interrupt hasn't be posted */
  774. if(wait_completed)
  775. {
  776. #ifdef DEBUG_INTERRUPT_ERROR
  777. printk(KERN_INFO "wv_82593_cmd: %s timeout, status 0x%02x\n",
  778. str, status);
  779. #endif
  780. return(FALSE);
  781. }
  782. /* Check the return code returned by the card (see above) against
  783. * the expected return code provided by the caller */
  784. if((status & SR0_EVENT_MASK) != result)
  785. {
  786. #ifdef DEBUG_INTERRUPT_ERROR
  787. printk(KERN_INFO "wv_82593_cmd: %s failed, status = 0x%x\n",
  788. str, status);
  789. #endif
  790. return(FALSE);
  791. }
  792. return(TRUE);
  793. } /* wv_82593_cmd */
  794. /*------------------------------------------------------------------*/
  795. /*
  796. * This routine does a 593 op-code number 7, and obtains the diagnose
  797. * status for the WaveLAN.
  798. */
  799. static inline int
  800. wv_diag(struct net_device * dev)
  801. {
  802. return(wv_82593_cmd(dev, "wv_diag(): diagnose",
  803. OP0_DIAGNOSE, SR0_DIAGNOSE_PASSED));
  804. } /* wv_diag */
  805. /*------------------------------------------------------------------*/
  806. /*
  807. * Routine to read len bytes from the i82593's ring buffer, starting at
  808. * chip address addr. The results read from the chip are stored in buf.
  809. * The return value is the address to use for next the call.
  810. */
  811. static int
  812. read_ringbuf(struct net_device * dev,
  813. int addr,
  814. char * buf,
  815. int len)
  816. {
  817. kio_addr_t base = dev->base_addr;
  818. int ring_ptr = addr;
  819. int chunk_len;
  820. char * buf_ptr = buf;
  821. /* Get all the buffer */
  822. while(len > 0)
  823. {
  824. /* Position the Program I/O Register at the ring buffer pointer */
  825. outb(ring_ptr & 0xff, PIORL(base));
  826. outb(((ring_ptr >> 8) & PIORH_MASK), PIORH(base));
  827. /* First, determine how much we can read without wrapping around the
  828. ring buffer */
  829. if((addr + len) < (RX_BASE + RX_SIZE))
  830. chunk_len = len;
  831. else
  832. chunk_len = RX_BASE + RX_SIZE - addr;
  833. insb(PIOP(base), buf_ptr, chunk_len);
  834. buf_ptr += chunk_len;
  835. len -= chunk_len;
  836. ring_ptr = (ring_ptr - RX_BASE + chunk_len) % RX_SIZE + RX_BASE;
  837. }
  838. return(ring_ptr);
  839. } /* read_ringbuf */
  840. /*------------------------------------------------------------------*/
  841. /*
  842. * Reconfigure the i82593, or at least ask for it...
  843. * Because wv_82593_config use the transmission buffer, we must do it
  844. * when we are sure that there is no transmission, so we do it now
  845. * or in wavelan_packet_xmit() (I can't find any better place,
  846. * wavelan_interrupt is not an option...), so you may experience
  847. * some delay sometime...
  848. */
  849. static inline void
  850. wv_82593_reconfig(struct net_device * dev)
  851. {
  852. net_local * lp = netdev_priv(dev);
  853. struct pcmcia_device * link = lp->link;
  854. unsigned long flags;
  855. /* Arm the flag, will be cleard in wv_82593_config() */
  856. lp->reconfig_82593 = TRUE;
  857. /* Check if we can do it now ! */
  858. if((link->open) && (netif_running(dev)) && !(netif_queue_stopped(dev)))
  859. {
  860. spin_lock_irqsave(&lp->spinlock, flags); /* Disable interrupts */
  861. wv_82593_config(dev);
  862. spin_unlock_irqrestore(&lp->spinlock, flags); /* Re-enable interrupts */
  863. }
  864. else
  865. {
  866. #ifdef DEBUG_IOCTL_INFO
  867. printk(KERN_DEBUG
  868. "%s: wv_82593_reconfig(): delayed (state = %lX, link = %d)\n",
  869. dev->name, dev->state, link->open);
  870. #endif
  871. }
  872. }
  873. /********************* DEBUG & INFO SUBROUTINES *********************/
  874. /*
  875. * This routines are used in the code to show debug informations.
  876. * Most of the time, it dump the content of hardware structures...
  877. */
  878. #ifdef DEBUG_PSA_SHOW
  879. /*------------------------------------------------------------------*/
  880. /*
  881. * Print the formatted contents of the Parameter Storage Area.
  882. */
  883. static void
  884. wv_psa_show(psa_t * p)
  885. {
  886. printk(KERN_DEBUG "##### wavelan psa contents: #####\n");
  887. printk(KERN_DEBUG "psa_io_base_addr_1: 0x%02X %02X %02X %02X\n",
  888. p->psa_io_base_addr_1,
  889. p->psa_io_base_addr_2,
  890. p->psa_io_base_addr_3,
  891. p->psa_io_base_addr_4);
  892. printk(KERN_DEBUG "psa_rem_boot_addr_1: 0x%02X %02X %02X\n",
  893. p->psa_rem_boot_addr_1,
  894. p->psa_rem_boot_addr_2,
  895. p->psa_rem_boot_addr_3);
  896. printk(KERN_DEBUG "psa_holi_params: 0x%02x, ", p->psa_holi_params);
  897. printk("psa_int_req_no: %d\n", p->psa_int_req_no);
  898. #ifdef DEBUG_SHOW_UNUSED
  899. printk(KERN_DEBUG "psa_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
  900. p->psa_unused0[0],
  901. p->psa_unused0[1],
  902. p->psa_unused0[2],
  903. p->psa_unused0[3],
  904. p->psa_unused0[4],
  905. p->psa_unused0[5],
  906. p->psa_unused0[6]);
  907. #endif /* DEBUG_SHOW_UNUSED */
  908. printk(KERN_DEBUG "psa_univ_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
  909. p->psa_univ_mac_addr[0],
  910. p->psa_univ_mac_addr[1],
  911. p->psa_univ_mac_addr[2],
  912. p->psa_univ_mac_addr[3],
  913. p->psa_univ_mac_addr[4],
  914. p->psa_univ_mac_addr[5]);
  915. printk(KERN_DEBUG "psa_local_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
  916. p->psa_local_mac_addr[0],
  917. p->psa_local_mac_addr[1],
  918. p->psa_local_mac_addr[2],
  919. p->psa_local_mac_addr[3],
  920. p->psa_local_mac_addr[4],
  921. p->psa_local_mac_addr[5]);
  922. printk(KERN_DEBUG "psa_univ_local_sel: %d, ", p->psa_univ_local_sel);
  923. printk("psa_comp_number: %d, ", p->psa_comp_number);
  924. printk("psa_thr_pre_set: 0x%02x\n", p->psa_thr_pre_set);
  925. printk(KERN_DEBUG "psa_feature_select/decay_prm: 0x%02x, ",
  926. p->psa_feature_select);
  927. printk("psa_subband/decay_update_prm: %d\n", p->psa_subband);
  928. printk(KERN_DEBUG "psa_quality_thr: 0x%02x, ", p->psa_quality_thr);
  929. printk("psa_mod_delay: 0x%02x\n", p->psa_mod_delay);
  930. printk(KERN_DEBUG "psa_nwid: 0x%02x%02x, ", p->psa_nwid[0], p->psa_nwid[1]);
  931. printk("psa_nwid_select: %d\n", p->psa_nwid_select);
  932. printk(KERN_DEBUG "psa_encryption_select: %d, ", p->psa_encryption_select);
  933. printk("psa_encryption_key[]: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
  934. p->psa_encryption_key[0],
  935. p->psa_encryption_key[1],
  936. p->psa_encryption_key[2],
  937. p->psa_encryption_key[3],
  938. p->psa_encryption_key[4],
  939. p->psa_encryption_key[5],
  940. p->psa_encryption_key[6],
  941. p->psa_encryption_key[7]);
  942. printk(KERN_DEBUG "psa_databus_width: %d\n", p->psa_databus_width);
  943. printk(KERN_DEBUG "psa_call_code/auto_squelch: 0x%02x, ",
  944. p->psa_call_code[0]);
  945. printk("psa_call_code[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
  946. p->psa_call_code[0],
  947. p->psa_call_code[1],
  948. p->psa_call_code[2],
  949. p->psa_call_code[3],
  950. p->psa_call_code[4],
  951. p->psa_call_code[5],
  952. p->psa_call_code[6],
  953. p->psa_call_code[7]);
  954. #ifdef DEBUG_SHOW_UNUSED
  955. printk(KERN_DEBUG "psa_reserved[]: %02X:%02X:%02X:%02X\n",
  956. p->psa_reserved[0],
  957. p->psa_reserved[1],
  958. p->psa_reserved[2],
  959. p->psa_reserved[3]);
  960. #endif /* DEBUG_SHOW_UNUSED */
  961. printk(KERN_DEBUG "psa_conf_status: %d, ", p->psa_conf_status);
  962. printk("psa_crc: 0x%02x%02x, ", p->psa_crc[0], p->psa_crc[1]);
  963. printk("psa_crc_status: 0x%02x\n", p->psa_crc_status);
  964. } /* wv_psa_show */
  965. #endif /* DEBUG_PSA_SHOW */
  966. #ifdef DEBUG_MMC_SHOW
  967. /*------------------------------------------------------------------*/
  968. /*
  969. * Print the formatted status of the Modem Management Controller.
  970. * This function need to be completed...
  971. */
  972. static void
  973. wv_mmc_show(struct net_device * dev)
  974. {
  975. kio_addr_t base = dev->base_addr;
  976. net_local * lp = netdev_priv(dev);
  977. mmr_t m;
  978. /* Basic check */
  979. if(hasr_read(base) & HASR_NO_CLK)
  980. {
  981. printk(KERN_WARNING "%s: wv_mmc_show: modem not connected\n",
  982. dev->name);
  983. return;
  984. }
  985. spin_lock_irqsave(&lp->spinlock, flags);
  986. /* Read the mmc */
  987. mmc_out(base, mmwoff(0, mmw_freeze), 1);
  988. mmc_read(base, 0, (u_char *)&m, sizeof(m));
  989. mmc_out(base, mmwoff(0, mmw_freeze), 0);
  990. /* Don't forget to update statistics */
  991. lp->wstats.discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
  992. spin_unlock_irqrestore(&lp->spinlock, flags);
  993. printk(KERN_DEBUG "##### wavelan modem status registers: #####\n");
  994. #ifdef DEBUG_SHOW_UNUSED
  995. printk(KERN_DEBUG "mmc_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
  996. m.mmr_unused0[0],
  997. m.mmr_unused0[1],
  998. m.mmr_unused0[2],
  999. m.mmr_unused0[3],
  1000. m.mmr_unused0[4],
  1001. m.mmr_unused0[5],
  1002. m.mmr_unused0[6],
  1003. m.mmr_unused0[7]);
  1004. #endif /* DEBUG_SHOW_UNUSED */
  1005. printk(KERN_DEBUG "Encryption algorythm: %02X - Status: %02X\n",
  1006. m.mmr_des_avail, m.mmr_des_status);
  1007. #ifdef DEBUG_SHOW_UNUSED
  1008. printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n",
  1009. m.mmr_unused1[0],
  1010. m.mmr_unused1[1],
  1011. m.mmr_unused1[2],
  1012. m.mmr_unused1[3],
  1013. m.mmr_unused1[4]);
  1014. #endif /* DEBUG_SHOW_UNUSED */
  1015. printk(KERN_DEBUG "dce_status: 0x%x [%s%s%s%s]\n",
  1016. m.mmr_dce_status,
  1017. (m.mmr_dce_status & MMR_DCE_STATUS_RX_BUSY) ? "energy detected,":"",
  1018. (m.mmr_dce_status & MMR_DCE_STATUS_LOOPT_IND) ?
  1019. "loop test indicated," : "",
  1020. (m.mmr_dce_status & MMR_DCE_STATUS_TX_BUSY) ? "transmitter on," : "",
  1021. (m.mmr_dce_status & MMR_DCE_STATUS_JBR_EXPIRED) ?
  1022. "jabber timer expired," : "");
  1023. printk(KERN_DEBUG "Dsp ID: %02X\n",
  1024. m.mmr_dsp_id);
  1025. #ifdef DEBUG_SHOW_UNUSED
  1026. printk(KERN_DEBUG "mmc_unused2[]: %02X:%02X\n",
  1027. m.mmr_unused2[0],
  1028. m.mmr_unused2[1]);
  1029. #endif /* DEBUG_SHOW_UNUSED */
  1030. printk(KERN_DEBUG "# correct_nwid: %d, # wrong_nwid: %d\n",
  1031. (m.mmr_correct_nwid_h << 8) | m.mmr_correct_nwid_l,
  1032. (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l);
  1033. printk(KERN_DEBUG "thr_pre_set: 0x%x [current signal %s]\n",
  1034. m.mmr_thr_pre_set & MMR_THR_PRE_SET,
  1035. (m.mmr_thr_pre_set & MMR_THR_PRE_SET_CUR) ? "above" : "below");
  1036. printk(KERN_DEBUG "signal_lvl: %d [%s], ",
  1037. m.mmr_signal_lvl & MMR_SIGNAL_LVL,
  1038. (m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) ? "new msg" : "no new msg");
  1039. printk("silence_lvl: %d [%s], ", m.mmr_silence_lvl & MMR_SILENCE_LVL,
  1040. (m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) ? "update done" : "no new update");
  1041. printk("sgnl_qual: 0x%x [%s]\n", m.mmr_sgnl_qual & MMR_SGNL_QUAL,
  1042. (m.mmr_sgnl_qual & MMR_SGNL_QUAL_ANT) ? "Antenna 1" : "Antenna 0");
  1043. #ifdef DEBUG_SHOW_UNUSED
  1044. printk(KERN_DEBUG "netw_id_l: %x\n", m.mmr_netw_id_l);
  1045. #endif /* DEBUG_SHOW_UNUSED */
  1046. } /* wv_mmc_show */
  1047. #endif /* DEBUG_MMC_SHOW */
  1048. #ifdef DEBUG_I82593_SHOW
  1049. /*------------------------------------------------------------------*/
  1050. /*
  1051. * Print the formatted status of the i82593's receive unit.
  1052. */
  1053. static void
  1054. wv_ru_show(struct net_device * dev)
  1055. {
  1056. net_local *lp = netdev_priv(dev);
  1057. printk(KERN_DEBUG "##### wavelan i82593 receiver status: #####\n");
  1058. printk(KERN_DEBUG "ru: rfp %d stop %d", lp->rfp, lp->stop);
  1059. /*
  1060. * Not implemented yet...
  1061. */
  1062. printk("\n");
  1063. } /* wv_ru_show */
  1064. #endif /* DEBUG_I82593_SHOW */
  1065. #ifdef DEBUG_DEVICE_SHOW
  1066. /*------------------------------------------------------------------*/
  1067. /*
  1068. * Print the formatted status of the WaveLAN PCMCIA device driver.
  1069. */
  1070. static void
  1071. wv_dev_show(struct net_device * dev)
  1072. {
  1073. printk(KERN_DEBUG "dev:");
  1074. printk(" state=%lX,", dev->state);
  1075. printk(" trans_start=%ld,", dev->trans_start);
  1076. printk(" flags=0x%x,", dev->flags);
  1077. printk("\n");
  1078. } /* wv_dev_show */
  1079. /*------------------------------------------------------------------*/
  1080. /*
  1081. * Print the formatted status of the WaveLAN PCMCIA device driver's
  1082. * private information.
  1083. */
  1084. static void
  1085. wv_local_show(struct net_device * dev)
  1086. {
  1087. net_local *lp = netdev_priv(dev);
  1088. printk(KERN_DEBUG "local:");
  1089. /*
  1090. * Not implemented yet...
  1091. */
  1092. printk("\n");
  1093. } /* wv_local_show */
  1094. #endif /* DEBUG_DEVICE_SHOW */
  1095. #if defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO)
  1096. /*------------------------------------------------------------------*/
  1097. /*
  1098. * Dump packet header (and content if necessary) on the screen
  1099. */
  1100. static inline void
  1101. wv_packet_info(u_char * p, /* Packet to dump */
  1102. int length, /* Length of the packet */
  1103. char * msg1, /* Name of the device */
  1104. char * msg2) /* Name of the function */
  1105. {
  1106. int i;
  1107. int maxi;
  1108. printk(KERN_DEBUG "%s: %s(): dest %02X:%02X:%02X:%02X:%02X:%02X, length %d\n",
  1109. msg1, msg2, p[0], p[1], p[2], p[3], p[4], p[5], length);
  1110. printk(KERN_DEBUG "%s: %s(): src %02X:%02X:%02X:%02X:%02X:%02X, type 0x%02X%02X\n",
  1111. msg1, msg2, p[6], p[7], p[8], p[9], p[10], p[11], p[12], p[13]);
  1112. #ifdef DEBUG_PACKET_DUMP
  1113. printk(KERN_DEBUG "data=\"");
  1114. if((maxi = length) > DEBUG_PACKET_DUMP)
  1115. maxi = DEBUG_PACKET_DUMP;
  1116. for(i = 14; i < maxi; i++)
  1117. if(p[i] >= ' ' && p[i] <= '~')
  1118. printk(" %c", p[i]);
  1119. else
  1120. printk("%02X", p[i]);
  1121. if(maxi < length)
  1122. printk("..");
  1123. printk("\"\n");
  1124. printk(KERN_DEBUG "\n");
  1125. #endif /* DEBUG_PACKET_DUMP */
  1126. }
  1127. #endif /* defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) */
  1128. /*------------------------------------------------------------------*/
  1129. /*
  1130. * This is the information which is displayed by the driver at startup
  1131. * There is a lot of flag to configure it at your will...
  1132. */
  1133. static inline void
  1134. wv_init_info(struct net_device * dev)
  1135. {
  1136. kio_addr_t base = dev->base_addr;
  1137. psa_t psa;
  1138. int i;
  1139. /* Read the parameter storage area */
  1140. psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
  1141. #ifdef DEBUG_PSA_SHOW
  1142. wv_psa_show(&psa);
  1143. #endif
  1144. #ifdef DEBUG_MMC_SHOW
  1145. wv_mmc_show(dev);
  1146. #endif
  1147. #ifdef DEBUG_I82593_SHOW
  1148. wv_ru_show(dev);
  1149. #endif
  1150. #ifdef DEBUG_BASIC_SHOW
  1151. /* Now, let's go for the basic stuff */
  1152. printk(KERN_NOTICE "%s: WaveLAN: port %#lx, irq %d, hw_addr",
  1153. dev->name, base, dev->irq);
  1154. for(i = 0; i < WAVELAN_ADDR_SIZE; i++)
  1155. printk("%s%02X", (i == 0) ? " " : ":", dev->dev_addr[i]);
  1156. /* Print current network id */
  1157. if(psa.psa_nwid_select)
  1158. printk(", nwid 0x%02X-%02X", psa.psa_nwid[0], psa.psa_nwid[1]);
  1159. else
  1160. printk(", nwid off");
  1161. /* If 2.00 card */
  1162. if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
  1163. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
  1164. {
  1165. unsigned short freq;
  1166. /* Ask the EEprom to read the frequency from the first area */
  1167. fee_read(base, 0x00 /* 1st area - frequency... */,
  1168. &freq, 1);
  1169. /* Print frequency */
  1170. printk(", 2.00, %ld", (freq >> 6) + 2400L);
  1171. /* Hack !!! */
  1172. if(freq & 0x20)
  1173. printk(".5");
  1174. }
  1175. else
  1176. {
  1177. printk(", PCMCIA, ");
  1178. switch (psa.psa_subband)
  1179. {
  1180. case PSA_SUBBAND_915:
  1181. printk("915");
  1182. break;
  1183. case PSA_SUBBAND_2425:
  1184. printk("2425");
  1185. break;
  1186. case PSA_SUBBAND_2460:
  1187. printk("2460");
  1188. break;
  1189. case PSA_SUBBAND_2484:
  1190. printk("2484");
  1191. break;
  1192. case PSA_SUBBAND_2430_5:
  1193. printk("2430.5");
  1194. break;
  1195. default:
  1196. printk("unknown");
  1197. }
  1198. }
  1199. printk(" MHz\n");
  1200. #endif /* DEBUG_BASIC_SHOW */
  1201. #ifdef DEBUG_VERSION_SHOW
  1202. /* Print version information */
  1203. printk(KERN_NOTICE "%s", version);
  1204. #endif
  1205. } /* wv_init_info */
  1206. /********************* IOCTL, STATS & RECONFIG *********************/
  1207. /*
  1208. * We found here routines that are called by Linux on differents
  1209. * occasions after the configuration and not for transmitting data
  1210. * These may be called when the user use ifconfig, /proc/net/dev
  1211. * or wireless extensions
  1212. */
  1213. /*------------------------------------------------------------------*/
  1214. /*
  1215. * Get the current ethernet statistics. This may be called with the
  1216. * card open or closed.
  1217. * Used when the user read /proc/net/dev
  1218. */
  1219. static en_stats *
  1220. wavelan_get_stats(struct net_device * dev)
  1221. {
  1222. #ifdef DEBUG_IOCTL_TRACE
  1223. printk(KERN_DEBUG "%s: <>wavelan_get_stats()\n", dev->name);
  1224. #endif
  1225. return(&((net_local *)netdev_priv(dev))->stats);
  1226. }
  1227. /*------------------------------------------------------------------*/
  1228. /*
  1229. * Set or clear the multicast filter for this adaptor.
  1230. * num_addrs == -1 Promiscuous mode, receive all packets
  1231. * num_addrs == 0 Normal mode, clear multicast list
  1232. * num_addrs > 0 Multicast mode, receive normal and MC packets,
  1233. * and do best-effort filtering.
  1234. */
  1235. static void
  1236. wavelan_set_multicast_list(struct net_device * dev)
  1237. {
  1238. net_local * lp = netdev_priv(dev);
  1239. #ifdef DEBUG_IOCTL_TRACE
  1240. printk(KERN_DEBUG "%s: ->wavelan_set_multicast_list()\n", dev->name);
  1241. #endif
  1242. #ifdef DEBUG_IOCTL_INFO
  1243. printk(KERN_DEBUG "%s: wavelan_set_multicast_list(): setting Rx mode %02X to %d addresses.\n",
  1244. dev->name, dev->flags, dev->mc_count);
  1245. #endif
  1246. if(dev->flags & IFF_PROMISC)
  1247. {
  1248. /*
  1249. * Enable promiscuous mode: receive all packets.
  1250. */
  1251. if(!lp->promiscuous)
  1252. {
  1253. lp->promiscuous = 1;
  1254. lp->allmulticast = 0;
  1255. lp->mc_count = 0;
  1256. wv_82593_reconfig(dev);
  1257. /* Tell the kernel that we are doing a really bad job... */
  1258. dev->flags |= IFF_PROMISC;
  1259. }
  1260. }
  1261. else
  1262. /* If all multicast addresses
  1263. * or too much multicast addresses for the hardware filter */
  1264. if((dev->flags & IFF_ALLMULTI) ||
  1265. (dev->mc_count > I82593_MAX_MULTICAST_ADDRESSES))
  1266. {
  1267. /*
  1268. * Disable promiscuous mode, but active the all multicast mode
  1269. */
  1270. if(!lp->allmulticast)
  1271. {
  1272. lp->promiscuous = 0;
  1273. lp->allmulticast = 1;
  1274. lp->mc_count = 0;
  1275. wv_82593_reconfig(dev);
  1276. /* Tell the kernel that we are doing a really bad job... */
  1277. dev->flags |= IFF_ALLMULTI;
  1278. }
  1279. }
  1280. else
  1281. /* If there is some multicast addresses to send */
  1282. if(dev->mc_list != (struct dev_mc_list *) NULL)
  1283. {
  1284. /*
  1285. * Disable promiscuous mode, but receive all packets
  1286. * in multicast list
  1287. */
  1288. #ifdef MULTICAST_AVOID
  1289. if(lp->promiscuous || lp->allmulticast ||
  1290. (dev->mc_count != lp->mc_count))
  1291. #endif
  1292. {
  1293. lp->promiscuous = 0;
  1294. lp->allmulticast = 0;
  1295. lp->mc_count = dev->mc_count;
  1296. wv_82593_reconfig(dev);
  1297. }
  1298. }
  1299. else
  1300. {
  1301. /*
  1302. * Switch to normal mode: disable promiscuous mode and
  1303. * clear the multicast list.
  1304. */
  1305. if(lp->promiscuous || lp->mc_count == 0)
  1306. {
  1307. lp->promiscuous = 0;
  1308. lp->allmulticast = 0;
  1309. lp->mc_count = 0;
  1310. wv_82593_reconfig(dev);
  1311. }
  1312. }
  1313. #ifdef DEBUG_IOCTL_TRACE
  1314. printk(KERN_DEBUG "%s: <-wavelan_set_multicast_list()\n", dev->name);
  1315. #endif
  1316. }
  1317. /*------------------------------------------------------------------*/
  1318. /*
  1319. * This function doesn't exist...
  1320. * (Note : it was a nice way to test the reconfigure stuff...)
  1321. */
  1322. #ifdef SET_MAC_ADDRESS
  1323. static int
  1324. wavelan_set_mac_address(struct net_device * dev,
  1325. void * addr)
  1326. {
  1327. struct sockaddr * mac = addr;
  1328. /* Copy the address */
  1329. memcpy(dev->dev_addr, mac->sa_data, WAVELAN_ADDR_SIZE);
  1330. /* Reconfig the beast */
  1331. wv_82593_reconfig(dev);
  1332. return 0;
  1333. }
  1334. #endif /* SET_MAC_ADDRESS */
  1335. /*------------------------------------------------------------------*/
  1336. /*
  1337. * Frequency setting (for hardware able of it)
  1338. * It's a bit complicated and you don't really want to look into it...
  1339. */
  1340. static inline int
  1341. wv_set_frequency(u_long base, /* i/o port of the card */
  1342. iw_freq * frequency)
  1343. {
  1344. const int BAND_NUM = 10; /* Number of bands */
  1345. long freq = 0L; /* offset to 2.4 GHz in .5 MHz */
  1346. #ifdef DEBUG_IOCTL_INFO
  1347. int i;
  1348. #endif
  1349. /* Setting by frequency */
  1350. /* Theoritically, you may set any frequency between
  1351. * the two limits with a 0.5 MHz precision. In practice,
  1352. * I don't want you to have trouble with local
  1353. * regulations... */
  1354. if((frequency->e == 1) &&
  1355. (frequency->m >= (int) 2.412e8) && (frequency->m <= (int) 2.487e8))
  1356. {
  1357. freq = ((frequency->m / 10000) - 24000L) / 5;
  1358. }
  1359. /* Setting by channel (same as wfreqsel) */
  1360. /* Warning : each channel is 22MHz wide, so some of the channels
  1361. * will interfere... */
  1362. if((frequency->e == 0) &&
  1363. (frequency->m >= 0) && (frequency->m < BAND_NUM))
  1364. {
  1365. /* Get frequency offset. */
  1366. freq = channel_bands[frequency->m] >> 1;
  1367. }
  1368. /* Verify if the frequency is allowed */
  1369. if(freq != 0L)
  1370. {
  1371. u_short table[10]; /* Authorized frequency table */
  1372. /* Read the frequency table */
  1373. fee_read(base, 0x71 /* frequency table */,
  1374. table, 10);
  1375. #ifdef DEBUG_IOCTL_INFO
  1376. printk(KERN_DEBUG "Frequency table :");
  1377. for(i = 0; i < 10; i++)
  1378. {
  1379. printk(" %04X",
  1380. table[i]);
  1381. }
  1382. printk("\n");
  1383. #endif
  1384. /* Look in the table if the frequency is allowed */
  1385. if(!(table[9 - ((freq - 24) / 16)] &
  1386. (1 << ((freq - 24) % 16))))
  1387. return -EINVAL; /* not allowed */
  1388. }
  1389. else
  1390. return -EINVAL;
  1391. /* If we get a usable frequency */
  1392. if(freq != 0L)
  1393. {
  1394. unsigned short area[16];
  1395. unsigned short dac[2];
  1396. unsigned short area_verify[16];
  1397. unsigned short dac_verify[2];
  1398. /* Corresponding gain (in the power adjust value table)
  1399. * see AT&T Wavelan Data Manual, REF 407-024689/E, page 3-8
  1400. * & WCIN062D.DOC, page 6.2.9 */
  1401. unsigned short power_limit[] = { 40, 80, 120, 160, 0 };
  1402. int power_band = 0; /* Selected band */
  1403. unsigned short power_adjust; /* Correct value */
  1404. /* Search for the gain */
  1405. power_band = 0;
  1406. while((freq > power_limit[power_band]) &&
  1407. (power_limit[++power_band] != 0))
  1408. ;
  1409. /* Read the first area */
  1410. fee_read(base, 0x00,
  1411. area, 16);
  1412. /* Read the DAC */
  1413. fee_read(base, 0x60,
  1414. dac, 2);
  1415. /* Read the new power adjust value */
  1416. fee_read(base, 0x6B - (power_band >> 1),
  1417. &power_adjust, 1);
  1418. if(power_band & 0x1)
  1419. power_adjust >>= 8;
  1420. else
  1421. power_adjust &= 0xFF;
  1422. #ifdef DEBUG_IOCTL_INFO
  1423. printk(KERN_DEBUG "Wavelan EEprom Area 1 :");
  1424. for(i = 0; i < 16; i++)
  1425. {
  1426. printk(" %04X",
  1427. area[i]);
  1428. }
  1429. printk("\n");
  1430. printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n",
  1431. dac[0], dac[1]);
  1432. #endif
  1433. /* Frequency offset (for info only...) */
  1434. area[0] = ((freq << 5) & 0xFFE0) | (area[0] & 0x1F);
  1435. /* Receiver Principle main divider coefficient */
  1436. area[3] = (freq >> 1) + 2400L - 352L;
  1437. area[2] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
  1438. /* Transmitter Main divider coefficient */
  1439. area[13] = (freq >> 1) + 2400L;
  1440. area[12] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
  1441. /* Others part of the area are flags, bit streams or unused... */
  1442. /* Set the value in the DAC */
  1443. dac[1] = ((power_adjust >> 1) & 0x7F) | (dac[1] & 0xFF80);
  1444. dac[0] = ((power_adjust & 0x1) << 4) | (dac[0] & 0xFFEF);
  1445. /* Write the first area */
  1446. fee_write(base, 0x00,
  1447. area, 16);
  1448. /* Write the DAC */
  1449. fee_write(base, 0x60,
  1450. dac, 2);
  1451. /* We now should verify here that the EEprom writting was ok */
  1452. /* ReRead the first area */
  1453. fee_read(base, 0x00,
  1454. area_verify, 16);
  1455. /* ReRead the DAC */
  1456. fee_read(base, 0x60,
  1457. dac_verify, 2);
  1458. /* Compare */
  1459. if(memcmp(area, area_verify, 16 * 2) ||
  1460. memcmp(dac, dac_verify, 2 * 2))
  1461. {
  1462. #ifdef DEBUG_IOCTL_ERROR
  1463. printk(KERN_INFO "Wavelan: wv_set_frequency : unable to write new frequency to EEprom (?)\n");
  1464. #endif
  1465. return -EOPNOTSUPP;
  1466. }
  1467. /* We must download the frequency parameters to the
  1468. * synthetisers (from the EEprom - area 1)
  1469. * Note : as the EEprom is auto decremented, we set the end
  1470. * if the area... */
  1471. mmc_out(base, mmwoff(0, mmw_fee_addr), 0x0F);
  1472. mmc_out(base, mmwoff(0, mmw_fee_ctrl),
  1473. MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
  1474. /* Wait until the download is finished */
  1475. fee_wait(base, 100, 100);
  1476. /* We must now download the power adjust value (gain) to
  1477. * the synthetisers (from the EEprom - area 7 - DAC) */
  1478. mmc_out(base, mmwoff(0, mmw_fee_addr), 0x61);
  1479. mmc_out(base, mmwoff(0, mmw_fee_ctrl),
  1480. MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
  1481. /* Wait until the download is finished */
  1482. fee_wait(base, 100, 100);
  1483. #ifdef DEBUG_IOCTL_INFO
  1484. /* Verification of what we have done... */
  1485. printk(KERN_DEBUG "Wavelan EEprom Area 1 :");
  1486. for(i = 0; i < 16; i++)
  1487. {
  1488. printk(" %04X",
  1489. area_verify[i]);
  1490. }
  1491. printk("\n");
  1492. printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n",
  1493. dac_verify[0], dac_verify[1]);
  1494. #endif
  1495. return 0;
  1496. }
  1497. else
  1498. return -EINVAL; /* Bah, never get there... */
  1499. }
  1500. /*------------------------------------------------------------------*/
  1501. /*
  1502. * Give the list of available frequencies
  1503. */
  1504. static inline int
  1505. wv_frequency_list(u_long base, /* i/o port of the card */
  1506. iw_freq * list, /* List of frequency to fill */
  1507. int max) /* Maximum number of frequencies */
  1508. {
  1509. u_short table[10]; /* Authorized frequency table */
  1510. long freq = 0L; /* offset to 2.4 GHz in .5 MHz + 12 MHz */
  1511. int i; /* index in the table */
  1512. const int BAND_NUM = 10; /* Number of bands */
  1513. int c = 0; /* Channel number */
  1514. /* Read the frequency table */
  1515. fee_read(base, 0x71 /* frequency table */,
  1516. table, 10);
  1517. /* Look all frequencies */
  1518. i = 0;
  1519. for(freq = 0; freq < 150; freq++)
  1520. /* Look in the table if the frequency is allowed */
  1521. if(table[9 - (freq / 16)] & (1 << (freq % 16)))
  1522. {
  1523. /* Compute approximate channel number */
  1524. while((((channel_bands[c] >> 1) - 24) < freq) &&
  1525. (c < BAND_NUM))
  1526. c++;
  1527. list[i].i = c; /* Set the list index */
  1528. /* put in the list */
  1529. list[i].m = (((freq + 24) * 5) + 24000L) * 10000;
  1530. list[i++].e = 1;
  1531. /* Check number */
  1532. if(i >= max)
  1533. return(i);
  1534. }
  1535. return(i);
  1536. }
  1537. #ifdef IW_WIRELESS_SPY
  1538. /*------------------------------------------------------------------*/
  1539. /*
  1540. * Gather wireless spy statistics : for each packet, compare the source
  1541. * address with out list, and if match, get the stats...
  1542. * Sorry, but this function really need wireless extensions...
  1543. */
  1544. static inline void
  1545. wl_spy_gather(struct net_device * dev,
  1546. u_char * mac, /* MAC address */
  1547. u_char * stats) /* Statistics to gather */
  1548. {
  1549. struct iw_quality wstats;
  1550. wstats.qual = stats[2] & MMR_SGNL_QUAL;
  1551. wstats.level = stats[0] & MMR_SIGNAL_LVL;
  1552. wstats.noise = stats[1] & MMR_SILENCE_LVL;
  1553. wstats.updated = 0x7;
  1554. /* Update spy records */
  1555. wireless_spy_update(dev, mac, &wstats);
  1556. }
  1557. #endif /* IW_WIRELESS_SPY */
  1558. #ifdef HISTOGRAM
  1559. /*------------------------------------------------------------------*/
  1560. /*
  1561. * This function calculate an histogram on the signal level.
  1562. * As the noise is quite constant, it's like doing it on the SNR.
  1563. * We have defined a set of interval (lp->his_range), and each time
  1564. * the level goes in that interval, we increment the count (lp->his_sum).
  1565. * With this histogram you may detect if one wavelan is really weak,
  1566. * or you may also calculate the mean and standard deviation of the level...
  1567. */
  1568. static inline void
  1569. wl_his_gather(struct net_device * dev,
  1570. u_char * stats) /* Statistics to gather */
  1571. {
  1572. net_local * lp = netdev_priv(dev);
  1573. u_char level = stats[0] & MMR_SIGNAL_LVL;
  1574. int i;
  1575. /* Find the correct interval */
  1576. i = 0;
  1577. while((i < (lp->his_number - 1)) && (level >= lp->his_range[i++]))
  1578. ;
  1579. /* Increment interval counter */
  1580. (lp->his_sum[i])++;
  1581. }
  1582. #endif /* HISTOGRAM */
  1583. static void wl_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  1584. {
  1585. strncpy(info->driver, "wavelan_cs", sizeof(info->driver)-1);
  1586. }
  1587. static struct ethtool_ops ops = {
  1588. .get_drvinfo = wl_get_drvinfo
  1589. };
  1590. /*------------------------------------------------------------------*/
  1591. /*
  1592. * Wireless Handler : get protocol name
  1593. */
  1594. static int wavelan_get_name(struct net_device *dev,
  1595. struct iw_request_info *info,
  1596. union iwreq_data *wrqu,
  1597. char *extra)
  1598. {
  1599. strcpy(wrqu->name, "WaveLAN");
  1600. return 0;
  1601. }
  1602. /*------------------------------------------------------------------*/
  1603. /*
  1604. * Wireless Handler : set NWID
  1605. */
  1606. static int wavelan_set_nwid(struct net_device *dev,
  1607. struct iw_request_info *info,
  1608. union iwreq_data *wrqu,
  1609. char *extra)
  1610. {
  1611. kio_addr_t base = dev->base_addr;
  1612. net_local *lp = netdev_priv(dev);
  1613. psa_t psa;
  1614. mm_t m;
  1615. unsigned long flags;
  1616. int ret = 0;
  1617. /* Disable interrupts and save flags. */
  1618. spin_lock_irqsave(&lp->spinlock, flags);
  1619. /* Set NWID in WaveLAN. */
  1620. if (!wrqu->nwid.disabled) {
  1621. /* Set NWID in psa */
  1622. psa.psa_nwid[0] = (wrqu->nwid.value & 0xFF00) >> 8;
  1623. psa.psa_nwid[1] = wrqu->nwid.value & 0xFF;
  1624. psa.psa_nwid_select = 0x01;
  1625. psa_write(dev,
  1626. (char *) psa.psa_nwid - (char *) &psa,
  1627. (unsigned char *) psa.psa_nwid, 3);
  1628. /* Set NWID in mmc. */
  1629. m.w.mmw_netw_id_l = psa.psa_nwid[1];
  1630. m.w.mmw_netw_id_h = psa.psa_nwid[0];
  1631. mmc_write(base,
  1632. (char *) &m.w.mmw_netw_id_l -
  1633. (char *) &m,
  1634. (unsigned char *) &m.w.mmw_netw_id_l, 2);
  1635. mmc_out(base, mmwoff(0, mmw_loopt_sel), 0x00);
  1636. } else {
  1637. /* Disable NWID in the psa. */
  1638. psa.psa_nwid_select = 0x00;
  1639. psa_write(dev,
  1640. (char *) &psa.psa_nwid_select -
  1641. (char *) &psa,
  1642. (unsigned char *) &psa.psa_nwid_select,
  1643. 1);
  1644. /* Disable NWID in the mmc (no filtering). */
  1645. mmc_out(base, mmwoff(0, mmw_loopt_sel),
  1646. MMW_LOOPT_SEL_DIS_NWID);
  1647. }
  1648. /* update the Wavelan checksum */
  1649. update_psa_checksum(dev);
  1650. /* Enable interrupts and restore flags. */
  1651. spin_unlock_irqrestore(&lp->spinlock, flags);
  1652. return ret;
  1653. }
  1654. /*------------------------------------------------------------------*/
  1655. /*
  1656. * Wireless Handler : get NWID
  1657. */
  1658. static int wavelan_get_nwid(struct net_device *dev,
  1659. struct iw_request_info *info,
  1660. union iwreq_data *wrqu,
  1661. char *extra)
  1662. {
  1663. net_local *lp = netdev_priv(dev);
  1664. psa_t psa;
  1665. unsigned long flags;
  1666. int ret = 0;
  1667. /* Disable interrupts and save flags. */
  1668. spin_lock_irqsave(&lp->spinlock, flags);
  1669. /* Read the NWID. */
  1670. psa_read(dev,
  1671. (char *) psa.psa_nwid - (char *) &psa,
  1672. (unsigned char *) psa.psa_nwid, 3);
  1673. wrqu->nwid.value = (psa.psa_nwid[0] << 8) + psa.psa_nwid[1];
  1674. wrqu->nwid.disabled = !(psa.psa_nwid_select);
  1675. wrqu->nwid.fixed = 1; /* Superfluous */
  1676. /* Enable interrupts and restore flags. */
  1677. spin_unlock_irqrestore(&lp->spinlock, flags);
  1678. return ret;
  1679. }
  1680. /*------------------------------------------------------------------*/
  1681. /*
  1682. * Wireless Handler : set frequency
  1683. */
  1684. static int wavelan_set_freq(struct net_device *dev,
  1685. struct iw_request_info *info,
  1686. union iwreq_data *wrqu,
  1687. char *extra)
  1688. {
  1689. kio_addr_t base = dev->base_addr;
  1690. net_local *lp = netdev_priv(dev);
  1691. unsigned long flags;
  1692. int ret;
  1693. /* Disable interrupts and save flags. */
  1694. spin_lock_irqsave(&lp->spinlock, flags);
  1695. /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
  1696. if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
  1697. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
  1698. ret = wv_set_frequency(base, &(wrqu->freq));
  1699. else
  1700. ret = -EOPNOTSUPP;
  1701. /* Enable interrupts and restore flags. */
  1702. spin_unlock_irqrestore(&lp->spinlock, flags);
  1703. return ret;
  1704. }
  1705. /*------------------------------------------------------------------*/
  1706. /*
  1707. * Wireless Handler : get frequency
  1708. */
  1709. static int wavelan_get_freq(struct net_device *dev,
  1710. struct iw_request_info *info,
  1711. union iwreq_data *wrqu,
  1712. char *extra)
  1713. {
  1714. kio_addr_t base = dev->base_addr;
  1715. net_local *lp = netdev_priv(dev);
  1716. psa_t psa;
  1717. unsigned long flags;
  1718. int ret = 0;
  1719. /* Disable interrupts and save flags. */
  1720. spin_lock_irqsave(&lp->spinlock, flags);
  1721. /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable).
  1722. * Does it work for everybody, especially old cards? */
  1723. if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
  1724. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
  1725. unsigned short freq;
  1726. /* Ask the EEPROM to read the frequency from the first area. */
  1727. fee_read(base, 0x00, &freq, 1);
  1728. wrqu->freq.m = ((freq >> 5) * 5 + 24000L) * 10000;
  1729. wrqu->freq.e = 1;
  1730. } else {
  1731. psa_read(dev,
  1732. (char *) &psa.psa_subband - (char *) &psa,
  1733. (unsigned char *) &psa.psa_subband, 1);
  1734. if (psa.psa_subband <= 4) {
  1735. wrqu->freq.m = fixed_bands[psa.psa_subband];
  1736. wrqu->freq.e = (psa.psa_subband != 0);
  1737. } else
  1738. ret = -EOPNOTSUPP;
  1739. }
  1740. /* Enable interrupts and restore flags. */
  1741. spin_unlock_irqrestore(&lp->spinlock, flags);
  1742. return ret;
  1743. }
  1744. /*------------------------------------------------------------------*/
  1745. /*
  1746. * Wireless Handler : set level threshold
  1747. */
  1748. static int wavelan_set_sens(struct net_device *dev,
  1749. struct iw_request_info *info,
  1750. union iwreq_data *wrqu,
  1751. char *extra)
  1752. {
  1753. kio_addr_t base = dev->base_addr;
  1754. net_local *lp = netdev_priv(dev);
  1755. psa_t psa;
  1756. unsigned long flags;
  1757. int ret = 0;
  1758. /* Disable interrupts and save flags. */
  1759. spin_lock_irqsave(&lp->spinlock, flags);
  1760. /* Set the level threshold. */
  1761. /* We should complain loudly if wrqu->sens.fixed = 0, because we
  1762. * can't set auto mode... */
  1763. psa.psa_thr_pre_set = wrqu->sens.value & 0x3F;
  1764. psa_write(dev,
  1765. (char *) &psa.psa_thr_pre_set - (char *) &psa,
  1766. (unsigned char *) &psa.psa_thr_pre_set, 1);
  1767. /* update the Wavelan checksum */
  1768. update_psa_checksum(dev);
  1769. mmc_out(base, mmwoff(0, mmw_thr_pre_set),
  1770. psa.psa_thr_pre_set);
  1771. /* Enable interrupts and restore flags. */
  1772. spin_unlock_irqrestore(&lp->spinlock, flags);
  1773. return ret;
  1774. }
  1775. /*------------------------------------------------------------------*/
  1776. /*
  1777. * Wireless Handler : get level threshold
  1778. */
  1779. static int wavelan_get_sens(struct net_device *dev,
  1780. struct iw_request_info *info,
  1781. union iwreq_data *wrqu,
  1782. char *extra)
  1783. {
  1784. net_local *lp = netdev_priv(dev);
  1785. psa_t psa;
  1786. unsigned long flags;
  1787. int ret = 0;
  1788. /* Disable interrupts and save flags. */
  1789. spin_lock_irqsave(&lp->spinlock, flags);
  1790. /* Read the level threshold. */
  1791. psa_read(dev,
  1792. (char *) &psa.psa_thr_pre_set - (char *) &psa,
  1793. (unsigned char *) &psa.psa_thr_pre_set, 1);
  1794. wrqu->sens.value = psa.psa_thr_pre_set & 0x3F;
  1795. wrqu->sens.fixed = 1;
  1796. /* Enable interrupts and restore flags. */
  1797. spin_unlock_irqrestore(&lp->spinlock, flags);
  1798. return ret;
  1799. }
  1800. /*------------------------------------------------------------------*/
  1801. /*
  1802. * Wireless Handler : set encryption key
  1803. */
  1804. static int wavelan_set_encode(struct net_device *dev,
  1805. struct iw_request_info *info,
  1806. union iwreq_data *wrqu,
  1807. char *extra)
  1808. {
  1809. kio_addr_t base = dev->base_addr;
  1810. net_local *lp = netdev_priv(dev);
  1811. unsigned long flags;
  1812. psa_t psa;
  1813. int ret = 0;
  1814. /* Disable interrupts and save flags. */
  1815. spin_lock_irqsave(&lp->spinlock, flags);
  1816. /* Check if capable of encryption */
  1817. if (!mmc_encr(base)) {
  1818. ret = -EOPNOTSUPP;
  1819. }
  1820. /* Check the size of the key */
  1821. if((wrqu->encoding.length != 8) && (wrqu->encoding.length != 0)) {
  1822. ret = -EINVAL;
  1823. }
  1824. if(!ret) {
  1825. /* Basic checking... */
  1826. if (wrqu->encoding.length == 8) {
  1827. /* Copy the key in the driver */
  1828. memcpy(psa.psa_encryption_key, extra,
  1829. wrqu->encoding.length);
  1830. psa.psa_encryption_select = 1;
  1831. psa_write(dev,
  1832. (char *) &psa.psa_encryption_select -
  1833. (char *) &psa,
  1834. (unsigned char *) &psa.
  1835. psa_encryption_select, 8 + 1);
  1836. mmc_out(base, mmwoff(0, mmw_encr_enable),
  1837. MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE);
  1838. mmc_write(base, mmwoff(0, mmw_encr_key),
  1839. (unsigned char *) &psa.
  1840. psa_encryption_key, 8);
  1841. }
  1842. /* disable encryption */
  1843. if (wrqu->encoding.flags & IW_ENCODE_DISABLED) {
  1844. psa.psa_encryption_select = 0;
  1845. psa_write(dev,
  1846. (char *) &psa.psa_encryption_select -
  1847. (char *) &psa,
  1848. (unsigned char *) &psa.
  1849. psa_encryption_select, 1);
  1850. mmc_out(base, mmwoff(0, mmw_encr_enable), 0);
  1851. }
  1852. /* update the Wavelan checksum */
  1853. update_psa_checksum(dev);
  1854. }
  1855. /* Enable interrupts and restore flags. */
  1856. spin_unlock_irqrestore(&lp->spinlock, flags);
  1857. return ret;
  1858. }
  1859. /*------------------------------------------------------------------*/
  1860. /*
  1861. * Wireless Handler : get encryption key
  1862. */
  1863. static int wavelan_get_encode(struct net_device *dev,
  1864. struct iw_request_info *info,
  1865. union iwreq_data *wrqu,
  1866. char *extra)
  1867. {
  1868. kio_addr_t base = dev->base_addr;
  1869. net_local *lp = netdev_priv(dev);
  1870. psa_t psa;
  1871. unsigned long flags;
  1872. int ret = 0;
  1873. /* Disable interrupts and save flags. */
  1874. spin_lock_irqsave(&lp->spinlock, flags);
  1875. /* Check if encryption is available */
  1876. if (!mmc_encr(base)) {
  1877. ret = -EOPNOTSUPP;
  1878. } else {
  1879. /* Read the encryption key */
  1880. psa_read(dev,
  1881. (char *) &psa.psa_encryption_select -
  1882. (char *) &psa,
  1883. (unsigned char *) &psa.
  1884. psa_encryption_select, 1 + 8);
  1885. /* encryption is enabled ? */
  1886. if (psa.psa_encryption_select)
  1887. wrqu->encoding.flags = IW_ENCODE_ENABLED;
  1888. else
  1889. wrqu->encoding.flags = IW_ENCODE_DISABLED;
  1890. wrqu->encoding.flags |= mmc_encr(base);
  1891. /* Copy the key to the user buffer */
  1892. wrqu->encoding.length = 8;
  1893. memcpy(extra, psa.psa_encryption_key, wrqu->encoding.length);
  1894. }
  1895. /* Enable interrupts and restore flags. */
  1896. spin_unlock_irqrestore(&lp->spinlock, flags);
  1897. return ret;
  1898. }
  1899. #ifdef WAVELAN_ROAMING_EXT
  1900. /*------------------------------------------------------------------*/
  1901. /*
  1902. * Wireless Handler : set ESSID (domain)
  1903. */
  1904. static int wavelan_set_essid(struct net_device *dev,
  1905. struct iw_request_info *info,
  1906. union iwreq_data *wrqu,
  1907. char *extra)
  1908. {
  1909. net_local *lp = netdev_priv(dev);
  1910. unsigned long flags;
  1911. int ret = 0;
  1912. /* Disable interrupts and save flags. */
  1913. spin_lock_irqsave(&lp->spinlock, flags);
  1914. /* Check if disable */
  1915. if(wrqu->data.flags == 0)
  1916. lp->filter_domains = 0;
  1917. else {
  1918. char essid[IW_ESSID_MAX_SIZE + 1];
  1919. char * endp;
  1920. /* Terminate the string */
  1921. memcpy(essid, extra, wrqu->data.length);
  1922. essid[IW_ESSID_MAX_SIZE] = '\0';
  1923. #ifdef DEBUG_IOCTL_INFO
  1924. printk(KERN_DEBUG "SetEssid : ``%s''\n", essid);
  1925. #endif /* DEBUG_IOCTL_INFO */
  1926. /* Convert to a number (note : Wavelan specific) */
  1927. lp->domain_id = simple_strtoul(essid, &endp, 16);
  1928. /* Has it worked ? */
  1929. if(endp > essid)
  1930. lp->filter_domains = 1;
  1931. else {
  1932. lp->filter_domains = 0;
  1933. ret = -EINVAL;
  1934. }
  1935. }
  1936. /* Enable interrupts and restore flags. */
  1937. spin_unlock_irqrestore(&lp->spinlock, flags);
  1938. return ret;
  1939. }
  1940. /*------------------------------------------------------------------*/
  1941. /*
  1942. * Wireless Handler : get ESSID (domain)
  1943. */
  1944. static int wavelan_get_essid(struct net_device *dev,
  1945. struct iw_request_info *info,
  1946. union iwreq_data *wrqu,
  1947. char *extra)
  1948. {
  1949. net_local *lp = netdev_priv(dev);
  1950. /* Is the domain ID active ? */
  1951. wrqu->data.flags = lp->filter_domains;
  1952. /* Copy Domain ID into a string (Wavelan specific) */
  1953. /* Sound crazy, be we can't have a snprintf in the kernel !!! */
  1954. sprintf(extra, "%lX", lp->domain_id);
  1955. extra[IW_ESSID_MAX_SIZE] = '\0';
  1956. /* Set the length */
  1957. wrqu->data.length = strlen(extra);
  1958. return 0;
  1959. }
  1960. /*------------------------------------------------------------------*/
  1961. /*
  1962. * Wireless Handler : set AP address
  1963. */
  1964. static int wavelan_set_wap(struct net_device *dev,
  1965. struct iw_request_info *info,
  1966. union iwreq_data *wrqu,
  1967. char *extra)
  1968. {
  1969. #ifdef DEBUG_IOCTL_INFO
  1970. printk(KERN_DEBUG "Set AP to : %02X:%02X:%02X:%02X:%02X:%02X\n",
  1971. wrqu->ap_addr.sa_data[0],
  1972. wrqu->ap_addr.sa_data[1],
  1973. wrqu->ap_addr.sa_data[2],
  1974. wrqu->ap_addr.sa_data[3],
  1975. wrqu->ap_addr.sa_data[4],
  1976. wrqu->ap_addr.sa_data[5]);
  1977. #endif /* DEBUG_IOCTL_INFO */
  1978. return -EOPNOTSUPP;
  1979. }
  1980. /*------------------------------------------------------------------*/
  1981. /*
  1982. * Wireless Handler : get AP address
  1983. */
  1984. static int wavelan_get_wap(struct net_device *dev,
  1985. struct iw_request_info *info,
  1986. union iwreq_data *wrqu,
  1987. char *extra)
  1988. {
  1989. /* Should get the real McCoy instead of own Ethernet address */
  1990. memcpy(wrqu->ap_addr.sa_data, dev->dev_addr, WAVELAN_ADDR_SIZE);
  1991. wrqu->ap_addr.sa_family = ARPHRD_ETHER;
  1992. return -EOPNOTSUPP;
  1993. }
  1994. #endif /* WAVELAN_ROAMING_EXT */
  1995. #ifdef WAVELAN_ROAMING
  1996. /*------------------------------------------------------------------*/
  1997. /*
  1998. * Wireless Handler : set mode
  1999. */
  2000. static int wavelan_set_mode(struct net_device *dev,
  2001. struct iw_request_info *info,
  2002. union iwreq_data *wrqu,
  2003. char *extra)
  2004. {
  2005. net_local *lp = netdev_priv(dev);
  2006. unsigned long flags;
  2007. int ret = 0;
  2008. /* Disable interrupts and save flags. */
  2009. spin_lock_irqsave(&lp->spinlock, flags);
  2010. /* Check mode */
  2011. switch(wrqu->mode) {
  2012. case IW_MODE_ADHOC:
  2013. if(do_roaming) {
  2014. wv_roam_cleanup(dev);
  2015. do_roaming = 0;
  2016. }
  2017. break;
  2018. case IW_MODE_INFRA:
  2019. if(!do_roaming) {
  2020. wv_roam_init(dev);
  2021. do_roaming = 1;
  2022. }
  2023. break;
  2024. default:
  2025. ret = -EINVAL;
  2026. }
  2027. /* Enable interrupts and restore flags. */
  2028. spin_unlock_irqrestore(&lp->spinlock, flags);
  2029. return ret;
  2030. }
  2031. /*------------------------------------------------------------------*/
  2032. /*
  2033. * Wireless Handler : get mode
  2034. */
  2035. static int wavelan_get_mode(struct net_device *dev,
  2036. struct iw_request_info *info,
  2037. union iwreq_data *wrqu,
  2038. char *extra)
  2039. {
  2040. if(do_roaming)
  2041. wrqu->mode = IW_MODE_INFRA;
  2042. else
  2043. wrqu->mode = IW_MODE_ADHOC;
  2044. return 0;
  2045. }
  2046. #endif /* WAVELAN_ROAMING */
  2047. /*------------------------------------------------------------------*/
  2048. /*
  2049. * Wireless Handler : get range info
  2050. */
  2051. static int wavelan_get_range(struct net_device *dev,
  2052. struct iw_request_info *info,
  2053. union iwreq_data *wrqu,
  2054. char *extra)
  2055. {
  2056. kio_addr_t base = dev->base_addr;
  2057. net_local *lp = netdev_priv(dev);
  2058. struct iw_range *range = (struct iw_range *) extra;
  2059. unsigned long flags;
  2060. int ret = 0;
  2061. /* Set the length (very important for backward compatibility) */
  2062. wrqu->data.length = sizeof(struct iw_range);
  2063. /* Set all the info we don't care or don't know about to zero */
  2064. memset(range, 0, sizeof(struct iw_range));
  2065. /* Set the Wireless Extension versions */
  2066. range->we_version_compiled = WIRELESS_EXT;
  2067. range->we_version_source = 9;
  2068. /* Set information in the range struct. */
  2069. range->throughput = 1.4 * 1000 * 1000; /* don't argue on this ! */
  2070. range->min_nwid = 0x0000;
  2071. range->max_nwid = 0xFFFF;
  2072. range->sensitivity = 0x3F;
  2073. range->max_qual.qual = MMR_SGNL_QUAL;
  2074. range->max_qual.level = MMR_SIGNAL_LVL;
  2075. range->max_qual.noise = MMR_SILENCE_LVL;
  2076. range->avg_qual.qual = MMR_SGNL_QUAL; /* Always max */
  2077. /* Need to get better values for those two */
  2078. range->avg_qual.level = 30;
  2079. range->avg_qual.noise = 8;
  2080. range->num_bitrates = 1;
  2081. range->bitrate[0] = 2000000; /* 2 Mb/s */
  2082. /* Event capability (kernel + driver) */
  2083. range->event_capa[0] = (IW_EVENT_CAPA_MASK(0x8B02) |
  2084. IW_EVENT_CAPA_MASK(0x8B04) |
  2085. IW_EVENT_CAPA_MASK(0x8B06));
  2086. range->event_capa[1] = IW_EVENT_CAPA_K_1;
  2087. /* Disable interrupts and save flags. */
  2088. spin_lock_irqsave(&lp->spinlock, flags);
  2089. /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
  2090. if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
  2091. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
  2092. range->num_channels = 10;
  2093. range->num_frequency = wv_frequency_list(base, range->freq,
  2094. IW_MAX_FREQUENCIES);
  2095. } else
  2096. range->num_channels = range->num_frequency = 0;
  2097. /* Encryption supported ? */
  2098. if (mmc_encr(base)) {
  2099. range->encoding_size[0] = 8; /* DES = 64 bits key */
  2100. range->num_encoding_sizes = 1;
  2101. range->max_encoding_tokens = 1; /* Only one key possible */
  2102. } else {
  2103. range->num_encoding_sizes = 0;
  2104. range->max_encoding_tokens = 0;
  2105. }
  2106. /* Enable interrupts and restore flags. */
  2107. spin_unlock_irqrestore(&lp->spinlock, flags);
  2108. return ret;
  2109. }
  2110. /*------------------------------------------------------------------*/
  2111. /*
  2112. * Wireless Private Handler : set quality threshold
  2113. */
  2114. static int wavelan_set_qthr(struct net_device *dev,
  2115. struct iw_request_info *info,
  2116. union iwreq_data *wrqu,
  2117. char *extra)
  2118. {
  2119. kio_addr_t base = dev->base_addr;
  2120. net_local *lp = netdev_priv(dev);
  2121. psa_t psa;
  2122. unsigned long flags;
  2123. /* Disable interrupts and save flags. */
  2124. spin_lock_irqsave(&lp->spinlock, flags);
  2125. psa.psa_quality_thr = *(extra) & 0x0F;
  2126. psa_write(dev,
  2127. (char *) &psa.psa_quality_thr - (char *) &psa,
  2128. (unsigned char *) &psa.psa_quality_thr, 1);
  2129. /* update the Wavelan checksum */
  2130. update_psa_checksum(dev);
  2131. mmc_out(base, mmwoff(0, mmw_quality_thr),
  2132. psa.psa_quality_thr);
  2133. /* Enable interrupts and restore flags. */
  2134. spin_unlock_irqrestore(&lp->spinlock, flags);
  2135. return 0;
  2136. }
  2137. /*------------------------------------------------------------------*/
  2138. /*
  2139. * Wireless Private Handler : get quality threshold
  2140. */
  2141. static int wavelan_get_qthr(struct net_device *dev,
  2142. struct iw_request_info *info,
  2143. union iwreq_data *wrqu,
  2144. char *extra)
  2145. {
  2146. net_local *lp = netdev_priv(dev);
  2147. psa_t psa;
  2148. unsigned long flags;
  2149. /* Disable interrupts and save flags. */
  2150. spin_lock_irqsave(&lp->spinlock, flags);
  2151. psa_read(dev,
  2152. (char *) &psa.psa_quality_thr - (char *) &psa,
  2153. (unsigned char *) &psa.psa_quality_thr, 1);
  2154. *(extra) = psa.psa_quality_thr & 0x0F;
  2155. /* Enable interrupts and restore flags. */
  2156. spin_unlock_irqrestore(&lp->spinlock, flags);
  2157. return 0;
  2158. }
  2159. #ifdef WAVELAN_ROAMING
  2160. /*------------------------------------------------------------------*/
  2161. /*
  2162. * Wireless Private Handler : set roaming
  2163. */
  2164. static int wavelan_set_roam(struct net_device *dev,
  2165. struct iw_request_info *info,
  2166. union iwreq_data *wrqu,
  2167. char *extra)
  2168. {
  2169. net_local *lp = netdev_priv(dev);
  2170. unsigned long flags;
  2171. /* Disable interrupts and save flags. */
  2172. spin_lock_irqsave(&lp->spinlock, flags);
  2173. /* Note : should check if user == root */
  2174. if(do_roaming && (*extra)==0)
  2175. wv_roam_cleanup(dev);
  2176. else if(do_roaming==0 && (*extra)!=0)
  2177. wv_roam_init(dev);
  2178. do_roaming = (*extra);
  2179. /* Enable interrupts and restore flags. */
  2180. spin_unlock_irqrestore(&lp->spinlock, flags);
  2181. return 0;
  2182. }
  2183. /*------------------------------------------------------------------*/
  2184. /*
  2185. * Wireless Private Handler : get quality threshold
  2186. */
  2187. static int wavelan_get_roam(struct net_device *dev,
  2188. struct iw_request_info *info,
  2189. union iwreq_data *wrqu,
  2190. char *extra)
  2191. {
  2192. *(extra) = do_roaming;
  2193. return 0;
  2194. }
  2195. #endif /* WAVELAN_ROAMING */
  2196. #ifdef HISTOGRAM
  2197. /*------------------------------------------------------------------*/
  2198. /*
  2199. * Wireless Private Handler : set histogram
  2200. */
  2201. static int wavelan_set_histo(struct net_device *dev,
  2202. struct iw_request_info *info,
  2203. union iwreq_data *wrqu,
  2204. char *extra)
  2205. {
  2206. net_local *lp = netdev_priv(dev);
  2207. /* Check the number of intervals. */
  2208. if (wrqu->data.length > 16) {
  2209. return(-E2BIG);
  2210. }
  2211. /* Disable histo while we copy the addresses.
  2212. * As we don't disable interrupts, we need to do this */
  2213. lp->his_number = 0;
  2214. /* Are there ranges to copy? */
  2215. if (wrqu->data.length > 0) {
  2216. /* Copy interval ranges to the driver */
  2217. memcpy(lp->his_range, extra, wrqu->data.length);
  2218. {
  2219. int i;
  2220. printk(KERN_DEBUG "Histo :");
  2221. for(i = 0; i < wrqu->data.length; i++)
  2222. printk(" %d", lp->his_range[i]);
  2223. printk("\n");
  2224. }
  2225. /* Reset result structure. */
  2226. memset(lp->his_sum, 0x00, sizeof(long) * 16);
  2227. }
  2228. /* Now we can set the number of ranges */
  2229. lp->his_number = wrqu->data.length;
  2230. return(0);
  2231. }
  2232. /*------------------------------------------------------------------*/
  2233. /*
  2234. * Wireless Private Handler : get histogram
  2235. */
  2236. static int wavelan_get_histo(struct net_device *dev,
  2237. struct iw_request_info *info,
  2238. union iwreq_data *wrqu,
  2239. char *extra)
  2240. {
  2241. net_local *lp = netdev_priv(dev);
  2242. /* Set the number of intervals. */
  2243. wrqu->data.length = lp->his_number;
  2244. /* Give back the distribution statistics */
  2245. if(lp->his_number > 0)
  2246. memcpy(extra, lp->his_sum, sizeof(long) * lp->his_number);
  2247. return(0);
  2248. }
  2249. #endif /* HISTOGRAM */
  2250. /*------------------------------------------------------------------*/
  2251. /*
  2252. * Structures to export the Wireless Handlers
  2253. */
  2254. static const struct iw_priv_args wavelan_private_args[] = {
  2255. /*{ cmd, set_args, get_args, name } */
  2256. { SIOCSIPQTHR, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setqualthr" },
  2257. { SIOCGIPQTHR, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getqualthr" },
  2258. { SIOCSIPROAM, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setroam" },
  2259. { SIOCGIPROAM, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getroam" },
  2260. { SIOCSIPHISTO, IW_PRIV_TYPE_BYTE | 16, 0, "sethisto" },
  2261. { SIOCGIPHISTO, 0, IW_PRIV_TYPE_INT | 16, "gethisto" },
  2262. };
  2263. static const iw_handler wavelan_handler[] =
  2264. {
  2265. NULL, /* SIOCSIWNAME */
  2266. wavelan_get_name, /* SIOCGIWNAME */
  2267. wavelan_set_nwid, /* SIOCSIWNWID */
  2268. wavelan_get_nwid, /* SIOCGIWNWID */
  2269. wavelan_set_freq, /* SIOCSIWFREQ */
  2270. wavelan_get_freq, /* SIOCGIWFREQ */
  2271. #ifdef WAVELAN_ROAMING
  2272. wavelan_set_mode, /* SIOCSIWMODE */
  2273. wavelan_get_mode, /* SIOCGIWMODE */
  2274. #else /* WAVELAN_ROAMING */
  2275. NULL, /* SIOCSIWMODE */
  2276. NULL, /* SIOCGIWMODE */
  2277. #endif /* WAVELAN_ROAMING */
  2278. wavelan_set_sens, /* SIOCSIWSENS */
  2279. wavelan_get_sens, /* SIOCGIWSENS */
  2280. NULL, /* SIOCSIWRANGE */
  2281. wavelan_get_range, /* SIOCGIWRANGE */
  2282. NULL, /* SIOCSIWPRIV */
  2283. NULL, /* SIOCGIWPRIV */
  2284. NULL, /* SIOCSIWSTATS */
  2285. NULL, /* SIOCGIWSTATS */
  2286. iw_handler_set_spy, /* SIOCSIWSPY */
  2287. iw_handler_get_spy, /* SIOCGIWSPY */
  2288. iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
  2289. iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
  2290. #ifdef WAVELAN_ROAMING_EXT
  2291. wavelan_set_wap, /* SIOCSIWAP */
  2292. wavelan_get_wap, /* SIOCGIWAP */
  2293. NULL, /* -- hole -- */
  2294. NULL, /* SIOCGIWAPLIST */
  2295. NULL, /* -- hole -- */
  2296. NULL, /* -- hole -- */
  2297. wavelan_set_essid, /* SIOCSIWESSID */
  2298. wavelan_get_essid, /* SIOCGIWESSID */
  2299. #else /* WAVELAN_ROAMING_EXT */
  2300. NULL, /* SIOCSIWAP */
  2301. NULL, /* SIOCGIWAP */
  2302. NULL, /* -- hole -- */
  2303. NULL, /* SIOCGIWAPLIST */
  2304. NULL, /* -- hole -- */
  2305. NULL, /* -- hole -- */
  2306. NULL, /* SIOCSIWESSID */
  2307. NULL, /* SIOCGIWESSID */
  2308. #endif /* WAVELAN_ROAMING_EXT */
  2309. NULL, /* SIOCSIWNICKN */
  2310. NULL, /* SIOCGIWNICKN */
  2311. NULL, /* -- hole -- */
  2312. NULL, /* -- hole -- */
  2313. NULL, /* SIOCSIWRATE */
  2314. NULL, /* SIOCGIWRATE */
  2315. NULL, /* SIOCSIWRTS */
  2316. NULL, /* SIOCGIWRTS */
  2317. NULL, /* SIOCSIWFRAG */
  2318. NULL, /* SIOCGIWFRAG */
  2319. NULL, /* SIOCSIWTXPOW */
  2320. NULL, /* SIOCGIWTXPOW */
  2321. NULL, /* SIOCSIWRETRY */
  2322. NULL, /* SIOCGIWRETRY */
  2323. wavelan_set_encode, /* SIOCSIWENCODE */
  2324. wavelan_get_encode, /* SIOCGIWENCODE */
  2325. };
  2326. static const iw_handler wavelan_private_handler[] =
  2327. {
  2328. wavelan_set_qthr, /* SIOCIWFIRSTPRIV */
  2329. wavelan_get_qthr, /* SIOCIWFIRSTPRIV + 1 */
  2330. #ifdef WAVELAN_ROAMING
  2331. wavelan_set_roam, /* SIOCIWFIRSTPRIV + 2 */
  2332. wavelan_get_roam, /* SIOCIWFIRSTPRIV + 3 */
  2333. #else /* WAVELAN_ROAMING */
  2334. NULL, /* SIOCIWFIRSTPRIV + 2 */
  2335. NULL, /* SIOCIWFIRSTPRIV + 3 */
  2336. #endif /* WAVELAN_ROAMING */
  2337. #ifdef HISTOGRAM
  2338. wavelan_set_histo, /* SIOCIWFIRSTPRIV + 4 */
  2339. wavelan_get_histo, /* SIOCIWFIRSTPRIV + 5 */
  2340. #endif /* HISTOGRAM */
  2341. };
  2342. static const struct iw_handler_def wavelan_handler_def =
  2343. {
  2344. .num_standard = sizeof(wavelan_handler)/sizeof(iw_handler),
  2345. .num_private = sizeof(wavelan_private_handler)/sizeof(iw_handler),
  2346. .num_private_args = sizeof(wavelan_private_args)/sizeof(struct iw_priv_args),
  2347. .standard = wavelan_handler,
  2348. .private = wavelan_private_handler,
  2349. .private_args = wavelan_private_args,
  2350. .get_wireless_stats = wavelan_get_wireless_stats,
  2351. };
  2352. /*------------------------------------------------------------------*/
  2353. /*
  2354. * Get wireless statistics
  2355. * Called by /proc/net/wireless...
  2356. */
  2357. static iw_stats *
  2358. wavelan_get_wireless_stats(struct net_device * dev)
  2359. {
  2360. kio_addr_t base = dev->base_addr;
  2361. net_local * lp = netdev_priv(dev);
  2362. mmr_t m;
  2363. iw_stats * wstats;
  2364. unsigned long flags;
  2365. #ifdef DEBUG_IOCTL_TRACE
  2366. printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()\n", dev->name);
  2367. #endif
  2368. /* Disable interrupts & save flags */
  2369. spin_lock_irqsave(&lp->spinlock, flags);
  2370. wstats = &lp->wstats;
  2371. /* Get data from the mmc */
  2372. mmc_out(base, mmwoff(0, mmw_freeze), 1);
  2373. mmc_read(base, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1);
  2374. mmc_read(base, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l, 2);
  2375. mmc_read(base, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set, 4);
  2376. mmc_out(base, mmwoff(0, mmw_freeze), 0);
  2377. /* Copy data to wireless stuff */
  2378. wstats->status = m.mmr_dce_status & MMR_DCE_STATUS;
  2379. wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL;
  2380. wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL;
  2381. wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL;
  2382. wstats->qual.updated = (((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7) |
  2383. ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6) |
  2384. ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5));
  2385. wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
  2386. wstats->discard.code = 0L;
  2387. wstats->discard.misc = 0L;
  2388. /* ReEnable interrupts & restore flags */
  2389. spin_unlock_irqrestore(&lp->spinlock, flags);
  2390. #ifdef DEBUG_IOCTL_TRACE
  2391. printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()\n", dev->name);
  2392. #endif
  2393. return &lp->wstats;
  2394. }
  2395. /************************* PACKET RECEPTION *************************/
  2396. /*
  2397. * This part deal with receiving the packets.
  2398. * The interrupt handler get an interrupt when a packet has been
  2399. * successfully received and called this part...
  2400. */
  2401. /*------------------------------------------------------------------*/
  2402. /*
  2403. * Calculate the starting address of the frame pointed to by the receive
  2404. * frame pointer and verify that the frame seem correct
  2405. * (called by wv_packet_rcv())
  2406. */
  2407. static inline int
  2408. wv_start_of_frame(struct net_device * dev,
  2409. int rfp, /* end of frame */
  2410. int wrap) /* start of buffer */
  2411. {
  2412. kio_addr_t base = dev->base_addr;
  2413. int rp;
  2414. int len;
  2415. rp = (rfp - 5 + RX_SIZE) % RX_SIZE;
  2416. outb(rp & 0xff, PIORL(base));
  2417. outb(((rp >> 8) & PIORH_MASK), PIORH(base));
  2418. len = inb(PIOP(base));
  2419. len |= inb(PIOP(base)) << 8;
  2420. /* Sanity checks on size */
  2421. /* Frame too big */
  2422. if(len > MAXDATAZ + 100)
  2423. {
  2424. #ifdef DEBUG_RX_ERROR
  2425. printk(KERN_INFO "%s: wv_start_of_frame: Received frame too large, rfp %d len 0x%x\n",
  2426. dev->name, rfp, len);
  2427. #endif
  2428. return(-1);
  2429. }
  2430. /* Frame too short */
  2431. if(len < 7)
  2432. {
  2433. #ifdef DEBUG_RX_ERROR
  2434. printk(KERN_INFO "%s: wv_start_of_frame: Received null frame, rfp %d len 0x%x\n",
  2435. dev->name, rfp, len);
  2436. #endif
  2437. return(-1);
  2438. }
  2439. /* Wrap around buffer */
  2440. if(len > ((wrap - (rfp - len) + RX_SIZE) % RX_SIZE)) /* magic formula ! */
  2441. {
  2442. #ifdef DEBUG_RX_ERROR
  2443. printk(KERN_INFO "%s: wv_start_of_frame: wrap around buffer, wrap %d rfp %d len 0x%x\n",
  2444. dev->name, wrap, rfp, len);
  2445. #endif
  2446. return(-1);
  2447. }
  2448. return((rp - len + RX_SIZE) % RX_SIZE);
  2449. } /* wv_start_of_frame */
  2450. /*------------------------------------------------------------------*/
  2451. /*
  2452. * This routine does the actual copy of data (including the ethernet
  2453. * header structure) from the WaveLAN card to an sk_buff chain that
  2454. * will be passed up to the network interface layer. NOTE: We
  2455. * currently don't handle trailer protocols (neither does the rest of
  2456. * the network interface), so if that is needed, it will (at least in
  2457. * part) be added here. The contents of the receive ring buffer are
  2458. * copied to a message chain that is then passed to the kernel.
  2459. *
  2460. * Note: if any errors occur, the packet is "dropped on the floor"
  2461. * (called by wv_packet_rcv())
  2462. */
  2463. static inline void
  2464. wv_packet_read(struct net_device * dev,
  2465. int fd_p,
  2466. int sksize)
  2467. {
  2468. net_local * lp = netdev_priv(dev);
  2469. struct sk_buff * skb;
  2470. #ifdef DEBUG_RX_TRACE
  2471. printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)\n",
  2472. dev->name, fd_p, sksize);
  2473. #endif
  2474. /* Allocate some buffer for the new packet */
  2475. if((skb = dev_alloc_skb(sksize+2)) == (struct sk_buff *) NULL)
  2476. {
  2477. #ifdef DEBUG_RX_ERROR
  2478. printk(KERN_INFO "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC)\n",
  2479. dev->name, sksize);
  2480. #endif
  2481. lp->stats.rx_dropped++;
  2482. /*
  2483. * Not only do we want to return here, but we also need to drop the
  2484. * packet on the floor to clear the interrupt.
  2485. */
  2486. return;
  2487. }
  2488. skb->dev = dev;
  2489. skb_reserve(skb, 2);
  2490. fd_p = read_ringbuf(dev, fd_p, (char *) skb_put(skb, sksize), sksize);
  2491. skb->protocol = eth_type_trans(skb, dev);
  2492. #ifdef DEBUG_RX_INFO
  2493. wv_packet_info(skb->mac.raw, sksize, dev->name, "wv_packet_read");
  2494. #endif /* DEBUG_RX_INFO */
  2495. /* Statistics gathering & stuff associated.
  2496. * It seem a bit messy with all the define, but it's really simple... */
  2497. if(
  2498. #ifdef IW_WIRELESS_SPY
  2499. (lp->spy_data.spy_number > 0) ||
  2500. #endif /* IW_WIRELESS_SPY */
  2501. #ifdef HISTOGRAM
  2502. (lp->his_number > 0) ||
  2503. #endif /* HISTOGRAM */
  2504. #ifdef WAVELAN_ROAMING
  2505. (do_roaming) ||
  2506. #endif /* WAVELAN_ROAMING */
  2507. 0)
  2508. {
  2509. u_char stats[3]; /* Signal level, Noise level, Signal quality */
  2510. /* read signal level, silence level and signal quality bytes */
  2511. fd_p = read_ringbuf(dev, (fd_p + 4) % RX_SIZE + RX_BASE,
  2512. stats, 3);
  2513. #ifdef DEBUG_RX_INFO
  2514. printk(KERN_DEBUG "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n",
  2515. dev->name, stats[0] & 0x3F, stats[1] & 0x3F, stats[2] & 0x0F);
  2516. #endif
  2517. #ifdef WAVELAN_ROAMING
  2518. if(do_roaming)
  2519. if(WAVELAN_BEACON(skb->data))
  2520. wl_roam_gather(dev, skb->data, stats);
  2521. #endif /* WAVELAN_ROAMING */
  2522. #ifdef WIRELESS_SPY
  2523. wl_spy_gather(dev, skb->mac.raw + WAVELAN_ADDR_SIZE, stats);
  2524. #endif /* WIRELESS_SPY */
  2525. #ifdef HISTOGRAM
  2526. wl_his_gather(dev, stats);
  2527. #endif /* HISTOGRAM */
  2528. }
  2529. /*
  2530. * Hand the packet to the Network Module
  2531. */
  2532. netif_rx(skb);
  2533. /* Keep stats up to date */
  2534. dev->last_rx = jiffies;
  2535. lp->stats.rx_packets++;
  2536. lp->stats.rx_bytes += sksize;
  2537. #ifdef DEBUG_RX_TRACE
  2538. printk(KERN_DEBUG "%s: <-wv_packet_read()\n", dev->name);
  2539. #endif
  2540. return;
  2541. }
  2542. /*------------------------------------------------------------------*/
  2543. /*
  2544. * This routine is called by the interrupt handler to initiate a
  2545. * packet transfer from the card to the network interface layer above
  2546. * this driver. This routine checks if a buffer has been successfully
  2547. * received by the WaveLAN card. If so, the routine wv_packet_read is
  2548. * called to do the actual transfer of the card's data including the
  2549. * ethernet header into a packet consisting of an sk_buff chain.
  2550. * (called by wavelan_interrupt())
  2551. * Note : the spinlock is already grabbed for us and irq are disabled.
  2552. */
  2553. static inline void
  2554. wv_packet_rcv(struct net_device * dev)
  2555. {
  2556. kio_addr_t base = dev->base_addr;
  2557. net_local * lp = netdev_priv(dev);
  2558. int newrfp;
  2559. int rp;
  2560. int len;
  2561. int f_start;
  2562. int status;
  2563. int i593_rfp;
  2564. int stat_ptr;
  2565. u_char c[4];
  2566. #ifdef DEBUG_RX_TRACE
  2567. printk(KERN_DEBUG "%s: ->wv_packet_rcv()\n", dev->name);
  2568. #endif
  2569. /* Get the new receive frame pointer from the i82593 chip */
  2570. outb(CR0_STATUS_2 | OP0_NOP, LCCR(base));
  2571. i593_rfp = inb(LCSR(base));
  2572. i593_rfp |= inb(LCSR(base)) << 8;
  2573. i593_rfp %= RX_SIZE;
  2574. /* Get the new receive frame pointer from the WaveLAN card.
  2575. * It is 3 bytes more than the increment of the i82593 receive
  2576. * frame pointer, for each packet. This is because it includes the
  2577. * 3 roaming bytes added by the mmc.
  2578. */
  2579. newrfp = inb(RPLL(base));
  2580. newrfp |= inb(RPLH(base)) << 8;
  2581. newrfp %= RX_SIZE;
  2582. #ifdef DEBUG_RX_INFO
  2583. printk(KERN_DEBUG "%s: wv_packet_rcv(): i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
  2584. dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
  2585. #endif
  2586. #ifdef DEBUG_RX_ERROR
  2587. /* If no new frame pointer... */
  2588. if(lp->overrunning || newrfp == lp->rfp)
  2589. printk(KERN_INFO "%s: wv_packet_rcv(): no new frame: i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
  2590. dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
  2591. #endif
  2592. /* Read all frames (packets) received */
  2593. while(newrfp != lp->rfp)
  2594. {
  2595. /* A frame is composed of the packet, followed by a status word,
  2596. * the length of the frame (word) and the mmc info (SNR & qual).
  2597. * It's because the length is at the end that we can only scan
  2598. * frames backward. */
  2599. /* Find the first frame by skipping backwards over the frames */
  2600. rp = newrfp; /* End of last frame */
  2601. while(((f_start = wv_start_of_frame(dev, rp, newrfp)) != lp->rfp) &&
  2602. (f_start != -1))
  2603. rp = f_start;
  2604. /* If we had a problem */
  2605. if(f_start == -1)
  2606. {
  2607. #ifdef DEBUG_RX_ERROR
  2608. printk(KERN_INFO "wavelan_cs: cannot find start of frame ");
  2609. printk(" i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
  2610. i593_rfp, lp->stop, newrfp, lp->rfp);
  2611. #endif
  2612. lp->rfp = rp; /* Get to the last usable frame */
  2613. continue;
  2614. }
  2615. /* f_start point to the beggining of the first frame received
  2616. * and rp to the beggining of the next one */
  2617. /* Read status & length of the frame */
  2618. stat_ptr = (rp - 7 + RX_SIZE) % RX_SIZE;
  2619. stat_ptr = read_ringbuf(dev, stat_ptr, c, 4);
  2620. status = c[0] | (c[1] << 8);
  2621. len = c[2] | (c[3] << 8);
  2622. /* Check status */
  2623. if((status & RX_RCV_OK) != RX_RCV_OK)
  2624. {
  2625. lp->stats.rx_errors++;
  2626. if(status & RX_NO_SFD)
  2627. lp->stats.rx_frame_errors++;
  2628. if(status & RX_CRC_ERR)
  2629. lp->stats.rx_crc_errors++;
  2630. if(status & RX_OVRRUN)
  2631. lp->stats.rx_over_errors++;
  2632. #ifdef DEBUG_RX_FAIL
  2633. printk(KERN_DEBUG "%s: wv_packet_rcv(): packet not received ok, status = 0x%x\n",
  2634. dev->name, status);
  2635. #endif
  2636. }
  2637. else
  2638. /* Read the packet and transmit to Linux */
  2639. wv_packet_read(dev, f_start, len - 2);
  2640. /* One frame has been processed, skip it */
  2641. lp->rfp = rp;
  2642. }
  2643. /*
  2644. * Update the frame stop register, but set it to less than
  2645. * the full 8K to allow space for 3 bytes of signal strength
  2646. * per packet.
  2647. */
  2648. lp->stop = (i593_rfp + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
  2649. outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
  2650. outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
  2651. outb(OP1_SWIT_TO_PORT_0, LCCR(base));
  2652. #ifdef DEBUG_RX_TRACE
  2653. printk(KERN_DEBUG "%s: <-wv_packet_rcv()\n", dev->name);
  2654. #endif
  2655. }
  2656. /*********************** PACKET TRANSMISSION ***********************/
  2657. /*
  2658. * This part deal with sending packet through the wavelan
  2659. * We copy the packet to the send buffer and then issue the send
  2660. * command to the i82593. The result of this operation will be
  2661. * checked in wavelan_interrupt()
  2662. */
  2663. /*------------------------------------------------------------------*/
  2664. /*
  2665. * This routine fills in the appropriate registers and memory
  2666. * locations on the WaveLAN card and starts the card off on
  2667. * the transmit.
  2668. * (called in wavelan_packet_xmit())
  2669. */
  2670. static inline void
  2671. wv_packet_write(struct net_device * dev,
  2672. void * buf,
  2673. short length)
  2674. {
  2675. net_local * lp = netdev_priv(dev);
  2676. kio_addr_t base = dev->base_addr;
  2677. unsigned long flags;
  2678. int clen = length;
  2679. register u_short xmtdata_base = TX_BASE;
  2680. #ifdef DEBUG_TX_TRACE
  2681. printk(KERN_DEBUG "%s: ->wv_packet_write(%d)\n", dev->name, length);
  2682. #endif
  2683. spin_lock_irqsave(&lp->spinlock, flags);
  2684. /* Write the length of data buffer followed by the buffer */
  2685. outb(xmtdata_base & 0xff, PIORL(base));
  2686. outb(((xmtdata_base >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
  2687. outb(clen & 0xff, PIOP(base)); /* lsb */
  2688. outb(clen >> 8, PIOP(base)); /* msb */
  2689. /* Send the data */
  2690. outsb(PIOP(base), buf, clen);
  2691. /* Indicate end of transmit chain */
  2692. outb(OP0_NOP, PIOP(base));
  2693. /* josullvn@cs.cmu.edu: need to send a second NOP for alignment... */
  2694. outb(OP0_NOP, PIOP(base));
  2695. /* Reset the transmit DMA pointer */
  2696. hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  2697. hacr_write(base, HACR_DEFAULT);
  2698. /* Send the transmit command */
  2699. wv_82593_cmd(dev, "wv_packet_write(): transmit",
  2700. OP0_TRANSMIT, SR0_NO_RESULT);
  2701. /* Make sure the watchdog will keep quiet for a while */
  2702. dev->trans_start = jiffies;
  2703. /* Keep stats up to date */
  2704. lp->stats.tx_bytes += length;
  2705. spin_unlock_irqrestore(&lp->spinlock, flags);
  2706. #ifdef DEBUG_TX_INFO
  2707. wv_packet_info((u_char *) buf, length, dev->name, "wv_packet_write");
  2708. #endif /* DEBUG_TX_INFO */
  2709. #ifdef DEBUG_TX_TRACE
  2710. printk(KERN_DEBUG "%s: <-wv_packet_write()\n", dev->name);
  2711. #endif
  2712. }
  2713. /*------------------------------------------------------------------*/
  2714. /*
  2715. * This routine is called when we want to send a packet (NET3 callback)
  2716. * In this routine, we check if the harware is ready to accept
  2717. * the packet. We also prevent reentrance. Then, we call the function
  2718. * to send the packet...
  2719. */
  2720. static int
  2721. wavelan_packet_xmit(struct sk_buff * skb,
  2722. struct net_device * dev)
  2723. {
  2724. net_local * lp = netdev_priv(dev);
  2725. unsigned long flags;
  2726. #ifdef DEBUG_TX_TRACE
  2727. printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)\n", dev->name,
  2728. (unsigned) skb);
  2729. #endif
  2730. /*
  2731. * Block a timer-based transmit from overlapping a previous transmit.
  2732. * In other words, prevent reentering this routine.
  2733. */
  2734. netif_stop_queue(dev);
  2735. /* If somebody has asked to reconfigure the controller,
  2736. * we can do it now */
  2737. if(lp->reconfig_82593)
  2738. {
  2739. spin_lock_irqsave(&lp->spinlock, flags); /* Disable interrupts */
  2740. wv_82593_config(dev);
  2741. spin_unlock_irqrestore(&lp->spinlock, flags); /* Re-enable interrupts */
  2742. /* Note : the configure procedure was totally synchronous,
  2743. * so the Tx buffer is now free */
  2744. }
  2745. #ifdef DEBUG_TX_ERROR
  2746. if (skb->next)
  2747. printk(KERN_INFO "skb has next\n");
  2748. #endif
  2749. /* Check if we need some padding */
  2750. /* Note : on wireless the propagation time is in the order of 1us,
  2751. * and we don't have the Ethernet specific requirement of beeing
  2752. * able to detect collisions, therefore in theory we don't really
  2753. * need to pad. Jean II */
  2754. if (skb->len < ETH_ZLEN) {
  2755. skb = skb_padto(skb, ETH_ZLEN);
  2756. if (skb == NULL)
  2757. return 0;
  2758. }
  2759. wv_packet_write(dev, skb->data, skb->len);
  2760. dev_kfree_skb(skb);
  2761. #ifdef DEBUG_TX_TRACE
  2762. printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
  2763. #endif
  2764. return(0);
  2765. }
  2766. /********************** HARDWARE CONFIGURATION **********************/
  2767. /*
  2768. * This part do the real job of starting and configuring the hardware.
  2769. */
  2770. /*------------------------------------------------------------------*/
  2771. /*
  2772. * Routine to initialize the Modem Management Controller.
  2773. * (called by wv_hw_config())
  2774. */
  2775. static inline int
  2776. wv_mmc_init(struct net_device * dev)
  2777. {
  2778. kio_addr_t base = dev->base_addr;
  2779. psa_t psa;
  2780. mmw_t m;
  2781. int configured;
  2782. int i; /* Loop counter */
  2783. #ifdef DEBUG_CONFIG_TRACE
  2784. printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name);
  2785. #endif
  2786. /* Read the parameter storage area */
  2787. psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
  2788. /*
  2789. * Check the first three octets of the MAC addr for the manufacturer's code.
  2790. * Note: If you get the error message below, you've got a
  2791. * non-NCR/AT&T/Lucent PCMCIA cards, see wavelan_cs.h for detail on
  2792. * how to configure your card...
  2793. */
  2794. for(i = 0; i < (sizeof(MAC_ADDRESSES) / sizeof(char) / 3); i++)
  2795. if((psa.psa_univ_mac_addr[0] == MAC_ADDRESSES[i][0]) &&
  2796. (psa.psa_univ_mac_addr[1] == MAC_ADDRESSES[i][1]) &&
  2797. (psa.psa_univ_mac_addr[2] == MAC_ADDRESSES[i][2]))
  2798. break;
  2799. /* If we have not found it... */
  2800. if(i == (sizeof(MAC_ADDRESSES) / sizeof(char) / 3))
  2801. {
  2802. #ifdef DEBUG_CONFIG_ERRORS
  2803. printk(KERN_WARNING "%s: wv_mmc_init(): Invalid MAC address: %02X:%02X:%02X:...\n",
  2804. dev->name, psa.psa_univ_mac_addr[0],
  2805. psa.psa_univ_mac_addr[1], psa.psa_univ_mac_addr[2]);
  2806. #endif
  2807. return FALSE;
  2808. }
  2809. /* Get the MAC address */
  2810. memcpy(&dev->dev_addr[0], &psa.psa_univ_mac_addr[0], WAVELAN_ADDR_SIZE);
  2811. #ifdef USE_PSA_CONFIG
  2812. configured = psa.psa_conf_status & 1;
  2813. #else
  2814. configured = 0;
  2815. #endif
  2816. /* Is the PSA is not configured */
  2817. if(!configured)
  2818. {
  2819. /* User will be able to configure NWID after (with iwconfig) */
  2820. psa.psa_nwid[0] = 0;
  2821. psa.psa_nwid[1] = 0;
  2822. /* As NWID is not set : no NWID checking */
  2823. psa.psa_nwid_select = 0;
  2824. /* Disable encryption */
  2825. psa.psa_encryption_select = 0;
  2826. /* Set to standard values
  2827. * 0x04 for AT,
  2828. * 0x01 for MCA,
  2829. * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
  2830. */
  2831. if (psa.psa_comp_number & 1)
  2832. psa.psa_thr_pre_set = 0x01;
  2833. else
  2834. psa.psa_thr_pre_set = 0x04;
  2835. psa.psa_quality_thr = 0x03;
  2836. /* It is configured */
  2837. psa.psa_conf_status |= 1;
  2838. #ifdef USE_PSA_CONFIG
  2839. /* Write the psa */
  2840. psa_write(dev, (char *)psa.psa_nwid - (char *)&psa,
  2841. (unsigned char *)psa.psa_nwid, 4);
  2842. psa_write(dev, (char *)&psa.psa_thr_pre_set - (char *)&psa,
  2843. (unsigned char *)&psa.psa_thr_pre_set, 1);
  2844. psa_write(dev, (char *)&psa.psa_quality_thr - (char *)&psa,
  2845. (unsigned char *)&psa.psa_quality_thr, 1);
  2846. psa_write(dev, (char *)&psa.psa_conf_status - (char *)&psa,
  2847. (unsigned char *)&psa.psa_conf_status, 1);
  2848. /* update the Wavelan checksum */
  2849. update_psa_checksum(dev);
  2850. #endif /* USE_PSA_CONFIG */
  2851. }
  2852. /* Zero the mmc structure */
  2853. memset(&m, 0x00, sizeof(m));
  2854. /* Copy PSA info to the mmc */
  2855. m.mmw_netw_id_l = psa.psa_nwid[1];
  2856. m.mmw_netw_id_h = psa.psa_nwid[0];
  2857. if(psa.psa_nwid_select & 1)
  2858. m.mmw_loopt_sel = 0x00;
  2859. else
  2860. m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
  2861. memcpy(&m.mmw_encr_key, &psa.psa_encryption_key,
  2862. sizeof(m.mmw_encr_key));
  2863. if(psa.psa_encryption_select)
  2864. m.mmw_encr_enable = MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
  2865. else
  2866. m.mmw_encr_enable = 0;
  2867. m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
  2868. m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
  2869. /*
  2870. * Set default modem control parameters.
  2871. * See NCR document 407-0024326 Rev. A.
  2872. */
  2873. m.mmw_jabber_enable = 0x01;
  2874. m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
  2875. m.mmw_ifs = 0x20;
  2876. m.mmw_mod_delay = 0x04;
  2877. m.mmw_jam_time = 0x38;
  2878. m.mmw_des_io_invert = 0;
  2879. m.mmw_freeze = 0;
  2880. m.mmw_decay_prm = 0;
  2881. m.mmw_decay_updat_prm = 0;
  2882. /* Write all info to mmc */
  2883. mmc_write(base, 0, (u_char *)&m, sizeof(m));
  2884. /* The following code start the modem of the 2.00 frequency
  2885. * selectable cards at power on. It's not strictly needed for the
  2886. * following boots...
  2887. * The original patch was by Joe Finney for the PCMCIA driver, but
  2888. * I've cleaned it a bit and add documentation.
  2889. * Thanks to Loeke Brederveld from Lucent for the info.
  2890. */
  2891. /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
  2892. * (does it work for everybody ? - especially old cards...) */
  2893. /* Note : WFREQSEL verify that it is able to read from EEprom
  2894. * a sensible frequency (address 0x00) + that MMR_FEE_STATUS_ID
  2895. * is 0xA (Xilinx version) or 0xB (Ariadne version).
  2896. * My test is more crude but do work... */
  2897. if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
  2898. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
  2899. {
  2900. /* We must download the frequency parameters to the
  2901. * synthetisers (from the EEprom - area 1)
  2902. * Note : as the EEprom is auto decremented, we set the end
  2903. * if the area... */
  2904. m.mmw_fee_addr = 0x0F;
  2905. m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
  2906. mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
  2907. (unsigned char *)&m.mmw_fee_ctrl, 2);
  2908. /* Wait until the download is finished */
  2909. fee_wait(base, 100, 100);
  2910. #ifdef DEBUG_CONFIG_INFO
  2911. /* The frequency was in the last word downloaded... */
  2912. mmc_read(base, (char *)&m.mmw_fee_data_l - (char *)&m,
  2913. (unsigned char *)&m.mmw_fee_data_l, 2);
  2914. /* Print some info for the user */
  2915. printk(KERN_DEBUG "%s: Wavelan 2.00 recognised (frequency select) : Current frequency = %ld\n",
  2916. dev->name,
  2917. ((m.mmw_fee_data_h << 4) |
  2918. (m.mmw_fee_data_l >> 4)) * 5 / 2 + 24000L);
  2919. #endif
  2920. /* We must now download the power adjust value (gain) to
  2921. * the synthetisers (from the EEprom - area 7 - DAC) */
  2922. m.mmw_fee_addr = 0x61;
  2923. m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
  2924. mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
  2925. (unsigned char *)&m.mmw_fee_ctrl, 2);
  2926. /* Wait until the download is finished */
  2927. } /* if 2.00 card */
  2928. #ifdef DEBUG_CONFIG_TRACE
  2929. printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name);
  2930. #endif
  2931. return TRUE;
  2932. }
  2933. /*------------------------------------------------------------------*/
  2934. /*
  2935. * Routine to gracefully turn off reception, and wait for any commands
  2936. * to complete.
  2937. * (called in wv_ru_start() and wavelan_close() and wavelan_event())
  2938. */
  2939. static int
  2940. wv_ru_stop(struct net_device * dev)
  2941. {
  2942. kio_addr_t base = dev->base_addr;
  2943. net_local * lp = netdev_priv(dev);
  2944. unsigned long flags;
  2945. int status;
  2946. int spin;
  2947. #ifdef DEBUG_CONFIG_TRACE
  2948. printk(KERN_DEBUG "%s: ->wv_ru_stop()\n", dev->name);
  2949. #endif
  2950. spin_lock_irqsave(&lp->spinlock, flags);
  2951. /* First, send the LAN controller a stop receive command */
  2952. wv_82593_cmd(dev, "wv_graceful_shutdown(): stop-rcv",
  2953. OP0_STOP_RCV, SR0_NO_RESULT);
  2954. /* Then, spin until the receive unit goes idle */
  2955. spin = 300;
  2956. do
  2957. {
  2958. udelay(10);
  2959. outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
  2960. status = inb(LCSR(base));
  2961. }
  2962. while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_IDLE) && (spin-- > 0));
  2963. /* Now, spin until the chip finishes executing its current command */
  2964. do
  2965. {
  2966. udelay(10);
  2967. outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
  2968. status = inb(LCSR(base));
  2969. }
  2970. while(((status & SR3_EXEC_STATE_MASK) != SR3_EXEC_IDLE) && (spin-- > 0));
  2971. spin_unlock_irqrestore(&lp->spinlock, flags);
  2972. /* If there was a problem */
  2973. if(spin <= 0)
  2974. {
  2975. #ifdef DEBUG_CONFIG_ERRORS
  2976. printk(KERN_INFO "%s: wv_ru_stop(): The chip doesn't want to stop...\n",
  2977. dev->name);
  2978. #endif
  2979. return FALSE;
  2980. }
  2981. #ifdef DEBUG_CONFIG_TRACE
  2982. printk(KERN_DEBUG "%s: <-wv_ru_stop()\n", dev->name);
  2983. #endif
  2984. return TRUE;
  2985. } /* wv_ru_stop */
  2986. /*------------------------------------------------------------------*/
  2987. /*
  2988. * This routine starts the receive unit running. First, it checks if
  2989. * the card is actually ready. Then the card is instructed to receive
  2990. * packets again.
  2991. * (called in wv_hw_reset() & wavelan_open())
  2992. */
  2993. static int
  2994. wv_ru_start(struct net_device * dev)
  2995. {
  2996. kio_addr_t base = dev->base_addr;
  2997. net_local * lp = netdev_priv(dev);
  2998. unsigned long flags;
  2999. #ifdef DEBUG_CONFIG_TRACE
  3000. printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name);
  3001. #endif
  3002. /*
  3003. * We need to start from a quiescent state. To do so, we could check
  3004. * if the card is already running, but instead we just try to shut
  3005. * it down. First, we disable reception (in case it was already enabled).
  3006. */
  3007. if(!wv_ru_stop(dev))
  3008. return FALSE;
  3009. spin_lock_irqsave(&lp->spinlock, flags);
  3010. /* Now we know that no command is being executed. */
  3011. /* Set the receive frame pointer and stop pointer */
  3012. lp->rfp = 0;
  3013. outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
  3014. /* Reset ring management. This sets the receive frame pointer to 1 */
  3015. outb(OP1_RESET_RING_MNGMT, LCCR(base));
  3016. #if 0
  3017. /* XXX the i82593 manual page 6-4 seems to indicate that the stop register
  3018. should be set as below */
  3019. /* outb(CR1_STOP_REG_UPDATE|((RX_SIZE - 0x40)>> RX_SIZE_SHIFT),LCCR(base));*/
  3020. #elif 0
  3021. /* but I set it 0 instead */
  3022. lp->stop = 0;
  3023. #else
  3024. /* but I set it to 3 bytes per packet less than 8K */
  3025. lp->stop = (0 + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
  3026. #endif
  3027. outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
  3028. outb(OP1_INT_ENABLE, LCCR(base));
  3029. outb(OP1_SWIT_TO_PORT_0, LCCR(base));
  3030. /* Reset receive DMA pointer */
  3031. hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  3032. hacr_write_slow(base, HACR_DEFAULT);
  3033. /* Receive DMA on channel 1 */
  3034. wv_82593_cmd(dev, "wv_ru_start(): rcv-enable",
  3035. CR0_CHNL | OP0_RCV_ENABLE, SR0_NO_RESULT);
  3036. #ifdef DEBUG_I82593_SHOW
  3037. {
  3038. int status;
  3039. int opri;
  3040. int spin = 10000;
  3041. /* spin until the chip starts receiving */
  3042. do
  3043. {
  3044. outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
  3045. status = inb(LCSR(base));
  3046. if(spin-- <= 0)
  3047. break;
  3048. }
  3049. while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_ACTIVE) &&
  3050. ((status & SR3_RCV_STATE_MASK) != SR3_RCV_READY));
  3051. printk(KERN_DEBUG "rcv status is 0x%x [i:%d]\n",
  3052. (status & SR3_RCV_STATE_MASK), i);
  3053. }
  3054. #endif
  3055. spin_unlock_irqrestore(&lp->spinlock, flags);
  3056. #ifdef DEBUG_CONFIG_TRACE
  3057. printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name);
  3058. #endif
  3059. return TRUE;
  3060. }
  3061. /*------------------------------------------------------------------*/
  3062. /*
  3063. * This routine does a standard config of the WaveLAN controller (i82593).
  3064. * In the ISA driver, this is integrated in wavelan_hardware_reset()
  3065. * (called by wv_hw_config(), wv_82593_reconfig() & wavelan_packet_xmit())
  3066. */
  3067. static int
  3068. wv_82593_config(struct net_device * dev)
  3069. {
  3070. kio_addr_t base = dev->base_addr;
  3071. net_local * lp = netdev_priv(dev);
  3072. struct i82593_conf_block cfblk;
  3073. int ret = TRUE;
  3074. #ifdef DEBUG_CONFIG_TRACE
  3075. printk(KERN_DEBUG "%s: ->wv_82593_config()\n", dev->name);
  3076. #endif
  3077. /* Create & fill i82593 config block
  3078. *
  3079. * Now conform to Wavelan document WCIN085B
  3080. */
  3081. memset(&cfblk, 0x00, sizeof(struct i82593_conf_block));
  3082. cfblk.d6mod = FALSE; /* Run in i82593 advanced mode */
  3083. cfblk.fifo_limit = 5; /* = 56 B rx and 40 B tx fifo thresholds */
  3084. cfblk.forgnesi = FALSE; /* 0=82C501, 1=AMD7992B compatibility */
  3085. cfblk.fifo_32 = 1;
  3086. cfblk.throttle_enb = FALSE;
  3087. cfblk.contin = TRUE; /* enable continuous mode */
  3088. cfblk.cntrxint = FALSE; /* enable continuous mode receive interrupts */
  3089. cfblk.addr_len = WAVELAN_ADDR_SIZE;
  3090. cfblk.acloc = TRUE; /* Disable source addr insertion by i82593 */
  3091. cfblk.preamb_len = 0; /* 2 bytes preamble (SFD) */
  3092. cfblk.loopback = FALSE;
  3093. cfblk.lin_prio = 0; /* conform to 802.3 backoff algoritm */
  3094. cfblk.exp_prio = 5; /* conform to 802.3 backoff algoritm */
  3095. cfblk.bof_met = 1; /* conform to 802.3 backoff algoritm */
  3096. cfblk.ifrm_spc = 0x20 >> 4; /* 32 bit times interframe spacing */
  3097. cfblk.slottim_low = 0x20 >> 5; /* 32 bit times slot time */
  3098. cfblk.slottim_hi = 0x0;
  3099. cfblk.max_retr = 15;
  3100. cfblk.prmisc = ((lp->promiscuous) ? TRUE: FALSE); /* Promiscuous mode */
  3101. cfblk.bc_dis = FALSE; /* Enable broadcast reception */
  3102. cfblk.crs_1 = TRUE; /* Transmit without carrier sense */
  3103. cfblk.nocrc_ins = FALSE; /* i82593 generates CRC */
  3104. cfblk.crc_1632 = FALSE; /* 32-bit Autodin-II CRC */
  3105. cfblk.crs_cdt = FALSE; /* CD not to be interpreted as CS */
  3106. cfblk.cs_filter = 0; /* CS is recognized immediately */
  3107. cfblk.crs_src = FALSE; /* External carrier sense */
  3108. cfblk.cd_filter = 0; /* CD is recognized immediately */
  3109. cfblk.min_fr_len = ETH_ZLEN >> 2; /* Minimum frame length 64 bytes */
  3110. cfblk.lng_typ = FALSE; /* Length field > 1500 = type field */
  3111. cfblk.lng_fld = TRUE; /* Disable 802.3 length field check */
  3112. cfblk.rxcrc_xf = TRUE; /* Don't transfer CRC to memory */
  3113. cfblk.artx = TRUE; /* Disable automatic retransmission */
  3114. cfblk.sarec = TRUE; /* Disable source addr trig of CD */
  3115. cfblk.tx_jabber = TRUE; /* Disable jabber jam sequence */
  3116. cfblk.hash_1 = FALSE; /* Use bits 0-5 in mc address hash */
  3117. cfblk.lbpkpol = TRUE; /* Loopback pin active high */
  3118. cfblk.fdx = FALSE; /* Disable full duplex operation */
  3119. cfblk.dummy_6 = 0x3f; /* all ones */
  3120. cfblk.mult_ia = FALSE; /* No multiple individual addresses */
  3121. cfblk.dis_bof = FALSE; /* Disable the backoff algorithm ?! */
  3122. cfblk.dummy_1 = TRUE; /* set to 1 */
  3123. cfblk.tx_ifs_retrig = 3; /* Hmm... Disabled */
  3124. #ifdef MULTICAST_ALL
  3125. cfblk.mc_all = (lp->allmulticast ? TRUE: FALSE); /* Allow all multicasts */
  3126. #else
  3127. cfblk.mc_all = FALSE; /* No multicast all mode */
  3128. #endif
  3129. cfblk.rcv_mon = 0; /* Monitor mode disabled */
  3130. cfblk.frag_acpt = TRUE; /* Do not accept fragments */
  3131. cfblk.tstrttrs = FALSE; /* No start transmission threshold */
  3132. cfblk.fretx = TRUE; /* FIFO automatic retransmission */
  3133. cfblk.syncrqs = FALSE; /* Synchronous DRQ deassertion... */
  3134. cfblk.sttlen = TRUE; /* 6 byte status registers */
  3135. cfblk.rx_eop = TRUE; /* Signal EOP on packet reception */
  3136. cfblk.tx_eop = TRUE; /* Signal EOP on packet transmission */
  3137. cfblk.rbuf_size = RX_SIZE>>11; /* Set receive buffer size */
  3138. cfblk.rcvstop = TRUE; /* Enable Receive Stop Register */
  3139. #ifdef DEBUG_I82593_SHOW
  3140. {
  3141. u_char *c = (u_char *) &cfblk;
  3142. int i;
  3143. printk(KERN_DEBUG "wavelan_cs: config block:");
  3144. for(i = 0; i < sizeof(struct i82593_conf_block); i++,c++)
  3145. {
  3146. if((i % 16) == 0) printk("\n" KERN_DEBUG);
  3147. printk("%02x ", *c);
  3148. }
  3149. printk("\n");
  3150. }
  3151. #endif
  3152. /* Copy the config block to the i82593 */
  3153. outb(TX_BASE & 0xff, PIORL(base));
  3154. outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
  3155. outb(sizeof(struct i82593_conf_block) & 0xff, PIOP(base)); /* lsb */
  3156. outb(sizeof(struct i82593_conf_block) >> 8, PIOP(base)); /* msb */
  3157. outsb(PIOP(base), (char *) &cfblk, sizeof(struct i82593_conf_block));
  3158. /* reset transmit DMA pointer */
  3159. hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  3160. hacr_write(base, HACR_DEFAULT);
  3161. if(!wv_82593_cmd(dev, "wv_82593_config(): configure",
  3162. OP0_CONFIGURE, SR0_CONFIGURE_DONE))
  3163. ret = FALSE;
  3164. /* Initialize adapter's ethernet MAC address */
  3165. outb(TX_BASE & 0xff, PIORL(base));
  3166. outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
  3167. outb(WAVELAN_ADDR_SIZE, PIOP(base)); /* byte count lsb */
  3168. outb(0, PIOP(base)); /* byte count msb */
  3169. outsb(PIOP(base), &dev->dev_addr[0], WAVELAN_ADDR_SIZE);
  3170. /* reset transmit DMA pointer */
  3171. hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  3172. hacr_write(base, HACR_DEFAULT);
  3173. if(!wv_82593_cmd(dev, "wv_82593_config(): ia-setup",
  3174. OP0_IA_SETUP, SR0_IA_SETUP_DONE))
  3175. ret = FALSE;
  3176. #ifdef WAVELAN_ROAMING
  3177. /* If roaming is enabled, join the "Beacon Request" multicast group... */
  3178. /* But only if it's not in there already! */
  3179. if(do_roaming)
  3180. dev_mc_add(dev,WAVELAN_BEACON_ADDRESS, WAVELAN_ADDR_SIZE, 1);
  3181. #endif /* WAVELAN_ROAMING */
  3182. /* If any multicast address to set */
  3183. if(lp->mc_count)
  3184. {
  3185. struct dev_mc_list * dmi;
  3186. int addrs_len = WAVELAN_ADDR_SIZE * lp->mc_count;
  3187. #ifdef DEBUG_CONFIG_INFO
  3188. printk(KERN_DEBUG "%s: wv_hw_config(): set %d multicast addresses:\n",
  3189. dev->name, lp->mc_count);
  3190. for(dmi=dev->mc_list; dmi; dmi=dmi->next)
  3191. printk(KERN_DEBUG " %02x:%02x:%02x:%02x:%02x:%02x\n",
  3192. dmi->dmi_addr[0], dmi->dmi_addr[1], dmi->dmi_addr[2],
  3193. dmi->dmi_addr[3], dmi->dmi_addr[4], dmi->dmi_addr[5] );
  3194. #endif
  3195. /* Initialize adapter's ethernet multicast addresses */
  3196. outb(TX_BASE & 0xff, PIORL(base));
  3197. outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
  3198. outb(addrs_len & 0xff, PIOP(base)); /* byte count lsb */
  3199. outb((addrs_len >> 8), PIOP(base)); /* byte count msb */
  3200. for(dmi=dev->mc_list; dmi; dmi=dmi->next)
  3201. outsb(PIOP(base), dmi->dmi_addr, dmi->dmi_addrlen);
  3202. /* reset transmit DMA pointer */
  3203. hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  3204. hacr_write(base, HACR_DEFAULT);
  3205. if(!wv_82593_cmd(dev, "wv_82593_config(): mc-setup",
  3206. OP0_MC_SETUP, SR0_MC_SETUP_DONE))
  3207. ret = FALSE;
  3208. lp->mc_count = dev->mc_count; /* remember to avoid repeated reset */
  3209. }
  3210. /* Job done, clear the flag */
  3211. lp->reconfig_82593 = FALSE;
  3212. #ifdef DEBUG_CONFIG_TRACE
  3213. printk(KERN_DEBUG "%s: <-wv_82593_config()\n", dev->name);
  3214. #endif
  3215. return(ret);
  3216. }
  3217. /*------------------------------------------------------------------*/
  3218. /*
  3219. * Read the Access Configuration Register, perform a software reset,
  3220. * and then re-enable the card's software.
  3221. *
  3222. * If I understand correctly : reset the pcmcia interface of the
  3223. * wavelan.
  3224. * (called by wv_config())
  3225. */
  3226. static inline int
  3227. wv_pcmcia_reset(struct net_device * dev)
  3228. {
  3229. int i;
  3230. conf_reg_t reg = { 0, CS_READ, CISREG_COR, 0 };
  3231. struct pcmcia_device * link = ((net_local *)netdev_priv(dev))->link;
  3232. #ifdef DEBUG_CONFIG_TRACE
  3233. printk(KERN_DEBUG "%s: ->wv_pcmcia_reset()\n", dev->name);
  3234. #endif
  3235. i = pcmcia_access_configuration_register(link, &reg);
  3236. if(i != CS_SUCCESS)
  3237. {
  3238. cs_error(link, AccessConfigurationRegister, i);
  3239. return FALSE;
  3240. }
  3241. #ifdef DEBUG_CONFIG_INFO
  3242. printk(KERN_DEBUG "%s: wavelan_pcmcia_reset(): Config reg is 0x%x\n",
  3243. dev->name, (u_int) reg.Value);
  3244. #endif
  3245. reg.Action = CS_WRITE;
  3246. reg.Value = reg.Value | COR_SW_RESET;
  3247. i = pcmcia_access_configuration_register(link, &reg);
  3248. if(i != CS_SUCCESS)
  3249. {
  3250. cs_error(link, AccessConfigurationRegister, i);
  3251. return FALSE;
  3252. }
  3253. reg.Action = CS_WRITE;
  3254. reg.Value = COR_LEVEL_IRQ | COR_CONFIG;
  3255. i = pcmcia_access_configuration_register(link, &reg);
  3256. if(i != CS_SUCCESS)
  3257. {
  3258. cs_error(link, AccessConfigurationRegister, i);
  3259. return FALSE;
  3260. }
  3261. #ifdef DEBUG_CONFIG_TRACE
  3262. printk(KERN_DEBUG "%s: <-wv_pcmcia_reset()\n", dev->name);
  3263. #endif
  3264. return TRUE;
  3265. }
  3266. /*------------------------------------------------------------------*/
  3267. /*
  3268. * wavelan_hw_config() is called after a CARD_INSERTION event is
  3269. * received, to configure the wavelan hardware.
  3270. * Note that the reception will be enabled in wavelan->open(), so the
  3271. * device is configured but idle...
  3272. * Performs the following actions:
  3273. * 1. A pcmcia software reset (using wv_pcmcia_reset())
  3274. * 2. A power reset (reset DMA)
  3275. * 3. Reset the LAN controller
  3276. * 4. Initialize the radio modem (using wv_mmc_init)
  3277. * 5. Configure LAN controller (using wv_82593_config)
  3278. * 6. Perform a diagnostic on the LAN controller
  3279. * (called by wavelan_event() & wv_hw_reset())
  3280. */
  3281. static int
  3282. wv_hw_config(struct net_device * dev)
  3283. {
  3284. net_local * lp = netdev_priv(dev);
  3285. kio_addr_t base = dev->base_addr;
  3286. unsigned long flags;
  3287. int ret = FALSE;
  3288. #ifdef DEBUG_CONFIG_TRACE
  3289. printk(KERN_DEBUG "%s: ->wv_hw_config()\n", dev->name);
  3290. #endif
  3291. #ifdef STRUCT_CHECK
  3292. if(wv_structuct_check() != (char *) NULL)
  3293. {
  3294. printk(KERN_WARNING "%s: wv_hw_config: structure/compiler botch: \"%s\"\n",
  3295. dev->name, wv_structuct_check());
  3296. return FALSE;
  3297. }
  3298. #endif /* STRUCT_CHECK == 1 */
  3299. /* Reset the pcmcia interface */
  3300. if(wv_pcmcia_reset(dev) == FALSE)
  3301. return FALSE;
  3302. /* Disable interrupts */
  3303. spin_lock_irqsave(&lp->spinlock, flags);
  3304. /* Disguised goto ;-) */
  3305. do
  3306. {
  3307. /* Power UP the module + reset the modem + reset host adapter
  3308. * (in fact, reset DMA channels) */
  3309. hacr_write_slow(base, HACR_RESET);
  3310. hacr_write(base, HACR_DEFAULT);
  3311. /* Check if the module has been powered up... */
  3312. if(hasr_read(base) & HASR_NO_CLK)
  3313. {
  3314. #ifdef DEBUG_CONFIG_ERRORS
  3315. printk(KERN_WARNING "%s: wv_hw_config(): modem not connected or not a wavelan card\n",
  3316. dev->name);
  3317. #endif
  3318. break;
  3319. }
  3320. /* initialize the modem */
  3321. if(wv_mmc_init(dev) == FALSE)
  3322. {
  3323. #ifdef DEBUG_CONFIG_ERRORS
  3324. printk(KERN_WARNING "%s: wv_hw_config(): Can't configure the modem\n",
  3325. dev->name);
  3326. #endif
  3327. break;
  3328. }
  3329. /* reset the LAN controller (i82593) */
  3330. outb(OP0_RESET, LCCR(base));
  3331. mdelay(1); /* A bit crude ! */
  3332. /* Initialize the LAN controller */
  3333. if(wv_82593_config(dev) == FALSE)
  3334. {
  3335. #ifdef DEBUG_CONFIG_ERRORS
  3336. printk(KERN_INFO "%s: wv_hw_config(): i82593 init failed\n",
  3337. dev->name);
  3338. #endif
  3339. break;
  3340. }
  3341. /* Diagnostic */
  3342. if(wv_diag(dev) == FALSE)
  3343. {
  3344. #ifdef DEBUG_CONFIG_ERRORS
  3345. printk(KERN_INFO "%s: wv_hw_config(): i82593 diagnostic failed\n",
  3346. dev->name);
  3347. #endif
  3348. break;
  3349. }
  3350. /*
  3351. * insert code for loopback test here
  3352. */
  3353. /* The device is now configured */
  3354. lp->configured = 1;
  3355. ret = TRUE;
  3356. }
  3357. while(0);
  3358. /* Re-enable interrupts */
  3359. spin_unlock_irqrestore(&lp->spinlock, flags);
  3360. #ifdef DEBUG_CONFIG_TRACE
  3361. printk(KERN_DEBUG "%s: <-wv_hw_config()\n", dev->name);
  3362. #endif
  3363. return(ret);
  3364. }
  3365. /*------------------------------------------------------------------*/
  3366. /*
  3367. * Totally reset the wavelan and restart it.
  3368. * Performs the following actions:
  3369. * 1. Call wv_hw_config()
  3370. * 2. Start the LAN controller's receive unit
  3371. * (called by wavelan_event(), wavelan_watchdog() and wavelan_open())
  3372. */
  3373. static inline void
  3374. wv_hw_reset(struct net_device * dev)
  3375. {
  3376. net_local * lp = netdev_priv(dev);
  3377. #ifdef DEBUG_CONFIG_TRACE
  3378. printk(KERN_DEBUG "%s: ->wv_hw_reset()\n", dev->name);
  3379. #endif
  3380. lp->nresets++;
  3381. lp->configured = 0;
  3382. /* Call wv_hw_config() for most of the reset & init stuff */
  3383. if(wv_hw_config(dev) == FALSE)
  3384. return;
  3385. /* start receive unit */
  3386. wv_ru_start(dev);
  3387. #ifdef DEBUG_CONFIG_TRACE
  3388. printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name);
  3389. #endif
  3390. }
  3391. /*------------------------------------------------------------------*/
  3392. /*
  3393. * wv_pcmcia_config() is called after a CARD_INSERTION event is
  3394. * received, to configure the PCMCIA socket, and to make the ethernet
  3395. * device available to the system.
  3396. * (called by wavelan_event())
  3397. */
  3398. static inline int
  3399. wv_pcmcia_config(struct pcmcia_device * link)
  3400. {
  3401. tuple_t tuple;
  3402. cisparse_t parse;
  3403. struct net_device * dev = (struct net_device *) link->priv;
  3404. int i;
  3405. u_char buf[64];
  3406. win_req_t req;
  3407. memreq_t mem;
  3408. net_local * lp = netdev_priv(dev);
  3409. #ifdef DEBUG_CONFIG_TRACE
  3410. printk(KERN_DEBUG "->wv_pcmcia_config(0x%p)\n", link);
  3411. #endif
  3412. /*
  3413. * This reads the card's CONFIG tuple to find its configuration
  3414. * registers.
  3415. */
  3416. do
  3417. {
  3418. tuple.Attributes = 0;
  3419. tuple.DesiredTuple = CISTPL_CONFIG;
  3420. i = pcmcia_get_first_tuple(link, &tuple);
  3421. if(i != CS_SUCCESS)
  3422. break;
  3423. tuple.TupleData = (cisdata_t *)buf;
  3424. tuple.TupleDataMax = 64;
  3425. tuple.TupleOffset = 0;
  3426. i = pcmcia_get_tuple_data(link, &tuple);
  3427. if(i != CS_SUCCESS)
  3428. break;
  3429. i = pcmcia_parse_tuple(link, &tuple, &parse);
  3430. if(i != CS_SUCCESS)
  3431. break;
  3432. link->conf.ConfigBase = parse.config.base;
  3433. link->conf.Present = parse.config.rmask[0];
  3434. }
  3435. while(0);
  3436. if(i != CS_SUCCESS)
  3437. {
  3438. cs_error(link, ParseTuple, i);
  3439. return FALSE;
  3440. }
  3441. do
  3442. {
  3443. i = pcmcia_request_io(link, &link->io);
  3444. if(i != CS_SUCCESS)
  3445. {
  3446. cs_error(link, RequestIO, i);
  3447. break;
  3448. }
  3449. /*
  3450. * Now allocate an interrupt line. Note that this does not
  3451. * actually assign a handler to the interrupt.
  3452. */
  3453. i = pcmcia_request_irq(link, &link->irq);
  3454. if(i != CS_SUCCESS)
  3455. {
  3456. cs_error(link, RequestIRQ, i);
  3457. break;
  3458. }
  3459. /*
  3460. * This actually configures the PCMCIA socket -- setting up
  3461. * the I/O windows and the interrupt mapping.
  3462. */
  3463. link->conf.ConfigIndex = 1;
  3464. i = pcmcia_request_configuration(link, &link->conf);
  3465. if(i != CS_SUCCESS)
  3466. {
  3467. cs_error(link, RequestConfiguration, i);
  3468. break;
  3469. }
  3470. /*
  3471. * Allocate a small memory window. Note that the struct pcmcia_device
  3472. * structure provides space for one window handle -- if your
  3473. * device needs several windows, you'll need to keep track of
  3474. * the handles in your private data structure, link->priv.
  3475. */
  3476. req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
  3477. req.Base = req.Size = 0;
  3478. req.AccessSpeed = mem_speed;
  3479. i = pcmcia_request_window(&link, &req, &link->win);
  3480. if(i != CS_SUCCESS)
  3481. {
  3482. cs_error(link, RequestWindow, i);
  3483. break;
  3484. }
  3485. lp->mem = ioremap(req.Base, req.Size);
  3486. dev->mem_start = (u_long)lp->mem;
  3487. dev->mem_end = dev->mem_start + req.Size;
  3488. mem.CardOffset = 0; mem.Page = 0;
  3489. i = pcmcia_map_mem_page(link->win, &mem);
  3490. if(i != CS_SUCCESS)
  3491. {
  3492. cs_error(link, MapMemPage, i);
  3493. break;
  3494. }
  3495. /* Feed device with this info... */
  3496. dev->irq = link->irq.AssignedIRQ;
  3497. dev->base_addr = link->io.BasePort1;
  3498. netif_start_queue(dev);
  3499. #ifdef DEBUG_CONFIG_INFO
  3500. printk(KERN_DEBUG "wv_pcmcia_config: MEMSTART %p IRQ %d IOPORT 0x%x\n",
  3501. lp->mem, dev->irq, (u_int) dev->base_addr);
  3502. #endif
  3503. SET_NETDEV_DEV(dev, &handle_to_dev(link));
  3504. i = register_netdev(dev);
  3505. if(i != 0)
  3506. {
  3507. #ifdef DEBUG_CONFIG_ERRORS
  3508. printk(KERN_INFO "wv_pcmcia_config(): register_netdev() failed\n");
  3509. #endif
  3510. break;
  3511. }
  3512. }
  3513. while(0); /* Humm... Disguised goto !!! */
  3514. /* If any step failed, release any partially configured state */
  3515. if(i != 0)
  3516. {
  3517. wv_pcmcia_release(link);
  3518. return FALSE;
  3519. }
  3520. strcpy(((net_local *) netdev_priv(dev))->node.dev_name, dev->name);
  3521. link->dev_node = &((net_local *) netdev_priv(dev))->node;
  3522. #ifdef DEBUG_CONFIG_TRACE
  3523. printk(KERN_DEBUG "<-wv_pcmcia_config()\n");
  3524. #endif
  3525. return TRUE;
  3526. }
  3527. /*------------------------------------------------------------------*/
  3528. /*
  3529. * After a card is removed, wv_pcmcia_release() will unregister the net
  3530. * device, and release the PCMCIA configuration. If the device is
  3531. * still open, this will be postponed until it is closed.
  3532. */
  3533. static void
  3534. wv_pcmcia_release(struct pcmcia_device *link)
  3535. {
  3536. struct net_device * dev = (struct net_device *) link->priv;
  3537. net_local * lp = netdev_priv(dev);
  3538. #ifdef DEBUG_CONFIG_TRACE
  3539. printk(KERN_DEBUG "%s: -> wv_pcmcia_release(0x%p)\n", dev->name, link);
  3540. #endif
  3541. iounmap(lp->mem);
  3542. pcmcia_disable_device(link);
  3543. #ifdef DEBUG_CONFIG_TRACE
  3544. printk(KERN_DEBUG "%s: <- wv_pcmcia_release()\n", dev->name);
  3545. #endif
  3546. }
  3547. /************************ INTERRUPT HANDLING ************************/
  3548. /*
  3549. * This function is the interrupt handler for the WaveLAN card. This
  3550. * routine will be called whenever:
  3551. * 1. A packet is received.
  3552. * 2. A packet has successfully been transferred and the unit is
  3553. * ready to transmit another packet.
  3554. * 3. A command has completed execution.
  3555. */
  3556. static irqreturn_t
  3557. wavelan_interrupt(int irq,
  3558. void * dev_id,
  3559. struct pt_regs * regs)
  3560. {
  3561. struct net_device * dev;
  3562. net_local * lp;
  3563. kio_addr_t base;
  3564. int status0;
  3565. u_int tx_status;
  3566. if ((dev = dev_id) == NULL)
  3567. {
  3568. #ifdef DEBUG_INTERRUPT_ERROR
  3569. printk(KERN_WARNING "wavelan_interrupt(): irq %d for unknown device.\n",
  3570. irq);
  3571. #endif
  3572. return IRQ_NONE;
  3573. }
  3574. #ifdef DEBUG_INTERRUPT_TRACE
  3575. printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name);
  3576. #endif
  3577. lp = netdev_priv(dev);
  3578. base = dev->base_addr;
  3579. #ifdef DEBUG_INTERRUPT_INFO
  3580. /* Check state of our spinlock (it should be cleared) */
  3581. if(spin_is_locked(&lp->spinlock))
  3582. printk(KERN_DEBUG
  3583. "%s: wavelan_interrupt(): spinlock is already locked !!!\n",
  3584. dev->name);
  3585. #endif
  3586. /* Prevent reentrancy. We need to do that because we may have
  3587. * multiple interrupt handler running concurently.
  3588. * It is safe because interrupts are disabled before aquiring
  3589. * the spinlock. */
  3590. spin_lock(&lp->spinlock);
  3591. /* Treat all pending interrupts */
  3592. while(1)
  3593. {
  3594. /* ---------------- INTERRUPT CHECKING ---------------- */
  3595. /*
  3596. * Look for the interrupt and verify the validity
  3597. */
  3598. outb(CR0_STATUS_0 | OP0_NOP, LCCR(base));
  3599. status0 = inb(LCSR(base));
  3600. #ifdef DEBUG_INTERRUPT_INFO
  3601. printk(KERN_DEBUG "status0 0x%x [%s => 0x%x]", status0,
  3602. (status0&SR0_INTERRUPT)?"int":"no int",status0&~SR0_INTERRUPT);
  3603. if(status0&SR0_INTERRUPT)
  3604. {
  3605. printk(" [%s => %d]\n", (status0 & SR0_CHNL) ? "chnl" :
  3606. ((status0 & SR0_EXECUTION) ? "cmd" :
  3607. ((status0 & SR0_RECEPTION) ? "recv" : "unknown")),
  3608. (status0 & SR0_EVENT_MASK));
  3609. }
  3610. else
  3611. printk("\n");
  3612. #endif
  3613. /* Return if no actual interrupt from i82593 (normal exit) */
  3614. if(!(status0 & SR0_INTERRUPT))
  3615. break;
  3616. /* If interrupt is both Rx and Tx or none...
  3617. * This code in fact is there to catch the spurious interrupt
  3618. * when you remove the wavelan pcmcia card from the socket */
  3619. if(((status0 & SR0_BOTH_RX_TX) == SR0_BOTH_RX_TX) ||
  3620. ((status0 & SR0_BOTH_RX_TX) == 0x0))
  3621. {
  3622. #ifdef DEBUG_INTERRUPT_INFO
  3623. printk(KERN_INFO "%s: wv_interrupt(): bogus interrupt (or from dead card) : %X\n",
  3624. dev->name, status0);
  3625. #endif
  3626. /* Acknowledge the interrupt */
  3627. outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
  3628. break;
  3629. }
  3630. /* ----------------- RECEIVING PACKET ----------------- */
  3631. /*
  3632. * When the wavelan signal the reception of a new packet,
  3633. * we call wv_packet_rcv() to copy if from the buffer and
  3634. * send it to NET3
  3635. */
  3636. if(status0 & SR0_RECEPTION)
  3637. {
  3638. #ifdef DEBUG_INTERRUPT_INFO
  3639. printk(KERN_DEBUG "%s: wv_interrupt(): receive\n", dev->name);
  3640. #endif
  3641. if((status0 & SR0_EVENT_MASK) == SR0_STOP_REG_HIT)
  3642. {
  3643. #ifdef DEBUG_INTERRUPT_ERROR
  3644. printk(KERN_INFO "%s: wv_interrupt(): receive buffer overflow\n",
  3645. dev->name);
  3646. #endif
  3647. lp->stats.rx_over_errors++;
  3648. lp->overrunning = 1;
  3649. }
  3650. /* Get the packet */
  3651. wv_packet_rcv(dev);
  3652. lp->overrunning = 0;
  3653. /* Acknowledge the interrupt */
  3654. outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
  3655. continue;
  3656. }
  3657. /* ---------------- COMMAND COMPLETION ---------------- */
  3658. /*
  3659. * Interrupts issued when the i82593 has completed a command.
  3660. * Most likely : transmission done
  3661. */
  3662. /* If a transmission has been done */
  3663. if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_DONE ||
  3664. (status0 & SR0_EVENT_MASK) == SR0_RETRANSMIT_DONE ||
  3665. (status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
  3666. {
  3667. #ifdef DEBUG_TX_ERROR
  3668. if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
  3669. printk(KERN_INFO "%s: wv_interrupt(): packet transmitted without CRC.\n",
  3670. dev->name);
  3671. #endif
  3672. /* Get transmission status */
  3673. tx_status = inb(LCSR(base));
  3674. tx_status |= (inb(LCSR(base)) << 8);
  3675. #ifdef DEBUG_INTERRUPT_INFO
  3676. printk(KERN_DEBUG "%s: wv_interrupt(): transmission done\n",
  3677. dev->name);
  3678. {
  3679. u_int rcv_bytes;
  3680. u_char status3;
  3681. rcv_bytes = inb(LCSR(base));
  3682. rcv_bytes |= (inb(LCSR(base)) << 8);
  3683. status3 = inb(LCSR(base));
  3684. printk(KERN_DEBUG "tx_status 0x%02x rcv_bytes 0x%02x status3 0x%x\n",
  3685. tx_status, rcv_bytes, (u_int) status3);
  3686. }
  3687. #endif
  3688. /* Check for possible errors */
  3689. if((tx_status & TX_OK) != TX_OK)
  3690. {
  3691. lp->stats.tx_errors++;
  3692. if(tx_status & TX_FRTL)
  3693. {
  3694. #ifdef DEBUG_TX_ERROR
  3695. printk(KERN_INFO "%s: wv_interrupt(): frame too long\n",
  3696. dev->name);
  3697. #endif
  3698. }
  3699. if(tx_status & TX_UND_RUN)
  3700. {
  3701. #ifdef DEBUG_TX_FAIL
  3702. printk(KERN_DEBUG "%s: wv_interrupt(): DMA underrun\n",
  3703. dev->name);
  3704. #endif
  3705. lp->stats.tx_aborted_errors++;
  3706. }
  3707. if(tx_status & TX_LOST_CTS)
  3708. {
  3709. #ifdef DEBUG_TX_FAIL
  3710. printk(KERN_DEBUG "%s: wv_interrupt(): no CTS\n", dev->name);
  3711. #endif
  3712. lp->stats.tx_carrier_errors++;
  3713. }
  3714. if(tx_status & TX_LOST_CRS)
  3715. {
  3716. #ifdef DEBUG_TX_FAIL
  3717. printk(KERN_DEBUG "%s: wv_interrupt(): no carrier\n",
  3718. dev->name);
  3719. #endif
  3720. lp->stats.tx_carrier_errors++;
  3721. }
  3722. if(tx_status & TX_HRT_BEAT)
  3723. {
  3724. #ifdef DEBUG_TX_FAIL
  3725. printk(KERN_DEBUG "%s: wv_interrupt(): heart beat\n", dev->name);
  3726. #endif
  3727. lp->stats.tx_heartbeat_errors++;
  3728. }
  3729. if(tx_status & TX_DEFER)
  3730. {
  3731. #ifdef DEBUG_TX_FAIL
  3732. printk(KERN_DEBUG "%s: wv_interrupt(): channel jammed\n",
  3733. dev->name);
  3734. #endif
  3735. }
  3736. /* Ignore late collisions since they're more likely to happen
  3737. * here (the WaveLAN design prevents the LAN controller from
  3738. * receiving while it is transmitting). We take action only when
  3739. * the maximum retransmit attempts is exceeded.
  3740. */
  3741. if(tx_status & TX_COLL)
  3742. {
  3743. if(tx_status & TX_MAX_COL)
  3744. {
  3745. #ifdef DEBUG_TX_FAIL
  3746. printk(KERN_DEBUG "%s: wv_interrupt(): channel congestion\n",
  3747. dev->name);
  3748. #endif
  3749. if(!(tx_status & TX_NCOL_MASK))
  3750. {
  3751. lp->stats.collisions += 0x10;
  3752. }
  3753. }
  3754. }
  3755. } /* if(!(tx_status & TX_OK)) */
  3756. lp->stats.collisions += (tx_status & TX_NCOL_MASK);
  3757. lp->stats.tx_packets++;
  3758. netif_wake_queue(dev);
  3759. outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
  3760. }
  3761. else /* if interrupt = transmit done or retransmit done */
  3762. {
  3763. #ifdef DEBUG_INTERRUPT_ERROR
  3764. printk(KERN_INFO "wavelan_cs: unknown interrupt, status0 = %02x\n",
  3765. status0);
  3766. #endif
  3767. outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
  3768. }
  3769. } /* while(1) */
  3770. spin_unlock(&lp->spinlock);
  3771. #ifdef DEBUG_INTERRUPT_TRACE
  3772. printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name);
  3773. #endif
  3774. /* We always return IRQ_HANDLED, because we will receive empty
  3775. * interrupts under normal operations. Anyway, it doesn't matter
  3776. * as we are dealing with an ISA interrupt that can't be shared.
  3777. *
  3778. * Explanation : under heavy receive, the following happens :
  3779. * ->wavelan_interrupt()
  3780. * (status0 & SR0_INTERRUPT) != 0
  3781. * ->wv_packet_rcv()
  3782. * (status0 & SR0_INTERRUPT) != 0
  3783. * ->wv_packet_rcv()
  3784. * (status0 & SR0_INTERRUPT) == 0 // i.e. no more event
  3785. * <-wavelan_interrupt()
  3786. * ->wavelan_interrupt()
  3787. * (status0 & SR0_INTERRUPT) == 0 // i.e. empty interrupt
  3788. * <-wavelan_interrupt()
  3789. * Jean II */
  3790. return IRQ_HANDLED;
  3791. } /* wv_interrupt */
  3792. /*------------------------------------------------------------------*/
  3793. /*
  3794. * Watchdog: when we start a transmission, a timer is set for us in the
  3795. * kernel. If the transmission completes, this timer is disabled. If
  3796. * the timer expires, we are called and we try to unlock the hardware.
  3797. *
  3798. * Note : This watchdog is move clever than the one in the ISA driver,
  3799. * because it try to abort the current command before reseting
  3800. * everything...
  3801. * On the other hand, it's a bit simpler, because we don't have to
  3802. * deal with the multiple Tx buffers...
  3803. */
  3804. static void
  3805. wavelan_watchdog(struct net_device * dev)
  3806. {
  3807. net_local * lp = netdev_priv(dev);
  3808. kio_addr_t base = dev->base_addr;
  3809. unsigned long flags;
  3810. int aborted = FALSE;
  3811. #ifdef DEBUG_INTERRUPT_TRACE
  3812. printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name);
  3813. #endif
  3814. #ifdef DEBUG_INTERRUPT_ERROR
  3815. printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n",
  3816. dev->name);
  3817. #endif
  3818. spin_lock_irqsave(&lp->spinlock, flags);
  3819. /* Ask to abort the current command */
  3820. outb(OP0_ABORT, LCCR(base));
  3821. /* Wait for the end of the command (a bit hackish) */
  3822. if(wv_82593_cmd(dev, "wavelan_watchdog(): abort",
  3823. OP0_NOP | CR0_STATUS_3, SR0_EXECUTION_ABORTED))
  3824. aborted = TRUE;
  3825. /* Release spinlock here so that wv_hw_reset() can grab it */
  3826. spin_unlock_irqrestore(&lp->spinlock, flags);
  3827. /* Check if we were successful in aborting it */
  3828. if(!aborted)
  3829. {
  3830. /* It seem that it wasn't enough */
  3831. #ifdef DEBUG_INTERRUPT_ERROR
  3832. printk(KERN_INFO "%s: wavelan_watchdog: abort failed, trying reset\n",
  3833. dev->name);
  3834. #endif
  3835. wv_hw_reset(dev);
  3836. }
  3837. #ifdef DEBUG_PSA_SHOW
  3838. {
  3839. psa_t psa;
  3840. psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
  3841. wv_psa_show(&psa);
  3842. }
  3843. #endif
  3844. #ifdef DEBUG_MMC_SHOW
  3845. wv_mmc_show(dev);
  3846. #endif
  3847. #ifdef DEBUG_I82593_SHOW
  3848. wv_ru_show(dev);
  3849. #endif
  3850. /* We are no more waiting for something... */
  3851. netif_wake_queue(dev);
  3852. #ifdef DEBUG_INTERRUPT_TRACE
  3853. printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name);
  3854. #endif
  3855. }
  3856. /********************* CONFIGURATION CALLBACKS *********************/
  3857. /*
  3858. * Here are the functions called by the pcmcia package (cardmgr) and
  3859. * linux networking (NET3) for initialization, configuration and
  3860. * deinstallations of the Wavelan Pcmcia Hardware.
  3861. */
  3862. /*------------------------------------------------------------------*/
  3863. /*
  3864. * Configure and start up the WaveLAN PCMCIA adaptor.
  3865. * Called by NET3 when it "open" the device.
  3866. */
  3867. static int
  3868. wavelan_open(struct net_device * dev)
  3869. {
  3870. net_local * lp = netdev_priv(dev);
  3871. struct pcmcia_device * link = lp->link;
  3872. kio_addr_t base = dev->base_addr;
  3873. #ifdef DEBUG_CALLBACK_TRACE
  3874. printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name,
  3875. (unsigned int) dev);
  3876. #endif
  3877. /* Check if the modem is powered up (wavelan_close() power it down */
  3878. if(hasr_read(base) & HASR_NO_CLK)
  3879. {
  3880. /* Power up (power up time is 250us) */
  3881. hacr_write(base, HACR_DEFAULT);
  3882. /* Check if the module has been powered up... */
  3883. if(hasr_read(base) & HASR_NO_CLK)
  3884. {
  3885. #ifdef DEBUG_CONFIG_ERRORS
  3886. printk(KERN_WARNING "%s: wavelan_open(): modem not connected\n",
  3887. dev->name);
  3888. #endif
  3889. return FALSE;
  3890. }
  3891. }
  3892. /* Start reception and declare the driver ready */
  3893. if(!lp->configured)
  3894. return FALSE;
  3895. if(!wv_ru_start(dev))
  3896. wv_hw_reset(dev); /* If problem : reset */
  3897. netif_start_queue(dev);
  3898. /* Mark the device as used */
  3899. link->open++;
  3900. #ifdef WAVELAN_ROAMING
  3901. if(do_roaming)
  3902. wv_roam_init(dev);
  3903. #endif /* WAVELAN_ROAMING */
  3904. #ifdef DEBUG_CALLBACK_TRACE
  3905. printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name);
  3906. #endif
  3907. return 0;
  3908. }
  3909. /*------------------------------------------------------------------*/
  3910. /*
  3911. * Shutdown the WaveLAN PCMCIA adaptor.
  3912. * Called by NET3 when it "close" the device.
  3913. */
  3914. static int
  3915. wavelan_close(struct net_device * dev)
  3916. {
  3917. struct pcmcia_device * link = ((net_local *)netdev_priv(dev))->link;
  3918. kio_addr_t base = dev->base_addr;
  3919. #ifdef DEBUG_CALLBACK_TRACE
  3920. printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name,
  3921. (unsigned int) dev);
  3922. #endif
  3923. /* If the device isn't open, then nothing to do */
  3924. if(!link->open)
  3925. {
  3926. #ifdef DEBUG_CONFIG_INFO
  3927. printk(KERN_DEBUG "%s: wavelan_close(): device not open\n", dev->name);
  3928. #endif
  3929. return 0;
  3930. }
  3931. #ifdef WAVELAN_ROAMING
  3932. /* Cleanup of roaming stuff... */
  3933. if(do_roaming)
  3934. wv_roam_cleanup(dev);
  3935. #endif /* WAVELAN_ROAMING */
  3936. link->open--;
  3937. /* If the card is still present */
  3938. if(netif_running(dev))
  3939. {
  3940. netif_stop_queue(dev);
  3941. /* Stop receiving new messages and wait end of transmission */
  3942. wv_ru_stop(dev);
  3943. /* Power down the module */
  3944. hacr_write(base, HACR_DEFAULT & (~HACR_PWR_STAT));
  3945. }
  3946. #ifdef DEBUG_CALLBACK_TRACE
  3947. printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name);
  3948. #endif
  3949. return 0;
  3950. }
  3951. /*------------------------------------------------------------------*/
  3952. /*
  3953. * wavelan_attach() creates an "instance" of the driver, allocating
  3954. * local data structures for one device (one interface). The device
  3955. * is registered with Card Services.
  3956. *
  3957. * The dev_link structure is initialized, but we don't actually
  3958. * configure the card at this point -- we wait until we receive a
  3959. * card insertion event.
  3960. */
  3961. static int
  3962. wavelan_probe(struct pcmcia_device *p_dev)
  3963. {
  3964. struct net_device * dev; /* Interface generic data */
  3965. net_local * lp; /* Interface specific data */
  3966. int ret;
  3967. #ifdef DEBUG_CALLBACK_TRACE
  3968. printk(KERN_DEBUG "-> wavelan_attach()\n");
  3969. #endif
  3970. /* The io structure describes IO port mapping */
  3971. p_dev->io.NumPorts1 = 8;
  3972. p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  3973. p_dev->io.IOAddrLines = 3;
  3974. /* Interrupt setup */
  3975. p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
  3976. p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
  3977. p_dev->irq.Handler = wavelan_interrupt;
  3978. /* General socket configuration */
  3979. p_dev->conf.Attributes = CONF_ENABLE_IRQ;
  3980. p_dev->conf.IntType = INT_MEMORY_AND_IO;
  3981. /* Allocate the generic data structure */
  3982. dev = alloc_etherdev(sizeof(net_local));
  3983. if (!dev)
  3984. return -ENOMEM;
  3985. p_dev->priv = p_dev->irq.Instance = dev;
  3986. lp = netdev_priv(dev);
  3987. /* Init specific data */
  3988. lp->configured = 0;
  3989. lp->reconfig_82593 = FALSE;
  3990. lp->nresets = 0;
  3991. /* Multicast stuff */
  3992. lp->promiscuous = 0;
  3993. lp->allmulticast = 0;
  3994. lp->mc_count = 0;
  3995. /* Init spinlock */
  3996. spin_lock_init(&lp->spinlock);
  3997. /* back links */
  3998. lp->dev = dev;
  3999. /* wavelan NET3 callbacks */
  4000. SET_MODULE_OWNER(dev);
  4001. dev->open = &wavelan_open;
  4002. dev->stop = &wavelan_close;
  4003. dev->hard_start_xmit = &wavelan_packet_xmit;
  4004. dev->get_stats = &wavelan_get_stats;
  4005. dev->set_multicast_list = &wavelan_set_multicast_list;
  4006. #ifdef SET_MAC_ADDRESS
  4007. dev->set_mac_address = &wavelan_set_mac_address;
  4008. #endif /* SET_MAC_ADDRESS */
  4009. /* Set the watchdog timer */
  4010. dev->tx_timeout = &wavelan_watchdog;
  4011. dev->watchdog_timeo = WATCHDOG_JIFFIES;
  4012. SET_ETHTOOL_OPS(dev, &ops);
  4013. dev->wireless_handlers = &wavelan_handler_def;
  4014. lp->wireless_data.spy_data = &lp->spy_data;
  4015. dev->wireless_data = &lp->wireless_data;
  4016. /* Other specific data */
  4017. dev->mtu = WAVELAN_MTU;
  4018. ret = wv_pcmcia_config(p_dev);
  4019. if (ret)
  4020. return ret;
  4021. ret = wv_hw_config(dev);
  4022. if (ret) {
  4023. dev->irq = 0;
  4024. pcmcia_disable_device(p_dev);
  4025. return ret;
  4026. }
  4027. wv_init_info(dev);
  4028. #ifdef DEBUG_CALLBACK_TRACE
  4029. printk(KERN_DEBUG "<- wavelan_attach()\n");
  4030. #endif
  4031. return 0;
  4032. }
  4033. /*------------------------------------------------------------------*/
  4034. /*
  4035. * This deletes a driver "instance". The device is de-registered with
  4036. * Card Services. If it has been released, all local data structures
  4037. * are freed. Otherwise, the structures will be freed when the device
  4038. * is released.
  4039. */
  4040. static void
  4041. wavelan_detach(struct pcmcia_device *link)
  4042. {
  4043. #ifdef DEBUG_CALLBACK_TRACE
  4044. printk(KERN_DEBUG "-> wavelan_detach(0x%p)\n", link);
  4045. #endif
  4046. /* Some others haven't done their job : give them another chance */
  4047. wv_pcmcia_release(link);
  4048. /* Free pieces */
  4049. if(link->priv)
  4050. {
  4051. struct net_device * dev = (struct net_device *) link->priv;
  4052. /* Remove ourselves from the kernel list of ethernet devices */
  4053. /* Warning : can't be called from interrupt, timer or wavelan_close() */
  4054. if (link->dev_node)
  4055. unregister_netdev(dev);
  4056. link->dev_node = NULL;
  4057. ((net_local *)netdev_priv(dev))->link = NULL;
  4058. ((net_local *)netdev_priv(dev))->dev = NULL;
  4059. free_netdev(dev);
  4060. }
  4061. #ifdef DEBUG_CALLBACK_TRACE
  4062. printk(KERN_DEBUG "<- wavelan_detach()\n");
  4063. #endif
  4064. }
  4065. static int wavelan_suspend(struct pcmcia_device *link)
  4066. {
  4067. struct net_device * dev = (struct net_device *) link->priv;
  4068. /* NB: wavelan_close will be called, but too late, so we are
  4069. * obliged to close nicely the wavelan here. David, could you
  4070. * close the device before suspending them ? And, by the way,
  4071. * could you, on resume, add a "route add -net ..." after the
  4072. * ifconfig up ? Thanks... */
  4073. /* Stop receiving new messages and wait end of transmission */
  4074. wv_ru_stop(dev);
  4075. if (link->open)
  4076. netif_device_detach(dev);
  4077. /* Power down the module */
  4078. hacr_write(dev->base_addr, HACR_DEFAULT & (~HACR_PWR_STAT));
  4079. return 0;
  4080. }
  4081. static int wavelan_resume(struct pcmcia_device *link)
  4082. {
  4083. struct net_device * dev = (struct net_device *) link->priv;
  4084. if (link->open) {
  4085. wv_hw_reset(dev);
  4086. netif_device_attach(dev);
  4087. }
  4088. return 0;
  4089. }
  4090. static struct pcmcia_device_id wavelan_ids[] = {
  4091. PCMCIA_DEVICE_PROD_ID12("AT&T","WaveLAN/PCMCIA", 0xe7c5affd, 0x1bc50975),
  4092. PCMCIA_DEVICE_PROD_ID12("Digital", "RoamAbout/DS", 0x9999ab35, 0x00d05e06),
  4093. PCMCIA_DEVICE_PROD_ID12("Lucent Technologies", "WaveLAN/PCMCIA", 0x23eb9949, 0x1bc50975),
  4094. PCMCIA_DEVICE_PROD_ID12("NCR", "WaveLAN/PCMCIA", 0x24358cd4, 0x1bc50975),
  4095. PCMCIA_DEVICE_NULL,
  4096. };
  4097. MODULE_DEVICE_TABLE(pcmcia, wavelan_ids);
  4098. static struct pcmcia_driver wavelan_driver = {
  4099. .owner = THIS_MODULE,
  4100. .drv = {
  4101. .name = "wavelan_cs",
  4102. },
  4103. .probe = wavelan_probe,
  4104. .remove = wavelan_detach,
  4105. .id_table = wavelan_ids,
  4106. .suspend = wavelan_suspend,
  4107. .resume = wavelan_resume,
  4108. };
  4109. static int __init
  4110. init_wavelan_cs(void)
  4111. {
  4112. return pcmcia_register_driver(&wavelan_driver);
  4113. }
  4114. static void __exit
  4115. exit_wavelan_cs(void)
  4116. {
  4117. pcmcia_unregister_driver(&wavelan_driver);
  4118. }
  4119. module_init(init_wavelan_cs);
  4120. module_exit(exit_wavelan_cs);