skge.c 147 KB

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