wavelan_cs.c 133 KB

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