wavelan.c 121 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410
  1. /*
  2. * WaveLAN ISA driver
  3. *
  4. * Jean II - HPLB '96
  5. *
  6. * Reorganisation and extension of the driver.
  7. * Original copyright follows (also see the end of this file).
  8. * See wavelan.p.h for details.
  9. *
  10. *
  11. *
  12. * AT&T GIS (nee NCR) WaveLAN card:
  13. * An Ethernet-like radio transceiver
  14. * controlled by an Intel 82586 coprocessor.
  15. */
  16. #include "wavelan.p.h" /* Private header */
  17. /************************* MISC SUBROUTINES **************************/
  18. /*
  19. * Subroutines which won't fit in one of the following category
  20. * (WaveLAN modem or i82586)
  21. */
  22. /*------------------------------------------------------------------*/
  23. /*
  24. * Translate irq number to PSA irq parameter
  25. */
  26. static u8 wv_irq_to_psa(int irq)
  27. {
  28. if (irq < 0 || irq >= ARRAY_SIZE(irqvals))
  29. return 0;
  30. return irqvals[irq];
  31. }
  32. /*------------------------------------------------------------------*/
  33. /*
  34. * Translate PSA irq parameter to irq number
  35. */
  36. static int __init wv_psa_to_irq(u8 irqval)
  37. {
  38. int irq;
  39. for (irq = 0; irq < ARRAY_SIZE(irqvals); irq++)
  40. if (irqvals[irq] == irqval)
  41. return irq;
  42. return -1;
  43. }
  44. /********************* HOST ADAPTER SUBROUTINES *********************/
  45. /*
  46. * Useful subroutines to manage the WaveLAN ISA interface
  47. *
  48. * One major difference with the PCMCIA hardware (except the port mapping)
  49. * is that we have to keep the state of the Host Control Register
  50. * because of the interrupt enable & bus size flags.
  51. */
  52. /*------------------------------------------------------------------*/
  53. /*
  54. * Read from card's Host Adaptor Status Register.
  55. */
  56. static inline u16 hasr_read(unsigned long ioaddr)
  57. {
  58. return (inw(HASR(ioaddr)));
  59. } /* hasr_read */
  60. /*------------------------------------------------------------------*/
  61. /*
  62. * Write to card's Host Adapter Command Register.
  63. */
  64. static inline void hacr_write(unsigned long ioaddr, u16 hacr)
  65. {
  66. outw(hacr, HACR(ioaddr));
  67. } /* hacr_write */
  68. /*------------------------------------------------------------------*/
  69. /*
  70. * Write to card's Host Adapter Command Register. Include a delay for
  71. * those times when it is needed.
  72. */
  73. static void hacr_write_slow(unsigned long ioaddr, u16 hacr)
  74. {
  75. hacr_write(ioaddr, hacr);
  76. /* delay might only be needed sometimes */
  77. mdelay(1);
  78. } /* hacr_write_slow */
  79. /*------------------------------------------------------------------*/
  80. /*
  81. * Set the channel attention bit.
  82. */
  83. static inline void set_chan_attn(unsigned long ioaddr, u16 hacr)
  84. {
  85. hacr_write(ioaddr, hacr | HACR_CA);
  86. } /* set_chan_attn */
  87. /*------------------------------------------------------------------*/
  88. /*
  89. * Reset, and then set host adaptor into default mode.
  90. */
  91. static inline void wv_hacr_reset(unsigned long ioaddr)
  92. {
  93. hacr_write_slow(ioaddr, HACR_RESET);
  94. hacr_write(ioaddr, HACR_DEFAULT);
  95. } /* wv_hacr_reset */
  96. /*------------------------------------------------------------------*/
  97. /*
  98. * Set the I/O transfer over the ISA bus to 8-bit mode
  99. */
  100. static inline void wv_16_off(unsigned long ioaddr, u16 hacr)
  101. {
  102. hacr &= ~HACR_16BITS;
  103. hacr_write(ioaddr, hacr);
  104. } /* wv_16_off */
  105. /*------------------------------------------------------------------*/
  106. /*
  107. * Set the I/O transfer over the ISA bus to 8-bit mode
  108. */
  109. static inline void wv_16_on(unsigned long ioaddr, u16 hacr)
  110. {
  111. hacr |= HACR_16BITS;
  112. hacr_write(ioaddr, hacr);
  113. } /* wv_16_on */
  114. /*------------------------------------------------------------------*/
  115. /*
  116. * Disable interrupts on the WaveLAN hardware.
  117. * (called by wv_82586_stop())
  118. */
  119. static inline void wv_ints_off(struct net_device * dev)
  120. {
  121. net_local *lp = (net_local *) dev->priv;
  122. unsigned long ioaddr = dev->base_addr;
  123. lp->hacr &= ~HACR_INTRON;
  124. hacr_write(ioaddr, lp->hacr);
  125. } /* wv_ints_off */
  126. /*------------------------------------------------------------------*/
  127. /*
  128. * Enable interrupts on the WaveLAN hardware.
  129. * (called by wv_hw_reset())
  130. */
  131. static inline void wv_ints_on(struct net_device * dev)
  132. {
  133. net_local *lp = (net_local *) dev->priv;
  134. unsigned long ioaddr = dev->base_addr;
  135. lp->hacr |= HACR_INTRON;
  136. hacr_write(ioaddr, lp->hacr);
  137. } /* wv_ints_on */
  138. /******************* MODEM MANAGEMENT SUBROUTINES *******************/
  139. /*
  140. * Useful subroutines to manage the modem of the WaveLAN
  141. */
  142. /*------------------------------------------------------------------*/
  143. /*
  144. * Read the Parameter Storage Area from the WaveLAN card's memory
  145. */
  146. /*
  147. * Read bytes from the PSA.
  148. */
  149. static void psa_read(unsigned long ioaddr, u16 hacr, int o, /* offset in PSA */
  150. u8 * b, /* buffer to fill */
  151. int n)
  152. { /* size to read */
  153. wv_16_off(ioaddr, hacr);
  154. while (n-- > 0) {
  155. outw(o, PIOR2(ioaddr));
  156. o++;
  157. *b++ = inb(PIOP2(ioaddr));
  158. }
  159. wv_16_on(ioaddr, hacr);
  160. } /* psa_read */
  161. /*------------------------------------------------------------------*/
  162. /*
  163. * Write the Parameter Storage Area to the WaveLAN card's memory.
  164. */
  165. static void psa_write(unsigned long ioaddr, u16 hacr, int o, /* Offset in PSA */
  166. u8 * b, /* Buffer in memory */
  167. int n)
  168. { /* Length of buffer */
  169. int count = 0;
  170. wv_16_off(ioaddr, hacr);
  171. while (n-- > 0) {
  172. outw(o, PIOR2(ioaddr));
  173. o++;
  174. outb(*b, PIOP2(ioaddr));
  175. b++;
  176. /* Wait for the memory to finish its write cycle */
  177. count = 0;
  178. while ((count++ < 100) &&
  179. (hasr_read(ioaddr) & HASR_PSA_BUSY)) mdelay(1);
  180. }
  181. wv_16_on(ioaddr, hacr);
  182. } /* psa_write */
  183. #ifdef SET_PSA_CRC
  184. /*------------------------------------------------------------------*/
  185. /*
  186. * Calculate the PSA CRC
  187. * Thanks to Valster, Nico <NVALSTER@wcnd.nl.lucent.com> for the code
  188. * NOTE: By specifying a length including the CRC position the
  189. * returned value should be zero. (i.e. a correct checksum in the PSA)
  190. *
  191. * The Windows drivers don't use the CRC, but the AP and the PtP tool
  192. * depend on it.
  193. */
  194. static u16 psa_crc(u8 * psa, /* The PSA */
  195. int size)
  196. { /* Number of short for CRC */
  197. int byte_cnt; /* Loop on the PSA */
  198. u16 crc_bytes = 0; /* Data in the PSA */
  199. int bit_cnt; /* Loop on the bits of the short */
  200. for (byte_cnt = 0; byte_cnt < size; byte_cnt++) {
  201. crc_bytes ^= psa[byte_cnt]; /* Its an xor */
  202. for (bit_cnt = 1; bit_cnt < 9; bit_cnt++) {
  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 update_psa_checksum(struct net_device * dev, unsigned long ioaddr, u16 hacr)
  217. {
  218. #ifdef SET_PSA_CRC
  219. psa_t psa;
  220. u16 crc;
  221. /* read the parameter storage area */
  222. psa_read(ioaddr, hacr, 0, (unsigned char *) &psa, sizeof(psa));
  223. /* update the checksum */
  224. crc = psa_crc((unsigned char *) &psa,
  225. sizeof(psa) - sizeof(psa.psa_crc[0]) -
  226. 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(ioaddr, hacr, (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
  241. "%s: update_psa_checksum(): CRC does not agree with PSA data (even after recalculating)\n",
  242. dev->name);
  243. #endif /* DEBUG_IOCTL_INFO */
  244. #endif /* SET_PSA_CRC */
  245. } /* update_psa_checksum */
  246. /*------------------------------------------------------------------*/
  247. /*
  248. * Write 1 byte to the MMC.
  249. */
  250. static void mmc_out(unsigned long ioaddr, u16 o, u8 d)
  251. {
  252. int count = 0;
  253. /* Wait for MMC to go idle */
  254. while ((count++ < 100) && (inw(HASR(ioaddr)) & HASR_MMC_BUSY))
  255. udelay(10);
  256. outw((u16) (((u16) d << 8) | (o << 1) | 1), MMCR(ioaddr));
  257. }
  258. /*------------------------------------------------------------------*/
  259. /*
  260. * Routine to write bytes to the Modem Management Controller.
  261. * We start at the end because it is the way it should be!
  262. */
  263. static void mmc_write(unsigned long ioaddr, u8 o, u8 * b, int n)
  264. {
  265. o += n;
  266. b += n;
  267. while (n-- > 0)
  268. mmc_out(ioaddr, --o, *(--b));
  269. } /* mmc_write */
  270. /*------------------------------------------------------------------*/
  271. /*
  272. * Read a byte from the MMC.
  273. * Optimised version for 1 byte, avoid using memory.
  274. */
  275. static u8 mmc_in(unsigned long ioaddr, u16 o)
  276. {
  277. int count = 0;
  278. while ((count++ < 100) && (inw(HASR(ioaddr)) & HASR_MMC_BUSY))
  279. udelay(10);
  280. outw(o << 1, MMCR(ioaddr));
  281. while ((count++ < 100) && (inw(HASR(ioaddr)) & HASR_MMC_BUSY))
  282. udelay(10);
  283. return (u8) (inw(MMCR(ioaddr)) >> 8);
  284. }
  285. /*------------------------------------------------------------------*/
  286. /*
  287. * Routine to read bytes from the Modem Management Controller.
  288. * The implementation is complicated by a lack of address lines,
  289. * which prevents decoding of the low-order bit.
  290. * (code has just been moved in the above function)
  291. * We start at the end because it is the way it should be!
  292. */
  293. static inline void mmc_read(unsigned long ioaddr, u8 o, u8 * b, int n)
  294. {
  295. o += n;
  296. b += n;
  297. while (n-- > 0)
  298. *(--b) = mmc_in(ioaddr, --o);
  299. } /* mmc_read */
  300. /*------------------------------------------------------------------*/
  301. /*
  302. * Get the type of encryption available.
  303. */
  304. static inline int mmc_encr(unsigned long ioaddr)
  305. { /* I/O port of the card */
  306. int temp;
  307. temp = mmc_in(ioaddr, mmroff(0, mmr_des_avail));
  308. if ((temp != MMR_DES_AVAIL_DES) && (temp != MMR_DES_AVAIL_AES))
  309. return 0;
  310. else
  311. return temp;
  312. }
  313. /*------------------------------------------------------------------*/
  314. /*
  315. * Wait for the frequency EEPROM to complete a command.
  316. * I hope this one will be optimally inlined.
  317. */
  318. static inline void fee_wait(unsigned long ioaddr, /* I/O port of the card */
  319. int delay, /* Base delay to wait for */
  320. int number)
  321. { /* Number of time to wait */
  322. int count = 0; /* Wait only a limited time */
  323. while ((count++ < number) &&
  324. (mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
  325. MMR_FEE_STATUS_BUSY)) udelay(delay);
  326. }
  327. /*------------------------------------------------------------------*/
  328. /*
  329. * Read bytes from the Frequency EEPROM (frequency select cards).
  330. */
  331. static void fee_read(unsigned long ioaddr, /* I/O port of the card */
  332. u16 o, /* destination offset */
  333. u16 * b, /* data buffer */
  334. int n)
  335. { /* number of registers */
  336. b += n; /* Position at the end of the area */
  337. /* Write the address */
  338. mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n - 1);
  339. /* Loop on all buffer */
  340. while (n-- > 0) {
  341. /* Write the read command */
  342. mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
  343. MMW_FEE_CTRL_READ);
  344. /* Wait until EEPROM is ready (should be quick). */
  345. fee_wait(ioaddr, 10, 100);
  346. /* Read the value. */
  347. *--b = ((mmc_in(ioaddr, mmroff(0, mmr_fee_data_h)) << 8) |
  348. mmc_in(ioaddr, mmroff(0, mmr_fee_data_l)));
  349. }
  350. }
  351. /*------------------------------------------------------------------*/
  352. /*
  353. * Write bytes from the Frequency EEPROM (frequency select cards).
  354. * This is a bit complicated, because the frequency EEPROM has to
  355. * be unprotected and the write enabled.
  356. * Jean II
  357. */
  358. static void fee_write(unsigned long ioaddr, /* I/O port of the card */
  359. u16 o, /* destination offset */
  360. u16 * b, /* data buffer */
  361. int n)
  362. { /* number of registers */
  363. b += n; /* Position at the end of the area. */
  364. #ifdef EEPROM_IS_PROTECTED /* disabled */
  365. #ifdef DOESNT_SEEM_TO_WORK /* disabled */
  366. /* Ask to read the protected register */
  367. mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRREAD);
  368. fee_wait(ioaddr, 10, 100);
  369. /* Read the protected register. */
  370. printk("Protected 2: %02X-%02X\n",
  371. mmc_in(ioaddr, mmroff(0, mmr_fee_data_h)),
  372. mmc_in(ioaddr, mmroff(0, mmr_fee_data_l)));
  373. #endif /* DOESNT_SEEM_TO_WORK */
  374. /* Enable protected register. */
  375. mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
  376. mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PREN);
  377. fee_wait(ioaddr, 10, 100);
  378. /* Unprotect area. */
  379. mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n);
  380. mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
  381. #ifdef DOESNT_SEEM_TO_WORK /* disabled */
  382. /* or use: */
  383. mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRCLEAR);
  384. #endif /* DOESNT_SEEM_TO_WORK */
  385. fee_wait(ioaddr, 10, 100);
  386. #endif /* EEPROM_IS_PROTECTED */
  387. /* Write enable. */
  388. mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
  389. mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WREN);
  390. fee_wait(ioaddr, 10, 100);
  391. /* Write the EEPROM address. */
  392. mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n - 1);
  393. /* Loop on all buffer */
  394. while (n-- > 0) {
  395. /* Write the value. */
  396. mmc_out(ioaddr, mmwoff(0, mmw_fee_data_h), (*--b) >> 8);
  397. mmc_out(ioaddr, mmwoff(0, mmw_fee_data_l), *b & 0xFF);
  398. /* Write the write command. */
  399. mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
  400. MMW_FEE_CTRL_WRITE);
  401. /* WaveLAN documentation says to wait at least 10 ms for EEBUSY = 0 */
  402. mdelay(10);
  403. fee_wait(ioaddr, 10, 100);
  404. }
  405. /* Write disable. */
  406. mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_DS);
  407. mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WDS);
  408. fee_wait(ioaddr, 10, 100);
  409. #ifdef EEPROM_IS_PROTECTED /* disabled */
  410. /* Reprotect EEPROM. */
  411. mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x00);
  412. mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
  413. fee_wait(ioaddr, 10, 100);
  414. #endif /* EEPROM_IS_PROTECTED */
  415. }
  416. /************************ I82586 SUBROUTINES *************************/
  417. /*
  418. * Useful subroutines to manage the Ethernet controller
  419. */
  420. /*------------------------------------------------------------------*/
  421. /*
  422. * Read bytes from the on-board RAM.
  423. * Why does inlining this function make it fail?
  424. */
  425. static /*inline */ void obram_read(unsigned long ioaddr,
  426. u16 o, u8 * b, int n)
  427. {
  428. outw(o, PIOR1(ioaddr));
  429. insw(PIOP1(ioaddr), (unsigned short *) b, (n + 1) >> 1);
  430. }
  431. /*------------------------------------------------------------------*/
  432. /*
  433. * Write bytes to the on-board RAM.
  434. */
  435. static inline void obram_write(unsigned long ioaddr, u16 o, u8 * b, int n)
  436. {
  437. outw(o, PIOR1(ioaddr));
  438. outsw(PIOP1(ioaddr), (unsigned short *) b, (n + 1) >> 1);
  439. }
  440. /*------------------------------------------------------------------*/
  441. /*
  442. * Acknowledge the reading of the status issued by the i82586.
  443. */
  444. static void wv_ack(struct net_device * dev)
  445. {
  446. net_local *lp = (net_local *) dev->priv;
  447. unsigned long ioaddr = dev->base_addr;
  448. u16 scb_cs;
  449. int i;
  450. obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
  451. (unsigned char *) &scb_cs, sizeof(scb_cs));
  452. scb_cs &= SCB_ST_INT;
  453. if (scb_cs == 0)
  454. return;
  455. obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
  456. (unsigned char *) &scb_cs, sizeof(scb_cs));
  457. set_chan_attn(ioaddr, lp->hacr);
  458. for (i = 1000; i > 0; i--) {
  459. obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
  460. (unsigned char *) &scb_cs, sizeof(scb_cs));
  461. if (scb_cs == 0)
  462. break;
  463. udelay(10);
  464. }
  465. udelay(100);
  466. #ifdef DEBUG_CONFIG_ERROR
  467. if (i <= 0)
  468. printk(KERN_INFO
  469. "%s: wv_ack(): board not accepting command.\n",
  470. dev->name);
  471. #endif
  472. }
  473. /*------------------------------------------------------------------*/
  474. /*
  475. * Set channel attention bit and busy wait until command has
  476. * completed, then acknowledge completion of the command.
  477. */
  478. static int wv_synchronous_cmd(struct net_device * dev, const char *str)
  479. {
  480. net_local *lp = (net_local *) dev->priv;
  481. unsigned long ioaddr = dev->base_addr;
  482. u16 scb_cmd;
  483. ach_t cb;
  484. int i;
  485. scb_cmd = SCB_CMD_CUC & SCB_CMD_CUC_GO;
  486. obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
  487. (unsigned char *) &scb_cmd, sizeof(scb_cmd));
  488. set_chan_attn(ioaddr, lp->hacr);
  489. for (i = 1000; i > 0; i--) {
  490. obram_read(ioaddr, OFFSET_CU, (unsigned char *) &cb,
  491. sizeof(cb));
  492. if (cb.ac_status & AC_SFLD_C)
  493. break;
  494. udelay(10);
  495. }
  496. udelay(100);
  497. if (i <= 0 || !(cb.ac_status & AC_SFLD_OK)) {
  498. #ifdef DEBUG_CONFIG_ERROR
  499. printk(KERN_INFO "%s: %s failed; status = 0x%x\n",
  500. dev->name, str, cb.ac_status);
  501. #endif
  502. #ifdef DEBUG_I82586_SHOW
  503. wv_scb_show(ioaddr);
  504. #endif
  505. return -1;
  506. }
  507. /* Ack the status */
  508. wv_ack(dev);
  509. return 0;
  510. }
  511. /*------------------------------------------------------------------*/
  512. /*
  513. * Configuration commands completion interrupt.
  514. * Check if done, and if OK.
  515. */
  516. static int
  517. wv_config_complete(struct net_device * dev, unsigned long ioaddr, net_local * lp)
  518. {
  519. unsigned short mcs_addr;
  520. unsigned short status;
  521. int ret;
  522. #ifdef DEBUG_INTERRUPT_TRACE
  523. printk(KERN_DEBUG "%s: ->wv_config_complete()\n", dev->name);
  524. #endif
  525. mcs_addr = lp->tx_first_in_use + sizeof(ac_tx_t) + sizeof(ac_nop_t)
  526. + sizeof(tbd_t) + sizeof(ac_cfg_t) + sizeof(ac_ias_t);
  527. /* Read the status of the last command (set mc list). */
  528. obram_read(ioaddr, acoff(mcs_addr, ac_status),
  529. (unsigned char *) &status, sizeof(status));
  530. /* If not completed -> exit */
  531. if ((status & AC_SFLD_C) == 0)
  532. ret = 0; /* Not ready to be scrapped */
  533. else {
  534. #ifdef DEBUG_CONFIG_ERROR
  535. unsigned short cfg_addr;
  536. unsigned short ias_addr;
  537. /* Check mc_config command */
  538. if ((status & AC_SFLD_OK) != AC_SFLD_OK)
  539. printk(KERN_INFO
  540. "%s: wv_config_complete(): set_multicast_address failed; status = 0x%x\n",
  541. dev->name, status);
  542. /* check ia-config command */
  543. ias_addr = mcs_addr - sizeof(ac_ias_t);
  544. obram_read(ioaddr, acoff(ias_addr, ac_status),
  545. (unsigned char *) &status, sizeof(status));
  546. if ((status & AC_SFLD_OK) != AC_SFLD_OK)
  547. printk(KERN_INFO
  548. "%s: wv_config_complete(): set_MAC_address failed; status = 0x%x\n",
  549. dev->name, status);
  550. /* Check config command. */
  551. cfg_addr = ias_addr - sizeof(ac_cfg_t);
  552. obram_read(ioaddr, acoff(cfg_addr, ac_status),
  553. (unsigned char *) &status, sizeof(status));
  554. if ((status & AC_SFLD_OK) != AC_SFLD_OK)
  555. printk(KERN_INFO
  556. "%s: wv_config_complete(): configure failed; status = 0x%x\n",
  557. dev->name, status);
  558. #endif /* DEBUG_CONFIG_ERROR */
  559. ret = 1; /* Ready to be scrapped */
  560. }
  561. #ifdef DEBUG_INTERRUPT_TRACE
  562. printk(KERN_DEBUG "%s: <-wv_config_complete() - %d\n", dev->name,
  563. ret);
  564. #endif
  565. return ret;
  566. }
  567. /*------------------------------------------------------------------*/
  568. /*
  569. * Command completion interrupt.
  570. * Reclaim as many freed tx buffers as we can.
  571. * (called in wavelan_interrupt()).
  572. * Note : the spinlock is already grabbed for us.
  573. */
  574. static int wv_complete(struct net_device * dev, unsigned long ioaddr, net_local * lp)
  575. {
  576. int nreaped = 0;
  577. #ifdef DEBUG_INTERRUPT_TRACE
  578. printk(KERN_DEBUG "%s: ->wv_complete()\n", dev->name);
  579. #endif
  580. /* Loop on all the transmit buffers */
  581. while (lp->tx_first_in_use != I82586NULL) {
  582. unsigned short tx_status;
  583. /* Read the first transmit buffer */
  584. obram_read(ioaddr, acoff(lp->tx_first_in_use, ac_status),
  585. (unsigned char *) &tx_status,
  586. sizeof(tx_status));
  587. /* If not completed -> exit */
  588. if ((tx_status & AC_SFLD_C) == 0)
  589. break;
  590. /* Hack for reconfiguration */
  591. if (tx_status == 0xFFFF)
  592. if (!wv_config_complete(dev, ioaddr, lp))
  593. break; /* Not completed */
  594. /* We now remove this buffer */
  595. nreaped++;
  596. --lp->tx_n_in_use;
  597. /*
  598. if (lp->tx_n_in_use > 0)
  599. printk("%c", "0123456789abcdefghijk"[lp->tx_n_in_use]);
  600. */
  601. /* Was it the last one? */
  602. if (lp->tx_n_in_use <= 0)
  603. lp->tx_first_in_use = I82586NULL;
  604. else {
  605. /* Next one in the chain */
  606. lp->tx_first_in_use += TXBLOCKZ;
  607. if (lp->tx_first_in_use >=
  608. OFFSET_CU +
  609. NTXBLOCKS * TXBLOCKZ) lp->tx_first_in_use -=
  610. NTXBLOCKS * TXBLOCKZ;
  611. }
  612. /* Hack for reconfiguration */
  613. if (tx_status == 0xFFFF)
  614. continue;
  615. /* Now, check status of the finished command */
  616. if (tx_status & AC_SFLD_OK) {
  617. int ncollisions;
  618. lp->stats.tx_packets++;
  619. ncollisions = tx_status & AC_SFLD_MAXCOL;
  620. lp->stats.collisions += ncollisions;
  621. #ifdef DEBUG_TX_INFO
  622. if (ncollisions > 0)
  623. printk(KERN_DEBUG
  624. "%s: wv_complete(): tx completed after %d collisions.\n",
  625. dev->name, ncollisions);
  626. #endif
  627. } else {
  628. lp->stats.tx_errors++;
  629. if (tx_status & AC_SFLD_S10) {
  630. lp->stats.tx_carrier_errors++;
  631. #ifdef DEBUG_TX_FAIL
  632. printk(KERN_DEBUG
  633. "%s: wv_complete(): tx error: no CS.\n",
  634. dev->name);
  635. #endif
  636. }
  637. if (tx_status & AC_SFLD_S9) {
  638. lp->stats.tx_carrier_errors++;
  639. #ifdef DEBUG_TX_FAIL
  640. printk(KERN_DEBUG
  641. "%s: wv_complete(): tx error: lost CTS.\n",
  642. dev->name);
  643. #endif
  644. }
  645. if (tx_status & AC_SFLD_S8) {
  646. lp->stats.tx_fifo_errors++;
  647. #ifdef DEBUG_TX_FAIL
  648. printk(KERN_DEBUG
  649. "%s: wv_complete(): tx error: slow DMA.\n",
  650. dev->name);
  651. #endif
  652. }
  653. if (tx_status & AC_SFLD_S6) {
  654. lp->stats.tx_heartbeat_errors++;
  655. #ifdef DEBUG_TX_FAIL
  656. printk(KERN_DEBUG
  657. "%s: wv_complete(): tx error: heart beat.\n",
  658. dev->name);
  659. #endif
  660. }
  661. if (tx_status & AC_SFLD_S5) {
  662. lp->stats.tx_aborted_errors++;
  663. #ifdef DEBUG_TX_FAIL
  664. printk(KERN_DEBUG
  665. "%s: wv_complete(): tx error: too many collisions.\n",
  666. dev->name);
  667. #endif
  668. }
  669. }
  670. #ifdef DEBUG_TX_INFO
  671. printk(KERN_DEBUG
  672. "%s: wv_complete(): tx completed, tx_status 0x%04x\n",
  673. dev->name, tx_status);
  674. #endif
  675. }
  676. #ifdef DEBUG_INTERRUPT_INFO
  677. if (nreaped > 1)
  678. printk(KERN_DEBUG "%s: wv_complete(): reaped %d\n",
  679. dev->name, nreaped);
  680. #endif
  681. /*
  682. * Inform upper layers.
  683. */
  684. if (lp->tx_n_in_use < NTXBLOCKS - 1) {
  685. netif_wake_queue(dev);
  686. }
  687. #ifdef DEBUG_INTERRUPT_TRACE
  688. printk(KERN_DEBUG "%s: <-wv_complete()\n", dev->name);
  689. #endif
  690. return nreaped;
  691. }
  692. /*------------------------------------------------------------------*/
  693. /*
  694. * Reconfigure the i82586, or at least ask for it.
  695. * Because wv_82586_config uses a transmission buffer, we must do it
  696. * when we are sure that there is one left, so we do it now
  697. * or in wavelan_packet_xmit() (I can't find any better place,
  698. * wavelan_interrupt is not an option), so you may experience
  699. * delays sometimes.
  700. */
  701. static void wv_82586_reconfig(struct net_device * dev)
  702. {
  703. net_local *lp = (net_local *) dev->priv;
  704. unsigned long flags;
  705. /* Arm the flag, will be cleard in wv_82586_config() */
  706. lp->reconfig_82586 = 1;
  707. /* Check if we can do it now ! */
  708. if((netif_running(dev)) && !(netif_queue_stopped(dev))) {
  709. spin_lock_irqsave(&lp->spinlock, flags);
  710. /* May fail */
  711. wv_82586_config(dev);
  712. spin_unlock_irqrestore(&lp->spinlock, flags);
  713. }
  714. else {
  715. #ifdef DEBUG_CONFIG_INFO
  716. printk(KERN_DEBUG
  717. "%s: wv_82586_reconfig(): delayed (state = %lX)\n",
  718. dev->name, dev->state);
  719. #endif
  720. }
  721. }
  722. /********************* DEBUG & INFO SUBROUTINES *********************/
  723. /*
  724. * This routine is used in the code to show information for debugging.
  725. * Most of the time, it dumps the contents of hardware structures.
  726. */
  727. #ifdef DEBUG_PSA_SHOW
  728. /*------------------------------------------------------------------*/
  729. /*
  730. * Print the formatted contents of the Parameter Storage Area.
  731. */
  732. static void wv_psa_show(psa_t * p)
  733. {
  734. DECLARE_MAC_BUF(mac);
  735. printk(KERN_DEBUG "##### WaveLAN PSA contents: #####\n");
  736. printk(KERN_DEBUG "psa_io_base_addr_1: 0x%02X %02X %02X %02X\n",
  737. p->psa_io_base_addr_1,
  738. p->psa_io_base_addr_2,
  739. p->psa_io_base_addr_3, p->psa_io_base_addr_4);
  740. printk(KERN_DEBUG "psa_rem_boot_addr_1: 0x%02X %02X %02X\n",
  741. p->psa_rem_boot_addr_1,
  742. p->psa_rem_boot_addr_2, p->psa_rem_boot_addr_3);
  743. printk(KERN_DEBUG "psa_holi_params: 0x%02x, ", p->psa_holi_params);
  744. printk("psa_int_req_no: %d\n", p->psa_int_req_no);
  745. #ifdef DEBUG_SHOW_UNUSED
  746. printk(KERN_DEBUG "psa_unused0[]: %s\n",
  747. print_mac(mac, p->psa_unused0));
  748. #endif /* DEBUG_SHOW_UNUSED */
  749. printk(KERN_DEBUG "psa_univ_mac_addr[]: %s\n",
  750. print_mac(mac, p->psa_univ_mac_addr));
  751. printk(KERN_DEBUG "psa_local_mac_addr[]: %s\n",
  752. print_mac(mac, p->psa_local_mac_addr));
  753. printk(KERN_DEBUG "psa_univ_local_sel: %d, ",
  754. p->psa_univ_local_sel);
  755. printk("psa_comp_number: %d, ", p->psa_comp_number);
  756. printk("psa_thr_pre_set: 0x%02x\n", p->psa_thr_pre_set);
  757. printk(KERN_DEBUG "psa_feature_select/decay_prm: 0x%02x, ",
  758. p->psa_feature_select);
  759. printk("psa_subband/decay_update_prm: %d\n", p->psa_subband);
  760. printk(KERN_DEBUG "psa_quality_thr: 0x%02x, ", p->psa_quality_thr);
  761. printk("psa_mod_delay: 0x%02x\n", p->psa_mod_delay);
  762. printk(KERN_DEBUG "psa_nwid: 0x%02x%02x, ", p->psa_nwid[0],
  763. p->psa_nwid[1]);
  764. printk("psa_nwid_select: %d\n", p->psa_nwid_select);
  765. printk(KERN_DEBUG "psa_encryption_select: %d, ",
  766. p->psa_encryption_select);
  767. printk
  768. ("psa_encryption_key[]: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
  769. p->psa_encryption_key[0], p->psa_encryption_key[1],
  770. p->psa_encryption_key[2], p->psa_encryption_key[3],
  771. p->psa_encryption_key[4], p->psa_encryption_key[5],
  772. p->psa_encryption_key[6], p->psa_encryption_key[7]);
  773. printk(KERN_DEBUG "psa_databus_width: %d\n", p->psa_databus_width);
  774. printk(KERN_DEBUG "psa_call_code/auto_squelch: 0x%02x, ",
  775. p->psa_call_code[0]);
  776. printk
  777. ("psa_call_code[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
  778. p->psa_call_code[0], p->psa_call_code[1], p->psa_call_code[2],
  779. p->psa_call_code[3], p->psa_call_code[4], p->psa_call_code[5],
  780. p->psa_call_code[6], p->psa_call_code[7]);
  781. #ifdef DEBUG_SHOW_UNUSED
  782. printk(KERN_DEBUG "psa_reserved[]: %02X:%02X\n",
  783. p->psa_reserved[0],
  784. p->psa_reserved[1]);
  785. #endif /* DEBUG_SHOW_UNUSED */
  786. printk(KERN_DEBUG "psa_conf_status: %d, ", p->psa_conf_status);
  787. printk("psa_crc: 0x%02x%02x, ", p->psa_crc[0], p->psa_crc[1]);
  788. printk("psa_crc_status: 0x%02x\n", p->psa_crc_status);
  789. } /* wv_psa_show */
  790. #endif /* DEBUG_PSA_SHOW */
  791. #ifdef DEBUG_MMC_SHOW
  792. /*------------------------------------------------------------------*/
  793. /*
  794. * Print the formatted status of the Modem Management Controller.
  795. * This function needs to be completed.
  796. */
  797. static void wv_mmc_show(struct net_device * dev)
  798. {
  799. unsigned long ioaddr = dev->base_addr;
  800. net_local *lp = (net_local *) dev->priv;
  801. mmr_t m;
  802. /* Basic check */
  803. if (hasr_read(ioaddr) & HASR_NO_CLK) {
  804. printk(KERN_WARNING
  805. "%s: wv_mmc_show: modem not connected\n",
  806. dev->name);
  807. return;
  808. }
  809. /* Read the mmc */
  810. mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
  811. mmc_read(ioaddr, 0, (u8 *) & m, sizeof(m));
  812. mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
  813. /* Don't forget to update statistics */
  814. lp->wstats.discard.nwid +=
  815. (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
  816. printk(KERN_DEBUG "##### WaveLAN modem status registers: #####\n");
  817. #ifdef DEBUG_SHOW_UNUSED
  818. printk(KERN_DEBUG
  819. "mmc_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
  820. m.mmr_unused0[0], m.mmr_unused0[1], m.mmr_unused0[2],
  821. m.mmr_unused0[3], m.mmr_unused0[4], m.mmr_unused0[5],
  822. m.mmr_unused0[6], m.mmr_unused0[7]);
  823. #endif /* DEBUG_SHOW_UNUSED */
  824. printk(KERN_DEBUG "Encryption algorithm: %02X - Status: %02X\n",
  825. m.mmr_des_avail, m.mmr_des_status);
  826. #ifdef DEBUG_SHOW_UNUSED
  827. printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n",
  828. m.mmr_unused1[0],
  829. m.mmr_unused1[1],
  830. m.mmr_unused1[2], m.mmr_unused1[3], m.mmr_unused1[4]);
  831. #endif /* DEBUG_SHOW_UNUSED */
  832. printk(KERN_DEBUG "dce_status: 0x%x [%s%s%s%s]\n",
  833. m.mmr_dce_status,
  834. (m.
  835. mmr_dce_status & MMR_DCE_STATUS_RX_BUSY) ?
  836. "energy detected," : "",
  837. (m.
  838. mmr_dce_status & MMR_DCE_STATUS_LOOPT_IND) ?
  839. "loop test indicated," : "",
  840. (m.
  841. mmr_dce_status & MMR_DCE_STATUS_TX_BUSY) ?
  842. "transmitter on," : "",
  843. (m.
  844. mmr_dce_status & MMR_DCE_STATUS_JBR_EXPIRED) ?
  845. "jabber timer expired," : "");
  846. printk(KERN_DEBUG "Dsp ID: %02X\n", m.mmr_dsp_id);
  847. #ifdef DEBUG_SHOW_UNUSED
  848. printk(KERN_DEBUG "mmc_unused2[]: %02X:%02X\n",
  849. m.mmr_unused2[0], m.mmr_unused2[1]);
  850. #endif /* DEBUG_SHOW_UNUSED */
  851. printk(KERN_DEBUG "# correct_nwid: %d, # wrong_nwid: %d\n",
  852. (m.mmr_correct_nwid_h << 8) | m.mmr_correct_nwid_l,
  853. (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l);
  854. printk(KERN_DEBUG "thr_pre_set: 0x%x [current signal %s]\n",
  855. m.mmr_thr_pre_set & MMR_THR_PRE_SET,
  856. (m.
  857. mmr_thr_pre_set & MMR_THR_PRE_SET_CUR) ? "above" :
  858. "below");
  859. printk(KERN_DEBUG "signal_lvl: %d [%s], ",
  860. m.mmr_signal_lvl & MMR_SIGNAL_LVL,
  861. (m.
  862. mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) ? "new msg" :
  863. "no new msg");
  864. printk("silence_lvl: %d [%s], ",
  865. m.mmr_silence_lvl & MMR_SILENCE_LVL,
  866. (m.
  867. mmr_silence_lvl & MMR_SILENCE_LVL_VALID) ? "update done" :
  868. "no new update");
  869. printk("sgnl_qual: 0x%x [%s]\n", m.mmr_sgnl_qual & MMR_SGNL_QUAL,
  870. (m.
  871. mmr_sgnl_qual & MMR_SGNL_QUAL_ANT) ? "Antenna 1" :
  872. "Antenna 0");
  873. #ifdef DEBUG_SHOW_UNUSED
  874. printk(KERN_DEBUG "netw_id_l: %x\n", m.mmr_netw_id_l);
  875. #endif /* DEBUG_SHOW_UNUSED */
  876. } /* wv_mmc_show */
  877. #endif /* DEBUG_MMC_SHOW */
  878. #ifdef DEBUG_I82586_SHOW
  879. /*------------------------------------------------------------------*/
  880. /*
  881. * Print the last block of the i82586 memory.
  882. */
  883. static void wv_scb_show(unsigned long ioaddr)
  884. {
  885. scb_t scb;
  886. obram_read(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
  887. sizeof(scb));
  888. printk(KERN_DEBUG "##### WaveLAN system control block: #####\n");
  889. printk(KERN_DEBUG "status: ");
  890. printk("stat 0x%x[%s%s%s%s] ",
  891. (scb.
  892. scb_status & (SCB_ST_CX | SCB_ST_FR | SCB_ST_CNA |
  893. SCB_ST_RNR)) >> 12,
  894. (scb.
  895. scb_status & SCB_ST_CX) ? "command completion interrupt," :
  896. "", (scb.scb_status & SCB_ST_FR) ? "frame received," : "",
  897. (scb.
  898. scb_status & SCB_ST_CNA) ? "command unit not active," : "",
  899. (scb.
  900. scb_status & SCB_ST_RNR) ? "receiving unit not ready," :
  901. "");
  902. printk("cus 0x%x[%s%s%s] ", (scb.scb_status & SCB_ST_CUS) >> 8,
  903. ((scb.scb_status & SCB_ST_CUS) ==
  904. SCB_ST_CUS_IDLE) ? "idle" : "",
  905. ((scb.scb_status & SCB_ST_CUS) ==
  906. SCB_ST_CUS_SUSP) ? "suspended" : "",
  907. ((scb.scb_status & SCB_ST_CUS) ==
  908. SCB_ST_CUS_ACTV) ? "active" : "");
  909. printk("rus 0x%x[%s%s%s%s]\n", (scb.scb_status & SCB_ST_RUS) >> 4,
  910. ((scb.scb_status & SCB_ST_RUS) ==
  911. SCB_ST_RUS_IDLE) ? "idle" : "",
  912. ((scb.scb_status & SCB_ST_RUS) ==
  913. SCB_ST_RUS_SUSP) ? "suspended" : "",
  914. ((scb.scb_status & SCB_ST_RUS) ==
  915. SCB_ST_RUS_NRES) ? "no resources" : "",
  916. ((scb.scb_status & SCB_ST_RUS) ==
  917. SCB_ST_RUS_RDY) ? "ready" : "");
  918. printk(KERN_DEBUG "command: ");
  919. printk("ack 0x%x[%s%s%s%s] ",
  920. (scb.
  921. scb_command & (SCB_CMD_ACK_CX | SCB_CMD_ACK_FR |
  922. SCB_CMD_ACK_CNA | SCB_CMD_ACK_RNR)) >> 12,
  923. (scb.
  924. scb_command & SCB_CMD_ACK_CX) ? "ack cmd completion," : "",
  925. (scb.
  926. scb_command & SCB_CMD_ACK_FR) ? "ack frame received," : "",
  927. (scb.
  928. scb_command & SCB_CMD_ACK_CNA) ? "ack CU not active," : "",
  929. (scb.
  930. scb_command & SCB_CMD_ACK_RNR) ? "ack RU not ready," : "");
  931. printk("cuc 0x%x[%s%s%s%s%s] ",
  932. (scb.scb_command & SCB_CMD_CUC) >> 8,
  933. ((scb.scb_command & SCB_CMD_CUC) ==
  934. SCB_CMD_CUC_NOP) ? "nop" : "",
  935. ((scb.scb_command & SCB_CMD_CUC) ==
  936. SCB_CMD_CUC_GO) ? "start cbl_offset" : "",
  937. ((scb.scb_command & SCB_CMD_CUC) ==
  938. SCB_CMD_CUC_RES) ? "resume execution" : "",
  939. ((scb.scb_command & SCB_CMD_CUC) ==
  940. SCB_CMD_CUC_SUS) ? "suspend execution" : "",
  941. ((scb.scb_command & SCB_CMD_CUC) ==
  942. SCB_CMD_CUC_ABT) ? "abort execution" : "");
  943. printk("ruc 0x%x[%s%s%s%s%s]\n",
  944. (scb.scb_command & SCB_CMD_RUC) >> 4,
  945. ((scb.scb_command & SCB_CMD_RUC) ==
  946. SCB_CMD_RUC_NOP) ? "nop" : "",
  947. ((scb.scb_command & SCB_CMD_RUC) ==
  948. SCB_CMD_RUC_GO) ? "start rfa_offset" : "",
  949. ((scb.scb_command & SCB_CMD_RUC) ==
  950. SCB_CMD_RUC_RES) ? "resume reception" : "",
  951. ((scb.scb_command & SCB_CMD_RUC) ==
  952. SCB_CMD_RUC_SUS) ? "suspend reception" : "",
  953. ((scb.scb_command & SCB_CMD_RUC) ==
  954. SCB_CMD_RUC_ABT) ? "abort reception" : "");
  955. printk(KERN_DEBUG "cbl_offset 0x%x ", scb.scb_cbl_offset);
  956. printk("rfa_offset 0x%x\n", scb.scb_rfa_offset);
  957. printk(KERN_DEBUG "crcerrs %d ", scb.scb_crcerrs);
  958. printk("alnerrs %d ", scb.scb_alnerrs);
  959. printk("rscerrs %d ", scb.scb_rscerrs);
  960. printk("ovrnerrs %d\n", scb.scb_ovrnerrs);
  961. }
  962. /*------------------------------------------------------------------*/
  963. /*
  964. * Print the formatted status of the i82586's receive unit.
  965. */
  966. static void wv_ru_show(struct net_device * dev)
  967. {
  968. /* net_local *lp = (net_local *) dev->priv; */
  969. printk(KERN_DEBUG
  970. "##### WaveLAN i82586 receiver unit status: #####\n");
  971. printk(KERN_DEBUG "ru:");
  972. /*
  973. * Not implemented yet
  974. */
  975. printk("\n");
  976. } /* wv_ru_show */
  977. /*------------------------------------------------------------------*/
  978. /*
  979. * Display info about one control block of the i82586 memory.
  980. */
  981. static void wv_cu_show_one(struct net_device * dev, net_local * lp, int i, u16 p)
  982. {
  983. unsigned long ioaddr;
  984. ac_tx_t actx;
  985. ioaddr = dev->base_addr;
  986. printk("%d: 0x%x:", i, p);
  987. obram_read(ioaddr, p, (unsigned char *) &actx, sizeof(actx));
  988. printk(" status=0x%x,", actx.tx_h.ac_status);
  989. printk(" command=0x%x,", actx.tx_h.ac_command);
  990. /*
  991. {
  992. tbd_t tbd;
  993. obram_read(ioaddr, actx.tx_tbd_offset, (unsigned char *)&tbd, sizeof(tbd));
  994. printk(" tbd_status=0x%x,", tbd.tbd_status);
  995. }
  996. */
  997. printk("|");
  998. }
  999. /*------------------------------------------------------------------*/
  1000. /*
  1001. * Print status of the command unit of the i82586.
  1002. */
  1003. static void wv_cu_show(struct net_device * dev)
  1004. {
  1005. net_local *lp = (net_local *) dev->priv;
  1006. unsigned int i;
  1007. u16 p;
  1008. printk(KERN_DEBUG
  1009. "##### WaveLAN i82586 command unit status: #####\n");
  1010. printk(KERN_DEBUG);
  1011. for (i = 0, p = lp->tx_first_in_use; i < NTXBLOCKS; i++) {
  1012. wv_cu_show_one(dev, lp, i, p);
  1013. p += TXBLOCKZ;
  1014. if (p >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
  1015. p -= NTXBLOCKS * TXBLOCKZ;
  1016. }
  1017. printk("\n");
  1018. }
  1019. #endif /* DEBUG_I82586_SHOW */
  1020. #ifdef DEBUG_DEVICE_SHOW
  1021. /*------------------------------------------------------------------*/
  1022. /*
  1023. * Print the formatted status of the WaveLAN PCMCIA device driver.
  1024. */
  1025. static void wv_dev_show(struct net_device * dev)
  1026. {
  1027. printk(KERN_DEBUG "dev:");
  1028. printk(" state=%lX,", dev->state);
  1029. printk(" trans_start=%ld,", dev->trans_start);
  1030. printk(" flags=0x%x,", dev->flags);
  1031. printk("\n");
  1032. } /* wv_dev_show */
  1033. /*------------------------------------------------------------------*/
  1034. /*
  1035. * Print the formatted status of the WaveLAN PCMCIA device driver's
  1036. * private information.
  1037. */
  1038. static void wv_local_show(struct net_device * dev)
  1039. {
  1040. net_local *lp;
  1041. lp = (net_local *) dev->priv;
  1042. printk(KERN_DEBUG "local:");
  1043. printk(" tx_n_in_use=%d,", lp->tx_n_in_use);
  1044. printk(" hacr=0x%x,", lp->hacr);
  1045. printk(" rx_head=0x%x,", lp->rx_head);
  1046. printk(" rx_last=0x%x,", lp->rx_last);
  1047. printk(" tx_first_free=0x%x,", lp->tx_first_free);
  1048. printk(" tx_first_in_use=0x%x,", lp->tx_first_in_use);
  1049. printk("\n");
  1050. } /* wv_local_show */
  1051. #endif /* DEBUG_DEVICE_SHOW */
  1052. #if defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO)
  1053. /*------------------------------------------------------------------*/
  1054. /*
  1055. * Dump packet header (and content if necessary) on the screen
  1056. */
  1057. static inline void wv_packet_info(u8 * p, /* Packet to dump */
  1058. int length, /* Length of the packet */
  1059. char *msg1, /* Name of the device */
  1060. char *msg2)
  1061. { /* Name of the function */
  1062. int i;
  1063. int maxi;
  1064. DECLARE_MAC_BUF(mac);
  1065. printk(KERN_DEBUG
  1066. "%s: %s(): dest %s, length %d\n",
  1067. msg1, msg2, print_mac(mac, p), length);
  1068. printk(KERN_DEBUG
  1069. "%s: %s(): src %s, type 0x%02X%02X\n",
  1070. msg1, msg2, print_mac(mac, &p[6]), p[12], p[13]);
  1071. #ifdef DEBUG_PACKET_DUMP
  1072. printk(KERN_DEBUG "data=\"");
  1073. if ((maxi = length) > DEBUG_PACKET_DUMP)
  1074. maxi = DEBUG_PACKET_DUMP;
  1075. for (i = 14; i < maxi; i++)
  1076. if (p[i] >= ' ' && p[i] <= '~')
  1077. printk(" %c", p[i]);
  1078. else
  1079. printk("%02X", p[i]);
  1080. if (maxi < length)
  1081. printk("..");
  1082. printk("\"\n");
  1083. printk(KERN_DEBUG "\n");
  1084. #endif /* DEBUG_PACKET_DUMP */
  1085. }
  1086. #endif /* defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) */
  1087. /*------------------------------------------------------------------*/
  1088. /*
  1089. * This is the information which is displayed by the driver at startup.
  1090. * There are lots of flags for configuring it to your liking.
  1091. */
  1092. static void wv_init_info(struct net_device * dev)
  1093. {
  1094. short ioaddr = dev->base_addr;
  1095. net_local *lp = (net_local *) dev->priv;
  1096. psa_t psa;
  1097. #ifdef DEBUG_BASIC_SHOW
  1098. DECLARE_MAC_BUF(mac);
  1099. #endif
  1100. /* Read the parameter storage area */
  1101. psa_read(ioaddr, lp->hacr, 0, (unsigned char *) &psa, sizeof(psa));
  1102. #ifdef DEBUG_PSA_SHOW
  1103. wv_psa_show(&psa);
  1104. #endif
  1105. #ifdef DEBUG_MMC_SHOW
  1106. wv_mmc_show(dev);
  1107. #endif
  1108. #ifdef DEBUG_I82586_SHOW
  1109. wv_cu_show(dev);
  1110. #endif
  1111. #ifdef DEBUG_BASIC_SHOW
  1112. /* Now, let's go for the basic stuff. */
  1113. printk(KERN_NOTICE "%s: WaveLAN at %#x, %s, IRQ %d",
  1114. dev->name, ioaddr, print_mac(mac, dev->dev_addr), dev->irq);
  1115. /* Print current network ID. */
  1116. if (psa.psa_nwid_select)
  1117. printk(", nwid 0x%02X-%02X", psa.psa_nwid[0],
  1118. psa.psa_nwid[1]);
  1119. else
  1120. printk(", nwid off");
  1121. /* If 2.00 card */
  1122. if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
  1123. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
  1124. unsigned short freq;
  1125. /* Ask the EEPROM to read the frequency from the first area. */
  1126. fee_read(ioaddr, 0x00, &freq, 1);
  1127. /* Print frequency */
  1128. printk(", 2.00, %ld", (freq >> 6) + 2400L);
  1129. /* Hack! */
  1130. if (freq & 0x20)
  1131. printk(".5");
  1132. } else {
  1133. printk(", PC");
  1134. switch (psa.psa_comp_number) {
  1135. case PSA_COMP_PC_AT_915:
  1136. case PSA_COMP_PC_AT_2400:
  1137. printk("-AT");
  1138. break;
  1139. case PSA_COMP_PC_MC_915:
  1140. case PSA_COMP_PC_MC_2400:
  1141. printk("-MC");
  1142. break;
  1143. case PSA_COMP_PCMCIA_915:
  1144. printk("MCIA");
  1145. break;
  1146. default:
  1147. printk("?");
  1148. }
  1149. printk(", ");
  1150. switch (psa.psa_subband) {
  1151. case PSA_SUBBAND_915:
  1152. printk("915");
  1153. break;
  1154. case PSA_SUBBAND_2425:
  1155. printk("2425");
  1156. break;
  1157. case PSA_SUBBAND_2460:
  1158. printk("2460");
  1159. break;
  1160. case PSA_SUBBAND_2484:
  1161. printk("2484");
  1162. break;
  1163. case PSA_SUBBAND_2430_5:
  1164. printk("2430.5");
  1165. break;
  1166. default:
  1167. printk("?");
  1168. }
  1169. }
  1170. printk(" MHz\n");
  1171. #endif /* DEBUG_BASIC_SHOW */
  1172. #ifdef DEBUG_VERSION_SHOW
  1173. /* Print version information */
  1174. printk(KERN_NOTICE "%s", version);
  1175. #endif
  1176. } /* wv_init_info */
  1177. /********************* IOCTL, STATS & RECONFIG *********************/
  1178. /*
  1179. * We found here routines that are called by Linux on different
  1180. * occasions after the configuration and not for transmitting data
  1181. * These may be called when the user use ifconfig, /proc/net/dev
  1182. * or wireless extensions
  1183. */
  1184. /*------------------------------------------------------------------*/
  1185. /*
  1186. * Get the current Ethernet statistics. This may be called with the
  1187. * card open or closed.
  1188. * Used when the user read /proc/net/dev
  1189. */
  1190. static en_stats *wavelan_get_stats(struct net_device * dev)
  1191. {
  1192. #ifdef DEBUG_IOCTL_TRACE
  1193. printk(KERN_DEBUG "%s: <>wavelan_get_stats()\n", dev->name);
  1194. #endif
  1195. return (&((net_local *) dev->priv)->stats);
  1196. }
  1197. /*------------------------------------------------------------------*/
  1198. /*
  1199. * Set or clear the multicast filter for this adaptor.
  1200. * num_addrs == -1 Promiscuous mode, receive all packets
  1201. * num_addrs == 0 Normal mode, clear multicast list
  1202. * num_addrs > 0 Multicast mode, receive normal and MC packets,
  1203. * and do best-effort filtering.
  1204. */
  1205. static void wavelan_set_multicast_list(struct net_device * dev)
  1206. {
  1207. net_local *lp = (net_local *) dev->priv;
  1208. #ifdef DEBUG_IOCTL_TRACE
  1209. printk(KERN_DEBUG "%s: ->wavelan_set_multicast_list()\n",
  1210. dev->name);
  1211. #endif
  1212. #ifdef DEBUG_IOCTL_INFO
  1213. printk(KERN_DEBUG
  1214. "%s: wavelan_set_multicast_list(): setting Rx mode %02X to %d addresses.\n",
  1215. dev->name, dev->flags, dev->mc_count);
  1216. #endif
  1217. /* Are we asking for promiscuous mode,
  1218. * or all multicast addresses (we don't have that!)
  1219. * or too many multicast addresses for the hardware filter? */
  1220. if ((dev->flags & IFF_PROMISC) ||
  1221. (dev->flags & IFF_ALLMULTI) ||
  1222. (dev->mc_count > I82586_MAX_MULTICAST_ADDRESSES)) {
  1223. /*
  1224. * Enable promiscuous mode: receive all packets.
  1225. */
  1226. if (!lp->promiscuous) {
  1227. lp->promiscuous = 1;
  1228. lp->mc_count = 0;
  1229. wv_82586_reconfig(dev);
  1230. }
  1231. } else
  1232. /* Are there multicast addresses to send? */
  1233. if (dev->mc_list != (struct dev_mc_list *) NULL) {
  1234. /*
  1235. * Disable promiscuous mode, but receive all packets
  1236. * in multicast list
  1237. */
  1238. #ifdef MULTICAST_AVOID
  1239. if (lp->promiscuous || (dev->mc_count != lp->mc_count))
  1240. #endif
  1241. {
  1242. lp->promiscuous = 0;
  1243. lp->mc_count = dev->mc_count;
  1244. wv_82586_reconfig(dev);
  1245. }
  1246. } else {
  1247. /*
  1248. * Switch to normal mode: disable promiscuous mode and
  1249. * clear the multicast list.
  1250. */
  1251. if (lp->promiscuous || lp->mc_count == 0) {
  1252. lp->promiscuous = 0;
  1253. lp->mc_count = 0;
  1254. wv_82586_reconfig(dev);
  1255. }
  1256. }
  1257. #ifdef DEBUG_IOCTL_TRACE
  1258. printk(KERN_DEBUG "%s: <-wavelan_set_multicast_list()\n",
  1259. dev->name);
  1260. #endif
  1261. }
  1262. /*------------------------------------------------------------------*/
  1263. /*
  1264. * This function doesn't exist.
  1265. * (Note : it was a nice way to test the reconfigure stuff...)
  1266. */
  1267. #ifdef SET_MAC_ADDRESS
  1268. static int wavelan_set_mac_address(struct net_device * dev, void *addr)
  1269. {
  1270. struct sockaddr *mac = addr;
  1271. /* Copy the address. */
  1272. memcpy(dev->dev_addr, mac->sa_data, WAVELAN_ADDR_SIZE);
  1273. /* Reconfigure the beast. */
  1274. wv_82586_reconfig(dev);
  1275. return 0;
  1276. }
  1277. #endif /* SET_MAC_ADDRESS */
  1278. /*------------------------------------------------------------------*/
  1279. /*
  1280. * Frequency setting (for hardware capable of it)
  1281. * It's a bit complicated and you don't really want to look into it.
  1282. * (called in wavelan_ioctl)
  1283. */
  1284. static int wv_set_frequency(unsigned long ioaddr, /* I/O port of the card */
  1285. iw_freq * frequency)
  1286. {
  1287. const int BAND_NUM = 10; /* Number of bands */
  1288. long freq = 0L; /* offset to 2.4 GHz in .5 MHz */
  1289. #ifdef DEBUG_IOCTL_INFO
  1290. int i;
  1291. #endif
  1292. /* Setting by frequency */
  1293. /* Theoretically, you may set any frequency between
  1294. * the two limits with a 0.5 MHz precision. In practice,
  1295. * I don't want you to have trouble with local regulations.
  1296. */
  1297. if ((frequency->e == 1) &&
  1298. (frequency->m >= (int) 2.412e8)
  1299. && (frequency->m <= (int) 2.487e8)) {
  1300. freq = ((frequency->m / 10000) - 24000L) / 5;
  1301. }
  1302. /* Setting by channel (same as wfreqsel) */
  1303. /* Warning: each channel is 22 MHz wide, so some of the channels
  1304. * will interfere. */
  1305. if ((frequency->e == 0) && (frequency->m < BAND_NUM)) {
  1306. /* Get frequency offset. */
  1307. freq = channel_bands[frequency->m] >> 1;
  1308. }
  1309. /* Verify that the frequency is allowed. */
  1310. if (freq != 0L) {
  1311. u16 table[10]; /* Authorized frequency table */
  1312. /* Read the frequency table. */
  1313. fee_read(ioaddr, 0x71, table, 10);
  1314. #ifdef DEBUG_IOCTL_INFO
  1315. printk(KERN_DEBUG "Frequency table: ");
  1316. for (i = 0; i < 10; i++) {
  1317. printk(" %04X", table[i]);
  1318. }
  1319. printk("\n");
  1320. #endif
  1321. /* Look in the table to see whether the frequency is allowed. */
  1322. if (!(table[9 - ((freq - 24) / 16)] &
  1323. (1 << ((freq - 24) % 16)))) return -EINVAL; /* not allowed */
  1324. } else
  1325. return -EINVAL;
  1326. /* if we get a usable frequency */
  1327. if (freq != 0L) {
  1328. unsigned short area[16];
  1329. unsigned short dac[2];
  1330. unsigned short area_verify[16];
  1331. unsigned short dac_verify[2];
  1332. /* Corresponding gain (in the power adjust value table)
  1333. * See AT&T WaveLAN Data Manual, REF 407-024689/E, page 3-8
  1334. * and WCIN062D.DOC, page 6.2.9. */
  1335. unsigned short power_limit[] = { 40, 80, 120, 160, 0 };
  1336. int power_band = 0; /* Selected band */
  1337. unsigned short power_adjust; /* Correct value */
  1338. /* Search for the gain. */
  1339. power_band = 0;
  1340. while ((freq > power_limit[power_band]) &&
  1341. (power_limit[++power_band] != 0));
  1342. /* Read the first area. */
  1343. fee_read(ioaddr, 0x00, area, 16);
  1344. /* Read the DAC. */
  1345. fee_read(ioaddr, 0x60, dac, 2);
  1346. /* Read the new power adjust value. */
  1347. fee_read(ioaddr, 0x6B - (power_band >> 1), &power_adjust,
  1348. 1);
  1349. if (power_band & 0x1)
  1350. power_adjust >>= 8;
  1351. else
  1352. power_adjust &= 0xFF;
  1353. #ifdef DEBUG_IOCTL_INFO
  1354. printk(KERN_DEBUG "WaveLAN EEPROM Area 1: ");
  1355. for (i = 0; i < 16; i++) {
  1356. printk(" %04X", area[i]);
  1357. }
  1358. printk("\n");
  1359. printk(KERN_DEBUG "WaveLAN EEPROM DAC: %04X %04X\n",
  1360. dac[0], dac[1]);
  1361. #endif
  1362. /* Frequency offset (for info only) */
  1363. area[0] = ((freq << 5) & 0xFFE0) | (area[0] & 0x1F);
  1364. /* Receiver Principle main divider coefficient */
  1365. area[3] = (freq >> 1) + 2400L - 352L;
  1366. area[2] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
  1367. /* Transmitter Main divider coefficient */
  1368. area[13] = (freq >> 1) + 2400L;
  1369. area[12] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
  1370. /* Other parts of the area are flags, bit streams or unused. */
  1371. /* Set the value in the DAC. */
  1372. dac[1] = ((power_adjust >> 1) & 0x7F) | (dac[1] & 0xFF80);
  1373. dac[0] = ((power_adjust & 0x1) << 4) | (dac[0] & 0xFFEF);
  1374. /* Write the first area. */
  1375. fee_write(ioaddr, 0x00, area, 16);
  1376. /* Write the DAC. */
  1377. fee_write(ioaddr, 0x60, dac, 2);
  1378. /* We now should verify here that the writing of the EEPROM went OK. */
  1379. /* Reread the first area. */
  1380. fee_read(ioaddr, 0x00, area_verify, 16);
  1381. /* Reread the DAC. */
  1382. fee_read(ioaddr, 0x60, dac_verify, 2);
  1383. /* Compare. */
  1384. if (memcmp(area, area_verify, 16 * 2) ||
  1385. memcmp(dac, dac_verify, 2 * 2)) {
  1386. #ifdef DEBUG_IOCTL_ERROR
  1387. printk(KERN_INFO
  1388. "WaveLAN: wv_set_frequency: unable to write new frequency to EEPROM(?).\n");
  1389. #endif
  1390. return -EOPNOTSUPP;
  1391. }
  1392. /* We must download the frequency parameters to the
  1393. * synthesizers (from the EEPROM - area 1)
  1394. * Note: as the EEPROM is automatically decremented, we set the end
  1395. * if the area... */
  1396. mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x0F);
  1397. mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
  1398. MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
  1399. /* Wait until the download is finished. */
  1400. fee_wait(ioaddr, 100, 100);
  1401. /* We must now download the power adjust value (gain) to
  1402. * the synthesizers (from the EEPROM - area 7 - DAC). */
  1403. mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x61);
  1404. mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
  1405. MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
  1406. /* Wait for the download to finish. */
  1407. fee_wait(ioaddr, 100, 100);
  1408. #ifdef DEBUG_IOCTL_INFO
  1409. /* Verification of what we have done */
  1410. printk(KERN_DEBUG "WaveLAN EEPROM Area 1: ");
  1411. for (i = 0; i < 16; i++) {
  1412. printk(" %04X", area_verify[i]);
  1413. }
  1414. printk("\n");
  1415. printk(KERN_DEBUG "WaveLAN EEPROM DAC: %04X %04X\n",
  1416. dac_verify[0], dac_verify[1]);
  1417. #endif
  1418. return 0;
  1419. } else
  1420. return -EINVAL; /* Bah, never get there... */
  1421. }
  1422. /*------------------------------------------------------------------*/
  1423. /*
  1424. * Give the list of available frequencies.
  1425. */
  1426. static int wv_frequency_list(unsigned long ioaddr, /* I/O port of the card */
  1427. iw_freq * list, /* List of frequencies to fill */
  1428. int max)
  1429. { /* Maximum number of frequencies */
  1430. u16 table[10]; /* Authorized frequency table */
  1431. long freq = 0L; /* offset to 2.4 GHz in .5 MHz + 12 MHz */
  1432. int i; /* index in the table */
  1433. int c = 0; /* Channel number */
  1434. /* Read the frequency table. */
  1435. fee_read(ioaddr, 0x71 /* frequency table */ , table, 10);
  1436. /* Check all frequencies. */
  1437. i = 0;
  1438. for (freq = 0; freq < 150; freq++)
  1439. /* Look in the table if the frequency is allowed */
  1440. if (table[9 - (freq / 16)] & (1 << (freq % 16))) {
  1441. /* Compute approximate channel number */
  1442. while ((c < ARRAY_SIZE(channel_bands)) &&
  1443. (((channel_bands[c] >> 1) - 24) < freq))
  1444. c++;
  1445. list[i].i = c; /* Set the list index */
  1446. /* put in the list */
  1447. list[i].m = (((freq + 24) * 5) + 24000L) * 10000;
  1448. list[i++].e = 1;
  1449. /* Check number. */
  1450. if (i >= max)
  1451. return (i);
  1452. }
  1453. return (i);
  1454. }
  1455. #ifdef IW_WIRELESS_SPY
  1456. /*------------------------------------------------------------------*/
  1457. /*
  1458. * Gather wireless spy statistics: for each packet, compare the source
  1459. * address with our list, and if they match, get the statistics.
  1460. * Sorry, but this function really needs the wireless extensions.
  1461. */
  1462. static inline void wl_spy_gather(struct net_device * dev,
  1463. u8 * mac, /* MAC address */
  1464. u8 * stats) /* Statistics to gather */
  1465. {
  1466. struct iw_quality wstats;
  1467. wstats.qual = stats[2] & MMR_SGNL_QUAL;
  1468. wstats.level = stats[0] & MMR_SIGNAL_LVL;
  1469. wstats.noise = stats[1] & MMR_SILENCE_LVL;
  1470. wstats.updated = 0x7;
  1471. /* Update spy records */
  1472. wireless_spy_update(dev, mac, &wstats);
  1473. }
  1474. #endif /* IW_WIRELESS_SPY */
  1475. #ifdef HISTOGRAM
  1476. /*------------------------------------------------------------------*/
  1477. /*
  1478. * This function calculates a histogram of the signal level.
  1479. * As the noise is quite constant, it's like doing it on the SNR.
  1480. * We have defined a set of interval (lp->his_range), and each time
  1481. * the level goes in that interval, we increment the count (lp->his_sum).
  1482. * With this histogram you may detect if one WaveLAN is really weak,
  1483. * or you may also calculate the mean and standard deviation of the level.
  1484. */
  1485. static inline void wl_his_gather(struct net_device * dev, u8 * stats)
  1486. { /* Statistics to gather */
  1487. net_local *lp = (net_local *) dev->priv;
  1488. u8 level = stats[0] & MMR_SIGNAL_LVL;
  1489. int i;
  1490. /* Find the correct interval. */
  1491. i = 0;
  1492. while ((i < (lp->his_number - 1))
  1493. && (level >= lp->his_range[i++]));
  1494. /* Increment interval counter. */
  1495. (lp->his_sum[i])++;
  1496. }
  1497. #endif /* HISTOGRAM */
  1498. /*------------------------------------------------------------------*/
  1499. /*
  1500. * Wireless Handler : get protocol name
  1501. */
  1502. static int wavelan_get_name(struct net_device *dev,
  1503. struct iw_request_info *info,
  1504. union iwreq_data *wrqu,
  1505. char *extra)
  1506. {
  1507. strcpy(wrqu->name, "WaveLAN");
  1508. return 0;
  1509. }
  1510. /*------------------------------------------------------------------*/
  1511. /*
  1512. * Wireless Handler : set NWID
  1513. */
  1514. static int wavelan_set_nwid(struct net_device *dev,
  1515. struct iw_request_info *info,
  1516. union iwreq_data *wrqu,
  1517. char *extra)
  1518. {
  1519. unsigned long ioaddr = dev->base_addr;
  1520. net_local *lp = (net_local *) dev->priv; /* lp is not unused */
  1521. psa_t psa;
  1522. mm_t m;
  1523. unsigned long flags;
  1524. int ret = 0;
  1525. /* Disable interrupts and save flags. */
  1526. spin_lock_irqsave(&lp->spinlock, flags);
  1527. /* Set NWID in WaveLAN. */
  1528. if (!wrqu->nwid.disabled) {
  1529. /* Set NWID in psa */
  1530. psa.psa_nwid[0] = (wrqu->nwid.value & 0xFF00) >> 8;
  1531. psa.psa_nwid[1] = wrqu->nwid.value & 0xFF;
  1532. psa.psa_nwid_select = 0x01;
  1533. psa_write(ioaddr, lp->hacr,
  1534. (char *) psa.psa_nwid - (char *) &psa,
  1535. (unsigned char *) psa.psa_nwid, 3);
  1536. /* Set NWID in mmc. */
  1537. m.w.mmw_netw_id_l = psa.psa_nwid[1];
  1538. m.w.mmw_netw_id_h = psa.psa_nwid[0];
  1539. mmc_write(ioaddr,
  1540. (char *) &m.w.mmw_netw_id_l -
  1541. (char *) &m,
  1542. (unsigned char *) &m.w.mmw_netw_id_l, 2);
  1543. mmc_out(ioaddr, mmwoff(0, mmw_loopt_sel), 0x00);
  1544. } else {
  1545. /* Disable NWID in the psa. */
  1546. psa.psa_nwid_select = 0x00;
  1547. psa_write(ioaddr, lp->hacr,
  1548. (char *) &psa.psa_nwid_select -
  1549. (char *) &psa,
  1550. (unsigned char *) &psa.psa_nwid_select,
  1551. 1);
  1552. /* Disable NWID in the mmc (no filtering). */
  1553. mmc_out(ioaddr, mmwoff(0, mmw_loopt_sel),
  1554. MMW_LOOPT_SEL_DIS_NWID);
  1555. }
  1556. /* update the Wavelan checksum */
  1557. update_psa_checksum(dev, ioaddr, lp->hacr);
  1558. /* Enable interrupts and restore flags. */
  1559. spin_unlock_irqrestore(&lp->spinlock, flags);
  1560. return ret;
  1561. }
  1562. /*------------------------------------------------------------------*/
  1563. /*
  1564. * Wireless Handler : get NWID
  1565. */
  1566. static int wavelan_get_nwid(struct net_device *dev,
  1567. struct iw_request_info *info,
  1568. union iwreq_data *wrqu,
  1569. char *extra)
  1570. {
  1571. unsigned long ioaddr = dev->base_addr;
  1572. net_local *lp = (net_local *) dev->priv; /* lp is not unused */
  1573. psa_t psa;
  1574. unsigned long flags;
  1575. int ret = 0;
  1576. /* Disable interrupts and save flags. */
  1577. spin_lock_irqsave(&lp->spinlock, flags);
  1578. /* Read the NWID. */
  1579. psa_read(ioaddr, lp->hacr,
  1580. (char *) psa.psa_nwid - (char *) &psa,
  1581. (unsigned char *) psa.psa_nwid, 3);
  1582. wrqu->nwid.value = (psa.psa_nwid[0] << 8) + psa.psa_nwid[1];
  1583. wrqu->nwid.disabled = !(psa.psa_nwid_select);
  1584. wrqu->nwid.fixed = 1; /* Superfluous */
  1585. /* Enable interrupts and restore flags. */
  1586. spin_unlock_irqrestore(&lp->spinlock, flags);
  1587. return ret;
  1588. }
  1589. /*------------------------------------------------------------------*/
  1590. /*
  1591. * Wireless Handler : set frequency
  1592. */
  1593. static int wavelan_set_freq(struct net_device *dev,
  1594. struct iw_request_info *info,
  1595. union iwreq_data *wrqu,
  1596. char *extra)
  1597. {
  1598. unsigned long ioaddr = dev->base_addr;
  1599. net_local *lp = (net_local *) dev->priv; /* lp is not unused */
  1600. unsigned long flags;
  1601. int ret;
  1602. /* Disable interrupts and save flags. */
  1603. spin_lock_irqsave(&lp->spinlock, flags);
  1604. /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
  1605. if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
  1606. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
  1607. ret = wv_set_frequency(ioaddr, &(wrqu->freq));
  1608. else
  1609. ret = -EOPNOTSUPP;
  1610. /* Enable interrupts and restore flags. */
  1611. spin_unlock_irqrestore(&lp->spinlock, flags);
  1612. return ret;
  1613. }
  1614. /*------------------------------------------------------------------*/
  1615. /*
  1616. * Wireless Handler : get frequency
  1617. */
  1618. static int wavelan_get_freq(struct net_device *dev,
  1619. struct iw_request_info *info,
  1620. union iwreq_data *wrqu,
  1621. char *extra)
  1622. {
  1623. unsigned long ioaddr = dev->base_addr;
  1624. net_local *lp = (net_local *) dev->priv; /* lp is not unused */
  1625. psa_t psa;
  1626. unsigned long flags;
  1627. int ret = 0;
  1628. /* Disable interrupts and save flags. */
  1629. spin_lock_irqsave(&lp->spinlock, flags);
  1630. /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable).
  1631. * Does it work for everybody, especially old cards? */
  1632. if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
  1633. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
  1634. unsigned short freq;
  1635. /* Ask the EEPROM to read the frequency from the first area. */
  1636. fee_read(ioaddr, 0x00, &freq, 1);
  1637. wrqu->freq.m = ((freq >> 5) * 5 + 24000L) * 10000;
  1638. wrqu->freq.e = 1;
  1639. } else {
  1640. psa_read(ioaddr, lp->hacr,
  1641. (char *) &psa.psa_subband - (char *) &psa,
  1642. (unsigned char *) &psa.psa_subband, 1);
  1643. if (psa.psa_subband <= 4) {
  1644. wrqu->freq.m = fixed_bands[psa.psa_subband];
  1645. wrqu->freq.e = (psa.psa_subband != 0);
  1646. } else
  1647. ret = -EOPNOTSUPP;
  1648. }
  1649. /* Enable interrupts and restore flags. */
  1650. spin_unlock_irqrestore(&lp->spinlock, flags);
  1651. return ret;
  1652. }
  1653. /*------------------------------------------------------------------*/
  1654. /*
  1655. * Wireless Handler : set level threshold
  1656. */
  1657. static int wavelan_set_sens(struct net_device *dev,
  1658. struct iw_request_info *info,
  1659. union iwreq_data *wrqu,
  1660. char *extra)
  1661. {
  1662. unsigned long ioaddr = dev->base_addr;
  1663. net_local *lp = (net_local *) dev->priv; /* lp is not unused */
  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. /* Set the level threshold. */
  1670. /* We should complain loudly if wrqu->sens.fixed = 0, because we
  1671. * can't set auto mode... */
  1672. psa.psa_thr_pre_set = wrqu->sens.value & 0x3F;
  1673. psa_write(ioaddr, lp->hacr,
  1674. (char *) &psa.psa_thr_pre_set - (char *) &psa,
  1675. (unsigned char *) &psa.psa_thr_pre_set, 1);
  1676. /* update the Wavelan checksum */
  1677. update_psa_checksum(dev, ioaddr, lp->hacr);
  1678. mmc_out(ioaddr, mmwoff(0, mmw_thr_pre_set),
  1679. psa.psa_thr_pre_set);
  1680. /* Enable interrupts and restore flags. */
  1681. spin_unlock_irqrestore(&lp->spinlock, flags);
  1682. return ret;
  1683. }
  1684. /*------------------------------------------------------------------*/
  1685. /*
  1686. * Wireless Handler : get level threshold
  1687. */
  1688. static int wavelan_get_sens(struct net_device *dev,
  1689. struct iw_request_info *info,
  1690. union iwreq_data *wrqu,
  1691. char *extra)
  1692. {
  1693. unsigned long ioaddr = dev->base_addr;
  1694. net_local *lp = (net_local *) dev->priv; /* lp is not unused */
  1695. psa_t psa;
  1696. unsigned long flags;
  1697. int ret = 0;
  1698. /* Disable interrupts and save flags. */
  1699. spin_lock_irqsave(&lp->spinlock, flags);
  1700. /* Read the level threshold. */
  1701. psa_read(ioaddr, lp->hacr,
  1702. (char *) &psa.psa_thr_pre_set - (char *) &psa,
  1703. (unsigned char *) &psa.psa_thr_pre_set, 1);
  1704. wrqu->sens.value = psa.psa_thr_pre_set & 0x3F;
  1705. wrqu->sens.fixed = 1;
  1706. /* Enable interrupts and restore flags. */
  1707. spin_unlock_irqrestore(&lp->spinlock, flags);
  1708. return ret;
  1709. }
  1710. /*------------------------------------------------------------------*/
  1711. /*
  1712. * Wireless Handler : set encryption key
  1713. */
  1714. static int wavelan_set_encode(struct net_device *dev,
  1715. struct iw_request_info *info,
  1716. union iwreq_data *wrqu,
  1717. char *extra)
  1718. {
  1719. unsigned long ioaddr = dev->base_addr;
  1720. net_local *lp = (net_local *) dev->priv; /* lp is not unused */
  1721. unsigned long flags;
  1722. psa_t psa;
  1723. int ret = 0;
  1724. /* Disable interrupts and save flags. */
  1725. spin_lock_irqsave(&lp->spinlock, flags);
  1726. /* Check if capable of encryption */
  1727. if (!mmc_encr(ioaddr)) {
  1728. ret = -EOPNOTSUPP;
  1729. }
  1730. /* Check the size of the key */
  1731. if((wrqu->encoding.length != 8) && (wrqu->encoding.length != 0)) {
  1732. ret = -EINVAL;
  1733. }
  1734. if(!ret) {
  1735. /* Basic checking... */
  1736. if (wrqu->encoding.length == 8) {
  1737. /* Copy the key in the driver */
  1738. memcpy(psa.psa_encryption_key, extra,
  1739. wrqu->encoding.length);
  1740. psa.psa_encryption_select = 1;
  1741. psa_write(ioaddr, lp->hacr,
  1742. (char *) &psa.psa_encryption_select -
  1743. (char *) &psa,
  1744. (unsigned char *) &psa.
  1745. psa_encryption_select, 8 + 1);
  1746. mmc_out(ioaddr, mmwoff(0, mmw_encr_enable),
  1747. MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE);
  1748. mmc_write(ioaddr, mmwoff(0, mmw_encr_key),
  1749. (unsigned char *) &psa.
  1750. psa_encryption_key, 8);
  1751. }
  1752. /* disable encryption */
  1753. if (wrqu->encoding.flags & IW_ENCODE_DISABLED) {
  1754. psa.psa_encryption_select = 0;
  1755. psa_write(ioaddr, lp->hacr,
  1756. (char *) &psa.psa_encryption_select -
  1757. (char *) &psa,
  1758. (unsigned char *) &psa.
  1759. psa_encryption_select, 1);
  1760. mmc_out(ioaddr, mmwoff(0, mmw_encr_enable), 0);
  1761. }
  1762. /* update the Wavelan checksum */
  1763. update_psa_checksum(dev, ioaddr, lp->hacr);
  1764. }
  1765. /* Enable interrupts and restore flags. */
  1766. spin_unlock_irqrestore(&lp->spinlock, flags);
  1767. return ret;
  1768. }
  1769. /*------------------------------------------------------------------*/
  1770. /*
  1771. * Wireless Handler : get encryption key
  1772. */
  1773. static int wavelan_get_encode(struct net_device *dev,
  1774. struct iw_request_info *info,
  1775. union iwreq_data *wrqu,
  1776. char *extra)
  1777. {
  1778. unsigned long ioaddr = dev->base_addr;
  1779. net_local *lp = (net_local *) dev->priv; /* lp is not unused */
  1780. psa_t psa;
  1781. unsigned long flags;
  1782. int ret = 0;
  1783. /* Disable interrupts and save flags. */
  1784. spin_lock_irqsave(&lp->spinlock, flags);
  1785. /* Check if encryption is available */
  1786. if (!mmc_encr(ioaddr)) {
  1787. ret = -EOPNOTSUPP;
  1788. } else {
  1789. /* Read the encryption key */
  1790. psa_read(ioaddr, lp->hacr,
  1791. (char *) &psa.psa_encryption_select -
  1792. (char *) &psa,
  1793. (unsigned char *) &psa.
  1794. psa_encryption_select, 1 + 8);
  1795. /* encryption is enabled ? */
  1796. if (psa.psa_encryption_select)
  1797. wrqu->encoding.flags = IW_ENCODE_ENABLED;
  1798. else
  1799. wrqu->encoding.flags = IW_ENCODE_DISABLED;
  1800. wrqu->encoding.flags |= mmc_encr(ioaddr);
  1801. /* Copy the key to the user buffer */
  1802. wrqu->encoding.length = 8;
  1803. memcpy(extra, psa.psa_encryption_key, wrqu->encoding.length);
  1804. }
  1805. /* Enable interrupts and restore flags. */
  1806. spin_unlock_irqrestore(&lp->spinlock, flags);
  1807. return ret;
  1808. }
  1809. /*------------------------------------------------------------------*/
  1810. /*
  1811. * Wireless Handler : get range info
  1812. */
  1813. static int wavelan_get_range(struct net_device *dev,
  1814. struct iw_request_info *info,
  1815. union iwreq_data *wrqu,
  1816. char *extra)
  1817. {
  1818. unsigned long ioaddr = dev->base_addr;
  1819. net_local *lp = (net_local *) dev->priv; /* lp is not unused */
  1820. struct iw_range *range = (struct iw_range *) extra;
  1821. unsigned long flags;
  1822. int ret = 0;
  1823. /* Set the length (very important for backward compatibility) */
  1824. wrqu->data.length = sizeof(struct iw_range);
  1825. /* Set all the info we don't care or don't know about to zero */
  1826. memset(range, 0, sizeof(struct iw_range));
  1827. /* Set the Wireless Extension versions */
  1828. range->we_version_compiled = WIRELESS_EXT;
  1829. range->we_version_source = 9;
  1830. /* Set information in the range struct. */
  1831. range->throughput = 1.6 * 1000 * 1000; /* don't argue on this ! */
  1832. range->min_nwid = 0x0000;
  1833. range->max_nwid = 0xFFFF;
  1834. range->sensitivity = 0x3F;
  1835. range->max_qual.qual = MMR_SGNL_QUAL;
  1836. range->max_qual.level = MMR_SIGNAL_LVL;
  1837. range->max_qual.noise = MMR_SILENCE_LVL;
  1838. range->avg_qual.qual = MMR_SGNL_QUAL; /* Always max */
  1839. /* Need to get better values for those two */
  1840. range->avg_qual.level = 30;
  1841. range->avg_qual.noise = 8;
  1842. range->num_bitrates = 1;
  1843. range->bitrate[0] = 2000000; /* 2 Mb/s */
  1844. /* Event capability (kernel + driver) */
  1845. range->event_capa[0] = (IW_EVENT_CAPA_MASK(0x8B02) |
  1846. IW_EVENT_CAPA_MASK(0x8B04));
  1847. range->event_capa[1] = IW_EVENT_CAPA_K_1;
  1848. /* Disable interrupts and save flags. */
  1849. spin_lock_irqsave(&lp->spinlock, flags);
  1850. /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
  1851. if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
  1852. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
  1853. range->num_channels = 10;
  1854. range->num_frequency = wv_frequency_list(ioaddr, range->freq,
  1855. IW_MAX_FREQUENCIES);
  1856. } else
  1857. range->num_channels = range->num_frequency = 0;
  1858. /* Encryption supported ? */
  1859. if (mmc_encr(ioaddr)) {
  1860. range->encoding_size[0] = 8; /* DES = 64 bits key */
  1861. range->num_encoding_sizes = 1;
  1862. range->max_encoding_tokens = 1; /* Only one key possible */
  1863. } else {
  1864. range->num_encoding_sizes = 0;
  1865. range->max_encoding_tokens = 0;
  1866. }
  1867. /* Enable interrupts and restore flags. */
  1868. spin_unlock_irqrestore(&lp->spinlock, flags);
  1869. return ret;
  1870. }
  1871. /*------------------------------------------------------------------*/
  1872. /*
  1873. * Wireless Private Handler : set quality threshold
  1874. */
  1875. static int wavelan_set_qthr(struct net_device *dev,
  1876. struct iw_request_info *info,
  1877. union iwreq_data *wrqu,
  1878. char *extra)
  1879. {
  1880. unsigned long ioaddr = dev->base_addr;
  1881. net_local *lp = (net_local *) dev->priv; /* lp is not unused */
  1882. psa_t psa;
  1883. unsigned long flags;
  1884. /* Disable interrupts and save flags. */
  1885. spin_lock_irqsave(&lp->spinlock, flags);
  1886. psa.psa_quality_thr = *(extra) & 0x0F;
  1887. psa_write(ioaddr, lp->hacr,
  1888. (char *) &psa.psa_quality_thr - (char *) &psa,
  1889. (unsigned char *) &psa.psa_quality_thr, 1);
  1890. /* update the Wavelan checksum */
  1891. update_psa_checksum(dev, ioaddr, lp->hacr);
  1892. mmc_out(ioaddr, mmwoff(0, mmw_quality_thr),
  1893. psa.psa_quality_thr);
  1894. /* Enable interrupts and restore flags. */
  1895. spin_unlock_irqrestore(&lp->spinlock, flags);
  1896. return 0;
  1897. }
  1898. /*------------------------------------------------------------------*/
  1899. /*
  1900. * Wireless Private Handler : get quality threshold
  1901. */
  1902. static int wavelan_get_qthr(struct net_device *dev,
  1903. struct iw_request_info *info,
  1904. union iwreq_data *wrqu,
  1905. char *extra)
  1906. {
  1907. unsigned long ioaddr = dev->base_addr;
  1908. net_local *lp = (net_local *) dev->priv; /* lp is not unused */
  1909. psa_t psa;
  1910. unsigned long flags;
  1911. /* Disable interrupts and save flags. */
  1912. spin_lock_irqsave(&lp->spinlock, flags);
  1913. psa_read(ioaddr, lp->hacr,
  1914. (char *) &psa.psa_quality_thr - (char *) &psa,
  1915. (unsigned char *) &psa.psa_quality_thr, 1);
  1916. *(extra) = psa.psa_quality_thr & 0x0F;
  1917. /* Enable interrupts and restore flags. */
  1918. spin_unlock_irqrestore(&lp->spinlock, flags);
  1919. return 0;
  1920. }
  1921. #ifdef HISTOGRAM
  1922. /*------------------------------------------------------------------*/
  1923. /*
  1924. * Wireless Private Handler : set histogram
  1925. */
  1926. static int wavelan_set_histo(struct net_device *dev,
  1927. struct iw_request_info *info,
  1928. union iwreq_data *wrqu,
  1929. char *extra)
  1930. {
  1931. net_local *lp = (net_local *) dev->priv; /* lp is not unused */
  1932. /* Check the number of intervals. */
  1933. if (wrqu->data.length > 16) {
  1934. return(-E2BIG);
  1935. }
  1936. /* Disable histo while we copy the addresses.
  1937. * As we don't disable interrupts, we need to do this */
  1938. lp->his_number = 0;
  1939. /* Are there ranges to copy? */
  1940. if (wrqu->data.length > 0) {
  1941. /* Copy interval ranges to the driver */
  1942. memcpy(lp->his_range, extra, wrqu->data.length);
  1943. {
  1944. int i;
  1945. printk(KERN_DEBUG "Histo :");
  1946. for(i = 0; i < wrqu->data.length; i++)
  1947. printk(" %d", lp->his_range[i]);
  1948. printk("\n");
  1949. }
  1950. /* Reset result structure. */
  1951. memset(lp->his_sum, 0x00, sizeof(long) * 16);
  1952. }
  1953. /* Now we can set the number of ranges */
  1954. lp->his_number = wrqu->data.length;
  1955. return(0);
  1956. }
  1957. /*------------------------------------------------------------------*/
  1958. /*
  1959. * Wireless Private Handler : get histogram
  1960. */
  1961. static int wavelan_get_histo(struct net_device *dev,
  1962. struct iw_request_info *info,
  1963. union iwreq_data *wrqu,
  1964. char *extra)
  1965. {
  1966. net_local *lp = (net_local *) dev->priv; /* lp is not unused */
  1967. /* Set the number of intervals. */
  1968. wrqu->data.length = lp->his_number;
  1969. /* Give back the distribution statistics */
  1970. if(lp->his_number > 0)
  1971. memcpy(extra, lp->his_sum, sizeof(long) * lp->his_number);
  1972. return(0);
  1973. }
  1974. #endif /* HISTOGRAM */
  1975. /*------------------------------------------------------------------*/
  1976. /*
  1977. * Structures to export the Wireless Handlers
  1978. */
  1979. static const iw_handler wavelan_handler[] =
  1980. {
  1981. NULL, /* SIOCSIWNAME */
  1982. wavelan_get_name, /* SIOCGIWNAME */
  1983. wavelan_set_nwid, /* SIOCSIWNWID */
  1984. wavelan_get_nwid, /* SIOCGIWNWID */
  1985. wavelan_set_freq, /* SIOCSIWFREQ */
  1986. wavelan_get_freq, /* SIOCGIWFREQ */
  1987. NULL, /* SIOCSIWMODE */
  1988. NULL, /* SIOCGIWMODE */
  1989. wavelan_set_sens, /* SIOCSIWSENS */
  1990. wavelan_get_sens, /* SIOCGIWSENS */
  1991. NULL, /* SIOCSIWRANGE */
  1992. wavelan_get_range, /* SIOCGIWRANGE */
  1993. NULL, /* SIOCSIWPRIV */
  1994. NULL, /* SIOCGIWPRIV */
  1995. NULL, /* SIOCSIWSTATS */
  1996. NULL, /* SIOCGIWSTATS */
  1997. iw_handler_set_spy, /* SIOCSIWSPY */
  1998. iw_handler_get_spy, /* SIOCGIWSPY */
  1999. iw_handler_set_thrspy, /* SIOCSIWTHRSPY */
  2000. iw_handler_get_thrspy, /* SIOCGIWTHRSPY */
  2001. NULL, /* SIOCSIWAP */
  2002. NULL, /* SIOCGIWAP */
  2003. NULL, /* -- hole -- */
  2004. NULL, /* SIOCGIWAPLIST */
  2005. NULL, /* -- hole -- */
  2006. NULL, /* -- hole -- */
  2007. NULL, /* SIOCSIWESSID */
  2008. NULL, /* SIOCGIWESSID */
  2009. NULL, /* SIOCSIWNICKN */
  2010. NULL, /* SIOCGIWNICKN */
  2011. NULL, /* -- hole -- */
  2012. NULL, /* -- hole -- */
  2013. NULL, /* SIOCSIWRATE */
  2014. NULL, /* SIOCGIWRATE */
  2015. NULL, /* SIOCSIWRTS */
  2016. NULL, /* SIOCGIWRTS */
  2017. NULL, /* SIOCSIWFRAG */
  2018. NULL, /* SIOCGIWFRAG */
  2019. NULL, /* SIOCSIWTXPOW */
  2020. NULL, /* SIOCGIWTXPOW */
  2021. NULL, /* SIOCSIWRETRY */
  2022. NULL, /* SIOCGIWRETRY */
  2023. /* Bummer ! Why those are only at the end ??? */
  2024. wavelan_set_encode, /* SIOCSIWENCODE */
  2025. wavelan_get_encode, /* SIOCGIWENCODE */
  2026. };
  2027. static const iw_handler wavelan_private_handler[] =
  2028. {
  2029. wavelan_set_qthr, /* SIOCIWFIRSTPRIV */
  2030. wavelan_get_qthr, /* SIOCIWFIRSTPRIV + 1 */
  2031. #ifdef HISTOGRAM
  2032. wavelan_set_histo, /* SIOCIWFIRSTPRIV + 2 */
  2033. wavelan_get_histo, /* SIOCIWFIRSTPRIV + 3 */
  2034. #endif /* HISTOGRAM */
  2035. };
  2036. static const struct iw_priv_args wavelan_private_args[] = {
  2037. /*{ cmd, set_args, get_args, name } */
  2038. { SIOCSIPQTHR, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, 0, "setqualthr" },
  2039. { SIOCGIPQTHR, 0, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1, "getqualthr" },
  2040. { SIOCSIPHISTO, IW_PRIV_TYPE_BYTE | 16, 0, "sethisto" },
  2041. { SIOCGIPHISTO, 0, IW_PRIV_TYPE_INT | 16, "gethisto" },
  2042. };
  2043. static const struct iw_handler_def wavelan_handler_def =
  2044. {
  2045. .num_standard = ARRAY_SIZE(wavelan_handler),
  2046. .num_private = ARRAY_SIZE(wavelan_private_handler),
  2047. .num_private_args = ARRAY_SIZE(wavelan_private_args),
  2048. .standard = wavelan_handler,
  2049. .private = wavelan_private_handler,
  2050. .private_args = wavelan_private_args,
  2051. .get_wireless_stats = wavelan_get_wireless_stats,
  2052. };
  2053. /*------------------------------------------------------------------*/
  2054. /*
  2055. * Get wireless statistics.
  2056. * Called by /proc/net/wireless
  2057. */
  2058. static iw_stats *wavelan_get_wireless_stats(struct net_device * dev)
  2059. {
  2060. unsigned long ioaddr = dev->base_addr;
  2061. net_local *lp = (net_local *) dev->priv;
  2062. mmr_t m;
  2063. iw_stats *wstats;
  2064. unsigned long flags;
  2065. #ifdef DEBUG_IOCTL_TRACE
  2066. printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()\n",
  2067. dev->name);
  2068. #endif
  2069. /* Check */
  2070. if (lp == (net_local *) NULL)
  2071. return (iw_stats *) NULL;
  2072. /* Disable interrupts and save flags. */
  2073. spin_lock_irqsave(&lp->spinlock, flags);
  2074. wstats = &lp->wstats;
  2075. /* Get data from the mmc. */
  2076. mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
  2077. mmc_read(ioaddr, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1);
  2078. mmc_read(ioaddr, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l,
  2079. 2);
  2080. mmc_read(ioaddr, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set,
  2081. 4);
  2082. mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
  2083. /* Copy data to wireless stuff. */
  2084. wstats->status = m.mmr_dce_status & MMR_DCE_STATUS;
  2085. wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL;
  2086. wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL;
  2087. wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL;
  2088. wstats->qual.updated = (((m. mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7)
  2089. | ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6)
  2090. | ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5));
  2091. wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
  2092. wstats->discard.code = 0L;
  2093. wstats->discard.misc = 0L;
  2094. /* Enable interrupts and restore flags. */
  2095. spin_unlock_irqrestore(&lp->spinlock, flags);
  2096. #ifdef DEBUG_IOCTL_TRACE
  2097. printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()\n",
  2098. dev->name);
  2099. #endif
  2100. return &lp->wstats;
  2101. }
  2102. /************************* PACKET RECEPTION *************************/
  2103. /*
  2104. * This part deals with receiving the packets.
  2105. * The interrupt handler gets an interrupt when a packet has been
  2106. * successfully received and calls this part.
  2107. */
  2108. /*------------------------------------------------------------------*/
  2109. /*
  2110. * This routine does the actual copying of data (including the Ethernet
  2111. * header structure) from the WaveLAN card to an sk_buff chain that
  2112. * will be passed up to the network interface layer. NOTE: we
  2113. * currently don't handle trailer protocols (neither does the rest of
  2114. * the network interface), so if that is needed, it will (at least in
  2115. * part) be added here. The contents of the receive ring buffer are
  2116. * copied to a message chain that is then passed to the kernel.
  2117. *
  2118. * Note: if any errors occur, the packet is "dropped on the floor".
  2119. * (called by wv_packet_rcv())
  2120. */
  2121. static void
  2122. wv_packet_read(struct net_device * dev, u16 buf_off, int sksize)
  2123. {
  2124. net_local *lp = (net_local *) dev->priv;
  2125. unsigned long ioaddr = dev->base_addr;
  2126. struct sk_buff *skb;
  2127. #ifdef DEBUG_RX_TRACE
  2128. printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)\n",
  2129. dev->name, buf_off, sksize);
  2130. #endif
  2131. /* Allocate buffer for the data */
  2132. if ((skb = dev_alloc_skb(sksize)) == (struct sk_buff *) NULL) {
  2133. #ifdef DEBUG_RX_ERROR
  2134. printk(KERN_INFO
  2135. "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC).\n",
  2136. dev->name, sksize);
  2137. #endif
  2138. lp->stats.rx_dropped++;
  2139. return;
  2140. }
  2141. /* Copy the packet to the buffer. */
  2142. obram_read(ioaddr, buf_off, skb_put(skb, sksize), sksize);
  2143. skb->protocol = eth_type_trans(skb, dev);
  2144. #ifdef DEBUG_RX_INFO
  2145. wv_packet_info(skb_mac_header(skb), sksize, dev->name,
  2146. "wv_packet_read");
  2147. #endif /* DEBUG_RX_INFO */
  2148. /* Statistics-gathering and associated stuff.
  2149. * It seem a bit messy with all the define, but it's really
  2150. * simple... */
  2151. if (
  2152. #ifdef IW_WIRELESS_SPY /* defined in iw_handler.h */
  2153. (lp->spy_data.spy_number > 0) ||
  2154. #endif /* IW_WIRELESS_SPY */
  2155. #ifdef HISTOGRAM
  2156. (lp->his_number > 0) ||
  2157. #endif /* HISTOGRAM */
  2158. 0) {
  2159. u8 stats[3]; /* signal level, noise level, signal quality */
  2160. /* Read signal level, silence level and signal quality bytes */
  2161. /* Note: in the PCMCIA hardware, these are part of the frame.
  2162. * It seems that for the ISA hardware, it's nowhere to be
  2163. * found in the frame, so I'm obliged to do this (it has a
  2164. * side effect on /proc/net/wireless).
  2165. * Any ideas?
  2166. */
  2167. mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
  2168. mmc_read(ioaddr, mmroff(0, mmr_signal_lvl), stats, 3);
  2169. mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
  2170. #ifdef DEBUG_RX_INFO
  2171. printk(KERN_DEBUG
  2172. "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n",
  2173. dev->name, stats[0] & 0x3F, stats[1] & 0x3F,
  2174. stats[2] & 0x0F);
  2175. #endif
  2176. /* Spying stuff */
  2177. #ifdef IW_WIRELESS_SPY
  2178. wl_spy_gather(dev, skb_mac_header(skb) + WAVELAN_ADDR_SIZE,
  2179. stats);
  2180. #endif /* IW_WIRELESS_SPY */
  2181. #ifdef HISTOGRAM
  2182. wl_his_gather(dev, stats);
  2183. #endif /* HISTOGRAM */
  2184. }
  2185. /*
  2186. * Hand the packet to the network module.
  2187. */
  2188. netif_rx(skb);
  2189. /* Keep statistics up to date */
  2190. dev->last_rx = jiffies;
  2191. lp->stats.rx_packets++;
  2192. lp->stats.rx_bytes += sksize;
  2193. #ifdef DEBUG_RX_TRACE
  2194. printk(KERN_DEBUG "%s: <-wv_packet_read()\n", dev->name);
  2195. #endif
  2196. }
  2197. /*------------------------------------------------------------------*/
  2198. /*
  2199. * Transfer as many packets as we can
  2200. * from the device RAM.
  2201. * (called in wavelan_interrupt()).
  2202. * Note : the spinlock is already grabbed for us.
  2203. */
  2204. static void wv_receive(struct net_device * dev)
  2205. {
  2206. unsigned long ioaddr = dev->base_addr;
  2207. net_local *lp = (net_local *) dev->priv;
  2208. fd_t fd;
  2209. rbd_t rbd;
  2210. int nreaped = 0;
  2211. #ifdef DEBUG_RX_TRACE
  2212. printk(KERN_DEBUG "%s: ->wv_receive()\n", dev->name);
  2213. #endif
  2214. /* Loop on each received packet. */
  2215. for (;;) {
  2216. obram_read(ioaddr, lp->rx_head, (unsigned char *) &fd,
  2217. sizeof(fd));
  2218. /* Note about the status :
  2219. * It start up to be 0 (the value we set). Then, when the RU
  2220. * grab the buffer to prepare for reception, it sets the
  2221. * FD_STATUS_B flag. When the RU has finished receiving the
  2222. * frame, it clears FD_STATUS_B, set FD_STATUS_C to indicate
  2223. * completion and set the other flags to indicate the eventual
  2224. * errors. FD_STATUS_OK indicates that the reception was OK.
  2225. */
  2226. /* If the current frame is not complete, we have reached the end. */
  2227. if ((fd.fd_status & FD_STATUS_C) != FD_STATUS_C)
  2228. break; /* This is how we exit the loop. */
  2229. nreaped++;
  2230. /* Check whether frame was correctly received. */
  2231. if ((fd.fd_status & FD_STATUS_OK) == FD_STATUS_OK) {
  2232. /* Does the frame contain a pointer to the data? Let's check. */
  2233. if (fd.fd_rbd_offset != I82586NULL) {
  2234. /* Read the receive buffer descriptor */
  2235. obram_read(ioaddr, fd.fd_rbd_offset,
  2236. (unsigned char *) &rbd,
  2237. sizeof(rbd));
  2238. #ifdef DEBUG_RX_ERROR
  2239. if ((rbd.rbd_status & RBD_STATUS_EOF) !=
  2240. RBD_STATUS_EOF) printk(KERN_INFO
  2241. "%s: wv_receive(): missing EOF flag.\n",
  2242. dev->name);
  2243. if ((rbd.rbd_status & RBD_STATUS_F) !=
  2244. RBD_STATUS_F) printk(KERN_INFO
  2245. "%s: wv_receive(): missing F flag.\n",
  2246. dev->name);
  2247. #endif /* DEBUG_RX_ERROR */
  2248. /* Read the packet and transmit to Linux */
  2249. wv_packet_read(dev, rbd.rbd_bufl,
  2250. rbd.
  2251. rbd_status &
  2252. RBD_STATUS_ACNT);
  2253. }
  2254. #ifdef DEBUG_RX_ERROR
  2255. else /* if frame has no data */
  2256. printk(KERN_INFO
  2257. "%s: wv_receive(): frame has no data.\n",
  2258. dev->name);
  2259. #endif
  2260. } else { /* If reception was no successful */
  2261. lp->stats.rx_errors++;
  2262. #ifdef DEBUG_RX_INFO
  2263. printk(KERN_DEBUG
  2264. "%s: wv_receive(): frame not received successfully (%X).\n",
  2265. dev->name, fd.fd_status);
  2266. #endif
  2267. #ifdef DEBUG_RX_ERROR
  2268. if ((fd.fd_status & FD_STATUS_S6) != 0)
  2269. printk(KERN_INFO
  2270. "%s: wv_receive(): no EOF flag.\n",
  2271. dev->name);
  2272. #endif
  2273. if ((fd.fd_status & FD_STATUS_S7) != 0) {
  2274. lp->stats.rx_length_errors++;
  2275. #ifdef DEBUG_RX_FAIL
  2276. printk(KERN_DEBUG
  2277. "%s: wv_receive(): frame too short.\n",
  2278. dev->name);
  2279. #endif
  2280. }
  2281. if ((fd.fd_status & FD_STATUS_S8) != 0) {
  2282. lp->stats.rx_over_errors++;
  2283. #ifdef DEBUG_RX_FAIL
  2284. printk(KERN_DEBUG
  2285. "%s: wv_receive(): rx DMA overrun.\n",
  2286. dev->name);
  2287. #endif
  2288. }
  2289. if ((fd.fd_status & FD_STATUS_S9) != 0) {
  2290. lp->stats.rx_fifo_errors++;
  2291. #ifdef DEBUG_RX_FAIL
  2292. printk(KERN_DEBUG
  2293. "%s: wv_receive(): ran out of resources.\n",
  2294. dev->name);
  2295. #endif
  2296. }
  2297. if ((fd.fd_status & FD_STATUS_S10) != 0) {
  2298. lp->stats.rx_frame_errors++;
  2299. #ifdef DEBUG_RX_FAIL
  2300. printk(KERN_DEBUG
  2301. "%s: wv_receive(): alignment error.\n",
  2302. dev->name);
  2303. #endif
  2304. }
  2305. if ((fd.fd_status & FD_STATUS_S11) != 0) {
  2306. lp->stats.rx_crc_errors++;
  2307. #ifdef DEBUG_RX_FAIL
  2308. printk(KERN_DEBUG
  2309. "%s: wv_receive(): CRC error.\n",
  2310. dev->name);
  2311. #endif
  2312. }
  2313. }
  2314. fd.fd_status = 0;
  2315. obram_write(ioaddr, fdoff(lp->rx_head, fd_status),
  2316. (unsigned char *) &fd.fd_status,
  2317. sizeof(fd.fd_status));
  2318. fd.fd_command = FD_COMMAND_EL;
  2319. obram_write(ioaddr, fdoff(lp->rx_head, fd_command),
  2320. (unsigned char *) &fd.fd_command,
  2321. sizeof(fd.fd_command));
  2322. fd.fd_command = 0;
  2323. obram_write(ioaddr, fdoff(lp->rx_last, fd_command),
  2324. (unsigned char *) &fd.fd_command,
  2325. sizeof(fd.fd_command));
  2326. lp->rx_last = lp->rx_head;
  2327. lp->rx_head = fd.fd_link_offset;
  2328. } /* for(;;) -> loop on all frames */
  2329. #ifdef DEBUG_RX_INFO
  2330. if (nreaped > 1)
  2331. printk(KERN_DEBUG "%s: wv_receive(): reaped %d\n",
  2332. dev->name, nreaped);
  2333. #endif
  2334. #ifdef DEBUG_RX_TRACE
  2335. printk(KERN_DEBUG "%s: <-wv_receive()\n", dev->name);
  2336. #endif
  2337. }
  2338. /*********************** PACKET TRANSMISSION ***********************/
  2339. /*
  2340. * This part deals with sending packets through the WaveLAN.
  2341. *
  2342. */
  2343. /*------------------------------------------------------------------*/
  2344. /*
  2345. * This routine fills in the appropriate registers and memory
  2346. * locations on the WaveLAN card and starts the card off on
  2347. * the transmit.
  2348. *
  2349. * The principle:
  2350. * Each block contains a transmit command, a NOP command,
  2351. * a transmit block descriptor and a buffer.
  2352. * The CU read the transmit block which point to the tbd,
  2353. * read the tbd and the content of the buffer.
  2354. * When it has finish with it, it goes to the next command
  2355. * which in our case is the NOP. The NOP points on itself,
  2356. * so the CU stop here.
  2357. * When we add the next block, we modify the previous nop
  2358. * to make it point on the new tx command.
  2359. * Simple, isn't it ?
  2360. *
  2361. * (called in wavelan_packet_xmit())
  2362. */
  2363. static int wv_packet_write(struct net_device * dev, void *buf, short length)
  2364. {
  2365. net_local *lp = (net_local *) dev->priv;
  2366. unsigned long ioaddr = dev->base_addr;
  2367. unsigned short txblock;
  2368. unsigned short txpred;
  2369. unsigned short tx_addr;
  2370. unsigned short nop_addr;
  2371. unsigned short tbd_addr;
  2372. unsigned short buf_addr;
  2373. ac_tx_t tx;
  2374. ac_nop_t nop;
  2375. tbd_t tbd;
  2376. int clen = length;
  2377. unsigned long flags;
  2378. #ifdef DEBUG_TX_TRACE
  2379. printk(KERN_DEBUG "%s: ->wv_packet_write(%d)\n", dev->name,
  2380. length);
  2381. #endif
  2382. spin_lock_irqsave(&lp->spinlock, flags);
  2383. /* Check nothing bad has happened */
  2384. if (lp->tx_n_in_use == (NTXBLOCKS - 1)) {
  2385. #ifdef DEBUG_TX_ERROR
  2386. printk(KERN_INFO "%s: wv_packet_write(): Tx queue full.\n",
  2387. dev->name);
  2388. #endif
  2389. spin_unlock_irqrestore(&lp->spinlock, flags);
  2390. return 1;
  2391. }
  2392. /* Calculate addresses of next block and previous block. */
  2393. txblock = lp->tx_first_free;
  2394. txpred = txblock - TXBLOCKZ;
  2395. if (txpred < OFFSET_CU)
  2396. txpred += NTXBLOCKS * TXBLOCKZ;
  2397. lp->tx_first_free += TXBLOCKZ;
  2398. if (lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
  2399. lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ;
  2400. lp->tx_n_in_use++;
  2401. /* Calculate addresses of the different parts of the block. */
  2402. tx_addr = txblock;
  2403. nop_addr = tx_addr + sizeof(tx);
  2404. tbd_addr = nop_addr + sizeof(nop);
  2405. buf_addr = tbd_addr + sizeof(tbd);
  2406. /*
  2407. * Transmit command
  2408. */
  2409. tx.tx_h.ac_status = 0;
  2410. obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status),
  2411. (unsigned char *) &tx.tx_h.ac_status,
  2412. sizeof(tx.tx_h.ac_status));
  2413. /*
  2414. * NOP command
  2415. */
  2416. nop.nop_h.ac_status = 0;
  2417. obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
  2418. (unsigned char *) &nop.nop_h.ac_status,
  2419. sizeof(nop.nop_h.ac_status));
  2420. nop.nop_h.ac_link = nop_addr;
  2421. obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
  2422. (unsigned char *) &nop.nop_h.ac_link,
  2423. sizeof(nop.nop_h.ac_link));
  2424. /*
  2425. * Transmit buffer descriptor
  2426. */
  2427. tbd.tbd_status = TBD_STATUS_EOF | (TBD_STATUS_ACNT & clen);
  2428. tbd.tbd_next_bd_offset = I82586NULL;
  2429. tbd.tbd_bufl = buf_addr;
  2430. tbd.tbd_bufh = 0;
  2431. obram_write(ioaddr, tbd_addr, (unsigned char *) &tbd, sizeof(tbd));
  2432. /*
  2433. * Data
  2434. */
  2435. obram_write(ioaddr, buf_addr, buf, length);
  2436. /*
  2437. * Overwrite the predecessor NOP link
  2438. * so that it points to this txblock.
  2439. */
  2440. nop_addr = txpred + sizeof(tx);
  2441. nop.nop_h.ac_status = 0;
  2442. obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
  2443. (unsigned char *) &nop.nop_h.ac_status,
  2444. sizeof(nop.nop_h.ac_status));
  2445. nop.nop_h.ac_link = txblock;
  2446. obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
  2447. (unsigned char *) &nop.nop_h.ac_link,
  2448. sizeof(nop.nop_h.ac_link));
  2449. /* Make sure the watchdog will keep quiet for a while */
  2450. dev->trans_start = jiffies;
  2451. /* Keep stats up to date. */
  2452. lp->stats.tx_bytes += length;
  2453. if (lp->tx_first_in_use == I82586NULL)
  2454. lp->tx_first_in_use = txblock;
  2455. if (lp->tx_n_in_use < NTXBLOCKS - 1)
  2456. netif_wake_queue(dev);
  2457. spin_unlock_irqrestore(&lp->spinlock, flags);
  2458. #ifdef DEBUG_TX_INFO
  2459. wv_packet_info((u8 *) buf, length, dev->name,
  2460. "wv_packet_write");
  2461. #endif /* DEBUG_TX_INFO */
  2462. #ifdef DEBUG_TX_TRACE
  2463. printk(KERN_DEBUG "%s: <-wv_packet_write()\n", dev->name);
  2464. #endif
  2465. return 0;
  2466. }
  2467. /*------------------------------------------------------------------*/
  2468. /*
  2469. * This routine is called when we want to send a packet (NET3 callback)
  2470. * In this routine, we check if the harware is ready to accept
  2471. * the packet. We also prevent reentrance. Then we call the function
  2472. * to send the packet.
  2473. */
  2474. static int wavelan_packet_xmit(struct sk_buff *skb, struct net_device * dev)
  2475. {
  2476. net_local *lp = (net_local *) dev->priv;
  2477. unsigned long flags;
  2478. char data[ETH_ZLEN];
  2479. #ifdef DEBUG_TX_TRACE
  2480. printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)\n", dev->name,
  2481. (unsigned) skb);
  2482. #endif
  2483. /*
  2484. * Block a timer-based transmit from overlapping.
  2485. * In other words, prevent reentering this routine.
  2486. */
  2487. netif_stop_queue(dev);
  2488. /* If somebody has asked to reconfigure the controller,
  2489. * we can do it now.
  2490. */
  2491. if (lp->reconfig_82586) {
  2492. spin_lock_irqsave(&lp->spinlock, flags);
  2493. wv_82586_config(dev);
  2494. spin_unlock_irqrestore(&lp->spinlock, flags);
  2495. /* Check that we can continue */
  2496. if (lp->tx_n_in_use == (NTXBLOCKS - 1))
  2497. return 1;
  2498. }
  2499. #ifdef DEBUG_TX_ERROR
  2500. if (skb->next)
  2501. printk(KERN_INFO "skb has next\n");
  2502. #endif
  2503. /* Do we need some padding? */
  2504. /* Note : on wireless the propagation time is in the order of 1us,
  2505. * and we don't have the Ethernet specific requirement of beeing
  2506. * able to detect collisions, therefore in theory we don't really
  2507. * need to pad. Jean II */
  2508. if (skb->len < ETH_ZLEN) {
  2509. memset(data, 0, ETH_ZLEN);
  2510. skb_copy_from_linear_data(skb, data, skb->len);
  2511. /* Write packet on the card */
  2512. if(wv_packet_write(dev, data, ETH_ZLEN))
  2513. return 1; /* We failed */
  2514. }
  2515. else if(wv_packet_write(dev, skb->data, skb->len))
  2516. return 1; /* We failed */
  2517. dev_kfree_skb(skb);
  2518. #ifdef DEBUG_TX_TRACE
  2519. printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
  2520. #endif
  2521. return 0;
  2522. }
  2523. /*********************** HARDWARE CONFIGURATION ***********************/
  2524. /*
  2525. * This part does the real job of starting and configuring the hardware.
  2526. */
  2527. /*--------------------------------------------------------------------*/
  2528. /*
  2529. * Routine to initialize the Modem Management Controller.
  2530. * (called by wv_hw_reset())
  2531. */
  2532. static int wv_mmc_init(struct net_device * dev)
  2533. {
  2534. unsigned long ioaddr = dev->base_addr;
  2535. net_local *lp = (net_local *) dev->priv;
  2536. psa_t psa;
  2537. mmw_t m;
  2538. int configured;
  2539. #ifdef DEBUG_CONFIG_TRACE
  2540. printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name);
  2541. #endif
  2542. /* Read the parameter storage area. */
  2543. psa_read(ioaddr, lp->hacr, 0, (unsigned char *) &psa, sizeof(psa));
  2544. #ifdef USE_PSA_CONFIG
  2545. configured = psa.psa_conf_status & 1;
  2546. #else
  2547. configured = 0;
  2548. #endif
  2549. /* Is the PSA is not configured */
  2550. if (!configured) {
  2551. /* User will be able to configure NWID later (with iwconfig). */
  2552. psa.psa_nwid[0] = 0;
  2553. psa.psa_nwid[1] = 0;
  2554. /* no NWID checking since NWID is not set */
  2555. psa.psa_nwid_select = 0;
  2556. /* Disable encryption */
  2557. psa.psa_encryption_select = 0;
  2558. /* Set to standard values:
  2559. * 0x04 for AT,
  2560. * 0x01 for MCA,
  2561. * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
  2562. */
  2563. if (psa.psa_comp_number & 1)
  2564. psa.psa_thr_pre_set = 0x01;
  2565. else
  2566. psa.psa_thr_pre_set = 0x04;
  2567. psa.psa_quality_thr = 0x03;
  2568. /* It is configured */
  2569. psa.psa_conf_status |= 1;
  2570. #ifdef USE_PSA_CONFIG
  2571. /* Write the psa. */
  2572. psa_write(ioaddr, lp->hacr,
  2573. (char *) psa.psa_nwid - (char *) &psa,
  2574. (unsigned char *) psa.psa_nwid, 4);
  2575. psa_write(ioaddr, lp->hacr,
  2576. (char *) &psa.psa_thr_pre_set - (char *) &psa,
  2577. (unsigned char *) &psa.psa_thr_pre_set, 1);
  2578. psa_write(ioaddr, lp->hacr,
  2579. (char *) &psa.psa_quality_thr - (char *) &psa,
  2580. (unsigned char *) &psa.psa_quality_thr, 1);
  2581. psa_write(ioaddr, lp->hacr,
  2582. (char *) &psa.psa_conf_status - (char *) &psa,
  2583. (unsigned char *) &psa.psa_conf_status, 1);
  2584. /* update the Wavelan checksum */
  2585. update_psa_checksum(dev, ioaddr, lp->hacr);
  2586. #endif
  2587. }
  2588. /* Zero the mmc structure. */
  2589. memset(&m, 0x00, sizeof(m));
  2590. /* Copy PSA info to the mmc. */
  2591. m.mmw_netw_id_l = psa.psa_nwid[1];
  2592. m.mmw_netw_id_h = psa.psa_nwid[0];
  2593. if (psa.psa_nwid_select & 1)
  2594. m.mmw_loopt_sel = 0x00;
  2595. else
  2596. m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
  2597. memcpy(&m.mmw_encr_key, &psa.psa_encryption_key,
  2598. sizeof(m.mmw_encr_key));
  2599. if (psa.psa_encryption_select)
  2600. m.mmw_encr_enable =
  2601. MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
  2602. else
  2603. m.mmw_encr_enable = 0;
  2604. m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
  2605. m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
  2606. /*
  2607. * Set default modem control parameters.
  2608. * See NCR document 407-0024326 Rev. A.
  2609. */
  2610. m.mmw_jabber_enable = 0x01;
  2611. m.mmw_freeze = 0;
  2612. m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
  2613. m.mmw_ifs = 0x20;
  2614. m.mmw_mod_delay = 0x04;
  2615. m.mmw_jam_time = 0x38;
  2616. m.mmw_des_io_invert = 0;
  2617. m.mmw_decay_prm = 0;
  2618. m.mmw_decay_updat_prm = 0;
  2619. /* Write all info to MMC. */
  2620. mmc_write(ioaddr, 0, (u8 *) & m, sizeof(m));
  2621. /* The following code starts the modem of the 2.00 frequency
  2622. * selectable cards at power on. It's not strictly needed for the
  2623. * following boots.
  2624. * The original patch was by Joe Finney for the PCMCIA driver, but
  2625. * I've cleaned it up a bit and added documentation.
  2626. * Thanks to Loeke Brederveld from Lucent for the info.
  2627. */
  2628. /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
  2629. * Does it work for everybody, especially old cards? */
  2630. /* Note: WFREQSEL verifies that it is able to read a sensible
  2631. * frequency from EEPROM (address 0x00) and that MMR_FEE_STATUS_ID
  2632. * is 0xA (Xilinx version) or 0xB (Ariadne version).
  2633. * My test is more crude but does work. */
  2634. if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
  2635. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
  2636. /* We must download the frequency parameters to the
  2637. * synthesizers (from the EEPROM - area 1)
  2638. * Note: as the EEPROM is automatically decremented, we set the end
  2639. * if the area... */
  2640. m.mmw_fee_addr = 0x0F;
  2641. m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
  2642. mmc_write(ioaddr, (char *) &m.mmw_fee_ctrl - (char *) &m,
  2643. (unsigned char *) &m.mmw_fee_ctrl, 2);
  2644. /* Wait until the download is finished. */
  2645. fee_wait(ioaddr, 100, 100);
  2646. #ifdef DEBUG_CONFIG_INFO
  2647. /* The frequency was in the last word downloaded. */
  2648. mmc_read(ioaddr, (char *) &m.mmw_fee_data_l - (char *) &m,
  2649. (unsigned char *) &m.mmw_fee_data_l, 2);
  2650. /* Print some info for the user. */
  2651. printk(KERN_DEBUG
  2652. "%s: WaveLAN 2.00 recognised (frequency select). Current frequency = %ld\n",
  2653. dev->name,
  2654. ((m.
  2655. mmw_fee_data_h << 4) | (m.mmw_fee_data_l >> 4)) *
  2656. 5 / 2 + 24000L);
  2657. #endif
  2658. /* We must now download the power adjust value (gain) to
  2659. * the synthesizers (from the EEPROM - area 7 - DAC). */
  2660. m.mmw_fee_addr = 0x61;
  2661. m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
  2662. mmc_write(ioaddr, (char *) &m.mmw_fee_ctrl - (char *) &m,
  2663. (unsigned char *) &m.mmw_fee_ctrl, 2);
  2664. /* Wait until the download is finished. */
  2665. }
  2666. /* if 2.00 card */
  2667. #ifdef DEBUG_CONFIG_TRACE
  2668. printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name);
  2669. #endif
  2670. return 0;
  2671. }
  2672. /*------------------------------------------------------------------*/
  2673. /*
  2674. * Construct the fd and rbd structures.
  2675. * Start the receive unit.
  2676. * (called by wv_hw_reset())
  2677. */
  2678. static int wv_ru_start(struct net_device * dev)
  2679. {
  2680. net_local *lp = (net_local *) dev->priv;
  2681. unsigned long ioaddr = dev->base_addr;
  2682. u16 scb_cs;
  2683. fd_t fd;
  2684. rbd_t rbd;
  2685. u16 rx;
  2686. u16 rx_next;
  2687. int i;
  2688. #ifdef DEBUG_CONFIG_TRACE
  2689. printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name);
  2690. #endif
  2691. obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
  2692. (unsigned char *) &scb_cs, sizeof(scb_cs));
  2693. if ((scb_cs & SCB_ST_RUS) == SCB_ST_RUS_RDY)
  2694. return 0;
  2695. lp->rx_head = OFFSET_RU;
  2696. for (i = 0, rx = lp->rx_head; i < NRXBLOCKS; i++, rx = rx_next) {
  2697. rx_next =
  2698. (i == NRXBLOCKS - 1) ? lp->rx_head : rx + RXBLOCKZ;
  2699. fd.fd_status = 0;
  2700. fd.fd_command = (i == NRXBLOCKS - 1) ? FD_COMMAND_EL : 0;
  2701. fd.fd_link_offset = rx_next;
  2702. fd.fd_rbd_offset = rx + sizeof(fd);
  2703. obram_write(ioaddr, rx, (unsigned char *) &fd, sizeof(fd));
  2704. rbd.rbd_status = 0;
  2705. rbd.rbd_next_rbd_offset = I82586NULL;
  2706. rbd.rbd_bufl = rx + sizeof(fd) + sizeof(rbd);
  2707. rbd.rbd_bufh = 0;
  2708. rbd.rbd_el_size = RBD_EL | (RBD_SIZE & MAXDATAZ);
  2709. obram_write(ioaddr, rx + sizeof(fd),
  2710. (unsigned char *) &rbd, sizeof(rbd));
  2711. lp->rx_last = rx;
  2712. }
  2713. obram_write(ioaddr, scboff(OFFSET_SCB, scb_rfa_offset),
  2714. (unsigned char *) &lp->rx_head, sizeof(lp->rx_head));
  2715. scb_cs = SCB_CMD_RUC_GO;
  2716. obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
  2717. (unsigned char *) &scb_cs, sizeof(scb_cs));
  2718. set_chan_attn(ioaddr, lp->hacr);
  2719. for (i = 1000; i > 0; i--) {
  2720. obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
  2721. (unsigned char *) &scb_cs, sizeof(scb_cs));
  2722. if (scb_cs == 0)
  2723. break;
  2724. udelay(10);
  2725. }
  2726. if (i <= 0) {
  2727. #ifdef DEBUG_CONFIG_ERROR
  2728. printk(KERN_INFO
  2729. "%s: wavelan_ru_start(): board not accepting command.\n",
  2730. dev->name);
  2731. #endif
  2732. return -1;
  2733. }
  2734. #ifdef DEBUG_CONFIG_TRACE
  2735. printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name);
  2736. #endif
  2737. return 0;
  2738. }
  2739. /*------------------------------------------------------------------*/
  2740. /*
  2741. * Initialise the transmit blocks.
  2742. * Start the command unit executing the NOP
  2743. * self-loop of the first transmit block.
  2744. *
  2745. * Here we create the list of send buffers used to transmit packets
  2746. * between the PC and the command unit. For each buffer, we create a
  2747. * buffer descriptor (pointing on the buffer), a transmit command
  2748. * (pointing to the buffer descriptor) and a NOP command.
  2749. * The transmit command is linked to the NOP, and the NOP to itself.
  2750. * When we will have finished executing the transmit command, we will
  2751. * then loop on the NOP. By releasing the NOP link to a new command,
  2752. * we may send another buffer.
  2753. *
  2754. * (called by wv_hw_reset())
  2755. */
  2756. static int wv_cu_start(struct net_device * dev)
  2757. {
  2758. net_local *lp = (net_local *) dev->priv;
  2759. unsigned long ioaddr = dev->base_addr;
  2760. int i;
  2761. u16 txblock;
  2762. u16 first_nop;
  2763. u16 scb_cs;
  2764. #ifdef DEBUG_CONFIG_TRACE
  2765. printk(KERN_DEBUG "%s: ->wv_cu_start()\n", dev->name);
  2766. #endif
  2767. lp->tx_first_free = OFFSET_CU;
  2768. lp->tx_first_in_use = I82586NULL;
  2769. for (i = 0, txblock = OFFSET_CU;
  2770. i < NTXBLOCKS; i++, txblock += TXBLOCKZ) {
  2771. ac_tx_t tx;
  2772. ac_nop_t nop;
  2773. tbd_t tbd;
  2774. unsigned short tx_addr;
  2775. unsigned short nop_addr;
  2776. unsigned short tbd_addr;
  2777. unsigned short buf_addr;
  2778. tx_addr = txblock;
  2779. nop_addr = tx_addr + sizeof(tx);
  2780. tbd_addr = nop_addr + sizeof(nop);
  2781. buf_addr = tbd_addr + sizeof(tbd);
  2782. tx.tx_h.ac_status = 0;
  2783. tx.tx_h.ac_command = acmd_transmit | AC_CFLD_I;
  2784. tx.tx_h.ac_link = nop_addr;
  2785. tx.tx_tbd_offset = tbd_addr;
  2786. obram_write(ioaddr, tx_addr, (unsigned char *) &tx,
  2787. sizeof(tx));
  2788. nop.nop_h.ac_status = 0;
  2789. nop.nop_h.ac_command = acmd_nop;
  2790. nop.nop_h.ac_link = nop_addr;
  2791. obram_write(ioaddr, nop_addr, (unsigned char *) &nop,
  2792. sizeof(nop));
  2793. tbd.tbd_status = TBD_STATUS_EOF;
  2794. tbd.tbd_next_bd_offset = I82586NULL;
  2795. tbd.tbd_bufl = buf_addr;
  2796. tbd.tbd_bufh = 0;
  2797. obram_write(ioaddr, tbd_addr, (unsigned char *) &tbd,
  2798. sizeof(tbd));
  2799. }
  2800. first_nop =
  2801. OFFSET_CU + (NTXBLOCKS - 1) * TXBLOCKZ + sizeof(ac_tx_t);
  2802. obram_write(ioaddr, scboff(OFFSET_SCB, scb_cbl_offset),
  2803. (unsigned char *) &first_nop, sizeof(first_nop));
  2804. scb_cs = SCB_CMD_CUC_GO;
  2805. obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
  2806. (unsigned char *) &scb_cs, sizeof(scb_cs));
  2807. set_chan_attn(ioaddr, lp->hacr);
  2808. for (i = 1000; i > 0; i--) {
  2809. obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
  2810. (unsigned char *) &scb_cs, sizeof(scb_cs));
  2811. if (scb_cs == 0)
  2812. break;
  2813. udelay(10);
  2814. }
  2815. if (i <= 0) {
  2816. #ifdef DEBUG_CONFIG_ERROR
  2817. printk(KERN_INFO
  2818. "%s: wavelan_cu_start(): board not accepting command.\n",
  2819. dev->name);
  2820. #endif
  2821. return -1;
  2822. }
  2823. lp->tx_n_in_use = 0;
  2824. netif_start_queue(dev);
  2825. #ifdef DEBUG_CONFIG_TRACE
  2826. printk(KERN_DEBUG "%s: <-wv_cu_start()\n", dev->name);
  2827. #endif
  2828. return 0;
  2829. }
  2830. /*------------------------------------------------------------------*/
  2831. /*
  2832. * This routine does a standard configuration of the WaveLAN
  2833. * controller (i82586).
  2834. *
  2835. * It initialises the scp, iscp and scb structure
  2836. * The first two are just pointers to the next.
  2837. * The last one is used for basic configuration and for basic
  2838. * communication (interrupt status).
  2839. *
  2840. * (called by wv_hw_reset())
  2841. */
  2842. static int wv_82586_start(struct net_device * dev)
  2843. {
  2844. net_local *lp = (net_local *) dev->priv;
  2845. unsigned long ioaddr = dev->base_addr;
  2846. scp_t scp; /* system configuration pointer */
  2847. iscp_t iscp; /* intermediate scp */
  2848. scb_t scb; /* system control block */
  2849. ach_t cb; /* Action command header */
  2850. u8 zeroes[512];
  2851. int i;
  2852. #ifdef DEBUG_CONFIG_TRACE
  2853. printk(KERN_DEBUG "%s: ->wv_82586_start()\n", dev->name);
  2854. #endif
  2855. /*
  2856. * Clear the onboard RAM.
  2857. */
  2858. memset(&zeroes[0], 0x00, sizeof(zeroes));
  2859. for (i = 0; i < I82586_MEMZ; i += sizeof(zeroes))
  2860. obram_write(ioaddr, i, &zeroes[0], sizeof(zeroes));
  2861. /*
  2862. * Construct the command unit structures:
  2863. * scp, iscp, scb, cb.
  2864. */
  2865. memset(&scp, 0x00, sizeof(scp));
  2866. scp.scp_sysbus = SCP_SY_16BBUS;
  2867. scp.scp_iscpl = OFFSET_ISCP;
  2868. obram_write(ioaddr, OFFSET_SCP, (unsigned char *) &scp,
  2869. sizeof(scp));
  2870. memset(&iscp, 0x00, sizeof(iscp));
  2871. iscp.iscp_busy = 1;
  2872. iscp.iscp_offset = OFFSET_SCB;
  2873. obram_write(ioaddr, OFFSET_ISCP, (unsigned char *) &iscp,
  2874. sizeof(iscp));
  2875. /* Our first command is to reset the i82586. */
  2876. memset(&scb, 0x00, sizeof(scb));
  2877. scb.scb_command = SCB_CMD_RESET;
  2878. scb.scb_cbl_offset = OFFSET_CU;
  2879. scb.scb_rfa_offset = OFFSET_RU;
  2880. obram_write(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
  2881. sizeof(scb));
  2882. set_chan_attn(ioaddr, lp->hacr);
  2883. /* Wait for command to finish. */
  2884. for (i = 1000; i > 0; i--) {
  2885. obram_read(ioaddr, OFFSET_ISCP, (unsigned char *) &iscp,
  2886. sizeof(iscp));
  2887. if (iscp.iscp_busy == (unsigned short) 0)
  2888. break;
  2889. udelay(10);
  2890. }
  2891. if (i <= 0) {
  2892. #ifdef DEBUG_CONFIG_ERROR
  2893. printk(KERN_INFO
  2894. "%s: wv_82586_start(): iscp_busy timeout.\n",
  2895. dev->name);
  2896. #endif
  2897. return -1;
  2898. }
  2899. /* Check command completion. */
  2900. for (i = 15; i > 0; i--) {
  2901. obram_read(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
  2902. sizeof(scb));
  2903. if (scb.scb_status == (SCB_ST_CX | SCB_ST_CNA))
  2904. break;
  2905. udelay(10);
  2906. }
  2907. if (i <= 0) {
  2908. #ifdef DEBUG_CONFIG_ERROR
  2909. printk(KERN_INFO
  2910. "%s: wv_82586_start(): status: expected 0x%02x, got 0x%02x.\n",
  2911. dev->name, SCB_ST_CX | SCB_ST_CNA, scb.scb_status);
  2912. #endif
  2913. return -1;
  2914. }
  2915. wv_ack(dev);
  2916. /* Set the action command header. */
  2917. memset(&cb, 0x00, sizeof(cb));
  2918. cb.ac_command = AC_CFLD_EL | (AC_CFLD_CMD & acmd_diagnose);
  2919. cb.ac_link = OFFSET_CU;
  2920. obram_write(ioaddr, OFFSET_CU, (unsigned char *) &cb, sizeof(cb));
  2921. if (wv_synchronous_cmd(dev, "diag()") == -1)
  2922. return -1;
  2923. obram_read(ioaddr, OFFSET_CU, (unsigned char *) &cb, sizeof(cb));
  2924. if (cb.ac_status & AC_SFLD_FAIL) {
  2925. #ifdef DEBUG_CONFIG_ERROR
  2926. printk(KERN_INFO
  2927. "%s: wv_82586_start(): i82586 Self Test failed.\n",
  2928. dev->name);
  2929. #endif
  2930. return -1;
  2931. }
  2932. #ifdef DEBUG_I82586_SHOW
  2933. wv_scb_show(ioaddr);
  2934. #endif
  2935. #ifdef DEBUG_CONFIG_TRACE
  2936. printk(KERN_DEBUG "%s: <-wv_82586_start()\n", dev->name);
  2937. #endif
  2938. return 0;
  2939. }
  2940. /*------------------------------------------------------------------*/
  2941. /*
  2942. * This routine does a standard configuration of the WaveLAN
  2943. * controller (i82586).
  2944. *
  2945. * This routine is a violent hack. We use the first free transmit block
  2946. * to make our configuration. In the buffer area, we create the three
  2947. * configuration commands (linked). We make the previous NOP point to
  2948. * the beginning of the buffer instead of the tx command. After, we go
  2949. * as usual to the NOP command.
  2950. * Note that only the last command (mc_set) will generate an interrupt.
  2951. *
  2952. * (called by wv_hw_reset(), wv_82586_reconfig(), wavelan_packet_xmit())
  2953. */
  2954. static void wv_82586_config(struct net_device * dev)
  2955. {
  2956. net_local *lp = (net_local *) dev->priv;
  2957. unsigned long ioaddr = dev->base_addr;
  2958. unsigned short txblock;
  2959. unsigned short txpred;
  2960. unsigned short tx_addr;
  2961. unsigned short nop_addr;
  2962. unsigned short tbd_addr;
  2963. unsigned short cfg_addr;
  2964. unsigned short ias_addr;
  2965. unsigned short mcs_addr;
  2966. ac_tx_t tx;
  2967. ac_nop_t nop;
  2968. ac_cfg_t cfg; /* Configure action */
  2969. ac_ias_t ias; /* IA-setup action */
  2970. ac_mcs_t mcs; /* Multicast setup */
  2971. struct dev_mc_list *dmi;
  2972. #ifdef DEBUG_CONFIG_TRACE
  2973. printk(KERN_DEBUG "%s: ->wv_82586_config()\n", dev->name);
  2974. #endif
  2975. /* Check nothing bad has happened */
  2976. if (lp->tx_n_in_use == (NTXBLOCKS - 1)) {
  2977. #ifdef DEBUG_CONFIG_ERROR
  2978. printk(KERN_INFO "%s: wv_82586_config(): Tx queue full.\n",
  2979. dev->name);
  2980. #endif
  2981. return;
  2982. }
  2983. /* Calculate addresses of next block and previous block. */
  2984. txblock = lp->tx_first_free;
  2985. txpred = txblock - TXBLOCKZ;
  2986. if (txpred < OFFSET_CU)
  2987. txpred += NTXBLOCKS * TXBLOCKZ;
  2988. lp->tx_first_free += TXBLOCKZ;
  2989. if (lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
  2990. lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ;
  2991. lp->tx_n_in_use++;
  2992. /* Calculate addresses of the different parts of the block. */
  2993. tx_addr = txblock;
  2994. nop_addr = tx_addr + sizeof(tx);
  2995. tbd_addr = nop_addr + sizeof(nop);
  2996. cfg_addr = tbd_addr + sizeof(tbd_t); /* beginning of the buffer */
  2997. ias_addr = cfg_addr + sizeof(cfg);
  2998. mcs_addr = ias_addr + sizeof(ias);
  2999. /*
  3000. * Transmit command
  3001. */
  3002. tx.tx_h.ac_status = 0xFFFF; /* Fake completion value */
  3003. obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status),
  3004. (unsigned char *) &tx.tx_h.ac_status,
  3005. sizeof(tx.tx_h.ac_status));
  3006. /*
  3007. * NOP command
  3008. */
  3009. nop.nop_h.ac_status = 0;
  3010. obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
  3011. (unsigned char *) &nop.nop_h.ac_status,
  3012. sizeof(nop.nop_h.ac_status));
  3013. nop.nop_h.ac_link = nop_addr;
  3014. obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
  3015. (unsigned char *) &nop.nop_h.ac_link,
  3016. sizeof(nop.nop_h.ac_link));
  3017. /* Create a configure action. */
  3018. memset(&cfg, 0x00, sizeof(cfg));
  3019. /*
  3020. * For Linux we invert AC_CFG_ALOC() so as to conform
  3021. * to the way that net packets reach us from above.
  3022. * (See also ac_tx_t.)
  3023. *
  3024. * Updated from Wavelan Manual WCIN085B
  3025. */
  3026. cfg.cfg_byte_cnt =
  3027. AC_CFG_BYTE_CNT(sizeof(ac_cfg_t) - sizeof(ach_t));
  3028. cfg.cfg_fifolim = AC_CFG_FIFOLIM(4);
  3029. cfg.cfg_byte8 = AC_CFG_SAV_BF(1) | AC_CFG_SRDY(0);
  3030. cfg.cfg_byte9 = AC_CFG_ELPBCK(0) |
  3031. AC_CFG_ILPBCK(0) |
  3032. AC_CFG_PRELEN(AC_CFG_PLEN_2) |
  3033. AC_CFG_ALOC(1) | AC_CFG_ADDRLEN(WAVELAN_ADDR_SIZE);
  3034. cfg.cfg_byte10 = AC_CFG_BOFMET(1) |
  3035. AC_CFG_ACR(6) | AC_CFG_LINPRIO(0);
  3036. cfg.cfg_ifs = 0x20;
  3037. cfg.cfg_slotl = 0x0C;
  3038. cfg.cfg_byte13 = AC_CFG_RETRYNUM(15) | AC_CFG_SLTTMHI(0);
  3039. cfg.cfg_byte14 = AC_CFG_FLGPAD(0) |
  3040. AC_CFG_BTSTF(0) |
  3041. AC_CFG_CRC16(0) |
  3042. AC_CFG_NCRC(0) |
  3043. AC_CFG_TNCRS(1) |
  3044. AC_CFG_MANCH(0) |
  3045. AC_CFG_BCDIS(0) | AC_CFG_PRM(lp->promiscuous);
  3046. cfg.cfg_byte15 = AC_CFG_ICDS(0) |
  3047. AC_CFG_CDTF(0) | AC_CFG_ICSS(0) | AC_CFG_CSTF(0);
  3048. /*
  3049. cfg.cfg_min_frm_len = AC_CFG_MNFRM(64);
  3050. */
  3051. cfg.cfg_min_frm_len = AC_CFG_MNFRM(8);
  3052. cfg.cfg_h.ac_command = (AC_CFLD_CMD & acmd_configure);
  3053. cfg.cfg_h.ac_link = ias_addr;
  3054. obram_write(ioaddr, cfg_addr, (unsigned char *) &cfg, sizeof(cfg));
  3055. /* Set up the MAC address */
  3056. memset(&ias, 0x00, sizeof(ias));
  3057. ias.ias_h.ac_command = (AC_CFLD_CMD & acmd_ia_setup);
  3058. ias.ias_h.ac_link = mcs_addr;
  3059. memcpy(&ias.ias_addr[0], (unsigned char *) &dev->dev_addr[0],
  3060. sizeof(ias.ias_addr));
  3061. obram_write(ioaddr, ias_addr, (unsigned char *) &ias, sizeof(ias));
  3062. /* Initialize adapter's Ethernet multicast addresses */
  3063. memset(&mcs, 0x00, sizeof(mcs));
  3064. mcs.mcs_h.ac_command = AC_CFLD_I | (AC_CFLD_CMD & acmd_mc_setup);
  3065. mcs.mcs_h.ac_link = nop_addr;
  3066. mcs.mcs_cnt = WAVELAN_ADDR_SIZE * lp->mc_count;
  3067. obram_write(ioaddr, mcs_addr, (unsigned char *) &mcs, sizeof(mcs));
  3068. /* Any address to set? */
  3069. if (lp->mc_count) {
  3070. for (dmi = dev->mc_list; dmi; dmi = dmi->next)
  3071. outsw(PIOP1(ioaddr), (u16 *) dmi->dmi_addr,
  3072. WAVELAN_ADDR_SIZE >> 1);
  3073. #ifdef DEBUG_CONFIG_INFO
  3074. {
  3075. DECLARE_MAC_BUF(mac);
  3076. printk(KERN_DEBUG
  3077. "%s: wv_82586_config(): set %d multicast addresses:\n",
  3078. dev->name, lp->mc_count);
  3079. for (dmi = dev->mc_list; dmi; dmi = dmi->next)
  3080. printk(KERN_DEBUG " %s\n",
  3081. print_mac(mac, dmi->dmi_addr));
  3082. }
  3083. #endif
  3084. }
  3085. /*
  3086. * Overwrite the predecessor NOP link
  3087. * so that it points to the configure action.
  3088. */
  3089. nop_addr = txpred + sizeof(tx);
  3090. nop.nop_h.ac_status = 0;
  3091. obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
  3092. (unsigned char *) &nop.nop_h.ac_status,
  3093. sizeof(nop.nop_h.ac_status));
  3094. nop.nop_h.ac_link = cfg_addr;
  3095. obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
  3096. (unsigned char *) &nop.nop_h.ac_link,
  3097. sizeof(nop.nop_h.ac_link));
  3098. /* Job done, clear the flag */
  3099. lp->reconfig_82586 = 0;
  3100. if (lp->tx_first_in_use == I82586NULL)
  3101. lp->tx_first_in_use = txblock;
  3102. if (lp->tx_n_in_use == (NTXBLOCKS - 1))
  3103. netif_stop_queue(dev);
  3104. #ifdef DEBUG_CONFIG_TRACE
  3105. printk(KERN_DEBUG "%s: <-wv_82586_config()\n", dev->name);
  3106. #endif
  3107. }
  3108. /*------------------------------------------------------------------*/
  3109. /*
  3110. * This routine, called by wavelan_close(), gracefully stops the
  3111. * WaveLAN controller (i82586).
  3112. * (called by wavelan_close())
  3113. */
  3114. static void wv_82586_stop(struct net_device * dev)
  3115. {
  3116. net_local *lp = (net_local *) dev->priv;
  3117. unsigned long ioaddr = dev->base_addr;
  3118. u16 scb_cmd;
  3119. #ifdef DEBUG_CONFIG_TRACE
  3120. printk(KERN_DEBUG "%s: ->wv_82586_stop()\n", dev->name);
  3121. #endif
  3122. /* Suspend both command unit and receive unit. */
  3123. scb_cmd =
  3124. (SCB_CMD_CUC & SCB_CMD_CUC_SUS) | (SCB_CMD_RUC &
  3125. SCB_CMD_RUC_SUS);
  3126. obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
  3127. (unsigned char *) &scb_cmd, sizeof(scb_cmd));
  3128. set_chan_attn(ioaddr, lp->hacr);
  3129. /* No more interrupts */
  3130. wv_ints_off(dev);
  3131. #ifdef DEBUG_CONFIG_TRACE
  3132. printk(KERN_DEBUG "%s: <-wv_82586_stop()\n", dev->name);
  3133. #endif
  3134. }
  3135. /*------------------------------------------------------------------*/
  3136. /*
  3137. * Totally reset the WaveLAN and restart it.
  3138. * Performs the following actions:
  3139. * 1. A power reset (reset DMA)
  3140. * 2. Initialize the radio modem (using wv_mmc_init)
  3141. * 3. Reset & Configure LAN controller (using wv_82586_start)
  3142. * 4. Start the LAN controller's command unit
  3143. * 5. Start the LAN controller's receive unit
  3144. * (called by wavelan_interrupt(), wavelan_watchdog() & wavelan_open())
  3145. */
  3146. static int wv_hw_reset(struct net_device * dev)
  3147. {
  3148. net_local *lp = (net_local *) dev->priv;
  3149. unsigned long ioaddr = dev->base_addr;
  3150. #ifdef DEBUG_CONFIG_TRACE
  3151. printk(KERN_DEBUG "%s: ->wv_hw_reset(dev=0x%x)\n", dev->name,
  3152. (unsigned int) dev);
  3153. #endif
  3154. /* Increase the number of resets done. */
  3155. lp->nresets++;
  3156. wv_hacr_reset(ioaddr);
  3157. lp->hacr = HACR_DEFAULT;
  3158. if ((wv_mmc_init(dev) < 0) || (wv_82586_start(dev) < 0))
  3159. return -1;
  3160. /* Enable the card to send interrupts. */
  3161. wv_ints_on(dev);
  3162. /* Start card functions */
  3163. if (wv_cu_start(dev) < 0)
  3164. return -1;
  3165. /* Setup the controller and parameters */
  3166. wv_82586_config(dev);
  3167. /* Finish configuration with the receive unit */
  3168. if (wv_ru_start(dev) < 0)
  3169. return -1;
  3170. #ifdef DEBUG_CONFIG_TRACE
  3171. printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name);
  3172. #endif
  3173. return 0;
  3174. }
  3175. /*------------------------------------------------------------------*/
  3176. /*
  3177. * Check if there is a WaveLAN at the specific base address.
  3178. * As a side effect, this reads the MAC address.
  3179. * (called in wavelan_probe() and init_module())
  3180. */
  3181. static int wv_check_ioaddr(unsigned long ioaddr, u8 * mac)
  3182. {
  3183. int i; /* Loop counter */
  3184. /* Check if the base address if available. */
  3185. if (!request_region(ioaddr, sizeof(ha_t), "wavelan probe"))
  3186. return -EBUSY; /* ioaddr already used */
  3187. /* Reset host interface */
  3188. wv_hacr_reset(ioaddr);
  3189. /* Read the MAC address from the parameter storage area. */
  3190. psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_univ_mac_addr),
  3191. mac, 6);
  3192. release_region(ioaddr, sizeof(ha_t));
  3193. /*
  3194. * Check the first three octets of the address for the manufacturer's code.
  3195. * Note: if this can't find your WaveLAN card, you've got a
  3196. * non-NCR/AT&T/Lucent ISA card. See wavelan.p.h for detail on
  3197. * how to configure your card.
  3198. */
  3199. for (i = 0; i < ARRAY_SIZE(MAC_ADDRESSES); i++)
  3200. if ((mac[0] == MAC_ADDRESSES[i][0]) &&
  3201. (mac[1] == MAC_ADDRESSES[i][1]) &&
  3202. (mac[2] == MAC_ADDRESSES[i][2]))
  3203. return 0;
  3204. #ifdef DEBUG_CONFIG_INFO
  3205. printk(KERN_WARNING
  3206. "WaveLAN (0x%3X): your MAC address might be %02X:%02X:%02X.\n",
  3207. ioaddr, mac[0], mac[1], mac[2]);
  3208. #endif
  3209. return -ENODEV;
  3210. }
  3211. /************************ INTERRUPT HANDLING ************************/
  3212. /*
  3213. * This function is the interrupt handler for the WaveLAN card. This
  3214. * routine will be called whenever:
  3215. */
  3216. static irqreturn_t wavelan_interrupt(int irq, void *dev_id)
  3217. {
  3218. struct net_device *dev;
  3219. unsigned long ioaddr;
  3220. net_local *lp;
  3221. u16 hasr;
  3222. u16 status;
  3223. u16 ack_cmd;
  3224. dev = dev_id;
  3225. #ifdef DEBUG_INTERRUPT_TRACE
  3226. printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name);
  3227. #endif
  3228. lp = (net_local *) dev->priv;
  3229. ioaddr = dev->base_addr;
  3230. #ifdef DEBUG_INTERRUPT_INFO
  3231. /* Check state of our spinlock */
  3232. if(spin_is_locked(&lp->spinlock))
  3233. printk(KERN_DEBUG
  3234. "%s: wavelan_interrupt(): spinlock is already locked !!!\n",
  3235. dev->name);
  3236. #endif
  3237. /* Prevent reentrancy. We need to do that because we may have
  3238. * multiple interrupt handler running concurrently.
  3239. * It is safe because interrupts are disabled before acquiring
  3240. * the spinlock. */
  3241. spin_lock(&lp->spinlock);
  3242. /* We always had spurious interrupts at startup, but lately I
  3243. * saw them comming *between* the request_irq() and the
  3244. * spin_lock_irqsave() in wavelan_open(), so the spinlock
  3245. * protection is no enough.
  3246. * So, we also check lp->hacr that will tell us is we enabled
  3247. * irqs or not (see wv_ints_on()).
  3248. * We can't use netif_running(dev) because we depend on the
  3249. * proper processing of the irq generated during the config. */
  3250. /* Which interrupt it is ? */
  3251. hasr = hasr_read(ioaddr);
  3252. #ifdef DEBUG_INTERRUPT_INFO
  3253. printk(KERN_INFO
  3254. "%s: wavelan_interrupt(): hasr 0x%04x; hacr 0x%04x.\n",
  3255. dev->name, hasr, lp->hacr);
  3256. #endif
  3257. /* Check modem interrupt */
  3258. if ((hasr & HASR_MMC_INTR) && (lp->hacr & HACR_MMC_INT_ENABLE)) {
  3259. u8 dce_status;
  3260. /*
  3261. * Interrupt from the modem management controller.
  3262. * This will clear it -- ignored for now.
  3263. */
  3264. mmc_read(ioaddr, mmroff(0, mmr_dce_status), &dce_status,
  3265. sizeof(dce_status));
  3266. #ifdef DEBUG_INTERRUPT_ERROR
  3267. printk(KERN_INFO
  3268. "%s: wavelan_interrupt(): unexpected mmc interrupt: status 0x%04x.\n",
  3269. dev->name, dce_status);
  3270. #endif
  3271. }
  3272. /* Check if not controller interrupt */
  3273. if (((hasr & HASR_82586_INTR) == 0) ||
  3274. ((lp->hacr & HACR_82586_INT_ENABLE) == 0)) {
  3275. #ifdef DEBUG_INTERRUPT_ERROR
  3276. printk(KERN_INFO
  3277. "%s: wavelan_interrupt(): interrupt not coming from i82586 - hasr 0x%04x.\n",
  3278. dev->name, hasr);
  3279. #endif
  3280. spin_unlock (&lp->spinlock);
  3281. return IRQ_NONE;
  3282. }
  3283. /* Read interrupt data. */
  3284. obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
  3285. (unsigned char *) &status, sizeof(status));
  3286. /*
  3287. * Acknowledge the interrupt(s).
  3288. */
  3289. ack_cmd = status & SCB_ST_INT;
  3290. obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
  3291. (unsigned char *) &ack_cmd, sizeof(ack_cmd));
  3292. set_chan_attn(ioaddr, lp->hacr);
  3293. #ifdef DEBUG_INTERRUPT_INFO
  3294. printk(KERN_DEBUG "%s: wavelan_interrupt(): status 0x%04x.\n",
  3295. dev->name, status);
  3296. #endif
  3297. /* Command completed. */
  3298. if ((status & SCB_ST_CX) == SCB_ST_CX) {
  3299. #ifdef DEBUG_INTERRUPT_INFO
  3300. printk(KERN_DEBUG
  3301. "%s: wavelan_interrupt(): command completed.\n",
  3302. dev->name);
  3303. #endif
  3304. wv_complete(dev, ioaddr, lp);
  3305. }
  3306. /* Frame received. */
  3307. if ((status & SCB_ST_FR) == SCB_ST_FR) {
  3308. #ifdef DEBUG_INTERRUPT_INFO
  3309. printk(KERN_DEBUG
  3310. "%s: wavelan_interrupt(): received packet.\n",
  3311. dev->name);
  3312. #endif
  3313. wv_receive(dev);
  3314. }
  3315. /* Check the state of the command unit. */
  3316. if (((status & SCB_ST_CNA) == SCB_ST_CNA) ||
  3317. (((status & SCB_ST_CUS) != SCB_ST_CUS_ACTV) &&
  3318. (netif_running(dev)))) {
  3319. #ifdef DEBUG_INTERRUPT_ERROR
  3320. printk(KERN_INFO
  3321. "%s: wavelan_interrupt(): CU inactive -- restarting\n",
  3322. dev->name);
  3323. #endif
  3324. wv_hw_reset(dev);
  3325. }
  3326. /* Check the state of the command unit. */
  3327. if (((status & SCB_ST_RNR) == SCB_ST_RNR) ||
  3328. (((status & SCB_ST_RUS) != SCB_ST_RUS_RDY) &&
  3329. (netif_running(dev)))) {
  3330. #ifdef DEBUG_INTERRUPT_ERROR
  3331. printk(KERN_INFO
  3332. "%s: wavelan_interrupt(): RU not ready -- restarting\n",
  3333. dev->name);
  3334. #endif
  3335. wv_hw_reset(dev);
  3336. }
  3337. /* Release spinlock */
  3338. spin_unlock (&lp->spinlock);
  3339. #ifdef DEBUG_INTERRUPT_TRACE
  3340. printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name);
  3341. #endif
  3342. return IRQ_HANDLED;
  3343. }
  3344. /*------------------------------------------------------------------*/
  3345. /*
  3346. * Watchdog: when we start a transmission, a timer is set for us in the
  3347. * kernel. If the transmission completes, this timer is disabled. If
  3348. * the timer expires, we are called and we try to unlock the hardware.
  3349. */
  3350. static void wavelan_watchdog(struct net_device * dev)
  3351. {
  3352. net_local * lp = (net_local *)dev->priv;
  3353. u_long ioaddr = dev->base_addr;
  3354. unsigned long flags;
  3355. unsigned int nreaped;
  3356. #ifdef DEBUG_INTERRUPT_TRACE
  3357. printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name);
  3358. #endif
  3359. #ifdef DEBUG_INTERRUPT_ERROR
  3360. printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n",
  3361. dev->name);
  3362. #endif
  3363. /* Check that we came here for something */
  3364. if (lp->tx_n_in_use <= 0) {
  3365. return;
  3366. }
  3367. spin_lock_irqsave(&lp->spinlock, flags);
  3368. /* Try to see if some buffers are not free (in case we missed
  3369. * an interrupt */
  3370. nreaped = wv_complete(dev, ioaddr, lp);
  3371. #ifdef DEBUG_INTERRUPT_INFO
  3372. printk(KERN_DEBUG
  3373. "%s: wavelan_watchdog(): %d reaped, %d remain.\n",
  3374. dev->name, nreaped, lp->tx_n_in_use);
  3375. #endif
  3376. #ifdef DEBUG_PSA_SHOW
  3377. {
  3378. psa_t psa;
  3379. psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
  3380. wv_psa_show(&psa);
  3381. }
  3382. #endif
  3383. #ifdef DEBUG_MMC_SHOW
  3384. wv_mmc_show(dev);
  3385. #endif
  3386. #ifdef DEBUG_I82586_SHOW
  3387. wv_cu_show(dev);
  3388. #endif
  3389. /* If no buffer has been freed */
  3390. if (nreaped == 0) {
  3391. #ifdef DEBUG_INTERRUPT_ERROR
  3392. printk(KERN_INFO
  3393. "%s: wavelan_watchdog(): cleanup failed, trying reset\n",
  3394. dev->name);
  3395. #endif
  3396. wv_hw_reset(dev);
  3397. }
  3398. /* At this point, we should have some free Tx buffer ;-) */
  3399. if (lp->tx_n_in_use < NTXBLOCKS - 1)
  3400. netif_wake_queue(dev);
  3401. spin_unlock_irqrestore(&lp->spinlock, flags);
  3402. #ifdef DEBUG_INTERRUPT_TRACE
  3403. printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name);
  3404. #endif
  3405. }
  3406. /********************* CONFIGURATION CALLBACKS *********************/
  3407. /*
  3408. * Here are the functions called by the Linux networking code (NET3)
  3409. * for initialization, configuration and deinstallations of the
  3410. * WaveLAN ISA hardware.
  3411. */
  3412. /*------------------------------------------------------------------*/
  3413. /*
  3414. * Configure and start up the WaveLAN PCMCIA adaptor.
  3415. * Called by NET3 when it "opens" the device.
  3416. */
  3417. static int wavelan_open(struct net_device * dev)
  3418. {
  3419. net_local * lp = (net_local *)dev->priv;
  3420. unsigned long flags;
  3421. #ifdef DEBUG_CALLBACK_TRACE
  3422. printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name,
  3423. (unsigned int) dev);
  3424. #endif
  3425. /* Check irq */
  3426. if (dev->irq == 0) {
  3427. #ifdef DEBUG_CONFIG_ERROR
  3428. printk(KERN_WARNING "%s: wavelan_open(): no IRQ\n",
  3429. dev->name);
  3430. #endif
  3431. return -ENXIO;
  3432. }
  3433. if (request_irq(dev->irq, &wavelan_interrupt, 0, "WaveLAN", dev) != 0)
  3434. {
  3435. #ifdef DEBUG_CONFIG_ERROR
  3436. printk(KERN_WARNING "%s: wavelan_open(): invalid IRQ\n",
  3437. dev->name);
  3438. #endif
  3439. return -EAGAIN;
  3440. }
  3441. spin_lock_irqsave(&lp->spinlock, flags);
  3442. if (wv_hw_reset(dev) != -1) {
  3443. netif_start_queue(dev);
  3444. } else {
  3445. free_irq(dev->irq, dev);
  3446. #ifdef DEBUG_CONFIG_ERROR
  3447. printk(KERN_INFO
  3448. "%s: wavelan_open(): impossible to start the card\n",
  3449. dev->name);
  3450. #endif
  3451. spin_unlock_irqrestore(&lp->spinlock, flags);
  3452. return -EAGAIN;
  3453. }
  3454. spin_unlock_irqrestore(&lp->spinlock, flags);
  3455. #ifdef DEBUG_CALLBACK_TRACE
  3456. printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name);
  3457. #endif
  3458. return 0;
  3459. }
  3460. /*------------------------------------------------------------------*/
  3461. /*
  3462. * Shut down the WaveLAN ISA card.
  3463. * Called by NET3 when it "closes" the device.
  3464. */
  3465. static int wavelan_close(struct net_device * dev)
  3466. {
  3467. net_local *lp = (net_local *) dev->priv;
  3468. unsigned long flags;
  3469. #ifdef DEBUG_CALLBACK_TRACE
  3470. printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name,
  3471. (unsigned int) dev);
  3472. #endif
  3473. netif_stop_queue(dev);
  3474. /*
  3475. * Flush the Tx and disable Rx.
  3476. */
  3477. spin_lock_irqsave(&lp->spinlock, flags);
  3478. wv_82586_stop(dev);
  3479. spin_unlock_irqrestore(&lp->spinlock, flags);
  3480. free_irq(dev->irq, dev);
  3481. #ifdef DEBUG_CALLBACK_TRACE
  3482. printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name);
  3483. #endif
  3484. return 0;
  3485. }
  3486. /*------------------------------------------------------------------*/
  3487. /*
  3488. * Probe an I/O address, and if the WaveLAN is there configure the
  3489. * device structure
  3490. * (called by wavelan_probe() and via init_module()).
  3491. */
  3492. static int __init wavelan_config(struct net_device *dev, unsigned short ioaddr)
  3493. {
  3494. u8 irq_mask;
  3495. int irq;
  3496. net_local *lp;
  3497. mac_addr mac;
  3498. int err;
  3499. if (!request_region(ioaddr, sizeof(ha_t), "wavelan"))
  3500. return -EADDRINUSE;
  3501. err = wv_check_ioaddr(ioaddr, mac);
  3502. if (err)
  3503. goto out;
  3504. memcpy(dev->dev_addr, mac, 6);
  3505. dev->base_addr = ioaddr;
  3506. #ifdef DEBUG_CALLBACK_TRACE
  3507. printk(KERN_DEBUG "%s: ->wavelan_config(dev=0x%x, ioaddr=0x%lx)\n",
  3508. dev->name, (unsigned int) dev, ioaddr);
  3509. #endif
  3510. /* Check IRQ argument on command line. */
  3511. if (dev->irq != 0) {
  3512. irq_mask = wv_irq_to_psa(dev->irq);
  3513. if (irq_mask == 0) {
  3514. #ifdef DEBUG_CONFIG_ERROR
  3515. printk(KERN_WARNING
  3516. "%s: wavelan_config(): invalid IRQ %d ignored.\n",
  3517. dev->name, dev->irq);
  3518. #endif
  3519. dev->irq = 0;
  3520. } else {
  3521. #ifdef DEBUG_CONFIG_INFO
  3522. printk(KERN_DEBUG
  3523. "%s: wavelan_config(): changing IRQ to %d\n",
  3524. dev->name, dev->irq);
  3525. #endif
  3526. psa_write(ioaddr, HACR_DEFAULT,
  3527. psaoff(0, psa_int_req_no), &irq_mask, 1);
  3528. /* update the Wavelan checksum */
  3529. update_psa_checksum(dev, ioaddr, HACR_DEFAULT);
  3530. wv_hacr_reset(ioaddr);
  3531. }
  3532. }
  3533. psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_int_req_no),
  3534. &irq_mask, 1);
  3535. if ((irq = wv_psa_to_irq(irq_mask)) == -1) {
  3536. #ifdef DEBUG_CONFIG_ERROR
  3537. printk(KERN_INFO
  3538. "%s: wavelan_config(): could not wavelan_map_irq(%d).\n",
  3539. dev->name, irq_mask);
  3540. #endif
  3541. err = -EAGAIN;
  3542. goto out;
  3543. }
  3544. dev->irq = irq;
  3545. dev->mem_start = 0x0000;
  3546. dev->mem_end = 0x0000;
  3547. dev->if_port = 0;
  3548. /* Initialize device structures */
  3549. memset(dev->priv, 0, sizeof(net_local));
  3550. lp = (net_local *) dev->priv;
  3551. /* Back link to the device structure. */
  3552. lp->dev = dev;
  3553. /* Add the device at the beginning of the linked list. */
  3554. lp->next = wavelan_list;
  3555. wavelan_list = lp;
  3556. lp->hacr = HACR_DEFAULT;
  3557. /* Multicast stuff */
  3558. lp->promiscuous = 0;
  3559. lp->mc_count = 0;
  3560. /* Init spinlock */
  3561. spin_lock_init(&lp->spinlock);
  3562. dev->open = wavelan_open;
  3563. dev->stop = wavelan_close;
  3564. dev->hard_start_xmit = wavelan_packet_xmit;
  3565. dev->get_stats = wavelan_get_stats;
  3566. dev->set_multicast_list = &wavelan_set_multicast_list;
  3567. dev->tx_timeout = &wavelan_watchdog;
  3568. dev->watchdog_timeo = WATCHDOG_JIFFIES;
  3569. #ifdef SET_MAC_ADDRESS
  3570. dev->set_mac_address = &wavelan_set_mac_address;
  3571. #endif /* SET_MAC_ADDRESS */
  3572. dev->wireless_handlers = &wavelan_handler_def;
  3573. lp->wireless_data.spy_data = &lp->spy_data;
  3574. dev->wireless_data = &lp->wireless_data;
  3575. dev->mtu = WAVELAN_MTU;
  3576. /* Display nice information. */
  3577. wv_init_info(dev);
  3578. #ifdef DEBUG_CALLBACK_TRACE
  3579. printk(KERN_DEBUG "%s: <-wavelan_config()\n", dev->name);
  3580. #endif
  3581. return 0;
  3582. out:
  3583. release_region(ioaddr, sizeof(ha_t));
  3584. return err;
  3585. }
  3586. /*------------------------------------------------------------------*/
  3587. /*
  3588. * Check for a network adaptor of this type. Return '0' iff one
  3589. * exists. There seem to be different interpretations of
  3590. * the initial value of dev->base_addr.
  3591. * We follow the example in drivers/net/ne.c.
  3592. * (called in "Space.c")
  3593. */
  3594. struct net_device * __init wavelan_probe(int unit)
  3595. {
  3596. struct net_device *dev;
  3597. short base_addr;
  3598. int def_irq;
  3599. int i;
  3600. int r = 0;
  3601. /* compile-time check the sizes of structures */
  3602. BUILD_BUG_ON(sizeof(psa_t) != PSA_SIZE);
  3603. BUILD_BUG_ON(sizeof(mmw_t) != MMW_SIZE);
  3604. BUILD_BUG_ON(sizeof(mmr_t) != MMR_SIZE);
  3605. BUILD_BUG_ON(sizeof(ha_t) != HA_SIZE);
  3606. dev = alloc_etherdev(sizeof(net_local));
  3607. if (!dev)
  3608. return ERR_PTR(-ENOMEM);
  3609. sprintf(dev->name, "eth%d", unit);
  3610. netdev_boot_setup_check(dev);
  3611. base_addr = dev->base_addr;
  3612. def_irq = dev->irq;
  3613. #ifdef DEBUG_CALLBACK_TRACE
  3614. printk(KERN_DEBUG
  3615. "%s: ->wavelan_probe(dev=%p (base_addr=0x%x))\n",
  3616. dev->name, dev, (unsigned int) dev->base_addr);
  3617. #endif
  3618. /* Don't probe at all. */
  3619. if (base_addr < 0) {
  3620. #ifdef DEBUG_CONFIG_ERROR
  3621. printk(KERN_WARNING
  3622. "%s: wavelan_probe(): invalid base address\n",
  3623. dev->name);
  3624. #endif
  3625. r = -ENXIO;
  3626. } else if (base_addr > 0x100) { /* Check a single specified location. */
  3627. r = wavelan_config(dev, base_addr);
  3628. #ifdef DEBUG_CONFIG_INFO
  3629. if (r != 0)
  3630. printk(KERN_DEBUG
  3631. "%s: wavelan_probe(): no device at specified base address (0x%X) or address already in use\n",
  3632. dev->name, base_addr);
  3633. #endif
  3634. #ifdef DEBUG_CALLBACK_TRACE
  3635. printk(KERN_DEBUG "%s: <-wavelan_probe()\n", dev->name);
  3636. #endif
  3637. } else { /* Scan all possible addresses of the WaveLAN hardware. */
  3638. for (i = 0; i < ARRAY_SIZE(iobase); i++) {
  3639. dev->irq = def_irq;
  3640. if (wavelan_config(dev, iobase[i]) == 0) {
  3641. #ifdef DEBUG_CALLBACK_TRACE
  3642. printk(KERN_DEBUG
  3643. "%s: <-wavelan_probe()\n",
  3644. dev->name);
  3645. #endif
  3646. break;
  3647. }
  3648. }
  3649. if (i == ARRAY_SIZE(iobase))
  3650. r = -ENODEV;
  3651. }
  3652. if (r)
  3653. goto out;
  3654. r = register_netdev(dev);
  3655. if (r)
  3656. goto out1;
  3657. return dev;
  3658. out1:
  3659. release_region(dev->base_addr, sizeof(ha_t));
  3660. wavelan_list = wavelan_list->next;
  3661. out:
  3662. free_netdev(dev);
  3663. return ERR_PTR(r);
  3664. }
  3665. /****************************** MODULE ******************************/
  3666. /*
  3667. * Module entry point: insertion and removal
  3668. */
  3669. #ifdef MODULE
  3670. /*------------------------------------------------------------------*/
  3671. /*
  3672. * Insertion of the module
  3673. * I'm now quite proud of the multi-device support.
  3674. */
  3675. int __init init_module(void)
  3676. {
  3677. int ret = -EIO; /* Return error if no cards found */
  3678. int i;
  3679. #ifdef DEBUG_MODULE_TRACE
  3680. printk(KERN_DEBUG "-> init_module()\n");
  3681. #endif
  3682. /* If probing is asked */
  3683. if (io[0] == 0) {
  3684. #ifdef DEBUG_CONFIG_ERROR
  3685. printk(KERN_WARNING
  3686. "WaveLAN init_module(): doing device probing (bad !)\n");
  3687. printk(KERN_WARNING
  3688. "Specify base addresses while loading module to correct the problem\n");
  3689. #endif
  3690. /* Copy the basic set of address to be probed. */
  3691. for (i = 0; i < ARRAY_SIZE(iobase); i++)
  3692. io[i] = iobase[i];
  3693. }
  3694. /* Loop on all possible base addresses. */
  3695. i = -1;
  3696. while ((io[++i] != 0) && (i < ARRAY_SIZE(io))) {
  3697. struct net_device *dev = alloc_etherdev(sizeof(net_local));
  3698. if (!dev)
  3699. break;
  3700. if (name[i])
  3701. strcpy(dev->name, name[i]); /* Copy name */
  3702. dev->base_addr = io[i];
  3703. dev->irq = irq[i];
  3704. /* Check if there is something at this base address. */
  3705. if (wavelan_config(dev, io[i]) == 0) {
  3706. if (register_netdev(dev) != 0) {
  3707. release_region(dev->base_addr, sizeof(ha_t));
  3708. wavelan_list = wavelan_list->next;
  3709. } else {
  3710. ret = 0;
  3711. continue;
  3712. }
  3713. }
  3714. free_netdev(dev);
  3715. }
  3716. #ifdef DEBUG_CONFIG_ERROR
  3717. if (!wavelan_list)
  3718. printk(KERN_WARNING
  3719. "WaveLAN init_module(): no device found\n");
  3720. #endif
  3721. #ifdef DEBUG_MODULE_TRACE
  3722. printk(KERN_DEBUG "<- init_module()\n");
  3723. #endif
  3724. return ret;
  3725. }
  3726. /*------------------------------------------------------------------*/
  3727. /*
  3728. * Removal of the module
  3729. */
  3730. void cleanup_module(void)
  3731. {
  3732. #ifdef DEBUG_MODULE_TRACE
  3733. printk(KERN_DEBUG "-> cleanup_module()\n");
  3734. #endif
  3735. /* Loop on all devices and release them. */
  3736. while (wavelan_list) {
  3737. struct net_device *dev = wavelan_list->dev;
  3738. #ifdef DEBUG_CONFIG_INFO
  3739. printk(KERN_DEBUG
  3740. "%s: cleanup_module(): removing device at 0x%x\n",
  3741. dev->name, (unsigned int) dev);
  3742. #endif
  3743. unregister_netdev(dev);
  3744. release_region(dev->base_addr, sizeof(ha_t));
  3745. wavelan_list = wavelan_list->next;
  3746. free_netdev(dev);
  3747. }
  3748. #ifdef DEBUG_MODULE_TRACE
  3749. printk(KERN_DEBUG "<- cleanup_module()\n");
  3750. #endif
  3751. }
  3752. #endif /* MODULE */
  3753. MODULE_LICENSE("GPL");
  3754. /*
  3755. * This software may only be used and distributed
  3756. * according to the terms of the GNU General Public License.
  3757. *
  3758. * This software was developed as a component of the
  3759. * Linux operating system.
  3760. * It is based on other device drivers and information
  3761. * either written or supplied by:
  3762. * Ajay Bakre (bakre@paul.rutgers.edu),
  3763. * Donald Becker (becker@scyld.com),
  3764. * Loeke Brederveld (Loeke.Brederveld@Utrecht.NCR.com),
  3765. * Anders Klemets (klemets@it.kth.se),
  3766. * Vladimir V. Kolpakov (w@stier.koenig.ru),
  3767. * Marc Meertens (Marc.Meertens@Utrecht.NCR.com),
  3768. * Pauline Middelink (middelin@polyware.iaf.nl),
  3769. * Robert Morris (rtm@das.harvard.edu),
  3770. * Jean Tourrilhes (jt@hplb.hpl.hp.com),
  3771. * Girish Welling (welling@paul.rutgers.edu),
  3772. *
  3773. * Thanks go also to:
  3774. * James Ashton (jaa101@syseng.anu.edu.au),
  3775. * Alan Cox (alan@lxorguk.ukuu.org.uk),
  3776. * Allan Creighton (allanc@cs.usyd.edu.au),
  3777. * Matthew Geier (matthew@cs.usyd.edu.au),
  3778. * Remo di Giovanni (remo@cs.usyd.edu.au),
  3779. * Eckhard Grah (grah@wrcs1.urz.uni-wuppertal.de),
  3780. * Vipul Gupta (vgupta@cs.binghamton.edu),
  3781. * Mark Hagan (mhagan@wtcpost.daytonoh.NCR.COM),
  3782. * Tim Nicholson (tim@cs.usyd.edu.au),
  3783. * Ian Parkin (ian@cs.usyd.edu.au),
  3784. * John Rosenberg (johnr@cs.usyd.edu.au),
  3785. * George Rossi (george@phm.gov.au),
  3786. * Arthur Scott (arthur@cs.usyd.edu.au),
  3787. * Peter Storey,
  3788. * for their assistance and advice.
  3789. *
  3790. * Please send bug reports, updates, comments to:
  3791. *
  3792. * Bruce Janson Email: bruce@cs.usyd.edu.au
  3793. * Basser Department of Computer Science Phone: +61-2-9351-3423
  3794. * University of Sydney, N.S.W., 2006, AUSTRALIA Fax: +61-2-9351-3838
  3795. */