ixgbe_x550.c 68 KB

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