s2io.c 178 KB

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