s2io.c 245 KB

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