forcedeth.c 189 KB

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