wavelan_cs.c 132 KB

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