wavelan_cs.c 139 KB

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