skge.c 149 KB

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