s2io.c 246 KB

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