skge.c 149 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262
  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[] = "net/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. * SkPciWriteCfgDWord - write a 32 bit value to pci config space
  248. *
  249. * Description:
  250. * This routine writes a 32 bit value to the pci configuration
  251. * space.
  252. *
  253. * Returns:
  254. * 0 - indicate everything worked ok.
  255. * != 0 - error indication
  256. */
  257. static inline int SkPciWriteCfgDWord(
  258. SK_AC *pAC, /* Adapter Control structure pointer */
  259. int PciAddr, /* PCI register address */
  260. SK_U32 Val) /* pointer to store the read value */
  261. {
  262. pci_write_config_dword(pAC->PciDev, PciAddr, Val);
  263. return(0);
  264. } /* SkPciWriteCfgDWord */
  265. /*****************************************************************************
  266. *
  267. * SkGeInitPCI - Init the PCI resources
  268. *
  269. * Description:
  270. * This function initialize the PCI resources and IO
  271. *
  272. * Returns: N/A
  273. *
  274. */
  275. int SkGeInitPCI(SK_AC *pAC)
  276. {
  277. struct SK_NET_DEVICE *dev = pAC->dev[0];
  278. struct pci_dev *pdev = pAC->PciDev;
  279. int retval;
  280. if (pci_enable_device(pdev) != 0) {
  281. return 1;
  282. }
  283. dev->mem_start = pci_resource_start (pdev, 0);
  284. pci_set_master(pdev);
  285. if (pci_request_regions(pdev, pAC->Name) != 0) {
  286. retval = 2;
  287. goto out_disable;
  288. }
  289. #ifdef SK_BIG_ENDIAN
  290. /*
  291. * On big endian machines, we use the adapter's aibility of
  292. * reading the descriptors as big endian.
  293. */
  294. {
  295. SK_U32 our2;
  296. SkPciReadCfgDWord(pAC, PCI_OUR_REG_2, &our2);
  297. our2 |= PCI_REV_DESC;
  298. SkPciWriteCfgDWord(pAC, PCI_OUR_REG_2, our2);
  299. }
  300. #endif
  301. /*
  302. * Remap the regs into kernel space.
  303. */
  304. pAC->IoBase = ioremap_nocache(dev->mem_start, 0x4000);
  305. if (!pAC->IoBase){
  306. retval = 3;
  307. goto out_release;
  308. }
  309. return 0;
  310. out_release:
  311. pci_release_regions(pdev);
  312. out_disable:
  313. pci_disable_device(pdev);
  314. return retval;
  315. }
  316. /*****************************************************************************
  317. *
  318. * FreeResources - release resources allocated for adapter
  319. *
  320. * Description:
  321. * This function releases the IRQ, unmaps the IO and
  322. * frees the desriptor ring.
  323. *
  324. * Returns: N/A
  325. *
  326. */
  327. static void FreeResources(struct SK_NET_DEVICE *dev)
  328. {
  329. SK_U32 AllocFlag;
  330. DEV_NET *pNet;
  331. SK_AC *pAC;
  332. pNet = netdev_priv(dev);
  333. pAC = pNet->pAC;
  334. AllocFlag = pAC->AllocFlag;
  335. if (pAC->PciDev) {
  336. pci_release_regions(pAC->PciDev);
  337. }
  338. if (AllocFlag & SK_ALLOC_IRQ) {
  339. free_irq(dev->irq, dev);
  340. }
  341. if (pAC->IoBase) {
  342. iounmap(pAC->IoBase);
  343. }
  344. if (pAC->pDescrMem) {
  345. BoardFreeMem(pAC);
  346. }
  347. } /* FreeResources */
  348. MODULE_AUTHOR("Mirko Lindner <mlindner@syskonnect.de>");
  349. MODULE_DESCRIPTION("SysKonnect SK-NET Gigabit Ethernet SK-98xx driver");
  350. MODULE_LICENSE("GPL");
  351. #ifdef LINK_SPEED_A
  352. static char *Speed_A[SK_MAX_CARD_PARAM] = LINK_SPEED;
  353. #else
  354. static char *Speed_A[SK_MAX_CARD_PARAM] = {"", };
  355. #endif
  356. #ifdef LINK_SPEED_B
  357. static char *Speed_B[SK_MAX_CARD_PARAM] = LINK_SPEED;
  358. #else
  359. static char *Speed_B[SK_MAX_CARD_PARAM] = {"", };
  360. #endif
  361. #ifdef AUTO_NEG_A
  362. static char *AutoNeg_A[SK_MAX_CARD_PARAM] = AUTO_NEG_A;
  363. #else
  364. static char *AutoNeg_A[SK_MAX_CARD_PARAM] = {"", };
  365. #endif
  366. #ifdef DUP_CAP_A
  367. static char *DupCap_A[SK_MAX_CARD_PARAM] = DUP_CAP_A;
  368. #else
  369. static char *DupCap_A[SK_MAX_CARD_PARAM] = {"", };
  370. #endif
  371. #ifdef FLOW_CTRL_A
  372. static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = FLOW_CTRL_A;
  373. #else
  374. static char *FlowCtrl_A[SK_MAX_CARD_PARAM] = {"", };
  375. #endif
  376. #ifdef ROLE_A
  377. static char *Role_A[SK_MAX_CARD_PARAM] = ROLE_A;
  378. #else
  379. static char *Role_A[SK_MAX_CARD_PARAM] = {"", };
  380. #endif
  381. #ifdef AUTO_NEG_B
  382. static char *AutoNeg_B[SK_MAX_CARD_PARAM] = AUTO_NEG_B;
  383. #else
  384. static char *AutoNeg_B[SK_MAX_CARD_PARAM] = {"", };
  385. #endif
  386. #ifdef DUP_CAP_B
  387. static char *DupCap_B[SK_MAX_CARD_PARAM] = DUP_CAP_B;
  388. #else
  389. static char *DupCap_B[SK_MAX_CARD_PARAM] = {"", };
  390. #endif
  391. #ifdef FLOW_CTRL_B
  392. static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = FLOW_CTRL_B;
  393. #else
  394. static char *FlowCtrl_B[SK_MAX_CARD_PARAM] = {"", };
  395. #endif
  396. #ifdef ROLE_B
  397. static char *Role_B[SK_MAX_CARD_PARAM] = ROLE_B;
  398. #else
  399. static char *Role_B[SK_MAX_CARD_PARAM] = {"", };
  400. #endif
  401. #ifdef CON_TYPE
  402. static char *ConType[SK_MAX_CARD_PARAM] = CON_TYPE;
  403. #else
  404. static char *ConType[SK_MAX_CARD_PARAM] = {"", };
  405. #endif
  406. #ifdef PREF_PORT
  407. static char *PrefPort[SK_MAX_CARD_PARAM] = PREF_PORT;
  408. #else
  409. static char *PrefPort[SK_MAX_CARD_PARAM] = {"", };
  410. #endif
  411. #ifdef RLMT_MODE
  412. static char *RlmtMode[SK_MAX_CARD_PARAM] = RLMT_MODE;
  413. #else
  414. static char *RlmtMode[SK_MAX_CARD_PARAM] = {"", };
  415. #endif
  416. static int IntsPerSec[SK_MAX_CARD_PARAM];
  417. static char *Moderation[SK_MAX_CARD_PARAM];
  418. static char *ModerationMask[SK_MAX_CARD_PARAM];
  419. static char *AutoSizing[SK_MAX_CARD_PARAM];
  420. static char *Stats[SK_MAX_CARD_PARAM];
  421. module_param_array(Speed_A, charp, NULL, 0);
  422. module_param_array(Speed_B, charp, NULL, 0);
  423. module_param_array(AutoNeg_A, charp, NULL, 0);
  424. module_param_array(AutoNeg_B, charp, NULL, 0);
  425. module_param_array(DupCap_A, charp, NULL, 0);
  426. module_param_array(DupCap_B, charp, NULL, 0);
  427. module_param_array(FlowCtrl_A, charp, NULL, 0);
  428. module_param_array(FlowCtrl_B, charp, NULL, 0);
  429. module_param_array(Role_A, charp, NULL, 0);
  430. module_param_array(Role_B, charp, NULL, 0);
  431. module_param_array(ConType, charp, NULL, 0);
  432. module_param_array(PrefPort, charp, NULL, 0);
  433. module_param_array(RlmtMode, charp, NULL, 0);
  434. /* used for interrupt moderation */
  435. module_param_array(IntsPerSec, int, NULL, 0);
  436. module_param_array(Moderation, charp, NULL, 0);
  437. module_param_array(Stats, charp, NULL, 0);
  438. module_param_array(ModerationMask, charp, NULL, 0);
  439. module_param_array(AutoSizing, charp, NULL, 0);
  440. /*****************************************************************************
  441. *
  442. * SkGeBoardInit - do level 0 and 1 initialization
  443. *
  444. * Description:
  445. * This function prepares the board hardware for running. The desriptor
  446. * ring is set up, the IRQ is allocated and the configuration settings
  447. * are examined.
  448. *
  449. * Returns:
  450. * 0, if everything is ok
  451. * !=0, on error
  452. */
  453. static int __init SkGeBoardInit(struct SK_NET_DEVICE *dev, SK_AC *pAC)
  454. {
  455. short i;
  456. unsigned long Flags;
  457. char *DescrString = "sk98lin: Driver for Linux"; /* this is given to PNMI */
  458. char *VerStr = VER_STRING;
  459. int Ret; /* return code of request_irq */
  460. SK_BOOL DualNet;
  461. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  462. ("IoBase: %08lX\n", (unsigned long)pAC->IoBase));
  463. for (i=0; i<SK_MAX_MACS; i++) {
  464. pAC->TxPort[i][0].HwAddr = pAC->IoBase + TxQueueAddr[i][0];
  465. pAC->TxPort[i][0].PortIndex = i;
  466. pAC->RxPort[i].HwAddr = pAC->IoBase + RxQueueAddr[i];
  467. pAC->RxPort[i].PortIndex = i;
  468. }
  469. /* Initialize the mutexes */
  470. for (i=0; i<SK_MAX_MACS; i++) {
  471. spin_lock_init(&pAC->TxPort[i][0].TxDesRingLock);
  472. spin_lock_init(&pAC->RxPort[i].RxDesRingLock);
  473. }
  474. spin_lock_init(&pAC->SlowPathLock);
  475. /* setup phy_id blink timer */
  476. pAC->BlinkTimer.function = SkGeBlinkTimer;
  477. pAC->BlinkTimer.data = (unsigned long) dev;
  478. init_timer(&pAC->BlinkTimer);
  479. /* level 0 init common modules here */
  480. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  481. /* Does a RESET on board ...*/
  482. if (SkGeInit(pAC, pAC->IoBase, SK_INIT_DATA) != 0) {
  483. printk("HWInit (0) failed.\n");
  484. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  485. return(-EAGAIN);
  486. }
  487. SkI2cInit( pAC, pAC->IoBase, SK_INIT_DATA);
  488. SkEventInit(pAC, pAC->IoBase, SK_INIT_DATA);
  489. SkPnmiInit( pAC, pAC->IoBase, SK_INIT_DATA);
  490. SkAddrInit( pAC, pAC->IoBase, SK_INIT_DATA);
  491. SkRlmtInit( pAC, pAC->IoBase, SK_INIT_DATA);
  492. SkTimerInit(pAC, pAC->IoBase, SK_INIT_DATA);
  493. pAC->BoardLevel = SK_INIT_DATA;
  494. pAC->RxBufSize = ETH_BUF_SIZE;
  495. SK_PNMI_SET_DRIVER_DESCR(pAC, DescrString);
  496. SK_PNMI_SET_DRIVER_VER(pAC, VerStr);
  497. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  498. /* level 1 init common modules here (HW init) */
  499. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  500. if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
  501. printk("sk98lin: HWInit (1) failed.\n");
  502. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  503. return(-EAGAIN);
  504. }
  505. SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
  506. SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
  507. SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
  508. SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
  509. SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
  510. SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
  511. /* Set chipset type support */
  512. pAC->ChipsetType = 0;
  513. if ((pAC->GIni.GIChipId == CHIP_ID_YUKON) ||
  514. (pAC->GIni.GIChipId == CHIP_ID_YUKON_LITE)) {
  515. pAC->ChipsetType = 1;
  516. }
  517. GetConfiguration(pAC);
  518. if (pAC->RlmtNets == 2) {
  519. pAC->GIni.GIPortUsage = SK_MUL_LINK;
  520. }
  521. pAC->BoardLevel = SK_INIT_IO;
  522. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  523. if (pAC->GIni.GIMacsFound == 2) {
  524. Ret = request_irq(dev->irq, SkGeIsr, SA_SHIRQ, pAC->Name, dev);
  525. } else if (pAC->GIni.GIMacsFound == 1) {
  526. Ret = request_irq(dev->irq, SkGeIsrOnePort, SA_SHIRQ,
  527. pAC->Name, dev);
  528. } else {
  529. printk(KERN_WARNING "sk98lin: Illegal number of ports: %d\n",
  530. pAC->GIni.GIMacsFound);
  531. return -EAGAIN;
  532. }
  533. if (Ret) {
  534. printk(KERN_WARNING "sk98lin: Requested IRQ %d is busy.\n",
  535. dev->irq);
  536. return -EAGAIN;
  537. }
  538. pAC->AllocFlag |= SK_ALLOC_IRQ;
  539. /* Alloc memory for this board (Mem for RxD/TxD) : */
  540. if(!BoardAllocMem(pAC)) {
  541. printk("No memory for descriptor rings.\n");
  542. return(-EAGAIN);
  543. }
  544. SkCsSetReceiveFlags(pAC,
  545. SKCS_PROTO_IP | SKCS_PROTO_TCP | SKCS_PROTO_UDP,
  546. &pAC->CsOfs1, &pAC->CsOfs2, 0);
  547. pAC->CsOfs = (pAC->CsOfs2 << 16) | pAC->CsOfs1;
  548. BoardInitMem(pAC);
  549. /* tschilling: New common function with minimum size check. */
  550. DualNet = SK_FALSE;
  551. if (pAC->RlmtNets == 2) {
  552. DualNet = SK_TRUE;
  553. }
  554. if (SkGeInitAssignRamToQueues(
  555. pAC,
  556. pAC->ActivePort,
  557. DualNet)) {
  558. BoardFreeMem(pAC);
  559. printk("sk98lin: SkGeInitAssignRamToQueues failed.\n");
  560. return(-EAGAIN);
  561. }
  562. return (0);
  563. } /* SkGeBoardInit */
  564. /*****************************************************************************
  565. *
  566. * BoardAllocMem - allocate the memory for the descriptor rings
  567. *
  568. * Description:
  569. * This function allocates the memory for all descriptor rings.
  570. * Each ring is aligned for the desriptor alignment and no ring
  571. * has a 4 GByte boundary in it (because the upper 32 bit must
  572. * be constant for all descriptiors in one rings).
  573. *
  574. * Returns:
  575. * SK_TRUE, if all memory could be allocated
  576. * SK_FALSE, if not
  577. */
  578. static SK_BOOL BoardAllocMem(
  579. SK_AC *pAC)
  580. {
  581. caddr_t pDescrMem; /* pointer to descriptor memory area */
  582. size_t AllocLength; /* length of complete descriptor area */
  583. int i; /* loop counter */
  584. unsigned long BusAddr;
  585. /* rings plus one for alignment (do not cross 4 GB boundary) */
  586. /* RX_RING_SIZE is assumed bigger than TX_RING_SIZE */
  587. #if (BITS_PER_LONG == 32)
  588. AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
  589. #else
  590. AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
  591. + RX_RING_SIZE + 8;
  592. #endif
  593. pDescrMem = pci_alloc_consistent(pAC->PciDev, AllocLength,
  594. &pAC->pDescrMemDMA);
  595. if (pDescrMem == NULL) {
  596. return (SK_FALSE);
  597. }
  598. pAC->pDescrMem = pDescrMem;
  599. BusAddr = (unsigned long) pAC->pDescrMemDMA;
  600. /* Descriptors need 8 byte alignment, and this is ensured
  601. * by pci_alloc_consistent.
  602. */
  603. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  604. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
  605. ("TX%d/A: pDescrMem: %lX, PhysDescrMem: %lX\n",
  606. i, (unsigned long) pDescrMem,
  607. BusAddr));
  608. pAC->TxPort[i][0].pTxDescrRing = pDescrMem;
  609. pAC->TxPort[i][0].VTxDescrRing = BusAddr;
  610. pDescrMem += TX_RING_SIZE;
  611. BusAddr += TX_RING_SIZE;
  612. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
  613. ("RX%d: pDescrMem: %lX, PhysDescrMem: %lX\n",
  614. i, (unsigned long) pDescrMem,
  615. (unsigned long)BusAddr));
  616. pAC->RxPort[i].pRxDescrRing = pDescrMem;
  617. pAC->RxPort[i].VRxDescrRing = BusAddr;
  618. pDescrMem += RX_RING_SIZE;
  619. BusAddr += RX_RING_SIZE;
  620. } /* for */
  621. return (SK_TRUE);
  622. } /* BoardAllocMem */
  623. /****************************************************************************
  624. *
  625. * BoardFreeMem - reverse of BoardAllocMem
  626. *
  627. * Description:
  628. * Free all memory allocated in BoardAllocMem: adapter context,
  629. * descriptor rings, locks.
  630. *
  631. * Returns: N/A
  632. */
  633. static void BoardFreeMem(
  634. SK_AC *pAC)
  635. {
  636. size_t AllocLength; /* length of complete descriptor area */
  637. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  638. ("BoardFreeMem\n"));
  639. #if (BITS_PER_LONG == 32)
  640. AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound + 8;
  641. #else
  642. AllocLength = (RX_RING_SIZE + TX_RING_SIZE) * pAC->GIni.GIMacsFound
  643. + RX_RING_SIZE + 8;
  644. #endif
  645. pci_free_consistent(pAC->PciDev, AllocLength,
  646. pAC->pDescrMem, pAC->pDescrMemDMA);
  647. pAC->pDescrMem = NULL;
  648. } /* BoardFreeMem */
  649. /*****************************************************************************
  650. *
  651. * BoardInitMem - initiate the descriptor rings
  652. *
  653. * Description:
  654. * This function sets the descriptor rings up in memory.
  655. * The adapter is initialized with the descriptor start addresses.
  656. *
  657. * Returns: N/A
  658. */
  659. static void BoardInitMem(
  660. SK_AC *pAC) /* pointer to adapter context */
  661. {
  662. int i; /* loop counter */
  663. int RxDescrSize; /* the size of a rx descriptor rounded up to alignment*/
  664. int TxDescrSize; /* the size of a tx descriptor rounded up to alignment*/
  665. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  666. ("BoardInitMem\n"));
  667. RxDescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
  668. pAC->RxDescrPerRing = RX_RING_SIZE / RxDescrSize;
  669. TxDescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) * DESCR_ALIGN;
  670. pAC->TxDescrPerRing = TX_RING_SIZE / RxDescrSize;
  671. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  672. SetupRing(
  673. pAC,
  674. pAC->TxPort[i][0].pTxDescrRing,
  675. pAC->TxPort[i][0].VTxDescrRing,
  676. (RXD**)&pAC->TxPort[i][0].pTxdRingHead,
  677. (RXD**)&pAC->TxPort[i][0].pTxdRingTail,
  678. (RXD**)&pAC->TxPort[i][0].pTxdRingPrev,
  679. &pAC->TxPort[i][0].TxdRingFree,
  680. SK_TRUE);
  681. SetupRing(
  682. pAC,
  683. pAC->RxPort[i].pRxDescrRing,
  684. pAC->RxPort[i].VRxDescrRing,
  685. &pAC->RxPort[i].pRxdRingHead,
  686. &pAC->RxPort[i].pRxdRingTail,
  687. &pAC->RxPort[i].pRxdRingPrev,
  688. &pAC->RxPort[i].RxdRingFree,
  689. SK_FALSE);
  690. }
  691. } /* BoardInitMem */
  692. /*****************************************************************************
  693. *
  694. * SetupRing - create one descriptor ring
  695. *
  696. * Description:
  697. * This function creates one descriptor ring in the given memory area.
  698. * The head, tail and number of free descriptors in the ring are set.
  699. *
  700. * Returns:
  701. * none
  702. */
  703. static void SetupRing(
  704. SK_AC *pAC,
  705. void *pMemArea, /* a pointer to the memory area for the ring */
  706. uintptr_t VMemArea, /* the virtual bus address of the memory area */
  707. RXD **ppRingHead, /* address where the head should be written */
  708. RXD **ppRingTail, /* address where the tail should be written */
  709. RXD **ppRingPrev, /* address where the tail should be written */
  710. int *pRingFree, /* address where the # of free descr. goes */
  711. SK_BOOL IsTx) /* flag: is this a tx ring */
  712. {
  713. int i; /* loop counter */
  714. int DescrSize; /* the size of a descriptor rounded up to alignment*/
  715. int DescrNum; /* number of descriptors per ring */
  716. RXD *pDescr; /* pointer to a descriptor (receive or transmit) */
  717. RXD *pNextDescr; /* pointer to the next descriptor */
  718. RXD *pPrevDescr; /* pointer to the previous descriptor */
  719. uintptr_t VNextDescr; /* the virtual bus address of the next descriptor */
  720. if (IsTx == SK_TRUE) {
  721. DescrSize = (((sizeof(TXD) - 1) / DESCR_ALIGN) + 1) *
  722. DESCR_ALIGN;
  723. DescrNum = TX_RING_SIZE / DescrSize;
  724. } else {
  725. DescrSize = (((sizeof(RXD) - 1) / DESCR_ALIGN) + 1) *
  726. DESCR_ALIGN;
  727. DescrNum = RX_RING_SIZE / DescrSize;
  728. }
  729. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS,
  730. ("Descriptor size: %d Descriptor Number: %d\n",
  731. DescrSize,DescrNum));
  732. pDescr = (RXD*) pMemArea;
  733. pPrevDescr = NULL;
  734. pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
  735. VNextDescr = VMemArea + DescrSize;
  736. for(i=0; i<DescrNum; i++) {
  737. /* set the pointers right */
  738. pDescr->VNextRxd = VNextDescr & 0xffffffffULL;
  739. pDescr->pNextRxd = pNextDescr;
  740. pDescr->TcpSumStarts = pAC->CsOfs;
  741. /* advance one step */
  742. pPrevDescr = pDescr;
  743. pDescr = pNextDescr;
  744. pNextDescr = (RXD*) (((char*)pDescr) + DescrSize);
  745. VNextDescr += DescrSize;
  746. }
  747. pPrevDescr->pNextRxd = (RXD*) pMemArea;
  748. pPrevDescr->VNextRxd = VMemArea;
  749. pDescr = (RXD*) pMemArea;
  750. *ppRingHead = (RXD*) pMemArea;
  751. *ppRingTail = *ppRingHead;
  752. *ppRingPrev = pPrevDescr;
  753. *pRingFree = DescrNum;
  754. } /* SetupRing */
  755. /*****************************************************************************
  756. *
  757. * PortReInitBmu - re-initiate the descriptor rings for one port
  758. *
  759. * Description:
  760. * This function reinitializes the descriptor rings of one port
  761. * in memory. The port must be stopped before.
  762. * The HW is initialized with the descriptor start addresses.
  763. *
  764. * Returns:
  765. * none
  766. */
  767. static void PortReInitBmu(
  768. SK_AC *pAC, /* pointer to adapter context */
  769. int PortIndex) /* index of the port for which to re-init */
  770. {
  771. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  772. ("PortReInitBmu "));
  773. /* set address of first descriptor of ring in BMU */
  774. SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_L,
  775. (uint32_t)(((caddr_t)
  776. (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
  777. pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
  778. pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) &
  779. 0xFFFFFFFF));
  780. SK_OUT32(pAC->IoBase, TxQueueAddr[PortIndex][TX_PRIO_LOW]+ Q_DA_H,
  781. (uint32_t)(((caddr_t)
  782. (pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxdRingHead) -
  783. pAC->TxPort[PortIndex][TX_PRIO_LOW].pTxDescrRing +
  784. pAC->TxPort[PortIndex][TX_PRIO_LOW].VTxDescrRing) >> 32));
  785. SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_L,
  786. (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
  787. pAC->RxPort[PortIndex].pRxDescrRing +
  788. pAC->RxPort[PortIndex].VRxDescrRing) & 0xFFFFFFFF));
  789. SK_OUT32(pAC->IoBase, RxQueueAddr[PortIndex]+Q_DA_H,
  790. (uint32_t)(((caddr_t)(pAC->RxPort[PortIndex].pRxdRingHead) -
  791. pAC->RxPort[PortIndex].pRxDescrRing +
  792. pAC->RxPort[PortIndex].VRxDescrRing) >> 32));
  793. } /* PortReInitBmu */
  794. /****************************************************************************
  795. *
  796. * SkGeIsr - handle adapter interrupts
  797. *
  798. * Description:
  799. * The interrupt routine is called when the network adapter
  800. * generates an interrupt. It may also be called if another device
  801. * shares this interrupt vector with the driver.
  802. *
  803. * Returns: N/A
  804. *
  805. */
  806. static SkIsrRetVar SkGeIsr(int irq, void *dev_id, struct pt_regs *ptregs)
  807. {
  808. struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
  809. DEV_NET *pNet;
  810. SK_AC *pAC;
  811. SK_U32 IntSrc; /* interrupts source register contents */
  812. pNet = netdev_priv(dev);
  813. pAC = pNet->pAC;
  814. /*
  815. * Check and process if its our interrupt
  816. */
  817. SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
  818. if (IntSrc == 0) {
  819. return SkIsrRetNone;
  820. }
  821. while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
  822. #if 0 /* software irq currently not used */
  823. if (IntSrc & IS_IRQ_SW) {
  824. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  825. SK_DBGCAT_DRV_INT_SRC,
  826. ("Software IRQ\n"));
  827. }
  828. #endif
  829. if (IntSrc & IS_R1_F) {
  830. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  831. SK_DBGCAT_DRV_INT_SRC,
  832. ("EOF RX1 IRQ\n"));
  833. ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
  834. SK_PNMI_CNT_RX_INTR(pAC, 0);
  835. }
  836. if (IntSrc & IS_R2_F) {
  837. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  838. SK_DBGCAT_DRV_INT_SRC,
  839. ("EOF RX2 IRQ\n"));
  840. ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
  841. SK_PNMI_CNT_RX_INTR(pAC, 1);
  842. }
  843. #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
  844. if (IntSrc & IS_XA1_F) {
  845. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  846. SK_DBGCAT_DRV_INT_SRC,
  847. ("EOF AS TX1 IRQ\n"));
  848. SK_PNMI_CNT_TX_INTR(pAC, 0);
  849. spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
  850. FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
  851. spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
  852. }
  853. if (IntSrc & IS_XA2_F) {
  854. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  855. SK_DBGCAT_DRV_INT_SRC,
  856. ("EOF AS TX2 IRQ\n"));
  857. SK_PNMI_CNT_TX_INTR(pAC, 1);
  858. spin_lock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
  859. FreeTxDescriptors(pAC, &pAC->TxPort[1][TX_PRIO_LOW]);
  860. spin_unlock(&pAC->TxPort[1][TX_PRIO_LOW].TxDesRingLock);
  861. }
  862. #if 0 /* only if sync. queues used */
  863. if (IntSrc & IS_XS1_F) {
  864. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  865. SK_DBGCAT_DRV_INT_SRC,
  866. ("EOF SY TX1 IRQ\n"));
  867. SK_PNMI_CNT_TX_INTR(pAC, 1);
  868. spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
  869. FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
  870. spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
  871. ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
  872. }
  873. if (IntSrc & IS_XS2_F) {
  874. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  875. SK_DBGCAT_DRV_INT_SRC,
  876. ("EOF SY TX2 IRQ\n"));
  877. SK_PNMI_CNT_TX_INTR(pAC, 1);
  878. spin_lock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
  879. FreeTxDescriptors(pAC, 1, TX_PRIO_HIGH);
  880. spin_unlock(&pAC->TxPort[1][TX_PRIO_HIGH].TxDesRingLock);
  881. ClearTxIrq(pAC, 1, TX_PRIO_HIGH);
  882. }
  883. #endif
  884. #endif
  885. /* do all IO at once */
  886. if (IntSrc & IS_R1_F)
  887. ClearAndStartRx(pAC, 0);
  888. if (IntSrc & IS_R2_F)
  889. ClearAndStartRx(pAC, 1);
  890. #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
  891. if (IntSrc & IS_XA1_F)
  892. ClearTxIrq(pAC, 0, TX_PRIO_LOW);
  893. if (IntSrc & IS_XA2_F)
  894. ClearTxIrq(pAC, 1, TX_PRIO_LOW);
  895. #endif
  896. SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
  897. } /* while (IntSrc & IRQ_MASK != 0) */
  898. IntSrc &= pAC->GIni.GIValIrqMask;
  899. if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
  900. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
  901. ("SPECIAL IRQ DP-Cards => %x\n", IntSrc));
  902. pAC->CheckQueue = SK_FALSE;
  903. spin_lock(&pAC->SlowPathLock);
  904. if (IntSrc & SPECIAL_IRQS)
  905. SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
  906. SkEventDispatcher(pAC, pAC->IoBase);
  907. spin_unlock(&pAC->SlowPathLock);
  908. }
  909. /*
  910. * do it all again is case we cleared an interrupt that
  911. * came in after handling the ring (OUTs may be delayed
  912. * in hardware buffers, but are through after IN)
  913. *
  914. * rroesler: has been commented out and shifted to
  915. * SkGeDrvEvent(), because it is timer
  916. * guarded now
  917. *
  918. ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
  919. ReceiveIrq(pAC, &pAC->RxPort[1], SK_TRUE);
  920. */
  921. if (pAC->CheckQueue) {
  922. pAC->CheckQueue = SK_FALSE;
  923. spin_lock(&pAC->SlowPathLock);
  924. SkEventDispatcher(pAC, pAC->IoBase);
  925. spin_unlock(&pAC->SlowPathLock);
  926. }
  927. /* IRQ is processed - Enable IRQs again*/
  928. SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
  929. return SkIsrRetHandled;
  930. } /* SkGeIsr */
  931. /****************************************************************************
  932. *
  933. * SkGeIsrOnePort - handle adapter interrupts for single port adapter
  934. *
  935. * Description:
  936. * The interrupt routine is called when the network adapter
  937. * generates an interrupt. It may also be called if another device
  938. * shares this interrupt vector with the driver.
  939. * This is the same as above, but handles only one port.
  940. *
  941. * Returns: N/A
  942. *
  943. */
  944. static SkIsrRetVar SkGeIsrOnePort(int irq, void *dev_id, struct pt_regs *ptregs)
  945. {
  946. struct SK_NET_DEVICE *dev = (struct SK_NET_DEVICE *)dev_id;
  947. DEV_NET *pNet;
  948. SK_AC *pAC;
  949. SK_U32 IntSrc; /* interrupts source register contents */
  950. pNet = netdev_priv(dev);
  951. pAC = pNet->pAC;
  952. /*
  953. * Check and process if its our interrupt
  954. */
  955. SK_IN32(pAC->IoBase, B0_SP_ISRC, &IntSrc);
  956. if (IntSrc == 0) {
  957. return SkIsrRetNone;
  958. }
  959. while (((IntSrc & IRQ_MASK) & ~SPECIAL_IRQS) != 0) {
  960. #if 0 /* software irq currently not used */
  961. if (IntSrc & IS_IRQ_SW) {
  962. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  963. SK_DBGCAT_DRV_INT_SRC,
  964. ("Software IRQ\n"));
  965. }
  966. #endif
  967. if (IntSrc & IS_R1_F) {
  968. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  969. SK_DBGCAT_DRV_INT_SRC,
  970. ("EOF RX1 IRQ\n"));
  971. ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
  972. SK_PNMI_CNT_RX_INTR(pAC, 0);
  973. }
  974. #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
  975. if (IntSrc & IS_XA1_F) {
  976. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  977. SK_DBGCAT_DRV_INT_SRC,
  978. ("EOF AS TX1 IRQ\n"));
  979. SK_PNMI_CNT_TX_INTR(pAC, 0);
  980. spin_lock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
  981. FreeTxDescriptors(pAC, &pAC->TxPort[0][TX_PRIO_LOW]);
  982. spin_unlock(&pAC->TxPort[0][TX_PRIO_LOW].TxDesRingLock);
  983. }
  984. #if 0 /* only if sync. queues used */
  985. if (IntSrc & IS_XS1_F) {
  986. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  987. SK_DBGCAT_DRV_INT_SRC,
  988. ("EOF SY TX1 IRQ\n"));
  989. SK_PNMI_CNT_TX_INTR(pAC, 0);
  990. spin_lock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
  991. FreeTxDescriptors(pAC, 0, TX_PRIO_HIGH);
  992. spin_unlock(&pAC->TxPort[0][TX_PRIO_HIGH].TxDesRingLock);
  993. ClearTxIrq(pAC, 0, TX_PRIO_HIGH);
  994. }
  995. #endif
  996. #endif
  997. /* do all IO at once */
  998. if (IntSrc & IS_R1_F)
  999. ClearAndStartRx(pAC, 0);
  1000. #ifdef USE_TX_COMPLETE /* only if tx complete interrupt used */
  1001. if (IntSrc & IS_XA1_F)
  1002. ClearTxIrq(pAC, 0, TX_PRIO_LOW);
  1003. #endif
  1004. SK_IN32(pAC->IoBase, B0_ISRC, &IntSrc);
  1005. } /* while (IntSrc & IRQ_MASK != 0) */
  1006. IntSrc &= pAC->GIni.GIValIrqMask;
  1007. if ((IntSrc & SPECIAL_IRQS) || pAC->CheckQueue) {
  1008. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_INT_SRC,
  1009. ("SPECIAL IRQ SP-Cards => %x\n", IntSrc));
  1010. pAC->CheckQueue = SK_FALSE;
  1011. spin_lock(&pAC->SlowPathLock);
  1012. if (IntSrc & SPECIAL_IRQS)
  1013. SkGeSirqIsr(pAC, pAC->IoBase, IntSrc);
  1014. SkEventDispatcher(pAC, pAC->IoBase);
  1015. spin_unlock(&pAC->SlowPathLock);
  1016. }
  1017. /*
  1018. * do it all again is case we cleared an interrupt that
  1019. * came in after handling the ring (OUTs may be delayed
  1020. * in hardware buffers, but are through after IN)
  1021. *
  1022. * rroesler: has been commented out and shifted to
  1023. * SkGeDrvEvent(), because it is timer
  1024. * guarded now
  1025. *
  1026. ReceiveIrq(pAC, &pAC->RxPort[0], SK_TRUE);
  1027. */
  1028. /* IRQ is processed - Enable IRQs again*/
  1029. SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
  1030. return SkIsrRetHandled;
  1031. } /* SkGeIsrOnePort */
  1032. #ifdef CONFIG_NET_POLL_CONTROLLER
  1033. /****************************************************************************
  1034. *
  1035. * SkGePollController - polling receive, for netconsole
  1036. *
  1037. * Description:
  1038. * Polling receive - used by netconsole and other diagnostic tools
  1039. * to allow network i/o with interrupts disabled.
  1040. *
  1041. * Returns: N/A
  1042. */
  1043. static void SkGePollController(struct net_device *dev)
  1044. {
  1045. disable_irq(dev->irq);
  1046. SkGeIsr(dev->irq, dev, NULL);
  1047. enable_irq(dev->irq);
  1048. }
  1049. #endif
  1050. /****************************************************************************
  1051. *
  1052. * SkGeOpen - handle start of initialized adapter
  1053. *
  1054. * Description:
  1055. * This function starts the initialized adapter.
  1056. * The board level variable is set and the adapter is
  1057. * brought to full functionality.
  1058. * The device flags are set for operation.
  1059. * Do all necessary level 2 initialization, enable interrupts and
  1060. * give start command to RLMT.
  1061. *
  1062. * Returns:
  1063. * 0 on success
  1064. * != 0 on error
  1065. */
  1066. static int SkGeOpen(
  1067. struct SK_NET_DEVICE *dev)
  1068. {
  1069. DEV_NET *pNet;
  1070. SK_AC *pAC;
  1071. unsigned long Flags; /* for spin lock */
  1072. int i;
  1073. SK_EVPARA EvPara; /* an event parameter union */
  1074. pNet = netdev_priv(dev);
  1075. pAC = pNet->pAC;
  1076. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  1077. ("SkGeOpen: pAC=0x%lX:\n", (unsigned long)pAC));
  1078. #ifdef SK_DIAG_SUPPORT
  1079. if (pAC->DiagModeActive == DIAG_ACTIVE) {
  1080. if (pAC->Pnmi.DiagAttached == SK_DIAG_RUNNING) {
  1081. return (-1); /* still in use by diag; deny actions */
  1082. }
  1083. }
  1084. #endif
  1085. /* Set blink mode */
  1086. if ((pAC->PciDev->vendor == 0x1186) || (pAC->PciDev->vendor == 0x11ab ))
  1087. pAC->GIni.GILedBlinkCtrl = OEM_CONFIG_VALUE;
  1088. if (pAC->BoardLevel == SK_INIT_DATA) {
  1089. /* level 1 init common modules here */
  1090. if (SkGeInit(pAC, pAC->IoBase, SK_INIT_IO) != 0) {
  1091. printk("%s: HWInit (1) failed.\n", pAC->dev[pNet->PortNr]->name);
  1092. return (-1);
  1093. }
  1094. SkI2cInit (pAC, pAC->IoBase, SK_INIT_IO);
  1095. SkEventInit (pAC, pAC->IoBase, SK_INIT_IO);
  1096. SkPnmiInit (pAC, pAC->IoBase, SK_INIT_IO);
  1097. SkAddrInit (pAC, pAC->IoBase, SK_INIT_IO);
  1098. SkRlmtInit (pAC, pAC->IoBase, SK_INIT_IO);
  1099. SkTimerInit (pAC, pAC->IoBase, SK_INIT_IO);
  1100. pAC->BoardLevel = SK_INIT_IO;
  1101. }
  1102. if (pAC->BoardLevel != SK_INIT_RUN) {
  1103. /* tschilling: Level 2 init modules here, check return value. */
  1104. if (SkGeInit(pAC, pAC->IoBase, SK_INIT_RUN) != 0) {
  1105. printk("%s: HWInit (2) failed.\n", pAC->dev[pNet->PortNr]->name);
  1106. return (-1);
  1107. }
  1108. SkI2cInit (pAC, pAC->IoBase, SK_INIT_RUN);
  1109. SkEventInit (pAC, pAC->IoBase, SK_INIT_RUN);
  1110. SkPnmiInit (pAC, pAC->IoBase, SK_INIT_RUN);
  1111. SkAddrInit (pAC, pAC->IoBase, SK_INIT_RUN);
  1112. SkRlmtInit (pAC, pAC->IoBase, SK_INIT_RUN);
  1113. SkTimerInit (pAC, pAC->IoBase, SK_INIT_RUN);
  1114. pAC->BoardLevel = SK_INIT_RUN;
  1115. }
  1116. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  1117. /* Enable transmit descriptor polling. */
  1118. SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
  1119. FillRxRing(pAC, &pAC->RxPort[i]);
  1120. }
  1121. SkGeYellowLED(pAC, pAC->IoBase, 1);
  1122. StartDrvCleanupTimer(pAC);
  1123. SkDimEnableModerationIfNeeded(pAC);
  1124. SkDimDisplayModerationSettings(pAC);
  1125. pAC->GIni.GIValIrqMask &= IRQ_MASK;
  1126. /* enable Interrupts */
  1127. SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
  1128. SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
  1129. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  1130. if ((pAC->RlmtMode != 0) && (pAC->MaxPorts == 0)) {
  1131. EvPara.Para32[0] = pAC->RlmtNets;
  1132. EvPara.Para32[1] = -1;
  1133. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS,
  1134. EvPara);
  1135. EvPara.Para32[0] = pAC->RlmtMode;
  1136. EvPara.Para32[1] = 0;
  1137. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_MODE_CHANGE,
  1138. EvPara);
  1139. }
  1140. EvPara.Para32[0] = pNet->NetNr;
  1141. EvPara.Para32[1] = -1;
  1142. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
  1143. SkEventDispatcher(pAC, pAC->IoBase);
  1144. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  1145. pAC->MaxPorts++;
  1146. pNet->Up = 1;
  1147. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  1148. ("SkGeOpen suceeded\n"));
  1149. return (0);
  1150. } /* SkGeOpen */
  1151. /****************************************************************************
  1152. *
  1153. * SkGeClose - Stop initialized adapter
  1154. *
  1155. * Description:
  1156. * Close initialized adapter.
  1157. *
  1158. * Returns:
  1159. * 0 - on success
  1160. * error code - on error
  1161. */
  1162. static int SkGeClose(
  1163. struct SK_NET_DEVICE *dev)
  1164. {
  1165. DEV_NET *pNet;
  1166. DEV_NET *newPtrNet;
  1167. SK_AC *pAC;
  1168. unsigned long Flags; /* for spin lock */
  1169. int i;
  1170. int PortIdx;
  1171. SK_EVPARA EvPara;
  1172. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  1173. ("SkGeClose: pAC=0x%lX ", (unsigned long)pAC));
  1174. pNet = netdev_priv(dev);
  1175. pAC = pNet->pAC;
  1176. #ifdef SK_DIAG_SUPPORT
  1177. if (pAC->DiagModeActive == DIAG_ACTIVE) {
  1178. if (pAC->DiagFlowCtrl == SK_FALSE) {
  1179. /*
  1180. ** notify that the interface which has been closed
  1181. ** by operator interaction must not be started up
  1182. ** again when the DIAG has finished.
  1183. */
  1184. newPtrNet = netdev_priv(pAC->dev[0]);
  1185. if (newPtrNet == pNet) {
  1186. pAC->WasIfUp[0] = SK_FALSE;
  1187. } else {
  1188. pAC->WasIfUp[1] = SK_FALSE;
  1189. }
  1190. return 0; /* return to system everything is fine... */
  1191. } else {
  1192. pAC->DiagFlowCtrl = SK_FALSE;
  1193. }
  1194. }
  1195. #endif
  1196. netif_stop_queue(dev);
  1197. if (pAC->RlmtNets == 1)
  1198. PortIdx = pAC->ActivePort;
  1199. else
  1200. PortIdx = pNet->NetNr;
  1201. StopDrvCleanupTimer(pAC);
  1202. /*
  1203. * Clear multicast table, promiscuous mode ....
  1204. */
  1205. SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
  1206. SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
  1207. SK_PROM_MODE_NONE);
  1208. if (pAC->MaxPorts == 1) {
  1209. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  1210. /* disable interrupts */
  1211. SK_OUT32(pAC->IoBase, B0_IMSK, 0);
  1212. EvPara.Para32[0] = pNet->NetNr;
  1213. EvPara.Para32[1] = -1;
  1214. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
  1215. SkEventDispatcher(pAC, pAC->IoBase);
  1216. SK_OUT32(pAC->IoBase, B0_IMSK, 0);
  1217. /* stop the hardware */
  1218. SkGeDeInit(pAC, pAC->IoBase);
  1219. pAC->BoardLevel = SK_INIT_DATA;
  1220. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  1221. } else {
  1222. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  1223. EvPara.Para32[0] = pNet->NetNr;
  1224. EvPara.Para32[1] = -1;
  1225. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
  1226. SkPnmiEvent(pAC, pAC->IoBase, SK_PNMI_EVT_XMAC_RESET, EvPara);
  1227. SkEventDispatcher(pAC, pAC->IoBase);
  1228. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  1229. /* Stop port */
  1230. spin_lock_irqsave(&pAC->TxPort[pNet->PortNr]
  1231. [TX_PRIO_LOW].TxDesRingLock, Flags);
  1232. SkGeStopPort(pAC, pAC->IoBase, pNet->PortNr,
  1233. SK_STOP_ALL, SK_HARD_RST);
  1234. spin_unlock_irqrestore(&pAC->TxPort[pNet->PortNr]
  1235. [TX_PRIO_LOW].TxDesRingLock, Flags);
  1236. }
  1237. if (pAC->RlmtNets == 1) {
  1238. /* clear all descriptor rings */
  1239. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  1240. ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
  1241. ClearRxRing(pAC, &pAC->RxPort[i]);
  1242. ClearTxRing(pAC, &pAC->TxPort[i][TX_PRIO_LOW]);
  1243. }
  1244. } else {
  1245. /* clear port descriptor rings */
  1246. ReceiveIrq(pAC, &pAC->RxPort[pNet->PortNr], SK_TRUE);
  1247. ClearRxRing(pAC, &pAC->RxPort[pNet->PortNr]);
  1248. ClearTxRing(pAC, &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW]);
  1249. }
  1250. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  1251. ("SkGeClose: done "));
  1252. SK_MEMSET(&(pAC->PnmiBackup), 0, sizeof(SK_PNMI_STRUCT_DATA));
  1253. SK_MEMCPY(&(pAC->PnmiBackup), &(pAC->PnmiStruct),
  1254. sizeof(SK_PNMI_STRUCT_DATA));
  1255. pAC->MaxPorts--;
  1256. pNet->Up = 0;
  1257. return (0);
  1258. } /* SkGeClose */
  1259. /*****************************************************************************
  1260. *
  1261. * SkGeXmit - Linux frame transmit function
  1262. *
  1263. * Description:
  1264. * The system calls this function to send frames onto the wire.
  1265. * It puts the frame in the tx descriptor ring. If the ring is
  1266. * full then, the 'tbusy' flag is set.
  1267. *
  1268. * Returns:
  1269. * 0, if everything is ok
  1270. * !=0, on error
  1271. * WARNING: returning 1 in 'tbusy' case caused system crashes (double
  1272. * allocated skb's) !!!
  1273. */
  1274. static int SkGeXmit(struct sk_buff *skb, struct SK_NET_DEVICE *dev)
  1275. {
  1276. DEV_NET *pNet;
  1277. SK_AC *pAC;
  1278. int Rc; /* return code of XmitFrame */
  1279. pNet = netdev_priv(dev);
  1280. pAC = pNet->pAC;
  1281. if ((!skb_shinfo(skb)->nr_frags) ||
  1282. (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) {
  1283. /* Don't activate scatter-gather and hardware checksum */
  1284. if (pAC->RlmtNets == 2)
  1285. Rc = XmitFrame(
  1286. pAC,
  1287. &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
  1288. skb);
  1289. else
  1290. Rc = XmitFrame(
  1291. pAC,
  1292. &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
  1293. skb);
  1294. } else {
  1295. /* scatter-gather and hardware TCP checksumming anabled*/
  1296. if (pAC->RlmtNets == 2)
  1297. Rc = XmitFrameSG(
  1298. pAC,
  1299. &pAC->TxPort[pNet->PortNr][TX_PRIO_LOW],
  1300. skb);
  1301. else
  1302. Rc = XmitFrameSG(
  1303. pAC,
  1304. &pAC->TxPort[pAC->ActivePort][TX_PRIO_LOW],
  1305. skb);
  1306. }
  1307. /* Transmitter out of resources? */
  1308. if (Rc <= 0) {
  1309. netif_stop_queue(dev);
  1310. }
  1311. /* If not taken, give buffer ownership back to the
  1312. * queueing layer.
  1313. */
  1314. if (Rc < 0)
  1315. return (1);
  1316. dev->trans_start = jiffies;
  1317. return (0);
  1318. } /* SkGeXmit */
  1319. /*****************************************************************************
  1320. *
  1321. * XmitFrame - fill one socket buffer into the transmit ring
  1322. *
  1323. * Description:
  1324. * This function puts a message into the transmit descriptor ring
  1325. * if there is a descriptors left.
  1326. * Linux skb's consist of only one continuous buffer.
  1327. * The first step locks the ring. It is held locked
  1328. * all time to avoid problems with SWITCH_../PORT_RESET.
  1329. * Then the descriptoris allocated.
  1330. * The second part is linking the buffer to the descriptor.
  1331. * At the very last, the Control field of the descriptor
  1332. * is made valid for the BMU and a start TX command is given
  1333. * if necessary.
  1334. *
  1335. * Returns:
  1336. * > 0 - on succes: the number of bytes in the message
  1337. * = 0 - on resource shortage: this frame sent or dropped, now
  1338. * the ring is full ( -> set tbusy)
  1339. * < 0 - on failure: other problems ( -> return failure to upper layers)
  1340. */
  1341. static int XmitFrame(
  1342. SK_AC *pAC, /* pointer to adapter context */
  1343. TX_PORT *pTxPort, /* pointer to struct of port to send to */
  1344. struct sk_buff *pMessage) /* pointer to send-message */
  1345. {
  1346. TXD *pTxd; /* the rxd to fill */
  1347. TXD *pOldTxd;
  1348. unsigned long Flags;
  1349. SK_U64 PhysAddr;
  1350. int Protocol;
  1351. int IpHeaderLength;
  1352. int BytesSend = pMessage->len;
  1353. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_TX_PROGRESS, ("X"));
  1354. spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
  1355. #ifndef USE_TX_COMPLETE
  1356. FreeTxDescriptors(pAC, pTxPort);
  1357. #endif
  1358. if (pTxPort->TxdRingFree == 0) {
  1359. /*
  1360. ** no enough free descriptors in ring at the moment.
  1361. ** Maybe free'ing some old one help?
  1362. */
  1363. FreeTxDescriptors(pAC, pTxPort);
  1364. if (pTxPort->TxdRingFree == 0) {
  1365. spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
  1366. SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
  1367. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1368. SK_DBGCAT_DRV_TX_PROGRESS,
  1369. ("XmitFrame failed\n"));
  1370. /*
  1371. ** the desired message can not be sent
  1372. ** Because tbusy seems to be set, the message
  1373. ** should not be freed here. It will be used
  1374. ** by the scheduler of the ethernet handler
  1375. */
  1376. return (-1);
  1377. }
  1378. }
  1379. /*
  1380. ** If the passed socket buffer is of smaller MTU-size than 60,
  1381. ** copy everything into new buffer and fill all bytes between
  1382. ** the original packet end and the new packet end of 60 with 0x00.
  1383. ** This is to resolve faulty padding by the HW with 0xaa bytes.
  1384. */
  1385. if (BytesSend < C_LEN_ETHERNET_MINSIZE) {
  1386. if ((pMessage = skb_padto(pMessage, C_LEN_ETHERNET_MINSIZE)) == NULL) {
  1387. spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
  1388. return 0;
  1389. }
  1390. pMessage->len = C_LEN_ETHERNET_MINSIZE;
  1391. }
  1392. /*
  1393. ** advance head counter behind descriptor needed for this frame,
  1394. ** so that needed descriptor is reserved from that on. The next
  1395. ** action will be to add the passed buffer to the TX-descriptor
  1396. */
  1397. pTxd = pTxPort->pTxdRingHead;
  1398. pTxPort->pTxdRingHead = pTxd->pNextTxd;
  1399. pTxPort->TxdRingFree--;
  1400. #ifdef SK_DUMP_TX
  1401. DumpMsg(pMessage, "XmitFrame");
  1402. #endif
  1403. /*
  1404. ** First step is to map the data to be sent via the adapter onto
  1405. ** the DMA memory. Kernel 2.2 uses virt_to_bus(), but kernels 2.4
  1406. ** and 2.6 need to use pci_map_page() for that mapping.
  1407. */
  1408. PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
  1409. virt_to_page(pMessage->data),
  1410. ((unsigned long) pMessage->data & ~PAGE_MASK),
  1411. pMessage->len,
  1412. PCI_DMA_TODEVICE);
  1413. pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
  1414. pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
  1415. pTxd->pMBuf = pMessage;
  1416. if (pMessage->ip_summed == CHECKSUM_HW) {
  1417. Protocol = ((SK_U8)pMessage->data[C_OFFSET_IPPROTO] & 0xff);
  1418. if ((Protocol == C_PROTO_ID_UDP) &&
  1419. (pAC->GIni.GIChipRev == 0) &&
  1420. (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
  1421. pTxd->TBControl = BMU_TCP_CHECK;
  1422. } else {
  1423. pTxd->TBControl = BMU_UDP_CHECK;
  1424. }
  1425. IpHeaderLength = (SK_U8)pMessage->data[C_OFFSET_IPHEADER];
  1426. IpHeaderLength = (IpHeaderLength & 0xf) * 4;
  1427. pTxd->TcpSumOfs = 0; /* PH-Checksum already calculated */
  1428. pTxd->TcpSumSt = C_LEN_ETHERMAC_HEADER + IpHeaderLength +
  1429. (Protocol == C_PROTO_ID_UDP ?
  1430. C_OFFSET_UDPHEADER_UDPCS :
  1431. C_OFFSET_TCPHEADER_TCPCS);
  1432. pTxd->TcpSumWr = C_LEN_ETHERMAC_HEADER + IpHeaderLength;
  1433. pTxd->TBControl |= BMU_OWN | BMU_STF |
  1434. BMU_SW | BMU_EOF |
  1435. #ifdef USE_TX_COMPLETE
  1436. BMU_IRQ_EOF |
  1437. #endif
  1438. pMessage->len;
  1439. } else {
  1440. pTxd->TBControl = BMU_OWN | BMU_STF | BMU_CHECK |
  1441. BMU_SW | BMU_EOF |
  1442. #ifdef USE_TX_COMPLETE
  1443. BMU_IRQ_EOF |
  1444. #endif
  1445. pMessage->len;
  1446. }
  1447. /*
  1448. ** If previous descriptor already done, give TX start cmd
  1449. */
  1450. pOldTxd = xchg(&pTxPort->pTxdRingPrev, pTxd);
  1451. if ((pOldTxd->TBControl & BMU_OWN) == 0) {
  1452. SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
  1453. }
  1454. /*
  1455. ** after releasing the lock, the skb may immediately be free'd
  1456. */
  1457. spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
  1458. if (pTxPort->TxdRingFree != 0) {
  1459. return (BytesSend);
  1460. } else {
  1461. return (0);
  1462. }
  1463. } /* XmitFrame */
  1464. /*****************************************************************************
  1465. *
  1466. * XmitFrameSG - fill one socket buffer into the transmit ring
  1467. * (use SG and TCP/UDP hardware checksumming)
  1468. *
  1469. * Description:
  1470. * This function puts a message into the transmit descriptor ring
  1471. * if there is a descriptors left.
  1472. *
  1473. * Returns:
  1474. * > 0 - on succes: the number of bytes in the message
  1475. * = 0 - on resource shortage: this frame sent or dropped, now
  1476. * the ring is full ( -> set tbusy)
  1477. * < 0 - on failure: other problems ( -> return failure to upper layers)
  1478. */
  1479. static int XmitFrameSG(
  1480. SK_AC *pAC, /* pointer to adapter context */
  1481. TX_PORT *pTxPort, /* pointer to struct of port to send to */
  1482. struct sk_buff *pMessage) /* pointer to send-message */
  1483. {
  1484. TXD *pTxd;
  1485. TXD *pTxdFst;
  1486. TXD *pTxdLst;
  1487. int CurrFrag;
  1488. int BytesSend;
  1489. int IpHeaderLength;
  1490. int Protocol;
  1491. skb_frag_t *sk_frag;
  1492. SK_U64 PhysAddr;
  1493. unsigned long Flags;
  1494. spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
  1495. #ifndef USE_TX_COMPLETE
  1496. FreeTxDescriptors(pAC, pTxPort);
  1497. #endif
  1498. if ((skb_shinfo(pMessage)->nr_frags +1) > pTxPort->TxdRingFree) {
  1499. FreeTxDescriptors(pAC, pTxPort);
  1500. if ((skb_shinfo(pMessage)->nr_frags + 1) > pTxPort->TxdRingFree) {
  1501. spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
  1502. SK_PNMI_CNT_NO_TX_BUF(pAC, pTxPort->PortIndex);
  1503. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1504. SK_DBGCAT_DRV_TX_PROGRESS,
  1505. ("XmitFrameSG failed - Ring full\n"));
  1506. /* this message can not be sent now */
  1507. return(-1);
  1508. }
  1509. }
  1510. pTxd = pTxPort->pTxdRingHead;
  1511. pTxdFst = pTxd;
  1512. pTxdLst = pTxd;
  1513. BytesSend = 0;
  1514. Protocol = 0;
  1515. /*
  1516. ** Map the first fragment (header) into the DMA-space
  1517. */
  1518. PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
  1519. virt_to_page(pMessage->data),
  1520. ((unsigned long) pMessage->data & ~PAGE_MASK),
  1521. skb_headlen(pMessage),
  1522. PCI_DMA_TODEVICE);
  1523. pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
  1524. pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
  1525. /*
  1526. ** Does the HW need to evaluate checksum for TCP or UDP packets?
  1527. */
  1528. if (pMessage->ip_summed == CHECKSUM_HW) {
  1529. pTxd->TBControl = BMU_STF | BMU_STFWD | skb_headlen(pMessage);
  1530. /*
  1531. ** We have to use the opcode for tcp here, because the
  1532. ** opcode for udp is not working in the hardware yet
  1533. ** (Revision 2.0)
  1534. */
  1535. Protocol = ((SK_U8)pMessage->data[C_OFFSET_IPPROTO] & 0xff);
  1536. if ((Protocol == C_PROTO_ID_UDP) &&
  1537. (pAC->GIni.GIChipRev == 0) &&
  1538. (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
  1539. pTxd->TBControl |= BMU_TCP_CHECK;
  1540. } else {
  1541. pTxd->TBControl |= BMU_UDP_CHECK;
  1542. }
  1543. IpHeaderLength = ((SK_U8)pMessage->data[C_OFFSET_IPHEADER] & 0xf)*4;
  1544. pTxd->TcpSumOfs = 0; /* PH-Checksum already claculated */
  1545. pTxd->TcpSumSt = C_LEN_ETHERMAC_HEADER + IpHeaderLength +
  1546. (Protocol == C_PROTO_ID_UDP ?
  1547. C_OFFSET_UDPHEADER_UDPCS :
  1548. C_OFFSET_TCPHEADER_TCPCS);
  1549. pTxd->TcpSumWr = C_LEN_ETHERMAC_HEADER + IpHeaderLength;
  1550. } else {
  1551. pTxd->TBControl = BMU_CHECK | BMU_SW | BMU_STF |
  1552. skb_headlen(pMessage);
  1553. }
  1554. pTxd = pTxd->pNextTxd;
  1555. pTxPort->TxdRingFree--;
  1556. BytesSend += skb_headlen(pMessage);
  1557. /*
  1558. ** Browse over all SG fragments and map each of them into the DMA space
  1559. */
  1560. for (CurrFrag = 0; CurrFrag < skb_shinfo(pMessage)->nr_frags; CurrFrag++) {
  1561. sk_frag = &skb_shinfo(pMessage)->frags[CurrFrag];
  1562. /*
  1563. ** we already have the proper value in entry
  1564. */
  1565. PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
  1566. sk_frag->page,
  1567. sk_frag->page_offset,
  1568. sk_frag->size,
  1569. PCI_DMA_TODEVICE);
  1570. pTxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
  1571. pTxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
  1572. pTxd->pMBuf = pMessage;
  1573. /*
  1574. ** Does the HW need to evaluate checksum for TCP or UDP packets?
  1575. */
  1576. if (pMessage->ip_summed == CHECKSUM_HW) {
  1577. pTxd->TBControl = BMU_OWN | BMU_SW | BMU_STFWD;
  1578. /*
  1579. ** We have to use the opcode for tcp here because the
  1580. ** opcode for udp is not working in the hardware yet
  1581. ** (revision 2.0)
  1582. */
  1583. if ((Protocol == C_PROTO_ID_UDP) &&
  1584. (pAC->GIni.GIChipRev == 0) &&
  1585. (pAC->GIni.GIChipId == CHIP_ID_YUKON)) {
  1586. pTxd->TBControl |= BMU_TCP_CHECK;
  1587. } else {
  1588. pTxd->TBControl |= BMU_UDP_CHECK;
  1589. }
  1590. } else {
  1591. pTxd->TBControl = BMU_CHECK | BMU_SW | BMU_OWN;
  1592. }
  1593. /*
  1594. ** Do we have the last fragment?
  1595. */
  1596. if( (CurrFrag+1) == skb_shinfo(pMessage)->nr_frags ) {
  1597. #ifdef USE_TX_COMPLETE
  1598. pTxd->TBControl |= BMU_EOF | BMU_IRQ_EOF | sk_frag->size;
  1599. #else
  1600. pTxd->TBControl |= BMU_EOF | sk_frag->size;
  1601. #endif
  1602. pTxdFst->TBControl |= BMU_OWN | BMU_SW;
  1603. } else {
  1604. pTxd->TBControl |= sk_frag->size;
  1605. }
  1606. pTxdLst = pTxd;
  1607. pTxd = pTxd->pNextTxd;
  1608. pTxPort->TxdRingFree--;
  1609. BytesSend += sk_frag->size;
  1610. }
  1611. /*
  1612. ** If previous descriptor already done, give TX start cmd
  1613. */
  1614. if ((pTxPort->pTxdRingPrev->TBControl & BMU_OWN) == 0) {
  1615. SK_OUT8(pTxPort->HwAddr, Q_CSR, CSR_START);
  1616. }
  1617. pTxPort->pTxdRingPrev = pTxdLst;
  1618. pTxPort->pTxdRingHead = pTxd;
  1619. spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
  1620. if (pTxPort->TxdRingFree > 0) {
  1621. return (BytesSend);
  1622. } else {
  1623. return (0);
  1624. }
  1625. }
  1626. /*****************************************************************************
  1627. *
  1628. * FreeTxDescriptors - release descriptors from the descriptor ring
  1629. *
  1630. * Description:
  1631. * This function releases descriptors from a transmit ring if they
  1632. * have been sent by the BMU.
  1633. * If a descriptors is sent, it can be freed and the message can
  1634. * be freed, too.
  1635. * The SOFTWARE controllable bit is used to prevent running around a
  1636. * completely free ring for ever. If this bit is no set in the
  1637. * frame (by XmitFrame), this frame has never been sent or is
  1638. * already freed.
  1639. * The Tx descriptor ring lock must be held while calling this function !!!
  1640. *
  1641. * Returns:
  1642. * none
  1643. */
  1644. static void FreeTxDescriptors(
  1645. SK_AC *pAC, /* pointer to the adapter context */
  1646. TX_PORT *pTxPort) /* pointer to destination port structure */
  1647. {
  1648. TXD *pTxd; /* pointer to the checked descriptor */
  1649. TXD *pNewTail; /* pointer to 'end' of the ring */
  1650. SK_U32 Control; /* TBControl field of descriptor */
  1651. SK_U64 PhysAddr; /* address of DMA mapping */
  1652. pNewTail = pTxPort->pTxdRingTail;
  1653. pTxd = pNewTail;
  1654. /*
  1655. ** loop forever; exits if BMU_SW bit not set in start frame
  1656. ** or BMU_OWN bit set in any frame
  1657. */
  1658. while (1) {
  1659. Control = pTxd->TBControl;
  1660. if ((Control & BMU_SW) == 0) {
  1661. /*
  1662. ** software controllable bit is set in first
  1663. ** fragment when given to BMU. Not set means that
  1664. ** this fragment was never sent or is already
  1665. ** freed ( -> ring completely free now).
  1666. */
  1667. pTxPort->pTxdRingTail = pTxd;
  1668. netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
  1669. return;
  1670. }
  1671. if (Control & BMU_OWN) {
  1672. pTxPort->pTxdRingTail = pTxd;
  1673. if (pTxPort->TxdRingFree > 0) {
  1674. netif_wake_queue(pAC->dev[pTxPort->PortIndex]);
  1675. }
  1676. return;
  1677. }
  1678. /*
  1679. ** release the DMA mapping, because until not unmapped
  1680. ** this buffer is considered being under control of the
  1681. ** adapter card!
  1682. */
  1683. PhysAddr = ((SK_U64) pTxd->VDataHigh) << (SK_U64) 32;
  1684. PhysAddr |= (SK_U64) pTxd->VDataLow;
  1685. pci_unmap_page(pAC->PciDev, PhysAddr,
  1686. pTxd->pMBuf->len,
  1687. PCI_DMA_TODEVICE);
  1688. if (Control & BMU_EOF)
  1689. DEV_KFREE_SKB_ANY(pTxd->pMBuf); /* free message */
  1690. pTxPort->TxdRingFree++;
  1691. pTxd->TBControl &= ~BMU_SW;
  1692. pTxd = pTxd->pNextTxd; /* point behind fragment with EOF */
  1693. } /* while(forever) */
  1694. } /* FreeTxDescriptors */
  1695. /*****************************************************************************
  1696. *
  1697. * FillRxRing - fill the receive ring with valid descriptors
  1698. *
  1699. * Description:
  1700. * This function fills the receive ring descriptors with data
  1701. * segments and makes them valid for the BMU.
  1702. * The active ring is filled completely, if possible.
  1703. * The non-active ring is filled only partial to save memory.
  1704. *
  1705. * Description of rx ring structure:
  1706. * head - points to the descriptor which will be used next by the BMU
  1707. * tail - points to the next descriptor to give to the BMU
  1708. *
  1709. * Returns: N/A
  1710. */
  1711. static void FillRxRing(
  1712. SK_AC *pAC, /* pointer to the adapter context */
  1713. RX_PORT *pRxPort) /* ptr to port struct for which the ring
  1714. should be filled */
  1715. {
  1716. unsigned long Flags;
  1717. spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
  1718. while (pRxPort->RxdRingFree > pRxPort->RxFillLimit) {
  1719. if(!FillRxDescriptor(pAC, pRxPort))
  1720. break;
  1721. }
  1722. spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
  1723. } /* FillRxRing */
  1724. /*****************************************************************************
  1725. *
  1726. * FillRxDescriptor - fill one buffer into the receive ring
  1727. *
  1728. * Description:
  1729. * The function allocates a new receive buffer and
  1730. * puts it into the next descriptor.
  1731. *
  1732. * Returns:
  1733. * SK_TRUE - a buffer was added to the ring
  1734. * SK_FALSE - a buffer could not be added
  1735. */
  1736. static SK_BOOL FillRxDescriptor(
  1737. SK_AC *pAC, /* pointer to the adapter context struct */
  1738. RX_PORT *pRxPort) /* ptr to port struct of ring to fill */
  1739. {
  1740. struct sk_buff *pMsgBlock; /* pointer to a new message block */
  1741. RXD *pRxd; /* the rxd to fill */
  1742. SK_U16 Length; /* data fragment length */
  1743. SK_U64 PhysAddr; /* physical address of a rx buffer */
  1744. pMsgBlock = alloc_skb(pAC->RxBufSize, GFP_ATOMIC);
  1745. if (pMsgBlock == NULL) {
  1746. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1747. SK_DBGCAT_DRV_ENTRY,
  1748. ("%s: Allocation of rx buffer failed !\n",
  1749. pAC->dev[pRxPort->PortIndex]->name));
  1750. SK_PNMI_CNT_NO_RX_BUF(pAC, pRxPort->PortIndex);
  1751. return(SK_FALSE);
  1752. }
  1753. skb_reserve(pMsgBlock, 2); /* to align IP frames */
  1754. /* skb allocated ok, so add buffer */
  1755. pRxd = pRxPort->pRxdRingTail;
  1756. pRxPort->pRxdRingTail = pRxd->pNextRxd;
  1757. pRxPort->RxdRingFree--;
  1758. Length = pAC->RxBufSize;
  1759. PhysAddr = (SK_U64) pci_map_page(pAC->PciDev,
  1760. virt_to_page(pMsgBlock->data),
  1761. ((unsigned long) pMsgBlock->data &
  1762. ~PAGE_MASK),
  1763. pAC->RxBufSize - 2,
  1764. PCI_DMA_FROMDEVICE);
  1765. pRxd->VDataLow = (SK_U32) (PhysAddr & 0xffffffff);
  1766. pRxd->VDataHigh = (SK_U32) (PhysAddr >> 32);
  1767. pRxd->pMBuf = pMsgBlock;
  1768. pRxd->RBControl = BMU_OWN |
  1769. BMU_STF |
  1770. BMU_IRQ_EOF |
  1771. BMU_TCP_CHECK |
  1772. Length;
  1773. return (SK_TRUE);
  1774. } /* FillRxDescriptor */
  1775. /*****************************************************************************
  1776. *
  1777. * ReQueueRxBuffer - fill one buffer back into the receive ring
  1778. *
  1779. * Description:
  1780. * Fill a given buffer back into the rx ring. The buffer
  1781. * has been previously allocated and aligned, and its phys.
  1782. * address calculated, so this is no more necessary.
  1783. *
  1784. * Returns: N/A
  1785. */
  1786. static void ReQueueRxBuffer(
  1787. SK_AC *pAC, /* pointer to the adapter context struct */
  1788. RX_PORT *pRxPort, /* ptr to port struct of ring to fill */
  1789. struct sk_buff *pMsg, /* pointer to the buffer */
  1790. SK_U32 PhysHigh, /* phys address high dword */
  1791. SK_U32 PhysLow) /* phys address low dword */
  1792. {
  1793. RXD *pRxd; /* the rxd to fill */
  1794. SK_U16 Length; /* data fragment length */
  1795. pRxd = pRxPort->pRxdRingTail;
  1796. pRxPort->pRxdRingTail = pRxd->pNextRxd;
  1797. pRxPort->RxdRingFree--;
  1798. Length = pAC->RxBufSize;
  1799. pRxd->VDataLow = PhysLow;
  1800. pRxd->VDataHigh = PhysHigh;
  1801. pRxd->pMBuf = pMsg;
  1802. pRxd->RBControl = BMU_OWN |
  1803. BMU_STF |
  1804. BMU_IRQ_EOF |
  1805. BMU_TCP_CHECK |
  1806. Length;
  1807. return;
  1808. } /* ReQueueRxBuffer */
  1809. /*****************************************************************************
  1810. *
  1811. * ReceiveIrq - handle a receive IRQ
  1812. *
  1813. * Description:
  1814. * This function is called when a receive IRQ is set.
  1815. * It walks the receive descriptor ring and sends up all
  1816. * frames that are complete.
  1817. *
  1818. * Returns: N/A
  1819. */
  1820. static void ReceiveIrq(
  1821. SK_AC *pAC, /* pointer to adapter context */
  1822. RX_PORT *pRxPort, /* pointer to receive port struct */
  1823. SK_BOOL SlowPathLock) /* indicates if SlowPathLock is needed */
  1824. {
  1825. RXD *pRxd; /* pointer to receive descriptors */
  1826. SK_U32 Control; /* control field of descriptor */
  1827. struct sk_buff *pMsg; /* pointer to message holding frame */
  1828. struct sk_buff *pNewMsg; /* pointer to a new message for copying frame */
  1829. int FrameLength; /* total length of received frame */
  1830. int IpFrameLength;
  1831. SK_MBUF *pRlmtMbuf; /* ptr to a buffer for giving a frame to rlmt */
  1832. SK_EVPARA EvPara; /* an event parameter union */
  1833. unsigned long Flags; /* for spin lock */
  1834. int PortIndex = pRxPort->PortIndex;
  1835. unsigned int Offset;
  1836. unsigned int NumBytes;
  1837. unsigned int ForRlmt;
  1838. SK_BOOL IsBc;
  1839. SK_BOOL IsMc;
  1840. SK_BOOL IsBadFrame; /* Bad frame */
  1841. SK_U32 FrameStat;
  1842. unsigned short Csum1;
  1843. unsigned short Csum2;
  1844. unsigned short Type;
  1845. int Result;
  1846. SK_U64 PhysAddr;
  1847. rx_start:
  1848. /* do forever; exit if BMU_OWN found */
  1849. for ( pRxd = pRxPort->pRxdRingHead ;
  1850. pRxPort->RxdRingFree < pAC->RxDescrPerRing ;
  1851. pRxd = pRxd->pNextRxd,
  1852. pRxPort->pRxdRingHead = pRxd,
  1853. pRxPort->RxdRingFree ++) {
  1854. /*
  1855. * For a better understanding of this loop
  1856. * Go through every descriptor beginning at the head
  1857. * Please note: the ring might be completely received so the OWN bit
  1858. * set is not a good crirteria to leave that loop.
  1859. * Therefore the RingFree counter is used.
  1860. * On entry of this loop pRxd is a pointer to the Rxd that needs
  1861. * to be checked next.
  1862. */
  1863. Control = pRxd->RBControl;
  1864. /* check if this descriptor is ready */
  1865. if ((Control & BMU_OWN) != 0) {
  1866. /* this descriptor is not yet ready */
  1867. /* This is the usual end of the loop */
  1868. /* We don't need to start the ring again */
  1869. FillRxRing(pAC, pRxPort);
  1870. return;
  1871. }
  1872. pAC->DynIrqModInfo.NbrProcessedDescr++;
  1873. /* get length of frame and check it */
  1874. FrameLength = Control & BMU_BBC;
  1875. if (FrameLength > pAC->RxBufSize) {
  1876. goto rx_failed;
  1877. }
  1878. /* check for STF and EOF */
  1879. if ((Control & (BMU_STF | BMU_EOF)) != (BMU_STF | BMU_EOF)) {
  1880. goto rx_failed;
  1881. }
  1882. /* here we have a complete frame in the ring */
  1883. pMsg = pRxd->pMBuf;
  1884. FrameStat = pRxd->FrameStat;
  1885. /* check for frame length mismatch */
  1886. #define XMR_FS_LEN_SHIFT 18
  1887. #define GMR_FS_LEN_SHIFT 16
  1888. if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
  1889. if (FrameLength != (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)) {
  1890. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1891. SK_DBGCAT_DRV_RX_PROGRESS,
  1892. ("skge: Frame length mismatch (%u/%u).\n",
  1893. FrameLength,
  1894. (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
  1895. goto rx_failed;
  1896. }
  1897. }
  1898. else {
  1899. if (FrameLength != (SK_U32) (FrameStat >> GMR_FS_LEN_SHIFT)) {
  1900. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1901. SK_DBGCAT_DRV_RX_PROGRESS,
  1902. ("skge: Frame length mismatch (%u/%u).\n",
  1903. FrameLength,
  1904. (SK_U32) (FrameStat >> XMR_FS_LEN_SHIFT)));
  1905. goto rx_failed;
  1906. }
  1907. }
  1908. /* Set Rx Status */
  1909. if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
  1910. IsBc = (FrameStat & XMR_FS_BC) != 0;
  1911. IsMc = (FrameStat & XMR_FS_MC) != 0;
  1912. IsBadFrame = (FrameStat &
  1913. (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0;
  1914. } else {
  1915. IsBc = (FrameStat & GMR_FS_BC) != 0;
  1916. IsMc = (FrameStat & GMR_FS_MC) != 0;
  1917. IsBadFrame = (((FrameStat & GMR_FS_ANY_ERR) != 0) ||
  1918. ((FrameStat & GMR_FS_RX_OK) == 0));
  1919. }
  1920. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
  1921. ("Received frame of length %d on port %d\n",
  1922. FrameLength, PortIndex));
  1923. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 0,
  1924. ("Number of free rx descriptors: %d\n",
  1925. pRxPort->RxdRingFree));
  1926. /* DumpMsg(pMsg, "Rx"); */
  1927. if ((Control & BMU_STAT_VAL) != BMU_STAT_VAL || (IsBadFrame)) {
  1928. #if 0
  1929. (FrameStat & (XMR_FS_ANY_ERR | XMR_FS_2L_VLAN)) != 0) {
  1930. #endif
  1931. /* there is a receive error in this frame */
  1932. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  1933. SK_DBGCAT_DRV_RX_PROGRESS,
  1934. ("skge: Error in received frame, dropped!\n"
  1935. "Control: %x\nRxStat: %x\n",
  1936. Control, FrameStat));
  1937. ReQueueRxBuffer(pAC, pRxPort, pMsg,
  1938. pRxd->VDataHigh, pRxd->VDataLow);
  1939. continue;
  1940. }
  1941. /*
  1942. * if short frame then copy data to reduce memory waste
  1943. */
  1944. if ((FrameLength < SK_COPY_THRESHOLD) &&
  1945. ((pNewMsg = alloc_skb(FrameLength+2, GFP_ATOMIC)) != NULL)) {
  1946. /*
  1947. * Short frame detected and allocation successfull
  1948. */
  1949. /* use new skb and copy data */
  1950. skb_reserve(pNewMsg, 2);
  1951. skb_put(pNewMsg, FrameLength);
  1952. PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
  1953. PhysAddr |= (SK_U64) pRxd->VDataLow;
  1954. pci_dma_sync_single_for_cpu(pAC->PciDev,
  1955. (dma_addr_t) PhysAddr,
  1956. FrameLength,
  1957. PCI_DMA_FROMDEVICE);
  1958. eth_copy_and_sum(pNewMsg, pMsg->data,
  1959. FrameLength, 0);
  1960. pci_dma_sync_single_for_device(pAC->PciDev,
  1961. (dma_addr_t) PhysAddr,
  1962. FrameLength,
  1963. PCI_DMA_FROMDEVICE);
  1964. ReQueueRxBuffer(pAC, pRxPort, pMsg,
  1965. pRxd->VDataHigh, pRxd->VDataLow);
  1966. pMsg = pNewMsg;
  1967. }
  1968. else {
  1969. /*
  1970. * if large frame, or SKB allocation failed, pass
  1971. * the SKB directly to the networking
  1972. */
  1973. PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
  1974. PhysAddr |= (SK_U64) pRxd->VDataLow;
  1975. /* release the DMA mapping */
  1976. pci_unmap_single(pAC->PciDev,
  1977. PhysAddr,
  1978. pAC->RxBufSize - 2,
  1979. PCI_DMA_FROMDEVICE);
  1980. /* set length in message */
  1981. skb_put(pMsg, FrameLength);
  1982. /* hardware checksum */
  1983. Type = ntohs(*((short*)&pMsg->data[12]));
  1984. #ifdef USE_SK_RX_CHECKSUM
  1985. if (Type == 0x800) {
  1986. Csum1=le16_to_cpu(pRxd->TcpSums & 0xffff);
  1987. Csum2=le16_to_cpu((pRxd->TcpSums >> 16) & 0xffff);
  1988. IpFrameLength = (int) ntohs((unsigned short)
  1989. ((unsigned short *) pMsg->data)[8]);
  1990. /*
  1991. * Test: If frame is padded, a check is not possible!
  1992. * Frame not padded? Length difference must be 14 (0xe)!
  1993. */
  1994. if ((FrameLength - IpFrameLength) != 0xe) {
  1995. /* Frame padded => TCP offload not possible! */
  1996. pMsg->ip_summed = CHECKSUM_NONE;
  1997. } else {
  1998. /* Frame not padded => TCP offload! */
  1999. if ((((Csum1 & 0xfffe) && (Csum2 & 0xfffe)) &&
  2000. (pAC->GIni.GIChipId == CHIP_ID_GENESIS)) ||
  2001. (pAC->ChipsetType)) {
  2002. Result = SkCsGetReceiveInfo(pAC,
  2003. &pMsg->data[14],
  2004. Csum1, Csum2, pRxPort->PortIndex);
  2005. if (Result ==
  2006. SKCS_STATUS_IP_FRAGMENT ||
  2007. Result ==
  2008. SKCS_STATUS_IP_CSUM_OK ||
  2009. Result ==
  2010. SKCS_STATUS_TCP_CSUM_OK ||
  2011. Result ==
  2012. SKCS_STATUS_UDP_CSUM_OK) {
  2013. pMsg->ip_summed =
  2014. CHECKSUM_UNNECESSARY;
  2015. }
  2016. else if (Result ==
  2017. SKCS_STATUS_TCP_CSUM_ERROR ||
  2018. Result ==
  2019. SKCS_STATUS_UDP_CSUM_ERROR ||
  2020. Result ==
  2021. SKCS_STATUS_IP_CSUM_ERROR_UDP ||
  2022. Result ==
  2023. SKCS_STATUS_IP_CSUM_ERROR_TCP ||
  2024. Result ==
  2025. SKCS_STATUS_IP_CSUM_ERROR ) {
  2026. /* HW Checksum error */
  2027. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  2028. SK_DBGCAT_DRV_RX_PROGRESS,
  2029. ("skge: CRC error. Frame dropped!\n"));
  2030. goto rx_failed;
  2031. } else {
  2032. pMsg->ip_summed =
  2033. CHECKSUM_NONE;
  2034. }
  2035. }/* checksumControl calculation valid */
  2036. } /* Frame length check */
  2037. } /* IP frame */
  2038. #else
  2039. pMsg->ip_summed = CHECKSUM_NONE;
  2040. #endif
  2041. } /* frame > SK_COPY_TRESHOLD */
  2042. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("V"));
  2043. ForRlmt = SK_RLMT_RX_PROTOCOL;
  2044. #if 0
  2045. IsBc = (FrameStat & XMR_FS_BC)==XMR_FS_BC;
  2046. #endif
  2047. SK_RLMT_PRE_LOOKAHEAD(pAC, PortIndex, FrameLength,
  2048. IsBc, &Offset, &NumBytes);
  2049. if (NumBytes != 0) {
  2050. #if 0
  2051. IsMc = (FrameStat & XMR_FS_MC)==XMR_FS_MC;
  2052. #endif
  2053. SK_RLMT_LOOKAHEAD(pAC, PortIndex,
  2054. &pMsg->data[Offset],
  2055. IsBc, IsMc, &ForRlmt);
  2056. }
  2057. if (ForRlmt == SK_RLMT_RX_PROTOCOL) {
  2058. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("W"));
  2059. /* send up only frames from active port */
  2060. if ((PortIndex == pAC->ActivePort) ||
  2061. (pAC->RlmtNets == 2)) {
  2062. /* frame for upper layer */
  2063. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, 1,("U"));
  2064. #ifdef xDEBUG
  2065. DumpMsg(pMsg, "Rx");
  2066. #endif
  2067. SK_PNMI_CNT_RX_OCTETS_DELIVERED(pAC,
  2068. FrameLength, pRxPort->PortIndex);
  2069. pMsg->dev = pAC->dev[pRxPort->PortIndex];
  2070. pMsg->protocol = eth_type_trans(pMsg,
  2071. pAC->dev[pRxPort->PortIndex]);
  2072. netif_rx(pMsg);
  2073. pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
  2074. }
  2075. else {
  2076. /* drop frame */
  2077. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  2078. SK_DBGCAT_DRV_RX_PROGRESS,
  2079. ("D"));
  2080. DEV_KFREE_SKB(pMsg);
  2081. }
  2082. } /* if not for rlmt */
  2083. else {
  2084. /* packet for rlmt */
  2085. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  2086. SK_DBGCAT_DRV_RX_PROGRESS, ("R"));
  2087. pRlmtMbuf = SkDrvAllocRlmtMbuf(pAC,
  2088. pAC->IoBase, FrameLength);
  2089. if (pRlmtMbuf != NULL) {
  2090. pRlmtMbuf->pNext = NULL;
  2091. pRlmtMbuf->Length = FrameLength;
  2092. pRlmtMbuf->PortIdx = PortIndex;
  2093. EvPara.pParaPtr = pRlmtMbuf;
  2094. memcpy((char*)(pRlmtMbuf->pData),
  2095. (char*)(pMsg->data),
  2096. FrameLength);
  2097. /* SlowPathLock needed? */
  2098. if (SlowPathLock == SK_TRUE) {
  2099. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  2100. SkEventQueue(pAC, SKGE_RLMT,
  2101. SK_RLMT_PACKET_RECEIVED,
  2102. EvPara);
  2103. pAC->CheckQueue = SK_TRUE;
  2104. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  2105. } else {
  2106. SkEventQueue(pAC, SKGE_RLMT,
  2107. SK_RLMT_PACKET_RECEIVED,
  2108. EvPara);
  2109. pAC->CheckQueue = SK_TRUE;
  2110. }
  2111. SK_DBG_MSG(NULL, SK_DBGMOD_DRV,
  2112. SK_DBGCAT_DRV_RX_PROGRESS,
  2113. ("Q"));
  2114. }
  2115. if ((pAC->dev[pRxPort->PortIndex]->flags &
  2116. (IFF_PROMISC | IFF_ALLMULTI)) != 0 ||
  2117. (ForRlmt & SK_RLMT_RX_PROTOCOL) ==
  2118. SK_RLMT_RX_PROTOCOL) {
  2119. pMsg->dev = pAC->dev[pRxPort->PortIndex];
  2120. pMsg->protocol = eth_type_trans(pMsg,
  2121. pAC->dev[pRxPort->PortIndex]);
  2122. netif_rx(pMsg);
  2123. pAC->dev[pRxPort->PortIndex]->last_rx = jiffies;
  2124. }
  2125. else {
  2126. DEV_KFREE_SKB(pMsg);
  2127. }
  2128. } /* if packet for rlmt */
  2129. } /* for ... scanning the RXD ring */
  2130. /* RXD ring is empty -> fill and restart */
  2131. FillRxRing(pAC, pRxPort);
  2132. /* do not start if called from Close */
  2133. if (pAC->BoardLevel > SK_INIT_DATA) {
  2134. ClearAndStartRx(pAC, PortIndex);
  2135. }
  2136. return;
  2137. rx_failed:
  2138. /* remove error frame */
  2139. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
  2140. ("Schrottdescriptor, length: 0x%x\n", FrameLength));
  2141. /* release the DMA mapping */
  2142. PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
  2143. PhysAddr |= (SK_U64) pRxd->VDataLow;
  2144. pci_unmap_page(pAC->PciDev,
  2145. PhysAddr,
  2146. pAC->RxBufSize - 2,
  2147. PCI_DMA_FROMDEVICE);
  2148. DEV_KFREE_SKB_IRQ(pRxd->pMBuf);
  2149. pRxd->pMBuf = NULL;
  2150. pRxPort->RxdRingFree++;
  2151. pRxPort->pRxdRingHead = pRxd->pNextRxd;
  2152. goto rx_start;
  2153. } /* ReceiveIrq */
  2154. /*****************************************************************************
  2155. *
  2156. * ClearAndStartRx - give a start receive command to BMU, clear IRQ
  2157. *
  2158. * Description:
  2159. * This function sends a start command and a clear interrupt
  2160. * command for one receive queue to the BMU.
  2161. *
  2162. * Returns: N/A
  2163. * none
  2164. */
  2165. static void ClearAndStartRx(
  2166. SK_AC *pAC, /* pointer to the adapter context */
  2167. int PortIndex) /* index of the receive port (XMAC) */
  2168. {
  2169. SK_OUT8(pAC->IoBase,
  2170. RxQueueAddr[PortIndex]+Q_CSR,
  2171. CSR_START | CSR_IRQ_CL_F);
  2172. } /* ClearAndStartRx */
  2173. /*****************************************************************************
  2174. *
  2175. * ClearTxIrq - give a clear transmit IRQ command to BMU
  2176. *
  2177. * Description:
  2178. * This function sends a clear tx IRQ command for one
  2179. * transmit queue to the BMU.
  2180. *
  2181. * Returns: N/A
  2182. */
  2183. static void ClearTxIrq(
  2184. SK_AC *pAC, /* pointer to the adapter context */
  2185. int PortIndex, /* index of the transmit port (XMAC) */
  2186. int Prio) /* priority or normal queue */
  2187. {
  2188. SK_OUT8(pAC->IoBase,
  2189. TxQueueAddr[PortIndex][Prio]+Q_CSR,
  2190. CSR_IRQ_CL_F);
  2191. } /* ClearTxIrq */
  2192. /*****************************************************************************
  2193. *
  2194. * ClearRxRing - remove all buffers from the receive ring
  2195. *
  2196. * Description:
  2197. * This function removes all receive buffers from the ring.
  2198. * The receive BMU must be stopped before calling this function.
  2199. *
  2200. * Returns: N/A
  2201. */
  2202. static void ClearRxRing(
  2203. SK_AC *pAC, /* pointer to adapter context */
  2204. RX_PORT *pRxPort) /* pointer to rx port struct */
  2205. {
  2206. RXD *pRxd; /* pointer to the current descriptor */
  2207. unsigned long Flags;
  2208. SK_U64 PhysAddr;
  2209. if (pRxPort->RxdRingFree == pAC->RxDescrPerRing) {
  2210. return;
  2211. }
  2212. spin_lock_irqsave(&pRxPort->RxDesRingLock, Flags);
  2213. pRxd = pRxPort->pRxdRingHead;
  2214. do {
  2215. if (pRxd->pMBuf != NULL) {
  2216. PhysAddr = ((SK_U64) pRxd->VDataHigh) << (SK_U64)32;
  2217. PhysAddr |= (SK_U64) pRxd->VDataLow;
  2218. pci_unmap_page(pAC->PciDev,
  2219. PhysAddr,
  2220. pAC->RxBufSize - 2,
  2221. PCI_DMA_FROMDEVICE);
  2222. DEV_KFREE_SKB(pRxd->pMBuf);
  2223. pRxd->pMBuf = NULL;
  2224. }
  2225. pRxd->RBControl &= BMU_OWN;
  2226. pRxd = pRxd->pNextRxd;
  2227. pRxPort->RxdRingFree++;
  2228. } while (pRxd != pRxPort->pRxdRingTail);
  2229. pRxPort->pRxdRingTail = pRxPort->pRxdRingHead;
  2230. spin_unlock_irqrestore(&pRxPort->RxDesRingLock, Flags);
  2231. } /* ClearRxRing */
  2232. /*****************************************************************************
  2233. *
  2234. * ClearTxRing - remove all buffers from the transmit ring
  2235. *
  2236. * Description:
  2237. * This function removes all transmit buffers from the ring.
  2238. * The transmit BMU must be stopped before calling this function
  2239. * and transmitting at the upper level must be disabled.
  2240. * The BMU own bit of all descriptors is cleared, the rest is
  2241. * done by calling FreeTxDescriptors.
  2242. *
  2243. * Returns: N/A
  2244. */
  2245. static void ClearTxRing(
  2246. SK_AC *pAC, /* pointer to adapter context */
  2247. TX_PORT *pTxPort) /* pointer to tx prt struct */
  2248. {
  2249. TXD *pTxd; /* pointer to the current descriptor */
  2250. int i;
  2251. unsigned long Flags;
  2252. spin_lock_irqsave(&pTxPort->TxDesRingLock, Flags);
  2253. pTxd = pTxPort->pTxdRingHead;
  2254. for (i=0; i<pAC->TxDescrPerRing; i++) {
  2255. pTxd->TBControl &= ~BMU_OWN;
  2256. pTxd = pTxd->pNextTxd;
  2257. }
  2258. FreeTxDescriptors(pAC, pTxPort);
  2259. spin_unlock_irqrestore(&pTxPort->TxDesRingLock, Flags);
  2260. } /* ClearTxRing */
  2261. /*****************************************************************************
  2262. *
  2263. * SkGeSetMacAddr - Set the hardware MAC address
  2264. *
  2265. * Description:
  2266. * This function sets the MAC address used by the adapter.
  2267. *
  2268. * Returns:
  2269. * 0, if everything is ok
  2270. * !=0, on error
  2271. */
  2272. static int SkGeSetMacAddr(struct SK_NET_DEVICE *dev, void *p)
  2273. {
  2274. DEV_NET *pNet = netdev_priv(dev);
  2275. SK_AC *pAC = pNet->pAC;
  2276. struct sockaddr *addr = p;
  2277. unsigned long Flags;
  2278. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2279. ("SkGeSetMacAddr starts now...\n"));
  2280. if(netif_running(dev))
  2281. return -EBUSY;
  2282. memcpy(dev->dev_addr, addr->sa_data,dev->addr_len);
  2283. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  2284. if (pAC->RlmtNets == 2)
  2285. SkAddrOverride(pAC, pAC->IoBase, pNet->NetNr,
  2286. (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
  2287. else
  2288. SkAddrOverride(pAC, pAC->IoBase, pAC->ActivePort,
  2289. (SK_MAC_ADDR*)dev->dev_addr, SK_ADDR_VIRTUAL_ADDRESS);
  2290. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  2291. return 0;
  2292. } /* SkGeSetMacAddr */
  2293. /*****************************************************************************
  2294. *
  2295. * SkGeSetRxMode - set receive mode
  2296. *
  2297. * Description:
  2298. * This function sets the receive mode of an adapter. The adapter
  2299. * supports promiscuous mode, allmulticast mode and a number of
  2300. * multicast addresses. If more multicast addresses the available
  2301. * are selected, a hash function in the hardware is used.
  2302. *
  2303. * Returns:
  2304. * 0, if everything is ok
  2305. * !=0, on error
  2306. */
  2307. static void SkGeSetRxMode(struct SK_NET_DEVICE *dev)
  2308. {
  2309. DEV_NET *pNet;
  2310. SK_AC *pAC;
  2311. struct dev_mc_list *pMcList;
  2312. int i;
  2313. int PortIdx;
  2314. unsigned long Flags;
  2315. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2316. ("SkGeSetRxMode starts now... "));
  2317. pNet = netdev_priv(dev);
  2318. pAC = pNet->pAC;
  2319. if (pAC->RlmtNets == 1)
  2320. PortIdx = pAC->ActivePort;
  2321. else
  2322. PortIdx = pNet->NetNr;
  2323. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  2324. if (dev->flags & IFF_PROMISC) {
  2325. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2326. ("PROMISCUOUS mode\n"));
  2327. SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
  2328. SK_PROM_MODE_LLC);
  2329. } else if (dev->flags & IFF_ALLMULTI) {
  2330. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2331. ("ALLMULTI mode\n"));
  2332. SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
  2333. SK_PROM_MODE_ALL_MC);
  2334. } else {
  2335. SkAddrPromiscuousChange(pAC, pAC->IoBase, PortIdx,
  2336. SK_PROM_MODE_NONE);
  2337. SkAddrMcClear(pAC, pAC->IoBase, PortIdx, 0);
  2338. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2339. ("Number of MC entries: %d ", dev->mc_count));
  2340. pMcList = dev->mc_list;
  2341. for (i=0; i<dev->mc_count; i++, pMcList = pMcList->next) {
  2342. SkAddrMcAdd(pAC, pAC->IoBase, PortIdx,
  2343. (SK_MAC_ADDR*)pMcList->dmi_addr, 0);
  2344. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_MCA,
  2345. ("%02x:%02x:%02x:%02x:%02x:%02x\n",
  2346. pMcList->dmi_addr[0],
  2347. pMcList->dmi_addr[1],
  2348. pMcList->dmi_addr[2],
  2349. pMcList->dmi_addr[3],
  2350. pMcList->dmi_addr[4],
  2351. pMcList->dmi_addr[5]));
  2352. }
  2353. SkAddrMcUpdate(pAC, pAC->IoBase, PortIdx);
  2354. }
  2355. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  2356. return;
  2357. } /* SkGeSetRxMode */
  2358. /*****************************************************************************
  2359. *
  2360. * SkGeChangeMtu - set the MTU to another value
  2361. *
  2362. * Description:
  2363. * This function sets is called whenever the MTU size is changed
  2364. * (ifconfig mtu xxx dev ethX). If the MTU is bigger than standard
  2365. * ethernet MTU size, long frame support is activated.
  2366. *
  2367. * Returns:
  2368. * 0, if everything is ok
  2369. * !=0, on error
  2370. */
  2371. static int SkGeChangeMtu(struct SK_NET_DEVICE *dev, int NewMtu)
  2372. {
  2373. DEV_NET *pNet;
  2374. DEV_NET *pOtherNet;
  2375. SK_AC *pAC;
  2376. unsigned long Flags;
  2377. int i;
  2378. SK_EVPARA EvPara;
  2379. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2380. ("SkGeChangeMtu starts now...\n"));
  2381. pNet = netdev_priv(dev);
  2382. pAC = pNet->pAC;
  2383. if ((NewMtu < 68) || (NewMtu > SK_JUMBO_MTU)) {
  2384. return -EINVAL;
  2385. }
  2386. if(pAC->BoardLevel != SK_INIT_RUN) {
  2387. return -EINVAL;
  2388. }
  2389. #ifdef SK_DIAG_SUPPORT
  2390. if (pAC->DiagModeActive == DIAG_ACTIVE) {
  2391. if (pAC->DiagFlowCtrl == SK_FALSE) {
  2392. return -1; /* still in use, deny any actions of MTU */
  2393. } else {
  2394. pAC->DiagFlowCtrl = SK_FALSE;
  2395. }
  2396. }
  2397. #endif
  2398. pNet->Mtu = NewMtu;
  2399. pOtherNet = netdev_priv(pAC->dev[1 - pNet->NetNr]);
  2400. if ((pOtherNet->Mtu>1500) && (NewMtu<=1500) && (pOtherNet->Up==1)) {
  2401. return(0);
  2402. }
  2403. pAC->RxBufSize = NewMtu + 32;
  2404. dev->mtu = NewMtu;
  2405. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2406. ("New MTU: %d\n", NewMtu));
  2407. /*
  2408. ** Prevent any reconfiguration while changing the MTU
  2409. ** by disabling any interrupts
  2410. */
  2411. SK_OUT32(pAC->IoBase, B0_IMSK, 0);
  2412. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  2413. /*
  2414. ** Notify RLMT that any ports are to be stopped
  2415. */
  2416. EvPara.Para32[0] = 0;
  2417. EvPara.Para32[1] = -1;
  2418. if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
  2419. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
  2420. EvPara.Para32[0] = 1;
  2421. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
  2422. } else {
  2423. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_STOP, EvPara);
  2424. }
  2425. /*
  2426. ** After calling the SkEventDispatcher(), RLMT is aware about
  2427. ** the stopped ports -> configuration can take place!
  2428. */
  2429. SkEventDispatcher(pAC, pAC->IoBase);
  2430. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  2431. spin_lock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
  2432. netif_stop_queue(pAC->dev[i]);
  2433. }
  2434. /*
  2435. ** Depending on the desired MTU size change, a different number of
  2436. ** RX buffers need to be allocated
  2437. */
  2438. if (NewMtu > 1500) {
  2439. /*
  2440. ** Use less rx buffers
  2441. */
  2442. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  2443. if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
  2444. pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
  2445. (pAC->RxDescrPerRing / 4);
  2446. } else {
  2447. if (i == pAC->ActivePort) {
  2448. pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
  2449. (pAC->RxDescrPerRing / 4);
  2450. } else {
  2451. pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
  2452. (pAC->RxDescrPerRing / 10);
  2453. }
  2454. }
  2455. }
  2456. } else {
  2457. /*
  2458. ** Use the normal amount of rx buffers
  2459. */
  2460. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  2461. if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
  2462. pAC->RxPort[i].RxFillLimit = 1;
  2463. } else {
  2464. if (i == pAC->ActivePort) {
  2465. pAC->RxPort[i].RxFillLimit = 1;
  2466. } else {
  2467. pAC->RxPort[i].RxFillLimit = pAC->RxDescrPerRing -
  2468. (pAC->RxDescrPerRing / 4);
  2469. }
  2470. }
  2471. }
  2472. }
  2473. SkGeDeInit(pAC, pAC->IoBase);
  2474. /*
  2475. ** enable/disable hardware support for long frames
  2476. */
  2477. if (NewMtu > 1500) {
  2478. // pAC->JumboActivated = SK_TRUE; /* is never set back !!! */
  2479. pAC->GIni.GIPortUsage = SK_JUMBO_LINK;
  2480. } else {
  2481. if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
  2482. pAC->GIni.GIPortUsage = SK_MUL_LINK;
  2483. } else {
  2484. pAC->GIni.GIPortUsage = SK_RED_LINK;
  2485. }
  2486. }
  2487. SkGeInit( pAC, pAC->IoBase, SK_INIT_IO);
  2488. SkI2cInit( pAC, pAC->IoBase, SK_INIT_IO);
  2489. SkEventInit(pAC, pAC->IoBase, SK_INIT_IO);
  2490. SkPnmiInit( pAC, pAC->IoBase, SK_INIT_IO);
  2491. SkAddrInit( pAC, pAC->IoBase, SK_INIT_IO);
  2492. SkRlmtInit( pAC, pAC->IoBase, SK_INIT_IO);
  2493. SkTimerInit(pAC, pAC->IoBase, SK_INIT_IO);
  2494. /*
  2495. ** tschilling:
  2496. ** Speed and others are set back to default in level 1 init!
  2497. */
  2498. GetConfiguration(pAC);
  2499. SkGeInit( pAC, pAC->IoBase, SK_INIT_RUN);
  2500. SkI2cInit( pAC, pAC->IoBase, SK_INIT_RUN);
  2501. SkEventInit(pAC, pAC->IoBase, SK_INIT_RUN);
  2502. SkPnmiInit( pAC, pAC->IoBase, SK_INIT_RUN);
  2503. SkAddrInit( pAC, pAC->IoBase, SK_INIT_RUN);
  2504. SkRlmtInit( pAC, pAC->IoBase, SK_INIT_RUN);
  2505. SkTimerInit(pAC, pAC->IoBase, SK_INIT_RUN);
  2506. /*
  2507. ** clear and reinit the rx rings here
  2508. */
  2509. for (i=0; i<pAC->GIni.GIMacsFound; i++) {
  2510. ReceiveIrq(pAC, &pAC->RxPort[i], SK_TRUE);
  2511. ClearRxRing(pAC, &pAC->RxPort[i]);
  2512. FillRxRing(pAC, &pAC->RxPort[i]);
  2513. /*
  2514. ** Enable transmit descriptor polling
  2515. */
  2516. SkGePollTxD(pAC, pAC->IoBase, i, SK_TRUE);
  2517. FillRxRing(pAC, &pAC->RxPort[i]);
  2518. };
  2519. SkGeYellowLED(pAC, pAC->IoBase, 1);
  2520. SkDimEnableModerationIfNeeded(pAC);
  2521. SkDimDisplayModerationSettings(pAC);
  2522. netif_start_queue(pAC->dev[pNet->PortNr]);
  2523. for (i=pAC->GIni.GIMacsFound-1; i>=0; i--) {
  2524. spin_unlock(&pAC->TxPort[i][TX_PRIO_LOW].TxDesRingLock);
  2525. }
  2526. /*
  2527. ** Enable Interrupts again
  2528. */
  2529. SK_OUT32(pAC->IoBase, B0_IMSK, pAC->GIni.GIValIrqMask);
  2530. SK_OUT32(pAC->IoBase, B0_HWE_IMSK, IRQ_HWE_MASK);
  2531. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
  2532. SkEventDispatcher(pAC, pAC->IoBase);
  2533. /*
  2534. ** Notify RLMT about the changing and restarting one (or more) ports
  2535. */
  2536. if ((pAC->GIni.GIMacsFound == 2 ) && (pAC->RlmtNets == 2)) {
  2537. EvPara.Para32[0] = pAC->RlmtNets;
  2538. EvPara.Para32[1] = -1;
  2539. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_SET_NETS, EvPara);
  2540. EvPara.Para32[0] = pNet->PortNr;
  2541. EvPara.Para32[1] = -1;
  2542. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
  2543. if (pOtherNet->Up) {
  2544. EvPara.Para32[0] = pOtherNet->PortNr;
  2545. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
  2546. }
  2547. } else {
  2548. SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_START, EvPara);
  2549. }
  2550. SkEventDispatcher(pAC, pAC->IoBase);
  2551. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  2552. /*
  2553. ** While testing this driver with latest kernel 2.5 (2.5.70), it
  2554. ** seems as if upper layers have a problem to handle a successful
  2555. ** return value of '0'. If such a zero is returned, the complete
  2556. ** system hangs for several minutes (!), which is in acceptable.
  2557. **
  2558. ** Currently it is not clear, what the exact reason for this problem
  2559. ** is. The implemented workaround for 2.5 is to return the desired
  2560. ** new MTU size if all needed changes for the new MTU size where
  2561. ** performed. In kernels 2.2 and 2.4, a zero value is returned,
  2562. ** which indicates the successful change of the mtu-size.
  2563. */
  2564. return NewMtu;
  2565. } /* SkGeChangeMtu */
  2566. /*****************************************************************************
  2567. *
  2568. * SkGeStats - return ethernet device statistics
  2569. *
  2570. * Description:
  2571. * This function return statistic data about the ethernet device
  2572. * to the operating system.
  2573. *
  2574. * Returns:
  2575. * pointer to the statistic structure.
  2576. */
  2577. static struct net_device_stats *SkGeStats(struct SK_NET_DEVICE *dev)
  2578. {
  2579. DEV_NET *pNet = netdev_priv(dev);
  2580. SK_AC *pAC = pNet->pAC;
  2581. SK_PNMI_STRUCT_DATA *pPnmiStruct; /* structure for all Pnmi-Data */
  2582. SK_PNMI_STAT *pPnmiStat; /* pointer to virtual XMAC stat. data */
  2583. SK_PNMI_CONF *pPnmiConf; /* pointer to virtual link config. */
  2584. unsigned int Size; /* size of pnmi struct */
  2585. unsigned long Flags; /* for spin lock */
  2586. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2587. ("SkGeStats starts now...\n"));
  2588. pPnmiStruct = &pAC->PnmiStruct;
  2589. #ifdef SK_DIAG_SUPPORT
  2590. if ((pAC->DiagModeActive == DIAG_NOTACTIVE) &&
  2591. (pAC->BoardLevel == SK_INIT_RUN)) {
  2592. #endif
  2593. SK_MEMSET(pPnmiStruct, 0, sizeof(SK_PNMI_STRUCT_DATA));
  2594. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  2595. Size = SK_PNMI_STRUCT_SIZE;
  2596. SkPnmiGetStruct(pAC, pAC->IoBase, pPnmiStruct, &Size, pNet->NetNr);
  2597. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  2598. #ifdef SK_DIAG_SUPPORT
  2599. }
  2600. #endif
  2601. pPnmiStat = &pPnmiStruct->Stat[0];
  2602. pPnmiConf = &pPnmiStruct->Conf[0];
  2603. pAC->stats.rx_packets = (SK_U32) pPnmiStruct->RxDeliveredCts & 0xFFFFFFFF;
  2604. pAC->stats.tx_packets = (SK_U32) pPnmiStat->StatTxOkCts & 0xFFFFFFFF;
  2605. pAC->stats.rx_bytes = (SK_U32) pPnmiStruct->RxOctetsDeliveredCts;
  2606. pAC->stats.tx_bytes = (SK_U32) pPnmiStat->StatTxOctetsOkCts;
  2607. if (pNet->Mtu <= 1500) {
  2608. pAC->stats.rx_errors = (SK_U32) pPnmiStruct->InErrorsCts & 0xFFFFFFFF;
  2609. } else {
  2610. pAC->stats.rx_errors = (SK_U32) ((pPnmiStruct->InErrorsCts -
  2611. pPnmiStat->StatRxTooLongCts) & 0xFFFFFFFF);
  2612. }
  2613. if (pAC->GIni.GP[0].PhyType == SK_PHY_XMAC && pAC->HWRevision < 12)
  2614. pAC->stats.rx_errors = pAC->stats.rx_errors - pPnmiStat->StatRxShortsCts;
  2615. pAC->stats.tx_errors = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
  2616. pAC->stats.rx_dropped = (SK_U32) pPnmiStruct->RxNoBufCts & 0xFFFFFFFF;
  2617. pAC->stats.tx_dropped = (SK_U32) pPnmiStruct->TxNoBufCts & 0xFFFFFFFF;
  2618. pAC->stats.multicast = (SK_U32) pPnmiStat->StatRxMulticastOkCts & 0xFFFFFFFF;
  2619. pAC->stats.collisions = (SK_U32) pPnmiStat->StatTxSingleCollisionCts & 0xFFFFFFFF;
  2620. /* detailed rx_errors: */
  2621. pAC->stats.rx_length_errors = (SK_U32) pPnmiStat->StatRxRuntCts & 0xFFFFFFFF;
  2622. pAC->stats.rx_over_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
  2623. pAC->stats.rx_crc_errors = (SK_U32) pPnmiStat->StatRxFcsCts & 0xFFFFFFFF;
  2624. pAC->stats.rx_frame_errors = (SK_U32) pPnmiStat->StatRxFramingCts & 0xFFFFFFFF;
  2625. pAC->stats.rx_fifo_errors = (SK_U32) pPnmiStat->StatRxFifoOverflowCts & 0xFFFFFFFF;
  2626. pAC->stats.rx_missed_errors = (SK_U32) pPnmiStat->StatRxMissedCts & 0xFFFFFFFF;
  2627. /* detailed tx_errors */
  2628. pAC->stats.tx_aborted_errors = (SK_U32) 0;
  2629. pAC->stats.tx_carrier_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
  2630. pAC->stats.tx_fifo_errors = (SK_U32) pPnmiStat->StatTxFifoUnderrunCts & 0xFFFFFFFF;
  2631. pAC->stats.tx_heartbeat_errors = (SK_U32) pPnmiStat->StatTxCarrierCts & 0xFFFFFFFF;
  2632. pAC->stats.tx_window_errors = (SK_U32) 0;
  2633. return(&pAC->stats);
  2634. } /* SkGeStats */
  2635. /*****************************************************************************
  2636. *
  2637. * SkGeIoctl - IO-control function
  2638. *
  2639. * Description:
  2640. * This function is called if an ioctl is issued on the device.
  2641. * There are three subfunction for reading, writing and test-writing
  2642. * the private MIB data structure (usefull for SysKonnect-internal tools).
  2643. *
  2644. * Returns:
  2645. * 0, if everything is ok
  2646. * !=0, on error
  2647. */
  2648. static int SkGeIoctl(struct SK_NET_DEVICE *dev, struct ifreq *rq, int cmd)
  2649. {
  2650. DEV_NET *pNet;
  2651. SK_AC *pAC;
  2652. void *pMemBuf;
  2653. struct pci_dev *pdev = NULL;
  2654. SK_GE_IOCTL Ioctl;
  2655. unsigned int Err = 0;
  2656. int Size = 0;
  2657. int Ret = 0;
  2658. unsigned int Length = 0;
  2659. int HeaderLength = sizeof(SK_U32) + sizeof(SK_U32);
  2660. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2661. ("SkGeIoctl starts now...\n"));
  2662. pNet = netdev_priv(dev);
  2663. pAC = pNet->pAC;
  2664. if(copy_from_user(&Ioctl, rq->ifr_data, sizeof(SK_GE_IOCTL))) {
  2665. return -EFAULT;
  2666. }
  2667. switch(cmd) {
  2668. case SK_IOCTL_SETMIB:
  2669. case SK_IOCTL_PRESETMIB:
  2670. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2671. case SK_IOCTL_GETMIB:
  2672. if(copy_from_user(&pAC->PnmiStruct, Ioctl.pData,
  2673. Ioctl.Len<sizeof(pAC->PnmiStruct)?
  2674. Ioctl.Len : sizeof(pAC->PnmiStruct))) {
  2675. return -EFAULT;
  2676. }
  2677. Size = SkGeIocMib(pNet, Ioctl.Len, cmd);
  2678. if(copy_to_user(Ioctl.pData, &pAC->PnmiStruct,
  2679. Ioctl.Len<Size? Ioctl.Len : Size)) {
  2680. return -EFAULT;
  2681. }
  2682. Ioctl.Len = Size;
  2683. if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
  2684. return -EFAULT;
  2685. }
  2686. break;
  2687. case SK_IOCTL_GEN:
  2688. if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
  2689. Length = Ioctl.Len;
  2690. } else {
  2691. Length = sizeof(pAC->PnmiStruct) + HeaderLength;
  2692. }
  2693. if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
  2694. return -ENOMEM;
  2695. }
  2696. if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
  2697. Err = -EFAULT;
  2698. goto fault_gen;
  2699. }
  2700. if ((Ret = SkPnmiGenIoctl(pAC, pAC->IoBase, pMemBuf, &Length, 0)) < 0) {
  2701. Err = -EFAULT;
  2702. goto fault_gen;
  2703. }
  2704. if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
  2705. Err = -EFAULT;
  2706. goto fault_gen;
  2707. }
  2708. Ioctl.Len = Length;
  2709. if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
  2710. Err = -EFAULT;
  2711. goto fault_gen;
  2712. }
  2713. fault_gen:
  2714. kfree(pMemBuf); /* cleanup everything */
  2715. break;
  2716. #ifdef SK_DIAG_SUPPORT
  2717. case SK_IOCTL_DIAG:
  2718. if (!capable(CAP_NET_ADMIN)) return -EPERM;
  2719. if (Ioctl.Len < (sizeof(pAC->PnmiStruct) + HeaderLength)) {
  2720. Length = Ioctl.Len;
  2721. } else {
  2722. Length = sizeof(pAC->PnmiStruct) + HeaderLength;
  2723. }
  2724. if (NULL == (pMemBuf = kmalloc(Length, GFP_KERNEL))) {
  2725. return -ENOMEM;
  2726. }
  2727. if(copy_from_user(pMemBuf, Ioctl.pData, Length)) {
  2728. Err = -EFAULT;
  2729. goto fault_diag;
  2730. }
  2731. pdev = pAC->PciDev;
  2732. Length = 3 * sizeof(SK_U32); /* Error, Bus and Device */
  2733. /*
  2734. ** While coding this new IOCTL interface, only a few lines of code
  2735. ** are to to be added. Therefore no dedicated function has been
  2736. ** added. If more functionality is added, a separate function
  2737. ** should be used...
  2738. */
  2739. * ((SK_U32 *)pMemBuf) = 0;
  2740. * ((SK_U32 *)pMemBuf + 1) = pdev->bus->number;
  2741. * ((SK_U32 *)pMemBuf + 2) = ParseDeviceNbrFromSlotName(pci_name(pdev));
  2742. if(copy_to_user(Ioctl.pData, pMemBuf, Length) ) {
  2743. Err = -EFAULT;
  2744. goto fault_diag;
  2745. }
  2746. Ioctl.Len = Length;
  2747. if(copy_to_user(rq->ifr_data, &Ioctl, sizeof(SK_GE_IOCTL))) {
  2748. Err = -EFAULT;
  2749. goto fault_diag;
  2750. }
  2751. fault_diag:
  2752. kfree(pMemBuf); /* cleanup everything */
  2753. break;
  2754. #endif
  2755. default:
  2756. Err = -EOPNOTSUPP;
  2757. }
  2758. return(Err);
  2759. } /* SkGeIoctl */
  2760. /*****************************************************************************
  2761. *
  2762. * SkGeIocMib - handle a GetMib, SetMib- or PresetMib-ioctl message
  2763. *
  2764. * Description:
  2765. * This function reads/writes the MIB data using PNMI (Private Network
  2766. * Management Interface).
  2767. * The destination for the data must be provided with the
  2768. * ioctl call and is given to the driver in the form of
  2769. * a user space address.
  2770. * Copying from the user-provided data area into kernel messages
  2771. * and back is done by copy_from_user and copy_to_user calls in
  2772. * SkGeIoctl.
  2773. *
  2774. * Returns:
  2775. * returned size from PNMI call
  2776. */
  2777. static int SkGeIocMib(
  2778. DEV_NET *pNet, /* pointer to the adapter context */
  2779. unsigned int Size, /* length of ioctl data */
  2780. int mode) /* flag for set/preset */
  2781. {
  2782. unsigned long Flags; /* for spin lock */
  2783. SK_AC *pAC;
  2784. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2785. ("SkGeIocMib starts now...\n"));
  2786. pAC = pNet->pAC;
  2787. /* access MIB */
  2788. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  2789. switch(mode) {
  2790. case SK_IOCTL_GETMIB:
  2791. SkPnmiGetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
  2792. pNet->NetNr);
  2793. break;
  2794. case SK_IOCTL_PRESETMIB:
  2795. SkPnmiPreSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
  2796. pNet->NetNr);
  2797. break;
  2798. case SK_IOCTL_SETMIB:
  2799. SkPnmiSetStruct(pAC, pAC->IoBase, &pAC->PnmiStruct, &Size,
  2800. pNet->NetNr);
  2801. break;
  2802. default:
  2803. break;
  2804. }
  2805. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  2806. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ENTRY,
  2807. ("MIB data access succeeded\n"));
  2808. return (Size);
  2809. } /* SkGeIocMib */
  2810. /*****************************************************************************
  2811. *
  2812. * GetConfiguration - read configuration information
  2813. *
  2814. * Description:
  2815. * This function reads per-adapter configuration information from
  2816. * the options provided on the command line.
  2817. *
  2818. * Returns:
  2819. * none
  2820. */
  2821. static void GetConfiguration(
  2822. SK_AC *pAC) /* pointer to the adapter context structure */
  2823. {
  2824. SK_I32 Port; /* preferred port */
  2825. SK_BOOL AutoSet;
  2826. SK_BOOL DupSet;
  2827. int LinkSpeed = SK_LSPEED_AUTO; /* Link speed */
  2828. int AutoNeg = 1; /* autoneg off (0) or on (1) */
  2829. int DuplexCap = 0; /* 0=both,1=full,2=half */
  2830. int FlowCtrl = SK_FLOW_MODE_SYM_OR_REM; /* FlowControl */
  2831. int MSMode = SK_MS_MODE_AUTO; /* master/slave mode */
  2832. SK_BOOL IsConTypeDefined = SK_TRUE;
  2833. SK_BOOL IsLinkSpeedDefined = SK_TRUE;
  2834. SK_BOOL IsFlowCtrlDefined = SK_TRUE;
  2835. SK_BOOL IsRoleDefined = SK_TRUE;
  2836. SK_BOOL IsModeDefined = SK_TRUE;
  2837. /*
  2838. * The two parameters AutoNeg. and DuplexCap. map to one configuration
  2839. * parameter. The mapping is described by this table:
  2840. * DuplexCap -> | both | full | half |
  2841. * AutoNeg | | | |
  2842. * -----------------------------------------------------------------
  2843. * Off | illegal | Full | Half |
  2844. * -----------------------------------------------------------------
  2845. * On | AutoBoth | AutoFull | AutoHalf |
  2846. * -----------------------------------------------------------------
  2847. * Sense | AutoSense | AutoSense | AutoSense |
  2848. */
  2849. int Capabilities[3][3] =
  2850. { { -1, SK_LMODE_FULL , SK_LMODE_HALF },
  2851. {SK_LMODE_AUTOBOTH , SK_LMODE_AUTOFULL , SK_LMODE_AUTOHALF },
  2852. {SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE, SK_LMODE_AUTOSENSE} };
  2853. #define DC_BOTH 0
  2854. #define DC_FULL 1
  2855. #define DC_HALF 2
  2856. #define AN_OFF 0
  2857. #define AN_ON 1
  2858. #define AN_SENS 2
  2859. #define M_CurrPort pAC->GIni.GP[Port]
  2860. /*
  2861. ** Set the default values first for both ports!
  2862. */
  2863. for (Port = 0; Port < SK_MAX_MACS; Port++) {
  2864. M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
  2865. M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
  2866. M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
  2867. M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
  2868. }
  2869. /*
  2870. ** Check merged parameter ConType. If it has not been used,
  2871. ** verify any other parameter (e.g. AutoNeg) and use default values.
  2872. **
  2873. ** Stating both ConType and other lowlevel link parameters is also
  2874. ** possible. If this is the case, the passed ConType-parameter is
  2875. ** overwritten by the lowlevel link parameter.
  2876. **
  2877. ** The following settings are used for a merged ConType-parameter:
  2878. **
  2879. ** ConType DupCap AutoNeg FlowCtrl Role Speed
  2880. ** ------- ------ ------- -------- ---------- -----
  2881. ** Auto Both On SymOrRem Auto Auto
  2882. ** 100FD Full Off None <ignored> 100
  2883. ** 100HD Half Off None <ignored> 100
  2884. ** 10FD Full Off None <ignored> 10
  2885. ** 10HD Half Off None <ignored> 10
  2886. **
  2887. ** This ConType parameter is used for all ports of the adapter!
  2888. */
  2889. if ( (ConType != NULL) &&
  2890. (pAC->Index < SK_MAX_CARD_PARAM) &&
  2891. (ConType[pAC->Index] != NULL) ) {
  2892. /* Check chipset family */
  2893. if ((!pAC->ChipsetType) &&
  2894. (strcmp(ConType[pAC->Index],"Auto")!=0) &&
  2895. (strcmp(ConType[pAC->Index],"")!=0)) {
  2896. /* Set the speed parameter back */
  2897. printk("sk98lin: Illegal value \"%s\" "
  2898. "for ConType."
  2899. " Using Auto.\n",
  2900. ConType[pAC->Index]);
  2901. sprintf(ConType[pAC->Index], "Auto");
  2902. }
  2903. if (strcmp(ConType[pAC->Index],"")==0) {
  2904. IsConTypeDefined = SK_FALSE; /* No ConType defined */
  2905. } else if (strcmp(ConType[pAC->Index],"Auto")==0) {
  2906. for (Port = 0; Port < SK_MAX_MACS; Port++) {
  2907. M_CurrPort.PLinkModeConf = Capabilities[AN_ON][DC_BOTH];
  2908. M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
  2909. M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
  2910. M_CurrPort.PLinkSpeed = SK_LSPEED_AUTO;
  2911. }
  2912. } else if (strcmp(ConType[pAC->Index],"100FD")==0) {
  2913. for (Port = 0; Port < SK_MAX_MACS; Port++) {
  2914. M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
  2915. M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
  2916. M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
  2917. M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
  2918. }
  2919. } else if (strcmp(ConType[pAC->Index],"100HD")==0) {
  2920. for (Port = 0; Port < SK_MAX_MACS; Port++) {
  2921. M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
  2922. M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
  2923. M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
  2924. M_CurrPort.PLinkSpeed = SK_LSPEED_100MBPS;
  2925. }
  2926. } else if (strcmp(ConType[pAC->Index],"10FD")==0) {
  2927. for (Port = 0; Port < SK_MAX_MACS; Port++) {
  2928. M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_FULL];
  2929. M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
  2930. M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
  2931. M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
  2932. }
  2933. } else if (strcmp(ConType[pAC->Index],"10HD")==0) {
  2934. for (Port = 0; Port < SK_MAX_MACS; Port++) {
  2935. M_CurrPort.PLinkModeConf = Capabilities[AN_OFF][DC_HALF];
  2936. M_CurrPort.PFlowCtrlMode = SK_FLOW_MODE_NONE;
  2937. M_CurrPort.PMSMode = SK_MS_MODE_AUTO;
  2938. M_CurrPort.PLinkSpeed = SK_LSPEED_10MBPS;
  2939. }
  2940. } else {
  2941. printk("sk98lin: Illegal value \"%s\" for ConType\n",
  2942. ConType[pAC->Index]);
  2943. IsConTypeDefined = SK_FALSE; /* Wrong ConType defined */
  2944. }
  2945. } else {
  2946. IsConTypeDefined = SK_FALSE; /* No ConType defined */
  2947. }
  2948. /*
  2949. ** Parse any parameter settings for port A:
  2950. ** a) any LinkSpeed stated?
  2951. */
  2952. if (Speed_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  2953. Speed_A[pAC->Index] != NULL) {
  2954. if (strcmp(Speed_A[pAC->Index],"")==0) {
  2955. IsLinkSpeedDefined = SK_FALSE;
  2956. } else if (strcmp(Speed_A[pAC->Index],"Auto")==0) {
  2957. LinkSpeed = SK_LSPEED_AUTO;
  2958. } else if (strcmp(Speed_A[pAC->Index],"10")==0) {
  2959. LinkSpeed = SK_LSPEED_10MBPS;
  2960. } else if (strcmp(Speed_A[pAC->Index],"100")==0) {
  2961. LinkSpeed = SK_LSPEED_100MBPS;
  2962. } else if (strcmp(Speed_A[pAC->Index],"1000")==0) {
  2963. LinkSpeed = SK_LSPEED_1000MBPS;
  2964. } else {
  2965. printk("sk98lin: Illegal value \"%s\" for Speed_A\n",
  2966. Speed_A[pAC->Index]);
  2967. IsLinkSpeedDefined = SK_FALSE;
  2968. }
  2969. } else {
  2970. IsLinkSpeedDefined = SK_FALSE;
  2971. }
  2972. /*
  2973. ** Check speed parameter:
  2974. ** Only copper type adapter and GE V2 cards
  2975. */
  2976. if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
  2977. ((LinkSpeed != SK_LSPEED_AUTO) &&
  2978. (LinkSpeed != SK_LSPEED_1000MBPS))) {
  2979. printk("sk98lin: Illegal value for Speed_A. "
  2980. "Not a copper card or GE V2 card\n Using "
  2981. "speed 1000\n");
  2982. LinkSpeed = SK_LSPEED_1000MBPS;
  2983. }
  2984. /*
  2985. ** Decide whether to set new config value if somethig valid has
  2986. ** been received.
  2987. */
  2988. if (IsLinkSpeedDefined) {
  2989. pAC->GIni.GP[0].PLinkSpeed = LinkSpeed;
  2990. }
  2991. /*
  2992. ** b) Any Autonegotiation and DuplexCapabilities set?
  2993. ** Please note that both belong together...
  2994. */
  2995. AutoNeg = AN_ON; /* tschilling: Default: Autonegotiation on! */
  2996. AutoSet = SK_FALSE;
  2997. if (AutoNeg_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  2998. AutoNeg_A[pAC->Index] != NULL) {
  2999. AutoSet = SK_TRUE;
  3000. if (strcmp(AutoNeg_A[pAC->Index],"")==0) {
  3001. AutoSet = SK_FALSE;
  3002. } else if (strcmp(AutoNeg_A[pAC->Index],"On")==0) {
  3003. AutoNeg = AN_ON;
  3004. } else if (strcmp(AutoNeg_A[pAC->Index],"Off")==0) {
  3005. AutoNeg = AN_OFF;
  3006. } else if (strcmp(AutoNeg_A[pAC->Index],"Sense")==0) {
  3007. AutoNeg = AN_SENS;
  3008. } else {
  3009. printk("sk98lin: Illegal value \"%s\" for AutoNeg_A\n",
  3010. AutoNeg_A[pAC->Index]);
  3011. }
  3012. }
  3013. DuplexCap = DC_BOTH;
  3014. DupSet = SK_FALSE;
  3015. if (DupCap_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3016. DupCap_A[pAC->Index] != NULL) {
  3017. DupSet = SK_TRUE;
  3018. if (strcmp(DupCap_A[pAC->Index],"")==0) {
  3019. DupSet = SK_FALSE;
  3020. } else if (strcmp(DupCap_A[pAC->Index],"Both")==0) {
  3021. DuplexCap = DC_BOTH;
  3022. } else if (strcmp(DupCap_A[pAC->Index],"Full")==0) {
  3023. DuplexCap = DC_FULL;
  3024. } else if (strcmp(DupCap_A[pAC->Index],"Half")==0) {
  3025. DuplexCap = DC_HALF;
  3026. } else {
  3027. printk("sk98lin: Illegal value \"%s\" for DupCap_A\n",
  3028. DupCap_A[pAC->Index]);
  3029. }
  3030. }
  3031. /*
  3032. ** Check for illegal combinations
  3033. */
  3034. if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
  3035. ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
  3036. (DuplexCap == SK_LMODE_STAT_HALF)) &&
  3037. (pAC->ChipsetType)) {
  3038. printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
  3039. " Using Full Duplex.\n");
  3040. DuplexCap = DC_FULL;
  3041. }
  3042. if ( AutoSet && AutoNeg==AN_SENS && DupSet) {
  3043. printk("sk98lin, Port A: DuplexCapabilities"
  3044. " ignored using Sense mode\n");
  3045. }
  3046. if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
  3047. printk("sk98lin: Port A: Illegal combination"
  3048. " of values AutoNeg. and DuplexCap.\n Using "
  3049. "Full Duplex\n");
  3050. DuplexCap = DC_FULL;
  3051. }
  3052. if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
  3053. DuplexCap = DC_FULL;
  3054. }
  3055. if (!AutoSet && DupSet) {
  3056. printk("sk98lin: Port A: Duplex setting not"
  3057. " possible in\n default AutoNegotiation mode"
  3058. " (Sense).\n Using AutoNegotiation On\n");
  3059. AutoNeg = AN_ON;
  3060. }
  3061. /*
  3062. ** set the desired mode
  3063. */
  3064. if (AutoSet || DupSet) {
  3065. pAC->GIni.GP[0].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
  3066. }
  3067. /*
  3068. ** c) Any Flowcontrol-parameter set?
  3069. */
  3070. if (FlowCtrl_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3071. FlowCtrl_A[pAC->Index] != NULL) {
  3072. if (strcmp(FlowCtrl_A[pAC->Index],"") == 0) {
  3073. IsFlowCtrlDefined = SK_FALSE;
  3074. } else if (strcmp(FlowCtrl_A[pAC->Index],"SymOrRem") == 0) {
  3075. FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
  3076. } else if (strcmp(FlowCtrl_A[pAC->Index],"Sym")==0) {
  3077. FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
  3078. } else if (strcmp(FlowCtrl_A[pAC->Index],"LocSend")==0) {
  3079. FlowCtrl = SK_FLOW_MODE_LOC_SEND;
  3080. } else if (strcmp(FlowCtrl_A[pAC->Index],"None")==0) {
  3081. FlowCtrl = SK_FLOW_MODE_NONE;
  3082. } else {
  3083. printk("sk98lin: Illegal value \"%s\" for FlowCtrl_A\n",
  3084. FlowCtrl_A[pAC->Index]);
  3085. IsFlowCtrlDefined = SK_FALSE;
  3086. }
  3087. } else {
  3088. IsFlowCtrlDefined = SK_FALSE;
  3089. }
  3090. if (IsFlowCtrlDefined) {
  3091. if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
  3092. printk("sk98lin: Port A: FlowControl"
  3093. " impossible without AutoNegotiation,"
  3094. " disabled\n");
  3095. FlowCtrl = SK_FLOW_MODE_NONE;
  3096. }
  3097. pAC->GIni.GP[0].PFlowCtrlMode = FlowCtrl;
  3098. }
  3099. /*
  3100. ** d) What is with the RoleParameter?
  3101. */
  3102. if (Role_A != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3103. Role_A[pAC->Index] != NULL) {
  3104. if (strcmp(Role_A[pAC->Index],"")==0) {
  3105. IsRoleDefined = SK_FALSE;
  3106. } else if (strcmp(Role_A[pAC->Index],"Auto")==0) {
  3107. MSMode = SK_MS_MODE_AUTO;
  3108. } else if (strcmp(Role_A[pAC->Index],"Master")==0) {
  3109. MSMode = SK_MS_MODE_MASTER;
  3110. } else if (strcmp(Role_A[pAC->Index],"Slave")==0) {
  3111. MSMode = SK_MS_MODE_SLAVE;
  3112. } else {
  3113. printk("sk98lin: Illegal value \"%s\" for Role_A\n",
  3114. Role_A[pAC->Index]);
  3115. IsRoleDefined = SK_FALSE;
  3116. }
  3117. } else {
  3118. IsRoleDefined = SK_FALSE;
  3119. }
  3120. if (IsRoleDefined == SK_TRUE) {
  3121. pAC->GIni.GP[0].PMSMode = MSMode;
  3122. }
  3123. /*
  3124. ** Parse any parameter settings for port B:
  3125. ** a) any LinkSpeed stated?
  3126. */
  3127. IsConTypeDefined = SK_TRUE;
  3128. IsLinkSpeedDefined = SK_TRUE;
  3129. IsFlowCtrlDefined = SK_TRUE;
  3130. IsModeDefined = SK_TRUE;
  3131. if (Speed_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3132. Speed_B[pAC->Index] != NULL) {
  3133. if (strcmp(Speed_B[pAC->Index],"")==0) {
  3134. IsLinkSpeedDefined = SK_FALSE;
  3135. } else if (strcmp(Speed_B[pAC->Index],"Auto")==0) {
  3136. LinkSpeed = SK_LSPEED_AUTO;
  3137. } else if (strcmp(Speed_B[pAC->Index],"10")==0) {
  3138. LinkSpeed = SK_LSPEED_10MBPS;
  3139. } else if (strcmp(Speed_B[pAC->Index],"100")==0) {
  3140. LinkSpeed = SK_LSPEED_100MBPS;
  3141. } else if (strcmp(Speed_B[pAC->Index],"1000")==0) {
  3142. LinkSpeed = SK_LSPEED_1000MBPS;
  3143. } else {
  3144. printk("sk98lin: Illegal value \"%s\" for Speed_B\n",
  3145. Speed_B[pAC->Index]);
  3146. IsLinkSpeedDefined = SK_FALSE;
  3147. }
  3148. } else {
  3149. IsLinkSpeedDefined = SK_FALSE;
  3150. }
  3151. /*
  3152. ** Check speed parameter:
  3153. ** Only copper type adapter and GE V2 cards
  3154. */
  3155. if (((!pAC->ChipsetType) || (pAC->GIni.GICopperType != SK_TRUE)) &&
  3156. ((LinkSpeed != SK_LSPEED_AUTO) &&
  3157. (LinkSpeed != SK_LSPEED_1000MBPS))) {
  3158. printk("sk98lin: Illegal value for Speed_B. "
  3159. "Not a copper card or GE V2 card\n Using "
  3160. "speed 1000\n");
  3161. LinkSpeed = SK_LSPEED_1000MBPS;
  3162. }
  3163. /*
  3164. ** Decide whether to set new config value if somethig valid has
  3165. ** been received.
  3166. */
  3167. if (IsLinkSpeedDefined) {
  3168. pAC->GIni.GP[1].PLinkSpeed = LinkSpeed;
  3169. }
  3170. /*
  3171. ** b) Any Autonegotiation and DuplexCapabilities set?
  3172. ** Please note that both belong together...
  3173. */
  3174. AutoNeg = AN_SENS; /* default: do auto Sense */
  3175. AutoSet = SK_FALSE;
  3176. if (AutoNeg_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3177. AutoNeg_B[pAC->Index] != NULL) {
  3178. AutoSet = SK_TRUE;
  3179. if (strcmp(AutoNeg_B[pAC->Index],"")==0) {
  3180. AutoSet = SK_FALSE;
  3181. } else if (strcmp(AutoNeg_B[pAC->Index],"On")==0) {
  3182. AutoNeg = AN_ON;
  3183. } else if (strcmp(AutoNeg_B[pAC->Index],"Off")==0) {
  3184. AutoNeg = AN_OFF;
  3185. } else if (strcmp(AutoNeg_B[pAC->Index],"Sense")==0) {
  3186. AutoNeg = AN_SENS;
  3187. } else {
  3188. printk("sk98lin: Illegal value \"%s\" for AutoNeg_B\n",
  3189. AutoNeg_B[pAC->Index]);
  3190. }
  3191. }
  3192. DuplexCap = DC_BOTH;
  3193. DupSet = SK_FALSE;
  3194. if (DupCap_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3195. DupCap_B[pAC->Index] != NULL) {
  3196. DupSet = SK_TRUE;
  3197. if (strcmp(DupCap_B[pAC->Index],"")==0) {
  3198. DupSet = SK_FALSE;
  3199. } else if (strcmp(DupCap_B[pAC->Index],"Both")==0) {
  3200. DuplexCap = DC_BOTH;
  3201. } else if (strcmp(DupCap_B[pAC->Index],"Full")==0) {
  3202. DuplexCap = DC_FULL;
  3203. } else if (strcmp(DupCap_B[pAC->Index],"Half")==0) {
  3204. DuplexCap = DC_HALF;
  3205. } else {
  3206. printk("sk98lin: Illegal value \"%s\" for DupCap_B\n",
  3207. DupCap_B[pAC->Index]);
  3208. }
  3209. }
  3210. /*
  3211. ** Check for illegal combinations
  3212. */
  3213. if ((LinkSpeed == SK_LSPEED_1000MBPS) &&
  3214. ((DuplexCap == SK_LMODE_STAT_AUTOHALF) ||
  3215. (DuplexCap == SK_LMODE_STAT_HALF)) &&
  3216. (pAC->ChipsetType)) {
  3217. printk("sk98lin: Half Duplex not possible with Gigabit speed!\n"
  3218. " Using Full Duplex.\n");
  3219. DuplexCap = DC_FULL;
  3220. }
  3221. if (AutoSet && AutoNeg==AN_SENS && DupSet) {
  3222. printk("sk98lin, Port B: DuplexCapabilities"
  3223. " ignored using Sense mode\n");
  3224. }
  3225. if (AutoSet && AutoNeg==AN_OFF && DupSet && DuplexCap==DC_BOTH){
  3226. printk("sk98lin: Port B: Illegal combination"
  3227. " of values AutoNeg. and DuplexCap.\n Using "
  3228. "Full Duplex\n");
  3229. DuplexCap = DC_FULL;
  3230. }
  3231. if (AutoSet && AutoNeg==AN_OFF && !DupSet) {
  3232. DuplexCap = DC_FULL;
  3233. }
  3234. if (!AutoSet && DupSet) {
  3235. printk("sk98lin: Port B: Duplex setting not"
  3236. " possible in\n default AutoNegotiation mode"
  3237. " (Sense).\n Using AutoNegotiation On\n");
  3238. AutoNeg = AN_ON;
  3239. }
  3240. /*
  3241. ** set the desired mode
  3242. */
  3243. if (AutoSet || DupSet) {
  3244. pAC->GIni.GP[1].PLinkModeConf = Capabilities[AutoNeg][DuplexCap];
  3245. }
  3246. /*
  3247. ** c) Any FlowCtrl parameter set?
  3248. */
  3249. if (FlowCtrl_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3250. FlowCtrl_B[pAC->Index] != NULL) {
  3251. if (strcmp(FlowCtrl_B[pAC->Index],"") == 0) {
  3252. IsFlowCtrlDefined = SK_FALSE;
  3253. } else if (strcmp(FlowCtrl_B[pAC->Index],"SymOrRem") == 0) {
  3254. FlowCtrl = SK_FLOW_MODE_SYM_OR_REM;
  3255. } else if (strcmp(FlowCtrl_B[pAC->Index],"Sym")==0) {
  3256. FlowCtrl = SK_FLOW_MODE_SYMMETRIC;
  3257. } else if (strcmp(FlowCtrl_B[pAC->Index],"LocSend")==0) {
  3258. FlowCtrl = SK_FLOW_MODE_LOC_SEND;
  3259. } else if (strcmp(FlowCtrl_B[pAC->Index],"None")==0) {
  3260. FlowCtrl = SK_FLOW_MODE_NONE;
  3261. } else {
  3262. printk("sk98lin: Illegal value \"%s\" for FlowCtrl_B\n",
  3263. FlowCtrl_B[pAC->Index]);
  3264. IsFlowCtrlDefined = SK_FALSE;
  3265. }
  3266. } else {
  3267. IsFlowCtrlDefined = SK_FALSE;
  3268. }
  3269. if (IsFlowCtrlDefined) {
  3270. if ((AutoNeg == AN_OFF) && (FlowCtrl != SK_FLOW_MODE_NONE)) {
  3271. printk("sk98lin: Port B: FlowControl"
  3272. " impossible without AutoNegotiation,"
  3273. " disabled\n");
  3274. FlowCtrl = SK_FLOW_MODE_NONE;
  3275. }
  3276. pAC->GIni.GP[1].PFlowCtrlMode = FlowCtrl;
  3277. }
  3278. /*
  3279. ** d) What is the RoleParameter?
  3280. */
  3281. if (Role_B != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3282. Role_B[pAC->Index] != NULL) {
  3283. if (strcmp(Role_B[pAC->Index],"")==0) {
  3284. IsRoleDefined = SK_FALSE;
  3285. } else if (strcmp(Role_B[pAC->Index],"Auto")==0) {
  3286. MSMode = SK_MS_MODE_AUTO;
  3287. } else if (strcmp(Role_B[pAC->Index],"Master")==0) {
  3288. MSMode = SK_MS_MODE_MASTER;
  3289. } else if (strcmp(Role_B[pAC->Index],"Slave")==0) {
  3290. MSMode = SK_MS_MODE_SLAVE;
  3291. } else {
  3292. printk("sk98lin: Illegal value \"%s\" for Role_B\n",
  3293. Role_B[pAC->Index]);
  3294. IsRoleDefined = SK_FALSE;
  3295. }
  3296. } else {
  3297. IsRoleDefined = SK_FALSE;
  3298. }
  3299. if (IsRoleDefined) {
  3300. pAC->GIni.GP[1].PMSMode = MSMode;
  3301. }
  3302. /*
  3303. ** Evaluate settings for both ports
  3304. */
  3305. pAC->ActivePort = 0;
  3306. if (PrefPort != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3307. PrefPort[pAC->Index] != NULL) {
  3308. if (strcmp(PrefPort[pAC->Index],"") == 0) { /* Auto */
  3309. pAC->ActivePort = 0;
  3310. pAC->Rlmt.Net[0].Preference = -1; /* auto */
  3311. pAC->Rlmt.Net[0].PrefPort = 0;
  3312. } else if (strcmp(PrefPort[pAC->Index],"A") == 0) {
  3313. /*
  3314. ** do not set ActivePort here, thus a port
  3315. ** switch is issued after net up.
  3316. */
  3317. Port = 0;
  3318. pAC->Rlmt.Net[0].Preference = Port;
  3319. pAC->Rlmt.Net[0].PrefPort = Port;
  3320. } else if (strcmp(PrefPort[pAC->Index],"B") == 0) {
  3321. /*
  3322. ** do not set ActivePort here, thus a port
  3323. ** switch is issued after net up.
  3324. */
  3325. if (pAC->GIni.GIMacsFound == 1) {
  3326. printk("sk98lin: Illegal value \"B\" for PrefPort.\n"
  3327. " Port B not available on single port adapters.\n");
  3328. pAC->ActivePort = 0;
  3329. pAC->Rlmt.Net[0].Preference = -1; /* auto */
  3330. pAC->Rlmt.Net[0].PrefPort = 0;
  3331. } else {
  3332. Port = 1;
  3333. pAC->Rlmt.Net[0].Preference = Port;
  3334. pAC->Rlmt.Net[0].PrefPort = Port;
  3335. }
  3336. } else {
  3337. printk("sk98lin: Illegal value \"%s\" for PrefPort\n",
  3338. PrefPort[pAC->Index]);
  3339. }
  3340. }
  3341. pAC->RlmtNets = 1;
  3342. if (RlmtMode != NULL && pAC->Index<SK_MAX_CARD_PARAM &&
  3343. RlmtMode[pAC->Index] != NULL) {
  3344. if (strcmp(RlmtMode[pAC->Index], "") == 0) {
  3345. pAC->RlmtMode = 0;
  3346. } else if (strcmp(RlmtMode[pAC->Index], "CheckLinkState") == 0) {
  3347. pAC->RlmtMode = SK_RLMT_CHECK_LINK;
  3348. } else if (strcmp(RlmtMode[pAC->Index], "CheckLocalPort") == 0) {
  3349. pAC->RlmtMode = SK_RLMT_CHECK_LINK |
  3350. SK_RLMT_CHECK_LOC_LINK;
  3351. } else if (strcmp(RlmtMode[pAC->Index], "CheckSeg") == 0) {
  3352. pAC->RlmtMode = SK_RLMT_CHECK_LINK |
  3353. SK_RLMT_CHECK_LOC_LINK |
  3354. SK_RLMT_CHECK_SEG;
  3355. } else if ((strcmp(RlmtMode[pAC->Index], "DualNet") == 0) &&
  3356. (pAC->GIni.GIMacsFound == 2)) {
  3357. pAC->RlmtMode = SK_RLMT_CHECK_LINK;
  3358. pAC->RlmtNets = 2;
  3359. } else {
  3360. printk("sk98lin: Illegal value \"%s\" for"
  3361. " RlmtMode, using default\n",
  3362. RlmtMode[pAC->Index]);
  3363. pAC->RlmtMode = 0;
  3364. }
  3365. } else {
  3366. pAC->RlmtMode = 0;
  3367. }
  3368. /*
  3369. ** Check the interrupt moderation parameters
  3370. */
  3371. if (Moderation[pAC->Index] != NULL) {
  3372. if (strcmp(Moderation[pAC->Index], "") == 0) {
  3373. pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
  3374. } else if (strcmp(Moderation[pAC->Index], "Static") == 0) {
  3375. pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_STATIC;
  3376. } else if (strcmp(Moderation[pAC->Index], "Dynamic") == 0) {
  3377. pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_DYNAMIC;
  3378. } else if (strcmp(Moderation[pAC->Index], "None") == 0) {
  3379. pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
  3380. } else {
  3381. printk("sk98lin: Illegal value \"%s\" for Moderation.\n"
  3382. " Disable interrupt moderation.\n",
  3383. Moderation[pAC->Index]);
  3384. pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
  3385. }
  3386. } else {
  3387. pAC->DynIrqModInfo.IntModTypeSelect = C_INT_MOD_NONE;
  3388. }
  3389. if (Stats[pAC->Index] != NULL) {
  3390. if (strcmp(Stats[pAC->Index], "Yes") == 0) {
  3391. pAC->DynIrqModInfo.DisplayStats = SK_TRUE;
  3392. } else {
  3393. pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
  3394. }
  3395. } else {
  3396. pAC->DynIrqModInfo.DisplayStats = SK_FALSE;
  3397. }
  3398. if (ModerationMask[pAC->Index] != NULL) {
  3399. if (strcmp(ModerationMask[pAC->Index], "Rx") == 0) {
  3400. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
  3401. } else if (strcmp(ModerationMask[pAC->Index], "Tx") == 0) {
  3402. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_ONLY;
  3403. } else if (strcmp(ModerationMask[pAC->Index], "Sp") == 0) {
  3404. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_ONLY;
  3405. } else if (strcmp(ModerationMask[pAC->Index], "RxSp") == 0) {
  3406. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
  3407. } else if (strcmp(ModerationMask[pAC->Index], "SpRx") == 0) {
  3408. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_RX;
  3409. } else if (strcmp(ModerationMask[pAC->Index], "RxTx") == 0) {
  3410. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
  3411. } else if (strcmp(ModerationMask[pAC->Index], "TxRx") == 0) {
  3412. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
  3413. } else if (strcmp(ModerationMask[pAC->Index], "TxSp") == 0) {
  3414. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
  3415. } else if (strcmp(ModerationMask[pAC->Index], "SpTx") == 0) {
  3416. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_SP_TX;
  3417. } else if (strcmp(ModerationMask[pAC->Index], "RxTxSp") == 0) {
  3418. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
  3419. } else if (strcmp(ModerationMask[pAC->Index], "RxSpTx") == 0) {
  3420. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
  3421. } else if (strcmp(ModerationMask[pAC->Index], "TxRxSp") == 0) {
  3422. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
  3423. } else if (strcmp(ModerationMask[pAC->Index], "TxSpRx") == 0) {
  3424. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
  3425. } else if (strcmp(ModerationMask[pAC->Index], "SpTxRx") == 0) {
  3426. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
  3427. } else if (strcmp(ModerationMask[pAC->Index], "SpRxTx") == 0) {
  3428. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_TX_SP;
  3429. } else { /* some rubbish */
  3430. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_RX_ONLY;
  3431. }
  3432. } else { /* operator has stated nothing */
  3433. pAC->DynIrqModInfo.MaskIrqModeration = IRQ_MASK_TX_RX;
  3434. }
  3435. if (AutoSizing[pAC->Index] != NULL) {
  3436. if (strcmp(AutoSizing[pAC->Index], "On") == 0) {
  3437. pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
  3438. } else {
  3439. pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
  3440. }
  3441. } else { /* operator has stated nothing */
  3442. pAC->DynIrqModInfo.AutoSizing = SK_FALSE;
  3443. }
  3444. if (IntsPerSec[pAC->Index] != 0) {
  3445. if ((IntsPerSec[pAC->Index]< C_INT_MOD_IPS_LOWER_RANGE) ||
  3446. (IntsPerSec[pAC->Index] > C_INT_MOD_IPS_UPPER_RANGE)) {
  3447. printk("sk98lin: Illegal value \"%d\" for IntsPerSec. (Range: %d - %d)\n"
  3448. " Using default value of %i.\n",
  3449. IntsPerSec[pAC->Index],
  3450. C_INT_MOD_IPS_LOWER_RANGE,
  3451. C_INT_MOD_IPS_UPPER_RANGE,
  3452. C_INTS_PER_SEC_DEFAULT);
  3453. pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
  3454. } else {
  3455. pAC->DynIrqModInfo.MaxModIntsPerSec = IntsPerSec[pAC->Index];
  3456. }
  3457. } else {
  3458. pAC->DynIrqModInfo.MaxModIntsPerSec = C_INTS_PER_SEC_DEFAULT;
  3459. }
  3460. /*
  3461. ** Evaluate upper and lower moderation threshold
  3462. */
  3463. pAC->DynIrqModInfo.MaxModIntsPerSecUpperLimit =
  3464. pAC->DynIrqModInfo.MaxModIntsPerSec +
  3465. (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
  3466. pAC->DynIrqModInfo.MaxModIntsPerSecLowerLimit =
  3467. pAC->DynIrqModInfo.MaxModIntsPerSec -
  3468. (pAC->DynIrqModInfo.MaxModIntsPerSec / 2);
  3469. pAC->DynIrqModInfo.PrevTimeVal = jiffies; /* initial value */
  3470. } /* GetConfiguration */
  3471. /*****************************************************************************
  3472. *
  3473. * ProductStr - return a adapter identification string from vpd
  3474. *
  3475. * Description:
  3476. * This function reads the product name string from the vpd area
  3477. * and puts it the field pAC->DeviceString.
  3478. *
  3479. * Returns: N/A
  3480. */
  3481. static void ProductStr(
  3482. SK_AC *pAC /* pointer to adapter context */
  3483. )
  3484. {
  3485. int StrLen = 80; /* length of the string, defined in SK_AC */
  3486. char Keyword[] = VPD_NAME; /* vpd productname identifier */
  3487. int ReturnCode; /* return code from vpd_read */
  3488. unsigned long Flags;
  3489. spin_lock_irqsave(&pAC->SlowPathLock, Flags);
  3490. ReturnCode = VpdRead(pAC, pAC->IoBase, Keyword, pAC->DeviceStr,
  3491. &StrLen);
  3492. spin_unlock_irqrestore(&pAC->SlowPathLock, Flags);
  3493. if (ReturnCode != 0) {
  3494. /* there was an error reading the vpd data */
  3495. SK_DBG_MSG(NULL, SK_DBGMOD_DRV, SK_DBGCAT_DRV_ERROR,
  3496. ("Error reading VPD data: %d\n", ReturnCode));
  3497. pAC->DeviceStr[0] = '\0';
  3498. }
  3499. } /* ProductStr */
  3500. /*****************************************************************************
  3501. *
  3502. * StartDrvCleanupTimer - Start timer to check for descriptors which
  3503. * might be placed in descriptor ring, but
  3504. * havent been handled up to now
  3505. *
  3506. * Description:
  3507. * This function requests a HW-timer fo the Yukon card. The actions to
  3508. * perform when this timer expires, are located in the SkDrvEvent().
  3509. *
  3510. * Returns: N/A
  3511. */
  3512. static void
  3513. StartDrvCleanupTimer(SK_AC *pAC) {
  3514. SK_EVPARA EventParam; /* Event struct for timer event */
  3515. SK_MEMSET((char *) &EventParam, 0, sizeof(EventParam));
  3516. EventParam.Para32[0] = SK_DRV_RX_CLEANUP_TIMER;
  3517. SkTimerStart(pAC, pAC->IoBase, &pAC->DrvCleanupTimer,
  3518. SK_DRV_RX_CLEANUP_TIMER_LENGTH,
  3519. SKGE_DRV, SK_DRV_TIMER, EventParam);
  3520. }
  3521. /*****************************************************************************
  3522. *
  3523. * StopDrvCleanupTimer - Stop timer to check for descriptors
  3524. *
  3525. * Description:
  3526. * This function requests a HW-timer fo the Yukon card. The actions to
  3527. * perform when this timer expires, are located in the SkDrvEvent().
  3528. *
  3529. * Returns: N/A
  3530. */
  3531. static void
  3532. StopDrvCleanupTimer(SK_AC *pAC) {
  3533. SkTimerStop(pAC, pAC->IoBase, &pAC->DrvCleanupTimer);
  3534. SK_MEMSET((char *) &pAC->DrvCleanupTimer, 0, sizeof(SK_TIMER));
  3535. }
  3536. /****************************************************************************/
  3537. /* functions for common modules *********************************************/
  3538. /****************************************************************************/
  3539. /*****************************************************************************
  3540. *
  3541. * SkDrvAllocRlmtMbuf - allocate an RLMT mbuf
  3542. *
  3543. * Description:
  3544. * This routine returns an RLMT mbuf or NULL. The RLMT Mbuf structure
  3545. * is embedded into a socket buff data area.
  3546. *
  3547. * Context:
  3548. * runtime
  3549. *
  3550. * Returns:
  3551. * NULL or pointer to Mbuf.
  3552. */
  3553. SK_MBUF *SkDrvAllocRlmtMbuf(
  3554. SK_AC *pAC, /* pointer to adapter context */
  3555. SK_IOC IoC, /* the IO-context */
  3556. unsigned BufferSize) /* size of the requested buffer */
  3557. {
  3558. SK_MBUF *pRlmtMbuf; /* pointer to a new rlmt-mbuf structure */
  3559. struct sk_buff *pMsgBlock; /* pointer to a new message block */
  3560. pMsgBlock = alloc_skb(BufferSize + sizeof(SK_MBUF), GFP_ATOMIC);
  3561. if (pMsgBlock == NULL) {
  3562. return (NULL);
  3563. }
  3564. pRlmtMbuf = (SK_MBUF*) pMsgBlock->data;
  3565. skb_reserve(pMsgBlock, sizeof(SK_MBUF));
  3566. pRlmtMbuf->pNext = NULL;
  3567. pRlmtMbuf->pOs = pMsgBlock;
  3568. pRlmtMbuf->pData = pMsgBlock->data; /* Data buffer. */
  3569. pRlmtMbuf->Size = BufferSize; /* Data buffer size. */
  3570. pRlmtMbuf->Length = 0; /* Length of packet (<= Size). */
  3571. return (pRlmtMbuf);
  3572. } /* SkDrvAllocRlmtMbuf */
  3573. /*****************************************************************************
  3574. *
  3575. * SkDrvFreeRlmtMbuf - free an RLMT mbuf
  3576. *
  3577. * Description:
  3578. * This routine frees one or more RLMT mbuf(s).
  3579. *
  3580. * Context:
  3581. * runtime
  3582. *
  3583. * Returns:
  3584. * Nothing
  3585. */
  3586. void SkDrvFreeRlmtMbuf(
  3587. SK_AC *pAC, /* pointer to adapter context */
  3588. SK_IOC IoC, /* the IO-context */
  3589. SK_MBUF *pMbuf) /* size of the requested buffer */
  3590. {
  3591. SK_MBUF *pFreeMbuf;
  3592. SK_MBUF *pNextMbuf;
  3593. pFreeMbuf = pMbuf;
  3594. do {
  3595. pNextMbuf = pFreeMbuf->pNext;
  3596. DEV_KFREE_SKB_ANY(pFreeMbuf->pOs);
  3597. pFreeMbuf = pNextMbuf;
  3598. } while ( pFreeMbuf != NULL );
  3599. } /* SkDrvFreeRlmtMbuf */
  3600. /*****************************************************************************
  3601. *
  3602. * SkOsGetTime - provide a time value
  3603. *
  3604. * Description:
  3605. * This routine provides a time value. The unit is 1/HZ (defined by Linux).
  3606. * It is not used for absolute time, but only for time differences.
  3607. *
  3608. *
  3609. * Returns:
  3610. * Time value
  3611. */
  3612. SK_U64 SkOsGetTime(SK_AC *pAC)
  3613. {
  3614. SK_U64 PrivateJiffies;
  3615. SkOsGetTimeCurrent(pAC, &PrivateJiffies);
  3616. return PrivateJiffies;
  3617. } /* SkOsGetTime */
  3618. /*****************************************************************************
  3619. *
  3620. * SkPciReadCfgDWord - read a 32 bit value from pci config space
  3621. *
  3622. * Description:
  3623. * This routine reads a 32 bit value from the pci configuration
  3624. * space.
  3625. *
  3626. * Returns:
  3627. * 0 - indicate everything worked ok.
  3628. * != 0 - error indication
  3629. */
  3630. int SkPciReadCfgDWord(
  3631. SK_AC *pAC, /* Adapter Control structure pointer */
  3632. int PciAddr, /* PCI register address */
  3633. SK_U32 *pVal) /* pointer to store the read value */
  3634. {
  3635. pci_read_config_dword(pAC->PciDev, PciAddr, pVal);
  3636. return(0);
  3637. } /* SkPciReadCfgDWord */
  3638. /*****************************************************************************
  3639. *
  3640. * SkPciReadCfgWord - read a 16 bit value from pci config space
  3641. *
  3642. * Description:
  3643. * This routine reads a 16 bit value from the pci configuration
  3644. * space.
  3645. *
  3646. * Returns:
  3647. * 0 - indicate everything worked ok.
  3648. * != 0 - error indication
  3649. */
  3650. int SkPciReadCfgWord(
  3651. SK_AC *pAC, /* Adapter Control structure pointer */
  3652. int PciAddr, /* PCI register address */
  3653. SK_U16 *pVal) /* pointer to store the read value */
  3654. {
  3655. pci_read_config_word(pAC->PciDev, PciAddr, pVal);
  3656. return(0);
  3657. } /* SkPciReadCfgWord */
  3658. /*****************************************************************************
  3659. *
  3660. * SkPciReadCfgByte - read a 8 bit value from pci config space
  3661. *
  3662. * Description:
  3663. * This routine reads a 8 bit value from the pci configuration
  3664. * space.
  3665. *
  3666. * Returns:
  3667. * 0 - indicate everything worked ok.
  3668. * != 0 - error indication
  3669. */
  3670. int SkPciReadCfgByte(
  3671. SK_AC *pAC, /* Adapter Control structure pointer */
  3672. int PciAddr, /* PCI register address */
  3673. SK_U8 *pVal) /* pointer to store the read value */
  3674. {
  3675. pci_read_config_byte(pAC->PciDev, PciAddr, pVal);
  3676. return(0);
  3677. } /* SkPciReadCfgByte */
  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. /* DLink card does not have valid VPD so this driver gags
  4675. * { PCI_VENDOR_ID_DLINK, 0x4c00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  4676. */
  4677. { PCI_VENDOR_ID_MARVELL, 0x4320, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  4678. { PCI_VENDOR_ID_MARVELL, 0x5005, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  4679. { PCI_VENDOR_ID_CNET, 0x434e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  4680. { PCI_VENDOR_ID_LINKSYS, 0x1032, PCI_ANY_ID, 0x0015, },
  4681. { PCI_VENDOR_ID_LINKSYS, 0x1064, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  4682. { 0 }
  4683. };
  4684. MODULE_DEVICE_TABLE(pci, skge_pci_tbl);
  4685. static struct pci_driver skge_driver = {
  4686. .name = "sk98lin",
  4687. .id_table = skge_pci_tbl,
  4688. .probe = skge_probe_one,
  4689. .remove = __devexit_p(skge_remove_one),
  4690. .suspend = skge_suspend,
  4691. .resume = skge_resume,
  4692. };
  4693. static int __init skge_init(void)
  4694. {
  4695. int error;
  4696. pSkRootDir = proc_mkdir(SKRootName, NULL);
  4697. if (pSkRootDir)
  4698. pSkRootDir->owner = THIS_MODULE;
  4699. error = pci_register_driver(&skge_driver);
  4700. if (error)
  4701. remove_proc_entry(SKRootName, NULL);
  4702. return error;
  4703. }
  4704. static void __exit skge_exit(void)
  4705. {
  4706. pci_unregister_driver(&skge_driver);
  4707. remove_proc_entry(SKRootName, NULL);
  4708. }
  4709. module_init(skge_init);
  4710. module_exit(skge_exit);