wavelan_cs.c 136 KB

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