s2io.c 189 KB

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