ixgbe_x550.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432
  1. /*******************************************************************************
  2. *
  3. * Intel 10 Gigabit PCI Express Linux driver
  4. * Copyright(c) 1999 - 2014 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. /** ixgbe_identify_phy_x550em - Get PHY type based on device id
  29. * @hw: pointer to hardware structure
  30. *
  31. * Returns error code
  32. */
  33. static s32 ixgbe_identify_phy_x550em(struct ixgbe_hw *hw)
  34. {
  35. u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  36. switch (hw->device_id) {
  37. case IXGBE_DEV_ID_X550EM_X_SFP:
  38. /* set up for CS4227 usage */
  39. hw->phy.phy_semaphore_mask = IXGBE_GSSR_SHARED_I2C_SM;
  40. if (hw->bus.lan_id) {
  41. esdp &= ~(IXGBE_ESDP_SDP1_NATIVE | IXGBE_ESDP_SDP1);
  42. esdp |= IXGBE_ESDP_SDP1_DIR;
  43. }
  44. esdp &= ~(IXGBE_ESDP_SDP0_NATIVE | IXGBE_ESDP_SDP0_DIR);
  45. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
  46. return ixgbe_identify_module_generic(hw);
  47. case IXGBE_DEV_ID_X550EM_X_KX4:
  48. hw->phy.type = ixgbe_phy_x550em_kx4;
  49. break;
  50. case IXGBE_DEV_ID_X550EM_X_KR:
  51. hw->phy.type = ixgbe_phy_x550em_kr;
  52. break;
  53. case IXGBE_DEV_ID_X550EM_X_1G_T:
  54. case IXGBE_DEV_ID_X550EM_X_10G_T:
  55. return ixgbe_identify_phy_generic(hw);
  56. default:
  57. break;
  58. }
  59. return 0;
  60. }
  61. static s32 ixgbe_read_phy_reg_x550em(struct ixgbe_hw *hw, u32 reg_addr,
  62. u32 device_type, u16 *phy_data)
  63. {
  64. return IXGBE_NOT_IMPLEMENTED;
  65. }
  66. static s32 ixgbe_write_phy_reg_x550em(struct ixgbe_hw *hw, u32 reg_addr,
  67. u32 device_type, u16 phy_data)
  68. {
  69. return IXGBE_NOT_IMPLEMENTED;
  70. }
  71. /** ixgbe_init_eeprom_params_X550 - Initialize EEPROM params
  72. * @hw: pointer to hardware structure
  73. *
  74. * Initializes the EEPROM parameters ixgbe_eeprom_info within the
  75. * ixgbe_hw struct in order to set up EEPROM access.
  76. **/
  77. s32 ixgbe_init_eeprom_params_X550(struct ixgbe_hw *hw)
  78. {
  79. struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
  80. u32 eec;
  81. u16 eeprom_size;
  82. if (eeprom->type == ixgbe_eeprom_uninitialized) {
  83. eeprom->semaphore_delay = 10;
  84. eeprom->type = ixgbe_flash;
  85. eec = IXGBE_READ_REG(hw, IXGBE_EEC);
  86. eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
  87. IXGBE_EEC_SIZE_SHIFT);
  88. eeprom->word_size = 1 << (eeprom_size +
  89. IXGBE_EEPROM_WORD_SIZE_SHIFT);
  90. hw_dbg(hw, "Eeprom params: type = %d, size = %d\n",
  91. eeprom->type, eeprom->word_size);
  92. }
  93. return 0;
  94. }
  95. /** ixgbe_read_iosf_sb_reg_x550 - Writes a value to specified register of the
  96. * IOSF device
  97. * @hw: pointer to hardware structure
  98. * @reg_addr: 32 bit PHY register to write
  99. * @device_type: 3 bit device type
  100. * @phy_data: Pointer to read data from the register
  101. **/
  102. s32 ixgbe_read_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr,
  103. u32 device_type, u32 *data)
  104. {
  105. u32 i, command, error;
  106. command = ((reg_addr << IXGBE_SB_IOSF_CTRL_ADDR_SHIFT) |
  107. (device_type << IXGBE_SB_IOSF_CTRL_TARGET_SELECT_SHIFT));
  108. /* Write IOSF control register */
  109. IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL, command);
  110. /* Check every 10 usec to see if the address cycle completed.
  111. * The SB IOSF BUSY bit will clear when the operation is
  112. * complete
  113. */
  114. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  115. usleep_range(10, 20);
  116. command = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL);
  117. if ((command & IXGBE_SB_IOSF_CTRL_BUSY) == 0)
  118. break;
  119. }
  120. if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) {
  121. error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >>
  122. IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT;
  123. hw_dbg(hw, "Failed to read, error %x\n", error);
  124. return IXGBE_ERR_PHY;
  125. }
  126. if (i == IXGBE_MDIO_COMMAND_TIMEOUT) {
  127. hw_dbg(hw, "Read timed out\n");
  128. return IXGBE_ERR_PHY;
  129. }
  130. *data = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_DATA);
  131. return 0;
  132. }
  133. /** ixgbe_read_ee_hostif_data_X550 - Read EEPROM word using a host interface
  134. * command assuming that the semaphore is already obtained.
  135. * @hw: pointer to hardware structure
  136. * @offset: offset of word in the EEPROM to read
  137. * @data: word read from the EEPROM
  138. *
  139. * Reads a 16 bit word from the EEPROM using the hostif.
  140. **/
  141. s32 ixgbe_read_ee_hostif_data_X550(struct ixgbe_hw *hw, u16 offset, u16 *data)
  142. {
  143. s32 status;
  144. struct ixgbe_hic_read_shadow_ram buffer;
  145. buffer.hdr.req.cmd = FW_READ_SHADOW_RAM_CMD;
  146. buffer.hdr.req.buf_lenh = 0;
  147. buffer.hdr.req.buf_lenl = FW_READ_SHADOW_RAM_LEN;
  148. buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
  149. /* convert offset from words to bytes */
  150. buffer.address = cpu_to_be32(offset * 2);
  151. /* one word */
  152. buffer.length = cpu_to_be16(sizeof(u16));
  153. status = ixgbe_host_interface_command(hw, (u32 *)&buffer,
  154. sizeof(buffer),
  155. IXGBE_HI_COMMAND_TIMEOUT, false);
  156. if (status)
  157. return status;
  158. *data = (u16)IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG,
  159. FW_NVM_DATA_OFFSET);
  160. return 0;
  161. }
  162. /** ixgbe_read_ee_hostif_buffer_X550- Read EEPROM word(s) using hostif
  163. * @hw: pointer to hardware structure
  164. * @offset: offset of word in the EEPROM to read
  165. * @words: number of words
  166. * @data: word(s) read from the EEPROM
  167. *
  168. * Reads a 16 bit word(s) from the EEPROM using the hostif.
  169. **/
  170. s32 ixgbe_read_ee_hostif_buffer_X550(struct ixgbe_hw *hw,
  171. u16 offset, u16 words, u16 *data)
  172. {
  173. struct ixgbe_hic_read_shadow_ram buffer;
  174. u32 current_word = 0;
  175. u16 words_to_read;
  176. s32 status;
  177. u32 i;
  178. /* Take semaphore for the entire operation. */
  179. status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  180. if (status) {
  181. hw_dbg(hw, "EEPROM read buffer - semaphore failed\n");
  182. return status;
  183. }
  184. while (words) {
  185. if (words > FW_MAX_READ_BUFFER_SIZE / 2)
  186. words_to_read = FW_MAX_READ_BUFFER_SIZE / 2;
  187. else
  188. words_to_read = words;
  189. buffer.hdr.req.cmd = FW_READ_SHADOW_RAM_CMD;
  190. buffer.hdr.req.buf_lenh = 0;
  191. buffer.hdr.req.buf_lenl = FW_READ_SHADOW_RAM_LEN;
  192. buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
  193. /* convert offset from words to bytes */
  194. buffer.address = cpu_to_be32((offset + current_word) * 2);
  195. buffer.length = cpu_to_be16(words_to_read * 2);
  196. status = ixgbe_host_interface_command(hw, (u32 *)&buffer,
  197. sizeof(buffer),
  198. IXGBE_HI_COMMAND_TIMEOUT,
  199. false);
  200. if (status) {
  201. hw_dbg(hw, "Host interface command failed\n");
  202. goto out;
  203. }
  204. for (i = 0; i < words_to_read; i++) {
  205. u32 reg = IXGBE_FLEX_MNG + (FW_NVM_DATA_OFFSET << 2) +
  206. 2 * i;
  207. u32 value = IXGBE_READ_REG(hw, reg);
  208. data[current_word] = (u16)(value & 0xffff);
  209. current_word++;
  210. i++;
  211. if (i < words_to_read) {
  212. value >>= 16;
  213. data[current_word] = (u16)(value & 0xffff);
  214. current_word++;
  215. }
  216. }
  217. words -= words_to_read;
  218. }
  219. out:
  220. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  221. return status;
  222. }
  223. /** ixgbe_checksum_ptr_x550 - Checksum one pointer region
  224. * @hw: pointer to hardware structure
  225. * @ptr: pointer offset in eeprom
  226. * @size: size of section pointed by ptr, if 0 first word will be used as size
  227. * @csum: address of checksum to update
  228. *
  229. * Returns error status for any failure
  230. **/
  231. static s32 ixgbe_checksum_ptr_x550(struct ixgbe_hw *hw, u16 ptr,
  232. u16 size, u16 *csum, u16 *buffer,
  233. u32 buffer_size)
  234. {
  235. u16 buf[256];
  236. s32 status;
  237. u16 length, bufsz, i, start;
  238. u16 *local_buffer;
  239. bufsz = sizeof(buf) / sizeof(buf[0]);
  240. /* Read a chunk at the pointer location */
  241. if (!buffer) {
  242. status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr, bufsz, buf);
  243. if (status) {
  244. hw_dbg(hw, "Failed to read EEPROM image\n");
  245. return status;
  246. }
  247. local_buffer = buf;
  248. } else {
  249. if (buffer_size < ptr)
  250. return IXGBE_ERR_PARAM;
  251. local_buffer = &buffer[ptr];
  252. }
  253. if (size) {
  254. start = 0;
  255. length = size;
  256. } else {
  257. start = 1;
  258. length = local_buffer[0];
  259. /* Skip pointer section if length is invalid. */
  260. if (length == 0xFFFF || length == 0 ||
  261. (ptr + length) >= hw->eeprom.word_size)
  262. return 0;
  263. }
  264. if (buffer && ((u32)start + (u32)length > buffer_size))
  265. return IXGBE_ERR_PARAM;
  266. for (i = start; length; i++, length--) {
  267. if (i == bufsz && !buffer) {
  268. ptr += bufsz;
  269. i = 0;
  270. if (length < bufsz)
  271. bufsz = length;
  272. /* Read a chunk at the pointer location */
  273. status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr,
  274. bufsz, buf);
  275. if (status) {
  276. hw_dbg(hw, "Failed to read EEPROM image\n");
  277. return status;
  278. }
  279. }
  280. *csum += local_buffer[i];
  281. }
  282. return 0;
  283. }
  284. /** ixgbe_calc_checksum_X550 - Calculates and returns the checksum
  285. * @hw: pointer to hardware structure
  286. * @buffer: pointer to buffer containing calculated checksum
  287. * @buffer_size: size of buffer
  288. *
  289. * Returns a negative error code on error, or the 16-bit checksum
  290. **/
  291. s32 ixgbe_calc_checksum_X550(struct ixgbe_hw *hw, u16 *buffer, u32 buffer_size)
  292. {
  293. u16 eeprom_ptrs[IXGBE_EEPROM_LAST_WORD + 1];
  294. u16 *local_buffer;
  295. s32 status;
  296. u16 checksum = 0;
  297. u16 pointer, i, size;
  298. hw->eeprom.ops.init_params(hw);
  299. if (!buffer) {
  300. /* Read pointer area */
  301. status = ixgbe_read_ee_hostif_buffer_X550(hw, 0,
  302. IXGBE_EEPROM_LAST_WORD + 1,
  303. eeprom_ptrs);
  304. if (status) {
  305. hw_dbg(hw, "Failed to read EEPROM image\n");
  306. return status;
  307. }
  308. local_buffer = eeprom_ptrs;
  309. } else {
  310. if (buffer_size < IXGBE_EEPROM_LAST_WORD)
  311. return IXGBE_ERR_PARAM;
  312. local_buffer = buffer;
  313. }
  314. /* For X550 hardware include 0x0-0x41 in the checksum, skip the
  315. * checksum word itself
  316. */
  317. for (i = 0; i <= IXGBE_EEPROM_LAST_WORD; i++)
  318. if (i != IXGBE_EEPROM_CHECKSUM)
  319. checksum += local_buffer[i];
  320. /* Include all data from pointers 0x3, 0x6-0xE. This excludes the
  321. * FW, PHY module, and PCIe Expansion/Option ROM pointers.
  322. */
  323. for (i = IXGBE_PCIE_ANALOG_PTR_X550; i < IXGBE_FW_PTR; i++) {
  324. if (i == IXGBE_PHY_PTR || i == IXGBE_OPTION_ROM_PTR)
  325. continue;
  326. pointer = local_buffer[i];
  327. /* Skip pointer section if the pointer is invalid. */
  328. if (pointer == 0xFFFF || pointer == 0 ||
  329. pointer >= hw->eeprom.word_size)
  330. continue;
  331. switch (i) {
  332. case IXGBE_PCIE_GENERAL_PTR:
  333. size = IXGBE_IXGBE_PCIE_GENERAL_SIZE;
  334. break;
  335. case IXGBE_PCIE_CONFIG0_PTR:
  336. case IXGBE_PCIE_CONFIG1_PTR:
  337. size = IXGBE_PCIE_CONFIG_SIZE;
  338. break;
  339. default:
  340. size = 0;
  341. break;
  342. }
  343. status = ixgbe_checksum_ptr_x550(hw, pointer, size, &checksum,
  344. buffer, buffer_size);
  345. if (status)
  346. return status;
  347. }
  348. checksum = (u16)IXGBE_EEPROM_SUM - checksum;
  349. return (s32)checksum;
  350. }
  351. /** ixgbe_calc_eeprom_checksum_X550 - Calculates and returns the checksum
  352. * @hw: pointer to hardware structure
  353. *
  354. * Returns a negative error code on error, or the 16-bit checksum
  355. **/
  356. s32 ixgbe_calc_eeprom_checksum_X550(struct ixgbe_hw *hw)
  357. {
  358. return ixgbe_calc_checksum_X550(hw, NULL, 0);
  359. }
  360. /** ixgbe_read_ee_hostif_X550 - Read EEPROM word using a host interface command
  361. * @hw: pointer to hardware structure
  362. * @offset: offset of word in the EEPROM to read
  363. * @data: word read from the EEPROM
  364. *
  365. * Reads a 16 bit word from the EEPROM using the hostif.
  366. **/
  367. s32 ixgbe_read_ee_hostif_X550(struct ixgbe_hw *hw, u16 offset, u16 *data)
  368. {
  369. s32 status = 0;
  370. if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0) {
  371. status = ixgbe_read_ee_hostif_data_X550(hw, offset, data);
  372. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  373. } else {
  374. status = IXGBE_ERR_SWFW_SYNC;
  375. }
  376. return status;
  377. }
  378. /** ixgbe_validate_eeprom_checksum_X550 - Validate EEPROM checksum
  379. * @hw: pointer to hardware structure
  380. * @checksum_val: calculated checksum
  381. *
  382. * Performs checksum calculation and validates the EEPROM checksum. If the
  383. * caller does not need checksum_val, the value can be NULL.
  384. **/
  385. s32 ixgbe_validate_eeprom_checksum_X550(struct ixgbe_hw *hw, u16 *checksum_val)
  386. {
  387. s32 status;
  388. u16 checksum;
  389. u16 read_checksum = 0;
  390. /* Read the first word from the EEPROM. If this times out or fails, do
  391. * not continue or we could be in for a very long wait while every
  392. * EEPROM read fails
  393. */
  394. status = hw->eeprom.ops.read(hw, 0, &checksum);
  395. if (status) {
  396. hw_dbg(hw, "EEPROM read failed\n");
  397. return status;
  398. }
  399. status = hw->eeprom.ops.calc_checksum(hw);
  400. if (status < 0)
  401. return status;
  402. checksum = (u16)(status & 0xffff);
  403. status = ixgbe_read_ee_hostif_X550(hw, IXGBE_EEPROM_CHECKSUM,
  404. &read_checksum);
  405. if (status)
  406. return status;
  407. /* Verify read checksum from EEPROM is the same as
  408. * calculated checksum
  409. */
  410. if (read_checksum != checksum) {
  411. status = IXGBE_ERR_EEPROM_CHECKSUM;
  412. hw_dbg(hw, "Invalid EEPROM checksum");
  413. }
  414. /* If the user cares, return the calculated checksum */
  415. if (checksum_val)
  416. *checksum_val = checksum;
  417. return status;
  418. }
  419. /** ixgbe_write_ee_hostif_X550 - Write EEPROM word using hostif
  420. * @hw: pointer to hardware structure
  421. * @offset: offset of word in the EEPROM to write
  422. * @data: word write to the EEPROM
  423. *
  424. * Write a 16 bit word to the EEPROM using the hostif.
  425. **/
  426. s32 ixgbe_write_ee_hostif_data_X550(struct ixgbe_hw *hw, u16 offset, u16 data)
  427. {
  428. s32 status;
  429. struct ixgbe_hic_write_shadow_ram buffer;
  430. buffer.hdr.req.cmd = FW_WRITE_SHADOW_RAM_CMD;
  431. buffer.hdr.req.buf_lenh = 0;
  432. buffer.hdr.req.buf_lenl = FW_WRITE_SHADOW_RAM_LEN;
  433. buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
  434. /* one word */
  435. buffer.length = cpu_to_be16(sizeof(u16));
  436. buffer.data = data;
  437. buffer.address = cpu_to_be32(offset * 2);
  438. status = ixgbe_host_interface_command(hw, (u32 *)&buffer,
  439. sizeof(buffer),
  440. IXGBE_HI_COMMAND_TIMEOUT, false);
  441. return status;
  442. }
  443. /** ixgbe_write_ee_hostif_X550 - Write EEPROM word using hostif
  444. * @hw: pointer to hardware structure
  445. * @offset: offset of word in the EEPROM to write
  446. * @data: word write to the EEPROM
  447. *
  448. * Write a 16 bit word to the EEPROM using the hostif.
  449. **/
  450. s32 ixgbe_write_ee_hostif_X550(struct ixgbe_hw *hw, u16 offset, u16 data)
  451. {
  452. s32 status = 0;
  453. if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0) {
  454. status = ixgbe_write_ee_hostif_data_X550(hw, offset, data);
  455. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  456. } else {
  457. hw_dbg(hw, "write ee hostif failed to get semaphore");
  458. status = IXGBE_ERR_SWFW_SYNC;
  459. }
  460. return status;
  461. }
  462. /** ixgbe_update_flash_X550 - Instruct HW to copy EEPROM to Flash device
  463. * @hw: pointer to hardware structure
  464. *
  465. * Issue a shadow RAM dump to FW to copy EEPROM from shadow RAM to the flash.
  466. **/
  467. s32 ixgbe_update_flash_X550(struct ixgbe_hw *hw)
  468. {
  469. s32 status = 0;
  470. union ixgbe_hic_hdr2 buffer;
  471. buffer.req.cmd = FW_SHADOW_RAM_DUMP_CMD;
  472. buffer.req.buf_lenh = 0;
  473. buffer.req.buf_lenl = FW_SHADOW_RAM_DUMP_LEN;
  474. buffer.req.checksum = FW_DEFAULT_CHECKSUM;
  475. status = ixgbe_host_interface_command(hw, (u32 *)&buffer,
  476. sizeof(buffer),
  477. IXGBE_HI_COMMAND_TIMEOUT, false);
  478. return status;
  479. }
  480. /** ixgbe_update_eeprom_checksum_X550 - Updates the EEPROM checksum and flash
  481. * @hw: pointer to hardware structure
  482. *
  483. * After writing EEPROM to shadow RAM using EEWR register, software calculates
  484. * checksum and updates the EEPROM and instructs the hardware to update
  485. * the flash.
  486. **/
  487. s32 ixgbe_update_eeprom_checksum_X550(struct ixgbe_hw *hw)
  488. {
  489. s32 status;
  490. u16 checksum = 0;
  491. /* Read the first word from the EEPROM. If this times out or fails, do
  492. * not continue or we could be in for a very long wait while every
  493. * EEPROM read fails
  494. */
  495. status = ixgbe_read_ee_hostif_X550(hw, 0, &checksum);
  496. if (status) {
  497. hw_dbg(hw, "EEPROM read failed\n");
  498. return status;
  499. }
  500. status = ixgbe_calc_eeprom_checksum_X550(hw);
  501. if (status < 0)
  502. return status;
  503. checksum = (u16)(status & 0xffff);
  504. status = ixgbe_write_ee_hostif_X550(hw, IXGBE_EEPROM_CHECKSUM,
  505. checksum);
  506. if (status)
  507. return status;
  508. status = ixgbe_update_flash_X550(hw);
  509. return status;
  510. }
  511. /** ixgbe_write_ee_hostif_buffer_X550 - Write EEPROM word(s) using hostif
  512. * @hw: pointer to hardware structure
  513. * @offset: offset of word in the EEPROM to write
  514. * @words: number of words
  515. * @data: word(s) write to the EEPROM
  516. *
  517. *
  518. * Write a 16 bit word(s) to the EEPROM using the hostif.
  519. **/
  520. s32 ixgbe_write_ee_hostif_buffer_X550(struct ixgbe_hw *hw,
  521. u16 offset, u16 words, u16 *data)
  522. {
  523. s32 status = 0;
  524. u32 i = 0;
  525. /* Take semaphore for the entire operation. */
  526. status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  527. if (status) {
  528. hw_dbg(hw, "EEPROM write buffer - semaphore failed\n");
  529. return status;
  530. }
  531. for (i = 0; i < words; i++) {
  532. status = ixgbe_write_ee_hostif_data_X550(hw, offset + i,
  533. data[i]);
  534. if (status) {
  535. hw_dbg(hw, "Eeprom buffered write failed\n");
  536. break;
  537. }
  538. }
  539. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  540. return status;
  541. }
  542. /** ixgbe_init_mac_link_ops_X550em - init mac link function pointers
  543. * @hw: pointer to hardware structure
  544. **/
  545. void ixgbe_init_mac_link_ops_X550em(struct ixgbe_hw *hw)
  546. {
  547. struct ixgbe_mac_info *mac = &hw->mac;
  548. /* CS4227 does not support autoneg, so disable the laser control
  549. * functions for SFP+ fiber
  550. */
  551. if (hw->device_id == IXGBE_DEV_ID_X550EM_X_SFP) {
  552. mac->ops.disable_tx_laser = NULL;
  553. mac->ops.enable_tx_laser = NULL;
  554. mac->ops.flap_tx_laser = NULL;
  555. }
  556. }
  557. /** ixgbe_setup_sfp_modules_X550em - Setup SFP module
  558. * @hw: pointer to hardware structure
  559. */
  560. s32 ixgbe_setup_sfp_modules_X550em(struct ixgbe_hw *hw)
  561. {
  562. bool setup_linear;
  563. u16 reg_slice, edc_mode;
  564. s32 ret_val;
  565. switch (hw->phy.sfp_type) {
  566. case ixgbe_sfp_type_unknown:
  567. return 0;
  568. case ixgbe_sfp_type_not_present:
  569. return IXGBE_ERR_SFP_NOT_PRESENT;
  570. case ixgbe_sfp_type_da_cu_core0:
  571. case ixgbe_sfp_type_da_cu_core1:
  572. setup_linear = true;
  573. break;
  574. case ixgbe_sfp_type_srlr_core0:
  575. case ixgbe_sfp_type_srlr_core1:
  576. case ixgbe_sfp_type_da_act_lmt_core0:
  577. case ixgbe_sfp_type_da_act_lmt_core1:
  578. case ixgbe_sfp_type_1g_sx_core0:
  579. case ixgbe_sfp_type_1g_sx_core1:
  580. setup_linear = false;
  581. break;
  582. default:
  583. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  584. }
  585. ixgbe_init_mac_link_ops_X550em(hw);
  586. hw->phy.ops.reset = NULL;
  587. /* The CS4227 slice address is the base address + the port-pair reg
  588. * offset. I.e. Slice 0 = 0x12B0 and slice 1 = 0x22B0.
  589. */
  590. reg_slice = IXGBE_CS4227_SPARE24_LSB + (hw->bus.lan_id << 12);
  591. if (setup_linear)
  592. edc_mode = (IXGBE_CS4227_EDC_MODE_CX1 << 1) | 0x1;
  593. else
  594. edc_mode = (IXGBE_CS4227_EDC_MODE_SR << 1) | 0x1;
  595. /* Configure CS4227 for connection type. */
  596. ret_val = hw->phy.ops.write_i2c_combined(hw, IXGBE_CS4227, reg_slice,
  597. edc_mode);
  598. if (ret_val)
  599. ret_val = hw->phy.ops.write_i2c_combined(hw, 0x80, reg_slice,
  600. edc_mode);
  601. return ret_val;
  602. }
  603. /** ixgbe_get_link_capabilities_x550em - Determines link capabilities
  604. * @hw: pointer to hardware structure
  605. * @speed: pointer to link speed
  606. * @autoneg: true when autoneg or autotry is enabled
  607. **/
  608. s32 ixgbe_get_link_capabilities_X550em(struct ixgbe_hw *hw,
  609. ixgbe_link_speed *speed,
  610. bool *autoneg)
  611. {
  612. /* SFP */
  613. if (hw->phy.media_type == ixgbe_media_type_fiber) {
  614. /* CS4227 SFP must not enable auto-negotiation */
  615. *autoneg = false;
  616. if (hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
  617. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1) {
  618. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  619. return 0;
  620. }
  621. /* Link capabilities are based on SFP */
  622. if (hw->phy.multispeed_fiber)
  623. *speed = IXGBE_LINK_SPEED_10GB_FULL |
  624. IXGBE_LINK_SPEED_1GB_FULL;
  625. else
  626. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  627. } else {
  628. *speed = IXGBE_LINK_SPEED_10GB_FULL |
  629. IXGBE_LINK_SPEED_1GB_FULL;
  630. *autoneg = true;
  631. }
  632. return 0;
  633. }
  634. /** ixgbe_write_iosf_sb_reg_x550 - Writes a value to specified register of the
  635. * IOSF device
  636. *
  637. * @hw: pointer to hardware structure
  638. * @reg_addr: 32 bit PHY register to write
  639. * @device_type: 3 bit device type
  640. * @data: Data to write to the register
  641. **/
  642. s32 ixgbe_write_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr,
  643. u32 device_type, u32 data)
  644. {
  645. u32 i, command, error;
  646. command = ((reg_addr << IXGBE_SB_IOSF_CTRL_ADDR_SHIFT) |
  647. (device_type << IXGBE_SB_IOSF_CTRL_TARGET_SELECT_SHIFT));
  648. /* Write IOSF control register */
  649. IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL, command);
  650. /* Write IOSF data register */
  651. IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_DATA, data);
  652. /* Check every 10 usec to see if the address cycle completed.
  653. * The SB IOSF BUSY bit will clear when the operation is
  654. * complete
  655. */
  656. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  657. usleep_range(10, 20);
  658. command = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL);
  659. if ((command & IXGBE_SB_IOSF_CTRL_BUSY) == 0)
  660. break;
  661. }
  662. if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) {
  663. error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >>
  664. IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT;
  665. hw_dbg(hw, "Failed to write, error %x\n", error);
  666. return IXGBE_ERR_PHY;
  667. }
  668. if (i == IXGBE_MDIO_COMMAND_TIMEOUT) {
  669. hw_dbg(hw, "Write timed out\n");
  670. return IXGBE_ERR_PHY;
  671. }
  672. return 0;
  673. }
  674. /** ixgbe_setup_ixfi_x550em - Configure the KR PHY for iXFI mode.
  675. * @hw: pointer to hardware structure
  676. * @speed: the link speed to force
  677. *
  678. * Configures the integrated KR PHY to use iXFI mode. Used to connect an
  679. * internal and external PHY at a specific speed, without autonegotiation.
  680. **/
  681. static s32 ixgbe_setup_ixfi_x550em(struct ixgbe_hw *hw, ixgbe_link_speed *speed)
  682. {
  683. s32 status;
  684. u32 reg_val;
  685. /* Disable AN and force speed to 10G Serial. */
  686. status = ixgbe_read_iosf_sb_reg_x550(hw,
  687. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  688. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  689. if (status)
  690. return status;
  691. reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
  692. reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
  693. /* Select forced link speed for internal PHY. */
  694. switch (*speed) {
  695. case IXGBE_LINK_SPEED_10GB_FULL:
  696. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_10G;
  697. break;
  698. case IXGBE_LINK_SPEED_1GB_FULL:
  699. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_1G;
  700. break;
  701. default:
  702. /* Other link speeds are not supported by internal KR PHY. */
  703. return IXGBE_ERR_LINK_SETUP;
  704. }
  705. status = ixgbe_write_iosf_sb_reg_x550(hw,
  706. IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
  707. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  708. if (status)
  709. return status;
  710. /* Disable training protocol FSM. */
  711. status = ixgbe_read_iosf_sb_reg_x550(hw,
  712. IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
  713. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  714. if (status)
  715. return status;
  716. reg_val |= IXGBE_KRM_RX_TRN_LINKUP_CTRL_CONV_WO_PROTOCOL;
  717. status = ixgbe_write_iosf_sb_reg_x550(hw,
  718. IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
  719. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  720. if (status)
  721. return status;
  722. /* Disable Flex from training TXFFE. */
  723. status = ixgbe_read_iosf_sb_reg_x550(hw,
  724. IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id),
  725. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  726. if (status)
  727. return status;
  728. reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN;
  729. reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN;
  730. reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN;
  731. status = ixgbe_write_iosf_sb_reg_x550(hw,
  732. IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id),
  733. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  734. if (status)
  735. return status;
  736. status = ixgbe_read_iosf_sb_reg_x550(hw,
  737. IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id),
  738. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  739. if (status)
  740. return status;
  741. reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN;
  742. reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN;
  743. reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN;
  744. status = ixgbe_write_iosf_sb_reg_x550(hw,
  745. IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id),
  746. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  747. if (status)
  748. return status;
  749. /* Enable override for coefficients. */
  750. status = ixgbe_read_iosf_sb_reg_x550(hw,
  751. IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id),
  752. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  753. if (status)
  754. return status;
  755. reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_OVRRD_EN;
  756. reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CZERO_EN;
  757. reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CPLUS1_OVRRD_EN;
  758. reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CMINUS1_OVRRD_EN;
  759. status = ixgbe_write_iosf_sb_reg_x550(hw,
  760. IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id),
  761. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  762. if (status)
  763. return status;
  764. /* Toggle port SW reset by AN reset. */
  765. status = ixgbe_read_iosf_sb_reg_x550(hw,
  766. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  767. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  768. if (status)
  769. return status;
  770. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_RESTART;
  771. status = ixgbe_write_iosf_sb_reg_x550(hw,
  772. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  773. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  774. return status;
  775. }
  776. /** ixgbe_setup_kx4_x550em - Configure the KX4 PHY.
  777. * @hw: pointer to hardware structure
  778. *
  779. * Configures the integrated KX4 PHY.
  780. **/
  781. s32 ixgbe_setup_kx4_x550em(struct ixgbe_hw *hw)
  782. {
  783. s32 status;
  784. u32 reg_val;
  785. status = ixgbe_read_iosf_sb_reg_x550(hw, IXGBE_KX4_LINK_CNTL_1,
  786. IXGBE_SB_IOSF_TARGET_KX4_PCS0 +
  787. hw->bus.lan_id, &reg_val);
  788. if (status)
  789. return status;
  790. reg_val &= ~(IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX4 |
  791. IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX);
  792. reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_ENABLE;
  793. /* Advertise 10G support. */
  794. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
  795. reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX4;
  796. /* Advertise 1G support. */
  797. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
  798. reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX;
  799. /* Restart auto-negotiation. */
  800. reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_RESTART;
  801. status = ixgbe_write_iosf_sb_reg_x550(hw, IXGBE_KX4_LINK_CNTL_1,
  802. IXGBE_SB_IOSF_TARGET_KX4_PCS0 +
  803. hw->bus.lan_id, reg_val);
  804. return status;
  805. }
  806. /** ixgbe_setup_kr_x550em - Configure the KR PHY.
  807. * @hw: pointer to hardware structure
  808. *
  809. * Configures the integrated KR PHY.
  810. **/
  811. s32 ixgbe_setup_kr_x550em(struct ixgbe_hw *hw)
  812. {
  813. s32 status;
  814. u32 reg_val;
  815. status = ixgbe_read_iosf_sb_reg_x550(hw,
  816. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  817. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  818. if (status)
  819. return status;
  820. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
  821. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_FEC_REQ;
  822. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_FEC;
  823. reg_val &= ~(IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR |
  824. IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX);
  825. /* Advertise 10G support. */
  826. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
  827. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR;
  828. /* Advertise 1G support. */
  829. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
  830. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX;
  831. /* Restart auto-negotiation. */
  832. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_RESTART;
  833. status = ixgbe_write_iosf_sb_reg_x550(hw,
  834. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  835. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  836. return status;
  837. }
  838. /** ixgbe_setup_internal_phy_x550em - Configure integrated KR PHY
  839. * @hw: point to hardware structure
  840. *
  841. * Configures the integrated KR PHY to talk to the external PHY. The base
  842. * driver will call this function when it gets notification via interrupt from
  843. * the external PHY. This function forces the internal PHY into iXFI mode at
  844. * the correct speed.
  845. *
  846. * A return of a non-zero value indicates an error, and the base driver should
  847. * not report link up.
  848. **/
  849. s32 ixgbe_setup_internal_phy_x550em(struct ixgbe_hw *hw)
  850. {
  851. u32 status;
  852. u16 lasi, autoneg_status, speed;
  853. ixgbe_link_speed force_speed;
  854. /* Verify that the external link status has changed */
  855. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_XENPAK_LASI_STATUS,
  856. IXGBE_MDIO_PMA_PMD_DEV_TYPE, &lasi);
  857. if (status)
  858. return status;
  859. /* If there was no change in link status, we can just exit */
  860. if (!(lasi & IXGBE_XENPAK_LASI_LINK_STATUS_ALARM))
  861. return 0;
  862. /* we read this twice back to back to indicate current status */
  863. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
  864. IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
  865. &autoneg_status);
  866. if (status)
  867. return status;
  868. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
  869. IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
  870. &autoneg_status);
  871. if (status)
  872. return status;
  873. /* If link is not up return an error indicating treat link as down */
  874. if (!(autoneg_status & IXGBE_MDIO_AUTO_NEG_LINK_STATUS))
  875. return IXGBE_ERR_INVALID_LINK_SETTINGS;
  876. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_STAT,
  877. IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
  878. &speed);
  879. /* clear everything but the speed and duplex bits */
  880. speed &= IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_MASK;
  881. switch (speed) {
  882. case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_10GB_FULL:
  883. force_speed = IXGBE_LINK_SPEED_10GB_FULL;
  884. break;
  885. case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_1GB_FULL:
  886. force_speed = IXGBE_LINK_SPEED_1GB_FULL;
  887. break;
  888. default:
  889. /* Internal PHY does not support anything else */
  890. return IXGBE_ERR_INVALID_LINK_SETTINGS;
  891. }
  892. return ixgbe_setup_ixfi_x550em(hw, &force_speed);
  893. }
  894. /** ixgbe_init_phy_ops_X550em - PHY/SFP specific init
  895. * @hw: pointer to hardware structure
  896. *
  897. * Initialize any function pointers that were not able to be
  898. * set during init_shared_code because the PHY/SFP type was
  899. * not known. Perform the SFP init if necessary.
  900. **/
  901. s32 ixgbe_init_phy_ops_X550em(struct ixgbe_hw *hw)
  902. {
  903. struct ixgbe_phy_info *phy = &hw->phy;
  904. s32 ret_val;
  905. u32 esdp;
  906. if (hw->device_id == IXGBE_DEV_ID_X550EM_X_SFP) {
  907. esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  908. phy->phy_semaphore_mask = IXGBE_GSSR_SHARED_I2C_SM;
  909. if (hw->bus.lan_id) {
  910. esdp &= ~(IXGBE_ESDP_SDP1_NATIVE | IXGBE_ESDP_SDP1);
  911. esdp |= IXGBE_ESDP_SDP1_DIR;
  912. }
  913. esdp &= ~(IXGBE_ESDP_SDP0_NATIVE | IXGBE_ESDP_SDP0_DIR);
  914. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
  915. }
  916. /* Identify the PHY or SFP module */
  917. ret_val = phy->ops.identify(hw);
  918. /* Setup function pointers based on detected SFP module and speeds */
  919. ixgbe_init_mac_link_ops_X550em(hw);
  920. if (phy->sfp_type != ixgbe_sfp_type_unknown)
  921. phy->ops.reset = NULL;
  922. /* Set functions pointers based on phy type */
  923. switch (hw->phy.type) {
  924. case ixgbe_phy_x550em_kx4:
  925. phy->ops.setup_link = ixgbe_setup_kx4_x550em;
  926. phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
  927. phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
  928. break;
  929. case ixgbe_phy_x550em_kr:
  930. phy->ops.setup_link = ixgbe_setup_kr_x550em;
  931. phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
  932. phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
  933. break;
  934. case ixgbe_phy_x550em_ext_t:
  935. phy->ops.setup_internal_link = ixgbe_setup_internal_phy_x550em;
  936. break;
  937. default:
  938. break;
  939. }
  940. return ret_val;
  941. }
  942. /** ixgbe_get_media_type_X550em - Get media type
  943. * @hw: pointer to hardware structure
  944. *
  945. * Returns the media type (fiber, copper, backplane)
  946. *
  947. */
  948. enum ixgbe_media_type ixgbe_get_media_type_X550em(struct ixgbe_hw *hw)
  949. {
  950. enum ixgbe_media_type media_type;
  951. /* Detect if there is a copper PHY attached. */
  952. switch (hw->device_id) {
  953. case IXGBE_DEV_ID_X550EM_X_KR:
  954. case IXGBE_DEV_ID_X550EM_X_KX4:
  955. media_type = ixgbe_media_type_backplane;
  956. break;
  957. case IXGBE_DEV_ID_X550EM_X_SFP:
  958. media_type = ixgbe_media_type_fiber;
  959. break;
  960. case IXGBE_DEV_ID_X550EM_X_1G_T:
  961. case IXGBE_DEV_ID_X550EM_X_10G_T:
  962. media_type = ixgbe_media_type_copper;
  963. break;
  964. default:
  965. media_type = ixgbe_media_type_unknown;
  966. break;
  967. }
  968. return media_type;
  969. }
  970. /** ixgbe_init_ext_t_x550em - Start (unstall) the external Base T PHY.
  971. ** @hw: pointer to hardware structure
  972. **/
  973. s32 ixgbe_init_ext_t_x550em(struct ixgbe_hw *hw)
  974. {
  975. u32 status;
  976. u16 reg;
  977. u32 retries = 2;
  978. do {
  979. /* decrement retries counter and exit if we hit 0 */
  980. if (retries < 1) {
  981. hw_dbg(hw, "External PHY not yet finished resetting.");
  982. return IXGBE_ERR_PHY;
  983. }
  984. retries--;
  985. status = hw->phy.ops.read_reg(hw,
  986. IXGBE_MDIO_TX_VENDOR_ALARMS_3,
  987. IXGBE_MDIO_PMA_PMD_DEV_TYPE,
  988. &reg);
  989. if (status)
  990. return status;
  991. /* Verify PHY FW reset has completed */
  992. } while ((reg & IXGBE_MDIO_TX_VENDOR_ALARMS_3_RST_MASK) != 1);
  993. /* Set port to low power mode */
  994. status = hw->phy.ops.read_reg(hw,
  995. IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL,
  996. IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
  997. &reg);
  998. if (status)
  999. return status;
  1000. /* Enable the transmitter */
  1001. status = hw->phy.ops.read_reg(hw,
  1002. IXGBE_MDIO_PMD_STD_TX_DISABLE_CNTR,
  1003. IXGBE_MDIO_PMA_PMD_DEV_TYPE,
  1004. &reg);
  1005. if (status)
  1006. return status;
  1007. reg &= ~IXGBE_MDIO_PMD_GLOBAL_TX_DISABLE;
  1008. status = hw->phy.ops.write_reg(hw,
  1009. IXGBE_MDIO_PMD_STD_TX_DISABLE_CNTR,
  1010. IXGBE_MDIO_PMA_PMD_DEV_TYPE,
  1011. reg);
  1012. if (status)
  1013. return status;
  1014. /* Un-stall the PHY FW */
  1015. status = hw->phy.ops.read_reg(hw,
  1016. IXGBE_MDIO_GLOBAL_RES_PR_10,
  1017. IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
  1018. &reg);
  1019. if (status)
  1020. return status;
  1021. reg &= ~IXGBE_MDIO_POWER_UP_STALL;
  1022. status = hw->phy.ops.write_reg(hw,
  1023. IXGBE_MDIO_GLOBAL_RES_PR_10,
  1024. IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
  1025. reg);
  1026. return status;
  1027. }
  1028. /** ixgbe_reset_hw_X550em - Perform hardware reset
  1029. ** @hw: pointer to hardware structure
  1030. **
  1031. ** Resets the hardware by resetting the transmit and receive units, masks
  1032. ** and clears all interrupts, perform a PHY reset, and perform a link (MAC)
  1033. ** reset.
  1034. **/
  1035. s32 ixgbe_reset_hw_X550em(struct ixgbe_hw *hw)
  1036. {
  1037. ixgbe_link_speed link_speed;
  1038. s32 status;
  1039. u32 ctrl = 0;
  1040. u32 i;
  1041. bool link_up = false;
  1042. /* Call adapter stop to disable Tx/Rx and clear interrupts */
  1043. status = hw->mac.ops.stop_adapter(hw);
  1044. if (status)
  1045. return status;
  1046. /* flush pending Tx transactions */
  1047. ixgbe_clear_tx_pending(hw);
  1048. /* PHY ops must be identified and initialized prior to reset */
  1049. /* Identify PHY and related function pointers */
  1050. status = hw->phy.ops.init(hw);
  1051. /* start the external PHY */
  1052. if (hw->phy.type == ixgbe_phy_x550em_ext_t) {
  1053. status = ixgbe_init_ext_t_x550em(hw);
  1054. if (status)
  1055. return status;
  1056. }
  1057. /* Setup SFP module if there is one present. */
  1058. if (hw->phy.sfp_setup_needed) {
  1059. status = hw->mac.ops.setup_sfp(hw);
  1060. hw->phy.sfp_setup_needed = false;
  1061. }
  1062. /* Reset PHY */
  1063. if (!hw->phy.reset_disable && hw->phy.ops.reset)
  1064. hw->phy.ops.reset(hw);
  1065. mac_reset_top:
  1066. /* Issue global reset to the MAC. Needs to be SW reset if link is up.
  1067. * If link reset is used when link is up, it might reset the PHY when
  1068. * mng is using it. If link is down or the flag to force full link
  1069. * reset is set, then perform link reset.
  1070. */
  1071. ctrl = IXGBE_CTRL_LNK_RST;
  1072. if (!hw->force_full_reset) {
  1073. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  1074. if (link_up)
  1075. ctrl = IXGBE_CTRL_RST;
  1076. }
  1077. ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL);
  1078. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  1079. IXGBE_WRITE_FLUSH(hw);
  1080. /* Poll for reset bit to self-clear meaning reset is complete */
  1081. for (i = 0; i < 10; i++) {
  1082. udelay(1);
  1083. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  1084. if (!(ctrl & IXGBE_CTRL_RST_MASK))
  1085. break;
  1086. }
  1087. if (ctrl & IXGBE_CTRL_RST_MASK) {
  1088. status = IXGBE_ERR_RESET_FAILED;
  1089. hw_dbg(hw, "Reset polling failed to complete.\n");
  1090. }
  1091. msleep(50);
  1092. /* Double resets are required for recovery from certain error
  1093. * clear the multicast table. Also reset num_rar_entries to 128,
  1094. * since we modify this value when programming the SAN MAC address.
  1095. */
  1096. if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
  1097. hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
  1098. goto mac_reset_top;
  1099. }
  1100. /* Store the permanent mac address */
  1101. hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
  1102. /* Store MAC address from RAR0, clear receive address registers, and
  1103. * clear the multicast table. Also reset num_rar_entries to 128,
  1104. * since we modify this value when programming the SAN MAC address.
  1105. */
  1106. hw->mac.num_rar_entries = 128;
  1107. hw->mac.ops.init_rx_addrs(hw);
  1108. return status;
  1109. }
  1110. #define X550_COMMON_MAC \
  1111. .init_hw = &ixgbe_init_hw_generic, \
  1112. .start_hw = &ixgbe_start_hw_X540, \
  1113. .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic, \
  1114. .enable_rx_dma = &ixgbe_enable_rx_dma_generic, \
  1115. .get_mac_addr = &ixgbe_get_mac_addr_generic, \
  1116. .get_device_caps = &ixgbe_get_device_caps_generic, \
  1117. .stop_adapter = &ixgbe_stop_adapter_generic, \
  1118. .get_bus_info = &ixgbe_get_bus_info_generic, \
  1119. .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie, \
  1120. .read_analog_reg8 = NULL, \
  1121. .write_analog_reg8 = NULL, \
  1122. .set_rxpba = &ixgbe_set_rxpba_generic, \
  1123. .check_link = &ixgbe_check_mac_link_generic, \
  1124. .led_on = &ixgbe_led_on_generic, \
  1125. .led_off = &ixgbe_led_off_generic, \
  1126. .blink_led_start = &ixgbe_blink_led_start_X540, \
  1127. .blink_led_stop = &ixgbe_blink_led_stop_X540, \
  1128. .set_rar = &ixgbe_set_rar_generic, \
  1129. .clear_rar = &ixgbe_clear_rar_generic, \
  1130. .set_vmdq = &ixgbe_set_vmdq_generic, \
  1131. .set_vmdq_san_mac = &ixgbe_set_vmdq_san_mac_generic, \
  1132. .clear_vmdq = &ixgbe_clear_vmdq_generic, \
  1133. .init_rx_addrs = &ixgbe_init_rx_addrs_generic, \
  1134. .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic, \
  1135. .enable_mc = &ixgbe_enable_mc_generic, \
  1136. .disable_mc = &ixgbe_disable_mc_generic, \
  1137. .clear_vfta = &ixgbe_clear_vfta_generic, \
  1138. .set_vfta = &ixgbe_set_vfta_generic, \
  1139. .fc_enable = &ixgbe_fc_enable_generic, \
  1140. .set_fw_drv_ver = &ixgbe_set_fw_drv_ver_generic, \
  1141. .init_uta_tables = &ixgbe_init_uta_tables_generic, \
  1142. .set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing, \
  1143. .set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing, \
  1144. .acquire_swfw_sync = &ixgbe_acquire_swfw_sync_X540, \
  1145. .release_swfw_sync = &ixgbe_release_swfw_sync_X540, \
  1146. .disable_rx_buff = &ixgbe_disable_rx_buff_generic, \
  1147. .enable_rx_buff = &ixgbe_enable_rx_buff_generic, \
  1148. .get_thermal_sensor_data = NULL, \
  1149. .init_thermal_sensor_thresh = NULL, \
  1150. .prot_autoc_read = &prot_autoc_read_generic, \
  1151. .prot_autoc_write = &prot_autoc_write_generic, \
  1152. static struct ixgbe_mac_operations mac_ops_X550 = {
  1153. X550_COMMON_MAC
  1154. .reset_hw = &ixgbe_reset_hw_X540,
  1155. .get_media_type = &ixgbe_get_media_type_X540,
  1156. .get_san_mac_addr = &ixgbe_get_san_mac_addr_generic,
  1157. .get_wwn_prefix = &ixgbe_get_wwn_prefix_generic,
  1158. .setup_link = &ixgbe_setup_mac_link_X540,
  1159. .set_rxpba = &ixgbe_set_rxpba_generic,
  1160. .get_link_capabilities = &ixgbe_get_copper_link_capabilities_generic,
  1161. .setup_sfp = NULL,
  1162. };
  1163. static struct ixgbe_mac_operations mac_ops_X550EM_x = {
  1164. X550_COMMON_MAC
  1165. .reset_hw = &ixgbe_reset_hw_X550em,
  1166. .get_media_type = &ixgbe_get_media_type_X550em,
  1167. .get_san_mac_addr = NULL,
  1168. .get_wwn_prefix = NULL,
  1169. .setup_link = NULL, /* defined later */
  1170. .get_link_capabilities = &ixgbe_get_link_capabilities_X550em,
  1171. .setup_sfp = ixgbe_setup_sfp_modules_X550em,
  1172. };
  1173. #define X550_COMMON_EEP \
  1174. .read = &ixgbe_read_ee_hostif_X550, \
  1175. .read_buffer = &ixgbe_read_ee_hostif_buffer_X550, \
  1176. .write = &ixgbe_write_ee_hostif_X550, \
  1177. .write_buffer = &ixgbe_write_ee_hostif_buffer_X550, \
  1178. .validate_checksum = &ixgbe_validate_eeprom_checksum_X550, \
  1179. .update_checksum = &ixgbe_update_eeprom_checksum_X550, \
  1180. .calc_checksum = &ixgbe_calc_eeprom_checksum_X550, \
  1181. static struct ixgbe_eeprom_operations eeprom_ops_X550 = {
  1182. X550_COMMON_EEP
  1183. .init_params = &ixgbe_init_eeprom_params_X550,
  1184. };
  1185. static struct ixgbe_eeprom_operations eeprom_ops_X550EM_x = {
  1186. X550_COMMON_EEP
  1187. .init_params = &ixgbe_init_eeprom_params_X540,
  1188. };
  1189. #define X550_COMMON_PHY \
  1190. .identify_sfp = &ixgbe_identify_module_generic, \
  1191. .reset = NULL, \
  1192. .setup_link_speed = &ixgbe_setup_phy_link_speed_generic, \
  1193. .read_i2c_byte = &ixgbe_read_i2c_byte_generic, \
  1194. .write_i2c_byte = &ixgbe_write_i2c_byte_generic, \
  1195. .read_i2c_sff8472 = &ixgbe_read_i2c_sff8472_generic, \
  1196. .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic, \
  1197. .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic, \
  1198. .check_overtemp = &ixgbe_tn_check_overtemp, \
  1199. .get_firmware_version = &ixgbe_get_phy_firmware_version_generic,
  1200. static struct ixgbe_phy_operations phy_ops_X550 = {
  1201. X550_COMMON_PHY
  1202. .init = NULL,
  1203. .identify = &ixgbe_identify_phy_generic,
  1204. .read_reg = &ixgbe_read_phy_reg_generic,
  1205. .write_reg = &ixgbe_write_phy_reg_generic,
  1206. .setup_link = &ixgbe_setup_phy_link_generic,
  1207. .read_i2c_combined = &ixgbe_read_i2c_combined_generic,
  1208. .write_i2c_combined = &ixgbe_write_i2c_combined_generic,
  1209. };
  1210. static struct ixgbe_phy_operations phy_ops_X550EM_x = {
  1211. X550_COMMON_PHY
  1212. .init = &ixgbe_init_phy_ops_X550em,
  1213. .identify = &ixgbe_identify_phy_x550em,
  1214. .read_reg = NULL, /* defined later */
  1215. .write_reg = NULL, /* defined later */
  1216. .setup_link = NULL, /* defined later */
  1217. };
  1218. struct ixgbe_info ixgbe_X550_info = {
  1219. .mac = ixgbe_mac_X550,
  1220. .get_invariants = &ixgbe_get_invariants_X540,
  1221. .mac_ops = &mac_ops_X550,
  1222. .eeprom_ops = &eeprom_ops_X550,
  1223. .phy_ops = &phy_ops_X550,
  1224. .mbx_ops = &mbx_ops_generic,
  1225. };
  1226. struct ixgbe_info ixgbe_X550EM_x_info = {
  1227. .mac = ixgbe_mac_X550EM_x,
  1228. .get_invariants = &ixgbe_get_invariants_X540,
  1229. .mac_ops = &mac_ops_X550EM_x,
  1230. .eeprom_ops = &eeprom_ops_X550EM_x,
  1231. .phy_ops = &phy_ops_X550EM_x,
  1232. .mbx_ops = &mbx_ops_generic,
  1233. };