ixgbe_x550.c 110 KB

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