wavelan_cs.c 131 KB

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