skge.c 145 KB

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