wavelan_cs.c 132 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685
  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. /* Tell the kernel that we are doing a really bad job... */
  1224. dev->flags |= IFF_PROMISC;
  1225. }
  1226. }
  1227. else
  1228. /* If all multicast addresses
  1229. * or too much multicast addresses for the hardware filter */
  1230. if((dev->flags & IFF_ALLMULTI) ||
  1231. (dev->mc_count > I82593_MAX_MULTICAST_ADDRESSES))
  1232. {
  1233. /*
  1234. * Disable promiscuous mode, but active the all multicast mode
  1235. */
  1236. if(!lp->allmulticast)
  1237. {
  1238. lp->promiscuous = 0;
  1239. lp->allmulticast = 1;
  1240. lp->mc_count = 0;
  1241. wv_82593_reconfig(dev);
  1242. /* Tell the kernel that we are doing a really bad job... */
  1243. dev->flags |= IFF_ALLMULTI;
  1244. }
  1245. }
  1246. else
  1247. /* If there is some multicast addresses to send */
  1248. if(dev->mc_list != (struct dev_mc_list *) NULL)
  1249. {
  1250. /*
  1251. * Disable promiscuous mode, but receive all packets
  1252. * in multicast list
  1253. */
  1254. #ifdef MULTICAST_AVOID
  1255. if(lp->promiscuous || lp->allmulticast ||
  1256. (dev->mc_count != lp->mc_count))
  1257. #endif
  1258. {
  1259. lp->promiscuous = 0;
  1260. lp->allmulticast = 0;
  1261. lp->mc_count = dev->mc_count;
  1262. wv_82593_reconfig(dev);
  1263. }
  1264. }
  1265. else
  1266. {
  1267. /*
  1268. * Switch to normal mode: disable promiscuous mode and
  1269. * clear the multicast list.
  1270. */
  1271. if(lp->promiscuous || lp->mc_count == 0)
  1272. {
  1273. lp->promiscuous = 0;
  1274. lp->allmulticast = 0;
  1275. lp->mc_count = 0;
  1276. wv_82593_reconfig(dev);
  1277. }
  1278. }
  1279. #ifdef DEBUG_IOCTL_TRACE
  1280. printk(KERN_DEBUG "%s: <-wavelan_set_multicast_list()\n", dev->name);
  1281. #endif
  1282. }
  1283. /*------------------------------------------------------------------*/
  1284. /*
  1285. * This function doesn't exist...
  1286. * (Note : it was a nice way to test the reconfigure stuff...)
  1287. */
  1288. #ifdef SET_MAC_ADDRESS
  1289. static int
  1290. wavelan_set_mac_address(struct net_device * dev,
  1291. void * addr)
  1292. {
  1293. struct sockaddr * mac = addr;
  1294. /* Copy the address */
  1295. memcpy(dev->dev_addr, mac->sa_data, WAVELAN_ADDR_SIZE);
  1296. /* Reconfig the beast */
  1297. wv_82593_reconfig(dev);
  1298. return 0;
  1299. }
  1300. #endif /* SET_MAC_ADDRESS */
  1301. /*------------------------------------------------------------------*/
  1302. /*
  1303. * Frequency setting (for hardware able of it)
  1304. * It's a bit complicated and you don't really want to look into it...
  1305. */
  1306. static int
  1307. wv_set_frequency(u_long base, /* i/o port of the card */
  1308. iw_freq * frequency)
  1309. {
  1310. const int BAND_NUM = 10; /* Number of bands */
  1311. long freq = 0L; /* offset to 2.4 GHz in .5 MHz */
  1312. #ifdef DEBUG_IOCTL_INFO
  1313. int i;
  1314. #endif
  1315. /* Setting by frequency */
  1316. /* Theoritically, you may set any frequency between
  1317. * the two limits with a 0.5 MHz precision. In practice,
  1318. * I don't want you to have trouble with local
  1319. * regulations... */
  1320. if((frequency->e == 1) &&
  1321. (frequency->m >= (int) 2.412e8) && (frequency->m <= (int) 2.487e8))
  1322. {
  1323. freq = ((frequency->m / 10000) - 24000L) / 5;
  1324. }
  1325. /* Setting by channel (same as wfreqsel) */
  1326. /* Warning : each channel is 22MHz wide, so some of the channels
  1327. * will interfere... */
  1328. if((frequency->e == 0) &&
  1329. (frequency->m >= 0) && (frequency->m < BAND_NUM))
  1330. {
  1331. /* Get frequency offset. */
  1332. freq = channel_bands[frequency->m] >> 1;
  1333. }
  1334. /* Verify if the frequency is allowed */
  1335. if(freq != 0L)
  1336. {
  1337. u_short table[10]; /* Authorized frequency table */
  1338. /* Read the frequency table */
  1339. fee_read(base, 0x71 /* frequency table */,
  1340. table, 10);
  1341. #ifdef DEBUG_IOCTL_INFO
  1342. printk(KERN_DEBUG "Frequency table :");
  1343. for(i = 0; i < 10; i++)
  1344. {
  1345. printk(" %04X",
  1346. table[i]);
  1347. }
  1348. printk("\n");
  1349. #endif
  1350. /* Look in the table if the frequency is allowed */
  1351. if(!(table[9 - ((freq - 24) / 16)] &
  1352. (1 << ((freq - 24) % 16))))
  1353. return -EINVAL; /* not allowed */
  1354. }
  1355. else
  1356. return -EINVAL;
  1357. /* If we get a usable frequency */
  1358. if(freq != 0L)
  1359. {
  1360. unsigned short area[16];
  1361. unsigned short dac[2];
  1362. unsigned short area_verify[16];
  1363. unsigned short dac_verify[2];
  1364. /* Corresponding gain (in the power adjust value table)
  1365. * see AT&T Wavelan Data Manual, REF 407-024689/E, page 3-8
  1366. * & WCIN062D.DOC, page 6.2.9 */
  1367. unsigned short power_limit[] = { 40, 80, 120, 160, 0 };
  1368. int power_band = 0; /* Selected band */
  1369. unsigned short power_adjust; /* Correct value */
  1370. /* Search for the gain */
  1371. power_band = 0;
  1372. while((freq > power_limit[power_band]) &&
  1373. (power_limit[++power_band] != 0))
  1374. ;
  1375. /* Read the first area */
  1376. fee_read(base, 0x00,
  1377. area, 16);
  1378. /* Read the DAC */
  1379. fee_read(base, 0x60,
  1380. dac, 2);
  1381. /* Read the new power adjust value */
  1382. fee_read(base, 0x6B - (power_band >> 1),
  1383. &power_adjust, 1);
  1384. if(power_band & 0x1)
  1385. power_adjust >>= 8;
  1386. else
  1387. power_adjust &= 0xFF;
  1388. #ifdef DEBUG_IOCTL_INFO
  1389. printk(KERN_DEBUG "Wavelan EEprom Area 1 :");
  1390. for(i = 0; i < 16; i++)
  1391. {
  1392. printk(" %04X",
  1393. area[i]);
  1394. }
  1395. printk("\n");
  1396. printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n",
  1397. dac[0], dac[1]);
  1398. #endif
  1399. /* Frequency offset (for info only...) */
  1400. area[0] = ((freq << 5) & 0xFFE0) | (area[0] & 0x1F);
  1401. /* Receiver Principle main divider coefficient */
  1402. area[3] = (freq >> 1) + 2400L - 352L;
  1403. area[2] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
  1404. /* Transmitter Main divider coefficient */
  1405. area[13] = (freq >> 1) + 2400L;
  1406. area[12] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
  1407. /* Others part of the area are flags, bit streams or unused... */
  1408. /* Set the value in the DAC */
  1409. dac[1] = ((power_adjust >> 1) & 0x7F) | (dac[1] & 0xFF80);
  1410. dac[0] = ((power_adjust & 0x1) << 4) | (dac[0] & 0xFFEF);
  1411. /* Write the first area */
  1412. fee_write(base, 0x00,
  1413. area, 16);
  1414. /* Write the DAC */
  1415. fee_write(base, 0x60,
  1416. dac, 2);
  1417. /* We now should verify here that the EEprom writing was ok */
  1418. /* ReRead the first area */
  1419. fee_read(base, 0x00,
  1420. area_verify, 16);
  1421. /* ReRead the DAC */
  1422. fee_read(base, 0x60,
  1423. dac_verify, 2);
  1424. /* Compare */
  1425. if(memcmp(area, area_verify, 16 * 2) ||
  1426. memcmp(dac, dac_verify, 2 * 2))
  1427. {
  1428. #ifdef DEBUG_IOCTL_ERROR
  1429. printk(KERN_INFO "Wavelan: wv_set_frequency : unable to write new frequency to EEprom (?)\n");
  1430. #endif
  1431. return -EOPNOTSUPP;
  1432. }
  1433. /* We must download the frequency parameters to the
  1434. * synthetisers (from the EEprom - area 1)
  1435. * Note : as the EEprom is auto decremented, we set the end
  1436. * if the area... */
  1437. mmc_out(base, mmwoff(0, mmw_fee_addr), 0x0F);
  1438. mmc_out(base, mmwoff(0, mmw_fee_ctrl),
  1439. MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
  1440. /* Wait until the download is finished */
  1441. fee_wait(base, 100, 100);
  1442. /* We must now download the power adjust value (gain) to
  1443. * the synthetisers (from the EEprom - area 7 - DAC) */
  1444. mmc_out(base, mmwoff(0, mmw_fee_addr), 0x61);
  1445. mmc_out(base, mmwoff(0, mmw_fee_ctrl),
  1446. MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
  1447. /* Wait until the download is finished */
  1448. fee_wait(base, 100, 100);
  1449. #ifdef DEBUG_IOCTL_INFO
  1450. /* Verification of what we have done... */
  1451. printk(KERN_DEBUG "Wavelan EEprom Area 1 :");
  1452. for(i = 0; i < 16; i++)
  1453. {
  1454. printk(" %04X",
  1455. area_verify[i]);
  1456. }
  1457. printk("\n");
  1458. printk(KERN_DEBUG "Wavelan EEprom DAC : %04X %04X\n",
  1459. dac_verify[0], dac_verify[1]);
  1460. #endif
  1461. return 0;
  1462. }
  1463. else
  1464. return -EINVAL; /* Bah, never get there... */
  1465. }
  1466. /*------------------------------------------------------------------*/
  1467. /*
  1468. * Give the list of available frequencies
  1469. */
  1470. static int
  1471. wv_frequency_list(u_long base, /* i/o port of the card */
  1472. iw_freq * list, /* List of frequency to fill */
  1473. int max) /* Maximum number of frequencies */
  1474. {
  1475. u_short table[10]; /* Authorized frequency table */
  1476. long freq = 0L; /* offset to 2.4 GHz in .5 MHz + 12 MHz */
  1477. int i; /* index in the table */
  1478. const int BAND_NUM = 10; /* Number of bands */
  1479. int c = 0; /* Channel number */
  1480. /* Read the frequency table */
  1481. fee_read(base, 0x71 /* frequency table */,
  1482. table, 10);
  1483. /* Look all frequencies */
  1484. i = 0;
  1485. for(freq = 0; freq < 150; freq++)
  1486. /* Look in the table if the frequency is allowed */
  1487. if(table[9 - (freq / 16)] & (1 << (freq % 16)))
  1488. {
  1489. /* Compute approximate channel number */
  1490. while((((channel_bands[c] >> 1) - 24) < freq) &&
  1491. (c < BAND_NUM))
  1492. c++;
  1493. list[i].i = c; /* Set the list index */
  1494. /* put in the list */
  1495. list[i].m = (((freq + 24) * 5) + 24000L) * 10000;
  1496. list[i++].e = 1;
  1497. /* Check number */
  1498. if(i >= max)
  1499. return(i);
  1500. }
  1501. return(i);
  1502. }
  1503. #ifdef IW_WIRELESS_SPY
  1504. /*------------------------------------------------------------------*/
  1505. /*
  1506. * Gather wireless spy statistics : for each packet, compare the source
  1507. * address with out list, and if match, get the stats...
  1508. * Sorry, but this function really need wireless extensions...
  1509. */
  1510. static inline void
  1511. wl_spy_gather(struct net_device * dev,
  1512. u_char * mac, /* MAC address */
  1513. u_char * stats) /* Statistics to gather */
  1514. {
  1515. struct iw_quality wstats;
  1516. wstats.qual = stats[2] & MMR_SGNL_QUAL;
  1517. wstats.level = stats[0] & MMR_SIGNAL_LVL;
  1518. wstats.noise = stats[1] & MMR_SILENCE_LVL;
  1519. wstats.updated = 0x7;
  1520. /* Update spy records */
  1521. wireless_spy_update(dev, mac, &wstats);
  1522. }
  1523. #endif /* IW_WIRELESS_SPY */
  1524. #ifdef HISTOGRAM
  1525. /*------------------------------------------------------------------*/
  1526. /*
  1527. * This function calculate an histogram on the signal level.
  1528. * As the noise is quite constant, it's like doing it on the SNR.
  1529. * We have defined a set of interval (lp->his_range), and each time
  1530. * the level goes in that interval, we increment the count (lp->his_sum).
  1531. * With this histogram you may detect if one wavelan is really weak,
  1532. * or you may also calculate the mean and standard deviation of the level...
  1533. */
  1534. static inline void
  1535. wl_his_gather(struct net_device * dev,
  1536. u_char * stats) /* Statistics to gather */
  1537. {
  1538. net_local * lp = netdev_priv(dev);
  1539. u_char level = stats[0] & MMR_SIGNAL_LVL;
  1540. int i;
  1541. /* Find the correct interval */
  1542. i = 0;
  1543. while((i < (lp->his_number - 1)) && (level >= lp->his_range[i++]))
  1544. ;
  1545. /* Increment interval counter */
  1546. (lp->his_sum[i])++;
  1547. }
  1548. #endif /* HISTOGRAM */
  1549. static void wl_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  1550. {
  1551. strncpy(info->driver, "wavelan_cs", sizeof(info->driver)-1);
  1552. }
  1553. static const struct ethtool_ops ops = {
  1554. .get_drvinfo = wl_get_drvinfo
  1555. };
  1556. /*------------------------------------------------------------------*/
  1557. /*
  1558. * Wireless Handler : get protocol name
  1559. */
  1560. static int wavelan_get_name(struct net_device *dev,
  1561. struct iw_request_info *info,
  1562. union iwreq_data *wrqu,
  1563. char *extra)
  1564. {
  1565. strcpy(wrqu->name, "WaveLAN");
  1566. return 0;
  1567. }
  1568. /*------------------------------------------------------------------*/
  1569. /*
  1570. * Wireless Handler : set NWID
  1571. */
  1572. static int wavelan_set_nwid(struct net_device *dev,
  1573. struct iw_request_info *info,
  1574. union iwreq_data *wrqu,
  1575. char *extra)
  1576. {
  1577. unsigned int base = dev->base_addr;
  1578. net_local *lp = netdev_priv(dev);
  1579. psa_t psa;
  1580. mm_t m;
  1581. unsigned long flags;
  1582. int ret = 0;
  1583. /* Disable interrupts and save flags. */
  1584. spin_lock_irqsave(&lp->spinlock, flags);
  1585. /* Set NWID in WaveLAN. */
  1586. if (!wrqu->nwid.disabled) {
  1587. /* Set NWID in psa */
  1588. psa.psa_nwid[0] = (wrqu->nwid.value & 0xFF00) >> 8;
  1589. psa.psa_nwid[1] = wrqu->nwid.value & 0xFF;
  1590. psa.psa_nwid_select = 0x01;
  1591. psa_write(dev,
  1592. (char *) psa.psa_nwid - (char *) &psa,
  1593. (unsigned char *) psa.psa_nwid, 3);
  1594. /* Set NWID in mmc. */
  1595. m.w.mmw_netw_id_l = psa.psa_nwid[1];
  1596. m.w.mmw_netw_id_h = psa.psa_nwid[0];
  1597. mmc_write(base,
  1598. (char *) &m.w.mmw_netw_id_l -
  1599. (char *) &m,
  1600. (unsigned char *) &m.w.mmw_netw_id_l, 2);
  1601. mmc_out(base, mmwoff(0, mmw_loopt_sel), 0x00);
  1602. } else {
  1603. /* Disable NWID in the psa. */
  1604. psa.psa_nwid_select = 0x00;
  1605. psa_write(dev,
  1606. (char *) &psa.psa_nwid_select -
  1607. (char *) &psa,
  1608. (unsigned char *) &psa.psa_nwid_select,
  1609. 1);
  1610. /* Disable NWID in the mmc (no filtering). */
  1611. mmc_out(base, mmwoff(0, mmw_loopt_sel),
  1612. MMW_LOOPT_SEL_DIS_NWID);
  1613. }
  1614. /* update the Wavelan checksum */
  1615. update_psa_checksum(dev);
  1616. /* Enable interrupts and restore flags. */
  1617. spin_unlock_irqrestore(&lp->spinlock, flags);
  1618. return ret;
  1619. }
  1620. /*------------------------------------------------------------------*/
  1621. /*
  1622. * Wireless Handler : get NWID
  1623. */
  1624. static int wavelan_get_nwid(struct net_device *dev,
  1625. struct iw_request_info *info,
  1626. union iwreq_data *wrqu,
  1627. char *extra)
  1628. {
  1629. net_local *lp = netdev_priv(dev);
  1630. psa_t psa;
  1631. unsigned long flags;
  1632. int ret = 0;
  1633. /* Disable interrupts and save flags. */
  1634. spin_lock_irqsave(&lp->spinlock, flags);
  1635. /* Read the NWID. */
  1636. psa_read(dev,
  1637. (char *) psa.psa_nwid - (char *) &psa,
  1638. (unsigned char *) psa.psa_nwid, 3);
  1639. wrqu->nwid.value = (psa.psa_nwid[0] << 8) + psa.psa_nwid[1];
  1640. wrqu->nwid.disabled = !(psa.psa_nwid_select);
  1641. wrqu->nwid.fixed = 1; /* Superfluous */
  1642. /* Enable interrupts and restore flags. */
  1643. spin_unlock_irqrestore(&lp->spinlock, flags);
  1644. return ret;
  1645. }
  1646. /*------------------------------------------------------------------*/
  1647. /*
  1648. * Wireless Handler : set frequency
  1649. */
  1650. static int wavelan_set_freq(struct net_device *dev,
  1651. struct iw_request_info *info,
  1652. union iwreq_data *wrqu,
  1653. char *extra)
  1654. {
  1655. unsigned int base = dev->base_addr;
  1656. net_local *lp = netdev_priv(dev);
  1657. unsigned long flags;
  1658. int ret;
  1659. /* Disable interrupts and save flags. */
  1660. spin_lock_irqsave(&lp->spinlock, flags);
  1661. /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
  1662. if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
  1663. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
  1664. ret = wv_set_frequency(base, &(wrqu->freq));
  1665. else
  1666. ret = -EOPNOTSUPP;
  1667. /* Enable interrupts and restore flags. */
  1668. spin_unlock_irqrestore(&lp->spinlock, flags);
  1669. return ret;
  1670. }
  1671. /*------------------------------------------------------------------*/
  1672. /*
  1673. * Wireless Handler : get frequency
  1674. */
  1675. static int wavelan_get_freq(struct net_device *dev,
  1676. struct iw_request_info *info,
  1677. union iwreq_data *wrqu,
  1678. char *extra)
  1679. {
  1680. unsigned int base = dev->base_addr;
  1681. net_local *lp = netdev_priv(dev);
  1682. psa_t psa;
  1683. unsigned long flags;
  1684. int ret = 0;
  1685. /* Disable interrupts and save flags. */
  1686. spin_lock_irqsave(&lp->spinlock, flags);
  1687. /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable).
  1688. * Does it work for everybody, especially old cards? */
  1689. if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
  1690. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
  1691. unsigned short freq;
  1692. /* Ask the EEPROM to read the frequency from the first area. */
  1693. fee_read(base, 0x00, &freq, 1);
  1694. wrqu->freq.m = ((freq >> 5) * 5 + 24000L) * 10000;
  1695. wrqu->freq.e = 1;
  1696. } else {
  1697. psa_read(dev,
  1698. (char *) &psa.psa_subband - (char *) &psa,
  1699. (unsigned char *) &psa.psa_subband, 1);
  1700. if (psa.psa_subband <= 4) {
  1701. wrqu->freq.m = fixed_bands[psa.psa_subband];
  1702. wrqu->freq.e = (psa.psa_subband != 0);
  1703. } else
  1704. ret = -EOPNOTSUPP;
  1705. }
  1706. /* Enable interrupts and restore flags. */
  1707. spin_unlock_irqrestore(&lp->spinlock, flags);
  1708. return ret;
  1709. }
  1710. /*------------------------------------------------------------------*/
  1711. /*
  1712. * Wireless Handler : set level threshold
  1713. */
  1714. static int wavelan_set_sens(struct net_device *dev,
  1715. struct iw_request_info *info,
  1716. union iwreq_data *wrqu,
  1717. char *extra)
  1718. {
  1719. unsigned int base = dev->base_addr;
  1720. net_local *lp = netdev_priv(dev);
  1721. psa_t psa;
  1722. unsigned long flags;
  1723. int ret = 0;
  1724. /* Disable interrupts and save flags. */
  1725. spin_lock_irqsave(&lp->spinlock, flags);
  1726. /* Set the level threshold. */
  1727. /* We should complain loudly if wrqu->sens.fixed = 0, because we
  1728. * can't set auto mode... */
  1729. psa.psa_thr_pre_set = wrqu->sens.value & 0x3F;
  1730. psa_write(dev,
  1731. (char *) &psa.psa_thr_pre_set - (char *) &psa,
  1732. (unsigned char *) &psa.psa_thr_pre_set, 1);
  1733. /* update the Wavelan checksum */
  1734. update_psa_checksum(dev);
  1735. mmc_out(base, mmwoff(0, mmw_thr_pre_set),
  1736. psa.psa_thr_pre_set);
  1737. /* Enable interrupts and restore flags. */
  1738. spin_unlock_irqrestore(&lp->spinlock, flags);
  1739. return ret;
  1740. }
  1741. /*------------------------------------------------------------------*/
  1742. /*
  1743. * Wireless Handler : get level threshold
  1744. */
  1745. static int wavelan_get_sens(struct net_device *dev,
  1746. struct iw_request_info *info,
  1747. union iwreq_data *wrqu,
  1748. char *extra)
  1749. {
  1750. net_local *lp = netdev_priv(dev);
  1751. psa_t psa;
  1752. unsigned long flags;
  1753. int ret = 0;
  1754. /* Disable interrupts and save flags. */
  1755. spin_lock_irqsave(&lp->spinlock, flags);
  1756. /* Read the level threshold. */
  1757. psa_read(dev,
  1758. (char *) &psa.psa_thr_pre_set - (char *) &psa,
  1759. (unsigned char *) &psa.psa_thr_pre_set, 1);
  1760. wrqu->sens.value = psa.psa_thr_pre_set & 0x3F;
  1761. wrqu->sens.fixed = 1;
  1762. /* Enable interrupts and restore flags. */
  1763. spin_unlock_irqrestore(&lp->spinlock, flags);
  1764. return ret;
  1765. }
  1766. /*------------------------------------------------------------------*/
  1767. /*
  1768. * Wireless Handler : set encryption key
  1769. */
  1770. static int wavelan_set_encode(struct net_device *dev,
  1771. struct iw_request_info *info,
  1772. union iwreq_data *wrqu,
  1773. char *extra)
  1774. {
  1775. unsigned int base = dev->base_addr;
  1776. net_local *lp = netdev_priv(dev);
  1777. unsigned long flags;
  1778. psa_t psa;
  1779. int ret = 0;
  1780. /* Disable interrupts and save flags. */
  1781. spin_lock_irqsave(&lp->spinlock, flags);
  1782. /* Check if capable of encryption */
  1783. if (!mmc_encr(base)) {
  1784. ret = -EOPNOTSUPP;
  1785. }
  1786. /* Check the size of the key */
  1787. if((wrqu->encoding.length != 8) && (wrqu->encoding.length != 0)) {
  1788. ret = -EINVAL;
  1789. }
  1790. if(!ret) {
  1791. /* Basic checking... */
  1792. if (wrqu->encoding.length == 8) {
  1793. /* Copy the key in the driver */
  1794. memcpy(psa.psa_encryption_key, extra,
  1795. wrqu->encoding.length);
  1796. psa.psa_encryption_select = 1;
  1797. psa_write(dev,
  1798. (char *) &psa.psa_encryption_select -
  1799. (char *) &psa,
  1800. (unsigned char *) &psa.
  1801. psa_encryption_select, 8 + 1);
  1802. mmc_out(base, mmwoff(0, mmw_encr_enable),
  1803. MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE);
  1804. mmc_write(base, mmwoff(0, mmw_encr_key),
  1805. (unsigned char *) &psa.
  1806. psa_encryption_key, 8);
  1807. }
  1808. /* disable encryption */
  1809. if (wrqu->encoding.flags & IW_ENCODE_DISABLED) {
  1810. psa.psa_encryption_select = 0;
  1811. psa_write(dev,
  1812. (char *) &psa.psa_encryption_select -
  1813. (char *) &psa,
  1814. (unsigned char *) &psa.
  1815. psa_encryption_select, 1);
  1816. mmc_out(base, mmwoff(0, mmw_encr_enable), 0);
  1817. }
  1818. /* update the Wavelan checksum */
  1819. update_psa_checksum(dev);
  1820. }
  1821. /* Enable interrupts and restore flags. */
  1822. spin_unlock_irqrestore(&lp->spinlock, flags);
  1823. return ret;
  1824. }
  1825. /*------------------------------------------------------------------*/
  1826. /*
  1827. * Wireless Handler : get encryption key
  1828. */
  1829. static int wavelan_get_encode(struct net_device *dev,
  1830. struct iw_request_info *info,
  1831. union iwreq_data *wrqu,
  1832. char *extra)
  1833. {
  1834. unsigned int base = dev->base_addr;
  1835. net_local *lp = netdev_priv(dev);
  1836. psa_t psa;
  1837. unsigned long flags;
  1838. int ret = 0;
  1839. /* Disable interrupts and save flags. */
  1840. spin_lock_irqsave(&lp->spinlock, flags);
  1841. /* Check if encryption is available */
  1842. if (!mmc_encr(base)) {
  1843. ret = -EOPNOTSUPP;
  1844. } else {
  1845. /* Read the encryption key */
  1846. psa_read(dev,
  1847. (char *) &psa.psa_encryption_select -
  1848. (char *) &psa,
  1849. (unsigned char *) &psa.
  1850. psa_encryption_select, 1 + 8);
  1851. /* encryption is enabled ? */
  1852. if (psa.psa_encryption_select)
  1853. wrqu->encoding.flags = IW_ENCODE_ENABLED;
  1854. else
  1855. wrqu->encoding.flags = IW_ENCODE_DISABLED;
  1856. wrqu->encoding.flags |= mmc_encr(base);
  1857. /* Copy the key to the user buffer */
  1858. wrqu->encoding.length = 8;
  1859. memcpy(extra, psa.psa_encryption_key, wrqu->encoding.length);
  1860. }
  1861. /* Enable interrupts and restore flags. */
  1862. spin_unlock_irqrestore(&lp->spinlock, flags);
  1863. return ret;
  1864. }
  1865. #ifdef WAVELAN_ROAMING_EXT
  1866. /*------------------------------------------------------------------*/
  1867. /*
  1868. * Wireless Handler : set ESSID (domain)
  1869. */
  1870. static int wavelan_set_essid(struct net_device *dev,
  1871. struct iw_request_info *info,
  1872. union iwreq_data *wrqu,
  1873. char *extra)
  1874. {
  1875. net_local *lp = netdev_priv(dev);
  1876. unsigned long flags;
  1877. int ret = 0;
  1878. /* Disable interrupts and save flags. */
  1879. spin_lock_irqsave(&lp->spinlock, flags);
  1880. /* Check if disable */
  1881. if(wrqu->data.flags == 0)
  1882. lp->filter_domains = 0;
  1883. else {
  1884. char essid[IW_ESSID_MAX_SIZE + 1];
  1885. char * endp;
  1886. /* Terminate the string */
  1887. memcpy(essid, extra, wrqu->data.length);
  1888. essid[IW_ESSID_MAX_SIZE] = '\0';
  1889. #ifdef DEBUG_IOCTL_INFO
  1890. printk(KERN_DEBUG "SetEssid : ``%s''\n", essid);
  1891. #endif /* DEBUG_IOCTL_INFO */
  1892. /* Convert to a number (note : Wavelan specific) */
  1893. lp->domain_id = simple_strtoul(essid, &endp, 16);
  1894. /* Has it worked ? */
  1895. if(endp > essid)
  1896. lp->filter_domains = 1;
  1897. else {
  1898. lp->filter_domains = 0;
  1899. ret = -EINVAL;
  1900. }
  1901. }
  1902. /* Enable interrupts and restore flags. */
  1903. spin_unlock_irqrestore(&lp->spinlock, flags);
  1904. return ret;
  1905. }
  1906. /*------------------------------------------------------------------*/
  1907. /*
  1908. * Wireless Handler : get ESSID (domain)
  1909. */
  1910. static int wavelan_get_essid(struct net_device *dev,
  1911. struct iw_request_info *info,
  1912. union iwreq_data *wrqu,
  1913. char *extra)
  1914. {
  1915. net_local *lp = netdev_priv(dev);
  1916. /* Is the domain ID active ? */
  1917. wrqu->data.flags = lp->filter_domains;
  1918. /* Copy Domain ID into a string (Wavelan specific) */
  1919. /* Sound crazy, be we can't have a snprintf in the kernel !!! */
  1920. sprintf(extra, "%lX", lp->domain_id);
  1921. extra[IW_ESSID_MAX_SIZE] = '\0';
  1922. /* Set the length */
  1923. wrqu->data.length = strlen(extra);
  1924. return 0;
  1925. }
  1926. /*------------------------------------------------------------------*/
  1927. /*
  1928. * Wireless Handler : set AP address
  1929. */
  1930. static int wavelan_set_wap(struct net_device *dev,
  1931. struct iw_request_info *info,
  1932. union iwreq_data *wrqu,
  1933. char *extra)
  1934. {
  1935. #ifdef DEBUG_IOCTL_INFO
  1936. printk(KERN_DEBUG "Set AP to : %02X:%02X:%02X:%02X:%02X:%02X\n",
  1937. wrqu->ap_addr.sa_data[0],
  1938. wrqu->ap_addr.sa_data[1],
  1939. wrqu->ap_addr.sa_data[2],
  1940. wrqu->ap_addr.sa_data[3],
  1941. wrqu->ap_addr.sa_data[4],
  1942. wrqu->ap_addr.sa_data[5]);
  1943. #endif /* DEBUG_IOCTL_INFO */
  1944. return -EOPNOTSUPP;
  1945. }
  1946. /*------------------------------------------------------------------*/
  1947. /*
  1948. * Wireless Handler : get AP address
  1949. */
  1950. static int wavelan_get_wap(struct net_device *dev,
  1951. struct iw_request_info *info,
  1952. union iwreq_data *wrqu,
  1953. char *extra)
  1954. {
  1955. /* Should get the real McCoy instead of own Ethernet address */
  1956. memcpy(wrqu->ap_addr.sa_data, dev->dev_addr, WAVELAN_ADDR_SIZE);
  1957. wrqu->ap_addr.sa_family = ARPHRD_ETHER;
  1958. return -EOPNOTSUPP;
  1959. }
  1960. #endif /* WAVELAN_ROAMING_EXT */
  1961. #ifdef WAVELAN_ROAMING
  1962. /*------------------------------------------------------------------*/
  1963. /*
  1964. * Wireless Handler : set mode
  1965. */
  1966. static int wavelan_set_mode(struct net_device *dev,
  1967. struct iw_request_info *info,
  1968. union iwreq_data *wrqu,
  1969. char *extra)
  1970. {
  1971. net_local *lp = netdev_priv(dev);
  1972. unsigned long flags;
  1973. int ret = 0;
  1974. /* Disable interrupts and save flags. */
  1975. spin_lock_irqsave(&lp->spinlock, flags);
  1976. /* Check mode */
  1977. switch(wrqu->mode) {
  1978. case IW_MODE_ADHOC:
  1979. if(do_roaming) {
  1980. wv_roam_cleanup(dev);
  1981. do_roaming = 0;
  1982. }
  1983. break;
  1984. case IW_MODE_INFRA:
  1985. if(!do_roaming) {
  1986. wv_roam_init(dev);
  1987. do_roaming = 1;
  1988. }
  1989. break;
  1990. default:
  1991. ret = -EINVAL;
  1992. }
  1993. /* Enable interrupts and restore flags. */
  1994. spin_unlock_irqrestore(&lp->spinlock, flags);
  1995. return ret;
  1996. }
  1997. /*------------------------------------------------------------------*/
  1998. /*
  1999. * Wireless Handler : get mode
  2000. */
  2001. static int wavelan_get_mode(struct net_device *dev,
  2002. struct iw_request_info *info,
  2003. union iwreq_data *wrqu,
  2004. char *extra)
  2005. {
  2006. if(do_roaming)
  2007. wrqu->mode = IW_MODE_INFRA;
  2008. else
  2009. wrqu->mode = IW_MODE_ADHOC;
  2010. return 0;
  2011. }
  2012. #endif /* WAVELAN_ROAMING */
  2013. /*------------------------------------------------------------------*/
  2014. /*
  2015. * Wireless Handler : get range info
  2016. */
  2017. static int wavelan_get_range(struct net_device *dev,
  2018. struct iw_request_info *info,
  2019. union iwreq_data *wrqu,
  2020. char *extra)
  2021. {
  2022. unsigned int base = dev->base_addr;
  2023. net_local *lp = netdev_priv(dev);
  2024. struct iw_range *range = (struct iw_range *) extra;
  2025. unsigned long flags;
  2026. int ret = 0;
  2027. /* Set the length (very important for backward compatibility) */
  2028. wrqu->data.length = sizeof(struct iw_range);
  2029. /* Set all the info we don't care or don't know about to zero */
  2030. memset(range, 0, sizeof(struct iw_range));
  2031. /* Set the Wireless Extension versions */
  2032. range->we_version_compiled = WIRELESS_EXT;
  2033. range->we_version_source = 9;
  2034. /* Set information in the range struct. */
  2035. range->throughput = 1.4 * 1000 * 1000; /* don't argue on this ! */
  2036. range->min_nwid = 0x0000;
  2037. range->max_nwid = 0xFFFF;
  2038. range->sensitivity = 0x3F;
  2039. range->max_qual.qual = MMR_SGNL_QUAL;
  2040. range->max_qual.level = MMR_SIGNAL_LVL;
  2041. range->max_qual.noise = MMR_SILENCE_LVL;
  2042. range->avg_qual.qual = MMR_SGNL_QUAL; /* Always max */
  2043. /* Need to get better values for those two */
  2044. range->avg_qual.level = 30;
  2045. range->avg_qual.noise = 8;
  2046. range->num_bitrates = 1;
  2047. range->bitrate[0] = 2000000; /* 2 Mb/s */
  2048. /* Event capability (kernel + driver) */
  2049. range->event_capa[0] = (IW_EVENT_CAPA_MASK(0x8B02) |
  2050. IW_EVENT_CAPA_MASK(0x8B04) |
  2051. IW_EVENT_CAPA_MASK(0x8B06));
  2052. range->event_capa[1] = IW_EVENT_CAPA_K_1;
  2053. /* Disable interrupts and save flags. */
  2054. spin_lock_irqsave(&lp->spinlock, flags);
  2055. /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
  2056. if (!(mmc_in(base, mmroff(0, mmr_fee_status)) &
  2057. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
  2058. range->num_channels = 10;
  2059. range->num_frequency = wv_frequency_list(base, range->freq,
  2060. IW_MAX_FREQUENCIES);
  2061. } else
  2062. range->num_channels = range->num_frequency = 0;
  2063. /* Encryption supported ? */
  2064. if (mmc_encr(base)) {
  2065. range->encoding_size[0] = 8; /* DES = 64 bits key */
  2066. range->num_encoding_sizes = 1;
  2067. range->max_encoding_tokens = 1; /* Only one key possible */
  2068. } else {
  2069. range->num_encoding_sizes = 0;
  2070. range->max_encoding_tokens = 0;
  2071. }
  2072. /* Enable interrupts and restore flags. */
  2073. spin_unlock_irqrestore(&lp->spinlock, flags);
  2074. return ret;
  2075. }
  2076. /*------------------------------------------------------------------*/
  2077. /*
  2078. * Wireless Private Handler : set quality threshold
  2079. */
  2080. static int wavelan_set_qthr(struct net_device *dev,
  2081. struct iw_request_info *info,
  2082. union iwreq_data *wrqu,
  2083. char *extra)
  2084. {
  2085. unsigned int base = dev->base_addr;
  2086. net_local *lp = netdev_priv(dev);
  2087. psa_t psa;
  2088. unsigned long flags;
  2089. /* Disable interrupts and save flags. */
  2090. spin_lock_irqsave(&lp->spinlock, flags);
  2091. psa.psa_quality_thr = *(extra) & 0x0F;
  2092. psa_write(dev,
  2093. (char *) &psa.psa_quality_thr - (char *) &psa,
  2094. (unsigned char *) &psa.psa_quality_thr, 1);
  2095. /* update the Wavelan checksum */
  2096. update_psa_checksum(dev);
  2097. mmc_out(base, mmwoff(0, mmw_quality_thr),
  2098. psa.psa_quality_thr);
  2099. /* Enable interrupts and restore flags. */
  2100. spin_unlock_irqrestore(&lp->spinlock, flags);
  2101. return 0;
  2102. }
  2103. /*------------------------------------------------------------------*/
  2104. /*
  2105. * Wireless Private Handler : get quality threshold
  2106. */
  2107. static int wavelan_get_qthr(struct net_device *dev,
  2108. struct iw_request_info *info,
  2109. union iwreq_data *wrqu,
  2110. char *extra)
  2111. {
  2112. net_local *lp = netdev_priv(dev);
  2113. psa_t psa;
  2114. unsigned long flags;
  2115. /* Disable interrupts and save flags. */
  2116. spin_lock_irqsave(&lp->spinlock, flags);
  2117. psa_read(dev,
  2118. (char *) &psa.psa_quality_thr - (char *) &psa,
  2119. (unsigned char *) &psa.psa_quality_thr, 1);
  2120. *(extra) = psa.psa_quality_thr & 0x0F;
  2121. /* Enable interrupts and restore flags. */
  2122. spin_unlock_irqrestore(&lp->spinlock, flags);
  2123. return 0;
  2124. }
  2125. #ifdef WAVELAN_ROAMING
  2126. /*------------------------------------------------------------------*/
  2127. /*
  2128. * Wireless Private Handler : set roaming
  2129. */
  2130. static int wavelan_set_roam(struct net_device *dev,
  2131. struct iw_request_info *info,
  2132. union iwreq_data *wrqu,
  2133. char *extra)
  2134. {
  2135. net_local *lp = netdev_priv(dev);
  2136. unsigned long flags;
  2137. /* Disable interrupts and save flags. */
  2138. spin_lock_irqsave(&lp->spinlock, flags);
  2139. /* Note : should check if user == root */
  2140. if(do_roaming && (*extra)==0)
  2141. wv_roam_cleanup(dev);
  2142. else if(do_roaming==0 && (*extra)!=0)
  2143. wv_roam_init(dev);
  2144. do_roaming = (*extra);
  2145. /* Enable interrupts and restore flags. */
  2146. spin_unlock_irqrestore(&lp->spinlock, flags);
  2147. return 0;
  2148. }
  2149. /*------------------------------------------------------------------*/
  2150. /*
  2151. * Wireless Private Handler : get quality threshold
  2152. */
  2153. static int wavelan_get_roam(struct net_device *dev,
  2154. struct iw_request_info *info,
  2155. union iwreq_data *wrqu,
  2156. char *extra)
  2157. {
  2158. *(extra) = do_roaming;
  2159. return 0;
  2160. }
  2161. #endif /* WAVELAN_ROAMING */
  2162. #ifdef HISTOGRAM
  2163. /*------------------------------------------------------------------*/
  2164. /*
  2165. * Wireless Private Handler : set histogram
  2166. */
  2167. static int wavelan_set_histo(struct net_device *dev,
  2168. struct iw_request_info *info,
  2169. union iwreq_data *wrqu,
  2170. char *extra)
  2171. {
  2172. net_local *lp = netdev_priv(dev);
  2173. /* Check the number of intervals. */
  2174. if (wrqu->data.length > 16) {
  2175. return(-E2BIG);
  2176. }
  2177. /* Disable histo while we copy the addresses.
  2178. * As we don't disable interrupts, we need to do this */
  2179. lp->his_number = 0;
  2180. /* Are there ranges to copy? */
  2181. if (wrqu->data.length > 0) {
  2182. /* Copy interval ranges to the driver */
  2183. memcpy(lp->his_range, extra, wrqu->data.length);
  2184. {
  2185. int i;
  2186. printk(KERN_DEBUG "Histo :");
  2187. for(i = 0; i < wrqu->data.length; i++)
  2188. printk(" %d", lp->his_range[i]);
  2189. printk("\n");
  2190. }
  2191. /* Reset result structure. */
  2192. memset(lp->his_sum, 0x00, sizeof(long) * 16);
  2193. }
  2194. /* Now we can set the number of ranges */
  2195. lp->his_number = wrqu->data.length;
  2196. return(0);
  2197. }
  2198. /*------------------------------------------------------------------*/
  2199. /*
  2200. * Wireless Private Handler : get histogram
  2201. */
  2202. static int wavelan_get_histo(struct net_device *dev,
  2203. struct iw_request_info *info,
  2204. union iwreq_data *wrqu,
  2205. char *extra)
  2206. {
  2207. net_local *lp = netdev_priv(dev);
  2208. /* Set the number of intervals. */
  2209. wrqu->data.length = lp->his_number;
  2210. /* Give back the distribution statistics */
  2211. if(lp->his_number > 0)
  2212. memcpy(extra, lp->his_sum, sizeof(long) * lp->his_number);
  2213. return(0);
  2214. }
  2215. #endif /* HISTOGRAM */
  2216. /*------------------------------------------------------------------*/
  2217. /*
  2218. * Structures to export the Wireless Handlers
  2219. */
  2220. static const struct iw_priv_args wavelan_private_args[] = {
  2221. /*{ cmd, set_args, get_args, name } */
  2222. { SIOCSIPQTHR, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setqualthr" },
  2223. { SIOCGIPQTHR, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getqualthr" },
  2224. { SIOCSIPROAM, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setroam" },
  2225. { SIOCGIPROAM, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getroam" },
  2226. { SIOCSIPHISTO, IW_PRIV_TYPE_BYTE | 16, 0, "sethisto" },
  2227. { SIOCGIPHISTO, 0, IW_PRIV_TYPE_INT | 16, "gethisto" },
  2228. };
  2229. static const iw_handler wavelan_handler[] =
  2230. {
  2231. NULL, /* SIOCSIWNAME */
  2232. wavelan_get_name, /* SIOCGIWNAME */
  2233. wavelan_set_nwid, /* SIOCSIWNWID */
  2234. wavelan_get_nwid, /* SIOCGIWNWID */
  2235. wavelan_set_freq, /* SIOCSIWFREQ */
  2236. wavelan_get_freq, /* SIOCGIWFREQ */
  2237. #ifdef WAVELAN_ROAMING
  2238. wavelan_set_mode, /* SIOCSIWMODE */
  2239. wavelan_get_mode, /* SIOCGIWMODE */
  2240. #else /* WAVELAN_ROAMING */
  2241. NULL, /* SIOCSIWMODE */
  2242. NULL, /* SIOCGIWMODE */
  2243. #endif /* WAVELAN_ROAMING */
  2244. wavelan_set_sens, /* SIOCSIWSENS */
  2245. wavelan_get_sens, /* SIOCGIWSENS */
  2246. NULL, /* SIOCSIWRANGE */
  2247. wavelan_get_range, /* SIOCGIWRANGE */
  2248. NULL, /* SIOCSIWPRIV */
  2249. NULL, /* SIOCGIWPRIV */
  2250. NULL, /* SIOCSIWSTATS */
  2251. NULL, /* SIOCGIWSTATS */
  2252. iw_handler_set_spy, /* SIOCSIWSPY */
  2253. iw_handler_get_spy, /* SIOCGIWSPY */
  2254. iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
  2255. iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
  2256. #ifdef WAVELAN_ROAMING_EXT
  2257. wavelan_set_wap, /* SIOCSIWAP */
  2258. wavelan_get_wap, /* SIOCGIWAP */
  2259. NULL, /* -- hole -- */
  2260. NULL, /* SIOCGIWAPLIST */
  2261. NULL, /* -- hole -- */
  2262. NULL, /* -- hole -- */
  2263. wavelan_set_essid, /* SIOCSIWESSID */
  2264. wavelan_get_essid, /* SIOCGIWESSID */
  2265. #else /* WAVELAN_ROAMING_EXT */
  2266. NULL, /* SIOCSIWAP */
  2267. NULL, /* SIOCGIWAP */
  2268. NULL, /* -- hole -- */
  2269. NULL, /* SIOCGIWAPLIST */
  2270. NULL, /* -- hole -- */
  2271. NULL, /* -- hole -- */
  2272. NULL, /* SIOCSIWESSID */
  2273. NULL, /* SIOCGIWESSID */
  2274. #endif /* WAVELAN_ROAMING_EXT */
  2275. NULL, /* SIOCSIWNICKN */
  2276. NULL, /* SIOCGIWNICKN */
  2277. NULL, /* -- hole -- */
  2278. NULL, /* -- hole -- */
  2279. NULL, /* SIOCSIWRATE */
  2280. NULL, /* SIOCGIWRATE */
  2281. NULL, /* SIOCSIWRTS */
  2282. NULL, /* SIOCGIWRTS */
  2283. NULL, /* SIOCSIWFRAG */
  2284. NULL, /* SIOCGIWFRAG */
  2285. NULL, /* SIOCSIWTXPOW */
  2286. NULL, /* SIOCGIWTXPOW */
  2287. NULL, /* SIOCSIWRETRY */
  2288. NULL, /* SIOCGIWRETRY */
  2289. wavelan_set_encode, /* SIOCSIWENCODE */
  2290. wavelan_get_encode, /* SIOCGIWENCODE */
  2291. };
  2292. static const iw_handler wavelan_private_handler[] =
  2293. {
  2294. wavelan_set_qthr, /* SIOCIWFIRSTPRIV */
  2295. wavelan_get_qthr, /* SIOCIWFIRSTPRIV + 1 */
  2296. #ifdef WAVELAN_ROAMING
  2297. wavelan_set_roam, /* SIOCIWFIRSTPRIV + 2 */
  2298. wavelan_get_roam, /* SIOCIWFIRSTPRIV + 3 */
  2299. #else /* WAVELAN_ROAMING */
  2300. NULL, /* SIOCIWFIRSTPRIV + 2 */
  2301. NULL, /* SIOCIWFIRSTPRIV + 3 */
  2302. #endif /* WAVELAN_ROAMING */
  2303. #ifdef HISTOGRAM
  2304. wavelan_set_histo, /* SIOCIWFIRSTPRIV + 4 */
  2305. wavelan_get_histo, /* SIOCIWFIRSTPRIV + 5 */
  2306. #endif /* HISTOGRAM */
  2307. };
  2308. static const struct iw_handler_def wavelan_handler_def =
  2309. {
  2310. .num_standard = ARRAY_SIZE(wavelan_handler),
  2311. .num_private = ARRAY_SIZE(wavelan_private_handler),
  2312. .num_private_args = ARRAY_SIZE(wavelan_private_args),
  2313. .standard = wavelan_handler,
  2314. .private = wavelan_private_handler,
  2315. .private_args = wavelan_private_args,
  2316. .get_wireless_stats = wavelan_get_wireless_stats,
  2317. };
  2318. /*------------------------------------------------------------------*/
  2319. /*
  2320. * Get wireless statistics
  2321. * Called by /proc/net/wireless...
  2322. */
  2323. static iw_stats *
  2324. wavelan_get_wireless_stats(struct net_device * dev)
  2325. {
  2326. unsigned int base = dev->base_addr;
  2327. net_local * lp = netdev_priv(dev);
  2328. mmr_t m;
  2329. iw_stats * wstats;
  2330. unsigned long flags;
  2331. #ifdef DEBUG_IOCTL_TRACE
  2332. printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()\n", dev->name);
  2333. #endif
  2334. /* Disable interrupts & save flags */
  2335. spin_lock_irqsave(&lp->spinlock, flags);
  2336. wstats = &lp->wstats;
  2337. /* Get data from the mmc */
  2338. mmc_out(base, mmwoff(0, mmw_freeze), 1);
  2339. mmc_read(base, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1);
  2340. mmc_read(base, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l, 2);
  2341. mmc_read(base, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set, 4);
  2342. mmc_out(base, mmwoff(0, mmw_freeze), 0);
  2343. /* Copy data to wireless stuff */
  2344. wstats->status = m.mmr_dce_status & MMR_DCE_STATUS;
  2345. wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL;
  2346. wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL;
  2347. wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL;
  2348. wstats->qual.updated = (((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7) |
  2349. ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6) |
  2350. ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5));
  2351. wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
  2352. wstats->discard.code = 0L;
  2353. wstats->discard.misc = 0L;
  2354. /* ReEnable interrupts & restore flags */
  2355. spin_unlock_irqrestore(&lp->spinlock, flags);
  2356. #ifdef DEBUG_IOCTL_TRACE
  2357. printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()\n", dev->name);
  2358. #endif
  2359. return &lp->wstats;
  2360. }
  2361. /************************* PACKET RECEPTION *************************/
  2362. /*
  2363. * This part deal with receiving the packets.
  2364. * The interrupt handler get an interrupt when a packet has been
  2365. * successfully received and called this part...
  2366. */
  2367. /*------------------------------------------------------------------*/
  2368. /*
  2369. * Calculate the starting address of the frame pointed to by the receive
  2370. * frame pointer and verify that the frame seem correct
  2371. * (called by wv_packet_rcv())
  2372. */
  2373. static int
  2374. wv_start_of_frame(struct net_device * dev,
  2375. int rfp, /* end of frame */
  2376. int wrap) /* start of buffer */
  2377. {
  2378. unsigned int base = dev->base_addr;
  2379. int rp;
  2380. int len;
  2381. rp = (rfp - 5 + RX_SIZE) % RX_SIZE;
  2382. outb(rp & 0xff, PIORL(base));
  2383. outb(((rp >> 8) & PIORH_MASK), PIORH(base));
  2384. len = inb(PIOP(base));
  2385. len |= inb(PIOP(base)) << 8;
  2386. /* Sanity checks on size */
  2387. /* Frame too big */
  2388. if(len > MAXDATAZ + 100)
  2389. {
  2390. #ifdef DEBUG_RX_ERROR
  2391. printk(KERN_INFO "%s: wv_start_of_frame: Received frame too large, rfp %d len 0x%x\n",
  2392. dev->name, rfp, len);
  2393. #endif
  2394. return(-1);
  2395. }
  2396. /* Frame too short */
  2397. if(len < 7)
  2398. {
  2399. #ifdef DEBUG_RX_ERROR
  2400. printk(KERN_INFO "%s: wv_start_of_frame: Received null frame, rfp %d len 0x%x\n",
  2401. dev->name, rfp, len);
  2402. #endif
  2403. return(-1);
  2404. }
  2405. /* Wrap around buffer */
  2406. if(len > ((wrap - (rfp - len) + RX_SIZE) % RX_SIZE)) /* magic formula ! */
  2407. {
  2408. #ifdef DEBUG_RX_ERROR
  2409. printk(KERN_INFO "%s: wv_start_of_frame: wrap around buffer, wrap %d rfp %d len 0x%x\n",
  2410. dev->name, wrap, rfp, len);
  2411. #endif
  2412. return(-1);
  2413. }
  2414. return((rp - len + RX_SIZE) % RX_SIZE);
  2415. } /* wv_start_of_frame */
  2416. /*------------------------------------------------------------------*/
  2417. /*
  2418. * This routine does the actual copy of data (including the ethernet
  2419. * header structure) from the WaveLAN card to an sk_buff chain that
  2420. * will be passed up to the network interface layer. NOTE: We
  2421. * currently don't handle trailer protocols (neither does the rest of
  2422. * the network interface), so if that is needed, it will (at least in
  2423. * part) be added here. The contents of the receive ring buffer are
  2424. * copied to a message chain that is then passed to the kernel.
  2425. *
  2426. * Note: if any errors occur, the packet is "dropped on the floor"
  2427. * (called by wv_packet_rcv())
  2428. */
  2429. static void
  2430. wv_packet_read(struct net_device * dev,
  2431. int fd_p,
  2432. int sksize)
  2433. {
  2434. net_local * lp = netdev_priv(dev);
  2435. struct sk_buff * skb;
  2436. #ifdef DEBUG_RX_TRACE
  2437. printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)\n",
  2438. dev->name, fd_p, sksize);
  2439. #endif
  2440. /* Allocate some buffer for the new packet */
  2441. if((skb = dev_alloc_skb(sksize+2)) == (struct sk_buff *) NULL)
  2442. {
  2443. #ifdef DEBUG_RX_ERROR
  2444. printk(KERN_INFO "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC)\n",
  2445. dev->name, sksize);
  2446. #endif
  2447. lp->stats.rx_dropped++;
  2448. /*
  2449. * Not only do we want to return here, but we also need to drop the
  2450. * packet on the floor to clear the interrupt.
  2451. */
  2452. return;
  2453. }
  2454. skb_reserve(skb, 2);
  2455. fd_p = read_ringbuf(dev, fd_p, (char *) skb_put(skb, sksize), sksize);
  2456. skb->protocol = eth_type_trans(skb, dev);
  2457. #ifdef DEBUG_RX_INFO
  2458. wv_packet_info(skb_mac_header(skb), sksize, dev->name, "wv_packet_read");
  2459. #endif /* DEBUG_RX_INFO */
  2460. /* Statistics gathering & stuff associated.
  2461. * It seem a bit messy with all the define, but it's really simple... */
  2462. if(
  2463. #ifdef IW_WIRELESS_SPY
  2464. (lp->spy_data.spy_number > 0) ||
  2465. #endif /* IW_WIRELESS_SPY */
  2466. #ifdef HISTOGRAM
  2467. (lp->his_number > 0) ||
  2468. #endif /* HISTOGRAM */
  2469. #ifdef WAVELAN_ROAMING
  2470. (do_roaming) ||
  2471. #endif /* WAVELAN_ROAMING */
  2472. 0)
  2473. {
  2474. u_char stats[3]; /* Signal level, Noise level, Signal quality */
  2475. /* read signal level, silence level and signal quality bytes */
  2476. fd_p = read_ringbuf(dev, (fd_p + 4) % RX_SIZE + RX_BASE,
  2477. stats, 3);
  2478. #ifdef DEBUG_RX_INFO
  2479. printk(KERN_DEBUG "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n",
  2480. dev->name, stats[0] & 0x3F, stats[1] & 0x3F, stats[2] & 0x0F);
  2481. #endif
  2482. #ifdef WAVELAN_ROAMING
  2483. if(do_roaming)
  2484. if(WAVELAN_BEACON(skb->data))
  2485. wl_roam_gather(dev, skb->data, stats);
  2486. #endif /* WAVELAN_ROAMING */
  2487. #ifdef WIRELESS_SPY
  2488. wl_spy_gather(dev, skb_mac_header(skb) + WAVELAN_ADDR_SIZE, stats);
  2489. #endif /* WIRELESS_SPY */
  2490. #ifdef HISTOGRAM
  2491. wl_his_gather(dev, stats);
  2492. #endif /* HISTOGRAM */
  2493. }
  2494. /*
  2495. * Hand the packet to the Network Module
  2496. */
  2497. netif_rx(skb);
  2498. /* Keep stats up to date */
  2499. dev->last_rx = jiffies;
  2500. lp->stats.rx_packets++;
  2501. lp->stats.rx_bytes += sksize;
  2502. #ifdef DEBUG_RX_TRACE
  2503. printk(KERN_DEBUG "%s: <-wv_packet_read()\n", dev->name);
  2504. #endif
  2505. return;
  2506. }
  2507. /*------------------------------------------------------------------*/
  2508. /*
  2509. * This routine is called by the interrupt handler to initiate a
  2510. * packet transfer from the card to the network interface layer above
  2511. * this driver. This routine checks if a buffer has been successfully
  2512. * received by the WaveLAN card. If so, the routine wv_packet_read is
  2513. * called to do the actual transfer of the card's data including the
  2514. * ethernet header into a packet consisting of an sk_buff chain.
  2515. * (called by wavelan_interrupt())
  2516. * Note : the spinlock is already grabbed for us and irq are disabled.
  2517. */
  2518. static void
  2519. wv_packet_rcv(struct net_device * dev)
  2520. {
  2521. unsigned int base = dev->base_addr;
  2522. net_local * lp = netdev_priv(dev);
  2523. int newrfp;
  2524. int rp;
  2525. int len;
  2526. int f_start;
  2527. int status;
  2528. int i593_rfp;
  2529. int stat_ptr;
  2530. u_char c[4];
  2531. #ifdef DEBUG_RX_TRACE
  2532. printk(KERN_DEBUG "%s: ->wv_packet_rcv()\n", dev->name);
  2533. #endif
  2534. /* Get the new receive frame pointer from the i82593 chip */
  2535. outb(CR0_STATUS_2 | OP0_NOP, LCCR(base));
  2536. i593_rfp = inb(LCSR(base));
  2537. i593_rfp |= inb(LCSR(base)) << 8;
  2538. i593_rfp %= RX_SIZE;
  2539. /* Get the new receive frame pointer from the WaveLAN card.
  2540. * It is 3 bytes more than the increment of the i82593 receive
  2541. * frame pointer, for each packet. This is because it includes the
  2542. * 3 roaming bytes added by the mmc.
  2543. */
  2544. newrfp = inb(RPLL(base));
  2545. newrfp |= inb(RPLH(base)) << 8;
  2546. newrfp %= RX_SIZE;
  2547. #ifdef DEBUG_RX_INFO
  2548. printk(KERN_DEBUG "%s: wv_packet_rcv(): i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
  2549. dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
  2550. #endif
  2551. #ifdef DEBUG_RX_ERROR
  2552. /* If no new frame pointer... */
  2553. if(lp->overrunning || newrfp == lp->rfp)
  2554. printk(KERN_INFO "%s: wv_packet_rcv(): no new frame: i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
  2555. dev->name, i593_rfp, lp->stop, newrfp, lp->rfp);
  2556. #endif
  2557. /* Read all frames (packets) received */
  2558. while(newrfp != lp->rfp)
  2559. {
  2560. /* A frame is composed of the packet, followed by a status word,
  2561. * the length of the frame (word) and the mmc info (SNR & qual).
  2562. * It's because the length is at the end that we can only scan
  2563. * frames backward. */
  2564. /* Find the first frame by skipping backwards over the frames */
  2565. rp = newrfp; /* End of last frame */
  2566. while(((f_start = wv_start_of_frame(dev, rp, newrfp)) != lp->rfp) &&
  2567. (f_start != -1))
  2568. rp = f_start;
  2569. /* If we had a problem */
  2570. if(f_start == -1)
  2571. {
  2572. #ifdef DEBUG_RX_ERROR
  2573. printk(KERN_INFO "wavelan_cs: cannot find start of frame ");
  2574. printk(" i593_rfp %d stop %d newrfp %d lp->rfp %d\n",
  2575. i593_rfp, lp->stop, newrfp, lp->rfp);
  2576. #endif
  2577. lp->rfp = rp; /* Get to the last usable frame */
  2578. continue;
  2579. }
  2580. /* f_start point to the beggining of the first frame received
  2581. * and rp to the beggining of the next one */
  2582. /* Read status & length of the frame */
  2583. stat_ptr = (rp - 7 + RX_SIZE) % RX_SIZE;
  2584. stat_ptr = read_ringbuf(dev, stat_ptr, c, 4);
  2585. status = c[0] | (c[1] << 8);
  2586. len = c[2] | (c[3] << 8);
  2587. /* Check status */
  2588. if((status & RX_RCV_OK) != RX_RCV_OK)
  2589. {
  2590. lp->stats.rx_errors++;
  2591. if(status & RX_NO_SFD)
  2592. lp->stats.rx_frame_errors++;
  2593. if(status & RX_CRC_ERR)
  2594. lp->stats.rx_crc_errors++;
  2595. if(status & RX_OVRRUN)
  2596. lp->stats.rx_over_errors++;
  2597. #ifdef DEBUG_RX_FAIL
  2598. printk(KERN_DEBUG "%s: wv_packet_rcv(): packet not received ok, status = 0x%x\n",
  2599. dev->name, status);
  2600. #endif
  2601. }
  2602. else
  2603. /* Read the packet and transmit to Linux */
  2604. wv_packet_read(dev, f_start, len - 2);
  2605. /* One frame has been processed, skip it */
  2606. lp->rfp = rp;
  2607. }
  2608. /*
  2609. * Update the frame stop register, but set it to less than
  2610. * the full 8K to allow space for 3 bytes of signal strength
  2611. * per packet.
  2612. */
  2613. lp->stop = (i593_rfp + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
  2614. outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
  2615. outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
  2616. outb(OP1_SWIT_TO_PORT_0, LCCR(base));
  2617. #ifdef DEBUG_RX_TRACE
  2618. printk(KERN_DEBUG "%s: <-wv_packet_rcv()\n", dev->name);
  2619. #endif
  2620. }
  2621. /*********************** PACKET TRANSMISSION ***********************/
  2622. /*
  2623. * This part deal with sending packet through the wavelan
  2624. * We copy the packet to the send buffer and then issue the send
  2625. * command to the i82593. The result of this operation will be
  2626. * checked in wavelan_interrupt()
  2627. */
  2628. /*------------------------------------------------------------------*/
  2629. /*
  2630. * This routine fills in the appropriate registers and memory
  2631. * locations on the WaveLAN card and starts the card off on
  2632. * the transmit.
  2633. * (called in wavelan_packet_xmit())
  2634. */
  2635. static void
  2636. wv_packet_write(struct net_device * dev,
  2637. void * buf,
  2638. short length)
  2639. {
  2640. net_local * lp = netdev_priv(dev);
  2641. unsigned int base = dev->base_addr;
  2642. unsigned long flags;
  2643. int clen = length;
  2644. register u_short xmtdata_base = TX_BASE;
  2645. #ifdef DEBUG_TX_TRACE
  2646. printk(KERN_DEBUG "%s: ->wv_packet_write(%d)\n", dev->name, length);
  2647. #endif
  2648. spin_lock_irqsave(&lp->spinlock, flags);
  2649. /* Write the length of data buffer followed by the buffer */
  2650. outb(xmtdata_base & 0xff, PIORL(base));
  2651. outb(((xmtdata_base >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
  2652. outb(clen & 0xff, PIOP(base)); /* lsb */
  2653. outb(clen >> 8, PIOP(base)); /* msb */
  2654. /* Send the data */
  2655. outsb(PIOP(base), buf, clen);
  2656. /* Indicate end of transmit chain */
  2657. outb(OP0_NOP, PIOP(base));
  2658. /* josullvn@cs.cmu.edu: need to send a second NOP for alignment... */
  2659. outb(OP0_NOP, PIOP(base));
  2660. /* Reset the transmit DMA pointer */
  2661. hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  2662. hacr_write(base, HACR_DEFAULT);
  2663. /* Send the transmit command */
  2664. wv_82593_cmd(dev, "wv_packet_write(): transmit",
  2665. OP0_TRANSMIT, SR0_NO_RESULT);
  2666. /* Make sure the watchdog will keep quiet for a while */
  2667. dev->trans_start = jiffies;
  2668. /* Keep stats up to date */
  2669. lp->stats.tx_bytes += length;
  2670. spin_unlock_irqrestore(&lp->spinlock, flags);
  2671. #ifdef DEBUG_TX_INFO
  2672. wv_packet_info((u_char *) buf, length, dev->name, "wv_packet_write");
  2673. #endif /* DEBUG_TX_INFO */
  2674. #ifdef DEBUG_TX_TRACE
  2675. printk(KERN_DEBUG "%s: <-wv_packet_write()\n", dev->name);
  2676. #endif
  2677. }
  2678. /*------------------------------------------------------------------*/
  2679. /*
  2680. * This routine is called when we want to send a packet (NET3 callback)
  2681. * In this routine, we check if the harware is ready to accept
  2682. * the packet. We also prevent reentrance. Then, we call the function
  2683. * to send the packet...
  2684. */
  2685. static int
  2686. wavelan_packet_xmit(struct sk_buff * skb,
  2687. struct net_device * dev)
  2688. {
  2689. net_local * lp = netdev_priv(dev);
  2690. unsigned long flags;
  2691. #ifdef DEBUG_TX_TRACE
  2692. printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)\n", dev->name,
  2693. (unsigned) skb);
  2694. #endif
  2695. /*
  2696. * Block a timer-based transmit from overlapping a previous transmit.
  2697. * In other words, prevent reentering this routine.
  2698. */
  2699. netif_stop_queue(dev);
  2700. /* If somebody has asked to reconfigure the controller,
  2701. * we can do it now */
  2702. if(lp->reconfig_82593)
  2703. {
  2704. spin_lock_irqsave(&lp->spinlock, flags); /* Disable interrupts */
  2705. wv_82593_config(dev);
  2706. spin_unlock_irqrestore(&lp->spinlock, flags); /* Re-enable interrupts */
  2707. /* Note : the configure procedure was totally synchronous,
  2708. * so the Tx buffer is now free */
  2709. }
  2710. #ifdef DEBUG_TX_ERROR
  2711. if (skb->next)
  2712. printk(KERN_INFO "skb has next\n");
  2713. #endif
  2714. /* Check if we need some padding */
  2715. /* Note : on wireless the propagation time is in the order of 1us,
  2716. * and we don't have the Ethernet specific requirement of beeing
  2717. * able to detect collisions, therefore in theory we don't really
  2718. * need to pad. Jean II */
  2719. if (skb_padto(skb, ETH_ZLEN))
  2720. return 0;
  2721. wv_packet_write(dev, skb->data, skb->len);
  2722. dev_kfree_skb(skb);
  2723. #ifdef DEBUG_TX_TRACE
  2724. printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
  2725. #endif
  2726. return(0);
  2727. }
  2728. /********************** HARDWARE CONFIGURATION **********************/
  2729. /*
  2730. * This part do the real job of starting and configuring the hardware.
  2731. */
  2732. /*------------------------------------------------------------------*/
  2733. /*
  2734. * Routine to initialize the Modem Management Controller.
  2735. * (called by wv_hw_config())
  2736. */
  2737. static int
  2738. wv_mmc_init(struct net_device * dev)
  2739. {
  2740. unsigned int base = dev->base_addr;
  2741. psa_t psa;
  2742. mmw_t m;
  2743. int configured;
  2744. int i; /* Loop counter */
  2745. #ifdef DEBUG_CONFIG_TRACE
  2746. printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name);
  2747. #endif
  2748. /* Read the parameter storage area */
  2749. psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
  2750. /*
  2751. * Check the first three octets of the MAC addr for the manufacturer's code.
  2752. * Note: If you get the error message below, you've got a
  2753. * non-NCR/AT&T/Lucent PCMCIA cards, see wavelan_cs.h for detail on
  2754. * how to configure your card...
  2755. */
  2756. for (i = 0; i < ARRAY_SIZE(MAC_ADDRESSES); i++)
  2757. if ((psa.psa_univ_mac_addr[0] == MAC_ADDRESSES[i][0]) &&
  2758. (psa.psa_univ_mac_addr[1] == MAC_ADDRESSES[i][1]) &&
  2759. (psa.psa_univ_mac_addr[2] == MAC_ADDRESSES[i][2]))
  2760. break;
  2761. /* If we have not found it... */
  2762. if (i == ARRAY_SIZE(MAC_ADDRESSES))
  2763. {
  2764. #ifdef DEBUG_CONFIG_ERRORS
  2765. printk(KERN_WARNING "%s: wv_mmc_init(): Invalid MAC address: %02X:%02X:%02X:...\n",
  2766. dev->name, psa.psa_univ_mac_addr[0],
  2767. psa.psa_univ_mac_addr[1], psa.psa_univ_mac_addr[2]);
  2768. #endif
  2769. return FALSE;
  2770. }
  2771. /* Get the MAC address */
  2772. memcpy(&dev->dev_addr[0], &psa.psa_univ_mac_addr[0], WAVELAN_ADDR_SIZE);
  2773. #ifdef USE_PSA_CONFIG
  2774. configured = psa.psa_conf_status & 1;
  2775. #else
  2776. configured = 0;
  2777. #endif
  2778. /* Is the PSA is not configured */
  2779. if(!configured)
  2780. {
  2781. /* User will be able to configure NWID after (with iwconfig) */
  2782. psa.psa_nwid[0] = 0;
  2783. psa.psa_nwid[1] = 0;
  2784. /* As NWID is not set : no NWID checking */
  2785. psa.psa_nwid_select = 0;
  2786. /* Disable encryption */
  2787. psa.psa_encryption_select = 0;
  2788. /* Set to standard values
  2789. * 0x04 for AT,
  2790. * 0x01 for MCA,
  2791. * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
  2792. */
  2793. if (psa.psa_comp_number & 1)
  2794. psa.psa_thr_pre_set = 0x01;
  2795. else
  2796. psa.psa_thr_pre_set = 0x04;
  2797. psa.psa_quality_thr = 0x03;
  2798. /* It is configured */
  2799. psa.psa_conf_status |= 1;
  2800. #ifdef USE_PSA_CONFIG
  2801. /* Write the psa */
  2802. psa_write(dev, (char *)psa.psa_nwid - (char *)&psa,
  2803. (unsigned char *)psa.psa_nwid, 4);
  2804. psa_write(dev, (char *)&psa.psa_thr_pre_set - (char *)&psa,
  2805. (unsigned char *)&psa.psa_thr_pre_set, 1);
  2806. psa_write(dev, (char *)&psa.psa_quality_thr - (char *)&psa,
  2807. (unsigned char *)&psa.psa_quality_thr, 1);
  2808. psa_write(dev, (char *)&psa.psa_conf_status - (char *)&psa,
  2809. (unsigned char *)&psa.psa_conf_status, 1);
  2810. /* update the Wavelan checksum */
  2811. update_psa_checksum(dev);
  2812. #endif /* USE_PSA_CONFIG */
  2813. }
  2814. /* Zero the mmc structure */
  2815. memset(&m, 0x00, sizeof(m));
  2816. /* Copy PSA info to the mmc */
  2817. m.mmw_netw_id_l = psa.psa_nwid[1];
  2818. m.mmw_netw_id_h = psa.psa_nwid[0];
  2819. if(psa.psa_nwid_select & 1)
  2820. m.mmw_loopt_sel = 0x00;
  2821. else
  2822. m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
  2823. memcpy(&m.mmw_encr_key, &psa.psa_encryption_key,
  2824. sizeof(m.mmw_encr_key));
  2825. if(psa.psa_encryption_select)
  2826. m.mmw_encr_enable = MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
  2827. else
  2828. m.mmw_encr_enable = 0;
  2829. m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
  2830. m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
  2831. /*
  2832. * Set default modem control parameters.
  2833. * See NCR document 407-0024326 Rev. A.
  2834. */
  2835. m.mmw_jabber_enable = 0x01;
  2836. m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
  2837. m.mmw_ifs = 0x20;
  2838. m.mmw_mod_delay = 0x04;
  2839. m.mmw_jam_time = 0x38;
  2840. m.mmw_des_io_invert = 0;
  2841. m.mmw_freeze = 0;
  2842. m.mmw_decay_prm = 0;
  2843. m.mmw_decay_updat_prm = 0;
  2844. /* Write all info to mmc */
  2845. mmc_write(base, 0, (u_char *)&m, sizeof(m));
  2846. /* The following code start the modem of the 2.00 frequency
  2847. * selectable cards at power on. It's not strictly needed for the
  2848. * following boots...
  2849. * The original patch was by Joe Finney for the PCMCIA driver, but
  2850. * I've cleaned it a bit and add documentation.
  2851. * Thanks to Loeke Brederveld from Lucent for the info.
  2852. */
  2853. /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
  2854. * (does it work for everybody ? - especially old cards...) */
  2855. /* Note : WFREQSEL verify that it is able to read from EEprom
  2856. * a sensible frequency (address 0x00) + that MMR_FEE_STATUS_ID
  2857. * is 0xA (Xilinx version) or 0xB (Ariadne version).
  2858. * My test is more crude but do work... */
  2859. if(!(mmc_in(base, mmroff(0, mmr_fee_status)) &
  2860. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
  2861. {
  2862. /* We must download the frequency parameters to the
  2863. * synthetisers (from the EEprom - area 1)
  2864. * Note : as the EEprom is auto decremented, we set the end
  2865. * if the area... */
  2866. m.mmw_fee_addr = 0x0F;
  2867. m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
  2868. mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
  2869. (unsigned char *)&m.mmw_fee_ctrl, 2);
  2870. /* Wait until the download is finished */
  2871. fee_wait(base, 100, 100);
  2872. #ifdef DEBUG_CONFIG_INFO
  2873. /* The frequency was in the last word downloaded... */
  2874. mmc_read(base, (char *)&m.mmw_fee_data_l - (char *)&m,
  2875. (unsigned char *)&m.mmw_fee_data_l, 2);
  2876. /* Print some info for the user */
  2877. printk(KERN_DEBUG "%s: Wavelan 2.00 recognised (frequency select) : Current frequency = %ld\n",
  2878. dev->name,
  2879. ((m.mmw_fee_data_h << 4) |
  2880. (m.mmw_fee_data_l >> 4)) * 5 / 2 + 24000L);
  2881. #endif
  2882. /* We must now download the power adjust value (gain) to
  2883. * the synthetisers (from the EEprom - area 7 - DAC) */
  2884. m.mmw_fee_addr = 0x61;
  2885. m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
  2886. mmc_write(base, (char *)&m.mmw_fee_ctrl - (char *)&m,
  2887. (unsigned char *)&m.mmw_fee_ctrl, 2);
  2888. /* Wait until the download is finished */
  2889. } /* if 2.00 card */
  2890. #ifdef DEBUG_CONFIG_TRACE
  2891. printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name);
  2892. #endif
  2893. return TRUE;
  2894. }
  2895. /*------------------------------------------------------------------*/
  2896. /*
  2897. * Routine to gracefully turn off reception, and wait for any commands
  2898. * to complete.
  2899. * (called in wv_ru_start() and wavelan_close() and wavelan_event())
  2900. */
  2901. static int
  2902. wv_ru_stop(struct net_device * dev)
  2903. {
  2904. unsigned int base = dev->base_addr;
  2905. net_local * lp = netdev_priv(dev);
  2906. unsigned long flags;
  2907. int status;
  2908. int spin;
  2909. #ifdef DEBUG_CONFIG_TRACE
  2910. printk(KERN_DEBUG "%s: ->wv_ru_stop()\n", dev->name);
  2911. #endif
  2912. spin_lock_irqsave(&lp->spinlock, flags);
  2913. /* First, send the LAN controller a stop receive command */
  2914. wv_82593_cmd(dev, "wv_graceful_shutdown(): stop-rcv",
  2915. OP0_STOP_RCV, SR0_NO_RESULT);
  2916. /* Then, spin until the receive unit goes idle */
  2917. spin = 300;
  2918. do
  2919. {
  2920. udelay(10);
  2921. outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
  2922. status = inb(LCSR(base));
  2923. }
  2924. while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_IDLE) && (spin-- > 0));
  2925. /* Now, spin until the chip finishes executing its current command */
  2926. do
  2927. {
  2928. udelay(10);
  2929. outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
  2930. status = inb(LCSR(base));
  2931. }
  2932. while(((status & SR3_EXEC_STATE_MASK) != SR3_EXEC_IDLE) && (spin-- > 0));
  2933. spin_unlock_irqrestore(&lp->spinlock, flags);
  2934. /* If there was a problem */
  2935. if(spin <= 0)
  2936. {
  2937. #ifdef DEBUG_CONFIG_ERRORS
  2938. printk(KERN_INFO "%s: wv_ru_stop(): The chip doesn't want to stop...\n",
  2939. dev->name);
  2940. #endif
  2941. return FALSE;
  2942. }
  2943. #ifdef DEBUG_CONFIG_TRACE
  2944. printk(KERN_DEBUG "%s: <-wv_ru_stop()\n", dev->name);
  2945. #endif
  2946. return TRUE;
  2947. } /* wv_ru_stop */
  2948. /*------------------------------------------------------------------*/
  2949. /*
  2950. * This routine starts the receive unit running. First, it checks if
  2951. * the card is actually ready. Then the card is instructed to receive
  2952. * packets again.
  2953. * (called in wv_hw_reset() & wavelan_open())
  2954. */
  2955. static int
  2956. wv_ru_start(struct net_device * dev)
  2957. {
  2958. unsigned int base = dev->base_addr;
  2959. net_local * lp = netdev_priv(dev);
  2960. unsigned long flags;
  2961. #ifdef DEBUG_CONFIG_TRACE
  2962. printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name);
  2963. #endif
  2964. /*
  2965. * We need to start from a quiescent state. To do so, we could check
  2966. * if the card is already running, but instead we just try to shut
  2967. * it down. First, we disable reception (in case it was already enabled).
  2968. */
  2969. if(!wv_ru_stop(dev))
  2970. return FALSE;
  2971. spin_lock_irqsave(&lp->spinlock, flags);
  2972. /* Now we know that no command is being executed. */
  2973. /* Set the receive frame pointer and stop pointer */
  2974. lp->rfp = 0;
  2975. outb(OP0_SWIT_TO_PORT_1 | CR0_CHNL, LCCR(base));
  2976. /* Reset ring management. This sets the receive frame pointer to 1 */
  2977. outb(OP1_RESET_RING_MNGMT, LCCR(base));
  2978. #if 0
  2979. /* XXX the i82593 manual page 6-4 seems to indicate that the stop register
  2980. should be set as below */
  2981. /* outb(CR1_STOP_REG_UPDATE|((RX_SIZE - 0x40)>> RX_SIZE_SHIFT),LCCR(base));*/
  2982. #elif 0
  2983. /* but I set it 0 instead */
  2984. lp->stop = 0;
  2985. #else
  2986. /* but I set it to 3 bytes per packet less than 8K */
  2987. lp->stop = (0 + RX_SIZE - ((RX_SIZE / 64) * 3)) % RX_SIZE;
  2988. #endif
  2989. outb(CR1_STOP_REG_UPDATE | (lp->stop >> RX_SIZE_SHIFT), LCCR(base));
  2990. outb(OP1_INT_ENABLE, LCCR(base));
  2991. outb(OP1_SWIT_TO_PORT_0, LCCR(base));
  2992. /* Reset receive DMA pointer */
  2993. hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  2994. hacr_write_slow(base, HACR_DEFAULT);
  2995. /* Receive DMA on channel 1 */
  2996. wv_82593_cmd(dev, "wv_ru_start(): rcv-enable",
  2997. CR0_CHNL | OP0_RCV_ENABLE, SR0_NO_RESULT);
  2998. #ifdef DEBUG_I82593_SHOW
  2999. {
  3000. int status;
  3001. int opri;
  3002. int spin = 10000;
  3003. /* spin until the chip starts receiving */
  3004. do
  3005. {
  3006. outb(OP0_NOP | CR0_STATUS_3, LCCR(base));
  3007. status = inb(LCSR(base));
  3008. if(spin-- <= 0)
  3009. break;
  3010. }
  3011. while(((status & SR3_RCV_STATE_MASK) != SR3_RCV_ACTIVE) &&
  3012. ((status & SR3_RCV_STATE_MASK) != SR3_RCV_READY));
  3013. printk(KERN_DEBUG "rcv status is 0x%x [i:%d]\n",
  3014. (status & SR3_RCV_STATE_MASK), i);
  3015. }
  3016. #endif
  3017. spin_unlock_irqrestore(&lp->spinlock, flags);
  3018. #ifdef DEBUG_CONFIG_TRACE
  3019. printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name);
  3020. #endif
  3021. return TRUE;
  3022. }
  3023. /*------------------------------------------------------------------*/
  3024. /*
  3025. * This routine does a standard config of the WaveLAN controller (i82593).
  3026. * In the ISA driver, this is integrated in wavelan_hardware_reset()
  3027. * (called by wv_hw_config(), wv_82593_reconfig() & wavelan_packet_xmit())
  3028. */
  3029. static int
  3030. wv_82593_config(struct net_device * dev)
  3031. {
  3032. unsigned int base = dev->base_addr;
  3033. net_local * lp = netdev_priv(dev);
  3034. struct i82593_conf_block cfblk;
  3035. int ret = TRUE;
  3036. #ifdef DEBUG_CONFIG_TRACE
  3037. printk(KERN_DEBUG "%s: ->wv_82593_config()\n", dev->name);
  3038. #endif
  3039. /* Create & fill i82593 config block
  3040. *
  3041. * Now conform to Wavelan document WCIN085B
  3042. */
  3043. memset(&cfblk, 0x00, sizeof(struct i82593_conf_block));
  3044. cfblk.d6mod = FALSE; /* Run in i82593 advanced mode */
  3045. cfblk.fifo_limit = 5; /* = 56 B rx and 40 B tx fifo thresholds */
  3046. cfblk.forgnesi = FALSE; /* 0=82C501, 1=AMD7992B compatibility */
  3047. cfblk.fifo_32 = 1;
  3048. cfblk.throttle_enb = FALSE;
  3049. cfblk.contin = TRUE; /* enable continuous mode */
  3050. cfblk.cntrxint = FALSE; /* enable continuous mode receive interrupts */
  3051. cfblk.addr_len = WAVELAN_ADDR_SIZE;
  3052. cfblk.acloc = TRUE; /* Disable source addr insertion by i82593 */
  3053. cfblk.preamb_len = 0; /* 2 bytes preamble (SFD) */
  3054. cfblk.loopback = FALSE;
  3055. cfblk.lin_prio = 0; /* conform to 802.3 backoff algorithm */
  3056. cfblk.exp_prio = 5; /* conform to 802.3 backoff algorithm */
  3057. cfblk.bof_met = 1; /* conform to 802.3 backoff algorithm */
  3058. cfblk.ifrm_spc = 0x20 >> 4; /* 32 bit times interframe spacing */
  3059. cfblk.slottim_low = 0x20 >> 5; /* 32 bit times slot time */
  3060. cfblk.slottim_hi = 0x0;
  3061. cfblk.max_retr = 15;
  3062. cfblk.prmisc = ((lp->promiscuous) ? TRUE: FALSE); /* Promiscuous mode */
  3063. cfblk.bc_dis = FALSE; /* Enable broadcast reception */
  3064. cfblk.crs_1 = TRUE; /* Transmit without carrier sense */
  3065. cfblk.nocrc_ins = FALSE; /* i82593 generates CRC */
  3066. cfblk.crc_1632 = FALSE; /* 32-bit Autodin-II CRC */
  3067. cfblk.crs_cdt = FALSE; /* CD not to be interpreted as CS */
  3068. cfblk.cs_filter = 0; /* CS is recognized immediately */
  3069. cfblk.crs_src = FALSE; /* External carrier sense */
  3070. cfblk.cd_filter = 0; /* CD is recognized immediately */
  3071. cfblk.min_fr_len = ETH_ZLEN >> 2; /* Minimum frame length 64 bytes */
  3072. cfblk.lng_typ = FALSE; /* Length field > 1500 = type field */
  3073. cfblk.lng_fld = TRUE; /* Disable 802.3 length field check */
  3074. cfblk.rxcrc_xf = TRUE; /* Don't transfer CRC to memory */
  3075. cfblk.artx = TRUE; /* Disable automatic retransmission */
  3076. cfblk.sarec = TRUE; /* Disable source addr trig of CD */
  3077. cfblk.tx_jabber = TRUE; /* Disable jabber jam sequence */
  3078. cfblk.hash_1 = FALSE; /* Use bits 0-5 in mc address hash */
  3079. cfblk.lbpkpol = TRUE; /* Loopback pin active high */
  3080. cfblk.fdx = FALSE; /* Disable full duplex operation */
  3081. cfblk.dummy_6 = 0x3f; /* all ones */
  3082. cfblk.mult_ia = FALSE; /* No multiple individual addresses */
  3083. cfblk.dis_bof = FALSE; /* Disable the backoff algorithm ?! */
  3084. cfblk.dummy_1 = TRUE; /* set to 1 */
  3085. cfblk.tx_ifs_retrig = 3; /* Hmm... Disabled */
  3086. #ifdef MULTICAST_ALL
  3087. cfblk.mc_all = (lp->allmulticast ? TRUE: FALSE); /* Allow all multicasts */
  3088. #else
  3089. cfblk.mc_all = FALSE; /* No multicast all mode */
  3090. #endif
  3091. cfblk.rcv_mon = 0; /* Monitor mode disabled */
  3092. cfblk.frag_acpt = TRUE; /* Do not accept fragments */
  3093. cfblk.tstrttrs = FALSE; /* No start transmission threshold */
  3094. cfblk.fretx = TRUE; /* FIFO automatic retransmission */
  3095. cfblk.syncrqs = FALSE; /* Synchronous DRQ deassertion... */
  3096. cfblk.sttlen = TRUE; /* 6 byte status registers */
  3097. cfblk.rx_eop = TRUE; /* Signal EOP on packet reception */
  3098. cfblk.tx_eop = TRUE; /* Signal EOP on packet transmission */
  3099. cfblk.rbuf_size = RX_SIZE>>11; /* Set receive buffer size */
  3100. cfblk.rcvstop = TRUE; /* Enable Receive Stop Register */
  3101. #ifdef DEBUG_I82593_SHOW
  3102. {
  3103. u_char *c = (u_char *) &cfblk;
  3104. int i;
  3105. printk(KERN_DEBUG "wavelan_cs: config block:");
  3106. for(i = 0; i < sizeof(struct i82593_conf_block); i++,c++)
  3107. {
  3108. if((i % 16) == 0) printk("\n" KERN_DEBUG);
  3109. printk("%02x ", *c);
  3110. }
  3111. printk("\n");
  3112. }
  3113. #endif
  3114. /* Copy the config block to the i82593 */
  3115. outb(TX_BASE & 0xff, PIORL(base));
  3116. outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
  3117. outb(sizeof(struct i82593_conf_block) & 0xff, PIOP(base)); /* lsb */
  3118. outb(sizeof(struct i82593_conf_block) >> 8, PIOP(base)); /* msb */
  3119. outsb(PIOP(base), (char *) &cfblk, sizeof(struct i82593_conf_block));
  3120. /* reset transmit DMA pointer */
  3121. hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  3122. hacr_write(base, HACR_DEFAULT);
  3123. if(!wv_82593_cmd(dev, "wv_82593_config(): configure",
  3124. OP0_CONFIGURE, SR0_CONFIGURE_DONE))
  3125. ret = FALSE;
  3126. /* Initialize adapter's ethernet MAC address */
  3127. outb(TX_BASE & 0xff, PIORL(base));
  3128. outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
  3129. outb(WAVELAN_ADDR_SIZE, PIOP(base)); /* byte count lsb */
  3130. outb(0, PIOP(base)); /* byte count msb */
  3131. outsb(PIOP(base), &dev->dev_addr[0], WAVELAN_ADDR_SIZE);
  3132. /* reset transmit DMA pointer */
  3133. hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  3134. hacr_write(base, HACR_DEFAULT);
  3135. if(!wv_82593_cmd(dev, "wv_82593_config(): ia-setup",
  3136. OP0_IA_SETUP, SR0_IA_SETUP_DONE))
  3137. ret = FALSE;
  3138. #ifdef WAVELAN_ROAMING
  3139. /* If roaming is enabled, join the "Beacon Request" multicast group... */
  3140. /* But only if it's not in there already! */
  3141. if(do_roaming)
  3142. dev_mc_add(dev,WAVELAN_BEACON_ADDRESS, WAVELAN_ADDR_SIZE, 1);
  3143. #endif /* WAVELAN_ROAMING */
  3144. /* If any multicast address to set */
  3145. if(lp->mc_count)
  3146. {
  3147. struct dev_mc_list * dmi;
  3148. int addrs_len = WAVELAN_ADDR_SIZE * lp->mc_count;
  3149. #ifdef DEBUG_CONFIG_INFO
  3150. DECLARE_MAC_BUF(mac);
  3151. printk(KERN_DEBUG "%s: wv_hw_config(): set %d multicast addresses:\n",
  3152. dev->name, lp->mc_count);
  3153. for(dmi=dev->mc_list; dmi; dmi=dmi->next)
  3154. printk(KERN_DEBUG " %s\n",
  3155. print_mac(mac, dmi->dmi_addr));
  3156. #endif
  3157. /* Initialize adapter's ethernet multicast addresses */
  3158. outb(TX_BASE & 0xff, PIORL(base));
  3159. outb(((TX_BASE >> 8) & PIORH_MASK) | PIORH_SEL_TX, PIORH(base));
  3160. outb(addrs_len & 0xff, PIOP(base)); /* byte count lsb */
  3161. outb((addrs_len >> 8), PIOP(base)); /* byte count msb */
  3162. for(dmi=dev->mc_list; dmi; dmi=dmi->next)
  3163. outsb(PIOP(base), dmi->dmi_addr, dmi->dmi_addrlen);
  3164. /* reset transmit DMA pointer */
  3165. hacr_write_slow(base, HACR_PWR_STAT | HACR_TX_DMA_RESET);
  3166. hacr_write(base, HACR_DEFAULT);
  3167. if(!wv_82593_cmd(dev, "wv_82593_config(): mc-setup",
  3168. OP0_MC_SETUP, SR0_MC_SETUP_DONE))
  3169. ret = FALSE;
  3170. lp->mc_count = dev->mc_count; /* remember to avoid repeated reset */
  3171. }
  3172. /* Job done, clear the flag */
  3173. lp->reconfig_82593 = FALSE;
  3174. #ifdef DEBUG_CONFIG_TRACE
  3175. printk(KERN_DEBUG "%s: <-wv_82593_config()\n", dev->name);
  3176. #endif
  3177. return(ret);
  3178. }
  3179. /*------------------------------------------------------------------*/
  3180. /*
  3181. * Read the Access Configuration Register, perform a software reset,
  3182. * and then re-enable the card's software.
  3183. *
  3184. * If I understand correctly : reset the pcmcia interface of the
  3185. * wavelan.
  3186. * (called by wv_config())
  3187. */
  3188. static int
  3189. wv_pcmcia_reset(struct net_device * dev)
  3190. {
  3191. int i;
  3192. conf_reg_t reg = { 0, CS_READ, CISREG_COR, 0 };
  3193. struct pcmcia_device * link = ((net_local *)netdev_priv(dev))->link;
  3194. #ifdef DEBUG_CONFIG_TRACE
  3195. printk(KERN_DEBUG "%s: ->wv_pcmcia_reset()\n", dev->name);
  3196. #endif
  3197. i = pcmcia_access_configuration_register(link, &reg);
  3198. if(i != CS_SUCCESS)
  3199. {
  3200. cs_error(link, AccessConfigurationRegister, i);
  3201. return FALSE;
  3202. }
  3203. #ifdef DEBUG_CONFIG_INFO
  3204. printk(KERN_DEBUG "%s: wavelan_pcmcia_reset(): Config reg is 0x%x\n",
  3205. dev->name, (u_int) reg.Value);
  3206. #endif
  3207. reg.Action = CS_WRITE;
  3208. reg.Value = reg.Value | COR_SW_RESET;
  3209. i = pcmcia_access_configuration_register(link, &reg);
  3210. if(i != CS_SUCCESS)
  3211. {
  3212. cs_error(link, AccessConfigurationRegister, i);
  3213. return FALSE;
  3214. }
  3215. reg.Action = CS_WRITE;
  3216. reg.Value = COR_LEVEL_IRQ | COR_CONFIG;
  3217. i = pcmcia_access_configuration_register(link, &reg);
  3218. if(i != CS_SUCCESS)
  3219. {
  3220. cs_error(link, AccessConfigurationRegister, i);
  3221. return FALSE;
  3222. }
  3223. #ifdef DEBUG_CONFIG_TRACE
  3224. printk(KERN_DEBUG "%s: <-wv_pcmcia_reset()\n", dev->name);
  3225. #endif
  3226. return TRUE;
  3227. }
  3228. /*------------------------------------------------------------------*/
  3229. /*
  3230. * wavelan_hw_config() is called after a CARD_INSERTION event is
  3231. * received, to configure the wavelan hardware.
  3232. * Note that the reception will be enabled in wavelan->open(), so the
  3233. * device is configured but idle...
  3234. * Performs the following actions:
  3235. * 1. A pcmcia software reset (using wv_pcmcia_reset())
  3236. * 2. A power reset (reset DMA)
  3237. * 3. Reset the LAN controller
  3238. * 4. Initialize the radio modem (using wv_mmc_init)
  3239. * 5. Configure LAN controller (using wv_82593_config)
  3240. * 6. Perform a diagnostic on the LAN controller
  3241. * (called by wavelan_event() & wv_hw_reset())
  3242. */
  3243. static int
  3244. wv_hw_config(struct net_device * dev)
  3245. {
  3246. net_local * lp = netdev_priv(dev);
  3247. unsigned int base = dev->base_addr;
  3248. unsigned long flags;
  3249. int ret = FALSE;
  3250. #ifdef DEBUG_CONFIG_TRACE
  3251. printk(KERN_DEBUG "%s: ->wv_hw_config()\n", dev->name);
  3252. #endif
  3253. /* compile-time check the sizes of structures */
  3254. BUILD_BUG_ON(sizeof(psa_t) != PSA_SIZE);
  3255. BUILD_BUG_ON(sizeof(mmw_t) != MMW_SIZE);
  3256. BUILD_BUG_ON(sizeof(mmr_t) != MMR_SIZE);
  3257. /* Reset the pcmcia interface */
  3258. if(wv_pcmcia_reset(dev) == FALSE)
  3259. return FALSE;
  3260. /* Disable interrupts */
  3261. spin_lock_irqsave(&lp->spinlock, flags);
  3262. /* Disguised goto ;-) */
  3263. do
  3264. {
  3265. /* Power UP the module + reset the modem + reset host adapter
  3266. * (in fact, reset DMA channels) */
  3267. hacr_write_slow(base, HACR_RESET);
  3268. hacr_write(base, HACR_DEFAULT);
  3269. /* Check if the module has been powered up... */
  3270. if(hasr_read(base) & HASR_NO_CLK)
  3271. {
  3272. #ifdef DEBUG_CONFIG_ERRORS
  3273. printk(KERN_WARNING "%s: wv_hw_config(): modem not connected or not a wavelan card\n",
  3274. dev->name);
  3275. #endif
  3276. break;
  3277. }
  3278. /* initialize the modem */
  3279. if(wv_mmc_init(dev) == FALSE)
  3280. {
  3281. #ifdef DEBUG_CONFIG_ERRORS
  3282. printk(KERN_WARNING "%s: wv_hw_config(): Can't configure the modem\n",
  3283. dev->name);
  3284. #endif
  3285. break;
  3286. }
  3287. /* reset the LAN controller (i82593) */
  3288. outb(OP0_RESET, LCCR(base));
  3289. mdelay(1); /* A bit crude ! */
  3290. /* Initialize the LAN controller */
  3291. if(wv_82593_config(dev) == FALSE)
  3292. {
  3293. #ifdef DEBUG_CONFIG_ERRORS
  3294. printk(KERN_INFO "%s: wv_hw_config(): i82593 init failed\n",
  3295. dev->name);
  3296. #endif
  3297. break;
  3298. }
  3299. /* Diagnostic */
  3300. if(wv_diag(dev) == FALSE)
  3301. {
  3302. #ifdef DEBUG_CONFIG_ERRORS
  3303. printk(KERN_INFO "%s: wv_hw_config(): i82593 diagnostic failed\n",
  3304. dev->name);
  3305. #endif
  3306. break;
  3307. }
  3308. /*
  3309. * insert code for loopback test here
  3310. */
  3311. /* The device is now configured */
  3312. lp->configured = 1;
  3313. ret = TRUE;
  3314. }
  3315. while(0);
  3316. /* Re-enable interrupts */
  3317. spin_unlock_irqrestore(&lp->spinlock, flags);
  3318. #ifdef DEBUG_CONFIG_TRACE
  3319. printk(KERN_DEBUG "%s: <-wv_hw_config()\n", dev->name);
  3320. #endif
  3321. return(ret);
  3322. }
  3323. /*------------------------------------------------------------------*/
  3324. /*
  3325. * Totally reset the wavelan and restart it.
  3326. * Performs the following actions:
  3327. * 1. Call wv_hw_config()
  3328. * 2. Start the LAN controller's receive unit
  3329. * (called by wavelan_event(), wavelan_watchdog() and wavelan_open())
  3330. */
  3331. static void
  3332. wv_hw_reset(struct net_device * dev)
  3333. {
  3334. net_local * lp = netdev_priv(dev);
  3335. #ifdef DEBUG_CONFIG_TRACE
  3336. printk(KERN_DEBUG "%s: ->wv_hw_reset()\n", dev->name);
  3337. #endif
  3338. lp->nresets++;
  3339. lp->configured = 0;
  3340. /* Call wv_hw_config() for most of the reset & init stuff */
  3341. if(wv_hw_config(dev) == FALSE)
  3342. return;
  3343. /* start receive unit */
  3344. wv_ru_start(dev);
  3345. #ifdef DEBUG_CONFIG_TRACE
  3346. printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name);
  3347. #endif
  3348. }
  3349. /*------------------------------------------------------------------*/
  3350. /*
  3351. * wv_pcmcia_config() is called after a CARD_INSERTION event is
  3352. * received, to configure the PCMCIA socket, and to make the ethernet
  3353. * device available to the system.
  3354. * (called by wavelan_event())
  3355. */
  3356. static int
  3357. wv_pcmcia_config(struct pcmcia_device * link)
  3358. {
  3359. struct net_device * dev = (struct net_device *) link->priv;
  3360. int i;
  3361. win_req_t req;
  3362. memreq_t mem;
  3363. net_local * lp = netdev_priv(dev);
  3364. #ifdef DEBUG_CONFIG_TRACE
  3365. printk(KERN_DEBUG "->wv_pcmcia_config(0x%p)\n", link);
  3366. #endif
  3367. do
  3368. {
  3369. i = pcmcia_request_io(link, &link->io);
  3370. if(i != CS_SUCCESS)
  3371. {
  3372. cs_error(link, RequestIO, i);
  3373. break;
  3374. }
  3375. /*
  3376. * Now allocate an interrupt line. Note that this does not
  3377. * actually assign a handler to the interrupt.
  3378. */
  3379. i = pcmcia_request_irq(link, &link->irq);
  3380. if(i != CS_SUCCESS)
  3381. {
  3382. cs_error(link, RequestIRQ, i);
  3383. break;
  3384. }
  3385. /*
  3386. * This actually configures the PCMCIA socket -- setting up
  3387. * the I/O windows and the interrupt mapping.
  3388. */
  3389. link->conf.ConfigIndex = 1;
  3390. i = pcmcia_request_configuration(link, &link->conf);
  3391. if(i != CS_SUCCESS)
  3392. {
  3393. cs_error(link, RequestConfiguration, i);
  3394. break;
  3395. }
  3396. /*
  3397. * Allocate a small memory window. Note that the struct pcmcia_device
  3398. * structure provides space for one window handle -- if your
  3399. * device needs several windows, you'll need to keep track of
  3400. * the handles in your private data structure, link->priv.
  3401. */
  3402. req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE;
  3403. req.Base = req.Size = 0;
  3404. req.AccessSpeed = mem_speed;
  3405. i = pcmcia_request_window(&link, &req, &link->win);
  3406. if(i != CS_SUCCESS)
  3407. {
  3408. cs_error(link, RequestWindow, i);
  3409. break;
  3410. }
  3411. lp->mem = ioremap(req.Base, req.Size);
  3412. dev->mem_start = (u_long)lp->mem;
  3413. dev->mem_end = dev->mem_start + req.Size;
  3414. mem.CardOffset = 0; mem.Page = 0;
  3415. i = pcmcia_map_mem_page(link->win, &mem);
  3416. if(i != CS_SUCCESS)
  3417. {
  3418. cs_error(link, MapMemPage, i);
  3419. break;
  3420. }
  3421. /* Feed device with this info... */
  3422. dev->irq = link->irq.AssignedIRQ;
  3423. dev->base_addr = link->io.BasePort1;
  3424. netif_start_queue(dev);
  3425. #ifdef DEBUG_CONFIG_INFO
  3426. printk(KERN_DEBUG "wv_pcmcia_config: MEMSTART %p IRQ %d IOPORT 0x%x\n",
  3427. lp->mem, dev->irq, (u_int) dev->base_addr);
  3428. #endif
  3429. SET_NETDEV_DEV(dev, &handle_to_dev(link));
  3430. i = register_netdev(dev);
  3431. if(i != 0)
  3432. {
  3433. #ifdef DEBUG_CONFIG_ERRORS
  3434. printk(KERN_INFO "wv_pcmcia_config(): register_netdev() failed\n");
  3435. #endif
  3436. break;
  3437. }
  3438. }
  3439. while(0); /* Humm... Disguised goto !!! */
  3440. /* If any step failed, release any partially configured state */
  3441. if(i != 0)
  3442. {
  3443. wv_pcmcia_release(link);
  3444. return FALSE;
  3445. }
  3446. strcpy(((net_local *) netdev_priv(dev))->node.dev_name, dev->name);
  3447. link->dev_node = &((net_local *) netdev_priv(dev))->node;
  3448. #ifdef DEBUG_CONFIG_TRACE
  3449. printk(KERN_DEBUG "<-wv_pcmcia_config()\n");
  3450. #endif
  3451. return TRUE;
  3452. }
  3453. /*------------------------------------------------------------------*/
  3454. /*
  3455. * After a card is removed, wv_pcmcia_release() will unregister the net
  3456. * device, and release the PCMCIA configuration. If the device is
  3457. * still open, this will be postponed until it is closed.
  3458. */
  3459. static void
  3460. wv_pcmcia_release(struct pcmcia_device *link)
  3461. {
  3462. struct net_device * dev = (struct net_device *) link->priv;
  3463. net_local * lp = netdev_priv(dev);
  3464. #ifdef DEBUG_CONFIG_TRACE
  3465. printk(KERN_DEBUG "%s: -> wv_pcmcia_release(0x%p)\n", dev->name, link);
  3466. #endif
  3467. iounmap(lp->mem);
  3468. pcmcia_disable_device(link);
  3469. #ifdef DEBUG_CONFIG_TRACE
  3470. printk(KERN_DEBUG "%s: <- wv_pcmcia_release()\n", dev->name);
  3471. #endif
  3472. }
  3473. /************************ INTERRUPT HANDLING ************************/
  3474. /*
  3475. * This function is the interrupt handler for the WaveLAN card. This
  3476. * routine will be called whenever:
  3477. * 1. A packet is received.
  3478. * 2. A packet has successfully been transferred and the unit is
  3479. * ready to transmit another packet.
  3480. * 3. A command has completed execution.
  3481. */
  3482. static irqreturn_t
  3483. wavelan_interrupt(int irq,
  3484. void * dev_id)
  3485. {
  3486. struct net_device * dev = dev_id;
  3487. net_local * lp;
  3488. unsigned int base;
  3489. int status0;
  3490. u_int tx_status;
  3491. #ifdef DEBUG_INTERRUPT_TRACE
  3492. printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name);
  3493. #endif
  3494. lp = netdev_priv(dev);
  3495. base = dev->base_addr;
  3496. #ifdef DEBUG_INTERRUPT_INFO
  3497. /* Check state of our spinlock (it should be cleared) */
  3498. if(spin_is_locked(&lp->spinlock))
  3499. printk(KERN_DEBUG
  3500. "%s: wavelan_interrupt(): spinlock is already locked !!!\n",
  3501. dev->name);
  3502. #endif
  3503. /* Prevent reentrancy. We need to do that because we may have
  3504. * multiple interrupt handler running concurently.
  3505. * It is safe because interrupts are disabled before aquiring
  3506. * the spinlock. */
  3507. spin_lock(&lp->spinlock);
  3508. /* Treat all pending interrupts */
  3509. while(1)
  3510. {
  3511. /* ---------------- INTERRUPT CHECKING ---------------- */
  3512. /*
  3513. * Look for the interrupt and verify the validity
  3514. */
  3515. outb(CR0_STATUS_0 | OP0_NOP, LCCR(base));
  3516. status0 = inb(LCSR(base));
  3517. #ifdef DEBUG_INTERRUPT_INFO
  3518. printk(KERN_DEBUG "status0 0x%x [%s => 0x%x]", status0,
  3519. (status0&SR0_INTERRUPT)?"int":"no int",status0&~SR0_INTERRUPT);
  3520. if(status0&SR0_INTERRUPT)
  3521. {
  3522. printk(" [%s => %d]\n", (status0 & SR0_CHNL) ? "chnl" :
  3523. ((status0 & SR0_EXECUTION) ? "cmd" :
  3524. ((status0 & SR0_RECEPTION) ? "recv" : "unknown")),
  3525. (status0 & SR0_EVENT_MASK));
  3526. }
  3527. else
  3528. printk("\n");
  3529. #endif
  3530. /* Return if no actual interrupt from i82593 (normal exit) */
  3531. if(!(status0 & SR0_INTERRUPT))
  3532. break;
  3533. /* If interrupt is both Rx and Tx or none...
  3534. * This code in fact is there to catch the spurious interrupt
  3535. * when you remove the wavelan pcmcia card from the socket */
  3536. if(((status0 & SR0_BOTH_RX_TX) == SR0_BOTH_RX_TX) ||
  3537. ((status0 & SR0_BOTH_RX_TX) == 0x0))
  3538. {
  3539. #ifdef DEBUG_INTERRUPT_INFO
  3540. printk(KERN_INFO "%s: wv_interrupt(): bogus interrupt (or from dead card) : %X\n",
  3541. dev->name, status0);
  3542. #endif
  3543. /* Acknowledge the interrupt */
  3544. outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
  3545. break;
  3546. }
  3547. /* ----------------- RECEIVING PACKET ----------------- */
  3548. /*
  3549. * When the wavelan signal the reception of a new packet,
  3550. * we call wv_packet_rcv() to copy if from the buffer and
  3551. * send it to NET3
  3552. */
  3553. if(status0 & SR0_RECEPTION)
  3554. {
  3555. #ifdef DEBUG_INTERRUPT_INFO
  3556. printk(KERN_DEBUG "%s: wv_interrupt(): receive\n", dev->name);
  3557. #endif
  3558. if((status0 & SR0_EVENT_MASK) == SR0_STOP_REG_HIT)
  3559. {
  3560. #ifdef DEBUG_INTERRUPT_ERROR
  3561. printk(KERN_INFO "%s: wv_interrupt(): receive buffer overflow\n",
  3562. dev->name);
  3563. #endif
  3564. lp->stats.rx_over_errors++;
  3565. lp->overrunning = 1;
  3566. }
  3567. /* Get the packet */
  3568. wv_packet_rcv(dev);
  3569. lp->overrunning = 0;
  3570. /* Acknowledge the interrupt */
  3571. outb(CR0_INT_ACK | OP0_NOP, LCCR(base));
  3572. continue;
  3573. }
  3574. /* ---------------- COMMAND COMPLETION ---------------- */
  3575. /*
  3576. * Interrupts issued when the i82593 has completed a command.
  3577. * Most likely : transmission done
  3578. */
  3579. /* If a transmission has been done */
  3580. if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_DONE ||
  3581. (status0 & SR0_EVENT_MASK) == SR0_RETRANSMIT_DONE ||
  3582. (status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
  3583. {
  3584. #ifdef DEBUG_TX_ERROR
  3585. if((status0 & SR0_EVENT_MASK) == SR0_TRANSMIT_NO_CRC_DONE)
  3586. printk(KERN_INFO "%s: wv_interrupt(): packet transmitted without CRC.\n",
  3587. dev->name);
  3588. #endif
  3589. /* Get transmission status */
  3590. tx_status = inb(LCSR(base));
  3591. tx_status |= (inb(LCSR(base)) << 8);
  3592. #ifdef DEBUG_INTERRUPT_INFO
  3593. printk(KERN_DEBUG "%s: wv_interrupt(): transmission done\n",
  3594. dev->name);
  3595. {
  3596. u_int rcv_bytes;
  3597. u_char status3;
  3598. rcv_bytes = inb(LCSR(base));
  3599. rcv_bytes |= (inb(LCSR(base)) << 8);
  3600. status3 = inb(LCSR(base));
  3601. printk(KERN_DEBUG "tx_status 0x%02x rcv_bytes 0x%02x status3 0x%x\n",
  3602. tx_status, rcv_bytes, (u_int) status3);
  3603. }
  3604. #endif
  3605. /* Check for possible errors */
  3606. if((tx_status & TX_OK) != TX_OK)
  3607. {
  3608. lp->stats.tx_errors++;
  3609. if(tx_status & TX_FRTL)
  3610. {
  3611. #ifdef DEBUG_TX_ERROR
  3612. printk(KERN_INFO "%s: wv_interrupt(): frame too long\n",
  3613. dev->name);
  3614. #endif
  3615. }
  3616. if(tx_status & TX_UND_RUN)
  3617. {
  3618. #ifdef DEBUG_TX_FAIL
  3619. printk(KERN_DEBUG "%s: wv_interrupt(): DMA underrun\n",
  3620. dev->name);
  3621. #endif
  3622. lp->stats.tx_aborted_errors++;
  3623. }
  3624. if(tx_status & TX_LOST_CTS)
  3625. {
  3626. #ifdef DEBUG_TX_FAIL
  3627. printk(KERN_DEBUG "%s: wv_interrupt(): no CTS\n", dev->name);
  3628. #endif
  3629. lp->stats.tx_carrier_errors++;
  3630. }
  3631. if(tx_status & TX_LOST_CRS)
  3632. {
  3633. #ifdef DEBUG_TX_FAIL
  3634. printk(KERN_DEBUG "%s: wv_interrupt(): no carrier\n",
  3635. dev->name);
  3636. #endif
  3637. lp->stats.tx_carrier_errors++;
  3638. }
  3639. if(tx_status & TX_HRT_BEAT)
  3640. {
  3641. #ifdef DEBUG_TX_FAIL
  3642. printk(KERN_DEBUG "%s: wv_interrupt(): heart beat\n", dev->name);
  3643. #endif
  3644. lp->stats.tx_heartbeat_errors++;
  3645. }
  3646. if(tx_status & TX_DEFER)
  3647. {
  3648. #ifdef DEBUG_TX_FAIL
  3649. printk(KERN_DEBUG "%s: wv_interrupt(): channel jammed\n",
  3650. dev->name);
  3651. #endif
  3652. }
  3653. /* Ignore late collisions since they're more likely to happen
  3654. * here (the WaveLAN design prevents the LAN controller from
  3655. * receiving while it is transmitting). We take action only when
  3656. * the maximum retransmit attempts is exceeded.
  3657. */
  3658. if(tx_status & TX_COLL)
  3659. {
  3660. if(tx_status & TX_MAX_COL)
  3661. {
  3662. #ifdef DEBUG_TX_FAIL
  3663. printk(KERN_DEBUG "%s: wv_interrupt(): channel congestion\n",
  3664. dev->name);
  3665. #endif
  3666. if(!(tx_status & TX_NCOL_MASK))
  3667. {
  3668. lp->stats.collisions += 0x10;
  3669. }
  3670. }
  3671. }
  3672. } /* if(!(tx_status & TX_OK)) */
  3673. lp->stats.collisions += (tx_status & TX_NCOL_MASK);
  3674. lp->stats.tx_packets++;
  3675. netif_wake_queue(dev);
  3676. outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
  3677. }
  3678. else /* if interrupt = transmit done or retransmit done */
  3679. {
  3680. #ifdef DEBUG_INTERRUPT_ERROR
  3681. printk(KERN_INFO "wavelan_cs: unknown interrupt, status0 = %02x\n",
  3682. status0);
  3683. #endif
  3684. outb(CR0_INT_ACK | OP0_NOP, LCCR(base)); /* Acknowledge the interrupt */
  3685. }
  3686. } /* while(1) */
  3687. spin_unlock(&lp->spinlock);
  3688. #ifdef DEBUG_INTERRUPT_TRACE
  3689. printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name);
  3690. #endif
  3691. /* We always return IRQ_HANDLED, because we will receive empty
  3692. * interrupts under normal operations. Anyway, it doesn't matter
  3693. * as we are dealing with an ISA interrupt that can't be shared.
  3694. *
  3695. * Explanation : under heavy receive, the following happens :
  3696. * ->wavelan_interrupt()
  3697. * (status0 & SR0_INTERRUPT) != 0
  3698. * ->wv_packet_rcv()
  3699. * (status0 & SR0_INTERRUPT) != 0
  3700. * ->wv_packet_rcv()
  3701. * (status0 & SR0_INTERRUPT) == 0 // i.e. no more event
  3702. * <-wavelan_interrupt()
  3703. * ->wavelan_interrupt()
  3704. * (status0 & SR0_INTERRUPT) == 0 // i.e. empty interrupt
  3705. * <-wavelan_interrupt()
  3706. * Jean II */
  3707. return IRQ_HANDLED;
  3708. } /* wv_interrupt */
  3709. /*------------------------------------------------------------------*/
  3710. /*
  3711. * Watchdog: when we start a transmission, a timer is set for us in the
  3712. * kernel. If the transmission completes, this timer is disabled. If
  3713. * the timer expires, we are called and we try to unlock the hardware.
  3714. *
  3715. * Note : This watchdog is move clever than the one in the ISA driver,
  3716. * because it try to abort the current command before reseting
  3717. * everything...
  3718. * On the other hand, it's a bit simpler, because we don't have to
  3719. * deal with the multiple Tx buffers...
  3720. */
  3721. static void
  3722. wavelan_watchdog(struct net_device * dev)
  3723. {
  3724. net_local * lp = netdev_priv(dev);
  3725. unsigned int base = dev->base_addr;
  3726. unsigned long flags;
  3727. int aborted = FALSE;
  3728. #ifdef DEBUG_INTERRUPT_TRACE
  3729. printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name);
  3730. #endif
  3731. #ifdef DEBUG_INTERRUPT_ERROR
  3732. printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n",
  3733. dev->name);
  3734. #endif
  3735. spin_lock_irqsave(&lp->spinlock, flags);
  3736. /* Ask to abort the current command */
  3737. outb(OP0_ABORT, LCCR(base));
  3738. /* Wait for the end of the command (a bit hackish) */
  3739. if(wv_82593_cmd(dev, "wavelan_watchdog(): abort",
  3740. OP0_NOP | CR0_STATUS_3, SR0_EXECUTION_ABORTED))
  3741. aborted = TRUE;
  3742. /* Release spinlock here so that wv_hw_reset() can grab it */
  3743. spin_unlock_irqrestore(&lp->spinlock, flags);
  3744. /* Check if we were successful in aborting it */
  3745. if(!aborted)
  3746. {
  3747. /* It seem that it wasn't enough */
  3748. #ifdef DEBUG_INTERRUPT_ERROR
  3749. printk(KERN_INFO "%s: wavelan_watchdog: abort failed, trying reset\n",
  3750. dev->name);
  3751. #endif
  3752. wv_hw_reset(dev);
  3753. }
  3754. #ifdef DEBUG_PSA_SHOW
  3755. {
  3756. psa_t psa;
  3757. psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
  3758. wv_psa_show(&psa);
  3759. }
  3760. #endif
  3761. #ifdef DEBUG_MMC_SHOW
  3762. wv_mmc_show(dev);
  3763. #endif
  3764. #ifdef DEBUG_I82593_SHOW
  3765. wv_ru_show(dev);
  3766. #endif
  3767. /* We are no more waiting for something... */
  3768. netif_wake_queue(dev);
  3769. #ifdef DEBUG_INTERRUPT_TRACE
  3770. printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name);
  3771. #endif
  3772. }
  3773. /********************* CONFIGURATION CALLBACKS *********************/
  3774. /*
  3775. * Here are the functions called by the pcmcia package (cardmgr) and
  3776. * linux networking (NET3) for initialization, configuration and
  3777. * deinstallations of the Wavelan Pcmcia Hardware.
  3778. */
  3779. /*------------------------------------------------------------------*/
  3780. /*
  3781. * Configure and start up the WaveLAN PCMCIA adaptor.
  3782. * Called by NET3 when it "open" the device.
  3783. */
  3784. static int
  3785. wavelan_open(struct net_device * dev)
  3786. {
  3787. net_local * lp = netdev_priv(dev);
  3788. struct pcmcia_device * link = lp->link;
  3789. unsigned int base = dev->base_addr;
  3790. #ifdef DEBUG_CALLBACK_TRACE
  3791. printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name,
  3792. (unsigned int) dev);
  3793. #endif
  3794. /* Check if the modem is powered up (wavelan_close() power it down */
  3795. if(hasr_read(base) & HASR_NO_CLK)
  3796. {
  3797. /* Power up (power up time is 250us) */
  3798. hacr_write(base, HACR_DEFAULT);
  3799. /* Check if the module has been powered up... */
  3800. if(hasr_read(base) & HASR_NO_CLK)
  3801. {
  3802. #ifdef DEBUG_CONFIG_ERRORS
  3803. printk(KERN_WARNING "%s: wavelan_open(): modem not connected\n",
  3804. dev->name);
  3805. #endif
  3806. return FALSE;
  3807. }
  3808. }
  3809. /* Start reception and declare the driver ready */
  3810. if(!lp->configured)
  3811. return FALSE;
  3812. if(!wv_ru_start(dev))
  3813. wv_hw_reset(dev); /* If problem : reset */
  3814. netif_start_queue(dev);
  3815. /* Mark the device as used */
  3816. link->open++;
  3817. #ifdef WAVELAN_ROAMING
  3818. if(do_roaming)
  3819. wv_roam_init(dev);
  3820. #endif /* WAVELAN_ROAMING */
  3821. #ifdef DEBUG_CALLBACK_TRACE
  3822. printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name);
  3823. #endif
  3824. return 0;
  3825. }
  3826. /*------------------------------------------------------------------*/
  3827. /*
  3828. * Shutdown the WaveLAN PCMCIA adaptor.
  3829. * Called by NET3 when it "close" the device.
  3830. */
  3831. static int
  3832. wavelan_close(struct net_device * dev)
  3833. {
  3834. struct pcmcia_device * link = ((net_local *)netdev_priv(dev))->link;
  3835. unsigned int base = dev->base_addr;
  3836. #ifdef DEBUG_CALLBACK_TRACE
  3837. printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name,
  3838. (unsigned int) dev);
  3839. #endif
  3840. /* If the device isn't open, then nothing to do */
  3841. if(!link->open)
  3842. {
  3843. #ifdef DEBUG_CONFIG_INFO
  3844. printk(KERN_DEBUG "%s: wavelan_close(): device not open\n", dev->name);
  3845. #endif
  3846. return 0;
  3847. }
  3848. #ifdef WAVELAN_ROAMING
  3849. /* Cleanup of roaming stuff... */
  3850. if(do_roaming)
  3851. wv_roam_cleanup(dev);
  3852. #endif /* WAVELAN_ROAMING */
  3853. link->open--;
  3854. /* If the card is still present */
  3855. if(netif_running(dev))
  3856. {
  3857. netif_stop_queue(dev);
  3858. /* Stop receiving new messages and wait end of transmission */
  3859. wv_ru_stop(dev);
  3860. /* Power down the module */
  3861. hacr_write(base, HACR_DEFAULT & (~HACR_PWR_STAT));
  3862. }
  3863. #ifdef DEBUG_CALLBACK_TRACE
  3864. printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name);
  3865. #endif
  3866. return 0;
  3867. }
  3868. /*------------------------------------------------------------------*/
  3869. /*
  3870. * wavelan_attach() creates an "instance" of the driver, allocating
  3871. * local data structures for one device (one interface). The device
  3872. * is registered with Card Services.
  3873. *
  3874. * The dev_link structure is initialized, but we don't actually
  3875. * configure the card at this point -- we wait until we receive a
  3876. * card insertion event.
  3877. */
  3878. static int
  3879. wavelan_probe(struct pcmcia_device *p_dev)
  3880. {
  3881. struct net_device * dev; /* Interface generic data */
  3882. net_local * lp; /* Interface specific data */
  3883. int ret;
  3884. #ifdef DEBUG_CALLBACK_TRACE
  3885. printk(KERN_DEBUG "-> wavelan_attach()\n");
  3886. #endif
  3887. /* The io structure describes IO port mapping */
  3888. p_dev->io.NumPorts1 = 8;
  3889. p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
  3890. p_dev->io.IOAddrLines = 3;
  3891. /* Interrupt setup */
  3892. p_dev->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
  3893. p_dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
  3894. p_dev->irq.Handler = wavelan_interrupt;
  3895. /* General socket configuration */
  3896. p_dev->conf.Attributes = CONF_ENABLE_IRQ;
  3897. p_dev->conf.IntType = INT_MEMORY_AND_IO;
  3898. /* Allocate the generic data structure */
  3899. dev = alloc_etherdev(sizeof(net_local));
  3900. if (!dev)
  3901. return -ENOMEM;
  3902. p_dev->priv = p_dev->irq.Instance = dev;
  3903. lp = netdev_priv(dev);
  3904. /* Init specific data */
  3905. lp->configured = 0;
  3906. lp->reconfig_82593 = FALSE;
  3907. lp->nresets = 0;
  3908. /* Multicast stuff */
  3909. lp->promiscuous = 0;
  3910. lp->allmulticast = 0;
  3911. lp->mc_count = 0;
  3912. /* Init spinlock */
  3913. spin_lock_init(&lp->spinlock);
  3914. /* back links */
  3915. lp->dev = dev;
  3916. /* wavelan NET3 callbacks */
  3917. dev->open = &wavelan_open;
  3918. dev->stop = &wavelan_close;
  3919. dev->hard_start_xmit = &wavelan_packet_xmit;
  3920. dev->get_stats = &wavelan_get_stats;
  3921. dev->set_multicast_list = &wavelan_set_multicast_list;
  3922. #ifdef SET_MAC_ADDRESS
  3923. dev->set_mac_address = &wavelan_set_mac_address;
  3924. #endif /* SET_MAC_ADDRESS */
  3925. /* Set the watchdog timer */
  3926. dev->tx_timeout = &wavelan_watchdog;
  3927. dev->watchdog_timeo = WATCHDOG_JIFFIES;
  3928. SET_ETHTOOL_OPS(dev, &ops);
  3929. dev->wireless_handlers = &wavelan_handler_def;
  3930. lp->wireless_data.spy_data = &lp->spy_data;
  3931. dev->wireless_data = &lp->wireless_data;
  3932. /* Other specific data */
  3933. dev->mtu = WAVELAN_MTU;
  3934. ret = wv_pcmcia_config(p_dev);
  3935. if (ret)
  3936. return ret;
  3937. ret = wv_hw_config(dev);
  3938. if (ret) {
  3939. dev->irq = 0;
  3940. pcmcia_disable_device(p_dev);
  3941. return ret;
  3942. }
  3943. wv_init_info(dev);
  3944. #ifdef DEBUG_CALLBACK_TRACE
  3945. printk(KERN_DEBUG "<- wavelan_attach()\n");
  3946. #endif
  3947. return 0;
  3948. }
  3949. /*------------------------------------------------------------------*/
  3950. /*
  3951. * This deletes a driver "instance". The device is de-registered with
  3952. * Card Services. If it has been released, all local data structures
  3953. * are freed. Otherwise, the structures will be freed when the device
  3954. * is released.
  3955. */
  3956. static void
  3957. wavelan_detach(struct pcmcia_device *link)
  3958. {
  3959. #ifdef DEBUG_CALLBACK_TRACE
  3960. printk(KERN_DEBUG "-> wavelan_detach(0x%p)\n", link);
  3961. #endif
  3962. /* Some others haven't done their job : give them another chance */
  3963. wv_pcmcia_release(link);
  3964. /* Free pieces */
  3965. if(link->priv)
  3966. {
  3967. struct net_device * dev = (struct net_device *) link->priv;
  3968. /* Remove ourselves from the kernel list of ethernet devices */
  3969. /* Warning : can't be called from interrupt, timer or wavelan_close() */
  3970. if (link->dev_node)
  3971. unregister_netdev(dev);
  3972. link->dev_node = NULL;
  3973. ((net_local *)netdev_priv(dev))->link = NULL;
  3974. ((net_local *)netdev_priv(dev))->dev = NULL;
  3975. free_netdev(dev);
  3976. }
  3977. #ifdef DEBUG_CALLBACK_TRACE
  3978. printk(KERN_DEBUG "<- wavelan_detach()\n");
  3979. #endif
  3980. }
  3981. static int wavelan_suspend(struct pcmcia_device *link)
  3982. {
  3983. struct net_device * dev = (struct net_device *) link->priv;
  3984. /* NB: wavelan_close will be called, but too late, so we are
  3985. * obliged to close nicely the wavelan here. David, could you
  3986. * close the device before suspending them ? And, by the way,
  3987. * could you, on resume, add a "route add -net ..." after the
  3988. * ifconfig up ? Thanks... */
  3989. /* Stop receiving new messages and wait end of transmission */
  3990. wv_ru_stop(dev);
  3991. if (link->open)
  3992. netif_device_detach(dev);
  3993. /* Power down the module */
  3994. hacr_write(dev->base_addr, HACR_DEFAULT & (~HACR_PWR_STAT));
  3995. return 0;
  3996. }
  3997. static int wavelan_resume(struct pcmcia_device *link)
  3998. {
  3999. struct net_device * dev = (struct net_device *) link->priv;
  4000. if (link->open) {
  4001. wv_hw_reset(dev);
  4002. netif_device_attach(dev);
  4003. }
  4004. return 0;
  4005. }
  4006. static struct pcmcia_device_id wavelan_ids[] = {
  4007. PCMCIA_DEVICE_PROD_ID12("AT&T","WaveLAN/PCMCIA", 0xe7c5affd, 0x1bc50975),
  4008. PCMCIA_DEVICE_PROD_ID12("Digital", "RoamAbout/DS", 0x9999ab35, 0x00d05e06),
  4009. PCMCIA_DEVICE_PROD_ID12("Lucent Technologies", "WaveLAN/PCMCIA", 0x23eb9949, 0x1bc50975),
  4010. PCMCIA_DEVICE_PROD_ID12("NCR", "WaveLAN/PCMCIA", 0x24358cd4, 0x1bc50975),
  4011. PCMCIA_DEVICE_NULL,
  4012. };
  4013. MODULE_DEVICE_TABLE(pcmcia, wavelan_ids);
  4014. static struct pcmcia_driver wavelan_driver = {
  4015. .owner = THIS_MODULE,
  4016. .drv = {
  4017. .name = "wavelan_cs",
  4018. },
  4019. .probe = wavelan_probe,
  4020. .remove = wavelan_detach,
  4021. .id_table = wavelan_ids,
  4022. .suspend = wavelan_suspend,
  4023. .resume = wavelan_resume,
  4024. };
  4025. static int __init
  4026. init_wavelan_cs(void)
  4027. {
  4028. return pcmcia_register_driver(&wavelan_driver);
  4029. }
  4030. static void __exit
  4031. exit_wavelan_cs(void)
  4032. {
  4033. pcmcia_unregister_driver(&wavelan_driver);
  4034. }
  4035. module_init(init_wavelan_cs);
  4036. module_exit(exit_wavelan_cs);