skge.c 146 KB

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