skge.c 146 KB

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