e1000_hw.c 308 KB

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