s2io.c 243 KB

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