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