e1000_hw.c 234 KB

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