forcedeth.c 188 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311
  1. /*
  2. * forcedeth: Ethernet driver for NVIDIA nForce media access controllers.
  3. *
  4. * Note: This driver is a cleanroom reimplementation based on reverse
  5. * engineered documentation written by Carl-Daniel Hailfinger
  6. * and Andrew de Quincey.
  7. *
  8. * NVIDIA, nForce and other NVIDIA marks are trademarks or registered
  9. * trademarks of NVIDIA Corporation in the United States and other
  10. * countries.
  11. *
  12. * Copyright (C) 2003,4,5 Manfred Spraul
  13. * Copyright (C) 2004 Andrew de Quincey (wol support)
  14. * Copyright (C) 2004 Carl-Daniel Hailfinger (invalid MAC handling, insane
  15. * IRQ rate fixes, bigendian fixes, cleanups, verification)
  16. * Copyright (c) 2004,2005,2006,2007,2008,2009 NVIDIA Corporation
  17. *
  18. * This program is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation; either version 2 of the License, or
  21. * (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * along with this program; if not, write to the Free Software
  30. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  31. *
  32. * Known bugs:
  33. * We suspect that on some hardware no TX done interrupts are generated.
  34. * This means recovery from netif_stop_queue only happens if the hw timer
  35. * interrupt fires (100 times/second, configurable with NVREG_POLL_DEFAULT)
  36. * and the timer is active in the IRQMask, or if a rx packet arrives by chance.
  37. * If your hardware reliably generates tx done interrupts, then you can remove
  38. * DEV_NEED_TIMERIRQ from the driver_data flags.
  39. * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few
  40. * superfluous timer interrupts from the nic.
  41. */
  42. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  43. #define FORCEDETH_VERSION "0.64"
  44. #define DRV_NAME "forcedeth"
  45. #include <linux/module.h>
  46. #include <linux/types.h>
  47. #include <linux/pci.h>
  48. #include <linux/interrupt.h>
  49. #include <linux/netdevice.h>
  50. #include <linux/etherdevice.h>
  51. #include <linux/delay.h>
  52. #include <linux/sched.h>
  53. #include <linux/spinlock.h>
  54. #include <linux/ethtool.h>
  55. #include <linux/timer.h>
  56. #include <linux/skbuff.h>
  57. #include <linux/mii.h>
  58. #include <linux/random.h>
  59. #include <linux/init.h>
  60. #include <linux/if_vlan.h>
  61. #include <linux/dma-mapping.h>
  62. #include <linux/slab.h>
  63. #include <linux/uaccess.h>
  64. #include <linux/prefetch.h>
  65. #include <linux/u64_stats_sync.h>
  66. #include <linux/io.h>
  67. #include <asm/irq.h>
  68. #define TX_WORK_PER_LOOP 64
  69. #define RX_WORK_PER_LOOP 64
  70. /*
  71. * Hardware access:
  72. */
  73. #define DEV_NEED_TIMERIRQ 0x0000001 /* set the timer irq flag in the irq mask */
  74. #define DEV_NEED_LINKTIMER 0x0000002 /* poll link settings. Relies on the timer irq */
  75. #define DEV_HAS_LARGEDESC 0x0000004 /* device supports jumbo frames and needs packet format 2 */
  76. #define DEV_HAS_HIGH_DMA 0x0000008 /* device supports 64bit dma */
  77. #define DEV_HAS_CHECKSUM 0x0000010 /* device supports tx and rx checksum offloads */
  78. #define DEV_HAS_VLAN 0x0000020 /* device supports vlan tagging and striping */
  79. #define DEV_HAS_MSI 0x0000040 /* device supports MSI */
  80. #define DEV_HAS_MSI_X 0x0000080 /* device supports MSI-X */
  81. #define DEV_HAS_POWER_CNTRL 0x0000100 /* device supports power savings */
  82. #define DEV_HAS_STATISTICS_V1 0x0000200 /* device supports hw statistics version 1 */
  83. #define DEV_HAS_STATISTICS_V2 0x0000400 /* device supports hw statistics version 2 */
  84. #define DEV_HAS_STATISTICS_V3 0x0000800 /* device supports hw statistics version 3 */
  85. #define DEV_HAS_STATISTICS_V12 0x0000600 /* device supports hw statistics version 1 and 2 */
  86. #define DEV_HAS_STATISTICS_V123 0x0000e00 /* device supports hw statistics version 1, 2, and 3 */
  87. #define DEV_HAS_TEST_EXTENDED 0x0001000 /* device supports extended diagnostic test */
  88. #define DEV_HAS_MGMT_UNIT 0x0002000 /* device supports management unit */
  89. #define DEV_HAS_CORRECT_MACADDR 0x0004000 /* device supports correct mac address order */
  90. #define DEV_HAS_COLLISION_FIX 0x0008000 /* device supports tx collision fix */
  91. #define DEV_HAS_PAUSEFRAME_TX_V1 0x0010000 /* device supports tx pause frames version 1 */
  92. #define DEV_HAS_PAUSEFRAME_TX_V2 0x0020000 /* device supports tx pause frames version 2 */
  93. #define DEV_HAS_PAUSEFRAME_TX_V3 0x0040000 /* device supports tx pause frames version 3 */
  94. #define DEV_NEED_TX_LIMIT 0x0080000 /* device needs to limit tx */
  95. #define DEV_NEED_TX_LIMIT2 0x0180000 /* device needs to limit tx, expect for some revs */
  96. #define DEV_HAS_GEAR_MODE 0x0200000 /* device supports gear mode */
  97. #define DEV_NEED_PHY_INIT_FIX 0x0400000 /* device needs specific phy workaround */
  98. #define DEV_NEED_LOW_POWER_FIX 0x0800000 /* device needs special power up workaround */
  99. #define DEV_NEED_MSI_FIX 0x1000000 /* device needs msi workaround */
  100. enum {
  101. NvRegIrqStatus = 0x000,
  102. #define NVREG_IRQSTAT_MIIEVENT 0x040
  103. #define NVREG_IRQSTAT_MASK 0x83ff
  104. NvRegIrqMask = 0x004,
  105. #define NVREG_IRQ_RX_ERROR 0x0001
  106. #define NVREG_IRQ_RX 0x0002
  107. #define NVREG_IRQ_RX_NOBUF 0x0004
  108. #define NVREG_IRQ_TX_ERR 0x0008
  109. #define NVREG_IRQ_TX_OK 0x0010
  110. #define NVREG_IRQ_TIMER 0x0020
  111. #define NVREG_IRQ_LINK 0x0040
  112. #define NVREG_IRQ_RX_FORCED 0x0080
  113. #define NVREG_IRQ_TX_FORCED 0x0100
  114. #define NVREG_IRQ_RECOVER_ERROR 0x8200
  115. #define NVREG_IRQMASK_THROUGHPUT 0x00df
  116. #define NVREG_IRQMASK_CPU 0x0060
  117. #define NVREG_IRQ_TX_ALL (NVREG_IRQ_TX_ERR|NVREG_IRQ_TX_OK|NVREG_IRQ_TX_FORCED)
  118. #define NVREG_IRQ_RX_ALL (NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_RX_FORCED)
  119. #define NVREG_IRQ_OTHER (NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RECOVER_ERROR)
  120. NvRegUnknownSetupReg6 = 0x008,
  121. #define NVREG_UNKSETUP6_VAL 3
  122. /*
  123. * NVREG_POLL_DEFAULT is the interval length of the timer source on the nic
  124. * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms
  125. */
  126. NvRegPollingInterval = 0x00c,
  127. #define NVREG_POLL_DEFAULT_THROUGHPUT 65535 /* backup tx cleanup if loop max reached */
  128. #define NVREG_POLL_DEFAULT_CPU 13
  129. NvRegMSIMap0 = 0x020,
  130. NvRegMSIMap1 = 0x024,
  131. NvRegMSIIrqMask = 0x030,
  132. #define NVREG_MSI_VECTOR_0_ENABLED 0x01
  133. NvRegMisc1 = 0x080,
  134. #define NVREG_MISC1_PAUSE_TX 0x01
  135. #define NVREG_MISC1_HD 0x02
  136. #define NVREG_MISC1_FORCE 0x3b0f3c
  137. NvRegMacReset = 0x34,
  138. #define NVREG_MAC_RESET_ASSERT 0x0F3
  139. NvRegTransmitterControl = 0x084,
  140. #define NVREG_XMITCTL_START 0x01
  141. #define NVREG_XMITCTL_MGMT_ST 0x40000000
  142. #define NVREG_XMITCTL_SYNC_MASK 0x000f0000
  143. #define NVREG_XMITCTL_SYNC_NOT_READY 0x0
  144. #define NVREG_XMITCTL_SYNC_PHY_INIT 0x00040000
  145. #define NVREG_XMITCTL_MGMT_SEMA_MASK 0x00000f00
  146. #define NVREG_XMITCTL_MGMT_SEMA_FREE 0x0
  147. #define NVREG_XMITCTL_HOST_SEMA_MASK 0x0000f000
  148. #define NVREG_XMITCTL_HOST_SEMA_ACQ 0x0000f000
  149. #define NVREG_XMITCTL_HOST_LOADED 0x00004000
  150. #define NVREG_XMITCTL_TX_PATH_EN 0x01000000
  151. #define NVREG_XMITCTL_DATA_START 0x00100000
  152. #define NVREG_XMITCTL_DATA_READY 0x00010000
  153. #define NVREG_XMITCTL_DATA_ERROR 0x00020000
  154. NvRegTransmitterStatus = 0x088,
  155. #define NVREG_XMITSTAT_BUSY 0x01
  156. NvRegPacketFilterFlags = 0x8c,
  157. #define NVREG_PFF_PAUSE_RX 0x08
  158. #define NVREG_PFF_ALWAYS 0x7F0000
  159. #define NVREG_PFF_PROMISC 0x80
  160. #define NVREG_PFF_MYADDR 0x20
  161. #define NVREG_PFF_LOOPBACK 0x10
  162. NvRegOffloadConfig = 0x90,
  163. #define NVREG_OFFLOAD_HOMEPHY 0x601
  164. #define NVREG_OFFLOAD_NORMAL RX_NIC_BUFSIZE
  165. NvRegReceiverControl = 0x094,
  166. #define NVREG_RCVCTL_START 0x01
  167. #define NVREG_RCVCTL_RX_PATH_EN 0x01000000
  168. NvRegReceiverStatus = 0x98,
  169. #define NVREG_RCVSTAT_BUSY 0x01
  170. NvRegSlotTime = 0x9c,
  171. #define NVREG_SLOTTIME_LEGBF_ENABLED 0x80000000
  172. #define NVREG_SLOTTIME_10_100_FULL 0x00007f00
  173. #define NVREG_SLOTTIME_1000_FULL 0x0003ff00
  174. #define NVREG_SLOTTIME_HALF 0x0000ff00
  175. #define NVREG_SLOTTIME_DEFAULT 0x00007f00
  176. #define NVREG_SLOTTIME_MASK 0x000000ff
  177. NvRegTxDeferral = 0xA0,
  178. #define NVREG_TX_DEFERRAL_DEFAULT 0x15050f
  179. #define NVREG_TX_DEFERRAL_RGMII_10_100 0x16070f
  180. #define NVREG_TX_DEFERRAL_RGMII_1000 0x14050f
  181. #define NVREG_TX_DEFERRAL_RGMII_STRETCH_10 0x16190f
  182. #define NVREG_TX_DEFERRAL_RGMII_STRETCH_100 0x16300f
  183. #define NVREG_TX_DEFERRAL_MII_STRETCH 0x152000
  184. NvRegRxDeferral = 0xA4,
  185. #define NVREG_RX_DEFERRAL_DEFAULT 0x16
  186. NvRegMacAddrA = 0xA8,
  187. NvRegMacAddrB = 0xAC,
  188. NvRegMulticastAddrA = 0xB0,
  189. #define NVREG_MCASTADDRA_FORCE 0x01
  190. NvRegMulticastAddrB = 0xB4,
  191. NvRegMulticastMaskA = 0xB8,
  192. #define NVREG_MCASTMASKA_NONE 0xffffffff
  193. NvRegMulticastMaskB = 0xBC,
  194. #define NVREG_MCASTMASKB_NONE 0xffff
  195. NvRegPhyInterface = 0xC0,
  196. #define PHY_RGMII 0x10000000
  197. NvRegBackOffControl = 0xC4,
  198. #define NVREG_BKOFFCTRL_DEFAULT 0x70000000
  199. #define NVREG_BKOFFCTRL_SEED_MASK 0x000003ff
  200. #define NVREG_BKOFFCTRL_SELECT 24
  201. #define NVREG_BKOFFCTRL_GEAR 12
  202. NvRegTxRingPhysAddr = 0x100,
  203. NvRegRxRingPhysAddr = 0x104,
  204. NvRegRingSizes = 0x108,
  205. #define NVREG_RINGSZ_TXSHIFT 0
  206. #define NVREG_RINGSZ_RXSHIFT 16
  207. NvRegTransmitPoll = 0x10c,
  208. #define NVREG_TRANSMITPOLL_MAC_ADDR_REV 0x00008000
  209. NvRegLinkSpeed = 0x110,
  210. #define NVREG_LINKSPEED_FORCE 0x10000
  211. #define NVREG_LINKSPEED_10 1000
  212. #define NVREG_LINKSPEED_100 100
  213. #define NVREG_LINKSPEED_1000 50
  214. #define NVREG_LINKSPEED_MASK (0xFFF)
  215. NvRegUnknownSetupReg5 = 0x130,
  216. #define NVREG_UNKSETUP5_BIT31 (1<<31)
  217. NvRegTxWatermark = 0x13c,
  218. #define NVREG_TX_WM_DESC1_DEFAULT 0x0200010
  219. #define NVREG_TX_WM_DESC2_3_DEFAULT 0x1e08000
  220. #define NVREG_TX_WM_DESC2_3_1000 0xfe08000
  221. NvRegTxRxControl = 0x144,
  222. #define NVREG_TXRXCTL_KICK 0x0001
  223. #define NVREG_TXRXCTL_BIT1 0x0002
  224. #define NVREG_TXRXCTL_BIT2 0x0004
  225. #define NVREG_TXRXCTL_IDLE 0x0008
  226. #define NVREG_TXRXCTL_RESET 0x0010
  227. #define NVREG_TXRXCTL_RXCHECK 0x0400
  228. #define NVREG_TXRXCTL_DESC_1 0
  229. #define NVREG_TXRXCTL_DESC_2 0x002100
  230. #define NVREG_TXRXCTL_DESC_3 0xc02200
  231. #define NVREG_TXRXCTL_VLANSTRIP 0x00040
  232. #define NVREG_TXRXCTL_VLANINS 0x00080
  233. NvRegTxRingPhysAddrHigh = 0x148,
  234. NvRegRxRingPhysAddrHigh = 0x14C,
  235. NvRegTxPauseFrame = 0x170,
  236. #define NVREG_TX_PAUSEFRAME_DISABLE 0x0fff0080
  237. #define NVREG_TX_PAUSEFRAME_ENABLE_V1 0x01800010
  238. #define NVREG_TX_PAUSEFRAME_ENABLE_V2 0x056003f0
  239. #define NVREG_TX_PAUSEFRAME_ENABLE_V3 0x09f00880
  240. NvRegTxPauseFrameLimit = 0x174,
  241. #define NVREG_TX_PAUSEFRAMELIMIT_ENABLE 0x00010000
  242. NvRegMIIStatus = 0x180,
  243. #define NVREG_MIISTAT_ERROR 0x0001
  244. #define NVREG_MIISTAT_LINKCHANGE 0x0008
  245. #define NVREG_MIISTAT_MASK_RW 0x0007
  246. #define NVREG_MIISTAT_MASK_ALL 0x000f
  247. NvRegMIIMask = 0x184,
  248. #define NVREG_MII_LINKCHANGE 0x0008
  249. NvRegAdapterControl = 0x188,
  250. #define NVREG_ADAPTCTL_START 0x02
  251. #define NVREG_ADAPTCTL_LINKUP 0x04
  252. #define NVREG_ADAPTCTL_PHYVALID 0x40000
  253. #define NVREG_ADAPTCTL_RUNNING 0x100000
  254. #define NVREG_ADAPTCTL_PHYSHIFT 24
  255. NvRegMIISpeed = 0x18c,
  256. #define NVREG_MIISPEED_BIT8 (1<<8)
  257. #define NVREG_MIIDELAY 5
  258. NvRegMIIControl = 0x190,
  259. #define NVREG_MIICTL_INUSE 0x08000
  260. #define NVREG_MIICTL_WRITE 0x00400
  261. #define NVREG_MIICTL_ADDRSHIFT 5
  262. NvRegMIIData = 0x194,
  263. NvRegTxUnicast = 0x1a0,
  264. NvRegTxMulticast = 0x1a4,
  265. NvRegTxBroadcast = 0x1a8,
  266. NvRegWakeUpFlags = 0x200,
  267. #define NVREG_WAKEUPFLAGS_VAL 0x7770
  268. #define NVREG_WAKEUPFLAGS_BUSYSHIFT 24
  269. #define NVREG_WAKEUPFLAGS_ENABLESHIFT 16
  270. #define NVREG_WAKEUPFLAGS_D3SHIFT 12
  271. #define NVREG_WAKEUPFLAGS_D2SHIFT 8
  272. #define NVREG_WAKEUPFLAGS_D1SHIFT 4
  273. #define NVREG_WAKEUPFLAGS_D0SHIFT 0
  274. #define NVREG_WAKEUPFLAGS_ACCEPT_MAGPAT 0x01
  275. #define NVREG_WAKEUPFLAGS_ACCEPT_WAKEUPPAT 0x02
  276. #define NVREG_WAKEUPFLAGS_ACCEPT_LINKCHANGE 0x04
  277. #define NVREG_WAKEUPFLAGS_ENABLE 0x1111
  278. NvRegMgmtUnitGetVersion = 0x204,
  279. #define NVREG_MGMTUNITGETVERSION 0x01
  280. NvRegMgmtUnitVersion = 0x208,
  281. #define NVREG_MGMTUNITVERSION 0x08
  282. NvRegPowerCap = 0x268,
  283. #define NVREG_POWERCAP_D3SUPP (1<<30)
  284. #define NVREG_POWERCAP_D2SUPP (1<<26)
  285. #define NVREG_POWERCAP_D1SUPP (1<<25)
  286. NvRegPowerState = 0x26c,
  287. #define NVREG_POWERSTATE_POWEREDUP 0x8000
  288. #define NVREG_POWERSTATE_VALID 0x0100
  289. #define NVREG_POWERSTATE_MASK 0x0003
  290. #define NVREG_POWERSTATE_D0 0x0000
  291. #define NVREG_POWERSTATE_D1 0x0001
  292. #define NVREG_POWERSTATE_D2 0x0002
  293. #define NVREG_POWERSTATE_D3 0x0003
  294. NvRegMgmtUnitControl = 0x278,
  295. #define NVREG_MGMTUNITCONTROL_INUSE 0x20000
  296. NvRegTxCnt = 0x280,
  297. NvRegTxZeroReXmt = 0x284,
  298. NvRegTxOneReXmt = 0x288,
  299. NvRegTxManyReXmt = 0x28c,
  300. NvRegTxLateCol = 0x290,
  301. NvRegTxUnderflow = 0x294,
  302. NvRegTxLossCarrier = 0x298,
  303. NvRegTxExcessDef = 0x29c,
  304. NvRegTxRetryErr = 0x2a0,
  305. NvRegRxFrameErr = 0x2a4,
  306. NvRegRxExtraByte = 0x2a8,
  307. NvRegRxLateCol = 0x2ac,
  308. NvRegRxRunt = 0x2b0,
  309. NvRegRxFrameTooLong = 0x2b4,
  310. NvRegRxOverflow = 0x2b8,
  311. NvRegRxFCSErr = 0x2bc,
  312. NvRegRxFrameAlignErr = 0x2c0,
  313. NvRegRxLenErr = 0x2c4,
  314. NvRegRxUnicast = 0x2c8,
  315. NvRegRxMulticast = 0x2cc,
  316. NvRegRxBroadcast = 0x2d0,
  317. NvRegTxDef = 0x2d4,
  318. NvRegTxFrame = 0x2d8,
  319. NvRegRxCnt = 0x2dc,
  320. NvRegTxPause = 0x2e0,
  321. NvRegRxPause = 0x2e4,
  322. NvRegRxDropFrame = 0x2e8,
  323. NvRegVlanControl = 0x300,
  324. #define NVREG_VLANCONTROL_ENABLE 0x2000
  325. NvRegMSIXMap0 = 0x3e0,
  326. NvRegMSIXMap1 = 0x3e4,
  327. NvRegMSIXIrqStatus = 0x3f0,
  328. NvRegPowerState2 = 0x600,
  329. #define NVREG_POWERSTATE2_POWERUP_MASK 0x0F15
  330. #define NVREG_POWERSTATE2_POWERUP_REV_A3 0x0001
  331. #define NVREG_POWERSTATE2_PHY_RESET 0x0004
  332. #define NVREG_POWERSTATE2_GATE_CLOCKS 0x0F00
  333. };
  334. /* Big endian: should work, but is untested */
  335. struct ring_desc {
  336. __le32 buf;
  337. __le32 flaglen;
  338. };
  339. struct ring_desc_ex {
  340. __le32 bufhigh;
  341. __le32 buflow;
  342. __le32 txvlan;
  343. __le32 flaglen;
  344. };
  345. union ring_type {
  346. struct ring_desc *orig;
  347. struct ring_desc_ex *ex;
  348. };
  349. #define FLAG_MASK_V1 0xffff0000
  350. #define FLAG_MASK_V2 0xffffc000
  351. #define LEN_MASK_V1 (0xffffffff ^ FLAG_MASK_V1)
  352. #define LEN_MASK_V2 (0xffffffff ^ FLAG_MASK_V2)
  353. #define NV_TX_LASTPACKET (1<<16)
  354. #define NV_TX_RETRYERROR (1<<19)
  355. #define NV_TX_RETRYCOUNT_MASK (0xF<<20)
  356. #define NV_TX_FORCED_INTERRUPT (1<<24)
  357. #define NV_TX_DEFERRED (1<<26)
  358. #define NV_TX_CARRIERLOST (1<<27)
  359. #define NV_TX_LATECOLLISION (1<<28)
  360. #define NV_TX_UNDERFLOW (1<<29)
  361. #define NV_TX_ERROR (1<<30)
  362. #define NV_TX_VALID (1<<31)
  363. #define NV_TX2_LASTPACKET (1<<29)
  364. #define NV_TX2_RETRYERROR (1<<18)
  365. #define NV_TX2_RETRYCOUNT_MASK (0xF<<19)
  366. #define NV_TX2_FORCED_INTERRUPT (1<<30)
  367. #define NV_TX2_DEFERRED (1<<25)
  368. #define NV_TX2_CARRIERLOST (1<<26)
  369. #define NV_TX2_LATECOLLISION (1<<27)
  370. #define NV_TX2_UNDERFLOW (1<<28)
  371. /* error and valid are the same for both */
  372. #define NV_TX2_ERROR (1<<30)
  373. #define NV_TX2_VALID (1<<31)
  374. #define NV_TX2_TSO (1<<28)
  375. #define NV_TX2_TSO_SHIFT 14
  376. #define NV_TX2_TSO_MAX_SHIFT 14
  377. #define NV_TX2_TSO_MAX_SIZE (1<<NV_TX2_TSO_MAX_SHIFT)
  378. #define NV_TX2_CHECKSUM_L3 (1<<27)
  379. #define NV_TX2_CHECKSUM_L4 (1<<26)
  380. #define NV_TX3_VLAN_TAG_PRESENT (1<<18)
  381. #define NV_RX_DESCRIPTORVALID (1<<16)
  382. #define NV_RX_MISSEDFRAME (1<<17)
  383. #define NV_RX_SUBSTRACT1 (1<<18)
  384. #define NV_RX_ERROR1 (1<<23)
  385. #define NV_RX_ERROR2 (1<<24)
  386. #define NV_RX_ERROR3 (1<<25)
  387. #define NV_RX_ERROR4 (1<<26)
  388. #define NV_RX_CRCERR (1<<27)
  389. #define NV_RX_OVERFLOW (1<<28)
  390. #define NV_RX_FRAMINGERR (1<<29)
  391. #define NV_RX_ERROR (1<<30)
  392. #define NV_RX_AVAIL (1<<31)
  393. #define NV_RX_ERROR_MASK (NV_RX_ERROR1|NV_RX_ERROR2|NV_RX_ERROR3|NV_RX_ERROR4|NV_RX_CRCERR|NV_RX_OVERFLOW|NV_RX_FRAMINGERR)
  394. #define NV_RX2_CHECKSUMMASK (0x1C000000)
  395. #define NV_RX2_CHECKSUM_IP (0x10000000)
  396. #define NV_RX2_CHECKSUM_IP_TCP (0x14000000)
  397. #define NV_RX2_CHECKSUM_IP_UDP (0x18000000)
  398. #define NV_RX2_DESCRIPTORVALID (1<<29)
  399. #define NV_RX2_SUBSTRACT1 (1<<25)
  400. #define NV_RX2_ERROR1 (1<<18)
  401. #define NV_RX2_ERROR2 (1<<19)
  402. #define NV_RX2_ERROR3 (1<<20)
  403. #define NV_RX2_ERROR4 (1<<21)
  404. #define NV_RX2_CRCERR (1<<22)
  405. #define NV_RX2_OVERFLOW (1<<23)
  406. #define NV_RX2_FRAMINGERR (1<<24)
  407. /* error and avail are the same for both */
  408. #define NV_RX2_ERROR (1<<30)
  409. #define NV_RX2_AVAIL (1<<31)
  410. #define NV_RX2_ERROR_MASK (NV_RX2_ERROR1|NV_RX2_ERROR2|NV_RX2_ERROR3|NV_RX2_ERROR4|NV_RX2_CRCERR|NV_RX2_OVERFLOW|NV_RX2_FRAMINGERR)
  411. #define NV_RX3_VLAN_TAG_PRESENT (1<<16)
  412. #define NV_RX3_VLAN_TAG_MASK (0x0000FFFF)
  413. /* Miscellaneous hardware related defines: */
  414. #define NV_PCI_REGSZ_VER1 0x270
  415. #define NV_PCI_REGSZ_VER2 0x2d4
  416. #define NV_PCI_REGSZ_VER3 0x604
  417. #define NV_PCI_REGSZ_MAX 0x604
  418. /* various timeout delays: all in usec */
  419. #define NV_TXRX_RESET_DELAY 4
  420. #define NV_TXSTOP_DELAY1 10
  421. #define NV_TXSTOP_DELAY1MAX 500000
  422. #define NV_TXSTOP_DELAY2 100
  423. #define NV_RXSTOP_DELAY1 10
  424. #define NV_RXSTOP_DELAY1MAX 500000
  425. #define NV_RXSTOP_DELAY2 100
  426. #define NV_SETUP5_DELAY 5
  427. #define NV_SETUP5_DELAYMAX 50000
  428. #define NV_POWERUP_DELAY 5
  429. #define NV_POWERUP_DELAYMAX 5000
  430. #define NV_MIIBUSY_DELAY 50
  431. #define NV_MIIPHY_DELAY 10
  432. #define NV_MIIPHY_DELAYMAX 10000
  433. #define NV_MAC_RESET_DELAY 64
  434. #define NV_WAKEUPPATTERNS 5
  435. #define NV_WAKEUPMASKENTRIES 4
  436. /* General driver defaults */
  437. #define NV_WATCHDOG_TIMEO (5*HZ)
  438. #define RX_RING_DEFAULT 512
  439. #define TX_RING_DEFAULT 256
  440. #define RX_RING_MIN 128
  441. #define TX_RING_MIN 64
  442. #define RING_MAX_DESC_VER_1 1024
  443. #define RING_MAX_DESC_VER_2_3 16384
  444. /* rx/tx mac addr + type + vlan + align + slack*/
  445. #define NV_RX_HEADERS (64)
  446. /* even more slack. */
  447. #define NV_RX_ALLOC_PAD (64)
  448. /* maximum mtu size */
  449. #define NV_PKTLIMIT_1 ETH_DATA_LEN /* hard limit not known */
  450. #define NV_PKTLIMIT_2 9100 /* Actual limit according to NVidia: 9202 */
  451. #define OOM_REFILL (1+HZ/20)
  452. #define POLL_WAIT (1+HZ/100)
  453. #define LINK_TIMEOUT (3*HZ)
  454. #define STATS_INTERVAL (10*HZ)
  455. /*
  456. * desc_ver values:
  457. * The nic supports three different descriptor types:
  458. * - DESC_VER_1: Original
  459. * - DESC_VER_2: support for jumbo frames.
  460. * - DESC_VER_3: 64-bit format.
  461. */
  462. #define DESC_VER_1 1
  463. #define DESC_VER_2 2
  464. #define DESC_VER_3 3
  465. /* PHY defines */
  466. #define PHY_OUI_MARVELL 0x5043
  467. #define PHY_OUI_CICADA 0x03f1
  468. #define PHY_OUI_VITESSE 0x01c1
  469. #define PHY_OUI_REALTEK 0x0732
  470. #define PHY_OUI_REALTEK2 0x0020
  471. #define PHYID1_OUI_MASK 0x03ff
  472. #define PHYID1_OUI_SHFT 6
  473. #define PHYID2_OUI_MASK 0xfc00
  474. #define PHYID2_OUI_SHFT 10
  475. #define PHYID2_MODEL_MASK 0x03f0
  476. #define PHY_MODEL_REALTEK_8211 0x0110
  477. #define PHY_REV_MASK 0x0001
  478. #define PHY_REV_REALTEK_8211B 0x0000
  479. #define PHY_REV_REALTEK_8211C 0x0001
  480. #define PHY_MODEL_REALTEK_8201 0x0200
  481. #define PHY_MODEL_MARVELL_E3016 0x0220
  482. #define PHY_MARVELL_E3016_INITMASK 0x0300
  483. #define PHY_CICADA_INIT1 0x0f000
  484. #define PHY_CICADA_INIT2 0x0e00
  485. #define PHY_CICADA_INIT3 0x01000
  486. #define PHY_CICADA_INIT4 0x0200
  487. #define PHY_CICADA_INIT5 0x0004
  488. #define PHY_CICADA_INIT6 0x02000
  489. #define PHY_VITESSE_INIT_REG1 0x1f
  490. #define PHY_VITESSE_INIT_REG2 0x10
  491. #define PHY_VITESSE_INIT_REG3 0x11
  492. #define PHY_VITESSE_INIT_REG4 0x12
  493. #define PHY_VITESSE_INIT_MSK1 0xc
  494. #define PHY_VITESSE_INIT_MSK2 0x0180
  495. #define PHY_VITESSE_INIT1 0x52b5
  496. #define PHY_VITESSE_INIT2 0xaf8a
  497. #define PHY_VITESSE_INIT3 0x8
  498. #define PHY_VITESSE_INIT4 0x8f8a
  499. #define PHY_VITESSE_INIT5 0xaf86
  500. #define PHY_VITESSE_INIT6 0x8f86
  501. #define PHY_VITESSE_INIT7 0xaf82
  502. #define PHY_VITESSE_INIT8 0x0100
  503. #define PHY_VITESSE_INIT9 0x8f82
  504. #define PHY_VITESSE_INIT10 0x0
  505. #define PHY_REALTEK_INIT_REG1 0x1f
  506. #define PHY_REALTEK_INIT_REG2 0x19
  507. #define PHY_REALTEK_INIT_REG3 0x13
  508. #define PHY_REALTEK_INIT_REG4 0x14
  509. #define PHY_REALTEK_INIT_REG5 0x18
  510. #define PHY_REALTEK_INIT_REG6 0x11
  511. #define PHY_REALTEK_INIT_REG7 0x01
  512. #define PHY_REALTEK_INIT1 0x0000
  513. #define PHY_REALTEK_INIT2 0x8e00
  514. #define PHY_REALTEK_INIT3 0x0001
  515. #define PHY_REALTEK_INIT4 0xad17
  516. #define PHY_REALTEK_INIT5 0xfb54
  517. #define PHY_REALTEK_INIT6 0xf5c7
  518. #define PHY_REALTEK_INIT7 0x1000
  519. #define PHY_REALTEK_INIT8 0x0003
  520. #define PHY_REALTEK_INIT9 0x0008
  521. #define PHY_REALTEK_INIT10 0x0005
  522. #define PHY_REALTEK_INIT11 0x0200
  523. #define PHY_REALTEK_INIT_MSK1 0x0003
  524. #define PHY_GIGABIT 0x0100
  525. #define PHY_TIMEOUT 0x1
  526. #define PHY_ERROR 0x2
  527. #define PHY_100 0x1
  528. #define PHY_1000 0x2
  529. #define PHY_HALF 0x100
  530. #define NV_PAUSEFRAME_RX_CAPABLE 0x0001
  531. #define NV_PAUSEFRAME_TX_CAPABLE 0x0002
  532. #define NV_PAUSEFRAME_RX_ENABLE 0x0004
  533. #define NV_PAUSEFRAME_TX_ENABLE 0x0008
  534. #define NV_PAUSEFRAME_RX_REQ 0x0010
  535. #define NV_PAUSEFRAME_TX_REQ 0x0020
  536. #define NV_PAUSEFRAME_AUTONEG 0x0040
  537. /* MSI/MSI-X defines */
  538. #define NV_MSI_X_MAX_VECTORS 8
  539. #define NV_MSI_X_VECTORS_MASK 0x000f
  540. #define NV_MSI_CAPABLE 0x0010
  541. #define NV_MSI_X_CAPABLE 0x0020
  542. #define NV_MSI_ENABLED 0x0040
  543. #define NV_MSI_X_ENABLED 0x0080
  544. #define NV_MSI_X_VECTOR_ALL 0x0
  545. #define NV_MSI_X_VECTOR_RX 0x0
  546. #define NV_MSI_X_VECTOR_TX 0x1
  547. #define NV_MSI_X_VECTOR_OTHER 0x2
  548. #define NV_MSI_PRIV_OFFSET 0x68
  549. #define NV_MSI_PRIV_VALUE 0xffffffff
  550. #define NV_RESTART_TX 0x1
  551. #define NV_RESTART_RX 0x2
  552. #define NV_TX_LIMIT_COUNT 16
  553. #define NV_DYNAMIC_THRESHOLD 4
  554. #define NV_DYNAMIC_MAX_QUIET_COUNT 2048
  555. /* statistics */
  556. struct nv_ethtool_str {
  557. char name[ETH_GSTRING_LEN];
  558. };
  559. static const struct nv_ethtool_str nv_estats_str[] = {
  560. { "tx_bytes" }, /* includes Ethernet FCS CRC */
  561. { "tx_zero_rexmt" },
  562. { "tx_one_rexmt" },
  563. { "tx_many_rexmt" },
  564. { "tx_late_collision" },
  565. { "tx_fifo_errors" },
  566. { "tx_carrier_errors" },
  567. { "tx_excess_deferral" },
  568. { "tx_retry_error" },
  569. { "rx_frame_error" },
  570. { "rx_extra_byte" },
  571. { "rx_late_collision" },
  572. { "rx_runt" },
  573. { "rx_frame_too_long" },
  574. { "rx_over_errors" },
  575. { "rx_crc_errors" },
  576. { "rx_frame_align_error" },
  577. { "rx_length_error" },
  578. { "rx_unicast" },
  579. { "rx_multicast" },
  580. { "rx_broadcast" },
  581. { "rx_packets" },
  582. { "rx_errors_total" },
  583. { "tx_errors_total" },
  584. /* version 2 stats */
  585. { "tx_deferral" },
  586. { "tx_packets" },
  587. { "rx_bytes" }, /* includes Ethernet FCS CRC */
  588. { "tx_pause" },
  589. { "rx_pause" },
  590. { "rx_drop_frame" },
  591. /* version 3 stats */
  592. { "tx_unicast" },
  593. { "tx_multicast" },
  594. { "tx_broadcast" }
  595. };
  596. struct nv_ethtool_stats {
  597. u64 tx_bytes; /* should be ifconfig->tx_bytes + 4*tx_packets */
  598. u64 tx_zero_rexmt;
  599. u64 tx_one_rexmt;
  600. u64 tx_many_rexmt;
  601. u64 tx_late_collision;
  602. u64 tx_fifo_errors;
  603. u64 tx_carrier_errors;
  604. u64 tx_excess_deferral;
  605. u64 tx_retry_error;
  606. u64 rx_frame_error;
  607. u64 rx_extra_byte;
  608. u64 rx_late_collision;
  609. u64 rx_runt;
  610. u64 rx_frame_too_long;
  611. u64 rx_over_errors;
  612. u64 rx_crc_errors;
  613. u64 rx_frame_align_error;
  614. u64 rx_length_error;
  615. u64 rx_unicast;
  616. u64 rx_multicast;
  617. u64 rx_broadcast;
  618. u64 rx_packets; /* should be ifconfig->rx_packets */
  619. u64 rx_errors_total;
  620. u64 tx_errors_total;
  621. /* version 2 stats */
  622. u64 tx_deferral;
  623. u64 tx_packets; /* should be ifconfig->tx_packets */
  624. u64 rx_bytes; /* should be ifconfig->rx_bytes + 4*rx_packets */
  625. u64 tx_pause;
  626. u64 rx_pause;
  627. u64 rx_drop_frame;
  628. /* version 3 stats */
  629. u64 tx_unicast;
  630. u64 tx_multicast;
  631. u64 tx_broadcast;
  632. };
  633. #define NV_DEV_STATISTICS_V3_COUNT (sizeof(struct nv_ethtool_stats)/sizeof(u64))
  634. #define NV_DEV_STATISTICS_V2_COUNT (NV_DEV_STATISTICS_V3_COUNT - 3)
  635. #define NV_DEV_STATISTICS_V1_COUNT (NV_DEV_STATISTICS_V2_COUNT - 6)
  636. /* diagnostics */
  637. #define NV_TEST_COUNT_BASE 3
  638. #define NV_TEST_COUNT_EXTENDED 4
  639. static const struct nv_ethtool_str nv_etests_str[] = {
  640. { "link (online/offline)" },
  641. { "register (offline) " },
  642. { "interrupt (offline) " },
  643. { "loopback (offline) " }
  644. };
  645. struct register_test {
  646. __u32 reg;
  647. __u32 mask;
  648. };
  649. static const struct register_test nv_registers_test[] = {
  650. { NvRegUnknownSetupReg6, 0x01 },
  651. { NvRegMisc1, 0x03c },
  652. { NvRegOffloadConfig, 0x03ff },
  653. { NvRegMulticastAddrA, 0xffffffff },
  654. { NvRegTxWatermark, 0x0ff },
  655. { NvRegWakeUpFlags, 0x07777 },
  656. { 0, 0 }
  657. };
  658. struct nv_skb_map {
  659. struct sk_buff *skb;
  660. dma_addr_t dma;
  661. unsigned int dma_len:31;
  662. unsigned int dma_single:1;
  663. struct ring_desc_ex *first_tx_desc;
  664. struct nv_skb_map *next_tx_ctx;
  665. };
  666. /*
  667. * SMP locking:
  668. * All hardware access under netdev_priv(dev)->lock, except the performance
  669. * critical parts:
  670. * - rx is (pseudo-) lockless: it relies on the single-threading provided
  671. * by the arch code for interrupts.
  672. * - tx setup is lockless: it relies on netif_tx_lock. Actual submission
  673. * needs netdev_priv(dev)->lock :-(
  674. * - set_multicast_list: preparation lockless, relies on netif_tx_lock.
  675. *
  676. * Hardware stats updates are protected by hwstats_lock:
  677. * - updated by nv_do_stats_poll (timer). This is meant to avoid
  678. * integer wraparound in the NIC stats registers, at low frequency
  679. * (0.1 Hz)
  680. * - updated by nv_get_ethtool_stats + nv_get_stats64
  681. *
  682. * Software stats are accessed only through 64b synchronization points
  683. * and are not subject to other synchronization techniques (single
  684. * update thread on the TX or RX paths).
  685. */
  686. /* in dev: base, irq */
  687. struct fe_priv {
  688. spinlock_t lock;
  689. struct net_device *dev;
  690. struct napi_struct napi;
  691. /* hardware stats are updated in syscall and timer */
  692. spinlock_t hwstats_lock;
  693. struct nv_ethtool_stats estats;
  694. int in_shutdown;
  695. u32 linkspeed;
  696. int duplex;
  697. int autoneg;
  698. int fixed_mode;
  699. int phyaddr;
  700. int wolenabled;
  701. unsigned int phy_oui;
  702. unsigned int phy_model;
  703. unsigned int phy_rev;
  704. u16 gigabit;
  705. int intr_test;
  706. int recover_error;
  707. int quiet_count;
  708. /* General data: RO fields */
  709. dma_addr_t ring_addr;
  710. struct pci_dev *pci_dev;
  711. u32 orig_mac[2];
  712. u32 events;
  713. u32 irqmask;
  714. u32 desc_ver;
  715. u32 txrxctl_bits;
  716. u32 vlanctl_bits;
  717. u32 driver_data;
  718. u32 device_id;
  719. u32 register_size;
  720. u32 mac_in_use;
  721. int mgmt_version;
  722. int mgmt_sema;
  723. void __iomem *base;
  724. /* rx specific fields.
  725. * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
  726. */
  727. union ring_type get_rx, put_rx, first_rx, last_rx;
  728. struct nv_skb_map *get_rx_ctx, *put_rx_ctx;
  729. struct nv_skb_map *first_rx_ctx, *last_rx_ctx;
  730. struct nv_skb_map *rx_skb;
  731. union ring_type rx_ring;
  732. unsigned int rx_buf_sz;
  733. unsigned int pkt_limit;
  734. struct timer_list oom_kick;
  735. struct timer_list nic_poll;
  736. struct timer_list stats_poll;
  737. u32 nic_poll_irq;
  738. int rx_ring_size;
  739. /* RX software stats */
  740. struct u64_stats_sync swstats_rx_syncp;
  741. u64 stat_rx_packets;
  742. u64 stat_rx_bytes; /* not always available in HW */
  743. u64 stat_rx_missed_errors;
  744. u64 stat_rx_dropped;
  745. /* media detection workaround.
  746. * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
  747. */
  748. int need_linktimer;
  749. unsigned long link_timeout;
  750. /*
  751. * tx specific fields.
  752. */
  753. union ring_type get_tx, put_tx, first_tx, last_tx;
  754. struct nv_skb_map *get_tx_ctx, *put_tx_ctx;
  755. struct nv_skb_map *first_tx_ctx, *last_tx_ctx;
  756. struct nv_skb_map *tx_skb;
  757. union ring_type tx_ring;
  758. u32 tx_flags;
  759. int tx_ring_size;
  760. int tx_limit;
  761. u32 tx_pkts_in_progress;
  762. struct nv_skb_map *tx_change_owner;
  763. struct nv_skb_map *tx_end_flip;
  764. int tx_stop;
  765. /* TX software stats */
  766. struct u64_stats_sync swstats_tx_syncp;
  767. u64 stat_tx_packets; /* not always available in HW */
  768. u64 stat_tx_bytes;
  769. u64 stat_tx_dropped;
  770. /* msi/msi-x fields */
  771. u32 msi_flags;
  772. struct msix_entry msi_x_entry[NV_MSI_X_MAX_VECTORS];
  773. /* flow control */
  774. u32 pause_flags;
  775. /* power saved state */
  776. u32 saved_config_space[NV_PCI_REGSZ_MAX/4];
  777. /* for different msi-x irq type */
  778. char name_rx[IFNAMSIZ + 3]; /* -rx */
  779. char name_tx[IFNAMSIZ + 3]; /* -tx */
  780. char name_other[IFNAMSIZ + 6]; /* -other */
  781. };
  782. /*
  783. * Maximum number of loops until we assume that a bit in the irq mask
  784. * is stuck. Overridable with module param.
  785. */
  786. static int max_interrupt_work = 4;
  787. /*
  788. * Optimization can be either throuput mode or cpu mode
  789. *
  790. * Throughput Mode: Every tx and rx packet will generate an interrupt.
  791. * CPU Mode: Interrupts are controlled by a timer.
  792. */
  793. enum {
  794. NV_OPTIMIZATION_MODE_THROUGHPUT,
  795. NV_OPTIMIZATION_MODE_CPU,
  796. NV_OPTIMIZATION_MODE_DYNAMIC
  797. };
  798. static int optimization_mode = NV_OPTIMIZATION_MODE_DYNAMIC;
  799. /*
  800. * Poll interval for timer irq
  801. *
  802. * This interval determines how frequent an interrupt is generated.
  803. * The is value is determined by [(time_in_micro_secs * 100) / (2^10)]
  804. * Min = 0, and Max = 65535
  805. */
  806. static int poll_interval = -1;
  807. /*
  808. * MSI interrupts
  809. */
  810. enum {
  811. NV_MSI_INT_DISABLED,
  812. NV_MSI_INT_ENABLED
  813. };
  814. static int msi = NV_MSI_INT_ENABLED;
  815. /*
  816. * MSIX interrupts
  817. */
  818. enum {
  819. NV_MSIX_INT_DISABLED,
  820. NV_MSIX_INT_ENABLED
  821. };
  822. static int msix = NV_MSIX_INT_ENABLED;
  823. /*
  824. * DMA 64bit
  825. */
  826. enum {
  827. NV_DMA_64BIT_DISABLED,
  828. NV_DMA_64BIT_ENABLED
  829. };
  830. static int dma_64bit = NV_DMA_64BIT_ENABLED;
  831. /*
  832. * Debug output control for tx_timeout
  833. */
  834. static bool debug_tx_timeout = false;
  835. /*
  836. * Crossover Detection
  837. * Realtek 8201 phy + some OEM boards do not work properly.
  838. */
  839. enum {
  840. NV_CROSSOVER_DETECTION_DISABLED,
  841. NV_CROSSOVER_DETECTION_ENABLED
  842. };
  843. static int phy_cross = NV_CROSSOVER_DETECTION_DISABLED;
  844. /*
  845. * Power down phy when interface is down (persists through reboot;
  846. * older Linux and other OSes may not power it up again)
  847. */
  848. static int phy_power_down;
  849. static inline struct fe_priv *get_nvpriv(struct net_device *dev)
  850. {
  851. return netdev_priv(dev);
  852. }
  853. static inline u8 __iomem *get_hwbase(struct net_device *dev)
  854. {
  855. return ((struct fe_priv *)netdev_priv(dev))->base;
  856. }
  857. static inline void pci_push(u8 __iomem *base)
  858. {
  859. /* force out pending posted writes */
  860. readl(base);
  861. }
  862. static inline u32 nv_descr_getlength(struct ring_desc *prd, u32 v)
  863. {
  864. return le32_to_cpu(prd->flaglen)
  865. & ((v == DESC_VER_1) ? LEN_MASK_V1 : LEN_MASK_V2);
  866. }
  867. static inline u32 nv_descr_getlength_ex(struct ring_desc_ex *prd, u32 v)
  868. {
  869. return le32_to_cpu(prd->flaglen) & LEN_MASK_V2;
  870. }
  871. static bool nv_optimized(struct fe_priv *np)
  872. {
  873. if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
  874. return false;
  875. return true;
  876. }
  877. static int reg_delay(struct net_device *dev, int offset, u32 mask, u32 target,
  878. int delay, int delaymax)
  879. {
  880. u8 __iomem *base = get_hwbase(dev);
  881. pci_push(base);
  882. do {
  883. udelay(delay);
  884. delaymax -= delay;
  885. if (delaymax < 0)
  886. return 1;
  887. } while ((readl(base + offset) & mask) != target);
  888. return 0;
  889. }
  890. #define NV_SETUP_RX_RING 0x01
  891. #define NV_SETUP_TX_RING 0x02
  892. static inline u32 dma_low(dma_addr_t addr)
  893. {
  894. return addr;
  895. }
  896. static inline u32 dma_high(dma_addr_t addr)
  897. {
  898. return addr>>31>>1; /* 0 if 32bit, shift down by 32 if 64bit */
  899. }
  900. static void setup_hw_rings(struct net_device *dev, int rxtx_flags)
  901. {
  902. struct fe_priv *np = get_nvpriv(dev);
  903. u8 __iomem *base = get_hwbase(dev);
  904. if (!nv_optimized(np)) {
  905. if (rxtx_flags & NV_SETUP_RX_RING)
  906. writel(dma_low(np->ring_addr), base + NvRegRxRingPhysAddr);
  907. if (rxtx_flags & NV_SETUP_TX_RING)
  908. writel(dma_low(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr);
  909. } else {
  910. if (rxtx_flags & NV_SETUP_RX_RING) {
  911. writel(dma_low(np->ring_addr), base + NvRegRxRingPhysAddr);
  912. writel(dma_high(np->ring_addr), base + NvRegRxRingPhysAddrHigh);
  913. }
  914. if (rxtx_flags & NV_SETUP_TX_RING) {
  915. writel(dma_low(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr);
  916. writel(dma_high(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddrHigh);
  917. }
  918. }
  919. }
  920. static void free_rings(struct net_device *dev)
  921. {
  922. struct fe_priv *np = get_nvpriv(dev);
  923. if (!nv_optimized(np)) {
  924. if (np->rx_ring.orig)
  925. pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
  926. np->rx_ring.orig, np->ring_addr);
  927. } else {
  928. if (np->rx_ring.ex)
  929. pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
  930. np->rx_ring.ex, np->ring_addr);
  931. }
  932. kfree(np->rx_skb);
  933. kfree(np->tx_skb);
  934. }
  935. static int using_multi_irqs(struct net_device *dev)
  936. {
  937. struct fe_priv *np = get_nvpriv(dev);
  938. if (!(np->msi_flags & NV_MSI_X_ENABLED) ||
  939. ((np->msi_flags & NV_MSI_X_ENABLED) &&
  940. ((np->msi_flags & NV_MSI_X_VECTORS_MASK) == 0x1)))
  941. return 0;
  942. else
  943. return 1;
  944. }
  945. static void nv_txrx_gate(struct net_device *dev, bool gate)
  946. {
  947. struct fe_priv *np = get_nvpriv(dev);
  948. u8 __iomem *base = get_hwbase(dev);
  949. u32 powerstate;
  950. if (!np->mac_in_use &&
  951. (np->driver_data & DEV_HAS_POWER_CNTRL)) {
  952. powerstate = readl(base + NvRegPowerState2);
  953. if (gate)
  954. powerstate |= NVREG_POWERSTATE2_GATE_CLOCKS;
  955. else
  956. powerstate &= ~NVREG_POWERSTATE2_GATE_CLOCKS;
  957. writel(powerstate, base + NvRegPowerState2);
  958. }
  959. }
  960. static void nv_enable_irq(struct net_device *dev)
  961. {
  962. struct fe_priv *np = get_nvpriv(dev);
  963. if (!using_multi_irqs(dev)) {
  964. if (np->msi_flags & NV_MSI_X_ENABLED)
  965. enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
  966. else
  967. enable_irq(np->pci_dev->irq);
  968. } else {
  969. enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
  970. enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
  971. enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
  972. }
  973. }
  974. static void nv_disable_irq(struct net_device *dev)
  975. {
  976. struct fe_priv *np = get_nvpriv(dev);
  977. if (!using_multi_irqs(dev)) {
  978. if (np->msi_flags & NV_MSI_X_ENABLED)
  979. disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
  980. else
  981. disable_irq(np->pci_dev->irq);
  982. } else {
  983. disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
  984. disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
  985. disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
  986. }
  987. }
  988. /* In MSIX mode, a write to irqmask behaves as XOR */
  989. static void nv_enable_hw_interrupts(struct net_device *dev, u32 mask)
  990. {
  991. u8 __iomem *base = get_hwbase(dev);
  992. writel(mask, base + NvRegIrqMask);
  993. }
  994. static void nv_disable_hw_interrupts(struct net_device *dev, u32 mask)
  995. {
  996. struct fe_priv *np = get_nvpriv(dev);
  997. u8 __iomem *base = get_hwbase(dev);
  998. if (np->msi_flags & NV_MSI_X_ENABLED) {
  999. writel(mask, base + NvRegIrqMask);
  1000. } else {
  1001. if (np->msi_flags & NV_MSI_ENABLED)
  1002. writel(0, base + NvRegMSIIrqMask);
  1003. writel(0, base + NvRegIrqMask);
  1004. }
  1005. }
  1006. static void nv_napi_enable(struct net_device *dev)
  1007. {
  1008. struct fe_priv *np = get_nvpriv(dev);
  1009. napi_enable(&np->napi);
  1010. }
  1011. static void nv_napi_disable(struct net_device *dev)
  1012. {
  1013. struct fe_priv *np = get_nvpriv(dev);
  1014. napi_disable(&np->napi);
  1015. }
  1016. #define MII_READ (-1)
  1017. /* mii_rw: read/write a register on the PHY.
  1018. *
  1019. * Caller must guarantee serialization
  1020. */
  1021. static int mii_rw(struct net_device *dev, int addr, int miireg, int value)
  1022. {
  1023. u8 __iomem *base = get_hwbase(dev);
  1024. u32 reg;
  1025. int retval;
  1026. writel(NVREG_MIISTAT_MASK_RW, base + NvRegMIIStatus);
  1027. reg = readl(base + NvRegMIIControl);
  1028. if (reg & NVREG_MIICTL_INUSE) {
  1029. writel(NVREG_MIICTL_INUSE, base + NvRegMIIControl);
  1030. udelay(NV_MIIBUSY_DELAY);
  1031. }
  1032. reg = (addr << NVREG_MIICTL_ADDRSHIFT) | miireg;
  1033. if (value != MII_READ) {
  1034. writel(value, base + NvRegMIIData);
  1035. reg |= NVREG_MIICTL_WRITE;
  1036. }
  1037. writel(reg, base + NvRegMIIControl);
  1038. if (reg_delay(dev, NvRegMIIControl, NVREG_MIICTL_INUSE, 0,
  1039. NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX)) {
  1040. retval = -1;
  1041. } else if (value != MII_READ) {
  1042. /* it was a write operation - fewer failures are detectable */
  1043. retval = 0;
  1044. } else if (readl(base + NvRegMIIStatus) & NVREG_MIISTAT_ERROR) {
  1045. retval = -1;
  1046. } else {
  1047. retval = readl(base + NvRegMIIData);
  1048. }
  1049. return retval;
  1050. }
  1051. static int phy_reset(struct net_device *dev, u32 bmcr_setup)
  1052. {
  1053. struct fe_priv *np = netdev_priv(dev);
  1054. u32 miicontrol;
  1055. unsigned int tries = 0;
  1056. miicontrol = BMCR_RESET | bmcr_setup;
  1057. if (mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol))
  1058. return -1;
  1059. /* wait for 500ms */
  1060. msleep(500);
  1061. /* must wait till reset is deasserted */
  1062. while (miicontrol & BMCR_RESET) {
  1063. usleep_range(10000, 20000);
  1064. miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
  1065. /* FIXME: 100 tries seem excessive */
  1066. if (tries++ > 100)
  1067. return -1;
  1068. }
  1069. return 0;
  1070. }
  1071. static int init_realtek_8211b(struct net_device *dev, struct fe_priv *np)
  1072. {
  1073. static const struct {
  1074. int reg;
  1075. int init;
  1076. } ri[] = {
  1077. { PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1 },
  1078. { PHY_REALTEK_INIT_REG2, PHY_REALTEK_INIT2 },
  1079. { PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3 },
  1080. { PHY_REALTEK_INIT_REG3, PHY_REALTEK_INIT4 },
  1081. { PHY_REALTEK_INIT_REG4, PHY_REALTEK_INIT5 },
  1082. { PHY_REALTEK_INIT_REG5, PHY_REALTEK_INIT6 },
  1083. { PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1 },
  1084. };
  1085. int i;
  1086. for (i = 0; i < ARRAY_SIZE(ri); i++) {
  1087. if (mii_rw(dev, np->phyaddr, ri[i].reg, ri[i].init))
  1088. return PHY_ERROR;
  1089. }
  1090. return 0;
  1091. }
  1092. static int init_realtek_8211c(struct net_device *dev, struct fe_priv *np)
  1093. {
  1094. u32 reg;
  1095. u8 __iomem *base = get_hwbase(dev);
  1096. u32 powerstate = readl(base + NvRegPowerState2);
  1097. /* need to perform hw phy reset */
  1098. powerstate |= NVREG_POWERSTATE2_PHY_RESET;
  1099. writel(powerstate, base + NvRegPowerState2);
  1100. msleep(25);
  1101. powerstate &= ~NVREG_POWERSTATE2_PHY_RESET;
  1102. writel(powerstate, base + NvRegPowerState2);
  1103. msleep(25);
  1104. reg = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, MII_READ);
  1105. reg |= PHY_REALTEK_INIT9;
  1106. if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, reg))
  1107. return PHY_ERROR;
  1108. if (mii_rw(dev, np->phyaddr,
  1109. PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT10))
  1110. return PHY_ERROR;
  1111. reg = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG7, MII_READ);
  1112. if (!(reg & PHY_REALTEK_INIT11)) {
  1113. reg |= PHY_REALTEK_INIT11;
  1114. if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG7, reg))
  1115. return PHY_ERROR;
  1116. }
  1117. if (mii_rw(dev, np->phyaddr,
  1118. PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1))
  1119. return PHY_ERROR;
  1120. return 0;
  1121. }
  1122. static int init_realtek_8201(struct net_device *dev, struct fe_priv *np)
  1123. {
  1124. u32 phy_reserved;
  1125. if (np->driver_data & DEV_NEED_PHY_INIT_FIX) {
  1126. phy_reserved = mii_rw(dev, np->phyaddr,
  1127. PHY_REALTEK_INIT_REG6, MII_READ);
  1128. phy_reserved |= PHY_REALTEK_INIT7;
  1129. if (mii_rw(dev, np->phyaddr,
  1130. PHY_REALTEK_INIT_REG6, phy_reserved))
  1131. return PHY_ERROR;
  1132. }
  1133. return 0;
  1134. }
  1135. static int init_realtek_8201_cross(struct net_device *dev, struct fe_priv *np)
  1136. {
  1137. u32 phy_reserved;
  1138. if (phy_cross == NV_CROSSOVER_DETECTION_DISABLED) {
  1139. if (mii_rw(dev, np->phyaddr,
  1140. PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3))
  1141. return PHY_ERROR;
  1142. phy_reserved = mii_rw(dev, np->phyaddr,
  1143. PHY_REALTEK_INIT_REG2, MII_READ);
  1144. phy_reserved &= ~PHY_REALTEK_INIT_MSK1;
  1145. phy_reserved |= PHY_REALTEK_INIT3;
  1146. if (mii_rw(dev, np->phyaddr,
  1147. PHY_REALTEK_INIT_REG2, phy_reserved))
  1148. return PHY_ERROR;
  1149. if (mii_rw(dev, np->phyaddr,
  1150. PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1))
  1151. return PHY_ERROR;
  1152. }
  1153. return 0;
  1154. }
  1155. static int init_cicada(struct net_device *dev, struct fe_priv *np,
  1156. u32 phyinterface)
  1157. {
  1158. u32 phy_reserved;
  1159. if (phyinterface & PHY_RGMII) {
  1160. phy_reserved = mii_rw(dev, np->phyaddr, MII_RESV1, MII_READ);
  1161. phy_reserved &= ~(PHY_CICADA_INIT1 | PHY_CICADA_INIT2);
  1162. phy_reserved |= (PHY_CICADA_INIT3 | PHY_CICADA_INIT4);
  1163. if (mii_rw(dev, np->phyaddr, MII_RESV1, phy_reserved))
  1164. return PHY_ERROR;
  1165. phy_reserved = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
  1166. phy_reserved |= PHY_CICADA_INIT5;
  1167. if (mii_rw(dev, np->phyaddr, MII_NCONFIG, phy_reserved))
  1168. return PHY_ERROR;
  1169. }
  1170. phy_reserved = mii_rw(dev, np->phyaddr, MII_SREVISION, MII_READ);
  1171. phy_reserved |= PHY_CICADA_INIT6;
  1172. if (mii_rw(dev, np->phyaddr, MII_SREVISION, phy_reserved))
  1173. return PHY_ERROR;
  1174. return 0;
  1175. }
  1176. static int init_vitesse(struct net_device *dev, struct fe_priv *np)
  1177. {
  1178. u32 phy_reserved;
  1179. if (mii_rw(dev, np->phyaddr,
  1180. PHY_VITESSE_INIT_REG1, PHY_VITESSE_INIT1))
  1181. return PHY_ERROR;
  1182. if (mii_rw(dev, np->phyaddr,
  1183. PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT2))
  1184. return PHY_ERROR;
  1185. phy_reserved = mii_rw(dev, np->phyaddr,
  1186. PHY_VITESSE_INIT_REG4, MII_READ);
  1187. if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved))
  1188. return PHY_ERROR;
  1189. phy_reserved = mii_rw(dev, np->phyaddr,
  1190. PHY_VITESSE_INIT_REG3, MII_READ);
  1191. phy_reserved &= ~PHY_VITESSE_INIT_MSK1;
  1192. phy_reserved |= PHY_VITESSE_INIT3;
  1193. if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved))
  1194. return PHY_ERROR;
  1195. if (mii_rw(dev, np->phyaddr,
  1196. PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT4))
  1197. return PHY_ERROR;
  1198. if (mii_rw(dev, np->phyaddr,
  1199. PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT5))
  1200. return PHY_ERROR;
  1201. phy_reserved = mii_rw(dev, np->phyaddr,
  1202. PHY_VITESSE_INIT_REG4, MII_READ);
  1203. phy_reserved &= ~PHY_VITESSE_INIT_MSK1;
  1204. phy_reserved |= PHY_VITESSE_INIT3;
  1205. if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved))
  1206. return PHY_ERROR;
  1207. phy_reserved = mii_rw(dev, np->phyaddr,
  1208. PHY_VITESSE_INIT_REG3, MII_READ);
  1209. if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved))
  1210. return PHY_ERROR;
  1211. if (mii_rw(dev, np->phyaddr,
  1212. PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT6))
  1213. return PHY_ERROR;
  1214. if (mii_rw(dev, np->phyaddr,
  1215. PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT7))
  1216. return PHY_ERROR;
  1217. phy_reserved = mii_rw(dev, np->phyaddr,
  1218. PHY_VITESSE_INIT_REG4, MII_READ);
  1219. if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved))
  1220. return PHY_ERROR;
  1221. phy_reserved = mii_rw(dev, np->phyaddr,
  1222. PHY_VITESSE_INIT_REG3, MII_READ);
  1223. phy_reserved &= ~PHY_VITESSE_INIT_MSK2;
  1224. phy_reserved |= PHY_VITESSE_INIT8;
  1225. if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved))
  1226. return PHY_ERROR;
  1227. if (mii_rw(dev, np->phyaddr,
  1228. PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT9))
  1229. return PHY_ERROR;
  1230. if (mii_rw(dev, np->phyaddr,
  1231. PHY_VITESSE_INIT_REG1, PHY_VITESSE_INIT10))
  1232. return PHY_ERROR;
  1233. return 0;
  1234. }
  1235. static int phy_init(struct net_device *dev)
  1236. {
  1237. struct fe_priv *np = get_nvpriv(dev);
  1238. u8 __iomem *base = get_hwbase(dev);
  1239. u32 phyinterface;
  1240. u32 mii_status, mii_control, mii_control_1000, reg;
  1241. /* phy errata for E3016 phy */
  1242. if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
  1243. reg = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
  1244. reg &= ~PHY_MARVELL_E3016_INITMASK;
  1245. if (mii_rw(dev, np->phyaddr, MII_NCONFIG, reg)) {
  1246. netdev_info(dev, "%s: phy write to errata reg failed\n",
  1247. pci_name(np->pci_dev));
  1248. return PHY_ERROR;
  1249. }
  1250. }
  1251. if (np->phy_oui == PHY_OUI_REALTEK) {
  1252. if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
  1253. np->phy_rev == PHY_REV_REALTEK_8211B) {
  1254. if (init_realtek_8211b(dev, np)) {
  1255. netdev_info(dev, "%s: phy init failed\n",
  1256. pci_name(np->pci_dev));
  1257. return PHY_ERROR;
  1258. }
  1259. } else if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
  1260. np->phy_rev == PHY_REV_REALTEK_8211C) {
  1261. if (init_realtek_8211c(dev, np)) {
  1262. netdev_info(dev, "%s: phy init failed\n",
  1263. pci_name(np->pci_dev));
  1264. return PHY_ERROR;
  1265. }
  1266. } else if (np->phy_model == PHY_MODEL_REALTEK_8201) {
  1267. if (init_realtek_8201(dev, np)) {
  1268. netdev_info(dev, "%s: phy init failed\n",
  1269. pci_name(np->pci_dev));
  1270. return PHY_ERROR;
  1271. }
  1272. }
  1273. }
  1274. /* set advertise register */
  1275. reg = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
  1276. reg |= (ADVERTISE_10HALF | ADVERTISE_10FULL |
  1277. ADVERTISE_100HALF | ADVERTISE_100FULL |
  1278. ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
  1279. if (mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg)) {
  1280. netdev_info(dev, "%s: phy write to advertise failed\n",
  1281. pci_name(np->pci_dev));
  1282. return PHY_ERROR;
  1283. }
  1284. /* get phy interface type */
  1285. phyinterface = readl(base + NvRegPhyInterface);
  1286. /* see if gigabit phy */
  1287. mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
  1288. if (mii_status & PHY_GIGABIT) {
  1289. np->gigabit = PHY_GIGABIT;
  1290. mii_control_1000 = mii_rw(dev, np->phyaddr,
  1291. MII_CTRL1000, MII_READ);
  1292. mii_control_1000 &= ~ADVERTISE_1000HALF;
  1293. if (phyinterface & PHY_RGMII)
  1294. mii_control_1000 |= ADVERTISE_1000FULL;
  1295. else
  1296. mii_control_1000 &= ~ADVERTISE_1000FULL;
  1297. if (mii_rw(dev, np->phyaddr, MII_CTRL1000, mii_control_1000)) {
  1298. netdev_info(dev, "%s: phy init failed\n",
  1299. pci_name(np->pci_dev));
  1300. return PHY_ERROR;
  1301. }
  1302. } else
  1303. np->gigabit = 0;
  1304. mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
  1305. mii_control |= BMCR_ANENABLE;
  1306. if (np->phy_oui == PHY_OUI_REALTEK &&
  1307. np->phy_model == PHY_MODEL_REALTEK_8211 &&
  1308. np->phy_rev == PHY_REV_REALTEK_8211C) {
  1309. /* start autoneg since we already performed hw reset above */
  1310. mii_control |= BMCR_ANRESTART;
  1311. if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) {
  1312. netdev_info(dev, "%s: phy init failed\n",
  1313. pci_name(np->pci_dev));
  1314. return PHY_ERROR;
  1315. }
  1316. } else {
  1317. /* reset the phy
  1318. * (certain phys need bmcr to be setup with reset)
  1319. */
  1320. if (phy_reset(dev, mii_control)) {
  1321. netdev_info(dev, "%s: phy reset failed\n",
  1322. pci_name(np->pci_dev));
  1323. return PHY_ERROR;
  1324. }
  1325. }
  1326. /* phy vendor specific configuration */
  1327. if ((np->phy_oui == PHY_OUI_CICADA)) {
  1328. if (init_cicada(dev, np, phyinterface)) {
  1329. netdev_info(dev, "%s: phy init failed\n",
  1330. pci_name(np->pci_dev));
  1331. return PHY_ERROR;
  1332. }
  1333. } else if (np->phy_oui == PHY_OUI_VITESSE) {
  1334. if (init_vitesse(dev, np)) {
  1335. netdev_info(dev, "%s: phy init failed\n",
  1336. pci_name(np->pci_dev));
  1337. return PHY_ERROR;
  1338. }
  1339. } else if (np->phy_oui == PHY_OUI_REALTEK) {
  1340. if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
  1341. np->phy_rev == PHY_REV_REALTEK_8211B) {
  1342. /* reset could have cleared these out, set them back */
  1343. if (init_realtek_8211b(dev, np)) {
  1344. netdev_info(dev, "%s: phy init failed\n",
  1345. pci_name(np->pci_dev));
  1346. return PHY_ERROR;
  1347. }
  1348. } else if (np->phy_model == PHY_MODEL_REALTEK_8201) {
  1349. if (init_realtek_8201(dev, np) ||
  1350. init_realtek_8201_cross(dev, np)) {
  1351. netdev_info(dev, "%s: phy init failed\n",
  1352. pci_name(np->pci_dev));
  1353. return PHY_ERROR;
  1354. }
  1355. }
  1356. }
  1357. /* some phys clear out pause advertisement on reset, set it back */
  1358. mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg);
  1359. /* restart auto negotiation, power down phy */
  1360. mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
  1361. mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
  1362. if (phy_power_down)
  1363. mii_control |= BMCR_PDOWN;
  1364. if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control))
  1365. return PHY_ERROR;
  1366. return 0;
  1367. }
  1368. static void nv_start_rx(struct net_device *dev)
  1369. {
  1370. struct fe_priv *np = netdev_priv(dev);
  1371. u8 __iomem *base = get_hwbase(dev);
  1372. u32 rx_ctrl = readl(base + NvRegReceiverControl);
  1373. /* Already running? Stop it. */
  1374. if ((readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) && !np->mac_in_use) {
  1375. rx_ctrl &= ~NVREG_RCVCTL_START;
  1376. writel(rx_ctrl, base + NvRegReceiverControl);
  1377. pci_push(base);
  1378. }
  1379. writel(np->linkspeed, base + NvRegLinkSpeed);
  1380. pci_push(base);
  1381. rx_ctrl |= NVREG_RCVCTL_START;
  1382. if (np->mac_in_use)
  1383. rx_ctrl &= ~NVREG_RCVCTL_RX_PATH_EN;
  1384. writel(rx_ctrl, base + NvRegReceiverControl);
  1385. pci_push(base);
  1386. }
  1387. static void nv_stop_rx(struct net_device *dev)
  1388. {
  1389. struct fe_priv *np = netdev_priv(dev);
  1390. u8 __iomem *base = get_hwbase(dev);
  1391. u32 rx_ctrl = readl(base + NvRegReceiverControl);
  1392. if (!np->mac_in_use)
  1393. rx_ctrl &= ~NVREG_RCVCTL_START;
  1394. else
  1395. rx_ctrl |= NVREG_RCVCTL_RX_PATH_EN;
  1396. writel(rx_ctrl, base + NvRegReceiverControl);
  1397. if (reg_delay(dev, NvRegReceiverStatus, NVREG_RCVSTAT_BUSY, 0,
  1398. NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX))
  1399. netdev_info(dev, "%s: ReceiverStatus remained busy\n",
  1400. __func__);
  1401. udelay(NV_RXSTOP_DELAY2);
  1402. if (!np->mac_in_use)
  1403. writel(0, base + NvRegLinkSpeed);
  1404. }
  1405. static void nv_start_tx(struct net_device *dev)
  1406. {
  1407. struct fe_priv *np = netdev_priv(dev);
  1408. u8 __iomem *base = get_hwbase(dev);
  1409. u32 tx_ctrl = readl(base + NvRegTransmitterControl);
  1410. tx_ctrl |= NVREG_XMITCTL_START;
  1411. if (np->mac_in_use)
  1412. tx_ctrl &= ~NVREG_XMITCTL_TX_PATH_EN;
  1413. writel(tx_ctrl, base + NvRegTransmitterControl);
  1414. pci_push(base);
  1415. }
  1416. static void nv_stop_tx(struct net_device *dev)
  1417. {
  1418. struct fe_priv *np = netdev_priv(dev);
  1419. u8 __iomem *base = get_hwbase(dev);
  1420. u32 tx_ctrl = readl(base + NvRegTransmitterControl);
  1421. if (!np->mac_in_use)
  1422. tx_ctrl &= ~NVREG_XMITCTL_START;
  1423. else
  1424. tx_ctrl |= NVREG_XMITCTL_TX_PATH_EN;
  1425. writel(tx_ctrl, base + NvRegTransmitterControl);
  1426. if (reg_delay(dev, NvRegTransmitterStatus, NVREG_XMITSTAT_BUSY, 0,
  1427. NV_TXSTOP_DELAY1, NV_TXSTOP_DELAY1MAX))
  1428. netdev_info(dev, "%s: TransmitterStatus remained busy\n",
  1429. __func__);
  1430. udelay(NV_TXSTOP_DELAY2);
  1431. if (!np->mac_in_use)
  1432. writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV,
  1433. base + NvRegTransmitPoll);
  1434. }
  1435. static void nv_start_rxtx(struct net_device *dev)
  1436. {
  1437. nv_start_rx(dev);
  1438. nv_start_tx(dev);
  1439. }
  1440. static void nv_stop_rxtx(struct net_device *dev)
  1441. {
  1442. nv_stop_rx(dev);
  1443. nv_stop_tx(dev);
  1444. }
  1445. static void nv_txrx_reset(struct net_device *dev)
  1446. {
  1447. struct fe_priv *np = netdev_priv(dev);
  1448. u8 __iomem *base = get_hwbase(dev);
  1449. writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
  1450. pci_push(base);
  1451. udelay(NV_TXRX_RESET_DELAY);
  1452. writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
  1453. pci_push(base);
  1454. }
  1455. static void nv_mac_reset(struct net_device *dev)
  1456. {
  1457. struct fe_priv *np = netdev_priv(dev);
  1458. u8 __iomem *base = get_hwbase(dev);
  1459. u32 temp1, temp2, temp3;
  1460. writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
  1461. pci_push(base);
  1462. /* save registers since they will be cleared on reset */
  1463. temp1 = readl(base + NvRegMacAddrA);
  1464. temp2 = readl(base + NvRegMacAddrB);
  1465. temp3 = readl(base + NvRegTransmitPoll);
  1466. writel(NVREG_MAC_RESET_ASSERT, base + NvRegMacReset);
  1467. pci_push(base);
  1468. udelay(NV_MAC_RESET_DELAY);
  1469. writel(0, base + NvRegMacReset);
  1470. pci_push(base);
  1471. udelay(NV_MAC_RESET_DELAY);
  1472. /* restore saved registers */
  1473. writel(temp1, base + NvRegMacAddrA);
  1474. writel(temp2, base + NvRegMacAddrB);
  1475. writel(temp3, base + NvRegTransmitPoll);
  1476. writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
  1477. pci_push(base);
  1478. }
  1479. /* Caller must appropriately lock netdev_priv(dev)->hwstats_lock */
  1480. static void nv_update_stats(struct net_device *dev)
  1481. {
  1482. struct fe_priv *np = netdev_priv(dev);
  1483. u8 __iomem *base = get_hwbase(dev);
  1484. /* If it happens that this is run in top-half context, then
  1485. * replace the spin_lock of hwstats_lock with
  1486. * spin_lock_irqsave() in calling functions. */
  1487. WARN_ONCE(in_irq(), "forcedeth: estats spin_lock(_bh) from top-half");
  1488. assert_spin_locked(&np->hwstats_lock);
  1489. /* query hardware */
  1490. np->estats.tx_bytes += readl(base + NvRegTxCnt);
  1491. np->estats.tx_zero_rexmt += readl(base + NvRegTxZeroReXmt);
  1492. np->estats.tx_one_rexmt += readl(base + NvRegTxOneReXmt);
  1493. np->estats.tx_many_rexmt += readl(base + NvRegTxManyReXmt);
  1494. np->estats.tx_late_collision += readl(base + NvRegTxLateCol);
  1495. np->estats.tx_fifo_errors += readl(base + NvRegTxUnderflow);
  1496. np->estats.tx_carrier_errors += readl(base + NvRegTxLossCarrier);
  1497. np->estats.tx_excess_deferral += readl(base + NvRegTxExcessDef);
  1498. np->estats.tx_retry_error += readl(base + NvRegTxRetryErr);
  1499. np->estats.rx_frame_error += readl(base + NvRegRxFrameErr);
  1500. np->estats.rx_extra_byte += readl(base + NvRegRxExtraByte);
  1501. np->estats.rx_late_collision += readl(base + NvRegRxLateCol);
  1502. np->estats.rx_runt += readl(base + NvRegRxRunt);
  1503. np->estats.rx_frame_too_long += readl(base + NvRegRxFrameTooLong);
  1504. np->estats.rx_over_errors += readl(base + NvRegRxOverflow);
  1505. np->estats.rx_crc_errors += readl(base + NvRegRxFCSErr);
  1506. np->estats.rx_frame_align_error += readl(base + NvRegRxFrameAlignErr);
  1507. np->estats.rx_length_error += readl(base + NvRegRxLenErr);
  1508. np->estats.rx_unicast += readl(base + NvRegRxUnicast);
  1509. np->estats.rx_multicast += readl(base + NvRegRxMulticast);
  1510. np->estats.rx_broadcast += readl(base + NvRegRxBroadcast);
  1511. np->estats.rx_packets =
  1512. np->estats.rx_unicast +
  1513. np->estats.rx_multicast +
  1514. np->estats.rx_broadcast;
  1515. np->estats.rx_errors_total =
  1516. np->estats.rx_crc_errors +
  1517. np->estats.rx_over_errors +
  1518. np->estats.rx_frame_error +
  1519. (np->estats.rx_frame_align_error - np->estats.rx_extra_byte) +
  1520. np->estats.rx_late_collision +
  1521. np->estats.rx_runt +
  1522. np->estats.rx_frame_too_long;
  1523. np->estats.tx_errors_total =
  1524. np->estats.tx_late_collision +
  1525. np->estats.tx_fifo_errors +
  1526. np->estats.tx_carrier_errors +
  1527. np->estats.tx_excess_deferral +
  1528. np->estats.tx_retry_error;
  1529. if (np->driver_data & DEV_HAS_STATISTICS_V2) {
  1530. np->estats.tx_deferral += readl(base + NvRegTxDef);
  1531. np->estats.tx_packets += readl(base + NvRegTxFrame);
  1532. np->estats.rx_bytes += readl(base + NvRegRxCnt);
  1533. np->estats.tx_pause += readl(base + NvRegTxPause);
  1534. np->estats.rx_pause += readl(base + NvRegRxPause);
  1535. np->estats.rx_drop_frame += readl(base + NvRegRxDropFrame);
  1536. np->estats.rx_errors_total += np->estats.rx_drop_frame;
  1537. }
  1538. if (np->driver_data & DEV_HAS_STATISTICS_V3) {
  1539. np->estats.tx_unicast += readl(base + NvRegTxUnicast);
  1540. np->estats.tx_multicast += readl(base + NvRegTxMulticast);
  1541. np->estats.tx_broadcast += readl(base + NvRegTxBroadcast);
  1542. }
  1543. }
  1544. /*
  1545. * nv_get_stats64: dev->ndo_get_stats64 function
  1546. * Get latest stats value from the nic.
  1547. * Called with read_lock(&dev_base_lock) held for read -
  1548. * only synchronized against unregister_netdevice.
  1549. */
  1550. static struct rtnl_link_stats64*
  1551. nv_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *storage)
  1552. __acquires(&netdev_priv(dev)->hwstats_lock)
  1553. __releases(&netdev_priv(dev)->hwstats_lock)
  1554. {
  1555. struct fe_priv *np = netdev_priv(dev);
  1556. unsigned int syncp_start;
  1557. /*
  1558. * Note: because HW stats are not always available and for
  1559. * consistency reasons, the following ifconfig stats are
  1560. * managed by software: rx_bytes, tx_bytes, rx_packets and
  1561. * tx_packets. The related hardware stats reported by ethtool
  1562. * should be equivalent to these ifconfig stats, with 4
  1563. * additional bytes per packet (Ethernet FCS CRC), except for
  1564. * tx_packets when TSO kicks in.
  1565. */
  1566. /* software stats */
  1567. do {
  1568. syncp_start = u64_stats_fetch_begin_irq(&np->swstats_rx_syncp);
  1569. storage->rx_packets = np->stat_rx_packets;
  1570. storage->rx_bytes = np->stat_rx_bytes;
  1571. storage->rx_dropped = np->stat_rx_dropped;
  1572. storage->rx_missed_errors = np->stat_rx_missed_errors;
  1573. } while (u64_stats_fetch_retry_irq(&np->swstats_rx_syncp, syncp_start));
  1574. do {
  1575. syncp_start = u64_stats_fetch_begin_irq(&np->swstats_tx_syncp);
  1576. storage->tx_packets = np->stat_tx_packets;
  1577. storage->tx_bytes = np->stat_tx_bytes;
  1578. storage->tx_dropped = np->stat_tx_dropped;
  1579. } while (u64_stats_fetch_retry_irq(&np->swstats_tx_syncp, syncp_start));
  1580. /* If the nic supports hw counters then retrieve latest values */
  1581. if (np->driver_data & DEV_HAS_STATISTICS_V123) {
  1582. spin_lock_bh(&np->hwstats_lock);
  1583. nv_update_stats(dev);
  1584. /* generic stats */
  1585. storage->rx_errors = np->estats.rx_errors_total;
  1586. storage->tx_errors = np->estats.tx_errors_total;
  1587. /* meaningful only when NIC supports stats v3 */
  1588. storage->multicast = np->estats.rx_multicast;
  1589. /* detailed rx_errors */
  1590. storage->rx_length_errors = np->estats.rx_length_error;
  1591. storage->rx_over_errors = np->estats.rx_over_errors;
  1592. storage->rx_crc_errors = np->estats.rx_crc_errors;
  1593. storage->rx_frame_errors = np->estats.rx_frame_align_error;
  1594. storage->rx_fifo_errors = np->estats.rx_drop_frame;
  1595. /* detailed tx_errors */
  1596. storage->tx_carrier_errors = np->estats.tx_carrier_errors;
  1597. storage->tx_fifo_errors = np->estats.tx_fifo_errors;
  1598. spin_unlock_bh(&np->hwstats_lock);
  1599. }
  1600. return storage;
  1601. }
  1602. /*
  1603. * nv_alloc_rx: fill rx ring entries.
  1604. * Return 1 if the allocations for the skbs failed and the
  1605. * rx engine is without Available descriptors
  1606. */
  1607. static int nv_alloc_rx(struct net_device *dev)
  1608. {
  1609. struct fe_priv *np = netdev_priv(dev);
  1610. struct ring_desc *less_rx;
  1611. less_rx = np->get_rx.orig;
  1612. if (less_rx-- == np->first_rx.orig)
  1613. less_rx = np->last_rx.orig;
  1614. while (np->put_rx.orig != less_rx) {
  1615. struct sk_buff *skb = netdev_alloc_skb(dev, np->rx_buf_sz + NV_RX_ALLOC_PAD);
  1616. if (skb) {
  1617. np->put_rx_ctx->skb = skb;
  1618. np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
  1619. skb->data,
  1620. skb_tailroom(skb),
  1621. PCI_DMA_FROMDEVICE);
  1622. np->put_rx_ctx->dma_len = skb_tailroom(skb);
  1623. np->put_rx.orig->buf = cpu_to_le32(np->put_rx_ctx->dma);
  1624. wmb();
  1625. np->put_rx.orig->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL);
  1626. if (unlikely(np->put_rx.orig++ == np->last_rx.orig))
  1627. np->put_rx.orig = np->first_rx.orig;
  1628. if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
  1629. np->put_rx_ctx = np->first_rx_ctx;
  1630. } else {
  1631. u64_stats_update_begin(&np->swstats_rx_syncp);
  1632. np->stat_rx_dropped++;
  1633. u64_stats_update_end(&np->swstats_rx_syncp);
  1634. return 1;
  1635. }
  1636. }
  1637. return 0;
  1638. }
  1639. static int nv_alloc_rx_optimized(struct net_device *dev)
  1640. {
  1641. struct fe_priv *np = netdev_priv(dev);
  1642. struct ring_desc_ex *less_rx;
  1643. less_rx = np->get_rx.ex;
  1644. if (less_rx-- == np->first_rx.ex)
  1645. less_rx = np->last_rx.ex;
  1646. while (np->put_rx.ex != less_rx) {
  1647. struct sk_buff *skb = netdev_alloc_skb(dev, np->rx_buf_sz + NV_RX_ALLOC_PAD);
  1648. if (skb) {
  1649. np->put_rx_ctx->skb = skb;
  1650. np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
  1651. skb->data,
  1652. skb_tailroom(skb),
  1653. PCI_DMA_FROMDEVICE);
  1654. np->put_rx_ctx->dma_len = skb_tailroom(skb);
  1655. np->put_rx.ex->bufhigh = cpu_to_le32(dma_high(np->put_rx_ctx->dma));
  1656. np->put_rx.ex->buflow = cpu_to_le32(dma_low(np->put_rx_ctx->dma));
  1657. wmb();
  1658. np->put_rx.ex->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL);
  1659. if (unlikely(np->put_rx.ex++ == np->last_rx.ex))
  1660. np->put_rx.ex = np->first_rx.ex;
  1661. if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
  1662. np->put_rx_ctx = np->first_rx_ctx;
  1663. } else {
  1664. u64_stats_update_begin(&np->swstats_rx_syncp);
  1665. np->stat_rx_dropped++;
  1666. u64_stats_update_end(&np->swstats_rx_syncp);
  1667. return 1;
  1668. }
  1669. }
  1670. return 0;
  1671. }
  1672. /* If rx bufs are exhausted called after 50ms to attempt to refresh */
  1673. static void nv_do_rx_refill(unsigned long data)
  1674. {
  1675. struct net_device *dev = (struct net_device *) data;
  1676. struct fe_priv *np = netdev_priv(dev);
  1677. /* Just reschedule NAPI rx processing */
  1678. napi_schedule(&np->napi);
  1679. }
  1680. static void nv_init_rx(struct net_device *dev)
  1681. {
  1682. struct fe_priv *np = netdev_priv(dev);
  1683. int i;
  1684. np->get_rx = np->put_rx = np->first_rx = np->rx_ring;
  1685. if (!nv_optimized(np))
  1686. np->last_rx.orig = &np->rx_ring.orig[np->rx_ring_size-1];
  1687. else
  1688. np->last_rx.ex = &np->rx_ring.ex[np->rx_ring_size-1];
  1689. np->get_rx_ctx = np->put_rx_ctx = np->first_rx_ctx = np->rx_skb;
  1690. np->last_rx_ctx = &np->rx_skb[np->rx_ring_size-1];
  1691. for (i = 0; i < np->rx_ring_size; i++) {
  1692. if (!nv_optimized(np)) {
  1693. np->rx_ring.orig[i].flaglen = 0;
  1694. np->rx_ring.orig[i].buf = 0;
  1695. } else {
  1696. np->rx_ring.ex[i].flaglen = 0;
  1697. np->rx_ring.ex[i].txvlan = 0;
  1698. np->rx_ring.ex[i].bufhigh = 0;
  1699. np->rx_ring.ex[i].buflow = 0;
  1700. }
  1701. np->rx_skb[i].skb = NULL;
  1702. np->rx_skb[i].dma = 0;
  1703. }
  1704. }
  1705. static void nv_init_tx(struct net_device *dev)
  1706. {
  1707. struct fe_priv *np = netdev_priv(dev);
  1708. int i;
  1709. np->get_tx = np->put_tx = np->first_tx = np->tx_ring;
  1710. if (!nv_optimized(np))
  1711. np->last_tx.orig = &np->tx_ring.orig[np->tx_ring_size-1];
  1712. else
  1713. np->last_tx.ex = &np->tx_ring.ex[np->tx_ring_size-1];
  1714. np->get_tx_ctx = np->put_tx_ctx = np->first_tx_ctx = np->tx_skb;
  1715. np->last_tx_ctx = &np->tx_skb[np->tx_ring_size-1];
  1716. netdev_reset_queue(np->dev);
  1717. np->tx_pkts_in_progress = 0;
  1718. np->tx_change_owner = NULL;
  1719. np->tx_end_flip = NULL;
  1720. np->tx_stop = 0;
  1721. for (i = 0; i < np->tx_ring_size; i++) {
  1722. if (!nv_optimized(np)) {
  1723. np->tx_ring.orig[i].flaglen = 0;
  1724. np->tx_ring.orig[i].buf = 0;
  1725. } else {
  1726. np->tx_ring.ex[i].flaglen = 0;
  1727. np->tx_ring.ex[i].txvlan = 0;
  1728. np->tx_ring.ex[i].bufhigh = 0;
  1729. np->tx_ring.ex[i].buflow = 0;
  1730. }
  1731. np->tx_skb[i].skb = NULL;
  1732. np->tx_skb[i].dma = 0;
  1733. np->tx_skb[i].dma_len = 0;
  1734. np->tx_skb[i].dma_single = 0;
  1735. np->tx_skb[i].first_tx_desc = NULL;
  1736. np->tx_skb[i].next_tx_ctx = NULL;
  1737. }
  1738. }
  1739. static int nv_init_ring(struct net_device *dev)
  1740. {
  1741. struct fe_priv *np = netdev_priv(dev);
  1742. nv_init_tx(dev);
  1743. nv_init_rx(dev);
  1744. if (!nv_optimized(np))
  1745. return nv_alloc_rx(dev);
  1746. else
  1747. return nv_alloc_rx_optimized(dev);
  1748. }
  1749. static void nv_unmap_txskb(struct fe_priv *np, struct nv_skb_map *tx_skb)
  1750. {
  1751. if (tx_skb->dma) {
  1752. if (tx_skb->dma_single)
  1753. pci_unmap_single(np->pci_dev, tx_skb->dma,
  1754. tx_skb->dma_len,
  1755. PCI_DMA_TODEVICE);
  1756. else
  1757. pci_unmap_page(np->pci_dev, tx_skb->dma,
  1758. tx_skb->dma_len,
  1759. PCI_DMA_TODEVICE);
  1760. tx_skb->dma = 0;
  1761. }
  1762. }
  1763. static int nv_release_txskb(struct fe_priv *np, struct nv_skb_map *tx_skb)
  1764. {
  1765. nv_unmap_txskb(np, tx_skb);
  1766. if (tx_skb->skb) {
  1767. dev_kfree_skb_any(tx_skb->skb);
  1768. tx_skb->skb = NULL;
  1769. return 1;
  1770. }
  1771. return 0;
  1772. }
  1773. static void nv_drain_tx(struct net_device *dev)
  1774. {
  1775. struct fe_priv *np = netdev_priv(dev);
  1776. unsigned int i;
  1777. for (i = 0; i < np->tx_ring_size; i++) {
  1778. if (!nv_optimized(np)) {
  1779. np->tx_ring.orig[i].flaglen = 0;
  1780. np->tx_ring.orig[i].buf = 0;
  1781. } else {
  1782. np->tx_ring.ex[i].flaglen = 0;
  1783. np->tx_ring.ex[i].txvlan = 0;
  1784. np->tx_ring.ex[i].bufhigh = 0;
  1785. np->tx_ring.ex[i].buflow = 0;
  1786. }
  1787. if (nv_release_txskb(np, &np->tx_skb[i])) {
  1788. u64_stats_update_begin(&np->swstats_tx_syncp);
  1789. np->stat_tx_dropped++;
  1790. u64_stats_update_end(&np->swstats_tx_syncp);
  1791. }
  1792. np->tx_skb[i].dma = 0;
  1793. np->tx_skb[i].dma_len = 0;
  1794. np->tx_skb[i].dma_single = 0;
  1795. np->tx_skb[i].first_tx_desc = NULL;
  1796. np->tx_skb[i].next_tx_ctx = NULL;
  1797. }
  1798. np->tx_pkts_in_progress = 0;
  1799. np->tx_change_owner = NULL;
  1800. np->tx_end_flip = NULL;
  1801. }
  1802. static void nv_drain_rx(struct net_device *dev)
  1803. {
  1804. struct fe_priv *np = netdev_priv(dev);
  1805. int i;
  1806. for (i = 0; i < np->rx_ring_size; i++) {
  1807. if (!nv_optimized(np)) {
  1808. np->rx_ring.orig[i].flaglen = 0;
  1809. np->rx_ring.orig[i].buf = 0;
  1810. } else {
  1811. np->rx_ring.ex[i].flaglen = 0;
  1812. np->rx_ring.ex[i].txvlan = 0;
  1813. np->rx_ring.ex[i].bufhigh = 0;
  1814. np->rx_ring.ex[i].buflow = 0;
  1815. }
  1816. wmb();
  1817. if (np->rx_skb[i].skb) {
  1818. pci_unmap_single(np->pci_dev, np->rx_skb[i].dma,
  1819. (skb_end_pointer(np->rx_skb[i].skb) -
  1820. np->rx_skb[i].skb->data),
  1821. PCI_DMA_FROMDEVICE);
  1822. dev_kfree_skb(np->rx_skb[i].skb);
  1823. np->rx_skb[i].skb = NULL;
  1824. }
  1825. }
  1826. }
  1827. static void nv_drain_rxtx(struct net_device *dev)
  1828. {
  1829. nv_drain_tx(dev);
  1830. nv_drain_rx(dev);
  1831. }
  1832. static inline u32 nv_get_empty_tx_slots(struct fe_priv *np)
  1833. {
  1834. return (u32)(np->tx_ring_size - ((np->tx_ring_size + (np->put_tx_ctx - np->get_tx_ctx)) % np->tx_ring_size));
  1835. }
  1836. static void nv_legacybackoff_reseed(struct net_device *dev)
  1837. {
  1838. u8 __iomem *base = get_hwbase(dev);
  1839. u32 reg;
  1840. u32 low;
  1841. int tx_status = 0;
  1842. reg = readl(base + NvRegSlotTime) & ~NVREG_SLOTTIME_MASK;
  1843. get_random_bytes(&low, sizeof(low));
  1844. reg |= low & NVREG_SLOTTIME_MASK;
  1845. /* Need to stop tx before change takes effect.
  1846. * Caller has already gained np->lock.
  1847. */
  1848. tx_status = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START;
  1849. if (tx_status)
  1850. nv_stop_tx(dev);
  1851. nv_stop_rx(dev);
  1852. writel(reg, base + NvRegSlotTime);
  1853. if (tx_status)
  1854. nv_start_tx(dev);
  1855. nv_start_rx(dev);
  1856. }
  1857. /* Gear Backoff Seeds */
  1858. #define BACKOFF_SEEDSET_ROWS 8
  1859. #define BACKOFF_SEEDSET_LFSRS 15
  1860. /* Known Good seed sets */
  1861. static const u32 main_seedset[BACKOFF_SEEDSET_ROWS][BACKOFF_SEEDSET_LFSRS] = {
  1862. {145, 155, 165, 175, 185, 196, 235, 245, 255, 265, 275, 285, 660, 690, 874},
  1863. {245, 255, 265, 575, 385, 298, 335, 345, 355, 366, 375, 385, 761, 790, 974},
  1864. {145, 155, 165, 175, 185, 196, 235, 245, 255, 265, 275, 285, 660, 690, 874},
  1865. {245, 255, 265, 575, 385, 298, 335, 345, 355, 366, 375, 386, 761, 790, 974},
  1866. {266, 265, 276, 585, 397, 208, 345, 355, 365, 376, 385, 396, 771, 700, 984},
  1867. {266, 265, 276, 586, 397, 208, 346, 355, 365, 376, 285, 396, 771, 700, 984},
  1868. {366, 365, 376, 686, 497, 308, 447, 455, 466, 476, 485, 496, 871, 800, 84},
  1869. {466, 465, 476, 786, 597, 408, 547, 555, 566, 576, 585, 597, 971, 900, 184} };
  1870. static const u32 gear_seedset[BACKOFF_SEEDSET_ROWS][BACKOFF_SEEDSET_LFSRS] = {
  1871. {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
  1872. {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
  1873. {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 397},
  1874. {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
  1875. {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
  1876. {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
  1877. {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
  1878. {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395} };
  1879. static void nv_gear_backoff_reseed(struct net_device *dev)
  1880. {
  1881. u8 __iomem *base = get_hwbase(dev);
  1882. u32 miniseed1, miniseed2, miniseed2_reversed, miniseed3, miniseed3_reversed;
  1883. u32 temp, seedset, combinedSeed;
  1884. int i;
  1885. /* Setup seed for free running LFSR */
  1886. /* We are going to read the time stamp counter 3 times
  1887. and swizzle bits around to increase randomness */
  1888. get_random_bytes(&miniseed1, sizeof(miniseed1));
  1889. miniseed1 &= 0x0fff;
  1890. if (miniseed1 == 0)
  1891. miniseed1 = 0xabc;
  1892. get_random_bytes(&miniseed2, sizeof(miniseed2));
  1893. miniseed2 &= 0x0fff;
  1894. if (miniseed2 == 0)
  1895. miniseed2 = 0xabc;
  1896. miniseed2_reversed =
  1897. ((miniseed2 & 0xF00) >> 8) |
  1898. (miniseed2 & 0x0F0) |
  1899. ((miniseed2 & 0x00F) << 8);
  1900. get_random_bytes(&miniseed3, sizeof(miniseed3));
  1901. miniseed3 &= 0x0fff;
  1902. if (miniseed3 == 0)
  1903. miniseed3 = 0xabc;
  1904. miniseed3_reversed =
  1905. ((miniseed3 & 0xF00) >> 8) |
  1906. (miniseed3 & 0x0F0) |
  1907. ((miniseed3 & 0x00F) << 8);
  1908. combinedSeed = ((miniseed1 ^ miniseed2_reversed) << 12) |
  1909. (miniseed2 ^ miniseed3_reversed);
  1910. /* Seeds can not be zero */
  1911. if ((combinedSeed & NVREG_BKOFFCTRL_SEED_MASK) == 0)
  1912. combinedSeed |= 0x08;
  1913. if ((combinedSeed & (NVREG_BKOFFCTRL_SEED_MASK << NVREG_BKOFFCTRL_GEAR)) == 0)
  1914. combinedSeed |= 0x8000;
  1915. /* No need to disable tx here */
  1916. temp = NVREG_BKOFFCTRL_DEFAULT | (0 << NVREG_BKOFFCTRL_SELECT);
  1917. temp |= combinedSeed & NVREG_BKOFFCTRL_SEED_MASK;
  1918. temp |= combinedSeed >> NVREG_BKOFFCTRL_GEAR;
  1919. writel(temp, base + NvRegBackOffControl);
  1920. /* Setup seeds for all gear LFSRs. */
  1921. get_random_bytes(&seedset, sizeof(seedset));
  1922. seedset = seedset % BACKOFF_SEEDSET_ROWS;
  1923. for (i = 1; i <= BACKOFF_SEEDSET_LFSRS; i++) {
  1924. temp = NVREG_BKOFFCTRL_DEFAULT | (i << NVREG_BKOFFCTRL_SELECT);
  1925. temp |= main_seedset[seedset][i-1] & 0x3ff;
  1926. temp |= ((gear_seedset[seedset][i-1] & 0x3ff) << NVREG_BKOFFCTRL_GEAR);
  1927. writel(temp, base + NvRegBackOffControl);
  1928. }
  1929. }
  1930. /*
  1931. * nv_start_xmit: dev->hard_start_xmit function
  1932. * Called with netif_tx_lock held.
  1933. */
  1934. static netdev_tx_t nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
  1935. {
  1936. struct fe_priv *np = netdev_priv(dev);
  1937. u32 tx_flags = 0;
  1938. u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
  1939. unsigned int fragments = skb_shinfo(skb)->nr_frags;
  1940. unsigned int i;
  1941. u32 offset = 0;
  1942. u32 bcnt;
  1943. u32 size = skb_headlen(skb);
  1944. u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
  1945. u32 empty_slots;
  1946. struct ring_desc *put_tx;
  1947. struct ring_desc *start_tx;
  1948. struct ring_desc *prev_tx;
  1949. struct nv_skb_map *prev_tx_ctx;
  1950. unsigned long flags;
  1951. /* add fragments to entries count */
  1952. for (i = 0; i < fragments; i++) {
  1953. u32 frag_size = skb_frag_size(&skb_shinfo(skb)->frags[i]);
  1954. entries += (frag_size >> NV_TX2_TSO_MAX_SHIFT) +
  1955. ((frag_size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
  1956. }
  1957. spin_lock_irqsave(&np->lock, flags);
  1958. empty_slots = nv_get_empty_tx_slots(np);
  1959. if (unlikely(empty_slots <= entries)) {
  1960. netif_stop_queue(dev);
  1961. np->tx_stop = 1;
  1962. spin_unlock_irqrestore(&np->lock, flags);
  1963. return NETDEV_TX_BUSY;
  1964. }
  1965. spin_unlock_irqrestore(&np->lock, flags);
  1966. start_tx = put_tx = np->put_tx.orig;
  1967. /* setup the header buffer */
  1968. do {
  1969. prev_tx = put_tx;
  1970. prev_tx_ctx = np->put_tx_ctx;
  1971. bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
  1972. np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
  1973. PCI_DMA_TODEVICE);
  1974. np->put_tx_ctx->dma_len = bcnt;
  1975. np->put_tx_ctx->dma_single = 1;
  1976. put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
  1977. put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
  1978. tx_flags = np->tx_flags;
  1979. offset += bcnt;
  1980. size -= bcnt;
  1981. if (unlikely(put_tx++ == np->last_tx.orig))
  1982. put_tx = np->first_tx.orig;
  1983. if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
  1984. np->put_tx_ctx = np->first_tx_ctx;
  1985. } while (size);
  1986. /* setup the fragments */
  1987. for (i = 0; i < fragments; i++) {
  1988. const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  1989. u32 frag_size = skb_frag_size(frag);
  1990. offset = 0;
  1991. do {
  1992. prev_tx = put_tx;
  1993. prev_tx_ctx = np->put_tx_ctx;
  1994. bcnt = (frag_size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : frag_size;
  1995. np->put_tx_ctx->dma = skb_frag_dma_map(
  1996. &np->pci_dev->dev,
  1997. frag, offset,
  1998. bcnt,
  1999. DMA_TO_DEVICE);
  2000. np->put_tx_ctx->dma_len = bcnt;
  2001. np->put_tx_ctx->dma_single = 0;
  2002. put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
  2003. put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
  2004. offset += bcnt;
  2005. frag_size -= bcnt;
  2006. if (unlikely(put_tx++ == np->last_tx.orig))
  2007. put_tx = np->first_tx.orig;
  2008. if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
  2009. np->put_tx_ctx = np->first_tx_ctx;
  2010. } while (frag_size);
  2011. }
  2012. /* set last fragment flag */
  2013. prev_tx->flaglen |= cpu_to_le32(tx_flags_extra);
  2014. /* save skb in this slot's context area */
  2015. prev_tx_ctx->skb = skb;
  2016. if (skb_is_gso(skb))
  2017. tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
  2018. else
  2019. tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
  2020. NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
  2021. spin_lock_irqsave(&np->lock, flags);
  2022. /* set tx flags */
  2023. start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
  2024. netdev_sent_queue(np->dev, skb->len);
  2025. np->put_tx.orig = put_tx;
  2026. spin_unlock_irqrestore(&np->lock, flags);
  2027. writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
  2028. return NETDEV_TX_OK;
  2029. }
  2030. static netdev_tx_t nv_start_xmit_optimized(struct sk_buff *skb,
  2031. struct net_device *dev)
  2032. {
  2033. struct fe_priv *np = netdev_priv(dev);
  2034. u32 tx_flags = 0;
  2035. u32 tx_flags_extra;
  2036. unsigned int fragments = skb_shinfo(skb)->nr_frags;
  2037. unsigned int i;
  2038. u32 offset = 0;
  2039. u32 bcnt;
  2040. u32 size = skb_headlen(skb);
  2041. u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
  2042. u32 empty_slots;
  2043. struct ring_desc_ex *put_tx;
  2044. struct ring_desc_ex *start_tx;
  2045. struct ring_desc_ex *prev_tx;
  2046. struct nv_skb_map *prev_tx_ctx;
  2047. struct nv_skb_map *start_tx_ctx;
  2048. unsigned long flags;
  2049. /* add fragments to entries count */
  2050. for (i = 0; i < fragments; i++) {
  2051. u32 frag_size = skb_frag_size(&skb_shinfo(skb)->frags[i]);
  2052. entries += (frag_size >> NV_TX2_TSO_MAX_SHIFT) +
  2053. ((frag_size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
  2054. }
  2055. spin_lock_irqsave(&np->lock, flags);
  2056. empty_slots = nv_get_empty_tx_slots(np);
  2057. if (unlikely(empty_slots <= entries)) {
  2058. netif_stop_queue(dev);
  2059. np->tx_stop = 1;
  2060. spin_unlock_irqrestore(&np->lock, flags);
  2061. return NETDEV_TX_BUSY;
  2062. }
  2063. spin_unlock_irqrestore(&np->lock, flags);
  2064. start_tx = put_tx = np->put_tx.ex;
  2065. start_tx_ctx = np->put_tx_ctx;
  2066. /* setup the header buffer */
  2067. do {
  2068. prev_tx = put_tx;
  2069. prev_tx_ctx = np->put_tx_ctx;
  2070. bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
  2071. np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
  2072. PCI_DMA_TODEVICE);
  2073. np->put_tx_ctx->dma_len = bcnt;
  2074. np->put_tx_ctx->dma_single = 1;
  2075. put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma));
  2076. put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma));
  2077. put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
  2078. tx_flags = NV_TX2_VALID;
  2079. offset += bcnt;
  2080. size -= bcnt;
  2081. if (unlikely(put_tx++ == np->last_tx.ex))
  2082. put_tx = np->first_tx.ex;
  2083. if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
  2084. np->put_tx_ctx = np->first_tx_ctx;
  2085. } while (size);
  2086. /* setup the fragments */
  2087. for (i = 0; i < fragments; i++) {
  2088. skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
  2089. u32 frag_size = skb_frag_size(frag);
  2090. offset = 0;
  2091. do {
  2092. prev_tx = put_tx;
  2093. prev_tx_ctx = np->put_tx_ctx;
  2094. bcnt = (frag_size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : frag_size;
  2095. np->put_tx_ctx->dma = skb_frag_dma_map(
  2096. &np->pci_dev->dev,
  2097. frag, offset,
  2098. bcnt,
  2099. DMA_TO_DEVICE);
  2100. np->put_tx_ctx->dma_len = bcnt;
  2101. np->put_tx_ctx->dma_single = 0;
  2102. put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma));
  2103. put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma));
  2104. put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
  2105. offset += bcnt;
  2106. frag_size -= bcnt;
  2107. if (unlikely(put_tx++ == np->last_tx.ex))
  2108. put_tx = np->first_tx.ex;
  2109. if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
  2110. np->put_tx_ctx = np->first_tx_ctx;
  2111. } while (frag_size);
  2112. }
  2113. /* set last fragment flag */
  2114. prev_tx->flaglen |= cpu_to_le32(NV_TX2_LASTPACKET);
  2115. /* save skb in this slot's context area */
  2116. prev_tx_ctx->skb = skb;
  2117. if (skb_is_gso(skb))
  2118. tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
  2119. else
  2120. tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
  2121. NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
  2122. /* vlan tag */
  2123. if (vlan_tx_tag_present(skb))
  2124. start_tx->txvlan = cpu_to_le32(NV_TX3_VLAN_TAG_PRESENT |
  2125. vlan_tx_tag_get(skb));
  2126. else
  2127. start_tx->txvlan = 0;
  2128. spin_lock_irqsave(&np->lock, flags);
  2129. if (np->tx_limit) {
  2130. /* Limit the number of outstanding tx. Setup all fragments, but
  2131. * do not set the VALID bit on the first descriptor. Save a pointer
  2132. * to that descriptor and also for next skb_map element.
  2133. */
  2134. if (np->tx_pkts_in_progress == NV_TX_LIMIT_COUNT) {
  2135. if (!np->tx_change_owner)
  2136. np->tx_change_owner = start_tx_ctx;
  2137. /* remove VALID bit */
  2138. tx_flags &= ~NV_TX2_VALID;
  2139. start_tx_ctx->first_tx_desc = start_tx;
  2140. start_tx_ctx->next_tx_ctx = np->put_tx_ctx;
  2141. np->tx_end_flip = np->put_tx_ctx;
  2142. } else {
  2143. np->tx_pkts_in_progress++;
  2144. }
  2145. }
  2146. /* set tx flags */
  2147. start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
  2148. netdev_sent_queue(np->dev, skb->len);
  2149. np->put_tx.ex = put_tx;
  2150. spin_unlock_irqrestore(&np->lock, flags);
  2151. writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
  2152. return NETDEV_TX_OK;
  2153. }
  2154. static inline void nv_tx_flip_ownership(struct net_device *dev)
  2155. {
  2156. struct fe_priv *np = netdev_priv(dev);
  2157. np->tx_pkts_in_progress--;
  2158. if (np->tx_change_owner) {
  2159. np->tx_change_owner->first_tx_desc->flaglen |=
  2160. cpu_to_le32(NV_TX2_VALID);
  2161. np->tx_pkts_in_progress++;
  2162. np->tx_change_owner = np->tx_change_owner->next_tx_ctx;
  2163. if (np->tx_change_owner == np->tx_end_flip)
  2164. np->tx_change_owner = NULL;
  2165. writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
  2166. }
  2167. }
  2168. /*
  2169. * nv_tx_done: check for completed packets, release the skbs.
  2170. *
  2171. * Caller must own np->lock.
  2172. */
  2173. static int nv_tx_done(struct net_device *dev, int limit)
  2174. {
  2175. struct fe_priv *np = netdev_priv(dev);
  2176. u32 flags;
  2177. int tx_work = 0;
  2178. struct ring_desc *orig_get_tx = np->get_tx.orig;
  2179. unsigned int bytes_compl = 0;
  2180. while ((np->get_tx.orig != np->put_tx.orig) &&
  2181. !((flags = le32_to_cpu(np->get_tx.orig->flaglen)) & NV_TX_VALID) &&
  2182. (tx_work < limit)) {
  2183. nv_unmap_txskb(np, np->get_tx_ctx);
  2184. if (np->desc_ver == DESC_VER_1) {
  2185. if (flags & NV_TX_LASTPACKET) {
  2186. if (flags & NV_TX_ERROR) {
  2187. if ((flags & NV_TX_RETRYERROR)
  2188. && !(flags & NV_TX_RETRYCOUNT_MASK))
  2189. nv_legacybackoff_reseed(dev);
  2190. } else {
  2191. u64_stats_update_begin(&np->swstats_tx_syncp);
  2192. np->stat_tx_packets++;
  2193. np->stat_tx_bytes += np->get_tx_ctx->skb->len;
  2194. u64_stats_update_end(&np->swstats_tx_syncp);
  2195. }
  2196. bytes_compl += np->get_tx_ctx->skb->len;
  2197. dev_kfree_skb_any(np->get_tx_ctx->skb);
  2198. np->get_tx_ctx->skb = NULL;
  2199. tx_work++;
  2200. }
  2201. } else {
  2202. if (flags & NV_TX2_LASTPACKET) {
  2203. if (flags & NV_TX2_ERROR) {
  2204. if ((flags & NV_TX2_RETRYERROR)
  2205. && !(flags & NV_TX2_RETRYCOUNT_MASK))
  2206. nv_legacybackoff_reseed(dev);
  2207. } else {
  2208. u64_stats_update_begin(&np->swstats_tx_syncp);
  2209. np->stat_tx_packets++;
  2210. np->stat_tx_bytes += np->get_tx_ctx->skb->len;
  2211. u64_stats_update_end(&np->swstats_tx_syncp);
  2212. }
  2213. bytes_compl += np->get_tx_ctx->skb->len;
  2214. dev_kfree_skb_any(np->get_tx_ctx->skb);
  2215. np->get_tx_ctx->skb = NULL;
  2216. tx_work++;
  2217. }
  2218. }
  2219. if (unlikely(np->get_tx.orig++ == np->last_tx.orig))
  2220. np->get_tx.orig = np->first_tx.orig;
  2221. if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
  2222. np->get_tx_ctx = np->first_tx_ctx;
  2223. }
  2224. netdev_completed_queue(np->dev, tx_work, bytes_compl);
  2225. if (unlikely((np->tx_stop == 1) && (np->get_tx.orig != orig_get_tx))) {
  2226. np->tx_stop = 0;
  2227. netif_wake_queue(dev);
  2228. }
  2229. return tx_work;
  2230. }
  2231. static int nv_tx_done_optimized(struct net_device *dev, int limit)
  2232. {
  2233. struct fe_priv *np = netdev_priv(dev);
  2234. u32 flags;
  2235. int tx_work = 0;
  2236. struct ring_desc_ex *orig_get_tx = np->get_tx.ex;
  2237. unsigned long bytes_cleaned = 0;
  2238. while ((np->get_tx.ex != np->put_tx.ex) &&
  2239. !((flags = le32_to_cpu(np->get_tx.ex->flaglen)) & NV_TX2_VALID) &&
  2240. (tx_work < limit)) {
  2241. nv_unmap_txskb(np, np->get_tx_ctx);
  2242. if (flags & NV_TX2_LASTPACKET) {
  2243. if (flags & NV_TX2_ERROR) {
  2244. if ((flags & NV_TX2_RETRYERROR)
  2245. && !(flags & NV_TX2_RETRYCOUNT_MASK)) {
  2246. if (np->driver_data & DEV_HAS_GEAR_MODE)
  2247. nv_gear_backoff_reseed(dev);
  2248. else
  2249. nv_legacybackoff_reseed(dev);
  2250. }
  2251. } else {
  2252. u64_stats_update_begin(&np->swstats_tx_syncp);
  2253. np->stat_tx_packets++;
  2254. np->stat_tx_bytes += np->get_tx_ctx->skb->len;
  2255. u64_stats_update_end(&np->swstats_tx_syncp);
  2256. }
  2257. bytes_cleaned += np->get_tx_ctx->skb->len;
  2258. dev_kfree_skb_any(np->get_tx_ctx->skb);
  2259. np->get_tx_ctx->skb = NULL;
  2260. tx_work++;
  2261. if (np->tx_limit)
  2262. nv_tx_flip_ownership(dev);
  2263. }
  2264. if (unlikely(np->get_tx.ex++ == np->last_tx.ex))
  2265. np->get_tx.ex = np->first_tx.ex;
  2266. if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
  2267. np->get_tx_ctx = np->first_tx_ctx;
  2268. }
  2269. netdev_completed_queue(np->dev, tx_work, bytes_cleaned);
  2270. if (unlikely((np->tx_stop == 1) && (np->get_tx.ex != orig_get_tx))) {
  2271. np->tx_stop = 0;
  2272. netif_wake_queue(dev);
  2273. }
  2274. return tx_work;
  2275. }
  2276. /*
  2277. * nv_tx_timeout: dev->tx_timeout function
  2278. * Called with netif_tx_lock held.
  2279. */
  2280. static void nv_tx_timeout(struct net_device *dev)
  2281. {
  2282. struct fe_priv *np = netdev_priv(dev);
  2283. u8 __iomem *base = get_hwbase(dev);
  2284. u32 status;
  2285. union ring_type put_tx;
  2286. int saved_tx_limit;
  2287. if (np->msi_flags & NV_MSI_X_ENABLED)
  2288. status = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
  2289. else
  2290. status = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
  2291. netdev_warn(dev, "Got tx_timeout. irq status: %08x\n", status);
  2292. if (unlikely(debug_tx_timeout)) {
  2293. int i;
  2294. netdev_info(dev, "Ring at %lx\n", (unsigned long)np->ring_addr);
  2295. netdev_info(dev, "Dumping tx registers\n");
  2296. for (i = 0; i <= np->register_size; i += 32) {
  2297. netdev_info(dev,
  2298. "%3x: %08x %08x %08x %08x "
  2299. "%08x %08x %08x %08x\n",
  2300. i,
  2301. readl(base + i + 0), readl(base + i + 4),
  2302. readl(base + i + 8), readl(base + i + 12),
  2303. readl(base + i + 16), readl(base + i + 20),
  2304. readl(base + i + 24), readl(base + i + 28));
  2305. }
  2306. netdev_info(dev, "Dumping tx ring\n");
  2307. for (i = 0; i < np->tx_ring_size; i += 4) {
  2308. if (!nv_optimized(np)) {
  2309. netdev_info(dev,
  2310. "%03x: %08x %08x // %08x %08x "
  2311. "// %08x %08x // %08x %08x\n",
  2312. i,
  2313. le32_to_cpu(np->tx_ring.orig[i].buf),
  2314. le32_to_cpu(np->tx_ring.orig[i].flaglen),
  2315. le32_to_cpu(np->tx_ring.orig[i+1].buf),
  2316. le32_to_cpu(np->tx_ring.orig[i+1].flaglen),
  2317. le32_to_cpu(np->tx_ring.orig[i+2].buf),
  2318. le32_to_cpu(np->tx_ring.orig[i+2].flaglen),
  2319. le32_to_cpu(np->tx_ring.orig[i+3].buf),
  2320. le32_to_cpu(np->tx_ring.orig[i+3].flaglen));
  2321. } else {
  2322. netdev_info(dev,
  2323. "%03x: %08x %08x %08x "
  2324. "// %08x %08x %08x "
  2325. "// %08x %08x %08x "
  2326. "// %08x %08x %08x\n",
  2327. i,
  2328. le32_to_cpu(np->tx_ring.ex[i].bufhigh),
  2329. le32_to_cpu(np->tx_ring.ex[i].buflow),
  2330. le32_to_cpu(np->tx_ring.ex[i].flaglen),
  2331. le32_to_cpu(np->tx_ring.ex[i+1].bufhigh),
  2332. le32_to_cpu(np->tx_ring.ex[i+1].buflow),
  2333. le32_to_cpu(np->tx_ring.ex[i+1].flaglen),
  2334. le32_to_cpu(np->tx_ring.ex[i+2].bufhigh),
  2335. le32_to_cpu(np->tx_ring.ex[i+2].buflow),
  2336. le32_to_cpu(np->tx_ring.ex[i+2].flaglen),
  2337. le32_to_cpu(np->tx_ring.ex[i+3].bufhigh),
  2338. le32_to_cpu(np->tx_ring.ex[i+3].buflow),
  2339. le32_to_cpu(np->tx_ring.ex[i+3].flaglen));
  2340. }
  2341. }
  2342. }
  2343. spin_lock_irq(&np->lock);
  2344. /* 1) stop tx engine */
  2345. nv_stop_tx(dev);
  2346. /* 2) complete any outstanding tx and do not give HW any limited tx pkts */
  2347. saved_tx_limit = np->tx_limit;
  2348. np->tx_limit = 0; /* prevent giving HW any limited pkts */
  2349. np->tx_stop = 0; /* prevent waking tx queue */
  2350. if (!nv_optimized(np))
  2351. nv_tx_done(dev, np->tx_ring_size);
  2352. else
  2353. nv_tx_done_optimized(dev, np->tx_ring_size);
  2354. /* save current HW position */
  2355. if (np->tx_change_owner)
  2356. put_tx.ex = np->tx_change_owner->first_tx_desc;
  2357. else
  2358. put_tx = np->put_tx;
  2359. /* 3) clear all tx state */
  2360. nv_drain_tx(dev);
  2361. nv_init_tx(dev);
  2362. /* 4) restore state to current HW position */
  2363. np->get_tx = np->put_tx = put_tx;
  2364. np->tx_limit = saved_tx_limit;
  2365. /* 5) restart tx engine */
  2366. nv_start_tx(dev);
  2367. netif_wake_queue(dev);
  2368. spin_unlock_irq(&np->lock);
  2369. }
  2370. /*
  2371. * Called when the nic notices a mismatch between the actual data len on the
  2372. * wire and the len indicated in the 802 header
  2373. */
  2374. static int nv_getlen(struct net_device *dev, void *packet, int datalen)
  2375. {
  2376. int hdrlen; /* length of the 802 header */
  2377. int protolen; /* length as stored in the proto field */
  2378. /* 1) calculate len according to header */
  2379. if (((struct vlan_ethhdr *)packet)->h_vlan_proto == htons(ETH_P_8021Q)) {
  2380. protolen = ntohs(((struct vlan_ethhdr *)packet)->h_vlan_encapsulated_proto);
  2381. hdrlen = VLAN_HLEN;
  2382. } else {
  2383. protolen = ntohs(((struct ethhdr *)packet)->h_proto);
  2384. hdrlen = ETH_HLEN;
  2385. }
  2386. if (protolen > ETH_DATA_LEN)
  2387. return datalen; /* Value in proto field not a len, no checks possible */
  2388. protolen += hdrlen;
  2389. /* consistency checks: */
  2390. if (datalen > ETH_ZLEN) {
  2391. if (datalen >= protolen) {
  2392. /* more data on wire than in 802 header, trim of
  2393. * additional data.
  2394. */
  2395. return protolen;
  2396. } else {
  2397. /* less data on wire than mentioned in header.
  2398. * Discard the packet.
  2399. */
  2400. return -1;
  2401. }
  2402. } else {
  2403. /* short packet. Accept only if 802 values are also short */
  2404. if (protolen > ETH_ZLEN) {
  2405. return -1;
  2406. }
  2407. return datalen;
  2408. }
  2409. }
  2410. static int nv_rx_process(struct net_device *dev, int limit)
  2411. {
  2412. struct fe_priv *np = netdev_priv(dev);
  2413. u32 flags;
  2414. int rx_work = 0;
  2415. struct sk_buff *skb;
  2416. int len;
  2417. while ((np->get_rx.orig != np->put_rx.orig) &&
  2418. !((flags = le32_to_cpu(np->get_rx.orig->flaglen)) & NV_RX_AVAIL) &&
  2419. (rx_work < limit)) {
  2420. /*
  2421. * the packet is for us - immediately tear down the pci mapping.
  2422. * TODO: check if a prefetch of the first cacheline improves
  2423. * the performance.
  2424. */
  2425. pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
  2426. np->get_rx_ctx->dma_len,
  2427. PCI_DMA_FROMDEVICE);
  2428. skb = np->get_rx_ctx->skb;
  2429. np->get_rx_ctx->skb = NULL;
  2430. /* look at what we actually got: */
  2431. if (np->desc_ver == DESC_VER_1) {
  2432. if (likely(flags & NV_RX_DESCRIPTORVALID)) {
  2433. len = flags & LEN_MASK_V1;
  2434. if (unlikely(flags & NV_RX_ERROR)) {
  2435. if ((flags & NV_RX_ERROR_MASK) == NV_RX_ERROR4) {
  2436. len = nv_getlen(dev, skb->data, len);
  2437. if (len < 0) {
  2438. dev_kfree_skb(skb);
  2439. goto next_pkt;
  2440. }
  2441. }
  2442. /* framing errors are soft errors */
  2443. else if ((flags & NV_RX_ERROR_MASK) == NV_RX_FRAMINGERR) {
  2444. if (flags & NV_RX_SUBSTRACT1)
  2445. len--;
  2446. }
  2447. /* the rest are hard errors */
  2448. else {
  2449. if (flags & NV_RX_MISSEDFRAME) {
  2450. u64_stats_update_begin(&np->swstats_rx_syncp);
  2451. np->stat_rx_missed_errors++;
  2452. u64_stats_update_end(&np->swstats_rx_syncp);
  2453. }
  2454. dev_kfree_skb(skb);
  2455. goto next_pkt;
  2456. }
  2457. }
  2458. } else {
  2459. dev_kfree_skb(skb);
  2460. goto next_pkt;
  2461. }
  2462. } else {
  2463. if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
  2464. len = flags & LEN_MASK_V2;
  2465. if (unlikely(flags & NV_RX2_ERROR)) {
  2466. if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_ERROR4) {
  2467. len = nv_getlen(dev, skb->data, len);
  2468. if (len < 0) {
  2469. dev_kfree_skb(skb);
  2470. goto next_pkt;
  2471. }
  2472. }
  2473. /* framing errors are soft errors */
  2474. else if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_FRAMINGERR) {
  2475. if (flags & NV_RX2_SUBSTRACT1)
  2476. len--;
  2477. }
  2478. /* the rest are hard errors */
  2479. else {
  2480. dev_kfree_skb(skb);
  2481. goto next_pkt;
  2482. }
  2483. }
  2484. if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
  2485. ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */
  2486. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2487. } else {
  2488. dev_kfree_skb(skb);
  2489. goto next_pkt;
  2490. }
  2491. }
  2492. /* got a valid packet - forward it to the network core */
  2493. skb_put(skb, len);
  2494. skb->protocol = eth_type_trans(skb, dev);
  2495. napi_gro_receive(&np->napi, skb);
  2496. u64_stats_update_begin(&np->swstats_rx_syncp);
  2497. np->stat_rx_packets++;
  2498. np->stat_rx_bytes += len;
  2499. u64_stats_update_end(&np->swstats_rx_syncp);
  2500. next_pkt:
  2501. if (unlikely(np->get_rx.orig++ == np->last_rx.orig))
  2502. np->get_rx.orig = np->first_rx.orig;
  2503. if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
  2504. np->get_rx_ctx = np->first_rx_ctx;
  2505. rx_work++;
  2506. }
  2507. return rx_work;
  2508. }
  2509. static int nv_rx_process_optimized(struct net_device *dev, int limit)
  2510. {
  2511. struct fe_priv *np = netdev_priv(dev);
  2512. u32 flags;
  2513. u32 vlanflags = 0;
  2514. int rx_work = 0;
  2515. struct sk_buff *skb;
  2516. int len;
  2517. while ((np->get_rx.ex != np->put_rx.ex) &&
  2518. !((flags = le32_to_cpu(np->get_rx.ex->flaglen)) & NV_RX2_AVAIL) &&
  2519. (rx_work < limit)) {
  2520. /*
  2521. * the packet is for us - immediately tear down the pci mapping.
  2522. * TODO: check if a prefetch of the first cacheline improves
  2523. * the performance.
  2524. */
  2525. pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
  2526. np->get_rx_ctx->dma_len,
  2527. PCI_DMA_FROMDEVICE);
  2528. skb = np->get_rx_ctx->skb;
  2529. np->get_rx_ctx->skb = NULL;
  2530. /* look at what we actually got: */
  2531. if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
  2532. len = flags & LEN_MASK_V2;
  2533. if (unlikely(flags & NV_RX2_ERROR)) {
  2534. if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_ERROR4) {
  2535. len = nv_getlen(dev, skb->data, len);
  2536. if (len < 0) {
  2537. dev_kfree_skb(skb);
  2538. goto next_pkt;
  2539. }
  2540. }
  2541. /* framing errors are soft errors */
  2542. else if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_FRAMINGERR) {
  2543. if (flags & NV_RX2_SUBSTRACT1)
  2544. len--;
  2545. }
  2546. /* the rest are hard errors */
  2547. else {
  2548. dev_kfree_skb(skb);
  2549. goto next_pkt;
  2550. }
  2551. }
  2552. if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
  2553. ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */
  2554. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2555. /* got a valid packet - forward it to the network core */
  2556. skb_put(skb, len);
  2557. skb->protocol = eth_type_trans(skb, dev);
  2558. prefetch(skb->data);
  2559. vlanflags = le32_to_cpu(np->get_rx.ex->buflow);
  2560. /*
  2561. * There's need to check for NETIF_F_HW_VLAN_RX here.
  2562. * Even if vlan rx accel is disabled,
  2563. * NV_RX3_VLAN_TAG_PRESENT is pseudo randomly set.
  2564. */
  2565. if (dev->features & NETIF_F_HW_VLAN_RX &&
  2566. vlanflags & NV_RX3_VLAN_TAG_PRESENT) {
  2567. u16 vid = vlanflags & NV_RX3_VLAN_TAG_MASK;
  2568. __vlan_hwaccel_put_tag(skb, vid);
  2569. }
  2570. napi_gro_receive(&np->napi, skb);
  2571. u64_stats_update_begin(&np->swstats_rx_syncp);
  2572. np->stat_rx_packets++;
  2573. np->stat_rx_bytes += len;
  2574. u64_stats_update_end(&np->swstats_rx_syncp);
  2575. } else {
  2576. dev_kfree_skb(skb);
  2577. }
  2578. next_pkt:
  2579. if (unlikely(np->get_rx.ex++ == np->last_rx.ex))
  2580. np->get_rx.ex = np->first_rx.ex;
  2581. if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
  2582. np->get_rx_ctx = np->first_rx_ctx;
  2583. rx_work++;
  2584. }
  2585. return rx_work;
  2586. }
  2587. static void set_bufsize(struct net_device *dev)
  2588. {
  2589. struct fe_priv *np = netdev_priv(dev);
  2590. if (dev->mtu <= ETH_DATA_LEN)
  2591. np->rx_buf_sz = ETH_DATA_LEN + NV_RX_HEADERS;
  2592. else
  2593. np->rx_buf_sz = dev->mtu + NV_RX_HEADERS;
  2594. }
  2595. /*
  2596. * nv_change_mtu: dev->change_mtu function
  2597. * Called with dev_base_lock held for read.
  2598. */
  2599. static int nv_change_mtu(struct net_device *dev, int new_mtu)
  2600. {
  2601. struct fe_priv *np = netdev_priv(dev);
  2602. int old_mtu;
  2603. if (new_mtu < 64 || new_mtu > np->pkt_limit)
  2604. return -EINVAL;
  2605. old_mtu = dev->mtu;
  2606. dev->mtu = new_mtu;
  2607. /* return early if the buffer sizes will not change */
  2608. if (old_mtu <= ETH_DATA_LEN && new_mtu <= ETH_DATA_LEN)
  2609. return 0;
  2610. if (old_mtu == new_mtu)
  2611. return 0;
  2612. /* synchronized against open : rtnl_lock() held by caller */
  2613. if (netif_running(dev)) {
  2614. u8 __iomem *base = get_hwbase(dev);
  2615. /*
  2616. * It seems that the nic preloads valid ring entries into an
  2617. * internal buffer. The procedure for flushing everything is
  2618. * guessed, there is probably a simpler approach.
  2619. * Changing the MTU is a rare event, it shouldn't matter.
  2620. */
  2621. nv_disable_irq(dev);
  2622. nv_napi_disable(dev);
  2623. netif_tx_lock_bh(dev);
  2624. netif_addr_lock(dev);
  2625. spin_lock(&np->lock);
  2626. /* stop engines */
  2627. nv_stop_rxtx(dev);
  2628. nv_txrx_reset(dev);
  2629. /* drain rx queue */
  2630. nv_drain_rxtx(dev);
  2631. /* reinit driver view of the rx queue */
  2632. set_bufsize(dev);
  2633. if (nv_init_ring(dev)) {
  2634. if (!np->in_shutdown)
  2635. mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
  2636. }
  2637. /* reinit nic view of the rx queue */
  2638. writel(np->rx_buf_sz, base + NvRegOffloadConfig);
  2639. setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
  2640. writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
  2641. base + NvRegRingSizes);
  2642. pci_push(base);
  2643. writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
  2644. pci_push(base);
  2645. /* restart rx engine */
  2646. nv_start_rxtx(dev);
  2647. spin_unlock(&np->lock);
  2648. netif_addr_unlock(dev);
  2649. netif_tx_unlock_bh(dev);
  2650. nv_napi_enable(dev);
  2651. nv_enable_irq(dev);
  2652. }
  2653. return 0;
  2654. }
  2655. static void nv_copy_mac_to_hw(struct net_device *dev)
  2656. {
  2657. u8 __iomem *base = get_hwbase(dev);
  2658. u32 mac[2];
  2659. mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
  2660. (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
  2661. mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8);
  2662. writel(mac[0], base + NvRegMacAddrA);
  2663. writel(mac[1], base + NvRegMacAddrB);
  2664. }
  2665. /*
  2666. * nv_set_mac_address: dev->set_mac_address function
  2667. * Called with rtnl_lock() held.
  2668. */
  2669. static int nv_set_mac_address(struct net_device *dev, void *addr)
  2670. {
  2671. struct fe_priv *np = netdev_priv(dev);
  2672. struct sockaddr *macaddr = (struct sockaddr *)addr;
  2673. if (!is_valid_ether_addr(macaddr->sa_data))
  2674. return -EADDRNOTAVAIL;
  2675. /* synchronized against open : rtnl_lock() held by caller */
  2676. memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN);
  2677. dev->addr_assign_type &= ~NET_ADDR_RANDOM;
  2678. if (netif_running(dev)) {
  2679. netif_tx_lock_bh(dev);
  2680. netif_addr_lock(dev);
  2681. spin_lock_irq(&np->lock);
  2682. /* stop rx engine */
  2683. nv_stop_rx(dev);
  2684. /* set mac address */
  2685. nv_copy_mac_to_hw(dev);
  2686. /* restart rx engine */
  2687. nv_start_rx(dev);
  2688. spin_unlock_irq(&np->lock);
  2689. netif_addr_unlock(dev);
  2690. netif_tx_unlock_bh(dev);
  2691. } else {
  2692. nv_copy_mac_to_hw(dev);
  2693. }
  2694. return 0;
  2695. }
  2696. /*
  2697. * nv_set_multicast: dev->set_multicast function
  2698. * Called with netif_tx_lock held.
  2699. */
  2700. static void nv_set_multicast(struct net_device *dev)
  2701. {
  2702. struct fe_priv *np = netdev_priv(dev);
  2703. u8 __iomem *base = get_hwbase(dev);
  2704. u32 addr[2];
  2705. u32 mask[2];
  2706. u32 pff = readl(base + NvRegPacketFilterFlags) & NVREG_PFF_PAUSE_RX;
  2707. memset(addr, 0, sizeof(addr));
  2708. memset(mask, 0, sizeof(mask));
  2709. if (dev->flags & IFF_PROMISC) {
  2710. pff |= NVREG_PFF_PROMISC;
  2711. } else {
  2712. pff |= NVREG_PFF_MYADDR;
  2713. if (dev->flags & IFF_ALLMULTI || !netdev_mc_empty(dev)) {
  2714. u32 alwaysOff[2];
  2715. u32 alwaysOn[2];
  2716. alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0xffffffff;
  2717. if (dev->flags & IFF_ALLMULTI) {
  2718. alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0;
  2719. } else {
  2720. struct netdev_hw_addr *ha;
  2721. netdev_for_each_mc_addr(ha, dev) {
  2722. unsigned char *hw_addr = ha->addr;
  2723. u32 a, b;
  2724. a = le32_to_cpu(*(__le32 *) hw_addr);
  2725. b = le16_to_cpu(*(__le16 *) (&hw_addr[4]));
  2726. alwaysOn[0] &= a;
  2727. alwaysOff[0] &= ~a;
  2728. alwaysOn[1] &= b;
  2729. alwaysOff[1] &= ~b;
  2730. }
  2731. }
  2732. addr[0] = alwaysOn[0];
  2733. addr[1] = alwaysOn[1];
  2734. mask[0] = alwaysOn[0] | alwaysOff[0];
  2735. mask[1] = alwaysOn[1] | alwaysOff[1];
  2736. } else {
  2737. mask[0] = NVREG_MCASTMASKA_NONE;
  2738. mask[1] = NVREG_MCASTMASKB_NONE;
  2739. }
  2740. }
  2741. addr[0] |= NVREG_MCASTADDRA_FORCE;
  2742. pff |= NVREG_PFF_ALWAYS;
  2743. spin_lock_irq(&np->lock);
  2744. nv_stop_rx(dev);
  2745. writel(addr[0], base + NvRegMulticastAddrA);
  2746. writel(addr[1], base + NvRegMulticastAddrB);
  2747. writel(mask[0], base + NvRegMulticastMaskA);
  2748. writel(mask[1], base + NvRegMulticastMaskB);
  2749. writel(pff, base + NvRegPacketFilterFlags);
  2750. nv_start_rx(dev);
  2751. spin_unlock_irq(&np->lock);
  2752. }
  2753. static void nv_update_pause(struct net_device *dev, u32 pause_flags)
  2754. {
  2755. struct fe_priv *np = netdev_priv(dev);
  2756. u8 __iomem *base = get_hwbase(dev);
  2757. np->pause_flags &= ~(NV_PAUSEFRAME_TX_ENABLE | NV_PAUSEFRAME_RX_ENABLE);
  2758. if (np->pause_flags & NV_PAUSEFRAME_RX_CAPABLE) {
  2759. u32 pff = readl(base + NvRegPacketFilterFlags) & ~NVREG_PFF_PAUSE_RX;
  2760. if (pause_flags & NV_PAUSEFRAME_RX_ENABLE) {
  2761. writel(pff|NVREG_PFF_PAUSE_RX, base + NvRegPacketFilterFlags);
  2762. np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
  2763. } else {
  2764. writel(pff, base + NvRegPacketFilterFlags);
  2765. }
  2766. }
  2767. if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE) {
  2768. u32 regmisc = readl(base + NvRegMisc1) & ~NVREG_MISC1_PAUSE_TX;
  2769. if (pause_flags & NV_PAUSEFRAME_TX_ENABLE) {
  2770. u32 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V1;
  2771. if (np->driver_data & DEV_HAS_PAUSEFRAME_TX_V2)
  2772. pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V2;
  2773. if (np->driver_data & DEV_HAS_PAUSEFRAME_TX_V3) {
  2774. pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V3;
  2775. /* limit the number of tx pause frames to a default of 8 */
  2776. writel(readl(base + NvRegTxPauseFrameLimit)|NVREG_TX_PAUSEFRAMELIMIT_ENABLE, base + NvRegTxPauseFrameLimit);
  2777. }
  2778. writel(pause_enable, base + NvRegTxPauseFrame);
  2779. writel(regmisc|NVREG_MISC1_PAUSE_TX, base + NvRegMisc1);
  2780. np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
  2781. } else {
  2782. writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
  2783. writel(regmisc, base + NvRegMisc1);
  2784. }
  2785. }
  2786. }
  2787. static void nv_force_linkspeed(struct net_device *dev, int speed, int duplex)
  2788. {
  2789. struct fe_priv *np = netdev_priv(dev);
  2790. u8 __iomem *base = get_hwbase(dev);
  2791. u32 phyreg, txreg;
  2792. int mii_status;
  2793. np->linkspeed = NVREG_LINKSPEED_FORCE|speed;
  2794. np->duplex = duplex;
  2795. /* see if gigabit phy */
  2796. mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
  2797. if (mii_status & PHY_GIGABIT) {
  2798. np->gigabit = PHY_GIGABIT;
  2799. phyreg = readl(base + NvRegSlotTime);
  2800. phyreg &= ~(0x3FF00);
  2801. if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10)
  2802. phyreg |= NVREG_SLOTTIME_10_100_FULL;
  2803. else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100)
  2804. phyreg |= NVREG_SLOTTIME_10_100_FULL;
  2805. else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
  2806. phyreg |= NVREG_SLOTTIME_1000_FULL;
  2807. writel(phyreg, base + NvRegSlotTime);
  2808. }
  2809. phyreg = readl(base + NvRegPhyInterface);
  2810. phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
  2811. if (np->duplex == 0)
  2812. phyreg |= PHY_HALF;
  2813. if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
  2814. phyreg |= PHY_100;
  2815. else if ((np->linkspeed & NVREG_LINKSPEED_MASK) ==
  2816. NVREG_LINKSPEED_1000)
  2817. phyreg |= PHY_1000;
  2818. writel(phyreg, base + NvRegPhyInterface);
  2819. if (phyreg & PHY_RGMII) {
  2820. if ((np->linkspeed & NVREG_LINKSPEED_MASK) ==
  2821. NVREG_LINKSPEED_1000)
  2822. txreg = NVREG_TX_DEFERRAL_RGMII_1000;
  2823. else
  2824. txreg = NVREG_TX_DEFERRAL_RGMII_10_100;
  2825. } else {
  2826. txreg = NVREG_TX_DEFERRAL_DEFAULT;
  2827. }
  2828. writel(txreg, base + NvRegTxDeferral);
  2829. if (np->desc_ver == DESC_VER_1) {
  2830. txreg = NVREG_TX_WM_DESC1_DEFAULT;
  2831. } else {
  2832. if ((np->linkspeed & NVREG_LINKSPEED_MASK) ==
  2833. NVREG_LINKSPEED_1000)
  2834. txreg = NVREG_TX_WM_DESC2_3_1000;
  2835. else
  2836. txreg = NVREG_TX_WM_DESC2_3_DEFAULT;
  2837. }
  2838. writel(txreg, base + NvRegTxWatermark);
  2839. writel(NVREG_MISC1_FORCE | (np->duplex ? 0 : NVREG_MISC1_HD),
  2840. base + NvRegMisc1);
  2841. pci_push(base);
  2842. writel(np->linkspeed, base + NvRegLinkSpeed);
  2843. pci_push(base);
  2844. return;
  2845. }
  2846. /**
  2847. * nv_update_linkspeed: Setup the MAC according to the link partner
  2848. * @dev: Network device to be configured
  2849. *
  2850. * The function queries the PHY and checks if there is a link partner.
  2851. * If yes, then it sets up the MAC accordingly. Otherwise, the MAC is
  2852. * set to 10 MBit HD.
  2853. *
  2854. * The function returns 0 if there is no link partner and 1 if there is
  2855. * a good link partner.
  2856. */
  2857. static int nv_update_linkspeed(struct net_device *dev)
  2858. {
  2859. struct fe_priv *np = netdev_priv(dev);
  2860. u8 __iomem *base = get_hwbase(dev);
  2861. int adv = 0;
  2862. int lpa = 0;
  2863. int adv_lpa, adv_pause, lpa_pause;
  2864. int newls = np->linkspeed;
  2865. int newdup = np->duplex;
  2866. int mii_status;
  2867. u32 bmcr;
  2868. int retval = 0;
  2869. u32 control_1000, status_1000, phyreg, pause_flags, txreg;
  2870. u32 txrxFlags = 0;
  2871. u32 phy_exp;
  2872. /* If device loopback is enabled, set carrier on and enable max link
  2873. * speed.
  2874. */
  2875. bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
  2876. if (bmcr & BMCR_LOOPBACK) {
  2877. if (netif_running(dev)) {
  2878. nv_force_linkspeed(dev, NVREG_LINKSPEED_1000, 1);
  2879. if (!netif_carrier_ok(dev))
  2880. netif_carrier_on(dev);
  2881. }
  2882. return 1;
  2883. }
  2884. /* BMSR_LSTATUS is latched, read it twice:
  2885. * we want the current value.
  2886. */
  2887. mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
  2888. mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
  2889. if (!(mii_status & BMSR_LSTATUS)) {
  2890. newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
  2891. newdup = 0;
  2892. retval = 0;
  2893. goto set_speed;
  2894. }
  2895. if (np->autoneg == 0) {
  2896. if (np->fixed_mode & LPA_100FULL) {
  2897. newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
  2898. newdup = 1;
  2899. } else if (np->fixed_mode & LPA_100HALF) {
  2900. newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
  2901. newdup = 0;
  2902. } else if (np->fixed_mode & LPA_10FULL) {
  2903. newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
  2904. newdup = 1;
  2905. } else {
  2906. newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
  2907. newdup = 0;
  2908. }
  2909. retval = 1;
  2910. goto set_speed;
  2911. }
  2912. /* check auto negotiation is complete */
  2913. if (!(mii_status & BMSR_ANEGCOMPLETE)) {
  2914. /* still in autonegotiation - configure nic for 10 MBit HD and wait. */
  2915. newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
  2916. newdup = 0;
  2917. retval = 0;
  2918. goto set_speed;
  2919. }
  2920. adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
  2921. lpa = mii_rw(dev, np->phyaddr, MII_LPA, MII_READ);
  2922. retval = 1;
  2923. if (np->gigabit == PHY_GIGABIT) {
  2924. control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
  2925. status_1000 = mii_rw(dev, np->phyaddr, MII_STAT1000, MII_READ);
  2926. if ((control_1000 & ADVERTISE_1000FULL) &&
  2927. (status_1000 & LPA_1000FULL)) {
  2928. newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_1000;
  2929. newdup = 1;
  2930. goto set_speed;
  2931. }
  2932. }
  2933. /* FIXME: handle parallel detection properly */
  2934. adv_lpa = lpa & adv;
  2935. if (adv_lpa & LPA_100FULL) {
  2936. newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
  2937. newdup = 1;
  2938. } else if (adv_lpa & LPA_100HALF) {
  2939. newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
  2940. newdup = 0;
  2941. } else if (adv_lpa & LPA_10FULL) {
  2942. newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
  2943. newdup = 1;
  2944. } else if (adv_lpa & LPA_10HALF) {
  2945. newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
  2946. newdup = 0;
  2947. } else {
  2948. newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
  2949. newdup = 0;
  2950. }
  2951. set_speed:
  2952. if (np->duplex == newdup && np->linkspeed == newls)
  2953. return retval;
  2954. np->duplex = newdup;
  2955. np->linkspeed = newls;
  2956. /* The transmitter and receiver must be restarted for safe update */
  2957. if (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START) {
  2958. txrxFlags |= NV_RESTART_TX;
  2959. nv_stop_tx(dev);
  2960. }
  2961. if (readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) {
  2962. txrxFlags |= NV_RESTART_RX;
  2963. nv_stop_rx(dev);
  2964. }
  2965. if (np->gigabit == PHY_GIGABIT) {
  2966. phyreg = readl(base + NvRegSlotTime);
  2967. phyreg &= ~(0x3FF00);
  2968. if (((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10) ||
  2969. ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100))
  2970. phyreg |= NVREG_SLOTTIME_10_100_FULL;
  2971. else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
  2972. phyreg |= NVREG_SLOTTIME_1000_FULL;
  2973. writel(phyreg, base + NvRegSlotTime);
  2974. }
  2975. phyreg = readl(base + NvRegPhyInterface);
  2976. phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
  2977. if (np->duplex == 0)
  2978. phyreg |= PHY_HALF;
  2979. if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
  2980. phyreg |= PHY_100;
  2981. else if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
  2982. phyreg |= PHY_1000;
  2983. writel(phyreg, base + NvRegPhyInterface);
  2984. phy_exp = mii_rw(dev, np->phyaddr, MII_EXPANSION, MII_READ) & EXPANSION_NWAY; /* autoneg capable */
  2985. if (phyreg & PHY_RGMII) {
  2986. if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000) {
  2987. txreg = NVREG_TX_DEFERRAL_RGMII_1000;
  2988. } else {
  2989. if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX)) {
  2990. if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_10)
  2991. txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_10;
  2992. else
  2993. txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_100;
  2994. } else {
  2995. txreg = NVREG_TX_DEFERRAL_RGMII_10_100;
  2996. }
  2997. }
  2998. } else {
  2999. if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX))
  3000. txreg = NVREG_TX_DEFERRAL_MII_STRETCH;
  3001. else
  3002. txreg = NVREG_TX_DEFERRAL_DEFAULT;
  3003. }
  3004. writel(txreg, base + NvRegTxDeferral);
  3005. if (np->desc_ver == DESC_VER_1) {
  3006. txreg = NVREG_TX_WM_DESC1_DEFAULT;
  3007. } else {
  3008. if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
  3009. txreg = NVREG_TX_WM_DESC2_3_1000;
  3010. else
  3011. txreg = NVREG_TX_WM_DESC2_3_DEFAULT;
  3012. }
  3013. writel(txreg, base + NvRegTxWatermark);
  3014. writel(NVREG_MISC1_FORCE | (np->duplex ? 0 : NVREG_MISC1_HD),
  3015. base + NvRegMisc1);
  3016. pci_push(base);
  3017. writel(np->linkspeed, base + NvRegLinkSpeed);
  3018. pci_push(base);
  3019. pause_flags = 0;
  3020. /* setup pause frame */
  3021. if (np->duplex != 0) {
  3022. if (np->autoneg && np->pause_flags & NV_PAUSEFRAME_AUTONEG) {
  3023. adv_pause = adv & (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
  3024. lpa_pause = lpa & (LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
  3025. switch (adv_pause) {
  3026. case ADVERTISE_PAUSE_CAP:
  3027. if (lpa_pause & LPA_PAUSE_CAP) {
  3028. pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
  3029. if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
  3030. pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
  3031. }
  3032. break;
  3033. case ADVERTISE_PAUSE_ASYM:
  3034. if (lpa_pause == (LPA_PAUSE_CAP | LPA_PAUSE_ASYM))
  3035. pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
  3036. break;
  3037. case ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM:
  3038. if (lpa_pause & LPA_PAUSE_CAP) {
  3039. pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
  3040. if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
  3041. pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
  3042. }
  3043. if (lpa_pause == LPA_PAUSE_ASYM)
  3044. pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
  3045. break;
  3046. }
  3047. } else {
  3048. pause_flags = np->pause_flags;
  3049. }
  3050. }
  3051. nv_update_pause(dev, pause_flags);
  3052. if (txrxFlags & NV_RESTART_TX)
  3053. nv_start_tx(dev);
  3054. if (txrxFlags & NV_RESTART_RX)
  3055. nv_start_rx(dev);
  3056. return retval;
  3057. }
  3058. static void nv_linkchange(struct net_device *dev)
  3059. {
  3060. if (nv_update_linkspeed(dev)) {
  3061. if (!netif_carrier_ok(dev)) {
  3062. netif_carrier_on(dev);
  3063. netdev_info(dev, "link up\n");
  3064. nv_txrx_gate(dev, false);
  3065. nv_start_rx(dev);
  3066. }
  3067. } else {
  3068. if (netif_carrier_ok(dev)) {
  3069. netif_carrier_off(dev);
  3070. netdev_info(dev, "link down\n");
  3071. nv_txrx_gate(dev, true);
  3072. nv_stop_rx(dev);
  3073. }
  3074. }
  3075. }
  3076. static void nv_link_irq(struct net_device *dev)
  3077. {
  3078. u8 __iomem *base = get_hwbase(dev);
  3079. u32 miistat;
  3080. miistat = readl(base + NvRegMIIStatus);
  3081. writel(NVREG_MIISTAT_LINKCHANGE, base + NvRegMIIStatus);
  3082. if (miistat & (NVREG_MIISTAT_LINKCHANGE))
  3083. nv_linkchange(dev);
  3084. }
  3085. static void nv_msi_workaround(struct fe_priv *np)
  3086. {
  3087. /* Need to toggle the msi irq mask within the ethernet device,
  3088. * otherwise, future interrupts will not be detected.
  3089. */
  3090. if (np->msi_flags & NV_MSI_ENABLED) {
  3091. u8 __iomem *base = np->base;
  3092. writel(0, base + NvRegMSIIrqMask);
  3093. writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
  3094. }
  3095. }
  3096. static inline int nv_change_interrupt_mode(struct net_device *dev, int total_work)
  3097. {
  3098. struct fe_priv *np = netdev_priv(dev);
  3099. if (optimization_mode == NV_OPTIMIZATION_MODE_DYNAMIC) {
  3100. if (total_work > NV_DYNAMIC_THRESHOLD) {
  3101. /* transition to poll based interrupts */
  3102. np->quiet_count = 0;
  3103. if (np->irqmask != NVREG_IRQMASK_CPU) {
  3104. np->irqmask = NVREG_IRQMASK_CPU;
  3105. return 1;
  3106. }
  3107. } else {
  3108. if (np->quiet_count < NV_DYNAMIC_MAX_QUIET_COUNT) {
  3109. np->quiet_count++;
  3110. } else {
  3111. /* reached a period of low activity, switch
  3112. to per tx/rx packet interrupts */
  3113. if (np->irqmask != NVREG_IRQMASK_THROUGHPUT) {
  3114. np->irqmask = NVREG_IRQMASK_THROUGHPUT;
  3115. return 1;
  3116. }
  3117. }
  3118. }
  3119. }
  3120. return 0;
  3121. }
  3122. static irqreturn_t nv_nic_irq(int foo, void *data)
  3123. {
  3124. struct net_device *dev = (struct net_device *) data;
  3125. struct fe_priv *np = netdev_priv(dev);
  3126. u8 __iomem *base = get_hwbase(dev);
  3127. if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
  3128. np->events = readl(base + NvRegIrqStatus);
  3129. writel(np->events, base + NvRegIrqStatus);
  3130. } else {
  3131. np->events = readl(base + NvRegMSIXIrqStatus);
  3132. writel(np->events, base + NvRegMSIXIrqStatus);
  3133. }
  3134. if (!(np->events & np->irqmask))
  3135. return IRQ_NONE;
  3136. nv_msi_workaround(np);
  3137. if (napi_schedule_prep(&np->napi)) {
  3138. /*
  3139. * Disable further irq's (msix not enabled with napi)
  3140. */
  3141. writel(0, base + NvRegIrqMask);
  3142. __napi_schedule(&np->napi);
  3143. }
  3144. return IRQ_HANDLED;
  3145. }
  3146. /**
  3147. * All _optimized functions are used to help increase performance
  3148. * (reduce CPU and increase throughput). They use descripter version 3,
  3149. * compiler directives, and reduce memory accesses.
  3150. */
  3151. static irqreturn_t nv_nic_irq_optimized(int foo, void *data)
  3152. {
  3153. struct net_device *dev = (struct net_device *) data;
  3154. struct fe_priv *np = netdev_priv(dev);
  3155. u8 __iomem *base = get_hwbase(dev);
  3156. if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
  3157. np->events = readl(base + NvRegIrqStatus);
  3158. writel(np->events, base + NvRegIrqStatus);
  3159. } else {
  3160. np->events = readl(base + NvRegMSIXIrqStatus);
  3161. writel(np->events, base + NvRegMSIXIrqStatus);
  3162. }
  3163. if (!(np->events & np->irqmask))
  3164. return IRQ_NONE;
  3165. nv_msi_workaround(np);
  3166. if (napi_schedule_prep(&np->napi)) {
  3167. /*
  3168. * Disable further irq's (msix not enabled with napi)
  3169. */
  3170. writel(0, base + NvRegIrqMask);
  3171. __napi_schedule(&np->napi);
  3172. }
  3173. return IRQ_HANDLED;
  3174. }
  3175. static irqreturn_t nv_nic_irq_tx(int foo, void *data)
  3176. {
  3177. struct net_device *dev = (struct net_device *) data;
  3178. struct fe_priv *np = netdev_priv(dev);
  3179. u8 __iomem *base = get_hwbase(dev);
  3180. u32 events;
  3181. int i;
  3182. unsigned long flags;
  3183. for (i = 0;; i++) {
  3184. events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL;
  3185. writel(events, base + NvRegMSIXIrqStatus);
  3186. netdev_dbg(dev, "tx irq events: %08x\n", events);
  3187. if (!(events & np->irqmask))
  3188. break;
  3189. spin_lock_irqsave(&np->lock, flags);
  3190. nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
  3191. spin_unlock_irqrestore(&np->lock, flags);
  3192. if (unlikely(i > max_interrupt_work)) {
  3193. spin_lock_irqsave(&np->lock, flags);
  3194. /* disable interrupts on the nic */
  3195. writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask);
  3196. pci_push(base);
  3197. if (!np->in_shutdown) {
  3198. np->nic_poll_irq |= NVREG_IRQ_TX_ALL;
  3199. mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
  3200. }
  3201. spin_unlock_irqrestore(&np->lock, flags);
  3202. netdev_dbg(dev, "%s: too many iterations (%d)\n",
  3203. __func__, i);
  3204. break;
  3205. }
  3206. }
  3207. return IRQ_RETVAL(i);
  3208. }
  3209. static int nv_napi_poll(struct napi_struct *napi, int budget)
  3210. {
  3211. struct fe_priv *np = container_of(napi, struct fe_priv, napi);
  3212. struct net_device *dev = np->dev;
  3213. u8 __iomem *base = get_hwbase(dev);
  3214. unsigned long flags;
  3215. int retcode;
  3216. int rx_count, tx_work = 0, rx_work = 0;
  3217. do {
  3218. if (!nv_optimized(np)) {
  3219. spin_lock_irqsave(&np->lock, flags);
  3220. tx_work += nv_tx_done(dev, np->tx_ring_size);
  3221. spin_unlock_irqrestore(&np->lock, flags);
  3222. rx_count = nv_rx_process(dev, budget - rx_work);
  3223. retcode = nv_alloc_rx(dev);
  3224. } else {
  3225. spin_lock_irqsave(&np->lock, flags);
  3226. tx_work += nv_tx_done_optimized(dev, np->tx_ring_size);
  3227. spin_unlock_irqrestore(&np->lock, flags);
  3228. rx_count = nv_rx_process_optimized(dev,
  3229. budget - rx_work);
  3230. retcode = nv_alloc_rx_optimized(dev);
  3231. }
  3232. } while (retcode == 0 &&
  3233. rx_count > 0 && (rx_work += rx_count) < budget);
  3234. if (retcode) {
  3235. spin_lock_irqsave(&np->lock, flags);
  3236. if (!np->in_shutdown)
  3237. mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
  3238. spin_unlock_irqrestore(&np->lock, flags);
  3239. }
  3240. nv_change_interrupt_mode(dev, tx_work + rx_work);
  3241. if (unlikely(np->events & NVREG_IRQ_LINK)) {
  3242. spin_lock_irqsave(&np->lock, flags);
  3243. nv_link_irq(dev);
  3244. spin_unlock_irqrestore(&np->lock, flags);
  3245. }
  3246. if (unlikely(np->need_linktimer && time_after(jiffies, np->link_timeout))) {
  3247. spin_lock_irqsave(&np->lock, flags);
  3248. nv_linkchange(dev);
  3249. spin_unlock_irqrestore(&np->lock, flags);
  3250. np->link_timeout = jiffies + LINK_TIMEOUT;
  3251. }
  3252. if (unlikely(np->events & NVREG_IRQ_RECOVER_ERROR)) {
  3253. spin_lock_irqsave(&np->lock, flags);
  3254. if (!np->in_shutdown) {
  3255. np->nic_poll_irq = np->irqmask;
  3256. np->recover_error = 1;
  3257. mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
  3258. }
  3259. spin_unlock_irqrestore(&np->lock, flags);
  3260. napi_complete(napi);
  3261. return rx_work;
  3262. }
  3263. if (rx_work < budget) {
  3264. /* re-enable interrupts
  3265. (msix not enabled in napi) */
  3266. napi_complete(napi);
  3267. writel(np->irqmask, base + NvRegIrqMask);
  3268. }
  3269. return rx_work;
  3270. }
  3271. static irqreturn_t nv_nic_irq_rx(int foo, void *data)
  3272. {
  3273. struct net_device *dev = (struct net_device *) data;
  3274. struct fe_priv *np = netdev_priv(dev);
  3275. u8 __iomem *base = get_hwbase(dev);
  3276. u32 events;
  3277. int i;
  3278. unsigned long flags;
  3279. for (i = 0;; i++) {
  3280. events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
  3281. writel(events, base + NvRegMSIXIrqStatus);
  3282. netdev_dbg(dev, "rx irq events: %08x\n", events);
  3283. if (!(events & np->irqmask))
  3284. break;
  3285. if (nv_rx_process_optimized(dev, RX_WORK_PER_LOOP)) {
  3286. if (unlikely(nv_alloc_rx_optimized(dev))) {
  3287. spin_lock_irqsave(&np->lock, flags);
  3288. if (!np->in_shutdown)
  3289. mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
  3290. spin_unlock_irqrestore(&np->lock, flags);
  3291. }
  3292. }
  3293. if (unlikely(i > max_interrupt_work)) {
  3294. spin_lock_irqsave(&np->lock, flags);
  3295. /* disable interrupts on the nic */
  3296. writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
  3297. pci_push(base);
  3298. if (!np->in_shutdown) {
  3299. np->nic_poll_irq |= NVREG_IRQ_RX_ALL;
  3300. mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
  3301. }
  3302. spin_unlock_irqrestore(&np->lock, flags);
  3303. netdev_dbg(dev, "%s: too many iterations (%d)\n",
  3304. __func__, i);
  3305. break;
  3306. }
  3307. }
  3308. return IRQ_RETVAL(i);
  3309. }
  3310. static irqreturn_t nv_nic_irq_other(int foo, void *data)
  3311. {
  3312. struct net_device *dev = (struct net_device *) data;
  3313. struct fe_priv *np = netdev_priv(dev);
  3314. u8 __iomem *base = get_hwbase(dev);
  3315. u32 events;
  3316. int i;
  3317. unsigned long flags;
  3318. for (i = 0;; i++) {
  3319. events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER;
  3320. writel(events, base + NvRegMSIXIrqStatus);
  3321. netdev_dbg(dev, "irq events: %08x\n", events);
  3322. if (!(events & np->irqmask))
  3323. break;
  3324. /* check tx in case we reached max loop limit in tx isr */
  3325. spin_lock_irqsave(&np->lock, flags);
  3326. nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
  3327. spin_unlock_irqrestore(&np->lock, flags);
  3328. if (events & NVREG_IRQ_LINK) {
  3329. spin_lock_irqsave(&np->lock, flags);
  3330. nv_link_irq(dev);
  3331. spin_unlock_irqrestore(&np->lock, flags);
  3332. }
  3333. if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
  3334. spin_lock_irqsave(&np->lock, flags);
  3335. nv_linkchange(dev);
  3336. spin_unlock_irqrestore(&np->lock, flags);
  3337. np->link_timeout = jiffies + LINK_TIMEOUT;
  3338. }
  3339. if (events & NVREG_IRQ_RECOVER_ERROR) {
  3340. spin_lock_irq(&np->lock);
  3341. /* disable interrupts on the nic */
  3342. writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
  3343. pci_push(base);
  3344. if (!np->in_shutdown) {
  3345. np->nic_poll_irq |= NVREG_IRQ_OTHER;
  3346. np->recover_error = 1;
  3347. mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
  3348. }
  3349. spin_unlock_irq(&np->lock);
  3350. break;
  3351. }
  3352. if (unlikely(i > max_interrupt_work)) {
  3353. spin_lock_irqsave(&np->lock, flags);
  3354. /* disable interrupts on the nic */
  3355. writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
  3356. pci_push(base);
  3357. if (!np->in_shutdown) {
  3358. np->nic_poll_irq |= NVREG_IRQ_OTHER;
  3359. mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
  3360. }
  3361. spin_unlock_irqrestore(&np->lock, flags);
  3362. netdev_dbg(dev, "%s: too many iterations (%d)\n",
  3363. __func__, i);
  3364. break;
  3365. }
  3366. }
  3367. return IRQ_RETVAL(i);
  3368. }
  3369. static irqreturn_t nv_nic_irq_test(int foo, void *data)
  3370. {
  3371. struct net_device *dev = (struct net_device *) data;
  3372. struct fe_priv *np = netdev_priv(dev);
  3373. u8 __iomem *base = get_hwbase(dev);
  3374. u32 events;
  3375. if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
  3376. events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
  3377. writel(events & NVREG_IRQ_TIMER, base + NvRegIrqStatus);
  3378. } else {
  3379. events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
  3380. writel(events & NVREG_IRQ_TIMER, base + NvRegMSIXIrqStatus);
  3381. }
  3382. pci_push(base);
  3383. if (!(events & NVREG_IRQ_TIMER))
  3384. return IRQ_RETVAL(0);
  3385. nv_msi_workaround(np);
  3386. spin_lock(&np->lock);
  3387. np->intr_test = 1;
  3388. spin_unlock(&np->lock);
  3389. return IRQ_RETVAL(1);
  3390. }
  3391. static void set_msix_vector_map(struct net_device *dev, u32 vector, u32 irqmask)
  3392. {
  3393. u8 __iomem *base = get_hwbase(dev);
  3394. int i;
  3395. u32 msixmap = 0;
  3396. /* Each interrupt bit can be mapped to a MSIX vector (4 bits).
  3397. * MSIXMap0 represents the first 8 interrupts and MSIXMap1 represents
  3398. * the remaining 8 interrupts.
  3399. */
  3400. for (i = 0; i < 8; i++) {
  3401. if ((irqmask >> i) & 0x1)
  3402. msixmap |= vector << (i << 2);
  3403. }
  3404. writel(readl(base + NvRegMSIXMap0) | msixmap, base + NvRegMSIXMap0);
  3405. msixmap = 0;
  3406. for (i = 0; i < 8; i++) {
  3407. if ((irqmask >> (i + 8)) & 0x1)
  3408. msixmap |= vector << (i << 2);
  3409. }
  3410. writel(readl(base + NvRegMSIXMap1) | msixmap, base + NvRegMSIXMap1);
  3411. }
  3412. static int nv_request_irq(struct net_device *dev, int intr_test)
  3413. {
  3414. struct fe_priv *np = get_nvpriv(dev);
  3415. u8 __iomem *base = get_hwbase(dev);
  3416. int ret = 1;
  3417. int i;
  3418. irqreturn_t (*handler)(int foo, void *data);
  3419. if (intr_test) {
  3420. handler = nv_nic_irq_test;
  3421. } else {
  3422. if (nv_optimized(np))
  3423. handler = nv_nic_irq_optimized;
  3424. else
  3425. handler = nv_nic_irq;
  3426. }
  3427. if (np->msi_flags & NV_MSI_X_CAPABLE) {
  3428. for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++)
  3429. np->msi_x_entry[i].entry = i;
  3430. ret = pci_enable_msix(np->pci_dev, np->msi_x_entry, (np->msi_flags & NV_MSI_X_VECTORS_MASK));
  3431. if (ret == 0) {
  3432. np->msi_flags |= NV_MSI_X_ENABLED;
  3433. if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT && !intr_test) {
  3434. /* Request irq for rx handling */
  3435. sprintf(np->name_rx, "%s-rx", dev->name);
  3436. if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector,
  3437. nv_nic_irq_rx, IRQF_SHARED, np->name_rx, dev) != 0) {
  3438. netdev_info(dev,
  3439. "request_irq failed for rx %d\n",
  3440. ret);
  3441. pci_disable_msix(np->pci_dev);
  3442. np->msi_flags &= ~NV_MSI_X_ENABLED;
  3443. goto out_err;
  3444. }
  3445. /* Request irq for tx handling */
  3446. sprintf(np->name_tx, "%s-tx", dev->name);
  3447. if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector,
  3448. nv_nic_irq_tx, IRQF_SHARED, np->name_tx, dev) != 0) {
  3449. netdev_info(dev,
  3450. "request_irq failed for tx %d\n",
  3451. ret);
  3452. pci_disable_msix(np->pci_dev);
  3453. np->msi_flags &= ~NV_MSI_X_ENABLED;
  3454. goto out_free_rx;
  3455. }
  3456. /* Request irq for link and timer handling */
  3457. sprintf(np->name_other, "%s-other", dev->name);
  3458. if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector,
  3459. nv_nic_irq_other, IRQF_SHARED, np->name_other, dev) != 0) {
  3460. netdev_info(dev,
  3461. "request_irq failed for link %d\n",
  3462. ret);
  3463. pci_disable_msix(np->pci_dev);
  3464. np->msi_flags &= ~NV_MSI_X_ENABLED;
  3465. goto out_free_tx;
  3466. }
  3467. /* map interrupts to their respective vector */
  3468. writel(0, base + NvRegMSIXMap0);
  3469. writel(0, base + NvRegMSIXMap1);
  3470. set_msix_vector_map(dev, NV_MSI_X_VECTOR_RX, NVREG_IRQ_RX_ALL);
  3471. set_msix_vector_map(dev, NV_MSI_X_VECTOR_TX, NVREG_IRQ_TX_ALL);
  3472. set_msix_vector_map(dev, NV_MSI_X_VECTOR_OTHER, NVREG_IRQ_OTHER);
  3473. } else {
  3474. /* Request irq for all interrupts */
  3475. if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector, handler, IRQF_SHARED, dev->name, dev) != 0) {
  3476. netdev_info(dev,
  3477. "request_irq failed %d\n",
  3478. ret);
  3479. pci_disable_msix(np->pci_dev);
  3480. np->msi_flags &= ~NV_MSI_X_ENABLED;
  3481. goto out_err;
  3482. }
  3483. /* map interrupts to vector 0 */
  3484. writel(0, base + NvRegMSIXMap0);
  3485. writel(0, base + NvRegMSIXMap1);
  3486. }
  3487. netdev_info(dev, "MSI-X enabled\n");
  3488. }
  3489. }
  3490. if (ret != 0 && np->msi_flags & NV_MSI_CAPABLE) {
  3491. ret = pci_enable_msi(np->pci_dev);
  3492. if (ret == 0) {
  3493. np->msi_flags |= NV_MSI_ENABLED;
  3494. dev->irq = np->pci_dev->irq;
  3495. if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0) {
  3496. netdev_info(dev, "request_irq failed %d\n",
  3497. ret);
  3498. pci_disable_msi(np->pci_dev);
  3499. np->msi_flags &= ~NV_MSI_ENABLED;
  3500. dev->irq = np->pci_dev->irq;
  3501. goto out_err;
  3502. }
  3503. /* map interrupts to vector 0 */
  3504. writel(0, base + NvRegMSIMap0);
  3505. writel(0, base + NvRegMSIMap1);
  3506. /* enable msi vector 0 */
  3507. writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
  3508. netdev_info(dev, "MSI enabled\n");
  3509. }
  3510. }
  3511. if (ret != 0) {
  3512. if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0)
  3513. goto out_err;
  3514. }
  3515. return 0;
  3516. out_free_tx:
  3517. free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, dev);
  3518. out_free_rx:
  3519. free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, dev);
  3520. out_err:
  3521. return 1;
  3522. }
  3523. static void nv_free_irq(struct net_device *dev)
  3524. {
  3525. struct fe_priv *np = get_nvpriv(dev);
  3526. int i;
  3527. if (np->msi_flags & NV_MSI_X_ENABLED) {
  3528. for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++)
  3529. free_irq(np->msi_x_entry[i].vector, dev);
  3530. pci_disable_msix(np->pci_dev);
  3531. np->msi_flags &= ~NV_MSI_X_ENABLED;
  3532. } else {
  3533. free_irq(np->pci_dev->irq, dev);
  3534. if (np->msi_flags & NV_MSI_ENABLED) {
  3535. pci_disable_msi(np->pci_dev);
  3536. np->msi_flags &= ~NV_MSI_ENABLED;
  3537. }
  3538. }
  3539. }
  3540. static void nv_do_nic_poll(unsigned long data)
  3541. {
  3542. struct net_device *dev = (struct net_device *) data;
  3543. struct fe_priv *np = netdev_priv(dev);
  3544. u8 __iomem *base = get_hwbase(dev);
  3545. u32 mask = 0;
  3546. /*
  3547. * First disable irq(s) and then
  3548. * reenable interrupts on the nic, we have to do this before calling
  3549. * nv_nic_irq because that may decide to do otherwise
  3550. */
  3551. if (!using_multi_irqs(dev)) {
  3552. if (np->msi_flags & NV_MSI_X_ENABLED)
  3553. disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
  3554. else
  3555. disable_irq_lockdep(np->pci_dev->irq);
  3556. mask = np->irqmask;
  3557. } else {
  3558. if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
  3559. disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
  3560. mask |= NVREG_IRQ_RX_ALL;
  3561. }
  3562. if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
  3563. disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
  3564. mask |= NVREG_IRQ_TX_ALL;
  3565. }
  3566. if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
  3567. disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
  3568. mask |= NVREG_IRQ_OTHER;
  3569. }
  3570. }
  3571. /* disable_irq() contains synchronize_irq, thus no irq handler can run now */
  3572. if (np->recover_error) {
  3573. np->recover_error = 0;
  3574. netdev_info(dev, "MAC in recoverable error state\n");
  3575. if (netif_running(dev)) {
  3576. netif_tx_lock_bh(dev);
  3577. netif_addr_lock(dev);
  3578. spin_lock(&np->lock);
  3579. /* stop engines */
  3580. nv_stop_rxtx(dev);
  3581. if (np->driver_data & DEV_HAS_POWER_CNTRL)
  3582. nv_mac_reset(dev);
  3583. nv_txrx_reset(dev);
  3584. /* drain rx queue */
  3585. nv_drain_rxtx(dev);
  3586. /* reinit driver view of the rx queue */
  3587. set_bufsize(dev);
  3588. if (nv_init_ring(dev)) {
  3589. if (!np->in_shutdown)
  3590. mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
  3591. }
  3592. /* reinit nic view of the rx queue */
  3593. writel(np->rx_buf_sz, base + NvRegOffloadConfig);
  3594. setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
  3595. writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
  3596. base + NvRegRingSizes);
  3597. pci_push(base);
  3598. writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
  3599. pci_push(base);
  3600. /* clear interrupts */
  3601. if (!(np->msi_flags & NV_MSI_X_ENABLED))
  3602. writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
  3603. else
  3604. writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
  3605. /* restart rx engine */
  3606. nv_start_rxtx(dev);
  3607. spin_unlock(&np->lock);
  3608. netif_addr_unlock(dev);
  3609. netif_tx_unlock_bh(dev);
  3610. }
  3611. }
  3612. writel(mask, base + NvRegIrqMask);
  3613. pci_push(base);
  3614. if (!using_multi_irqs(dev)) {
  3615. np->nic_poll_irq = 0;
  3616. if (nv_optimized(np))
  3617. nv_nic_irq_optimized(0, dev);
  3618. else
  3619. nv_nic_irq(0, dev);
  3620. if (np->msi_flags & NV_MSI_X_ENABLED)
  3621. enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
  3622. else
  3623. enable_irq_lockdep(np->pci_dev->irq);
  3624. } else {
  3625. if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
  3626. np->nic_poll_irq &= ~NVREG_IRQ_RX_ALL;
  3627. nv_nic_irq_rx(0, dev);
  3628. enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
  3629. }
  3630. if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
  3631. np->nic_poll_irq &= ~NVREG_IRQ_TX_ALL;
  3632. nv_nic_irq_tx(0, dev);
  3633. enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
  3634. }
  3635. if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
  3636. np->nic_poll_irq &= ~NVREG_IRQ_OTHER;
  3637. nv_nic_irq_other(0, dev);
  3638. enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
  3639. }
  3640. }
  3641. }
  3642. #ifdef CONFIG_NET_POLL_CONTROLLER
  3643. static void nv_poll_controller(struct net_device *dev)
  3644. {
  3645. nv_do_nic_poll((unsigned long) dev);
  3646. }
  3647. #endif
  3648. static void nv_do_stats_poll(unsigned long data)
  3649. __acquires(&netdev_priv(dev)->hwstats_lock)
  3650. __releases(&netdev_priv(dev)->hwstats_lock)
  3651. {
  3652. struct net_device *dev = (struct net_device *) data;
  3653. struct fe_priv *np = netdev_priv(dev);
  3654. /* If lock is currently taken, the stats are being refreshed
  3655. * and hence fresh enough */
  3656. if (spin_trylock(&np->hwstats_lock)) {
  3657. nv_update_stats(dev);
  3658. spin_unlock(&np->hwstats_lock);
  3659. }
  3660. if (!np->in_shutdown)
  3661. mod_timer(&np->stats_poll,
  3662. round_jiffies(jiffies + STATS_INTERVAL));
  3663. }
  3664. static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
  3665. {
  3666. struct fe_priv *np = netdev_priv(dev);
  3667. strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
  3668. strlcpy(info->version, FORCEDETH_VERSION, sizeof(info->version));
  3669. strlcpy(info->bus_info, pci_name(np->pci_dev), sizeof(info->bus_info));
  3670. }
  3671. static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
  3672. {
  3673. struct fe_priv *np = netdev_priv(dev);
  3674. wolinfo->supported = WAKE_MAGIC;
  3675. spin_lock_irq(&np->lock);
  3676. if (np->wolenabled)
  3677. wolinfo->wolopts = WAKE_MAGIC;
  3678. spin_unlock_irq(&np->lock);
  3679. }
  3680. static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
  3681. {
  3682. struct fe_priv *np = netdev_priv(dev);
  3683. u8 __iomem *base = get_hwbase(dev);
  3684. u32 flags = 0;
  3685. if (wolinfo->wolopts == 0) {
  3686. np->wolenabled = 0;
  3687. } else if (wolinfo->wolopts & WAKE_MAGIC) {
  3688. np->wolenabled = 1;
  3689. flags = NVREG_WAKEUPFLAGS_ENABLE;
  3690. }
  3691. if (netif_running(dev)) {
  3692. spin_lock_irq(&np->lock);
  3693. writel(flags, base + NvRegWakeUpFlags);
  3694. spin_unlock_irq(&np->lock);
  3695. }
  3696. device_set_wakeup_enable(&np->pci_dev->dev, np->wolenabled);
  3697. return 0;
  3698. }
  3699. static int nv_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  3700. {
  3701. struct fe_priv *np = netdev_priv(dev);
  3702. u32 speed;
  3703. int adv;
  3704. spin_lock_irq(&np->lock);
  3705. ecmd->port = PORT_MII;
  3706. if (!netif_running(dev)) {
  3707. /* We do not track link speed / duplex setting if the
  3708. * interface is disabled. Force a link check */
  3709. if (nv_update_linkspeed(dev)) {
  3710. if (!netif_carrier_ok(dev))
  3711. netif_carrier_on(dev);
  3712. } else {
  3713. if (netif_carrier_ok(dev))
  3714. netif_carrier_off(dev);
  3715. }
  3716. }
  3717. if (netif_carrier_ok(dev)) {
  3718. switch (np->linkspeed & (NVREG_LINKSPEED_MASK)) {
  3719. case NVREG_LINKSPEED_10:
  3720. speed = SPEED_10;
  3721. break;
  3722. case NVREG_LINKSPEED_100:
  3723. speed = SPEED_100;
  3724. break;
  3725. case NVREG_LINKSPEED_1000:
  3726. speed = SPEED_1000;
  3727. break;
  3728. default:
  3729. speed = -1;
  3730. break;
  3731. }
  3732. ecmd->duplex = DUPLEX_HALF;
  3733. if (np->duplex)
  3734. ecmd->duplex = DUPLEX_FULL;
  3735. } else {
  3736. speed = -1;
  3737. ecmd->duplex = -1;
  3738. }
  3739. ethtool_cmd_speed_set(ecmd, speed);
  3740. ecmd->autoneg = np->autoneg;
  3741. ecmd->advertising = ADVERTISED_MII;
  3742. if (np->autoneg) {
  3743. ecmd->advertising |= ADVERTISED_Autoneg;
  3744. adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
  3745. if (adv & ADVERTISE_10HALF)
  3746. ecmd->advertising |= ADVERTISED_10baseT_Half;
  3747. if (adv & ADVERTISE_10FULL)
  3748. ecmd->advertising |= ADVERTISED_10baseT_Full;
  3749. if (adv & ADVERTISE_100HALF)
  3750. ecmd->advertising |= ADVERTISED_100baseT_Half;
  3751. if (adv & ADVERTISE_100FULL)
  3752. ecmd->advertising |= ADVERTISED_100baseT_Full;
  3753. if (np->gigabit == PHY_GIGABIT) {
  3754. adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
  3755. if (adv & ADVERTISE_1000FULL)
  3756. ecmd->advertising |= ADVERTISED_1000baseT_Full;
  3757. }
  3758. }
  3759. ecmd->supported = (SUPPORTED_Autoneg |
  3760. SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
  3761. SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
  3762. SUPPORTED_MII);
  3763. if (np->gigabit == PHY_GIGABIT)
  3764. ecmd->supported |= SUPPORTED_1000baseT_Full;
  3765. ecmd->phy_address = np->phyaddr;
  3766. ecmd->transceiver = XCVR_EXTERNAL;
  3767. /* ignore maxtxpkt, maxrxpkt for now */
  3768. spin_unlock_irq(&np->lock);
  3769. return 0;
  3770. }
  3771. static int nv_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
  3772. {
  3773. struct fe_priv *np = netdev_priv(dev);
  3774. u32 speed = ethtool_cmd_speed(ecmd);
  3775. if (ecmd->port != PORT_MII)
  3776. return -EINVAL;
  3777. if (ecmd->transceiver != XCVR_EXTERNAL)
  3778. return -EINVAL;
  3779. if (ecmd->phy_address != np->phyaddr) {
  3780. /* TODO: support switching between multiple phys. Should be
  3781. * trivial, but not enabled due to lack of test hardware. */
  3782. return -EINVAL;
  3783. }
  3784. if (ecmd->autoneg == AUTONEG_ENABLE) {
  3785. u32 mask;
  3786. mask = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
  3787. ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full;
  3788. if (np->gigabit == PHY_GIGABIT)
  3789. mask |= ADVERTISED_1000baseT_Full;
  3790. if ((ecmd->advertising & mask) == 0)
  3791. return -EINVAL;
  3792. } else if (ecmd->autoneg == AUTONEG_DISABLE) {
  3793. /* Note: autonegotiation disable, speed 1000 intentionally
  3794. * forbidden - no one should need that. */
  3795. if (speed != SPEED_10 && speed != SPEED_100)
  3796. return -EINVAL;
  3797. if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
  3798. return -EINVAL;
  3799. } else {
  3800. return -EINVAL;
  3801. }
  3802. netif_carrier_off(dev);
  3803. if (netif_running(dev)) {
  3804. unsigned long flags;
  3805. nv_disable_irq(dev);
  3806. netif_tx_lock_bh(dev);
  3807. netif_addr_lock(dev);
  3808. /* with plain spinlock lockdep complains */
  3809. spin_lock_irqsave(&np->lock, flags);
  3810. /* stop engines */
  3811. /* FIXME:
  3812. * this can take some time, and interrupts are disabled
  3813. * due to spin_lock_irqsave, but let's hope no daemon
  3814. * is going to change the settings very often...
  3815. * Worst case:
  3816. * NV_RXSTOP_DELAY1MAX + NV_TXSTOP_DELAY1MAX
  3817. * + some minor delays, which is up to a second approximately
  3818. */
  3819. nv_stop_rxtx(dev);
  3820. spin_unlock_irqrestore(&np->lock, flags);
  3821. netif_addr_unlock(dev);
  3822. netif_tx_unlock_bh(dev);
  3823. }
  3824. if (ecmd->autoneg == AUTONEG_ENABLE) {
  3825. int adv, bmcr;
  3826. np->autoneg = 1;
  3827. /* advertise only what has been requested */
  3828. adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
  3829. adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
  3830. if (ecmd->advertising & ADVERTISED_10baseT_Half)
  3831. adv |= ADVERTISE_10HALF;
  3832. if (ecmd->advertising & ADVERTISED_10baseT_Full)
  3833. adv |= ADVERTISE_10FULL;
  3834. if (ecmd->advertising & ADVERTISED_100baseT_Half)
  3835. adv |= ADVERTISE_100HALF;
  3836. if (ecmd->advertising & ADVERTISED_100baseT_Full)
  3837. adv |= ADVERTISE_100FULL;
  3838. if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisements but disable tx pause */
  3839. adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  3840. if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
  3841. adv |= ADVERTISE_PAUSE_ASYM;
  3842. mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
  3843. if (np->gigabit == PHY_GIGABIT) {
  3844. adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
  3845. adv &= ~ADVERTISE_1000FULL;
  3846. if (ecmd->advertising & ADVERTISED_1000baseT_Full)
  3847. adv |= ADVERTISE_1000FULL;
  3848. mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
  3849. }
  3850. if (netif_running(dev))
  3851. netdev_info(dev, "link down\n");
  3852. bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
  3853. if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
  3854. bmcr |= BMCR_ANENABLE;
  3855. /* reset the phy in order for settings to stick,
  3856. * and cause autoneg to start */
  3857. if (phy_reset(dev, bmcr)) {
  3858. netdev_info(dev, "phy reset failed\n");
  3859. return -EINVAL;
  3860. }
  3861. } else {
  3862. bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
  3863. mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
  3864. }
  3865. } else {
  3866. int adv, bmcr;
  3867. np->autoneg = 0;
  3868. adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
  3869. adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
  3870. if (speed == SPEED_10 && ecmd->duplex == DUPLEX_HALF)
  3871. adv |= ADVERTISE_10HALF;
  3872. if (speed == SPEED_10 && ecmd->duplex == DUPLEX_FULL)
  3873. adv |= ADVERTISE_10FULL;
  3874. if (speed == SPEED_100 && ecmd->duplex == DUPLEX_HALF)
  3875. adv |= ADVERTISE_100HALF;
  3876. if (speed == SPEED_100 && ecmd->duplex == DUPLEX_FULL)
  3877. adv |= ADVERTISE_100FULL;
  3878. np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
  3879. if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) {/* for rx we set both advertisements but disable tx pause */
  3880. adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  3881. np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
  3882. }
  3883. if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) {
  3884. adv |= ADVERTISE_PAUSE_ASYM;
  3885. np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
  3886. }
  3887. mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
  3888. np->fixed_mode = adv;
  3889. if (np->gigabit == PHY_GIGABIT) {
  3890. adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
  3891. adv &= ~ADVERTISE_1000FULL;
  3892. mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
  3893. }
  3894. bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
  3895. bmcr &= ~(BMCR_ANENABLE|BMCR_SPEED100|BMCR_SPEED1000|BMCR_FULLDPLX);
  3896. if (np->fixed_mode & (ADVERTISE_10FULL|ADVERTISE_100FULL))
  3897. bmcr |= BMCR_FULLDPLX;
  3898. if (np->fixed_mode & (ADVERTISE_100HALF|ADVERTISE_100FULL))
  3899. bmcr |= BMCR_SPEED100;
  3900. if (np->phy_oui == PHY_OUI_MARVELL) {
  3901. /* reset the phy in order for forced mode settings to stick */
  3902. if (phy_reset(dev, bmcr)) {
  3903. netdev_info(dev, "phy reset failed\n");
  3904. return -EINVAL;
  3905. }
  3906. } else {
  3907. mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
  3908. if (netif_running(dev)) {
  3909. /* Wait a bit and then reconfigure the nic. */
  3910. udelay(10);
  3911. nv_linkchange(dev);
  3912. }
  3913. }
  3914. }
  3915. if (netif_running(dev)) {
  3916. nv_start_rxtx(dev);
  3917. nv_enable_irq(dev);
  3918. }
  3919. return 0;
  3920. }
  3921. #define FORCEDETH_REGS_VER 1
  3922. static int nv_get_regs_len(struct net_device *dev)
  3923. {
  3924. struct fe_priv *np = netdev_priv(dev);
  3925. return np->register_size;
  3926. }
  3927. static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf)
  3928. {
  3929. struct fe_priv *np = netdev_priv(dev);
  3930. u8 __iomem *base = get_hwbase(dev);
  3931. u32 *rbuf = buf;
  3932. int i;
  3933. regs->version = FORCEDETH_REGS_VER;
  3934. spin_lock_irq(&np->lock);
  3935. for (i = 0; i <= np->register_size/sizeof(u32); i++)
  3936. rbuf[i] = readl(base + i*sizeof(u32));
  3937. spin_unlock_irq(&np->lock);
  3938. }
  3939. static int nv_nway_reset(struct net_device *dev)
  3940. {
  3941. struct fe_priv *np = netdev_priv(dev);
  3942. int ret;
  3943. if (np->autoneg) {
  3944. int bmcr;
  3945. netif_carrier_off(dev);
  3946. if (netif_running(dev)) {
  3947. nv_disable_irq(dev);
  3948. netif_tx_lock_bh(dev);
  3949. netif_addr_lock(dev);
  3950. spin_lock(&np->lock);
  3951. /* stop engines */
  3952. nv_stop_rxtx(dev);
  3953. spin_unlock(&np->lock);
  3954. netif_addr_unlock(dev);
  3955. netif_tx_unlock_bh(dev);
  3956. netdev_info(dev, "link down\n");
  3957. }
  3958. bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
  3959. if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
  3960. bmcr |= BMCR_ANENABLE;
  3961. /* reset the phy in order for settings to stick*/
  3962. if (phy_reset(dev, bmcr)) {
  3963. netdev_info(dev, "phy reset failed\n");
  3964. return -EINVAL;
  3965. }
  3966. } else {
  3967. bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
  3968. mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
  3969. }
  3970. if (netif_running(dev)) {
  3971. nv_start_rxtx(dev);
  3972. nv_enable_irq(dev);
  3973. }
  3974. ret = 0;
  3975. } else {
  3976. ret = -EINVAL;
  3977. }
  3978. return ret;
  3979. }
  3980. static void nv_get_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
  3981. {
  3982. struct fe_priv *np = netdev_priv(dev);
  3983. ring->rx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
  3984. ring->tx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
  3985. ring->rx_pending = np->rx_ring_size;
  3986. ring->tx_pending = np->tx_ring_size;
  3987. }
  3988. static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
  3989. {
  3990. struct fe_priv *np = netdev_priv(dev);
  3991. u8 __iomem *base = get_hwbase(dev);
  3992. u8 *rxtx_ring, *rx_skbuff, *tx_skbuff;
  3993. dma_addr_t ring_addr;
  3994. if (ring->rx_pending < RX_RING_MIN ||
  3995. ring->tx_pending < TX_RING_MIN ||
  3996. ring->rx_mini_pending != 0 ||
  3997. ring->rx_jumbo_pending != 0 ||
  3998. (np->desc_ver == DESC_VER_1 &&
  3999. (ring->rx_pending > RING_MAX_DESC_VER_1 ||
  4000. ring->tx_pending > RING_MAX_DESC_VER_1)) ||
  4001. (np->desc_ver != DESC_VER_1 &&
  4002. (ring->rx_pending > RING_MAX_DESC_VER_2_3 ||
  4003. ring->tx_pending > RING_MAX_DESC_VER_2_3))) {
  4004. return -EINVAL;
  4005. }
  4006. /* allocate new rings */
  4007. if (!nv_optimized(np)) {
  4008. rxtx_ring = pci_alloc_consistent(np->pci_dev,
  4009. sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
  4010. &ring_addr);
  4011. } else {
  4012. rxtx_ring = pci_alloc_consistent(np->pci_dev,
  4013. sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
  4014. &ring_addr);
  4015. }
  4016. rx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->rx_pending, GFP_KERNEL);
  4017. tx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->tx_pending, GFP_KERNEL);
  4018. if (!rxtx_ring || !rx_skbuff || !tx_skbuff) {
  4019. /* fall back to old rings */
  4020. if (!nv_optimized(np)) {
  4021. if (rxtx_ring)
  4022. pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
  4023. rxtx_ring, ring_addr);
  4024. } else {
  4025. if (rxtx_ring)
  4026. pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
  4027. rxtx_ring, ring_addr);
  4028. }
  4029. kfree(rx_skbuff);
  4030. kfree(tx_skbuff);
  4031. goto exit;
  4032. }
  4033. if (netif_running(dev)) {
  4034. nv_disable_irq(dev);
  4035. nv_napi_disable(dev);
  4036. netif_tx_lock_bh(dev);
  4037. netif_addr_lock(dev);
  4038. spin_lock(&np->lock);
  4039. /* stop engines */
  4040. nv_stop_rxtx(dev);
  4041. nv_txrx_reset(dev);
  4042. /* drain queues */
  4043. nv_drain_rxtx(dev);
  4044. /* delete queues */
  4045. free_rings(dev);
  4046. }
  4047. /* set new values */
  4048. np->rx_ring_size = ring->rx_pending;
  4049. np->tx_ring_size = ring->tx_pending;
  4050. if (!nv_optimized(np)) {
  4051. np->rx_ring.orig = (struct ring_desc *)rxtx_ring;
  4052. np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
  4053. } else {
  4054. np->rx_ring.ex = (struct ring_desc_ex *)rxtx_ring;
  4055. np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
  4056. }
  4057. np->rx_skb = (struct nv_skb_map *)rx_skbuff;
  4058. np->tx_skb = (struct nv_skb_map *)tx_skbuff;
  4059. np->ring_addr = ring_addr;
  4060. memset(np->rx_skb, 0, sizeof(struct nv_skb_map) * np->rx_ring_size);
  4061. memset(np->tx_skb, 0, sizeof(struct nv_skb_map) * np->tx_ring_size);
  4062. if (netif_running(dev)) {
  4063. /* reinit driver view of the queues */
  4064. set_bufsize(dev);
  4065. if (nv_init_ring(dev)) {
  4066. if (!np->in_shutdown)
  4067. mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
  4068. }
  4069. /* reinit nic view of the queues */
  4070. writel(np->rx_buf_sz, base + NvRegOffloadConfig);
  4071. setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
  4072. writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
  4073. base + NvRegRingSizes);
  4074. pci_push(base);
  4075. writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
  4076. pci_push(base);
  4077. /* restart engines */
  4078. nv_start_rxtx(dev);
  4079. spin_unlock(&np->lock);
  4080. netif_addr_unlock(dev);
  4081. netif_tx_unlock_bh(dev);
  4082. nv_napi_enable(dev);
  4083. nv_enable_irq(dev);
  4084. }
  4085. return 0;
  4086. exit:
  4087. return -ENOMEM;
  4088. }
  4089. static void nv_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
  4090. {
  4091. struct fe_priv *np = netdev_priv(dev);
  4092. pause->autoneg = (np->pause_flags & NV_PAUSEFRAME_AUTONEG) != 0;
  4093. pause->rx_pause = (np->pause_flags & NV_PAUSEFRAME_RX_ENABLE) != 0;
  4094. pause->tx_pause = (np->pause_flags & NV_PAUSEFRAME_TX_ENABLE) != 0;
  4095. }
  4096. static int nv_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
  4097. {
  4098. struct fe_priv *np = netdev_priv(dev);
  4099. int adv, bmcr;
  4100. if ((!np->autoneg && np->duplex == 0) ||
  4101. (np->autoneg && !pause->autoneg && np->duplex == 0)) {
  4102. netdev_info(dev, "can not set pause settings when forced link is in half duplex\n");
  4103. return -EINVAL;
  4104. }
  4105. if (pause->tx_pause && !(np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)) {
  4106. netdev_info(dev, "hardware does not support tx pause frames\n");
  4107. return -EINVAL;
  4108. }
  4109. netif_carrier_off(dev);
  4110. if (netif_running(dev)) {
  4111. nv_disable_irq(dev);
  4112. netif_tx_lock_bh(dev);
  4113. netif_addr_lock(dev);
  4114. spin_lock(&np->lock);
  4115. /* stop engines */
  4116. nv_stop_rxtx(dev);
  4117. spin_unlock(&np->lock);
  4118. netif_addr_unlock(dev);
  4119. netif_tx_unlock_bh(dev);
  4120. }
  4121. np->pause_flags &= ~(NV_PAUSEFRAME_RX_REQ|NV_PAUSEFRAME_TX_REQ);
  4122. if (pause->rx_pause)
  4123. np->pause_flags |= NV_PAUSEFRAME_RX_REQ;
  4124. if (pause->tx_pause)
  4125. np->pause_flags |= NV_PAUSEFRAME_TX_REQ;
  4126. if (np->autoneg && pause->autoneg) {
  4127. np->pause_flags |= NV_PAUSEFRAME_AUTONEG;
  4128. adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
  4129. adv &= ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
  4130. if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisements but disable tx pause */
  4131. adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
  4132. if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
  4133. adv |= ADVERTISE_PAUSE_ASYM;
  4134. mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
  4135. if (netif_running(dev))
  4136. netdev_info(dev, "link down\n");
  4137. bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
  4138. bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
  4139. mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
  4140. } else {
  4141. np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
  4142. if (pause->rx_pause)
  4143. np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
  4144. if (pause->tx_pause)
  4145. np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
  4146. if (!netif_running(dev))
  4147. nv_update_linkspeed(dev);
  4148. else
  4149. nv_update_pause(dev, np->pause_flags);
  4150. }
  4151. if (netif_running(dev)) {
  4152. nv_start_rxtx(dev);
  4153. nv_enable_irq(dev);
  4154. }
  4155. return 0;
  4156. }
  4157. static int nv_set_loopback(struct net_device *dev, netdev_features_t features)
  4158. {
  4159. struct fe_priv *np = netdev_priv(dev);
  4160. unsigned long flags;
  4161. u32 miicontrol;
  4162. int err, retval = 0;
  4163. spin_lock_irqsave(&np->lock, flags);
  4164. miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
  4165. if (features & NETIF_F_LOOPBACK) {
  4166. if (miicontrol & BMCR_LOOPBACK) {
  4167. spin_unlock_irqrestore(&np->lock, flags);
  4168. netdev_info(dev, "Loopback already enabled\n");
  4169. return 0;
  4170. }
  4171. nv_disable_irq(dev);
  4172. /* Turn on loopback mode */
  4173. miicontrol |= BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000;
  4174. err = mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol);
  4175. if (err) {
  4176. retval = PHY_ERROR;
  4177. spin_unlock_irqrestore(&np->lock, flags);
  4178. phy_init(dev);
  4179. } else {
  4180. if (netif_running(dev)) {
  4181. /* Force 1000 Mbps full-duplex */
  4182. nv_force_linkspeed(dev, NVREG_LINKSPEED_1000,
  4183. 1);
  4184. /* Force link up */
  4185. netif_carrier_on(dev);
  4186. }
  4187. spin_unlock_irqrestore(&np->lock, flags);
  4188. netdev_info(dev,
  4189. "Internal PHY loopback mode enabled.\n");
  4190. }
  4191. } else {
  4192. if (!(miicontrol & BMCR_LOOPBACK)) {
  4193. spin_unlock_irqrestore(&np->lock, flags);
  4194. netdev_info(dev, "Loopback already disabled\n");
  4195. return 0;
  4196. }
  4197. nv_disable_irq(dev);
  4198. /* Turn off loopback */
  4199. spin_unlock_irqrestore(&np->lock, flags);
  4200. netdev_info(dev, "Internal PHY loopback mode disabled.\n");
  4201. phy_init(dev);
  4202. }
  4203. msleep(500);
  4204. spin_lock_irqsave(&np->lock, flags);
  4205. nv_enable_irq(dev);
  4206. spin_unlock_irqrestore(&np->lock, flags);
  4207. return retval;
  4208. }
  4209. static netdev_features_t nv_fix_features(struct net_device *dev,
  4210. netdev_features_t features)
  4211. {
  4212. /* vlan is dependent on rx checksum offload */
  4213. if (features & (NETIF_F_HW_VLAN_TX|NETIF_F_HW_VLAN_RX))
  4214. features |= NETIF_F_RXCSUM;
  4215. return features;
  4216. }
  4217. static void nv_vlan_mode(struct net_device *dev, netdev_features_t features)
  4218. {
  4219. struct fe_priv *np = get_nvpriv(dev);
  4220. spin_lock_irq(&np->lock);
  4221. if (features & NETIF_F_HW_VLAN_RX)
  4222. np->txrxctl_bits |= NVREG_TXRXCTL_VLANSTRIP;
  4223. else
  4224. np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANSTRIP;
  4225. if (features & NETIF_F_HW_VLAN_TX)
  4226. np->txrxctl_bits |= NVREG_TXRXCTL_VLANINS;
  4227. else
  4228. np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANINS;
  4229. writel(np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
  4230. spin_unlock_irq(&np->lock);
  4231. }
  4232. static int nv_set_features(struct net_device *dev, netdev_features_t features)
  4233. {
  4234. struct fe_priv *np = netdev_priv(dev);
  4235. u8 __iomem *base = get_hwbase(dev);
  4236. netdev_features_t changed = dev->features ^ features;
  4237. int retval;
  4238. if ((changed & NETIF_F_LOOPBACK) && netif_running(dev)) {
  4239. retval = nv_set_loopback(dev, features);
  4240. if (retval != 0)
  4241. return retval;
  4242. }
  4243. if (changed & NETIF_F_RXCSUM) {
  4244. spin_lock_irq(&np->lock);
  4245. if (features & NETIF_F_RXCSUM)
  4246. np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
  4247. else
  4248. np->txrxctl_bits &= ~NVREG_TXRXCTL_RXCHECK;
  4249. if (netif_running(dev))
  4250. writel(np->txrxctl_bits, base + NvRegTxRxControl);
  4251. spin_unlock_irq(&np->lock);
  4252. }
  4253. if (changed & (NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX))
  4254. nv_vlan_mode(dev, features);
  4255. return 0;
  4256. }
  4257. static int nv_get_sset_count(struct net_device *dev, int sset)
  4258. {
  4259. struct fe_priv *np = netdev_priv(dev);
  4260. switch (sset) {
  4261. case ETH_SS_TEST:
  4262. if (np->driver_data & DEV_HAS_TEST_EXTENDED)
  4263. return NV_TEST_COUNT_EXTENDED;
  4264. else
  4265. return NV_TEST_COUNT_BASE;
  4266. case ETH_SS_STATS:
  4267. if (np->driver_data & DEV_HAS_STATISTICS_V3)
  4268. return NV_DEV_STATISTICS_V3_COUNT;
  4269. else if (np->driver_data & DEV_HAS_STATISTICS_V2)
  4270. return NV_DEV_STATISTICS_V2_COUNT;
  4271. else if (np->driver_data & DEV_HAS_STATISTICS_V1)
  4272. return NV_DEV_STATISTICS_V1_COUNT;
  4273. else
  4274. return 0;
  4275. default:
  4276. return -EOPNOTSUPP;
  4277. }
  4278. }
  4279. static void nv_get_ethtool_stats(struct net_device *dev,
  4280. struct ethtool_stats *estats, u64 *buffer)
  4281. __acquires(&netdev_priv(dev)->hwstats_lock)
  4282. __releases(&netdev_priv(dev)->hwstats_lock)
  4283. {
  4284. struct fe_priv *np = netdev_priv(dev);
  4285. spin_lock_bh(&np->hwstats_lock);
  4286. nv_update_stats(dev);
  4287. memcpy(buffer, &np->estats,
  4288. nv_get_sset_count(dev, ETH_SS_STATS)*sizeof(u64));
  4289. spin_unlock_bh(&np->hwstats_lock);
  4290. }
  4291. static int nv_link_test(struct net_device *dev)
  4292. {
  4293. struct fe_priv *np = netdev_priv(dev);
  4294. int mii_status;
  4295. mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
  4296. mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
  4297. /* check phy link status */
  4298. if (!(mii_status & BMSR_LSTATUS))
  4299. return 0;
  4300. else
  4301. return 1;
  4302. }
  4303. static int nv_register_test(struct net_device *dev)
  4304. {
  4305. u8 __iomem *base = get_hwbase(dev);
  4306. int i = 0;
  4307. u32 orig_read, new_read;
  4308. do {
  4309. orig_read = readl(base + nv_registers_test[i].reg);
  4310. /* xor with mask to toggle bits */
  4311. orig_read ^= nv_registers_test[i].mask;
  4312. writel(orig_read, base + nv_registers_test[i].reg);
  4313. new_read = readl(base + nv_registers_test[i].reg);
  4314. if ((new_read & nv_registers_test[i].mask) != (orig_read & nv_registers_test[i].mask))
  4315. return 0;
  4316. /* restore original value */
  4317. orig_read ^= nv_registers_test[i].mask;
  4318. writel(orig_read, base + nv_registers_test[i].reg);
  4319. } while (nv_registers_test[++i].reg != 0);
  4320. return 1;
  4321. }
  4322. static int nv_interrupt_test(struct net_device *dev)
  4323. {
  4324. struct fe_priv *np = netdev_priv(dev);
  4325. u8 __iomem *base = get_hwbase(dev);
  4326. int ret = 1;
  4327. int testcnt;
  4328. u32 save_msi_flags, save_poll_interval = 0;
  4329. if (netif_running(dev)) {
  4330. /* free current irq */
  4331. nv_free_irq(dev);
  4332. save_poll_interval = readl(base+NvRegPollingInterval);
  4333. }
  4334. /* flag to test interrupt handler */
  4335. np->intr_test = 0;
  4336. /* setup test irq */
  4337. save_msi_flags = np->msi_flags;
  4338. np->msi_flags &= ~NV_MSI_X_VECTORS_MASK;
  4339. np->msi_flags |= 0x001; /* setup 1 vector */
  4340. if (nv_request_irq(dev, 1))
  4341. return 0;
  4342. /* setup timer interrupt */
  4343. writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
  4344. writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
  4345. nv_enable_hw_interrupts(dev, NVREG_IRQ_TIMER);
  4346. /* wait for at least one interrupt */
  4347. msleep(100);
  4348. spin_lock_irq(&np->lock);
  4349. /* flag should be set within ISR */
  4350. testcnt = np->intr_test;
  4351. if (!testcnt)
  4352. ret = 2;
  4353. nv_disable_hw_interrupts(dev, NVREG_IRQ_TIMER);
  4354. if (!(np->msi_flags & NV_MSI_X_ENABLED))
  4355. writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
  4356. else
  4357. writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
  4358. spin_unlock_irq(&np->lock);
  4359. nv_free_irq(dev);
  4360. np->msi_flags = save_msi_flags;
  4361. if (netif_running(dev)) {
  4362. writel(save_poll_interval, base + NvRegPollingInterval);
  4363. writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
  4364. /* restore original irq */
  4365. if (nv_request_irq(dev, 0))
  4366. return 0;
  4367. }
  4368. return ret;
  4369. }
  4370. static int nv_loopback_test(struct net_device *dev)
  4371. {
  4372. struct fe_priv *np = netdev_priv(dev);
  4373. u8 __iomem *base = get_hwbase(dev);
  4374. struct sk_buff *tx_skb, *rx_skb;
  4375. dma_addr_t test_dma_addr;
  4376. u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
  4377. u32 flags;
  4378. int len, i, pkt_len;
  4379. u8 *pkt_data;
  4380. u32 filter_flags = 0;
  4381. u32 misc1_flags = 0;
  4382. int ret = 1;
  4383. if (netif_running(dev)) {
  4384. nv_disable_irq(dev);
  4385. filter_flags = readl(base + NvRegPacketFilterFlags);
  4386. misc1_flags = readl(base + NvRegMisc1);
  4387. } else {
  4388. nv_txrx_reset(dev);
  4389. }
  4390. /* reinit driver view of the rx queue */
  4391. set_bufsize(dev);
  4392. nv_init_ring(dev);
  4393. /* setup hardware for loopback */
  4394. writel(NVREG_MISC1_FORCE, base + NvRegMisc1);
  4395. writel(NVREG_PFF_ALWAYS | NVREG_PFF_LOOPBACK, base + NvRegPacketFilterFlags);
  4396. /* reinit nic view of the rx queue */
  4397. writel(np->rx_buf_sz, base + NvRegOffloadConfig);
  4398. setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
  4399. writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
  4400. base + NvRegRingSizes);
  4401. pci_push(base);
  4402. /* restart rx engine */
  4403. nv_start_rxtx(dev);
  4404. /* setup packet for tx */
  4405. pkt_len = ETH_DATA_LEN;
  4406. tx_skb = netdev_alloc_skb(dev, pkt_len);
  4407. if (!tx_skb) {
  4408. netdev_err(dev, "netdev_alloc_skb() failed during loopback test\n");
  4409. ret = 0;
  4410. goto out;
  4411. }
  4412. test_dma_addr = pci_map_single(np->pci_dev, tx_skb->data,
  4413. skb_tailroom(tx_skb),
  4414. PCI_DMA_FROMDEVICE);
  4415. pkt_data = skb_put(tx_skb, pkt_len);
  4416. for (i = 0; i < pkt_len; i++)
  4417. pkt_data[i] = (u8)(i & 0xff);
  4418. if (!nv_optimized(np)) {
  4419. np->tx_ring.orig[0].buf = cpu_to_le32(test_dma_addr);
  4420. np->tx_ring.orig[0].flaglen = cpu_to_le32((pkt_len-1) | np->tx_flags | tx_flags_extra);
  4421. } else {
  4422. np->tx_ring.ex[0].bufhigh = cpu_to_le32(dma_high(test_dma_addr));
  4423. np->tx_ring.ex[0].buflow = cpu_to_le32(dma_low(test_dma_addr));
  4424. np->tx_ring.ex[0].flaglen = cpu_to_le32((pkt_len-1) | np->tx_flags | tx_flags_extra);
  4425. }
  4426. writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
  4427. pci_push(get_hwbase(dev));
  4428. msleep(500);
  4429. /* check for rx of the packet */
  4430. if (!nv_optimized(np)) {
  4431. flags = le32_to_cpu(np->rx_ring.orig[0].flaglen);
  4432. len = nv_descr_getlength(&np->rx_ring.orig[0], np->desc_ver);
  4433. } else {
  4434. flags = le32_to_cpu(np->rx_ring.ex[0].flaglen);
  4435. len = nv_descr_getlength_ex(&np->rx_ring.ex[0], np->desc_ver);
  4436. }
  4437. if (flags & NV_RX_AVAIL) {
  4438. ret = 0;
  4439. } else if (np->desc_ver == DESC_VER_1) {
  4440. if (flags & NV_RX_ERROR)
  4441. ret = 0;
  4442. } else {
  4443. if (flags & NV_RX2_ERROR)
  4444. ret = 0;
  4445. }
  4446. if (ret) {
  4447. if (len != pkt_len) {
  4448. ret = 0;
  4449. } else {
  4450. rx_skb = np->rx_skb[0].skb;
  4451. for (i = 0; i < pkt_len; i++) {
  4452. if (rx_skb->data[i] != (u8)(i & 0xff)) {
  4453. ret = 0;
  4454. break;
  4455. }
  4456. }
  4457. }
  4458. }
  4459. pci_unmap_single(np->pci_dev, test_dma_addr,
  4460. (skb_end_pointer(tx_skb) - tx_skb->data),
  4461. PCI_DMA_TODEVICE);
  4462. dev_kfree_skb_any(tx_skb);
  4463. out:
  4464. /* stop engines */
  4465. nv_stop_rxtx(dev);
  4466. nv_txrx_reset(dev);
  4467. /* drain rx queue */
  4468. nv_drain_rxtx(dev);
  4469. if (netif_running(dev)) {
  4470. writel(misc1_flags, base + NvRegMisc1);
  4471. writel(filter_flags, base + NvRegPacketFilterFlags);
  4472. nv_enable_irq(dev);
  4473. }
  4474. return ret;
  4475. }
  4476. static void nv_self_test(struct net_device *dev, struct ethtool_test *test, u64 *buffer)
  4477. {
  4478. struct fe_priv *np = netdev_priv(dev);
  4479. u8 __iomem *base = get_hwbase(dev);
  4480. int result;
  4481. memset(buffer, 0, nv_get_sset_count(dev, ETH_SS_TEST)*sizeof(u64));
  4482. if (!nv_link_test(dev)) {
  4483. test->flags |= ETH_TEST_FL_FAILED;
  4484. buffer[0] = 1;
  4485. }
  4486. if (test->flags & ETH_TEST_FL_OFFLINE) {
  4487. if (netif_running(dev)) {
  4488. netif_stop_queue(dev);
  4489. nv_napi_disable(dev);
  4490. netif_tx_lock_bh(dev);
  4491. netif_addr_lock(dev);
  4492. spin_lock_irq(&np->lock);
  4493. nv_disable_hw_interrupts(dev, np->irqmask);
  4494. if (!(np->msi_flags & NV_MSI_X_ENABLED))
  4495. writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
  4496. else
  4497. writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
  4498. /* stop engines */
  4499. nv_stop_rxtx(dev);
  4500. nv_txrx_reset(dev);
  4501. /* drain rx queue */
  4502. nv_drain_rxtx(dev);
  4503. spin_unlock_irq(&np->lock);
  4504. netif_addr_unlock(dev);
  4505. netif_tx_unlock_bh(dev);
  4506. }
  4507. if (!nv_register_test(dev)) {
  4508. test->flags |= ETH_TEST_FL_FAILED;
  4509. buffer[1] = 1;
  4510. }
  4511. result = nv_interrupt_test(dev);
  4512. if (result != 1) {
  4513. test->flags |= ETH_TEST_FL_FAILED;
  4514. buffer[2] = 1;
  4515. }
  4516. if (result == 0) {
  4517. /* bail out */
  4518. return;
  4519. }
  4520. if (!nv_loopback_test(dev)) {
  4521. test->flags |= ETH_TEST_FL_FAILED;
  4522. buffer[3] = 1;
  4523. }
  4524. if (netif_running(dev)) {
  4525. /* reinit driver view of the rx queue */
  4526. set_bufsize(dev);
  4527. if (nv_init_ring(dev)) {
  4528. if (!np->in_shutdown)
  4529. mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
  4530. }
  4531. /* reinit nic view of the rx queue */
  4532. writel(np->rx_buf_sz, base + NvRegOffloadConfig);
  4533. setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
  4534. writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
  4535. base + NvRegRingSizes);
  4536. pci_push(base);
  4537. writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
  4538. pci_push(base);
  4539. /* restart rx engine */
  4540. nv_start_rxtx(dev);
  4541. netif_start_queue(dev);
  4542. nv_napi_enable(dev);
  4543. nv_enable_hw_interrupts(dev, np->irqmask);
  4544. }
  4545. }
  4546. }
  4547. static void nv_get_strings(struct net_device *dev, u32 stringset, u8 *buffer)
  4548. {
  4549. switch (stringset) {
  4550. case ETH_SS_STATS:
  4551. memcpy(buffer, &nv_estats_str, nv_get_sset_count(dev, ETH_SS_STATS)*sizeof(struct nv_ethtool_str));
  4552. break;
  4553. case ETH_SS_TEST:
  4554. memcpy(buffer, &nv_etests_str, nv_get_sset_count(dev, ETH_SS_TEST)*sizeof(struct nv_ethtool_str));
  4555. break;
  4556. }
  4557. }
  4558. static const struct ethtool_ops ops = {
  4559. .get_drvinfo = nv_get_drvinfo,
  4560. .get_link = ethtool_op_get_link,
  4561. .get_wol = nv_get_wol,
  4562. .set_wol = nv_set_wol,
  4563. .get_settings = nv_get_settings,
  4564. .set_settings = nv_set_settings,
  4565. .get_regs_len = nv_get_regs_len,
  4566. .get_regs = nv_get_regs,
  4567. .nway_reset = nv_nway_reset,
  4568. .get_ringparam = nv_get_ringparam,
  4569. .set_ringparam = nv_set_ringparam,
  4570. .get_pauseparam = nv_get_pauseparam,
  4571. .set_pauseparam = nv_set_pauseparam,
  4572. .get_strings = nv_get_strings,
  4573. .get_ethtool_stats = nv_get_ethtool_stats,
  4574. .get_sset_count = nv_get_sset_count,
  4575. .self_test = nv_self_test,
  4576. };
  4577. /* The mgmt unit and driver use a semaphore to access the phy during init */
  4578. static int nv_mgmt_acquire_sema(struct net_device *dev)
  4579. {
  4580. struct fe_priv *np = netdev_priv(dev);
  4581. u8 __iomem *base = get_hwbase(dev);
  4582. int i;
  4583. u32 tx_ctrl, mgmt_sema;
  4584. for (i = 0; i < 10; i++) {
  4585. mgmt_sema = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_SEMA_MASK;
  4586. if (mgmt_sema == NVREG_XMITCTL_MGMT_SEMA_FREE)
  4587. break;
  4588. msleep(500);
  4589. }
  4590. if (mgmt_sema != NVREG_XMITCTL_MGMT_SEMA_FREE)
  4591. return 0;
  4592. for (i = 0; i < 2; i++) {
  4593. tx_ctrl = readl(base + NvRegTransmitterControl);
  4594. tx_ctrl |= NVREG_XMITCTL_HOST_SEMA_ACQ;
  4595. writel(tx_ctrl, base + NvRegTransmitterControl);
  4596. /* verify that semaphore was acquired */
  4597. tx_ctrl = readl(base + NvRegTransmitterControl);
  4598. if (((tx_ctrl & NVREG_XMITCTL_HOST_SEMA_MASK) == NVREG_XMITCTL_HOST_SEMA_ACQ) &&
  4599. ((tx_ctrl & NVREG_XMITCTL_MGMT_SEMA_MASK) == NVREG_XMITCTL_MGMT_SEMA_FREE)) {
  4600. np->mgmt_sema = 1;
  4601. return 1;
  4602. } else
  4603. udelay(50);
  4604. }
  4605. return 0;
  4606. }
  4607. static void nv_mgmt_release_sema(struct net_device *dev)
  4608. {
  4609. struct fe_priv *np = netdev_priv(dev);
  4610. u8 __iomem *base = get_hwbase(dev);
  4611. u32 tx_ctrl;
  4612. if (np->driver_data & DEV_HAS_MGMT_UNIT) {
  4613. if (np->mgmt_sema) {
  4614. tx_ctrl = readl(base + NvRegTransmitterControl);
  4615. tx_ctrl &= ~NVREG_XMITCTL_HOST_SEMA_ACQ;
  4616. writel(tx_ctrl, base + NvRegTransmitterControl);
  4617. }
  4618. }
  4619. }
  4620. static int nv_mgmt_get_version(struct net_device *dev)
  4621. {
  4622. struct fe_priv *np = netdev_priv(dev);
  4623. u8 __iomem *base = get_hwbase(dev);
  4624. u32 data_ready = readl(base + NvRegTransmitterControl);
  4625. u32 data_ready2 = 0;
  4626. unsigned long start;
  4627. int ready = 0;
  4628. writel(NVREG_MGMTUNITGETVERSION, base + NvRegMgmtUnitGetVersion);
  4629. writel(data_ready ^ NVREG_XMITCTL_DATA_START, base + NvRegTransmitterControl);
  4630. start = jiffies;
  4631. while (time_before(jiffies, start + 5*HZ)) {
  4632. data_ready2 = readl(base + NvRegTransmitterControl);
  4633. if ((data_ready & NVREG_XMITCTL_DATA_READY) != (data_ready2 & NVREG_XMITCTL_DATA_READY)) {
  4634. ready = 1;
  4635. break;
  4636. }
  4637. schedule_timeout_uninterruptible(1);
  4638. }
  4639. if (!ready || (data_ready2 & NVREG_XMITCTL_DATA_ERROR))
  4640. return 0;
  4641. np->mgmt_version = readl(base + NvRegMgmtUnitVersion) & NVREG_MGMTUNITVERSION;
  4642. return 1;
  4643. }
  4644. static int nv_open(struct net_device *dev)
  4645. {
  4646. struct fe_priv *np = netdev_priv(dev);
  4647. u8 __iomem *base = get_hwbase(dev);
  4648. int ret = 1;
  4649. int oom, i;
  4650. u32 low;
  4651. /* power up phy */
  4652. mii_rw(dev, np->phyaddr, MII_BMCR,
  4653. mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ) & ~BMCR_PDOWN);
  4654. nv_txrx_gate(dev, false);
  4655. /* erase previous misconfiguration */
  4656. if (np->driver_data & DEV_HAS_POWER_CNTRL)
  4657. nv_mac_reset(dev);
  4658. writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
  4659. writel(0, base + NvRegMulticastAddrB);
  4660. writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
  4661. writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
  4662. writel(0, base + NvRegPacketFilterFlags);
  4663. writel(0, base + NvRegTransmitterControl);
  4664. writel(0, base + NvRegReceiverControl);
  4665. writel(0, base + NvRegAdapterControl);
  4666. if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)
  4667. writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
  4668. /* initialize descriptor rings */
  4669. set_bufsize(dev);
  4670. oom = nv_init_ring(dev);
  4671. writel(0, base + NvRegLinkSpeed);
  4672. writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
  4673. nv_txrx_reset(dev);
  4674. writel(0, base + NvRegUnknownSetupReg6);
  4675. np->in_shutdown = 0;
  4676. /* give hw rings */
  4677. setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
  4678. writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
  4679. base + NvRegRingSizes);
  4680. writel(np->linkspeed, base + NvRegLinkSpeed);
  4681. if (np->desc_ver == DESC_VER_1)
  4682. writel(NVREG_TX_WM_DESC1_DEFAULT, base + NvRegTxWatermark);
  4683. else
  4684. writel(NVREG_TX_WM_DESC2_3_DEFAULT, base + NvRegTxWatermark);
  4685. writel(np->txrxctl_bits, base + NvRegTxRxControl);
  4686. writel(np->vlanctl_bits, base + NvRegVlanControl);
  4687. pci_push(base);
  4688. writel(NVREG_TXRXCTL_BIT1|np->txrxctl_bits, base + NvRegTxRxControl);
  4689. if (reg_delay(dev, NvRegUnknownSetupReg5,
  4690. NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31,
  4691. NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX))
  4692. netdev_info(dev,
  4693. "%s: SetupReg5, Bit 31 remained off\n", __func__);
  4694. writel(0, base + NvRegMIIMask);
  4695. writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
  4696. writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
  4697. writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1);
  4698. writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus);
  4699. writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags);
  4700. writel(np->rx_buf_sz, base + NvRegOffloadConfig);
  4701. writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus);
  4702. get_random_bytes(&low, sizeof(low));
  4703. low &= NVREG_SLOTTIME_MASK;
  4704. if (np->desc_ver == DESC_VER_1) {
  4705. writel(low|NVREG_SLOTTIME_DEFAULT, base + NvRegSlotTime);
  4706. } else {
  4707. if (!(np->driver_data & DEV_HAS_GEAR_MODE)) {
  4708. /* setup legacy backoff */
  4709. writel(NVREG_SLOTTIME_LEGBF_ENABLED|NVREG_SLOTTIME_10_100_FULL|low, base + NvRegSlotTime);
  4710. } else {
  4711. writel(NVREG_SLOTTIME_10_100_FULL, base + NvRegSlotTime);
  4712. nv_gear_backoff_reseed(dev);
  4713. }
  4714. }
  4715. writel(NVREG_TX_DEFERRAL_DEFAULT, base + NvRegTxDeferral);
  4716. writel(NVREG_RX_DEFERRAL_DEFAULT, base + NvRegRxDeferral);
  4717. if (poll_interval == -1) {
  4718. if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT)
  4719. writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval);
  4720. else
  4721. writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
  4722. } else
  4723. writel(poll_interval & 0xFFFF, base + NvRegPollingInterval);
  4724. writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
  4725. writel((np->phyaddr << NVREG_ADAPTCTL_PHYSHIFT)|NVREG_ADAPTCTL_PHYVALID|NVREG_ADAPTCTL_RUNNING,
  4726. base + NvRegAdapterControl);
  4727. writel(NVREG_MIISPEED_BIT8|NVREG_MIIDELAY, base + NvRegMIISpeed);
  4728. writel(NVREG_MII_LINKCHANGE, base + NvRegMIIMask);
  4729. if (np->wolenabled)
  4730. writel(NVREG_WAKEUPFLAGS_ENABLE , base + NvRegWakeUpFlags);
  4731. i = readl(base + NvRegPowerState);
  4732. if ((i & NVREG_POWERSTATE_POWEREDUP) == 0)
  4733. writel(NVREG_POWERSTATE_POWEREDUP|i, base + NvRegPowerState);
  4734. pci_push(base);
  4735. udelay(10);
  4736. writel(readl(base + NvRegPowerState) | NVREG_POWERSTATE_VALID, base + NvRegPowerState);
  4737. nv_disable_hw_interrupts(dev, np->irqmask);
  4738. pci_push(base);
  4739. writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
  4740. writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
  4741. pci_push(base);
  4742. if (nv_request_irq(dev, 0))
  4743. goto out_drain;
  4744. /* ask for interrupts */
  4745. nv_enable_hw_interrupts(dev, np->irqmask);
  4746. spin_lock_irq(&np->lock);
  4747. writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
  4748. writel(0, base + NvRegMulticastAddrB);
  4749. writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
  4750. writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
  4751. writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
  4752. /* One manual link speed update: Interrupts are enabled, future link
  4753. * speed changes cause interrupts and are handled by nv_link_irq().
  4754. */
  4755. {
  4756. u32 miistat;
  4757. miistat = readl(base + NvRegMIIStatus);
  4758. writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
  4759. }
  4760. /* set linkspeed to invalid value, thus force nv_update_linkspeed
  4761. * to init hw */
  4762. np->linkspeed = 0;
  4763. ret = nv_update_linkspeed(dev);
  4764. nv_start_rxtx(dev);
  4765. netif_start_queue(dev);
  4766. nv_napi_enable(dev);
  4767. if (ret) {
  4768. netif_carrier_on(dev);
  4769. } else {
  4770. netdev_info(dev, "no link during initialization\n");
  4771. netif_carrier_off(dev);
  4772. }
  4773. if (oom)
  4774. mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
  4775. /* start statistics timer */
  4776. if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_STATISTICS_V3))
  4777. mod_timer(&np->stats_poll,
  4778. round_jiffies(jiffies + STATS_INTERVAL));
  4779. spin_unlock_irq(&np->lock);
  4780. /* If the loopback feature was set while the device was down, make sure
  4781. * that it's set correctly now.
  4782. */
  4783. if (dev->features & NETIF_F_LOOPBACK)
  4784. nv_set_loopback(dev, dev->features);
  4785. return 0;
  4786. out_drain:
  4787. nv_drain_rxtx(dev);
  4788. return ret;
  4789. }
  4790. static int nv_close(struct net_device *dev)
  4791. {
  4792. struct fe_priv *np = netdev_priv(dev);
  4793. u8 __iomem *base;
  4794. spin_lock_irq(&np->lock);
  4795. np->in_shutdown = 1;
  4796. spin_unlock_irq(&np->lock);
  4797. nv_napi_disable(dev);
  4798. synchronize_irq(np->pci_dev->irq);
  4799. del_timer_sync(&np->oom_kick);
  4800. del_timer_sync(&np->nic_poll);
  4801. del_timer_sync(&np->stats_poll);
  4802. netif_stop_queue(dev);
  4803. spin_lock_irq(&np->lock);
  4804. nv_stop_rxtx(dev);
  4805. nv_txrx_reset(dev);
  4806. /* disable interrupts on the nic or we will lock up */
  4807. base = get_hwbase(dev);
  4808. nv_disable_hw_interrupts(dev, np->irqmask);
  4809. pci_push(base);
  4810. spin_unlock_irq(&np->lock);
  4811. nv_free_irq(dev);
  4812. nv_drain_rxtx(dev);
  4813. if (np->wolenabled || !phy_power_down) {
  4814. nv_txrx_gate(dev, false);
  4815. writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
  4816. nv_start_rx(dev);
  4817. } else {
  4818. /* power down phy */
  4819. mii_rw(dev, np->phyaddr, MII_BMCR,
  4820. mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ)|BMCR_PDOWN);
  4821. nv_txrx_gate(dev, true);
  4822. }
  4823. /* FIXME: power down nic */
  4824. return 0;
  4825. }
  4826. static const struct net_device_ops nv_netdev_ops = {
  4827. .ndo_open = nv_open,
  4828. .ndo_stop = nv_close,
  4829. .ndo_get_stats64 = nv_get_stats64,
  4830. .ndo_start_xmit = nv_start_xmit,
  4831. .ndo_tx_timeout = nv_tx_timeout,
  4832. .ndo_change_mtu = nv_change_mtu,
  4833. .ndo_fix_features = nv_fix_features,
  4834. .ndo_set_features = nv_set_features,
  4835. .ndo_validate_addr = eth_validate_addr,
  4836. .ndo_set_mac_address = nv_set_mac_address,
  4837. .ndo_set_rx_mode = nv_set_multicast,
  4838. #ifdef CONFIG_NET_POLL_CONTROLLER
  4839. .ndo_poll_controller = nv_poll_controller,
  4840. #endif
  4841. };
  4842. static const struct net_device_ops nv_netdev_ops_optimized = {
  4843. .ndo_open = nv_open,
  4844. .ndo_stop = nv_close,
  4845. .ndo_get_stats64 = nv_get_stats64,
  4846. .ndo_start_xmit = nv_start_xmit_optimized,
  4847. .ndo_tx_timeout = nv_tx_timeout,
  4848. .ndo_change_mtu = nv_change_mtu,
  4849. .ndo_fix_features = nv_fix_features,
  4850. .ndo_set_features = nv_set_features,
  4851. .ndo_validate_addr = eth_validate_addr,
  4852. .ndo_set_mac_address = nv_set_mac_address,
  4853. .ndo_set_rx_mode = nv_set_multicast,
  4854. #ifdef CONFIG_NET_POLL_CONTROLLER
  4855. .ndo_poll_controller = nv_poll_controller,
  4856. #endif
  4857. };
  4858. static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
  4859. {
  4860. struct net_device *dev;
  4861. struct fe_priv *np;
  4862. unsigned long addr;
  4863. u8 __iomem *base;
  4864. int err, i;
  4865. u32 powerstate, txreg;
  4866. u32 phystate_orig = 0, phystate;
  4867. int phyinitialized = 0;
  4868. static int printed_version;
  4869. if (!printed_version++)
  4870. pr_info("Reverse Engineered nForce ethernet driver. Version %s.\n",
  4871. FORCEDETH_VERSION);
  4872. dev = alloc_etherdev(sizeof(struct fe_priv));
  4873. err = -ENOMEM;
  4874. if (!dev)
  4875. goto out;
  4876. np = netdev_priv(dev);
  4877. np->dev = dev;
  4878. np->pci_dev = pci_dev;
  4879. spin_lock_init(&np->lock);
  4880. spin_lock_init(&np->hwstats_lock);
  4881. SET_NETDEV_DEV(dev, &pci_dev->dev);
  4882. u64_stats_init(&np->swstats_rx_syncp);
  4883. u64_stats_init(&np->swstats_tx_syncp);
  4884. init_timer(&np->oom_kick);
  4885. np->oom_kick.data = (unsigned long) dev;
  4886. np->oom_kick.function = nv_do_rx_refill; /* timer handler */
  4887. init_timer(&np->nic_poll);
  4888. np->nic_poll.data = (unsigned long) dev;
  4889. np->nic_poll.function = nv_do_nic_poll; /* timer handler */
  4890. init_timer_deferrable(&np->stats_poll);
  4891. np->stats_poll.data = (unsigned long) dev;
  4892. np->stats_poll.function = nv_do_stats_poll; /* timer handler */
  4893. err = pci_enable_device(pci_dev);
  4894. if (err)
  4895. goto out_free;
  4896. pci_set_master(pci_dev);
  4897. err = pci_request_regions(pci_dev, DRV_NAME);
  4898. if (err < 0)
  4899. goto out_disable;
  4900. if (id->driver_data & (DEV_HAS_VLAN|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V2|DEV_HAS_STATISTICS_V3))
  4901. np->register_size = NV_PCI_REGSZ_VER3;
  4902. else if (id->driver_data & DEV_HAS_STATISTICS_V1)
  4903. np->register_size = NV_PCI_REGSZ_VER2;
  4904. else
  4905. np->register_size = NV_PCI_REGSZ_VER1;
  4906. err = -EINVAL;
  4907. addr = 0;
  4908. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  4909. if (pci_resource_flags(pci_dev, i) & IORESOURCE_MEM &&
  4910. pci_resource_len(pci_dev, i) >= np->register_size) {
  4911. addr = pci_resource_start(pci_dev, i);
  4912. break;
  4913. }
  4914. }
  4915. if (i == DEVICE_COUNT_RESOURCE) {
  4916. dev_info(&pci_dev->dev, "Couldn't find register window\n");
  4917. goto out_relreg;
  4918. }
  4919. /* copy of driver data */
  4920. np->driver_data = id->driver_data;
  4921. /* copy of device id */
  4922. np->device_id = id->device;
  4923. /* handle different descriptor versions */
  4924. if (id->driver_data & DEV_HAS_HIGH_DMA) {
  4925. /* packet format 3: supports 40-bit addressing */
  4926. np->desc_ver = DESC_VER_3;
  4927. np->txrxctl_bits = NVREG_TXRXCTL_DESC_3;
  4928. if (dma_64bit) {
  4929. if (pci_set_dma_mask(pci_dev, DMA_BIT_MASK(39)))
  4930. dev_info(&pci_dev->dev,
  4931. "64-bit DMA failed, using 32-bit addressing\n");
  4932. else
  4933. dev->features |= NETIF_F_HIGHDMA;
  4934. if (pci_set_consistent_dma_mask(pci_dev, DMA_BIT_MASK(39))) {
  4935. dev_info(&pci_dev->dev,
  4936. "64-bit DMA (consistent) failed, using 32-bit ring buffers\n");
  4937. }
  4938. }
  4939. } else if (id->driver_data & DEV_HAS_LARGEDESC) {
  4940. /* packet format 2: supports jumbo frames */
  4941. np->desc_ver = DESC_VER_2;
  4942. np->txrxctl_bits = NVREG_TXRXCTL_DESC_2;
  4943. } else {
  4944. /* original packet format */
  4945. np->desc_ver = DESC_VER_1;
  4946. np->txrxctl_bits = NVREG_TXRXCTL_DESC_1;
  4947. }
  4948. np->pkt_limit = NV_PKTLIMIT_1;
  4949. if (id->driver_data & DEV_HAS_LARGEDESC)
  4950. np->pkt_limit = NV_PKTLIMIT_2;
  4951. if (id->driver_data & DEV_HAS_CHECKSUM) {
  4952. np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
  4953. dev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_SG |
  4954. NETIF_F_TSO | NETIF_F_RXCSUM;
  4955. }
  4956. np->vlanctl_bits = 0;
  4957. if (id->driver_data & DEV_HAS_VLAN) {
  4958. np->vlanctl_bits = NVREG_VLANCONTROL_ENABLE;
  4959. dev->hw_features |= NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX;
  4960. }
  4961. dev->features |= dev->hw_features;
  4962. /* Add loopback capability to the device. */
  4963. dev->hw_features |= NETIF_F_LOOPBACK;
  4964. np->pause_flags = NV_PAUSEFRAME_RX_CAPABLE | NV_PAUSEFRAME_RX_REQ | NV_PAUSEFRAME_AUTONEG;
  4965. if ((id->driver_data & DEV_HAS_PAUSEFRAME_TX_V1) ||
  4966. (id->driver_data & DEV_HAS_PAUSEFRAME_TX_V2) ||
  4967. (id->driver_data & DEV_HAS_PAUSEFRAME_TX_V3)) {
  4968. np->pause_flags |= NV_PAUSEFRAME_TX_CAPABLE | NV_PAUSEFRAME_TX_REQ;
  4969. }
  4970. err = -ENOMEM;
  4971. np->base = ioremap(addr, np->register_size);
  4972. if (!np->base)
  4973. goto out_relreg;
  4974. dev->base_addr = (unsigned long)np->base;
  4975. dev->irq = pci_dev->irq;
  4976. np->rx_ring_size = RX_RING_DEFAULT;
  4977. np->tx_ring_size = TX_RING_DEFAULT;
  4978. if (!nv_optimized(np)) {
  4979. np->rx_ring.orig = pci_alloc_consistent(pci_dev,
  4980. sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
  4981. &np->ring_addr);
  4982. if (!np->rx_ring.orig)
  4983. goto out_unmap;
  4984. np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
  4985. } else {
  4986. np->rx_ring.ex = pci_alloc_consistent(pci_dev,
  4987. sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
  4988. &np->ring_addr);
  4989. if (!np->rx_ring.ex)
  4990. goto out_unmap;
  4991. np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
  4992. }
  4993. np->rx_skb = kcalloc(np->rx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL);
  4994. np->tx_skb = kcalloc(np->tx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL);
  4995. if (!np->rx_skb || !np->tx_skb)
  4996. goto out_freering;
  4997. if (!nv_optimized(np))
  4998. dev->netdev_ops = &nv_netdev_ops;
  4999. else
  5000. dev->netdev_ops = &nv_netdev_ops_optimized;
  5001. netif_napi_add(dev, &np->napi, nv_napi_poll, RX_WORK_PER_LOOP);
  5002. SET_ETHTOOL_OPS(dev, &ops);
  5003. dev->watchdog_timeo = NV_WATCHDOG_TIMEO;
  5004. pci_set_drvdata(pci_dev, dev);
  5005. /* read the mac address */
  5006. base = get_hwbase(dev);
  5007. np->orig_mac[0] = readl(base + NvRegMacAddrA);
  5008. np->orig_mac[1] = readl(base + NvRegMacAddrB);
  5009. /* check the workaround bit for correct mac address order */
  5010. txreg = readl(base + NvRegTransmitPoll);
  5011. if (id->driver_data & DEV_HAS_CORRECT_MACADDR) {
  5012. /* mac address is already in correct order */
  5013. dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
  5014. dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
  5015. dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
  5016. dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
  5017. dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
  5018. dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
  5019. } else if (txreg & NVREG_TRANSMITPOLL_MAC_ADDR_REV) {
  5020. /* mac address is already in correct order */
  5021. dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
  5022. dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
  5023. dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
  5024. dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
  5025. dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
  5026. dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
  5027. /*
  5028. * Set orig mac address back to the reversed version.
  5029. * This flag will be cleared during low power transition.
  5030. * Therefore, we should always put back the reversed address.
  5031. */
  5032. np->orig_mac[0] = (dev->dev_addr[5] << 0) + (dev->dev_addr[4] << 8) +
  5033. (dev->dev_addr[3] << 16) + (dev->dev_addr[2] << 24);
  5034. np->orig_mac[1] = (dev->dev_addr[1] << 0) + (dev->dev_addr[0] << 8);
  5035. } else {
  5036. /* need to reverse mac address to correct order */
  5037. dev->dev_addr[0] = (np->orig_mac[1] >> 8) & 0xff;
  5038. dev->dev_addr[1] = (np->orig_mac[1] >> 0) & 0xff;
  5039. dev->dev_addr[2] = (np->orig_mac[0] >> 24) & 0xff;
  5040. dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff;
  5041. dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff;
  5042. dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff;
  5043. writel(txreg|NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
  5044. dev_dbg(&pci_dev->dev,
  5045. "%s: set workaround bit for reversed mac addr\n",
  5046. __func__);
  5047. }
  5048. memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
  5049. if (!is_valid_ether_addr(dev->perm_addr)) {
  5050. /*
  5051. * Bad mac address. At least one bios sets the mac address
  5052. * to 01:23:45:67:89:ab
  5053. */
  5054. dev_err(&pci_dev->dev,
  5055. "Invalid MAC address detected: %pM - Please complain to your hardware vendor.\n",
  5056. dev->dev_addr);
  5057. eth_hw_addr_random(dev);
  5058. dev_err(&pci_dev->dev,
  5059. "Using random MAC address: %pM\n", dev->dev_addr);
  5060. }
  5061. /* set mac address */
  5062. nv_copy_mac_to_hw(dev);
  5063. /* disable WOL */
  5064. writel(0, base + NvRegWakeUpFlags);
  5065. np->wolenabled = 0;
  5066. device_set_wakeup_enable(&pci_dev->dev, false);
  5067. if (id->driver_data & DEV_HAS_POWER_CNTRL) {
  5068. /* take phy and nic out of low power mode */
  5069. powerstate = readl(base + NvRegPowerState2);
  5070. powerstate &= ~NVREG_POWERSTATE2_POWERUP_MASK;
  5071. if ((id->driver_data & DEV_NEED_LOW_POWER_FIX) &&
  5072. pci_dev->revision >= 0xA3)
  5073. powerstate |= NVREG_POWERSTATE2_POWERUP_REV_A3;
  5074. writel(powerstate, base + NvRegPowerState2);
  5075. }
  5076. if (np->desc_ver == DESC_VER_1)
  5077. np->tx_flags = NV_TX_VALID;
  5078. else
  5079. np->tx_flags = NV_TX2_VALID;
  5080. np->msi_flags = 0;
  5081. if ((id->driver_data & DEV_HAS_MSI) && msi)
  5082. np->msi_flags |= NV_MSI_CAPABLE;
  5083. if ((id->driver_data & DEV_HAS_MSI_X) && msix) {
  5084. /* msix has had reported issues when modifying irqmask
  5085. as in the case of napi, therefore, disable for now
  5086. */
  5087. #if 0
  5088. np->msi_flags |= NV_MSI_X_CAPABLE;
  5089. #endif
  5090. }
  5091. if (optimization_mode == NV_OPTIMIZATION_MODE_CPU) {
  5092. np->irqmask = NVREG_IRQMASK_CPU;
  5093. if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
  5094. np->msi_flags |= 0x0001;
  5095. } else if (optimization_mode == NV_OPTIMIZATION_MODE_DYNAMIC &&
  5096. !(id->driver_data & DEV_NEED_TIMERIRQ)) {
  5097. /* start off in throughput mode */
  5098. np->irqmask = NVREG_IRQMASK_THROUGHPUT;
  5099. /* remove support for msix mode */
  5100. np->msi_flags &= ~NV_MSI_X_CAPABLE;
  5101. } else {
  5102. optimization_mode = NV_OPTIMIZATION_MODE_THROUGHPUT;
  5103. np->irqmask = NVREG_IRQMASK_THROUGHPUT;
  5104. if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
  5105. np->msi_flags |= 0x0003;
  5106. }
  5107. if (id->driver_data & DEV_NEED_TIMERIRQ)
  5108. np->irqmask |= NVREG_IRQ_TIMER;
  5109. if (id->driver_data & DEV_NEED_LINKTIMER) {
  5110. np->need_linktimer = 1;
  5111. np->link_timeout = jiffies + LINK_TIMEOUT;
  5112. } else {
  5113. np->need_linktimer = 0;
  5114. }
  5115. /* Limit the number of tx's outstanding for hw bug */
  5116. if (id->driver_data & DEV_NEED_TX_LIMIT) {
  5117. np->tx_limit = 1;
  5118. if (((id->driver_data & DEV_NEED_TX_LIMIT2) == DEV_NEED_TX_LIMIT2) &&
  5119. pci_dev->revision >= 0xA2)
  5120. np->tx_limit = 0;
  5121. }
  5122. /* clear phy state and temporarily halt phy interrupts */
  5123. writel(0, base + NvRegMIIMask);
  5124. phystate = readl(base + NvRegAdapterControl);
  5125. if (phystate & NVREG_ADAPTCTL_RUNNING) {
  5126. phystate_orig = 1;
  5127. phystate &= ~NVREG_ADAPTCTL_RUNNING;
  5128. writel(phystate, base + NvRegAdapterControl);
  5129. }
  5130. writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
  5131. if (id->driver_data & DEV_HAS_MGMT_UNIT) {
  5132. /* management unit running on the mac? */
  5133. if ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_ST) &&
  5134. (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_PHY_INIT) &&
  5135. nv_mgmt_acquire_sema(dev) &&
  5136. nv_mgmt_get_version(dev)) {
  5137. np->mac_in_use = 1;
  5138. if (np->mgmt_version > 0)
  5139. np->mac_in_use = readl(base + NvRegMgmtUnitControl) & NVREG_MGMTUNITCONTROL_INUSE;
  5140. /* management unit setup the phy already? */
  5141. if (np->mac_in_use &&
  5142. ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK) ==
  5143. NVREG_XMITCTL_SYNC_PHY_INIT)) {
  5144. /* phy is inited by mgmt unit */
  5145. phyinitialized = 1;
  5146. } else {
  5147. /* we need to init the phy */
  5148. }
  5149. }
  5150. }
  5151. /* find a suitable phy */
  5152. for (i = 1; i <= 32; i++) {
  5153. int id1, id2;
  5154. int phyaddr = i & 0x1F;
  5155. spin_lock_irq(&np->lock);
  5156. id1 = mii_rw(dev, phyaddr, MII_PHYSID1, MII_READ);
  5157. spin_unlock_irq(&np->lock);
  5158. if (id1 < 0 || id1 == 0xffff)
  5159. continue;
  5160. spin_lock_irq(&np->lock);
  5161. id2 = mii_rw(dev, phyaddr, MII_PHYSID2, MII_READ);
  5162. spin_unlock_irq(&np->lock);
  5163. if (id2 < 0 || id2 == 0xffff)
  5164. continue;
  5165. np->phy_model = id2 & PHYID2_MODEL_MASK;
  5166. id1 = (id1 & PHYID1_OUI_MASK) << PHYID1_OUI_SHFT;
  5167. id2 = (id2 & PHYID2_OUI_MASK) >> PHYID2_OUI_SHFT;
  5168. np->phyaddr = phyaddr;
  5169. np->phy_oui = id1 | id2;
  5170. /* Realtek hardcoded phy id1 to all zero's on certain phys */
  5171. if (np->phy_oui == PHY_OUI_REALTEK2)
  5172. np->phy_oui = PHY_OUI_REALTEK;
  5173. /* Setup phy revision for Realtek */
  5174. if (np->phy_oui == PHY_OUI_REALTEK && np->phy_model == PHY_MODEL_REALTEK_8211)
  5175. np->phy_rev = mii_rw(dev, phyaddr, MII_RESV1, MII_READ) & PHY_REV_MASK;
  5176. break;
  5177. }
  5178. if (i == 33) {
  5179. dev_info(&pci_dev->dev, "open: Could not find a valid PHY\n");
  5180. goto out_error;
  5181. }
  5182. if (!phyinitialized) {
  5183. /* reset it */
  5184. phy_init(dev);
  5185. } else {
  5186. /* see if it is a gigabit phy */
  5187. u32 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
  5188. if (mii_status & PHY_GIGABIT)
  5189. np->gigabit = PHY_GIGABIT;
  5190. }
  5191. /* set default link speed settings */
  5192. np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
  5193. np->duplex = 0;
  5194. np->autoneg = 1;
  5195. err = register_netdev(dev);
  5196. if (err) {
  5197. dev_info(&pci_dev->dev, "unable to register netdev: %d\n", err);
  5198. goto out_error;
  5199. }
  5200. if (id->driver_data & DEV_HAS_VLAN)
  5201. nv_vlan_mode(dev, dev->features);
  5202. netif_carrier_off(dev);
  5203. dev_info(&pci_dev->dev, "ifname %s, PHY OUI 0x%x @ %d, addr %pM\n",
  5204. dev->name, np->phy_oui, np->phyaddr, dev->dev_addr);
  5205. dev_info(&pci_dev->dev, "%s%s%s%s%s%s%s%s%s%s%sdesc-v%u\n",
  5206. dev->features & NETIF_F_HIGHDMA ? "highdma " : "",
  5207. dev->features & (NETIF_F_IP_CSUM | NETIF_F_SG) ?
  5208. "csum " : "",
  5209. dev->features & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX) ?
  5210. "vlan " : "",
  5211. dev->features & (NETIF_F_LOOPBACK) ?
  5212. "loopback " : "",
  5213. id->driver_data & DEV_HAS_POWER_CNTRL ? "pwrctl " : "",
  5214. id->driver_data & DEV_HAS_MGMT_UNIT ? "mgmt " : "",
  5215. id->driver_data & DEV_NEED_TIMERIRQ ? "timirq " : "",
  5216. np->gigabit == PHY_GIGABIT ? "gbit " : "",
  5217. np->need_linktimer ? "lnktim " : "",
  5218. np->msi_flags & NV_MSI_CAPABLE ? "msi " : "",
  5219. np->msi_flags & NV_MSI_X_CAPABLE ? "msi-x " : "",
  5220. np->desc_ver);
  5221. return 0;
  5222. out_error:
  5223. if (phystate_orig)
  5224. writel(phystate|NVREG_ADAPTCTL_RUNNING, base + NvRegAdapterControl);
  5225. pci_set_drvdata(pci_dev, NULL);
  5226. out_freering:
  5227. free_rings(dev);
  5228. out_unmap:
  5229. iounmap(get_hwbase(dev));
  5230. out_relreg:
  5231. pci_release_regions(pci_dev);
  5232. out_disable:
  5233. pci_disable_device(pci_dev);
  5234. out_free:
  5235. free_netdev(dev);
  5236. out:
  5237. return err;
  5238. }
  5239. static void nv_restore_phy(struct net_device *dev)
  5240. {
  5241. struct fe_priv *np = netdev_priv(dev);
  5242. u16 phy_reserved, mii_control;
  5243. if (np->phy_oui == PHY_OUI_REALTEK &&
  5244. np->phy_model == PHY_MODEL_REALTEK_8201 &&
  5245. phy_cross == NV_CROSSOVER_DETECTION_DISABLED) {
  5246. mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3);
  5247. phy_reserved = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, MII_READ);
  5248. phy_reserved &= ~PHY_REALTEK_INIT_MSK1;
  5249. phy_reserved |= PHY_REALTEK_INIT8;
  5250. mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, phy_reserved);
  5251. mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1);
  5252. /* restart auto negotiation */
  5253. mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
  5254. mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
  5255. mii_rw(dev, np->phyaddr, MII_BMCR, mii_control);
  5256. }
  5257. }
  5258. static void nv_restore_mac_addr(struct pci_dev *pci_dev)
  5259. {
  5260. struct net_device *dev = pci_get_drvdata(pci_dev);
  5261. struct fe_priv *np = netdev_priv(dev);
  5262. u8 __iomem *base = get_hwbase(dev);
  5263. /* special op: write back the misordered MAC address - otherwise
  5264. * the next nv_probe would see a wrong address.
  5265. */
  5266. writel(np->orig_mac[0], base + NvRegMacAddrA);
  5267. writel(np->orig_mac[1], base + NvRegMacAddrB);
  5268. writel(readl(base + NvRegTransmitPoll) & ~NVREG_TRANSMITPOLL_MAC_ADDR_REV,
  5269. base + NvRegTransmitPoll);
  5270. }
  5271. static void __devexit nv_remove(struct pci_dev *pci_dev)
  5272. {
  5273. struct net_device *dev = pci_get_drvdata(pci_dev);
  5274. unregister_netdev(dev);
  5275. nv_restore_mac_addr(pci_dev);
  5276. /* restore any phy related changes */
  5277. nv_restore_phy(dev);
  5278. nv_mgmt_release_sema(dev);
  5279. /* free all structures */
  5280. free_rings(dev);
  5281. iounmap(get_hwbase(dev));
  5282. pci_release_regions(pci_dev);
  5283. pci_disable_device(pci_dev);
  5284. free_netdev(dev);
  5285. pci_set_drvdata(pci_dev, NULL);
  5286. }
  5287. #ifdef CONFIG_PM_SLEEP
  5288. static int nv_suspend(struct device *device)
  5289. {
  5290. struct pci_dev *pdev = to_pci_dev(device);
  5291. struct net_device *dev = pci_get_drvdata(pdev);
  5292. struct fe_priv *np = netdev_priv(dev);
  5293. u8 __iomem *base = get_hwbase(dev);
  5294. int i;
  5295. if (netif_running(dev)) {
  5296. /* Gross. */
  5297. nv_close(dev);
  5298. }
  5299. netif_device_detach(dev);
  5300. /* save non-pci configuration space */
  5301. for (i = 0; i <= np->register_size/sizeof(u32); i++)
  5302. np->saved_config_space[i] = readl(base + i*sizeof(u32));
  5303. return 0;
  5304. }
  5305. static int nv_resume(struct device *device)
  5306. {
  5307. struct pci_dev *pdev = to_pci_dev(device);
  5308. struct net_device *dev = pci_get_drvdata(pdev);
  5309. struct fe_priv *np = netdev_priv(dev);
  5310. u8 __iomem *base = get_hwbase(dev);
  5311. int i, rc = 0;
  5312. /* restore non-pci configuration space */
  5313. for (i = 0; i <= np->register_size/sizeof(u32); i++)
  5314. writel(np->saved_config_space[i], base+i*sizeof(u32));
  5315. if (np->driver_data & DEV_NEED_MSI_FIX)
  5316. pci_write_config_dword(pdev, NV_MSI_PRIV_OFFSET, NV_MSI_PRIV_VALUE);
  5317. /* restore phy state, including autoneg */
  5318. phy_init(dev);
  5319. netif_device_attach(dev);
  5320. if (netif_running(dev)) {
  5321. rc = nv_open(dev);
  5322. nv_set_multicast(dev);
  5323. }
  5324. return rc;
  5325. }
  5326. static SIMPLE_DEV_PM_OPS(nv_pm_ops, nv_suspend, nv_resume);
  5327. #define NV_PM_OPS (&nv_pm_ops)
  5328. #else
  5329. #define NV_PM_OPS NULL
  5330. #endif /* CONFIG_PM_SLEEP */
  5331. #ifdef CONFIG_PM
  5332. static void nv_shutdown(struct pci_dev *pdev)
  5333. {
  5334. struct net_device *dev = pci_get_drvdata(pdev);
  5335. struct fe_priv *np = netdev_priv(dev);
  5336. if (netif_running(dev))
  5337. nv_close(dev);
  5338. /*
  5339. * Restore the MAC so a kernel started by kexec won't get confused.
  5340. * If we really go for poweroff, we must not restore the MAC,
  5341. * otherwise the MAC for WOL will be reversed at least on some boards.
  5342. */
  5343. if (system_state != SYSTEM_POWER_OFF)
  5344. nv_restore_mac_addr(pdev);
  5345. pci_disable_device(pdev);
  5346. /*
  5347. * Apparently it is not possible to reinitialise from D3 hot,
  5348. * only put the device into D3 if we really go for poweroff.
  5349. */
  5350. if (system_state == SYSTEM_POWER_OFF) {
  5351. pci_wake_from_d3(pdev, np->wolenabled);
  5352. pci_set_power_state(pdev, PCI_D3hot);
  5353. }
  5354. }
  5355. #else
  5356. #define nv_shutdown NULL
  5357. #endif /* CONFIG_PM */
  5358. static DEFINE_PCI_DEVICE_TABLE(pci_tbl) = {
  5359. { /* nForce Ethernet Controller */
  5360. PCI_DEVICE(0x10DE, 0x01C3),
  5361. .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
  5362. },
  5363. { /* nForce2 Ethernet Controller */
  5364. PCI_DEVICE(0x10DE, 0x0066),
  5365. .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
  5366. },
  5367. { /* nForce3 Ethernet Controller */
  5368. PCI_DEVICE(0x10DE, 0x00D6),
  5369. .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
  5370. },
  5371. { /* nForce3 Ethernet Controller */
  5372. PCI_DEVICE(0x10DE, 0x0086),
  5373. .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
  5374. },
  5375. { /* nForce3 Ethernet Controller */
  5376. PCI_DEVICE(0x10DE, 0x008C),
  5377. .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
  5378. },
  5379. { /* nForce3 Ethernet Controller */
  5380. PCI_DEVICE(0x10DE, 0x00E6),
  5381. .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
  5382. },
  5383. { /* nForce3 Ethernet Controller */
  5384. PCI_DEVICE(0x10DE, 0x00DF),
  5385. .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
  5386. },
  5387. { /* CK804 Ethernet Controller */
  5388. PCI_DEVICE(0x10DE, 0x0056),
  5389. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
  5390. },
  5391. { /* CK804 Ethernet Controller */
  5392. PCI_DEVICE(0x10DE, 0x0057),
  5393. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
  5394. },
  5395. { /* MCP04 Ethernet Controller */
  5396. PCI_DEVICE(0x10DE, 0x0037),
  5397. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
  5398. },
  5399. { /* MCP04 Ethernet Controller */
  5400. PCI_DEVICE(0x10DE, 0x0038),
  5401. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
  5402. },
  5403. { /* MCP51 Ethernet Controller */
  5404. PCI_DEVICE(0x10DE, 0x0268),
  5405. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V1|DEV_NEED_LOW_POWER_FIX,
  5406. },
  5407. { /* MCP51 Ethernet Controller */
  5408. PCI_DEVICE(0x10DE, 0x0269),
  5409. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V1|DEV_NEED_LOW_POWER_FIX,
  5410. },
  5411. { /* MCP55 Ethernet Controller */
  5412. PCI_DEVICE(0x10DE, 0x0372),
  5413. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_NEED_TX_LIMIT|DEV_NEED_MSI_FIX,
  5414. },
  5415. { /* MCP55 Ethernet Controller */
  5416. PCI_DEVICE(0x10DE, 0x0373),
  5417. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_NEED_TX_LIMIT|DEV_NEED_MSI_FIX,
  5418. },
  5419. { /* MCP61 Ethernet Controller */
  5420. PCI_DEVICE(0x10DE, 0x03E5),
  5421. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX,
  5422. },
  5423. { /* MCP61 Ethernet Controller */
  5424. PCI_DEVICE(0x10DE, 0x03E6),
  5425. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX,
  5426. },
  5427. { /* MCP61 Ethernet Controller */
  5428. PCI_DEVICE(0x10DE, 0x03EE),
  5429. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX,
  5430. },
  5431. { /* MCP61 Ethernet Controller */
  5432. PCI_DEVICE(0x10DE, 0x03EF),
  5433. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX,
  5434. },
  5435. { /* MCP65 Ethernet Controller */
  5436. PCI_DEVICE(0x10DE, 0x0450),
  5437. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
  5438. },
  5439. { /* MCP65 Ethernet Controller */
  5440. PCI_DEVICE(0x10DE, 0x0451),
  5441. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
  5442. },
  5443. { /* MCP65 Ethernet Controller */
  5444. PCI_DEVICE(0x10DE, 0x0452),
  5445. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
  5446. },
  5447. { /* MCP65 Ethernet Controller */
  5448. PCI_DEVICE(0x10DE, 0x0453),
  5449. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
  5450. },
  5451. { /* MCP67 Ethernet Controller */
  5452. PCI_DEVICE(0x10DE, 0x054C),
  5453. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
  5454. },
  5455. { /* MCP67 Ethernet Controller */
  5456. PCI_DEVICE(0x10DE, 0x054D),
  5457. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
  5458. },
  5459. { /* MCP67 Ethernet Controller */
  5460. PCI_DEVICE(0x10DE, 0x054E),
  5461. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
  5462. },
  5463. { /* MCP67 Ethernet Controller */
  5464. PCI_DEVICE(0x10DE, 0x054F),
  5465. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
  5466. },
  5467. { /* MCP73 Ethernet Controller */
  5468. PCI_DEVICE(0x10DE, 0x07DC),
  5469. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
  5470. },
  5471. { /* MCP73 Ethernet Controller */
  5472. PCI_DEVICE(0x10DE, 0x07DD),
  5473. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
  5474. },
  5475. { /* MCP73 Ethernet Controller */
  5476. PCI_DEVICE(0x10DE, 0x07DE),
  5477. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
  5478. },
  5479. { /* MCP73 Ethernet Controller */
  5480. PCI_DEVICE(0x10DE, 0x07DF),
  5481. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
  5482. },
  5483. { /* MCP77 Ethernet Controller */
  5484. PCI_DEVICE(0x10DE, 0x0760),
  5485. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
  5486. },
  5487. { /* MCP77 Ethernet Controller */
  5488. PCI_DEVICE(0x10DE, 0x0761),
  5489. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
  5490. },
  5491. { /* MCP77 Ethernet Controller */
  5492. PCI_DEVICE(0x10DE, 0x0762),
  5493. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
  5494. },
  5495. { /* MCP77 Ethernet Controller */
  5496. PCI_DEVICE(0x10DE, 0x0763),
  5497. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
  5498. },
  5499. { /* MCP79 Ethernet Controller */
  5500. PCI_DEVICE(0x10DE, 0x0AB0),
  5501. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
  5502. },
  5503. { /* MCP79 Ethernet Controller */
  5504. PCI_DEVICE(0x10DE, 0x0AB1),
  5505. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
  5506. },
  5507. { /* MCP79 Ethernet Controller */
  5508. PCI_DEVICE(0x10DE, 0x0AB2),
  5509. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
  5510. },
  5511. { /* MCP79 Ethernet Controller */
  5512. PCI_DEVICE(0x10DE, 0x0AB3),
  5513. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
  5514. },
  5515. { /* MCP89 Ethernet Controller */
  5516. PCI_DEVICE(0x10DE, 0x0D7D),
  5517. .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX,
  5518. },
  5519. {0,},
  5520. };
  5521. static struct pci_driver driver = {
  5522. .name = DRV_NAME,
  5523. .id_table = pci_tbl,
  5524. .probe = nv_probe,
  5525. .remove = __devexit_p(nv_remove),
  5526. .shutdown = nv_shutdown,
  5527. .driver.pm = NV_PM_OPS,
  5528. };
  5529. static int __init init_nic(void)
  5530. {
  5531. return pci_register_driver(&driver);
  5532. }
  5533. static void __exit exit_nic(void)
  5534. {
  5535. pci_unregister_driver(&driver);
  5536. }
  5537. module_param(max_interrupt_work, int, 0);
  5538. MODULE_PARM_DESC(max_interrupt_work, "forcedeth maximum events handled per interrupt");
  5539. module_param(optimization_mode, int, 0);
  5540. MODULE_PARM_DESC(optimization_mode, "In throughput mode (0), every tx & rx packet will generate an interrupt. In CPU mode (1), interrupts are controlled by a timer. In dynamic mode (2), the mode toggles between throughput and CPU mode based on network load.");
  5541. module_param(poll_interval, int, 0);
  5542. MODULE_PARM_DESC(poll_interval, "Interval determines how frequent timer interrupt is generated by [(time_in_micro_secs * 100) / (2^10)]. Min is 0 and Max is 65535.");
  5543. module_param(msi, int, 0);
  5544. MODULE_PARM_DESC(msi, "MSI interrupts are enabled by setting to 1 and disabled by setting to 0.");
  5545. module_param(msix, int, 0);
  5546. MODULE_PARM_DESC(msix, "MSIX interrupts are enabled by setting to 1 and disabled by setting to 0.");
  5547. module_param(dma_64bit, int, 0);
  5548. MODULE_PARM_DESC(dma_64bit, "High DMA is enabled by setting to 1 and disabled by setting to 0.");
  5549. module_param(phy_cross, int, 0);
  5550. MODULE_PARM_DESC(phy_cross, "Phy crossover detection for Realtek 8201 phy is enabled by setting to 1 and disabled by setting to 0.");
  5551. module_param(phy_power_down, int, 0);
  5552. MODULE_PARM_DESC(phy_power_down, "Power down phy and disable link when interface is down (1), or leave phy powered up (0).");
  5553. module_param(debug_tx_timeout, bool, 0);
  5554. MODULE_PARM_DESC(debug_tx_timeout,
  5555. "Dump tx related registers and ring when tx_timeout happens");
  5556. MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>");
  5557. MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver");
  5558. MODULE_LICENSE("GPL");
  5559. MODULE_DEVICE_TABLE(pci, pci_tbl);
  5560. module_init(init_nic);
  5561. module_exit(exit_nic);