wavelan_cs.c 132 KB

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