e1000.c 153 KB

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