wavelan.c 120 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382
  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 NETDEV_TX_BUSY;
  2475. }
  2476. /* Do we need some padding? */
  2477. /* Note : on wireless the propagation time is in the order of 1us,
  2478. * and we don't have the Ethernet specific requirement of beeing
  2479. * able to detect collisions, therefore in theory we don't really
  2480. * need to pad. Jean II */
  2481. if (skb->len < ETH_ZLEN) {
  2482. memset(data, 0, ETH_ZLEN);
  2483. skb_copy_from_linear_data(skb, data, skb->len);
  2484. /* Write packet on the card */
  2485. if(wv_packet_write(dev, data, ETH_ZLEN))
  2486. return NETDEV_TX_BUSY; /* We failed */
  2487. }
  2488. else if(wv_packet_write(dev, skb->data, skb->len))
  2489. return NETDEV_TX_BUSY; /* We failed */
  2490. dev_kfree_skb(skb);
  2491. #ifdef DEBUG_TX_TRACE
  2492. printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
  2493. #endif
  2494. return NETDEV_TX_OK;
  2495. }
  2496. /*********************** HARDWARE CONFIGURATION ***********************/
  2497. /*
  2498. * This part does the real job of starting and configuring the hardware.
  2499. */
  2500. /*--------------------------------------------------------------------*/
  2501. /*
  2502. * Routine to initialize the Modem Management Controller.
  2503. * (called by wv_hw_reset())
  2504. */
  2505. static int wv_mmc_init(struct net_device * dev)
  2506. {
  2507. unsigned long ioaddr = dev->base_addr;
  2508. net_local *lp = netdev_priv(dev);
  2509. psa_t psa;
  2510. mmw_t m;
  2511. int configured;
  2512. #ifdef DEBUG_CONFIG_TRACE
  2513. printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name);
  2514. #endif
  2515. /* Read the parameter storage area. */
  2516. psa_read(ioaddr, lp->hacr, 0, (unsigned char *) &psa, sizeof(psa));
  2517. #ifdef USE_PSA_CONFIG
  2518. configured = psa.psa_conf_status & 1;
  2519. #else
  2520. configured = 0;
  2521. #endif
  2522. /* Is the PSA is not configured */
  2523. if (!configured) {
  2524. /* User will be able to configure NWID later (with iwconfig). */
  2525. psa.psa_nwid[0] = 0;
  2526. psa.psa_nwid[1] = 0;
  2527. /* no NWID checking since NWID is not set */
  2528. psa.psa_nwid_select = 0;
  2529. /* Disable encryption */
  2530. psa.psa_encryption_select = 0;
  2531. /* Set to standard values:
  2532. * 0x04 for AT,
  2533. * 0x01 for MCA,
  2534. * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
  2535. */
  2536. if (psa.psa_comp_number & 1)
  2537. psa.psa_thr_pre_set = 0x01;
  2538. else
  2539. psa.psa_thr_pre_set = 0x04;
  2540. psa.psa_quality_thr = 0x03;
  2541. /* It is configured */
  2542. psa.psa_conf_status |= 1;
  2543. #ifdef USE_PSA_CONFIG
  2544. /* Write the psa. */
  2545. psa_write(ioaddr, lp->hacr,
  2546. (char *) psa.psa_nwid - (char *) &psa,
  2547. (unsigned char *) psa.psa_nwid, 4);
  2548. psa_write(ioaddr, lp->hacr,
  2549. (char *) &psa.psa_thr_pre_set - (char *) &psa,
  2550. (unsigned char *) &psa.psa_thr_pre_set, 1);
  2551. psa_write(ioaddr, lp->hacr,
  2552. (char *) &psa.psa_quality_thr - (char *) &psa,
  2553. (unsigned char *) &psa.psa_quality_thr, 1);
  2554. psa_write(ioaddr, lp->hacr,
  2555. (char *) &psa.psa_conf_status - (char *) &psa,
  2556. (unsigned char *) &psa.psa_conf_status, 1);
  2557. /* update the Wavelan checksum */
  2558. update_psa_checksum(dev, ioaddr, lp->hacr);
  2559. #endif
  2560. }
  2561. /* Zero the mmc structure. */
  2562. memset(&m, 0x00, sizeof(m));
  2563. /* Copy PSA info to the mmc. */
  2564. m.mmw_netw_id_l = psa.psa_nwid[1];
  2565. m.mmw_netw_id_h = psa.psa_nwid[0];
  2566. if (psa.psa_nwid_select & 1)
  2567. m.mmw_loopt_sel = 0x00;
  2568. else
  2569. m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
  2570. memcpy(&m.mmw_encr_key, &psa.psa_encryption_key,
  2571. sizeof(m.mmw_encr_key));
  2572. if (psa.psa_encryption_select)
  2573. m.mmw_encr_enable =
  2574. MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
  2575. else
  2576. m.mmw_encr_enable = 0;
  2577. m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
  2578. m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
  2579. /*
  2580. * Set default modem control parameters.
  2581. * See NCR document 407-0024326 Rev. A.
  2582. */
  2583. m.mmw_jabber_enable = 0x01;
  2584. m.mmw_freeze = 0;
  2585. m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
  2586. m.mmw_ifs = 0x20;
  2587. m.mmw_mod_delay = 0x04;
  2588. m.mmw_jam_time = 0x38;
  2589. m.mmw_des_io_invert = 0;
  2590. m.mmw_decay_prm = 0;
  2591. m.mmw_decay_updat_prm = 0;
  2592. /* Write all info to MMC. */
  2593. mmc_write(ioaddr, 0, (u8 *) & m, sizeof(m));
  2594. /* The following code starts the modem of the 2.00 frequency
  2595. * selectable cards at power on. It's not strictly needed for the
  2596. * following boots.
  2597. * The original patch was by Joe Finney for the PCMCIA driver, but
  2598. * I've cleaned it up a bit and added documentation.
  2599. * Thanks to Loeke Brederveld from Lucent for the info.
  2600. */
  2601. /* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
  2602. * Does it work for everybody, especially old cards? */
  2603. /* Note: WFREQSEL verifies that it is able to read a sensible
  2604. * frequency from EEPROM (address 0x00) and that MMR_FEE_STATUS_ID
  2605. * is 0xA (Xilinx version) or 0xB (Ariadne version).
  2606. * My test is more crude but does work. */
  2607. if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
  2608. (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
  2609. /* We must download the frequency parameters to the
  2610. * synthesizers (from the EEPROM - area 1)
  2611. * Note: as the EEPROM is automatically decremented, we set the end
  2612. * if the area... */
  2613. m.mmw_fee_addr = 0x0F;
  2614. m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
  2615. mmc_write(ioaddr, (char *) &m.mmw_fee_ctrl - (char *) &m,
  2616. (unsigned char *) &m.mmw_fee_ctrl, 2);
  2617. /* Wait until the download is finished. */
  2618. fee_wait(ioaddr, 100, 100);
  2619. #ifdef DEBUG_CONFIG_INFO
  2620. /* The frequency was in the last word downloaded. */
  2621. mmc_read(ioaddr, (char *) &m.mmw_fee_data_l - (char *) &m,
  2622. (unsigned char *) &m.mmw_fee_data_l, 2);
  2623. /* Print some info for the user. */
  2624. printk(KERN_DEBUG
  2625. "%s: WaveLAN 2.00 recognised (frequency select). Current frequency = %ld\n",
  2626. dev->name,
  2627. ((m.
  2628. mmw_fee_data_h << 4) | (m.mmw_fee_data_l >> 4)) *
  2629. 5 / 2 + 24000L);
  2630. #endif
  2631. /* We must now download the power adjust value (gain) to
  2632. * the synthesizers (from the EEPROM - area 7 - DAC). */
  2633. m.mmw_fee_addr = 0x61;
  2634. m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
  2635. mmc_write(ioaddr, (char *) &m.mmw_fee_ctrl - (char *) &m,
  2636. (unsigned char *) &m.mmw_fee_ctrl, 2);
  2637. /* Wait until the download is finished. */
  2638. }
  2639. /* if 2.00 card */
  2640. #ifdef DEBUG_CONFIG_TRACE
  2641. printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name);
  2642. #endif
  2643. return 0;
  2644. }
  2645. /*------------------------------------------------------------------*/
  2646. /*
  2647. * Construct the fd and rbd structures.
  2648. * Start the receive unit.
  2649. * (called by wv_hw_reset())
  2650. */
  2651. static int wv_ru_start(struct net_device * dev)
  2652. {
  2653. net_local *lp = netdev_priv(dev);
  2654. unsigned long ioaddr = dev->base_addr;
  2655. u16 scb_cs;
  2656. fd_t fd;
  2657. rbd_t rbd;
  2658. u16 rx;
  2659. u16 rx_next;
  2660. int i;
  2661. #ifdef DEBUG_CONFIG_TRACE
  2662. printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name);
  2663. #endif
  2664. obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
  2665. (unsigned char *) &scb_cs, sizeof(scb_cs));
  2666. if ((scb_cs & SCB_ST_RUS) == SCB_ST_RUS_RDY)
  2667. return 0;
  2668. lp->rx_head = OFFSET_RU;
  2669. for (i = 0, rx = lp->rx_head; i < NRXBLOCKS; i++, rx = rx_next) {
  2670. rx_next =
  2671. (i == NRXBLOCKS - 1) ? lp->rx_head : rx + RXBLOCKZ;
  2672. fd.fd_status = 0;
  2673. fd.fd_command = (i == NRXBLOCKS - 1) ? FD_COMMAND_EL : 0;
  2674. fd.fd_link_offset = rx_next;
  2675. fd.fd_rbd_offset = rx + sizeof(fd);
  2676. obram_write(ioaddr, rx, (unsigned char *) &fd, sizeof(fd));
  2677. rbd.rbd_status = 0;
  2678. rbd.rbd_next_rbd_offset = I82586NULL;
  2679. rbd.rbd_bufl = rx + sizeof(fd) + sizeof(rbd);
  2680. rbd.rbd_bufh = 0;
  2681. rbd.rbd_el_size = RBD_EL | (RBD_SIZE & MAXDATAZ);
  2682. obram_write(ioaddr, rx + sizeof(fd),
  2683. (unsigned char *) &rbd, sizeof(rbd));
  2684. lp->rx_last = rx;
  2685. }
  2686. obram_write(ioaddr, scboff(OFFSET_SCB, scb_rfa_offset),
  2687. (unsigned char *) &lp->rx_head, sizeof(lp->rx_head));
  2688. scb_cs = SCB_CMD_RUC_GO;
  2689. obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
  2690. (unsigned char *) &scb_cs, sizeof(scb_cs));
  2691. set_chan_attn(ioaddr, lp->hacr);
  2692. for (i = 1000; i > 0; i--) {
  2693. obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
  2694. (unsigned char *) &scb_cs, sizeof(scb_cs));
  2695. if (scb_cs == 0)
  2696. break;
  2697. udelay(10);
  2698. }
  2699. if (i <= 0) {
  2700. #ifdef DEBUG_CONFIG_ERROR
  2701. printk(KERN_INFO
  2702. "%s: wavelan_ru_start(): board not accepting command.\n",
  2703. dev->name);
  2704. #endif
  2705. return -1;
  2706. }
  2707. #ifdef DEBUG_CONFIG_TRACE
  2708. printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name);
  2709. #endif
  2710. return 0;
  2711. }
  2712. /*------------------------------------------------------------------*/
  2713. /*
  2714. * Initialise the transmit blocks.
  2715. * Start the command unit executing the NOP
  2716. * self-loop of the first transmit block.
  2717. *
  2718. * Here we create the list of send buffers used to transmit packets
  2719. * between the PC and the command unit. For each buffer, we create a
  2720. * buffer descriptor (pointing on the buffer), a transmit command
  2721. * (pointing to the buffer descriptor) and a NOP command.
  2722. * The transmit command is linked to the NOP, and the NOP to itself.
  2723. * When we will have finished executing the transmit command, we will
  2724. * then loop on the NOP. By releasing the NOP link to a new command,
  2725. * we may send another buffer.
  2726. *
  2727. * (called by wv_hw_reset())
  2728. */
  2729. static int wv_cu_start(struct net_device * dev)
  2730. {
  2731. net_local *lp = netdev_priv(dev);
  2732. unsigned long ioaddr = dev->base_addr;
  2733. int i;
  2734. u16 txblock;
  2735. u16 first_nop;
  2736. u16 scb_cs;
  2737. #ifdef DEBUG_CONFIG_TRACE
  2738. printk(KERN_DEBUG "%s: ->wv_cu_start()\n", dev->name);
  2739. #endif
  2740. lp->tx_first_free = OFFSET_CU;
  2741. lp->tx_first_in_use = I82586NULL;
  2742. for (i = 0, txblock = OFFSET_CU;
  2743. i < NTXBLOCKS; i++, txblock += TXBLOCKZ) {
  2744. ac_tx_t tx;
  2745. ac_nop_t nop;
  2746. tbd_t tbd;
  2747. unsigned short tx_addr;
  2748. unsigned short nop_addr;
  2749. unsigned short tbd_addr;
  2750. unsigned short buf_addr;
  2751. tx_addr = txblock;
  2752. nop_addr = tx_addr + sizeof(tx);
  2753. tbd_addr = nop_addr + sizeof(nop);
  2754. buf_addr = tbd_addr + sizeof(tbd);
  2755. tx.tx_h.ac_status = 0;
  2756. tx.tx_h.ac_command = acmd_transmit | AC_CFLD_I;
  2757. tx.tx_h.ac_link = nop_addr;
  2758. tx.tx_tbd_offset = tbd_addr;
  2759. obram_write(ioaddr, tx_addr, (unsigned char *) &tx,
  2760. sizeof(tx));
  2761. nop.nop_h.ac_status = 0;
  2762. nop.nop_h.ac_command = acmd_nop;
  2763. nop.nop_h.ac_link = nop_addr;
  2764. obram_write(ioaddr, nop_addr, (unsigned char *) &nop,
  2765. sizeof(nop));
  2766. tbd.tbd_status = TBD_STATUS_EOF;
  2767. tbd.tbd_next_bd_offset = I82586NULL;
  2768. tbd.tbd_bufl = buf_addr;
  2769. tbd.tbd_bufh = 0;
  2770. obram_write(ioaddr, tbd_addr, (unsigned char *) &tbd,
  2771. sizeof(tbd));
  2772. }
  2773. first_nop =
  2774. OFFSET_CU + (NTXBLOCKS - 1) * TXBLOCKZ + sizeof(ac_tx_t);
  2775. obram_write(ioaddr, scboff(OFFSET_SCB, scb_cbl_offset),
  2776. (unsigned char *) &first_nop, sizeof(first_nop));
  2777. scb_cs = SCB_CMD_CUC_GO;
  2778. obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
  2779. (unsigned char *) &scb_cs, sizeof(scb_cs));
  2780. set_chan_attn(ioaddr, lp->hacr);
  2781. for (i = 1000; i > 0; i--) {
  2782. obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
  2783. (unsigned char *) &scb_cs, sizeof(scb_cs));
  2784. if (scb_cs == 0)
  2785. break;
  2786. udelay(10);
  2787. }
  2788. if (i <= 0) {
  2789. #ifdef DEBUG_CONFIG_ERROR
  2790. printk(KERN_INFO
  2791. "%s: wavelan_cu_start(): board not accepting command.\n",
  2792. dev->name);
  2793. #endif
  2794. return -1;
  2795. }
  2796. lp->tx_n_in_use = 0;
  2797. netif_start_queue(dev);
  2798. #ifdef DEBUG_CONFIG_TRACE
  2799. printk(KERN_DEBUG "%s: <-wv_cu_start()\n", dev->name);
  2800. #endif
  2801. return 0;
  2802. }
  2803. /*------------------------------------------------------------------*/
  2804. /*
  2805. * This routine does a standard configuration of the WaveLAN
  2806. * controller (i82586).
  2807. *
  2808. * It initialises the scp, iscp and scb structure
  2809. * The first two are just pointers to the next.
  2810. * The last one is used for basic configuration and for basic
  2811. * communication (interrupt status).
  2812. *
  2813. * (called by wv_hw_reset())
  2814. */
  2815. static int wv_82586_start(struct net_device * dev)
  2816. {
  2817. net_local *lp = netdev_priv(dev);
  2818. unsigned long ioaddr = dev->base_addr;
  2819. scp_t scp; /* system configuration pointer */
  2820. iscp_t iscp; /* intermediate scp */
  2821. scb_t scb; /* system control block */
  2822. ach_t cb; /* Action command header */
  2823. u8 zeroes[512];
  2824. int i;
  2825. #ifdef DEBUG_CONFIG_TRACE
  2826. printk(KERN_DEBUG "%s: ->wv_82586_start()\n", dev->name);
  2827. #endif
  2828. /*
  2829. * Clear the onboard RAM.
  2830. */
  2831. memset(&zeroes[0], 0x00, sizeof(zeroes));
  2832. for (i = 0; i < I82586_MEMZ; i += sizeof(zeroes))
  2833. obram_write(ioaddr, i, &zeroes[0], sizeof(zeroes));
  2834. /*
  2835. * Construct the command unit structures:
  2836. * scp, iscp, scb, cb.
  2837. */
  2838. memset(&scp, 0x00, sizeof(scp));
  2839. scp.scp_sysbus = SCP_SY_16BBUS;
  2840. scp.scp_iscpl = OFFSET_ISCP;
  2841. obram_write(ioaddr, OFFSET_SCP, (unsigned char *) &scp,
  2842. sizeof(scp));
  2843. memset(&iscp, 0x00, sizeof(iscp));
  2844. iscp.iscp_busy = 1;
  2845. iscp.iscp_offset = OFFSET_SCB;
  2846. obram_write(ioaddr, OFFSET_ISCP, (unsigned char *) &iscp,
  2847. sizeof(iscp));
  2848. /* Our first command is to reset the i82586. */
  2849. memset(&scb, 0x00, sizeof(scb));
  2850. scb.scb_command = SCB_CMD_RESET;
  2851. scb.scb_cbl_offset = OFFSET_CU;
  2852. scb.scb_rfa_offset = OFFSET_RU;
  2853. obram_write(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
  2854. sizeof(scb));
  2855. set_chan_attn(ioaddr, lp->hacr);
  2856. /* Wait for command to finish. */
  2857. for (i = 1000; i > 0; i--) {
  2858. obram_read(ioaddr, OFFSET_ISCP, (unsigned char *) &iscp,
  2859. sizeof(iscp));
  2860. if (iscp.iscp_busy == (unsigned short) 0)
  2861. break;
  2862. udelay(10);
  2863. }
  2864. if (i <= 0) {
  2865. #ifdef DEBUG_CONFIG_ERROR
  2866. printk(KERN_INFO
  2867. "%s: wv_82586_start(): iscp_busy timeout.\n",
  2868. dev->name);
  2869. #endif
  2870. return -1;
  2871. }
  2872. /* Check command completion. */
  2873. for (i = 15; i > 0; i--) {
  2874. obram_read(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
  2875. sizeof(scb));
  2876. if (scb.scb_status == (SCB_ST_CX | SCB_ST_CNA))
  2877. break;
  2878. udelay(10);
  2879. }
  2880. if (i <= 0) {
  2881. #ifdef DEBUG_CONFIG_ERROR
  2882. printk(KERN_INFO
  2883. "%s: wv_82586_start(): status: expected 0x%02x, got 0x%02x.\n",
  2884. dev->name, SCB_ST_CX | SCB_ST_CNA, scb.scb_status);
  2885. #endif
  2886. return -1;
  2887. }
  2888. wv_ack(dev);
  2889. /* Set the action command header. */
  2890. memset(&cb, 0x00, sizeof(cb));
  2891. cb.ac_command = AC_CFLD_EL | (AC_CFLD_CMD & acmd_diagnose);
  2892. cb.ac_link = OFFSET_CU;
  2893. obram_write(ioaddr, OFFSET_CU, (unsigned char *) &cb, sizeof(cb));
  2894. if (wv_synchronous_cmd(dev, "diag()") == -1)
  2895. return -1;
  2896. obram_read(ioaddr, OFFSET_CU, (unsigned char *) &cb, sizeof(cb));
  2897. if (cb.ac_status & AC_SFLD_FAIL) {
  2898. #ifdef DEBUG_CONFIG_ERROR
  2899. printk(KERN_INFO
  2900. "%s: wv_82586_start(): i82586 Self Test failed.\n",
  2901. dev->name);
  2902. #endif
  2903. return -1;
  2904. }
  2905. #ifdef DEBUG_I82586_SHOW
  2906. wv_scb_show(ioaddr);
  2907. #endif
  2908. #ifdef DEBUG_CONFIG_TRACE
  2909. printk(KERN_DEBUG "%s: <-wv_82586_start()\n", dev->name);
  2910. #endif
  2911. return 0;
  2912. }
  2913. /*------------------------------------------------------------------*/
  2914. /*
  2915. * This routine does a standard configuration of the WaveLAN
  2916. * controller (i82586).
  2917. *
  2918. * This routine is a violent hack. We use the first free transmit block
  2919. * to make our configuration. In the buffer area, we create the three
  2920. * configuration commands (linked). We make the previous NOP point to
  2921. * the beginning of the buffer instead of the tx command. After, we go
  2922. * as usual to the NOP command.
  2923. * Note that only the last command (mc_set) will generate an interrupt.
  2924. *
  2925. * (called by wv_hw_reset(), wv_82586_reconfig(), wavelan_packet_xmit())
  2926. */
  2927. static void wv_82586_config(struct net_device * dev)
  2928. {
  2929. net_local *lp = netdev_priv(dev);
  2930. unsigned long ioaddr = dev->base_addr;
  2931. unsigned short txblock;
  2932. unsigned short txpred;
  2933. unsigned short tx_addr;
  2934. unsigned short nop_addr;
  2935. unsigned short tbd_addr;
  2936. unsigned short cfg_addr;
  2937. unsigned short ias_addr;
  2938. unsigned short mcs_addr;
  2939. ac_tx_t tx;
  2940. ac_nop_t nop;
  2941. ac_cfg_t cfg; /* Configure action */
  2942. ac_ias_t ias; /* IA-setup action */
  2943. ac_mcs_t mcs; /* Multicast setup */
  2944. struct dev_mc_list *dmi;
  2945. #ifdef DEBUG_CONFIG_TRACE
  2946. printk(KERN_DEBUG "%s: ->wv_82586_config()\n", dev->name);
  2947. #endif
  2948. /* Check nothing bad has happened */
  2949. if (lp->tx_n_in_use == (NTXBLOCKS - 1)) {
  2950. #ifdef DEBUG_CONFIG_ERROR
  2951. printk(KERN_INFO "%s: wv_82586_config(): Tx queue full.\n",
  2952. dev->name);
  2953. #endif
  2954. return;
  2955. }
  2956. /* Calculate addresses of next block and previous block. */
  2957. txblock = lp->tx_first_free;
  2958. txpred = txblock - TXBLOCKZ;
  2959. if (txpred < OFFSET_CU)
  2960. txpred += NTXBLOCKS * TXBLOCKZ;
  2961. lp->tx_first_free += TXBLOCKZ;
  2962. if (lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
  2963. lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ;
  2964. lp->tx_n_in_use++;
  2965. /* Calculate addresses of the different parts of the block. */
  2966. tx_addr = txblock;
  2967. nop_addr = tx_addr + sizeof(tx);
  2968. tbd_addr = nop_addr + sizeof(nop);
  2969. cfg_addr = tbd_addr + sizeof(tbd_t); /* beginning of the buffer */
  2970. ias_addr = cfg_addr + sizeof(cfg);
  2971. mcs_addr = ias_addr + sizeof(ias);
  2972. /*
  2973. * Transmit command
  2974. */
  2975. tx.tx_h.ac_status = 0xFFFF; /* Fake completion value */
  2976. obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status),
  2977. (unsigned char *) &tx.tx_h.ac_status,
  2978. sizeof(tx.tx_h.ac_status));
  2979. /*
  2980. * NOP command
  2981. */
  2982. nop.nop_h.ac_status = 0;
  2983. obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
  2984. (unsigned char *) &nop.nop_h.ac_status,
  2985. sizeof(nop.nop_h.ac_status));
  2986. nop.nop_h.ac_link = nop_addr;
  2987. obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
  2988. (unsigned char *) &nop.nop_h.ac_link,
  2989. sizeof(nop.nop_h.ac_link));
  2990. /* Create a configure action. */
  2991. memset(&cfg, 0x00, sizeof(cfg));
  2992. /*
  2993. * For Linux we invert AC_CFG_ALOC() so as to conform
  2994. * to the way that net packets reach us from above.
  2995. * (See also ac_tx_t.)
  2996. *
  2997. * Updated from Wavelan Manual WCIN085B
  2998. */
  2999. cfg.cfg_byte_cnt =
  3000. AC_CFG_BYTE_CNT(sizeof(ac_cfg_t) - sizeof(ach_t));
  3001. cfg.cfg_fifolim = AC_CFG_FIFOLIM(4);
  3002. cfg.cfg_byte8 = AC_CFG_SAV_BF(1) | AC_CFG_SRDY(0);
  3003. cfg.cfg_byte9 = AC_CFG_ELPBCK(0) |
  3004. AC_CFG_ILPBCK(0) |
  3005. AC_CFG_PRELEN(AC_CFG_PLEN_2) |
  3006. AC_CFG_ALOC(1) | AC_CFG_ADDRLEN(WAVELAN_ADDR_SIZE);
  3007. cfg.cfg_byte10 = AC_CFG_BOFMET(1) |
  3008. AC_CFG_ACR(6) | AC_CFG_LINPRIO(0);
  3009. cfg.cfg_ifs = 0x20;
  3010. cfg.cfg_slotl = 0x0C;
  3011. cfg.cfg_byte13 = AC_CFG_RETRYNUM(15) | AC_CFG_SLTTMHI(0);
  3012. cfg.cfg_byte14 = AC_CFG_FLGPAD(0) |
  3013. AC_CFG_BTSTF(0) |
  3014. AC_CFG_CRC16(0) |
  3015. AC_CFG_NCRC(0) |
  3016. AC_CFG_TNCRS(1) |
  3017. AC_CFG_MANCH(0) |
  3018. AC_CFG_BCDIS(0) | AC_CFG_PRM(lp->promiscuous);
  3019. cfg.cfg_byte15 = AC_CFG_ICDS(0) |
  3020. AC_CFG_CDTF(0) | AC_CFG_ICSS(0) | AC_CFG_CSTF(0);
  3021. /*
  3022. cfg.cfg_min_frm_len = AC_CFG_MNFRM(64);
  3023. */
  3024. cfg.cfg_min_frm_len = AC_CFG_MNFRM(8);
  3025. cfg.cfg_h.ac_command = (AC_CFLD_CMD & acmd_configure);
  3026. cfg.cfg_h.ac_link = ias_addr;
  3027. obram_write(ioaddr, cfg_addr, (unsigned char *) &cfg, sizeof(cfg));
  3028. /* Set up the MAC address */
  3029. memset(&ias, 0x00, sizeof(ias));
  3030. ias.ias_h.ac_command = (AC_CFLD_CMD & acmd_ia_setup);
  3031. ias.ias_h.ac_link = mcs_addr;
  3032. memcpy(&ias.ias_addr[0], (unsigned char *) &dev->dev_addr[0],
  3033. sizeof(ias.ias_addr));
  3034. obram_write(ioaddr, ias_addr, (unsigned char *) &ias, sizeof(ias));
  3035. /* Initialize adapter's Ethernet multicast addresses */
  3036. memset(&mcs, 0x00, sizeof(mcs));
  3037. mcs.mcs_h.ac_command = AC_CFLD_I | (AC_CFLD_CMD & acmd_mc_setup);
  3038. mcs.mcs_h.ac_link = nop_addr;
  3039. mcs.mcs_cnt = WAVELAN_ADDR_SIZE * lp->mc_count;
  3040. obram_write(ioaddr, mcs_addr, (unsigned char *) &mcs, sizeof(mcs));
  3041. /* Any address to set? */
  3042. if (lp->mc_count) {
  3043. for (dmi = dev->mc_list; dmi; dmi = dmi->next)
  3044. outsw(PIOP1(ioaddr), (u16 *) dmi->dmi_addr,
  3045. WAVELAN_ADDR_SIZE >> 1);
  3046. #ifdef DEBUG_CONFIG_INFO
  3047. printk(KERN_DEBUG
  3048. "%s: wv_82586_config(): set %d multicast addresses:\n",
  3049. dev->name, lp->mc_count);
  3050. for (dmi = dev->mc_list; dmi; dmi = dmi->next)
  3051. printk(KERN_DEBUG " %pM\n", dmi->dmi_addr);
  3052. #endif
  3053. }
  3054. /*
  3055. * Overwrite the predecessor NOP link
  3056. * so that it points to the configure action.
  3057. */
  3058. nop_addr = txpred + sizeof(tx);
  3059. nop.nop_h.ac_status = 0;
  3060. obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
  3061. (unsigned char *) &nop.nop_h.ac_status,
  3062. sizeof(nop.nop_h.ac_status));
  3063. nop.nop_h.ac_link = cfg_addr;
  3064. obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
  3065. (unsigned char *) &nop.nop_h.ac_link,
  3066. sizeof(nop.nop_h.ac_link));
  3067. /* Job done, clear the flag */
  3068. lp->reconfig_82586 = 0;
  3069. if (lp->tx_first_in_use == I82586NULL)
  3070. lp->tx_first_in_use = txblock;
  3071. if (lp->tx_n_in_use == (NTXBLOCKS - 1))
  3072. netif_stop_queue(dev);
  3073. #ifdef DEBUG_CONFIG_TRACE
  3074. printk(KERN_DEBUG "%s: <-wv_82586_config()\n", dev->name);
  3075. #endif
  3076. }
  3077. /*------------------------------------------------------------------*/
  3078. /*
  3079. * This routine, called by wavelan_close(), gracefully stops the
  3080. * WaveLAN controller (i82586).
  3081. * (called by wavelan_close())
  3082. */
  3083. static void wv_82586_stop(struct net_device * dev)
  3084. {
  3085. net_local *lp = netdev_priv(dev);
  3086. unsigned long ioaddr = dev->base_addr;
  3087. u16 scb_cmd;
  3088. #ifdef DEBUG_CONFIG_TRACE
  3089. printk(KERN_DEBUG "%s: ->wv_82586_stop()\n", dev->name);
  3090. #endif
  3091. /* Suspend both command unit and receive unit. */
  3092. scb_cmd =
  3093. (SCB_CMD_CUC & SCB_CMD_CUC_SUS) | (SCB_CMD_RUC &
  3094. SCB_CMD_RUC_SUS);
  3095. obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
  3096. (unsigned char *) &scb_cmd, sizeof(scb_cmd));
  3097. set_chan_attn(ioaddr, lp->hacr);
  3098. /* No more interrupts */
  3099. wv_ints_off(dev);
  3100. #ifdef DEBUG_CONFIG_TRACE
  3101. printk(KERN_DEBUG "%s: <-wv_82586_stop()\n", dev->name);
  3102. #endif
  3103. }
  3104. /*------------------------------------------------------------------*/
  3105. /*
  3106. * Totally reset the WaveLAN and restart it.
  3107. * Performs the following actions:
  3108. * 1. A power reset (reset DMA)
  3109. * 2. Initialize the radio modem (using wv_mmc_init)
  3110. * 3. Reset & Configure LAN controller (using wv_82586_start)
  3111. * 4. Start the LAN controller's command unit
  3112. * 5. Start the LAN controller's receive unit
  3113. * (called by wavelan_interrupt(), wavelan_watchdog() & wavelan_open())
  3114. */
  3115. static int wv_hw_reset(struct net_device * dev)
  3116. {
  3117. net_local *lp = netdev_priv(dev);
  3118. unsigned long ioaddr = dev->base_addr;
  3119. #ifdef DEBUG_CONFIG_TRACE
  3120. printk(KERN_DEBUG "%s: ->wv_hw_reset(dev=0x%x)\n", dev->name,
  3121. (unsigned int) dev);
  3122. #endif
  3123. /* Increase the number of resets done. */
  3124. lp->nresets++;
  3125. wv_hacr_reset(ioaddr);
  3126. lp->hacr = HACR_DEFAULT;
  3127. if ((wv_mmc_init(dev) < 0) || (wv_82586_start(dev) < 0))
  3128. return -1;
  3129. /* Enable the card to send interrupts. */
  3130. wv_ints_on(dev);
  3131. /* Start card functions */
  3132. if (wv_cu_start(dev) < 0)
  3133. return -1;
  3134. /* Setup the controller and parameters */
  3135. wv_82586_config(dev);
  3136. /* Finish configuration with the receive unit */
  3137. if (wv_ru_start(dev) < 0)
  3138. return -1;
  3139. #ifdef DEBUG_CONFIG_TRACE
  3140. printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name);
  3141. #endif
  3142. return 0;
  3143. }
  3144. /*------------------------------------------------------------------*/
  3145. /*
  3146. * Check if there is a WaveLAN at the specific base address.
  3147. * As a side effect, this reads the MAC address.
  3148. * (called in wavelan_probe() and init_module())
  3149. */
  3150. static int wv_check_ioaddr(unsigned long ioaddr, u8 * mac)
  3151. {
  3152. int i; /* Loop counter */
  3153. /* Check if the base address if available. */
  3154. if (!request_region(ioaddr, sizeof(ha_t), "wavelan probe"))
  3155. return -EBUSY; /* ioaddr already used */
  3156. /* Reset host interface */
  3157. wv_hacr_reset(ioaddr);
  3158. /* Read the MAC address from the parameter storage area. */
  3159. psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_univ_mac_addr),
  3160. mac, 6);
  3161. release_region(ioaddr, sizeof(ha_t));
  3162. /*
  3163. * Check the first three octets of the address for the manufacturer's code.
  3164. * Note: if this can't find your WaveLAN card, you've got a
  3165. * non-NCR/AT&T/Lucent ISA card. See wavelan.p.h for detail on
  3166. * how to configure your card.
  3167. */
  3168. for (i = 0; i < ARRAY_SIZE(MAC_ADDRESSES); i++)
  3169. if ((mac[0] == MAC_ADDRESSES[i][0]) &&
  3170. (mac[1] == MAC_ADDRESSES[i][1]) &&
  3171. (mac[2] == MAC_ADDRESSES[i][2]))
  3172. return 0;
  3173. #ifdef DEBUG_CONFIG_INFO
  3174. printk(KERN_WARNING
  3175. "WaveLAN (0x%3X): your MAC address might be %02X:%02X:%02X.\n",
  3176. ioaddr, mac[0], mac[1], mac[2]);
  3177. #endif
  3178. return -ENODEV;
  3179. }
  3180. /************************ INTERRUPT HANDLING ************************/
  3181. /*
  3182. * This function is the interrupt handler for the WaveLAN card. This
  3183. * routine will be called whenever:
  3184. */
  3185. static irqreturn_t wavelan_interrupt(int irq, void *dev_id)
  3186. {
  3187. struct net_device *dev;
  3188. unsigned long ioaddr;
  3189. net_local *lp;
  3190. u16 hasr;
  3191. u16 status;
  3192. u16 ack_cmd;
  3193. dev = dev_id;
  3194. #ifdef DEBUG_INTERRUPT_TRACE
  3195. printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name);
  3196. #endif
  3197. lp = netdev_priv(dev);
  3198. ioaddr = dev->base_addr;
  3199. #ifdef DEBUG_INTERRUPT_INFO
  3200. /* Check state of our spinlock */
  3201. if(spin_is_locked(&lp->spinlock))
  3202. printk(KERN_DEBUG
  3203. "%s: wavelan_interrupt(): spinlock is already locked !!!\n",
  3204. dev->name);
  3205. #endif
  3206. /* Prevent reentrancy. We need to do that because we may have
  3207. * multiple interrupt handler running concurrently.
  3208. * It is safe because interrupts are disabled before acquiring
  3209. * the spinlock. */
  3210. spin_lock(&lp->spinlock);
  3211. /* We always had spurious interrupts at startup, but lately I
  3212. * saw them comming *between* the request_irq() and the
  3213. * spin_lock_irqsave() in wavelan_open(), so the spinlock
  3214. * protection is no enough.
  3215. * So, we also check lp->hacr that will tell us is we enabled
  3216. * irqs or not (see wv_ints_on()).
  3217. * We can't use netif_running(dev) because we depend on the
  3218. * proper processing of the irq generated during the config. */
  3219. /* Which interrupt it is ? */
  3220. hasr = hasr_read(ioaddr);
  3221. #ifdef DEBUG_INTERRUPT_INFO
  3222. printk(KERN_INFO
  3223. "%s: wavelan_interrupt(): hasr 0x%04x; hacr 0x%04x.\n",
  3224. dev->name, hasr, lp->hacr);
  3225. #endif
  3226. /* Check modem interrupt */
  3227. if ((hasr & HASR_MMC_INTR) && (lp->hacr & HACR_MMC_INT_ENABLE)) {
  3228. u8 dce_status;
  3229. /*
  3230. * Interrupt from the modem management controller.
  3231. * This will clear it -- ignored for now.
  3232. */
  3233. mmc_read(ioaddr, mmroff(0, mmr_dce_status), &dce_status,
  3234. sizeof(dce_status));
  3235. #ifdef DEBUG_INTERRUPT_ERROR
  3236. printk(KERN_INFO
  3237. "%s: wavelan_interrupt(): unexpected mmc interrupt: status 0x%04x.\n",
  3238. dev->name, dce_status);
  3239. #endif
  3240. }
  3241. /* Check if not controller interrupt */
  3242. if (((hasr & HASR_82586_INTR) == 0) ||
  3243. ((lp->hacr & HACR_82586_INT_ENABLE) == 0)) {
  3244. #ifdef DEBUG_INTERRUPT_ERROR
  3245. printk(KERN_INFO
  3246. "%s: wavelan_interrupt(): interrupt not coming from i82586 - hasr 0x%04x.\n",
  3247. dev->name, hasr);
  3248. #endif
  3249. spin_unlock (&lp->spinlock);
  3250. return IRQ_NONE;
  3251. }
  3252. /* Read interrupt data. */
  3253. obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
  3254. (unsigned char *) &status, sizeof(status));
  3255. /*
  3256. * Acknowledge the interrupt(s).
  3257. */
  3258. ack_cmd = status & SCB_ST_INT;
  3259. obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
  3260. (unsigned char *) &ack_cmd, sizeof(ack_cmd));
  3261. set_chan_attn(ioaddr, lp->hacr);
  3262. #ifdef DEBUG_INTERRUPT_INFO
  3263. printk(KERN_DEBUG "%s: wavelan_interrupt(): status 0x%04x.\n",
  3264. dev->name, status);
  3265. #endif
  3266. /* Command completed. */
  3267. if ((status & SCB_ST_CX) == SCB_ST_CX) {
  3268. #ifdef DEBUG_INTERRUPT_INFO
  3269. printk(KERN_DEBUG
  3270. "%s: wavelan_interrupt(): command completed.\n",
  3271. dev->name);
  3272. #endif
  3273. wv_complete(dev, ioaddr, lp);
  3274. }
  3275. /* Frame received. */
  3276. if ((status & SCB_ST_FR) == SCB_ST_FR) {
  3277. #ifdef DEBUG_INTERRUPT_INFO
  3278. printk(KERN_DEBUG
  3279. "%s: wavelan_interrupt(): received packet.\n",
  3280. dev->name);
  3281. #endif
  3282. wv_receive(dev);
  3283. }
  3284. /* Check the state of the command unit. */
  3285. if (((status & SCB_ST_CNA) == SCB_ST_CNA) ||
  3286. (((status & SCB_ST_CUS) != SCB_ST_CUS_ACTV) &&
  3287. (netif_running(dev)))) {
  3288. #ifdef DEBUG_INTERRUPT_ERROR
  3289. printk(KERN_INFO
  3290. "%s: wavelan_interrupt(): CU inactive -- restarting\n",
  3291. dev->name);
  3292. #endif
  3293. wv_hw_reset(dev);
  3294. }
  3295. /* Check the state of the command unit. */
  3296. if (((status & SCB_ST_RNR) == SCB_ST_RNR) ||
  3297. (((status & SCB_ST_RUS) != SCB_ST_RUS_RDY) &&
  3298. (netif_running(dev)))) {
  3299. #ifdef DEBUG_INTERRUPT_ERROR
  3300. printk(KERN_INFO
  3301. "%s: wavelan_interrupt(): RU not ready -- restarting\n",
  3302. dev->name);
  3303. #endif
  3304. wv_hw_reset(dev);
  3305. }
  3306. /* Release spinlock */
  3307. spin_unlock (&lp->spinlock);
  3308. #ifdef DEBUG_INTERRUPT_TRACE
  3309. printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name);
  3310. #endif
  3311. return IRQ_HANDLED;
  3312. }
  3313. /*------------------------------------------------------------------*/
  3314. /*
  3315. * Watchdog: when we start a transmission, a timer is set for us in the
  3316. * kernel. If the transmission completes, this timer is disabled. If
  3317. * the timer expires, we are called and we try to unlock the hardware.
  3318. */
  3319. static void wavelan_watchdog(struct net_device * dev)
  3320. {
  3321. net_local *lp = netdev_priv(dev);
  3322. u_long ioaddr = dev->base_addr;
  3323. unsigned long flags;
  3324. unsigned int nreaped;
  3325. #ifdef DEBUG_INTERRUPT_TRACE
  3326. printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name);
  3327. #endif
  3328. #ifdef DEBUG_INTERRUPT_ERROR
  3329. printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n",
  3330. dev->name);
  3331. #endif
  3332. /* Check that we came here for something */
  3333. if (lp->tx_n_in_use <= 0) {
  3334. return;
  3335. }
  3336. spin_lock_irqsave(&lp->spinlock, flags);
  3337. /* Try to see if some buffers are not free (in case we missed
  3338. * an interrupt */
  3339. nreaped = wv_complete(dev, ioaddr, lp);
  3340. #ifdef DEBUG_INTERRUPT_INFO
  3341. printk(KERN_DEBUG
  3342. "%s: wavelan_watchdog(): %d reaped, %d remain.\n",
  3343. dev->name, nreaped, lp->tx_n_in_use);
  3344. #endif
  3345. #ifdef DEBUG_PSA_SHOW
  3346. {
  3347. psa_t psa;
  3348. psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
  3349. wv_psa_show(&psa);
  3350. }
  3351. #endif
  3352. #ifdef DEBUG_MMC_SHOW
  3353. wv_mmc_show(dev);
  3354. #endif
  3355. #ifdef DEBUG_I82586_SHOW
  3356. wv_cu_show(dev);
  3357. #endif
  3358. /* If no buffer has been freed */
  3359. if (nreaped == 0) {
  3360. #ifdef DEBUG_INTERRUPT_ERROR
  3361. printk(KERN_INFO
  3362. "%s: wavelan_watchdog(): cleanup failed, trying reset\n",
  3363. dev->name);
  3364. #endif
  3365. wv_hw_reset(dev);
  3366. }
  3367. /* At this point, we should have some free Tx buffer ;-) */
  3368. if (lp->tx_n_in_use < NTXBLOCKS - 1)
  3369. netif_wake_queue(dev);
  3370. spin_unlock_irqrestore(&lp->spinlock, flags);
  3371. #ifdef DEBUG_INTERRUPT_TRACE
  3372. printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name);
  3373. #endif
  3374. }
  3375. /********************* CONFIGURATION CALLBACKS *********************/
  3376. /*
  3377. * Here are the functions called by the Linux networking code (NET3)
  3378. * for initialization, configuration and deinstallations of the
  3379. * WaveLAN ISA hardware.
  3380. */
  3381. /*------------------------------------------------------------------*/
  3382. /*
  3383. * Configure and start up the WaveLAN PCMCIA adaptor.
  3384. * Called by NET3 when it "opens" the device.
  3385. */
  3386. static int wavelan_open(struct net_device * dev)
  3387. {
  3388. net_local *lp = netdev_priv(dev);
  3389. unsigned long flags;
  3390. #ifdef DEBUG_CALLBACK_TRACE
  3391. printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name,
  3392. (unsigned int) dev);
  3393. #endif
  3394. /* Check irq */
  3395. if (dev->irq == 0) {
  3396. #ifdef DEBUG_CONFIG_ERROR
  3397. printk(KERN_WARNING "%s: wavelan_open(): no IRQ\n",
  3398. dev->name);
  3399. #endif
  3400. return -ENXIO;
  3401. }
  3402. if (request_irq(dev->irq, &wavelan_interrupt, 0, "WaveLAN", dev) != 0)
  3403. {
  3404. #ifdef DEBUG_CONFIG_ERROR
  3405. printk(KERN_WARNING "%s: wavelan_open(): invalid IRQ\n",
  3406. dev->name);
  3407. #endif
  3408. return -EAGAIN;
  3409. }
  3410. spin_lock_irqsave(&lp->spinlock, flags);
  3411. if (wv_hw_reset(dev) != -1) {
  3412. netif_start_queue(dev);
  3413. } else {
  3414. free_irq(dev->irq, dev);
  3415. #ifdef DEBUG_CONFIG_ERROR
  3416. printk(KERN_INFO
  3417. "%s: wavelan_open(): impossible to start the card\n",
  3418. dev->name);
  3419. #endif
  3420. spin_unlock_irqrestore(&lp->spinlock, flags);
  3421. return -EAGAIN;
  3422. }
  3423. spin_unlock_irqrestore(&lp->spinlock, flags);
  3424. #ifdef DEBUG_CALLBACK_TRACE
  3425. printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name);
  3426. #endif
  3427. return 0;
  3428. }
  3429. /*------------------------------------------------------------------*/
  3430. /*
  3431. * Shut down the WaveLAN ISA card.
  3432. * Called by NET3 when it "closes" the device.
  3433. */
  3434. static int wavelan_close(struct net_device * dev)
  3435. {
  3436. net_local *lp = netdev_priv(dev);
  3437. unsigned long flags;
  3438. #ifdef DEBUG_CALLBACK_TRACE
  3439. printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name,
  3440. (unsigned int) dev);
  3441. #endif
  3442. netif_stop_queue(dev);
  3443. /*
  3444. * Flush the Tx and disable Rx.
  3445. */
  3446. spin_lock_irqsave(&lp->spinlock, flags);
  3447. wv_82586_stop(dev);
  3448. spin_unlock_irqrestore(&lp->spinlock, flags);
  3449. free_irq(dev->irq, dev);
  3450. #ifdef DEBUG_CALLBACK_TRACE
  3451. printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name);
  3452. #endif
  3453. return 0;
  3454. }
  3455. static const struct net_device_ops wavelan_netdev_ops = {
  3456. .ndo_open = wavelan_open,
  3457. .ndo_stop = wavelan_close,
  3458. .ndo_start_xmit = wavelan_packet_xmit,
  3459. .ndo_set_multicast_list = wavelan_set_multicast_list,
  3460. .ndo_tx_timeout = wavelan_watchdog,
  3461. .ndo_change_mtu = eth_change_mtu,
  3462. .ndo_validate_addr = eth_validate_addr,
  3463. #ifdef SET_MAC_ADDRESS
  3464. .ndo_set_mac_address = wavelan_set_mac_address
  3465. #else
  3466. .ndo_set_mac_address = eth_mac_addr,
  3467. #endif
  3468. };
  3469. /*------------------------------------------------------------------*/
  3470. /*
  3471. * Probe an I/O address, and if the WaveLAN is there configure the
  3472. * device structure
  3473. * (called by wavelan_probe() and via init_module()).
  3474. */
  3475. static int __init wavelan_config(struct net_device *dev, unsigned short ioaddr)
  3476. {
  3477. u8 irq_mask;
  3478. int irq;
  3479. net_local *lp;
  3480. mac_addr mac;
  3481. int err;
  3482. if (!request_region(ioaddr, sizeof(ha_t), "wavelan"))
  3483. return -EADDRINUSE;
  3484. err = wv_check_ioaddr(ioaddr, mac);
  3485. if (err)
  3486. goto out;
  3487. memcpy(dev->dev_addr, mac, 6);
  3488. dev->base_addr = ioaddr;
  3489. #ifdef DEBUG_CALLBACK_TRACE
  3490. printk(KERN_DEBUG "%s: ->wavelan_config(dev=0x%x, ioaddr=0x%lx)\n",
  3491. dev->name, (unsigned int) dev, ioaddr);
  3492. #endif
  3493. /* Check IRQ argument on command line. */
  3494. if (dev->irq != 0) {
  3495. irq_mask = wv_irq_to_psa(dev->irq);
  3496. if (irq_mask == 0) {
  3497. #ifdef DEBUG_CONFIG_ERROR
  3498. printk(KERN_WARNING
  3499. "%s: wavelan_config(): invalid IRQ %d ignored.\n",
  3500. dev->name, dev->irq);
  3501. #endif
  3502. dev->irq = 0;
  3503. } else {
  3504. #ifdef DEBUG_CONFIG_INFO
  3505. printk(KERN_DEBUG
  3506. "%s: wavelan_config(): changing IRQ to %d\n",
  3507. dev->name, dev->irq);
  3508. #endif
  3509. psa_write(ioaddr, HACR_DEFAULT,
  3510. psaoff(0, psa_int_req_no), &irq_mask, 1);
  3511. /* update the Wavelan checksum */
  3512. update_psa_checksum(dev, ioaddr, HACR_DEFAULT);
  3513. wv_hacr_reset(ioaddr);
  3514. }
  3515. }
  3516. psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_int_req_no),
  3517. &irq_mask, 1);
  3518. if ((irq = wv_psa_to_irq(irq_mask)) == -1) {
  3519. #ifdef DEBUG_CONFIG_ERROR
  3520. printk(KERN_INFO
  3521. "%s: wavelan_config(): could not wavelan_map_irq(%d).\n",
  3522. dev->name, irq_mask);
  3523. #endif
  3524. err = -EAGAIN;
  3525. goto out;
  3526. }
  3527. dev->irq = irq;
  3528. dev->mem_start = 0x0000;
  3529. dev->mem_end = 0x0000;
  3530. dev->if_port = 0;
  3531. /* Initialize device structures */
  3532. memset(netdev_priv(dev), 0, sizeof(net_local));
  3533. lp = netdev_priv(dev);
  3534. /* Back link to the device structure. */
  3535. lp->dev = dev;
  3536. /* Add the device at the beginning of the linked list. */
  3537. lp->next = wavelan_list;
  3538. wavelan_list = lp;
  3539. lp->hacr = HACR_DEFAULT;
  3540. /* Multicast stuff */
  3541. lp->promiscuous = 0;
  3542. lp->mc_count = 0;
  3543. /* Init spinlock */
  3544. spin_lock_init(&lp->spinlock);
  3545. dev->netdev_ops = &wavelan_netdev_ops;
  3546. dev->watchdog_timeo = WATCHDOG_JIFFIES;
  3547. dev->wireless_handlers = &wavelan_handler_def;
  3548. lp->wireless_data.spy_data = &lp->spy_data;
  3549. dev->wireless_data = &lp->wireless_data;
  3550. dev->mtu = WAVELAN_MTU;
  3551. /* Display nice information. */
  3552. wv_init_info(dev);
  3553. #ifdef DEBUG_CALLBACK_TRACE
  3554. printk(KERN_DEBUG "%s: <-wavelan_config()\n", dev->name);
  3555. #endif
  3556. return 0;
  3557. out:
  3558. release_region(ioaddr, sizeof(ha_t));
  3559. return err;
  3560. }
  3561. /*------------------------------------------------------------------*/
  3562. /*
  3563. * Check for a network adaptor of this type. Return '0' iff one
  3564. * exists. There seem to be different interpretations of
  3565. * the initial value of dev->base_addr.
  3566. * We follow the example in drivers/net/ne.c.
  3567. * (called in "Space.c")
  3568. */
  3569. struct net_device * __init wavelan_probe(int unit)
  3570. {
  3571. struct net_device *dev;
  3572. short base_addr;
  3573. int def_irq;
  3574. int i;
  3575. int r = 0;
  3576. /* compile-time check the sizes of structures */
  3577. BUILD_BUG_ON(sizeof(psa_t) != PSA_SIZE);
  3578. BUILD_BUG_ON(sizeof(mmw_t) != MMW_SIZE);
  3579. BUILD_BUG_ON(sizeof(mmr_t) != MMR_SIZE);
  3580. BUILD_BUG_ON(sizeof(ha_t) != HA_SIZE);
  3581. dev = alloc_etherdev(sizeof(net_local));
  3582. if (!dev)
  3583. return ERR_PTR(-ENOMEM);
  3584. sprintf(dev->name, "eth%d", unit);
  3585. netdev_boot_setup_check(dev);
  3586. base_addr = dev->base_addr;
  3587. def_irq = dev->irq;
  3588. #ifdef DEBUG_CALLBACK_TRACE
  3589. printk(KERN_DEBUG
  3590. "%s: ->wavelan_probe(dev=%p (base_addr=0x%x))\n",
  3591. dev->name, dev, (unsigned int) dev->base_addr);
  3592. #endif
  3593. /* Don't probe at all. */
  3594. if (base_addr < 0) {
  3595. #ifdef DEBUG_CONFIG_ERROR
  3596. printk(KERN_WARNING
  3597. "%s: wavelan_probe(): invalid base address\n",
  3598. dev->name);
  3599. #endif
  3600. r = -ENXIO;
  3601. } else if (base_addr > 0x100) { /* Check a single specified location. */
  3602. r = wavelan_config(dev, base_addr);
  3603. #ifdef DEBUG_CONFIG_INFO
  3604. if (r != 0)
  3605. printk(KERN_DEBUG
  3606. "%s: wavelan_probe(): no device at specified base address (0x%X) or address already in use\n",
  3607. dev->name, base_addr);
  3608. #endif
  3609. #ifdef DEBUG_CALLBACK_TRACE
  3610. printk(KERN_DEBUG "%s: <-wavelan_probe()\n", dev->name);
  3611. #endif
  3612. } else { /* Scan all possible addresses of the WaveLAN hardware. */
  3613. for (i = 0; i < ARRAY_SIZE(iobase); i++) {
  3614. dev->irq = def_irq;
  3615. if (wavelan_config(dev, iobase[i]) == 0) {
  3616. #ifdef DEBUG_CALLBACK_TRACE
  3617. printk(KERN_DEBUG
  3618. "%s: <-wavelan_probe()\n",
  3619. dev->name);
  3620. #endif
  3621. break;
  3622. }
  3623. }
  3624. if (i == ARRAY_SIZE(iobase))
  3625. r = -ENODEV;
  3626. }
  3627. if (r)
  3628. goto out;
  3629. r = register_netdev(dev);
  3630. if (r)
  3631. goto out1;
  3632. return dev;
  3633. out1:
  3634. release_region(dev->base_addr, sizeof(ha_t));
  3635. wavelan_list = wavelan_list->next;
  3636. out:
  3637. free_netdev(dev);
  3638. return ERR_PTR(r);
  3639. }
  3640. /****************************** MODULE ******************************/
  3641. /*
  3642. * Module entry point: insertion and removal
  3643. */
  3644. #ifdef MODULE
  3645. /*------------------------------------------------------------------*/
  3646. /*
  3647. * Insertion of the module
  3648. * I'm now quite proud of the multi-device support.
  3649. */
  3650. int __init init_module(void)
  3651. {
  3652. int ret = -EIO; /* Return error if no cards found */
  3653. int i;
  3654. #ifdef DEBUG_MODULE_TRACE
  3655. printk(KERN_DEBUG "-> init_module()\n");
  3656. #endif
  3657. /* If probing is asked */
  3658. if (io[0] == 0) {
  3659. #ifdef DEBUG_CONFIG_ERROR
  3660. printk(KERN_WARNING
  3661. "WaveLAN init_module(): doing device probing (bad !)\n");
  3662. printk(KERN_WARNING
  3663. "Specify base addresses while loading module to correct the problem\n");
  3664. #endif
  3665. /* Copy the basic set of address to be probed. */
  3666. for (i = 0; i < ARRAY_SIZE(iobase); i++)
  3667. io[i] = iobase[i];
  3668. }
  3669. /* Loop on all possible base addresses. */
  3670. for (i = 0; i < ARRAY_SIZE(io) && io[i] != 0; i++) {
  3671. struct net_device *dev = alloc_etherdev(sizeof(net_local));
  3672. if (!dev)
  3673. break;
  3674. if (name[i])
  3675. strcpy(dev->name, name[i]); /* Copy name */
  3676. dev->base_addr = io[i];
  3677. dev->irq = irq[i];
  3678. /* Check if there is something at this base address. */
  3679. if (wavelan_config(dev, io[i]) == 0) {
  3680. if (register_netdev(dev) != 0) {
  3681. release_region(dev->base_addr, sizeof(ha_t));
  3682. wavelan_list = wavelan_list->next;
  3683. } else {
  3684. ret = 0;
  3685. continue;
  3686. }
  3687. }
  3688. free_netdev(dev);
  3689. }
  3690. #ifdef DEBUG_CONFIG_ERROR
  3691. if (!wavelan_list)
  3692. printk(KERN_WARNING
  3693. "WaveLAN init_module(): no device found\n");
  3694. #endif
  3695. #ifdef DEBUG_MODULE_TRACE
  3696. printk(KERN_DEBUG "<- init_module()\n");
  3697. #endif
  3698. return ret;
  3699. }
  3700. /*------------------------------------------------------------------*/
  3701. /*
  3702. * Removal of the module
  3703. */
  3704. void cleanup_module(void)
  3705. {
  3706. #ifdef DEBUG_MODULE_TRACE
  3707. printk(KERN_DEBUG "-> cleanup_module()\n");
  3708. #endif
  3709. /* Loop on all devices and release them. */
  3710. while (wavelan_list) {
  3711. struct net_device *dev = wavelan_list->dev;
  3712. #ifdef DEBUG_CONFIG_INFO
  3713. printk(KERN_DEBUG
  3714. "%s: cleanup_module(): removing device at 0x%x\n",
  3715. dev->name, (unsigned int) dev);
  3716. #endif
  3717. unregister_netdev(dev);
  3718. release_region(dev->base_addr, sizeof(ha_t));
  3719. wavelan_list = wavelan_list->next;
  3720. free_netdev(dev);
  3721. }
  3722. #ifdef DEBUG_MODULE_TRACE
  3723. printk(KERN_DEBUG "<- cleanup_module()\n");
  3724. #endif
  3725. }
  3726. #endif /* MODULE */
  3727. MODULE_LICENSE("GPL");
  3728. /*
  3729. * This software may only be used and distributed
  3730. * according to the terms of the GNU General Public License.
  3731. *
  3732. * This software was developed as a component of the
  3733. * Linux operating system.
  3734. * It is based on other device drivers and information
  3735. * either written or supplied by:
  3736. * Ajay Bakre (bakre@paul.rutgers.edu),
  3737. * Donald Becker (becker@scyld.com),
  3738. * Loeke Brederveld (Loeke.Brederveld@Utrecht.NCR.com),
  3739. * Anders Klemets (klemets@it.kth.se),
  3740. * Vladimir V. Kolpakov (w@stier.koenig.ru),
  3741. * Marc Meertens (Marc.Meertens@Utrecht.NCR.com),
  3742. * Pauline Middelink (middelin@polyware.iaf.nl),
  3743. * Robert Morris (rtm@das.harvard.edu),
  3744. * Jean Tourrilhes (jt@hplb.hpl.hp.com),
  3745. * Girish Welling (welling@paul.rutgers.edu),
  3746. *
  3747. * Thanks go also to:
  3748. * James Ashton (jaa101@syseng.anu.edu.au),
  3749. * Alan Cox (alan@lxorguk.ukuu.org.uk),
  3750. * Allan Creighton (allanc@cs.usyd.edu.au),
  3751. * Matthew Geier (matthew@cs.usyd.edu.au),
  3752. * Remo di Giovanni (remo@cs.usyd.edu.au),
  3753. * Eckhard Grah (grah@wrcs1.urz.uni-wuppertal.de),
  3754. * Vipul Gupta (vgupta@cs.binghamton.edu),
  3755. * Mark Hagan (mhagan@wtcpost.daytonoh.NCR.COM),
  3756. * Tim Nicholson (tim@cs.usyd.edu.au),
  3757. * Ian Parkin (ian@cs.usyd.edu.au),
  3758. * John Rosenberg (johnr@cs.usyd.edu.au),
  3759. * George Rossi (george@phm.gov.au),
  3760. * Arthur Scott (arthur@cs.usyd.edu.au),
  3761. * Peter Storey,
  3762. * for their assistance and advice.
  3763. *
  3764. * Please send bug reports, updates, comments to:
  3765. *
  3766. * Bruce Janson Email: bruce@cs.usyd.edu.au
  3767. * Basser Department of Computer Science Phone: +61-2-9351-3423
  3768. * University of Sydney, N.S.W., 2006, AUSTRALIA Fax: +61-2-9351-3838
  3769. */