e1000_hw.c 313 KB

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