e1000_hw.c 257 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559
  1. /*******************************************************************************
  2. Copyright(c) 1999 - 2006 Intel Corporation. All rights reserved.
  3. This program is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the Free
  5. Software Foundation; either version 2 of the License, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc., 59
  13. Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. The full GNU General Public License is included in this distribution in the
  15. file called LICENSE.
  16. Contact Information:
  17. Linux NICS <linux.nics@intel.com>
  18. e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  19. Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  20. *******************************************************************************/
  21. /* e1000_hw.c
  22. * Shared functions for accessing and configuring the MAC
  23. */
  24. #include "e1000_hw.h"
  25. static int32_t e1000_set_phy_type(struct e1000_hw *hw);
  26. static void e1000_phy_init_script(struct e1000_hw *hw);
  27. static int32_t e1000_setup_copper_link(struct e1000_hw *hw);
  28. static int32_t e1000_setup_fiber_serdes_link(struct e1000_hw *hw);
  29. static int32_t e1000_adjust_serdes_amplitude(struct e1000_hw *hw);
  30. static int32_t e1000_phy_force_speed_duplex(struct e1000_hw *hw);
  31. static int32_t e1000_config_mac_to_phy(struct e1000_hw *hw);
  32. static void e1000_raise_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
  33. static void e1000_lower_mdi_clk(struct e1000_hw *hw, uint32_t *ctrl);
  34. static void e1000_shift_out_mdi_bits(struct e1000_hw *hw, uint32_t data,
  35. uint16_t count);
  36. static uint16_t e1000_shift_in_mdi_bits(struct e1000_hw *hw);
  37. static int32_t e1000_phy_reset_dsp(struct e1000_hw *hw);
  38. static int32_t e1000_write_eeprom_spi(struct e1000_hw *hw, uint16_t offset,
  39. uint16_t words, uint16_t *data);
  40. static int32_t e1000_write_eeprom_microwire(struct e1000_hw *hw,
  41. uint16_t offset, uint16_t words,
  42. uint16_t *data);
  43. static int32_t e1000_spi_eeprom_ready(struct e1000_hw *hw);
  44. static void e1000_raise_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
  45. static void e1000_lower_ee_clk(struct e1000_hw *hw, uint32_t *eecd);
  46. static void e1000_shift_out_ee_bits(struct e1000_hw *hw, uint16_t data,
  47. uint16_t count);
  48. static int32_t e1000_write_phy_reg_ex(struct e1000_hw *hw, uint32_t reg_addr,
  49. uint16_t phy_data);
  50. static int32_t e1000_read_phy_reg_ex(struct e1000_hw *hw,uint32_t reg_addr,
  51. uint16_t *phy_data);
  52. static uint16_t e1000_shift_in_ee_bits(struct e1000_hw *hw, uint16_t count);
  53. static int32_t e1000_acquire_eeprom(struct e1000_hw *hw);
  54. static void e1000_release_eeprom(struct e1000_hw *hw);
  55. static void e1000_standby_eeprom(struct e1000_hw *hw);
  56. static int32_t e1000_set_vco_speed(struct e1000_hw *hw);
  57. static int32_t e1000_polarity_reversal_workaround(struct e1000_hw *hw);
  58. static int32_t e1000_set_phy_mode(struct e1000_hw *hw);
  59. static int32_t e1000_host_if_read_cookie(struct e1000_hw *hw, uint8_t *buffer);
  60. static uint8_t e1000_calculate_mng_checksum(char *buffer, uint32_t length);
  61. static uint8_t e1000_arc_subsystem_valid(struct e1000_hw *hw);
  62. static int32_t e1000_check_downshift(struct e1000_hw *hw);
  63. static int32_t e1000_check_polarity(struct e1000_hw *hw, uint16_t *polarity);
  64. static void e1000_clear_hw_cntrs(struct e1000_hw *hw);
  65. static void e1000_clear_vfta(struct e1000_hw *hw);
  66. static int32_t e1000_commit_shadow_ram(struct e1000_hw *hw);
  67. static int32_t e1000_config_dsp_after_link_change(struct e1000_hw *hw,
  68. boolean_t link_up);
  69. static int32_t e1000_config_fc_after_link_up(struct e1000_hw *hw);
  70. static int32_t e1000_detect_gig_phy(struct e1000_hw *hw);
  71. static int32_t e1000_get_auto_rd_done(struct e1000_hw *hw);
  72. static int32_t e1000_get_cable_length(struct e1000_hw *hw,
  73. uint16_t *min_length,
  74. uint16_t *max_length);
  75. static int32_t e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw);
  76. static int32_t e1000_get_phy_cfg_done(struct e1000_hw *hw);
  77. static int32_t e1000_id_led_init(struct e1000_hw * hw);
  78. static void e1000_init_rx_addrs(struct e1000_hw *hw);
  79. static boolean_t e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw);
  80. static int32_t e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd);
  81. static void e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw);
  82. static int32_t e1000_read_eeprom_eerd(struct e1000_hw *hw, uint16_t offset,
  83. uint16_t words, uint16_t *data);
  84. static int32_t e1000_set_d0_lplu_state(struct e1000_hw *hw, boolean_t active);
  85. static int32_t e1000_set_d3_lplu_state(struct e1000_hw *hw, boolean_t active);
  86. static int32_t e1000_wait_autoneg(struct e1000_hw *hw);
  87. static void e1000_write_reg_io(struct e1000_hw *hw, uint32_t offset,
  88. uint32_t value);
  89. #define E1000_WRITE_REG_IO(a, reg, val) \
  90. e1000_write_reg_io((a), E1000_##reg, val)
  91. static int32_t e1000_configure_kmrn_for_10_100(struct e1000_hw *hw);
  92. static int32_t e1000_configure_kmrn_for_1000(struct e1000_hw *hw);
  93. /* IGP cable length table */
  94. static const
  95. uint16_t e1000_igp_cable_length_table[IGP01E1000_AGC_LENGTH_TABLE_SIZE] =
  96. { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  97. 5, 10, 10, 10, 10, 10, 10, 10, 20, 20, 20, 20, 20, 25, 25, 25,
  98. 25, 25, 25, 25, 30, 30, 30, 30, 40, 40, 40, 40, 40, 40, 40, 40,
  99. 40, 50, 50, 50, 50, 50, 50, 50, 60, 60, 60, 60, 60, 60, 60, 60,
  100. 60, 70, 70, 70, 70, 70, 70, 80, 80, 80, 80, 80, 80, 90, 90, 90,
  101. 90, 90, 90, 90, 90, 90, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
  102. 100, 100, 100, 100, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110, 110,
  103. 110, 110, 110, 110, 110, 110, 120, 120, 120, 120, 120, 120, 120, 120, 120, 120};
  104. static const
  105. uint16_t e1000_igp_2_cable_length_table[IGP02E1000_AGC_LENGTH_TABLE_SIZE] =
  106. { 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 8, 11, 13, 16, 18, 21,
  107. 0, 0, 0, 3, 6, 10, 13, 16, 19, 23, 26, 29, 32, 35, 38, 41,
  108. 6, 10, 14, 18, 22, 26, 30, 33, 37, 41, 44, 48, 51, 54, 58, 61,
  109. 21, 26, 31, 35, 40, 44, 49, 53, 57, 61, 65, 68, 72, 75, 79, 82,
  110. 40, 45, 51, 56, 61, 66, 70, 75, 79, 83, 87, 91, 94, 98, 101, 104,
  111. 60, 66, 72, 77, 82, 87, 92, 96, 100, 104, 108, 111, 114, 117, 119, 121,
  112. 83, 89, 95, 100, 105, 109, 113, 116, 119, 122, 124,
  113. 104, 109, 114, 118, 121, 124};
  114. /******************************************************************************
  115. * Set the phy type member in the hw struct.
  116. *
  117. * hw - Struct containing variables accessed by shared code
  118. *****************************************************************************/
  119. int32_t
  120. e1000_set_phy_type(struct e1000_hw *hw)
  121. {
  122. DEBUGFUNC("e1000_set_phy_type");
  123. if(hw->mac_type == e1000_undefined)
  124. return -E1000_ERR_PHY_TYPE;
  125. switch(hw->phy_id) {
  126. case M88E1000_E_PHY_ID:
  127. case M88E1000_I_PHY_ID:
  128. case M88E1011_I_PHY_ID:
  129. case M88E1111_I_PHY_ID:
  130. hw->phy_type = e1000_phy_m88;
  131. break;
  132. case IGP01E1000_I_PHY_ID:
  133. if(hw->mac_type == e1000_82541 ||
  134. hw->mac_type == e1000_82541_rev_2 ||
  135. hw->mac_type == e1000_82547 ||
  136. hw->mac_type == e1000_82547_rev_2) {
  137. hw->phy_type = e1000_phy_igp;
  138. break;
  139. }
  140. case GG82563_E_PHY_ID:
  141. if (hw->mac_type == e1000_80003es2lan) {
  142. hw->phy_type = e1000_phy_gg82563;
  143. break;
  144. }
  145. /* Fall Through */
  146. default:
  147. /* Should never have loaded on this device */
  148. hw->phy_type = e1000_phy_undefined;
  149. return -E1000_ERR_PHY_TYPE;
  150. }
  151. return E1000_SUCCESS;
  152. }
  153. /******************************************************************************
  154. * IGP phy init script - initializes the GbE PHY
  155. *
  156. * hw - Struct containing variables accessed by shared code
  157. *****************************************************************************/
  158. static void
  159. e1000_phy_init_script(struct e1000_hw *hw)
  160. {
  161. uint32_t ret_val;
  162. uint16_t phy_saved_data;
  163. DEBUGFUNC("e1000_phy_init_script");
  164. if(hw->phy_init_script) {
  165. msec_delay(20);
  166. /* Save off the current value of register 0x2F5B to be restored at
  167. * the end of this routine. */
  168. ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
  169. /* Disabled the PHY transmitter */
  170. e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
  171. msec_delay(20);
  172. e1000_write_phy_reg(hw,0x0000,0x0140);
  173. msec_delay(5);
  174. switch(hw->mac_type) {
  175. case e1000_82541:
  176. case e1000_82547:
  177. e1000_write_phy_reg(hw, 0x1F95, 0x0001);
  178. e1000_write_phy_reg(hw, 0x1F71, 0xBD21);
  179. e1000_write_phy_reg(hw, 0x1F79, 0x0018);
  180. e1000_write_phy_reg(hw, 0x1F30, 0x1600);
  181. e1000_write_phy_reg(hw, 0x1F31, 0x0014);
  182. e1000_write_phy_reg(hw, 0x1F32, 0x161C);
  183. e1000_write_phy_reg(hw, 0x1F94, 0x0003);
  184. e1000_write_phy_reg(hw, 0x1F96, 0x003F);
  185. e1000_write_phy_reg(hw, 0x2010, 0x0008);
  186. break;
  187. case e1000_82541_rev_2:
  188. case e1000_82547_rev_2:
  189. e1000_write_phy_reg(hw, 0x1F73, 0x0099);
  190. break;
  191. default:
  192. break;
  193. }
  194. e1000_write_phy_reg(hw, 0x0000, 0x3300);
  195. msec_delay(20);
  196. /* Now enable the transmitter */
  197. e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
  198. if(hw->mac_type == e1000_82547) {
  199. uint16_t fused, fine, coarse;
  200. /* Move to analog registers page */
  201. e1000_read_phy_reg(hw, IGP01E1000_ANALOG_SPARE_FUSE_STATUS, &fused);
  202. if(!(fused & IGP01E1000_ANALOG_SPARE_FUSE_ENABLED)) {
  203. e1000_read_phy_reg(hw, IGP01E1000_ANALOG_FUSE_STATUS, &fused);
  204. fine = fused & IGP01E1000_ANALOG_FUSE_FINE_MASK;
  205. coarse = fused & IGP01E1000_ANALOG_FUSE_COARSE_MASK;
  206. if(coarse > IGP01E1000_ANALOG_FUSE_COARSE_THRESH) {
  207. coarse -= IGP01E1000_ANALOG_FUSE_COARSE_10;
  208. fine -= IGP01E1000_ANALOG_FUSE_FINE_1;
  209. } else if(coarse == IGP01E1000_ANALOG_FUSE_COARSE_THRESH)
  210. fine -= IGP01E1000_ANALOG_FUSE_FINE_10;
  211. fused = (fused & IGP01E1000_ANALOG_FUSE_POLY_MASK) |
  212. (fine & IGP01E1000_ANALOG_FUSE_FINE_MASK) |
  213. (coarse & IGP01E1000_ANALOG_FUSE_COARSE_MASK);
  214. e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_CONTROL, fused);
  215. e1000_write_phy_reg(hw, IGP01E1000_ANALOG_FUSE_BYPASS,
  216. IGP01E1000_ANALOG_FUSE_ENABLE_SW_CONTROL);
  217. }
  218. }
  219. }
  220. }
  221. /******************************************************************************
  222. * Set the mac type member in the hw struct.
  223. *
  224. * hw - Struct containing variables accessed by shared code
  225. *****************************************************************************/
  226. int32_t
  227. e1000_set_mac_type(struct e1000_hw *hw)
  228. {
  229. DEBUGFUNC("e1000_set_mac_type");
  230. switch (hw->device_id) {
  231. case E1000_DEV_ID_82542:
  232. switch (hw->revision_id) {
  233. case E1000_82542_2_0_REV_ID:
  234. hw->mac_type = e1000_82542_rev2_0;
  235. break;
  236. case E1000_82542_2_1_REV_ID:
  237. hw->mac_type = e1000_82542_rev2_1;
  238. break;
  239. default:
  240. /* Invalid 82542 revision ID */
  241. return -E1000_ERR_MAC_TYPE;
  242. }
  243. break;
  244. case E1000_DEV_ID_82543GC_FIBER:
  245. case E1000_DEV_ID_82543GC_COPPER:
  246. hw->mac_type = e1000_82543;
  247. break;
  248. case E1000_DEV_ID_82544EI_COPPER:
  249. case E1000_DEV_ID_82544EI_FIBER:
  250. case E1000_DEV_ID_82544GC_COPPER:
  251. case E1000_DEV_ID_82544GC_LOM:
  252. hw->mac_type = e1000_82544;
  253. break;
  254. case E1000_DEV_ID_82540EM:
  255. case E1000_DEV_ID_82540EM_LOM:
  256. case E1000_DEV_ID_82540EP:
  257. case E1000_DEV_ID_82540EP_LOM:
  258. case E1000_DEV_ID_82540EP_LP:
  259. hw->mac_type = e1000_82540;
  260. break;
  261. case E1000_DEV_ID_82545EM_COPPER:
  262. case E1000_DEV_ID_82545EM_FIBER:
  263. hw->mac_type = e1000_82545;
  264. break;
  265. case E1000_DEV_ID_82545GM_COPPER:
  266. case E1000_DEV_ID_82545GM_FIBER:
  267. case E1000_DEV_ID_82545GM_SERDES:
  268. hw->mac_type = e1000_82545_rev_3;
  269. break;
  270. case E1000_DEV_ID_82546EB_COPPER:
  271. case E1000_DEV_ID_82546EB_FIBER:
  272. case E1000_DEV_ID_82546EB_QUAD_COPPER:
  273. hw->mac_type = e1000_82546;
  274. break;
  275. case E1000_DEV_ID_82546GB_COPPER:
  276. case E1000_DEV_ID_82546GB_FIBER:
  277. case E1000_DEV_ID_82546GB_SERDES:
  278. case E1000_DEV_ID_82546GB_PCIE:
  279. case E1000_DEV_ID_82546GB_QUAD_COPPER:
  280. case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
  281. hw->mac_type = e1000_82546_rev_3;
  282. break;
  283. case E1000_DEV_ID_82541EI:
  284. case E1000_DEV_ID_82541EI_MOBILE:
  285. hw->mac_type = e1000_82541;
  286. break;
  287. case E1000_DEV_ID_82541ER:
  288. case E1000_DEV_ID_82541GI:
  289. case E1000_DEV_ID_82541GI_LF:
  290. case E1000_DEV_ID_82541GI_MOBILE:
  291. hw->mac_type = e1000_82541_rev_2;
  292. break;
  293. case E1000_DEV_ID_82547EI:
  294. hw->mac_type = e1000_82547;
  295. break;
  296. case E1000_DEV_ID_82547GI:
  297. hw->mac_type = e1000_82547_rev_2;
  298. break;
  299. case E1000_DEV_ID_82571EB_COPPER:
  300. case E1000_DEV_ID_82571EB_FIBER:
  301. case E1000_DEV_ID_82571EB_SERDES:
  302. hw->mac_type = e1000_82571;
  303. break;
  304. case E1000_DEV_ID_82572EI_COPPER:
  305. case E1000_DEV_ID_82572EI_FIBER:
  306. case E1000_DEV_ID_82572EI_SERDES:
  307. hw->mac_type = e1000_82572;
  308. break;
  309. case E1000_DEV_ID_82573E:
  310. case E1000_DEV_ID_82573E_IAMT:
  311. case E1000_DEV_ID_82573L:
  312. hw->mac_type = e1000_82573;
  313. break;
  314. case E1000_DEV_ID_80003ES2LAN_COPPER_DPT:
  315. case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
  316. hw->mac_type = e1000_80003es2lan;
  317. break;
  318. default:
  319. /* Should never have loaded on this device */
  320. return -E1000_ERR_MAC_TYPE;
  321. }
  322. switch(hw->mac_type) {
  323. case e1000_80003es2lan:
  324. hw->swfw_sync_present = TRUE;
  325. /* fall through */
  326. case e1000_82571:
  327. case e1000_82572:
  328. case e1000_82573:
  329. hw->eeprom_semaphore_present = TRUE;
  330. /* fall through */
  331. case e1000_82541:
  332. case e1000_82547:
  333. case e1000_82541_rev_2:
  334. case e1000_82547_rev_2:
  335. hw->asf_firmware_present = TRUE;
  336. break;
  337. default:
  338. break;
  339. }
  340. return E1000_SUCCESS;
  341. }
  342. /*****************************************************************************
  343. * Set media type and TBI compatibility.
  344. *
  345. * hw - Struct containing variables accessed by shared code
  346. * **************************************************************************/
  347. void
  348. e1000_set_media_type(struct e1000_hw *hw)
  349. {
  350. uint32_t status;
  351. DEBUGFUNC("e1000_set_media_type");
  352. if(hw->mac_type != e1000_82543) {
  353. /* tbi_compatibility is only valid on 82543 */
  354. hw->tbi_compatibility_en = FALSE;
  355. }
  356. switch (hw->device_id) {
  357. case E1000_DEV_ID_82545GM_SERDES:
  358. case E1000_DEV_ID_82546GB_SERDES:
  359. case E1000_DEV_ID_82571EB_SERDES:
  360. case E1000_DEV_ID_82572EI_SERDES:
  361. case E1000_DEV_ID_80003ES2LAN_SERDES_DPT:
  362. hw->media_type = e1000_media_type_internal_serdes;
  363. break;
  364. default:
  365. switch (hw->mac_type) {
  366. case e1000_82542_rev2_0:
  367. case e1000_82542_rev2_1:
  368. hw->media_type = e1000_media_type_fiber;
  369. break;
  370. case e1000_82573:
  371. /* The STATUS_TBIMODE bit is reserved or reused for the this
  372. * device.
  373. */
  374. hw->media_type = e1000_media_type_copper;
  375. break;
  376. default:
  377. status = E1000_READ_REG(hw, STATUS);
  378. if (status & E1000_STATUS_TBIMODE) {
  379. hw->media_type = e1000_media_type_fiber;
  380. /* tbi_compatibility not valid on fiber */
  381. hw->tbi_compatibility_en = FALSE;
  382. } else {
  383. hw->media_type = e1000_media_type_copper;
  384. }
  385. break;
  386. }
  387. }
  388. }
  389. /******************************************************************************
  390. * Reset the transmit and receive units; mask and clear all interrupts.
  391. *
  392. * hw - Struct containing variables accessed by shared code
  393. *****************************************************************************/
  394. int32_t
  395. e1000_reset_hw(struct e1000_hw *hw)
  396. {
  397. uint32_t ctrl;
  398. uint32_t ctrl_ext;
  399. uint32_t icr;
  400. uint32_t manc;
  401. uint32_t led_ctrl;
  402. uint32_t timeout;
  403. uint32_t extcnf_ctrl;
  404. int32_t ret_val;
  405. DEBUGFUNC("e1000_reset_hw");
  406. /* For 82542 (rev 2.0), disable MWI before issuing a device reset */
  407. if(hw->mac_type == e1000_82542_rev2_0) {
  408. DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  409. e1000_pci_clear_mwi(hw);
  410. }
  411. if(hw->bus_type == e1000_bus_type_pci_express) {
  412. /* Prevent the PCI-E bus from sticking if there is no TLP connection
  413. * on the last TLP read/write transaction when MAC is reset.
  414. */
  415. if(e1000_disable_pciex_master(hw) != E1000_SUCCESS) {
  416. DEBUGOUT("PCI-E Master disable polling has failed.\n");
  417. }
  418. }
  419. /* Clear interrupt mask to stop board from generating interrupts */
  420. DEBUGOUT("Masking off all interrupts\n");
  421. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  422. /* Disable the Transmit and Receive units. Then delay to allow
  423. * any pending transactions to complete before we hit the MAC with
  424. * the global reset.
  425. */
  426. E1000_WRITE_REG(hw, RCTL, 0);
  427. E1000_WRITE_REG(hw, TCTL, E1000_TCTL_PSP);
  428. E1000_WRITE_FLUSH(hw);
  429. /* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
  430. hw->tbi_compatibility_on = FALSE;
  431. /* Delay to allow any outstanding PCI transactions to complete before
  432. * resetting the device
  433. */
  434. msec_delay(10);
  435. ctrl = E1000_READ_REG(hw, CTRL);
  436. /* Must reset the PHY before resetting the MAC */
  437. if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  438. E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_PHY_RST));
  439. msec_delay(5);
  440. }
  441. /* Must acquire the MDIO ownership before MAC reset.
  442. * Ownership defaults to firmware after a reset. */
  443. if(hw->mac_type == e1000_82573) {
  444. timeout = 10;
  445. extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
  446. extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
  447. do {
  448. E1000_WRITE_REG(hw, EXTCNF_CTRL, extcnf_ctrl);
  449. extcnf_ctrl = E1000_READ_REG(hw, EXTCNF_CTRL);
  450. if(extcnf_ctrl & E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP)
  451. break;
  452. else
  453. extcnf_ctrl |= E1000_EXTCNF_CTRL_MDIO_SW_OWNERSHIP;
  454. msec_delay(2);
  455. timeout--;
  456. } while(timeout);
  457. }
  458. /* Issue a global reset to the MAC. This will reset the chip's
  459. * transmit, receive, DMA, and link units. It will not effect
  460. * the current PCI configuration. The global reset bit is self-
  461. * clearing, and should clear within a microsecond.
  462. */
  463. DEBUGOUT("Issuing a global reset to MAC\n");
  464. switch(hw->mac_type) {
  465. case e1000_82544:
  466. case e1000_82540:
  467. case e1000_82545:
  468. case e1000_82546:
  469. case e1000_82541:
  470. case e1000_82541_rev_2:
  471. /* These controllers can't ack the 64-bit write when issuing the
  472. * reset, so use IO-mapping as a workaround to issue the reset */
  473. E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST));
  474. break;
  475. case e1000_82545_rev_3:
  476. case e1000_82546_rev_3:
  477. /* Reset is performed on a shadow of the control register */
  478. E1000_WRITE_REG(hw, CTRL_DUP, (ctrl | E1000_CTRL_RST));
  479. break;
  480. default:
  481. E1000_WRITE_REG(hw, CTRL, (ctrl | E1000_CTRL_RST));
  482. break;
  483. }
  484. /* After MAC reset, force reload of EEPROM to restore power-on settings to
  485. * device. Later controllers reload the EEPROM automatically, so just wait
  486. * for reload to complete.
  487. */
  488. switch(hw->mac_type) {
  489. case e1000_82542_rev2_0:
  490. case e1000_82542_rev2_1:
  491. case e1000_82543:
  492. case e1000_82544:
  493. /* Wait for reset to complete */
  494. udelay(10);
  495. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  496. ctrl_ext |= E1000_CTRL_EXT_EE_RST;
  497. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  498. E1000_WRITE_FLUSH(hw);
  499. /* Wait for EEPROM reload */
  500. msec_delay(2);
  501. break;
  502. case e1000_82541:
  503. case e1000_82541_rev_2:
  504. case e1000_82547:
  505. case e1000_82547_rev_2:
  506. /* Wait for EEPROM reload */
  507. msec_delay(20);
  508. break;
  509. case e1000_82573:
  510. if (e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
  511. udelay(10);
  512. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  513. ctrl_ext |= E1000_CTRL_EXT_EE_RST;
  514. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  515. E1000_WRITE_FLUSH(hw);
  516. }
  517. /* fall through */
  518. case e1000_82571:
  519. case e1000_82572:
  520. case e1000_80003es2lan:
  521. ret_val = e1000_get_auto_rd_done(hw);
  522. if(ret_val)
  523. /* We don't want to continue accessing MAC registers. */
  524. return ret_val;
  525. break;
  526. default:
  527. /* Wait for EEPROM reload (it happens automatically) */
  528. msec_delay(5);
  529. break;
  530. }
  531. /* Disable HW ARPs on ASF enabled adapters */
  532. if(hw->mac_type >= e1000_82540 && hw->mac_type <= e1000_82547_rev_2) {
  533. manc = E1000_READ_REG(hw, MANC);
  534. manc &= ~(E1000_MANC_ARP_EN);
  535. E1000_WRITE_REG(hw, MANC, manc);
  536. }
  537. if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  538. e1000_phy_init_script(hw);
  539. /* Configure activity LED after PHY reset */
  540. led_ctrl = E1000_READ_REG(hw, LEDCTL);
  541. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  542. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  543. E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
  544. }
  545. /* Clear interrupt mask to stop board from generating interrupts */
  546. DEBUGOUT("Masking off all interrupts\n");
  547. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  548. /* Clear any pending interrupt events. */
  549. icr = E1000_READ_REG(hw, ICR);
  550. /* If MWI was previously enabled, reenable it. */
  551. if(hw->mac_type == e1000_82542_rev2_0) {
  552. if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
  553. e1000_pci_set_mwi(hw);
  554. }
  555. return E1000_SUCCESS;
  556. }
  557. /******************************************************************************
  558. * Performs basic configuration of the adapter.
  559. *
  560. * hw - Struct containing variables accessed by shared code
  561. *
  562. * Assumes that the controller has previously been reset and is in a
  563. * post-reset uninitialized state. Initializes the receive address registers,
  564. * multicast table, and VLAN filter table. Calls routines to setup link
  565. * configuration and flow control settings. Clears all on-chip counters. Leaves
  566. * the transmit and receive units disabled and uninitialized.
  567. *****************************************************************************/
  568. int32_t
  569. e1000_init_hw(struct e1000_hw *hw)
  570. {
  571. uint32_t ctrl;
  572. uint32_t i;
  573. int32_t ret_val;
  574. uint16_t pcix_cmd_word;
  575. uint16_t pcix_stat_hi_word;
  576. uint16_t cmd_mmrbc;
  577. uint16_t stat_mmrbc;
  578. uint32_t mta_size;
  579. uint32_t reg_data;
  580. uint32_t ctrl_ext;
  581. DEBUGFUNC("e1000_init_hw");
  582. /* Initialize Identification LED */
  583. ret_val = e1000_id_led_init(hw);
  584. if(ret_val) {
  585. DEBUGOUT("Error Initializing Identification LED\n");
  586. return ret_val;
  587. }
  588. /* Set the media type and TBI compatibility */
  589. e1000_set_media_type(hw);
  590. /* Disabling VLAN filtering. */
  591. DEBUGOUT("Initializing the IEEE VLAN\n");
  592. if (hw->mac_type < e1000_82545_rev_3)
  593. E1000_WRITE_REG(hw, VET, 0);
  594. e1000_clear_vfta(hw);
  595. /* For 82542 (rev 2.0), disable MWI and put the receiver into reset */
  596. if(hw->mac_type == e1000_82542_rev2_0) {
  597. DEBUGOUT("Disabling MWI on 82542 rev 2.0\n");
  598. e1000_pci_clear_mwi(hw);
  599. E1000_WRITE_REG(hw, RCTL, E1000_RCTL_RST);
  600. E1000_WRITE_FLUSH(hw);
  601. msec_delay(5);
  602. }
  603. /* Setup the receive address. This involves initializing all of the Receive
  604. * Address Registers (RARs 0 - 15).
  605. */
  606. e1000_init_rx_addrs(hw);
  607. /* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */
  608. if(hw->mac_type == e1000_82542_rev2_0) {
  609. E1000_WRITE_REG(hw, RCTL, 0);
  610. E1000_WRITE_FLUSH(hw);
  611. msec_delay(1);
  612. if(hw->pci_cmd_word & CMD_MEM_WRT_INVALIDATE)
  613. e1000_pci_set_mwi(hw);
  614. }
  615. /* Zero out the Multicast HASH table */
  616. DEBUGOUT("Zeroing the MTA\n");
  617. mta_size = E1000_MC_TBL_SIZE;
  618. for(i = 0; i < mta_size; i++)
  619. E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
  620. /* Set the PCI priority bit correctly in the CTRL register. This
  621. * determines if the adapter gives priority to receives, or if it
  622. * gives equal priority to transmits and receives. Valid only on
  623. * 82542 and 82543 silicon.
  624. */
  625. if(hw->dma_fairness && hw->mac_type <= e1000_82543) {
  626. ctrl = E1000_READ_REG(hw, CTRL);
  627. E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PRIOR);
  628. }
  629. switch(hw->mac_type) {
  630. case e1000_82545_rev_3:
  631. case e1000_82546_rev_3:
  632. break;
  633. default:
  634. /* Workaround for PCI-X problem when BIOS sets MMRBC incorrectly. */
  635. if(hw->bus_type == e1000_bus_type_pcix) {
  636. e1000_read_pci_cfg(hw, PCIX_COMMAND_REGISTER, &pcix_cmd_word);
  637. e1000_read_pci_cfg(hw, PCIX_STATUS_REGISTER_HI,
  638. &pcix_stat_hi_word);
  639. cmd_mmrbc = (pcix_cmd_word & PCIX_COMMAND_MMRBC_MASK) >>
  640. PCIX_COMMAND_MMRBC_SHIFT;
  641. stat_mmrbc = (pcix_stat_hi_word & PCIX_STATUS_HI_MMRBC_MASK) >>
  642. PCIX_STATUS_HI_MMRBC_SHIFT;
  643. if(stat_mmrbc == PCIX_STATUS_HI_MMRBC_4K)
  644. stat_mmrbc = PCIX_STATUS_HI_MMRBC_2K;
  645. if(cmd_mmrbc > stat_mmrbc) {
  646. pcix_cmd_word &= ~PCIX_COMMAND_MMRBC_MASK;
  647. pcix_cmd_word |= stat_mmrbc << PCIX_COMMAND_MMRBC_SHIFT;
  648. e1000_write_pci_cfg(hw, PCIX_COMMAND_REGISTER,
  649. &pcix_cmd_word);
  650. }
  651. }
  652. break;
  653. }
  654. /* Call a subroutine to configure the link and setup flow control. */
  655. ret_val = e1000_setup_link(hw);
  656. /* Set the transmit descriptor write-back policy */
  657. if(hw->mac_type > e1000_82544) {
  658. ctrl = E1000_READ_REG(hw, TXDCTL);
  659. ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
  660. switch (hw->mac_type) {
  661. default:
  662. break;
  663. case e1000_82571:
  664. case e1000_82572:
  665. case e1000_82573:
  666. case e1000_80003es2lan:
  667. ctrl |= E1000_TXDCTL_COUNT_DESC;
  668. break;
  669. }
  670. E1000_WRITE_REG(hw, TXDCTL, ctrl);
  671. }
  672. if (hw->mac_type == e1000_82573) {
  673. e1000_enable_tx_pkt_filtering(hw);
  674. }
  675. switch (hw->mac_type) {
  676. default:
  677. break;
  678. case e1000_80003es2lan:
  679. /* Enable retransmit on late collisions */
  680. reg_data = E1000_READ_REG(hw, TCTL);
  681. reg_data |= E1000_TCTL_RTLC;
  682. E1000_WRITE_REG(hw, TCTL, reg_data);
  683. /* Configure Gigabit Carry Extend Padding */
  684. reg_data = E1000_READ_REG(hw, TCTL_EXT);
  685. reg_data &= ~E1000_TCTL_EXT_GCEX_MASK;
  686. reg_data |= DEFAULT_80003ES2LAN_TCTL_EXT_GCEX;
  687. E1000_WRITE_REG(hw, TCTL_EXT, reg_data);
  688. /* Configure Transmit Inter-Packet Gap */
  689. reg_data = E1000_READ_REG(hw, TIPG);
  690. reg_data &= ~E1000_TIPG_IPGT_MASK;
  691. reg_data |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
  692. E1000_WRITE_REG(hw, TIPG, reg_data);
  693. reg_data = E1000_READ_REG_ARRAY(hw, FFLT, 0x0001);
  694. reg_data &= ~0x00100000;
  695. E1000_WRITE_REG_ARRAY(hw, FFLT, 0x0001, reg_data);
  696. /* Fall through */
  697. case e1000_82571:
  698. case e1000_82572:
  699. ctrl = E1000_READ_REG(hw, TXDCTL1);
  700. ctrl = (ctrl & ~E1000_TXDCTL_WTHRESH) | E1000_TXDCTL_FULL_TX_DESC_WB;
  701. if(hw->mac_type >= e1000_82571)
  702. ctrl |= E1000_TXDCTL_COUNT_DESC;
  703. E1000_WRITE_REG(hw, TXDCTL1, ctrl);
  704. break;
  705. }
  706. if (hw->mac_type == e1000_82573) {
  707. uint32_t gcr = E1000_READ_REG(hw, GCR);
  708. gcr |= E1000_GCR_L1_ACT_WITHOUT_L0S_RX;
  709. E1000_WRITE_REG(hw, GCR, gcr);
  710. }
  711. /* Clear all of the statistics registers (clear on read). It is
  712. * important that we do this after we have tried to establish link
  713. * because the symbol error count will increment wildly if there
  714. * is no link.
  715. */
  716. e1000_clear_hw_cntrs(hw);
  717. if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
  718. hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
  719. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  720. /* Relaxed ordering must be disabled to avoid a parity
  721. * error crash in a PCI slot. */
  722. ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
  723. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  724. }
  725. return ret_val;
  726. }
  727. /******************************************************************************
  728. * Adjust SERDES output amplitude based on EEPROM setting.
  729. *
  730. * hw - Struct containing variables accessed by shared code.
  731. *****************************************************************************/
  732. static int32_t
  733. e1000_adjust_serdes_amplitude(struct e1000_hw *hw)
  734. {
  735. uint16_t eeprom_data;
  736. int32_t ret_val;
  737. DEBUGFUNC("e1000_adjust_serdes_amplitude");
  738. if(hw->media_type != e1000_media_type_internal_serdes)
  739. return E1000_SUCCESS;
  740. switch(hw->mac_type) {
  741. case e1000_82545_rev_3:
  742. case e1000_82546_rev_3:
  743. break;
  744. default:
  745. return E1000_SUCCESS;
  746. }
  747. ret_val = e1000_read_eeprom(hw, EEPROM_SERDES_AMPLITUDE, 1, &eeprom_data);
  748. if (ret_val) {
  749. return ret_val;
  750. }
  751. if(eeprom_data != EEPROM_RESERVED_WORD) {
  752. /* Adjust SERDES output amplitude only. */
  753. eeprom_data &= EEPROM_SERDES_AMPLITUDE_MASK;
  754. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_EXT_CTRL, eeprom_data);
  755. if(ret_val)
  756. return ret_val;
  757. }
  758. return E1000_SUCCESS;
  759. }
  760. /******************************************************************************
  761. * Configures flow control and link settings.
  762. *
  763. * hw - Struct containing variables accessed by shared code
  764. *
  765. * Determines which flow control settings to use. Calls the apropriate media-
  766. * specific link configuration function. Configures the flow control settings.
  767. * Assuming the adapter has a valid link partner, a valid link should be
  768. * established. Assumes the hardware has previously been reset and the
  769. * transmitter and receiver are not enabled.
  770. *****************************************************************************/
  771. int32_t
  772. e1000_setup_link(struct e1000_hw *hw)
  773. {
  774. uint32_t ctrl_ext;
  775. int32_t ret_val;
  776. uint16_t eeprom_data;
  777. DEBUGFUNC("e1000_setup_link");
  778. /* In the case of the phy reset being blocked, we already have a link.
  779. * We do not have to set it up again. */
  780. if (e1000_check_phy_reset_block(hw))
  781. return E1000_SUCCESS;
  782. /* Read and store word 0x0F of the EEPROM. This word contains bits
  783. * that determine the hardware's default PAUSE (flow control) mode,
  784. * a bit that determines whether the HW defaults to enabling or
  785. * disabling auto-negotiation, and the direction of the
  786. * SW defined pins. If there is no SW over-ride of the flow
  787. * control setting, then the variable hw->fc will
  788. * be initialized based on a value in the EEPROM.
  789. */
  790. if (hw->fc == e1000_fc_default) {
  791. switch (hw->mac_type) {
  792. case e1000_82573:
  793. hw->fc = e1000_fc_full;
  794. break;
  795. default:
  796. ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
  797. 1, &eeprom_data);
  798. if (ret_val) {
  799. DEBUGOUT("EEPROM Read Error\n");
  800. return -E1000_ERR_EEPROM;
  801. }
  802. if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
  803. hw->fc = e1000_fc_none;
  804. else if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
  805. EEPROM_WORD0F_ASM_DIR)
  806. hw->fc = e1000_fc_tx_pause;
  807. else
  808. hw->fc = e1000_fc_full;
  809. break;
  810. }
  811. }
  812. /* We want to save off the original Flow Control configuration just
  813. * in case we get disconnected and then reconnected into a different
  814. * hub or switch with different Flow Control capabilities.
  815. */
  816. if(hw->mac_type == e1000_82542_rev2_0)
  817. hw->fc &= (~e1000_fc_tx_pause);
  818. if((hw->mac_type < e1000_82543) && (hw->report_tx_early == 1))
  819. hw->fc &= (~e1000_fc_rx_pause);
  820. hw->original_fc = hw->fc;
  821. DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc);
  822. /* Take the 4 bits from EEPROM word 0x0F that determine the initial
  823. * polarity value for the SW controlled pins, and setup the
  824. * Extended Device Control reg with that info.
  825. * This is needed because one of the SW controlled pins is used for
  826. * signal detection. So this should be done before e1000_setup_pcs_link()
  827. * or e1000_phy_setup() is called.
  828. */
  829. if (hw->mac_type == e1000_82543) {
  830. ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG,
  831. 1, &eeprom_data);
  832. if (ret_val) {
  833. DEBUGOUT("EEPROM Read Error\n");
  834. return -E1000_ERR_EEPROM;
  835. }
  836. ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
  837. SWDPIO__EXT_SHIFT);
  838. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  839. }
  840. /* Call the necessary subroutine to configure the link. */
  841. ret_val = (hw->media_type == e1000_media_type_copper) ?
  842. e1000_setup_copper_link(hw) :
  843. e1000_setup_fiber_serdes_link(hw);
  844. /* Initialize the flow control address, type, and PAUSE timer
  845. * registers to their default values. This is done even if flow
  846. * control is disabled, because it does not hurt anything to
  847. * initialize these registers.
  848. */
  849. DEBUGOUT("Initializing the Flow Control address, type and timer regs\n");
  850. E1000_WRITE_REG(hw, FCAL, FLOW_CONTROL_ADDRESS_LOW);
  851. E1000_WRITE_REG(hw, FCAH, FLOW_CONTROL_ADDRESS_HIGH);
  852. E1000_WRITE_REG(hw, FCT, FLOW_CONTROL_TYPE);
  853. E1000_WRITE_REG(hw, FCTTV, hw->fc_pause_time);
  854. /* Set the flow control receive threshold registers. Normally,
  855. * these registers will be set to a default threshold that may be
  856. * adjusted later by the driver's runtime code. However, if the
  857. * ability to transmit pause frames in not enabled, then these
  858. * registers will be set to 0.
  859. */
  860. if(!(hw->fc & e1000_fc_tx_pause)) {
  861. E1000_WRITE_REG(hw, FCRTL, 0);
  862. E1000_WRITE_REG(hw, FCRTH, 0);
  863. } else {
  864. /* We need to set up the Receive Threshold high and low water marks
  865. * as well as (optionally) enabling the transmission of XON frames.
  866. */
  867. if(hw->fc_send_xon) {
  868. E1000_WRITE_REG(hw, FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
  869. E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  870. } else {
  871. E1000_WRITE_REG(hw, FCRTL, hw->fc_low_water);
  872. E1000_WRITE_REG(hw, FCRTH, hw->fc_high_water);
  873. }
  874. }
  875. return ret_val;
  876. }
  877. /******************************************************************************
  878. * Sets up link for a fiber based or serdes based adapter
  879. *
  880. * hw - Struct containing variables accessed by shared code
  881. *
  882. * Manipulates Physical Coding Sublayer functions in order to configure
  883. * link. Assumes the hardware has been previously reset and the transmitter
  884. * and receiver are not enabled.
  885. *****************************************************************************/
  886. static int32_t
  887. e1000_setup_fiber_serdes_link(struct e1000_hw *hw)
  888. {
  889. uint32_t ctrl;
  890. uint32_t status;
  891. uint32_t txcw = 0;
  892. uint32_t i;
  893. uint32_t signal = 0;
  894. int32_t ret_val;
  895. DEBUGFUNC("e1000_setup_fiber_serdes_link");
  896. /* On 82571 and 82572 Fiber connections, SerDes loopback mode persists
  897. * until explicitly turned off or a power cycle is performed. A read to
  898. * the register does not indicate its status. Therefore, we ensure
  899. * loopback mode is disabled during initialization.
  900. */
  901. if (hw->mac_type == e1000_82571 || hw->mac_type == e1000_82572)
  902. E1000_WRITE_REG(hw, SCTL, E1000_DISABLE_SERDES_LOOPBACK);
  903. /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
  904. * set when the optics detect a signal. On older adapters, it will be
  905. * cleared when there is a signal. This applies to fiber media only.
  906. * If we're on serdes media, adjust the output amplitude to value set in
  907. * the EEPROM.
  908. */
  909. ctrl = E1000_READ_REG(hw, CTRL);
  910. if(hw->media_type == e1000_media_type_fiber)
  911. signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
  912. ret_val = e1000_adjust_serdes_amplitude(hw);
  913. if(ret_val)
  914. return ret_val;
  915. /* Take the link out of reset */
  916. ctrl &= ~(E1000_CTRL_LRST);
  917. /* Adjust VCO speed to improve BER performance */
  918. ret_val = e1000_set_vco_speed(hw);
  919. if(ret_val)
  920. return ret_val;
  921. e1000_config_collision_dist(hw);
  922. /* Check for a software override of the flow control settings, and setup
  923. * the device accordingly. If auto-negotiation is enabled, then software
  924. * will have to set the "PAUSE" bits to the correct value in the Tranmsit
  925. * Config Word Register (TXCW) and re-start auto-negotiation. However, if
  926. * auto-negotiation is disabled, then software will have to manually
  927. * configure the two flow control enable bits in the CTRL register.
  928. *
  929. * The possible values of the "fc" parameter are:
  930. * 0: Flow control is completely disabled
  931. * 1: Rx flow control is enabled (we can receive pause frames, but
  932. * not send pause frames).
  933. * 2: Tx flow control is enabled (we can send pause frames but we do
  934. * not support receiving pause frames).
  935. * 3: Both Rx and TX flow control (symmetric) are enabled.
  936. */
  937. switch (hw->fc) {
  938. case e1000_fc_none:
  939. /* Flow control is completely disabled by a software over-ride. */
  940. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD);
  941. break;
  942. case e1000_fc_rx_pause:
  943. /* RX Flow control is enabled and TX Flow control is disabled by a
  944. * software over-ride. Since there really isn't a way to advertise
  945. * that we are capable of RX Pause ONLY, we will advertise that we
  946. * support both symmetric and asymmetric RX PAUSE. Later, we will
  947. * disable the adapter's ability to send PAUSE frames.
  948. */
  949. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  950. break;
  951. case e1000_fc_tx_pause:
  952. /* TX Flow control is enabled, and RX Flow control is disabled, by a
  953. * software over-ride.
  954. */
  955. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR);
  956. break;
  957. case e1000_fc_full:
  958. /* Flow control (both RX and TX) is enabled by a software over-ride. */
  959. txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK);
  960. break;
  961. default:
  962. DEBUGOUT("Flow control param set incorrectly\n");
  963. return -E1000_ERR_CONFIG;
  964. break;
  965. }
  966. /* Since auto-negotiation is enabled, take the link out of reset (the link
  967. * will be in reset, because we previously reset the chip). This will
  968. * restart auto-negotiation. If auto-neogtiation is successful then the
  969. * link-up status bit will be set and the flow control enable bits (RFCE
  970. * and TFCE) will be set according to their negotiated value.
  971. */
  972. DEBUGOUT("Auto-negotiation enabled\n");
  973. E1000_WRITE_REG(hw, TXCW, txcw);
  974. E1000_WRITE_REG(hw, CTRL, ctrl);
  975. E1000_WRITE_FLUSH(hw);
  976. hw->txcw = txcw;
  977. msec_delay(1);
  978. /* If we have a signal (the cable is plugged in) then poll for a "Link-Up"
  979. * indication in the Device Status Register. Time-out if a link isn't
  980. * seen in 500 milliseconds seconds (Auto-negotiation should complete in
  981. * less than 500 milliseconds even if the other end is doing it in SW).
  982. * For internal serdes, we just assume a signal is present, then poll.
  983. */
  984. if(hw->media_type == e1000_media_type_internal_serdes ||
  985. (E1000_READ_REG(hw, CTRL) & E1000_CTRL_SWDPIN1) == signal) {
  986. DEBUGOUT("Looking for Link\n");
  987. for(i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
  988. msec_delay(10);
  989. status = E1000_READ_REG(hw, STATUS);
  990. if(status & E1000_STATUS_LU) break;
  991. }
  992. if(i == (LINK_UP_TIMEOUT / 10)) {
  993. DEBUGOUT("Never got a valid link from auto-neg!!!\n");
  994. hw->autoneg_failed = 1;
  995. /* AutoNeg failed to achieve a link, so we'll call
  996. * e1000_check_for_link. This routine will force the link up if
  997. * we detect a signal. This will allow us to communicate with
  998. * non-autonegotiating link partners.
  999. */
  1000. ret_val = e1000_check_for_link(hw);
  1001. if(ret_val) {
  1002. DEBUGOUT("Error while checking for link\n");
  1003. return ret_val;
  1004. }
  1005. hw->autoneg_failed = 0;
  1006. } else {
  1007. hw->autoneg_failed = 0;
  1008. DEBUGOUT("Valid Link Found\n");
  1009. }
  1010. } else {
  1011. DEBUGOUT("No Signal Detected\n");
  1012. }
  1013. return E1000_SUCCESS;
  1014. }
  1015. /******************************************************************************
  1016. * Make sure we have a valid PHY and change PHY mode before link setup.
  1017. *
  1018. * hw - Struct containing variables accessed by shared code
  1019. ******************************************************************************/
  1020. static int32_t
  1021. e1000_copper_link_preconfig(struct e1000_hw *hw)
  1022. {
  1023. uint32_t ctrl;
  1024. int32_t ret_val;
  1025. uint16_t phy_data;
  1026. DEBUGFUNC("e1000_copper_link_preconfig");
  1027. ctrl = E1000_READ_REG(hw, CTRL);
  1028. /* With 82543, we need to force speed and duplex on the MAC equal to what
  1029. * the PHY speed and duplex configuration is. In addition, we need to
  1030. * perform a hardware reset on the PHY to take it out of reset.
  1031. */
  1032. if(hw->mac_type > e1000_82543) {
  1033. ctrl |= E1000_CTRL_SLU;
  1034. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1035. E1000_WRITE_REG(hw, CTRL, ctrl);
  1036. } else {
  1037. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
  1038. E1000_WRITE_REG(hw, CTRL, ctrl);
  1039. ret_val = e1000_phy_hw_reset(hw);
  1040. if(ret_val)
  1041. return ret_val;
  1042. }
  1043. /* Make sure we have a valid PHY */
  1044. ret_val = e1000_detect_gig_phy(hw);
  1045. if(ret_val) {
  1046. DEBUGOUT("Error, did not detect valid phy.\n");
  1047. return ret_val;
  1048. }
  1049. DEBUGOUT1("Phy ID = %x \n", hw->phy_id);
  1050. /* Set PHY to class A mode (if necessary) */
  1051. ret_val = e1000_set_phy_mode(hw);
  1052. if(ret_val)
  1053. return ret_val;
  1054. if((hw->mac_type == e1000_82545_rev_3) ||
  1055. (hw->mac_type == e1000_82546_rev_3)) {
  1056. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1057. phy_data |= 0x00000008;
  1058. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1059. }
  1060. if(hw->mac_type <= e1000_82543 ||
  1061. hw->mac_type == e1000_82541 || hw->mac_type == e1000_82547 ||
  1062. hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2)
  1063. hw->phy_reset_disable = FALSE;
  1064. return E1000_SUCCESS;
  1065. }
  1066. /********************************************************************
  1067. * Copper link setup for e1000_phy_igp series.
  1068. *
  1069. * hw - Struct containing variables accessed by shared code
  1070. *********************************************************************/
  1071. static int32_t
  1072. e1000_copper_link_igp_setup(struct e1000_hw *hw)
  1073. {
  1074. uint32_t led_ctrl;
  1075. int32_t ret_val;
  1076. uint16_t phy_data;
  1077. DEBUGFUNC("e1000_copper_link_igp_setup");
  1078. if (hw->phy_reset_disable)
  1079. return E1000_SUCCESS;
  1080. ret_val = e1000_phy_reset(hw);
  1081. if (ret_val) {
  1082. DEBUGOUT("Error Resetting the PHY\n");
  1083. return ret_val;
  1084. }
  1085. /* Wait 10ms for MAC to configure PHY from eeprom settings */
  1086. msec_delay(15);
  1087. /* Configure activity LED after PHY reset */
  1088. led_ctrl = E1000_READ_REG(hw, LEDCTL);
  1089. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  1090. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  1091. E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
  1092. /* disable lplu d3 during driver init */
  1093. ret_val = e1000_set_d3_lplu_state(hw, FALSE);
  1094. if (ret_val) {
  1095. DEBUGOUT("Error Disabling LPLU D3\n");
  1096. return ret_val;
  1097. }
  1098. /* disable lplu d0 during driver init */
  1099. ret_val = e1000_set_d0_lplu_state(hw, FALSE);
  1100. if (ret_val) {
  1101. DEBUGOUT("Error Disabling LPLU D0\n");
  1102. return ret_val;
  1103. }
  1104. /* Configure mdi-mdix settings */
  1105. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
  1106. if (ret_val)
  1107. return ret_val;
  1108. if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  1109. hw->dsp_config_state = e1000_dsp_config_disabled;
  1110. /* Force MDI for earlier revs of the IGP PHY */
  1111. phy_data &= ~(IGP01E1000_PSCR_AUTO_MDIX | IGP01E1000_PSCR_FORCE_MDI_MDIX);
  1112. hw->mdix = 1;
  1113. } else {
  1114. hw->dsp_config_state = e1000_dsp_config_enabled;
  1115. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  1116. switch (hw->mdix) {
  1117. case 1:
  1118. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  1119. break;
  1120. case 2:
  1121. phy_data |= IGP01E1000_PSCR_FORCE_MDI_MDIX;
  1122. break;
  1123. case 0:
  1124. default:
  1125. phy_data |= IGP01E1000_PSCR_AUTO_MDIX;
  1126. break;
  1127. }
  1128. }
  1129. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
  1130. if(ret_val)
  1131. return ret_val;
  1132. /* set auto-master slave resolution settings */
  1133. if(hw->autoneg) {
  1134. e1000_ms_type phy_ms_setting = hw->master_slave;
  1135. if(hw->ffe_config_state == e1000_ffe_config_active)
  1136. hw->ffe_config_state = e1000_ffe_config_enabled;
  1137. if(hw->dsp_config_state == e1000_dsp_config_activated)
  1138. hw->dsp_config_state = e1000_dsp_config_enabled;
  1139. /* when autonegotiation advertisment is only 1000Mbps then we
  1140. * should disable SmartSpeed and enable Auto MasterSlave
  1141. * resolution as hardware default. */
  1142. if(hw->autoneg_advertised == ADVERTISE_1000_FULL) {
  1143. /* Disable SmartSpeed */
  1144. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  1145. if(ret_val)
  1146. return ret_val;
  1147. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  1148. ret_val = e1000_write_phy_reg(hw,
  1149. IGP01E1000_PHY_PORT_CONFIG,
  1150. phy_data);
  1151. if(ret_val)
  1152. return ret_val;
  1153. /* Set auto Master/Slave resolution process */
  1154. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
  1155. if(ret_val)
  1156. return ret_val;
  1157. phy_data &= ~CR_1000T_MS_ENABLE;
  1158. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
  1159. if(ret_val)
  1160. return ret_val;
  1161. }
  1162. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &phy_data);
  1163. if(ret_val)
  1164. return ret_val;
  1165. /* load defaults for future use */
  1166. hw->original_master_slave = (phy_data & CR_1000T_MS_ENABLE) ?
  1167. ((phy_data & CR_1000T_MS_VALUE) ?
  1168. e1000_ms_force_master :
  1169. e1000_ms_force_slave) :
  1170. e1000_ms_auto;
  1171. switch (phy_ms_setting) {
  1172. case e1000_ms_force_master:
  1173. phy_data |= (CR_1000T_MS_ENABLE | CR_1000T_MS_VALUE);
  1174. break;
  1175. case e1000_ms_force_slave:
  1176. phy_data |= CR_1000T_MS_ENABLE;
  1177. phy_data &= ~(CR_1000T_MS_VALUE);
  1178. break;
  1179. case e1000_ms_auto:
  1180. phy_data &= ~CR_1000T_MS_ENABLE;
  1181. default:
  1182. break;
  1183. }
  1184. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, phy_data);
  1185. if(ret_val)
  1186. return ret_val;
  1187. }
  1188. return E1000_SUCCESS;
  1189. }
  1190. /********************************************************************
  1191. * Copper link setup for e1000_phy_gg82563 series.
  1192. *
  1193. * hw - Struct containing variables accessed by shared code
  1194. *********************************************************************/
  1195. static int32_t
  1196. e1000_copper_link_ggp_setup(struct e1000_hw *hw)
  1197. {
  1198. int32_t ret_val;
  1199. uint16_t phy_data;
  1200. uint32_t reg_data;
  1201. DEBUGFUNC("e1000_copper_link_ggp_setup");
  1202. if(!hw->phy_reset_disable) {
  1203. /* Enable CRS on TX for half-duplex operation. */
  1204. ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
  1205. &phy_data);
  1206. if(ret_val)
  1207. return ret_val;
  1208. phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
  1209. /* Use 25MHz for both link down and 1000BASE-T for Tx clock */
  1210. phy_data |= GG82563_MSCR_TX_CLK_1000MBPS_25MHZ;
  1211. ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL,
  1212. phy_data);
  1213. if(ret_val)
  1214. return ret_val;
  1215. /* Options:
  1216. * MDI/MDI-X = 0 (default)
  1217. * 0 - Auto for all speeds
  1218. * 1 - MDI mode
  1219. * 2 - MDI-X mode
  1220. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  1221. */
  1222. ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL, &phy_data);
  1223. if(ret_val)
  1224. return ret_val;
  1225. phy_data &= ~GG82563_PSCR_CROSSOVER_MODE_MASK;
  1226. switch (hw->mdix) {
  1227. case 1:
  1228. phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDI;
  1229. break;
  1230. case 2:
  1231. phy_data |= GG82563_PSCR_CROSSOVER_MODE_MDIX;
  1232. break;
  1233. case 0:
  1234. default:
  1235. phy_data |= GG82563_PSCR_CROSSOVER_MODE_AUTO;
  1236. break;
  1237. }
  1238. /* Options:
  1239. * disable_polarity_correction = 0 (default)
  1240. * Automatic Correction for Reversed Cable Polarity
  1241. * 0 - Disabled
  1242. * 1 - Enabled
  1243. */
  1244. phy_data &= ~GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
  1245. if(hw->disable_polarity_correction == 1)
  1246. phy_data |= GG82563_PSCR_POLARITY_REVERSAL_DISABLE;
  1247. ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL, phy_data);
  1248. if(ret_val)
  1249. return ret_val;
  1250. /* SW Reset the PHY so all changes take effect */
  1251. ret_val = e1000_phy_reset(hw);
  1252. if (ret_val) {
  1253. DEBUGOUT("Error Resetting the PHY\n");
  1254. return ret_val;
  1255. }
  1256. } /* phy_reset_disable */
  1257. if (hw->mac_type == e1000_80003es2lan) {
  1258. /* Bypass RX and TX FIFO's */
  1259. ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_FIFO_CTRL,
  1260. E1000_KUMCTRLSTA_FIFO_CTRL_RX_BYPASS |
  1261. E1000_KUMCTRLSTA_FIFO_CTRL_TX_BYPASS);
  1262. if (ret_val)
  1263. return ret_val;
  1264. ret_val = e1000_read_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, &phy_data);
  1265. if (ret_val)
  1266. return ret_val;
  1267. phy_data &= ~GG82563_PSCR2_REVERSE_AUTO_NEG;
  1268. ret_val = e1000_write_phy_reg(hw, GG82563_PHY_SPEC_CTRL_2, phy_data);
  1269. if (ret_val)
  1270. return ret_val;
  1271. reg_data = E1000_READ_REG(hw, CTRL_EXT);
  1272. reg_data &= ~(E1000_CTRL_EXT_LINK_MODE_MASK);
  1273. E1000_WRITE_REG(hw, CTRL_EXT, reg_data);
  1274. ret_val = e1000_read_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
  1275. &phy_data);
  1276. if (ret_val)
  1277. return ret_val;
  1278. /* Do not init these registers when the HW is in IAMT mode, since the
  1279. * firmware will have already initialized them. We only initialize
  1280. * them if the HW is not in IAMT mode.
  1281. */
  1282. if (e1000_check_mng_mode(hw) == FALSE) {
  1283. /* Enable Electrical Idle on the PHY */
  1284. phy_data |= GG82563_PMCR_ENABLE_ELECTRICAL_IDLE;
  1285. ret_val = e1000_write_phy_reg(hw, GG82563_PHY_PWR_MGMT_CTRL,
  1286. phy_data);
  1287. if (ret_val)
  1288. return ret_val;
  1289. ret_val = e1000_read_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
  1290. &phy_data);
  1291. if (ret_val)
  1292. return ret_val;
  1293. /* Enable Pass False Carrier on the PHY */
  1294. phy_data |= GG82563_KMCR_PASS_FALSE_CARRIER;
  1295. ret_val = e1000_write_phy_reg(hw, GG82563_PHY_KMRN_MODE_CTRL,
  1296. phy_data);
  1297. if (ret_val)
  1298. return ret_val;
  1299. }
  1300. /* Workaround: Disable padding in Kumeran interface in the MAC
  1301. * and in the PHY to avoid CRC errors.
  1302. */
  1303. ret_val = e1000_read_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
  1304. &phy_data);
  1305. if (ret_val)
  1306. return ret_val;
  1307. phy_data |= GG82563_ICR_DIS_PADDING;
  1308. ret_val = e1000_write_phy_reg(hw, GG82563_PHY_INBAND_CTRL,
  1309. phy_data);
  1310. if (ret_val)
  1311. return ret_val;
  1312. }
  1313. return E1000_SUCCESS;
  1314. }
  1315. /********************************************************************
  1316. * Copper link setup for e1000_phy_m88 series.
  1317. *
  1318. * hw - Struct containing variables accessed by shared code
  1319. *********************************************************************/
  1320. static int32_t
  1321. e1000_copper_link_mgp_setup(struct e1000_hw *hw)
  1322. {
  1323. int32_t ret_val;
  1324. uint16_t phy_data;
  1325. DEBUGFUNC("e1000_copper_link_mgp_setup");
  1326. if(hw->phy_reset_disable)
  1327. return E1000_SUCCESS;
  1328. /* Enable CRS on TX. This must be set for half-duplex operation. */
  1329. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1330. if(ret_val)
  1331. return ret_val;
  1332. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  1333. /* Options:
  1334. * MDI/MDI-X = 0 (default)
  1335. * 0 - Auto for all speeds
  1336. * 1 - MDI mode
  1337. * 2 - MDI-X mode
  1338. * 3 - Auto for 1000Base-T only (MDI-X for 10/100Base-T modes)
  1339. */
  1340. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  1341. switch (hw->mdix) {
  1342. case 1:
  1343. phy_data |= M88E1000_PSCR_MDI_MANUAL_MODE;
  1344. break;
  1345. case 2:
  1346. phy_data |= M88E1000_PSCR_MDIX_MANUAL_MODE;
  1347. break;
  1348. case 3:
  1349. phy_data |= M88E1000_PSCR_AUTO_X_1000T;
  1350. break;
  1351. case 0:
  1352. default:
  1353. phy_data |= M88E1000_PSCR_AUTO_X_MODE;
  1354. break;
  1355. }
  1356. /* Options:
  1357. * disable_polarity_correction = 0 (default)
  1358. * Automatic Correction for Reversed Cable Polarity
  1359. * 0 - Disabled
  1360. * 1 - Enabled
  1361. */
  1362. phy_data &= ~M88E1000_PSCR_POLARITY_REVERSAL;
  1363. if(hw->disable_polarity_correction == 1)
  1364. phy_data |= M88E1000_PSCR_POLARITY_REVERSAL;
  1365. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1366. if(ret_val)
  1367. return ret_val;
  1368. /* Force TX_CLK in the Extended PHY Specific Control Register
  1369. * to 25MHz clock.
  1370. */
  1371. ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  1372. if(ret_val)
  1373. return ret_val;
  1374. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  1375. if (hw->phy_revision < M88E1011_I_REV_4) {
  1376. /* Configure Master and Slave downshift values */
  1377. phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
  1378. M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
  1379. phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
  1380. M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
  1381. ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  1382. if(ret_val)
  1383. return ret_val;
  1384. }
  1385. /* SW Reset the PHY so all changes take effect */
  1386. ret_val = e1000_phy_reset(hw);
  1387. if(ret_val) {
  1388. DEBUGOUT("Error Resetting the PHY\n");
  1389. return ret_val;
  1390. }
  1391. return E1000_SUCCESS;
  1392. }
  1393. /********************************************************************
  1394. * Setup auto-negotiation and flow control advertisements,
  1395. * and then perform auto-negotiation.
  1396. *
  1397. * hw - Struct containing variables accessed by shared code
  1398. *********************************************************************/
  1399. static int32_t
  1400. e1000_copper_link_autoneg(struct e1000_hw *hw)
  1401. {
  1402. int32_t ret_val;
  1403. uint16_t phy_data;
  1404. DEBUGFUNC("e1000_copper_link_autoneg");
  1405. /* Perform some bounds checking on the hw->autoneg_advertised
  1406. * parameter. If this variable is zero, then set it to the default.
  1407. */
  1408. hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
  1409. /* If autoneg_advertised is zero, we assume it was not defaulted
  1410. * by the calling code so we set to advertise full capability.
  1411. */
  1412. if(hw->autoneg_advertised == 0)
  1413. hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  1414. DEBUGOUT("Reconfiguring auto-neg advertisement params\n");
  1415. ret_val = e1000_phy_setup_autoneg(hw);
  1416. if(ret_val) {
  1417. DEBUGOUT("Error Setting up Auto-Negotiation\n");
  1418. return ret_val;
  1419. }
  1420. DEBUGOUT("Restarting Auto-Neg\n");
  1421. /* Restart auto-negotiation by setting the Auto Neg Enable bit and
  1422. * the Auto Neg Restart bit in the PHY control register.
  1423. */
  1424. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
  1425. if(ret_val)
  1426. return ret_val;
  1427. phy_data |= (MII_CR_AUTO_NEG_EN | MII_CR_RESTART_AUTO_NEG);
  1428. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
  1429. if(ret_val)
  1430. return ret_val;
  1431. /* Does the user want to wait for Auto-Neg to complete here, or
  1432. * check at a later time (for example, callback routine).
  1433. */
  1434. if(hw->wait_autoneg_complete) {
  1435. ret_val = e1000_wait_autoneg(hw);
  1436. if(ret_val) {
  1437. DEBUGOUT("Error while waiting for autoneg to complete\n");
  1438. return ret_val;
  1439. }
  1440. }
  1441. hw->get_link_status = TRUE;
  1442. return E1000_SUCCESS;
  1443. }
  1444. /******************************************************************************
  1445. * Config the MAC and the PHY after link is up.
  1446. * 1) Set up the MAC to the current PHY speed/duplex
  1447. * if we are on 82543. If we
  1448. * are on newer silicon, we only need to configure
  1449. * collision distance in the Transmit Control Register.
  1450. * 2) Set up flow control on the MAC to that established with
  1451. * the link partner.
  1452. * 3) Config DSP to improve Gigabit link quality for some PHY revisions.
  1453. *
  1454. * hw - Struct containing variables accessed by shared code
  1455. ******************************************************************************/
  1456. static int32_t
  1457. e1000_copper_link_postconfig(struct e1000_hw *hw)
  1458. {
  1459. int32_t ret_val;
  1460. DEBUGFUNC("e1000_copper_link_postconfig");
  1461. if(hw->mac_type >= e1000_82544) {
  1462. e1000_config_collision_dist(hw);
  1463. } else {
  1464. ret_val = e1000_config_mac_to_phy(hw);
  1465. if(ret_val) {
  1466. DEBUGOUT("Error configuring MAC to PHY settings\n");
  1467. return ret_val;
  1468. }
  1469. }
  1470. ret_val = e1000_config_fc_after_link_up(hw);
  1471. if(ret_val) {
  1472. DEBUGOUT("Error Configuring Flow Control\n");
  1473. return ret_val;
  1474. }
  1475. /* Config DSP to improve Giga link quality */
  1476. if(hw->phy_type == e1000_phy_igp) {
  1477. ret_val = e1000_config_dsp_after_link_change(hw, TRUE);
  1478. if(ret_val) {
  1479. DEBUGOUT("Error Configuring DSP after link up\n");
  1480. return ret_val;
  1481. }
  1482. }
  1483. return E1000_SUCCESS;
  1484. }
  1485. /******************************************************************************
  1486. * Detects which PHY is present and setup the speed and duplex
  1487. *
  1488. * hw - Struct containing variables accessed by shared code
  1489. ******************************************************************************/
  1490. static int32_t
  1491. e1000_setup_copper_link(struct e1000_hw *hw)
  1492. {
  1493. int32_t ret_val;
  1494. uint16_t i;
  1495. uint16_t phy_data;
  1496. uint16_t reg_data;
  1497. DEBUGFUNC("e1000_setup_copper_link");
  1498. /* Check if it is a valid PHY and set PHY mode if necessary. */
  1499. ret_val = e1000_copper_link_preconfig(hw);
  1500. if(ret_val)
  1501. return ret_val;
  1502. switch (hw->mac_type) {
  1503. case e1000_80003es2lan:
  1504. ret_val = e1000_read_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
  1505. &reg_data);
  1506. if (ret_val)
  1507. return ret_val;
  1508. reg_data |= E1000_KUMCTRLSTA_INB_CTRL_DIS_PADDING;
  1509. ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_INB_CTRL,
  1510. reg_data);
  1511. if (ret_val)
  1512. return ret_val;
  1513. break;
  1514. default:
  1515. break;
  1516. }
  1517. if (hw->phy_type == e1000_phy_igp ||
  1518. hw->phy_type == e1000_phy_igp_2) {
  1519. ret_val = e1000_copper_link_igp_setup(hw);
  1520. if(ret_val)
  1521. return ret_val;
  1522. } else if (hw->phy_type == e1000_phy_m88) {
  1523. ret_val = e1000_copper_link_mgp_setup(hw);
  1524. if(ret_val)
  1525. return ret_val;
  1526. } else if (hw->phy_type == e1000_phy_gg82563) {
  1527. ret_val = e1000_copper_link_ggp_setup(hw);
  1528. if(ret_val)
  1529. return ret_val;
  1530. }
  1531. if(hw->autoneg) {
  1532. /* Setup autoneg and flow control advertisement
  1533. * and perform autonegotiation */
  1534. ret_val = e1000_copper_link_autoneg(hw);
  1535. if(ret_val)
  1536. return ret_val;
  1537. } else {
  1538. /* PHY will be set to 10H, 10F, 100H,or 100F
  1539. * depending on value from forced_speed_duplex. */
  1540. DEBUGOUT("Forcing speed and duplex\n");
  1541. ret_val = e1000_phy_force_speed_duplex(hw);
  1542. if(ret_val) {
  1543. DEBUGOUT("Error Forcing Speed and Duplex\n");
  1544. return ret_val;
  1545. }
  1546. }
  1547. /* Check link status. Wait up to 100 microseconds for link to become
  1548. * valid.
  1549. */
  1550. for(i = 0; i < 10; i++) {
  1551. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  1552. if(ret_val)
  1553. return ret_val;
  1554. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  1555. if(ret_val)
  1556. return ret_val;
  1557. if(phy_data & MII_SR_LINK_STATUS) {
  1558. /* Config the MAC and PHY after link is up */
  1559. ret_val = e1000_copper_link_postconfig(hw);
  1560. if(ret_val)
  1561. return ret_val;
  1562. DEBUGOUT("Valid link established!!!\n");
  1563. return E1000_SUCCESS;
  1564. }
  1565. udelay(10);
  1566. }
  1567. DEBUGOUT("Unable to establish link!!!\n");
  1568. return E1000_SUCCESS;
  1569. }
  1570. /******************************************************************************
  1571. * Configure the MAC-to-PHY interface for 10/100Mbps
  1572. *
  1573. * hw - Struct containing variables accessed by shared code
  1574. ******************************************************************************/
  1575. static int32_t
  1576. e1000_configure_kmrn_for_10_100(struct e1000_hw *hw)
  1577. {
  1578. int32_t ret_val = E1000_SUCCESS;
  1579. uint32_t tipg;
  1580. uint16_t reg_data;
  1581. DEBUGFUNC("e1000_configure_kmrn_for_10_100");
  1582. reg_data = E1000_KUMCTRLSTA_HD_CTRL_10_100_DEFAULT;
  1583. ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
  1584. reg_data);
  1585. if (ret_val)
  1586. return ret_val;
  1587. /* Configure Transmit Inter-Packet Gap */
  1588. tipg = E1000_READ_REG(hw, TIPG);
  1589. tipg &= ~E1000_TIPG_IPGT_MASK;
  1590. tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_10_100;
  1591. E1000_WRITE_REG(hw, TIPG, tipg);
  1592. return ret_val;
  1593. }
  1594. static int32_t
  1595. e1000_configure_kmrn_for_1000(struct e1000_hw *hw)
  1596. {
  1597. int32_t ret_val = E1000_SUCCESS;
  1598. uint16_t reg_data;
  1599. uint32_t tipg;
  1600. DEBUGFUNC("e1000_configure_kmrn_for_1000");
  1601. reg_data = E1000_KUMCTRLSTA_HD_CTRL_1000_DEFAULT;
  1602. ret_val = e1000_write_kmrn_reg(hw, E1000_KUMCTRLSTA_OFFSET_HD_CTRL,
  1603. reg_data);
  1604. if (ret_val)
  1605. return ret_val;
  1606. /* Configure Transmit Inter-Packet Gap */
  1607. tipg = E1000_READ_REG(hw, TIPG);
  1608. tipg &= ~E1000_TIPG_IPGT_MASK;
  1609. tipg |= DEFAULT_80003ES2LAN_TIPG_IPGT_1000;
  1610. E1000_WRITE_REG(hw, TIPG, tipg);
  1611. return ret_val;
  1612. }
  1613. /******************************************************************************
  1614. * Configures PHY autoneg and flow control advertisement settings
  1615. *
  1616. * hw - Struct containing variables accessed by shared code
  1617. ******************************************************************************/
  1618. int32_t
  1619. e1000_phy_setup_autoneg(struct e1000_hw *hw)
  1620. {
  1621. int32_t ret_val;
  1622. uint16_t mii_autoneg_adv_reg;
  1623. uint16_t mii_1000t_ctrl_reg;
  1624. DEBUGFUNC("e1000_phy_setup_autoneg");
  1625. /* Read the MII Auto-Neg Advertisement Register (Address 4). */
  1626. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg);
  1627. if(ret_val)
  1628. return ret_val;
  1629. /* Read the MII 1000Base-T Control Register (Address 9). */
  1630. ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg);
  1631. if(ret_val)
  1632. return ret_val;
  1633. /* Need to parse both autoneg_advertised and fc and set up
  1634. * the appropriate PHY registers. First we will parse for
  1635. * autoneg_advertised software override. Since we can advertise
  1636. * a plethora of combinations, we need to check each bit
  1637. * individually.
  1638. */
  1639. /* First we clear all the 10/100 mb speed bits in the Auto-Neg
  1640. * Advertisement Register (Address 4) and the 1000 mb speed bits in
  1641. * the 1000Base-T Control Register (Address 9).
  1642. */
  1643. mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
  1644. mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
  1645. DEBUGOUT1("autoneg_advertised %x\n", hw->autoneg_advertised);
  1646. /* Do we want to advertise 10 Mb Half Duplex? */
  1647. if(hw->autoneg_advertised & ADVERTISE_10_HALF) {
  1648. DEBUGOUT("Advertise 10mb Half duplex\n");
  1649. mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
  1650. }
  1651. /* Do we want to advertise 10 Mb Full Duplex? */
  1652. if(hw->autoneg_advertised & ADVERTISE_10_FULL) {
  1653. DEBUGOUT("Advertise 10mb Full duplex\n");
  1654. mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
  1655. }
  1656. /* Do we want to advertise 100 Mb Half Duplex? */
  1657. if(hw->autoneg_advertised & ADVERTISE_100_HALF) {
  1658. DEBUGOUT("Advertise 100mb Half duplex\n");
  1659. mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
  1660. }
  1661. /* Do we want to advertise 100 Mb Full Duplex? */
  1662. if(hw->autoneg_advertised & ADVERTISE_100_FULL) {
  1663. DEBUGOUT("Advertise 100mb Full duplex\n");
  1664. mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
  1665. }
  1666. /* We do not allow the Phy to advertise 1000 Mb Half Duplex */
  1667. if(hw->autoneg_advertised & ADVERTISE_1000_HALF) {
  1668. DEBUGOUT("Advertise 1000mb Half duplex requested, request denied!\n");
  1669. }
  1670. /* Do we want to advertise 1000 Mb Full Duplex? */
  1671. if(hw->autoneg_advertised & ADVERTISE_1000_FULL) {
  1672. DEBUGOUT("Advertise 1000mb Full duplex\n");
  1673. mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
  1674. }
  1675. /* Check for a software override of the flow control settings, and
  1676. * setup the PHY advertisement registers accordingly. If
  1677. * auto-negotiation is enabled, then software will have to set the
  1678. * "PAUSE" bits to the correct value in the Auto-Negotiation
  1679. * Advertisement Register (PHY_AUTONEG_ADV) and re-start auto-negotiation.
  1680. *
  1681. * The possible values of the "fc" parameter are:
  1682. * 0: Flow control is completely disabled
  1683. * 1: Rx flow control is enabled (we can receive pause frames
  1684. * but not send pause frames).
  1685. * 2: Tx flow control is enabled (we can send pause frames
  1686. * but we do not support receiving pause frames).
  1687. * 3: Both Rx and TX flow control (symmetric) are enabled.
  1688. * other: No software override. The flow control configuration
  1689. * in the EEPROM is used.
  1690. */
  1691. switch (hw->fc) {
  1692. case e1000_fc_none: /* 0 */
  1693. /* Flow control (RX & TX) is completely disabled by a
  1694. * software over-ride.
  1695. */
  1696. mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  1697. break;
  1698. case e1000_fc_rx_pause: /* 1 */
  1699. /* RX Flow control is enabled, and TX Flow control is
  1700. * disabled, by a software over-ride.
  1701. */
  1702. /* Since there really isn't a way to advertise that we are
  1703. * capable of RX Pause ONLY, we will advertise that we
  1704. * support both symmetric and asymmetric RX PAUSE. Later
  1705. * (in e1000_config_fc_after_link_up) we will disable the
  1706. *hw's ability to send PAUSE frames.
  1707. */
  1708. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  1709. break;
  1710. case e1000_fc_tx_pause: /* 2 */
  1711. /* TX Flow control is enabled, and RX Flow control is
  1712. * disabled, by a software over-ride.
  1713. */
  1714. mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
  1715. mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE;
  1716. break;
  1717. case e1000_fc_full: /* 3 */
  1718. /* Flow control (both RX and TX) is enabled by a software
  1719. * over-ride.
  1720. */
  1721. mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE);
  1722. break;
  1723. default:
  1724. DEBUGOUT("Flow control param set incorrectly\n");
  1725. return -E1000_ERR_CONFIG;
  1726. }
  1727. ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg);
  1728. if(ret_val)
  1729. return ret_val;
  1730. DEBUGOUT1("Auto-Neg Advertising %x\n", mii_autoneg_adv_reg);
  1731. ret_val = e1000_write_phy_reg(hw, PHY_1000T_CTRL, mii_1000t_ctrl_reg);
  1732. if(ret_val)
  1733. return ret_val;
  1734. return E1000_SUCCESS;
  1735. }
  1736. /******************************************************************************
  1737. * Force PHY speed and duplex settings to hw->forced_speed_duplex
  1738. *
  1739. * hw - Struct containing variables accessed by shared code
  1740. ******************************************************************************/
  1741. static int32_t
  1742. e1000_phy_force_speed_duplex(struct e1000_hw *hw)
  1743. {
  1744. uint32_t ctrl;
  1745. int32_t ret_val;
  1746. uint16_t mii_ctrl_reg;
  1747. uint16_t mii_status_reg;
  1748. uint16_t phy_data;
  1749. uint16_t i;
  1750. DEBUGFUNC("e1000_phy_force_speed_duplex");
  1751. /* Turn off Flow control if we are forcing speed and duplex. */
  1752. hw->fc = e1000_fc_none;
  1753. DEBUGOUT1("hw->fc = %d\n", hw->fc);
  1754. /* Read the Device Control Register. */
  1755. ctrl = E1000_READ_REG(hw, CTRL);
  1756. /* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
  1757. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1758. ctrl &= ~(DEVICE_SPEED_MASK);
  1759. /* Clear the Auto Speed Detect Enable bit. */
  1760. ctrl &= ~E1000_CTRL_ASDE;
  1761. /* Read the MII Control Register. */
  1762. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg);
  1763. if(ret_val)
  1764. return ret_val;
  1765. /* We need to disable autoneg in order to force link and duplex. */
  1766. mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
  1767. /* Are we forcing Full or Half Duplex? */
  1768. if(hw->forced_speed_duplex == e1000_100_full ||
  1769. hw->forced_speed_duplex == e1000_10_full) {
  1770. /* We want to force full duplex so we SET the full duplex bits in the
  1771. * Device and MII Control Registers.
  1772. */
  1773. ctrl |= E1000_CTRL_FD;
  1774. mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
  1775. DEBUGOUT("Full Duplex\n");
  1776. } else {
  1777. /* We want to force half duplex so we CLEAR the full duplex bits in
  1778. * the Device and MII Control Registers.
  1779. */
  1780. ctrl &= ~E1000_CTRL_FD;
  1781. mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
  1782. DEBUGOUT("Half Duplex\n");
  1783. }
  1784. /* Are we forcing 100Mbps??? */
  1785. if(hw->forced_speed_duplex == e1000_100_full ||
  1786. hw->forced_speed_duplex == e1000_100_half) {
  1787. /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
  1788. ctrl |= E1000_CTRL_SPD_100;
  1789. mii_ctrl_reg |= MII_CR_SPEED_100;
  1790. mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
  1791. DEBUGOUT("Forcing 100mb ");
  1792. } else {
  1793. /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
  1794. ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
  1795. mii_ctrl_reg |= MII_CR_SPEED_10;
  1796. mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
  1797. DEBUGOUT("Forcing 10mb ");
  1798. }
  1799. e1000_config_collision_dist(hw);
  1800. /* Write the configured values back to the Device Control Reg. */
  1801. E1000_WRITE_REG(hw, CTRL, ctrl);
  1802. if ((hw->phy_type == e1000_phy_m88) ||
  1803. (hw->phy_type == e1000_phy_gg82563)) {
  1804. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1805. if(ret_val)
  1806. return ret_val;
  1807. /* Clear Auto-Crossover to force MDI manually. M88E1000 requires MDI
  1808. * forced whenever speed are duplex are forced.
  1809. */
  1810. phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
  1811. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1812. if(ret_val)
  1813. return ret_val;
  1814. DEBUGOUT1("M88E1000 PSCR: %x \n", phy_data);
  1815. /* Need to reset the PHY or these changes will be ignored */
  1816. mii_ctrl_reg |= MII_CR_RESET;
  1817. } else {
  1818. /* Clear Auto-Crossover to force MDI manually. IGP requires MDI
  1819. * forced whenever speed or duplex are forced.
  1820. */
  1821. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data);
  1822. if(ret_val)
  1823. return ret_val;
  1824. phy_data &= ~IGP01E1000_PSCR_AUTO_MDIX;
  1825. phy_data &= ~IGP01E1000_PSCR_FORCE_MDI_MDIX;
  1826. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data);
  1827. if(ret_val)
  1828. return ret_val;
  1829. }
  1830. /* Write back the modified PHY MII control register. */
  1831. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg);
  1832. if(ret_val)
  1833. return ret_val;
  1834. udelay(1);
  1835. /* The wait_autoneg_complete flag may be a little misleading here.
  1836. * Since we are forcing speed and duplex, Auto-Neg is not enabled.
  1837. * But we do want to delay for a period while forcing only so we
  1838. * don't generate false No Link messages. So we will wait here
  1839. * only if the user has set wait_autoneg_complete to 1, which is
  1840. * the default.
  1841. */
  1842. if(hw->wait_autoneg_complete) {
  1843. /* We will wait for autoneg to complete. */
  1844. DEBUGOUT("Waiting for forced speed/duplex link.\n");
  1845. mii_status_reg = 0;
  1846. /* We will wait for autoneg to complete or 4.5 seconds to expire. */
  1847. for(i = PHY_FORCE_TIME; i > 0; i--) {
  1848. /* Read the MII Status Register and wait for Auto-Neg Complete bit
  1849. * to be set.
  1850. */
  1851. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1852. if(ret_val)
  1853. return ret_val;
  1854. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1855. if(ret_val)
  1856. return ret_val;
  1857. if(mii_status_reg & MII_SR_LINK_STATUS) break;
  1858. msec_delay(100);
  1859. }
  1860. if((i == 0) &&
  1861. ((hw->phy_type == e1000_phy_m88) ||
  1862. (hw->phy_type == e1000_phy_gg82563))) {
  1863. /* We didn't get link. Reset the DSP and wait again for link. */
  1864. ret_val = e1000_phy_reset_dsp(hw);
  1865. if(ret_val) {
  1866. DEBUGOUT("Error Resetting PHY DSP\n");
  1867. return ret_val;
  1868. }
  1869. }
  1870. /* This loop will early-out if the link condition has been met. */
  1871. for(i = PHY_FORCE_TIME; i > 0; i--) {
  1872. if(mii_status_reg & MII_SR_LINK_STATUS) break;
  1873. msec_delay(100);
  1874. /* Read the MII Status Register and wait for Auto-Neg Complete bit
  1875. * to be set.
  1876. */
  1877. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1878. if(ret_val)
  1879. return ret_val;
  1880. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  1881. if(ret_val)
  1882. return ret_val;
  1883. }
  1884. }
  1885. if (hw->phy_type == e1000_phy_m88) {
  1886. /* Because we reset the PHY above, we need to re-force TX_CLK in the
  1887. * Extended PHY Specific Control Register to 25MHz clock. This value
  1888. * defaults back to a 2.5MHz clock when the PHY is reset.
  1889. */
  1890. ret_val = e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, &phy_data);
  1891. if(ret_val)
  1892. return ret_val;
  1893. phy_data |= M88E1000_EPSCR_TX_CLK_25;
  1894. ret_val = e1000_write_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL, phy_data);
  1895. if(ret_val)
  1896. return ret_val;
  1897. /* In addition, because of the s/w reset above, we need to enable CRS on
  1898. * TX. This must be set for both full and half duplex operation.
  1899. */
  1900. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  1901. if(ret_val)
  1902. return ret_val;
  1903. phy_data |= M88E1000_PSCR_ASSERT_CRS_ON_TX;
  1904. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data);
  1905. if(ret_val)
  1906. return ret_val;
  1907. if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
  1908. (!hw->autoneg) &&
  1909. (hw->forced_speed_duplex == e1000_10_full ||
  1910. hw->forced_speed_duplex == e1000_10_half)) {
  1911. ret_val = e1000_polarity_reversal_workaround(hw);
  1912. if(ret_val)
  1913. return ret_val;
  1914. }
  1915. } else if (hw->phy_type == e1000_phy_gg82563) {
  1916. /* The TX_CLK of the Extended PHY Specific Control Register defaults
  1917. * to 2.5MHz on a reset. We need to re-force it back to 25MHz, if
  1918. * we're not in a forced 10/duplex configuration. */
  1919. ret_val = e1000_read_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, &phy_data);
  1920. if (ret_val)
  1921. return ret_val;
  1922. phy_data &= ~GG82563_MSCR_TX_CLK_MASK;
  1923. if ((hw->forced_speed_duplex == e1000_10_full) ||
  1924. (hw->forced_speed_duplex == e1000_10_half))
  1925. phy_data |= GG82563_MSCR_TX_CLK_10MBPS_2_5MHZ;
  1926. else
  1927. phy_data |= GG82563_MSCR_TX_CLK_100MBPS_25MHZ;
  1928. /* Also due to the reset, we need to enable CRS on Tx. */
  1929. phy_data |= GG82563_MSCR_ASSERT_CRS_ON_TX;
  1930. ret_val = e1000_write_phy_reg(hw, GG82563_PHY_MAC_SPEC_CTRL, phy_data);
  1931. if (ret_val)
  1932. return ret_val;
  1933. }
  1934. return E1000_SUCCESS;
  1935. }
  1936. /******************************************************************************
  1937. * Sets the collision distance in the Transmit Control register
  1938. *
  1939. * hw - Struct containing variables accessed by shared code
  1940. *
  1941. * Link should have been established previously. Reads the speed and duplex
  1942. * information from the Device Status register.
  1943. ******************************************************************************/
  1944. void
  1945. e1000_config_collision_dist(struct e1000_hw *hw)
  1946. {
  1947. uint32_t tctl, coll_dist;
  1948. DEBUGFUNC("e1000_config_collision_dist");
  1949. if (hw->mac_type < e1000_82543)
  1950. coll_dist = E1000_COLLISION_DISTANCE_82542;
  1951. else
  1952. coll_dist = E1000_COLLISION_DISTANCE;
  1953. tctl = E1000_READ_REG(hw, TCTL);
  1954. tctl &= ~E1000_TCTL_COLD;
  1955. tctl |= coll_dist << E1000_COLD_SHIFT;
  1956. E1000_WRITE_REG(hw, TCTL, tctl);
  1957. E1000_WRITE_FLUSH(hw);
  1958. }
  1959. /******************************************************************************
  1960. * Sets MAC speed and duplex settings to reflect the those in the PHY
  1961. *
  1962. * hw - Struct containing variables accessed by shared code
  1963. * mii_reg - data to write to the MII control register
  1964. *
  1965. * The contents of the PHY register containing the needed information need to
  1966. * be passed in.
  1967. ******************************************************************************/
  1968. static int32_t
  1969. e1000_config_mac_to_phy(struct e1000_hw *hw)
  1970. {
  1971. uint32_t ctrl;
  1972. int32_t ret_val;
  1973. uint16_t phy_data;
  1974. DEBUGFUNC("e1000_config_mac_to_phy");
  1975. /* 82544 or newer MAC, Auto Speed Detection takes care of
  1976. * MAC speed/duplex configuration.*/
  1977. if (hw->mac_type >= e1000_82544)
  1978. return E1000_SUCCESS;
  1979. /* Read the Device Control Register and set the bits to Force Speed
  1980. * and Duplex.
  1981. */
  1982. ctrl = E1000_READ_REG(hw, CTRL);
  1983. ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  1984. ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
  1985. /* Set up duplex in the Device Control and Transmit Control
  1986. * registers depending on negotiated values.
  1987. */
  1988. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  1989. if(ret_val)
  1990. return ret_val;
  1991. if(phy_data & M88E1000_PSSR_DPLX)
  1992. ctrl |= E1000_CTRL_FD;
  1993. else
  1994. ctrl &= ~E1000_CTRL_FD;
  1995. e1000_config_collision_dist(hw);
  1996. /* Set up speed in the Device Control register depending on
  1997. * negotiated values.
  1998. */
  1999. if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
  2000. ctrl |= E1000_CTRL_SPD_1000;
  2001. else if((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_100MBS)
  2002. ctrl |= E1000_CTRL_SPD_100;
  2003. /* Write the configured values back to the Device Control Reg. */
  2004. E1000_WRITE_REG(hw, CTRL, ctrl);
  2005. return E1000_SUCCESS;
  2006. }
  2007. /******************************************************************************
  2008. * Forces the MAC's flow control settings.
  2009. *
  2010. * hw - Struct containing variables accessed by shared code
  2011. *
  2012. * Sets the TFCE and RFCE bits in the device control register to reflect
  2013. * the adapter settings. TFCE and RFCE need to be explicitly set by
  2014. * software when a Copper PHY is used because autonegotiation is managed
  2015. * by the PHY rather than the MAC. Software must also configure these
  2016. * bits when link is forced on a fiber connection.
  2017. *****************************************************************************/
  2018. int32_t
  2019. e1000_force_mac_fc(struct e1000_hw *hw)
  2020. {
  2021. uint32_t ctrl;
  2022. DEBUGFUNC("e1000_force_mac_fc");
  2023. /* Get the current configuration of the Device Control Register */
  2024. ctrl = E1000_READ_REG(hw, CTRL);
  2025. /* Because we didn't get link via the internal auto-negotiation
  2026. * mechanism (we either forced link or we got link via PHY
  2027. * auto-neg), we have to manually enable/disable transmit an
  2028. * receive flow control.
  2029. *
  2030. * The "Case" statement below enables/disable flow control
  2031. * according to the "hw->fc" parameter.
  2032. *
  2033. * The possible values of the "fc" parameter are:
  2034. * 0: Flow control is completely disabled
  2035. * 1: Rx flow control is enabled (we can receive pause
  2036. * frames but not send pause frames).
  2037. * 2: Tx flow control is enabled (we can send pause frames
  2038. * frames but we do not receive pause frames).
  2039. * 3: Both Rx and TX flow control (symmetric) is enabled.
  2040. * other: No other values should be possible at this point.
  2041. */
  2042. switch (hw->fc) {
  2043. case e1000_fc_none:
  2044. ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE));
  2045. break;
  2046. case e1000_fc_rx_pause:
  2047. ctrl &= (~E1000_CTRL_TFCE);
  2048. ctrl |= E1000_CTRL_RFCE;
  2049. break;
  2050. case e1000_fc_tx_pause:
  2051. ctrl &= (~E1000_CTRL_RFCE);
  2052. ctrl |= E1000_CTRL_TFCE;
  2053. break;
  2054. case e1000_fc_full:
  2055. ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE);
  2056. break;
  2057. default:
  2058. DEBUGOUT("Flow control param set incorrectly\n");
  2059. return -E1000_ERR_CONFIG;
  2060. }
  2061. /* Disable TX Flow Control for 82542 (rev 2.0) */
  2062. if(hw->mac_type == e1000_82542_rev2_0)
  2063. ctrl &= (~E1000_CTRL_TFCE);
  2064. E1000_WRITE_REG(hw, CTRL, ctrl);
  2065. return E1000_SUCCESS;
  2066. }
  2067. /******************************************************************************
  2068. * Configures flow control settings after link is established
  2069. *
  2070. * hw - Struct containing variables accessed by shared code
  2071. *
  2072. * Should be called immediately after a valid link has been established.
  2073. * Forces MAC flow control settings if link was forced. When in MII/GMII mode
  2074. * and autonegotiation is enabled, the MAC flow control settings will be set
  2075. * based on the flow control negotiated by the PHY. In TBI mode, the TFCE
  2076. * and RFCE bits will be automaticaly set to the negotiated flow control mode.
  2077. *****************************************************************************/
  2078. static int32_t
  2079. e1000_config_fc_after_link_up(struct e1000_hw *hw)
  2080. {
  2081. int32_t ret_val;
  2082. uint16_t mii_status_reg;
  2083. uint16_t mii_nway_adv_reg;
  2084. uint16_t mii_nway_lp_ability_reg;
  2085. uint16_t speed;
  2086. uint16_t duplex;
  2087. DEBUGFUNC("e1000_config_fc_after_link_up");
  2088. /* Check for the case where we have fiber media and auto-neg failed
  2089. * so we had to force link. In this case, we need to force the
  2090. * configuration of the MAC to match the "fc" parameter.
  2091. */
  2092. if(((hw->media_type == e1000_media_type_fiber) && (hw->autoneg_failed)) ||
  2093. ((hw->media_type == e1000_media_type_internal_serdes) && (hw->autoneg_failed)) ||
  2094. ((hw->media_type == e1000_media_type_copper) && (!hw->autoneg))) {
  2095. ret_val = e1000_force_mac_fc(hw);
  2096. if(ret_val) {
  2097. DEBUGOUT("Error forcing flow control settings\n");
  2098. return ret_val;
  2099. }
  2100. }
  2101. /* Check for the case where we have copper media and auto-neg is
  2102. * enabled. In this case, we need to check and see if Auto-Neg
  2103. * has completed, and if so, how the PHY and link partner has
  2104. * flow control configured.
  2105. */
  2106. if((hw->media_type == e1000_media_type_copper) && hw->autoneg) {
  2107. /* Read the MII Status Register and check to see if AutoNeg
  2108. * has completed. We read this twice because this reg has
  2109. * some "sticky" (latched) bits.
  2110. */
  2111. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  2112. if(ret_val)
  2113. return ret_val;
  2114. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  2115. if(ret_val)
  2116. return ret_val;
  2117. if(mii_status_reg & MII_SR_AUTONEG_COMPLETE) {
  2118. /* The AutoNeg process has completed, so we now need to
  2119. * read both the Auto Negotiation Advertisement Register
  2120. * (Address 4) and the Auto_Negotiation Base Page Ability
  2121. * Register (Address 5) to determine how flow control was
  2122. * negotiated.
  2123. */
  2124. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
  2125. &mii_nway_adv_reg);
  2126. if(ret_val)
  2127. return ret_val;
  2128. ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
  2129. &mii_nway_lp_ability_reg);
  2130. if(ret_val)
  2131. return ret_val;
  2132. /* Two bits in the Auto Negotiation Advertisement Register
  2133. * (Address 4) and two bits in the Auto Negotiation Base
  2134. * Page Ability Register (Address 5) determine flow control
  2135. * for both the PHY and the link partner. The following
  2136. * table, taken out of the IEEE 802.3ab/D6.0 dated March 25,
  2137. * 1999, describes these PAUSE resolution bits and how flow
  2138. * control is determined based upon these settings.
  2139. * NOTE: DC = Don't Care
  2140. *
  2141. * LOCAL DEVICE | LINK PARTNER
  2142. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | NIC Resolution
  2143. *-------|---------|-------|---------|--------------------
  2144. * 0 | 0 | DC | DC | e1000_fc_none
  2145. * 0 | 1 | 0 | DC | e1000_fc_none
  2146. * 0 | 1 | 1 | 0 | e1000_fc_none
  2147. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  2148. * 1 | 0 | 0 | DC | e1000_fc_none
  2149. * 1 | DC | 1 | DC | e1000_fc_full
  2150. * 1 | 1 | 0 | 0 | e1000_fc_none
  2151. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  2152. *
  2153. */
  2154. /* Are both PAUSE bits set to 1? If so, this implies
  2155. * Symmetric Flow Control is enabled at both ends. The
  2156. * ASM_DIR bits are irrelevant per the spec.
  2157. *
  2158. * For Symmetric Flow Control:
  2159. *
  2160. * LOCAL DEVICE | LINK PARTNER
  2161. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  2162. *-------|---------|-------|---------|--------------------
  2163. * 1 | DC | 1 | DC | e1000_fc_full
  2164. *
  2165. */
  2166. if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  2167. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) {
  2168. /* Now we need to check if the user selected RX ONLY
  2169. * of pause frames. In this case, we had to advertise
  2170. * FULL flow control because we could not advertise RX
  2171. * ONLY. Hence, we must now check to see if we need to
  2172. * turn OFF the TRANSMISSION of PAUSE frames.
  2173. */
  2174. if(hw->original_fc == e1000_fc_full) {
  2175. hw->fc = e1000_fc_full;
  2176. DEBUGOUT("Flow Control = FULL.\n");
  2177. } else {
  2178. hw->fc = e1000_fc_rx_pause;
  2179. DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
  2180. }
  2181. }
  2182. /* For receiving PAUSE frames ONLY.
  2183. *
  2184. * LOCAL DEVICE | LINK PARTNER
  2185. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  2186. *-------|---------|-------|---------|--------------------
  2187. * 0 | 1 | 1 | 1 | e1000_fc_tx_pause
  2188. *
  2189. */
  2190. else if(!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  2191. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  2192. (mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  2193. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  2194. hw->fc = e1000_fc_tx_pause;
  2195. DEBUGOUT("Flow Control = TX PAUSE frames only.\n");
  2196. }
  2197. /* For transmitting PAUSE frames ONLY.
  2198. *
  2199. * LOCAL DEVICE | LINK PARTNER
  2200. * PAUSE | ASM_DIR | PAUSE | ASM_DIR | Result
  2201. *-------|---------|-------|---------|--------------------
  2202. * 1 | 1 | 0 | 1 | e1000_fc_rx_pause
  2203. *
  2204. */
  2205. else if((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
  2206. (mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
  2207. !(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
  2208. (mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
  2209. hw->fc = e1000_fc_rx_pause;
  2210. DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
  2211. }
  2212. /* Per the IEEE spec, at this point flow control should be
  2213. * disabled. However, we want to consider that we could
  2214. * be connected to a legacy switch that doesn't advertise
  2215. * desired flow control, but can be forced on the link
  2216. * partner. So if we advertised no flow control, that is
  2217. * what we will resolve to. If we advertised some kind of
  2218. * receive capability (Rx Pause Only or Full Flow Control)
  2219. * and the link partner advertised none, we will configure
  2220. * ourselves to enable Rx Flow Control only. We can do
  2221. * this safely for two reasons: If the link partner really
  2222. * didn't want flow control enabled, and we enable Rx, no
  2223. * harm done since we won't be receiving any PAUSE frames
  2224. * anyway. If the intent on the link partner was to have
  2225. * flow control enabled, then by us enabling RX only, we
  2226. * can at least receive pause frames and process them.
  2227. * This is a good idea because in most cases, since we are
  2228. * predominantly a server NIC, more times than not we will
  2229. * be asked to delay transmission of packets than asking
  2230. * our link partner to pause transmission of frames.
  2231. */
  2232. else if((hw->original_fc == e1000_fc_none ||
  2233. hw->original_fc == e1000_fc_tx_pause) ||
  2234. hw->fc_strict_ieee) {
  2235. hw->fc = e1000_fc_none;
  2236. DEBUGOUT("Flow Control = NONE.\n");
  2237. } else {
  2238. hw->fc = e1000_fc_rx_pause;
  2239. DEBUGOUT("Flow Control = RX PAUSE frames only.\n");
  2240. }
  2241. /* Now we need to do one last check... If we auto-
  2242. * negotiated to HALF DUPLEX, flow control should not be
  2243. * enabled per IEEE 802.3 spec.
  2244. */
  2245. ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
  2246. if(ret_val) {
  2247. DEBUGOUT("Error getting link speed and duplex\n");
  2248. return ret_val;
  2249. }
  2250. if(duplex == HALF_DUPLEX)
  2251. hw->fc = e1000_fc_none;
  2252. /* Now we call a subroutine to actually force the MAC
  2253. * controller to use the correct flow control settings.
  2254. */
  2255. ret_val = e1000_force_mac_fc(hw);
  2256. if(ret_val) {
  2257. DEBUGOUT("Error forcing flow control settings\n");
  2258. return ret_val;
  2259. }
  2260. } else {
  2261. DEBUGOUT("Copper PHY and Auto Neg has not completed.\n");
  2262. }
  2263. }
  2264. return E1000_SUCCESS;
  2265. }
  2266. /******************************************************************************
  2267. * Checks to see if the link status of the hardware has changed.
  2268. *
  2269. * hw - Struct containing variables accessed by shared code
  2270. *
  2271. * Called by any function that needs to check the link status of the adapter.
  2272. *****************************************************************************/
  2273. int32_t
  2274. e1000_check_for_link(struct e1000_hw *hw)
  2275. {
  2276. uint32_t rxcw = 0;
  2277. uint32_t ctrl;
  2278. uint32_t status;
  2279. uint32_t rctl;
  2280. uint32_t icr;
  2281. uint32_t signal = 0;
  2282. int32_t ret_val;
  2283. uint16_t phy_data;
  2284. DEBUGFUNC("e1000_check_for_link");
  2285. ctrl = E1000_READ_REG(hw, CTRL);
  2286. status = E1000_READ_REG(hw, STATUS);
  2287. /* On adapters with a MAC newer than 82544, SW Defineable pin 1 will be
  2288. * set when the optics detect a signal. On older adapters, it will be
  2289. * cleared when there is a signal. This applies to fiber media only.
  2290. */
  2291. if((hw->media_type == e1000_media_type_fiber) ||
  2292. (hw->media_type == e1000_media_type_internal_serdes)) {
  2293. rxcw = E1000_READ_REG(hw, RXCW);
  2294. if(hw->media_type == e1000_media_type_fiber) {
  2295. signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
  2296. if(status & E1000_STATUS_LU)
  2297. hw->get_link_status = FALSE;
  2298. }
  2299. }
  2300. /* If we have a copper PHY then we only want to go out to the PHY
  2301. * registers to see if Auto-Neg has completed and/or if our link
  2302. * status has changed. The get_link_status flag will be set if we
  2303. * receive a Link Status Change interrupt or we have Rx Sequence
  2304. * Errors.
  2305. */
  2306. if((hw->media_type == e1000_media_type_copper) && hw->get_link_status) {
  2307. /* First we want to see if the MII Status Register reports
  2308. * link. If so, then we want to get the current speed/duplex
  2309. * of the PHY.
  2310. * Read the register twice since the link bit is sticky.
  2311. */
  2312. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2313. if(ret_val)
  2314. return ret_val;
  2315. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2316. if(ret_val)
  2317. return ret_val;
  2318. if(phy_data & MII_SR_LINK_STATUS) {
  2319. hw->get_link_status = FALSE;
  2320. /* Check if there was DownShift, must be checked immediately after
  2321. * link-up */
  2322. e1000_check_downshift(hw);
  2323. /* If we are on 82544 or 82543 silicon and speed/duplex
  2324. * are forced to 10H or 10F, then we will implement the polarity
  2325. * reversal workaround. We disable interrupts first, and upon
  2326. * returning, place the devices interrupt state to its previous
  2327. * value except for the link status change interrupt which will
  2328. * happen due to the execution of this workaround.
  2329. */
  2330. if((hw->mac_type == e1000_82544 || hw->mac_type == e1000_82543) &&
  2331. (!hw->autoneg) &&
  2332. (hw->forced_speed_duplex == e1000_10_full ||
  2333. hw->forced_speed_duplex == e1000_10_half)) {
  2334. E1000_WRITE_REG(hw, IMC, 0xffffffff);
  2335. ret_val = e1000_polarity_reversal_workaround(hw);
  2336. icr = E1000_READ_REG(hw, ICR);
  2337. E1000_WRITE_REG(hw, ICS, (icr & ~E1000_ICS_LSC));
  2338. E1000_WRITE_REG(hw, IMS, IMS_ENABLE_MASK);
  2339. }
  2340. } else {
  2341. /* No link detected */
  2342. e1000_config_dsp_after_link_change(hw, FALSE);
  2343. return 0;
  2344. }
  2345. /* If we are forcing speed/duplex, then we simply return since
  2346. * we have already determined whether we have link or not.
  2347. */
  2348. if(!hw->autoneg) return -E1000_ERR_CONFIG;
  2349. /* optimize the dsp settings for the igp phy */
  2350. e1000_config_dsp_after_link_change(hw, TRUE);
  2351. /* We have a M88E1000 PHY and Auto-Neg is enabled. If we
  2352. * have Si on board that is 82544 or newer, Auto
  2353. * Speed Detection takes care of MAC speed/duplex
  2354. * configuration. So we only need to configure Collision
  2355. * Distance in the MAC. Otherwise, we need to force
  2356. * speed/duplex on the MAC to the current PHY speed/duplex
  2357. * settings.
  2358. */
  2359. if(hw->mac_type >= e1000_82544)
  2360. e1000_config_collision_dist(hw);
  2361. else {
  2362. ret_val = e1000_config_mac_to_phy(hw);
  2363. if(ret_val) {
  2364. DEBUGOUT("Error configuring MAC to PHY settings\n");
  2365. return ret_val;
  2366. }
  2367. }
  2368. /* Configure Flow Control now that Auto-Neg has completed. First, we
  2369. * need to restore the desired flow control settings because we may
  2370. * have had to re-autoneg with a different link partner.
  2371. */
  2372. ret_val = e1000_config_fc_after_link_up(hw);
  2373. if(ret_val) {
  2374. DEBUGOUT("Error configuring flow control\n");
  2375. return ret_val;
  2376. }
  2377. /* At this point we know that we are on copper and we have
  2378. * auto-negotiated link. These are conditions for checking the link
  2379. * partner capability register. We use the link speed to determine if
  2380. * TBI compatibility needs to be turned on or off. If the link is not
  2381. * at gigabit speed, then TBI compatibility is not needed. If we are
  2382. * at gigabit speed, we turn on TBI compatibility.
  2383. */
  2384. if(hw->tbi_compatibility_en) {
  2385. uint16_t speed, duplex;
  2386. e1000_get_speed_and_duplex(hw, &speed, &duplex);
  2387. if(speed != SPEED_1000) {
  2388. /* If link speed is not set to gigabit speed, we do not need
  2389. * to enable TBI compatibility.
  2390. */
  2391. if(hw->tbi_compatibility_on) {
  2392. /* If we previously were in the mode, turn it off. */
  2393. rctl = E1000_READ_REG(hw, RCTL);
  2394. rctl &= ~E1000_RCTL_SBP;
  2395. E1000_WRITE_REG(hw, RCTL, rctl);
  2396. hw->tbi_compatibility_on = FALSE;
  2397. }
  2398. } else {
  2399. /* If TBI compatibility is was previously off, turn it on. For
  2400. * compatibility with a TBI link partner, we will store bad
  2401. * packets. Some frames have an additional byte on the end and
  2402. * will look like CRC errors to to the hardware.
  2403. */
  2404. if(!hw->tbi_compatibility_on) {
  2405. hw->tbi_compatibility_on = TRUE;
  2406. rctl = E1000_READ_REG(hw, RCTL);
  2407. rctl |= E1000_RCTL_SBP;
  2408. E1000_WRITE_REG(hw, RCTL, rctl);
  2409. }
  2410. }
  2411. }
  2412. }
  2413. /* If we don't have link (auto-negotiation failed or link partner cannot
  2414. * auto-negotiate), the cable is plugged in (we have signal), and our
  2415. * link partner is not trying to auto-negotiate with us (we are receiving
  2416. * idles or data), we need to force link up. We also need to give
  2417. * auto-negotiation time to complete, in case the cable was just plugged
  2418. * in. The autoneg_failed flag does this.
  2419. */
  2420. else if((((hw->media_type == e1000_media_type_fiber) &&
  2421. ((ctrl & E1000_CTRL_SWDPIN1) == signal)) ||
  2422. (hw->media_type == e1000_media_type_internal_serdes)) &&
  2423. (!(status & E1000_STATUS_LU)) &&
  2424. (!(rxcw & E1000_RXCW_C))) {
  2425. if(hw->autoneg_failed == 0) {
  2426. hw->autoneg_failed = 1;
  2427. return 0;
  2428. }
  2429. DEBUGOUT("NOT RXing /C/, disable AutoNeg and force link.\n");
  2430. /* Disable auto-negotiation in the TXCW register */
  2431. E1000_WRITE_REG(hw, TXCW, (hw->txcw & ~E1000_TXCW_ANE));
  2432. /* Force link-up and also force full-duplex. */
  2433. ctrl = E1000_READ_REG(hw, CTRL);
  2434. ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
  2435. E1000_WRITE_REG(hw, CTRL, ctrl);
  2436. /* Configure Flow Control after forcing link up. */
  2437. ret_val = e1000_config_fc_after_link_up(hw);
  2438. if(ret_val) {
  2439. DEBUGOUT("Error configuring flow control\n");
  2440. return ret_val;
  2441. }
  2442. }
  2443. /* If we are forcing link and we are receiving /C/ ordered sets, re-enable
  2444. * auto-negotiation in the TXCW register and disable forced link in the
  2445. * Device Control register in an attempt to auto-negotiate with our link
  2446. * partner.
  2447. */
  2448. else if(((hw->media_type == e1000_media_type_fiber) ||
  2449. (hw->media_type == e1000_media_type_internal_serdes)) &&
  2450. (ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) {
  2451. DEBUGOUT("RXing /C/, enable AutoNeg and stop forcing link.\n");
  2452. E1000_WRITE_REG(hw, TXCW, hw->txcw);
  2453. E1000_WRITE_REG(hw, CTRL, (ctrl & ~E1000_CTRL_SLU));
  2454. hw->serdes_link_down = FALSE;
  2455. }
  2456. /* If we force link for non-auto-negotiation switch, check link status
  2457. * based on MAC synchronization for internal serdes media type.
  2458. */
  2459. else if((hw->media_type == e1000_media_type_internal_serdes) &&
  2460. !(E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
  2461. /* SYNCH bit and IV bit are sticky. */
  2462. udelay(10);
  2463. if(E1000_RXCW_SYNCH & E1000_READ_REG(hw, RXCW)) {
  2464. if(!(rxcw & E1000_RXCW_IV)) {
  2465. hw->serdes_link_down = FALSE;
  2466. DEBUGOUT("SERDES: Link is up.\n");
  2467. }
  2468. } else {
  2469. hw->serdes_link_down = TRUE;
  2470. DEBUGOUT("SERDES: Link is down.\n");
  2471. }
  2472. }
  2473. if((hw->media_type == e1000_media_type_internal_serdes) &&
  2474. (E1000_TXCW_ANE & E1000_READ_REG(hw, TXCW))) {
  2475. hw->serdes_link_down = !(E1000_STATUS_LU & E1000_READ_REG(hw, STATUS));
  2476. }
  2477. return E1000_SUCCESS;
  2478. }
  2479. /******************************************************************************
  2480. * Detects the current speed and duplex settings of the hardware.
  2481. *
  2482. * hw - Struct containing variables accessed by shared code
  2483. * speed - Speed of the connection
  2484. * duplex - Duplex setting of the connection
  2485. *****************************************************************************/
  2486. int32_t
  2487. e1000_get_speed_and_duplex(struct e1000_hw *hw,
  2488. uint16_t *speed,
  2489. uint16_t *duplex)
  2490. {
  2491. uint32_t status;
  2492. int32_t ret_val;
  2493. uint16_t phy_data;
  2494. DEBUGFUNC("e1000_get_speed_and_duplex");
  2495. if(hw->mac_type >= e1000_82543) {
  2496. status = E1000_READ_REG(hw, STATUS);
  2497. if(status & E1000_STATUS_SPEED_1000) {
  2498. *speed = SPEED_1000;
  2499. DEBUGOUT("1000 Mbs, ");
  2500. } else if(status & E1000_STATUS_SPEED_100) {
  2501. *speed = SPEED_100;
  2502. DEBUGOUT("100 Mbs, ");
  2503. } else {
  2504. *speed = SPEED_10;
  2505. DEBUGOUT("10 Mbs, ");
  2506. }
  2507. if(status & E1000_STATUS_FD) {
  2508. *duplex = FULL_DUPLEX;
  2509. DEBUGOUT("Full Duplex\n");
  2510. } else {
  2511. *duplex = HALF_DUPLEX;
  2512. DEBUGOUT(" Half Duplex\n");
  2513. }
  2514. } else {
  2515. DEBUGOUT("1000 Mbs, Full Duplex\n");
  2516. *speed = SPEED_1000;
  2517. *duplex = FULL_DUPLEX;
  2518. }
  2519. /* IGP01 PHY may advertise full duplex operation after speed downgrade even
  2520. * if it is operating at half duplex. Here we set the duplex settings to
  2521. * match the duplex in the link partner's capabilities.
  2522. */
  2523. if(hw->phy_type == e1000_phy_igp && hw->speed_downgraded) {
  2524. ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_EXP, &phy_data);
  2525. if(ret_val)
  2526. return ret_val;
  2527. if(!(phy_data & NWAY_ER_LP_NWAY_CAPS))
  2528. *duplex = HALF_DUPLEX;
  2529. else {
  2530. ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY, &phy_data);
  2531. if(ret_val)
  2532. return ret_val;
  2533. if((*speed == SPEED_100 && !(phy_data & NWAY_LPAR_100TX_FD_CAPS)) ||
  2534. (*speed == SPEED_10 && !(phy_data & NWAY_LPAR_10T_FD_CAPS)))
  2535. *duplex = HALF_DUPLEX;
  2536. }
  2537. }
  2538. if ((hw->mac_type == e1000_80003es2lan) &&
  2539. (hw->media_type == e1000_media_type_copper)) {
  2540. if (*speed == SPEED_1000)
  2541. ret_val = e1000_configure_kmrn_for_1000(hw);
  2542. else
  2543. ret_val = e1000_configure_kmrn_for_10_100(hw);
  2544. if (ret_val)
  2545. return ret_val;
  2546. }
  2547. return E1000_SUCCESS;
  2548. }
  2549. /******************************************************************************
  2550. * Blocks until autoneg completes or times out (~4.5 seconds)
  2551. *
  2552. * hw - Struct containing variables accessed by shared code
  2553. ******************************************************************************/
  2554. static int32_t
  2555. e1000_wait_autoneg(struct e1000_hw *hw)
  2556. {
  2557. int32_t ret_val;
  2558. uint16_t i;
  2559. uint16_t phy_data;
  2560. DEBUGFUNC("e1000_wait_autoneg");
  2561. DEBUGOUT("Waiting for Auto-Neg to complete.\n");
  2562. /* We will wait for autoneg to complete or 4.5 seconds to expire. */
  2563. for(i = PHY_AUTO_NEG_TIME; i > 0; i--) {
  2564. /* Read the MII Status Register and wait for Auto-Neg
  2565. * Complete bit to be set.
  2566. */
  2567. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2568. if(ret_val)
  2569. return ret_val;
  2570. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  2571. if(ret_val)
  2572. return ret_val;
  2573. if(phy_data & MII_SR_AUTONEG_COMPLETE) {
  2574. return E1000_SUCCESS;
  2575. }
  2576. msec_delay(100);
  2577. }
  2578. return E1000_SUCCESS;
  2579. }
  2580. /******************************************************************************
  2581. * Raises the Management Data Clock
  2582. *
  2583. * hw - Struct containing variables accessed by shared code
  2584. * ctrl - Device control register's current value
  2585. ******************************************************************************/
  2586. static void
  2587. e1000_raise_mdi_clk(struct e1000_hw *hw,
  2588. uint32_t *ctrl)
  2589. {
  2590. /* Raise the clock input to the Management Data Clock (by setting the MDC
  2591. * bit), and then delay 10 microseconds.
  2592. */
  2593. E1000_WRITE_REG(hw, CTRL, (*ctrl | E1000_CTRL_MDC));
  2594. E1000_WRITE_FLUSH(hw);
  2595. udelay(10);
  2596. }
  2597. /******************************************************************************
  2598. * Lowers the Management Data Clock
  2599. *
  2600. * hw - Struct containing variables accessed by shared code
  2601. * ctrl - Device control register's current value
  2602. ******************************************************************************/
  2603. static void
  2604. e1000_lower_mdi_clk(struct e1000_hw *hw,
  2605. uint32_t *ctrl)
  2606. {
  2607. /* Lower the clock input to the Management Data Clock (by clearing the MDC
  2608. * bit), and then delay 10 microseconds.
  2609. */
  2610. E1000_WRITE_REG(hw, CTRL, (*ctrl & ~E1000_CTRL_MDC));
  2611. E1000_WRITE_FLUSH(hw);
  2612. udelay(10);
  2613. }
  2614. /******************************************************************************
  2615. * Shifts data bits out to the PHY
  2616. *
  2617. * hw - Struct containing variables accessed by shared code
  2618. * data - Data to send out to the PHY
  2619. * count - Number of bits to shift out
  2620. *
  2621. * Bits are shifted out in MSB to LSB order.
  2622. ******************************************************************************/
  2623. static void
  2624. e1000_shift_out_mdi_bits(struct e1000_hw *hw,
  2625. uint32_t data,
  2626. uint16_t count)
  2627. {
  2628. uint32_t ctrl;
  2629. uint32_t mask;
  2630. /* We need to shift "count" number of bits out to the PHY. So, the value
  2631. * in the "data" parameter will be shifted out to the PHY one bit at a
  2632. * time. In order to do this, "data" must be broken down into bits.
  2633. */
  2634. mask = 0x01;
  2635. mask <<= (count - 1);
  2636. ctrl = E1000_READ_REG(hw, CTRL);
  2637. /* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
  2638. ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
  2639. while(mask) {
  2640. /* A "1" is shifted out to the PHY by setting the MDIO bit to "1" and
  2641. * then raising and lowering the Management Data Clock. A "0" is
  2642. * shifted out to the PHY by setting the MDIO bit to "0" and then
  2643. * raising and lowering the clock.
  2644. */
  2645. if(data & mask) ctrl |= E1000_CTRL_MDIO;
  2646. else ctrl &= ~E1000_CTRL_MDIO;
  2647. E1000_WRITE_REG(hw, CTRL, ctrl);
  2648. E1000_WRITE_FLUSH(hw);
  2649. udelay(10);
  2650. e1000_raise_mdi_clk(hw, &ctrl);
  2651. e1000_lower_mdi_clk(hw, &ctrl);
  2652. mask = mask >> 1;
  2653. }
  2654. }
  2655. /******************************************************************************
  2656. * Shifts data bits in from the PHY
  2657. *
  2658. * hw - Struct containing variables accessed by shared code
  2659. *
  2660. * Bits are shifted in in MSB to LSB order.
  2661. ******************************************************************************/
  2662. static uint16_t
  2663. e1000_shift_in_mdi_bits(struct e1000_hw *hw)
  2664. {
  2665. uint32_t ctrl;
  2666. uint16_t data = 0;
  2667. uint8_t i;
  2668. /* In order to read a register from the PHY, we need to shift in a total
  2669. * of 18 bits from the PHY. The first two bit (turnaround) times are used
  2670. * to avoid contention on the MDIO pin when a read operation is performed.
  2671. * These two bits are ignored by us and thrown away. Bits are "shifted in"
  2672. * by raising the input to the Management Data Clock (setting the MDC bit),
  2673. * and then reading the value of the MDIO bit.
  2674. */
  2675. ctrl = E1000_READ_REG(hw, CTRL);
  2676. /* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as input. */
  2677. ctrl &= ~E1000_CTRL_MDIO_DIR;
  2678. ctrl &= ~E1000_CTRL_MDIO;
  2679. E1000_WRITE_REG(hw, CTRL, ctrl);
  2680. E1000_WRITE_FLUSH(hw);
  2681. /* Raise and Lower the clock before reading in the data. This accounts for
  2682. * the turnaround bits. The first clock occurred when we clocked out the
  2683. * last bit of the Register Address.
  2684. */
  2685. e1000_raise_mdi_clk(hw, &ctrl);
  2686. e1000_lower_mdi_clk(hw, &ctrl);
  2687. for(data = 0, i = 0; i < 16; i++) {
  2688. data = data << 1;
  2689. e1000_raise_mdi_clk(hw, &ctrl);
  2690. ctrl = E1000_READ_REG(hw, CTRL);
  2691. /* Check to see if we shifted in a "1". */
  2692. if(ctrl & E1000_CTRL_MDIO) data |= 1;
  2693. e1000_lower_mdi_clk(hw, &ctrl);
  2694. }
  2695. e1000_raise_mdi_clk(hw, &ctrl);
  2696. e1000_lower_mdi_clk(hw, &ctrl);
  2697. return data;
  2698. }
  2699. int32_t
  2700. e1000_swfw_sync_acquire(struct e1000_hw *hw, uint16_t mask)
  2701. {
  2702. uint32_t swfw_sync = 0;
  2703. uint32_t swmask = mask;
  2704. uint32_t fwmask = mask << 16;
  2705. int32_t timeout = 200;
  2706. DEBUGFUNC("e1000_swfw_sync_acquire");
  2707. if (!hw->swfw_sync_present)
  2708. return e1000_get_hw_eeprom_semaphore(hw);
  2709. while(timeout) {
  2710. if (e1000_get_hw_eeprom_semaphore(hw))
  2711. return -E1000_ERR_SWFW_SYNC;
  2712. swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
  2713. if (!(swfw_sync & (fwmask | swmask))) {
  2714. break;
  2715. }
  2716. /* firmware currently using resource (fwmask) */
  2717. /* or other software thread currently using resource (swmask) */
  2718. e1000_put_hw_eeprom_semaphore(hw);
  2719. msec_delay_irq(5);
  2720. timeout--;
  2721. }
  2722. if (!timeout) {
  2723. DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
  2724. return -E1000_ERR_SWFW_SYNC;
  2725. }
  2726. swfw_sync |= swmask;
  2727. E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
  2728. e1000_put_hw_eeprom_semaphore(hw);
  2729. return E1000_SUCCESS;
  2730. }
  2731. void
  2732. e1000_swfw_sync_release(struct e1000_hw *hw, uint16_t mask)
  2733. {
  2734. uint32_t swfw_sync;
  2735. uint32_t swmask = mask;
  2736. DEBUGFUNC("e1000_swfw_sync_release");
  2737. if (!hw->swfw_sync_present) {
  2738. e1000_put_hw_eeprom_semaphore(hw);
  2739. return;
  2740. }
  2741. /* if (e1000_get_hw_eeprom_semaphore(hw))
  2742. * return -E1000_ERR_SWFW_SYNC; */
  2743. while (e1000_get_hw_eeprom_semaphore(hw) != E1000_SUCCESS);
  2744. /* empty */
  2745. swfw_sync = E1000_READ_REG(hw, SW_FW_SYNC);
  2746. swfw_sync &= ~swmask;
  2747. E1000_WRITE_REG(hw, SW_FW_SYNC, swfw_sync);
  2748. e1000_put_hw_eeprom_semaphore(hw);
  2749. }
  2750. /*****************************************************************************
  2751. * Reads the value from a PHY register, if the value is on a specific non zero
  2752. * page, sets the page first.
  2753. * hw - Struct containing variables accessed by shared code
  2754. * reg_addr - address of the PHY register to read
  2755. ******************************************************************************/
  2756. int32_t
  2757. e1000_read_phy_reg(struct e1000_hw *hw,
  2758. uint32_t reg_addr,
  2759. uint16_t *phy_data)
  2760. {
  2761. uint32_t ret_val;
  2762. uint16_t swfw;
  2763. DEBUGFUNC("e1000_read_phy_reg");
  2764. if ((hw->mac_type == e1000_80003es2lan) &&
  2765. (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
  2766. swfw = E1000_SWFW_PHY1_SM;
  2767. } else {
  2768. swfw = E1000_SWFW_PHY0_SM;
  2769. }
  2770. if (e1000_swfw_sync_acquire(hw, swfw))
  2771. return -E1000_ERR_SWFW_SYNC;
  2772. if((hw->phy_type == e1000_phy_igp ||
  2773. hw->phy_type == e1000_phy_igp_2) &&
  2774. (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
  2775. ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
  2776. (uint16_t)reg_addr);
  2777. if(ret_val) {
  2778. e1000_swfw_sync_release(hw, swfw);
  2779. return ret_val;
  2780. }
  2781. } else if (hw->phy_type == e1000_phy_gg82563) {
  2782. if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
  2783. (hw->mac_type == e1000_80003es2lan)) {
  2784. /* Select Configuration Page */
  2785. if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
  2786. ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
  2787. (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
  2788. } else {
  2789. /* Use Alternative Page Select register to access
  2790. * registers 30 and 31
  2791. */
  2792. ret_val = e1000_write_phy_reg_ex(hw,
  2793. GG82563_PHY_PAGE_SELECT_ALT,
  2794. (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
  2795. }
  2796. if (ret_val) {
  2797. e1000_swfw_sync_release(hw, swfw);
  2798. return ret_val;
  2799. }
  2800. }
  2801. }
  2802. ret_val = e1000_read_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
  2803. phy_data);
  2804. e1000_swfw_sync_release(hw, swfw);
  2805. return ret_val;
  2806. }
  2807. int32_t
  2808. e1000_read_phy_reg_ex(struct e1000_hw *hw,
  2809. uint32_t reg_addr,
  2810. uint16_t *phy_data)
  2811. {
  2812. uint32_t i;
  2813. uint32_t mdic = 0;
  2814. const uint32_t phy_addr = 1;
  2815. DEBUGFUNC("e1000_read_phy_reg_ex");
  2816. if(reg_addr > MAX_PHY_REG_ADDRESS) {
  2817. DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
  2818. return -E1000_ERR_PARAM;
  2819. }
  2820. if(hw->mac_type > e1000_82543) {
  2821. /* Set up Op-code, Phy Address, and register address in the MDI
  2822. * Control register. The MAC will take care of interfacing with the
  2823. * PHY to retrieve the desired data.
  2824. */
  2825. mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
  2826. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  2827. (E1000_MDIC_OP_READ));
  2828. E1000_WRITE_REG(hw, MDIC, mdic);
  2829. /* Poll the ready bit to see if the MDI read completed */
  2830. for(i = 0; i < 64; i++) {
  2831. udelay(50);
  2832. mdic = E1000_READ_REG(hw, MDIC);
  2833. if(mdic & E1000_MDIC_READY) break;
  2834. }
  2835. if(!(mdic & E1000_MDIC_READY)) {
  2836. DEBUGOUT("MDI Read did not complete\n");
  2837. return -E1000_ERR_PHY;
  2838. }
  2839. if(mdic & E1000_MDIC_ERROR) {
  2840. DEBUGOUT("MDI Error\n");
  2841. return -E1000_ERR_PHY;
  2842. }
  2843. *phy_data = (uint16_t) mdic;
  2844. } else {
  2845. /* We must first send a preamble through the MDIO pin to signal the
  2846. * beginning of an MII instruction. This is done by sending 32
  2847. * consecutive "1" bits.
  2848. */
  2849. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  2850. /* Now combine the next few fields that are required for a read
  2851. * operation. We use this method instead of calling the
  2852. * e1000_shift_out_mdi_bits routine five different times. The format of
  2853. * a MII read instruction consists of a shift out of 14 bits and is
  2854. * defined as follows:
  2855. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr>
  2856. * followed by a shift in of 18 bits. This first two bits shifted in
  2857. * are TurnAround bits used to avoid contention on the MDIO pin when a
  2858. * READ operation is performed. These two bits are thrown away
  2859. * followed by a shift in of 16 bits which contains the desired data.
  2860. */
  2861. mdic = ((reg_addr) | (phy_addr << 5) |
  2862. (PHY_OP_READ << 10) | (PHY_SOF << 12));
  2863. e1000_shift_out_mdi_bits(hw, mdic, 14);
  2864. /* Now that we've shifted out the read command to the MII, we need to
  2865. * "shift in" the 16-bit value (18 total bits) of the requested PHY
  2866. * register address.
  2867. */
  2868. *phy_data = e1000_shift_in_mdi_bits(hw);
  2869. }
  2870. return E1000_SUCCESS;
  2871. }
  2872. /******************************************************************************
  2873. * Writes a value to a PHY register
  2874. *
  2875. * hw - Struct containing variables accessed by shared code
  2876. * reg_addr - address of the PHY register to write
  2877. * data - data to write to the PHY
  2878. ******************************************************************************/
  2879. int32_t
  2880. e1000_write_phy_reg(struct e1000_hw *hw,
  2881. uint32_t reg_addr,
  2882. uint16_t phy_data)
  2883. {
  2884. uint32_t ret_val;
  2885. uint16_t swfw;
  2886. DEBUGFUNC("e1000_write_phy_reg");
  2887. if ((hw->mac_type == e1000_80003es2lan) &&
  2888. (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
  2889. swfw = E1000_SWFW_PHY1_SM;
  2890. } else {
  2891. swfw = E1000_SWFW_PHY0_SM;
  2892. }
  2893. if (e1000_swfw_sync_acquire(hw, swfw))
  2894. return -E1000_ERR_SWFW_SYNC;
  2895. if((hw->phy_type == e1000_phy_igp ||
  2896. hw->phy_type == e1000_phy_igp_2) &&
  2897. (reg_addr > MAX_PHY_MULTI_PAGE_REG)) {
  2898. ret_val = e1000_write_phy_reg_ex(hw, IGP01E1000_PHY_PAGE_SELECT,
  2899. (uint16_t)reg_addr);
  2900. if(ret_val) {
  2901. e1000_swfw_sync_release(hw, swfw);
  2902. return ret_val;
  2903. }
  2904. } else if (hw->phy_type == e1000_phy_gg82563) {
  2905. if (((reg_addr & MAX_PHY_REG_ADDRESS) > MAX_PHY_MULTI_PAGE_REG) ||
  2906. (hw->mac_type == e1000_80003es2lan)) {
  2907. /* Select Configuration Page */
  2908. if ((reg_addr & MAX_PHY_REG_ADDRESS) < GG82563_MIN_ALT_REG) {
  2909. ret_val = e1000_write_phy_reg_ex(hw, GG82563_PHY_PAGE_SELECT,
  2910. (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
  2911. } else {
  2912. /* Use Alternative Page Select register to access
  2913. * registers 30 and 31
  2914. */
  2915. ret_val = e1000_write_phy_reg_ex(hw,
  2916. GG82563_PHY_PAGE_SELECT_ALT,
  2917. (uint16_t)((uint16_t)reg_addr >> GG82563_PAGE_SHIFT));
  2918. }
  2919. if (ret_val) {
  2920. e1000_swfw_sync_release(hw, swfw);
  2921. return ret_val;
  2922. }
  2923. }
  2924. }
  2925. ret_val = e1000_write_phy_reg_ex(hw, MAX_PHY_REG_ADDRESS & reg_addr,
  2926. phy_data);
  2927. e1000_swfw_sync_release(hw, swfw);
  2928. return ret_val;
  2929. }
  2930. int32_t
  2931. e1000_write_phy_reg_ex(struct e1000_hw *hw,
  2932. uint32_t reg_addr,
  2933. uint16_t phy_data)
  2934. {
  2935. uint32_t i;
  2936. uint32_t mdic = 0;
  2937. const uint32_t phy_addr = 1;
  2938. DEBUGFUNC("e1000_write_phy_reg_ex");
  2939. if(reg_addr > MAX_PHY_REG_ADDRESS) {
  2940. DEBUGOUT1("PHY Address %d is out of range\n", reg_addr);
  2941. return -E1000_ERR_PARAM;
  2942. }
  2943. if(hw->mac_type > e1000_82543) {
  2944. /* Set up Op-code, Phy Address, register address, and data intended
  2945. * for the PHY register in the MDI Control register. The MAC will take
  2946. * care of interfacing with the PHY to send the desired data.
  2947. */
  2948. mdic = (((uint32_t) phy_data) |
  2949. (reg_addr << E1000_MDIC_REG_SHIFT) |
  2950. (phy_addr << E1000_MDIC_PHY_SHIFT) |
  2951. (E1000_MDIC_OP_WRITE));
  2952. E1000_WRITE_REG(hw, MDIC, mdic);
  2953. /* Poll the ready bit to see if the MDI read completed */
  2954. for(i = 0; i < 640; i++) {
  2955. udelay(5);
  2956. mdic = E1000_READ_REG(hw, MDIC);
  2957. if(mdic & E1000_MDIC_READY) break;
  2958. }
  2959. if(!(mdic & E1000_MDIC_READY)) {
  2960. DEBUGOUT("MDI Write did not complete\n");
  2961. return -E1000_ERR_PHY;
  2962. }
  2963. } else {
  2964. /* We'll need to use the SW defined pins to shift the write command
  2965. * out to the PHY. We first send a preamble to the PHY to signal the
  2966. * beginning of the MII instruction. This is done by sending 32
  2967. * consecutive "1" bits.
  2968. */
  2969. e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
  2970. /* Now combine the remaining required fields that will indicate a
  2971. * write operation. We use this method instead of calling the
  2972. * e1000_shift_out_mdi_bits routine for each field in the command. The
  2973. * format of a MII write instruction is as follows:
  2974. * <Preamble><SOF><Op Code><Phy Addr><Reg Addr><Turnaround><Data>.
  2975. */
  2976. mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
  2977. (PHY_OP_WRITE << 12) | (PHY_SOF << 14));
  2978. mdic <<= 16;
  2979. mdic |= (uint32_t) phy_data;
  2980. e1000_shift_out_mdi_bits(hw, mdic, 32);
  2981. }
  2982. return E1000_SUCCESS;
  2983. }
  2984. int32_t
  2985. e1000_read_kmrn_reg(struct e1000_hw *hw,
  2986. uint32_t reg_addr,
  2987. uint16_t *data)
  2988. {
  2989. uint32_t reg_val;
  2990. uint16_t swfw;
  2991. DEBUGFUNC("e1000_read_kmrn_reg");
  2992. if ((hw->mac_type == e1000_80003es2lan) &&
  2993. (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
  2994. swfw = E1000_SWFW_PHY1_SM;
  2995. } else {
  2996. swfw = E1000_SWFW_PHY0_SM;
  2997. }
  2998. if (e1000_swfw_sync_acquire(hw, swfw))
  2999. return -E1000_ERR_SWFW_SYNC;
  3000. /* Write register address */
  3001. reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
  3002. E1000_KUMCTRLSTA_OFFSET) |
  3003. E1000_KUMCTRLSTA_REN;
  3004. E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
  3005. udelay(2);
  3006. /* Read the data returned */
  3007. reg_val = E1000_READ_REG(hw, KUMCTRLSTA);
  3008. *data = (uint16_t)reg_val;
  3009. e1000_swfw_sync_release(hw, swfw);
  3010. return E1000_SUCCESS;
  3011. }
  3012. int32_t
  3013. e1000_write_kmrn_reg(struct e1000_hw *hw,
  3014. uint32_t reg_addr,
  3015. uint16_t data)
  3016. {
  3017. uint32_t reg_val;
  3018. uint16_t swfw;
  3019. DEBUGFUNC("e1000_write_kmrn_reg");
  3020. if ((hw->mac_type == e1000_80003es2lan) &&
  3021. (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
  3022. swfw = E1000_SWFW_PHY1_SM;
  3023. } else {
  3024. swfw = E1000_SWFW_PHY0_SM;
  3025. }
  3026. if (e1000_swfw_sync_acquire(hw, swfw))
  3027. return -E1000_ERR_SWFW_SYNC;
  3028. reg_val = ((reg_addr << E1000_KUMCTRLSTA_OFFSET_SHIFT) &
  3029. E1000_KUMCTRLSTA_OFFSET) | data;
  3030. E1000_WRITE_REG(hw, KUMCTRLSTA, reg_val);
  3031. udelay(2);
  3032. e1000_swfw_sync_release(hw, swfw);
  3033. return E1000_SUCCESS;
  3034. }
  3035. /******************************************************************************
  3036. * Returns the PHY to the power-on reset state
  3037. *
  3038. * hw - Struct containing variables accessed by shared code
  3039. ******************************************************************************/
  3040. int32_t
  3041. e1000_phy_hw_reset(struct e1000_hw *hw)
  3042. {
  3043. uint32_t ctrl, ctrl_ext;
  3044. uint32_t led_ctrl;
  3045. int32_t ret_val;
  3046. uint16_t swfw;
  3047. DEBUGFUNC("e1000_phy_hw_reset");
  3048. /* In the case of the phy reset being blocked, it's not an error, we
  3049. * simply return success without performing the reset. */
  3050. ret_val = e1000_check_phy_reset_block(hw);
  3051. if (ret_val)
  3052. return E1000_SUCCESS;
  3053. DEBUGOUT("Resetting Phy...\n");
  3054. if(hw->mac_type > e1000_82543) {
  3055. if ((hw->mac_type == e1000_80003es2lan) &&
  3056. (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)) {
  3057. swfw = E1000_SWFW_PHY1_SM;
  3058. } else {
  3059. swfw = E1000_SWFW_PHY0_SM;
  3060. }
  3061. if (e1000_swfw_sync_acquire(hw, swfw)) {
  3062. e1000_release_software_semaphore(hw);
  3063. return -E1000_ERR_SWFW_SYNC;
  3064. }
  3065. /* Read the device control register and assert the E1000_CTRL_PHY_RST
  3066. * bit. Then, take it out of reset.
  3067. * For pre-e1000_82571 hardware, we delay for 10ms between the assert
  3068. * and deassert. For e1000_82571 hardware and later, we instead delay
  3069. * for 50us between and 10ms after the deassertion.
  3070. */
  3071. ctrl = E1000_READ_REG(hw, CTRL);
  3072. E1000_WRITE_REG(hw, CTRL, ctrl | E1000_CTRL_PHY_RST);
  3073. E1000_WRITE_FLUSH(hw);
  3074. if (hw->mac_type < e1000_82571)
  3075. msec_delay(10);
  3076. else
  3077. udelay(100);
  3078. E1000_WRITE_REG(hw, CTRL, ctrl);
  3079. E1000_WRITE_FLUSH(hw);
  3080. if (hw->mac_type >= e1000_82571)
  3081. msec_delay(10);
  3082. e1000_swfw_sync_release(hw, swfw);
  3083. } else {
  3084. /* Read the Extended Device Control Register, assert the PHY_RESET_DIR
  3085. * bit to put the PHY into reset. Then, take it out of reset.
  3086. */
  3087. ctrl_ext = E1000_READ_REG(hw, CTRL_EXT);
  3088. ctrl_ext |= E1000_CTRL_EXT_SDP4_DIR;
  3089. ctrl_ext &= ~E1000_CTRL_EXT_SDP4_DATA;
  3090. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  3091. E1000_WRITE_FLUSH(hw);
  3092. msec_delay(10);
  3093. ctrl_ext |= E1000_CTRL_EXT_SDP4_DATA;
  3094. E1000_WRITE_REG(hw, CTRL_EXT, ctrl_ext);
  3095. E1000_WRITE_FLUSH(hw);
  3096. }
  3097. udelay(150);
  3098. if((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
  3099. /* Configure activity LED after PHY reset */
  3100. led_ctrl = E1000_READ_REG(hw, LEDCTL);
  3101. led_ctrl &= IGP_ACTIVITY_LED_MASK;
  3102. led_ctrl |= (IGP_ACTIVITY_LED_ENABLE | IGP_LED3_MODE);
  3103. E1000_WRITE_REG(hw, LEDCTL, led_ctrl);
  3104. }
  3105. /* Wait for FW to finish PHY configuration. */
  3106. ret_val = e1000_get_phy_cfg_done(hw);
  3107. e1000_release_software_semaphore(hw);
  3108. return ret_val;
  3109. }
  3110. /******************************************************************************
  3111. * Resets the PHY
  3112. *
  3113. * hw - Struct containing variables accessed by shared code
  3114. *
  3115. * Sets bit 15 of the MII Control regiser
  3116. ******************************************************************************/
  3117. int32_t
  3118. e1000_phy_reset(struct e1000_hw *hw)
  3119. {
  3120. int32_t ret_val;
  3121. uint16_t phy_data;
  3122. DEBUGFUNC("e1000_phy_reset");
  3123. /* In the case of the phy reset being blocked, it's not an error, we
  3124. * simply return success without performing the reset. */
  3125. ret_val = e1000_check_phy_reset_block(hw);
  3126. if (ret_val)
  3127. return E1000_SUCCESS;
  3128. switch (hw->mac_type) {
  3129. case e1000_82541_rev_2:
  3130. case e1000_82571:
  3131. case e1000_82572:
  3132. ret_val = e1000_phy_hw_reset(hw);
  3133. if(ret_val)
  3134. return ret_val;
  3135. break;
  3136. default:
  3137. ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data);
  3138. if(ret_val)
  3139. return ret_val;
  3140. phy_data |= MII_CR_RESET;
  3141. ret_val = e1000_write_phy_reg(hw, PHY_CTRL, phy_data);
  3142. if(ret_val)
  3143. return ret_val;
  3144. udelay(1);
  3145. break;
  3146. }
  3147. if(hw->phy_type == e1000_phy_igp || hw->phy_type == e1000_phy_igp_2)
  3148. e1000_phy_init_script(hw);
  3149. return E1000_SUCCESS;
  3150. }
  3151. /******************************************************************************
  3152. * Probes the expected PHY address for known PHY IDs
  3153. *
  3154. * hw - Struct containing variables accessed by shared code
  3155. ******************************************************************************/
  3156. static int32_t
  3157. e1000_detect_gig_phy(struct e1000_hw *hw)
  3158. {
  3159. int32_t phy_init_status, ret_val;
  3160. uint16_t phy_id_high, phy_id_low;
  3161. boolean_t match = FALSE;
  3162. DEBUGFUNC("e1000_detect_gig_phy");
  3163. /* The 82571 firmware may still be configuring the PHY. In this
  3164. * case, we cannot access the PHY until the configuration is done. So
  3165. * we explicitly set the PHY values. */
  3166. if(hw->mac_type == e1000_82571 ||
  3167. hw->mac_type == e1000_82572) {
  3168. hw->phy_id = IGP01E1000_I_PHY_ID;
  3169. hw->phy_type = e1000_phy_igp_2;
  3170. return E1000_SUCCESS;
  3171. }
  3172. /* ESB-2 PHY reads require e1000_phy_gg82563 to be set because of a work-
  3173. * around that forces PHY page 0 to be set or the reads fail. The rest of
  3174. * the code in this routine uses e1000_read_phy_reg to read the PHY ID.
  3175. * So for ESB-2 we need to have this set so our reads won't fail. If the
  3176. * attached PHY is not a e1000_phy_gg82563, the routines below will figure
  3177. * this out as well. */
  3178. if (hw->mac_type == e1000_80003es2lan)
  3179. hw->phy_type = e1000_phy_gg82563;
  3180. /* Read the PHY ID Registers to identify which PHY is onboard. */
  3181. ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high);
  3182. if(ret_val)
  3183. return ret_val;
  3184. hw->phy_id = (uint32_t) (phy_id_high << 16);
  3185. udelay(20);
  3186. ret_val = e1000_read_phy_reg(hw, PHY_ID2, &phy_id_low);
  3187. if(ret_val)
  3188. return ret_val;
  3189. hw->phy_id |= (uint32_t) (phy_id_low & PHY_REVISION_MASK);
  3190. hw->phy_revision = (uint32_t) phy_id_low & ~PHY_REVISION_MASK;
  3191. switch(hw->mac_type) {
  3192. case e1000_82543:
  3193. if(hw->phy_id == M88E1000_E_PHY_ID) match = TRUE;
  3194. break;
  3195. case e1000_82544:
  3196. if(hw->phy_id == M88E1000_I_PHY_ID) match = TRUE;
  3197. break;
  3198. case e1000_82540:
  3199. case e1000_82545:
  3200. case e1000_82545_rev_3:
  3201. case e1000_82546:
  3202. case e1000_82546_rev_3:
  3203. if(hw->phy_id == M88E1011_I_PHY_ID) match = TRUE;
  3204. break;
  3205. case e1000_82541:
  3206. case e1000_82541_rev_2:
  3207. case e1000_82547:
  3208. case e1000_82547_rev_2:
  3209. if(hw->phy_id == IGP01E1000_I_PHY_ID) match = TRUE;
  3210. break;
  3211. case e1000_82573:
  3212. if(hw->phy_id == M88E1111_I_PHY_ID) match = TRUE;
  3213. break;
  3214. case e1000_80003es2lan:
  3215. if (hw->phy_id == GG82563_E_PHY_ID) match = TRUE;
  3216. break;
  3217. default:
  3218. DEBUGOUT1("Invalid MAC type %d\n", hw->mac_type);
  3219. return -E1000_ERR_CONFIG;
  3220. }
  3221. phy_init_status = e1000_set_phy_type(hw);
  3222. if ((match) && (phy_init_status == E1000_SUCCESS)) {
  3223. DEBUGOUT1("PHY ID 0x%X detected\n", hw->phy_id);
  3224. return E1000_SUCCESS;
  3225. }
  3226. DEBUGOUT1("Invalid PHY ID 0x%X\n", hw->phy_id);
  3227. return -E1000_ERR_PHY;
  3228. }
  3229. /******************************************************************************
  3230. * Resets the PHY's DSP
  3231. *
  3232. * hw - Struct containing variables accessed by shared code
  3233. ******************************************************************************/
  3234. static int32_t
  3235. e1000_phy_reset_dsp(struct e1000_hw *hw)
  3236. {
  3237. int32_t ret_val;
  3238. DEBUGFUNC("e1000_phy_reset_dsp");
  3239. do {
  3240. if (hw->phy_type != e1000_phy_gg82563) {
  3241. ret_val = e1000_write_phy_reg(hw, 29, 0x001d);
  3242. if(ret_val) break;
  3243. }
  3244. ret_val = e1000_write_phy_reg(hw, 30, 0x00c1);
  3245. if(ret_val) break;
  3246. ret_val = e1000_write_phy_reg(hw, 30, 0x0000);
  3247. if(ret_val) break;
  3248. ret_val = E1000_SUCCESS;
  3249. } while(0);
  3250. return ret_val;
  3251. }
  3252. /******************************************************************************
  3253. * Get PHY information from various PHY registers for igp PHY only.
  3254. *
  3255. * hw - Struct containing variables accessed by shared code
  3256. * phy_info - PHY information structure
  3257. ******************************************************************************/
  3258. static int32_t
  3259. e1000_phy_igp_get_info(struct e1000_hw *hw,
  3260. struct e1000_phy_info *phy_info)
  3261. {
  3262. int32_t ret_val;
  3263. uint16_t phy_data, polarity, min_length, max_length, average;
  3264. DEBUGFUNC("e1000_phy_igp_get_info");
  3265. /* The downshift status is checked only once, after link is established,
  3266. * and it stored in the hw->speed_downgraded parameter. */
  3267. phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
  3268. /* IGP01E1000 does not need to support it. */
  3269. phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
  3270. /* IGP01E1000 always correct polarity reversal */
  3271. phy_info->polarity_correction = e1000_polarity_reversal_enabled;
  3272. /* Check polarity status */
  3273. ret_val = e1000_check_polarity(hw, &polarity);
  3274. if(ret_val)
  3275. return ret_val;
  3276. phy_info->cable_polarity = polarity;
  3277. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS, &phy_data);
  3278. if(ret_val)
  3279. return ret_val;
  3280. phy_info->mdix_mode = (phy_data & IGP01E1000_PSSR_MDIX) >>
  3281. IGP01E1000_PSSR_MDIX_SHIFT;
  3282. if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
  3283. IGP01E1000_PSSR_SPEED_1000MBPS) {
  3284. /* Local/Remote Receiver Information are only valid at 1000 Mbps */
  3285. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
  3286. if(ret_val)
  3287. return ret_val;
  3288. phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
  3289. SR_1000T_LOCAL_RX_STATUS_SHIFT;
  3290. phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
  3291. SR_1000T_REMOTE_RX_STATUS_SHIFT;
  3292. /* Get cable length */
  3293. ret_val = e1000_get_cable_length(hw, &min_length, &max_length);
  3294. if(ret_val)
  3295. return ret_val;
  3296. /* Translate to old method */
  3297. average = (max_length + min_length) / 2;
  3298. if(average <= e1000_igp_cable_length_50)
  3299. phy_info->cable_length = e1000_cable_length_50;
  3300. else if(average <= e1000_igp_cable_length_80)
  3301. phy_info->cable_length = e1000_cable_length_50_80;
  3302. else if(average <= e1000_igp_cable_length_110)
  3303. phy_info->cable_length = e1000_cable_length_80_110;
  3304. else if(average <= e1000_igp_cable_length_140)
  3305. phy_info->cable_length = e1000_cable_length_110_140;
  3306. else
  3307. phy_info->cable_length = e1000_cable_length_140;
  3308. }
  3309. return E1000_SUCCESS;
  3310. }
  3311. /******************************************************************************
  3312. * Get PHY information from various PHY registers fot m88 PHY only.
  3313. *
  3314. * hw - Struct containing variables accessed by shared code
  3315. * phy_info - PHY information structure
  3316. ******************************************************************************/
  3317. static int32_t
  3318. e1000_phy_m88_get_info(struct e1000_hw *hw,
  3319. struct e1000_phy_info *phy_info)
  3320. {
  3321. int32_t ret_val;
  3322. uint16_t phy_data, polarity;
  3323. DEBUGFUNC("e1000_phy_m88_get_info");
  3324. /* The downshift status is checked only once, after link is established,
  3325. * and it stored in the hw->speed_downgraded parameter. */
  3326. phy_info->downshift = (e1000_downshift)hw->speed_downgraded;
  3327. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data);
  3328. if(ret_val)
  3329. return ret_val;
  3330. phy_info->extended_10bt_distance =
  3331. (phy_data & M88E1000_PSCR_10BT_EXT_DIST_ENABLE) >>
  3332. M88E1000_PSCR_10BT_EXT_DIST_ENABLE_SHIFT;
  3333. phy_info->polarity_correction =
  3334. (phy_data & M88E1000_PSCR_POLARITY_REVERSAL) >>
  3335. M88E1000_PSCR_POLARITY_REVERSAL_SHIFT;
  3336. /* Check polarity status */
  3337. ret_val = e1000_check_polarity(hw, &polarity);
  3338. if(ret_val)
  3339. return ret_val;
  3340. phy_info->cable_polarity = polarity;
  3341. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS, &phy_data);
  3342. if(ret_val)
  3343. return ret_val;
  3344. phy_info->mdix_mode = (phy_data & M88E1000_PSSR_MDIX) >>
  3345. M88E1000_PSSR_MDIX_SHIFT;
  3346. if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS) {
  3347. /* Cable Length Estimation and Local/Remote Receiver Information
  3348. * are only valid at 1000 Mbps.
  3349. */
  3350. if (hw->phy_type != e1000_phy_gg82563) {
  3351. phy_info->cable_length = ((phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
  3352. M88E1000_PSSR_CABLE_LENGTH_SHIFT);
  3353. } else {
  3354. ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
  3355. &phy_data);
  3356. if (ret_val)
  3357. return ret_val;
  3358. phy_info->cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
  3359. }
  3360. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS, &phy_data);
  3361. if(ret_val)
  3362. return ret_val;
  3363. phy_info->local_rx = (phy_data & SR_1000T_LOCAL_RX_STATUS) >>
  3364. SR_1000T_LOCAL_RX_STATUS_SHIFT;
  3365. phy_info->remote_rx = (phy_data & SR_1000T_REMOTE_RX_STATUS) >>
  3366. SR_1000T_REMOTE_RX_STATUS_SHIFT;
  3367. }
  3368. return E1000_SUCCESS;
  3369. }
  3370. /******************************************************************************
  3371. * Get PHY information from various PHY registers
  3372. *
  3373. * hw - Struct containing variables accessed by shared code
  3374. * phy_info - PHY information structure
  3375. ******************************************************************************/
  3376. int32_t
  3377. e1000_phy_get_info(struct e1000_hw *hw,
  3378. struct e1000_phy_info *phy_info)
  3379. {
  3380. int32_t ret_val;
  3381. uint16_t phy_data;
  3382. DEBUGFUNC("e1000_phy_get_info");
  3383. phy_info->cable_length = e1000_cable_length_undefined;
  3384. phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_undefined;
  3385. phy_info->cable_polarity = e1000_rev_polarity_undefined;
  3386. phy_info->downshift = e1000_downshift_undefined;
  3387. phy_info->polarity_correction = e1000_polarity_reversal_undefined;
  3388. phy_info->mdix_mode = e1000_auto_x_mode_undefined;
  3389. phy_info->local_rx = e1000_1000t_rx_status_undefined;
  3390. phy_info->remote_rx = e1000_1000t_rx_status_undefined;
  3391. if(hw->media_type != e1000_media_type_copper) {
  3392. DEBUGOUT("PHY info is only valid for copper media\n");
  3393. return -E1000_ERR_CONFIG;
  3394. }
  3395. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  3396. if(ret_val)
  3397. return ret_val;
  3398. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data);
  3399. if(ret_val)
  3400. return ret_val;
  3401. if((phy_data & MII_SR_LINK_STATUS) != MII_SR_LINK_STATUS) {
  3402. DEBUGOUT("PHY info is only valid if link is up\n");
  3403. return -E1000_ERR_CONFIG;
  3404. }
  3405. if(hw->phy_type == e1000_phy_igp ||
  3406. hw->phy_type == e1000_phy_igp_2)
  3407. return e1000_phy_igp_get_info(hw, phy_info);
  3408. else
  3409. return e1000_phy_m88_get_info(hw, phy_info);
  3410. }
  3411. int32_t
  3412. e1000_validate_mdi_setting(struct e1000_hw *hw)
  3413. {
  3414. DEBUGFUNC("e1000_validate_mdi_settings");
  3415. if(!hw->autoneg && (hw->mdix == 0 || hw->mdix == 3)) {
  3416. DEBUGOUT("Invalid MDI setting detected\n");
  3417. hw->mdix = 1;
  3418. return -E1000_ERR_CONFIG;
  3419. }
  3420. return E1000_SUCCESS;
  3421. }
  3422. /******************************************************************************
  3423. * Sets up eeprom variables in the hw struct. Must be called after mac_type
  3424. * is configured. Additionally, if this is ICH8, the flash controller GbE
  3425. * registers must be mapped, or this will crash.
  3426. *
  3427. * hw - Struct containing variables accessed by shared code
  3428. *****************************************************************************/
  3429. int32_t
  3430. e1000_init_eeprom_params(struct e1000_hw *hw)
  3431. {
  3432. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3433. uint32_t eecd = E1000_READ_REG(hw, EECD);
  3434. int32_t ret_val = E1000_SUCCESS;
  3435. uint16_t eeprom_size;
  3436. DEBUGFUNC("e1000_init_eeprom_params");
  3437. switch (hw->mac_type) {
  3438. case e1000_82542_rev2_0:
  3439. case e1000_82542_rev2_1:
  3440. case e1000_82543:
  3441. case e1000_82544:
  3442. eeprom->type = e1000_eeprom_microwire;
  3443. eeprom->word_size = 64;
  3444. eeprom->opcode_bits = 3;
  3445. eeprom->address_bits = 6;
  3446. eeprom->delay_usec = 50;
  3447. eeprom->use_eerd = FALSE;
  3448. eeprom->use_eewr = FALSE;
  3449. break;
  3450. case e1000_82540:
  3451. case e1000_82545:
  3452. case e1000_82545_rev_3:
  3453. case e1000_82546:
  3454. case e1000_82546_rev_3:
  3455. eeprom->type = e1000_eeprom_microwire;
  3456. eeprom->opcode_bits = 3;
  3457. eeprom->delay_usec = 50;
  3458. if(eecd & E1000_EECD_SIZE) {
  3459. eeprom->word_size = 256;
  3460. eeprom->address_bits = 8;
  3461. } else {
  3462. eeprom->word_size = 64;
  3463. eeprom->address_bits = 6;
  3464. }
  3465. eeprom->use_eerd = FALSE;
  3466. eeprom->use_eewr = FALSE;
  3467. break;
  3468. case e1000_82541:
  3469. case e1000_82541_rev_2:
  3470. case e1000_82547:
  3471. case e1000_82547_rev_2:
  3472. if (eecd & E1000_EECD_TYPE) {
  3473. eeprom->type = e1000_eeprom_spi;
  3474. eeprom->opcode_bits = 8;
  3475. eeprom->delay_usec = 1;
  3476. if (eecd & E1000_EECD_ADDR_BITS) {
  3477. eeprom->page_size = 32;
  3478. eeprom->address_bits = 16;
  3479. } else {
  3480. eeprom->page_size = 8;
  3481. eeprom->address_bits = 8;
  3482. }
  3483. } else {
  3484. eeprom->type = e1000_eeprom_microwire;
  3485. eeprom->opcode_bits = 3;
  3486. eeprom->delay_usec = 50;
  3487. if (eecd & E1000_EECD_ADDR_BITS) {
  3488. eeprom->word_size = 256;
  3489. eeprom->address_bits = 8;
  3490. } else {
  3491. eeprom->word_size = 64;
  3492. eeprom->address_bits = 6;
  3493. }
  3494. }
  3495. eeprom->use_eerd = FALSE;
  3496. eeprom->use_eewr = FALSE;
  3497. break;
  3498. case e1000_82571:
  3499. case e1000_82572:
  3500. eeprom->type = e1000_eeprom_spi;
  3501. eeprom->opcode_bits = 8;
  3502. eeprom->delay_usec = 1;
  3503. if (eecd & E1000_EECD_ADDR_BITS) {
  3504. eeprom->page_size = 32;
  3505. eeprom->address_bits = 16;
  3506. } else {
  3507. eeprom->page_size = 8;
  3508. eeprom->address_bits = 8;
  3509. }
  3510. eeprom->use_eerd = FALSE;
  3511. eeprom->use_eewr = FALSE;
  3512. break;
  3513. case e1000_82573:
  3514. eeprom->type = e1000_eeprom_spi;
  3515. eeprom->opcode_bits = 8;
  3516. eeprom->delay_usec = 1;
  3517. if (eecd & E1000_EECD_ADDR_BITS) {
  3518. eeprom->page_size = 32;
  3519. eeprom->address_bits = 16;
  3520. } else {
  3521. eeprom->page_size = 8;
  3522. eeprom->address_bits = 8;
  3523. }
  3524. eeprom->use_eerd = TRUE;
  3525. eeprom->use_eewr = TRUE;
  3526. if(e1000_is_onboard_nvm_eeprom(hw) == FALSE) {
  3527. eeprom->type = e1000_eeprom_flash;
  3528. eeprom->word_size = 2048;
  3529. /* Ensure that the Autonomous FLASH update bit is cleared due to
  3530. * Flash update issue on parts which use a FLASH for NVM. */
  3531. eecd &= ~E1000_EECD_AUPDEN;
  3532. E1000_WRITE_REG(hw, EECD, eecd);
  3533. }
  3534. break;
  3535. case e1000_80003es2lan:
  3536. eeprom->type = e1000_eeprom_spi;
  3537. eeprom->opcode_bits = 8;
  3538. eeprom->delay_usec = 1;
  3539. if (eecd & E1000_EECD_ADDR_BITS) {
  3540. eeprom->page_size = 32;
  3541. eeprom->address_bits = 16;
  3542. } else {
  3543. eeprom->page_size = 8;
  3544. eeprom->address_bits = 8;
  3545. }
  3546. eeprom->use_eerd = TRUE;
  3547. eeprom->use_eewr = FALSE;
  3548. break;
  3549. default:
  3550. break;
  3551. }
  3552. if (eeprom->type == e1000_eeprom_spi) {
  3553. /* eeprom_size will be an enum [0..8] that maps to eeprom sizes 128B to
  3554. * 32KB (incremented by powers of 2).
  3555. */
  3556. if(hw->mac_type <= e1000_82547_rev_2) {
  3557. /* Set to default value for initial eeprom read. */
  3558. eeprom->word_size = 64;
  3559. ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size);
  3560. if(ret_val)
  3561. return ret_val;
  3562. eeprom_size = (eeprom_size & EEPROM_SIZE_MASK) >> EEPROM_SIZE_SHIFT;
  3563. /* 256B eeprom size was not supported in earlier hardware, so we
  3564. * bump eeprom_size up one to ensure that "1" (which maps to 256B)
  3565. * is never the result used in the shifting logic below. */
  3566. if(eeprom_size)
  3567. eeprom_size++;
  3568. } else {
  3569. eeprom_size = (uint16_t)((eecd & E1000_EECD_SIZE_EX_MASK) >>
  3570. E1000_EECD_SIZE_EX_SHIFT);
  3571. }
  3572. eeprom->word_size = 1 << (eeprom_size + EEPROM_WORD_SIZE_SHIFT);
  3573. }
  3574. return ret_val;
  3575. }
  3576. /******************************************************************************
  3577. * Raises the EEPROM's clock input.
  3578. *
  3579. * hw - Struct containing variables accessed by shared code
  3580. * eecd - EECD's current value
  3581. *****************************************************************************/
  3582. static void
  3583. e1000_raise_ee_clk(struct e1000_hw *hw,
  3584. uint32_t *eecd)
  3585. {
  3586. /* Raise the clock input to the EEPROM (by setting the SK bit), and then
  3587. * wait <delay> microseconds.
  3588. */
  3589. *eecd = *eecd | E1000_EECD_SK;
  3590. E1000_WRITE_REG(hw, EECD, *eecd);
  3591. E1000_WRITE_FLUSH(hw);
  3592. udelay(hw->eeprom.delay_usec);
  3593. }
  3594. /******************************************************************************
  3595. * Lowers the EEPROM's clock input.
  3596. *
  3597. * hw - Struct containing variables accessed by shared code
  3598. * eecd - EECD's current value
  3599. *****************************************************************************/
  3600. static void
  3601. e1000_lower_ee_clk(struct e1000_hw *hw,
  3602. uint32_t *eecd)
  3603. {
  3604. /* Lower the clock input to the EEPROM (by clearing the SK bit), and then
  3605. * wait 50 microseconds.
  3606. */
  3607. *eecd = *eecd & ~E1000_EECD_SK;
  3608. E1000_WRITE_REG(hw, EECD, *eecd);
  3609. E1000_WRITE_FLUSH(hw);
  3610. udelay(hw->eeprom.delay_usec);
  3611. }
  3612. /******************************************************************************
  3613. * Shift data bits out to the EEPROM.
  3614. *
  3615. * hw - Struct containing variables accessed by shared code
  3616. * data - data to send to the EEPROM
  3617. * count - number of bits to shift out
  3618. *****************************************************************************/
  3619. static void
  3620. e1000_shift_out_ee_bits(struct e1000_hw *hw,
  3621. uint16_t data,
  3622. uint16_t count)
  3623. {
  3624. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3625. uint32_t eecd;
  3626. uint32_t mask;
  3627. /* We need to shift "count" bits out to the EEPROM. So, value in the
  3628. * "data" parameter will be shifted out to the EEPROM one bit at a time.
  3629. * In order to do this, "data" must be broken down into bits.
  3630. */
  3631. mask = 0x01 << (count - 1);
  3632. eecd = E1000_READ_REG(hw, EECD);
  3633. if (eeprom->type == e1000_eeprom_microwire) {
  3634. eecd &= ~E1000_EECD_DO;
  3635. } else if (eeprom->type == e1000_eeprom_spi) {
  3636. eecd |= E1000_EECD_DO;
  3637. }
  3638. do {
  3639. /* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
  3640. * and then raising and then lowering the clock (the SK bit controls
  3641. * the clock input to the EEPROM). A "0" is shifted out to the EEPROM
  3642. * by setting "DI" to "0" and then raising and then lowering the clock.
  3643. */
  3644. eecd &= ~E1000_EECD_DI;
  3645. if(data & mask)
  3646. eecd |= E1000_EECD_DI;
  3647. E1000_WRITE_REG(hw, EECD, eecd);
  3648. E1000_WRITE_FLUSH(hw);
  3649. udelay(eeprom->delay_usec);
  3650. e1000_raise_ee_clk(hw, &eecd);
  3651. e1000_lower_ee_clk(hw, &eecd);
  3652. mask = mask >> 1;
  3653. } while(mask);
  3654. /* We leave the "DI" bit set to "0" when we leave this routine. */
  3655. eecd &= ~E1000_EECD_DI;
  3656. E1000_WRITE_REG(hw, EECD, eecd);
  3657. }
  3658. /******************************************************************************
  3659. * Shift data bits in from the EEPROM
  3660. *
  3661. * hw - Struct containing variables accessed by shared code
  3662. *****************************************************************************/
  3663. static uint16_t
  3664. e1000_shift_in_ee_bits(struct e1000_hw *hw,
  3665. uint16_t count)
  3666. {
  3667. uint32_t eecd;
  3668. uint32_t i;
  3669. uint16_t data;
  3670. /* In order to read a register from the EEPROM, we need to shift 'count'
  3671. * bits in from the EEPROM. Bits are "shifted in" by raising the clock
  3672. * input to the EEPROM (setting the SK bit), and then reading the value of
  3673. * the "DO" bit. During this "shifting in" process the "DI" bit should
  3674. * always be clear.
  3675. */
  3676. eecd = E1000_READ_REG(hw, EECD);
  3677. eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
  3678. data = 0;
  3679. for(i = 0; i < count; i++) {
  3680. data = data << 1;
  3681. e1000_raise_ee_clk(hw, &eecd);
  3682. eecd = E1000_READ_REG(hw, EECD);
  3683. eecd &= ~(E1000_EECD_DI);
  3684. if(eecd & E1000_EECD_DO)
  3685. data |= 1;
  3686. e1000_lower_ee_clk(hw, &eecd);
  3687. }
  3688. return data;
  3689. }
  3690. /******************************************************************************
  3691. * Prepares EEPROM for access
  3692. *
  3693. * hw - Struct containing variables accessed by shared code
  3694. *
  3695. * Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
  3696. * function should be called before issuing a command to the EEPROM.
  3697. *****************************************************************************/
  3698. static int32_t
  3699. e1000_acquire_eeprom(struct e1000_hw *hw)
  3700. {
  3701. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3702. uint32_t eecd, i=0;
  3703. DEBUGFUNC("e1000_acquire_eeprom");
  3704. if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
  3705. return -E1000_ERR_SWFW_SYNC;
  3706. eecd = E1000_READ_REG(hw, EECD);
  3707. if (hw->mac_type != e1000_82573) {
  3708. /* Request EEPROM Access */
  3709. if(hw->mac_type > e1000_82544) {
  3710. eecd |= E1000_EECD_REQ;
  3711. E1000_WRITE_REG(hw, EECD, eecd);
  3712. eecd = E1000_READ_REG(hw, EECD);
  3713. while((!(eecd & E1000_EECD_GNT)) &&
  3714. (i < E1000_EEPROM_GRANT_ATTEMPTS)) {
  3715. i++;
  3716. udelay(5);
  3717. eecd = E1000_READ_REG(hw, EECD);
  3718. }
  3719. if(!(eecd & E1000_EECD_GNT)) {
  3720. eecd &= ~E1000_EECD_REQ;
  3721. E1000_WRITE_REG(hw, EECD, eecd);
  3722. DEBUGOUT("Could not acquire EEPROM grant\n");
  3723. e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
  3724. return -E1000_ERR_EEPROM;
  3725. }
  3726. }
  3727. }
  3728. /* Setup EEPROM for Read/Write */
  3729. if (eeprom->type == e1000_eeprom_microwire) {
  3730. /* Clear SK and DI */
  3731. eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
  3732. E1000_WRITE_REG(hw, EECD, eecd);
  3733. /* Set CS */
  3734. eecd |= E1000_EECD_CS;
  3735. E1000_WRITE_REG(hw, EECD, eecd);
  3736. } else if (eeprom->type == e1000_eeprom_spi) {
  3737. /* Clear SK and CS */
  3738. eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
  3739. E1000_WRITE_REG(hw, EECD, eecd);
  3740. udelay(1);
  3741. }
  3742. return E1000_SUCCESS;
  3743. }
  3744. /******************************************************************************
  3745. * Returns EEPROM to a "standby" state
  3746. *
  3747. * hw - Struct containing variables accessed by shared code
  3748. *****************************************************************************/
  3749. static void
  3750. e1000_standby_eeprom(struct e1000_hw *hw)
  3751. {
  3752. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3753. uint32_t eecd;
  3754. eecd = E1000_READ_REG(hw, EECD);
  3755. if(eeprom->type == e1000_eeprom_microwire) {
  3756. eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
  3757. E1000_WRITE_REG(hw, EECD, eecd);
  3758. E1000_WRITE_FLUSH(hw);
  3759. udelay(eeprom->delay_usec);
  3760. /* Clock high */
  3761. eecd |= E1000_EECD_SK;
  3762. E1000_WRITE_REG(hw, EECD, eecd);
  3763. E1000_WRITE_FLUSH(hw);
  3764. udelay(eeprom->delay_usec);
  3765. /* Select EEPROM */
  3766. eecd |= E1000_EECD_CS;
  3767. E1000_WRITE_REG(hw, EECD, eecd);
  3768. E1000_WRITE_FLUSH(hw);
  3769. udelay(eeprom->delay_usec);
  3770. /* Clock low */
  3771. eecd &= ~E1000_EECD_SK;
  3772. E1000_WRITE_REG(hw, EECD, eecd);
  3773. E1000_WRITE_FLUSH(hw);
  3774. udelay(eeprom->delay_usec);
  3775. } else if(eeprom->type == e1000_eeprom_spi) {
  3776. /* Toggle CS to flush commands */
  3777. eecd |= E1000_EECD_CS;
  3778. E1000_WRITE_REG(hw, EECD, eecd);
  3779. E1000_WRITE_FLUSH(hw);
  3780. udelay(eeprom->delay_usec);
  3781. eecd &= ~E1000_EECD_CS;
  3782. E1000_WRITE_REG(hw, EECD, eecd);
  3783. E1000_WRITE_FLUSH(hw);
  3784. udelay(eeprom->delay_usec);
  3785. }
  3786. }
  3787. /******************************************************************************
  3788. * Terminates a command by inverting the EEPROM's chip select pin
  3789. *
  3790. * hw - Struct containing variables accessed by shared code
  3791. *****************************************************************************/
  3792. static void
  3793. e1000_release_eeprom(struct e1000_hw *hw)
  3794. {
  3795. uint32_t eecd;
  3796. DEBUGFUNC("e1000_release_eeprom");
  3797. eecd = E1000_READ_REG(hw, EECD);
  3798. if (hw->eeprom.type == e1000_eeprom_spi) {
  3799. eecd |= E1000_EECD_CS; /* Pull CS high */
  3800. eecd &= ~E1000_EECD_SK; /* Lower SCK */
  3801. E1000_WRITE_REG(hw, EECD, eecd);
  3802. udelay(hw->eeprom.delay_usec);
  3803. } else if(hw->eeprom.type == e1000_eeprom_microwire) {
  3804. /* cleanup eeprom */
  3805. /* CS on Microwire is active-high */
  3806. eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
  3807. E1000_WRITE_REG(hw, EECD, eecd);
  3808. /* Rising edge of clock */
  3809. eecd |= E1000_EECD_SK;
  3810. E1000_WRITE_REG(hw, EECD, eecd);
  3811. E1000_WRITE_FLUSH(hw);
  3812. udelay(hw->eeprom.delay_usec);
  3813. /* Falling edge of clock */
  3814. eecd &= ~E1000_EECD_SK;
  3815. E1000_WRITE_REG(hw, EECD, eecd);
  3816. E1000_WRITE_FLUSH(hw);
  3817. udelay(hw->eeprom.delay_usec);
  3818. }
  3819. /* Stop requesting EEPROM access */
  3820. if(hw->mac_type > e1000_82544) {
  3821. eecd &= ~E1000_EECD_REQ;
  3822. E1000_WRITE_REG(hw, EECD, eecd);
  3823. }
  3824. e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
  3825. }
  3826. /******************************************************************************
  3827. * Reads a 16 bit word from the EEPROM.
  3828. *
  3829. * hw - Struct containing variables accessed by shared code
  3830. *****************************************************************************/
  3831. int32_t
  3832. e1000_spi_eeprom_ready(struct e1000_hw *hw)
  3833. {
  3834. uint16_t retry_count = 0;
  3835. uint8_t spi_stat_reg;
  3836. DEBUGFUNC("e1000_spi_eeprom_ready");
  3837. /* Read "Status Register" repeatedly until the LSB is cleared. The
  3838. * EEPROM will signal that the command has been completed by clearing
  3839. * bit 0 of the internal status register. If it's not cleared within
  3840. * 5 milliseconds, then error out.
  3841. */
  3842. retry_count = 0;
  3843. do {
  3844. e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
  3845. hw->eeprom.opcode_bits);
  3846. spi_stat_reg = (uint8_t)e1000_shift_in_ee_bits(hw, 8);
  3847. if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI))
  3848. break;
  3849. udelay(5);
  3850. retry_count += 5;
  3851. e1000_standby_eeprom(hw);
  3852. } while(retry_count < EEPROM_MAX_RETRY_SPI);
  3853. /* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and
  3854. * only 0-5mSec on 5V devices)
  3855. */
  3856. if(retry_count >= EEPROM_MAX_RETRY_SPI) {
  3857. DEBUGOUT("SPI EEPROM Status error\n");
  3858. return -E1000_ERR_EEPROM;
  3859. }
  3860. return E1000_SUCCESS;
  3861. }
  3862. /******************************************************************************
  3863. * Reads a 16 bit word from the EEPROM.
  3864. *
  3865. * hw - Struct containing variables accessed by shared code
  3866. * offset - offset of word in the EEPROM to read
  3867. * data - word read from the EEPROM
  3868. * words - number of words to read
  3869. *****************************************************************************/
  3870. int32_t
  3871. e1000_read_eeprom(struct e1000_hw *hw,
  3872. uint16_t offset,
  3873. uint16_t words,
  3874. uint16_t *data)
  3875. {
  3876. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  3877. uint32_t i = 0;
  3878. int32_t ret_val;
  3879. DEBUGFUNC("e1000_read_eeprom");
  3880. /* A check for invalid values: offset too large, too many words, and not
  3881. * enough words.
  3882. */
  3883. if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
  3884. (words == 0)) {
  3885. DEBUGOUT("\"words\" parameter out of bounds\n");
  3886. return -E1000_ERR_EEPROM;
  3887. }
  3888. /* FLASH reads without acquiring the semaphore are safe */
  3889. if (e1000_is_onboard_nvm_eeprom(hw) == TRUE &&
  3890. hw->eeprom.use_eerd == FALSE) {
  3891. switch (hw->mac_type) {
  3892. case e1000_80003es2lan:
  3893. break;
  3894. default:
  3895. /* Prepare the EEPROM for reading */
  3896. if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
  3897. return -E1000_ERR_EEPROM;
  3898. break;
  3899. }
  3900. }
  3901. if (eeprom->use_eerd == TRUE) {
  3902. ret_val = e1000_read_eeprom_eerd(hw, offset, words, data);
  3903. if ((e1000_is_onboard_nvm_eeprom(hw) == TRUE) ||
  3904. (hw->mac_type != e1000_82573))
  3905. e1000_release_eeprom(hw);
  3906. return ret_val;
  3907. }
  3908. if(eeprom->type == e1000_eeprom_spi) {
  3909. uint16_t word_in;
  3910. uint8_t read_opcode = EEPROM_READ_OPCODE_SPI;
  3911. if(e1000_spi_eeprom_ready(hw)) {
  3912. e1000_release_eeprom(hw);
  3913. return -E1000_ERR_EEPROM;
  3914. }
  3915. e1000_standby_eeprom(hw);
  3916. /* Some SPI eeproms use the 8th address bit embedded in the opcode */
  3917. if((eeprom->address_bits == 8) && (offset >= 128))
  3918. read_opcode |= EEPROM_A8_OPCODE_SPI;
  3919. /* Send the READ command (opcode + addr) */
  3920. e1000_shift_out_ee_bits(hw, read_opcode, eeprom->opcode_bits);
  3921. e1000_shift_out_ee_bits(hw, (uint16_t)(offset*2), eeprom->address_bits);
  3922. /* Read the data. The address of the eeprom internally increments with
  3923. * each byte (spi) being read, saving on the overhead of eeprom setup
  3924. * and tear-down. The address counter will roll over if reading beyond
  3925. * the size of the eeprom, thus allowing the entire memory to be read
  3926. * starting from any offset. */
  3927. for (i = 0; i < words; i++) {
  3928. word_in = e1000_shift_in_ee_bits(hw, 16);
  3929. data[i] = (word_in >> 8) | (word_in << 8);
  3930. }
  3931. } else if(eeprom->type == e1000_eeprom_microwire) {
  3932. for (i = 0; i < words; i++) {
  3933. /* Send the READ command (opcode + addr) */
  3934. e1000_shift_out_ee_bits(hw, EEPROM_READ_OPCODE_MICROWIRE,
  3935. eeprom->opcode_bits);
  3936. e1000_shift_out_ee_bits(hw, (uint16_t)(offset + i),
  3937. eeprom->address_bits);
  3938. /* Read the data. For microwire, each word requires the overhead
  3939. * of eeprom setup and tear-down. */
  3940. data[i] = e1000_shift_in_ee_bits(hw, 16);
  3941. e1000_standby_eeprom(hw);
  3942. }
  3943. }
  3944. /* End this read operation */
  3945. e1000_release_eeprom(hw);
  3946. return E1000_SUCCESS;
  3947. }
  3948. /******************************************************************************
  3949. * Reads a 16 bit word from the EEPROM using the EERD register.
  3950. *
  3951. * hw - Struct containing variables accessed by shared code
  3952. * offset - offset of word in the EEPROM to read
  3953. * data - word read from the EEPROM
  3954. * words - number of words to read
  3955. *****************************************************************************/
  3956. static int32_t
  3957. e1000_read_eeprom_eerd(struct e1000_hw *hw,
  3958. uint16_t offset,
  3959. uint16_t words,
  3960. uint16_t *data)
  3961. {
  3962. uint32_t i, eerd = 0;
  3963. int32_t error = 0;
  3964. for (i = 0; i < words; i++) {
  3965. eerd = ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) +
  3966. E1000_EEPROM_RW_REG_START;
  3967. E1000_WRITE_REG(hw, EERD, eerd);
  3968. error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_READ);
  3969. if(error) {
  3970. break;
  3971. }
  3972. data[i] = (E1000_READ_REG(hw, EERD) >> E1000_EEPROM_RW_REG_DATA);
  3973. }
  3974. return error;
  3975. }
  3976. /******************************************************************************
  3977. * Writes a 16 bit word from the EEPROM using the EEWR register.
  3978. *
  3979. * hw - Struct containing variables accessed by shared code
  3980. * offset - offset of word in the EEPROM to read
  3981. * data - word read from the EEPROM
  3982. * words - number of words to read
  3983. *****************************************************************************/
  3984. static int32_t
  3985. e1000_write_eeprom_eewr(struct e1000_hw *hw,
  3986. uint16_t offset,
  3987. uint16_t words,
  3988. uint16_t *data)
  3989. {
  3990. uint32_t register_value = 0;
  3991. uint32_t i = 0;
  3992. int32_t error = 0;
  3993. if (e1000_swfw_sync_acquire(hw, E1000_SWFW_EEP_SM))
  3994. return -E1000_ERR_SWFW_SYNC;
  3995. for (i = 0; i < words; i++) {
  3996. register_value = (data[i] << E1000_EEPROM_RW_REG_DATA) |
  3997. ((offset+i) << E1000_EEPROM_RW_ADDR_SHIFT) |
  3998. E1000_EEPROM_RW_REG_START;
  3999. error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
  4000. if(error) {
  4001. break;
  4002. }
  4003. E1000_WRITE_REG(hw, EEWR, register_value);
  4004. error = e1000_poll_eerd_eewr_done(hw, E1000_EEPROM_POLL_WRITE);
  4005. if(error) {
  4006. break;
  4007. }
  4008. }
  4009. e1000_swfw_sync_release(hw, E1000_SWFW_EEP_SM);
  4010. return error;
  4011. }
  4012. /******************************************************************************
  4013. * Polls the status bit (bit 1) of the EERD to determine when the read is done.
  4014. *
  4015. * hw - Struct containing variables accessed by shared code
  4016. *****************************************************************************/
  4017. static int32_t
  4018. e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int eerd)
  4019. {
  4020. uint32_t attempts = 100000;
  4021. uint32_t i, reg = 0;
  4022. int32_t done = E1000_ERR_EEPROM;
  4023. for(i = 0; i < attempts; i++) {
  4024. if(eerd == E1000_EEPROM_POLL_READ)
  4025. reg = E1000_READ_REG(hw, EERD);
  4026. else
  4027. reg = E1000_READ_REG(hw, EEWR);
  4028. if(reg & E1000_EEPROM_RW_REG_DONE) {
  4029. done = E1000_SUCCESS;
  4030. break;
  4031. }
  4032. udelay(5);
  4033. }
  4034. return done;
  4035. }
  4036. /***************************************************************************
  4037. * Description: Determines if the onboard NVM is FLASH or EEPROM.
  4038. *
  4039. * hw - Struct containing variables accessed by shared code
  4040. ****************************************************************************/
  4041. static boolean_t
  4042. e1000_is_onboard_nvm_eeprom(struct e1000_hw *hw)
  4043. {
  4044. uint32_t eecd = 0;
  4045. DEBUGFUNC("e1000_is_onboard_nvm_eeprom");
  4046. if(hw->mac_type == e1000_82573) {
  4047. eecd = E1000_READ_REG(hw, EECD);
  4048. /* Isolate bits 15 & 16 */
  4049. eecd = ((eecd >> 15) & 0x03);
  4050. /* If both bits are set, device is Flash type */
  4051. if(eecd == 0x03) {
  4052. return FALSE;
  4053. }
  4054. }
  4055. return TRUE;
  4056. }
  4057. /******************************************************************************
  4058. * Verifies that the EEPROM has a valid checksum
  4059. *
  4060. * hw - Struct containing variables accessed by shared code
  4061. *
  4062. * Reads the first 64 16 bit words of the EEPROM and sums the values read.
  4063. * If the the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
  4064. * valid.
  4065. *****************************************************************************/
  4066. int32_t
  4067. e1000_validate_eeprom_checksum(struct e1000_hw *hw)
  4068. {
  4069. uint16_t checksum = 0;
  4070. uint16_t i, eeprom_data;
  4071. DEBUGFUNC("e1000_validate_eeprom_checksum");
  4072. if ((hw->mac_type == e1000_82573) &&
  4073. (e1000_is_onboard_nvm_eeprom(hw) == FALSE)) {
  4074. /* Check bit 4 of word 10h. If it is 0, firmware is done updating
  4075. * 10h-12h. Checksum may need to be fixed. */
  4076. e1000_read_eeprom(hw, 0x10, 1, &eeprom_data);
  4077. if ((eeprom_data & 0x10) == 0) {
  4078. /* Read 0x23 and check bit 15. This bit is a 1 when the checksum
  4079. * has already been fixed. If the checksum is still wrong and this
  4080. * bit is a 1, we need to return bad checksum. Otherwise, we need
  4081. * to set this bit to a 1 and update the checksum. */
  4082. e1000_read_eeprom(hw, 0x23, 1, &eeprom_data);
  4083. if ((eeprom_data & 0x8000) == 0) {
  4084. eeprom_data |= 0x8000;
  4085. e1000_write_eeprom(hw, 0x23, 1, &eeprom_data);
  4086. e1000_update_eeprom_checksum(hw);
  4087. }
  4088. }
  4089. }
  4090. for(i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) {
  4091. if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
  4092. DEBUGOUT("EEPROM Read Error\n");
  4093. return -E1000_ERR_EEPROM;
  4094. }
  4095. checksum += eeprom_data;
  4096. }
  4097. if(checksum == (uint16_t) EEPROM_SUM)
  4098. return E1000_SUCCESS;
  4099. else {
  4100. DEBUGOUT("EEPROM Checksum Invalid\n");
  4101. return -E1000_ERR_EEPROM;
  4102. }
  4103. }
  4104. /******************************************************************************
  4105. * Calculates the EEPROM checksum and writes it to the EEPROM
  4106. *
  4107. * hw - Struct containing variables accessed by shared code
  4108. *
  4109. * Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
  4110. * Writes the difference to word offset 63 of the EEPROM.
  4111. *****************************************************************************/
  4112. int32_t
  4113. e1000_update_eeprom_checksum(struct e1000_hw *hw)
  4114. {
  4115. uint16_t checksum = 0;
  4116. uint16_t i, eeprom_data;
  4117. DEBUGFUNC("e1000_update_eeprom_checksum");
  4118. for(i = 0; i < EEPROM_CHECKSUM_REG; i++) {
  4119. if(e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
  4120. DEBUGOUT("EEPROM Read Error\n");
  4121. return -E1000_ERR_EEPROM;
  4122. }
  4123. checksum += eeprom_data;
  4124. }
  4125. checksum = (uint16_t) EEPROM_SUM - checksum;
  4126. if(e1000_write_eeprom(hw, EEPROM_CHECKSUM_REG, 1, &checksum) < 0) {
  4127. DEBUGOUT("EEPROM Write Error\n");
  4128. return -E1000_ERR_EEPROM;
  4129. } else if (hw->eeprom.type == e1000_eeprom_flash) {
  4130. e1000_commit_shadow_ram(hw);
  4131. }
  4132. return E1000_SUCCESS;
  4133. }
  4134. /******************************************************************************
  4135. * Parent function for writing words to the different EEPROM types.
  4136. *
  4137. * hw - Struct containing variables accessed by shared code
  4138. * offset - offset within the EEPROM to be written to
  4139. * words - number of words to write
  4140. * data - 16 bit word to be written to the EEPROM
  4141. *
  4142. * If e1000_update_eeprom_checksum is not called after this function, the
  4143. * EEPROM will most likely contain an invalid checksum.
  4144. *****************************************************************************/
  4145. int32_t
  4146. e1000_write_eeprom(struct e1000_hw *hw,
  4147. uint16_t offset,
  4148. uint16_t words,
  4149. uint16_t *data)
  4150. {
  4151. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  4152. int32_t status = 0;
  4153. DEBUGFUNC("e1000_write_eeprom");
  4154. /* A check for invalid values: offset too large, too many words, and not
  4155. * enough words.
  4156. */
  4157. if((offset >= eeprom->word_size) || (words > eeprom->word_size - offset) ||
  4158. (words == 0)) {
  4159. DEBUGOUT("\"words\" parameter out of bounds\n");
  4160. return -E1000_ERR_EEPROM;
  4161. }
  4162. /* 82573 writes only through eewr */
  4163. if(eeprom->use_eewr == TRUE)
  4164. return e1000_write_eeprom_eewr(hw, offset, words, data);
  4165. /* Prepare the EEPROM for writing */
  4166. if (e1000_acquire_eeprom(hw) != E1000_SUCCESS)
  4167. return -E1000_ERR_EEPROM;
  4168. if(eeprom->type == e1000_eeprom_microwire) {
  4169. status = e1000_write_eeprom_microwire(hw, offset, words, data);
  4170. } else {
  4171. status = e1000_write_eeprom_spi(hw, offset, words, data);
  4172. msec_delay(10);
  4173. }
  4174. /* Done with writing */
  4175. e1000_release_eeprom(hw);
  4176. return status;
  4177. }
  4178. /******************************************************************************
  4179. * Writes a 16 bit word to a given offset in an SPI EEPROM.
  4180. *
  4181. * hw - Struct containing variables accessed by shared code
  4182. * offset - offset within the EEPROM to be written to
  4183. * words - number of words to write
  4184. * data - pointer to array of 8 bit words to be written to the EEPROM
  4185. *
  4186. *****************************************************************************/
  4187. int32_t
  4188. e1000_write_eeprom_spi(struct e1000_hw *hw,
  4189. uint16_t offset,
  4190. uint16_t words,
  4191. uint16_t *data)
  4192. {
  4193. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  4194. uint16_t widx = 0;
  4195. DEBUGFUNC("e1000_write_eeprom_spi");
  4196. while (widx < words) {
  4197. uint8_t write_opcode = EEPROM_WRITE_OPCODE_SPI;
  4198. if(e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
  4199. e1000_standby_eeprom(hw);
  4200. /* Send the WRITE ENABLE command (8 bit opcode ) */
  4201. e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
  4202. eeprom->opcode_bits);
  4203. e1000_standby_eeprom(hw);
  4204. /* Some SPI eeproms use the 8th address bit embedded in the opcode */
  4205. if((eeprom->address_bits == 8) && (offset >= 128))
  4206. write_opcode |= EEPROM_A8_OPCODE_SPI;
  4207. /* Send the Write command (8-bit opcode + addr) */
  4208. e1000_shift_out_ee_bits(hw, write_opcode, eeprom->opcode_bits);
  4209. e1000_shift_out_ee_bits(hw, (uint16_t)((offset + widx)*2),
  4210. eeprom->address_bits);
  4211. /* Send the data */
  4212. /* Loop to allow for up to whole page write (32 bytes) of eeprom */
  4213. while (widx < words) {
  4214. uint16_t word_out = data[widx];
  4215. word_out = (word_out >> 8) | (word_out << 8);
  4216. e1000_shift_out_ee_bits(hw, word_out, 16);
  4217. widx++;
  4218. /* Some larger eeprom sizes are capable of a 32-byte PAGE WRITE
  4219. * operation, while the smaller eeproms are capable of an 8-byte
  4220. * PAGE WRITE operation. Break the inner loop to pass new address
  4221. */
  4222. if((((offset + widx)*2) % eeprom->page_size) == 0) {
  4223. e1000_standby_eeprom(hw);
  4224. break;
  4225. }
  4226. }
  4227. }
  4228. return E1000_SUCCESS;
  4229. }
  4230. /******************************************************************************
  4231. * Writes a 16 bit word to a given offset in a Microwire EEPROM.
  4232. *
  4233. * hw - Struct containing variables accessed by shared code
  4234. * offset - offset within the EEPROM to be written to
  4235. * words - number of words to write
  4236. * data - pointer to array of 16 bit words to be written to the EEPROM
  4237. *
  4238. *****************************************************************************/
  4239. int32_t
  4240. e1000_write_eeprom_microwire(struct e1000_hw *hw,
  4241. uint16_t offset,
  4242. uint16_t words,
  4243. uint16_t *data)
  4244. {
  4245. struct e1000_eeprom_info *eeprom = &hw->eeprom;
  4246. uint32_t eecd;
  4247. uint16_t words_written = 0;
  4248. uint16_t i = 0;
  4249. DEBUGFUNC("e1000_write_eeprom_microwire");
  4250. /* Send the write enable command to the EEPROM (3-bit opcode plus
  4251. * 6/8-bit dummy address beginning with 11). It's less work to include
  4252. * the 11 of the dummy address as part of the opcode than it is to shift
  4253. * it over the correct number of bits for the address. This puts the
  4254. * EEPROM into write/erase mode.
  4255. */
  4256. e1000_shift_out_ee_bits(hw, EEPROM_EWEN_OPCODE_MICROWIRE,
  4257. (uint16_t)(eeprom->opcode_bits + 2));
  4258. e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
  4259. /* Prepare the EEPROM */
  4260. e1000_standby_eeprom(hw);
  4261. while (words_written < words) {
  4262. /* Send the Write command (3-bit opcode + addr) */
  4263. e1000_shift_out_ee_bits(hw, EEPROM_WRITE_OPCODE_MICROWIRE,
  4264. eeprom->opcode_bits);
  4265. e1000_shift_out_ee_bits(hw, (uint16_t)(offset + words_written),
  4266. eeprom->address_bits);
  4267. /* Send the data */
  4268. e1000_shift_out_ee_bits(hw, data[words_written], 16);
  4269. /* Toggle the CS line. This in effect tells the EEPROM to execute
  4270. * the previous command.
  4271. */
  4272. e1000_standby_eeprom(hw);
  4273. /* Read DO repeatedly until it is high (equal to '1'). The EEPROM will
  4274. * signal that the command has been completed by raising the DO signal.
  4275. * If DO does not go high in 10 milliseconds, then error out.
  4276. */
  4277. for(i = 0; i < 200; i++) {
  4278. eecd = E1000_READ_REG(hw, EECD);
  4279. if(eecd & E1000_EECD_DO) break;
  4280. udelay(50);
  4281. }
  4282. if(i == 200) {
  4283. DEBUGOUT("EEPROM Write did not complete\n");
  4284. return -E1000_ERR_EEPROM;
  4285. }
  4286. /* Recover from write */
  4287. e1000_standby_eeprom(hw);
  4288. words_written++;
  4289. }
  4290. /* Send the write disable command to the EEPROM (3-bit opcode plus
  4291. * 6/8-bit dummy address beginning with 10). It's less work to include
  4292. * the 10 of the dummy address as part of the opcode than it is to shift
  4293. * it over the correct number of bits for the address. This takes the
  4294. * EEPROM out of write/erase mode.
  4295. */
  4296. e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
  4297. (uint16_t)(eeprom->opcode_bits + 2));
  4298. e1000_shift_out_ee_bits(hw, 0, (uint16_t)(eeprom->address_bits - 2));
  4299. return E1000_SUCCESS;
  4300. }
  4301. /******************************************************************************
  4302. * Flushes the cached eeprom to NVM. This is done by saving the modified values
  4303. * in the eeprom cache and the non modified values in the currently active bank
  4304. * to the new bank.
  4305. *
  4306. * hw - Struct containing variables accessed by shared code
  4307. * offset - offset of word in the EEPROM to read
  4308. * data - word read from the EEPROM
  4309. * words - number of words to read
  4310. *****************************************************************************/
  4311. static int32_t
  4312. e1000_commit_shadow_ram(struct e1000_hw *hw)
  4313. {
  4314. uint32_t attempts = 100000;
  4315. uint32_t eecd = 0;
  4316. uint32_t flop = 0;
  4317. uint32_t i = 0;
  4318. int32_t error = E1000_SUCCESS;
  4319. /* The flop register will be used to determine if flash type is STM */
  4320. flop = E1000_READ_REG(hw, FLOP);
  4321. if (hw->mac_type == e1000_82573) {
  4322. for (i=0; i < attempts; i++) {
  4323. eecd = E1000_READ_REG(hw, EECD);
  4324. if ((eecd & E1000_EECD_FLUPD) == 0) {
  4325. break;
  4326. }
  4327. udelay(5);
  4328. }
  4329. if (i == attempts) {
  4330. return -E1000_ERR_EEPROM;
  4331. }
  4332. /* If STM opcode located in bits 15:8 of flop, reset firmware */
  4333. if ((flop & 0xFF00) == E1000_STM_OPCODE) {
  4334. E1000_WRITE_REG(hw, HICR, E1000_HICR_FW_RESET);
  4335. }
  4336. /* Perform the flash update */
  4337. E1000_WRITE_REG(hw, EECD, eecd | E1000_EECD_FLUPD);
  4338. for (i=0; i < attempts; i++) {
  4339. eecd = E1000_READ_REG(hw, EECD);
  4340. if ((eecd & E1000_EECD_FLUPD) == 0) {
  4341. break;
  4342. }
  4343. udelay(5);
  4344. }
  4345. if (i == attempts) {
  4346. return -E1000_ERR_EEPROM;
  4347. }
  4348. }
  4349. return error;
  4350. }
  4351. /******************************************************************************
  4352. * Reads the adapter's part number from the EEPROM
  4353. *
  4354. * hw - Struct containing variables accessed by shared code
  4355. * part_num - Adapter's part number
  4356. *****************************************************************************/
  4357. int32_t
  4358. e1000_read_part_num(struct e1000_hw *hw,
  4359. uint32_t *part_num)
  4360. {
  4361. uint16_t offset = EEPROM_PBA_BYTE_1;
  4362. uint16_t eeprom_data;
  4363. DEBUGFUNC("e1000_read_part_num");
  4364. /* Get word 0 from EEPROM */
  4365. if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
  4366. DEBUGOUT("EEPROM Read Error\n");
  4367. return -E1000_ERR_EEPROM;
  4368. }
  4369. /* Save word 0 in upper half of part_num */
  4370. *part_num = (uint32_t) (eeprom_data << 16);
  4371. /* Get word 1 from EEPROM */
  4372. if(e1000_read_eeprom(hw, ++offset, 1, &eeprom_data) < 0) {
  4373. DEBUGOUT("EEPROM Read Error\n");
  4374. return -E1000_ERR_EEPROM;
  4375. }
  4376. /* Save word 1 in lower half of part_num */
  4377. *part_num |= eeprom_data;
  4378. return E1000_SUCCESS;
  4379. }
  4380. /******************************************************************************
  4381. * Reads the adapter's MAC address from the EEPROM and inverts the LSB for the
  4382. * second function of dual function devices
  4383. *
  4384. * hw - Struct containing variables accessed by shared code
  4385. *****************************************************************************/
  4386. int32_t
  4387. e1000_read_mac_addr(struct e1000_hw * hw)
  4388. {
  4389. uint16_t offset;
  4390. uint16_t eeprom_data, i;
  4391. DEBUGFUNC("e1000_read_mac_addr");
  4392. for(i = 0; i < NODE_ADDRESS_SIZE; i += 2) {
  4393. offset = i >> 1;
  4394. if(e1000_read_eeprom(hw, offset, 1, &eeprom_data) < 0) {
  4395. DEBUGOUT("EEPROM Read Error\n");
  4396. return -E1000_ERR_EEPROM;
  4397. }
  4398. hw->perm_mac_addr[i] = (uint8_t) (eeprom_data & 0x00FF);
  4399. hw->perm_mac_addr[i+1] = (uint8_t) (eeprom_data >> 8);
  4400. }
  4401. switch (hw->mac_type) {
  4402. default:
  4403. break;
  4404. case e1000_82546:
  4405. case e1000_82546_rev_3:
  4406. case e1000_82571:
  4407. case e1000_80003es2lan:
  4408. if(E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
  4409. hw->perm_mac_addr[5] ^= 0x01;
  4410. break;
  4411. }
  4412. for(i = 0; i < NODE_ADDRESS_SIZE; i++)
  4413. hw->mac_addr[i] = hw->perm_mac_addr[i];
  4414. return E1000_SUCCESS;
  4415. }
  4416. /******************************************************************************
  4417. * Initializes receive address filters.
  4418. *
  4419. * hw - Struct containing variables accessed by shared code
  4420. *
  4421. * Places the MAC address in receive address register 0 and clears the rest
  4422. * of the receive addresss registers. Clears the multicast table. Assumes
  4423. * the receiver is in reset when the routine is called.
  4424. *****************************************************************************/
  4425. static void
  4426. e1000_init_rx_addrs(struct e1000_hw *hw)
  4427. {
  4428. uint32_t i;
  4429. uint32_t rar_num;
  4430. DEBUGFUNC("e1000_init_rx_addrs");
  4431. /* Setup the receive address. */
  4432. DEBUGOUT("Programming MAC Address into RAR[0]\n");
  4433. e1000_rar_set(hw, hw->mac_addr, 0);
  4434. rar_num = E1000_RAR_ENTRIES;
  4435. /* Reserve a spot for the Locally Administered Address to work around
  4436. * an 82571 issue in which a reset on one port will reload the MAC on
  4437. * the other port. */
  4438. if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
  4439. rar_num -= 1;
  4440. /* Zero out the other 15 receive addresses. */
  4441. DEBUGOUT("Clearing RAR[1-15]\n");
  4442. for(i = 1; i < rar_num; i++) {
  4443. E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
  4444. E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
  4445. }
  4446. }
  4447. #if 0
  4448. /******************************************************************************
  4449. * Updates the MAC's list of multicast addresses.
  4450. *
  4451. * hw - Struct containing variables accessed by shared code
  4452. * mc_addr_list - the list of new multicast addresses
  4453. * mc_addr_count - number of addresses
  4454. * pad - number of bytes between addresses in the list
  4455. * rar_used_count - offset where to start adding mc addresses into the RAR's
  4456. *
  4457. * The given list replaces any existing list. Clears the last 15 receive
  4458. * address registers and the multicast table. Uses receive address registers
  4459. * for the first 15 multicast addresses, and hashes the rest into the
  4460. * multicast table.
  4461. *****************************************************************************/
  4462. void
  4463. e1000_mc_addr_list_update(struct e1000_hw *hw,
  4464. uint8_t *mc_addr_list,
  4465. uint32_t mc_addr_count,
  4466. uint32_t pad,
  4467. uint32_t rar_used_count)
  4468. {
  4469. uint32_t hash_value;
  4470. uint32_t i;
  4471. uint32_t num_rar_entry;
  4472. uint32_t num_mta_entry;
  4473. DEBUGFUNC("e1000_mc_addr_list_update");
  4474. /* Set the new number of MC addresses that we are being requested to use. */
  4475. hw->num_mc_addrs = mc_addr_count;
  4476. /* Clear RAR[1-15] */
  4477. DEBUGOUT(" Clearing RAR[1-15]\n");
  4478. num_rar_entry = E1000_RAR_ENTRIES;
  4479. /* Reserve a spot for the Locally Administered Address to work around
  4480. * an 82571 issue in which a reset on one port will reload the MAC on
  4481. * the other port. */
  4482. if ((hw->mac_type == e1000_82571) && (hw->laa_is_present == TRUE))
  4483. num_rar_entry -= 1;
  4484. for(i = rar_used_count; i < num_rar_entry; i++) {
  4485. E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
  4486. E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
  4487. }
  4488. /* Clear the MTA */
  4489. DEBUGOUT(" Clearing MTA\n");
  4490. num_mta_entry = E1000_NUM_MTA_REGISTERS;
  4491. for(i = 0; i < num_mta_entry; i++) {
  4492. E1000_WRITE_REG_ARRAY(hw, MTA, i, 0);
  4493. }
  4494. /* Add the new addresses */
  4495. for(i = 0; i < mc_addr_count; i++) {
  4496. DEBUGOUT(" Adding the multicast addresses:\n");
  4497. DEBUGOUT7(" MC Addr #%d =%.2X %.2X %.2X %.2X %.2X %.2X\n", i,
  4498. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad)],
  4499. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 1],
  4500. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 2],
  4501. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 3],
  4502. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 4],
  4503. mc_addr_list[i * (ETH_LENGTH_OF_ADDRESS + pad) + 5]);
  4504. hash_value = e1000_hash_mc_addr(hw,
  4505. mc_addr_list +
  4506. (i * (ETH_LENGTH_OF_ADDRESS + pad)));
  4507. DEBUGOUT1(" Hash value = 0x%03X\n", hash_value);
  4508. /* Place this multicast address in the RAR if there is room, *
  4509. * else put it in the MTA
  4510. */
  4511. if (rar_used_count < num_rar_entry) {
  4512. e1000_rar_set(hw,
  4513. mc_addr_list + (i * (ETH_LENGTH_OF_ADDRESS + pad)),
  4514. rar_used_count);
  4515. rar_used_count++;
  4516. } else {
  4517. e1000_mta_set(hw, hash_value);
  4518. }
  4519. }
  4520. DEBUGOUT("MC Update Complete\n");
  4521. }
  4522. #endif /* 0 */
  4523. /******************************************************************************
  4524. * Hashes an address to determine its location in the multicast table
  4525. *
  4526. * hw - Struct containing variables accessed by shared code
  4527. * mc_addr - the multicast address to hash
  4528. *****************************************************************************/
  4529. uint32_t
  4530. e1000_hash_mc_addr(struct e1000_hw *hw,
  4531. uint8_t *mc_addr)
  4532. {
  4533. uint32_t hash_value = 0;
  4534. /* The portion of the address that is used for the hash table is
  4535. * determined by the mc_filter_type setting.
  4536. */
  4537. switch (hw->mc_filter_type) {
  4538. /* [0] [1] [2] [3] [4] [5]
  4539. * 01 AA 00 12 34 56
  4540. * LSB MSB
  4541. */
  4542. case 0:
  4543. /* [47:36] i.e. 0x563 for above example address */
  4544. hash_value = ((mc_addr[4] >> 4) | (((uint16_t) mc_addr[5]) << 4));
  4545. break;
  4546. case 1:
  4547. /* [46:35] i.e. 0xAC6 for above example address */
  4548. hash_value = ((mc_addr[4] >> 3) | (((uint16_t) mc_addr[5]) << 5));
  4549. break;
  4550. case 2:
  4551. /* [45:34] i.e. 0x5D8 for above example address */
  4552. hash_value = ((mc_addr[4] >> 2) | (((uint16_t) mc_addr[5]) << 6));
  4553. break;
  4554. case 3:
  4555. /* [43:32] i.e. 0x634 for above example address */
  4556. hash_value = ((mc_addr[4]) | (((uint16_t) mc_addr[5]) << 8));
  4557. break;
  4558. }
  4559. hash_value &= 0xFFF;
  4560. return hash_value;
  4561. }
  4562. /******************************************************************************
  4563. * Sets the bit in the multicast table corresponding to the hash value.
  4564. *
  4565. * hw - Struct containing variables accessed by shared code
  4566. * hash_value - Multicast address hash value
  4567. *****************************************************************************/
  4568. void
  4569. e1000_mta_set(struct e1000_hw *hw,
  4570. uint32_t hash_value)
  4571. {
  4572. uint32_t hash_bit, hash_reg;
  4573. uint32_t mta;
  4574. uint32_t temp;
  4575. /* The MTA is a register array of 128 32-bit registers.
  4576. * It is treated like an array of 4096 bits. We want to set
  4577. * bit BitArray[hash_value]. So we figure out what register
  4578. * the bit is in, read it, OR in the new bit, then write
  4579. * back the new value. The register is determined by the
  4580. * upper 7 bits of the hash value and the bit within that
  4581. * register are determined by the lower 5 bits of the value.
  4582. */
  4583. hash_reg = (hash_value >> 5) & 0x7F;
  4584. hash_bit = hash_value & 0x1F;
  4585. mta = E1000_READ_REG_ARRAY(hw, MTA, hash_reg);
  4586. mta |= (1 << hash_bit);
  4587. /* If we are on an 82544 and we are trying to write an odd offset
  4588. * in the MTA, save off the previous entry before writing and
  4589. * restore the old value after writing.
  4590. */
  4591. if((hw->mac_type == e1000_82544) && ((hash_reg & 0x1) == 1)) {
  4592. temp = E1000_READ_REG_ARRAY(hw, MTA, (hash_reg - 1));
  4593. E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
  4594. E1000_WRITE_REG_ARRAY(hw, MTA, (hash_reg - 1), temp);
  4595. } else {
  4596. E1000_WRITE_REG_ARRAY(hw, MTA, hash_reg, mta);
  4597. }
  4598. }
  4599. /******************************************************************************
  4600. * Puts an ethernet address into a receive address register.
  4601. *
  4602. * hw - Struct containing variables accessed by shared code
  4603. * addr - Address to put into receive address register
  4604. * index - Receive address register to write
  4605. *****************************************************************************/
  4606. void
  4607. e1000_rar_set(struct e1000_hw *hw,
  4608. uint8_t *addr,
  4609. uint32_t index)
  4610. {
  4611. uint32_t rar_low, rar_high;
  4612. /* HW expects these in little endian so we reverse the byte order
  4613. * from network order (big endian) to little endian
  4614. */
  4615. rar_low = ((uint32_t) addr[0] |
  4616. ((uint32_t) addr[1] << 8) |
  4617. ((uint32_t) addr[2] << 16) | ((uint32_t) addr[3] << 24));
  4618. rar_high = ((uint32_t) addr[4] | ((uint32_t) addr[5] << 8));
  4619. /* Disable Rx and flush all Rx frames before enabling RSS to avoid Rx
  4620. * unit hang.
  4621. *
  4622. * Description:
  4623. * If there are any Rx frames queued up or otherwise present in the HW
  4624. * before RSS is enabled, and then we enable RSS, the HW Rx unit will
  4625. * hang. To work around this issue, we have to disable receives and
  4626. * flush out all Rx frames before we enable RSS. To do so, we modify we
  4627. * redirect all Rx traffic to manageability and then reset the HW.
  4628. * This flushes away Rx frames, and (since the redirections to
  4629. * manageability persists across resets) keeps new ones from coming in
  4630. * while we work. Then, we clear the Address Valid AV bit for all MAC
  4631. * addresses and undo the re-direction to manageability.
  4632. * Now, frames are coming in again, but the MAC won't accept them, so
  4633. * far so good. We now proceed to initialize RSS (if necessary) and
  4634. * configure the Rx unit. Last, we re-enable the AV bits and continue
  4635. * on our merry way.
  4636. */
  4637. switch (hw->mac_type) {
  4638. case e1000_82571:
  4639. case e1000_82572:
  4640. case e1000_80003es2lan:
  4641. if (hw->leave_av_bit_off == TRUE)
  4642. break;
  4643. default:
  4644. /* Indicate to hardware the Address is Valid. */
  4645. rar_high |= E1000_RAH_AV;
  4646. break;
  4647. }
  4648. E1000_WRITE_REG_ARRAY(hw, RA, (index << 1), rar_low);
  4649. E1000_WRITE_REG_ARRAY(hw, RA, ((index << 1) + 1), rar_high);
  4650. }
  4651. /******************************************************************************
  4652. * Writes a value to the specified offset in the VLAN filter table.
  4653. *
  4654. * hw - Struct containing variables accessed by shared code
  4655. * offset - Offset in VLAN filer table to write
  4656. * value - Value to write into VLAN filter table
  4657. *****************************************************************************/
  4658. void
  4659. e1000_write_vfta(struct e1000_hw *hw,
  4660. uint32_t offset,
  4661. uint32_t value)
  4662. {
  4663. uint32_t temp;
  4664. if((hw->mac_type == e1000_82544) && ((offset & 0x1) == 1)) {
  4665. temp = E1000_READ_REG_ARRAY(hw, VFTA, (offset - 1));
  4666. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
  4667. E1000_WRITE_REG_ARRAY(hw, VFTA, (offset - 1), temp);
  4668. } else {
  4669. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, value);
  4670. }
  4671. }
  4672. /******************************************************************************
  4673. * Clears the VLAN filer table
  4674. *
  4675. * hw - Struct containing variables accessed by shared code
  4676. *****************************************************************************/
  4677. static void
  4678. e1000_clear_vfta(struct e1000_hw *hw)
  4679. {
  4680. uint32_t offset;
  4681. uint32_t vfta_value = 0;
  4682. uint32_t vfta_offset = 0;
  4683. uint32_t vfta_bit_in_reg = 0;
  4684. if (hw->mac_type == e1000_82573) {
  4685. if (hw->mng_cookie.vlan_id != 0) {
  4686. /* The VFTA is a 4096b bit-field, each identifying a single VLAN
  4687. * ID. The following operations determine which 32b entry
  4688. * (i.e. offset) into the array we want to set the VLAN ID
  4689. * (i.e. bit) of the manageability unit. */
  4690. vfta_offset = (hw->mng_cookie.vlan_id >>
  4691. E1000_VFTA_ENTRY_SHIFT) &
  4692. E1000_VFTA_ENTRY_MASK;
  4693. vfta_bit_in_reg = 1 << (hw->mng_cookie.vlan_id &
  4694. E1000_VFTA_ENTRY_BIT_SHIFT_MASK);
  4695. }
  4696. }
  4697. for (offset = 0; offset < E1000_VLAN_FILTER_TBL_SIZE; offset++) {
  4698. /* If the offset we want to clear is the same offset of the
  4699. * manageability VLAN ID, then clear all bits except that of the
  4700. * manageability unit */
  4701. vfta_value = (offset == vfta_offset) ? vfta_bit_in_reg : 0;
  4702. E1000_WRITE_REG_ARRAY(hw, VFTA, offset, vfta_value);
  4703. }
  4704. }
  4705. static int32_t
  4706. e1000_id_led_init(struct e1000_hw * hw)
  4707. {
  4708. uint32_t ledctl;
  4709. const uint32_t ledctl_mask = 0x000000FF;
  4710. const uint32_t ledctl_on = E1000_LEDCTL_MODE_LED_ON;
  4711. const uint32_t ledctl_off = E1000_LEDCTL_MODE_LED_OFF;
  4712. uint16_t eeprom_data, i, temp;
  4713. const uint16_t led_mask = 0x0F;
  4714. DEBUGFUNC("e1000_id_led_init");
  4715. if(hw->mac_type < e1000_82540) {
  4716. /* Nothing to do */
  4717. return E1000_SUCCESS;
  4718. }
  4719. ledctl = E1000_READ_REG(hw, LEDCTL);
  4720. hw->ledctl_default = ledctl;
  4721. hw->ledctl_mode1 = hw->ledctl_default;
  4722. hw->ledctl_mode2 = hw->ledctl_default;
  4723. if(e1000_read_eeprom(hw, EEPROM_ID_LED_SETTINGS, 1, &eeprom_data) < 0) {
  4724. DEBUGOUT("EEPROM Read Error\n");
  4725. return -E1000_ERR_EEPROM;
  4726. }
  4727. if((eeprom_data== ID_LED_RESERVED_0000) ||
  4728. (eeprom_data == ID_LED_RESERVED_FFFF)) eeprom_data = ID_LED_DEFAULT;
  4729. for(i = 0; i < 4; i++) {
  4730. temp = (eeprom_data >> (i << 2)) & led_mask;
  4731. switch(temp) {
  4732. case ID_LED_ON1_DEF2:
  4733. case ID_LED_ON1_ON2:
  4734. case ID_LED_ON1_OFF2:
  4735. hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  4736. hw->ledctl_mode1 |= ledctl_on << (i << 3);
  4737. break;
  4738. case ID_LED_OFF1_DEF2:
  4739. case ID_LED_OFF1_ON2:
  4740. case ID_LED_OFF1_OFF2:
  4741. hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
  4742. hw->ledctl_mode1 |= ledctl_off << (i << 3);
  4743. break;
  4744. default:
  4745. /* Do nothing */
  4746. break;
  4747. }
  4748. switch(temp) {
  4749. case ID_LED_DEF1_ON2:
  4750. case ID_LED_ON1_ON2:
  4751. case ID_LED_OFF1_ON2:
  4752. hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  4753. hw->ledctl_mode2 |= ledctl_on << (i << 3);
  4754. break;
  4755. case ID_LED_DEF1_OFF2:
  4756. case ID_LED_ON1_OFF2:
  4757. case ID_LED_OFF1_OFF2:
  4758. hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
  4759. hw->ledctl_mode2 |= ledctl_off << (i << 3);
  4760. break;
  4761. default:
  4762. /* Do nothing */
  4763. break;
  4764. }
  4765. }
  4766. return E1000_SUCCESS;
  4767. }
  4768. /******************************************************************************
  4769. * Prepares SW controlable LED for use and saves the current state of the LED.
  4770. *
  4771. * hw - Struct containing variables accessed by shared code
  4772. *****************************************************************************/
  4773. int32_t
  4774. e1000_setup_led(struct e1000_hw *hw)
  4775. {
  4776. uint32_t ledctl;
  4777. int32_t ret_val = E1000_SUCCESS;
  4778. DEBUGFUNC("e1000_setup_led");
  4779. switch(hw->mac_type) {
  4780. case e1000_82542_rev2_0:
  4781. case e1000_82542_rev2_1:
  4782. case e1000_82543:
  4783. case e1000_82544:
  4784. /* No setup necessary */
  4785. break;
  4786. case e1000_82541:
  4787. case e1000_82547:
  4788. case e1000_82541_rev_2:
  4789. case e1000_82547_rev_2:
  4790. /* Turn off PHY Smart Power Down (if enabled) */
  4791. ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO,
  4792. &hw->phy_spd_default);
  4793. if(ret_val)
  4794. return ret_val;
  4795. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
  4796. (uint16_t)(hw->phy_spd_default &
  4797. ~IGP01E1000_GMII_SPD));
  4798. if(ret_val)
  4799. return ret_val;
  4800. /* Fall Through */
  4801. default:
  4802. if(hw->media_type == e1000_media_type_fiber) {
  4803. ledctl = E1000_READ_REG(hw, LEDCTL);
  4804. /* Save current LEDCTL settings */
  4805. hw->ledctl_default = ledctl;
  4806. /* Turn off LED0 */
  4807. ledctl &= ~(E1000_LEDCTL_LED0_IVRT |
  4808. E1000_LEDCTL_LED0_BLINK |
  4809. E1000_LEDCTL_LED0_MODE_MASK);
  4810. ledctl |= (E1000_LEDCTL_MODE_LED_OFF <<
  4811. E1000_LEDCTL_LED0_MODE_SHIFT);
  4812. E1000_WRITE_REG(hw, LEDCTL, ledctl);
  4813. } else if(hw->media_type == e1000_media_type_copper)
  4814. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
  4815. break;
  4816. }
  4817. return E1000_SUCCESS;
  4818. }
  4819. /******************************************************************************
  4820. * Restores the saved state of the SW controlable LED.
  4821. *
  4822. * hw - Struct containing variables accessed by shared code
  4823. *****************************************************************************/
  4824. int32_t
  4825. e1000_cleanup_led(struct e1000_hw *hw)
  4826. {
  4827. int32_t ret_val = E1000_SUCCESS;
  4828. DEBUGFUNC("e1000_cleanup_led");
  4829. switch(hw->mac_type) {
  4830. case e1000_82542_rev2_0:
  4831. case e1000_82542_rev2_1:
  4832. case e1000_82543:
  4833. case e1000_82544:
  4834. /* No cleanup necessary */
  4835. break;
  4836. case e1000_82541:
  4837. case e1000_82547:
  4838. case e1000_82541_rev_2:
  4839. case e1000_82547_rev_2:
  4840. /* Turn on PHY Smart Power Down (if previously enabled) */
  4841. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
  4842. hw->phy_spd_default);
  4843. if(ret_val)
  4844. return ret_val;
  4845. /* Fall Through */
  4846. default:
  4847. /* Restore LEDCTL settings */
  4848. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_default);
  4849. break;
  4850. }
  4851. return E1000_SUCCESS;
  4852. }
  4853. /******************************************************************************
  4854. * Turns on the software controllable LED
  4855. *
  4856. * hw - Struct containing variables accessed by shared code
  4857. *****************************************************************************/
  4858. int32_t
  4859. e1000_led_on(struct e1000_hw *hw)
  4860. {
  4861. uint32_t ctrl = E1000_READ_REG(hw, CTRL);
  4862. DEBUGFUNC("e1000_led_on");
  4863. switch(hw->mac_type) {
  4864. case e1000_82542_rev2_0:
  4865. case e1000_82542_rev2_1:
  4866. case e1000_82543:
  4867. /* Set SW Defineable Pin 0 to turn on the LED */
  4868. ctrl |= E1000_CTRL_SWDPIN0;
  4869. ctrl |= E1000_CTRL_SWDPIO0;
  4870. break;
  4871. case e1000_82544:
  4872. if(hw->media_type == e1000_media_type_fiber) {
  4873. /* Set SW Defineable Pin 0 to turn on the LED */
  4874. ctrl |= E1000_CTRL_SWDPIN0;
  4875. ctrl |= E1000_CTRL_SWDPIO0;
  4876. } else {
  4877. /* Clear SW Defineable Pin 0 to turn on the LED */
  4878. ctrl &= ~E1000_CTRL_SWDPIN0;
  4879. ctrl |= E1000_CTRL_SWDPIO0;
  4880. }
  4881. break;
  4882. default:
  4883. if(hw->media_type == e1000_media_type_fiber) {
  4884. /* Clear SW Defineable Pin 0 to turn on the LED */
  4885. ctrl &= ~E1000_CTRL_SWDPIN0;
  4886. ctrl |= E1000_CTRL_SWDPIO0;
  4887. } else if(hw->media_type == e1000_media_type_copper) {
  4888. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode2);
  4889. return E1000_SUCCESS;
  4890. }
  4891. break;
  4892. }
  4893. E1000_WRITE_REG(hw, CTRL, ctrl);
  4894. return E1000_SUCCESS;
  4895. }
  4896. /******************************************************************************
  4897. * Turns off the software controllable LED
  4898. *
  4899. * hw - Struct containing variables accessed by shared code
  4900. *****************************************************************************/
  4901. int32_t
  4902. e1000_led_off(struct e1000_hw *hw)
  4903. {
  4904. uint32_t ctrl = E1000_READ_REG(hw, CTRL);
  4905. DEBUGFUNC("e1000_led_off");
  4906. switch(hw->mac_type) {
  4907. case e1000_82542_rev2_0:
  4908. case e1000_82542_rev2_1:
  4909. case e1000_82543:
  4910. /* Clear SW Defineable Pin 0 to turn off the LED */
  4911. ctrl &= ~E1000_CTRL_SWDPIN0;
  4912. ctrl |= E1000_CTRL_SWDPIO0;
  4913. break;
  4914. case e1000_82544:
  4915. if(hw->media_type == e1000_media_type_fiber) {
  4916. /* Clear SW Defineable Pin 0 to turn off the LED */
  4917. ctrl &= ~E1000_CTRL_SWDPIN0;
  4918. ctrl |= E1000_CTRL_SWDPIO0;
  4919. } else {
  4920. /* Set SW Defineable Pin 0 to turn off the LED */
  4921. ctrl |= E1000_CTRL_SWDPIN0;
  4922. ctrl |= E1000_CTRL_SWDPIO0;
  4923. }
  4924. break;
  4925. default:
  4926. if(hw->media_type == e1000_media_type_fiber) {
  4927. /* Set SW Defineable Pin 0 to turn off the LED */
  4928. ctrl |= E1000_CTRL_SWDPIN0;
  4929. ctrl |= E1000_CTRL_SWDPIO0;
  4930. } else if(hw->media_type == e1000_media_type_copper) {
  4931. E1000_WRITE_REG(hw, LEDCTL, hw->ledctl_mode1);
  4932. return E1000_SUCCESS;
  4933. }
  4934. break;
  4935. }
  4936. E1000_WRITE_REG(hw, CTRL, ctrl);
  4937. return E1000_SUCCESS;
  4938. }
  4939. /******************************************************************************
  4940. * Clears all hardware statistics counters.
  4941. *
  4942. * hw - Struct containing variables accessed by shared code
  4943. *****************************************************************************/
  4944. static void
  4945. e1000_clear_hw_cntrs(struct e1000_hw *hw)
  4946. {
  4947. volatile uint32_t temp;
  4948. temp = E1000_READ_REG(hw, CRCERRS);
  4949. temp = E1000_READ_REG(hw, SYMERRS);
  4950. temp = E1000_READ_REG(hw, MPC);
  4951. temp = E1000_READ_REG(hw, SCC);
  4952. temp = E1000_READ_REG(hw, ECOL);
  4953. temp = E1000_READ_REG(hw, MCC);
  4954. temp = E1000_READ_REG(hw, LATECOL);
  4955. temp = E1000_READ_REG(hw, COLC);
  4956. temp = E1000_READ_REG(hw, DC);
  4957. temp = E1000_READ_REG(hw, SEC);
  4958. temp = E1000_READ_REG(hw, RLEC);
  4959. temp = E1000_READ_REG(hw, XONRXC);
  4960. temp = E1000_READ_REG(hw, XONTXC);
  4961. temp = E1000_READ_REG(hw, XOFFRXC);
  4962. temp = E1000_READ_REG(hw, XOFFTXC);
  4963. temp = E1000_READ_REG(hw, FCRUC);
  4964. temp = E1000_READ_REG(hw, PRC64);
  4965. temp = E1000_READ_REG(hw, PRC127);
  4966. temp = E1000_READ_REG(hw, PRC255);
  4967. temp = E1000_READ_REG(hw, PRC511);
  4968. temp = E1000_READ_REG(hw, PRC1023);
  4969. temp = E1000_READ_REG(hw, PRC1522);
  4970. temp = E1000_READ_REG(hw, GPRC);
  4971. temp = E1000_READ_REG(hw, BPRC);
  4972. temp = E1000_READ_REG(hw, MPRC);
  4973. temp = E1000_READ_REG(hw, GPTC);
  4974. temp = E1000_READ_REG(hw, GORCL);
  4975. temp = E1000_READ_REG(hw, GORCH);
  4976. temp = E1000_READ_REG(hw, GOTCL);
  4977. temp = E1000_READ_REG(hw, GOTCH);
  4978. temp = E1000_READ_REG(hw, RNBC);
  4979. temp = E1000_READ_REG(hw, RUC);
  4980. temp = E1000_READ_REG(hw, RFC);
  4981. temp = E1000_READ_REG(hw, ROC);
  4982. temp = E1000_READ_REG(hw, RJC);
  4983. temp = E1000_READ_REG(hw, TORL);
  4984. temp = E1000_READ_REG(hw, TORH);
  4985. temp = E1000_READ_REG(hw, TOTL);
  4986. temp = E1000_READ_REG(hw, TOTH);
  4987. temp = E1000_READ_REG(hw, TPR);
  4988. temp = E1000_READ_REG(hw, TPT);
  4989. temp = E1000_READ_REG(hw, PTC64);
  4990. temp = E1000_READ_REG(hw, PTC127);
  4991. temp = E1000_READ_REG(hw, PTC255);
  4992. temp = E1000_READ_REG(hw, PTC511);
  4993. temp = E1000_READ_REG(hw, PTC1023);
  4994. temp = E1000_READ_REG(hw, PTC1522);
  4995. temp = E1000_READ_REG(hw, MPTC);
  4996. temp = E1000_READ_REG(hw, BPTC);
  4997. if(hw->mac_type < e1000_82543) return;
  4998. temp = E1000_READ_REG(hw, ALGNERRC);
  4999. temp = E1000_READ_REG(hw, RXERRC);
  5000. temp = E1000_READ_REG(hw, TNCRS);
  5001. temp = E1000_READ_REG(hw, CEXTERR);
  5002. temp = E1000_READ_REG(hw, TSCTC);
  5003. temp = E1000_READ_REG(hw, TSCTFC);
  5004. if(hw->mac_type <= e1000_82544) return;
  5005. temp = E1000_READ_REG(hw, MGTPRC);
  5006. temp = E1000_READ_REG(hw, MGTPDC);
  5007. temp = E1000_READ_REG(hw, MGTPTC);
  5008. if(hw->mac_type <= e1000_82547_rev_2) return;
  5009. temp = E1000_READ_REG(hw, IAC);
  5010. temp = E1000_READ_REG(hw, ICRXOC);
  5011. temp = E1000_READ_REG(hw, ICRXPTC);
  5012. temp = E1000_READ_REG(hw, ICRXATC);
  5013. temp = E1000_READ_REG(hw, ICTXPTC);
  5014. temp = E1000_READ_REG(hw, ICTXATC);
  5015. temp = E1000_READ_REG(hw, ICTXQEC);
  5016. temp = E1000_READ_REG(hw, ICTXQMTC);
  5017. temp = E1000_READ_REG(hw, ICRXDMTC);
  5018. }
  5019. /******************************************************************************
  5020. * Resets Adaptive IFS to its default state.
  5021. *
  5022. * hw - Struct containing variables accessed by shared code
  5023. *
  5024. * Call this after e1000_init_hw. You may override the IFS defaults by setting
  5025. * hw->ifs_params_forced to TRUE. However, you must initialize hw->
  5026. * current_ifs_val, ifs_min_val, ifs_max_val, ifs_step_size, and ifs_ratio
  5027. * before calling this function.
  5028. *****************************************************************************/
  5029. void
  5030. e1000_reset_adaptive(struct e1000_hw *hw)
  5031. {
  5032. DEBUGFUNC("e1000_reset_adaptive");
  5033. if(hw->adaptive_ifs) {
  5034. if(!hw->ifs_params_forced) {
  5035. hw->current_ifs_val = 0;
  5036. hw->ifs_min_val = IFS_MIN;
  5037. hw->ifs_max_val = IFS_MAX;
  5038. hw->ifs_step_size = IFS_STEP;
  5039. hw->ifs_ratio = IFS_RATIO;
  5040. }
  5041. hw->in_ifs_mode = FALSE;
  5042. E1000_WRITE_REG(hw, AIT, 0);
  5043. } else {
  5044. DEBUGOUT("Not in Adaptive IFS mode!\n");
  5045. }
  5046. }
  5047. /******************************************************************************
  5048. * Called during the callback/watchdog routine to update IFS value based on
  5049. * the ratio of transmits to collisions.
  5050. *
  5051. * hw - Struct containing variables accessed by shared code
  5052. * tx_packets - Number of transmits since last callback
  5053. * total_collisions - Number of collisions since last callback
  5054. *****************************************************************************/
  5055. void
  5056. e1000_update_adaptive(struct e1000_hw *hw)
  5057. {
  5058. DEBUGFUNC("e1000_update_adaptive");
  5059. if(hw->adaptive_ifs) {
  5060. if((hw->collision_delta * hw->ifs_ratio) > hw->tx_packet_delta) {
  5061. if(hw->tx_packet_delta > MIN_NUM_XMITS) {
  5062. hw->in_ifs_mode = TRUE;
  5063. if(hw->current_ifs_val < hw->ifs_max_val) {
  5064. if(hw->current_ifs_val == 0)
  5065. hw->current_ifs_val = hw->ifs_min_val;
  5066. else
  5067. hw->current_ifs_val += hw->ifs_step_size;
  5068. E1000_WRITE_REG(hw, AIT, hw->current_ifs_val);
  5069. }
  5070. }
  5071. } else {
  5072. if(hw->in_ifs_mode && (hw->tx_packet_delta <= MIN_NUM_XMITS)) {
  5073. hw->current_ifs_val = 0;
  5074. hw->in_ifs_mode = FALSE;
  5075. E1000_WRITE_REG(hw, AIT, 0);
  5076. }
  5077. }
  5078. } else {
  5079. DEBUGOUT("Not in Adaptive IFS mode!\n");
  5080. }
  5081. }
  5082. /******************************************************************************
  5083. * Adjusts the statistic counters when a frame is accepted by TBI_ACCEPT
  5084. *
  5085. * hw - Struct containing variables accessed by shared code
  5086. * frame_len - The length of the frame in question
  5087. * mac_addr - The Ethernet destination address of the frame in question
  5088. *****************************************************************************/
  5089. void
  5090. e1000_tbi_adjust_stats(struct e1000_hw *hw,
  5091. struct e1000_hw_stats *stats,
  5092. uint32_t frame_len,
  5093. uint8_t *mac_addr)
  5094. {
  5095. uint64_t carry_bit;
  5096. /* First adjust the frame length. */
  5097. frame_len--;
  5098. /* We need to adjust the statistics counters, since the hardware
  5099. * counters overcount this packet as a CRC error and undercount
  5100. * the packet as a good packet
  5101. */
  5102. /* This packet should not be counted as a CRC error. */
  5103. stats->crcerrs--;
  5104. /* This packet does count as a Good Packet Received. */
  5105. stats->gprc++;
  5106. /* Adjust the Good Octets received counters */
  5107. carry_bit = 0x80000000 & stats->gorcl;
  5108. stats->gorcl += frame_len;
  5109. /* If the high bit of Gorcl (the low 32 bits of the Good Octets
  5110. * Received Count) was one before the addition,
  5111. * AND it is zero after, then we lost the carry out,
  5112. * need to add one to Gorch (Good Octets Received Count High).
  5113. * This could be simplified if all environments supported
  5114. * 64-bit integers.
  5115. */
  5116. if(carry_bit && ((stats->gorcl & 0x80000000) == 0))
  5117. stats->gorch++;
  5118. /* Is this a broadcast or multicast? Check broadcast first,
  5119. * since the test for a multicast frame will test positive on
  5120. * a broadcast frame.
  5121. */
  5122. if((mac_addr[0] == (uint8_t) 0xff) && (mac_addr[1] == (uint8_t) 0xff))
  5123. /* Broadcast packet */
  5124. stats->bprc++;
  5125. else if(*mac_addr & 0x01)
  5126. /* Multicast packet */
  5127. stats->mprc++;
  5128. if(frame_len == hw->max_frame_size) {
  5129. /* In this case, the hardware has overcounted the number of
  5130. * oversize frames.
  5131. */
  5132. if(stats->roc > 0)
  5133. stats->roc--;
  5134. }
  5135. /* Adjust the bin counters when the extra byte put the frame in the
  5136. * wrong bin. Remember that the frame_len was adjusted above.
  5137. */
  5138. if(frame_len == 64) {
  5139. stats->prc64++;
  5140. stats->prc127--;
  5141. } else if(frame_len == 127) {
  5142. stats->prc127++;
  5143. stats->prc255--;
  5144. } else if(frame_len == 255) {
  5145. stats->prc255++;
  5146. stats->prc511--;
  5147. } else if(frame_len == 511) {
  5148. stats->prc511++;
  5149. stats->prc1023--;
  5150. } else if(frame_len == 1023) {
  5151. stats->prc1023++;
  5152. stats->prc1522--;
  5153. } else if(frame_len == 1522) {
  5154. stats->prc1522++;
  5155. }
  5156. }
  5157. /******************************************************************************
  5158. * Gets the current PCI bus type, speed, and width of the hardware
  5159. *
  5160. * hw - Struct containing variables accessed by shared code
  5161. *****************************************************************************/
  5162. void
  5163. e1000_get_bus_info(struct e1000_hw *hw)
  5164. {
  5165. uint32_t status;
  5166. switch (hw->mac_type) {
  5167. case e1000_82542_rev2_0:
  5168. case e1000_82542_rev2_1:
  5169. hw->bus_type = e1000_bus_type_unknown;
  5170. hw->bus_speed = e1000_bus_speed_unknown;
  5171. hw->bus_width = e1000_bus_width_unknown;
  5172. break;
  5173. case e1000_82572:
  5174. case e1000_82573:
  5175. hw->bus_type = e1000_bus_type_pci_express;
  5176. hw->bus_speed = e1000_bus_speed_2500;
  5177. hw->bus_width = e1000_bus_width_pciex_1;
  5178. break;
  5179. case e1000_82571:
  5180. case e1000_80003es2lan:
  5181. hw->bus_type = e1000_bus_type_pci_express;
  5182. hw->bus_speed = e1000_bus_speed_2500;
  5183. hw->bus_width = e1000_bus_width_pciex_4;
  5184. break;
  5185. default:
  5186. status = E1000_READ_REG(hw, STATUS);
  5187. hw->bus_type = (status & E1000_STATUS_PCIX_MODE) ?
  5188. e1000_bus_type_pcix : e1000_bus_type_pci;
  5189. if(hw->device_id == E1000_DEV_ID_82546EB_QUAD_COPPER) {
  5190. hw->bus_speed = (hw->bus_type == e1000_bus_type_pci) ?
  5191. e1000_bus_speed_66 : e1000_bus_speed_120;
  5192. } else if(hw->bus_type == e1000_bus_type_pci) {
  5193. hw->bus_speed = (status & E1000_STATUS_PCI66) ?
  5194. e1000_bus_speed_66 : e1000_bus_speed_33;
  5195. } else {
  5196. switch (status & E1000_STATUS_PCIX_SPEED) {
  5197. case E1000_STATUS_PCIX_SPEED_66:
  5198. hw->bus_speed = e1000_bus_speed_66;
  5199. break;
  5200. case E1000_STATUS_PCIX_SPEED_100:
  5201. hw->bus_speed = e1000_bus_speed_100;
  5202. break;
  5203. case E1000_STATUS_PCIX_SPEED_133:
  5204. hw->bus_speed = e1000_bus_speed_133;
  5205. break;
  5206. default:
  5207. hw->bus_speed = e1000_bus_speed_reserved;
  5208. break;
  5209. }
  5210. }
  5211. hw->bus_width = (status & E1000_STATUS_BUS64) ?
  5212. e1000_bus_width_64 : e1000_bus_width_32;
  5213. break;
  5214. }
  5215. }
  5216. #if 0
  5217. /******************************************************************************
  5218. * Reads a value from one of the devices registers using port I/O (as opposed
  5219. * memory mapped I/O). Only 82544 and newer devices support port I/O.
  5220. *
  5221. * hw - Struct containing variables accessed by shared code
  5222. * offset - offset to read from
  5223. *****************************************************************************/
  5224. uint32_t
  5225. e1000_read_reg_io(struct e1000_hw *hw,
  5226. uint32_t offset)
  5227. {
  5228. unsigned long io_addr = hw->io_base;
  5229. unsigned long io_data = hw->io_base + 4;
  5230. e1000_io_write(hw, io_addr, offset);
  5231. return e1000_io_read(hw, io_data);
  5232. }
  5233. #endif /* 0 */
  5234. /******************************************************************************
  5235. * Writes a value to one of the devices registers using port I/O (as opposed to
  5236. * memory mapped I/O). Only 82544 and newer devices support port I/O.
  5237. *
  5238. * hw - Struct containing variables accessed by shared code
  5239. * offset - offset to write to
  5240. * value - value to write
  5241. *****************************************************************************/
  5242. static void
  5243. e1000_write_reg_io(struct e1000_hw *hw,
  5244. uint32_t offset,
  5245. uint32_t value)
  5246. {
  5247. unsigned long io_addr = hw->io_base;
  5248. unsigned long io_data = hw->io_base + 4;
  5249. e1000_io_write(hw, io_addr, offset);
  5250. e1000_io_write(hw, io_data, value);
  5251. }
  5252. /******************************************************************************
  5253. * Estimates the cable length.
  5254. *
  5255. * hw - Struct containing variables accessed by shared code
  5256. * min_length - The estimated minimum length
  5257. * max_length - The estimated maximum length
  5258. *
  5259. * returns: - E1000_ERR_XXX
  5260. * E1000_SUCCESS
  5261. *
  5262. * This function always returns a ranged length (minimum & maximum).
  5263. * So for M88 phy's, this function interprets the one value returned from the
  5264. * register to the minimum and maximum range.
  5265. * For IGP phy's, the function calculates the range by the AGC registers.
  5266. *****************************************************************************/
  5267. static int32_t
  5268. e1000_get_cable_length(struct e1000_hw *hw,
  5269. uint16_t *min_length,
  5270. uint16_t *max_length)
  5271. {
  5272. int32_t ret_val;
  5273. uint16_t agc_value = 0;
  5274. uint16_t cur_agc, min_agc = IGP01E1000_AGC_LENGTH_TABLE_SIZE;
  5275. uint16_t max_agc = 0;
  5276. uint16_t i, phy_data;
  5277. uint16_t cable_length;
  5278. DEBUGFUNC("e1000_get_cable_length");
  5279. *min_length = *max_length = 0;
  5280. /* Use old method for Phy older than IGP */
  5281. if(hw->phy_type == e1000_phy_m88) {
  5282. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  5283. &phy_data);
  5284. if(ret_val)
  5285. return ret_val;
  5286. cable_length = (phy_data & M88E1000_PSSR_CABLE_LENGTH) >>
  5287. M88E1000_PSSR_CABLE_LENGTH_SHIFT;
  5288. /* Convert the enum value to ranged values */
  5289. switch (cable_length) {
  5290. case e1000_cable_length_50:
  5291. *min_length = 0;
  5292. *max_length = e1000_igp_cable_length_50;
  5293. break;
  5294. case e1000_cable_length_50_80:
  5295. *min_length = e1000_igp_cable_length_50;
  5296. *max_length = e1000_igp_cable_length_80;
  5297. break;
  5298. case e1000_cable_length_80_110:
  5299. *min_length = e1000_igp_cable_length_80;
  5300. *max_length = e1000_igp_cable_length_110;
  5301. break;
  5302. case e1000_cable_length_110_140:
  5303. *min_length = e1000_igp_cable_length_110;
  5304. *max_length = e1000_igp_cable_length_140;
  5305. break;
  5306. case e1000_cable_length_140:
  5307. *min_length = e1000_igp_cable_length_140;
  5308. *max_length = e1000_igp_cable_length_170;
  5309. break;
  5310. default:
  5311. return -E1000_ERR_PHY;
  5312. break;
  5313. }
  5314. } else if (hw->phy_type == e1000_phy_gg82563) {
  5315. ret_val = e1000_read_phy_reg(hw, GG82563_PHY_DSP_DISTANCE,
  5316. &phy_data);
  5317. if (ret_val)
  5318. return ret_val;
  5319. cable_length = phy_data & GG82563_DSPD_CABLE_LENGTH;
  5320. switch (cable_length) {
  5321. case e1000_gg_cable_length_60:
  5322. *min_length = 0;
  5323. *max_length = e1000_igp_cable_length_60;
  5324. break;
  5325. case e1000_gg_cable_length_60_115:
  5326. *min_length = e1000_igp_cable_length_60;
  5327. *max_length = e1000_igp_cable_length_115;
  5328. break;
  5329. case e1000_gg_cable_length_115_150:
  5330. *min_length = e1000_igp_cable_length_115;
  5331. *max_length = e1000_igp_cable_length_150;
  5332. break;
  5333. case e1000_gg_cable_length_150:
  5334. *min_length = e1000_igp_cable_length_150;
  5335. *max_length = e1000_igp_cable_length_180;
  5336. break;
  5337. default:
  5338. return -E1000_ERR_PHY;
  5339. break;
  5340. }
  5341. } else if(hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
  5342. uint16_t agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
  5343. {IGP01E1000_PHY_AGC_A,
  5344. IGP01E1000_PHY_AGC_B,
  5345. IGP01E1000_PHY_AGC_C,
  5346. IGP01E1000_PHY_AGC_D};
  5347. /* Read the AGC registers for all channels */
  5348. for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
  5349. ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
  5350. if(ret_val)
  5351. return ret_val;
  5352. cur_agc = phy_data >> IGP01E1000_AGC_LENGTH_SHIFT;
  5353. /* Array bound check. */
  5354. if((cur_agc >= IGP01E1000_AGC_LENGTH_TABLE_SIZE - 1) ||
  5355. (cur_agc == 0))
  5356. return -E1000_ERR_PHY;
  5357. agc_value += cur_agc;
  5358. /* Update minimal AGC value. */
  5359. if(min_agc > cur_agc)
  5360. min_agc = cur_agc;
  5361. }
  5362. /* Remove the minimal AGC result for length < 50m */
  5363. if(agc_value < IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
  5364. agc_value -= min_agc;
  5365. /* Get the average length of the remaining 3 channels */
  5366. agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
  5367. } else {
  5368. /* Get the average length of all the 4 channels. */
  5369. agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
  5370. }
  5371. /* Set the range of the calculated length. */
  5372. *min_length = ((e1000_igp_cable_length_table[agc_value] -
  5373. IGP01E1000_AGC_RANGE) > 0) ?
  5374. (e1000_igp_cable_length_table[agc_value] -
  5375. IGP01E1000_AGC_RANGE) : 0;
  5376. *max_length = e1000_igp_cable_length_table[agc_value] +
  5377. IGP01E1000_AGC_RANGE;
  5378. } else if (hw->phy_type == e1000_phy_igp_2) {
  5379. uint16_t agc_reg_array[IGP02E1000_PHY_CHANNEL_NUM] =
  5380. {IGP02E1000_PHY_AGC_A,
  5381. IGP02E1000_PHY_AGC_B,
  5382. IGP02E1000_PHY_AGC_C,
  5383. IGP02E1000_PHY_AGC_D};
  5384. /* Read the AGC registers for all channels */
  5385. for (i = 0; i < IGP02E1000_PHY_CHANNEL_NUM; i++) {
  5386. ret_val = e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data);
  5387. if (ret_val)
  5388. return ret_val;
  5389. /* Getting bits 15:9, which represent the combination of course and
  5390. * fine gain values. The result is a number that can be put into
  5391. * the lookup table to obtain the approximate cable length. */
  5392. cur_agc = (phy_data >> IGP02E1000_AGC_LENGTH_SHIFT) &
  5393. IGP02E1000_AGC_LENGTH_MASK;
  5394. /* Remove min & max AGC values from calculation. */
  5395. if (e1000_igp_2_cable_length_table[min_agc] > e1000_igp_2_cable_length_table[cur_agc])
  5396. min_agc = cur_agc;
  5397. if (e1000_igp_2_cable_length_table[max_agc] < e1000_igp_2_cable_length_table[cur_agc])
  5398. max_agc = cur_agc;
  5399. agc_value += e1000_igp_2_cable_length_table[cur_agc];
  5400. }
  5401. agc_value -= (e1000_igp_2_cable_length_table[min_agc] + e1000_igp_2_cable_length_table[max_agc]);
  5402. agc_value /= (IGP02E1000_PHY_CHANNEL_NUM - 2);
  5403. /* Calculate cable length with the error range of +/- 10 meters. */
  5404. *min_length = ((agc_value - IGP02E1000_AGC_RANGE) > 0) ?
  5405. (agc_value - IGP02E1000_AGC_RANGE) : 0;
  5406. *max_length = agc_value + IGP02E1000_AGC_RANGE;
  5407. }
  5408. return E1000_SUCCESS;
  5409. }
  5410. /******************************************************************************
  5411. * Check the cable polarity
  5412. *
  5413. * hw - Struct containing variables accessed by shared code
  5414. * polarity - output parameter : 0 - Polarity is not reversed
  5415. * 1 - Polarity is reversed.
  5416. *
  5417. * returns: - E1000_ERR_XXX
  5418. * E1000_SUCCESS
  5419. *
  5420. * For phy's older then IGP, this function simply reads the polarity bit in the
  5421. * Phy Status register. For IGP phy's, this bit is valid only if link speed is
  5422. * 10 Mbps. If the link speed is 100 Mbps there is no polarity so this bit will
  5423. * return 0. If the link speed is 1000 Mbps the polarity status is in the
  5424. * IGP01E1000_PHY_PCS_INIT_REG.
  5425. *****************************************************************************/
  5426. static int32_t
  5427. e1000_check_polarity(struct e1000_hw *hw,
  5428. uint16_t *polarity)
  5429. {
  5430. int32_t ret_val;
  5431. uint16_t phy_data;
  5432. DEBUGFUNC("e1000_check_polarity");
  5433. if ((hw->phy_type == e1000_phy_m88) ||
  5434. (hw->phy_type == e1000_phy_gg82563)) {
  5435. /* return the Polarity bit in the Status register. */
  5436. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  5437. &phy_data);
  5438. if(ret_val)
  5439. return ret_val;
  5440. *polarity = (phy_data & M88E1000_PSSR_REV_POLARITY) >>
  5441. M88E1000_PSSR_REV_POLARITY_SHIFT;
  5442. } else if(hw->phy_type == e1000_phy_igp ||
  5443. hw->phy_type == e1000_phy_igp_2) {
  5444. /* Read the Status register to check the speed */
  5445. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
  5446. &phy_data);
  5447. if(ret_val)
  5448. return ret_val;
  5449. /* If speed is 1000 Mbps, must read the IGP01E1000_PHY_PCS_INIT_REG to
  5450. * find the polarity status */
  5451. if((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
  5452. IGP01E1000_PSSR_SPEED_1000MBPS) {
  5453. /* Read the GIG initialization PCS register (0x00B4) */
  5454. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
  5455. &phy_data);
  5456. if(ret_val)
  5457. return ret_val;
  5458. /* Check the polarity bits */
  5459. *polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ? 1 : 0;
  5460. } else {
  5461. /* For 10 Mbps, read the polarity bit in the status register. (for
  5462. * 100 Mbps this bit is always 0) */
  5463. *polarity = phy_data & IGP01E1000_PSSR_POLARITY_REVERSED;
  5464. }
  5465. }
  5466. return E1000_SUCCESS;
  5467. }
  5468. /******************************************************************************
  5469. * Check if Downshift occured
  5470. *
  5471. * hw - Struct containing variables accessed by shared code
  5472. * downshift - output parameter : 0 - No Downshift ocured.
  5473. * 1 - Downshift ocured.
  5474. *
  5475. * returns: - E1000_ERR_XXX
  5476. * E1000_SUCCESS
  5477. *
  5478. * For phy's older then IGP, this function reads the Downshift bit in the Phy
  5479. * Specific Status register. For IGP phy's, it reads the Downgrade bit in the
  5480. * Link Health register. In IGP this bit is latched high, so the driver must
  5481. * read it immediately after link is established.
  5482. *****************************************************************************/
  5483. static int32_t
  5484. e1000_check_downshift(struct e1000_hw *hw)
  5485. {
  5486. int32_t ret_val;
  5487. uint16_t phy_data;
  5488. DEBUGFUNC("e1000_check_downshift");
  5489. if(hw->phy_type == e1000_phy_igp ||
  5490. hw->phy_type == e1000_phy_igp_2) {
  5491. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_LINK_HEALTH,
  5492. &phy_data);
  5493. if(ret_val)
  5494. return ret_val;
  5495. hw->speed_downgraded = (phy_data & IGP01E1000_PLHR_SS_DOWNGRADE) ? 1 : 0;
  5496. } else if ((hw->phy_type == e1000_phy_m88) ||
  5497. (hw->phy_type == e1000_phy_gg82563)) {
  5498. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
  5499. &phy_data);
  5500. if(ret_val)
  5501. return ret_val;
  5502. hw->speed_downgraded = (phy_data & M88E1000_PSSR_DOWNSHIFT) >>
  5503. M88E1000_PSSR_DOWNSHIFT_SHIFT;
  5504. }
  5505. return E1000_SUCCESS;
  5506. }
  5507. /*****************************************************************************
  5508. *
  5509. * 82541_rev_2 & 82547_rev_2 have the capability to configure the DSP when a
  5510. * gigabit link is achieved to improve link quality.
  5511. *
  5512. * hw: Struct containing variables accessed by shared code
  5513. *
  5514. * returns: - E1000_ERR_PHY if fail to read/write the PHY
  5515. * E1000_SUCCESS at any other case.
  5516. *
  5517. ****************************************************************************/
  5518. static int32_t
  5519. e1000_config_dsp_after_link_change(struct e1000_hw *hw,
  5520. boolean_t link_up)
  5521. {
  5522. int32_t ret_val;
  5523. uint16_t phy_data, phy_saved_data, speed, duplex, i;
  5524. uint16_t dsp_reg_array[IGP01E1000_PHY_CHANNEL_NUM] =
  5525. {IGP01E1000_PHY_AGC_PARAM_A,
  5526. IGP01E1000_PHY_AGC_PARAM_B,
  5527. IGP01E1000_PHY_AGC_PARAM_C,
  5528. IGP01E1000_PHY_AGC_PARAM_D};
  5529. uint16_t min_length, max_length;
  5530. DEBUGFUNC("e1000_config_dsp_after_link_change");
  5531. if(hw->phy_type != e1000_phy_igp)
  5532. return E1000_SUCCESS;
  5533. if(link_up) {
  5534. ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex);
  5535. if(ret_val) {
  5536. DEBUGOUT("Error getting link speed and duplex\n");
  5537. return ret_val;
  5538. }
  5539. if(speed == SPEED_1000) {
  5540. e1000_get_cable_length(hw, &min_length, &max_length);
  5541. if((hw->dsp_config_state == e1000_dsp_config_enabled) &&
  5542. min_length >= e1000_igp_cable_length_50) {
  5543. for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
  5544. ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
  5545. &phy_data);
  5546. if(ret_val)
  5547. return ret_val;
  5548. phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
  5549. ret_val = e1000_write_phy_reg(hw, dsp_reg_array[i],
  5550. phy_data);
  5551. if(ret_val)
  5552. return ret_val;
  5553. }
  5554. hw->dsp_config_state = e1000_dsp_config_activated;
  5555. }
  5556. if((hw->ffe_config_state == e1000_ffe_config_enabled) &&
  5557. (min_length < e1000_igp_cable_length_50)) {
  5558. uint16_t ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_20;
  5559. uint32_t idle_errs = 0;
  5560. /* clear previous idle error counts */
  5561. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
  5562. &phy_data);
  5563. if(ret_val)
  5564. return ret_val;
  5565. for(i = 0; i < ffe_idle_err_timeout; i++) {
  5566. udelay(1000);
  5567. ret_val = e1000_read_phy_reg(hw, PHY_1000T_STATUS,
  5568. &phy_data);
  5569. if(ret_val)
  5570. return ret_val;
  5571. idle_errs += (phy_data & SR_1000T_IDLE_ERROR_CNT);
  5572. if(idle_errs > SR_1000T_PHY_EXCESSIVE_IDLE_ERR_COUNT) {
  5573. hw->ffe_config_state = e1000_ffe_config_active;
  5574. ret_val = e1000_write_phy_reg(hw,
  5575. IGP01E1000_PHY_DSP_FFE,
  5576. IGP01E1000_PHY_DSP_FFE_CM_CP);
  5577. if(ret_val)
  5578. return ret_val;
  5579. break;
  5580. }
  5581. if(idle_errs)
  5582. ffe_idle_err_timeout = FFE_IDLE_ERR_COUNT_TIMEOUT_100;
  5583. }
  5584. }
  5585. }
  5586. } else {
  5587. if(hw->dsp_config_state == e1000_dsp_config_activated) {
  5588. /* Save off the current value of register 0x2F5B to be restored at
  5589. * the end of the routines. */
  5590. ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
  5591. if(ret_val)
  5592. return ret_val;
  5593. /* Disable the PHY transmitter */
  5594. ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
  5595. if(ret_val)
  5596. return ret_val;
  5597. msec_delay_irq(20);
  5598. ret_val = e1000_write_phy_reg(hw, 0x0000,
  5599. IGP01E1000_IEEE_FORCE_GIGA);
  5600. if(ret_val)
  5601. return ret_val;
  5602. for(i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
  5603. ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i], &phy_data);
  5604. if(ret_val)
  5605. return ret_val;
  5606. phy_data &= ~IGP01E1000_PHY_EDAC_MU_INDEX;
  5607. phy_data |= IGP01E1000_PHY_EDAC_SIGN_EXT_9_BITS;
  5608. ret_val = e1000_write_phy_reg(hw,dsp_reg_array[i], phy_data);
  5609. if(ret_val)
  5610. return ret_val;
  5611. }
  5612. ret_val = e1000_write_phy_reg(hw, 0x0000,
  5613. IGP01E1000_IEEE_RESTART_AUTONEG);
  5614. if(ret_val)
  5615. return ret_val;
  5616. msec_delay_irq(20);
  5617. /* Now enable the transmitter */
  5618. ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
  5619. if(ret_val)
  5620. return ret_val;
  5621. hw->dsp_config_state = e1000_dsp_config_enabled;
  5622. }
  5623. if(hw->ffe_config_state == e1000_ffe_config_active) {
  5624. /* Save off the current value of register 0x2F5B to be restored at
  5625. * the end of the routines. */
  5626. ret_val = e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
  5627. if(ret_val)
  5628. return ret_val;
  5629. /* Disable the PHY transmitter */
  5630. ret_val = e1000_write_phy_reg(hw, 0x2F5B, 0x0003);
  5631. if(ret_val)
  5632. return ret_val;
  5633. msec_delay_irq(20);
  5634. ret_val = e1000_write_phy_reg(hw, 0x0000,
  5635. IGP01E1000_IEEE_FORCE_GIGA);
  5636. if(ret_val)
  5637. return ret_val;
  5638. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_DSP_FFE,
  5639. IGP01E1000_PHY_DSP_FFE_DEFAULT);
  5640. if(ret_val)
  5641. return ret_val;
  5642. ret_val = e1000_write_phy_reg(hw, 0x0000,
  5643. IGP01E1000_IEEE_RESTART_AUTONEG);
  5644. if(ret_val)
  5645. return ret_val;
  5646. msec_delay_irq(20);
  5647. /* Now enable the transmitter */
  5648. ret_val = e1000_write_phy_reg(hw, 0x2F5B, phy_saved_data);
  5649. if(ret_val)
  5650. return ret_val;
  5651. hw->ffe_config_state = e1000_ffe_config_enabled;
  5652. }
  5653. }
  5654. return E1000_SUCCESS;
  5655. }
  5656. /*****************************************************************************
  5657. * Set PHY to class A mode
  5658. * Assumes the following operations will follow to enable the new class mode.
  5659. * 1. Do a PHY soft reset
  5660. * 2. Restart auto-negotiation or force link.
  5661. *
  5662. * hw - Struct containing variables accessed by shared code
  5663. ****************************************************************************/
  5664. static int32_t
  5665. e1000_set_phy_mode(struct e1000_hw *hw)
  5666. {
  5667. int32_t ret_val;
  5668. uint16_t eeprom_data;
  5669. DEBUGFUNC("e1000_set_phy_mode");
  5670. if((hw->mac_type == e1000_82545_rev_3) &&
  5671. (hw->media_type == e1000_media_type_copper)) {
  5672. ret_val = e1000_read_eeprom(hw, EEPROM_PHY_CLASS_WORD, 1, &eeprom_data);
  5673. if(ret_val) {
  5674. return ret_val;
  5675. }
  5676. if((eeprom_data != EEPROM_RESERVED_WORD) &&
  5677. (eeprom_data & EEPROM_PHY_CLASS_A)) {
  5678. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x000B);
  5679. if(ret_val)
  5680. return ret_val;
  5681. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x8104);
  5682. if(ret_val)
  5683. return ret_val;
  5684. hw->phy_reset_disable = FALSE;
  5685. }
  5686. }
  5687. return E1000_SUCCESS;
  5688. }
  5689. /*****************************************************************************
  5690. *
  5691. * This function sets the lplu state according to the active flag. When
  5692. * activating lplu this function also disables smart speed and vise versa.
  5693. * lplu will not be activated unless the device autonegotiation advertisment
  5694. * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
  5695. * hw: Struct containing variables accessed by shared code
  5696. * active - true to enable lplu false to disable lplu.
  5697. *
  5698. * returns: - E1000_ERR_PHY if fail to read/write the PHY
  5699. * E1000_SUCCESS at any other case.
  5700. *
  5701. ****************************************************************************/
  5702. static int32_t
  5703. e1000_set_d3_lplu_state(struct e1000_hw *hw,
  5704. boolean_t active)
  5705. {
  5706. int32_t ret_val;
  5707. uint16_t phy_data;
  5708. DEBUGFUNC("e1000_set_d3_lplu_state");
  5709. if(hw->phy_type != e1000_phy_igp && hw->phy_type != e1000_phy_igp_2)
  5710. return E1000_SUCCESS;
  5711. /* During driver activity LPLU should not be used or it will attain link
  5712. * from the lowest speeds starting from 10Mbps. The capability is used for
  5713. * Dx transitions and states */
  5714. if(hw->mac_type == e1000_82541_rev_2 || hw->mac_type == e1000_82547_rev_2) {
  5715. ret_val = e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data);
  5716. if(ret_val)
  5717. return ret_val;
  5718. } else {
  5719. ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
  5720. if(ret_val)
  5721. return ret_val;
  5722. }
  5723. if(!active) {
  5724. if(hw->mac_type == e1000_82541_rev_2 ||
  5725. hw->mac_type == e1000_82547_rev_2) {
  5726. phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
  5727. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
  5728. if(ret_val)
  5729. return ret_val;
  5730. } else {
  5731. phy_data &= ~IGP02E1000_PM_D3_LPLU;
  5732. ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  5733. phy_data);
  5734. if (ret_val)
  5735. return ret_val;
  5736. }
  5737. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
  5738. * Dx states where the power conservation is most important. During
  5739. * driver activity we should enable SmartSpeed, so performance is
  5740. * maintained. */
  5741. if (hw->smart_speed == e1000_smart_speed_on) {
  5742. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5743. &phy_data);
  5744. if(ret_val)
  5745. return ret_val;
  5746. phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
  5747. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5748. phy_data);
  5749. if(ret_val)
  5750. return ret_val;
  5751. } else if (hw->smart_speed == e1000_smart_speed_off) {
  5752. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5753. &phy_data);
  5754. if (ret_val)
  5755. return ret_val;
  5756. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  5757. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5758. phy_data);
  5759. if(ret_val)
  5760. return ret_val;
  5761. }
  5762. } else if((hw->autoneg_advertised == AUTONEG_ADVERTISE_SPEED_DEFAULT) ||
  5763. (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_ALL ) ||
  5764. (hw->autoneg_advertised == AUTONEG_ADVERTISE_10_100_ALL)) {
  5765. if(hw->mac_type == e1000_82541_rev_2 ||
  5766. hw->mac_type == e1000_82547_rev_2) {
  5767. phy_data |= IGP01E1000_GMII_FLEX_SPD;
  5768. ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO, phy_data);
  5769. if(ret_val)
  5770. return ret_val;
  5771. } else {
  5772. phy_data |= IGP02E1000_PM_D3_LPLU;
  5773. ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT,
  5774. phy_data);
  5775. if (ret_val)
  5776. return ret_val;
  5777. }
  5778. /* When LPLU is enabled we should disable SmartSpeed */
  5779. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  5780. if(ret_val)
  5781. return ret_val;
  5782. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  5783. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
  5784. if(ret_val)
  5785. return ret_val;
  5786. }
  5787. return E1000_SUCCESS;
  5788. }
  5789. /*****************************************************************************
  5790. *
  5791. * This function sets the lplu d0 state according to the active flag. When
  5792. * activating lplu this function also disables smart speed and vise versa.
  5793. * lplu will not be activated unless the device autonegotiation advertisment
  5794. * meets standards of either 10 or 10/100 or 10/100/1000 at all duplexes.
  5795. * hw: Struct containing variables accessed by shared code
  5796. * active - true to enable lplu false to disable lplu.
  5797. *
  5798. * returns: - E1000_ERR_PHY if fail to read/write the PHY
  5799. * E1000_SUCCESS at any other case.
  5800. *
  5801. ****************************************************************************/
  5802. static int32_t
  5803. e1000_set_d0_lplu_state(struct e1000_hw *hw,
  5804. boolean_t active)
  5805. {
  5806. int32_t ret_val;
  5807. uint16_t phy_data;
  5808. DEBUGFUNC("e1000_set_d0_lplu_state");
  5809. if(hw->mac_type <= e1000_82547_rev_2)
  5810. return E1000_SUCCESS;
  5811. ret_val = e1000_read_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, &phy_data);
  5812. if(ret_val)
  5813. return ret_val;
  5814. if (!active) {
  5815. phy_data &= ~IGP02E1000_PM_D0_LPLU;
  5816. ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
  5817. if (ret_val)
  5818. return ret_val;
  5819. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used during
  5820. * Dx states where the power conservation is most important. During
  5821. * driver activity we should enable SmartSpeed, so performance is
  5822. * maintained. */
  5823. if (hw->smart_speed == e1000_smart_speed_on) {
  5824. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5825. &phy_data);
  5826. if(ret_val)
  5827. return ret_val;
  5828. phy_data |= IGP01E1000_PSCFR_SMART_SPEED;
  5829. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5830. phy_data);
  5831. if(ret_val)
  5832. return ret_val;
  5833. } else if (hw->smart_speed == e1000_smart_speed_off) {
  5834. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5835. &phy_data);
  5836. if (ret_val)
  5837. return ret_val;
  5838. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  5839. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
  5840. phy_data);
  5841. if(ret_val)
  5842. return ret_val;
  5843. }
  5844. } else {
  5845. phy_data |= IGP02E1000_PM_D0_LPLU;
  5846. ret_val = e1000_write_phy_reg(hw, IGP02E1000_PHY_POWER_MGMT, phy_data);
  5847. if (ret_val)
  5848. return ret_val;
  5849. /* When LPLU is enabled we should disable SmartSpeed */
  5850. ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, &phy_data);
  5851. if(ret_val)
  5852. return ret_val;
  5853. phy_data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  5854. ret_val = e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG, phy_data);
  5855. if(ret_val)
  5856. return ret_val;
  5857. }
  5858. return E1000_SUCCESS;
  5859. }
  5860. /******************************************************************************
  5861. * Change VCO speed register to improve Bit Error Rate performance of SERDES.
  5862. *
  5863. * hw - Struct containing variables accessed by shared code
  5864. *****************************************************************************/
  5865. static int32_t
  5866. e1000_set_vco_speed(struct e1000_hw *hw)
  5867. {
  5868. int32_t ret_val;
  5869. uint16_t default_page = 0;
  5870. uint16_t phy_data;
  5871. DEBUGFUNC("e1000_set_vco_speed");
  5872. switch(hw->mac_type) {
  5873. case e1000_82545_rev_3:
  5874. case e1000_82546_rev_3:
  5875. break;
  5876. default:
  5877. return E1000_SUCCESS;
  5878. }
  5879. /* Set PHY register 30, page 5, bit 8 to 0 */
  5880. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, &default_page);
  5881. if(ret_val)
  5882. return ret_val;
  5883. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0005);
  5884. if(ret_val)
  5885. return ret_val;
  5886. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
  5887. if(ret_val)
  5888. return ret_val;
  5889. phy_data &= ~M88E1000_PHY_VCO_REG_BIT8;
  5890. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
  5891. if(ret_val)
  5892. return ret_val;
  5893. /* Set PHY register 30, page 4, bit 11 to 1 */
  5894. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0004);
  5895. if(ret_val)
  5896. return ret_val;
  5897. ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, &phy_data);
  5898. if(ret_val)
  5899. return ret_val;
  5900. phy_data |= M88E1000_PHY_VCO_REG_BIT11;
  5901. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, phy_data);
  5902. if(ret_val)
  5903. return ret_val;
  5904. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, default_page);
  5905. if(ret_val)
  5906. return ret_val;
  5907. return E1000_SUCCESS;
  5908. }
  5909. /*****************************************************************************
  5910. * This function reads the cookie from ARC ram.
  5911. *
  5912. * returns: - E1000_SUCCESS .
  5913. ****************************************************************************/
  5914. int32_t
  5915. e1000_host_if_read_cookie(struct e1000_hw * hw, uint8_t *buffer)
  5916. {
  5917. uint8_t i;
  5918. uint32_t offset = E1000_MNG_DHCP_COOKIE_OFFSET;
  5919. uint8_t length = E1000_MNG_DHCP_COOKIE_LENGTH;
  5920. length = (length >> 2);
  5921. offset = (offset >> 2);
  5922. for (i = 0; i < length; i++) {
  5923. *((uint32_t *) buffer + i) =
  5924. E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset + i);
  5925. }
  5926. return E1000_SUCCESS;
  5927. }
  5928. /*****************************************************************************
  5929. * This function checks whether the HOST IF is enabled for command operaton
  5930. * and also checks whether the previous command is completed.
  5931. * It busy waits in case of previous command is not completed.
  5932. *
  5933. * returns: - E1000_ERR_HOST_INTERFACE_COMMAND in case if is not ready or
  5934. * timeout
  5935. * - E1000_SUCCESS for success.
  5936. ****************************************************************************/
  5937. static int32_t
  5938. e1000_mng_enable_host_if(struct e1000_hw * hw)
  5939. {
  5940. uint32_t hicr;
  5941. uint8_t i;
  5942. /* Check that the host interface is enabled. */
  5943. hicr = E1000_READ_REG(hw, HICR);
  5944. if ((hicr & E1000_HICR_EN) == 0) {
  5945. DEBUGOUT("E1000_HOST_EN bit disabled.\n");
  5946. return -E1000_ERR_HOST_INTERFACE_COMMAND;
  5947. }
  5948. /* check the previous command is completed */
  5949. for (i = 0; i < E1000_MNG_DHCP_COMMAND_TIMEOUT; i++) {
  5950. hicr = E1000_READ_REG(hw, HICR);
  5951. if (!(hicr & E1000_HICR_C))
  5952. break;
  5953. msec_delay_irq(1);
  5954. }
  5955. if (i == E1000_MNG_DHCP_COMMAND_TIMEOUT) {
  5956. DEBUGOUT("Previous command timeout failed .\n");
  5957. return -E1000_ERR_HOST_INTERFACE_COMMAND;
  5958. }
  5959. return E1000_SUCCESS;
  5960. }
  5961. /*****************************************************************************
  5962. * This function writes the buffer content at the offset given on the host if.
  5963. * It also does alignment considerations to do the writes in most efficient way.
  5964. * Also fills up the sum of the buffer in *buffer parameter.
  5965. *
  5966. * returns - E1000_SUCCESS for success.
  5967. ****************************************************************************/
  5968. static int32_t
  5969. e1000_mng_host_if_write(struct e1000_hw * hw, uint8_t *buffer,
  5970. uint16_t length, uint16_t offset, uint8_t *sum)
  5971. {
  5972. uint8_t *tmp;
  5973. uint8_t *bufptr = buffer;
  5974. uint32_t data;
  5975. uint16_t remaining, i, j, prev_bytes;
  5976. /* sum = only sum of the data and it is not checksum */
  5977. if (length == 0 || offset + length > E1000_HI_MAX_MNG_DATA_LENGTH) {
  5978. return -E1000_ERR_PARAM;
  5979. }
  5980. tmp = (uint8_t *)&data;
  5981. prev_bytes = offset & 0x3;
  5982. offset &= 0xFFFC;
  5983. offset >>= 2;
  5984. if (prev_bytes) {
  5985. data = E1000_READ_REG_ARRAY_DWORD(hw, HOST_IF, offset);
  5986. for (j = prev_bytes; j < sizeof(uint32_t); j++) {
  5987. *(tmp + j) = *bufptr++;
  5988. *sum += *(tmp + j);
  5989. }
  5990. E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset, data);
  5991. length -= j - prev_bytes;
  5992. offset++;
  5993. }
  5994. remaining = length & 0x3;
  5995. length -= remaining;
  5996. /* Calculate length in DWORDs */
  5997. length >>= 2;
  5998. /* The device driver writes the relevant command block into the
  5999. * ram area. */
  6000. for (i = 0; i < length; i++) {
  6001. for (j = 0; j < sizeof(uint32_t); j++) {
  6002. *(tmp + j) = *bufptr++;
  6003. *sum += *(tmp + j);
  6004. }
  6005. E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
  6006. }
  6007. if (remaining) {
  6008. for (j = 0; j < sizeof(uint32_t); j++) {
  6009. if (j < remaining)
  6010. *(tmp + j) = *bufptr++;
  6011. else
  6012. *(tmp + j) = 0;
  6013. *sum += *(tmp + j);
  6014. }
  6015. E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, offset + i, data);
  6016. }
  6017. return E1000_SUCCESS;
  6018. }
  6019. /*****************************************************************************
  6020. * This function writes the command header after does the checksum calculation.
  6021. *
  6022. * returns - E1000_SUCCESS for success.
  6023. ****************************************************************************/
  6024. static int32_t
  6025. e1000_mng_write_cmd_header(struct e1000_hw * hw,
  6026. struct e1000_host_mng_command_header * hdr)
  6027. {
  6028. uint16_t i;
  6029. uint8_t sum;
  6030. uint8_t *buffer;
  6031. /* Write the whole command header structure which includes sum of
  6032. * the buffer */
  6033. uint16_t length = sizeof(struct e1000_host_mng_command_header);
  6034. sum = hdr->checksum;
  6035. hdr->checksum = 0;
  6036. buffer = (uint8_t *) hdr;
  6037. i = length;
  6038. while(i--)
  6039. sum += buffer[i];
  6040. hdr->checksum = 0 - sum;
  6041. length >>= 2;
  6042. /* The device driver writes the relevant command block into the ram area. */
  6043. for (i = 0; i < length; i++)
  6044. E1000_WRITE_REG_ARRAY_DWORD(hw, HOST_IF, i, *((uint32_t *) hdr + i));
  6045. return E1000_SUCCESS;
  6046. }
  6047. /*****************************************************************************
  6048. * This function indicates to ARC that a new command is pending which completes
  6049. * one write operation by the driver.
  6050. *
  6051. * returns - E1000_SUCCESS for success.
  6052. ****************************************************************************/
  6053. static int32_t
  6054. e1000_mng_write_commit(
  6055. struct e1000_hw * hw)
  6056. {
  6057. uint32_t hicr;
  6058. hicr = E1000_READ_REG(hw, HICR);
  6059. /* Setting this bit tells the ARC that a new command is pending. */
  6060. E1000_WRITE_REG(hw, HICR, hicr | E1000_HICR_C);
  6061. return E1000_SUCCESS;
  6062. }
  6063. /*****************************************************************************
  6064. * This function checks the mode of the firmware.
  6065. *
  6066. * returns - TRUE when the mode is IAMT or FALSE.
  6067. ****************************************************************************/
  6068. boolean_t
  6069. e1000_check_mng_mode(
  6070. struct e1000_hw *hw)
  6071. {
  6072. uint32_t fwsm;
  6073. fwsm = E1000_READ_REG(hw, FWSM);
  6074. if((fwsm & E1000_FWSM_MODE_MASK) ==
  6075. (E1000_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT))
  6076. return TRUE;
  6077. return FALSE;
  6078. }
  6079. /*****************************************************************************
  6080. * This function writes the dhcp info .
  6081. ****************************************************************************/
  6082. int32_t
  6083. e1000_mng_write_dhcp_info(struct e1000_hw * hw, uint8_t *buffer,
  6084. uint16_t length)
  6085. {
  6086. int32_t ret_val;
  6087. struct e1000_host_mng_command_header hdr;
  6088. hdr.command_id = E1000_MNG_DHCP_TX_PAYLOAD_CMD;
  6089. hdr.command_length = length;
  6090. hdr.reserved1 = 0;
  6091. hdr.reserved2 = 0;
  6092. hdr.checksum = 0;
  6093. ret_val = e1000_mng_enable_host_if(hw);
  6094. if (ret_val == E1000_SUCCESS) {
  6095. ret_val = e1000_mng_host_if_write(hw, buffer, length, sizeof(hdr),
  6096. &(hdr.checksum));
  6097. if (ret_val == E1000_SUCCESS) {
  6098. ret_val = e1000_mng_write_cmd_header(hw, &hdr);
  6099. if (ret_val == E1000_SUCCESS)
  6100. ret_val = e1000_mng_write_commit(hw);
  6101. }
  6102. }
  6103. return ret_val;
  6104. }
  6105. /*****************************************************************************
  6106. * This function calculates the checksum.
  6107. *
  6108. * returns - checksum of buffer contents.
  6109. ****************************************************************************/
  6110. uint8_t
  6111. e1000_calculate_mng_checksum(char *buffer, uint32_t length)
  6112. {
  6113. uint8_t sum = 0;
  6114. uint32_t i;
  6115. if (!buffer)
  6116. return 0;
  6117. for (i=0; i < length; i++)
  6118. sum += buffer[i];
  6119. return (uint8_t) (0 - sum);
  6120. }
  6121. /*****************************************************************************
  6122. * This function checks whether tx pkt filtering needs to be enabled or not.
  6123. *
  6124. * returns - TRUE for packet filtering or FALSE.
  6125. ****************************************************************************/
  6126. boolean_t
  6127. e1000_enable_tx_pkt_filtering(struct e1000_hw *hw)
  6128. {
  6129. /* called in init as well as watchdog timer functions */
  6130. int32_t ret_val, checksum;
  6131. boolean_t tx_filter = FALSE;
  6132. struct e1000_host_mng_dhcp_cookie *hdr = &(hw->mng_cookie);
  6133. uint8_t *buffer = (uint8_t *) &(hw->mng_cookie);
  6134. if (e1000_check_mng_mode(hw)) {
  6135. ret_val = e1000_mng_enable_host_if(hw);
  6136. if (ret_val == E1000_SUCCESS) {
  6137. ret_val = e1000_host_if_read_cookie(hw, buffer);
  6138. if (ret_val == E1000_SUCCESS) {
  6139. checksum = hdr->checksum;
  6140. hdr->checksum = 0;
  6141. if ((hdr->signature == E1000_IAMT_SIGNATURE) &&
  6142. checksum == e1000_calculate_mng_checksum((char *)buffer,
  6143. E1000_MNG_DHCP_COOKIE_LENGTH)) {
  6144. if (hdr->status &
  6145. E1000_MNG_DHCP_COOKIE_STATUS_PARSING_SUPPORT)
  6146. tx_filter = TRUE;
  6147. } else
  6148. tx_filter = TRUE;
  6149. } else
  6150. tx_filter = TRUE;
  6151. }
  6152. }
  6153. hw->tx_pkt_filtering = tx_filter;
  6154. return tx_filter;
  6155. }
  6156. /******************************************************************************
  6157. * Verifies the hardware needs to allow ARPs to be processed by the host
  6158. *
  6159. * hw - Struct containing variables accessed by shared code
  6160. *
  6161. * returns: - TRUE/FALSE
  6162. *
  6163. *****************************************************************************/
  6164. uint32_t
  6165. e1000_enable_mng_pass_thru(struct e1000_hw *hw)
  6166. {
  6167. uint32_t manc;
  6168. uint32_t fwsm, factps;
  6169. if (hw->asf_firmware_present) {
  6170. manc = E1000_READ_REG(hw, MANC);
  6171. if (!(manc & E1000_MANC_RCV_TCO_EN) ||
  6172. !(manc & E1000_MANC_EN_MAC_ADDR_FILTER))
  6173. return FALSE;
  6174. if (e1000_arc_subsystem_valid(hw) == TRUE) {
  6175. fwsm = E1000_READ_REG(hw, FWSM);
  6176. factps = E1000_READ_REG(hw, FACTPS);
  6177. if (((fwsm & E1000_FWSM_MODE_MASK) ==
  6178. (e1000_mng_mode_pt << E1000_FWSM_MODE_SHIFT)) &&
  6179. (factps & E1000_FACTPS_MNGCG))
  6180. return TRUE;
  6181. } else
  6182. if ((manc & E1000_MANC_SMBUS_EN) && !(manc & E1000_MANC_ASF_EN))
  6183. return TRUE;
  6184. }
  6185. return FALSE;
  6186. }
  6187. static int32_t
  6188. e1000_polarity_reversal_workaround(struct e1000_hw *hw)
  6189. {
  6190. int32_t ret_val;
  6191. uint16_t mii_status_reg;
  6192. uint16_t i;
  6193. /* Polarity reversal workaround for forced 10F/10H links. */
  6194. /* Disable the transmitter on the PHY */
  6195. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
  6196. if(ret_val)
  6197. return ret_val;
  6198. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF);
  6199. if(ret_val)
  6200. return ret_val;
  6201. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
  6202. if(ret_val)
  6203. return ret_val;
  6204. /* This loop will early-out if the NO link condition has been met. */
  6205. for(i = PHY_FORCE_TIME; i > 0; i--) {
  6206. /* Read the MII Status Register and wait for Link Status bit
  6207. * to be clear.
  6208. */
  6209. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  6210. if(ret_val)
  6211. return ret_val;
  6212. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  6213. if(ret_val)
  6214. return ret_val;
  6215. if((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
  6216. msec_delay_irq(100);
  6217. }
  6218. /* Recommended delay time after link has been lost */
  6219. msec_delay_irq(1000);
  6220. /* Now we will re-enable th transmitter on the PHY */
  6221. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019);
  6222. if(ret_val)
  6223. return ret_val;
  6224. msec_delay_irq(50);
  6225. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0);
  6226. if(ret_val)
  6227. return ret_val;
  6228. msec_delay_irq(50);
  6229. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00);
  6230. if(ret_val)
  6231. return ret_val;
  6232. msec_delay_irq(50);
  6233. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000);
  6234. if(ret_val)
  6235. return ret_val;
  6236. ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000);
  6237. if(ret_val)
  6238. return ret_val;
  6239. /* This loop will early-out if the link condition has been met. */
  6240. for(i = PHY_FORCE_TIME; i > 0; i--) {
  6241. /* Read the MII Status Register and wait for Link Status bit
  6242. * to be set.
  6243. */
  6244. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  6245. if(ret_val)
  6246. return ret_val;
  6247. ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg);
  6248. if(ret_val)
  6249. return ret_val;
  6250. if(mii_status_reg & MII_SR_LINK_STATUS) break;
  6251. msec_delay_irq(100);
  6252. }
  6253. return E1000_SUCCESS;
  6254. }
  6255. /***************************************************************************
  6256. *
  6257. * Disables PCI-Express master access.
  6258. *
  6259. * hw: Struct containing variables accessed by shared code
  6260. *
  6261. * returns: - none.
  6262. *
  6263. ***************************************************************************/
  6264. static void
  6265. e1000_set_pci_express_master_disable(struct e1000_hw *hw)
  6266. {
  6267. uint32_t ctrl;
  6268. DEBUGFUNC("e1000_set_pci_express_master_disable");
  6269. if (hw->bus_type != e1000_bus_type_pci_express)
  6270. return;
  6271. ctrl = E1000_READ_REG(hw, CTRL);
  6272. ctrl |= E1000_CTRL_GIO_MASTER_DISABLE;
  6273. E1000_WRITE_REG(hw, CTRL, ctrl);
  6274. }
  6275. #if 0
  6276. /***************************************************************************
  6277. *
  6278. * Enables PCI-Express master access.
  6279. *
  6280. * hw: Struct containing variables accessed by shared code
  6281. *
  6282. * returns: - none.
  6283. *
  6284. ***************************************************************************/
  6285. void
  6286. e1000_enable_pciex_master(struct e1000_hw *hw)
  6287. {
  6288. uint32_t ctrl;
  6289. DEBUGFUNC("e1000_enable_pciex_master");
  6290. if (hw->bus_type != e1000_bus_type_pci_express)
  6291. return;
  6292. ctrl = E1000_READ_REG(hw, CTRL);
  6293. ctrl &= ~E1000_CTRL_GIO_MASTER_DISABLE;
  6294. E1000_WRITE_REG(hw, CTRL, ctrl);
  6295. }
  6296. #endif /* 0 */
  6297. /*******************************************************************************
  6298. *
  6299. * Disables PCI-Express master access and verifies there are no pending requests
  6300. *
  6301. * hw: Struct containing variables accessed by shared code
  6302. *
  6303. * returns: - E1000_ERR_MASTER_REQUESTS_PENDING if master disable bit hasn't
  6304. * caused the master requests to be disabled.
  6305. * E1000_SUCCESS master requests disabled.
  6306. *
  6307. ******************************************************************************/
  6308. int32_t
  6309. e1000_disable_pciex_master(struct e1000_hw *hw)
  6310. {
  6311. int32_t timeout = MASTER_DISABLE_TIMEOUT; /* 80ms */
  6312. DEBUGFUNC("e1000_disable_pciex_master");
  6313. if (hw->bus_type != e1000_bus_type_pci_express)
  6314. return E1000_SUCCESS;
  6315. e1000_set_pci_express_master_disable(hw);
  6316. while(timeout) {
  6317. if(!(E1000_READ_REG(hw, STATUS) & E1000_STATUS_GIO_MASTER_ENABLE))
  6318. break;
  6319. else
  6320. udelay(100);
  6321. timeout--;
  6322. }
  6323. if(!timeout) {
  6324. DEBUGOUT("Master requests are pending.\n");
  6325. return -E1000_ERR_MASTER_REQUESTS_PENDING;
  6326. }
  6327. return E1000_SUCCESS;
  6328. }
  6329. /*******************************************************************************
  6330. *
  6331. * Check for EEPROM Auto Read bit done.
  6332. *
  6333. * hw: Struct containing variables accessed by shared code
  6334. *
  6335. * returns: - E1000_ERR_RESET if fail to reset MAC
  6336. * E1000_SUCCESS at any other case.
  6337. *
  6338. ******************************************************************************/
  6339. static int32_t
  6340. e1000_get_auto_rd_done(struct e1000_hw *hw)
  6341. {
  6342. int32_t timeout = AUTO_READ_DONE_TIMEOUT;
  6343. DEBUGFUNC("e1000_get_auto_rd_done");
  6344. switch (hw->mac_type) {
  6345. default:
  6346. msec_delay(5);
  6347. break;
  6348. case e1000_82571:
  6349. case e1000_82572:
  6350. case e1000_82573:
  6351. case e1000_80003es2lan:
  6352. while(timeout) {
  6353. if (E1000_READ_REG(hw, EECD) & E1000_EECD_AUTO_RD) break;
  6354. else msec_delay(1);
  6355. timeout--;
  6356. }
  6357. if(!timeout) {
  6358. DEBUGOUT("Auto read by HW from EEPROM has not completed.\n");
  6359. return -E1000_ERR_RESET;
  6360. }
  6361. break;
  6362. }
  6363. /* PHY configuration from NVM just starts after EECD_AUTO_RD sets to high.
  6364. * Need to wait for PHY configuration completion before accessing NVM
  6365. * and PHY. */
  6366. if (hw->mac_type == e1000_82573)
  6367. msec_delay(25);
  6368. return E1000_SUCCESS;
  6369. }
  6370. /***************************************************************************
  6371. * Checks if the PHY configuration is done
  6372. *
  6373. * hw: Struct containing variables accessed by shared code
  6374. *
  6375. * returns: - E1000_ERR_RESET if fail to reset MAC
  6376. * E1000_SUCCESS at any other case.
  6377. *
  6378. ***************************************************************************/
  6379. static int32_t
  6380. e1000_get_phy_cfg_done(struct e1000_hw *hw)
  6381. {
  6382. int32_t timeout = PHY_CFG_TIMEOUT;
  6383. uint32_t cfg_mask = E1000_EEPROM_CFG_DONE;
  6384. DEBUGFUNC("e1000_get_phy_cfg_done");
  6385. switch (hw->mac_type) {
  6386. default:
  6387. msec_delay(10);
  6388. break;
  6389. case e1000_80003es2lan:
  6390. /* Separate *_CFG_DONE_* bit for each port */
  6391. if (E1000_READ_REG(hw, STATUS) & E1000_STATUS_FUNC_1)
  6392. cfg_mask = E1000_EEPROM_CFG_DONE_PORT_1;
  6393. /* Fall Through */
  6394. case e1000_82571:
  6395. case e1000_82572:
  6396. while (timeout) {
  6397. if (E1000_READ_REG(hw, EEMNGCTL) & cfg_mask)
  6398. break;
  6399. else
  6400. msec_delay(1);
  6401. timeout--;
  6402. }
  6403. if (!timeout) {
  6404. DEBUGOUT("MNG configuration cycle has not completed.\n");
  6405. return -E1000_ERR_RESET;
  6406. }
  6407. break;
  6408. }
  6409. return E1000_SUCCESS;
  6410. }
  6411. /***************************************************************************
  6412. *
  6413. * Using the combination of SMBI and SWESMBI semaphore bits when resetting
  6414. * adapter or Eeprom access.
  6415. *
  6416. * hw: Struct containing variables accessed by shared code
  6417. *
  6418. * returns: - E1000_ERR_EEPROM if fail to access EEPROM.
  6419. * E1000_SUCCESS at any other case.
  6420. *
  6421. ***************************************************************************/
  6422. static int32_t
  6423. e1000_get_hw_eeprom_semaphore(struct e1000_hw *hw)
  6424. {
  6425. int32_t timeout;
  6426. uint32_t swsm;
  6427. DEBUGFUNC("e1000_get_hw_eeprom_semaphore");
  6428. if(!hw->eeprom_semaphore_present)
  6429. return E1000_SUCCESS;
  6430. if (hw->mac_type == e1000_80003es2lan) {
  6431. /* Get the SW semaphore. */
  6432. if (e1000_get_software_semaphore(hw) != E1000_SUCCESS)
  6433. return -E1000_ERR_EEPROM;
  6434. }
  6435. /* Get the FW semaphore. */
  6436. timeout = hw->eeprom.word_size + 1;
  6437. while(timeout) {
  6438. swsm = E1000_READ_REG(hw, SWSM);
  6439. swsm |= E1000_SWSM_SWESMBI;
  6440. E1000_WRITE_REG(hw, SWSM, swsm);
  6441. /* if we managed to set the bit we got the semaphore. */
  6442. swsm = E1000_READ_REG(hw, SWSM);
  6443. if(swsm & E1000_SWSM_SWESMBI)
  6444. break;
  6445. udelay(50);
  6446. timeout--;
  6447. }
  6448. if(!timeout) {
  6449. /* Release semaphores */
  6450. e1000_put_hw_eeprom_semaphore(hw);
  6451. DEBUGOUT("Driver can't access the Eeprom - SWESMBI bit is set.\n");
  6452. return -E1000_ERR_EEPROM;
  6453. }
  6454. return E1000_SUCCESS;
  6455. }
  6456. /***************************************************************************
  6457. * This function clears HW semaphore bits.
  6458. *
  6459. * hw: Struct containing variables accessed by shared code
  6460. *
  6461. * returns: - None.
  6462. *
  6463. ***************************************************************************/
  6464. static void
  6465. e1000_put_hw_eeprom_semaphore(struct e1000_hw *hw)
  6466. {
  6467. uint32_t swsm;
  6468. DEBUGFUNC("e1000_put_hw_eeprom_semaphore");
  6469. if(!hw->eeprom_semaphore_present)
  6470. return;
  6471. swsm = E1000_READ_REG(hw, SWSM);
  6472. if (hw->mac_type == e1000_80003es2lan) {
  6473. /* Release both semaphores. */
  6474. swsm &= ~(E1000_SWSM_SMBI | E1000_SWSM_SWESMBI);
  6475. } else
  6476. swsm &= ~(E1000_SWSM_SWESMBI);
  6477. E1000_WRITE_REG(hw, SWSM, swsm);
  6478. }
  6479. /***************************************************************************
  6480. *
  6481. * Obtaining software semaphore bit (SMBI) before resetting PHY.
  6482. *
  6483. * hw: Struct containing variables accessed by shared code
  6484. *
  6485. * returns: - E1000_ERR_RESET if fail to obtain semaphore.
  6486. * E1000_SUCCESS at any other case.
  6487. *
  6488. ***************************************************************************/
  6489. int32_t
  6490. e1000_get_software_semaphore(struct e1000_hw *hw)
  6491. {
  6492. int32_t timeout = hw->eeprom.word_size + 1;
  6493. uint32_t swsm;
  6494. DEBUGFUNC("e1000_get_software_semaphore");
  6495. if (hw->mac_type != e1000_80003es2lan)
  6496. return E1000_SUCCESS;
  6497. while(timeout) {
  6498. swsm = E1000_READ_REG(hw, SWSM);
  6499. /* If SMBI bit cleared, it is now set and we hold the semaphore */
  6500. if(!(swsm & E1000_SWSM_SMBI))
  6501. break;
  6502. msec_delay_irq(1);
  6503. timeout--;
  6504. }
  6505. if(!timeout) {
  6506. DEBUGOUT("Driver can't access device - SMBI bit is set.\n");
  6507. return -E1000_ERR_RESET;
  6508. }
  6509. return E1000_SUCCESS;
  6510. }
  6511. /***************************************************************************
  6512. *
  6513. * Release semaphore bit (SMBI).
  6514. *
  6515. * hw: Struct containing variables accessed by shared code
  6516. *
  6517. ***************************************************************************/
  6518. void
  6519. e1000_release_software_semaphore(struct e1000_hw *hw)
  6520. {
  6521. uint32_t swsm;
  6522. DEBUGFUNC("e1000_release_software_semaphore");
  6523. if (hw->mac_type != e1000_80003es2lan)
  6524. return;
  6525. swsm = E1000_READ_REG(hw, SWSM);
  6526. /* Release the SW semaphores.*/
  6527. swsm &= ~E1000_SWSM_SMBI;
  6528. E1000_WRITE_REG(hw, SWSM, swsm);
  6529. }
  6530. /******************************************************************************
  6531. * Checks if PHY reset is blocked due to SOL/IDER session, for example.
  6532. * Returning E1000_BLK_PHY_RESET isn't necessarily an error. But it's up to
  6533. * the caller to figure out how to deal with it.
  6534. *
  6535. * hw - Struct containing variables accessed by shared code
  6536. *
  6537. * returns: - E1000_BLK_PHY_RESET
  6538. * E1000_SUCCESS
  6539. *
  6540. *****************************************************************************/
  6541. int32_t
  6542. e1000_check_phy_reset_block(struct e1000_hw *hw)
  6543. {
  6544. uint32_t manc = 0;
  6545. if (hw->mac_type > e1000_82547_rev_2)
  6546. manc = E1000_READ_REG(hw, MANC);
  6547. return (manc & E1000_MANC_BLK_PHY_RST_ON_IDE) ?
  6548. E1000_BLK_PHY_RESET : E1000_SUCCESS;
  6549. }
  6550. static uint8_t
  6551. e1000_arc_subsystem_valid(struct e1000_hw *hw)
  6552. {
  6553. uint32_t fwsm;
  6554. /* On 8257x silicon, registers in the range of 0x8800 - 0x8FFC
  6555. * may not be provided a DMA clock when no manageability features are
  6556. * enabled. We do not want to perform any reads/writes to these registers
  6557. * if this is the case. We read FWSM to determine the manageability mode.
  6558. */
  6559. switch (hw->mac_type) {
  6560. case e1000_82571:
  6561. case e1000_82572:
  6562. case e1000_82573:
  6563. case e1000_80003es2lan:
  6564. fwsm = E1000_READ_REG(hw, FWSM);
  6565. if((fwsm & E1000_FWSM_MODE_MASK) != 0)
  6566. return TRUE;
  6567. break;
  6568. default:
  6569. break;
  6570. }
  6571. return FALSE;
  6572. }