e1000.c 153 KB

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