s2io.c 243 KB

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