ich8lan.c 161 KB

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