ich8lan.c 159 KB

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