skge.c 147 KB

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