s2io.c 177 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315
  1. /************************************************************************
  2. * s2io.c: A Linux PCI-X Ethernet driver for Neterion 10GbE Server NIC
  3. * Copyright(c) 2002-2005 Neterion Inc.
  4. * This software may be used and distributed according to the terms of
  5. * the GNU General Public License (GPL), incorporated herein by reference.
  6. * Drivers based on or derived from this code fall under the GPL and must
  7. * retain the authorship, copyright and license notice. This file is not
  8. * a complete program and may only be used when the entire operating
  9. * system is licensed under the GPL.
  10. * See the file COPYING in this distribution for more information.
  11. *
  12. * Credits:
  13. * Jeff Garzik : For pointing out the improper error condition
  14. * check in the s2io_xmit routine and also some
  15. * issues in the Tx watch dog function. Also for
  16. * patiently answering all those innumerable
  17. * questions regaring the 2.6 porting issues.
  18. * Stephen Hemminger : Providing proper 2.6 porting mechanism for some
  19. * macros available only in 2.6 Kernel.
  20. * Francois Romieu : For pointing out all code part that were
  21. * deprecated and also styling related comments.
  22. * Grant Grundler : For helping me get rid of some Architecture
  23. * dependent code.
  24. * Christopher Hellwig : Some more 2.6 specific issues in the driver.
  25. *
  26. * The module loadable parameters that are supported by the driver and a brief
  27. * explaination of all the variables.
  28. * rx_ring_num : This can be used to program the number of receive rings used
  29. * in the driver.
  30. * rx_ring_sz: This defines the number of descriptors each ring can have. This
  31. * is also an array of size 8.
  32. * rx_ring_mode: This defines the operation mode of all 8 rings. The valid
  33. * values are 1, 2 and 3.
  34. * tx_fifo_num: This defines the number of Tx FIFOs thats used int the driver.
  35. * tx_fifo_len: This too is an array of 8. Each element defines the number of
  36. * Tx descriptors that can be associated with each corresponding FIFO.
  37. ************************************************************************/
  38. #include <linux/config.h>
  39. #include <linux/module.h>
  40. #include <linux/types.h>
  41. #include <linux/errno.h>
  42. #include <linux/ioport.h>
  43. #include <linux/pci.h>
  44. #include <linux/dma-mapping.h>
  45. #include <linux/kernel.h>
  46. #include <linux/netdevice.h>
  47. #include <linux/etherdevice.h>
  48. #include <linux/skbuff.h>
  49. #include <linux/init.h>
  50. #include <linux/delay.h>
  51. #include <linux/stddef.h>
  52. #include <linux/ioctl.h>
  53. #include <linux/timex.h>
  54. #include <linux/sched.h>
  55. #include <linux/ethtool.h>
  56. #include <linux/workqueue.h>
  57. #include <linux/if_vlan.h>
  58. #include <asm/system.h>
  59. #include <asm/uaccess.h>
  60. #include <asm/io.h>
  61. /* local include */
  62. #include "s2io.h"
  63. #include "s2io-regs.h"
  64. #define DRV_VERSION "Version 2.0.9.3"
  65. /* S2io Driver name & version. */
  66. static char s2io_driver_name[] = "Neterion";
  67. static char s2io_driver_version[] = DRV_VERSION;
  68. int rxd_size[4] = {32,48,48,64};
  69. int rxd_count[4] = {127,85,85,63};
  70. static inline int RXD_IS_UP2DT(RxD_t *rxdp)
  71. {
  72. int ret;
  73. ret = ((!(rxdp->Control_1 & RXD_OWN_XENA)) &&
  74. (GET_RXD_MARKER(rxdp->Control_2) != THE_RXD_MARK));
  75. return ret;
  76. }
  77. /*
  78. * Cards with following subsystem_id have a link state indication
  79. * problem, 600B, 600C, 600D, 640B, 640C and 640D.
  80. * macro below identifies these cards given the subsystem_id.
  81. */
  82. #define CARDS_WITH_FAULTY_LINK_INDICATORS(dev_type, subid) \
  83. (dev_type == XFRAME_I_DEVICE) ? \
  84. ((((subid >= 0x600B) && (subid <= 0x600D)) || \
  85. ((subid >= 0x640B) && (subid <= 0x640D))) ? 1 : 0) : 0
  86. #define LINK_IS_UP(val64) (!(val64 & (ADAPTER_STATUS_RMAC_REMOTE_FAULT | \
  87. ADAPTER_STATUS_RMAC_LOCAL_FAULT)))
  88. #define TASKLET_IN_USE test_and_set_bit(0, (&sp->tasklet_status))
  89. #define PANIC 1
  90. #define LOW 2
  91. static inline int rx_buffer_level(nic_t * sp, int rxb_size, int ring)
  92. {
  93. int level = 0;
  94. mac_info_t *mac_control;
  95. mac_control = &sp->mac_control;
  96. if ((mac_control->rings[ring].pkt_cnt - rxb_size) > 16) {
  97. level = LOW;
  98. if (rxb_size <= rxd_count[sp->rxd_mode]) {
  99. level = PANIC;
  100. }
  101. }
  102. return level;
  103. }
  104. /* Ethtool related variables and Macros. */
  105. static char s2io_gstrings[][ETH_GSTRING_LEN] = {
  106. "Register test\t(offline)",
  107. "Eeprom test\t(offline)",
  108. "Link test\t(online)",
  109. "RLDRAM test\t(offline)",
  110. "BIST Test\t(offline)"
  111. };
  112. static char ethtool_stats_keys[][ETH_GSTRING_LEN] = {
  113. {"tmac_frms"},
  114. {"tmac_data_octets"},
  115. {"tmac_drop_frms"},
  116. {"tmac_mcst_frms"},
  117. {"tmac_bcst_frms"},
  118. {"tmac_pause_ctrl_frms"},
  119. {"tmac_any_err_frms"},
  120. {"tmac_vld_ip_octets"},
  121. {"tmac_vld_ip"},
  122. {"tmac_drop_ip"},
  123. {"tmac_icmp"},
  124. {"tmac_rst_tcp"},
  125. {"tmac_tcp"},
  126. {"tmac_udp"},
  127. {"rmac_vld_frms"},
  128. {"rmac_data_octets"},
  129. {"rmac_fcs_err_frms"},
  130. {"rmac_drop_frms"},
  131. {"rmac_vld_mcst_frms"},
  132. {"rmac_vld_bcst_frms"},
  133. {"rmac_in_rng_len_err_frms"},
  134. {"rmac_long_frms"},
  135. {"rmac_pause_ctrl_frms"},
  136. {"rmac_discarded_frms"},
  137. {"rmac_usized_frms"},
  138. {"rmac_osized_frms"},
  139. {"rmac_frag_frms"},
  140. {"rmac_jabber_frms"},
  141. {"rmac_ip"},
  142. {"rmac_ip_octets"},
  143. {"rmac_hdr_err_ip"},
  144. {"rmac_drop_ip"},
  145. {"rmac_icmp"},
  146. {"rmac_tcp"},
  147. {"rmac_udp"},
  148. {"rmac_err_drp_udp"},
  149. {"rmac_pause_cnt"},
  150. {"rmac_accepted_ip"},
  151. {"rmac_err_tcp"},
  152. {"\n DRIVER STATISTICS"},
  153. {"single_bit_ecc_errs"},
  154. {"double_bit_ecc_errs"},
  155. };
  156. #define S2IO_STAT_LEN sizeof(ethtool_stats_keys)/ ETH_GSTRING_LEN
  157. #define S2IO_STAT_STRINGS_LEN S2IO_STAT_LEN * ETH_GSTRING_LEN
  158. #define S2IO_TEST_LEN sizeof(s2io_gstrings) / ETH_GSTRING_LEN
  159. #define S2IO_STRINGS_LEN S2IO_TEST_LEN * ETH_GSTRING_LEN
  160. #define S2IO_TIMER_CONF(timer, handle, arg, exp) \
  161. init_timer(&timer); \
  162. timer.function = handle; \
  163. timer.data = (unsigned long) arg; \
  164. mod_timer(&timer, (jiffies + exp)) \
  165. /* Add the vlan */
  166. static void s2io_vlan_rx_register(struct net_device *dev,
  167. struct vlan_group *grp)
  168. {
  169. nic_t *nic = dev->priv;
  170. unsigned long flags;
  171. spin_lock_irqsave(&nic->tx_lock, flags);
  172. nic->vlgrp = grp;
  173. spin_unlock_irqrestore(&nic->tx_lock, flags);
  174. }
  175. /* Unregister the vlan */
  176. static void s2io_vlan_rx_kill_vid(struct net_device *dev, unsigned long vid)
  177. {
  178. nic_t *nic = dev->priv;
  179. unsigned long flags;
  180. spin_lock_irqsave(&nic->tx_lock, flags);
  181. if (nic->vlgrp)
  182. nic->vlgrp->vlan_devices[vid] = NULL;
  183. spin_unlock_irqrestore(&nic->tx_lock, flags);
  184. }
  185. /*
  186. * Constants to be programmed into the Xena's registers, to configure
  187. * the XAUI.
  188. */
  189. #define SWITCH_SIGN 0xA5A5A5A5A5A5A5A5ULL
  190. #define END_SIGN 0x0
  191. static u64 herc_act_dtx_cfg[] = {
  192. /* Set address */
  193. 0x8000051536750000ULL, 0x80000515367500E0ULL,
  194. /* Write data */
  195. 0x8000051536750004ULL, 0x80000515367500E4ULL,
  196. /* Set address */
  197. 0x80010515003F0000ULL, 0x80010515003F00E0ULL,
  198. /* Write data */
  199. 0x80010515003F0004ULL, 0x80010515003F00E4ULL,
  200. /* Set address */
  201. 0x801205150D440000ULL, 0x801205150D4400E0ULL,
  202. /* Write data */
  203. 0x801205150D440004ULL, 0x801205150D4400E4ULL,
  204. /* Set address */
  205. 0x80020515F2100000ULL, 0x80020515F21000E0ULL,
  206. /* Write data */
  207. 0x80020515F2100004ULL, 0x80020515F21000E4ULL,
  208. /* Done */
  209. END_SIGN
  210. };
  211. static u64 xena_mdio_cfg[] = {
  212. /* Reset PMA PLL */
  213. 0xC001010000000000ULL, 0xC0010100000000E0ULL,
  214. 0xC0010100008000E4ULL,
  215. /* Remove Reset from PMA PLL */
  216. 0xC001010000000000ULL, 0xC0010100000000E0ULL,
  217. 0xC0010100000000E4ULL,
  218. END_SIGN
  219. };
  220. static u64 xena_dtx_cfg[] = {
  221. 0x8000051500000000ULL, 0x80000515000000E0ULL,
  222. 0x80000515D93500E4ULL, 0x8001051500000000ULL,
  223. 0x80010515000000E0ULL, 0x80010515001E00E4ULL,
  224. 0x8002051500000000ULL, 0x80020515000000E0ULL,
  225. 0x80020515F21000E4ULL,
  226. /* Set PADLOOPBACKN */
  227. 0x8002051500000000ULL, 0x80020515000000E0ULL,
  228. 0x80020515B20000E4ULL, 0x8003051500000000ULL,
  229. 0x80030515000000E0ULL, 0x80030515B20000E4ULL,
  230. 0x8004051500000000ULL, 0x80040515000000E0ULL,
  231. 0x80040515B20000E4ULL, 0x8005051500000000ULL,
  232. 0x80050515000000E0ULL, 0x80050515B20000E4ULL,
  233. SWITCH_SIGN,
  234. /* Remove PADLOOPBACKN */
  235. 0x8002051500000000ULL, 0x80020515000000E0ULL,
  236. 0x80020515F20000E4ULL, 0x8003051500000000ULL,
  237. 0x80030515000000E0ULL, 0x80030515F20000E4ULL,
  238. 0x8004051500000000ULL, 0x80040515000000E0ULL,
  239. 0x80040515F20000E4ULL, 0x8005051500000000ULL,
  240. 0x80050515000000E0ULL, 0x80050515F20000E4ULL,
  241. END_SIGN
  242. };
  243. /*
  244. * Constants for Fixing the MacAddress problem seen mostly on
  245. * Alpha machines.
  246. */
  247. static u64 fix_mac[] = {
  248. 0x0060000000000000ULL, 0x0060600000000000ULL,
  249. 0x0040600000000000ULL, 0x0000600000000000ULL,
  250. 0x0020600000000000ULL, 0x0060600000000000ULL,
  251. 0x0020600000000000ULL, 0x0060600000000000ULL,
  252. 0x0020600000000000ULL, 0x0060600000000000ULL,
  253. 0x0020600000000000ULL, 0x0060600000000000ULL,
  254. 0x0020600000000000ULL, 0x0060600000000000ULL,
  255. 0x0020600000000000ULL, 0x0060600000000000ULL,
  256. 0x0020600000000000ULL, 0x0060600000000000ULL,
  257. 0x0020600000000000ULL, 0x0060600000000000ULL,
  258. 0x0020600000000000ULL, 0x0060600000000000ULL,
  259. 0x0020600000000000ULL, 0x0060600000000000ULL,
  260. 0x0020600000000000ULL, 0x0000600000000000ULL,
  261. 0x0040600000000000ULL, 0x0060600000000000ULL,
  262. END_SIGN
  263. };
  264. /* Module Loadable parameters. */
  265. static unsigned int tx_fifo_num = 1;
  266. static unsigned int tx_fifo_len[MAX_TX_FIFOS] =
  267. {[0 ...(MAX_TX_FIFOS - 1)] = 0 };
  268. static unsigned int rx_ring_num = 1;
  269. static unsigned int rx_ring_sz[MAX_RX_RINGS] =
  270. {[0 ...(MAX_RX_RINGS - 1)] = 0 };
  271. static unsigned int rts_frm_len[MAX_RX_RINGS] =
  272. {[0 ...(MAX_RX_RINGS - 1)] = 0 };
  273. static unsigned int rx_ring_mode = 1;
  274. static unsigned int use_continuous_tx_intrs = 1;
  275. static unsigned int rmac_pause_time = 65535;
  276. static unsigned int mc_pause_threshold_q0q3 = 187;
  277. static unsigned int mc_pause_threshold_q4q7 = 187;
  278. static unsigned int shared_splits;
  279. static unsigned int tmac_util_period = 5;
  280. static unsigned int rmac_util_period = 5;
  281. static unsigned int bimodal = 0;
  282. static unsigned int l3l4hdr_size = 128;
  283. #ifndef CONFIG_S2IO_NAPI
  284. static unsigned int indicate_max_pkts;
  285. #endif
  286. /* Frequency of Rx desc syncs expressed as power of 2 */
  287. static unsigned int rxsync_frequency = 3;
  288. /* Interrupt type. Values can be 0(INTA), 1(MSI), 2(MSI_X) */
  289. static unsigned int intr_type = 0;
  290. /*
  291. * S2IO device table.
  292. * This table lists all the devices that this driver supports.
  293. */
  294. static struct pci_device_id s2io_tbl[] __devinitdata = {
  295. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_S2IO_WIN,
  296. PCI_ANY_ID, PCI_ANY_ID},
  297. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_S2IO_UNI,
  298. PCI_ANY_ID, PCI_ANY_ID},
  299. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_HERC_WIN,
  300. PCI_ANY_ID, PCI_ANY_ID},
  301. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_HERC_UNI,
  302. PCI_ANY_ID, PCI_ANY_ID},
  303. {0,}
  304. };
  305. MODULE_DEVICE_TABLE(pci, s2io_tbl);
  306. static struct pci_driver s2io_driver = {
  307. .name = "S2IO",
  308. .id_table = s2io_tbl,
  309. .probe = s2io_init_nic,
  310. .remove = __devexit_p(s2io_rem_nic),
  311. };
  312. /* A simplifier macro used both by init and free shared_mem Fns(). */
  313. #define TXD_MEM_PAGE_CNT(len, per_each) ((len+per_each - 1) / per_each)
  314. /**
  315. * init_shared_mem - Allocation and Initialization of Memory
  316. * @nic: Device private variable.
  317. * Description: The function allocates all the memory areas shared
  318. * between the NIC and the driver. This includes Tx descriptors,
  319. * Rx descriptors and the statistics block.
  320. */
  321. static int init_shared_mem(struct s2io_nic *nic)
  322. {
  323. u32 size;
  324. void *tmp_v_addr, *tmp_v_addr_next;
  325. dma_addr_t tmp_p_addr, tmp_p_addr_next;
  326. RxD_block_t *pre_rxd_blk = NULL;
  327. int i, j, blk_cnt, rx_sz, tx_sz;
  328. int lst_size, lst_per_page;
  329. struct net_device *dev = nic->dev;
  330. unsigned long tmp;
  331. buffAdd_t *ba;
  332. mac_info_t *mac_control;
  333. struct config_param *config;
  334. mac_control = &nic->mac_control;
  335. config = &nic->config;
  336. /* Allocation and initialization of TXDLs in FIOFs */
  337. size = 0;
  338. for (i = 0; i < config->tx_fifo_num; i++) {
  339. size += config->tx_cfg[i].fifo_len;
  340. }
  341. if (size > MAX_AVAILABLE_TXDS) {
  342. DBG_PRINT(ERR_DBG, "%s: Requested TxDs too high, ",
  343. __FUNCTION__);
  344. DBG_PRINT(ERR_DBG, "Requested: %d, max supported: 8192\n", size);
  345. return FAILURE;
  346. }
  347. lst_size = (sizeof(TxD_t) * config->max_txds);
  348. tx_sz = lst_size * size;
  349. lst_per_page = PAGE_SIZE / lst_size;
  350. for (i = 0; i < config->tx_fifo_num; i++) {
  351. int fifo_len = config->tx_cfg[i].fifo_len;
  352. int list_holder_size = fifo_len * sizeof(list_info_hold_t);
  353. mac_control->fifos[i].list_info = kmalloc(list_holder_size,
  354. GFP_KERNEL);
  355. if (!mac_control->fifos[i].list_info) {
  356. DBG_PRINT(ERR_DBG,
  357. "Malloc failed for list_info\n");
  358. return -ENOMEM;
  359. }
  360. memset(mac_control->fifos[i].list_info, 0, list_holder_size);
  361. }
  362. for (i = 0; i < config->tx_fifo_num; i++) {
  363. int page_num = TXD_MEM_PAGE_CNT(config->tx_cfg[i].fifo_len,
  364. lst_per_page);
  365. mac_control->fifos[i].tx_curr_put_info.offset = 0;
  366. mac_control->fifos[i].tx_curr_put_info.fifo_len =
  367. config->tx_cfg[i].fifo_len - 1;
  368. mac_control->fifos[i].tx_curr_get_info.offset = 0;
  369. mac_control->fifos[i].tx_curr_get_info.fifo_len =
  370. config->tx_cfg[i].fifo_len - 1;
  371. mac_control->fifos[i].fifo_no = i;
  372. mac_control->fifos[i].nic = nic;
  373. mac_control->fifos[i].max_txds = MAX_SKB_FRAGS + 1;
  374. for (j = 0; j < page_num; j++) {
  375. int k = 0;
  376. dma_addr_t tmp_p;
  377. void *tmp_v;
  378. tmp_v = pci_alloc_consistent(nic->pdev,
  379. PAGE_SIZE, &tmp_p);
  380. if (!tmp_v) {
  381. DBG_PRINT(ERR_DBG,
  382. "pci_alloc_consistent ");
  383. DBG_PRINT(ERR_DBG, "failed for TxDL\n");
  384. return -ENOMEM;
  385. }
  386. /* If we got a zero DMA address(can happen on
  387. * certain platforms like PPC), reallocate.
  388. * Store virtual address of page we don't want,
  389. * to be freed later.
  390. */
  391. if (!tmp_p) {
  392. mac_control->zerodma_virt_addr = tmp_v;
  393. DBG_PRINT(INIT_DBG,
  394. "%s: Zero DMA address for TxDL. ", dev->name);
  395. DBG_PRINT(INIT_DBG,
  396. "Virtual address %p\n", tmp_v);
  397. tmp_v = pci_alloc_consistent(nic->pdev,
  398. PAGE_SIZE, &tmp_p);
  399. if (!tmp_v) {
  400. DBG_PRINT(ERR_DBG,
  401. "pci_alloc_consistent ");
  402. DBG_PRINT(ERR_DBG, "failed for TxDL\n");
  403. return -ENOMEM;
  404. }
  405. }
  406. while (k < lst_per_page) {
  407. int l = (j * lst_per_page) + k;
  408. if (l == config->tx_cfg[i].fifo_len)
  409. break;
  410. mac_control->fifos[i].list_info[l].list_virt_addr =
  411. tmp_v + (k * lst_size);
  412. mac_control->fifos[i].list_info[l].list_phy_addr =
  413. tmp_p + (k * lst_size);
  414. k++;
  415. }
  416. }
  417. }
  418. /* Allocation and initialization of RXDs in Rings */
  419. size = 0;
  420. for (i = 0; i < config->rx_ring_num; i++) {
  421. if (config->rx_cfg[i].num_rxd %
  422. (rxd_count[nic->rxd_mode] + 1)) {
  423. DBG_PRINT(ERR_DBG, "%s: RxD count of ", dev->name);
  424. DBG_PRINT(ERR_DBG, "Ring%d is not a multiple of ",
  425. i);
  426. DBG_PRINT(ERR_DBG, "RxDs per Block");
  427. return FAILURE;
  428. }
  429. size += config->rx_cfg[i].num_rxd;
  430. mac_control->rings[i].block_count =
  431. config->rx_cfg[i].num_rxd /
  432. (rxd_count[nic->rxd_mode] + 1 );
  433. mac_control->rings[i].pkt_cnt = config->rx_cfg[i].num_rxd -
  434. mac_control->rings[i].block_count;
  435. }
  436. if (nic->rxd_mode == RXD_MODE_1)
  437. size = (size * (sizeof(RxD1_t)));
  438. else
  439. size = (size * (sizeof(RxD3_t)));
  440. rx_sz = size;
  441. for (i = 0; i < config->rx_ring_num; i++) {
  442. mac_control->rings[i].rx_curr_get_info.block_index = 0;
  443. mac_control->rings[i].rx_curr_get_info.offset = 0;
  444. mac_control->rings[i].rx_curr_get_info.ring_len =
  445. config->rx_cfg[i].num_rxd - 1;
  446. mac_control->rings[i].rx_curr_put_info.block_index = 0;
  447. mac_control->rings[i].rx_curr_put_info.offset = 0;
  448. mac_control->rings[i].rx_curr_put_info.ring_len =
  449. config->rx_cfg[i].num_rxd - 1;
  450. mac_control->rings[i].nic = nic;
  451. mac_control->rings[i].ring_no = i;
  452. blk_cnt = config->rx_cfg[i].num_rxd /
  453. (rxd_count[nic->rxd_mode] + 1);
  454. /* Allocating all the Rx blocks */
  455. for (j = 0; j < blk_cnt; j++) {
  456. rx_block_info_t *rx_blocks;
  457. int l;
  458. rx_blocks = &mac_control->rings[i].rx_blocks[j];
  459. size = SIZE_OF_BLOCK; //size is always page size
  460. tmp_v_addr = pci_alloc_consistent(nic->pdev, size,
  461. &tmp_p_addr);
  462. if (tmp_v_addr == NULL) {
  463. /*
  464. * In case of failure, free_shared_mem()
  465. * is called, which should free any
  466. * memory that was alloced till the
  467. * failure happened.
  468. */
  469. rx_blocks->block_virt_addr = tmp_v_addr;
  470. return -ENOMEM;
  471. }
  472. memset(tmp_v_addr, 0, size);
  473. rx_blocks->block_virt_addr = tmp_v_addr;
  474. rx_blocks->block_dma_addr = tmp_p_addr;
  475. rx_blocks->rxds = kmalloc(sizeof(rxd_info_t)*
  476. rxd_count[nic->rxd_mode],
  477. GFP_KERNEL);
  478. for (l=0; l<rxd_count[nic->rxd_mode];l++) {
  479. rx_blocks->rxds[l].virt_addr =
  480. rx_blocks->block_virt_addr +
  481. (rxd_size[nic->rxd_mode] * l);
  482. rx_blocks->rxds[l].dma_addr =
  483. rx_blocks->block_dma_addr +
  484. (rxd_size[nic->rxd_mode] * l);
  485. }
  486. mac_control->rings[i].rx_blocks[j].block_virt_addr =
  487. tmp_v_addr;
  488. mac_control->rings[i].rx_blocks[j].block_dma_addr =
  489. tmp_p_addr;
  490. }
  491. /* Interlinking all Rx Blocks */
  492. for (j = 0; j < blk_cnt; j++) {
  493. tmp_v_addr =
  494. mac_control->rings[i].rx_blocks[j].block_virt_addr;
  495. tmp_v_addr_next =
  496. mac_control->rings[i].rx_blocks[(j + 1) %
  497. blk_cnt].block_virt_addr;
  498. tmp_p_addr =
  499. mac_control->rings[i].rx_blocks[j].block_dma_addr;
  500. tmp_p_addr_next =
  501. mac_control->rings[i].rx_blocks[(j + 1) %
  502. blk_cnt].block_dma_addr;
  503. pre_rxd_blk = (RxD_block_t *) tmp_v_addr;
  504. pre_rxd_blk->reserved_2_pNext_RxD_block =
  505. (unsigned long) tmp_v_addr_next;
  506. pre_rxd_blk->pNext_RxD_Blk_physical =
  507. (u64) tmp_p_addr_next;
  508. }
  509. }
  510. if (nic->rxd_mode >= RXD_MODE_3A) {
  511. /*
  512. * Allocation of Storages for buffer addresses in 2BUFF mode
  513. * and the buffers as well.
  514. */
  515. for (i = 0; i < config->rx_ring_num; i++) {
  516. blk_cnt = config->rx_cfg[i].num_rxd /
  517. (rxd_count[nic->rxd_mode]+ 1);
  518. mac_control->rings[i].ba =
  519. kmalloc((sizeof(buffAdd_t *) * blk_cnt),
  520. GFP_KERNEL);
  521. if (!mac_control->rings[i].ba)
  522. return -ENOMEM;
  523. for (j = 0; j < blk_cnt; j++) {
  524. int k = 0;
  525. mac_control->rings[i].ba[j] =
  526. kmalloc((sizeof(buffAdd_t) *
  527. (rxd_count[nic->rxd_mode] + 1)),
  528. GFP_KERNEL);
  529. if (!mac_control->rings[i].ba[j])
  530. return -ENOMEM;
  531. while (k != rxd_count[nic->rxd_mode]) {
  532. ba = &mac_control->rings[i].ba[j][k];
  533. ba->ba_0_org = (void *) kmalloc
  534. (BUF0_LEN + ALIGN_SIZE, GFP_KERNEL);
  535. if (!ba->ba_0_org)
  536. return -ENOMEM;
  537. tmp = (unsigned long)ba->ba_0_org;
  538. tmp += ALIGN_SIZE;
  539. tmp &= ~((unsigned long) ALIGN_SIZE);
  540. ba->ba_0 = (void *) tmp;
  541. ba->ba_1_org = (void *) kmalloc
  542. (BUF1_LEN + ALIGN_SIZE, GFP_KERNEL);
  543. if (!ba->ba_1_org)
  544. return -ENOMEM;
  545. tmp = (unsigned long) ba->ba_1_org;
  546. tmp += ALIGN_SIZE;
  547. tmp &= ~((unsigned long) ALIGN_SIZE);
  548. ba->ba_1 = (void *) tmp;
  549. k++;
  550. }
  551. }
  552. }
  553. }
  554. /* Allocation and initialization of Statistics block */
  555. size = sizeof(StatInfo_t);
  556. mac_control->stats_mem = pci_alloc_consistent
  557. (nic->pdev, size, &mac_control->stats_mem_phy);
  558. if (!mac_control->stats_mem) {
  559. /*
  560. * In case of failure, free_shared_mem() is called, which
  561. * should free any memory that was alloced till the
  562. * failure happened.
  563. */
  564. return -ENOMEM;
  565. }
  566. mac_control->stats_mem_sz = size;
  567. tmp_v_addr = mac_control->stats_mem;
  568. mac_control->stats_info = (StatInfo_t *) tmp_v_addr;
  569. memset(tmp_v_addr, 0, size);
  570. DBG_PRINT(INIT_DBG, "%s:Ring Mem PHY: 0x%llx\n", dev->name,
  571. (unsigned long long) tmp_p_addr);
  572. return SUCCESS;
  573. }
  574. /**
  575. * free_shared_mem - Free the allocated Memory
  576. * @nic: Device private variable.
  577. * Description: This function is to free all memory locations allocated by
  578. * the init_shared_mem() function and return it to the kernel.
  579. */
  580. static void free_shared_mem(struct s2io_nic *nic)
  581. {
  582. int i, j, blk_cnt, size;
  583. void *tmp_v_addr;
  584. dma_addr_t tmp_p_addr;
  585. mac_info_t *mac_control;
  586. struct config_param *config;
  587. int lst_size, lst_per_page;
  588. struct net_device *dev = nic->dev;
  589. if (!nic)
  590. return;
  591. mac_control = &nic->mac_control;
  592. config = &nic->config;
  593. lst_size = (sizeof(TxD_t) * config->max_txds);
  594. lst_per_page = PAGE_SIZE / lst_size;
  595. for (i = 0; i < config->tx_fifo_num; i++) {
  596. int page_num = TXD_MEM_PAGE_CNT(config->tx_cfg[i].fifo_len,
  597. lst_per_page);
  598. for (j = 0; j < page_num; j++) {
  599. int mem_blks = (j * lst_per_page);
  600. if (!mac_control->fifos[i].list_info)
  601. return;
  602. if (!mac_control->fifos[i].list_info[mem_blks].
  603. list_virt_addr)
  604. break;
  605. pci_free_consistent(nic->pdev, PAGE_SIZE,
  606. mac_control->fifos[i].
  607. list_info[mem_blks].
  608. list_virt_addr,
  609. mac_control->fifos[i].
  610. list_info[mem_blks].
  611. list_phy_addr);
  612. }
  613. /* If we got a zero DMA address during allocation,
  614. * free the page now
  615. */
  616. if (mac_control->zerodma_virt_addr) {
  617. pci_free_consistent(nic->pdev, PAGE_SIZE,
  618. mac_control->zerodma_virt_addr,
  619. (dma_addr_t)0);
  620. DBG_PRINT(INIT_DBG,
  621. "%s: Freeing TxDL with zero DMA addr. ",
  622. dev->name);
  623. DBG_PRINT(INIT_DBG, "Virtual address %p\n",
  624. mac_control->zerodma_virt_addr);
  625. }
  626. kfree(mac_control->fifos[i].list_info);
  627. }
  628. size = SIZE_OF_BLOCK;
  629. for (i = 0; i < config->rx_ring_num; i++) {
  630. blk_cnt = mac_control->rings[i].block_count;
  631. for (j = 0; j < blk_cnt; j++) {
  632. tmp_v_addr = mac_control->rings[i].rx_blocks[j].
  633. block_virt_addr;
  634. tmp_p_addr = mac_control->rings[i].rx_blocks[j].
  635. block_dma_addr;
  636. if (tmp_v_addr == NULL)
  637. break;
  638. pci_free_consistent(nic->pdev, size,
  639. tmp_v_addr, tmp_p_addr);
  640. kfree(mac_control->rings[i].rx_blocks[j].rxds);
  641. }
  642. }
  643. if (nic->rxd_mode >= RXD_MODE_3A) {
  644. /* Freeing buffer storage addresses in 2BUFF mode. */
  645. for (i = 0; i < config->rx_ring_num; i++) {
  646. blk_cnt = config->rx_cfg[i].num_rxd /
  647. (rxd_count[nic->rxd_mode] + 1);
  648. for (j = 0; j < blk_cnt; j++) {
  649. int k = 0;
  650. if (!mac_control->rings[i].ba[j])
  651. continue;
  652. while (k != rxd_count[nic->rxd_mode]) {
  653. buffAdd_t *ba =
  654. &mac_control->rings[i].ba[j][k];
  655. kfree(ba->ba_0_org);
  656. kfree(ba->ba_1_org);
  657. k++;
  658. }
  659. kfree(mac_control->rings[i].ba[j]);
  660. }
  661. kfree(mac_control->rings[i].ba);
  662. }
  663. }
  664. if (mac_control->stats_mem) {
  665. pci_free_consistent(nic->pdev,
  666. mac_control->stats_mem_sz,
  667. mac_control->stats_mem,
  668. mac_control->stats_mem_phy);
  669. }
  670. }
  671. /**
  672. * s2io_verify_pci_mode -
  673. */
  674. static int s2io_verify_pci_mode(nic_t *nic)
  675. {
  676. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  677. register u64 val64 = 0;
  678. int mode;
  679. val64 = readq(&bar0->pci_mode);
  680. mode = (u8)GET_PCI_MODE(val64);
  681. if ( val64 & PCI_MODE_UNKNOWN_MODE)
  682. return -1; /* Unknown PCI mode */
  683. return mode;
  684. }
  685. /**
  686. * s2io_print_pci_mode -
  687. */
  688. static int s2io_print_pci_mode(nic_t *nic)
  689. {
  690. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  691. register u64 val64 = 0;
  692. int mode;
  693. struct config_param *config = &nic->config;
  694. val64 = readq(&bar0->pci_mode);
  695. mode = (u8)GET_PCI_MODE(val64);
  696. if ( val64 & PCI_MODE_UNKNOWN_MODE)
  697. return -1; /* Unknown PCI mode */
  698. if (val64 & PCI_MODE_32_BITS) {
  699. DBG_PRINT(ERR_DBG, "%s: Device is on 32 bit ", nic->dev->name);
  700. } else {
  701. DBG_PRINT(ERR_DBG, "%s: Device is on 64 bit ", nic->dev->name);
  702. }
  703. switch(mode) {
  704. case PCI_MODE_PCI_33:
  705. DBG_PRINT(ERR_DBG, "33MHz PCI bus\n");
  706. config->bus_speed = 33;
  707. break;
  708. case PCI_MODE_PCI_66:
  709. DBG_PRINT(ERR_DBG, "66MHz PCI bus\n");
  710. config->bus_speed = 133;
  711. break;
  712. case PCI_MODE_PCIX_M1_66:
  713. DBG_PRINT(ERR_DBG, "66MHz PCIX(M1) bus\n");
  714. config->bus_speed = 133; /* Herc doubles the clock rate */
  715. break;
  716. case PCI_MODE_PCIX_M1_100:
  717. DBG_PRINT(ERR_DBG, "100MHz PCIX(M1) bus\n");
  718. config->bus_speed = 200;
  719. break;
  720. case PCI_MODE_PCIX_M1_133:
  721. DBG_PRINT(ERR_DBG, "133MHz PCIX(M1) bus\n");
  722. config->bus_speed = 266;
  723. break;
  724. case PCI_MODE_PCIX_M2_66:
  725. DBG_PRINT(ERR_DBG, "133MHz PCIX(M2) bus\n");
  726. config->bus_speed = 133;
  727. break;
  728. case PCI_MODE_PCIX_M2_100:
  729. DBG_PRINT(ERR_DBG, "200MHz PCIX(M2) bus\n");
  730. config->bus_speed = 200;
  731. break;
  732. case PCI_MODE_PCIX_M2_133:
  733. DBG_PRINT(ERR_DBG, "266MHz PCIX(M2) bus\n");
  734. config->bus_speed = 266;
  735. break;
  736. default:
  737. return -1; /* Unsupported bus speed */
  738. }
  739. return mode;
  740. }
  741. /**
  742. * init_nic - Initialization of hardware
  743. * @nic: device peivate variable
  744. * Description: The function sequentially configures every block
  745. * of the H/W from their reset values.
  746. * Return Value: SUCCESS on success and
  747. * '-1' on failure (endian settings incorrect).
  748. */
  749. static int init_nic(struct s2io_nic *nic)
  750. {
  751. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  752. struct net_device *dev = nic->dev;
  753. register u64 val64 = 0;
  754. void __iomem *add;
  755. u32 time;
  756. int i, j;
  757. mac_info_t *mac_control;
  758. struct config_param *config;
  759. int mdio_cnt = 0, dtx_cnt = 0;
  760. unsigned long long mem_share;
  761. int mem_size;
  762. mac_control = &nic->mac_control;
  763. config = &nic->config;
  764. /* to set the swapper controle on the card */
  765. if(s2io_set_swapper(nic)) {
  766. DBG_PRINT(ERR_DBG,"ERROR: Setting Swapper failed\n");
  767. return -1;
  768. }
  769. /*
  770. * Herc requires EOI to be removed from reset before XGXS, so..
  771. */
  772. if (nic->device_type & XFRAME_II_DEVICE) {
  773. val64 = 0xA500000000ULL;
  774. writeq(val64, &bar0->sw_reset);
  775. msleep(500);
  776. val64 = readq(&bar0->sw_reset);
  777. }
  778. /* Remove XGXS from reset state */
  779. val64 = 0;
  780. writeq(val64, &bar0->sw_reset);
  781. msleep(500);
  782. val64 = readq(&bar0->sw_reset);
  783. /* Enable Receiving broadcasts */
  784. add = &bar0->mac_cfg;
  785. val64 = readq(&bar0->mac_cfg);
  786. val64 |= MAC_RMAC_BCAST_ENABLE;
  787. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  788. writel((u32) val64, add);
  789. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  790. writel((u32) (val64 >> 32), (add + 4));
  791. /* Read registers in all blocks */
  792. val64 = readq(&bar0->mac_int_mask);
  793. val64 = readq(&bar0->mc_int_mask);
  794. val64 = readq(&bar0->xgxs_int_mask);
  795. /* Set MTU */
  796. val64 = dev->mtu;
  797. writeq(vBIT(val64, 2, 14), &bar0->rmac_max_pyld_len);
  798. /*
  799. * Configuring the XAUI Interface of Xena.
  800. * ***************************************
  801. * To Configure the Xena's XAUI, one has to write a series
  802. * of 64 bit values into two registers in a particular
  803. * sequence. Hence a macro 'SWITCH_SIGN' has been defined
  804. * which will be defined in the array of configuration values
  805. * (xena_dtx_cfg & xena_mdio_cfg) at appropriate places
  806. * to switch writing from one regsiter to another. We continue
  807. * writing these values until we encounter the 'END_SIGN' macro.
  808. * For example, After making a series of 21 writes into
  809. * dtx_control register the 'SWITCH_SIGN' appears and hence we
  810. * start writing into mdio_control until we encounter END_SIGN.
  811. */
  812. if (nic->device_type & XFRAME_II_DEVICE) {
  813. while (herc_act_dtx_cfg[dtx_cnt] != END_SIGN) {
  814. SPECIAL_REG_WRITE(herc_act_dtx_cfg[dtx_cnt],
  815. &bar0->dtx_control, UF);
  816. if (dtx_cnt & 0x1)
  817. msleep(1); /* Necessary!! */
  818. dtx_cnt++;
  819. }
  820. } else {
  821. while (1) {
  822. dtx_cfg:
  823. while (xena_dtx_cfg[dtx_cnt] != END_SIGN) {
  824. if (xena_dtx_cfg[dtx_cnt] == SWITCH_SIGN) {
  825. dtx_cnt++;
  826. goto mdio_cfg;
  827. }
  828. SPECIAL_REG_WRITE(xena_dtx_cfg[dtx_cnt],
  829. &bar0->dtx_control, UF);
  830. val64 = readq(&bar0->dtx_control);
  831. dtx_cnt++;
  832. }
  833. mdio_cfg:
  834. while (xena_mdio_cfg[mdio_cnt] != END_SIGN) {
  835. if (xena_mdio_cfg[mdio_cnt] == SWITCH_SIGN) {
  836. mdio_cnt++;
  837. goto dtx_cfg;
  838. }
  839. SPECIAL_REG_WRITE(xena_mdio_cfg[mdio_cnt],
  840. &bar0->mdio_control, UF);
  841. val64 = readq(&bar0->mdio_control);
  842. mdio_cnt++;
  843. }
  844. if ((xena_dtx_cfg[dtx_cnt] == END_SIGN) &&
  845. (xena_mdio_cfg[mdio_cnt] == END_SIGN)) {
  846. break;
  847. } else {
  848. goto dtx_cfg;
  849. }
  850. }
  851. }
  852. /* Tx DMA Initialization */
  853. val64 = 0;
  854. writeq(val64, &bar0->tx_fifo_partition_0);
  855. writeq(val64, &bar0->tx_fifo_partition_1);
  856. writeq(val64, &bar0->tx_fifo_partition_2);
  857. writeq(val64, &bar0->tx_fifo_partition_3);
  858. for (i = 0, j = 0; i < config->tx_fifo_num; i++) {
  859. val64 |=
  860. vBIT(config->tx_cfg[i].fifo_len - 1, ((i * 32) + 19),
  861. 13) | vBIT(config->tx_cfg[i].fifo_priority,
  862. ((i * 32) + 5), 3);
  863. if (i == (config->tx_fifo_num - 1)) {
  864. if (i % 2 == 0)
  865. i++;
  866. }
  867. switch (i) {
  868. case 1:
  869. writeq(val64, &bar0->tx_fifo_partition_0);
  870. val64 = 0;
  871. break;
  872. case 3:
  873. writeq(val64, &bar0->tx_fifo_partition_1);
  874. val64 = 0;
  875. break;
  876. case 5:
  877. writeq(val64, &bar0->tx_fifo_partition_2);
  878. val64 = 0;
  879. break;
  880. case 7:
  881. writeq(val64, &bar0->tx_fifo_partition_3);
  882. break;
  883. }
  884. }
  885. /* Enable Tx FIFO partition 0. */
  886. val64 = readq(&bar0->tx_fifo_partition_0);
  887. val64 |= BIT(0); /* To enable the FIFO partition. */
  888. writeq(val64, &bar0->tx_fifo_partition_0);
  889. /*
  890. * Disable 4 PCCs for Xena1, 2 and 3 as per H/W bug
  891. * SXE-008 TRANSMIT DMA ARBITRATION ISSUE.
  892. */
  893. if ((nic->device_type == XFRAME_I_DEVICE) &&
  894. (get_xena_rev_id(nic->pdev) < 4))
  895. writeq(PCC_ENABLE_FOUR, &bar0->pcc_enable);
  896. val64 = readq(&bar0->tx_fifo_partition_0);
  897. DBG_PRINT(INIT_DBG, "Fifo partition at: 0x%p is: 0x%llx\n",
  898. &bar0->tx_fifo_partition_0, (unsigned long long) val64);
  899. /*
  900. * Initialization of Tx_PA_CONFIG register to ignore packet
  901. * integrity checking.
  902. */
  903. val64 = readq(&bar0->tx_pa_cfg);
  904. val64 |= TX_PA_CFG_IGNORE_FRM_ERR | TX_PA_CFG_IGNORE_SNAP_OUI |
  905. TX_PA_CFG_IGNORE_LLC_CTRL | TX_PA_CFG_IGNORE_L2_ERR;
  906. writeq(val64, &bar0->tx_pa_cfg);
  907. /* Rx DMA intialization. */
  908. val64 = 0;
  909. for (i = 0; i < config->rx_ring_num; i++) {
  910. val64 |=
  911. vBIT(config->rx_cfg[i].ring_priority, (5 + (i * 8)),
  912. 3);
  913. }
  914. writeq(val64, &bar0->rx_queue_priority);
  915. /*
  916. * Allocating equal share of memory to all the
  917. * configured Rings.
  918. */
  919. val64 = 0;
  920. if (nic->device_type & XFRAME_II_DEVICE)
  921. mem_size = 32;
  922. else
  923. mem_size = 64;
  924. for (i = 0; i < config->rx_ring_num; i++) {
  925. switch (i) {
  926. case 0:
  927. mem_share = (mem_size / config->rx_ring_num +
  928. mem_size % config->rx_ring_num);
  929. val64 |= RX_QUEUE_CFG_Q0_SZ(mem_share);
  930. continue;
  931. case 1:
  932. mem_share = (mem_size / config->rx_ring_num);
  933. val64 |= RX_QUEUE_CFG_Q1_SZ(mem_share);
  934. continue;
  935. case 2:
  936. mem_share = (mem_size / config->rx_ring_num);
  937. val64 |= RX_QUEUE_CFG_Q2_SZ(mem_share);
  938. continue;
  939. case 3:
  940. mem_share = (mem_size / config->rx_ring_num);
  941. val64 |= RX_QUEUE_CFG_Q3_SZ(mem_share);
  942. continue;
  943. case 4:
  944. mem_share = (mem_size / config->rx_ring_num);
  945. val64 |= RX_QUEUE_CFG_Q4_SZ(mem_share);
  946. continue;
  947. case 5:
  948. mem_share = (mem_size / config->rx_ring_num);
  949. val64 |= RX_QUEUE_CFG_Q5_SZ(mem_share);
  950. continue;
  951. case 6:
  952. mem_share = (mem_size / config->rx_ring_num);
  953. val64 |= RX_QUEUE_CFG_Q6_SZ(mem_share);
  954. continue;
  955. case 7:
  956. mem_share = (mem_size / config->rx_ring_num);
  957. val64 |= RX_QUEUE_CFG_Q7_SZ(mem_share);
  958. continue;
  959. }
  960. }
  961. writeq(val64, &bar0->rx_queue_cfg);
  962. /*
  963. * Filling Tx round robin registers
  964. * as per the number of FIFOs
  965. */
  966. switch (config->tx_fifo_num) {
  967. case 1:
  968. val64 = 0x0000000000000000ULL;
  969. writeq(val64, &bar0->tx_w_round_robin_0);
  970. writeq(val64, &bar0->tx_w_round_robin_1);
  971. writeq(val64, &bar0->tx_w_round_robin_2);
  972. writeq(val64, &bar0->tx_w_round_robin_3);
  973. writeq(val64, &bar0->tx_w_round_robin_4);
  974. break;
  975. case 2:
  976. val64 = 0x0000010000010000ULL;
  977. writeq(val64, &bar0->tx_w_round_robin_0);
  978. val64 = 0x0100000100000100ULL;
  979. writeq(val64, &bar0->tx_w_round_robin_1);
  980. val64 = 0x0001000001000001ULL;
  981. writeq(val64, &bar0->tx_w_round_robin_2);
  982. val64 = 0x0000010000010000ULL;
  983. writeq(val64, &bar0->tx_w_round_robin_3);
  984. val64 = 0x0100000000000000ULL;
  985. writeq(val64, &bar0->tx_w_round_robin_4);
  986. break;
  987. case 3:
  988. val64 = 0x0001000102000001ULL;
  989. writeq(val64, &bar0->tx_w_round_robin_0);
  990. val64 = 0x0001020000010001ULL;
  991. writeq(val64, &bar0->tx_w_round_robin_1);
  992. val64 = 0x0200000100010200ULL;
  993. writeq(val64, &bar0->tx_w_round_robin_2);
  994. val64 = 0x0001000102000001ULL;
  995. writeq(val64, &bar0->tx_w_round_robin_3);
  996. val64 = 0x0001020000000000ULL;
  997. writeq(val64, &bar0->tx_w_round_robin_4);
  998. break;
  999. case 4:
  1000. val64 = 0x0001020300010200ULL;
  1001. writeq(val64, &bar0->tx_w_round_robin_0);
  1002. val64 = 0x0100000102030001ULL;
  1003. writeq(val64, &bar0->tx_w_round_robin_1);
  1004. val64 = 0x0200010000010203ULL;
  1005. writeq(val64, &bar0->tx_w_round_robin_2);
  1006. val64 = 0x0001020001000001ULL;
  1007. writeq(val64, &bar0->tx_w_round_robin_3);
  1008. val64 = 0x0203000100000000ULL;
  1009. writeq(val64, &bar0->tx_w_round_robin_4);
  1010. break;
  1011. case 5:
  1012. val64 = 0x0001000203000102ULL;
  1013. writeq(val64, &bar0->tx_w_round_robin_0);
  1014. val64 = 0x0001020001030004ULL;
  1015. writeq(val64, &bar0->tx_w_round_robin_1);
  1016. val64 = 0x0001000203000102ULL;
  1017. writeq(val64, &bar0->tx_w_round_robin_2);
  1018. val64 = 0x0001020001030004ULL;
  1019. writeq(val64, &bar0->tx_w_round_robin_3);
  1020. val64 = 0x0001000000000000ULL;
  1021. writeq(val64, &bar0->tx_w_round_robin_4);
  1022. break;
  1023. case 6:
  1024. val64 = 0x0001020304000102ULL;
  1025. writeq(val64, &bar0->tx_w_round_robin_0);
  1026. val64 = 0x0304050001020001ULL;
  1027. writeq(val64, &bar0->tx_w_round_robin_1);
  1028. val64 = 0x0203000100000102ULL;
  1029. writeq(val64, &bar0->tx_w_round_robin_2);
  1030. val64 = 0x0304000102030405ULL;
  1031. writeq(val64, &bar0->tx_w_round_robin_3);
  1032. val64 = 0x0001000200000000ULL;
  1033. writeq(val64, &bar0->tx_w_round_robin_4);
  1034. break;
  1035. case 7:
  1036. val64 = 0x0001020001020300ULL;
  1037. writeq(val64, &bar0->tx_w_round_robin_0);
  1038. val64 = 0x0102030400010203ULL;
  1039. writeq(val64, &bar0->tx_w_round_robin_1);
  1040. val64 = 0x0405060001020001ULL;
  1041. writeq(val64, &bar0->tx_w_round_robin_2);
  1042. val64 = 0x0304050000010200ULL;
  1043. writeq(val64, &bar0->tx_w_round_robin_3);
  1044. val64 = 0x0102030000000000ULL;
  1045. writeq(val64, &bar0->tx_w_round_robin_4);
  1046. break;
  1047. case 8:
  1048. val64 = 0x0001020300040105ULL;
  1049. writeq(val64, &bar0->tx_w_round_robin_0);
  1050. val64 = 0x0200030106000204ULL;
  1051. writeq(val64, &bar0->tx_w_round_robin_1);
  1052. val64 = 0x0103000502010007ULL;
  1053. writeq(val64, &bar0->tx_w_round_robin_2);
  1054. val64 = 0x0304010002060500ULL;
  1055. writeq(val64, &bar0->tx_w_round_robin_3);
  1056. val64 = 0x0103020400000000ULL;
  1057. writeq(val64, &bar0->tx_w_round_robin_4);
  1058. break;
  1059. }
  1060. /* Filling the Rx round robin registers as per the
  1061. * number of Rings and steering based on QoS.
  1062. */
  1063. switch (config->rx_ring_num) {
  1064. case 1:
  1065. val64 = 0x8080808080808080ULL;
  1066. writeq(val64, &bar0->rts_qos_steering);
  1067. break;
  1068. case 2:
  1069. val64 = 0x0000010000010000ULL;
  1070. writeq(val64, &bar0->rx_w_round_robin_0);
  1071. val64 = 0x0100000100000100ULL;
  1072. writeq(val64, &bar0->rx_w_round_robin_1);
  1073. val64 = 0x0001000001000001ULL;
  1074. writeq(val64, &bar0->rx_w_round_robin_2);
  1075. val64 = 0x0000010000010000ULL;
  1076. writeq(val64, &bar0->rx_w_round_robin_3);
  1077. val64 = 0x0100000000000000ULL;
  1078. writeq(val64, &bar0->rx_w_round_robin_4);
  1079. val64 = 0x8080808040404040ULL;
  1080. writeq(val64, &bar0->rts_qos_steering);
  1081. break;
  1082. case 3:
  1083. val64 = 0x0001000102000001ULL;
  1084. writeq(val64, &bar0->rx_w_round_robin_0);
  1085. val64 = 0x0001020000010001ULL;
  1086. writeq(val64, &bar0->rx_w_round_robin_1);
  1087. val64 = 0x0200000100010200ULL;
  1088. writeq(val64, &bar0->rx_w_round_robin_2);
  1089. val64 = 0x0001000102000001ULL;
  1090. writeq(val64, &bar0->rx_w_round_robin_3);
  1091. val64 = 0x0001020000000000ULL;
  1092. writeq(val64, &bar0->rx_w_round_robin_4);
  1093. val64 = 0x8080804040402020ULL;
  1094. writeq(val64, &bar0->rts_qos_steering);
  1095. break;
  1096. case 4:
  1097. val64 = 0x0001020300010200ULL;
  1098. writeq(val64, &bar0->rx_w_round_robin_0);
  1099. val64 = 0x0100000102030001ULL;
  1100. writeq(val64, &bar0->rx_w_round_robin_1);
  1101. val64 = 0x0200010000010203ULL;
  1102. writeq(val64, &bar0->rx_w_round_robin_2);
  1103. val64 = 0x0001020001000001ULL;
  1104. writeq(val64, &bar0->rx_w_round_robin_3);
  1105. val64 = 0x0203000100000000ULL;
  1106. writeq(val64, &bar0->rx_w_round_robin_4);
  1107. val64 = 0x8080404020201010ULL;
  1108. writeq(val64, &bar0->rts_qos_steering);
  1109. break;
  1110. case 5:
  1111. val64 = 0x0001000203000102ULL;
  1112. writeq(val64, &bar0->rx_w_round_robin_0);
  1113. val64 = 0x0001020001030004ULL;
  1114. writeq(val64, &bar0->rx_w_round_robin_1);
  1115. val64 = 0x0001000203000102ULL;
  1116. writeq(val64, &bar0->rx_w_round_robin_2);
  1117. val64 = 0x0001020001030004ULL;
  1118. writeq(val64, &bar0->rx_w_round_robin_3);
  1119. val64 = 0x0001000000000000ULL;
  1120. writeq(val64, &bar0->rx_w_round_robin_4);
  1121. val64 = 0x8080404020201008ULL;
  1122. writeq(val64, &bar0->rts_qos_steering);
  1123. break;
  1124. case 6:
  1125. val64 = 0x0001020304000102ULL;
  1126. writeq(val64, &bar0->rx_w_round_robin_0);
  1127. val64 = 0x0304050001020001ULL;
  1128. writeq(val64, &bar0->rx_w_round_robin_1);
  1129. val64 = 0x0203000100000102ULL;
  1130. writeq(val64, &bar0->rx_w_round_robin_2);
  1131. val64 = 0x0304000102030405ULL;
  1132. writeq(val64, &bar0->rx_w_round_robin_3);
  1133. val64 = 0x0001000200000000ULL;
  1134. writeq(val64, &bar0->rx_w_round_robin_4);
  1135. val64 = 0x8080404020100804ULL;
  1136. writeq(val64, &bar0->rts_qos_steering);
  1137. break;
  1138. case 7:
  1139. val64 = 0x0001020001020300ULL;
  1140. writeq(val64, &bar0->rx_w_round_robin_0);
  1141. val64 = 0x0102030400010203ULL;
  1142. writeq(val64, &bar0->rx_w_round_robin_1);
  1143. val64 = 0x0405060001020001ULL;
  1144. writeq(val64, &bar0->rx_w_round_robin_2);
  1145. val64 = 0x0304050000010200ULL;
  1146. writeq(val64, &bar0->rx_w_round_robin_3);
  1147. val64 = 0x0102030000000000ULL;
  1148. writeq(val64, &bar0->rx_w_round_robin_4);
  1149. val64 = 0x8080402010080402ULL;
  1150. writeq(val64, &bar0->rts_qos_steering);
  1151. break;
  1152. case 8:
  1153. val64 = 0x0001020300040105ULL;
  1154. writeq(val64, &bar0->rx_w_round_robin_0);
  1155. val64 = 0x0200030106000204ULL;
  1156. writeq(val64, &bar0->rx_w_round_robin_1);
  1157. val64 = 0x0103000502010007ULL;
  1158. writeq(val64, &bar0->rx_w_round_robin_2);
  1159. val64 = 0x0304010002060500ULL;
  1160. writeq(val64, &bar0->rx_w_round_robin_3);
  1161. val64 = 0x0103020400000000ULL;
  1162. writeq(val64, &bar0->rx_w_round_robin_4);
  1163. val64 = 0x8040201008040201ULL;
  1164. writeq(val64, &bar0->rts_qos_steering);
  1165. break;
  1166. }
  1167. /* UDP Fix */
  1168. val64 = 0;
  1169. for (i = 0; i < 8; i++)
  1170. writeq(val64, &bar0->rts_frm_len_n[i]);
  1171. /* Set the default rts frame length for the rings configured */
  1172. val64 = MAC_RTS_FRM_LEN_SET(dev->mtu+22);
  1173. for (i = 0 ; i < config->rx_ring_num ; i++)
  1174. writeq(val64, &bar0->rts_frm_len_n[i]);
  1175. /* Set the frame length for the configured rings
  1176. * desired by the user
  1177. */
  1178. for (i = 0; i < config->rx_ring_num; i++) {
  1179. /* If rts_frm_len[i] == 0 then it is assumed that user not
  1180. * specified frame length steering.
  1181. * If the user provides the frame length then program
  1182. * the rts_frm_len register for those values or else
  1183. * leave it as it is.
  1184. */
  1185. if (rts_frm_len[i] != 0) {
  1186. writeq(MAC_RTS_FRM_LEN_SET(rts_frm_len[i]),
  1187. &bar0->rts_frm_len_n[i]);
  1188. }
  1189. }
  1190. /* Program statistics memory */
  1191. writeq(mac_control->stats_mem_phy, &bar0->stat_addr);
  1192. if (nic->device_type == XFRAME_II_DEVICE) {
  1193. val64 = STAT_BC(0x320);
  1194. writeq(val64, &bar0->stat_byte_cnt);
  1195. }
  1196. /*
  1197. * Initializing the sampling rate for the device to calculate the
  1198. * bandwidth utilization.
  1199. */
  1200. val64 = MAC_TX_LINK_UTIL_VAL(tmac_util_period) |
  1201. MAC_RX_LINK_UTIL_VAL(rmac_util_period);
  1202. writeq(val64, &bar0->mac_link_util);
  1203. /*
  1204. * Initializing the Transmit and Receive Traffic Interrupt
  1205. * Scheme.
  1206. */
  1207. /*
  1208. * TTI Initialization. Default Tx timer gets us about
  1209. * 250 interrupts per sec. Continuous interrupts are enabled
  1210. * by default.
  1211. */
  1212. if (nic->device_type == XFRAME_II_DEVICE) {
  1213. int count = (nic->config.bus_speed * 125)/2;
  1214. val64 = TTI_DATA1_MEM_TX_TIMER_VAL(count);
  1215. } else {
  1216. val64 = TTI_DATA1_MEM_TX_TIMER_VAL(0x2078);
  1217. }
  1218. val64 |= TTI_DATA1_MEM_TX_URNG_A(0xA) |
  1219. TTI_DATA1_MEM_TX_URNG_B(0x10) |
  1220. TTI_DATA1_MEM_TX_URNG_C(0x30) | TTI_DATA1_MEM_TX_TIMER_AC_EN;
  1221. if (use_continuous_tx_intrs)
  1222. val64 |= TTI_DATA1_MEM_TX_TIMER_CI_EN;
  1223. writeq(val64, &bar0->tti_data1_mem);
  1224. val64 = TTI_DATA2_MEM_TX_UFC_A(0x10) |
  1225. TTI_DATA2_MEM_TX_UFC_B(0x20) |
  1226. TTI_DATA2_MEM_TX_UFC_C(0x70) | TTI_DATA2_MEM_TX_UFC_D(0x80);
  1227. writeq(val64, &bar0->tti_data2_mem);
  1228. val64 = TTI_CMD_MEM_WE | TTI_CMD_MEM_STROBE_NEW_CMD;
  1229. writeq(val64, &bar0->tti_command_mem);
  1230. /*
  1231. * Once the operation completes, the Strobe bit of the command
  1232. * register will be reset. We poll for this particular condition
  1233. * We wait for a maximum of 500ms for the operation to complete,
  1234. * if it's not complete by then we return error.
  1235. */
  1236. time = 0;
  1237. while (TRUE) {
  1238. val64 = readq(&bar0->tti_command_mem);
  1239. if (!(val64 & TTI_CMD_MEM_STROBE_NEW_CMD)) {
  1240. break;
  1241. }
  1242. if (time > 10) {
  1243. DBG_PRINT(ERR_DBG, "%s: TTI init Failed\n",
  1244. dev->name);
  1245. return -1;
  1246. }
  1247. msleep(50);
  1248. time++;
  1249. }
  1250. if (nic->config.bimodal) {
  1251. int k = 0;
  1252. for (k = 0; k < config->rx_ring_num; k++) {
  1253. val64 = TTI_CMD_MEM_WE | TTI_CMD_MEM_STROBE_NEW_CMD;
  1254. val64 |= TTI_CMD_MEM_OFFSET(0x38+k);
  1255. writeq(val64, &bar0->tti_command_mem);
  1256. /*
  1257. * Once the operation completes, the Strobe bit of the command
  1258. * register will be reset. We poll for this particular condition
  1259. * We wait for a maximum of 500ms for the operation to complete,
  1260. * if it's not complete by then we return error.
  1261. */
  1262. time = 0;
  1263. while (TRUE) {
  1264. val64 = readq(&bar0->tti_command_mem);
  1265. if (!(val64 & TTI_CMD_MEM_STROBE_NEW_CMD)) {
  1266. break;
  1267. }
  1268. if (time > 10) {
  1269. DBG_PRINT(ERR_DBG,
  1270. "%s: TTI init Failed\n",
  1271. dev->name);
  1272. return -1;
  1273. }
  1274. time++;
  1275. msleep(50);
  1276. }
  1277. }
  1278. } else {
  1279. /* RTI Initialization */
  1280. if (nic->device_type == XFRAME_II_DEVICE) {
  1281. /*
  1282. * Programmed to generate Apprx 500 Intrs per
  1283. * second
  1284. */
  1285. int count = (nic->config.bus_speed * 125)/4;
  1286. val64 = RTI_DATA1_MEM_RX_TIMER_VAL(count);
  1287. } else {
  1288. val64 = RTI_DATA1_MEM_RX_TIMER_VAL(0xFFF);
  1289. }
  1290. val64 |= RTI_DATA1_MEM_RX_URNG_A(0xA) |
  1291. RTI_DATA1_MEM_RX_URNG_B(0x10) |
  1292. RTI_DATA1_MEM_RX_URNG_C(0x30) | RTI_DATA1_MEM_RX_TIMER_AC_EN;
  1293. writeq(val64, &bar0->rti_data1_mem);
  1294. val64 = RTI_DATA2_MEM_RX_UFC_A(0x1) |
  1295. RTI_DATA2_MEM_RX_UFC_B(0x2) ;
  1296. if (nic->intr_type == MSI_X)
  1297. val64 |= (RTI_DATA2_MEM_RX_UFC_C(0x20) | \
  1298. RTI_DATA2_MEM_RX_UFC_D(0x40));
  1299. else
  1300. val64 |= (RTI_DATA2_MEM_RX_UFC_C(0x40) | \
  1301. RTI_DATA2_MEM_RX_UFC_D(0x80));
  1302. writeq(val64, &bar0->rti_data2_mem);
  1303. for (i = 0; i < config->rx_ring_num; i++) {
  1304. val64 = RTI_CMD_MEM_WE | RTI_CMD_MEM_STROBE_NEW_CMD
  1305. | RTI_CMD_MEM_OFFSET(i);
  1306. writeq(val64, &bar0->rti_command_mem);
  1307. /*
  1308. * Once the operation completes, the Strobe bit of the
  1309. * command register will be reset. We poll for this
  1310. * particular condition. We wait for a maximum of 500ms
  1311. * for the operation to complete, if it's not complete
  1312. * by then we return error.
  1313. */
  1314. time = 0;
  1315. while (TRUE) {
  1316. val64 = readq(&bar0->rti_command_mem);
  1317. if (!(val64 & RTI_CMD_MEM_STROBE_NEW_CMD)) {
  1318. break;
  1319. }
  1320. if (time > 10) {
  1321. DBG_PRINT(ERR_DBG, "%s: RTI init Failed\n",
  1322. dev->name);
  1323. return -1;
  1324. }
  1325. time++;
  1326. msleep(50);
  1327. }
  1328. }
  1329. }
  1330. /*
  1331. * Initializing proper values as Pause threshold into all
  1332. * the 8 Queues on Rx side.
  1333. */
  1334. writeq(0xffbbffbbffbbffbbULL, &bar0->mc_pause_thresh_q0q3);
  1335. writeq(0xffbbffbbffbbffbbULL, &bar0->mc_pause_thresh_q4q7);
  1336. /* Disable RMAC PAD STRIPPING */
  1337. add = &bar0->mac_cfg;
  1338. val64 = readq(&bar0->mac_cfg);
  1339. val64 &= ~(MAC_CFG_RMAC_STRIP_PAD);
  1340. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  1341. writel((u32) (val64), add);
  1342. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  1343. writel((u32) (val64 >> 32), (add + 4));
  1344. val64 = readq(&bar0->mac_cfg);
  1345. /*
  1346. * Set the time value to be inserted in the pause frame
  1347. * generated by xena.
  1348. */
  1349. val64 = readq(&bar0->rmac_pause_cfg);
  1350. val64 &= ~(RMAC_PAUSE_HG_PTIME(0xffff));
  1351. val64 |= RMAC_PAUSE_HG_PTIME(nic->mac_control.rmac_pause_time);
  1352. writeq(val64, &bar0->rmac_pause_cfg);
  1353. /*
  1354. * Set the Threshold Limit for Generating the pause frame
  1355. * If the amount of data in any Queue exceeds ratio of
  1356. * (mac_control.mc_pause_threshold_q0q3 or q4q7)/256
  1357. * pause frame is generated
  1358. */
  1359. val64 = 0;
  1360. for (i = 0; i < 4; i++) {
  1361. val64 |=
  1362. (((u64) 0xFF00 | nic->mac_control.
  1363. mc_pause_threshold_q0q3)
  1364. << (i * 2 * 8));
  1365. }
  1366. writeq(val64, &bar0->mc_pause_thresh_q0q3);
  1367. val64 = 0;
  1368. for (i = 0; i < 4; i++) {
  1369. val64 |=
  1370. (((u64) 0xFF00 | nic->mac_control.
  1371. mc_pause_threshold_q4q7)
  1372. << (i * 2 * 8));
  1373. }
  1374. writeq(val64, &bar0->mc_pause_thresh_q4q7);
  1375. /*
  1376. * TxDMA will stop Read request if the number of read split has
  1377. * exceeded the limit pointed by shared_splits
  1378. */
  1379. val64 = readq(&bar0->pic_control);
  1380. val64 |= PIC_CNTL_SHARED_SPLITS(shared_splits);
  1381. writeq(val64, &bar0->pic_control);
  1382. /*
  1383. * Programming the Herc to split every write transaction
  1384. * that does not start on an ADB to reduce disconnects.
  1385. */
  1386. if (nic->device_type == XFRAME_II_DEVICE) {
  1387. val64 = WREQ_SPLIT_MASK_SET_MASK(255);
  1388. writeq(val64, &bar0->wreq_split_mask);
  1389. }
  1390. /* Setting Link stability period to 64 ms */
  1391. if (nic->device_type == XFRAME_II_DEVICE) {
  1392. val64 = MISC_LINK_STABILITY_PRD(3);
  1393. writeq(val64, &bar0->misc_control);
  1394. }
  1395. return SUCCESS;
  1396. }
  1397. #define LINK_UP_DOWN_INTERRUPT 1
  1398. #define MAC_RMAC_ERR_TIMER 2
  1399. static int s2io_link_fault_indication(nic_t *nic)
  1400. {
  1401. if (nic->intr_type != INTA)
  1402. return MAC_RMAC_ERR_TIMER;
  1403. if (nic->device_type == XFRAME_II_DEVICE)
  1404. return LINK_UP_DOWN_INTERRUPT;
  1405. else
  1406. return MAC_RMAC_ERR_TIMER;
  1407. }
  1408. /**
  1409. * en_dis_able_nic_intrs - Enable or Disable the interrupts
  1410. * @nic: device private variable,
  1411. * @mask: A mask indicating which Intr block must be modified and,
  1412. * @flag: A flag indicating whether to enable or disable the Intrs.
  1413. * Description: This function will either disable or enable the interrupts
  1414. * depending on the flag argument. The mask argument can be used to
  1415. * enable/disable any Intr block.
  1416. * Return Value: NONE.
  1417. */
  1418. static void en_dis_able_nic_intrs(struct s2io_nic *nic, u16 mask, int flag)
  1419. {
  1420. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  1421. register u64 val64 = 0, temp64 = 0;
  1422. /* Top level interrupt classification */
  1423. /* PIC Interrupts */
  1424. if ((mask & (TX_PIC_INTR | RX_PIC_INTR))) {
  1425. /* Enable PIC Intrs in the general intr mask register */
  1426. val64 = TXPIC_INT_M | PIC_RX_INT_M;
  1427. if (flag == ENABLE_INTRS) {
  1428. temp64 = readq(&bar0->general_int_mask);
  1429. temp64 &= ~((u64) val64);
  1430. writeq(temp64, &bar0->general_int_mask);
  1431. /*
  1432. * If Hercules adapter enable GPIO otherwise
  1433. * disabled all PCIX, Flash, MDIO, IIC and GPIO
  1434. * interrupts for now.
  1435. * TODO
  1436. */
  1437. if (s2io_link_fault_indication(nic) ==
  1438. LINK_UP_DOWN_INTERRUPT ) {
  1439. temp64 = readq(&bar0->pic_int_mask);
  1440. temp64 &= ~((u64) PIC_INT_GPIO);
  1441. writeq(temp64, &bar0->pic_int_mask);
  1442. temp64 = readq(&bar0->gpio_int_mask);
  1443. temp64 &= ~((u64) GPIO_INT_MASK_LINK_UP);
  1444. writeq(temp64, &bar0->gpio_int_mask);
  1445. } else {
  1446. writeq(DISABLE_ALL_INTRS, &bar0->pic_int_mask);
  1447. }
  1448. /*
  1449. * No MSI Support is available presently, so TTI and
  1450. * RTI interrupts are also disabled.
  1451. */
  1452. } else if (flag == DISABLE_INTRS) {
  1453. /*
  1454. * Disable PIC Intrs in the general
  1455. * intr mask register
  1456. */
  1457. writeq(DISABLE_ALL_INTRS, &bar0->pic_int_mask);
  1458. temp64 = readq(&bar0->general_int_mask);
  1459. val64 |= temp64;
  1460. writeq(val64, &bar0->general_int_mask);
  1461. }
  1462. }
  1463. /* DMA Interrupts */
  1464. /* Enabling/Disabling Tx DMA interrupts */
  1465. if (mask & TX_DMA_INTR) {
  1466. /* Enable TxDMA Intrs in the general intr mask register */
  1467. val64 = TXDMA_INT_M;
  1468. if (flag == ENABLE_INTRS) {
  1469. temp64 = readq(&bar0->general_int_mask);
  1470. temp64 &= ~((u64) val64);
  1471. writeq(temp64, &bar0->general_int_mask);
  1472. /*
  1473. * Keep all interrupts other than PFC interrupt
  1474. * and PCC interrupt disabled in DMA level.
  1475. */
  1476. val64 = DISABLE_ALL_INTRS & ~(TXDMA_PFC_INT_M |
  1477. TXDMA_PCC_INT_M);
  1478. writeq(val64, &bar0->txdma_int_mask);
  1479. /*
  1480. * Enable only the MISC error 1 interrupt in PFC block
  1481. */
  1482. val64 = DISABLE_ALL_INTRS & (~PFC_MISC_ERR_1);
  1483. writeq(val64, &bar0->pfc_err_mask);
  1484. /*
  1485. * Enable only the FB_ECC error interrupt in PCC block
  1486. */
  1487. val64 = DISABLE_ALL_INTRS & (~PCC_FB_ECC_ERR);
  1488. writeq(val64, &bar0->pcc_err_mask);
  1489. } else if (flag == DISABLE_INTRS) {
  1490. /*
  1491. * Disable TxDMA Intrs in the general intr mask
  1492. * register
  1493. */
  1494. writeq(DISABLE_ALL_INTRS, &bar0->txdma_int_mask);
  1495. writeq(DISABLE_ALL_INTRS, &bar0->pfc_err_mask);
  1496. temp64 = readq(&bar0->general_int_mask);
  1497. val64 |= temp64;
  1498. writeq(val64, &bar0->general_int_mask);
  1499. }
  1500. }
  1501. /* Enabling/Disabling Rx DMA interrupts */
  1502. if (mask & RX_DMA_INTR) {
  1503. /* Enable RxDMA Intrs in the general intr mask register */
  1504. val64 = RXDMA_INT_M;
  1505. if (flag == ENABLE_INTRS) {
  1506. temp64 = readq(&bar0->general_int_mask);
  1507. temp64 &= ~((u64) val64);
  1508. writeq(temp64, &bar0->general_int_mask);
  1509. /*
  1510. * All RxDMA block interrupts are disabled for now
  1511. * TODO
  1512. */
  1513. writeq(DISABLE_ALL_INTRS, &bar0->rxdma_int_mask);
  1514. } else if (flag == DISABLE_INTRS) {
  1515. /*
  1516. * Disable RxDMA Intrs in the general intr mask
  1517. * register
  1518. */
  1519. writeq(DISABLE_ALL_INTRS, &bar0->rxdma_int_mask);
  1520. temp64 = readq(&bar0->general_int_mask);
  1521. val64 |= temp64;
  1522. writeq(val64, &bar0->general_int_mask);
  1523. }
  1524. }
  1525. /* MAC Interrupts */
  1526. /* Enabling/Disabling MAC interrupts */
  1527. if (mask & (TX_MAC_INTR | RX_MAC_INTR)) {
  1528. val64 = TXMAC_INT_M | RXMAC_INT_M;
  1529. if (flag == ENABLE_INTRS) {
  1530. temp64 = readq(&bar0->general_int_mask);
  1531. temp64 &= ~((u64) val64);
  1532. writeq(temp64, &bar0->general_int_mask);
  1533. /*
  1534. * All MAC block error interrupts are disabled for now
  1535. * TODO
  1536. */
  1537. } else if (flag == DISABLE_INTRS) {
  1538. /*
  1539. * Disable MAC Intrs in the general intr mask register
  1540. */
  1541. writeq(DISABLE_ALL_INTRS, &bar0->mac_int_mask);
  1542. writeq(DISABLE_ALL_INTRS,
  1543. &bar0->mac_rmac_err_mask);
  1544. temp64 = readq(&bar0->general_int_mask);
  1545. val64 |= temp64;
  1546. writeq(val64, &bar0->general_int_mask);
  1547. }
  1548. }
  1549. /* XGXS Interrupts */
  1550. if (mask & (TX_XGXS_INTR | RX_XGXS_INTR)) {
  1551. val64 = TXXGXS_INT_M | RXXGXS_INT_M;
  1552. if (flag == ENABLE_INTRS) {
  1553. temp64 = readq(&bar0->general_int_mask);
  1554. temp64 &= ~((u64) val64);
  1555. writeq(temp64, &bar0->general_int_mask);
  1556. /*
  1557. * All XGXS block error interrupts are disabled for now
  1558. * TODO
  1559. */
  1560. writeq(DISABLE_ALL_INTRS, &bar0->xgxs_int_mask);
  1561. } else if (flag == DISABLE_INTRS) {
  1562. /*
  1563. * Disable MC Intrs in the general intr mask register
  1564. */
  1565. writeq(DISABLE_ALL_INTRS, &bar0->xgxs_int_mask);
  1566. temp64 = readq(&bar0->general_int_mask);
  1567. val64 |= temp64;
  1568. writeq(val64, &bar0->general_int_mask);
  1569. }
  1570. }
  1571. /* Memory Controller(MC) interrupts */
  1572. if (mask & MC_INTR) {
  1573. val64 = MC_INT_M;
  1574. if (flag == ENABLE_INTRS) {
  1575. temp64 = readq(&bar0->general_int_mask);
  1576. temp64 &= ~((u64) val64);
  1577. writeq(temp64, &bar0->general_int_mask);
  1578. /*
  1579. * Enable all MC Intrs.
  1580. */
  1581. writeq(0x0, &bar0->mc_int_mask);
  1582. writeq(0x0, &bar0->mc_err_mask);
  1583. } else if (flag == DISABLE_INTRS) {
  1584. /*
  1585. * Disable MC Intrs in the general intr mask register
  1586. */
  1587. writeq(DISABLE_ALL_INTRS, &bar0->mc_int_mask);
  1588. temp64 = readq(&bar0->general_int_mask);
  1589. val64 |= temp64;
  1590. writeq(val64, &bar0->general_int_mask);
  1591. }
  1592. }
  1593. /* Tx traffic interrupts */
  1594. if (mask & TX_TRAFFIC_INTR) {
  1595. val64 = TXTRAFFIC_INT_M;
  1596. if (flag == ENABLE_INTRS) {
  1597. temp64 = readq(&bar0->general_int_mask);
  1598. temp64 &= ~((u64) val64);
  1599. writeq(temp64, &bar0->general_int_mask);
  1600. /*
  1601. * Enable all the Tx side interrupts
  1602. * writing 0 Enables all 64 TX interrupt levels
  1603. */
  1604. writeq(0x0, &bar0->tx_traffic_mask);
  1605. } else if (flag == DISABLE_INTRS) {
  1606. /*
  1607. * Disable Tx Traffic Intrs in the general intr mask
  1608. * register.
  1609. */
  1610. writeq(DISABLE_ALL_INTRS, &bar0->tx_traffic_mask);
  1611. temp64 = readq(&bar0->general_int_mask);
  1612. val64 |= temp64;
  1613. writeq(val64, &bar0->general_int_mask);
  1614. }
  1615. }
  1616. /* Rx traffic interrupts */
  1617. if (mask & RX_TRAFFIC_INTR) {
  1618. val64 = RXTRAFFIC_INT_M;
  1619. if (flag == ENABLE_INTRS) {
  1620. temp64 = readq(&bar0->general_int_mask);
  1621. temp64 &= ~((u64) val64);
  1622. writeq(temp64, &bar0->general_int_mask);
  1623. /* writing 0 Enables all 8 RX interrupt levels */
  1624. writeq(0x0, &bar0->rx_traffic_mask);
  1625. } else if (flag == DISABLE_INTRS) {
  1626. /*
  1627. * Disable Rx Traffic Intrs in the general intr mask
  1628. * register.
  1629. */
  1630. writeq(DISABLE_ALL_INTRS, &bar0->rx_traffic_mask);
  1631. temp64 = readq(&bar0->general_int_mask);
  1632. val64 |= temp64;
  1633. writeq(val64, &bar0->general_int_mask);
  1634. }
  1635. }
  1636. }
  1637. static int check_prc_pcc_state(u64 val64, int flag, int rev_id, int herc)
  1638. {
  1639. int ret = 0;
  1640. if (flag == FALSE) {
  1641. if ((!herc && (rev_id >= 4)) || herc) {
  1642. if (!(val64 & ADAPTER_STATUS_RMAC_PCC_IDLE) &&
  1643. ((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
  1644. ADAPTER_STATUS_RC_PRC_QUIESCENT)) {
  1645. ret = 1;
  1646. }
  1647. }else {
  1648. if (!(val64 & ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE) &&
  1649. ((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
  1650. ADAPTER_STATUS_RC_PRC_QUIESCENT)) {
  1651. ret = 1;
  1652. }
  1653. }
  1654. } else {
  1655. if ((!herc && (rev_id >= 4)) || herc) {
  1656. if (((val64 & ADAPTER_STATUS_RMAC_PCC_IDLE) ==
  1657. ADAPTER_STATUS_RMAC_PCC_IDLE) &&
  1658. (!(val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ||
  1659. ((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
  1660. ADAPTER_STATUS_RC_PRC_QUIESCENT))) {
  1661. ret = 1;
  1662. }
  1663. } else {
  1664. if (((val64 & ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE) ==
  1665. ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE) &&
  1666. (!(val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ||
  1667. ((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
  1668. ADAPTER_STATUS_RC_PRC_QUIESCENT))) {
  1669. ret = 1;
  1670. }
  1671. }
  1672. }
  1673. return ret;
  1674. }
  1675. /**
  1676. * verify_xena_quiescence - Checks whether the H/W is ready
  1677. * @val64 : Value read from adapter status register.
  1678. * @flag : indicates if the adapter enable bit was ever written once
  1679. * before.
  1680. * Description: Returns whether the H/W is ready to go or not. Depending
  1681. * on whether adapter enable bit was written or not the comparison
  1682. * differs and the calling function passes the input argument flag to
  1683. * indicate this.
  1684. * Return: 1 If xena is quiescence
  1685. * 0 If Xena is not quiescence
  1686. */
  1687. static int verify_xena_quiescence(nic_t *sp, u64 val64, int flag)
  1688. {
  1689. int ret = 0, herc;
  1690. u64 tmp64 = ~((u64) val64);
  1691. int rev_id = get_xena_rev_id(sp->pdev);
  1692. herc = (sp->device_type == XFRAME_II_DEVICE);
  1693. if (!
  1694. (tmp64 &
  1695. (ADAPTER_STATUS_TDMA_READY | ADAPTER_STATUS_RDMA_READY |
  1696. ADAPTER_STATUS_PFC_READY | ADAPTER_STATUS_TMAC_BUF_EMPTY |
  1697. ADAPTER_STATUS_PIC_QUIESCENT | ADAPTER_STATUS_MC_DRAM_READY |
  1698. ADAPTER_STATUS_MC_QUEUES_READY | ADAPTER_STATUS_M_PLL_LOCK |
  1699. ADAPTER_STATUS_P_PLL_LOCK))) {
  1700. ret = check_prc_pcc_state(val64, flag, rev_id, herc);
  1701. }
  1702. return ret;
  1703. }
  1704. /**
  1705. * fix_mac_address - Fix for Mac addr problem on Alpha platforms
  1706. * @sp: Pointer to device specifc structure
  1707. * Description :
  1708. * New procedure to clear mac address reading problems on Alpha platforms
  1709. *
  1710. */
  1711. static void fix_mac_address(nic_t * sp)
  1712. {
  1713. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  1714. u64 val64;
  1715. int i = 0;
  1716. while (fix_mac[i] != END_SIGN) {
  1717. writeq(fix_mac[i++], &bar0->gpio_control);
  1718. udelay(10);
  1719. val64 = readq(&bar0->gpio_control);
  1720. }
  1721. }
  1722. /**
  1723. * start_nic - Turns the device on
  1724. * @nic : device private variable.
  1725. * Description:
  1726. * This function actually turns the device on. Before this function is
  1727. * called,all Registers are configured from their reset states
  1728. * and shared memory is allocated but the NIC is still quiescent. On
  1729. * calling this function, the device interrupts are cleared and the NIC is
  1730. * literally switched on by writing into the adapter control register.
  1731. * Return Value:
  1732. * SUCCESS on success and -1 on failure.
  1733. */
  1734. static int start_nic(struct s2io_nic *nic)
  1735. {
  1736. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  1737. struct net_device *dev = nic->dev;
  1738. register u64 val64 = 0;
  1739. u16 interruptible;
  1740. u16 subid, i;
  1741. mac_info_t *mac_control;
  1742. struct config_param *config;
  1743. mac_control = &nic->mac_control;
  1744. config = &nic->config;
  1745. /* PRC Initialization and configuration */
  1746. for (i = 0; i < config->rx_ring_num; i++) {
  1747. writeq((u64) mac_control->rings[i].rx_blocks[0].block_dma_addr,
  1748. &bar0->prc_rxd0_n[i]);
  1749. val64 = readq(&bar0->prc_ctrl_n[i]);
  1750. if (nic->config.bimodal)
  1751. val64 |= PRC_CTRL_BIMODAL_INTERRUPT;
  1752. if (nic->rxd_mode == RXD_MODE_1)
  1753. val64 |= PRC_CTRL_RC_ENABLED;
  1754. else
  1755. val64 |= PRC_CTRL_RC_ENABLED | PRC_CTRL_RING_MODE_3;
  1756. writeq(val64, &bar0->prc_ctrl_n[i]);
  1757. }
  1758. if (nic->rxd_mode == RXD_MODE_3B) {
  1759. /* Enabling 2 buffer mode by writing into Rx_pa_cfg reg. */
  1760. val64 = readq(&bar0->rx_pa_cfg);
  1761. val64 |= RX_PA_CFG_IGNORE_L2_ERR;
  1762. writeq(val64, &bar0->rx_pa_cfg);
  1763. }
  1764. /*
  1765. * Enabling MC-RLDRAM. After enabling the device, we timeout
  1766. * for around 100ms, which is approximately the time required
  1767. * for the device to be ready for operation.
  1768. */
  1769. val64 = readq(&bar0->mc_rldram_mrs);
  1770. val64 |= MC_RLDRAM_QUEUE_SIZE_ENABLE | MC_RLDRAM_MRS_ENABLE;
  1771. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
  1772. val64 = readq(&bar0->mc_rldram_mrs);
  1773. msleep(100); /* Delay by around 100 ms. */
  1774. /* Enabling ECC Protection. */
  1775. val64 = readq(&bar0->adapter_control);
  1776. val64 &= ~ADAPTER_ECC_EN;
  1777. writeq(val64, &bar0->adapter_control);
  1778. /*
  1779. * Clearing any possible Link state change interrupts that
  1780. * could have popped up just before Enabling the card.
  1781. */
  1782. val64 = readq(&bar0->mac_rmac_err_reg);
  1783. if (val64)
  1784. writeq(val64, &bar0->mac_rmac_err_reg);
  1785. /*
  1786. * Verify if the device is ready to be enabled, if so enable
  1787. * it.
  1788. */
  1789. val64 = readq(&bar0->adapter_status);
  1790. if (!verify_xena_quiescence(nic, val64, nic->device_enabled_once)) {
  1791. DBG_PRINT(ERR_DBG, "%s: device is not ready, ", dev->name);
  1792. DBG_PRINT(ERR_DBG, "Adapter status reads: 0x%llx\n",
  1793. (unsigned long long) val64);
  1794. return FAILURE;
  1795. }
  1796. /* Enable select interrupts */
  1797. if (nic->intr_type != INTA)
  1798. en_dis_able_nic_intrs(nic, ENA_ALL_INTRS, DISABLE_INTRS);
  1799. else {
  1800. interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR;
  1801. interruptible |= TX_PIC_INTR | RX_PIC_INTR;
  1802. interruptible |= TX_MAC_INTR | RX_MAC_INTR;
  1803. en_dis_able_nic_intrs(nic, interruptible, ENABLE_INTRS);
  1804. }
  1805. /*
  1806. * With some switches, link might be already up at this point.
  1807. * Because of this weird behavior, when we enable laser,
  1808. * we may not get link. We need to handle this. We cannot
  1809. * figure out which switch is misbehaving. So we are forced to
  1810. * make a global change.
  1811. */
  1812. /* Enabling Laser. */
  1813. val64 = readq(&bar0->adapter_control);
  1814. val64 |= ADAPTER_EOI_TX_ON;
  1815. writeq(val64, &bar0->adapter_control);
  1816. /* SXE-002: Initialize link and activity LED */
  1817. subid = nic->pdev->subsystem_device;
  1818. if (((subid & 0xFF) >= 0x07) &&
  1819. (nic->device_type == XFRAME_I_DEVICE)) {
  1820. val64 = readq(&bar0->gpio_control);
  1821. val64 |= 0x0000800000000000ULL;
  1822. writeq(val64, &bar0->gpio_control);
  1823. val64 = 0x0411040400000000ULL;
  1824. writeq(val64, (void __iomem *)bar0 + 0x2700);
  1825. }
  1826. /*
  1827. * Don't see link state interrupts on certain switches, so
  1828. * directly scheduling a link state task from here.
  1829. */
  1830. schedule_work(&nic->set_link_task);
  1831. return SUCCESS;
  1832. }
  1833. /**
  1834. * free_tx_buffers - Free all queued Tx buffers
  1835. * @nic : device private variable.
  1836. * Description:
  1837. * Free all queued Tx buffers.
  1838. * Return Value: void
  1839. */
  1840. static void free_tx_buffers(struct s2io_nic *nic)
  1841. {
  1842. struct net_device *dev = nic->dev;
  1843. struct sk_buff *skb;
  1844. TxD_t *txdp;
  1845. int i, j;
  1846. mac_info_t *mac_control;
  1847. struct config_param *config;
  1848. int cnt = 0, frg_cnt;
  1849. mac_control = &nic->mac_control;
  1850. config = &nic->config;
  1851. for (i = 0; i < config->tx_fifo_num; i++) {
  1852. for (j = 0; j < config->tx_cfg[i].fifo_len - 1; j++) {
  1853. txdp = (TxD_t *) mac_control->fifos[i].list_info[j].
  1854. list_virt_addr;
  1855. skb =
  1856. (struct sk_buff *) ((unsigned long) txdp->
  1857. Host_Control);
  1858. if (skb == NULL) {
  1859. memset(txdp, 0, sizeof(TxD_t) *
  1860. config->max_txds);
  1861. continue;
  1862. }
  1863. frg_cnt = skb_shinfo(skb)->nr_frags;
  1864. pci_unmap_single(nic->pdev, (dma_addr_t)
  1865. txdp->Buffer_Pointer,
  1866. skb->len - skb->data_len,
  1867. PCI_DMA_TODEVICE);
  1868. if (frg_cnt) {
  1869. TxD_t *temp;
  1870. temp = txdp;
  1871. txdp++;
  1872. for (j = 0; j < frg_cnt; j++, txdp++) {
  1873. skb_frag_t *frag =
  1874. &skb_shinfo(skb)->frags[j];
  1875. pci_unmap_page(nic->pdev,
  1876. (dma_addr_t)
  1877. txdp->
  1878. Buffer_Pointer,
  1879. frag->size,
  1880. PCI_DMA_TODEVICE);
  1881. }
  1882. txdp = temp;
  1883. }
  1884. dev_kfree_skb(skb);
  1885. memset(txdp, 0, sizeof(TxD_t) * config->max_txds);
  1886. cnt++;
  1887. }
  1888. DBG_PRINT(INTR_DBG,
  1889. "%s:forcibly freeing %d skbs on FIFO%d\n",
  1890. dev->name, cnt, i);
  1891. mac_control->fifos[i].tx_curr_get_info.offset = 0;
  1892. mac_control->fifos[i].tx_curr_put_info.offset = 0;
  1893. }
  1894. }
  1895. /**
  1896. * stop_nic - To stop the nic
  1897. * @nic ; device private variable.
  1898. * Description:
  1899. * This function does exactly the opposite of what the start_nic()
  1900. * function does. This function is called to stop the device.
  1901. * Return Value:
  1902. * void.
  1903. */
  1904. static void stop_nic(struct s2io_nic *nic)
  1905. {
  1906. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  1907. register u64 val64 = 0;
  1908. u16 interruptible, i;
  1909. mac_info_t *mac_control;
  1910. struct config_param *config;
  1911. mac_control = &nic->mac_control;
  1912. config = &nic->config;
  1913. /* Disable all interrupts */
  1914. interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR;
  1915. interruptible |= TX_PIC_INTR | RX_PIC_INTR;
  1916. interruptible |= TX_MAC_INTR | RX_MAC_INTR;
  1917. en_dis_able_nic_intrs(nic, interruptible, DISABLE_INTRS);
  1918. /* Disable PRCs */
  1919. for (i = 0; i < config->rx_ring_num; i++) {
  1920. val64 = readq(&bar0->prc_ctrl_n[i]);
  1921. val64 &= ~((u64) PRC_CTRL_RC_ENABLED);
  1922. writeq(val64, &bar0->prc_ctrl_n[i]);
  1923. }
  1924. }
  1925. int fill_rxd_3buf(nic_t *nic, RxD_t *rxdp, struct sk_buff *skb)
  1926. {
  1927. struct net_device *dev = nic->dev;
  1928. struct sk_buff *frag_list;
  1929. void *tmp;
  1930. /* Buffer-1 receives L3/L4 headers */
  1931. ((RxD3_t*)rxdp)->Buffer1_ptr = pci_map_single
  1932. (nic->pdev, skb->data, l3l4hdr_size + 4,
  1933. PCI_DMA_FROMDEVICE);
  1934. /* skb_shinfo(skb)->frag_list will have L4 data payload */
  1935. skb_shinfo(skb)->frag_list = dev_alloc_skb(dev->mtu + ALIGN_SIZE);
  1936. if (skb_shinfo(skb)->frag_list == NULL) {
  1937. DBG_PRINT(ERR_DBG, "%s: dev_alloc_skb failed\n ", dev->name);
  1938. return -ENOMEM ;
  1939. }
  1940. frag_list = skb_shinfo(skb)->frag_list;
  1941. frag_list->next = NULL;
  1942. tmp = (void *)ALIGN((long)frag_list->data, ALIGN_SIZE + 1);
  1943. frag_list->data = tmp;
  1944. frag_list->tail = tmp;
  1945. /* Buffer-2 receives L4 data payload */
  1946. ((RxD3_t*)rxdp)->Buffer2_ptr = pci_map_single(nic->pdev,
  1947. frag_list->data, dev->mtu,
  1948. PCI_DMA_FROMDEVICE);
  1949. rxdp->Control_2 |= SET_BUFFER1_SIZE_3(l3l4hdr_size + 4);
  1950. rxdp->Control_2 |= SET_BUFFER2_SIZE_3(dev->mtu);
  1951. return SUCCESS;
  1952. }
  1953. /**
  1954. * fill_rx_buffers - Allocates the Rx side skbs
  1955. * @nic: device private variable
  1956. * @ring_no: ring number
  1957. * Description:
  1958. * The function allocates Rx side skbs and puts the physical
  1959. * address of these buffers into the RxD buffer pointers, so that the NIC
  1960. * can DMA the received frame into these locations.
  1961. * The NIC supports 3 receive modes, viz
  1962. * 1. single buffer,
  1963. * 2. three buffer and
  1964. * 3. Five buffer modes.
  1965. * Each mode defines how many fragments the received frame will be split
  1966. * up into by the NIC. The frame is split into L3 header, L4 Header,
  1967. * L4 payload in three buffer mode and in 5 buffer mode, L4 payload itself
  1968. * is split into 3 fragments. As of now only single buffer mode is
  1969. * supported.
  1970. * Return Value:
  1971. * SUCCESS on success or an appropriate -ve value on failure.
  1972. */
  1973. static int fill_rx_buffers(struct s2io_nic *nic, int ring_no)
  1974. {
  1975. struct net_device *dev = nic->dev;
  1976. struct sk_buff *skb;
  1977. RxD_t *rxdp;
  1978. int off, off1, size, block_no, block_no1;
  1979. u32 alloc_tab = 0;
  1980. u32 alloc_cnt;
  1981. mac_info_t *mac_control;
  1982. struct config_param *config;
  1983. u64 tmp;
  1984. buffAdd_t *ba;
  1985. #ifndef CONFIG_S2IO_NAPI
  1986. unsigned long flags;
  1987. #endif
  1988. RxD_t *first_rxdp = NULL;
  1989. mac_control = &nic->mac_control;
  1990. config = &nic->config;
  1991. alloc_cnt = mac_control->rings[ring_no].pkt_cnt -
  1992. atomic_read(&nic->rx_bufs_left[ring_no]);
  1993. while (alloc_tab < alloc_cnt) {
  1994. block_no = mac_control->rings[ring_no].rx_curr_put_info.
  1995. block_index;
  1996. block_no1 = mac_control->rings[ring_no].rx_curr_get_info.
  1997. block_index;
  1998. off = mac_control->rings[ring_no].rx_curr_put_info.offset;
  1999. off1 = mac_control->rings[ring_no].rx_curr_get_info.offset;
  2000. rxdp = mac_control->rings[ring_no].
  2001. rx_blocks[block_no].rxds[off].virt_addr;
  2002. if ((block_no == block_no1) && (off == off1) &&
  2003. (rxdp->Host_Control)) {
  2004. DBG_PRINT(INTR_DBG, "%s: Get and Put",
  2005. dev->name);
  2006. DBG_PRINT(INTR_DBG, " info equated\n");
  2007. goto end;
  2008. }
  2009. if (off && (off == rxd_count[nic->rxd_mode])) {
  2010. mac_control->rings[ring_no].rx_curr_put_info.
  2011. block_index++;
  2012. if (mac_control->rings[ring_no].rx_curr_put_info.
  2013. block_index == mac_control->rings[ring_no].
  2014. block_count)
  2015. mac_control->rings[ring_no].rx_curr_put_info.
  2016. block_index = 0;
  2017. block_no = mac_control->rings[ring_no].
  2018. rx_curr_put_info.block_index;
  2019. if (off == rxd_count[nic->rxd_mode])
  2020. off = 0;
  2021. mac_control->rings[ring_no].rx_curr_put_info.
  2022. offset = off;
  2023. rxdp = mac_control->rings[ring_no].
  2024. rx_blocks[block_no].block_virt_addr;
  2025. DBG_PRINT(INTR_DBG, "%s: Next block at: %p\n",
  2026. dev->name, rxdp);
  2027. }
  2028. #ifndef CONFIG_S2IO_NAPI
  2029. spin_lock_irqsave(&nic->put_lock, flags);
  2030. mac_control->rings[ring_no].put_pos =
  2031. (block_no * (rxd_count[nic->rxd_mode] + 1)) + off;
  2032. spin_unlock_irqrestore(&nic->put_lock, flags);
  2033. #endif
  2034. if ((rxdp->Control_1 & RXD_OWN_XENA) &&
  2035. ((nic->rxd_mode >= RXD_MODE_3A) &&
  2036. (rxdp->Control_2 & BIT(0)))) {
  2037. mac_control->rings[ring_no].rx_curr_put_info.
  2038. offset = off;
  2039. goto end;
  2040. }
  2041. /* calculate size of skb based on ring mode */
  2042. size = dev->mtu + HEADER_ETHERNET_II_802_3_SIZE +
  2043. HEADER_802_2_SIZE + HEADER_SNAP_SIZE;
  2044. if (nic->rxd_mode == RXD_MODE_1)
  2045. size += NET_IP_ALIGN;
  2046. else if (nic->rxd_mode == RXD_MODE_3B)
  2047. size = dev->mtu + ALIGN_SIZE + BUF0_LEN + 4;
  2048. else
  2049. size = l3l4hdr_size + ALIGN_SIZE + BUF0_LEN + 4;
  2050. /* allocate skb */
  2051. skb = dev_alloc_skb(size);
  2052. if(!skb) {
  2053. DBG_PRINT(ERR_DBG, "%s: Out of ", dev->name);
  2054. DBG_PRINT(ERR_DBG, "memory to allocate SKBs\n");
  2055. if (first_rxdp) {
  2056. wmb();
  2057. first_rxdp->Control_1 |= RXD_OWN_XENA;
  2058. }
  2059. return -ENOMEM ;
  2060. }
  2061. if (nic->rxd_mode == RXD_MODE_1) {
  2062. /* 1 buffer mode - normal operation mode */
  2063. memset(rxdp, 0, sizeof(RxD1_t));
  2064. skb_reserve(skb, NET_IP_ALIGN);
  2065. ((RxD1_t*)rxdp)->Buffer0_ptr = pci_map_single
  2066. (nic->pdev, skb->data, size, PCI_DMA_FROMDEVICE);
  2067. rxdp->Control_2 &= (~MASK_BUFFER0_SIZE_1);
  2068. rxdp->Control_2 |= SET_BUFFER0_SIZE_1(size);
  2069. } else if (nic->rxd_mode >= RXD_MODE_3A) {
  2070. /*
  2071. * 2 or 3 buffer mode -
  2072. * Both 2 buffer mode and 3 buffer mode provides 128
  2073. * byte aligned receive buffers.
  2074. *
  2075. * 3 buffer mode provides header separation where in
  2076. * skb->data will have L3/L4 headers where as
  2077. * skb_shinfo(skb)->frag_list will have the L4 data
  2078. * payload
  2079. */
  2080. memset(rxdp, 0, sizeof(RxD3_t));
  2081. ba = &mac_control->rings[ring_no].ba[block_no][off];
  2082. skb_reserve(skb, BUF0_LEN);
  2083. tmp = (u64)(unsigned long) skb->data;
  2084. tmp += ALIGN_SIZE;
  2085. tmp &= ~ALIGN_SIZE;
  2086. skb->data = (void *) (unsigned long)tmp;
  2087. skb->tail = (void *) (unsigned long)tmp;
  2088. ((RxD3_t*)rxdp)->Buffer0_ptr =
  2089. pci_map_single(nic->pdev, ba->ba_0, BUF0_LEN,
  2090. PCI_DMA_FROMDEVICE);
  2091. rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN);
  2092. if (nic->rxd_mode == RXD_MODE_3B) {
  2093. /* Two buffer mode */
  2094. /*
  2095. * Buffer2 will have L3/L4 header plus
  2096. * L4 payload
  2097. */
  2098. ((RxD3_t*)rxdp)->Buffer2_ptr = pci_map_single
  2099. (nic->pdev, skb->data, dev->mtu + 4,
  2100. PCI_DMA_FROMDEVICE);
  2101. /* Buffer-1 will be dummy buffer not used */
  2102. ((RxD3_t*)rxdp)->Buffer1_ptr =
  2103. pci_map_single(nic->pdev, ba->ba_1, BUF1_LEN,
  2104. PCI_DMA_FROMDEVICE);
  2105. rxdp->Control_2 |= SET_BUFFER1_SIZE_3(1);
  2106. rxdp->Control_2 |= SET_BUFFER2_SIZE_3
  2107. (dev->mtu + 4);
  2108. } else {
  2109. /* 3 buffer mode */
  2110. if (fill_rxd_3buf(nic, rxdp, skb) == -ENOMEM) {
  2111. dev_kfree_skb_irq(skb);
  2112. if (first_rxdp) {
  2113. wmb();
  2114. first_rxdp->Control_1 |=
  2115. RXD_OWN_XENA;
  2116. }
  2117. return -ENOMEM ;
  2118. }
  2119. }
  2120. rxdp->Control_2 |= BIT(0);
  2121. }
  2122. rxdp->Host_Control = (unsigned long) (skb);
  2123. if (alloc_tab & ((1 << rxsync_frequency) - 1))
  2124. rxdp->Control_1 |= RXD_OWN_XENA;
  2125. off++;
  2126. if (off == (rxd_count[nic->rxd_mode] + 1))
  2127. off = 0;
  2128. mac_control->rings[ring_no].rx_curr_put_info.offset = off;
  2129. rxdp->Control_2 |= SET_RXD_MARKER;
  2130. if (!(alloc_tab & ((1 << rxsync_frequency) - 1))) {
  2131. if (first_rxdp) {
  2132. wmb();
  2133. first_rxdp->Control_1 |= RXD_OWN_XENA;
  2134. }
  2135. first_rxdp = rxdp;
  2136. }
  2137. atomic_inc(&nic->rx_bufs_left[ring_no]);
  2138. alloc_tab++;
  2139. }
  2140. end:
  2141. /* Transfer ownership of first descriptor to adapter just before
  2142. * exiting. Before that, use memory barrier so that ownership
  2143. * and other fields are seen by adapter correctly.
  2144. */
  2145. if (first_rxdp) {
  2146. wmb();
  2147. first_rxdp->Control_1 |= RXD_OWN_XENA;
  2148. }
  2149. return SUCCESS;
  2150. }
  2151. static void free_rxd_blk(struct s2io_nic *sp, int ring_no, int blk)
  2152. {
  2153. struct net_device *dev = sp->dev;
  2154. int j;
  2155. struct sk_buff *skb;
  2156. RxD_t *rxdp;
  2157. mac_info_t *mac_control;
  2158. buffAdd_t *ba;
  2159. mac_control = &sp->mac_control;
  2160. for (j = 0 ; j < rxd_count[sp->rxd_mode]; j++) {
  2161. rxdp = mac_control->rings[ring_no].
  2162. rx_blocks[blk].rxds[j].virt_addr;
  2163. skb = (struct sk_buff *)
  2164. ((unsigned long) rxdp->Host_Control);
  2165. if (!skb) {
  2166. continue;
  2167. }
  2168. if (sp->rxd_mode == RXD_MODE_1) {
  2169. pci_unmap_single(sp->pdev, (dma_addr_t)
  2170. ((RxD1_t*)rxdp)->Buffer0_ptr,
  2171. dev->mtu +
  2172. HEADER_ETHERNET_II_802_3_SIZE
  2173. + HEADER_802_2_SIZE +
  2174. HEADER_SNAP_SIZE,
  2175. PCI_DMA_FROMDEVICE);
  2176. memset(rxdp, 0, sizeof(RxD1_t));
  2177. } else if(sp->rxd_mode == RXD_MODE_3B) {
  2178. ba = &mac_control->rings[ring_no].
  2179. ba[blk][j];
  2180. pci_unmap_single(sp->pdev, (dma_addr_t)
  2181. ((RxD3_t*)rxdp)->Buffer0_ptr,
  2182. BUF0_LEN,
  2183. PCI_DMA_FROMDEVICE);
  2184. pci_unmap_single(sp->pdev, (dma_addr_t)
  2185. ((RxD3_t*)rxdp)->Buffer1_ptr,
  2186. BUF1_LEN,
  2187. PCI_DMA_FROMDEVICE);
  2188. pci_unmap_single(sp->pdev, (dma_addr_t)
  2189. ((RxD3_t*)rxdp)->Buffer2_ptr,
  2190. dev->mtu + 4,
  2191. PCI_DMA_FROMDEVICE);
  2192. memset(rxdp, 0, sizeof(RxD3_t));
  2193. } else {
  2194. pci_unmap_single(sp->pdev, (dma_addr_t)
  2195. ((RxD3_t*)rxdp)->Buffer0_ptr, BUF0_LEN,
  2196. PCI_DMA_FROMDEVICE);
  2197. pci_unmap_single(sp->pdev, (dma_addr_t)
  2198. ((RxD3_t*)rxdp)->Buffer1_ptr,
  2199. l3l4hdr_size + 4,
  2200. PCI_DMA_FROMDEVICE);
  2201. pci_unmap_single(sp->pdev, (dma_addr_t)
  2202. ((RxD3_t*)rxdp)->Buffer2_ptr, dev->mtu,
  2203. PCI_DMA_FROMDEVICE);
  2204. memset(rxdp, 0, sizeof(RxD3_t));
  2205. }
  2206. dev_kfree_skb(skb);
  2207. atomic_dec(&sp->rx_bufs_left[ring_no]);
  2208. }
  2209. }
  2210. /**
  2211. * free_rx_buffers - Frees all Rx buffers
  2212. * @sp: device private variable.
  2213. * Description:
  2214. * This function will free all Rx buffers allocated by host.
  2215. * Return Value:
  2216. * NONE.
  2217. */
  2218. static void free_rx_buffers(struct s2io_nic *sp)
  2219. {
  2220. struct net_device *dev = sp->dev;
  2221. int i, blk = 0, buf_cnt = 0;
  2222. mac_info_t *mac_control;
  2223. struct config_param *config;
  2224. mac_control = &sp->mac_control;
  2225. config = &sp->config;
  2226. for (i = 0; i < config->rx_ring_num; i++) {
  2227. for (blk = 0; blk < rx_ring_sz[i]; blk++)
  2228. free_rxd_blk(sp,i,blk);
  2229. mac_control->rings[i].rx_curr_put_info.block_index = 0;
  2230. mac_control->rings[i].rx_curr_get_info.block_index = 0;
  2231. mac_control->rings[i].rx_curr_put_info.offset = 0;
  2232. mac_control->rings[i].rx_curr_get_info.offset = 0;
  2233. atomic_set(&sp->rx_bufs_left[i], 0);
  2234. DBG_PRINT(INIT_DBG, "%s:Freed 0x%x Rx Buffers on ring%d\n",
  2235. dev->name, buf_cnt, i);
  2236. }
  2237. }
  2238. /**
  2239. * s2io_poll - Rx interrupt handler for NAPI support
  2240. * @dev : pointer to the device structure.
  2241. * @budget : The number of packets that were budgeted to be processed
  2242. * during one pass through the 'Poll" function.
  2243. * Description:
  2244. * Comes into picture only if NAPI support has been incorporated. It does
  2245. * the same thing that rx_intr_handler does, but not in a interrupt context
  2246. * also It will process only a given number of packets.
  2247. * Return value:
  2248. * 0 on success and 1 if there are No Rx packets to be processed.
  2249. */
  2250. #if defined(CONFIG_S2IO_NAPI)
  2251. static int s2io_poll(struct net_device *dev, int *budget)
  2252. {
  2253. nic_t *nic = dev->priv;
  2254. int pkt_cnt = 0, org_pkts_to_process;
  2255. mac_info_t *mac_control;
  2256. struct config_param *config;
  2257. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  2258. u64 val64;
  2259. int i;
  2260. atomic_inc(&nic->isr_cnt);
  2261. mac_control = &nic->mac_control;
  2262. config = &nic->config;
  2263. nic->pkts_to_process = *budget;
  2264. if (nic->pkts_to_process > dev->quota)
  2265. nic->pkts_to_process = dev->quota;
  2266. org_pkts_to_process = nic->pkts_to_process;
  2267. val64 = readq(&bar0->rx_traffic_int);
  2268. writeq(val64, &bar0->rx_traffic_int);
  2269. for (i = 0; i < config->rx_ring_num; i++) {
  2270. rx_intr_handler(&mac_control->rings[i]);
  2271. pkt_cnt = org_pkts_to_process - nic->pkts_to_process;
  2272. if (!nic->pkts_to_process) {
  2273. /* Quota for the current iteration has been met */
  2274. goto no_rx;
  2275. }
  2276. }
  2277. if (!pkt_cnt)
  2278. pkt_cnt = 1;
  2279. dev->quota -= pkt_cnt;
  2280. *budget -= pkt_cnt;
  2281. netif_rx_complete(dev);
  2282. for (i = 0; i < config->rx_ring_num; i++) {
  2283. if (fill_rx_buffers(nic, i) == -ENOMEM) {
  2284. DBG_PRINT(ERR_DBG, "%s:Out of memory", dev->name);
  2285. DBG_PRINT(ERR_DBG, " in Rx Poll!!\n");
  2286. break;
  2287. }
  2288. }
  2289. /* Re enable the Rx interrupts. */
  2290. en_dis_able_nic_intrs(nic, RX_TRAFFIC_INTR, ENABLE_INTRS);
  2291. atomic_dec(&nic->isr_cnt);
  2292. return 0;
  2293. no_rx:
  2294. dev->quota -= pkt_cnt;
  2295. *budget -= pkt_cnt;
  2296. for (i = 0; i < config->rx_ring_num; i++) {
  2297. if (fill_rx_buffers(nic, i) == -ENOMEM) {
  2298. DBG_PRINT(ERR_DBG, "%s:Out of memory", dev->name);
  2299. DBG_PRINT(ERR_DBG, " in Rx Poll!!\n");
  2300. break;
  2301. }
  2302. }
  2303. atomic_dec(&nic->isr_cnt);
  2304. return 1;
  2305. }
  2306. #endif
  2307. /**
  2308. * rx_intr_handler - Rx interrupt handler
  2309. * @nic: device private variable.
  2310. * Description:
  2311. * If the interrupt is because of a received frame or if the
  2312. * receive ring contains fresh as yet un-processed frames,this function is
  2313. * called. It picks out the RxD at which place the last Rx processing had
  2314. * stopped and sends the skb to the OSM's Rx handler and then increments
  2315. * the offset.
  2316. * Return Value:
  2317. * NONE.
  2318. */
  2319. static void rx_intr_handler(ring_info_t *ring_data)
  2320. {
  2321. nic_t *nic = ring_data->nic;
  2322. struct net_device *dev = (struct net_device *) nic->dev;
  2323. int get_block, put_block, put_offset;
  2324. rx_curr_get_info_t get_info, put_info;
  2325. RxD_t *rxdp;
  2326. struct sk_buff *skb;
  2327. #ifndef CONFIG_S2IO_NAPI
  2328. int pkt_cnt = 0;
  2329. #endif
  2330. spin_lock(&nic->rx_lock);
  2331. if (atomic_read(&nic->card_state) == CARD_DOWN) {
  2332. DBG_PRINT(INTR_DBG, "%s: %s going down for reset\n",
  2333. __FUNCTION__, dev->name);
  2334. spin_unlock(&nic->rx_lock);
  2335. return;
  2336. }
  2337. get_info = ring_data->rx_curr_get_info;
  2338. get_block = get_info.block_index;
  2339. put_info = ring_data->rx_curr_put_info;
  2340. put_block = put_info.block_index;
  2341. rxdp = ring_data->rx_blocks[get_block].rxds[get_info.offset].virt_addr;
  2342. #ifndef CONFIG_S2IO_NAPI
  2343. spin_lock(&nic->put_lock);
  2344. put_offset = ring_data->put_pos;
  2345. spin_unlock(&nic->put_lock);
  2346. #else
  2347. put_offset = (put_block * (rxd_count[nic->rxd_mode] + 1)) +
  2348. put_info.offset;
  2349. #endif
  2350. while (RXD_IS_UP2DT(rxdp)) {
  2351. /* If your are next to put index then it's FIFO full condition */
  2352. if ((get_block == put_block) &&
  2353. (get_info.offset + 1) == put_info.offset) {
  2354. DBG_PRINT(ERR_DBG, "%s: Ring Full\n",dev->name);
  2355. break;
  2356. }
  2357. skb = (struct sk_buff *) ((unsigned long)rxdp->Host_Control);
  2358. if (skb == NULL) {
  2359. DBG_PRINT(ERR_DBG, "%s: The skb is ",
  2360. dev->name);
  2361. DBG_PRINT(ERR_DBG, "Null in Rx Intr\n");
  2362. spin_unlock(&nic->rx_lock);
  2363. return;
  2364. }
  2365. if (nic->rxd_mode == RXD_MODE_1) {
  2366. pci_unmap_single(nic->pdev, (dma_addr_t)
  2367. ((RxD1_t*)rxdp)->Buffer0_ptr,
  2368. dev->mtu +
  2369. HEADER_ETHERNET_II_802_3_SIZE +
  2370. HEADER_802_2_SIZE +
  2371. HEADER_SNAP_SIZE,
  2372. PCI_DMA_FROMDEVICE);
  2373. } else if (nic->rxd_mode == RXD_MODE_3B) {
  2374. pci_unmap_single(nic->pdev, (dma_addr_t)
  2375. ((RxD3_t*)rxdp)->Buffer0_ptr,
  2376. BUF0_LEN, PCI_DMA_FROMDEVICE);
  2377. pci_unmap_single(nic->pdev, (dma_addr_t)
  2378. ((RxD3_t*)rxdp)->Buffer1_ptr,
  2379. BUF1_LEN, PCI_DMA_FROMDEVICE);
  2380. pci_unmap_single(nic->pdev, (dma_addr_t)
  2381. ((RxD3_t*)rxdp)->Buffer2_ptr,
  2382. dev->mtu + 4,
  2383. PCI_DMA_FROMDEVICE);
  2384. } else {
  2385. pci_unmap_single(nic->pdev, (dma_addr_t)
  2386. ((RxD3_t*)rxdp)->Buffer0_ptr, BUF0_LEN,
  2387. PCI_DMA_FROMDEVICE);
  2388. pci_unmap_single(nic->pdev, (dma_addr_t)
  2389. ((RxD3_t*)rxdp)->Buffer1_ptr,
  2390. l3l4hdr_size + 4,
  2391. PCI_DMA_FROMDEVICE);
  2392. pci_unmap_single(nic->pdev, (dma_addr_t)
  2393. ((RxD3_t*)rxdp)->Buffer2_ptr,
  2394. dev->mtu, PCI_DMA_FROMDEVICE);
  2395. }
  2396. rx_osm_handler(ring_data, rxdp);
  2397. get_info.offset++;
  2398. ring_data->rx_curr_get_info.offset = get_info.offset;
  2399. rxdp = ring_data->rx_blocks[get_block].
  2400. rxds[get_info.offset].virt_addr;
  2401. if (get_info.offset == rxd_count[nic->rxd_mode]) {
  2402. get_info.offset = 0;
  2403. ring_data->rx_curr_get_info.offset = get_info.offset;
  2404. get_block++;
  2405. if (get_block == ring_data->block_count)
  2406. get_block = 0;
  2407. ring_data->rx_curr_get_info.block_index = get_block;
  2408. rxdp = ring_data->rx_blocks[get_block].block_virt_addr;
  2409. }
  2410. #ifdef CONFIG_S2IO_NAPI
  2411. nic->pkts_to_process -= 1;
  2412. if (!nic->pkts_to_process)
  2413. break;
  2414. #else
  2415. pkt_cnt++;
  2416. if ((indicate_max_pkts) && (pkt_cnt > indicate_max_pkts))
  2417. break;
  2418. #endif
  2419. }
  2420. spin_unlock(&nic->rx_lock);
  2421. }
  2422. /**
  2423. * tx_intr_handler - Transmit interrupt handler
  2424. * @nic : device private variable
  2425. * Description:
  2426. * If an interrupt was raised to indicate DMA complete of the
  2427. * Tx packet, this function is called. It identifies the last TxD
  2428. * whose buffer was freed and frees all skbs whose data have already
  2429. * DMA'ed into the NICs internal memory.
  2430. * Return Value:
  2431. * NONE
  2432. */
  2433. static void tx_intr_handler(fifo_info_t *fifo_data)
  2434. {
  2435. nic_t *nic = fifo_data->nic;
  2436. struct net_device *dev = (struct net_device *) nic->dev;
  2437. tx_curr_get_info_t get_info, put_info;
  2438. struct sk_buff *skb;
  2439. TxD_t *txdlp;
  2440. u16 j, frg_cnt;
  2441. get_info = fifo_data->tx_curr_get_info;
  2442. put_info = fifo_data->tx_curr_put_info;
  2443. txdlp = (TxD_t *) fifo_data->list_info[get_info.offset].
  2444. list_virt_addr;
  2445. while ((!(txdlp->Control_1 & TXD_LIST_OWN_XENA)) &&
  2446. (get_info.offset != put_info.offset) &&
  2447. (txdlp->Host_Control)) {
  2448. /* Check for TxD errors */
  2449. if (txdlp->Control_1 & TXD_T_CODE) {
  2450. unsigned long long err;
  2451. err = txdlp->Control_1 & TXD_T_CODE;
  2452. if ((err >> 48) == 0xA) {
  2453. DBG_PRINT(TX_DBG, "TxD returned due \
  2454. to loss of link\n");
  2455. }
  2456. else {
  2457. DBG_PRINT(ERR_DBG, "***TxD error \
  2458. %llx\n", err);
  2459. }
  2460. }
  2461. skb = (struct sk_buff *) ((unsigned long)
  2462. txdlp->Host_Control);
  2463. if (skb == NULL) {
  2464. DBG_PRINT(ERR_DBG, "%s: Null skb ",
  2465. __FUNCTION__);
  2466. DBG_PRINT(ERR_DBG, "in Tx Free Intr\n");
  2467. return;
  2468. }
  2469. frg_cnt = skb_shinfo(skb)->nr_frags;
  2470. nic->tx_pkt_count++;
  2471. pci_unmap_single(nic->pdev, (dma_addr_t)
  2472. txdlp->Buffer_Pointer,
  2473. skb->len - skb->data_len,
  2474. PCI_DMA_TODEVICE);
  2475. if (frg_cnt) {
  2476. TxD_t *temp;
  2477. temp = txdlp;
  2478. txdlp++;
  2479. for (j = 0; j < frg_cnt; j++, txdlp++) {
  2480. skb_frag_t *frag =
  2481. &skb_shinfo(skb)->frags[j];
  2482. if (!txdlp->Buffer_Pointer)
  2483. break;
  2484. pci_unmap_page(nic->pdev,
  2485. (dma_addr_t)
  2486. txdlp->
  2487. Buffer_Pointer,
  2488. frag->size,
  2489. PCI_DMA_TODEVICE);
  2490. }
  2491. txdlp = temp;
  2492. }
  2493. memset(txdlp, 0,
  2494. (sizeof(TxD_t) * fifo_data->max_txds));
  2495. /* Updating the statistics block */
  2496. nic->stats.tx_bytes += skb->len;
  2497. dev_kfree_skb_irq(skb);
  2498. get_info.offset++;
  2499. get_info.offset %= get_info.fifo_len + 1;
  2500. txdlp = (TxD_t *) fifo_data->list_info
  2501. [get_info.offset].list_virt_addr;
  2502. fifo_data->tx_curr_get_info.offset =
  2503. get_info.offset;
  2504. }
  2505. spin_lock(&nic->tx_lock);
  2506. if (netif_queue_stopped(dev))
  2507. netif_wake_queue(dev);
  2508. spin_unlock(&nic->tx_lock);
  2509. }
  2510. /**
  2511. * alarm_intr_handler - Alarm Interrrupt handler
  2512. * @nic: device private variable
  2513. * Description: If the interrupt was neither because of Rx packet or Tx
  2514. * complete, this function is called. If the interrupt was to indicate
  2515. * a loss of link, the OSM link status handler is invoked for any other
  2516. * alarm interrupt the block that raised the interrupt is displayed
  2517. * and a H/W reset is issued.
  2518. * Return Value:
  2519. * NONE
  2520. */
  2521. static void alarm_intr_handler(struct s2io_nic *nic)
  2522. {
  2523. struct net_device *dev = (struct net_device *) nic->dev;
  2524. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  2525. register u64 val64 = 0, err_reg = 0;
  2526. /* Handling link status change error Intr */
  2527. if (s2io_link_fault_indication(nic) == MAC_RMAC_ERR_TIMER) {
  2528. err_reg = readq(&bar0->mac_rmac_err_reg);
  2529. writeq(err_reg, &bar0->mac_rmac_err_reg);
  2530. if (err_reg & RMAC_LINK_STATE_CHANGE_INT) {
  2531. schedule_work(&nic->set_link_task);
  2532. }
  2533. }
  2534. /* Handling Ecc errors */
  2535. val64 = readq(&bar0->mc_err_reg);
  2536. writeq(val64, &bar0->mc_err_reg);
  2537. if (val64 & (MC_ERR_REG_ECC_ALL_SNG | MC_ERR_REG_ECC_ALL_DBL)) {
  2538. if (val64 & MC_ERR_REG_ECC_ALL_DBL) {
  2539. nic->mac_control.stats_info->sw_stat.
  2540. double_ecc_errs++;
  2541. DBG_PRINT(INIT_DBG, "%s: Device indicates ",
  2542. dev->name);
  2543. DBG_PRINT(INIT_DBG, "double ECC error!!\n");
  2544. if (nic->device_type != XFRAME_II_DEVICE) {
  2545. /* Reset XframeI only if critical error */
  2546. if (val64 & (MC_ERR_REG_MIRI_ECC_DB_ERR_0 |
  2547. MC_ERR_REG_MIRI_ECC_DB_ERR_1)) {
  2548. netif_stop_queue(dev);
  2549. schedule_work(&nic->rst_timer_task);
  2550. }
  2551. }
  2552. } else {
  2553. nic->mac_control.stats_info->sw_stat.
  2554. single_ecc_errs++;
  2555. }
  2556. }
  2557. /* In case of a serious error, the device will be Reset. */
  2558. val64 = readq(&bar0->serr_source);
  2559. if (val64 & SERR_SOURCE_ANY) {
  2560. DBG_PRINT(ERR_DBG, "%s: Device indicates ", dev->name);
  2561. DBG_PRINT(ERR_DBG, "serious error %llx!!\n",
  2562. (unsigned long long)val64);
  2563. netif_stop_queue(dev);
  2564. schedule_work(&nic->rst_timer_task);
  2565. }
  2566. /*
  2567. * Also as mentioned in the latest Errata sheets if the PCC_FB_ECC
  2568. * Error occurs, the adapter will be recycled by disabling the
  2569. * adapter enable bit and enabling it again after the device
  2570. * becomes Quiescent.
  2571. */
  2572. val64 = readq(&bar0->pcc_err_reg);
  2573. writeq(val64, &bar0->pcc_err_reg);
  2574. if (val64 & PCC_FB_ECC_DB_ERR) {
  2575. u64 ac = readq(&bar0->adapter_control);
  2576. ac &= ~(ADAPTER_CNTL_EN);
  2577. writeq(ac, &bar0->adapter_control);
  2578. ac = readq(&bar0->adapter_control);
  2579. schedule_work(&nic->set_link_task);
  2580. }
  2581. /* Other type of interrupts are not being handled now, TODO */
  2582. }
  2583. /**
  2584. * wait_for_cmd_complete - waits for a command to complete.
  2585. * @sp : private member of the device structure, which is a pointer to the
  2586. * s2io_nic structure.
  2587. * Description: Function that waits for a command to Write into RMAC
  2588. * ADDR DATA registers to be completed and returns either success or
  2589. * error depending on whether the command was complete or not.
  2590. * Return value:
  2591. * SUCCESS on success and FAILURE on failure.
  2592. */
  2593. static int wait_for_cmd_complete(nic_t * sp)
  2594. {
  2595. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  2596. int ret = FAILURE, cnt = 0;
  2597. u64 val64;
  2598. while (TRUE) {
  2599. val64 = readq(&bar0->rmac_addr_cmd_mem);
  2600. if (!(val64 & RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING)) {
  2601. ret = SUCCESS;
  2602. break;
  2603. }
  2604. msleep(50);
  2605. if (cnt++ > 10)
  2606. break;
  2607. }
  2608. return ret;
  2609. }
  2610. /**
  2611. * s2io_reset - Resets the card.
  2612. * @sp : private member of the device structure.
  2613. * Description: Function to Reset the card. This function then also
  2614. * restores the previously saved PCI configuration space registers as
  2615. * the card reset also resets the configuration space.
  2616. * Return value:
  2617. * void.
  2618. */
  2619. void s2io_reset(nic_t * sp)
  2620. {
  2621. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  2622. u64 val64;
  2623. u16 subid, pci_cmd;
  2624. /* Back up the PCI-X CMD reg, dont want to lose MMRBC, OST settings */
  2625. pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER, &(pci_cmd));
  2626. val64 = SW_RESET_ALL;
  2627. writeq(val64, &bar0->sw_reset);
  2628. /*
  2629. * At this stage, if the PCI write is indeed completed, the
  2630. * card is reset and so is the PCI Config space of the device.
  2631. * So a read cannot be issued at this stage on any of the
  2632. * registers to ensure the write into "sw_reset" register
  2633. * has gone through.
  2634. * Question: Is there any system call that will explicitly force
  2635. * all the write commands still pending on the bus to be pushed
  2636. * through?
  2637. * As of now I'am just giving a 250ms delay and hoping that the
  2638. * PCI write to sw_reset register is done by this time.
  2639. */
  2640. msleep(250);
  2641. /* Restore the PCI state saved during initialization. */
  2642. pci_restore_state(sp->pdev);
  2643. pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  2644. pci_cmd);
  2645. s2io_init_pci(sp);
  2646. msleep(250);
  2647. /* Set swapper to enable I/O register access */
  2648. s2io_set_swapper(sp);
  2649. /* Restore the MSIX table entries from local variables */
  2650. restore_xmsi_data(sp);
  2651. /* Clear certain PCI/PCI-X fields after reset */
  2652. if (sp->device_type == XFRAME_II_DEVICE) {
  2653. /* Clear parity err detect bit */
  2654. pci_write_config_word(sp->pdev, PCI_STATUS, 0x8000);
  2655. /* Clearing PCIX Ecc status register */
  2656. pci_write_config_dword(sp->pdev, 0x68, 0x7C);
  2657. /* Clearing PCI_STATUS error reflected here */
  2658. writeq(BIT(62), &bar0->txpic_int_reg);
  2659. }
  2660. /* Reset device statistics maintained by OS */
  2661. memset(&sp->stats, 0, sizeof (struct net_device_stats));
  2662. /* SXE-002: Configure link and activity LED to turn it off */
  2663. subid = sp->pdev->subsystem_device;
  2664. if (((subid & 0xFF) >= 0x07) &&
  2665. (sp->device_type == XFRAME_I_DEVICE)) {
  2666. val64 = readq(&bar0->gpio_control);
  2667. val64 |= 0x0000800000000000ULL;
  2668. writeq(val64, &bar0->gpio_control);
  2669. val64 = 0x0411040400000000ULL;
  2670. writeq(val64, (void __iomem *)bar0 + 0x2700);
  2671. }
  2672. /*
  2673. * Clear spurious ECC interrupts that would have occured on
  2674. * XFRAME II cards after reset.
  2675. */
  2676. if (sp->device_type == XFRAME_II_DEVICE) {
  2677. val64 = readq(&bar0->pcc_err_reg);
  2678. writeq(val64, &bar0->pcc_err_reg);
  2679. }
  2680. sp->device_enabled_once = FALSE;
  2681. }
  2682. /**
  2683. * s2io_set_swapper - to set the swapper controle on the card
  2684. * @sp : private member of the device structure,
  2685. * pointer to the s2io_nic structure.
  2686. * Description: Function to set the swapper control on the card
  2687. * correctly depending on the 'endianness' of the system.
  2688. * Return value:
  2689. * SUCCESS on success and FAILURE on failure.
  2690. */
  2691. int s2io_set_swapper(nic_t * sp)
  2692. {
  2693. struct net_device *dev = sp->dev;
  2694. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  2695. u64 val64, valt, valr;
  2696. /*
  2697. * Set proper endian settings and verify the same by reading
  2698. * the PIF Feed-back register.
  2699. */
  2700. val64 = readq(&bar0->pif_rd_swapper_fb);
  2701. if (val64 != 0x0123456789ABCDEFULL) {
  2702. int i = 0;
  2703. u64 value[] = { 0xC30000C3C30000C3ULL, /* FE=1, SE=1 */
  2704. 0x8100008181000081ULL, /* FE=1, SE=0 */
  2705. 0x4200004242000042ULL, /* FE=0, SE=1 */
  2706. 0}; /* FE=0, SE=0 */
  2707. while(i<4) {
  2708. writeq(value[i], &bar0->swapper_ctrl);
  2709. val64 = readq(&bar0->pif_rd_swapper_fb);
  2710. if (val64 == 0x0123456789ABCDEFULL)
  2711. break;
  2712. i++;
  2713. }
  2714. if (i == 4) {
  2715. DBG_PRINT(ERR_DBG, "%s: Endian settings are wrong, ",
  2716. dev->name);
  2717. DBG_PRINT(ERR_DBG, "feedback read %llx\n",
  2718. (unsigned long long) val64);
  2719. return FAILURE;
  2720. }
  2721. valr = value[i];
  2722. } else {
  2723. valr = readq(&bar0->swapper_ctrl);
  2724. }
  2725. valt = 0x0123456789ABCDEFULL;
  2726. writeq(valt, &bar0->xmsi_address);
  2727. val64 = readq(&bar0->xmsi_address);
  2728. if(val64 != valt) {
  2729. int i = 0;
  2730. u64 value[] = { 0x00C3C30000C3C300ULL, /* FE=1, SE=1 */
  2731. 0x0081810000818100ULL, /* FE=1, SE=0 */
  2732. 0x0042420000424200ULL, /* FE=0, SE=1 */
  2733. 0}; /* FE=0, SE=0 */
  2734. while(i<4) {
  2735. writeq((value[i] | valr), &bar0->swapper_ctrl);
  2736. writeq(valt, &bar0->xmsi_address);
  2737. val64 = readq(&bar0->xmsi_address);
  2738. if(val64 == valt)
  2739. break;
  2740. i++;
  2741. }
  2742. if(i == 4) {
  2743. unsigned long long x = val64;
  2744. DBG_PRINT(ERR_DBG, "Write failed, Xmsi_addr ");
  2745. DBG_PRINT(ERR_DBG, "reads:0x%llx\n", x);
  2746. return FAILURE;
  2747. }
  2748. }
  2749. val64 = readq(&bar0->swapper_ctrl);
  2750. val64 &= 0xFFFF000000000000ULL;
  2751. #ifdef __BIG_ENDIAN
  2752. /*
  2753. * The device by default set to a big endian format, so a
  2754. * big endian driver need not set anything.
  2755. */
  2756. val64 |= (SWAPPER_CTRL_TXP_FE |
  2757. SWAPPER_CTRL_TXP_SE |
  2758. SWAPPER_CTRL_TXD_R_FE |
  2759. SWAPPER_CTRL_TXD_W_FE |
  2760. SWAPPER_CTRL_TXF_R_FE |
  2761. SWAPPER_CTRL_RXD_R_FE |
  2762. SWAPPER_CTRL_RXD_W_FE |
  2763. SWAPPER_CTRL_RXF_W_FE |
  2764. SWAPPER_CTRL_XMSI_FE |
  2765. SWAPPER_CTRL_STATS_FE | SWAPPER_CTRL_STATS_SE);
  2766. if (sp->intr_type == INTA)
  2767. val64 |= SWAPPER_CTRL_XMSI_SE;
  2768. writeq(val64, &bar0->swapper_ctrl);
  2769. #else
  2770. /*
  2771. * Initially we enable all bits to make it accessible by the
  2772. * driver, then we selectively enable only those bits that
  2773. * we want to set.
  2774. */
  2775. val64 |= (SWAPPER_CTRL_TXP_FE |
  2776. SWAPPER_CTRL_TXP_SE |
  2777. SWAPPER_CTRL_TXD_R_FE |
  2778. SWAPPER_CTRL_TXD_R_SE |
  2779. SWAPPER_CTRL_TXD_W_FE |
  2780. SWAPPER_CTRL_TXD_W_SE |
  2781. SWAPPER_CTRL_TXF_R_FE |
  2782. SWAPPER_CTRL_RXD_R_FE |
  2783. SWAPPER_CTRL_RXD_R_SE |
  2784. SWAPPER_CTRL_RXD_W_FE |
  2785. SWAPPER_CTRL_RXD_W_SE |
  2786. SWAPPER_CTRL_RXF_W_FE |
  2787. SWAPPER_CTRL_XMSI_FE |
  2788. SWAPPER_CTRL_STATS_FE | SWAPPER_CTRL_STATS_SE);
  2789. if (sp->intr_type == INTA)
  2790. val64 |= SWAPPER_CTRL_XMSI_SE;
  2791. writeq(val64, &bar0->swapper_ctrl);
  2792. #endif
  2793. val64 = readq(&bar0->swapper_ctrl);
  2794. /*
  2795. * Verifying if endian settings are accurate by reading a
  2796. * feedback register.
  2797. */
  2798. val64 = readq(&bar0->pif_rd_swapper_fb);
  2799. if (val64 != 0x0123456789ABCDEFULL) {
  2800. /* Endian settings are incorrect, calls for another dekko. */
  2801. DBG_PRINT(ERR_DBG, "%s: Endian settings are wrong, ",
  2802. dev->name);
  2803. DBG_PRINT(ERR_DBG, "feedback read %llx\n",
  2804. (unsigned long long) val64);
  2805. return FAILURE;
  2806. }
  2807. return SUCCESS;
  2808. }
  2809. static int wait_for_msix_trans(nic_t *nic, int i)
  2810. {
  2811. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  2812. u64 val64;
  2813. int ret = 0, cnt = 0;
  2814. do {
  2815. val64 = readq(&bar0->xmsi_access);
  2816. if (!(val64 & BIT(15)))
  2817. break;
  2818. mdelay(1);
  2819. cnt++;
  2820. } while(cnt < 5);
  2821. if (cnt == 5) {
  2822. DBG_PRINT(ERR_DBG, "XMSI # %d Access failed\n", i);
  2823. ret = 1;
  2824. }
  2825. return ret;
  2826. }
  2827. void restore_xmsi_data(nic_t *nic)
  2828. {
  2829. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  2830. u64 val64;
  2831. int i;
  2832. for (i=0; i< MAX_REQUESTED_MSI_X; i++) {
  2833. writeq(nic->msix_info[i].addr, &bar0->xmsi_address);
  2834. writeq(nic->msix_info[i].data, &bar0->xmsi_data);
  2835. val64 = (BIT(7) | BIT(15) | vBIT(i, 26, 6));
  2836. writeq(val64, &bar0->xmsi_access);
  2837. if (wait_for_msix_trans(nic, i)) {
  2838. DBG_PRINT(ERR_DBG, "failed in %s\n", __FUNCTION__);
  2839. continue;
  2840. }
  2841. }
  2842. }
  2843. static void store_xmsi_data(nic_t *nic)
  2844. {
  2845. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  2846. u64 val64, addr, data;
  2847. int i;
  2848. /* Store and display */
  2849. for (i=0; i< MAX_REQUESTED_MSI_X; i++) {
  2850. val64 = (BIT(15) | vBIT(i, 26, 6));
  2851. writeq(val64, &bar0->xmsi_access);
  2852. if (wait_for_msix_trans(nic, i)) {
  2853. DBG_PRINT(ERR_DBG, "failed in %s\n", __FUNCTION__);
  2854. continue;
  2855. }
  2856. addr = readq(&bar0->xmsi_address);
  2857. data = readq(&bar0->xmsi_data);
  2858. if (addr && data) {
  2859. nic->msix_info[i].addr = addr;
  2860. nic->msix_info[i].data = data;
  2861. }
  2862. }
  2863. }
  2864. int s2io_enable_msi(nic_t *nic)
  2865. {
  2866. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  2867. u16 msi_ctrl, msg_val;
  2868. struct config_param *config = &nic->config;
  2869. struct net_device *dev = nic->dev;
  2870. u64 val64, tx_mat, rx_mat;
  2871. int i, err;
  2872. val64 = readq(&bar0->pic_control);
  2873. val64 &= ~BIT(1);
  2874. writeq(val64, &bar0->pic_control);
  2875. err = pci_enable_msi(nic->pdev);
  2876. if (err) {
  2877. DBG_PRINT(ERR_DBG, "%s: enabling MSI failed\n",
  2878. nic->dev->name);
  2879. return err;
  2880. }
  2881. /*
  2882. * Enable MSI and use MSI-1 in stead of the standard MSI-0
  2883. * for interrupt handling.
  2884. */
  2885. pci_read_config_word(nic->pdev, 0x4c, &msg_val);
  2886. msg_val ^= 0x1;
  2887. pci_write_config_word(nic->pdev, 0x4c, msg_val);
  2888. pci_read_config_word(nic->pdev, 0x4c, &msg_val);
  2889. pci_read_config_word(nic->pdev, 0x42, &msi_ctrl);
  2890. msi_ctrl |= 0x10;
  2891. pci_write_config_word(nic->pdev, 0x42, msi_ctrl);
  2892. /* program MSI-1 into all usable Tx_Mat and Rx_Mat fields */
  2893. tx_mat = readq(&bar0->tx_mat0_n[0]);
  2894. for (i=0; i<config->tx_fifo_num; i++) {
  2895. tx_mat |= TX_MAT_SET(i, 1);
  2896. }
  2897. writeq(tx_mat, &bar0->tx_mat0_n[0]);
  2898. rx_mat = readq(&bar0->rx_mat);
  2899. for (i=0; i<config->rx_ring_num; i++) {
  2900. rx_mat |= RX_MAT_SET(i, 1);
  2901. }
  2902. writeq(rx_mat, &bar0->rx_mat);
  2903. dev->irq = nic->pdev->irq;
  2904. return 0;
  2905. }
  2906. int s2io_enable_msi_x(nic_t *nic)
  2907. {
  2908. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  2909. u64 tx_mat, rx_mat;
  2910. u16 msi_control; /* Temp variable */
  2911. int ret, i, j, msix_indx = 1;
  2912. nic->entries = kmalloc(MAX_REQUESTED_MSI_X * sizeof(struct msix_entry),
  2913. GFP_KERNEL);
  2914. if (nic->entries == NULL) {
  2915. DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n", __FUNCTION__);
  2916. return -ENOMEM;
  2917. }
  2918. memset(nic->entries, 0, MAX_REQUESTED_MSI_X * sizeof(struct msix_entry));
  2919. nic->s2io_entries =
  2920. kmalloc(MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry),
  2921. GFP_KERNEL);
  2922. if (nic->s2io_entries == NULL) {
  2923. DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n", __FUNCTION__);
  2924. kfree(nic->entries);
  2925. return -ENOMEM;
  2926. }
  2927. memset(nic->s2io_entries, 0,
  2928. MAX_REQUESTED_MSI_X * sizeof(struct s2io_msix_entry));
  2929. for (i=0; i< MAX_REQUESTED_MSI_X; i++) {
  2930. nic->entries[i].entry = i;
  2931. nic->s2io_entries[i].entry = i;
  2932. nic->s2io_entries[i].arg = NULL;
  2933. nic->s2io_entries[i].in_use = 0;
  2934. }
  2935. tx_mat = readq(&bar0->tx_mat0_n[0]);
  2936. for (i=0; i<nic->config.tx_fifo_num; i++, msix_indx++) {
  2937. tx_mat |= TX_MAT_SET(i, msix_indx);
  2938. nic->s2io_entries[msix_indx].arg = &nic->mac_control.fifos[i];
  2939. nic->s2io_entries[msix_indx].type = MSIX_FIFO_TYPE;
  2940. nic->s2io_entries[msix_indx].in_use = MSIX_FLG;
  2941. }
  2942. writeq(tx_mat, &bar0->tx_mat0_n[0]);
  2943. if (!nic->config.bimodal) {
  2944. rx_mat = readq(&bar0->rx_mat);
  2945. for (j=0; j<nic->config.rx_ring_num; j++, msix_indx++) {
  2946. rx_mat |= RX_MAT_SET(j, msix_indx);
  2947. nic->s2io_entries[msix_indx].arg = &nic->mac_control.rings[j];
  2948. nic->s2io_entries[msix_indx].type = MSIX_RING_TYPE;
  2949. nic->s2io_entries[msix_indx].in_use = MSIX_FLG;
  2950. }
  2951. writeq(rx_mat, &bar0->rx_mat);
  2952. } else {
  2953. tx_mat = readq(&bar0->tx_mat0_n[7]);
  2954. for (j=0; j<nic->config.rx_ring_num; j++, msix_indx++) {
  2955. tx_mat |= TX_MAT_SET(i, msix_indx);
  2956. nic->s2io_entries[msix_indx].arg = &nic->mac_control.rings[j];
  2957. nic->s2io_entries[msix_indx].type = MSIX_RING_TYPE;
  2958. nic->s2io_entries[msix_indx].in_use = MSIX_FLG;
  2959. }
  2960. writeq(tx_mat, &bar0->tx_mat0_n[7]);
  2961. }
  2962. ret = pci_enable_msix(nic->pdev, nic->entries, MAX_REQUESTED_MSI_X);
  2963. if (ret) {
  2964. DBG_PRINT(ERR_DBG, "%s: Enabling MSIX failed\n", nic->dev->name);
  2965. kfree(nic->entries);
  2966. kfree(nic->s2io_entries);
  2967. nic->entries = NULL;
  2968. nic->s2io_entries = NULL;
  2969. return -ENOMEM;
  2970. }
  2971. /*
  2972. * To enable MSI-X, MSI also needs to be enabled, due to a bug
  2973. * in the herc NIC. (Temp change, needs to be removed later)
  2974. */
  2975. pci_read_config_word(nic->pdev, 0x42, &msi_control);
  2976. msi_control |= 0x1; /* Enable MSI */
  2977. pci_write_config_word(nic->pdev, 0x42, msi_control);
  2978. return 0;
  2979. }
  2980. /* ********************************************************* *
  2981. * Functions defined below concern the OS part of the driver *
  2982. * ********************************************************* */
  2983. /**
  2984. * s2io_open - open entry point of the driver
  2985. * @dev : pointer to the device structure.
  2986. * Description:
  2987. * This function is the open entry point of the driver. It mainly calls a
  2988. * function to allocate Rx buffers and inserts them into the buffer
  2989. * descriptors and then enables the Rx part of the NIC.
  2990. * Return value:
  2991. * 0 on success and an appropriate (-)ve integer as defined in errno.h
  2992. * file on failure.
  2993. */
  2994. static int s2io_open(struct net_device *dev)
  2995. {
  2996. nic_t *sp = dev->priv;
  2997. int err = 0;
  2998. int i;
  2999. u16 msi_control; /* Temp variable */
  3000. /*
  3001. * Make sure you have link off by default every time
  3002. * Nic is initialized
  3003. */
  3004. netif_carrier_off(dev);
  3005. sp->last_link_state = 0;
  3006. /* Initialize H/W and enable interrupts */
  3007. if (s2io_card_up(sp)) {
  3008. DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n",
  3009. dev->name);
  3010. err = -ENODEV;
  3011. goto hw_init_failed;
  3012. }
  3013. /* Store the values of the MSIX table in the nic_t structure */
  3014. store_xmsi_data(sp);
  3015. /* After proper initialization of H/W, register ISR */
  3016. if (sp->intr_type == MSI) {
  3017. err = request_irq((int) sp->pdev->irq, s2io_msi_handle,
  3018. SA_SHIRQ, sp->name, dev);
  3019. if (err) {
  3020. DBG_PRINT(ERR_DBG, "%s: MSI registration \
  3021. failed\n", dev->name);
  3022. goto isr_registration_failed;
  3023. }
  3024. }
  3025. if (sp->intr_type == MSI_X) {
  3026. for (i=1; (sp->s2io_entries[i].in_use == MSIX_FLG); i++) {
  3027. if (sp->s2io_entries[i].type == MSIX_FIFO_TYPE) {
  3028. sprintf(sp->desc1, "%s:MSI-X-%d-TX",
  3029. dev->name, i);
  3030. err = request_irq(sp->entries[i].vector,
  3031. s2io_msix_fifo_handle, 0, sp->desc1,
  3032. sp->s2io_entries[i].arg);
  3033. DBG_PRINT(ERR_DBG, "%s @ 0x%llx\n", sp->desc1,
  3034. sp->msix_info[i].addr);
  3035. } else {
  3036. sprintf(sp->desc2, "%s:MSI-X-%d-RX",
  3037. dev->name, i);
  3038. err = request_irq(sp->entries[i].vector,
  3039. s2io_msix_ring_handle, 0, sp->desc2,
  3040. sp->s2io_entries[i].arg);
  3041. DBG_PRINT(ERR_DBG, "%s @ 0x%llx\n", sp->desc2,
  3042. sp->msix_info[i].addr);
  3043. }
  3044. if (err) {
  3045. DBG_PRINT(ERR_DBG, "%s: MSI-X-%d registration \
  3046. failed\n", dev->name, i);
  3047. DBG_PRINT(ERR_DBG, "Returned: %d\n", err);
  3048. goto isr_registration_failed;
  3049. }
  3050. sp->s2io_entries[i].in_use = MSIX_REGISTERED_SUCCESS;
  3051. }
  3052. }
  3053. if (sp->intr_type == INTA) {
  3054. err = request_irq((int) sp->pdev->irq, s2io_isr, SA_SHIRQ,
  3055. sp->name, dev);
  3056. if (err) {
  3057. DBG_PRINT(ERR_DBG, "%s: ISR registration failed\n",
  3058. dev->name);
  3059. goto isr_registration_failed;
  3060. }
  3061. }
  3062. if (s2io_set_mac_addr(dev, dev->dev_addr) == FAILURE) {
  3063. DBG_PRINT(ERR_DBG, "Set Mac Address Failed\n");
  3064. err = -ENODEV;
  3065. goto setting_mac_address_failed;
  3066. }
  3067. netif_start_queue(dev);
  3068. return 0;
  3069. setting_mac_address_failed:
  3070. if (sp->intr_type != MSI_X)
  3071. free_irq(sp->pdev->irq, dev);
  3072. isr_registration_failed:
  3073. del_timer_sync(&sp->alarm_timer);
  3074. if (sp->intr_type == MSI_X) {
  3075. if (sp->device_type == XFRAME_II_DEVICE) {
  3076. for (i=1; (sp->s2io_entries[i].in_use ==
  3077. MSIX_REGISTERED_SUCCESS); i++) {
  3078. int vector = sp->entries[i].vector;
  3079. void *arg = sp->s2io_entries[i].arg;
  3080. free_irq(vector, arg);
  3081. }
  3082. pci_disable_msix(sp->pdev);
  3083. /* Temp */
  3084. pci_read_config_word(sp->pdev, 0x42, &msi_control);
  3085. msi_control &= 0xFFFE; /* Disable MSI */
  3086. pci_write_config_word(sp->pdev, 0x42, msi_control);
  3087. }
  3088. }
  3089. else if (sp->intr_type == MSI)
  3090. pci_disable_msi(sp->pdev);
  3091. s2io_reset(sp);
  3092. hw_init_failed:
  3093. if (sp->intr_type == MSI_X) {
  3094. if (sp->entries)
  3095. kfree(sp->entries);
  3096. if (sp->s2io_entries)
  3097. kfree(sp->s2io_entries);
  3098. }
  3099. return err;
  3100. }
  3101. /**
  3102. * s2io_close -close entry point of the driver
  3103. * @dev : device pointer.
  3104. * Description:
  3105. * This is the stop entry point of the driver. It needs to undo exactly
  3106. * whatever was done by the open entry point,thus it's usually referred to
  3107. * as the close function.Among other things this function mainly stops the
  3108. * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
  3109. * Return value:
  3110. * 0 on success and an appropriate (-)ve integer as defined in errno.h
  3111. * file on failure.
  3112. */
  3113. static int s2io_close(struct net_device *dev)
  3114. {
  3115. nic_t *sp = dev->priv;
  3116. int i;
  3117. u16 msi_control;
  3118. flush_scheduled_work();
  3119. netif_stop_queue(dev);
  3120. /* Reset card, kill tasklet and free Tx and Rx buffers. */
  3121. s2io_card_down(sp);
  3122. if (sp->intr_type == MSI_X) {
  3123. if (sp->device_type == XFRAME_II_DEVICE) {
  3124. for (i=1; (sp->s2io_entries[i].in_use ==
  3125. MSIX_REGISTERED_SUCCESS); i++) {
  3126. int vector = sp->entries[i].vector;
  3127. void *arg = sp->s2io_entries[i].arg;
  3128. free_irq(vector, arg);
  3129. }
  3130. pci_read_config_word(sp->pdev, 0x42, &msi_control);
  3131. msi_control &= 0xFFFE; /* Disable MSI */
  3132. pci_write_config_word(sp->pdev, 0x42, msi_control);
  3133. pci_disable_msix(sp->pdev);
  3134. }
  3135. }
  3136. else {
  3137. free_irq(sp->pdev->irq, dev);
  3138. if (sp->intr_type == MSI)
  3139. pci_disable_msi(sp->pdev);
  3140. }
  3141. sp->device_close_flag = TRUE; /* Device is shut down. */
  3142. return 0;
  3143. }
  3144. /**
  3145. * s2io_xmit - Tx entry point of te driver
  3146. * @skb : the socket buffer containing the Tx data.
  3147. * @dev : device pointer.
  3148. * Description :
  3149. * This function is the Tx entry point of the driver. S2IO NIC supports
  3150. * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
  3151. * NOTE: when device cant queue the pkt,just the trans_start variable will
  3152. * not be upadted.
  3153. * Return value:
  3154. * 0 on success & 1 on failure.
  3155. */
  3156. static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
  3157. {
  3158. nic_t *sp = dev->priv;
  3159. u16 frg_cnt, frg_len, i, queue, queue_len, put_off, get_off;
  3160. register u64 val64;
  3161. TxD_t *txdp;
  3162. TxFIFO_element_t __iomem *tx_fifo;
  3163. unsigned long flags;
  3164. #ifdef NETIF_F_TSO
  3165. int mss;
  3166. #endif
  3167. u16 vlan_tag = 0;
  3168. int vlan_priority = 0;
  3169. mac_info_t *mac_control;
  3170. struct config_param *config;
  3171. mac_control = &sp->mac_control;
  3172. config = &sp->config;
  3173. DBG_PRINT(TX_DBG, "%s: In Neterion Tx routine\n", dev->name);
  3174. spin_lock_irqsave(&sp->tx_lock, flags);
  3175. if (atomic_read(&sp->card_state) == CARD_DOWN) {
  3176. DBG_PRINT(TX_DBG, "%s: Card going down for reset\n",
  3177. dev->name);
  3178. spin_unlock_irqrestore(&sp->tx_lock, flags);
  3179. dev_kfree_skb(skb);
  3180. return 0;
  3181. }
  3182. queue = 0;
  3183. /* Get Fifo number to Transmit based on vlan priority */
  3184. if (sp->vlgrp && vlan_tx_tag_present(skb)) {
  3185. vlan_tag = vlan_tx_tag_get(skb);
  3186. vlan_priority = vlan_tag >> 13;
  3187. queue = config->fifo_mapping[vlan_priority];
  3188. }
  3189. put_off = (u16) mac_control->fifos[queue].tx_curr_put_info.offset;
  3190. get_off = (u16) mac_control->fifos[queue].tx_curr_get_info.offset;
  3191. txdp = (TxD_t *) mac_control->fifos[queue].list_info[put_off].
  3192. list_virt_addr;
  3193. queue_len = mac_control->fifos[queue].tx_curr_put_info.fifo_len + 1;
  3194. /* Avoid "put" pointer going beyond "get" pointer */
  3195. if (txdp->Host_Control || (((put_off + 1) % queue_len) == get_off)) {
  3196. DBG_PRINT(TX_DBG, "Error in xmit, No free TXDs.\n");
  3197. netif_stop_queue(dev);
  3198. dev_kfree_skb(skb);
  3199. spin_unlock_irqrestore(&sp->tx_lock, flags);
  3200. return 0;
  3201. }
  3202. /* A buffer with no data will be dropped */
  3203. if (!skb->len) {
  3204. DBG_PRINT(TX_DBG, "%s:Buffer has no data..\n", dev->name);
  3205. dev_kfree_skb(skb);
  3206. spin_unlock_irqrestore(&sp->tx_lock, flags);
  3207. return 0;
  3208. }
  3209. #ifdef NETIF_F_TSO
  3210. mss = skb_shinfo(skb)->tso_size;
  3211. if (mss) {
  3212. txdp->Control_1 |= TXD_TCP_LSO_EN;
  3213. txdp->Control_1 |= TXD_TCP_LSO_MSS(mss);
  3214. }
  3215. #endif
  3216. frg_cnt = skb_shinfo(skb)->nr_frags;
  3217. frg_len = skb->len - skb->data_len;
  3218. txdp->Buffer_Pointer = pci_map_single
  3219. (sp->pdev, skb->data, frg_len, PCI_DMA_TODEVICE);
  3220. txdp->Host_Control = (unsigned long) skb;
  3221. if (skb->ip_summed == CHECKSUM_HW) {
  3222. txdp->Control_2 |=
  3223. (TXD_TX_CKO_IPV4_EN | TXD_TX_CKO_TCP_EN |
  3224. TXD_TX_CKO_UDP_EN);
  3225. }
  3226. txdp->Control_2 |= config->tx_intr_type;
  3227. if (sp->vlgrp && vlan_tx_tag_present(skb)) {
  3228. txdp->Control_2 |= TXD_VLAN_ENABLE;
  3229. txdp->Control_2 |= TXD_VLAN_TAG(vlan_tag);
  3230. }
  3231. txdp->Control_1 |= (TXD_BUFFER0_SIZE(frg_len) |
  3232. TXD_GATHER_CODE_FIRST);
  3233. txdp->Control_1 |= TXD_LIST_OWN_XENA;
  3234. /* For fragmented SKB. */
  3235. for (i = 0; i < frg_cnt; i++) {
  3236. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3237. /* A '0' length fragment will be ignored */
  3238. if (!frag->size)
  3239. continue;
  3240. txdp++;
  3241. txdp->Buffer_Pointer = (u64) pci_map_page
  3242. (sp->pdev, frag->page, frag->page_offset,
  3243. frag->size, PCI_DMA_TODEVICE);
  3244. txdp->Control_1 |= TXD_BUFFER0_SIZE(frag->size);
  3245. }
  3246. txdp->Control_1 |= TXD_GATHER_CODE_LAST;
  3247. tx_fifo = mac_control->tx_FIFO_start[queue];
  3248. val64 = mac_control->fifos[queue].list_info[put_off].list_phy_addr;
  3249. writeq(val64, &tx_fifo->TxDL_Pointer);
  3250. val64 = (TX_FIFO_LAST_TXD_NUM(frg_cnt) | TX_FIFO_FIRST_LIST |
  3251. TX_FIFO_LAST_LIST);
  3252. #ifdef NETIF_F_TSO
  3253. if (mss)
  3254. val64 |= TX_FIFO_SPECIAL_FUNC;
  3255. #endif
  3256. writeq(val64, &tx_fifo->List_Control);
  3257. mmiowb();
  3258. put_off++;
  3259. put_off %= mac_control->fifos[queue].tx_curr_put_info.fifo_len + 1;
  3260. mac_control->fifos[queue].tx_curr_put_info.offset = put_off;
  3261. /* Avoid "put" pointer going beyond "get" pointer */
  3262. if (((put_off + 1) % queue_len) == get_off) {
  3263. DBG_PRINT(TX_DBG,
  3264. "No free TxDs for xmit, Put: 0x%x Get:0x%x\n",
  3265. put_off, get_off);
  3266. netif_stop_queue(dev);
  3267. }
  3268. dev->trans_start = jiffies;
  3269. spin_unlock_irqrestore(&sp->tx_lock, flags);
  3270. return 0;
  3271. }
  3272. static void
  3273. s2io_alarm_handle(unsigned long data)
  3274. {
  3275. nic_t *sp = (nic_t *)data;
  3276. alarm_intr_handler(sp);
  3277. mod_timer(&sp->alarm_timer, jiffies + HZ / 2);
  3278. }
  3279. static irqreturn_t
  3280. s2io_msi_handle(int irq, void *dev_id, struct pt_regs *regs)
  3281. {
  3282. struct net_device *dev = (struct net_device *) dev_id;
  3283. nic_t *sp = dev->priv;
  3284. int i;
  3285. int ret;
  3286. mac_info_t *mac_control;
  3287. struct config_param *config;
  3288. atomic_inc(&sp->isr_cnt);
  3289. mac_control = &sp->mac_control;
  3290. config = &sp->config;
  3291. DBG_PRINT(INTR_DBG, "%s: MSI handler\n", __FUNCTION__);
  3292. /* If Intr is because of Rx Traffic */
  3293. for (i = 0; i < config->rx_ring_num; i++)
  3294. rx_intr_handler(&mac_control->rings[i]);
  3295. /* If Intr is because of Tx Traffic */
  3296. for (i = 0; i < config->tx_fifo_num; i++)
  3297. tx_intr_handler(&mac_control->fifos[i]);
  3298. /*
  3299. * If the Rx buffer count is below the panic threshold then
  3300. * reallocate the buffers from the interrupt handler itself,
  3301. * else schedule a tasklet to reallocate the buffers.
  3302. */
  3303. for (i = 0; i < config->rx_ring_num; i++) {
  3304. int rxb_size = atomic_read(&sp->rx_bufs_left[i]);
  3305. int level = rx_buffer_level(sp, rxb_size, i);
  3306. if ((level == PANIC) && (!TASKLET_IN_USE)) {
  3307. DBG_PRINT(INTR_DBG, "%s: Rx BD hit ", dev->name);
  3308. DBG_PRINT(INTR_DBG, "PANIC levels\n");
  3309. if ((ret = fill_rx_buffers(sp, i)) == -ENOMEM) {
  3310. DBG_PRINT(ERR_DBG, "%s:Out of memory",
  3311. dev->name);
  3312. DBG_PRINT(ERR_DBG, " in ISR!!\n");
  3313. clear_bit(0, (&sp->tasklet_status));
  3314. atomic_dec(&sp->isr_cnt);
  3315. return IRQ_HANDLED;
  3316. }
  3317. clear_bit(0, (&sp->tasklet_status));
  3318. } else if (level == LOW) {
  3319. tasklet_schedule(&sp->task);
  3320. }
  3321. }
  3322. atomic_dec(&sp->isr_cnt);
  3323. return IRQ_HANDLED;
  3324. }
  3325. static irqreturn_t
  3326. s2io_msix_ring_handle(int irq, void *dev_id, struct pt_regs *regs)
  3327. {
  3328. ring_info_t *ring = (ring_info_t *)dev_id;
  3329. nic_t *sp = ring->nic;
  3330. int rxb_size, level, rng_n;
  3331. atomic_inc(&sp->isr_cnt);
  3332. rx_intr_handler(ring);
  3333. rng_n = ring->ring_no;
  3334. rxb_size = atomic_read(&sp->rx_bufs_left[rng_n]);
  3335. level = rx_buffer_level(sp, rxb_size, rng_n);
  3336. if ((level == PANIC) && (!TASKLET_IN_USE)) {
  3337. int ret;
  3338. DBG_PRINT(INTR_DBG, "%s: Rx BD hit ", __FUNCTION__);
  3339. DBG_PRINT(INTR_DBG, "PANIC levels\n");
  3340. if ((ret = fill_rx_buffers(sp, rng_n)) == -ENOMEM) {
  3341. DBG_PRINT(ERR_DBG, "Out of memory in %s",
  3342. __FUNCTION__);
  3343. clear_bit(0, (&sp->tasklet_status));
  3344. return IRQ_HANDLED;
  3345. }
  3346. clear_bit(0, (&sp->tasklet_status));
  3347. } else if (level == LOW) {
  3348. tasklet_schedule(&sp->task);
  3349. }
  3350. atomic_dec(&sp->isr_cnt);
  3351. return IRQ_HANDLED;
  3352. }
  3353. static irqreturn_t
  3354. s2io_msix_fifo_handle(int irq, void *dev_id, struct pt_regs *regs)
  3355. {
  3356. fifo_info_t *fifo = (fifo_info_t *)dev_id;
  3357. nic_t *sp = fifo->nic;
  3358. atomic_inc(&sp->isr_cnt);
  3359. tx_intr_handler(fifo);
  3360. atomic_dec(&sp->isr_cnt);
  3361. return IRQ_HANDLED;
  3362. }
  3363. static void s2io_txpic_intr_handle(nic_t *sp)
  3364. {
  3365. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  3366. u64 val64;
  3367. val64 = readq(&bar0->pic_int_status);
  3368. if (val64 & PIC_INT_GPIO) {
  3369. val64 = readq(&bar0->gpio_int_reg);
  3370. if ((val64 & GPIO_INT_REG_LINK_DOWN) &&
  3371. (val64 & GPIO_INT_REG_LINK_UP)) {
  3372. val64 |= GPIO_INT_REG_LINK_DOWN;
  3373. val64 |= GPIO_INT_REG_LINK_UP;
  3374. writeq(val64, &bar0->gpio_int_reg);
  3375. goto masking;
  3376. }
  3377. if (((sp->last_link_state == LINK_UP) &&
  3378. (val64 & GPIO_INT_REG_LINK_DOWN)) ||
  3379. ((sp->last_link_state == LINK_DOWN) &&
  3380. (val64 & GPIO_INT_REG_LINK_UP))) {
  3381. val64 = readq(&bar0->gpio_int_mask);
  3382. val64 |= GPIO_INT_MASK_LINK_DOWN;
  3383. val64 |= GPIO_INT_MASK_LINK_UP;
  3384. writeq(val64, &bar0->gpio_int_mask);
  3385. s2io_set_link((unsigned long)sp);
  3386. }
  3387. masking:
  3388. if (sp->last_link_state == LINK_UP) {
  3389. /*enable down interrupt */
  3390. val64 = readq(&bar0->gpio_int_mask);
  3391. /* unmasks link down intr */
  3392. val64 &= ~GPIO_INT_MASK_LINK_DOWN;
  3393. /* masks link up intr */
  3394. val64 |= GPIO_INT_MASK_LINK_UP;
  3395. writeq(val64, &bar0->gpio_int_mask);
  3396. } else {
  3397. /*enable UP Interrupt */
  3398. val64 = readq(&bar0->gpio_int_mask);
  3399. /* unmasks link up interrupt */
  3400. val64 &= ~GPIO_INT_MASK_LINK_UP;
  3401. /* masks link down interrupt */
  3402. val64 |= GPIO_INT_MASK_LINK_DOWN;
  3403. writeq(val64, &bar0->gpio_int_mask);
  3404. }
  3405. }
  3406. }
  3407. /**
  3408. * s2io_isr - ISR handler of the device .
  3409. * @irq: the irq of the device.
  3410. * @dev_id: a void pointer to the dev structure of the NIC.
  3411. * @pt_regs: pointer to the registers pushed on the stack.
  3412. * Description: This function is the ISR handler of the device. It
  3413. * identifies the reason for the interrupt and calls the relevant
  3414. * service routines. As a contongency measure, this ISR allocates the
  3415. * recv buffers, if their numbers are below the panic value which is
  3416. * presently set to 25% of the original number of rcv buffers allocated.
  3417. * Return value:
  3418. * IRQ_HANDLED: will be returned if IRQ was handled by this routine
  3419. * IRQ_NONE: will be returned if interrupt is not from our device
  3420. */
  3421. static irqreturn_t s2io_isr(int irq, void *dev_id, struct pt_regs *regs)
  3422. {
  3423. struct net_device *dev = (struct net_device *) dev_id;
  3424. nic_t *sp = dev->priv;
  3425. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  3426. int i;
  3427. u64 reason = 0, val64;
  3428. mac_info_t *mac_control;
  3429. struct config_param *config;
  3430. atomic_inc(&sp->isr_cnt);
  3431. mac_control = &sp->mac_control;
  3432. config = &sp->config;
  3433. /*
  3434. * Identify the cause for interrupt and call the appropriate
  3435. * interrupt handler. Causes for the interrupt could be;
  3436. * 1. Rx of packet.
  3437. * 2. Tx complete.
  3438. * 3. Link down.
  3439. * 4. Error in any functional blocks of the NIC.
  3440. */
  3441. reason = readq(&bar0->general_int_status);
  3442. if (!reason) {
  3443. /* The interrupt was not raised by Xena. */
  3444. atomic_dec(&sp->isr_cnt);
  3445. return IRQ_NONE;
  3446. }
  3447. #ifdef CONFIG_S2IO_NAPI
  3448. if (reason & GEN_INTR_RXTRAFFIC) {
  3449. if (netif_rx_schedule_prep(dev)) {
  3450. en_dis_able_nic_intrs(sp, RX_TRAFFIC_INTR,
  3451. DISABLE_INTRS);
  3452. __netif_rx_schedule(dev);
  3453. }
  3454. }
  3455. #else
  3456. /* If Intr is because of Rx Traffic */
  3457. if (reason & GEN_INTR_RXTRAFFIC) {
  3458. /*
  3459. * rx_traffic_int reg is an R1 register, writing all 1's
  3460. * will ensure that the actual interrupt causing bit get's
  3461. * cleared and hence a read can be avoided.
  3462. */
  3463. val64 = 0xFFFFFFFFFFFFFFFFULL;
  3464. writeq(val64, &bar0->rx_traffic_int);
  3465. for (i = 0; i < config->rx_ring_num; i++) {
  3466. rx_intr_handler(&mac_control->rings[i]);
  3467. }
  3468. }
  3469. #endif
  3470. /* If Intr is because of Tx Traffic */
  3471. if (reason & GEN_INTR_TXTRAFFIC) {
  3472. /*
  3473. * tx_traffic_int reg is an R1 register, writing all 1's
  3474. * will ensure that the actual interrupt causing bit get's
  3475. * cleared and hence a read can be avoided.
  3476. */
  3477. val64 = 0xFFFFFFFFFFFFFFFFULL;
  3478. writeq(val64, &bar0->tx_traffic_int);
  3479. for (i = 0; i < config->tx_fifo_num; i++)
  3480. tx_intr_handler(&mac_control->fifos[i]);
  3481. }
  3482. if (reason & GEN_INTR_TXPIC)
  3483. s2io_txpic_intr_handle(sp);
  3484. /*
  3485. * If the Rx buffer count is below the panic threshold then
  3486. * reallocate the buffers from the interrupt handler itself,
  3487. * else schedule a tasklet to reallocate the buffers.
  3488. */
  3489. #ifndef CONFIG_S2IO_NAPI
  3490. for (i = 0; i < config->rx_ring_num; i++) {
  3491. int ret;
  3492. int rxb_size = atomic_read(&sp->rx_bufs_left[i]);
  3493. int level = rx_buffer_level(sp, rxb_size, i);
  3494. if ((level == PANIC) && (!TASKLET_IN_USE)) {
  3495. DBG_PRINT(INTR_DBG, "%s: Rx BD hit ", dev->name);
  3496. DBG_PRINT(INTR_DBG, "PANIC levels\n");
  3497. if ((ret = fill_rx_buffers(sp, i)) == -ENOMEM) {
  3498. DBG_PRINT(ERR_DBG, "%s:Out of memory",
  3499. dev->name);
  3500. DBG_PRINT(ERR_DBG, " in ISR!!\n");
  3501. clear_bit(0, (&sp->tasklet_status));
  3502. atomic_dec(&sp->isr_cnt);
  3503. return IRQ_HANDLED;
  3504. }
  3505. clear_bit(0, (&sp->tasklet_status));
  3506. } else if (level == LOW) {
  3507. tasklet_schedule(&sp->task);
  3508. }
  3509. }
  3510. #endif
  3511. atomic_dec(&sp->isr_cnt);
  3512. return IRQ_HANDLED;
  3513. }
  3514. /**
  3515. * s2io_updt_stats -
  3516. */
  3517. static void s2io_updt_stats(nic_t *sp)
  3518. {
  3519. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  3520. u64 val64;
  3521. int cnt = 0;
  3522. if (atomic_read(&sp->card_state) == CARD_UP) {
  3523. /* Apprx 30us on a 133 MHz bus */
  3524. val64 = SET_UPDT_CLICKS(10) |
  3525. STAT_CFG_ONE_SHOT_EN | STAT_CFG_STAT_EN;
  3526. writeq(val64, &bar0->stat_cfg);
  3527. do {
  3528. udelay(100);
  3529. val64 = readq(&bar0->stat_cfg);
  3530. if (!(val64 & BIT(0)))
  3531. break;
  3532. cnt++;
  3533. if (cnt == 5)
  3534. break; /* Updt failed */
  3535. } while(1);
  3536. }
  3537. }
  3538. /**
  3539. * s2io_get_stats - Updates the device statistics structure.
  3540. * @dev : pointer to the device structure.
  3541. * Description:
  3542. * This function updates the device statistics structure in the s2io_nic
  3543. * structure and returns a pointer to the same.
  3544. * Return value:
  3545. * pointer to the updated net_device_stats structure.
  3546. */
  3547. static struct net_device_stats *s2io_get_stats(struct net_device *dev)
  3548. {
  3549. nic_t *sp = dev->priv;
  3550. mac_info_t *mac_control;
  3551. struct config_param *config;
  3552. mac_control = &sp->mac_control;
  3553. config = &sp->config;
  3554. /* Configure Stats for immediate updt */
  3555. s2io_updt_stats(sp);
  3556. sp->stats.tx_packets =
  3557. le32_to_cpu(mac_control->stats_info->tmac_frms);
  3558. sp->stats.tx_errors =
  3559. le32_to_cpu(mac_control->stats_info->tmac_any_err_frms);
  3560. sp->stats.rx_errors =
  3561. le32_to_cpu(mac_control->stats_info->rmac_drop_frms);
  3562. sp->stats.multicast =
  3563. le32_to_cpu(mac_control->stats_info->rmac_vld_mcst_frms);
  3564. sp->stats.rx_length_errors =
  3565. le32_to_cpu(mac_control->stats_info->rmac_long_frms);
  3566. return (&sp->stats);
  3567. }
  3568. /**
  3569. * s2io_set_multicast - entry point for multicast address enable/disable.
  3570. * @dev : pointer to the device structure
  3571. * Description:
  3572. * This function is a driver entry point which gets called by the kernel
  3573. * whenever multicast addresses must be enabled/disabled. This also gets
  3574. * called to set/reset promiscuous mode. Depending on the deivce flag, we
  3575. * determine, if multicast address must be enabled or if promiscuous mode
  3576. * is to be disabled etc.
  3577. * Return value:
  3578. * void.
  3579. */
  3580. static void s2io_set_multicast(struct net_device *dev)
  3581. {
  3582. int i, j, prev_cnt;
  3583. struct dev_mc_list *mclist;
  3584. nic_t *sp = dev->priv;
  3585. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  3586. u64 val64 = 0, multi_mac = 0x010203040506ULL, mask =
  3587. 0xfeffffffffffULL;
  3588. u64 dis_addr = 0xffffffffffffULL, mac_addr = 0;
  3589. void __iomem *add;
  3590. if ((dev->flags & IFF_ALLMULTI) && (!sp->m_cast_flg)) {
  3591. /* Enable all Multicast addresses */
  3592. writeq(RMAC_ADDR_DATA0_MEM_ADDR(multi_mac),
  3593. &bar0->rmac_addr_data0_mem);
  3594. writeq(RMAC_ADDR_DATA1_MEM_MASK(mask),
  3595. &bar0->rmac_addr_data1_mem);
  3596. val64 = RMAC_ADDR_CMD_MEM_WE |
  3597. RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  3598. RMAC_ADDR_CMD_MEM_OFFSET(MAC_MC_ALL_MC_ADDR_OFFSET);
  3599. writeq(val64, &bar0->rmac_addr_cmd_mem);
  3600. /* Wait till command completes */
  3601. wait_for_cmd_complete(sp);
  3602. sp->m_cast_flg = 1;
  3603. sp->all_multi_pos = MAC_MC_ALL_MC_ADDR_OFFSET;
  3604. } else if ((dev->flags & IFF_ALLMULTI) && (sp->m_cast_flg)) {
  3605. /* Disable all Multicast addresses */
  3606. writeq(RMAC_ADDR_DATA0_MEM_ADDR(dis_addr),
  3607. &bar0->rmac_addr_data0_mem);
  3608. writeq(RMAC_ADDR_DATA1_MEM_MASK(0x0),
  3609. &bar0->rmac_addr_data1_mem);
  3610. val64 = RMAC_ADDR_CMD_MEM_WE |
  3611. RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  3612. RMAC_ADDR_CMD_MEM_OFFSET(sp->all_multi_pos);
  3613. writeq(val64, &bar0->rmac_addr_cmd_mem);
  3614. /* Wait till command completes */
  3615. wait_for_cmd_complete(sp);
  3616. sp->m_cast_flg = 0;
  3617. sp->all_multi_pos = 0;
  3618. }
  3619. if ((dev->flags & IFF_PROMISC) && (!sp->promisc_flg)) {
  3620. /* Put the NIC into promiscuous mode */
  3621. add = &bar0->mac_cfg;
  3622. val64 = readq(&bar0->mac_cfg);
  3623. val64 |= MAC_CFG_RMAC_PROM_ENABLE;
  3624. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  3625. writel((u32) val64, add);
  3626. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  3627. writel((u32) (val64 >> 32), (add + 4));
  3628. val64 = readq(&bar0->mac_cfg);
  3629. sp->promisc_flg = 1;
  3630. DBG_PRINT(INFO_DBG, "%s: entered promiscuous mode\n",
  3631. dev->name);
  3632. } else if (!(dev->flags & IFF_PROMISC) && (sp->promisc_flg)) {
  3633. /* Remove the NIC from promiscuous mode */
  3634. add = &bar0->mac_cfg;
  3635. val64 = readq(&bar0->mac_cfg);
  3636. val64 &= ~MAC_CFG_RMAC_PROM_ENABLE;
  3637. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  3638. writel((u32) val64, add);
  3639. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  3640. writel((u32) (val64 >> 32), (add + 4));
  3641. val64 = readq(&bar0->mac_cfg);
  3642. sp->promisc_flg = 0;
  3643. DBG_PRINT(INFO_DBG, "%s: left promiscuous mode\n",
  3644. dev->name);
  3645. }
  3646. /* Update individual M_CAST address list */
  3647. if ((!sp->m_cast_flg) && dev->mc_count) {
  3648. if (dev->mc_count >
  3649. (MAX_ADDRS_SUPPORTED - MAC_MC_ADDR_START_OFFSET - 1)) {
  3650. DBG_PRINT(ERR_DBG, "%s: No more Rx filters ",
  3651. dev->name);
  3652. DBG_PRINT(ERR_DBG, "can be added, please enable ");
  3653. DBG_PRINT(ERR_DBG, "ALL_MULTI instead\n");
  3654. return;
  3655. }
  3656. prev_cnt = sp->mc_addr_count;
  3657. sp->mc_addr_count = dev->mc_count;
  3658. /* Clear out the previous list of Mc in the H/W. */
  3659. for (i = 0; i < prev_cnt; i++) {
  3660. writeq(RMAC_ADDR_DATA0_MEM_ADDR(dis_addr),
  3661. &bar0->rmac_addr_data0_mem);
  3662. writeq(RMAC_ADDR_DATA1_MEM_MASK(0ULL),
  3663. &bar0->rmac_addr_data1_mem);
  3664. val64 = RMAC_ADDR_CMD_MEM_WE |
  3665. RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  3666. RMAC_ADDR_CMD_MEM_OFFSET
  3667. (MAC_MC_ADDR_START_OFFSET + i);
  3668. writeq(val64, &bar0->rmac_addr_cmd_mem);
  3669. /* Wait for command completes */
  3670. if (wait_for_cmd_complete(sp)) {
  3671. DBG_PRINT(ERR_DBG, "%s: Adding ",
  3672. dev->name);
  3673. DBG_PRINT(ERR_DBG, "Multicasts failed\n");
  3674. return;
  3675. }
  3676. }
  3677. /* Create the new Rx filter list and update the same in H/W. */
  3678. for (i = 0, mclist = dev->mc_list; i < dev->mc_count;
  3679. i++, mclist = mclist->next) {
  3680. memcpy(sp->usr_addrs[i].addr, mclist->dmi_addr,
  3681. ETH_ALEN);
  3682. for (j = 0; j < ETH_ALEN; j++) {
  3683. mac_addr |= mclist->dmi_addr[j];
  3684. mac_addr <<= 8;
  3685. }
  3686. mac_addr >>= 8;
  3687. writeq(RMAC_ADDR_DATA0_MEM_ADDR(mac_addr),
  3688. &bar0->rmac_addr_data0_mem);
  3689. writeq(RMAC_ADDR_DATA1_MEM_MASK(0ULL),
  3690. &bar0->rmac_addr_data1_mem);
  3691. val64 = RMAC_ADDR_CMD_MEM_WE |
  3692. RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  3693. RMAC_ADDR_CMD_MEM_OFFSET
  3694. (i + MAC_MC_ADDR_START_OFFSET);
  3695. writeq(val64, &bar0->rmac_addr_cmd_mem);
  3696. /* Wait for command completes */
  3697. if (wait_for_cmd_complete(sp)) {
  3698. DBG_PRINT(ERR_DBG, "%s: Adding ",
  3699. dev->name);
  3700. DBG_PRINT(ERR_DBG, "Multicasts failed\n");
  3701. return;
  3702. }
  3703. }
  3704. }
  3705. }
  3706. /**
  3707. * s2io_set_mac_addr - Programs the Xframe mac address
  3708. * @dev : pointer to the device structure.
  3709. * @addr: a uchar pointer to the new mac address which is to be set.
  3710. * Description : This procedure will program the Xframe to receive
  3711. * frames with new Mac Address
  3712. * Return value: SUCCESS on success and an appropriate (-)ve integer
  3713. * as defined in errno.h file on failure.
  3714. */
  3715. int s2io_set_mac_addr(struct net_device *dev, u8 * addr)
  3716. {
  3717. nic_t *sp = dev->priv;
  3718. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  3719. register u64 val64, mac_addr = 0;
  3720. int i;
  3721. /*
  3722. * Set the new MAC address as the new unicast filter and reflect this
  3723. * change on the device address registered with the OS. It will be
  3724. * at offset 0.
  3725. */
  3726. for (i = 0; i < ETH_ALEN; i++) {
  3727. mac_addr <<= 8;
  3728. mac_addr |= addr[i];
  3729. }
  3730. writeq(RMAC_ADDR_DATA0_MEM_ADDR(mac_addr),
  3731. &bar0->rmac_addr_data0_mem);
  3732. val64 =
  3733. RMAC_ADDR_CMD_MEM_WE | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  3734. RMAC_ADDR_CMD_MEM_OFFSET(0);
  3735. writeq(val64, &bar0->rmac_addr_cmd_mem);
  3736. /* Wait till command completes */
  3737. if (wait_for_cmd_complete(sp)) {
  3738. DBG_PRINT(ERR_DBG, "%s: set_mac_addr failed\n", dev->name);
  3739. return FAILURE;
  3740. }
  3741. return SUCCESS;
  3742. }
  3743. /**
  3744. * s2io_ethtool_sset - Sets different link parameters.
  3745. * @sp : private member of the device structure, which is a pointer to the * s2io_nic structure.
  3746. * @info: pointer to the structure with parameters given by ethtool to set
  3747. * link information.
  3748. * Description:
  3749. * The function sets different link parameters provided by the user onto
  3750. * the NIC.
  3751. * Return value:
  3752. * 0 on success.
  3753. */
  3754. static int s2io_ethtool_sset(struct net_device *dev,
  3755. struct ethtool_cmd *info)
  3756. {
  3757. nic_t *sp = dev->priv;
  3758. if ((info->autoneg == AUTONEG_ENABLE) ||
  3759. (info->speed != SPEED_10000) || (info->duplex != DUPLEX_FULL))
  3760. return -EINVAL;
  3761. else {
  3762. s2io_close(sp->dev);
  3763. s2io_open(sp->dev);
  3764. }
  3765. return 0;
  3766. }
  3767. /**
  3768. * s2io_ethtol_gset - Return link specific information.
  3769. * @sp : private member of the device structure, pointer to the
  3770. * s2io_nic structure.
  3771. * @info : pointer to the structure with parameters given by ethtool
  3772. * to return link information.
  3773. * Description:
  3774. * Returns link specific information like speed, duplex etc.. to ethtool.
  3775. * Return value :
  3776. * return 0 on success.
  3777. */
  3778. static int s2io_ethtool_gset(struct net_device *dev, struct ethtool_cmd *info)
  3779. {
  3780. nic_t *sp = dev->priv;
  3781. info->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  3782. info->advertising = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  3783. info->port = PORT_FIBRE;
  3784. /* info->transceiver?? TODO */
  3785. if (netif_carrier_ok(sp->dev)) {
  3786. info->speed = 10000;
  3787. info->duplex = DUPLEX_FULL;
  3788. } else {
  3789. info->speed = -1;
  3790. info->duplex = -1;
  3791. }
  3792. info->autoneg = AUTONEG_DISABLE;
  3793. return 0;
  3794. }
  3795. /**
  3796. * s2io_ethtool_gdrvinfo - Returns driver specific information.
  3797. * @sp : private member of the device structure, which is a pointer to the
  3798. * s2io_nic structure.
  3799. * @info : pointer to the structure with parameters given by ethtool to
  3800. * return driver information.
  3801. * Description:
  3802. * Returns driver specefic information like name, version etc.. to ethtool.
  3803. * Return value:
  3804. * void
  3805. */
  3806. static void s2io_ethtool_gdrvinfo(struct net_device *dev,
  3807. struct ethtool_drvinfo *info)
  3808. {
  3809. nic_t *sp = dev->priv;
  3810. strncpy(info->driver, s2io_driver_name, sizeof(info->driver));
  3811. strncpy(info->version, s2io_driver_version, sizeof(info->version));
  3812. strncpy(info->fw_version, "", sizeof(info->fw_version));
  3813. strncpy(info->bus_info, pci_name(sp->pdev), sizeof(info->bus_info));
  3814. info->regdump_len = XENA_REG_SPACE;
  3815. info->eedump_len = XENA_EEPROM_SPACE;
  3816. info->testinfo_len = S2IO_TEST_LEN;
  3817. info->n_stats = S2IO_STAT_LEN;
  3818. }
  3819. /**
  3820. * s2io_ethtool_gregs - dumps the entire space of Xfame into the buffer.
  3821. * @sp: private member of the device structure, which is a pointer to the
  3822. * s2io_nic structure.
  3823. * @regs : pointer to the structure with parameters given by ethtool for
  3824. * dumping the registers.
  3825. * @reg_space: The input argumnet into which all the registers are dumped.
  3826. * Description:
  3827. * Dumps the entire register space of xFrame NIC into the user given
  3828. * buffer area.
  3829. * Return value :
  3830. * void .
  3831. */
  3832. static void s2io_ethtool_gregs(struct net_device *dev,
  3833. struct ethtool_regs *regs, void *space)
  3834. {
  3835. int i;
  3836. u64 reg;
  3837. u8 *reg_space = (u8 *) space;
  3838. nic_t *sp = dev->priv;
  3839. regs->len = XENA_REG_SPACE;
  3840. regs->version = sp->pdev->subsystem_device;
  3841. for (i = 0; i < regs->len; i += 8) {
  3842. reg = readq(sp->bar0 + i);
  3843. memcpy((reg_space + i), &reg, 8);
  3844. }
  3845. }
  3846. /**
  3847. * s2io_phy_id - timer function that alternates adapter LED.
  3848. * @data : address of the private member of the device structure, which
  3849. * is a pointer to the s2io_nic structure, provided as an u32.
  3850. * Description: This is actually the timer function that alternates the
  3851. * adapter LED bit of the adapter control bit to set/reset every time on
  3852. * invocation. The timer is set for 1/2 a second, hence tha NIC blinks
  3853. * once every second.
  3854. */
  3855. static void s2io_phy_id(unsigned long data)
  3856. {
  3857. nic_t *sp = (nic_t *) data;
  3858. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  3859. u64 val64 = 0;
  3860. u16 subid;
  3861. subid = sp->pdev->subsystem_device;
  3862. if ((sp->device_type == XFRAME_II_DEVICE) ||
  3863. ((subid & 0xFF) >= 0x07)) {
  3864. val64 = readq(&bar0->gpio_control);
  3865. val64 ^= GPIO_CTRL_GPIO_0;
  3866. writeq(val64, &bar0->gpio_control);
  3867. } else {
  3868. val64 = readq(&bar0->adapter_control);
  3869. val64 ^= ADAPTER_LED_ON;
  3870. writeq(val64, &bar0->adapter_control);
  3871. }
  3872. mod_timer(&sp->id_timer, jiffies + HZ / 2);
  3873. }
  3874. /**
  3875. * s2io_ethtool_idnic - To physically identify the nic on the system.
  3876. * @sp : private member of the device structure, which is a pointer to the
  3877. * s2io_nic structure.
  3878. * @id : pointer to the structure with identification parameters given by
  3879. * ethtool.
  3880. * Description: Used to physically identify the NIC on the system.
  3881. * The Link LED will blink for a time specified by the user for
  3882. * identification.
  3883. * NOTE: The Link has to be Up to be able to blink the LED. Hence
  3884. * identification is possible only if it's link is up.
  3885. * Return value:
  3886. * int , returns 0 on success
  3887. */
  3888. static int s2io_ethtool_idnic(struct net_device *dev, u32 data)
  3889. {
  3890. u64 val64 = 0, last_gpio_ctrl_val;
  3891. nic_t *sp = dev->priv;
  3892. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  3893. u16 subid;
  3894. subid = sp->pdev->subsystem_device;
  3895. last_gpio_ctrl_val = readq(&bar0->gpio_control);
  3896. if ((sp->device_type == XFRAME_I_DEVICE) &&
  3897. ((subid & 0xFF) < 0x07)) {
  3898. val64 = readq(&bar0->adapter_control);
  3899. if (!(val64 & ADAPTER_CNTL_EN)) {
  3900. printk(KERN_ERR
  3901. "Adapter Link down, cannot blink LED\n");
  3902. return -EFAULT;
  3903. }
  3904. }
  3905. if (sp->id_timer.function == NULL) {
  3906. init_timer(&sp->id_timer);
  3907. sp->id_timer.function = s2io_phy_id;
  3908. sp->id_timer.data = (unsigned long) sp;
  3909. }
  3910. mod_timer(&sp->id_timer, jiffies);
  3911. if (data)
  3912. msleep_interruptible(data * HZ);
  3913. else
  3914. msleep_interruptible(MAX_FLICKER_TIME);
  3915. del_timer_sync(&sp->id_timer);
  3916. if (CARDS_WITH_FAULTY_LINK_INDICATORS(sp->device_type, subid)) {
  3917. writeq(last_gpio_ctrl_val, &bar0->gpio_control);
  3918. last_gpio_ctrl_val = readq(&bar0->gpio_control);
  3919. }
  3920. return 0;
  3921. }
  3922. /**
  3923. * s2io_ethtool_getpause_data -Pause frame frame generation and reception.
  3924. * @sp : private member of the device structure, which is a pointer to the
  3925. * s2io_nic structure.
  3926. * @ep : pointer to the structure with pause parameters given by ethtool.
  3927. * Description:
  3928. * Returns the Pause frame generation and reception capability of the NIC.
  3929. * Return value:
  3930. * void
  3931. */
  3932. static void s2io_ethtool_getpause_data(struct net_device *dev,
  3933. struct ethtool_pauseparam *ep)
  3934. {
  3935. u64 val64;
  3936. nic_t *sp = dev->priv;
  3937. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  3938. val64 = readq(&bar0->rmac_pause_cfg);
  3939. if (val64 & RMAC_PAUSE_GEN_ENABLE)
  3940. ep->tx_pause = TRUE;
  3941. if (val64 & RMAC_PAUSE_RX_ENABLE)
  3942. ep->rx_pause = TRUE;
  3943. ep->autoneg = FALSE;
  3944. }
  3945. /**
  3946. * s2io_ethtool_setpause_data - set/reset pause frame generation.
  3947. * @sp : private member of the device structure, which is a pointer to the
  3948. * s2io_nic structure.
  3949. * @ep : pointer to the structure with pause parameters given by ethtool.
  3950. * Description:
  3951. * It can be used to set or reset Pause frame generation or reception
  3952. * support of the NIC.
  3953. * Return value:
  3954. * int, returns 0 on Success
  3955. */
  3956. static int s2io_ethtool_setpause_data(struct net_device *dev,
  3957. struct ethtool_pauseparam *ep)
  3958. {
  3959. u64 val64;
  3960. nic_t *sp = dev->priv;
  3961. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  3962. val64 = readq(&bar0->rmac_pause_cfg);
  3963. if (ep->tx_pause)
  3964. val64 |= RMAC_PAUSE_GEN_ENABLE;
  3965. else
  3966. val64 &= ~RMAC_PAUSE_GEN_ENABLE;
  3967. if (ep->rx_pause)
  3968. val64 |= RMAC_PAUSE_RX_ENABLE;
  3969. else
  3970. val64 &= ~RMAC_PAUSE_RX_ENABLE;
  3971. writeq(val64, &bar0->rmac_pause_cfg);
  3972. return 0;
  3973. }
  3974. /**
  3975. * read_eeprom - reads 4 bytes of data from user given offset.
  3976. * @sp : private member of the device structure, which is a pointer to the
  3977. * s2io_nic structure.
  3978. * @off : offset at which the data must be written
  3979. * @data : Its an output parameter where the data read at the given
  3980. * offset is stored.
  3981. * Description:
  3982. * Will read 4 bytes of data from the user given offset and return the
  3983. * read data.
  3984. * NOTE: Will allow to read only part of the EEPROM visible through the
  3985. * I2C bus.
  3986. * Return value:
  3987. * -1 on failure and 0 on success.
  3988. */
  3989. #define S2IO_DEV_ID 5
  3990. static int read_eeprom(nic_t * sp, int off, u64 * data)
  3991. {
  3992. int ret = -1;
  3993. u32 exit_cnt = 0;
  3994. u64 val64;
  3995. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  3996. if (sp->device_type == XFRAME_I_DEVICE) {
  3997. val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) |
  3998. I2C_CONTROL_BYTE_CNT(0x3) | I2C_CONTROL_READ |
  3999. I2C_CONTROL_CNTL_START;
  4000. SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF);
  4001. while (exit_cnt < 5) {
  4002. val64 = readq(&bar0->i2c_control);
  4003. if (I2C_CONTROL_CNTL_END(val64)) {
  4004. *data = I2C_CONTROL_GET_DATA(val64);
  4005. ret = 0;
  4006. break;
  4007. }
  4008. msleep(50);
  4009. exit_cnt++;
  4010. }
  4011. }
  4012. if (sp->device_type == XFRAME_II_DEVICE) {
  4013. val64 = SPI_CONTROL_KEY(0x9) | SPI_CONTROL_SEL1 |
  4014. SPI_CONTROL_BYTECNT(0x3) |
  4015. SPI_CONTROL_CMD(0x3) | SPI_CONTROL_ADDR(off);
  4016. SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
  4017. val64 |= SPI_CONTROL_REQ;
  4018. SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
  4019. while (exit_cnt < 5) {
  4020. val64 = readq(&bar0->spi_control);
  4021. if (val64 & SPI_CONTROL_NACK) {
  4022. ret = 1;
  4023. break;
  4024. } else if (val64 & SPI_CONTROL_DONE) {
  4025. *data = readq(&bar0->spi_data);
  4026. *data &= 0xffffff;
  4027. ret = 0;
  4028. break;
  4029. }
  4030. msleep(50);
  4031. exit_cnt++;
  4032. }
  4033. }
  4034. return ret;
  4035. }
  4036. /**
  4037. * write_eeprom - actually writes the relevant part of the data value.
  4038. * @sp : private member of the device structure, which is a pointer to the
  4039. * s2io_nic structure.
  4040. * @off : offset at which the data must be written
  4041. * @data : The data that is to be written
  4042. * @cnt : Number of bytes of the data that are actually to be written into
  4043. * the Eeprom. (max of 3)
  4044. * Description:
  4045. * Actually writes the relevant part of the data value into the Eeprom
  4046. * through the I2C bus.
  4047. * Return value:
  4048. * 0 on success, -1 on failure.
  4049. */
  4050. static int write_eeprom(nic_t * sp, int off, u64 data, int cnt)
  4051. {
  4052. int exit_cnt = 0, ret = -1;
  4053. u64 val64;
  4054. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  4055. if (sp->device_type == XFRAME_I_DEVICE) {
  4056. val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) |
  4057. I2C_CONTROL_BYTE_CNT(cnt) | I2C_CONTROL_SET_DATA((u32)data) |
  4058. I2C_CONTROL_CNTL_START;
  4059. SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF);
  4060. while (exit_cnt < 5) {
  4061. val64 = readq(&bar0->i2c_control);
  4062. if (I2C_CONTROL_CNTL_END(val64)) {
  4063. if (!(val64 & I2C_CONTROL_NACK))
  4064. ret = 0;
  4065. break;
  4066. }
  4067. msleep(50);
  4068. exit_cnt++;
  4069. }
  4070. }
  4071. if (sp->device_type == XFRAME_II_DEVICE) {
  4072. int write_cnt = (cnt == 8) ? 0 : cnt;
  4073. writeq(SPI_DATA_WRITE(data,(cnt<<3)), &bar0->spi_data);
  4074. val64 = SPI_CONTROL_KEY(0x9) | SPI_CONTROL_SEL1 |
  4075. SPI_CONTROL_BYTECNT(write_cnt) |
  4076. SPI_CONTROL_CMD(0x2) | SPI_CONTROL_ADDR(off);
  4077. SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
  4078. val64 |= SPI_CONTROL_REQ;
  4079. SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
  4080. while (exit_cnt < 5) {
  4081. val64 = readq(&bar0->spi_control);
  4082. if (val64 & SPI_CONTROL_NACK) {
  4083. ret = 1;
  4084. break;
  4085. } else if (val64 & SPI_CONTROL_DONE) {
  4086. ret = 0;
  4087. break;
  4088. }
  4089. msleep(50);
  4090. exit_cnt++;
  4091. }
  4092. }
  4093. return ret;
  4094. }
  4095. /**
  4096. * s2io_ethtool_geeprom - reads the value stored in the Eeprom.
  4097. * @sp : private member of the device structure, which is a pointer to the * s2io_nic structure.
  4098. * @eeprom : pointer to the user level structure provided by ethtool,
  4099. * containing all relevant information.
  4100. * @data_buf : user defined value to be written into Eeprom.
  4101. * Description: Reads the values stored in the Eeprom at given offset
  4102. * for a given length. Stores these values int the input argument data
  4103. * buffer 'data_buf' and returns these to the caller (ethtool.)
  4104. * Return value:
  4105. * int 0 on success
  4106. */
  4107. static int s2io_ethtool_geeprom(struct net_device *dev,
  4108. struct ethtool_eeprom *eeprom, u8 * data_buf)
  4109. {
  4110. u32 i, valid;
  4111. u64 data;
  4112. nic_t *sp = dev->priv;
  4113. eeprom->magic = sp->pdev->vendor | (sp->pdev->device << 16);
  4114. if ((eeprom->offset + eeprom->len) > (XENA_EEPROM_SPACE))
  4115. eeprom->len = XENA_EEPROM_SPACE - eeprom->offset;
  4116. for (i = 0; i < eeprom->len; i += 4) {
  4117. if (read_eeprom(sp, (eeprom->offset + i), &data)) {
  4118. DBG_PRINT(ERR_DBG, "Read of EEPROM failed\n");
  4119. return -EFAULT;
  4120. }
  4121. valid = INV(data);
  4122. memcpy((data_buf + i), &valid, 4);
  4123. }
  4124. return 0;
  4125. }
  4126. /**
  4127. * s2io_ethtool_seeprom - tries to write the user provided value in Eeprom
  4128. * @sp : private member of the device structure, which is a pointer to the
  4129. * s2io_nic structure.
  4130. * @eeprom : pointer to the user level structure provided by ethtool,
  4131. * containing all relevant information.
  4132. * @data_buf ; user defined value to be written into Eeprom.
  4133. * Description:
  4134. * Tries to write the user provided value in the Eeprom, at the offset
  4135. * given by the user.
  4136. * Return value:
  4137. * 0 on success, -EFAULT on failure.
  4138. */
  4139. static int s2io_ethtool_seeprom(struct net_device *dev,
  4140. struct ethtool_eeprom *eeprom,
  4141. u8 * data_buf)
  4142. {
  4143. int len = eeprom->len, cnt = 0;
  4144. u64 valid = 0, data;
  4145. nic_t *sp = dev->priv;
  4146. if (eeprom->magic != (sp->pdev->vendor | (sp->pdev->device << 16))) {
  4147. DBG_PRINT(ERR_DBG,
  4148. "ETHTOOL_WRITE_EEPROM Err: Magic value ");
  4149. DBG_PRINT(ERR_DBG, "is wrong, Its not 0x%x\n",
  4150. eeprom->magic);
  4151. return -EFAULT;
  4152. }
  4153. while (len) {
  4154. data = (u32) data_buf[cnt] & 0x000000FF;
  4155. if (data) {
  4156. valid = (u32) (data << 24);
  4157. } else
  4158. valid = data;
  4159. if (write_eeprom(sp, (eeprom->offset + cnt), valid, 0)) {
  4160. DBG_PRINT(ERR_DBG,
  4161. "ETHTOOL_WRITE_EEPROM Err: Cannot ");
  4162. DBG_PRINT(ERR_DBG,
  4163. "write into the specified offset\n");
  4164. return -EFAULT;
  4165. }
  4166. cnt++;
  4167. len--;
  4168. }
  4169. return 0;
  4170. }
  4171. /**
  4172. * s2io_register_test - reads and writes into all clock domains.
  4173. * @sp : private member of the device structure, which is a pointer to the
  4174. * s2io_nic structure.
  4175. * @data : variable that returns the result of each of the test conducted b
  4176. * by the driver.
  4177. * Description:
  4178. * Read and write into all clock domains. The NIC has 3 clock domains,
  4179. * see that registers in all the three regions are accessible.
  4180. * Return value:
  4181. * 0 on success.
  4182. */
  4183. static int s2io_register_test(nic_t * sp, uint64_t * data)
  4184. {
  4185. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  4186. u64 val64 = 0, exp_val;
  4187. int fail = 0;
  4188. val64 = readq(&bar0->pif_rd_swapper_fb);
  4189. if (val64 != 0x123456789abcdefULL) {
  4190. fail = 1;
  4191. DBG_PRINT(INFO_DBG, "Read Test level 1 fails\n");
  4192. }
  4193. val64 = readq(&bar0->rmac_pause_cfg);
  4194. if (val64 != 0xc000ffff00000000ULL) {
  4195. fail = 1;
  4196. DBG_PRINT(INFO_DBG, "Read Test level 2 fails\n");
  4197. }
  4198. val64 = readq(&bar0->rx_queue_cfg);
  4199. if (sp->device_type == XFRAME_II_DEVICE)
  4200. exp_val = 0x0404040404040404ULL;
  4201. else
  4202. exp_val = 0x0808080808080808ULL;
  4203. if (val64 != exp_val) {
  4204. fail = 1;
  4205. DBG_PRINT(INFO_DBG, "Read Test level 3 fails\n");
  4206. }
  4207. val64 = readq(&bar0->xgxs_efifo_cfg);
  4208. if (val64 != 0x000000001923141EULL) {
  4209. fail = 1;
  4210. DBG_PRINT(INFO_DBG, "Read Test level 4 fails\n");
  4211. }
  4212. val64 = 0x5A5A5A5A5A5A5A5AULL;
  4213. writeq(val64, &bar0->xmsi_data);
  4214. val64 = readq(&bar0->xmsi_data);
  4215. if (val64 != 0x5A5A5A5A5A5A5A5AULL) {
  4216. fail = 1;
  4217. DBG_PRINT(ERR_DBG, "Write Test level 1 fails\n");
  4218. }
  4219. val64 = 0xA5A5A5A5A5A5A5A5ULL;
  4220. writeq(val64, &bar0->xmsi_data);
  4221. val64 = readq(&bar0->xmsi_data);
  4222. if (val64 != 0xA5A5A5A5A5A5A5A5ULL) {
  4223. fail = 1;
  4224. DBG_PRINT(ERR_DBG, "Write Test level 2 fails\n");
  4225. }
  4226. *data = fail;
  4227. return fail;
  4228. }
  4229. /**
  4230. * s2io_eeprom_test - to verify that EEprom in the xena can be programmed.
  4231. * @sp : private member of the device structure, which is a pointer to the
  4232. * s2io_nic structure.
  4233. * @data:variable that returns the result of each of the test conducted by
  4234. * the driver.
  4235. * Description:
  4236. * Verify that EEPROM in the xena can be programmed using I2C_CONTROL
  4237. * register.
  4238. * Return value:
  4239. * 0 on success.
  4240. */
  4241. static int s2io_eeprom_test(nic_t * sp, uint64_t * data)
  4242. {
  4243. int fail = 0;
  4244. u64 ret_data, org_4F0, org_7F0;
  4245. u8 saved_4F0 = 0, saved_7F0 = 0;
  4246. struct net_device *dev = sp->dev;
  4247. /* Test Write Error at offset 0 */
  4248. /* Note that SPI interface allows write access to all areas
  4249. * of EEPROM. Hence doing all negative testing only for Xframe I.
  4250. */
  4251. if (sp->device_type == XFRAME_I_DEVICE)
  4252. if (!write_eeprom(sp, 0, 0, 3))
  4253. fail = 1;
  4254. /* Save current values at offsets 0x4F0 and 0x7F0 */
  4255. if (!read_eeprom(sp, 0x4F0, &org_4F0))
  4256. saved_4F0 = 1;
  4257. if (!read_eeprom(sp, 0x7F0, &org_7F0))
  4258. saved_7F0 = 1;
  4259. /* Test Write at offset 4f0 */
  4260. if (write_eeprom(sp, 0x4F0, 0x012345, 3))
  4261. fail = 1;
  4262. if (read_eeprom(sp, 0x4F0, &ret_data))
  4263. fail = 1;
  4264. if (ret_data != 0x012345) {
  4265. DBG_PRINT(ERR_DBG, "%s: eeprom test error at offset 0x4F0. Data written %llx Data read %llx\n", dev->name, (u64)0x12345, ret_data);
  4266. fail = 1;
  4267. }
  4268. /* Reset the EEPROM data go FFFF */
  4269. write_eeprom(sp, 0x4F0, 0xFFFFFF, 3);
  4270. /* Test Write Request Error at offset 0x7c */
  4271. if (sp->device_type == XFRAME_I_DEVICE)
  4272. if (!write_eeprom(sp, 0x07C, 0, 3))
  4273. fail = 1;
  4274. /* Test Write Request at offset 0x7f0 */
  4275. if (write_eeprom(sp, 0x7F0, 0x012345, 3))
  4276. fail = 1;
  4277. if (read_eeprom(sp, 0x7F0, &ret_data))
  4278. fail = 1;
  4279. if (ret_data != 0x012345) {
  4280. DBG_PRINT(ERR_DBG, "%s: eeprom test error at offset 0x7F0. Data written %llx Data read %llx\n", dev->name, (u64)0x12345, ret_data);
  4281. fail = 1;
  4282. }
  4283. /* Reset the EEPROM data go FFFF */
  4284. write_eeprom(sp, 0x7F0, 0xFFFFFF, 3);
  4285. if (sp->device_type == XFRAME_I_DEVICE) {
  4286. /* Test Write Error at offset 0x80 */
  4287. if (!write_eeprom(sp, 0x080, 0, 3))
  4288. fail = 1;
  4289. /* Test Write Error at offset 0xfc */
  4290. if (!write_eeprom(sp, 0x0FC, 0, 3))
  4291. fail = 1;
  4292. /* Test Write Error at offset 0x100 */
  4293. if (!write_eeprom(sp, 0x100, 0, 3))
  4294. fail = 1;
  4295. /* Test Write Error at offset 4ec */
  4296. if (!write_eeprom(sp, 0x4EC, 0, 3))
  4297. fail = 1;
  4298. }
  4299. /* Restore values at offsets 0x4F0 and 0x7F0 */
  4300. if (saved_4F0)
  4301. write_eeprom(sp, 0x4F0, org_4F0, 3);
  4302. if (saved_7F0)
  4303. write_eeprom(sp, 0x7F0, org_7F0, 3);
  4304. *data = fail;
  4305. return fail;
  4306. }
  4307. /**
  4308. * s2io_bist_test - invokes the MemBist test of the card .
  4309. * @sp : private member of the device structure, which is a pointer to the
  4310. * s2io_nic structure.
  4311. * @data:variable that returns the result of each of the test conducted by
  4312. * the driver.
  4313. * Description:
  4314. * This invokes the MemBist test of the card. We give around
  4315. * 2 secs time for the Test to complete. If it's still not complete
  4316. * within this peiod, we consider that the test failed.
  4317. * Return value:
  4318. * 0 on success and -1 on failure.
  4319. */
  4320. static int s2io_bist_test(nic_t * sp, uint64_t * data)
  4321. {
  4322. u8 bist = 0;
  4323. int cnt = 0, ret = -1;
  4324. pci_read_config_byte(sp->pdev, PCI_BIST, &bist);
  4325. bist |= PCI_BIST_START;
  4326. pci_write_config_word(sp->pdev, PCI_BIST, bist);
  4327. while (cnt < 20) {
  4328. pci_read_config_byte(sp->pdev, PCI_BIST, &bist);
  4329. if (!(bist & PCI_BIST_START)) {
  4330. *data = (bist & PCI_BIST_CODE_MASK);
  4331. ret = 0;
  4332. break;
  4333. }
  4334. msleep(100);
  4335. cnt++;
  4336. }
  4337. return ret;
  4338. }
  4339. /**
  4340. * s2io-link_test - verifies the link state of the nic
  4341. * @sp ; private member of the device structure, which is a pointer to the
  4342. * s2io_nic structure.
  4343. * @data: variable that returns the result of each of the test conducted by
  4344. * the driver.
  4345. * Description:
  4346. * The function verifies the link state of the NIC and updates the input
  4347. * argument 'data' appropriately.
  4348. * Return value:
  4349. * 0 on success.
  4350. */
  4351. static int s2io_link_test(nic_t * sp, uint64_t * data)
  4352. {
  4353. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  4354. u64 val64;
  4355. val64 = readq(&bar0->adapter_status);
  4356. if (val64 & ADAPTER_STATUS_RMAC_LOCAL_FAULT)
  4357. *data = 1;
  4358. return 0;
  4359. }
  4360. /**
  4361. * s2io_rldram_test - offline test for access to the RldRam chip on the NIC
  4362. * @sp - private member of the device structure, which is a pointer to the
  4363. * s2io_nic structure.
  4364. * @data - variable that returns the result of each of the test
  4365. * conducted by the driver.
  4366. * Description:
  4367. * This is one of the offline test that tests the read and write
  4368. * access to the RldRam chip on the NIC.
  4369. * Return value:
  4370. * 0 on success.
  4371. */
  4372. static int s2io_rldram_test(nic_t * sp, uint64_t * data)
  4373. {
  4374. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  4375. u64 val64;
  4376. int cnt, iteration = 0, test_fail = 0;
  4377. val64 = readq(&bar0->adapter_control);
  4378. val64 &= ~ADAPTER_ECC_EN;
  4379. writeq(val64, &bar0->adapter_control);
  4380. val64 = readq(&bar0->mc_rldram_test_ctrl);
  4381. val64 |= MC_RLDRAM_TEST_MODE;
  4382. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
  4383. val64 = readq(&bar0->mc_rldram_mrs);
  4384. val64 |= MC_RLDRAM_QUEUE_SIZE_ENABLE;
  4385. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
  4386. val64 |= MC_RLDRAM_MRS_ENABLE;
  4387. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
  4388. while (iteration < 2) {
  4389. val64 = 0x55555555aaaa0000ULL;
  4390. if (iteration == 1) {
  4391. val64 ^= 0xFFFFFFFFFFFF0000ULL;
  4392. }
  4393. writeq(val64, &bar0->mc_rldram_test_d0);
  4394. val64 = 0xaaaa5a5555550000ULL;
  4395. if (iteration == 1) {
  4396. val64 ^= 0xFFFFFFFFFFFF0000ULL;
  4397. }
  4398. writeq(val64, &bar0->mc_rldram_test_d1);
  4399. val64 = 0x55aaaaaaaa5a0000ULL;
  4400. if (iteration == 1) {
  4401. val64 ^= 0xFFFFFFFFFFFF0000ULL;
  4402. }
  4403. writeq(val64, &bar0->mc_rldram_test_d2);
  4404. val64 = (u64) (0x0000003ffffe0100ULL);
  4405. writeq(val64, &bar0->mc_rldram_test_add);
  4406. val64 = MC_RLDRAM_TEST_MODE | MC_RLDRAM_TEST_WRITE |
  4407. MC_RLDRAM_TEST_GO;
  4408. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
  4409. for (cnt = 0; cnt < 5; cnt++) {
  4410. val64 = readq(&bar0->mc_rldram_test_ctrl);
  4411. if (val64 & MC_RLDRAM_TEST_DONE)
  4412. break;
  4413. msleep(200);
  4414. }
  4415. if (cnt == 5)
  4416. break;
  4417. val64 = MC_RLDRAM_TEST_MODE | MC_RLDRAM_TEST_GO;
  4418. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
  4419. for (cnt = 0; cnt < 5; cnt++) {
  4420. val64 = readq(&bar0->mc_rldram_test_ctrl);
  4421. if (val64 & MC_RLDRAM_TEST_DONE)
  4422. break;
  4423. msleep(500);
  4424. }
  4425. if (cnt == 5)
  4426. break;
  4427. val64 = readq(&bar0->mc_rldram_test_ctrl);
  4428. if (!(val64 & MC_RLDRAM_TEST_PASS))
  4429. test_fail = 1;
  4430. iteration++;
  4431. }
  4432. *data = test_fail;
  4433. /* Bring the adapter out of test mode */
  4434. SPECIAL_REG_WRITE(0, &bar0->mc_rldram_test_ctrl, LF);
  4435. return test_fail;
  4436. }
  4437. /**
  4438. * s2io_ethtool_test - conducts 6 tsets to determine the health of card.
  4439. * @sp : private member of the device structure, which is a pointer to the
  4440. * s2io_nic structure.
  4441. * @ethtest : pointer to a ethtool command specific structure that will be
  4442. * returned to the user.
  4443. * @data : variable that returns the result of each of the test
  4444. * conducted by the driver.
  4445. * Description:
  4446. * This function conducts 6 tests ( 4 offline and 2 online) to determine
  4447. * the health of the card.
  4448. * Return value:
  4449. * void
  4450. */
  4451. static void s2io_ethtool_test(struct net_device *dev,
  4452. struct ethtool_test *ethtest,
  4453. uint64_t * data)
  4454. {
  4455. nic_t *sp = dev->priv;
  4456. int orig_state = netif_running(sp->dev);
  4457. if (ethtest->flags == ETH_TEST_FL_OFFLINE) {
  4458. /* Offline Tests. */
  4459. if (orig_state)
  4460. s2io_close(sp->dev);
  4461. if (s2io_register_test(sp, &data[0]))
  4462. ethtest->flags |= ETH_TEST_FL_FAILED;
  4463. s2io_reset(sp);
  4464. if (s2io_rldram_test(sp, &data[3]))
  4465. ethtest->flags |= ETH_TEST_FL_FAILED;
  4466. s2io_reset(sp);
  4467. if (s2io_eeprom_test(sp, &data[1]))
  4468. ethtest->flags |= ETH_TEST_FL_FAILED;
  4469. if (s2io_bist_test(sp, &data[4]))
  4470. ethtest->flags |= ETH_TEST_FL_FAILED;
  4471. if (orig_state)
  4472. s2io_open(sp->dev);
  4473. data[2] = 0;
  4474. } else {
  4475. /* Online Tests. */
  4476. if (!orig_state) {
  4477. DBG_PRINT(ERR_DBG,
  4478. "%s: is not up, cannot run test\n",
  4479. dev->name);
  4480. data[0] = -1;
  4481. data[1] = -1;
  4482. data[2] = -1;
  4483. data[3] = -1;
  4484. data[4] = -1;
  4485. }
  4486. if (s2io_link_test(sp, &data[2]))
  4487. ethtest->flags |= ETH_TEST_FL_FAILED;
  4488. data[0] = 0;
  4489. data[1] = 0;
  4490. data[3] = 0;
  4491. data[4] = 0;
  4492. }
  4493. }
  4494. static void s2io_get_ethtool_stats(struct net_device *dev,
  4495. struct ethtool_stats *estats,
  4496. u64 * tmp_stats)
  4497. {
  4498. int i = 0;
  4499. nic_t *sp = dev->priv;
  4500. StatInfo_t *stat_info = sp->mac_control.stats_info;
  4501. s2io_updt_stats(sp);
  4502. tmp_stats[i++] =
  4503. (u64)le32_to_cpu(stat_info->tmac_frms_oflow) << 32 |
  4504. le32_to_cpu(stat_info->tmac_frms);
  4505. tmp_stats[i++] =
  4506. (u64)le32_to_cpu(stat_info->tmac_data_octets_oflow) << 32 |
  4507. le32_to_cpu(stat_info->tmac_data_octets);
  4508. tmp_stats[i++] = le64_to_cpu(stat_info->tmac_drop_frms);
  4509. tmp_stats[i++] =
  4510. (u64)le32_to_cpu(stat_info->tmac_mcst_frms_oflow) << 32 |
  4511. le32_to_cpu(stat_info->tmac_mcst_frms);
  4512. tmp_stats[i++] =
  4513. (u64)le32_to_cpu(stat_info->tmac_bcst_frms_oflow) << 32 |
  4514. le32_to_cpu(stat_info->tmac_bcst_frms);
  4515. tmp_stats[i++] = le64_to_cpu(stat_info->tmac_pause_ctrl_frms);
  4516. tmp_stats[i++] =
  4517. (u64)le32_to_cpu(stat_info->tmac_any_err_frms_oflow) << 32 |
  4518. le32_to_cpu(stat_info->tmac_any_err_frms);
  4519. tmp_stats[i++] = le64_to_cpu(stat_info->tmac_vld_ip_octets);
  4520. tmp_stats[i++] =
  4521. (u64)le32_to_cpu(stat_info->tmac_vld_ip_oflow) << 32 |
  4522. le32_to_cpu(stat_info->tmac_vld_ip);
  4523. tmp_stats[i++] =
  4524. (u64)le32_to_cpu(stat_info->tmac_drop_ip_oflow) << 32 |
  4525. le32_to_cpu(stat_info->tmac_drop_ip);
  4526. tmp_stats[i++] =
  4527. (u64)le32_to_cpu(stat_info->tmac_icmp_oflow) << 32 |
  4528. le32_to_cpu(stat_info->tmac_icmp);
  4529. tmp_stats[i++] =
  4530. (u64)le32_to_cpu(stat_info->tmac_rst_tcp_oflow) << 32 |
  4531. le32_to_cpu(stat_info->tmac_rst_tcp);
  4532. tmp_stats[i++] = le64_to_cpu(stat_info->tmac_tcp);
  4533. tmp_stats[i++] = (u64)le32_to_cpu(stat_info->tmac_udp_oflow) << 32 |
  4534. le32_to_cpu(stat_info->tmac_udp);
  4535. tmp_stats[i++] =
  4536. (u64)le32_to_cpu(stat_info->rmac_vld_frms_oflow) << 32 |
  4537. le32_to_cpu(stat_info->rmac_vld_frms);
  4538. tmp_stats[i++] =
  4539. (u64)le32_to_cpu(stat_info->rmac_data_octets_oflow) << 32 |
  4540. le32_to_cpu(stat_info->rmac_data_octets);
  4541. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_fcs_err_frms);
  4542. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_drop_frms);
  4543. tmp_stats[i++] =
  4544. (u64)le32_to_cpu(stat_info->rmac_vld_mcst_frms_oflow) << 32 |
  4545. le32_to_cpu(stat_info->rmac_vld_mcst_frms);
  4546. tmp_stats[i++] =
  4547. (u64)le32_to_cpu(stat_info->rmac_vld_bcst_frms_oflow) << 32 |
  4548. le32_to_cpu(stat_info->rmac_vld_bcst_frms);
  4549. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_in_rng_len_err_frms);
  4550. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_long_frms);
  4551. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_pause_ctrl_frms);
  4552. tmp_stats[i++] =
  4553. (u64)le32_to_cpu(stat_info->rmac_discarded_frms_oflow) << 32 |
  4554. le32_to_cpu(stat_info->rmac_discarded_frms);
  4555. tmp_stats[i++] =
  4556. (u64)le32_to_cpu(stat_info->rmac_usized_frms_oflow) << 32 |
  4557. le32_to_cpu(stat_info->rmac_usized_frms);
  4558. tmp_stats[i++] =
  4559. (u64)le32_to_cpu(stat_info->rmac_osized_frms_oflow) << 32 |
  4560. le32_to_cpu(stat_info->rmac_osized_frms);
  4561. tmp_stats[i++] =
  4562. (u64)le32_to_cpu(stat_info->rmac_frag_frms_oflow) << 32 |
  4563. le32_to_cpu(stat_info->rmac_frag_frms);
  4564. tmp_stats[i++] =
  4565. (u64)le32_to_cpu(stat_info->rmac_jabber_frms_oflow) << 32 |
  4566. le32_to_cpu(stat_info->rmac_jabber_frms);
  4567. tmp_stats[i++] = (u64)le32_to_cpu(stat_info->rmac_ip_oflow) << 32 |
  4568. le32_to_cpu(stat_info->rmac_ip);
  4569. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ip_octets);
  4570. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_hdr_err_ip);
  4571. tmp_stats[i++] = (u64)le32_to_cpu(stat_info->rmac_drop_ip_oflow) << 32 |
  4572. le32_to_cpu(stat_info->rmac_drop_ip);
  4573. tmp_stats[i++] = (u64)le32_to_cpu(stat_info->rmac_icmp_oflow) << 32 |
  4574. le32_to_cpu(stat_info->rmac_icmp);
  4575. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_tcp);
  4576. tmp_stats[i++] = (u64)le32_to_cpu(stat_info->rmac_udp_oflow) << 32 |
  4577. le32_to_cpu(stat_info->rmac_udp);
  4578. tmp_stats[i++] =
  4579. (u64)le32_to_cpu(stat_info->rmac_err_drp_udp_oflow) << 32 |
  4580. le32_to_cpu(stat_info->rmac_err_drp_udp);
  4581. tmp_stats[i++] =
  4582. (u64)le32_to_cpu(stat_info->rmac_pause_cnt_oflow) << 32 |
  4583. le32_to_cpu(stat_info->rmac_pause_cnt);
  4584. tmp_stats[i++] =
  4585. (u64)le32_to_cpu(stat_info->rmac_accepted_ip_oflow) << 32 |
  4586. le32_to_cpu(stat_info->rmac_accepted_ip);
  4587. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_err_tcp);
  4588. tmp_stats[i++] = 0;
  4589. tmp_stats[i++] = stat_info->sw_stat.single_ecc_errs;
  4590. tmp_stats[i++] = stat_info->sw_stat.double_ecc_errs;
  4591. }
  4592. static int s2io_ethtool_get_regs_len(struct net_device *dev)
  4593. {
  4594. return (XENA_REG_SPACE);
  4595. }
  4596. static u32 s2io_ethtool_get_rx_csum(struct net_device * dev)
  4597. {
  4598. nic_t *sp = dev->priv;
  4599. return (sp->rx_csum);
  4600. }
  4601. static int s2io_ethtool_set_rx_csum(struct net_device *dev, u32 data)
  4602. {
  4603. nic_t *sp = dev->priv;
  4604. if (data)
  4605. sp->rx_csum = 1;
  4606. else
  4607. sp->rx_csum = 0;
  4608. return 0;
  4609. }
  4610. static int s2io_get_eeprom_len(struct net_device *dev)
  4611. {
  4612. return (XENA_EEPROM_SPACE);
  4613. }
  4614. static int s2io_ethtool_self_test_count(struct net_device *dev)
  4615. {
  4616. return (S2IO_TEST_LEN);
  4617. }
  4618. static void s2io_ethtool_get_strings(struct net_device *dev,
  4619. u32 stringset, u8 * data)
  4620. {
  4621. switch (stringset) {
  4622. case ETH_SS_TEST:
  4623. memcpy(data, s2io_gstrings, S2IO_STRINGS_LEN);
  4624. break;
  4625. case ETH_SS_STATS:
  4626. memcpy(data, &ethtool_stats_keys,
  4627. sizeof(ethtool_stats_keys));
  4628. }
  4629. }
  4630. static int s2io_ethtool_get_stats_count(struct net_device *dev)
  4631. {
  4632. return (S2IO_STAT_LEN);
  4633. }
  4634. static int s2io_ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
  4635. {
  4636. if (data)
  4637. dev->features |= NETIF_F_IP_CSUM;
  4638. else
  4639. dev->features &= ~NETIF_F_IP_CSUM;
  4640. return 0;
  4641. }
  4642. static struct ethtool_ops netdev_ethtool_ops = {
  4643. .get_settings = s2io_ethtool_gset,
  4644. .set_settings = s2io_ethtool_sset,
  4645. .get_drvinfo = s2io_ethtool_gdrvinfo,
  4646. .get_regs_len = s2io_ethtool_get_regs_len,
  4647. .get_regs = s2io_ethtool_gregs,
  4648. .get_link = ethtool_op_get_link,
  4649. .get_eeprom_len = s2io_get_eeprom_len,
  4650. .get_eeprom = s2io_ethtool_geeprom,
  4651. .set_eeprom = s2io_ethtool_seeprom,
  4652. .get_pauseparam = s2io_ethtool_getpause_data,
  4653. .set_pauseparam = s2io_ethtool_setpause_data,
  4654. .get_rx_csum = s2io_ethtool_get_rx_csum,
  4655. .set_rx_csum = s2io_ethtool_set_rx_csum,
  4656. .get_tx_csum = ethtool_op_get_tx_csum,
  4657. .set_tx_csum = s2io_ethtool_op_set_tx_csum,
  4658. .get_sg = ethtool_op_get_sg,
  4659. .set_sg = ethtool_op_set_sg,
  4660. #ifdef NETIF_F_TSO
  4661. .get_tso = ethtool_op_get_tso,
  4662. .set_tso = ethtool_op_set_tso,
  4663. #endif
  4664. .self_test_count = s2io_ethtool_self_test_count,
  4665. .self_test = s2io_ethtool_test,
  4666. .get_strings = s2io_ethtool_get_strings,
  4667. .phys_id = s2io_ethtool_idnic,
  4668. .get_stats_count = s2io_ethtool_get_stats_count,
  4669. .get_ethtool_stats = s2io_get_ethtool_stats
  4670. };
  4671. /**
  4672. * s2io_ioctl - Entry point for the Ioctl
  4673. * @dev : Device pointer.
  4674. * @ifr : An IOCTL specefic structure, that can contain a pointer to
  4675. * a proprietary structure used to pass information to the driver.
  4676. * @cmd : This is used to distinguish between the different commands that
  4677. * can be passed to the IOCTL functions.
  4678. * Description:
  4679. * Currently there are no special functionality supported in IOCTL, hence
  4680. * function always return EOPNOTSUPPORTED
  4681. */
  4682. static int s2io_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  4683. {
  4684. return -EOPNOTSUPP;
  4685. }
  4686. /**
  4687. * s2io_change_mtu - entry point to change MTU size for the device.
  4688. * @dev : device pointer.
  4689. * @new_mtu : the new MTU size for the device.
  4690. * Description: A driver entry point to change MTU size for the device.
  4691. * Before changing the MTU the device must be stopped.
  4692. * Return value:
  4693. * 0 on success and an appropriate (-)ve integer as defined in errno.h
  4694. * file on failure.
  4695. */
  4696. static int s2io_change_mtu(struct net_device *dev, int new_mtu)
  4697. {
  4698. nic_t *sp = dev->priv;
  4699. if ((new_mtu < MIN_MTU) || (new_mtu > S2IO_JUMBO_SIZE)) {
  4700. DBG_PRINT(ERR_DBG, "%s: MTU size is invalid.\n",
  4701. dev->name);
  4702. return -EPERM;
  4703. }
  4704. dev->mtu = new_mtu;
  4705. if (netif_running(dev)) {
  4706. s2io_card_down(sp);
  4707. netif_stop_queue(dev);
  4708. if (s2io_card_up(sp)) {
  4709. DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n",
  4710. __FUNCTION__);
  4711. }
  4712. if (netif_queue_stopped(dev))
  4713. netif_wake_queue(dev);
  4714. } else { /* Device is down */
  4715. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  4716. u64 val64 = new_mtu;
  4717. writeq(vBIT(val64, 2, 14), &bar0->rmac_max_pyld_len);
  4718. }
  4719. return 0;
  4720. }
  4721. /**
  4722. * s2io_tasklet - Bottom half of the ISR.
  4723. * @dev_adr : address of the device structure in dma_addr_t format.
  4724. * Description:
  4725. * This is the tasklet or the bottom half of the ISR. This is
  4726. * an extension of the ISR which is scheduled by the scheduler to be run
  4727. * when the load on the CPU is low. All low priority tasks of the ISR can
  4728. * be pushed into the tasklet. For now the tasklet is used only to
  4729. * replenish the Rx buffers in the Rx buffer descriptors.
  4730. * Return value:
  4731. * void.
  4732. */
  4733. static void s2io_tasklet(unsigned long dev_addr)
  4734. {
  4735. struct net_device *dev = (struct net_device *) dev_addr;
  4736. nic_t *sp = dev->priv;
  4737. int i, ret;
  4738. mac_info_t *mac_control;
  4739. struct config_param *config;
  4740. mac_control = &sp->mac_control;
  4741. config = &sp->config;
  4742. if (!TASKLET_IN_USE) {
  4743. for (i = 0; i < config->rx_ring_num; i++) {
  4744. ret = fill_rx_buffers(sp, i);
  4745. if (ret == -ENOMEM) {
  4746. DBG_PRINT(ERR_DBG, "%s: Out of ",
  4747. dev->name);
  4748. DBG_PRINT(ERR_DBG, "memory in tasklet\n");
  4749. break;
  4750. } else if (ret == -EFILL) {
  4751. DBG_PRINT(ERR_DBG,
  4752. "%s: Rx Ring %d is full\n",
  4753. dev->name, i);
  4754. break;
  4755. }
  4756. }
  4757. clear_bit(0, (&sp->tasklet_status));
  4758. }
  4759. }
  4760. /**
  4761. * s2io_set_link - Set the LInk status
  4762. * @data: long pointer to device private structue
  4763. * Description: Sets the link status for the adapter
  4764. */
  4765. static void s2io_set_link(unsigned long data)
  4766. {
  4767. nic_t *nic = (nic_t *) data;
  4768. struct net_device *dev = nic->dev;
  4769. XENA_dev_config_t __iomem *bar0 = nic->bar0;
  4770. register u64 val64;
  4771. u16 subid;
  4772. if (test_and_set_bit(0, &(nic->link_state))) {
  4773. /* The card is being reset, no point doing anything */
  4774. return;
  4775. }
  4776. subid = nic->pdev->subsystem_device;
  4777. if (s2io_link_fault_indication(nic) == MAC_RMAC_ERR_TIMER) {
  4778. /*
  4779. * Allow a small delay for the NICs self initiated
  4780. * cleanup to complete.
  4781. */
  4782. msleep(100);
  4783. }
  4784. val64 = readq(&bar0->adapter_status);
  4785. if (verify_xena_quiescence(nic, val64, nic->device_enabled_once)) {
  4786. if (LINK_IS_UP(val64)) {
  4787. val64 = readq(&bar0->adapter_control);
  4788. val64 |= ADAPTER_CNTL_EN;
  4789. writeq(val64, &bar0->adapter_control);
  4790. if (CARDS_WITH_FAULTY_LINK_INDICATORS(nic->device_type,
  4791. subid)) {
  4792. val64 = readq(&bar0->gpio_control);
  4793. val64 |= GPIO_CTRL_GPIO_0;
  4794. writeq(val64, &bar0->gpio_control);
  4795. val64 = readq(&bar0->gpio_control);
  4796. } else {
  4797. val64 |= ADAPTER_LED_ON;
  4798. writeq(val64, &bar0->adapter_control);
  4799. }
  4800. if (s2io_link_fault_indication(nic) ==
  4801. MAC_RMAC_ERR_TIMER) {
  4802. val64 = readq(&bar0->adapter_status);
  4803. if (!LINK_IS_UP(val64)) {
  4804. DBG_PRINT(ERR_DBG, "%s:", dev->name);
  4805. DBG_PRINT(ERR_DBG, " Link down");
  4806. DBG_PRINT(ERR_DBG, "after ");
  4807. DBG_PRINT(ERR_DBG, "enabling ");
  4808. DBG_PRINT(ERR_DBG, "device \n");
  4809. }
  4810. }
  4811. if (nic->device_enabled_once == FALSE) {
  4812. nic->device_enabled_once = TRUE;
  4813. }
  4814. s2io_link(nic, LINK_UP);
  4815. } else {
  4816. if (CARDS_WITH_FAULTY_LINK_INDICATORS(nic->device_type,
  4817. subid)) {
  4818. val64 = readq(&bar0->gpio_control);
  4819. val64 &= ~GPIO_CTRL_GPIO_0;
  4820. writeq(val64, &bar0->gpio_control);
  4821. val64 = readq(&bar0->gpio_control);
  4822. }
  4823. s2io_link(nic, LINK_DOWN);
  4824. }
  4825. } else { /* NIC is not Quiescent. */
  4826. DBG_PRINT(ERR_DBG, "%s: Error: ", dev->name);
  4827. DBG_PRINT(ERR_DBG, "device is not Quiescent\n");
  4828. netif_stop_queue(dev);
  4829. }
  4830. clear_bit(0, &(nic->link_state));
  4831. }
  4832. static void s2io_card_down(nic_t * sp)
  4833. {
  4834. int cnt = 0;
  4835. XENA_dev_config_t __iomem *bar0 = sp->bar0;
  4836. unsigned long flags;
  4837. register u64 val64 = 0;
  4838. del_timer_sync(&sp->alarm_timer);
  4839. /* If s2io_set_link task is executing, wait till it completes. */
  4840. while (test_and_set_bit(0, &(sp->link_state))) {
  4841. msleep(50);
  4842. }
  4843. atomic_set(&sp->card_state, CARD_DOWN);
  4844. /* disable Tx and Rx traffic on the NIC */
  4845. stop_nic(sp);
  4846. /* Kill tasklet. */
  4847. tasklet_kill(&sp->task);
  4848. /* Check if the device is Quiescent and then Reset the NIC */
  4849. do {
  4850. val64 = readq(&bar0->adapter_status);
  4851. if (verify_xena_quiescence(sp, val64, sp->device_enabled_once)) {
  4852. break;
  4853. }
  4854. msleep(50);
  4855. cnt++;
  4856. if (cnt == 10) {
  4857. DBG_PRINT(ERR_DBG,
  4858. "s2io_close:Device not Quiescent ");
  4859. DBG_PRINT(ERR_DBG, "adaper status reads 0x%llx\n",
  4860. (unsigned long long) val64);
  4861. break;
  4862. }
  4863. } while (1);
  4864. s2io_reset(sp);
  4865. /* Waiting till all Interrupt handlers are complete */
  4866. cnt = 0;
  4867. do {
  4868. msleep(10);
  4869. if (!atomic_read(&sp->isr_cnt))
  4870. break;
  4871. cnt++;
  4872. } while(cnt < 5);
  4873. spin_lock_irqsave(&sp->tx_lock, flags);
  4874. /* Free all Tx buffers */
  4875. free_tx_buffers(sp);
  4876. spin_unlock_irqrestore(&sp->tx_lock, flags);
  4877. /* Free all Rx buffers */
  4878. spin_lock_irqsave(&sp->rx_lock, flags);
  4879. free_rx_buffers(sp);
  4880. spin_unlock_irqrestore(&sp->rx_lock, flags);
  4881. clear_bit(0, &(sp->link_state));
  4882. }
  4883. static int s2io_card_up(nic_t * sp)
  4884. {
  4885. int i, ret = 0;
  4886. mac_info_t *mac_control;
  4887. struct config_param *config;
  4888. struct net_device *dev = (struct net_device *) sp->dev;
  4889. /* Initialize the H/W I/O registers */
  4890. if (init_nic(sp) != 0) {
  4891. DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n",
  4892. dev->name);
  4893. return -ENODEV;
  4894. }
  4895. if (sp->intr_type == MSI)
  4896. ret = s2io_enable_msi(sp);
  4897. else if (sp->intr_type == MSI_X)
  4898. ret = s2io_enable_msi_x(sp);
  4899. if (ret) {
  4900. DBG_PRINT(ERR_DBG, "%s: Defaulting to INTA\n", dev->name);
  4901. sp->intr_type = INTA;
  4902. }
  4903. /*
  4904. * Initializing the Rx buffers. For now we are considering only 1
  4905. * Rx ring and initializing buffers into 30 Rx blocks
  4906. */
  4907. mac_control = &sp->mac_control;
  4908. config = &sp->config;
  4909. for (i = 0; i < config->rx_ring_num; i++) {
  4910. if ((ret = fill_rx_buffers(sp, i))) {
  4911. DBG_PRINT(ERR_DBG, "%s: Out of memory in Open\n",
  4912. dev->name);
  4913. s2io_reset(sp);
  4914. free_rx_buffers(sp);
  4915. return -ENOMEM;
  4916. }
  4917. DBG_PRINT(INFO_DBG, "Buf in ring:%d is %d:\n", i,
  4918. atomic_read(&sp->rx_bufs_left[i]));
  4919. }
  4920. /* Setting its receive mode */
  4921. s2io_set_multicast(dev);
  4922. /* Enable tasklet for the device */
  4923. tasklet_init(&sp->task, s2io_tasklet, (unsigned long) dev);
  4924. /* Enable Rx Traffic and interrupts on the NIC */
  4925. if (start_nic(sp)) {
  4926. DBG_PRINT(ERR_DBG, "%s: Starting NIC failed\n", dev->name);
  4927. tasklet_kill(&sp->task);
  4928. s2io_reset(sp);
  4929. free_irq(dev->irq, dev);
  4930. free_rx_buffers(sp);
  4931. return -ENODEV;
  4932. }
  4933. S2IO_TIMER_CONF(sp->alarm_timer, s2io_alarm_handle, sp, (HZ/2));
  4934. atomic_set(&sp->card_state, CARD_UP);
  4935. return 0;
  4936. }
  4937. /**
  4938. * s2io_restart_nic - Resets the NIC.
  4939. * @data : long pointer to the device private structure
  4940. * Description:
  4941. * This function is scheduled to be run by the s2io_tx_watchdog
  4942. * function after 0.5 secs to reset the NIC. The idea is to reduce
  4943. * the run time of the watch dog routine which is run holding a
  4944. * spin lock.
  4945. */
  4946. static void s2io_restart_nic(unsigned long data)
  4947. {
  4948. struct net_device *dev = (struct net_device *) data;
  4949. nic_t *sp = dev->priv;
  4950. s2io_card_down(sp);
  4951. if (s2io_card_up(sp)) {
  4952. DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n",
  4953. dev->name);
  4954. }
  4955. netif_wake_queue(dev);
  4956. DBG_PRINT(ERR_DBG, "%s: was reset by Tx watchdog timer\n",
  4957. dev->name);
  4958. }
  4959. /**
  4960. * s2io_tx_watchdog - Watchdog for transmit side.
  4961. * @dev : Pointer to net device structure
  4962. * Description:
  4963. * This function is triggered if the Tx Queue is stopped
  4964. * for a pre-defined amount of time when the Interface is still up.
  4965. * If the Interface is jammed in such a situation, the hardware is
  4966. * reset (by s2io_close) and restarted again (by s2io_open) to
  4967. * overcome any problem that might have been caused in the hardware.
  4968. * Return value:
  4969. * void
  4970. */
  4971. static void s2io_tx_watchdog(struct net_device *dev)
  4972. {
  4973. nic_t *sp = dev->priv;
  4974. if (netif_carrier_ok(dev)) {
  4975. schedule_work(&sp->rst_timer_task);
  4976. }
  4977. }
  4978. /**
  4979. * rx_osm_handler - To perform some OS related operations on SKB.
  4980. * @sp: private member of the device structure,pointer to s2io_nic structure.
  4981. * @skb : the socket buffer pointer.
  4982. * @len : length of the packet
  4983. * @cksum : FCS checksum of the frame.
  4984. * @ring_no : the ring from which this RxD was extracted.
  4985. * Description:
  4986. * This function is called by the Tx interrupt serivce routine to perform
  4987. * some OS related operations on the SKB before passing it to the upper
  4988. * layers. It mainly checks if the checksum is OK, if so adds it to the
  4989. * SKBs cksum variable, increments the Rx packet count and passes the SKB
  4990. * to the upper layer. If the checksum is wrong, it increments the Rx
  4991. * packet error count, frees the SKB and returns error.
  4992. * Return value:
  4993. * SUCCESS on success and -1 on failure.
  4994. */
  4995. static int rx_osm_handler(ring_info_t *ring_data, RxD_t * rxdp)
  4996. {
  4997. nic_t *sp = ring_data->nic;
  4998. struct net_device *dev = (struct net_device *) sp->dev;
  4999. struct sk_buff *skb = (struct sk_buff *)
  5000. ((unsigned long) rxdp->Host_Control);
  5001. int ring_no = ring_data->ring_no;
  5002. u16 l3_csum, l4_csum;
  5003. skb->dev = dev;
  5004. if (rxdp->Control_1 & RXD_T_CODE) {
  5005. unsigned long long err = rxdp->Control_1 & RXD_T_CODE;
  5006. DBG_PRINT(ERR_DBG, "%s: Rx error Value: 0x%llx\n",
  5007. dev->name, err);
  5008. dev_kfree_skb(skb);
  5009. sp->stats.rx_crc_errors++;
  5010. atomic_dec(&sp->rx_bufs_left[ring_no]);
  5011. rxdp->Host_Control = 0;
  5012. return 0;
  5013. }
  5014. /* Updating statistics */
  5015. rxdp->Host_Control = 0;
  5016. sp->rx_pkt_count++;
  5017. sp->stats.rx_packets++;
  5018. if (sp->rxd_mode == RXD_MODE_1) {
  5019. int len = RXD_GET_BUFFER0_SIZE_1(rxdp->Control_2);
  5020. sp->stats.rx_bytes += len;
  5021. skb_put(skb, len);
  5022. } else if (sp->rxd_mode >= RXD_MODE_3A) {
  5023. int get_block = ring_data->rx_curr_get_info.block_index;
  5024. int get_off = ring_data->rx_curr_get_info.offset;
  5025. int buf0_len = RXD_GET_BUFFER0_SIZE_3(rxdp->Control_2);
  5026. int buf2_len = RXD_GET_BUFFER2_SIZE_3(rxdp->Control_2);
  5027. unsigned char *buff = skb_push(skb, buf0_len);
  5028. buffAdd_t *ba = &ring_data->ba[get_block][get_off];
  5029. sp->stats.rx_bytes += buf0_len + buf2_len;
  5030. memcpy(buff, ba->ba_0, buf0_len);
  5031. if (sp->rxd_mode == RXD_MODE_3A) {
  5032. int buf1_len = RXD_GET_BUFFER1_SIZE_3(rxdp->Control_2);
  5033. skb_put(skb, buf1_len);
  5034. skb->len += buf2_len;
  5035. skb->data_len += buf2_len;
  5036. skb->truesize += buf2_len;
  5037. skb_put(skb_shinfo(skb)->frag_list, buf2_len);
  5038. sp->stats.rx_bytes += buf1_len;
  5039. } else
  5040. skb_put(skb, buf2_len);
  5041. }
  5042. if ((rxdp->Control_1 & TCP_OR_UDP_FRAME) &&
  5043. (sp->rx_csum)) {
  5044. l3_csum = RXD_GET_L3_CKSUM(rxdp->Control_1);
  5045. l4_csum = RXD_GET_L4_CKSUM(rxdp->Control_1);
  5046. if ((l3_csum == L3_CKSUM_OK) && (l4_csum == L4_CKSUM_OK)) {
  5047. /*
  5048. * NIC verifies if the Checksum of the received
  5049. * frame is Ok or not and accordingly returns
  5050. * a flag in the RxD.
  5051. */
  5052. skb->ip_summed = CHECKSUM_UNNECESSARY;
  5053. } else {
  5054. /*
  5055. * Packet with erroneous checksum, let the
  5056. * upper layers deal with it.
  5057. */
  5058. skb->ip_summed = CHECKSUM_NONE;
  5059. }
  5060. } else {
  5061. skb->ip_summed = CHECKSUM_NONE;
  5062. }
  5063. skb->protocol = eth_type_trans(skb, dev);
  5064. #ifdef CONFIG_S2IO_NAPI
  5065. if (sp->vlgrp && RXD_GET_VLAN_TAG(rxdp->Control_2)) {
  5066. /* Queueing the vlan frame to the upper layer */
  5067. vlan_hwaccel_receive_skb(skb, sp->vlgrp,
  5068. RXD_GET_VLAN_TAG(rxdp->Control_2));
  5069. } else {
  5070. netif_receive_skb(skb);
  5071. }
  5072. #else
  5073. if (sp->vlgrp && RXD_GET_VLAN_TAG(rxdp->Control_2)) {
  5074. /* Queueing the vlan frame to the upper layer */
  5075. vlan_hwaccel_rx(skb, sp->vlgrp,
  5076. RXD_GET_VLAN_TAG(rxdp->Control_2));
  5077. } else {
  5078. netif_rx(skb);
  5079. }
  5080. #endif
  5081. dev->last_rx = jiffies;
  5082. atomic_dec(&sp->rx_bufs_left[ring_no]);
  5083. return SUCCESS;
  5084. }
  5085. /**
  5086. * s2io_link - stops/starts the Tx queue.
  5087. * @sp : private member of the device structure, which is a pointer to the
  5088. * s2io_nic structure.
  5089. * @link : inidicates whether link is UP/DOWN.
  5090. * Description:
  5091. * This function stops/starts the Tx queue depending on whether the link
  5092. * status of the NIC is is down or up. This is called by the Alarm
  5093. * interrupt handler whenever a link change interrupt comes up.
  5094. * Return value:
  5095. * void.
  5096. */
  5097. void s2io_link(nic_t * sp, int link)
  5098. {
  5099. struct net_device *dev = (struct net_device *) sp->dev;
  5100. if (link != sp->last_link_state) {
  5101. if (link == LINK_DOWN) {
  5102. DBG_PRINT(ERR_DBG, "%s: Link down\n", dev->name);
  5103. netif_carrier_off(dev);
  5104. } else {
  5105. DBG_PRINT(ERR_DBG, "%s: Link Up\n", dev->name);
  5106. netif_carrier_on(dev);
  5107. }
  5108. }
  5109. sp->last_link_state = link;
  5110. }
  5111. /**
  5112. * get_xena_rev_id - to identify revision ID of xena.
  5113. * @pdev : PCI Dev structure
  5114. * Description:
  5115. * Function to identify the Revision ID of xena.
  5116. * Return value:
  5117. * returns the revision ID of the device.
  5118. */
  5119. int get_xena_rev_id(struct pci_dev *pdev)
  5120. {
  5121. u8 id = 0;
  5122. int ret;
  5123. ret = pci_read_config_byte(pdev, PCI_REVISION_ID, (u8 *) & id);
  5124. return id;
  5125. }
  5126. /**
  5127. * s2io_init_pci -Initialization of PCI and PCI-X configuration registers .
  5128. * @sp : private member of the device structure, which is a pointer to the
  5129. * s2io_nic structure.
  5130. * Description:
  5131. * This function initializes a few of the PCI and PCI-X configuration registers
  5132. * with recommended values.
  5133. * Return value:
  5134. * void
  5135. */
  5136. static void s2io_init_pci(nic_t * sp)
  5137. {
  5138. u16 pci_cmd = 0, pcix_cmd = 0;
  5139. /* Enable Data Parity Error Recovery in PCI-X command register. */
  5140. pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  5141. &(pcix_cmd));
  5142. pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  5143. (pcix_cmd | 1));
  5144. pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  5145. &(pcix_cmd));
  5146. /* Set the PErr Response bit in PCI command register. */
  5147. pci_read_config_word(sp->pdev, PCI_COMMAND, &pci_cmd);
  5148. pci_write_config_word(sp->pdev, PCI_COMMAND,
  5149. (pci_cmd | PCI_COMMAND_PARITY));
  5150. pci_read_config_word(sp->pdev, PCI_COMMAND, &pci_cmd);
  5151. /* Forcibly disabling relaxed ordering capability of the card. */
  5152. pcix_cmd &= 0xfffd;
  5153. pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  5154. pcix_cmd);
  5155. pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  5156. &(pcix_cmd));
  5157. }
  5158. MODULE_AUTHOR("Raghavendra Koushik <raghavendra.koushik@neterion.com>");
  5159. MODULE_LICENSE("GPL");
  5160. MODULE_VERSION(DRV_VERSION);
  5161. module_param(tx_fifo_num, int, 0);
  5162. module_param(rx_ring_num, int, 0);
  5163. module_param(rx_ring_mode, int, 0);
  5164. module_param_array(tx_fifo_len, uint, NULL, 0);
  5165. module_param_array(rx_ring_sz, uint, NULL, 0);
  5166. module_param_array(rts_frm_len, uint, NULL, 0);
  5167. module_param(use_continuous_tx_intrs, int, 1);
  5168. module_param(rmac_pause_time, int, 0);
  5169. module_param(mc_pause_threshold_q0q3, int, 0);
  5170. module_param(mc_pause_threshold_q4q7, int, 0);
  5171. module_param(shared_splits, int, 0);
  5172. module_param(tmac_util_period, int, 0);
  5173. module_param(rmac_util_period, int, 0);
  5174. module_param(bimodal, bool, 0);
  5175. module_param(l3l4hdr_size, int , 0);
  5176. #ifndef CONFIG_S2IO_NAPI
  5177. module_param(indicate_max_pkts, int, 0);
  5178. #endif
  5179. module_param(rxsync_frequency, int, 0);
  5180. module_param(intr_type, int, 0);
  5181. /**
  5182. * s2io_init_nic - Initialization of the adapter .
  5183. * @pdev : structure containing the PCI related information of the device.
  5184. * @pre: List of PCI devices supported by the driver listed in s2io_tbl.
  5185. * Description:
  5186. * The function initializes an adapter identified by the pci_dec structure.
  5187. * All OS related initialization including memory and device structure and
  5188. * initlaization of the device private variable is done. Also the swapper
  5189. * control register is initialized to enable read and write into the I/O
  5190. * registers of the device.
  5191. * Return value:
  5192. * returns 0 on success and negative on failure.
  5193. */
  5194. static int __devinit
  5195. s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
  5196. {
  5197. nic_t *sp;
  5198. struct net_device *dev;
  5199. int i, j, ret;
  5200. int dma_flag = FALSE;
  5201. u32 mac_up, mac_down;
  5202. u64 val64 = 0, tmp64 = 0;
  5203. XENA_dev_config_t __iomem *bar0 = NULL;
  5204. u16 subid;
  5205. mac_info_t *mac_control;
  5206. struct config_param *config;
  5207. int mode;
  5208. u8 dev_intr_type = intr_type;
  5209. #ifdef CONFIG_S2IO_NAPI
  5210. if (dev_intr_type != INTA) {
  5211. DBG_PRINT(ERR_DBG, "NAPI cannot be enabled when MSI/MSI-X \
  5212. is enabled. Defaulting to INTA\n");
  5213. dev_intr_type = INTA;
  5214. }
  5215. else
  5216. DBG_PRINT(ERR_DBG, "NAPI support has been enabled\n");
  5217. #endif
  5218. if ((ret = pci_enable_device(pdev))) {
  5219. DBG_PRINT(ERR_DBG,
  5220. "s2io_init_nic: pci_enable_device failed\n");
  5221. return ret;
  5222. }
  5223. if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK)) {
  5224. DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 64bit DMA\n");
  5225. dma_flag = TRUE;
  5226. if (pci_set_consistent_dma_mask
  5227. (pdev, DMA_64BIT_MASK)) {
  5228. DBG_PRINT(ERR_DBG,
  5229. "Unable to obtain 64bit DMA for \
  5230. consistent allocations\n");
  5231. pci_disable_device(pdev);
  5232. return -ENOMEM;
  5233. }
  5234. } else if (!pci_set_dma_mask(pdev, DMA_32BIT_MASK)) {
  5235. DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 32bit DMA\n");
  5236. } else {
  5237. pci_disable_device(pdev);
  5238. return -ENOMEM;
  5239. }
  5240. if ((dev_intr_type == MSI_X) &&
  5241. ((pdev->device != PCI_DEVICE_ID_HERC_WIN) &&
  5242. (pdev->device != PCI_DEVICE_ID_HERC_UNI))) {
  5243. DBG_PRINT(ERR_DBG, "Xframe I does not support MSI_X. \
  5244. Defaulting to INTA\n");
  5245. dev_intr_type = INTA;
  5246. }
  5247. if (dev_intr_type != MSI_X) {
  5248. if (pci_request_regions(pdev, s2io_driver_name)) {
  5249. DBG_PRINT(ERR_DBG, "Request Regions failed\n"),
  5250. pci_disable_device(pdev);
  5251. return -ENODEV;
  5252. }
  5253. }
  5254. else {
  5255. if (!(request_mem_region(pci_resource_start(pdev, 0),
  5256. pci_resource_len(pdev, 0), s2io_driver_name))) {
  5257. DBG_PRINT(ERR_DBG, "bar0 Request Regions failed\n");
  5258. pci_disable_device(pdev);
  5259. return -ENODEV;
  5260. }
  5261. if (!(request_mem_region(pci_resource_start(pdev, 2),
  5262. pci_resource_len(pdev, 2), s2io_driver_name))) {
  5263. DBG_PRINT(ERR_DBG, "bar1 Request Regions failed\n");
  5264. release_mem_region(pci_resource_start(pdev, 0),
  5265. pci_resource_len(pdev, 0));
  5266. pci_disable_device(pdev);
  5267. return -ENODEV;
  5268. }
  5269. }
  5270. dev = alloc_etherdev(sizeof(nic_t));
  5271. if (dev == NULL) {
  5272. DBG_PRINT(ERR_DBG, "Device allocation failed\n");
  5273. pci_disable_device(pdev);
  5274. pci_release_regions(pdev);
  5275. return -ENODEV;
  5276. }
  5277. pci_set_master(pdev);
  5278. pci_set_drvdata(pdev, dev);
  5279. SET_MODULE_OWNER(dev);
  5280. SET_NETDEV_DEV(dev, &pdev->dev);
  5281. /* Private member variable initialized to s2io NIC structure */
  5282. sp = dev->priv;
  5283. memset(sp, 0, sizeof(nic_t));
  5284. sp->dev = dev;
  5285. sp->pdev = pdev;
  5286. sp->high_dma_flag = dma_flag;
  5287. sp->device_enabled_once = FALSE;
  5288. if (rx_ring_mode == 1)
  5289. sp->rxd_mode = RXD_MODE_1;
  5290. if (rx_ring_mode == 2)
  5291. sp->rxd_mode = RXD_MODE_3B;
  5292. if (rx_ring_mode == 3)
  5293. sp->rxd_mode = RXD_MODE_3A;
  5294. sp->intr_type = dev_intr_type;
  5295. if ((pdev->device == PCI_DEVICE_ID_HERC_WIN) ||
  5296. (pdev->device == PCI_DEVICE_ID_HERC_UNI))
  5297. sp->device_type = XFRAME_II_DEVICE;
  5298. else
  5299. sp->device_type = XFRAME_I_DEVICE;
  5300. /* Initialize some PCI/PCI-X fields of the NIC. */
  5301. s2io_init_pci(sp);
  5302. /*
  5303. * Setting the device configuration parameters.
  5304. * Most of these parameters can be specified by the user during
  5305. * module insertion as they are module loadable parameters. If
  5306. * these parameters are not not specified during load time, they
  5307. * are initialized with default values.
  5308. */
  5309. mac_control = &sp->mac_control;
  5310. config = &sp->config;
  5311. /* Tx side parameters. */
  5312. if (tx_fifo_len[0] == 0)
  5313. tx_fifo_len[0] = DEFAULT_FIFO_LEN; /* Default value. */
  5314. config->tx_fifo_num = tx_fifo_num;
  5315. for (i = 0; i < MAX_TX_FIFOS; i++) {
  5316. config->tx_cfg[i].fifo_len = tx_fifo_len[i];
  5317. config->tx_cfg[i].fifo_priority = i;
  5318. }
  5319. /* mapping the QoS priority to the configured fifos */
  5320. for (i = 0; i < MAX_TX_FIFOS; i++)
  5321. config->fifo_mapping[i] = fifo_map[config->tx_fifo_num][i];
  5322. config->tx_intr_type = TXD_INT_TYPE_UTILZ;
  5323. for (i = 0; i < config->tx_fifo_num; i++) {
  5324. config->tx_cfg[i].f_no_snoop =
  5325. (NO_SNOOP_TXD | NO_SNOOP_TXD_BUFFER);
  5326. if (config->tx_cfg[i].fifo_len < 65) {
  5327. config->tx_intr_type = TXD_INT_TYPE_PER_LIST;
  5328. break;
  5329. }
  5330. }
  5331. config->max_txds = MAX_SKB_FRAGS + 1;
  5332. /* Rx side parameters. */
  5333. if (rx_ring_sz[0] == 0)
  5334. rx_ring_sz[0] = SMALL_BLK_CNT; /* Default value. */
  5335. config->rx_ring_num = rx_ring_num;
  5336. for (i = 0; i < MAX_RX_RINGS; i++) {
  5337. config->rx_cfg[i].num_rxd = rx_ring_sz[i] *
  5338. (rxd_count[sp->rxd_mode] + 1);
  5339. config->rx_cfg[i].ring_priority = i;
  5340. }
  5341. for (i = 0; i < rx_ring_num; i++) {
  5342. config->rx_cfg[i].ring_org = RING_ORG_BUFF1;
  5343. config->rx_cfg[i].f_no_snoop =
  5344. (NO_SNOOP_RXD | NO_SNOOP_RXD_BUFFER);
  5345. }
  5346. /* Setting Mac Control parameters */
  5347. mac_control->rmac_pause_time = rmac_pause_time;
  5348. mac_control->mc_pause_threshold_q0q3 = mc_pause_threshold_q0q3;
  5349. mac_control->mc_pause_threshold_q4q7 = mc_pause_threshold_q4q7;
  5350. /* Initialize Ring buffer parameters. */
  5351. for (i = 0; i < config->rx_ring_num; i++)
  5352. atomic_set(&sp->rx_bufs_left[i], 0);
  5353. /* Initialize the number of ISRs currently running */
  5354. atomic_set(&sp->isr_cnt, 0);
  5355. /* initialize the shared memory used by the NIC and the host */
  5356. if (init_shared_mem(sp)) {
  5357. DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n",
  5358. __FUNCTION__);
  5359. ret = -ENOMEM;
  5360. goto mem_alloc_failed;
  5361. }
  5362. sp->bar0 = ioremap(pci_resource_start(pdev, 0),
  5363. pci_resource_len(pdev, 0));
  5364. if (!sp->bar0) {
  5365. DBG_PRINT(ERR_DBG, "%s: S2IO: cannot remap io mem1\n",
  5366. dev->name);
  5367. ret = -ENOMEM;
  5368. goto bar0_remap_failed;
  5369. }
  5370. sp->bar1 = ioremap(pci_resource_start(pdev, 2),
  5371. pci_resource_len(pdev, 2));
  5372. if (!sp->bar1) {
  5373. DBG_PRINT(ERR_DBG, "%s: S2IO: cannot remap io mem2\n",
  5374. dev->name);
  5375. ret = -ENOMEM;
  5376. goto bar1_remap_failed;
  5377. }
  5378. dev->irq = pdev->irq;
  5379. dev->base_addr = (unsigned long) sp->bar0;
  5380. /* Initializing the BAR1 address as the start of the FIFO pointer. */
  5381. for (j = 0; j < MAX_TX_FIFOS; j++) {
  5382. mac_control->tx_FIFO_start[j] = (TxFIFO_element_t __iomem *)
  5383. (sp->bar1 + (j * 0x00020000));
  5384. }
  5385. /* Driver entry points */
  5386. dev->open = &s2io_open;
  5387. dev->stop = &s2io_close;
  5388. dev->hard_start_xmit = &s2io_xmit;
  5389. dev->get_stats = &s2io_get_stats;
  5390. dev->set_multicast_list = &s2io_set_multicast;
  5391. dev->do_ioctl = &s2io_ioctl;
  5392. dev->change_mtu = &s2io_change_mtu;
  5393. SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
  5394. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  5395. dev->vlan_rx_register = s2io_vlan_rx_register;
  5396. dev->vlan_rx_kill_vid = (void *)s2io_vlan_rx_kill_vid;
  5397. /*
  5398. * will use eth_mac_addr() for dev->set_mac_address
  5399. * mac address will be set every time dev->open() is called
  5400. */
  5401. #if defined(CONFIG_S2IO_NAPI)
  5402. dev->poll = s2io_poll;
  5403. dev->weight = 32;
  5404. #endif
  5405. dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
  5406. if (sp->high_dma_flag == TRUE)
  5407. dev->features |= NETIF_F_HIGHDMA;
  5408. #ifdef NETIF_F_TSO
  5409. dev->features |= NETIF_F_TSO;
  5410. #endif
  5411. dev->tx_timeout = &s2io_tx_watchdog;
  5412. dev->watchdog_timeo = WATCH_DOG_TIMEOUT;
  5413. INIT_WORK(&sp->rst_timer_task,
  5414. (void (*)(void *)) s2io_restart_nic, dev);
  5415. INIT_WORK(&sp->set_link_task,
  5416. (void (*)(void *)) s2io_set_link, sp);
  5417. pci_save_state(sp->pdev);
  5418. /* Setting swapper control on the NIC, for proper reset operation */
  5419. if (s2io_set_swapper(sp)) {
  5420. DBG_PRINT(ERR_DBG, "%s:swapper settings are wrong\n",
  5421. dev->name);
  5422. ret = -EAGAIN;
  5423. goto set_swap_failed;
  5424. }
  5425. /* Verify if the Herc works on the slot its placed into */
  5426. if (sp->device_type & XFRAME_II_DEVICE) {
  5427. mode = s2io_verify_pci_mode(sp);
  5428. if (mode < 0) {
  5429. DBG_PRINT(ERR_DBG, "%s: ", __FUNCTION__);
  5430. DBG_PRINT(ERR_DBG, " Unsupported PCI bus mode\n");
  5431. ret = -EBADSLT;
  5432. goto set_swap_failed;
  5433. }
  5434. }
  5435. /* Not needed for Herc */
  5436. if (sp->device_type & XFRAME_I_DEVICE) {
  5437. /*
  5438. * Fix for all "FFs" MAC address problems observed on
  5439. * Alpha platforms
  5440. */
  5441. fix_mac_address(sp);
  5442. s2io_reset(sp);
  5443. }
  5444. /*
  5445. * MAC address initialization.
  5446. * For now only one mac address will be read and used.
  5447. */
  5448. bar0 = sp->bar0;
  5449. val64 = RMAC_ADDR_CMD_MEM_RD | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  5450. RMAC_ADDR_CMD_MEM_OFFSET(0 + MAC_MAC_ADDR_START_OFFSET);
  5451. writeq(val64, &bar0->rmac_addr_cmd_mem);
  5452. wait_for_cmd_complete(sp);
  5453. tmp64 = readq(&bar0->rmac_addr_data0_mem);
  5454. mac_down = (u32) tmp64;
  5455. mac_up = (u32) (tmp64 >> 32);
  5456. memset(sp->def_mac_addr[0].mac_addr, 0, sizeof(ETH_ALEN));
  5457. sp->def_mac_addr[0].mac_addr[3] = (u8) (mac_up);
  5458. sp->def_mac_addr[0].mac_addr[2] = (u8) (mac_up >> 8);
  5459. sp->def_mac_addr[0].mac_addr[1] = (u8) (mac_up >> 16);
  5460. sp->def_mac_addr[0].mac_addr[0] = (u8) (mac_up >> 24);
  5461. sp->def_mac_addr[0].mac_addr[5] = (u8) (mac_down >> 16);
  5462. sp->def_mac_addr[0].mac_addr[4] = (u8) (mac_down >> 24);
  5463. /* Set the factory defined MAC address initially */
  5464. dev->addr_len = ETH_ALEN;
  5465. memcpy(dev->dev_addr, sp->def_mac_addr, ETH_ALEN);
  5466. /*
  5467. * Initialize the tasklet status and link state flags
  5468. * and the card state parameter
  5469. */
  5470. atomic_set(&(sp->card_state), 0);
  5471. sp->tasklet_status = 0;
  5472. sp->link_state = 0;
  5473. /* Initialize spinlocks */
  5474. spin_lock_init(&sp->tx_lock);
  5475. #ifndef CONFIG_S2IO_NAPI
  5476. spin_lock_init(&sp->put_lock);
  5477. #endif
  5478. spin_lock_init(&sp->rx_lock);
  5479. /*
  5480. * SXE-002: Configure link and activity LED to init state
  5481. * on driver load.
  5482. */
  5483. subid = sp->pdev->subsystem_device;
  5484. if ((subid & 0xFF) >= 0x07) {
  5485. val64 = readq(&bar0->gpio_control);
  5486. val64 |= 0x0000800000000000ULL;
  5487. writeq(val64, &bar0->gpio_control);
  5488. val64 = 0x0411040400000000ULL;
  5489. writeq(val64, (void __iomem *) bar0 + 0x2700);
  5490. val64 = readq(&bar0->gpio_control);
  5491. }
  5492. sp->rx_csum = 1; /* Rx chksum verify enabled by default */
  5493. if (register_netdev(dev)) {
  5494. DBG_PRINT(ERR_DBG, "Device registration failed\n");
  5495. ret = -ENODEV;
  5496. goto register_failed;
  5497. }
  5498. if (sp->device_type & XFRAME_II_DEVICE) {
  5499. DBG_PRINT(ERR_DBG, "%s: Neterion Xframe II 10GbE adapter ",
  5500. dev->name);
  5501. DBG_PRINT(ERR_DBG, "(rev %d), Version %s",
  5502. get_xena_rev_id(sp->pdev),
  5503. s2io_driver_version);
  5504. switch(sp->intr_type) {
  5505. case INTA:
  5506. DBG_PRINT(ERR_DBG, ", Intr type INTA");
  5507. break;
  5508. case MSI:
  5509. DBG_PRINT(ERR_DBG, ", Intr type MSI");
  5510. break;
  5511. case MSI_X:
  5512. DBG_PRINT(ERR_DBG, ", Intr type MSI-X");
  5513. break;
  5514. }
  5515. DBG_PRINT(ERR_DBG, "\nCopyright(c) 2002-2005 Neterion Inc.\n");
  5516. DBG_PRINT(ERR_DBG, "MAC ADDR: %02x:%02x:%02x:%02x:%02x:%02x\n",
  5517. sp->def_mac_addr[0].mac_addr[0],
  5518. sp->def_mac_addr[0].mac_addr[1],
  5519. sp->def_mac_addr[0].mac_addr[2],
  5520. sp->def_mac_addr[0].mac_addr[3],
  5521. sp->def_mac_addr[0].mac_addr[4],
  5522. sp->def_mac_addr[0].mac_addr[5]);
  5523. mode = s2io_print_pci_mode(sp);
  5524. if (mode < 0) {
  5525. DBG_PRINT(ERR_DBG, " Unsupported PCI bus mode ");
  5526. ret = -EBADSLT;
  5527. goto set_swap_failed;
  5528. }
  5529. } else {
  5530. DBG_PRINT(ERR_DBG, "%s: Neterion Xframe I 10GbE adapter ",
  5531. dev->name);
  5532. DBG_PRINT(ERR_DBG, "(rev %d), Version %s",
  5533. get_xena_rev_id(sp->pdev),
  5534. s2io_driver_version);
  5535. switch(sp->intr_type) {
  5536. case INTA:
  5537. DBG_PRINT(ERR_DBG, ", Intr type INTA");
  5538. break;
  5539. case MSI:
  5540. DBG_PRINT(ERR_DBG, ", Intr type MSI");
  5541. break;
  5542. case MSI_X:
  5543. DBG_PRINT(ERR_DBG, ", Intr type MSI-X");
  5544. break;
  5545. }
  5546. DBG_PRINT(ERR_DBG, "\nCopyright(c) 2002-2005 Neterion Inc.\n");
  5547. DBG_PRINT(ERR_DBG, "MAC ADDR: %02x:%02x:%02x:%02x:%02x:%02x\n",
  5548. sp->def_mac_addr[0].mac_addr[0],
  5549. sp->def_mac_addr[0].mac_addr[1],
  5550. sp->def_mac_addr[0].mac_addr[2],
  5551. sp->def_mac_addr[0].mac_addr[3],
  5552. sp->def_mac_addr[0].mac_addr[4],
  5553. sp->def_mac_addr[0].mac_addr[5]);
  5554. }
  5555. if (sp->rxd_mode == RXD_MODE_3B)
  5556. DBG_PRINT(ERR_DBG, "%s: 2-Buffer mode support has been "
  5557. "enabled\n",dev->name);
  5558. if (sp->rxd_mode == RXD_MODE_3A)
  5559. DBG_PRINT(ERR_DBG, "%s: 3-Buffer mode support has been "
  5560. "enabled\n",dev->name);
  5561. /* Initialize device name */
  5562. strcpy(sp->name, dev->name);
  5563. if (sp->device_type & XFRAME_II_DEVICE)
  5564. strcat(sp->name, ": Neterion Xframe II 10GbE adapter");
  5565. else
  5566. strcat(sp->name, ": Neterion Xframe I 10GbE adapter");
  5567. /* Initialize bimodal Interrupts */
  5568. sp->config.bimodal = bimodal;
  5569. if (!(sp->device_type & XFRAME_II_DEVICE) && bimodal) {
  5570. sp->config.bimodal = 0;
  5571. DBG_PRINT(ERR_DBG,"%s:Bimodal intr not supported by Xframe I\n",
  5572. dev->name);
  5573. }
  5574. /*
  5575. * Make Link state as off at this point, when the Link change
  5576. * interrupt comes the state will be automatically changed to
  5577. * the right state.
  5578. */
  5579. netif_carrier_off(dev);
  5580. return 0;
  5581. register_failed:
  5582. set_swap_failed:
  5583. iounmap(sp->bar1);
  5584. bar1_remap_failed:
  5585. iounmap(sp->bar0);
  5586. bar0_remap_failed:
  5587. mem_alloc_failed:
  5588. free_shared_mem(sp);
  5589. pci_disable_device(pdev);
  5590. if (dev_intr_type != MSI_X)
  5591. pci_release_regions(pdev);
  5592. else {
  5593. release_mem_region(pci_resource_start(pdev, 0),
  5594. pci_resource_len(pdev, 0));
  5595. release_mem_region(pci_resource_start(pdev, 2),
  5596. pci_resource_len(pdev, 2));
  5597. }
  5598. pci_set_drvdata(pdev, NULL);
  5599. free_netdev(dev);
  5600. return ret;
  5601. }
  5602. /**
  5603. * s2io_rem_nic - Free the PCI device
  5604. * @pdev: structure containing the PCI related information of the device.
  5605. * Description: This function is called by the Pci subsystem to release a
  5606. * PCI device and free up all resource held up by the device. This could
  5607. * be in response to a Hot plug event or when the driver is to be removed
  5608. * from memory.
  5609. */
  5610. static void __devexit s2io_rem_nic(struct pci_dev *pdev)
  5611. {
  5612. struct net_device *dev =
  5613. (struct net_device *) pci_get_drvdata(pdev);
  5614. nic_t *sp;
  5615. if (dev == NULL) {
  5616. DBG_PRINT(ERR_DBG, "Driver Data is NULL!!\n");
  5617. return;
  5618. }
  5619. sp = dev->priv;
  5620. unregister_netdev(dev);
  5621. free_shared_mem(sp);
  5622. iounmap(sp->bar0);
  5623. iounmap(sp->bar1);
  5624. pci_disable_device(pdev);
  5625. if (sp->intr_type != MSI_X)
  5626. pci_release_regions(pdev);
  5627. else {
  5628. release_mem_region(pci_resource_start(pdev, 0),
  5629. pci_resource_len(pdev, 0));
  5630. release_mem_region(pci_resource_start(pdev, 2),
  5631. pci_resource_len(pdev, 2));
  5632. }
  5633. pci_set_drvdata(pdev, NULL);
  5634. free_netdev(dev);
  5635. }
  5636. /**
  5637. * s2io_starter - Entry point for the driver
  5638. * Description: This function is the entry point for the driver. It verifies
  5639. * the module loadable parameters and initializes PCI configuration space.
  5640. */
  5641. int __init s2io_starter(void)
  5642. {
  5643. return pci_module_init(&s2io_driver);
  5644. }
  5645. /**
  5646. * s2io_closer - Cleanup routine for the driver
  5647. * Description: This function is the cleanup routine for the driver. It unregist * ers the driver.
  5648. */
  5649. void s2io_closer(void)
  5650. {
  5651. pci_unregister_driver(&s2io_driver);
  5652. DBG_PRINT(INIT_DBG, "cleanup done\n");
  5653. }
  5654. module_init(s2io_starter);
  5655. module_exit(s2io_closer);