s2io.c 218 KB

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