ich8lan.c 141 KB

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