ixgbe_x550.c 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532
  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_disable_rx_x550 - Disable RX unit
  485. *
  486. * Enables the Rx DMA unit for x550
  487. **/
  488. static void ixgbe_disable_rx_x550(struct ixgbe_hw *hw)
  489. {
  490. u32 rxctrl, pfdtxgswc;
  491. s32 status;
  492. struct ixgbe_hic_disable_rxen fw_cmd;
  493. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  494. if (rxctrl & IXGBE_RXCTRL_RXEN) {
  495. pfdtxgswc = IXGBE_READ_REG(hw, IXGBE_PFDTXGSWC);
  496. if (pfdtxgswc & IXGBE_PFDTXGSWC_VT_LBEN) {
  497. pfdtxgswc &= ~IXGBE_PFDTXGSWC_VT_LBEN;
  498. IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, pfdtxgswc);
  499. hw->mac.set_lben = true;
  500. } else {
  501. hw->mac.set_lben = false;
  502. }
  503. fw_cmd.hdr.cmd = FW_DISABLE_RXEN_CMD;
  504. fw_cmd.hdr.buf_len = FW_DISABLE_RXEN_LEN;
  505. fw_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
  506. fw_cmd.port_number = (u8)hw->bus.lan_id;
  507. status = ixgbe_host_interface_command(hw, (u32 *)&fw_cmd,
  508. sizeof(struct ixgbe_hic_disable_rxen),
  509. IXGBE_HI_COMMAND_TIMEOUT, true);
  510. /* If we fail - disable RX using register write */
  511. if (status) {
  512. rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
  513. if (rxctrl & IXGBE_RXCTRL_RXEN) {
  514. rxctrl &= ~IXGBE_RXCTRL_RXEN;
  515. IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl);
  516. }
  517. }
  518. }
  519. }
  520. /** ixgbe_update_eeprom_checksum_X550 - Updates the EEPROM checksum and flash
  521. * @hw: pointer to hardware structure
  522. *
  523. * After writing EEPROM to shadow RAM using EEWR register, software calculates
  524. * checksum and updates the EEPROM and instructs the hardware to update
  525. * the flash.
  526. **/
  527. static s32 ixgbe_update_eeprom_checksum_X550(struct ixgbe_hw *hw)
  528. {
  529. s32 status;
  530. u16 checksum = 0;
  531. /* Read the first word from the EEPROM. If this times out or fails, do
  532. * not continue or we could be in for a very long wait while every
  533. * EEPROM read fails
  534. */
  535. status = ixgbe_read_ee_hostif_X550(hw, 0, &checksum);
  536. if (status) {
  537. hw_dbg(hw, "EEPROM read failed\n");
  538. return status;
  539. }
  540. status = ixgbe_calc_eeprom_checksum_X550(hw);
  541. if (status < 0)
  542. return status;
  543. checksum = (u16)(status & 0xffff);
  544. status = ixgbe_write_ee_hostif_X550(hw, IXGBE_EEPROM_CHECKSUM,
  545. checksum);
  546. if (status)
  547. return status;
  548. status = ixgbe_update_flash_X550(hw);
  549. return status;
  550. }
  551. /** ixgbe_write_ee_hostif_buffer_X550 - Write EEPROM word(s) using hostif
  552. * @hw: pointer to hardware structure
  553. * @offset: offset of word in the EEPROM to write
  554. * @words: number of words
  555. * @data: word(s) write to the EEPROM
  556. *
  557. *
  558. * Write a 16 bit word(s) to the EEPROM using the hostif.
  559. **/
  560. static s32 ixgbe_write_ee_hostif_buffer_X550(struct ixgbe_hw *hw,
  561. u16 offset, u16 words,
  562. u16 *data)
  563. {
  564. s32 status = 0;
  565. u32 i = 0;
  566. /* Take semaphore for the entire operation. */
  567. status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  568. if (status) {
  569. hw_dbg(hw, "EEPROM write buffer - semaphore failed\n");
  570. return status;
  571. }
  572. for (i = 0; i < words; i++) {
  573. status = ixgbe_write_ee_hostif_data_X550(hw, offset + i,
  574. data[i]);
  575. if (status) {
  576. hw_dbg(hw, "Eeprom buffered write failed\n");
  577. break;
  578. }
  579. }
  580. hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
  581. return status;
  582. }
  583. /** ixgbe_init_mac_link_ops_X550em - init mac link function pointers
  584. * @hw: pointer to hardware structure
  585. **/
  586. static void ixgbe_init_mac_link_ops_X550em(struct ixgbe_hw *hw)
  587. {
  588. struct ixgbe_mac_info *mac = &hw->mac;
  589. /* CS4227 does not support autoneg, so disable the laser control
  590. * functions for SFP+ fiber
  591. */
  592. if (hw->device_id == IXGBE_DEV_ID_X550EM_X_SFP) {
  593. mac->ops.disable_tx_laser = NULL;
  594. mac->ops.enable_tx_laser = NULL;
  595. mac->ops.flap_tx_laser = NULL;
  596. }
  597. }
  598. /** ixgbe_setup_sfp_modules_X550em - Setup SFP module
  599. * @hw: pointer to hardware structure
  600. */
  601. static s32 ixgbe_setup_sfp_modules_X550em(struct ixgbe_hw *hw)
  602. {
  603. bool setup_linear;
  604. u16 reg_slice, edc_mode;
  605. s32 ret_val;
  606. switch (hw->phy.sfp_type) {
  607. case ixgbe_sfp_type_unknown:
  608. return 0;
  609. case ixgbe_sfp_type_not_present:
  610. return IXGBE_ERR_SFP_NOT_PRESENT;
  611. case ixgbe_sfp_type_da_cu_core0:
  612. case ixgbe_sfp_type_da_cu_core1:
  613. setup_linear = true;
  614. break;
  615. case ixgbe_sfp_type_srlr_core0:
  616. case ixgbe_sfp_type_srlr_core1:
  617. case ixgbe_sfp_type_da_act_lmt_core0:
  618. case ixgbe_sfp_type_da_act_lmt_core1:
  619. case ixgbe_sfp_type_1g_sx_core0:
  620. case ixgbe_sfp_type_1g_sx_core1:
  621. setup_linear = false;
  622. break;
  623. default:
  624. return IXGBE_ERR_SFP_NOT_SUPPORTED;
  625. }
  626. ixgbe_init_mac_link_ops_X550em(hw);
  627. hw->phy.ops.reset = NULL;
  628. /* The CS4227 slice address is the base address + the port-pair reg
  629. * offset. I.e. Slice 0 = 0x12B0 and slice 1 = 0x22B0.
  630. */
  631. reg_slice = IXGBE_CS4227_SPARE24_LSB + (hw->bus.lan_id << 12);
  632. if (setup_linear)
  633. edc_mode = (IXGBE_CS4227_EDC_MODE_CX1 << 1) | 0x1;
  634. else
  635. edc_mode = (IXGBE_CS4227_EDC_MODE_SR << 1) | 0x1;
  636. /* Configure CS4227 for connection type. */
  637. ret_val = hw->phy.ops.write_i2c_combined(hw, IXGBE_CS4227, reg_slice,
  638. edc_mode);
  639. if (ret_val)
  640. ret_val = hw->phy.ops.write_i2c_combined(hw, 0x80, reg_slice,
  641. edc_mode);
  642. return ret_val;
  643. }
  644. /** ixgbe_get_link_capabilities_x550em - Determines link capabilities
  645. * @hw: pointer to hardware structure
  646. * @speed: pointer to link speed
  647. * @autoneg: true when autoneg or autotry is enabled
  648. **/
  649. static s32 ixgbe_get_link_capabilities_X550em(struct ixgbe_hw *hw,
  650. ixgbe_link_speed *speed,
  651. bool *autoneg)
  652. {
  653. /* SFP */
  654. if (hw->phy.media_type == ixgbe_media_type_fiber) {
  655. /* CS4227 SFP must not enable auto-negotiation */
  656. *autoneg = false;
  657. if (hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
  658. hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1) {
  659. *speed = IXGBE_LINK_SPEED_1GB_FULL;
  660. return 0;
  661. }
  662. /* Link capabilities are based on SFP */
  663. if (hw->phy.multispeed_fiber)
  664. *speed = IXGBE_LINK_SPEED_10GB_FULL |
  665. IXGBE_LINK_SPEED_1GB_FULL;
  666. else
  667. *speed = IXGBE_LINK_SPEED_10GB_FULL;
  668. } else {
  669. *speed = IXGBE_LINK_SPEED_10GB_FULL |
  670. IXGBE_LINK_SPEED_1GB_FULL;
  671. *autoneg = true;
  672. }
  673. return 0;
  674. }
  675. /** ixgbe_write_iosf_sb_reg_x550 - Writes a value to specified register of the
  676. * IOSF device
  677. *
  678. * @hw: pointer to hardware structure
  679. * @reg_addr: 32 bit PHY register to write
  680. * @device_type: 3 bit device type
  681. * @data: Data to write to the register
  682. **/
  683. static s32 ixgbe_write_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr,
  684. u32 device_type, u32 data)
  685. {
  686. u32 i, command, error;
  687. command = ((reg_addr << IXGBE_SB_IOSF_CTRL_ADDR_SHIFT) |
  688. (device_type << IXGBE_SB_IOSF_CTRL_TARGET_SELECT_SHIFT));
  689. /* Write IOSF control register */
  690. IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL, command);
  691. /* Write IOSF data register */
  692. IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_DATA, data);
  693. /* Check every 10 usec to see if the address cycle completed.
  694. * The SB IOSF BUSY bit will clear when the operation is
  695. * complete
  696. */
  697. for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
  698. usleep_range(10, 20);
  699. command = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL);
  700. if ((command & IXGBE_SB_IOSF_CTRL_BUSY) == 0)
  701. break;
  702. }
  703. if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) {
  704. error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >>
  705. IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT;
  706. hw_dbg(hw, "Failed to write, error %x\n", error);
  707. return IXGBE_ERR_PHY;
  708. }
  709. if (i == IXGBE_MDIO_COMMAND_TIMEOUT) {
  710. hw_dbg(hw, "Write timed out\n");
  711. return IXGBE_ERR_PHY;
  712. }
  713. return 0;
  714. }
  715. /** ixgbe_setup_ixfi_x550em - Configure the KR PHY for iXFI mode.
  716. * @hw: pointer to hardware structure
  717. * @speed: the link speed to force
  718. *
  719. * Configures the integrated KR PHY to use iXFI mode. Used to connect an
  720. * internal and external PHY at a specific speed, without autonegotiation.
  721. **/
  722. static s32 ixgbe_setup_ixfi_x550em(struct ixgbe_hw *hw, ixgbe_link_speed *speed)
  723. {
  724. s32 status;
  725. u32 reg_val;
  726. /* Disable AN and force speed to 10G Serial. */
  727. status = ixgbe_read_iosf_sb_reg_x550(hw,
  728. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  729. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  730. if (status)
  731. return status;
  732. reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
  733. reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
  734. /* Select forced link speed for internal PHY. */
  735. switch (*speed) {
  736. case IXGBE_LINK_SPEED_10GB_FULL:
  737. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_10G;
  738. break;
  739. case IXGBE_LINK_SPEED_1GB_FULL:
  740. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_1G;
  741. break;
  742. default:
  743. /* Other link speeds are not supported by internal KR PHY. */
  744. return IXGBE_ERR_LINK_SETUP;
  745. }
  746. status = ixgbe_write_iosf_sb_reg_x550(hw,
  747. IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
  748. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  749. if (status)
  750. return status;
  751. /* Disable training protocol FSM. */
  752. status = ixgbe_read_iosf_sb_reg_x550(hw,
  753. IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
  754. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  755. if (status)
  756. return status;
  757. reg_val |= IXGBE_KRM_RX_TRN_LINKUP_CTRL_CONV_WO_PROTOCOL;
  758. status = ixgbe_write_iosf_sb_reg_x550(hw,
  759. IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
  760. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  761. if (status)
  762. return status;
  763. /* Disable Flex from training TXFFE. */
  764. status = ixgbe_read_iosf_sb_reg_x550(hw,
  765. IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id),
  766. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  767. if (status)
  768. return status;
  769. reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN;
  770. reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN;
  771. reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN;
  772. status = ixgbe_write_iosf_sb_reg_x550(hw,
  773. IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id),
  774. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  775. if (status)
  776. return status;
  777. status = ixgbe_read_iosf_sb_reg_x550(hw,
  778. IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id),
  779. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  780. if (status)
  781. return status;
  782. reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN;
  783. reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN;
  784. reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN;
  785. status = ixgbe_write_iosf_sb_reg_x550(hw,
  786. IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id),
  787. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  788. if (status)
  789. return status;
  790. /* Enable override for coefficients. */
  791. status = ixgbe_read_iosf_sb_reg_x550(hw,
  792. IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id),
  793. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  794. if (status)
  795. return status;
  796. reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_OVRRD_EN;
  797. reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CZERO_EN;
  798. reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CPLUS1_OVRRD_EN;
  799. reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CMINUS1_OVRRD_EN;
  800. status = ixgbe_write_iosf_sb_reg_x550(hw,
  801. IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id),
  802. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  803. if (status)
  804. return status;
  805. /* Toggle port SW reset by AN reset. */
  806. status = ixgbe_read_iosf_sb_reg_x550(hw,
  807. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  808. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  809. if (status)
  810. return status;
  811. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_RESTART;
  812. status = ixgbe_write_iosf_sb_reg_x550(hw,
  813. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  814. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  815. return status;
  816. }
  817. /** ixgbe_setup_kx4_x550em - Configure the KX4 PHY.
  818. * @hw: pointer to hardware structure
  819. *
  820. * Configures the integrated KX4 PHY.
  821. **/
  822. static s32 ixgbe_setup_kx4_x550em(struct ixgbe_hw *hw)
  823. {
  824. s32 status;
  825. u32 reg_val;
  826. status = ixgbe_read_iosf_sb_reg_x550(hw, IXGBE_KX4_LINK_CNTL_1,
  827. IXGBE_SB_IOSF_TARGET_KX4_PCS0 +
  828. hw->bus.lan_id, &reg_val);
  829. if (status)
  830. return status;
  831. reg_val &= ~(IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX4 |
  832. IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX);
  833. reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_ENABLE;
  834. /* Advertise 10G support. */
  835. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
  836. reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX4;
  837. /* Advertise 1G support. */
  838. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
  839. reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX;
  840. /* Restart auto-negotiation. */
  841. reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_RESTART;
  842. status = ixgbe_write_iosf_sb_reg_x550(hw, IXGBE_KX4_LINK_CNTL_1,
  843. IXGBE_SB_IOSF_TARGET_KX4_PCS0 +
  844. hw->bus.lan_id, reg_val);
  845. return status;
  846. }
  847. /** ixgbe_setup_kr_x550em - Configure the KR PHY.
  848. * @hw: pointer to hardware structure
  849. *
  850. * Configures the integrated KR PHY.
  851. **/
  852. static s32 ixgbe_setup_kr_x550em(struct ixgbe_hw *hw)
  853. {
  854. s32 status;
  855. u32 reg_val;
  856. status = ixgbe_read_iosf_sb_reg_x550(hw,
  857. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  858. IXGBE_SB_IOSF_TARGET_KR_PHY, &reg_val);
  859. if (status)
  860. return status;
  861. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
  862. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_FEC_REQ;
  863. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_FEC;
  864. reg_val &= ~(IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR |
  865. IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX);
  866. /* Advertise 10G support. */
  867. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
  868. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR;
  869. /* Advertise 1G support. */
  870. if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
  871. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX;
  872. /* Restart auto-negotiation. */
  873. reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_RESTART;
  874. status = ixgbe_write_iosf_sb_reg_x550(hw,
  875. IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
  876. IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
  877. return status;
  878. }
  879. /** ixgbe_setup_internal_phy_x550em - Configure integrated KR PHY
  880. * @hw: point to hardware structure
  881. *
  882. * Configures the integrated KR PHY to talk to the external PHY. The base
  883. * driver will call this function when it gets notification via interrupt from
  884. * the external PHY. This function forces the internal PHY into iXFI mode at
  885. * the correct speed.
  886. *
  887. * A return of a non-zero value indicates an error, and the base driver should
  888. * not report link up.
  889. **/
  890. static s32 ixgbe_setup_internal_phy_x550em(struct ixgbe_hw *hw)
  891. {
  892. u32 status;
  893. u16 lasi, autoneg_status, speed;
  894. ixgbe_link_speed force_speed;
  895. /* Verify that the external link status has changed */
  896. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_XENPAK_LASI_STATUS,
  897. IXGBE_MDIO_PMA_PMD_DEV_TYPE, &lasi);
  898. if (status)
  899. return status;
  900. /* If there was no change in link status, we can just exit */
  901. if (!(lasi & IXGBE_XENPAK_LASI_LINK_STATUS_ALARM))
  902. return 0;
  903. /* we read this twice back to back to indicate current status */
  904. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
  905. IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
  906. &autoneg_status);
  907. if (status)
  908. return status;
  909. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
  910. IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
  911. &autoneg_status);
  912. if (status)
  913. return status;
  914. /* If link is not up return an error indicating treat link as down */
  915. if (!(autoneg_status & IXGBE_MDIO_AUTO_NEG_LINK_STATUS))
  916. return IXGBE_ERR_INVALID_LINK_SETTINGS;
  917. status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_STAT,
  918. IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
  919. &speed);
  920. /* clear everything but the speed and duplex bits */
  921. speed &= IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_MASK;
  922. switch (speed) {
  923. case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_10GB_FULL:
  924. force_speed = IXGBE_LINK_SPEED_10GB_FULL;
  925. break;
  926. case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_1GB_FULL:
  927. force_speed = IXGBE_LINK_SPEED_1GB_FULL;
  928. break;
  929. default:
  930. /* Internal PHY does not support anything else */
  931. return IXGBE_ERR_INVALID_LINK_SETTINGS;
  932. }
  933. return ixgbe_setup_ixfi_x550em(hw, &force_speed);
  934. }
  935. /** ixgbe_init_phy_ops_X550em - PHY/SFP specific init
  936. * @hw: pointer to hardware structure
  937. *
  938. * Initialize any function pointers that were not able to be
  939. * set during init_shared_code because the PHY/SFP type was
  940. * not known. Perform the SFP init if necessary.
  941. **/
  942. static s32 ixgbe_init_phy_ops_X550em(struct ixgbe_hw *hw)
  943. {
  944. struct ixgbe_phy_info *phy = &hw->phy;
  945. s32 ret_val;
  946. u32 esdp;
  947. if (hw->device_id == IXGBE_DEV_ID_X550EM_X_SFP) {
  948. esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
  949. phy->phy_semaphore_mask = IXGBE_GSSR_SHARED_I2C_SM;
  950. if (hw->bus.lan_id) {
  951. esdp &= ~(IXGBE_ESDP_SDP1_NATIVE | IXGBE_ESDP_SDP1);
  952. esdp |= IXGBE_ESDP_SDP1_DIR;
  953. }
  954. esdp &= ~(IXGBE_ESDP_SDP0_NATIVE | IXGBE_ESDP_SDP0_DIR);
  955. IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
  956. }
  957. /* Identify the PHY or SFP module */
  958. ret_val = phy->ops.identify(hw);
  959. /* Setup function pointers based on detected SFP module and speeds */
  960. ixgbe_init_mac_link_ops_X550em(hw);
  961. if (phy->sfp_type != ixgbe_sfp_type_unknown)
  962. phy->ops.reset = NULL;
  963. /* Set functions pointers based on phy type */
  964. switch (hw->phy.type) {
  965. case ixgbe_phy_x550em_kx4:
  966. phy->ops.setup_link = ixgbe_setup_kx4_x550em;
  967. phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
  968. phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
  969. break;
  970. case ixgbe_phy_x550em_kr:
  971. phy->ops.setup_link = ixgbe_setup_kr_x550em;
  972. phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
  973. phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
  974. break;
  975. case ixgbe_phy_x550em_ext_t:
  976. phy->ops.setup_internal_link = ixgbe_setup_internal_phy_x550em;
  977. break;
  978. default:
  979. break;
  980. }
  981. return ret_val;
  982. }
  983. /** ixgbe_get_media_type_X550em - Get media type
  984. * @hw: pointer to hardware structure
  985. *
  986. * Returns the media type (fiber, copper, backplane)
  987. *
  988. */
  989. static enum ixgbe_media_type ixgbe_get_media_type_X550em(struct ixgbe_hw *hw)
  990. {
  991. enum ixgbe_media_type media_type;
  992. /* Detect if there is a copper PHY attached. */
  993. switch (hw->device_id) {
  994. case IXGBE_DEV_ID_X550EM_X_KR:
  995. case IXGBE_DEV_ID_X550EM_X_KX4:
  996. media_type = ixgbe_media_type_backplane;
  997. break;
  998. case IXGBE_DEV_ID_X550EM_X_SFP:
  999. media_type = ixgbe_media_type_fiber;
  1000. break;
  1001. case IXGBE_DEV_ID_X550EM_X_1G_T:
  1002. case IXGBE_DEV_ID_X550EM_X_10G_T:
  1003. media_type = ixgbe_media_type_copper;
  1004. break;
  1005. default:
  1006. media_type = ixgbe_media_type_unknown;
  1007. break;
  1008. }
  1009. return media_type;
  1010. }
  1011. /** ixgbe_init_ext_t_x550em - Start (unstall) the external Base T PHY.
  1012. ** @hw: pointer to hardware structure
  1013. **/
  1014. static s32 ixgbe_init_ext_t_x550em(struct ixgbe_hw *hw)
  1015. {
  1016. u32 status;
  1017. u16 reg;
  1018. u32 retries = 2;
  1019. do {
  1020. /* decrement retries counter and exit if we hit 0 */
  1021. if (retries < 1) {
  1022. hw_dbg(hw, "External PHY not yet finished resetting.");
  1023. return IXGBE_ERR_PHY;
  1024. }
  1025. retries--;
  1026. status = hw->phy.ops.read_reg(hw,
  1027. IXGBE_MDIO_TX_VENDOR_ALARMS_3,
  1028. IXGBE_MDIO_PMA_PMD_DEV_TYPE,
  1029. &reg);
  1030. if (status)
  1031. return status;
  1032. /* Verify PHY FW reset has completed */
  1033. } while ((reg & IXGBE_MDIO_TX_VENDOR_ALARMS_3_RST_MASK) != 1);
  1034. /* Set port to low power mode */
  1035. status = hw->phy.ops.read_reg(hw,
  1036. IXGBE_MDIO_VENDOR_SPECIFIC_1_CONTROL,
  1037. IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
  1038. &reg);
  1039. if (status)
  1040. return status;
  1041. /* Enable the transmitter */
  1042. status = hw->phy.ops.read_reg(hw,
  1043. IXGBE_MDIO_PMD_STD_TX_DISABLE_CNTR,
  1044. IXGBE_MDIO_PMA_PMD_DEV_TYPE,
  1045. &reg);
  1046. if (status)
  1047. return status;
  1048. reg &= ~IXGBE_MDIO_PMD_GLOBAL_TX_DISABLE;
  1049. status = hw->phy.ops.write_reg(hw,
  1050. IXGBE_MDIO_PMD_STD_TX_DISABLE_CNTR,
  1051. IXGBE_MDIO_PMA_PMD_DEV_TYPE,
  1052. reg);
  1053. if (status)
  1054. return status;
  1055. /* Un-stall the PHY FW */
  1056. status = hw->phy.ops.read_reg(hw,
  1057. IXGBE_MDIO_GLOBAL_RES_PR_10,
  1058. IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
  1059. &reg);
  1060. if (status)
  1061. return status;
  1062. reg &= ~IXGBE_MDIO_POWER_UP_STALL;
  1063. status = hw->phy.ops.write_reg(hw,
  1064. IXGBE_MDIO_GLOBAL_RES_PR_10,
  1065. IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
  1066. reg);
  1067. return status;
  1068. }
  1069. /** ixgbe_reset_hw_X550em - Perform hardware reset
  1070. ** @hw: pointer to hardware structure
  1071. **
  1072. ** Resets the hardware by resetting the transmit and receive units, masks
  1073. ** and clears all interrupts, perform a PHY reset, and perform a link (MAC)
  1074. ** reset.
  1075. **/
  1076. static s32 ixgbe_reset_hw_X550em(struct ixgbe_hw *hw)
  1077. {
  1078. ixgbe_link_speed link_speed;
  1079. s32 status;
  1080. u32 ctrl = 0;
  1081. u32 i;
  1082. bool link_up = false;
  1083. /* Call adapter stop to disable Tx/Rx and clear interrupts */
  1084. status = hw->mac.ops.stop_adapter(hw);
  1085. if (status)
  1086. return status;
  1087. /* flush pending Tx transactions */
  1088. ixgbe_clear_tx_pending(hw);
  1089. /* PHY ops must be identified and initialized prior to reset */
  1090. /* Identify PHY and related function pointers */
  1091. status = hw->phy.ops.init(hw);
  1092. /* start the external PHY */
  1093. if (hw->phy.type == ixgbe_phy_x550em_ext_t) {
  1094. status = ixgbe_init_ext_t_x550em(hw);
  1095. if (status)
  1096. return status;
  1097. }
  1098. /* Setup SFP module if there is one present. */
  1099. if (hw->phy.sfp_setup_needed) {
  1100. status = hw->mac.ops.setup_sfp(hw);
  1101. hw->phy.sfp_setup_needed = false;
  1102. }
  1103. /* Reset PHY */
  1104. if (!hw->phy.reset_disable && hw->phy.ops.reset)
  1105. hw->phy.ops.reset(hw);
  1106. mac_reset_top:
  1107. /* Issue global reset to the MAC. Needs to be SW reset if link is up.
  1108. * If link reset is used when link is up, it might reset the PHY when
  1109. * mng is using it. If link is down or the flag to force full link
  1110. * reset is set, then perform link reset.
  1111. */
  1112. ctrl = IXGBE_CTRL_LNK_RST;
  1113. if (!hw->force_full_reset) {
  1114. hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
  1115. if (link_up)
  1116. ctrl = IXGBE_CTRL_RST;
  1117. }
  1118. ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL);
  1119. IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
  1120. IXGBE_WRITE_FLUSH(hw);
  1121. /* Poll for reset bit to self-clear meaning reset is complete */
  1122. for (i = 0; i < 10; i++) {
  1123. udelay(1);
  1124. ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
  1125. if (!(ctrl & IXGBE_CTRL_RST_MASK))
  1126. break;
  1127. }
  1128. if (ctrl & IXGBE_CTRL_RST_MASK) {
  1129. status = IXGBE_ERR_RESET_FAILED;
  1130. hw_dbg(hw, "Reset polling failed to complete.\n");
  1131. }
  1132. msleep(50);
  1133. /* Double resets are required for recovery from certain error
  1134. * clear the multicast table. Also reset num_rar_entries to 128,
  1135. * since we modify this value when programming the SAN MAC address.
  1136. */
  1137. if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
  1138. hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
  1139. goto mac_reset_top;
  1140. }
  1141. /* Store the permanent mac address */
  1142. hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
  1143. /* Store MAC address from RAR0, clear receive address registers, and
  1144. * clear the multicast table. Also reset num_rar_entries to 128,
  1145. * since we modify this value when programming the SAN MAC address.
  1146. */
  1147. hw->mac.num_rar_entries = 128;
  1148. hw->mac.ops.init_rx_addrs(hw);
  1149. return status;
  1150. }
  1151. /** ixgbe_set_ethertype_anti_spoofing_X550 - Enable/Disable Ethertype
  1152. * anti-spoofing
  1153. * @hw: pointer to hardware structure
  1154. * @enable: enable or disable switch for Ethertype anti-spoofing
  1155. * @vf: Virtual Function pool - VF Pool to set for Ethertype anti-spoofing
  1156. **/
  1157. static void ixgbe_set_ethertype_anti_spoofing_X550(struct ixgbe_hw *hw,
  1158. bool enable, int vf)
  1159. {
  1160. int vf_target_reg = vf >> 3;
  1161. int vf_target_shift = vf % 8 + IXGBE_SPOOF_ETHERTYPEAS_SHIFT;
  1162. u32 pfvfspoof;
  1163. pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
  1164. if (enable)
  1165. pfvfspoof |= (1 << vf_target_shift);
  1166. else
  1167. pfvfspoof &= ~(1 << vf_target_shift);
  1168. IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
  1169. }
  1170. /** ixgbe_set_source_address_pruning_X550 - Enable/Disbale src address pruning
  1171. * @hw: pointer to hardware structure
  1172. * @enable: enable or disable source address pruning
  1173. * @pool: Rx pool to set source address pruning for
  1174. **/
  1175. static void ixgbe_set_source_address_pruning_X550(struct ixgbe_hw *hw,
  1176. bool enable,
  1177. unsigned int pool)
  1178. {
  1179. u64 pfflp;
  1180. /* max rx pool is 63 */
  1181. if (pool > 63)
  1182. return;
  1183. pfflp = (u64)IXGBE_READ_REG(hw, IXGBE_PFFLPL);
  1184. pfflp |= (u64)IXGBE_READ_REG(hw, IXGBE_PFFLPH) << 32;
  1185. if (enable)
  1186. pfflp |= (1ULL << pool);
  1187. else
  1188. pfflp &= ~(1ULL << pool);
  1189. IXGBE_WRITE_REG(hw, IXGBE_PFFLPL, (u32)pfflp);
  1190. IXGBE_WRITE_REG(hw, IXGBE_PFFLPH, (u32)(pfflp >> 32));
  1191. }
  1192. #define X550_COMMON_MAC \
  1193. .init_hw = &ixgbe_init_hw_generic, \
  1194. .start_hw = &ixgbe_start_hw_X540, \
  1195. .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic, \
  1196. .enable_rx_dma = &ixgbe_enable_rx_dma_generic, \
  1197. .get_mac_addr = &ixgbe_get_mac_addr_generic, \
  1198. .get_device_caps = &ixgbe_get_device_caps_generic, \
  1199. .stop_adapter = &ixgbe_stop_adapter_generic, \
  1200. .get_bus_info = &ixgbe_get_bus_info_generic, \
  1201. .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie, \
  1202. .read_analog_reg8 = NULL, \
  1203. .write_analog_reg8 = NULL, \
  1204. .set_rxpba = &ixgbe_set_rxpba_generic, \
  1205. .check_link = &ixgbe_check_mac_link_generic, \
  1206. .led_on = &ixgbe_led_on_generic, \
  1207. .led_off = &ixgbe_led_off_generic, \
  1208. .blink_led_start = &ixgbe_blink_led_start_X540, \
  1209. .blink_led_stop = &ixgbe_blink_led_stop_X540, \
  1210. .set_rar = &ixgbe_set_rar_generic, \
  1211. .clear_rar = &ixgbe_clear_rar_generic, \
  1212. .set_vmdq = &ixgbe_set_vmdq_generic, \
  1213. .set_vmdq_san_mac = &ixgbe_set_vmdq_san_mac_generic, \
  1214. .clear_vmdq = &ixgbe_clear_vmdq_generic, \
  1215. .init_rx_addrs = &ixgbe_init_rx_addrs_generic, \
  1216. .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic, \
  1217. .enable_mc = &ixgbe_enable_mc_generic, \
  1218. .disable_mc = &ixgbe_disable_mc_generic, \
  1219. .clear_vfta = &ixgbe_clear_vfta_generic, \
  1220. .set_vfta = &ixgbe_set_vfta_generic, \
  1221. .fc_enable = &ixgbe_fc_enable_generic, \
  1222. .set_fw_drv_ver = &ixgbe_set_fw_drv_ver_generic, \
  1223. .init_uta_tables = &ixgbe_init_uta_tables_generic, \
  1224. .set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing, \
  1225. .set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing, \
  1226. .set_source_address_pruning = \
  1227. &ixgbe_set_source_address_pruning_X550, \
  1228. .set_ethertype_anti_spoofing = \
  1229. &ixgbe_set_ethertype_anti_spoofing_X550, \
  1230. .acquire_swfw_sync = &ixgbe_acquire_swfw_sync_X540, \
  1231. .release_swfw_sync = &ixgbe_release_swfw_sync_X540, \
  1232. .disable_rx_buff = &ixgbe_disable_rx_buff_generic, \
  1233. .enable_rx_buff = &ixgbe_enable_rx_buff_generic, \
  1234. .get_thermal_sensor_data = NULL, \
  1235. .init_thermal_sensor_thresh = NULL, \
  1236. .prot_autoc_read = &prot_autoc_read_generic, \
  1237. .prot_autoc_write = &prot_autoc_write_generic, \
  1238. .enable_rx = &ixgbe_enable_rx_generic, \
  1239. .disable_rx = &ixgbe_disable_rx_x550, \
  1240. static struct ixgbe_mac_operations mac_ops_X550 = {
  1241. X550_COMMON_MAC
  1242. .reset_hw = &ixgbe_reset_hw_X540,
  1243. .get_media_type = &ixgbe_get_media_type_X540,
  1244. .get_san_mac_addr = &ixgbe_get_san_mac_addr_generic,
  1245. .get_wwn_prefix = &ixgbe_get_wwn_prefix_generic,
  1246. .setup_link = &ixgbe_setup_mac_link_X540,
  1247. .get_link_capabilities = &ixgbe_get_copper_link_capabilities_generic,
  1248. .setup_sfp = NULL,
  1249. };
  1250. static struct ixgbe_mac_operations mac_ops_X550EM_x = {
  1251. X550_COMMON_MAC
  1252. .reset_hw = &ixgbe_reset_hw_X550em,
  1253. .get_media_type = &ixgbe_get_media_type_X550em,
  1254. .get_san_mac_addr = NULL,
  1255. .get_wwn_prefix = NULL,
  1256. .setup_link = NULL, /* defined later */
  1257. .get_link_capabilities = &ixgbe_get_link_capabilities_X550em,
  1258. .setup_sfp = ixgbe_setup_sfp_modules_X550em,
  1259. };
  1260. #define X550_COMMON_EEP \
  1261. .read = &ixgbe_read_ee_hostif_X550, \
  1262. .read_buffer = &ixgbe_read_ee_hostif_buffer_X550, \
  1263. .write = &ixgbe_write_ee_hostif_X550, \
  1264. .write_buffer = &ixgbe_write_ee_hostif_buffer_X550, \
  1265. .validate_checksum = &ixgbe_validate_eeprom_checksum_X550, \
  1266. .update_checksum = &ixgbe_update_eeprom_checksum_X550, \
  1267. .calc_checksum = &ixgbe_calc_eeprom_checksum_X550, \
  1268. static struct ixgbe_eeprom_operations eeprom_ops_X550 = {
  1269. X550_COMMON_EEP
  1270. .init_params = &ixgbe_init_eeprom_params_X550,
  1271. };
  1272. static struct ixgbe_eeprom_operations eeprom_ops_X550EM_x = {
  1273. X550_COMMON_EEP
  1274. .init_params = &ixgbe_init_eeprom_params_X540,
  1275. };
  1276. #define X550_COMMON_PHY \
  1277. .identify_sfp = &ixgbe_identify_module_generic, \
  1278. .reset = NULL, \
  1279. .setup_link_speed = &ixgbe_setup_phy_link_speed_generic, \
  1280. .read_i2c_byte = &ixgbe_read_i2c_byte_generic, \
  1281. .write_i2c_byte = &ixgbe_write_i2c_byte_generic, \
  1282. .read_i2c_sff8472 = &ixgbe_read_i2c_sff8472_generic, \
  1283. .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic, \
  1284. .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic, \
  1285. .check_overtemp = &ixgbe_tn_check_overtemp, \
  1286. .get_firmware_version = &ixgbe_get_phy_firmware_version_generic,
  1287. static struct ixgbe_phy_operations phy_ops_X550 = {
  1288. X550_COMMON_PHY
  1289. .init = NULL,
  1290. .identify = &ixgbe_identify_phy_generic,
  1291. .read_reg = &ixgbe_read_phy_reg_generic,
  1292. .write_reg = &ixgbe_write_phy_reg_generic,
  1293. .setup_link = &ixgbe_setup_phy_link_generic,
  1294. .read_i2c_combined = &ixgbe_read_i2c_combined_generic,
  1295. .write_i2c_combined = &ixgbe_write_i2c_combined_generic,
  1296. };
  1297. static struct ixgbe_phy_operations phy_ops_X550EM_x = {
  1298. X550_COMMON_PHY
  1299. .init = &ixgbe_init_phy_ops_X550em,
  1300. .identify = &ixgbe_identify_phy_x550em,
  1301. .read_reg = NULL, /* defined later */
  1302. .write_reg = NULL, /* defined later */
  1303. .setup_link = NULL, /* defined later */
  1304. };
  1305. struct ixgbe_info ixgbe_X550_info = {
  1306. .mac = ixgbe_mac_X550,
  1307. .get_invariants = &ixgbe_get_invariants_X540,
  1308. .mac_ops = &mac_ops_X550,
  1309. .eeprom_ops = &eeprom_ops_X550,
  1310. .phy_ops = &phy_ops_X550,
  1311. .mbx_ops = &mbx_ops_generic,
  1312. };
  1313. struct ixgbe_info ixgbe_X550EM_x_info = {
  1314. .mac = ixgbe_mac_X550EM_x,
  1315. .get_invariants = &ixgbe_get_invariants_X540,
  1316. .mac_ops = &mac_ops_X550EM_x,
  1317. .eeprom_ops = &eeprom_ops_X550EM_x,
  1318. .phy_ops = &phy_ops_X550EM_x,
  1319. .mbx_ops = &mbx_ops_generic,
  1320. };