wavelan_cs.c 139 KB

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