e1000_hw.c 313 KB

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