s2io.c 213 KB

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