skge.c 133 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866
  1. /******************************************************************************
  2. *
  3. * Name: skge.c
  4. * Project: GEnesis, PCI Gigabit Ethernet Adapter
  5. * Version: $Revision: 1.46 $
  6. * Date: $Date: 2003/02/25 14:16:36 $
  7. * Purpose: The main driver source module
  8. *
  9. ******************************************************************************/
  10. /******************************************************************************
  11. *
  12. * (C)Copyright 1998-2003 SysKonnect GmbH.
  13. *
  14. * Driver for SysKonnect Gigabit Ethernet Server Adapters:
  15. *
  16. * SK-9871 (single link 1000Base-ZX)
  17. * SK-9872 (dual link 1000Base-ZX)
  18. * SK-9861 (single link 1000Base-SX, VF45 Volition Plug)
  19. * SK-9862 (dual link 1000Base-SX, VF45 Volition Plug)
  20. * SK-9841 (single link 1000Base-LX)
  21. * SK-9842 (dual link 1000Base-LX)
  22. * SK-9843 (single link 1000Base-SX)
  23. * SK-9844 (dual link 1000Base-SX)
  24. * SK-9821 (single link 1000Base-T)
  25. * SK-9822 (dual link 1000Base-T)
  26. * SK-9881 (single link 1000Base-SX V2 LC)
  27. * SK-9871 (single link 1000Base-ZX V2)
  28. * SK-9861 (single link 1000Base-SX V2, VF45 Volition Plug)
  29. * SK-9841 (single link 1000Base-LX V2)
  30. * SK-9843 (single link 1000Base-SX V2)
  31. * SK-9821 (single link 1000Base-T V2)
  32. *
  33. * Created 10-Feb-1999, based on Linux' acenic.c, 3c59x.c and
  34. * SysKonnects GEnesis Solaris driver
  35. * Author: Christoph Goos (cgoos@syskonnect.de)
  36. * Mirko Lindner (mlindner@syskonnect.de)
  37. *
  38. * Address all question to: linux@syskonnect.de
  39. *
  40. * The technical manual for the adapters is available from SysKonnect's
  41. * web pages: www.syskonnect.com
  42. * Goto "Support" and search Knowledge Base for "manual".
  43. *
  44. * This program is free software; you can redistribute it and/or modify
  45. * it under the terms of the GNU General Public License as published by
  46. * the Free Software Foundation; either version 2 of the License, or
  47. * (at your option) any later version.
  48. *
  49. * The information in this file is provided "AS IS" without warranty.
  50. *
  51. ******************************************************************************/
  52. /******************************************************************************
  53. *
  54. * History:
  55. *
  56. * $Log: skge.c,v $
  57. * Revision 1.46 2003/02/25 14:16:36 mlindner
  58. * Fix: Copyright statement
  59. *
  60. * Revision 1.45 2003/02/25 13:25:55 mlindner
  61. * Add: Performance improvements
  62. * Add: Support for various vendors
  63. * Fix: Init function
  64. *
  65. * Revision 1.44 2003/01/09 09:25:26 mlindner
  66. * Fix: Remove useless init_module/cleanup_module forward declarations
  67. *
  68. * Revision 1.43 2002/11/29 08:42:41 mlindner
  69. * Fix: Boot message
  70. *
  71. * Revision 1.42 2002/11/28 13:30:23 mlindner
  72. * Add: New frame check
  73. *
  74. * Revision 1.41 2002/11/27 13:55:18 mlindner
  75. * Fix: Drop wrong csum packets
  76. * Fix: Initialize proc_entry after hw check
  77. *
  78. * Revision 1.40 2002/10/31 07:50:37 tschilli
  79. * Function SkGeInitAssignRamToQueues() from common module inserted.
  80. * Autonegotiation is set to ON for all adapters.
  81. * LinkSpeedUsed is used in link up status report.
  82. * Role parameter will show up for 1000 Mbps links only.
  83. * GetConfiguration() inserted after init level 1 in SkGeChangeMtu().
  84. * All return values of SkGeInit() and SkGeInitPort() are checked.
  85. *
  86. * Revision 1.39 2002/10/02 12:56:05 mlindner
  87. * Add: Support for Yukon
  88. * Add: Support for ZEROCOPY, scatter-gather and hw checksum
  89. * Add: New transmit ring function (use SG and TCP/UDP hardware checksumming)
  90. * Add: New init function
  91. * Add: Speed check and setup
  92. * Add: Merge source for kernel 2.2.x and 2.4.x
  93. * Add: Opcode check for tcp
  94. * Add: Frame length check
  95. * Fix: Transmit complete interrupt
  96. * Fix: Interrupt moderation
  97. *
  98. * Revision 1.29.2.13 2002/01/14 12:44:52 mlindner
  99. * Fix: Rlmt modes
  100. *
  101. * Revision 1.29.2.12 2001/12/07 12:06:18 mlindner
  102. * Fix: malloc -> slab changes
  103. *
  104. * Revision 1.29.2.11 2001/12/06 15:19:20 mlindner
  105. * Add: DMA attributes
  106. * Fix: Module initialisation
  107. * Fix: pci_map_single and pci_unmap_single replaced
  108. *
  109. * Revision 1.29.2.10 2001/12/06 09:56:50 mlindner
  110. * Corrected some printk's
  111. *
  112. * Revision 1.29.2.9 2001/09/05 12:15:34 mlindner
  113. * Add: LBFO Changes
  114. * Fix: Counter Errors (Jumbo == to long errors)
  115. * Fix: Changed pAC->PciDev declaration
  116. * Fix: too short counters
  117. *
  118. * Revision 1.29.2.8 2001/06/25 12:10:44 mlindner
  119. * fix: ReceiveIrq() changed.
  120. *
  121. * Revision 1.29.2.7 2001/06/25 08:07:05 mlindner
  122. * fix: RLMT locking in ReceiveIrq() changed.
  123. *
  124. * Revision 1.29.2.6 2001/05/21 07:59:29 mlindner
  125. * fix: MTU init problems
  126. *
  127. * Revision 1.29.2.5 2001/05/08 11:25:08 mlindner
  128. * fix: removed VLAN error message
  129. *
  130. * Revision 1.29.2.4 2001/05/04 13:31:43 gklug
  131. * fix: do not handle eth_copy on bad fragments received.
  132. *
  133. * Revision 1.29.2.3 2001/04/23 08:06:43 mlindner
  134. * Fix: error handling
  135. *
  136. * Revision 1.29.2.2 2001/03/15 12:04:54 mlindner
  137. * Fixed memory problem
  138. *
  139. * Revision 1.29.2.1 2001/03/12 16:41:44 mlindner
  140. * add: procfs function
  141. * add: dual-net function
  142. * add: RLMT networks
  143. * add: extended PNMI features
  144. *
  145. * Kernel 2.4.x specific:
  146. * Revision 1.xx 2000/09/12 13:31:56 cgoos
  147. * Fixed missign "dev=NULL in skge_probe.
  148. * Added counting for jumbo frames (corrects error statistic).
  149. * Removed VLAN tag check (enables VLAN support).
  150. *
  151. * Kernel 2.2.x specific:
  152. * Revision 1.29 2000/02/21 13:31:56 cgoos
  153. * Fixed "unused" warning for UltraSPARC change.
  154. *
  155. * Partially kernel 2.2.x specific:
  156. * Revision 1.28 2000/02/21 10:32:36 cgoos
  157. * Added fixes for UltraSPARC.
  158. * Now printing RlmtMode and PrefPort setting at startup.
  159. * Changed XmitFrame return value.
  160. * Fixed rx checksum calculation for BIG ENDIAN systems.
  161. * Fixed rx jumbo frames counted as ierrors.
  162. *
  163. *
  164. * Revision 1.27 1999/11/25 09:06:28 cgoos
  165. * Changed base_addr to unsigned long.
  166. *
  167. * Revision 1.26 1999/11/22 13:29:16 cgoos
  168. * Changed license header to GPL.
  169. * Changes for inclusion in linux kernel (2.2.13).
  170. * Removed 2.0.x defines.
  171. * Changed SkGeProbe to skge_probe.
  172. * Added checks in SkGeIoctl.
  173. *
  174. * Revision 1.25 1999/10/07 14:47:52 cgoos
  175. * Changed 984x to 98xx.
  176. *
  177. * Revision 1.24 1999/09/30 07:21:01 cgoos
  178. * Removed SK_RLMT_SLOW_LOOKAHEAD option.
  179. * Giving spanning tree packets also to OS now.
  180. *
  181. * Revision 1.23 1999/09/29 07:36:50 cgoos
  182. * Changed assignment for IsBc/IsMc.
  183. *
  184. * Revision 1.22 1999/09/28 12:57:09 cgoos
  185. * Added CheckQueue also to Single-Port-ISR.
  186. *
  187. * Revision 1.21 1999/09/28 12:42:41 cgoos
  188. * Changed parameter strings for RlmtMode.
  189. *
  190. * Revision 1.20 1999/09/28 12:37:57 cgoos
  191. * Added CheckQueue for fast delivery of RLMT frames.
  192. *
  193. * Revision 1.19 1999/09/16 07:57:25 cgoos
  194. * Copperfield changes.
  195. *
  196. * Revision 1.18 1999/09/03 13:06:30 cgoos
  197. * Fixed RlmtMode=CheckSeg bug: wrong DEV_KFREE_SKB in RLMT_SEND caused
  198. * double allocated skb's.
  199. * FrameStat in ReceiveIrq was accessed via wrong Rxd.
  200. * Queue size for async. standby Tx queue was zero.
  201. * FillRxLimit of 0 could cause problems with ReQueue, changed to 1.
  202. * Removed debug output of checksum statistic.
  203. *
  204. * Revision 1.17 1999/08/11 13:55:27 cgoos
  205. * Transmit descriptor polling was not reenabled after SkGePortInit.
  206. *
  207. * Revision 1.16 1999/07/27 15:17:29 cgoos
  208. * Added some "\n" in output strings (removed while debuging...).
  209. *
  210. * Revision 1.15 1999/07/23 12:09:30 cgoos
  211. * Performance optimization, rx checksumming, large frame support.
  212. *
  213. * Revision 1.14 1999/07/14 11:26:27 cgoos
  214. * Removed Link LED settings (now in RLMT).
  215. * Added status output at NET UP.
  216. * Fixed SMP problems with Tx and SWITCH running in parallel.
  217. * Fixed return code problem at RLMT_SEND event.
  218. *
  219. * Revision 1.13 1999/04/07 10:11:42 cgoos
  220. * Fixed Single Port problems.
  221. * Fixed Multi-Adapter problems.
  222. * Always display startup string.
  223. *
  224. * Revision 1.12 1999/03/29 12:26:37 cgoos
  225. * Reversed locking to fine granularity.
  226. * Fixed skb double alloc problem (caused by incorrect xmit return code).
  227. * Enhanced function descriptions.
  228. *
  229. * Revision 1.11 1999/03/15 13:10:51 cgoos
  230. * Changed device identifier in output string to ethX.
  231. *
  232. * Revision 1.10 1999/03/15 12:12:34 cgoos
  233. * Changed copyright notice.
  234. *
  235. * Revision 1.9 1999/03/15 12:10:17 cgoos
  236. * Changed locking to one driver lock.
  237. * Added check of SK_AC-size (for consistency with library).
  238. *
  239. * Revision 1.8 1999/03/08 11:44:02 cgoos
  240. * Fixed missing dev->tbusy in SkGeXmit.
  241. * Changed large frame (jumbo) buffer number.
  242. * Added copying of short frames.
  243. *
  244. * Revision 1.7 1999/03/04 13:26:57 cgoos
  245. * Fixed spinlock calls for SMP.
  246. *
  247. * Revision 1.6 1999/03/02 09:53:51 cgoos
  248. * Added descriptor revertion for big endian machines.
  249. *
  250. * Revision 1.5 1999/03/01 08:50:59 cgoos
  251. * Fixed SkGeChangeMtu.
  252. * Fixed pci config space accesses.
  253. *
  254. * Revision 1.4 1999/02/18 15:48:44 cgoos
  255. * Corrected some printk's.
  256. *
  257. * Revision 1.3 1999/02/18 12:45:55 cgoos
  258. * Changed SK_MAX_CARD_PARAM to default 16
  259. *
  260. * Revision 1.2 1999/02/18 10:55:32 cgoos
  261. * Removed SkGeDrvTimeStamp function.
  262. * Printing "ethX:" before adapter type at adapter init.
  263. *
  264. *
  265. * 10-Feb-1999 cg Created, based on Linux' acenic.c, 3c59x.c and
  266. * SysKonnects GEnesis Solaris driver
  267. *
  268. ******************************************************************************/
  269. /******************************************************************************
  270. *
  271. * Possible compiler options (#define xxx / -Dxxx):
  272. *
  273. * debugging can be enable by changing SK_DEBUG_CHKMOD and
  274. * SK_DEBUG_CHKCAT in makefile (described there).
  275. *
  276. ******************************************************************************/
  277. /******************************************************************************
  278. *
  279. * Description:
  280. *
  281. * This is the main module of the Linux GE driver.
  282. *
  283. * All source files except skge.c, skdrv1st.h, skdrv2nd.h and sktypes.h
  284. * are part of SysKonnect's COMMON MODULES for the SK-98xx adapters.
  285. * Those are used for drivers on multiple OS', so some thing may seem
  286. * unnecessary complicated on Linux. Please do not try to 'clean up'
  287. * them without VERY good reasons, because this will make it more
  288. * difficult to keep the Linux driver in synchronisation with the
  289. * other versions.
  290. *
  291. * Include file hierarchy:
  292. *
  293. * <linux/module.h>
  294. *
  295. * "h/skdrv1st.h"
  296. * <linux/version.h>
  297. * <linux/types.h>
  298. * <linux/kernel.h>
  299. * <linux/string.h>
  300. * <linux/errno.h>
  301. * <linux/ioport.h>
  302. * <linux/slab.h>
  303. * <linux/interrupt.h>
  304. * <linux/pci.h>
  305. * <asm/byteorder.h>
  306. * <asm/bitops.h>
  307. * <asm/io.h>
  308. * <linux/netdevice.h>
  309. * <linux/etherdevice.h>
  310. * <linux/skbuff.h>
  311. * those three depending on kernel version used:
  312. * <linux/bios32.h>
  313. * <linux/init.h>
  314. * <asm/uaccess.h>
  315. * <net/checksum.h>
  316. *
  317. * "h/skerror.h"
  318. * "h/skdebug.h"
  319. * "h/sktypes.h"
  320. * "h/lm80.h"
  321. * "h/xmac_ii.h"
  322. *
  323. * "h/skdrv2nd.h"
  324. * "h/skqueue.h"
  325. * "h/skgehwt.h"
  326. * "h/sktimer.h"
  327. * "h/ski2c.h"
  328. * "h/skgepnmi.h"
  329. * "h/skvpd.h"
  330. * "h/skgehw.h"
  331. * "h/skgeinit.h"
  332. * "h/skaddr.h"
  333. * "h/skgesirq.h"
  334. * "h/skcsum.h"
  335. * "h/skrlmt.h"
  336. *
  337. ******************************************************************************/
  338. #include <config.h>
  339. #include "h/skversion.h"
  340. #if 0
  341. #include <linux/module.h>
  342. #include <linux/init.h>
  343. #include <linux/proc_fs.h>
  344. #endif
  345. #include "h/skdrv1st.h"
  346. #include "h/skdrv2nd.h"
  347. /* defines ******************************************************************/
  348. /* for debuging on x86 only */
  349. /* #define BREAKPOINT() asm(" int $3"); */
  350. /* use the scatter-gather functionality with sendfile() */
  351. #if 0
  352. #define SK_ZEROCOPY
  353. #endif
  354. /* use of a transmit complete interrupt */
  355. #define USE_TX_COMPLETE
  356. /* use interrupt moderation (for tx complete only) */
  357. #define USE_INT_MOD
  358. #define INTS_PER_SEC 1000
  359. /*
  360. * threshold for copying small receive frames
  361. * set to 0 to avoid copying, set to 9001 to copy all frames
  362. */
  363. #define SK_COPY_THRESHOLD 50
  364. /* number of adapters that can be configured via command line params */
  365. #define SK_MAX_CARD_PARAM 16
  366. /*
  367. * use those defines for a compile-in version of the driver instead
  368. * of command line parameters
  369. */
  370. /* #define LINK_SPEED_A {"Auto", } */
  371. /* #define LINK_SPEED_B {"Auto", } */
  372. /* #define AUTO_NEG_A {"Sense", } */
  373. /* #define AUTO_NEG_B {"Sense", } */
  374. /* #define DUP_CAP_A {"Both", } */
  375. /* #define DUP_CAP_B {"Both", } */
  376. /* #define FLOW_CTRL_A {"SymOrRem", } */
  377. /* #define FLOW_CTRL_B {"SymOrRem", } */
  378. /* #define ROLE_A {"Auto", } */
  379. /* #define ROLE_B {"Auto", } */
  380. /* #define PREF_PORT {"A", } */
  381. /* #define RLMT_MODE {"CheckLinkState", } */
  382. #define DEV_KFREE_SKB(skb) dev_kfree_skb(skb)
  383. #define DEV_KFREE_SKB_IRQ(skb) dev_kfree_skb_irq(skb)
  384. #define DEV_KFREE_SKB_ANY(skb) dev_kfree_skb_any(skb)
  385. /* function prototypes ******************************************************/
  386. static void FreeResources(struct SK_NET_DEVICE *dev);
  387. static int SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC);
  388. static SK_BOOL BoardAllocMem(SK_AC *pAC);
  389. static void BoardFreeMem(SK_AC *pAC);
  390. static void BoardInitMem(SK_AC *pAC);
  391. static void SetupRing(SK_AC*, void*, uintptr_t, RXD**, RXD**, RXD**,
  392. int*, SK_BOOL);
  393. #if 0
  394. static void SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs);
  395. static void SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs);
  396. static int SkGeOpen(struct SK_NET_DEVICE *dev);
  397. static int SkGeClose(struct SK_NET_DEVICE *dev);
  398. static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev);
  399. static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p);
  400. static void SkGeSetRxMode(struct SK_NET_DEVICE *dev);
  401. static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev);
  402. static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd);
  403. #else
  404. void SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs);
  405. void SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs);
  406. int SkGeOpen(struct SK_NET_DEVICE *dev);
  407. int SkGeClose(struct SK_NET_DEVICE *dev);
  408. int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev);
  409. #endif
  410. static void GetConfiguration(SK_AC*);
  411. static void ProductStr(SK_AC*);
  412. static int XmitFrame(SK_AC*, TX_PORT*, struct sk_buff*);
  413. static void FreeTxDescriptors(SK_AC*pAC, TX_PORT*);
  414. static void FillRxRing(SK_AC*, RX_PORT*);
  415. static SK_BOOL FillRxDescriptor(SK_AC*, RX_PORT*);
  416. #if 0
  417. static void ReceiveIrq(SK_AC*, RX_PORT*, SK_BOOL);
  418. #else
  419. void ReceiveIrq(SK_AC*, RX_PORT*, SK_BOOL);
  420. #endif
  421. static void ClearAndStartRx(SK_AC*, int);
  422. static void ClearTxIrq(SK_AC*, int, int);
  423. static void ClearRxRing(SK_AC*, RX_PORT*);
  424. static void ClearTxRing(SK_AC*, TX_PORT*);
  425. #if 0
  426. static void SetQueueSizes(SK_AC *pAC);
  427. static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int new_mtu);
  428. #endif
  429. static void PortReInitBmu(SK_AC*, int);
  430. #if 0
  431. static int SkGeIocMib(DEV_NET*, unsigned int, int);
  432. static int XmitFrameSG(SK_AC*, TX_PORT*, struct sk_buff*);
  433. #endif
  434. /*Extern */
  435. /* external Proc function */
  436. extern int proc_read(
  437. char *buffer,
  438. char **buffer_location,
  439. off_t offset,
  440. int buffer_length,
  441. int *eof,
  442. void *data);
  443. #ifdef DEBUG
  444. static void DumpMsg(struct sk_buff*, char*);
  445. static void DumpData(char*, int);
  446. static void DumpLong(char*, int);
  447. #endif
  448. void dump_frag( SK_U8 *data, int length);
  449. /* global variables *********************************************************/
  450. #if 0
  451. static const char *BootString = BOOT_STRING;
  452. #endif
  453. struct SK_NET_DEVICE *SkGeRootDev = NULL;
  454. static int probed __initdata = 0;
  455. /* local variables **********************************************************/
  456. static uintptr_t TxQueueAddr[SK_MAX_MACS][2] = {{0x680, 0x600},{0x780, 0x700}};
  457. static uintptr_t RxQueueAddr[SK_MAX_MACS] = {0x400, 0x480};
  458. /* local variables **********************************************************/
  459. const char SK_Root_Dir_entry[8];
  460. #if 0
  461. static struct proc_dir_entry *pSkRootDir;
  462. #endif
  463. static struct pci_device_id supported[] = {
  464. {PCI_VENDOR_ID_3COM, 0x1700},
  465. {PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_GE},
  466. {PCI_VENDOR_ID_SYSKONNECT, PCI_DEVICE_ID_SYSKONNECT_YU},
  467. {}
  468. };
  469. /*****************************************************************************
  470. *
  471. * skge_probe - find all SK-98xx adapters
  472. *
  473. * Description:
  474. * This function scans the PCI bus for SK-98xx adapters. Resources for
  475. * each adapter are allocated and the adapter is brought into Init 1
  476. * state.
  477. *
  478. * Returns:
  479. * 0, if everything is ok
  480. * !=0, on error
  481. */
  482. #if 0
  483. static int __init skge_probe (void)
  484. #else
  485. int skge_probe (struct eth_device ** ret_dev)
  486. #endif
  487. {
  488. #if 0
  489. int proc_root_initialized = 0;
  490. #endif
  491. int boards_found = 0;
  492. #if 0
  493. int vendor_flag = SK_FALSE;
  494. #endif
  495. SK_AC *pAC;
  496. DEV_NET *pNet = NULL;
  497. #if 0
  498. struct proc_dir_entry *pProcFile;
  499. struct pci_dev *pdev = NULL;
  500. unsigned long base_address;
  501. #else
  502. u32 base_address;
  503. #endif
  504. struct SK_NET_DEVICE *dev = NULL;
  505. #if 0
  506. SK_BOOL DeviceFound = SK_FALSE;
  507. #endif
  508. SK_BOOL BootStringCount = SK_FALSE;
  509. #if 1
  510. pci_dev_t devno;
  511. #endif
  512. if (probed)
  513. return -ENODEV;
  514. probed++;
  515. if (!pci_present()) /* is PCI support present? */
  516. return -ENODEV;
  517. #if 0
  518. while((pdev = pci_find_class(PCI_CLASS_NETWORK_ETHERNET << 8, pdev)))
  519. #else
  520. while((devno = pci_find_devices (supported, boards_found)) >= 0)
  521. #endif
  522. {
  523. dev = NULL;
  524. pNet = NULL;
  525. #if 0
  526. SK_PCI_ISCOMPLIANT(vendor_flag, pdev);
  527. if (!vendor_flag)
  528. continue;
  529. #endif
  530. /* if ((pdev->vendor != PCI_VENDOR_ID_SYSKONNECT) &&
  531. ((pdev->device != PCI_DEVICE_ID_SYSKONNECT_GE) ||
  532. (pdev->device != PCI_DEVICE_ID_SYSKONNECT_YU))){
  533. continue;
  534. }
  535. */
  536. #if 0
  537. /* Configure DMA attributes. */
  538. if (pci_set_dma_mask(pdev, (u64) 0xffffffffffffffff) &&
  539. pci_set_dma_mask(pdev, (u64) 0xffffffff))
  540. continue;
  541. #endif
  542. #if 0
  543. if ((dev = init_etherdev(dev, sizeof(DEV_NET))) == NULL) {
  544. printk(KERN_ERR "Unable to allocate etherdev "
  545. "structure!\n");
  546. break;
  547. }
  548. #else
  549. dev = malloc (sizeof *dev);
  550. memset(dev, 0, sizeof(*dev));
  551. dev->priv = malloc(sizeof(DEV_NET));
  552. #endif
  553. if (dev->priv == NULL) {
  554. printk(KERN_ERR "Unable to allocate adapter "
  555. "structure!\n");
  556. break;
  557. }
  558. pNet = dev->priv;
  559. pNet->pAC = kmalloc(sizeof(SK_AC), GFP_KERNEL);
  560. if (pNet->pAC == NULL){
  561. kfree(dev->priv);
  562. printk(KERN_ERR "Unable to allocate adapter "
  563. "structure!\n");
  564. break;
  565. }
  566. /* Print message */
  567. if (!BootStringCount) {
  568. /* set display flag to TRUE so that */
  569. /* we only display this string ONCE */
  570. BootStringCount = SK_TRUE;
  571. #ifdef SK98_INFO
  572. printk("%s\n", BootString);
  573. #endif
  574. }
  575. memset(pNet->pAC, 0, sizeof(SK_AC));
  576. pAC = pNet->pAC;
  577. #if 0
  578. pAC->PciDev = pdev;
  579. pAC->PciDevId = pdev->device;
  580. pAC->dev[0] = dev;
  581. pAC->dev[1] = dev;
  582. #else
  583. pAC->PciDev = devno;
  584. ret_dev[0] = pAC->dev[0] = dev;
  585. ret_dev[1] = pAC->dev[1] = dev;
  586. #endif
  587. sprintf(pAC->Name, "SysKonnect SK-98xx");
  588. pAC->CheckQueue = SK_FALSE;
  589. pNet->Mtu = 1500;
  590. pNet->Up = 0;
  591. #if 0
  592. dev->irq = pdev->irq;
  593. dev->open = &SkGeOpen;
  594. dev->stop = &SkGeClose;
  595. dev->hard_start_xmit = &SkGeXmit;
  596. dev->get_stats = &SkGeStats;
  597. dev->set_multicast_list = &SkGeSetRxMode;
  598. dev->set_mac_address = &SkGeSetMacAddr;
  599. dev->do_ioctl = &SkGeIoctl;
  600. dev->change_mtu = &SkGeChangeMtu;
  601. dev->flags &= ~IFF_RUNNING;
  602. #endif
  603. #ifdef SK_ZEROCOPY
  604. if (pAC->GIni.GIChipId == CHIP_ID_YUKON) {
  605. /* Use only if yukon hardware */
  606. /* SK and ZEROCOPY - fly baby... */
  607. dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
  608. }
  609. #endif
  610. #if 0
  611. /*
  612. * Dummy value.
  613. */
  614. dev->base_addr = 42;
  615. pci_set_master(pdev);
  616. pci_set_master(pdev);
  617. base_address = pci_resource_start (pdev, 0);
  618. #else
  619. pci_write_config_dword(devno,
  620. PCI_COMMAND,
  621. PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER);
  622. pci_read_config_dword (devno, PCI_BASE_ADDRESS_0,
  623. &base_address);
  624. #endif
  625. #ifdef SK_BIG_ENDIAN
  626. /*
  627. * On big endian machines, we use the adapter's aibility of
  628. * reading the descriptors as big endian.
  629. */
  630. {
  631. SK_U32 our2;
  632. SkPciReadCfgDWord(pAC, PCI_OUR_REG_2, &our2);
  633. our2 |= PCI_REV_DESC;
  634. SkPciWriteCfgDWord(pAC, PCI_OUR_REG_2, our2);
  635. }
  636. #endif
  637. /*
  638. * Remap the regs into kernel space.
  639. */
  640. #if 0
  641. pAC->IoBase = (char*)ioremap(base_address, 0x4000);
  642. #else
  643. pAC->IoBase = (char*)pci_mem_to_phys(devno, base_address);
  644. #endif
  645. if (!pAC->IoBase){
  646. printk(KERN_ERR "%s: Unable to map I/O register, "
  647. "SK 98xx No. %i will be disabled.\n",
  648. dev->name, boards_found);
  649. kfree(dev);
  650. break;
  651. }
  652. pAC->Index = boards_found;
  653. if (SkGeBoardInit(dev, pAC)) {
  654. FreeResources(dev);
  655. kfree(dev);
  656. continue;
  657. }
  658. #if 0
  659. memcpy((caddr_t) &dev->dev_addr,
  660. (caddr_t) &pAC->Addr.Net[0].CurrentMacAddress, 6);
  661. #else
  662. memcpy((caddr_t) &dev->enetaddr,
  663. (caddr_t) &pAC->Addr.Net[0].CurrentMacAddress, 6);
  664. #endif
  665. #if 0
  666. /* First adapter... Create proc and print message */
  667. if (!DeviceFound) {
  668. DeviceFound = SK_TRUE;
  669. SK_MEMCPY(&SK_Root_Dir_entry, BootString,
  670. sizeof(SK_Root_Dir_entry) - 1);
  671. /*Create proc (directory)*/
  672. if(!proc_root_initialized) {
  673. pSkRootDir = create_proc_entry(SK_Root_Dir_entry,
  674. S_IFDIR | S_IWUSR | S_IRUGO | S_IXUGO, proc_net);
  675. proc_root_initialized = 1;
  676. }
  677. pSkRootDir->owner = THIS_MODULE;
  678. }
  679. /* Create proc file */
  680. pProcFile = create_proc_entry(dev->name,
  681. S_IFREG | S_IXUSR | S_IWGRP | S_IROTH,
  682. pSkRootDir);
  683. pProcFile->read_proc = proc_read;
  684. pProcFile->write_proc = NULL;
  685. pProcFile->nlink = 1;
  686. pProcFile->size = sizeof(dev->name + 1);
  687. pProcFile->data = (void *)pProcFile;
  688. #endif
  689. pNet->PortNr = 0;
  690. pNet->NetNr = 0;
  691. #ifdef SK_ZEROCOPY
  692. if (pAC->GIni.GIChipId == CHIP_ID_YUKON) {
  693. /* SG and ZEROCOPY - fly baby... */
  694. dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
  695. }
  696. #endif
  697. boards_found++;
  698. /* More then one port found */
  699. if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
  700. #if 0
  701. if ((dev = init_etherdev(NULL, sizeof(DEV_NET))) == 0) {
  702. printk(KERN_ERR "Unable to allocate etherdev "
  703. "structure!\n");
  704. break;
  705. }
  706. #else
  707. dev = malloc (sizeof *dev);
  708. memset(dev, 0, sizeof(*dev));
  709. dev->priv = malloc(sizeof(DEV_NET));
  710. #endif
  711. pAC->dev[1] = dev;
  712. pNet = dev->priv;
  713. pNet->PortNr = 1;
  714. pNet->NetNr = 1;
  715. pNet->pAC = pAC;
  716. pNet->Mtu = 1500;
  717. pNet->Up = 0;
  718. #if 0
  719. dev->open = &SkGeOpen;
  720. dev->stop = &SkGeClose;
  721. dev->hard_start_xmit = &SkGeXmit;
  722. dev->get_stats = &SkGeStats;
  723. dev->set_multicast_list = &SkGeSetRxMode;
  724. dev->set_mac_address = &SkGeSetMacAddr;
  725. dev->do_ioctl = &SkGeIoctl;
  726. dev->change_mtu = &SkGeChangeMtu;
  727. dev->flags &= ~IFF_RUNNING;
  728. #endif
  729. #ifdef SK_ZEROCOPY
  730. if (pAC->GIni.GIChipId == CHIP_ID_YUKON) {
  731. /* SG and ZEROCOPY - fly baby... */
  732. dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
  733. }
  734. #endif
  735. #if 0
  736. pProcFile = create_proc_entry(dev->name,
  737. S_IFREG | S_IXUSR | S_IWGRP | S_IROTH,
  738. pSkRootDir);
  739. pProcFile->read_proc = proc_read;
  740. pProcFile->write_proc = NULL;
  741. pProcFile->nlink = 1;
  742. pProcFile->size = sizeof(dev->name + 1);
  743. pProcFile->data = (void *)pProcFile;
  744. #endif
  745. #if 0
  746. memcpy((caddr_t) &dev->dev_addr,
  747. (caddr_t) &pAC->Addr.Net[1].CurrentMacAddress, 6);
  748. #else
  749. memcpy((caddr_t) &dev->enetaddr,
  750. (caddr_t) &pAC->Addr.Net[1].CurrentMacAddress, 6);
  751. #endif
  752. printk("%s: %s\n", dev->name, pAC->DeviceStr);
  753. printk(" PrefPort:B RlmtMode:Dual Check Link State\n");
  754. }
  755. /* Save the hardware revision */
  756. pAC->HWRevision = (((pAC->GIni.GIPciHwRev >> 4) & 0x0F)*10) +
  757. (pAC->GIni.GIPciHwRev & 0x0F);
  758. /*
  759. * This is bollocks, but we need to tell the net-init
  760. * code that it shall go for the next device.
  761. */
  762. #if 0
  763. #ifndef MODULE
  764. dev->base_addr = 0;
  765. #endif
  766. #endif
  767. }
  768. /*
  769. * If we're at this point we're going through skge_probe() for
  770. * the first time. Return success (0) if we've initialized 1
  771. * or more boards. Otherwise, return failure (-ENODEV).
  772. */
  773. return boards_found;
  774. } /* skge_probe */
  775. /*****************************************************************************
  776. *
  777. * FreeResources - release resources allocated for adapter
  778. *
  779. * Description:
  780. * This function releases the IRQ, unmaps the IO and
  781. * frees the desriptor ring.
  782. *
  783. * Returns: N/A
  784. *
  785. */
  786. static void FreeResources(struct SK_NET_DEVICE *dev)
  787. {
  788. SK_U32 AllocFlag;
  789. DEV_NET *pNet;
  790. SK_AC *pAC;
  791. if (dev->priv) {
  792. pNet = (DEV_NET*) dev->priv;
  793. pAC = pNet->pAC;
  794. AllocFlag = pAC->AllocFlag;
  795. #if 0
  796. if (AllocFlag & SK_ALLOC_IRQ) {
  797. free_irq(dev->irq, dev);
  798. }
  799. if (pAC->IoBase) {
  800. iounmap(pAC->IoBase);
  801. }
  802. #endif
  803. if (pAC->pDescrMem) {
  804. BoardFreeMem(pAC);
  805. }
  806. }
  807. } /* FreeResources */
  808. #if 0
  809. MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
  810. MODULE_DESCRIPTION("SysKonnect SK-NET Gigabit Ethernet SK-98xx driver");
  811. MODULE_LICENSE("GPL");
  812. MODULE_PARM(Speed_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
  813. MODULE_PARM(Speed_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
  814. MODULE_PARM(AutoNeg_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
  815. MODULE_PARM(AutoNeg_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
  816. MODULE_PARM(DupCap_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
  817. MODULE_PARM(DupCap_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
  818. MODULE_PARM(FlowCtrl_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
  819. MODULE_PARM(FlowCtrl_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
  820. MODULE_PARM(Role_A, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
  821. MODULE_PARM(Role_B, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
  822. MODULE_PARM(PrefPort, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
  823. MODULE_PARM(RlmtMode, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "s");
  824. /* not used, just there because every driver should have them: */
  825. MODULE_PARM(options, "1-" __MODULE_STRING(SK_MAX_CARD_PARAM) "i");
  826. MODULE_PARM(debug, "i");
  827. #endif
  828. #ifdef LINK_SPEED_A
  829. static char *Speed_A[SK_MAX_CARD_PARAM] = LINK_SPEED_A;
  830. #else
  831. static char *Speed_A[SK_MAX_CARD_PARAM] = {"", };
  832. #endif
  833. #ifdef LINK_SPEED_B
  834. static char *Speed_B[SK_MAX_CARD_PARAM] = LINK_SPEED_B;
  835. #else
  836. static char *Speed_B[SK_MAX_CARD_PARAM] = {"", };
  837. #endif
  838. #ifdef AUTO_NEG_A
  839. static char *AutoNeg_A[SK_MAX_CARD_PARAM] = AUTO_NEG_A;
  840. #else
  841. static char *AutoNeg_A[SK_MAX_CARD_PARAM] = {"", };
  842. #endif
  843. #ifdef DUP_CAP_A
  844. static char *DupCap_A[SK_MAX_CARD_PARAM] = DUP_CAP_A;
  845. #else
  846. static char *DupCap_A[SK_MAX_CARD_PARAM] = {"", };
  847. #endif
  848. #ifdef FLOW_CTRL_A
  849. static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = FLOW_CTRL_A;
  850. #else
  851. static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = {"", };
  852. #endif
  853. #ifdef ROLE_A
  854. static char *Role_A[SK_MAX_CARD_PARAM] = ROLE_A;
  855. #else
  856. static char *Role_A[SK_MAX_CARD_PARAM] = {"", };
  857. #endif
  858. #ifdef AUTO_NEG_B
  859. static char *AutoNeg_B[SK_MAX_CARD_PARAM] = AUTO_NEG_B;
  860. #else
  861. static char *AutoNeg_B[SK_MAX_CARD_PARAM] = {"", };
  862. #endif
  863. #ifdef DUP_CAP_B
  864. static char *DupCap_B[SK_MAX_CARD_PARAM] = DUP_CAP_B;
  865. #else
  866. static char *DupCap_B[SK_MAX_CARD_PARAM] = {"", };
  867. #endif
  868. #ifdef FLOW_CTRL_B
  869. static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = FLOW_CTRL_B;
  870. #else
  871. static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = {"", };
  872. #endif
  873. #ifdef ROLE_B
  874. static char *Role_B[SK_MAX_CARD_PARAM] = ROLE_B;
  875. #else
  876. static char *Role_B[SK_MAX_CARD_PARAM] = {"", };
  877. #endif
  878. #ifdef PREF_PORT
  879. static char *PrefPort[SK_MAX_CARD_PARAM] = PREF_PORT;
  880. #else
  881. static char *PrefPort[SK_MAX_CARD_PARAM] = {"", };
  882. #endif
  883. #ifdef RLMT_MODE
  884. static char *RlmtMode[SK_MAX_CARD_PARAM] = RLMT_MODE;
  885. #else
  886. static char *RlmtMode[SK_MAX_CARD_PARAM] = {"", };
  887. #endif
  888. #if 0
  889. static int debug = 0; /* not used */
  890. static int options[SK_MAX_CARD_PARAM] = {0, }; /* not used */
  891. /*****************************************************************************
  892. *
  893. * skge_init_module - module initialization function
  894. *
  895. * Description:
  896. * Very simple, only call skge_probe and return approriate result.
  897. *
  898. * Returns:
  899. * 0, if everything is ok
  900. * !=0, on error
  901. */
  902. static int __init skge_init_module(void)
  903. {
  904. int cards;
  905. SkGeRootDev = NULL;
  906. /* just to avoid warnings ... */
  907. debug = 0;
  908. options[0] = 0;
  909. cards = skge_probe();
  910. if (cards == 0) {
  911. printk("sk98lin: No adapter found.\n");
  912. }
  913. return cards ? 0 : -ENODEV;
  914. } /* skge_init_module */
  915. /*****************************************************************************
  916. *
  917. * skge_cleanup_module - module unload function
  918. *
  919. * Description:
  920. * Disable adapter if it is still running, free resources,
  921. * free device struct.
  922. *
  923. * Returns: N/A
  924. */
  925. static void __exit skge_cleanup_module(void)
  926. {
  927. DEV_NET *pNet;
  928. SK_AC *pAC;
  929. struct SK_NET_DEVICE *next;
  930. unsigned long Flags;
  931. SK_EVPARA EvPara;
  932. while (SkGeRootDev) {
  933. pNet = (DEV_NET*) SkGeRootDev->priv;
  934. pAC = pNet->pAC;
  935. next = pAC->Next;
  936. netif_stop_queue(SkGeRootDev);
  937. SkGeYellowLED(pAC, pAC->IoBase, 0);
  938. if(pAC->BoardLevel == 2) {
  939. /* board is still alive */
  940. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  941. EvPara.Para32[0] = 0;
  942. EvPara.Para32[1] = -1;
  943. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
  944. EvPara.Para32[0] = 1;
  945. EvPara.Para32[1] = -1;
  946. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
  947. SkEventDispatcher(pAC, pAC->IoBase);
  948. /* disable interrupts */
  949. SK_OUT32(pAC->IoBase, B0_IMSK, 0);
  950. SkGeDeInit(pAC, pAC->IoBase);
  951. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  952. pAC->BoardLevel = 0;
  953. /* We do NOT check here, if IRQ was pending, of course*/
  954. }
  955. if(pAC->BoardLevel == 1) {
  956. /* board is still alive */
  957. SkGeDeInit(pAC, pAC->IoBase);
  958. pAC->BoardLevel = 0;
  959. }
  960. if ((pAC->GIni.GIMacsFound == 2) && pAC->RlmtNets == 2){
  961. unregister_netdev(pAC->dev[1]);
  962. kfree(pAC->dev[1]);
  963. }
  964. FreeResources(SkGeRootDev);
  965. SkGeRootDev->get_stats = NULL;
  966. /*
  967. * otherwise unregister_netdev calls get_stats with
  968. * invalid IO ... :-(
  969. */
  970. unregister_netdev(SkGeRootDev);
  971. kfree(SkGeRootDev);
  972. kfree(pAC);
  973. SkGeRootDev = next;
  974. }
  975. /* clear proc-dir */
  976. remove_proc_entry(pSkRootDir->name, proc_net);
  977. } /* skge_cleanup_module */
  978. module_init(skge_init_module);
  979. module_exit(skge_cleanup_module);
  980. #endif
  981. /*****************************************************************************
  982. *
  983. * SkGeBoardInit - do level 0 and 1 initialization
  984. *
  985. * Description:
  986. * This function prepares the board hardware for running. The desriptor
  987. * ring is set up, the IRQ is allocated and the configuration settings
  988. * are examined.
  989. *
  990. * Returns:
  991. * 0, if everything is ok
  992. * !=0, on error
  993. */
  994. static int __init SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC)
  995. {
  996. short i;
  997. unsigned long Flags;
  998. char *DescrString = "sk98lin: Driver for Linux"; /* this is given to PNMI */
  999. char *VerStr = VER_STRING;
  1000. #if 0
  1001. int Ret; /* return code of request_irq */
  1002. #endif
  1003. SK_BOOL DualNet;
  1004. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  1005. ("IoBase: %08lX\n", (unsigned long)pAC->IoBase));
  1006. for (i=0; i<SK_MAX_MACS; i++) {
  1007. pAC->TxPort[i][0].HwAddr = pAC->IoBase + TxQueueAddr[i][0];
  1008. pAC->TxPort[i][0].PortIndex = i;
  1009. pAC->RxPort[i].HwAddr = pAC->IoBase + RxQueueAddr[i];
  1010. pAC->RxPort[i].PortIndex = i;
  1011. }
  1012. /* Initialize the mutexes */
  1013. for (i=0; i<SK_MAX_MACS; i++) {
  1014. spin_lock_init(&pAC->TxPort[i][0].TxDesRingLock);
  1015. spin_lock_init(&pAC->RxPort[i].RxDesRingLock);
  1016. }
  1017. spin_lock_init(&pAC->SlowPathLock);
  1018. /* level 0 init common modules here */
  1019. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  1020. /* Does a RESET on board ...*/
  1021. if (SkGeInit(pAC, pAC->IoBase, 0) != 0) {
  1022. printk("HWInit (0) failed.\n");
  1023. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  1024. return(-EAGAIN);
  1025. }
  1026. SkI2cInit( pAC, pAC->IoBase, 0);
  1027. SkEventInit(pAC, pAC->IoBase, 0);
  1028. SkPnmiInit( pAC, pAC->IoBase, 0);
  1029. SkAddrInit( pAC, pAC->IoBase, 0);
  1030. SkRlmtInit( pAC, pAC->IoBase, 0);
  1031. SkTimerInit(pAC, pAC->IoBase, 0);
  1032. pAC->BoardLevel = 0;
  1033. pAC->RxBufSize = ETH_BUF_SIZE;
  1034. SK_PNMI_SET_DRIVER_DESCR(pAC, DescrString);
  1035. SK_PNMI_SET_DRIVER_VER(pAC, VerStr);
  1036. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  1037. /* level 1 init common modules here (HW init) */
  1038. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  1039. if (SkGeInit(pAC, pAC->IoBase, 1) != 0) {
  1040. printk("HWInit (1) failed.\n");
  1041. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  1042. return(-EAGAIN);
  1043. }
  1044. SkI2cInit( pAC, pAC->IoBase, 1);
  1045. SkEventInit(pAC, pAC->IoBase, 1);
  1046. SkPnmiInit( pAC, pAC->IoBase, 1);
  1047. SkAddrInit( pAC, pAC->IoBase, 1);
  1048. SkRlmtInit( pAC, pAC->IoBase, 1);
  1049. SkTimerInit(pAC, pAC->IoBase, 1);
  1050. GetConfiguration(pAC);
  1051. if (pAC->RlmtNets == 2) {
  1052. pAC->GIni.GIPortUsage = SK_MUL_LINK;
  1053. }
  1054. pAC->BoardLevel = 1;
  1055. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  1056. #if 0
  1057. if (pAC->GIni.GIMacsFound == 2) {
  1058. Ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
  1059. } else if (pAC->GIni.GIMacsFound == 1) {
  1060. Ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ,
  1061. pAC->Name, dev);
  1062. } else {
  1063. printk(KERN_WARNING "%s: Illegal number of ports: %d\n",
  1064. dev->name, pAC->GIni.GIMacsFound);
  1065. return -EAGAIN;
  1066. }
  1067. if (Ret) {
  1068. printk(KERN_WARNING "%s: Requested IRQ %d is busy.\n",
  1069. dev->name, dev->irq);
  1070. return -EAGAIN;
  1071. }
  1072. #endif
  1073. pAC->AllocFlag |= SK_ALLOC_IRQ;
  1074. /* Alloc memory for this board (Mem for RxD/TxD) : */
  1075. if(!BoardAllocMem(pAC)) {
  1076. printk("No memory for descriptor rings.\n");
  1077. return(-EAGAIN);
  1078. }
  1079. SkCsSetReceiveFlags(pAC,
  1080. SKCS_PROTO_IP | SKCS_PROTO_TCP | SKCS_PROTO_UDP,
  1081. &pAC->CsOfs1, &pAC->CsOfs2, 0);
  1082. pAC->CsOfs = (pAC->CsOfs2 << 16) | pAC->CsOfs1;
  1083. BoardInitMem(pAC);
  1084. #if 0
  1085. SetQueueSizes(pAC);
  1086. #else
  1087. /* tschilling: New common function with minimum size check. */
  1088. DualNet = SK_FALSE;
  1089. if (pAC->RlmtNets == 2) {
  1090. DualNet = SK_TRUE;
  1091. }
  1092. if (SkGeInitAssignRamToQueues(
  1093. pAC,
  1094. pAC->ActivePort,
  1095. DualNet)) {
  1096. BoardFreeMem(pAC);
  1097. printk("SkGeInitAssignRamToQueues failed.\n");
  1098. return(-EAGAIN);
  1099. }
  1100. #endif
  1101. /* Print adapter specific string from vpd */
  1102. ProductStr(pAC);
  1103. #ifdef SK98_INFO
  1104. printk("%s: %s\n", dev->name, pAC->DeviceStr);
  1105. /* Print configuration settings */
  1106. printk(" PrefPort:%c RlmtMode:%s\n",
  1107. 'A' + pAC->Rlmt.Net[0].Port[pAC->Rlmt.Net[0].PrefPort]->PortNumber,
  1108. (pAC->RlmtMode==0) ? "Check Link State" :
  1109. ((pAC->RlmtMode==1) ? "Check Link State" :
  1110. ((pAC->RlmtMode==3) ? "Check Local Port" :
  1111. ((pAC->RlmtMode==7) ? "Check Segmentation" :
  1112. ((pAC->RlmtMode==17) ? "Dual Check Link State" :"Error")))));
  1113. #endif
  1114. SkGeYellowLED(pAC, pAC->IoBase, 1);
  1115. /*
  1116. * Register the device here
  1117. */
  1118. pAC->Next = SkGeRootDev;
  1119. SkGeRootDev = dev;
  1120. return (0);
  1121. } /* SkGeBoardInit */
  1122. /*****************************************************************************
  1123. *
  1124. * BoardAllocMem - allocate the memory for the descriptor rings
  1125. *
  1126. * Description:
  1127. * This function allocates the memory for all descriptor rings.
  1128. * Each ring is aligned for the desriptor alignment and no ring
  1129. * has a 4 GByte boundary in it (because the upper 32 bit must
  1130. * be constant for all descriptiors in one rings).
  1131. *
  1132. * Returns:
  1133. * SK_TRUE, if all memory could be allocated
  1134. * SK_FALSE, if not
  1135. */
  1136. static SK_BOOL BoardAllocMem(
  1137. SK_AC *pAC)
  1138. {
  1139. caddr_t pDescrMem; /* pointer to descriptor memory area */
  1140. size_t AllocLength; /* length of complete descriptor area */
  1141. int i; /* loop counter */
  1142. unsigned long BusAddr;
  1143. /* rings plus one for alignment (do not cross 4 GB boundary) */
  1144. /* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
  1145. #if (BITS_PER_LONG == 32)
  1146. AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
  1147. #else
  1148. AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
  1149. + RX_RING_SIZE + 8;
  1150. #endif
  1151. pDescrMem = pci_alloc_consistent(pAC->PciDev, AllocLength,
  1152. &pAC->pDescrMemDMA);
  1153. if (pDescrMem == NULL) {
  1154. return (SK_FALSE);
  1155. }
  1156. pAC->pDescrMem = pDescrMem;
  1157. BusAddr = (unsigned long) pAC->pDescrMemDMA;
  1158. /* Descriptors need 8 byte alignment, and this is ensured
  1159. * by pci_alloc_consistent.
  1160. */
  1161. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  1162. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
  1163. ("TX%d/A: pDescrMem: %lX, PhysDescrMem: %lX\n",
  1164. i, (unsigned long) pDescrMem,
  1165. BusAddr));
  1166. pAC->TxPort[i][0].pTxDescrRing = pDescrMem;
  1167. pAC->TxPort[i][0].VTxDescrRing = BusAddr;
  1168. pDescrMem += TX_RING_SIZE;
  1169. BusAddr += TX_RING_SIZE;
  1170. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
  1171. ("RX%d: pDescrMem: %lX, PhysDescrMem: %lX\n",
  1172. i, (unsigned long) pDescrMem,
  1173. (unsigned long)BusAddr));
  1174. pAC->RxPort[i].pRxDescrRing = pDescrMem;
  1175. pAC->RxPort[i].VRxDescrRing = BusAddr;
  1176. pDescrMem += RX_RING_SIZE;
  1177. BusAddr += RX_RING_SIZE;
  1178. } /* for */
  1179. return (SK_TRUE);
  1180. } /* BoardAllocMem */
  1181. /****************************************************************************
  1182. *
  1183. * BoardFreeMem - reverse of BoardAllocMem
  1184. *
  1185. * Description:
  1186. * Free all memory allocated in BoardAllocMem: adapter context,
  1187. * descriptor rings, locks.
  1188. *
  1189. * Returns: N/A
  1190. */
  1191. static void BoardFreeMem(
  1192. SK_AC *pAC)
  1193. {
  1194. size_t AllocLength; /* length of complete descriptor area */
  1195. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  1196. ("BoardFreeMem\n"));
  1197. #if (BITS_PER_LONG == 32)
  1198. AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
  1199. #else
  1200. AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
  1201. + RX_RING_SIZE + 8;
  1202. #endif
  1203. pci_free_consistent(pAC->PciDev, AllocLength,
  1204. pAC->pDescrMem, pAC->pDescrMemDMA);
  1205. pAC->pDescrMem = NULL;
  1206. } /* BoardFreeMem */
  1207. /*****************************************************************************
  1208. *
  1209. * BoardInitMem - initiate the descriptor rings
  1210. *
  1211. * Description:
  1212. * This function sets the descriptor rings up in memory.
  1213. * The adapter is initialized with the descriptor start addresses.
  1214. *
  1215. * Returns: N/A
  1216. */
  1217. static void BoardInitMem(
  1218. SK_AC *pAC) /* pointer to adapter context */
  1219. {
  1220. int i; /* loop counter */
  1221. int RxDescrSize; /* the size of a rx descriptor rounded up to alignment*/
  1222. int TxDescrSize; /* the size of a tx descriptor rounded up to alignment*/
  1223. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  1224. ("BoardInitMem\n"));
  1225. RxDescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
  1226. pAC->RxDescrPerRing = RX_RING_SIZE / RxDescrSize;
  1227. TxDescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
  1228. pAC->TxDescrPerRing = TX_RING_SIZE / RxDescrSize;
  1229. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  1230. TXD **txd_head, **txd_tail, **txd_prev;
  1231. txd_head = &pAC->TxPort[i][0].pTxdRingHead;
  1232. txd_tail = &pAC->TxPort[i][0].pTxdRingTail;
  1233. txd_prev = &pAC->TxPort[i][0].pTxdRingPrev;
  1234. SetupRing(
  1235. pAC,
  1236. pAC->TxPort[i][0].pTxDescrRing,
  1237. pAC->TxPort[i][0].VTxDescrRing,
  1238. (RXD**)txd_head,
  1239. (RXD**)txd_tail,
  1240. (RXD**)txd_prev,
  1241. &pAC->TxPort[i][0].TxdRingFree,
  1242. SK_TRUE);
  1243. SetupRing(
  1244. pAC,
  1245. pAC->RxPort[i].pRxDescrRing,
  1246. pAC->RxPort[i].VRxDescrRing,
  1247. &pAC->RxPort[i].pRxdRingHead,
  1248. &pAC->RxPort[i].pRxdRingTail,
  1249. &pAC->RxPort[i].pRxdRingPrev,
  1250. &pAC->RxPort[i].RxdRingFree,
  1251. SK_FALSE);
  1252. }
  1253. } /* BoardInitMem */
  1254. /*****************************************************************************
  1255. *
  1256. * SetupRing - create one descriptor ring
  1257. *
  1258. * Description:
  1259. * This function creates one descriptor ring in the given memory area.
  1260. * The head, tail and number of free descriptors in the ring are set.
  1261. *
  1262. * Returns:
  1263. * none
  1264. */
  1265. static void SetupRing(
  1266. SK_AC *pAC,
  1267. void *pMemArea, /* a pointer to the memory area for the ring */
  1268. uintptr_t VMemArea, /* the virtual bus address of the memory area */
  1269. RXD **ppRingHead, /* address where the head should be written */
  1270. RXD **ppRingTail, /* address where the tail should be written */
  1271. RXD **ppRingPrev, /* address where the tail should be written */
  1272. int *pRingFree, /* address where the # of free descr. goes */
  1273. SK_BOOL IsTx) /* flag: is this a tx ring */
  1274. {
  1275. int i; /* loop counter */
  1276. int DescrSize; /* the size of a descriptor rounded up to alignment*/
  1277. int DescrNum; /* number of descriptors per ring */
  1278. RXD *pDescr; /* pointer to a descriptor (receive or transmit) */
  1279. RXD *pNextDescr; /* pointer to the next descriptor */
  1280. RXD *pPrevDescr; /* pointer to the previous descriptor */
  1281. uintptr_t VNextDescr; /* the virtual bus address of the next descriptor */
  1282. if (IsTx == SK_TRUE) {
  1283. DescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) *
  1284. DESCR_ALIGN;
  1285. DescrNum = TX_RING_SIZE / DescrSize;
  1286. } else {
  1287. DescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) *
  1288. DESCR_ALIGN;
  1289. DescrNum = RX_RING_SIZE / DescrSize;
  1290. }
  1291. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
  1292. ("Descriptor size: %d Descriptor Number: %d\n",
  1293. DescrSize,DescrNum));
  1294. pDescr = (RXD*) pMemArea;
  1295. pPrevDescr = NULL;
  1296. pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
  1297. VNextDescr = VMemArea + DescrSize;
  1298. for(i=0; i<DescrNum; i++) {
  1299. /* set the pointers right */
  1300. pDescr->VNextRxd = VNextDescr & 0xffffffffULL;
  1301. pDescr->pNextRxd = pNextDescr;
  1302. pDescr->TcpSumStarts = pAC->CsOfs;
  1303. /* advance one step */
  1304. pPrevDescr = pDescr;
  1305. pDescr = pNextDescr;
  1306. pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
  1307. VNextDescr += DescrSize;
  1308. }
  1309. pPrevDescr->pNextRxd = (RXD*) pMemArea;
  1310. pPrevDescr->VNextRxd = VMemArea;
  1311. pDescr = (RXD*) pMemArea;
  1312. *ppRingHead = (RXD*) pMemArea;
  1313. *ppRingTail = *ppRingHead;
  1314. *ppRingPrev = pPrevDescr;
  1315. *pRingFree = DescrNum;
  1316. } /* SetupRing */
  1317. /*****************************************************************************
  1318. *
  1319. * PortReInitBmu - re-initiate the descriptor rings for one port
  1320. *
  1321. * Description:
  1322. * This function reinitializes the descriptor rings of one port
  1323. * in memory. The port must be stopped before.
  1324. * The HW is initialized with the descriptor start addresses.
  1325. *
  1326. * Returns:
  1327. * none
  1328. */
  1329. static void PortReInitBmu(
  1330. SK_AC *pAC, /* pointer to adapter context */
  1331. int PortIndex) /* index of the port for which to re-init */
  1332. {
  1333. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  1334. ("PortReInitBmu "));
  1335. /* set address of first descriptor of ring in BMU */
  1336. SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+
  1337. TX_Q_CUR_DESCR_LOW,
  1338. (uint32_t)(((caddr_t)
  1339. (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
  1340. pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
  1341. pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) &
  1342. 0xFFFFFFFF));
  1343. SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+
  1344. TX_Q_DESCR_HIGH,
  1345. (uint32_t)(((caddr_t)
  1346. (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
  1347. pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
  1348. pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) >> 32));
  1349. SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+RX_Q_CUR_DESCR_LOW,
  1350. (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
  1351. pAC->RxPort[PortIndex].pRxDescrRing +
  1352. pAC->RxPort[PortIndex].VRxDescrRing) & 0xFFFFFFFF));
  1353. SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+RX_Q_DESCR_HIGH,
  1354. (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
  1355. pAC->RxPort[PortIndex].pRxDescrRing +
  1356. pAC->RxPort[PortIndex].VRxDescrRing) >> 32));
  1357. } /* PortReInitBmu */
  1358. /****************************************************************************
  1359. *
  1360. * SkGeIsr - handle adapter interrupts
  1361. *
  1362. * Description:
  1363. * The interrupt routine is called when the network adapter
  1364. * generates an interrupt. It may also be called if another device
  1365. * shares this interrupt vector with the driver.
  1366. *
  1367. * Returns: N/A
  1368. *
  1369. */
  1370. #if 0
  1371. static void SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs)
  1372. #else
  1373. void SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs)
  1374. #endif
  1375. {
  1376. struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
  1377. DEV_NET *pNet;
  1378. SK_AC *pAC;
  1379. SK_U32 IntSrc; /* interrupts source register contents */
  1380. pNet = (DEV_NET*) dev->priv;
  1381. pAC = pNet->pAC;
  1382. /*
  1383. * Check and process if its our interrupt
  1384. */
  1385. SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
  1386. if (IntSrc == 0) {
  1387. return;
  1388. }
  1389. while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
  1390. #if 0 /* software irq currently not used */
  1391. if (IntSrc & IRQ_SW) {
  1392. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1393. SK_DBGCAT_DRV_INT_SRC,
  1394. ("Software IRQ\n"));
  1395. }
  1396. #endif
  1397. if (IntSrc & IRQ_EOF_RX1) {
  1398. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1399. SK_DBGCAT_DRV_INT_SRC,
  1400. ("EOF RX1 IRQ\n"));
  1401. ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
  1402. SK_PNMI_CNT_RX_INTR(pAC, 0);
  1403. }
  1404. if (IntSrc & IRQ_EOF_RX2) {
  1405. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1406. SK_DBGCAT_DRV_INT_SRC,
  1407. ("EOF RX2 IRQ\n"));
  1408. ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
  1409. SK_PNMI_CNT_RX_INTR(pAC, 1);
  1410. }
  1411. #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
  1412. if (IntSrc & IRQ_EOF_AS_TX1) {
  1413. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1414. SK_DBGCAT_DRV_INT_SRC,
  1415. ("EOF AS TX1 IRQ\n"));
  1416. SK_PNMI_CNT_TX_INTR(pAC, 0);
  1417. spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
  1418. FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
  1419. spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
  1420. }
  1421. if (IntSrc & IRQ_EOF_AS_TX2) {
  1422. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1423. SK_DBGCAT_DRV_INT_SRC,
  1424. ("EOF AS TX2 IRQ\n"));
  1425. SK_PNMI_CNT_TX_INTR(pAC, 1);
  1426. spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
  1427. FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
  1428. spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
  1429. }
  1430. #if 0 /* only if sync. queues used */
  1431. if (IntSrc & IRQ_EOF_SY_TX1) {
  1432. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1433. SK_DBGCAT_DRV_INT_SRC,
  1434. ("EOF SY TX1 IRQ\n"));
  1435. SK_PNMI_CNT_TX_INTR(pAC, 1);
  1436. spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
  1437. FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
  1438. spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
  1439. ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
  1440. }
  1441. if (IntSrc & IRQ_EOF_SY_TX2) {
  1442. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1443. SK_DBGCAT_DRV_INT_SRC,
  1444. ("EOF SY TX2 IRQ\n"));
  1445. SK_PNMI_CNT_TX_INTR(pAC, 1);
  1446. spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
  1447. FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
  1448. spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
  1449. ClearTxIrq(pAC, 1, TX_PRIO_HIGH);
  1450. }
  1451. #endif
  1452. #endif
  1453. /* do all IO at once */
  1454. if (IntSrc & IRQ_EOF_RX1)
  1455. ClearAndStartRx(pAC, 0);
  1456. if (IntSrc & IRQ_EOF_RX2)
  1457. ClearAndStartRx(pAC, 1);
  1458. #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
  1459. if (IntSrc & IRQ_EOF_AS_TX1)
  1460. ClearTxIrq(pAC, 0, TX_PRIO_LOW);
  1461. if (IntSrc & IRQ_EOF_AS_TX2)
  1462. ClearTxIrq(pAC, 1, TX_PRIO_LOW);
  1463. #endif
  1464. SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
  1465. } /* while (IntSrc & IRQ_MASK != 0) */
  1466. if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
  1467. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
  1468. ("SPECIAL IRQ DP-Cards => %x\n", IntSrc));
  1469. pAC->CheckQueue = SK_FALSE;
  1470. spin_lock(&pAC->SlowPathLock);
  1471. if (IntSrc & SPECIAL_IRQS)
  1472. SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
  1473. SkEventDispatcher(pAC, pAC->IoBase);
  1474. spin_unlock(&pAC->SlowPathLock);
  1475. }
  1476. /*
  1477. * do it all again is case we cleared an interrupt that
  1478. * came in after handling the ring (OUTs may be delayed
  1479. * in hardware buffers, but are through after IN)
  1480. */
  1481. ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
  1482. ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
  1483. if (pAC->CheckQueue) {
  1484. pAC->CheckQueue = SK_FALSE;
  1485. spin_lock(&pAC->SlowPathLock);
  1486. SkEventDispatcher(pAC, pAC->IoBase);
  1487. spin_unlock(&pAC->SlowPathLock);
  1488. }
  1489. /* IRQ is processed - Enable IRQs again*/
  1490. SK_OUT32(pAC->IoBase, B0_IMSK, IRQ_MASK);
  1491. return;
  1492. } /* SkGeIsr */
  1493. /****************************************************************************
  1494. *
  1495. * SkGeIsrOnePort - handle adapter interrupts for single port adapter
  1496. *
  1497. * Description:
  1498. * The interrupt routine is called when the network adapter
  1499. * generates an interrupt. It may also be called if another device
  1500. * shares this interrupt vector with the driver.
  1501. * This is the same as above, but handles only one port.
  1502. *
  1503. * Returns: N/A
  1504. *
  1505. */
  1506. #if 0
  1507. static void SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs)
  1508. #else
  1509. void SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs)
  1510. #endif
  1511. {
  1512. struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
  1513. DEV_NET *pNet;
  1514. SK_AC *pAC;
  1515. SK_U32 IntSrc; /* interrupts source register contents */
  1516. pNet = (DEV_NET*) dev->priv;
  1517. pAC = pNet->pAC;
  1518. /*
  1519. * Check and process if its our interrupt
  1520. */
  1521. SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
  1522. if (IntSrc == 0) {
  1523. return;
  1524. }
  1525. while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
  1526. #if 0 /* software irq currently not used */
  1527. if (IntSrc & IRQ_SW) {
  1528. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1529. SK_DBGCAT_DRV_INT_SRC,
  1530. ("Software IRQ\n"));
  1531. }
  1532. #endif
  1533. if (IntSrc & IRQ_EOF_RX1) {
  1534. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1535. SK_DBGCAT_DRV_INT_SRC,
  1536. ("EOF RX1 IRQ\n"));
  1537. ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
  1538. SK_PNMI_CNT_RX_INTR(pAC, 0);
  1539. }
  1540. #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
  1541. if (IntSrc & IRQ_EOF_AS_TX1) {
  1542. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1543. SK_DBGCAT_DRV_INT_SRC,
  1544. ("EOF AS TX1 IRQ\n"));
  1545. SK_PNMI_CNT_TX_INTR(pAC, 0);
  1546. spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
  1547. FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
  1548. spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
  1549. }
  1550. #if 0 /* only if sync. queues used */
  1551. if (IntSrc & IRQ_EOF_SY_TX1) {
  1552. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1553. SK_DBGCAT_DRV_INT_SRC,
  1554. ("EOF SY TX1 IRQ\n"));
  1555. SK_PNMI_CNT_TX_INTR(pAC, 0);
  1556. spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
  1557. FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
  1558. spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
  1559. ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
  1560. }
  1561. #endif
  1562. #endif
  1563. /* do all IO at once */
  1564. if (IntSrc & IRQ_EOF_RX1)
  1565. ClearAndStartRx(pAC, 0);
  1566. #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
  1567. if (IntSrc & IRQ_EOF_AS_TX1)
  1568. ClearTxIrq(pAC, 0, TX_PRIO_LOW);
  1569. #endif
  1570. SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
  1571. } /* while (IntSrc & IRQ_MASK != 0) */
  1572. if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
  1573. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
  1574. ("SPECIAL IRQ SP-Cards => %x\n", IntSrc));
  1575. pAC->CheckQueue = SK_FALSE;
  1576. spin_lock(&pAC->SlowPathLock);
  1577. if (IntSrc & SPECIAL_IRQS)
  1578. SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
  1579. SkEventDispatcher(pAC, pAC->IoBase);
  1580. spin_unlock(&pAC->SlowPathLock);
  1581. }
  1582. /*
  1583. * do it all again is case we cleared an interrupt that
  1584. * came in after handling the ring (OUTs may be delayed
  1585. * in hardware buffers, but are through after IN)
  1586. */
  1587. ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
  1588. /* IRQ is processed - Enable IRQs again*/
  1589. SK_OUT32(pAC->IoBase, B0_IMSK, IRQ_MASK);
  1590. return;
  1591. } /* SkGeIsrOnePort */
  1592. /****************************************************************************
  1593. *
  1594. * SkGeOpen - handle start of initialized adapter
  1595. *
  1596. * Description:
  1597. * This function starts the initialized adapter.
  1598. * The board level variable is set and the adapter is
  1599. * brought to full functionality.
  1600. * The device flags are set for operation.
  1601. * Do all necessary level 2 initialization, enable interrupts and
  1602. * give start command to RLMT.
  1603. *
  1604. * Returns:
  1605. * 0 on success
  1606. * != 0 on error
  1607. */
  1608. #if 0
  1609. static int SkGeOpen(
  1610. #else
  1611. int SkGeOpen(
  1612. #endif
  1613. struct SK_NET_DEVICE *dev)
  1614. {
  1615. DEV_NET *pNet;
  1616. SK_AC *pAC;
  1617. unsigned long Flags; /* for spin lock */
  1618. int i;
  1619. SK_EVPARA EvPara; /* an event parameter union */
  1620. pNet = (DEV_NET*) dev->priv;
  1621. pAC = pNet->pAC;
  1622. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  1623. ("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC));
  1624. if (pAC->BoardLevel == 0) {
  1625. /* level 1 init common modules here */
  1626. if (SkGeInit(pAC, pAC->IoBase, 1) != 0) {
  1627. printk("%s: HWInit (1) failed.\n", pAC->dev[pNet->PortNr]->name);
  1628. return (-1);
  1629. }
  1630. SkI2cInit (pAC, pAC->IoBase, 1);
  1631. SkEventInit (pAC, pAC->IoBase, 1);
  1632. SkPnmiInit (pAC, pAC->IoBase, 1);
  1633. SkAddrInit (pAC, pAC->IoBase, 1);
  1634. SkRlmtInit (pAC, pAC->IoBase, 1);
  1635. SkTimerInit (pAC, pAC->IoBase, 1);
  1636. pAC->BoardLevel = 1;
  1637. }
  1638. if (pAC->BoardLevel != 2) {
  1639. /* tschilling: Level 2 init modules here, check return value. */
  1640. if (SkGeInit(pAC, pAC->IoBase, 2) != 0) {
  1641. printk("%s: HWInit (2) failed.\n", pAC->dev[pNet->PortNr]->name);
  1642. return (-1);
  1643. }
  1644. SkI2cInit (pAC, pAC->IoBase, 2);
  1645. SkEventInit (pAC, pAC->IoBase, 2);
  1646. SkPnmiInit (pAC, pAC->IoBase, 2);
  1647. SkAddrInit (pAC, pAC->IoBase, 2);
  1648. SkRlmtInit (pAC, pAC->IoBase, 2);
  1649. SkTimerInit (pAC, pAC->IoBase, 2);
  1650. pAC->BoardLevel = 2;
  1651. }
  1652. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  1653. /* Enable transmit descriptor polling. */
  1654. SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
  1655. FillRxRing(pAC, &pAC->RxPort[i]);
  1656. }
  1657. SkGeYellowLED(pAC, pAC->IoBase, 1);
  1658. #ifdef USE_INT_MOD
  1659. /* moderate only TX complete interrupts (these are not time critical) */
  1660. #define IRQ_MOD_MASK (IRQ_EOF_AS_TX1 | IRQ_EOF_AS_TX2)
  1661. {
  1662. unsigned long ModBase;
  1663. ModBase = 53125000 / INTS_PER_SEC;
  1664. SK_OUT32(pAC->IoBase, B2_IRQM_INI, ModBase);
  1665. SK_OUT32(pAC->IoBase, B2_IRQM_MSK, IRQ_MOD_MASK);
  1666. SK_OUT32(pAC->IoBase, B2_IRQM_CTRL, TIM_START);
  1667. }
  1668. #endif
  1669. /* enable Interrupts */
  1670. SK_OUT32(pAC->IoBase, B0_IMSK, IRQ_MASK);
  1671. SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
  1672. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  1673. if ((pAC->RlmtMode != 0) && (pAC->MaxPorts == 0)) {
  1674. EvPara.Para32[0] = pAC->RlmtNets;
  1675. EvPara.Para32[1] = -1;
  1676. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
  1677. EvPara);
  1678. EvPara.Para32[0] = pAC->RlmtMode;
  1679. EvPara.Para32[1] = 0;
  1680. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_MODE_CHANGE,
  1681. EvPara);
  1682. }
  1683. EvPara.Para32[0] = pNet->NetNr;
  1684. EvPara.Para32[1] = -1;
  1685. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
  1686. SkEventDispatcher(pAC, pAC->IoBase);
  1687. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  1688. pAC->MaxPorts++;
  1689. pNet->Up = 1;
  1690. MOD_INC_USE_COUNT;
  1691. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  1692. ("SkGeOpen suceeded\n"));
  1693. return (0);
  1694. } /* SkGeOpen */
  1695. /****************************************************************************
  1696. *
  1697. * SkGeClose - Stop initialized adapter
  1698. *
  1699. * Description:
  1700. * Close initialized adapter.
  1701. *
  1702. * Returns:
  1703. * 0 - on success
  1704. * error code - on error
  1705. */
  1706. #if 0
  1707. static int SkGeClose(
  1708. #else
  1709. int SkGeClose(
  1710. #endif
  1711. struct SK_NET_DEVICE *dev)
  1712. {
  1713. DEV_NET *pNet;
  1714. SK_AC *pAC;
  1715. unsigned long Flags; /* for spin lock */
  1716. int i;
  1717. int PortIdx;
  1718. SK_EVPARA EvPara;
  1719. netif_stop_queue(dev);
  1720. pNet = (DEV_NET*) dev->priv;
  1721. pAC = pNet->pAC;
  1722. if (pAC->RlmtNets == 1)
  1723. PortIdx = pAC->ActivePort;
  1724. else
  1725. PortIdx = pNet->NetNr;
  1726. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  1727. ("SkGeClose: pAC=0x%lX ", (unsigned long)pAC));
  1728. /*
  1729. * Clear multicast table, promiscuous mode ....
  1730. */
  1731. SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
  1732. SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
  1733. SK_PROM_MODE_NONE);
  1734. if (pAC->MaxPorts == 1) {
  1735. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  1736. /* disable interrupts */
  1737. SK_OUT32(pAC->IoBase, B0_IMSK, 0);
  1738. EvPara.Para32[0] = pNet->NetNr;
  1739. EvPara.Para32[1] = -1;
  1740. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
  1741. SkEventDispatcher(pAC, pAC->IoBase);
  1742. SK_OUT32(pAC->IoBase, B0_IMSK, 0);
  1743. /* stop the hardware */
  1744. SkGeDeInit(pAC, pAC->IoBase);
  1745. pAC->BoardLevel = 0;
  1746. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  1747. } else {
  1748. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  1749. EvPara.Para32[0] = pNet->NetNr;
  1750. EvPara.Para32[1] = -1;
  1751. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
  1752. SkEventDispatcher(pAC, pAC->IoBase);
  1753. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  1754. /* Stop port */
  1755. spin_lock_irqsave(&pAC->TxPort[pNet->PortNr]
  1756. [TX_PRIO_LOW].TxDesRingLock, Flags);
  1757. SkGeStopPort(pAC, pAC->IoBase, pNet->PortNr,
  1758. SK_STOP_ALL, SK_HARD_RST);
  1759. spin_unlock_irqrestore(&pAC->TxPort[pNet->PortNr]
  1760. [TX_PRIO_LOW].TxDesRingLock, Flags);
  1761. }
  1762. if (pAC->RlmtNets == 1) {
  1763. /* clear all descriptor rings */
  1764. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  1765. ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
  1766. ClearRxRing(pAC, &pAC->RxPort[i]);
  1767. ClearTxRing(pAC, &pAC->TxPort[i][TX_PRIO_LOW]);
  1768. }
  1769. } else {
  1770. /* clear port descriptor rings */
  1771. ReceiveIrq(pAC, &pAC->RxPort[pNet->PortNr], SK_TRUE);
  1772. ClearRxRing(pAC, &pAC->RxPort[pNet->PortNr]);
  1773. ClearTxRing(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW]);
  1774. }
  1775. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  1776. ("SkGeClose: done "));
  1777. pAC->MaxPorts--;
  1778. pNet->Up = 0;
  1779. MOD_DEC_USE_COUNT;
  1780. return (0);
  1781. } /* SkGeClose */
  1782. /*****************************************************************************
  1783. *
  1784. * SkGeXmit - Linux frame transmit function
  1785. *
  1786. * Description:
  1787. * The system calls this function to send frames onto the wire.
  1788. * It puts the frame in the tx descriptor ring. If the ring is
  1789. * full then, the 'tbusy' flag is set.
  1790. *
  1791. * Returns:
  1792. * 0, if everything is ok
  1793. * !=0, on error
  1794. * WARNING: returning 1 in 'tbusy' case caused system crashes (double
  1795. * allocated skb's) !!!
  1796. */
  1797. #if 0
  1798. static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev)
  1799. #else
  1800. int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev)
  1801. #endif
  1802. {
  1803. DEV_NET *pNet;
  1804. SK_AC *pAC;
  1805. int Rc; /* return code of XmitFrame */
  1806. pNet = (DEV_NET*) dev->priv;
  1807. pAC = pNet->pAC;
  1808. #if 0
  1809. if ((!skb_shinfo(skb)->nr_frags) ||
  1810. #else
  1811. if (1 ||
  1812. #endif
  1813. (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) {
  1814. /* Don't activate scatter-gather and hardware checksum */
  1815. if (pAC->RlmtNets == 2)
  1816. Rc = XmitFrame(
  1817. pAC,
  1818. &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
  1819. skb);
  1820. else
  1821. Rc = XmitFrame(
  1822. pAC,
  1823. &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
  1824. skb);
  1825. } else {
  1826. #if 0
  1827. /* scatter-gather and hardware TCP checksumming anabled*/
  1828. if (pAC->RlmtNets == 2)
  1829. Rc = XmitFrameSG(
  1830. pAC,
  1831. &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
  1832. skb);
  1833. else
  1834. Rc = XmitFrameSG(
  1835. pAC,
  1836. &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
  1837. skb);
  1838. #endif
  1839. }
  1840. /* Transmitter out of resources? */
  1841. if (Rc <= 0) {
  1842. netif_stop_queue(dev);
  1843. }
  1844. /* If not taken, give buffer ownership back to the
  1845. * queueing layer.
  1846. */
  1847. if (Rc < 0)
  1848. return (1);
  1849. #if 0
  1850. dev->trans_start = jiffies;
  1851. #endif
  1852. return (0);
  1853. } /* SkGeXmit */
  1854. /*****************************************************************************
  1855. *
  1856. * XmitFrame - fill one socket buffer into the transmit ring
  1857. *
  1858. * Description:
  1859. * This function puts a message into the transmit descriptor ring
  1860. * if there is a descriptors left.
  1861. * Linux skb's consist of only one continuous buffer.
  1862. * The first step locks the ring. It is held locked
  1863. * all time to avoid problems with SWITCH_../PORT_RESET.
  1864. * Then the descriptoris allocated.
  1865. * The second part is linking the buffer to the descriptor.
  1866. * At the very last, the Control field of the descriptor
  1867. * is made valid for the BMU and a start TX command is given
  1868. * if necessary.
  1869. *
  1870. * Returns:
  1871. * > 0 - on succes: the number of bytes in the message
  1872. * = 0 - on resource shortage: this frame sent or dropped, now
  1873. * the ring is full ( -> set tbusy)
  1874. * < 0 - on failure: other problems ( -> return failure to upper layers)
  1875. */
  1876. static int XmitFrame(
  1877. SK_AC *pAC, /* pointer to adapter context */
  1878. TX_PORT *pTxPort, /* pointer to struct of port to send to */
  1879. struct sk_buff *pMessage) /* pointer to send-message */
  1880. {
  1881. TXD *pTxd; /* the rxd to fill */
  1882. unsigned long Flags;
  1883. SK_U64 PhysAddr;
  1884. int BytesSend;
  1885. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
  1886. ("X"));
  1887. spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
  1888. #ifndef USE_TX_COMPLETE
  1889. FreeTxDescriptors(pAC, pTxPort);
  1890. #endif
  1891. if (pTxPort->TxdRingFree == 0) {
  1892. /* no enough free descriptors in ring at the moment */
  1893. FreeTxDescriptors(pAC, pTxPort);
  1894. if (pTxPort->TxdRingFree == 0) {
  1895. spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
  1896. SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
  1897. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1898. SK_DBGCAT_DRV_TX_PROGRESS,
  1899. ("XmitFrame failed\n"));
  1900. /* this message can not be sent now */
  1901. /* Because tbusy seems to be set, the message should not be freed here */
  1902. /* It will be used by the scheduler of the ethernet handler */
  1903. return (-1);
  1904. }
  1905. }
  1906. /* advance head counter behind descriptor needed for this frame */
  1907. pTxd = pTxPort->pTxdRingHead;
  1908. pTxPort->pTxdRingHead = pTxd->pNextTxd;
  1909. pTxPort->TxdRingFree--;
  1910. /* the needed descriptor is reserved now */
  1911. /*
  1912. * everything allocated ok, so add buffer to descriptor
  1913. */
  1914. #ifdef SK_DUMP_TX
  1915. DumpMsg(pMessage, "XmitFrame");
  1916. #endif
  1917. /* set up descriptor and CONTROL dword */
  1918. #if 0
  1919. PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
  1920. virt_to_page(pMessage->data),
  1921. ((unsigned long) pMessage->data &
  1922. ~PAGE_MASK),
  1923. pMessage->len,
  1924. PCI_DMA_TODEVICE);
  1925. #else
  1926. PhysAddr = (SK_U64) pci_phys_to_mem(pAC->PciDev, (u32) pMessage->data);
  1927. #endif
  1928. pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
  1929. pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
  1930. pTxd->pMBuf = pMessage;
  1931. pTxd->TBControl = TX_CTRL_OWN_BMU | TX_CTRL_STF |
  1932. TX_CTRL_CHECK_DEFAULT | TX_CTRL_SOFTWARE |
  1933. #ifdef USE_TX_COMPLETE
  1934. TX_CTRL_EOF | TX_CTRL_EOF_IRQ | pMessage->len;
  1935. #else
  1936. TX_CTRL_EOF | pMessage->len;
  1937. #endif
  1938. if ((pTxPort->pTxdRingPrev->TBControl & TX_CTRL_OWN_BMU) == 0) {
  1939. /* previous descriptor already done, so give tx start cmd */
  1940. /* StartTx(pAC, pTxPort->HwAddr); */
  1941. SK_OUT8(pTxPort->HwAddr, TX_Q_CTRL, TX_Q_CTRL_START);
  1942. }
  1943. pTxPort->pTxdRingPrev = pTxd;
  1944. BytesSend = pMessage->len;
  1945. spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
  1946. /* after releasing the lock, the skb may be immidiately freed */
  1947. if (pTxPort->TxdRingFree != 0)
  1948. return (BytesSend);
  1949. else
  1950. return (0);
  1951. } /* XmitFrame */
  1952. /*****************************************************************************
  1953. *
  1954. * XmitFrameSG - fill one socket buffer into the transmit ring
  1955. * (use SG and TCP/UDP hardware checksumming)
  1956. *
  1957. * Description:
  1958. * This function puts a message into the transmit descriptor ring
  1959. * if there is a descriptors left.
  1960. *
  1961. * Returns:
  1962. * > 0 - on succes: the number of bytes in the message
  1963. * = 0 - on resource shortage: this frame sent or dropped, now
  1964. * the ring is full ( -> set tbusy)
  1965. * < 0 - on failure: other problems ( -> return failure to upper layers)
  1966. */
  1967. #if 0
  1968. static int XmitFrameSG(
  1969. SK_AC *pAC, /* pointer to adapter context */
  1970. TX_PORT *pTxPort, /* pointer to struct of port to send to */
  1971. struct sk_buff *pMessage) /* pointer to send-message */
  1972. {
  1973. int i;
  1974. int BytesSend;
  1975. int hlength;
  1976. int protocol;
  1977. skb_frag_t *sk_frag;
  1978. TXD *pTxd;
  1979. TXD *pTxdFst;
  1980. TXD *pTxdLst;
  1981. SK_U64 PhysAddr;
  1982. unsigned long Flags;
  1983. spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
  1984. #ifndef USE_TX_COMPLETE
  1985. FreeTxDescriptors(pAC, pTxPort);
  1986. #endif
  1987. if ((skb_shinfo(pMessage)->nr_frags +1) > pTxPort->TxdRingFree) {
  1988. FreeTxDescriptors(pAC, pTxPort);
  1989. if ((skb_shinfo(pMessage)->nr_frags + 1) > pTxPort->TxdRingFree) {
  1990. spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
  1991. SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
  1992. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1993. SK_DBGCAT_DRV_TX_PROGRESS,
  1994. ("XmitFrameSG failed - Ring full\n"));
  1995. /* this message can not be sent now */
  1996. return(-1);
  1997. }
  1998. }
  1999. pTxd = pTxPort->pTxdRingHead;
  2000. pTxdFst = pTxd;
  2001. pTxdLst = pTxd;
  2002. BytesSend = 0;
  2003. protocol = 0;
  2004. /* map first fragment (header) */
  2005. PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
  2006. virt_to_page(pMessage->data),
  2007. ((unsigned long) pMessage->data & ~PAGE_MASK),
  2008. skb_headlen(pMessage),
  2009. PCI_DMA_TODEVICE);
  2010. pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
  2011. pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
  2012. /* HW checksum? */
  2013. if (pMessage->ip_summed == CHECKSUM_HW) {
  2014. pTxd->TBControl = TX_CTRL_STF |
  2015. TX_CTRL_ST_FWD |
  2016. skb_headlen(pMessage);
  2017. /* We have to use the opcode for tcp here because the opcode for
  2018. udp is not working in the hardware yet (revision 2.0)*/
  2019. protocol = ((SK_U8)pMessage->data[23] & 0xf);
  2020. if ((protocol == 17) && (pAC->GIni.GIChipRev != 0))
  2021. pTxd->TBControl |= BMU_UDP_CHECK;
  2022. else
  2023. pTxd->TBControl |= BMU_TCP_CHECK ;
  2024. hlength = ((SK_U8)pMessage->data[14] & 0xf) * 4;
  2025. pTxd->TcpSumOfs = 0; /* PH-Checksum already claculated */
  2026. pTxd->TcpSumSt = 14+hlength+16;
  2027. pTxd->TcpSumWr = 14+hlength;
  2028. } else {
  2029. pTxd->TBControl = TX_CTRL_CHECK_DEFAULT |
  2030. TX_CTRL_SOFTWARE |
  2031. TX_CTRL_STF |
  2032. skb_headlen(pMessage);
  2033. }
  2034. pTxd = pTxd->pNextTxd;
  2035. pTxPort->TxdRingFree--;
  2036. BytesSend += skb_headlen(pMessage);
  2037. /* Map SG fragments */
  2038. for (i = 0; i < skb_shinfo(pMessage)->nr_frags; i++) {
  2039. sk_frag = &skb_shinfo(pMessage)->frags[i];
  2040. /* we already have the proper value in entry */
  2041. PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
  2042. sk_frag->page,
  2043. sk_frag->page_offset,
  2044. sk_frag->size,
  2045. PCI_DMA_TODEVICE);
  2046. pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
  2047. pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
  2048. pTxd->pMBuf = pMessage;
  2049. /* HW checksum */
  2050. if (pMessage->ip_summed == CHECKSUM_HW) {
  2051. pTxd->TBControl = TX_CTRL_OWN_BMU |
  2052. TX_CTRL_SOFTWARE |
  2053. TX_CTRL_ST_FWD;
  2054. /* We have to use the opcode for tcp here because the opcode for
  2055. udp is not working in the hardware yet (revision 2.0)*/
  2056. if ((protocol == 17) && (pAC->GIni.GIChipRev != 0))
  2057. pTxd->TBControl |= BMU_UDP_CHECK ;
  2058. else
  2059. pTxd->TBControl |= BMU_TCP_CHECK ;
  2060. } else {
  2061. pTxd->TBControl = TX_CTRL_CHECK_DEFAULT |
  2062. TX_CTRL_SOFTWARE |
  2063. TX_CTRL_OWN_BMU;
  2064. }
  2065. /* Last fragment */
  2066. if( (i+1) == skb_shinfo(pMessage)->nr_frags ) {
  2067. #ifdef USE_TX_COMPLETE
  2068. pTxd->TBControl |= TX_CTRL_EOF |
  2069. TX_CTRL_EOF_IRQ |
  2070. sk_frag->size;
  2071. #else
  2072. pTxd->TBControl |= TX_CTRL_EOF |
  2073. sk_frag->size;
  2074. #endif
  2075. pTxdFst->TBControl |= TX_CTRL_OWN_BMU |
  2076. TX_CTRL_SOFTWARE;
  2077. } else {
  2078. pTxd->TBControl |= sk_frag->size;
  2079. }
  2080. pTxdLst = pTxd;
  2081. pTxd = pTxd->pNextTxd;
  2082. pTxPort->TxdRingFree--;
  2083. BytesSend += sk_frag->size;
  2084. }
  2085. if ((pTxPort->pTxdRingPrev->TBControl & TX_CTRL_OWN_BMU) == 0) {
  2086. /* previous descriptor already done, so give tx start cmd */
  2087. /* StartTx(pAC, pTxPort->HwAddr); */
  2088. SK_OUT8(pTxPort->HwAddr, TX_Q_CTRL, TX_Q_CTRL_START);
  2089. }
  2090. pTxPort->pTxdRingPrev = pTxdLst;
  2091. pTxPort->pTxdRingHead = pTxd;
  2092. spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
  2093. if (pTxPort->TxdRingFree > 0)
  2094. return (BytesSend);
  2095. else
  2096. return (0);
  2097. }
  2098. #endif
  2099. void dump_frag( SK_U8 *data, int length)
  2100. {
  2101. int i;
  2102. printk("Length: %d\n", length);
  2103. for( i=0; i < length; i++ ) {
  2104. printk(" %02x", (SK_U8)*(data + i) );
  2105. if( !((i+1) % 20) )
  2106. printk("\n");
  2107. }
  2108. printk("\n\n");
  2109. }
  2110. /*****************************************************************************
  2111. *
  2112. * FreeTxDescriptors - release descriptors from the descriptor ring
  2113. *
  2114. * Description:
  2115. * This function releases descriptors from a transmit ring if they
  2116. * have been sent by the BMU.
  2117. * If a descriptors is sent, it can be freed and the message can
  2118. * be freed, too.
  2119. * The SOFTWARE controllable bit is used to prevent running around a
  2120. * completely free ring for ever. If this bit is no set in the
  2121. * frame (by XmitFrame), this frame has never been sent or is
  2122. * already freed.
  2123. * The Tx descriptor ring lock must be held while calling this function !!!
  2124. *
  2125. * Returns:
  2126. * none
  2127. */
  2128. static void FreeTxDescriptors(
  2129. SK_AC *pAC, /* pointer to the adapter context */
  2130. TX_PORT *pTxPort) /* pointer to destination port structure */
  2131. {
  2132. TXD *pTxd; /* pointer to the checked descriptor */
  2133. TXD *pNewTail; /* pointer to 'end' of the ring */
  2134. SK_U32 Control; /* TBControl field of descriptor */
  2135. SK_U64 PhysAddr; /* address of DMA mapping */
  2136. pNewTail = pTxPort->pTxdRingTail;
  2137. pTxd = pNewTail;
  2138. /*
  2139. * loop forever; exits if TX_CTRL_SOFTWARE bit not set in start frame
  2140. * or TX_CTRL_OWN_BMU bit set in any frame
  2141. */
  2142. while (1) {
  2143. Control = pTxd->TBControl;
  2144. if ((Control & TX_CTRL_SOFTWARE) == 0) {
  2145. /*
  2146. * software controllable bit is set in first
  2147. * fragment when given to BMU. Not set means that
  2148. * this fragment was never sent or is already
  2149. * freed ( -> ring completely free now).
  2150. */
  2151. pTxPort->pTxdRingTail = pTxd;
  2152. netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
  2153. return;
  2154. }
  2155. if (Control & TX_CTRL_OWN_BMU) {
  2156. pTxPort->pTxdRingTail = pTxd;
  2157. if (pTxPort->TxdRingFree > 0) {
  2158. netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
  2159. }
  2160. return;
  2161. }
  2162. /* release the DMA mapping */
  2163. PhysAddr = ((SK_U64) pTxd->VDataHigh) << (SK_U64) 32;
  2164. PhysAddr |= (SK_U64) pTxd->VDataLow;
  2165. pci_unmap_page(pAC->PciDev, PhysAddr,
  2166. pTxd->pMBuf->len,
  2167. PCI_DMA_TODEVICE);
  2168. if (Control & TX_CTRL_EOF)
  2169. DEV_KFREE_SKB_ANY(pTxd->pMBuf); /* free message */
  2170. pTxPort->TxdRingFree++;
  2171. pTxd->TBControl &= ~TX_CTRL_SOFTWARE;
  2172. pTxd = pTxd->pNextTxd; /* point behind fragment with EOF */
  2173. } /* while(forever) */
  2174. } /* FreeTxDescriptors */
  2175. /*****************************************************************************
  2176. *
  2177. * FillRxRing - fill the receive ring with valid descriptors
  2178. *
  2179. * Description:
  2180. * This function fills the receive ring descriptors with data
  2181. * segments and makes them valid for the BMU.
  2182. * The active ring is filled completely, if possible.
  2183. * The non-active ring is filled only partial to save memory.
  2184. *
  2185. * Description of rx ring structure:
  2186. * head - points to the descriptor which will be used next by the BMU
  2187. * tail - points to the next descriptor to give to the BMU
  2188. *
  2189. * Returns: N/A
  2190. */
  2191. static void FillRxRing(
  2192. SK_AC *pAC, /* pointer to the adapter context */
  2193. RX_PORT *pRxPort) /* ptr to port struct for which the ring
  2194. should be filled */
  2195. {
  2196. unsigned long Flags;
  2197. spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
  2198. while (pRxPort->RxdRingFree > pRxPort->RxFillLimit) {
  2199. if(!FillRxDescriptor(pAC, pRxPort))
  2200. break;
  2201. }
  2202. spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
  2203. } /* FillRxRing */
  2204. /*****************************************************************************
  2205. *
  2206. * FillRxDescriptor - fill one buffer into the receive ring
  2207. *
  2208. * Description:
  2209. * The function allocates a new receive buffer and
  2210. * puts it into the next descriptor.
  2211. *
  2212. * Returns:
  2213. * SK_TRUE - a buffer was added to the ring
  2214. * SK_FALSE - a buffer could not be added
  2215. */
  2216. static SK_BOOL FillRxDescriptor(
  2217. SK_AC *pAC, /* pointer to the adapter context struct */
  2218. RX_PORT *pRxPort) /* ptr to port struct of ring to fill */
  2219. {
  2220. struct sk_buff *pMsgBlock; /* pointer to a new message block */
  2221. RXD *pRxd; /* the rxd to fill */
  2222. SK_U16 Length; /* data fragment length */
  2223. SK_U64 PhysAddr; /* physical address of a rx buffer */
  2224. pMsgBlock = alloc_skb(pAC->RxBufSize, GFP_ATOMIC);
  2225. if (pMsgBlock == NULL) {
  2226. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  2227. SK_DBGCAT_DRV_ENTRY,
  2228. ("%s: Allocation of rx buffer failed !\n",
  2229. pAC->dev[pRxPort->PortIndex]->name));
  2230. SK_PNMI_CNT_NO_RX_BUF(pAC, pRxPort->PortIndex);
  2231. return(SK_FALSE);
  2232. }
  2233. skb_reserve(pMsgBlock, 2); /* to align IP frames */
  2234. /* skb allocated ok, so add buffer */
  2235. pRxd = pRxPort->pRxdRingTail;
  2236. pRxPort->pRxdRingTail = pRxd->pNextRxd;
  2237. pRxPort->RxdRingFree--;
  2238. Length = pAC->RxBufSize;
  2239. #if 0
  2240. PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
  2241. virt_to_page(pMsgBlock->data),
  2242. ((unsigned long) pMsgBlock->data &
  2243. ~PAGE_MASK),
  2244. pAC->RxBufSize - 2,
  2245. PCI_DMA_FROMDEVICE);
  2246. #else
  2247. PhysAddr = (SK_U64) pci_phys_to_mem(pAC->PciDev, (u32)pMsgBlock->data);
  2248. #endif
  2249. pRxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
  2250. pRxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
  2251. pRxd->pMBuf = pMsgBlock;
  2252. pRxd->RBControl = RX_CTRL_OWN_BMU | RX_CTRL_STF |
  2253. RX_CTRL_EOF_IRQ | RX_CTRL_CHECK_CSUM | Length;
  2254. return (SK_TRUE);
  2255. } /* FillRxDescriptor */
  2256. /*****************************************************************************
  2257. *
  2258. * ReQueueRxBuffer - fill one buffer back into the receive ring
  2259. *
  2260. * Description:
  2261. * Fill a given buffer back into the rx ring. The buffer
  2262. * has been previously allocated and aligned, and its phys.
  2263. * address calculated, so this is no more necessary.
  2264. *
  2265. * Returns: N/A
  2266. */
  2267. static void ReQueueRxBuffer(
  2268. SK_AC *pAC, /* pointer to the adapter context struct */
  2269. RX_PORT *pRxPort, /* ptr to port struct of ring to fill */
  2270. struct sk_buff *pMsg, /* pointer to the buffer */
  2271. SK_U32 PhysHigh, /* phys address high dword */
  2272. SK_U32 PhysLow) /* phys address low dword */
  2273. {
  2274. RXD *pRxd; /* the rxd to fill */
  2275. SK_U16 Length; /* data fragment length */
  2276. pRxd = pRxPort->pRxdRingTail;
  2277. pRxPort->pRxdRingTail = pRxd->pNextRxd;
  2278. pRxPort->RxdRingFree--;
  2279. Length = pAC->RxBufSize;
  2280. pRxd->VDataLow = PhysLow;
  2281. pRxd->VDataHigh = PhysHigh;
  2282. pRxd->pMBuf = pMsg;
  2283. pRxd->RBControl = RX_CTRL_OWN_BMU | RX_CTRL_STF |
  2284. RX_CTRL_EOF_IRQ | RX_CTRL_CHECK_CSUM | Length;
  2285. return;
  2286. } /* ReQueueRxBuffer */
  2287. /*****************************************************************************
  2288. *
  2289. * ReceiveIrq - handle a receive IRQ
  2290. *
  2291. * Description:
  2292. * This function is called when a receive IRQ is set.
  2293. * It walks the receive descriptor ring and sends up all
  2294. * frames that are complete.
  2295. *
  2296. * Returns: N/A
  2297. */
  2298. #if 0
  2299. static void ReceiveIrq(
  2300. #else
  2301. void ReceiveIrq(
  2302. #endif
  2303. SK_AC *pAC, /* pointer to adapter context */
  2304. RX_PORT *pRxPort, /* pointer to receive port struct */
  2305. SK_BOOL SlowPathLock) /* indicates if SlowPathLock is needed */
  2306. {
  2307. RXD *pRxd; /* pointer to receive descriptors */
  2308. SK_U32 Control; /* control field of descriptor */
  2309. struct sk_buff *pMsg; /* pointer to message holding frame */
  2310. struct sk_buff *pNewMsg; /* pointer to a new message for copying frame */
  2311. int FrameLength; /* total length of received frame */
  2312. SK_MBUF *pRlmtMbuf; /* ptr to a buffer for giving a frame to rlmt */
  2313. SK_EVPARA EvPara; /* an event parameter union */
  2314. unsigned long Flags; /* for spin lock */
  2315. int PortIndex = pRxPort->PortIndex;
  2316. unsigned int Offset;
  2317. unsigned int NumBytes;
  2318. unsigned int ForRlmt;
  2319. SK_BOOL IsBc;
  2320. SK_BOOL IsMc;
  2321. SK_BOOL IsBadFrame; /* Bad frame */
  2322. SK_U32 FrameStat;
  2323. unsigned short Csum1;
  2324. unsigned short Csum2;
  2325. unsigned short Type;
  2326. #if 0
  2327. int Result;
  2328. #endif
  2329. SK_U64 PhysAddr;
  2330. rx_start:
  2331. /* do forever; exit if RX_CTRL_OWN_BMU found */
  2332. for ( pRxd = pRxPort->pRxdRingHead ;
  2333. pRxPort->RxdRingFree < pAC->RxDescrPerRing ;
  2334. pRxd = pRxd->pNextRxd,
  2335. pRxPort->pRxdRingHead = pRxd,
  2336. pRxPort->RxdRingFree ++) {
  2337. /*
  2338. * For a better understanding of this loop
  2339. * Go through every descriptor beginning at the head
  2340. * Please note: the ring might be completely received so the OWN bit
  2341. * set is not a good crirteria to leave that loop.
  2342. * Therefore the RingFree counter is used.
  2343. * On entry of this loop pRxd is a pointer to the Rxd that needs
  2344. * to be checked next.
  2345. */
  2346. Control = pRxd->RBControl;
  2347. /* check if this descriptor is ready */
  2348. if ((Control & RX_CTRL_OWN_BMU) != 0) {
  2349. /* this descriptor is not yet ready */
  2350. /* This is the usual end of the loop */
  2351. /* We don't need to start the ring again */
  2352. FillRxRing(pAC, pRxPort);
  2353. return;
  2354. }
  2355. /* get length of frame and check it */
  2356. FrameLength = Control & RX_CTRL_LEN_MASK;
  2357. if (FrameLength > pAC->RxBufSize) {
  2358. goto rx_failed;
  2359. }
  2360. /* check for STF and EOF */
  2361. if ((Control & (RX_CTRL_STF | RX_CTRL_EOF)) !=
  2362. (RX_CTRL_STF | RX_CTRL_EOF)) {
  2363. goto rx_failed;
  2364. }
  2365. /* here we have a complete frame in the ring */
  2366. pMsg = pRxd->pMBuf;
  2367. FrameStat = pRxd->FrameStat;
  2368. /* check for frame length mismatch */
  2369. #define XMR_FS_LEN_SHIFT 18
  2370. #define GMR_FS_LEN_SHIFT 16
  2371. if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
  2372. if (FrameLength != (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)) {
  2373. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  2374. SK_DBGCAT_DRV_RX_PROGRESS,
  2375. ("skge: Frame length mismatch (%u/%u).\n",
  2376. FrameLength,
  2377. (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
  2378. goto rx_failed;
  2379. }
  2380. }
  2381. else {
  2382. if (FrameLength != (SK_U32) (FrameStat >> GMR_FS_LEN_SHIFT)) {
  2383. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  2384. SK_DBGCAT_DRV_RX_PROGRESS,
  2385. ("skge: Frame length mismatch (%u/%u).\n",
  2386. FrameLength,
  2387. (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
  2388. goto rx_failed;
  2389. }
  2390. }
  2391. /* Set Rx Status */
  2392. if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
  2393. IsBc = (FrameStat & XMR_FS_BC) != 0;
  2394. IsMc = (FrameStat & XMR_FS_MC) != 0;
  2395. IsBadFrame = (FrameStat &
  2396. (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0;
  2397. } else {
  2398. IsBc = (FrameStat & GMR_FS_BC) != 0;
  2399. IsMc = (FrameStat & GMR_FS_MC) != 0;
  2400. IsBadFrame = (((FrameStat & GMR_FS_ANY_ERR) != 0) ||
  2401. ((FrameStat & GMR_FS_RX_OK) == 0));
  2402. }
  2403. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
  2404. ("Received frame of length %d on port %d\n",
  2405. FrameLength, PortIndex));
  2406. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
  2407. ("Number of free rx descriptors: %d\n",
  2408. pRxPort->RxdRingFree));
  2409. /* DumpMsg(pMsg, "Rx"); */
  2410. if ((Control & RX_CTRL_STAT_VALID) != RX_CTRL_STAT_VALID ||
  2411. (IsBadFrame)) {
  2412. #if 0
  2413. (FrameStat & (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0) {
  2414. #endif
  2415. /* there is a receive error in this frame */
  2416. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  2417. SK_DBGCAT_DRV_RX_PROGRESS,
  2418. ("skge: Error in received frame, dropped!\n"
  2419. "Control: %x\nRxStat: %x\n",
  2420. Control, FrameStat));
  2421. PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
  2422. PhysAddr |= (SK_U64) pRxd->VDataLow;
  2423. pci_dma_sync_single(pAC->PciDev,
  2424. (dma_addr_t) PhysAddr,
  2425. FrameLength,
  2426. PCI_DMA_FROMDEVICE);
  2427. ReQueueRxBuffer(pAC, pRxPort, pMsg,
  2428. pRxd->VDataHigh, pRxd->VDataLow);
  2429. continue;
  2430. }
  2431. /*
  2432. * if short frame then copy data to reduce memory waste
  2433. */
  2434. if ((FrameLength < SK_COPY_THRESHOLD) &&
  2435. ((pNewMsg = alloc_skb(FrameLength+2, GFP_ATOMIC)) != NULL)) {
  2436. /*
  2437. * Short frame detected and allocation successfull
  2438. */
  2439. /* use new skb and copy data */
  2440. skb_reserve(pNewMsg, 2);
  2441. skb_put(pNewMsg, FrameLength);
  2442. PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
  2443. PhysAddr |= (SK_U64) pRxd->VDataLow;
  2444. pci_dma_sync_single(pAC->PciDev,
  2445. (dma_addr_t) PhysAddr,
  2446. FrameLength,
  2447. PCI_DMA_FROMDEVICE);
  2448. eth_copy_and_sum(pNewMsg, pMsg->data,
  2449. FrameLength, 0);
  2450. ReQueueRxBuffer(pAC, pRxPort, pMsg,
  2451. pRxd->VDataHigh, pRxd->VDataLow);
  2452. pMsg = pNewMsg;
  2453. }
  2454. else {
  2455. /*
  2456. * if large frame, or SKB allocation failed, pass
  2457. * the SKB directly to the networking
  2458. */
  2459. PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
  2460. PhysAddr |= (SK_U64) pRxd->VDataLow;
  2461. /* release the DMA mapping */
  2462. pci_unmap_single(pAC->PciDev,
  2463. PhysAddr,
  2464. pAC->RxBufSize - 2,
  2465. PCI_DMA_FROMDEVICE);
  2466. /* set length in message */
  2467. skb_put(pMsg, FrameLength);
  2468. /* hardware checksum */
  2469. Type = ntohs(*((short*)&pMsg->data[12]));
  2470. if (Type == 0x800) {
  2471. Csum1=le16_to_cpu(pRxd->TcpSums & 0xffff);
  2472. Csum2=le16_to_cpu((pRxd->TcpSums >> 16) & 0xffff);
  2473. #if 0
  2474. if ((((Csum1 & 0xfffe) && (Csum2 & 0xfffe)) &&
  2475. (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) ||
  2476. (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
  2477. Result = SkCsGetReceiveInfo(pAC,
  2478. &pMsg->data[14],
  2479. Csum1, Csum2, pRxPort->PortIndex);
  2480. if (Result ==
  2481. SKCS_STATUS_IP_FRAGMENT ||
  2482. Result ==
  2483. SKCS_STATUS_IP_CSUM_OK ||
  2484. Result ==
  2485. SKCS_STATUS_TCP_CSUM_OK ||
  2486. Result ==
  2487. SKCS_STATUS_UDP_CSUM_OK) {
  2488. pMsg->ip_summed =
  2489. CHECKSUM_UNNECESSARY;
  2490. } else {
  2491. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  2492. SK_DBGCAT_DRV_RX_PROGRESS,
  2493. ("skge: CRC error. Frame dropped!\n"));
  2494. goto rx_failed;
  2495. }
  2496. }/* checksumControl calculation valid */
  2497. #endif
  2498. } /* IP frame */
  2499. } /* frame > SK_COPY_TRESHOLD */
  2500. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("V"));
  2501. ForRlmt = SK_RLMT_RX_PROTOCOL;
  2502. #if 0
  2503. IsBc = (FrameStat & XMR_FS_BC)==XMR_FS_BC;
  2504. #endif
  2505. SK_RLMT_PRE_LOOKAHEAD(pAC, PortIndex, FrameLength,
  2506. IsBc, &Offset, &NumBytes);
  2507. if (NumBytes != 0) {
  2508. #if 0
  2509. IsMc = (FrameStat & XMR_FS_MC)==XMR_FS_MC;
  2510. #endif
  2511. SK_RLMT_LOOKAHEAD(pAC, PortIndex,
  2512. &pMsg->data[Offset],
  2513. IsBc, IsMc, &ForRlmt);
  2514. }
  2515. if (ForRlmt == SK_RLMT_RX_PROTOCOL) {
  2516. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("W"));
  2517. /* send up only frames from active port */
  2518. if ((PortIndex == pAC->ActivePort) ||
  2519. (pAC->RlmtNets == 2)) {
  2520. /* frame for upper layer */
  2521. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("U"));
  2522. #ifdef xDEBUG
  2523. DumpMsg(pMsg, "Rx");
  2524. #endif
  2525. SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC,
  2526. FrameLength, pRxPort->PortIndex);
  2527. #if 0
  2528. pMsg->dev = pAC->dev[pRxPort->PortIndex];
  2529. pMsg->protocol = eth_type_trans(pMsg,
  2530. pAC->dev[pRxPort->PortIndex]);
  2531. netif_rx(pMsg);
  2532. pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
  2533. #else
  2534. NetReceive(pMsg->data, pMsg->len);
  2535. dev_kfree_skb_any(pMsg);
  2536. #endif
  2537. }
  2538. else {
  2539. /* drop frame */
  2540. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  2541. SK_DBGCAT_DRV_RX_PROGRESS,
  2542. ("D"));
  2543. DEV_KFREE_SKB(pMsg);
  2544. }
  2545. } /* if not for rlmt */
  2546. else {
  2547. /* packet for rlmt */
  2548. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  2549. SK_DBGCAT_DRV_RX_PROGRESS, ("R"));
  2550. pRlmtMbuf = SkDrvAllocRlmtMbuf(pAC,
  2551. pAC->IoBase, FrameLength);
  2552. if (pRlmtMbuf != NULL) {
  2553. pRlmtMbuf->pNext = NULL;
  2554. pRlmtMbuf->Length = FrameLength;
  2555. pRlmtMbuf->PortIdx = PortIndex;
  2556. EvPara.pParaPtr = pRlmtMbuf;
  2557. memcpy((char*)(pRlmtMbuf->pData),
  2558. (char*)(pMsg->data),
  2559. FrameLength);
  2560. /* SlowPathLock needed? */
  2561. if (SlowPathLock == SK_TRUE) {
  2562. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  2563. SkEventQueue(pAC, SKGE_RLMT,
  2564. SK_RLMT_PACKET_RECEIVED,
  2565. EvPara);
  2566. pAC->CheckQueue = SK_TRUE;
  2567. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  2568. } else {
  2569. SkEventQueue(pAC, SKGE_RLMT,
  2570. SK_RLMT_PACKET_RECEIVED,
  2571. EvPara);
  2572. pAC->CheckQueue = SK_TRUE;
  2573. }
  2574. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  2575. SK_DBGCAT_DRV_RX_PROGRESS,
  2576. ("Q"));
  2577. }
  2578. #if 0
  2579. if ((pAC->dev[pRxPort->PortIndex]->flags &
  2580. (IFF_PROMISC | IFF_ALLMULTI)) != 0 ||
  2581. (ForRlmt & SK_RLMT_RX_PROTOCOL) ==
  2582. SK_RLMT_RX_PROTOCOL) {
  2583. pMsg->dev = pAC->dev[pRxPort->PortIndex];
  2584. pMsg->protocol = eth_type_trans(pMsg,
  2585. pAC->dev[pRxPort->PortIndex]);
  2586. netif_rx(pMsg);
  2587. pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
  2588. }
  2589. #else
  2590. if (0) {
  2591. }
  2592. #endif
  2593. else {
  2594. DEV_KFREE_SKB(pMsg);
  2595. }
  2596. } /* if packet for rlmt */
  2597. } /* for ... scanning the RXD ring */
  2598. /* RXD ring is empty -> fill and restart */
  2599. FillRxRing(pAC, pRxPort);
  2600. /* do not start if called from Close */
  2601. if (pAC->BoardLevel > 0) {
  2602. ClearAndStartRx(pAC, PortIndex);
  2603. }
  2604. return;
  2605. rx_failed:
  2606. /* remove error frame */
  2607. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
  2608. ("Schrottdescriptor, length: 0x%x\n", FrameLength));
  2609. /* release the DMA mapping */
  2610. PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
  2611. PhysAddr |= (SK_U64) pRxd->VDataLow;
  2612. pci_unmap_page(pAC->PciDev,
  2613. PhysAddr,
  2614. pAC->RxBufSize - 2,
  2615. PCI_DMA_FROMDEVICE);
  2616. DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
  2617. pRxd->pMBuf = NULL;
  2618. pRxPort->RxdRingFree++;
  2619. pRxPort->pRxdRingHead = pRxd->pNextRxd;
  2620. goto rx_start;
  2621. } /* ReceiveIrq */
  2622. /*****************************************************************************
  2623. *
  2624. * ClearAndStartRx - give a start receive command to BMU, clear IRQ
  2625. *
  2626. * Description:
  2627. * This function sends a start command and a clear interrupt
  2628. * command for one receive queue to the BMU.
  2629. *
  2630. * Returns: N/A
  2631. * none
  2632. */
  2633. static void ClearAndStartRx(
  2634. SK_AC *pAC, /* pointer to the adapter context */
  2635. int PortIndex) /* index of the receive port (XMAC) */
  2636. {
  2637. SK_OUT8(pAC->IoBase, RxQueueAddr[PortIndex]+RX_Q_CTRL,
  2638. RX_Q_CTRL_START | RX_Q_CTRL_CLR_I_EOF);
  2639. } /* ClearAndStartRx */
  2640. /*****************************************************************************
  2641. *
  2642. * ClearTxIrq - give a clear transmit IRQ command to BMU
  2643. *
  2644. * Description:
  2645. * This function sends a clear tx IRQ command for one
  2646. * transmit queue to the BMU.
  2647. *
  2648. * Returns: N/A
  2649. */
  2650. static void ClearTxIrq(
  2651. SK_AC *pAC, /* pointer to the adapter context */
  2652. int PortIndex, /* index of the transmit port (XMAC) */
  2653. int Prio) /* priority or normal queue */
  2654. {
  2655. SK_OUT8(pAC->IoBase, TxQueueAddr[PortIndex][Prio]+TX_Q_CTRL,
  2656. TX_Q_CTRL_CLR_I_EOF);
  2657. } /* ClearTxIrq */
  2658. /*****************************************************************************
  2659. *
  2660. * ClearRxRing - remove all buffers from the receive ring
  2661. *
  2662. * Description:
  2663. * This function removes all receive buffers from the ring.
  2664. * The receive BMU must be stopped before calling this function.
  2665. *
  2666. * Returns: N/A
  2667. */
  2668. static void ClearRxRing(
  2669. SK_AC *pAC, /* pointer to adapter context */
  2670. RX_PORT *pRxPort) /* pointer to rx port struct */
  2671. {
  2672. RXD *pRxd; /* pointer to the current descriptor */
  2673. unsigned long Flags;
  2674. SK_U64 PhysAddr;
  2675. if (pRxPort->RxdRingFree == pAC->RxDescrPerRing) {
  2676. return;
  2677. }
  2678. spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
  2679. pRxd = pRxPort->pRxdRingHead;
  2680. do {
  2681. if (pRxd->pMBuf != NULL) {
  2682. PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
  2683. PhysAddr |= (SK_U64) pRxd->VDataLow;
  2684. pci_unmap_page(pAC->PciDev,
  2685. PhysAddr,
  2686. pAC->RxBufSize - 2,
  2687. PCI_DMA_FROMDEVICE);
  2688. DEV_KFREE_SKB(pRxd->pMBuf);
  2689. pRxd->pMBuf = NULL;
  2690. }
  2691. pRxd->RBControl &= RX_CTRL_OWN_BMU;
  2692. pRxd = pRxd->pNextRxd;
  2693. pRxPort->RxdRingFree++;
  2694. } while (pRxd != pRxPort->pRxdRingTail);
  2695. pRxPort->pRxdRingTail = pRxPort->pRxdRingHead;
  2696. spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
  2697. } /* ClearRxRing */
  2698. /*****************************************************************************
  2699. *
  2700. * ClearTxRing - remove all buffers from the transmit ring
  2701. *
  2702. * Description:
  2703. * This function removes all transmit buffers from the ring.
  2704. * The transmit BMU must be stopped before calling this function
  2705. * and transmitting at the upper level must be disabled.
  2706. * The BMU own bit of all descriptors is cleared, the rest is
  2707. * done by calling FreeTxDescriptors.
  2708. *
  2709. * Returns: N/A
  2710. */
  2711. static void ClearTxRing(
  2712. SK_AC *pAC, /* pointer to adapter context */
  2713. TX_PORT *pTxPort) /* pointer to tx prt struct */
  2714. {
  2715. TXD *pTxd; /* pointer to the current descriptor */
  2716. int i;
  2717. unsigned long Flags;
  2718. spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
  2719. pTxd = pTxPort->pTxdRingHead;
  2720. for (i=0; i<pAC->TxDescrPerRing; i++) {
  2721. pTxd->TBControl &= ~TX_CTRL_OWN_BMU;
  2722. pTxd = pTxd->pNextTxd;
  2723. }
  2724. FreeTxDescriptors(pAC, pTxPort);
  2725. spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
  2726. } /* ClearTxRing */
  2727. #if 0
  2728. /*****************************************************************************
  2729. *
  2730. * SetQueueSizes - configure the sizes of rx and tx queues
  2731. *
  2732. * Description:
  2733. * This function assigns the sizes for active and passive port
  2734. * to the appropriate HWinit structure variables.
  2735. * The passive port(s) get standard values, all remaining RAM
  2736. * is given to the active port.
  2737. * The queue sizes are in kbyte and must be multiple of 8.
  2738. * The limits for the number of buffers filled into the rx rings
  2739. * is also set in this routine.
  2740. *
  2741. * Returns:
  2742. * none
  2743. */
  2744. static void SetQueueSizes(
  2745. SK_AC *pAC) /* pointer to the adapter context */
  2746. {
  2747. int StandbyRam; /* adapter RAM used for a standby port */
  2748. int RemainingRam; /* adapter RAM available for the active port */
  2749. int RxRam; /* RAM used for the active port receive queue */
  2750. int i; /* loop counter */
  2751. if (pAC->RlmtNets == 1) {
  2752. StandbyRam = SK_RLMT_STANDBY_QRXSIZE + SK_RLMT_STANDBY_QXASIZE +
  2753. SK_RLMT_STANDBY_QXSSIZE;
  2754. RemainingRam = pAC->GIni.GIRamSize -
  2755. (pAC->GIni.GIMacsFound-1) * StandbyRam;
  2756. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  2757. pAC->GIni.GP[i].PRxQSize = SK_RLMT_STANDBY_QRXSIZE;
  2758. pAC->GIni.GP[i].PXSQSize = SK_RLMT_STANDBY_QXSSIZE;
  2759. pAC->GIni.GP[i].PXAQSize = SK_RLMT_STANDBY_QXASIZE;
  2760. }
  2761. RxRam = (RemainingRam * 8 / 10) & ~7;
  2762. pAC->GIni.GP[pAC->ActivePort].PRxQSize = RxRam;
  2763. pAC->GIni.GP[pAC->ActivePort].PXSQSize = 0;
  2764. pAC->GIni.GP[pAC->ActivePort].PXAQSize =
  2765. (RemainingRam - RxRam) & ~7;
  2766. pAC->RxQueueSize = RxRam;
  2767. pAC->TxSQueueSize = 0;
  2768. pAC->TxAQueueSize = (RemainingRam - RxRam) & ~7;
  2769. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2770. ("queue sizes settings - rx:%d txA:%d txS:%d\n",
  2771. pAC->RxQueueSize,pAC->TxAQueueSize, pAC->TxSQueueSize));
  2772. } else {
  2773. RemainingRam = pAC->GIni.GIRamSize/pAC->GIni.GIMacsFound;
  2774. RxRam = (RemainingRam * 8 / 10) & ~7;
  2775. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  2776. pAC->GIni.GP[i].PRxQSize = RxRam;
  2777. pAC->GIni.GP[i].PXSQSize = 0;
  2778. pAC->GIni.GP[i].PXAQSize = (RemainingRam - RxRam) & ~7;
  2779. }
  2780. pAC->RxQueueSize = RxRam;
  2781. pAC->TxSQueueSize = 0;
  2782. pAC->TxAQueueSize = (RemainingRam - RxRam) & ~7;
  2783. }
  2784. for (i=0; i<SK_MAX_MACS; i++) {
  2785. pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing;
  2786. }
  2787. if (pAC->RlmtNets == 2) {
  2788. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  2789. pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing - 100;
  2790. }
  2791. } else {
  2792. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  2793. pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing - 100;
  2794. }
  2795. /*
  2796. * Do not set the Limit to 0, because this could cause
  2797. * wrap around with ReQueue'ed buffers (a buffer could
  2798. * be requeued in the same position, made accessable to
  2799. * the hardware, and the hardware could change its
  2800. * contents!
  2801. */
  2802. pAC->RxPort[pAC->ActivePort].RxFillLimit = 1;
  2803. }
  2804. #ifdef DEBUG
  2805. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  2806. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
  2807. ("i: %d, RxQSize: %d, PXSQsize: %d, PXAQSize: %d\n",
  2808. i,
  2809. pAC->GIni.GP[i].PRxQSize,
  2810. pAC->GIni.GP[i].PXSQSize,
  2811. pAC->GIni.GP[i].PXAQSize));
  2812. }
  2813. #endif
  2814. } /* SetQueueSizes */
  2815. /*****************************************************************************
  2816. *
  2817. * SkGeSetMacAddr - Set the hardware MAC address
  2818. *
  2819. * Description:
  2820. * This function sets the MAC address used by the adapter.
  2821. *
  2822. * Returns:
  2823. * 0, if everything is ok
  2824. * !=0, on error
  2825. */
  2826. static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p)
  2827. {
  2828. DEV_NET *pNet = (DEV_NET*) dev->priv;
  2829. SK_AC *pAC = pNet->pAC;
  2830. struct sockaddr *addr = p;
  2831. unsigned long Flags;
  2832. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2833. ("SkGeSetMacAddr starts now...\n"));
  2834. if(netif_running(dev))
  2835. return -EBUSY;
  2836. memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
  2837. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  2838. if (pAC->RlmtNets == 2)
  2839. SkAddrOverride(pAC, pAC->IoBase, pNet->NetNr,
  2840. (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
  2841. else
  2842. SkAddrOverride(pAC, pAC->IoBase, pAC->ActivePort,
  2843. (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
  2844. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  2845. return 0;
  2846. } /* SkGeSetMacAddr */
  2847. #endif
  2848. /*****************************************************************************
  2849. *
  2850. * SkGeSetRxMode - set receive mode
  2851. *
  2852. * Description:
  2853. * This function sets the receive mode of an adapter. The adapter
  2854. * supports promiscuous mode, allmulticast mode and a number of
  2855. * multicast addresses. If more multicast addresses the available
  2856. * are selected, a hash function in the hardware is used.
  2857. *
  2858. * Returns:
  2859. * 0, if everything is ok
  2860. * !=0, on error
  2861. */
  2862. #if 0
  2863. static void SkGeSetRxMode(struct SK_NET_DEVICE *dev)
  2864. {
  2865. DEV_NET *pNet;
  2866. SK_AC *pAC;
  2867. struct dev_mc_list *pMcList;
  2868. int i;
  2869. int PortIdx;
  2870. unsigned long Flags;
  2871. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2872. ("SkGeSetRxMode starts now... "));
  2873. pNet = (DEV_NET*) dev->priv;
  2874. pAC = pNet->pAC;
  2875. if (pAC->RlmtNets == 1)
  2876. PortIdx = pAC->ActivePort;
  2877. else
  2878. PortIdx = pNet->NetNr;
  2879. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  2880. if (dev->flags & IFF_PROMISC) {
  2881. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2882. ("PROMISCUOUS mode\n"));
  2883. SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
  2884. SK_PROM_MODE_LLC);
  2885. } else if (dev->flags & IFF_ALLMULTI) {
  2886. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2887. ("ALLMULTI mode\n"));
  2888. SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
  2889. SK_PROM_MODE_ALL_MC);
  2890. } else {
  2891. SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
  2892. SK_PROM_MODE_NONE);
  2893. SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
  2894. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2895. ("Number of MC entries: %d ", dev->mc_count));
  2896. pMcList = dev->mc_list;
  2897. for (i=0; i<dev->mc_count; i++, pMcList = pMcList->next) {
  2898. SkAddrMcAdd(pAC, pAC->IoBase, PortIdx,
  2899. (SK_MAC_ADDR*)pMcList->dmi_addr, 0);
  2900. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_MCA,
  2901. ("%02x:%02x:%02x:%02x:%02x:%02x\n",
  2902. pMcList->dmi_addr[0],
  2903. pMcList->dmi_addr[1],
  2904. pMcList->dmi_addr[2],
  2905. pMcList->dmi_addr[3],
  2906. pMcList->dmi_addr[4],
  2907. pMcList->dmi_addr[5]));
  2908. }
  2909. SkAddrMcUpdate(pAC, pAC->IoBase, PortIdx);
  2910. }
  2911. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  2912. return;
  2913. } /* SkGeSetRxMode */
  2914. /*****************************************************************************
  2915. *
  2916. * SkGeChangeMtu - set the MTU to another value
  2917. *
  2918. * Description:
  2919. * This function sets is called whenever the MTU size is changed
  2920. * (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
  2921. * ethernet MTU size, long frame support is activated.
  2922. *
  2923. * Returns:
  2924. * 0, if everything is ok
  2925. * !=0, on error
  2926. */
  2927. static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int NewMtu)
  2928. {
  2929. DEV_NET *pNet;
  2930. DEV_NET *pOtherNet;
  2931. SK_AC *pAC;
  2932. unsigned long Flags;
  2933. int i;
  2934. SK_EVPARA EvPara;
  2935. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2936. ("SkGeChangeMtu starts now...\n"));
  2937. pNet = (DEV_NET*) dev->priv;
  2938. pAC = pNet->pAC;
  2939. if ((NewMtu < 68) || (NewMtu > SK_JUMBO_MTU)) {
  2940. return -EINVAL;
  2941. }
  2942. if(pAC->BoardLevel != 2) {
  2943. return -EINVAL;
  2944. }
  2945. pNet->Mtu = NewMtu;
  2946. pOtherNet = (DEV_NET*)pAC->dev[1 - pNet->NetNr]->priv;
  2947. if ((pOtherNet->Mtu > 1500) && (NewMtu <= 1500) && (pOtherNet->Up==1)) {
  2948. return(0);
  2949. }
  2950. EvPara.Para32[0] = pNet->NetNr;
  2951. EvPara.Para32[1] = -1;
  2952. pAC->RxBufSize = NewMtu + 32;
  2953. dev->mtu = NewMtu;
  2954. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2955. ("New MTU: %d\n", NewMtu));
  2956. /* prevent reconfiguration while changing the MTU */
  2957. /* disable interrupts */
  2958. SK_OUT32(pAC->IoBase, B0_IMSK, 0);
  2959. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  2960. /* Found more than one port */
  2961. if ((pAC->GIni.GIMacsFound == 2 ) &&
  2962. (pAC->RlmtNets == 2)) {
  2963. /* Stop both ports */
  2964. EvPara.Para32[0] = 0;
  2965. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
  2966. EvPara.Para32[0] = 1;
  2967. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
  2968. } else {
  2969. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
  2970. }
  2971. SkEventDispatcher(pAC, pAC->IoBase);
  2972. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  2973. spin_lock_irqsave(
  2974. &pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock, Flags);
  2975. netif_stop_queue(pAC->dev[i]);
  2976. }
  2977. /*
  2978. * adjust number of rx buffers allocated
  2979. */
  2980. if (NewMtu > 1500) {
  2981. /* use less rx buffers */
  2982. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  2983. /* Found more than one port */
  2984. if ((pAC->GIni.GIMacsFound == 2 ) &&
  2985. (pAC->RlmtNets == 2)) {
  2986. pAC->RxPort[i].RxFillLimit =
  2987. pAC->RxDescrPerRing - 100;
  2988. } else {
  2989. if (i == pAC->ActivePort)
  2990. pAC->RxPort[i].RxFillLimit =
  2991. pAC->RxDescrPerRing - 100;
  2992. else
  2993. pAC->RxPort[i].RxFillLimit =
  2994. pAC->RxDescrPerRing - 10;
  2995. }
  2996. }
  2997. }
  2998. else {
  2999. /* use normal amount of rx buffers */
  3000. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  3001. /* Found more than one port */
  3002. if ((pAC->GIni.GIMacsFound == 2 ) &&
  3003. (pAC->RlmtNets == 2)) {
  3004. pAC->RxPort[i].RxFillLimit = 1;
  3005. } else {
  3006. if (i == pAC->ActivePort)
  3007. pAC->RxPort[i].RxFillLimit = 1;
  3008. else
  3009. pAC->RxPort[i].RxFillLimit =
  3010. pAC->RxDescrPerRing - 100;
  3011. }
  3012. }
  3013. }
  3014. SkGeDeInit(pAC, pAC->IoBase);
  3015. /*
  3016. * enable/disable hardware support for long frames
  3017. */
  3018. if (NewMtu > 1500) {
  3019. /* pAC->JumboActivated = SK_TRUE; /#* is never set back !!! */
  3020. pAC->GIni.GIPortUsage = SK_JUMBO_LINK;
  3021. }
  3022. else {
  3023. if ((pAC->GIni.GIMacsFound == 2 ) &&
  3024. (pAC->RlmtNets == 2)) {
  3025. pAC->GIni.GIPortUsage = SK_MUL_LINK;
  3026. } else {
  3027. pAC->GIni.GIPortUsage = SK_RED_LINK;
  3028. }
  3029. }
  3030. SkGeInit( pAC, pAC->IoBase, 1);
  3031. SkI2cInit( pAC, pAC->IoBase, 1);
  3032. SkEventInit(pAC, pAC->IoBase, 1);
  3033. SkPnmiInit( pAC, pAC->IoBase, 1);
  3034. SkAddrInit( pAC, pAC->IoBase, 1);
  3035. SkRlmtInit( pAC, pAC->IoBase, 1);
  3036. SkTimerInit(pAC, pAC->IoBase, 1);
  3037. /*
  3038. * tschilling:
  3039. * Speed and others are set back to default in level 1 init!
  3040. */
  3041. GetConfiguration(pAC);
  3042. SkGeInit( pAC, pAC->IoBase, 2);
  3043. SkI2cInit( pAC, pAC->IoBase, 2);
  3044. SkEventInit(pAC, pAC->IoBase, 2);
  3045. SkPnmiInit( pAC, pAC->IoBase, 2);
  3046. SkAddrInit( pAC, pAC->IoBase, 2);
  3047. SkRlmtInit( pAC, pAC->IoBase, 2);
  3048. SkTimerInit(pAC, pAC->IoBase, 2);
  3049. /*
  3050. * clear and reinit the rx rings here
  3051. */
  3052. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  3053. ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
  3054. ClearRxRing(pAC, &pAC->RxPort[i]);
  3055. FillRxRing(pAC, &pAC->RxPort[i]);
  3056. /* Enable transmit descriptor polling. */
  3057. SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
  3058. FillRxRing(pAC, &pAC->RxPort[i]);
  3059. };
  3060. SkGeYellowLED(pAC, pAC->IoBase, 1);
  3061. #ifdef USE_INT_MOD
  3062. {
  3063. unsigned long ModBase;
  3064. ModBase = 53125000 / INTS_PER_SEC;
  3065. SK_OUT32(pAC->IoBase, B2_IRQM_INI, ModBase);
  3066. SK_OUT32(pAC->IoBase, B2_IRQM_MSK, IRQ_MOD_MASK);
  3067. SK_OUT32(pAC->IoBase, B2_IRQM_CTRL, TIM_START);
  3068. }
  3069. #endif
  3070. netif_start_queue(pAC->dev[pNet->PortNr]);
  3071. for (i=pAC->GIni.GIMacsFound-1; i>=0; i--) {
  3072. spin_unlock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
  3073. }
  3074. /* enable Interrupts */
  3075. SK_OUT32(pAC->IoBase, B0_IMSK, IRQ_MASK);
  3076. SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
  3077. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
  3078. SkEventDispatcher(pAC, pAC->IoBase);
  3079. /* Found more than one port */
  3080. if ((pAC->GIni.GIMacsFound == 2 ) &&
  3081. (pAC->RlmtNets == 2)) {
  3082. /* Start both ports */
  3083. EvPara.Para32[0] = pAC->RlmtNets;
  3084. EvPara.Para32[1] = -1;
  3085. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
  3086. EvPara);
  3087. EvPara.Para32[1] = -1;
  3088. EvPara.Para32[0] = pNet->PortNr;
  3089. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
  3090. if (pOtherNet->Up) {
  3091. EvPara.Para32[0] = pOtherNet->PortNr;
  3092. SkEventQueue(pAC, SKGE_RLMT,
  3093. SK_RLMT_START, EvPara);
  3094. }
  3095. } else {
  3096. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
  3097. }
  3098. SkEventDispatcher(pAC, pAC->IoBase);
  3099. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  3100. return 0;
  3101. } /* SkGeChangeMtu */
  3102. /*****************************************************************************
  3103. *
  3104. * SkGeStats - return ethernet device statistics
  3105. *
  3106. * Description:
  3107. * This function return statistic data about the ethernet device
  3108. * to the operating system.
  3109. *
  3110. * Returns:
  3111. * pointer to the statistic structure.
  3112. */
  3113. static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev)
  3114. {
  3115. DEV_NET *pNet = (DEV_NET*) dev->priv;
  3116. SK_AC *pAC = pNet->pAC;
  3117. SK_PNMI_STRUCT_DATA *pPnmiStruct; /* structure for all Pnmi-Data */
  3118. SK_PNMI_STAT *pPnmiStat; /* pointer to virtual XMAC stat. data */
  3119. SK_PNMI_CONF *pPnmiConf; /* pointer to virtual link config. */
  3120. unsigned int Size; /* size of pnmi struct */
  3121. unsigned long Flags; /* for spin lock */
  3122. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  3123. ("SkGeStats starts now...\n"));
  3124. pPnmiStruct = &pAC->PnmiStruct;
  3125. memset(pPnmiStruct, 0, sizeof(SK_PNMI_STRUCT_DATA));
  3126. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  3127. Size = SK_PNMI_STRUCT_SIZE;
  3128. SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size, pNet->NetNr);
  3129. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  3130. pPnmiStat = &pPnmiStruct->Stat[0];
  3131. pPnmiConf = &pPnmiStruct->Conf[0];
  3132. pAC->stats.rx_packets = (SK_U32) pPnmiStruct->RxDeliveredCts & 0xFFFFFFFF;
  3133. pAC->stats.tx_packets = (SK_U32) pPnmiStat->StatTxOkCts & 0xFFFFFFFF;
  3134. pAC->stats.rx_bytes = (SK_U32) pPnmiStruct->RxOctetsDeliveredCts;
  3135. pAC->stats.tx_bytes = (SK_U32) pPnmiStat->StatTxOctetsOkCts;
  3136. if (pNet->Mtu <= 1500) {
  3137. pAC->stats.rx_errors = (SK_U32) pPnmiStruct->InErrorsCts & 0xFFFFFFFF;
  3138. } else {
  3139. pAC->stats.rx_errors = (SK_U32) ((pPnmiStruct->InErrorsCts -
  3140. pPnmiStat->StatRxTooLongCts) & 0xFFFFFFFF);
  3141. }
  3142. if (pAC->GIni.GP[0].PhyType == SK_PHY_XMAC && pAC->HWRevision < 12)
  3143. pAC->stats.rx_errors = pAC->stats.rx_errors - pPnmiStat->StatRxShortsCts;
  3144. pAC->stats.tx_errors = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
  3145. pAC->stats.rx_dropped = (SK_U32) pPnmiStruct->RxNoBufCts & 0xFFFFFFFF;
  3146. pAC->stats.tx_dropped = (SK_U32) pPnmiStruct->TxNoBufCts & 0xFFFFFFFF;
  3147. pAC->stats.multicast = (SK_U32) pPnmiStat->StatRxMulticastOkCts & 0xFFFFFFFF;
  3148. pAC->stats.collisions = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
  3149. /* detailed rx_errors: */
  3150. pAC->stats.rx_length_errors = (SK_U32) pPnmiStat->StatRxRuntCts & 0xFFFFFFFF;
  3151. pAC->stats.rx_over_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
  3152. pAC->stats.rx_crc_errors = (SK_U32) pPnmiStat->StatRxFcsCts & 0xFFFFFFFF;
  3153. pAC->stats.rx_frame_errors = (SK_U32) pPnmiStat->StatRxFramingCts & 0xFFFFFFFF;
  3154. pAC->stats.rx_fifo_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
  3155. pAC->stats.rx_missed_errors = (SK_U32) pPnmiStat->StatRxMissedCts & 0xFFFFFFFF;
  3156. /* detailed tx_errors */
  3157. pAC->stats.tx_aborted_errors = (SK_U32) 0;
  3158. pAC->stats.tx_carrier_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
  3159. pAC->stats.tx_fifo_errors = (SK_U32) pPnmiStat->StatTxFifoUnderrunCts & 0xFFFFFFFF;
  3160. pAC->stats.tx_heartbeat_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
  3161. pAC->stats.tx_window_errors = (SK_U32) 0;
  3162. return(&pAC->stats);
  3163. } /* SkGeStats */
  3164. /*****************************************************************************
  3165. *
  3166. * SkGeIoctl - IO-control function
  3167. *
  3168. * Description:
  3169. * This function is called if an ioctl is issued on the device.
  3170. * There are three subfunction for reading, writing and test-writing
  3171. * the private MIB data structure (usefull for SysKonnect-internal tools).
  3172. *
  3173. * Returns:
  3174. * 0, if everything is ok
  3175. * !=0, on error
  3176. */
  3177. static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd)
  3178. {
  3179. DEV_NET *pNet;
  3180. SK_AC *pAC;
  3181. SK_GE_IOCTL Ioctl;
  3182. unsigned int Err = 0;
  3183. int Size;
  3184. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  3185. ("SkGeIoctl starts now...\n"));
  3186. pNet = (DEV_NET*) dev->priv;
  3187. pAC = pNet->pAC;
  3188. if(copy_from_user(&Ioctl, rq->ifr_data, sizeof(SK_GE_IOCTL))) {
  3189. return -EFAULT;
  3190. }
  3191. switch(cmd) {
  3192. case SK_IOCTL_SETMIB:
  3193. case SK_IOCTL_PRESETMIB:
  3194. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  3195. case SK_IOCTL_GETMIB:
  3196. if(copy_from_user(&pAC->PnmiStruct, Ioctl.pData,
  3197. Ioctl.Len<sizeof(pAC->PnmiStruct)?
  3198. Ioctl.Len : sizeof(pAC->PnmiStruct))) {
  3199. return -EFAULT;
  3200. }
  3201. Size = SkGeIocMib(pNet, Ioctl.Len, cmd);
  3202. if(copy_to_user(Ioctl.pData, &pAC->PnmiStruct,
  3203. Ioctl.Len<Size? Ioctl.Len : Size)) {
  3204. return -EFAULT;
  3205. }
  3206. Ioctl.Len = Size;
  3207. if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
  3208. return -EFAULT;
  3209. }
  3210. break;
  3211. default:
  3212. Err = -EOPNOTSUPP;
  3213. }
  3214. return(Err);
  3215. } /* SkGeIoctl */
  3216. /*****************************************************************************
  3217. *
  3218. * SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
  3219. *
  3220. * Description:
  3221. * This function reads/writes the MIB data using PNMI (Private Network
  3222. * Management Interface).
  3223. * The destination for the data must be provided with the
  3224. * ioctl call and is given to the driver in the form of
  3225. * a user space address.
  3226. * Copying from the user-provided data area into kernel messages
  3227. * and back is done by copy_from_user and copy_to_user calls in
  3228. * SkGeIoctl.
  3229. *
  3230. * Returns:
  3231. * returned size from PNMI call
  3232. */
  3233. static int SkGeIocMib(
  3234. DEV_NET *pNet, /* pointer to the adapter context */
  3235. unsigned int Size, /* length of ioctl data */
  3236. int mode) /* flag for set/preset */
  3237. {
  3238. unsigned long Flags; /* for spin lock */
  3239. SK_AC *pAC;
  3240. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  3241. ("SkGeIocMib starts now...\n"));
  3242. pAC = pNet->pAC;
  3243. /* access MIB */
  3244. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  3245. switch(mode) {
  3246. case SK_IOCTL_GETMIB:
  3247. SkPnmiGetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
  3248. pNet->NetNr);
  3249. break;
  3250. case SK_IOCTL_PRESETMIB:
  3251. SkPnmiPreSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
  3252. pNet->NetNr);
  3253. break;
  3254. case SK_IOCTL_SETMIB:
  3255. SkPnmiSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
  3256. pNet->NetNr);
  3257. break;
  3258. default:
  3259. break;
  3260. }
  3261. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  3262. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  3263. ("MIB data access succeeded\n"));
  3264. return (Size);
  3265. } /* SkGeIocMib */
  3266. #endif
  3267. /*****************************************************************************
  3268. *
  3269. * GetConfiguration - read configuration information
  3270. *
  3271. * Description:
  3272. * This function reads per-adapter configuration information from
  3273. * the options provided on the command line.
  3274. *
  3275. * Returns:
  3276. * none
  3277. */
  3278. static void GetConfiguration(
  3279. SK_AC *pAC) /* pointer to the adapter context structure */
  3280. {
  3281. SK_I32 Port; /* preferred port */
  3282. int LinkSpeed; /* Link speed */
  3283. int AutoNeg; /* auto negotiation off (0) or on (1) */
  3284. int DuplexCap; /* duplex capabilities (0=both, 1=full, 2=half */
  3285. int MSMode; /* master / slave mode selection */
  3286. SK_BOOL AutoSet;
  3287. SK_BOOL DupSet;
  3288. /*
  3289. * The two parameters AutoNeg. and DuplexCap. map to one configuration
  3290. * parameter. The mapping is described by this table:
  3291. * DuplexCap -> | both | full | half |
  3292. * AutoNeg | | | |
  3293. * -----------------------------------------------------------------
  3294. * Off | illegal | Full | Half |
  3295. * -----------------------------------------------------------------
  3296. * On | AutoBoth | AutoFull | AutoHalf |
  3297. * -----------------------------------------------------------------
  3298. * Sense | AutoSense | AutoSense | AutoSense |
  3299. */
  3300. int Capabilities[3][3] =
  3301. { { -1, SK_LMODE_FULL, SK_LMODE_HALF},
  3302. {SK_LMODE_AUTOBOTH, SK_LMODE_AUTOFULL, SK_LMODE_AUTOHALF},
  3303. {SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE} };
  3304. #define DC_BOTH 0
  3305. #define DC_FULL 1
  3306. #define DC_HALF 2
  3307. #define AN_OFF 0
  3308. #define AN_ON 1
  3309. #define AN_SENS 2
  3310. /* settings for port A */
  3311. /* settings link speed */
  3312. LinkSpeed = SK_LSPEED_AUTO; /* default: do auto select */
  3313. if (Speed_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3314. Speed_A[pAC->Index] != NULL) {
  3315. if (strcmp(Speed_A[pAC->Index],"")==0) {
  3316. LinkSpeed = SK_LSPEED_AUTO;
  3317. }
  3318. else if (strcmp(Speed_A[pAC->Index],"Auto")==0) {
  3319. LinkSpeed = SK_LSPEED_AUTO;
  3320. }
  3321. else if (strcmp(Speed_A[pAC->Index],"10")==0) {
  3322. LinkSpeed = SK_LSPEED_10MBPS;
  3323. }
  3324. else if (strcmp(Speed_A[pAC->Index],"100")==0) {
  3325. LinkSpeed = SK_LSPEED_100MBPS;
  3326. }
  3327. else if (strcmp(Speed_A[pAC->Index],"1000")==0) {
  3328. LinkSpeed = SK_LSPEED_1000MBPS;
  3329. }
  3330. else printk("%s: Illegal value for Speed_A\n",
  3331. pAC->dev[0]->name);
  3332. }
  3333. /* Check speed parameter */
  3334. /* Only copper type adapter and GE V2 cards */
  3335. if (((pAC->GIni.GIChipId != CHIP_ID_YUKON) ||
  3336. (pAC->GIni.GICopperType != SK_TRUE)) &&
  3337. ((LinkSpeed != SK_LSPEED_AUTO) &&
  3338. (LinkSpeed != SK_LSPEED_1000MBPS))) {
  3339. printk("%s: Illegal value for Speed_A. "
  3340. "Not a copper card or GE V2 card\n Using "
  3341. "speed 1000\n", pAC->dev[0]->name);
  3342. LinkSpeed = SK_LSPEED_1000MBPS;
  3343. }
  3344. pAC->GIni.GP[0].PLinkSpeed = LinkSpeed;
  3345. /* Autonegotiation */
  3346. AutoNeg = AN_ON; /* tschilling: Default: Autonegotiation on! */
  3347. AutoSet = SK_FALSE;
  3348. if (AutoNeg_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3349. AutoNeg_A[pAC->Index] != NULL) {
  3350. AutoSet = SK_TRUE;
  3351. if (strcmp(AutoNeg_A[pAC->Index],"")==0) {
  3352. AutoSet = SK_FALSE;
  3353. }
  3354. else if (strcmp(AutoNeg_A[pAC->Index],"On")==0) {
  3355. AutoNeg = AN_ON;
  3356. }
  3357. else if (strcmp(AutoNeg_A[pAC->Index],"Off")==0) {
  3358. AutoNeg = AN_OFF;
  3359. }
  3360. else if (strcmp(AutoNeg_A[pAC->Index],"Sense")==0) {
  3361. AutoNeg = AN_SENS;
  3362. }
  3363. else printk("%s: Illegal value for AutoNeg_A\n",
  3364. pAC->dev[0]->name);
  3365. }
  3366. DuplexCap = DC_BOTH;
  3367. DupSet = SK_FALSE;
  3368. if (DupCap_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3369. DupCap_A[pAC->Index] != NULL) {
  3370. DupSet = SK_TRUE;
  3371. if (strcmp(DupCap_A[pAC->Index],"")==0) {
  3372. DupSet = SK_FALSE;
  3373. }
  3374. else if (strcmp(DupCap_A[pAC->Index],"Both")==0) {
  3375. DuplexCap = DC_BOTH;
  3376. }
  3377. else if (strcmp(DupCap_A[pAC->Index],"Full")==0) {
  3378. DuplexCap = DC_FULL;
  3379. }
  3380. else if (strcmp(DupCap_A[pAC->Index],"Half")==0) {
  3381. DuplexCap = DC_HALF;
  3382. }
  3383. else printk("%s: Illegal value for DupCap_A\n",
  3384. pAC->dev[0]->name);
  3385. }
  3386. /* check for illegal combinations */
  3387. if (AutoSet && AutoNeg==AN_SENS && DupSet) {
  3388. printk("%s, Port A: DuplexCapabilities"
  3389. " ignored using Sense mode\n", pAC->dev[0]->name);
  3390. }
  3391. if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
  3392. printk("%s, Port A: Illegal combination"
  3393. " of values AutoNeg. and DuplexCap.\n Using "
  3394. "Full Duplex\n", pAC->dev[0]->name);
  3395. DuplexCap = DC_FULL;
  3396. }
  3397. if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
  3398. DuplexCap = DC_FULL;
  3399. }
  3400. if (!AutoSet && DupSet) {
  3401. printk("%s, Port A: Duplex setting not"
  3402. " possible in\n default AutoNegotiation mode"
  3403. " (Sense).\n Using AutoNegotiation On\n",
  3404. pAC->dev[0]->name);
  3405. AutoNeg = AN_ON;
  3406. }
  3407. /* set the desired mode */
  3408. pAC->GIni.GP[0].PLinkModeConf =
  3409. Capabilities[AutoNeg][DuplexCap];
  3410. pAC->GIni.GP[0].PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
  3411. if (FlowCtrl_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3412. FlowCtrl_A[pAC->Index] != NULL) {
  3413. if (strcmp(FlowCtrl_A[pAC->Index],"") == 0) {
  3414. }
  3415. else if (strcmp(FlowCtrl_A[pAC->Index],"SymOrRem") == 0) {
  3416. pAC->GIni.GP[0].PFlowCtrlMode =
  3417. SK_FLOW_MODE_SYM_OR_REM;
  3418. }
  3419. else if (strcmp(FlowCtrl_A[pAC->Index],"Sym")==0) {
  3420. pAC->GIni.GP[0].PFlowCtrlMode =
  3421. SK_FLOW_MODE_SYMMETRIC;
  3422. }
  3423. else if (strcmp(FlowCtrl_A[pAC->Index],"LocSend")==0) {
  3424. pAC->GIni.GP[0].PFlowCtrlMode =
  3425. SK_FLOW_MODE_LOC_SEND;
  3426. }
  3427. else if (strcmp(FlowCtrl_A[pAC->Index],"None")==0) {
  3428. pAC->GIni.GP[0].PFlowCtrlMode =
  3429. SK_FLOW_MODE_NONE;
  3430. }
  3431. else printk("Illegal value for FlowCtrl_A\n");
  3432. }
  3433. if (AutoNeg==AN_OFF && pAC->GIni.GP[0].PFlowCtrlMode!=
  3434. SK_FLOW_MODE_NONE) {
  3435. printk("%s, Port A: FlowControl"
  3436. " impossible without AutoNegotiation,"
  3437. " disabled\n", pAC->dev[0]->name);
  3438. pAC->GIni.GP[0].PFlowCtrlMode = SK_FLOW_MODE_NONE;
  3439. }
  3440. MSMode = SK_MS_MODE_AUTO; /* default: do auto select */
  3441. if (Role_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3442. Role_A[pAC->Index] != NULL) {
  3443. if (strcmp(Role_A[pAC->Index],"")==0) {
  3444. }
  3445. else if (strcmp(Role_A[pAC->Index],"Auto")==0) {
  3446. MSMode = SK_MS_MODE_AUTO;
  3447. }
  3448. else if (strcmp(Role_A[pAC->Index],"Master")==0) {
  3449. MSMode = SK_MS_MODE_MASTER;
  3450. }
  3451. else if (strcmp(Role_A[pAC->Index],"Slave")==0) {
  3452. MSMode = SK_MS_MODE_SLAVE;
  3453. }
  3454. else printk("%s: Illegal value for Role_A\n",
  3455. pAC->dev[0]->name);
  3456. }
  3457. pAC->GIni.GP[0].PMSMode = MSMode;
  3458. /* settings for port B */
  3459. /* settings link speed */
  3460. LinkSpeed = SK_LSPEED_AUTO; /* default: do auto select */
  3461. if (Speed_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3462. Speed_B[pAC->Index] != NULL) {
  3463. if (strcmp(Speed_B[pAC->Index],"")==0) {
  3464. LinkSpeed = SK_LSPEED_AUTO;
  3465. }
  3466. else if (strcmp(Speed_B[pAC->Index],"Auto")==0) {
  3467. LinkSpeed = SK_LSPEED_AUTO;
  3468. }
  3469. else if (strcmp(Speed_B[pAC->Index],"10")==0) {
  3470. LinkSpeed = SK_LSPEED_10MBPS;
  3471. }
  3472. else if (strcmp(Speed_B[pAC->Index],"100")==0) {
  3473. LinkSpeed = SK_LSPEED_100MBPS;
  3474. }
  3475. else if (strcmp(Speed_B[pAC->Index],"1000")==0) {
  3476. LinkSpeed = SK_LSPEED_1000MBPS;
  3477. }
  3478. else printk("%s: Illegal value for Speed_B\n",
  3479. pAC->dev[1]->name);
  3480. }
  3481. /* Check speed parameter */
  3482. /* Only copper type adapter and GE V2 cards */
  3483. if (((pAC->GIni.GIChipId != CHIP_ID_YUKON) ||
  3484. (pAC->GIni.GICopperType != SK_TRUE)) &&
  3485. ((LinkSpeed != SK_LSPEED_AUTO) &&
  3486. (LinkSpeed != SK_LSPEED_1000MBPS))) {
  3487. printk("%s: Illegal value for Speed_B. "
  3488. "Not a copper card or GE V2 card\n Using "
  3489. "speed 1000\n", pAC->dev[1]->name);
  3490. LinkSpeed = SK_LSPEED_1000MBPS;
  3491. }
  3492. pAC->GIni.GP[1].PLinkSpeed = LinkSpeed;
  3493. /* Auto negotiation */
  3494. AutoNeg = AN_SENS; /* default: do auto Sense */
  3495. AutoSet = SK_FALSE;
  3496. if (AutoNeg_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3497. AutoNeg_B[pAC->Index] != NULL) {
  3498. AutoSet = SK_TRUE;
  3499. if (strcmp(AutoNeg_B[pAC->Index],"")==0) {
  3500. AutoSet = SK_FALSE;
  3501. }
  3502. else if (strcmp(AutoNeg_B[pAC->Index],"On")==0) {
  3503. AutoNeg = AN_ON;
  3504. }
  3505. else if (strcmp(AutoNeg_B[pAC->Index],"Off")==0) {
  3506. AutoNeg = AN_OFF;
  3507. }
  3508. else if (strcmp(AutoNeg_B[pAC->Index],"Sense")==0) {
  3509. AutoNeg = AN_SENS;
  3510. }
  3511. else printk("Illegal value for AutoNeg_B\n");
  3512. }
  3513. DuplexCap = DC_BOTH;
  3514. DupSet = SK_FALSE;
  3515. if (DupCap_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3516. DupCap_B[pAC->Index] != NULL) {
  3517. DupSet = SK_TRUE;
  3518. if (strcmp(DupCap_B[pAC->Index],"")==0) {
  3519. DupSet = SK_FALSE;
  3520. }
  3521. else if (strcmp(DupCap_B[pAC->Index],"Both")==0) {
  3522. DuplexCap = DC_BOTH;
  3523. }
  3524. else if (strcmp(DupCap_B[pAC->Index],"Full")==0) {
  3525. DuplexCap = DC_FULL;
  3526. }
  3527. else if (strcmp(DupCap_B[pAC->Index],"Half")==0) {
  3528. DuplexCap = DC_HALF;
  3529. }
  3530. else printk("Illegal value for DupCap_B\n");
  3531. }
  3532. /* check for illegal combinations */
  3533. if (AutoSet && AutoNeg==AN_SENS && DupSet) {
  3534. printk("%s, Port B: DuplexCapabilities"
  3535. " ignored using Sense mode\n", pAC->dev[1]->name);
  3536. }
  3537. if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
  3538. printk("%s, Port B: Illegal combination"
  3539. " of values AutoNeg. and DuplexCap.\n Using "
  3540. "Full Duplex\n", pAC->dev[1]->name);
  3541. DuplexCap = DC_FULL;
  3542. }
  3543. if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
  3544. DuplexCap = DC_FULL;
  3545. }
  3546. if (!AutoSet && DupSet) {
  3547. printk("%s, Port B: Duplex setting not"
  3548. " possible in\n default AutoNegotiation mode"
  3549. " (Sense).\n Using AutoNegotiation On\n",
  3550. pAC->dev[1]->name);
  3551. AutoNeg = AN_ON;
  3552. }
  3553. /* set the desired mode */
  3554. pAC->GIni.GP[1].PLinkModeConf =
  3555. Capabilities[AutoNeg][DuplexCap];
  3556. pAC->GIni.GP[1].PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
  3557. if (FlowCtrl_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3558. FlowCtrl_B[pAC->Index] != NULL) {
  3559. if (strcmp(FlowCtrl_B[pAC->Index],"") == 0) {
  3560. }
  3561. else if (strcmp(FlowCtrl_B[pAC->Index],"SymOrRem") == 0) {
  3562. pAC->GIni.GP[1].PFlowCtrlMode =
  3563. SK_FLOW_MODE_SYM_OR_REM;
  3564. }
  3565. else if (strcmp(FlowCtrl_B[pAC->Index],"Sym")==0) {
  3566. pAC->GIni.GP[1].PFlowCtrlMode =
  3567. SK_FLOW_MODE_SYMMETRIC;
  3568. }
  3569. else if (strcmp(FlowCtrl_B[pAC->Index],"LocSend")==0) {
  3570. pAC->GIni.GP[1].PFlowCtrlMode =
  3571. SK_FLOW_MODE_LOC_SEND;
  3572. }
  3573. else if (strcmp(FlowCtrl_B[pAC->Index],"None")==0) {
  3574. pAC->GIni.GP[1].PFlowCtrlMode =
  3575. SK_FLOW_MODE_NONE;
  3576. }
  3577. else printk("Illegal value for FlowCtrl_B\n");
  3578. }
  3579. if (AutoNeg==AN_OFF && pAC->GIni.GP[1].PFlowCtrlMode!=
  3580. SK_FLOW_MODE_NONE) {
  3581. printk("%s, Port B: FlowControl"
  3582. " impossible without AutoNegotiation,"
  3583. " disabled\n", pAC->dev[1]->name);
  3584. pAC->GIni.GP[1].PFlowCtrlMode = SK_FLOW_MODE_NONE;
  3585. }
  3586. MSMode = SK_MS_MODE_AUTO; /* default: do auto select */
  3587. if (Role_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3588. Role_B[pAC->Index] != NULL) {
  3589. if (strcmp(Role_B[pAC->Index],"")==0) {
  3590. }
  3591. else if (strcmp(Role_B[pAC->Index],"Auto")==0) {
  3592. MSMode = SK_MS_MODE_AUTO;
  3593. }
  3594. else if (strcmp(Role_B[pAC->Index],"Master")==0) {
  3595. MSMode = SK_MS_MODE_MASTER;
  3596. }
  3597. else if (strcmp(Role_B[pAC->Index],"Slave")==0) {
  3598. MSMode = SK_MS_MODE_SLAVE;
  3599. }
  3600. else printk("%s: Illegal value for Role_B\n",
  3601. pAC->dev[1]->name);
  3602. }
  3603. pAC->GIni.GP[1].PMSMode = MSMode;
  3604. /* settings for both ports */
  3605. pAC->ActivePort = 0;
  3606. if (PrefPort != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3607. PrefPort[pAC->Index] != NULL) {
  3608. if (strcmp(PrefPort[pAC->Index],"") == 0) { /* Auto */
  3609. pAC->ActivePort = 0;
  3610. pAC->Rlmt.Net[0].Preference = -1; /* auto */
  3611. pAC->Rlmt.Net[0].PrefPort = 0;
  3612. }
  3613. else if (strcmp(PrefPort[pAC->Index],"A") == 0) {
  3614. /*
  3615. * do not set ActivePort here, thus a port
  3616. * switch is issued after net up.
  3617. */
  3618. Port = 0;
  3619. pAC->Rlmt.Net[0].Preference = Port;
  3620. pAC->Rlmt.Net[0].PrefPort = Port;
  3621. }
  3622. else if (strcmp(PrefPort[pAC->Index],"B") == 0) {
  3623. /*
  3624. * do not set ActivePort here, thus a port
  3625. * switch is issued after net up.
  3626. */
  3627. Port = 1;
  3628. pAC->Rlmt.Net[0].Preference = Port;
  3629. pAC->Rlmt.Net[0].PrefPort = Port;
  3630. }
  3631. else printk("%s: Illegal value for PrefPort\n",
  3632. pAC->dev[0]->name);
  3633. }
  3634. pAC->RlmtNets = 1;
  3635. if (RlmtMode != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3636. RlmtMode[pAC->Index] != NULL) {
  3637. if (strcmp(RlmtMode[pAC->Index], "") == 0) {
  3638. pAC->RlmtMode = 0;
  3639. }
  3640. else if (strcmp(RlmtMode[pAC->Index], "CheckLinkState") == 0) {
  3641. pAC->RlmtMode = SK_RLMT_CHECK_LINK;
  3642. }
  3643. else if (strcmp(RlmtMode[pAC->Index], "CheckLocalPort") == 0) {
  3644. pAC->RlmtMode = SK_RLMT_CHECK_LINK |
  3645. SK_RLMT_CHECK_LOC_LINK;
  3646. }
  3647. else if (strcmp(RlmtMode[pAC->Index], "CheckSeg") == 0) {
  3648. pAC->RlmtMode = SK_RLMT_CHECK_LINK |
  3649. SK_RLMT_CHECK_LOC_LINK |
  3650. SK_RLMT_CHECK_SEG;
  3651. }
  3652. else if ((strcmp(RlmtMode[pAC->Index], "DualNet") == 0) &&
  3653. (pAC->GIni.GIMacsFound == 2)) {
  3654. pAC->RlmtMode = SK_RLMT_CHECK_LINK;
  3655. pAC->RlmtNets = 2;
  3656. }
  3657. else {
  3658. printk("%s: Illegal value for"
  3659. " RlmtMode, using default\n", pAC->dev[0]->name);
  3660. pAC->RlmtMode = 0;
  3661. }
  3662. }
  3663. else {
  3664. pAC->RlmtMode = 0;
  3665. }
  3666. } /* GetConfiguration */
  3667. /*****************************************************************************
  3668. *
  3669. * ProductStr - return a adapter identification string from vpd
  3670. *
  3671. * Description:
  3672. * This function reads the product name string from the vpd area
  3673. * and puts it the field pAC->DeviceString.
  3674. *
  3675. * Returns: N/A
  3676. */
  3677. static void ProductStr(
  3678. SK_AC *pAC /* pointer to adapter context */
  3679. )
  3680. {
  3681. int StrLen = 80; /* length of the string, defined in SK_AC */
  3682. char Keyword[] = VPD_NAME; /* vpd productname identifier */
  3683. int ReturnCode; /* return code from vpd_read */
  3684. unsigned long Flags;
  3685. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  3686. ReturnCode = VpdRead(pAC, pAC->IoBase, Keyword, pAC->DeviceStr,
  3687. &StrLen);
  3688. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  3689. if (ReturnCode != 0) {
  3690. /* there was an error reading the vpd data */
  3691. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
  3692. ("Error reading VPD data: %d\n", ReturnCode));
  3693. pAC->DeviceStr[0] = '\0';
  3694. }
  3695. } /* ProductStr */
  3696. /****************************************************************************/
  3697. /* functions for common modules *********************************************/
  3698. /****************************************************************************/
  3699. /*****************************************************************************
  3700. *
  3701. * SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
  3702. *
  3703. * Description:
  3704. * This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
  3705. * is embedded into a socket buff data area.
  3706. *
  3707. * Context:
  3708. * runtime
  3709. *
  3710. * Returns:
  3711. * NULL or pointer to Mbuf.
  3712. */
  3713. SK_MBUF *SkDrvAllocRlmtMbuf(
  3714. SK_AC *pAC, /* pointer to adapter context */
  3715. SK_IOC IoC, /* the IO-context */
  3716. unsigned BufferSize) /* size of the requested buffer */
  3717. {
  3718. SK_MBUF *pRlmtMbuf; /* pointer to a new rlmt-mbuf structure */
  3719. struct sk_buff *pMsgBlock; /* pointer to a new message block */
  3720. pMsgBlock = alloc_skb(BufferSize + sizeof(SK_MBUF), GFP_ATOMIC);
  3721. if (pMsgBlock == NULL) {
  3722. return (NULL);
  3723. }
  3724. pRlmtMbuf = (SK_MBUF*) pMsgBlock->data;
  3725. skb_reserve(pMsgBlock, sizeof(SK_MBUF));
  3726. pRlmtMbuf->pNext = NULL;
  3727. pRlmtMbuf->pOs = pMsgBlock;
  3728. pRlmtMbuf->pData = pMsgBlock->data; /* Data buffer. */
  3729. pRlmtMbuf->Size = BufferSize; /* Data buffer size. */
  3730. pRlmtMbuf->Length = 0; /* Length of packet (<= Size). */
  3731. return (pRlmtMbuf);
  3732. } /* SkDrvAllocRlmtMbuf */
  3733. /*****************************************************************************
  3734. *
  3735. * SkDrvFreeRlmtMbuf - free an RLMT mbuf
  3736. *
  3737. * Description:
  3738. * This routine frees one or more RLMT mbuf(s).
  3739. *
  3740. * Context:
  3741. * runtime
  3742. *
  3743. * Returns:
  3744. * Nothing
  3745. */
  3746. void SkDrvFreeRlmtMbuf(
  3747. SK_AC *pAC, /* pointer to adapter context */
  3748. SK_IOC IoC, /* the IO-context */
  3749. SK_MBUF *pMbuf) /* size of the requested buffer */
  3750. {
  3751. SK_MBUF *pFreeMbuf;
  3752. SK_MBUF *pNextMbuf;
  3753. pFreeMbuf = pMbuf;
  3754. do {
  3755. pNextMbuf = pFreeMbuf->pNext;
  3756. DEV_KFREE_SKB_ANY(pFreeMbuf->pOs);
  3757. pFreeMbuf = pNextMbuf;
  3758. } while ( pFreeMbuf != NULL );
  3759. } /* SkDrvFreeRlmtMbuf */
  3760. /*****************************************************************************
  3761. *
  3762. * SkOsGetTime - provide a time value
  3763. *
  3764. * Description:
  3765. * This routine provides a time value. The unit is 1/HZ (defined by Linux).
  3766. * It is not used for absolute time, but only for time differences.
  3767. *
  3768. *
  3769. * Returns:
  3770. * Time value
  3771. */
  3772. SK_U64 SkOsGetTime(SK_AC *pAC)
  3773. {
  3774. #if 0
  3775. return jiffies;
  3776. #else
  3777. return get_timer(0);
  3778. #endif
  3779. } /* SkOsGetTime */
  3780. /*****************************************************************************
  3781. *
  3782. * SkPciReadCfgDWord - read a 32 bit value from pci config space
  3783. *
  3784. * Description:
  3785. * This routine reads a 32 bit value from the pci configuration
  3786. * space.
  3787. *
  3788. * Returns:
  3789. * 0 - indicate everything worked ok.
  3790. * != 0 - error indication
  3791. */
  3792. int SkPciReadCfgDWord(
  3793. SK_AC *pAC, /* Adapter Control structure pointer */
  3794. int PciAddr, /* PCI register address */
  3795. SK_U32 *pVal) /* pointer to store the read value */
  3796. {
  3797. pci_read_config_dword(pAC->PciDev, PciAddr, pVal);
  3798. return(0);
  3799. } /* SkPciReadCfgDWord */
  3800. /*****************************************************************************
  3801. *
  3802. * SkPciReadCfgWord - read a 16 bit value from pci config space
  3803. *
  3804. * Description:
  3805. * This routine reads a 16 bit value from the pci configuration
  3806. * space.
  3807. *
  3808. * Returns:
  3809. * 0 - indicate everything worked ok.
  3810. * != 0 - error indication
  3811. */
  3812. int SkPciReadCfgWord(
  3813. SK_AC *pAC, /* Adapter Control structure pointer */
  3814. int PciAddr, /* PCI register address */
  3815. SK_U16 *pVal) /* pointer to store the read value */
  3816. {
  3817. pci_read_config_word(pAC->PciDev, PciAddr, pVal);
  3818. return(0);
  3819. } /* SkPciReadCfgWord */
  3820. /*****************************************************************************
  3821. *
  3822. * SkPciReadCfgByte - read a 8 bit value from pci config space
  3823. *
  3824. * Description:
  3825. * This routine reads a 8 bit value from the pci configuration
  3826. * space.
  3827. *
  3828. * Returns:
  3829. * 0 - indicate everything worked ok.
  3830. * != 0 - error indication
  3831. */
  3832. int SkPciReadCfgByte(
  3833. SK_AC *pAC, /* Adapter Control structure pointer */
  3834. int PciAddr, /* PCI register address */
  3835. SK_U8 *pVal) /* pointer to store the read value */
  3836. {
  3837. pci_read_config_byte(pAC->PciDev, PciAddr, pVal);
  3838. return(0);
  3839. } /* SkPciReadCfgByte */
  3840. /*****************************************************************************
  3841. *
  3842. * SkPciWriteCfgDWord - write a 32 bit value to pci config space
  3843. *
  3844. * Description:
  3845. * This routine writes a 32 bit value to the pci configuration
  3846. * space.
  3847. *
  3848. * Returns:
  3849. * 0 - indicate everything worked ok.
  3850. * != 0 - error indication
  3851. */
  3852. int SkPciWriteCfgDWord(
  3853. SK_AC *pAC, /* Adapter Control structure pointer */
  3854. int PciAddr, /* PCI register address */
  3855. SK_U32 Val) /* pointer to store the read value */
  3856. {
  3857. pci_write_config_dword(pAC->PciDev, PciAddr, Val);
  3858. return(0);
  3859. } /* SkPciWriteCfgDWord */
  3860. /*****************************************************************************
  3861. *
  3862. * SkPciWriteCfgWord - write a 16 bit value to pci config space
  3863. *
  3864. * Description:
  3865. * This routine writes a 16 bit value to the pci configuration
  3866. * space. The flag PciConfigUp indicates whether the config space
  3867. * is accesible or must be set up first.
  3868. *
  3869. * Returns:
  3870. * 0 - indicate everything worked ok.
  3871. * != 0 - error indication
  3872. */
  3873. int SkPciWriteCfgWord(
  3874. SK_AC *pAC, /* Adapter Control structure pointer */
  3875. int PciAddr, /* PCI register address */
  3876. SK_U16 Val) /* pointer to store the read value */
  3877. {
  3878. pci_write_config_word(pAC->PciDev, PciAddr, Val);
  3879. return(0);
  3880. } /* SkPciWriteCfgWord */
  3881. /*****************************************************************************
  3882. *
  3883. * SkPciWriteCfgWord - write a 8 bit value to pci config space
  3884. *
  3885. * Description:
  3886. * This routine writes a 8 bit value to the pci configuration
  3887. * space. The flag PciConfigUp indicates whether the config space
  3888. * is accesible or must be set up first.
  3889. *
  3890. * Returns:
  3891. * 0 - indicate everything worked ok.
  3892. * != 0 - error indication
  3893. */
  3894. int SkPciWriteCfgByte(
  3895. SK_AC *pAC, /* Adapter Control structure pointer */
  3896. int PciAddr, /* PCI register address */
  3897. SK_U8 Val) /* pointer to store the read value */
  3898. {
  3899. pci_write_config_byte(pAC->PciDev, PciAddr, Val);
  3900. return(0);
  3901. } /* SkPciWriteCfgByte */
  3902. /*****************************************************************************
  3903. *
  3904. * SkDrvEvent - handle driver events
  3905. *
  3906. * Description:
  3907. * This function handles events from all modules directed to the driver
  3908. *
  3909. * Context:
  3910. * Is called under protection of slow path lock.
  3911. *
  3912. * Returns:
  3913. * 0 if everything ok
  3914. * < 0 on error
  3915. *
  3916. */
  3917. int SkDrvEvent(
  3918. SK_AC *pAC, /* pointer to adapter context */
  3919. SK_IOC IoC, /* io-context */
  3920. SK_U32 Event, /* event-id */
  3921. SK_EVPARA Param) /* event-parameter */
  3922. {
  3923. SK_MBUF *pRlmtMbuf; /* pointer to a rlmt-mbuf structure */
  3924. struct sk_buff *pMsg; /* pointer to a message block */
  3925. int FromPort; /* the port from which we switch away */
  3926. int ToPort; /* the port we switch to */
  3927. SK_EVPARA NewPara; /* parameter for further events */
  3928. #if 0
  3929. int Stat;
  3930. #endif
  3931. unsigned long Flags;
  3932. SK_BOOL DualNet;
  3933. switch (Event) {
  3934. case SK_DRV_ADAP_FAIL:
  3935. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
  3936. ("ADAPTER FAIL EVENT\n"));
  3937. printk("%s: Adapter failed.\n", pAC->dev[0]->name);
  3938. /* disable interrupts */
  3939. SK_OUT32(pAC->IoBase, B0_IMSK, 0);
  3940. /* cgoos */
  3941. break;
  3942. case SK_DRV_PORT_FAIL:
  3943. FromPort = Param.Para32[0];
  3944. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
  3945. ("PORT FAIL EVENT, Port: %d\n", FromPort));
  3946. if (FromPort == 0) {
  3947. printk("%s: Port A failed.\n", pAC->dev[0]->name);
  3948. } else {
  3949. printk("%s: Port B failed.\n", pAC->dev[1]->name);
  3950. }
  3951. /* cgoos */
  3952. break;
  3953. case SK_DRV_PORT_RESET: /* SK_U32 PortIdx */
  3954. /* action list 4 */
  3955. FromPort = Param.Para32[0];
  3956. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
  3957. ("PORT RESET EVENT, Port: %d ", FromPort));
  3958. NewPara.Para64 = FromPort;
  3959. SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
  3960. spin_lock_irqsave(
  3961. &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
  3962. Flags);
  3963. SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_HARD_RST);
  3964. #if 0
  3965. pAC->dev[Param.Para32[0]]->flags &= ~IFF_RUNNING;
  3966. #endif
  3967. spin_unlock_irqrestore(
  3968. &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
  3969. Flags);
  3970. /* clear rx ring from received frames */
  3971. ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE);
  3972. ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
  3973. spin_lock_irqsave(
  3974. &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
  3975. Flags);
  3976. /* tschilling: Handling of return value inserted. */
  3977. if (SkGeInitPort(pAC, IoC, FromPort)) {
  3978. if (FromPort == 0) {
  3979. printk("%s: SkGeInitPort A failed.\n", pAC->dev[0]->name);
  3980. } else {
  3981. printk("%s: SkGeInitPort B failed.\n", pAC->dev[1]->name);
  3982. }
  3983. }
  3984. SkAddrMcUpdate(pAC,IoC, FromPort);
  3985. PortReInitBmu(pAC, FromPort);
  3986. SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
  3987. ClearAndStartRx(pAC, FromPort);
  3988. spin_unlock_irqrestore(
  3989. &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
  3990. Flags);
  3991. break;
  3992. case SK_DRV_NET_UP: /* SK_U32 PortIdx */
  3993. /* action list 5 */
  3994. FromPort = Param.Para32[0];
  3995. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
  3996. ("NET UP EVENT, Port: %d ", Param.Para32[0]));
  3997. #ifdef SK98_INFO
  3998. printk("%s: network connection up using"
  3999. " port %c\n", pAC->dev[Param.Para32[0]]->name, 'A'+Param.Para32[0]);
  4000. /* tschilling: Values changed according to LinkSpeedUsed. */
  4001. Stat = pAC->GIni.GP[FromPort].PLinkSpeedUsed;
  4002. if (Stat == SK_LSPEED_STAT_10MBPS) {
  4003. printk(" speed: 10\n");
  4004. } else if (Stat == SK_LSPEED_STAT_100MBPS) {
  4005. printk(" speed: 100\n");
  4006. } else if (Stat == SK_LSPEED_STAT_1000MBPS) {
  4007. printk(" speed: 1000\n");
  4008. } else {
  4009. printk(" speed: unknown\n");
  4010. }
  4011. Stat = pAC->GIni.GP[FromPort].PLinkModeStatus;
  4012. if (Stat == SK_LMODE_STAT_AUTOHALF ||
  4013. Stat == SK_LMODE_STAT_AUTOFULL) {
  4014. printk(" autonegotiation: yes\n");
  4015. }
  4016. else {
  4017. printk(" autonegotiation: no\n");
  4018. }
  4019. if (Stat == SK_LMODE_STAT_AUTOHALF ||
  4020. Stat == SK_LMODE_STAT_HALF) {
  4021. printk(" duplex mode: half\n");
  4022. }
  4023. else {
  4024. printk(" duplex mode: full\n");
  4025. }
  4026. Stat = pAC->GIni.GP[FromPort].PFlowCtrlStatus;
  4027. if (Stat == SK_FLOW_STAT_REM_SEND ) {
  4028. printk(" flowctrl: remote send\n");
  4029. }
  4030. else if (Stat == SK_FLOW_STAT_LOC_SEND ){
  4031. printk(" flowctrl: local send\n");
  4032. }
  4033. else if (Stat == SK_FLOW_STAT_SYMMETRIC ){
  4034. printk(" flowctrl: symmetric\n");
  4035. }
  4036. else {
  4037. printk(" flowctrl: none\n");
  4038. }
  4039. /* tschilling: Check against CopperType now. */
  4040. if ((pAC->GIni.GICopperType == SK_TRUE) &&
  4041. (pAC->GIni.GP[FromPort].PLinkSpeedUsed ==
  4042. SK_LSPEED_STAT_1000MBPS)) {
  4043. Stat = pAC->GIni.GP[FromPort].PMSStatus;
  4044. if (Stat == SK_MS_STAT_MASTER ) {
  4045. printk(" role: master\n");
  4046. }
  4047. else if (Stat == SK_MS_STAT_SLAVE ) {
  4048. printk(" role: slave\n");
  4049. }
  4050. else {
  4051. printk(" role: ???\n");
  4052. }
  4053. }
  4054. #ifdef SK_ZEROCOPY
  4055. if (pAC->GIni.GIChipId == CHIP_ID_YUKON)
  4056. printk(" scatter-gather: enabled\n");
  4057. else
  4058. printk(" scatter-gather: disabled\n");
  4059. #else
  4060. printk(" scatter-gather: disabled\n");
  4061. #endif
  4062. #endif /* SK98_INFO */
  4063. if ((Param.Para32[0] != pAC->ActivePort) &&
  4064. (pAC->RlmtNets == 1)) {
  4065. NewPara.Para32[0] = pAC->ActivePort;
  4066. NewPara.Para32[1] = Param.Para32[0];
  4067. SkEventQueue(pAC, SKGE_DRV, SK_DRV_SWITCH_INTERN,
  4068. NewPara);
  4069. }
  4070. /* Inform the world that link protocol is up. */
  4071. #if 0
  4072. pAC->dev[Param.Para32[0]]->flags |= IFF_RUNNING;
  4073. #endif
  4074. break;
  4075. case SK_DRV_NET_DOWN: /* SK_U32 Reason */
  4076. /* action list 7 */
  4077. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
  4078. ("NET DOWN EVENT "));
  4079. #ifdef SK98_INFO
  4080. printk("%s: network connection down\n", pAC->dev[Param.Para32[1]]->name);
  4081. #endif
  4082. #if 0
  4083. pAC->dev[Param.Para32[1]]->flags &= ~IFF_RUNNING;
  4084. #endif
  4085. break;
  4086. case SK_DRV_SWITCH_HARD: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
  4087. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
  4088. ("PORT SWITCH HARD "));
  4089. case SK_DRV_SWITCH_SOFT: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
  4090. /* action list 6 */
  4091. printk("%s: switching to port %c\n", pAC->dev[0]->name,
  4092. 'A'+Param.Para32[1]);
  4093. case SK_DRV_SWITCH_INTERN: /* SK_U32 FromPortIdx SK_U32 ToPortIdx */
  4094. FromPort = Param.Para32[0];
  4095. ToPort = Param.Para32[1];
  4096. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
  4097. ("PORT SWITCH EVENT, From: %d To: %d (Pref %d) ",
  4098. FromPort, ToPort, pAC->Rlmt.Net[0].PrefPort));
  4099. NewPara.Para64 = FromPort;
  4100. SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
  4101. NewPara.Para64 = ToPort;
  4102. SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_XMAC_RESET, NewPara);
  4103. spin_lock_irqsave(
  4104. &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
  4105. Flags);
  4106. spin_lock_irqsave(
  4107. &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
  4108. SkGeStopPort(pAC, IoC, FromPort, SK_STOP_ALL, SK_SOFT_RST);
  4109. SkGeStopPort(pAC, IoC, ToPort, SK_STOP_ALL, SK_SOFT_RST);
  4110. spin_unlock_irqrestore(
  4111. &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
  4112. spin_unlock_irqrestore(
  4113. &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
  4114. Flags);
  4115. ReceiveIrq(pAC, &pAC->RxPort[FromPort], SK_FALSE); /* clears rx ring */
  4116. ReceiveIrq(pAC, &pAC->RxPort[ToPort], SK_FALSE); /* clears rx ring */
  4117. ClearTxRing(pAC, &pAC->TxPort[FromPort][TX_PRIO_LOW]);
  4118. ClearTxRing(pAC, &pAC->TxPort[ToPort][TX_PRIO_LOW]);
  4119. spin_lock_irqsave(
  4120. &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
  4121. Flags);
  4122. spin_lock_irqsave(
  4123. &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
  4124. pAC->ActivePort = ToPort;
  4125. #if 0
  4126. SetQueueSizes(pAC);
  4127. #else
  4128. /* tschilling: New common function with minimum size check. */
  4129. DualNet = SK_FALSE;
  4130. if (pAC->RlmtNets == 2) {
  4131. DualNet = SK_TRUE;
  4132. }
  4133. if (SkGeInitAssignRamToQueues(
  4134. pAC,
  4135. pAC->ActivePort,
  4136. DualNet)) {
  4137. spin_unlock_irqrestore(
  4138. &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
  4139. spin_unlock_irqrestore(
  4140. &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
  4141. Flags);
  4142. printk("SkGeInitAssignRamToQueues failed.\n");
  4143. break;
  4144. }
  4145. #endif
  4146. /* tschilling: Handling of return values inserted. */
  4147. if (SkGeInitPort(pAC, IoC, FromPort) ||
  4148. SkGeInitPort(pAC, IoC, ToPort)) {
  4149. printk("%s: SkGeInitPort failed.\n", pAC->dev[0]->name);
  4150. }
  4151. if (Event == SK_DRV_SWITCH_SOFT) {
  4152. SkMacRxTxEnable(pAC, IoC, FromPort);
  4153. }
  4154. SkMacRxTxEnable(pAC, IoC, ToPort);
  4155. SkAddrSwap(pAC, IoC, FromPort, ToPort);
  4156. SkAddrMcUpdate(pAC, IoC, FromPort);
  4157. SkAddrMcUpdate(pAC, IoC, ToPort);
  4158. PortReInitBmu(pAC, FromPort);
  4159. PortReInitBmu(pAC, ToPort);
  4160. SkGePollTxD(pAC, IoC, FromPort, SK_TRUE);
  4161. SkGePollTxD(pAC, IoC, ToPort, SK_TRUE);
  4162. ClearAndStartRx(pAC, FromPort);
  4163. ClearAndStartRx(pAC, ToPort);
  4164. spin_unlock_irqrestore(
  4165. &pAC->TxPort[ToPort][TX_PRIO_LOW].TxDesRingLock, Flags);
  4166. spin_unlock_irqrestore(
  4167. &pAC->TxPort[FromPort][TX_PRIO_LOW].TxDesRingLock,
  4168. Flags);
  4169. break;
  4170. case SK_DRV_RLMT_SEND: /* SK_MBUF *pMb */
  4171. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
  4172. ("RLS "));
  4173. pRlmtMbuf = (SK_MBUF*) Param.pParaPtr;
  4174. pMsg = (struct sk_buff*) pRlmtMbuf->pOs;
  4175. skb_put(pMsg, pRlmtMbuf->Length);
  4176. if (XmitFrame(pAC, &pAC->TxPort[pRlmtMbuf->PortIdx][TX_PRIO_LOW],
  4177. pMsg) < 0)
  4178. DEV_KFREE_SKB_ANY(pMsg);
  4179. break;
  4180. default:
  4181. break;
  4182. }
  4183. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_EVENT,
  4184. ("END EVENT "));
  4185. return (0);
  4186. } /* SkDrvEvent */
  4187. /*****************************************************************************
  4188. *
  4189. * SkErrorLog - log errors
  4190. *
  4191. * Description:
  4192. * This function logs errors to the system buffer and to the console
  4193. *
  4194. * Returns:
  4195. * 0 if everything ok
  4196. * < 0 on error
  4197. *
  4198. */
  4199. void SkErrorLog(
  4200. SK_AC *pAC,
  4201. int ErrClass,
  4202. int ErrNum,
  4203. char *pErrorMsg)
  4204. {
  4205. char ClassStr[80];
  4206. switch (ErrClass) {
  4207. case SK_ERRCL_OTHER:
  4208. strcpy(ClassStr, "Other error");
  4209. break;
  4210. case SK_ERRCL_CONFIG:
  4211. strcpy(ClassStr, "Configuration error");
  4212. break;
  4213. case SK_ERRCL_INIT:
  4214. strcpy(ClassStr, "Initialization error");
  4215. break;
  4216. case SK_ERRCL_NORES:
  4217. strcpy(ClassStr, "Out of resources error");
  4218. break;
  4219. case SK_ERRCL_SW:
  4220. strcpy(ClassStr, "internal Software error");
  4221. break;
  4222. case SK_ERRCL_HW:
  4223. strcpy(ClassStr, "Hardware failure");
  4224. break;
  4225. case SK_ERRCL_COMM:
  4226. strcpy(ClassStr, "Communication error");
  4227. break;
  4228. }
  4229. printk(KERN_INFO "%s: -- ERROR --\n Class: %s\n"
  4230. " Nr: 0x%x\n Msg: %s\n", pAC->dev[0]->name,
  4231. ClassStr, ErrNum, pErrorMsg);
  4232. } /* SkErrorLog */
  4233. #ifdef DEBUG
  4234. /****************************************************************************/
  4235. /* "debug only" section *****************************************************/
  4236. /****************************************************************************/
  4237. /*****************************************************************************
  4238. *
  4239. * DumpMsg - print a frame
  4240. *
  4241. * Description:
  4242. * This function prints frames to the system logfile/to the console.
  4243. *
  4244. * Returns: N/A
  4245. *
  4246. */
  4247. static void DumpMsg(struct sk_buff *skb, char *str)
  4248. {
  4249. int msglen;
  4250. if (skb == NULL) {
  4251. printk("DumpMsg(): NULL-Message\n");
  4252. return;
  4253. }
  4254. if (skb->data == NULL) {
  4255. printk("DumpMsg(): Message empty\n");
  4256. return;
  4257. }
  4258. msglen = skb->len;
  4259. if (msglen > 64)
  4260. msglen = 64;
  4261. printk("--- Begin of message from %s , len %d (from %d) ----\n", str, msglen, skb->len);
  4262. DumpData((char *)skb->data, msglen);
  4263. printk("------- End of message ---------\n");
  4264. } /* DumpMsg */
  4265. /*****************************************************************************
  4266. *
  4267. * DumpData - print a data area
  4268. *
  4269. * Description:
  4270. * This function prints a area of data to the system logfile/to the
  4271. * console.
  4272. *
  4273. * Returns: N/A
  4274. *
  4275. */
  4276. static void DumpData(char *p, int size)
  4277. {
  4278. register int i;
  4279. int haddr, addr;
  4280. char hex_buffer[180];
  4281. char asc_buffer[180];
  4282. char HEXCHAR[] = "0123456789ABCDEF";
  4283. addr = 0;
  4284. haddr = 0;
  4285. hex_buffer[0] = 0;
  4286. asc_buffer[0] = 0;
  4287. for (i=0; i < size; ) {
  4288. if (*p >= '0' && *p <='z')
  4289. asc_buffer[addr] = *p;
  4290. else
  4291. asc_buffer[addr] = '.';
  4292. addr++;
  4293. asc_buffer[addr] = 0;
  4294. hex_buffer[haddr] = HEXCHAR[(*p & 0xf0) >> 4];
  4295. haddr++;
  4296. hex_buffer[haddr] = HEXCHAR[*p & 0x0f];
  4297. haddr++;
  4298. hex_buffer[haddr] = ' ';
  4299. haddr++;
  4300. hex_buffer[haddr] = 0;
  4301. p++;
  4302. i++;
  4303. if (i%16 == 0) {
  4304. printk("%s %s\n", hex_buffer, asc_buffer);
  4305. addr = 0;
  4306. haddr = 0;
  4307. }
  4308. }
  4309. } /* DumpData */
  4310. /*****************************************************************************
  4311. *
  4312. * DumpLong - print a data area as long values
  4313. *
  4314. * Description:
  4315. * This function prints a area of data to the system logfile/to the
  4316. * console.
  4317. *
  4318. * Returns: N/A
  4319. *
  4320. */
  4321. static void DumpLong(char *pc, int size)
  4322. {
  4323. register int i;
  4324. int haddr, addr;
  4325. char hex_buffer[180];
  4326. char asc_buffer[180];
  4327. char HEXCHAR[] = "0123456789ABCDEF";
  4328. long *p;
  4329. int l;
  4330. addr = 0;
  4331. haddr = 0;
  4332. hex_buffer[0] = 0;
  4333. asc_buffer[0] = 0;
  4334. p = (long*) pc;
  4335. for (i=0; i < size; ) {
  4336. l = (long) *p;
  4337. hex_buffer[haddr] = HEXCHAR[(l >> 28) & 0xf];
  4338. haddr++;
  4339. hex_buffer[haddr] = HEXCHAR[(l >> 24) & 0xf];
  4340. haddr++;
  4341. hex_buffer[haddr] = HEXCHAR[(l >> 20) & 0xf];
  4342. haddr++;
  4343. hex_buffer[haddr] = HEXCHAR[(l >> 16) & 0xf];
  4344. haddr++;
  4345. hex_buffer[haddr] = HEXCHAR[(l >> 12) & 0xf];
  4346. haddr++;
  4347. hex_buffer[haddr] = HEXCHAR[(l >> 8) & 0xf];
  4348. haddr++;
  4349. hex_buffer[haddr] = HEXCHAR[(l >> 4) & 0xf];
  4350. haddr++;
  4351. hex_buffer[haddr] = HEXCHAR[l & 0x0f];
  4352. haddr++;
  4353. hex_buffer[haddr] = ' ';
  4354. haddr++;
  4355. hex_buffer[haddr] = 0;
  4356. p++;
  4357. i++;
  4358. if (i%8 == 0) {
  4359. printk("%4x %s\n", (i-8)*4, hex_buffer);
  4360. haddr = 0;
  4361. }
  4362. }
  4363. printk("------------------------\n");
  4364. } /* DumpLong */
  4365. #endif