s2io.c 238 KB

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