s2io.c 238 KB

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