s2io.c 239 KB

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