e1000_hw.c 312 KB

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