s2io.c 172 KB

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