forcedeth.c 190 KB

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