ixgbe_x550.c 96 KB

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