wavelan_cs.c 131 KB

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