e1000_hw.c 313 KB

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