s2io.c 213 KB

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