s2io.c 189 KB

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