s2io.c 214 KB

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