wavelan_cs.c 132 KB

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