s2io.c 245 KB

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