s2io.c 178 KB

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