ixgbe_x550.c 111 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014
  1. /*******************************************************************************
  2. *
  3. * Intel 10 Gigabit PCI Express Linux driver
  4. * Copyright(c) 1999 - 2016 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * The full GNU General Public License is included in this distribution in
  16. * the file called "COPYING".
  17. *
  18. * Contact Information:
  19. * Linux NICS <linux.nics@intel.com>
  20. * e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
  21. * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
  22. *
  23. ******************************************************************************/
  24. #include "ixgbe_x540.h"
  25. #include "ixgbe_type.h"
  26. #include "ixgbe_common.h"
  27. #include "ixgbe_phy.h"
  28. static s32 ixgbe_setup_kr_speed_x550em(struct ixgbe_hw *, ixgbe_link_speed);
  29. static s32 ixgbe_setup_fc_x550em(struct ixgbe_hw *);
  30. static void ixgbe_fc_autoneg_fiber_x550em_a(struct ixgbe_hw *);
  31. static void ixgbe_fc_autoneg_backplane_x550em_a(struct ixgbe_hw *);
  32. static s32 ixgbe_setup_fc_backplane_x550em_a(struct ixgbe_hw *);
  33. static s32 ixgbe_get_invariants_X550_x(struct ixgbe_hw *hw)
  34. {
  35. struct ixgbe_mac_info *mac = &hw->mac;
  36. struct ixgbe_phy_info *phy = &hw->phy;
  37. struct ixgbe_link_info *link = &hw->link;
  38. /* Start with X540 invariants, since so simular */
  39. ixgbe_get_invariants_X540(hw);
  40. if (mac->ops.get_media_type(hw) != ixgbe_media_type_copper)
  41. phy->ops.set_phy_power = NULL;
  42. link->addr = IXGBE_CS4227;
  43. return 0;
  44. }
  45. static s32 ixgbe_get_invariants_X550_x_fw(struct ixgbe_hw *hw)
  46. {
  47. struct ixgbe_phy_info *phy = &hw->phy;
  48. /* Start with X540 invariants, since so similar */
  49. ixgbe_get_invariants_X540(hw);
  50. phy->ops.set_phy_power = NULL;
  51. return 0;
  52. }
  53. static s32 ixgbe_get_invariants_X550_a(struct ixgbe_hw *hw)
  54. {
  55. struct ixgbe_mac_info *mac = &hw->mac;
  56. struct ixgbe_phy_info *phy = &hw->phy;
  57. /* Start with X540 invariants, since so simular */
  58. ixgbe_get_invariants_X540(hw);
  59. if (mac->ops.get_media_type(hw) != ixgbe_media_type_copper)
  60. phy->ops.set_phy_power = NULL;
  61. return 0;
  62. }
  63. static s32 ixgbe_get_invariants_X550_a_fw(struct ixgbe_hw *hw)
  64. {
  65. struct ixgbe_phy_info *phy = &hw->phy;
  66. /* Start with X540 invariants, since so similar */
  67. ixgbe_get_invariants_X540(hw);
  68. phy->ops.set_phy_power = NULL;
  69. return 0;
  70. }
  71. /** ixgbe_setup_mux_ctl - Setup ESDP register for I2C mux control
  72. * @hw: pointer to hardware structure
  73. **/
  74. static void ixgbe_setup_mux_ctl(struct ixgbe_hw *hw)
  75. {
  76. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  77. if (hw->bus.lan_id) {
  78. esdp &= ~(IXGBE_ESDP_SDP1_NATIVE | IXGBE_ESDP_SDP1);
  79. esdp |= IXGBE_ESDP_SDP1_DIR;
  80. }
  81. esdp &= ~(IXGBE_ESDP_SDP0_NATIVE | IXGBE_ESDP_SDP0_DIR);
  82. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
  83. IXGBE_WRITE_FLUSH(hw);
  84. }
  85. /**
  86. * ixgbe_read_cs4227 - Read CS4227 register
  87. * @hw: pointer to hardware structure
  88. * @reg: register number to write
  89. * @value: pointer to receive value read
  90. *
  91. * Returns status code
  92. */
  93. static s32 ixgbe_read_cs4227(struct ixgbe_hw *hw, u16 reg, u16 *value)
  94. {
  95. return hw->link.ops.read_link_unlocked(hw, hw->link.addr, reg, value);
  96. }
  97. /**
  98. * ixgbe_write_cs4227 - Write CS4227 register
  99. * @hw: pointer to hardware structure
  100. * @reg: register number to write
  101. * @value: value to write to register
  102. *
  103. * Returns status code
  104. */
  105. static s32 ixgbe_write_cs4227(struct ixgbe_hw *hw, u16 reg, u16 value)
  106. {
  107. return hw->link.ops.write_link_unlocked(hw, hw->link.addr, reg, value);
  108. }
  109. /**
  110. * ixgbe_read_pe - Read register from port expander
  111. * @hw: pointer to hardware structure
  112. * @reg: register number to read
  113. * @value: pointer to receive read value
  114. *
  115. * Returns status code
  116. */
  117. static s32 ixgbe_read_pe(struct ixgbe_hw *hw, u8 reg, u8 *value)
  118. {
  119. s32 status;
  120. status = ixgbe_read_i2c_byte_generic_unlocked(hw, reg, IXGBE_PE, value);
  121. if (status)
  122. hw_err(hw, "port expander access failed with %d\n", status);
  123. return status;
  124. }
  125. /**
  126. * ixgbe_write_pe - Write register to port expander
  127. * @hw: pointer to hardware structure
  128. * @reg: register number to write
  129. * @value: value to write
  130. *
  131. * Returns status code
  132. */
  133. static s32 ixgbe_write_pe(struct ixgbe_hw *hw, u8 reg, u8 value)
  134. {
  135. s32 status;
  136. status = ixgbe_write_i2c_byte_generic_unlocked(hw, reg, IXGBE_PE,
  137. value);
  138. if (status)
  139. hw_err(hw, "port expander access failed with %d\n", status);
  140. return status;
  141. }
  142. /**
  143. * ixgbe_reset_cs4227 - Reset CS4227 using port expander
  144. * @hw: pointer to hardware structure
  145. *
  146. * This function assumes that the caller has acquired the proper semaphore.
  147. * Returns error code
  148. */
  149. static s32 ixgbe_reset_cs4227(struct ixgbe_hw *hw)
  150. {
  151. s32 status;
  152. u32 retry;
  153. u16 value;
  154. u8 reg;
  155. /* Trigger hard reset. */
  156. status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, &reg);
  157. if (status)
  158. return status;
  159. reg |= IXGBE_PE_BIT1;
  160. status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
  161. if (status)
  162. return status;
  163. status = ixgbe_read_pe(hw, IXGBE_PE_CONFIG, &reg);
  164. if (status)
  165. return status;
  166. reg &= ~IXGBE_PE_BIT1;
  167. status = ixgbe_write_pe(hw, IXGBE_PE_CONFIG, reg);
  168. if (status)
  169. return status;
  170. status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, &reg);
  171. if (status)
  172. return status;
  173. reg &= ~IXGBE_PE_BIT1;
  174. status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
  175. if (status)
  176. return status;
  177. usleep_range(IXGBE_CS4227_RESET_HOLD, IXGBE_CS4227_RESET_HOLD + 100);
  178. status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, &reg);
  179. if (status)
  180. return status;
  181. reg |= IXGBE_PE_BIT1;
  182. status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
  183. if (status)
  184. return status;
  185. /* Wait for the reset to complete. */
  186. msleep(IXGBE_CS4227_RESET_DELAY);
  187. for (retry = 0; retry < IXGBE_CS4227_RETRIES; retry++) {
  188. status = ixgbe_read_cs4227(hw, IXGBE_CS4227_EFUSE_STATUS,
  189. &value);
  190. if (!status && value == IXGBE_CS4227_EEPROM_LOAD_OK)
  191. break;
  192. msleep(IXGBE_CS4227_CHECK_DELAY);
  193. }
  194. if (retry == IXGBE_CS4227_RETRIES) {
  195. hw_err(hw, "CS4227 reset did not complete\n");
  196. return IXGBE_ERR_PHY;
  197. }
  198. status = ixgbe_read_cs4227(hw, IXGBE_CS4227_EEPROM_STATUS, &value);
  199. if (status || !(value & IXGBE_CS4227_EEPROM_LOAD_OK)) {
  200. hw_err(hw, "CS4227 EEPROM did not load successfully\n");
  201. return IXGBE_ERR_PHY;
  202. }
  203. return 0;
  204. }
  205. /**
  206. * ixgbe_check_cs4227 - Check CS4227 and reset as needed
  207. * @hw: pointer to hardware structure
  208. */
  209. static void ixgbe_check_cs4227(struct ixgbe_hw *hw)
  210. {
  211. u32 swfw_mask = hw->phy.phy_semaphore_mask;
  212. s32 status;
  213. u16 value;
  214. u8 retry;
  215. for (retry = 0; retry < IXGBE_CS4227_RETRIES; retry++) {
  216. status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
  217. if (status) {
  218. hw_err(hw, "semaphore failed with %d\n", status);
  219. msleep(IXGBE_CS4227_CHECK_DELAY);
  220. continue;
  221. }
  222. /* Get status of reset flow. */
  223. status = ixgbe_read_cs4227(hw, IXGBE_CS4227_SCRATCH, &value);
  224. if (!status && value == IXGBE_CS4227_RESET_COMPLETE)
  225. goto out;
  226. if (status || value != IXGBE_CS4227_RESET_PENDING)
  227. break;
  228. /* Reset is pending. Wait and check again. */
  229. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  230. msleep(IXGBE_CS4227_CHECK_DELAY);
  231. }
  232. /* If still pending, assume other instance failed. */
  233. if (retry == IXGBE_CS4227_RETRIES) {
  234. status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
  235. if (status) {
  236. hw_err(hw, "semaphore failed with %d\n", status);
  237. return;
  238. }
  239. }
  240. /* Reset the CS4227. */
  241. status = ixgbe_reset_cs4227(hw);
  242. if (status) {
  243. hw_err(hw, "CS4227 reset failed: %d", status);
  244. goto out;
  245. }
  246. /* Reset takes so long, temporarily release semaphore in case the
  247. * other driver instance is waiting for the reset indication.
  248. */
  249. ixgbe_write_cs4227(hw, IXGBE_CS4227_SCRATCH,
  250. IXGBE_CS4227_RESET_PENDING);
  251. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  252. usleep_range(10000, 12000);
  253. status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
  254. if (status) {
  255. hw_err(hw, "semaphore failed with %d", status);
  256. return;
  257. }
  258. /* Record completion for next time. */
  259. status = ixgbe_write_cs4227(hw, IXGBE_CS4227_SCRATCH,
  260. IXGBE_CS4227_RESET_COMPLETE);
  261. out:
  262. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  263. msleep(hw->eeprom.semaphore_delay);
  264. }
  265. /** ixgbe_identify_phy_x550em - Get PHY type based on device id
  266. * @hw: pointer to hardware structure
  267. *
  268. * Returns error code
  269. */
  270. static s32 ixgbe_identify_phy_x550em(struct ixgbe_hw *hw)
  271. {
  272. switch (hw->device_id) {
  273. case IXGBE_DEV_ID_X550EM_A_SFP:
  274. if (hw->bus.lan_id)
  275. hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
  276. else
  277. hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
  278. return ixgbe_identify_module_generic(hw);
  279. case IXGBE_DEV_ID_X550EM_X_SFP:
  280. /* set up for CS4227 usage */
  281. hw->phy.phy_semaphore_mask = IXGBE_GSSR_SHARED_I2C_SM;
  282. ixgbe_setup_mux_ctl(hw);
  283. ixgbe_check_cs4227(hw);
  284. /* Fallthrough */
  285. case IXGBE_DEV_ID_X550EM_A_SFP_N:
  286. return ixgbe_identify_module_generic(hw);
  287. case IXGBE_DEV_ID_X550EM_X_KX4:
  288. hw->phy.type = ixgbe_phy_x550em_kx4;
  289. break;
  290. case IXGBE_DEV_ID_X550EM_X_XFI:
  291. hw->phy.type = ixgbe_phy_x550em_xfi;
  292. break;
  293. case IXGBE_DEV_ID_X550EM_X_KR:
  294. case IXGBE_DEV_ID_X550EM_A_KR:
  295. case IXGBE_DEV_ID_X550EM_A_KR_L:
  296. hw->phy.type = ixgbe_phy_x550em_kr;
  297. break;
  298. case IXGBE_DEV_ID_X550EM_A_10G_T:
  299. if (hw->bus.lan_id)
  300. hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
  301. else
  302. hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
  303. /* Fallthrough */
  304. case IXGBE_DEV_ID_X550EM_X_10G_T:
  305. return ixgbe_identify_phy_generic(hw);
  306. case IXGBE_DEV_ID_X550EM_X_1G_T:
  307. hw->phy.type = ixgbe_phy_ext_1g_t;
  308. break;
  309. case IXGBE_DEV_ID_X550EM_A_1G_T:
  310. case IXGBE_DEV_ID_X550EM_A_1G_T_L:
  311. hw->phy.type = ixgbe_phy_fw;
  312. hw->phy.ops.read_reg = NULL;
  313. hw->phy.ops.write_reg = NULL;
  314. if (hw->bus.lan_id)
  315. hw->phy.phy_semaphore_mask |= IXGBE_GSSR_PHY1_SM;
  316. else
  317. hw->phy.phy_semaphore_mask |= IXGBE_GSSR_PHY0_SM;
  318. break;
  319. default:
  320. break;
  321. }
  322. return 0;
  323. }
  324. static s32 ixgbe_read_phy_reg_x550em(struct ixgbe_hw *hw, u32 reg_addr,
  325. u32 device_type, u16 *phy_data)
  326. {
  327. return IXGBE_NOT_IMPLEMENTED;
  328. }
  329. static s32 ixgbe_write_phy_reg_x550em(struct ixgbe_hw *hw, u32 reg_addr,
  330. u32 device_type, u16 phy_data)
  331. {
  332. return IXGBE_NOT_IMPLEMENTED;
  333. }
  334. /**
  335. * ixgbe_read_i2c_combined_generic - Perform I2C read combined operation
  336. * @hw: pointer to the hardware structure
  337. * @addr: I2C bus address to read from
  338. * @reg: I2C device register to read from
  339. * @val: pointer to location to receive read value
  340. *
  341. * Returns an error code on error.
  342. **/
  343. static s32 ixgbe_read_i2c_combined_generic(struct ixgbe_hw *hw, u8 addr,
  344. u16 reg, u16 *val)
  345. {
  346. return ixgbe_read_i2c_combined_generic_int(hw, addr, reg, val, true);
  347. }
  348. /**
  349. * ixgbe_read_i2c_combined_generic_unlocked - Do I2C read combined operation
  350. * @hw: pointer to the hardware structure
  351. * @addr: I2C bus address to read from
  352. * @reg: I2C device register to read from
  353. * @val: pointer to location to receive read value
  354. *
  355. * Returns an error code on error.
  356. **/
  357. static s32
  358. ixgbe_read_i2c_combined_generic_unlocked(struct ixgbe_hw *hw, u8 addr,
  359. u16 reg, u16 *val)
  360. {
  361. return ixgbe_read_i2c_combined_generic_int(hw, addr, reg, val, false);
  362. }
  363. /**
  364. * ixgbe_write_i2c_combined_generic - Perform I2C write combined operation
  365. * @hw: pointer to the hardware structure
  366. * @addr: I2C bus address to write to
  367. * @reg: I2C device register to write to
  368. * @val: value to write
  369. *
  370. * Returns an error code on error.
  371. **/
  372. static s32 ixgbe_write_i2c_combined_generic(struct ixgbe_hw *hw,
  373. u8 addr, u16 reg, u16 val)
  374. {
  375. return ixgbe_write_i2c_combined_generic_int(hw, addr, reg, val, true);
  376. }
  377. /**
  378. * ixgbe_write_i2c_combined_generic_unlocked - Do I2C write combined operation
  379. * @hw: pointer to the hardware structure
  380. * @addr: I2C bus address to write to
  381. * @reg: I2C device register to write to
  382. * @val: value to write
  383. *
  384. * Returns an error code on error.
  385. **/
  386. static s32
  387. ixgbe_write_i2c_combined_generic_unlocked(struct ixgbe_hw *hw,
  388. u8 addr, u16 reg, u16 val)
  389. {
  390. return ixgbe_write_i2c_combined_generic_int(hw, addr, reg, val, false);
  391. }
  392. /**
  393. * ixgbe_fw_phy_activity - Perform an activity on a PHY
  394. * @hw: pointer to hardware structure
  395. * @activity: activity to perform
  396. * @data: Pointer to 4 32-bit words of data
  397. */
  398. s32 ixgbe_fw_phy_activity(struct ixgbe_hw *hw, u16 activity,
  399. u32 (*data)[FW_PHY_ACT_DATA_COUNT])
  400. {
  401. union {
  402. struct ixgbe_hic_phy_activity_req cmd;
  403. struct ixgbe_hic_phy_activity_resp rsp;
  404. } hic;
  405. u16 retries = FW_PHY_ACT_RETRIES;
  406. s32 rc;
  407. u32 i;
  408. do {
  409. memset(&hic, 0, sizeof(hic));
  410. hic.cmd.hdr.cmd = FW_PHY_ACT_REQ_CMD;
  411. hic.cmd.hdr.buf_len = FW_PHY_ACT_REQ_LEN;
  412. hic.cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
  413. hic.cmd.port_number = hw->bus.lan_id;
  414. hic.cmd.activity_id = cpu_to_le16(activity);
  415. for (i = 0; i < ARRAY_SIZE(hic.cmd.data); ++i)
  416. hic.cmd.data[i] = cpu_to_be32((*data)[i]);
  417. rc = ixgbe_host_interface_command(hw, &hic.cmd, sizeof(hic.cmd),
  418. IXGBE_HI_COMMAND_TIMEOUT,
  419. true);
  420. if (rc)
  421. return rc;
  422. if (hic.rsp.hdr.cmd_or_resp.ret_status ==
  423. FW_CEM_RESP_STATUS_SUCCESS) {
  424. for (i = 0; i < FW_PHY_ACT_DATA_COUNT; ++i)
  425. (*data)[i] = be32_to_cpu(hic.rsp.data[i]);
  426. return 0;
  427. }
  428. usleep_range(20, 30);
  429. --retries;
  430. } while (retries > 0);
  431. return IXGBE_ERR_HOST_INTERFACE_COMMAND;
  432. }
  433. static const struct {
  434. u16 fw_speed;
  435. ixgbe_link_speed phy_speed;
  436. } ixgbe_fw_map[] = {
  437. { FW_PHY_ACT_LINK_SPEED_10, IXGBE_LINK_SPEED_10_FULL },
  438. { FW_PHY_ACT_LINK_SPEED_100, IXGBE_LINK_SPEED_100_FULL },
  439. { FW_PHY_ACT_LINK_SPEED_1G, IXGBE_LINK_SPEED_1GB_FULL },
  440. { FW_PHY_ACT_LINK_SPEED_2_5G, IXGBE_LINK_SPEED_2_5GB_FULL },
  441. { FW_PHY_ACT_LINK_SPEED_5G, IXGBE_LINK_SPEED_5GB_FULL },
  442. { FW_PHY_ACT_LINK_SPEED_10G, IXGBE_LINK_SPEED_10GB_FULL },
  443. };
  444. /**
  445. * ixgbe_get_phy_id_fw - Get the phy ID via firmware command
  446. * @hw: pointer to hardware structure
  447. *
  448. * Returns error code
  449. */
  450. static s32 ixgbe_get_phy_id_fw(struct ixgbe_hw *hw)
  451. {
  452. u32 info[FW_PHY_ACT_DATA_COUNT] = { 0 };
  453. u16 phy_speeds;
  454. u16 phy_id_lo;
  455. s32 rc;
  456. u16 i;
  457. if (hw->phy.id)
  458. return 0;
  459. rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_GET_PHY_INFO, &info);
  460. if (rc)
  461. return rc;
  462. hw->phy.speeds_supported = 0;
  463. phy_speeds = info[0] & FW_PHY_INFO_SPEED_MASK;
  464. for (i = 0; i < ARRAY_SIZE(ixgbe_fw_map); ++i) {
  465. if (phy_speeds & ixgbe_fw_map[i].fw_speed)
  466. hw->phy.speeds_supported |= ixgbe_fw_map[i].phy_speed;
  467. }
  468. hw->phy.id = info[0] & FW_PHY_INFO_ID_HI_MASK;
  469. phy_id_lo = info[1] & FW_PHY_INFO_ID_LO_MASK;
  470. hw->phy.id |= phy_id_lo & IXGBE_PHY_REVISION_MASK;
  471. hw->phy.revision = phy_id_lo & ~IXGBE_PHY_REVISION_MASK;
  472. if (!hw->phy.id || hw->phy.id == IXGBE_PHY_REVISION_MASK)
  473. return IXGBE_ERR_PHY_ADDR_INVALID;
  474. hw->phy.autoneg_advertised = hw->phy.speeds_supported;
  475. hw->phy.eee_speeds_supported = IXGBE_LINK_SPEED_100_FULL |
  476. IXGBE_LINK_SPEED_1GB_FULL;
  477. hw->phy.eee_speeds_advertised = hw->phy.eee_speeds_supported;
  478. return 0;
  479. }
  480. /**
  481. * ixgbe_identify_phy_fw - Get PHY type based on firmware command
  482. * @hw: pointer to hardware structure
  483. *
  484. * Returns error code
  485. */
  486. static s32 ixgbe_identify_phy_fw(struct ixgbe_hw *hw)
  487. {
  488. if (hw->bus.lan_id)
  489. hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY1_SM;
  490. else
  491. hw->phy.phy_semaphore_mask = IXGBE_GSSR_PHY0_SM;
  492. hw->phy.type = ixgbe_phy_fw;
  493. hw->phy.ops.read_reg = NULL;
  494. hw->phy.ops.write_reg = NULL;
  495. return ixgbe_get_phy_id_fw(hw);
  496. }
  497. /**
  498. * ixgbe_shutdown_fw_phy - Shutdown a firmware-controlled PHY
  499. * @hw: pointer to hardware structure
  500. *
  501. * Returns error code
  502. */
  503. static s32 ixgbe_shutdown_fw_phy(struct ixgbe_hw *hw)
  504. {
  505. u32 setup[FW_PHY_ACT_DATA_COUNT] = { 0 };
  506. setup[0] = FW_PHY_ACT_FORCE_LINK_DOWN_OFF;
  507. return ixgbe_fw_phy_activity(hw, FW_PHY_ACT_FORCE_LINK_DOWN, &setup);
  508. }
  509. /**
  510. * ixgbe_setup_fw_link - Setup firmware-controlled PHYs
  511. * @hw: pointer to hardware structure
  512. */
  513. static s32 ixgbe_setup_fw_link(struct ixgbe_hw *hw)
  514. {
  515. u32 setup[FW_PHY_ACT_DATA_COUNT] = { 0 };
  516. s32 rc;
  517. u16 i;
  518. if (hw->phy.reset_disable || ixgbe_check_reset_blocked(hw))
  519. return 0;
  520. if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
  521. hw_err(hw, "rx_pause not valid in strict IEEE mode\n");
  522. return IXGBE_ERR_INVALID_LINK_SETTINGS;
  523. }
  524. switch (hw->fc.requested_mode) {
  525. case ixgbe_fc_full:
  526. setup[0] |= FW_PHY_ACT_SETUP_LINK_PAUSE_RXTX <<
  527. FW_PHY_ACT_SETUP_LINK_PAUSE_SHIFT;
  528. break;
  529. case ixgbe_fc_rx_pause:
  530. setup[0] |= FW_PHY_ACT_SETUP_LINK_PAUSE_RX <<
  531. FW_PHY_ACT_SETUP_LINK_PAUSE_SHIFT;
  532. break;
  533. case ixgbe_fc_tx_pause:
  534. setup[0] |= FW_PHY_ACT_SETUP_LINK_PAUSE_TX <<
  535. FW_PHY_ACT_SETUP_LINK_PAUSE_SHIFT;
  536. break;
  537. default:
  538. break;
  539. }
  540. for (i = 0; i < ARRAY_SIZE(ixgbe_fw_map); ++i) {
  541. if (hw->phy.autoneg_advertised & ixgbe_fw_map[i].phy_speed)
  542. setup[0] |= ixgbe_fw_map[i].fw_speed;
  543. }
  544. setup[0] |= FW_PHY_ACT_SETUP_LINK_HP | FW_PHY_ACT_SETUP_LINK_AN;
  545. if (hw->phy.eee_speeds_advertised)
  546. setup[0] |= FW_PHY_ACT_SETUP_LINK_EEE;
  547. rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_SETUP_LINK, &setup);
  548. if (rc)
  549. return rc;
  550. if (setup[0] == FW_PHY_ACT_SETUP_LINK_RSP_DOWN)
  551. return IXGBE_ERR_OVERTEMP;
  552. return 0;
  553. }
  554. /**
  555. * ixgbe_fc_autoneg_fw - Set up flow control for FW-controlled PHYs
  556. * @hw: pointer to hardware structure
  557. *
  558. * Called at init time to set up flow control.
  559. */
  560. static s32 ixgbe_fc_autoneg_fw(struct ixgbe_hw *hw)
  561. {
  562. if (hw->fc.requested_mode == ixgbe_fc_default)
  563. hw->fc.requested_mode = ixgbe_fc_full;
  564. return ixgbe_setup_fw_link(hw);
  565. }
  566. /** ixgbe_init_eeprom_params_X550 - Initialize EEPROM params
  567. * @hw: pointer to hardware structure
  568. *
  569. * Initializes the EEPROM parameters ixgbe_eeprom_info within the
  570. * ixgbe_hw struct in order to set up EEPROM access.
  571. **/
  572. static s32 ixgbe_init_eeprom_params_X550(struct ixgbe_hw *hw)
  573. {
  574. struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
  575. u32 eec;
  576. u16 eeprom_size;
  577. if (eeprom->type == ixgbe_eeprom_uninitialized) {
  578. eeprom->semaphore_delay = 10;
  579. eeprom->type = ixgbe_flash;
  580. eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
  581. eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
  582. IXGBE_EEC_SIZE_SHIFT);
  583. eeprom->word_size = BIT(eeprom_size +
  584. IXGBE_EEPROM_WORD_SIZE_SHIFT);
  585. hw_dbg(hw, "Eeprom params: type = %d, size = %d\n",
  586. eeprom->type, eeprom->word_size);
  587. }
  588. return 0;
  589. }
  590. /**
  591. * ixgbe_iosf_wait - Wait for IOSF command completion
  592. * @hw: pointer to hardware structure
  593. * @ctrl: pointer to location to receive final IOSF control value
  594. *
  595. * Return: failing status on timeout
  596. *
  597. * Note: ctrl can be NULL if the IOSF control register value is not needed
  598. */
  599. static s32 ixgbe_iosf_wait(struct ixgbe_hw *hw, u32 *ctrl)
  600. {
  601. u32 i, command;
  602. /* Check every 10 usec to see if the address cycle completed.
  603. * The SB IOSF BUSY bit will clear when the operation is
  604. * complete.
  605. */
  606. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  607. command = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL);
  608. if (!(command & IXGBE_SB_IOSF_CTRL_BUSY))
  609. break;
  610. udelay(10);
  611. }
  612. if (ctrl)
  613. *ctrl = command;
  614. if (i == IXGBE_MDIO_COMMAND_TIMEOUT) {
  615. hw_dbg(hw, "IOSF wait timed out\n");
  616. return IXGBE_ERR_PHY;
  617. }
  618. return 0;
  619. }
  620. /** ixgbe_read_iosf_sb_reg_x550 - Writes a value to specified register of the
  621. * IOSF device
  622. * @hw: pointer to hardware structure
  623. * @reg_addr: 32 bit PHY register to write
  624. * @device_type: 3 bit device type
  625. * @phy_data: Pointer to read data from the register
  626. **/
  627. static s32 ixgbe_read_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr,
  628. u32 device_type, u32 *data)
  629. {
  630. u32 gssr = IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_PHY0_SM;
  631. u32 command, error;
  632. s32 ret;
  633. ret = hw->mac.ops.acquire_swfw_sync(hw, gssr);
  634. if (ret)
  635. return ret;
  636. ret = ixgbe_iosf_wait(hw, NULL);
  637. if (ret)
  638. goto out;
  639. command = ((reg_addr << IXGBE_SB_IOSF_CTRL_ADDR_SHIFT) |
  640. (device_type << IXGBE_SB_IOSF_CTRL_TARGET_SELECT_SHIFT));
  641. /* Write IOSF control register */
  642. IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL, command);
  643. ret = ixgbe_iosf_wait(hw, &command);
  644. if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) {
  645. error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >>
  646. IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT;
  647. hw_dbg(hw, "Failed to read, error %x\n", error);
  648. return IXGBE_ERR_PHY;
  649. }
  650. if (!ret)
  651. *data = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_DATA);
  652. out:
  653. hw->mac.ops.release_swfw_sync(hw, gssr);
  654. return ret;
  655. }
  656. /**
  657. * ixgbe_get_phy_token - Get the token for shared PHY access
  658. * @hw: Pointer to hardware structure
  659. */
  660. static s32 ixgbe_get_phy_token(struct ixgbe_hw *hw)
  661. {
  662. struct ixgbe_hic_phy_token_req token_cmd;
  663. s32 status;
  664. token_cmd.hdr.cmd = FW_PHY_TOKEN_REQ_CMD;
  665. token_cmd.hdr.buf_len = FW_PHY_TOKEN_REQ_LEN;
  666. token_cmd.hdr.cmd_or_resp.cmd_resv = 0;
  667. token_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
  668. token_cmd.port_number = hw->bus.lan_id;
  669. token_cmd.command_type = FW_PHY_TOKEN_REQ;
  670. token_cmd.pad = 0;
  671. status = ixgbe_host_interface_command(hw, &token_cmd, sizeof(token_cmd),
  672. IXGBE_HI_COMMAND_TIMEOUT,
  673. true);
  674. if (status)
  675. return status;
  676. if (token_cmd.hdr.cmd_or_resp.ret_status == FW_PHY_TOKEN_OK)
  677. return 0;
  678. if (token_cmd.hdr.cmd_or_resp.ret_status != FW_PHY_TOKEN_RETRY)
  679. return IXGBE_ERR_FW_RESP_INVALID;
  680. return IXGBE_ERR_TOKEN_RETRY;
  681. }
  682. /**
  683. * ixgbe_put_phy_token - Put the token for shared PHY access
  684. * @hw: Pointer to hardware structure
  685. */
  686. static s32 ixgbe_put_phy_token(struct ixgbe_hw *hw)
  687. {
  688. struct ixgbe_hic_phy_token_req token_cmd;
  689. s32 status;
  690. token_cmd.hdr.cmd = FW_PHY_TOKEN_REQ_CMD;
  691. token_cmd.hdr.buf_len = FW_PHY_TOKEN_REQ_LEN;
  692. token_cmd.hdr.cmd_or_resp.cmd_resv = 0;
  693. token_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
  694. token_cmd.port_number = hw->bus.lan_id;
  695. token_cmd.command_type = FW_PHY_TOKEN_REL;
  696. token_cmd.pad = 0;
  697. status = ixgbe_host_interface_command(hw, &token_cmd, sizeof(token_cmd),
  698. IXGBE_HI_COMMAND_TIMEOUT,
  699. true);
  700. if (status)
  701. return status;
  702. if (token_cmd.hdr.cmd_or_resp.ret_status == FW_PHY_TOKEN_OK)
  703. return 0;
  704. return IXGBE_ERR_FW_RESP_INVALID;
  705. }
  706. /**
  707. * ixgbe_write_iosf_sb_reg_x550a - Write to IOSF PHY register
  708. * @hw: pointer to hardware structure
  709. * @reg_addr: 32 bit PHY register to write
  710. * @device_type: 3 bit device type
  711. * @data: Data to write to the register
  712. **/
  713. static s32 ixgbe_write_iosf_sb_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
  714. __always_unused u32 device_type,
  715. u32 data)
  716. {
  717. struct ixgbe_hic_internal_phy_req write_cmd;
  718. memset(&write_cmd, 0, sizeof(write_cmd));
  719. write_cmd.hdr.cmd = FW_INT_PHY_REQ_CMD;
  720. write_cmd.hdr.buf_len = FW_INT_PHY_REQ_LEN;
  721. write_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
  722. write_cmd.port_number = hw->bus.lan_id;
  723. write_cmd.command_type = FW_INT_PHY_REQ_WRITE;
  724. write_cmd.address = cpu_to_be16(reg_addr);
  725. write_cmd.write_data = cpu_to_be32(data);
  726. return ixgbe_host_interface_command(hw, &write_cmd, sizeof(write_cmd),
  727. IXGBE_HI_COMMAND_TIMEOUT, false);
  728. }
  729. /**
  730. * ixgbe_read_iosf_sb_reg_x550a - Read from IOSF PHY register
  731. * @hw: pointer to hardware structure
  732. * @reg_addr: 32 bit PHY register to write
  733. * @device_type: 3 bit device type
  734. * @data: Pointer to read data from the register
  735. **/
  736. static s32 ixgbe_read_iosf_sb_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
  737. __always_unused u32 device_type,
  738. u32 *data)
  739. {
  740. union {
  741. struct ixgbe_hic_internal_phy_req cmd;
  742. struct ixgbe_hic_internal_phy_resp rsp;
  743. } hic;
  744. s32 status;
  745. memset(&hic, 0, sizeof(hic));
  746. hic.cmd.hdr.cmd = FW_INT_PHY_REQ_CMD;
  747. hic.cmd.hdr.buf_len = FW_INT_PHY_REQ_LEN;
  748. hic.cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
  749. hic.cmd.port_number = hw->bus.lan_id;
  750. hic.cmd.command_type = FW_INT_PHY_REQ_READ;
  751. hic.cmd.address = cpu_to_be16(reg_addr);
  752. status = ixgbe_host_interface_command(hw, &hic.cmd, sizeof(hic.cmd),
  753. IXGBE_HI_COMMAND_TIMEOUT, true);
  754. /* Extract the register value from the response. */
  755. *data = be32_to_cpu(hic.rsp.read_data);
  756. return status;
  757. }
  758. /** ixgbe_read_ee_hostif_buffer_X550- Read EEPROM word(s) using hostif
  759. * @hw: pointer to hardware structure
  760. * @offset: offset of word in the EEPROM to read
  761. * @words: number of words
  762. * @data: word(s) read from the EEPROM
  763. *
  764. * Reads a 16 bit word(s) from the EEPROM using the hostif.
  765. **/
  766. static s32 ixgbe_read_ee_hostif_buffer_X550(struct ixgbe_hw *hw,
  767. u16 offset, u16 words, u16 *data)
  768. {
  769. const u32 mask = IXGBE_GSSR_SW_MNG_SM | IXGBE_GSSR_EEP_SM;
  770. struct ixgbe_hic_read_shadow_ram buffer;
  771. u32 current_word = 0;
  772. u16 words_to_read;
  773. s32 status;
  774. u32 i;
  775. /* Take semaphore for the entire operation. */
  776. status = hw->mac.ops.acquire_swfw_sync(hw, mask);
  777. if (status) {
  778. hw_dbg(hw, "EEPROM read buffer - semaphore failed\n");
  779. return status;
  780. }
  781. while (words) {
  782. if (words > FW_MAX_READ_BUFFER_SIZE / 2)
  783. words_to_read = FW_MAX_READ_BUFFER_SIZE / 2;
  784. else
  785. words_to_read = words;
  786. buffer.hdr.req.cmd = FW_READ_SHADOW_RAM_CMD;
  787. buffer.hdr.req.buf_lenh = 0;
  788. buffer.hdr.req.buf_lenl = FW_READ_SHADOW_RAM_LEN;
  789. buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
  790. /* convert offset from words to bytes */
  791. buffer.address = cpu_to_be32((offset + current_word) * 2);
  792. buffer.length = cpu_to_be16(words_to_read * 2);
  793. status = ixgbe_hic_unlocked(hw, (u32 *)&buffer, sizeof(buffer),
  794. IXGBE_HI_COMMAND_TIMEOUT);
  795. if (status) {
  796. hw_dbg(hw, "Host interface command failed\n");
  797. goto out;
  798. }
  799. for (i = 0; i < words_to_read; i++) {
  800. u32 reg = IXGBE_FLEX_MNG + (FW_NVM_DATA_OFFSET << 2) +
  801. 2 * i;
  802. u32 value = IXGBE_READ_REG(hw, reg);
  803. data[current_word] = (u16)(value & 0xffff);
  804. current_word++;
  805. i++;
  806. if (i < words_to_read) {
  807. value >>= 16;
  808. data[current_word] = (u16)(value & 0xffff);
  809. current_word++;
  810. }
  811. }
  812. words -= words_to_read;
  813. }
  814. out:
  815. hw->mac.ops.release_swfw_sync(hw, mask);
  816. return status;
  817. }
  818. /** ixgbe_checksum_ptr_x550 - Checksum one pointer region
  819. * @hw: pointer to hardware structure
  820. * @ptr: pointer offset in eeprom
  821. * @size: size of section pointed by ptr, if 0 first word will be used as size
  822. * @csum: address of checksum to update
  823. *
  824. * Returns error status for any failure
  825. **/
  826. static s32 ixgbe_checksum_ptr_x550(struct ixgbe_hw *hw, u16 ptr,
  827. u16 size, u16 *csum, u16 *buffer,
  828. u32 buffer_size)
  829. {
  830. u16 buf[256];
  831. s32 status;
  832. u16 length, bufsz, i, start;
  833. u16 *local_buffer;
  834. bufsz = sizeof(buf) / sizeof(buf[0]);
  835. /* Read a chunk at the pointer location */
  836. if (!buffer) {
  837. status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr, bufsz, buf);
  838. if (status) {
  839. hw_dbg(hw, "Failed to read EEPROM image\n");
  840. return status;
  841. }
  842. local_buffer = buf;
  843. } else {
  844. if (buffer_size < ptr)
  845. return IXGBE_ERR_PARAM;
  846. local_buffer = &buffer[ptr];
  847. }
  848. if (size) {
  849. start = 0;
  850. length = size;
  851. } else {
  852. start = 1;
  853. length = local_buffer[0];
  854. /* Skip pointer section if length is invalid. */
  855. if (length == 0xFFFF || length == 0 ||
  856. (ptr + length) >= hw->eeprom.word_size)
  857. return 0;
  858. }
  859. if (buffer && ((u32)start + (u32)length > buffer_size))
  860. return IXGBE_ERR_PARAM;
  861. for (i = start; length; i++, length--) {
  862. if (i == bufsz && !buffer) {
  863. ptr += bufsz;
  864. i = 0;
  865. if (length < bufsz)
  866. bufsz = length;
  867. /* Read a chunk at the pointer location */
  868. status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr,
  869. bufsz, buf);
  870. if (status) {
  871. hw_dbg(hw, "Failed to read EEPROM image\n");
  872. return status;
  873. }
  874. }
  875. *csum += local_buffer[i];
  876. }
  877. return 0;
  878. }
  879. /** ixgbe_calc_checksum_X550 - Calculates and returns the checksum
  880. * @hw: pointer to hardware structure
  881. * @buffer: pointer to buffer containing calculated checksum
  882. * @buffer_size: size of buffer
  883. *
  884. * Returns a negative error code on error, or the 16-bit checksum
  885. **/
  886. static s32 ixgbe_calc_checksum_X550(struct ixgbe_hw *hw, u16 *buffer,
  887. u32 buffer_size)
  888. {
  889. u16 eeprom_ptrs[IXGBE_EEPROM_LAST_WORD + 1];
  890. u16 *local_buffer;
  891. s32 status;
  892. u16 checksum = 0;
  893. u16 pointer, i, size;
  894. hw->eeprom.ops.init_params(hw);
  895. if (!buffer) {
  896. /* Read pointer area */
  897. status = ixgbe_read_ee_hostif_buffer_X550(hw, 0,
  898. IXGBE_EEPROM_LAST_WORD + 1,
  899. eeprom_ptrs);
  900. if (status) {
  901. hw_dbg(hw, "Failed to read EEPROM image\n");
  902. return status;
  903. }
  904. local_buffer = eeprom_ptrs;
  905. } else {
  906. if (buffer_size < IXGBE_EEPROM_LAST_WORD)
  907. return IXGBE_ERR_PARAM;
  908. local_buffer = buffer;
  909. }
  910. /* For X550 hardware include 0x0-0x41 in the checksum, skip the
  911. * checksum word itself
  912. */
  913. for (i = 0; i <= IXGBE_EEPROM_LAST_WORD; i++)
  914. if (i != IXGBE_EEPROM_CHECKSUM)
  915. checksum += local_buffer[i];
  916. /* Include all data from pointers 0x3, 0x6-0xE. This excludes the
  917. * FW, PHY module, and PCIe Expansion/Option ROM pointers.
  918. */
  919. for (i = IXGBE_PCIE_ANALOG_PTR_X550; i < IXGBE_FW_PTR; i++) {
  920. if (i == IXGBE_PHY_PTR || i == IXGBE_OPTION_ROM_PTR)
  921. continue;
  922. pointer = local_buffer[i];
  923. /* Skip pointer section if the pointer is invalid. */
  924. if (pointer == 0xFFFF || pointer == 0 ||
  925. pointer >= hw->eeprom.word_size)
  926. continue;
  927. switch (i) {
  928. case IXGBE_PCIE_GENERAL_PTR:
  929. size = IXGBE_IXGBE_PCIE_GENERAL_SIZE;
  930. break;
  931. case IXGBE_PCIE_CONFIG0_PTR:
  932. case IXGBE_PCIE_CONFIG1_PTR:
  933. size = IXGBE_PCIE_CONFIG_SIZE;
  934. break;
  935. default:
  936. size = 0;
  937. break;
  938. }
  939. status = ixgbe_checksum_ptr_x550(hw, pointer, size, &checksum,
  940. buffer, buffer_size);
  941. if (status)
  942. return status;
  943. }
  944. checksum = (u16)IXGBE_EEPROM_SUM - checksum;
  945. return (s32)checksum;
  946. }
  947. /** ixgbe_calc_eeprom_checksum_X550 - Calculates and returns the checksum
  948. * @hw: pointer to hardware structure
  949. *
  950. * Returns a negative error code on error, or the 16-bit checksum
  951. **/
  952. static s32 ixgbe_calc_eeprom_checksum_X550(struct ixgbe_hw *hw)
  953. {
  954. return ixgbe_calc_checksum_X550(hw, NULL, 0);
  955. }
  956. /** ixgbe_read_ee_hostif_X550 - Read EEPROM word using a host interface command
  957. * @hw: pointer to hardware structure
  958. * @offset: offset of word in the EEPROM to read
  959. * @data: word read from the EEPROM
  960. *
  961. * Reads a 16 bit word from the EEPROM using the hostif.
  962. **/
  963. static s32 ixgbe_read_ee_hostif_X550(struct ixgbe_hw *hw, u16 offset, u16 *data)
  964. {
  965. const u32 mask = IXGBE_GSSR_SW_MNG_SM | IXGBE_GSSR_EEP_SM;
  966. struct ixgbe_hic_read_shadow_ram buffer;
  967. s32 status;
  968. buffer.hdr.req.cmd = FW_READ_SHADOW_RAM_CMD;
  969. buffer.hdr.req.buf_lenh = 0;
  970. buffer.hdr.req.buf_lenl = FW_READ_SHADOW_RAM_LEN;
  971. buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
  972. /* convert offset from words to bytes */
  973. buffer.address = cpu_to_be32(offset * 2);
  974. /* one word */
  975. buffer.length = cpu_to_be16(sizeof(u16));
  976. status = hw->mac.ops.acquire_swfw_sync(hw, mask);
  977. if (status)
  978. return status;
  979. status = ixgbe_hic_unlocked(hw, (u32 *)&buffer, sizeof(buffer),
  980. IXGBE_HI_COMMAND_TIMEOUT);
  981. if (!status) {
  982. *data = (u16)IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG,
  983. FW_NVM_DATA_OFFSET);
  984. }
  985. hw->mac.ops.release_swfw_sync(hw, mask);
  986. return status;
  987. }
  988. /** ixgbe_validate_eeprom_checksum_X550 - Validate EEPROM checksum
  989. * @hw: pointer to hardware structure
  990. * @checksum_val: calculated checksum
  991. *
  992. * Performs checksum calculation and validates the EEPROM checksum. If the
  993. * caller does not need checksum_val, the value can be NULL.
  994. **/
  995. static s32 ixgbe_validate_eeprom_checksum_X550(struct ixgbe_hw *hw,
  996. u16 *checksum_val)
  997. {
  998. s32 status;
  999. u16 checksum;
  1000. u16 read_checksum = 0;
  1001. /* Read the first word from the EEPROM. If this times out or fails, do
  1002. * not continue or we could be in for a very long wait while every
  1003. * EEPROM read fails
  1004. */
  1005. status = hw->eeprom.ops.read(hw, 0, &checksum);
  1006. if (status) {
  1007. hw_dbg(hw, "EEPROM read failed\n");
  1008. return status;
  1009. }
  1010. status = hw->eeprom.ops.calc_checksum(hw);
  1011. if (status < 0)
  1012. return status;
  1013. checksum = (u16)(status & 0xffff);
  1014. status = ixgbe_read_ee_hostif_X550(hw, IXGBE_EEPROM_CHECKSUM,
  1015. &read_checksum);
  1016. if (status)
  1017. return status;
  1018. /* Verify read checksum from EEPROM is the same as
  1019. * calculated checksum
  1020. */
  1021. if (read_checksum != checksum) {
  1022. status = IXGBE_ERR_EEPROM_CHECKSUM;
  1023. hw_dbg(hw, "Invalid EEPROM checksum");
  1024. }
  1025. /* If the user cares, return the calculated checksum */
  1026. if (checksum_val)
  1027. *checksum_val = checksum;
  1028. return status;
  1029. }
  1030. /** ixgbe_write_ee_hostif_X550 - Write EEPROM word using hostif
  1031. * @hw: pointer to hardware structure
  1032. * @offset: offset of word in the EEPROM to write
  1033. * @data: word write to the EEPROM
  1034. *
  1035. * Write a 16 bit word to the EEPROM using the hostif.
  1036. **/
  1037. static s32 ixgbe_write_ee_hostif_data_X550(struct ixgbe_hw *hw, u16 offset,
  1038. u16 data)
  1039. {
  1040. s32 status;
  1041. struct ixgbe_hic_write_shadow_ram buffer;
  1042. buffer.hdr.req.cmd = FW_WRITE_SHADOW_RAM_CMD;
  1043. buffer.hdr.req.buf_lenh = 0;
  1044. buffer.hdr.req.buf_lenl = FW_WRITE_SHADOW_RAM_LEN;
  1045. buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
  1046. /* one word */
  1047. buffer.length = cpu_to_be16(sizeof(u16));
  1048. buffer.data = data;
  1049. buffer.address = cpu_to_be32(offset * 2);
  1050. status = ixgbe_host_interface_command(hw, &buffer, sizeof(buffer),
  1051. IXGBE_HI_COMMAND_TIMEOUT, false);
  1052. return status;
  1053. }
  1054. /** ixgbe_write_ee_hostif_X550 - Write EEPROM word using hostif
  1055. * @hw: pointer to hardware structure
  1056. * @offset: offset of word in the EEPROM to write
  1057. * @data: word write to the EEPROM
  1058. *
  1059. * Write a 16 bit word to the EEPROM using the hostif.
  1060. **/
  1061. static s32 ixgbe_write_ee_hostif_X550(struct ixgbe_hw *hw, u16 offset, u16 data)
  1062. {
  1063. s32 status = 0;
  1064. if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0) {
  1065. status = ixgbe_write_ee_hostif_data_X550(hw, offset, data);
  1066. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  1067. } else {
  1068. hw_dbg(hw, "write ee hostif failed to get semaphore");
  1069. status = IXGBE_ERR_SWFW_SYNC;
  1070. }
  1071. return status;
  1072. }
  1073. /** ixgbe_update_flash_X550 - Instruct HW to copy EEPROM to Flash device
  1074. * @hw: pointer to hardware structure
  1075. *
  1076. * Issue a shadow RAM dump to FW to copy EEPROM from shadow RAM to the flash.
  1077. **/
  1078. static s32 ixgbe_update_flash_X550(struct ixgbe_hw *hw)
  1079. {
  1080. s32 status = 0;
  1081. union ixgbe_hic_hdr2 buffer;
  1082. buffer.req.cmd = FW_SHADOW_RAM_DUMP_CMD;
  1083. buffer.req.buf_lenh = 0;
  1084. buffer.req.buf_lenl = FW_SHADOW_RAM_DUMP_LEN;
  1085. buffer.req.checksum = FW_DEFAULT_CHECKSUM;
  1086. status = ixgbe_host_interface_command(hw, &buffer, sizeof(buffer),
  1087. IXGBE_HI_COMMAND_TIMEOUT, false);
  1088. return status;
  1089. }
  1090. /**
  1091. * ixgbe_get_bus_info_X550em - Set PCI bus info
  1092. * @hw: pointer to hardware structure
  1093. *
  1094. * Sets bus link width and speed to unknown because X550em is
  1095. * not a PCI device.
  1096. **/
  1097. static s32 ixgbe_get_bus_info_X550em(struct ixgbe_hw *hw)
  1098. {
  1099. hw->bus.type = ixgbe_bus_type_internal;
  1100. hw->bus.width = ixgbe_bus_width_unknown;
  1101. hw->bus.speed = ixgbe_bus_speed_unknown;
  1102. hw->mac.ops.set_lan_id(hw);
  1103. return 0;
  1104. }
  1105. /** ixgbe_disable_rx_x550 - Disable RX unit
  1106. *
  1107. * Enables the Rx DMA unit for x550
  1108. **/
  1109. static void ixgbe_disable_rx_x550(struct ixgbe_hw *hw)
  1110. {
  1111. u32 rxctrl, pfdtxgswc;
  1112. s32 status;
  1113. struct ixgbe_hic_disable_rxen fw_cmd;
  1114. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  1115. if (rxctrl & IXGBE_RXCTRL_RXEN) {
  1116. pfdtxgswc = IXGBE_READ_REG(hw, IXGBE_PFDTXGSWC);
  1117. if (pfdtxgswc & IXGBE_PFDTXGSWC_VT_LBEN) {
  1118. pfdtxgswc &= ~IXGBE_PFDTXGSWC_VT_LBEN;
  1119. IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, pfdtxgswc);
  1120. hw->mac.set_lben = true;
  1121. } else {
  1122. hw->mac.set_lben = false;
  1123. }
  1124. fw_cmd.hdr.cmd = FW_DISABLE_RXEN_CMD;
  1125. fw_cmd.hdr.buf_len = FW_DISABLE_RXEN_LEN;
  1126. fw_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
  1127. fw_cmd.port_number = hw->bus.lan_id;
  1128. status = ixgbe_host_interface_command(hw, &fw_cmd,
  1129. sizeof(struct ixgbe_hic_disable_rxen),
  1130. IXGBE_HI_COMMAND_TIMEOUT, true);
  1131. /* If we fail - disable RX using register write */
  1132. if (status) {
  1133. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  1134. if (rxctrl & IXGBE_RXCTRL_RXEN) {
  1135. rxctrl &= ~IXGBE_RXCTRL_RXEN;
  1136. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl);
  1137. }
  1138. }
  1139. }
  1140. }
  1141. /** ixgbe_update_eeprom_checksum_X550 - Updates the EEPROM checksum and flash
  1142. * @hw: pointer to hardware structure
  1143. *
  1144. * After writing EEPROM to shadow RAM using EEWR register, software calculates
  1145. * checksum and updates the EEPROM and instructs the hardware to update
  1146. * the flash.
  1147. **/
  1148. static s32 ixgbe_update_eeprom_checksum_X550(struct ixgbe_hw *hw)
  1149. {
  1150. s32 status;
  1151. u16 checksum = 0;
  1152. /* Read the first word from the EEPROM. If this times out or fails, do
  1153. * not continue or we could be in for a very long wait while every
  1154. * EEPROM read fails
  1155. */
  1156. status = ixgbe_read_ee_hostif_X550(hw, 0, &checksum);
  1157. if (status) {
  1158. hw_dbg(hw, "EEPROM read failed\n");
  1159. return status;
  1160. }
  1161. status = ixgbe_calc_eeprom_checksum_X550(hw);
  1162. if (status < 0)
  1163. return status;
  1164. checksum = (u16)(status & 0xffff);
  1165. status = ixgbe_write_ee_hostif_X550(hw, IXGBE_EEPROM_CHECKSUM,
  1166. checksum);
  1167. if (status)
  1168. return status;
  1169. status = ixgbe_update_flash_X550(hw);
  1170. return status;
  1171. }
  1172. /** ixgbe_write_ee_hostif_buffer_X550 - Write EEPROM word(s) using hostif
  1173. * @hw: pointer to hardware structure
  1174. * @offset: offset of word in the EEPROM to write
  1175. * @words: number of words
  1176. * @data: word(s) write to the EEPROM
  1177. *
  1178. *
  1179. * Write a 16 bit word(s) to the EEPROM using the hostif.
  1180. **/
  1181. static s32 ixgbe_write_ee_hostif_buffer_X550(struct ixgbe_hw *hw,
  1182. u16 offset, u16 words,
  1183. u16 *data)
  1184. {
  1185. s32 status = 0;
  1186. u32 i = 0;
  1187. /* Take semaphore for the entire operation. */
  1188. status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  1189. if (status) {
  1190. hw_dbg(hw, "EEPROM write buffer - semaphore failed\n");
  1191. return status;
  1192. }
  1193. for (i = 0; i < words; i++) {
  1194. status = ixgbe_write_ee_hostif_data_X550(hw, offset + i,
  1195. data[i]);
  1196. if (status) {
  1197. hw_dbg(hw, "Eeprom buffered write failed\n");
  1198. break;
  1199. }
  1200. }
  1201. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  1202. return status;
  1203. }
  1204. /** ixgbe_write_iosf_sb_reg_x550 - Writes a value to specified register of the
  1205. * IOSF device
  1206. *
  1207. * @hw: pointer to hardware structure
  1208. * @reg_addr: 32 bit PHY register to write
  1209. * @device_type: 3 bit device type
  1210. * @data: Data to write to the register
  1211. **/
  1212. static s32 ixgbe_write_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr,
  1213. u32 device_type, u32 data)
  1214. {
  1215. u32 gssr = IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_PHY0_SM;
  1216. u32 command, error;
  1217. s32 ret;
  1218. ret = hw->mac.ops.acquire_swfw_sync(hw, gssr);
  1219. if (ret)
  1220. return ret;
  1221. ret = ixgbe_iosf_wait(hw, NULL);
  1222. if (ret)
  1223. goto out;
  1224. command = ((reg_addr << IXGBE_SB_IOSF_CTRL_ADDR_SHIFT) |
  1225. (device_type << IXGBE_SB_IOSF_CTRL_TARGET_SELECT_SHIFT));
  1226. /* Write IOSF control register */
  1227. IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL, command);
  1228. /* Write IOSF data register */
  1229. IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_DATA, data);
  1230. ret = ixgbe_iosf_wait(hw, &command);
  1231. if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) {
  1232. error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >>
  1233. IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT;
  1234. hw_dbg(hw, "Failed to write, error %x\n", error);
  1235. return IXGBE_ERR_PHY;
  1236. }
  1237. out:
  1238. hw->mac.ops.release_swfw_sync(hw, gssr);
  1239. return ret;
  1240. }
  1241. /**
  1242. * ixgbe_setup_ixfi_x550em_x - MAC specific iXFI configuration
  1243. * @hw: pointer to hardware structure
  1244. *
  1245. * iXfI configuration needed for ixgbe_mac_X550EM_x devices.
  1246. **/
  1247. static s32 ixgbe_setup_ixfi_x550em_x(struct ixgbe_hw *hw)
  1248. {
  1249. s32 status;
  1250. u32 reg_val;
  1251. /* Disable training protocol FSM. */
  1252. status = ixgbe_read_iosf_sb_reg_x550(hw,
  1253. IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
  1254. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  1255. if (status)
  1256. return status;
  1257. reg_val |= IXGBE_KRM_RX_TRN_LINKUP_CTRL_CONV_WO_PROTOCOL;
  1258. status = ixgbe_write_iosf_sb_reg_x550(hw,
  1259. IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
  1260. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  1261. if (status)
  1262. return status;
  1263. /* Disable Flex from training TXFFE. */
  1264. status = ixgbe_read_iosf_sb_reg_x550(hw,
  1265. IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id),
  1266. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  1267. if (status)
  1268. return status;
  1269. reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN;
  1270. reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN;
  1271. reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN;
  1272. status = ixgbe_write_iosf_sb_reg_x550(hw,
  1273. IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id),
  1274. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  1275. if (status)
  1276. return status;
  1277. status = ixgbe_read_iosf_sb_reg_x550(hw,
  1278. IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id),
  1279. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  1280. if (status)
  1281. return status;
  1282. reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN;
  1283. reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN;
  1284. reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN;
  1285. status = ixgbe_write_iosf_sb_reg_x550(hw,
  1286. IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id),
  1287. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  1288. if (status)
  1289. return status;
  1290. /* Enable override for coefficients. */
  1291. status = ixgbe_read_iosf_sb_reg_x550(hw,
  1292. IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id),
  1293. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  1294. if (status)
  1295. return status;
  1296. reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_OVRRD_EN;
  1297. reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CZERO_EN;
  1298. reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CPLUS1_OVRRD_EN;
  1299. reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CMINUS1_OVRRD_EN;
  1300. status = ixgbe_write_iosf_sb_reg_x550(hw,
  1301. IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id),
  1302. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  1303. return status;
  1304. }
  1305. /**
  1306. * ixgbe_restart_an_internal_phy_x550em - restart autonegotiation for the
  1307. * internal PHY
  1308. * @hw: pointer to hardware structure
  1309. **/
  1310. static s32 ixgbe_restart_an_internal_phy_x550em(struct ixgbe_hw *hw)
  1311. {
  1312. s32 status;
  1313. u32 link_ctrl;
  1314. /* Restart auto-negotiation. */
  1315. status = hw->mac.ops.read_iosf_sb_reg(hw,
  1316. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  1317. IXGBE_SB_IOSF_TARGET_KR_PHY, &link_ctrl);
  1318. if (status) {
  1319. hw_dbg(hw, "Auto-negotiation did not complete\n");
  1320. return status;
  1321. }
  1322. link_ctrl |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_RESTART;
  1323. status = hw->mac.ops.write_iosf_sb_reg(hw,
  1324. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  1325. IXGBE_SB_IOSF_TARGET_KR_PHY, link_ctrl);
  1326. if (hw->mac.type == ixgbe_mac_x550em_a) {
  1327. u32 flx_mask_st20;
  1328. /* Indicate to FW that AN restart has been asserted */
  1329. status = hw->mac.ops.read_iosf_sb_reg(hw,
  1330. IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
  1331. IXGBE_SB_IOSF_TARGET_KR_PHY, &flx_mask_st20);
  1332. if (status) {
  1333. hw_dbg(hw, "Auto-negotiation did not complete\n");
  1334. return status;
  1335. }
  1336. flx_mask_st20 |= IXGBE_KRM_PMD_FLX_MASK_ST20_FW_AN_RESTART;
  1337. status = hw->mac.ops.write_iosf_sb_reg(hw,
  1338. IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
  1339. IXGBE_SB_IOSF_TARGET_KR_PHY, flx_mask_st20);
  1340. }
  1341. return status;
  1342. }
  1343. /** ixgbe_setup_ixfi_x550em - Configure the KR PHY for iXFI mode.
  1344. * @hw: pointer to hardware structure
  1345. * @speed: the link speed to force
  1346. *
  1347. * Configures the integrated KR PHY to use iXFI mode. Used to connect an
  1348. * internal and external PHY at a specific speed, without autonegotiation.
  1349. **/
  1350. static s32 ixgbe_setup_ixfi_x550em(struct ixgbe_hw *hw, ixgbe_link_speed *speed)
  1351. {
  1352. s32 status;
  1353. u32 reg_val;
  1354. /* Disable AN and force speed to 10G Serial. */
  1355. status = ixgbe_read_iosf_sb_reg_x550(hw,
  1356. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  1357. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  1358. if (status)
  1359. return status;
  1360. reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
  1361. reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
  1362. /* Select forced link speed for internal PHY. */
  1363. switch (*speed) {
  1364. case IXGBE_LINK_SPEED_10GB_FULL:
  1365. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_10G;
  1366. break;
  1367. case IXGBE_LINK_SPEED_1GB_FULL:
  1368. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_1G;
  1369. break;
  1370. default:
  1371. /* Other link speeds are not supported by internal KR PHY. */
  1372. return IXGBE_ERR_LINK_SETUP;
  1373. }
  1374. status = ixgbe_write_iosf_sb_reg_x550(hw,
  1375. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  1376. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  1377. if (status)
  1378. return status;
  1379. /* Additional configuration needed for x550em_x */
  1380. if (hw->mac.type == ixgbe_mac_X550EM_x) {
  1381. status = ixgbe_setup_ixfi_x550em_x(hw);
  1382. if (status)
  1383. return status;
  1384. }
  1385. /* Toggle port SW reset by AN reset. */
  1386. status = ixgbe_restart_an_internal_phy_x550em(hw);
  1387. return status;
  1388. }
  1389. /**
  1390. * ixgbe_supported_sfp_modules_X550em - Check if SFP module type is supported
  1391. * @hw: pointer to hardware structure
  1392. * @linear: true if SFP module is linear
  1393. */
  1394. static s32 ixgbe_supported_sfp_modules_X550em(struct ixgbe_hw *hw, bool *linear)
  1395. {
  1396. switch (hw->phy.sfp_type) {
  1397. case ixgbe_sfp_type_not_present:
  1398. return IXGBE_ERR_SFP_NOT_PRESENT;
  1399. case ixgbe_sfp_type_da_cu_core0:
  1400. case ixgbe_sfp_type_da_cu_core1:
  1401. *linear = true;
  1402. break;
  1403. case ixgbe_sfp_type_srlr_core0:
  1404. case ixgbe_sfp_type_srlr_core1:
  1405. case ixgbe_sfp_type_da_act_lmt_core0:
  1406. case ixgbe_sfp_type_da_act_lmt_core1:
  1407. case ixgbe_sfp_type_1g_sx_core0:
  1408. case ixgbe_sfp_type_1g_sx_core1:
  1409. case ixgbe_sfp_type_1g_lx_core0:
  1410. case ixgbe_sfp_type_1g_lx_core1:
  1411. *linear = false;
  1412. break;
  1413. case ixgbe_sfp_type_unknown:
  1414. case ixgbe_sfp_type_1g_cu_core0:
  1415. case ixgbe_sfp_type_1g_cu_core1:
  1416. default:
  1417. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  1418. }
  1419. return 0;
  1420. }
  1421. /**
  1422. * ixgbe_setup_mac_link_sfp_x550em - Configure the KR PHY for SFP.
  1423. * @hw: pointer to hardware structure
  1424. *
  1425. * Configures the extern PHY and the integrated KR PHY for SFP support.
  1426. */
  1427. static s32
  1428. ixgbe_setup_mac_link_sfp_x550em(struct ixgbe_hw *hw,
  1429. ixgbe_link_speed speed,
  1430. __always_unused bool autoneg_wait_to_complete)
  1431. {
  1432. s32 status;
  1433. u16 reg_slice, reg_val;
  1434. bool setup_linear = false;
  1435. /* Check if SFP module is supported and linear */
  1436. status = ixgbe_supported_sfp_modules_X550em(hw, &setup_linear);
  1437. /* If no SFP module present, then return success. Return success since
  1438. * there is no reason to configure CS4227 and SFP not present error is
  1439. * not accepted in the setup MAC link flow.
  1440. */
  1441. if (status == IXGBE_ERR_SFP_NOT_PRESENT)
  1442. return 0;
  1443. if (status)
  1444. return status;
  1445. /* Configure internal PHY for KR/KX. */
  1446. ixgbe_setup_kr_speed_x550em(hw, speed);
  1447. /* Configure CS4227 LINE side to proper mode. */
  1448. reg_slice = IXGBE_CS4227_LINE_SPARE24_LSB + (hw->bus.lan_id << 12);
  1449. if (setup_linear)
  1450. reg_val = (IXGBE_CS4227_EDC_MODE_CX1 << 1) | 0x1;
  1451. else
  1452. reg_val = (IXGBE_CS4227_EDC_MODE_SR << 1) | 0x1;
  1453. status = hw->link.ops.write_link(hw, hw->link.addr, reg_slice,
  1454. reg_val);
  1455. return status;
  1456. }
  1457. /**
  1458. * ixgbe_setup_sfi_x550a - Configure the internal PHY for native SFI mode
  1459. * @hw: pointer to hardware structure
  1460. * @speed: the link speed to force
  1461. *
  1462. * Configures the integrated PHY for native SFI mode. Used to connect the
  1463. * internal PHY directly to an SFP cage, without autonegotiation.
  1464. **/
  1465. static s32 ixgbe_setup_sfi_x550a(struct ixgbe_hw *hw, ixgbe_link_speed *speed)
  1466. {
  1467. struct ixgbe_mac_info *mac = &hw->mac;
  1468. s32 status;
  1469. u32 reg_val;
  1470. /* Disable all AN and force speed to 10G Serial. */
  1471. status = mac->ops.read_iosf_sb_reg(hw,
  1472. IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
  1473. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  1474. if (status)
  1475. return status;
  1476. reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN_EN;
  1477. reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN37_EN;
  1478. reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SGMII_EN;
  1479. reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_MASK;
  1480. /* Select forced link speed for internal PHY. */
  1481. switch (*speed) {
  1482. case IXGBE_LINK_SPEED_10GB_FULL:
  1483. reg_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_10G;
  1484. break;
  1485. case IXGBE_LINK_SPEED_1GB_FULL:
  1486. reg_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_1G;
  1487. break;
  1488. default:
  1489. /* Other link speeds are not supported by internal PHY. */
  1490. return IXGBE_ERR_LINK_SETUP;
  1491. }
  1492. status = mac->ops.write_iosf_sb_reg(hw,
  1493. IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
  1494. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  1495. /* Toggle port SW reset by AN reset. */
  1496. status = ixgbe_restart_an_internal_phy_x550em(hw);
  1497. return status;
  1498. }
  1499. /**
  1500. * ixgbe_setup_mac_link_sfp_n - Setup internal PHY for native SFP
  1501. * @hw: pointer to hardware structure
  1502. *
  1503. * Configure the the integrated PHY for native SFP support.
  1504. */
  1505. static s32
  1506. ixgbe_setup_mac_link_sfp_n(struct ixgbe_hw *hw, ixgbe_link_speed speed,
  1507. __always_unused bool autoneg_wait_to_complete)
  1508. {
  1509. bool setup_linear = false;
  1510. u32 reg_phy_int;
  1511. s32 ret_val;
  1512. /* Check if SFP module is supported and linear */
  1513. ret_val = ixgbe_supported_sfp_modules_X550em(hw, &setup_linear);
  1514. /* If no SFP module present, then return success. Return success since
  1515. * SFP not present error is not excepted in the setup MAC link flow.
  1516. */
  1517. if (ret_val == IXGBE_ERR_SFP_NOT_PRESENT)
  1518. return 0;
  1519. if (!ret_val)
  1520. return ret_val;
  1521. /* Configure internal PHY for native SFI based on module type */
  1522. ret_val = hw->mac.ops.read_iosf_sb_reg(hw,
  1523. IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
  1524. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_phy_int);
  1525. if (!ret_val)
  1526. return ret_val;
  1527. reg_phy_int &= IXGBE_KRM_PMD_FLX_MASK_ST20_SFI_10G_DA;
  1528. if (!setup_linear)
  1529. reg_phy_int |= IXGBE_KRM_PMD_FLX_MASK_ST20_SFI_10G_SR;
  1530. ret_val = hw->mac.ops.write_iosf_sb_reg(hw,
  1531. IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
  1532. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_phy_int);
  1533. if (!ret_val)
  1534. return ret_val;
  1535. /* Setup SFI internal link. */
  1536. return ixgbe_setup_sfi_x550a(hw, &speed);
  1537. }
  1538. /**
  1539. * ixgbe_setup_mac_link_sfp_x550a - Setup internal PHY for SFP
  1540. * @hw: pointer to hardware structure
  1541. *
  1542. * Configure the the integrated PHY for SFP support.
  1543. */
  1544. static s32
  1545. ixgbe_setup_mac_link_sfp_x550a(struct ixgbe_hw *hw, ixgbe_link_speed speed,
  1546. __always_unused bool autoneg_wait_to_complete)
  1547. {
  1548. u32 reg_slice, slice_offset;
  1549. bool setup_linear = false;
  1550. u16 reg_phy_ext;
  1551. s32 ret_val;
  1552. /* Check if SFP module is supported and linear */
  1553. ret_val = ixgbe_supported_sfp_modules_X550em(hw, &setup_linear);
  1554. /* If no SFP module present, then return success. Return success since
  1555. * SFP not present error is not excepted in the setup MAC link flow.
  1556. */
  1557. if (ret_val == IXGBE_ERR_SFP_NOT_PRESENT)
  1558. return 0;
  1559. if (!ret_val)
  1560. return ret_val;
  1561. /* Configure internal PHY for KR/KX. */
  1562. ixgbe_setup_kr_speed_x550em(hw, speed);
  1563. if (hw->phy.mdio.prtad == MDIO_PRTAD_NONE)
  1564. return IXGBE_ERR_PHY_ADDR_INVALID;
  1565. /* Get external PHY device id */
  1566. ret_val = hw->phy.ops.read_reg(hw, IXGBE_CS4227_GLOBAL_ID_MSB,
  1567. IXGBE_MDIO_ZERO_DEV_TYPE, &reg_phy_ext);
  1568. if (ret_val)
  1569. return ret_val;
  1570. /* When configuring quad port CS4223, the MAC instance is part
  1571. * of the slice offset.
  1572. */
  1573. if (reg_phy_ext == IXGBE_CS4223_PHY_ID)
  1574. slice_offset = (hw->bus.lan_id +
  1575. (hw->bus.instance_id << 1)) << 12;
  1576. else
  1577. slice_offset = hw->bus.lan_id << 12;
  1578. /* Configure CS4227/CS4223 LINE side to proper mode. */
  1579. reg_slice = IXGBE_CS4227_LINE_SPARE24_LSB + slice_offset;
  1580. if (setup_linear)
  1581. reg_phy_ext = (IXGBE_CS4227_EDC_MODE_CX1 << 1) | 1;
  1582. else
  1583. reg_phy_ext = (IXGBE_CS4227_EDC_MODE_SR << 1) | 1;
  1584. return hw->phy.ops.write_reg(hw, reg_slice, IXGBE_MDIO_ZERO_DEV_TYPE,
  1585. reg_phy_ext);
  1586. }
  1587. /**
  1588. * ixgbe_setup_mac_link_t_X550em - Sets the auto advertised link speed
  1589. * @hw: pointer to hardware structure
  1590. * @speed: new link speed
  1591. * @autoneg_wait_to_complete: true when waiting for completion is needed
  1592. *
  1593. * Setup internal/external PHY link speed based on link speed, then set
  1594. * external PHY auto advertised link speed.
  1595. *
  1596. * Returns error status for any failure
  1597. **/
  1598. static s32 ixgbe_setup_mac_link_t_X550em(struct ixgbe_hw *hw,
  1599. ixgbe_link_speed speed,
  1600. bool autoneg_wait)
  1601. {
  1602. s32 status;
  1603. ixgbe_link_speed force_speed;
  1604. /* Setup internal/external PHY link speed to iXFI (10G), unless
  1605. * only 1G is auto advertised then setup KX link.
  1606. */
  1607. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  1608. force_speed = IXGBE_LINK_SPEED_10GB_FULL;
  1609. else
  1610. force_speed = IXGBE_LINK_SPEED_1GB_FULL;
  1611. /* If internal link mode is XFI, then setup XFI internal link. */
  1612. if (!(hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_INT_PHY_MODE)) {
  1613. status = ixgbe_setup_ixfi_x550em(hw, &force_speed);
  1614. if (status)
  1615. return status;
  1616. }
  1617. return hw->phy.ops.setup_link_speed(hw, speed, autoneg_wait);
  1618. }
  1619. /** ixgbe_check_link_t_X550em - Determine link and speed status
  1620. * @hw: pointer to hardware structure
  1621. * @speed: pointer to link speed
  1622. * @link_up: true when link is up
  1623. * @link_up_wait_to_complete: bool used to wait for link up or not
  1624. *
  1625. * Check that both the MAC and X557 external PHY have link.
  1626. **/
  1627. static s32 ixgbe_check_link_t_X550em(struct ixgbe_hw *hw,
  1628. ixgbe_link_speed *speed,
  1629. bool *link_up,
  1630. bool link_up_wait_to_complete)
  1631. {
  1632. u32 status;
  1633. u16 i, autoneg_status;
  1634. if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
  1635. return IXGBE_ERR_CONFIG;
  1636. status = ixgbe_check_mac_link_generic(hw, speed, link_up,
  1637. link_up_wait_to_complete);
  1638. /* If check link fails or MAC link is not up, then return */
  1639. if (status || !(*link_up))
  1640. return status;
  1641. /* MAC link is up, so check external PHY link.
  1642. * Link status is latching low, and can only be used to detect link
  1643. * drop, and not the current status of the link without performing
  1644. * back-to-back reads.
  1645. */
  1646. for (i = 0; i < 2; i++) {
  1647. status = hw->phy.ops.read_reg(hw, MDIO_STAT1, MDIO_MMD_AN,
  1648. &autoneg_status);
  1649. if (status)
  1650. return status;
  1651. }
  1652. /* If external PHY link is not up, then indicate link not up */
  1653. if (!(autoneg_status & IXGBE_MDIO_AUTO_NEG_LINK_STATUS))
  1654. *link_up = false;
  1655. return 0;
  1656. }
  1657. /**
  1658. * ixgbe_setup_sgmii - Set up link for sgmii
  1659. * @hw: pointer to hardware structure
  1660. */
  1661. static s32
  1662. ixgbe_setup_sgmii(struct ixgbe_hw *hw, __always_unused ixgbe_link_speed speed,
  1663. __always_unused bool autoneg_wait_to_complete)
  1664. {
  1665. struct ixgbe_mac_info *mac = &hw->mac;
  1666. u32 lval, sval, flx_val;
  1667. s32 rc;
  1668. rc = mac->ops.read_iosf_sb_reg(hw,
  1669. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  1670. IXGBE_SB_IOSF_TARGET_KR_PHY, &lval);
  1671. if (rc)
  1672. return rc;
  1673. lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
  1674. lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
  1675. lval |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_SGMII_EN;
  1676. lval |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CLAUSE_37_EN;
  1677. lval |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_1G;
  1678. rc = mac->ops.write_iosf_sb_reg(hw,
  1679. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  1680. IXGBE_SB_IOSF_TARGET_KR_PHY, lval);
  1681. if (rc)
  1682. return rc;
  1683. rc = mac->ops.read_iosf_sb_reg(hw,
  1684. IXGBE_KRM_SGMII_CTRL(hw->bus.lan_id),
  1685. IXGBE_SB_IOSF_TARGET_KR_PHY, &sval);
  1686. if (rc)
  1687. return rc;
  1688. sval |= IXGBE_KRM_SGMII_CTRL_MAC_TAR_FORCE_10_D;
  1689. sval |= IXGBE_KRM_SGMII_CTRL_MAC_TAR_FORCE_100_D;
  1690. rc = mac->ops.write_iosf_sb_reg(hw,
  1691. IXGBE_KRM_SGMII_CTRL(hw->bus.lan_id),
  1692. IXGBE_SB_IOSF_TARGET_KR_PHY, sval);
  1693. if (rc)
  1694. return rc;
  1695. rc = mac->ops.read_iosf_sb_reg(hw,
  1696. IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
  1697. IXGBE_SB_IOSF_TARGET_KR_PHY, &flx_val);
  1698. if (rc)
  1699. return rc;
  1700. rc = mac->ops.read_iosf_sb_reg(hw,
  1701. IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
  1702. IXGBE_SB_IOSF_TARGET_KR_PHY, &flx_val);
  1703. if (rc)
  1704. return rc;
  1705. flx_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_MASK;
  1706. flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_1G;
  1707. flx_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN_EN;
  1708. flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SGMII_EN;
  1709. flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_AN37_EN;
  1710. rc = mac->ops.write_iosf_sb_reg(hw,
  1711. IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
  1712. IXGBE_SB_IOSF_TARGET_KR_PHY, flx_val);
  1713. if (rc)
  1714. return rc;
  1715. rc = ixgbe_restart_an_internal_phy_x550em(hw);
  1716. return rc;
  1717. }
  1718. /**
  1719. * ixgbe_setup_sgmii_fw - Set up link for sgmii with firmware-controlled PHYs
  1720. * @hw: pointer to hardware structure
  1721. */
  1722. static s32 ixgbe_setup_sgmii_fw(struct ixgbe_hw *hw, ixgbe_link_speed speed,
  1723. bool autoneg_wait)
  1724. {
  1725. struct ixgbe_mac_info *mac = &hw->mac;
  1726. u32 lval, sval, flx_val;
  1727. s32 rc;
  1728. rc = mac->ops.read_iosf_sb_reg(hw,
  1729. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  1730. IXGBE_SB_IOSF_TARGET_KR_PHY, &lval);
  1731. if (rc)
  1732. return rc;
  1733. lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
  1734. lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
  1735. lval |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_SGMII_EN;
  1736. lval |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CLAUSE_37_EN;
  1737. lval &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_1G;
  1738. rc = mac->ops.write_iosf_sb_reg(hw,
  1739. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  1740. IXGBE_SB_IOSF_TARGET_KR_PHY, lval);
  1741. if (rc)
  1742. return rc;
  1743. rc = mac->ops.read_iosf_sb_reg(hw,
  1744. IXGBE_KRM_SGMII_CTRL(hw->bus.lan_id),
  1745. IXGBE_SB_IOSF_TARGET_KR_PHY, &sval);
  1746. if (rc)
  1747. return rc;
  1748. sval &= ~IXGBE_KRM_SGMII_CTRL_MAC_TAR_FORCE_10_D;
  1749. sval &= ~IXGBE_KRM_SGMII_CTRL_MAC_TAR_FORCE_100_D;
  1750. rc = mac->ops.write_iosf_sb_reg(hw,
  1751. IXGBE_KRM_SGMII_CTRL(hw->bus.lan_id),
  1752. IXGBE_SB_IOSF_TARGET_KR_PHY, sval);
  1753. if (rc)
  1754. return rc;
  1755. rc = mac->ops.write_iosf_sb_reg(hw,
  1756. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  1757. IXGBE_SB_IOSF_TARGET_KR_PHY, lval);
  1758. if (rc)
  1759. return rc;
  1760. rc = mac->ops.read_iosf_sb_reg(hw,
  1761. IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
  1762. IXGBE_SB_IOSF_TARGET_KR_PHY, &flx_val);
  1763. if (rc)
  1764. return rc;
  1765. flx_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_MASK;
  1766. flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_AN;
  1767. flx_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN_EN;
  1768. flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SGMII_EN;
  1769. flx_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_AN37_EN;
  1770. rc = mac->ops.write_iosf_sb_reg(hw,
  1771. IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
  1772. IXGBE_SB_IOSF_TARGET_KR_PHY, flx_val);
  1773. if (rc)
  1774. return rc;
  1775. ixgbe_restart_an_internal_phy_x550em(hw);
  1776. return hw->phy.ops.setup_link_speed(hw, speed, autoneg_wait);
  1777. }
  1778. /**
  1779. * ixgbe_fc_autoneg_sgmii_x550em_a - Enable flow control IEEE clause 37
  1780. * @hw: pointer to hardware structure
  1781. *
  1782. * Enable flow control according to IEEE clause 37.
  1783. */
  1784. static void ixgbe_fc_autoneg_sgmii_x550em_a(struct ixgbe_hw *hw)
  1785. {
  1786. s32 status = IXGBE_ERR_FC_NOT_NEGOTIATED;
  1787. u32 info[FW_PHY_ACT_DATA_COUNT] = { 0 };
  1788. ixgbe_link_speed speed;
  1789. bool link_up;
  1790. /* AN should have completed when the cable was plugged in.
  1791. * Look for reasons to bail out. Bail out if:
  1792. * - FC autoneg is disabled, or if
  1793. * - link is not up.
  1794. */
  1795. if (hw->fc.disable_fc_autoneg)
  1796. goto out;
  1797. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  1798. if (!link_up)
  1799. goto out;
  1800. /* Check if auto-negotiation has completed */
  1801. status = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_GET_LINK_INFO, &info);
  1802. if (status || !(info[0] & FW_PHY_ACT_GET_LINK_INFO_AN_COMPLETE)) {
  1803. status = IXGBE_ERR_FC_NOT_NEGOTIATED;
  1804. goto out;
  1805. }
  1806. /* Negotiate the flow control */
  1807. status = ixgbe_negotiate_fc(hw, info[0], info[0],
  1808. FW_PHY_ACT_GET_LINK_INFO_FC_RX,
  1809. FW_PHY_ACT_GET_LINK_INFO_FC_TX,
  1810. FW_PHY_ACT_GET_LINK_INFO_LP_FC_RX,
  1811. FW_PHY_ACT_GET_LINK_INFO_LP_FC_TX);
  1812. out:
  1813. if (!status) {
  1814. hw->fc.fc_was_autonegged = true;
  1815. } else {
  1816. hw->fc.fc_was_autonegged = false;
  1817. hw->fc.current_mode = hw->fc.requested_mode;
  1818. }
  1819. }
  1820. /** ixgbe_init_mac_link_ops_X550em_a - Init mac link function pointers
  1821. * @hw: pointer to hardware structure
  1822. **/
  1823. static void ixgbe_init_mac_link_ops_X550em_a(struct ixgbe_hw *hw)
  1824. {
  1825. struct ixgbe_mac_info *mac = &hw->mac;
  1826. switch (mac->ops.get_media_type(hw)) {
  1827. case ixgbe_media_type_fiber:
  1828. mac->ops.setup_fc = NULL;
  1829. mac->ops.fc_autoneg = ixgbe_fc_autoneg_fiber_x550em_a;
  1830. break;
  1831. case ixgbe_media_type_copper:
  1832. if (hw->device_id != IXGBE_DEV_ID_X550EM_A_1G_T &&
  1833. hw->device_id != IXGBE_DEV_ID_X550EM_A_1G_T_L) {
  1834. mac->ops.setup_link = ixgbe_setup_mac_link_t_X550em;
  1835. break;
  1836. }
  1837. mac->ops.fc_autoneg = ixgbe_fc_autoneg_sgmii_x550em_a;
  1838. mac->ops.setup_fc = ixgbe_fc_autoneg_fw;
  1839. mac->ops.setup_link = ixgbe_setup_sgmii_fw;
  1840. mac->ops.check_link = ixgbe_check_mac_link_generic;
  1841. break;
  1842. case ixgbe_media_type_backplane:
  1843. mac->ops.fc_autoneg = ixgbe_fc_autoneg_backplane_x550em_a;
  1844. mac->ops.setup_fc = ixgbe_setup_fc_backplane_x550em_a;
  1845. break;
  1846. default:
  1847. break;
  1848. }
  1849. }
  1850. /** ixgbe_init_mac_link_ops_X550em - init mac link function pointers
  1851. * @hw: pointer to hardware structure
  1852. **/
  1853. static void ixgbe_init_mac_link_ops_X550em(struct ixgbe_hw *hw)
  1854. {
  1855. struct ixgbe_mac_info *mac = &hw->mac;
  1856. mac->ops.setup_fc = ixgbe_setup_fc_x550em;
  1857. switch (mac->ops.get_media_type(hw)) {
  1858. case ixgbe_media_type_fiber:
  1859. /* CS4227 does not support autoneg, so disable the laser control
  1860. * functions for SFP+ fiber
  1861. */
  1862. mac->ops.disable_tx_laser = NULL;
  1863. mac->ops.enable_tx_laser = NULL;
  1864. mac->ops.flap_tx_laser = NULL;
  1865. mac->ops.setup_link = ixgbe_setup_mac_link_multispeed_fiber;
  1866. switch (hw->device_id) {
  1867. case IXGBE_DEV_ID_X550EM_A_SFP_N:
  1868. mac->ops.setup_mac_link = ixgbe_setup_mac_link_sfp_n;
  1869. break;
  1870. case IXGBE_DEV_ID_X550EM_A_SFP:
  1871. mac->ops.setup_mac_link =
  1872. ixgbe_setup_mac_link_sfp_x550a;
  1873. break;
  1874. default:
  1875. mac->ops.setup_mac_link =
  1876. ixgbe_setup_mac_link_sfp_x550em;
  1877. break;
  1878. }
  1879. mac->ops.set_rate_select_speed =
  1880. ixgbe_set_soft_rate_select_speed;
  1881. break;
  1882. case ixgbe_media_type_copper:
  1883. if (hw->device_id == IXGBE_DEV_ID_X550EM_X_1G_T)
  1884. break;
  1885. mac->ops.setup_link = ixgbe_setup_mac_link_t_X550em;
  1886. mac->ops.setup_fc = ixgbe_setup_fc_generic;
  1887. mac->ops.check_link = ixgbe_check_link_t_X550em;
  1888. break;
  1889. case ixgbe_media_type_backplane:
  1890. if (hw->device_id == IXGBE_DEV_ID_X550EM_A_SGMII ||
  1891. hw->device_id == IXGBE_DEV_ID_X550EM_A_SGMII_L)
  1892. mac->ops.setup_link = ixgbe_setup_sgmii;
  1893. break;
  1894. default:
  1895. break;
  1896. }
  1897. /* Additional modification for X550em_a devices */
  1898. if (hw->mac.type == ixgbe_mac_x550em_a)
  1899. ixgbe_init_mac_link_ops_X550em_a(hw);
  1900. }
  1901. /** ixgbe_setup_sfp_modules_X550em - Setup SFP module
  1902. * @hw: pointer to hardware structure
  1903. */
  1904. static s32 ixgbe_setup_sfp_modules_X550em(struct ixgbe_hw *hw)
  1905. {
  1906. s32 status;
  1907. bool linear;
  1908. /* Check if SFP module is supported */
  1909. status = ixgbe_supported_sfp_modules_X550em(hw, &linear);
  1910. if (status)
  1911. return status;
  1912. ixgbe_init_mac_link_ops_X550em(hw);
  1913. hw->phy.ops.reset = NULL;
  1914. return 0;
  1915. }
  1916. /** ixgbe_get_link_capabilities_x550em - Determines link capabilities
  1917. * @hw: pointer to hardware structure
  1918. * @speed: pointer to link speed
  1919. * @autoneg: true when autoneg or autotry is enabled
  1920. **/
  1921. static s32 ixgbe_get_link_capabilities_X550em(struct ixgbe_hw *hw,
  1922. ixgbe_link_speed *speed,
  1923. bool *autoneg)
  1924. {
  1925. if (hw->phy.type == ixgbe_phy_fw) {
  1926. *autoneg = true;
  1927. *speed = hw->phy.speeds_supported;
  1928. return 0;
  1929. }
  1930. /* SFP */
  1931. if (hw->phy.media_type == ixgbe_media_type_fiber) {
  1932. /* CS4227 SFP must not enable auto-negotiation */
  1933. *autoneg = false;
  1934. if (hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
  1935. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1) {
  1936. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  1937. return 0;
  1938. }
  1939. /* Link capabilities are based on SFP */
  1940. if (hw->phy.multispeed_fiber)
  1941. *speed = IXGBE_LINK_SPEED_10GB_FULL |
  1942. IXGBE_LINK_SPEED_1GB_FULL;
  1943. else
  1944. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  1945. } else {
  1946. switch (hw->phy.type) {
  1947. case ixgbe_phy_x550em_kx4:
  1948. *speed = IXGBE_LINK_SPEED_1GB_FULL |
  1949. IXGBE_LINK_SPEED_2_5GB_FULL |
  1950. IXGBE_LINK_SPEED_10GB_FULL;
  1951. break;
  1952. case ixgbe_phy_x550em_xfi:
  1953. *speed = IXGBE_LINK_SPEED_1GB_FULL |
  1954. IXGBE_LINK_SPEED_10GB_FULL;
  1955. break;
  1956. case ixgbe_phy_ext_1g_t:
  1957. case ixgbe_phy_sgmii:
  1958. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  1959. break;
  1960. case ixgbe_phy_x550em_kr:
  1961. if (hw->mac.type == ixgbe_mac_x550em_a) {
  1962. /* check different backplane modes */
  1963. if (hw->phy.nw_mng_if_sel &
  1964. IXGBE_NW_MNG_IF_SEL_PHY_SPEED_2_5G) {
  1965. *speed = IXGBE_LINK_SPEED_2_5GB_FULL;
  1966. break;
  1967. } else if (hw->device_id ==
  1968. IXGBE_DEV_ID_X550EM_A_KR_L) {
  1969. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  1970. break;
  1971. }
  1972. }
  1973. /* fall through */
  1974. default:
  1975. *speed = IXGBE_LINK_SPEED_10GB_FULL |
  1976. IXGBE_LINK_SPEED_1GB_FULL;
  1977. break;
  1978. }
  1979. *autoneg = true;
  1980. }
  1981. return 0;
  1982. }
  1983. /**
  1984. * ixgbe_get_lasi_ext_t_x550em - Determime external Base T PHY interrupt cause
  1985. * @hw: pointer to hardware structure
  1986. * @lsc: pointer to boolean flag which indicates whether external Base T
  1987. * PHY interrupt is lsc
  1988. *
  1989. * Determime if external Base T PHY interrupt cause is high temperature
  1990. * failure alarm or link status change.
  1991. *
  1992. * Return IXGBE_ERR_OVERTEMP if interrupt is high temperature
  1993. * failure alarm, else return PHY access status.
  1994. **/
  1995. static s32 ixgbe_get_lasi_ext_t_x550em(struct ixgbe_hw *hw, bool *lsc)
  1996. {
  1997. u32 status;
  1998. u16 reg;
  1999. *lsc = false;
  2000. /* Vendor alarm triggered */
  2001. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_CHIP_STD_INT_FLAG,
  2002. MDIO_MMD_VEND1,
  2003. &reg);
  2004. if (status || !(reg & IXGBE_MDIO_GLOBAL_VEN_ALM_INT_EN))
  2005. return status;
  2006. /* Vendor Auto-Neg alarm triggered or Global alarm 1 triggered */
  2007. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_FLAG,
  2008. MDIO_MMD_VEND1,
  2009. &reg);
  2010. if (status || !(reg & (IXGBE_MDIO_GLOBAL_AN_VEN_ALM_INT_EN |
  2011. IXGBE_MDIO_GLOBAL_ALARM_1_INT)))
  2012. return status;
  2013. /* Global alarm triggered */
  2014. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_ALARM_1,
  2015. MDIO_MMD_VEND1,
  2016. &reg);
  2017. if (status)
  2018. return status;
  2019. /* If high temperature failure, then return over temp error and exit */
  2020. if (reg & IXGBE_MDIO_GLOBAL_ALM_1_HI_TMP_FAIL) {
  2021. /* power down the PHY in case the PHY FW didn't already */
  2022. ixgbe_set_copper_phy_power(hw, false);
  2023. return IXGBE_ERR_OVERTEMP;
  2024. }
  2025. if (reg & IXGBE_MDIO_GLOBAL_ALM_1_DEV_FAULT) {
  2026. /* device fault alarm triggered */
  2027. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_FAULT_MSG,
  2028. MDIO_MMD_VEND1,
  2029. &reg);
  2030. if (status)
  2031. return status;
  2032. /* if device fault was due to high temp alarm handle and exit */
  2033. if (reg == IXGBE_MDIO_GLOBAL_FAULT_MSG_HI_TMP) {
  2034. /* power down the PHY in case the PHY FW didn't */
  2035. ixgbe_set_copper_phy_power(hw, false);
  2036. return IXGBE_ERR_OVERTEMP;
  2037. }
  2038. }
  2039. /* Vendor alarm 2 triggered */
  2040. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_CHIP_STD_INT_FLAG,
  2041. MDIO_MMD_AN, &reg);
  2042. if (status || !(reg & IXGBE_MDIO_GLOBAL_STD_ALM2_INT))
  2043. return status;
  2044. /* link connect/disconnect event occurred */
  2045. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_TX_ALARM2,
  2046. MDIO_MMD_AN, &reg);
  2047. if (status)
  2048. return status;
  2049. /* Indicate LSC */
  2050. if (reg & IXGBE_MDIO_AUTO_NEG_VEN_LSC)
  2051. *lsc = true;
  2052. return 0;
  2053. }
  2054. /**
  2055. * ixgbe_enable_lasi_ext_t_x550em - Enable external Base T PHY interrupts
  2056. * @hw: pointer to hardware structure
  2057. *
  2058. * Enable link status change and temperature failure alarm for the external
  2059. * Base T PHY
  2060. *
  2061. * Returns PHY access status
  2062. **/
  2063. static s32 ixgbe_enable_lasi_ext_t_x550em(struct ixgbe_hw *hw)
  2064. {
  2065. u32 status;
  2066. u16 reg;
  2067. bool lsc;
  2068. /* Clear interrupt flags */
  2069. status = ixgbe_get_lasi_ext_t_x550em(hw, &lsc);
  2070. /* Enable link status change alarm */
  2071. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PMA_TX_VEN_LASI_INT_MASK,
  2072. MDIO_MMD_AN, &reg);
  2073. if (status)
  2074. return status;
  2075. reg |= IXGBE_MDIO_PMA_TX_VEN_LASI_INT_EN;
  2076. status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_PMA_TX_VEN_LASI_INT_MASK,
  2077. MDIO_MMD_AN, reg);
  2078. if (status)
  2079. return status;
  2080. /* Enable high temperature failure and global fault alarms */
  2081. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_MASK,
  2082. MDIO_MMD_VEND1,
  2083. &reg);
  2084. if (status)
  2085. return status;
  2086. reg |= (IXGBE_MDIO_GLOBAL_INT_HI_TEMP_EN |
  2087. IXGBE_MDIO_GLOBAL_INT_DEV_FAULT_EN);
  2088. status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_MASK,
  2089. MDIO_MMD_VEND1,
  2090. reg);
  2091. if (status)
  2092. return status;
  2093. /* Enable vendor Auto-Neg alarm and Global Interrupt Mask 1 alarm */
  2094. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_MASK,
  2095. MDIO_MMD_VEND1,
  2096. &reg);
  2097. if (status)
  2098. return status;
  2099. reg |= (IXGBE_MDIO_GLOBAL_AN_VEN_ALM_INT_EN |
  2100. IXGBE_MDIO_GLOBAL_ALARM_1_INT);
  2101. status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_MASK,
  2102. MDIO_MMD_VEND1,
  2103. reg);
  2104. if (status)
  2105. return status;
  2106. /* Enable chip-wide vendor alarm */
  2107. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_STD_MASK,
  2108. MDIO_MMD_VEND1,
  2109. &reg);
  2110. if (status)
  2111. return status;
  2112. reg |= IXGBE_MDIO_GLOBAL_VEN_ALM_INT_EN;
  2113. status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_STD_MASK,
  2114. MDIO_MMD_VEND1,
  2115. reg);
  2116. return status;
  2117. }
  2118. /**
  2119. * ixgbe_handle_lasi_ext_t_x550em - Handle external Base T PHY interrupt
  2120. * @hw: pointer to hardware structure
  2121. *
  2122. * Handle external Base T PHY interrupt. If high temperature
  2123. * failure alarm then return error, else if link status change
  2124. * then setup internal/external PHY link
  2125. *
  2126. * Return IXGBE_ERR_OVERTEMP if interrupt is high temperature
  2127. * failure alarm, else return PHY access status.
  2128. **/
  2129. static s32 ixgbe_handle_lasi_ext_t_x550em(struct ixgbe_hw *hw)
  2130. {
  2131. struct ixgbe_phy_info *phy = &hw->phy;
  2132. bool lsc;
  2133. u32 status;
  2134. status = ixgbe_get_lasi_ext_t_x550em(hw, &lsc);
  2135. if (status)
  2136. return status;
  2137. if (lsc && phy->ops.setup_internal_link)
  2138. return phy->ops.setup_internal_link(hw);
  2139. return 0;
  2140. }
  2141. /**
  2142. * ixgbe_setup_kr_speed_x550em - Configure the KR PHY for link speed.
  2143. * @hw: pointer to hardware structure
  2144. * @speed: link speed
  2145. *
  2146. * Configures the integrated KR PHY.
  2147. **/
  2148. static s32 ixgbe_setup_kr_speed_x550em(struct ixgbe_hw *hw,
  2149. ixgbe_link_speed speed)
  2150. {
  2151. s32 status;
  2152. u32 reg_val;
  2153. status = hw->mac.ops.read_iosf_sb_reg(hw,
  2154. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  2155. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  2156. if (status)
  2157. return status;
  2158. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
  2159. reg_val &= ~(IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR |
  2160. IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX);
  2161. /* Advertise 10G support. */
  2162. if (speed & IXGBE_LINK_SPEED_10GB_FULL)
  2163. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR;
  2164. /* Advertise 1G support. */
  2165. if (speed & IXGBE_LINK_SPEED_1GB_FULL)
  2166. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX;
  2167. status = hw->mac.ops.write_iosf_sb_reg(hw,
  2168. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  2169. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  2170. if (hw->mac.type == ixgbe_mac_x550em_a) {
  2171. /* Set lane mode to KR auto negotiation */
  2172. status = hw->mac.ops.read_iosf_sb_reg(hw,
  2173. IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
  2174. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  2175. if (status)
  2176. return status;
  2177. reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_MASK;
  2178. reg_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_SPEED_AN;
  2179. reg_val |= IXGBE_KRM_PMD_FLX_MASK_ST20_AN_EN;
  2180. reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_AN37_EN;
  2181. reg_val &= ~IXGBE_KRM_PMD_FLX_MASK_ST20_SGMII_EN;
  2182. status = hw->mac.ops.write_iosf_sb_reg(hw,
  2183. IXGBE_KRM_PMD_FLX_MASK_ST20(hw->bus.lan_id),
  2184. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  2185. }
  2186. return ixgbe_restart_an_internal_phy_x550em(hw);
  2187. }
  2188. /**
  2189. * ixgbe_setup_kr_x550em - Configure the KR PHY
  2190. * @hw: pointer to hardware structure
  2191. **/
  2192. static s32 ixgbe_setup_kr_x550em(struct ixgbe_hw *hw)
  2193. {
  2194. /* leave link alone for 2.5G */
  2195. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_2_5GB_FULL)
  2196. return 0;
  2197. if (ixgbe_check_reset_blocked(hw))
  2198. return 0;
  2199. return ixgbe_setup_kr_speed_x550em(hw, hw->phy.autoneg_advertised);
  2200. }
  2201. /** ixgbe_ext_phy_t_x550em_get_link - Get ext phy link status
  2202. * @hw: address of hardware structure
  2203. * @link_up: address of boolean to indicate link status
  2204. *
  2205. * Returns error code if unable to get link status.
  2206. **/
  2207. static s32 ixgbe_ext_phy_t_x550em_get_link(struct ixgbe_hw *hw, bool *link_up)
  2208. {
  2209. u32 ret;
  2210. u16 autoneg_status;
  2211. *link_up = false;
  2212. /* read this twice back to back to indicate current status */
  2213. ret = hw->phy.ops.read_reg(hw, MDIO_STAT1, MDIO_MMD_AN,
  2214. &autoneg_status);
  2215. if (ret)
  2216. return ret;
  2217. ret = hw->phy.ops.read_reg(hw, MDIO_STAT1, MDIO_MMD_AN,
  2218. &autoneg_status);
  2219. if (ret)
  2220. return ret;
  2221. *link_up = !!(autoneg_status & IXGBE_MDIO_AUTO_NEG_LINK_STATUS);
  2222. return 0;
  2223. }
  2224. /** ixgbe_setup_internal_phy_t_x550em - Configure KR PHY to X557 link
  2225. * @hw: point to hardware structure
  2226. *
  2227. * Configures the link between the integrated KR PHY and the external X557 PHY
  2228. * The driver will call this function when it gets a link status change
  2229. * interrupt from the X557 PHY. This function configures the link speed
  2230. * between the PHYs to match the link speed of the BASE-T link.
  2231. *
  2232. * A return of a non-zero value indicates an error, and the base driver should
  2233. * not report link up.
  2234. **/
  2235. static s32 ixgbe_setup_internal_phy_t_x550em(struct ixgbe_hw *hw)
  2236. {
  2237. ixgbe_link_speed force_speed;
  2238. bool link_up;
  2239. u32 status;
  2240. u16 speed;
  2241. if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
  2242. return IXGBE_ERR_CONFIG;
  2243. if (hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_INT_PHY_MODE) {
  2244. speed = IXGBE_LINK_SPEED_10GB_FULL |
  2245. IXGBE_LINK_SPEED_1GB_FULL;
  2246. return ixgbe_setup_kr_speed_x550em(hw, speed);
  2247. }
  2248. /* If link is not up, then there is no setup necessary so return */
  2249. status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
  2250. if (status)
  2251. return status;
  2252. if (!link_up)
  2253. return 0;
  2254. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_STAT,
  2255. MDIO_MMD_AN,
  2256. &speed);
  2257. if (status)
  2258. return status;
  2259. /* If link is not still up, then no setup is necessary so return */
  2260. status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
  2261. if (status)
  2262. return status;
  2263. if (!link_up)
  2264. return 0;
  2265. /* clear everything but the speed and duplex bits */
  2266. speed &= IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_MASK;
  2267. switch (speed) {
  2268. case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_10GB_FULL:
  2269. force_speed = IXGBE_LINK_SPEED_10GB_FULL;
  2270. break;
  2271. case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_1GB_FULL:
  2272. force_speed = IXGBE_LINK_SPEED_1GB_FULL;
  2273. break;
  2274. default:
  2275. /* Internal PHY does not support anything else */
  2276. return IXGBE_ERR_INVALID_LINK_SETTINGS;
  2277. }
  2278. return ixgbe_setup_ixfi_x550em(hw, &force_speed);
  2279. }
  2280. /** ixgbe_reset_phy_t_X550em - Performs X557 PHY reset and enables LASI
  2281. * @hw: pointer to hardware structure
  2282. **/
  2283. static s32 ixgbe_reset_phy_t_X550em(struct ixgbe_hw *hw)
  2284. {
  2285. s32 status;
  2286. status = ixgbe_reset_phy_generic(hw);
  2287. if (status)
  2288. return status;
  2289. /* Configure Link Status Alarm and Temperature Threshold interrupts */
  2290. return ixgbe_enable_lasi_ext_t_x550em(hw);
  2291. }
  2292. /**
  2293. * ixgbe_led_on_t_x550em - Turns on the software controllable LEDs.
  2294. * @hw: pointer to hardware structure
  2295. * @led_idx: led number to turn on
  2296. **/
  2297. static s32 ixgbe_led_on_t_x550em(struct ixgbe_hw *hw, u32 led_idx)
  2298. {
  2299. u16 phy_data;
  2300. if (led_idx >= IXGBE_X557_MAX_LED_INDEX)
  2301. return IXGBE_ERR_PARAM;
  2302. /* To turn on the LED, set mode to ON. */
  2303. hw->phy.ops.read_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
  2304. MDIO_MMD_VEND1, &phy_data);
  2305. phy_data |= IXGBE_X557_LED_MANUAL_SET_MASK;
  2306. hw->phy.ops.write_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
  2307. MDIO_MMD_VEND1, phy_data);
  2308. return 0;
  2309. }
  2310. /**
  2311. * ixgbe_led_off_t_x550em - Turns off the software controllable LEDs.
  2312. * @hw: pointer to hardware structure
  2313. * @led_idx: led number to turn off
  2314. **/
  2315. static s32 ixgbe_led_off_t_x550em(struct ixgbe_hw *hw, u32 led_idx)
  2316. {
  2317. u16 phy_data;
  2318. if (led_idx >= IXGBE_X557_MAX_LED_INDEX)
  2319. return IXGBE_ERR_PARAM;
  2320. /* To turn on the LED, set mode to ON. */
  2321. hw->phy.ops.read_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
  2322. MDIO_MMD_VEND1, &phy_data);
  2323. phy_data &= ~IXGBE_X557_LED_MANUAL_SET_MASK;
  2324. hw->phy.ops.write_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
  2325. MDIO_MMD_VEND1, phy_data);
  2326. return 0;
  2327. }
  2328. /**
  2329. * ixgbe_set_fw_drv_ver_x550 - Sends driver version to firmware
  2330. * @hw: pointer to the HW structure
  2331. * @maj: driver version major number
  2332. * @min: driver version minor number
  2333. * @build: driver version build number
  2334. * @sub: driver version sub build number
  2335. * @len: length of driver_ver string
  2336. * @driver_ver: driver string
  2337. *
  2338. * Sends driver version number to firmware through the manageability
  2339. * block. On success return 0
  2340. * else returns IXGBE_ERR_SWFW_SYNC when encountering an error acquiring
  2341. * semaphore or IXGBE_ERR_HOST_INTERFACE_COMMAND when command fails.
  2342. **/
  2343. static s32 ixgbe_set_fw_drv_ver_x550(struct ixgbe_hw *hw, u8 maj, u8 min,
  2344. u8 build, u8 sub, u16 len,
  2345. const char *driver_ver)
  2346. {
  2347. struct ixgbe_hic_drv_info2 fw_cmd;
  2348. s32 ret_val;
  2349. int i;
  2350. if (!len || !driver_ver || (len > sizeof(fw_cmd.driver_string)))
  2351. return IXGBE_ERR_INVALID_ARGUMENT;
  2352. fw_cmd.hdr.cmd = FW_CEM_CMD_DRIVER_INFO;
  2353. fw_cmd.hdr.buf_len = FW_CEM_CMD_DRIVER_INFO_LEN + len;
  2354. fw_cmd.hdr.cmd_or_resp.cmd_resv = FW_CEM_CMD_RESERVED;
  2355. fw_cmd.port_num = (u8)hw->bus.func;
  2356. fw_cmd.ver_maj = maj;
  2357. fw_cmd.ver_min = min;
  2358. fw_cmd.ver_build = build;
  2359. fw_cmd.ver_sub = sub;
  2360. fw_cmd.hdr.checksum = 0;
  2361. memcpy(fw_cmd.driver_string, driver_ver, len);
  2362. fw_cmd.hdr.checksum = ixgbe_calculate_checksum((u8 *)&fw_cmd,
  2363. (FW_CEM_HDR_LEN + fw_cmd.hdr.buf_len));
  2364. for (i = 0; i <= FW_CEM_MAX_RETRIES; i++) {
  2365. ret_val = ixgbe_host_interface_command(hw, (u32 *)&fw_cmd,
  2366. sizeof(fw_cmd),
  2367. IXGBE_HI_COMMAND_TIMEOUT,
  2368. true);
  2369. if (ret_val)
  2370. continue;
  2371. if (fw_cmd.hdr.cmd_or_resp.ret_status !=
  2372. FW_CEM_RESP_STATUS_SUCCESS)
  2373. return IXGBE_ERR_HOST_INTERFACE_COMMAND;
  2374. return 0;
  2375. }
  2376. return ret_val;
  2377. }
  2378. /** ixgbe_get_lcd_x550em - Determine lowest common denominator
  2379. * @hw: pointer to hardware structure
  2380. * @lcd_speed: pointer to lowest common link speed
  2381. *
  2382. * Determine lowest common link speed with link partner.
  2383. **/
  2384. static s32 ixgbe_get_lcd_t_x550em(struct ixgbe_hw *hw,
  2385. ixgbe_link_speed *lcd_speed)
  2386. {
  2387. u16 an_lp_status;
  2388. s32 status;
  2389. u16 word = hw->eeprom.ctrl_word_3;
  2390. *lcd_speed = IXGBE_LINK_SPEED_UNKNOWN;
  2391. status = hw->phy.ops.read_reg(hw, IXGBE_AUTO_NEG_LP_STATUS,
  2392. MDIO_MMD_AN,
  2393. &an_lp_status);
  2394. if (status)
  2395. return status;
  2396. /* If link partner advertised 1G, return 1G */
  2397. if (an_lp_status & IXGBE_AUTO_NEG_LP_1000BASE_CAP) {
  2398. *lcd_speed = IXGBE_LINK_SPEED_1GB_FULL;
  2399. return status;
  2400. }
  2401. /* If 10G disabled for LPLU via NVM D10GMP, then return no valid LCD */
  2402. if ((hw->bus.lan_id && (word & NVM_INIT_CTRL_3_D10GMP_PORT1)) ||
  2403. (word & NVM_INIT_CTRL_3_D10GMP_PORT0))
  2404. return status;
  2405. /* Link partner not capable of lower speeds, return 10G */
  2406. *lcd_speed = IXGBE_LINK_SPEED_10GB_FULL;
  2407. return status;
  2408. }
  2409. /**
  2410. * ixgbe_setup_fc_x550em - Set up flow control
  2411. * @hw: pointer to hardware structure
  2412. */
  2413. static s32 ixgbe_setup_fc_x550em(struct ixgbe_hw *hw)
  2414. {
  2415. bool pause, asm_dir;
  2416. u32 reg_val;
  2417. s32 rc;
  2418. /* Validate the requested mode */
  2419. if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
  2420. hw_err(hw, "ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
  2421. return IXGBE_ERR_INVALID_LINK_SETTINGS;
  2422. }
  2423. /* 10gig parts do not have a word in the EEPROM to determine the
  2424. * default flow control setting, so we explicitly set it to full.
  2425. */
  2426. if (hw->fc.requested_mode == ixgbe_fc_default)
  2427. hw->fc.requested_mode = ixgbe_fc_full;
  2428. /* Determine PAUSE and ASM_DIR bits. */
  2429. switch (hw->fc.requested_mode) {
  2430. case ixgbe_fc_none:
  2431. pause = false;
  2432. asm_dir = false;
  2433. break;
  2434. case ixgbe_fc_tx_pause:
  2435. pause = false;
  2436. asm_dir = true;
  2437. break;
  2438. case ixgbe_fc_rx_pause:
  2439. /* Rx Flow control is enabled and Tx Flow control is
  2440. * disabled by software override. Since there really
  2441. * isn't a way to advertise that we are capable of RX
  2442. * Pause ONLY, we will advertise that we support both
  2443. * symmetric and asymmetric Rx PAUSE, as such we fall
  2444. * through to the fc_full statement. Later, we will
  2445. * disable the adapter's ability to send PAUSE frames.
  2446. */
  2447. /* Fallthrough */
  2448. case ixgbe_fc_full:
  2449. pause = true;
  2450. asm_dir = true;
  2451. break;
  2452. default:
  2453. hw_err(hw, "Flow control param set incorrectly\n");
  2454. return IXGBE_ERR_CONFIG;
  2455. }
  2456. if (hw->device_id != IXGBE_DEV_ID_X550EM_X_KR &&
  2457. hw->device_id != IXGBE_DEV_ID_X550EM_A_KR &&
  2458. hw->device_id != IXGBE_DEV_ID_X550EM_A_KR_L)
  2459. return 0;
  2460. rc = hw->mac.ops.read_iosf_sb_reg(hw,
  2461. IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
  2462. IXGBE_SB_IOSF_TARGET_KR_PHY,
  2463. &reg_val);
  2464. if (rc)
  2465. return rc;
  2466. reg_val &= ~(IXGBE_KRM_AN_CNTL_1_SYM_PAUSE |
  2467. IXGBE_KRM_AN_CNTL_1_ASM_PAUSE);
  2468. if (pause)
  2469. reg_val |= IXGBE_KRM_AN_CNTL_1_SYM_PAUSE;
  2470. if (asm_dir)
  2471. reg_val |= IXGBE_KRM_AN_CNTL_1_ASM_PAUSE;
  2472. rc = hw->mac.ops.write_iosf_sb_reg(hw,
  2473. IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
  2474. IXGBE_SB_IOSF_TARGET_KR_PHY,
  2475. reg_val);
  2476. /* This device does not fully support AN. */
  2477. hw->fc.disable_fc_autoneg = true;
  2478. return rc;
  2479. }
  2480. /**
  2481. * ixgbe_fc_autoneg_backplane_x550em_a - Enable flow control IEEE clause 37
  2482. * @hw: pointer to hardware structure
  2483. **/
  2484. static void ixgbe_fc_autoneg_backplane_x550em_a(struct ixgbe_hw *hw)
  2485. {
  2486. u32 link_s1, lp_an_page_low, an_cntl_1;
  2487. s32 status = IXGBE_ERR_FC_NOT_NEGOTIATED;
  2488. ixgbe_link_speed speed;
  2489. bool link_up;
  2490. /* AN should have completed when the cable was plugged in.
  2491. * Look for reasons to bail out. Bail out if:
  2492. * - FC autoneg is disabled, or if
  2493. * - link is not up.
  2494. */
  2495. if (hw->fc.disable_fc_autoneg) {
  2496. hw_err(hw, "Flow control autoneg is disabled");
  2497. goto out;
  2498. }
  2499. hw->mac.ops.check_link(hw, &speed, &link_up, false);
  2500. if (!link_up) {
  2501. hw_err(hw, "The link is down");
  2502. goto out;
  2503. }
  2504. /* Check at auto-negotiation has completed */
  2505. status = hw->mac.ops.read_iosf_sb_reg(hw,
  2506. IXGBE_KRM_LINK_S1(hw->bus.lan_id),
  2507. IXGBE_SB_IOSF_TARGET_KR_PHY, &link_s1);
  2508. if (status || (link_s1 & IXGBE_KRM_LINK_S1_MAC_AN_COMPLETE) == 0) {
  2509. hw_dbg(hw, "Auto-Negotiation did not complete\n");
  2510. status = IXGBE_ERR_FC_NOT_NEGOTIATED;
  2511. goto out;
  2512. }
  2513. /* Read the 10g AN autoc and LP ability registers and resolve
  2514. * local flow control settings accordingly
  2515. */
  2516. status = hw->mac.ops.read_iosf_sb_reg(hw,
  2517. IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
  2518. IXGBE_SB_IOSF_TARGET_KR_PHY, &an_cntl_1);
  2519. if (status) {
  2520. hw_dbg(hw, "Auto-Negotiation did not complete\n");
  2521. goto out;
  2522. }
  2523. status = hw->mac.ops.read_iosf_sb_reg(hw,
  2524. IXGBE_KRM_LP_BASE_PAGE_HIGH(hw->bus.lan_id),
  2525. IXGBE_SB_IOSF_TARGET_KR_PHY, &lp_an_page_low);
  2526. if (status) {
  2527. hw_dbg(hw, "Auto-Negotiation did not complete\n");
  2528. goto out;
  2529. }
  2530. status = ixgbe_negotiate_fc(hw, an_cntl_1, lp_an_page_low,
  2531. IXGBE_KRM_AN_CNTL_1_SYM_PAUSE,
  2532. IXGBE_KRM_AN_CNTL_1_ASM_PAUSE,
  2533. IXGBE_KRM_LP_BASE_PAGE_HIGH_SYM_PAUSE,
  2534. IXGBE_KRM_LP_BASE_PAGE_HIGH_ASM_PAUSE);
  2535. out:
  2536. if (!status) {
  2537. hw->fc.fc_was_autonegged = true;
  2538. } else {
  2539. hw->fc.fc_was_autonegged = false;
  2540. hw->fc.current_mode = hw->fc.requested_mode;
  2541. }
  2542. }
  2543. /**
  2544. * ixgbe_fc_autoneg_fiber_x550em_a - passthrough FC settings
  2545. * @hw: pointer to hardware structure
  2546. **/
  2547. static void ixgbe_fc_autoneg_fiber_x550em_a(struct ixgbe_hw *hw)
  2548. {
  2549. hw->fc.fc_was_autonegged = false;
  2550. hw->fc.current_mode = hw->fc.requested_mode;
  2551. }
  2552. /** ixgbe_enter_lplu_x550em - Transition to low power states
  2553. * @hw: pointer to hardware structure
  2554. *
  2555. * Configures Low Power Link Up on transition to low power states
  2556. * (from D0 to non-D0). Link is required to enter LPLU so avoid resetting
  2557. * the X557 PHY immediately prior to entering LPLU.
  2558. **/
  2559. static s32 ixgbe_enter_lplu_t_x550em(struct ixgbe_hw *hw)
  2560. {
  2561. u16 an_10g_cntl_reg, autoneg_reg, speed;
  2562. s32 status;
  2563. ixgbe_link_speed lcd_speed;
  2564. u32 save_autoneg;
  2565. bool link_up;
  2566. /* If blocked by MNG FW, then don't restart AN */
  2567. if (ixgbe_check_reset_blocked(hw))
  2568. return 0;
  2569. status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
  2570. if (status)
  2571. return status;
  2572. status = hw->eeprom.ops.read(hw, NVM_INIT_CTRL_3,
  2573. &hw->eeprom.ctrl_word_3);
  2574. if (status)
  2575. return status;
  2576. /* If link is down, LPLU disabled in NVM, WoL disabled, or
  2577. * manageability disabled, then force link down by entering
  2578. * low power mode.
  2579. */
  2580. if (!link_up || !(hw->eeprom.ctrl_word_3 & NVM_INIT_CTRL_3_LPLU) ||
  2581. !(hw->wol_enabled || ixgbe_mng_present(hw)))
  2582. return ixgbe_set_copper_phy_power(hw, false);
  2583. /* Determine LCD */
  2584. status = ixgbe_get_lcd_t_x550em(hw, &lcd_speed);
  2585. if (status)
  2586. return status;
  2587. /* If no valid LCD link speed, then force link down and exit. */
  2588. if (lcd_speed == IXGBE_LINK_SPEED_UNKNOWN)
  2589. return ixgbe_set_copper_phy_power(hw, false);
  2590. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_STAT,
  2591. MDIO_MMD_AN,
  2592. &speed);
  2593. if (status)
  2594. return status;
  2595. /* If no link now, speed is invalid so take link down */
  2596. status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
  2597. if (status)
  2598. return ixgbe_set_copper_phy_power(hw, false);
  2599. /* clear everything but the speed bits */
  2600. speed &= IXGBE_MDIO_AUTO_NEG_VEN_STAT_SPEED_MASK;
  2601. /* If current speed is already LCD, then exit. */
  2602. if (((speed == IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_1GB) &&
  2603. (lcd_speed == IXGBE_LINK_SPEED_1GB_FULL)) ||
  2604. ((speed == IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_10GB) &&
  2605. (lcd_speed == IXGBE_LINK_SPEED_10GB_FULL)))
  2606. return status;
  2607. /* Clear AN completed indication */
  2608. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_TX_ALARM,
  2609. MDIO_MMD_AN,
  2610. &autoneg_reg);
  2611. if (status)
  2612. return status;
  2613. status = hw->phy.ops.read_reg(hw, MDIO_AN_10GBT_CTRL,
  2614. MDIO_MMD_AN,
  2615. &an_10g_cntl_reg);
  2616. if (status)
  2617. return status;
  2618. status = hw->phy.ops.read_reg(hw,
  2619. IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
  2620. MDIO_MMD_AN,
  2621. &autoneg_reg);
  2622. if (status)
  2623. return status;
  2624. save_autoneg = hw->phy.autoneg_advertised;
  2625. /* Setup link at least common link speed */
  2626. status = hw->mac.ops.setup_link(hw, lcd_speed, false);
  2627. /* restore autoneg from before setting lplu speed */
  2628. hw->phy.autoneg_advertised = save_autoneg;
  2629. return status;
  2630. }
  2631. /**
  2632. * ixgbe_reset_phy_fw - Reset firmware-controlled PHYs
  2633. * @hw: pointer to hardware structure
  2634. */
  2635. static s32 ixgbe_reset_phy_fw(struct ixgbe_hw *hw)
  2636. {
  2637. u32 store[FW_PHY_ACT_DATA_COUNT] = { 0 };
  2638. s32 rc;
  2639. if (hw->phy.reset_disable || ixgbe_check_reset_blocked(hw))
  2640. return 0;
  2641. rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_PHY_SW_RESET, &store);
  2642. if (rc)
  2643. return rc;
  2644. memset(store, 0, sizeof(store));
  2645. rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_INIT_PHY, &store);
  2646. if (rc)
  2647. return rc;
  2648. return ixgbe_setup_fw_link(hw);
  2649. }
  2650. /**
  2651. * ixgbe_check_overtemp_fw - Check firmware-controlled PHYs for overtemp
  2652. * @hw: pointer to hardware structure
  2653. */
  2654. static s32 ixgbe_check_overtemp_fw(struct ixgbe_hw *hw)
  2655. {
  2656. u32 store[FW_PHY_ACT_DATA_COUNT] = { 0 };
  2657. s32 rc;
  2658. rc = ixgbe_fw_phy_activity(hw, FW_PHY_ACT_GET_LINK_INFO, &store);
  2659. if (rc)
  2660. return rc;
  2661. if (store[0] & FW_PHY_ACT_GET_LINK_INFO_TEMP) {
  2662. ixgbe_shutdown_fw_phy(hw);
  2663. return IXGBE_ERR_OVERTEMP;
  2664. }
  2665. return 0;
  2666. }
  2667. /**
  2668. * ixgbe_read_mng_if_sel_x550em - Read NW_MNG_IF_SEL register
  2669. * @hw: pointer to hardware structure
  2670. *
  2671. * Read NW_MNG_IF_SEL register and save field values.
  2672. */
  2673. static void ixgbe_read_mng_if_sel_x550em(struct ixgbe_hw *hw)
  2674. {
  2675. /* Save NW management interface connected on board. This is used
  2676. * to determine internal PHY mode.
  2677. */
  2678. hw->phy.nw_mng_if_sel = IXGBE_READ_REG(hw, IXGBE_NW_MNG_IF_SEL);
  2679. /* If X552 (X550EM_a) and MDIO is connected to external PHY, then set
  2680. * PHY address. This register field was has only been used for X552.
  2681. */
  2682. if (hw->mac.type == ixgbe_mac_x550em_a &&
  2683. hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_MDIO_ACT) {
  2684. hw->phy.mdio.prtad = (hw->phy.nw_mng_if_sel &
  2685. IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD) >>
  2686. IXGBE_NW_MNG_IF_SEL_MDIO_PHY_ADD_SHIFT;
  2687. }
  2688. }
  2689. /** ixgbe_init_phy_ops_X550em - PHY/SFP specific init
  2690. * @hw: pointer to hardware structure
  2691. *
  2692. * Initialize any function pointers that were not able to be
  2693. * set during init_shared_code because the PHY/SFP type was
  2694. * not known. Perform the SFP init if necessary.
  2695. **/
  2696. static s32 ixgbe_init_phy_ops_X550em(struct ixgbe_hw *hw)
  2697. {
  2698. struct ixgbe_phy_info *phy = &hw->phy;
  2699. s32 ret_val;
  2700. hw->mac.ops.set_lan_id(hw);
  2701. ixgbe_read_mng_if_sel_x550em(hw);
  2702. if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) {
  2703. phy->phy_semaphore_mask = IXGBE_GSSR_SHARED_I2C_SM;
  2704. ixgbe_setup_mux_ctl(hw);
  2705. }
  2706. /* Identify the PHY or SFP module */
  2707. ret_val = phy->ops.identify(hw);
  2708. /* Setup function pointers based on detected hardware */
  2709. ixgbe_init_mac_link_ops_X550em(hw);
  2710. if (phy->sfp_type != ixgbe_sfp_type_unknown)
  2711. phy->ops.reset = NULL;
  2712. /* Set functions pointers based on phy type */
  2713. switch (hw->phy.type) {
  2714. case ixgbe_phy_x550em_kx4:
  2715. phy->ops.setup_link = NULL;
  2716. phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
  2717. phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
  2718. break;
  2719. case ixgbe_phy_x550em_kr:
  2720. phy->ops.setup_link = ixgbe_setup_kr_x550em;
  2721. phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
  2722. phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
  2723. break;
  2724. case ixgbe_phy_x550em_xfi:
  2725. /* link is managed by HW */
  2726. phy->ops.setup_link = NULL;
  2727. phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
  2728. phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
  2729. break;
  2730. case ixgbe_phy_x550em_ext_t:
  2731. /* Save NW management interface connected on board. This is used
  2732. * to determine internal PHY mode
  2733. */
  2734. phy->nw_mng_if_sel = IXGBE_READ_REG(hw, IXGBE_NW_MNG_IF_SEL);
  2735. /* If internal link mode is XFI, then setup iXFI internal link,
  2736. * else setup KR now.
  2737. */
  2738. phy->ops.setup_internal_link =
  2739. ixgbe_setup_internal_phy_t_x550em;
  2740. /* setup SW LPLU only for first revision */
  2741. if (hw->mac.type == ixgbe_mac_X550EM_x &&
  2742. !(IXGBE_READ_REG(hw, IXGBE_FUSES0_GROUP(0)) &
  2743. IXGBE_FUSES0_REV_MASK))
  2744. phy->ops.enter_lplu = ixgbe_enter_lplu_t_x550em;
  2745. phy->ops.handle_lasi = ixgbe_handle_lasi_ext_t_x550em;
  2746. phy->ops.reset = ixgbe_reset_phy_t_X550em;
  2747. break;
  2748. case ixgbe_phy_sgmii:
  2749. phy->ops.setup_link = NULL;
  2750. break;
  2751. case ixgbe_phy_fw:
  2752. phy->ops.setup_link = ixgbe_setup_fw_link;
  2753. phy->ops.reset = ixgbe_reset_phy_fw;
  2754. break;
  2755. case ixgbe_phy_ext_1g_t:
  2756. phy->ops.setup_link = NULL;
  2757. phy->ops.read_reg = NULL;
  2758. phy->ops.write_reg = NULL;
  2759. break;
  2760. default:
  2761. break;
  2762. }
  2763. return ret_val;
  2764. }
  2765. /** ixgbe_get_media_type_X550em - Get media type
  2766. * @hw: pointer to hardware structure
  2767. *
  2768. * Returns the media type (fiber, copper, backplane)
  2769. *
  2770. */
  2771. static enum ixgbe_media_type ixgbe_get_media_type_X550em(struct ixgbe_hw *hw)
  2772. {
  2773. enum ixgbe_media_type media_type;
  2774. /* Detect if there is a copper PHY attached. */
  2775. switch (hw->device_id) {
  2776. case IXGBE_DEV_ID_X550EM_A_SGMII:
  2777. case IXGBE_DEV_ID_X550EM_A_SGMII_L:
  2778. hw->phy.type = ixgbe_phy_sgmii;
  2779. /* Fallthrough */
  2780. case IXGBE_DEV_ID_X550EM_X_KR:
  2781. case IXGBE_DEV_ID_X550EM_X_KX4:
  2782. case IXGBE_DEV_ID_X550EM_X_XFI:
  2783. case IXGBE_DEV_ID_X550EM_A_KR:
  2784. case IXGBE_DEV_ID_X550EM_A_KR_L:
  2785. media_type = ixgbe_media_type_backplane;
  2786. break;
  2787. case IXGBE_DEV_ID_X550EM_X_SFP:
  2788. case IXGBE_DEV_ID_X550EM_A_SFP:
  2789. case IXGBE_DEV_ID_X550EM_A_SFP_N:
  2790. media_type = ixgbe_media_type_fiber;
  2791. break;
  2792. case IXGBE_DEV_ID_X550EM_X_1G_T:
  2793. case IXGBE_DEV_ID_X550EM_X_10G_T:
  2794. case IXGBE_DEV_ID_X550EM_A_10G_T:
  2795. case IXGBE_DEV_ID_X550EM_A_1G_T:
  2796. case IXGBE_DEV_ID_X550EM_A_1G_T_L:
  2797. media_type = ixgbe_media_type_copper;
  2798. break;
  2799. default:
  2800. media_type = ixgbe_media_type_unknown;
  2801. break;
  2802. }
  2803. return media_type;
  2804. }
  2805. /** ixgbe_init_ext_t_x550em - Start (unstall) the external Base T PHY.
  2806. ** @hw: pointer to hardware structure
  2807. **/
  2808. static s32 ixgbe_init_ext_t_x550em(struct ixgbe_hw *hw)
  2809. {
  2810. s32 status;
  2811. u16 reg;
  2812. status = hw->phy.ops.read_reg(hw,
  2813. IXGBE_MDIO_TX_VENDOR_ALARMS_3,
  2814. MDIO_MMD_PMAPMD,
  2815. &reg);
  2816. if (status)
  2817. return status;
  2818. /* If PHY FW reset completed bit is set then this is the first
  2819. * SW instance after a power on so the PHY FW must be un-stalled.
  2820. */
  2821. if (reg & IXGBE_MDIO_TX_VENDOR_ALARMS_3_RST_MASK) {
  2822. status = hw->phy.ops.read_reg(hw,
  2823. IXGBE_MDIO_GLOBAL_RES_PR_10,
  2824. MDIO_MMD_VEND1,
  2825. &reg);
  2826. if (status)
  2827. return status;
  2828. reg &= ~IXGBE_MDIO_POWER_UP_STALL;
  2829. status = hw->phy.ops.write_reg(hw,
  2830. IXGBE_MDIO_GLOBAL_RES_PR_10,
  2831. MDIO_MMD_VEND1,
  2832. reg);
  2833. if (status)
  2834. return status;
  2835. }
  2836. return status;
  2837. }
  2838. /**
  2839. * ixgbe_set_mdio_speed - Set MDIO clock speed
  2840. * @hw: pointer to hardware structure
  2841. */
  2842. static void ixgbe_set_mdio_speed(struct ixgbe_hw *hw)
  2843. {
  2844. u32 hlreg0;
  2845. switch (hw->device_id) {
  2846. case IXGBE_DEV_ID_X550EM_X_10G_T:
  2847. case IXGBE_DEV_ID_X550EM_A_SGMII:
  2848. case IXGBE_DEV_ID_X550EM_A_SGMII_L:
  2849. case IXGBE_DEV_ID_X550EM_A_10G_T:
  2850. case IXGBE_DEV_ID_X550EM_A_SFP:
  2851. /* Config MDIO clock speed before the first MDIO PHY access */
  2852. hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
  2853. hlreg0 &= ~IXGBE_HLREG0_MDCSPD;
  2854. IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
  2855. break;
  2856. case IXGBE_DEV_ID_X550EM_A_1G_T:
  2857. case IXGBE_DEV_ID_X550EM_A_1G_T_L:
  2858. /* Select fast MDIO clock speed for these devices */
  2859. hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
  2860. hlreg0 |= IXGBE_HLREG0_MDCSPD;
  2861. IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
  2862. break;
  2863. default:
  2864. break;
  2865. }
  2866. }
  2867. /** ixgbe_reset_hw_X550em - Perform hardware reset
  2868. ** @hw: pointer to hardware structure
  2869. **
  2870. ** Resets the hardware by resetting the transmit and receive units, masks
  2871. ** and clears all interrupts, perform a PHY reset, and perform a link (MAC)
  2872. ** reset.
  2873. **/
  2874. static s32 ixgbe_reset_hw_X550em(struct ixgbe_hw *hw)
  2875. {
  2876. ixgbe_link_speed link_speed;
  2877. s32 status;
  2878. u32 ctrl = 0;
  2879. u32 i;
  2880. bool link_up = false;
  2881. u32 swfw_mask = hw->phy.phy_semaphore_mask;
  2882. /* Call adapter stop to disable Tx/Rx and clear interrupts */
  2883. status = hw->mac.ops.stop_adapter(hw);
  2884. if (status)
  2885. return status;
  2886. /* flush pending Tx transactions */
  2887. ixgbe_clear_tx_pending(hw);
  2888. /* PHY ops must be identified and initialized prior to reset */
  2889. /* Identify PHY and related function pointers */
  2890. status = hw->phy.ops.init(hw);
  2891. /* start the external PHY */
  2892. if (hw->phy.type == ixgbe_phy_x550em_ext_t) {
  2893. status = ixgbe_init_ext_t_x550em(hw);
  2894. if (status)
  2895. return status;
  2896. }
  2897. /* Setup SFP module if there is one present. */
  2898. if (hw->phy.sfp_setup_needed) {
  2899. status = hw->mac.ops.setup_sfp(hw);
  2900. hw->phy.sfp_setup_needed = false;
  2901. }
  2902. /* Reset PHY */
  2903. if (!hw->phy.reset_disable && hw->phy.ops.reset)
  2904. hw->phy.ops.reset(hw);
  2905. mac_reset_top:
  2906. /* Issue global reset to the MAC. Needs to be SW reset if link is up.
  2907. * If link reset is used when link is up, it might reset the PHY when
  2908. * mng is using it. If link is down or the flag to force full link
  2909. * reset is set, then perform link reset.
  2910. */
  2911. ctrl = IXGBE_CTRL_LNK_RST;
  2912. if (!hw->force_full_reset) {
  2913. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  2914. if (link_up)
  2915. ctrl = IXGBE_CTRL_RST;
  2916. }
  2917. status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
  2918. if (status) {
  2919. hw_dbg(hw, "semaphore failed with %d", status);
  2920. return IXGBE_ERR_SWFW_SYNC;
  2921. }
  2922. ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL);
  2923. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  2924. IXGBE_WRITE_FLUSH(hw);
  2925. hw->mac.ops.release_swfw_sync(hw, swfw_mask);
  2926. usleep_range(1000, 1200);
  2927. /* Poll for reset bit to self-clear meaning reset is complete */
  2928. for (i = 0; i < 10; i++) {
  2929. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  2930. if (!(ctrl & IXGBE_CTRL_RST_MASK))
  2931. break;
  2932. udelay(1);
  2933. }
  2934. if (ctrl & IXGBE_CTRL_RST_MASK) {
  2935. status = IXGBE_ERR_RESET_FAILED;
  2936. hw_dbg(hw, "Reset polling failed to complete.\n");
  2937. }
  2938. msleep(50);
  2939. /* Double resets are required for recovery from certain error
  2940. * clear the multicast table. Also reset num_rar_entries to 128,
  2941. * since we modify this value when programming the SAN MAC address.
  2942. */
  2943. if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
  2944. hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
  2945. goto mac_reset_top;
  2946. }
  2947. /* Store the permanent mac address */
  2948. hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
  2949. /* Store MAC address from RAR0, clear receive address registers, and
  2950. * clear the multicast table. Also reset num_rar_entries to 128,
  2951. * since we modify this value when programming the SAN MAC address.
  2952. */
  2953. hw->mac.num_rar_entries = 128;
  2954. hw->mac.ops.init_rx_addrs(hw);
  2955. ixgbe_set_mdio_speed(hw);
  2956. if (hw->device_id == IXGBE_DEV_ID_X550EM_X_SFP)
  2957. ixgbe_setup_mux_ctl(hw);
  2958. return status;
  2959. }
  2960. /** ixgbe_set_ethertype_anti_spoofing_X550 - Enable/Disable Ethertype
  2961. * anti-spoofing
  2962. * @hw: pointer to hardware structure
  2963. * @enable: enable or disable switch for Ethertype anti-spoofing
  2964. * @vf: Virtual Function pool - VF Pool to set for Ethertype anti-spoofing
  2965. **/
  2966. static void ixgbe_set_ethertype_anti_spoofing_X550(struct ixgbe_hw *hw,
  2967. bool enable, int vf)
  2968. {
  2969. int vf_target_reg = vf >> 3;
  2970. int vf_target_shift = vf % 8 + IXGBE_SPOOF_ETHERTYPEAS_SHIFT;
  2971. u32 pfvfspoof;
  2972. pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
  2973. if (enable)
  2974. pfvfspoof |= BIT(vf_target_shift);
  2975. else
  2976. pfvfspoof &= ~BIT(vf_target_shift);
  2977. IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
  2978. }
  2979. /** ixgbe_set_source_address_pruning_X550 - Enable/Disbale src address pruning
  2980. * @hw: pointer to hardware structure
  2981. * @enable: enable or disable source address pruning
  2982. * @pool: Rx pool to set source address pruning for
  2983. **/
  2984. static void ixgbe_set_source_address_pruning_X550(struct ixgbe_hw *hw,
  2985. bool enable,
  2986. unsigned int pool)
  2987. {
  2988. u64 pfflp;
  2989. /* max rx pool is 63 */
  2990. if (pool > 63)
  2991. return;
  2992. pfflp = (u64)IXGBE_READ_REG(hw, IXGBE_PFFLPL);
  2993. pfflp |= (u64)IXGBE_READ_REG(hw, IXGBE_PFFLPH) << 32;
  2994. if (enable)
  2995. pfflp |= (1ULL << pool);
  2996. else
  2997. pfflp &= ~(1ULL << pool);
  2998. IXGBE_WRITE_REG(hw, IXGBE_PFFLPL, (u32)pfflp);
  2999. IXGBE_WRITE_REG(hw, IXGBE_PFFLPH, (u32)(pfflp >> 32));
  3000. }
  3001. /**
  3002. * ixgbe_setup_fc_backplane_x550em_a - Set up flow control
  3003. * @hw: pointer to hardware structure
  3004. *
  3005. * Called at init time to set up flow control.
  3006. **/
  3007. static s32 ixgbe_setup_fc_backplane_x550em_a(struct ixgbe_hw *hw)
  3008. {
  3009. s32 status = 0;
  3010. u32 an_cntl = 0;
  3011. /* Validate the requested mode */
  3012. if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
  3013. hw_err(hw, "ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
  3014. return IXGBE_ERR_INVALID_LINK_SETTINGS;
  3015. }
  3016. if (hw->fc.requested_mode == ixgbe_fc_default)
  3017. hw->fc.requested_mode = ixgbe_fc_full;
  3018. /* Set up the 1G and 10G flow control advertisement registers so the
  3019. * HW will be able to do FC autoneg once the cable is plugged in. If
  3020. * we link at 10G, the 1G advertisement is harmless and vice versa.
  3021. */
  3022. status = hw->mac.ops.read_iosf_sb_reg(hw,
  3023. IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
  3024. IXGBE_SB_IOSF_TARGET_KR_PHY, &an_cntl);
  3025. if (status) {
  3026. hw_dbg(hw, "Auto-Negotiation did not complete\n");
  3027. return status;
  3028. }
  3029. /* The possible values of fc.requested_mode are:
  3030. * 0: Flow control is completely disabled
  3031. * 1: Rx flow control is enabled (we can receive pause frames,
  3032. * but not send pause frames).
  3033. * 2: Tx flow control is enabled (we can send pause frames but
  3034. * we do not support receiving pause frames).
  3035. * 3: Both Rx and Tx flow control (symmetric) are enabled.
  3036. * other: Invalid.
  3037. */
  3038. switch (hw->fc.requested_mode) {
  3039. case ixgbe_fc_none:
  3040. /* Flow control completely disabled by software override. */
  3041. an_cntl &= ~(IXGBE_KRM_AN_CNTL_1_SYM_PAUSE |
  3042. IXGBE_KRM_AN_CNTL_1_ASM_PAUSE);
  3043. break;
  3044. case ixgbe_fc_tx_pause:
  3045. /* Tx Flow control is enabled, and Rx Flow control is
  3046. * disabled by software override.
  3047. */
  3048. an_cntl |= IXGBE_KRM_AN_CNTL_1_ASM_PAUSE;
  3049. an_cntl &= ~IXGBE_KRM_AN_CNTL_1_SYM_PAUSE;
  3050. break;
  3051. case ixgbe_fc_rx_pause:
  3052. /* Rx Flow control is enabled and Tx Flow control is
  3053. * disabled by software override. Since there really
  3054. * isn't a way to advertise that we are capable of RX
  3055. * Pause ONLY, we will advertise that we support both
  3056. * symmetric and asymmetric Rx PAUSE, as such we fall
  3057. * through to the fc_full statement. Later, we will
  3058. * disable the adapter's ability to send PAUSE frames.
  3059. */
  3060. case ixgbe_fc_full:
  3061. /* Flow control (both Rx and Tx) is enabled by SW override. */
  3062. an_cntl |= IXGBE_KRM_AN_CNTL_1_SYM_PAUSE |
  3063. IXGBE_KRM_AN_CNTL_1_ASM_PAUSE;
  3064. break;
  3065. default:
  3066. hw_err(hw, "Flow control param set incorrectly\n");
  3067. return IXGBE_ERR_CONFIG;
  3068. }
  3069. status = hw->mac.ops.write_iosf_sb_reg(hw,
  3070. IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
  3071. IXGBE_SB_IOSF_TARGET_KR_PHY, an_cntl);
  3072. /* Restart auto-negotiation. */
  3073. status = ixgbe_restart_an_internal_phy_x550em(hw);
  3074. return status;
  3075. }
  3076. /**
  3077. * ixgbe_set_mux - Set mux for port 1 access with CS4227
  3078. * @hw: pointer to hardware structure
  3079. * @state: set mux if 1, clear if 0
  3080. */
  3081. static void ixgbe_set_mux(struct ixgbe_hw *hw, u8 state)
  3082. {
  3083. u32 esdp;
  3084. if (!hw->bus.lan_id)
  3085. return;
  3086. esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  3087. if (state)
  3088. esdp |= IXGBE_ESDP_SDP1;
  3089. else
  3090. esdp &= ~IXGBE_ESDP_SDP1;
  3091. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
  3092. IXGBE_WRITE_FLUSH(hw);
  3093. }
  3094. /**
  3095. * ixgbe_acquire_swfw_sync_X550em - Acquire SWFW semaphore
  3096. * @hw: pointer to hardware structure
  3097. * @mask: Mask to specify which semaphore to acquire
  3098. *
  3099. * Acquires the SWFW semaphore and sets the I2C MUX
  3100. */
  3101. static s32 ixgbe_acquire_swfw_sync_X550em(struct ixgbe_hw *hw, u32 mask)
  3102. {
  3103. s32 status;
  3104. status = ixgbe_acquire_swfw_sync_X540(hw, mask);
  3105. if (status)
  3106. return status;
  3107. if (mask & IXGBE_GSSR_I2C_MASK)
  3108. ixgbe_set_mux(hw, 1);
  3109. return 0;
  3110. }
  3111. /**
  3112. * ixgbe_release_swfw_sync_X550em - Release SWFW semaphore
  3113. * @hw: pointer to hardware structure
  3114. * @mask: Mask to specify which semaphore to release
  3115. *
  3116. * Releases the SWFW semaphore and sets the I2C MUX
  3117. */
  3118. static void ixgbe_release_swfw_sync_X550em(struct ixgbe_hw *hw, u32 mask)
  3119. {
  3120. if (mask & IXGBE_GSSR_I2C_MASK)
  3121. ixgbe_set_mux(hw, 0);
  3122. ixgbe_release_swfw_sync_X540(hw, mask);
  3123. }
  3124. /**
  3125. * ixgbe_acquire_swfw_sync_x550em_a - Acquire SWFW semaphore
  3126. * @hw: pointer to hardware structure
  3127. * @mask: Mask to specify which semaphore to acquire
  3128. *
  3129. * Acquires the SWFW semaphore and get the shared PHY token as needed
  3130. */
  3131. static s32 ixgbe_acquire_swfw_sync_x550em_a(struct ixgbe_hw *hw, u32 mask)
  3132. {
  3133. u32 hmask = mask & ~IXGBE_GSSR_TOKEN_SM;
  3134. int retries = FW_PHY_TOKEN_RETRIES;
  3135. s32 status;
  3136. while (--retries) {
  3137. status = 0;
  3138. if (hmask)
  3139. status = ixgbe_acquire_swfw_sync_X540(hw, hmask);
  3140. if (status)
  3141. return status;
  3142. if (!(mask & IXGBE_GSSR_TOKEN_SM))
  3143. return 0;
  3144. status = ixgbe_get_phy_token(hw);
  3145. if (!status)
  3146. return 0;
  3147. if (hmask)
  3148. ixgbe_release_swfw_sync_X540(hw, hmask);
  3149. if (status != IXGBE_ERR_TOKEN_RETRY)
  3150. return status;
  3151. msleep(FW_PHY_TOKEN_DELAY);
  3152. }
  3153. return status;
  3154. }
  3155. /**
  3156. * ixgbe_release_swfw_sync_x550em_a - Release SWFW semaphore
  3157. * @hw: pointer to hardware structure
  3158. * @mask: Mask to specify which semaphore to release
  3159. *
  3160. * Release the SWFW semaphore and puts the shared PHY token as needed
  3161. */
  3162. static void ixgbe_release_swfw_sync_x550em_a(struct ixgbe_hw *hw, u32 mask)
  3163. {
  3164. u32 hmask = mask & ~IXGBE_GSSR_TOKEN_SM;
  3165. if (mask & IXGBE_GSSR_TOKEN_SM)
  3166. ixgbe_put_phy_token(hw);
  3167. if (hmask)
  3168. ixgbe_release_swfw_sync_X540(hw, hmask);
  3169. }
  3170. /**
  3171. * ixgbe_read_phy_reg_x550a - Reads specified PHY register
  3172. * @hw: pointer to hardware structure
  3173. * @reg_addr: 32 bit address of PHY register to read
  3174. * @phy_data: Pointer to read data from PHY register
  3175. *
  3176. * Reads a value from a specified PHY register using the SWFW lock and PHY
  3177. * Token. The PHY Token is needed since the MDIO is shared between to MAC
  3178. * instances.
  3179. */
  3180. static s32 ixgbe_read_phy_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
  3181. u32 device_type, u16 *phy_data)
  3182. {
  3183. u32 mask = hw->phy.phy_semaphore_mask | IXGBE_GSSR_TOKEN_SM;
  3184. s32 status;
  3185. if (hw->mac.ops.acquire_swfw_sync(hw, mask))
  3186. return IXGBE_ERR_SWFW_SYNC;
  3187. status = hw->phy.ops.read_reg_mdi(hw, reg_addr, device_type, phy_data);
  3188. hw->mac.ops.release_swfw_sync(hw, mask);
  3189. return status;
  3190. }
  3191. /**
  3192. * ixgbe_write_phy_reg_x550a - Writes specified PHY register
  3193. * @hw: pointer to hardware structure
  3194. * @reg_addr: 32 bit PHY register to write
  3195. * @device_type: 5 bit device type
  3196. * @phy_data: Data to write to the PHY register
  3197. *
  3198. * Writes a value to specified PHY register using the SWFW lock and PHY Token.
  3199. * The PHY Token is needed since the MDIO is shared between to MAC instances.
  3200. */
  3201. static s32 ixgbe_write_phy_reg_x550a(struct ixgbe_hw *hw, u32 reg_addr,
  3202. u32 device_type, u16 phy_data)
  3203. {
  3204. u32 mask = hw->phy.phy_semaphore_mask | IXGBE_GSSR_TOKEN_SM;
  3205. s32 status;
  3206. if (hw->mac.ops.acquire_swfw_sync(hw, mask))
  3207. return IXGBE_ERR_SWFW_SYNC;
  3208. status = ixgbe_write_phy_reg_mdi(hw, reg_addr, device_type, phy_data);
  3209. hw->mac.ops.release_swfw_sync(hw, mask);
  3210. return status;
  3211. }
  3212. #define X550_COMMON_MAC \
  3213. .init_hw = &ixgbe_init_hw_generic, \
  3214. .start_hw = &ixgbe_start_hw_X540, \
  3215. .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic, \
  3216. .enable_rx_dma = &ixgbe_enable_rx_dma_generic, \
  3217. .get_mac_addr = &ixgbe_get_mac_addr_generic, \
  3218. .get_device_caps = &ixgbe_get_device_caps_generic, \
  3219. .stop_adapter = &ixgbe_stop_adapter_generic, \
  3220. .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie, \
  3221. .read_analog_reg8 = NULL, \
  3222. .write_analog_reg8 = NULL, \
  3223. .set_rxpba = &ixgbe_set_rxpba_generic, \
  3224. .check_link = &ixgbe_check_mac_link_generic, \
  3225. .blink_led_start = &ixgbe_blink_led_start_X540, \
  3226. .blink_led_stop = &ixgbe_blink_led_stop_X540, \
  3227. .set_rar = &ixgbe_set_rar_generic, \
  3228. .clear_rar = &ixgbe_clear_rar_generic, \
  3229. .set_vmdq = &ixgbe_set_vmdq_generic, \
  3230. .set_vmdq_san_mac = &ixgbe_set_vmdq_san_mac_generic, \
  3231. .clear_vmdq = &ixgbe_clear_vmdq_generic, \
  3232. .init_rx_addrs = &ixgbe_init_rx_addrs_generic, \
  3233. .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic, \
  3234. .enable_mc = &ixgbe_enable_mc_generic, \
  3235. .disable_mc = &ixgbe_disable_mc_generic, \
  3236. .clear_vfta = &ixgbe_clear_vfta_generic, \
  3237. .set_vfta = &ixgbe_set_vfta_generic, \
  3238. .fc_enable = &ixgbe_fc_enable_generic, \
  3239. .set_fw_drv_ver = &ixgbe_set_fw_drv_ver_x550, \
  3240. .init_uta_tables = &ixgbe_init_uta_tables_generic, \
  3241. .set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing, \
  3242. .set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing, \
  3243. .set_source_address_pruning = \
  3244. &ixgbe_set_source_address_pruning_X550, \
  3245. .set_ethertype_anti_spoofing = \
  3246. &ixgbe_set_ethertype_anti_spoofing_X550, \
  3247. .disable_rx_buff = &ixgbe_disable_rx_buff_generic, \
  3248. .enable_rx_buff = &ixgbe_enable_rx_buff_generic, \
  3249. .get_thermal_sensor_data = NULL, \
  3250. .init_thermal_sensor_thresh = NULL, \
  3251. .enable_rx = &ixgbe_enable_rx_generic, \
  3252. .disable_rx = &ixgbe_disable_rx_x550, \
  3253. static const struct ixgbe_mac_operations mac_ops_X550 = {
  3254. X550_COMMON_MAC
  3255. .led_on = ixgbe_led_on_generic,
  3256. .led_off = ixgbe_led_off_generic,
  3257. .init_led_link_act = ixgbe_init_led_link_act_generic,
  3258. .reset_hw = &ixgbe_reset_hw_X540,
  3259. .get_media_type = &ixgbe_get_media_type_X540,
  3260. .get_san_mac_addr = &ixgbe_get_san_mac_addr_generic,
  3261. .get_wwn_prefix = &ixgbe_get_wwn_prefix_generic,
  3262. .setup_link = &ixgbe_setup_mac_link_X540,
  3263. .get_link_capabilities = &ixgbe_get_copper_link_capabilities_generic,
  3264. .get_bus_info = &ixgbe_get_bus_info_generic,
  3265. .setup_sfp = NULL,
  3266. .acquire_swfw_sync = &ixgbe_acquire_swfw_sync_X540,
  3267. .release_swfw_sync = &ixgbe_release_swfw_sync_X540,
  3268. .init_swfw_sync = &ixgbe_init_swfw_sync_X540,
  3269. .prot_autoc_read = prot_autoc_read_generic,
  3270. .prot_autoc_write = prot_autoc_write_generic,
  3271. .setup_fc = ixgbe_setup_fc_generic,
  3272. .fc_autoneg = ixgbe_fc_autoneg,
  3273. };
  3274. static const struct ixgbe_mac_operations mac_ops_X550EM_x = {
  3275. X550_COMMON_MAC
  3276. .led_on = ixgbe_led_on_t_x550em,
  3277. .led_off = ixgbe_led_off_t_x550em,
  3278. .init_led_link_act = ixgbe_init_led_link_act_generic,
  3279. .reset_hw = &ixgbe_reset_hw_X550em,
  3280. .get_media_type = &ixgbe_get_media_type_X550em,
  3281. .get_san_mac_addr = NULL,
  3282. .get_wwn_prefix = NULL,
  3283. .setup_link = &ixgbe_setup_mac_link_X540,
  3284. .get_link_capabilities = &ixgbe_get_link_capabilities_X550em,
  3285. .get_bus_info = &ixgbe_get_bus_info_X550em,
  3286. .setup_sfp = ixgbe_setup_sfp_modules_X550em,
  3287. .acquire_swfw_sync = &ixgbe_acquire_swfw_sync_X550em,
  3288. .release_swfw_sync = &ixgbe_release_swfw_sync_X550em,
  3289. .init_swfw_sync = &ixgbe_init_swfw_sync_X540,
  3290. .setup_fc = NULL, /* defined later */
  3291. .fc_autoneg = ixgbe_fc_autoneg,
  3292. .read_iosf_sb_reg = ixgbe_read_iosf_sb_reg_x550,
  3293. .write_iosf_sb_reg = ixgbe_write_iosf_sb_reg_x550,
  3294. };
  3295. static struct ixgbe_mac_operations mac_ops_x550em_a = {
  3296. X550_COMMON_MAC
  3297. .led_on = ixgbe_led_on_t_x550em,
  3298. .led_off = ixgbe_led_off_t_x550em,
  3299. .init_led_link_act = ixgbe_init_led_link_act_generic,
  3300. .reset_hw = ixgbe_reset_hw_X550em,
  3301. .get_media_type = ixgbe_get_media_type_X550em,
  3302. .get_san_mac_addr = NULL,
  3303. .get_wwn_prefix = NULL,
  3304. .setup_link = &ixgbe_setup_mac_link_X540,
  3305. .get_link_capabilities = ixgbe_get_link_capabilities_X550em,
  3306. .get_bus_info = ixgbe_get_bus_info_X550em,
  3307. .setup_sfp = ixgbe_setup_sfp_modules_X550em,
  3308. .acquire_swfw_sync = ixgbe_acquire_swfw_sync_x550em_a,
  3309. .release_swfw_sync = ixgbe_release_swfw_sync_x550em_a,
  3310. .setup_fc = ixgbe_setup_fc_x550em,
  3311. .fc_autoneg = ixgbe_fc_autoneg,
  3312. .read_iosf_sb_reg = ixgbe_read_iosf_sb_reg_x550a,
  3313. .write_iosf_sb_reg = ixgbe_write_iosf_sb_reg_x550a,
  3314. };
  3315. static struct ixgbe_mac_operations mac_ops_x550em_a_fw = {
  3316. X550_COMMON_MAC
  3317. .led_on = ixgbe_led_on_generic,
  3318. .led_off = ixgbe_led_off_generic,
  3319. .init_led_link_act = ixgbe_init_led_link_act_generic,
  3320. .reset_hw = ixgbe_reset_hw_X550em,
  3321. .get_media_type = ixgbe_get_media_type_X550em,
  3322. .get_san_mac_addr = NULL,
  3323. .get_wwn_prefix = NULL,
  3324. .setup_link = NULL, /* defined later */
  3325. .get_link_capabilities = ixgbe_get_link_capabilities_X550em,
  3326. .get_bus_info = ixgbe_get_bus_info_X550em,
  3327. .setup_sfp = ixgbe_setup_sfp_modules_X550em,
  3328. .acquire_swfw_sync = ixgbe_acquire_swfw_sync_x550em_a,
  3329. .release_swfw_sync = ixgbe_release_swfw_sync_x550em_a,
  3330. .setup_fc = ixgbe_setup_fc_x550em,
  3331. .fc_autoneg = ixgbe_fc_autoneg,
  3332. .read_iosf_sb_reg = ixgbe_read_iosf_sb_reg_x550a,
  3333. .write_iosf_sb_reg = ixgbe_write_iosf_sb_reg_x550a,
  3334. };
  3335. #define X550_COMMON_EEP \
  3336. .read = &ixgbe_read_ee_hostif_X550, \
  3337. .read_buffer = &ixgbe_read_ee_hostif_buffer_X550, \
  3338. .write = &ixgbe_write_ee_hostif_X550, \
  3339. .write_buffer = &ixgbe_write_ee_hostif_buffer_X550, \
  3340. .validate_checksum = &ixgbe_validate_eeprom_checksum_X550, \
  3341. .update_checksum = &ixgbe_update_eeprom_checksum_X550, \
  3342. .calc_checksum = &ixgbe_calc_eeprom_checksum_X550, \
  3343. static const struct ixgbe_eeprom_operations eeprom_ops_X550 = {
  3344. X550_COMMON_EEP
  3345. .init_params = &ixgbe_init_eeprom_params_X550,
  3346. };
  3347. static const struct ixgbe_eeprom_operations eeprom_ops_X550EM_x = {
  3348. X550_COMMON_EEP
  3349. .init_params = &ixgbe_init_eeprom_params_X540,
  3350. };
  3351. #define X550_COMMON_PHY \
  3352. .identify_sfp = &ixgbe_identify_module_generic, \
  3353. .reset = NULL, \
  3354. .setup_link_speed = &ixgbe_setup_phy_link_speed_generic, \
  3355. .read_i2c_byte = &ixgbe_read_i2c_byte_generic, \
  3356. .write_i2c_byte = &ixgbe_write_i2c_byte_generic, \
  3357. .read_i2c_sff8472 = &ixgbe_read_i2c_sff8472_generic, \
  3358. .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic, \
  3359. .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic, \
  3360. .setup_link = &ixgbe_setup_phy_link_generic, \
  3361. .set_phy_power = NULL,
  3362. static const struct ixgbe_phy_operations phy_ops_X550 = {
  3363. X550_COMMON_PHY
  3364. .check_overtemp = &ixgbe_tn_check_overtemp,
  3365. .init = NULL,
  3366. .identify = &ixgbe_identify_phy_generic,
  3367. .read_reg = &ixgbe_read_phy_reg_generic,
  3368. .write_reg = &ixgbe_write_phy_reg_generic,
  3369. };
  3370. static const struct ixgbe_phy_operations phy_ops_X550EM_x = {
  3371. X550_COMMON_PHY
  3372. .check_overtemp = &ixgbe_tn_check_overtemp,
  3373. .init = &ixgbe_init_phy_ops_X550em,
  3374. .identify = &ixgbe_identify_phy_x550em,
  3375. .read_reg = &ixgbe_read_phy_reg_generic,
  3376. .write_reg = &ixgbe_write_phy_reg_generic,
  3377. };
  3378. static const struct ixgbe_phy_operations phy_ops_x550em_x_fw = {
  3379. X550_COMMON_PHY
  3380. .check_overtemp = NULL,
  3381. .init = ixgbe_init_phy_ops_X550em,
  3382. .identify = ixgbe_identify_phy_x550em,
  3383. .read_reg = NULL,
  3384. .write_reg = NULL,
  3385. .read_reg_mdi = NULL,
  3386. .write_reg_mdi = NULL,
  3387. };
  3388. static const struct ixgbe_phy_operations phy_ops_x550em_a = {
  3389. X550_COMMON_PHY
  3390. .check_overtemp = &ixgbe_tn_check_overtemp,
  3391. .init = &ixgbe_init_phy_ops_X550em,
  3392. .identify = &ixgbe_identify_phy_x550em,
  3393. .read_reg = &ixgbe_read_phy_reg_x550a,
  3394. .write_reg = &ixgbe_write_phy_reg_x550a,
  3395. .read_reg_mdi = &ixgbe_read_phy_reg_mdi,
  3396. .write_reg_mdi = &ixgbe_write_phy_reg_mdi,
  3397. };
  3398. static const struct ixgbe_phy_operations phy_ops_x550em_a_fw = {
  3399. X550_COMMON_PHY
  3400. .check_overtemp = ixgbe_check_overtemp_fw,
  3401. .init = ixgbe_init_phy_ops_X550em,
  3402. .identify = ixgbe_identify_phy_fw,
  3403. .read_reg = NULL,
  3404. .write_reg = NULL,
  3405. .read_reg_mdi = NULL,
  3406. .write_reg_mdi = NULL,
  3407. };
  3408. static const struct ixgbe_link_operations link_ops_x550em_x = {
  3409. .read_link = &ixgbe_read_i2c_combined_generic,
  3410. .read_link_unlocked = &ixgbe_read_i2c_combined_generic_unlocked,
  3411. .write_link = &ixgbe_write_i2c_combined_generic,
  3412. .write_link_unlocked = &ixgbe_write_i2c_combined_generic_unlocked,
  3413. };
  3414. static const u32 ixgbe_mvals_X550[IXGBE_MVALS_IDX_LIMIT] = {
  3415. IXGBE_MVALS_INIT(X550)
  3416. };
  3417. static const u32 ixgbe_mvals_X550EM_x[IXGBE_MVALS_IDX_LIMIT] = {
  3418. IXGBE_MVALS_INIT(X550EM_x)
  3419. };
  3420. static const u32 ixgbe_mvals_x550em_a[IXGBE_MVALS_IDX_LIMIT] = {
  3421. IXGBE_MVALS_INIT(X550EM_a)
  3422. };
  3423. const struct ixgbe_info ixgbe_X550_info = {
  3424. .mac = ixgbe_mac_X550,
  3425. .get_invariants = &ixgbe_get_invariants_X540,
  3426. .mac_ops = &mac_ops_X550,
  3427. .eeprom_ops = &eeprom_ops_X550,
  3428. .phy_ops = &phy_ops_X550,
  3429. .mbx_ops = &mbx_ops_generic,
  3430. .mvals = ixgbe_mvals_X550,
  3431. };
  3432. const struct ixgbe_info ixgbe_X550EM_x_info = {
  3433. .mac = ixgbe_mac_X550EM_x,
  3434. .get_invariants = &ixgbe_get_invariants_X550_x,
  3435. .mac_ops = &mac_ops_X550EM_x,
  3436. .eeprom_ops = &eeprom_ops_X550EM_x,
  3437. .phy_ops = &phy_ops_X550EM_x,
  3438. .mbx_ops = &mbx_ops_generic,
  3439. .mvals = ixgbe_mvals_X550EM_x,
  3440. .link_ops = &link_ops_x550em_x,
  3441. };
  3442. const struct ixgbe_info ixgbe_x550em_x_fw_info = {
  3443. .mac = ixgbe_mac_X550EM_x,
  3444. .get_invariants = ixgbe_get_invariants_X550_x_fw,
  3445. .mac_ops = &mac_ops_X550EM_x,
  3446. .eeprom_ops = &eeprom_ops_X550EM_x,
  3447. .phy_ops = &phy_ops_x550em_x_fw,
  3448. .mbx_ops = &mbx_ops_generic,
  3449. .mvals = ixgbe_mvals_X550EM_x,
  3450. };
  3451. const struct ixgbe_info ixgbe_x550em_a_info = {
  3452. .mac = ixgbe_mac_x550em_a,
  3453. .get_invariants = &ixgbe_get_invariants_X550_a,
  3454. .mac_ops = &mac_ops_x550em_a,
  3455. .eeprom_ops = &eeprom_ops_X550EM_x,
  3456. .phy_ops = &phy_ops_x550em_a,
  3457. .mbx_ops = &mbx_ops_generic,
  3458. .mvals = ixgbe_mvals_x550em_a,
  3459. };
  3460. const struct ixgbe_info ixgbe_x550em_a_fw_info = {
  3461. .mac = ixgbe_mac_x550em_a,
  3462. .get_invariants = ixgbe_get_invariants_X550_a_fw,
  3463. .mac_ops = &mac_ops_x550em_a_fw,
  3464. .eeprom_ops = &eeprom_ops_X550EM_x,
  3465. .phy_ops = &phy_ops_x550em_a_fw,
  3466. .mbx_ops = &mbx_ops_generic,
  3467. .mvals = ixgbe_mvals_x550em_a,
  3468. };