s2io.c 246 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703
  1. /************************************************************************
  2. * s2io.c: A Linux PCI-X Ethernet driver for Neterion 10GbE Server NIC
  3. * Copyright(c) 2002-2007 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. *
  29. * rx_ring_num : This can be used to program the number of receive rings used
  30. * in the driver.
  31. * rx_ring_sz: This defines the number of receive blocks each ring can have.
  32. * This is also an array of size 8.
  33. * rx_ring_mode: This defines the operation mode of all 8 rings. The valid
  34. * values are 1, 2.
  35. * tx_fifo_num: This defines the number of Tx FIFOs thats used int the driver.
  36. * tx_fifo_len: This too is an array of 8. Each element defines the number of
  37. * Tx descriptors that can be associated with each corresponding FIFO.
  38. * intr_type: This defines the type of interrupt. The values can be 0(INTA),
  39. * 2(MSI_X). Default value is '2(MSI_X)'
  40. * lro_enable: Specifies whether to enable Large Receive Offload (LRO) or not.
  41. * Possible values '1' for enable '0' for disable. Default is '0'
  42. * lro_max_pkts: This parameter defines maximum number of packets can be
  43. * aggregated as a single large packet
  44. * napi: This parameter used to enable/disable NAPI (polling Rx)
  45. * Possible values '1' for enable and '0' for disable. Default is '1'
  46. * ufo: This parameter used to enable/disable UDP Fragmentation Offload(UFO)
  47. * Possible values '1' for enable and '0' for disable. Default is '0'
  48. * vlan_tag_strip: This can be used to enable or disable vlan stripping.
  49. * Possible values '1' for enable , '0' for disable.
  50. * Default is '2' - which means disable in promisc mode
  51. * and enable in non-promiscuous mode.
  52. * multiq: This parameter used to enable/disable MULTIQUEUE support.
  53. * Possible values '1' for enable and '0' for disable. Default is '0'
  54. ************************************************************************/
  55. #include <linux/module.h>
  56. #include <linux/types.h>
  57. #include <linux/errno.h>
  58. #include <linux/ioport.h>
  59. #include <linux/pci.h>
  60. #include <linux/dma-mapping.h>
  61. #include <linux/kernel.h>
  62. #include <linux/netdevice.h>
  63. #include <linux/etherdevice.h>
  64. #include <linux/skbuff.h>
  65. #include <linux/init.h>
  66. #include <linux/delay.h>
  67. #include <linux/stddef.h>
  68. #include <linux/ioctl.h>
  69. #include <linux/timex.h>
  70. #include <linux/ethtool.h>
  71. #include <linux/workqueue.h>
  72. #include <linux/if_vlan.h>
  73. #include <linux/ip.h>
  74. #include <linux/tcp.h>
  75. #include <net/tcp.h>
  76. #include <asm/system.h>
  77. #include <asm/uaccess.h>
  78. #include <asm/io.h>
  79. #include <asm/div64.h>
  80. #include <asm/irq.h>
  81. /* local include */
  82. #include "s2io.h"
  83. #include "s2io-regs.h"
  84. #define DRV_VERSION "2.0.26.25"
  85. /* S2io Driver name & version. */
  86. static char s2io_driver_name[] = "Neterion";
  87. static char s2io_driver_version[] = DRV_VERSION;
  88. static int rxd_size[2] = {32,48};
  89. static int rxd_count[2] = {127,85};
  90. static inline int RXD_IS_UP2DT(struct RxD_t *rxdp)
  91. {
  92. int ret;
  93. ret = ((!(rxdp->Control_1 & RXD_OWN_XENA)) &&
  94. (GET_RXD_MARKER(rxdp->Control_2) != THE_RXD_MARK));
  95. return ret;
  96. }
  97. /*
  98. * Cards with following subsystem_id have a link state indication
  99. * problem, 600B, 600C, 600D, 640B, 640C and 640D.
  100. * macro below identifies these cards given the subsystem_id.
  101. */
  102. #define CARDS_WITH_FAULTY_LINK_INDICATORS(dev_type, subid) \
  103. (dev_type == XFRAME_I_DEVICE) ? \
  104. ((((subid >= 0x600B) && (subid <= 0x600D)) || \
  105. ((subid >= 0x640B) && (subid <= 0x640D))) ? 1 : 0) : 0
  106. #define LINK_IS_UP(val64) (!(val64 & (ADAPTER_STATUS_RMAC_REMOTE_FAULT | \
  107. ADAPTER_STATUS_RMAC_LOCAL_FAULT)))
  108. static inline int is_s2io_card_up(const struct s2io_nic * sp)
  109. {
  110. return test_bit(__S2IO_STATE_CARD_UP, &sp->state);
  111. }
  112. /* Ethtool related variables and Macros. */
  113. static char s2io_gstrings[][ETH_GSTRING_LEN] = {
  114. "Register test\t(offline)",
  115. "Eeprom test\t(offline)",
  116. "Link test\t(online)",
  117. "RLDRAM test\t(offline)",
  118. "BIST Test\t(offline)"
  119. };
  120. static char ethtool_xena_stats_keys[][ETH_GSTRING_LEN] = {
  121. {"tmac_frms"},
  122. {"tmac_data_octets"},
  123. {"tmac_drop_frms"},
  124. {"tmac_mcst_frms"},
  125. {"tmac_bcst_frms"},
  126. {"tmac_pause_ctrl_frms"},
  127. {"tmac_ttl_octets"},
  128. {"tmac_ucst_frms"},
  129. {"tmac_nucst_frms"},
  130. {"tmac_any_err_frms"},
  131. {"tmac_ttl_less_fb_octets"},
  132. {"tmac_vld_ip_octets"},
  133. {"tmac_vld_ip"},
  134. {"tmac_drop_ip"},
  135. {"tmac_icmp"},
  136. {"tmac_rst_tcp"},
  137. {"tmac_tcp"},
  138. {"tmac_udp"},
  139. {"rmac_vld_frms"},
  140. {"rmac_data_octets"},
  141. {"rmac_fcs_err_frms"},
  142. {"rmac_drop_frms"},
  143. {"rmac_vld_mcst_frms"},
  144. {"rmac_vld_bcst_frms"},
  145. {"rmac_in_rng_len_err_frms"},
  146. {"rmac_out_rng_len_err_frms"},
  147. {"rmac_long_frms"},
  148. {"rmac_pause_ctrl_frms"},
  149. {"rmac_unsup_ctrl_frms"},
  150. {"rmac_ttl_octets"},
  151. {"rmac_accepted_ucst_frms"},
  152. {"rmac_accepted_nucst_frms"},
  153. {"rmac_discarded_frms"},
  154. {"rmac_drop_events"},
  155. {"rmac_ttl_less_fb_octets"},
  156. {"rmac_ttl_frms"},
  157. {"rmac_usized_frms"},
  158. {"rmac_osized_frms"},
  159. {"rmac_frag_frms"},
  160. {"rmac_jabber_frms"},
  161. {"rmac_ttl_64_frms"},
  162. {"rmac_ttl_65_127_frms"},
  163. {"rmac_ttl_128_255_frms"},
  164. {"rmac_ttl_256_511_frms"},
  165. {"rmac_ttl_512_1023_frms"},
  166. {"rmac_ttl_1024_1518_frms"},
  167. {"rmac_ip"},
  168. {"rmac_ip_octets"},
  169. {"rmac_hdr_err_ip"},
  170. {"rmac_drop_ip"},
  171. {"rmac_icmp"},
  172. {"rmac_tcp"},
  173. {"rmac_udp"},
  174. {"rmac_err_drp_udp"},
  175. {"rmac_xgmii_err_sym"},
  176. {"rmac_frms_q0"},
  177. {"rmac_frms_q1"},
  178. {"rmac_frms_q2"},
  179. {"rmac_frms_q3"},
  180. {"rmac_frms_q4"},
  181. {"rmac_frms_q5"},
  182. {"rmac_frms_q6"},
  183. {"rmac_frms_q7"},
  184. {"rmac_full_q0"},
  185. {"rmac_full_q1"},
  186. {"rmac_full_q2"},
  187. {"rmac_full_q3"},
  188. {"rmac_full_q4"},
  189. {"rmac_full_q5"},
  190. {"rmac_full_q6"},
  191. {"rmac_full_q7"},
  192. {"rmac_pause_cnt"},
  193. {"rmac_xgmii_data_err_cnt"},
  194. {"rmac_xgmii_ctrl_err_cnt"},
  195. {"rmac_accepted_ip"},
  196. {"rmac_err_tcp"},
  197. {"rd_req_cnt"},
  198. {"new_rd_req_cnt"},
  199. {"new_rd_req_rtry_cnt"},
  200. {"rd_rtry_cnt"},
  201. {"wr_rtry_rd_ack_cnt"},
  202. {"wr_req_cnt"},
  203. {"new_wr_req_cnt"},
  204. {"new_wr_req_rtry_cnt"},
  205. {"wr_rtry_cnt"},
  206. {"wr_disc_cnt"},
  207. {"rd_rtry_wr_ack_cnt"},
  208. {"txp_wr_cnt"},
  209. {"txd_rd_cnt"},
  210. {"txd_wr_cnt"},
  211. {"rxd_rd_cnt"},
  212. {"rxd_wr_cnt"},
  213. {"txf_rd_cnt"},
  214. {"rxf_wr_cnt"}
  215. };
  216. static char ethtool_enhanced_stats_keys[][ETH_GSTRING_LEN] = {
  217. {"rmac_ttl_1519_4095_frms"},
  218. {"rmac_ttl_4096_8191_frms"},
  219. {"rmac_ttl_8192_max_frms"},
  220. {"rmac_ttl_gt_max_frms"},
  221. {"rmac_osized_alt_frms"},
  222. {"rmac_jabber_alt_frms"},
  223. {"rmac_gt_max_alt_frms"},
  224. {"rmac_vlan_frms"},
  225. {"rmac_len_discard"},
  226. {"rmac_fcs_discard"},
  227. {"rmac_pf_discard"},
  228. {"rmac_da_discard"},
  229. {"rmac_red_discard"},
  230. {"rmac_rts_discard"},
  231. {"rmac_ingm_full_discard"},
  232. {"link_fault_cnt"}
  233. };
  234. static char ethtool_driver_stats_keys[][ETH_GSTRING_LEN] = {
  235. {"\n DRIVER STATISTICS"},
  236. {"single_bit_ecc_errs"},
  237. {"double_bit_ecc_errs"},
  238. {"parity_err_cnt"},
  239. {"serious_err_cnt"},
  240. {"soft_reset_cnt"},
  241. {"fifo_full_cnt"},
  242. {"ring_0_full_cnt"},
  243. {"ring_1_full_cnt"},
  244. {"ring_2_full_cnt"},
  245. {"ring_3_full_cnt"},
  246. {"ring_4_full_cnt"},
  247. {"ring_5_full_cnt"},
  248. {"ring_6_full_cnt"},
  249. {"ring_7_full_cnt"},
  250. {"alarm_transceiver_temp_high"},
  251. {"alarm_transceiver_temp_low"},
  252. {"alarm_laser_bias_current_high"},
  253. {"alarm_laser_bias_current_low"},
  254. {"alarm_laser_output_power_high"},
  255. {"alarm_laser_output_power_low"},
  256. {"warn_transceiver_temp_high"},
  257. {"warn_transceiver_temp_low"},
  258. {"warn_laser_bias_current_high"},
  259. {"warn_laser_bias_current_low"},
  260. {"warn_laser_output_power_high"},
  261. {"warn_laser_output_power_low"},
  262. {"lro_aggregated_pkts"},
  263. {"lro_flush_both_count"},
  264. {"lro_out_of_sequence_pkts"},
  265. {"lro_flush_due_to_max_pkts"},
  266. {"lro_avg_aggr_pkts"},
  267. {"mem_alloc_fail_cnt"},
  268. {"pci_map_fail_cnt"},
  269. {"watchdog_timer_cnt"},
  270. {"mem_allocated"},
  271. {"mem_freed"},
  272. {"link_up_cnt"},
  273. {"link_down_cnt"},
  274. {"link_up_time"},
  275. {"link_down_time"},
  276. {"tx_tcode_buf_abort_cnt"},
  277. {"tx_tcode_desc_abort_cnt"},
  278. {"tx_tcode_parity_err_cnt"},
  279. {"tx_tcode_link_loss_cnt"},
  280. {"tx_tcode_list_proc_err_cnt"},
  281. {"rx_tcode_parity_err_cnt"},
  282. {"rx_tcode_abort_cnt"},
  283. {"rx_tcode_parity_abort_cnt"},
  284. {"rx_tcode_rda_fail_cnt"},
  285. {"rx_tcode_unkn_prot_cnt"},
  286. {"rx_tcode_fcs_err_cnt"},
  287. {"rx_tcode_buf_size_err_cnt"},
  288. {"rx_tcode_rxd_corrupt_cnt"},
  289. {"rx_tcode_unkn_err_cnt"},
  290. {"tda_err_cnt"},
  291. {"pfc_err_cnt"},
  292. {"pcc_err_cnt"},
  293. {"tti_err_cnt"},
  294. {"tpa_err_cnt"},
  295. {"sm_err_cnt"},
  296. {"lso_err_cnt"},
  297. {"mac_tmac_err_cnt"},
  298. {"mac_rmac_err_cnt"},
  299. {"xgxs_txgxs_err_cnt"},
  300. {"xgxs_rxgxs_err_cnt"},
  301. {"rc_err_cnt"},
  302. {"prc_pcix_err_cnt"},
  303. {"rpa_err_cnt"},
  304. {"rda_err_cnt"},
  305. {"rti_err_cnt"},
  306. {"mc_err_cnt"}
  307. };
  308. #define S2IO_XENA_STAT_LEN ARRAY_SIZE(ethtool_xena_stats_keys)
  309. #define S2IO_ENHANCED_STAT_LEN ARRAY_SIZE(ethtool_enhanced_stats_keys)
  310. #define S2IO_DRIVER_STAT_LEN ARRAY_SIZE(ethtool_driver_stats_keys)
  311. #define XFRAME_I_STAT_LEN (S2IO_XENA_STAT_LEN + S2IO_DRIVER_STAT_LEN )
  312. #define XFRAME_II_STAT_LEN (XFRAME_I_STAT_LEN + S2IO_ENHANCED_STAT_LEN )
  313. #define XFRAME_I_STAT_STRINGS_LEN ( XFRAME_I_STAT_LEN * ETH_GSTRING_LEN )
  314. #define XFRAME_II_STAT_STRINGS_LEN ( XFRAME_II_STAT_LEN * ETH_GSTRING_LEN )
  315. #define S2IO_TEST_LEN ARRAY_SIZE(s2io_gstrings)
  316. #define S2IO_STRINGS_LEN S2IO_TEST_LEN * ETH_GSTRING_LEN
  317. #define S2IO_TIMER_CONF(timer, handle, arg, exp) \
  318. init_timer(&timer); \
  319. timer.function = handle; \
  320. timer.data = (unsigned long) arg; \
  321. mod_timer(&timer, (jiffies + exp)) \
  322. /* copy mac addr to def_mac_addr array */
  323. static void do_s2io_copy_mac_addr(struct s2io_nic *sp, int offset, u64 mac_addr)
  324. {
  325. sp->def_mac_addr[offset].mac_addr[5] = (u8) (mac_addr);
  326. sp->def_mac_addr[offset].mac_addr[4] = (u8) (mac_addr >> 8);
  327. sp->def_mac_addr[offset].mac_addr[3] = (u8) (mac_addr >> 16);
  328. sp->def_mac_addr[offset].mac_addr[2] = (u8) (mac_addr >> 24);
  329. sp->def_mac_addr[offset].mac_addr[1] = (u8) (mac_addr >> 32);
  330. sp->def_mac_addr[offset].mac_addr[0] = (u8) (mac_addr >> 40);
  331. }
  332. /* Add the vlan */
  333. static void s2io_vlan_rx_register(struct net_device *dev,
  334. struct vlan_group *grp)
  335. {
  336. int i;
  337. struct s2io_nic *nic = netdev_priv(dev);
  338. unsigned long flags[MAX_TX_FIFOS];
  339. struct mac_info *mac_control = &nic->mac_control;
  340. struct config_param *config = &nic->config;
  341. for (i = 0; i < config->tx_fifo_num; i++)
  342. spin_lock_irqsave(&mac_control->fifos[i].tx_lock, flags[i]);
  343. nic->vlgrp = grp;
  344. for (i = config->tx_fifo_num - 1; i >= 0; i--)
  345. spin_unlock_irqrestore(&mac_control->fifos[i].tx_lock,
  346. flags[i]);
  347. }
  348. /* Unregister the vlan */
  349. static void s2io_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
  350. {
  351. int i;
  352. struct s2io_nic *nic = netdev_priv(dev);
  353. unsigned long flags[MAX_TX_FIFOS];
  354. struct mac_info *mac_control = &nic->mac_control;
  355. struct config_param *config = &nic->config;
  356. for (i = 0; i < config->tx_fifo_num; i++)
  357. spin_lock_irqsave(&mac_control->fifos[i].tx_lock, flags[i]);
  358. if (nic->vlgrp)
  359. vlan_group_set_device(nic->vlgrp, vid, NULL);
  360. for (i = config->tx_fifo_num - 1; i >= 0; i--)
  361. spin_unlock_irqrestore(&mac_control->fifos[i].tx_lock,
  362. flags[i]);
  363. }
  364. /*
  365. * Constants to be programmed into the Xena's registers, to configure
  366. * the XAUI.
  367. */
  368. #define END_SIGN 0x0
  369. static const u64 herc_act_dtx_cfg[] = {
  370. /* Set address */
  371. 0x8000051536750000ULL, 0x80000515367500E0ULL,
  372. /* Write data */
  373. 0x8000051536750004ULL, 0x80000515367500E4ULL,
  374. /* Set address */
  375. 0x80010515003F0000ULL, 0x80010515003F00E0ULL,
  376. /* Write data */
  377. 0x80010515003F0004ULL, 0x80010515003F00E4ULL,
  378. /* Set address */
  379. 0x801205150D440000ULL, 0x801205150D4400E0ULL,
  380. /* Write data */
  381. 0x801205150D440004ULL, 0x801205150D4400E4ULL,
  382. /* Set address */
  383. 0x80020515F2100000ULL, 0x80020515F21000E0ULL,
  384. /* Write data */
  385. 0x80020515F2100004ULL, 0x80020515F21000E4ULL,
  386. /* Done */
  387. END_SIGN
  388. };
  389. static const u64 xena_dtx_cfg[] = {
  390. /* Set address */
  391. 0x8000051500000000ULL, 0x80000515000000E0ULL,
  392. /* Write data */
  393. 0x80000515D9350004ULL, 0x80000515D93500E4ULL,
  394. /* Set address */
  395. 0x8001051500000000ULL, 0x80010515000000E0ULL,
  396. /* Write data */
  397. 0x80010515001E0004ULL, 0x80010515001E00E4ULL,
  398. /* Set address */
  399. 0x8002051500000000ULL, 0x80020515000000E0ULL,
  400. /* Write data */
  401. 0x80020515F2100004ULL, 0x80020515F21000E4ULL,
  402. END_SIGN
  403. };
  404. /*
  405. * Constants for Fixing the MacAddress problem seen mostly on
  406. * Alpha machines.
  407. */
  408. static const u64 fix_mac[] = {
  409. 0x0060000000000000ULL, 0x0060600000000000ULL,
  410. 0x0040600000000000ULL, 0x0000600000000000ULL,
  411. 0x0020600000000000ULL, 0x0060600000000000ULL,
  412. 0x0020600000000000ULL, 0x0060600000000000ULL,
  413. 0x0020600000000000ULL, 0x0060600000000000ULL,
  414. 0x0020600000000000ULL, 0x0060600000000000ULL,
  415. 0x0020600000000000ULL, 0x0060600000000000ULL,
  416. 0x0020600000000000ULL, 0x0060600000000000ULL,
  417. 0x0020600000000000ULL, 0x0060600000000000ULL,
  418. 0x0020600000000000ULL, 0x0060600000000000ULL,
  419. 0x0020600000000000ULL, 0x0060600000000000ULL,
  420. 0x0020600000000000ULL, 0x0060600000000000ULL,
  421. 0x0020600000000000ULL, 0x0000600000000000ULL,
  422. 0x0040600000000000ULL, 0x0060600000000000ULL,
  423. END_SIGN
  424. };
  425. MODULE_LICENSE("GPL");
  426. MODULE_VERSION(DRV_VERSION);
  427. /* Module Loadable parameters. */
  428. S2IO_PARM_INT(tx_fifo_num, FIFO_DEFAULT_NUM);
  429. S2IO_PARM_INT(rx_ring_num, 1);
  430. S2IO_PARM_INT(multiq, 0);
  431. S2IO_PARM_INT(rx_ring_mode, 1);
  432. S2IO_PARM_INT(use_continuous_tx_intrs, 1);
  433. S2IO_PARM_INT(rmac_pause_time, 0x100);
  434. S2IO_PARM_INT(mc_pause_threshold_q0q3, 187);
  435. S2IO_PARM_INT(mc_pause_threshold_q4q7, 187);
  436. S2IO_PARM_INT(shared_splits, 0);
  437. S2IO_PARM_INT(tmac_util_period, 5);
  438. S2IO_PARM_INT(rmac_util_period, 5);
  439. S2IO_PARM_INT(l3l4hdr_size, 128);
  440. /* 0 is no steering, 1 is Priority steering, 2 is Default steering */
  441. S2IO_PARM_INT(tx_steering_type, TX_DEFAULT_STEERING);
  442. /* Frequency of Rx desc syncs expressed as power of 2 */
  443. S2IO_PARM_INT(rxsync_frequency, 3);
  444. /* Interrupt type. Values can be 0(INTA), 2(MSI_X) */
  445. S2IO_PARM_INT(intr_type, 2);
  446. /* Large receive offload feature */
  447. static unsigned int lro_enable;
  448. module_param_named(lro, lro_enable, uint, 0);
  449. /* Max pkts to be aggregated by LRO at one time. If not specified,
  450. * aggregation happens until we hit max IP pkt size(64K)
  451. */
  452. S2IO_PARM_INT(lro_max_pkts, 0xFFFF);
  453. S2IO_PARM_INT(indicate_max_pkts, 0);
  454. S2IO_PARM_INT(napi, 1);
  455. S2IO_PARM_INT(ufo, 0);
  456. S2IO_PARM_INT(vlan_tag_strip, NO_STRIP_IN_PROMISC);
  457. static unsigned int tx_fifo_len[MAX_TX_FIFOS] =
  458. {DEFAULT_FIFO_0_LEN, [1 ...(MAX_TX_FIFOS - 1)] = DEFAULT_FIFO_1_7_LEN};
  459. static unsigned int rx_ring_sz[MAX_RX_RINGS] =
  460. {[0 ...(MAX_RX_RINGS - 1)] = SMALL_BLK_CNT};
  461. static unsigned int rts_frm_len[MAX_RX_RINGS] =
  462. {[0 ...(MAX_RX_RINGS - 1)] = 0 };
  463. module_param_array(tx_fifo_len, uint, NULL, 0);
  464. module_param_array(rx_ring_sz, uint, NULL, 0);
  465. module_param_array(rts_frm_len, uint, NULL, 0);
  466. /*
  467. * S2IO device table.
  468. * This table lists all the devices that this driver supports.
  469. */
  470. static struct pci_device_id s2io_tbl[] __devinitdata = {
  471. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_S2IO_WIN,
  472. PCI_ANY_ID, PCI_ANY_ID},
  473. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_S2IO_UNI,
  474. PCI_ANY_ID, PCI_ANY_ID},
  475. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_HERC_WIN,
  476. PCI_ANY_ID, PCI_ANY_ID},
  477. {PCI_VENDOR_ID_S2IO, PCI_DEVICE_ID_HERC_UNI,
  478. PCI_ANY_ID, PCI_ANY_ID},
  479. {0,}
  480. };
  481. MODULE_DEVICE_TABLE(pci, s2io_tbl);
  482. static struct pci_error_handlers s2io_err_handler = {
  483. .error_detected = s2io_io_error_detected,
  484. .slot_reset = s2io_io_slot_reset,
  485. .resume = s2io_io_resume,
  486. };
  487. static struct pci_driver s2io_driver = {
  488. .name = "S2IO",
  489. .id_table = s2io_tbl,
  490. .probe = s2io_init_nic,
  491. .remove = __devexit_p(s2io_rem_nic),
  492. .err_handler = &s2io_err_handler,
  493. };
  494. /* A simplifier macro used both by init and free shared_mem Fns(). */
  495. #define TXD_MEM_PAGE_CNT(len, per_each) ((len+per_each - 1) / per_each)
  496. /* netqueue manipulation helper functions */
  497. static inline void s2io_stop_all_tx_queue(struct s2io_nic *sp)
  498. {
  499. if (!sp->config.multiq) {
  500. int i;
  501. for (i = 0; i < sp->config.tx_fifo_num; i++)
  502. sp->mac_control.fifos[i].queue_state = FIFO_QUEUE_STOP;
  503. }
  504. netif_tx_stop_all_queues(sp->dev);
  505. }
  506. static inline void s2io_stop_tx_queue(struct s2io_nic *sp, int fifo_no)
  507. {
  508. if (!sp->config.multiq)
  509. sp->mac_control.fifos[fifo_no].queue_state =
  510. FIFO_QUEUE_STOP;
  511. netif_tx_stop_all_queues(sp->dev);
  512. }
  513. static inline void s2io_start_all_tx_queue(struct s2io_nic *sp)
  514. {
  515. if (!sp->config.multiq) {
  516. int i;
  517. for (i = 0; i < sp->config.tx_fifo_num; i++)
  518. sp->mac_control.fifos[i].queue_state = FIFO_QUEUE_START;
  519. }
  520. netif_tx_start_all_queues(sp->dev);
  521. }
  522. static inline void s2io_start_tx_queue(struct s2io_nic *sp, int fifo_no)
  523. {
  524. if (!sp->config.multiq)
  525. sp->mac_control.fifos[fifo_no].queue_state =
  526. FIFO_QUEUE_START;
  527. netif_tx_start_all_queues(sp->dev);
  528. }
  529. static inline void s2io_wake_all_tx_queue(struct s2io_nic *sp)
  530. {
  531. if (!sp->config.multiq) {
  532. int i;
  533. for (i = 0; i < sp->config.tx_fifo_num; i++)
  534. sp->mac_control.fifos[i].queue_state = FIFO_QUEUE_START;
  535. }
  536. netif_tx_wake_all_queues(sp->dev);
  537. }
  538. static inline void s2io_wake_tx_queue(
  539. struct fifo_info *fifo, int cnt, u8 multiq)
  540. {
  541. if (multiq) {
  542. if (cnt && __netif_subqueue_stopped(fifo->dev, fifo->fifo_no))
  543. netif_wake_subqueue(fifo->dev, fifo->fifo_no);
  544. } else if (cnt && (fifo->queue_state == FIFO_QUEUE_STOP)) {
  545. if (netif_queue_stopped(fifo->dev)) {
  546. fifo->queue_state = FIFO_QUEUE_START;
  547. netif_wake_queue(fifo->dev);
  548. }
  549. }
  550. }
  551. /**
  552. * init_shared_mem - Allocation and Initialization of Memory
  553. * @nic: Device private variable.
  554. * Description: The function allocates all the memory areas shared
  555. * between the NIC and the driver. This includes Tx descriptors,
  556. * Rx descriptors and the statistics block.
  557. */
  558. static int init_shared_mem(struct s2io_nic *nic)
  559. {
  560. u32 size;
  561. void *tmp_v_addr, *tmp_v_addr_next;
  562. dma_addr_t tmp_p_addr, tmp_p_addr_next;
  563. struct RxD_block *pre_rxd_blk = NULL;
  564. int i, j, blk_cnt;
  565. int lst_size, lst_per_page;
  566. struct net_device *dev = nic->dev;
  567. unsigned long tmp;
  568. struct buffAdd *ba;
  569. struct mac_info *mac_control;
  570. struct config_param *config;
  571. unsigned long long mem_allocated = 0;
  572. mac_control = &nic->mac_control;
  573. config = &nic->config;
  574. /* Allocation and initialization of TXDLs in FIOFs */
  575. size = 0;
  576. for (i = 0; i < config->tx_fifo_num; i++) {
  577. size += config->tx_cfg[i].fifo_len;
  578. }
  579. if (size > MAX_AVAILABLE_TXDS) {
  580. DBG_PRINT(ERR_DBG, "s2io: Requested TxDs too high, ");
  581. DBG_PRINT(ERR_DBG, "Requested: %d, max supported: 8192\n", size);
  582. return -EINVAL;
  583. }
  584. size = 0;
  585. for (i = 0; i < config->tx_fifo_num; i++) {
  586. size = config->tx_cfg[i].fifo_len;
  587. /*
  588. * Legal values are from 2 to 8192
  589. */
  590. if (size < 2) {
  591. DBG_PRINT(ERR_DBG, "s2io: Invalid fifo len (%d)", size);
  592. DBG_PRINT(ERR_DBG, "for fifo %d\n", i);
  593. DBG_PRINT(ERR_DBG, "s2io: Legal values for fifo len"
  594. "are 2 to 8192\n");
  595. return -EINVAL;
  596. }
  597. }
  598. lst_size = (sizeof(struct TxD) * config->max_txds);
  599. lst_per_page = PAGE_SIZE / lst_size;
  600. for (i = 0; i < config->tx_fifo_num; i++) {
  601. int fifo_len = config->tx_cfg[i].fifo_len;
  602. int list_holder_size = fifo_len * sizeof(struct list_info_hold);
  603. mac_control->fifos[i].list_info = kzalloc(list_holder_size,
  604. GFP_KERNEL);
  605. if (!mac_control->fifos[i].list_info) {
  606. DBG_PRINT(INFO_DBG,
  607. "Malloc failed for list_info\n");
  608. return -ENOMEM;
  609. }
  610. mem_allocated += list_holder_size;
  611. }
  612. for (i = 0; i < config->tx_fifo_num; i++) {
  613. int page_num = TXD_MEM_PAGE_CNT(config->tx_cfg[i].fifo_len,
  614. lst_per_page);
  615. mac_control->fifos[i].tx_curr_put_info.offset = 0;
  616. mac_control->fifos[i].tx_curr_put_info.fifo_len =
  617. config->tx_cfg[i].fifo_len - 1;
  618. mac_control->fifos[i].tx_curr_get_info.offset = 0;
  619. mac_control->fifos[i].tx_curr_get_info.fifo_len =
  620. config->tx_cfg[i].fifo_len - 1;
  621. mac_control->fifos[i].fifo_no = i;
  622. mac_control->fifos[i].nic = nic;
  623. mac_control->fifos[i].max_txds = MAX_SKB_FRAGS + 2;
  624. mac_control->fifos[i].dev = dev;
  625. for (j = 0; j < page_num; j++) {
  626. int k = 0;
  627. dma_addr_t tmp_p;
  628. void *tmp_v;
  629. tmp_v = pci_alloc_consistent(nic->pdev,
  630. PAGE_SIZE, &tmp_p);
  631. if (!tmp_v) {
  632. DBG_PRINT(INFO_DBG,
  633. "pci_alloc_consistent ");
  634. DBG_PRINT(INFO_DBG, "failed for TxDL\n");
  635. return -ENOMEM;
  636. }
  637. /* If we got a zero DMA address(can happen on
  638. * certain platforms like PPC), reallocate.
  639. * Store virtual address of page we don't want,
  640. * to be freed later.
  641. */
  642. if (!tmp_p) {
  643. mac_control->zerodma_virt_addr = tmp_v;
  644. DBG_PRINT(INIT_DBG,
  645. "%s: Zero DMA address for TxDL. ", dev->name);
  646. DBG_PRINT(INIT_DBG,
  647. "Virtual address %p\n", tmp_v);
  648. tmp_v = pci_alloc_consistent(nic->pdev,
  649. PAGE_SIZE, &tmp_p);
  650. if (!tmp_v) {
  651. DBG_PRINT(INFO_DBG,
  652. "pci_alloc_consistent ");
  653. DBG_PRINT(INFO_DBG, "failed for TxDL\n");
  654. return -ENOMEM;
  655. }
  656. mem_allocated += PAGE_SIZE;
  657. }
  658. while (k < lst_per_page) {
  659. int l = (j * lst_per_page) + k;
  660. if (l == config->tx_cfg[i].fifo_len)
  661. break;
  662. mac_control->fifos[i].list_info[l].list_virt_addr =
  663. tmp_v + (k * lst_size);
  664. mac_control->fifos[i].list_info[l].list_phy_addr =
  665. tmp_p + (k * lst_size);
  666. k++;
  667. }
  668. }
  669. }
  670. for (i = 0; i < config->tx_fifo_num; i++) {
  671. size = config->tx_cfg[i].fifo_len;
  672. mac_control->fifos[i].ufo_in_band_v
  673. = kcalloc(size, sizeof(u64), GFP_KERNEL);
  674. if (!mac_control->fifos[i].ufo_in_band_v)
  675. return -ENOMEM;
  676. mem_allocated += (size * sizeof(u64));
  677. }
  678. /* Allocation and initialization of RXDs in Rings */
  679. size = 0;
  680. for (i = 0; i < config->rx_ring_num; i++) {
  681. if (config->rx_cfg[i].num_rxd %
  682. (rxd_count[nic->rxd_mode] + 1)) {
  683. DBG_PRINT(ERR_DBG, "%s: RxD count of ", dev->name);
  684. DBG_PRINT(ERR_DBG, "Ring%d is not a multiple of ",
  685. i);
  686. DBG_PRINT(ERR_DBG, "RxDs per Block");
  687. return FAILURE;
  688. }
  689. size += config->rx_cfg[i].num_rxd;
  690. mac_control->rings[i].block_count =
  691. config->rx_cfg[i].num_rxd /
  692. (rxd_count[nic->rxd_mode] + 1 );
  693. mac_control->rings[i].pkt_cnt = config->rx_cfg[i].num_rxd -
  694. mac_control->rings[i].block_count;
  695. }
  696. if (nic->rxd_mode == RXD_MODE_1)
  697. size = (size * (sizeof(struct RxD1)));
  698. else
  699. size = (size * (sizeof(struct RxD3)));
  700. for (i = 0; i < config->rx_ring_num; i++) {
  701. mac_control->rings[i].rx_curr_get_info.block_index = 0;
  702. mac_control->rings[i].rx_curr_get_info.offset = 0;
  703. mac_control->rings[i].rx_curr_get_info.ring_len =
  704. config->rx_cfg[i].num_rxd - 1;
  705. mac_control->rings[i].rx_curr_put_info.block_index = 0;
  706. mac_control->rings[i].rx_curr_put_info.offset = 0;
  707. mac_control->rings[i].rx_curr_put_info.ring_len =
  708. config->rx_cfg[i].num_rxd - 1;
  709. mac_control->rings[i].nic = nic;
  710. mac_control->rings[i].ring_no = i;
  711. mac_control->rings[i].lro = lro_enable;
  712. blk_cnt = config->rx_cfg[i].num_rxd /
  713. (rxd_count[nic->rxd_mode] + 1);
  714. /* Allocating all the Rx blocks */
  715. for (j = 0; j < blk_cnt; j++) {
  716. struct rx_block_info *rx_blocks;
  717. int l;
  718. rx_blocks = &mac_control->rings[i].rx_blocks[j];
  719. size = SIZE_OF_BLOCK; //size is always page size
  720. tmp_v_addr = pci_alloc_consistent(nic->pdev, size,
  721. &tmp_p_addr);
  722. if (tmp_v_addr == NULL) {
  723. /*
  724. * In case of failure, free_shared_mem()
  725. * is called, which should free any
  726. * memory that was alloced till the
  727. * failure happened.
  728. */
  729. rx_blocks->block_virt_addr = tmp_v_addr;
  730. return -ENOMEM;
  731. }
  732. mem_allocated += size;
  733. memset(tmp_v_addr, 0, size);
  734. rx_blocks->block_virt_addr = tmp_v_addr;
  735. rx_blocks->block_dma_addr = tmp_p_addr;
  736. rx_blocks->rxds = kmalloc(sizeof(struct rxd_info)*
  737. rxd_count[nic->rxd_mode],
  738. GFP_KERNEL);
  739. if (!rx_blocks->rxds)
  740. return -ENOMEM;
  741. mem_allocated +=
  742. (sizeof(struct rxd_info)* rxd_count[nic->rxd_mode]);
  743. for (l=0; l<rxd_count[nic->rxd_mode];l++) {
  744. rx_blocks->rxds[l].virt_addr =
  745. rx_blocks->block_virt_addr +
  746. (rxd_size[nic->rxd_mode] * l);
  747. rx_blocks->rxds[l].dma_addr =
  748. rx_blocks->block_dma_addr +
  749. (rxd_size[nic->rxd_mode] * l);
  750. }
  751. }
  752. /* Interlinking all Rx Blocks */
  753. for (j = 0; j < blk_cnt; j++) {
  754. tmp_v_addr =
  755. mac_control->rings[i].rx_blocks[j].block_virt_addr;
  756. tmp_v_addr_next =
  757. mac_control->rings[i].rx_blocks[(j + 1) %
  758. blk_cnt].block_virt_addr;
  759. tmp_p_addr =
  760. mac_control->rings[i].rx_blocks[j].block_dma_addr;
  761. tmp_p_addr_next =
  762. mac_control->rings[i].rx_blocks[(j + 1) %
  763. blk_cnt].block_dma_addr;
  764. pre_rxd_blk = (struct RxD_block *) tmp_v_addr;
  765. pre_rxd_blk->reserved_2_pNext_RxD_block =
  766. (unsigned long) tmp_v_addr_next;
  767. pre_rxd_blk->pNext_RxD_Blk_physical =
  768. (u64) tmp_p_addr_next;
  769. }
  770. }
  771. if (nic->rxd_mode == RXD_MODE_3B) {
  772. /*
  773. * Allocation of Storages for buffer addresses in 2BUFF mode
  774. * and the buffers as well.
  775. */
  776. for (i = 0; i < config->rx_ring_num; i++) {
  777. blk_cnt = config->rx_cfg[i].num_rxd /
  778. (rxd_count[nic->rxd_mode]+ 1);
  779. mac_control->rings[i].ba =
  780. kmalloc((sizeof(struct buffAdd *) * blk_cnt),
  781. GFP_KERNEL);
  782. if (!mac_control->rings[i].ba)
  783. return -ENOMEM;
  784. mem_allocated +=(sizeof(struct buffAdd *) * blk_cnt);
  785. for (j = 0; j < blk_cnt; j++) {
  786. int k = 0;
  787. mac_control->rings[i].ba[j] =
  788. kmalloc((sizeof(struct buffAdd) *
  789. (rxd_count[nic->rxd_mode] + 1)),
  790. GFP_KERNEL);
  791. if (!mac_control->rings[i].ba[j])
  792. return -ENOMEM;
  793. mem_allocated += (sizeof(struct buffAdd) * \
  794. (rxd_count[nic->rxd_mode] + 1));
  795. while (k != rxd_count[nic->rxd_mode]) {
  796. ba = &mac_control->rings[i].ba[j][k];
  797. ba->ba_0_org = (void *) kmalloc
  798. (BUF0_LEN + ALIGN_SIZE, GFP_KERNEL);
  799. if (!ba->ba_0_org)
  800. return -ENOMEM;
  801. mem_allocated +=
  802. (BUF0_LEN + ALIGN_SIZE);
  803. tmp = (unsigned long)ba->ba_0_org;
  804. tmp += ALIGN_SIZE;
  805. tmp &= ~((unsigned long) ALIGN_SIZE);
  806. ba->ba_0 = (void *) tmp;
  807. ba->ba_1_org = (void *) kmalloc
  808. (BUF1_LEN + ALIGN_SIZE, GFP_KERNEL);
  809. if (!ba->ba_1_org)
  810. return -ENOMEM;
  811. mem_allocated
  812. += (BUF1_LEN + ALIGN_SIZE);
  813. tmp = (unsigned long) ba->ba_1_org;
  814. tmp += ALIGN_SIZE;
  815. tmp &= ~((unsigned long) ALIGN_SIZE);
  816. ba->ba_1 = (void *) tmp;
  817. k++;
  818. }
  819. }
  820. }
  821. }
  822. /* Allocation and initialization of Statistics block */
  823. size = sizeof(struct stat_block);
  824. mac_control->stats_mem = pci_alloc_consistent
  825. (nic->pdev, size, &mac_control->stats_mem_phy);
  826. if (!mac_control->stats_mem) {
  827. /*
  828. * In case of failure, free_shared_mem() is called, which
  829. * should free any memory that was alloced till the
  830. * failure happened.
  831. */
  832. return -ENOMEM;
  833. }
  834. mem_allocated += size;
  835. mac_control->stats_mem_sz = size;
  836. tmp_v_addr = mac_control->stats_mem;
  837. mac_control->stats_info = (struct stat_block *) tmp_v_addr;
  838. memset(tmp_v_addr, 0, size);
  839. DBG_PRINT(INIT_DBG, "%s:Ring Mem PHY: 0x%llx\n", dev->name,
  840. (unsigned long long) tmp_p_addr);
  841. mac_control->stats_info->sw_stat.mem_allocated += mem_allocated;
  842. return SUCCESS;
  843. }
  844. /**
  845. * free_shared_mem - Free the allocated Memory
  846. * @nic: Device private variable.
  847. * Description: This function is to free all memory locations allocated by
  848. * the init_shared_mem() function and return it to the kernel.
  849. */
  850. static void free_shared_mem(struct s2io_nic *nic)
  851. {
  852. int i, j, blk_cnt, size;
  853. void *tmp_v_addr;
  854. dma_addr_t tmp_p_addr;
  855. struct mac_info *mac_control;
  856. struct config_param *config;
  857. int lst_size, lst_per_page;
  858. struct net_device *dev;
  859. int page_num = 0;
  860. if (!nic)
  861. return;
  862. dev = nic->dev;
  863. mac_control = &nic->mac_control;
  864. config = &nic->config;
  865. lst_size = (sizeof(struct TxD) * config->max_txds);
  866. lst_per_page = PAGE_SIZE / lst_size;
  867. for (i = 0; i < config->tx_fifo_num; i++) {
  868. page_num = TXD_MEM_PAGE_CNT(config->tx_cfg[i].fifo_len,
  869. lst_per_page);
  870. for (j = 0; j < page_num; j++) {
  871. int mem_blks = (j * lst_per_page);
  872. if (!mac_control->fifos[i].list_info)
  873. return;
  874. if (!mac_control->fifos[i].list_info[mem_blks].
  875. list_virt_addr)
  876. break;
  877. pci_free_consistent(nic->pdev, PAGE_SIZE,
  878. mac_control->fifos[i].
  879. list_info[mem_blks].
  880. list_virt_addr,
  881. mac_control->fifos[i].
  882. list_info[mem_blks].
  883. list_phy_addr);
  884. nic->mac_control.stats_info->sw_stat.mem_freed
  885. += PAGE_SIZE;
  886. }
  887. /* If we got a zero DMA address during allocation,
  888. * free the page now
  889. */
  890. if (mac_control->zerodma_virt_addr) {
  891. pci_free_consistent(nic->pdev, PAGE_SIZE,
  892. mac_control->zerodma_virt_addr,
  893. (dma_addr_t)0);
  894. DBG_PRINT(INIT_DBG,
  895. "%s: Freeing TxDL with zero DMA addr. ",
  896. dev->name);
  897. DBG_PRINT(INIT_DBG, "Virtual address %p\n",
  898. mac_control->zerodma_virt_addr);
  899. nic->mac_control.stats_info->sw_stat.mem_freed
  900. += PAGE_SIZE;
  901. }
  902. kfree(mac_control->fifos[i].list_info);
  903. nic->mac_control.stats_info->sw_stat.mem_freed +=
  904. (nic->config.tx_cfg[i].fifo_len *sizeof(struct list_info_hold));
  905. }
  906. size = SIZE_OF_BLOCK;
  907. for (i = 0; i < config->rx_ring_num; i++) {
  908. blk_cnt = mac_control->rings[i].block_count;
  909. for (j = 0; j < blk_cnt; j++) {
  910. tmp_v_addr = mac_control->rings[i].rx_blocks[j].
  911. block_virt_addr;
  912. tmp_p_addr = mac_control->rings[i].rx_blocks[j].
  913. block_dma_addr;
  914. if (tmp_v_addr == NULL)
  915. break;
  916. pci_free_consistent(nic->pdev, size,
  917. tmp_v_addr, tmp_p_addr);
  918. nic->mac_control.stats_info->sw_stat.mem_freed += size;
  919. kfree(mac_control->rings[i].rx_blocks[j].rxds);
  920. nic->mac_control.stats_info->sw_stat.mem_freed +=
  921. ( sizeof(struct rxd_info)* rxd_count[nic->rxd_mode]);
  922. }
  923. }
  924. if (nic->rxd_mode == RXD_MODE_3B) {
  925. /* Freeing buffer storage addresses in 2BUFF mode. */
  926. for (i = 0; i < config->rx_ring_num; i++) {
  927. blk_cnt = config->rx_cfg[i].num_rxd /
  928. (rxd_count[nic->rxd_mode] + 1);
  929. for (j = 0; j < blk_cnt; j++) {
  930. int k = 0;
  931. if (!mac_control->rings[i].ba[j])
  932. continue;
  933. while (k != rxd_count[nic->rxd_mode]) {
  934. struct buffAdd *ba =
  935. &mac_control->rings[i].ba[j][k];
  936. kfree(ba->ba_0_org);
  937. nic->mac_control.stats_info->sw_stat.\
  938. mem_freed += (BUF0_LEN + ALIGN_SIZE);
  939. kfree(ba->ba_1_org);
  940. nic->mac_control.stats_info->sw_stat.\
  941. mem_freed += (BUF1_LEN + ALIGN_SIZE);
  942. k++;
  943. }
  944. kfree(mac_control->rings[i].ba[j]);
  945. nic->mac_control.stats_info->sw_stat.mem_freed +=
  946. (sizeof(struct buffAdd) *
  947. (rxd_count[nic->rxd_mode] + 1));
  948. }
  949. kfree(mac_control->rings[i].ba);
  950. nic->mac_control.stats_info->sw_stat.mem_freed +=
  951. (sizeof(struct buffAdd *) * blk_cnt);
  952. }
  953. }
  954. for (i = 0; i < nic->config.tx_fifo_num; i++) {
  955. if (mac_control->fifos[i].ufo_in_band_v) {
  956. nic->mac_control.stats_info->sw_stat.mem_freed
  957. += (config->tx_cfg[i].fifo_len * sizeof(u64));
  958. kfree(mac_control->fifos[i].ufo_in_band_v);
  959. }
  960. }
  961. if (mac_control->stats_mem) {
  962. nic->mac_control.stats_info->sw_stat.mem_freed +=
  963. mac_control->stats_mem_sz;
  964. pci_free_consistent(nic->pdev,
  965. mac_control->stats_mem_sz,
  966. mac_control->stats_mem,
  967. mac_control->stats_mem_phy);
  968. }
  969. }
  970. /**
  971. * s2io_verify_pci_mode -
  972. */
  973. static int s2io_verify_pci_mode(struct s2io_nic *nic)
  974. {
  975. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  976. register u64 val64 = 0;
  977. int mode;
  978. val64 = readq(&bar0->pci_mode);
  979. mode = (u8)GET_PCI_MODE(val64);
  980. if ( val64 & PCI_MODE_UNKNOWN_MODE)
  981. return -1; /* Unknown PCI mode */
  982. return mode;
  983. }
  984. #define NEC_VENID 0x1033
  985. #define NEC_DEVID 0x0125
  986. static int s2io_on_nec_bridge(struct pci_dev *s2io_pdev)
  987. {
  988. struct pci_dev *tdev = NULL;
  989. while ((tdev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, tdev)) != NULL) {
  990. if (tdev->vendor == NEC_VENID && tdev->device == NEC_DEVID) {
  991. if (tdev->bus == s2io_pdev->bus->parent) {
  992. pci_dev_put(tdev);
  993. return 1;
  994. }
  995. }
  996. }
  997. return 0;
  998. }
  999. static int bus_speed[8] = {33, 133, 133, 200, 266, 133, 200, 266};
  1000. /**
  1001. * s2io_print_pci_mode -
  1002. */
  1003. static int s2io_print_pci_mode(struct s2io_nic *nic)
  1004. {
  1005. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  1006. register u64 val64 = 0;
  1007. int mode;
  1008. struct config_param *config = &nic->config;
  1009. val64 = readq(&bar0->pci_mode);
  1010. mode = (u8)GET_PCI_MODE(val64);
  1011. if ( val64 & PCI_MODE_UNKNOWN_MODE)
  1012. return -1; /* Unknown PCI mode */
  1013. config->bus_speed = bus_speed[mode];
  1014. if (s2io_on_nec_bridge(nic->pdev)) {
  1015. DBG_PRINT(ERR_DBG, "%s: Device is on PCI-E bus\n",
  1016. nic->dev->name);
  1017. return mode;
  1018. }
  1019. if (val64 & PCI_MODE_32_BITS) {
  1020. DBG_PRINT(ERR_DBG, "%s: Device is on 32 bit ", nic->dev->name);
  1021. } else {
  1022. DBG_PRINT(ERR_DBG, "%s: Device is on 64 bit ", nic->dev->name);
  1023. }
  1024. switch(mode) {
  1025. case PCI_MODE_PCI_33:
  1026. DBG_PRINT(ERR_DBG, "33MHz PCI bus\n");
  1027. break;
  1028. case PCI_MODE_PCI_66:
  1029. DBG_PRINT(ERR_DBG, "66MHz PCI bus\n");
  1030. break;
  1031. case PCI_MODE_PCIX_M1_66:
  1032. DBG_PRINT(ERR_DBG, "66MHz PCIX(M1) bus\n");
  1033. break;
  1034. case PCI_MODE_PCIX_M1_100:
  1035. DBG_PRINT(ERR_DBG, "100MHz PCIX(M1) bus\n");
  1036. break;
  1037. case PCI_MODE_PCIX_M1_133:
  1038. DBG_PRINT(ERR_DBG, "133MHz PCIX(M1) bus\n");
  1039. break;
  1040. case PCI_MODE_PCIX_M2_66:
  1041. DBG_PRINT(ERR_DBG, "133MHz PCIX(M2) bus\n");
  1042. break;
  1043. case PCI_MODE_PCIX_M2_100:
  1044. DBG_PRINT(ERR_DBG, "200MHz PCIX(M2) bus\n");
  1045. break;
  1046. case PCI_MODE_PCIX_M2_133:
  1047. DBG_PRINT(ERR_DBG, "266MHz PCIX(M2) bus\n");
  1048. break;
  1049. default:
  1050. return -1; /* Unsupported bus speed */
  1051. }
  1052. return mode;
  1053. }
  1054. /**
  1055. * init_tti - Initialization transmit traffic interrupt scheme
  1056. * @nic: device private variable
  1057. * @link: link status (UP/DOWN) used to enable/disable continuous
  1058. * transmit interrupts
  1059. * Description: The function configures transmit traffic interrupts
  1060. * Return Value: SUCCESS on success and
  1061. * '-1' on failure
  1062. */
  1063. static int init_tti(struct s2io_nic *nic, int link)
  1064. {
  1065. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  1066. register u64 val64 = 0;
  1067. int i;
  1068. struct config_param *config;
  1069. config = &nic->config;
  1070. for (i = 0; i < config->tx_fifo_num; i++) {
  1071. /*
  1072. * TTI Initialization. Default Tx timer gets us about
  1073. * 250 interrupts per sec. Continuous interrupts are enabled
  1074. * by default.
  1075. */
  1076. if (nic->device_type == XFRAME_II_DEVICE) {
  1077. int count = (nic->config.bus_speed * 125)/2;
  1078. val64 = TTI_DATA1_MEM_TX_TIMER_VAL(count);
  1079. } else
  1080. val64 = TTI_DATA1_MEM_TX_TIMER_VAL(0x2078);
  1081. val64 |= TTI_DATA1_MEM_TX_URNG_A(0xA) |
  1082. TTI_DATA1_MEM_TX_URNG_B(0x10) |
  1083. TTI_DATA1_MEM_TX_URNG_C(0x30) |
  1084. TTI_DATA1_MEM_TX_TIMER_AC_EN;
  1085. if (i == 0)
  1086. if (use_continuous_tx_intrs && (link == LINK_UP))
  1087. val64 |= TTI_DATA1_MEM_TX_TIMER_CI_EN;
  1088. writeq(val64, &bar0->tti_data1_mem);
  1089. if (nic->config.intr_type == MSI_X) {
  1090. val64 = TTI_DATA2_MEM_TX_UFC_A(0x10) |
  1091. TTI_DATA2_MEM_TX_UFC_B(0x100) |
  1092. TTI_DATA2_MEM_TX_UFC_C(0x200) |
  1093. TTI_DATA2_MEM_TX_UFC_D(0x300);
  1094. } else {
  1095. if ((nic->config.tx_steering_type ==
  1096. TX_DEFAULT_STEERING) &&
  1097. (config->tx_fifo_num > 1) &&
  1098. (i >= nic->udp_fifo_idx) &&
  1099. (i < (nic->udp_fifo_idx +
  1100. nic->total_udp_fifos)))
  1101. val64 = TTI_DATA2_MEM_TX_UFC_A(0x50) |
  1102. TTI_DATA2_MEM_TX_UFC_B(0x80) |
  1103. TTI_DATA2_MEM_TX_UFC_C(0x100) |
  1104. TTI_DATA2_MEM_TX_UFC_D(0x120);
  1105. else
  1106. val64 = TTI_DATA2_MEM_TX_UFC_A(0x10) |
  1107. TTI_DATA2_MEM_TX_UFC_B(0x20) |
  1108. TTI_DATA2_MEM_TX_UFC_C(0x40) |
  1109. TTI_DATA2_MEM_TX_UFC_D(0x80);
  1110. }
  1111. writeq(val64, &bar0->tti_data2_mem);
  1112. val64 = TTI_CMD_MEM_WE | TTI_CMD_MEM_STROBE_NEW_CMD |
  1113. TTI_CMD_MEM_OFFSET(i);
  1114. writeq(val64, &bar0->tti_command_mem);
  1115. if (wait_for_cmd_complete(&bar0->tti_command_mem,
  1116. TTI_CMD_MEM_STROBE_NEW_CMD, S2IO_BIT_RESET) != SUCCESS)
  1117. return FAILURE;
  1118. }
  1119. return SUCCESS;
  1120. }
  1121. /**
  1122. * init_nic - Initialization of hardware
  1123. * @nic: device private variable
  1124. * Description: The function sequentially configures every block
  1125. * of the H/W from their reset values.
  1126. * Return Value: SUCCESS on success and
  1127. * '-1' on failure (endian settings incorrect).
  1128. */
  1129. static int init_nic(struct s2io_nic *nic)
  1130. {
  1131. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  1132. struct net_device *dev = nic->dev;
  1133. register u64 val64 = 0;
  1134. void __iomem *add;
  1135. u32 time;
  1136. int i, j;
  1137. struct mac_info *mac_control;
  1138. struct config_param *config;
  1139. int dtx_cnt = 0;
  1140. unsigned long long mem_share;
  1141. int mem_size;
  1142. mac_control = &nic->mac_control;
  1143. config = &nic->config;
  1144. /* to set the swapper controle on the card */
  1145. if(s2io_set_swapper(nic)) {
  1146. DBG_PRINT(ERR_DBG,"ERROR: Setting Swapper failed\n");
  1147. return -EIO;
  1148. }
  1149. /*
  1150. * Herc requires EOI to be removed from reset before XGXS, so..
  1151. */
  1152. if (nic->device_type & XFRAME_II_DEVICE) {
  1153. val64 = 0xA500000000ULL;
  1154. writeq(val64, &bar0->sw_reset);
  1155. msleep(500);
  1156. val64 = readq(&bar0->sw_reset);
  1157. }
  1158. /* Remove XGXS from reset state */
  1159. val64 = 0;
  1160. writeq(val64, &bar0->sw_reset);
  1161. msleep(500);
  1162. val64 = readq(&bar0->sw_reset);
  1163. /* Ensure that it's safe to access registers by checking
  1164. * RIC_RUNNING bit is reset. Check is valid only for XframeII.
  1165. */
  1166. if (nic->device_type == XFRAME_II_DEVICE) {
  1167. for (i = 0; i < 50; i++) {
  1168. val64 = readq(&bar0->adapter_status);
  1169. if (!(val64 & ADAPTER_STATUS_RIC_RUNNING))
  1170. break;
  1171. msleep(10);
  1172. }
  1173. if (i == 50)
  1174. return -ENODEV;
  1175. }
  1176. /* Enable Receiving broadcasts */
  1177. add = &bar0->mac_cfg;
  1178. val64 = readq(&bar0->mac_cfg);
  1179. val64 |= MAC_RMAC_BCAST_ENABLE;
  1180. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  1181. writel((u32) val64, add);
  1182. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  1183. writel((u32) (val64 >> 32), (add + 4));
  1184. /* Read registers in all blocks */
  1185. val64 = readq(&bar0->mac_int_mask);
  1186. val64 = readq(&bar0->mc_int_mask);
  1187. val64 = readq(&bar0->xgxs_int_mask);
  1188. /* Set MTU */
  1189. val64 = dev->mtu;
  1190. writeq(vBIT(val64, 2, 14), &bar0->rmac_max_pyld_len);
  1191. if (nic->device_type & XFRAME_II_DEVICE) {
  1192. while (herc_act_dtx_cfg[dtx_cnt] != END_SIGN) {
  1193. SPECIAL_REG_WRITE(herc_act_dtx_cfg[dtx_cnt],
  1194. &bar0->dtx_control, UF);
  1195. if (dtx_cnt & 0x1)
  1196. msleep(1); /* Necessary!! */
  1197. dtx_cnt++;
  1198. }
  1199. } else {
  1200. while (xena_dtx_cfg[dtx_cnt] != END_SIGN) {
  1201. SPECIAL_REG_WRITE(xena_dtx_cfg[dtx_cnt],
  1202. &bar0->dtx_control, UF);
  1203. val64 = readq(&bar0->dtx_control);
  1204. dtx_cnt++;
  1205. }
  1206. }
  1207. /* Tx DMA Initialization */
  1208. val64 = 0;
  1209. writeq(val64, &bar0->tx_fifo_partition_0);
  1210. writeq(val64, &bar0->tx_fifo_partition_1);
  1211. writeq(val64, &bar0->tx_fifo_partition_2);
  1212. writeq(val64, &bar0->tx_fifo_partition_3);
  1213. for (i = 0, j = 0; i < config->tx_fifo_num; i++) {
  1214. val64 |=
  1215. vBIT(config->tx_cfg[i].fifo_len - 1, ((j * 32) + 19),
  1216. 13) | vBIT(config->tx_cfg[i].fifo_priority,
  1217. ((j * 32) + 5), 3);
  1218. if (i == (config->tx_fifo_num - 1)) {
  1219. if (i % 2 == 0)
  1220. i++;
  1221. }
  1222. switch (i) {
  1223. case 1:
  1224. writeq(val64, &bar0->tx_fifo_partition_0);
  1225. val64 = 0;
  1226. j = 0;
  1227. break;
  1228. case 3:
  1229. writeq(val64, &bar0->tx_fifo_partition_1);
  1230. val64 = 0;
  1231. j = 0;
  1232. break;
  1233. case 5:
  1234. writeq(val64, &bar0->tx_fifo_partition_2);
  1235. val64 = 0;
  1236. j = 0;
  1237. break;
  1238. case 7:
  1239. writeq(val64, &bar0->tx_fifo_partition_3);
  1240. val64 = 0;
  1241. j = 0;
  1242. break;
  1243. default:
  1244. j++;
  1245. break;
  1246. }
  1247. }
  1248. /*
  1249. * Disable 4 PCCs for Xena1, 2 and 3 as per H/W bug
  1250. * SXE-008 TRANSMIT DMA ARBITRATION ISSUE.
  1251. */
  1252. if ((nic->device_type == XFRAME_I_DEVICE) &&
  1253. (nic->pdev->revision < 4))
  1254. writeq(PCC_ENABLE_FOUR, &bar0->pcc_enable);
  1255. val64 = readq(&bar0->tx_fifo_partition_0);
  1256. DBG_PRINT(INIT_DBG, "Fifo partition at: 0x%p is: 0x%llx\n",
  1257. &bar0->tx_fifo_partition_0, (unsigned long long) val64);
  1258. /*
  1259. * Initialization of Tx_PA_CONFIG register to ignore packet
  1260. * integrity checking.
  1261. */
  1262. val64 = readq(&bar0->tx_pa_cfg);
  1263. val64 |= TX_PA_CFG_IGNORE_FRM_ERR | TX_PA_CFG_IGNORE_SNAP_OUI |
  1264. TX_PA_CFG_IGNORE_LLC_CTRL | TX_PA_CFG_IGNORE_L2_ERR;
  1265. writeq(val64, &bar0->tx_pa_cfg);
  1266. /* Rx DMA intialization. */
  1267. val64 = 0;
  1268. for (i = 0; i < config->rx_ring_num; i++) {
  1269. val64 |=
  1270. vBIT(config->rx_cfg[i].ring_priority, (5 + (i * 8)),
  1271. 3);
  1272. }
  1273. writeq(val64, &bar0->rx_queue_priority);
  1274. /*
  1275. * Allocating equal share of memory to all the
  1276. * configured Rings.
  1277. */
  1278. val64 = 0;
  1279. if (nic->device_type & XFRAME_II_DEVICE)
  1280. mem_size = 32;
  1281. else
  1282. mem_size = 64;
  1283. for (i = 0; i < config->rx_ring_num; i++) {
  1284. switch (i) {
  1285. case 0:
  1286. mem_share = (mem_size / config->rx_ring_num +
  1287. mem_size % config->rx_ring_num);
  1288. val64 |= RX_QUEUE_CFG_Q0_SZ(mem_share);
  1289. continue;
  1290. case 1:
  1291. mem_share = (mem_size / config->rx_ring_num);
  1292. val64 |= RX_QUEUE_CFG_Q1_SZ(mem_share);
  1293. continue;
  1294. case 2:
  1295. mem_share = (mem_size / config->rx_ring_num);
  1296. val64 |= RX_QUEUE_CFG_Q2_SZ(mem_share);
  1297. continue;
  1298. case 3:
  1299. mem_share = (mem_size / config->rx_ring_num);
  1300. val64 |= RX_QUEUE_CFG_Q3_SZ(mem_share);
  1301. continue;
  1302. case 4:
  1303. mem_share = (mem_size / config->rx_ring_num);
  1304. val64 |= RX_QUEUE_CFG_Q4_SZ(mem_share);
  1305. continue;
  1306. case 5:
  1307. mem_share = (mem_size / config->rx_ring_num);
  1308. val64 |= RX_QUEUE_CFG_Q5_SZ(mem_share);
  1309. continue;
  1310. case 6:
  1311. mem_share = (mem_size / config->rx_ring_num);
  1312. val64 |= RX_QUEUE_CFG_Q6_SZ(mem_share);
  1313. continue;
  1314. case 7:
  1315. mem_share = (mem_size / config->rx_ring_num);
  1316. val64 |= RX_QUEUE_CFG_Q7_SZ(mem_share);
  1317. continue;
  1318. }
  1319. }
  1320. writeq(val64, &bar0->rx_queue_cfg);
  1321. /*
  1322. * Filling Tx round robin registers
  1323. * as per the number of FIFOs for equal scheduling priority
  1324. */
  1325. switch (config->tx_fifo_num) {
  1326. case 1:
  1327. val64 = 0x0;
  1328. writeq(val64, &bar0->tx_w_round_robin_0);
  1329. writeq(val64, &bar0->tx_w_round_robin_1);
  1330. writeq(val64, &bar0->tx_w_round_robin_2);
  1331. writeq(val64, &bar0->tx_w_round_robin_3);
  1332. writeq(val64, &bar0->tx_w_round_robin_4);
  1333. break;
  1334. case 2:
  1335. val64 = 0x0001000100010001ULL;
  1336. writeq(val64, &bar0->tx_w_round_robin_0);
  1337. writeq(val64, &bar0->tx_w_round_robin_1);
  1338. writeq(val64, &bar0->tx_w_round_robin_2);
  1339. writeq(val64, &bar0->tx_w_round_robin_3);
  1340. val64 = 0x0001000100000000ULL;
  1341. writeq(val64, &bar0->tx_w_round_robin_4);
  1342. break;
  1343. case 3:
  1344. val64 = 0x0001020001020001ULL;
  1345. writeq(val64, &bar0->tx_w_round_robin_0);
  1346. val64 = 0x0200010200010200ULL;
  1347. writeq(val64, &bar0->tx_w_round_robin_1);
  1348. val64 = 0x0102000102000102ULL;
  1349. writeq(val64, &bar0->tx_w_round_robin_2);
  1350. val64 = 0x0001020001020001ULL;
  1351. writeq(val64, &bar0->tx_w_round_robin_3);
  1352. val64 = 0x0200010200000000ULL;
  1353. writeq(val64, &bar0->tx_w_round_robin_4);
  1354. break;
  1355. case 4:
  1356. val64 = 0x0001020300010203ULL;
  1357. writeq(val64, &bar0->tx_w_round_robin_0);
  1358. writeq(val64, &bar0->tx_w_round_robin_1);
  1359. writeq(val64, &bar0->tx_w_round_robin_2);
  1360. writeq(val64, &bar0->tx_w_round_robin_3);
  1361. val64 = 0x0001020300000000ULL;
  1362. writeq(val64, &bar0->tx_w_round_robin_4);
  1363. break;
  1364. case 5:
  1365. val64 = 0x0001020304000102ULL;
  1366. writeq(val64, &bar0->tx_w_round_robin_0);
  1367. val64 = 0x0304000102030400ULL;
  1368. writeq(val64, &bar0->tx_w_round_robin_1);
  1369. val64 = 0x0102030400010203ULL;
  1370. writeq(val64, &bar0->tx_w_round_robin_2);
  1371. val64 = 0x0400010203040001ULL;
  1372. writeq(val64, &bar0->tx_w_round_robin_3);
  1373. val64 = 0x0203040000000000ULL;
  1374. writeq(val64, &bar0->tx_w_round_robin_4);
  1375. break;
  1376. case 6:
  1377. val64 = 0x0001020304050001ULL;
  1378. writeq(val64, &bar0->tx_w_round_robin_0);
  1379. val64 = 0x0203040500010203ULL;
  1380. writeq(val64, &bar0->tx_w_round_robin_1);
  1381. val64 = 0x0405000102030405ULL;
  1382. writeq(val64, &bar0->tx_w_round_robin_2);
  1383. val64 = 0x0001020304050001ULL;
  1384. writeq(val64, &bar0->tx_w_round_robin_3);
  1385. val64 = 0x0203040500000000ULL;
  1386. writeq(val64, &bar0->tx_w_round_robin_4);
  1387. break;
  1388. case 7:
  1389. val64 = 0x0001020304050600ULL;
  1390. writeq(val64, &bar0->tx_w_round_robin_0);
  1391. val64 = 0x0102030405060001ULL;
  1392. writeq(val64, &bar0->tx_w_round_robin_1);
  1393. val64 = 0x0203040506000102ULL;
  1394. writeq(val64, &bar0->tx_w_round_robin_2);
  1395. val64 = 0x0304050600010203ULL;
  1396. writeq(val64, &bar0->tx_w_round_robin_3);
  1397. val64 = 0x0405060000000000ULL;
  1398. writeq(val64, &bar0->tx_w_round_robin_4);
  1399. break;
  1400. case 8:
  1401. val64 = 0x0001020304050607ULL;
  1402. writeq(val64, &bar0->tx_w_round_robin_0);
  1403. writeq(val64, &bar0->tx_w_round_robin_1);
  1404. writeq(val64, &bar0->tx_w_round_robin_2);
  1405. writeq(val64, &bar0->tx_w_round_robin_3);
  1406. val64 = 0x0001020300000000ULL;
  1407. writeq(val64, &bar0->tx_w_round_robin_4);
  1408. break;
  1409. }
  1410. /* Enable all configured Tx FIFO partitions */
  1411. val64 = readq(&bar0->tx_fifo_partition_0);
  1412. val64 |= (TX_FIFO_PARTITION_EN);
  1413. writeq(val64, &bar0->tx_fifo_partition_0);
  1414. /* Filling the Rx round robin registers as per the
  1415. * number of Rings and steering based on QoS with
  1416. * equal priority.
  1417. */
  1418. switch (config->rx_ring_num) {
  1419. case 1:
  1420. val64 = 0x0;
  1421. writeq(val64, &bar0->rx_w_round_robin_0);
  1422. writeq(val64, &bar0->rx_w_round_robin_1);
  1423. writeq(val64, &bar0->rx_w_round_robin_2);
  1424. writeq(val64, &bar0->rx_w_round_robin_3);
  1425. writeq(val64, &bar0->rx_w_round_robin_4);
  1426. val64 = 0x8080808080808080ULL;
  1427. writeq(val64, &bar0->rts_qos_steering);
  1428. break;
  1429. case 2:
  1430. val64 = 0x0001000100010001ULL;
  1431. writeq(val64, &bar0->rx_w_round_robin_0);
  1432. writeq(val64, &bar0->rx_w_round_robin_1);
  1433. writeq(val64, &bar0->rx_w_round_robin_2);
  1434. writeq(val64, &bar0->rx_w_round_robin_3);
  1435. val64 = 0x0001000100000000ULL;
  1436. writeq(val64, &bar0->rx_w_round_robin_4);
  1437. val64 = 0x8080808040404040ULL;
  1438. writeq(val64, &bar0->rts_qos_steering);
  1439. break;
  1440. case 3:
  1441. val64 = 0x0001020001020001ULL;
  1442. writeq(val64, &bar0->rx_w_round_robin_0);
  1443. val64 = 0x0200010200010200ULL;
  1444. writeq(val64, &bar0->rx_w_round_robin_1);
  1445. val64 = 0x0102000102000102ULL;
  1446. writeq(val64, &bar0->rx_w_round_robin_2);
  1447. val64 = 0x0001020001020001ULL;
  1448. writeq(val64, &bar0->rx_w_round_robin_3);
  1449. val64 = 0x0200010200000000ULL;
  1450. writeq(val64, &bar0->rx_w_round_robin_4);
  1451. val64 = 0x8080804040402020ULL;
  1452. writeq(val64, &bar0->rts_qos_steering);
  1453. break;
  1454. case 4:
  1455. val64 = 0x0001020300010203ULL;
  1456. writeq(val64, &bar0->rx_w_round_robin_0);
  1457. writeq(val64, &bar0->rx_w_round_robin_1);
  1458. writeq(val64, &bar0->rx_w_round_robin_2);
  1459. writeq(val64, &bar0->rx_w_round_robin_3);
  1460. val64 = 0x0001020300000000ULL;
  1461. writeq(val64, &bar0->rx_w_round_robin_4);
  1462. val64 = 0x8080404020201010ULL;
  1463. writeq(val64, &bar0->rts_qos_steering);
  1464. break;
  1465. case 5:
  1466. val64 = 0x0001020304000102ULL;
  1467. writeq(val64, &bar0->rx_w_round_robin_0);
  1468. val64 = 0x0304000102030400ULL;
  1469. writeq(val64, &bar0->rx_w_round_robin_1);
  1470. val64 = 0x0102030400010203ULL;
  1471. writeq(val64, &bar0->rx_w_round_robin_2);
  1472. val64 = 0x0400010203040001ULL;
  1473. writeq(val64, &bar0->rx_w_round_robin_3);
  1474. val64 = 0x0203040000000000ULL;
  1475. writeq(val64, &bar0->rx_w_round_robin_4);
  1476. val64 = 0x8080404020201008ULL;
  1477. writeq(val64, &bar0->rts_qos_steering);
  1478. break;
  1479. case 6:
  1480. val64 = 0x0001020304050001ULL;
  1481. writeq(val64, &bar0->rx_w_round_robin_0);
  1482. val64 = 0x0203040500010203ULL;
  1483. writeq(val64, &bar0->rx_w_round_robin_1);
  1484. val64 = 0x0405000102030405ULL;
  1485. writeq(val64, &bar0->rx_w_round_robin_2);
  1486. val64 = 0x0001020304050001ULL;
  1487. writeq(val64, &bar0->rx_w_round_robin_3);
  1488. val64 = 0x0203040500000000ULL;
  1489. writeq(val64, &bar0->rx_w_round_robin_4);
  1490. val64 = 0x8080404020100804ULL;
  1491. writeq(val64, &bar0->rts_qos_steering);
  1492. break;
  1493. case 7:
  1494. val64 = 0x0001020304050600ULL;
  1495. writeq(val64, &bar0->rx_w_round_robin_0);
  1496. val64 = 0x0102030405060001ULL;
  1497. writeq(val64, &bar0->rx_w_round_robin_1);
  1498. val64 = 0x0203040506000102ULL;
  1499. writeq(val64, &bar0->rx_w_round_robin_2);
  1500. val64 = 0x0304050600010203ULL;
  1501. writeq(val64, &bar0->rx_w_round_robin_3);
  1502. val64 = 0x0405060000000000ULL;
  1503. writeq(val64, &bar0->rx_w_round_robin_4);
  1504. val64 = 0x8080402010080402ULL;
  1505. writeq(val64, &bar0->rts_qos_steering);
  1506. break;
  1507. case 8:
  1508. val64 = 0x0001020304050607ULL;
  1509. writeq(val64, &bar0->rx_w_round_robin_0);
  1510. writeq(val64, &bar0->rx_w_round_robin_1);
  1511. writeq(val64, &bar0->rx_w_round_robin_2);
  1512. writeq(val64, &bar0->rx_w_round_robin_3);
  1513. val64 = 0x0001020300000000ULL;
  1514. writeq(val64, &bar0->rx_w_round_robin_4);
  1515. val64 = 0x8040201008040201ULL;
  1516. writeq(val64, &bar0->rts_qos_steering);
  1517. break;
  1518. }
  1519. /* UDP Fix */
  1520. val64 = 0;
  1521. for (i = 0; i < 8; i++)
  1522. writeq(val64, &bar0->rts_frm_len_n[i]);
  1523. /* Set the default rts frame length for the rings configured */
  1524. val64 = MAC_RTS_FRM_LEN_SET(dev->mtu+22);
  1525. for (i = 0 ; i < config->rx_ring_num ; i++)
  1526. writeq(val64, &bar0->rts_frm_len_n[i]);
  1527. /* Set the frame length for the configured rings
  1528. * desired by the user
  1529. */
  1530. for (i = 0; i < config->rx_ring_num; i++) {
  1531. /* If rts_frm_len[i] == 0 then it is assumed that user not
  1532. * specified frame length steering.
  1533. * If the user provides the frame length then program
  1534. * the rts_frm_len register for those values or else
  1535. * leave it as it is.
  1536. */
  1537. if (rts_frm_len[i] != 0) {
  1538. writeq(MAC_RTS_FRM_LEN_SET(rts_frm_len[i]),
  1539. &bar0->rts_frm_len_n[i]);
  1540. }
  1541. }
  1542. /* Disable differentiated services steering logic */
  1543. for (i = 0; i < 64; i++) {
  1544. if (rts_ds_steer(nic, i, 0) == FAILURE) {
  1545. DBG_PRINT(ERR_DBG, "%s: failed rts ds steering",
  1546. dev->name);
  1547. DBG_PRINT(ERR_DBG, "set on codepoint %d\n", i);
  1548. return -ENODEV;
  1549. }
  1550. }
  1551. /* Program statistics memory */
  1552. writeq(mac_control->stats_mem_phy, &bar0->stat_addr);
  1553. if (nic->device_type == XFRAME_II_DEVICE) {
  1554. val64 = STAT_BC(0x320);
  1555. writeq(val64, &bar0->stat_byte_cnt);
  1556. }
  1557. /*
  1558. * Initializing the sampling rate for the device to calculate the
  1559. * bandwidth utilization.
  1560. */
  1561. val64 = MAC_TX_LINK_UTIL_VAL(tmac_util_period) |
  1562. MAC_RX_LINK_UTIL_VAL(rmac_util_period);
  1563. writeq(val64, &bar0->mac_link_util);
  1564. /*
  1565. * Initializing the Transmit and Receive Traffic Interrupt
  1566. * Scheme.
  1567. */
  1568. /* Initialize TTI */
  1569. if (SUCCESS != init_tti(nic, nic->last_link_state))
  1570. return -ENODEV;
  1571. /* RTI Initialization */
  1572. if (nic->device_type == XFRAME_II_DEVICE) {
  1573. /*
  1574. * Programmed to generate Apprx 500 Intrs per
  1575. * second
  1576. */
  1577. int count = (nic->config.bus_speed * 125)/4;
  1578. val64 = RTI_DATA1_MEM_RX_TIMER_VAL(count);
  1579. } else
  1580. val64 = RTI_DATA1_MEM_RX_TIMER_VAL(0xFFF);
  1581. val64 |= RTI_DATA1_MEM_RX_URNG_A(0xA) |
  1582. RTI_DATA1_MEM_RX_URNG_B(0x10) |
  1583. RTI_DATA1_MEM_RX_URNG_C(0x30) | RTI_DATA1_MEM_RX_TIMER_AC_EN;
  1584. writeq(val64, &bar0->rti_data1_mem);
  1585. val64 = RTI_DATA2_MEM_RX_UFC_A(0x1) |
  1586. RTI_DATA2_MEM_RX_UFC_B(0x2) ;
  1587. if (nic->config.intr_type == MSI_X)
  1588. val64 |= (RTI_DATA2_MEM_RX_UFC_C(0x20) | \
  1589. RTI_DATA2_MEM_RX_UFC_D(0x40));
  1590. else
  1591. val64 |= (RTI_DATA2_MEM_RX_UFC_C(0x40) | \
  1592. RTI_DATA2_MEM_RX_UFC_D(0x80));
  1593. writeq(val64, &bar0->rti_data2_mem);
  1594. for (i = 0; i < config->rx_ring_num; i++) {
  1595. val64 = RTI_CMD_MEM_WE | RTI_CMD_MEM_STROBE_NEW_CMD
  1596. | RTI_CMD_MEM_OFFSET(i);
  1597. writeq(val64, &bar0->rti_command_mem);
  1598. /*
  1599. * Once the operation completes, the Strobe bit of the
  1600. * command register will be reset. We poll for this
  1601. * particular condition. We wait for a maximum of 500ms
  1602. * for the operation to complete, if it's not complete
  1603. * by then we return error.
  1604. */
  1605. time = 0;
  1606. while (TRUE) {
  1607. val64 = readq(&bar0->rti_command_mem);
  1608. if (!(val64 & RTI_CMD_MEM_STROBE_NEW_CMD))
  1609. break;
  1610. if (time > 10) {
  1611. DBG_PRINT(ERR_DBG, "%s: RTI init Failed\n",
  1612. dev->name);
  1613. return -ENODEV;
  1614. }
  1615. time++;
  1616. msleep(50);
  1617. }
  1618. }
  1619. /*
  1620. * Initializing proper values as Pause threshold into all
  1621. * the 8 Queues on Rx side.
  1622. */
  1623. writeq(0xffbbffbbffbbffbbULL, &bar0->mc_pause_thresh_q0q3);
  1624. writeq(0xffbbffbbffbbffbbULL, &bar0->mc_pause_thresh_q4q7);
  1625. /* Disable RMAC PAD STRIPPING */
  1626. add = &bar0->mac_cfg;
  1627. val64 = readq(&bar0->mac_cfg);
  1628. val64 &= ~(MAC_CFG_RMAC_STRIP_PAD);
  1629. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  1630. writel((u32) (val64), add);
  1631. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  1632. writel((u32) (val64 >> 32), (add + 4));
  1633. val64 = readq(&bar0->mac_cfg);
  1634. /* Enable FCS stripping by adapter */
  1635. add = &bar0->mac_cfg;
  1636. val64 = readq(&bar0->mac_cfg);
  1637. val64 |= MAC_CFG_RMAC_STRIP_FCS;
  1638. if (nic->device_type == XFRAME_II_DEVICE)
  1639. writeq(val64, &bar0->mac_cfg);
  1640. else {
  1641. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  1642. writel((u32) (val64), add);
  1643. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  1644. writel((u32) (val64 >> 32), (add + 4));
  1645. }
  1646. /*
  1647. * Set the time value to be inserted in the pause frame
  1648. * generated by xena.
  1649. */
  1650. val64 = readq(&bar0->rmac_pause_cfg);
  1651. val64 &= ~(RMAC_PAUSE_HG_PTIME(0xffff));
  1652. val64 |= RMAC_PAUSE_HG_PTIME(nic->mac_control.rmac_pause_time);
  1653. writeq(val64, &bar0->rmac_pause_cfg);
  1654. /*
  1655. * Set the Threshold Limit for Generating the pause frame
  1656. * If the amount of data in any Queue exceeds ratio of
  1657. * (mac_control.mc_pause_threshold_q0q3 or q4q7)/256
  1658. * pause frame is generated
  1659. */
  1660. val64 = 0;
  1661. for (i = 0; i < 4; i++) {
  1662. val64 |=
  1663. (((u64) 0xFF00 | nic->mac_control.
  1664. mc_pause_threshold_q0q3)
  1665. << (i * 2 * 8));
  1666. }
  1667. writeq(val64, &bar0->mc_pause_thresh_q0q3);
  1668. val64 = 0;
  1669. for (i = 0; i < 4; i++) {
  1670. val64 |=
  1671. (((u64) 0xFF00 | nic->mac_control.
  1672. mc_pause_threshold_q4q7)
  1673. << (i * 2 * 8));
  1674. }
  1675. writeq(val64, &bar0->mc_pause_thresh_q4q7);
  1676. /*
  1677. * TxDMA will stop Read request if the number of read split has
  1678. * exceeded the limit pointed by shared_splits
  1679. */
  1680. val64 = readq(&bar0->pic_control);
  1681. val64 |= PIC_CNTL_SHARED_SPLITS(shared_splits);
  1682. writeq(val64, &bar0->pic_control);
  1683. if (nic->config.bus_speed == 266) {
  1684. writeq(TXREQTO_VAL(0x7f) | TXREQTO_EN, &bar0->txreqtimeout);
  1685. writeq(0x0, &bar0->read_retry_delay);
  1686. writeq(0x0, &bar0->write_retry_delay);
  1687. }
  1688. /*
  1689. * Programming the Herc to split every write transaction
  1690. * that does not start on an ADB to reduce disconnects.
  1691. */
  1692. if (nic->device_type == XFRAME_II_DEVICE) {
  1693. val64 = FAULT_BEHAVIOUR | EXT_REQ_EN |
  1694. MISC_LINK_STABILITY_PRD(3);
  1695. writeq(val64, &bar0->misc_control);
  1696. val64 = readq(&bar0->pic_control2);
  1697. val64 &= ~(s2BIT(13)|s2BIT(14)|s2BIT(15));
  1698. writeq(val64, &bar0->pic_control2);
  1699. }
  1700. if (strstr(nic->product_name, "CX4")) {
  1701. val64 = TMAC_AVG_IPG(0x17);
  1702. writeq(val64, &bar0->tmac_avg_ipg);
  1703. }
  1704. return SUCCESS;
  1705. }
  1706. #define LINK_UP_DOWN_INTERRUPT 1
  1707. #define MAC_RMAC_ERR_TIMER 2
  1708. static int s2io_link_fault_indication(struct s2io_nic *nic)
  1709. {
  1710. if (nic->device_type == XFRAME_II_DEVICE)
  1711. return LINK_UP_DOWN_INTERRUPT;
  1712. else
  1713. return MAC_RMAC_ERR_TIMER;
  1714. }
  1715. /**
  1716. * do_s2io_write_bits - update alarm bits in alarm register
  1717. * @value: alarm bits
  1718. * @flag: interrupt status
  1719. * @addr: address value
  1720. * Description: update alarm bits in alarm register
  1721. * Return Value:
  1722. * NONE.
  1723. */
  1724. static void do_s2io_write_bits(u64 value, int flag, void __iomem *addr)
  1725. {
  1726. u64 temp64;
  1727. temp64 = readq(addr);
  1728. if(flag == ENABLE_INTRS)
  1729. temp64 &= ~((u64) value);
  1730. else
  1731. temp64 |= ((u64) value);
  1732. writeq(temp64, addr);
  1733. }
  1734. static void en_dis_err_alarms(struct s2io_nic *nic, u16 mask, int flag)
  1735. {
  1736. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  1737. register u64 gen_int_mask = 0;
  1738. u64 interruptible;
  1739. writeq(DISABLE_ALL_INTRS, &bar0->general_int_mask);
  1740. if (mask & TX_DMA_INTR) {
  1741. gen_int_mask |= TXDMA_INT_M;
  1742. do_s2io_write_bits(TXDMA_TDA_INT | TXDMA_PFC_INT |
  1743. TXDMA_PCC_INT | TXDMA_TTI_INT |
  1744. TXDMA_LSO_INT | TXDMA_TPA_INT |
  1745. TXDMA_SM_INT, flag, &bar0->txdma_int_mask);
  1746. do_s2io_write_bits(PFC_ECC_DB_ERR | PFC_SM_ERR_ALARM |
  1747. PFC_MISC_0_ERR | PFC_MISC_1_ERR |
  1748. PFC_PCIX_ERR | PFC_ECC_SG_ERR, flag,
  1749. &bar0->pfc_err_mask);
  1750. do_s2io_write_bits(TDA_Fn_ECC_DB_ERR | TDA_SM0_ERR_ALARM |
  1751. TDA_SM1_ERR_ALARM | TDA_Fn_ECC_SG_ERR |
  1752. TDA_PCIX_ERR, flag, &bar0->tda_err_mask);
  1753. do_s2io_write_bits(PCC_FB_ECC_DB_ERR | PCC_TXB_ECC_DB_ERR |
  1754. PCC_SM_ERR_ALARM | PCC_WR_ERR_ALARM |
  1755. PCC_N_SERR | PCC_6_COF_OV_ERR |
  1756. PCC_7_COF_OV_ERR | PCC_6_LSO_OV_ERR |
  1757. PCC_7_LSO_OV_ERR | PCC_FB_ECC_SG_ERR |
  1758. PCC_TXB_ECC_SG_ERR, flag, &bar0->pcc_err_mask);
  1759. do_s2io_write_bits(TTI_SM_ERR_ALARM | TTI_ECC_SG_ERR |
  1760. TTI_ECC_DB_ERR, flag, &bar0->tti_err_mask);
  1761. do_s2io_write_bits(LSO6_ABORT | LSO7_ABORT |
  1762. LSO6_SM_ERR_ALARM | LSO7_SM_ERR_ALARM |
  1763. LSO6_SEND_OFLOW | LSO7_SEND_OFLOW,
  1764. flag, &bar0->lso_err_mask);
  1765. do_s2io_write_bits(TPA_SM_ERR_ALARM | TPA_TX_FRM_DROP,
  1766. flag, &bar0->tpa_err_mask);
  1767. do_s2io_write_bits(SM_SM_ERR_ALARM, flag, &bar0->sm_err_mask);
  1768. }
  1769. if (mask & TX_MAC_INTR) {
  1770. gen_int_mask |= TXMAC_INT_M;
  1771. do_s2io_write_bits(MAC_INT_STATUS_TMAC_INT, flag,
  1772. &bar0->mac_int_mask);
  1773. do_s2io_write_bits(TMAC_TX_BUF_OVRN | TMAC_TX_SM_ERR |
  1774. TMAC_ECC_SG_ERR | TMAC_ECC_DB_ERR |
  1775. TMAC_DESC_ECC_SG_ERR | TMAC_DESC_ECC_DB_ERR,
  1776. flag, &bar0->mac_tmac_err_mask);
  1777. }
  1778. if (mask & TX_XGXS_INTR) {
  1779. gen_int_mask |= TXXGXS_INT_M;
  1780. do_s2io_write_bits(XGXS_INT_STATUS_TXGXS, flag,
  1781. &bar0->xgxs_int_mask);
  1782. do_s2io_write_bits(TXGXS_ESTORE_UFLOW | TXGXS_TX_SM_ERR |
  1783. TXGXS_ECC_SG_ERR | TXGXS_ECC_DB_ERR,
  1784. flag, &bar0->xgxs_txgxs_err_mask);
  1785. }
  1786. if (mask & RX_DMA_INTR) {
  1787. gen_int_mask |= RXDMA_INT_M;
  1788. do_s2io_write_bits(RXDMA_INT_RC_INT_M | RXDMA_INT_RPA_INT_M |
  1789. RXDMA_INT_RDA_INT_M | RXDMA_INT_RTI_INT_M,
  1790. flag, &bar0->rxdma_int_mask);
  1791. do_s2io_write_bits(RC_PRCn_ECC_DB_ERR | RC_FTC_ECC_DB_ERR |
  1792. RC_PRCn_SM_ERR_ALARM | RC_FTC_SM_ERR_ALARM |
  1793. RC_PRCn_ECC_SG_ERR | RC_FTC_ECC_SG_ERR |
  1794. RC_RDA_FAIL_WR_Rn, flag, &bar0->rc_err_mask);
  1795. do_s2io_write_bits(PRC_PCI_AB_RD_Rn | PRC_PCI_AB_WR_Rn |
  1796. PRC_PCI_AB_F_WR_Rn | PRC_PCI_DP_RD_Rn |
  1797. PRC_PCI_DP_WR_Rn | PRC_PCI_DP_F_WR_Rn, flag,
  1798. &bar0->prc_pcix_err_mask);
  1799. do_s2io_write_bits(RPA_SM_ERR_ALARM | RPA_CREDIT_ERR |
  1800. RPA_ECC_SG_ERR | RPA_ECC_DB_ERR, flag,
  1801. &bar0->rpa_err_mask);
  1802. do_s2io_write_bits(RDA_RXDn_ECC_DB_ERR | RDA_FRM_ECC_DB_N_AERR |
  1803. RDA_SM1_ERR_ALARM | RDA_SM0_ERR_ALARM |
  1804. RDA_RXD_ECC_DB_SERR | RDA_RXDn_ECC_SG_ERR |
  1805. RDA_FRM_ECC_SG_ERR | RDA_MISC_ERR|RDA_PCIX_ERR,
  1806. flag, &bar0->rda_err_mask);
  1807. do_s2io_write_bits(RTI_SM_ERR_ALARM |
  1808. RTI_ECC_SG_ERR | RTI_ECC_DB_ERR,
  1809. flag, &bar0->rti_err_mask);
  1810. }
  1811. if (mask & RX_MAC_INTR) {
  1812. gen_int_mask |= RXMAC_INT_M;
  1813. do_s2io_write_bits(MAC_INT_STATUS_RMAC_INT, flag,
  1814. &bar0->mac_int_mask);
  1815. interruptible = RMAC_RX_BUFF_OVRN | RMAC_RX_SM_ERR |
  1816. RMAC_UNUSED_INT | RMAC_SINGLE_ECC_ERR |
  1817. RMAC_DOUBLE_ECC_ERR;
  1818. if (s2io_link_fault_indication(nic) == MAC_RMAC_ERR_TIMER)
  1819. interruptible |= RMAC_LINK_STATE_CHANGE_INT;
  1820. do_s2io_write_bits(interruptible,
  1821. flag, &bar0->mac_rmac_err_mask);
  1822. }
  1823. if (mask & RX_XGXS_INTR)
  1824. {
  1825. gen_int_mask |= RXXGXS_INT_M;
  1826. do_s2io_write_bits(XGXS_INT_STATUS_RXGXS, flag,
  1827. &bar0->xgxs_int_mask);
  1828. do_s2io_write_bits(RXGXS_ESTORE_OFLOW | RXGXS_RX_SM_ERR, flag,
  1829. &bar0->xgxs_rxgxs_err_mask);
  1830. }
  1831. if (mask & MC_INTR) {
  1832. gen_int_mask |= MC_INT_M;
  1833. do_s2io_write_bits(MC_INT_MASK_MC_INT, flag, &bar0->mc_int_mask);
  1834. do_s2io_write_bits(MC_ERR_REG_SM_ERR | MC_ERR_REG_ECC_ALL_SNG |
  1835. MC_ERR_REG_ECC_ALL_DBL | PLL_LOCK_N, flag,
  1836. &bar0->mc_err_mask);
  1837. }
  1838. nic->general_int_mask = gen_int_mask;
  1839. /* Remove this line when alarm interrupts are enabled */
  1840. nic->general_int_mask = 0;
  1841. }
  1842. /**
  1843. * en_dis_able_nic_intrs - Enable or Disable the interrupts
  1844. * @nic: device private variable,
  1845. * @mask: A mask indicating which Intr block must be modified and,
  1846. * @flag: A flag indicating whether to enable or disable the Intrs.
  1847. * Description: This function will either disable or enable the interrupts
  1848. * depending on the flag argument. The mask argument can be used to
  1849. * enable/disable any Intr block.
  1850. * Return Value: NONE.
  1851. */
  1852. static void en_dis_able_nic_intrs(struct s2io_nic *nic, u16 mask, int flag)
  1853. {
  1854. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  1855. register u64 temp64 = 0, intr_mask = 0;
  1856. intr_mask = nic->general_int_mask;
  1857. /* Top level interrupt classification */
  1858. /* PIC Interrupts */
  1859. if (mask & TX_PIC_INTR) {
  1860. /* Enable PIC Intrs in the general intr mask register */
  1861. intr_mask |= TXPIC_INT_M;
  1862. if (flag == ENABLE_INTRS) {
  1863. /*
  1864. * If Hercules adapter enable GPIO otherwise
  1865. * disable all PCIX, Flash, MDIO, IIC and GPIO
  1866. * interrupts for now.
  1867. * TODO
  1868. */
  1869. if (s2io_link_fault_indication(nic) ==
  1870. LINK_UP_DOWN_INTERRUPT ) {
  1871. do_s2io_write_bits(PIC_INT_GPIO, flag,
  1872. &bar0->pic_int_mask);
  1873. do_s2io_write_bits(GPIO_INT_MASK_LINK_UP, flag,
  1874. &bar0->gpio_int_mask);
  1875. } else
  1876. writeq(DISABLE_ALL_INTRS, &bar0->pic_int_mask);
  1877. } else if (flag == DISABLE_INTRS) {
  1878. /*
  1879. * Disable PIC Intrs in the general
  1880. * intr mask register
  1881. */
  1882. writeq(DISABLE_ALL_INTRS, &bar0->pic_int_mask);
  1883. }
  1884. }
  1885. /* Tx traffic interrupts */
  1886. if (mask & TX_TRAFFIC_INTR) {
  1887. intr_mask |= TXTRAFFIC_INT_M;
  1888. if (flag == ENABLE_INTRS) {
  1889. /*
  1890. * Enable all the Tx side interrupts
  1891. * writing 0 Enables all 64 TX interrupt levels
  1892. */
  1893. writeq(0x0, &bar0->tx_traffic_mask);
  1894. } else if (flag == DISABLE_INTRS) {
  1895. /*
  1896. * Disable Tx Traffic Intrs in the general intr mask
  1897. * register.
  1898. */
  1899. writeq(DISABLE_ALL_INTRS, &bar0->tx_traffic_mask);
  1900. }
  1901. }
  1902. /* Rx traffic interrupts */
  1903. if (mask & RX_TRAFFIC_INTR) {
  1904. intr_mask |= RXTRAFFIC_INT_M;
  1905. if (flag == ENABLE_INTRS) {
  1906. /* writing 0 Enables all 8 RX interrupt levels */
  1907. writeq(0x0, &bar0->rx_traffic_mask);
  1908. } else if (flag == DISABLE_INTRS) {
  1909. /*
  1910. * Disable Rx Traffic Intrs in the general intr mask
  1911. * register.
  1912. */
  1913. writeq(DISABLE_ALL_INTRS, &bar0->rx_traffic_mask);
  1914. }
  1915. }
  1916. temp64 = readq(&bar0->general_int_mask);
  1917. if (flag == ENABLE_INTRS)
  1918. temp64 &= ~((u64) intr_mask);
  1919. else
  1920. temp64 = DISABLE_ALL_INTRS;
  1921. writeq(temp64, &bar0->general_int_mask);
  1922. nic->general_int_mask = readq(&bar0->general_int_mask);
  1923. }
  1924. /**
  1925. * verify_pcc_quiescent- Checks for PCC quiescent state
  1926. * Return: 1 If PCC is quiescence
  1927. * 0 If PCC is not quiescence
  1928. */
  1929. static int verify_pcc_quiescent(struct s2io_nic *sp, int flag)
  1930. {
  1931. int ret = 0, herc;
  1932. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  1933. u64 val64 = readq(&bar0->adapter_status);
  1934. herc = (sp->device_type == XFRAME_II_DEVICE);
  1935. if (flag == FALSE) {
  1936. if ((!herc && (sp->pdev->revision >= 4)) || herc) {
  1937. if (!(val64 & ADAPTER_STATUS_RMAC_PCC_IDLE))
  1938. ret = 1;
  1939. } else {
  1940. if (!(val64 & ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE))
  1941. ret = 1;
  1942. }
  1943. } else {
  1944. if ((!herc && (sp->pdev->revision >= 4)) || herc) {
  1945. if (((val64 & ADAPTER_STATUS_RMAC_PCC_IDLE) ==
  1946. ADAPTER_STATUS_RMAC_PCC_IDLE))
  1947. ret = 1;
  1948. } else {
  1949. if (((val64 & ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE) ==
  1950. ADAPTER_STATUS_RMAC_PCC_FOUR_IDLE))
  1951. ret = 1;
  1952. }
  1953. }
  1954. return ret;
  1955. }
  1956. /**
  1957. * verify_xena_quiescence - Checks whether the H/W is ready
  1958. * Description: Returns whether the H/W is ready to go or not. Depending
  1959. * on whether adapter enable bit was written or not the comparison
  1960. * differs and the calling function passes the input argument flag to
  1961. * indicate this.
  1962. * Return: 1 If xena is quiescence
  1963. * 0 If Xena is not quiescence
  1964. */
  1965. static int verify_xena_quiescence(struct s2io_nic *sp)
  1966. {
  1967. int mode;
  1968. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  1969. u64 val64 = readq(&bar0->adapter_status);
  1970. mode = s2io_verify_pci_mode(sp);
  1971. if (!(val64 & ADAPTER_STATUS_TDMA_READY)) {
  1972. DBG_PRINT(ERR_DBG, "%s", "TDMA is not ready!");
  1973. return 0;
  1974. }
  1975. if (!(val64 & ADAPTER_STATUS_RDMA_READY)) {
  1976. DBG_PRINT(ERR_DBG, "%s", "RDMA is not ready!");
  1977. return 0;
  1978. }
  1979. if (!(val64 & ADAPTER_STATUS_PFC_READY)) {
  1980. DBG_PRINT(ERR_DBG, "%s", "PFC is not ready!");
  1981. return 0;
  1982. }
  1983. if (!(val64 & ADAPTER_STATUS_TMAC_BUF_EMPTY)) {
  1984. DBG_PRINT(ERR_DBG, "%s", "TMAC BUF is not empty!");
  1985. return 0;
  1986. }
  1987. if (!(val64 & ADAPTER_STATUS_PIC_QUIESCENT)) {
  1988. DBG_PRINT(ERR_DBG, "%s", "PIC is not QUIESCENT!");
  1989. return 0;
  1990. }
  1991. if (!(val64 & ADAPTER_STATUS_MC_DRAM_READY)) {
  1992. DBG_PRINT(ERR_DBG, "%s", "MC_DRAM is not ready!");
  1993. return 0;
  1994. }
  1995. if (!(val64 & ADAPTER_STATUS_MC_QUEUES_READY)) {
  1996. DBG_PRINT(ERR_DBG, "%s", "MC_QUEUES is not ready!");
  1997. return 0;
  1998. }
  1999. if (!(val64 & ADAPTER_STATUS_M_PLL_LOCK)) {
  2000. DBG_PRINT(ERR_DBG, "%s", "M_PLL is not locked!");
  2001. return 0;
  2002. }
  2003. /*
  2004. * In PCI 33 mode, the P_PLL is not used, and therefore,
  2005. * the the P_PLL_LOCK bit in the adapter_status register will
  2006. * not be asserted.
  2007. */
  2008. if (!(val64 & ADAPTER_STATUS_P_PLL_LOCK) &&
  2009. sp->device_type == XFRAME_II_DEVICE && mode !=
  2010. PCI_MODE_PCI_33) {
  2011. DBG_PRINT(ERR_DBG, "%s", "P_PLL is not locked!");
  2012. return 0;
  2013. }
  2014. if (!((val64 & ADAPTER_STATUS_RC_PRC_QUIESCENT) ==
  2015. ADAPTER_STATUS_RC_PRC_QUIESCENT)) {
  2016. DBG_PRINT(ERR_DBG, "%s", "RC_PRC is not QUIESCENT!");
  2017. return 0;
  2018. }
  2019. return 1;
  2020. }
  2021. /**
  2022. * fix_mac_address - Fix for Mac addr problem on Alpha platforms
  2023. * @sp: Pointer to device specifc structure
  2024. * Description :
  2025. * New procedure to clear mac address reading problems on Alpha platforms
  2026. *
  2027. */
  2028. static void fix_mac_address(struct s2io_nic * sp)
  2029. {
  2030. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  2031. u64 val64;
  2032. int i = 0;
  2033. while (fix_mac[i] != END_SIGN) {
  2034. writeq(fix_mac[i++], &bar0->gpio_control);
  2035. udelay(10);
  2036. val64 = readq(&bar0->gpio_control);
  2037. }
  2038. }
  2039. /**
  2040. * start_nic - Turns the device on
  2041. * @nic : device private variable.
  2042. * Description:
  2043. * This function actually turns the device on. Before this function is
  2044. * called,all Registers are configured from their reset states
  2045. * and shared memory is allocated but the NIC is still quiescent. On
  2046. * calling this function, the device interrupts are cleared and the NIC is
  2047. * literally switched on by writing into the adapter control register.
  2048. * Return Value:
  2049. * SUCCESS on success and -1 on failure.
  2050. */
  2051. static int start_nic(struct s2io_nic *nic)
  2052. {
  2053. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  2054. struct net_device *dev = nic->dev;
  2055. register u64 val64 = 0;
  2056. u16 subid, i;
  2057. struct mac_info *mac_control;
  2058. struct config_param *config;
  2059. mac_control = &nic->mac_control;
  2060. config = &nic->config;
  2061. /* PRC Initialization and configuration */
  2062. for (i = 0; i < config->rx_ring_num; i++) {
  2063. writeq((u64) mac_control->rings[i].rx_blocks[0].block_dma_addr,
  2064. &bar0->prc_rxd0_n[i]);
  2065. val64 = readq(&bar0->prc_ctrl_n[i]);
  2066. if (nic->rxd_mode == RXD_MODE_1)
  2067. val64 |= PRC_CTRL_RC_ENABLED;
  2068. else
  2069. val64 |= PRC_CTRL_RC_ENABLED | PRC_CTRL_RING_MODE_3;
  2070. if (nic->device_type == XFRAME_II_DEVICE)
  2071. val64 |= PRC_CTRL_GROUP_READS;
  2072. val64 &= ~PRC_CTRL_RXD_BACKOFF_INTERVAL(0xFFFFFF);
  2073. val64 |= PRC_CTRL_RXD_BACKOFF_INTERVAL(0x1000);
  2074. writeq(val64, &bar0->prc_ctrl_n[i]);
  2075. }
  2076. if (nic->rxd_mode == RXD_MODE_3B) {
  2077. /* Enabling 2 buffer mode by writing into Rx_pa_cfg reg. */
  2078. val64 = readq(&bar0->rx_pa_cfg);
  2079. val64 |= RX_PA_CFG_IGNORE_L2_ERR;
  2080. writeq(val64, &bar0->rx_pa_cfg);
  2081. }
  2082. if (vlan_tag_strip == 0) {
  2083. val64 = readq(&bar0->rx_pa_cfg);
  2084. val64 &= ~RX_PA_CFG_STRIP_VLAN_TAG;
  2085. writeq(val64, &bar0->rx_pa_cfg);
  2086. nic->vlan_strip_flag = 0;
  2087. }
  2088. /*
  2089. * Enabling MC-RLDRAM. After enabling the device, we timeout
  2090. * for around 100ms, which is approximately the time required
  2091. * for the device to be ready for operation.
  2092. */
  2093. val64 = readq(&bar0->mc_rldram_mrs);
  2094. val64 |= MC_RLDRAM_QUEUE_SIZE_ENABLE | MC_RLDRAM_MRS_ENABLE;
  2095. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
  2096. val64 = readq(&bar0->mc_rldram_mrs);
  2097. msleep(100); /* Delay by around 100 ms. */
  2098. /* Enabling ECC Protection. */
  2099. val64 = readq(&bar0->adapter_control);
  2100. val64 &= ~ADAPTER_ECC_EN;
  2101. writeq(val64, &bar0->adapter_control);
  2102. /*
  2103. * Verify if the device is ready to be enabled, if so enable
  2104. * it.
  2105. */
  2106. val64 = readq(&bar0->adapter_status);
  2107. if (!verify_xena_quiescence(nic)) {
  2108. DBG_PRINT(ERR_DBG, "%s: device is not ready, ", dev->name);
  2109. DBG_PRINT(ERR_DBG, "Adapter status reads: 0x%llx\n",
  2110. (unsigned long long) val64);
  2111. return FAILURE;
  2112. }
  2113. /*
  2114. * With some switches, link might be already up at this point.
  2115. * Because of this weird behavior, when we enable laser,
  2116. * we may not get link. We need to handle this. We cannot
  2117. * figure out which switch is misbehaving. So we are forced to
  2118. * make a global change.
  2119. */
  2120. /* Enabling Laser. */
  2121. val64 = readq(&bar0->adapter_control);
  2122. val64 |= ADAPTER_EOI_TX_ON;
  2123. writeq(val64, &bar0->adapter_control);
  2124. if (s2io_link_fault_indication(nic) == MAC_RMAC_ERR_TIMER) {
  2125. /*
  2126. * Dont see link state interrupts initally on some switches,
  2127. * so directly scheduling the link state task here.
  2128. */
  2129. schedule_work(&nic->set_link_task);
  2130. }
  2131. /* SXE-002: Initialize link and activity LED */
  2132. subid = nic->pdev->subsystem_device;
  2133. if (((subid & 0xFF) >= 0x07) &&
  2134. (nic->device_type == XFRAME_I_DEVICE)) {
  2135. val64 = readq(&bar0->gpio_control);
  2136. val64 |= 0x0000800000000000ULL;
  2137. writeq(val64, &bar0->gpio_control);
  2138. val64 = 0x0411040400000000ULL;
  2139. writeq(val64, (void __iomem *)bar0 + 0x2700);
  2140. }
  2141. return SUCCESS;
  2142. }
  2143. /**
  2144. * s2io_txdl_getskb - Get the skb from txdl, unmap and return skb
  2145. */
  2146. static struct sk_buff *s2io_txdl_getskb(struct fifo_info *fifo_data, struct \
  2147. TxD *txdlp, int get_off)
  2148. {
  2149. struct s2io_nic *nic = fifo_data->nic;
  2150. struct sk_buff *skb;
  2151. struct TxD *txds;
  2152. u16 j, frg_cnt;
  2153. txds = txdlp;
  2154. if (txds->Host_Control == (u64)(long)fifo_data->ufo_in_band_v) {
  2155. pci_unmap_single(nic->pdev, (dma_addr_t)
  2156. txds->Buffer_Pointer, sizeof(u64),
  2157. PCI_DMA_TODEVICE);
  2158. txds++;
  2159. }
  2160. skb = (struct sk_buff *) ((unsigned long)
  2161. txds->Host_Control);
  2162. if (!skb) {
  2163. memset(txdlp, 0, (sizeof(struct TxD) * fifo_data->max_txds));
  2164. return NULL;
  2165. }
  2166. pci_unmap_single(nic->pdev, (dma_addr_t)
  2167. txds->Buffer_Pointer,
  2168. skb->len - skb->data_len,
  2169. PCI_DMA_TODEVICE);
  2170. frg_cnt = skb_shinfo(skb)->nr_frags;
  2171. if (frg_cnt) {
  2172. txds++;
  2173. for (j = 0; j < frg_cnt; j++, txds++) {
  2174. skb_frag_t *frag = &skb_shinfo(skb)->frags[j];
  2175. if (!txds->Buffer_Pointer)
  2176. break;
  2177. pci_unmap_page(nic->pdev, (dma_addr_t)
  2178. txds->Buffer_Pointer,
  2179. frag->size, PCI_DMA_TODEVICE);
  2180. }
  2181. }
  2182. memset(txdlp,0, (sizeof(struct TxD) * fifo_data->max_txds));
  2183. return(skb);
  2184. }
  2185. /**
  2186. * free_tx_buffers - Free all queued Tx buffers
  2187. * @nic : device private variable.
  2188. * Description:
  2189. * Free all queued Tx buffers.
  2190. * Return Value: void
  2191. */
  2192. static void free_tx_buffers(struct s2io_nic *nic)
  2193. {
  2194. struct net_device *dev = nic->dev;
  2195. struct sk_buff *skb;
  2196. struct TxD *txdp;
  2197. int i, j;
  2198. struct mac_info *mac_control;
  2199. struct config_param *config;
  2200. int cnt = 0;
  2201. mac_control = &nic->mac_control;
  2202. config = &nic->config;
  2203. for (i = 0; i < config->tx_fifo_num; i++) {
  2204. unsigned long flags;
  2205. spin_lock_irqsave(&mac_control->fifos[i].tx_lock, flags);
  2206. for (j = 0; j < config->tx_cfg[i].fifo_len; j++) {
  2207. txdp = (struct TxD *) \
  2208. mac_control->fifos[i].list_info[j].list_virt_addr;
  2209. skb = s2io_txdl_getskb(&mac_control->fifos[i], txdp, j);
  2210. if (skb) {
  2211. nic->mac_control.stats_info->sw_stat.mem_freed
  2212. += skb->truesize;
  2213. dev_kfree_skb(skb);
  2214. cnt++;
  2215. }
  2216. }
  2217. DBG_PRINT(INTR_DBG,
  2218. "%s:forcibly freeing %d skbs on FIFO%d\n",
  2219. dev->name, cnt, i);
  2220. mac_control->fifos[i].tx_curr_get_info.offset = 0;
  2221. mac_control->fifos[i].tx_curr_put_info.offset = 0;
  2222. spin_unlock_irqrestore(&mac_control->fifos[i].tx_lock, flags);
  2223. }
  2224. }
  2225. /**
  2226. * stop_nic - To stop the nic
  2227. * @nic ; device private variable.
  2228. * Description:
  2229. * This function does exactly the opposite of what the start_nic()
  2230. * function does. This function is called to stop the device.
  2231. * Return Value:
  2232. * void.
  2233. */
  2234. static void stop_nic(struct s2io_nic *nic)
  2235. {
  2236. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  2237. register u64 val64 = 0;
  2238. u16 interruptible;
  2239. struct mac_info *mac_control;
  2240. struct config_param *config;
  2241. mac_control = &nic->mac_control;
  2242. config = &nic->config;
  2243. /* Disable all interrupts */
  2244. en_dis_err_alarms(nic, ENA_ALL_INTRS, DISABLE_INTRS);
  2245. interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR;
  2246. interruptible |= TX_PIC_INTR;
  2247. en_dis_able_nic_intrs(nic, interruptible, DISABLE_INTRS);
  2248. /* Clearing Adapter_En bit of ADAPTER_CONTROL Register */
  2249. val64 = readq(&bar0->adapter_control);
  2250. val64 &= ~(ADAPTER_CNTL_EN);
  2251. writeq(val64, &bar0->adapter_control);
  2252. }
  2253. /**
  2254. * fill_rx_buffers - Allocates the Rx side skbs
  2255. * @ring_info: per ring structure
  2256. * @from_card_up: If this is true, we will map the buffer to get
  2257. * the dma address for buf0 and buf1 to give it to the card.
  2258. * Else we will sync the already mapped buffer to give it to the card.
  2259. * Description:
  2260. * The function allocates Rx side skbs and puts the physical
  2261. * address of these buffers into the RxD buffer pointers, so that the NIC
  2262. * can DMA the received frame into these locations.
  2263. * The NIC supports 3 receive modes, viz
  2264. * 1. single buffer,
  2265. * 2. three buffer and
  2266. * 3. Five buffer modes.
  2267. * Each mode defines how many fragments the received frame will be split
  2268. * up into by the NIC. The frame is split into L3 header, L4 Header,
  2269. * L4 payload in three buffer mode and in 5 buffer mode, L4 payload itself
  2270. * is split into 3 fragments. As of now only single buffer mode is
  2271. * supported.
  2272. * Return Value:
  2273. * SUCCESS on success or an appropriate -ve value on failure.
  2274. */
  2275. static int fill_rx_buffers(struct s2io_nic *nic, struct ring_info *ring,
  2276. int from_card_up)
  2277. {
  2278. struct sk_buff *skb;
  2279. struct RxD_t *rxdp;
  2280. int off, size, block_no, block_no1;
  2281. u32 alloc_tab = 0;
  2282. u32 alloc_cnt;
  2283. u64 tmp;
  2284. struct buffAdd *ba;
  2285. struct RxD_t *first_rxdp = NULL;
  2286. u64 Buffer0_ptr = 0, Buffer1_ptr = 0;
  2287. int rxd_index = 0;
  2288. struct RxD1 *rxdp1;
  2289. struct RxD3 *rxdp3;
  2290. struct swStat *stats = &ring->nic->mac_control.stats_info->sw_stat;
  2291. alloc_cnt = ring->pkt_cnt - ring->rx_bufs_left;
  2292. block_no1 = ring->rx_curr_get_info.block_index;
  2293. while (alloc_tab < alloc_cnt) {
  2294. block_no = ring->rx_curr_put_info.block_index;
  2295. off = ring->rx_curr_put_info.offset;
  2296. rxdp = ring->rx_blocks[block_no].rxds[off].virt_addr;
  2297. rxd_index = off + 1;
  2298. if (block_no)
  2299. rxd_index += (block_no * ring->rxd_count);
  2300. if ((block_no == block_no1) &&
  2301. (off == ring->rx_curr_get_info.offset) &&
  2302. (rxdp->Host_Control)) {
  2303. DBG_PRINT(INTR_DBG, "%s: Get and Put",
  2304. ring->dev->name);
  2305. DBG_PRINT(INTR_DBG, " info equated\n");
  2306. goto end;
  2307. }
  2308. if (off && (off == ring->rxd_count)) {
  2309. ring->rx_curr_put_info.block_index++;
  2310. if (ring->rx_curr_put_info.block_index ==
  2311. ring->block_count)
  2312. ring->rx_curr_put_info.block_index = 0;
  2313. block_no = ring->rx_curr_put_info.block_index;
  2314. off = 0;
  2315. ring->rx_curr_put_info.offset = off;
  2316. rxdp = ring->rx_blocks[block_no].block_virt_addr;
  2317. DBG_PRINT(INTR_DBG, "%s: Next block at: %p\n",
  2318. ring->dev->name, rxdp);
  2319. }
  2320. if ((rxdp->Control_1 & RXD_OWN_XENA) &&
  2321. ((ring->rxd_mode == RXD_MODE_3B) &&
  2322. (rxdp->Control_2 & s2BIT(0)))) {
  2323. ring->rx_curr_put_info.offset = off;
  2324. goto end;
  2325. }
  2326. /* calculate size of skb based on ring mode */
  2327. size = ring->mtu + HEADER_ETHERNET_II_802_3_SIZE +
  2328. HEADER_802_2_SIZE + HEADER_SNAP_SIZE;
  2329. if (ring->rxd_mode == RXD_MODE_1)
  2330. size += NET_IP_ALIGN;
  2331. else
  2332. size = ring->mtu + ALIGN_SIZE + BUF0_LEN + 4;
  2333. /* allocate skb */
  2334. skb = dev_alloc_skb(size);
  2335. if(!skb) {
  2336. DBG_PRINT(INFO_DBG, "%s: Out of ", ring->dev->name);
  2337. DBG_PRINT(INFO_DBG, "memory to allocate SKBs\n");
  2338. if (first_rxdp) {
  2339. wmb();
  2340. first_rxdp->Control_1 |= RXD_OWN_XENA;
  2341. }
  2342. stats->mem_alloc_fail_cnt++;
  2343. return -ENOMEM ;
  2344. }
  2345. stats->mem_allocated += skb->truesize;
  2346. if (ring->rxd_mode == RXD_MODE_1) {
  2347. /* 1 buffer mode - normal operation mode */
  2348. rxdp1 = (struct RxD1*)rxdp;
  2349. memset(rxdp, 0, sizeof(struct RxD1));
  2350. skb_reserve(skb, NET_IP_ALIGN);
  2351. rxdp1->Buffer0_ptr = pci_map_single
  2352. (ring->pdev, skb->data, size - NET_IP_ALIGN,
  2353. PCI_DMA_FROMDEVICE);
  2354. if (pci_dma_mapping_error(nic->pdev,
  2355. rxdp1->Buffer0_ptr))
  2356. goto pci_map_failed;
  2357. rxdp->Control_2 =
  2358. SET_BUFFER0_SIZE_1(size - NET_IP_ALIGN);
  2359. rxdp->Host_Control = (unsigned long) (skb);
  2360. } else if (ring->rxd_mode == RXD_MODE_3B) {
  2361. /*
  2362. * 2 buffer mode -
  2363. * 2 buffer mode provides 128
  2364. * byte aligned receive buffers.
  2365. */
  2366. rxdp3 = (struct RxD3*)rxdp;
  2367. /* save buffer pointers to avoid frequent dma mapping */
  2368. Buffer0_ptr = rxdp3->Buffer0_ptr;
  2369. Buffer1_ptr = rxdp3->Buffer1_ptr;
  2370. memset(rxdp, 0, sizeof(struct RxD3));
  2371. /* restore the buffer pointers for dma sync*/
  2372. rxdp3->Buffer0_ptr = Buffer0_ptr;
  2373. rxdp3->Buffer1_ptr = Buffer1_ptr;
  2374. ba = &ring->ba[block_no][off];
  2375. skb_reserve(skb, BUF0_LEN);
  2376. tmp = (u64)(unsigned long) skb->data;
  2377. tmp += ALIGN_SIZE;
  2378. tmp &= ~ALIGN_SIZE;
  2379. skb->data = (void *) (unsigned long)tmp;
  2380. skb_reset_tail_pointer(skb);
  2381. if (from_card_up) {
  2382. rxdp3->Buffer0_ptr =
  2383. pci_map_single(ring->pdev, ba->ba_0,
  2384. BUF0_LEN, PCI_DMA_FROMDEVICE);
  2385. if (pci_dma_mapping_error(nic->pdev,
  2386. rxdp3->Buffer0_ptr))
  2387. goto pci_map_failed;
  2388. } else
  2389. pci_dma_sync_single_for_device(ring->pdev,
  2390. (dma_addr_t) rxdp3->Buffer0_ptr,
  2391. BUF0_LEN, PCI_DMA_FROMDEVICE);
  2392. rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN);
  2393. if (ring->rxd_mode == RXD_MODE_3B) {
  2394. /* Two buffer mode */
  2395. /*
  2396. * Buffer2 will have L3/L4 header plus
  2397. * L4 payload
  2398. */
  2399. rxdp3->Buffer2_ptr = pci_map_single
  2400. (ring->pdev, skb->data, ring->mtu + 4,
  2401. PCI_DMA_FROMDEVICE);
  2402. if (pci_dma_mapping_error(nic->pdev,
  2403. rxdp3->Buffer2_ptr))
  2404. goto pci_map_failed;
  2405. if (from_card_up) {
  2406. rxdp3->Buffer1_ptr =
  2407. pci_map_single(ring->pdev,
  2408. ba->ba_1, BUF1_LEN,
  2409. PCI_DMA_FROMDEVICE);
  2410. if (pci_dma_mapping_error(nic->pdev,
  2411. rxdp3->Buffer1_ptr)) {
  2412. pci_unmap_single
  2413. (ring->pdev,
  2414. (dma_addr_t)(unsigned long)
  2415. skb->data,
  2416. ring->mtu + 4,
  2417. PCI_DMA_FROMDEVICE);
  2418. goto pci_map_failed;
  2419. }
  2420. }
  2421. rxdp->Control_2 |= SET_BUFFER1_SIZE_3(1);
  2422. rxdp->Control_2 |= SET_BUFFER2_SIZE_3
  2423. (ring->mtu + 4);
  2424. }
  2425. rxdp->Control_2 |= s2BIT(0);
  2426. rxdp->Host_Control = (unsigned long) (skb);
  2427. }
  2428. if (alloc_tab & ((1 << rxsync_frequency) - 1))
  2429. rxdp->Control_1 |= RXD_OWN_XENA;
  2430. off++;
  2431. if (off == (ring->rxd_count + 1))
  2432. off = 0;
  2433. ring->rx_curr_put_info.offset = off;
  2434. rxdp->Control_2 |= SET_RXD_MARKER;
  2435. if (!(alloc_tab & ((1 << rxsync_frequency) - 1))) {
  2436. if (first_rxdp) {
  2437. wmb();
  2438. first_rxdp->Control_1 |= RXD_OWN_XENA;
  2439. }
  2440. first_rxdp = rxdp;
  2441. }
  2442. ring->rx_bufs_left += 1;
  2443. alloc_tab++;
  2444. }
  2445. end:
  2446. /* Transfer ownership of first descriptor to adapter just before
  2447. * exiting. Before that, use memory barrier so that ownership
  2448. * and other fields are seen by adapter correctly.
  2449. */
  2450. if (first_rxdp) {
  2451. wmb();
  2452. first_rxdp->Control_1 |= RXD_OWN_XENA;
  2453. }
  2454. return SUCCESS;
  2455. pci_map_failed:
  2456. stats->pci_map_fail_cnt++;
  2457. stats->mem_freed += skb->truesize;
  2458. dev_kfree_skb_irq(skb);
  2459. return -ENOMEM;
  2460. }
  2461. static void free_rxd_blk(struct s2io_nic *sp, int ring_no, int blk)
  2462. {
  2463. struct net_device *dev = sp->dev;
  2464. int j;
  2465. struct sk_buff *skb;
  2466. struct RxD_t *rxdp;
  2467. struct mac_info *mac_control;
  2468. struct buffAdd *ba;
  2469. struct RxD1 *rxdp1;
  2470. struct RxD3 *rxdp3;
  2471. mac_control = &sp->mac_control;
  2472. for (j = 0 ; j < rxd_count[sp->rxd_mode]; j++) {
  2473. rxdp = mac_control->rings[ring_no].
  2474. rx_blocks[blk].rxds[j].virt_addr;
  2475. skb = (struct sk_buff *)
  2476. ((unsigned long) rxdp->Host_Control);
  2477. if (!skb) {
  2478. continue;
  2479. }
  2480. if (sp->rxd_mode == RXD_MODE_1) {
  2481. rxdp1 = (struct RxD1*)rxdp;
  2482. pci_unmap_single(sp->pdev, (dma_addr_t)
  2483. rxdp1->Buffer0_ptr,
  2484. dev->mtu +
  2485. HEADER_ETHERNET_II_802_3_SIZE
  2486. + HEADER_802_2_SIZE +
  2487. HEADER_SNAP_SIZE,
  2488. PCI_DMA_FROMDEVICE);
  2489. memset(rxdp, 0, sizeof(struct RxD1));
  2490. } else if(sp->rxd_mode == RXD_MODE_3B) {
  2491. rxdp3 = (struct RxD3*)rxdp;
  2492. ba = &mac_control->rings[ring_no].
  2493. ba[blk][j];
  2494. pci_unmap_single(sp->pdev, (dma_addr_t)
  2495. rxdp3->Buffer0_ptr,
  2496. BUF0_LEN,
  2497. PCI_DMA_FROMDEVICE);
  2498. pci_unmap_single(sp->pdev, (dma_addr_t)
  2499. rxdp3->Buffer1_ptr,
  2500. BUF1_LEN,
  2501. PCI_DMA_FROMDEVICE);
  2502. pci_unmap_single(sp->pdev, (dma_addr_t)
  2503. rxdp3->Buffer2_ptr,
  2504. dev->mtu + 4,
  2505. PCI_DMA_FROMDEVICE);
  2506. memset(rxdp, 0, sizeof(struct RxD3));
  2507. }
  2508. sp->mac_control.stats_info->sw_stat.mem_freed += skb->truesize;
  2509. dev_kfree_skb(skb);
  2510. mac_control->rings[ring_no].rx_bufs_left -= 1;
  2511. }
  2512. }
  2513. /**
  2514. * free_rx_buffers - Frees all Rx buffers
  2515. * @sp: device private variable.
  2516. * Description:
  2517. * This function will free all Rx buffers allocated by host.
  2518. * Return Value:
  2519. * NONE.
  2520. */
  2521. static void free_rx_buffers(struct s2io_nic *sp)
  2522. {
  2523. struct net_device *dev = sp->dev;
  2524. int i, blk = 0, buf_cnt = 0;
  2525. struct mac_info *mac_control;
  2526. struct config_param *config;
  2527. mac_control = &sp->mac_control;
  2528. config = &sp->config;
  2529. for (i = 0; i < config->rx_ring_num; i++) {
  2530. for (blk = 0; blk < rx_ring_sz[i]; blk++)
  2531. free_rxd_blk(sp,i,blk);
  2532. mac_control->rings[i].rx_curr_put_info.block_index = 0;
  2533. mac_control->rings[i].rx_curr_get_info.block_index = 0;
  2534. mac_control->rings[i].rx_curr_put_info.offset = 0;
  2535. mac_control->rings[i].rx_curr_get_info.offset = 0;
  2536. mac_control->rings[i].rx_bufs_left = 0;
  2537. DBG_PRINT(INIT_DBG, "%s:Freed 0x%x Rx Buffers on ring%d\n",
  2538. dev->name, buf_cnt, i);
  2539. }
  2540. }
  2541. static int s2io_chk_rx_buffers(struct s2io_nic *nic, struct ring_info *ring)
  2542. {
  2543. if (fill_rx_buffers(nic, ring, 0) == -ENOMEM) {
  2544. DBG_PRINT(INFO_DBG, "%s:Out of memory", ring->dev->name);
  2545. DBG_PRINT(INFO_DBG, " in Rx Intr!!\n");
  2546. }
  2547. return 0;
  2548. }
  2549. /**
  2550. * s2io_poll - Rx interrupt handler for NAPI support
  2551. * @napi : pointer to the napi structure.
  2552. * @budget : The number of packets that were budgeted to be processed
  2553. * during one pass through the 'Poll" function.
  2554. * Description:
  2555. * Comes into picture only if NAPI support has been incorporated. It does
  2556. * the same thing that rx_intr_handler does, but not in a interrupt context
  2557. * also It will process only a given number of packets.
  2558. * Return value:
  2559. * 0 on success and 1 if there are No Rx packets to be processed.
  2560. */
  2561. static int s2io_poll_msix(struct napi_struct *napi, int budget)
  2562. {
  2563. struct ring_info *ring = container_of(napi, struct ring_info, napi);
  2564. struct net_device *dev = ring->dev;
  2565. struct config_param *config;
  2566. struct mac_info *mac_control;
  2567. int pkts_processed = 0;
  2568. u8 __iomem *addr = NULL;
  2569. u8 val8 = 0;
  2570. struct s2io_nic *nic = netdev_priv(dev);
  2571. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  2572. int budget_org = budget;
  2573. config = &nic->config;
  2574. mac_control = &nic->mac_control;
  2575. if (unlikely(!is_s2io_card_up(nic)))
  2576. return 0;
  2577. pkts_processed = rx_intr_handler(ring, budget);
  2578. s2io_chk_rx_buffers(nic, ring);
  2579. if (pkts_processed < budget_org) {
  2580. napi_complete(napi);
  2581. /*Re Enable MSI-Rx Vector*/
  2582. addr = (u8 __iomem *)&bar0->xmsi_mask_reg;
  2583. addr += 7 - ring->ring_no;
  2584. val8 = (ring->ring_no == 0) ? 0x3f : 0xbf;
  2585. writeb(val8, addr);
  2586. val8 = readb(addr);
  2587. }
  2588. return pkts_processed;
  2589. }
  2590. static int s2io_poll_inta(struct napi_struct *napi, int budget)
  2591. {
  2592. struct s2io_nic *nic = container_of(napi, struct s2io_nic, napi);
  2593. struct ring_info *ring;
  2594. struct config_param *config;
  2595. struct mac_info *mac_control;
  2596. int pkts_processed = 0;
  2597. int ring_pkts_processed, i;
  2598. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  2599. int budget_org = budget;
  2600. config = &nic->config;
  2601. mac_control = &nic->mac_control;
  2602. if (unlikely(!is_s2io_card_up(nic)))
  2603. return 0;
  2604. for (i = 0; i < config->rx_ring_num; i++) {
  2605. ring = &mac_control->rings[i];
  2606. ring_pkts_processed = rx_intr_handler(ring, budget);
  2607. s2io_chk_rx_buffers(nic, ring);
  2608. pkts_processed += ring_pkts_processed;
  2609. budget -= ring_pkts_processed;
  2610. if (budget <= 0)
  2611. break;
  2612. }
  2613. if (pkts_processed < budget_org) {
  2614. napi_complete(napi);
  2615. /* Re enable the Rx interrupts for the ring */
  2616. writeq(0, &bar0->rx_traffic_mask);
  2617. readl(&bar0->rx_traffic_mask);
  2618. }
  2619. return pkts_processed;
  2620. }
  2621. #ifdef CONFIG_NET_POLL_CONTROLLER
  2622. /**
  2623. * s2io_netpoll - netpoll event handler entry point
  2624. * @dev : pointer to the device structure.
  2625. * Description:
  2626. * This function will be called by upper layer to check for events on the
  2627. * interface in situations where interrupts are disabled. It is used for
  2628. * specific in-kernel networking tasks, such as remote consoles and kernel
  2629. * debugging over the network (example netdump in RedHat).
  2630. */
  2631. static void s2io_netpoll(struct net_device *dev)
  2632. {
  2633. struct s2io_nic *nic = netdev_priv(dev);
  2634. struct mac_info *mac_control;
  2635. struct config_param *config;
  2636. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  2637. u64 val64 = 0xFFFFFFFFFFFFFFFFULL;
  2638. int i;
  2639. if (pci_channel_offline(nic->pdev))
  2640. return;
  2641. disable_irq(dev->irq);
  2642. mac_control = &nic->mac_control;
  2643. config = &nic->config;
  2644. writeq(val64, &bar0->rx_traffic_int);
  2645. writeq(val64, &bar0->tx_traffic_int);
  2646. /* we need to free up the transmitted skbufs or else netpoll will
  2647. * run out of skbs and will fail and eventually netpoll application such
  2648. * as netdump will fail.
  2649. */
  2650. for (i = 0; i < config->tx_fifo_num; i++)
  2651. tx_intr_handler(&mac_control->fifos[i]);
  2652. /* check for received packet and indicate up to network */
  2653. for (i = 0; i < config->rx_ring_num; i++)
  2654. rx_intr_handler(&mac_control->rings[i], 0);
  2655. for (i = 0; i < config->rx_ring_num; i++) {
  2656. if (fill_rx_buffers(nic, &mac_control->rings[i], 0) ==
  2657. -ENOMEM) {
  2658. DBG_PRINT(INFO_DBG, "%s:Out of memory", dev->name);
  2659. DBG_PRINT(INFO_DBG, " in Rx Netpoll!!\n");
  2660. break;
  2661. }
  2662. }
  2663. enable_irq(dev->irq);
  2664. return;
  2665. }
  2666. #endif
  2667. /**
  2668. * rx_intr_handler - Rx interrupt handler
  2669. * @ring_info: per ring structure.
  2670. * @budget: budget for napi processing.
  2671. * Description:
  2672. * If the interrupt is because of a received frame or if the
  2673. * receive ring contains fresh as yet un-processed frames,this function is
  2674. * called. It picks out the RxD at which place the last Rx processing had
  2675. * stopped and sends the skb to the OSM's Rx handler and then increments
  2676. * the offset.
  2677. * Return Value:
  2678. * No. of napi packets processed.
  2679. */
  2680. static int rx_intr_handler(struct ring_info *ring_data, int budget)
  2681. {
  2682. int get_block, put_block;
  2683. struct rx_curr_get_info get_info, put_info;
  2684. struct RxD_t *rxdp;
  2685. struct sk_buff *skb;
  2686. int pkt_cnt = 0, napi_pkts = 0;
  2687. int i;
  2688. struct RxD1* rxdp1;
  2689. struct RxD3* rxdp3;
  2690. get_info = ring_data->rx_curr_get_info;
  2691. get_block = get_info.block_index;
  2692. memcpy(&put_info, &ring_data->rx_curr_put_info, sizeof(put_info));
  2693. put_block = put_info.block_index;
  2694. rxdp = ring_data->rx_blocks[get_block].rxds[get_info.offset].virt_addr;
  2695. while (RXD_IS_UP2DT(rxdp)) {
  2696. /*
  2697. * If your are next to put index then it's
  2698. * FIFO full condition
  2699. */
  2700. if ((get_block == put_block) &&
  2701. (get_info.offset + 1) == put_info.offset) {
  2702. DBG_PRINT(INTR_DBG, "%s: Ring Full\n",
  2703. ring_data->dev->name);
  2704. break;
  2705. }
  2706. skb = (struct sk_buff *) ((unsigned long)rxdp->Host_Control);
  2707. if (skb == NULL) {
  2708. DBG_PRINT(ERR_DBG, "%s: The skb is ",
  2709. ring_data->dev->name);
  2710. DBG_PRINT(ERR_DBG, "Null in Rx Intr\n");
  2711. return 0;
  2712. }
  2713. if (ring_data->rxd_mode == RXD_MODE_1) {
  2714. rxdp1 = (struct RxD1*)rxdp;
  2715. pci_unmap_single(ring_data->pdev, (dma_addr_t)
  2716. rxdp1->Buffer0_ptr,
  2717. ring_data->mtu +
  2718. HEADER_ETHERNET_II_802_3_SIZE +
  2719. HEADER_802_2_SIZE +
  2720. HEADER_SNAP_SIZE,
  2721. PCI_DMA_FROMDEVICE);
  2722. } else if (ring_data->rxd_mode == RXD_MODE_3B) {
  2723. rxdp3 = (struct RxD3*)rxdp;
  2724. pci_dma_sync_single_for_cpu(ring_data->pdev, (dma_addr_t)
  2725. rxdp3->Buffer0_ptr,
  2726. BUF0_LEN, PCI_DMA_FROMDEVICE);
  2727. pci_unmap_single(ring_data->pdev, (dma_addr_t)
  2728. rxdp3->Buffer2_ptr,
  2729. ring_data->mtu + 4,
  2730. PCI_DMA_FROMDEVICE);
  2731. }
  2732. prefetch(skb->data);
  2733. rx_osm_handler(ring_data, rxdp);
  2734. get_info.offset++;
  2735. ring_data->rx_curr_get_info.offset = get_info.offset;
  2736. rxdp = ring_data->rx_blocks[get_block].
  2737. rxds[get_info.offset].virt_addr;
  2738. if (get_info.offset == rxd_count[ring_data->rxd_mode]) {
  2739. get_info.offset = 0;
  2740. ring_data->rx_curr_get_info.offset = get_info.offset;
  2741. get_block++;
  2742. if (get_block == ring_data->block_count)
  2743. get_block = 0;
  2744. ring_data->rx_curr_get_info.block_index = get_block;
  2745. rxdp = ring_data->rx_blocks[get_block].block_virt_addr;
  2746. }
  2747. if (ring_data->nic->config.napi) {
  2748. budget--;
  2749. napi_pkts++;
  2750. if (!budget)
  2751. break;
  2752. }
  2753. pkt_cnt++;
  2754. if ((indicate_max_pkts) && (pkt_cnt > indicate_max_pkts))
  2755. break;
  2756. }
  2757. if (ring_data->lro) {
  2758. /* Clear all LRO sessions before exiting */
  2759. for (i=0; i<MAX_LRO_SESSIONS; i++) {
  2760. struct lro *lro = &ring_data->lro0_n[i];
  2761. if (lro->in_use) {
  2762. update_L3L4_header(ring_data->nic, lro);
  2763. queue_rx_frame(lro->parent, lro->vlan_tag);
  2764. clear_lro_session(lro);
  2765. }
  2766. }
  2767. }
  2768. return(napi_pkts);
  2769. }
  2770. /**
  2771. * tx_intr_handler - Transmit interrupt handler
  2772. * @nic : device private variable
  2773. * Description:
  2774. * If an interrupt was raised to indicate DMA complete of the
  2775. * Tx packet, this function is called. It identifies the last TxD
  2776. * whose buffer was freed and frees all skbs whose data have already
  2777. * DMA'ed into the NICs internal memory.
  2778. * Return Value:
  2779. * NONE
  2780. */
  2781. static void tx_intr_handler(struct fifo_info *fifo_data)
  2782. {
  2783. struct s2io_nic *nic = fifo_data->nic;
  2784. struct tx_curr_get_info get_info, put_info;
  2785. struct sk_buff *skb = NULL;
  2786. struct TxD *txdlp;
  2787. int pkt_cnt = 0;
  2788. unsigned long flags = 0;
  2789. u8 err_mask;
  2790. if (!spin_trylock_irqsave(&fifo_data->tx_lock, flags))
  2791. return;
  2792. get_info = fifo_data->tx_curr_get_info;
  2793. memcpy(&put_info, &fifo_data->tx_curr_put_info, sizeof(put_info));
  2794. txdlp = (struct TxD *) fifo_data->list_info[get_info.offset].
  2795. list_virt_addr;
  2796. while ((!(txdlp->Control_1 & TXD_LIST_OWN_XENA)) &&
  2797. (get_info.offset != put_info.offset) &&
  2798. (txdlp->Host_Control)) {
  2799. /* Check for TxD errors */
  2800. if (txdlp->Control_1 & TXD_T_CODE) {
  2801. unsigned long long err;
  2802. err = txdlp->Control_1 & TXD_T_CODE;
  2803. if (err & 0x1) {
  2804. nic->mac_control.stats_info->sw_stat.
  2805. parity_err_cnt++;
  2806. }
  2807. /* update t_code statistics */
  2808. err_mask = err >> 48;
  2809. switch(err_mask) {
  2810. case 2:
  2811. nic->mac_control.stats_info->sw_stat.
  2812. tx_buf_abort_cnt++;
  2813. break;
  2814. case 3:
  2815. nic->mac_control.stats_info->sw_stat.
  2816. tx_desc_abort_cnt++;
  2817. break;
  2818. case 7:
  2819. nic->mac_control.stats_info->sw_stat.
  2820. tx_parity_err_cnt++;
  2821. break;
  2822. case 10:
  2823. nic->mac_control.stats_info->sw_stat.
  2824. tx_link_loss_cnt++;
  2825. break;
  2826. case 15:
  2827. nic->mac_control.stats_info->sw_stat.
  2828. tx_list_proc_err_cnt++;
  2829. break;
  2830. }
  2831. }
  2832. skb = s2io_txdl_getskb(fifo_data, txdlp, get_info.offset);
  2833. if (skb == NULL) {
  2834. spin_unlock_irqrestore(&fifo_data->tx_lock, flags);
  2835. DBG_PRINT(ERR_DBG, "%s: Null skb ",
  2836. __func__);
  2837. DBG_PRINT(ERR_DBG, "in Tx Free Intr\n");
  2838. return;
  2839. }
  2840. pkt_cnt++;
  2841. /* Updating the statistics block */
  2842. nic->dev->stats.tx_bytes += skb->len;
  2843. nic->mac_control.stats_info->sw_stat.mem_freed += skb->truesize;
  2844. dev_kfree_skb_irq(skb);
  2845. get_info.offset++;
  2846. if (get_info.offset == get_info.fifo_len + 1)
  2847. get_info.offset = 0;
  2848. txdlp = (struct TxD *) fifo_data->list_info
  2849. [get_info.offset].list_virt_addr;
  2850. fifo_data->tx_curr_get_info.offset =
  2851. get_info.offset;
  2852. }
  2853. s2io_wake_tx_queue(fifo_data, pkt_cnt, nic->config.multiq);
  2854. spin_unlock_irqrestore(&fifo_data->tx_lock, flags);
  2855. }
  2856. /**
  2857. * s2io_mdio_write - Function to write in to MDIO registers
  2858. * @mmd_type : MMD type value (PMA/PMD/WIS/PCS/PHYXS)
  2859. * @addr : address value
  2860. * @value : data value
  2861. * @dev : pointer to net_device structure
  2862. * Description:
  2863. * This function is used to write values to the MDIO registers
  2864. * NONE
  2865. */
  2866. static void s2io_mdio_write(u32 mmd_type, u64 addr, u16 value, struct net_device *dev)
  2867. {
  2868. u64 val64 = 0x0;
  2869. struct s2io_nic *sp = netdev_priv(dev);
  2870. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  2871. //address transaction
  2872. val64 = val64 | MDIO_MMD_INDX_ADDR(addr)
  2873. | MDIO_MMD_DEV_ADDR(mmd_type)
  2874. | MDIO_MMS_PRT_ADDR(0x0);
  2875. writeq(val64, &bar0->mdio_control);
  2876. val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
  2877. writeq(val64, &bar0->mdio_control);
  2878. udelay(100);
  2879. //Data transaction
  2880. val64 = 0x0;
  2881. val64 = val64 | MDIO_MMD_INDX_ADDR(addr)
  2882. | MDIO_MMD_DEV_ADDR(mmd_type)
  2883. | MDIO_MMS_PRT_ADDR(0x0)
  2884. | MDIO_MDIO_DATA(value)
  2885. | MDIO_OP(MDIO_OP_WRITE_TRANS);
  2886. writeq(val64, &bar0->mdio_control);
  2887. val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
  2888. writeq(val64, &bar0->mdio_control);
  2889. udelay(100);
  2890. val64 = 0x0;
  2891. val64 = val64 | MDIO_MMD_INDX_ADDR(addr)
  2892. | MDIO_MMD_DEV_ADDR(mmd_type)
  2893. | MDIO_MMS_PRT_ADDR(0x0)
  2894. | MDIO_OP(MDIO_OP_READ_TRANS);
  2895. writeq(val64, &bar0->mdio_control);
  2896. val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
  2897. writeq(val64, &bar0->mdio_control);
  2898. udelay(100);
  2899. }
  2900. /**
  2901. * s2io_mdio_read - Function to write in to MDIO registers
  2902. * @mmd_type : MMD type value (PMA/PMD/WIS/PCS/PHYXS)
  2903. * @addr : address value
  2904. * @dev : pointer to net_device structure
  2905. * Description:
  2906. * This function is used to read values to the MDIO registers
  2907. * NONE
  2908. */
  2909. static u64 s2io_mdio_read(u32 mmd_type, u64 addr, struct net_device *dev)
  2910. {
  2911. u64 val64 = 0x0;
  2912. u64 rval64 = 0x0;
  2913. struct s2io_nic *sp = netdev_priv(dev);
  2914. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  2915. /* address transaction */
  2916. val64 = val64 | MDIO_MMD_INDX_ADDR(addr)
  2917. | MDIO_MMD_DEV_ADDR(mmd_type)
  2918. | MDIO_MMS_PRT_ADDR(0x0);
  2919. writeq(val64, &bar0->mdio_control);
  2920. val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
  2921. writeq(val64, &bar0->mdio_control);
  2922. udelay(100);
  2923. /* Data transaction */
  2924. val64 = 0x0;
  2925. val64 = val64 | MDIO_MMD_INDX_ADDR(addr)
  2926. | MDIO_MMD_DEV_ADDR(mmd_type)
  2927. | MDIO_MMS_PRT_ADDR(0x0)
  2928. | MDIO_OP(MDIO_OP_READ_TRANS);
  2929. writeq(val64, &bar0->mdio_control);
  2930. val64 = val64 | MDIO_CTRL_START_TRANS(0xE);
  2931. writeq(val64, &bar0->mdio_control);
  2932. udelay(100);
  2933. /* Read the value from regs */
  2934. rval64 = readq(&bar0->mdio_control);
  2935. rval64 = rval64 & 0xFFFF0000;
  2936. rval64 = rval64 >> 16;
  2937. return rval64;
  2938. }
  2939. /**
  2940. * s2io_chk_xpak_counter - Function to check the status of the xpak counters
  2941. * @counter : couter value to be updated
  2942. * @flag : flag to indicate the status
  2943. * @type : counter type
  2944. * Description:
  2945. * This function is to check the status of the xpak counters value
  2946. * NONE
  2947. */
  2948. static void s2io_chk_xpak_counter(u64 *counter, u64 * regs_stat, u32 index, u16 flag, u16 type)
  2949. {
  2950. u64 mask = 0x3;
  2951. u64 val64;
  2952. int i;
  2953. for(i = 0; i <index; i++)
  2954. mask = mask << 0x2;
  2955. if(flag > 0)
  2956. {
  2957. *counter = *counter + 1;
  2958. val64 = *regs_stat & mask;
  2959. val64 = val64 >> (index * 0x2);
  2960. val64 = val64 + 1;
  2961. if(val64 == 3)
  2962. {
  2963. switch(type)
  2964. {
  2965. case 1:
  2966. DBG_PRINT(ERR_DBG, "Take Xframe NIC out of "
  2967. "service. Excessive temperatures may "
  2968. "result in premature transceiver "
  2969. "failure \n");
  2970. break;
  2971. case 2:
  2972. DBG_PRINT(ERR_DBG, "Take Xframe NIC out of "
  2973. "service Excessive bias currents may "
  2974. "indicate imminent laser diode "
  2975. "failure \n");
  2976. break;
  2977. case 3:
  2978. DBG_PRINT(ERR_DBG, "Take Xframe NIC out of "
  2979. "service Excessive laser output "
  2980. "power may saturate far-end "
  2981. "receiver\n");
  2982. break;
  2983. default:
  2984. DBG_PRINT(ERR_DBG, "Incorrect XPAK Alarm "
  2985. "type \n");
  2986. }
  2987. val64 = 0x0;
  2988. }
  2989. val64 = val64 << (index * 0x2);
  2990. *regs_stat = (*regs_stat & (~mask)) | (val64);
  2991. } else {
  2992. *regs_stat = *regs_stat & (~mask);
  2993. }
  2994. }
  2995. /**
  2996. * s2io_updt_xpak_counter - Function to update the xpak counters
  2997. * @dev : pointer to net_device struct
  2998. * Description:
  2999. * This function is to upate the status of the xpak counters value
  3000. * NONE
  3001. */
  3002. static void s2io_updt_xpak_counter(struct net_device *dev)
  3003. {
  3004. u16 flag = 0x0;
  3005. u16 type = 0x0;
  3006. u16 val16 = 0x0;
  3007. u64 val64 = 0x0;
  3008. u64 addr = 0x0;
  3009. struct s2io_nic *sp = netdev_priv(dev);
  3010. struct stat_block *stat_info = sp->mac_control.stats_info;
  3011. /* Check the communication with the MDIO slave */
  3012. addr = 0x0000;
  3013. val64 = 0x0;
  3014. val64 = s2io_mdio_read(MDIO_MMD_PMA_DEV_ADDR, addr, dev);
  3015. if((val64 == 0xFFFF) || (val64 == 0x0000))
  3016. {
  3017. DBG_PRINT(ERR_DBG, "ERR: MDIO slave access failed - "
  3018. "Returned %llx\n", (unsigned long long)val64);
  3019. return;
  3020. }
  3021. /* Check for the expecte value of 2040 at PMA address 0x0000 */
  3022. if(val64 != 0x2040)
  3023. {
  3024. DBG_PRINT(ERR_DBG, "Incorrect value at PMA address 0x0000 - ");
  3025. DBG_PRINT(ERR_DBG, "Returned: %llx- Expected: 0x2040\n",
  3026. (unsigned long long)val64);
  3027. return;
  3028. }
  3029. /* Loading the DOM register to MDIO register */
  3030. addr = 0xA100;
  3031. s2io_mdio_write(MDIO_MMD_PMA_DEV_ADDR, addr, val16, dev);
  3032. val64 = s2io_mdio_read(MDIO_MMD_PMA_DEV_ADDR, addr, dev);
  3033. /* Reading the Alarm flags */
  3034. addr = 0xA070;
  3035. val64 = 0x0;
  3036. val64 = s2io_mdio_read(MDIO_MMD_PMA_DEV_ADDR, addr, dev);
  3037. flag = CHECKBIT(val64, 0x7);
  3038. type = 1;
  3039. s2io_chk_xpak_counter(&stat_info->xpak_stat.alarm_transceiver_temp_high,
  3040. &stat_info->xpak_stat.xpak_regs_stat,
  3041. 0x0, flag, type);
  3042. if(CHECKBIT(val64, 0x6))
  3043. stat_info->xpak_stat.alarm_transceiver_temp_low++;
  3044. flag = CHECKBIT(val64, 0x3);
  3045. type = 2;
  3046. s2io_chk_xpak_counter(&stat_info->xpak_stat.alarm_laser_bias_current_high,
  3047. &stat_info->xpak_stat.xpak_regs_stat,
  3048. 0x2, flag, type);
  3049. if(CHECKBIT(val64, 0x2))
  3050. stat_info->xpak_stat.alarm_laser_bias_current_low++;
  3051. flag = CHECKBIT(val64, 0x1);
  3052. type = 3;
  3053. s2io_chk_xpak_counter(&stat_info->xpak_stat.alarm_laser_output_power_high,
  3054. &stat_info->xpak_stat.xpak_regs_stat,
  3055. 0x4, flag, type);
  3056. if(CHECKBIT(val64, 0x0))
  3057. stat_info->xpak_stat.alarm_laser_output_power_low++;
  3058. /* Reading the Warning flags */
  3059. addr = 0xA074;
  3060. val64 = 0x0;
  3061. val64 = s2io_mdio_read(MDIO_MMD_PMA_DEV_ADDR, addr, dev);
  3062. if(CHECKBIT(val64, 0x7))
  3063. stat_info->xpak_stat.warn_transceiver_temp_high++;
  3064. if(CHECKBIT(val64, 0x6))
  3065. stat_info->xpak_stat.warn_transceiver_temp_low++;
  3066. if(CHECKBIT(val64, 0x3))
  3067. stat_info->xpak_stat.warn_laser_bias_current_high++;
  3068. if(CHECKBIT(val64, 0x2))
  3069. stat_info->xpak_stat.warn_laser_bias_current_low++;
  3070. if(CHECKBIT(val64, 0x1))
  3071. stat_info->xpak_stat.warn_laser_output_power_high++;
  3072. if(CHECKBIT(val64, 0x0))
  3073. stat_info->xpak_stat.warn_laser_output_power_low++;
  3074. }
  3075. /**
  3076. * wait_for_cmd_complete - waits for a command to complete.
  3077. * @sp : private member of the device structure, which is a pointer to the
  3078. * s2io_nic structure.
  3079. * Description: Function that waits for a command to Write into RMAC
  3080. * ADDR DATA registers to be completed and returns either success or
  3081. * error depending on whether the command was complete or not.
  3082. * Return value:
  3083. * SUCCESS on success and FAILURE on failure.
  3084. */
  3085. static int wait_for_cmd_complete(void __iomem *addr, u64 busy_bit,
  3086. int bit_state)
  3087. {
  3088. int ret = FAILURE, cnt = 0, delay = 1;
  3089. u64 val64;
  3090. if ((bit_state != S2IO_BIT_RESET) && (bit_state != S2IO_BIT_SET))
  3091. return FAILURE;
  3092. do {
  3093. val64 = readq(addr);
  3094. if (bit_state == S2IO_BIT_RESET) {
  3095. if (!(val64 & busy_bit)) {
  3096. ret = SUCCESS;
  3097. break;
  3098. }
  3099. } else {
  3100. if (!(val64 & busy_bit)) {
  3101. ret = SUCCESS;
  3102. break;
  3103. }
  3104. }
  3105. if(in_interrupt())
  3106. mdelay(delay);
  3107. else
  3108. msleep(delay);
  3109. if (++cnt >= 10)
  3110. delay = 50;
  3111. } while (cnt < 20);
  3112. return ret;
  3113. }
  3114. /*
  3115. * check_pci_device_id - Checks if the device id is supported
  3116. * @id : device id
  3117. * Description: Function to check if the pci device id is supported by driver.
  3118. * Return value: Actual device id if supported else PCI_ANY_ID
  3119. */
  3120. static u16 check_pci_device_id(u16 id)
  3121. {
  3122. switch (id) {
  3123. case PCI_DEVICE_ID_HERC_WIN:
  3124. case PCI_DEVICE_ID_HERC_UNI:
  3125. return XFRAME_II_DEVICE;
  3126. case PCI_DEVICE_ID_S2IO_UNI:
  3127. case PCI_DEVICE_ID_S2IO_WIN:
  3128. return XFRAME_I_DEVICE;
  3129. default:
  3130. return PCI_ANY_ID;
  3131. }
  3132. }
  3133. /**
  3134. * s2io_reset - Resets the card.
  3135. * @sp : private member of the device structure.
  3136. * Description: Function to Reset the card. This function then also
  3137. * restores the previously saved PCI configuration space registers as
  3138. * the card reset also resets the configuration space.
  3139. * Return value:
  3140. * void.
  3141. */
  3142. static void s2io_reset(struct s2io_nic * sp)
  3143. {
  3144. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  3145. u64 val64;
  3146. u16 subid, pci_cmd;
  3147. int i;
  3148. u16 val16;
  3149. unsigned long long up_cnt, down_cnt, up_time, down_time, reset_cnt;
  3150. unsigned long long mem_alloc_cnt, mem_free_cnt, watchdog_cnt;
  3151. DBG_PRINT(INIT_DBG,"%s - Resetting XFrame card %s\n",
  3152. __func__, sp->dev->name);
  3153. /* Back up the PCI-X CMD reg, dont want to lose MMRBC, OST settings */
  3154. pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER, &(pci_cmd));
  3155. val64 = SW_RESET_ALL;
  3156. writeq(val64, &bar0->sw_reset);
  3157. if (strstr(sp->product_name, "CX4")) {
  3158. msleep(750);
  3159. }
  3160. msleep(250);
  3161. for (i = 0; i < S2IO_MAX_PCI_CONFIG_SPACE_REINIT; i++) {
  3162. /* Restore the PCI state saved during initialization. */
  3163. pci_restore_state(sp->pdev);
  3164. pci_read_config_word(sp->pdev, 0x2, &val16);
  3165. if (check_pci_device_id(val16) != (u16)PCI_ANY_ID)
  3166. break;
  3167. msleep(200);
  3168. }
  3169. if (check_pci_device_id(val16) == (u16)PCI_ANY_ID) {
  3170. DBG_PRINT(ERR_DBG,"%s SW_Reset failed!\n", __func__);
  3171. }
  3172. pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER, pci_cmd);
  3173. s2io_init_pci(sp);
  3174. /* Set swapper to enable I/O register access */
  3175. s2io_set_swapper(sp);
  3176. /* restore mac_addr entries */
  3177. do_s2io_restore_unicast_mc(sp);
  3178. /* Restore the MSIX table entries from local variables */
  3179. restore_xmsi_data(sp);
  3180. /* Clear certain PCI/PCI-X fields after reset */
  3181. if (sp->device_type == XFRAME_II_DEVICE) {
  3182. /* Clear "detected parity error" bit */
  3183. pci_write_config_word(sp->pdev, PCI_STATUS, 0x8000);
  3184. /* Clearing PCIX Ecc status register */
  3185. pci_write_config_dword(sp->pdev, 0x68, 0x7C);
  3186. /* Clearing PCI_STATUS error reflected here */
  3187. writeq(s2BIT(62), &bar0->txpic_int_reg);
  3188. }
  3189. /* Reset device statistics maintained by OS */
  3190. memset(&sp->stats, 0, sizeof (struct net_device_stats));
  3191. up_cnt = sp->mac_control.stats_info->sw_stat.link_up_cnt;
  3192. down_cnt = sp->mac_control.stats_info->sw_stat.link_down_cnt;
  3193. up_time = sp->mac_control.stats_info->sw_stat.link_up_time;
  3194. down_time = sp->mac_control.stats_info->sw_stat.link_down_time;
  3195. reset_cnt = sp->mac_control.stats_info->sw_stat.soft_reset_cnt;
  3196. mem_alloc_cnt = sp->mac_control.stats_info->sw_stat.mem_allocated;
  3197. mem_free_cnt = sp->mac_control.stats_info->sw_stat.mem_freed;
  3198. watchdog_cnt = sp->mac_control.stats_info->sw_stat.watchdog_timer_cnt;
  3199. /* save link up/down time/cnt, reset/memory/watchdog cnt */
  3200. memset(sp->mac_control.stats_info, 0, sizeof(struct stat_block));
  3201. /* restore link up/down time/cnt, reset/memory/watchdog cnt */
  3202. sp->mac_control.stats_info->sw_stat.link_up_cnt = up_cnt;
  3203. sp->mac_control.stats_info->sw_stat.link_down_cnt = down_cnt;
  3204. sp->mac_control.stats_info->sw_stat.link_up_time = up_time;
  3205. sp->mac_control.stats_info->sw_stat.link_down_time = down_time;
  3206. sp->mac_control.stats_info->sw_stat.soft_reset_cnt = reset_cnt;
  3207. sp->mac_control.stats_info->sw_stat.mem_allocated = mem_alloc_cnt;
  3208. sp->mac_control.stats_info->sw_stat.mem_freed = mem_free_cnt;
  3209. sp->mac_control.stats_info->sw_stat.watchdog_timer_cnt = watchdog_cnt;
  3210. /* SXE-002: Configure link and activity LED to turn it off */
  3211. subid = sp->pdev->subsystem_device;
  3212. if (((subid & 0xFF) >= 0x07) &&
  3213. (sp->device_type == XFRAME_I_DEVICE)) {
  3214. val64 = readq(&bar0->gpio_control);
  3215. val64 |= 0x0000800000000000ULL;
  3216. writeq(val64, &bar0->gpio_control);
  3217. val64 = 0x0411040400000000ULL;
  3218. writeq(val64, (void __iomem *)bar0 + 0x2700);
  3219. }
  3220. /*
  3221. * Clear spurious ECC interrupts that would have occured on
  3222. * XFRAME II cards after reset.
  3223. */
  3224. if (sp->device_type == XFRAME_II_DEVICE) {
  3225. val64 = readq(&bar0->pcc_err_reg);
  3226. writeq(val64, &bar0->pcc_err_reg);
  3227. }
  3228. sp->device_enabled_once = FALSE;
  3229. }
  3230. /**
  3231. * s2io_set_swapper - to set the swapper controle on the card
  3232. * @sp : private member of the device structure,
  3233. * pointer to the s2io_nic structure.
  3234. * Description: Function to set the swapper control on the card
  3235. * correctly depending on the 'endianness' of the system.
  3236. * Return value:
  3237. * SUCCESS on success and FAILURE on failure.
  3238. */
  3239. static int s2io_set_swapper(struct s2io_nic * sp)
  3240. {
  3241. struct net_device *dev = sp->dev;
  3242. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  3243. u64 val64, valt, valr;
  3244. /*
  3245. * Set proper endian settings and verify the same by reading
  3246. * the PIF Feed-back register.
  3247. */
  3248. val64 = readq(&bar0->pif_rd_swapper_fb);
  3249. if (val64 != 0x0123456789ABCDEFULL) {
  3250. int i = 0;
  3251. u64 value[] = { 0xC30000C3C30000C3ULL, /* FE=1, SE=1 */
  3252. 0x8100008181000081ULL, /* FE=1, SE=0 */
  3253. 0x4200004242000042ULL, /* FE=0, SE=1 */
  3254. 0}; /* FE=0, SE=0 */
  3255. while(i<4) {
  3256. writeq(value[i], &bar0->swapper_ctrl);
  3257. val64 = readq(&bar0->pif_rd_swapper_fb);
  3258. if (val64 == 0x0123456789ABCDEFULL)
  3259. break;
  3260. i++;
  3261. }
  3262. if (i == 4) {
  3263. DBG_PRINT(ERR_DBG, "%s: Endian settings are wrong, ",
  3264. dev->name);
  3265. DBG_PRINT(ERR_DBG, "feedback read %llx\n",
  3266. (unsigned long long) val64);
  3267. return FAILURE;
  3268. }
  3269. valr = value[i];
  3270. } else {
  3271. valr = readq(&bar0->swapper_ctrl);
  3272. }
  3273. valt = 0x0123456789ABCDEFULL;
  3274. writeq(valt, &bar0->xmsi_address);
  3275. val64 = readq(&bar0->xmsi_address);
  3276. if(val64 != valt) {
  3277. int i = 0;
  3278. u64 value[] = { 0x00C3C30000C3C300ULL, /* FE=1, SE=1 */
  3279. 0x0081810000818100ULL, /* FE=1, SE=0 */
  3280. 0x0042420000424200ULL, /* FE=0, SE=1 */
  3281. 0}; /* FE=0, SE=0 */
  3282. while(i<4) {
  3283. writeq((value[i] | valr), &bar0->swapper_ctrl);
  3284. writeq(valt, &bar0->xmsi_address);
  3285. val64 = readq(&bar0->xmsi_address);
  3286. if(val64 == valt)
  3287. break;
  3288. i++;
  3289. }
  3290. if(i == 4) {
  3291. unsigned long long x = val64;
  3292. DBG_PRINT(ERR_DBG, "Write failed, Xmsi_addr ");
  3293. DBG_PRINT(ERR_DBG, "reads:0x%llx\n", x);
  3294. return FAILURE;
  3295. }
  3296. }
  3297. val64 = readq(&bar0->swapper_ctrl);
  3298. val64 &= 0xFFFF000000000000ULL;
  3299. #ifdef __BIG_ENDIAN
  3300. /*
  3301. * The device by default set to a big endian format, so a
  3302. * big endian driver need not set anything.
  3303. */
  3304. val64 |= (SWAPPER_CTRL_TXP_FE |
  3305. SWAPPER_CTRL_TXP_SE |
  3306. SWAPPER_CTRL_TXD_R_FE |
  3307. SWAPPER_CTRL_TXD_W_FE |
  3308. SWAPPER_CTRL_TXF_R_FE |
  3309. SWAPPER_CTRL_RXD_R_FE |
  3310. SWAPPER_CTRL_RXD_W_FE |
  3311. SWAPPER_CTRL_RXF_W_FE |
  3312. SWAPPER_CTRL_XMSI_FE |
  3313. SWAPPER_CTRL_STATS_FE | SWAPPER_CTRL_STATS_SE);
  3314. if (sp->config.intr_type == INTA)
  3315. val64 |= SWAPPER_CTRL_XMSI_SE;
  3316. writeq(val64, &bar0->swapper_ctrl);
  3317. #else
  3318. /*
  3319. * Initially we enable all bits to make it accessible by the
  3320. * driver, then we selectively enable only those bits that
  3321. * we want to set.
  3322. */
  3323. val64 |= (SWAPPER_CTRL_TXP_FE |
  3324. SWAPPER_CTRL_TXP_SE |
  3325. SWAPPER_CTRL_TXD_R_FE |
  3326. SWAPPER_CTRL_TXD_R_SE |
  3327. SWAPPER_CTRL_TXD_W_FE |
  3328. SWAPPER_CTRL_TXD_W_SE |
  3329. SWAPPER_CTRL_TXF_R_FE |
  3330. SWAPPER_CTRL_RXD_R_FE |
  3331. SWAPPER_CTRL_RXD_R_SE |
  3332. SWAPPER_CTRL_RXD_W_FE |
  3333. SWAPPER_CTRL_RXD_W_SE |
  3334. SWAPPER_CTRL_RXF_W_FE |
  3335. SWAPPER_CTRL_XMSI_FE |
  3336. SWAPPER_CTRL_STATS_FE | SWAPPER_CTRL_STATS_SE);
  3337. if (sp->config.intr_type == INTA)
  3338. val64 |= SWAPPER_CTRL_XMSI_SE;
  3339. writeq(val64, &bar0->swapper_ctrl);
  3340. #endif
  3341. val64 = readq(&bar0->swapper_ctrl);
  3342. /*
  3343. * Verifying if endian settings are accurate by reading a
  3344. * feedback register.
  3345. */
  3346. val64 = readq(&bar0->pif_rd_swapper_fb);
  3347. if (val64 != 0x0123456789ABCDEFULL) {
  3348. /* Endian settings are incorrect, calls for another dekko. */
  3349. DBG_PRINT(ERR_DBG, "%s: Endian settings are wrong, ",
  3350. dev->name);
  3351. DBG_PRINT(ERR_DBG, "feedback read %llx\n",
  3352. (unsigned long long) val64);
  3353. return FAILURE;
  3354. }
  3355. return SUCCESS;
  3356. }
  3357. static int wait_for_msix_trans(struct s2io_nic *nic, int i)
  3358. {
  3359. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  3360. u64 val64;
  3361. int ret = 0, cnt = 0;
  3362. do {
  3363. val64 = readq(&bar0->xmsi_access);
  3364. if (!(val64 & s2BIT(15)))
  3365. break;
  3366. mdelay(1);
  3367. cnt++;
  3368. } while(cnt < 5);
  3369. if (cnt == 5) {
  3370. DBG_PRINT(ERR_DBG, "XMSI # %d Access failed\n", i);
  3371. ret = 1;
  3372. }
  3373. return ret;
  3374. }
  3375. static void restore_xmsi_data(struct s2io_nic *nic)
  3376. {
  3377. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  3378. u64 val64;
  3379. int i, msix_index;
  3380. if (nic->device_type == XFRAME_I_DEVICE)
  3381. return;
  3382. for (i=0; i < MAX_REQUESTED_MSI_X; i++) {
  3383. msix_index = (i) ? ((i-1) * 8 + 1): 0;
  3384. writeq(nic->msix_info[i].addr, &bar0->xmsi_address);
  3385. writeq(nic->msix_info[i].data, &bar0->xmsi_data);
  3386. val64 = (s2BIT(7) | s2BIT(15) | vBIT(msix_index, 26, 6));
  3387. writeq(val64, &bar0->xmsi_access);
  3388. if (wait_for_msix_trans(nic, msix_index)) {
  3389. DBG_PRINT(ERR_DBG, "failed in %s\n", __func__);
  3390. continue;
  3391. }
  3392. }
  3393. }
  3394. static void store_xmsi_data(struct s2io_nic *nic)
  3395. {
  3396. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  3397. u64 val64, addr, data;
  3398. int i, msix_index;
  3399. if (nic->device_type == XFRAME_I_DEVICE)
  3400. return;
  3401. /* Store and display */
  3402. for (i=0; i < MAX_REQUESTED_MSI_X; i++) {
  3403. msix_index = (i) ? ((i-1) * 8 + 1): 0;
  3404. val64 = (s2BIT(15) | vBIT(msix_index, 26, 6));
  3405. writeq(val64, &bar0->xmsi_access);
  3406. if (wait_for_msix_trans(nic, msix_index)) {
  3407. DBG_PRINT(ERR_DBG, "failed in %s\n", __func__);
  3408. continue;
  3409. }
  3410. addr = readq(&bar0->xmsi_address);
  3411. data = readq(&bar0->xmsi_data);
  3412. if (addr && data) {
  3413. nic->msix_info[i].addr = addr;
  3414. nic->msix_info[i].data = data;
  3415. }
  3416. }
  3417. }
  3418. static int s2io_enable_msi_x(struct s2io_nic *nic)
  3419. {
  3420. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  3421. u64 rx_mat;
  3422. u16 msi_control; /* Temp variable */
  3423. int ret, i, j, msix_indx = 1;
  3424. nic->entries = kmalloc(nic->num_entries * sizeof(struct msix_entry),
  3425. GFP_KERNEL);
  3426. if (!nic->entries) {
  3427. DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n", \
  3428. __func__);
  3429. nic->mac_control.stats_info->sw_stat.mem_alloc_fail_cnt++;
  3430. return -ENOMEM;
  3431. }
  3432. nic->mac_control.stats_info->sw_stat.mem_allocated
  3433. += (nic->num_entries * sizeof(struct msix_entry));
  3434. memset(nic->entries, 0, nic->num_entries * sizeof(struct msix_entry));
  3435. nic->s2io_entries =
  3436. kmalloc(nic->num_entries * sizeof(struct s2io_msix_entry),
  3437. GFP_KERNEL);
  3438. if (!nic->s2io_entries) {
  3439. DBG_PRINT(INFO_DBG, "%s: Memory allocation failed\n",
  3440. __func__);
  3441. nic->mac_control.stats_info->sw_stat.mem_alloc_fail_cnt++;
  3442. kfree(nic->entries);
  3443. nic->mac_control.stats_info->sw_stat.mem_freed
  3444. += (nic->num_entries * sizeof(struct msix_entry));
  3445. return -ENOMEM;
  3446. }
  3447. nic->mac_control.stats_info->sw_stat.mem_allocated
  3448. += (nic->num_entries * sizeof(struct s2io_msix_entry));
  3449. memset(nic->s2io_entries, 0,
  3450. nic->num_entries * sizeof(struct s2io_msix_entry));
  3451. nic->entries[0].entry = 0;
  3452. nic->s2io_entries[0].entry = 0;
  3453. nic->s2io_entries[0].in_use = MSIX_FLG;
  3454. nic->s2io_entries[0].type = MSIX_ALARM_TYPE;
  3455. nic->s2io_entries[0].arg = &nic->mac_control.fifos;
  3456. for (i = 1; i < nic->num_entries; i++) {
  3457. nic->entries[i].entry = ((i - 1) * 8) + 1;
  3458. nic->s2io_entries[i].entry = ((i - 1) * 8) + 1;
  3459. nic->s2io_entries[i].arg = NULL;
  3460. nic->s2io_entries[i].in_use = 0;
  3461. }
  3462. rx_mat = readq(&bar0->rx_mat);
  3463. for (j = 0; j < nic->config.rx_ring_num; j++) {
  3464. rx_mat |= RX_MAT_SET(j, msix_indx);
  3465. nic->s2io_entries[j+1].arg = &nic->mac_control.rings[j];
  3466. nic->s2io_entries[j+1].type = MSIX_RING_TYPE;
  3467. nic->s2io_entries[j+1].in_use = MSIX_FLG;
  3468. msix_indx += 8;
  3469. }
  3470. writeq(rx_mat, &bar0->rx_mat);
  3471. readq(&bar0->rx_mat);
  3472. ret = pci_enable_msix(nic->pdev, nic->entries, nic->num_entries);
  3473. /* We fail init if error or we get less vectors than min required */
  3474. if (ret) {
  3475. DBG_PRINT(ERR_DBG, "s2io: Enabling MSI-X failed\n");
  3476. kfree(nic->entries);
  3477. nic->mac_control.stats_info->sw_stat.mem_freed
  3478. += (nic->num_entries * sizeof(struct msix_entry));
  3479. kfree(nic->s2io_entries);
  3480. nic->mac_control.stats_info->sw_stat.mem_freed
  3481. += (nic->num_entries * sizeof(struct s2io_msix_entry));
  3482. nic->entries = NULL;
  3483. nic->s2io_entries = NULL;
  3484. return -ENOMEM;
  3485. }
  3486. /*
  3487. * To enable MSI-X, MSI also needs to be enabled, due to a bug
  3488. * in the herc NIC. (Temp change, needs to be removed later)
  3489. */
  3490. pci_read_config_word(nic->pdev, 0x42, &msi_control);
  3491. msi_control |= 0x1; /* Enable MSI */
  3492. pci_write_config_word(nic->pdev, 0x42, msi_control);
  3493. return 0;
  3494. }
  3495. /* Handle software interrupt used during MSI(X) test */
  3496. static irqreturn_t s2io_test_intr(int irq, void *dev_id)
  3497. {
  3498. struct s2io_nic *sp = dev_id;
  3499. sp->msi_detected = 1;
  3500. wake_up(&sp->msi_wait);
  3501. return IRQ_HANDLED;
  3502. }
  3503. /* Test interrupt path by forcing a a software IRQ */
  3504. static int s2io_test_msi(struct s2io_nic *sp)
  3505. {
  3506. struct pci_dev *pdev = sp->pdev;
  3507. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  3508. int err;
  3509. u64 val64, saved64;
  3510. err = request_irq(sp->entries[1].vector, s2io_test_intr, 0,
  3511. sp->name, sp);
  3512. if (err) {
  3513. DBG_PRINT(ERR_DBG, "%s: PCI %s: cannot assign irq %d\n",
  3514. sp->dev->name, pci_name(pdev), pdev->irq);
  3515. return err;
  3516. }
  3517. init_waitqueue_head (&sp->msi_wait);
  3518. sp->msi_detected = 0;
  3519. saved64 = val64 = readq(&bar0->scheduled_int_ctrl);
  3520. val64 |= SCHED_INT_CTRL_ONE_SHOT;
  3521. val64 |= SCHED_INT_CTRL_TIMER_EN;
  3522. val64 |= SCHED_INT_CTRL_INT2MSI(1);
  3523. writeq(val64, &bar0->scheduled_int_ctrl);
  3524. wait_event_timeout(sp->msi_wait, sp->msi_detected, HZ/10);
  3525. if (!sp->msi_detected) {
  3526. /* MSI(X) test failed, go back to INTx mode */
  3527. DBG_PRINT(ERR_DBG, "%s: PCI %s: No interrupt was generated "
  3528. "using MSI(X) during test\n", sp->dev->name,
  3529. pci_name(pdev));
  3530. err = -EOPNOTSUPP;
  3531. }
  3532. free_irq(sp->entries[1].vector, sp);
  3533. writeq(saved64, &bar0->scheduled_int_ctrl);
  3534. return err;
  3535. }
  3536. static void remove_msix_isr(struct s2io_nic *sp)
  3537. {
  3538. int i;
  3539. u16 msi_control;
  3540. for (i = 0; i < sp->num_entries; i++) {
  3541. if (sp->s2io_entries[i].in_use ==
  3542. MSIX_REGISTERED_SUCCESS) {
  3543. int vector = sp->entries[i].vector;
  3544. void *arg = sp->s2io_entries[i].arg;
  3545. free_irq(vector, arg);
  3546. }
  3547. }
  3548. kfree(sp->entries);
  3549. kfree(sp->s2io_entries);
  3550. sp->entries = NULL;
  3551. sp->s2io_entries = NULL;
  3552. pci_read_config_word(sp->pdev, 0x42, &msi_control);
  3553. msi_control &= 0xFFFE; /* Disable MSI */
  3554. pci_write_config_word(sp->pdev, 0x42, msi_control);
  3555. pci_disable_msix(sp->pdev);
  3556. }
  3557. static void remove_inta_isr(struct s2io_nic *sp)
  3558. {
  3559. struct net_device *dev = sp->dev;
  3560. free_irq(sp->pdev->irq, dev);
  3561. }
  3562. /* ********************************************************* *
  3563. * Functions defined below concern the OS part of the driver *
  3564. * ********************************************************* */
  3565. /**
  3566. * s2io_open - open entry point of the driver
  3567. * @dev : pointer to the device structure.
  3568. * Description:
  3569. * This function is the open entry point of the driver. It mainly calls a
  3570. * function to allocate Rx buffers and inserts them into the buffer
  3571. * descriptors and then enables the Rx part of the NIC.
  3572. * Return value:
  3573. * 0 on success and an appropriate (-)ve integer as defined in errno.h
  3574. * file on failure.
  3575. */
  3576. static int s2io_open(struct net_device *dev)
  3577. {
  3578. struct s2io_nic *sp = netdev_priv(dev);
  3579. int err = 0;
  3580. /*
  3581. * Make sure you have link off by default every time
  3582. * Nic is initialized
  3583. */
  3584. netif_carrier_off(dev);
  3585. sp->last_link_state = 0;
  3586. /* Initialize H/W and enable interrupts */
  3587. err = s2io_card_up(sp);
  3588. if (err) {
  3589. DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n",
  3590. dev->name);
  3591. goto hw_init_failed;
  3592. }
  3593. if (do_s2io_prog_unicast(dev, dev->dev_addr) == FAILURE) {
  3594. DBG_PRINT(ERR_DBG, "Set Mac Address Failed\n");
  3595. s2io_card_down(sp);
  3596. err = -ENODEV;
  3597. goto hw_init_failed;
  3598. }
  3599. s2io_start_all_tx_queue(sp);
  3600. return 0;
  3601. hw_init_failed:
  3602. if (sp->config.intr_type == MSI_X) {
  3603. if (sp->entries) {
  3604. kfree(sp->entries);
  3605. sp->mac_control.stats_info->sw_stat.mem_freed
  3606. += (sp->num_entries * sizeof(struct msix_entry));
  3607. }
  3608. if (sp->s2io_entries) {
  3609. kfree(sp->s2io_entries);
  3610. sp->mac_control.stats_info->sw_stat.mem_freed
  3611. += (sp->num_entries * sizeof(struct s2io_msix_entry));
  3612. }
  3613. }
  3614. return err;
  3615. }
  3616. /**
  3617. * s2io_close -close entry point of the driver
  3618. * @dev : device pointer.
  3619. * Description:
  3620. * This is the stop entry point of the driver. It needs to undo exactly
  3621. * whatever was done by the open entry point,thus it's usually referred to
  3622. * as the close function.Among other things this function mainly stops the
  3623. * Rx side of the NIC and frees all the Rx buffers in the Rx rings.
  3624. * Return value:
  3625. * 0 on success and an appropriate (-)ve integer as defined in errno.h
  3626. * file on failure.
  3627. */
  3628. static int s2io_close(struct net_device *dev)
  3629. {
  3630. struct s2io_nic *sp = netdev_priv(dev);
  3631. struct config_param *config = &sp->config;
  3632. u64 tmp64;
  3633. int offset;
  3634. /* Return if the device is already closed *
  3635. * Can happen when s2io_card_up failed in change_mtu *
  3636. */
  3637. if (!is_s2io_card_up(sp))
  3638. return 0;
  3639. s2io_stop_all_tx_queue(sp);
  3640. /* delete all populated mac entries */
  3641. for (offset = 1; offset < config->max_mc_addr; offset++) {
  3642. tmp64 = do_s2io_read_unicast_mc(sp, offset);
  3643. if (tmp64 != S2IO_DISABLE_MAC_ENTRY)
  3644. do_s2io_delete_unicast_mc(sp, tmp64);
  3645. }
  3646. s2io_card_down(sp);
  3647. return 0;
  3648. }
  3649. /**
  3650. * s2io_xmit - Tx entry point of te driver
  3651. * @skb : the socket buffer containing the Tx data.
  3652. * @dev : device pointer.
  3653. * Description :
  3654. * This function is the Tx entry point of the driver. S2IO NIC supports
  3655. * certain protocol assist features on Tx side, namely CSO, S/G, LSO.
  3656. * NOTE: when device cant queue the pkt,just the trans_start variable will
  3657. * not be upadted.
  3658. * Return value:
  3659. * 0 on success & 1 on failure.
  3660. */
  3661. static int s2io_xmit(struct sk_buff *skb, struct net_device *dev)
  3662. {
  3663. struct s2io_nic *sp = netdev_priv(dev);
  3664. u16 frg_cnt, frg_len, i, queue, queue_len, put_off, get_off;
  3665. register u64 val64;
  3666. struct TxD *txdp;
  3667. struct TxFIFO_element __iomem *tx_fifo;
  3668. unsigned long flags = 0;
  3669. u16 vlan_tag = 0;
  3670. struct fifo_info *fifo = NULL;
  3671. struct mac_info *mac_control;
  3672. struct config_param *config;
  3673. int do_spin_lock = 1;
  3674. int offload_type;
  3675. int enable_per_list_interrupt = 0;
  3676. struct swStat *stats = &sp->mac_control.stats_info->sw_stat;
  3677. mac_control = &sp->mac_control;
  3678. config = &sp->config;
  3679. DBG_PRINT(TX_DBG, "%s: In Neterion Tx routine\n", dev->name);
  3680. if (unlikely(skb->len <= 0)) {
  3681. DBG_PRINT(TX_DBG, "%s:Buffer has no data..\n", dev->name);
  3682. dev_kfree_skb_any(skb);
  3683. return 0;
  3684. }
  3685. if (!is_s2io_card_up(sp)) {
  3686. DBG_PRINT(TX_DBG, "%s: Card going down for reset\n",
  3687. dev->name);
  3688. dev_kfree_skb(skb);
  3689. return 0;
  3690. }
  3691. queue = 0;
  3692. if (sp->vlgrp && vlan_tx_tag_present(skb))
  3693. vlan_tag = vlan_tx_tag_get(skb);
  3694. if (sp->config.tx_steering_type == TX_DEFAULT_STEERING) {
  3695. if (skb->protocol == htons(ETH_P_IP)) {
  3696. struct iphdr *ip;
  3697. struct tcphdr *th;
  3698. ip = ip_hdr(skb);
  3699. if ((ip->frag_off & htons(IP_OFFSET|IP_MF)) == 0) {
  3700. th = (struct tcphdr *)(((unsigned char *)ip) +
  3701. ip->ihl*4);
  3702. if (ip->protocol == IPPROTO_TCP) {
  3703. queue_len = sp->total_tcp_fifos;
  3704. queue = (ntohs(th->source) +
  3705. ntohs(th->dest)) &
  3706. sp->fifo_selector[queue_len - 1];
  3707. if (queue >= queue_len)
  3708. queue = queue_len - 1;
  3709. } else if (ip->protocol == IPPROTO_UDP) {
  3710. queue_len = sp->total_udp_fifos;
  3711. queue = (ntohs(th->source) +
  3712. ntohs(th->dest)) &
  3713. sp->fifo_selector[queue_len - 1];
  3714. if (queue >= queue_len)
  3715. queue = queue_len - 1;
  3716. queue += sp->udp_fifo_idx;
  3717. if (skb->len > 1024)
  3718. enable_per_list_interrupt = 1;
  3719. do_spin_lock = 0;
  3720. }
  3721. }
  3722. }
  3723. } else if (sp->config.tx_steering_type == TX_PRIORITY_STEERING)
  3724. /* get fifo number based on skb->priority value */
  3725. queue = config->fifo_mapping
  3726. [skb->priority & (MAX_TX_FIFOS - 1)];
  3727. fifo = &mac_control->fifos[queue];
  3728. if (do_spin_lock)
  3729. spin_lock_irqsave(&fifo->tx_lock, flags);
  3730. else {
  3731. if (unlikely(!spin_trylock_irqsave(&fifo->tx_lock, flags)))
  3732. return NETDEV_TX_LOCKED;
  3733. }
  3734. if (sp->config.multiq) {
  3735. if (__netif_subqueue_stopped(dev, fifo->fifo_no)) {
  3736. spin_unlock_irqrestore(&fifo->tx_lock, flags);
  3737. return NETDEV_TX_BUSY;
  3738. }
  3739. } else if (unlikely(fifo->queue_state == FIFO_QUEUE_STOP)) {
  3740. if (netif_queue_stopped(dev)) {
  3741. spin_unlock_irqrestore(&fifo->tx_lock, flags);
  3742. return NETDEV_TX_BUSY;
  3743. }
  3744. }
  3745. put_off = (u16) fifo->tx_curr_put_info.offset;
  3746. get_off = (u16) fifo->tx_curr_get_info.offset;
  3747. txdp = (struct TxD *) fifo->list_info[put_off].list_virt_addr;
  3748. queue_len = fifo->tx_curr_put_info.fifo_len + 1;
  3749. /* Avoid "put" pointer going beyond "get" pointer */
  3750. if (txdp->Host_Control ||
  3751. ((put_off+1) == queue_len ? 0 : (put_off+1)) == get_off) {
  3752. DBG_PRINT(TX_DBG, "Error in xmit, No free TXDs.\n");
  3753. s2io_stop_tx_queue(sp, fifo->fifo_no);
  3754. dev_kfree_skb(skb);
  3755. spin_unlock_irqrestore(&fifo->tx_lock, flags);
  3756. return 0;
  3757. }
  3758. offload_type = s2io_offload_type(skb);
  3759. if (offload_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) {
  3760. txdp->Control_1 |= TXD_TCP_LSO_EN;
  3761. txdp->Control_1 |= TXD_TCP_LSO_MSS(s2io_tcp_mss(skb));
  3762. }
  3763. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  3764. txdp->Control_2 |=
  3765. (TXD_TX_CKO_IPV4_EN | TXD_TX_CKO_TCP_EN |
  3766. TXD_TX_CKO_UDP_EN);
  3767. }
  3768. txdp->Control_1 |= TXD_GATHER_CODE_FIRST;
  3769. txdp->Control_1 |= TXD_LIST_OWN_XENA;
  3770. txdp->Control_2 |= TXD_INT_NUMBER(fifo->fifo_no);
  3771. if (enable_per_list_interrupt)
  3772. if (put_off & (queue_len >> 5))
  3773. txdp->Control_2 |= TXD_INT_TYPE_PER_LIST;
  3774. if (vlan_tag) {
  3775. txdp->Control_2 |= TXD_VLAN_ENABLE;
  3776. txdp->Control_2 |= TXD_VLAN_TAG(vlan_tag);
  3777. }
  3778. frg_len = skb->len - skb->data_len;
  3779. if (offload_type == SKB_GSO_UDP) {
  3780. int ufo_size;
  3781. ufo_size = s2io_udp_mss(skb);
  3782. ufo_size &= ~7;
  3783. txdp->Control_1 |= TXD_UFO_EN;
  3784. txdp->Control_1 |= TXD_UFO_MSS(ufo_size);
  3785. txdp->Control_1 |= TXD_BUFFER0_SIZE(8);
  3786. #ifdef __BIG_ENDIAN
  3787. /* both variants do cpu_to_be64(be32_to_cpu(...)) */
  3788. fifo->ufo_in_band_v[put_off] =
  3789. (__force u64)skb_shinfo(skb)->ip6_frag_id;
  3790. #else
  3791. fifo->ufo_in_band_v[put_off] =
  3792. (__force u64)skb_shinfo(skb)->ip6_frag_id << 32;
  3793. #endif
  3794. txdp->Host_Control = (unsigned long)fifo->ufo_in_band_v;
  3795. txdp->Buffer_Pointer = pci_map_single(sp->pdev,
  3796. fifo->ufo_in_band_v,
  3797. sizeof(u64), PCI_DMA_TODEVICE);
  3798. if (pci_dma_mapping_error(sp->pdev, txdp->Buffer_Pointer))
  3799. goto pci_map_failed;
  3800. txdp++;
  3801. }
  3802. txdp->Buffer_Pointer = pci_map_single
  3803. (sp->pdev, skb->data, frg_len, PCI_DMA_TODEVICE);
  3804. if (pci_dma_mapping_error(sp->pdev, txdp->Buffer_Pointer))
  3805. goto pci_map_failed;
  3806. txdp->Host_Control = (unsigned long) skb;
  3807. txdp->Control_1 |= TXD_BUFFER0_SIZE(frg_len);
  3808. if (offload_type == SKB_GSO_UDP)
  3809. txdp->Control_1 |= TXD_UFO_EN;
  3810. frg_cnt = skb_shinfo(skb)->nr_frags;
  3811. /* For fragmented SKB. */
  3812. for (i = 0; i < frg_cnt; i++) {
  3813. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  3814. /* A '0' length fragment will be ignored */
  3815. if (!frag->size)
  3816. continue;
  3817. txdp++;
  3818. txdp->Buffer_Pointer = (u64) pci_map_page
  3819. (sp->pdev, frag->page, frag->page_offset,
  3820. frag->size, PCI_DMA_TODEVICE);
  3821. txdp->Control_1 = TXD_BUFFER0_SIZE(frag->size);
  3822. if (offload_type == SKB_GSO_UDP)
  3823. txdp->Control_1 |= TXD_UFO_EN;
  3824. }
  3825. txdp->Control_1 |= TXD_GATHER_CODE_LAST;
  3826. if (offload_type == SKB_GSO_UDP)
  3827. frg_cnt++; /* as Txd0 was used for inband header */
  3828. tx_fifo = mac_control->tx_FIFO_start[queue];
  3829. val64 = fifo->list_info[put_off].list_phy_addr;
  3830. writeq(val64, &tx_fifo->TxDL_Pointer);
  3831. val64 = (TX_FIFO_LAST_TXD_NUM(frg_cnt) | TX_FIFO_FIRST_LIST |
  3832. TX_FIFO_LAST_LIST);
  3833. if (offload_type)
  3834. val64 |= TX_FIFO_SPECIAL_FUNC;
  3835. writeq(val64, &tx_fifo->List_Control);
  3836. mmiowb();
  3837. put_off++;
  3838. if (put_off == fifo->tx_curr_put_info.fifo_len + 1)
  3839. put_off = 0;
  3840. fifo->tx_curr_put_info.offset = put_off;
  3841. /* Avoid "put" pointer going beyond "get" pointer */
  3842. if (((put_off+1) == queue_len ? 0 : (put_off+1)) == get_off) {
  3843. sp->mac_control.stats_info->sw_stat.fifo_full_cnt++;
  3844. DBG_PRINT(TX_DBG,
  3845. "No free TxDs for xmit, Put: 0x%x Get:0x%x\n",
  3846. put_off, get_off);
  3847. s2io_stop_tx_queue(sp, fifo->fifo_no);
  3848. }
  3849. mac_control->stats_info->sw_stat.mem_allocated += skb->truesize;
  3850. dev->trans_start = jiffies;
  3851. spin_unlock_irqrestore(&fifo->tx_lock, flags);
  3852. if (sp->config.intr_type == MSI_X)
  3853. tx_intr_handler(fifo);
  3854. return 0;
  3855. pci_map_failed:
  3856. stats->pci_map_fail_cnt++;
  3857. s2io_stop_tx_queue(sp, fifo->fifo_no);
  3858. stats->mem_freed += skb->truesize;
  3859. dev_kfree_skb(skb);
  3860. spin_unlock_irqrestore(&fifo->tx_lock, flags);
  3861. return 0;
  3862. }
  3863. static void
  3864. s2io_alarm_handle(unsigned long data)
  3865. {
  3866. struct s2io_nic *sp = (struct s2io_nic *)data;
  3867. struct net_device *dev = sp->dev;
  3868. s2io_handle_errors(dev);
  3869. mod_timer(&sp->alarm_timer, jiffies + HZ / 2);
  3870. }
  3871. static irqreturn_t s2io_msix_ring_handle(int irq, void *dev_id)
  3872. {
  3873. struct ring_info *ring = (struct ring_info *)dev_id;
  3874. struct s2io_nic *sp = ring->nic;
  3875. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  3876. if (unlikely(!is_s2io_card_up(sp)))
  3877. return IRQ_HANDLED;
  3878. if (sp->config.napi) {
  3879. u8 __iomem *addr = NULL;
  3880. u8 val8 = 0;
  3881. addr = (u8 __iomem *)&bar0->xmsi_mask_reg;
  3882. addr += (7 - ring->ring_no);
  3883. val8 = (ring->ring_no == 0) ? 0x7f : 0xff;
  3884. writeb(val8, addr);
  3885. val8 = readb(addr);
  3886. napi_schedule(&ring->napi);
  3887. } else {
  3888. rx_intr_handler(ring, 0);
  3889. s2io_chk_rx_buffers(sp, ring);
  3890. }
  3891. return IRQ_HANDLED;
  3892. }
  3893. static irqreturn_t s2io_msix_fifo_handle(int irq, void *dev_id)
  3894. {
  3895. int i;
  3896. struct fifo_info *fifos = (struct fifo_info *)dev_id;
  3897. struct s2io_nic *sp = fifos->nic;
  3898. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  3899. struct config_param *config = &sp->config;
  3900. u64 reason;
  3901. if (unlikely(!is_s2io_card_up(sp)))
  3902. return IRQ_NONE;
  3903. reason = readq(&bar0->general_int_status);
  3904. if (unlikely(reason == S2IO_MINUS_ONE))
  3905. /* Nothing much can be done. Get out */
  3906. return IRQ_HANDLED;
  3907. if (reason & (GEN_INTR_TXPIC | GEN_INTR_TXTRAFFIC)) {
  3908. writeq(S2IO_MINUS_ONE, &bar0->general_int_mask);
  3909. if (reason & GEN_INTR_TXPIC)
  3910. s2io_txpic_intr_handle(sp);
  3911. if (reason & GEN_INTR_TXTRAFFIC)
  3912. writeq(S2IO_MINUS_ONE, &bar0->tx_traffic_int);
  3913. for (i = 0; i < config->tx_fifo_num; i++)
  3914. tx_intr_handler(&fifos[i]);
  3915. writeq(sp->general_int_mask, &bar0->general_int_mask);
  3916. readl(&bar0->general_int_status);
  3917. return IRQ_HANDLED;
  3918. }
  3919. /* The interrupt was not raised by us */
  3920. return IRQ_NONE;
  3921. }
  3922. static void s2io_txpic_intr_handle(struct s2io_nic *sp)
  3923. {
  3924. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  3925. u64 val64;
  3926. val64 = readq(&bar0->pic_int_status);
  3927. if (val64 & PIC_INT_GPIO) {
  3928. val64 = readq(&bar0->gpio_int_reg);
  3929. if ((val64 & GPIO_INT_REG_LINK_DOWN) &&
  3930. (val64 & GPIO_INT_REG_LINK_UP)) {
  3931. /*
  3932. * This is unstable state so clear both up/down
  3933. * interrupt and adapter to re-evaluate the link state.
  3934. */
  3935. val64 |= GPIO_INT_REG_LINK_DOWN;
  3936. val64 |= GPIO_INT_REG_LINK_UP;
  3937. writeq(val64, &bar0->gpio_int_reg);
  3938. val64 = readq(&bar0->gpio_int_mask);
  3939. val64 &= ~(GPIO_INT_MASK_LINK_UP |
  3940. GPIO_INT_MASK_LINK_DOWN);
  3941. writeq(val64, &bar0->gpio_int_mask);
  3942. }
  3943. else if (val64 & GPIO_INT_REG_LINK_UP) {
  3944. val64 = readq(&bar0->adapter_status);
  3945. /* Enable Adapter */
  3946. val64 = readq(&bar0->adapter_control);
  3947. val64 |= ADAPTER_CNTL_EN;
  3948. writeq(val64, &bar0->adapter_control);
  3949. val64 |= ADAPTER_LED_ON;
  3950. writeq(val64, &bar0->adapter_control);
  3951. if (!sp->device_enabled_once)
  3952. sp->device_enabled_once = 1;
  3953. s2io_link(sp, LINK_UP);
  3954. /*
  3955. * unmask link down interrupt and mask link-up
  3956. * intr
  3957. */
  3958. val64 = readq(&bar0->gpio_int_mask);
  3959. val64 &= ~GPIO_INT_MASK_LINK_DOWN;
  3960. val64 |= GPIO_INT_MASK_LINK_UP;
  3961. writeq(val64, &bar0->gpio_int_mask);
  3962. }else if (val64 & GPIO_INT_REG_LINK_DOWN) {
  3963. val64 = readq(&bar0->adapter_status);
  3964. s2io_link(sp, LINK_DOWN);
  3965. /* Link is down so unmaks link up interrupt */
  3966. val64 = readq(&bar0->gpio_int_mask);
  3967. val64 &= ~GPIO_INT_MASK_LINK_UP;
  3968. val64 |= GPIO_INT_MASK_LINK_DOWN;
  3969. writeq(val64, &bar0->gpio_int_mask);
  3970. /* turn off LED */
  3971. val64 = readq(&bar0->adapter_control);
  3972. val64 = val64 &(~ADAPTER_LED_ON);
  3973. writeq(val64, &bar0->adapter_control);
  3974. }
  3975. }
  3976. val64 = readq(&bar0->gpio_int_mask);
  3977. }
  3978. /**
  3979. * do_s2io_chk_alarm_bit - Check for alarm and incrment the counter
  3980. * @value: alarm bits
  3981. * @addr: address value
  3982. * @cnt: counter variable
  3983. * Description: Check for alarm and increment the counter
  3984. * Return Value:
  3985. * 1 - if alarm bit set
  3986. * 0 - if alarm bit is not set
  3987. */
  3988. static int do_s2io_chk_alarm_bit(u64 value, void __iomem * addr,
  3989. unsigned long long *cnt)
  3990. {
  3991. u64 val64;
  3992. val64 = readq(addr);
  3993. if ( val64 & value ) {
  3994. writeq(val64, addr);
  3995. (*cnt)++;
  3996. return 1;
  3997. }
  3998. return 0;
  3999. }
  4000. /**
  4001. * s2io_handle_errors - Xframe error indication handler
  4002. * @nic: device private variable
  4003. * Description: Handle alarms such as loss of link, single or
  4004. * double ECC errors, critical and serious errors.
  4005. * Return Value:
  4006. * NONE
  4007. */
  4008. static void s2io_handle_errors(void * dev_id)
  4009. {
  4010. struct net_device *dev = (struct net_device *) dev_id;
  4011. struct s2io_nic *sp = netdev_priv(dev);
  4012. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4013. u64 temp64 = 0,val64=0;
  4014. int i = 0;
  4015. struct swStat *sw_stat = &sp->mac_control.stats_info->sw_stat;
  4016. struct xpakStat *stats = &sp->mac_control.stats_info->xpak_stat;
  4017. if (!is_s2io_card_up(sp))
  4018. return;
  4019. if (pci_channel_offline(sp->pdev))
  4020. return;
  4021. memset(&sw_stat->ring_full_cnt, 0,
  4022. sizeof(sw_stat->ring_full_cnt));
  4023. /* Handling the XPAK counters update */
  4024. if(stats->xpak_timer_count < 72000) {
  4025. /* waiting for an hour */
  4026. stats->xpak_timer_count++;
  4027. } else {
  4028. s2io_updt_xpak_counter(dev);
  4029. /* reset the count to zero */
  4030. stats->xpak_timer_count = 0;
  4031. }
  4032. /* Handling link status change error Intr */
  4033. if (s2io_link_fault_indication(sp) == MAC_RMAC_ERR_TIMER) {
  4034. val64 = readq(&bar0->mac_rmac_err_reg);
  4035. writeq(val64, &bar0->mac_rmac_err_reg);
  4036. if (val64 & RMAC_LINK_STATE_CHANGE_INT)
  4037. schedule_work(&sp->set_link_task);
  4038. }
  4039. /* In case of a serious error, the device will be Reset. */
  4040. if (do_s2io_chk_alarm_bit(SERR_SOURCE_ANY, &bar0->serr_source,
  4041. &sw_stat->serious_err_cnt))
  4042. goto reset;
  4043. /* Check for data parity error */
  4044. if (do_s2io_chk_alarm_bit(GPIO_INT_REG_DP_ERR_INT, &bar0->gpio_int_reg,
  4045. &sw_stat->parity_err_cnt))
  4046. goto reset;
  4047. /* Check for ring full counter */
  4048. if (sp->device_type == XFRAME_II_DEVICE) {
  4049. val64 = readq(&bar0->ring_bump_counter1);
  4050. for (i=0; i<4; i++) {
  4051. temp64 = ( val64 & vBIT(0xFFFF,(i*16),16));
  4052. temp64 >>= 64 - ((i+1)*16);
  4053. sw_stat->ring_full_cnt[i] += temp64;
  4054. }
  4055. val64 = readq(&bar0->ring_bump_counter2);
  4056. for (i=0; i<4; i++) {
  4057. temp64 = ( val64 & vBIT(0xFFFF,(i*16),16));
  4058. temp64 >>= 64 - ((i+1)*16);
  4059. sw_stat->ring_full_cnt[i+4] += temp64;
  4060. }
  4061. }
  4062. val64 = readq(&bar0->txdma_int_status);
  4063. /*check for pfc_err*/
  4064. if (val64 & TXDMA_PFC_INT) {
  4065. if (do_s2io_chk_alarm_bit(PFC_ECC_DB_ERR | PFC_SM_ERR_ALARM|
  4066. PFC_MISC_0_ERR | PFC_MISC_1_ERR|
  4067. PFC_PCIX_ERR, &bar0->pfc_err_reg,
  4068. &sw_stat->pfc_err_cnt))
  4069. goto reset;
  4070. do_s2io_chk_alarm_bit(PFC_ECC_SG_ERR, &bar0->pfc_err_reg,
  4071. &sw_stat->pfc_err_cnt);
  4072. }
  4073. /*check for tda_err*/
  4074. if (val64 & TXDMA_TDA_INT) {
  4075. if(do_s2io_chk_alarm_bit(TDA_Fn_ECC_DB_ERR | TDA_SM0_ERR_ALARM |
  4076. TDA_SM1_ERR_ALARM, &bar0->tda_err_reg,
  4077. &sw_stat->tda_err_cnt))
  4078. goto reset;
  4079. do_s2io_chk_alarm_bit(TDA_Fn_ECC_SG_ERR | TDA_PCIX_ERR,
  4080. &bar0->tda_err_reg, &sw_stat->tda_err_cnt);
  4081. }
  4082. /*check for pcc_err*/
  4083. if (val64 & TXDMA_PCC_INT) {
  4084. if (do_s2io_chk_alarm_bit(PCC_SM_ERR_ALARM | PCC_WR_ERR_ALARM
  4085. | PCC_N_SERR | PCC_6_COF_OV_ERR
  4086. | PCC_7_COF_OV_ERR | PCC_6_LSO_OV_ERR
  4087. | PCC_7_LSO_OV_ERR | PCC_FB_ECC_DB_ERR
  4088. | PCC_TXB_ECC_DB_ERR, &bar0->pcc_err_reg,
  4089. &sw_stat->pcc_err_cnt))
  4090. goto reset;
  4091. do_s2io_chk_alarm_bit(PCC_FB_ECC_SG_ERR | PCC_TXB_ECC_SG_ERR,
  4092. &bar0->pcc_err_reg, &sw_stat->pcc_err_cnt);
  4093. }
  4094. /*check for tti_err*/
  4095. if (val64 & TXDMA_TTI_INT) {
  4096. if (do_s2io_chk_alarm_bit(TTI_SM_ERR_ALARM, &bar0->tti_err_reg,
  4097. &sw_stat->tti_err_cnt))
  4098. goto reset;
  4099. do_s2io_chk_alarm_bit(TTI_ECC_SG_ERR | TTI_ECC_DB_ERR,
  4100. &bar0->tti_err_reg, &sw_stat->tti_err_cnt);
  4101. }
  4102. /*check for lso_err*/
  4103. if (val64 & TXDMA_LSO_INT) {
  4104. if (do_s2io_chk_alarm_bit(LSO6_ABORT | LSO7_ABORT
  4105. | LSO6_SM_ERR_ALARM | LSO7_SM_ERR_ALARM,
  4106. &bar0->lso_err_reg, &sw_stat->lso_err_cnt))
  4107. goto reset;
  4108. do_s2io_chk_alarm_bit(LSO6_SEND_OFLOW | LSO7_SEND_OFLOW,
  4109. &bar0->lso_err_reg, &sw_stat->lso_err_cnt);
  4110. }
  4111. /*check for tpa_err*/
  4112. if (val64 & TXDMA_TPA_INT) {
  4113. if (do_s2io_chk_alarm_bit(TPA_SM_ERR_ALARM, &bar0->tpa_err_reg,
  4114. &sw_stat->tpa_err_cnt))
  4115. goto reset;
  4116. do_s2io_chk_alarm_bit(TPA_TX_FRM_DROP, &bar0->tpa_err_reg,
  4117. &sw_stat->tpa_err_cnt);
  4118. }
  4119. /*check for sm_err*/
  4120. if (val64 & TXDMA_SM_INT) {
  4121. if (do_s2io_chk_alarm_bit(SM_SM_ERR_ALARM, &bar0->sm_err_reg,
  4122. &sw_stat->sm_err_cnt))
  4123. goto reset;
  4124. }
  4125. val64 = readq(&bar0->mac_int_status);
  4126. if (val64 & MAC_INT_STATUS_TMAC_INT) {
  4127. if (do_s2io_chk_alarm_bit(TMAC_TX_BUF_OVRN | TMAC_TX_SM_ERR,
  4128. &bar0->mac_tmac_err_reg,
  4129. &sw_stat->mac_tmac_err_cnt))
  4130. goto reset;
  4131. do_s2io_chk_alarm_bit(TMAC_ECC_SG_ERR | TMAC_ECC_DB_ERR
  4132. | TMAC_DESC_ECC_SG_ERR | TMAC_DESC_ECC_DB_ERR,
  4133. &bar0->mac_tmac_err_reg,
  4134. &sw_stat->mac_tmac_err_cnt);
  4135. }
  4136. val64 = readq(&bar0->xgxs_int_status);
  4137. if (val64 & XGXS_INT_STATUS_TXGXS) {
  4138. if (do_s2io_chk_alarm_bit(TXGXS_ESTORE_UFLOW | TXGXS_TX_SM_ERR,
  4139. &bar0->xgxs_txgxs_err_reg,
  4140. &sw_stat->xgxs_txgxs_err_cnt))
  4141. goto reset;
  4142. do_s2io_chk_alarm_bit(TXGXS_ECC_SG_ERR | TXGXS_ECC_DB_ERR,
  4143. &bar0->xgxs_txgxs_err_reg,
  4144. &sw_stat->xgxs_txgxs_err_cnt);
  4145. }
  4146. val64 = readq(&bar0->rxdma_int_status);
  4147. if (val64 & RXDMA_INT_RC_INT_M) {
  4148. if (do_s2io_chk_alarm_bit(RC_PRCn_ECC_DB_ERR | RC_FTC_ECC_DB_ERR
  4149. | RC_PRCn_SM_ERR_ALARM |RC_FTC_SM_ERR_ALARM,
  4150. &bar0->rc_err_reg, &sw_stat->rc_err_cnt))
  4151. goto reset;
  4152. do_s2io_chk_alarm_bit(RC_PRCn_ECC_SG_ERR | RC_FTC_ECC_SG_ERR
  4153. | RC_RDA_FAIL_WR_Rn, &bar0->rc_err_reg,
  4154. &sw_stat->rc_err_cnt);
  4155. if (do_s2io_chk_alarm_bit(PRC_PCI_AB_RD_Rn | PRC_PCI_AB_WR_Rn
  4156. | PRC_PCI_AB_F_WR_Rn, &bar0->prc_pcix_err_reg,
  4157. &sw_stat->prc_pcix_err_cnt))
  4158. goto reset;
  4159. do_s2io_chk_alarm_bit(PRC_PCI_DP_RD_Rn | PRC_PCI_DP_WR_Rn
  4160. | PRC_PCI_DP_F_WR_Rn, &bar0->prc_pcix_err_reg,
  4161. &sw_stat->prc_pcix_err_cnt);
  4162. }
  4163. if (val64 & RXDMA_INT_RPA_INT_M) {
  4164. if (do_s2io_chk_alarm_bit(RPA_SM_ERR_ALARM | RPA_CREDIT_ERR,
  4165. &bar0->rpa_err_reg, &sw_stat->rpa_err_cnt))
  4166. goto reset;
  4167. do_s2io_chk_alarm_bit(RPA_ECC_SG_ERR | RPA_ECC_DB_ERR,
  4168. &bar0->rpa_err_reg, &sw_stat->rpa_err_cnt);
  4169. }
  4170. if (val64 & RXDMA_INT_RDA_INT_M) {
  4171. if (do_s2io_chk_alarm_bit(RDA_RXDn_ECC_DB_ERR
  4172. | RDA_FRM_ECC_DB_N_AERR | RDA_SM1_ERR_ALARM
  4173. | RDA_SM0_ERR_ALARM | RDA_RXD_ECC_DB_SERR,
  4174. &bar0->rda_err_reg, &sw_stat->rda_err_cnt))
  4175. goto reset;
  4176. do_s2io_chk_alarm_bit(RDA_RXDn_ECC_SG_ERR | RDA_FRM_ECC_SG_ERR
  4177. | RDA_MISC_ERR | RDA_PCIX_ERR,
  4178. &bar0->rda_err_reg, &sw_stat->rda_err_cnt);
  4179. }
  4180. if (val64 & RXDMA_INT_RTI_INT_M) {
  4181. if (do_s2io_chk_alarm_bit(RTI_SM_ERR_ALARM, &bar0->rti_err_reg,
  4182. &sw_stat->rti_err_cnt))
  4183. goto reset;
  4184. do_s2io_chk_alarm_bit(RTI_ECC_SG_ERR | RTI_ECC_DB_ERR,
  4185. &bar0->rti_err_reg, &sw_stat->rti_err_cnt);
  4186. }
  4187. val64 = readq(&bar0->mac_int_status);
  4188. if (val64 & MAC_INT_STATUS_RMAC_INT) {
  4189. if (do_s2io_chk_alarm_bit(RMAC_RX_BUFF_OVRN | RMAC_RX_SM_ERR,
  4190. &bar0->mac_rmac_err_reg,
  4191. &sw_stat->mac_rmac_err_cnt))
  4192. goto reset;
  4193. do_s2io_chk_alarm_bit(RMAC_UNUSED_INT|RMAC_SINGLE_ECC_ERR|
  4194. RMAC_DOUBLE_ECC_ERR, &bar0->mac_rmac_err_reg,
  4195. &sw_stat->mac_rmac_err_cnt);
  4196. }
  4197. val64 = readq(&bar0->xgxs_int_status);
  4198. if (val64 & XGXS_INT_STATUS_RXGXS) {
  4199. if (do_s2io_chk_alarm_bit(RXGXS_ESTORE_OFLOW | RXGXS_RX_SM_ERR,
  4200. &bar0->xgxs_rxgxs_err_reg,
  4201. &sw_stat->xgxs_rxgxs_err_cnt))
  4202. goto reset;
  4203. }
  4204. val64 = readq(&bar0->mc_int_status);
  4205. if(val64 & MC_INT_STATUS_MC_INT) {
  4206. if (do_s2io_chk_alarm_bit(MC_ERR_REG_SM_ERR, &bar0->mc_err_reg,
  4207. &sw_stat->mc_err_cnt))
  4208. goto reset;
  4209. /* Handling Ecc errors */
  4210. if (val64 & (MC_ERR_REG_ECC_ALL_SNG | MC_ERR_REG_ECC_ALL_DBL)) {
  4211. writeq(val64, &bar0->mc_err_reg);
  4212. if (val64 & MC_ERR_REG_ECC_ALL_DBL) {
  4213. sw_stat->double_ecc_errs++;
  4214. if (sp->device_type != XFRAME_II_DEVICE) {
  4215. /*
  4216. * Reset XframeI only if critical error
  4217. */
  4218. if (val64 &
  4219. (MC_ERR_REG_MIRI_ECC_DB_ERR_0 |
  4220. MC_ERR_REG_MIRI_ECC_DB_ERR_1))
  4221. goto reset;
  4222. }
  4223. } else
  4224. sw_stat->single_ecc_errs++;
  4225. }
  4226. }
  4227. return;
  4228. reset:
  4229. s2io_stop_all_tx_queue(sp);
  4230. schedule_work(&sp->rst_timer_task);
  4231. sw_stat->soft_reset_cnt++;
  4232. return;
  4233. }
  4234. /**
  4235. * s2io_isr - ISR handler of the device .
  4236. * @irq: the irq of the device.
  4237. * @dev_id: a void pointer to the dev structure of the NIC.
  4238. * Description: This function is the ISR handler of the device. It
  4239. * identifies the reason for the interrupt and calls the relevant
  4240. * service routines. As a contongency measure, this ISR allocates the
  4241. * recv buffers, if their numbers are below the panic value which is
  4242. * presently set to 25% of the original number of rcv buffers allocated.
  4243. * Return value:
  4244. * IRQ_HANDLED: will be returned if IRQ was handled by this routine
  4245. * IRQ_NONE: will be returned if interrupt is not from our device
  4246. */
  4247. static irqreturn_t s2io_isr(int irq, void *dev_id)
  4248. {
  4249. struct net_device *dev = (struct net_device *) dev_id;
  4250. struct s2io_nic *sp = netdev_priv(dev);
  4251. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4252. int i;
  4253. u64 reason = 0;
  4254. struct mac_info *mac_control;
  4255. struct config_param *config;
  4256. /* Pretend we handled any irq's from a disconnected card */
  4257. if (pci_channel_offline(sp->pdev))
  4258. return IRQ_NONE;
  4259. if (!is_s2io_card_up(sp))
  4260. return IRQ_NONE;
  4261. mac_control = &sp->mac_control;
  4262. config = &sp->config;
  4263. /*
  4264. * Identify the cause for interrupt and call the appropriate
  4265. * interrupt handler. Causes for the interrupt could be;
  4266. * 1. Rx of packet.
  4267. * 2. Tx complete.
  4268. * 3. Link down.
  4269. */
  4270. reason = readq(&bar0->general_int_status);
  4271. if (unlikely(reason == S2IO_MINUS_ONE) ) {
  4272. /* Nothing much can be done. Get out */
  4273. return IRQ_HANDLED;
  4274. }
  4275. if (reason & (GEN_INTR_RXTRAFFIC |
  4276. GEN_INTR_TXTRAFFIC | GEN_INTR_TXPIC))
  4277. {
  4278. writeq(S2IO_MINUS_ONE, &bar0->general_int_mask);
  4279. if (config->napi) {
  4280. if (reason & GEN_INTR_RXTRAFFIC) {
  4281. napi_schedule(&sp->napi);
  4282. writeq(S2IO_MINUS_ONE, &bar0->rx_traffic_mask);
  4283. writeq(S2IO_MINUS_ONE, &bar0->rx_traffic_int);
  4284. readl(&bar0->rx_traffic_int);
  4285. }
  4286. } else {
  4287. /*
  4288. * rx_traffic_int reg is an R1 register, writing all 1's
  4289. * will ensure that the actual interrupt causing bit
  4290. * get's cleared and hence a read can be avoided.
  4291. */
  4292. if (reason & GEN_INTR_RXTRAFFIC)
  4293. writeq(S2IO_MINUS_ONE, &bar0->rx_traffic_int);
  4294. for (i = 0; i < config->rx_ring_num; i++)
  4295. rx_intr_handler(&mac_control->rings[i], 0);
  4296. }
  4297. /*
  4298. * tx_traffic_int reg is an R1 register, writing all 1's
  4299. * will ensure that the actual interrupt causing bit get's
  4300. * cleared and hence a read can be avoided.
  4301. */
  4302. if (reason & GEN_INTR_TXTRAFFIC)
  4303. writeq(S2IO_MINUS_ONE, &bar0->tx_traffic_int);
  4304. for (i = 0; i < config->tx_fifo_num; i++)
  4305. tx_intr_handler(&mac_control->fifos[i]);
  4306. if (reason & GEN_INTR_TXPIC)
  4307. s2io_txpic_intr_handle(sp);
  4308. /*
  4309. * Reallocate the buffers from the interrupt handler itself.
  4310. */
  4311. if (!config->napi) {
  4312. for (i = 0; i < config->rx_ring_num; i++)
  4313. s2io_chk_rx_buffers(sp, &mac_control->rings[i]);
  4314. }
  4315. writeq(sp->general_int_mask, &bar0->general_int_mask);
  4316. readl(&bar0->general_int_status);
  4317. return IRQ_HANDLED;
  4318. }
  4319. else if (!reason) {
  4320. /* The interrupt was not raised by us */
  4321. return IRQ_NONE;
  4322. }
  4323. return IRQ_HANDLED;
  4324. }
  4325. /**
  4326. * s2io_updt_stats -
  4327. */
  4328. static void s2io_updt_stats(struct s2io_nic *sp)
  4329. {
  4330. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4331. u64 val64;
  4332. int cnt = 0;
  4333. if (is_s2io_card_up(sp)) {
  4334. /* Apprx 30us on a 133 MHz bus */
  4335. val64 = SET_UPDT_CLICKS(10) |
  4336. STAT_CFG_ONE_SHOT_EN | STAT_CFG_STAT_EN;
  4337. writeq(val64, &bar0->stat_cfg);
  4338. do {
  4339. udelay(100);
  4340. val64 = readq(&bar0->stat_cfg);
  4341. if (!(val64 & s2BIT(0)))
  4342. break;
  4343. cnt++;
  4344. if (cnt == 5)
  4345. break; /* Updt failed */
  4346. } while(1);
  4347. }
  4348. }
  4349. /**
  4350. * s2io_get_stats - Updates the device statistics structure.
  4351. * @dev : pointer to the device structure.
  4352. * Description:
  4353. * This function updates the device statistics structure in the s2io_nic
  4354. * structure and returns a pointer to the same.
  4355. * Return value:
  4356. * pointer to the updated net_device_stats structure.
  4357. */
  4358. static struct net_device_stats *s2io_get_stats(struct net_device *dev)
  4359. {
  4360. struct s2io_nic *sp = netdev_priv(dev);
  4361. struct mac_info *mac_control;
  4362. struct config_param *config;
  4363. int i;
  4364. mac_control = &sp->mac_control;
  4365. config = &sp->config;
  4366. /* Configure Stats for immediate updt */
  4367. s2io_updt_stats(sp);
  4368. /* Using sp->stats as a staging area, because reset (due to mtu
  4369. change, for example) will clear some hardware counters */
  4370. dev->stats.tx_packets +=
  4371. le32_to_cpu(mac_control->stats_info->tmac_frms) -
  4372. sp->stats.tx_packets;
  4373. sp->stats.tx_packets =
  4374. le32_to_cpu(mac_control->stats_info->tmac_frms);
  4375. dev->stats.tx_errors +=
  4376. le32_to_cpu(mac_control->stats_info->tmac_any_err_frms) -
  4377. sp->stats.tx_errors;
  4378. sp->stats.tx_errors =
  4379. le32_to_cpu(mac_control->stats_info->tmac_any_err_frms);
  4380. dev->stats.rx_errors +=
  4381. le64_to_cpu(mac_control->stats_info->rmac_drop_frms) -
  4382. sp->stats.rx_errors;
  4383. sp->stats.rx_errors =
  4384. le64_to_cpu(mac_control->stats_info->rmac_drop_frms);
  4385. dev->stats.multicast =
  4386. le32_to_cpu(mac_control->stats_info->rmac_vld_mcst_frms) -
  4387. sp->stats.multicast;
  4388. sp->stats.multicast =
  4389. le32_to_cpu(mac_control->stats_info->rmac_vld_mcst_frms);
  4390. dev->stats.rx_length_errors =
  4391. le64_to_cpu(mac_control->stats_info->rmac_long_frms) -
  4392. sp->stats.rx_length_errors;
  4393. sp->stats.rx_length_errors =
  4394. le64_to_cpu(mac_control->stats_info->rmac_long_frms);
  4395. /* collect per-ring rx_packets and rx_bytes */
  4396. dev->stats.rx_packets = dev->stats.rx_bytes = 0;
  4397. for (i = 0; i < config->rx_ring_num; i++) {
  4398. dev->stats.rx_packets += mac_control->rings[i].rx_packets;
  4399. dev->stats.rx_bytes += mac_control->rings[i].rx_bytes;
  4400. }
  4401. return (&dev->stats);
  4402. }
  4403. /**
  4404. * s2io_set_multicast - entry point for multicast address enable/disable.
  4405. * @dev : pointer to the device structure
  4406. * Description:
  4407. * This function is a driver entry point which gets called by the kernel
  4408. * whenever multicast addresses must be enabled/disabled. This also gets
  4409. * called to set/reset promiscuous mode. Depending on the deivce flag, we
  4410. * determine, if multicast address must be enabled or if promiscuous mode
  4411. * is to be disabled etc.
  4412. * Return value:
  4413. * void.
  4414. */
  4415. static void s2io_set_multicast(struct net_device *dev)
  4416. {
  4417. int i, j, prev_cnt;
  4418. struct dev_mc_list *mclist;
  4419. struct s2io_nic *sp = netdev_priv(dev);
  4420. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4421. u64 val64 = 0, multi_mac = 0x010203040506ULL, mask =
  4422. 0xfeffffffffffULL;
  4423. u64 dis_addr = S2IO_DISABLE_MAC_ENTRY, mac_addr = 0;
  4424. void __iomem *add;
  4425. struct config_param *config = &sp->config;
  4426. if ((dev->flags & IFF_ALLMULTI) && (!sp->m_cast_flg)) {
  4427. /* Enable all Multicast addresses */
  4428. writeq(RMAC_ADDR_DATA0_MEM_ADDR(multi_mac),
  4429. &bar0->rmac_addr_data0_mem);
  4430. writeq(RMAC_ADDR_DATA1_MEM_MASK(mask),
  4431. &bar0->rmac_addr_data1_mem);
  4432. val64 = RMAC_ADDR_CMD_MEM_WE |
  4433. RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  4434. RMAC_ADDR_CMD_MEM_OFFSET(config->max_mc_addr - 1);
  4435. writeq(val64, &bar0->rmac_addr_cmd_mem);
  4436. /* Wait till command completes */
  4437. wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
  4438. RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
  4439. S2IO_BIT_RESET);
  4440. sp->m_cast_flg = 1;
  4441. sp->all_multi_pos = config->max_mc_addr - 1;
  4442. } else if ((dev->flags & IFF_ALLMULTI) && (sp->m_cast_flg)) {
  4443. /* Disable all Multicast addresses */
  4444. writeq(RMAC_ADDR_DATA0_MEM_ADDR(dis_addr),
  4445. &bar0->rmac_addr_data0_mem);
  4446. writeq(RMAC_ADDR_DATA1_MEM_MASK(0x0),
  4447. &bar0->rmac_addr_data1_mem);
  4448. val64 = RMAC_ADDR_CMD_MEM_WE |
  4449. RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  4450. RMAC_ADDR_CMD_MEM_OFFSET(sp->all_multi_pos);
  4451. writeq(val64, &bar0->rmac_addr_cmd_mem);
  4452. /* Wait till command completes */
  4453. wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
  4454. RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
  4455. S2IO_BIT_RESET);
  4456. sp->m_cast_flg = 0;
  4457. sp->all_multi_pos = 0;
  4458. }
  4459. if ((dev->flags & IFF_PROMISC) && (!sp->promisc_flg)) {
  4460. /* Put the NIC into promiscuous mode */
  4461. add = &bar0->mac_cfg;
  4462. val64 = readq(&bar0->mac_cfg);
  4463. val64 |= MAC_CFG_RMAC_PROM_ENABLE;
  4464. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  4465. writel((u32) val64, add);
  4466. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  4467. writel((u32) (val64 >> 32), (add + 4));
  4468. if (vlan_tag_strip != 1) {
  4469. val64 = readq(&bar0->rx_pa_cfg);
  4470. val64 &= ~RX_PA_CFG_STRIP_VLAN_TAG;
  4471. writeq(val64, &bar0->rx_pa_cfg);
  4472. sp->vlan_strip_flag = 0;
  4473. }
  4474. val64 = readq(&bar0->mac_cfg);
  4475. sp->promisc_flg = 1;
  4476. DBG_PRINT(INFO_DBG, "%s: entered promiscuous mode\n",
  4477. dev->name);
  4478. } else if (!(dev->flags & IFF_PROMISC) && (sp->promisc_flg)) {
  4479. /* Remove the NIC from promiscuous mode */
  4480. add = &bar0->mac_cfg;
  4481. val64 = readq(&bar0->mac_cfg);
  4482. val64 &= ~MAC_CFG_RMAC_PROM_ENABLE;
  4483. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  4484. writel((u32) val64, add);
  4485. writeq(RMAC_CFG_KEY(0x4C0D), &bar0->rmac_cfg_key);
  4486. writel((u32) (val64 >> 32), (add + 4));
  4487. if (vlan_tag_strip != 0) {
  4488. val64 = readq(&bar0->rx_pa_cfg);
  4489. val64 |= RX_PA_CFG_STRIP_VLAN_TAG;
  4490. writeq(val64, &bar0->rx_pa_cfg);
  4491. sp->vlan_strip_flag = 1;
  4492. }
  4493. val64 = readq(&bar0->mac_cfg);
  4494. sp->promisc_flg = 0;
  4495. DBG_PRINT(INFO_DBG, "%s: left promiscuous mode\n",
  4496. dev->name);
  4497. }
  4498. /* Update individual M_CAST address list */
  4499. if ((!sp->m_cast_flg) && dev->mc_count) {
  4500. if (dev->mc_count >
  4501. (config->max_mc_addr - config->max_mac_addr)) {
  4502. DBG_PRINT(ERR_DBG, "%s: No more Rx filters ",
  4503. dev->name);
  4504. DBG_PRINT(ERR_DBG, "can be added, please enable ");
  4505. DBG_PRINT(ERR_DBG, "ALL_MULTI instead\n");
  4506. return;
  4507. }
  4508. prev_cnt = sp->mc_addr_count;
  4509. sp->mc_addr_count = dev->mc_count;
  4510. /* Clear out the previous list of Mc in the H/W. */
  4511. for (i = 0; i < prev_cnt; i++) {
  4512. writeq(RMAC_ADDR_DATA0_MEM_ADDR(dis_addr),
  4513. &bar0->rmac_addr_data0_mem);
  4514. writeq(RMAC_ADDR_DATA1_MEM_MASK(0ULL),
  4515. &bar0->rmac_addr_data1_mem);
  4516. val64 = RMAC_ADDR_CMD_MEM_WE |
  4517. RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  4518. RMAC_ADDR_CMD_MEM_OFFSET
  4519. (config->mc_start_offset + i);
  4520. writeq(val64, &bar0->rmac_addr_cmd_mem);
  4521. /* Wait for command completes */
  4522. if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
  4523. RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
  4524. S2IO_BIT_RESET)) {
  4525. DBG_PRINT(ERR_DBG, "%s: Adding ",
  4526. dev->name);
  4527. DBG_PRINT(ERR_DBG, "Multicasts failed\n");
  4528. return;
  4529. }
  4530. }
  4531. /* Create the new Rx filter list and update the same in H/W. */
  4532. for (i = 0, mclist = dev->mc_list; i < dev->mc_count;
  4533. i++, mclist = mclist->next) {
  4534. memcpy(sp->usr_addrs[i].addr, mclist->dmi_addr,
  4535. ETH_ALEN);
  4536. mac_addr = 0;
  4537. for (j = 0; j < ETH_ALEN; j++) {
  4538. mac_addr |= mclist->dmi_addr[j];
  4539. mac_addr <<= 8;
  4540. }
  4541. mac_addr >>= 8;
  4542. writeq(RMAC_ADDR_DATA0_MEM_ADDR(mac_addr),
  4543. &bar0->rmac_addr_data0_mem);
  4544. writeq(RMAC_ADDR_DATA1_MEM_MASK(0ULL),
  4545. &bar0->rmac_addr_data1_mem);
  4546. val64 = RMAC_ADDR_CMD_MEM_WE |
  4547. RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  4548. RMAC_ADDR_CMD_MEM_OFFSET
  4549. (i + config->mc_start_offset);
  4550. writeq(val64, &bar0->rmac_addr_cmd_mem);
  4551. /* Wait for command completes */
  4552. if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
  4553. RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
  4554. S2IO_BIT_RESET)) {
  4555. DBG_PRINT(ERR_DBG, "%s: Adding ",
  4556. dev->name);
  4557. DBG_PRINT(ERR_DBG, "Multicasts failed\n");
  4558. return;
  4559. }
  4560. }
  4561. }
  4562. }
  4563. /* read from CAM unicast & multicast addresses and store it in
  4564. * def_mac_addr structure
  4565. */
  4566. static void do_s2io_store_unicast_mc(struct s2io_nic *sp)
  4567. {
  4568. int offset;
  4569. u64 mac_addr = 0x0;
  4570. struct config_param *config = &sp->config;
  4571. /* store unicast & multicast mac addresses */
  4572. for (offset = 0; offset < config->max_mc_addr; offset++) {
  4573. mac_addr = do_s2io_read_unicast_mc(sp, offset);
  4574. /* if read fails disable the entry */
  4575. if (mac_addr == FAILURE)
  4576. mac_addr = S2IO_DISABLE_MAC_ENTRY;
  4577. do_s2io_copy_mac_addr(sp, offset, mac_addr);
  4578. }
  4579. }
  4580. /* restore unicast & multicast MAC to CAM from def_mac_addr structure */
  4581. static void do_s2io_restore_unicast_mc(struct s2io_nic *sp)
  4582. {
  4583. int offset;
  4584. struct config_param *config = &sp->config;
  4585. /* restore unicast mac address */
  4586. for (offset = 0; offset < config->max_mac_addr; offset++)
  4587. do_s2io_prog_unicast(sp->dev,
  4588. sp->def_mac_addr[offset].mac_addr);
  4589. /* restore multicast mac address */
  4590. for (offset = config->mc_start_offset;
  4591. offset < config->max_mc_addr; offset++)
  4592. do_s2io_add_mc(sp, sp->def_mac_addr[offset].mac_addr);
  4593. }
  4594. /* add a multicast MAC address to CAM */
  4595. static int do_s2io_add_mc(struct s2io_nic *sp, u8 *addr)
  4596. {
  4597. int i;
  4598. u64 mac_addr = 0;
  4599. struct config_param *config = &sp->config;
  4600. for (i = 0; i < ETH_ALEN; i++) {
  4601. mac_addr <<= 8;
  4602. mac_addr |= addr[i];
  4603. }
  4604. if ((0ULL == mac_addr) || (mac_addr == S2IO_DISABLE_MAC_ENTRY))
  4605. return SUCCESS;
  4606. /* check if the multicast mac already preset in CAM */
  4607. for (i = config->mc_start_offset; i < config->max_mc_addr; i++) {
  4608. u64 tmp64;
  4609. tmp64 = do_s2io_read_unicast_mc(sp, i);
  4610. if (tmp64 == S2IO_DISABLE_MAC_ENTRY) /* CAM entry is empty */
  4611. break;
  4612. if (tmp64 == mac_addr)
  4613. return SUCCESS;
  4614. }
  4615. if (i == config->max_mc_addr) {
  4616. DBG_PRINT(ERR_DBG,
  4617. "CAM full no space left for multicast MAC\n");
  4618. return FAILURE;
  4619. }
  4620. /* Update the internal structure with this new mac address */
  4621. do_s2io_copy_mac_addr(sp, i, mac_addr);
  4622. return (do_s2io_add_mac(sp, mac_addr, i));
  4623. }
  4624. /* add MAC address to CAM */
  4625. static int do_s2io_add_mac(struct s2io_nic *sp, u64 addr, int off)
  4626. {
  4627. u64 val64;
  4628. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4629. writeq(RMAC_ADDR_DATA0_MEM_ADDR(addr),
  4630. &bar0->rmac_addr_data0_mem);
  4631. val64 =
  4632. RMAC_ADDR_CMD_MEM_WE | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  4633. RMAC_ADDR_CMD_MEM_OFFSET(off);
  4634. writeq(val64, &bar0->rmac_addr_cmd_mem);
  4635. /* Wait till command completes */
  4636. if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
  4637. RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
  4638. S2IO_BIT_RESET)) {
  4639. DBG_PRINT(INFO_DBG, "do_s2io_add_mac failed\n");
  4640. return FAILURE;
  4641. }
  4642. return SUCCESS;
  4643. }
  4644. /* deletes a specified unicast/multicast mac entry from CAM */
  4645. static int do_s2io_delete_unicast_mc(struct s2io_nic *sp, u64 addr)
  4646. {
  4647. int offset;
  4648. u64 dis_addr = S2IO_DISABLE_MAC_ENTRY, tmp64;
  4649. struct config_param *config = &sp->config;
  4650. for (offset = 1;
  4651. offset < config->max_mc_addr; offset++) {
  4652. tmp64 = do_s2io_read_unicast_mc(sp, offset);
  4653. if (tmp64 == addr) {
  4654. /* disable the entry by writing 0xffffffffffffULL */
  4655. if (do_s2io_add_mac(sp, dis_addr, offset) == FAILURE)
  4656. return FAILURE;
  4657. /* store the new mac list from CAM */
  4658. do_s2io_store_unicast_mc(sp);
  4659. return SUCCESS;
  4660. }
  4661. }
  4662. DBG_PRINT(ERR_DBG, "MAC address 0x%llx not found in CAM\n",
  4663. (unsigned long long)addr);
  4664. return FAILURE;
  4665. }
  4666. /* read mac entries from CAM */
  4667. static u64 do_s2io_read_unicast_mc(struct s2io_nic *sp, int offset)
  4668. {
  4669. u64 tmp64 = 0xffffffffffff0000ULL, val64;
  4670. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4671. /* read mac addr */
  4672. val64 =
  4673. RMAC_ADDR_CMD_MEM_RD | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  4674. RMAC_ADDR_CMD_MEM_OFFSET(offset);
  4675. writeq(val64, &bar0->rmac_addr_cmd_mem);
  4676. /* Wait till command completes */
  4677. if (wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
  4678. RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING,
  4679. S2IO_BIT_RESET)) {
  4680. DBG_PRINT(INFO_DBG, "do_s2io_read_unicast_mc failed\n");
  4681. return FAILURE;
  4682. }
  4683. tmp64 = readq(&bar0->rmac_addr_data0_mem);
  4684. return (tmp64 >> 16);
  4685. }
  4686. /**
  4687. * s2io_set_mac_addr driver entry point
  4688. */
  4689. static int s2io_set_mac_addr(struct net_device *dev, void *p)
  4690. {
  4691. struct sockaddr *addr = p;
  4692. if (!is_valid_ether_addr(addr->sa_data))
  4693. return -EINVAL;
  4694. memcpy(dev->dev_addr, addr->sa_data, dev->addr_len);
  4695. /* store the MAC address in CAM */
  4696. return (do_s2io_prog_unicast(dev, dev->dev_addr));
  4697. }
  4698. /**
  4699. * do_s2io_prog_unicast - Programs the Xframe mac address
  4700. * @dev : pointer to the device structure.
  4701. * @addr: a uchar pointer to the new mac address which is to be set.
  4702. * Description : This procedure will program the Xframe to receive
  4703. * frames with new Mac Address
  4704. * Return value: SUCCESS on success and an appropriate (-)ve integer
  4705. * as defined in errno.h file on failure.
  4706. */
  4707. static int do_s2io_prog_unicast(struct net_device *dev, u8 *addr)
  4708. {
  4709. struct s2io_nic *sp = netdev_priv(dev);
  4710. register u64 mac_addr = 0, perm_addr = 0;
  4711. int i;
  4712. u64 tmp64;
  4713. struct config_param *config = &sp->config;
  4714. /*
  4715. * Set the new MAC address as the new unicast filter and reflect this
  4716. * change on the device address registered with the OS. It will be
  4717. * at offset 0.
  4718. */
  4719. for (i = 0; i < ETH_ALEN; i++) {
  4720. mac_addr <<= 8;
  4721. mac_addr |= addr[i];
  4722. perm_addr <<= 8;
  4723. perm_addr |= sp->def_mac_addr[0].mac_addr[i];
  4724. }
  4725. /* check if the dev_addr is different than perm_addr */
  4726. if (mac_addr == perm_addr)
  4727. return SUCCESS;
  4728. /* check if the mac already preset in CAM */
  4729. for (i = 1; i < config->max_mac_addr; i++) {
  4730. tmp64 = do_s2io_read_unicast_mc(sp, i);
  4731. if (tmp64 == S2IO_DISABLE_MAC_ENTRY) /* CAM entry is empty */
  4732. break;
  4733. if (tmp64 == mac_addr) {
  4734. DBG_PRINT(INFO_DBG,
  4735. "MAC addr:0x%llx already present in CAM\n",
  4736. (unsigned long long)mac_addr);
  4737. return SUCCESS;
  4738. }
  4739. }
  4740. if (i == config->max_mac_addr) {
  4741. DBG_PRINT(ERR_DBG, "CAM full no space left for Unicast MAC\n");
  4742. return FAILURE;
  4743. }
  4744. /* Update the internal structure with this new mac address */
  4745. do_s2io_copy_mac_addr(sp, i, mac_addr);
  4746. return (do_s2io_add_mac(sp, mac_addr, i));
  4747. }
  4748. /**
  4749. * s2io_ethtool_sset - Sets different link parameters.
  4750. * @sp : private member of the device structure, which is a pointer to the * s2io_nic structure.
  4751. * @info: pointer to the structure with parameters given by ethtool to set
  4752. * link information.
  4753. * Description:
  4754. * The function sets different link parameters provided by the user onto
  4755. * the NIC.
  4756. * Return value:
  4757. * 0 on success.
  4758. */
  4759. static int s2io_ethtool_sset(struct net_device *dev,
  4760. struct ethtool_cmd *info)
  4761. {
  4762. struct s2io_nic *sp = netdev_priv(dev);
  4763. if ((info->autoneg == AUTONEG_ENABLE) ||
  4764. (info->speed != SPEED_10000) || (info->duplex != DUPLEX_FULL))
  4765. return -EINVAL;
  4766. else {
  4767. s2io_close(sp->dev);
  4768. s2io_open(sp->dev);
  4769. }
  4770. return 0;
  4771. }
  4772. /**
  4773. * s2io_ethtol_gset - Return link specific information.
  4774. * @sp : private member of the device structure, pointer to the
  4775. * s2io_nic structure.
  4776. * @info : pointer to the structure with parameters given by ethtool
  4777. * to return link information.
  4778. * Description:
  4779. * Returns link specific information like speed, duplex etc.. to ethtool.
  4780. * Return value :
  4781. * return 0 on success.
  4782. */
  4783. static int s2io_ethtool_gset(struct net_device *dev, struct ethtool_cmd *info)
  4784. {
  4785. struct s2io_nic *sp = netdev_priv(dev);
  4786. info->supported = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  4787. info->advertising = (SUPPORTED_10000baseT_Full | SUPPORTED_FIBRE);
  4788. info->port = PORT_FIBRE;
  4789. /* info->transceiver */
  4790. info->transceiver = XCVR_EXTERNAL;
  4791. if (netif_carrier_ok(sp->dev)) {
  4792. info->speed = 10000;
  4793. info->duplex = DUPLEX_FULL;
  4794. } else {
  4795. info->speed = -1;
  4796. info->duplex = -1;
  4797. }
  4798. info->autoneg = AUTONEG_DISABLE;
  4799. return 0;
  4800. }
  4801. /**
  4802. * s2io_ethtool_gdrvinfo - Returns driver specific information.
  4803. * @sp : private member of the device structure, which is a pointer to the
  4804. * s2io_nic structure.
  4805. * @info : pointer to the structure with parameters given by ethtool to
  4806. * return driver information.
  4807. * Description:
  4808. * Returns driver specefic information like name, version etc.. to ethtool.
  4809. * Return value:
  4810. * void
  4811. */
  4812. static void s2io_ethtool_gdrvinfo(struct net_device *dev,
  4813. struct ethtool_drvinfo *info)
  4814. {
  4815. struct s2io_nic *sp = netdev_priv(dev);
  4816. strncpy(info->driver, s2io_driver_name, sizeof(info->driver));
  4817. strncpy(info->version, s2io_driver_version, sizeof(info->version));
  4818. strncpy(info->fw_version, "", sizeof(info->fw_version));
  4819. strncpy(info->bus_info, pci_name(sp->pdev), sizeof(info->bus_info));
  4820. info->regdump_len = XENA_REG_SPACE;
  4821. info->eedump_len = XENA_EEPROM_SPACE;
  4822. }
  4823. /**
  4824. * s2io_ethtool_gregs - dumps the entire space of Xfame into the buffer.
  4825. * @sp: private member of the device structure, which is a pointer to the
  4826. * s2io_nic structure.
  4827. * @regs : pointer to the structure with parameters given by ethtool for
  4828. * dumping the registers.
  4829. * @reg_space: The input argumnet into which all the registers are dumped.
  4830. * Description:
  4831. * Dumps the entire register space of xFrame NIC into the user given
  4832. * buffer area.
  4833. * Return value :
  4834. * void .
  4835. */
  4836. static void s2io_ethtool_gregs(struct net_device *dev,
  4837. struct ethtool_regs *regs, void *space)
  4838. {
  4839. int i;
  4840. u64 reg;
  4841. u8 *reg_space = (u8 *) space;
  4842. struct s2io_nic *sp = netdev_priv(dev);
  4843. regs->len = XENA_REG_SPACE;
  4844. regs->version = sp->pdev->subsystem_device;
  4845. for (i = 0; i < regs->len; i += 8) {
  4846. reg = readq(sp->bar0 + i);
  4847. memcpy((reg_space + i), &reg, 8);
  4848. }
  4849. }
  4850. /**
  4851. * s2io_phy_id - timer function that alternates adapter LED.
  4852. * @data : address of the private member of the device structure, which
  4853. * is a pointer to the s2io_nic structure, provided as an u32.
  4854. * Description: This is actually the timer function that alternates the
  4855. * adapter LED bit of the adapter control bit to set/reset every time on
  4856. * invocation. The timer is set for 1/2 a second, hence tha NIC blinks
  4857. * once every second.
  4858. */
  4859. static void s2io_phy_id(unsigned long data)
  4860. {
  4861. struct s2io_nic *sp = (struct s2io_nic *) data;
  4862. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4863. u64 val64 = 0;
  4864. u16 subid;
  4865. subid = sp->pdev->subsystem_device;
  4866. if ((sp->device_type == XFRAME_II_DEVICE) ||
  4867. ((subid & 0xFF) >= 0x07)) {
  4868. val64 = readq(&bar0->gpio_control);
  4869. val64 ^= GPIO_CTRL_GPIO_0;
  4870. writeq(val64, &bar0->gpio_control);
  4871. } else {
  4872. val64 = readq(&bar0->adapter_control);
  4873. val64 ^= ADAPTER_LED_ON;
  4874. writeq(val64, &bar0->adapter_control);
  4875. }
  4876. mod_timer(&sp->id_timer, jiffies + HZ / 2);
  4877. }
  4878. /**
  4879. * s2io_ethtool_idnic - To physically identify the nic on the system.
  4880. * @sp : private member of the device structure, which is a pointer to the
  4881. * s2io_nic structure.
  4882. * @id : pointer to the structure with identification parameters given by
  4883. * ethtool.
  4884. * Description: Used to physically identify the NIC on the system.
  4885. * The Link LED will blink for a time specified by the user for
  4886. * identification.
  4887. * NOTE: The Link has to be Up to be able to blink the LED. Hence
  4888. * identification is possible only if it's link is up.
  4889. * Return value:
  4890. * int , returns 0 on success
  4891. */
  4892. static int s2io_ethtool_idnic(struct net_device *dev, u32 data)
  4893. {
  4894. u64 val64 = 0, last_gpio_ctrl_val;
  4895. struct s2io_nic *sp = netdev_priv(dev);
  4896. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4897. u16 subid;
  4898. subid = sp->pdev->subsystem_device;
  4899. last_gpio_ctrl_val = readq(&bar0->gpio_control);
  4900. if ((sp->device_type == XFRAME_I_DEVICE) &&
  4901. ((subid & 0xFF) < 0x07)) {
  4902. val64 = readq(&bar0->adapter_control);
  4903. if (!(val64 & ADAPTER_CNTL_EN)) {
  4904. printk(KERN_ERR
  4905. "Adapter Link down, cannot blink LED\n");
  4906. return -EFAULT;
  4907. }
  4908. }
  4909. if (sp->id_timer.function == NULL) {
  4910. init_timer(&sp->id_timer);
  4911. sp->id_timer.function = s2io_phy_id;
  4912. sp->id_timer.data = (unsigned long) sp;
  4913. }
  4914. mod_timer(&sp->id_timer, jiffies);
  4915. if (data)
  4916. msleep_interruptible(data * HZ);
  4917. else
  4918. msleep_interruptible(MAX_FLICKER_TIME);
  4919. del_timer_sync(&sp->id_timer);
  4920. if (CARDS_WITH_FAULTY_LINK_INDICATORS(sp->device_type, subid)) {
  4921. writeq(last_gpio_ctrl_val, &bar0->gpio_control);
  4922. last_gpio_ctrl_val = readq(&bar0->gpio_control);
  4923. }
  4924. return 0;
  4925. }
  4926. static void s2io_ethtool_gringparam(struct net_device *dev,
  4927. struct ethtool_ringparam *ering)
  4928. {
  4929. struct s2io_nic *sp = netdev_priv(dev);
  4930. int i,tx_desc_count=0,rx_desc_count=0;
  4931. if (sp->rxd_mode == RXD_MODE_1)
  4932. ering->rx_max_pending = MAX_RX_DESC_1;
  4933. else if (sp->rxd_mode == RXD_MODE_3B)
  4934. ering->rx_max_pending = MAX_RX_DESC_2;
  4935. ering->tx_max_pending = MAX_TX_DESC;
  4936. for (i = 0 ; i < sp->config.tx_fifo_num ; i++)
  4937. tx_desc_count += sp->config.tx_cfg[i].fifo_len;
  4938. DBG_PRINT(INFO_DBG,"\nmax txds : %d\n",sp->config.max_txds);
  4939. ering->tx_pending = tx_desc_count;
  4940. rx_desc_count = 0;
  4941. for (i = 0 ; i < sp->config.rx_ring_num ; i++)
  4942. rx_desc_count += sp->config.rx_cfg[i].num_rxd;
  4943. ering->rx_pending = rx_desc_count;
  4944. ering->rx_mini_max_pending = 0;
  4945. ering->rx_mini_pending = 0;
  4946. if(sp->rxd_mode == RXD_MODE_1)
  4947. ering->rx_jumbo_max_pending = MAX_RX_DESC_1;
  4948. else if (sp->rxd_mode == RXD_MODE_3B)
  4949. ering->rx_jumbo_max_pending = MAX_RX_DESC_2;
  4950. ering->rx_jumbo_pending = rx_desc_count;
  4951. }
  4952. /**
  4953. * s2io_ethtool_getpause_data -Pause frame frame generation and reception.
  4954. * @sp : private member of the device structure, which is a pointer to the
  4955. * s2io_nic structure.
  4956. * @ep : pointer to the structure with pause parameters given by ethtool.
  4957. * Description:
  4958. * Returns the Pause frame generation and reception capability of the NIC.
  4959. * Return value:
  4960. * void
  4961. */
  4962. static void s2io_ethtool_getpause_data(struct net_device *dev,
  4963. struct ethtool_pauseparam *ep)
  4964. {
  4965. u64 val64;
  4966. struct s2io_nic *sp = netdev_priv(dev);
  4967. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4968. val64 = readq(&bar0->rmac_pause_cfg);
  4969. if (val64 & RMAC_PAUSE_GEN_ENABLE)
  4970. ep->tx_pause = TRUE;
  4971. if (val64 & RMAC_PAUSE_RX_ENABLE)
  4972. ep->rx_pause = TRUE;
  4973. ep->autoneg = FALSE;
  4974. }
  4975. /**
  4976. * s2io_ethtool_setpause_data - set/reset pause frame generation.
  4977. * @sp : private member of the device structure, which is a pointer to the
  4978. * s2io_nic structure.
  4979. * @ep : pointer to the structure with pause parameters given by ethtool.
  4980. * Description:
  4981. * It can be used to set or reset Pause frame generation or reception
  4982. * support of the NIC.
  4983. * Return value:
  4984. * int, returns 0 on Success
  4985. */
  4986. static int s2io_ethtool_setpause_data(struct net_device *dev,
  4987. struct ethtool_pauseparam *ep)
  4988. {
  4989. u64 val64;
  4990. struct s2io_nic *sp = netdev_priv(dev);
  4991. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  4992. val64 = readq(&bar0->rmac_pause_cfg);
  4993. if (ep->tx_pause)
  4994. val64 |= RMAC_PAUSE_GEN_ENABLE;
  4995. else
  4996. val64 &= ~RMAC_PAUSE_GEN_ENABLE;
  4997. if (ep->rx_pause)
  4998. val64 |= RMAC_PAUSE_RX_ENABLE;
  4999. else
  5000. val64 &= ~RMAC_PAUSE_RX_ENABLE;
  5001. writeq(val64, &bar0->rmac_pause_cfg);
  5002. return 0;
  5003. }
  5004. /**
  5005. * read_eeprom - reads 4 bytes of data from user given offset.
  5006. * @sp : private member of the device structure, which is a pointer to the
  5007. * s2io_nic structure.
  5008. * @off : offset at which the data must be written
  5009. * @data : Its an output parameter where the data read at the given
  5010. * offset is stored.
  5011. * Description:
  5012. * Will read 4 bytes of data from the user given offset and return the
  5013. * read data.
  5014. * NOTE: Will allow to read only part of the EEPROM visible through the
  5015. * I2C bus.
  5016. * Return value:
  5017. * -1 on failure and 0 on success.
  5018. */
  5019. #define S2IO_DEV_ID 5
  5020. static int read_eeprom(struct s2io_nic * sp, int off, u64 * data)
  5021. {
  5022. int ret = -1;
  5023. u32 exit_cnt = 0;
  5024. u64 val64;
  5025. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  5026. if (sp->device_type == XFRAME_I_DEVICE) {
  5027. val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) |
  5028. I2C_CONTROL_BYTE_CNT(0x3) | I2C_CONTROL_READ |
  5029. I2C_CONTROL_CNTL_START;
  5030. SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF);
  5031. while (exit_cnt < 5) {
  5032. val64 = readq(&bar0->i2c_control);
  5033. if (I2C_CONTROL_CNTL_END(val64)) {
  5034. *data = I2C_CONTROL_GET_DATA(val64);
  5035. ret = 0;
  5036. break;
  5037. }
  5038. msleep(50);
  5039. exit_cnt++;
  5040. }
  5041. }
  5042. if (sp->device_type == XFRAME_II_DEVICE) {
  5043. val64 = SPI_CONTROL_KEY(0x9) | SPI_CONTROL_SEL1 |
  5044. SPI_CONTROL_BYTECNT(0x3) |
  5045. SPI_CONTROL_CMD(0x3) | SPI_CONTROL_ADDR(off);
  5046. SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
  5047. val64 |= SPI_CONTROL_REQ;
  5048. SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
  5049. while (exit_cnt < 5) {
  5050. val64 = readq(&bar0->spi_control);
  5051. if (val64 & SPI_CONTROL_NACK) {
  5052. ret = 1;
  5053. break;
  5054. } else if (val64 & SPI_CONTROL_DONE) {
  5055. *data = readq(&bar0->spi_data);
  5056. *data &= 0xffffff;
  5057. ret = 0;
  5058. break;
  5059. }
  5060. msleep(50);
  5061. exit_cnt++;
  5062. }
  5063. }
  5064. return ret;
  5065. }
  5066. /**
  5067. * write_eeprom - actually writes the relevant part of the data value.
  5068. * @sp : private member of the device structure, which is a pointer to the
  5069. * s2io_nic structure.
  5070. * @off : offset at which the data must be written
  5071. * @data : The data that is to be written
  5072. * @cnt : Number of bytes of the data that are actually to be written into
  5073. * the Eeprom. (max of 3)
  5074. * Description:
  5075. * Actually writes the relevant part of the data value into the Eeprom
  5076. * through the I2C bus.
  5077. * Return value:
  5078. * 0 on success, -1 on failure.
  5079. */
  5080. static int write_eeprom(struct s2io_nic * sp, int off, u64 data, int cnt)
  5081. {
  5082. int exit_cnt = 0, ret = -1;
  5083. u64 val64;
  5084. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  5085. if (sp->device_type == XFRAME_I_DEVICE) {
  5086. val64 = I2C_CONTROL_DEV_ID(S2IO_DEV_ID) | I2C_CONTROL_ADDR(off) |
  5087. I2C_CONTROL_BYTE_CNT(cnt) | I2C_CONTROL_SET_DATA((u32)data) |
  5088. I2C_CONTROL_CNTL_START;
  5089. SPECIAL_REG_WRITE(val64, &bar0->i2c_control, LF);
  5090. while (exit_cnt < 5) {
  5091. val64 = readq(&bar0->i2c_control);
  5092. if (I2C_CONTROL_CNTL_END(val64)) {
  5093. if (!(val64 & I2C_CONTROL_NACK))
  5094. ret = 0;
  5095. break;
  5096. }
  5097. msleep(50);
  5098. exit_cnt++;
  5099. }
  5100. }
  5101. if (sp->device_type == XFRAME_II_DEVICE) {
  5102. int write_cnt = (cnt == 8) ? 0 : cnt;
  5103. writeq(SPI_DATA_WRITE(data,(cnt<<3)), &bar0->spi_data);
  5104. val64 = SPI_CONTROL_KEY(0x9) | SPI_CONTROL_SEL1 |
  5105. SPI_CONTROL_BYTECNT(write_cnt) |
  5106. SPI_CONTROL_CMD(0x2) | SPI_CONTROL_ADDR(off);
  5107. SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
  5108. val64 |= SPI_CONTROL_REQ;
  5109. SPECIAL_REG_WRITE(val64, &bar0->spi_control, LF);
  5110. while (exit_cnt < 5) {
  5111. val64 = readq(&bar0->spi_control);
  5112. if (val64 & SPI_CONTROL_NACK) {
  5113. ret = 1;
  5114. break;
  5115. } else if (val64 & SPI_CONTROL_DONE) {
  5116. ret = 0;
  5117. break;
  5118. }
  5119. msleep(50);
  5120. exit_cnt++;
  5121. }
  5122. }
  5123. return ret;
  5124. }
  5125. static void s2io_vpd_read(struct s2io_nic *nic)
  5126. {
  5127. u8 *vpd_data;
  5128. u8 data;
  5129. int i=0, cnt, fail = 0;
  5130. int vpd_addr = 0x80;
  5131. if (nic->device_type == XFRAME_II_DEVICE) {
  5132. strcpy(nic->product_name, "Xframe II 10GbE network adapter");
  5133. vpd_addr = 0x80;
  5134. }
  5135. else {
  5136. strcpy(nic->product_name, "Xframe I 10GbE network adapter");
  5137. vpd_addr = 0x50;
  5138. }
  5139. strcpy(nic->serial_num, "NOT AVAILABLE");
  5140. vpd_data = kmalloc(256, GFP_KERNEL);
  5141. if (!vpd_data) {
  5142. nic->mac_control.stats_info->sw_stat.mem_alloc_fail_cnt++;
  5143. return;
  5144. }
  5145. nic->mac_control.stats_info->sw_stat.mem_allocated += 256;
  5146. for (i = 0; i < 256; i +=4 ) {
  5147. pci_write_config_byte(nic->pdev, (vpd_addr + 2), i);
  5148. pci_read_config_byte(nic->pdev, (vpd_addr + 2), &data);
  5149. pci_write_config_byte(nic->pdev, (vpd_addr + 3), 0);
  5150. for (cnt = 0; cnt <5; cnt++) {
  5151. msleep(2);
  5152. pci_read_config_byte(nic->pdev, (vpd_addr + 3), &data);
  5153. if (data == 0x80)
  5154. break;
  5155. }
  5156. if (cnt >= 5) {
  5157. DBG_PRINT(ERR_DBG, "Read of VPD data failed\n");
  5158. fail = 1;
  5159. break;
  5160. }
  5161. pci_read_config_dword(nic->pdev, (vpd_addr + 4),
  5162. (u32 *)&vpd_data[i]);
  5163. }
  5164. if(!fail) {
  5165. /* read serial number of adapter */
  5166. for (cnt = 0; cnt < 256; cnt++) {
  5167. if ((vpd_data[cnt] == 'S') &&
  5168. (vpd_data[cnt+1] == 'N') &&
  5169. (vpd_data[cnt+2] < VPD_STRING_LEN)) {
  5170. memset(nic->serial_num, 0, VPD_STRING_LEN);
  5171. memcpy(nic->serial_num, &vpd_data[cnt + 3],
  5172. vpd_data[cnt+2]);
  5173. break;
  5174. }
  5175. }
  5176. }
  5177. if ((!fail) && (vpd_data[1] < VPD_STRING_LEN)) {
  5178. memset(nic->product_name, 0, vpd_data[1]);
  5179. memcpy(nic->product_name, &vpd_data[3], vpd_data[1]);
  5180. }
  5181. kfree(vpd_data);
  5182. nic->mac_control.stats_info->sw_stat.mem_freed += 256;
  5183. }
  5184. /**
  5185. * s2io_ethtool_geeprom - reads the value stored in the Eeprom.
  5186. * @sp : private member of the device structure, which is a pointer to the * s2io_nic structure.
  5187. * @eeprom : pointer to the user level structure provided by ethtool,
  5188. * containing all relevant information.
  5189. * @data_buf : user defined value to be written into Eeprom.
  5190. * Description: Reads the values stored in the Eeprom at given offset
  5191. * for a given length. Stores these values int the input argument data
  5192. * buffer 'data_buf' and returns these to the caller (ethtool.)
  5193. * Return value:
  5194. * int 0 on success
  5195. */
  5196. static int s2io_ethtool_geeprom(struct net_device *dev,
  5197. struct ethtool_eeprom *eeprom, u8 * data_buf)
  5198. {
  5199. u32 i, valid;
  5200. u64 data;
  5201. struct s2io_nic *sp = netdev_priv(dev);
  5202. eeprom->magic = sp->pdev->vendor | (sp->pdev->device << 16);
  5203. if ((eeprom->offset + eeprom->len) > (XENA_EEPROM_SPACE))
  5204. eeprom->len = XENA_EEPROM_SPACE - eeprom->offset;
  5205. for (i = 0; i < eeprom->len; i += 4) {
  5206. if (read_eeprom(sp, (eeprom->offset + i), &data)) {
  5207. DBG_PRINT(ERR_DBG, "Read of EEPROM failed\n");
  5208. return -EFAULT;
  5209. }
  5210. valid = INV(data);
  5211. memcpy((data_buf + i), &valid, 4);
  5212. }
  5213. return 0;
  5214. }
  5215. /**
  5216. * s2io_ethtool_seeprom - tries to write the user provided value in Eeprom
  5217. * @sp : private member of the device structure, which is a pointer to the
  5218. * s2io_nic structure.
  5219. * @eeprom : pointer to the user level structure provided by ethtool,
  5220. * containing all relevant information.
  5221. * @data_buf ; user defined value to be written into Eeprom.
  5222. * Description:
  5223. * Tries to write the user provided value in the Eeprom, at the offset
  5224. * given by the user.
  5225. * Return value:
  5226. * 0 on success, -EFAULT on failure.
  5227. */
  5228. static int s2io_ethtool_seeprom(struct net_device *dev,
  5229. struct ethtool_eeprom *eeprom,
  5230. u8 * data_buf)
  5231. {
  5232. int len = eeprom->len, cnt = 0;
  5233. u64 valid = 0, data;
  5234. struct s2io_nic *sp = netdev_priv(dev);
  5235. if (eeprom->magic != (sp->pdev->vendor | (sp->pdev->device << 16))) {
  5236. DBG_PRINT(ERR_DBG,
  5237. "ETHTOOL_WRITE_EEPROM Err: Magic value ");
  5238. DBG_PRINT(ERR_DBG, "is wrong, Its not 0x%x\n",
  5239. eeprom->magic);
  5240. return -EFAULT;
  5241. }
  5242. while (len) {
  5243. data = (u32) data_buf[cnt] & 0x000000FF;
  5244. if (data) {
  5245. valid = (u32) (data << 24);
  5246. } else
  5247. valid = data;
  5248. if (write_eeprom(sp, (eeprom->offset + cnt), valid, 0)) {
  5249. DBG_PRINT(ERR_DBG,
  5250. "ETHTOOL_WRITE_EEPROM Err: Cannot ");
  5251. DBG_PRINT(ERR_DBG,
  5252. "write into the specified offset\n");
  5253. return -EFAULT;
  5254. }
  5255. cnt++;
  5256. len--;
  5257. }
  5258. return 0;
  5259. }
  5260. /**
  5261. * s2io_register_test - reads and writes into all clock domains.
  5262. * @sp : private member of the device structure, which is a pointer to the
  5263. * s2io_nic structure.
  5264. * @data : variable that returns the result of each of the test conducted b
  5265. * by the driver.
  5266. * Description:
  5267. * Read and write into all clock domains. The NIC has 3 clock domains,
  5268. * see that registers in all the three regions are accessible.
  5269. * Return value:
  5270. * 0 on success.
  5271. */
  5272. static int s2io_register_test(struct s2io_nic * sp, uint64_t * data)
  5273. {
  5274. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  5275. u64 val64 = 0, exp_val;
  5276. int fail = 0;
  5277. val64 = readq(&bar0->pif_rd_swapper_fb);
  5278. if (val64 != 0x123456789abcdefULL) {
  5279. fail = 1;
  5280. DBG_PRINT(INFO_DBG, "Read Test level 1 fails\n");
  5281. }
  5282. val64 = readq(&bar0->rmac_pause_cfg);
  5283. if (val64 != 0xc000ffff00000000ULL) {
  5284. fail = 1;
  5285. DBG_PRINT(INFO_DBG, "Read Test level 2 fails\n");
  5286. }
  5287. val64 = readq(&bar0->rx_queue_cfg);
  5288. if (sp->device_type == XFRAME_II_DEVICE)
  5289. exp_val = 0x0404040404040404ULL;
  5290. else
  5291. exp_val = 0x0808080808080808ULL;
  5292. if (val64 != exp_val) {
  5293. fail = 1;
  5294. DBG_PRINT(INFO_DBG, "Read Test level 3 fails\n");
  5295. }
  5296. val64 = readq(&bar0->xgxs_efifo_cfg);
  5297. if (val64 != 0x000000001923141EULL) {
  5298. fail = 1;
  5299. DBG_PRINT(INFO_DBG, "Read Test level 4 fails\n");
  5300. }
  5301. val64 = 0x5A5A5A5A5A5A5A5AULL;
  5302. writeq(val64, &bar0->xmsi_data);
  5303. val64 = readq(&bar0->xmsi_data);
  5304. if (val64 != 0x5A5A5A5A5A5A5A5AULL) {
  5305. fail = 1;
  5306. DBG_PRINT(ERR_DBG, "Write Test level 1 fails\n");
  5307. }
  5308. val64 = 0xA5A5A5A5A5A5A5A5ULL;
  5309. writeq(val64, &bar0->xmsi_data);
  5310. val64 = readq(&bar0->xmsi_data);
  5311. if (val64 != 0xA5A5A5A5A5A5A5A5ULL) {
  5312. fail = 1;
  5313. DBG_PRINT(ERR_DBG, "Write Test level 2 fails\n");
  5314. }
  5315. *data = fail;
  5316. return fail;
  5317. }
  5318. /**
  5319. * s2io_eeprom_test - to verify that EEprom in the xena can be programmed.
  5320. * @sp : private member of the device structure, which is a pointer to the
  5321. * s2io_nic structure.
  5322. * @data:variable that returns the result of each of the test conducted by
  5323. * the driver.
  5324. * Description:
  5325. * Verify that EEPROM in the xena can be programmed using I2C_CONTROL
  5326. * register.
  5327. * Return value:
  5328. * 0 on success.
  5329. */
  5330. static int s2io_eeprom_test(struct s2io_nic * sp, uint64_t * data)
  5331. {
  5332. int fail = 0;
  5333. u64 ret_data, org_4F0, org_7F0;
  5334. u8 saved_4F0 = 0, saved_7F0 = 0;
  5335. struct net_device *dev = sp->dev;
  5336. /* Test Write Error at offset 0 */
  5337. /* Note that SPI interface allows write access to all areas
  5338. * of EEPROM. Hence doing all negative testing only for Xframe I.
  5339. */
  5340. if (sp->device_type == XFRAME_I_DEVICE)
  5341. if (!write_eeprom(sp, 0, 0, 3))
  5342. fail = 1;
  5343. /* Save current values at offsets 0x4F0 and 0x7F0 */
  5344. if (!read_eeprom(sp, 0x4F0, &org_4F0))
  5345. saved_4F0 = 1;
  5346. if (!read_eeprom(sp, 0x7F0, &org_7F0))
  5347. saved_7F0 = 1;
  5348. /* Test Write at offset 4f0 */
  5349. if (write_eeprom(sp, 0x4F0, 0x012345, 3))
  5350. fail = 1;
  5351. if (read_eeprom(sp, 0x4F0, &ret_data))
  5352. fail = 1;
  5353. if (ret_data != 0x012345) {
  5354. DBG_PRINT(ERR_DBG, "%s: eeprom test error at offset 0x4F0. "
  5355. "Data written %llx Data read %llx\n",
  5356. dev->name, (unsigned long long)0x12345,
  5357. (unsigned long long)ret_data);
  5358. fail = 1;
  5359. }
  5360. /* Reset the EEPROM data go FFFF */
  5361. write_eeprom(sp, 0x4F0, 0xFFFFFF, 3);
  5362. /* Test Write Request Error at offset 0x7c */
  5363. if (sp->device_type == XFRAME_I_DEVICE)
  5364. if (!write_eeprom(sp, 0x07C, 0, 3))
  5365. fail = 1;
  5366. /* Test Write Request at offset 0x7f0 */
  5367. if (write_eeprom(sp, 0x7F0, 0x012345, 3))
  5368. fail = 1;
  5369. if (read_eeprom(sp, 0x7F0, &ret_data))
  5370. fail = 1;
  5371. if (ret_data != 0x012345) {
  5372. DBG_PRINT(ERR_DBG, "%s: eeprom test error at offset 0x7F0. "
  5373. "Data written %llx Data read %llx\n",
  5374. dev->name, (unsigned long long)0x12345,
  5375. (unsigned long long)ret_data);
  5376. fail = 1;
  5377. }
  5378. /* Reset the EEPROM data go FFFF */
  5379. write_eeprom(sp, 0x7F0, 0xFFFFFF, 3);
  5380. if (sp->device_type == XFRAME_I_DEVICE) {
  5381. /* Test Write Error at offset 0x80 */
  5382. if (!write_eeprom(sp, 0x080, 0, 3))
  5383. fail = 1;
  5384. /* Test Write Error at offset 0xfc */
  5385. if (!write_eeprom(sp, 0x0FC, 0, 3))
  5386. fail = 1;
  5387. /* Test Write Error at offset 0x100 */
  5388. if (!write_eeprom(sp, 0x100, 0, 3))
  5389. fail = 1;
  5390. /* Test Write Error at offset 4ec */
  5391. if (!write_eeprom(sp, 0x4EC, 0, 3))
  5392. fail = 1;
  5393. }
  5394. /* Restore values at offsets 0x4F0 and 0x7F0 */
  5395. if (saved_4F0)
  5396. write_eeprom(sp, 0x4F0, org_4F0, 3);
  5397. if (saved_7F0)
  5398. write_eeprom(sp, 0x7F0, org_7F0, 3);
  5399. *data = fail;
  5400. return fail;
  5401. }
  5402. /**
  5403. * s2io_bist_test - invokes the MemBist test of the card .
  5404. * @sp : private member of the device structure, which is a pointer to the
  5405. * s2io_nic structure.
  5406. * @data:variable that returns the result of each of the test conducted by
  5407. * the driver.
  5408. * Description:
  5409. * This invokes the MemBist test of the card. We give around
  5410. * 2 secs time for the Test to complete. If it's still not complete
  5411. * within this peiod, we consider that the test failed.
  5412. * Return value:
  5413. * 0 on success and -1 on failure.
  5414. */
  5415. static int s2io_bist_test(struct s2io_nic * sp, uint64_t * data)
  5416. {
  5417. u8 bist = 0;
  5418. int cnt = 0, ret = -1;
  5419. pci_read_config_byte(sp->pdev, PCI_BIST, &bist);
  5420. bist |= PCI_BIST_START;
  5421. pci_write_config_word(sp->pdev, PCI_BIST, bist);
  5422. while (cnt < 20) {
  5423. pci_read_config_byte(sp->pdev, PCI_BIST, &bist);
  5424. if (!(bist & PCI_BIST_START)) {
  5425. *data = (bist & PCI_BIST_CODE_MASK);
  5426. ret = 0;
  5427. break;
  5428. }
  5429. msleep(100);
  5430. cnt++;
  5431. }
  5432. return ret;
  5433. }
  5434. /**
  5435. * s2io-link_test - verifies the link state of the nic
  5436. * @sp ; private member of the device structure, which is a pointer to the
  5437. * s2io_nic structure.
  5438. * @data: variable that returns the result of each of the test conducted by
  5439. * the driver.
  5440. * Description:
  5441. * The function verifies the link state of the NIC and updates the input
  5442. * argument 'data' appropriately.
  5443. * Return value:
  5444. * 0 on success.
  5445. */
  5446. static int s2io_link_test(struct s2io_nic * sp, uint64_t * data)
  5447. {
  5448. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  5449. u64 val64;
  5450. val64 = readq(&bar0->adapter_status);
  5451. if(!(LINK_IS_UP(val64)))
  5452. *data = 1;
  5453. else
  5454. *data = 0;
  5455. return *data;
  5456. }
  5457. /**
  5458. * s2io_rldram_test - offline test for access to the RldRam chip on the NIC
  5459. * @sp - private member of the device structure, which is a pointer to the
  5460. * s2io_nic structure.
  5461. * @data - variable that returns the result of each of the test
  5462. * conducted by the driver.
  5463. * Description:
  5464. * This is one of the offline test that tests the read and write
  5465. * access to the RldRam chip on the NIC.
  5466. * Return value:
  5467. * 0 on success.
  5468. */
  5469. static int s2io_rldram_test(struct s2io_nic * sp, uint64_t * data)
  5470. {
  5471. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  5472. u64 val64;
  5473. int cnt, iteration = 0, test_fail = 0;
  5474. val64 = readq(&bar0->adapter_control);
  5475. val64 &= ~ADAPTER_ECC_EN;
  5476. writeq(val64, &bar0->adapter_control);
  5477. val64 = readq(&bar0->mc_rldram_test_ctrl);
  5478. val64 |= MC_RLDRAM_TEST_MODE;
  5479. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
  5480. val64 = readq(&bar0->mc_rldram_mrs);
  5481. val64 |= MC_RLDRAM_QUEUE_SIZE_ENABLE;
  5482. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
  5483. val64 |= MC_RLDRAM_MRS_ENABLE;
  5484. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_mrs, UF);
  5485. while (iteration < 2) {
  5486. val64 = 0x55555555aaaa0000ULL;
  5487. if (iteration == 1) {
  5488. val64 ^= 0xFFFFFFFFFFFF0000ULL;
  5489. }
  5490. writeq(val64, &bar0->mc_rldram_test_d0);
  5491. val64 = 0xaaaa5a5555550000ULL;
  5492. if (iteration == 1) {
  5493. val64 ^= 0xFFFFFFFFFFFF0000ULL;
  5494. }
  5495. writeq(val64, &bar0->mc_rldram_test_d1);
  5496. val64 = 0x55aaaaaaaa5a0000ULL;
  5497. if (iteration == 1) {
  5498. val64 ^= 0xFFFFFFFFFFFF0000ULL;
  5499. }
  5500. writeq(val64, &bar0->mc_rldram_test_d2);
  5501. val64 = (u64) (0x0000003ffffe0100ULL);
  5502. writeq(val64, &bar0->mc_rldram_test_add);
  5503. val64 = MC_RLDRAM_TEST_MODE | MC_RLDRAM_TEST_WRITE |
  5504. MC_RLDRAM_TEST_GO;
  5505. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
  5506. for (cnt = 0; cnt < 5; cnt++) {
  5507. val64 = readq(&bar0->mc_rldram_test_ctrl);
  5508. if (val64 & MC_RLDRAM_TEST_DONE)
  5509. break;
  5510. msleep(200);
  5511. }
  5512. if (cnt == 5)
  5513. break;
  5514. val64 = MC_RLDRAM_TEST_MODE | MC_RLDRAM_TEST_GO;
  5515. SPECIAL_REG_WRITE(val64, &bar0->mc_rldram_test_ctrl, LF);
  5516. for (cnt = 0; cnt < 5; cnt++) {
  5517. val64 = readq(&bar0->mc_rldram_test_ctrl);
  5518. if (val64 & MC_RLDRAM_TEST_DONE)
  5519. break;
  5520. msleep(500);
  5521. }
  5522. if (cnt == 5)
  5523. break;
  5524. val64 = readq(&bar0->mc_rldram_test_ctrl);
  5525. if (!(val64 & MC_RLDRAM_TEST_PASS))
  5526. test_fail = 1;
  5527. iteration++;
  5528. }
  5529. *data = test_fail;
  5530. /* Bring the adapter out of test mode */
  5531. SPECIAL_REG_WRITE(0, &bar0->mc_rldram_test_ctrl, LF);
  5532. return test_fail;
  5533. }
  5534. /**
  5535. * s2io_ethtool_test - conducts 6 tsets to determine the health of card.
  5536. * @sp : private member of the device structure, which is a pointer to the
  5537. * s2io_nic structure.
  5538. * @ethtest : pointer to a ethtool command specific structure that will be
  5539. * returned to the user.
  5540. * @data : variable that returns the result of each of the test
  5541. * conducted by the driver.
  5542. * Description:
  5543. * This function conducts 6 tests ( 4 offline and 2 online) to determine
  5544. * the health of the card.
  5545. * Return value:
  5546. * void
  5547. */
  5548. static void s2io_ethtool_test(struct net_device *dev,
  5549. struct ethtool_test *ethtest,
  5550. uint64_t * data)
  5551. {
  5552. struct s2io_nic *sp = netdev_priv(dev);
  5553. int orig_state = netif_running(sp->dev);
  5554. if (ethtest->flags == ETH_TEST_FL_OFFLINE) {
  5555. /* Offline Tests. */
  5556. if (orig_state)
  5557. s2io_close(sp->dev);
  5558. if (s2io_register_test(sp, &data[0]))
  5559. ethtest->flags |= ETH_TEST_FL_FAILED;
  5560. s2io_reset(sp);
  5561. if (s2io_rldram_test(sp, &data[3]))
  5562. ethtest->flags |= ETH_TEST_FL_FAILED;
  5563. s2io_reset(sp);
  5564. if (s2io_eeprom_test(sp, &data[1]))
  5565. ethtest->flags |= ETH_TEST_FL_FAILED;
  5566. if (s2io_bist_test(sp, &data[4]))
  5567. ethtest->flags |= ETH_TEST_FL_FAILED;
  5568. if (orig_state)
  5569. s2io_open(sp->dev);
  5570. data[2] = 0;
  5571. } else {
  5572. /* Online Tests. */
  5573. if (!orig_state) {
  5574. DBG_PRINT(ERR_DBG,
  5575. "%s: is not up, cannot run test\n",
  5576. dev->name);
  5577. data[0] = -1;
  5578. data[1] = -1;
  5579. data[2] = -1;
  5580. data[3] = -1;
  5581. data[4] = -1;
  5582. }
  5583. if (s2io_link_test(sp, &data[2]))
  5584. ethtest->flags |= ETH_TEST_FL_FAILED;
  5585. data[0] = 0;
  5586. data[1] = 0;
  5587. data[3] = 0;
  5588. data[4] = 0;
  5589. }
  5590. }
  5591. static void s2io_get_ethtool_stats(struct net_device *dev,
  5592. struct ethtool_stats *estats,
  5593. u64 * tmp_stats)
  5594. {
  5595. int i = 0, k;
  5596. struct s2io_nic *sp = netdev_priv(dev);
  5597. struct stat_block *stat_info = sp->mac_control.stats_info;
  5598. s2io_updt_stats(sp);
  5599. tmp_stats[i++] =
  5600. (u64)le32_to_cpu(stat_info->tmac_frms_oflow) << 32 |
  5601. le32_to_cpu(stat_info->tmac_frms);
  5602. tmp_stats[i++] =
  5603. (u64)le32_to_cpu(stat_info->tmac_data_octets_oflow) << 32 |
  5604. le32_to_cpu(stat_info->tmac_data_octets);
  5605. tmp_stats[i++] = le64_to_cpu(stat_info->tmac_drop_frms);
  5606. tmp_stats[i++] =
  5607. (u64)le32_to_cpu(stat_info->tmac_mcst_frms_oflow) << 32 |
  5608. le32_to_cpu(stat_info->tmac_mcst_frms);
  5609. tmp_stats[i++] =
  5610. (u64)le32_to_cpu(stat_info->tmac_bcst_frms_oflow) << 32 |
  5611. le32_to_cpu(stat_info->tmac_bcst_frms);
  5612. tmp_stats[i++] = le64_to_cpu(stat_info->tmac_pause_ctrl_frms);
  5613. tmp_stats[i++] =
  5614. (u64)le32_to_cpu(stat_info->tmac_ttl_octets_oflow) << 32 |
  5615. le32_to_cpu(stat_info->tmac_ttl_octets);
  5616. tmp_stats[i++] =
  5617. (u64)le32_to_cpu(stat_info->tmac_ucst_frms_oflow) << 32 |
  5618. le32_to_cpu(stat_info->tmac_ucst_frms);
  5619. tmp_stats[i++] =
  5620. (u64)le32_to_cpu(stat_info->tmac_nucst_frms_oflow) << 32 |
  5621. le32_to_cpu(stat_info->tmac_nucst_frms);
  5622. tmp_stats[i++] =
  5623. (u64)le32_to_cpu(stat_info->tmac_any_err_frms_oflow) << 32 |
  5624. le32_to_cpu(stat_info->tmac_any_err_frms);
  5625. tmp_stats[i++] = le64_to_cpu(stat_info->tmac_ttl_less_fb_octets);
  5626. tmp_stats[i++] = le64_to_cpu(stat_info->tmac_vld_ip_octets);
  5627. tmp_stats[i++] =
  5628. (u64)le32_to_cpu(stat_info->tmac_vld_ip_oflow) << 32 |
  5629. le32_to_cpu(stat_info->tmac_vld_ip);
  5630. tmp_stats[i++] =
  5631. (u64)le32_to_cpu(stat_info->tmac_drop_ip_oflow) << 32 |
  5632. le32_to_cpu(stat_info->tmac_drop_ip);
  5633. tmp_stats[i++] =
  5634. (u64)le32_to_cpu(stat_info->tmac_icmp_oflow) << 32 |
  5635. le32_to_cpu(stat_info->tmac_icmp);
  5636. tmp_stats[i++] =
  5637. (u64)le32_to_cpu(stat_info->tmac_rst_tcp_oflow) << 32 |
  5638. le32_to_cpu(stat_info->tmac_rst_tcp);
  5639. tmp_stats[i++] = le64_to_cpu(stat_info->tmac_tcp);
  5640. tmp_stats[i++] = (u64)le32_to_cpu(stat_info->tmac_udp_oflow) << 32 |
  5641. le32_to_cpu(stat_info->tmac_udp);
  5642. tmp_stats[i++] =
  5643. (u64)le32_to_cpu(stat_info->rmac_vld_frms_oflow) << 32 |
  5644. le32_to_cpu(stat_info->rmac_vld_frms);
  5645. tmp_stats[i++] =
  5646. (u64)le32_to_cpu(stat_info->rmac_data_octets_oflow) << 32 |
  5647. le32_to_cpu(stat_info->rmac_data_octets);
  5648. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_fcs_err_frms);
  5649. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_drop_frms);
  5650. tmp_stats[i++] =
  5651. (u64)le32_to_cpu(stat_info->rmac_vld_mcst_frms_oflow) << 32 |
  5652. le32_to_cpu(stat_info->rmac_vld_mcst_frms);
  5653. tmp_stats[i++] =
  5654. (u64)le32_to_cpu(stat_info->rmac_vld_bcst_frms_oflow) << 32 |
  5655. le32_to_cpu(stat_info->rmac_vld_bcst_frms);
  5656. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_in_rng_len_err_frms);
  5657. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_out_rng_len_err_frms);
  5658. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_long_frms);
  5659. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_pause_ctrl_frms);
  5660. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_unsup_ctrl_frms);
  5661. tmp_stats[i++] =
  5662. (u64)le32_to_cpu(stat_info->rmac_ttl_octets_oflow) << 32 |
  5663. le32_to_cpu(stat_info->rmac_ttl_octets);
  5664. tmp_stats[i++] =
  5665. (u64)le32_to_cpu(stat_info->rmac_accepted_ucst_frms_oflow)
  5666. << 32 | le32_to_cpu(stat_info->rmac_accepted_ucst_frms);
  5667. tmp_stats[i++] =
  5668. (u64)le32_to_cpu(stat_info->rmac_accepted_nucst_frms_oflow)
  5669. << 32 | le32_to_cpu(stat_info->rmac_accepted_nucst_frms);
  5670. tmp_stats[i++] =
  5671. (u64)le32_to_cpu(stat_info->rmac_discarded_frms_oflow) << 32 |
  5672. le32_to_cpu(stat_info->rmac_discarded_frms);
  5673. tmp_stats[i++] =
  5674. (u64)le32_to_cpu(stat_info->rmac_drop_events_oflow)
  5675. << 32 | le32_to_cpu(stat_info->rmac_drop_events);
  5676. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_less_fb_octets);
  5677. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_frms);
  5678. tmp_stats[i++] =
  5679. (u64)le32_to_cpu(stat_info->rmac_usized_frms_oflow) << 32 |
  5680. le32_to_cpu(stat_info->rmac_usized_frms);
  5681. tmp_stats[i++] =
  5682. (u64)le32_to_cpu(stat_info->rmac_osized_frms_oflow) << 32 |
  5683. le32_to_cpu(stat_info->rmac_osized_frms);
  5684. tmp_stats[i++] =
  5685. (u64)le32_to_cpu(stat_info->rmac_frag_frms_oflow) << 32 |
  5686. le32_to_cpu(stat_info->rmac_frag_frms);
  5687. tmp_stats[i++] =
  5688. (u64)le32_to_cpu(stat_info->rmac_jabber_frms_oflow) << 32 |
  5689. le32_to_cpu(stat_info->rmac_jabber_frms);
  5690. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_64_frms);
  5691. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_65_127_frms);
  5692. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_128_255_frms);
  5693. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_256_511_frms);
  5694. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_512_1023_frms);
  5695. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_1024_1518_frms);
  5696. tmp_stats[i++] =
  5697. (u64)le32_to_cpu(stat_info->rmac_ip_oflow) << 32 |
  5698. le32_to_cpu(stat_info->rmac_ip);
  5699. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ip_octets);
  5700. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_hdr_err_ip);
  5701. tmp_stats[i++] =
  5702. (u64)le32_to_cpu(stat_info->rmac_drop_ip_oflow) << 32 |
  5703. le32_to_cpu(stat_info->rmac_drop_ip);
  5704. tmp_stats[i++] =
  5705. (u64)le32_to_cpu(stat_info->rmac_icmp_oflow) << 32 |
  5706. le32_to_cpu(stat_info->rmac_icmp);
  5707. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_tcp);
  5708. tmp_stats[i++] =
  5709. (u64)le32_to_cpu(stat_info->rmac_udp_oflow) << 32 |
  5710. le32_to_cpu(stat_info->rmac_udp);
  5711. tmp_stats[i++] =
  5712. (u64)le32_to_cpu(stat_info->rmac_err_drp_udp_oflow) << 32 |
  5713. le32_to_cpu(stat_info->rmac_err_drp_udp);
  5714. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_xgmii_err_sym);
  5715. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q0);
  5716. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q1);
  5717. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q2);
  5718. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q3);
  5719. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q4);
  5720. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q5);
  5721. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q6);
  5722. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_frms_q7);
  5723. tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q0);
  5724. tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q1);
  5725. tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q2);
  5726. tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q3);
  5727. tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q4);
  5728. tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q5);
  5729. tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q6);
  5730. tmp_stats[i++] = le16_to_cpu(stat_info->rmac_full_q7);
  5731. tmp_stats[i++] =
  5732. (u64)le32_to_cpu(stat_info->rmac_pause_cnt_oflow) << 32 |
  5733. le32_to_cpu(stat_info->rmac_pause_cnt);
  5734. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_xgmii_data_err_cnt);
  5735. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_xgmii_ctrl_err_cnt);
  5736. tmp_stats[i++] =
  5737. (u64)le32_to_cpu(stat_info->rmac_accepted_ip_oflow) << 32 |
  5738. le32_to_cpu(stat_info->rmac_accepted_ip);
  5739. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_err_tcp);
  5740. tmp_stats[i++] = le32_to_cpu(stat_info->rd_req_cnt);
  5741. tmp_stats[i++] = le32_to_cpu(stat_info->new_rd_req_cnt);
  5742. tmp_stats[i++] = le32_to_cpu(stat_info->new_rd_req_rtry_cnt);
  5743. tmp_stats[i++] = le32_to_cpu(stat_info->rd_rtry_cnt);
  5744. tmp_stats[i++] = le32_to_cpu(stat_info->wr_rtry_rd_ack_cnt);
  5745. tmp_stats[i++] = le32_to_cpu(stat_info->wr_req_cnt);
  5746. tmp_stats[i++] = le32_to_cpu(stat_info->new_wr_req_cnt);
  5747. tmp_stats[i++] = le32_to_cpu(stat_info->new_wr_req_rtry_cnt);
  5748. tmp_stats[i++] = le32_to_cpu(stat_info->wr_rtry_cnt);
  5749. tmp_stats[i++] = le32_to_cpu(stat_info->wr_disc_cnt);
  5750. tmp_stats[i++] = le32_to_cpu(stat_info->rd_rtry_wr_ack_cnt);
  5751. tmp_stats[i++] = le32_to_cpu(stat_info->txp_wr_cnt);
  5752. tmp_stats[i++] = le32_to_cpu(stat_info->txd_rd_cnt);
  5753. tmp_stats[i++] = le32_to_cpu(stat_info->txd_wr_cnt);
  5754. tmp_stats[i++] = le32_to_cpu(stat_info->rxd_rd_cnt);
  5755. tmp_stats[i++] = le32_to_cpu(stat_info->rxd_wr_cnt);
  5756. tmp_stats[i++] = le32_to_cpu(stat_info->txf_rd_cnt);
  5757. tmp_stats[i++] = le32_to_cpu(stat_info->rxf_wr_cnt);
  5758. /* Enhanced statistics exist only for Hercules */
  5759. if(sp->device_type == XFRAME_II_DEVICE) {
  5760. tmp_stats[i++] =
  5761. le64_to_cpu(stat_info->rmac_ttl_1519_4095_frms);
  5762. tmp_stats[i++] =
  5763. le64_to_cpu(stat_info->rmac_ttl_4096_8191_frms);
  5764. tmp_stats[i++] =
  5765. le64_to_cpu(stat_info->rmac_ttl_8192_max_frms);
  5766. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_ttl_gt_max_frms);
  5767. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_osized_alt_frms);
  5768. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_jabber_alt_frms);
  5769. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_gt_max_alt_frms);
  5770. tmp_stats[i++] = le64_to_cpu(stat_info->rmac_vlan_frms);
  5771. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_len_discard);
  5772. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_fcs_discard);
  5773. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_pf_discard);
  5774. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_da_discard);
  5775. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_red_discard);
  5776. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_rts_discard);
  5777. tmp_stats[i++] = le32_to_cpu(stat_info->rmac_ingm_full_discard);
  5778. tmp_stats[i++] = le32_to_cpu(stat_info->link_fault_cnt);
  5779. }
  5780. tmp_stats[i++] = 0;
  5781. tmp_stats[i++] = stat_info->sw_stat.single_ecc_errs;
  5782. tmp_stats[i++] = stat_info->sw_stat.double_ecc_errs;
  5783. tmp_stats[i++] = stat_info->sw_stat.parity_err_cnt;
  5784. tmp_stats[i++] = stat_info->sw_stat.serious_err_cnt;
  5785. tmp_stats[i++] = stat_info->sw_stat.soft_reset_cnt;
  5786. tmp_stats[i++] = stat_info->sw_stat.fifo_full_cnt;
  5787. for (k = 0; k < MAX_RX_RINGS; k++)
  5788. tmp_stats[i++] = stat_info->sw_stat.ring_full_cnt[k];
  5789. tmp_stats[i++] = stat_info->xpak_stat.alarm_transceiver_temp_high;
  5790. tmp_stats[i++] = stat_info->xpak_stat.alarm_transceiver_temp_low;
  5791. tmp_stats[i++] = stat_info->xpak_stat.alarm_laser_bias_current_high;
  5792. tmp_stats[i++] = stat_info->xpak_stat.alarm_laser_bias_current_low;
  5793. tmp_stats[i++] = stat_info->xpak_stat.alarm_laser_output_power_high;
  5794. tmp_stats[i++] = stat_info->xpak_stat.alarm_laser_output_power_low;
  5795. tmp_stats[i++] = stat_info->xpak_stat.warn_transceiver_temp_high;
  5796. tmp_stats[i++] = stat_info->xpak_stat.warn_transceiver_temp_low;
  5797. tmp_stats[i++] = stat_info->xpak_stat.warn_laser_bias_current_high;
  5798. tmp_stats[i++] = stat_info->xpak_stat.warn_laser_bias_current_low;
  5799. tmp_stats[i++] = stat_info->xpak_stat.warn_laser_output_power_high;
  5800. tmp_stats[i++] = stat_info->xpak_stat.warn_laser_output_power_low;
  5801. tmp_stats[i++] = stat_info->sw_stat.clubbed_frms_cnt;
  5802. tmp_stats[i++] = stat_info->sw_stat.sending_both;
  5803. tmp_stats[i++] = stat_info->sw_stat.outof_sequence_pkts;
  5804. tmp_stats[i++] = stat_info->sw_stat.flush_max_pkts;
  5805. if (stat_info->sw_stat.num_aggregations) {
  5806. u64 tmp = stat_info->sw_stat.sum_avg_pkts_aggregated;
  5807. int count = 0;
  5808. /*
  5809. * Since 64-bit divide does not work on all platforms,
  5810. * do repeated subtraction.
  5811. */
  5812. while (tmp >= stat_info->sw_stat.num_aggregations) {
  5813. tmp -= stat_info->sw_stat.num_aggregations;
  5814. count++;
  5815. }
  5816. tmp_stats[i++] = count;
  5817. }
  5818. else
  5819. tmp_stats[i++] = 0;
  5820. tmp_stats[i++] = stat_info->sw_stat.mem_alloc_fail_cnt;
  5821. tmp_stats[i++] = stat_info->sw_stat.pci_map_fail_cnt;
  5822. tmp_stats[i++] = stat_info->sw_stat.watchdog_timer_cnt;
  5823. tmp_stats[i++] = stat_info->sw_stat.mem_allocated;
  5824. tmp_stats[i++] = stat_info->sw_stat.mem_freed;
  5825. tmp_stats[i++] = stat_info->sw_stat.link_up_cnt;
  5826. tmp_stats[i++] = stat_info->sw_stat.link_down_cnt;
  5827. tmp_stats[i++] = stat_info->sw_stat.link_up_time;
  5828. tmp_stats[i++] = stat_info->sw_stat.link_down_time;
  5829. tmp_stats[i++] = stat_info->sw_stat.tx_buf_abort_cnt;
  5830. tmp_stats[i++] = stat_info->sw_stat.tx_desc_abort_cnt;
  5831. tmp_stats[i++] = stat_info->sw_stat.tx_parity_err_cnt;
  5832. tmp_stats[i++] = stat_info->sw_stat.tx_link_loss_cnt;
  5833. tmp_stats[i++] = stat_info->sw_stat.tx_list_proc_err_cnt;
  5834. tmp_stats[i++] = stat_info->sw_stat.rx_parity_err_cnt;
  5835. tmp_stats[i++] = stat_info->sw_stat.rx_abort_cnt;
  5836. tmp_stats[i++] = stat_info->sw_stat.rx_parity_abort_cnt;
  5837. tmp_stats[i++] = stat_info->sw_stat.rx_rda_fail_cnt;
  5838. tmp_stats[i++] = stat_info->sw_stat.rx_unkn_prot_cnt;
  5839. tmp_stats[i++] = stat_info->sw_stat.rx_fcs_err_cnt;
  5840. tmp_stats[i++] = stat_info->sw_stat.rx_buf_size_err_cnt;
  5841. tmp_stats[i++] = stat_info->sw_stat.rx_rxd_corrupt_cnt;
  5842. tmp_stats[i++] = stat_info->sw_stat.rx_unkn_err_cnt;
  5843. tmp_stats[i++] = stat_info->sw_stat.tda_err_cnt;
  5844. tmp_stats[i++] = stat_info->sw_stat.pfc_err_cnt;
  5845. tmp_stats[i++] = stat_info->sw_stat.pcc_err_cnt;
  5846. tmp_stats[i++] = stat_info->sw_stat.tti_err_cnt;
  5847. tmp_stats[i++] = stat_info->sw_stat.tpa_err_cnt;
  5848. tmp_stats[i++] = stat_info->sw_stat.sm_err_cnt;
  5849. tmp_stats[i++] = stat_info->sw_stat.lso_err_cnt;
  5850. tmp_stats[i++] = stat_info->sw_stat.mac_tmac_err_cnt;
  5851. tmp_stats[i++] = stat_info->sw_stat.mac_rmac_err_cnt;
  5852. tmp_stats[i++] = stat_info->sw_stat.xgxs_txgxs_err_cnt;
  5853. tmp_stats[i++] = stat_info->sw_stat.xgxs_rxgxs_err_cnt;
  5854. tmp_stats[i++] = stat_info->sw_stat.rc_err_cnt;
  5855. tmp_stats[i++] = stat_info->sw_stat.prc_pcix_err_cnt;
  5856. tmp_stats[i++] = stat_info->sw_stat.rpa_err_cnt;
  5857. tmp_stats[i++] = stat_info->sw_stat.rda_err_cnt;
  5858. tmp_stats[i++] = stat_info->sw_stat.rti_err_cnt;
  5859. tmp_stats[i++] = stat_info->sw_stat.mc_err_cnt;
  5860. }
  5861. static int s2io_ethtool_get_regs_len(struct net_device *dev)
  5862. {
  5863. return (XENA_REG_SPACE);
  5864. }
  5865. static u32 s2io_ethtool_get_rx_csum(struct net_device * dev)
  5866. {
  5867. struct s2io_nic *sp = netdev_priv(dev);
  5868. return (sp->rx_csum);
  5869. }
  5870. static int s2io_ethtool_set_rx_csum(struct net_device *dev, u32 data)
  5871. {
  5872. struct s2io_nic *sp = netdev_priv(dev);
  5873. if (data)
  5874. sp->rx_csum = 1;
  5875. else
  5876. sp->rx_csum = 0;
  5877. return 0;
  5878. }
  5879. static int s2io_get_eeprom_len(struct net_device *dev)
  5880. {
  5881. return (XENA_EEPROM_SPACE);
  5882. }
  5883. static int s2io_get_sset_count(struct net_device *dev, int sset)
  5884. {
  5885. struct s2io_nic *sp = netdev_priv(dev);
  5886. switch (sset) {
  5887. case ETH_SS_TEST:
  5888. return S2IO_TEST_LEN;
  5889. case ETH_SS_STATS:
  5890. switch(sp->device_type) {
  5891. case XFRAME_I_DEVICE:
  5892. return XFRAME_I_STAT_LEN;
  5893. case XFRAME_II_DEVICE:
  5894. return XFRAME_II_STAT_LEN;
  5895. default:
  5896. return 0;
  5897. }
  5898. default:
  5899. return -EOPNOTSUPP;
  5900. }
  5901. }
  5902. static void s2io_ethtool_get_strings(struct net_device *dev,
  5903. u32 stringset, u8 * data)
  5904. {
  5905. int stat_size = 0;
  5906. struct s2io_nic *sp = netdev_priv(dev);
  5907. switch (stringset) {
  5908. case ETH_SS_TEST:
  5909. memcpy(data, s2io_gstrings, S2IO_STRINGS_LEN);
  5910. break;
  5911. case ETH_SS_STATS:
  5912. stat_size = sizeof(ethtool_xena_stats_keys);
  5913. memcpy(data, &ethtool_xena_stats_keys,stat_size);
  5914. if(sp->device_type == XFRAME_II_DEVICE) {
  5915. memcpy(data + stat_size,
  5916. &ethtool_enhanced_stats_keys,
  5917. sizeof(ethtool_enhanced_stats_keys));
  5918. stat_size += sizeof(ethtool_enhanced_stats_keys);
  5919. }
  5920. memcpy(data + stat_size, &ethtool_driver_stats_keys,
  5921. sizeof(ethtool_driver_stats_keys));
  5922. }
  5923. }
  5924. static int s2io_ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
  5925. {
  5926. if (data)
  5927. dev->features |= NETIF_F_IP_CSUM;
  5928. else
  5929. dev->features &= ~NETIF_F_IP_CSUM;
  5930. return 0;
  5931. }
  5932. static u32 s2io_ethtool_op_get_tso(struct net_device *dev)
  5933. {
  5934. return (dev->features & NETIF_F_TSO) != 0;
  5935. }
  5936. static int s2io_ethtool_op_set_tso(struct net_device *dev, u32 data)
  5937. {
  5938. if (data)
  5939. dev->features |= (NETIF_F_TSO | NETIF_F_TSO6);
  5940. else
  5941. dev->features &= ~(NETIF_F_TSO | NETIF_F_TSO6);
  5942. return 0;
  5943. }
  5944. static const struct ethtool_ops netdev_ethtool_ops = {
  5945. .get_settings = s2io_ethtool_gset,
  5946. .set_settings = s2io_ethtool_sset,
  5947. .get_drvinfo = s2io_ethtool_gdrvinfo,
  5948. .get_regs_len = s2io_ethtool_get_regs_len,
  5949. .get_regs = s2io_ethtool_gregs,
  5950. .get_link = ethtool_op_get_link,
  5951. .get_eeprom_len = s2io_get_eeprom_len,
  5952. .get_eeprom = s2io_ethtool_geeprom,
  5953. .set_eeprom = s2io_ethtool_seeprom,
  5954. .get_ringparam = s2io_ethtool_gringparam,
  5955. .get_pauseparam = s2io_ethtool_getpause_data,
  5956. .set_pauseparam = s2io_ethtool_setpause_data,
  5957. .get_rx_csum = s2io_ethtool_get_rx_csum,
  5958. .set_rx_csum = s2io_ethtool_set_rx_csum,
  5959. .set_tx_csum = s2io_ethtool_op_set_tx_csum,
  5960. .set_sg = ethtool_op_set_sg,
  5961. .get_tso = s2io_ethtool_op_get_tso,
  5962. .set_tso = s2io_ethtool_op_set_tso,
  5963. .set_ufo = ethtool_op_set_ufo,
  5964. .self_test = s2io_ethtool_test,
  5965. .get_strings = s2io_ethtool_get_strings,
  5966. .phys_id = s2io_ethtool_idnic,
  5967. .get_ethtool_stats = s2io_get_ethtool_stats,
  5968. .get_sset_count = s2io_get_sset_count,
  5969. };
  5970. /**
  5971. * s2io_ioctl - Entry point for the Ioctl
  5972. * @dev : Device pointer.
  5973. * @ifr : An IOCTL specefic structure, that can contain a pointer to
  5974. * a proprietary structure used to pass information to the driver.
  5975. * @cmd : This is used to distinguish between the different commands that
  5976. * can be passed to the IOCTL functions.
  5977. * Description:
  5978. * Currently there are no special functionality supported in IOCTL, hence
  5979. * function always return EOPNOTSUPPORTED
  5980. */
  5981. static int s2io_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
  5982. {
  5983. return -EOPNOTSUPP;
  5984. }
  5985. /**
  5986. * s2io_change_mtu - entry point to change MTU size for the device.
  5987. * @dev : device pointer.
  5988. * @new_mtu : the new MTU size for the device.
  5989. * Description: A driver entry point to change MTU size for the device.
  5990. * Before changing the MTU the device must be stopped.
  5991. * Return value:
  5992. * 0 on success and an appropriate (-)ve integer as defined in errno.h
  5993. * file on failure.
  5994. */
  5995. static int s2io_change_mtu(struct net_device *dev, int new_mtu)
  5996. {
  5997. struct s2io_nic *sp = netdev_priv(dev);
  5998. int ret = 0;
  5999. if ((new_mtu < MIN_MTU) || (new_mtu > S2IO_JUMBO_SIZE)) {
  6000. DBG_PRINT(ERR_DBG, "%s: MTU size is invalid.\n",
  6001. dev->name);
  6002. return -EPERM;
  6003. }
  6004. dev->mtu = new_mtu;
  6005. if (netif_running(dev)) {
  6006. s2io_stop_all_tx_queue(sp);
  6007. s2io_card_down(sp);
  6008. ret = s2io_card_up(sp);
  6009. if (ret) {
  6010. DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n",
  6011. __func__);
  6012. return ret;
  6013. }
  6014. s2io_wake_all_tx_queue(sp);
  6015. } else { /* Device is down */
  6016. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  6017. u64 val64 = new_mtu;
  6018. writeq(vBIT(val64, 2, 14), &bar0->rmac_max_pyld_len);
  6019. }
  6020. return ret;
  6021. }
  6022. /**
  6023. * s2io_set_link - Set the LInk status
  6024. * @data: long pointer to device private structue
  6025. * Description: Sets the link status for the adapter
  6026. */
  6027. static void s2io_set_link(struct work_struct *work)
  6028. {
  6029. struct s2io_nic *nic = container_of(work, struct s2io_nic, set_link_task);
  6030. struct net_device *dev = nic->dev;
  6031. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  6032. register u64 val64;
  6033. u16 subid;
  6034. rtnl_lock();
  6035. if (!netif_running(dev))
  6036. goto out_unlock;
  6037. if (test_and_set_bit(__S2IO_STATE_LINK_TASK, &(nic->state))) {
  6038. /* The card is being reset, no point doing anything */
  6039. goto out_unlock;
  6040. }
  6041. subid = nic->pdev->subsystem_device;
  6042. if (s2io_link_fault_indication(nic) == MAC_RMAC_ERR_TIMER) {
  6043. /*
  6044. * Allow a small delay for the NICs self initiated
  6045. * cleanup to complete.
  6046. */
  6047. msleep(100);
  6048. }
  6049. val64 = readq(&bar0->adapter_status);
  6050. if (LINK_IS_UP(val64)) {
  6051. if (!(readq(&bar0->adapter_control) & ADAPTER_CNTL_EN)) {
  6052. if (verify_xena_quiescence(nic)) {
  6053. val64 = readq(&bar0->adapter_control);
  6054. val64 |= ADAPTER_CNTL_EN;
  6055. writeq(val64, &bar0->adapter_control);
  6056. if (CARDS_WITH_FAULTY_LINK_INDICATORS(
  6057. nic->device_type, subid)) {
  6058. val64 = readq(&bar0->gpio_control);
  6059. val64 |= GPIO_CTRL_GPIO_0;
  6060. writeq(val64, &bar0->gpio_control);
  6061. val64 = readq(&bar0->gpio_control);
  6062. } else {
  6063. val64 |= ADAPTER_LED_ON;
  6064. writeq(val64, &bar0->adapter_control);
  6065. }
  6066. nic->device_enabled_once = TRUE;
  6067. } else {
  6068. DBG_PRINT(ERR_DBG, "%s: Error: ", dev->name);
  6069. DBG_PRINT(ERR_DBG, "device is not Quiescent\n");
  6070. s2io_stop_all_tx_queue(nic);
  6071. }
  6072. }
  6073. val64 = readq(&bar0->adapter_control);
  6074. val64 |= ADAPTER_LED_ON;
  6075. writeq(val64, &bar0->adapter_control);
  6076. s2io_link(nic, LINK_UP);
  6077. } else {
  6078. if (CARDS_WITH_FAULTY_LINK_INDICATORS(nic->device_type,
  6079. subid)) {
  6080. val64 = readq(&bar0->gpio_control);
  6081. val64 &= ~GPIO_CTRL_GPIO_0;
  6082. writeq(val64, &bar0->gpio_control);
  6083. val64 = readq(&bar0->gpio_control);
  6084. }
  6085. /* turn off LED */
  6086. val64 = readq(&bar0->adapter_control);
  6087. val64 = val64 &(~ADAPTER_LED_ON);
  6088. writeq(val64, &bar0->adapter_control);
  6089. s2io_link(nic, LINK_DOWN);
  6090. }
  6091. clear_bit(__S2IO_STATE_LINK_TASK, &(nic->state));
  6092. out_unlock:
  6093. rtnl_unlock();
  6094. }
  6095. static int set_rxd_buffer_pointer(struct s2io_nic *sp, struct RxD_t *rxdp,
  6096. struct buffAdd *ba,
  6097. struct sk_buff **skb, u64 *temp0, u64 *temp1,
  6098. u64 *temp2, int size)
  6099. {
  6100. struct net_device *dev = sp->dev;
  6101. struct swStat *stats = &sp->mac_control.stats_info->sw_stat;
  6102. if ((sp->rxd_mode == RXD_MODE_1) && (rxdp->Host_Control == 0)) {
  6103. struct RxD1 *rxdp1 = (struct RxD1 *)rxdp;
  6104. /* allocate skb */
  6105. if (*skb) {
  6106. DBG_PRINT(INFO_DBG, "SKB is not NULL\n");
  6107. /*
  6108. * As Rx frame are not going to be processed,
  6109. * using same mapped address for the Rxd
  6110. * buffer pointer
  6111. */
  6112. rxdp1->Buffer0_ptr = *temp0;
  6113. } else {
  6114. *skb = dev_alloc_skb(size);
  6115. if (!(*skb)) {
  6116. DBG_PRINT(INFO_DBG, "%s: Out of ", dev->name);
  6117. DBG_PRINT(INFO_DBG, "memory to allocate ");
  6118. DBG_PRINT(INFO_DBG, "1 buf mode SKBs\n");
  6119. sp->mac_control.stats_info->sw_stat. \
  6120. mem_alloc_fail_cnt++;
  6121. return -ENOMEM ;
  6122. }
  6123. sp->mac_control.stats_info->sw_stat.mem_allocated
  6124. += (*skb)->truesize;
  6125. /* storing the mapped addr in a temp variable
  6126. * such it will be used for next rxd whose
  6127. * Host Control is NULL
  6128. */
  6129. rxdp1->Buffer0_ptr = *temp0 =
  6130. pci_map_single( sp->pdev, (*skb)->data,
  6131. size - NET_IP_ALIGN,
  6132. PCI_DMA_FROMDEVICE);
  6133. if (pci_dma_mapping_error(sp->pdev, rxdp1->Buffer0_ptr))
  6134. goto memalloc_failed;
  6135. rxdp->Host_Control = (unsigned long) (*skb);
  6136. }
  6137. } else if ((sp->rxd_mode == RXD_MODE_3B) && (rxdp->Host_Control == 0)) {
  6138. struct RxD3 *rxdp3 = (struct RxD3 *)rxdp;
  6139. /* Two buffer Mode */
  6140. if (*skb) {
  6141. rxdp3->Buffer2_ptr = *temp2;
  6142. rxdp3->Buffer0_ptr = *temp0;
  6143. rxdp3->Buffer1_ptr = *temp1;
  6144. } else {
  6145. *skb = dev_alloc_skb(size);
  6146. if (!(*skb)) {
  6147. DBG_PRINT(INFO_DBG, "%s: Out of ", dev->name);
  6148. DBG_PRINT(INFO_DBG, "memory to allocate ");
  6149. DBG_PRINT(INFO_DBG, "2 buf mode SKBs\n");
  6150. sp->mac_control.stats_info->sw_stat. \
  6151. mem_alloc_fail_cnt++;
  6152. return -ENOMEM;
  6153. }
  6154. sp->mac_control.stats_info->sw_stat.mem_allocated
  6155. += (*skb)->truesize;
  6156. rxdp3->Buffer2_ptr = *temp2 =
  6157. pci_map_single(sp->pdev, (*skb)->data,
  6158. dev->mtu + 4,
  6159. PCI_DMA_FROMDEVICE);
  6160. if (pci_dma_mapping_error(sp->pdev, rxdp3->Buffer2_ptr))
  6161. goto memalloc_failed;
  6162. rxdp3->Buffer0_ptr = *temp0 =
  6163. pci_map_single( sp->pdev, ba->ba_0, BUF0_LEN,
  6164. PCI_DMA_FROMDEVICE);
  6165. if (pci_dma_mapping_error(sp->pdev,
  6166. rxdp3->Buffer0_ptr)) {
  6167. pci_unmap_single (sp->pdev,
  6168. (dma_addr_t)rxdp3->Buffer2_ptr,
  6169. dev->mtu + 4, PCI_DMA_FROMDEVICE);
  6170. goto memalloc_failed;
  6171. }
  6172. rxdp->Host_Control = (unsigned long) (*skb);
  6173. /* Buffer-1 will be dummy buffer not used */
  6174. rxdp3->Buffer1_ptr = *temp1 =
  6175. pci_map_single(sp->pdev, ba->ba_1, BUF1_LEN,
  6176. PCI_DMA_FROMDEVICE);
  6177. if (pci_dma_mapping_error(sp->pdev,
  6178. rxdp3->Buffer1_ptr)) {
  6179. pci_unmap_single (sp->pdev,
  6180. (dma_addr_t)rxdp3->Buffer0_ptr,
  6181. BUF0_LEN, PCI_DMA_FROMDEVICE);
  6182. pci_unmap_single (sp->pdev,
  6183. (dma_addr_t)rxdp3->Buffer2_ptr,
  6184. dev->mtu + 4, PCI_DMA_FROMDEVICE);
  6185. goto memalloc_failed;
  6186. }
  6187. }
  6188. }
  6189. return 0;
  6190. memalloc_failed:
  6191. stats->pci_map_fail_cnt++;
  6192. stats->mem_freed += (*skb)->truesize;
  6193. dev_kfree_skb(*skb);
  6194. return -ENOMEM;
  6195. }
  6196. static void set_rxd_buffer_size(struct s2io_nic *sp, struct RxD_t *rxdp,
  6197. int size)
  6198. {
  6199. struct net_device *dev = sp->dev;
  6200. if (sp->rxd_mode == RXD_MODE_1) {
  6201. rxdp->Control_2 = SET_BUFFER0_SIZE_1( size - NET_IP_ALIGN);
  6202. } else if (sp->rxd_mode == RXD_MODE_3B) {
  6203. rxdp->Control_2 = SET_BUFFER0_SIZE_3(BUF0_LEN);
  6204. rxdp->Control_2 |= SET_BUFFER1_SIZE_3(1);
  6205. rxdp->Control_2 |= SET_BUFFER2_SIZE_3( dev->mtu + 4);
  6206. }
  6207. }
  6208. static int rxd_owner_bit_reset(struct s2io_nic *sp)
  6209. {
  6210. int i, j, k, blk_cnt = 0, size;
  6211. struct mac_info * mac_control = &sp->mac_control;
  6212. struct config_param *config = &sp->config;
  6213. struct net_device *dev = sp->dev;
  6214. struct RxD_t *rxdp = NULL;
  6215. struct sk_buff *skb = NULL;
  6216. struct buffAdd *ba = NULL;
  6217. u64 temp0_64 = 0, temp1_64 = 0, temp2_64 = 0;
  6218. /* Calculate the size based on ring mode */
  6219. size = dev->mtu + HEADER_ETHERNET_II_802_3_SIZE +
  6220. HEADER_802_2_SIZE + HEADER_SNAP_SIZE;
  6221. if (sp->rxd_mode == RXD_MODE_1)
  6222. size += NET_IP_ALIGN;
  6223. else if (sp->rxd_mode == RXD_MODE_3B)
  6224. size = dev->mtu + ALIGN_SIZE + BUF0_LEN + 4;
  6225. for (i = 0; i < config->rx_ring_num; i++) {
  6226. blk_cnt = config->rx_cfg[i].num_rxd /
  6227. (rxd_count[sp->rxd_mode] +1);
  6228. for (j = 0; j < blk_cnt; j++) {
  6229. for (k = 0; k < rxd_count[sp->rxd_mode]; k++) {
  6230. rxdp = mac_control->rings[i].
  6231. rx_blocks[j].rxds[k].virt_addr;
  6232. if(sp->rxd_mode == RXD_MODE_3B)
  6233. ba = &mac_control->rings[i].ba[j][k];
  6234. if (set_rxd_buffer_pointer(sp, rxdp, ba,
  6235. &skb,(u64 *)&temp0_64,
  6236. (u64 *)&temp1_64,
  6237. (u64 *)&temp2_64,
  6238. size) == -ENOMEM) {
  6239. return 0;
  6240. }
  6241. set_rxd_buffer_size(sp, rxdp, size);
  6242. wmb();
  6243. /* flip the Ownership bit to Hardware */
  6244. rxdp->Control_1 |= RXD_OWN_XENA;
  6245. }
  6246. }
  6247. }
  6248. return 0;
  6249. }
  6250. static int s2io_add_isr(struct s2io_nic * sp)
  6251. {
  6252. int ret = 0;
  6253. struct net_device *dev = sp->dev;
  6254. int err = 0;
  6255. if (sp->config.intr_type == MSI_X)
  6256. ret = s2io_enable_msi_x(sp);
  6257. if (ret) {
  6258. DBG_PRINT(ERR_DBG, "%s: Defaulting to INTA\n", dev->name);
  6259. sp->config.intr_type = INTA;
  6260. }
  6261. /* Store the values of the MSIX table in the struct s2io_nic structure */
  6262. store_xmsi_data(sp);
  6263. /* After proper initialization of H/W, register ISR */
  6264. if (sp->config.intr_type == MSI_X) {
  6265. int i, msix_rx_cnt = 0;
  6266. for (i = 0; i < sp->num_entries; i++) {
  6267. if (sp->s2io_entries[i].in_use == MSIX_FLG) {
  6268. if (sp->s2io_entries[i].type ==
  6269. MSIX_RING_TYPE) {
  6270. sprintf(sp->desc[i], "%s:MSI-X-%d-RX",
  6271. dev->name, i);
  6272. err = request_irq(sp->entries[i].vector,
  6273. s2io_msix_ring_handle, 0,
  6274. sp->desc[i],
  6275. sp->s2io_entries[i].arg);
  6276. } else if (sp->s2io_entries[i].type ==
  6277. MSIX_ALARM_TYPE) {
  6278. sprintf(sp->desc[i], "%s:MSI-X-%d-TX",
  6279. dev->name, i);
  6280. err = request_irq(sp->entries[i].vector,
  6281. s2io_msix_fifo_handle, 0,
  6282. sp->desc[i],
  6283. sp->s2io_entries[i].arg);
  6284. }
  6285. /* if either data or addr is zero print it. */
  6286. if (!(sp->msix_info[i].addr &&
  6287. sp->msix_info[i].data)) {
  6288. DBG_PRINT(ERR_DBG,
  6289. "%s @Addr:0x%llx Data:0x%llx\n",
  6290. sp->desc[i],
  6291. (unsigned long long)
  6292. sp->msix_info[i].addr,
  6293. (unsigned long long)
  6294. ntohl(sp->msix_info[i].data));
  6295. } else
  6296. msix_rx_cnt++;
  6297. if (err) {
  6298. remove_msix_isr(sp);
  6299. DBG_PRINT(ERR_DBG,
  6300. "%s:MSI-X-%d registration "
  6301. "failed\n", dev->name, i);
  6302. DBG_PRINT(ERR_DBG,
  6303. "%s: Defaulting to INTA\n",
  6304. dev->name);
  6305. sp->config.intr_type = INTA;
  6306. break;
  6307. }
  6308. sp->s2io_entries[i].in_use =
  6309. MSIX_REGISTERED_SUCCESS;
  6310. }
  6311. }
  6312. if (!err) {
  6313. printk(KERN_INFO "MSI-X-RX %d entries enabled\n",
  6314. --msix_rx_cnt);
  6315. DBG_PRINT(INFO_DBG, "MSI-X-TX entries enabled"
  6316. " through alarm vector\n");
  6317. }
  6318. }
  6319. if (sp->config.intr_type == INTA) {
  6320. err = request_irq((int) sp->pdev->irq, s2io_isr, IRQF_SHARED,
  6321. sp->name, dev);
  6322. if (err) {
  6323. DBG_PRINT(ERR_DBG, "%s: ISR registration failed\n",
  6324. dev->name);
  6325. return -1;
  6326. }
  6327. }
  6328. return 0;
  6329. }
  6330. static void s2io_rem_isr(struct s2io_nic * sp)
  6331. {
  6332. if (sp->config.intr_type == MSI_X)
  6333. remove_msix_isr(sp);
  6334. else
  6335. remove_inta_isr(sp);
  6336. }
  6337. static void do_s2io_card_down(struct s2io_nic * sp, int do_io)
  6338. {
  6339. int cnt = 0;
  6340. struct XENA_dev_config __iomem *bar0 = sp->bar0;
  6341. register u64 val64 = 0;
  6342. struct config_param *config;
  6343. config = &sp->config;
  6344. if (!is_s2io_card_up(sp))
  6345. return;
  6346. del_timer_sync(&sp->alarm_timer);
  6347. /* If s2io_set_link task is executing, wait till it completes. */
  6348. while (test_and_set_bit(__S2IO_STATE_LINK_TASK, &(sp->state))) {
  6349. msleep(50);
  6350. }
  6351. clear_bit(__S2IO_STATE_CARD_UP, &sp->state);
  6352. /* Disable napi */
  6353. if (sp->config.napi) {
  6354. int off = 0;
  6355. if (config->intr_type == MSI_X) {
  6356. for (; off < sp->config.rx_ring_num; off++)
  6357. napi_disable(&sp->mac_control.rings[off].napi);
  6358. }
  6359. else
  6360. napi_disable(&sp->napi);
  6361. }
  6362. /* disable Tx and Rx traffic on the NIC */
  6363. if (do_io)
  6364. stop_nic(sp);
  6365. s2io_rem_isr(sp);
  6366. /* stop the tx queue, indicate link down */
  6367. s2io_link(sp, LINK_DOWN);
  6368. /* Check if the device is Quiescent and then Reset the NIC */
  6369. while(do_io) {
  6370. /* As per the HW requirement we need to replenish the
  6371. * receive buffer to avoid the ring bump. Since there is
  6372. * no intention of processing the Rx frame at this pointwe are
  6373. * just settting the ownership bit of rxd in Each Rx
  6374. * ring to HW and set the appropriate buffer size
  6375. * based on the ring mode
  6376. */
  6377. rxd_owner_bit_reset(sp);
  6378. val64 = readq(&bar0->adapter_status);
  6379. if (verify_xena_quiescence(sp)) {
  6380. if(verify_pcc_quiescent(sp, sp->device_enabled_once))
  6381. break;
  6382. }
  6383. msleep(50);
  6384. cnt++;
  6385. if (cnt == 10) {
  6386. DBG_PRINT(ERR_DBG,
  6387. "s2io_close:Device not Quiescent ");
  6388. DBG_PRINT(ERR_DBG, "adaper status reads 0x%llx\n",
  6389. (unsigned long long) val64);
  6390. break;
  6391. }
  6392. }
  6393. if (do_io)
  6394. s2io_reset(sp);
  6395. /* Free all Tx buffers */
  6396. free_tx_buffers(sp);
  6397. /* Free all Rx buffers */
  6398. free_rx_buffers(sp);
  6399. clear_bit(__S2IO_STATE_LINK_TASK, &(sp->state));
  6400. }
  6401. static void s2io_card_down(struct s2io_nic * sp)
  6402. {
  6403. do_s2io_card_down(sp, 1);
  6404. }
  6405. static int s2io_card_up(struct s2io_nic * sp)
  6406. {
  6407. int i, ret = 0;
  6408. struct mac_info *mac_control;
  6409. struct config_param *config;
  6410. struct net_device *dev = (struct net_device *) sp->dev;
  6411. u16 interruptible;
  6412. /* Initialize the H/W I/O registers */
  6413. ret = init_nic(sp);
  6414. if (ret != 0) {
  6415. DBG_PRINT(ERR_DBG, "%s: H/W initialization failed\n",
  6416. dev->name);
  6417. if (ret != -EIO)
  6418. s2io_reset(sp);
  6419. return ret;
  6420. }
  6421. /*
  6422. * Initializing the Rx buffers. For now we are considering only 1
  6423. * Rx ring and initializing buffers into 30 Rx blocks
  6424. */
  6425. mac_control = &sp->mac_control;
  6426. config = &sp->config;
  6427. for (i = 0; i < config->rx_ring_num; i++) {
  6428. mac_control->rings[i].mtu = dev->mtu;
  6429. ret = fill_rx_buffers(sp, &mac_control->rings[i], 1);
  6430. if (ret) {
  6431. DBG_PRINT(ERR_DBG, "%s: Out of memory in Open\n",
  6432. dev->name);
  6433. s2io_reset(sp);
  6434. free_rx_buffers(sp);
  6435. return -ENOMEM;
  6436. }
  6437. DBG_PRINT(INFO_DBG, "Buf in ring:%d is %d:\n", i,
  6438. mac_control->rings[i].rx_bufs_left);
  6439. }
  6440. /* Initialise napi */
  6441. if (config->napi) {
  6442. if (config->intr_type == MSI_X) {
  6443. for (i = 0; i < sp->config.rx_ring_num; i++)
  6444. napi_enable(&sp->mac_control.rings[i].napi);
  6445. } else {
  6446. napi_enable(&sp->napi);
  6447. }
  6448. }
  6449. /* Maintain the state prior to the open */
  6450. if (sp->promisc_flg)
  6451. sp->promisc_flg = 0;
  6452. if (sp->m_cast_flg) {
  6453. sp->m_cast_flg = 0;
  6454. sp->all_multi_pos= 0;
  6455. }
  6456. /* Setting its receive mode */
  6457. s2io_set_multicast(dev);
  6458. if (sp->lro) {
  6459. /* Initialize max aggregatable pkts per session based on MTU */
  6460. sp->lro_max_aggr_per_sess = ((1<<16) - 1) / dev->mtu;
  6461. /* Check if we can use(if specified) user provided value */
  6462. if (lro_max_pkts < sp->lro_max_aggr_per_sess)
  6463. sp->lro_max_aggr_per_sess = lro_max_pkts;
  6464. }
  6465. /* Enable Rx Traffic and interrupts on the NIC */
  6466. if (start_nic(sp)) {
  6467. DBG_PRINT(ERR_DBG, "%s: Starting NIC failed\n", dev->name);
  6468. s2io_reset(sp);
  6469. free_rx_buffers(sp);
  6470. return -ENODEV;
  6471. }
  6472. /* Add interrupt service routine */
  6473. if (s2io_add_isr(sp) != 0) {
  6474. if (sp->config.intr_type == MSI_X)
  6475. s2io_rem_isr(sp);
  6476. s2io_reset(sp);
  6477. free_rx_buffers(sp);
  6478. return -ENODEV;
  6479. }
  6480. S2IO_TIMER_CONF(sp->alarm_timer, s2io_alarm_handle, sp, (HZ/2));
  6481. set_bit(__S2IO_STATE_CARD_UP, &sp->state);
  6482. /* Enable select interrupts */
  6483. en_dis_err_alarms(sp, ENA_ALL_INTRS, ENABLE_INTRS);
  6484. if (sp->config.intr_type != INTA) {
  6485. interruptible = TX_TRAFFIC_INTR | TX_PIC_INTR;
  6486. en_dis_able_nic_intrs(sp, interruptible, ENABLE_INTRS);
  6487. } else {
  6488. interruptible = TX_TRAFFIC_INTR | RX_TRAFFIC_INTR;
  6489. interruptible |= TX_PIC_INTR;
  6490. en_dis_able_nic_intrs(sp, interruptible, ENABLE_INTRS);
  6491. }
  6492. return 0;
  6493. }
  6494. /**
  6495. * s2io_restart_nic - Resets the NIC.
  6496. * @data : long pointer to the device private structure
  6497. * Description:
  6498. * This function is scheduled to be run by the s2io_tx_watchdog
  6499. * function after 0.5 secs to reset the NIC. The idea is to reduce
  6500. * the run time of the watch dog routine which is run holding a
  6501. * spin lock.
  6502. */
  6503. static void s2io_restart_nic(struct work_struct *work)
  6504. {
  6505. struct s2io_nic *sp = container_of(work, struct s2io_nic, rst_timer_task);
  6506. struct net_device *dev = sp->dev;
  6507. rtnl_lock();
  6508. if (!netif_running(dev))
  6509. goto out_unlock;
  6510. s2io_card_down(sp);
  6511. if (s2io_card_up(sp)) {
  6512. DBG_PRINT(ERR_DBG, "%s: Device bring up failed\n",
  6513. dev->name);
  6514. }
  6515. s2io_wake_all_tx_queue(sp);
  6516. DBG_PRINT(ERR_DBG, "%s: was reset by Tx watchdog timer\n",
  6517. dev->name);
  6518. out_unlock:
  6519. rtnl_unlock();
  6520. }
  6521. /**
  6522. * s2io_tx_watchdog - Watchdog for transmit side.
  6523. * @dev : Pointer to net device structure
  6524. * Description:
  6525. * This function is triggered if the Tx Queue is stopped
  6526. * for a pre-defined amount of time when the Interface is still up.
  6527. * If the Interface is jammed in such a situation, the hardware is
  6528. * reset (by s2io_close) and restarted again (by s2io_open) to
  6529. * overcome any problem that might have been caused in the hardware.
  6530. * Return value:
  6531. * void
  6532. */
  6533. static void s2io_tx_watchdog(struct net_device *dev)
  6534. {
  6535. struct s2io_nic *sp = netdev_priv(dev);
  6536. if (netif_carrier_ok(dev)) {
  6537. sp->mac_control.stats_info->sw_stat.watchdog_timer_cnt++;
  6538. schedule_work(&sp->rst_timer_task);
  6539. sp->mac_control.stats_info->sw_stat.soft_reset_cnt++;
  6540. }
  6541. }
  6542. /**
  6543. * rx_osm_handler - To perform some OS related operations on SKB.
  6544. * @sp: private member of the device structure,pointer to s2io_nic structure.
  6545. * @skb : the socket buffer pointer.
  6546. * @len : length of the packet
  6547. * @cksum : FCS checksum of the frame.
  6548. * @ring_no : the ring from which this RxD was extracted.
  6549. * Description:
  6550. * This function is called by the Rx interrupt serivce routine to perform
  6551. * some OS related operations on the SKB before passing it to the upper
  6552. * layers. It mainly checks if the checksum is OK, if so adds it to the
  6553. * SKBs cksum variable, increments the Rx packet count and passes the SKB
  6554. * to the upper layer. If the checksum is wrong, it increments the Rx
  6555. * packet error count, frees the SKB and returns error.
  6556. * Return value:
  6557. * SUCCESS on success and -1 on failure.
  6558. */
  6559. static int rx_osm_handler(struct ring_info *ring_data, struct RxD_t * rxdp)
  6560. {
  6561. struct s2io_nic *sp = ring_data->nic;
  6562. struct net_device *dev = (struct net_device *) ring_data->dev;
  6563. struct sk_buff *skb = (struct sk_buff *)
  6564. ((unsigned long) rxdp->Host_Control);
  6565. int ring_no = ring_data->ring_no;
  6566. u16 l3_csum, l4_csum;
  6567. unsigned long long err = rxdp->Control_1 & RXD_T_CODE;
  6568. struct lro *uninitialized_var(lro);
  6569. u8 err_mask;
  6570. skb->dev = dev;
  6571. if (err) {
  6572. /* Check for parity error */
  6573. if (err & 0x1) {
  6574. sp->mac_control.stats_info->sw_stat.parity_err_cnt++;
  6575. }
  6576. err_mask = err >> 48;
  6577. switch(err_mask) {
  6578. case 1:
  6579. sp->mac_control.stats_info->sw_stat.
  6580. rx_parity_err_cnt++;
  6581. break;
  6582. case 2:
  6583. sp->mac_control.stats_info->sw_stat.
  6584. rx_abort_cnt++;
  6585. break;
  6586. case 3:
  6587. sp->mac_control.stats_info->sw_stat.
  6588. rx_parity_abort_cnt++;
  6589. break;
  6590. case 4:
  6591. sp->mac_control.stats_info->sw_stat.
  6592. rx_rda_fail_cnt++;
  6593. break;
  6594. case 5:
  6595. sp->mac_control.stats_info->sw_stat.
  6596. rx_unkn_prot_cnt++;
  6597. break;
  6598. case 6:
  6599. sp->mac_control.stats_info->sw_stat.
  6600. rx_fcs_err_cnt++;
  6601. break;
  6602. case 7:
  6603. sp->mac_control.stats_info->sw_stat.
  6604. rx_buf_size_err_cnt++;
  6605. break;
  6606. case 8:
  6607. sp->mac_control.stats_info->sw_stat.
  6608. rx_rxd_corrupt_cnt++;
  6609. break;
  6610. case 15:
  6611. sp->mac_control.stats_info->sw_stat.
  6612. rx_unkn_err_cnt++;
  6613. break;
  6614. }
  6615. /*
  6616. * Drop the packet if bad transfer code. Exception being
  6617. * 0x5, which could be due to unsupported IPv6 extension header.
  6618. * In this case, we let stack handle the packet.
  6619. * Note that in this case, since checksum will be incorrect,
  6620. * stack will validate the same.
  6621. */
  6622. if (err_mask != 0x5) {
  6623. DBG_PRINT(ERR_DBG, "%s: Rx error Value: 0x%x\n",
  6624. dev->name, err_mask);
  6625. dev->stats.rx_crc_errors++;
  6626. sp->mac_control.stats_info->sw_stat.mem_freed
  6627. += skb->truesize;
  6628. dev_kfree_skb(skb);
  6629. ring_data->rx_bufs_left -= 1;
  6630. rxdp->Host_Control = 0;
  6631. return 0;
  6632. }
  6633. }
  6634. /* Updating statistics */
  6635. ring_data->rx_packets++;
  6636. rxdp->Host_Control = 0;
  6637. if (sp->rxd_mode == RXD_MODE_1) {
  6638. int len = RXD_GET_BUFFER0_SIZE_1(rxdp->Control_2);
  6639. ring_data->rx_bytes += len;
  6640. skb_put(skb, len);
  6641. } else if (sp->rxd_mode == RXD_MODE_3B) {
  6642. int get_block = ring_data->rx_curr_get_info.block_index;
  6643. int get_off = ring_data->rx_curr_get_info.offset;
  6644. int buf0_len = RXD_GET_BUFFER0_SIZE_3(rxdp->Control_2);
  6645. int buf2_len = RXD_GET_BUFFER2_SIZE_3(rxdp->Control_2);
  6646. unsigned char *buff = skb_push(skb, buf0_len);
  6647. struct buffAdd *ba = &ring_data->ba[get_block][get_off];
  6648. ring_data->rx_bytes += buf0_len + buf2_len;
  6649. memcpy(buff, ba->ba_0, buf0_len);
  6650. skb_put(skb, buf2_len);
  6651. }
  6652. if ((rxdp->Control_1 & TCP_OR_UDP_FRAME) && ((!ring_data->lro) ||
  6653. (ring_data->lro && (!(rxdp->Control_1 & RXD_FRAME_IP_FRAG)))) &&
  6654. (sp->rx_csum)) {
  6655. l3_csum = RXD_GET_L3_CKSUM(rxdp->Control_1);
  6656. l4_csum = RXD_GET_L4_CKSUM(rxdp->Control_1);
  6657. if ((l3_csum == L3_CKSUM_OK) && (l4_csum == L4_CKSUM_OK)) {
  6658. /*
  6659. * NIC verifies if the Checksum of the received
  6660. * frame is Ok or not and accordingly returns
  6661. * a flag in the RxD.
  6662. */
  6663. skb->ip_summed = CHECKSUM_UNNECESSARY;
  6664. if (ring_data->lro) {
  6665. u32 tcp_len;
  6666. u8 *tcp;
  6667. int ret = 0;
  6668. ret = s2io_club_tcp_session(ring_data,
  6669. skb->data, &tcp, &tcp_len, &lro,
  6670. rxdp, sp);
  6671. switch (ret) {
  6672. case 3: /* Begin anew */
  6673. lro->parent = skb;
  6674. goto aggregate;
  6675. case 1: /* Aggregate */
  6676. {
  6677. lro_append_pkt(sp, lro,
  6678. skb, tcp_len);
  6679. goto aggregate;
  6680. }
  6681. case 4: /* Flush session */
  6682. {
  6683. lro_append_pkt(sp, lro,
  6684. skb, tcp_len);
  6685. queue_rx_frame(lro->parent,
  6686. lro->vlan_tag);
  6687. clear_lro_session(lro);
  6688. sp->mac_control.stats_info->
  6689. sw_stat.flush_max_pkts++;
  6690. goto aggregate;
  6691. }
  6692. case 2: /* Flush both */
  6693. lro->parent->data_len =
  6694. lro->frags_len;
  6695. sp->mac_control.stats_info->
  6696. sw_stat.sending_both++;
  6697. queue_rx_frame(lro->parent,
  6698. lro->vlan_tag);
  6699. clear_lro_session(lro);
  6700. goto send_up;
  6701. case 0: /* sessions exceeded */
  6702. case -1: /* non-TCP or not
  6703. * L2 aggregatable
  6704. */
  6705. case 5: /*
  6706. * First pkt in session not
  6707. * L3/L4 aggregatable
  6708. */
  6709. break;
  6710. default:
  6711. DBG_PRINT(ERR_DBG,
  6712. "%s: Samadhana!!\n",
  6713. __func__);
  6714. BUG();
  6715. }
  6716. }
  6717. } else {
  6718. /*
  6719. * Packet with erroneous checksum, let the
  6720. * upper layers deal with it.
  6721. */
  6722. skb->ip_summed = CHECKSUM_NONE;
  6723. }
  6724. } else
  6725. skb->ip_summed = CHECKSUM_NONE;
  6726. sp->mac_control.stats_info->sw_stat.mem_freed += skb->truesize;
  6727. send_up:
  6728. skb_record_rx_queue(skb, ring_no);
  6729. queue_rx_frame(skb, RXD_GET_VLAN_TAG(rxdp->Control_2));
  6730. aggregate:
  6731. sp->mac_control.rings[ring_no].rx_bufs_left -= 1;
  6732. return SUCCESS;
  6733. }
  6734. /**
  6735. * s2io_link - stops/starts the Tx queue.
  6736. * @sp : private member of the device structure, which is a pointer to the
  6737. * s2io_nic structure.
  6738. * @link : inidicates whether link is UP/DOWN.
  6739. * Description:
  6740. * This function stops/starts the Tx queue depending on whether the link
  6741. * status of the NIC is is down or up. This is called by the Alarm
  6742. * interrupt handler whenever a link change interrupt comes up.
  6743. * Return value:
  6744. * void.
  6745. */
  6746. static void s2io_link(struct s2io_nic * sp, int link)
  6747. {
  6748. struct net_device *dev = (struct net_device *) sp->dev;
  6749. if (link != sp->last_link_state) {
  6750. init_tti(sp, link);
  6751. if (link == LINK_DOWN) {
  6752. DBG_PRINT(ERR_DBG, "%s: Link down\n", dev->name);
  6753. s2io_stop_all_tx_queue(sp);
  6754. netif_carrier_off(dev);
  6755. if(sp->mac_control.stats_info->sw_stat.link_up_cnt)
  6756. sp->mac_control.stats_info->sw_stat.link_up_time =
  6757. jiffies - sp->start_time;
  6758. sp->mac_control.stats_info->sw_stat.link_down_cnt++;
  6759. } else {
  6760. DBG_PRINT(ERR_DBG, "%s: Link Up\n", dev->name);
  6761. if (sp->mac_control.stats_info->sw_stat.link_down_cnt)
  6762. sp->mac_control.stats_info->sw_stat.link_down_time =
  6763. jiffies - sp->start_time;
  6764. sp->mac_control.stats_info->sw_stat.link_up_cnt++;
  6765. netif_carrier_on(dev);
  6766. s2io_wake_all_tx_queue(sp);
  6767. }
  6768. }
  6769. sp->last_link_state = link;
  6770. sp->start_time = jiffies;
  6771. }
  6772. /**
  6773. * s2io_init_pci -Initialization of PCI and PCI-X configuration registers .
  6774. * @sp : private member of the device structure, which is a pointer to the
  6775. * s2io_nic structure.
  6776. * Description:
  6777. * This function initializes a few of the PCI and PCI-X configuration registers
  6778. * with recommended values.
  6779. * Return value:
  6780. * void
  6781. */
  6782. static void s2io_init_pci(struct s2io_nic * sp)
  6783. {
  6784. u16 pci_cmd = 0, pcix_cmd = 0;
  6785. /* Enable Data Parity Error Recovery in PCI-X command register. */
  6786. pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  6787. &(pcix_cmd));
  6788. pci_write_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  6789. (pcix_cmd | 1));
  6790. pci_read_config_word(sp->pdev, PCIX_COMMAND_REGISTER,
  6791. &(pcix_cmd));
  6792. /* Set the PErr Response bit in PCI command register. */
  6793. pci_read_config_word(sp->pdev, PCI_COMMAND, &pci_cmd);
  6794. pci_write_config_word(sp->pdev, PCI_COMMAND,
  6795. (pci_cmd | PCI_COMMAND_PARITY));
  6796. pci_read_config_word(sp->pdev, PCI_COMMAND, &pci_cmd);
  6797. }
  6798. static int s2io_verify_parm(struct pci_dev *pdev, u8 *dev_intr_type,
  6799. u8 *dev_multiq)
  6800. {
  6801. if ((tx_fifo_num > MAX_TX_FIFOS) ||
  6802. (tx_fifo_num < 1)) {
  6803. DBG_PRINT(ERR_DBG, "s2io: Requested number of tx fifos "
  6804. "(%d) not supported\n", tx_fifo_num);
  6805. if (tx_fifo_num < 1)
  6806. tx_fifo_num = 1;
  6807. else
  6808. tx_fifo_num = MAX_TX_FIFOS;
  6809. DBG_PRINT(ERR_DBG, "s2io: Default to %d ", tx_fifo_num);
  6810. DBG_PRINT(ERR_DBG, "tx fifos\n");
  6811. }
  6812. if (multiq)
  6813. *dev_multiq = multiq;
  6814. if (tx_steering_type && (1 == tx_fifo_num)) {
  6815. if (tx_steering_type != TX_DEFAULT_STEERING)
  6816. DBG_PRINT(ERR_DBG,
  6817. "s2io: Tx steering is not supported with "
  6818. "one fifo. Disabling Tx steering.\n");
  6819. tx_steering_type = NO_STEERING;
  6820. }
  6821. if ((tx_steering_type < NO_STEERING) ||
  6822. (tx_steering_type > TX_DEFAULT_STEERING)) {
  6823. DBG_PRINT(ERR_DBG, "s2io: Requested transmit steering not "
  6824. "supported\n");
  6825. DBG_PRINT(ERR_DBG, "s2io: Disabling transmit steering\n");
  6826. tx_steering_type = NO_STEERING;
  6827. }
  6828. if (rx_ring_num > MAX_RX_RINGS) {
  6829. DBG_PRINT(ERR_DBG, "s2io: Requested number of rx rings not "
  6830. "supported\n");
  6831. DBG_PRINT(ERR_DBG, "s2io: Default to %d rx rings\n",
  6832. MAX_RX_RINGS);
  6833. rx_ring_num = MAX_RX_RINGS;
  6834. }
  6835. if ((*dev_intr_type != INTA) && (*dev_intr_type != MSI_X)) {
  6836. DBG_PRINT(ERR_DBG, "s2io: Wrong intr_type requested. "
  6837. "Defaulting to INTA\n");
  6838. *dev_intr_type = INTA;
  6839. }
  6840. if ((*dev_intr_type == MSI_X) &&
  6841. ((pdev->device != PCI_DEVICE_ID_HERC_WIN) &&
  6842. (pdev->device != PCI_DEVICE_ID_HERC_UNI))) {
  6843. DBG_PRINT(ERR_DBG, "s2io: Xframe I does not support MSI_X. "
  6844. "Defaulting to INTA\n");
  6845. *dev_intr_type = INTA;
  6846. }
  6847. if ((rx_ring_mode != 1) && (rx_ring_mode != 2)) {
  6848. DBG_PRINT(ERR_DBG, "s2io: Requested ring mode not supported\n");
  6849. DBG_PRINT(ERR_DBG, "s2io: Defaulting to 1-buffer mode\n");
  6850. rx_ring_mode = 1;
  6851. }
  6852. return SUCCESS;
  6853. }
  6854. /**
  6855. * rts_ds_steer - Receive traffic steering based on IPv4 or IPv6 TOS
  6856. * or Traffic class respectively.
  6857. * @nic: device private variable
  6858. * Description: The function configures the receive steering to
  6859. * desired receive ring.
  6860. * Return Value: SUCCESS on success and
  6861. * '-1' on failure (endian settings incorrect).
  6862. */
  6863. static int rts_ds_steer(struct s2io_nic *nic, u8 ds_codepoint, u8 ring)
  6864. {
  6865. struct XENA_dev_config __iomem *bar0 = nic->bar0;
  6866. register u64 val64 = 0;
  6867. if (ds_codepoint > 63)
  6868. return FAILURE;
  6869. val64 = RTS_DS_MEM_DATA(ring);
  6870. writeq(val64, &bar0->rts_ds_mem_data);
  6871. val64 = RTS_DS_MEM_CTRL_WE |
  6872. RTS_DS_MEM_CTRL_STROBE_NEW_CMD |
  6873. RTS_DS_MEM_CTRL_OFFSET(ds_codepoint);
  6874. writeq(val64, &bar0->rts_ds_mem_ctrl);
  6875. return wait_for_cmd_complete(&bar0->rts_ds_mem_ctrl,
  6876. RTS_DS_MEM_CTRL_STROBE_CMD_BEING_EXECUTED,
  6877. S2IO_BIT_RESET);
  6878. }
  6879. static const struct net_device_ops s2io_netdev_ops = {
  6880. .ndo_open = s2io_open,
  6881. .ndo_stop = s2io_close,
  6882. .ndo_get_stats = s2io_get_stats,
  6883. .ndo_start_xmit = s2io_xmit,
  6884. .ndo_validate_addr = eth_validate_addr,
  6885. .ndo_set_multicast_list = s2io_set_multicast,
  6886. .ndo_do_ioctl = s2io_ioctl,
  6887. .ndo_set_mac_address = s2io_set_mac_addr,
  6888. .ndo_change_mtu = s2io_change_mtu,
  6889. .ndo_vlan_rx_register = s2io_vlan_rx_register,
  6890. .ndo_vlan_rx_kill_vid = s2io_vlan_rx_kill_vid,
  6891. .ndo_tx_timeout = s2io_tx_watchdog,
  6892. #ifdef CONFIG_NET_POLL_CONTROLLER
  6893. .ndo_poll_controller = s2io_netpoll,
  6894. #endif
  6895. };
  6896. /**
  6897. * s2io_init_nic - Initialization of the adapter .
  6898. * @pdev : structure containing the PCI related information of the device.
  6899. * @pre: List of PCI devices supported by the driver listed in s2io_tbl.
  6900. * Description:
  6901. * The function initializes an adapter identified by the pci_dec structure.
  6902. * All OS related initialization including memory and device structure and
  6903. * initlaization of the device private variable is done. Also the swapper
  6904. * control register is initialized to enable read and write into the I/O
  6905. * registers of the device.
  6906. * Return value:
  6907. * returns 0 on success and negative on failure.
  6908. */
  6909. static int __devinit
  6910. s2io_init_nic(struct pci_dev *pdev, const struct pci_device_id *pre)
  6911. {
  6912. struct s2io_nic *sp;
  6913. struct net_device *dev;
  6914. int i, j, ret;
  6915. int dma_flag = FALSE;
  6916. u32 mac_up, mac_down;
  6917. u64 val64 = 0, tmp64 = 0;
  6918. struct XENA_dev_config __iomem *bar0 = NULL;
  6919. u16 subid;
  6920. struct mac_info *mac_control;
  6921. struct config_param *config;
  6922. int mode;
  6923. u8 dev_intr_type = intr_type;
  6924. u8 dev_multiq = 0;
  6925. ret = s2io_verify_parm(pdev, &dev_intr_type, &dev_multiq);
  6926. if (ret)
  6927. return ret;
  6928. if ((ret = pci_enable_device(pdev))) {
  6929. DBG_PRINT(ERR_DBG,
  6930. "s2io_init_nic: pci_enable_device failed\n");
  6931. return ret;
  6932. }
  6933. if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) {
  6934. DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 64bit DMA\n");
  6935. dma_flag = TRUE;
  6936. if (pci_set_consistent_dma_mask
  6937. (pdev, DMA_BIT_MASK(64))) {
  6938. DBG_PRINT(ERR_DBG,
  6939. "Unable to obtain 64bit DMA for \
  6940. consistent allocations\n");
  6941. pci_disable_device(pdev);
  6942. return -ENOMEM;
  6943. }
  6944. } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) {
  6945. DBG_PRINT(INIT_DBG, "s2io_init_nic: Using 32bit DMA\n");
  6946. } else {
  6947. pci_disable_device(pdev);
  6948. return -ENOMEM;
  6949. }
  6950. if ((ret = pci_request_regions(pdev, s2io_driver_name))) {
  6951. DBG_PRINT(ERR_DBG, "%s: Request Regions failed - %x \n", __func__, ret);
  6952. pci_disable_device(pdev);
  6953. return -ENODEV;
  6954. }
  6955. if (dev_multiq)
  6956. dev = alloc_etherdev_mq(sizeof(struct s2io_nic), tx_fifo_num);
  6957. else
  6958. dev = alloc_etherdev(sizeof(struct s2io_nic));
  6959. if (dev == NULL) {
  6960. DBG_PRINT(ERR_DBG, "Device allocation failed\n");
  6961. pci_disable_device(pdev);
  6962. pci_release_regions(pdev);
  6963. return -ENODEV;
  6964. }
  6965. pci_set_master(pdev);
  6966. pci_set_drvdata(pdev, dev);
  6967. SET_NETDEV_DEV(dev, &pdev->dev);
  6968. /* Private member variable initialized to s2io NIC structure */
  6969. sp = netdev_priv(dev);
  6970. memset(sp, 0, sizeof(struct s2io_nic));
  6971. sp->dev = dev;
  6972. sp->pdev = pdev;
  6973. sp->high_dma_flag = dma_flag;
  6974. sp->device_enabled_once = FALSE;
  6975. if (rx_ring_mode == 1)
  6976. sp->rxd_mode = RXD_MODE_1;
  6977. if (rx_ring_mode == 2)
  6978. sp->rxd_mode = RXD_MODE_3B;
  6979. sp->config.intr_type = dev_intr_type;
  6980. if ((pdev->device == PCI_DEVICE_ID_HERC_WIN) ||
  6981. (pdev->device == PCI_DEVICE_ID_HERC_UNI))
  6982. sp->device_type = XFRAME_II_DEVICE;
  6983. else
  6984. sp->device_type = XFRAME_I_DEVICE;
  6985. sp->lro = lro_enable;
  6986. /* Initialize some PCI/PCI-X fields of the NIC. */
  6987. s2io_init_pci(sp);
  6988. /*
  6989. * Setting the device configuration parameters.
  6990. * Most of these parameters can be specified by the user during
  6991. * module insertion as they are module loadable parameters. If
  6992. * these parameters are not not specified during load time, they
  6993. * are initialized with default values.
  6994. */
  6995. mac_control = &sp->mac_control;
  6996. config = &sp->config;
  6997. config->napi = napi;
  6998. config->tx_steering_type = tx_steering_type;
  6999. /* Tx side parameters. */
  7000. if (config->tx_steering_type == TX_PRIORITY_STEERING)
  7001. config->tx_fifo_num = MAX_TX_FIFOS;
  7002. else
  7003. config->tx_fifo_num = tx_fifo_num;
  7004. /* Initialize the fifos used for tx steering */
  7005. if (config->tx_fifo_num < 5) {
  7006. if (config->tx_fifo_num == 1)
  7007. sp->total_tcp_fifos = 1;
  7008. else
  7009. sp->total_tcp_fifos = config->tx_fifo_num - 1;
  7010. sp->udp_fifo_idx = config->tx_fifo_num - 1;
  7011. sp->total_udp_fifos = 1;
  7012. sp->other_fifo_idx = sp->total_tcp_fifos - 1;
  7013. } else {
  7014. sp->total_tcp_fifos = (tx_fifo_num - FIFO_UDP_MAX_NUM -
  7015. FIFO_OTHER_MAX_NUM);
  7016. sp->udp_fifo_idx = sp->total_tcp_fifos;
  7017. sp->total_udp_fifos = FIFO_UDP_MAX_NUM;
  7018. sp->other_fifo_idx = sp->udp_fifo_idx + FIFO_UDP_MAX_NUM;
  7019. }
  7020. config->multiq = dev_multiq;
  7021. for (i = 0; i < config->tx_fifo_num; i++) {
  7022. config->tx_cfg[i].fifo_len = tx_fifo_len[i];
  7023. config->tx_cfg[i].fifo_priority = i;
  7024. }
  7025. /* mapping the QoS priority to the configured fifos */
  7026. for (i = 0; i < MAX_TX_FIFOS; i++)
  7027. config->fifo_mapping[i] = fifo_map[config->tx_fifo_num - 1][i];
  7028. /* map the hashing selector table to the configured fifos */
  7029. for (i = 0; i < config->tx_fifo_num; i++)
  7030. sp->fifo_selector[i] = fifo_selector[i];
  7031. config->tx_intr_type = TXD_INT_TYPE_UTILZ;
  7032. for (i = 0; i < config->tx_fifo_num; i++) {
  7033. config->tx_cfg[i].f_no_snoop =
  7034. (NO_SNOOP_TXD | NO_SNOOP_TXD_BUFFER);
  7035. if (config->tx_cfg[i].fifo_len < 65) {
  7036. config->tx_intr_type = TXD_INT_TYPE_PER_LIST;
  7037. break;
  7038. }
  7039. }
  7040. /* + 2 because one Txd for skb->data and one Txd for UFO */
  7041. config->max_txds = MAX_SKB_FRAGS + 2;
  7042. /* Rx side parameters. */
  7043. config->rx_ring_num = rx_ring_num;
  7044. for (i = 0; i < config->rx_ring_num; i++) {
  7045. config->rx_cfg[i].num_rxd = rx_ring_sz[i] *
  7046. (rxd_count[sp->rxd_mode] + 1);
  7047. config->rx_cfg[i].ring_priority = i;
  7048. mac_control->rings[i].rx_bufs_left = 0;
  7049. mac_control->rings[i].rxd_mode = sp->rxd_mode;
  7050. mac_control->rings[i].rxd_count = rxd_count[sp->rxd_mode];
  7051. mac_control->rings[i].pdev = sp->pdev;
  7052. mac_control->rings[i].dev = sp->dev;
  7053. }
  7054. for (i = 0; i < rx_ring_num; i++) {
  7055. config->rx_cfg[i].ring_org = RING_ORG_BUFF1;
  7056. config->rx_cfg[i].f_no_snoop =
  7057. (NO_SNOOP_RXD | NO_SNOOP_RXD_BUFFER);
  7058. }
  7059. /* Setting Mac Control parameters */
  7060. mac_control->rmac_pause_time = rmac_pause_time;
  7061. mac_control->mc_pause_threshold_q0q3 = mc_pause_threshold_q0q3;
  7062. mac_control->mc_pause_threshold_q4q7 = mc_pause_threshold_q4q7;
  7063. /* initialize the shared memory used by the NIC and the host */
  7064. if (init_shared_mem(sp)) {
  7065. DBG_PRINT(ERR_DBG, "%s: Memory allocation failed\n",
  7066. dev->name);
  7067. ret = -ENOMEM;
  7068. goto mem_alloc_failed;
  7069. }
  7070. sp->bar0 = pci_ioremap_bar(pdev, 0);
  7071. if (!sp->bar0) {
  7072. DBG_PRINT(ERR_DBG, "%s: Neterion: cannot remap io mem1\n",
  7073. dev->name);
  7074. ret = -ENOMEM;
  7075. goto bar0_remap_failed;
  7076. }
  7077. sp->bar1 = pci_ioremap_bar(pdev, 2);
  7078. if (!sp->bar1) {
  7079. DBG_PRINT(ERR_DBG, "%s: Neterion: cannot remap io mem2\n",
  7080. dev->name);
  7081. ret = -ENOMEM;
  7082. goto bar1_remap_failed;
  7083. }
  7084. dev->irq = pdev->irq;
  7085. dev->base_addr = (unsigned long) sp->bar0;
  7086. /* Initializing the BAR1 address as the start of the FIFO pointer. */
  7087. for (j = 0; j < MAX_TX_FIFOS; j++) {
  7088. mac_control->tx_FIFO_start[j] = (struct TxFIFO_element __iomem *)
  7089. (sp->bar1 + (j * 0x00020000));
  7090. }
  7091. /* Driver entry points */
  7092. dev->netdev_ops = &s2io_netdev_ops;
  7093. SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops);
  7094. dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX;
  7095. dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
  7096. if (sp->high_dma_flag == TRUE)
  7097. dev->features |= NETIF_F_HIGHDMA;
  7098. dev->features |= NETIF_F_TSO;
  7099. dev->features |= NETIF_F_TSO6;
  7100. if ((sp->device_type & XFRAME_II_DEVICE) && (ufo)) {
  7101. dev->features |= NETIF_F_UFO;
  7102. dev->features |= NETIF_F_HW_CSUM;
  7103. }
  7104. dev->watchdog_timeo = WATCH_DOG_TIMEOUT;
  7105. INIT_WORK(&sp->rst_timer_task, s2io_restart_nic);
  7106. INIT_WORK(&sp->set_link_task, s2io_set_link);
  7107. pci_save_state(sp->pdev);
  7108. /* Setting swapper control on the NIC, for proper reset operation */
  7109. if (s2io_set_swapper(sp)) {
  7110. DBG_PRINT(ERR_DBG, "%s:swapper settings are wrong\n",
  7111. dev->name);
  7112. ret = -EAGAIN;
  7113. goto set_swap_failed;
  7114. }
  7115. /* Verify if the Herc works on the slot its placed into */
  7116. if (sp->device_type & XFRAME_II_DEVICE) {
  7117. mode = s2io_verify_pci_mode(sp);
  7118. if (mode < 0) {
  7119. DBG_PRINT(ERR_DBG, "%s: ", __func__);
  7120. DBG_PRINT(ERR_DBG, " Unsupported PCI bus mode\n");
  7121. ret = -EBADSLT;
  7122. goto set_swap_failed;
  7123. }
  7124. }
  7125. if (sp->config.intr_type == MSI_X) {
  7126. sp->num_entries = config->rx_ring_num + 1;
  7127. ret = s2io_enable_msi_x(sp);
  7128. if (!ret) {
  7129. ret = s2io_test_msi(sp);
  7130. /* rollback MSI-X, will re-enable during add_isr() */
  7131. remove_msix_isr(sp);
  7132. }
  7133. if (ret) {
  7134. DBG_PRINT(ERR_DBG,
  7135. "s2io: MSI-X requested but failed to enable\n");
  7136. sp->config.intr_type = INTA;
  7137. }
  7138. }
  7139. if (config->intr_type == MSI_X) {
  7140. for (i = 0; i < config->rx_ring_num ; i++)
  7141. netif_napi_add(dev, &mac_control->rings[i].napi,
  7142. s2io_poll_msix, 64);
  7143. } else {
  7144. netif_napi_add(dev, &sp->napi, s2io_poll_inta, 64);
  7145. }
  7146. /* Not needed for Herc */
  7147. if (sp->device_type & XFRAME_I_DEVICE) {
  7148. /*
  7149. * Fix for all "FFs" MAC address problems observed on
  7150. * Alpha platforms
  7151. */
  7152. fix_mac_address(sp);
  7153. s2io_reset(sp);
  7154. }
  7155. /*
  7156. * MAC address initialization.
  7157. * For now only one mac address will be read and used.
  7158. */
  7159. bar0 = sp->bar0;
  7160. val64 = RMAC_ADDR_CMD_MEM_RD | RMAC_ADDR_CMD_MEM_STROBE_NEW_CMD |
  7161. RMAC_ADDR_CMD_MEM_OFFSET(0 + S2IO_MAC_ADDR_START_OFFSET);
  7162. writeq(val64, &bar0->rmac_addr_cmd_mem);
  7163. wait_for_cmd_complete(&bar0->rmac_addr_cmd_mem,
  7164. RMAC_ADDR_CMD_MEM_STROBE_CMD_EXECUTING, S2IO_BIT_RESET);
  7165. tmp64 = readq(&bar0->rmac_addr_data0_mem);
  7166. mac_down = (u32) tmp64;
  7167. mac_up = (u32) (tmp64 >> 32);
  7168. sp->def_mac_addr[0].mac_addr[3] = (u8) (mac_up);
  7169. sp->def_mac_addr[0].mac_addr[2] = (u8) (mac_up >> 8);
  7170. sp->def_mac_addr[0].mac_addr[1] = (u8) (mac_up >> 16);
  7171. sp->def_mac_addr[0].mac_addr[0] = (u8) (mac_up >> 24);
  7172. sp->def_mac_addr[0].mac_addr[5] = (u8) (mac_down >> 16);
  7173. sp->def_mac_addr[0].mac_addr[4] = (u8) (mac_down >> 24);
  7174. /* Set the factory defined MAC address initially */
  7175. dev->addr_len = ETH_ALEN;
  7176. memcpy(dev->dev_addr, sp->def_mac_addr, ETH_ALEN);
  7177. memcpy(dev->perm_addr, dev->dev_addr, ETH_ALEN);
  7178. /* initialize number of multicast & unicast MAC entries variables */
  7179. if (sp->device_type == XFRAME_I_DEVICE) {
  7180. config->max_mc_addr = S2IO_XENA_MAX_MC_ADDRESSES;
  7181. config->max_mac_addr = S2IO_XENA_MAX_MAC_ADDRESSES;
  7182. config->mc_start_offset = S2IO_XENA_MC_ADDR_START_OFFSET;
  7183. } else if (sp->device_type == XFRAME_II_DEVICE) {
  7184. config->max_mc_addr = S2IO_HERC_MAX_MC_ADDRESSES;
  7185. config->max_mac_addr = S2IO_HERC_MAX_MAC_ADDRESSES;
  7186. config->mc_start_offset = S2IO_HERC_MC_ADDR_START_OFFSET;
  7187. }
  7188. /* store mac addresses from CAM to s2io_nic structure */
  7189. do_s2io_store_unicast_mc(sp);
  7190. /* Configure MSIX vector for number of rings configured plus one */
  7191. if ((sp->device_type == XFRAME_II_DEVICE) &&
  7192. (config->intr_type == MSI_X))
  7193. sp->num_entries = config->rx_ring_num + 1;
  7194. /* Store the values of the MSIX table in the s2io_nic structure */
  7195. store_xmsi_data(sp);
  7196. /* reset Nic and bring it to known state */
  7197. s2io_reset(sp);
  7198. /*
  7199. * Initialize link state flags
  7200. * and the card state parameter
  7201. */
  7202. sp->state = 0;
  7203. /* Initialize spinlocks */
  7204. for (i = 0; i < sp->config.tx_fifo_num; i++)
  7205. spin_lock_init(&mac_control->fifos[i].tx_lock);
  7206. /*
  7207. * SXE-002: Configure link and activity LED to init state
  7208. * on driver load.
  7209. */
  7210. subid = sp->pdev->subsystem_device;
  7211. if ((subid & 0xFF) >= 0x07) {
  7212. val64 = readq(&bar0->gpio_control);
  7213. val64 |= 0x0000800000000000ULL;
  7214. writeq(val64, &bar0->gpio_control);
  7215. val64 = 0x0411040400000000ULL;
  7216. writeq(val64, (void __iomem *) bar0 + 0x2700);
  7217. val64 = readq(&bar0->gpio_control);
  7218. }
  7219. sp->rx_csum = 1; /* Rx chksum verify enabled by default */
  7220. if (register_netdev(dev)) {
  7221. DBG_PRINT(ERR_DBG, "Device registration failed\n");
  7222. ret = -ENODEV;
  7223. goto register_failed;
  7224. }
  7225. s2io_vpd_read(sp);
  7226. DBG_PRINT(ERR_DBG, "Copyright(c) 2002-2007 Neterion Inc.\n");
  7227. DBG_PRINT(ERR_DBG, "%s: Neterion %s (rev %d)\n",dev->name,
  7228. sp->product_name, pdev->revision);
  7229. DBG_PRINT(ERR_DBG, "%s: Driver version %s\n", dev->name,
  7230. s2io_driver_version);
  7231. DBG_PRINT(ERR_DBG, "%s: MAC ADDR: %pM\n", dev->name, dev->dev_addr);
  7232. DBG_PRINT(ERR_DBG, "SERIAL NUMBER: %s\n", sp->serial_num);
  7233. if (sp->device_type & XFRAME_II_DEVICE) {
  7234. mode = s2io_print_pci_mode(sp);
  7235. if (mode < 0) {
  7236. DBG_PRINT(ERR_DBG, " Unsupported PCI bus mode\n");
  7237. ret = -EBADSLT;
  7238. unregister_netdev(dev);
  7239. goto set_swap_failed;
  7240. }
  7241. }
  7242. switch(sp->rxd_mode) {
  7243. case RXD_MODE_1:
  7244. DBG_PRINT(ERR_DBG, "%s: 1-Buffer receive mode enabled\n",
  7245. dev->name);
  7246. break;
  7247. case RXD_MODE_3B:
  7248. DBG_PRINT(ERR_DBG, "%s: 2-Buffer receive mode enabled\n",
  7249. dev->name);
  7250. break;
  7251. }
  7252. switch (sp->config.napi) {
  7253. case 0:
  7254. DBG_PRINT(ERR_DBG, "%s: NAPI disabled\n", dev->name);
  7255. break;
  7256. case 1:
  7257. DBG_PRINT(ERR_DBG, "%s: NAPI enabled\n", dev->name);
  7258. break;
  7259. }
  7260. DBG_PRINT(ERR_DBG, "%s: Using %d Tx fifo(s)\n", dev->name,
  7261. sp->config.tx_fifo_num);
  7262. DBG_PRINT(ERR_DBG, "%s: Using %d Rx ring(s)\n", dev->name,
  7263. sp->config.rx_ring_num);
  7264. switch(sp->config.intr_type) {
  7265. case INTA:
  7266. DBG_PRINT(ERR_DBG, "%s: Interrupt type INTA\n", dev->name);
  7267. break;
  7268. case MSI_X:
  7269. DBG_PRINT(ERR_DBG, "%s: Interrupt type MSI-X\n", dev->name);
  7270. break;
  7271. }
  7272. if (sp->config.multiq) {
  7273. for (i = 0; i < sp->config.tx_fifo_num; i++)
  7274. mac_control->fifos[i].multiq = config->multiq;
  7275. DBG_PRINT(ERR_DBG, "%s: Multiqueue support enabled\n",
  7276. dev->name);
  7277. } else
  7278. DBG_PRINT(ERR_DBG, "%s: Multiqueue support disabled\n",
  7279. dev->name);
  7280. switch (sp->config.tx_steering_type) {
  7281. case NO_STEERING:
  7282. DBG_PRINT(ERR_DBG, "%s: No steering enabled for"
  7283. " transmit\n", dev->name);
  7284. break;
  7285. case TX_PRIORITY_STEERING:
  7286. DBG_PRINT(ERR_DBG, "%s: Priority steering enabled for"
  7287. " transmit\n", dev->name);
  7288. break;
  7289. case TX_DEFAULT_STEERING:
  7290. DBG_PRINT(ERR_DBG, "%s: Default steering enabled for"
  7291. " transmit\n", dev->name);
  7292. }
  7293. if (sp->lro)
  7294. DBG_PRINT(ERR_DBG, "%s: Large receive offload enabled\n",
  7295. dev->name);
  7296. if (ufo)
  7297. DBG_PRINT(ERR_DBG, "%s: UDP Fragmentation Offload(UFO)"
  7298. " enabled\n", dev->name);
  7299. /* Initialize device name */
  7300. sprintf(sp->name, "%s Neterion %s", dev->name, sp->product_name);
  7301. if (vlan_tag_strip)
  7302. sp->vlan_strip_flag = 1;
  7303. else
  7304. sp->vlan_strip_flag = 0;
  7305. /*
  7306. * Make Link state as off at this point, when the Link change
  7307. * interrupt comes the state will be automatically changed to
  7308. * the right state.
  7309. */
  7310. netif_carrier_off(dev);
  7311. return 0;
  7312. register_failed:
  7313. set_swap_failed:
  7314. iounmap(sp->bar1);
  7315. bar1_remap_failed:
  7316. iounmap(sp->bar0);
  7317. bar0_remap_failed:
  7318. mem_alloc_failed:
  7319. free_shared_mem(sp);
  7320. pci_disable_device(pdev);
  7321. pci_release_regions(pdev);
  7322. pci_set_drvdata(pdev, NULL);
  7323. free_netdev(dev);
  7324. return ret;
  7325. }
  7326. /**
  7327. * s2io_rem_nic - Free the PCI device
  7328. * @pdev: structure containing the PCI related information of the device.
  7329. * Description: This function is called by the Pci subsystem to release a
  7330. * PCI device and free up all resource held up by the device. This could
  7331. * be in response to a Hot plug event or when the driver is to be removed
  7332. * from memory.
  7333. */
  7334. static void __devexit s2io_rem_nic(struct pci_dev *pdev)
  7335. {
  7336. struct net_device *dev =
  7337. (struct net_device *) pci_get_drvdata(pdev);
  7338. struct s2io_nic *sp;
  7339. if (dev == NULL) {
  7340. DBG_PRINT(ERR_DBG, "Driver Data is NULL!!\n");
  7341. return;
  7342. }
  7343. flush_scheduled_work();
  7344. sp = netdev_priv(dev);
  7345. unregister_netdev(dev);
  7346. free_shared_mem(sp);
  7347. iounmap(sp->bar0);
  7348. iounmap(sp->bar1);
  7349. pci_release_regions(pdev);
  7350. pci_set_drvdata(pdev, NULL);
  7351. free_netdev(dev);
  7352. pci_disable_device(pdev);
  7353. }
  7354. /**
  7355. * s2io_starter - Entry point for the driver
  7356. * Description: This function is the entry point for the driver. It verifies
  7357. * the module loadable parameters and initializes PCI configuration space.
  7358. */
  7359. static int __init s2io_starter(void)
  7360. {
  7361. return pci_register_driver(&s2io_driver);
  7362. }
  7363. /**
  7364. * s2io_closer - Cleanup routine for the driver
  7365. * Description: This function is the cleanup routine for the driver. It unregist * ers the driver.
  7366. */
  7367. static __exit void s2io_closer(void)
  7368. {
  7369. pci_unregister_driver(&s2io_driver);
  7370. DBG_PRINT(INIT_DBG, "cleanup done\n");
  7371. }
  7372. module_init(s2io_starter);
  7373. module_exit(s2io_closer);
  7374. static int check_L2_lro_capable(u8 *buffer, struct iphdr **ip,
  7375. struct tcphdr **tcp, struct RxD_t *rxdp,
  7376. struct s2io_nic *sp)
  7377. {
  7378. int ip_off;
  7379. u8 l2_type = (u8)((rxdp->Control_1 >> 37) & 0x7), ip_len;
  7380. if (!(rxdp->Control_1 & RXD_FRAME_PROTO_TCP)) {
  7381. DBG_PRINT(INIT_DBG,"%s: Non-TCP frames not supported for LRO\n",
  7382. __func__);
  7383. return -1;
  7384. }
  7385. /* Checking for DIX type or DIX type with VLAN */
  7386. if ((l2_type == 0)
  7387. || (l2_type == 4)) {
  7388. ip_off = HEADER_ETHERNET_II_802_3_SIZE;
  7389. /*
  7390. * If vlan stripping is disabled and the frame is VLAN tagged,
  7391. * shift the offset by the VLAN header size bytes.
  7392. */
  7393. if ((!sp->vlan_strip_flag) &&
  7394. (rxdp->Control_1 & RXD_FRAME_VLAN_TAG))
  7395. ip_off += HEADER_VLAN_SIZE;
  7396. } else {
  7397. /* LLC, SNAP etc are considered non-mergeable */
  7398. return -1;
  7399. }
  7400. *ip = (struct iphdr *)((u8 *)buffer + ip_off);
  7401. ip_len = (u8)((*ip)->ihl);
  7402. ip_len <<= 2;
  7403. *tcp = (struct tcphdr *)((unsigned long)*ip + ip_len);
  7404. return 0;
  7405. }
  7406. static int check_for_socket_match(struct lro *lro, struct iphdr *ip,
  7407. struct tcphdr *tcp)
  7408. {
  7409. DBG_PRINT(INFO_DBG,"%s: Been here...\n", __func__);
  7410. if ((lro->iph->saddr != ip->saddr) || (lro->iph->daddr != ip->daddr) ||
  7411. (lro->tcph->source != tcp->source) || (lro->tcph->dest != tcp->dest))
  7412. return -1;
  7413. return 0;
  7414. }
  7415. static inline int get_l4_pyld_length(struct iphdr *ip, struct tcphdr *tcp)
  7416. {
  7417. return(ntohs(ip->tot_len) - (ip->ihl << 2) - (tcp->doff << 2));
  7418. }
  7419. static void initiate_new_session(struct lro *lro, u8 *l2h,
  7420. struct iphdr *ip, struct tcphdr *tcp, u32 tcp_pyld_len, u16 vlan_tag)
  7421. {
  7422. DBG_PRINT(INFO_DBG,"%s: Been here...\n", __func__);
  7423. lro->l2h = l2h;
  7424. lro->iph = ip;
  7425. lro->tcph = tcp;
  7426. lro->tcp_next_seq = tcp_pyld_len + ntohl(tcp->seq);
  7427. lro->tcp_ack = tcp->ack_seq;
  7428. lro->sg_num = 1;
  7429. lro->total_len = ntohs(ip->tot_len);
  7430. lro->frags_len = 0;
  7431. lro->vlan_tag = vlan_tag;
  7432. /*
  7433. * check if we saw TCP timestamp. Other consistency checks have
  7434. * already been done.
  7435. */
  7436. if (tcp->doff == 8) {
  7437. __be32 *ptr;
  7438. ptr = (__be32 *)(tcp+1);
  7439. lro->saw_ts = 1;
  7440. lro->cur_tsval = ntohl(*(ptr+1));
  7441. lro->cur_tsecr = *(ptr+2);
  7442. }
  7443. lro->in_use = 1;
  7444. }
  7445. static void update_L3L4_header(struct s2io_nic *sp, struct lro *lro)
  7446. {
  7447. struct iphdr *ip = lro->iph;
  7448. struct tcphdr *tcp = lro->tcph;
  7449. __sum16 nchk;
  7450. struct stat_block *statinfo = sp->mac_control.stats_info;
  7451. DBG_PRINT(INFO_DBG,"%s: Been here...\n", __func__);
  7452. /* Update L3 header */
  7453. ip->tot_len = htons(lro->total_len);
  7454. ip->check = 0;
  7455. nchk = ip_fast_csum((u8 *)lro->iph, ip->ihl);
  7456. ip->check = nchk;
  7457. /* Update L4 header */
  7458. tcp->ack_seq = lro->tcp_ack;
  7459. tcp->window = lro->window;
  7460. /* Update tsecr field if this session has timestamps enabled */
  7461. if (lro->saw_ts) {
  7462. __be32 *ptr = (__be32 *)(tcp + 1);
  7463. *(ptr+2) = lro->cur_tsecr;
  7464. }
  7465. /* Update counters required for calculation of
  7466. * average no. of packets aggregated.
  7467. */
  7468. statinfo->sw_stat.sum_avg_pkts_aggregated += lro->sg_num;
  7469. statinfo->sw_stat.num_aggregations++;
  7470. }
  7471. static void aggregate_new_rx(struct lro *lro, struct iphdr *ip,
  7472. struct tcphdr *tcp, u32 l4_pyld)
  7473. {
  7474. DBG_PRINT(INFO_DBG,"%s: Been here...\n", __func__);
  7475. lro->total_len += l4_pyld;
  7476. lro->frags_len += l4_pyld;
  7477. lro->tcp_next_seq += l4_pyld;
  7478. lro->sg_num++;
  7479. /* Update ack seq no. and window ad(from this pkt) in LRO object */
  7480. lro->tcp_ack = tcp->ack_seq;
  7481. lro->window = tcp->window;
  7482. if (lro->saw_ts) {
  7483. __be32 *ptr;
  7484. /* Update tsecr and tsval from this packet */
  7485. ptr = (__be32 *)(tcp+1);
  7486. lro->cur_tsval = ntohl(*(ptr+1));
  7487. lro->cur_tsecr = *(ptr + 2);
  7488. }
  7489. }
  7490. static int verify_l3_l4_lro_capable(struct lro *l_lro, struct iphdr *ip,
  7491. struct tcphdr *tcp, u32 tcp_pyld_len)
  7492. {
  7493. u8 *ptr;
  7494. DBG_PRINT(INFO_DBG,"%s: Been here...\n", __func__);
  7495. if (!tcp_pyld_len) {
  7496. /* Runt frame or a pure ack */
  7497. return -1;
  7498. }
  7499. if (ip->ihl != 5) /* IP has options */
  7500. return -1;
  7501. /* If we see CE codepoint in IP header, packet is not mergeable */
  7502. if (INET_ECN_is_ce(ipv4_get_dsfield(ip)))
  7503. return -1;
  7504. /* If we see ECE or CWR flags in TCP header, packet is not mergeable */
  7505. if (tcp->urg || tcp->psh || tcp->rst || tcp->syn || tcp->fin ||
  7506. tcp->ece || tcp->cwr || !tcp->ack) {
  7507. /*
  7508. * Currently recognize only the ack control word and
  7509. * any other control field being set would result in
  7510. * flushing the LRO session
  7511. */
  7512. return -1;
  7513. }
  7514. /*
  7515. * Allow only one TCP timestamp option. Don't aggregate if
  7516. * any other options are detected.
  7517. */
  7518. if (tcp->doff != 5 && tcp->doff != 8)
  7519. return -1;
  7520. if (tcp->doff == 8) {
  7521. ptr = (u8 *)(tcp + 1);
  7522. while (*ptr == TCPOPT_NOP)
  7523. ptr++;
  7524. if (*ptr != TCPOPT_TIMESTAMP || *(ptr+1) != TCPOLEN_TIMESTAMP)
  7525. return -1;
  7526. /* Ensure timestamp value increases monotonically */
  7527. if (l_lro)
  7528. if (l_lro->cur_tsval > ntohl(*((__be32 *)(ptr+2))))
  7529. return -1;
  7530. /* timestamp echo reply should be non-zero */
  7531. if (*((__be32 *)(ptr+6)) == 0)
  7532. return -1;
  7533. }
  7534. return 0;
  7535. }
  7536. static int
  7537. s2io_club_tcp_session(struct ring_info *ring_data, u8 *buffer, u8 **tcp,
  7538. u32 *tcp_len, struct lro **lro, struct RxD_t *rxdp,
  7539. struct s2io_nic *sp)
  7540. {
  7541. struct iphdr *ip;
  7542. struct tcphdr *tcph;
  7543. int ret = 0, i;
  7544. u16 vlan_tag = 0;
  7545. if (!(ret = check_L2_lro_capable(buffer, &ip, (struct tcphdr **)tcp,
  7546. rxdp, sp))) {
  7547. DBG_PRINT(INFO_DBG,"IP Saddr: %x Daddr: %x\n",
  7548. ip->saddr, ip->daddr);
  7549. } else
  7550. return ret;
  7551. vlan_tag = RXD_GET_VLAN_TAG(rxdp->Control_2);
  7552. tcph = (struct tcphdr *)*tcp;
  7553. *tcp_len = get_l4_pyld_length(ip, tcph);
  7554. for (i=0; i<MAX_LRO_SESSIONS; i++) {
  7555. struct lro *l_lro = &ring_data->lro0_n[i];
  7556. if (l_lro->in_use) {
  7557. if (check_for_socket_match(l_lro, ip, tcph))
  7558. continue;
  7559. /* Sock pair matched */
  7560. *lro = l_lro;
  7561. if ((*lro)->tcp_next_seq != ntohl(tcph->seq)) {
  7562. DBG_PRINT(INFO_DBG, "%s:Out of order. expected "
  7563. "0x%x, actual 0x%x\n", __func__,
  7564. (*lro)->tcp_next_seq,
  7565. ntohl(tcph->seq));
  7566. sp->mac_control.stats_info->
  7567. sw_stat.outof_sequence_pkts++;
  7568. ret = 2;
  7569. break;
  7570. }
  7571. if (!verify_l3_l4_lro_capable(l_lro, ip, tcph,*tcp_len))
  7572. ret = 1; /* Aggregate */
  7573. else
  7574. ret = 2; /* Flush both */
  7575. break;
  7576. }
  7577. }
  7578. if (ret == 0) {
  7579. /* Before searching for available LRO objects,
  7580. * check if the pkt is L3/L4 aggregatable. If not
  7581. * don't create new LRO session. Just send this
  7582. * packet up.
  7583. */
  7584. if (verify_l3_l4_lro_capable(NULL, ip, tcph, *tcp_len)) {
  7585. return 5;
  7586. }
  7587. for (i=0; i<MAX_LRO_SESSIONS; i++) {
  7588. struct lro *l_lro = &ring_data->lro0_n[i];
  7589. if (!(l_lro->in_use)) {
  7590. *lro = l_lro;
  7591. ret = 3; /* Begin anew */
  7592. break;
  7593. }
  7594. }
  7595. }
  7596. if (ret == 0) { /* sessions exceeded */
  7597. DBG_PRINT(INFO_DBG,"%s:All LRO sessions already in use\n",
  7598. __func__);
  7599. *lro = NULL;
  7600. return ret;
  7601. }
  7602. switch (ret) {
  7603. case 3:
  7604. initiate_new_session(*lro, buffer, ip, tcph, *tcp_len,
  7605. vlan_tag);
  7606. break;
  7607. case 2:
  7608. update_L3L4_header(sp, *lro);
  7609. break;
  7610. case 1:
  7611. aggregate_new_rx(*lro, ip, tcph, *tcp_len);
  7612. if ((*lro)->sg_num == sp->lro_max_aggr_per_sess) {
  7613. update_L3L4_header(sp, *lro);
  7614. ret = 4; /* Flush the LRO */
  7615. }
  7616. break;
  7617. default:
  7618. DBG_PRINT(ERR_DBG,"%s:Dont know, can't say!!\n",
  7619. __func__);
  7620. break;
  7621. }
  7622. return ret;
  7623. }
  7624. static void clear_lro_session(struct lro *lro)
  7625. {
  7626. static u16 lro_struct_size = sizeof(struct lro);
  7627. memset(lro, 0, lro_struct_size);
  7628. }
  7629. static void queue_rx_frame(struct sk_buff *skb, u16 vlan_tag)
  7630. {
  7631. struct net_device *dev = skb->dev;
  7632. struct s2io_nic *sp = netdev_priv(dev);
  7633. skb->protocol = eth_type_trans(skb, dev);
  7634. if (sp->vlgrp && vlan_tag
  7635. && (sp->vlan_strip_flag)) {
  7636. /* Queueing the vlan frame to the upper layer */
  7637. if (sp->config.napi)
  7638. vlan_hwaccel_receive_skb(skb, sp->vlgrp, vlan_tag);
  7639. else
  7640. vlan_hwaccel_rx(skb, sp->vlgrp, vlan_tag);
  7641. } else {
  7642. if (sp->config.napi)
  7643. netif_receive_skb(skb);
  7644. else
  7645. netif_rx(skb);
  7646. }
  7647. }
  7648. static void lro_append_pkt(struct s2io_nic *sp, struct lro *lro,
  7649. struct sk_buff *skb,
  7650. u32 tcp_len)
  7651. {
  7652. struct sk_buff *first = lro->parent;
  7653. first->len += tcp_len;
  7654. first->data_len = lro->frags_len;
  7655. skb_pull(skb, (skb->len - tcp_len));
  7656. if (skb_shinfo(first)->frag_list)
  7657. lro->last_frag->next = skb;
  7658. else
  7659. skb_shinfo(first)->frag_list = skb;
  7660. first->truesize += skb->truesize;
  7661. lro->last_frag = skb;
  7662. sp->mac_control.stats_info->sw_stat.clubbed_frms_cnt++;
  7663. return;
  7664. }
  7665. /**
  7666. * s2io_io_error_detected - called when PCI error is detected
  7667. * @pdev: Pointer to PCI device
  7668. * @state: The current pci connection state
  7669. *
  7670. * This function is called after a PCI bus error affecting
  7671. * this device has been detected.
  7672. */
  7673. static pci_ers_result_t s2io_io_error_detected(struct pci_dev *pdev,
  7674. pci_channel_state_t state)
  7675. {
  7676. struct net_device *netdev = pci_get_drvdata(pdev);
  7677. struct s2io_nic *sp = netdev_priv(netdev);
  7678. netif_device_detach(netdev);
  7679. if (netif_running(netdev)) {
  7680. /* Bring down the card, while avoiding PCI I/O */
  7681. do_s2io_card_down(sp, 0);
  7682. }
  7683. pci_disable_device(pdev);
  7684. return PCI_ERS_RESULT_NEED_RESET;
  7685. }
  7686. /**
  7687. * s2io_io_slot_reset - called after the pci bus has been reset.
  7688. * @pdev: Pointer to PCI device
  7689. *
  7690. * Restart the card from scratch, as if from a cold-boot.
  7691. * At this point, the card has exprienced a hard reset,
  7692. * followed by fixups by BIOS, and has its config space
  7693. * set up identically to what it was at cold boot.
  7694. */
  7695. static pci_ers_result_t s2io_io_slot_reset(struct pci_dev *pdev)
  7696. {
  7697. struct net_device *netdev = pci_get_drvdata(pdev);
  7698. struct s2io_nic *sp = netdev_priv(netdev);
  7699. if (pci_enable_device(pdev)) {
  7700. printk(KERN_ERR "s2io: "
  7701. "Cannot re-enable PCI device after reset.\n");
  7702. return PCI_ERS_RESULT_DISCONNECT;
  7703. }
  7704. pci_set_master(pdev);
  7705. s2io_reset(sp);
  7706. return PCI_ERS_RESULT_RECOVERED;
  7707. }
  7708. /**
  7709. * s2io_io_resume - called when traffic can start flowing again.
  7710. * @pdev: Pointer to PCI device
  7711. *
  7712. * This callback is called when the error recovery driver tells
  7713. * us that its OK to resume normal operation.
  7714. */
  7715. static void s2io_io_resume(struct pci_dev *pdev)
  7716. {
  7717. struct net_device *netdev = pci_get_drvdata(pdev);
  7718. struct s2io_nic *sp = netdev_priv(netdev);
  7719. if (netif_running(netdev)) {
  7720. if (s2io_card_up(sp)) {
  7721. printk(KERN_ERR "s2io: "
  7722. "Can't bring device back up after reset.\n");
  7723. return;
  7724. }
  7725. if (s2io_set_mac_addr(netdev, netdev->dev_addr) == FAILURE) {
  7726. s2io_card_down(sp);
  7727. printk(KERN_ERR "s2io: "
  7728. "Can't resetore mac addr after reset.\n");
  7729. return;
  7730. }
  7731. }
  7732. netif_device_attach(netdev);
  7733. netif_tx_wake_all_queues(netdev);
  7734. }