ixgbe_x550.c 41 KB

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