s2io.c 223 KB

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