s2io.c 214 KB

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