e1000.c 159 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510
  1. /**************************************************************************
  2. Intel Pro 1000 for ppcboot/das-u-boot
  3. Drivers are port from Intel's Linux driver e1000-4.3.15
  4. and from Etherboot pro 1000 driver by mrakes at vivato dot net
  5. tested on both gig copper and gig fiber boards
  6. ***************************************************************************/
  7. /*******************************************************************************
  8. Copyright(c) 1999 - 2002 Intel Corporation. All rights reserved.
  9. * SPDX-License-Identifier: GPL-2.0+
  10. Contact Information:
  11. Linux NICS <linux.nics@intel.com>
  12. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  13. *******************************************************************************/
  14. /*
  15. * Copyright (C) Archway Digital Solutions.
  16. *
  17. * written by Chrsitopher Li <cli at arcyway dot com> or <chrisl at gnuchina dot org>
  18. * 2/9/2002
  19. *
  20. * Copyright (C) Linux Networx.
  21. * Massive upgrade to work with the new intel gigabit NICs.
  22. * <ebiederman at lnxi dot com>
  23. *
  24. * Copyright 2011 Freescale Semiconductor, Inc.
  25. */
  26. #include "e1000.h"
  27. #define TOUT_LOOP 100000
  28. #define virt_to_bus(devno, v) pci_virt_to_mem(devno, (void *) (v))
  29. #define bus_to_phys(devno, a) pci_mem_to_phys(devno, a)
  30. #define E1000_DEFAULT_PCI_PBA 0x00000030
  31. #define E1000_DEFAULT_PCIE_PBA 0x000a0026
  32. /* NIC specific static variables go here */
  33. /* Intel i210 needs the DMA descriptor rings aligned to 128b */
  34. #define E1000_BUFFER_ALIGN 128
  35. DEFINE_ALIGN_BUFFER(struct e1000_tx_desc, tx_base, 16, E1000_BUFFER_ALIGN);
  36. DEFINE_ALIGN_BUFFER(struct e1000_rx_desc, rx_base, 16, E1000_BUFFER_ALIGN);
  37. DEFINE_ALIGN_BUFFER(unsigned char, packet, 4096, E1000_BUFFER_ALIGN);
  38. static int tx_tail;
  39. static int rx_tail, rx_last;
  40. static struct pci_device_id e1000_supported[] = {
  41. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82542},
  42. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_FIBER},
  43. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82543GC_COPPER},
  44. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_COPPER},
  45. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544EI_FIBER},
  46. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_COPPER},
  47. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82544GC_LOM},
  48. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM},
  49. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_COPPER},
  50. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545GM_COPPER},
  51. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_COPPER},
  52. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82545EM_FIBER},
  53. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546EB_FIBER},
  54. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_COPPER},
  55. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82540EM_LOM},
  56. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541ER},
  57. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82541GI_LF},
  58. /* E1000 PCIe card */
  59. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_COPPER},
  60. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_FIBER },
  61. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES },
  62. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER},
  63. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571PT_QUAD_COPPER},
  64. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_FIBER},
  65. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_QUAD_COPPER_LOWPROFILE},
  66. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_DUAL},
  67. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82571EB_SERDES_QUAD},
  68. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_COPPER},
  69. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_FIBER},
  70. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI_SERDES},
  71. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82572EI},
  72. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E},
  73. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573E_IAMT},
  74. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82573L},
  75. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82574L},
  76. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82546GB_QUAD_COPPER_KSP3},
  77. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_DPT},
  78. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_DPT},
  79. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_COPPER_SPT},
  80. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80003ES2LAN_SERDES_SPT},
  81. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_UNPROGRAMMED},
  82. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I211_UNPROGRAMMED},
  83. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER},
  84. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I211_COPPER},
  85. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS},
  86. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES},
  87. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS},
  88. {PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_I210_1000BASEKX},
  89. {}
  90. };
  91. /* Function forward declarations */
  92. static int e1000_setup_link(struct eth_device *nic);
  93. static int e1000_setup_fiber_link(struct eth_device *nic);
  94. static int e1000_setup_copper_link(struct eth_device *nic);
  95. static int e1000_phy_setup_autoneg(struct e1000_hw *hw);
  96. static void e1000_config_collision_dist(struct e1000_hw *hw);
  97. static int e1000_config_mac_to_phy(struct e1000_hw *hw);
  98. static int e1000_config_fc_after_link_up(struct e1000_hw *hw);
  99. static int e1000_check_for_link(struct eth_device *nic);
  100. static int e1000_wait_autoneg(struct e1000_hw *hw);
  101. static int e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t * speed,
  102. uint16_t * duplex);
  103. static int e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
  104. uint16_t * phy_data);
  105. static int e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr,
  106. uint16_t phy_data);
  107. static int32_t e1000_phy_hw_reset(struct e1000_hw *hw);
  108. static int e1000_phy_reset(struct e1000_hw *hw);
  109. static int e1000_detect_gig_phy(struct e1000_hw *hw);
  110. static void e1000_set_media_type(struct e1000_hw *hw);
  111. static int32_t e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask);
  112. static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask);
  113. static int32_t e1000_check_phy_reset_block(struct e1000_hw *hw);
  114. #ifndef CONFIG_E1000_NO_NVM
  115. static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
  116. static int32_t e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
  117. uint16_t words,
  118. uint16_t *data);
  119. /******************************************************************************
  120. * Raises the EEPROM's clock input.
  121. *
  122. * hw - Struct containing variables accessed by shared code
  123. * eecd - EECD's current value
  124. *****************************************************************************/
  125. void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
  126. {
  127. /* Raise the clock input to the EEPROM (by setting the SK bit), and then
  128. * wait 50 microseconds.
  129. */
  130. *eecd = *eecd | E1000_EECD_SK;
  131. E1000_WRITE_REG(hw, EECD, *eecd);
  132. E1000_WRITE_FLUSH(hw);
  133. udelay(50);
  134. }
  135. /******************************************************************************
  136. * Lowers the EEPROM's clock input.
  137. *
  138. * hw - Struct containing variables accessed by shared code
  139. * eecd - EECD's current value
  140. *****************************************************************************/
  141. void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t * eecd)
  142. {
  143. /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
  144. * wait 50 microseconds.
  145. */
  146. *eecd = *eecd & ~E1000_EECD_SK;
  147. E1000_WRITE_REG(hw, EECD, *eecd);
  148. E1000_WRITE_FLUSH(hw);
  149. udelay(50);
  150. }
  151. /******************************************************************************
  152. * Shift data bits out to the EEPROM.
  153. *
  154. * hw - Struct containing variables accessed by shared code
  155. * data - data to send to the EEPROM
  156. * count - number of bits to shift out
  157. *****************************************************************************/
  158. static void
  159. e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data, uint16_t count)
  160. {
  161. uint32_t eecd;
  162. uint32_t mask;
  163. /* We need to shift "count" bits out to the EEPROM. So, value in the
  164. * "data" parameter will be shifted out to the EEPROM one bit at a time.
  165. * In order to do this, "data" must be broken down into bits.
  166. */
  167. mask = 0x01 << (count - 1);
  168. eecd = E1000_READ_REG(hw, EECD);
  169. eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
  170. do {
  171. /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
  172. * and then raising and then lowering the clock (the SK bit controls
  173. * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
  174. * by setting "DI" to "0" and then raising and then lowering the clock.
  175. */
  176. eecd &= ~E1000_EECD_DI;
  177. if (data & mask)
  178. eecd |= E1000_EECD_DI;
  179. E1000_WRITE_REG(hw, EECD, eecd);
  180. E1000_WRITE_FLUSH(hw);
  181. udelay(50);
  182. e1000_raise_ee_clk(hw, &eecd);
  183. e1000_lower_ee_clk(hw, &eecd);
  184. mask = mask >> 1;
  185. } while (mask);
  186. /* We leave the "DI" bit set to "0" when we leave this routine. */
  187. eecd &= ~E1000_EECD_DI;
  188. E1000_WRITE_REG(hw, EECD, eecd);
  189. }
  190. /******************************************************************************
  191. * Shift data bits in from the EEPROM
  192. *
  193. * hw - Struct containing variables accessed by shared code
  194. *****************************************************************************/
  195. static uint16_t
  196. e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count)
  197. {
  198. uint32_t eecd;
  199. uint32_t i;
  200. uint16_t data;
  201. /* In order to read a register from the EEPROM, we need to shift 'count'
  202. * bits in from the EEPROM. Bits are "shifted in" by raising the clock
  203. * input to the EEPROM (setting the SK bit), and then reading the
  204. * value of the "DO" bit. During this "shifting in" process the
  205. * "DI" bit should always be clear.
  206. */
  207. eecd = E1000_READ_REG(hw, EECD);
  208. eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
  209. data = 0;
  210. for (i = 0; i < count; i++) {
  211. data = data << 1;
  212. e1000_raise_ee_clk(hw, &eecd);
  213. eecd = E1000_READ_REG(hw, EECD);
  214. eecd &= ~(E1000_EECD_DI);
  215. if (eecd & E1000_EECD_DO)
  216. data |= 1;
  217. e1000_lower_ee_clk(hw, &eecd);
  218. }
  219. return data;
  220. }
  221. /******************************************************************************
  222. * Returns EEPROM to a "standby" state
  223. *
  224. * hw - Struct containing variables accessed by shared code
  225. *****************************************************************************/
  226. void e1000_standby_eeprom(struct e1000_hw *hw)
  227. {
  228. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  229. uint32_t eecd;
  230. eecd = E1000_READ_REG(hw, EECD);
  231. if (eeprom->type == e1000_eeprom_microwire) {
  232. eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
  233. E1000_WRITE_REG(hw, EECD, eecd);
  234. E1000_WRITE_FLUSH(hw);
  235. udelay(eeprom->delay_usec);
  236. /* Clock high */
  237. eecd |= E1000_EECD_SK;
  238. E1000_WRITE_REG(hw, EECD, eecd);
  239. E1000_WRITE_FLUSH(hw);
  240. udelay(eeprom->delay_usec);
  241. /* Select EEPROM */
  242. eecd |= E1000_EECD_CS;
  243. E1000_WRITE_REG(hw, EECD, eecd);
  244. E1000_WRITE_FLUSH(hw);
  245. udelay(eeprom->delay_usec);
  246. /* Clock low */
  247. eecd &= ~E1000_EECD_SK;
  248. E1000_WRITE_REG(hw, EECD, eecd);
  249. E1000_WRITE_FLUSH(hw);
  250. udelay(eeprom->delay_usec);
  251. } else if (eeprom->type == e1000_eeprom_spi) {
  252. /* Toggle CS to flush commands */
  253. eecd |= E1000_EECD_CS;
  254. E1000_WRITE_REG(hw, EECD, eecd);
  255. E1000_WRITE_FLUSH(hw);
  256. udelay(eeprom->delay_usec);
  257. eecd &= ~E1000_EECD_CS;
  258. E1000_WRITE_REG(hw, EECD, eecd);
  259. E1000_WRITE_FLUSH(hw);
  260. udelay(eeprom->delay_usec);
  261. }
  262. }
  263. /***************************************************************************
  264. * Description: Determines if the onboard NVM is FLASH or EEPROM.
  265. *
  266. * hw - Struct containing variables accessed by shared code
  267. ****************************************************************************/
  268. static bool e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
  269. {
  270. uint32_t eecd = 0;
  271. DEBUGFUNC();
  272. if (hw->mac_type == e1000_ich8lan)
  273. return false;
  274. if (hw->mac_type == e1000_82573 || hw->mac_type == e1000_82574) {
  275. eecd = E1000_READ_REG(hw, EECD);
  276. /* Isolate bits 15 & 16 */
  277. eecd = ((eecd >> 15) & 0x03);
  278. /* If both bits are set, device is Flash type */
  279. if (eecd == 0x03)
  280. return false;
  281. }
  282. return true;
  283. }
  284. /******************************************************************************
  285. * Prepares EEPROM for access
  286. *
  287. * hw - Struct containing variables accessed by shared code
  288. *
  289. * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
  290. * function should be called before issuing a command to the EEPROM.
  291. *****************************************************************************/
  292. int32_t e1000_acquire_eeprom(struct e1000_hw *hw)
  293. {
  294. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  295. uint32_t eecd, i = 0;
  296. DEBUGFUNC();
  297. if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
  298. return -E1000_ERR_SWFW_SYNC;
  299. eecd = E1000_READ_REG(hw, EECD);
  300. if (hw->mac_type != e1000_82573 && hw->mac_type != e1000_82574) {
  301. /* Request EEPROM Access */
  302. if (hw->mac_type > e1000_82544) {
  303. eecd |= E1000_EECD_REQ;
  304. E1000_WRITE_REG(hw, EECD, eecd);
  305. eecd = E1000_READ_REG(hw, EECD);
  306. while ((!(eecd & E1000_EECD_GNT)) &&
  307. (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
  308. i++;
  309. udelay(5);
  310. eecd = E1000_READ_REG(hw, EECD);
  311. }
  312. if (!(eecd & E1000_EECD_GNT)) {
  313. eecd &= ~E1000_EECD_REQ;
  314. E1000_WRITE_REG(hw, EECD, eecd);
  315. DEBUGOUT("Could not acquire EEPROM grant\n");
  316. return -E1000_ERR_EEPROM;
  317. }
  318. }
  319. }
  320. /* Setup EEPROM for Read/Write */
  321. if (eeprom->type == e1000_eeprom_microwire) {
  322. /* Clear SK and DI */
  323. eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
  324. E1000_WRITE_REG(hw, EECD, eecd);
  325. /* Set CS */
  326. eecd |= E1000_EECD_CS;
  327. E1000_WRITE_REG(hw, EECD, eecd);
  328. } else if (eeprom->type == e1000_eeprom_spi) {
  329. /* Clear SK and CS */
  330. eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
  331. E1000_WRITE_REG(hw, EECD, eecd);
  332. udelay(1);
  333. }
  334. return E1000_SUCCESS;
  335. }
  336. /******************************************************************************
  337. * Sets up eeprom variables in the hw struct. Must be called after mac_type
  338. * is configured. Additionally, if this is ICH8, the flash controller GbE
  339. * registers must be mapped, or this will crash.
  340. *
  341. * hw - Struct containing variables accessed by shared code
  342. *****************************************************************************/
  343. static int32_t e1000_init_eeprom_params(struct e1000_hw *hw)
  344. {
  345. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  346. uint32_t eecd;
  347. int32_t ret_val = E1000_SUCCESS;
  348. uint16_t eeprom_size;
  349. if (hw->mac_type == e1000_igb)
  350. eecd = E1000_READ_REG(hw, I210_EECD);
  351. else
  352. eecd = E1000_READ_REG(hw, EECD);
  353. DEBUGFUNC();
  354. switch (hw->mac_type) {
  355. case e1000_82542_rev2_0:
  356. case e1000_82542_rev2_1:
  357. case e1000_82543:
  358. case e1000_82544:
  359. eeprom->type = e1000_eeprom_microwire;
  360. eeprom->word_size = 64;
  361. eeprom->opcode_bits = 3;
  362. eeprom->address_bits = 6;
  363. eeprom->delay_usec = 50;
  364. eeprom->use_eerd = false;
  365. eeprom->use_eewr = false;
  366. break;
  367. case e1000_82540:
  368. case e1000_82545:
  369. case e1000_82545_rev_3:
  370. case e1000_82546:
  371. case e1000_82546_rev_3:
  372. eeprom->type = e1000_eeprom_microwire;
  373. eeprom->opcode_bits = 3;
  374. eeprom->delay_usec = 50;
  375. if (eecd & E1000_EECD_SIZE) {
  376. eeprom->word_size = 256;
  377. eeprom->address_bits = 8;
  378. } else {
  379. eeprom->word_size = 64;
  380. eeprom->address_bits = 6;
  381. }
  382. eeprom->use_eerd = false;
  383. eeprom->use_eewr = false;
  384. break;
  385. case e1000_82541:
  386. case e1000_82541_rev_2:
  387. case e1000_82547:
  388. case e1000_82547_rev_2:
  389. if (eecd & E1000_EECD_TYPE) {
  390. eeprom->type = e1000_eeprom_spi;
  391. eeprom->opcode_bits = 8;
  392. eeprom->delay_usec = 1;
  393. if (eecd & E1000_EECD_ADDR_BITS) {
  394. eeprom->page_size = 32;
  395. eeprom->address_bits = 16;
  396. } else {
  397. eeprom->page_size = 8;
  398. eeprom->address_bits = 8;
  399. }
  400. } else {
  401. eeprom->type = e1000_eeprom_microwire;
  402. eeprom->opcode_bits = 3;
  403. eeprom->delay_usec = 50;
  404. if (eecd & E1000_EECD_ADDR_BITS) {
  405. eeprom->word_size = 256;
  406. eeprom->address_bits = 8;
  407. } else {
  408. eeprom->word_size = 64;
  409. eeprom->address_bits = 6;
  410. }
  411. }
  412. eeprom->use_eerd = false;
  413. eeprom->use_eewr = false;
  414. break;
  415. case e1000_82571:
  416. case e1000_82572:
  417. eeprom->type = e1000_eeprom_spi;
  418. eeprom->opcode_bits = 8;
  419. eeprom->delay_usec = 1;
  420. if (eecd & E1000_EECD_ADDR_BITS) {
  421. eeprom->page_size = 32;
  422. eeprom->address_bits = 16;
  423. } else {
  424. eeprom->page_size = 8;
  425. eeprom->address_bits = 8;
  426. }
  427. eeprom->use_eerd = false;
  428. eeprom->use_eewr = false;
  429. break;
  430. case e1000_82573:
  431. case e1000_82574:
  432. eeprom->type = e1000_eeprom_spi;
  433. eeprom->opcode_bits = 8;
  434. eeprom->delay_usec = 1;
  435. if (eecd & E1000_EECD_ADDR_BITS) {
  436. eeprom->page_size = 32;
  437. eeprom->address_bits = 16;
  438. } else {
  439. eeprom->page_size = 8;
  440. eeprom->address_bits = 8;
  441. }
  442. if (e1000_is_onboard_nvm_eeprom(hw) == false) {
  443. eeprom->use_eerd = true;
  444. eeprom->use_eewr = true;
  445. eeprom->type = e1000_eeprom_flash;
  446. eeprom->word_size = 2048;
  447. /* Ensure that the Autonomous FLASH update bit is cleared due to
  448. * Flash update issue on parts which use a FLASH for NVM. */
  449. eecd &= ~E1000_EECD_AUPDEN;
  450. E1000_WRITE_REG(hw, EECD, eecd);
  451. }
  452. break;
  453. case e1000_80003es2lan:
  454. eeprom->type = e1000_eeprom_spi;
  455. eeprom->opcode_bits = 8;
  456. eeprom->delay_usec = 1;
  457. if (eecd & E1000_EECD_ADDR_BITS) {
  458. eeprom->page_size = 32;
  459. eeprom->address_bits = 16;
  460. } else {
  461. eeprom->page_size = 8;
  462. eeprom->address_bits = 8;
  463. }
  464. eeprom->use_eerd = true;
  465. eeprom->use_eewr = false;
  466. break;
  467. case e1000_igb:
  468. /* i210 has 4k of iNVM mapped as EEPROM */
  469. eeprom->type = e1000_eeprom_invm;
  470. eeprom->opcode_bits = 8;
  471. eeprom->delay_usec = 1;
  472. eeprom->page_size = 32;
  473. eeprom->address_bits = 16;
  474. eeprom->use_eerd = true;
  475. eeprom->use_eewr = false;
  476. break;
  477. /* ich8lan does not support currently. if needed, please
  478. * add corresponding code and functions.
  479. */
  480. #if 0
  481. case e1000_ich8lan:
  482. {
  483. int32_t i = 0;
  484. eeprom->type = e1000_eeprom_ich8;
  485. eeprom->use_eerd = false;
  486. eeprom->use_eewr = false;
  487. eeprom->word_size = E1000_SHADOW_RAM_WORDS;
  488. uint32_t flash_size = E1000_READ_ICH_FLASH_REG(hw,
  489. ICH_FLASH_GFPREG);
  490. /* Zero the shadow RAM structure. But don't load it from NVM
  491. * so as to save time for driver init */
  492. if (hw->eeprom_shadow_ram != NULL) {
  493. for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
  494. hw->eeprom_shadow_ram[i].modified = false;
  495. hw->eeprom_shadow_ram[i].eeprom_word = 0xFFFF;
  496. }
  497. }
  498. hw->flash_base_addr = (flash_size & ICH_GFPREG_BASE_MASK) *
  499. ICH_FLASH_SECTOR_SIZE;
  500. hw->flash_bank_size = ((flash_size >> 16)
  501. & ICH_GFPREG_BASE_MASK) + 1;
  502. hw->flash_bank_size -= (flash_size & ICH_GFPREG_BASE_MASK);
  503. hw->flash_bank_size *= ICH_FLASH_SECTOR_SIZE;
  504. hw->flash_bank_size /= 2 * sizeof(uint16_t);
  505. break;
  506. }
  507. #endif
  508. default:
  509. break;
  510. }
  511. if (eeprom->type == e1000_eeprom_spi ||
  512. eeprom->type == e1000_eeprom_invm) {
  513. /* eeprom_size will be an enum [0..8] that maps
  514. * to eeprom sizes 128B to
  515. * 32KB (incremented by powers of 2).
  516. */
  517. if (hw->mac_type <= e1000_82547_rev_2) {
  518. /* Set to default value for initial eeprom read. */
  519. eeprom->word_size = 64;
  520. ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1,
  521. &eeprom_size);
  522. if (ret_val)
  523. return ret_val;
  524. eeprom_size = (eeprom_size & EEPROM_SIZE_MASK)
  525. >> EEPROM_SIZE_SHIFT;
  526. /* 256B eeprom size was not supported in earlier
  527. * hardware, so we bump eeprom_size up one to
  528. * ensure that "1" (which maps to 256B) is never
  529. * the result used in the shifting logic below. */
  530. if (eeprom_size)
  531. eeprom_size++;
  532. } else {
  533. eeprom_size = (uint16_t)((eecd &
  534. E1000_EECD_SIZE_EX_MASK) >>
  535. E1000_EECD_SIZE_EX_SHIFT);
  536. }
  537. eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
  538. }
  539. return ret_val;
  540. }
  541. /******************************************************************************
  542. * Polls the status bit (bit 1) of the EERD to determine when the read is done.
  543. *
  544. * hw - Struct containing variables accessed by shared code
  545. *****************************************************************************/
  546. static int32_t
  547. e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
  548. {
  549. uint32_t attempts = 100000;
  550. uint32_t i, reg = 0;
  551. int32_t done = E1000_ERR_EEPROM;
  552. for (i = 0; i < attempts; i++) {
  553. if (eerd == E1000_EEPROM_POLL_READ) {
  554. if (hw->mac_type == e1000_igb)
  555. reg = E1000_READ_REG(hw, I210_EERD);
  556. else
  557. reg = E1000_READ_REG(hw, EERD);
  558. } else {
  559. if (hw->mac_type == e1000_igb)
  560. reg = E1000_READ_REG(hw, I210_EEWR);
  561. else
  562. reg = E1000_READ_REG(hw, EEWR);
  563. }
  564. if (reg & E1000_EEPROM_RW_REG_DONE) {
  565. done = E1000_SUCCESS;
  566. break;
  567. }
  568. udelay(5);
  569. }
  570. return done;
  571. }
  572. /******************************************************************************
  573. * Reads a 16 bit word from the EEPROM using the EERD register.
  574. *
  575. * hw - Struct containing variables accessed by shared code
  576. * offset - offset of word in the EEPROM to read
  577. * data - word read from the EEPROM
  578. * words - number of words to read
  579. *****************************************************************************/
  580. static int32_t
  581. e1000_read_eeprom_eerd(struct e1000_hw *hw,
  582. uint16_t offset,
  583. uint16_t words,
  584. uint16_t *data)
  585. {
  586. uint32_t i, eerd = 0;
  587. int32_t error = 0;
  588. for (i = 0; i < words; i++) {
  589. eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
  590. E1000_EEPROM_RW_REG_START;
  591. if (hw->mac_type == e1000_igb)
  592. E1000_WRITE_REG(hw, I210_EERD, eerd);
  593. else
  594. E1000_WRITE_REG(hw, EERD, eerd);
  595. error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
  596. if (error)
  597. break;
  598. if (hw->mac_type == e1000_igb) {
  599. data[i] = (E1000_READ_REG(hw, I210_EERD) >>
  600. E1000_EEPROM_RW_REG_DATA);
  601. } else {
  602. data[i] = (E1000_READ_REG(hw, EERD) >>
  603. E1000_EEPROM_RW_REG_DATA);
  604. }
  605. }
  606. return error;
  607. }
  608. void e1000_release_eeprom(struct e1000_hw *hw)
  609. {
  610. uint32_t eecd;
  611. DEBUGFUNC();
  612. eecd = E1000_READ_REG(hw, EECD);
  613. if (hw->eeprom.type == e1000_eeprom_spi) {
  614. eecd |= E1000_EECD_CS; /* Pull CS high */
  615. eecd &= ~E1000_EECD_SK; /* Lower SCK */
  616. E1000_WRITE_REG(hw, EECD, eecd);
  617. udelay(hw->eeprom.delay_usec);
  618. } else if (hw->eeprom.type == e1000_eeprom_microwire) {
  619. /* cleanup eeprom */
  620. /* CS on Microwire is active-high */
  621. eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
  622. E1000_WRITE_REG(hw, EECD, eecd);
  623. /* Rising edge of clock */
  624. eecd |= E1000_EECD_SK;
  625. E1000_WRITE_REG(hw, EECD, eecd);
  626. E1000_WRITE_FLUSH(hw);
  627. udelay(hw->eeprom.delay_usec);
  628. /* Falling edge of clock */
  629. eecd &= ~E1000_EECD_SK;
  630. E1000_WRITE_REG(hw, EECD, eecd);
  631. E1000_WRITE_FLUSH(hw);
  632. udelay(hw->eeprom.delay_usec);
  633. }
  634. /* Stop requesting EEPROM access */
  635. if (hw->mac_type > e1000_82544) {
  636. eecd &= ~E1000_EECD_REQ;
  637. E1000_WRITE_REG(hw, EECD, eecd);
  638. }
  639. e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
  640. }
  641. /******************************************************************************
  642. * Reads a 16 bit word from the EEPROM.
  643. *
  644. * hw - Struct containing variables accessed by shared code
  645. *****************************************************************************/
  646. static int32_t
  647. e1000_spi_eeprom_ready(struct e1000_hw *hw)
  648. {
  649. uint16_t retry_count = 0;
  650. uint8_t spi_stat_reg;
  651. DEBUGFUNC();
  652. /* Read "Status Register" repeatedly until the LSB is cleared. The
  653. * EEPROM will signal that the command has been completed by clearing
  654. * bit 0 of the internal status register. If it's not cleared within
  655. * 5 milliseconds, then error out.
  656. */
  657. retry_count = 0;
  658. do {
  659. e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
  660. hw->eeprom.opcode_bits);
  661. spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
  662. if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
  663. break;
  664. udelay(5);
  665. retry_count += 5;
  666. e1000_standby_eeprom(hw);
  667. } while (retry_count < EEPROM_MAX_RETRY_SPI);
  668. /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
  669. * only 0-5mSec on 5V devices)
  670. */
  671. if (retry_count >= EEPROM_MAX_RETRY_SPI) {
  672. DEBUGOUT("SPI EEPROM Status error\n");
  673. return -E1000_ERR_EEPROM;
  674. }
  675. return E1000_SUCCESS;
  676. }
  677. /******************************************************************************
  678. * Reads a 16 bit word from the EEPROM.
  679. *
  680. * hw - Struct containing variables accessed by shared code
  681. * offset - offset of word in the EEPROM to read
  682. * data - word read from the EEPROM
  683. *****************************************************************************/
  684. static int32_t
  685. e1000_read_eeprom(struct e1000_hw *hw, uint16_t offset,
  686. uint16_t words, uint16_t *data)
  687. {
  688. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  689. uint32_t i = 0;
  690. DEBUGFUNC();
  691. /* If eeprom is not yet detected, do so now */
  692. if (eeprom->word_size == 0)
  693. e1000_init_eeprom_params(hw);
  694. /* A check for invalid values: offset too large, too many words,
  695. * and not enough words.
  696. */
  697. if ((offset >= eeprom->word_size) ||
  698. (words > eeprom->word_size - offset) ||
  699. (words == 0)) {
  700. DEBUGOUT("\"words\" parameter out of bounds."
  701. "Words = %d, size = %d\n", offset, eeprom->word_size);
  702. return -E1000_ERR_EEPROM;
  703. }
  704. /* EEPROM's that don't use EERD to read require us to bit-bang the SPI
  705. * directly. In this case, we need to acquire the EEPROM so that
  706. * FW or other port software does not interrupt.
  707. */
  708. if (e1000_is_onboard_nvm_eeprom(hw) == true &&
  709. hw->eeprom.use_eerd == false) {
  710. /* Prepare the EEPROM for bit-bang reading */
  711. if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
  712. return -E1000_ERR_EEPROM;
  713. }
  714. /* Eerd register EEPROM access requires no eeprom aquire/release */
  715. if (eeprom->use_eerd == true)
  716. return e1000_read_eeprom_eerd(hw, offset, words, data);
  717. /* ich8lan does not support currently. if needed, please
  718. * add corresponding code and functions.
  719. */
  720. #if 0
  721. /* ICH EEPROM access is done via the ICH flash controller */
  722. if (eeprom->type == e1000_eeprom_ich8)
  723. return e1000_read_eeprom_ich8(hw, offset, words, data);
  724. #endif
  725. /* Set up the SPI or Microwire EEPROM for bit-bang reading. We have
  726. * acquired the EEPROM at this point, so any returns should relase it */
  727. if (eeprom->type == e1000_eeprom_spi) {
  728. uint16_t word_in;
  729. uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
  730. if (e1000_spi_eeprom_ready(hw)) {
  731. e1000_release_eeprom(hw);
  732. return -E1000_ERR_EEPROM;
  733. }
  734. e1000_standby_eeprom(hw);
  735. /* Some SPI eeproms use the 8th address bit embedded in
  736. * the opcode */
  737. if ((eeprom->address_bits == 8) && (offset >= 128))
  738. read_opcode |= EEPROM_A8_OPCODE_SPI;
  739. /* Send the READ command (opcode + addr) */
  740. e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
  741. e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2),
  742. eeprom->address_bits);
  743. /* Read the data. The address of the eeprom internally
  744. * increments with each byte (spi) being read, saving on the
  745. * overhead of eeprom setup and tear-down. The address
  746. * counter will roll over if reading beyond the size of
  747. * the eeprom, thus allowing the entire memory to be read
  748. * starting from any offset. */
  749. for (i = 0; i < words; i++) {
  750. word_in = e1000_shift_in_ee_bits(hw, 16);
  751. data[i] = (word_in >> 8) | (word_in << 8);
  752. }
  753. } else if (eeprom->type == e1000_eeprom_microwire) {
  754. for (i = 0; i < words; i++) {
  755. /* Send the READ command (opcode + addr) */
  756. e1000_shift_out_ee_bits(hw,
  757. EEPROM_READ_OPCODE_MICROWIRE,
  758. eeprom->opcode_bits);
  759. e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
  760. eeprom->address_bits);
  761. /* Read the data. For microwire, each word requires
  762. * the overhead of eeprom setup and tear-down. */
  763. data[i] = e1000_shift_in_ee_bits(hw, 16);
  764. e1000_standby_eeprom(hw);
  765. }
  766. }
  767. /* End this read operation */
  768. e1000_release_eeprom(hw);
  769. return E1000_SUCCESS;
  770. }
  771. /******************************************************************************
  772. * Verifies that the EEPROM has a valid checksum
  773. *
  774. * hw - Struct containing variables accessed by shared code
  775. *
  776. * Reads the first 64 16 bit words of the EEPROM and sums the values read.
  777. * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
  778. * valid.
  779. *****************************************************************************/
  780. static int e1000_validate_eeprom_checksum(struct e1000_hw *hw)
  781. {
  782. uint16_t i, checksum, checksum_reg, *buf;
  783. DEBUGFUNC();
  784. /* Allocate a temporary buffer */
  785. buf = malloc(sizeof(buf[0]) * (EEPROM_CHECKSUM_REG + 1));
  786. if (!buf) {
  787. E1000_ERR(hw->nic, "Unable to allocate EEPROM buffer!\n");
  788. return -E1000_ERR_EEPROM;
  789. }
  790. /* Read the EEPROM */
  791. if (e1000_read_eeprom(hw, 0, EEPROM_CHECKSUM_REG + 1, buf) < 0) {
  792. E1000_ERR(hw->nic, "Unable to read EEPROM!\n");
  793. return -E1000_ERR_EEPROM;
  794. }
  795. /* Compute the checksum */
  796. checksum = 0;
  797. for (i = 0; i < EEPROM_CHECKSUM_REG; i++)
  798. checksum += buf[i];
  799. checksum = ((uint16_t)EEPROM_SUM) - checksum;
  800. checksum_reg = buf[i];
  801. /* Verify it! */
  802. if (checksum == checksum_reg)
  803. return 0;
  804. /* Hrm, verification failed, print an error */
  805. E1000_ERR(hw->nic, "EEPROM checksum is incorrect!\n");
  806. E1000_ERR(hw->nic, " ...register was 0x%04hx, calculated 0x%04hx\n",
  807. checksum_reg, checksum);
  808. return -E1000_ERR_EEPROM;
  809. }
  810. #endif /* CONFIG_E1000_NO_NVM */
  811. /*****************************************************************************
  812. * Set PHY to class A mode
  813. * Assumes the following operations will follow to enable the new class mode.
  814. * 1. Do a PHY soft reset
  815. * 2. Restart auto-negotiation or force link.
  816. *
  817. * hw - Struct containing variables accessed by shared code
  818. ****************************************************************************/
  819. static int32_t
  820. e1000_set_phy_mode(struct e1000_hw *hw)
  821. {
  822. #ifndef CONFIG_E1000_NO_NVM
  823. int32_t ret_val;
  824. uint16_t eeprom_data;
  825. DEBUGFUNC();
  826. if ((hw->mac_type == e1000_82545_rev_3) &&
  827. (hw->media_type == e1000_media_type_copper)) {
  828. ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD,
  829. 1, &eeprom_data);
  830. if (ret_val)
  831. return ret_val;
  832. if ((eeprom_data != EEPROM_RESERVED_WORD) &&
  833. (eeprom_data & EEPROM_PHY_CLASS_A)) {
  834. ret_val = e1000_write_phy_reg(hw,
  835. M88E1000_PHY_PAGE_SELECT, 0x000B);
  836. if (ret_val)
  837. return ret_val;
  838. ret_val = e1000_write_phy_reg(hw,
  839. M88E1000_PHY_GEN_CONTROL, 0x8104);
  840. if (ret_val)
  841. return ret_val;
  842. hw->phy_reset_disable = false;
  843. }
  844. }
  845. #endif
  846. return E1000_SUCCESS;
  847. }
  848. #ifndef CONFIG_E1000_NO_NVM
  849. /***************************************************************************
  850. *
  851. * Obtaining software semaphore bit (SMBI) before resetting PHY.
  852. *
  853. * hw: Struct containing variables accessed by shared code
  854. *
  855. * returns: - E1000_ERR_RESET if fail to obtain semaphore.
  856. * E1000_SUCCESS at any other case.
  857. *
  858. ***************************************************************************/
  859. static int32_t
  860. e1000_get_software_semaphore(struct e1000_hw *hw)
  861. {
  862. int32_t timeout = hw->eeprom.word_size + 1;
  863. uint32_t swsm;
  864. DEBUGFUNC();
  865. swsm = E1000_READ_REG(hw, SWSM);
  866. swsm &= ~E1000_SWSM_SMBI;
  867. E1000_WRITE_REG(hw, SWSM, swsm);
  868. if (hw->mac_type != e1000_80003es2lan)
  869. return E1000_SUCCESS;
  870. while (timeout) {
  871. swsm = E1000_READ_REG(hw, SWSM);
  872. /* If SMBI bit cleared, it is now set and we hold
  873. * the semaphore */
  874. if (!(swsm & E1000_SWSM_SMBI))
  875. break;
  876. mdelay(1);
  877. timeout--;
  878. }
  879. if (!timeout) {
  880. DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
  881. return -E1000_ERR_RESET;
  882. }
  883. return E1000_SUCCESS;
  884. }
  885. #endif
  886. /***************************************************************************
  887. * This function clears HW semaphore bits.
  888. *
  889. * hw: Struct containing variables accessed by shared code
  890. *
  891. * returns: - None.
  892. *
  893. ***************************************************************************/
  894. static void
  895. e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
  896. {
  897. #ifndef CONFIG_E1000_NO_NVM
  898. uint32_t swsm;
  899. DEBUGFUNC();
  900. if (!hw->eeprom_semaphore_present)
  901. return;
  902. swsm = E1000_READ_REG(hw, SWSM);
  903. if (hw->mac_type == e1000_80003es2lan) {
  904. /* Release both semaphores. */
  905. swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
  906. } else
  907. swsm &= ~(E1000_SWSM_SWESMBI);
  908. E1000_WRITE_REG(hw, SWSM, swsm);
  909. #endif
  910. }
  911. /***************************************************************************
  912. *
  913. * Using the combination of SMBI and SWESMBI semaphore bits when resetting
  914. * adapter or Eeprom access.
  915. *
  916. * hw: Struct containing variables accessed by shared code
  917. *
  918. * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
  919. * E1000_SUCCESS at any other case.
  920. *
  921. ***************************************************************************/
  922. static int32_t
  923. e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
  924. {
  925. #ifndef CONFIG_E1000_NO_NVM
  926. int32_t timeout;
  927. uint32_t swsm;
  928. DEBUGFUNC();
  929. if (!hw->eeprom_semaphore_present)
  930. return E1000_SUCCESS;
  931. if (hw->mac_type == e1000_80003es2lan) {
  932. /* Get the SW semaphore. */
  933. if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
  934. return -E1000_ERR_EEPROM;
  935. }
  936. /* Get the FW semaphore. */
  937. timeout = hw->eeprom.word_size + 1;
  938. while (timeout) {
  939. swsm = E1000_READ_REG(hw, SWSM);
  940. swsm |= E1000_SWSM_SWESMBI;
  941. E1000_WRITE_REG(hw, SWSM, swsm);
  942. /* if we managed to set the bit we got the semaphore. */
  943. swsm = E1000_READ_REG(hw, SWSM);
  944. if (swsm & E1000_SWSM_SWESMBI)
  945. break;
  946. udelay(50);
  947. timeout--;
  948. }
  949. if (!timeout) {
  950. /* Release semaphores */
  951. e1000_put_hw_eeprom_semaphore(hw);
  952. DEBUGOUT("Driver can't access the Eeprom - "
  953. "SWESMBI bit is set.\n");
  954. return -E1000_ERR_EEPROM;
  955. }
  956. #endif
  957. return E1000_SUCCESS;
  958. }
  959. /* Take ownership of the PHY */
  960. static int32_t
  961. e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
  962. {
  963. uint32_t swfw_sync = 0;
  964. uint32_t swmask = mask;
  965. uint32_t fwmask = mask << 16;
  966. int32_t timeout = 200;
  967. DEBUGFUNC();
  968. while (timeout) {
  969. if (e1000_get_hw_eeprom_semaphore(hw))
  970. return -E1000_ERR_SWFW_SYNC;
  971. if (hw->mac_type == e1000_igb)
  972. swfw_sync = E1000_READ_REG(hw, I210_SW_FW_SYNC);
  973. else
  974. swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
  975. if (!(swfw_sync & (fwmask | swmask)))
  976. break;
  977. /* firmware currently using resource (fwmask) */
  978. /* or other software thread currently using resource (swmask) */
  979. e1000_put_hw_eeprom_semaphore(hw);
  980. mdelay(5);
  981. timeout--;
  982. }
  983. if (!timeout) {
  984. DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
  985. return -E1000_ERR_SWFW_SYNC;
  986. }
  987. swfw_sync |= swmask;
  988. E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
  989. e1000_put_hw_eeprom_semaphore(hw);
  990. return E1000_SUCCESS;
  991. }
  992. static void e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
  993. {
  994. uint32_t swfw_sync = 0;
  995. DEBUGFUNC();
  996. while (e1000_get_hw_eeprom_semaphore(hw))
  997. ; /* Empty */
  998. swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
  999. swfw_sync &= ~mask;
  1000. E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
  1001. e1000_put_hw_eeprom_semaphore(hw);
  1002. }
  1003. static bool e1000_is_second_port(struct e1000_hw *hw)
  1004. {
  1005. switch (hw->mac_type) {
  1006. case e1000_80003es2lan:
  1007. case e1000_82546:
  1008. case e1000_82571:
  1009. if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
  1010. return true;
  1011. /* Fallthrough */
  1012. default:
  1013. return false;
  1014. }
  1015. }
  1016. #ifndef CONFIG_E1000_NO_NVM
  1017. /******************************************************************************
  1018. * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
  1019. * second function of dual function devices
  1020. *
  1021. * nic - Struct containing variables accessed by shared code
  1022. *****************************************************************************/
  1023. static int
  1024. e1000_read_mac_addr(struct eth_device *nic)
  1025. {
  1026. struct e1000_hw *hw = nic->priv;
  1027. uint16_t offset;
  1028. uint16_t eeprom_data;
  1029. uint32_t reg_data = 0;
  1030. int i;
  1031. DEBUGFUNC();
  1032. for (i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
  1033. offset = i >> 1;
  1034. if (hw->mac_type == e1000_igb) {
  1035. /* i210 preloads MAC address into RAL/RAH registers */
  1036. if (offset == 0)
  1037. reg_data = E1000_READ_REG_ARRAY(hw, RA, 0);
  1038. else if (offset == 1)
  1039. reg_data >>= 16;
  1040. else if (offset == 2)
  1041. reg_data = E1000_READ_REG_ARRAY(hw, RA, 1);
  1042. eeprom_data = reg_data & 0xffff;
  1043. } else if (e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
  1044. DEBUGOUT("EEPROM Read Error\n");
  1045. return -E1000_ERR_EEPROM;
  1046. }
  1047. nic->enetaddr[i] = eeprom_data & 0xff;
  1048. nic->enetaddr[i + 1] = (eeprom_data >> 8) & 0xff;
  1049. }
  1050. /* Invert the last bit if this is the second device */
  1051. if (e1000_is_second_port(hw))
  1052. nic->enetaddr[5] ^= 1;
  1053. #ifdef CONFIG_E1000_FALLBACK_MAC
  1054. if (!is_valid_ethaddr(nic->enetaddr)) {
  1055. unsigned char fb_mac[NODE_ADDRESS_SIZE] = CONFIG_E1000_FALLBACK_MAC;
  1056. memcpy (nic->enetaddr, fb_mac, NODE_ADDRESS_SIZE);
  1057. }
  1058. #endif
  1059. return 0;
  1060. }
  1061. #endif
  1062. /******************************************************************************
  1063. * Initializes receive address filters.
  1064. *
  1065. * hw - Struct containing variables accessed by shared code
  1066. *
  1067. * Places the MAC address in receive address register 0 and clears the rest
  1068. * of the receive addresss registers. Clears the multicast table. Assumes
  1069. * the receiver is in reset when the routine is called.
  1070. *****************************************************************************/
  1071. static void
  1072. e1000_init_rx_addrs(struct eth_device *nic)
  1073. {
  1074. struct e1000_hw *hw = nic->priv;
  1075. uint32_t i;
  1076. uint32_t addr_low;
  1077. uint32_t addr_high;
  1078. DEBUGFUNC();
  1079. /* Setup the receive address. */
  1080. DEBUGOUT("Programming MAC Address into RAR[0]\n");
  1081. addr_low = (nic->enetaddr[0] |
  1082. (nic->enetaddr[1] << 8) |
  1083. (nic->enetaddr[2] << 16) | (nic->enetaddr[3] << 24));
  1084. addr_high = (nic->enetaddr[4] | (nic->enetaddr[5] << 8) | E1000_RAH_AV);
  1085. E1000_WRITE_REG_ARRAY(hw, RA, 0, addr_low);
  1086. E1000_WRITE_REG_ARRAY(hw, RA, 1, addr_high);
  1087. /* Zero out the other 15 receive addresses. */
  1088. DEBUGOUT("Clearing RAR[1-15]\n");
  1089. for (i = 1; i < E1000_RAR_ENTRIES; i++) {
  1090. E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
  1091. E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
  1092. }
  1093. }
  1094. /******************************************************************************
  1095. * Clears the VLAN filer table
  1096. *
  1097. * hw - Struct containing variables accessed by shared code
  1098. *****************************************************************************/
  1099. static void
  1100. e1000_clear_vfta(struct e1000_hw *hw)
  1101. {
  1102. uint32_t offset;
  1103. for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++)
  1104. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, 0);
  1105. }
  1106. /******************************************************************************
  1107. * Set the mac type member in the hw struct.
  1108. *
  1109. * hw - Struct containing variables accessed by shared code
  1110. *****************************************************************************/
  1111. int32_t
  1112. e1000_set_mac_type(struct e1000_hw *hw)
  1113. {
  1114. DEBUGFUNC();
  1115. switch (hw->device_id) {
  1116. case E1000_DEV_ID_82542:
  1117. switch (hw->revision_id) {
  1118. case E1000_82542_2_0_REV_ID:
  1119. hw->mac_type = e1000_82542_rev2_0;
  1120. break;
  1121. case E1000_82542_2_1_REV_ID:
  1122. hw->mac_type = e1000_82542_rev2_1;
  1123. break;
  1124. default:
  1125. /* Invalid 82542 revision ID */
  1126. return -E1000_ERR_MAC_TYPE;
  1127. }
  1128. break;
  1129. case E1000_DEV_ID_82543GC_FIBER:
  1130. case E1000_DEV_ID_82543GC_COPPER:
  1131. hw->mac_type = e1000_82543;
  1132. break;
  1133. case E1000_DEV_ID_82544EI_COPPER:
  1134. case E1000_DEV_ID_82544EI_FIBER:
  1135. case E1000_DEV_ID_82544GC_COPPER:
  1136. case E1000_DEV_ID_82544GC_LOM:
  1137. hw->mac_type = e1000_82544;
  1138. break;
  1139. case E1000_DEV_ID_82540EM:
  1140. case E1000_DEV_ID_82540EM_LOM:
  1141. case E1000_DEV_ID_82540EP:
  1142. case E1000_DEV_ID_82540EP_LOM:
  1143. case E1000_DEV_ID_82540EP_LP:
  1144. hw->mac_type = e1000_82540;
  1145. break;
  1146. case E1000_DEV_ID_82545EM_COPPER:
  1147. case E1000_DEV_ID_82545EM_FIBER:
  1148. hw->mac_type = e1000_82545;
  1149. break;
  1150. case E1000_DEV_ID_82545GM_COPPER:
  1151. case E1000_DEV_ID_82545GM_FIBER:
  1152. case E1000_DEV_ID_82545GM_SERDES:
  1153. hw->mac_type = e1000_82545_rev_3;
  1154. break;
  1155. case E1000_DEV_ID_82546EB_COPPER:
  1156. case E1000_DEV_ID_82546EB_FIBER:
  1157. case E1000_DEV_ID_82546EB_QUAD_COPPER:
  1158. hw->mac_type = e1000_82546;
  1159. break;
  1160. case E1000_DEV_ID_82546GB_COPPER:
  1161. case E1000_DEV_ID_82546GB_FIBER:
  1162. case E1000_DEV_ID_82546GB_SERDES:
  1163. case E1000_DEV_ID_82546GB_PCIE:
  1164. case E1000_DEV_ID_82546GB_QUAD_COPPER:
  1165. case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
  1166. hw->mac_type = e1000_82546_rev_3;
  1167. break;
  1168. case E1000_DEV_ID_82541EI:
  1169. case E1000_DEV_ID_82541EI_MOBILE:
  1170. case E1000_DEV_ID_82541ER_LOM:
  1171. hw->mac_type = e1000_82541;
  1172. break;
  1173. case E1000_DEV_ID_82541ER:
  1174. case E1000_DEV_ID_82541GI:
  1175. case E1000_DEV_ID_82541GI_LF:
  1176. case E1000_DEV_ID_82541GI_MOBILE:
  1177. hw->mac_type = e1000_82541_rev_2;
  1178. break;
  1179. case E1000_DEV_ID_82547EI:
  1180. case E1000_DEV_ID_82547EI_MOBILE:
  1181. hw->mac_type = e1000_82547;
  1182. break;
  1183. case E1000_DEV_ID_82547GI:
  1184. hw->mac_type = e1000_82547_rev_2;
  1185. break;
  1186. case E1000_DEV_ID_82571EB_COPPER:
  1187. case E1000_DEV_ID_82571EB_FIBER:
  1188. case E1000_DEV_ID_82571EB_SERDES:
  1189. case E1000_DEV_ID_82571EB_SERDES_DUAL:
  1190. case E1000_DEV_ID_82571EB_SERDES_QUAD:
  1191. case E1000_DEV_ID_82571EB_QUAD_COPPER:
  1192. case E1000_DEV_ID_82571PT_QUAD_COPPER:
  1193. case E1000_DEV_ID_82571EB_QUAD_FIBER:
  1194. case E1000_DEV_ID_82571EB_QUAD_COPPER_LOWPROFILE:
  1195. hw->mac_type = e1000_82571;
  1196. break;
  1197. case E1000_DEV_ID_82572EI_COPPER:
  1198. case E1000_DEV_ID_82572EI_FIBER:
  1199. case E1000_DEV_ID_82572EI_SERDES:
  1200. case E1000_DEV_ID_82572EI:
  1201. hw->mac_type = e1000_82572;
  1202. break;
  1203. case E1000_DEV_ID_82573E:
  1204. case E1000_DEV_ID_82573E_IAMT:
  1205. case E1000_DEV_ID_82573L:
  1206. hw->mac_type = e1000_82573;
  1207. break;
  1208. case E1000_DEV_ID_82574L:
  1209. hw->mac_type = e1000_82574;
  1210. break;
  1211. case E1000_DEV_ID_80003ES2LAN_COPPER_SPT:
  1212. case E1000_DEV_ID_80003ES2LAN_SERDES_SPT:
  1213. case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
  1214. case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
  1215. hw->mac_type = e1000_80003es2lan;
  1216. break;
  1217. case E1000_DEV_ID_ICH8_IGP_M_AMT:
  1218. case E1000_DEV_ID_ICH8_IGP_AMT:
  1219. case E1000_DEV_ID_ICH8_IGP_C:
  1220. case E1000_DEV_ID_ICH8_IFE:
  1221. case E1000_DEV_ID_ICH8_IFE_GT:
  1222. case E1000_DEV_ID_ICH8_IFE_G:
  1223. case E1000_DEV_ID_ICH8_IGP_M:
  1224. hw->mac_type = e1000_ich8lan;
  1225. break;
  1226. case PCI_DEVICE_ID_INTEL_I210_UNPROGRAMMED:
  1227. case PCI_DEVICE_ID_INTEL_I211_UNPROGRAMMED:
  1228. case PCI_DEVICE_ID_INTEL_I210_COPPER:
  1229. case PCI_DEVICE_ID_INTEL_I211_COPPER:
  1230. case PCI_DEVICE_ID_INTEL_I210_COPPER_FLASHLESS:
  1231. case PCI_DEVICE_ID_INTEL_I210_SERDES:
  1232. case PCI_DEVICE_ID_INTEL_I210_SERDES_FLASHLESS:
  1233. case PCI_DEVICE_ID_INTEL_I210_1000BASEKX:
  1234. hw->mac_type = e1000_igb;
  1235. break;
  1236. default:
  1237. /* Should never have loaded on this device */
  1238. return -E1000_ERR_MAC_TYPE;
  1239. }
  1240. return E1000_SUCCESS;
  1241. }
  1242. /******************************************************************************
  1243. * Reset the transmit and receive units; mask and clear all interrupts.
  1244. *
  1245. * hw - Struct containing variables accessed by shared code
  1246. *****************************************************************************/
  1247. void
  1248. e1000_reset_hw(struct e1000_hw *hw)
  1249. {
  1250. uint32_t ctrl;
  1251. uint32_t ctrl_ext;
  1252. uint32_t manc;
  1253. uint32_t pba = 0;
  1254. uint32_t reg;
  1255. DEBUGFUNC();
  1256. /* get the correct pba value for both PCI and PCIe*/
  1257. if (hw->mac_type < e1000_82571)
  1258. pba = E1000_DEFAULT_PCI_PBA;
  1259. else
  1260. pba = E1000_DEFAULT_PCIE_PBA;
  1261. /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
  1262. if (hw->mac_type == e1000_82542_rev2_0) {
  1263. DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  1264. pci_write_config_word(hw->pdev, PCI_COMMAND,
  1265. hw->pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
  1266. }
  1267. /* Clear interrupt mask to stop board from generating interrupts */
  1268. DEBUGOUT("Masking off all interrupts\n");
  1269. if (hw->mac_type == e1000_igb)
  1270. E1000_WRITE_REG(hw, I210_IAM, 0);
  1271. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  1272. /* Disable the Transmit and Receive units. Then delay to allow
  1273. * any pending transactions to complete before we hit the MAC with
  1274. * the global reset.
  1275. */
  1276. E1000_WRITE_REG(hw, RCTL, 0);
  1277. E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
  1278. E1000_WRITE_FLUSH(hw);
  1279. /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
  1280. hw->tbi_compatibility_on = false;
  1281. /* Delay to allow any outstanding PCI transactions to complete before
  1282. * resetting the device
  1283. */
  1284. mdelay(10);
  1285. /* Issue a global reset to the MAC. This will reset the chip's
  1286. * transmit, receive, DMA, and link units. It will not effect
  1287. * the current PCI configuration. The global reset bit is self-
  1288. * clearing, and should clear within a microsecond.
  1289. */
  1290. DEBUGOUT("Issuing a global reset to MAC\n");
  1291. ctrl = E1000_READ_REG(hw, CTRL);
  1292. E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
  1293. /* Force a reload from the EEPROM if necessary */
  1294. if (hw->mac_type == e1000_igb) {
  1295. mdelay(20);
  1296. reg = E1000_READ_REG(hw, STATUS);
  1297. if (reg & E1000_STATUS_PF_RST_DONE)
  1298. DEBUGOUT("PF OK\n");
  1299. reg = E1000_READ_REG(hw, I210_EECD);
  1300. if (reg & E1000_EECD_AUTO_RD)
  1301. DEBUGOUT("EEC OK\n");
  1302. } else if (hw->mac_type < e1000_82540) {
  1303. /* Wait for reset to complete */
  1304. udelay(10);
  1305. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  1306. ctrl_ext |= E1000_CTRL_EXT_EE_RST;
  1307. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  1308. E1000_WRITE_FLUSH(hw);
  1309. /* Wait for EEPROM reload */
  1310. mdelay(2);
  1311. } else {
  1312. /* Wait for EEPROM reload (it happens automatically) */
  1313. mdelay(4);
  1314. /* Dissable HW ARPs on ASF enabled adapters */
  1315. manc = E1000_READ_REG(hw, MANC);
  1316. manc &= ~(E1000_MANC_ARP_EN);
  1317. E1000_WRITE_REG(hw, MANC, manc);
  1318. }
  1319. /* Clear interrupt mask to stop board from generating interrupts */
  1320. DEBUGOUT("Masking off all interrupts\n");
  1321. if (hw->mac_type == e1000_igb)
  1322. E1000_WRITE_REG(hw, I210_IAM, 0);
  1323. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  1324. /* Clear any pending interrupt events. */
  1325. E1000_READ_REG(hw, ICR);
  1326. /* If MWI was previously enabled, reenable it. */
  1327. if (hw->mac_type == e1000_82542_rev2_0) {
  1328. pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
  1329. }
  1330. if (hw->mac_type != e1000_igb)
  1331. E1000_WRITE_REG(hw, PBA, pba);
  1332. }
  1333. /******************************************************************************
  1334. *
  1335. * Initialize a number of hardware-dependent bits
  1336. *
  1337. * hw: Struct containing variables accessed by shared code
  1338. *
  1339. * This function contains hardware limitation workarounds for PCI-E adapters
  1340. *
  1341. *****************************************************************************/
  1342. static void
  1343. e1000_initialize_hardware_bits(struct e1000_hw *hw)
  1344. {
  1345. if ((hw->mac_type >= e1000_82571) &&
  1346. (!hw->initialize_hw_bits_disable)) {
  1347. /* Settings common to all PCI-express silicon */
  1348. uint32_t reg_ctrl, reg_ctrl_ext;
  1349. uint32_t reg_tarc0, reg_tarc1;
  1350. uint32_t reg_tctl;
  1351. uint32_t reg_txdctl, reg_txdctl1;
  1352. /* link autonegotiation/sync workarounds */
  1353. reg_tarc0 = E1000_READ_REG(hw, TARC0);
  1354. reg_tarc0 &= ~((1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
  1355. /* Enable not-done TX descriptor counting */
  1356. reg_txdctl = E1000_READ_REG(hw, TXDCTL);
  1357. reg_txdctl |= E1000_TXDCTL_COUNT_DESC;
  1358. E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
  1359. reg_txdctl1 = E1000_READ_REG(hw, TXDCTL1);
  1360. reg_txdctl1 |= E1000_TXDCTL_COUNT_DESC;
  1361. E1000_WRITE_REG(hw, TXDCTL1, reg_txdctl1);
  1362. /* IGB is cool */
  1363. if (hw->mac_type == e1000_igb)
  1364. return;
  1365. switch (hw->mac_type) {
  1366. case e1000_82571:
  1367. case e1000_82572:
  1368. /* Clear PHY TX compatible mode bits */
  1369. reg_tarc1 = E1000_READ_REG(hw, TARC1);
  1370. reg_tarc1 &= ~((1 << 30)|(1 << 29));
  1371. /* link autonegotiation/sync workarounds */
  1372. reg_tarc0 |= ((1 << 26)|(1 << 25)|(1 << 24)|(1 << 23));
  1373. /* TX ring control fixes */
  1374. reg_tarc1 |= ((1 << 26)|(1 << 25)|(1 << 24));
  1375. /* Multiple read bit is reversed polarity */
  1376. reg_tctl = E1000_READ_REG(hw, TCTL);
  1377. if (reg_tctl & E1000_TCTL_MULR)
  1378. reg_tarc1 &= ~(1 << 28);
  1379. else
  1380. reg_tarc1 |= (1 << 28);
  1381. E1000_WRITE_REG(hw, TARC1, reg_tarc1);
  1382. break;
  1383. case e1000_82573:
  1384. case e1000_82574:
  1385. reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  1386. reg_ctrl_ext &= ~(1 << 23);
  1387. reg_ctrl_ext |= (1 << 22);
  1388. /* TX byte count fix */
  1389. reg_ctrl = E1000_READ_REG(hw, CTRL);
  1390. reg_ctrl &= ~(1 << 29);
  1391. E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
  1392. E1000_WRITE_REG(hw, CTRL, reg_ctrl);
  1393. break;
  1394. case e1000_80003es2lan:
  1395. /* improve small packet performace for fiber/serdes */
  1396. if ((hw->media_type == e1000_media_type_fiber)
  1397. || (hw->media_type ==
  1398. e1000_media_type_internal_serdes)) {
  1399. reg_tarc0 &= ~(1 << 20);
  1400. }
  1401. /* Multiple read bit is reversed polarity */
  1402. reg_tctl = E1000_READ_REG(hw, TCTL);
  1403. reg_tarc1 = E1000_READ_REG(hw, TARC1);
  1404. if (reg_tctl & E1000_TCTL_MULR)
  1405. reg_tarc1 &= ~(1 << 28);
  1406. else
  1407. reg_tarc1 |= (1 << 28);
  1408. E1000_WRITE_REG(hw, TARC1, reg_tarc1);
  1409. break;
  1410. case e1000_ich8lan:
  1411. /* Reduce concurrent DMA requests to 3 from 4 */
  1412. if ((hw->revision_id < 3) ||
  1413. ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
  1414. (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))
  1415. reg_tarc0 |= ((1 << 29)|(1 << 28));
  1416. reg_ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  1417. reg_ctrl_ext |= (1 << 22);
  1418. E1000_WRITE_REG(hw, CTRL_EXT, reg_ctrl_ext);
  1419. /* workaround TX hang with TSO=on */
  1420. reg_tarc0 |= ((1 << 27)|(1 << 26)|(1 << 24)|(1 << 23));
  1421. /* Multiple read bit is reversed polarity */
  1422. reg_tctl = E1000_READ_REG(hw, TCTL);
  1423. reg_tarc1 = E1000_READ_REG(hw, TARC1);
  1424. if (reg_tctl & E1000_TCTL_MULR)
  1425. reg_tarc1 &= ~(1 << 28);
  1426. else
  1427. reg_tarc1 |= (1 << 28);
  1428. /* workaround TX hang with TSO=on */
  1429. reg_tarc1 |= ((1 << 30)|(1 << 26)|(1 << 24));
  1430. E1000_WRITE_REG(hw, TARC1, reg_tarc1);
  1431. break;
  1432. default:
  1433. break;
  1434. }
  1435. E1000_WRITE_REG(hw, TARC0, reg_tarc0);
  1436. }
  1437. }
  1438. /******************************************************************************
  1439. * Performs basic configuration of the adapter.
  1440. *
  1441. * hw - Struct containing variables accessed by shared code
  1442. *
  1443. * Assumes that the controller has previously been reset and is in a
  1444. * post-reset uninitialized state. Initializes the receive address registers,
  1445. * multicast table, and VLAN filter table. Calls routines to setup link
  1446. * configuration and flow control settings. Clears all on-chip counters. Leaves
  1447. * the transmit and receive units disabled and uninitialized.
  1448. *****************************************************************************/
  1449. static int
  1450. e1000_init_hw(struct eth_device *nic)
  1451. {
  1452. struct e1000_hw *hw = nic->priv;
  1453. uint32_t ctrl;
  1454. uint32_t i;
  1455. int32_t ret_val;
  1456. uint16_t pcix_cmd_word;
  1457. uint16_t pcix_stat_hi_word;
  1458. uint16_t cmd_mmrbc;
  1459. uint16_t stat_mmrbc;
  1460. uint32_t mta_size;
  1461. uint32_t reg_data;
  1462. uint32_t ctrl_ext;
  1463. DEBUGFUNC();
  1464. /* force full DMA clock frequency for 10/100 on ICH8 A0-B0 */
  1465. if ((hw->mac_type == e1000_ich8lan) &&
  1466. ((hw->revision_id < 3) ||
  1467. ((hw->device_id != E1000_DEV_ID_ICH8_IGP_M_AMT) &&
  1468. (hw->device_id != E1000_DEV_ID_ICH8_IGP_M)))) {
  1469. reg_data = E1000_READ_REG(hw, STATUS);
  1470. reg_data &= ~0x80000000;
  1471. E1000_WRITE_REG(hw, STATUS, reg_data);
  1472. }
  1473. /* Do not need initialize Identification LED */
  1474. /* Set the media type and TBI compatibility */
  1475. e1000_set_media_type(hw);
  1476. /* Must be called after e1000_set_media_type
  1477. * because media_type is used */
  1478. e1000_initialize_hardware_bits(hw);
  1479. /* Disabling VLAN filtering. */
  1480. DEBUGOUT("Initializing the IEEE VLAN\n");
  1481. /* VET hardcoded to standard value and VFTA removed in ICH8 LAN */
  1482. if (hw->mac_type != e1000_ich8lan) {
  1483. if (hw->mac_type < e1000_82545_rev_3)
  1484. E1000_WRITE_REG(hw, VET, 0);
  1485. e1000_clear_vfta(hw);
  1486. }
  1487. /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
  1488. if (hw->mac_type == e1000_82542_rev2_0) {
  1489. DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  1490. pci_write_config_word(hw->pdev, PCI_COMMAND,
  1491. hw->
  1492. pci_cmd_word & ~PCI_COMMAND_INVALIDATE);
  1493. E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
  1494. E1000_WRITE_FLUSH(hw);
  1495. mdelay(5);
  1496. }
  1497. /* Setup the receive address. This involves initializing all of the Receive
  1498. * Address Registers (RARs 0 - 15).
  1499. */
  1500. e1000_init_rx_addrs(nic);
  1501. /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
  1502. if (hw->mac_type == e1000_82542_rev2_0) {
  1503. E1000_WRITE_REG(hw, RCTL, 0);
  1504. E1000_WRITE_FLUSH(hw);
  1505. mdelay(1);
  1506. pci_write_config_word(hw->pdev, PCI_COMMAND, hw->pci_cmd_word);
  1507. }
  1508. /* Zero out the Multicast HASH table */
  1509. DEBUGOUT("Zeroing the MTA\n");
  1510. mta_size = E1000_MC_TBL_SIZE;
  1511. if (hw->mac_type == e1000_ich8lan)
  1512. mta_size = E1000_MC_TBL_SIZE_ICH8LAN;
  1513. for (i = 0; i < mta_size; i++) {
  1514. E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
  1515. /* use write flush to prevent Memory Write Block (MWB) from
  1516. * occuring when accessing our register space */
  1517. E1000_WRITE_FLUSH(hw);
  1518. }
  1519. #if 0
  1520. /* Set the PCI priority bit correctly in the CTRL register. This
  1521. * determines if the adapter gives priority to receives, or if it
  1522. * gives equal priority to transmits and receives. Valid only on
  1523. * 82542 and 82543 silicon.
  1524. */
  1525. if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
  1526. ctrl = E1000_READ_REG(hw, CTRL);
  1527. E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
  1528. }
  1529. #endif
  1530. switch (hw->mac_type) {
  1531. case e1000_82545_rev_3:
  1532. case e1000_82546_rev_3:
  1533. case e1000_igb:
  1534. break;
  1535. default:
  1536. /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
  1537. if (hw->bus_type == e1000_bus_type_pcix) {
  1538. pci_read_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
  1539. &pcix_cmd_word);
  1540. pci_read_config_word(hw->pdev, PCIX_STATUS_REGISTER_HI,
  1541. &pcix_stat_hi_word);
  1542. cmd_mmrbc =
  1543. (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
  1544. PCIX_COMMAND_MMRBC_SHIFT;
  1545. stat_mmrbc =
  1546. (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
  1547. PCIX_STATUS_HI_MMRBC_SHIFT;
  1548. if (stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
  1549. stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
  1550. if (cmd_mmrbc > stat_mmrbc) {
  1551. pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
  1552. pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
  1553. pci_write_config_word(hw->pdev, PCIX_COMMAND_REGISTER,
  1554. pcix_cmd_word);
  1555. }
  1556. }
  1557. break;
  1558. }
  1559. /* More time needed for PHY to initialize */
  1560. if (hw->mac_type == e1000_ich8lan)
  1561. mdelay(15);
  1562. if (hw->mac_type == e1000_igb)
  1563. mdelay(15);
  1564. /* Call a subroutine to configure the link and setup flow control. */
  1565. ret_val = e1000_setup_link(nic);
  1566. /* Set the transmit descriptor write-back policy */
  1567. if (hw->mac_type > e1000_82544) {
  1568. ctrl = E1000_READ_REG(hw, TXDCTL);
  1569. ctrl =
  1570. (ctrl & ~E1000_TXDCTL_WTHRESH) |
  1571. E1000_TXDCTL_FULL_TX_DESC_WB;
  1572. E1000_WRITE_REG(hw, TXDCTL, ctrl);
  1573. }
  1574. /* Set the receive descriptor write back policy */
  1575. if (hw->mac_type >= e1000_82571) {
  1576. ctrl = E1000_READ_REG(hw, RXDCTL);
  1577. ctrl =
  1578. (ctrl & ~E1000_RXDCTL_WTHRESH) |
  1579. E1000_RXDCTL_FULL_RX_DESC_WB;
  1580. E1000_WRITE_REG(hw, RXDCTL, ctrl);
  1581. }
  1582. switch (hw->mac_type) {
  1583. default:
  1584. break;
  1585. case e1000_80003es2lan:
  1586. /* Enable retransmit on late collisions */
  1587. reg_data = E1000_READ_REG(hw, TCTL);
  1588. reg_data |= E1000_TCTL_RTLC;
  1589. E1000_WRITE_REG(hw, TCTL, reg_data);
  1590. /* Configure Gigabit Carry Extend Padding */
  1591. reg_data = E1000_READ_REG(hw, TCTL_EXT);
  1592. reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
  1593. reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
  1594. E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
  1595. /* Configure Transmit Inter-Packet Gap */
  1596. reg_data = E1000_READ_REG(hw, TIPG);
  1597. reg_data &= ~E1000_TIPG_IPGT_MASK;
  1598. reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
  1599. E1000_WRITE_REG(hw, TIPG, reg_data);
  1600. reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
  1601. reg_data &= ~0x00100000;
  1602. E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
  1603. /* Fall through */
  1604. case e1000_82571:
  1605. case e1000_82572:
  1606. case e1000_ich8lan:
  1607. ctrl = E1000_READ_REG(hw, TXDCTL1);
  1608. ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH)
  1609. | E1000_TXDCTL_FULL_TX_DESC_WB;
  1610. E1000_WRITE_REG(hw, TXDCTL1, ctrl);
  1611. break;
  1612. case e1000_82573:
  1613. case e1000_82574:
  1614. reg_data = E1000_READ_REG(hw, GCR);
  1615. reg_data |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
  1616. E1000_WRITE_REG(hw, GCR, reg_data);
  1617. case e1000_igb:
  1618. break;
  1619. }
  1620. #if 0
  1621. /* Clear all of the statistics registers (clear on read). It is
  1622. * important that we do this after we have tried to establish link
  1623. * because the symbol error count will increment wildly if there
  1624. * is no link.
  1625. */
  1626. e1000_clear_hw_cntrs(hw);
  1627. /* ICH8 No-snoop bits are opposite polarity.
  1628. * Set to snoop by default after reset. */
  1629. if (hw->mac_type == e1000_ich8lan)
  1630. e1000_set_pci_ex_no_snoop(hw, PCI_EX_82566_SNOOP_ALL);
  1631. #endif
  1632. if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
  1633. hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
  1634. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  1635. /* Relaxed ordering must be disabled to avoid a parity
  1636. * error crash in a PCI slot. */
  1637. ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
  1638. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  1639. }
  1640. return ret_val;
  1641. }
  1642. /******************************************************************************
  1643. * Configures flow control and link settings.
  1644. *
  1645. * hw - Struct containing variables accessed by shared code
  1646. *
  1647. * Determines which flow control settings to use. Calls the apropriate media-
  1648. * specific link configuration function. Configures the flow control settings.
  1649. * Assuming the adapter has a valid link partner, a valid link should be
  1650. * established. Assumes the hardware has previously been reset and the
  1651. * transmitter and receiver are not enabled.
  1652. *****************************************************************************/
  1653. static int
  1654. e1000_setup_link(struct eth_device *nic)
  1655. {
  1656. struct e1000_hw *hw = nic->priv;
  1657. int32_t ret_val;
  1658. #ifndef CONFIG_E1000_NO_NVM
  1659. uint32_t ctrl_ext;
  1660. uint16_t eeprom_data;
  1661. #endif
  1662. DEBUGFUNC();
  1663. /* In the case of the phy reset being blocked, we already have a link.
  1664. * We do not have to set it up again. */
  1665. if (e1000_check_phy_reset_block(hw))
  1666. return E1000_SUCCESS;
  1667. #ifndef CONFIG_E1000_NO_NVM
  1668. /* Read and store word 0x0F of the EEPROM. This word contains bits
  1669. * that determine the hardware's default PAUSE (flow control) mode,
  1670. * a bit that determines whether the HW defaults to enabling or
  1671. * disabling auto-negotiation, and the direction of the
  1672. * SW defined pins. If there is no SW over-ride of the flow
  1673. * control setting, then the variable hw->fc will
  1674. * be initialized based on a value in the EEPROM.
  1675. */
  1676. if (e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1,
  1677. &eeprom_data) < 0) {
  1678. DEBUGOUT("EEPROM Read Error\n");
  1679. return -E1000_ERR_EEPROM;
  1680. }
  1681. #endif
  1682. if (hw->fc == e1000_fc_default) {
  1683. switch (hw->mac_type) {
  1684. case e1000_ich8lan:
  1685. case e1000_82573:
  1686. case e1000_82574:
  1687. case e1000_igb:
  1688. hw->fc = e1000_fc_full;
  1689. break;
  1690. default:
  1691. #ifndef CONFIG_E1000_NO_NVM
  1692. ret_val = e1000_read_eeprom(hw,
  1693. EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data);
  1694. if (ret_val) {
  1695. DEBUGOUT("EEPROM Read Error\n");
  1696. return -E1000_ERR_EEPROM;
  1697. }
  1698. if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
  1699. hw->fc = e1000_fc_none;
  1700. else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
  1701. EEPROM_WORD0F_ASM_DIR)
  1702. hw->fc = e1000_fc_tx_pause;
  1703. else
  1704. #endif
  1705. hw->fc = e1000_fc_full;
  1706. break;
  1707. }
  1708. }
  1709. /* We want to save off the original Flow Control configuration just
  1710. * in case we get disconnected and then reconnected into a different
  1711. * hub or switch with different Flow Control capabilities.
  1712. */
  1713. if (hw->mac_type == e1000_82542_rev2_0)
  1714. hw->fc &= (~e1000_fc_tx_pause);
  1715. if ((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
  1716. hw->fc &= (~e1000_fc_rx_pause);
  1717. hw->original_fc = hw->fc;
  1718. DEBUGOUT("After fix-ups FlowControl is now = %x\n", hw->fc);
  1719. #ifndef CONFIG_E1000_NO_NVM
  1720. /* Take the 4 bits from EEPROM word 0x0F that determine the initial
  1721. * polarity value for the SW controlled pins, and setup the
  1722. * Extended Device Control reg with that info.
  1723. * This is needed because one of the SW controlled pins is used for
  1724. * signal detection. So this should be done before e1000_setup_pcs_link()
  1725. * or e1000_phy_setup() is called.
  1726. */
  1727. if (hw->mac_type == e1000_82543) {
  1728. ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
  1729. SWDPIO__EXT_SHIFT);
  1730. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  1731. }
  1732. #endif
  1733. /* Call the necessary subroutine to configure the link. */
  1734. ret_val = (hw->media_type == e1000_media_type_fiber) ?
  1735. e1000_setup_fiber_link(nic) : e1000_setup_copper_link(nic);
  1736. if (ret_val < 0) {
  1737. return ret_val;
  1738. }
  1739. /* Initialize the flow control address, type, and PAUSE timer
  1740. * registers to their default values. This is done even if flow
  1741. * control is disabled, because it does not hurt anything to
  1742. * initialize these registers.
  1743. */
  1744. DEBUGOUT("Initializing the Flow Control address, type"
  1745. "and timer regs\n");
  1746. /* FCAL/H and FCT are hardcoded to standard values in e1000_ich8lan. */
  1747. if (hw->mac_type != e1000_ich8lan) {
  1748. E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
  1749. E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
  1750. E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
  1751. }
  1752. E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
  1753. /* Set the flow control receive threshold registers. Normally,
  1754. * these registers will be set to a default threshold that may be
  1755. * adjusted later by the driver's runtime code. However, if the
  1756. * ability to transmit pause frames in not enabled, then these
  1757. * registers will be set to 0.
  1758. */
  1759. if (!(hw->fc & e1000_fc_tx_pause)) {
  1760. E1000_WRITE_REG(hw, FCRTL, 0);
  1761. E1000_WRITE_REG(hw, FCRTH, 0);
  1762. } else {
  1763. /* We need to set up the Receive Threshold high and low water marks
  1764. * as well as (optionally) enabling the transmission of XON frames.
  1765. */
  1766. if (hw->fc_send_xon) {
  1767. E1000_WRITE_REG(hw, FCRTL,
  1768. (hw->fc_low_water | E1000_FCRTL_XONE));
  1769. E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  1770. } else {
  1771. E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
  1772. E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  1773. }
  1774. }
  1775. return ret_val;
  1776. }
  1777. /******************************************************************************
  1778. * Sets up link for a fiber based adapter
  1779. *
  1780. * hw - Struct containing variables accessed by shared code
  1781. *
  1782. * Manipulates Physical Coding Sublayer functions in order to configure
  1783. * link. Assumes the hardware has been previously reset and the transmitter
  1784. * and receiver are not enabled.
  1785. *****************************************************************************/
  1786. static int
  1787. e1000_setup_fiber_link(struct eth_device *nic)
  1788. {
  1789. struct e1000_hw *hw = nic->priv;
  1790. uint32_t ctrl;
  1791. uint32_t status;
  1792. uint32_t txcw = 0;
  1793. uint32_t i;
  1794. uint32_t signal;
  1795. int32_t ret_val;
  1796. DEBUGFUNC();
  1797. /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
  1798. * set when the optics detect a signal. On older adapters, it will be
  1799. * cleared when there is a signal
  1800. */
  1801. ctrl = E1000_READ_REG(hw, CTRL);
  1802. if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
  1803. signal = E1000_CTRL_SWDPIN1;
  1804. else
  1805. signal = 0;
  1806. printf("signal for %s is %x (ctrl %08x)!!!!\n", nic->name, signal,
  1807. ctrl);
  1808. /* Take the link out of reset */
  1809. ctrl &= ~(E1000_CTRL_LRST);
  1810. e1000_config_collision_dist(hw);
  1811. /* Check for a software override of the flow control settings, and setup
  1812. * the device accordingly. If auto-negotiation is enabled, then software
  1813. * will have to set the "PAUSE" bits to the correct value in the Tranmsit
  1814. * Config Word Register (TXCW) and re-start auto-negotiation. However, if
  1815. * auto-negotiation is disabled, then software will have to manually
  1816. * configure the two flow control enable bits in the CTRL register.
  1817. *
  1818. * The possible values of the "fc" parameter are:
  1819. * 0: Flow control is completely disabled
  1820. * 1: Rx flow control is enabled (we can receive pause frames, but
  1821. * not send pause frames).
  1822. * 2: Tx flow control is enabled (we can send pause frames but we do
  1823. * not support receiving pause frames).
  1824. * 3: Both Rx and TX flow control (symmetric) are enabled.
  1825. */
  1826. switch (hw->fc) {
  1827. case e1000_fc_none:
  1828. /* Flow control is completely disabled by a software over-ride. */
  1829. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
  1830. break;
  1831. case e1000_fc_rx_pause:
  1832. /* RX Flow control is enabled and TX Flow control is disabled by a
  1833. * software over-ride. Since there really isn't a way to advertise
  1834. * that we are capable of RX Pause ONLY, we will advertise that we
  1835. * support both symmetric and asymmetric RX PAUSE. Later, we will
  1836. * disable the adapter's ability to send PAUSE frames.
  1837. */
  1838. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  1839. break;
  1840. case e1000_fc_tx_pause:
  1841. /* TX Flow control is enabled, and RX Flow control is disabled, by a
  1842. * software over-ride.
  1843. */
  1844. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
  1845. break;
  1846. case e1000_fc_full:
  1847. /* Flow control (both RX and TX) is enabled by a software over-ride. */
  1848. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  1849. break;
  1850. default:
  1851. DEBUGOUT("Flow control param set incorrectly\n");
  1852. return -E1000_ERR_CONFIG;
  1853. break;
  1854. }
  1855. /* Since auto-negotiation is enabled, take the link out of reset (the link
  1856. * will be in reset, because we previously reset the chip). This will
  1857. * restart auto-negotiation. If auto-neogtiation is successful then the
  1858. * link-up status bit will be set and the flow control enable bits (RFCE
  1859. * and TFCE) will be set according to their negotiated value.
  1860. */
  1861. DEBUGOUT("Auto-negotiation enabled (%#x)\n", txcw);
  1862. E1000_WRITE_REG(hw, TXCW, txcw);
  1863. E1000_WRITE_REG(hw, CTRL, ctrl);
  1864. E1000_WRITE_FLUSH(hw);
  1865. hw->txcw = txcw;
  1866. mdelay(1);
  1867. /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
  1868. * indication in the Device Status Register. Time-out if a link isn't
  1869. * seen in 500 milliseconds seconds (Auto-negotiation should complete in
  1870. * less than 500 milliseconds even if the other end is doing it in SW).
  1871. */
  1872. if ((E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
  1873. DEBUGOUT("Looking for Link\n");
  1874. for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
  1875. mdelay(10);
  1876. status = E1000_READ_REG(hw, STATUS);
  1877. if (status & E1000_STATUS_LU)
  1878. break;
  1879. }
  1880. if (i == (LINK_UP_TIMEOUT / 10)) {
  1881. /* AutoNeg failed to achieve a link, so we'll call
  1882. * e1000_check_for_link. This routine will force the link up if we
  1883. * detect a signal. This will allow us to communicate with
  1884. * non-autonegotiating link partners.
  1885. */
  1886. DEBUGOUT("Never got a valid link from auto-neg!!!\n");
  1887. hw->autoneg_failed = 1;
  1888. ret_val = e1000_check_for_link(nic);
  1889. if (ret_val < 0) {
  1890. DEBUGOUT("Error while checking for link\n");
  1891. return ret_val;
  1892. }
  1893. hw->autoneg_failed = 0;
  1894. } else {
  1895. hw->autoneg_failed = 0;
  1896. DEBUGOUT("Valid Link Found\n");
  1897. }
  1898. } else {
  1899. DEBUGOUT("No Signal Detected\n");
  1900. return -E1000_ERR_NOLINK;
  1901. }
  1902. return 0;
  1903. }
  1904. /******************************************************************************
  1905. * Make sure we have a valid PHY and change PHY mode before link setup.
  1906. *
  1907. * hw - Struct containing variables accessed by shared code
  1908. ******************************************************************************/
  1909. static int32_t
  1910. e1000_copper_link_preconfig(struct e1000_hw *hw)
  1911. {
  1912. uint32_t ctrl;
  1913. int32_t ret_val;
  1914. uint16_t phy_data;
  1915. DEBUGFUNC();
  1916. ctrl = E1000_READ_REG(hw, CTRL);
  1917. /* With 82543, we need to force speed and duplex on the MAC equal to what
  1918. * the PHY speed and duplex configuration is. In addition, we need to
  1919. * perform a hardware reset on the PHY to take it out of reset.
  1920. */
  1921. if (hw->mac_type > e1000_82543) {
  1922. ctrl |= E1000_CTRL_SLU;
  1923. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1924. E1000_WRITE_REG(hw, CTRL, ctrl);
  1925. } else {
  1926. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX
  1927. | E1000_CTRL_SLU);
  1928. E1000_WRITE_REG(hw, CTRL, ctrl);
  1929. ret_val = e1000_phy_hw_reset(hw);
  1930. if (ret_val)
  1931. return ret_val;
  1932. }
  1933. /* Make sure we have a valid PHY */
  1934. ret_val = e1000_detect_gig_phy(hw);
  1935. if (ret_val) {
  1936. DEBUGOUT("Error, did not detect valid phy.\n");
  1937. return ret_val;
  1938. }
  1939. DEBUGOUT("Phy ID = %x\n", hw->phy_id);
  1940. /* Set PHY to class A mode (if necessary) */
  1941. ret_val = e1000_set_phy_mode(hw);
  1942. if (ret_val)
  1943. return ret_val;
  1944. if ((hw->mac_type == e1000_82545_rev_3) ||
  1945. (hw->mac_type == e1000_82546_rev_3)) {
  1946. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
  1947. &phy_data);
  1948. phy_data |= 0x00000008;
  1949. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL,
  1950. phy_data);
  1951. }
  1952. if (hw->mac_type <= e1000_82543 ||
  1953. hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
  1954. hw->mac_type == e1000_82541_rev_2
  1955. || hw->mac_type == e1000_82547_rev_2)
  1956. hw->phy_reset_disable = false;
  1957. return E1000_SUCCESS;
  1958. }
  1959. /*****************************************************************************
  1960. *
  1961. * This function sets the lplu state according to the active flag. When
  1962. * activating lplu this function also disables smart speed and vise versa.
  1963. * lplu will not be activated unless the device autonegotiation advertisment
  1964. * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
  1965. * hw: Struct containing variables accessed by shared code
  1966. * active - true to enable lplu false to disable lplu.
  1967. *
  1968. * returns: - E1000_ERR_PHY if fail to read/write the PHY
  1969. * E1000_SUCCESS at any other case.
  1970. *
  1971. ****************************************************************************/
  1972. static int32_t
  1973. e1000_set_d3_lplu_state(struct e1000_hw *hw, bool active)
  1974. {
  1975. uint32_t phy_ctrl = 0;
  1976. int32_t ret_val;
  1977. uint16_t phy_data;
  1978. DEBUGFUNC();
  1979. if (hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2
  1980. && hw->phy_type != e1000_phy_igp_3)
  1981. return E1000_SUCCESS;
  1982. /* During driver activity LPLU should not be used or it will attain link
  1983. * from the lowest speeds starting from 10Mbps. The capability is used
  1984. * for Dx transitions and states */
  1985. if (hw->mac_type == e1000_82541_rev_2
  1986. || hw->mac_type == e1000_82547_rev_2) {
  1987. ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
  1988. &phy_data);
  1989. if (ret_val)
  1990. return ret_val;
  1991. } else if (hw->mac_type == e1000_ich8lan) {
  1992. /* MAC writes into PHY register based on the state transition
  1993. * and start auto-negotiation. SW driver can overwrite the
  1994. * settings in CSR PHY power control E1000_PHY_CTRL register. */
  1995. phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
  1996. } else {
  1997. ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  1998. &phy_data);
  1999. if (ret_val)
  2000. return ret_val;
  2001. }
  2002. if (!active) {
  2003. if (hw->mac_type == e1000_82541_rev_2 ||
  2004. hw->mac_type == e1000_82547_rev_2) {
  2005. phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
  2006. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
  2007. phy_data);
  2008. if (ret_val)
  2009. return ret_val;
  2010. } else {
  2011. if (hw->mac_type == e1000_ich8lan) {
  2012. phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
  2013. E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
  2014. } else {
  2015. phy_data &= ~IGP02E1000_PM_D3_LPLU;
  2016. ret_val = e1000_write_phy_reg(hw,
  2017. IGP02E1000_PHY_POWER_MGMT, phy_data);
  2018. if (ret_val)
  2019. return ret_val;
  2020. }
  2021. }
  2022. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
  2023. * Dx states where the power conservation is most important. During
  2024. * driver activity we should enable SmartSpeed, so performance is
  2025. * maintained. */
  2026. if (hw->smart_speed == e1000_smart_speed_on) {
  2027. ret_val = e1000_read_phy_reg(hw,
  2028. IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  2029. if (ret_val)
  2030. return ret_val;
  2031. phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
  2032. ret_val = e1000_write_phy_reg(hw,
  2033. IGP01E1000_PHY_PORT_CONFIG, phy_data);
  2034. if (ret_val)
  2035. return ret_val;
  2036. } else if (hw->smart_speed == e1000_smart_speed_off) {
  2037. ret_val = e1000_read_phy_reg(hw,
  2038. IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  2039. if (ret_val)
  2040. return ret_val;
  2041. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2042. ret_val = e1000_write_phy_reg(hw,
  2043. IGP01E1000_PHY_PORT_CONFIG, phy_data);
  2044. if (ret_val)
  2045. return ret_val;
  2046. }
  2047. } else if ((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT)
  2048. || (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL) ||
  2049. (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
  2050. if (hw->mac_type == e1000_82541_rev_2 ||
  2051. hw->mac_type == e1000_82547_rev_2) {
  2052. phy_data |= IGP01E1000_GMII_FLEX_SPD;
  2053. ret_val = e1000_write_phy_reg(hw,
  2054. IGP01E1000_GMII_FIFO, phy_data);
  2055. if (ret_val)
  2056. return ret_val;
  2057. } else {
  2058. if (hw->mac_type == e1000_ich8lan) {
  2059. phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
  2060. E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
  2061. } else {
  2062. phy_data |= IGP02E1000_PM_D3_LPLU;
  2063. ret_val = e1000_write_phy_reg(hw,
  2064. IGP02E1000_PHY_POWER_MGMT, phy_data);
  2065. if (ret_val)
  2066. return ret_val;
  2067. }
  2068. }
  2069. /* When LPLU is enabled we should disable SmartSpeed */
  2070. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  2071. &phy_data);
  2072. if (ret_val)
  2073. return ret_val;
  2074. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2075. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  2076. phy_data);
  2077. if (ret_val)
  2078. return ret_val;
  2079. }
  2080. return E1000_SUCCESS;
  2081. }
  2082. /*****************************************************************************
  2083. *
  2084. * This function sets the lplu d0 state according to the active flag. When
  2085. * activating lplu this function also disables smart speed and vise versa.
  2086. * lplu will not be activated unless the device autonegotiation advertisment
  2087. * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
  2088. * hw: Struct containing variables accessed by shared code
  2089. * active - true to enable lplu false to disable lplu.
  2090. *
  2091. * returns: - E1000_ERR_PHY if fail to read/write the PHY
  2092. * E1000_SUCCESS at any other case.
  2093. *
  2094. ****************************************************************************/
  2095. static int32_t
  2096. e1000_set_d0_lplu_state(struct e1000_hw *hw, bool active)
  2097. {
  2098. uint32_t phy_ctrl = 0;
  2099. int32_t ret_val;
  2100. uint16_t phy_data;
  2101. DEBUGFUNC();
  2102. if (hw->mac_type <= e1000_82547_rev_2)
  2103. return E1000_SUCCESS;
  2104. if (hw->mac_type == e1000_ich8lan) {
  2105. phy_ctrl = E1000_READ_REG(hw, PHY_CTRL);
  2106. } else if (hw->mac_type == e1000_igb) {
  2107. phy_ctrl = E1000_READ_REG(hw, I210_PHY_CTRL);
  2108. } else {
  2109. ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  2110. &phy_data);
  2111. if (ret_val)
  2112. return ret_val;
  2113. }
  2114. if (!active) {
  2115. if (hw->mac_type == e1000_ich8lan) {
  2116. phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
  2117. E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
  2118. } else if (hw->mac_type == e1000_igb) {
  2119. phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
  2120. E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl);
  2121. } else {
  2122. phy_data &= ~IGP02E1000_PM_D0_LPLU;
  2123. ret_val = e1000_write_phy_reg(hw,
  2124. IGP02E1000_PHY_POWER_MGMT, phy_data);
  2125. if (ret_val)
  2126. return ret_val;
  2127. }
  2128. if (hw->mac_type == e1000_igb)
  2129. return E1000_SUCCESS;
  2130. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
  2131. * Dx states where the power conservation is most important. During
  2132. * driver activity we should enable SmartSpeed, so performance is
  2133. * maintained. */
  2134. if (hw->smart_speed == e1000_smart_speed_on) {
  2135. ret_val = e1000_read_phy_reg(hw,
  2136. IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  2137. if (ret_val)
  2138. return ret_val;
  2139. phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
  2140. ret_val = e1000_write_phy_reg(hw,
  2141. IGP01E1000_PHY_PORT_CONFIG, phy_data);
  2142. if (ret_val)
  2143. return ret_val;
  2144. } else if (hw->smart_speed == e1000_smart_speed_off) {
  2145. ret_val = e1000_read_phy_reg(hw,
  2146. IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  2147. if (ret_val)
  2148. return ret_val;
  2149. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2150. ret_val = e1000_write_phy_reg(hw,
  2151. IGP01E1000_PHY_PORT_CONFIG, phy_data);
  2152. if (ret_val)
  2153. return ret_val;
  2154. }
  2155. } else {
  2156. if (hw->mac_type == e1000_ich8lan) {
  2157. phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
  2158. E1000_WRITE_REG(hw, PHY_CTRL, phy_ctrl);
  2159. } else if (hw->mac_type == e1000_igb) {
  2160. phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
  2161. E1000_WRITE_REG(hw, I210_PHY_CTRL, phy_ctrl);
  2162. } else {
  2163. phy_data |= IGP02E1000_PM_D0_LPLU;
  2164. ret_val = e1000_write_phy_reg(hw,
  2165. IGP02E1000_PHY_POWER_MGMT, phy_data);
  2166. if (ret_val)
  2167. return ret_val;
  2168. }
  2169. if (hw->mac_type == e1000_igb)
  2170. return E1000_SUCCESS;
  2171. /* When LPLU is enabled we should disable SmartSpeed */
  2172. ret_val = e1000_read_phy_reg(hw,
  2173. IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  2174. if (ret_val)
  2175. return ret_val;
  2176. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2177. ret_val = e1000_write_phy_reg(hw,
  2178. IGP01E1000_PHY_PORT_CONFIG, phy_data);
  2179. if (ret_val)
  2180. return ret_val;
  2181. }
  2182. return E1000_SUCCESS;
  2183. }
  2184. /********************************************************************
  2185. * Copper link setup for e1000_phy_igp series.
  2186. *
  2187. * hw - Struct containing variables accessed by shared code
  2188. *********************************************************************/
  2189. static int32_t
  2190. e1000_copper_link_igp_setup(struct e1000_hw *hw)
  2191. {
  2192. uint32_t led_ctrl;
  2193. int32_t ret_val;
  2194. uint16_t phy_data;
  2195. DEBUGFUNC();
  2196. if (hw->phy_reset_disable)
  2197. return E1000_SUCCESS;
  2198. ret_val = e1000_phy_reset(hw);
  2199. if (ret_val) {
  2200. DEBUGOUT("Error Resetting the PHY\n");
  2201. return ret_val;
  2202. }
  2203. /* Wait 15ms for MAC to configure PHY from eeprom settings */
  2204. mdelay(15);
  2205. if (hw->mac_type != e1000_ich8lan) {
  2206. /* Configure activity LED after PHY reset */
  2207. led_ctrl = E1000_READ_REG(hw, LEDCTL);
  2208. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  2209. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  2210. E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
  2211. }
  2212. /* The NVM settings will configure LPLU in D3 for IGP2 and IGP3 PHYs */
  2213. if (hw->phy_type == e1000_phy_igp) {
  2214. /* disable lplu d3 during driver init */
  2215. ret_val = e1000_set_d3_lplu_state(hw, false);
  2216. if (ret_val) {
  2217. DEBUGOUT("Error Disabling LPLU D3\n");
  2218. return ret_val;
  2219. }
  2220. }
  2221. /* disable lplu d0 during driver init */
  2222. ret_val = e1000_set_d0_lplu_state(hw, false);
  2223. if (ret_val) {
  2224. DEBUGOUT("Error Disabling LPLU D0\n");
  2225. return ret_val;
  2226. }
  2227. /* Configure mdi-mdix settings */
  2228. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
  2229. if (ret_val)
  2230. return ret_val;
  2231. if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  2232. hw->dsp_config_state = e1000_dsp_config_disabled;
  2233. /* Force MDI for earlier revs of the IGP PHY */
  2234. phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX
  2235. | IGP01E1000_PSCR_FORCE_MDI_MDIX);
  2236. hw->mdix = 1;
  2237. } else {
  2238. hw->dsp_config_state = e1000_dsp_config_enabled;
  2239. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  2240. switch (hw->mdix) {
  2241. case 1:
  2242. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  2243. break;
  2244. case 2:
  2245. phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
  2246. break;
  2247. case 0:
  2248. default:
  2249. phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
  2250. break;
  2251. }
  2252. }
  2253. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
  2254. if (ret_val)
  2255. return ret_val;
  2256. /* set auto-master slave resolution settings */
  2257. if (hw->autoneg) {
  2258. e1000_ms_type phy_ms_setting = hw->master_slave;
  2259. if (hw->ffe_config_state == e1000_ffe_config_active)
  2260. hw->ffe_config_state = e1000_ffe_config_enabled;
  2261. if (hw->dsp_config_state == e1000_dsp_config_activated)
  2262. hw->dsp_config_state = e1000_dsp_config_enabled;
  2263. /* when autonegotiation advertisment is only 1000Mbps then we
  2264. * should disable SmartSpeed and enable Auto MasterSlave
  2265. * resolution as hardware default. */
  2266. if (hw->autoneg_advertised == ADVERTISE_1000_FULL) {
  2267. /* Disable SmartSpeed */
  2268. ret_val = e1000_read_phy_reg(hw,
  2269. IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  2270. if (ret_val)
  2271. return ret_val;
  2272. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2273. ret_val = e1000_write_phy_reg(hw,
  2274. IGP01E1000_PHY_PORT_CONFIG, phy_data);
  2275. if (ret_val)
  2276. return ret_val;
  2277. /* Set auto Master/Slave resolution process */
  2278. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
  2279. &phy_data);
  2280. if (ret_val)
  2281. return ret_val;
  2282. phy_data &= ~CR_1000T_MS_ENABLE;
  2283. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
  2284. phy_data);
  2285. if (ret_val)
  2286. return ret_val;
  2287. }
  2288. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
  2289. if (ret_val)
  2290. return ret_val;
  2291. /* load defaults for future use */
  2292. hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
  2293. ((phy_data & CR_1000T_MS_VALUE) ?
  2294. e1000_ms_force_master :
  2295. e1000_ms_force_slave) :
  2296. e1000_ms_auto;
  2297. switch (phy_ms_setting) {
  2298. case e1000_ms_force_master:
  2299. phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
  2300. break;
  2301. case e1000_ms_force_slave:
  2302. phy_data |= CR_1000T_MS_ENABLE;
  2303. phy_data &= ~(CR_1000T_MS_VALUE);
  2304. break;
  2305. case e1000_ms_auto:
  2306. phy_data &= ~CR_1000T_MS_ENABLE;
  2307. default:
  2308. break;
  2309. }
  2310. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
  2311. if (ret_val)
  2312. return ret_val;
  2313. }
  2314. return E1000_SUCCESS;
  2315. }
  2316. /*****************************************************************************
  2317. * This function checks the mode of the firmware.
  2318. *
  2319. * returns - true when the mode is IAMT or false.
  2320. ****************************************************************************/
  2321. bool
  2322. e1000_check_mng_mode(struct e1000_hw *hw)
  2323. {
  2324. uint32_t fwsm;
  2325. DEBUGFUNC();
  2326. fwsm = E1000_READ_REG(hw, FWSM);
  2327. if (hw->mac_type == e1000_ich8lan) {
  2328. if ((fwsm & E1000_FWSM_MODE_MASK) ==
  2329. (E1000_MNG_ICH_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
  2330. return true;
  2331. } else if ((fwsm & E1000_FWSM_MODE_MASK) ==
  2332. (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
  2333. return true;
  2334. return false;
  2335. }
  2336. static int32_t
  2337. e1000_write_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t data)
  2338. {
  2339. uint16_t swfw = E1000_SWFW_PHY0_SM;
  2340. uint32_t reg_val;
  2341. DEBUGFUNC();
  2342. if (e1000_is_second_port(hw))
  2343. swfw = E1000_SWFW_PHY1_SM;
  2344. if (e1000_swfw_sync_acquire(hw, swfw))
  2345. return -E1000_ERR_SWFW_SYNC;
  2346. reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT)
  2347. & E1000_KUMCTRLSTA_OFFSET) | data;
  2348. E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
  2349. udelay(2);
  2350. return E1000_SUCCESS;
  2351. }
  2352. static int32_t
  2353. e1000_read_kmrn_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t *data)
  2354. {
  2355. uint16_t swfw = E1000_SWFW_PHY0_SM;
  2356. uint32_t reg_val;
  2357. DEBUGFUNC();
  2358. if (e1000_is_second_port(hw))
  2359. swfw = E1000_SWFW_PHY1_SM;
  2360. if (e1000_swfw_sync_acquire(hw, swfw)) {
  2361. debug("%s[%i]\n", __func__, __LINE__);
  2362. return -E1000_ERR_SWFW_SYNC;
  2363. }
  2364. /* Write register address */
  2365. reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
  2366. E1000_KUMCTRLSTA_OFFSET) | E1000_KUMCTRLSTA_REN;
  2367. E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
  2368. udelay(2);
  2369. /* Read the data returned */
  2370. reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
  2371. *data = (uint16_t)reg_val;
  2372. return E1000_SUCCESS;
  2373. }
  2374. /********************************************************************
  2375. * Copper link setup for e1000_phy_gg82563 series.
  2376. *
  2377. * hw - Struct containing variables accessed by shared code
  2378. *********************************************************************/
  2379. static int32_t
  2380. e1000_copper_link_ggp_setup(struct e1000_hw *hw)
  2381. {
  2382. int32_t ret_val;
  2383. uint16_t phy_data;
  2384. uint32_t reg_data;
  2385. DEBUGFUNC();
  2386. if (!hw->phy_reset_disable) {
  2387. /* Enable CRS on TX for half-duplex operation. */
  2388. ret_val = e1000_read_phy_reg(hw,
  2389. GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
  2390. if (ret_val)
  2391. return ret_val;
  2392. phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
  2393. /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
  2394. phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
  2395. ret_val = e1000_write_phy_reg(hw,
  2396. GG82563_PHY_MAC_SPEC_CTRL, phy_data);
  2397. if (ret_val)
  2398. return ret_val;
  2399. /* Options:
  2400. * MDI/MDI-X = 0 (default)
  2401. * 0 - Auto for all speeds
  2402. * 1 - MDI mode
  2403. * 2 - MDI-X mode
  2404. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  2405. */
  2406. ret_val = e1000_read_phy_reg(hw,
  2407. GG82563_PHY_SPEC_CTRL, &phy_data);
  2408. if (ret_val)
  2409. return ret_val;
  2410. phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
  2411. switch (hw->mdix) {
  2412. case 1:
  2413. phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
  2414. break;
  2415. case 2:
  2416. phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
  2417. break;
  2418. case 0:
  2419. default:
  2420. phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
  2421. break;
  2422. }
  2423. /* Options:
  2424. * disable_polarity_correction = 0 (default)
  2425. * Automatic Correction for Reversed Cable Polarity
  2426. * 0 - Disabled
  2427. * 1 - Enabled
  2428. */
  2429. phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
  2430. ret_val = e1000_write_phy_reg(hw,
  2431. GG82563_PHY_SPEC_CTRL, phy_data);
  2432. if (ret_val)
  2433. return ret_val;
  2434. /* SW Reset the PHY so all changes take effect */
  2435. ret_val = e1000_phy_reset(hw);
  2436. if (ret_val) {
  2437. DEBUGOUT("Error Resetting the PHY\n");
  2438. return ret_val;
  2439. }
  2440. } /* phy_reset_disable */
  2441. if (hw->mac_type == e1000_80003es2lan) {
  2442. /* Bypass RX and TX FIFO's */
  2443. ret_val = e1000_write_kmrn_reg(hw,
  2444. E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
  2445. E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS
  2446. | E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
  2447. if (ret_val)
  2448. return ret_val;
  2449. ret_val = e1000_read_phy_reg(hw,
  2450. GG82563_PHY_SPEC_CTRL_2, &phy_data);
  2451. if (ret_val)
  2452. return ret_val;
  2453. phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
  2454. ret_val = e1000_write_phy_reg(hw,
  2455. GG82563_PHY_SPEC_CTRL_2, phy_data);
  2456. if (ret_val)
  2457. return ret_val;
  2458. reg_data = E1000_READ_REG(hw, CTRL_EXT);
  2459. reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
  2460. E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
  2461. ret_val = e1000_read_phy_reg(hw,
  2462. GG82563_PHY_PWR_MGMT_CTRL, &phy_data);
  2463. if (ret_val)
  2464. return ret_val;
  2465. /* Do not init these registers when the HW is in IAMT mode, since the
  2466. * firmware will have already initialized them. We only initialize
  2467. * them if the HW is not in IAMT mode.
  2468. */
  2469. if (e1000_check_mng_mode(hw) == false) {
  2470. /* Enable Electrical Idle on the PHY */
  2471. phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
  2472. ret_val = e1000_write_phy_reg(hw,
  2473. GG82563_PHY_PWR_MGMT_CTRL, phy_data);
  2474. if (ret_val)
  2475. return ret_val;
  2476. ret_val = e1000_read_phy_reg(hw,
  2477. GG82563_PHY_KMRN_MODE_CTRL, &phy_data);
  2478. if (ret_val)
  2479. return ret_val;
  2480. phy_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
  2481. ret_val = e1000_write_phy_reg(hw,
  2482. GG82563_PHY_KMRN_MODE_CTRL, phy_data);
  2483. if (ret_val)
  2484. return ret_val;
  2485. }
  2486. /* Workaround: Disable padding in Kumeran interface in the MAC
  2487. * and in the PHY to avoid CRC errors.
  2488. */
  2489. ret_val = e1000_read_phy_reg(hw,
  2490. GG82563_PHY_INBAND_CTRL, &phy_data);
  2491. if (ret_val)
  2492. return ret_val;
  2493. phy_data |= GG82563_ICR_DIS_PADDING;
  2494. ret_val = e1000_write_phy_reg(hw,
  2495. GG82563_PHY_INBAND_CTRL, phy_data);
  2496. if (ret_val)
  2497. return ret_val;
  2498. }
  2499. return E1000_SUCCESS;
  2500. }
  2501. /********************************************************************
  2502. * Copper link setup for e1000_phy_m88 series.
  2503. *
  2504. * hw - Struct containing variables accessed by shared code
  2505. *********************************************************************/
  2506. static int32_t
  2507. e1000_copper_link_mgp_setup(struct e1000_hw *hw)
  2508. {
  2509. int32_t ret_val;
  2510. uint16_t phy_data;
  2511. DEBUGFUNC();
  2512. if (hw->phy_reset_disable)
  2513. return E1000_SUCCESS;
  2514. /* Enable CRS on TX. This must be set for half-duplex operation. */
  2515. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  2516. if (ret_val)
  2517. return ret_val;
  2518. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  2519. /* Options:
  2520. * MDI/MDI-X = 0 (default)
  2521. * 0 - Auto for all speeds
  2522. * 1 - MDI mode
  2523. * 2 - MDI-X mode
  2524. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  2525. */
  2526. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  2527. switch (hw->mdix) {
  2528. case 1:
  2529. phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
  2530. break;
  2531. case 2:
  2532. phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
  2533. break;
  2534. case 3:
  2535. phy_data |= M88E1000_PSCR_AUTO_X_1000T;
  2536. break;
  2537. case 0:
  2538. default:
  2539. phy_data |= M88E1000_PSCR_AUTO_X_MODE;
  2540. break;
  2541. }
  2542. /* Options:
  2543. * disable_polarity_correction = 0 (default)
  2544. * Automatic Correction for Reversed Cable Polarity
  2545. * 0 - Disabled
  2546. * 1 - Enabled
  2547. */
  2548. phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
  2549. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  2550. if (ret_val)
  2551. return ret_val;
  2552. if (hw->phy_revision < M88E1011_I_REV_4) {
  2553. /* Force TX_CLK in the Extended PHY Specific Control Register
  2554. * to 25MHz clock.
  2555. */
  2556. ret_val = e1000_read_phy_reg(hw,
  2557. M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  2558. if (ret_val)
  2559. return ret_val;
  2560. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  2561. if ((hw->phy_revision == E1000_REVISION_2) &&
  2562. (hw->phy_id == M88E1111_I_PHY_ID)) {
  2563. /* Vidalia Phy, set the downshift counter to 5x */
  2564. phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
  2565. phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
  2566. ret_val = e1000_write_phy_reg(hw,
  2567. M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  2568. if (ret_val)
  2569. return ret_val;
  2570. } else {
  2571. /* Configure Master and Slave downshift values */
  2572. phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK
  2573. | M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
  2574. phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X
  2575. | M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
  2576. ret_val = e1000_write_phy_reg(hw,
  2577. M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  2578. if (ret_val)
  2579. return ret_val;
  2580. }
  2581. }
  2582. /* SW Reset the PHY so all changes take effect */
  2583. ret_val = e1000_phy_reset(hw);
  2584. if (ret_val) {
  2585. DEBUGOUT("Error Resetting the PHY\n");
  2586. return ret_val;
  2587. }
  2588. return E1000_SUCCESS;
  2589. }
  2590. /********************************************************************
  2591. * Setup auto-negotiation and flow control advertisements,
  2592. * and then perform auto-negotiation.
  2593. *
  2594. * hw - Struct containing variables accessed by shared code
  2595. *********************************************************************/
  2596. static int32_t
  2597. e1000_copper_link_autoneg(struct e1000_hw *hw)
  2598. {
  2599. int32_t ret_val;
  2600. uint16_t phy_data;
  2601. DEBUGFUNC();
  2602. /* Perform some bounds checking on the hw->autoneg_advertised
  2603. * parameter. If this variable is zero, then set it to the default.
  2604. */
  2605. hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
  2606. /* If autoneg_advertised is zero, we assume it was not defaulted
  2607. * by the calling code so we set to advertise full capability.
  2608. */
  2609. if (hw->autoneg_advertised == 0)
  2610. hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  2611. /* IFE phy only supports 10/100 */
  2612. if (hw->phy_type == e1000_phy_ife)
  2613. hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
  2614. DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
  2615. ret_val = e1000_phy_setup_autoneg(hw);
  2616. if (ret_val) {
  2617. DEBUGOUT("Error Setting up Auto-Negotiation\n");
  2618. return ret_val;
  2619. }
  2620. DEBUGOUT("Restarting Auto-Neg\n");
  2621. /* Restart auto-negotiation by setting the Auto Neg Enable bit and
  2622. * the Auto Neg Restart bit in the PHY control register.
  2623. */
  2624. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
  2625. if (ret_val)
  2626. return ret_val;
  2627. phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
  2628. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
  2629. if (ret_val)
  2630. return ret_val;
  2631. /* Does the user want to wait for Auto-Neg to complete here, or
  2632. * check at a later time (for example, callback routine).
  2633. */
  2634. /* If we do not wait for autonegtation to complete I
  2635. * do not see a valid link status.
  2636. * wait_autoneg_complete = 1 .
  2637. */
  2638. if (hw->wait_autoneg_complete) {
  2639. ret_val = e1000_wait_autoneg(hw);
  2640. if (ret_val) {
  2641. DEBUGOUT("Error while waiting for autoneg"
  2642. "to complete\n");
  2643. return ret_val;
  2644. }
  2645. }
  2646. hw->get_link_status = true;
  2647. return E1000_SUCCESS;
  2648. }
  2649. /******************************************************************************
  2650. * Config the MAC and the PHY after link is up.
  2651. * 1) Set up the MAC to the current PHY speed/duplex
  2652. * if we are on 82543. If we
  2653. * are on newer silicon, we only need to configure
  2654. * collision distance in the Transmit Control Register.
  2655. * 2) Set up flow control on the MAC to that established with
  2656. * the link partner.
  2657. * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
  2658. *
  2659. * hw - Struct containing variables accessed by shared code
  2660. ******************************************************************************/
  2661. static int32_t
  2662. e1000_copper_link_postconfig(struct e1000_hw *hw)
  2663. {
  2664. int32_t ret_val;
  2665. DEBUGFUNC();
  2666. if (hw->mac_type >= e1000_82544) {
  2667. e1000_config_collision_dist(hw);
  2668. } else {
  2669. ret_val = e1000_config_mac_to_phy(hw);
  2670. if (ret_val) {
  2671. DEBUGOUT("Error configuring MAC to PHY settings\n");
  2672. return ret_val;
  2673. }
  2674. }
  2675. ret_val = e1000_config_fc_after_link_up(hw);
  2676. if (ret_val) {
  2677. DEBUGOUT("Error Configuring Flow Control\n");
  2678. return ret_val;
  2679. }
  2680. return E1000_SUCCESS;
  2681. }
  2682. /******************************************************************************
  2683. * Detects which PHY is present and setup the speed and duplex
  2684. *
  2685. * hw - Struct containing variables accessed by shared code
  2686. ******************************************************************************/
  2687. static int
  2688. e1000_setup_copper_link(struct eth_device *nic)
  2689. {
  2690. struct e1000_hw *hw = nic->priv;
  2691. int32_t ret_val;
  2692. uint16_t i;
  2693. uint16_t phy_data;
  2694. uint16_t reg_data;
  2695. DEBUGFUNC();
  2696. switch (hw->mac_type) {
  2697. case e1000_80003es2lan:
  2698. case e1000_ich8lan:
  2699. /* Set the mac to wait the maximum time between each
  2700. * iteration and increase the max iterations when
  2701. * polling the phy; this fixes erroneous timeouts at 10Mbps. */
  2702. ret_val = e1000_write_kmrn_reg(hw,
  2703. GG82563_REG(0x34, 4), 0xFFFF);
  2704. if (ret_val)
  2705. return ret_val;
  2706. ret_val = e1000_read_kmrn_reg(hw,
  2707. GG82563_REG(0x34, 9), &reg_data);
  2708. if (ret_val)
  2709. return ret_val;
  2710. reg_data |= 0x3F;
  2711. ret_val = e1000_write_kmrn_reg(hw,
  2712. GG82563_REG(0x34, 9), reg_data);
  2713. if (ret_val)
  2714. return ret_val;
  2715. default:
  2716. break;
  2717. }
  2718. /* Check if it is a valid PHY and set PHY mode if necessary. */
  2719. ret_val = e1000_copper_link_preconfig(hw);
  2720. if (ret_val)
  2721. return ret_val;
  2722. switch (hw->mac_type) {
  2723. case e1000_80003es2lan:
  2724. /* Kumeran registers are written-only */
  2725. reg_data =
  2726. E1000_KUMCTRLSTA_INB_CTRL_LINK_STATUS_TX_TIMEOUT_DEFAULT;
  2727. reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
  2728. ret_val = e1000_write_kmrn_reg(hw,
  2729. E1000_KUMCTRLSTA_OFFSET_INB_CTRL, reg_data);
  2730. if (ret_val)
  2731. return ret_val;
  2732. break;
  2733. default:
  2734. break;
  2735. }
  2736. if (hw->phy_type == e1000_phy_igp ||
  2737. hw->phy_type == e1000_phy_igp_3 ||
  2738. hw->phy_type == e1000_phy_igp_2) {
  2739. ret_val = e1000_copper_link_igp_setup(hw);
  2740. if (ret_val)
  2741. return ret_val;
  2742. } else if (hw->phy_type == e1000_phy_m88 ||
  2743. hw->phy_type == e1000_phy_igb) {
  2744. ret_val = e1000_copper_link_mgp_setup(hw);
  2745. if (ret_val)
  2746. return ret_val;
  2747. } else if (hw->phy_type == e1000_phy_gg82563) {
  2748. ret_val = e1000_copper_link_ggp_setup(hw);
  2749. if (ret_val)
  2750. return ret_val;
  2751. }
  2752. /* always auto */
  2753. /* Setup autoneg and flow control advertisement
  2754. * and perform autonegotiation */
  2755. ret_val = e1000_copper_link_autoneg(hw);
  2756. if (ret_val)
  2757. return ret_val;
  2758. /* Check link status. Wait up to 100 microseconds for link to become
  2759. * valid.
  2760. */
  2761. for (i = 0; i < 10; i++) {
  2762. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2763. if (ret_val)
  2764. return ret_val;
  2765. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2766. if (ret_val)
  2767. return ret_val;
  2768. if (phy_data & MII_SR_LINK_STATUS) {
  2769. /* Config the MAC and PHY after link is up */
  2770. ret_val = e1000_copper_link_postconfig(hw);
  2771. if (ret_val)
  2772. return ret_val;
  2773. DEBUGOUT("Valid link established!!!\n");
  2774. return E1000_SUCCESS;
  2775. }
  2776. udelay(10);
  2777. }
  2778. DEBUGOUT("Unable to establish link!!!\n");
  2779. return E1000_SUCCESS;
  2780. }
  2781. /******************************************************************************
  2782. * Configures PHY autoneg and flow control advertisement settings
  2783. *
  2784. * hw - Struct containing variables accessed by shared code
  2785. ******************************************************************************/
  2786. int32_t
  2787. e1000_phy_setup_autoneg(struct e1000_hw *hw)
  2788. {
  2789. int32_t ret_val;
  2790. uint16_t mii_autoneg_adv_reg;
  2791. uint16_t mii_1000t_ctrl_reg;
  2792. DEBUGFUNC();
  2793. /* Read the MII Auto-Neg Advertisement Register (Address 4). */
  2794. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
  2795. if (ret_val)
  2796. return ret_val;
  2797. if (hw->phy_type != e1000_phy_ife) {
  2798. /* Read the MII 1000Base-T Control Register (Address 9). */
  2799. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL,
  2800. &mii_1000t_ctrl_reg);
  2801. if (ret_val)
  2802. return ret_val;
  2803. } else
  2804. mii_1000t_ctrl_reg = 0;
  2805. /* Need to parse both autoneg_advertised and fc and set up
  2806. * the appropriate PHY registers. First we will parse for
  2807. * autoneg_advertised software override. Since we can advertise
  2808. * a plethora of combinations, we need to check each bit
  2809. * individually.
  2810. */
  2811. /* First we clear all the 10/100 mb speed bits in the Auto-Neg
  2812. * Advertisement Register (Address 4) and the 1000 mb speed bits in
  2813. * the 1000Base-T Control Register (Address 9).
  2814. */
  2815. mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
  2816. mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
  2817. DEBUGOUT("autoneg_advertised %x\n", hw->autoneg_advertised);
  2818. /* Do we want to advertise 10 Mb Half Duplex? */
  2819. if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
  2820. DEBUGOUT("Advertise 10mb Half duplex\n");
  2821. mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
  2822. }
  2823. /* Do we want to advertise 10 Mb Full Duplex? */
  2824. if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
  2825. DEBUGOUT("Advertise 10mb Full duplex\n");
  2826. mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
  2827. }
  2828. /* Do we want to advertise 100 Mb Half Duplex? */
  2829. if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
  2830. DEBUGOUT("Advertise 100mb Half duplex\n");
  2831. mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
  2832. }
  2833. /* Do we want to advertise 100 Mb Full Duplex? */
  2834. if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
  2835. DEBUGOUT("Advertise 100mb Full duplex\n");
  2836. mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
  2837. }
  2838. /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
  2839. if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
  2840. DEBUGOUT
  2841. ("Advertise 1000mb Half duplex requested, request denied!\n");
  2842. }
  2843. /* Do we want to advertise 1000 Mb Full Duplex? */
  2844. if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
  2845. DEBUGOUT("Advertise 1000mb Full duplex\n");
  2846. mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
  2847. }
  2848. /* Check for a software override of the flow control settings, and
  2849. * setup the PHY advertisement registers accordingly. If
  2850. * auto-negotiation is enabled, then software will have to set the
  2851. * "PAUSE" bits to the correct value in the Auto-Negotiation
  2852. * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
  2853. *
  2854. * The possible values of the "fc" parameter are:
  2855. * 0: Flow control is completely disabled
  2856. * 1: Rx flow control is enabled (we can receive pause frames
  2857. * but not send pause frames).
  2858. * 2: Tx flow control is enabled (we can send pause frames
  2859. * but we do not support receiving pause frames).
  2860. * 3: Both Rx and TX flow control (symmetric) are enabled.
  2861. * other: No software override. The flow control configuration
  2862. * in the EEPROM is used.
  2863. */
  2864. switch (hw->fc) {
  2865. case e1000_fc_none: /* 0 */
  2866. /* Flow control (RX & TX) is completely disabled by a
  2867. * software over-ride.
  2868. */
  2869. mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  2870. break;
  2871. case e1000_fc_rx_pause: /* 1 */
  2872. /* RX Flow control is enabled, and TX Flow control is
  2873. * disabled, by a software over-ride.
  2874. */
  2875. /* Since there really isn't a way to advertise that we are
  2876. * capable of RX Pause ONLY, we will advertise that we
  2877. * support both symmetric and asymmetric RX PAUSE. Later
  2878. * (in e1000_config_fc_after_link_up) we will disable the
  2879. *hw's ability to send PAUSE frames.
  2880. */
  2881. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  2882. break;
  2883. case e1000_fc_tx_pause: /* 2 */
  2884. /* TX Flow control is enabled, and RX Flow control is
  2885. * disabled, by a software over-ride.
  2886. */
  2887. mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
  2888. mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
  2889. break;
  2890. case e1000_fc_full: /* 3 */
  2891. /* Flow control (both RX and TX) is enabled by a software
  2892. * over-ride.
  2893. */
  2894. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  2895. break;
  2896. default:
  2897. DEBUGOUT("Flow control param set incorrectly\n");
  2898. return -E1000_ERR_CONFIG;
  2899. }
  2900. ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
  2901. if (ret_val)
  2902. return ret_val;
  2903. DEBUGOUT("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
  2904. if (hw->phy_type != e1000_phy_ife) {
  2905. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL,
  2906. mii_1000t_ctrl_reg);
  2907. if (ret_val)
  2908. return ret_val;
  2909. }
  2910. return E1000_SUCCESS;
  2911. }
  2912. /******************************************************************************
  2913. * Sets the collision distance in the Transmit Control register
  2914. *
  2915. * hw - Struct containing variables accessed by shared code
  2916. *
  2917. * Link should have been established previously. Reads the speed and duplex
  2918. * information from the Device Status register.
  2919. ******************************************************************************/
  2920. static void
  2921. e1000_config_collision_dist(struct e1000_hw *hw)
  2922. {
  2923. uint32_t tctl, coll_dist;
  2924. DEBUGFUNC();
  2925. if (hw->mac_type < e1000_82543)
  2926. coll_dist = E1000_COLLISION_DISTANCE_82542;
  2927. else
  2928. coll_dist = E1000_COLLISION_DISTANCE;
  2929. tctl = E1000_READ_REG(hw, TCTL);
  2930. tctl &= ~E1000_TCTL_COLD;
  2931. tctl |= coll_dist << E1000_COLD_SHIFT;
  2932. E1000_WRITE_REG(hw, TCTL, tctl);
  2933. E1000_WRITE_FLUSH(hw);
  2934. }
  2935. /******************************************************************************
  2936. * Sets MAC speed and duplex settings to reflect the those in the PHY
  2937. *
  2938. * hw - Struct containing variables accessed by shared code
  2939. * mii_reg - data to write to the MII control register
  2940. *
  2941. * The contents of the PHY register containing the needed information need to
  2942. * be passed in.
  2943. ******************************************************************************/
  2944. static int
  2945. e1000_config_mac_to_phy(struct e1000_hw *hw)
  2946. {
  2947. uint32_t ctrl;
  2948. uint16_t phy_data;
  2949. DEBUGFUNC();
  2950. /* Read the Device Control Register and set the bits to Force Speed
  2951. * and Duplex.
  2952. */
  2953. ctrl = E1000_READ_REG(hw, CTRL);
  2954. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  2955. ctrl &= ~(E1000_CTRL_ILOS);
  2956. ctrl |= (E1000_CTRL_SPD_SEL);
  2957. /* Set up duplex in the Device Control and Transmit Control
  2958. * registers depending on negotiated values.
  2959. */
  2960. if (e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data) < 0) {
  2961. DEBUGOUT("PHY Read Error\n");
  2962. return -E1000_ERR_PHY;
  2963. }
  2964. if (phy_data & M88E1000_PSSR_DPLX)
  2965. ctrl |= E1000_CTRL_FD;
  2966. else
  2967. ctrl &= ~E1000_CTRL_FD;
  2968. e1000_config_collision_dist(hw);
  2969. /* Set up speed in the Device Control register depending on
  2970. * negotiated values.
  2971. */
  2972. if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
  2973. ctrl |= E1000_CTRL_SPD_1000;
  2974. else if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
  2975. ctrl |= E1000_CTRL_SPD_100;
  2976. /* Write the configured values back to the Device Control Reg. */
  2977. E1000_WRITE_REG(hw, CTRL, ctrl);
  2978. return 0;
  2979. }
  2980. /******************************************************************************
  2981. * Forces the MAC's flow control settings.
  2982. *
  2983. * hw - Struct containing variables accessed by shared code
  2984. *
  2985. * Sets the TFCE and RFCE bits in the device control register to reflect
  2986. * the adapter settings. TFCE and RFCE need to be explicitly set by
  2987. * software when a Copper PHY is used because autonegotiation is managed
  2988. * by the PHY rather than the MAC. Software must also configure these
  2989. * bits when link is forced on a fiber connection.
  2990. *****************************************************************************/
  2991. static int
  2992. e1000_force_mac_fc(struct e1000_hw *hw)
  2993. {
  2994. uint32_t ctrl;
  2995. DEBUGFUNC();
  2996. /* Get the current configuration of the Device Control Register */
  2997. ctrl = E1000_READ_REG(hw, CTRL);
  2998. /* Because we didn't get link via the internal auto-negotiation
  2999. * mechanism (we either forced link or we got link via PHY
  3000. * auto-neg), we have to manually enable/disable transmit an
  3001. * receive flow control.
  3002. *
  3003. * The "Case" statement below enables/disable flow control
  3004. * according to the "hw->fc" parameter.
  3005. *
  3006. * The possible values of the "fc" parameter are:
  3007. * 0: Flow control is completely disabled
  3008. * 1: Rx flow control is enabled (we can receive pause
  3009. * frames but not send pause frames).
  3010. * 2: Tx flow control is enabled (we can send pause frames
  3011. * frames but we do not receive pause frames).
  3012. * 3: Both Rx and TX flow control (symmetric) is enabled.
  3013. * other: No other values should be possible at this point.
  3014. */
  3015. switch (hw->fc) {
  3016. case e1000_fc_none:
  3017. ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
  3018. break;
  3019. case e1000_fc_rx_pause:
  3020. ctrl &= (~E1000_CTRL_TFCE);
  3021. ctrl |= E1000_CTRL_RFCE;
  3022. break;
  3023. case e1000_fc_tx_pause:
  3024. ctrl &= (~E1000_CTRL_RFCE);
  3025. ctrl |= E1000_CTRL_TFCE;
  3026. break;
  3027. case e1000_fc_full:
  3028. ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
  3029. break;
  3030. default:
  3031. DEBUGOUT("Flow control param set incorrectly\n");
  3032. return -E1000_ERR_CONFIG;
  3033. }
  3034. /* Disable TX Flow Control for 82542 (rev 2.0) */
  3035. if (hw->mac_type == e1000_82542_rev2_0)
  3036. ctrl &= (~E1000_CTRL_TFCE);
  3037. E1000_WRITE_REG(hw, CTRL, ctrl);
  3038. return 0;
  3039. }
  3040. /******************************************************************************
  3041. * Configures flow control settings after link is established
  3042. *
  3043. * hw - Struct containing variables accessed by shared code
  3044. *
  3045. * Should be called immediately after a valid link has been established.
  3046. * Forces MAC flow control settings if link was forced. When in MII/GMII mode
  3047. * and autonegotiation is enabled, the MAC flow control settings will be set
  3048. * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
  3049. * and RFCE bits will be automaticaly set to the negotiated flow control mode.
  3050. *****************************************************************************/
  3051. static int32_t
  3052. e1000_config_fc_after_link_up(struct e1000_hw *hw)
  3053. {
  3054. int32_t ret_val;
  3055. uint16_t mii_status_reg;
  3056. uint16_t mii_nway_adv_reg;
  3057. uint16_t mii_nway_lp_ability_reg;
  3058. uint16_t speed;
  3059. uint16_t duplex;
  3060. DEBUGFUNC();
  3061. /* Check for the case where we have fiber media and auto-neg failed
  3062. * so we had to force link. In this case, we need to force the
  3063. * configuration of the MAC to match the "fc" parameter.
  3064. */
  3065. if (((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed))
  3066. || ((hw->media_type == e1000_media_type_internal_serdes)
  3067. && (hw->autoneg_failed))
  3068. || ((hw->media_type == e1000_media_type_copper)
  3069. && (!hw->autoneg))) {
  3070. ret_val = e1000_force_mac_fc(hw);
  3071. if (ret_val < 0) {
  3072. DEBUGOUT("Error forcing flow control settings\n");
  3073. return ret_val;
  3074. }
  3075. }
  3076. /* Check for the case where we have copper media and auto-neg is
  3077. * enabled. In this case, we need to check and see if Auto-Neg
  3078. * has completed, and if so, how the PHY and link partner has
  3079. * flow control configured.
  3080. */
  3081. if (hw->media_type == e1000_media_type_copper) {
  3082. /* Read the MII Status Register and check to see if AutoNeg
  3083. * has completed. We read this twice because this reg has
  3084. * some "sticky" (latched) bits.
  3085. */
  3086. if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
  3087. DEBUGOUT("PHY Read Error\n");
  3088. return -E1000_ERR_PHY;
  3089. }
  3090. if (e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg) < 0) {
  3091. DEBUGOUT("PHY Read Error\n");
  3092. return -E1000_ERR_PHY;
  3093. }
  3094. if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
  3095. /* The AutoNeg process has completed, so we now need to
  3096. * read both the Auto Negotiation Advertisement Register
  3097. * (Address 4) and the Auto_Negotiation Base Page Ability
  3098. * Register (Address 5) to determine how flow control was
  3099. * negotiated.
  3100. */
  3101. if (e1000_read_phy_reg
  3102. (hw, PHY_AUTONEG_ADV, &mii_nway_adv_reg) < 0) {
  3103. DEBUGOUT("PHY Read Error\n");
  3104. return -E1000_ERR_PHY;
  3105. }
  3106. if (e1000_read_phy_reg
  3107. (hw, PHY_LP_ABILITY,
  3108. &mii_nway_lp_ability_reg) < 0) {
  3109. DEBUGOUT("PHY Read Error\n");
  3110. return -E1000_ERR_PHY;
  3111. }
  3112. /* Two bits in the Auto Negotiation Advertisement Register
  3113. * (Address 4) and two bits in the Auto Negotiation Base
  3114. * Page Ability Register (Address 5) determine flow control
  3115. * for both the PHY and the link partner. The following
  3116. * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
  3117. * 1999, describes these PAUSE resolution bits and how flow
  3118. * control is determined based upon these settings.
  3119. * NOTE: DC = Don't Care
  3120. *
  3121. * LOCAL DEVICE | LINK PARTNER
  3122. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
  3123. *-------|---------|-------|---------|--------------------
  3124. * 0 | 0 | DC | DC | e1000_fc_none
  3125. * 0 | 1 | 0 | DC | e1000_fc_none
  3126. * 0 | 1 | 1 | 0 | e1000_fc_none
  3127. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  3128. * 1 | 0 | 0 | DC | e1000_fc_none
  3129. * 1 | DC | 1 | DC | e1000_fc_full
  3130. * 1 | 1 | 0 | 0 | e1000_fc_none
  3131. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  3132. *
  3133. */
  3134. /* Are both PAUSE bits set to 1? If so, this implies
  3135. * Symmetric Flow Control is enabled at both ends. The
  3136. * ASM_DIR bits are irrelevant per the spec.
  3137. *
  3138. * For Symmetric Flow Control:
  3139. *
  3140. * LOCAL DEVICE | LINK PARTNER
  3141. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  3142. *-------|---------|-------|---------|--------------------
  3143. * 1 | DC | 1 | DC | e1000_fc_full
  3144. *
  3145. */
  3146. if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  3147. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
  3148. /* Now we need to check if the user selected RX ONLY
  3149. * of pause frames. In this case, we had to advertise
  3150. * FULL flow control because we could not advertise RX
  3151. * ONLY. Hence, we must now check to see if we need to
  3152. * turn OFF the TRANSMISSION of PAUSE frames.
  3153. */
  3154. if (hw->original_fc == e1000_fc_full) {
  3155. hw->fc = e1000_fc_full;
  3156. DEBUGOUT("Flow Control = FULL.\r\n");
  3157. } else {
  3158. hw->fc = e1000_fc_rx_pause;
  3159. DEBUGOUT
  3160. ("Flow Control = RX PAUSE frames only.\r\n");
  3161. }
  3162. }
  3163. /* For receiving PAUSE frames ONLY.
  3164. *
  3165. * LOCAL DEVICE | LINK PARTNER
  3166. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  3167. *-------|---------|-------|---------|--------------------
  3168. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  3169. *
  3170. */
  3171. else if (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  3172. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  3173. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  3174. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
  3175. {
  3176. hw->fc = e1000_fc_tx_pause;
  3177. DEBUGOUT
  3178. ("Flow Control = TX PAUSE frames only.\r\n");
  3179. }
  3180. /* For transmitting PAUSE frames ONLY.
  3181. *
  3182. * LOCAL DEVICE | LINK PARTNER
  3183. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  3184. *-------|---------|-------|---------|--------------------
  3185. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  3186. *
  3187. */
  3188. else if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  3189. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  3190. !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  3191. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR))
  3192. {
  3193. hw->fc = e1000_fc_rx_pause;
  3194. DEBUGOUT
  3195. ("Flow Control = RX PAUSE frames only.\r\n");
  3196. }
  3197. /* Per the IEEE spec, at this point flow control should be
  3198. * disabled. However, we want to consider that we could
  3199. * be connected to a legacy switch that doesn't advertise
  3200. * desired flow control, but can be forced on the link
  3201. * partner. So if we advertised no flow control, that is
  3202. * what we will resolve to. If we advertised some kind of
  3203. * receive capability (Rx Pause Only or Full Flow Control)
  3204. * and the link partner advertised none, we will configure
  3205. * ourselves to enable Rx Flow Control only. We can do
  3206. * this safely for two reasons: If the link partner really
  3207. * didn't want flow control enabled, and we enable Rx, no
  3208. * harm done since we won't be receiving any PAUSE frames
  3209. * anyway. If the intent on the link partner was to have
  3210. * flow control enabled, then by us enabling RX only, we
  3211. * can at least receive pause frames and process them.
  3212. * This is a good idea because in most cases, since we are
  3213. * predominantly a server NIC, more times than not we will
  3214. * be asked to delay transmission of packets than asking
  3215. * our link partner to pause transmission of frames.
  3216. */
  3217. else if (hw->original_fc == e1000_fc_none ||
  3218. hw->original_fc == e1000_fc_tx_pause) {
  3219. hw->fc = e1000_fc_none;
  3220. DEBUGOUT("Flow Control = NONE.\r\n");
  3221. } else {
  3222. hw->fc = e1000_fc_rx_pause;
  3223. DEBUGOUT
  3224. ("Flow Control = RX PAUSE frames only.\r\n");
  3225. }
  3226. /* Now we need to do one last check... If we auto-
  3227. * negotiated to HALF DUPLEX, flow control should not be
  3228. * enabled per IEEE 802.3 spec.
  3229. */
  3230. e1000_get_speed_and_duplex(hw, &speed, &duplex);
  3231. if (duplex == HALF_DUPLEX)
  3232. hw->fc = e1000_fc_none;
  3233. /* Now we call a subroutine to actually force the MAC
  3234. * controller to use the correct flow control settings.
  3235. */
  3236. ret_val = e1000_force_mac_fc(hw);
  3237. if (ret_val < 0) {
  3238. DEBUGOUT
  3239. ("Error forcing flow control settings\n");
  3240. return ret_val;
  3241. }
  3242. } else {
  3243. DEBUGOUT
  3244. ("Copper PHY and Auto Neg has not completed.\r\n");
  3245. }
  3246. }
  3247. return E1000_SUCCESS;
  3248. }
  3249. /******************************************************************************
  3250. * Checks to see if the link status of the hardware has changed.
  3251. *
  3252. * hw - Struct containing variables accessed by shared code
  3253. *
  3254. * Called by any function that needs to check the link status of the adapter.
  3255. *****************************************************************************/
  3256. static int
  3257. e1000_check_for_link(struct eth_device *nic)
  3258. {
  3259. struct e1000_hw *hw = nic->priv;
  3260. uint32_t rxcw;
  3261. uint32_t ctrl;
  3262. uint32_t status;
  3263. uint32_t rctl;
  3264. uint32_t signal;
  3265. int32_t ret_val;
  3266. uint16_t phy_data;
  3267. uint16_t lp_capability;
  3268. DEBUGFUNC();
  3269. /* On adapters with a MAC newer that 82544, SW Defineable pin 1 will be
  3270. * set when the optics detect a signal. On older adapters, it will be
  3271. * cleared when there is a signal
  3272. */
  3273. ctrl = E1000_READ_REG(hw, CTRL);
  3274. if ((hw->mac_type > e1000_82544) && !(ctrl & E1000_CTRL_ILOS))
  3275. signal = E1000_CTRL_SWDPIN1;
  3276. else
  3277. signal = 0;
  3278. status = E1000_READ_REG(hw, STATUS);
  3279. rxcw = E1000_READ_REG(hw, RXCW);
  3280. DEBUGOUT("ctrl: %#08x status %#08x rxcw %#08x\n", ctrl, status, rxcw);
  3281. /* If we have a copper PHY then we only want to go out to the PHY
  3282. * registers to see if Auto-Neg has completed and/or if our link
  3283. * status has changed. The get_link_status flag will be set if we
  3284. * receive a Link Status Change interrupt or we have Rx Sequence
  3285. * Errors.
  3286. */
  3287. if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
  3288. /* First we want to see if the MII Status Register reports
  3289. * link. If so, then we want to get the current speed/duplex
  3290. * of the PHY.
  3291. * Read the register twice since the link bit is sticky.
  3292. */
  3293. if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  3294. DEBUGOUT("PHY Read Error\n");
  3295. return -E1000_ERR_PHY;
  3296. }
  3297. if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  3298. DEBUGOUT("PHY Read Error\n");
  3299. return -E1000_ERR_PHY;
  3300. }
  3301. if (phy_data & MII_SR_LINK_STATUS) {
  3302. hw->get_link_status = false;
  3303. } else {
  3304. /* No link detected */
  3305. return -E1000_ERR_NOLINK;
  3306. }
  3307. /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
  3308. * have Si on board that is 82544 or newer, Auto
  3309. * Speed Detection takes care of MAC speed/duplex
  3310. * configuration. So we only need to configure Collision
  3311. * Distance in the MAC. Otherwise, we need to force
  3312. * speed/duplex on the MAC to the current PHY speed/duplex
  3313. * settings.
  3314. */
  3315. if (hw->mac_type >= e1000_82544)
  3316. e1000_config_collision_dist(hw);
  3317. else {
  3318. ret_val = e1000_config_mac_to_phy(hw);
  3319. if (ret_val < 0) {
  3320. DEBUGOUT
  3321. ("Error configuring MAC to PHY settings\n");
  3322. return ret_val;
  3323. }
  3324. }
  3325. /* Configure Flow Control now that Auto-Neg has completed. First, we
  3326. * need to restore the desired flow control settings because we may
  3327. * have had to re-autoneg with a different link partner.
  3328. */
  3329. ret_val = e1000_config_fc_after_link_up(hw);
  3330. if (ret_val < 0) {
  3331. DEBUGOUT("Error configuring flow control\n");
  3332. return ret_val;
  3333. }
  3334. /* At this point we know that we are on copper and we have
  3335. * auto-negotiated link. These are conditions for checking the link
  3336. * parter capability register. We use the link partner capability to
  3337. * determine if TBI Compatibility needs to be turned on or off. If
  3338. * the link partner advertises any speed in addition to Gigabit, then
  3339. * we assume that they are GMII-based, and TBI compatibility is not
  3340. * needed. If no other speeds are advertised, we assume the link
  3341. * partner is TBI-based, and we turn on TBI Compatibility.
  3342. */
  3343. if (hw->tbi_compatibility_en) {
  3344. if (e1000_read_phy_reg
  3345. (hw, PHY_LP_ABILITY, &lp_capability) < 0) {
  3346. DEBUGOUT("PHY Read Error\n");
  3347. return -E1000_ERR_PHY;
  3348. }
  3349. if (lp_capability & (NWAY_LPAR_10T_HD_CAPS |
  3350. NWAY_LPAR_10T_FD_CAPS |
  3351. NWAY_LPAR_100TX_HD_CAPS |
  3352. NWAY_LPAR_100TX_FD_CAPS |
  3353. NWAY_LPAR_100T4_CAPS)) {
  3354. /* If our link partner advertises anything in addition to
  3355. * gigabit, we do not need to enable TBI compatibility.
  3356. */
  3357. if (hw->tbi_compatibility_on) {
  3358. /* If we previously were in the mode, turn it off. */
  3359. rctl = E1000_READ_REG(hw, RCTL);
  3360. rctl &= ~E1000_RCTL_SBP;
  3361. E1000_WRITE_REG(hw, RCTL, rctl);
  3362. hw->tbi_compatibility_on = false;
  3363. }
  3364. } else {
  3365. /* If TBI compatibility is was previously off, turn it on. For
  3366. * compatibility with a TBI link partner, we will store bad
  3367. * packets. Some frames have an additional byte on the end and
  3368. * will look like CRC errors to to the hardware.
  3369. */
  3370. if (!hw->tbi_compatibility_on) {
  3371. hw->tbi_compatibility_on = true;
  3372. rctl = E1000_READ_REG(hw, RCTL);
  3373. rctl |= E1000_RCTL_SBP;
  3374. E1000_WRITE_REG(hw, RCTL, rctl);
  3375. }
  3376. }
  3377. }
  3378. }
  3379. /* If we don't have link (auto-negotiation failed or link partner cannot
  3380. * auto-negotiate), the cable is plugged in (we have signal), and our
  3381. * link partner is not trying to auto-negotiate with us (we are receiving
  3382. * idles or data), we need to force link up. We also need to give
  3383. * auto-negotiation time to complete, in case the cable was just plugged
  3384. * in. The autoneg_failed flag does this.
  3385. */
  3386. else if ((hw->media_type == e1000_media_type_fiber) &&
  3387. (!(status & E1000_STATUS_LU)) &&
  3388. ((ctrl & E1000_CTRL_SWDPIN1) == signal) &&
  3389. (!(rxcw & E1000_RXCW_C))) {
  3390. if (hw->autoneg_failed == 0) {
  3391. hw->autoneg_failed = 1;
  3392. return 0;
  3393. }
  3394. DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\r\n");
  3395. /* Disable auto-negotiation in the TXCW register */
  3396. E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
  3397. /* Force link-up and also force full-duplex. */
  3398. ctrl = E1000_READ_REG(hw, CTRL);
  3399. ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
  3400. E1000_WRITE_REG(hw, CTRL, ctrl);
  3401. /* Configure Flow Control after forcing link up. */
  3402. ret_val = e1000_config_fc_after_link_up(hw);
  3403. if (ret_val < 0) {
  3404. DEBUGOUT("Error configuring flow control\n");
  3405. return ret_val;
  3406. }
  3407. }
  3408. /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
  3409. * auto-negotiation in the TXCW register and disable forced link in the
  3410. * Device Control register in an attempt to auto-negotiate with our link
  3411. * partner.
  3412. */
  3413. else if ((hw->media_type == e1000_media_type_fiber) &&
  3414. (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
  3415. DEBUGOUT
  3416. ("RXing /C/, enable AutoNeg and stop forcing link.\r\n");
  3417. E1000_WRITE_REG(hw, TXCW, hw->txcw);
  3418. E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
  3419. }
  3420. return 0;
  3421. }
  3422. /******************************************************************************
  3423. * Configure the MAC-to-PHY interface for 10/100Mbps
  3424. *
  3425. * hw - Struct containing variables accessed by shared code
  3426. ******************************************************************************/
  3427. static int32_t
  3428. e1000_configure_kmrn_for_10_100(struct e1000_hw *hw, uint16_t duplex)
  3429. {
  3430. int32_t ret_val = E1000_SUCCESS;
  3431. uint32_t tipg;
  3432. uint16_t reg_data;
  3433. DEBUGFUNC();
  3434. reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
  3435. ret_val = e1000_write_kmrn_reg(hw,
  3436. E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
  3437. if (ret_val)
  3438. return ret_val;
  3439. /* Configure Transmit Inter-Packet Gap */
  3440. tipg = E1000_READ_REG(hw, TIPG);
  3441. tipg &= ~E1000_TIPG_IPGT_MASK;
  3442. tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
  3443. E1000_WRITE_REG(hw, TIPG, tipg);
  3444. ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
  3445. if (ret_val)
  3446. return ret_val;
  3447. if (duplex == HALF_DUPLEX)
  3448. reg_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
  3449. else
  3450. reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
  3451. ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
  3452. return ret_val;
  3453. }
  3454. static int32_t
  3455. e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
  3456. {
  3457. int32_t ret_val = E1000_SUCCESS;
  3458. uint16_t reg_data;
  3459. uint32_t tipg;
  3460. DEBUGFUNC();
  3461. reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
  3462. ret_val = e1000_write_kmrn_reg(hw,
  3463. E1000_KUMCTRLSTA_OFFSET_HD_CTRL, reg_data);
  3464. if (ret_val)
  3465. return ret_val;
  3466. /* Configure Transmit Inter-Packet Gap */
  3467. tipg = E1000_READ_REG(hw, TIPG);
  3468. tipg &= ~E1000_TIPG_IPGT_MASK;
  3469. tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
  3470. E1000_WRITE_REG(hw, TIPG, tipg);
  3471. ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, &reg_data);
  3472. if (ret_val)
  3473. return ret_val;
  3474. reg_data &= ~GG82563_KMCR_PASS_FALSE_CARRIER;
  3475. ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL, reg_data);
  3476. return ret_val;
  3477. }
  3478. /******************************************************************************
  3479. * Detects the current speed and duplex settings of the hardware.
  3480. *
  3481. * hw - Struct containing variables accessed by shared code
  3482. * speed - Speed of the connection
  3483. * duplex - Duplex setting of the connection
  3484. *****************************************************************************/
  3485. static int
  3486. e1000_get_speed_and_duplex(struct e1000_hw *hw, uint16_t *speed,
  3487. uint16_t *duplex)
  3488. {
  3489. uint32_t status;
  3490. int32_t ret_val;
  3491. uint16_t phy_data;
  3492. DEBUGFUNC();
  3493. if (hw->mac_type >= e1000_82543) {
  3494. status = E1000_READ_REG(hw, STATUS);
  3495. if (status & E1000_STATUS_SPEED_1000) {
  3496. *speed = SPEED_1000;
  3497. DEBUGOUT("1000 Mbs, ");
  3498. } else if (status & E1000_STATUS_SPEED_100) {
  3499. *speed = SPEED_100;
  3500. DEBUGOUT("100 Mbs, ");
  3501. } else {
  3502. *speed = SPEED_10;
  3503. DEBUGOUT("10 Mbs, ");
  3504. }
  3505. if (status & E1000_STATUS_FD) {
  3506. *duplex = FULL_DUPLEX;
  3507. DEBUGOUT("Full Duplex\r\n");
  3508. } else {
  3509. *duplex = HALF_DUPLEX;
  3510. DEBUGOUT(" Half Duplex\r\n");
  3511. }
  3512. } else {
  3513. DEBUGOUT("1000 Mbs, Full Duplex\r\n");
  3514. *speed = SPEED_1000;
  3515. *duplex = FULL_DUPLEX;
  3516. }
  3517. /* IGP01 PHY may advertise full duplex operation after speed downgrade
  3518. * even if it is operating at half duplex. Here we set the duplex
  3519. * settings to match the duplex in the link partner's capabilities.
  3520. */
  3521. if (hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
  3522. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
  3523. if (ret_val)
  3524. return ret_val;
  3525. if (!(phy_data & NWAY_ER_LP_NWAY_CAPS))
  3526. *duplex = HALF_DUPLEX;
  3527. else {
  3528. ret_val = e1000_read_phy_reg(hw,
  3529. PHY_LP_ABILITY, &phy_data);
  3530. if (ret_val)
  3531. return ret_val;
  3532. if ((*speed == SPEED_100 &&
  3533. !(phy_data & NWAY_LPAR_100TX_FD_CAPS))
  3534. || (*speed == SPEED_10
  3535. && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
  3536. *duplex = HALF_DUPLEX;
  3537. }
  3538. }
  3539. if ((hw->mac_type == e1000_80003es2lan) &&
  3540. (hw->media_type == e1000_media_type_copper)) {
  3541. if (*speed == SPEED_1000)
  3542. ret_val = e1000_configure_kmrn_for_1000(hw);
  3543. else
  3544. ret_val = e1000_configure_kmrn_for_10_100(hw, *duplex);
  3545. if (ret_val)
  3546. return ret_val;
  3547. }
  3548. return E1000_SUCCESS;
  3549. }
  3550. /******************************************************************************
  3551. * Blocks until autoneg completes or times out (~4.5 seconds)
  3552. *
  3553. * hw - Struct containing variables accessed by shared code
  3554. ******************************************************************************/
  3555. static int
  3556. e1000_wait_autoneg(struct e1000_hw *hw)
  3557. {
  3558. uint16_t i;
  3559. uint16_t phy_data;
  3560. DEBUGFUNC();
  3561. DEBUGOUT("Waiting for Auto-Neg to complete.\n");
  3562. /* We will wait for autoneg to complete or 4.5 seconds to expire. */
  3563. for (i = PHY_AUTO_NEG_TIME; i > 0; i--) {
  3564. /* Read the MII Status Register and wait for Auto-Neg
  3565. * Complete bit to be set.
  3566. */
  3567. if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  3568. DEBUGOUT("PHY Read Error\n");
  3569. return -E1000_ERR_PHY;
  3570. }
  3571. if (e1000_read_phy_reg(hw, PHY_STATUS, &phy_data) < 0) {
  3572. DEBUGOUT("PHY Read Error\n");
  3573. return -E1000_ERR_PHY;
  3574. }
  3575. if (phy_data & MII_SR_AUTONEG_COMPLETE) {
  3576. DEBUGOUT("Auto-Neg complete.\n");
  3577. return 0;
  3578. }
  3579. mdelay(100);
  3580. }
  3581. DEBUGOUT("Auto-Neg timedout.\n");
  3582. return -E1000_ERR_TIMEOUT;
  3583. }
  3584. /******************************************************************************
  3585. * Raises the Management Data Clock
  3586. *
  3587. * hw - Struct containing variables accessed by shared code
  3588. * ctrl - Device control register's current value
  3589. ******************************************************************************/
  3590. static void
  3591. e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
  3592. {
  3593. /* Raise the clock input to the Management Data Clock (by setting the MDC
  3594. * bit), and then delay 2 microseconds.
  3595. */
  3596. E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
  3597. E1000_WRITE_FLUSH(hw);
  3598. udelay(2);
  3599. }
  3600. /******************************************************************************
  3601. * Lowers the Management Data Clock
  3602. *
  3603. * hw - Struct containing variables accessed by shared code
  3604. * ctrl - Device control register's current value
  3605. ******************************************************************************/
  3606. static void
  3607. e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t * ctrl)
  3608. {
  3609. /* Lower the clock input to the Management Data Clock (by clearing the MDC
  3610. * bit), and then delay 2 microseconds.
  3611. */
  3612. E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
  3613. E1000_WRITE_FLUSH(hw);
  3614. udelay(2);
  3615. }
  3616. /******************************************************************************
  3617. * Shifts data bits out to the PHY
  3618. *
  3619. * hw - Struct containing variables accessed by shared code
  3620. * data - Data to send out to the PHY
  3621. * count - Number of bits to shift out
  3622. *
  3623. * Bits are shifted out in MSB to LSB order.
  3624. ******************************************************************************/
  3625. static void
  3626. e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data, uint16_t count)
  3627. {
  3628. uint32_t ctrl;
  3629. uint32_t mask;
  3630. /* We need to shift "count" number of bits out to the PHY. So, the value
  3631. * in the "data" parameter will be shifted out to the PHY one bit at a
  3632. * time. In order to do this, "data" must be broken down into bits.
  3633. */
  3634. mask = 0x01;
  3635. mask <<= (count - 1);
  3636. ctrl = E1000_READ_REG(hw, CTRL);
  3637. /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
  3638. ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
  3639. while (mask) {
  3640. /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
  3641. * then raising and lowering the Management Data Clock. A "0" is
  3642. * shifted out to the PHY by setting the MDIO bit to "0" and then
  3643. * raising and lowering the clock.
  3644. */
  3645. if (data & mask)
  3646. ctrl |= E1000_CTRL_MDIO;
  3647. else
  3648. ctrl &= ~E1000_CTRL_MDIO;
  3649. E1000_WRITE_REG(hw, CTRL, ctrl);
  3650. E1000_WRITE_FLUSH(hw);
  3651. udelay(2);
  3652. e1000_raise_mdi_clk(hw, &ctrl);
  3653. e1000_lower_mdi_clk(hw, &ctrl);
  3654. mask = mask >> 1;
  3655. }
  3656. }
  3657. /******************************************************************************
  3658. * Shifts data bits in from the PHY
  3659. *
  3660. * hw - Struct containing variables accessed by shared code
  3661. *
  3662. * Bits are shifted in in MSB to LSB order.
  3663. ******************************************************************************/
  3664. static uint16_t
  3665. e1000_shift_in_mdi_bits(struct e1000_hw *hw)
  3666. {
  3667. uint32_t ctrl;
  3668. uint16_t data = 0;
  3669. uint8_t i;
  3670. /* In order to read a register from the PHY, we need to shift in a total
  3671. * of 18 bits from the PHY. The first two bit (turnaround) times are used
  3672. * to avoid contention on the MDIO pin when a read operation is performed.
  3673. * These two bits are ignored by us and thrown away. Bits are "shifted in"
  3674. * by raising the input to the Management Data Clock (setting the MDC bit),
  3675. * and then reading the value of the MDIO bit.
  3676. */
  3677. ctrl = E1000_READ_REG(hw, CTRL);
  3678. /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
  3679. ctrl &= ~E1000_CTRL_MDIO_DIR;
  3680. ctrl &= ~E1000_CTRL_MDIO;
  3681. E1000_WRITE_REG(hw, CTRL, ctrl);
  3682. E1000_WRITE_FLUSH(hw);
  3683. /* Raise and Lower the clock before reading in the data. This accounts for
  3684. * the turnaround bits. The first clock occurred when we clocked out the
  3685. * last bit of the Register Address.
  3686. */
  3687. e1000_raise_mdi_clk(hw, &ctrl);
  3688. e1000_lower_mdi_clk(hw, &ctrl);
  3689. for (data = 0, i = 0; i < 16; i++) {
  3690. data = data << 1;
  3691. e1000_raise_mdi_clk(hw, &ctrl);
  3692. ctrl = E1000_READ_REG(hw, CTRL);
  3693. /* Check to see if we shifted in a "1". */
  3694. if (ctrl & E1000_CTRL_MDIO)
  3695. data |= 1;
  3696. e1000_lower_mdi_clk(hw, &ctrl);
  3697. }
  3698. e1000_raise_mdi_clk(hw, &ctrl);
  3699. e1000_lower_mdi_clk(hw, &ctrl);
  3700. return data;
  3701. }
  3702. /*****************************************************************************
  3703. * Reads the value from a PHY register
  3704. *
  3705. * hw - Struct containing variables accessed by shared code
  3706. * reg_addr - address of the PHY register to read
  3707. ******************************************************************************/
  3708. static int
  3709. e1000_read_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t * phy_data)
  3710. {
  3711. uint32_t i;
  3712. uint32_t mdic = 0;
  3713. const uint32_t phy_addr = 1;
  3714. if (reg_addr > MAX_PHY_REG_ADDRESS) {
  3715. DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
  3716. return -E1000_ERR_PARAM;
  3717. }
  3718. if (hw->mac_type > e1000_82543) {
  3719. /* Set up Op-code, Phy Address, and register address in the MDI
  3720. * Control register. The MAC will take care of interfacing with the
  3721. * PHY to retrieve the desired data.
  3722. */
  3723. mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
  3724. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  3725. (E1000_MDIC_OP_READ));
  3726. E1000_WRITE_REG(hw, MDIC, mdic);
  3727. /* Poll the ready bit to see if the MDI read completed */
  3728. for (i = 0; i < 64; i++) {
  3729. udelay(10);
  3730. mdic = E1000_READ_REG(hw, MDIC);
  3731. if (mdic & E1000_MDIC_READY)
  3732. break;
  3733. }
  3734. if (!(mdic & E1000_MDIC_READY)) {
  3735. DEBUGOUT("MDI Read did not complete\n");
  3736. return -E1000_ERR_PHY;
  3737. }
  3738. if (mdic & E1000_MDIC_ERROR) {
  3739. DEBUGOUT("MDI Error\n");
  3740. return -E1000_ERR_PHY;
  3741. }
  3742. *phy_data = (uint16_t) mdic;
  3743. } else {
  3744. /* We must first send a preamble through the MDIO pin to signal the
  3745. * beginning of an MII instruction. This is done by sending 32
  3746. * consecutive "1" bits.
  3747. */
  3748. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  3749. /* Now combine the next few fields that are required for a read
  3750. * operation. We use this method instead of calling the
  3751. * e1000_shift_out_mdi_bits routine five different times. The format of
  3752. * a MII read instruction consists of a shift out of 14 bits and is
  3753. * defined as follows:
  3754. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
  3755. * followed by a shift in of 18 bits. This first two bits shifted in
  3756. * are TurnAround bits used to avoid contention on the MDIO pin when a
  3757. * READ operation is performed. These two bits are thrown away
  3758. * followed by a shift in of 16 bits which contains the desired data.
  3759. */
  3760. mdic = ((reg_addr) | (phy_addr << 5) |
  3761. (PHY_OP_READ << 10) | (PHY_SOF << 12));
  3762. e1000_shift_out_mdi_bits(hw, mdic, 14);
  3763. /* Now that we've shifted out the read command to the MII, we need to
  3764. * "shift in" the 16-bit value (18 total bits) of the requested PHY
  3765. * register address.
  3766. */
  3767. *phy_data = e1000_shift_in_mdi_bits(hw);
  3768. }
  3769. return 0;
  3770. }
  3771. /******************************************************************************
  3772. * Writes a value to a PHY register
  3773. *
  3774. * hw - Struct containing variables accessed by shared code
  3775. * reg_addr - address of the PHY register to write
  3776. * data - data to write to the PHY
  3777. ******************************************************************************/
  3778. static int
  3779. e1000_write_phy_reg(struct e1000_hw *hw, uint32_t reg_addr, uint16_t phy_data)
  3780. {
  3781. uint32_t i;
  3782. uint32_t mdic = 0;
  3783. const uint32_t phy_addr = 1;
  3784. if (reg_addr > MAX_PHY_REG_ADDRESS) {
  3785. DEBUGOUT("PHY Address %d is out of range\n", reg_addr);
  3786. return -E1000_ERR_PARAM;
  3787. }
  3788. if (hw->mac_type > e1000_82543) {
  3789. /* Set up Op-code, Phy Address, register address, and data intended
  3790. * for the PHY register in the MDI Control register. The MAC will take
  3791. * care of interfacing with the PHY to send the desired data.
  3792. */
  3793. mdic = (((uint32_t) phy_data) |
  3794. (reg_addr << E1000_MDIC_REG_SHIFT) |
  3795. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  3796. (E1000_MDIC_OP_WRITE));
  3797. E1000_WRITE_REG(hw, MDIC, mdic);
  3798. /* Poll the ready bit to see if the MDI read completed */
  3799. for (i = 0; i < 64; i++) {
  3800. udelay(10);
  3801. mdic = E1000_READ_REG(hw, MDIC);
  3802. if (mdic & E1000_MDIC_READY)
  3803. break;
  3804. }
  3805. if (!(mdic & E1000_MDIC_READY)) {
  3806. DEBUGOUT("MDI Write did not complete\n");
  3807. return -E1000_ERR_PHY;
  3808. }
  3809. } else {
  3810. /* We'll need to use the SW defined pins to shift the write command
  3811. * out to the PHY. We first send a preamble to the PHY to signal the
  3812. * beginning of the MII instruction. This is done by sending 32
  3813. * consecutive "1" bits.
  3814. */
  3815. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  3816. /* Now combine the remaining required fields that will indicate a
  3817. * write operation. We use this method instead of calling the
  3818. * e1000_shift_out_mdi_bits routine for each field in the command. The
  3819. * format of a MII write instruction is as follows:
  3820. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
  3821. */
  3822. mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
  3823. (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
  3824. mdic <<= 16;
  3825. mdic |= (uint32_t) phy_data;
  3826. e1000_shift_out_mdi_bits(hw, mdic, 32);
  3827. }
  3828. return 0;
  3829. }
  3830. /******************************************************************************
  3831. * Checks if PHY reset is blocked due to SOL/IDER session, for example.
  3832. * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
  3833. * the caller to figure out how to deal with it.
  3834. *
  3835. * hw - Struct containing variables accessed by shared code
  3836. *
  3837. * returns: - E1000_BLK_PHY_RESET
  3838. * E1000_SUCCESS
  3839. *
  3840. *****************************************************************************/
  3841. int32_t
  3842. e1000_check_phy_reset_block(struct e1000_hw *hw)
  3843. {
  3844. uint32_t manc = 0;
  3845. uint32_t fwsm = 0;
  3846. if (hw->mac_type == e1000_ich8lan) {
  3847. fwsm = E1000_READ_REG(hw, FWSM);
  3848. return (fwsm & E1000_FWSM_RSPCIPHY) ? E1000_SUCCESS
  3849. : E1000_BLK_PHY_RESET;
  3850. }
  3851. if (hw->mac_type > e1000_82547_rev_2)
  3852. manc = E1000_READ_REG(hw, MANC);
  3853. return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
  3854. E1000_BLK_PHY_RESET : E1000_SUCCESS;
  3855. }
  3856. /***************************************************************************
  3857. * Checks if the PHY configuration is done
  3858. *
  3859. * hw: Struct containing variables accessed by shared code
  3860. *
  3861. * returns: - E1000_ERR_RESET if fail to reset MAC
  3862. * E1000_SUCCESS at any other case.
  3863. *
  3864. ***************************************************************************/
  3865. static int32_t
  3866. e1000_get_phy_cfg_done(struct e1000_hw *hw)
  3867. {
  3868. int32_t timeout = PHY_CFG_TIMEOUT;
  3869. uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
  3870. DEBUGFUNC();
  3871. switch (hw->mac_type) {
  3872. default:
  3873. mdelay(10);
  3874. break;
  3875. case e1000_80003es2lan:
  3876. /* Separate *_CFG_DONE_* bit for each port */
  3877. if (e1000_is_second_port(hw))
  3878. cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
  3879. /* Fall Through */
  3880. case e1000_82571:
  3881. case e1000_82572:
  3882. case e1000_igb:
  3883. while (timeout) {
  3884. if (hw->mac_type == e1000_igb) {
  3885. if (E1000_READ_REG(hw, I210_EEMNGCTL) & cfg_mask)
  3886. break;
  3887. } else {
  3888. if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
  3889. break;
  3890. }
  3891. mdelay(1);
  3892. timeout--;
  3893. }
  3894. if (!timeout) {
  3895. DEBUGOUT("MNG configuration cycle has not "
  3896. "completed.\n");
  3897. return -E1000_ERR_RESET;
  3898. }
  3899. break;
  3900. }
  3901. return E1000_SUCCESS;
  3902. }
  3903. /******************************************************************************
  3904. * Returns the PHY to the power-on reset state
  3905. *
  3906. * hw - Struct containing variables accessed by shared code
  3907. ******************************************************************************/
  3908. int32_t
  3909. e1000_phy_hw_reset(struct e1000_hw *hw)
  3910. {
  3911. uint16_t swfw = E1000_SWFW_PHY0_SM;
  3912. uint32_t ctrl, ctrl_ext;
  3913. uint32_t led_ctrl;
  3914. int32_t ret_val;
  3915. DEBUGFUNC();
  3916. /* In the case of the phy reset being blocked, it's not an error, we
  3917. * simply return success without performing the reset. */
  3918. ret_val = e1000_check_phy_reset_block(hw);
  3919. if (ret_val)
  3920. return E1000_SUCCESS;
  3921. DEBUGOUT("Resetting Phy...\n");
  3922. if (hw->mac_type > e1000_82543) {
  3923. if (e1000_is_second_port(hw))
  3924. swfw = E1000_SWFW_PHY1_SM;
  3925. if (e1000_swfw_sync_acquire(hw, swfw)) {
  3926. DEBUGOUT("Unable to acquire swfw sync\n");
  3927. return -E1000_ERR_SWFW_SYNC;
  3928. }
  3929. /* Read the device control register and assert the E1000_CTRL_PHY_RST
  3930. * bit. Then, take it out of reset.
  3931. */
  3932. ctrl = E1000_READ_REG(hw, CTRL);
  3933. E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
  3934. E1000_WRITE_FLUSH(hw);
  3935. if (hw->mac_type < e1000_82571)
  3936. udelay(10);
  3937. else
  3938. udelay(100);
  3939. E1000_WRITE_REG(hw, CTRL, ctrl);
  3940. E1000_WRITE_FLUSH(hw);
  3941. if (hw->mac_type >= e1000_82571)
  3942. mdelay(10);
  3943. } else {
  3944. /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
  3945. * bit to put the PHY into reset. Then, take it out of reset.
  3946. */
  3947. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  3948. ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
  3949. ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
  3950. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  3951. E1000_WRITE_FLUSH(hw);
  3952. mdelay(10);
  3953. ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
  3954. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  3955. E1000_WRITE_FLUSH(hw);
  3956. }
  3957. udelay(150);
  3958. if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  3959. /* Configure activity LED after PHY reset */
  3960. led_ctrl = E1000_READ_REG(hw, LEDCTL);
  3961. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  3962. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  3963. E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
  3964. }
  3965. e1000_swfw_sync_release(hw, swfw);
  3966. /* Wait for FW to finish PHY configuration. */
  3967. ret_val = e1000_get_phy_cfg_done(hw);
  3968. if (ret_val != E1000_SUCCESS)
  3969. return ret_val;
  3970. return ret_val;
  3971. }
  3972. /******************************************************************************
  3973. * IGP phy init script - initializes the GbE PHY
  3974. *
  3975. * hw - Struct containing variables accessed by shared code
  3976. *****************************************************************************/
  3977. static void
  3978. e1000_phy_init_script(struct e1000_hw *hw)
  3979. {
  3980. uint32_t ret_val;
  3981. uint16_t phy_saved_data;
  3982. DEBUGFUNC();
  3983. if (hw->phy_init_script) {
  3984. mdelay(20);
  3985. /* Save off the current value of register 0x2F5B to be
  3986. * restored at the end of this routine. */
  3987. ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
  3988. /* Disabled the PHY transmitter */
  3989. e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
  3990. mdelay(20);
  3991. e1000_write_phy_reg(hw, 0x0000, 0x0140);
  3992. mdelay(5);
  3993. switch (hw->mac_type) {
  3994. case e1000_82541:
  3995. case e1000_82547:
  3996. e1000_write_phy_reg(hw, 0x1F95, 0x0001);
  3997. e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
  3998. e1000_write_phy_reg(hw, 0x1F79, 0x0018);
  3999. e1000_write_phy_reg(hw, 0x1F30, 0x1600);
  4000. e1000_write_phy_reg(hw, 0x1F31, 0x0014);
  4001. e1000_write_phy_reg(hw, 0x1F32, 0x161C);
  4002. e1000_write_phy_reg(hw, 0x1F94, 0x0003);
  4003. e1000_write_phy_reg(hw, 0x1F96, 0x003F);
  4004. e1000_write_phy_reg(hw, 0x2010, 0x0008);
  4005. break;
  4006. case e1000_82541_rev_2:
  4007. case e1000_82547_rev_2:
  4008. e1000_write_phy_reg(hw, 0x1F73, 0x0099);
  4009. break;
  4010. default:
  4011. break;
  4012. }
  4013. e1000_write_phy_reg(hw, 0x0000, 0x3300);
  4014. mdelay(20);
  4015. /* Now enable the transmitter */
  4016. if (!ret_val)
  4017. e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
  4018. if (hw->mac_type == e1000_82547) {
  4019. uint16_t fused, fine, coarse;
  4020. /* Move to analog registers page */
  4021. e1000_read_phy_reg(hw,
  4022. IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
  4023. if (!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
  4024. e1000_read_phy_reg(hw,
  4025. IGP01E1000_ANALOG_FUSE_STATUS, &fused);
  4026. fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
  4027. coarse = fused
  4028. & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
  4029. if (coarse >
  4030. IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
  4031. coarse -=
  4032. IGP01E1000_ANALOG_FUSE_COARSE_10;
  4033. fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
  4034. } else if (coarse
  4035. == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
  4036. fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
  4037. fused = (fused
  4038. & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
  4039. (fine
  4040. & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
  4041. (coarse
  4042. & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
  4043. e1000_write_phy_reg(hw,
  4044. IGP01E1000_ANALOG_FUSE_CONTROL, fused);
  4045. e1000_write_phy_reg(hw,
  4046. IGP01E1000_ANALOG_FUSE_BYPASS,
  4047. IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
  4048. }
  4049. }
  4050. }
  4051. }
  4052. /******************************************************************************
  4053. * Resets the PHY
  4054. *
  4055. * hw - Struct containing variables accessed by shared code
  4056. *
  4057. * Sets bit 15 of the MII Control register
  4058. ******************************************************************************/
  4059. int32_t
  4060. e1000_phy_reset(struct e1000_hw *hw)
  4061. {
  4062. int32_t ret_val;
  4063. uint16_t phy_data;
  4064. DEBUGFUNC();
  4065. /* In the case of the phy reset being blocked, it's not an error, we
  4066. * simply return success without performing the reset. */
  4067. ret_val = e1000_check_phy_reset_block(hw);
  4068. if (ret_val)
  4069. return E1000_SUCCESS;
  4070. switch (hw->phy_type) {
  4071. case e1000_phy_igp:
  4072. case e1000_phy_igp_2:
  4073. case e1000_phy_igp_3:
  4074. case e1000_phy_ife:
  4075. case e1000_phy_igb:
  4076. ret_val = e1000_phy_hw_reset(hw);
  4077. if (ret_val)
  4078. return ret_val;
  4079. break;
  4080. default:
  4081. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
  4082. if (ret_val)
  4083. return ret_val;
  4084. phy_data |= MII_CR_RESET;
  4085. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
  4086. if (ret_val)
  4087. return ret_val;
  4088. udelay(1);
  4089. break;
  4090. }
  4091. if (hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
  4092. e1000_phy_init_script(hw);
  4093. return E1000_SUCCESS;
  4094. }
  4095. static int e1000_set_phy_type (struct e1000_hw *hw)
  4096. {
  4097. DEBUGFUNC ();
  4098. if (hw->mac_type == e1000_undefined)
  4099. return -E1000_ERR_PHY_TYPE;
  4100. switch (hw->phy_id) {
  4101. case M88E1000_E_PHY_ID:
  4102. case M88E1000_I_PHY_ID:
  4103. case M88E1011_I_PHY_ID:
  4104. case M88E1111_I_PHY_ID:
  4105. hw->phy_type = e1000_phy_m88;
  4106. break;
  4107. case IGP01E1000_I_PHY_ID:
  4108. if (hw->mac_type == e1000_82541 ||
  4109. hw->mac_type == e1000_82541_rev_2 ||
  4110. hw->mac_type == e1000_82547 ||
  4111. hw->mac_type == e1000_82547_rev_2) {
  4112. hw->phy_type = e1000_phy_igp;
  4113. break;
  4114. }
  4115. case IGP03E1000_E_PHY_ID:
  4116. hw->phy_type = e1000_phy_igp_3;
  4117. break;
  4118. case IFE_E_PHY_ID:
  4119. case IFE_PLUS_E_PHY_ID:
  4120. case IFE_C_E_PHY_ID:
  4121. hw->phy_type = e1000_phy_ife;
  4122. break;
  4123. case GG82563_E_PHY_ID:
  4124. if (hw->mac_type == e1000_80003es2lan) {
  4125. hw->phy_type = e1000_phy_gg82563;
  4126. break;
  4127. }
  4128. case BME1000_E_PHY_ID:
  4129. hw->phy_type = e1000_phy_bm;
  4130. break;
  4131. case I210_I_PHY_ID:
  4132. hw->phy_type = e1000_phy_igb;
  4133. break;
  4134. /* Fall Through */
  4135. default:
  4136. /* Should never have loaded on this device */
  4137. hw->phy_type = e1000_phy_undefined;
  4138. return -E1000_ERR_PHY_TYPE;
  4139. }
  4140. return E1000_SUCCESS;
  4141. }
  4142. /******************************************************************************
  4143. * Probes the expected PHY address for known PHY IDs
  4144. *
  4145. * hw - Struct containing variables accessed by shared code
  4146. ******************************************************************************/
  4147. static int32_t
  4148. e1000_detect_gig_phy(struct e1000_hw *hw)
  4149. {
  4150. int32_t phy_init_status, ret_val;
  4151. uint16_t phy_id_high, phy_id_low;
  4152. bool match = false;
  4153. DEBUGFUNC();
  4154. /* The 82571 firmware may still be configuring the PHY. In this
  4155. * case, we cannot access the PHY until the configuration is done. So
  4156. * we explicitly set the PHY values. */
  4157. if (hw->mac_type == e1000_82571 ||
  4158. hw->mac_type == e1000_82572) {
  4159. hw->phy_id = IGP01E1000_I_PHY_ID;
  4160. hw->phy_type = e1000_phy_igp_2;
  4161. return E1000_SUCCESS;
  4162. }
  4163. /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a
  4164. * work- around that forces PHY page 0 to be set or the reads fail.
  4165. * The rest of the code in this routine uses e1000_read_phy_reg to
  4166. * read the PHY ID. So for ESB-2 we need to have this set so our
  4167. * reads won't fail. If the attached PHY is not a e1000_phy_gg82563,
  4168. * the routines below will figure this out as well. */
  4169. if (hw->mac_type == e1000_80003es2lan)
  4170. hw->phy_type = e1000_phy_gg82563;
  4171. /* Read the PHY ID Registers to identify which PHY is onboard. */
  4172. ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
  4173. if (ret_val)
  4174. return ret_val;
  4175. hw->phy_id = (uint32_t) (phy_id_high << 16);
  4176. udelay(20);
  4177. ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
  4178. if (ret_val)
  4179. return ret_val;
  4180. hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
  4181. hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
  4182. switch (hw->mac_type) {
  4183. case e1000_82543:
  4184. if (hw->phy_id == M88E1000_E_PHY_ID)
  4185. match = true;
  4186. break;
  4187. case e1000_82544:
  4188. if (hw->phy_id == M88E1000_I_PHY_ID)
  4189. match = true;
  4190. break;
  4191. case e1000_82540:
  4192. case e1000_82545:
  4193. case e1000_82545_rev_3:
  4194. case e1000_82546:
  4195. case e1000_82546_rev_3:
  4196. if (hw->phy_id == M88E1011_I_PHY_ID)
  4197. match = true;
  4198. break;
  4199. case e1000_82541:
  4200. case e1000_82541_rev_2:
  4201. case e1000_82547:
  4202. case e1000_82547_rev_2:
  4203. if(hw->phy_id == IGP01E1000_I_PHY_ID)
  4204. match = true;
  4205. break;
  4206. case e1000_82573:
  4207. if (hw->phy_id == M88E1111_I_PHY_ID)
  4208. match = true;
  4209. break;
  4210. case e1000_82574:
  4211. if (hw->phy_id == BME1000_E_PHY_ID)
  4212. match = true;
  4213. break;
  4214. case e1000_80003es2lan:
  4215. if (hw->phy_id == GG82563_E_PHY_ID)
  4216. match = true;
  4217. break;
  4218. case e1000_ich8lan:
  4219. if (hw->phy_id == IGP03E1000_E_PHY_ID)
  4220. match = true;
  4221. if (hw->phy_id == IFE_E_PHY_ID)
  4222. match = true;
  4223. if (hw->phy_id == IFE_PLUS_E_PHY_ID)
  4224. match = true;
  4225. if (hw->phy_id == IFE_C_E_PHY_ID)
  4226. match = true;
  4227. break;
  4228. case e1000_igb:
  4229. if (hw->phy_id == I210_I_PHY_ID)
  4230. match = true;
  4231. break;
  4232. default:
  4233. DEBUGOUT("Invalid MAC type %d\n", hw->mac_type);
  4234. return -E1000_ERR_CONFIG;
  4235. }
  4236. phy_init_status = e1000_set_phy_type(hw);
  4237. if ((match) && (phy_init_status == E1000_SUCCESS)) {
  4238. DEBUGOUT("PHY ID 0x%X detected\n", hw->phy_id);
  4239. return 0;
  4240. }
  4241. DEBUGOUT("Invalid PHY ID 0x%X\n", hw->phy_id);
  4242. return -E1000_ERR_PHY;
  4243. }
  4244. /*****************************************************************************
  4245. * Set media type and TBI compatibility.
  4246. *
  4247. * hw - Struct containing variables accessed by shared code
  4248. * **************************************************************************/
  4249. void
  4250. e1000_set_media_type(struct e1000_hw *hw)
  4251. {
  4252. uint32_t status;
  4253. DEBUGFUNC();
  4254. if (hw->mac_type != e1000_82543) {
  4255. /* tbi_compatibility is only valid on 82543 */
  4256. hw->tbi_compatibility_en = false;
  4257. }
  4258. switch (hw->device_id) {
  4259. case E1000_DEV_ID_82545GM_SERDES:
  4260. case E1000_DEV_ID_82546GB_SERDES:
  4261. case E1000_DEV_ID_82571EB_SERDES:
  4262. case E1000_DEV_ID_82571EB_SERDES_DUAL:
  4263. case E1000_DEV_ID_82571EB_SERDES_QUAD:
  4264. case E1000_DEV_ID_82572EI_SERDES:
  4265. case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
  4266. hw->media_type = e1000_media_type_internal_serdes;
  4267. break;
  4268. default:
  4269. switch (hw->mac_type) {
  4270. case e1000_82542_rev2_0:
  4271. case e1000_82542_rev2_1:
  4272. hw->media_type = e1000_media_type_fiber;
  4273. break;
  4274. case e1000_ich8lan:
  4275. case e1000_82573:
  4276. case e1000_82574:
  4277. case e1000_igb:
  4278. /* The STATUS_TBIMODE bit is reserved or reused
  4279. * for the this device.
  4280. */
  4281. hw->media_type = e1000_media_type_copper;
  4282. break;
  4283. default:
  4284. status = E1000_READ_REG(hw, STATUS);
  4285. if (status & E1000_STATUS_TBIMODE) {
  4286. hw->media_type = e1000_media_type_fiber;
  4287. /* tbi_compatibility not valid on fiber */
  4288. hw->tbi_compatibility_en = false;
  4289. } else {
  4290. hw->media_type = e1000_media_type_copper;
  4291. }
  4292. break;
  4293. }
  4294. }
  4295. }
  4296. /**
  4297. * e1000_sw_init - Initialize general software structures (struct e1000_adapter)
  4298. *
  4299. * e1000_sw_init initializes the Adapter private data structure.
  4300. * Fields are initialized based on PCI device information and
  4301. * OS network device settings (MTU size).
  4302. **/
  4303. static int
  4304. e1000_sw_init(struct eth_device *nic)
  4305. {
  4306. struct e1000_hw *hw = (typeof(hw)) nic->priv;
  4307. int result;
  4308. /* PCI config space info */
  4309. pci_read_config_word(hw->pdev, PCI_VENDOR_ID, &hw->vendor_id);
  4310. pci_read_config_word(hw->pdev, PCI_DEVICE_ID, &hw->device_id);
  4311. pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_VENDOR_ID,
  4312. &hw->subsystem_vendor_id);
  4313. pci_read_config_word(hw->pdev, PCI_SUBSYSTEM_ID, &hw->subsystem_id);
  4314. pci_read_config_byte(hw->pdev, PCI_REVISION_ID, &hw->revision_id);
  4315. pci_read_config_word(hw->pdev, PCI_COMMAND, &hw->pci_cmd_word);
  4316. /* identify the MAC */
  4317. result = e1000_set_mac_type(hw);
  4318. if (result) {
  4319. E1000_ERR(hw->nic, "Unknown MAC Type\n");
  4320. return result;
  4321. }
  4322. switch (hw->mac_type) {
  4323. default:
  4324. break;
  4325. case e1000_82541:
  4326. case e1000_82547:
  4327. case e1000_82541_rev_2:
  4328. case e1000_82547_rev_2:
  4329. hw->phy_init_script = 1;
  4330. break;
  4331. }
  4332. /* flow control settings */
  4333. hw->fc_high_water = E1000_FC_HIGH_THRESH;
  4334. hw->fc_low_water = E1000_FC_LOW_THRESH;
  4335. hw->fc_pause_time = E1000_FC_PAUSE_TIME;
  4336. hw->fc_send_xon = 1;
  4337. /* Media type - copper or fiber */
  4338. hw->tbi_compatibility_en = true;
  4339. e1000_set_media_type(hw);
  4340. if (hw->mac_type >= e1000_82543) {
  4341. uint32_t status = E1000_READ_REG(hw, STATUS);
  4342. if (status & E1000_STATUS_TBIMODE) {
  4343. DEBUGOUT("fiber interface\n");
  4344. hw->media_type = e1000_media_type_fiber;
  4345. } else {
  4346. DEBUGOUT("copper interface\n");
  4347. hw->media_type = e1000_media_type_copper;
  4348. }
  4349. } else {
  4350. hw->media_type = e1000_media_type_fiber;
  4351. }
  4352. hw->wait_autoneg_complete = true;
  4353. if (hw->mac_type < e1000_82543)
  4354. hw->report_tx_early = 0;
  4355. else
  4356. hw->report_tx_early = 1;
  4357. return E1000_SUCCESS;
  4358. }
  4359. void
  4360. fill_rx(struct e1000_hw *hw)
  4361. {
  4362. struct e1000_rx_desc *rd;
  4363. unsigned long flush_start, flush_end;
  4364. rx_last = rx_tail;
  4365. rd = rx_base + rx_tail;
  4366. rx_tail = (rx_tail + 1) % 8;
  4367. memset(rd, 0, 16);
  4368. rd->buffer_addr = cpu_to_le64((unsigned long)packet);
  4369. /*
  4370. * Make sure there are no stale data in WB over this area, which
  4371. * might get written into the memory while the e1000 also writes
  4372. * into the same memory area.
  4373. */
  4374. invalidate_dcache_range((unsigned long)packet,
  4375. (unsigned long)packet + 4096);
  4376. /* Dump the DMA descriptor into RAM. */
  4377. flush_start = ((unsigned long)rd) & ~(ARCH_DMA_MINALIGN - 1);
  4378. flush_end = flush_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN);
  4379. flush_dcache_range(flush_start, flush_end);
  4380. E1000_WRITE_REG(hw, RDT, rx_tail);
  4381. }
  4382. /**
  4383. * e1000_configure_tx - Configure 8254x Transmit Unit after Reset
  4384. * @adapter: board private structure
  4385. *
  4386. * Configure the Tx unit of the MAC after a reset.
  4387. **/
  4388. static void
  4389. e1000_configure_tx(struct e1000_hw *hw)
  4390. {
  4391. unsigned long tctl;
  4392. unsigned long tipg, tarc;
  4393. uint32_t ipgr1, ipgr2;
  4394. E1000_WRITE_REG(hw, TDBAL, (unsigned long)tx_base);
  4395. E1000_WRITE_REG(hw, TDBAH, 0);
  4396. E1000_WRITE_REG(hw, TDLEN, 128);
  4397. /* Setup the HW Tx Head and Tail descriptor pointers */
  4398. E1000_WRITE_REG(hw, TDH, 0);
  4399. E1000_WRITE_REG(hw, TDT, 0);
  4400. tx_tail = 0;
  4401. /* Set the default values for the Tx Inter Packet Gap timer */
  4402. if (hw->mac_type <= e1000_82547_rev_2 &&
  4403. (hw->media_type == e1000_media_type_fiber ||
  4404. hw->media_type == e1000_media_type_internal_serdes))
  4405. tipg = DEFAULT_82543_TIPG_IPGT_FIBER;
  4406. else
  4407. tipg = DEFAULT_82543_TIPG_IPGT_COPPER;
  4408. /* Set the default values for the Tx Inter Packet Gap timer */
  4409. switch (hw->mac_type) {
  4410. case e1000_82542_rev2_0:
  4411. case e1000_82542_rev2_1:
  4412. tipg = DEFAULT_82542_TIPG_IPGT;
  4413. ipgr1 = DEFAULT_82542_TIPG_IPGR1;
  4414. ipgr2 = DEFAULT_82542_TIPG_IPGR2;
  4415. break;
  4416. case e1000_80003es2lan:
  4417. ipgr1 = DEFAULT_82543_TIPG_IPGR1;
  4418. ipgr2 = DEFAULT_80003ES2LAN_TIPG_IPGR2;
  4419. break;
  4420. default:
  4421. ipgr1 = DEFAULT_82543_TIPG_IPGR1;
  4422. ipgr2 = DEFAULT_82543_TIPG_IPGR2;
  4423. break;
  4424. }
  4425. tipg |= ipgr1 << E1000_TIPG_IPGR1_SHIFT;
  4426. tipg |= ipgr2 << E1000_TIPG_IPGR2_SHIFT;
  4427. E1000_WRITE_REG(hw, TIPG, tipg);
  4428. /* Program the Transmit Control Register */
  4429. tctl = E1000_READ_REG(hw, TCTL);
  4430. tctl &= ~E1000_TCTL_CT;
  4431. tctl |= E1000_TCTL_EN | E1000_TCTL_PSP |
  4432. (E1000_COLLISION_THRESHOLD << E1000_CT_SHIFT);
  4433. if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572) {
  4434. tarc = E1000_READ_REG(hw, TARC0);
  4435. /* set the speed mode bit, we'll clear it if we're not at
  4436. * gigabit link later */
  4437. /* git bit can be set to 1*/
  4438. } else if (hw->mac_type == e1000_80003es2lan) {
  4439. tarc = E1000_READ_REG(hw, TARC0);
  4440. tarc |= 1;
  4441. E1000_WRITE_REG(hw, TARC0, tarc);
  4442. tarc = E1000_READ_REG(hw, TARC1);
  4443. tarc |= 1;
  4444. E1000_WRITE_REG(hw, TARC1, tarc);
  4445. }
  4446. e1000_config_collision_dist(hw);
  4447. /* Setup Transmit Descriptor Settings for eop descriptor */
  4448. hw->txd_cmd = E1000_TXD_CMD_EOP | E1000_TXD_CMD_IFCS;
  4449. /* Need to set up RS bit */
  4450. if (hw->mac_type < e1000_82543)
  4451. hw->txd_cmd |= E1000_TXD_CMD_RPS;
  4452. else
  4453. hw->txd_cmd |= E1000_TXD_CMD_RS;
  4454. if (hw->mac_type == e1000_igb) {
  4455. E1000_WRITE_REG(hw, TCTL_EXT, 0x42 << 10);
  4456. uint32_t reg_txdctl = E1000_READ_REG(hw, TXDCTL);
  4457. reg_txdctl |= 1 << 25;
  4458. E1000_WRITE_REG(hw, TXDCTL, reg_txdctl);
  4459. mdelay(20);
  4460. }
  4461. E1000_WRITE_REG(hw, TCTL, tctl);
  4462. }
  4463. /**
  4464. * e1000_setup_rctl - configure the receive control register
  4465. * @adapter: Board private structure
  4466. **/
  4467. static void
  4468. e1000_setup_rctl(struct e1000_hw *hw)
  4469. {
  4470. uint32_t rctl;
  4471. rctl = E1000_READ_REG(hw, RCTL);
  4472. rctl &= ~(3 << E1000_RCTL_MO_SHIFT);
  4473. rctl |= E1000_RCTL_EN | E1000_RCTL_BAM | E1000_RCTL_LBM_NO
  4474. | E1000_RCTL_RDMTS_HALF; /* |
  4475. (hw.mc_filter_type << E1000_RCTL_MO_SHIFT); */
  4476. if (hw->tbi_compatibility_on == 1)
  4477. rctl |= E1000_RCTL_SBP;
  4478. else
  4479. rctl &= ~E1000_RCTL_SBP;
  4480. rctl &= ~(E1000_RCTL_SZ_4096);
  4481. rctl |= E1000_RCTL_SZ_2048;
  4482. rctl &= ~(E1000_RCTL_BSEX | E1000_RCTL_LPE);
  4483. E1000_WRITE_REG(hw, RCTL, rctl);
  4484. }
  4485. /**
  4486. * e1000_configure_rx - Configure 8254x Receive Unit after Reset
  4487. * @adapter: board private structure
  4488. *
  4489. * Configure the Rx unit of the MAC after a reset.
  4490. **/
  4491. static void
  4492. e1000_configure_rx(struct e1000_hw *hw)
  4493. {
  4494. unsigned long rctl, ctrl_ext;
  4495. rx_tail = 0;
  4496. /* make sure receives are disabled while setting up the descriptors */
  4497. rctl = E1000_READ_REG(hw, RCTL);
  4498. E1000_WRITE_REG(hw, RCTL, rctl & ~E1000_RCTL_EN);
  4499. if (hw->mac_type >= e1000_82540) {
  4500. /* Set the interrupt throttling rate. Value is calculated
  4501. * as DEFAULT_ITR = 1/(MAX_INTS_PER_SEC * 256ns) */
  4502. #define MAX_INTS_PER_SEC 8000
  4503. #define DEFAULT_ITR 1000000000/(MAX_INTS_PER_SEC * 256)
  4504. E1000_WRITE_REG(hw, ITR, DEFAULT_ITR);
  4505. }
  4506. if (hw->mac_type >= e1000_82571) {
  4507. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  4508. /* Reset delay timers after every interrupt */
  4509. ctrl_ext |= E1000_CTRL_EXT_INT_TIMER_CLR;
  4510. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  4511. E1000_WRITE_FLUSH(hw);
  4512. }
  4513. /* Setup the Base and Length of the Rx Descriptor Ring */
  4514. E1000_WRITE_REG(hw, RDBAL, (unsigned long)rx_base);
  4515. E1000_WRITE_REG(hw, RDBAH, 0);
  4516. E1000_WRITE_REG(hw, RDLEN, 128);
  4517. /* Setup the HW Rx Head and Tail Descriptor Pointers */
  4518. E1000_WRITE_REG(hw, RDH, 0);
  4519. E1000_WRITE_REG(hw, RDT, 0);
  4520. /* Enable Receives */
  4521. if (hw->mac_type == e1000_igb) {
  4522. uint32_t reg_rxdctl = E1000_READ_REG(hw, RXDCTL);
  4523. reg_rxdctl |= 1 << 25;
  4524. E1000_WRITE_REG(hw, RXDCTL, reg_rxdctl);
  4525. mdelay(20);
  4526. }
  4527. E1000_WRITE_REG(hw, RCTL, rctl);
  4528. fill_rx(hw);
  4529. }
  4530. /**************************************************************************
  4531. POLL - Wait for a frame
  4532. ***************************************************************************/
  4533. static int
  4534. e1000_poll(struct eth_device *nic)
  4535. {
  4536. struct e1000_hw *hw = nic->priv;
  4537. struct e1000_rx_desc *rd;
  4538. unsigned long inval_start, inval_end;
  4539. uint32_t len;
  4540. /* return true if there's an ethernet packet ready to read */
  4541. rd = rx_base + rx_last;
  4542. /* Re-load the descriptor from RAM. */
  4543. inval_start = ((unsigned long)rd) & ~(ARCH_DMA_MINALIGN - 1);
  4544. inval_end = inval_start + roundup(sizeof(*rd), ARCH_DMA_MINALIGN);
  4545. invalidate_dcache_range(inval_start, inval_end);
  4546. if (!(le32_to_cpu(rd->status)) & E1000_RXD_STAT_DD)
  4547. return 0;
  4548. /* DEBUGOUT("recv: packet len=%d\n", rd->length); */
  4549. /* Packet received, make sure the data are re-loaded from RAM. */
  4550. len = le32_to_cpu(rd->length);
  4551. invalidate_dcache_range((unsigned long)packet,
  4552. (unsigned long)packet +
  4553. roundup(len, ARCH_DMA_MINALIGN));
  4554. net_process_received_packet((uchar *)packet, len);
  4555. fill_rx(hw);
  4556. return 1;
  4557. }
  4558. /**************************************************************************
  4559. TRANSMIT - Transmit a frame
  4560. ***************************************************************************/
  4561. static int e1000_transmit(struct eth_device *nic, void *txpacket, int length)
  4562. {
  4563. void *nv_packet = (void *)txpacket;
  4564. struct e1000_hw *hw = nic->priv;
  4565. struct e1000_tx_desc *txp;
  4566. int i = 0;
  4567. unsigned long flush_start, flush_end;
  4568. txp = tx_base + tx_tail;
  4569. tx_tail = (tx_tail + 1) % 8;
  4570. txp->buffer_addr = cpu_to_le64(virt_to_bus(hw->pdev, nv_packet));
  4571. txp->lower.data = cpu_to_le32(hw->txd_cmd | length);
  4572. txp->upper.data = 0;
  4573. /* Dump the packet into RAM so e1000 can pick them. */
  4574. flush_dcache_range((unsigned long)nv_packet,
  4575. (unsigned long)nv_packet +
  4576. roundup(length, ARCH_DMA_MINALIGN));
  4577. /* Dump the descriptor into RAM as well. */
  4578. flush_start = ((unsigned long)txp) & ~(ARCH_DMA_MINALIGN - 1);
  4579. flush_end = flush_start + roundup(sizeof(*txp), ARCH_DMA_MINALIGN);
  4580. flush_dcache_range(flush_start, flush_end);
  4581. E1000_WRITE_REG(hw, TDT, tx_tail);
  4582. E1000_WRITE_FLUSH(hw);
  4583. while (1) {
  4584. invalidate_dcache_range(flush_start, flush_end);
  4585. if (le32_to_cpu(txp->upper.data) & E1000_TXD_STAT_DD)
  4586. break;
  4587. if (i++ > TOUT_LOOP) {
  4588. DEBUGOUT("e1000: tx timeout\n");
  4589. return 0;
  4590. }
  4591. udelay(10); /* give the nic a chance to write to the register */
  4592. }
  4593. return 1;
  4594. }
  4595. /*reset function*/
  4596. static inline int
  4597. e1000_reset(struct eth_device *nic)
  4598. {
  4599. struct e1000_hw *hw = nic->priv;
  4600. e1000_reset_hw(hw);
  4601. if (hw->mac_type >= e1000_82544) {
  4602. E1000_WRITE_REG(hw, WUC, 0);
  4603. }
  4604. return e1000_init_hw(nic);
  4605. }
  4606. /**************************************************************************
  4607. DISABLE - Turn off ethernet interface
  4608. ***************************************************************************/
  4609. static void
  4610. e1000_disable(struct eth_device *nic)
  4611. {
  4612. struct e1000_hw *hw = nic->priv;
  4613. /* Turn off the ethernet interface */
  4614. E1000_WRITE_REG(hw, RCTL, 0);
  4615. E1000_WRITE_REG(hw, TCTL, 0);
  4616. /* Clear the transmit ring */
  4617. E1000_WRITE_REG(hw, TDH, 0);
  4618. E1000_WRITE_REG(hw, TDT, 0);
  4619. /* Clear the receive ring */
  4620. E1000_WRITE_REG(hw, RDH, 0);
  4621. E1000_WRITE_REG(hw, RDT, 0);
  4622. /* put the card in its initial state */
  4623. #if 0
  4624. E1000_WRITE_REG(hw, CTRL, E1000_CTRL_RST);
  4625. #endif
  4626. mdelay(10);
  4627. }
  4628. /**************************************************************************
  4629. INIT - set up ethernet interface(s)
  4630. ***************************************************************************/
  4631. static int
  4632. e1000_init(struct eth_device *nic, bd_t * bis)
  4633. {
  4634. struct e1000_hw *hw = nic->priv;
  4635. int ret_val = 0;
  4636. ret_val = e1000_reset(nic);
  4637. if (ret_val < 0) {
  4638. if ((ret_val == -E1000_ERR_NOLINK) ||
  4639. (ret_val == -E1000_ERR_TIMEOUT)) {
  4640. E1000_ERR(hw->nic, "Valid Link not detected\n");
  4641. } else {
  4642. E1000_ERR(hw->nic, "Hardware Initialization Failed\n");
  4643. }
  4644. return 0;
  4645. }
  4646. e1000_configure_tx(hw);
  4647. e1000_setup_rctl(hw);
  4648. e1000_configure_rx(hw);
  4649. return 1;
  4650. }
  4651. /******************************************************************************
  4652. * Gets the current PCI bus type of hardware
  4653. *
  4654. * hw - Struct containing variables accessed by shared code
  4655. *****************************************************************************/
  4656. void e1000_get_bus_type(struct e1000_hw *hw)
  4657. {
  4658. uint32_t status;
  4659. switch (hw->mac_type) {
  4660. case e1000_82542_rev2_0:
  4661. case e1000_82542_rev2_1:
  4662. hw->bus_type = e1000_bus_type_pci;
  4663. break;
  4664. case e1000_82571:
  4665. case e1000_82572:
  4666. case e1000_82573:
  4667. case e1000_82574:
  4668. case e1000_80003es2lan:
  4669. case e1000_ich8lan:
  4670. case e1000_igb:
  4671. hw->bus_type = e1000_bus_type_pci_express;
  4672. break;
  4673. default:
  4674. status = E1000_READ_REG(hw, STATUS);
  4675. hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
  4676. e1000_bus_type_pcix : e1000_bus_type_pci;
  4677. break;
  4678. }
  4679. }
  4680. /* A list of all registered e1000 devices */
  4681. static LIST_HEAD(e1000_hw_list);
  4682. /**************************************************************************
  4683. PROBE - Look for an adapter, this routine's visible to the outside
  4684. You should omit the last argument struct pci_device * for a non-PCI NIC
  4685. ***************************************************************************/
  4686. int
  4687. e1000_initialize(bd_t * bis)
  4688. {
  4689. unsigned int i;
  4690. pci_dev_t devno;
  4691. DEBUGFUNC();
  4692. /* Find and probe all the matching PCI devices */
  4693. for (i = 0; (devno = pci_find_devices(e1000_supported, i)) >= 0; i++) {
  4694. u32 val;
  4695. /*
  4696. * These will never get freed due to errors, this allows us to
  4697. * perform SPI EEPROM programming from U-boot, for example.
  4698. */
  4699. struct eth_device *nic = malloc(sizeof(*nic));
  4700. struct e1000_hw *hw = malloc(sizeof(*hw));
  4701. if (!nic || !hw) {
  4702. printf("e1000#%u: Out of Memory!\n", i);
  4703. free(nic);
  4704. free(hw);
  4705. continue;
  4706. }
  4707. /* Make sure all of the fields are initially zeroed */
  4708. memset(nic, 0, sizeof(*nic));
  4709. memset(hw, 0, sizeof(*hw));
  4710. /* Assign the passed-in values */
  4711. hw->cardnum = i;
  4712. hw->pdev = devno;
  4713. hw->nic = nic;
  4714. nic->priv = hw;
  4715. /* Generate a card name */
  4716. sprintf(nic->name, "e1000#%u", hw->cardnum);
  4717. /* Print a debug message with the IO base address */
  4718. pci_read_config_dword(devno, PCI_BASE_ADDRESS_0, &val);
  4719. E1000_DBG(nic, "iobase 0x%08x\n", val & 0xfffffff0);
  4720. /* Try to enable I/O accesses and bus-mastering */
  4721. val = PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
  4722. pci_write_config_dword(devno, PCI_COMMAND, val);
  4723. /* Make sure it worked */
  4724. pci_read_config_dword(devno, PCI_COMMAND, &val);
  4725. if (!(val & PCI_COMMAND_MEMORY)) {
  4726. E1000_ERR(nic, "Can't enable I/O memory\n");
  4727. continue;
  4728. }
  4729. if (!(val & PCI_COMMAND_MASTER)) {
  4730. E1000_ERR(nic, "Can't enable bus-mastering\n");
  4731. continue;
  4732. }
  4733. /* Are these variables needed? */
  4734. hw->fc = e1000_fc_default;
  4735. hw->original_fc = e1000_fc_default;
  4736. hw->autoneg_failed = 0;
  4737. hw->autoneg = 1;
  4738. hw->get_link_status = true;
  4739. #ifndef CONFIG_E1000_NO_NVM
  4740. hw->eeprom_semaphore_present = true;
  4741. #endif
  4742. hw->hw_addr = pci_map_bar(devno, PCI_BASE_ADDRESS_0,
  4743. PCI_REGION_MEM);
  4744. hw->mac_type = e1000_undefined;
  4745. /* MAC and Phy settings */
  4746. if (e1000_sw_init(nic) < 0) {
  4747. E1000_ERR(nic, "Software init failed\n");
  4748. continue;
  4749. }
  4750. if (e1000_check_phy_reset_block(hw))
  4751. E1000_ERR(nic, "PHY Reset is blocked!\n");
  4752. /* Basic init was OK, reset the hardware and allow SPI access */
  4753. e1000_reset_hw(hw);
  4754. list_add_tail(&hw->list_node, &e1000_hw_list);
  4755. #ifndef CONFIG_E1000_NO_NVM
  4756. /* Validate the EEPROM and get chipset information */
  4757. #if !defined(CONFIG_MVBC_1G)
  4758. if (e1000_init_eeprom_params(hw)) {
  4759. E1000_ERR(nic, "EEPROM is invalid!\n");
  4760. continue;
  4761. }
  4762. if ((E1000_READ_REG(hw, I210_EECD) & E1000_EECD_FLUPD) &&
  4763. e1000_validate_eeprom_checksum(hw))
  4764. continue;
  4765. #endif
  4766. e1000_read_mac_addr(nic);
  4767. #endif
  4768. e1000_get_bus_type(hw);
  4769. #ifndef CONFIG_E1000_NO_NVM
  4770. printf("e1000: %02x:%02x:%02x:%02x:%02x:%02x\n ",
  4771. nic->enetaddr[0], nic->enetaddr[1], nic->enetaddr[2],
  4772. nic->enetaddr[3], nic->enetaddr[4], nic->enetaddr[5]);
  4773. #else
  4774. memset(nic->enetaddr, 0, 6);
  4775. printf("e1000: no NVM\n");
  4776. #endif
  4777. /* Set up the function pointers and register the device */
  4778. nic->init = e1000_init;
  4779. nic->recv = e1000_poll;
  4780. nic->send = e1000_transmit;
  4781. nic->halt = e1000_disable;
  4782. eth_register(nic);
  4783. }
  4784. return i;
  4785. }
  4786. struct e1000_hw *e1000_find_card(unsigned int cardnum)
  4787. {
  4788. struct e1000_hw *hw;
  4789. list_for_each_entry(hw, &e1000_hw_list, list_node)
  4790. if (hw->cardnum == cardnum)
  4791. return hw;
  4792. return NULL;
  4793. }
  4794. #ifdef CONFIG_CMD_E1000
  4795. static int do_e1000(cmd_tbl_t *cmdtp, int flag,
  4796. int argc, char * const argv[])
  4797. {
  4798. struct e1000_hw *hw;
  4799. if (argc < 3) {
  4800. cmd_usage(cmdtp);
  4801. return 1;
  4802. }
  4803. /* Make sure we can find the requested e1000 card */
  4804. hw = e1000_find_card(simple_strtoul(argv[1], NULL, 10));
  4805. if (!hw) {
  4806. printf("e1000: ERROR: No such device: e1000#%s\n", argv[1]);
  4807. return 1;
  4808. }
  4809. if (!strcmp(argv[2], "print-mac-address")) {
  4810. unsigned char *mac = hw->nic->enetaddr;
  4811. printf("%02x:%02x:%02x:%02x:%02x:%02x\n",
  4812. mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  4813. return 0;
  4814. }
  4815. #ifdef CONFIG_E1000_SPI
  4816. /* Handle the "SPI" subcommand */
  4817. if (!strcmp(argv[2], "spi"))
  4818. return do_e1000_spi(cmdtp, hw, argc - 3, argv + 3);
  4819. #endif
  4820. cmd_usage(cmdtp);
  4821. return 1;
  4822. }
  4823. U_BOOT_CMD(
  4824. e1000, 7, 0, do_e1000,
  4825. "Intel e1000 controller management",
  4826. /* */"<card#> print-mac-address\n"
  4827. #ifdef CONFIG_E1000_SPI
  4828. "e1000 <card#> spi show [<offset> [<length>]]\n"
  4829. "e1000 <card#> spi dump <addr> <offset> <length>\n"
  4830. "e1000 <card#> spi program <addr> <offset> <length>\n"
  4831. "e1000 <card#> spi checksum [update]\n"
  4832. #endif
  4833. " - Manage the Intel E1000 PCI device"
  4834. );
  4835. #endif /* not CONFIG_CMD_E1000 */