s2io.c 213 KB

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