wavelan.c 120 KB

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