wavelan_cs.c 131 KB

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