ixgbe_x550.c 84 KB

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