ixgbe_x550.c 58 KB

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