ich8lan.c 125 KB

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