s2io.c 241 KB

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