wavelan_cs.c 132 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713
  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 writing 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 = 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. DECLARE_MAC_BUF(mac);
  887. printk(KERN_DEBUG "##### wavelan psa contents: #####\n");
  888. printk(KERN_DEBUG "psa_io_base_addr_1: 0x%02X %02X %02X %02X\n",
  889. p->psa_io_base_addr_1,
  890. p->psa_io_base_addr_2,
  891. p->psa_io_base_addr_3,
  892. p->psa_io_base_addr_4);
  893. printk(KERN_DEBUG "psa_rem_boot_addr_1: 0x%02X %02X %02X\n",
  894. p->psa_rem_boot_addr_1,
  895. p->psa_rem_boot_addr_2,
  896. p->psa_rem_boot_addr_3);
  897. printk(KERN_DEBUG "psa_holi_params: 0x%02x, ", p->psa_holi_params);
  898. printk("psa_int_req_no: %d\n", p->psa_int_req_no);
  899. #ifdef DEBUG_SHOW_UNUSED
  900. printk(KERN_DEBUG "psa_unused0[]: %s\n",
  901. print_mac(mac, p->psa_unused0));
  902. #endif /* DEBUG_SHOW_UNUSED */
  903. printk(KERN_DEBUG "psa_univ_mac_addr[]: %s\n",
  904. print_mac(mac, p->psa_univ_mac_addr));
  905. printk(KERN_DEBUG "psa_local_mac_addr[]: %s\n",
  906. print_mac(mac, p->psa_local_mac_addr));
  907. printk(KERN_DEBUG "psa_univ_local_sel: %d, ", p->psa_univ_local_sel);
  908. printk("psa_comp_number: %d, ", p->psa_comp_number);
  909. printk("psa_thr_pre_set: 0x%02x\n", p->psa_thr_pre_set);
  910. printk(KERN_DEBUG "psa_feature_select/decay_prm: 0x%02x, ",
  911. p->psa_feature_select);
  912. printk("psa_subband/decay_update_prm: %d\n", p->psa_subband);
  913. printk(KERN_DEBUG "psa_quality_thr: 0x%02x, ", p->psa_quality_thr);
  914. printk("psa_mod_delay: 0x%02x\n", p->psa_mod_delay);
  915. printk(KERN_DEBUG "psa_nwid: 0x%02x%02x, ", p->psa_nwid[0], p->psa_nwid[1]);
  916. printk("psa_nwid_select: %d\n", p->psa_nwid_select);
  917. printk(KERN_DEBUG "psa_encryption_select: %d, ", p->psa_encryption_select);
  918. printk("psa_encryption_key[]: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
  919. p->psa_encryption_key[0],
  920. p->psa_encryption_key[1],
  921. p->psa_encryption_key[2],
  922. p->psa_encryption_key[3],
  923. p->psa_encryption_key[4],
  924. p->psa_encryption_key[5],
  925. p->psa_encryption_key[6],
  926. p->psa_encryption_key[7]);
  927. printk(KERN_DEBUG "psa_databus_width: %d\n", p->psa_databus_width);
  928. printk(KERN_DEBUG "psa_call_code/auto_squelch: 0x%02x, ",
  929. p->psa_call_code[0]);
  930. printk("psa_call_code[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
  931. p->psa_call_code[0],
  932. p->psa_call_code[1],
  933. p->psa_call_code[2],
  934. p->psa_call_code[3],
  935. p->psa_call_code[4],
  936. p->psa_call_code[5],
  937. p->psa_call_code[6],
  938. p->psa_call_code[7]);
  939. #ifdef DEBUG_SHOW_UNUSED
  940. printk(KERN_DEBUG "psa_reserved[]: %02X:%02X:%02X:%02X\n",
  941. p->psa_reserved[0],
  942. p->psa_reserved[1],
  943. p->psa_reserved[2],
  944. p->psa_reserved[3]);
  945. #endif /* DEBUG_SHOW_UNUSED */
  946. printk(KERN_DEBUG "psa_conf_status: %d, ", p->psa_conf_status);
  947. printk("psa_crc: 0x%02x%02x, ", p->psa_crc[0], p->psa_crc[1]);
  948. printk("psa_crc_status: 0x%02x\n", p->psa_crc_status);
  949. } /* wv_psa_show */
  950. #endif /* DEBUG_PSA_SHOW */
  951. #ifdef DEBUG_MMC_SHOW
  952. /*------------------------------------------------------------------*/
  953. /*
  954. * Print the formatted status of the Modem Management Controller.
  955. * This function need to be completed...
  956. */
  957. static void
  958. wv_mmc_show(struct net_device * dev)
  959. {
  960. kio_addr_t base = dev->base_addr;
  961. net_local * lp = netdev_priv(dev);
  962. mmr_t m;
  963. /* Basic check */
  964. if(hasr_read(base) & HASR_NO_CLK)
  965. {
  966. printk(KERN_WARNING "%s: wv_mmc_show: modem not connected\n",
  967. dev->name);
  968. return;
  969. }
  970. spin_lock_irqsave(&lp->spinlock, flags);
  971. /* Read the mmc */
  972. mmc_out(base, mmwoff(0, mmw_freeze), 1);
  973. mmc_read(base, 0, (u_char *)&m, sizeof(m));
  974. mmc_out(base, mmwoff(0, mmw_freeze), 0);
  975. /* Don't forget to update statistics */
  976. lp->wstats.discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
  977. spin_unlock_irqrestore(&lp->spinlock, flags);
  978. printk(KERN_DEBUG "##### wavelan modem status registers: #####\n");
  979. #ifdef DEBUG_SHOW_UNUSED
  980. printk(KERN_DEBUG "mmc_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
  981. m.mmr_unused0[0],
  982. m.mmr_unused0[1],
  983. m.mmr_unused0[2],
  984. m.mmr_unused0[3],
  985. m.mmr_unused0[4],
  986. m.mmr_unused0[5],
  987. m.mmr_unused0[6],
  988. m.mmr_unused0[7]);
  989. #endif /* DEBUG_SHOW_UNUSED */
  990. printk(KERN_DEBUG "Encryption algorithm: %02X - Status: %02X\n",
  991. m.mmr_des_avail, m.mmr_des_status);
  992. #ifdef DEBUG_SHOW_UNUSED
  993. printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n",
  994. m.mmr_unused1[0],
  995. m.mmr_unused1[1],
  996. m.mmr_unused1[2],
  997. m.mmr_unused1[3],
  998. m.mmr_unused1[4]);
  999. #endif /* DEBUG_SHOW_UNUSED */
  1000. printk(KERN_DEBUG "dce_status: 0x%x [%s%s%s%s]\n",
  1001. m.mmr_dce_status,
  1002. (m.mmr_dce_status & MMR_DCE_STATUS_RX_BUSY) ? "energy detected,":"",
  1003. (m.mmr_dce_status & MMR_DCE_STATUS_LOOPT_IND) ?
  1004. "loop test indicated," : "",
  1005. (m.mmr_dce_status & MMR_DCE_STATUS_TX_BUSY) ? "transmitter on," : "",
  1006. (m.mmr_dce_status & MMR_DCE_STATUS_JBR_EXPIRED) ?
  1007. "jabber timer expired," : "");
  1008. printk(KERN_DEBUG "Dsp ID: %02X\n",
  1009. m.mmr_dsp_id);
  1010. #ifdef DEBUG_SHOW_UNUSED
  1011. printk(KERN_DEBUG "mmc_unused2[]: %02X:%02X\n",
  1012. m.mmr_unused2[0],
  1013. m.mmr_unused2[1]);
  1014. #endif /* DEBUG_SHOW_UNUSED */
  1015. printk(KERN_DEBUG "# correct_nwid: %d, # wrong_nwid: %d\n",
  1016. (m.mmr_correct_nwid_h << 8) | m.mmr_correct_nwid_l,
  1017. (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l);
  1018. printk(KERN_DEBUG "thr_pre_set: 0x%x [current signal %s]\n",
  1019. m.mmr_thr_pre_set & MMR_THR_PRE_SET,
  1020. (m.mmr_thr_pre_set & MMR_THR_PRE_SET_CUR) ? "above" : "below");
  1021. printk(KERN_DEBUG "signal_lvl: %d [%s], ",
  1022. m.mmr_signal_lvl & MMR_SIGNAL_LVL,
  1023. (m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) ? "new msg" : "no new msg");
  1024. printk("silence_lvl: %d [%s], ", m.mmr_silence_lvl & MMR_SILENCE_LVL,
  1025. (m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) ? "update done" : "no new update");
  1026. printk("sgnl_qual: 0x%x [%s]\n", m.mmr_sgnl_qual & MMR_SGNL_QUAL,
  1027. (m.mmr_sgnl_qual & MMR_SGNL_QUAL_ANT) ? "Antenna 1" : "Antenna 0");
  1028. #ifdef DEBUG_SHOW_UNUSED
  1029. printk(KERN_DEBUG "netw_id_l: %x\n", m.mmr_netw_id_l);
  1030. #endif /* DEBUG_SHOW_UNUSED */
  1031. } /* wv_mmc_show */
  1032. #endif /* DEBUG_MMC_SHOW */
  1033. #ifdef DEBUG_I82593_SHOW
  1034. /*------------------------------------------------------------------*/
  1035. /*
  1036. * Print the formatted status of the i82593's receive unit.
  1037. */
  1038. static void
  1039. wv_ru_show(struct net_device * dev)
  1040. {
  1041. net_local *lp = netdev_priv(dev);
  1042. printk(KERN_DEBUG "##### wavelan i82593 receiver status: #####\n");
  1043. printk(KERN_DEBUG "ru: rfp %d stop %d", lp->rfp, lp->stop);
  1044. /*
  1045. * Not implemented yet...
  1046. */
  1047. printk("\n");
  1048. } /* wv_ru_show */
  1049. #endif /* DEBUG_I82593_SHOW */
  1050. #ifdef DEBUG_DEVICE_SHOW
  1051. /*------------------------------------------------------------------*/
  1052. /*
  1053. * Print the formatted status of the WaveLAN PCMCIA device driver.
  1054. */
  1055. static void
  1056. wv_dev_show(struct net_device * dev)
  1057. {
  1058. printk(KERN_DEBUG "dev:");
  1059. printk(" state=%lX,", dev->state);
  1060. printk(" trans_start=%ld,", dev->trans_start);
  1061. printk(" flags=0x%x,", dev->flags);
  1062. printk("\n");
  1063. } /* wv_dev_show */
  1064. /*------------------------------------------------------------------*/
  1065. /*
  1066. * Print the formatted status of the WaveLAN PCMCIA device driver's
  1067. * private information.
  1068. */
  1069. static void
  1070. wv_local_show(struct net_device * dev)
  1071. {
  1072. net_local *lp = netdev_priv(dev);
  1073. printk(KERN_DEBUG "local:");
  1074. /*
  1075. * Not implemented yet...
  1076. */
  1077. printk("\n");
  1078. } /* wv_local_show */
  1079. #endif /* DEBUG_DEVICE_SHOW */
  1080. #if defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO)
  1081. /*------------------------------------------------------------------*/
  1082. /*
  1083. * Dump packet header (and content if necessary) on the screen
  1084. */
  1085. static inline void
  1086. wv_packet_info(u_char * p, /* Packet to dump */
  1087. int length, /* Length of the packet */
  1088. char * msg1, /* Name of the device */
  1089. char * msg2) /* Name of the function */
  1090. {
  1091. int i;
  1092. int maxi;
  1093. DECLARE_MAC_BUF(mac);
  1094. printk(KERN_DEBUG "%s: %s(): dest %s, length %d\n",
  1095. msg1, msg2, print_mac(mac, p), length);
  1096. printk(KERN_DEBUG "%s: %s(): src %s, type 0x%02X%02X\n",
  1097. msg1, msg2, print_mac(mac, &p[6]), p[12], p[13]);
  1098. #ifdef DEBUG_PACKET_DUMP
  1099. printk(KERN_DEBUG "data=\"");
  1100. if((maxi = length) > DEBUG_PACKET_DUMP)
  1101. maxi = DEBUG_PACKET_DUMP;
  1102. for(i = 14; i < maxi; i++)
  1103. if(p[i] >= ' ' && p[i] <= '~')
  1104. printk(" %c", p[i]);
  1105. else
  1106. printk("%02X", p[i]);
  1107. if(maxi < length)
  1108. printk("..");
  1109. printk("\"\n");
  1110. printk(KERN_DEBUG "\n");
  1111. #endif /* DEBUG_PACKET_DUMP */
  1112. }
  1113. #endif /* defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) */
  1114. /*------------------------------------------------------------------*/
  1115. /*
  1116. * This is the information which is displayed by the driver at startup
  1117. * There is a lot of flag to configure it at your will...
  1118. */
  1119. static inline void
  1120. wv_init_info(struct net_device * dev)
  1121. {
  1122. kio_addr_t base = dev->base_addr;
  1123. psa_t psa;
  1124. DECLARE_MAC_BUF(mac);
  1125. /* Read the parameter storage area */
  1126. psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
  1127. #ifdef DEBUG_PSA_SHOW
  1128. wv_psa_show(&psa);
  1129. #endif
  1130. #ifdef DEBUG_MMC_SHOW
  1131. wv_mmc_show(dev);
  1132. #endif
  1133. #ifdef DEBUG_I82593_SHOW
  1134. wv_ru_show(dev);
  1135. #endif
  1136. #ifdef DEBUG_BASIC_SHOW
  1137. /* Now, let's go for the basic stuff */
  1138. printk(KERN_NOTICE "%s: WaveLAN: port %#lx, irq %d, "
  1139. "hw_addr %s",
  1140. dev->name, base, dev->irq,
  1141. print_mac(mac, dev->dev_addr));
  1142. /* Print current network id */
  1143. if(psa.psa_nwid_select)
  1144. printk(", nwid 0x%02X-%02X", psa.psa_nwid[0], psa.psa_nwid[1]);
  1145. else
  1146. printk(", nwid off");
  1147. /* If 2.00 card */
  1148. if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
  1149. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
  1150. {
  1151. unsigned short freq;
  1152. /* Ask the EEprom to read the frequency from the first area */
  1153. fee_read(base, 0x00 /* 1st area - frequency... */,
  1154. &freq, 1);
  1155. /* Print frequency */
  1156. printk(", 2.00, %ld", (freq >> 6) + 2400L);
  1157. /* Hack !!! */
  1158. if(freq & 0x20)
  1159. printk(".5");
  1160. }
  1161. else
  1162. {
  1163. printk(", PCMCIA, ");
  1164. switch (psa.psa_subband)
  1165. {
  1166. case PSA_SUBBAND_915:
  1167. printk("915");
  1168. break;
  1169. case PSA_SUBBAND_2425:
  1170. printk("2425");
  1171. break;
  1172. case PSA_SUBBAND_2460:
  1173. printk("2460");
  1174. break;
  1175. case PSA_SUBBAND_2484:
  1176. printk("2484");
  1177. break;
  1178. case PSA_SUBBAND_2430_5:
  1179. printk("2430.5");
  1180. break;
  1181. default:
  1182. printk("unknown");
  1183. }
  1184. }
  1185. printk(" MHz\n");
  1186. #endif /* DEBUG_BASIC_SHOW */
  1187. #ifdef DEBUG_VERSION_SHOW
  1188. /* Print version information */
  1189. printk(KERN_NOTICE "%s", version);
  1190. #endif
  1191. } /* wv_init_info */
  1192. /********************* IOCTL, STATS & RECONFIG *********************/
  1193. /*
  1194. * We found here routines that are called by Linux on differents
  1195. * occasions after the configuration and not for transmitting data
  1196. * These may be called when the user use ifconfig, /proc/net/dev
  1197. * or wireless extensions
  1198. */
  1199. /*------------------------------------------------------------------*/
  1200. /*
  1201. * Get the current ethernet statistics. This may be called with the
  1202. * card open or closed.
  1203. * Used when the user read /proc/net/dev
  1204. */
  1205. static en_stats *
  1206. wavelan_get_stats(struct net_device * dev)
  1207. {
  1208. #ifdef DEBUG_IOCTL_TRACE
  1209. printk(KERN_DEBUG "%s: <>wavelan_get_stats()\n", dev->name);
  1210. #endif
  1211. return(&((net_local *)netdev_priv(dev))->stats);
  1212. }
  1213. /*------------------------------------------------------------------*/
  1214. /*
  1215. * Set or clear the multicast filter for this adaptor.
  1216. * num_addrs == -1 Promiscuous mode, receive all packets
  1217. * num_addrs == 0 Normal mode, clear multicast list
  1218. * num_addrs > 0 Multicast mode, receive normal and MC packets,
  1219. * and do best-effort filtering.
  1220. */
  1221. static void
  1222. wavelan_set_multicast_list(struct net_device * dev)
  1223. {
  1224. net_local * lp = netdev_priv(dev);
  1225. #ifdef DEBUG_IOCTL_TRACE
  1226. printk(KERN_DEBUG "%s: ->wavelan_set_multicast_list()\n", dev->name);
  1227. #endif
  1228. #ifdef DEBUG_IOCTL_INFO
  1229. printk(KERN_DEBUG "%s: wavelan_set_multicast_list(): setting Rx mode %02X to %d addresses.\n",
  1230. dev->name, dev->flags, dev->mc_count);
  1231. #endif
  1232. if(dev->flags & IFF_PROMISC)
  1233. {
  1234. /*
  1235. * Enable promiscuous mode: receive all packets.
  1236. */
  1237. if(!lp->promiscuous)
  1238. {
  1239. lp->promiscuous = 1;
  1240. lp->allmulticast = 0;
  1241. lp->mc_count = 0;
  1242. wv_82593_reconfig(dev);
  1243. /* Tell the kernel that we are doing a really bad job... */
  1244. dev->flags |= IFF_PROMISC;
  1245. }
  1246. }
  1247. else
  1248. /* If all multicast addresses
  1249. * or too much multicast addresses for the hardware filter */
  1250. if((dev->flags & IFF_ALLMULTI) ||
  1251. (dev->mc_count > I82593_MAX_MULTICAST_ADDRESSES))
  1252. {
  1253. /*
  1254. * Disable promiscuous mode, but active the all multicast mode
  1255. */
  1256. if(!lp->allmulticast)
  1257. {
  1258. lp->promiscuous = 0;
  1259. lp->allmulticast = 1;
  1260. lp->mc_count = 0;
  1261. wv_82593_reconfig(dev);
  1262. /* Tell the kernel that we are doing a really bad job... */
  1263. dev->flags |= IFF_ALLMULTI;
  1264. }
  1265. }
  1266. else
  1267. /* If there is some multicast addresses to send */
  1268. if(dev->mc_list != (struct dev_mc_list *) NULL)
  1269. {
  1270. /*
  1271. * Disable promiscuous mode, but receive all packets
  1272. * in multicast list
  1273. */
  1274. #ifdef MULTICAST_AVOID
  1275. if(lp->promiscuous || lp->allmulticast ||
  1276. (dev->mc_count != lp->mc_count))
  1277. #endif
  1278. {
  1279. lp->promiscuous = 0;
  1280. lp->allmulticast = 0;
  1281. lp->mc_count = dev->mc_count;
  1282. wv_82593_reconfig(dev);
  1283. }
  1284. }
  1285. else
  1286. {
  1287. /*
  1288. * Switch to normal mode: disable promiscuous mode and
  1289. * clear the multicast list.
  1290. */
  1291. if(lp->promiscuous || lp->mc_count == 0)
  1292. {
  1293. lp->promiscuous = 0;
  1294. lp->allmulticast = 0;
  1295. lp->mc_count = 0;
  1296. wv_82593_reconfig(dev);
  1297. }
  1298. }
  1299. #ifdef DEBUG_IOCTL_TRACE
  1300. printk(KERN_DEBUG "%s: <-wavelan_set_multicast_list()\n", dev->name);
  1301. #endif
  1302. }
  1303. /*------------------------------------------------------------------*/
  1304. /*
  1305. * This function doesn't exist...
  1306. * (Note : it was a nice way to test the reconfigure stuff...)
  1307. */
  1308. #ifdef SET_MAC_ADDRESS
  1309. static int
  1310. wavelan_set_mac_address(struct net_device * dev,
  1311. void * addr)
  1312. {
  1313. struct sockaddr * mac = addr;
  1314. /* Copy the address */
  1315. memcpy(dev->dev_addr, mac->sa_data, WAVELAN_ADDR_SIZE);
  1316. /* Reconfig the beast */
  1317. wv_82593_reconfig(dev);
  1318. return 0;
  1319. }
  1320. #endif /* SET_MAC_ADDRESS */
  1321. /*------------------------------------------------------------------*/
  1322. /*
  1323. * Frequency setting (for hardware able of it)
  1324. * It's a bit complicated and you don't really want to look into it...
  1325. */
  1326. static inline int
  1327. wv_set_frequency(u_long base, /* i/o port of the card */
  1328. iw_freq * frequency)
  1329. {
  1330. const int BAND_NUM = 10; /* Number of bands */
  1331. long freq = 0L; /* offset to 2.4 GHz in .5 MHz */
  1332. #ifdef DEBUG_IOCTL_INFO
  1333. int i;
  1334. #endif
  1335. /* Setting by frequency */
  1336. /* Theoritically, you may set any frequency between
  1337. * the two limits with a 0.5 MHz precision. In practice,
  1338. * I don't want you to have trouble with local
  1339. * regulations... */
  1340. if((frequency->e == 1) &&
  1341. (frequency->m >= (int) 2.412e8) && (frequency->m <= (int) 2.487e8))
  1342. {
  1343. freq = ((frequency->m / 10000) - 24000L) / 5;
  1344. }
  1345. /* Setting by channel (same as wfreqsel) */
  1346. /* Warning : each channel is 22MHz wide, so some of the channels
  1347. * will interfere... */
  1348. if((frequency->e == 0) &&
  1349. (frequency->m >= 0) && (frequency->m < BAND_NUM))
  1350. {
  1351. /* Get frequency offset. */
  1352. freq = channel_bands[frequency->m] >> 1;
  1353. }
  1354. /* Verify if the frequency is allowed */
  1355. if(freq != 0L)
  1356. {
  1357. u_short table[10]; /* Authorized frequency table */
  1358. /* Read the frequency table */
  1359. fee_read(base, 0x71 /* frequency table */,
  1360. table, 10);
  1361. #ifdef DEBUG_IOCTL_INFO
  1362. printk(KERN_DEBUG "Frequency table :");
  1363. for(i = 0; i < 10; i++)
  1364. {
  1365. printk(" %04X",
  1366. table[i]);
  1367. }
  1368. printk("\n");
  1369. #endif
  1370. /* Look in the table if the frequency is allowed */
  1371. if(!(table[9 - ((freq - 24) / 16)] &
  1372. (1 << ((freq - 24) % 16))))
  1373. return -EINVAL; /* not allowed */
  1374. }
  1375. else
  1376. return -EINVAL;
  1377. /* If we get a usable frequency */
  1378. if(freq != 0L)
  1379. {
  1380. unsigned short area[16];
  1381. unsigned short dac[2];
  1382. unsigned short area_verify[16];
  1383. unsigned short dac_verify[2];
  1384. /* Corresponding gain (in the power adjust value table)
  1385. * see AT&T Wavelan Data Manual, REF 407-024689/E, page 3-8
  1386. * & WCIN062D.DOC, page 6.2.9 */
  1387. unsigned short power_limit[] = { 40, 80, 120, 160, 0 };
  1388. int power_band = 0; /* Selected band */
  1389. unsigned short power_adjust; /* Correct value */
  1390. /* Search for the gain */
  1391. power_band = 0;
  1392. while((freq > power_limit[power_band]) &&
  1393. (power_limit[++power_band] != 0))
  1394. ;
  1395. /* Read the first area */
  1396. fee_read(base, 0x00,
  1397. area, 16);
  1398. /* Read the DAC */
  1399. fee_read(base, 0x60,
  1400. dac, 2);
  1401. /* Read the new power adjust value */
  1402. fee_read(base, 0x6B - (power_band >> 1),
  1403. &power_adjust, 1);
  1404. if(power_band & 0x1)
  1405. power_adjust >>= 8;
  1406. else
  1407. power_adjust &= 0xFF;
  1408. #ifdef DEBUG_IOCTL_INFO
  1409. printk(KERN_DEBUG "Wavelan EEprom Area 1 :");
  1410. for(i = 0; i < 16; i++)
  1411. {
  1412. printk(" %04X",
  1413. area[i]);
  1414. }
  1415. printk("\n");
  1416. printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n",
  1417. dac[0], dac[1]);
  1418. #endif
  1419. /* Frequency offset (for info only...) */
  1420. area[0] = ((freq << 5) & 0xFFE0) | (area[0] & 0x1F);
  1421. /* Receiver Principle main divider coefficient */
  1422. area[3] = (freq >> 1) + 2400L - 352L;
  1423. area[2] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
  1424. /* Transmitter Main divider coefficient */
  1425. area[13] = (freq >> 1) + 2400L;
  1426. area[12] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
  1427. /* Others part of the area are flags, bit streams or unused... */
  1428. /* Set the value in the DAC */
  1429. dac[1] = ((power_adjust >> 1) & 0x7F) | (dac[1] & 0xFF80);
  1430. dac[0] = ((power_adjust & 0x1) << 4) | (dac[0] & 0xFFEF);
  1431. /* Write the first area */
  1432. fee_write(base, 0x00,
  1433. area, 16);
  1434. /* Write the DAC */
  1435. fee_write(base, 0x60,
  1436. dac, 2);
  1437. /* We now should verify here that the EEprom writing was ok */
  1438. /* ReRead the first area */
  1439. fee_read(base, 0x00,
  1440. area_verify, 16);
  1441. /* ReRead the DAC */
  1442. fee_read(base, 0x60,
  1443. dac_verify, 2);
  1444. /* Compare */
  1445. if(memcmp(area, area_verify, 16 * 2) ||
  1446. memcmp(dac, dac_verify, 2 * 2))
  1447. {
  1448. #ifdef DEBUG_IOCTL_ERROR
  1449. printk(KERN_INFO "Wavelan: wv_set_frequency : unable to write new frequency to EEprom (?)\n");
  1450. #endif
  1451. return -EOPNOTSUPP;
  1452. }
  1453. /* We must download the frequency parameters to the
  1454. * synthetisers (from the EEprom - area 1)
  1455. * Note : as the EEprom is auto decremented, we set the end
  1456. * if the area... */
  1457. mmc_out(base, mmwoff(0, mmw_fee_addr), 0x0F);
  1458. mmc_out(base, mmwoff(0, mmw_fee_ctrl),
  1459. MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
  1460. /* Wait until the download is finished */
  1461. fee_wait(base, 100, 100);
  1462. /* We must now download the power adjust value (gain) to
  1463. * the synthetisers (from the EEprom - area 7 - DAC) */
  1464. mmc_out(base, mmwoff(0, mmw_fee_addr), 0x61);
  1465. mmc_out(base, mmwoff(0, mmw_fee_ctrl),
  1466. MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
  1467. /* Wait until the download is finished */
  1468. fee_wait(base, 100, 100);
  1469. #ifdef DEBUG_IOCTL_INFO
  1470. /* Verification of what we have done... */
  1471. printk(KERN_DEBUG "Wavelan EEprom Area 1 :");
  1472. for(i = 0; i < 16; i++)
  1473. {
  1474. printk(" %04X",
  1475. area_verify[i]);
  1476. }
  1477. printk("\n");
  1478. printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n",
  1479. dac_verify[0], dac_verify[1]);
  1480. #endif
  1481. return 0;
  1482. }
  1483. else
  1484. return -EINVAL; /* Bah, never get there... */
  1485. }
  1486. /*------------------------------------------------------------------*/
  1487. /*
  1488. * Give the list of available frequencies
  1489. */
  1490. static inline int
  1491. wv_frequency_list(u_long base, /* i/o port of the card */
  1492. iw_freq * list, /* List of frequency to fill */
  1493. int max) /* Maximum number of frequencies */
  1494. {
  1495. u_short table[10]; /* Authorized frequency table */
  1496. long freq = 0L; /* offset to 2.4 GHz in .5 MHz + 12 MHz */
  1497. int i; /* index in the table */
  1498. const int BAND_NUM = 10; /* Number of bands */
  1499. int c = 0; /* Channel number */
  1500. /* Read the frequency table */
  1501. fee_read(base, 0x71 /* frequency table */,
  1502. table, 10);
  1503. /* Look all frequencies */
  1504. i = 0;
  1505. for(freq = 0; freq < 150; freq++)
  1506. /* Look in the table if the frequency is allowed */
  1507. if(table[9 - (freq / 16)] & (1 << (freq % 16)))
  1508. {
  1509. /* Compute approximate channel number */
  1510. while((((channel_bands[c] >> 1) - 24) < freq) &&
  1511. (c < BAND_NUM))
  1512. c++;
  1513. list[i].i = c; /* Set the list index */
  1514. /* put in the list */
  1515. list[i].m = (((freq + 24) * 5) + 24000L) * 10000;
  1516. list[i++].e = 1;
  1517. /* Check number */
  1518. if(i >= max)
  1519. return(i);
  1520. }
  1521. return(i);
  1522. }
  1523. #ifdef IW_WIRELESS_SPY
  1524. /*------------------------------------------------------------------*/
  1525. /*
  1526. * Gather wireless spy statistics : for each packet, compare the source
  1527. * address with out list, and if match, get the stats...
  1528. * Sorry, but this function really need wireless extensions...
  1529. */
  1530. static inline void
  1531. wl_spy_gather(struct net_device * dev,
  1532. u_char * mac, /* MAC address */
  1533. u_char * stats) /* Statistics to gather */
  1534. {
  1535. struct iw_quality wstats;
  1536. wstats.qual = stats[2] & MMR_SGNL_QUAL;
  1537. wstats.level = stats[0] & MMR_SIGNAL_LVL;
  1538. wstats.noise = stats[1] & MMR_SILENCE_LVL;
  1539. wstats.updated = 0x7;
  1540. /* Update spy records */
  1541. wireless_spy_update(dev, mac, &wstats);
  1542. }
  1543. #endif /* IW_WIRELESS_SPY */
  1544. #ifdef HISTOGRAM
  1545. /*------------------------------------------------------------------*/
  1546. /*
  1547. * This function calculate an histogram on the signal level.
  1548. * As the noise is quite constant, it's like doing it on the SNR.
  1549. * We have defined a set of interval (lp->his_range), and each time
  1550. * the level goes in that interval, we increment the count (lp->his_sum).
  1551. * With this histogram you may detect if one wavelan is really weak,
  1552. * or you may also calculate the mean and standard deviation of the level...
  1553. */
  1554. static inline void
  1555. wl_his_gather(struct net_device * dev,
  1556. u_char * stats) /* Statistics to gather */
  1557. {
  1558. net_local * lp = netdev_priv(dev);
  1559. u_char level = stats[0] & MMR_SIGNAL_LVL;
  1560. int i;
  1561. /* Find the correct interval */
  1562. i = 0;
  1563. while((i < (lp->his_number - 1)) && (level >= lp->his_range[i++]))
  1564. ;
  1565. /* Increment interval counter */
  1566. (lp->his_sum[i])++;
  1567. }
  1568. #endif /* HISTOGRAM */
  1569. static void wl_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  1570. {
  1571. strncpy(info->driver, "wavelan_cs", sizeof(info->driver)-1);
  1572. }
  1573. static const struct ethtool_ops ops = {
  1574. .get_drvinfo = wl_get_drvinfo
  1575. };
  1576. /*------------------------------------------------------------------*/
  1577. /*
  1578. * Wireless Handler : get protocol name
  1579. */
  1580. static int wavelan_get_name(struct net_device *dev,
  1581. struct iw_request_info *info,
  1582. union iwreq_data *wrqu,
  1583. char *extra)
  1584. {
  1585. strcpy(wrqu->name, "WaveLAN");
  1586. return 0;
  1587. }
  1588. /*------------------------------------------------------------------*/
  1589. /*
  1590. * Wireless Handler : set NWID
  1591. */
  1592. static int wavelan_set_nwid(struct net_device *dev,
  1593. struct iw_request_info *info,
  1594. union iwreq_data *wrqu,
  1595. char *extra)
  1596. {
  1597. kio_addr_t base = dev->base_addr;
  1598. net_local *lp = netdev_priv(dev);
  1599. psa_t psa;
  1600. mm_t m;
  1601. unsigned long flags;
  1602. int ret = 0;
  1603. /* Disable interrupts and save flags. */
  1604. spin_lock_irqsave(&lp->spinlock, flags);
  1605. /* Set NWID in WaveLAN. */
  1606. if (!wrqu->nwid.disabled) {
  1607. /* Set NWID in psa */
  1608. psa.psa_nwid[0] = (wrqu->nwid.value & 0xFF00) >> 8;
  1609. psa.psa_nwid[1] = wrqu->nwid.value & 0xFF;
  1610. psa.psa_nwid_select = 0x01;
  1611. psa_write(dev,
  1612. (char *) psa.psa_nwid - (char *) &psa,
  1613. (unsigned char *) psa.psa_nwid, 3);
  1614. /* Set NWID in mmc. */
  1615. m.w.mmw_netw_id_l = psa.psa_nwid[1];
  1616. m.w.mmw_netw_id_h = psa.psa_nwid[0];
  1617. mmc_write(base,
  1618. (char *) &m.w.mmw_netw_id_l -
  1619. (char *) &m,
  1620. (unsigned char *) &m.w.mmw_netw_id_l, 2);
  1621. mmc_out(base, mmwoff(0, mmw_loopt_sel), 0x00);
  1622. } else {
  1623. /* Disable NWID in the psa. */
  1624. psa.psa_nwid_select = 0x00;
  1625. psa_write(dev,
  1626. (char *) &psa.psa_nwid_select -
  1627. (char *) &psa,
  1628. (unsigned char *) &psa.psa_nwid_select,
  1629. 1);
  1630. /* Disable NWID in the mmc (no filtering). */
  1631. mmc_out(base, mmwoff(0, mmw_loopt_sel),
  1632. MMW_LOOPT_SEL_DIS_NWID);
  1633. }
  1634. /* update the Wavelan checksum */
  1635. update_psa_checksum(dev);
  1636. /* Enable interrupts and restore flags. */
  1637. spin_unlock_irqrestore(&lp->spinlock, flags);
  1638. return ret;
  1639. }
  1640. /*------------------------------------------------------------------*/
  1641. /*
  1642. * Wireless Handler : get NWID
  1643. */
  1644. static int wavelan_get_nwid(struct net_device *dev,
  1645. struct iw_request_info *info,
  1646. union iwreq_data *wrqu,
  1647. char *extra)
  1648. {
  1649. net_local *lp = netdev_priv(dev);
  1650. psa_t psa;
  1651. unsigned long flags;
  1652. int ret = 0;
  1653. /* Disable interrupts and save flags. */
  1654. spin_lock_irqsave(&lp->spinlock, flags);
  1655. /* Read the NWID. */
  1656. psa_read(dev,
  1657. (char *) psa.psa_nwid - (char *) &psa,
  1658. (unsigned char *) psa.psa_nwid, 3);
  1659. wrqu->nwid.value = (psa.psa_nwid[0] << 8) + psa.psa_nwid[1];
  1660. wrqu->nwid.disabled = !(psa.psa_nwid_select);
  1661. wrqu->nwid.fixed = 1; /* Superfluous */
  1662. /* Enable interrupts and restore flags. */
  1663. spin_unlock_irqrestore(&lp->spinlock, flags);
  1664. return ret;
  1665. }
  1666. /*------------------------------------------------------------------*/
  1667. /*
  1668. * Wireless Handler : set frequency
  1669. */
  1670. static int wavelan_set_freq(struct net_device *dev,
  1671. struct iw_request_info *info,
  1672. union iwreq_data *wrqu,
  1673. char *extra)
  1674. {
  1675. kio_addr_t base = dev->base_addr;
  1676. net_local *lp = netdev_priv(dev);
  1677. unsigned long flags;
  1678. int ret;
  1679. /* Disable interrupts and save flags. */
  1680. spin_lock_irqsave(&lp->spinlock, flags);
  1681. /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
  1682. if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
  1683. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
  1684. ret = wv_set_frequency(base, &(wrqu->freq));
  1685. else
  1686. ret = -EOPNOTSUPP;
  1687. /* Enable interrupts and restore flags. */
  1688. spin_unlock_irqrestore(&lp->spinlock, flags);
  1689. return ret;
  1690. }
  1691. /*------------------------------------------------------------------*/
  1692. /*
  1693. * Wireless Handler : get frequency
  1694. */
  1695. static int wavelan_get_freq(struct net_device *dev,
  1696. struct iw_request_info *info,
  1697. union iwreq_data *wrqu,
  1698. char *extra)
  1699. {
  1700. kio_addr_t base = dev->base_addr;
  1701. net_local *lp = netdev_priv(dev);
  1702. psa_t psa;
  1703. unsigned long flags;
  1704. int ret = 0;
  1705. /* Disable interrupts and save flags. */
  1706. spin_lock_irqsave(&lp->spinlock, flags);
  1707. /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable).
  1708. * Does it work for everybody, especially old cards? */
  1709. if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
  1710. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
  1711. unsigned short freq;
  1712. /* Ask the EEPROM to read the frequency from the first area. */
  1713. fee_read(base, 0x00, &freq, 1);
  1714. wrqu->freq.m = ((freq >> 5) * 5 + 24000L) * 10000;
  1715. wrqu->freq.e = 1;
  1716. } else {
  1717. psa_read(dev,
  1718. (char *) &psa.psa_subband - (char *) &psa,
  1719. (unsigned char *) &psa.psa_subband, 1);
  1720. if (psa.psa_subband <= 4) {
  1721. wrqu->freq.m = fixed_bands[psa.psa_subband];
  1722. wrqu->freq.e = (psa.psa_subband != 0);
  1723. } else
  1724. ret = -EOPNOTSUPP;
  1725. }
  1726. /* Enable interrupts and restore flags. */
  1727. spin_unlock_irqrestore(&lp->spinlock, flags);
  1728. return ret;
  1729. }
  1730. /*------------------------------------------------------------------*/
  1731. /*
  1732. * Wireless Handler : set level threshold
  1733. */
  1734. static int wavelan_set_sens(struct net_device *dev,
  1735. struct iw_request_info *info,
  1736. union iwreq_data *wrqu,
  1737. char *extra)
  1738. {
  1739. kio_addr_t base = dev->base_addr;
  1740. net_local *lp = netdev_priv(dev);
  1741. psa_t psa;
  1742. unsigned long flags;
  1743. int ret = 0;
  1744. /* Disable interrupts and save flags. */
  1745. spin_lock_irqsave(&lp->spinlock, flags);
  1746. /* Set the level threshold. */
  1747. /* We should complain loudly if wrqu->sens.fixed = 0, because we
  1748. * can't set auto mode... */
  1749. psa.psa_thr_pre_set = wrqu->sens.value & 0x3F;
  1750. psa_write(dev,
  1751. (char *) &psa.psa_thr_pre_set - (char *) &psa,
  1752. (unsigned char *) &psa.psa_thr_pre_set, 1);
  1753. /* update the Wavelan checksum */
  1754. update_psa_checksum(dev);
  1755. mmc_out(base, mmwoff(0, mmw_thr_pre_set),
  1756. psa.psa_thr_pre_set);
  1757. /* Enable interrupts and restore flags. */
  1758. spin_unlock_irqrestore(&lp->spinlock, flags);
  1759. return ret;
  1760. }
  1761. /*------------------------------------------------------------------*/
  1762. /*
  1763. * Wireless Handler : get level threshold
  1764. */
  1765. static int wavelan_get_sens(struct net_device *dev,
  1766. struct iw_request_info *info,
  1767. union iwreq_data *wrqu,
  1768. char *extra)
  1769. {
  1770. net_local *lp = netdev_priv(dev);
  1771. psa_t psa;
  1772. unsigned long flags;
  1773. int ret = 0;
  1774. /* Disable interrupts and save flags. */
  1775. spin_lock_irqsave(&lp->spinlock, flags);
  1776. /* Read the level threshold. */
  1777. psa_read(dev,
  1778. (char *) &psa.psa_thr_pre_set - (char *) &psa,
  1779. (unsigned char *) &psa.psa_thr_pre_set, 1);
  1780. wrqu->sens.value = psa.psa_thr_pre_set & 0x3F;
  1781. wrqu->sens.fixed = 1;
  1782. /* Enable interrupts and restore flags. */
  1783. spin_unlock_irqrestore(&lp->spinlock, flags);
  1784. return ret;
  1785. }
  1786. /*------------------------------------------------------------------*/
  1787. /*
  1788. * Wireless Handler : set encryption key
  1789. */
  1790. static int wavelan_set_encode(struct net_device *dev,
  1791. struct iw_request_info *info,
  1792. union iwreq_data *wrqu,
  1793. char *extra)
  1794. {
  1795. kio_addr_t base = dev->base_addr;
  1796. net_local *lp = netdev_priv(dev);
  1797. unsigned long flags;
  1798. psa_t psa;
  1799. int ret = 0;
  1800. /* Disable interrupts and save flags. */
  1801. spin_lock_irqsave(&lp->spinlock, flags);
  1802. /* Check if capable of encryption */
  1803. if (!mmc_encr(base)) {
  1804. ret = -EOPNOTSUPP;
  1805. }
  1806. /* Check the size of the key */
  1807. if((wrqu->encoding.length != 8) && (wrqu->encoding.length != 0)) {
  1808. ret = -EINVAL;
  1809. }
  1810. if(!ret) {
  1811. /* Basic checking... */
  1812. if (wrqu->encoding.length == 8) {
  1813. /* Copy the key in the driver */
  1814. memcpy(psa.psa_encryption_key, extra,
  1815. wrqu->encoding.length);
  1816. psa.psa_encryption_select = 1;
  1817. psa_write(dev,
  1818. (char *) &psa.psa_encryption_select -
  1819. (char *) &psa,
  1820. (unsigned char *) &psa.
  1821. psa_encryption_select, 8 + 1);
  1822. mmc_out(base, mmwoff(0, mmw_encr_enable),
  1823. MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE);
  1824. mmc_write(base, mmwoff(0, mmw_encr_key),
  1825. (unsigned char *) &psa.
  1826. psa_encryption_key, 8);
  1827. }
  1828. /* disable encryption */
  1829. if (wrqu->encoding.flags & IW_ENCODE_DISABLED) {
  1830. psa.psa_encryption_select = 0;
  1831. psa_write(dev,
  1832. (char *) &psa.psa_encryption_select -
  1833. (char *) &psa,
  1834. (unsigned char *) &psa.
  1835. psa_encryption_select, 1);
  1836. mmc_out(base, mmwoff(0, mmw_encr_enable), 0);
  1837. }
  1838. /* update the Wavelan checksum */
  1839. update_psa_checksum(dev);
  1840. }
  1841. /* Enable interrupts and restore flags. */
  1842. spin_unlock_irqrestore(&lp->spinlock, flags);
  1843. return ret;
  1844. }
  1845. /*------------------------------------------------------------------*/
  1846. /*
  1847. * Wireless Handler : get encryption key
  1848. */
  1849. static int wavelan_get_encode(struct net_device *dev,
  1850. struct iw_request_info *info,
  1851. union iwreq_data *wrqu,
  1852. char *extra)
  1853. {
  1854. kio_addr_t base = dev->base_addr;
  1855. net_local *lp = netdev_priv(dev);
  1856. psa_t psa;
  1857. unsigned long flags;
  1858. int ret = 0;
  1859. /* Disable interrupts and save flags. */
  1860. spin_lock_irqsave(&lp->spinlock, flags);
  1861. /* Check if encryption is available */
  1862. if (!mmc_encr(base)) {
  1863. ret = -EOPNOTSUPP;
  1864. } else {
  1865. /* Read the encryption key */
  1866. psa_read(dev,
  1867. (char *) &psa.psa_encryption_select -
  1868. (char *) &psa,
  1869. (unsigned char *) &psa.
  1870. psa_encryption_select, 1 + 8);
  1871. /* encryption is enabled ? */
  1872. if (psa.psa_encryption_select)
  1873. wrqu->encoding.flags = IW_ENCODE_ENABLED;
  1874. else
  1875. wrqu->encoding.flags = IW_ENCODE_DISABLED;
  1876. wrqu->encoding.flags |= mmc_encr(base);
  1877. /* Copy the key to the user buffer */
  1878. wrqu->encoding.length = 8;
  1879. memcpy(extra, psa.psa_encryption_key, wrqu->encoding.length);
  1880. }
  1881. /* Enable interrupts and restore flags. */
  1882. spin_unlock_irqrestore(&lp->spinlock, flags);
  1883. return ret;
  1884. }
  1885. #ifdef WAVELAN_ROAMING_EXT
  1886. /*------------------------------------------------------------------*/
  1887. /*
  1888. * Wireless Handler : set ESSID (domain)
  1889. */
  1890. static int wavelan_set_essid(struct net_device *dev,
  1891. struct iw_request_info *info,
  1892. union iwreq_data *wrqu,
  1893. char *extra)
  1894. {
  1895. net_local *lp = netdev_priv(dev);
  1896. unsigned long flags;
  1897. int ret = 0;
  1898. /* Disable interrupts and save flags. */
  1899. spin_lock_irqsave(&lp->spinlock, flags);
  1900. /* Check if disable */
  1901. if(wrqu->data.flags == 0)
  1902. lp->filter_domains = 0;
  1903. else {
  1904. char essid[IW_ESSID_MAX_SIZE + 1];
  1905. char * endp;
  1906. /* Terminate the string */
  1907. memcpy(essid, extra, wrqu->data.length);
  1908. essid[IW_ESSID_MAX_SIZE] = '\0';
  1909. #ifdef DEBUG_IOCTL_INFO
  1910. printk(KERN_DEBUG "SetEssid : ``%s''\n", essid);
  1911. #endif /* DEBUG_IOCTL_INFO */
  1912. /* Convert to a number (note : Wavelan specific) */
  1913. lp->domain_id = simple_strtoul(essid, &endp, 16);
  1914. /* Has it worked ? */
  1915. if(endp > essid)
  1916. lp->filter_domains = 1;
  1917. else {
  1918. lp->filter_domains = 0;
  1919. ret = -EINVAL;
  1920. }
  1921. }
  1922. /* Enable interrupts and restore flags. */
  1923. spin_unlock_irqrestore(&lp->spinlock, flags);
  1924. return ret;
  1925. }
  1926. /*------------------------------------------------------------------*/
  1927. /*
  1928. * Wireless Handler : get ESSID (domain)
  1929. */
  1930. static int wavelan_get_essid(struct net_device *dev,
  1931. struct iw_request_info *info,
  1932. union iwreq_data *wrqu,
  1933. char *extra)
  1934. {
  1935. net_local *lp = netdev_priv(dev);
  1936. /* Is the domain ID active ? */
  1937. wrqu->data.flags = lp->filter_domains;
  1938. /* Copy Domain ID into a string (Wavelan specific) */
  1939. /* Sound crazy, be we can't have a snprintf in the kernel !!! */
  1940. sprintf(extra, "%lX", lp->domain_id);
  1941. extra[IW_ESSID_MAX_SIZE] = '\0';
  1942. /* Set the length */
  1943. wrqu->data.length = strlen(extra);
  1944. return 0;
  1945. }
  1946. /*------------------------------------------------------------------*/
  1947. /*
  1948. * Wireless Handler : set AP address
  1949. */
  1950. static int wavelan_set_wap(struct net_device *dev,
  1951. struct iw_request_info *info,
  1952. union iwreq_data *wrqu,
  1953. char *extra)
  1954. {
  1955. #ifdef DEBUG_IOCTL_INFO
  1956. printk(KERN_DEBUG "Set AP to : %02X:%02X:%02X:%02X:%02X:%02X\n",
  1957. wrqu->ap_addr.sa_data[0],
  1958. wrqu->ap_addr.sa_data[1],
  1959. wrqu->ap_addr.sa_data[2],
  1960. wrqu->ap_addr.sa_data[3],
  1961. wrqu->ap_addr.sa_data[4],
  1962. wrqu->ap_addr.sa_data[5]);
  1963. #endif /* DEBUG_IOCTL_INFO */
  1964. return -EOPNOTSUPP;
  1965. }
  1966. /*------------------------------------------------------------------*/
  1967. /*
  1968. * Wireless Handler : get AP address
  1969. */
  1970. static int wavelan_get_wap(struct net_device *dev,
  1971. struct iw_request_info *info,
  1972. union iwreq_data *wrqu,
  1973. char *extra)
  1974. {
  1975. /* Should get the real McCoy instead of own Ethernet address */
  1976. memcpy(wrqu->ap_addr.sa_data, dev->dev_addr, WAVELAN_ADDR_SIZE);
  1977. wrqu->ap_addr.sa_family = ARPHRD_ETHER;
  1978. return -EOPNOTSUPP;
  1979. }
  1980. #endif /* WAVELAN_ROAMING_EXT */
  1981. #ifdef WAVELAN_ROAMING
  1982. /*------------------------------------------------------------------*/
  1983. /*
  1984. * Wireless Handler : set mode
  1985. */
  1986. static int wavelan_set_mode(struct net_device *dev,
  1987. struct iw_request_info *info,
  1988. union iwreq_data *wrqu,
  1989. char *extra)
  1990. {
  1991. net_local *lp = netdev_priv(dev);
  1992. unsigned long flags;
  1993. int ret = 0;
  1994. /* Disable interrupts and save flags. */
  1995. spin_lock_irqsave(&lp->spinlock, flags);
  1996. /* Check mode */
  1997. switch(wrqu->mode) {
  1998. case IW_MODE_ADHOC:
  1999. if(do_roaming) {
  2000. wv_roam_cleanup(dev);
  2001. do_roaming = 0;
  2002. }
  2003. break;
  2004. case IW_MODE_INFRA:
  2005. if(!do_roaming) {
  2006. wv_roam_init(dev);
  2007. do_roaming = 1;
  2008. }
  2009. break;
  2010. default:
  2011. ret = -EINVAL;
  2012. }
  2013. /* Enable interrupts and restore flags. */
  2014. spin_unlock_irqrestore(&lp->spinlock, flags);
  2015. return ret;
  2016. }
  2017. /*------------------------------------------------------------------*/
  2018. /*
  2019. * Wireless Handler : get mode
  2020. */
  2021. static int wavelan_get_mode(struct net_device *dev,
  2022. struct iw_request_info *info,
  2023. union iwreq_data *wrqu,
  2024. char *extra)
  2025. {
  2026. if(do_roaming)
  2027. wrqu->mode = IW_MODE_INFRA;
  2028. else
  2029. wrqu->mode = IW_MODE_ADHOC;
  2030. return 0;
  2031. }
  2032. #endif /* WAVELAN_ROAMING */
  2033. /*------------------------------------------------------------------*/
  2034. /*
  2035. * Wireless Handler : get range info
  2036. */
  2037. static int wavelan_get_range(struct net_device *dev,
  2038. struct iw_request_info *info,
  2039. union iwreq_data *wrqu,
  2040. char *extra)
  2041. {
  2042. kio_addr_t base = dev->base_addr;
  2043. net_local *lp = netdev_priv(dev);
  2044. struct iw_range *range = (struct iw_range *) extra;
  2045. unsigned long flags;
  2046. int ret = 0;
  2047. /* Set the length (very important for backward compatibility) */
  2048. wrqu->data.length = sizeof(struct iw_range);
  2049. /* Set all the info we don't care or don't know about to zero */
  2050. memset(range, 0, sizeof(struct iw_range));
  2051. /* Set the Wireless Extension versions */
  2052. range->we_version_compiled = WIRELESS_EXT;
  2053. range->we_version_source = 9;
  2054. /* Set information in the range struct. */
  2055. range->throughput = 1.4 * 1000 * 1000; /* don't argue on this ! */
  2056. range->min_nwid = 0x0000;
  2057. range->max_nwid = 0xFFFF;
  2058. range->sensitivity = 0x3F;
  2059. range->max_qual.qual = MMR_SGNL_QUAL;
  2060. range->max_qual.level = MMR_SIGNAL_LVL;
  2061. range->max_qual.noise = MMR_SILENCE_LVL;
  2062. range->avg_qual.qual = MMR_SGNL_QUAL; /* Always max */
  2063. /* Need to get better values for those two */
  2064. range->avg_qual.level = 30;
  2065. range->avg_qual.noise = 8;
  2066. range->num_bitrates = 1;
  2067. range->bitrate[0] = 2000000; /* 2 Mb/s */
  2068. /* Event capability (kernel + driver) */
  2069. range->event_capa[0] = (IW_EVENT_CAPA_MASK(0x8B02) |
  2070. IW_EVENT_CAPA_MASK(0x8B04) |
  2071. IW_EVENT_CAPA_MASK(0x8B06));
  2072. range->event_capa[1] = IW_EVENT_CAPA_K_1;
  2073. /* Disable interrupts and save flags. */
  2074. spin_lock_irqsave(&lp->spinlock, flags);
  2075. /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
  2076. if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
  2077. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
  2078. range->num_channels = 10;
  2079. range->num_frequency = wv_frequency_list(base, range->freq,
  2080. IW_MAX_FREQUENCIES);
  2081. } else
  2082. range->num_channels = range->num_frequency = 0;
  2083. /* Encryption supported ? */
  2084. if (mmc_encr(base)) {
  2085. range->encoding_size[0] = 8; /* DES = 64 bits key */
  2086. range->num_encoding_sizes = 1;
  2087. range->max_encoding_tokens = 1; /* Only one key possible */
  2088. } else {
  2089. range->num_encoding_sizes = 0;
  2090. range->max_encoding_tokens = 0;
  2091. }
  2092. /* Enable interrupts and restore flags. */
  2093. spin_unlock_irqrestore(&lp->spinlock, flags);
  2094. return ret;
  2095. }
  2096. /*------------------------------------------------------------------*/
  2097. /*
  2098. * Wireless Private Handler : set quality threshold
  2099. */
  2100. static int wavelan_set_qthr(struct net_device *dev,
  2101. struct iw_request_info *info,
  2102. union iwreq_data *wrqu,
  2103. char *extra)
  2104. {
  2105. kio_addr_t base = dev->base_addr;
  2106. net_local *lp = netdev_priv(dev);
  2107. psa_t psa;
  2108. unsigned long flags;
  2109. /* Disable interrupts and save flags. */
  2110. spin_lock_irqsave(&lp->spinlock, flags);
  2111. psa.psa_quality_thr = *(extra) & 0x0F;
  2112. psa_write(dev,
  2113. (char *) &psa.psa_quality_thr - (char *) &psa,
  2114. (unsigned char *) &psa.psa_quality_thr, 1);
  2115. /* update the Wavelan checksum */
  2116. update_psa_checksum(dev);
  2117. mmc_out(base, mmwoff(0, mmw_quality_thr),
  2118. psa.psa_quality_thr);
  2119. /* Enable interrupts and restore flags. */
  2120. spin_unlock_irqrestore(&lp->spinlock, flags);
  2121. return 0;
  2122. }
  2123. /*------------------------------------------------------------------*/
  2124. /*
  2125. * Wireless Private Handler : get quality threshold
  2126. */
  2127. static int wavelan_get_qthr(struct net_device *dev,
  2128. struct iw_request_info *info,
  2129. union iwreq_data *wrqu,
  2130. char *extra)
  2131. {
  2132. net_local *lp = netdev_priv(dev);
  2133. psa_t psa;
  2134. unsigned long flags;
  2135. /* Disable interrupts and save flags. */
  2136. spin_lock_irqsave(&lp->spinlock, flags);
  2137. psa_read(dev,
  2138. (char *) &psa.psa_quality_thr - (char *) &psa,
  2139. (unsigned char *) &psa.psa_quality_thr, 1);
  2140. *(extra) = psa.psa_quality_thr & 0x0F;
  2141. /* Enable interrupts and restore flags. */
  2142. spin_unlock_irqrestore(&lp->spinlock, flags);
  2143. return 0;
  2144. }
  2145. #ifdef WAVELAN_ROAMING
  2146. /*------------------------------------------------------------------*/
  2147. /*
  2148. * Wireless Private Handler : set roaming
  2149. */
  2150. static int wavelan_set_roam(struct net_device *dev,
  2151. struct iw_request_info *info,
  2152. union iwreq_data *wrqu,
  2153. char *extra)
  2154. {
  2155. net_local *lp = netdev_priv(dev);
  2156. unsigned long flags;
  2157. /* Disable interrupts and save flags. */
  2158. spin_lock_irqsave(&lp->spinlock, flags);
  2159. /* Note : should check if user == root */
  2160. if(do_roaming && (*extra)==0)
  2161. wv_roam_cleanup(dev);
  2162. else if(do_roaming==0 && (*extra)!=0)
  2163. wv_roam_init(dev);
  2164. do_roaming = (*extra);
  2165. /* Enable interrupts and restore flags. */
  2166. spin_unlock_irqrestore(&lp->spinlock, flags);
  2167. return 0;
  2168. }
  2169. /*------------------------------------------------------------------*/
  2170. /*
  2171. * Wireless Private Handler : get quality threshold
  2172. */
  2173. static int wavelan_get_roam(struct net_device *dev,
  2174. struct iw_request_info *info,
  2175. union iwreq_data *wrqu,
  2176. char *extra)
  2177. {
  2178. *(extra) = do_roaming;
  2179. return 0;
  2180. }
  2181. #endif /* WAVELAN_ROAMING */
  2182. #ifdef HISTOGRAM
  2183. /*------------------------------------------------------------------*/
  2184. /*
  2185. * Wireless Private Handler : set histogram
  2186. */
  2187. static int wavelan_set_histo(struct net_device *dev,
  2188. struct iw_request_info *info,
  2189. union iwreq_data *wrqu,
  2190. char *extra)
  2191. {
  2192. net_local *lp = netdev_priv(dev);
  2193. /* Check the number of intervals. */
  2194. if (wrqu->data.length > 16) {
  2195. return(-E2BIG);
  2196. }
  2197. /* Disable histo while we copy the addresses.
  2198. * As we don't disable interrupts, we need to do this */
  2199. lp->his_number = 0;
  2200. /* Are there ranges to copy? */
  2201. if (wrqu->data.length > 0) {
  2202. /* Copy interval ranges to the driver */
  2203. memcpy(lp->his_range, extra, wrqu->data.length);
  2204. {
  2205. int i;
  2206. printk(KERN_DEBUG "Histo :");
  2207. for(i = 0; i < wrqu->data.length; i++)
  2208. printk(" %d", lp->his_range[i]);
  2209. printk("\n");
  2210. }
  2211. /* Reset result structure. */
  2212. memset(lp->his_sum, 0x00, sizeof(long) * 16);
  2213. }
  2214. /* Now we can set the number of ranges */
  2215. lp->his_number = wrqu->data.length;
  2216. return(0);
  2217. }
  2218. /*------------------------------------------------------------------*/
  2219. /*
  2220. * Wireless Private Handler : get histogram
  2221. */
  2222. static int wavelan_get_histo(struct net_device *dev,
  2223. struct iw_request_info *info,
  2224. union iwreq_data *wrqu,
  2225. char *extra)
  2226. {
  2227. net_local *lp = netdev_priv(dev);
  2228. /* Set the number of intervals. */
  2229. wrqu->data.length = lp->his_number;
  2230. /* Give back the distribution statistics */
  2231. if(lp->his_number > 0)
  2232. memcpy(extra, lp->his_sum, sizeof(long) * lp->his_number);
  2233. return(0);
  2234. }
  2235. #endif /* HISTOGRAM */
  2236. /*------------------------------------------------------------------*/
  2237. /*
  2238. * Structures to export the Wireless Handlers
  2239. */
  2240. static const struct iw_priv_args wavelan_private_args[] = {
  2241. /*{ cmd, set_args, get_args, name } */
  2242. { SIOCSIPQTHR, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setqualthr" },
  2243. { SIOCGIPQTHR, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getqualthr" },
  2244. { SIOCSIPROAM, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setroam" },
  2245. { SIOCGIPROAM, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getroam" },
  2246. { SIOCSIPHISTO, IW_PRIV_TYPE_BYTE | 16, 0, "sethisto" },
  2247. { SIOCGIPHISTO, 0, IW_PRIV_TYPE_INT | 16, "gethisto" },
  2248. };
  2249. static const iw_handler wavelan_handler[] =
  2250. {
  2251. NULL, /* SIOCSIWNAME */
  2252. wavelan_get_name, /* SIOCGIWNAME */
  2253. wavelan_set_nwid, /* SIOCSIWNWID */
  2254. wavelan_get_nwid, /* SIOCGIWNWID */
  2255. wavelan_set_freq, /* SIOCSIWFREQ */
  2256. wavelan_get_freq, /* SIOCGIWFREQ */
  2257. #ifdef WAVELAN_ROAMING
  2258. wavelan_set_mode, /* SIOCSIWMODE */
  2259. wavelan_get_mode, /* SIOCGIWMODE */
  2260. #else /* WAVELAN_ROAMING */
  2261. NULL, /* SIOCSIWMODE */
  2262. NULL, /* SIOCGIWMODE */
  2263. #endif /* WAVELAN_ROAMING */
  2264. wavelan_set_sens, /* SIOCSIWSENS */
  2265. wavelan_get_sens, /* SIOCGIWSENS */
  2266. NULL, /* SIOCSIWRANGE */
  2267. wavelan_get_range, /* SIOCGIWRANGE */
  2268. NULL, /* SIOCSIWPRIV */
  2269. NULL, /* SIOCGIWPRIV */
  2270. NULL, /* SIOCSIWSTATS */
  2271. NULL, /* SIOCGIWSTATS */
  2272. iw_handler_set_spy, /* SIOCSIWSPY */
  2273. iw_handler_get_spy, /* SIOCGIWSPY */
  2274. iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
  2275. iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
  2276. #ifdef WAVELAN_ROAMING_EXT
  2277. wavelan_set_wap, /* SIOCSIWAP */
  2278. wavelan_get_wap, /* SIOCGIWAP */
  2279. NULL, /* -- hole -- */
  2280. NULL, /* SIOCGIWAPLIST */
  2281. NULL, /* -- hole -- */
  2282. NULL, /* -- hole -- */
  2283. wavelan_set_essid, /* SIOCSIWESSID */
  2284. wavelan_get_essid, /* SIOCGIWESSID */
  2285. #else /* WAVELAN_ROAMING_EXT */
  2286. NULL, /* SIOCSIWAP */
  2287. NULL, /* SIOCGIWAP */
  2288. NULL, /* -- hole -- */
  2289. NULL, /* SIOCGIWAPLIST */
  2290. NULL, /* -- hole -- */
  2291. NULL, /* -- hole -- */
  2292. NULL, /* SIOCSIWESSID */
  2293. NULL, /* SIOCGIWESSID */
  2294. #endif /* WAVELAN_ROAMING_EXT */
  2295. NULL, /* SIOCSIWNICKN */
  2296. NULL, /* SIOCGIWNICKN */
  2297. NULL, /* -- hole -- */
  2298. NULL, /* -- hole -- */
  2299. NULL, /* SIOCSIWRATE */
  2300. NULL, /* SIOCGIWRATE */
  2301. NULL, /* SIOCSIWRTS */
  2302. NULL, /* SIOCGIWRTS */
  2303. NULL, /* SIOCSIWFRAG */
  2304. NULL, /* SIOCGIWFRAG */
  2305. NULL, /* SIOCSIWTXPOW */
  2306. NULL, /* SIOCGIWTXPOW */
  2307. NULL, /* SIOCSIWRETRY */
  2308. NULL, /* SIOCGIWRETRY */
  2309. wavelan_set_encode, /* SIOCSIWENCODE */
  2310. wavelan_get_encode, /* SIOCGIWENCODE */
  2311. };
  2312. static const iw_handler wavelan_private_handler[] =
  2313. {
  2314. wavelan_set_qthr, /* SIOCIWFIRSTPRIV */
  2315. wavelan_get_qthr, /* SIOCIWFIRSTPRIV + 1 */
  2316. #ifdef WAVELAN_ROAMING
  2317. wavelan_set_roam, /* SIOCIWFIRSTPRIV + 2 */
  2318. wavelan_get_roam, /* SIOCIWFIRSTPRIV + 3 */
  2319. #else /* WAVELAN_ROAMING */
  2320. NULL, /* SIOCIWFIRSTPRIV + 2 */
  2321. NULL, /* SIOCIWFIRSTPRIV + 3 */
  2322. #endif /* WAVELAN_ROAMING */
  2323. #ifdef HISTOGRAM
  2324. wavelan_set_histo, /* SIOCIWFIRSTPRIV + 4 */
  2325. wavelan_get_histo, /* SIOCIWFIRSTPRIV + 5 */
  2326. #endif /* HISTOGRAM */
  2327. };
  2328. static const struct iw_handler_def wavelan_handler_def =
  2329. {
  2330. .num_standard = ARRAY_SIZE(wavelan_handler),
  2331. .num_private = ARRAY_SIZE(wavelan_private_handler),
  2332. .num_private_args = ARRAY_SIZE(wavelan_private_args),
  2333. .standard = wavelan_handler,
  2334. .private = wavelan_private_handler,
  2335. .private_args = wavelan_private_args,
  2336. .get_wireless_stats = wavelan_get_wireless_stats,
  2337. };
  2338. /*------------------------------------------------------------------*/
  2339. /*
  2340. * Get wireless statistics
  2341. * Called by /proc/net/wireless...
  2342. */
  2343. static iw_stats *
  2344. wavelan_get_wireless_stats(struct net_device * dev)
  2345. {
  2346. kio_addr_t base = dev->base_addr;
  2347. net_local * lp = netdev_priv(dev);
  2348. mmr_t m;
  2349. iw_stats * wstats;
  2350. unsigned long flags;
  2351. #ifdef DEBUG_IOCTL_TRACE
  2352. printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()\n", dev->name);
  2353. #endif
  2354. /* Disable interrupts & save flags */
  2355. spin_lock_irqsave(&lp->spinlock, flags);
  2356. wstats = &lp->wstats;
  2357. /* Get data from the mmc */
  2358. mmc_out(base, mmwoff(0, mmw_freeze), 1);
  2359. mmc_read(base, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1);
  2360. mmc_read(base, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l, 2);
  2361. mmc_read(base, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set, 4);
  2362. mmc_out(base, mmwoff(0, mmw_freeze), 0);
  2363. /* Copy data to wireless stuff */
  2364. wstats->status = m.mmr_dce_status & MMR_DCE_STATUS;
  2365. wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL;
  2366. wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL;
  2367. wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL;
  2368. wstats->qual.updated = (((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7) |
  2369. ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6) |
  2370. ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5));
  2371. wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
  2372. wstats->discard.code = 0L;
  2373. wstats->discard.misc = 0L;
  2374. /* ReEnable interrupts & restore flags */
  2375. spin_unlock_irqrestore(&lp->spinlock, flags);
  2376. #ifdef DEBUG_IOCTL_TRACE
  2377. printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()\n", dev->name);
  2378. #endif
  2379. return &lp->wstats;
  2380. }
  2381. /************************* PACKET RECEPTION *************************/
  2382. /*
  2383. * This part deal with receiving the packets.
  2384. * The interrupt handler get an interrupt when a packet has been
  2385. * successfully received and called this part...
  2386. */
  2387. /*------------------------------------------------------------------*/
  2388. /*
  2389. * Calculate the starting address of the frame pointed to by the receive
  2390. * frame pointer and verify that the frame seem correct
  2391. * (called by wv_packet_rcv())
  2392. */
  2393. static inline int
  2394. wv_start_of_frame(struct net_device * dev,
  2395. int rfp, /* end of frame */
  2396. int wrap) /* start of buffer */
  2397. {
  2398. kio_addr_t base = dev->base_addr;
  2399. int rp;
  2400. int len;
  2401. rp = (rfp - 5 + RX_SIZE) % RX_SIZE;
  2402. outb(rp & 0xff, PIORL(base));
  2403. outb(((rp >> 8) & PIORH_MASK), PIORH(base));
  2404. len = inb(PIOP(base));
  2405. len |= inb(PIOP(base)) << 8;
  2406. /* Sanity checks on size */
  2407. /* Frame too big */
  2408. if(len > MAXDATAZ + 100)
  2409. {
  2410. #ifdef DEBUG_RX_ERROR
  2411. printk(KERN_INFO "%s: wv_start_of_frame: Received frame too large, rfp %d len 0x%x\n",
  2412. dev->name, rfp, len);
  2413. #endif
  2414. return(-1);
  2415. }
  2416. /* Frame too short */
  2417. if(len < 7)
  2418. {
  2419. #ifdef DEBUG_RX_ERROR
  2420. printk(KERN_INFO "%s: wv_start_of_frame: Received null frame, rfp %d len 0x%x\n",
  2421. dev->name, rfp, len);
  2422. #endif
  2423. return(-1);
  2424. }
  2425. /* Wrap around buffer */
  2426. if(len > ((wrap - (rfp - len) + RX_SIZE) % RX_SIZE)) /* magic formula ! */
  2427. {
  2428. #ifdef DEBUG_RX_ERROR
  2429. printk(KERN_INFO "%s: wv_start_of_frame: wrap around buffer, wrap %d rfp %d len 0x%x\n",
  2430. dev->name, wrap, rfp, len);
  2431. #endif
  2432. return(-1);
  2433. }
  2434. return((rp - len + RX_SIZE) % RX_SIZE);
  2435. } /* wv_start_of_frame */
  2436. /*------------------------------------------------------------------*/
  2437. /*
  2438. * This routine does the actual copy of data (including the ethernet
  2439. * header structure) from the WaveLAN card to an sk_buff chain that
  2440. * will be passed up to the network interface layer. NOTE: We
  2441. * currently don't handle trailer protocols (neither does the rest of
  2442. * the network interface), so if that is needed, it will (at least in
  2443. * part) be added here. The contents of the receive ring buffer are
  2444. * copied to a message chain that is then passed to the kernel.
  2445. *
  2446. * Note: if any errors occur, the packet is "dropped on the floor"
  2447. * (called by wv_packet_rcv())
  2448. */
  2449. static inline void
  2450. wv_packet_read(struct net_device * dev,
  2451. int fd_p,
  2452. int sksize)
  2453. {
  2454. net_local * lp = netdev_priv(dev);
  2455. struct sk_buff * skb;
  2456. #ifdef DEBUG_RX_TRACE
  2457. printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)\n",
  2458. dev->name, fd_p, sksize);
  2459. #endif
  2460. /* Allocate some buffer for the new packet */
  2461. if((skb = dev_alloc_skb(sksize+2)) == (struct sk_buff *) NULL)
  2462. {
  2463. #ifdef DEBUG_RX_ERROR
  2464. printk(KERN_INFO "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC)\n",
  2465. dev->name, sksize);
  2466. #endif
  2467. lp->stats.rx_dropped++;
  2468. /*
  2469. * Not only do we want to return here, but we also need to drop the
  2470. * packet on the floor to clear the interrupt.
  2471. */
  2472. return;
  2473. }
  2474. skb_reserve(skb, 2);
  2475. fd_p = read_ringbuf(dev, fd_p, (char *) skb_put(skb, sksize), sksize);
  2476. skb->protocol = eth_type_trans(skb, dev);
  2477. #ifdef DEBUG_RX_INFO
  2478. wv_packet_info(skb_mac_header(skb), sksize, dev->name, "wv_packet_read");
  2479. #endif /* DEBUG_RX_INFO */
  2480. /* Statistics gathering & stuff associated.
  2481. * It seem a bit messy with all the define, but it's really simple... */
  2482. if(
  2483. #ifdef IW_WIRELESS_SPY
  2484. (lp->spy_data.spy_number > 0) ||
  2485. #endif /* IW_WIRELESS_SPY */
  2486. #ifdef HISTOGRAM
  2487. (lp->his_number > 0) ||
  2488. #endif /* HISTOGRAM */
  2489. #ifdef WAVELAN_ROAMING
  2490. (do_roaming) ||
  2491. #endif /* WAVELAN_ROAMING */
  2492. 0)
  2493. {
  2494. u_char stats[3]; /* Signal level, Noise level, Signal quality */
  2495. /* read signal level, silence level and signal quality bytes */
  2496. fd_p = read_ringbuf(dev, (fd_p + 4) % RX_SIZE + RX_BASE,
  2497. stats, 3);
  2498. #ifdef DEBUG_RX_INFO
  2499. printk(KERN_DEBUG "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n",
  2500. dev->name, stats[0] & 0x3F, stats[1] & 0x3F, stats[2] & 0x0F);
  2501. #endif
  2502. #ifdef WAVELAN_ROAMING
  2503. if(do_roaming)
  2504. if(WAVELAN_BEACON(skb->data))
  2505. wl_roam_gather(dev, skb->data, stats);
  2506. #endif /* WAVELAN_ROAMING */
  2507. #ifdef WIRELESS_SPY
  2508. wl_spy_gather(dev, skb_mac_header(skb) + WAVELAN_ADDR_SIZE, stats);
  2509. #endif /* WIRELESS_SPY */
  2510. #ifdef HISTOGRAM
  2511. wl_his_gather(dev, stats);
  2512. #endif /* HISTOGRAM */
  2513. }
  2514. /*
  2515. * Hand the packet to the Network Module
  2516. */
  2517. netif_rx(skb);
  2518. /* Keep stats up to date */
  2519. dev->last_rx = jiffies;
  2520. lp->stats.rx_packets++;
  2521. lp->stats.rx_bytes += sksize;
  2522. #ifdef DEBUG_RX_TRACE
  2523. printk(KERN_DEBUG "%s: <-wv_packet_read()\n", dev->name);
  2524. #endif
  2525. return;
  2526. }
  2527. /*------------------------------------------------------------------*/
  2528. /*
  2529. * This routine is called by the interrupt handler to initiate a
  2530. * packet transfer from the card to the network interface layer above
  2531. * this driver. This routine checks if a buffer has been successfully
  2532. * received by the WaveLAN card. If so, the routine wv_packet_read is
  2533. * called to do the actual transfer of the card's data including the
  2534. * ethernet header into a packet consisting of an sk_buff chain.
  2535. * (called by wavelan_interrupt())
  2536. * Note : the spinlock is already grabbed for us and irq are disabled.
  2537. */
  2538. static inline void
  2539. wv_packet_rcv(struct net_device * dev)
  2540. {
  2541. kio_addr_t base = dev->base_addr;
  2542. net_local * lp = netdev_priv(dev);
  2543. int newrfp;
  2544. int rp;
  2545. int len;
  2546. int f_start;
  2547. int status;
  2548. int i593_rfp;
  2549. int stat_ptr;
  2550. u_char c[4];
  2551. #ifdef DEBUG_RX_TRACE
  2552. printk(KERN_DEBUG "%s: ->wv_packet_rcv()\n", dev->name);
  2553. #endif
  2554. /* Get the new receive frame pointer from the i82593 chip */
  2555. outb(CR0_STATUS_2 | OP0_NOP, LCCR(base));
  2556. i593_rfp = inb(LCSR(base));
  2557. i593_rfp |= inb(LCSR(base)) << 8;
  2558. i593_rfp %= RX_SIZE;
  2559. /* Get the new receive frame pointer from the WaveLAN card.
  2560. * It is 3 bytes more than the increment of the i82593 receive
  2561. * frame pointer, for each packet. This is because it includes the
  2562. * 3 roaming bytes added by the mmc.
  2563. */
  2564. newrfp = inb(RPLL(base));
  2565. newrfp |= inb(RPLH(base)) << 8;
  2566. newrfp %= RX_SIZE;
  2567. #ifdef DEBUG_RX_INFO
  2568. printk(KERN_DEBUG "%s: wv_packet_rcv(): i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
  2569. dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
  2570. #endif
  2571. #ifdef DEBUG_RX_ERROR
  2572. /* If no new frame pointer... */
  2573. if(lp->overrunning || newrfp == lp->rfp)
  2574. printk(KERN_INFO "%s: wv_packet_rcv(): no new frame: i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
  2575. dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
  2576. #endif
  2577. /* Read all frames (packets) received */
  2578. while(newrfp != lp->rfp)
  2579. {
  2580. /* A frame is composed of the packet, followed by a status word,
  2581. * the length of the frame (word) and the mmc info (SNR & qual).
  2582. * It's because the length is at the end that we can only scan
  2583. * frames backward. */
  2584. /* Find the first frame by skipping backwards over the frames */
  2585. rp = newrfp; /* End of last frame */
  2586. while(((f_start = wv_start_of_frame(dev, rp, newrfp)) != lp->rfp) &&
  2587. (f_start != -1))
  2588. rp = f_start;
  2589. /* If we had a problem */
  2590. if(f_start == -1)
  2591. {
  2592. #ifdef DEBUG_RX_ERROR
  2593. printk(KERN_INFO "wavelan_cs: cannot find start of frame ");
  2594. printk(" i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
  2595. i593_rfp, lp->stop, newrfp, lp->rfp);
  2596. #endif
  2597. lp->rfp = rp; /* Get to the last usable frame */
  2598. continue;
  2599. }
  2600. /* f_start point to the beggining of the first frame received
  2601. * and rp to the beggining of the next one */
  2602. /* Read status & length of the frame */
  2603. stat_ptr = (rp - 7 + RX_SIZE) % RX_SIZE;
  2604. stat_ptr = read_ringbuf(dev, stat_ptr, c, 4);
  2605. status = c[0] | (c[1] << 8);
  2606. len = c[2] | (c[3] << 8);
  2607. /* Check status */
  2608. if((status & RX_RCV_OK) != RX_RCV_OK)
  2609. {
  2610. lp->stats.rx_errors++;
  2611. if(status & RX_NO_SFD)
  2612. lp->stats.rx_frame_errors++;
  2613. if(status & RX_CRC_ERR)
  2614. lp->stats.rx_crc_errors++;
  2615. if(status & RX_OVRRUN)
  2616. lp->stats.rx_over_errors++;
  2617. #ifdef DEBUG_RX_FAIL
  2618. printk(KERN_DEBUG "%s: wv_packet_rcv(): packet not received ok, status = 0x%x\n",
  2619. dev->name, status);
  2620. #endif
  2621. }
  2622. else
  2623. /* Read the packet and transmit to Linux */
  2624. wv_packet_read(dev, f_start, len - 2);
  2625. /* One frame has been processed, skip it */
  2626. lp->rfp = rp;
  2627. }
  2628. /*
  2629. * Update the frame stop register, but set it to less than
  2630. * the full 8K to allow space for 3 bytes of signal strength
  2631. * per packet.
  2632. */
  2633. lp->stop = (i593_rfp + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
  2634. outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
  2635. outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
  2636. outb(OP1_SWIT_TO_PORT_0, LCCR(base));
  2637. #ifdef DEBUG_RX_TRACE
  2638. printk(KERN_DEBUG "%s: <-wv_packet_rcv()\n", dev->name);
  2639. #endif
  2640. }
  2641. /*********************** PACKET TRANSMISSION ***********************/
  2642. /*
  2643. * This part deal with sending packet through the wavelan
  2644. * We copy the packet to the send buffer and then issue the send
  2645. * command to the i82593. The result of this operation will be
  2646. * checked in wavelan_interrupt()
  2647. */
  2648. /*------------------------------------------------------------------*/
  2649. /*
  2650. * This routine fills in the appropriate registers and memory
  2651. * locations on the WaveLAN card and starts the card off on
  2652. * the transmit.
  2653. * (called in wavelan_packet_xmit())
  2654. */
  2655. static inline void
  2656. wv_packet_write(struct net_device * dev,
  2657. void * buf,
  2658. short length)
  2659. {
  2660. net_local * lp = netdev_priv(dev);
  2661. kio_addr_t base = dev->base_addr;
  2662. unsigned long flags;
  2663. int clen = length;
  2664. register u_short xmtdata_base = TX_BASE;
  2665. #ifdef DEBUG_TX_TRACE
  2666. printk(KERN_DEBUG "%s: ->wv_packet_write(%d)\n", dev->name, length);
  2667. #endif
  2668. spin_lock_irqsave(&lp->spinlock, flags);
  2669. /* Write the length of data buffer followed by the buffer */
  2670. outb(xmtdata_base & 0xff, PIORL(base));
  2671. outb(((xmtdata_base >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
  2672. outb(clen & 0xff, PIOP(base)); /* lsb */
  2673. outb(clen >> 8, PIOP(base)); /* msb */
  2674. /* Send the data */
  2675. outsb(PIOP(base), buf, clen);
  2676. /* Indicate end of transmit chain */
  2677. outb(OP0_NOP, PIOP(base));
  2678. /* josullvn@cs.cmu.edu: need to send a second NOP for alignment... */
  2679. outb(OP0_NOP, PIOP(base));
  2680. /* Reset the transmit DMA pointer */
  2681. hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  2682. hacr_write(base, HACR_DEFAULT);
  2683. /* Send the transmit command */
  2684. wv_82593_cmd(dev, "wv_packet_write(): transmit",
  2685. OP0_TRANSMIT, SR0_NO_RESULT);
  2686. /* Make sure the watchdog will keep quiet for a while */
  2687. dev->trans_start = jiffies;
  2688. /* Keep stats up to date */
  2689. lp->stats.tx_bytes += length;
  2690. spin_unlock_irqrestore(&lp->spinlock, flags);
  2691. #ifdef DEBUG_TX_INFO
  2692. wv_packet_info((u_char *) buf, length, dev->name, "wv_packet_write");
  2693. #endif /* DEBUG_TX_INFO */
  2694. #ifdef DEBUG_TX_TRACE
  2695. printk(KERN_DEBUG "%s: <-wv_packet_write()\n", dev->name);
  2696. #endif
  2697. }
  2698. /*------------------------------------------------------------------*/
  2699. /*
  2700. * This routine is called when we want to send a packet (NET3 callback)
  2701. * In this routine, we check if the harware is ready to accept
  2702. * the packet. We also prevent reentrance. Then, we call the function
  2703. * to send the packet...
  2704. */
  2705. static int
  2706. wavelan_packet_xmit(struct sk_buff * skb,
  2707. struct net_device * dev)
  2708. {
  2709. net_local * lp = netdev_priv(dev);
  2710. unsigned long flags;
  2711. #ifdef DEBUG_TX_TRACE
  2712. printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)\n", dev->name,
  2713. (unsigned) skb);
  2714. #endif
  2715. /*
  2716. * Block a timer-based transmit from overlapping a previous transmit.
  2717. * In other words, prevent reentering this routine.
  2718. */
  2719. netif_stop_queue(dev);
  2720. /* If somebody has asked to reconfigure the controller,
  2721. * we can do it now */
  2722. if(lp->reconfig_82593)
  2723. {
  2724. spin_lock_irqsave(&lp->spinlock, flags); /* Disable interrupts */
  2725. wv_82593_config(dev);
  2726. spin_unlock_irqrestore(&lp->spinlock, flags); /* Re-enable interrupts */
  2727. /* Note : the configure procedure was totally synchronous,
  2728. * so the Tx buffer is now free */
  2729. }
  2730. #ifdef DEBUG_TX_ERROR
  2731. if (skb->next)
  2732. printk(KERN_INFO "skb has next\n");
  2733. #endif
  2734. /* Check if we need some padding */
  2735. /* Note : on wireless the propagation time is in the order of 1us,
  2736. * and we don't have the Ethernet specific requirement of beeing
  2737. * able to detect collisions, therefore in theory we don't really
  2738. * need to pad. Jean II */
  2739. if (skb_padto(skb, ETH_ZLEN))
  2740. return 0;
  2741. wv_packet_write(dev, skb->data, skb->len);
  2742. dev_kfree_skb(skb);
  2743. #ifdef DEBUG_TX_TRACE
  2744. printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
  2745. #endif
  2746. return(0);
  2747. }
  2748. /********************** HARDWARE CONFIGURATION **********************/
  2749. /*
  2750. * This part do the real job of starting and configuring the hardware.
  2751. */
  2752. /*------------------------------------------------------------------*/
  2753. /*
  2754. * Routine to initialize the Modem Management Controller.
  2755. * (called by wv_hw_config())
  2756. */
  2757. static inline int
  2758. wv_mmc_init(struct net_device * dev)
  2759. {
  2760. kio_addr_t base = dev->base_addr;
  2761. psa_t psa;
  2762. mmw_t m;
  2763. int configured;
  2764. int i; /* Loop counter */
  2765. #ifdef DEBUG_CONFIG_TRACE
  2766. printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name);
  2767. #endif
  2768. /* Read the parameter storage area */
  2769. psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
  2770. /*
  2771. * Check the first three octets of the MAC addr for the manufacturer's code.
  2772. * Note: If you get the error message below, you've got a
  2773. * non-NCR/AT&T/Lucent PCMCIA cards, see wavelan_cs.h for detail on
  2774. * how to configure your card...
  2775. */
  2776. for(i = 0; i < (sizeof(MAC_ADDRESSES) / sizeof(char) / 3); i++)
  2777. if((psa.psa_univ_mac_addr[0] == MAC_ADDRESSES[i][0]) &&
  2778. (psa.psa_univ_mac_addr[1] == MAC_ADDRESSES[i][1]) &&
  2779. (psa.psa_univ_mac_addr[2] == MAC_ADDRESSES[i][2]))
  2780. break;
  2781. /* If we have not found it... */
  2782. if(i == (sizeof(MAC_ADDRESSES) / sizeof(char) / 3))
  2783. {
  2784. #ifdef DEBUG_CONFIG_ERRORS
  2785. printk(KERN_WARNING "%s: wv_mmc_init(): Invalid MAC address: %02X:%02X:%02X:...\n",
  2786. dev->name, psa.psa_univ_mac_addr[0],
  2787. psa.psa_univ_mac_addr[1], psa.psa_univ_mac_addr[2]);
  2788. #endif
  2789. return FALSE;
  2790. }
  2791. /* Get the MAC address */
  2792. memcpy(&dev->dev_addr[0], &psa.psa_univ_mac_addr[0], WAVELAN_ADDR_SIZE);
  2793. #ifdef USE_PSA_CONFIG
  2794. configured = psa.psa_conf_status & 1;
  2795. #else
  2796. configured = 0;
  2797. #endif
  2798. /* Is the PSA is not configured */
  2799. if(!configured)
  2800. {
  2801. /* User will be able to configure NWID after (with iwconfig) */
  2802. psa.psa_nwid[0] = 0;
  2803. psa.psa_nwid[1] = 0;
  2804. /* As NWID is not set : no NWID checking */
  2805. psa.psa_nwid_select = 0;
  2806. /* Disable encryption */
  2807. psa.psa_encryption_select = 0;
  2808. /* Set to standard values
  2809. * 0x04 for AT,
  2810. * 0x01 for MCA,
  2811. * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
  2812. */
  2813. if (psa.psa_comp_number & 1)
  2814. psa.psa_thr_pre_set = 0x01;
  2815. else
  2816. psa.psa_thr_pre_set = 0x04;
  2817. psa.psa_quality_thr = 0x03;
  2818. /* It is configured */
  2819. psa.psa_conf_status |= 1;
  2820. #ifdef USE_PSA_CONFIG
  2821. /* Write the psa */
  2822. psa_write(dev, (char *)psa.psa_nwid - (char *)&psa,
  2823. (unsigned char *)psa.psa_nwid, 4);
  2824. psa_write(dev, (char *)&psa.psa_thr_pre_set - (char *)&psa,
  2825. (unsigned char *)&psa.psa_thr_pre_set, 1);
  2826. psa_write(dev, (char *)&psa.psa_quality_thr - (char *)&psa,
  2827. (unsigned char *)&psa.psa_quality_thr, 1);
  2828. psa_write(dev, (char *)&psa.psa_conf_status - (char *)&psa,
  2829. (unsigned char *)&psa.psa_conf_status, 1);
  2830. /* update the Wavelan checksum */
  2831. update_psa_checksum(dev);
  2832. #endif /* USE_PSA_CONFIG */
  2833. }
  2834. /* Zero the mmc structure */
  2835. memset(&m, 0x00, sizeof(m));
  2836. /* Copy PSA info to the mmc */
  2837. m.mmw_netw_id_l = psa.psa_nwid[1];
  2838. m.mmw_netw_id_h = psa.psa_nwid[0];
  2839. if(psa.psa_nwid_select & 1)
  2840. m.mmw_loopt_sel = 0x00;
  2841. else
  2842. m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
  2843. memcpy(&m.mmw_encr_key, &psa.psa_encryption_key,
  2844. sizeof(m.mmw_encr_key));
  2845. if(psa.psa_encryption_select)
  2846. m.mmw_encr_enable = MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
  2847. else
  2848. m.mmw_encr_enable = 0;
  2849. m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
  2850. m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
  2851. /*
  2852. * Set default modem control parameters.
  2853. * See NCR document 407-0024326 Rev. A.
  2854. */
  2855. m.mmw_jabber_enable = 0x01;
  2856. m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
  2857. m.mmw_ifs = 0x20;
  2858. m.mmw_mod_delay = 0x04;
  2859. m.mmw_jam_time = 0x38;
  2860. m.mmw_des_io_invert = 0;
  2861. m.mmw_freeze = 0;
  2862. m.mmw_decay_prm = 0;
  2863. m.mmw_decay_updat_prm = 0;
  2864. /* Write all info to mmc */
  2865. mmc_write(base, 0, (u_char *)&m, sizeof(m));
  2866. /* The following code start the modem of the 2.00 frequency
  2867. * selectable cards at power on. It's not strictly needed for the
  2868. * following boots...
  2869. * The original patch was by Joe Finney for the PCMCIA driver, but
  2870. * I've cleaned it a bit and add documentation.
  2871. * Thanks to Loeke Brederveld from Lucent for the info.
  2872. */
  2873. /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
  2874. * (does it work for everybody ? - especially old cards...) */
  2875. /* Note : WFREQSEL verify that it is able to read from EEprom
  2876. * a sensible frequency (address 0x00) + that MMR_FEE_STATUS_ID
  2877. * is 0xA (Xilinx version) or 0xB (Ariadne version).
  2878. * My test is more crude but do work... */
  2879. if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
  2880. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
  2881. {
  2882. /* We must download the frequency parameters to the
  2883. * synthetisers (from the EEprom - area 1)
  2884. * Note : as the EEprom is auto decremented, we set the end
  2885. * if the area... */
  2886. m.mmw_fee_addr = 0x0F;
  2887. m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
  2888. mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
  2889. (unsigned char *)&m.mmw_fee_ctrl, 2);
  2890. /* Wait until the download is finished */
  2891. fee_wait(base, 100, 100);
  2892. #ifdef DEBUG_CONFIG_INFO
  2893. /* The frequency was in the last word downloaded... */
  2894. mmc_read(base, (char *)&m.mmw_fee_data_l - (char *)&m,
  2895. (unsigned char *)&m.mmw_fee_data_l, 2);
  2896. /* Print some info for the user */
  2897. printk(KERN_DEBUG "%s: Wavelan 2.00 recognised (frequency select) : Current frequency = %ld\n",
  2898. dev->name,
  2899. ((m.mmw_fee_data_h << 4) |
  2900. (m.mmw_fee_data_l >> 4)) * 5 / 2 + 24000L);
  2901. #endif
  2902. /* We must now download the power adjust value (gain) to
  2903. * the synthetisers (from the EEprom - area 7 - DAC) */
  2904. m.mmw_fee_addr = 0x61;
  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. } /* if 2.00 card */
  2910. #ifdef DEBUG_CONFIG_TRACE
  2911. printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name);
  2912. #endif
  2913. return TRUE;
  2914. }
  2915. /*------------------------------------------------------------------*/
  2916. /*
  2917. * Routine to gracefully turn off reception, and wait for any commands
  2918. * to complete.
  2919. * (called in wv_ru_start() and wavelan_close() and wavelan_event())
  2920. */
  2921. static int
  2922. wv_ru_stop(struct net_device * dev)
  2923. {
  2924. kio_addr_t base = dev->base_addr;
  2925. net_local * lp = netdev_priv(dev);
  2926. unsigned long flags;
  2927. int status;
  2928. int spin;
  2929. #ifdef DEBUG_CONFIG_TRACE
  2930. printk(KERN_DEBUG "%s: ->wv_ru_stop()\n", dev->name);
  2931. #endif
  2932. spin_lock_irqsave(&lp->spinlock, flags);
  2933. /* First, send the LAN controller a stop receive command */
  2934. wv_82593_cmd(dev, "wv_graceful_shutdown(): stop-rcv",
  2935. OP0_STOP_RCV, SR0_NO_RESULT);
  2936. /* Then, spin until the receive unit goes idle */
  2937. spin = 300;
  2938. do
  2939. {
  2940. udelay(10);
  2941. outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
  2942. status = inb(LCSR(base));
  2943. }
  2944. while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_IDLE) && (spin-- > 0));
  2945. /* Now, spin until the chip finishes executing its current command */
  2946. do
  2947. {
  2948. udelay(10);
  2949. outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
  2950. status = inb(LCSR(base));
  2951. }
  2952. while(((status & SR3_EXEC_STATE_MASK) != SR3_EXEC_IDLE) && (spin-- > 0));
  2953. spin_unlock_irqrestore(&lp->spinlock, flags);
  2954. /* If there was a problem */
  2955. if(spin <= 0)
  2956. {
  2957. #ifdef DEBUG_CONFIG_ERRORS
  2958. printk(KERN_INFO "%s: wv_ru_stop(): The chip doesn't want to stop...\n",
  2959. dev->name);
  2960. #endif
  2961. return FALSE;
  2962. }
  2963. #ifdef DEBUG_CONFIG_TRACE
  2964. printk(KERN_DEBUG "%s: <-wv_ru_stop()\n", dev->name);
  2965. #endif
  2966. return TRUE;
  2967. } /* wv_ru_stop */
  2968. /*------------------------------------------------------------------*/
  2969. /*
  2970. * This routine starts the receive unit running. First, it checks if
  2971. * the card is actually ready. Then the card is instructed to receive
  2972. * packets again.
  2973. * (called in wv_hw_reset() & wavelan_open())
  2974. */
  2975. static int
  2976. wv_ru_start(struct net_device * dev)
  2977. {
  2978. kio_addr_t base = dev->base_addr;
  2979. net_local * lp = netdev_priv(dev);
  2980. unsigned long flags;
  2981. #ifdef DEBUG_CONFIG_TRACE
  2982. printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name);
  2983. #endif
  2984. /*
  2985. * We need to start from a quiescent state. To do so, we could check
  2986. * if the card is already running, but instead we just try to shut
  2987. * it down. First, we disable reception (in case it was already enabled).
  2988. */
  2989. if(!wv_ru_stop(dev))
  2990. return FALSE;
  2991. spin_lock_irqsave(&lp->spinlock, flags);
  2992. /* Now we know that no command is being executed. */
  2993. /* Set the receive frame pointer and stop pointer */
  2994. lp->rfp = 0;
  2995. outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
  2996. /* Reset ring management. This sets the receive frame pointer to 1 */
  2997. outb(OP1_RESET_RING_MNGMT, LCCR(base));
  2998. #if 0
  2999. /* XXX the i82593 manual page 6-4 seems to indicate that the stop register
  3000. should be set as below */
  3001. /* outb(CR1_STOP_REG_UPDATE|((RX_SIZE - 0x40)>> RX_SIZE_SHIFT),LCCR(base));*/
  3002. #elif 0
  3003. /* but I set it 0 instead */
  3004. lp->stop = 0;
  3005. #else
  3006. /* but I set it to 3 bytes per packet less than 8K */
  3007. lp->stop = (0 + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
  3008. #endif
  3009. outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
  3010. outb(OP1_INT_ENABLE, LCCR(base));
  3011. outb(OP1_SWIT_TO_PORT_0, LCCR(base));
  3012. /* Reset receive DMA pointer */
  3013. hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  3014. hacr_write_slow(base, HACR_DEFAULT);
  3015. /* Receive DMA on channel 1 */
  3016. wv_82593_cmd(dev, "wv_ru_start(): rcv-enable",
  3017. CR0_CHNL | OP0_RCV_ENABLE, SR0_NO_RESULT);
  3018. #ifdef DEBUG_I82593_SHOW
  3019. {
  3020. int status;
  3021. int opri;
  3022. int spin = 10000;
  3023. /* spin until the chip starts receiving */
  3024. do
  3025. {
  3026. outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
  3027. status = inb(LCSR(base));
  3028. if(spin-- <= 0)
  3029. break;
  3030. }
  3031. while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_ACTIVE) &&
  3032. ((status & SR3_RCV_STATE_MASK) != SR3_RCV_READY));
  3033. printk(KERN_DEBUG "rcv status is 0x%x [i:%d]\n",
  3034. (status & SR3_RCV_STATE_MASK), i);
  3035. }
  3036. #endif
  3037. spin_unlock_irqrestore(&lp->spinlock, flags);
  3038. #ifdef DEBUG_CONFIG_TRACE
  3039. printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name);
  3040. #endif
  3041. return TRUE;
  3042. }
  3043. /*------------------------------------------------------------------*/
  3044. /*
  3045. * This routine does a standard config of the WaveLAN controller (i82593).
  3046. * In the ISA driver, this is integrated in wavelan_hardware_reset()
  3047. * (called by wv_hw_config(), wv_82593_reconfig() & wavelan_packet_xmit())
  3048. */
  3049. static int
  3050. wv_82593_config(struct net_device * dev)
  3051. {
  3052. kio_addr_t base = dev->base_addr;
  3053. net_local * lp = netdev_priv(dev);
  3054. struct i82593_conf_block cfblk;
  3055. int ret = TRUE;
  3056. #ifdef DEBUG_CONFIG_TRACE
  3057. printk(KERN_DEBUG "%s: ->wv_82593_config()\n", dev->name);
  3058. #endif
  3059. /* Create & fill i82593 config block
  3060. *
  3061. * Now conform to Wavelan document WCIN085B
  3062. */
  3063. memset(&cfblk, 0x00, sizeof(struct i82593_conf_block));
  3064. cfblk.d6mod = FALSE; /* Run in i82593 advanced mode */
  3065. cfblk.fifo_limit = 5; /* = 56 B rx and 40 B tx fifo thresholds */
  3066. cfblk.forgnesi = FALSE; /* 0=82C501, 1=AMD7992B compatibility */
  3067. cfblk.fifo_32 = 1;
  3068. cfblk.throttle_enb = FALSE;
  3069. cfblk.contin = TRUE; /* enable continuous mode */
  3070. cfblk.cntrxint = FALSE; /* enable continuous mode receive interrupts */
  3071. cfblk.addr_len = WAVELAN_ADDR_SIZE;
  3072. cfblk.acloc = TRUE; /* Disable source addr insertion by i82593 */
  3073. cfblk.preamb_len = 0; /* 2 bytes preamble (SFD) */
  3074. cfblk.loopback = FALSE;
  3075. cfblk.lin_prio = 0; /* conform to 802.3 backoff algorithm */
  3076. cfblk.exp_prio = 5; /* conform to 802.3 backoff algorithm */
  3077. cfblk.bof_met = 1; /* conform to 802.3 backoff algorithm */
  3078. cfblk.ifrm_spc = 0x20 >> 4; /* 32 bit times interframe spacing */
  3079. cfblk.slottim_low = 0x20 >> 5; /* 32 bit times slot time */
  3080. cfblk.slottim_hi = 0x0;
  3081. cfblk.max_retr = 15;
  3082. cfblk.prmisc = ((lp->promiscuous) ? TRUE: FALSE); /* Promiscuous mode */
  3083. cfblk.bc_dis = FALSE; /* Enable broadcast reception */
  3084. cfblk.crs_1 = TRUE; /* Transmit without carrier sense */
  3085. cfblk.nocrc_ins = FALSE; /* i82593 generates CRC */
  3086. cfblk.crc_1632 = FALSE; /* 32-bit Autodin-II CRC */
  3087. cfblk.crs_cdt = FALSE; /* CD not to be interpreted as CS */
  3088. cfblk.cs_filter = 0; /* CS is recognized immediately */
  3089. cfblk.crs_src = FALSE; /* External carrier sense */
  3090. cfblk.cd_filter = 0; /* CD is recognized immediately */
  3091. cfblk.min_fr_len = ETH_ZLEN >> 2; /* Minimum frame length 64 bytes */
  3092. cfblk.lng_typ = FALSE; /* Length field > 1500 = type field */
  3093. cfblk.lng_fld = TRUE; /* Disable 802.3 length field check */
  3094. cfblk.rxcrc_xf = TRUE; /* Don't transfer CRC to memory */
  3095. cfblk.artx = TRUE; /* Disable automatic retransmission */
  3096. cfblk.sarec = TRUE; /* Disable source addr trig of CD */
  3097. cfblk.tx_jabber = TRUE; /* Disable jabber jam sequence */
  3098. cfblk.hash_1 = FALSE; /* Use bits 0-5 in mc address hash */
  3099. cfblk.lbpkpol = TRUE; /* Loopback pin active high */
  3100. cfblk.fdx = FALSE; /* Disable full duplex operation */
  3101. cfblk.dummy_6 = 0x3f; /* all ones */
  3102. cfblk.mult_ia = FALSE; /* No multiple individual addresses */
  3103. cfblk.dis_bof = FALSE; /* Disable the backoff algorithm ?! */
  3104. cfblk.dummy_1 = TRUE; /* set to 1 */
  3105. cfblk.tx_ifs_retrig = 3; /* Hmm... Disabled */
  3106. #ifdef MULTICAST_ALL
  3107. cfblk.mc_all = (lp->allmulticast ? TRUE: FALSE); /* Allow all multicasts */
  3108. #else
  3109. cfblk.mc_all = FALSE; /* No multicast all mode */
  3110. #endif
  3111. cfblk.rcv_mon = 0; /* Monitor mode disabled */
  3112. cfblk.frag_acpt = TRUE; /* Do not accept fragments */
  3113. cfblk.tstrttrs = FALSE; /* No start transmission threshold */
  3114. cfblk.fretx = TRUE; /* FIFO automatic retransmission */
  3115. cfblk.syncrqs = FALSE; /* Synchronous DRQ deassertion... */
  3116. cfblk.sttlen = TRUE; /* 6 byte status registers */
  3117. cfblk.rx_eop = TRUE; /* Signal EOP on packet reception */
  3118. cfblk.tx_eop = TRUE; /* Signal EOP on packet transmission */
  3119. cfblk.rbuf_size = RX_SIZE>>11; /* Set receive buffer size */
  3120. cfblk.rcvstop = TRUE; /* Enable Receive Stop Register */
  3121. #ifdef DEBUG_I82593_SHOW
  3122. {
  3123. u_char *c = (u_char *) &cfblk;
  3124. int i;
  3125. printk(KERN_DEBUG "wavelan_cs: config block:");
  3126. for(i = 0; i < sizeof(struct i82593_conf_block); i++,c++)
  3127. {
  3128. if((i % 16) == 0) printk("\n" KERN_DEBUG);
  3129. printk("%02x ", *c);
  3130. }
  3131. printk("\n");
  3132. }
  3133. #endif
  3134. /* Copy the config block to the i82593 */
  3135. outb(TX_BASE & 0xff, PIORL(base));
  3136. outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
  3137. outb(sizeof(struct i82593_conf_block) & 0xff, PIOP(base)); /* lsb */
  3138. outb(sizeof(struct i82593_conf_block) >> 8, PIOP(base)); /* msb */
  3139. outsb(PIOP(base), (char *) &cfblk, sizeof(struct i82593_conf_block));
  3140. /* reset transmit DMA pointer */
  3141. hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  3142. hacr_write(base, HACR_DEFAULT);
  3143. if(!wv_82593_cmd(dev, "wv_82593_config(): configure",
  3144. OP0_CONFIGURE, SR0_CONFIGURE_DONE))
  3145. ret = FALSE;
  3146. /* Initialize adapter's ethernet MAC address */
  3147. outb(TX_BASE & 0xff, PIORL(base));
  3148. outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
  3149. outb(WAVELAN_ADDR_SIZE, PIOP(base)); /* byte count lsb */
  3150. outb(0, PIOP(base)); /* byte count msb */
  3151. outsb(PIOP(base), &dev->dev_addr[0], WAVELAN_ADDR_SIZE);
  3152. /* reset transmit DMA pointer */
  3153. hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  3154. hacr_write(base, HACR_DEFAULT);
  3155. if(!wv_82593_cmd(dev, "wv_82593_config(): ia-setup",
  3156. OP0_IA_SETUP, SR0_IA_SETUP_DONE))
  3157. ret = FALSE;
  3158. #ifdef WAVELAN_ROAMING
  3159. /* If roaming is enabled, join the "Beacon Request" multicast group... */
  3160. /* But only if it's not in there already! */
  3161. if(do_roaming)
  3162. dev_mc_add(dev,WAVELAN_BEACON_ADDRESS, WAVELAN_ADDR_SIZE, 1);
  3163. #endif /* WAVELAN_ROAMING */
  3164. /* If any multicast address to set */
  3165. if(lp->mc_count)
  3166. {
  3167. struct dev_mc_list * dmi;
  3168. int addrs_len = WAVELAN_ADDR_SIZE * lp->mc_count;
  3169. #ifdef DEBUG_CONFIG_INFO
  3170. DECLARE_MAC_BUF(mac);
  3171. printk(KERN_DEBUG "%s: wv_hw_config(): set %d multicast addresses:\n",
  3172. dev->name, lp->mc_count);
  3173. for(dmi=dev->mc_list; dmi; dmi=dmi->next)
  3174. printk(KERN_DEBUG " %s\n",
  3175. print_mac(mac, dmi->dmi_addr));
  3176. #endif
  3177. /* Initialize adapter's ethernet multicast addresses */
  3178. outb(TX_BASE & 0xff, PIORL(base));
  3179. outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
  3180. outb(addrs_len & 0xff, PIOP(base)); /* byte count lsb */
  3181. outb((addrs_len >> 8), PIOP(base)); /* byte count msb */
  3182. for(dmi=dev->mc_list; dmi; dmi=dmi->next)
  3183. outsb(PIOP(base), dmi->dmi_addr, dmi->dmi_addrlen);
  3184. /* reset transmit DMA pointer */
  3185. hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  3186. hacr_write(base, HACR_DEFAULT);
  3187. if(!wv_82593_cmd(dev, "wv_82593_config(): mc-setup",
  3188. OP0_MC_SETUP, SR0_MC_SETUP_DONE))
  3189. ret = FALSE;
  3190. lp->mc_count = dev->mc_count; /* remember to avoid repeated reset */
  3191. }
  3192. /* Job done, clear the flag */
  3193. lp->reconfig_82593 = FALSE;
  3194. #ifdef DEBUG_CONFIG_TRACE
  3195. printk(KERN_DEBUG "%s: <-wv_82593_config()\n", dev->name);
  3196. #endif
  3197. return(ret);
  3198. }
  3199. /*------------------------------------------------------------------*/
  3200. /*
  3201. * Read the Access Configuration Register, perform a software reset,
  3202. * and then re-enable the card's software.
  3203. *
  3204. * If I understand correctly : reset the pcmcia interface of the
  3205. * wavelan.
  3206. * (called by wv_config())
  3207. */
  3208. static inline int
  3209. wv_pcmcia_reset(struct net_device * dev)
  3210. {
  3211. int i;
  3212. conf_reg_t reg = { 0, CS_READ, CISREG_COR, 0 };
  3213. struct pcmcia_device * link = ((net_local *)netdev_priv(dev))->link;
  3214. #ifdef DEBUG_CONFIG_TRACE
  3215. printk(KERN_DEBUG "%s: ->wv_pcmcia_reset()\n", dev->name);
  3216. #endif
  3217. i = pcmcia_access_configuration_register(link, &reg);
  3218. if(i != CS_SUCCESS)
  3219. {
  3220. cs_error(link, AccessConfigurationRegister, i);
  3221. return FALSE;
  3222. }
  3223. #ifdef DEBUG_CONFIG_INFO
  3224. printk(KERN_DEBUG "%s: wavelan_pcmcia_reset(): Config reg is 0x%x\n",
  3225. dev->name, (u_int) reg.Value);
  3226. #endif
  3227. reg.Action = CS_WRITE;
  3228. reg.Value = reg.Value | COR_SW_RESET;
  3229. i = pcmcia_access_configuration_register(link, &reg);
  3230. if(i != CS_SUCCESS)
  3231. {
  3232. cs_error(link, AccessConfigurationRegister, i);
  3233. return FALSE;
  3234. }
  3235. reg.Action = CS_WRITE;
  3236. reg.Value = COR_LEVEL_IRQ | COR_CONFIG;
  3237. i = pcmcia_access_configuration_register(link, &reg);
  3238. if(i != CS_SUCCESS)
  3239. {
  3240. cs_error(link, AccessConfigurationRegister, i);
  3241. return FALSE;
  3242. }
  3243. #ifdef DEBUG_CONFIG_TRACE
  3244. printk(KERN_DEBUG "%s: <-wv_pcmcia_reset()\n", dev->name);
  3245. #endif
  3246. return TRUE;
  3247. }
  3248. /*------------------------------------------------------------------*/
  3249. /*
  3250. * wavelan_hw_config() is called after a CARD_INSERTION event is
  3251. * received, to configure the wavelan hardware.
  3252. * Note that the reception will be enabled in wavelan->open(), so the
  3253. * device is configured but idle...
  3254. * Performs the following actions:
  3255. * 1. A pcmcia software reset (using wv_pcmcia_reset())
  3256. * 2. A power reset (reset DMA)
  3257. * 3. Reset the LAN controller
  3258. * 4. Initialize the radio modem (using wv_mmc_init)
  3259. * 5. Configure LAN controller (using wv_82593_config)
  3260. * 6. Perform a diagnostic on the LAN controller
  3261. * (called by wavelan_event() & wv_hw_reset())
  3262. */
  3263. static int
  3264. wv_hw_config(struct net_device * dev)
  3265. {
  3266. net_local * lp = netdev_priv(dev);
  3267. kio_addr_t base = dev->base_addr;
  3268. unsigned long flags;
  3269. int ret = FALSE;
  3270. #ifdef DEBUG_CONFIG_TRACE
  3271. printk(KERN_DEBUG "%s: ->wv_hw_config()\n", dev->name);
  3272. #endif
  3273. #ifdef STRUCT_CHECK
  3274. if(wv_structuct_check() != (char *) NULL)
  3275. {
  3276. printk(KERN_WARNING "%s: wv_hw_config: structure/compiler botch: \"%s\"\n",
  3277. dev->name, wv_structuct_check());
  3278. return FALSE;
  3279. }
  3280. #endif /* STRUCT_CHECK == 1 */
  3281. /* Reset the pcmcia interface */
  3282. if(wv_pcmcia_reset(dev) == FALSE)
  3283. return FALSE;
  3284. /* Disable interrupts */
  3285. spin_lock_irqsave(&lp->spinlock, flags);
  3286. /* Disguised goto ;-) */
  3287. do
  3288. {
  3289. /* Power UP the module + reset the modem + reset host adapter
  3290. * (in fact, reset DMA channels) */
  3291. hacr_write_slow(base, HACR_RESET);
  3292. hacr_write(base, HACR_DEFAULT);
  3293. /* Check if the module has been powered up... */
  3294. if(hasr_read(base) & HASR_NO_CLK)
  3295. {
  3296. #ifdef DEBUG_CONFIG_ERRORS
  3297. printk(KERN_WARNING "%s: wv_hw_config(): modem not connected or not a wavelan card\n",
  3298. dev->name);
  3299. #endif
  3300. break;
  3301. }
  3302. /* initialize the modem */
  3303. if(wv_mmc_init(dev) == FALSE)
  3304. {
  3305. #ifdef DEBUG_CONFIG_ERRORS
  3306. printk(KERN_WARNING "%s: wv_hw_config(): Can't configure the modem\n",
  3307. dev->name);
  3308. #endif
  3309. break;
  3310. }
  3311. /* reset the LAN controller (i82593) */
  3312. outb(OP0_RESET, LCCR(base));
  3313. mdelay(1); /* A bit crude ! */
  3314. /* Initialize the LAN controller */
  3315. if(wv_82593_config(dev) == FALSE)
  3316. {
  3317. #ifdef DEBUG_CONFIG_ERRORS
  3318. printk(KERN_INFO "%s: wv_hw_config(): i82593 init failed\n",
  3319. dev->name);
  3320. #endif
  3321. break;
  3322. }
  3323. /* Diagnostic */
  3324. if(wv_diag(dev) == FALSE)
  3325. {
  3326. #ifdef DEBUG_CONFIG_ERRORS
  3327. printk(KERN_INFO "%s: wv_hw_config(): i82593 diagnostic failed\n",
  3328. dev->name);
  3329. #endif
  3330. break;
  3331. }
  3332. /*
  3333. * insert code for loopback test here
  3334. */
  3335. /* The device is now configured */
  3336. lp->configured = 1;
  3337. ret = TRUE;
  3338. }
  3339. while(0);
  3340. /* Re-enable interrupts */
  3341. spin_unlock_irqrestore(&lp->spinlock, flags);
  3342. #ifdef DEBUG_CONFIG_TRACE
  3343. printk(KERN_DEBUG "%s: <-wv_hw_config()\n", dev->name);
  3344. #endif
  3345. return(ret);
  3346. }
  3347. /*------------------------------------------------------------------*/
  3348. /*
  3349. * Totally reset the wavelan and restart it.
  3350. * Performs the following actions:
  3351. * 1. Call wv_hw_config()
  3352. * 2. Start the LAN controller's receive unit
  3353. * (called by wavelan_event(), wavelan_watchdog() and wavelan_open())
  3354. */
  3355. static inline void
  3356. wv_hw_reset(struct net_device * dev)
  3357. {
  3358. net_local * lp = netdev_priv(dev);
  3359. #ifdef DEBUG_CONFIG_TRACE
  3360. printk(KERN_DEBUG "%s: ->wv_hw_reset()\n", dev->name);
  3361. #endif
  3362. lp->nresets++;
  3363. lp->configured = 0;
  3364. /* Call wv_hw_config() for most of the reset & init stuff */
  3365. if(wv_hw_config(dev) == FALSE)
  3366. return;
  3367. /* start receive unit */
  3368. wv_ru_start(dev);
  3369. #ifdef DEBUG_CONFIG_TRACE
  3370. printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name);
  3371. #endif
  3372. }
  3373. /*------------------------------------------------------------------*/
  3374. /*
  3375. * wv_pcmcia_config() is called after a CARD_INSERTION event is
  3376. * received, to configure the PCMCIA socket, and to make the ethernet
  3377. * device available to the system.
  3378. * (called by wavelan_event())
  3379. */
  3380. static inline int
  3381. wv_pcmcia_config(struct pcmcia_device * link)
  3382. {
  3383. struct net_device * dev = (struct net_device *) link->priv;
  3384. int i;
  3385. win_req_t req;
  3386. memreq_t mem;
  3387. net_local * lp = netdev_priv(dev);
  3388. #ifdef DEBUG_CONFIG_TRACE
  3389. printk(KERN_DEBUG "->wv_pcmcia_config(0x%p)\n", link);
  3390. #endif
  3391. do
  3392. {
  3393. i = pcmcia_request_io(link, &link->io);
  3394. if(i != CS_SUCCESS)
  3395. {
  3396. cs_error(link, RequestIO, i);
  3397. break;
  3398. }
  3399. /*
  3400. * Now allocate an interrupt line. Note that this does not
  3401. * actually assign a handler to the interrupt.
  3402. */
  3403. i = pcmcia_request_irq(link, &link->irq);
  3404. if(i != CS_SUCCESS)
  3405. {
  3406. cs_error(link, RequestIRQ, i);
  3407. break;
  3408. }
  3409. /*
  3410. * This actually configures the PCMCIA socket -- setting up
  3411. * the I/O windows and the interrupt mapping.
  3412. */
  3413. link->conf.ConfigIndex = 1;
  3414. i = pcmcia_request_configuration(link, &link->conf);
  3415. if(i != CS_SUCCESS)
  3416. {
  3417. cs_error(link, RequestConfiguration, i);
  3418. break;
  3419. }
  3420. /*
  3421. * Allocate a small memory window. Note that the struct pcmcia_device
  3422. * structure provides space for one window handle -- if your
  3423. * device needs several windows, you'll need to keep track of
  3424. * the handles in your private data structure, link->priv.
  3425. */
  3426. req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
  3427. req.Base = req.Size = 0;
  3428. req.AccessSpeed = mem_speed;
  3429. i = pcmcia_request_window(&link, &req, &link->win);
  3430. if(i != CS_SUCCESS)
  3431. {
  3432. cs_error(link, RequestWindow, i);
  3433. break;
  3434. }
  3435. lp->mem = ioremap(req.Base, req.Size);
  3436. dev->mem_start = (u_long)lp->mem;
  3437. dev->mem_end = dev->mem_start + req.Size;
  3438. mem.CardOffset = 0; mem.Page = 0;
  3439. i = pcmcia_map_mem_page(link->win, &mem);
  3440. if(i != CS_SUCCESS)
  3441. {
  3442. cs_error(link, MapMemPage, i);
  3443. break;
  3444. }
  3445. /* Feed device with this info... */
  3446. dev->irq = link->irq.AssignedIRQ;
  3447. dev->base_addr = link->io.BasePort1;
  3448. netif_start_queue(dev);
  3449. #ifdef DEBUG_CONFIG_INFO
  3450. printk(KERN_DEBUG "wv_pcmcia_config: MEMSTART %p IRQ %d IOPORT 0x%x\n",
  3451. lp->mem, dev->irq, (u_int) dev->base_addr);
  3452. #endif
  3453. SET_NETDEV_DEV(dev, &handle_to_dev(link));
  3454. i = register_netdev(dev);
  3455. if(i != 0)
  3456. {
  3457. #ifdef DEBUG_CONFIG_ERRORS
  3458. printk(KERN_INFO "wv_pcmcia_config(): register_netdev() failed\n");
  3459. #endif
  3460. break;
  3461. }
  3462. }
  3463. while(0); /* Humm... Disguised goto !!! */
  3464. /* If any step failed, release any partially configured state */
  3465. if(i != 0)
  3466. {
  3467. wv_pcmcia_release(link);
  3468. return FALSE;
  3469. }
  3470. strcpy(((net_local *) netdev_priv(dev))->node.dev_name, dev->name);
  3471. link->dev_node = &((net_local *) netdev_priv(dev))->node;
  3472. #ifdef DEBUG_CONFIG_TRACE
  3473. printk(KERN_DEBUG "<-wv_pcmcia_config()\n");
  3474. #endif
  3475. return TRUE;
  3476. }
  3477. /*------------------------------------------------------------------*/
  3478. /*
  3479. * After a card is removed, wv_pcmcia_release() will unregister the net
  3480. * device, and release the PCMCIA configuration. If the device is
  3481. * still open, this will be postponed until it is closed.
  3482. */
  3483. static void
  3484. wv_pcmcia_release(struct pcmcia_device *link)
  3485. {
  3486. struct net_device * dev = (struct net_device *) link->priv;
  3487. net_local * lp = netdev_priv(dev);
  3488. #ifdef DEBUG_CONFIG_TRACE
  3489. printk(KERN_DEBUG "%s: -> wv_pcmcia_release(0x%p)\n", dev->name, link);
  3490. #endif
  3491. iounmap(lp->mem);
  3492. pcmcia_disable_device(link);
  3493. #ifdef DEBUG_CONFIG_TRACE
  3494. printk(KERN_DEBUG "%s: <- wv_pcmcia_release()\n", dev->name);
  3495. #endif
  3496. }
  3497. /************************ INTERRUPT HANDLING ************************/
  3498. /*
  3499. * This function is the interrupt handler for the WaveLAN card. This
  3500. * routine will be called whenever:
  3501. * 1. A packet is received.
  3502. * 2. A packet has successfully been transferred and the unit is
  3503. * ready to transmit another packet.
  3504. * 3. A command has completed execution.
  3505. */
  3506. static irqreturn_t
  3507. wavelan_interrupt(int irq,
  3508. void * dev_id)
  3509. {
  3510. struct net_device * dev = dev_id;
  3511. net_local * lp;
  3512. kio_addr_t base;
  3513. int status0;
  3514. u_int tx_status;
  3515. #ifdef DEBUG_INTERRUPT_TRACE
  3516. printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name);
  3517. #endif
  3518. lp = netdev_priv(dev);
  3519. base = dev->base_addr;
  3520. #ifdef DEBUG_INTERRUPT_INFO
  3521. /* Check state of our spinlock (it should be cleared) */
  3522. if(spin_is_locked(&lp->spinlock))
  3523. printk(KERN_DEBUG
  3524. "%s: wavelan_interrupt(): spinlock is already locked !!!\n",
  3525. dev->name);
  3526. #endif
  3527. /* Prevent reentrancy. We need to do that because we may have
  3528. * multiple interrupt handler running concurently.
  3529. * It is safe because interrupts are disabled before aquiring
  3530. * the spinlock. */
  3531. spin_lock(&lp->spinlock);
  3532. /* Treat all pending interrupts */
  3533. while(1)
  3534. {
  3535. /* ---------------- INTERRUPT CHECKING ---------------- */
  3536. /*
  3537. * Look for the interrupt and verify the validity
  3538. */
  3539. outb(CR0_STATUS_0 | OP0_NOP, LCCR(base));
  3540. status0 = inb(LCSR(base));
  3541. #ifdef DEBUG_INTERRUPT_INFO
  3542. printk(KERN_DEBUG "status0 0x%x [%s => 0x%x]", status0,
  3543. (status0&SR0_INTERRUPT)?"int":"no int",status0&~SR0_INTERRUPT);
  3544. if(status0&SR0_INTERRUPT)
  3545. {
  3546. printk(" [%s => %d]\n", (status0 & SR0_CHNL) ? "chnl" :
  3547. ((status0 & SR0_EXECUTION) ? "cmd" :
  3548. ((status0 & SR0_RECEPTION) ? "recv" : "unknown")),
  3549. (status0 & SR0_EVENT_MASK));
  3550. }
  3551. else
  3552. printk("\n");
  3553. #endif
  3554. /* Return if no actual interrupt from i82593 (normal exit) */
  3555. if(!(status0 & SR0_INTERRUPT))
  3556. break;
  3557. /* If interrupt is both Rx and Tx or none...
  3558. * This code in fact is there to catch the spurious interrupt
  3559. * when you remove the wavelan pcmcia card from the socket */
  3560. if(((status0 & SR0_BOTH_RX_TX) == SR0_BOTH_RX_TX) ||
  3561. ((status0 & SR0_BOTH_RX_TX) == 0x0))
  3562. {
  3563. #ifdef DEBUG_INTERRUPT_INFO
  3564. printk(KERN_INFO "%s: wv_interrupt(): bogus interrupt (or from dead card) : %X\n",
  3565. dev->name, status0);
  3566. #endif
  3567. /* Acknowledge the interrupt */
  3568. outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
  3569. break;
  3570. }
  3571. /* ----------------- RECEIVING PACKET ----------------- */
  3572. /*
  3573. * When the wavelan signal the reception of a new packet,
  3574. * we call wv_packet_rcv() to copy if from the buffer and
  3575. * send it to NET3
  3576. */
  3577. if(status0 & SR0_RECEPTION)
  3578. {
  3579. #ifdef DEBUG_INTERRUPT_INFO
  3580. printk(KERN_DEBUG "%s: wv_interrupt(): receive\n", dev->name);
  3581. #endif
  3582. if((status0 & SR0_EVENT_MASK) == SR0_STOP_REG_HIT)
  3583. {
  3584. #ifdef DEBUG_INTERRUPT_ERROR
  3585. printk(KERN_INFO "%s: wv_interrupt(): receive buffer overflow\n",
  3586. dev->name);
  3587. #endif
  3588. lp->stats.rx_over_errors++;
  3589. lp->overrunning = 1;
  3590. }
  3591. /* Get the packet */
  3592. wv_packet_rcv(dev);
  3593. lp->overrunning = 0;
  3594. /* Acknowledge the interrupt */
  3595. outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
  3596. continue;
  3597. }
  3598. /* ---------------- COMMAND COMPLETION ---------------- */
  3599. /*
  3600. * Interrupts issued when the i82593 has completed a command.
  3601. * Most likely : transmission done
  3602. */
  3603. /* If a transmission has been done */
  3604. if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_DONE ||
  3605. (status0 & SR0_EVENT_MASK) == SR0_RETRANSMIT_DONE ||
  3606. (status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
  3607. {
  3608. #ifdef DEBUG_TX_ERROR
  3609. if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
  3610. printk(KERN_INFO "%s: wv_interrupt(): packet transmitted without CRC.\n",
  3611. dev->name);
  3612. #endif
  3613. /* Get transmission status */
  3614. tx_status = inb(LCSR(base));
  3615. tx_status |= (inb(LCSR(base)) << 8);
  3616. #ifdef DEBUG_INTERRUPT_INFO
  3617. printk(KERN_DEBUG "%s: wv_interrupt(): transmission done\n",
  3618. dev->name);
  3619. {
  3620. u_int rcv_bytes;
  3621. u_char status3;
  3622. rcv_bytes = inb(LCSR(base));
  3623. rcv_bytes |= (inb(LCSR(base)) << 8);
  3624. status3 = inb(LCSR(base));
  3625. printk(KERN_DEBUG "tx_status 0x%02x rcv_bytes 0x%02x status3 0x%x\n",
  3626. tx_status, rcv_bytes, (u_int) status3);
  3627. }
  3628. #endif
  3629. /* Check for possible errors */
  3630. if((tx_status & TX_OK) != TX_OK)
  3631. {
  3632. lp->stats.tx_errors++;
  3633. if(tx_status & TX_FRTL)
  3634. {
  3635. #ifdef DEBUG_TX_ERROR
  3636. printk(KERN_INFO "%s: wv_interrupt(): frame too long\n",
  3637. dev->name);
  3638. #endif
  3639. }
  3640. if(tx_status & TX_UND_RUN)
  3641. {
  3642. #ifdef DEBUG_TX_FAIL
  3643. printk(KERN_DEBUG "%s: wv_interrupt(): DMA underrun\n",
  3644. dev->name);
  3645. #endif
  3646. lp->stats.tx_aborted_errors++;
  3647. }
  3648. if(tx_status & TX_LOST_CTS)
  3649. {
  3650. #ifdef DEBUG_TX_FAIL
  3651. printk(KERN_DEBUG "%s: wv_interrupt(): no CTS\n", dev->name);
  3652. #endif
  3653. lp->stats.tx_carrier_errors++;
  3654. }
  3655. if(tx_status & TX_LOST_CRS)
  3656. {
  3657. #ifdef DEBUG_TX_FAIL
  3658. printk(KERN_DEBUG "%s: wv_interrupt(): no carrier\n",
  3659. dev->name);
  3660. #endif
  3661. lp->stats.tx_carrier_errors++;
  3662. }
  3663. if(tx_status & TX_HRT_BEAT)
  3664. {
  3665. #ifdef DEBUG_TX_FAIL
  3666. printk(KERN_DEBUG "%s: wv_interrupt(): heart beat\n", dev->name);
  3667. #endif
  3668. lp->stats.tx_heartbeat_errors++;
  3669. }
  3670. if(tx_status & TX_DEFER)
  3671. {
  3672. #ifdef DEBUG_TX_FAIL
  3673. printk(KERN_DEBUG "%s: wv_interrupt(): channel jammed\n",
  3674. dev->name);
  3675. #endif
  3676. }
  3677. /* Ignore late collisions since they're more likely to happen
  3678. * here (the WaveLAN design prevents the LAN controller from
  3679. * receiving while it is transmitting). We take action only when
  3680. * the maximum retransmit attempts is exceeded.
  3681. */
  3682. if(tx_status & TX_COLL)
  3683. {
  3684. if(tx_status & TX_MAX_COL)
  3685. {
  3686. #ifdef DEBUG_TX_FAIL
  3687. printk(KERN_DEBUG "%s: wv_interrupt(): channel congestion\n",
  3688. dev->name);
  3689. #endif
  3690. if(!(tx_status & TX_NCOL_MASK))
  3691. {
  3692. lp->stats.collisions += 0x10;
  3693. }
  3694. }
  3695. }
  3696. } /* if(!(tx_status & TX_OK)) */
  3697. lp->stats.collisions += (tx_status & TX_NCOL_MASK);
  3698. lp->stats.tx_packets++;
  3699. netif_wake_queue(dev);
  3700. outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
  3701. }
  3702. else /* if interrupt = transmit done or retransmit done */
  3703. {
  3704. #ifdef DEBUG_INTERRUPT_ERROR
  3705. printk(KERN_INFO "wavelan_cs: unknown interrupt, status0 = %02x\n",
  3706. status0);
  3707. #endif
  3708. outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
  3709. }
  3710. } /* while(1) */
  3711. spin_unlock(&lp->spinlock);
  3712. #ifdef DEBUG_INTERRUPT_TRACE
  3713. printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name);
  3714. #endif
  3715. /* We always return IRQ_HANDLED, because we will receive empty
  3716. * interrupts under normal operations. Anyway, it doesn't matter
  3717. * as we are dealing with an ISA interrupt that can't be shared.
  3718. *
  3719. * Explanation : under heavy receive, the following happens :
  3720. * ->wavelan_interrupt()
  3721. * (status0 & SR0_INTERRUPT) != 0
  3722. * ->wv_packet_rcv()
  3723. * (status0 & SR0_INTERRUPT) != 0
  3724. * ->wv_packet_rcv()
  3725. * (status0 & SR0_INTERRUPT) == 0 // i.e. no more event
  3726. * <-wavelan_interrupt()
  3727. * ->wavelan_interrupt()
  3728. * (status0 & SR0_INTERRUPT) == 0 // i.e. empty interrupt
  3729. * <-wavelan_interrupt()
  3730. * Jean II */
  3731. return IRQ_HANDLED;
  3732. } /* wv_interrupt */
  3733. /*------------------------------------------------------------------*/
  3734. /*
  3735. * Watchdog: when we start a transmission, a timer is set for us in the
  3736. * kernel. If the transmission completes, this timer is disabled. If
  3737. * the timer expires, we are called and we try to unlock the hardware.
  3738. *
  3739. * Note : This watchdog is move clever than the one in the ISA driver,
  3740. * because it try to abort the current command before reseting
  3741. * everything...
  3742. * On the other hand, it's a bit simpler, because we don't have to
  3743. * deal with the multiple Tx buffers...
  3744. */
  3745. static void
  3746. wavelan_watchdog(struct net_device * dev)
  3747. {
  3748. net_local * lp = netdev_priv(dev);
  3749. kio_addr_t base = dev->base_addr;
  3750. unsigned long flags;
  3751. int aborted = FALSE;
  3752. #ifdef DEBUG_INTERRUPT_TRACE
  3753. printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name);
  3754. #endif
  3755. #ifdef DEBUG_INTERRUPT_ERROR
  3756. printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n",
  3757. dev->name);
  3758. #endif
  3759. spin_lock_irqsave(&lp->spinlock, flags);
  3760. /* Ask to abort the current command */
  3761. outb(OP0_ABORT, LCCR(base));
  3762. /* Wait for the end of the command (a bit hackish) */
  3763. if(wv_82593_cmd(dev, "wavelan_watchdog(): abort",
  3764. OP0_NOP | CR0_STATUS_3, SR0_EXECUTION_ABORTED))
  3765. aborted = TRUE;
  3766. /* Release spinlock here so that wv_hw_reset() can grab it */
  3767. spin_unlock_irqrestore(&lp->spinlock, flags);
  3768. /* Check if we were successful in aborting it */
  3769. if(!aborted)
  3770. {
  3771. /* It seem that it wasn't enough */
  3772. #ifdef DEBUG_INTERRUPT_ERROR
  3773. printk(KERN_INFO "%s: wavelan_watchdog: abort failed, trying reset\n",
  3774. dev->name);
  3775. #endif
  3776. wv_hw_reset(dev);
  3777. }
  3778. #ifdef DEBUG_PSA_SHOW
  3779. {
  3780. psa_t psa;
  3781. psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
  3782. wv_psa_show(&psa);
  3783. }
  3784. #endif
  3785. #ifdef DEBUG_MMC_SHOW
  3786. wv_mmc_show(dev);
  3787. #endif
  3788. #ifdef DEBUG_I82593_SHOW
  3789. wv_ru_show(dev);
  3790. #endif
  3791. /* We are no more waiting for something... */
  3792. netif_wake_queue(dev);
  3793. #ifdef DEBUG_INTERRUPT_TRACE
  3794. printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name);
  3795. #endif
  3796. }
  3797. /********************* CONFIGURATION CALLBACKS *********************/
  3798. /*
  3799. * Here are the functions called by the pcmcia package (cardmgr) and
  3800. * linux networking (NET3) for initialization, configuration and
  3801. * deinstallations of the Wavelan Pcmcia Hardware.
  3802. */
  3803. /*------------------------------------------------------------------*/
  3804. /*
  3805. * Configure and start up the WaveLAN PCMCIA adaptor.
  3806. * Called by NET3 when it "open" the device.
  3807. */
  3808. static int
  3809. wavelan_open(struct net_device * dev)
  3810. {
  3811. net_local * lp = netdev_priv(dev);
  3812. struct pcmcia_device * link = lp->link;
  3813. kio_addr_t base = dev->base_addr;
  3814. #ifdef DEBUG_CALLBACK_TRACE
  3815. printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name,
  3816. (unsigned int) dev);
  3817. #endif
  3818. /* Check if the modem is powered up (wavelan_close() power it down */
  3819. if(hasr_read(base) & HASR_NO_CLK)
  3820. {
  3821. /* Power up (power up time is 250us) */
  3822. hacr_write(base, HACR_DEFAULT);
  3823. /* Check if the module has been powered up... */
  3824. if(hasr_read(base) & HASR_NO_CLK)
  3825. {
  3826. #ifdef DEBUG_CONFIG_ERRORS
  3827. printk(KERN_WARNING "%s: wavelan_open(): modem not connected\n",
  3828. dev->name);
  3829. #endif
  3830. return FALSE;
  3831. }
  3832. }
  3833. /* Start reception and declare the driver ready */
  3834. if(!lp->configured)
  3835. return FALSE;
  3836. if(!wv_ru_start(dev))
  3837. wv_hw_reset(dev); /* If problem : reset */
  3838. netif_start_queue(dev);
  3839. /* Mark the device as used */
  3840. link->open++;
  3841. #ifdef WAVELAN_ROAMING
  3842. if(do_roaming)
  3843. wv_roam_init(dev);
  3844. #endif /* WAVELAN_ROAMING */
  3845. #ifdef DEBUG_CALLBACK_TRACE
  3846. printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name);
  3847. #endif
  3848. return 0;
  3849. }
  3850. /*------------------------------------------------------------------*/
  3851. /*
  3852. * Shutdown the WaveLAN PCMCIA adaptor.
  3853. * Called by NET3 when it "close" the device.
  3854. */
  3855. static int
  3856. wavelan_close(struct net_device * dev)
  3857. {
  3858. struct pcmcia_device * link = ((net_local *)netdev_priv(dev))->link;
  3859. kio_addr_t base = dev->base_addr;
  3860. #ifdef DEBUG_CALLBACK_TRACE
  3861. printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name,
  3862. (unsigned int) dev);
  3863. #endif
  3864. /* If the device isn't open, then nothing to do */
  3865. if(!link->open)
  3866. {
  3867. #ifdef DEBUG_CONFIG_INFO
  3868. printk(KERN_DEBUG "%s: wavelan_close(): device not open\n", dev->name);
  3869. #endif
  3870. return 0;
  3871. }
  3872. #ifdef WAVELAN_ROAMING
  3873. /* Cleanup of roaming stuff... */
  3874. if(do_roaming)
  3875. wv_roam_cleanup(dev);
  3876. #endif /* WAVELAN_ROAMING */
  3877. link->open--;
  3878. /* If the card is still present */
  3879. if(netif_running(dev))
  3880. {
  3881. netif_stop_queue(dev);
  3882. /* Stop receiving new messages and wait end of transmission */
  3883. wv_ru_stop(dev);
  3884. /* Power down the module */
  3885. hacr_write(base, HACR_DEFAULT & (~HACR_PWR_STAT));
  3886. }
  3887. #ifdef DEBUG_CALLBACK_TRACE
  3888. printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name);
  3889. #endif
  3890. return 0;
  3891. }
  3892. /*------------------------------------------------------------------*/
  3893. /*
  3894. * wavelan_attach() creates an "instance" of the driver, allocating
  3895. * local data structures for one device (one interface). The device
  3896. * is registered with Card Services.
  3897. *
  3898. * The dev_link structure is initialized, but we don't actually
  3899. * configure the card at this point -- we wait until we receive a
  3900. * card insertion event.
  3901. */
  3902. static int
  3903. wavelan_probe(struct pcmcia_device *p_dev)
  3904. {
  3905. struct net_device * dev; /* Interface generic data */
  3906. net_local * lp; /* Interface specific data */
  3907. int ret;
  3908. #ifdef DEBUG_CALLBACK_TRACE
  3909. printk(KERN_DEBUG "-> wavelan_attach()\n");
  3910. #endif
  3911. /* The io structure describes IO port mapping */
  3912. p_dev->io.NumPorts1 = 8;
  3913. p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  3914. p_dev->io.IOAddrLines = 3;
  3915. /* Interrupt setup */
  3916. p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
  3917. p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
  3918. p_dev->irq.Handler = wavelan_interrupt;
  3919. /* General socket configuration */
  3920. p_dev->conf.Attributes = CONF_ENABLE_IRQ;
  3921. p_dev->conf.IntType = INT_MEMORY_AND_IO;
  3922. /* Allocate the generic data structure */
  3923. dev = alloc_etherdev(sizeof(net_local));
  3924. if (!dev)
  3925. return -ENOMEM;
  3926. p_dev->priv = p_dev->irq.Instance = dev;
  3927. lp = netdev_priv(dev);
  3928. /* Init specific data */
  3929. lp->configured = 0;
  3930. lp->reconfig_82593 = FALSE;
  3931. lp->nresets = 0;
  3932. /* Multicast stuff */
  3933. lp->promiscuous = 0;
  3934. lp->allmulticast = 0;
  3935. lp->mc_count = 0;
  3936. /* Init spinlock */
  3937. spin_lock_init(&lp->spinlock);
  3938. /* back links */
  3939. lp->dev = dev;
  3940. /* wavelan NET3 callbacks */
  3941. dev->open = &wavelan_open;
  3942. dev->stop = &wavelan_close;
  3943. dev->hard_start_xmit = &wavelan_packet_xmit;
  3944. dev->get_stats = &wavelan_get_stats;
  3945. dev->set_multicast_list = &wavelan_set_multicast_list;
  3946. #ifdef SET_MAC_ADDRESS
  3947. dev->set_mac_address = &wavelan_set_mac_address;
  3948. #endif /* SET_MAC_ADDRESS */
  3949. /* Set the watchdog timer */
  3950. dev->tx_timeout = &wavelan_watchdog;
  3951. dev->watchdog_timeo = WATCHDOG_JIFFIES;
  3952. SET_ETHTOOL_OPS(dev, &ops);
  3953. dev->wireless_handlers = &wavelan_handler_def;
  3954. lp->wireless_data.spy_data = &lp->spy_data;
  3955. dev->wireless_data = &lp->wireless_data;
  3956. /* Other specific data */
  3957. dev->mtu = WAVELAN_MTU;
  3958. ret = wv_pcmcia_config(p_dev);
  3959. if (ret)
  3960. return ret;
  3961. ret = wv_hw_config(dev);
  3962. if (ret) {
  3963. dev->irq = 0;
  3964. pcmcia_disable_device(p_dev);
  3965. return ret;
  3966. }
  3967. wv_init_info(dev);
  3968. #ifdef DEBUG_CALLBACK_TRACE
  3969. printk(KERN_DEBUG "<- wavelan_attach()\n");
  3970. #endif
  3971. return 0;
  3972. }
  3973. /*------------------------------------------------------------------*/
  3974. /*
  3975. * This deletes a driver "instance". The device is de-registered with
  3976. * Card Services. If it has been released, all local data structures
  3977. * are freed. Otherwise, the structures will be freed when the device
  3978. * is released.
  3979. */
  3980. static void
  3981. wavelan_detach(struct pcmcia_device *link)
  3982. {
  3983. #ifdef DEBUG_CALLBACK_TRACE
  3984. printk(KERN_DEBUG "-> wavelan_detach(0x%p)\n", link);
  3985. #endif
  3986. /* Some others haven't done their job : give them another chance */
  3987. wv_pcmcia_release(link);
  3988. /* Free pieces */
  3989. if(link->priv)
  3990. {
  3991. struct net_device * dev = (struct net_device *) link->priv;
  3992. /* Remove ourselves from the kernel list of ethernet devices */
  3993. /* Warning : can't be called from interrupt, timer or wavelan_close() */
  3994. if (link->dev_node)
  3995. unregister_netdev(dev);
  3996. link->dev_node = NULL;
  3997. ((net_local *)netdev_priv(dev))->link = NULL;
  3998. ((net_local *)netdev_priv(dev))->dev = NULL;
  3999. free_netdev(dev);
  4000. }
  4001. #ifdef DEBUG_CALLBACK_TRACE
  4002. printk(KERN_DEBUG "<- wavelan_detach()\n");
  4003. #endif
  4004. }
  4005. static int wavelan_suspend(struct pcmcia_device *link)
  4006. {
  4007. struct net_device * dev = (struct net_device *) link->priv;
  4008. /* NB: wavelan_close will be called, but too late, so we are
  4009. * obliged to close nicely the wavelan here. David, could you
  4010. * close the device before suspending them ? And, by the way,
  4011. * could you, on resume, add a "route add -net ..." after the
  4012. * ifconfig up ? Thanks... */
  4013. /* Stop receiving new messages and wait end of transmission */
  4014. wv_ru_stop(dev);
  4015. if (link->open)
  4016. netif_device_detach(dev);
  4017. /* Power down the module */
  4018. hacr_write(dev->base_addr, HACR_DEFAULT & (~HACR_PWR_STAT));
  4019. return 0;
  4020. }
  4021. static int wavelan_resume(struct pcmcia_device *link)
  4022. {
  4023. struct net_device * dev = (struct net_device *) link->priv;
  4024. if (link->open) {
  4025. wv_hw_reset(dev);
  4026. netif_device_attach(dev);
  4027. }
  4028. return 0;
  4029. }
  4030. static struct pcmcia_device_id wavelan_ids[] = {
  4031. PCMCIA_DEVICE_PROD_ID12("AT&T","WaveLAN/PCMCIA", 0xe7c5affd, 0x1bc50975),
  4032. PCMCIA_DEVICE_PROD_ID12("Digital", "RoamAbout/DS", 0x9999ab35, 0x00d05e06),
  4033. PCMCIA_DEVICE_PROD_ID12("Lucent Technologies", "WaveLAN/PCMCIA", 0x23eb9949, 0x1bc50975),
  4034. PCMCIA_DEVICE_PROD_ID12("NCR", "WaveLAN/PCMCIA", 0x24358cd4, 0x1bc50975),
  4035. PCMCIA_DEVICE_NULL,
  4036. };
  4037. MODULE_DEVICE_TABLE(pcmcia, wavelan_ids);
  4038. static struct pcmcia_driver wavelan_driver = {
  4039. .owner = THIS_MODULE,
  4040. .drv = {
  4041. .name = "wavelan_cs",
  4042. },
  4043. .probe = wavelan_probe,
  4044. .remove = wavelan_detach,
  4045. .id_table = wavelan_ids,
  4046. .suspend = wavelan_suspend,
  4047. .resume = wavelan_resume,
  4048. };
  4049. static int __init
  4050. init_wavelan_cs(void)
  4051. {
  4052. return pcmcia_register_driver(&wavelan_driver);
  4053. }
  4054. static void __exit
  4055. exit_wavelan_cs(void)
  4056. {
  4057. pcmcia_unregister_driver(&wavelan_driver);
  4058. }
  4059. module_init(init_wavelan_cs);
  4060. module_exit(exit_wavelan_cs);