s2io.c 219 KB

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