s2io.c 189 KB

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