e1000_hw.c 303 KB

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