s2io.c 242 KB

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