s2io.c 212 KB

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