ich8lan.c 159 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798
  1. /* Intel PRO/1000 Linux driver
  2. * Copyright(c) 1999 - 2014 Intel Corporation.
  3. *
  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. *
  8. * This program is distributed in the hope it will be useful, but WITHOUT
  9. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  10. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  11. * more details.
  12. *
  13. * The full GNU General Public License is included in this distribution in
  14. * the file called "COPYING".
  15. *
  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. /* 82562G 10/100 Network Connection
  22. * 82562G-2 10/100 Network Connection
  23. * 82562GT 10/100 Network Connection
  24. * 82562GT-2 10/100 Network Connection
  25. * 82562V 10/100 Network Connection
  26. * 82562V-2 10/100 Network Connection
  27. * 82566DC-2 Gigabit Network Connection
  28. * 82566DC Gigabit Network Connection
  29. * 82566DM-2 Gigabit Network Connection
  30. * 82566DM Gigabit Network Connection
  31. * 82566MC Gigabit Network Connection
  32. * 82566MM Gigabit Network Connection
  33. * 82567LM Gigabit Network Connection
  34. * 82567LF Gigabit Network Connection
  35. * 82567V Gigabit Network Connection
  36. * 82567LM-2 Gigabit Network Connection
  37. * 82567LF-2 Gigabit Network Connection
  38. * 82567V-2 Gigabit Network Connection
  39. * 82567LF-3 Gigabit Network Connection
  40. * 82567LM-3 Gigabit Network Connection
  41. * 82567LM-4 Gigabit Network Connection
  42. * 82577LM Gigabit Network Connection
  43. * 82577LC Gigabit Network Connection
  44. * 82578DM Gigabit Network Connection
  45. * 82578DC Gigabit Network Connection
  46. * 82579LM Gigabit Network Connection
  47. * 82579V Gigabit Network Connection
  48. * Ethernet Connection I217-LM
  49. * Ethernet Connection I217-V
  50. * Ethernet Connection I218-V
  51. * Ethernet Connection I218-LM
  52. * Ethernet Connection (2) I218-LM
  53. * Ethernet Connection (2) I218-V
  54. * Ethernet Connection (3) I218-LM
  55. * Ethernet Connection (3) I218-V
  56. */
  57. #include "e1000.h"
  58. /* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
  59. /* Offset 04h HSFSTS */
  60. union ich8_hws_flash_status {
  61. struct ich8_hsfsts {
  62. u16 flcdone:1; /* bit 0 Flash Cycle Done */
  63. u16 flcerr:1; /* bit 1 Flash Cycle Error */
  64. u16 dael:1; /* bit 2 Direct Access error Log */
  65. u16 berasesz:2; /* bit 4:3 Sector Erase Size */
  66. u16 flcinprog:1; /* bit 5 flash cycle in Progress */
  67. u16 reserved1:2; /* bit 13:6 Reserved */
  68. u16 reserved2:6; /* bit 13:6 Reserved */
  69. u16 fldesvalid:1; /* bit 14 Flash Descriptor Valid */
  70. u16 flockdn:1; /* bit 15 Flash Config Lock-Down */
  71. } hsf_status;
  72. u16 regval;
  73. };
  74. /* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
  75. /* Offset 06h FLCTL */
  76. union ich8_hws_flash_ctrl {
  77. struct ich8_hsflctl {
  78. u16 flcgo:1; /* 0 Flash Cycle Go */
  79. u16 flcycle:2; /* 2:1 Flash Cycle */
  80. u16 reserved:5; /* 7:3 Reserved */
  81. u16 fldbcount:2; /* 9:8 Flash Data Byte Count */
  82. u16 flockdn:6; /* 15:10 Reserved */
  83. } hsf_ctrl;
  84. u16 regval;
  85. };
  86. /* ICH Flash Region Access Permissions */
  87. union ich8_hws_flash_regacc {
  88. struct ich8_flracc {
  89. u32 grra:8; /* 0:7 GbE region Read Access */
  90. u32 grwa:8; /* 8:15 GbE region Write Access */
  91. u32 gmrag:8; /* 23:16 GbE Master Read Access Grant */
  92. u32 gmwag:8; /* 31:24 GbE Master Write Access Grant */
  93. } hsf_flregacc;
  94. u16 regval;
  95. };
  96. /* ICH Flash Protected Region */
  97. union ich8_flash_protected_range {
  98. struct ich8_pr {
  99. u32 base:13; /* 0:12 Protected Range Base */
  100. u32 reserved1:2; /* 13:14 Reserved */
  101. u32 rpe:1; /* 15 Read Protection Enable */
  102. u32 limit:13; /* 16:28 Protected Range Limit */
  103. u32 reserved2:2; /* 29:30 Reserved */
  104. u32 wpe:1; /* 31 Write Protection Enable */
  105. } range;
  106. u32 regval;
  107. };
  108. static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
  109. static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
  110. static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
  111. static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
  112. u32 offset, u8 byte);
  113. static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
  114. u8 *data);
  115. static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
  116. u16 *data);
  117. static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
  118. u8 size, u16 *data);
  119. static s32 e1000_read_flash_data32_ich8lan(struct e1000_hw *hw, u32 offset,
  120. u32 *data);
  121. static s32 e1000_read_flash_dword_ich8lan(struct e1000_hw *hw,
  122. u32 offset, u32 *data);
  123. static s32 e1000_write_flash_data32_ich8lan(struct e1000_hw *hw,
  124. u32 offset, u32 data);
  125. static s32 e1000_retry_write_flash_dword_ich8lan(struct e1000_hw *hw,
  126. u32 offset, u32 dword);
  127. static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
  128. static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
  129. static s32 e1000_led_on_ich8lan(struct e1000_hw *hw);
  130. static s32 e1000_led_off_ich8lan(struct e1000_hw *hw);
  131. static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw);
  132. static s32 e1000_setup_led_pchlan(struct e1000_hw *hw);
  133. static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw);
  134. static s32 e1000_led_on_pchlan(struct e1000_hw *hw);
  135. static s32 e1000_led_off_pchlan(struct e1000_hw *hw);
  136. static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active);
  137. static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw);
  138. static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw);
  139. static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link);
  140. static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw);
  141. static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
  142. static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw);
  143. static int e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index);
  144. static int e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index);
  145. static u32 e1000_rar_get_count_pch_lpt(struct e1000_hw *hw);
  146. static s32 e1000_k1_workaround_lv(struct e1000_hw *hw);
  147. static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate);
  148. static s32 e1000_disable_ulp_lpt_lp(struct e1000_hw *hw, bool force);
  149. static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw);
  150. static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state);
  151. static inline u16 __er16flash(struct e1000_hw *hw, unsigned long reg)
  152. {
  153. return readw(hw->flash_address + reg);
  154. }
  155. static inline u32 __er32flash(struct e1000_hw *hw, unsigned long reg)
  156. {
  157. return readl(hw->flash_address + reg);
  158. }
  159. static inline void __ew16flash(struct e1000_hw *hw, unsigned long reg, u16 val)
  160. {
  161. writew(val, hw->flash_address + reg);
  162. }
  163. static inline void __ew32flash(struct e1000_hw *hw, unsigned long reg, u32 val)
  164. {
  165. writel(val, hw->flash_address + reg);
  166. }
  167. #define er16flash(reg) __er16flash(hw, (reg))
  168. #define er32flash(reg) __er32flash(hw, (reg))
  169. #define ew16flash(reg, val) __ew16flash(hw, (reg), (val))
  170. #define ew32flash(reg, val) __ew32flash(hw, (reg), (val))
  171. /**
  172. * e1000_phy_is_accessible_pchlan - Check if able to access PHY registers
  173. * @hw: pointer to the HW structure
  174. *
  175. * Test access to the PHY registers by reading the PHY ID registers. If
  176. * the PHY ID is already known (e.g. resume path) compare it with known ID,
  177. * otherwise assume the read PHY ID is correct if it is valid.
  178. *
  179. * Assumes the sw/fw/hw semaphore is already acquired.
  180. **/
  181. static bool e1000_phy_is_accessible_pchlan(struct e1000_hw *hw)
  182. {
  183. u16 phy_reg = 0;
  184. u32 phy_id = 0;
  185. s32 ret_val = 0;
  186. u16 retry_count;
  187. u32 mac_reg = 0;
  188. for (retry_count = 0; retry_count < 2; retry_count++) {
  189. ret_val = e1e_rphy_locked(hw, MII_PHYSID1, &phy_reg);
  190. if (ret_val || (phy_reg == 0xFFFF))
  191. continue;
  192. phy_id = (u32)(phy_reg << 16);
  193. ret_val = e1e_rphy_locked(hw, MII_PHYSID2, &phy_reg);
  194. if (ret_val || (phy_reg == 0xFFFF)) {
  195. phy_id = 0;
  196. continue;
  197. }
  198. phy_id |= (u32)(phy_reg & PHY_REVISION_MASK);
  199. break;
  200. }
  201. if (hw->phy.id) {
  202. if (hw->phy.id == phy_id)
  203. goto out;
  204. } else if (phy_id) {
  205. hw->phy.id = phy_id;
  206. hw->phy.revision = (u32)(phy_reg & ~PHY_REVISION_MASK);
  207. goto out;
  208. }
  209. /* In case the PHY needs to be in mdio slow mode,
  210. * set slow mode and try to get the PHY id again.
  211. */
  212. if (hw->mac.type < e1000_pch_lpt) {
  213. hw->phy.ops.release(hw);
  214. ret_val = e1000_set_mdio_slow_mode_hv(hw);
  215. if (!ret_val)
  216. ret_val = e1000e_get_phy_id(hw);
  217. hw->phy.ops.acquire(hw);
  218. }
  219. if (ret_val)
  220. return false;
  221. out:
  222. if ((hw->mac.type == e1000_pch_lpt) ||
  223. (hw->mac.type == e1000_pch_spt)) {
  224. /* Unforce SMBus mode in PHY */
  225. e1e_rphy_locked(hw, CV_SMB_CTRL, &phy_reg);
  226. phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
  227. e1e_wphy_locked(hw, CV_SMB_CTRL, phy_reg);
  228. /* Unforce SMBus mode in MAC */
  229. mac_reg = er32(CTRL_EXT);
  230. mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
  231. ew32(CTRL_EXT, mac_reg);
  232. }
  233. return true;
  234. }
  235. /**
  236. * e1000_toggle_lanphypc_pch_lpt - toggle the LANPHYPC pin value
  237. * @hw: pointer to the HW structure
  238. *
  239. * Toggling the LANPHYPC pin value fully power-cycles the PHY and is
  240. * used to reset the PHY to a quiescent state when necessary.
  241. **/
  242. static void e1000_toggle_lanphypc_pch_lpt(struct e1000_hw *hw)
  243. {
  244. u32 mac_reg;
  245. /* Set Phy Config Counter to 50msec */
  246. mac_reg = er32(FEXTNVM3);
  247. mac_reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
  248. mac_reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
  249. ew32(FEXTNVM3, mac_reg);
  250. /* Toggle LANPHYPC Value bit */
  251. mac_reg = er32(CTRL);
  252. mac_reg |= E1000_CTRL_LANPHYPC_OVERRIDE;
  253. mac_reg &= ~E1000_CTRL_LANPHYPC_VALUE;
  254. ew32(CTRL, mac_reg);
  255. e1e_flush();
  256. usleep_range(10, 20);
  257. mac_reg &= ~E1000_CTRL_LANPHYPC_OVERRIDE;
  258. ew32(CTRL, mac_reg);
  259. e1e_flush();
  260. if (hw->mac.type < e1000_pch_lpt) {
  261. msleep(50);
  262. } else {
  263. u16 count = 20;
  264. do {
  265. usleep_range(5000, 10000);
  266. } while (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LPCD) && count--);
  267. msleep(30);
  268. }
  269. }
  270. /**
  271. * e1000_init_phy_workarounds_pchlan - PHY initialization workarounds
  272. * @hw: pointer to the HW structure
  273. *
  274. * Workarounds/flow necessary for PHY initialization during driver load
  275. * and resume paths.
  276. **/
  277. static s32 e1000_init_phy_workarounds_pchlan(struct e1000_hw *hw)
  278. {
  279. struct e1000_adapter *adapter = hw->adapter;
  280. u32 mac_reg, fwsm = er32(FWSM);
  281. s32 ret_val;
  282. /* Gate automatic PHY configuration by hardware on managed and
  283. * non-managed 82579 and newer adapters.
  284. */
  285. e1000_gate_hw_phy_config_ich8lan(hw, true);
  286. /* It is not possible to be certain of the current state of ULP
  287. * so forcibly disable it.
  288. */
  289. hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_unknown;
  290. e1000_disable_ulp_lpt_lp(hw, true);
  291. ret_val = hw->phy.ops.acquire(hw);
  292. if (ret_val) {
  293. e_dbg("Failed to initialize PHY flow\n");
  294. goto out;
  295. }
  296. /* The MAC-PHY interconnect may be in SMBus mode. If the PHY is
  297. * inaccessible and resetting the PHY is not blocked, toggle the
  298. * LANPHYPC Value bit to force the interconnect to PCIe mode.
  299. */
  300. switch (hw->mac.type) {
  301. case e1000_pch_lpt:
  302. case e1000_pch_spt:
  303. if (e1000_phy_is_accessible_pchlan(hw))
  304. break;
  305. /* Before toggling LANPHYPC, see if PHY is accessible by
  306. * forcing MAC to SMBus mode first.
  307. */
  308. mac_reg = er32(CTRL_EXT);
  309. mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
  310. ew32(CTRL_EXT, mac_reg);
  311. /* Wait 50 milliseconds for MAC to finish any retries
  312. * that it might be trying to perform from previous
  313. * attempts to acknowledge any phy read requests.
  314. */
  315. msleep(50);
  316. /* fall-through */
  317. case e1000_pch2lan:
  318. if (e1000_phy_is_accessible_pchlan(hw))
  319. break;
  320. /* fall-through */
  321. case e1000_pchlan:
  322. if ((hw->mac.type == e1000_pchlan) &&
  323. (fwsm & E1000_ICH_FWSM_FW_VALID))
  324. break;
  325. if (hw->phy.ops.check_reset_block(hw)) {
  326. e_dbg("Required LANPHYPC toggle blocked by ME\n");
  327. ret_val = -E1000_ERR_PHY;
  328. break;
  329. }
  330. /* Toggle LANPHYPC Value bit */
  331. e1000_toggle_lanphypc_pch_lpt(hw);
  332. if (hw->mac.type >= e1000_pch_lpt) {
  333. if (e1000_phy_is_accessible_pchlan(hw))
  334. break;
  335. /* Toggling LANPHYPC brings the PHY out of SMBus mode
  336. * so ensure that the MAC is also out of SMBus mode
  337. */
  338. mac_reg = er32(CTRL_EXT);
  339. mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
  340. ew32(CTRL_EXT, mac_reg);
  341. if (e1000_phy_is_accessible_pchlan(hw))
  342. break;
  343. ret_val = -E1000_ERR_PHY;
  344. }
  345. break;
  346. default:
  347. break;
  348. }
  349. hw->phy.ops.release(hw);
  350. if (!ret_val) {
  351. /* Check to see if able to reset PHY. Print error if not */
  352. if (hw->phy.ops.check_reset_block(hw)) {
  353. e_err("Reset blocked by ME\n");
  354. goto out;
  355. }
  356. /* Reset the PHY before any access to it. Doing so, ensures
  357. * that the PHY is in a known good state before we read/write
  358. * PHY registers. The generic reset is sufficient here,
  359. * because we haven't determined the PHY type yet.
  360. */
  361. ret_val = e1000e_phy_hw_reset_generic(hw);
  362. if (ret_val)
  363. goto out;
  364. /* On a successful reset, possibly need to wait for the PHY
  365. * to quiesce to an accessible state before returning control
  366. * to the calling function. If the PHY does not quiesce, then
  367. * return E1000E_BLK_PHY_RESET, as this is the condition that
  368. * the PHY is in.
  369. */
  370. ret_val = hw->phy.ops.check_reset_block(hw);
  371. if (ret_val)
  372. e_err("ME blocked access to PHY after reset\n");
  373. }
  374. out:
  375. /* Ungate automatic PHY configuration on non-managed 82579 */
  376. if ((hw->mac.type == e1000_pch2lan) &&
  377. !(fwsm & E1000_ICH_FWSM_FW_VALID)) {
  378. usleep_range(10000, 20000);
  379. e1000_gate_hw_phy_config_ich8lan(hw, false);
  380. }
  381. return ret_val;
  382. }
  383. /**
  384. * e1000_init_phy_params_pchlan - Initialize PHY function pointers
  385. * @hw: pointer to the HW structure
  386. *
  387. * Initialize family-specific PHY parameters and function pointers.
  388. **/
  389. static s32 e1000_init_phy_params_pchlan(struct e1000_hw *hw)
  390. {
  391. struct e1000_phy_info *phy = &hw->phy;
  392. s32 ret_val;
  393. phy->addr = 1;
  394. phy->reset_delay_us = 100;
  395. phy->ops.set_page = e1000_set_page_igp;
  396. phy->ops.read_reg = e1000_read_phy_reg_hv;
  397. phy->ops.read_reg_locked = e1000_read_phy_reg_hv_locked;
  398. phy->ops.read_reg_page = e1000_read_phy_reg_page_hv;
  399. phy->ops.set_d0_lplu_state = e1000_set_lplu_state_pchlan;
  400. phy->ops.set_d3_lplu_state = e1000_set_lplu_state_pchlan;
  401. phy->ops.write_reg = e1000_write_phy_reg_hv;
  402. phy->ops.write_reg_locked = e1000_write_phy_reg_hv_locked;
  403. phy->ops.write_reg_page = e1000_write_phy_reg_page_hv;
  404. phy->ops.power_up = e1000_power_up_phy_copper;
  405. phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
  406. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  407. phy->id = e1000_phy_unknown;
  408. ret_val = e1000_init_phy_workarounds_pchlan(hw);
  409. if (ret_val)
  410. return ret_val;
  411. if (phy->id == e1000_phy_unknown)
  412. switch (hw->mac.type) {
  413. default:
  414. ret_val = e1000e_get_phy_id(hw);
  415. if (ret_val)
  416. return ret_val;
  417. if ((phy->id != 0) && (phy->id != PHY_REVISION_MASK))
  418. break;
  419. /* fall-through */
  420. case e1000_pch2lan:
  421. case e1000_pch_lpt:
  422. case e1000_pch_spt:
  423. /* In case the PHY needs to be in mdio slow mode,
  424. * set slow mode and try to get the PHY id again.
  425. */
  426. ret_val = e1000_set_mdio_slow_mode_hv(hw);
  427. if (ret_val)
  428. return ret_val;
  429. ret_val = e1000e_get_phy_id(hw);
  430. if (ret_val)
  431. return ret_val;
  432. break;
  433. }
  434. phy->type = e1000e_get_phy_type_from_id(phy->id);
  435. switch (phy->type) {
  436. case e1000_phy_82577:
  437. case e1000_phy_82579:
  438. case e1000_phy_i217:
  439. phy->ops.check_polarity = e1000_check_polarity_82577;
  440. phy->ops.force_speed_duplex =
  441. e1000_phy_force_speed_duplex_82577;
  442. phy->ops.get_cable_length = e1000_get_cable_length_82577;
  443. phy->ops.get_info = e1000_get_phy_info_82577;
  444. phy->ops.commit = e1000e_phy_sw_reset;
  445. break;
  446. case e1000_phy_82578:
  447. phy->ops.check_polarity = e1000_check_polarity_m88;
  448. phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
  449. phy->ops.get_cable_length = e1000e_get_cable_length_m88;
  450. phy->ops.get_info = e1000e_get_phy_info_m88;
  451. break;
  452. default:
  453. ret_val = -E1000_ERR_PHY;
  454. break;
  455. }
  456. return ret_val;
  457. }
  458. /**
  459. * e1000_init_phy_params_ich8lan - Initialize PHY function pointers
  460. * @hw: pointer to the HW structure
  461. *
  462. * Initialize family-specific PHY parameters and function pointers.
  463. **/
  464. static s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
  465. {
  466. struct e1000_phy_info *phy = &hw->phy;
  467. s32 ret_val;
  468. u16 i = 0;
  469. phy->addr = 1;
  470. phy->reset_delay_us = 100;
  471. phy->ops.power_up = e1000_power_up_phy_copper;
  472. phy->ops.power_down = e1000_power_down_phy_copper_ich8lan;
  473. /* We may need to do this twice - once for IGP and if that fails,
  474. * we'll set BM func pointers and try again
  475. */
  476. ret_val = e1000e_determine_phy_address(hw);
  477. if (ret_val) {
  478. phy->ops.write_reg = e1000e_write_phy_reg_bm;
  479. phy->ops.read_reg = e1000e_read_phy_reg_bm;
  480. ret_val = e1000e_determine_phy_address(hw);
  481. if (ret_val) {
  482. e_dbg("Cannot determine PHY addr. Erroring out\n");
  483. return ret_val;
  484. }
  485. }
  486. phy->id = 0;
  487. while ((e1000_phy_unknown == e1000e_get_phy_type_from_id(phy->id)) &&
  488. (i++ < 100)) {
  489. usleep_range(1000, 2000);
  490. ret_val = e1000e_get_phy_id(hw);
  491. if (ret_val)
  492. return ret_val;
  493. }
  494. /* Verify phy id */
  495. switch (phy->id) {
  496. case IGP03E1000_E_PHY_ID:
  497. phy->type = e1000_phy_igp_3;
  498. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  499. phy->ops.read_reg_locked = e1000e_read_phy_reg_igp_locked;
  500. phy->ops.write_reg_locked = e1000e_write_phy_reg_igp_locked;
  501. phy->ops.get_info = e1000e_get_phy_info_igp;
  502. phy->ops.check_polarity = e1000_check_polarity_igp;
  503. phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_igp;
  504. break;
  505. case IFE_E_PHY_ID:
  506. case IFE_PLUS_E_PHY_ID:
  507. case IFE_C_E_PHY_ID:
  508. phy->type = e1000_phy_ife;
  509. phy->autoneg_mask = E1000_ALL_NOT_GIG;
  510. phy->ops.get_info = e1000_get_phy_info_ife;
  511. phy->ops.check_polarity = e1000_check_polarity_ife;
  512. phy->ops.force_speed_duplex = e1000_phy_force_speed_duplex_ife;
  513. break;
  514. case BME1000_E_PHY_ID:
  515. phy->type = e1000_phy_bm;
  516. phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  517. phy->ops.read_reg = e1000e_read_phy_reg_bm;
  518. phy->ops.write_reg = e1000e_write_phy_reg_bm;
  519. phy->ops.commit = e1000e_phy_sw_reset;
  520. phy->ops.get_info = e1000e_get_phy_info_m88;
  521. phy->ops.check_polarity = e1000_check_polarity_m88;
  522. phy->ops.force_speed_duplex = e1000e_phy_force_speed_duplex_m88;
  523. break;
  524. default:
  525. return -E1000_ERR_PHY;
  526. }
  527. return 0;
  528. }
  529. /**
  530. * e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
  531. * @hw: pointer to the HW structure
  532. *
  533. * Initialize family-specific NVM parameters and function
  534. * pointers.
  535. **/
  536. static s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
  537. {
  538. struct e1000_nvm_info *nvm = &hw->nvm;
  539. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  540. u32 gfpreg, sector_base_addr, sector_end_addr;
  541. u16 i;
  542. u32 nvm_size;
  543. /* Can't read flash registers if the register set isn't mapped. */
  544. nvm->type = e1000_nvm_flash_sw;
  545. /* in SPT, gfpreg doesn't exist. NVM size is taken from the
  546. * STRAP register
  547. */
  548. if (hw->mac.type == e1000_pch_spt) {
  549. nvm->flash_base_addr = 0;
  550. nvm_size = (((er32(STRAP) >> 1) & 0x1F) + 1)
  551. * NVM_SIZE_MULTIPLIER;
  552. nvm->flash_bank_size = nvm_size / 2;
  553. /* Adjust to word count */
  554. nvm->flash_bank_size /= sizeof(u16);
  555. /* Set the base address for flash register access */
  556. hw->flash_address = hw->hw_addr + E1000_FLASH_BASE_ADDR;
  557. } else {
  558. if (!hw->flash_address) {
  559. e_dbg("ERROR: Flash registers not mapped\n");
  560. return -E1000_ERR_CONFIG;
  561. }
  562. gfpreg = er32flash(ICH_FLASH_GFPREG);
  563. /* sector_X_addr is a "sector"-aligned address (4096 bytes)
  564. * Add 1 to sector_end_addr since this sector is included in
  565. * the overall size.
  566. */
  567. sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
  568. sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
  569. /* flash_base_addr is byte-aligned */
  570. nvm->flash_base_addr = sector_base_addr
  571. << FLASH_SECTOR_ADDR_SHIFT;
  572. /* find total size of the NVM, then cut in half since the total
  573. * size represents two separate NVM banks.
  574. */
  575. nvm->flash_bank_size = ((sector_end_addr - sector_base_addr)
  576. << FLASH_SECTOR_ADDR_SHIFT);
  577. nvm->flash_bank_size /= 2;
  578. /* Adjust to word count */
  579. nvm->flash_bank_size /= sizeof(u16);
  580. }
  581. nvm->word_size = E1000_ICH8_SHADOW_RAM_WORDS;
  582. /* Clear shadow ram */
  583. for (i = 0; i < nvm->word_size; i++) {
  584. dev_spec->shadow_ram[i].modified = false;
  585. dev_spec->shadow_ram[i].value = 0xFFFF;
  586. }
  587. return 0;
  588. }
  589. /**
  590. * e1000_init_mac_params_ich8lan - Initialize MAC function pointers
  591. * @hw: pointer to the HW structure
  592. *
  593. * Initialize family-specific MAC parameters and function
  594. * pointers.
  595. **/
  596. static s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
  597. {
  598. struct e1000_mac_info *mac = &hw->mac;
  599. /* Set media type function pointer */
  600. hw->phy.media_type = e1000_media_type_copper;
  601. /* Set mta register count */
  602. mac->mta_reg_count = 32;
  603. /* Set rar entry count */
  604. mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
  605. if (mac->type == e1000_ich8lan)
  606. mac->rar_entry_count--;
  607. /* FWSM register */
  608. mac->has_fwsm = true;
  609. /* ARC subsystem not supported */
  610. mac->arc_subsystem_valid = false;
  611. /* Adaptive IFS supported */
  612. mac->adaptive_ifs = true;
  613. /* LED and other operations */
  614. switch (mac->type) {
  615. case e1000_ich8lan:
  616. case e1000_ich9lan:
  617. case e1000_ich10lan:
  618. /* check management mode */
  619. mac->ops.check_mng_mode = e1000_check_mng_mode_ich8lan;
  620. /* ID LED init */
  621. mac->ops.id_led_init = e1000e_id_led_init_generic;
  622. /* blink LED */
  623. mac->ops.blink_led = e1000e_blink_led_generic;
  624. /* setup LED */
  625. mac->ops.setup_led = e1000e_setup_led_generic;
  626. /* cleanup LED */
  627. mac->ops.cleanup_led = e1000_cleanup_led_ich8lan;
  628. /* turn on/off LED */
  629. mac->ops.led_on = e1000_led_on_ich8lan;
  630. mac->ops.led_off = e1000_led_off_ich8lan;
  631. break;
  632. case e1000_pch2lan:
  633. mac->rar_entry_count = E1000_PCH2_RAR_ENTRIES;
  634. mac->ops.rar_set = e1000_rar_set_pch2lan;
  635. /* fall-through */
  636. case e1000_pch_lpt:
  637. case e1000_pch_spt:
  638. case e1000_pchlan:
  639. /* check management mode */
  640. mac->ops.check_mng_mode = e1000_check_mng_mode_pchlan;
  641. /* ID LED init */
  642. mac->ops.id_led_init = e1000_id_led_init_pchlan;
  643. /* setup LED */
  644. mac->ops.setup_led = e1000_setup_led_pchlan;
  645. /* cleanup LED */
  646. mac->ops.cleanup_led = e1000_cleanup_led_pchlan;
  647. /* turn on/off LED */
  648. mac->ops.led_on = e1000_led_on_pchlan;
  649. mac->ops.led_off = e1000_led_off_pchlan;
  650. break;
  651. default:
  652. break;
  653. }
  654. if ((mac->type == e1000_pch_lpt) || (mac->type == e1000_pch_spt)) {
  655. mac->rar_entry_count = E1000_PCH_LPT_RAR_ENTRIES;
  656. mac->ops.rar_set = e1000_rar_set_pch_lpt;
  657. mac->ops.setup_physical_interface =
  658. e1000_setup_copper_link_pch_lpt;
  659. mac->ops.rar_get_count = e1000_rar_get_count_pch_lpt;
  660. }
  661. /* Enable PCS Lock-loss workaround for ICH8 */
  662. if (mac->type == e1000_ich8lan)
  663. e1000e_set_kmrn_lock_loss_workaround_ich8lan(hw, true);
  664. return 0;
  665. }
  666. /**
  667. * __e1000_access_emi_reg_locked - Read/write EMI register
  668. * @hw: pointer to the HW structure
  669. * @addr: EMI address to program
  670. * @data: pointer to value to read/write from/to the EMI address
  671. * @read: boolean flag to indicate read or write
  672. *
  673. * This helper function assumes the SW/FW/HW Semaphore is already acquired.
  674. **/
  675. static s32 __e1000_access_emi_reg_locked(struct e1000_hw *hw, u16 address,
  676. u16 *data, bool read)
  677. {
  678. s32 ret_val;
  679. ret_val = e1e_wphy_locked(hw, I82579_EMI_ADDR, address);
  680. if (ret_val)
  681. return ret_val;
  682. if (read)
  683. ret_val = e1e_rphy_locked(hw, I82579_EMI_DATA, data);
  684. else
  685. ret_val = e1e_wphy_locked(hw, I82579_EMI_DATA, *data);
  686. return ret_val;
  687. }
  688. /**
  689. * e1000_read_emi_reg_locked - Read Extended Management Interface register
  690. * @hw: pointer to the HW structure
  691. * @addr: EMI address to program
  692. * @data: value to be read from the EMI address
  693. *
  694. * Assumes the SW/FW/HW Semaphore is already acquired.
  695. **/
  696. s32 e1000_read_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 *data)
  697. {
  698. return __e1000_access_emi_reg_locked(hw, addr, data, true);
  699. }
  700. /**
  701. * e1000_write_emi_reg_locked - Write Extended Management Interface register
  702. * @hw: pointer to the HW structure
  703. * @addr: EMI address to program
  704. * @data: value to be written to the EMI address
  705. *
  706. * Assumes the SW/FW/HW Semaphore is already acquired.
  707. **/
  708. s32 e1000_write_emi_reg_locked(struct e1000_hw *hw, u16 addr, u16 data)
  709. {
  710. return __e1000_access_emi_reg_locked(hw, addr, &data, false);
  711. }
  712. /**
  713. * e1000_set_eee_pchlan - Enable/disable EEE support
  714. * @hw: pointer to the HW structure
  715. *
  716. * Enable/disable EEE based on setting in dev_spec structure, the duplex of
  717. * the link and the EEE capabilities of the link partner. The LPI Control
  718. * register bits will remain set only if/when link is up.
  719. *
  720. * EEE LPI must not be asserted earlier than one second after link is up.
  721. * On 82579, EEE LPI should not be enabled until such time otherwise there
  722. * can be link issues with some switches. Other devices can have EEE LPI
  723. * enabled immediately upon link up since they have a timer in hardware which
  724. * prevents LPI from being asserted too early.
  725. **/
  726. s32 e1000_set_eee_pchlan(struct e1000_hw *hw)
  727. {
  728. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  729. s32 ret_val;
  730. u16 lpa, pcs_status, adv, adv_addr, lpi_ctrl, data;
  731. switch (hw->phy.type) {
  732. case e1000_phy_82579:
  733. lpa = I82579_EEE_LP_ABILITY;
  734. pcs_status = I82579_EEE_PCS_STATUS;
  735. adv_addr = I82579_EEE_ADVERTISEMENT;
  736. break;
  737. case e1000_phy_i217:
  738. lpa = I217_EEE_LP_ABILITY;
  739. pcs_status = I217_EEE_PCS_STATUS;
  740. adv_addr = I217_EEE_ADVERTISEMENT;
  741. break;
  742. default:
  743. return 0;
  744. }
  745. ret_val = hw->phy.ops.acquire(hw);
  746. if (ret_val)
  747. return ret_val;
  748. ret_val = e1e_rphy_locked(hw, I82579_LPI_CTRL, &lpi_ctrl);
  749. if (ret_val)
  750. goto release;
  751. /* Clear bits that enable EEE in various speeds */
  752. lpi_ctrl &= ~I82579_LPI_CTRL_ENABLE_MASK;
  753. /* Enable EEE if not disabled by user */
  754. if (!dev_spec->eee_disable) {
  755. /* Save off link partner's EEE ability */
  756. ret_val = e1000_read_emi_reg_locked(hw, lpa,
  757. &dev_spec->eee_lp_ability);
  758. if (ret_val)
  759. goto release;
  760. /* Read EEE advertisement */
  761. ret_val = e1000_read_emi_reg_locked(hw, adv_addr, &adv);
  762. if (ret_val)
  763. goto release;
  764. /* Enable EEE only for speeds in which the link partner is
  765. * EEE capable and for which we advertise EEE.
  766. */
  767. if (adv & dev_spec->eee_lp_ability & I82579_EEE_1000_SUPPORTED)
  768. lpi_ctrl |= I82579_LPI_CTRL_1000_ENABLE;
  769. if (adv & dev_spec->eee_lp_ability & I82579_EEE_100_SUPPORTED) {
  770. e1e_rphy_locked(hw, MII_LPA, &data);
  771. if (data & LPA_100FULL)
  772. lpi_ctrl |= I82579_LPI_CTRL_100_ENABLE;
  773. else
  774. /* EEE is not supported in 100Half, so ignore
  775. * partner's EEE in 100 ability if full-duplex
  776. * is not advertised.
  777. */
  778. dev_spec->eee_lp_ability &=
  779. ~I82579_EEE_100_SUPPORTED;
  780. }
  781. }
  782. if (hw->phy.type == e1000_phy_82579) {
  783. ret_val = e1000_read_emi_reg_locked(hw, I82579_LPI_PLL_SHUT,
  784. &data);
  785. if (ret_val)
  786. goto release;
  787. data &= ~I82579_LPI_100_PLL_SHUT;
  788. ret_val = e1000_write_emi_reg_locked(hw, I82579_LPI_PLL_SHUT,
  789. data);
  790. }
  791. /* R/Clr IEEE MMD 3.1 bits 11:10 - Tx/Rx LPI Received */
  792. ret_val = e1000_read_emi_reg_locked(hw, pcs_status, &data);
  793. if (ret_val)
  794. goto release;
  795. ret_val = e1e_wphy_locked(hw, I82579_LPI_CTRL, lpi_ctrl);
  796. release:
  797. hw->phy.ops.release(hw);
  798. return ret_val;
  799. }
  800. /**
  801. * e1000_k1_workaround_lpt_lp - K1 workaround on Lynxpoint-LP
  802. * @hw: pointer to the HW structure
  803. * @link: link up bool flag
  804. *
  805. * When K1 is enabled for 1Gbps, the MAC can miss 2 DMA completion indications
  806. * preventing further DMA write requests. Workaround the issue by disabling
  807. * the de-assertion of the clock request when in 1Gpbs mode.
  808. * Also, set appropriate Tx re-transmission timeouts for 10 and 100Half link
  809. * speeds in order to avoid Tx hangs.
  810. **/
  811. static s32 e1000_k1_workaround_lpt_lp(struct e1000_hw *hw, bool link)
  812. {
  813. u32 fextnvm6 = er32(FEXTNVM6);
  814. u32 status = er32(STATUS);
  815. s32 ret_val = 0;
  816. u16 reg;
  817. if (link && (status & E1000_STATUS_SPEED_1000)) {
  818. ret_val = hw->phy.ops.acquire(hw);
  819. if (ret_val)
  820. return ret_val;
  821. ret_val =
  822. e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
  823. &reg);
  824. if (ret_val)
  825. goto release;
  826. ret_val =
  827. e1000e_write_kmrn_reg_locked(hw,
  828. E1000_KMRNCTRLSTA_K1_CONFIG,
  829. reg &
  830. ~E1000_KMRNCTRLSTA_K1_ENABLE);
  831. if (ret_val)
  832. goto release;
  833. usleep_range(10, 20);
  834. ew32(FEXTNVM6, fextnvm6 | E1000_FEXTNVM6_REQ_PLL_CLK);
  835. ret_val =
  836. e1000e_write_kmrn_reg_locked(hw,
  837. E1000_KMRNCTRLSTA_K1_CONFIG,
  838. reg);
  839. release:
  840. hw->phy.ops.release(hw);
  841. } else {
  842. /* clear FEXTNVM6 bit 8 on link down or 10/100 */
  843. fextnvm6 &= ~E1000_FEXTNVM6_REQ_PLL_CLK;
  844. if ((hw->phy.revision > 5) || !link ||
  845. ((status & E1000_STATUS_SPEED_100) &&
  846. (status & E1000_STATUS_FD)))
  847. goto update_fextnvm6;
  848. ret_val = e1e_rphy(hw, I217_INBAND_CTRL, &reg);
  849. if (ret_val)
  850. return ret_val;
  851. /* Clear link status transmit timeout */
  852. reg &= ~I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_MASK;
  853. if (status & E1000_STATUS_SPEED_100) {
  854. /* Set inband Tx timeout to 5x10us for 100Half */
  855. reg |= 5 << I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
  856. /* Do not extend the K1 entry latency for 100Half */
  857. fextnvm6 &= ~E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
  858. } else {
  859. /* Set inband Tx timeout to 50x10us for 10Full/Half */
  860. reg |= 50 <<
  861. I217_INBAND_CTRL_LINK_STAT_TX_TIMEOUT_SHIFT;
  862. /* Extend the K1 entry latency for 10 Mbps */
  863. fextnvm6 |= E1000_FEXTNVM6_ENABLE_K1_ENTRY_CONDITION;
  864. }
  865. ret_val = e1e_wphy(hw, I217_INBAND_CTRL, reg);
  866. if (ret_val)
  867. return ret_val;
  868. update_fextnvm6:
  869. ew32(FEXTNVM6, fextnvm6);
  870. }
  871. return ret_val;
  872. }
  873. /**
  874. * e1000_platform_pm_pch_lpt - Set platform power management values
  875. * @hw: pointer to the HW structure
  876. * @link: bool indicating link status
  877. *
  878. * Set the Latency Tolerance Reporting (LTR) values for the "PCIe-like"
  879. * GbE MAC in the Lynx Point PCH based on Rx buffer size and link speed
  880. * when link is up (which must not exceed the maximum latency supported
  881. * by the platform), otherwise specify there is no LTR requirement.
  882. * Unlike true-PCIe devices which set the LTR maximum snoop/no-snoop
  883. * latencies in the LTR Extended Capability Structure in the PCIe Extended
  884. * Capability register set, on this device LTR is set by writing the
  885. * equivalent snoop/no-snoop latencies in the LTRV register in the MAC and
  886. * set the SEND bit to send an Intel On-chip System Fabric sideband (IOSF-SB)
  887. * message to the PMC.
  888. **/
  889. static s32 e1000_platform_pm_pch_lpt(struct e1000_hw *hw, bool link)
  890. {
  891. u32 reg = link << (E1000_LTRV_REQ_SHIFT + E1000_LTRV_NOSNOOP_SHIFT) |
  892. link << E1000_LTRV_REQ_SHIFT | E1000_LTRV_SEND;
  893. u16 lat_enc = 0; /* latency encoded */
  894. if (link) {
  895. u16 speed, duplex, scale = 0;
  896. u16 max_snoop, max_nosnoop;
  897. u16 max_ltr_enc; /* max LTR latency encoded */
  898. s64 lat_ns; /* latency (ns) */
  899. s64 value;
  900. u32 rxa;
  901. if (!hw->adapter->max_frame_size) {
  902. e_dbg("max_frame_size not set.\n");
  903. return -E1000_ERR_CONFIG;
  904. }
  905. hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
  906. if (!speed) {
  907. e_dbg("Speed not set.\n");
  908. return -E1000_ERR_CONFIG;
  909. }
  910. /* Rx Packet Buffer Allocation size (KB) */
  911. rxa = er32(PBA) & E1000_PBA_RXA_MASK;
  912. /* Determine the maximum latency tolerated by the device.
  913. *
  914. * Per the PCIe spec, the tolerated latencies are encoded as
  915. * a 3-bit encoded scale (only 0-5 are valid) multiplied by
  916. * a 10-bit value (0-1023) to provide a range from 1 ns to
  917. * 2^25*(2^10-1) ns. The scale is encoded as 0=2^0ns,
  918. * 1=2^5ns, 2=2^10ns,...5=2^25ns.
  919. */
  920. lat_ns = ((s64)rxa * 1024 -
  921. (2 * (s64)hw->adapter->max_frame_size)) * 8 * 1000;
  922. if (lat_ns < 0)
  923. lat_ns = 0;
  924. else
  925. do_div(lat_ns, speed);
  926. value = lat_ns;
  927. while (value > PCI_LTR_VALUE_MASK) {
  928. scale++;
  929. value = DIV_ROUND_UP(value, (1 << 5));
  930. }
  931. if (scale > E1000_LTRV_SCALE_MAX) {
  932. e_dbg("Invalid LTR latency scale %d\n", scale);
  933. return -E1000_ERR_CONFIG;
  934. }
  935. lat_enc = (u16)((scale << PCI_LTR_SCALE_SHIFT) | value);
  936. /* Determine the maximum latency tolerated by the platform */
  937. pci_read_config_word(hw->adapter->pdev, E1000_PCI_LTR_CAP_LPT,
  938. &max_snoop);
  939. pci_read_config_word(hw->adapter->pdev,
  940. E1000_PCI_LTR_CAP_LPT + 2, &max_nosnoop);
  941. max_ltr_enc = max_t(u16, max_snoop, max_nosnoop);
  942. if (lat_enc > max_ltr_enc)
  943. lat_enc = max_ltr_enc;
  944. }
  945. /* Set Snoop and No-Snoop latencies the same */
  946. reg |= lat_enc | (lat_enc << E1000_LTRV_NOSNOOP_SHIFT);
  947. ew32(LTRV, reg);
  948. return 0;
  949. }
  950. /**
  951. * e1000_enable_ulp_lpt_lp - configure Ultra Low Power mode for LynxPoint-LP
  952. * @hw: pointer to the HW structure
  953. * @to_sx: boolean indicating a system power state transition to Sx
  954. *
  955. * When link is down, configure ULP mode to significantly reduce the power
  956. * to the PHY. If on a Manageability Engine (ME) enabled system, tell the
  957. * ME firmware to start the ULP configuration. If not on an ME enabled
  958. * system, configure the ULP mode by software.
  959. */
  960. s32 e1000_enable_ulp_lpt_lp(struct e1000_hw *hw, bool to_sx)
  961. {
  962. u32 mac_reg;
  963. s32 ret_val = 0;
  964. u16 phy_reg;
  965. if ((hw->mac.type < e1000_pch_lpt) ||
  966. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_LM) ||
  967. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_V) ||
  968. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM2) ||
  969. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V2) ||
  970. (hw->dev_spec.ich8lan.ulp_state == e1000_ulp_state_on))
  971. return 0;
  972. if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) {
  973. /* Request ME configure ULP mode in the PHY */
  974. mac_reg = er32(H2ME);
  975. mac_reg |= E1000_H2ME_ULP | E1000_H2ME_ENFORCE_SETTINGS;
  976. ew32(H2ME, mac_reg);
  977. goto out;
  978. }
  979. if (!to_sx) {
  980. int i = 0;
  981. /* Poll up to 5 seconds for Cable Disconnected indication */
  982. while (!(er32(FEXT) & E1000_FEXT_PHY_CABLE_DISCONNECTED)) {
  983. /* Bail if link is re-acquired */
  984. if (er32(STATUS) & E1000_STATUS_LU)
  985. return -E1000_ERR_PHY;
  986. if (i++ == 100)
  987. break;
  988. msleep(50);
  989. }
  990. e_dbg("CABLE_DISCONNECTED %s set after %dmsec\n",
  991. (er32(FEXT) &
  992. E1000_FEXT_PHY_CABLE_DISCONNECTED) ? "" : "not", i * 50);
  993. }
  994. ret_val = hw->phy.ops.acquire(hw);
  995. if (ret_val)
  996. goto out;
  997. /* Si workaround for ULP entry flow on i127/rev6 h/w. Enable
  998. * LPLU and disable Gig speed when entering ULP
  999. */
  1000. if ((hw->phy.type == e1000_phy_i217) && (hw->phy.revision == 6)) {
  1001. ret_val = e1000_read_phy_reg_hv_locked(hw, HV_OEM_BITS,
  1002. &phy_reg);
  1003. if (ret_val)
  1004. goto release;
  1005. phy_reg |= HV_OEM_BITS_LPLU | HV_OEM_BITS_GBE_DIS;
  1006. ret_val = e1000_write_phy_reg_hv_locked(hw, HV_OEM_BITS,
  1007. phy_reg);
  1008. if (ret_val)
  1009. goto release;
  1010. }
  1011. /* Force SMBus mode in PHY */
  1012. ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL, &phy_reg);
  1013. if (ret_val)
  1014. goto release;
  1015. phy_reg |= CV_SMB_CTRL_FORCE_SMBUS;
  1016. e1000_write_phy_reg_hv_locked(hw, CV_SMB_CTRL, phy_reg);
  1017. /* Force SMBus mode in MAC */
  1018. mac_reg = er32(CTRL_EXT);
  1019. mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
  1020. ew32(CTRL_EXT, mac_reg);
  1021. /* Set Inband ULP Exit, Reset to SMBus mode and
  1022. * Disable SMBus Release on PERST# in PHY
  1023. */
  1024. ret_val = e1000_read_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, &phy_reg);
  1025. if (ret_val)
  1026. goto release;
  1027. phy_reg |= (I218_ULP_CONFIG1_RESET_TO_SMBUS |
  1028. I218_ULP_CONFIG1_DISABLE_SMB_PERST);
  1029. if (to_sx) {
  1030. if (er32(WUFC) & E1000_WUFC_LNKC)
  1031. phy_reg |= I218_ULP_CONFIG1_WOL_HOST;
  1032. phy_reg |= I218_ULP_CONFIG1_STICKY_ULP;
  1033. } else {
  1034. phy_reg |= I218_ULP_CONFIG1_INBAND_EXIT;
  1035. }
  1036. e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
  1037. /* Set Disable SMBus Release on PERST# in MAC */
  1038. mac_reg = er32(FEXTNVM7);
  1039. mac_reg |= E1000_FEXTNVM7_DISABLE_SMB_PERST;
  1040. ew32(FEXTNVM7, mac_reg);
  1041. /* Commit ULP changes in PHY by starting auto ULP configuration */
  1042. phy_reg |= I218_ULP_CONFIG1_START;
  1043. e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
  1044. release:
  1045. hw->phy.ops.release(hw);
  1046. out:
  1047. if (ret_val)
  1048. e_dbg("Error in ULP enable flow: %d\n", ret_val);
  1049. else
  1050. hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_on;
  1051. return ret_val;
  1052. }
  1053. /**
  1054. * e1000_disable_ulp_lpt_lp - unconfigure Ultra Low Power mode for LynxPoint-LP
  1055. * @hw: pointer to the HW structure
  1056. * @force: boolean indicating whether or not to force disabling ULP
  1057. *
  1058. * Un-configure ULP mode when link is up, the system is transitioned from
  1059. * Sx or the driver is unloaded. If on a Manageability Engine (ME) enabled
  1060. * system, poll for an indication from ME that ULP has been un-configured.
  1061. * If not on an ME enabled system, un-configure the ULP mode by software.
  1062. *
  1063. * During nominal operation, this function is called when link is acquired
  1064. * to disable ULP mode (force=false); otherwise, for example when unloading
  1065. * the driver or during Sx->S0 transitions, this is called with force=true
  1066. * to forcibly disable ULP.
  1067. */
  1068. static s32 e1000_disable_ulp_lpt_lp(struct e1000_hw *hw, bool force)
  1069. {
  1070. s32 ret_val = 0;
  1071. u32 mac_reg;
  1072. u16 phy_reg;
  1073. int i = 0;
  1074. if ((hw->mac.type < e1000_pch_lpt) ||
  1075. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_LM) ||
  1076. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPT_I217_V) ||
  1077. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM2) ||
  1078. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V2) ||
  1079. (hw->dev_spec.ich8lan.ulp_state == e1000_ulp_state_off))
  1080. return 0;
  1081. if (er32(FWSM) & E1000_ICH_FWSM_FW_VALID) {
  1082. if (force) {
  1083. /* Request ME un-configure ULP mode in the PHY */
  1084. mac_reg = er32(H2ME);
  1085. mac_reg &= ~E1000_H2ME_ULP;
  1086. mac_reg |= E1000_H2ME_ENFORCE_SETTINGS;
  1087. ew32(H2ME, mac_reg);
  1088. }
  1089. /* Poll up to 100msec for ME to clear ULP_CFG_DONE */
  1090. while (er32(FWSM) & E1000_FWSM_ULP_CFG_DONE) {
  1091. if (i++ == 10) {
  1092. ret_val = -E1000_ERR_PHY;
  1093. goto out;
  1094. }
  1095. usleep_range(10000, 20000);
  1096. }
  1097. e_dbg("ULP_CONFIG_DONE cleared after %dmsec\n", i * 10);
  1098. if (force) {
  1099. mac_reg = er32(H2ME);
  1100. mac_reg &= ~E1000_H2ME_ENFORCE_SETTINGS;
  1101. ew32(H2ME, mac_reg);
  1102. } else {
  1103. /* Clear H2ME.ULP after ME ULP configuration */
  1104. mac_reg = er32(H2ME);
  1105. mac_reg &= ~E1000_H2ME_ULP;
  1106. ew32(H2ME, mac_reg);
  1107. }
  1108. goto out;
  1109. }
  1110. ret_val = hw->phy.ops.acquire(hw);
  1111. if (ret_val)
  1112. goto out;
  1113. if (force)
  1114. /* Toggle LANPHYPC Value bit */
  1115. e1000_toggle_lanphypc_pch_lpt(hw);
  1116. /* Unforce SMBus mode in PHY */
  1117. ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL, &phy_reg);
  1118. if (ret_val) {
  1119. /* The MAC might be in PCIe mode, so temporarily force to
  1120. * SMBus mode in order to access the PHY.
  1121. */
  1122. mac_reg = er32(CTRL_EXT);
  1123. mac_reg |= E1000_CTRL_EXT_FORCE_SMBUS;
  1124. ew32(CTRL_EXT, mac_reg);
  1125. msleep(50);
  1126. ret_val = e1000_read_phy_reg_hv_locked(hw, CV_SMB_CTRL,
  1127. &phy_reg);
  1128. if (ret_val)
  1129. goto release;
  1130. }
  1131. phy_reg &= ~CV_SMB_CTRL_FORCE_SMBUS;
  1132. e1000_write_phy_reg_hv_locked(hw, CV_SMB_CTRL, phy_reg);
  1133. /* Unforce SMBus mode in MAC */
  1134. mac_reg = er32(CTRL_EXT);
  1135. mac_reg &= ~E1000_CTRL_EXT_FORCE_SMBUS;
  1136. ew32(CTRL_EXT, mac_reg);
  1137. /* When ULP mode was previously entered, K1 was disabled by the
  1138. * hardware. Re-Enable K1 in the PHY when exiting ULP.
  1139. */
  1140. ret_val = e1000_read_phy_reg_hv_locked(hw, HV_PM_CTRL, &phy_reg);
  1141. if (ret_val)
  1142. goto release;
  1143. phy_reg |= HV_PM_CTRL_K1_ENABLE;
  1144. e1000_write_phy_reg_hv_locked(hw, HV_PM_CTRL, phy_reg);
  1145. /* Clear ULP enabled configuration */
  1146. ret_val = e1000_read_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, &phy_reg);
  1147. if (ret_val)
  1148. goto release;
  1149. phy_reg &= ~(I218_ULP_CONFIG1_IND |
  1150. I218_ULP_CONFIG1_STICKY_ULP |
  1151. I218_ULP_CONFIG1_RESET_TO_SMBUS |
  1152. I218_ULP_CONFIG1_WOL_HOST |
  1153. I218_ULP_CONFIG1_INBAND_EXIT |
  1154. I218_ULP_CONFIG1_DISABLE_SMB_PERST);
  1155. e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
  1156. /* Commit ULP changes by starting auto ULP configuration */
  1157. phy_reg |= I218_ULP_CONFIG1_START;
  1158. e1000_write_phy_reg_hv_locked(hw, I218_ULP_CONFIG1, phy_reg);
  1159. /* Clear Disable SMBus Release on PERST# in MAC */
  1160. mac_reg = er32(FEXTNVM7);
  1161. mac_reg &= ~E1000_FEXTNVM7_DISABLE_SMB_PERST;
  1162. ew32(FEXTNVM7, mac_reg);
  1163. release:
  1164. hw->phy.ops.release(hw);
  1165. if (force) {
  1166. e1000_phy_hw_reset(hw);
  1167. msleep(50);
  1168. }
  1169. out:
  1170. if (ret_val)
  1171. e_dbg("Error in ULP disable flow: %d\n", ret_val);
  1172. else
  1173. hw->dev_spec.ich8lan.ulp_state = e1000_ulp_state_off;
  1174. return ret_val;
  1175. }
  1176. /**
  1177. * e1000_check_for_copper_link_ich8lan - Check for link (Copper)
  1178. * @hw: pointer to the HW structure
  1179. *
  1180. * Checks to see of the link status of the hardware has changed. If a
  1181. * change in link status has been detected, then we read the PHY registers
  1182. * to get the current speed/duplex if link exists.
  1183. **/
  1184. static s32 e1000_check_for_copper_link_ich8lan(struct e1000_hw *hw)
  1185. {
  1186. struct e1000_mac_info *mac = &hw->mac;
  1187. s32 ret_val, tipg_reg = 0;
  1188. u16 emi_addr, emi_val = 0;
  1189. bool link;
  1190. u16 phy_reg;
  1191. /* We only want to go out to the PHY registers to see if Auto-Neg
  1192. * has completed and/or if our link status has changed. The
  1193. * get_link_status flag is set upon receiving a Link Status
  1194. * Change or Rx Sequence Error interrupt.
  1195. */
  1196. if (!mac->get_link_status)
  1197. return 0;
  1198. /* First we want to see if the MII Status Register reports
  1199. * link. If so, then we want to get the current speed/duplex
  1200. * of the PHY.
  1201. */
  1202. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  1203. if (ret_val)
  1204. return ret_val;
  1205. if (hw->mac.type == e1000_pchlan) {
  1206. ret_val = e1000_k1_gig_workaround_hv(hw, link);
  1207. if (ret_val)
  1208. return ret_val;
  1209. }
  1210. /* When connected at 10Mbps half-duplex, some parts are excessively
  1211. * aggressive resulting in many collisions. To avoid this, increase
  1212. * the IPG and reduce Rx latency in the PHY.
  1213. */
  1214. if (((hw->mac.type == e1000_pch2lan) ||
  1215. (hw->mac.type == e1000_pch_lpt) ||
  1216. (hw->mac.type == e1000_pch_spt)) && link) {
  1217. u32 reg;
  1218. reg = er32(STATUS);
  1219. tipg_reg = er32(TIPG);
  1220. tipg_reg &= ~E1000_TIPG_IPGT_MASK;
  1221. if (!(reg & (E1000_STATUS_FD | E1000_STATUS_SPEED_MASK))) {
  1222. tipg_reg |= 0xFF;
  1223. /* Reduce Rx latency in analog PHY */
  1224. emi_val = 0;
  1225. } else {
  1226. /* Roll back the default values */
  1227. tipg_reg |= 0x08;
  1228. emi_val = 1;
  1229. }
  1230. ew32(TIPG, tipg_reg);
  1231. ret_val = hw->phy.ops.acquire(hw);
  1232. if (ret_val)
  1233. return ret_val;
  1234. if (hw->mac.type == e1000_pch2lan)
  1235. emi_addr = I82579_RX_CONFIG;
  1236. else
  1237. emi_addr = I217_RX_CONFIG;
  1238. ret_val = e1000_write_emi_reg_locked(hw, emi_addr, emi_val);
  1239. hw->phy.ops.release(hw);
  1240. if (ret_val)
  1241. return ret_val;
  1242. }
  1243. /* Work-around I218 hang issue */
  1244. if ((hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
  1245. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
  1246. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_LM3) ||
  1247. (hw->adapter->pdev->device == E1000_DEV_ID_PCH_I218_V3) ||
  1248. (hw->mac.type == e1000_pch_spt)) {
  1249. ret_val = e1000_k1_workaround_lpt_lp(hw, link);
  1250. if (ret_val)
  1251. return ret_val;
  1252. }
  1253. if ((hw->mac.type == e1000_pch_lpt) ||
  1254. (hw->mac.type == e1000_pch_spt)) {
  1255. /* Set platform power management values for
  1256. * Latency Tolerance Reporting (LTR)
  1257. */
  1258. ret_val = e1000_platform_pm_pch_lpt(hw, link);
  1259. if (ret_val)
  1260. return ret_val;
  1261. }
  1262. /* Clear link partner's EEE ability */
  1263. hw->dev_spec.ich8lan.eee_lp_ability = 0;
  1264. /* FEXTNVM6 K1-off workaround */
  1265. if (hw->mac.type == e1000_pch_spt) {
  1266. u32 pcieanacfg = er32(PCIEANACFG);
  1267. u32 fextnvm6 = er32(FEXTNVM6);
  1268. if (pcieanacfg & E1000_FEXTNVM6_K1_OFF_ENABLE)
  1269. fextnvm6 |= E1000_FEXTNVM6_K1_OFF_ENABLE;
  1270. else
  1271. fextnvm6 &= ~E1000_FEXTNVM6_K1_OFF_ENABLE;
  1272. ew32(FEXTNVM6, fextnvm6);
  1273. }
  1274. if (!link)
  1275. return 0; /* No link detected */
  1276. mac->get_link_status = false;
  1277. switch (hw->mac.type) {
  1278. case e1000_pch2lan:
  1279. ret_val = e1000_k1_workaround_lv(hw);
  1280. if (ret_val)
  1281. return ret_val;
  1282. /* fall-thru */
  1283. case e1000_pchlan:
  1284. if (hw->phy.type == e1000_phy_82578) {
  1285. ret_val = e1000_link_stall_workaround_hv(hw);
  1286. if (ret_val)
  1287. return ret_val;
  1288. }
  1289. /* Workaround for PCHx parts in half-duplex:
  1290. * Set the number of preambles removed from the packet
  1291. * when it is passed from the PHY to the MAC to prevent
  1292. * the MAC from misinterpreting the packet type.
  1293. */
  1294. e1e_rphy(hw, HV_KMRN_FIFO_CTRLSTA, &phy_reg);
  1295. phy_reg &= ~HV_KMRN_FIFO_CTRLSTA_PREAMBLE_MASK;
  1296. if ((er32(STATUS) & E1000_STATUS_FD) != E1000_STATUS_FD)
  1297. phy_reg |= (1 << HV_KMRN_FIFO_CTRLSTA_PREAMBLE_SHIFT);
  1298. e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, phy_reg);
  1299. break;
  1300. default:
  1301. break;
  1302. }
  1303. /* Check if there was DownShift, must be checked
  1304. * immediately after link-up
  1305. */
  1306. e1000e_check_downshift(hw);
  1307. /* Enable/Disable EEE after link up */
  1308. if (hw->phy.type > e1000_phy_82579) {
  1309. ret_val = e1000_set_eee_pchlan(hw);
  1310. if (ret_val)
  1311. return ret_val;
  1312. }
  1313. /* If we are forcing speed/duplex, then we simply return since
  1314. * we have already determined whether we have link or not.
  1315. */
  1316. if (!mac->autoneg)
  1317. return -E1000_ERR_CONFIG;
  1318. /* Auto-Neg is enabled. Auto Speed Detection takes care
  1319. * of MAC speed/duplex configuration. So we only need to
  1320. * configure Collision Distance in the MAC.
  1321. */
  1322. mac->ops.config_collision_dist(hw);
  1323. /* Configure Flow Control now that Auto-Neg has completed.
  1324. * First, we need to restore the desired flow control
  1325. * settings because we may have had to re-autoneg with a
  1326. * different link partner.
  1327. */
  1328. ret_val = e1000e_config_fc_after_link_up(hw);
  1329. if (ret_val)
  1330. e_dbg("Error configuring flow control\n");
  1331. return ret_val;
  1332. }
  1333. static s32 e1000_get_variants_ich8lan(struct e1000_adapter *adapter)
  1334. {
  1335. struct e1000_hw *hw = &adapter->hw;
  1336. s32 rc;
  1337. rc = e1000_init_mac_params_ich8lan(hw);
  1338. if (rc)
  1339. return rc;
  1340. rc = e1000_init_nvm_params_ich8lan(hw);
  1341. if (rc)
  1342. return rc;
  1343. switch (hw->mac.type) {
  1344. case e1000_ich8lan:
  1345. case e1000_ich9lan:
  1346. case e1000_ich10lan:
  1347. rc = e1000_init_phy_params_ich8lan(hw);
  1348. break;
  1349. case e1000_pchlan:
  1350. case e1000_pch2lan:
  1351. case e1000_pch_lpt:
  1352. case e1000_pch_spt:
  1353. rc = e1000_init_phy_params_pchlan(hw);
  1354. break;
  1355. default:
  1356. break;
  1357. }
  1358. if (rc)
  1359. return rc;
  1360. /* Disable Jumbo Frame support on parts with Intel 10/100 PHY or
  1361. * on parts with MACsec enabled in NVM (reflected in CTRL_EXT).
  1362. */
  1363. if ((adapter->hw.phy.type == e1000_phy_ife) ||
  1364. ((adapter->hw.mac.type >= e1000_pch2lan) &&
  1365. (!(er32(CTRL_EXT) & E1000_CTRL_EXT_LSECCK)))) {
  1366. adapter->flags &= ~FLAG_HAS_JUMBO_FRAMES;
  1367. adapter->max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN;
  1368. hw->mac.ops.blink_led = NULL;
  1369. }
  1370. if ((adapter->hw.mac.type == e1000_ich8lan) &&
  1371. (adapter->hw.phy.type != e1000_phy_ife))
  1372. adapter->flags |= FLAG_LSC_GIG_SPEED_DROP;
  1373. /* Enable workaround for 82579 w/ ME enabled */
  1374. if ((adapter->hw.mac.type == e1000_pch2lan) &&
  1375. (er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
  1376. adapter->flags2 |= FLAG2_PCIM2PCI_ARBITER_WA;
  1377. return 0;
  1378. }
  1379. static DEFINE_MUTEX(nvm_mutex);
  1380. /**
  1381. * e1000_acquire_nvm_ich8lan - Acquire NVM mutex
  1382. * @hw: pointer to the HW structure
  1383. *
  1384. * Acquires the mutex for performing NVM operations.
  1385. **/
  1386. static s32 e1000_acquire_nvm_ich8lan(struct e1000_hw __always_unused *hw)
  1387. {
  1388. mutex_lock(&nvm_mutex);
  1389. return 0;
  1390. }
  1391. /**
  1392. * e1000_release_nvm_ich8lan - Release NVM mutex
  1393. * @hw: pointer to the HW structure
  1394. *
  1395. * Releases the mutex used while performing NVM operations.
  1396. **/
  1397. static void e1000_release_nvm_ich8lan(struct e1000_hw __always_unused *hw)
  1398. {
  1399. mutex_unlock(&nvm_mutex);
  1400. }
  1401. /**
  1402. * e1000_acquire_swflag_ich8lan - Acquire software control flag
  1403. * @hw: pointer to the HW structure
  1404. *
  1405. * Acquires the software control flag for performing PHY and select
  1406. * MAC CSR accesses.
  1407. **/
  1408. static s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
  1409. {
  1410. u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
  1411. s32 ret_val = 0;
  1412. if (test_and_set_bit(__E1000_ACCESS_SHARED_RESOURCE,
  1413. &hw->adapter->state)) {
  1414. e_dbg("contention for Phy access\n");
  1415. return -E1000_ERR_PHY;
  1416. }
  1417. while (timeout) {
  1418. extcnf_ctrl = er32(EXTCNF_CTRL);
  1419. if (!(extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG))
  1420. break;
  1421. mdelay(1);
  1422. timeout--;
  1423. }
  1424. if (!timeout) {
  1425. e_dbg("SW has already locked the resource.\n");
  1426. ret_val = -E1000_ERR_CONFIG;
  1427. goto out;
  1428. }
  1429. timeout = SW_FLAG_TIMEOUT;
  1430. extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
  1431. ew32(EXTCNF_CTRL, extcnf_ctrl);
  1432. while (timeout) {
  1433. extcnf_ctrl = er32(EXTCNF_CTRL);
  1434. if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
  1435. break;
  1436. mdelay(1);
  1437. timeout--;
  1438. }
  1439. if (!timeout) {
  1440. e_dbg("Failed to acquire the semaphore, FW or HW has it: FWSM=0x%8.8x EXTCNF_CTRL=0x%8.8x)\n",
  1441. er32(FWSM), extcnf_ctrl);
  1442. extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
  1443. ew32(EXTCNF_CTRL, extcnf_ctrl);
  1444. ret_val = -E1000_ERR_CONFIG;
  1445. goto out;
  1446. }
  1447. out:
  1448. if (ret_val)
  1449. clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
  1450. return ret_val;
  1451. }
  1452. /**
  1453. * e1000_release_swflag_ich8lan - Release software control flag
  1454. * @hw: pointer to the HW structure
  1455. *
  1456. * Releases the software control flag for performing PHY and select
  1457. * MAC CSR accesses.
  1458. **/
  1459. static void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
  1460. {
  1461. u32 extcnf_ctrl;
  1462. extcnf_ctrl = er32(EXTCNF_CTRL);
  1463. if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG) {
  1464. extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
  1465. ew32(EXTCNF_CTRL, extcnf_ctrl);
  1466. } else {
  1467. e_dbg("Semaphore unexpectedly released by sw/fw/hw\n");
  1468. }
  1469. clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
  1470. }
  1471. /**
  1472. * e1000_check_mng_mode_ich8lan - Checks management mode
  1473. * @hw: pointer to the HW structure
  1474. *
  1475. * This checks if the adapter has any manageability enabled.
  1476. * This is a function pointer entry point only called by read/write
  1477. * routines for the PHY and NVM parts.
  1478. **/
  1479. static bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
  1480. {
  1481. u32 fwsm;
  1482. fwsm = er32(FWSM);
  1483. return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
  1484. ((fwsm & E1000_FWSM_MODE_MASK) ==
  1485. (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
  1486. }
  1487. /**
  1488. * e1000_check_mng_mode_pchlan - Checks management mode
  1489. * @hw: pointer to the HW structure
  1490. *
  1491. * This checks if the adapter has iAMT enabled.
  1492. * This is a function pointer entry point only called by read/write
  1493. * routines for the PHY and NVM parts.
  1494. **/
  1495. static bool e1000_check_mng_mode_pchlan(struct e1000_hw *hw)
  1496. {
  1497. u32 fwsm;
  1498. fwsm = er32(FWSM);
  1499. return (fwsm & E1000_ICH_FWSM_FW_VALID) &&
  1500. (fwsm & (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
  1501. }
  1502. /**
  1503. * e1000_rar_set_pch2lan - Set receive address register
  1504. * @hw: pointer to the HW structure
  1505. * @addr: pointer to the receive address
  1506. * @index: receive address array register
  1507. *
  1508. * Sets the receive address array register at index to the address passed
  1509. * in by addr. For 82579, RAR[0] is the base address register that is to
  1510. * contain the MAC address but RAR[1-6] are reserved for manageability (ME).
  1511. * Use SHRA[0-3] in place of those reserved for ME.
  1512. **/
  1513. static int e1000_rar_set_pch2lan(struct e1000_hw *hw, u8 *addr, u32 index)
  1514. {
  1515. u32 rar_low, rar_high;
  1516. /* HW expects these in little endian so we reverse the byte order
  1517. * from network order (big endian) to little endian
  1518. */
  1519. rar_low = ((u32)addr[0] |
  1520. ((u32)addr[1] << 8) |
  1521. ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
  1522. rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
  1523. /* If MAC address zero, no need to set the AV bit */
  1524. if (rar_low || rar_high)
  1525. rar_high |= E1000_RAH_AV;
  1526. if (index == 0) {
  1527. ew32(RAL(index), rar_low);
  1528. e1e_flush();
  1529. ew32(RAH(index), rar_high);
  1530. e1e_flush();
  1531. return 0;
  1532. }
  1533. /* RAR[1-6] are owned by manageability. Skip those and program the
  1534. * next address into the SHRA register array.
  1535. */
  1536. if (index < (u32)(hw->mac.rar_entry_count)) {
  1537. s32 ret_val;
  1538. ret_val = e1000_acquire_swflag_ich8lan(hw);
  1539. if (ret_val)
  1540. goto out;
  1541. ew32(SHRAL(index - 1), rar_low);
  1542. e1e_flush();
  1543. ew32(SHRAH(index - 1), rar_high);
  1544. e1e_flush();
  1545. e1000_release_swflag_ich8lan(hw);
  1546. /* verify the register updates */
  1547. if ((er32(SHRAL(index - 1)) == rar_low) &&
  1548. (er32(SHRAH(index - 1)) == rar_high))
  1549. return 0;
  1550. e_dbg("SHRA[%d] might be locked by ME - FWSM=0x%8.8x\n",
  1551. (index - 1), er32(FWSM));
  1552. }
  1553. out:
  1554. e_dbg("Failed to write receive address at index %d\n", index);
  1555. return -E1000_ERR_CONFIG;
  1556. }
  1557. /**
  1558. * e1000_rar_get_count_pch_lpt - Get the number of available SHRA
  1559. * @hw: pointer to the HW structure
  1560. *
  1561. * Get the number of available receive registers that the Host can
  1562. * program. SHRA[0-10] are the shared receive address registers
  1563. * that are shared between the Host and manageability engine (ME).
  1564. * ME can reserve any number of addresses and the host needs to be
  1565. * able to tell how many available registers it has access to.
  1566. **/
  1567. static u32 e1000_rar_get_count_pch_lpt(struct e1000_hw *hw)
  1568. {
  1569. u32 wlock_mac;
  1570. u32 num_entries;
  1571. wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
  1572. wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
  1573. switch (wlock_mac) {
  1574. case 0:
  1575. /* All SHRA[0..10] and RAR[0] available */
  1576. num_entries = hw->mac.rar_entry_count;
  1577. break;
  1578. case 1:
  1579. /* Only RAR[0] available */
  1580. num_entries = 1;
  1581. break;
  1582. default:
  1583. /* SHRA[0..(wlock_mac - 1)] available + RAR[0] */
  1584. num_entries = wlock_mac + 1;
  1585. break;
  1586. }
  1587. return num_entries;
  1588. }
  1589. /**
  1590. * e1000_rar_set_pch_lpt - Set receive address registers
  1591. * @hw: pointer to the HW structure
  1592. * @addr: pointer to the receive address
  1593. * @index: receive address array register
  1594. *
  1595. * Sets the receive address register array at index to the address passed
  1596. * in by addr. For LPT, RAR[0] is the base address register that is to
  1597. * contain the MAC address. SHRA[0-10] are the shared receive address
  1598. * registers that are shared between the Host and manageability engine (ME).
  1599. **/
  1600. static int e1000_rar_set_pch_lpt(struct e1000_hw *hw, u8 *addr, u32 index)
  1601. {
  1602. u32 rar_low, rar_high;
  1603. u32 wlock_mac;
  1604. /* HW expects these in little endian so we reverse the byte order
  1605. * from network order (big endian) to little endian
  1606. */
  1607. rar_low = ((u32)addr[0] | ((u32)addr[1] << 8) |
  1608. ((u32)addr[2] << 16) | ((u32)addr[3] << 24));
  1609. rar_high = ((u32)addr[4] | ((u32)addr[5] << 8));
  1610. /* If MAC address zero, no need to set the AV bit */
  1611. if (rar_low || rar_high)
  1612. rar_high |= E1000_RAH_AV;
  1613. if (index == 0) {
  1614. ew32(RAL(index), rar_low);
  1615. e1e_flush();
  1616. ew32(RAH(index), rar_high);
  1617. e1e_flush();
  1618. return 0;
  1619. }
  1620. /* The manageability engine (ME) can lock certain SHRAR registers that
  1621. * it is using - those registers are unavailable for use.
  1622. */
  1623. if (index < hw->mac.rar_entry_count) {
  1624. wlock_mac = er32(FWSM) & E1000_FWSM_WLOCK_MAC_MASK;
  1625. wlock_mac >>= E1000_FWSM_WLOCK_MAC_SHIFT;
  1626. /* Check if all SHRAR registers are locked */
  1627. if (wlock_mac == 1)
  1628. goto out;
  1629. if ((wlock_mac == 0) || (index <= wlock_mac)) {
  1630. s32 ret_val;
  1631. ret_val = e1000_acquire_swflag_ich8lan(hw);
  1632. if (ret_val)
  1633. goto out;
  1634. ew32(SHRAL_PCH_LPT(index - 1), rar_low);
  1635. e1e_flush();
  1636. ew32(SHRAH_PCH_LPT(index - 1), rar_high);
  1637. e1e_flush();
  1638. e1000_release_swflag_ich8lan(hw);
  1639. /* verify the register updates */
  1640. if ((er32(SHRAL_PCH_LPT(index - 1)) == rar_low) &&
  1641. (er32(SHRAH_PCH_LPT(index - 1)) == rar_high))
  1642. return 0;
  1643. }
  1644. }
  1645. out:
  1646. e_dbg("Failed to write receive address at index %d\n", index);
  1647. return -E1000_ERR_CONFIG;
  1648. }
  1649. /**
  1650. * e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
  1651. * @hw: pointer to the HW structure
  1652. *
  1653. * Checks if firmware is blocking the reset of the PHY.
  1654. * This is a function pointer entry point only called by
  1655. * reset routines.
  1656. **/
  1657. static s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
  1658. {
  1659. bool blocked = false;
  1660. int i = 0;
  1661. while ((blocked = !(er32(FWSM) & E1000_ICH_FWSM_RSPCIPHY)) &&
  1662. (i++ < 10))
  1663. usleep_range(10000, 20000);
  1664. return blocked ? E1000_BLK_PHY_RESET : 0;
  1665. }
  1666. /**
  1667. * e1000_write_smbus_addr - Write SMBus address to PHY needed during Sx states
  1668. * @hw: pointer to the HW structure
  1669. *
  1670. * Assumes semaphore already acquired.
  1671. *
  1672. **/
  1673. static s32 e1000_write_smbus_addr(struct e1000_hw *hw)
  1674. {
  1675. u16 phy_data;
  1676. u32 strap = er32(STRAP);
  1677. u32 freq = (strap & E1000_STRAP_SMT_FREQ_MASK) >>
  1678. E1000_STRAP_SMT_FREQ_SHIFT;
  1679. s32 ret_val;
  1680. strap &= E1000_STRAP_SMBUS_ADDRESS_MASK;
  1681. ret_val = e1000_read_phy_reg_hv_locked(hw, HV_SMB_ADDR, &phy_data);
  1682. if (ret_val)
  1683. return ret_val;
  1684. phy_data &= ~HV_SMB_ADDR_MASK;
  1685. phy_data |= (strap >> E1000_STRAP_SMBUS_ADDRESS_SHIFT);
  1686. phy_data |= HV_SMB_ADDR_PEC_EN | HV_SMB_ADDR_VALID;
  1687. if (hw->phy.type == e1000_phy_i217) {
  1688. /* Restore SMBus frequency */
  1689. if (freq--) {
  1690. phy_data &= ~HV_SMB_ADDR_FREQ_MASK;
  1691. phy_data |= (freq & (1 << 0)) <<
  1692. HV_SMB_ADDR_FREQ_LOW_SHIFT;
  1693. phy_data |= (freq & (1 << 1)) <<
  1694. (HV_SMB_ADDR_FREQ_HIGH_SHIFT - 1);
  1695. } else {
  1696. e_dbg("Unsupported SMB frequency in PHY\n");
  1697. }
  1698. }
  1699. return e1000_write_phy_reg_hv_locked(hw, HV_SMB_ADDR, phy_data);
  1700. }
  1701. /**
  1702. * e1000_sw_lcd_config_ich8lan - SW-based LCD Configuration
  1703. * @hw: pointer to the HW structure
  1704. *
  1705. * SW should configure the LCD from the NVM extended configuration region
  1706. * as a workaround for certain parts.
  1707. **/
  1708. static s32 e1000_sw_lcd_config_ich8lan(struct e1000_hw *hw)
  1709. {
  1710. struct e1000_phy_info *phy = &hw->phy;
  1711. u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
  1712. s32 ret_val = 0;
  1713. u16 word_addr, reg_data, reg_addr, phy_page = 0;
  1714. /* Initialize the PHY from the NVM on ICH platforms. This
  1715. * is needed due to an issue where the NVM configuration is
  1716. * not properly autoloaded after power transitions.
  1717. * Therefore, after each PHY reset, we will load the
  1718. * configuration data out of the NVM manually.
  1719. */
  1720. switch (hw->mac.type) {
  1721. case e1000_ich8lan:
  1722. if (phy->type != e1000_phy_igp_3)
  1723. return ret_val;
  1724. if ((hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_AMT) ||
  1725. (hw->adapter->pdev->device == E1000_DEV_ID_ICH8_IGP_C)) {
  1726. sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
  1727. break;
  1728. }
  1729. /* Fall-thru */
  1730. case e1000_pchlan:
  1731. case e1000_pch2lan:
  1732. case e1000_pch_lpt:
  1733. case e1000_pch_spt:
  1734. sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
  1735. break;
  1736. default:
  1737. return ret_val;
  1738. }
  1739. ret_val = hw->phy.ops.acquire(hw);
  1740. if (ret_val)
  1741. return ret_val;
  1742. data = er32(FEXTNVM);
  1743. if (!(data & sw_cfg_mask))
  1744. goto release;
  1745. /* Make sure HW does not configure LCD from PHY
  1746. * extended configuration before SW configuration
  1747. */
  1748. data = er32(EXTCNF_CTRL);
  1749. if ((hw->mac.type < e1000_pch2lan) &&
  1750. (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE))
  1751. goto release;
  1752. cnf_size = er32(EXTCNF_SIZE);
  1753. cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
  1754. cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
  1755. if (!cnf_size)
  1756. goto release;
  1757. cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
  1758. cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
  1759. if (((hw->mac.type == e1000_pchlan) &&
  1760. !(data & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)) ||
  1761. (hw->mac.type > e1000_pchlan)) {
  1762. /* HW configures the SMBus address and LEDs when the
  1763. * OEM and LCD Write Enable bits are set in the NVM.
  1764. * When both NVM bits are cleared, SW will configure
  1765. * them instead.
  1766. */
  1767. ret_val = e1000_write_smbus_addr(hw);
  1768. if (ret_val)
  1769. goto release;
  1770. data = er32(LEDCTL);
  1771. ret_val = e1000_write_phy_reg_hv_locked(hw, HV_LED_CONFIG,
  1772. (u16)data);
  1773. if (ret_val)
  1774. goto release;
  1775. }
  1776. /* Configure LCD from extended configuration region. */
  1777. /* cnf_base_addr is in DWORD */
  1778. word_addr = (u16)(cnf_base_addr << 1);
  1779. for (i = 0; i < cnf_size; i++) {
  1780. ret_val = e1000_read_nvm(hw, (word_addr + i * 2), 1, &reg_data);
  1781. if (ret_val)
  1782. goto release;
  1783. ret_val = e1000_read_nvm(hw, (word_addr + i * 2 + 1),
  1784. 1, &reg_addr);
  1785. if (ret_val)
  1786. goto release;
  1787. /* Save off the PHY page for future writes. */
  1788. if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
  1789. phy_page = reg_data;
  1790. continue;
  1791. }
  1792. reg_addr &= PHY_REG_MASK;
  1793. reg_addr |= phy_page;
  1794. ret_val = e1e_wphy_locked(hw, (u32)reg_addr, reg_data);
  1795. if (ret_val)
  1796. goto release;
  1797. }
  1798. release:
  1799. hw->phy.ops.release(hw);
  1800. return ret_val;
  1801. }
  1802. /**
  1803. * e1000_k1_gig_workaround_hv - K1 Si workaround
  1804. * @hw: pointer to the HW structure
  1805. * @link: link up bool flag
  1806. *
  1807. * If K1 is enabled for 1Gbps, the MAC might stall when transitioning
  1808. * from a lower speed. This workaround disables K1 whenever link is at 1Gig
  1809. * If link is down, the function will restore the default K1 setting located
  1810. * in the NVM.
  1811. **/
  1812. static s32 e1000_k1_gig_workaround_hv(struct e1000_hw *hw, bool link)
  1813. {
  1814. s32 ret_val = 0;
  1815. u16 status_reg = 0;
  1816. bool k1_enable = hw->dev_spec.ich8lan.nvm_k1_enabled;
  1817. if (hw->mac.type != e1000_pchlan)
  1818. return 0;
  1819. /* Wrap the whole flow with the sw flag */
  1820. ret_val = hw->phy.ops.acquire(hw);
  1821. if (ret_val)
  1822. return ret_val;
  1823. /* Disable K1 when link is 1Gbps, otherwise use the NVM setting */
  1824. if (link) {
  1825. if (hw->phy.type == e1000_phy_82578) {
  1826. ret_val = e1e_rphy_locked(hw, BM_CS_STATUS,
  1827. &status_reg);
  1828. if (ret_val)
  1829. goto release;
  1830. status_reg &= (BM_CS_STATUS_LINK_UP |
  1831. BM_CS_STATUS_RESOLVED |
  1832. BM_CS_STATUS_SPEED_MASK);
  1833. if (status_reg == (BM_CS_STATUS_LINK_UP |
  1834. BM_CS_STATUS_RESOLVED |
  1835. BM_CS_STATUS_SPEED_1000))
  1836. k1_enable = false;
  1837. }
  1838. if (hw->phy.type == e1000_phy_82577) {
  1839. ret_val = e1e_rphy_locked(hw, HV_M_STATUS, &status_reg);
  1840. if (ret_val)
  1841. goto release;
  1842. status_reg &= (HV_M_STATUS_LINK_UP |
  1843. HV_M_STATUS_AUTONEG_COMPLETE |
  1844. HV_M_STATUS_SPEED_MASK);
  1845. if (status_reg == (HV_M_STATUS_LINK_UP |
  1846. HV_M_STATUS_AUTONEG_COMPLETE |
  1847. HV_M_STATUS_SPEED_1000))
  1848. k1_enable = false;
  1849. }
  1850. /* Link stall fix for link up */
  1851. ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x0100);
  1852. if (ret_val)
  1853. goto release;
  1854. } else {
  1855. /* Link stall fix for link down */
  1856. ret_val = e1e_wphy_locked(hw, PHY_REG(770, 19), 0x4100);
  1857. if (ret_val)
  1858. goto release;
  1859. }
  1860. ret_val = e1000_configure_k1_ich8lan(hw, k1_enable);
  1861. release:
  1862. hw->phy.ops.release(hw);
  1863. return ret_val;
  1864. }
  1865. /**
  1866. * e1000_configure_k1_ich8lan - Configure K1 power state
  1867. * @hw: pointer to the HW structure
  1868. * @enable: K1 state to configure
  1869. *
  1870. * Configure the K1 power state based on the provided parameter.
  1871. * Assumes semaphore already acquired.
  1872. *
  1873. * Success returns 0, Failure returns -E1000_ERR_PHY (-2)
  1874. **/
  1875. s32 e1000_configure_k1_ich8lan(struct e1000_hw *hw, bool k1_enable)
  1876. {
  1877. s32 ret_val;
  1878. u32 ctrl_reg = 0;
  1879. u32 ctrl_ext = 0;
  1880. u32 reg = 0;
  1881. u16 kmrn_reg = 0;
  1882. ret_val = e1000e_read_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
  1883. &kmrn_reg);
  1884. if (ret_val)
  1885. return ret_val;
  1886. if (k1_enable)
  1887. kmrn_reg |= E1000_KMRNCTRLSTA_K1_ENABLE;
  1888. else
  1889. kmrn_reg &= ~E1000_KMRNCTRLSTA_K1_ENABLE;
  1890. ret_val = e1000e_write_kmrn_reg_locked(hw, E1000_KMRNCTRLSTA_K1_CONFIG,
  1891. kmrn_reg);
  1892. if (ret_val)
  1893. return ret_val;
  1894. usleep_range(20, 40);
  1895. ctrl_ext = er32(CTRL_EXT);
  1896. ctrl_reg = er32(CTRL);
  1897. reg = ctrl_reg & ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
  1898. reg |= E1000_CTRL_FRCSPD;
  1899. ew32(CTRL, reg);
  1900. ew32(CTRL_EXT, ctrl_ext | E1000_CTRL_EXT_SPD_BYPS);
  1901. e1e_flush();
  1902. usleep_range(20, 40);
  1903. ew32(CTRL, ctrl_reg);
  1904. ew32(CTRL_EXT, ctrl_ext);
  1905. e1e_flush();
  1906. usleep_range(20, 40);
  1907. return 0;
  1908. }
  1909. /**
  1910. * e1000_oem_bits_config_ich8lan - SW-based LCD Configuration
  1911. * @hw: pointer to the HW structure
  1912. * @d0_state: boolean if entering d0 or d3 device state
  1913. *
  1914. * SW will configure Gbe Disable and LPLU based on the NVM. The four bits are
  1915. * collectively called OEM bits. The OEM Write Enable bit and SW Config bit
  1916. * in NVM determines whether HW should configure LPLU and Gbe Disable.
  1917. **/
  1918. static s32 e1000_oem_bits_config_ich8lan(struct e1000_hw *hw, bool d0_state)
  1919. {
  1920. s32 ret_val = 0;
  1921. u32 mac_reg;
  1922. u16 oem_reg;
  1923. if (hw->mac.type < e1000_pchlan)
  1924. return ret_val;
  1925. ret_val = hw->phy.ops.acquire(hw);
  1926. if (ret_val)
  1927. return ret_val;
  1928. if (hw->mac.type == e1000_pchlan) {
  1929. mac_reg = er32(EXTCNF_CTRL);
  1930. if (mac_reg & E1000_EXTCNF_CTRL_OEM_WRITE_ENABLE)
  1931. goto release;
  1932. }
  1933. mac_reg = er32(FEXTNVM);
  1934. if (!(mac_reg & E1000_FEXTNVM_SW_CONFIG_ICH8M))
  1935. goto release;
  1936. mac_reg = er32(PHY_CTRL);
  1937. ret_val = e1e_rphy_locked(hw, HV_OEM_BITS, &oem_reg);
  1938. if (ret_val)
  1939. goto release;
  1940. oem_reg &= ~(HV_OEM_BITS_GBE_DIS | HV_OEM_BITS_LPLU);
  1941. if (d0_state) {
  1942. if (mac_reg & E1000_PHY_CTRL_GBE_DISABLE)
  1943. oem_reg |= HV_OEM_BITS_GBE_DIS;
  1944. if (mac_reg & E1000_PHY_CTRL_D0A_LPLU)
  1945. oem_reg |= HV_OEM_BITS_LPLU;
  1946. } else {
  1947. if (mac_reg & (E1000_PHY_CTRL_GBE_DISABLE |
  1948. E1000_PHY_CTRL_NOND0A_GBE_DISABLE))
  1949. oem_reg |= HV_OEM_BITS_GBE_DIS;
  1950. if (mac_reg & (E1000_PHY_CTRL_D0A_LPLU |
  1951. E1000_PHY_CTRL_NOND0A_LPLU))
  1952. oem_reg |= HV_OEM_BITS_LPLU;
  1953. }
  1954. /* Set Restart auto-neg to activate the bits */
  1955. if ((d0_state || (hw->mac.type != e1000_pchlan)) &&
  1956. !hw->phy.ops.check_reset_block(hw))
  1957. oem_reg |= HV_OEM_BITS_RESTART_AN;
  1958. ret_val = e1e_wphy_locked(hw, HV_OEM_BITS, oem_reg);
  1959. release:
  1960. hw->phy.ops.release(hw);
  1961. return ret_val;
  1962. }
  1963. /**
  1964. * e1000_set_mdio_slow_mode_hv - Set slow MDIO access mode
  1965. * @hw: pointer to the HW structure
  1966. **/
  1967. static s32 e1000_set_mdio_slow_mode_hv(struct e1000_hw *hw)
  1968. {
  1969. s32 ret_val;
  1970. u16 data;
  1971. ret_val = e1e_rphy(hw, HV_KMRN_MODE_CTRL, &data);
  1972. if (ret_val)
  1973. return ret_val;
  1974. data |= HV_KMRN_MDIO_SLOW;
  1975. ret_val = e1e_wphy(hw, HV_KMRN_MODE_CTRL, data);
  1976. return ret_val;
  1977. }
  1978. /**
  1979. * e1000_hv_phy_workarounds_ich8lan - A series of Phy workarounds to be
  1980. * done after every PHY reset.
  1981. **/
  1982. static s32 e1000_hv_phy_workarounds_ich8lan(struct e1000_hw *hw)
  1983. {
  1984. s32 ret_val = 0;
  1985. u16 phy_data;
  1986. if (hw->mac.type != e1000_pchlan)
  1987. return 0;
  1988. /* Set MDIO slow mode before any other MDIO access */
  1989. if (hw->phy.type == e1000_phy_82577) {
  1990. ret_val = e1000_set_mdio_slow_mode_hv(hw);
  1991. if (ret_val)
  1992. return ret_val;
  1993. }
  1994. if (((hw->phy.type == e1000_phy_82577) &&
  1995. ((hw->phy.revision == 1) || (hw->phy.revision == 2))) ||
  1996. ((hw->phy.type == e1000_phy_82578) && (hw->phy.revision == 1))) {
  1997. /* Disable generation of early preamble */
  1998. ret_val = e1e_wphy(hw, PHY_REG(769, 25), 0x4431);
  1999. if (ret_val)
  2000. return ret_val;
  2001. /* Preamble tuning for SSC */
  2002. ret_val = e1e_wphy(hw, HV_KMRN_FIFO_CTRLSTA, 0xA204);
  2003. if (ret_val)
  2004. return ret_val;
  2005. }
  2006. if (hw->phy.type == e1000_phy_82578) {
  2007. /* Return registers to default by doing a soft reset then
  2008. * writing 0x3140 to the control register.
  2009. */
  2010. if (hw->phy.revision < 2) {
  2011. e1000e_phy_sw_reset(hw);
  2012. ret_val = e1e_wphy(hw, MII_BMCR, 0x3140);
  2013. }
  2014. }
  2015. /* Select page 0 */
  2016. ret_val = hw->phy.ops.acquire(hw);
  2017. if (ret_val)
  2018. return ret_val;
  2019. hw->phy.addr = 1;
  2020. ret_val = e1000e_write_phy_reg_mdic(hw, IGP01E1000_PHY_PAGE_SELECT, 0);
  2021. hw->phy.ops.release(hw);
  2022. if (ret_val)
  2023. return ret_val;
  2024. /* Configure the K1 Si workaround during phy reset assuming there is
  2025. * link so that it disables K1 if link is in 1Gbps.
  2026. */
  2027. ret_val = e1000_k1_gig_workaround_hv(hw, true);
  2028. if (ret_val)
  2029. return ret_val;
  2030. /* Workaround for link disconnects on a busy hub in half duplex */
  2031. ret_val = hw->phy.ops.acquire(hw);
  2032. if (ret_val)
  2033. return ret_val;
  2034. ret_val = e1e_rphy_locked(hw, BM_PORT_GEN_CFG, &phy_data);
  2035. if (ret_val)
  2036. goto release;
  2037. ret_val = e1e_wphy_locked(hw, BM_PORT_GEN_CFG, phy_data & 0x00FF);
  2038. if (ret_val)
  2039. goto release;
  2040. /* set MSE higher to enable link to stay up when noise is high */
  2041. ret_val = e1000_write_emi_reg_locked(hw, I82577_MSE_THRESHOLD, 0x0034);
  2042. release:
  2043. hw->phy.ops.release(hw);
  2044. return ret_val;
  2045. }
  2046. /**
  2047. * e1000_copy_rx_addrs_to_phy_ich8lan - Copy Rx addresses from MAC to PHY
  2048. * @hw: pointer to the HW structure
  2049. **/
  2050. void e1000_copy_rx_addrs_to_phy_ich8lan(struct e1000_hw *hw)
  2051. {
  2052. u32 mac_reg;
  2053. u16 i, phy_reg = 0;
  2054. s32 ret_val;
  2055. ret_val = hw->phy.ops.acquire(hw);
  2056. if (ret_val)
  2057. return;
  2058. ret_val = e1000_enable_phy_wakeup_reg_access_bm(hw, &phy_reg);
  2059. if (ret_val)
  2060. goto release;
  2061. /* Copy both RAL/H (rar_entry_count) and SHRAL/H to PHY */
  2062. for (i = 0; i < (hw->mac.rar_entry_count); i++) {
  2063. mac_reg = er32(RAL(i));
  2064. hw->phy.ops.write_reg_page(hw, BM_RAR_L(i),
  2065. (u16)(mac_reg & 0xFFFF));
  2066. hw->phy.ops.write_reg_page(hw, BM_RAR_M(i),
  2067. (u16)((mac_reg >> 16) & 0xFFFF));
  2068. mac_reg = er32(RAH(i));
  2069. hw->phy.ops.write_reg_page(hw, BM_RAR_H(i),
  2070. (u16)(mac_reg & 0xFFFF));
  2071. hw->phy.ops.write_reg_page(hw, BM_RAR_CTRL(i),
  2072. (u16)((mac_reg & E1000_RAH_AV)
  2073. >> 16));
  2074. }
  2075. e1000_disable_phy_wakeup_reg_access_bm(hw, &phy_reg);
  2076. release:
  2077. hw->phy.ops.release(hw);
  2078. }
  2079. /**
  2080. * e1000_lv_jumbo_workaround_ich8lan - required for jumbo frame operation
  2081. * with 82579 PHY
  2082. * @hw: pointer to the HW structure
  2083. * @enable: flag to enable/disable workaround when enabling/disabling jumbos
  2084. **/
  2085. s32 e1000_lv_jumbo_workaround_ich8lan(struct e1000_hw *hw, bool enable)
  2086. {
  2087. s32 ret_val = 0;
  2088. u16 phy_reg, data;
  2089. u32 mac_reg;
  2090. u16 i;
  2091. if (hw->mac.type < e1000_pch2lan)
  2092. return 0;
  2093. /* disable Rx path while enabling/disabling workaround */
  2094. e1e_rphy(hw, PHY_REG(769, 20), &phy_reg);
  2095. ret_val = e1e_wphy(hw, PHY_REG(769, 20), phy_reg | (1 << 14));
  2096. if (ret_val)
  2097. return ret_val;
  2098. if (enable) {
  2099. /* Write Rx addresses (rar_entry_count for RAL/H, and
  2100. * SHRAL/H) and initial CRC values to the MAC
  2101. */
  2102. for (i = 0; i < hw->mac.rar_entry_count; i++) {
  2103. u8 mac_addr[ETH_ALEN] = { 0 };
  2104. u32 addr_high, addr_low;
  2105. addr_high = er32(RAH(i));
  2106. if (!(addr_high & E1000_RAH_AV))
  2107. continue;
  2108. addr_low = er32(RAL(i));
  2109. mac_addr[0] = (addr_low & 0xFF);
  2110. mac_addr[1] = ((addr_low >> 8) & 0xFF);
  2111. mac_addr[2] = ((addr_low >> 16) & 0xFF);
  2112. mac_addr[3] = ((addr_low >> 24) & 0xFF);
  2113. mac_addr[4] = (addr_high & 0xFF);
  2114. mac_addr[5] = ((addr_high >> 8) & 0xFF);
  2115. ew32(PCH_RAICC(i), ~ether_crc_le(ETH_ALEN, mac_addr));
  2116. }
  2117. /* Write Rx addresses to the PHY */
  2118. e1000_copy_rx_addrs_to_phy_ich8lan(hw);
  2119. /* Enable jumbo frame workaround in the MAC */
  2120. mac_reg = er32(FFLT_DBG);
  2121. mac_reg &= ~(1 << 14);
  2122. mac_reg |= (7 << 15);
  2123. ew32(FFLT_DBG, mac_reg);
  2124. mac_reg = er32(RCTL);
  2125. mac_reg |= E1000_RCTL_SECRC;
  2126. ew32(RCTL, mac_reg);
  2127. ret_val = e1000e_read_kmrn_reg(hw,
  2128. E1000_KMRNCTRLSTA_CTRL_OFFSET,
  2129. &data);
  2130. if (ret_val)
  2131. return ret_val;
  2132. ret_val = e1000e_write_kmrn_reg(hw,
  2133. E1000_KMRNCTRLSTA_CTRL_OFFSET,
  2134. data | (1 << 0));
  2135. if (ret_val)
  2136. return ret_val;
  2137. ret_val = e1000e_read_kmrn_reg(hw,
  2138. E1000_KMRNCTRLSTA_HD_CTRL,
  2139. &data);
  2140. if (ret_val)
  2141. return ret_val;
  2142. data &= ~(0xF << 8);
  2143. data |= (0xB << 8);
  2144. ret_val = e1000e_write_kmrn_reg(hw,
  2145. E1000_KMRNCTRLSTA_HD_CTRL,
  2146. data);
  2147. if (ret_val)
  2148. return ret_val;
  2149. /* Enable jumbo frame workaround in the PHY */
  2150. e1e_rphy(hw, PHY_REG(769, 23), &data);
  2151. data &= ~(0x7F << 5);
  2152. data |= (0x37 << 5);
  2153. ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
  2154. if (ret_val)
  2155. return ret_val;
  2156. e1e_rphy(hw, PHY_REG(769, 16), &data);
  2157. data &= ~(1 << 13);
  2158. ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
  2159. if (ret_val)
  2160. return ret_val;
  2161. e1e_rphy(hw, PHY_REG(776, 20), &data);
  2162. data &= ~(0x3FF << 2);
  2163. data |= (E1000_TX_PTR_GAP << 2);
  2164. ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
  2165. if (ret_val)
  2166. return ret_val;
  2167. ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0xF100);
  2168. if (ret_val)
  2169. return ret_val;
  2170. e1e_rphy(hw, HV_PM_CTRL, &data);
  2171. ret_val = e1e_wphy(hw, HV_PM_CTRL, data | (1 << 10));
  2172. if (ret_val)
  2173. return ret_val;
  2174. } else {
  2175. /* Write MAC register values back to h/w defaults */
  2176. mac_reg = er32(FFLT_DBG);
  2177. mac_reg &= ~(0xF << 14);
  2178. ew32(FFLT_DBG, mac_reg);
  2179. mac_reg = er32(RCTL);
  2180. mac_reg &= ~E1000_RCTL_SECRC;
  2181. ew32(RCTL, mac_reg);
  2182. ret_val = e1000e_read_kmrn_reg(hw,
  2183. E1000_KMRNCTRLSTA_CTRL_OFFSET,
  2184. &data);
  2185. if (ret_val)
  2186. return ret_val;
  2187. ret_val = e1000e_write_kmrn_reg(hw,
  2188. E1000_KMRNCTRLSTA_CTRL_OFFSET,
  2189. data & ~(1 << 0));
  2190. if (ret_val)
  2191. return ret_val;
  2192. ret_val = e1000e_read_kmrn_reg(hw,
  2193. E1000_KMRNCTRLSTA_HD_CTRL,
  2194. &data);
  2195. if (ret_val)
  2196. return ret_val;
  2197. data &= ~(0xF << 8);
  2198. data |= (0xB << 8);
  2199. ret_val = e1000e_write_kmrn_reg(hw,
  2200. E1000_KMRNCTRLSTA_HD_CTRL,
  2201. data);
  2202. if (ret_val)
  2203. return ret_val;
  2204. /* Write PHY register values back to h/w defaults */
  2205. e1e_rphy(hw, PHY_REG(769, 23), &data);
  2206. data &= ~(0x7F << 5);
  2207. ret_val = e1e_wphy(hw, PHY_REG(769, 23), data);
  2208. if (ret_val)
  2209. return ret_val;
  2210. e1e_rphy(hw, PHY_REG(769, 16), &data);
  2211. data |= (1 << 13);
  2212. ret_val = e1e_wphy(hw, PHY_REG(769, 16), data);
  2213. if (ret_val)
  2214. return ret_val;
  2215. e1e_rphy(hw, PHY_REG(776, 20), &data);
  2216. data &= ~(0x3FF << 2);
  2217. data |= (0x8 << 2);
  2218. ret_val = e1e_wphy(hw, PHY_REG(776, 20), data);
  2219. if (ret_val)
  2220. return ret_val;
  2221. ret_val = e1e_wphy(hw, PHY_REG(776, 23), 0x7E00);
  2222. if (ret_val)
  2223. return ret_val;
  2224. e1e_rphy(hw, HV_PM_CTRL, &data);
  2225. ret_val = e1e_wphy(hw, HV_PM_CTRL, data & ~(1 << 10));
  2226. if (ret_val)
  2227. return ret_val;
  2228. }
  2229. /* re-enable Rx path after enabling/disabling workaround */
  2230. return e1e_wphy(hw, PHY_REG(769, 20), phy_reg & ~(1 << 14));
  2231. }
  2232. /**
  2233. * e1000_lv_phy_workarounds_ich8lan - A series of Phy workarounds to be
  2234. * done after every PHY reset.
  2235. **/
  2236. static s32 e1000_lv_phy_workarounds_ich8lan(struct e1000_hw *hw)
  2237. {
  2238. s32 ret_val = 0;
  2239. if (hw->mac.type != e1000_pch2lan)
  2240. return 0;
  2241. /* Set MDIO slow mode before any other MDIO access */
  2242. ret_val = e1000_set_mdio_slow_mode_hv(hw);
  2243. if (ret_val)
  2244. return ret_val;
  2245. ret_val = hw->phy.ops.acquire(hw);
  2246. if (ret_val)
  2247. return ret_val;
  2248. /* set MSE higher to enable link to stay up when noise is high */
  2249. ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_THRESHOLD, 0x0034);
  2250. if (ret_val)
  2251. goto release;
  2252. /* drop link after 5 times MSE threshold was reached */
  2253. ret_val = e1000_write_emi_reg_locked(hw, I82579_MSE_LINK_DOWN, 0x0005);
  2254. release:
  2255. hw->phy.ops.release(hw);
  2256. return ret_val;
  2257. }
  2258. /**
  2259. * e1000_k1_gig_workaround_lv - K1 Si workaround
  2260. * @hw: pointer to the HW structure
  2261. *
  2262. * Workaround to set the K1 beacon duration for 82579 parts in 10Mbps
  2263. * Disable K1 in 1000Mbps and 100Mbps
  2264. **/
  2265. static s32 e1000_k1_workaround_lv(struct e1000_hw *hw)
  2266. {
  2267. s32 ret_val = 0;
  2268. u16 status_reg = 0;
  2269. if (hw->mac.type != e1000_pch2lan)
  2270. return 0;
  2271. /* Set K1 beacon duration based on 10Mbs speed */
  2272. ret_val = e1e_rphy(hw, HV_M_STATUS, &status_reg);
  2273. if (ret_val)
  2274. return ret_val;
  2275. if ((status_reg & (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE))
  2276. == (HV_M_STATUS_LINK_UP | HV_M_STATUS_AUTONEG_COMPLETE)) {
  2277. if (status_reg &
  2278. (HV_M_STATUS_SPEED_1000 | HV_M_STATUS_SPEED_100)) {
  2279. u16 pm_phy_reg;
  2280. /* LV 1G/100 Packet drop issue wa */
  2281. ret_val = e1e_rphy(hw, HV_PM_CTRL, &pm_phy_reg);
  2282. if (ret_val)
  2283. return ret_val;
  2284. pm_phy_reg &= ~HV_PM_CTRL_K1_ENABLE;
  2285. ret_val = e1e_wphy(hw, HV_PM_CTRL, pm_phy_reg);
  2286. if (ret_val)
  2287. return ret_val;
  2288. } else {
  2289. u32 mac_reg;
  2290. mac_reg = er32(FEXTNVM4);
  2291. mac_reg &= ~E1000_FEXTNVM4_BEACON_DURATION_MASK;
  2292. mac_reg |= E1000_FEXTNVM4_BEACON_DURATION_16USEC;
  2293. ew32(FEXTNVM4, mac_reg);
  2294. }
  2295. }
  2296. return ret_val;
  2297. }
  2298. /**
  2299. * e1000_gate_hw_phy_config_ich8lan - disable PHY config via hardware
  2300. * @hw: pointer to the HW structure
  2301. * @gate: boolean set to true to gate, false to ungate
  2302. *
  2303. * Gate/ungate the automatic PHY configuration via hardware; perform
  2304. * the configuration via software instead.
  2305. **/
  2306. static void e1000_gate_hw_phy_config_ich8lan(struct e1000_hw *hw, bool gate)
  2307. {
  2308. u32 extcnf_ctrl;
  2309. if (hw->mac.type < e1000_pch2lan)
  2310. return;
  2311. extcnf_ctrl = er32(EXTCNF_CTRL);
  2312. if (gate)
  2313. extcnf_ctrl |= E1000_EXTCNF_CTRL_GATE_PHY_CFG;
  2314. else
  2315. extcnf_ctrl &= ~E1000_EXTCNF_CTRL_GATE_PHY_CFG;
  2316. ew32(EXTCNF_CTRL, extcnf_ctrl);
  2317. }
  2318. /**
  2319. * e1000_lan_init_done_ich8lan - Check for PHY config completion
  2320. * @hw: pointer to the HW structure
  2321. *
  2322. * Check the appropriate indication the MAC has finished configuring the
  2323. * PHY after a software reset.
  2324. **/
  2325. static void e1000_lan_init_done_ich8lan(struct e1000_hw *hw)
  2326. {
  2327. u32 data, loop = E1000_ICH8_LAN_INIT_TIMEOUT;
  2328. /* Wait for basic configuration completes before proceeding */
  2329. do {
  2330. data = er32(STATUS);
  2331. data &= E1000_STATUS_LAN_INIT_DONE;
  2332. usleep_range(100, 200);
  2333. } while ((!data) && --loop);
  2334. /* If basic configuration is incomplete before the above loop
  2335. * count reaches 0, loading the configuration from NVM will
  2336. * leave the PHY in a bad state possibly resulting in no link.
  2337. */
  2338. if (loop == 0)
  2339. e_dbg("LAN_INIT_DONE not set, increase timeout\n");
  2340. /* Clear the Init Done bit for the next init event */
  2341. data = er32(STATUS);
  2342. data &= ~E1000_STATUS_LAN_INIT_DONE;
  2343. ew32(STATUS, data);
  2344. }
  2345. /**
  2346. * e1000_post_phy_reset_ich8lan - Perform steps required after a PHY reset
  2347. * @hw: pointer to the HW structure
  2348. **/
  2349. static s32 e1000_post_phy_reset_ich8lan(struct e1000_hw *hw)
  2350. {
  2351. s32 ret_val = 0;
  2352. u16 reg;
  2353. if (hw->phy.ops.check_reset_block(hw))
  2354. return 0;
  2355. /* Allow time for h/w to get to quiescent state after reset */
  2356. usleep_range(10000, 20000);
  2357. /* Perform any necessary post-reset workarounds */
  2358. switch (hw->mac.type) {
  2359. case e1000_pchlan:
  2360. ret_val = e1000_hv_phy_workarounds_ich8lan(hw);
  2361. if (ret_val)
  2362. return ret_val;
  2363. break;
  2364. case e1000_pch2lan:
  2365. ret_val = e1000_lv_phy_workarounds_ich8lan(hw);
  2366. if (ret_val)
  2367. return ret_val;
  2368. break;
  2369. default:
  2370. break;
  2371. }
  2372. /* Clear the host wakeup bit after lcd reset */
  2373. if (hw->mac.type >= e1000_pchlan) {
  2374. e1e_rphy(hw, BM_PORT_GEN_CFG, &reg);
  2375. reg &= ~BM_WUC_HOST_WU_BIT;
  2376. e1e_wphy(hw, BM_PORT_GEN_CFG, reg);
  2377. }
  2378. /* Configure the LCD with the extended configuration region in NVM */
  2379. ret_val = e1000_sw_lcd_config_ich8lan(hw);
  2380. if (ret_val)
  2381. return ret_val;
  2382. /* Configure the LCD with the OEM bits in NVM */
  2383. ret_val = e1000_oem_bits_config_ich8lan(hw, true);
  2384. if (hw->mac.type == e1000_pch2lan) {
  2385. /* Ungate automatic PHY configuration on non-managed 82579 */
  2386. if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
  2387. usleep_range(10000, 20000);
  2388. e1000_gate_hw_phy_config_ich8lan(hw, false);
  2389. }
  2390. /* Set EEE LPI Update Timer to 200usec */
  2391. ret_val = hw->phy.ops.acquire(hw);
  2392. if (ret_val)
  2393. return ret_val;
  2394. ret_val = e1000_write_emi_reg_locked(hw,
  2395. I82579_LPI_UPDATE_TIMER,
  2396. 0x1387);
  2397. hw->phy.ops.release(hw);
  2398. }
  2399. return ret_val;
  2400. }
  2401. /**
  2402. * e1000_phy_hw_reset_ich8lan - Performs a PHY reset
  2403. * @hw: pointer to the HW structure
  2404. *
  2405. * Resets the PHY
  2406. * This is a function pointer entry point called by drivers
  2407. * or other shared routines.
  2408. **/
  2409. static s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
  2410. {
  2411. s32 ret_val = 0;
  2412. /* Gate automatic PHY configuration by hardware on non-managed 82579 */
  2413. if ((hw->mac.type == e1000_pch2lan) &&
  2414. !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
  2415. e1000_gate_hw_phy_config_ich8lan(hw, true);
  2416. ret_val = e1000e_phy_hw_reset_generic(hw);
  2417. if (ret_val)
  2418. return ret_val;
  2419. return e1000_post_phy_reset_ich8lan(hw);
  2420. }
  2421. /**
  2422. * e1000_set_lplu_state_pchlan - Set Low Power Link Up state
  2423. * @hw: pointer to the HW structure
  2424. * @active: true to enable LPLU, false to disable
  2425. *
  2426. * Sets the LPLU state according to the active flag. For PCH, if OEM write
  2427. * bit are disabled in the NVM, writing the LPLU bits in the MAC will not set
  2428. * the phy speed. This function will manually set the LPLU bit and restart
  2429. * auto-neg as hw would do. D3 and D0 LPLU will call the same function
  2430. * since it configures the same bit.
  2431. **/
  2432. static s32 e1000_set_lplu_state_pchlan(struct e1000_hw *hw, bool active)
  2433. {
  2434. s32 ret_val;
  2435. u16 oem_reg;
  2436. ret_val = e1e_rphy(hw, HV_OEM_BITS, &oem_reg);
  2437. if (ret_val)
  2438. return ret_val;
  2439. if (active)
  2440. oem_reg |= HV_OEM_BITS_LPLU;
  2441. else
  2442. oem_reg &= ~HV_OEM_BITS_LPLU;
  2443. if (!hw->phy.ops.check_reset_block(hw))
  2444. oem_reg |= HV_OEM_BITS_RESTART_AN;
  2445. return e1e_wphy(hw, HV_OEM_BITS, oem_reg);
  2446. }
  2447. /**
  2448. * e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
  2449. * @hw: pointer to the HW structure
  2450. * @active: true to enable LPLU, false to disable
  2451. *
  2452. * Sets the LPLU D0 state according to the active flag. When
  2453. * activating LPLU this function also disables smart speed
  2454. * and vice versa. LPLU will not be activated unless the
  2455. * device autonegotiation advertisement meets standards of
  2456. * either 10 or 10/100 or 10/100/1000 at all duplexes.
  2457. * This is a function pointer entry point only called by
  2458. * PHY setup routines.
  2459. **/
  2460. static s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
  2461. {
  2462. struct e1000_phy_info *phy = &hw->phy;
  2463. u32 phy_ctrl;
  2464. s32 ret_val = 0;
  2465. u16 data;
  2466. if (phy->type == e1000_phy_ife)
  2467. return 0;
  2468. phy_ctrl = er32(PHY_CTRL);
  2469. if (active) {
  2470. phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
  2471. ew32(PHY_CTRL, phy_ctrl);
  2472. if (phy->type != e1000_phy_igp_3)
  2473. return 0;
  2474. /* Call gig speed drop workaround on LPLU before accessing
  2475. * any PHY registers
  2476. */
  2477. if (hw->mac.type == e1000_ich8lan)
  2478. e1000e_gig_downshift_workaround_ich8lan(hw);
  2479. /* When LPLU is enabled, we should disable SmartSpeed */
  2480. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
  2481. if (ret_val)
  2482. return ret_val;
  2483. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2484. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
  2485. if (ret_val)
  2486. return ret_val;
  2487. } else {
  2488. phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
  2489. ew32(PHY_CTRL, phy_ctrl);
  2490. if (phy->type != e1000_phy_igp_3)
  2491. return 0;
  2492. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
  2493. * during Dx states where the power conservation is most
  2494. * important. During driver activity we should enable
  2495. * SmartSpeed, so performance is maintained.
  2496. */
  2497. if (phy->smart_speed == e1000_smart_speed_on) {
  2498. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2499. &data);
  2500. if (ret_val)
  2501. return ret_val;
  2502. data |= IGP01E1000_PSCFR_SMART_SPEED;
  2503. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2504. data);
  2505. if (ret_val)
  2506. return ret_val;
  2507. } else if (phy->smart_speed == e1000_smart_speed_off) {
  2508. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2509. &data);
  2510. if (ret_val)
  2511. return ret_val;
  2512. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2513. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2514. data);
  2515. if (ret_val)
  2516. return ret_val;
  2517. }
  2518. }
  2519. return 0;
  2520. }
  2521. /**
  2522. * e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
  2523. * @hw: pointer to the HW structure
  2524. * @active: true to enable LPLU, false to disable
  2525. *
  2526. * Sets the LPLU D3 state according to the active flag. When
  2527. * activating LPLU this function also disables smart speed
  2528. * and vice versa. LPLU will not be activated unless the
  2529. * device autonegotiation advertisement meets standards of
  2530. * either 10 or 10/100 or 10/100/1000 at all duplexes.
  2531. * This is a function pointer entry point only called by
  2532. * PHY setup routines.
  2533. **/
  2534. static s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw, bool active)
  2535. {
  2536. struct e1000_phy_info *phy = &hw->phy;
  2537. u32 phy_ctrl;
  2538. s32 ret_val = 0;
  2539. u16 data;
  2540. phy_ctrl = er32(PHY_CTRL);
  2541. if (!active) {
  2542. phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
  2543. ew32(PHY_CTRL, phy_ctrl);
  2544. if (phy->type != e1000_phy_igp_3)
  2545. return 0;
  2546. /* LPLU and SmartSpeed are mutually exclusive. LPLU is used
  2547. * during Dx states where the power conservation is most
  2548. * important. During driver activity we should enable
  2549. * SmartSpeed, so performance is maintained.
  2550. */
  2551. if (phy->smart_speed == e1000_smart_speed_on) {
  2552. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2553. &data);
  2554. if (ret_val)
  2555. return ret_val;
  2556. data |= IGP01E1000_PSCFR_SMART_SPEED;
  2557. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2558. data);
  2559. if (ret_val)
  2560. return ret_val;
  2561. } else if (phy->smart_speed == e1000_smart_speed_off) {
  2562. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2563. &data);
  2564. if (ret_val)
  2565. return ret_val;
  2566. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2567. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG,
  2568. data);
  2569. if (ret_val)
  2570. return ret_val;
  2571. }
  2572. } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
  2573. (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
  2574. (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
  2575. phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
  2576. ew32(PHY_CTRL, phy_ctrl);
  2577. if (phy->type != e1000_phy_igp_3)
  2578. return 0;
  2579. /* Call gig speed drop workaround on LPLU before accessing
  2580. * any PHY registers
  2581. */
  2582. if (hw->mac.type == e1000_ich8lan)
  2583. e1000e_gig_downshift_workaround_ich8lan(hw);
  2584. /* When LPLU is enabled, we should disable SmartSpeed */
  2585. ret_val = e1e_rphy(hw, IGP01E1000_PHY_PORT_CONFIG, &data);
  2586. if (ret_val)
  2587. return ret_val;
  2588. data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  2589. ret_val = e1e_wphy(hw, IGP01E1000_PHY_PORT_CONFIG, data);
  2590. }
  2591. return ret_val;
  2592. }
  2593. /**
  2594. * e1000_valid_nvm_bank_detect_ich8lan - finds out the valid bank 0 or 1
  2595. * @hw: pointer to the HW structure
  2596. * @bank: pointer to the variable that returns the active bank
  2597. *
  2598. * Reads signature byte from the NVM using the flash access registers.
  2599. * Word 0x13 bits 15:14 = 10b indicate a valid signature for that bank.
  2600. **/
  2601. static s32 e1000_valid_nvm_bank_detect_ich8lan(struct e1000_hw *hw, u32 *bank)
  2602. {
  2603. u32 eecd;
  2604. struct e1000_nvm_info *nvm = &hw->nvm;
  2605. u32 bank1_offset = nvm->flash_bank_size * sizeof(u16);
  2606. u32 act_offset = E1000_ICH_NVM_SIG_WORD * 2 + 1;
  2607. u8 sig_byte = 0;
  2608. s32 ret_val;
  2609. switch (hw->mac.type) {
  2610. /* In SPT, read from the CTRL_EXT reg instead of
  2611. * accessing the sector valid bits from the nvm
  2612. */
  2613. case e1000_pch_spt:
  2614. *bank = er32(CTRL_EXT)
  2615. & E1000_CTRL_EXT_NVMVS;
  2616. if ((*bank == 0) || (*bank == 1)) {
  2617. e_dbg("ERROR: No valid NVM bank present\n");
  2618. return -E1000_ERR_NVM;
  2619. } else {
  2620. *bank = *bank - 2;
  2621. return 0;
  2622. }
  2623. break;
  2624. case e1000_ich8lan:
  2625. case e1000_ich9lan:
  2626. eecd = er32(EECD);
  2627. if ((eecd & E1000_EECD_SEC1VAL_VALID_MASK) ==
  2628. E1000_EECD_SEC1VAL_VALID_MASK) {
  2629. if (eecd & E1000_EECD_SEC1VAL)
  2630. *bank = 1;
  2631. else
  2632. *bank = 0;
  2633. return 0;
  2634. }
  2635. e_dbg("Unable to determine valid NVM bank via EEC - reading flash signature\n");
  2636. /* fall-thru */
  2637. default:
  2638. /* set bank to 0 in case flash read fails */
  2639. *bank = 0;
  2640. /* Check bank 0 */
  2641. ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset,
  2642. &sig_byte);
  2643. if (ret_val)
  2644. return ret_val;
  2645. if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
  2646. E1000_ICH_NVM_SIG_VALUE) {
  2647. *bank = 0;
  2648. return 0;
  2649. }
  2650. /* Check bank 1 */
  2651. ret_val = e1000_read_flash_byte_ich8lan(hw, act_offset +
  2652. bank1_offset,
  2653. &sig_byte);
  2654. if (ret_val)
  2655. return ret_val;
  2656. if ((sig_byte & E1000_ICH_NVM_VALID_SIG_MASK) ==
  2657. E1000_ICH_NVM_SIG_VALUE) {
  2658. *bank = 1;
  2659. return 0;
  2660. }
  2661. e_dbg("ERROR: No valid NVM bank present\n");
  2662. return -E1000_ERR_NVM;
  2663. }
  2664. }
  2665. /**
  2666. * e1000_read_nvm_spt - NVM access for SPT
  2667. * @hw: pointer to the HW structure
  2668. * @offset: The offset (in bytes) of the word(s) to read.
  2669. * @words: Size of data to read in words.
  2670. * @data: pointer to the word(s) to read at offset.
  2671. *
  2672. * Reads a word(s) from the NVM
  2673. **/
  2674. static s32 e1000_read_nvm_spt(struct e1000_hw *hw, u16 offset, u16 words,
  2675. u16 *data)
  2676. {
  2677. struct e1000_nvm_info *nvm = &hw->nvm;
  2678. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  2679. u32 act_offset;
  2680. s32 ret_val = 0;
  2681. u32 bank = 0;
  2682. u32 dword = 0;
  2683. u16 offset_to_read;
  2684. u16 i;
  2685. if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
  2686. (words == 0)) {
  2687. e_dbg("nvm parameter(s) out of bounds\n");
  2688. ret_val = -E1000_ERR_NVM;
  2689. goto out;
  2690. }
  2691. nvm->ops.acquire(hw);
  2692. ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
  2693. if (ret_val) {
  2694. e_dbg("Could not detect valid bank, assuming bank 0\n");
  2695. bank = 0;
  2696. }
  2697. act_offset = (bank) ? nvm->flash_bank_size : 0;
  2698. act_offset += offset;
  2699. ret_val = 0;
  2700. for (i = 0; i < words; i += 2) {
  2701. if (words - i == 1) {
  2702. if (dev_spec->shadow_ram[offset + i].modified) {
  2703. data[i] =
  2704. dev_spec->shadow_ram[offset + i].value;
  2705. } else {
  2706. offset_to_read = act_offset + i -
  2707. ((act_offset + i) % 2);
  2708. ret_val =
  2709. e1000_read_flash_dword_ich8lan(hw,
  2710. offset_to_read,
  2711. &dword);
  2712. if (ret_val)
  2713. break;
  2714. if ((act_offset + i) % 2 == 0)
  2715. data[i] = (u16)(dword & 0xFFFF);
  2716. else
  2717. data[i] = (u16)((dword >> 16) & 0xFFFF);
  2718. }
  2719. } else {
  2720. offset_to_read = act_offset + i;
  2721. if (!(dev_spec->shadow_ram[offset + i].modified) ||
  2722. !(dev_spec->shadow_ram[offset + i + 1].modified)) {
  2723. ret_val =
  2724. e1000_read_flash_dword_ich8lan(hw,
  2725. offset_to_read,
  2726. &dword);
  2727. if (ret_val)
  2728. break;
  2729. }
  2730. if (dev_spec->shadow_ram[offset + i].modified)
  2731. data[i] =
  2732. dev_spec->shadow_ram[offset + i].value;
  2733. else
  2734. data[i] = (u16)(dword & 0xFFFF);
  2735. if (dev_spec->shadow_ram[offset + i].modified)
  2736. data[i + 1] =
  2737. dev_spec->shadow_ram[offset + i + 1].value;
  2738. else
  2739. data[i + 1] = (u16)(dword >> 16 & 0xFFFF);
  2740. }
  2741. }
  2742. nvm->ops.release(hw);
  2743. out:
  2744. if (ret_val)
  2745. e_dbg("NVM read error: %d\n", ret_val);
  2746. return ret_val;
  2747. }
  2748. /**
  2749. * e1000_read_nvm_ich8lan - Read word(s) from the NVM
  2750. * @hw: pointer to the HW structure
  2751. * @offset: The offset (in bytes) of the word(s) to read.
  2752. * @words: Size of data to read in words
  2753. * @data: Pointer to the word(s) to read at offset.
  2754. *
  2755. * Reads a word(s) from the NVM using the flash access registers.
  2756. **/
  2757. static s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
  2758. u16 *data)
  2759. {
  2760. struct e1000_nvm_info *nvm = &hw->nvm;
  2761. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  2762. u32 act_offset;
  2763. s32 ret_val = 0;
  2764. u32 bank = 0;
  2765. u16 i, word;
  2766. if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
  2767. (words == 0)) {
  2768. e_dbg("nvm parameter(s) out of bounds\n");
  2769. ret_val = -E1000_ERR_NVM;
  2770. goto out;
  2771. }
  2772. nvm->ops.acquire(hw);
  2773. ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
  2774. if (ret_val) {
  2775. e_dbg("Could not detect valid bank, assuming bank 0\n");
  2776. bank = 0;
  2777. }
  2778. act_offset = (bank) ? nvm->flash_bank_size : 0;
  2779. act_offset += offset;
  2780. ret_val = 0;
  2781. for (i = 0; i < words; i++) {
  2782. if (dev_spec->shadow_ram[offset + i].modified) {
  2783. data[i] = dev_spec->shadow_ram[offset + i].value;
  2784. } else {
  2785. ret_val = e1000_read_flash_word_ich8lan(hw,
  2786. act_offset + i,
  2787. &word);
  2788. if (ret_val)
  2789. break;
  2790. data[i] = word;
  2791. }
  2792. }
  2793. nvm->ops.release(hw);
  2794. out:
  2795. if (ret_val)
  2796. e_dbg("NVM read error: %d\n", ret_val);
  2797. return ret_val;
  2798. }
  2799. /**
  2800. * e1000_flash_cycle_init_ich8lan - Initialize flash
  2801. * @hw: pointer to the HW structure
  2802. *
  2803. * This function does initial flash setup so that a new read/write/erase cycle
  2804. * can be started.
  2805. **/
  2806. static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
  2807. {
  2808. union ich8_hws_flash_status hsfsts;
  2809. s32 ret_val = -E1000_ERR_NVM;
  2810. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  2811. /* Check if the flash descriptor is valid */
  2812. if (!hsfsts.hsf_status.fldesvalid) {
  2813. e_dbg("Flash descriptor invalid. SW Sequencing must be used.\n");
  2814. return -E1000_ERR_NVM;
  2815. }
  2816. /* Clear FCERR and DAEL in hw status by writing 1 */
  2817. hsfsts.hsf_status.flcerr = 1;
  2818. hsfsts.hsf_status.dael = 1;
  2819. if (hw->mac.type == e1000_pch_spt)
  2820. ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval & 0xFFFF);
  2821. else
  2822. ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
  2823. /* Either we should have a hardware SPI cycle in progress
  2824. * bit to check against, in order to start a new cycle or
  2825. * FDONE bit should be changed in the hardware so that it
  2826. * is 1 after hardware reset, which can then be used as an
  2827. * indication whether a cycle is in progress or has been
  2828. * completed.
  2829. */
  2830. if (!hsfsts.hsf_status.flcinprog) {
  2831. /* There is no cycle running at present,
  2832. * so we can start a cycle.
  2833. * Begin by setting Flash Cycle Done.
  2834. */
  2835. hsfsts.hsf_status.flcdone = 1;
  2836. if (hw->mac.type == e1000_pch_spt)
  2837. ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval & 0xFFFF);
  2838. else
  2839. ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
  2840. ret_val = 0;
  2841. } else {
  2842. s32 i;
  2843. /* Otherwise poll for sometime so the current
  2844. * cycle has a chance to end before giving up.
  2845. */
  2846. for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
  2847. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  2848. if (!hsfsts.hsf_status.flcinprog) {
  2849. ret_val = 0;
  2850. break;
  2851. }
  2852. udelay(1);
  2853. }
  2854. if (!ret_val) {
  2855. /* Successful in waiting for previous cycle to timeout,
  2856. * now set the Flash Cycle Done.
  2857. */
  2858. hsfsts.hsf_status.flcdone = 1;
  2859. if (hw->mac.type == e1000_pch_spt)
  2860. ew32flash(ICH_FLASH_HSFSTS,
  2861. hsfsts.regval & 0xFFFF);
  2862. else
  2863. ew16flash(ICH_FLASH_HSFSTS, hsfsts.regval);
  2864. } else {
  2865. e_dbg("Flash controller busy, cannot get access\n");
  2866. }
  2867. }
  2868. return ret_val;
  2869. }
  2870. /**
  2871. * e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
  2872. * @hw: pointer to the HW structure
  2873. * @timeout: maximum time to wait for completion
  2874. *
  2875. * This function starts a flash cycle and waits for its completion.
  2876. **/
  2877. static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
  2878. {
  2879. union ich8_hws_flash_ctrl hsflctl;
  2880. union ich8_hws_flash_status hsfsts;
  2881. u32 i = 0;
  2882. /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
  2883. if (hw->mac.type == e1000_pch_spt)
  2884. hsflctl.regval = er32flash(ICH_FLASH_HSFSTS) >> 16;
  2885. else
  2886. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  2887. hsflctl.hsf_ctrl.flcgo = 1;
  2888. if (hw->mac.type == e1000_pch_spt)
  2889. ew32flash(ICH_FLASH_HSFSTS, hsflctl.regval << 16);
  2890. else
  2891. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  2892. /* wait till FDONE bit is set to 1 */
  2893. do {
  2894. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  2895. if (hsfsts.hsf_status.flcdone)
  2896. break;
  2897. udelay(1);
  2898. } while (i++ < timeout);
  2899. if (hsfsts.hsf_status.flcdone && !hsfsts.hsf_status.flcerr)
  2900. return 0;
  2901. return -E1000_ERR_NVM;
  2902. }
  2903. /**
  2904. * e1000_read_flash_dword_ich8lan - Read dword from flash
  2905. * @hw: pointer to the HW structure
  2906. * @offset: offset to data location
  2907. * @data: pointer to the location for storing the data
  2908. *
  2909. * Reads the flash dword at offset into data. Offset is converted
  2910. * to bytes before read.
  2911. **/
  2912. static s32 e1000_read_flash_dword_ich8lan(struct e1000_hw *hw, u32 offset,
  2913. u32 *data)
  2914. {
  2915. /* Must convert word offset into bytes. */
  2916. offset <<= 1;
  2917. return e1000_read_flash_data32_ich8lan(hw, offset, data);
  2918. }
  2919. /**
  2920. * e1000_read_flash_word_ich8lan - Read word from flash
  2921. * @hw: pointer to the HW structure
  2922. * @offset: offset to data location
  2923. * @data: pointer to the location for storing the data
  2924. *
  2925. * Reads the flash word at offset into data. Offset is converted
  2926. * to bytes before read.
  2927. **/
  2928. static s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
  2929. u16 *data)
  2930. {
  2931. /* Must convert offset into bytes. */
  2932. offset <<= 1;
  2933. return e1000_read_flash_data_ich8lan(hw, offset, 2, data);
  2934. }
  2935. /**
  2936. * e1000_read_flash_byte_ich8lan - Read byte from flash
  2937. * @hw: pointer to the HW structure
  2938. * @offset: The offset of the byte to read.
  2939. * @data: Pointer to a byte to store the value read.
  2940. *
  2941. * Reads a single byte from the NVM using the flash access registers.
  2942. **/
  2943. static s32 e1000_read_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
  2944. u8 *data)
  2945. {
  2946. s32 ret_val;
  2947. u16 word = 0;
  2948. /* In SPT, only 32 bits access is supported,
  2949. * so this function should not be called.
  2950. */
  2951. if (hw->mac.type == e1000_pch_spt)
  2952. return -E1000_ERR_NVM;
  2953. else
  2954. ret_val = e1000_read_flash_data_ich8lan(hw, offset, 1, &word);
  2955. if (ret_val)
  2956. return ret_val;
  2957. *data = (u8)word;
  2958. return 0;
  2959. }
  2960. /**
  2961. * e1000_read_flash_data_ich8lan - Read byte or word from NVM
  2962. * @hw: pointer to the HW structure
  2963. * @offset: The offset (in bytes) of the byte or word to read.
  2964. * @size: Size of data to read, 1=byte 2=word
  2965. * @data: Pointer to the word to store the value read.
  2966. *
  2967. * Reads a byte or word from the NVM using the flash access registers.
  2968. **/
  2969. static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
  2970. u8 size, u16 *data)
  2971. {
  2972. union ich8_hws_flash_status hsfsts;
  2973. union ich8_hws_flash_ctrl hsflctl;
  2974. u32 flash_linear_addr;
  2975. u32 flash_data = 0;
  2976. s32 ret_val = -E1000_ERR_NVM;
  2977. u8 count = 0;
  2978. if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
  2979. return -E1000_ERR_NVM;
  2980. flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
  2981. hw->nvm.flash_base_addr);
  2982. do {
  2983. udelay(1);
  2984. /* Steps */
  2985. ret_val = e1000_flash_cycle_init_ich8lan(hw);
  2986. if (ret_val)
  2987. break;
  2988. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  2989. /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
  2990. hsflctl.hsf_ctrl.fldbcount = size - 1;
  2991. hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
  2992. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  2993. ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
  2994. ret_val =
  2995. e1000_flash_cycle_ich8lan(hw,
  2996. ICH_FLASH_READ_COMMAND_TIMEOUT);
  2997. /* Check if FCERR is set to 1, if set to 1, clear it
  2998. * and try the whole sequence a few more times, else
  2999. * read in (shift in) the Flash Data0, the order is
  3000. * least significant byte first msb to lsb
  3001. */
  3002. if (!ret_val) {
  3003. flash_data = er32flash(ICH_FLASH_FDATA0);
  3004. if (size == 1)
  3005. *data = (u8)(flash_data & 0x000000FF);
  3006. else if (size == 2)
  3007. *data = (u16)(flash_data & 0x0000FFFF);
  3008. break;
  3009. } else {
  3010. /* If we've gotten here, then things are probably
  3011. * completely hosed, but if the error condition is
  3012. * detected, it won't hurt to give it another try...
  3013. * ICH_FLASH_CYCLE_REPEAT_COUNT times.
  3014. */
  3015. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  3016. if (hsfsts.hsf_status.flcerr) {
  3017. /* Repeat for some time before giving up. */
  3018. continue;
  3019. } else if (!hsfsts.hsf_status.flcdone) {
  3020. e_dbg("Timeout error - flash cycle did not complete.\n");
  3021. break;
  3022. }
  3023. }
  3024. } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
  3025. return ret_val;
  3026. }
  3027. /**
  3028. * e1000_read_flash_data32_ich8lan - Read dword from NVM
  3029. * @hw: pointer to the HW structure
  3030. * @offset: The offset (in bytes) of the dword to read.
  3031. * @data: Pointer to the dword to store the value read.
  3032. *
  3033. * Reads a byte or word from the NVM using the flash access registers.
  3034. **/
  3035. static s32 e1000_read_flash_data32_ich8lan(struct e1000_hw *hw, u32 offset,
  3036. u32 *data)
  3037. {
  3038. union ich8_hws_flash_status hsfsts;
  3039. union ich8_hws_flash_ctrl hsflctl;
  3040. u32 flash_linear_addr;
  3041. s32 ret_val = -E1000_ERR_NVM;
  3042. u8 count = 0;
  3043. if (offset > ICH_FLASH_LINEAR_ADDR_MASK ||
  3044. hw->mac.type != e1000_pch_spt)
  3045. return -E1000_ERR_NVM;
  3046. flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
  3047. hw->nvm.flash_base_addr);
  3048. do {
  3049. udelay(1);
  3050. /* Steps */
  3051. ret_val = e1000_flash_cycle_init_ich8lan(hw);
  3052. if (ret_val)
  3053. break;
  3054. /* In SPT, This register is in Lan memory space, not flash.
  3055. * Therefore, only 32 bit access is supported
  3056. */
  3057. hsflctl.regval = er32flash(ICH_FLASH_HSFSTS) >> 16;
  3058. /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
  3059. hsflctl.hsf_ctrl.fldbcount = sizeof(u32) - 1;
  3060. hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
  3061. /* In SPT, This register is in Lan memory space, not flash.
  3062. * Therefore, only 32 bit access is supported
  3063. */
  3064. ew32flash(ICH_FLASH_HSFSTS, (u32)hsflctl.regval << 16);
  3065. ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
  3066. ret_val =
  3067. e1000_flash_cycle_ich8lan(hw,
  3068. ICH_FLASH_READ_COMMAND_TIMEOUT);
  3069. /* Check if FCERR is set to 1, if set to 1, clear it
  3070. * and try the whole sequence a few more times, else
  3071. * read in (shift in) the Flash Data0, the order is
  3072. * least significant byte first msb to lsb
  3073. */
  3074. if (!ret_val) {
  3075. *data = er32flash(ICH_FLASH_FDATA0);
  3076. break;
  3077. } else {
  3078. /* If we've gotten here, then things are probably
  3079. * completely hosed, but if the error condition is
  3080. * detected, it won't hurt to give it another try...
  3081. * ICH_FLASH_CYCLE_REPEAT_COUNT times.
  3082. */
  3083. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  3084. if (hsfsts.hsf_status.flcerr) {
  3085. /* Repeat for some time before giving up. */
  3086. continue;
  3087. } else if (!hsfsts.hsf_status.flcdone) {
  3088. e_dbg("Timeout error - flash cycle did not complete.\n");
  3089. break;
  3090. }
  3091. }
  3092. } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
  3093. return ret_val;
  3094. }
  3095. /**
  3096. * e1000_write_nvm_ich8lan - Write word(s) to the NVM
  3097. * @hw: pointer to the HW structure
  3098. * @offset: The offset (in bytes) of the word(s) to write.
  3099. * @words: Size of data to write in words
  3100. * @data: Pointer to the word(s) to write at offset.
  3101. *
  3102. * Writes a byte or word to the NVM using the flash access registers.
  3103. **/
  3104. static s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
  3105. u16 *data)
  3106. {
  3107. struct e1000_nvm_info *nvm = &hw->nvm;
  3108. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  3109. u16 i;
  3110. if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
  3111. (words == 0)) {
  3112. e_dbg("nvm parameter(s) out of bounds\n");
  3113. return -E1000_ERR_NVM;
  3114. }
  3115. nvm->ops.acquire(hw);
  3116. for (i = 0; i < words; i++) {
  3117. dev_spec->shadow_ram[offset + i].modified = true;
  3118. dev_spec->shadow_ram[offset + i].value = data[i];
  3119. }
  3120. nvm->ops.release(hw);
  3121. return 0;
  3122. }
  3123. /**
  3124. * e1000_update_nvm_checksum_spt - Update the checksum for NVM
  3125. * @hw: pointer to the HW structure
  3126. *
  3127. * The NVM checksum is updated by calling the generic update_nvm_checksum,
  3128. * which writes the checksum to the shadow ram. The changes in the shadow
  3129. * ram are then committed to the EEPROM by processing each bank at a time
  3130. * checking for the modified bit and writing only the pending changes.
  3131. * After a successful commit, the shadow ram is cleared and is ready for
  3132. * future writes.
  3133. **/
  3134. static s32 e1000_update_nvm_checksum_spt(struct e1000_hw *hw)
  3135. {
  3136. struct e1000_nvm_info *nvm = &hw->nvm;
  3137. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  3138. u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
  3139. s32 ret_val;
  3140. u32 dword = 0;
  3141. ret_val = e1000e_update_nvm_checksum_generic(hw);
  3142. if (ret_val)
  3143. goto out;
  3144. if (nvm->type != e1000_nvm_flash_sw)
  3145. goto out;
  3146. nvm->ops.acquire(hw);
  3147. /* We're writing to the opposite bank so if we're on bank 1,
  3148. * write to bank 0 etc. We also need to erase the segment that
  3149. * is going to be written
  3150. */
  3151. ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
  3152. if (ret_val) {
  3153. e_dbg("Could not detect valid bank, assuming bank 0\n");
  3154. bank = 0;
  3155. }
  3156. if (bank == 0) {
  3157. new_bank_offset = nvm->flash_bank_size;
  3158. old_bank_offset = 0;
  3159. ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
  3160. if (ret_val)
  3161. goto release;
  3162. } else {
  3163. old_bank_offset = nvm->flash_bank_size;
  3164. new_bank_offset = 0;
  3165. ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
  3166. if (ret_val)
  3167. goto release;
  3168. }
  3169. for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i += 2) {
  3170. /* Determine whether to write the value stored
  3171. * in the other NVM bank or a modified value stored
  3172. * in the shadow RAM
  3173. */
  3174. ret_val = e1000_read_flash_dword_ich8lan(hw,
  3175. i + old_bank_offset,
  3176. &dword);
  3177. if (dev_spec->shadow_ram[i].modified) {
  3178. dword &= 0xffff0000;
  3179. dword |= (dev_spec->shadow_ram[i].value & 0xffff);
  3180. }
  3181. if (dev_spec->shadow_ram[i + 1].modified) {
  3182. dword &= 0x0000ffff;
  3183. dword |= ((dev_spec->shadow_ram[i + 1].value & 0xffff)
  3184. << 16);
  3185. }
  3186. if (ret_val)
  3187. break;
  3188. /* If the word is 0x13, then make sure the signature bits
  3189. * (15:14) are 11b until the commit has completed.
  3190. * This will allow us to write 10b which indicates the
  3191. * signature is valid. We want to do this after the write
  3192. * has completed so that we don't mark the segment valid
  3193. * while the write is still in progress
  3194. */
  3195. if (i == E1000_ICH_NVM_SIG_WORD - 1)
  3196. dword |= E1000_ICH_NVM_SIG_MASK << 16;
  3197. /* Convert offset to bytes. */
  3198. act_offset = (i + new_bank_offset) << 1;
  3199. usleep_range(100, 200);
  3200. /* Write the data to the new bank. Offset in words */
  3201. act_offset = i + new_bank_offset;
  3202. ret_val = e1000_retry_write_flash_dword_ich8lan(hw, act_offset,
  3203. dword);
  3204. if (ret_val)
  3205. break;
  3206. }
  3207. /* Don't bother writing the segment valid bits if sector
  3208. * programming failed.
  3209. */
  3210. if (ret_val) {
  3211. /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
  3212. e_dbg("Flash commit failed.\n");
  3213. goto release;
  3214. }
  3215. /* Finally validate the new segment by setting bit 15:14
  3216. * to 10b in word 0x13 , this can be done without an
  3217. * erase as well since these bits are 11 to start with
  3218. * and we need to change bit 14 to 0b
  3219. */
  3220. act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
  3221. /*offset in words but we read dword */
  3222. --act_offset;
  3223. ret_val = e1000_read_flash_dword_ich8lan(hw, act_offset, &dword);
  3224. if (ret_val)
  3225. goto release;
  3226. dword &= 0xBFFFFFFF;
  3227. ret_val = e1000_retry_write_flash_dword_ich8lan(hw, act_offset, dword);
  3228. if (ret_val)
  3229. goto release;
  3230. /* And invalidate the previously valid segment by setting
  3231. * its signature word (0x13) high_byte to 0b. This can be
  3232. * done without an erase because flash erase sets all bits
  3233. * to 1's. We can write 1's to 0's without an erase
  3234. */
  3235. act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
  3236. /* offset in words but we read dword */
  3237. act_offset = old_bank_offset + E1000_ICH_NVM_SIG_WORD - 1;
  3238. ret_val = e1000_read_flash_dword_ich8lan(hw, act_offset, &dword);
  3239. if (ret_val)
  3240. goto release;
  3241. dword &= 0x00FFFFFF;
  3242. ret_val = e1000_retry_write_flash_dword_ich8lan(hw, act_offset, dword);
  3243. if (ret_val)
  3244. goto release;
  3245. /* Great! Everything worked, we can now clear the cached entries. */
  3246. for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
  3247. dev_spec->shadow_ram[i].modified = false;
  3248. dev_spec->shadow_ram[i].value = 0xFFFF;
  3249. }
  3250. release:
  3251. nvm->ops.release(hw);
  3252. /* Reload the EEPROM, or else modifications will not appear
  3253. * until after the next adapter reset.
  3254. */
  3255. if (!ret_val) {
  3256. nvm->ops.reload(hw);
  3257. usleep_range(10000, 20000);
  3258. }
  3259. out:
  3260. if (ret_val)
  3261. e_dbg("NVM update error: %d\n", ret_val);
  3262. return ret_val;
  3263. }
  3264. /**
  3265. * e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
  3266. * @hw: pointer to the HW structure
  3267. *
  3268. * The NVM checksum is updated by calling the generic update_nvm_checksum,
  3269. * which writes the checksum to the shadow ram. The changes in the shadow
  3270. * ram are then committed to the EEPROM by processing each bank at a time
  3271. * checking for the modified bit and writing only the pending changes.
  3272. * After a successful commit, the shadow ram is cleared and is ready for
  3273. * future writes.
  3274. **/
  3275. static s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
  3276. {
  3277. struct e1000_nvm_info *nvm = &hw->nvm;
  3278. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  3279. u32 i, act_offset, new_bank_offset, old_bank_offset, bank;
  3280. s32 ret_val;
  3281. u16 data = 0;
  3282. ret_val = e1000e_update_nvm_checksum_generic(hw);
  3283. if (ret_val)
  3284. goto out;
  3285. if (nvm->type != e1000_nvm_flash_sw)
  3286. goto out;
  3287. nvm->ops.acquire(hw);
  3288. /* We're writing to the opposite bank so if we're on bank 1,
  3289. * write to bank 0 etc. We also need to erase the segment that
  3290. * is going to be written
  3291. */
  3292. ret_val = e1000_valid_nvm_bank_detect_ich8lan(hw, &bank);
  3293. if (ret_val) {
  3294. e_dbg("Could not detect valid bank, assuming bank 0\n");
  3295. bank = 0;
  3296. }
  3297. if (bank == 0) {
  3298. new_bank_offset = nvm->flash_bank_size;
  3299. old_bank_offset = 0;
  3300. ret_val = e1000_erase_flash_bank_ich8lan(hw, 1);
  3301. if (ret_val)
  3302. goto release;
  3303. } else {
  3304. old_bank_offset = nvm->flash_bank_size;
  3305. new_bank_offset = 0;
  3306. ret_val = e1000_erase_flash_bank_ich8lan(hw, 0);
  3307. if (ret_val)
  3308. goto release;
  3309. }
  3310. for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
  3311. if (dev_spec->shadow_ram[i].modified) {
  3312. data = dev_spec->shadow_ram[i].value;
  3313. } else {
  3314. ret_val = e1000_read_flash_word_ich8lan(hw, i +
  3315. old_bank_offset,
  3316. &data);
  3317. if (ret_val)
  3318. break;
  3319. }
  3320. /* If the word is 0x13, then make sure the signature bits
  3321. * (15:14) are 11b until the commit has completed.
  3322. * This will allow us to write 10b which indicates the
  3323. * signature is valid. We want to do this after the write
  3324. * has completed so that we don't mark the segment valid
  3325. * while the write is still in progress
  3326. */
  3327. if (i == E1000_ICH_NVM_SIG_WORD)
  3328. data |= E1000_ICH_NVM_SIG_MASK;
  3329. /* Convert offset to bytes. */
  3330. act_offset = (i + new_bank_offset) << 1;
  3331. usleep_range(100, 200);
  3332. /* Write the bytes to the new bank. */
  3333. ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
  3334. act_offset,
  3335. (u8)data);
  3336. if (ret_val)
  3337. break;
  3338. usleep_range(100, 200);
  3339. ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
  3340. act_offset + 1,
  3341. (u8)(data >> 8));
  3342. if (ret_val)
  3343. break;
  3344. }
  3345. /* Don't bother writing the segment valid bits if sector
  3346. * programming failed.
  3347. */
  3348. if (ret_val) {
  3349. /* Possibly read-only, see e1000e_write_protect_nvm_ich8lan() */
  3350. e_dbg("Flash commit failed.\n");
  3351. goto release;
  3352. }
  3353. /* Finally validate the new segment by setting bit 15:14
  3354. * to 10b in word 0x13 , this can be done without an
  3355. * erase as well since these bits are 11 to start with
  3356. * and we need to change bit 14 to 0b
  3357. */
  3358. act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
  3359. ret_val = e1000_read_flash_word_ich8lan(hw, act_offset, &data);
  3360. if (ret_val)
  3361. goto release;
  3362. data &= 0xBFFF;
  3363. ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
  3364. act_offset * 2 + 1,
  3365. (u8)(data >> 8));
  3366. if (ret_val)
  3367. goto release;
  3368. /* And invalidate the previously valid segment by setting
  3369. * its signature word (0x13) high_byte to 0b. This can be
  3370. * done without an erase because flash erase sets all bits
  3371. * to 1's. We can write 1's to 0's without an erase
  3372. */
  3373. act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
  3374. ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
  3375. if (ret_val)
  3376. goto release;
  3377. /* Great! Everything worked, we can now clear the cached entries. */
  3378. for (i = 0; i < E1000_ICH8_SHADOW_RAM_WORDS; i++) {
  3379. dev_spec->shadow_ram[i].modified = false;
  3380. dev_spec->shadow_ram[i].value = 0xFFFF;
  3381. }
  3382. release:
  3383. nvm->ops.release(hw);
  3384. /* Reload the EEPROM, or else modifications will not appear
  3385. * until after the next adapter reset.
  3386. */
  3387. if (!ret_val) {
  3388. nvm->ops.reload(hw);
  3389. usleep_range(10000, 20000);
  3390. }
  3391. out:
  3392. if (ret_val)
  3393. e_dbg("NVM update error: %d\n", ret_val);
  3394. return ret_val;
  3395. }
  3396. /**
  3397. * e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
  3398. * @hw: pointer to the HW structure
  3399. *
  3400. * Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
  3401. * If the bit is 0, that the EEPROM had been modified, but the checksum was not
  3402. * calculated, in which case we need to calculate the checksum and set bit 6.
  3403. **/
  3404. static s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
  3405. {
  3406. s32 ret_val;
  3407. u16 data;
  3408. u16 word;
  3409. u16 valid_csum_mask;
  3410. /* Read NVM and check Invalid Image CSUM bit. If this bit is 0,
  3411. * the checksum needs to be fixed. This bit is an indication that
  3412. * the NVM was prepared by OEM software and did not calculate
  3413. * the checksum...a likely scenario.
  3414. */
  3415. switch (hw->mac.type) {
  3416. case e1000_pch_lpt:
  3417. case e1000_pch_spt:
  3418. word = NVM_COMPAT;
  3419. valid_csum_mask = NVM_COMPAT_VALID_CSUM;
  3420. break;
  3421. default:
  3422. word = NVM_FUTURE_INIT_WORD1;
  3423. valid_csum_mask = NVM_FUTURE_INIT_WORD1_VALID_CSUM;
  3424. break;
  3425. }
  3426. ret_val = e1000_read_nvm(hw, word, 1, &data);
  3427. if (ret_val)
  3428. return ret_val;
  3429. if (!(data & valid_csum_mask)) {
  3430. data |= valid_csum_mask;
  3431. ret_val = e1000_write_nvm(hw, word, 1, &data);
  3432. if (ret_val)
  3433. return ret_val;
  3434. ret_val = e1000e_update_nvm_checksum(hw);
  3435. if (ret_val)
  3436. return ret_val;
  3437. }
  3438. return e1000e_validate_nvm_checksum_generic(hw);
  3439. }
  3440. /**
  3441. * e1000e_write_protect_nvm_ich8lan - Make the NVM read-only
  3442. * @hw: pointer to the HW structure
  3443. *
  3444. * To prevent malicious write/erase of the NVM, set it to be read-only
  3445. * so that the hardware ignores all write/erase cycles of the NVM via
  3446. * the flash control registers. The shadow-ram copy of the NVM will
  3447. * still be updated, however any updates to this copy will not stick
  3448. * across driver reloads.
  3449. **/
  3450. void e1000e_write_protect_nvm_ich8lan(struct e1000_hw *hw)
  3451. {
  3452. struct e1000_nvm_info *nvm = &hw->nvm;
  3453. union ich8_flash_protected_range pr0;
  3454. union ich8_hws_flash_status hsfsts;
  3455. u32 gfpreg;
  3456. nvm->ops.acquire(hw);
  3457. gfpreg = er32flash(ICH_FLASH_GFPREG);
  3458. /* Write-protect GbE Sector of NVM */
  3459. pr0.regval = er32flash(ICH_FLASH_PR0);
  3460. pr0.range.base = gfpreg & FLASH_GFPREG_BASE_MASK;
  3461. pr0.range.limit = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK);
  3462. pr0.range.wpe = true;
  3463. ew32flash(ICH_FLASH_PR0, pr0.regval);
  3464. /* Lock down a subset of GbE Flash Control Registers, e.g.
  3465. * PR0 to prevent the write-protection from being lifted.
  3466. * Once FLOCKDN is set, the registers protected by it cannot
  3467. * be written until FLOCKDN is cleared by a hardware reset.
  3468. */
  3469. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  3470. hsfsts.hsf_status.flockdn = true;
  3471. ew32flash(ICH_FLASH_HSFSTS, hsfsts.regval);
  3472. nvm->ops.release(hw);
  3473. }
  3474. /**
  3475. * e1000_write_flash_data_ich8lan - Writes bytes to the NVM
  3476. * @hw: pointer to the HW structure
  3477. * @offset: The offset (in bytes) of the byte/word to read.
  3478. * @size: Size of data to read, 1=byte 2=word
  3479. * @data: The byte(s) to write to the NVM.
  3480. *
  3481. * Writes one/two bytes to the NVM using the flash access registers.
  3482. **/
  3483. static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
  3484. u8 size, u16 data)
  3485. {
  3486. union ich8_hws_flash_status hsfsts;
  3487. union ich8_hws_flash_ctrl hsflctl;
  3488. u32 flash_linear_addr;
  3489. u32 flash_data = 0;
  3490. s32 ret_val;
  3491. u8 count = 0;
  3492. if (hw->mac.type == e1000_pch_spt) {
  3493. if (size != 4 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
  3494. return -E1000_ERR_NVM;
  3495. } else {
  3496. if (size < 1 || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
  3497. return -E1000_ERR_NVM;
  3498. }
  3499. flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
  3500. hw->nvm.flash_base_addr);
  3501. do {
  3502. udelay(1);
  3503. /* Steps */
  3504. ret_val = e1000_flash_cycle_init_ich8lan(hw);
  3505. if (ret_val)
  3506. break;
  3507. /* In SPT, This register is in Lan memory space, not
  3508. * flash. Therefore, only 32 bit access is supported
  3509. */
  3510. if (hw->mac.type == e1000_pch_spt)
  3511. hsflctl.regval = er32flash(ICH_FLASH_HSFSTS) >> 16;
  3512. else
  3513. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  3514. /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
  3515. hsflctl.hsf_ctrl.fldbcount = size - 1;
  3516. hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
  3517. /* In SPT, This register is in Lan memory space,
  3518. * not flash. Therefore, only 32 bit access is
  3519. * supported
  3520. */
  3521. if (hw->mac.type == e1000_pch_spt)
  3522. ew32flash(ICH_FLASH_HSFSTS, hsflctl.regval << 16);
  3523. else
  3524. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  3525. ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
  3526. if (size == 1)
  3527. flash_data = (u32)data & 0x00FF;
  3528. else
  3529. flash_data = (u32)data;
  3530. ew32flash(ICH_FLASH_FDATA0, flash_data);
  3531. /* check if FCERR is set to 1 , if set to 1, clear it
  3532. * and try the whole sequence a few more times else done
  3533. */
  3534. ret_val =
  3535. e1000_flash_cycle_ich8lan(hw,
  3536. ICH_FLASH_WRITE_COMMAND_TIMEOUT);
  3537. if (!ret_val)
  3538. break;
  3539. /* If we're here, then things are most likely
  3540. * completely hosed, but if the error condition
  3541. * is detected, it won't hurt to give it another
  3542. * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
  3543. */
  3544. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  3545. if (hsfsts.hsf_status.flcerr)
  3546. /* Repeat for some time before giving up. */
  3547. continue;
  3548. if (!hsfsts.hsf_status.flcdone) {
  3549. e_dbg("Timeout error - flash cycle did not complete.\n");
  3550. break;
  3551. }
  3552. } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
  3553. return ret_val;
  3554. }
  3555. /**
  3556. * e1000_write_flash_data32_ich8lan - Writes 4 bytes to the NVM
  3557. * @hw: pointer to the HW structure
  3558. * @offset: The offset (in bytes) of the dwords to read.
  3559. * @data: The 4 bytes to write to the NVM.
  3560. *
  3561. * Writes one/two/four bytes to the NVM using the flash access registers.
  3562. **/
  3563. static s32 e1000_write_flash_data32_ich8lan(struct e1000_hw *hw, u32 offset,
  3564. u32 data)
  3565. {
  3566. union ich8_hws_flash_status hsfsts;
  3567. union ich8_hws_flash_ctrl hsflctl;
  3568. u32 flash_linear_addr;
  3569. s32 ret_val;
  3570. u8 count = 0;
  3571. if (hw->mac.type == e1000_pch_spt) {
  3572. if (offset > ICH_FLASH_LINEAR_ADDR_MASK)
  3573. return -E1000_ERR_NVM;
  3574. }
  3575. flash_linear_addr = ((ICH_FLASH_LINEAR_ADDR_MASK & offset) +
  3576. hw->nvm.flash_base_addr);
  3577. do {
  3578. udelay(1);
  3579. /* Steps */
  3580. ret_val = e1000_flash_cycle_init_ich8lan(hw);
  3581. if (ret_val)
  3582. break;
  3583. /* In SPT, This register is in Lan memory space, not
  3584. * flash. Therefore, only 32 bit access is supported
  3585. */
  3586. if (hw->mac.type == e1000_pch_spt)
  3587. hsflctl.regval = er32flash(ICH_FLASH_HSFSTS)
  3588. >> 16;
  3589. else
  3590. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  3591. hsflctl.hsf_ctrl.fldbcount = sizeof(u32) - 1;
  3592. hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
  3593. /* In SPT, This register is in Lan memory space,
  3594. * not flash. Therefore, only 32 bit access is
  3595. * supported
  3596. */
  3597. if (hw->mac.type == e1000_pch_spt)
  3598. ew32flash(ICH_FLASH_HSFSTS, hsflctl.regval << 16);
  3599. else
  3600. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  3601. ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
  3602. ew32flash(ICH_FLASH_FDATA0, data);
  3603. /* check if FCERR is set to 1 , if set to 1, clear it
  3604. * and try the whole sequence a few more times else done
  3605. */
  3606. ret_val =
  3607. e1000_flash_cycle_ich8lan(hw,
  3608. ICH_FLASH_WRITE_COMMAND_TIMEOUT);
  3609. if (!ret_val)
  3610. break;
  3611. /* If we're here, then things are most likely
  3612. * completely hosed, but if the error condition
  3613. * is detected, it won't hurt to give it another
  3614. * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
  3615. */
  3616. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  3617. if (hsfsts.hsf_status.flcerr)
  3618. /* Repeat for some time before giving up. */
  3619. continue;
  3620. if (!hsfsts.hsf_status.flcdone) {
  3621. e_dbg("Timeout error - flash cycle did not complete.\n");
  3622. break;
  3623. }
  3624. } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
  3625. return ret_val;
  3626. }
  3627. /**
  3628. * e1000_write_flash_byte_ich8lan - Write a single byte to NVM
  3629. * @hw: pointer to the HW structure
  3630. * @offset: The index of the byte to read.
  3631. * @data: The byte to write to the NVM.
  3632. *
  3633. * Writes a single byte to the NVM using the flash access registers.
  3634. **/
  3635. static s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
  3636. u8 data)
  3637. {
  3638. u16 word = (u16)data;
  3639. return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
  3640. }
  3641. /**
  3642. * e1000_retry_write_flash_dword_ich8lan - Writes a dword to NVM
  3643. * @hw: pointer to the HW structure
  3644. * @offset: The offset of the word to write.
  3645. * @dword: The dword to write to the NVM.
  3646. *
  3647. * Writes a single dword to the NVM using the flash access registers.
  3648. * Goes through a retry algorithm before giving up.
  3649. **/
  3650. static s32 e1000_retry_write_flash_dword_ich8lan(struct e1000_hw *hw,
  3651. u32 offset, u32 dword)
  3652. {
  3653. s32 ret_val;
  3654. u16 program_retries;
  3655. /* Must convert word offset into bytes. */
  3656. offset <<= 1;
  3657. ret_val = e1000_write_flash_data32_ich8lan(hw, offset, dword);
  3658. if (!ret_val)
  3659. return ret_val;
  3660. for (program_retries = 0; program_retries < 100; program_retries++) {
  3661. e_dbg("Retrying Byte %8.8X at offset %u\n", dword, offset);
  3662. usleep_range(100, 200);
  3663. ret_val = e1000_write_flash_data32_ich8lan(hw, offset, dword);
  3664. if (!ret_val)
  3665. break;
  3666. }
  3667. if (program_retries == 100)
  3668. return -E1000_ERR_NVM;
  3669. return 0;
  3670. }
  3671. /**
  3672. * e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
  3673. * @hw: pointer to the HW structure
  3674. * @offset: The offset of the byte to write.
  3675. * @byte: The byte to write to the NVM.
  3676. *
  3677. * Writes a single byte to the NVM using the flash access registers.
  3678. * Goes through a retry algorithm before giving up.
  3679. **/
  3680. static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
  3681. u32 offset, u8 byte)
  3682. {
  3683. s32 ret_val;
  3684. u16 program_retries;
  3685. ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
  3686. if (!ret_val)
  3687. return ret_val;
  3688. for (program_retries = 0; program_retries < 100; program_retries++) {
  3689. e_dbg("Retrying Byte %2.2X at offset %u\n", byte, offset);
  3690. usleep_range(100, 200);
  3691. ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
  3692. if (!ret_val)
  3693. break;
  3694. }
  3695. if (program_retries == 100)
  3696. return -E1000_ERR_NVM;
  3697. return 0;
  3698. }
  3699. /**
  3700. * e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
  3701. * @hw: pointer to the HW structure
  3702. * @bank: 0 for first bank, 1 for second bank, etc.
  3703. *
  3704. * Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
  3705. * bank N is 4096 * N + flash_reg_addr.
  3706. **/
  3707. static s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
  3708. {
  3709. struct e1000_nvm_info *nvm = &hw->nvm;
  3710. union ich8_hws_flash_status hsfsts;
  3711. union ich8_hws_flash_ctrl hsflctl;
  3712. u32 flash_linear_addr;
  3713. /* bank size is in 16bit words - adjust to bytes */
  3714. u32 flash_bank_size = nvm->flash_bank_size * 2;
  3715. s32 ret_val;
  3716. s32 count = 0;
  3717. s32 j, iteration, sector_size;
  3718. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  3719. /* Determine HW Sector size: Read BERASE bits of hw flash status
  3720. * register
  3721. * 00: The Hw sector is 256 bytes, hence we need to erase 16
  3722. * consecutive sectors. The start index for the nth Hw sector
  3723. * can be calculated as = bank * 4096 + n * 256
  3724. * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
  3725. * The start index for the nth Hw sector can be calculated
  3726. * as = bank * 4096
  3727. * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
  3728. * (ich9 only, otherwise error condition)
  3729. * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
  3730. */
  3731. switch (hsfsts.hsf_status.berasesz) {
  3732. case 0:
  3733. /* Hw sector size 256 */
  3734. sector_size = ICH_FLASH_SEG_SIZE_256;
  3735. iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
  3736. break;
  3737. case 1:
  3738. sector_size = ICH_FLASH_SEG_SIZE_4K;
  3739. iteration = 1;
  3740. break;
  3741. case 2:
  3742. sector_size = ICH_FLASH_SEG_SIZE_8K;
  3743. iteration = 1;
  3744. break;
  3745. case 3:
  3746. sector_size = ICH_FLASH_SEG_SIZE_64K;
  3747. iteration = 1;
  3748. break;
  3749. default:
  3750. return -E1000_ERR_NVM;
  3751. }
  3752. /* Start with the base address, then add the sector offset. */
  3753. flash_linear_addr = hw->nvm.flash_base_addr;
  3754. flash_linear_addr += (bank) ? flash_bank_size : 0;
  3755. for (j = 0; j < iteration; j++) {
  3756. do {
  3757. u32 timeout = ICH_FLASH_ERASE_COMMAND_TIMEOUT;
  3758. /* Steps */
  3759. ret_val = e1000_flash_cycle_init_ich8lan(hw);
  3760. if (ret_val)
  3761. return ret_val;
  3762. /* Write a value 11 (block Erase) in Flash
  3763. * Cycle field in hw flash control
  3764. */
  3765. if (hw->mac.type == e1000_pch_spt)
  3766. hsflctl.regval =
  3767. er32flash(ICH_FLASH_HSFSTS) >> 16;
  3768. else
  3769. hsflctl.regval = er16flash(ICH_FLASH_HSFCTL);
  3770. hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
  3771. if (hw->mac.type == e1000_pch_spt)
  3772. ew32flash(ICH_FLASH_HSFSTS,
  3773. hsflctl.regval << 16);
  3774. else
  3775. ew16flash(ICH_FLASH_HSFCTL, hsflctl.regval);
  3776. /* Write the last 24 bits of an index within the
  3777. * block into Flash Linear address field in Flash
  3778. * Address.
  3779. */
  3780. flash_linear_addr += (j * sector_size);
  3781. ew32flash(ICH_FLASH_FADDR, flash_linear_addr);
  3782. ret_val = e1000_flash_cycle_ich8lan(hw, timeout);
  3783. if (!ret_val)
  3784. break;
  3785. /* Check if FCERR is set to 1. If 1,
  3786. * clear it and try the whole sequence
  3787. * a few more times else Done
  3788. */
  3789. hsfsts.regval = er16flash(ICH_FLASH_HSFSTS);
  3790. if (hsfsts.hsf_status.flcerr)
  3791. /* repeat for some time before giving up */
  3792. continue;
  3793. else if (!hsfsts.hsf_status.flcdone)
  3794. return ret_val;
  3795. } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
  3796. }
  3797. return 0;
  3798. }
  3799. /**
  3800. * e1000_valid_led_default_ich8lan - Set the default LED settings
  3801. * @hw: pointer to the HW structure
  3802. * @data: Pointer to the LED settings
  3803. *
  3804. * Reads the LED default settings from the NVM to data. If the NVM LED
  3805. * settings is all 0's or F's, set the LED default to a valid LED default
  3806. * setting.
  3807. **/
  3808. static s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
  3809. {
  3810. s32 ret_val;
  3811. ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
  3812. if (ret_val) {
  3813. e_dbg("NVM Read Error\n");
  3814. return ret_val;
  3815. }
  3816. if (*data == ID_LED_RESERVED_0000 || *data == ID_LED_RESERVED_FFFF)
  3817. *data = ID_LED_DEFAULT_ICH8LAN;
  3818. return 0;
  3819. }
  3820. /**
  3821. * e1000_id_led_init_pchlan - store LED configurations
  3822. * @hw: pointer to the HW structure
  3823. *
  3824. * PCH does not control LEDs via the LEDCTL register, rather it uses
  3825. * the PHY LED configuration register.
  3826. *
  3827. * PCH also does not have an "always on" or "always off" mode which
  3828. * complicates the ID feature. Instead of using the "on" mode to indicate
  3829. * in ledctl_mode2 the LEDs to use for ID (see e1000e_id_led_init_generic()),
  3830. * use "link_up" mode. The LEDs will still ID on request if there is no
  3831. * link based on logic in e1000_led_[on|off]_pchlan().
  3832. **/
  3833. static s32 e1000_id_led_init_pchlan(struct e1000_hw *hw)
  3834. {
  3835. struct e1000_mac_info *mac = &hw->mac;
  3836. s32 ret_val;
  3837. const u32 ledctl_on = E1000_LEDCTL_MODE_LINK_UP;
  3838. const u32 ledctl_off = E1000_LEDCTL_MODE_LINK_UP | E1000_PHY_LED0_IVRT;
  3839. u16 data, i, temp, shift;
  3840. /* Get default ID LED modes */
  3841. ret_val = hw->nvm.ops.valid_led_default(hw, &data);
  3842. if (ret_val)
  3843. return ret_val;
  3844. mac->ledctl_default = er32(LEDCTL);
  3845. mac->ledctl_mode1 = mac->ledctl_default;
  3846. mac->ledctl_mode2 = mac->ledctl_default;
  3847. for (i = 0; i < 4; i++) {
  3848. temp = (data >> (i << 2)) & E1000_LEDCTL_LED0_MODE_MASK;
  3849. shift = (i * 5);
  3850. switch (temp) {
  3851. case ID_LED_ON1_DEF2:
  3852. case ID_LED_ON1_ON2:
  3853. case ID_LED_ON1_OFF2:
  3854. mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
  3855. mac->ledctl_mode1 |= (ledctl_on << shift);
  3856. break;
  3857. case ID_LED_OFF1_DEF2:
  3858. case ID_LED_OFF1_ON2:
  3859. case ID_LED_OFF1_OFF2:
  3860. mac->ledctl_mode1 &= ~(E1000_PHY_LED0_MASK << shift);
  3861. mac->ledctl_mode1 |= (ledctl_off << shift);
  3862. break;
  3863. default:
  3864. /* Do nothing */
  3865. break;
  3866. }
  3867. switch (temp) {
  3868. case ID_LED_DEF1_ON2:
  3869. case ID_LED_ON1_ON2:
  3870. case ID_LED_OFF1_ON2:
  3871. mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
  3872. mac->ledctl_mode2 |= (ledctl_on << shift);
  3873. break;
  3874. case ID_LED_DEF1_OFF2:
  3875. case ID_LED_ON1_OFF2:
  3876. case ID_LED_OFF1_OFF2:
  3877. mac->ledctl_mode2 &= ~(E1000_PHY_LED0_MASK << shift);
  3878. mac->ledctl_mode2 |= (ledctl_off << shift);
  3879. break;
  3880. default:
  3881. /* Do nothing */
  3882. break;
  3883. }
  3884. }
  3885. return 0;
  3886. }
  3887. /**
  3888. * e1000_get_bus_info_ich8lan - Get/Set the bus type and width
  3889. * @hw: pointer to the HW structure
  3890. *
  3891. * ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
  3892. * register, so the the bus width is hard coded.
  3893. **/
  3894. static s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
  3895. {
  3896. struct e1000_bus_info *bus = &hw->bus;
  3897. s32 ret_val;
  3898. ret_val = e1000e_get_bus_info_pcie(hw);
  3899. /* ICH devices are "PCI Express"-ish. They have
  3900. * a configuration space, but do not contain
  3901. * PCI Express Capability registers, so bus width
  3902. * must be hardcoded.
  3903. */
  3904. if (bus->width == e1000_bus_width_unknown)
  3905. bus->width = e1000_bus_width_pcie_x1;
  3906. return ret_val;
  3907. }
  3908. /**
  3909. * e1000_reset_hw_ich8lan - Reset the hardware
  3910. * @hw: pointer to the HW structure
  3911. *
  3912. * Does a full reset of the hardware which includes a reset of the PHY and
  3913. * MAC.
  3914. **/
  3915. static s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
  3916. {
  3917. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  3918. u16 kum_cfg;
  3919. u32 ctrl, reg;
  3920. s32 ret_val;
  3921. /* Prevent the PCI-E bus from sticking if there is no TLP connection
  3922. * on the last TLP read/write transaction when MAC is reset.
  3923. */
  3924. ret_val = e1000e_disable_pcie_master(hw);
  3925. if (ret_val)
  3926. e_dbg("PCI-E Master disable polling has failed.\n");
  3927. e_dbg("Masking off all interrupts\n");
  3928. ew32(IMC, 0xffffffff);
  3929. /* Disable the Transmit and Receive units. Then delay to allow
  3930. * any pending transactions to complete before we hit the MAC
  3931. * with the global reset.
  3932. */
  3933. ew32(RCTL, 0);
  3934. ew32(TCTL, E1000_TCTL_PSP);
  3935. e1e_flush();
  3936. usleep_range(10000, 20000);
  3937. /* Workaround for ICH8 bit corruption issue in FIFO memory */
  3938. if (hw->mac.type == e1000_ich8lan) {
  3939. /* Set Tx and Rx buffer allocation to 8k apiece. */
  3940. ew32(PBA, E1000_PBA_8K);
  3941. /* Set Packet Buffer Size to 16k. */
  3942. ew32(PBS, E1000_PBS_16K);
  3943. }
  3944. if (hw->mac.type == e1000_pchlan) {
  3945. /* Save the NVM K1 bit setting */
  3946. ret_val = e1000_read_nvm(hw, E1000_NVM_K1_CONFIG, 1, &kum_cfg);
  3947. if (ret_val)
  3948. return ret_val;
  3949. if (kum_cfg & E1000_NVM_K1_ENABLE)
  3950. dev_spec->nvm_k1_enabled = true;
  3951. else
  3952. dev_spec->nvm_k1_enabled = false;
  3953. }
  3954. ctrl = er32(CTRL);
  3955. if (!hw->phy.ops.check_reset_block(hw)) {
  3956. /* Full-chip reset requires MAC and PHY reset at the same
  3957. * time to make sure the interface between MAC and the
  3958. * external PHY is reset.
  3959. */
  3960. ctrl |= E1000_CTRL_PHY_RST;
  3961. /* Gate automatic PHY configuration by hardware on
  3962. * non-managed 82579
  3963. */
  3964. if ((hw->mac.type == e1000_pch2lan) &&
  3965. !(er32(FWSM) & E1000_ICH_FWSM_FW_VALID))
  3966. e1000_gate_hw_phy_config_ich8lan(hw, true);
  3967. }
  3968. ret_val = e1000_acquire_swflag_ich8lan(hw);
  3969. e_dbg("Issuing a global reset to ich8lan\n");
  3970. ew32(CTRL, (ctrl | E1000_CTRL_RST));
  3971. /* cannot issue a flush here because it hangs the hardware */
  3972. msleep(20);
  3973. /* Set Phy Config Counter to 50msec */
  3974. if (hw->mac.type == e1000_pch2lan) {
  3975. reg = er32(FEXTNVM3);
  3976. reg &= ~E1000_FEXTNVM3_PHY_CFG_COUNTER_MASK;
  3977. reg |= E1000_FEXTNVM3_PHY_CFG_COUNTER_50MSEC;
  3978. ew32(FEXTNVM3, reg);
  3979. }
  3980. if (!ret_val)
  3981. clear_bit(__E1000_ACCESS_SHARED_RESOURCE, &hw->adapter->state);
  3982. if (ctrl & E1000_CTRL_PHY_RST) {
  3983. ret_val = hw->phy.ops.get_cfg_done(hw);
  3984. if (ret_val)
  3985. return ret_val;
  3986. ret_val = e1000_post_phy_reset_ich8lan(hw);
  3987. if (ret_val)
  3988. return ret_val;
  3989. }
  3990. /* For PCH, this write will make sure that any noise
  3991. * will be detected as a CRC error and be dropped rather than show up
  3992. * as a bad packet to the DMA engine.
  3993. */
  3994. if (hw->mac.type == e1000_pchlan)
  3995. ew32(CRC_OFFSET, 0x65656565);
  3996. ew32(IMC, 0xffffffff);
  3997. er32(ICR);
  3998. reg = er32(KABGTXD);
  3999. reg |= E1000_KABGTXD_BGSQLBIAS;
  4000. ew32(KABGTXD, reg);
  4001. return 0;
  4002. }
  4003. /**
  4004. * e1000_init_hw_ich8lan - Initialize the hardware
  4005. * @hw: pointer to the HW structure
  4006. *
  4007. * Prepares the hardware for transmit and receive by doing the following:
  4008. * - initialize hardware bits
  4009. * - initialize LED identification
  4010. * - setup receive address registers
  4011. * - setup flow control
  4012. * - setup transmit descriptors
  4013. * - clear statistics
  4014. **/
  4015. static s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
  4016. {
  4017. struct e1000_mac_info *mac = &hw->mac;
  4018. u32 ctrl_ext, txdctl, snoop;
  4019. s32 ret_val;
  4020. u16 i;
  4021. e1000_initialize_hw_bits_ich8lan(hw);
  4022. /* Initialize identification LED */
  4023. ret_val = mac->ops.id_led_init(hw);
  4024. /* An error is not fatal and we should not stop init due to this */
  4025. if (ret_val)
  4026. e_dbg("Error initializing identification LED\n");
  4027. /* Setup the receive address. */
  4028. e1000e_init_rx_addrs(hw, mac->rar_entry_count);
  4029. /* Zero out the Multicast HASH table */
  4030. e_dbg("Zeroing the MTA\n");
  4031. for (i = 0; i < mac->mta_reg_count; i++)
  4032. E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
  4033. /* The 82578 Rx buffer will stall if wakeup is enabled in host and
  4034. * the ME. Disable wakeup by clearing the host wakeup bit.
  4035. * Reset the phy after disabling host wakeup to reset the Rx buffer.
  4036. */
  4037. if (hw->phy.type == e1000_phy_82578) {
  4038. e1e_rphy(hw, BM_PORT_GEN_CFG, &i);
  4039. i &= ~BM_WUC_HOST_WU_BIT;
  4040. e1e_wphy(hw, BM_PORT_GEN_CFG, i);
  4041. ret_val = e1000_phy_hw_reset_ich8lan(hw);
  4042. if (ret_val)
  4043. return ret_val;
  4044. }
  4045. /* Setup link and flow control */
  4046. ret_val = mac->ops.setup_link(hw);
  4047. /* Set the transmit descriptor write-back policy for both queues */
  4048. txdctl = er32(TXDCTL(0));
  4049. txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
  4050. E1000_TXDCTL_FULL_TX_DESC_WB);
  4051. txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
  4052. E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
  4053. ew32(TXDCTL(0), txdctl);
  4054. txdctl = er32(TXDCTL(1));
  4055. txdctl = ((txdctl & ~E1000_TXDCTL_WTHRESH) |
  4056. E1000_TXDCTL_FULL_TX_DESC_WB);
  4057. txdctl = ((txdctl & ~E1000_TXDCTL_PTHRESH) |
  4058. E1000_TXDCTL_MAX_TX_DESC_PREFETCH);
  4059. ew32(TXDCTL(1), txdctl);
  4060. /* ICH8 has opposite polarity of no_snoop bits.
  4061. * By default, we should use snoop behavior.
  4062. */
  4063. if (mac->type == e1000_ich8lan)
  4064. snoop = PCIE_ICH8_SNOOP_ALL;
  4065. else
  4066. snoop = (u32)~(PCIE_NO_SNOOP_ALL);
  4067. e1000e_set_pcie_no_snoop(hw, snoop);
  4068. ctrl_ext = er32(CTRL_EXT);
  4069. ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
  4070. ew32(CTRL_EXT, ctrl_ext);
  4071. /* Clear all of the statistics registers (clear on read). It is
  4072. * important that we do this after we have tried to establish link
  4073. * because the symbol error count will increment wildly if there
  4074. * is no link.
  4075. */
  4076. e1000_clear_hw_cntrs_ich8lan(hw);
  4077. return ret_val;
  4078. }
  4079. /**
  4080. * e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
  4081. * @hw: pointer to the HW structure
  4082. *
  4083. * Sets/Clears required hardware bits necessary for correctly setting up the
  4084. * hardware for transmit and receive.
  4085. **/
  4086. static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
  4087. {
  4088. u32 reg;
  4089. /* Extended Device Control */
  4090. reg = er32(CTRL_EXT);
  4091. reg |= (1 << 22);
  4092. /* Enable PHY low-power state when MAC is at D3 w/o WoL */
  4093. if (hw->mac.type >= e1000_pchlan)
  4094. reg |= E1000_CTRL_EXT_PHYPDEN;
  4095. ew32(CTRL_EXT, reg);
  4096. /* Transmit Descriptor Control 0 */
  4097. reg = er32(TXDCTL(0));
  4098. reg |= (1 << 22);
  4099. ew32(TXDCTL(0), reg);
  4100. /* Transmit Descriptor Control 1 */
  4101. reg = er32(TXDCTL(1));
  4102. reg |= (1 << 22);
  4103. ew32(TXDCTL(1), reg);
  4104. /* Transmit Arbitration Control 0 */
  4105. reg = er32(TARC(0));
  4106. if (hw->mac.type == e1000_ich8lan)
  4107. reg |= (1 << 28) | (1 << 29);
  4108. reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
  4109. ew32(TARC(0), reg);
  4110. /* Transmit Arbitration Control 1 */
  4111. reg = er32(TARC(1));
  4112. if (er32(TCTL) & E1000_TCTL_MULR)
  4113. reg &= ~(1 << 28);
  4114. else
  4115. reg |= (1 << 28);
  4116. reg |= (1 << 24) | (1 << 26) | (1 << 30);
  4117. ew32(TARC(1), reg);
  4118. /* Device Status */
  4119. if (hw->mac.type == e1000_ich8lan) {
  4120. reg = er32(STATUS);
  4121. reg &= ~(1 << 31);
  4122. ew32(STATUS, reg);
  4123. }
  4124. /* work-around descriptor data corruption issue during nfs v2 udp
  4125. * traffic, just disable the nfs filtering capability
  4126. */
  4127. reg = er32(RFCTL);
  4128. reg |= (E1000_RFCTL_NFSW_DIS | E1000_RFCTL_NFSR_DIS);
  4129. /* Disable IPv6 extension header parsing because some malformed
  4130. * IPv6 headers can hang the Rx.
  4131. */
  4132. if (hw->mac.type == e1000_ich8lan)
  4133. reg |= (E1000_RFCTL_IPV6_EX_DIS | E1000_RFCTL_NEW_IPV6_EXT_DIS);
  4134. ew32(RFCTL, reg);
  4135. /* Enable ECC on Lynxpoint */
  4136. if ((hw->mac.type == e1000_pch_lpt) ||
  4137. (hw->mac.type == e1000_pch_spt)) {
  4138. reg = er32(PBECCSTS);
  4139. reg |= E1000_PBECCSTS_ECC_ENABLE;
  4140. ew32(PBECCSTS, reg);
  4141. reg = er32(CTRL);
  4142. reg |= E1000_CTRL_MEHE;
  4143. ew32(CTRL, reg);
  4144. }
  4145. }
  4146. /**
  4147. * e1000_setup_link_ich8lan - Setup flow control and link settings
  4148. * @hw: pointer to the HW structure
  4149. *
  4150. * Determines which flow control settings to use, then configures flow
  4151. * control. Calls the appropriate media-specific link configuration
  4152. * function. Assuming the adapter has a valid link partner, a valid link
  4153. * should be established. Assumes the hardware has previously been reset
  4154. * and the transmitter and receiver are not enabled.
  4155. **/
  4156. static s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
  4157. {
  4158. s32 ret_val;
  4159. if (hw->phy.ops.check_reset_block(hw))
  4160. return 0;
  4161. /* ICH parts do not have a word in the NVM to determine
  4162. * the default flow control setting, so we explicitly
  4163. * set it to full.
  4164. */
  4165. if (hw->fc.requested_mode == e1000_fc_default) {
  4166. /* Workaround h/w hang when Tx flow control enabled */
  4167. if (hw->mac.type == e1000_pchlan)
  4168. hw->fc.requested_mode = e1000_fc_rx_pause;
  4169. else
  4170. hw->fc.requested_mode = e1000_fc_full;
  4171. }
  4172. /* Save off the requested flow control mode for use later. Depending
  4173. * on the link partner's capabilities, we may or may not use this mode.
  4174. */
  4175. hw->fc.current_mode = hw->fc.requested_mode;
  4176. e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc.current_mode);
  4177. /* Continue to configure the copper link. */
  4178. ret_val = hw->mac.ops.setup_physical_interface(hw);
  4179. if (ret_val)
  4180. return ret_val;
  4181. ew32(FCTTV, hw->fc.pause_time);
  4182. if ((hw->phy.type == e1000_phy_82578) ||
  4183. (hw->phy.type == e1000_phy_82579) ||
  4184. (hw->phy.type == e1000_phy_i217) ||
  4185. (hw->phy.type == e1000_phy_82577)) {
  4186. ew32(FCRTV_PCH, hw->fc.refresh_time);
  4187. ret_val = e1e_wphy(hw, PHY_REG(BM_PORT_CTRL_PAGE, 27),
  4188. hw->fc.pause_time);
  4189. if (ret_val)
  4190. return ret_val;
  4191. }
  4192. return e1000e_set_fc_watermarks(hw);
  4193. }
  4194. /**
  4195. * e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
  4196. * @hw: pointer to the HW structure
  4197. *
  4198. * Configures the kumeran interface to the PHY to wait the appropriate time
  4199. * when polling the PHY, then call the generic setup_copper_link to finish
  4200. * configuring the copper link.
  4201. **/
  4202. static s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
  4203. {
  4204. u32 ctrl;
  4205. s32 ret_val;
  4206. u16 reg_data;
  4207. ctrl = er32(CTRL);
  4208. ctrl |= E1000_CTRL_SLU;
  4209. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  4210. ew32(CTRL, ctrl);
  4211. /* Set the mac to wait the maximum time between each iteration
  4212. * and increase the max iterations when polling the phy;
  4213. * this fixes erroneous timeouts at 10Mbps.
  4214. */
  4215. ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_TIMEOUTS, 0xFFFF);
  4216. if (ret_val)
  4217. return ret_val;
  4218. ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
  4219. &reg_data);
  4220. if (ret_val)
  4221. return ret_val;
  4222. reg_data |= 0x3F;
  4223. ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_INBAND_PARAM,
  4224. reg_data);
  4225. if (ret_val)
  4226. return ret_val;
  4227. switch (hw->phy.type) {
  4228. case e1000_phy_igp_3:
  4229. ret_val = e1000e_copper_link_setup_igp(hw);
  4230. if (ret_val)
  4231. return ret_val;
  4232. break;
  4233. case e1000_phy_bm:
  4234. case e1000_phy_82578:
  4235. ret_val = e1000e_copper_link_setup_m88(hw);
  4236. if (ret_val)
  4237. return ret_val;
  4238. break;
  4239. case e1000_phy_82577:
  4240. case e1000_phy_82579:
  4241. ret_val = e1000_copper_link_setup_82577(hw);
  4242. if (ret_val)
  4243. return ret_val;
  4244. break;
  4245. case e1000_phy_ife:
  4246. ret_val = e1e_rphy(hw, IFE_PHY_MDIX_CONTROL, &reg_data);
  4247. if (ret_val)
  4248. return ret_val;
  4249. reg_data &= ~IFE_PMC_AUTO_MDIX;
  4250. switch (hw->phy.mdix) {
  4251. case 1:
  4252. reg_data &= ~IFE_PMC_FORCE_MDIX;
  4253. break;
  4254. case 2:
  4255. reg_data |= IFE_PMC_FORCE_MDIX;
  4256. break;
  4257. case 0:
  4258. default:
  4259. reg_data |= IFE_PMC_AUTO_MDIX;
  4260. break;
  4261. }
  4262. ret_val = e1e_wphy(hw, IFE_PHY_MDIX_CONTROL, reg_data);
  4263. if (ret_val)
  4264. return ret_val;
  4265. break;
  4266. default:
  4267. break;
  4268. }
  4269. return e1000e_setup_copper_link(hw);
  4270. }
  4271. /**
  4272. * e1000_setup_copper_link_pch_lpt - Configure MAC/PHY interface
  4273. * @hw: pointer to the HW structure
  4274. *
  4275. * Calls the PHY specific link setup function and then calls the
  4276. * generic setup_copper_link to finish configuring the link for
  4277. * Lynxpoint PCH devices
  4278. **/
  4279. static s32 e1000_setup_copper_link_pch_lpt(struct e1000_hw *hw)
  4280. {
  4281. u32 ctrl;
  4282. s32 ret_val;
  4283. ctrl = er32(CTRL);
  4284. ctrl |= E1000_CTRL_SLU;
  4285. ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
  4286. ew32(CTRL, ctrl);
  4287. ret_val = e1000_copper_link_setup_82577(hw);
  4288. if (ret_val)
  4289. return ret_val;
  4290. return e1000e_setup_copper_link(hw);
  4291. }
  4292. /**
  4293. * e1000_get_link_up_info_ich8lan - Get current link speed and duplex
  4294. * @hw: pointer to the HW structure
  4295. * @speed: pointer to store current link speed
  4296. * @duplex: pointer to store the current link duplex
  4297. *
  4298. * Calls the generic get_speed_and_duplex to retrieve the current link
  4299. * information and then calls the Kumeran lock loss workaround for links at
  4300. * gigabit speeds.
  4301. **/
  4302. static s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
  4303. u16 *duplex)
  4304. {
  4305. s32 ret_val;
  4306. ret_val = e1000e_get_speed_and_duplex_copper(hw, speed, duplex);
  4307. if (ret_val)
  4308. return ret_val;
  4309. if ((hw->mac.type == e1000_ich8lan) &&
  4310. (hw->phy.type == e1000_phy_igp_3) && (*speed == SPEED_1000)) {
  4311. ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
  4312. }
  4313. return ret_val;
  4314. }
  4315. /**
  4316. * e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
  4317. * @hw: pointer to the HW structure
  4318. *
  4319. * Work-around for 82566 Kumeran PCS lock loss:
  4320. * On link status change (i.e. PCI reset, speed change) and link is up and
  4321. * speed is gigabit-
  4322. * 0) if workaround is optionally disabled do nothing
  4323. * 1) wait 1ms for Kumeran link to come up
  4324. * 2) check Kumeran Diagnostic register PCS lock loss bit
  4325. * 3) if not set the link is locked (all is good), otherwise...
  4326. * 4) reset the PHY
  4327. * 5) repeat up to 10 times
  4328. * Note: this is only called for IGP3 copper when speed is 1gb.
  4329. **/
  4330. static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
  4331. {
  4332. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  4333. u32 phy_ctrl;
  4334. s32 ret_val;
  4335. u16 i, data;
  4336. bool link;
  4337. if (!dev_spec->kmrn_lock_loss_workaround_enabled)
  4338. return 0;
  4339. /* Make sure link is up before proceeding. If not just return.
  4340. * Attempting this while link is negotiating fouled up link
  4341. * stability
  4342. */
  4343. ret_val = e1000e_phy_has_link_generic(hw, 1, 0, &link);
  4344. if (!link)
  4345. return 0;
  4346. for (i = 0; i < 10; i++) {
  4347. /* read once to clear */
  4348. ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
  4349. if (ret_val)
  4350. return ret_val;
  4351. /* and again to get new status */
  4352. ret_val = e1e_rphy(hw, IGP3_KMRN_DIAG, &data);
  4353. if (ret_val)
  4354. return ret_val;
  4355. /* check for PCS lock */
  4356. if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS))
  4357. return 0;
  4358. /* Issue PHY reset */
  4359. e1000_phy_hw_reset(hw);
  4360. mdelay(5);
  4361. }
  4362. /* Disable GigE link negotiation */
  4363. phy_ctrl = er32(PHY_CTRL);
  4364. phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
  4365. E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
  4366. ew32(PHY_CTRL, phy_ctrl);
  4367. /* Call gig speed drop workaround on Gig disable before accessing
  4368. * any PHY registers
  4369. */
  4370. e1000e_gig_downshift_workaround_ich8lan(hw);
  4371. /* unable to acquire PCS lock */
  4372. return -E1000_ERR_PHY;
  4373. }
  4374. /**
  4375. * e1000e_set_kmrn_lock_loss_workaround_ich8lan - Set Kumeran workaround state
  4376. * @hw: pointer to the HW structure
  4377. * @state: boolean value used to set the current Kumeran workaround state
  4378. *
  4379. * If ICH8, set the current Kumeran workaround state (enabled - true
  4380. * /disabled - false).
  4381. **/
  4382. void e1000e_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
  4383. bool state)
  4384. {
  4385. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  4386. if (hw->mac.type != e1000_ich8lan) {
  4387. e_dbg("Workaround applies to ICH8 only.\n");
  4388. return;
  4389. }
  4390. dev_spec->kmrn_lock_loss_workaround_enabled = state;
  4391. }
  4392. /**
  4393. * e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
  4394. * @hw: pointer to the HW structure
  4395. *
  4396. * Workaround for 82566 power-down on D3 entry:
  4397. * 1) disable gigabit link
  4398. * 2) write VR power-down enable
  4399. * 3) read it back
  4400. * Continue if successful, else issue LCD reset and repeat
  4401. **/
  4402. void e1000e_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
  4403. {
  4404. u32 reg;
  4405. u16 data;
  4406. u8 retry = 0;
  4407. if (hw->phy.type != e1000_phy_igp_3)
  4408. return;
  4409. /* Try the workaround twice (if needed) */
  4410. do {
  4411. /* Disable link */
  4412. reg = er32(PHY_CTRL);
  4413. reg |= (E1000_PHY_CTRL_GBE_DISABLE |
  4414. E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
  4415. ew32(PHY_CTRL, reg);
  4416. /* Call gig speed drop workaround on Gig disable before
  4417. * accessing any PHY registers
  4418. */
  4419. if (hw->mac.type == e1000_ich8lan)
  4420. e1000e_gig_downshift_workaround_ich8lan(hw);
  4421. /* Write VR power-down enable */
  4422. e1e_rphy(hw, IGP3_VR_CTRL, &data);
  4423. data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
  4424. e1e_wphy(hw, IGP3_VR_CTRL, data | IGP3_VR_CTRL_MODE_SHUTDOWN);
  4425. /* Read it back and test */
  4426. e1e_rphy(hw, IGP3_VR_CTRL, &data);
  4427. data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
  4428. if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
  4429. break;
  4430. /* Issue PHY reset and repeat at most one more time */
  4431. reg = er32(CTRL);
  4432. ew32(CTRL, reg | E1000_CTRL_PHY_RST);
  4433. retry++;
  4434. } while (retry);
  4435. }
  4436. /**
  4437. * e1000e_gig_downshift_workaround_ich8lan - WoL from S5 stops working
  4438. * @hw: pointer to the HW structure
  4439. *
  4440. * Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
  4441. * LPLU, Gig disable, MDIC PHY reset):
  4442. * 1) Set Kumeran Near-end loopback
  4443. * 2) Clear Kumeran Near-end loopback
  4444. * Should only be called for ICH8[m] devices with any 1G Phy.
  4445. **/
  4446. void e1000e_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
  4447. {
  4448. s32 ret_val;
  4449. u16 reg_data;
  4450. if ((hw->mac.type != e1000_ich8lan) || (hw->phy.type == e1000_phy_ife))
  4451. return;
  4452. ret_val = e1000e_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
  4453. &reg_data);
  4454. if (ret_val)
  4455. return;
  4456. reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
  4457. ret_val = e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
  4458. reg_data);
  4459. if (ret_val)
  4460. return;
  4461. reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
  4462. e1000e_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET, reg_data);
  4463. }
  4464. /**
  4465. * e1000_suspend_workarounds_ich8lan - workarounds needed during S0->Sx
  4466. * @hw: pointer to the HW structure
  4467. *
  4468. * During S0 to Sx transition, it is possible the link remains at gig
  4469. * instead of negotiating to a lower speed. Before going to Sx, set
  4470. * 'Gig Disable' to force link speed negotiation to a lower speed based on
  4471. * the LPLU setting in the NVM or custom setting. For PCH and newer parts,
  4472. * the OEM bits PHY register (LED, GbE disable and LPLU configurations) also
  4473. * needs to be written.
  4474. * Parts that support (and are linked to a partner which support) EEE in
  4475. * 100Mbps should disable LPLU since 100Mbps w/ EEE requires less power
  4476. * than 10Mbps w/o EEE.
  4477. **/
  4478. void e1000_suspend_workarounds_ich8lan(struct e1000_hw *hw)
  4479. {
  4480. struct e1000_dev_spec_ich8lan *dev_spec = &hw->dev_spec.ich8lan;
  4481. u32 phy_ctrl;
  4482. s32 ret_val;
  4483. phy_ctrl = er32(PHY_CTRL);
  4484. phy_ctrl |= E1000_PHY_CTRL_GBE_DISABLE;
  4485. if (hw->phy.type == e1000_phy_i217) {
  4486. u16 phy_reg, device_id = hw->adapter->pdev->device;
  4487. if ((device_id == E1000_DEV_ID_PCH_LPTLP_I218_LM) ||
  4488. (device_id == E1000_DEV_ID_PCH_LPTLP_I218_V) ||
  4489. (device_id == E1000_DEV_ID_PCH_I218_LM3) ||
  4490. (device_id == E1000_DEV_ID_PCH_I218_V3) ||
  4491. (hw->mac.type == e1000_pch_spt)) {
  4492. u32 fextnvm6 = er32(FEXTNVM6);
  4493. ew32(FEXTNVM6, fextnvm6 & ~E1000_FEXTNVM6_REQ_PLL_CLK);
  4494. }
  4495. ret_val = hw->phy.ops.acquire(hw);
  4496. if (ret_val)
  4497. goto out;
  4498. if (!dev_spec->eee_disable) {
  4499. u16 eee_advert;
  4500. ret_val =
  4501. e1000_read_emi_reg_locked(hw,
  4502. I217_EEE_ADVERTISEMENT,
  4503. &eee_advert);
  4504. if (ret_val)
  4505. goto release;
  4506. /* Disable LPLU if both link partners support 100BaseT
  4507. * EEE and 100Full is advertised on both ends of the
  4508. * link, and enable Auto Enable LPI since there will
  4509. * be no driver to enable LPI while in Sx.
  4510. */
  4511. if ((eee_advert & I82579_EEE_100_SUPPORTED) &&
  4512. (dev_spec->eee_lp_ability &
  4513. I82579_EEE_100_SUPPORTED) &&
  4514. (hw->phy.autoneg_advertised & ADVERTISE_100_FULL)) {
  4515. phy_ctrl &= ~(E1000_PHY_CTRL_D0A_LPLU |
  4516. E1000_PHY_CTRL_NOND0A_LPLU);
  4517. /* Set Auto Enable LPI after link up */
  4518. e1e_rphy_locked(hw,
  4519. I217_LPI_GPIO_CTRL, &phy_reg);
  4520. phy_reg |= I217_LPI_GPIO_CTRL_AUTO_EN_LPI;
  4521. e1e_wphy_locked(hw,
  4522. I217_LPI_GPIO_CTRL, phy_reg);
  4523. }
  4524. }
  4525. /* For i217 Intel Rapid Start Technology support,
  4526. * when the system is going into Sx and no manageability engine
  4527. * is present, the driver must configure proxy to reset only on
  4528. * power good. LPI (Low Power Idle) state must also reset only
  4529. * on power good, as well as the MTA (Multicast table array).
  4530. * The SMBus release must also be disabled on LCD reset.
  4531. */
  4532. if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
  4533. /* Enable proxy to reset only on power good. */
  4534. e1e_rphy_locked(hw, I217_PROXY_CTRL, &phy_reg);
  4535. phy_reg |= I217_PROXY_CTRL_AUTO_DISABLE;
  4536. e1e_wphy_locked(hw, I217_PROXY_CTRL, phy_reg);
  4537. /* Set bit enable LPI (EEE) to reset only on
  4538. * power good.
  4539. */
  4540. e1e_rphy_locked(hw, I217_SxCTRL, &phy_reg);
  4541. phy_reg |= I217_SxCTRL_ENABLE_LPI_RESET;
  4542. e1e_wphy_locked(hw, I217_SxCTRL, phy_reg);
  4543. /* Disable the SMB release on LCD reset. */
  4544. e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
  4545. phy_reg &= ~I217_MEMPWR_DISABLE_SMB_RELEASE;
  4546. e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
  4547. }
  4548. /* Enable MTA to reset for Intel Rapid Start Technology
  4549. * Support
  4550. */
  4551. e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
  4552. phy_reg |= I217_CGFREG_ENABLE_MTA_RESET;
  4553. e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
  4554. release:
  4555. hw->phy.ops.release(hw);
  4556. }
  4557. out:
  4558. ew32(PHY_CTRL, phy_ctrl);
  4559. if (hw->mac.type == e1000_ich8lan)
  4560. e1000e_gig_downshift_workaround_ich8lan(hw);
  4561. if (hw->mac.type >= e1000_pchlan) {
  4562. e1000_oem_bits_config_ich8lan(hw, false);
  4563. /* Reset PHY to activate OEM bits on 82577/8 */
  4564. if (hw->mac.type == e1000_pchlan)
  4565. e1000e_phy_hw_reset_generic(hw);
  4566. ret_val = hw->phy.ops.acquire(hw);
  4567. if (ret_val)
  4568. return;
  4569. e1000_write_smbus_addr(hw);
  4570. hw->phy.ops.release(hw);
  4571. }
  4572. }
  4573. /**
  4574. * e1000_resume_workarounds_pchlan - workarounds needed during Sx->S0
  4575. * @hw: pointer to the HW structure
  4576. *
  4577. * During Sx to S0 transitions on non-managed devices or managed devices
  4578. * on which PHY resets are not blocked, if the PHY registers cannot be
  4579. * accessed properly by the s/w toggle the LANPHYPC value to power cycle
  4580. * the PHY.
  4581. * On i217, setup Intel Rapid Start Technology.
  4582. **/
  4583. void e1000_resume_workarounds_pchlan(struct e1000_hw *hw)
  4584. {
  4585. s32 ret_val;
  4586. if (hw->mac.type < e1000_pch2lan)
  4587. return;
  4588. ret_val = e1000_init_phy_workarounds_pchlan(hw);
  4589. if (ret_val) {
  4590. e_dbg("Failed to init PHY flow ret_val=%d\n", ret_val);
  4591. return;
  4592. }
  4593. /* For i217 Intel Rapid Start Technology support when the system
  4594. * is transitioning from Sx and no manageability engine is present
  4595. * configure SMBus to restore on reset, disable proxy, and enable
  4596. * the reset on MTA (Multicast table array).
  4597. */
  4598. if (hw->phy.type == e1000_phy_i217) {
  4599. u16 phy_reg;
  4600. ret_val = hw->phy.ops.acquire(hw);
  4601. if (ret_val) {
  4602. e_dbg("Failed to setup iRST\n");
  4603. return;
  4604. }
  4605. /* Clear Auto Enable LPI after link up */
  4606. e1e_rphy_locked(hw, I217_LPI_GPIO_CTRL, &phy_reg);
  4607. phy_reg &= ~I217_LPI_GPIO_CTRL_AUTO_EN_LPI;
  4608. e1e_wphy_locked(hw, I217_LPI_GPIO_CTRL, phy_reg);
  4609. if (!(er32(FWSM) & E1000_ICH_FWSM_FW_VALID)) {
  4610. /* Restore clear on SMB if no manageability engine
  4611. * is present
  4612. */
  4613. ret_val = e1e_rphy_locked(hw, I217_MEMPWR, &phy_reg);
  4614. if (ret_val)
  4615. goto release;
  4616. phy_reg |= I217_MEMPWR_DISABLE_SMB_RELEASE;
  4617. e1e_wphy_locked(hw, I217_MEMPWR, phy_reg);
  4618. /* Disable Proxy */
  4619. e1e_wphy_locked(hw, I217_PROXY_CTRL, 0);
  4620. }
  4621. /* Enable reset on MTA */
  4622. ret_val = e1e_rphy_locked(hw, I217_CGFREG, &phy_reg);
  4623. if (ret_val)
  4624. goto release;
  4625. phy_reg &= ~I217_CGFREG_ENABLE_MTA_RESET;
  4626. e1e_wphy_locked(hw, I217_CGFREG, phy_reg);
  4627. release:
  4628. if (ret_val)
  4629. e_dbg("Error %d in resume workarounds\n", ret_val);
  4630. hw->phy.ops.release(hw);
  4631. }
  4632. }
  4633. /**
  4634. * e1000_cleanup_led_ich8lan - Restore the default LED operation
  4635. * @hw: pointer to the HW structure
  4636. *
  4637. * Return the LED back to the default configuration.
  4638. **/
  4639. static s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
  4640. {
  4641. if (hw->phy.type == e1000_phy_ife)
  4642. return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED, 0);
  4643. ew32(LEDCTL, hw->mac.ledctl_default);
  4644. return 0;
  4645. }
  4646. /**
  4647. * e1000_led_on_ich8lan - Turn LEDs on
  4648. * @hw: pointer to the HW structure
  4649. *
  4650. * Turn on the LEDs.
  4651. **/
  4652. static s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
  4653. {
  4654. if (hw->phy.type == e1000_phy_ife)
  4655. return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
  4656. (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
  4657. ew32(LEDCTL, hw->mac.ledctl_mode2);
  4658. return 0;
  4659. }
  4660. /**
  4661. * e1000_led_off_ich8lan - Turn LEDs off
  4662. * @hw: pointer to the HW structure
  4663. *
  4664. * Turn off the LEDs.
  4665. **/
  4666. static s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
  4667. {
  4668. if (hw->phy.type == e1000_phy_ife)
  4669. return e1e_wphy(hw, IFE_PHY_SPECIAL_CONTROL_LED,
  4670. (IFE_PSCL_PROBE_MODE |
  4671. IFE_PSCL_PROBE_LEDS_OFF));
  4672. ew32(LEDCTL, hw->mac.ledctl_mode1);
  4673. return 0;
  4674. }
  4675. /**
  4676. * e1000_setup_led_pchlan - Configures SW controllable LED
  4677. * @hw: pointer to the HW structure
  4678. *
  4679. * This prepares the SW controllable LED for use.
  4680. **/
  4681. static s32 e1000_setup_led_pchlan(struct e1000_hw *hw)
  4682. {
  4683. return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_mode1);
  4684. }
  4685. /**
  4686. * e1000_cleanup_led_pchlan - Restore the default LED operation
  4687. * @hw: pointer to the HW structure
  4688. *
  4689. * Return the LED back to the default configuration.
  4690. **/
  4691. static s32 e1000_cleanup_led_pchlan(struct e1000_hw *hw)
  4692. {
  4693. return e1e_wphy(hw, HV_LED_CONFIG, (u16)hw->mac.ledctl_default);
  4694. }
  4695. /**
  4696. * e1000_led_on_pchlan - Turn LEDs on
  4697. * @hw: pointer to the HW structure
  4698. *
  4699. * Turn on the LEDs.
  4700. **/
  4701. static s32 e1000_led_on_pchlan(struct e1000_hw *hw)
  4702. {
  4703. u16 data = (u16)hw->mac.ledctl_mode2;
  4704. u32 i, led;
  4705. /* If no link, then turn LED on by setting the invert bit
  4706. * for each LED that's mode is "link_up" in ledctl_mode2.
  4707. */
  4708. if (!(er32(STATUS) & E1000_STATUS_LU)) {
  4709. for (i = 0; i < 3; i++) {
  4710. led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
  4711. if ((led & E1000_PHY_LED0_MODE_MASK) !=
  4712. E1000_LEDCTL_MODE_LINK_UP)
  4713. continue;
  4714. if (led & E1000_PHY_LED0_IVRT)
  4715. data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
  4716. else
  4717. data |= (E1000_PHY_LED0_IVRT << (i * 5));
  4718. }
  4719. }
  4720. return e1e_wphy(hw, HV_LED_CONFIG, data);
  4721. }
  4722. /**
  4723. * e1000_led_off_pchlan - Turn LEDs off
  4724. * @hw: pointer to the HW structure
  4725. *
  4726. * Turn off the LEDs.
  4727. **/
  4728. static s32 e1000_led_off_pchlan(struct e1000_hw *hw)
  4729. {
  4730. u16 data = (u16)hw->mac.ledctl_mode1;
  4731. u32 i, led;
  4732. /* If no link, then turn LED off by clearing the invert bit
  4733. * for each LED that's mode is "link_up" in ledctl_mode1.
  4734. */
  4735. if (!(er32(STATUS) & E1000_STATUS_LU)) {
  4736. for (i = 0; i < 3; i++) {
  4737. led = (data >> (i * 5)) & E1000_PHY_LED0_MASK;
  4738. if ((led & E1000_PHY_LED0_MODE_MASK) !=
  4739. E1000_LEDCTL_MODE_LINK_UP)
  4740. continue;
  4741. if (led & E1000_PHY_LED0_IVRT)
  4742. data &= ~(E1000_PHY_LED0_IVRT << (i * 5));
  4743. else
  4744. data |= (E1000_PHY_LED0_IVRT << (i * 5));
  4745. }
  4746. }
  4747. return e1e_wphy(hw, HV_LED_CONFIG, data);
  4748. }
  4749. /**
  4750. * e1000_get_cfg_done_ich8lan - Read config done bit after Full or PHY reset
  4751. * @hw: pointer to the HW structure
  4752. *
  4753. * Read appropriate register for the config done bit for completion status
  4754. * and configure the PHY through s/w for EEPROM-less parts.
  4755. *
  4756. * NOTE: some silicon which is EEPROM-less will fail trying to read the
  4757. * config done bit, so only an error is logged and continues. If we were
  4758. * to return with error, EEPROM-less silicon would not be able to be reset
  4759. * or change link.
  4760. **/
  4761. static s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
  4762. {
  4763. s32 ret_val = 0;
  4764. u32 bank = 0;
  4765. u32 status;
  4766. e1000e_get_cfg_done_generic(hw);
  4767. /* Wait for indication from h/w that it has completed basic config */
  4768. if (hw->mac.type >= e1000_ich10lan) {
  4769. e1000_lan_init_done_ich8lan(hw);
  4770. } else {
  4771. ret_val = e1000e_get_auto_rd_done(hw);
  4772. if (ret_val) {
  4773. /* When auto config read does not complete, do not
  4774. * return with an error. This can happen in situations
  4775. * where there is no eeprom and prevents getting link.
  4776. */
  4777. e_dbg("Auto Read Done did not complete\n");
  4778. ret_val = 0;
  4779. }
  4780. }
  4781. /* Clear PHY Reset Asserted bit */
  4782. status = er32(STATUS);
  4783. if (status & E1000_STATUS_PHYRA)
  4784. ew32(STATUS, status & ~E1000_STATUS_PHYRA);
  4785. else
  4786. e_dbg("PHY Reset Asserted not set - needs delay\n");
  4787. /* If EEPROM is not marked present, init the IGP 3 PHY manually */
  4788. if (hw->mac.type <= e1000_ich9lan) {
  4789. if (!(er32(EECD) & E1000_EECD_PRES) &&
  4790. (hw->phy.type == e1000_phy_igp_3)) {
  4791. e1000e_phy_init_script_igp3(hw);
  4792. }
  4793. } else {
  4794. if (e1000_valid_nvm_bank_detect_ich8lan(hw, &bank)) {
  4795. /* Maybe we should do a basic PHY config */
  4796. e_dbg("EEPROM not present\n");
  4797. ret_val = -E1000_ERR_CONFIG;
  4798. }
  4799. }
  4800. return ret_val;
  4801. }
  4802. /**
  4803. * e1000_power_down_phy_copper_ich8lan - Remove link during PHY power down
  4804. * @hw: pointer to the HW structure
  4805. *
  4806. * In the case of a PHY power down to save power, or to turn off link during a
  4807. * driver unload, or wake on lan is not enabled, remove the link.
  4808. **/
  4809. static void e1000_power_down_phy_copper_ich8lan(struct e1000_hw *hw)
  4810. {
  4811. /* If the management interface is not enabled, then power down */
  4812. if (!(hw->mac.ops.check_mng_mode(hw) ||
  4813. hw->phy.ops.check_reset_block(hw)))
  4814. e1000_power_down_phy_copper(hw);
  4815. }
  4816. /**
  4817. * e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
  4818. * @hw: pointer to the HW structure
  4819. *
  4820. * Clears hardware counters specific to the silicon family and calls
  4821. * clear_hw_cntrs_generic to clear all general purpose counters.
  4822. **/
  4823. static void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
  4824. {
  4825. u16 phy_data;
  4826. s32 ret_val;
  4827. e1000e_clear_hw_cntrs_base(hw);
  4828. er32(ALGNERRC);
  4829. er32(RXERRC);
  4830. er32(TNCRS);
  4831. er32(CEXTERR);
  4832. er32(TSCTC);
  4833. er32(TSCTFC);
  4834. er32(MGTPRC);
  4835. er32(MGTPDC);
  4836. er32(MGTPTC);
  4837. er32(IAC);
  4838. er32(ICRXOC);
  4839. /* Clear PHY statistics registers */
  4840. if ((hw->phy.type == e1000_phy_82578) ||
  4841. (hw->phy.type == e1000_phy_82579) ||
  4842. (hw->phy.type == e1000_phy_i217) ||
  4843. (hw->phy.type == e1000_phy_82577)) {
  4844. ret_val = hw->phy.ops.acquire(hw);
  4845. if (ret_val)
  4846. return;
  4847. ret_val = hw->phy.ops.set_page(hw,
  4848. HV_STATS_PAGE << IGP_PAGE_SHIFT);
  4849. if (ret_val)
  4850. goto release;
  4851. hw->phy.ops.read_reg_page(hw, HV_SCC_UPPER, &phy_data);
  4852. hw->phy.ops.read_reg_page(hw, HV_SCC_LOWER, &phy_data);
  4853. hw->phy.ops.read_reg_page(hw, HV_ECOL_UPPER, &phy_data);
  4854. hw->phy.ops.read_reg_page(hw, HV_ECOL_LOWER, &phy_data);
  4855. hw->phy.ops.read_reg_page(hw, HV_MCC_UPPER, &phy_data);
  4856. hw->phy.ops.read_reg_page(hw, HV_MCC_LOWER, &phy_data);
  4857. hw->phy.ops.read_reg_page(hw, HV_LATECOL_UPPER, &phy_data);
  4858. hw->phy.ops.read_reg_page(hw, HV_LATECOL_LOWER, &phy_data);
  4859. hw->phy.ops.read_reg_page(hw, HV_COLC_UPPER, &phy_data);
  4860. hw->phy.ops.read_reg_page(hw, HV_COLC_LOWER, &phy_data);
  4861. hw->phy.ops.read_reg_page(hw, HV_DC_UPPER, &phy_data);
  4862. hw->phy.ops.read_reg_page(hw, HV_DC_LOWER, &phy_data);
  4863. hw->phy.ops.read_reg_page(hw, HV_TNCRS_UPPER, &phy_data);
  4864. hw->phy.ops.read_reg_page(hw, HV_TNCRS_LOWER, &phy_data);
  4865. release:
  4866. hw->phy.ops.release(hw);
  4867. }
  4868. }
  4869. static const struct e1000_mac_operations ich8_mac_ops = {
  4870. /* check_mng_mode dependent on mac type */
  4871. .check_for_link = e1000_check_for_copper_link_ich8lan,
  4872. /* cleanup_led dependent on mac type */
  4873. .clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan,
  4874. .get_bus_info = e1000_get_bus_info_ich8lan,
  4875. .set_lan_id = e1000_set_lan_id_single_port,
  4876. .get_link_up_info = e1000_get_link_up_info_ich8lan,
  4877. /* led_on dependent on mac type */
  4878. /* led_off dependent on mac type */
  4879. .update_mc_addr_list = e1000e_update_mc_addr_list_generic,
  4880. .reset_hw = e1000_reset_hw_ich8lan,
  4881. .init_hw = e1000_init_hw_ich8lan,
  4882. .setup_link = e1000_setup_link_ich8lan,
  4883. .setup_physical_interface = e1000_setup_copper_link_ich8lan,
  4884. /* id_led_init dependent on mac type */
  4885. .config_collision_dist = e1000e_config_collision_dist_generic,
  4886. .rar_set = e1000e_rar_set_generic,
  4887. .rar_get_count = e1000e_rar_get_count_generic,
  4888. };
  4889. static const struct e1000_phy_operations ich8_phy_ops = {
  4890. .acquire = e1000_acquire_swflag_ich8lan,
  4891. .check_reset_block = e1000_check_reset_block_ich8lan,
  4892. .commit = NULL,
  4893. .get_cfg_done = e1000_get_cfg_done_ich8lan,
  4894. .get_cable_length = e1000e_get_cable_length_igp_2,
  4895. .read_reg = e1000e_read_phy_reg_igp,
  4896. .release = e1000_release_swflag_ich8lan,
  4897. .reset = e1000_phy_hw_reset_ich8lan,
  4898. .set_d0_lplu_state = e1000_set_d0_lplu_state_ich8lan,
  4899. .set_d3_lplu_state = e1000_set_d3_lplu_state_ich8lan,
  4900. .write_reg = e1000e_write_phy_reg_igp,
  4901. };
  4902. static const struct e1000_nvm_operations ich8_nvm_ops = {
  4903. .acquire = e1000_acquire_nvm_ich8lan,
  4904. .read = e1000_read_nvm_ich8lan,
  4905. .release = e1000_release_nvm_ich8lan,
  4906. .reload = e1000e_reload_nvm_generic,
  4907. .update = e1000_update_nvm_checksum_ich8lan,
  4908. .valid_led_default = e1000_valid_led_default_ich8lan,
  4909. .validate = e1000_validate_nvm_checksum_ich8lan,
  4910. .write = e1000_write_nvm_ich8lan,
  4911. };
  4912. static const struct e1000_nvm_operations spt_nvm_ops = {
  4913. .acquire = e1000_acquire_nvm_ich8lan,
  4914. .release = e1000_release_nvm_ich8lan,
  4915. .read = e1000_read_nvm_spt,
  4916. .update = e1000_update_nvm_checksum_spt,
  4917. .reload = e1000e_reload_nvm_generic,
  4918. .valid_led_default = e1000_valid_led_default_ich8lan,
  4919. .validate = e1000_validate_nvm_checksum_ich8lan,
  4920. .write = e1000_write_nvm_ich8lan,
  4921. };
  4922. const struct e1000_info e1000_ich8_info = {
  4923. .mac = e1000_ich8lan,
  4924. .flags = FLAG_HAS_WOL
  4925. | FLAG_IS_ICH
  4926. | FLAG_HAS_CTRLEXT_ON_LOAD
  4927. | FLAG_HAS_AMT
  4928. | FLAG_HAS_FLASH
  4929. | FLAG_APME_IN_WUC,
  4930. .pba = 8,
  4931. .max_hw_frame_size = ETH_FRAME_LEN + ETH_FCS_LEN,
  4932. .get_variants = e1000_get_variants_ich8lan,
  4933. .mac_ops = &ich8_mac_ops,
  4934. .phy_ops = &ich8_phy_ops,
  4935. .nvm_ops = &ich8_nvm_ops,
  4936. };
  4937. const struct e1000_info e1000_ich9_info = {
  4938. .mac = e1000_ich9lan,
  4939. .flags = FLAG_HAS_JUMBO_FRAMES
  4940. | FLAG_IS_ICH
  4941. | FLAG_HAS_WOL
  4942. | FLAG_HAS_CTRLEXT_ON_LOAD
  4943. | FLAG_HAS_AMT
  4944. | FLAG_HAS_FLASH
  4945. | FLAG_APME_IN_WUC,
  4946. .pba = 18,
  4947. .max_hw_frame_size = DEFAULT_JUMBO,
  4948. .get_variants = e1000_get_variants_ich8lan,
  4949. .mac_ops = &ich8_mac_ops,
  4950. .phy_ops = &ich8_phy_ops,
  4951. .nvm_ops = &ich8_nvm_ops,
  4952. };
  4953. const struct e1000_info e1000_ich10_info = {
  4954. .mac = e1000_ich10lan,
  4955. .flags = FLAG_HAS_JUMBO_FRAMES
  4956. | FLAG_IS_ICH
  4957. | FLAG_HAS_WOL
  4958. | FLAG_HAS_CTRLEXT_ON_LOAD
  4959. | FLAG_HAS_AMT
  4960. | FLAG_HAS_FLASH
  4961. | FLAG_APME_IN_WUC,
  4962. .pba = 18,
  4963. .max_hw_frame_size = DEFAULT_JUMBO,
  4964. .get_variants = e1000_get_variants_ich8lan,
  4965. .mac_ops = &ich8_mac_ops,
  4966. .phy_ops = &ich8_phy_ops,
  4967. .nvm_ops = &ich8_nvm_ops,
  4968. };
  4969. const struct e1000_info e1000_pch_info = {
  4970. .mac = e1000_pchlan,
  4971. .flags = FLAG_IS_ICH
  4972. | FLAG_HAS_WOL
  4973. | FLAG_HAS_CTRLEXT_ON_LOAD
  4974. | FLAG_HAS_AMT
  4975. | FLAG_HAS_FLASH
  4976. | FLAG_HAS_JUMBO_FRAMES
  4977. | FLAG_DISABLE_FC_PAUSE_TIME /* errata */
  4978. | FLAG_APME_IN_WUC,
  4979. .flags2 = FLAG2_HAS_PHY_STATS,
  4980. .pba = 26,
  4981. .max_hw_frame_size = 4096,
  4982. .get_variants = e1000_get_variants_ich8lan,
  4983. .mac_ops = &ich8_mac_ops,
  4984. .phy_ops = &ich8_phy_ops,
  4985. .nvm_ops = &ich8_nvm_ops,
  4986. };
  4987. const struct e1000_info e1000_pch2_info = {
  4988. .mac = e1000_pch2lan,
  4989. .flags = FLAG_IS_ICH
  4990. | FLAG_HAS_WOL
  4991. | FLAG_HAS_HW_TIMESTAMP
  4992. | FLAG_HAS_CTRLEXT_ON_LOAD
  4993. | FLAG_HAS_AMT
  4994. | FLAG_HAS_FLASH
  4995. | FLAG_HAS_JUMBO_FRAMES
  4996. | FLAG_APME_IN_WUC,
  4997. .flags2 = FLAG2_HAS_PHY_STATS
  4998. | FLAG2_HAS_EEE,
  4999. .pba = 26,
  5000. .max_hw_frame_size = 9018,
  5001. .get_variants = e1000_get_variants_ich8lan,
  5002. .mac_ops = &ich8_mac_ops,
  5003. .phy_ops = &ich8_phy_ops,
  5004. .nvm_ops = &ich8_nvm_ops,
  5005. };
  5006. const struct e1000_info e1000_pch_lpt_info = {
  5007. .mac = e1000_pch_lpt,
  5008. .flags = FLAG_IS_ICH
  5009. | FLAG_HAS_WOL
  5010. | FLAG_HAS_HW_TIMESTAMP
  5011. | FLAG_HAS_CTRLEXT_ON_LOAD
  5012. | FLAG_HAS_AMT
  5013. | FLAG_HAS_FLASH
  5014. | FLAG_HAS_JUMBO_FRAMES
  5015. | FLAG_APME_IN_WUC,
  5016. .flags2 = FLAG2_HAS_PHY_STATS
  5017. | FLAG2_HAS_EEE,
  5018. .pba = 26,
  5019. .max_hw_frame_size = 9018,
  5020. .get_variants = e1000_get_variants_ich8lan,
  5021. .mac_ops = &ich8_mac_ops,
  5022. .phy_ops = &ich8_phy_ops,
  5023. .nvm_ops = &ich8_nvm_ops,
  5024. };
  5025. const struct e1000_info e1000_pch_spt_info = {
  5026. .mac = e1000_pch_spt,
  5027. .flags = FLAG_IS_ICH
  5028. | FLAG_HAS_WOL
  5029. | FLAG_HAS_HW_TIMESTAMP
  5030. | FLAG_HAS_CTRLEXT_ON_LOAD
  5031. | FLAG_HAS_AMT
  5032. | FLAG_HAS_FLASH
  5033. | FLAG_HAS_JUMBO_FRAMES
  5034. | FLAG_APME_IN_WUC,
  5035. .flags2 = FLAG2_HAS_PHY_STATS
  5036. | FLAG2_HAS_EEE,
  5037. .pba = 26,
  5038. .max_hw_frame_size = 9018,
  5039. .get_variants = e1000_get_variants_ich8lan,
  5040. .mac_ops = &ich8_mac_ops,
  5041. .phy_ops = &ich8_phy_ops,
  5042. .nvm_ops = &spt_nvm_ops,
  5043. };