s2io.c 235 KB

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