ich8lan.c 131 KB

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