s2io.c 228 KB

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