1 /*******************************************************************************
3 * Intel 10 Gigabit PCI Express Linux driver
4 * Copyright(c) 1999 - 2016 Intel Corporation.
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.
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
15 * The full GNU General Public License is included in this distribution in
16 * the file called "COPYING".
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
23 ******************************************************************************/
24 #include "ixgbe_x540.h"
25 #include "ixgbe_type.h"
26 #include "ixgbe_common.h"
27 #include "ixgbe_phy.h"
29 static s32 ixgbe_setup_kr_speed_x550em(struct ixgbe_hw *, ixgbe_link_speed);
30 static s32 ixgbe_setup_fc_x550em(struct ixgbe_hw *);
32 static s32 ixgbe_get_invariants_X550_x(struct ixgbe_hw *hw)
34 struct ixgbe_mac_info *mac = &hw->mac;
35 struct ixgbe_phy_info *phy = &hw->phy;
37 /* Start with X540 invariants, since so simular */
38 ixgbe_get_invariants_X540(hw);
40 if (mac->ops.get_media_type(hw) != ixgbe_media_type_copper)
41 phy->ops.set_phy_power = NULL;
46 /** ixgbe_setup_mux_ctl - Setup ESDP register for I2C mux control
47 * @hw: pointer to hardware structure
49 static void ixgbe_setup_mux_ctl(struct ixgbe_hw *hw)
51 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
54 esdp &= ~(IXGBE_ESDP_SDP1_NATIVE | IXGBE_ESDP_SDP1);
55 esdp |= IXGBE_ESDP_SDP1_DIR;
57 esdp &= ~(IXGBE_ESDP_SDP0_NATIVE | IXGBE_ESDP_SDP0_DIR);
58 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
59 IXGBE_WRITE_FLUSH(hw);
63 * ixgbe_read_cs4227 - Read CS4227 register
64 * @hw: pointer to hardware structure
65 * @reg: register number to write
66 * @value: pointer to receive value read
70 static s32 ixgbe_read_cs4227(struct ixgbe_hw *hw, u16 reg, u16 *value)
72 return hw->phy.ops.read_i2c_combined_unlocked(hw, IXGBE_CS4227, reg,
77 * ixgbe_write_cs4227 - Write CS4227 register
78 * @hw: pointer to hardware structure
79 * @reg: register number to write
80 * @value: value to write to register
84 static s32 ixgbe_write_cs4227(struct ixgbe_hw *hw, u16 reg, u16 value)
86 return hw->phy.ops.write_i2c_combined_unlocked(hw, IXGBE_CS4227, reg,
91 * ixgbe_read_pe - Read register from port expander
92 * @hw: pointer to hardware structure
93 * @reg: register number to read
94 * @value: pointer to receive read value
98 static s32 ixgbe_read_pe(struct ixgbe_hw *hw, u8 reg, u8 *value)
102 status = ixgbe_read_i2c_byte_generic_unlocked(hw, reg, IXGBE_PE, value);
104 hw_err(hw, "port expander access failed with %d\n", status);
109 * ixgbe_write_pe - Write register to port expander
110 * @hw: pointer to hardware structure
111 * @reg: register number to write
112 * @value: value to write
114 * Returns status code
116 static s32 ixgbe_write_pe(struct ixgbe_hw *hw, u8 reg, u8 value)
120 status = ixgbe_write_i2c_byte_generic_unlocked(hw, reg, IXGBE_PE,
123 hw_err(hw, "port expander access failed with %d\n", status);
128 * ixgbe_reset_cs4227 - Reset CS4227 using port expander
129 * @hw: pointer to hardware structure
131 * This function assumes that the caller has acquired the proper semaphore.
134 static s32 ixgbe_reset_cs4227(struct ixgbe_hw *hw)
141 /* Trigger hard reset. */
142 status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, ®);
145 reg |= IXGBE_PE_BIT1;
146 status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
150 status = ixgbe_read_pe(hw, IXGBE_PE_CONFIG, ®);
153 reg &= ~IXGBE_PE_BIT1;
154 status = ixgbe_write_pe(hw, IXGBE_PE_CONFIG, reg);
158 status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, ®);
161 reg &= ~IXGBE_PE_BIT1;
162 status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
166 usleep_range(IXGBE_CS4227_RESET_HOLD, IXGBE_CS4227_RESET_HOLD + 100);
168 status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, ®);
171 reg |= IXGBE_PE_BIT1;
172 status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
176 /* Wait for the reset to complete. */
177 msleep(IXGBE_CS4227_RESET_DELAY);
178 for (retry = 0; retry < IXGBE_CS4227_RETRIES; retry++) {
179 status = ixgbe_read_cs4227(hw, IXGBE_CS4227_EFUSE_STATUS,
181 if (!status && value == IXGBE_CS4227_EEPROM_LOAD_OK)
183 msleep(IXGBE_CS4227_CHECK_DELAY);
185 if (retry == IXGBE_CS4227_RETRIES) {
186 hw_err(hw, "CS4227 reset did not complete\n");
187 return IXGBE_ERR_PHY;
190 status = ixgbe_read_cs4227(hw, IXGBE_CS4227_EEPROM_STATUS, &value);
191 if (status || !(value & IXGBE_CS4227_EEPROM_LOAD_OK)) {
192 hw_err(hw, "CS4227 EEPROM did not load successfully\n");
193 return IXGBE_ERR_PHY;
200 * ixgbe_check_cs4227 - Check CS4227 and reset as needed
201 * @hw: pointer to hardware structure
203 static void ixgbe_check_cs4227(struct ixgbe_hw *hw)
205 u32 swfw_mask = hw->phy.phy_semaphore_mask;
210 for (retry = 0; retry < IXGBE_CS4227_RETRIES; retry++) {
211 status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
213 hw_err(hw, "semaphore failed with %d\n", status);
214 msleep(IXGBE_CS4227_CHECK_DELAY);
218 /* Get status of reset flow. */
219 status = ixgbe_read_cs4227(hw, IXGBE_CS4227_SCRATCH, &value);
220 if (!status && value == IXGBE_CS4227_RESET_COMPLETE)
223 if (status || value != IXGBE_CS4227_RESET_PENDING)
226 /* Reset is pending. Wait and check again. */
227 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
228 msleep(IXGBE_CS4227_CHECK_DELAY);
230 /* If still pending, assume other instance failed. */
231 if (retry == IXGBE_CS4227_RETRIES) {
232 status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
234 hw_err(hw, "semaphore failed with %d\n", status);
239 /* Reset the CS4227. */
240 status = ixgbe_reset_cs4227(hw);
242 hw_err(hw, "CS4227 reset failed: %d", status);
246 /* Reset takes so long, temporarily release semaphore in case the
247 * other driver instance is waiting for the reset indication.
249 ixgbe_write_cs4227(hw, IXGBE_CS4227_SCRATCH,
250 IXGBE_CS4227_RESET_PENDING);
251 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
252 usleep_range(10000, 12000);
253 status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
255 hw_err(hw, "semaphore failed with %d", status);
259 /* Record completion for next time. */
260 status = ixgbe_write_cs4227(hw, IXGBE_CS4227_SCRATCH,
261 IXGBE_CS4227_RESET_COMPLETE);
264 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
265 msleep(hw->eeprom.semaphore_delay);
268 /** ixgbe_identify_phy_x550em - Get PHY type based on device id
269 * @hw: pointer to hardware structure
273 static s32 ixgbe_identify_phy_x550em(struct ixgbe_hw *hw)
275 switch (hw->device_id) {
276 case IXGBE_DEV_ID_X550EM_X_SFP:
277 /* set up for CS4227 usage */
278 hw->phy.phy_semaphore_mask = IXGBE_GSSR_SHARED_I2C_SM;
279 ixgbe_setup_mux_ctl(hw);
280 ixgbe_check_cs4227(hw);
281 return ixgbe_identify_module_generic(hw);
282 case IXGBE_DEV_ID_X550EM_X_KX4:
283 hw->phy.type = ixgbe_phy_x550em_kx4;
285 case IXGBE_DEV_ID_X550EM_X_KR:
286 hw->phy.type = ixgbe_phy_x550em_kr;
288 case IXGBE_DEV_ID_X550EM_X_1G_T:
289 case IXGBE_DEV_ID_X550EM_X_10G_T:
290 return ixgbe_identify_phy_generic(hw);
297 static s32 ixgbe_read_phy_reg_x550em(struct ixgbe_hw *hw, u32 reg_addr,
298 u32 device_type, u16 *phy_data)
300 return IXGBE_NOT_IMPLEMENTED;
303 static s32 ixgbe_write_phy_reg_x550em(struct ixgbe_hw *hw, u32 reg_addr,
304 u32 device_type, u16 phy_data)
306 return IXGBE_NOT_IMPLEMENTED;
309 /** ixgbe_init_eeprom_params_X550 - Initialize EEPROM params
310 * @hw: pointer to hardware structure
312 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
313 * ixgbe_hw struct in order to set up EEPROM access.
315 static s32 ixgbe_init_eeprom_params_X550(struct ixgbe_hw *hw)
317 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
321 if (eeprom->type == ixgbe_eeprom_uninitialized) {
322 eeprom->semaphore_delay = 10;
323 eeprom->type = ixgbe_flash;
325 eec = IXGBE_READ_REG(hw, IXGBE_EEC(hw));
326 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
327 IXGBE_EEC_SIZE_SHIFT);
328 eeprom->word_size = 1 << (eeprom_size +
329 IXGBE_EEPROM_WORD_SIZE_SHIFT);
331 hw_dbg(hw, "Eeprom params: type = %d, size = %d\n",
332 eeprom->type, eeprom->word_size);
339 * ixgbe_iosf_wait - Wait for IOSF command completion
340 * @hw: pointer to hardware structure
341 * @ctrl: pointer to location to receive final IOSF control value
343 * Return: failing status on timeout
345 * Note: ctrl can be NULL if the IOSF control register value is not needed
347 static s32 ixgbe_iosf_wait(struct ixgbe_hw *hw, u32 *ctrl)
351 /* Check every 10 usec to see if the address cycle completed.
352 * The SB IOSF BUSY bit will clear when the operation is
355 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
356 command = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL);
357 if (!(command & IXGBE_SB_IOSF_CTRL_BUSY))
363 if (i == IXGBE_MDIO_COMMAND_TIMEOUT) {
364 hw_dbg(hw, "IOSF wait timed out\n");
365 return IXGBE_ERR_PHY;
371 /** ixgbe_read_iosf_sb_reg_x550 - Writes a value to specified register of the
373 * @hw: pointer to hardware structure
374 * @reg_addr: 32 bit PHY register to write
375 * @device_type: 3 bit device type
376 * @phy_data: Pointer to read data from the register
378 static s32 ixgbe_read_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr,
379 u32 device_type, u32 *data)
381 u32 gssr = IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_PHY0_SM;
385 ret = hw->mac.ops.acquire_swfw_sync(hw, gssr);
389 ret = ixgbe_iosf_wait(hw, NULL);
393 command = ((reg_addr << IXGBE_SB_IOSF_CTRL_ADDR_SHIFT) |
394 (device_type << IXGBE_SB_IOSF_CTRL_TARGET_SELECT_SHIFT));
396 /* Write IOSF control register */
397 IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL, command);
399 ret = ixgbe_iosf_wait(hw, &command);
401 if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) {
402 error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >>
403 IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT;
404 hw_dbg(hw, "Failed to read, error %x\n", error);
405 return IXGBE_ERR_PHY;
409 *data = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_DATA);
412 hw->mac.ops.release_swfw_sync(hw, gssr);
416 /** ixgbe_read_ee_hostif_data_X550 - Read EEPROM word using a host interface
417 * command assuming that the semaphore is already obtained.
418 * @hw: pointer to hardware structure
419 * @offset: offset of word in the EEPROM to read
420 * @data: word read from the EEPROM
422 * Reads a 16 bit word from the EEPROM using the hostif.
424 static s32 ixgbe_read_ee_hostif_data_X550(struct ixgbe_hw *hw, u16 offset,
428 struct ixgbe_hic_read_shadow_ram buffer;
430 buffer.hdr.req.cmd = FW_READ_SHADOW_RAM_CMD;
431 buffer.hdr.req.buf_lenh = 0;
432 buffer.hdr.req.buf_lenl = FW_READ_SHADOW_RAM_LEN;
433 buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
435 /* convert offset from words to bytes */
436 buffer.address = cpu_to_be32(offset * 2);
438 buffer.length = cpu_to_be16(sizeof(u16));
440 status = ixgbe_host_interface_command(hw, (u32 *)&buffer,
442 IXGBE_HI_COMMAND_TIMEOUT, false);
446 *data = (u16)IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG,
452 /** ixgbe_read_ee_hostif_buffer_X550- Read EEPROM word(s) using hostif
453 * @hw: pointer to hardware structure
454 * @offset: offset of word in the EEPROM to read
455 * @words: number of words
456 * @data: word(s) read from the EEPROM
458 * Reads a 16 bit word(s) from the EEPROM using the hostif.
460 static s32 ixgbe_read_ee_hostif_buffer_X550(struct ixgbe_hw *hw,
461 u16 offset, u16 words, u16 *data)
463 struct ixgbe_hic_read_shadow_ram buffer;
464 u32 current_word = 0;
469 /* Take semaphore for the entire operation. */
470 status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
472 hw_dbg(hw, "EEPROM read buffer - semaphore failed\n");
477 if (words > FW_MAX_READ_BUFFER_SIZE / 2)
478 words_to_read = FW_MAX_READ_BUFFER_SIZE / 2;
480 words_to_read = words;
482 buffer.hdr.req.cmd = FW_READ_SHADOW_RAM_CMD;
483 buffer.hdr.req.buf_lenh = 0;
484 buffer.hdr.req.buf_lenl = FW_READ_SHADOW_RAM_LEN;
485 buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
487 /* convert offset from words to bytes */
488 buffer.address = cpu_to_be32((offset + current_word) * 2);
489 buffer.length = cpu_to_be16(words_to_read * 2);
491 status = ixgbe_host_interface_command(hw, (u32 *)&buffer,
493 IXGBE_HI_COMMAND_TIMEOUT,
496 hw_dbg(hw, "Host interface command failed\n");
500 for (i = 0; i < words_to_read; i++) {
501 u32 reg = IXGBE_FLEX_MNG + (FW_NVM_DATA_OFFSET << 2) +
503 u32 value = IXGBE_READ_REG(hw, reg);
505 data[current_word] = (u16)(value & 0xffff);
508 if (i < words_to_read) {
510 data[current_word] = (u16)(value & 0xffff);
514 words -= words_to_read;
518 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
522 /** ixgbe_checksum_ptr_x550 - Checksum one pointer region
523 * @hw: pointer to hardware structure
524 * @ptr: pointer offset in eeprom
525 * @size: size of section pointed by ptr, if 0 first word will be used as size
526 * @csum: address of checksum to update
528 * Returns error status for any failure
530 static s32 ixgbe_checksum_ptr_x550(struct ixgbe_hw *hw, u16 ptr,
531 u16 size, u16 *csum, u16 *buffer,
536 u16 length, bufsz, i, start;
539 bufsz = sizeof(buf) / sizeof(buf[0]);
541 /* Read a chunk at the pointer location */
543 status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr, bufsz, buf);
545 hw_dbg(hw, "Failed to read EEPROM image\n");
550 if (buffer_size < ptr)
551 return IXGBE_ERR_PARAM;
552 local_buffer = &buffer[ptr];
560 length = local_buffer[0];
562 /* Skip pointer section if length is invalid. */
563 if (length == 0xFFFF || length == 0 ||
564 (ptr + length) >= hw->eeprom.word_size)
568 if (buffer && ((u32)start + (u32)length > buffer_size))
569 return IXGBE_ERR_PARAM;
571 for (i = start; length; i++, length--) {
572 if (i == bufsz && !buffer) {
578 /* Read a chunk at the pointer location */
579 status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr,
582 hw_dbg(hw, "Failed to read EEPROM image\n");
586 *csum += local_buffer[i];
591 /** ixgbe_calc_checksum_X550 - Calculates and returns the checksum
592 * @hw: pointer to hardware structure
593 * @buffer: pointer to buffer containing calculated checksum
594 * @buffer_size: size of buffer
596 * Returns a negative error code on error, or the 16-bit checksum
598 static s32 ixgbe_calc_checksum_X550(struct ixgbe_hw *hw, u16 *buffer,
601 u16 eeprom_ptrs[IXGBE_EEPROM_LAST_WORD + 1];
605 u16 pointer, i, size;
607 hw->eeprom.ops.init_params(hw);
610 /* Read pointer area */
611 status = ixgbe_read_ee_hostif_buffer_X550(hw, 0,
612 IXGBE_EEPROM_LAST_WORD + 1,
615 hw_dbg(hw, "Failed to read EEPROM image\n");
618 local_buffer = eeprom_ptrs;
620 if (buffer_size < IXGBE_EEPROM_LAST_WORD)
621 return IXGBE_ERR_PARAM;
622 local_buffer = buffer;
625 /* For X550 hardware include 0x0-0x41 in the checksum, skip the
626 * checksum word itself
628 for (i = 0; i <= IXGBE_EEPROM_LAST_WORD; i++)
629 if (i != IXGBE_EEPROM_CHECKSUM)
630 checksum += local_buffer[i];
632 /* Include all data from pointers 0x3, 0x6-0xE. This excludes the
633 * FW, PHY module, and PCIe Expansion/Option ROM pointers.
635 for (i = IXGBE_PCIE_ANALOG_PTR_X550; i < IXGBE_FW_PTR; i++) {
636 if (i == IXGBE_PHY_PTR || i == IXGBE_OPTION_ROM_PTR)
639 pointer = local_buffer[i];
641 /* Skip pointer section if the pointer is invalid. */
642 if (pointer == 0xFFFF || pointer == 0 ||
643 pointer >= hw->eeprom.word_size)
647 case IXGBE_PCIE_GENERAL_PTR:
648 size = IXGBE_IXGBE_PCIE_GENERAL_SIZE;
650 case IXGBE_PCIE_CONFIG0_PTR:
651 case IXGBE_PCIE_CONFIG1_PTR:
652 size = IXGBE_PCIE_CONFIG_SIZE;
659 status = ixgbe_checksum_ptr_x550(hw, pointer, size, &checksum,
660 buffer, buffer_size);
665 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
667 return (s32)checksum;
670 /** ixgbe_calc_eeprom_checksum_X550 - Calculates and returns the checksum
671 * @hw: pointer to hardware structure
673 * Returns a negative error code on error, or the 16-bit checksum
675 static s32 ixgbe_calc_eeprom_checksum_X550(struct ixgbe_hw *hw)
677 return ixgbe_calc_checksum_X550(hw, NULL, 0);
680 /** ixgbe_read_ee_hostif_X550 - Read EEPROM word using a host interface command
681 * @hw: pointer to hardware structure
682 * @offset: offset of word in the EEPROM to read
683 * @data: word read from the EEPROM
685 * Reads a 16 bit word from the EEPROM using the hostif.
687 static s32 ixgbe_read_ee_hostif_X550(struct ixgbe_hw *hw, u16 offset, u16 *data)
691 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0) {
692 status = ixgbe_read_ee_hostif_data_X550(hw, offset, data);
693 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
695 status = IXGBE_ERR_SWFW_SYNC;
701 /** ixgbe_validate_eeprom_checksum_X550 - Validate EEPROM checksum
702 * @hw: pointer to hardware structure
703 * @checksum_val: calculated checksum
705 * Performs checksum calculation and validates the EEPROM checksum. If the
706 * caller does not need checksum_val, the value can be NULL.
708 static s32 ixgbe_validate_eeprom_checksum_X550(struct ixgbe_hw *hw,
713 u16 read_checksum = 0;
715 /* Read the first word from the EEPROM. If this times out or fails, do
716 * not continue or we could be in for a very long wait while every
719 status = hw->eeprom.ops.read(hw, 0, &checksum);
721 hw_dbg(hw, "EEPROM read failed\n");
725 status = hw->eeprom.ops.calc_checksum(hw);
729 checksum = (u16)(status & 0xffff);
731 status = ixgbe_read_ee_hostif_X550(hw, IXGBE_EEPROM_CHECKSUM,
736 /* Verify read checksum from EEPROM is the same as
737 * calculated checksum
739 if (read_checksum != checksum) {
740 status = IXGBE_ERR_EEPROM_CHECKSUM;
741 hw_dbg(hw, "Invalid EEPROM checksum");
744 /* If the user cares, return the calculated checksum */
746 *checksum_val = checksum;
751 /** ixgbe_write_ee_hostif_X550 - Write EEPROM word using hostif
752 * @hw: pointer to hardware structure
753 * @offset: offset of word in the EEPROM to write
754 * @data: word write to the EEPROM
756 * Write a 16 bit word to the EEPROM using the hostif.
758 static s32 ixgbe_write_ee_hostif_data_X550(struct ixgbe_hw *hw, u16 offset,
762 struct ixgbe_hic_write_shadow_ram buffer;
764 buffer.hdr.req.cmd = FW_WRITE_SHADOW_RAM_CMD;
765 buffer.hdr.req.buf_lenh = 0;
766 buffer.hdr.req.buf_lenl = FW_WRITE_SHADOW_RAM_LEN;
767 buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
770 buffer.length = cpu_to_be16(sizeof(u16));
772 buffer.address = cpu_to_be32(offset * 2);
774 status = ixgbe_host_interface_command(hw, (u32 *)&buffer,
776 IXGBE_HI_COMMAND_TIMEOUT, false);
780 /** ixgbe_write_ee_hostif_X550 - Write EEPROM word using hostif
781 * @hw: pointer to hardware structure
782 * @offset: offset of word in the EEPROM to write
783 * @data: word write to the EEPROM
785 * Write a 16 bit word to the EEPROM using the hostif.
787 static s32 ixgbe_write_ee_hostif_X550(struct ixgbe_hw *hw, u16 offset, u16 data)
791 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) == 0) {
792 status = ixgbe_write_ee_hostif_data_X550(hw, offset, data);
793 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
795 hw_dbg(hw, "write ee hostif failed to get semaphore");
796 status = IXGBE_ERR_SWFW_SYNC;
802 /** ixgbe_update_flash_X550 - Instruct HW to copy EEPROM to Flash device
803 * @hw: pointer to hardware structure
805 * Issue a shadow RAM dump to FW to copy EEPROM from shadow RAM to the flash.
807 static s32 ixgbe_update_flash_X550(struct ixgbe_hw *hw)
810 union ixgbe_hic_hdr2 buffer;
812 buffer.req.cmd = FW_SHADOW_RAM_DUMP_CMD;
813 buffer.req.buf_lenh = 0;
814 buffer.req.buf_lenl = FW_SHADOW_RAM_DUMP_LEN;
815 buffer.req.checksum = FW_DEFAULT_CHECKSUM;
817 status = ixgbe_host_interface_command(hw, (u32 *)&buffer,
819 IXGBE_HI_COMMAND_TIMEOUT, false);
824 * ixgbe_get_bus_info_X550em - Set PCI bus info
825 * @hw: pointer to hardware structure
827 * Sets bus link width and speed to unknown because X550em is
830 static s32 ixgbe_get_bus_info_X550em(struct ixgbe_hw *hw)
832 hw->bus.type = ixgbe_bus_type_internal;
833 hw->bus.width = ixgbe_bus_width_unknown;
834 hw->bus.speed = ixgbe_bus_speed_unknown;
836 hw->mac.ops.set_lan_id(hw);
841 /** ixgbe_disable_rx_x550 - Disable RX unit
843 * Enables the Rx DMA unit for x550
845 static void ixgbe_disable_rx_x550(struct ixgbe_hw *hw)
847 u32 rxctrl, pfdtxgswc;
849 struct ixgbe_hic_disable_rxen fw_cmd;
851 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
852 if (rxctrl & IXGBE_RXCTRL_RXEN) {
853 pfdtxgswc = IXGBE_READ_REG(hw, IXGBE_PFDTXGSWC);
854 if (pfdtxgswc & IXGBE_PFDTXGSWC_VT_LBEN) {
855 pfdtxgswc &= ~IXGBE_PFDTXGSWC_VT_LBEN;
856 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, pfdtxgswc);
857 hw->mac.set_lben = true;
859 hw->mac.set_lben = false;
862 fw_cmd.hdr.cmd = FW_DISABLE_RXEN_CMD;
863 fw_cmd.hdr.buf_len = FW_DISABLE_RXEN_LEN;
864 fw_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
865 fw_cmd.port_number = (u8)hw->bus.lan_id;
867 status = ixgbe_host_interface_command(hw, (u32 *)&fw_cmd,
868 sizeof(struct ixgbe_hic_disable_rxen),
869 IXGBE_HI_COMMAND_TIMEOUT, true);
871 /* If we fail - disable RX using register write */
873 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
874 if (rxctrl & IXGBE_RXCTRL_RXEN) {
875 rxctrl &= ~IXGBE_RXCTRL_RXEN;
876 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl);
882 /** ixgbe_update_eeprom_checksum_X550 - Updates the EEPROM checksum and flash
883 * @hw: pointer to hardware structure
885 * After writing EEPROM to shadow RAM using EEWR register, software calculates
886 * checksum and updates the EEPROM and instructs the hardware to update
889 static s32 ixgbe_update_eeprom_checksum_X550(struct ixgbe_hw *hw)
894 /* Read the first word from the EEPROM. If this times out or fails, do
895 * not continue or we could be in for a very long wait while every
898 status = ixgbe_read_ee_hostif_X550(hw, 0, &checksum);
900 hw_dbg(hw, "EEPROM read failed\n");
904 status = ixgbe_calc_eeprom_checksum_X550(hw);
908 checksum = (u16)(status & 0xffff);
910 status = ixgbe_write_ee_hostif_X550(hw, IXGBE_EEPROM_CHECKSUM,
915 status = ixgbe_update_flash_X550(hw);
920 /** ixgbe_write_ee_hostif_buffer_X550 - Write EEPROM word(s) using hostif
921 * @hw: pointer to hardware structure
922 * @offset: offset of word in the EEPROM to write
923 * @words: number of words
924 * @data: word(s) write to the EEPROM
927 * Write a 16 bit word(s) to the EEPROM using the hostif.
929 static s32 ixgbe_write_ee_hostif_buffer_X550(struct ixgbe_hw *hw,
930 u16 offset, u16 words,
936 /* Take semaphore for the entire operation. */
937 status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
939 hw_dbg(hw, "EEPROM write buffer - semaphore failed\n");
943 for (i = 0; i < words; i++) {
944 status = ixgbe_write_ee_hostif_data_X550(hw, offset + i,
947 hw_dbg(hw, "Eeprom buffered write failed\n");
952 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
957 /** ixgbe_write_iosf_sb_reg_x550 - Writes a value to specified register of the
960 * @hw: pointer to hardware structure
961 * @reg_addr: 32 bit PHY register to write
962 * @device_type: 3 bit device type
963 * @data: Data to write to the register
965 static s32 ixgbe_write_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr,
966 u32 device_type, u32 data)
968 u32 gssr = IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_PHY0_SM;
972 ret = hw->mac.ops.acquire_swfw_sync(hw, gssr);
976 ret = ixgbe_iosf_wait(hw, NULL);
980 command = ((reg_addr << IXGBE_SB_IOSF_CTRL_ADDR_SHIFT) |
981 (device_type << IXGBE_SB_IOSF_CTRL_TARGET_SELECT_SHIFT));
983 /* Write IOSF control register */
984 IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL, command);
986 /* Write IOSF data register */
987 IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_DATA, data);
989 ret = ixgbe_iosf_wait(hw, &command);
991 if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) {
992 error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >>
993 IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT;
994 hw_dbg(hw, "Failed to write, error %x\n", error);
995 return IXGBE_ERR_PHY;
999 hw->mac.ops.release_swfw_sync(hw, gssr);
1003 /** ixgbe_setup_ixfi_x550em - Configure the KR PHY for iXFI mode.
1004 * @hw: pointer to hardware structure
1005 * @speed: the link speed to force
1007 * Configures the integrated KR PHY to use iXFI mode. Used to connect an
1008 * internal and external PHY at a specific speed, without autonegotiation.
1010 static s32 ixgbe_setup_ixfi_x550em(struct ixgbe_hw *hw, ixgbe_link_speed *speed)
1015 /* Disable AN and force speed to 10G Serial. */
1016 status = ixgbe_read_iosf_sb_reg_x550(hw,
1017 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1018 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
1022 reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
1023 reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
1025 /* Select forced link speed for internal PHY. */
1027 case IXGBE_LINK_SPEED_10GB_FULL:
1028 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_10G;
1030 case IXGBE_LINK_SPEED_1GB_FULL:
1031 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_1G;
1034 /* Other link speeds are not supported by internal KR PHY. */
1035 return IXGBE_ERR_LINK_SETUP;
1038 status = ixgbe_write_iosf_sb_reg_x550(hw,
1039 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1040 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1044 /* Disable training protocol FSM. */
1045 status = ixgbe_read_iosf_sb_reg_x550(hw,
1046 IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
1047 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
1051 reg_val |= IXGBE_KRM_RX_TRN_LINKUP_CTRL_CONV_WO_PROTOCOL;
1052 status = ixgbe_write_iosf_sb_reg_x550(hw,
1053 IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
1054 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1058 /* Disable Flex from training TXFFE. */
1059 status = ixgbe_read_iosf_sb_reg_x550(hw,
1060 IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id),
1061 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
1065 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN;
1066 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN;
1067 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN;
1068 status = ixgbe_write_iosf_sb_reg_x550(hw,
1069 IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id),
1070 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1074 status = ixgbe_read_iosf_sb_reg_x550(hw,
1075 IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id),
1076 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
1080 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN;
1081 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN;
1082 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN;
1083 status = ixgbe_write_iosf_sb_reg_x550(hw,
1084 IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id),
1085 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1089 /* Enable override for coefficients. */
1090 status = ixgbe_read_iosf_sb_reg_x550(hw,
1091 IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id),
1092 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
1096 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_OVRRD_EN;
1097 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CZERO_EN;
1098 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CPLUS1_OVRRD_EN;
1099 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CMINUS1_OVRRD_EN;
1100 status = ixgbe_write_iosf_sb_reg_x550(hw,
1101 IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id),
1102 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1106 /* Toggle port SW reset by AN reset. */
1107 status = ixgbe_read_iosf_sb_reg_x550(hw,
1108 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1109 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
1113 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_RESTART;
1114 status = ixgbe_write_iosf_sb_reg_x550(hw,
1115 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1116 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1122 * ixgbe_supported_sfp_modules_X550em - Check if SFP module type is supported
1123 * @hw: pointer to hardware structure
1124 * @linear: true if SFP module is linear
1126 static s32 ixgbe_supported_sfp_modules_X550em(struct ixgbe_hw *hw, bool *linear)
1128 switch (hw->phy.sfp_type) {
1129 case ixgbe_sfp_type_not_present:
1130 return IXGBE_ERR_SFP_NOT_PRESENT;
1131 case ixgbe_sfp_type_da_cu_core0:
1132 case ixgbe_sfp_type_da_cu_core1:
1135 case ixgbe_sfp_type_srlr_core0:
1136 case ixgbe_sfp_type_srlr_core1:
1137 case ixgbe_sfp_type_da_act_lmt_core0:
1138 case ixgbe_sfp_type_da_act_lmt_core1:
1139 case ixgbe_sfp_type_1g_sx_core0:
1140 case ixgbe_sfp_type_1g_sx_core1:
1141 case ixgbe_sfp_type_1g_lx_core0:
1142 case ixgbe_sfp_type_1g_lx_core1:
1145 case ixgbe_sfp_type_unknown:
1146 case ixgbe_sfp_type_1g_cu_core0:
1147 case ixgbe_sfp_type_1g_cu_core1:
1149 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1156 * ixgbe_setup_mac_link_sfp_x550em - Configure the KR PHY for SFP.
1157 * @hw: pointer to hardware structure
1159 * Configures the extern PHY and the integrated KR PHY for SFP support.
1162 ixgbe_setup_mac_link_sfp_x550em(struct ixgbe_hw *hw,
1163 ixgbe_link_speed speed,
1164 __always_unused bool autoneg_wait_to_complete)
1168 bool setup_linear = false;
1170 /* Check if SFP module is supported and linear */
1171 status = ixgbe_supported_sfp_modules_X550em(hw, &setup_linear);
1173 /* If no SFP module present, then return success. Return success since
1174 * there is no reason to configure CS4227 and SFP not present error is
1175 * not accepted in the setup MAC link flow.
1177 if (status == IXGBE_ERR_SFP_NOT_PRESENT)
1183 if (!(hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_INT_PHY_MODE)) {
1184 /* Configure CS4227 LINE side to 10G SR. */
1185 slice = IXGBE_CS4227_LINE_SPARE22_MSB + (hw->bus.lan_id << 12);
1186 value = IXGBE_CS4227_SPEED_10G;
1187 status = ixgbe_write_i2c_combined_generic(hw, IXGBE_CS4227,
1192 slice = IXGBE_CS4227_LINE_SPARE24_LSB + (hw->bus.lan_id << 12);
1193 value = (IXGBE_CS4227_EDC_MODE_SR << 1) | 1;
1194 status = ixgbe_write_i2c_combined_generic(hw, IXGBE_CS4227,
1199 /* Configure CS4227 for HOST connection rate then type. */
1200 slice = IXGBE_CS4227_HOST_SPARE22_MSB + (hw->bus.lan_id << 12);
1201 value = speed & IXGBE_LINK_SPEED_10GB_FULL ?
1202 IXGBE_CS4227_SPEED_10G : IXGBE_CS4227_SPEED_1G;
1203 status = ixgbe_write_i2c_combined_generic(hw, IXGBE_CS4227,
1208 slice = IXGBE_CS4227_HOST_SPARE24_LSB + (hw->bus.lan_id << 12);
1210 value = (IXGBE_CS4227_EDC_MODE_CX1 << 1) | 1;
1212 value = (IXGBE_CS4227_EDC_MODE_SR << 1) | 1;
1213 status = ixgbe_write_i2c_combined_generic(hw, IXGBE_CS4227,
1218 /* Setup XFI internal link. */
1219 status = ixgbe_setup_ixfi_x550em(hw, &speed);
1221 hw_dbg(hw, "setup_ixfi failed with %d\n", status);
1225 /* Configure internal PHY for KR/KX. */
1226 status = ixgbe_setup_kr_speed_x550em(hw, speed);
1228 hw_dbg(hw, "setup_kr_speed failed with %d\n", status);
1232 /* Configure CS4227 LINE side to proper mode. */
1233 slice = IXGBE_CS4227_LINE_SPARE24_LSB + (hw->bus.lan_id << 12);
1235 value = (IXGBE_CS4227_EDC_MODE_CX1 << 1) | 1;
1237 value = (IXGBE_CS4227_EDC_MODE_SR << 1) | 1;
1238 status = ixgbe_write_i2c_combined_generic(hw, IXGBE_CS4227,
1247 hw_dbg(hw, "combined i2c access failed with %d\n", status);
1252 * ixgbe_setup_mac_link_t_X550em - Sets the auto advertised link speed
1253 * @hw: pointer to hardware structure
1254 * @speed: new link speed
1255 * @autoneg_wait_to_complete: true when waiting for completion is needed
1257 * Setup internal/external PHY link speed based on link speed, then set
1258 * external PHY auto advertised link speed.
1260 * Returns error status for any failure
1262 static s32 ixgbe_setup_mac_link_t_X550em(struct ixgbe_hw *hw,
1263 ixgbe_link_speed speed,
1267 ixgbe_link_speed force_speed;
1269 /* Setup internal/external PHY link speed to iXFI (10G), unless
1270 * only 1G is auto advertised then setup KX link.
1272 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
1273 force_speed = IXGBE_LINK_SPEED_10GB_FULL;
1275 force_speed = IXGBE_LINK_SPEED_1GB_FULL;
1277 /* If internal link mode is XFI, then setup XFI internal link. */
1278 if (!(hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_INT_PHY_MODE)) {
1279 status = ixgbe_setup_ixfi_x550em(hw, &force_speed);
1285 return hw->phy.ops.setup_link_speed(hw, speed, autoneg_wait);
1288 /** ixgbe_check_link_t_X550em - Determine link and speed status
1289 * @hw: pointer to hardware structure
1290 * @speed: pointer to link speed
1291 * @link_up: true when link is up
1292 * @link_up_wait_to_complete: bool used to wait for link up or not
1294 * Check that both the MAC and X557 external PHY have link.
1296 static s32 ixgbe_check_link_t_X550em(struct ixgbe_hw *hw,
1297 ixgbe_link_speed *speed,
1299 bool link_up_wait_to_complete)
1304 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
1305 return IXGBE_ERR_CONFIG;
1307 status = ixgbe_check_mac_link_generic(hw, speed, link_up,
1308 link_up_wait_to_complete);
1310 /* If check link fails or MAC link is not up, then return */
1311 if (status || !(*link_up))
1314 /* MAC link is up, so check external PHY link.
1315 * Read this twice back to back to indicate current status.
1317 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
1318 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
1323 /* If external PHY link is not up, then indicate link not up */
1324 if (!(autoneg_status & IXGBE_MDIO_AUTO_NEG_LINK_STATUS))
1330 /** ixgbe_init_mac_link_ops_X550em - init mac link function pointers
1331 * @hw: pointer to hardware structure
1333 static void ixgbe_init_mac_link_ops_X550em(struct ixgbe_hw *hw)
1335 struct ixgbe_mac_info *mac = &hw->mac;
1337 switch (mac->ops.get_media_type(hw)) {
1338 case ixgbe_media_type_fiber:
1339 /* CS4227 does not support autoneg, so disable the laser control
1340 * functions for SFP+ fiber
1342 mac->ops.disable_tx_laser = NULL;
1343 mac->ops.enable_tx_laser = NULL;
1344 mac->ops.flap_tx_laser = NULL;
1345 mac->ops.setup_link = ixgbe_setup_mac_link_multispeed_fiber;
1346 mac->ops.setup_fc = ixgbe_setup_fc_x550em;
1347 mac->ops.setup_mac_link = ixgbe_setup_mac_link_sfp_x550em;
1348 mac->ops.set_rate_select_speed =
1349 ixgbe_set_soft_rate_select_speed;
1351 case ixgbe_media_type_copper:
1352 mac->ops.setup_link = ixgbe_setup_mac_link_t_X550em;
1353 mac->ops.setup_fc = ixgbe_setup_fc_generic;
1354 mac->ops.check_link = ixgbe_check_link_t_X550em;
1357 mac->ops.setup_fc = ixgbe_setup_fc_x550em;
1362 /** ixgbe_setup_sfp_modules_X550em - Setup SFP module
1363 * @hw: pointer to hardware structure
1365 static s32 ixgbe_setup_sfp_modules_X550em(struct ixgbe_hw *hw)
1370 /* Check if SFP module is supported */
1371 status = ixgbe_supported_sfp_modules_X550em(hw, &linear);
1375 ixgbe_init_mac_link_ops_X550em(hw);
1376 hw->phy.ops.reset = NULL;
1381 /** ixgbe_get_link_capabilities_x550em - Determines link capabilities
1382 * @hw: pointer to hardware structure
1383 * @speed: pointer to link speed
1384 * @autoneg: true when autoneg or autotry is enabled
1386 static s32 ixgbe_get_link_capabilities_X550em(struct ixgbe_hw *hw,
1387 ixgbe_link_speed *speed,
1391 if (hw->phy.media_type == ixgbe_media_type_fiber) {
1392 /* CS4227 SFP must not enable auto-negotiation */
1395 if (hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1396 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1) {
1397 *speed = IXGBE_LINK_SPEED_1GB_FULL;
1401 /* Link capabilities are based on SFP */
1402 if (hw->phy.multispeed_fiber)
1403 *speed = IXGBE_LINK_SPEED_10GB_FULL |
1404 IXGBE_LINK_SPEED_1GB_FULL;
1406 *speed = IXGBE_LINK_SPEED_10GB_FULL;
1408 *speed = IXGBE_LINK_SPEED_10GB_FULL |
1409 IXGBE_LINK_SPEED_1GB_FULL;
1416 * ixgbe_get_lasi_ext_t_x550em - Determime external Base T PHY interrupt cause
1417 * @hw: pointer to hardware structure
1418 * @lsc: pointer to boolean flag which indicates whether external Base T
1419 * PHY interrupt is lsc
1421 * Determime if external Base T PHY interrupt cause is high temperature
1422 * failure alarm or link status change.
1424 * Return IXGBE_ERR_OVERTEMP if interrupt is high temperature
1425 * failure alarm, else return PHY access status.
1427 static s32 ixgbe_get_lasi_ext_t_x550em(struct ixgbe_hw *hw, bool *lsc)
1434 /* Vendor alarm triggered */
1435 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_CHIP_STD_INT_FLAG,
1436 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1439 if (status || !(reg & IXGBE_MDIO_GLOBAL_VEN_ALM_INT_EN))
1442 /* Vendor Auto-Neg alarm triggered or Global alarm 1 triggered */
1443 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_FLAG,
1444 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1447 if (status || !(reg & (IXGBE_MDIO_GLOBAL_AN_VEN_ALM_INT_EN |
1448 IXGBE_MDIO_GLOBAL_ALARM_1_INT)))
1451 /* Global alarm triggered */
1452 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_ALARM_1,
1453 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1459 /* If high temperature failure, then return over temp error and exit */
1460 if (reg & IXGBE_MDIO_GLOBAL_ALM_1_HI_TMP_FAIL) {
1461 /* power down the PHY in case the PHY FW didn't already */
1462 ixgbe_set_copper_phy_power(hw, false);
1463 return IXGBE_ERR_OVERTEMP;
1465 if (reg & IXGBE_MDIO_GLOBAL_ALM_1_DEV_FAULT) {
1466 /* device fault alarm triggered */
1467 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_FAULT_MSG,
1468 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1473 /* if device fault was due to high temp alarm handle and exit */
1474 if (reg == IXGBE_MDIO_GLOBAL_FAULT_MSG_HI_TMP) {
1475 /* power down the PHY in case the PHY FW didn't */
1476 ixgbe_set_copper_phy_power(hw, false);
1477 return IXGBE_ERR_OVERTEMP;
1481 /* Vendor alarm 2 triggered */
1482 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_CHIP_STD_INT_FLAG,
1483 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, ®);
1485 if (status || !(reg & IXGBE_MDIO_GLOBAL_STD_ALM2_INT))
1488 /* link connect/disconnect event occurred */
1489 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_TX_ALARM2,
1490 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, ®);
1496 if (reg & IXGBE_MDIO_AUTO_NEG_VEN_LSC)
1503 * ixgbe_enable_lasi_ext_t_x550em - Enable external Base T PHY interrupts
1504 * @hw: pointer to hardware structure
1506 * Enable link status change and temperature failure alarm for the external
1509 * Returns PHY access status
1511 static s32 ixgbe_enable_lasi_ext_t_x550em(struct ixgbe_hw *hw)
1517 /* Clear interrupt flags */
1518 status = ixgbe_get_lasi_ext_t_x550em(hw, &lsc);
1520 /* Enable link status change alarm */
1521 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PMA_TX_VEN_LASI_INT_MASK,
1522 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, ®);
1526 reg |= IXGBE_MDIO_PMA_TX_VEN_LASI_INT_EN;
1528 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_PMA_TX_VEN_LASI_INT_MASK,
1529 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, reg);
1533 /* Enable high temperature failure and global fault alarms */
1534 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_MASK,
1535 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1540 reg |= (IXGBE_MDIO_GLOBAL_INT_HI_TEMP_EN |
1541 IXGBE_MDIO_GLOBAL_INT_DEV_FAULT_EN);
1543 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_MASK,
1544 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1549 /* Enable vendor Auto-Neg alarm and Global Interrupt Mask 1 alarm */
1550 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_MASK,
1551 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1556 reg |= (IXGBE_MDIO_GLOBAL_AN_VEN_ALM_INT_EN |
1557 IXGBE_MDIO_GLOBAL_ALARM_1_INT);
1559 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_MASK,
1560 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1565 /* Enable chip-wide vendor alarm */
1566 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_STD_MASK,
1567 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1572 reg |= IXGBE_MDIO_GLOBAL_VEN_ALM_INT_EN;
1574 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_STD_MASK,
1575 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1582 * ixgbe_handle_lasi_ext_t_x550em - Handle external Base T PHY interrupt
1583 * @hw: pointer to hardware structure
1585 * Handle external Base T PHY interrupt. If high temperature
1586 * failure alarm then return error, else if link status change
1587 * then setup internal/external PHY link
1589 * Return IXGBE_ERR_OVERTEMP if interrupt is high temperature
1590 * failure alarm, else return PHY access status.
1592 static s32 ixgbe_handle_lasi_ext_t_x550em(struct ixgbe_hw *hw)
1594 struct ixgbe_phy_info *phy = &hw->phy;
1598 status = ixgbe_get_lasi_ext_t_x550em(hw, &lsc);
1602 if (lsc && phy->ops.setup_internal_link)
1603 return phy->ops.setup_internal_link(hw);
1609 * ixgbe_setup_kr_speed_x550em - Configure the KR PHY for link speed.
1610 * @hw: pointer to hardware structure
1611 * @speed: link speed
1613 * Configures the integrated KR PHY.
1615 static s32 ixgbe_setup_kr_speed_x550em(struct ixgbe_hw *hw,
1616 ixgbe_link_speed speed)
1621 status = ixgbe_read_iosf_sb_reg_x550(hw,
1622 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1623 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
1627 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
1628 reg_val &= ~(IXGBE_KRM_LINK_CTRL_1_TETH_AN_FEC_REQ |
1629 IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_FEC);
1630 reg_val &= ~(IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR |
1631 IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX);
1633 /* Advertise 10G support. */
1634 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
1635 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR;
1637 /* Advertise 1G support. */
1638 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
1639 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX;
1641 /* Restart auto-negotiation. */
1642 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_RESTART;
1643 status = ixgbe_write_iosf_sb_reg_x550(hw,
1644 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1645 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1650 /** ixgbe_setup_kx4_x550em - Configure the KX4 PHY.
1651 * @hw: pointer to hardware structure
1653 * Configures the integrated KX4 PHY.
1655 static s32 ixgbe_setup_kx4_x550em(struct ixgbe_hw *hw)
1660 status = ixgbe_read_iosf_sb_reg_x550(hw, IXGBE_KX4_LINK_CNTL_1,
1661 IXGBE_SB_IOSF_TARGET_KX4_PCS0 +
1662 hw->bus.lan_id, ®_val);
1666 reg_val &= ~(IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX4 |
1667 IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX);
1669 reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_ENABLE;
1671 /* Advertise 10G support. */
1672 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_10GB_FULL)
1673 reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX4;
1675 /* Advertise 1G support. */
1676 if (hw->phy.autoneg_advertised & IXGBE_LINK_SPEED_1GB_FULL)
1677 reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_CAP_KX;
1679 /* Restart auto-negotiation. */
1680 reg_val |= IXGBE_KX4_LINK_CNTL_1_TETH_AN_RESTART;
1681 status = ixgbe_write_iosf_sb_reg_x550(hw, IXGBE_KX4_LINK_CNTL_1,
1682 IXGBE_SB_IOSF_TARGET_KX4_PCS0 +
1683 hw->bus.lan_id, reg_val);
1688 /** ixgbe_setup_kr_x550em - Configure the KR PHY.
1689 * @hw: pointer to hardware structure
1691 * Configures the integrated KR PHY.
1693 static s32 ixgbe_setup_kr_x550em(struct ixgbe_hw *hw)
1695 return ixgbe_setup_kr_speed_x550em(hw, hw->phy.autoneg_advertised);
1698 /** ixgbe_ext_phy_t_x550em_get_link - Get ext phy link status
1699 * @hw: address of hardware structure
1700 * @link_up: address of boolean to indicate link status
1702 * Returns error code if unable to get link status.
1704 static s32 ixgbe_ext_phy_t_x550em_get_link(struct ixgbe_hw *hw, bool *link_up)
1711 /* read this twice back to back to indicate current status */
1712 ret = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
1713 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
1718 ret = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
1719 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
1724 *link_up = !!(autoneg_status & IXGBE_MDIO_AUTO_NEG_LINK_STATUS);
1729 /** ixgbe_setup_internal_phy_t_x550em - Configure KR PHY to X557 link
1730 * @hw: point to hardware structure
1732 * Configures the link between the integrated KR PHY and the external X557 PHY
1733 * The driver will call this function when it gets a link status change
1734 * interrupt from the X557 PHY. This function configures the link speed
1735 * between the PHYs to match the link speed of the BASE-T link.
1737 * A return of a non-zero value indicates an error, and the base driver should
1738 * not report link up.
1740 static s32 ixgbe_setup_internal_phy_t_x550em(struct ixgbe_hw *hw)
1742 ixgbe_link_speed force_speed;
1747 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
1748 return IXGBE_ERR_CONFIG;
1750 if (hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_INT_PHY_MODE) {
1751 speed = IXGBE_LINK_SPEED_10GB_FULL |
1752 IXGBE_LINK_SPEED_1GB_FULL;
1753 return ixgbe_setup_kr_speed_x550em(hw, speed);
1756 /* If link is not up, then there is no setup necessary so return */
1757 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
1764 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_STAT,
1765 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
1770 /* If link is not still up, then no setup is necessary so return */
1771 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
1778 /* clear everything but the speed and duplex bits */
1779 speed &= IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_MASK;
1782 case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_10GB_FULL:
1783 force_speed = IXGBE_LINK_SPEED_10GB_FULL;
1785 case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_1GB_FULL:
1786 force_speed = IXGBE_LINK_SPEED_1GB_FULL;
1789 /* Internal PHY does not support anything else */
1790 return IXGBE_ERR_INVALID_LINK_SETTINGS;
1793 return ixgbe_setup_ixfi_x550em(hw, &force_speed);
1796 /** ixgbe_reset_phy_t_X550em - Performs X557 PHY reset and enables LASI
1797 * @hw: pointer to hardware structure
1799 static s32 ixgbe_reset_phy_t_X550em(struct ixgbe_hw *hw)
1803 status = ixgbe_reset_phy_generic(hw);
1808 /* Configure Link Status Alarm and Temperature Threshold interrupts */
1809 return ixgbe_enable_lasi_ext_t_x550em(hw);
1812 /** ixgbe_get_lcd_x550em - Determine lowest common denominator
1813 * @hw: pointer to hardware structure
1814 * @lcd_speed: pointer to lowest common link speed
1816 * Determine lowest common link speed with link partner.
1818 static s32 ixgbe_get_lcd_t_x550em(struct ixgbe_hw *hw,
1819 ixgbe_link_speed *lcd_speed)
1823 u16 word = hw->eeprom.ctrl_word_3;
1825 *lcd_speed = IXGBE_LINK_SPEED_UNKNOWN;
1827 status = hw->phy.ops.read_reg(hw, IXGBE_AUTO_NEG_LP_STATUS,
1828 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
1833 /* If link partner advertised 1G, return 1G */
1834 if (an_lp_status & IXGBE_AUTO_NEG_LP_1000BASE_CAP) {
1835 *lcd_speed = IXGBE_LINK_SPEED_1GB_FULL;
1839 /* If 10G disabled for LPLU via NVM D10GMP, then return no valid LCD */
1840 if ((hw->bus.lan_id && (word & NVM_INIT_CTRL_3_D10GMP_PORT1)) ||
1841 (word & NVM_INIT_CTRL_3_D10GMP_PORT0))
1844 /* Link partner not capable of lower speeds, return 10G */
1845 *lcd_speed = IXGBE_LINK_SPEED_10GB_FULL;
1850 * ixgbe_setup_fc_x550em - Set up flow control
1851 * @hw: pointer to hardware structure
1853 static s32 ixgbe_setup_fc_x550em(struct ixgbe_hw *hw)
1855 bool pause, asm_dir;
1859 /* Validate the requested mode */
1860 if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
1861 hw_err(hw, "ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
1862 return IXGBE_ERR_INVALID_LINK_SETTINGS;
1865 /* 10gig parts do not have a word in the EEPROM to determine the
1866 * default flow control setting, so we explicitly set it to full.
1868 if (hw->fc.requested_mode == ixgbe_fc_default)
1869 hw->fc.requested_mode = ixgbe_fc_full;
1871 /* Determine PAUSE and ASM_DIR bits. */
1872 switch (hw->fc.requested_mode) {
1877 case ixgbe_fc_tx_pause:
1881 case ixgbe_fc_rx_pause:
1882 /* Rx Flow control is enabled and Tx Flow control is
1883 * disabled by software override. Since there really
1884 * isn't a way to advertise that we are capable of RX
1885 * Pause ONLY, we will advertise that we support both
1886 * symmetric and asymmetric Rx PAUSE, as such we fall
1887 * through to the fc_full statement. Later, we will
1888 * disable the adapter's ability to send PAUSE frames.
1896 hw_err(hw, "Flow control param set incorrectly\n");
1897 return IXGBE_ERR_CONFIG;
1900 if (hw->device_id != IXGBE_DEV_ID_X550EM_X_KR)
1903 rc = ixgbe_read_iosf_sb_reg_x550(hw,
1904 IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
1905 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
1909 reg_val &= ~(IXGBE_KRM_AN_CNTL_1_SYM_PAUSE |
1910 IXGBE_KRM_AN_CNTL_1_ASM_PAUSE);
1912 reg_val |= IXGBE_KRM_AN_CNTL_1_SYM_PAUSE;
1914 reg_val |= IXGBE_KRM_AN_CNTL_1_ASM_PAUSE;
1915 rc = ixgbe_write_iosf_sb_reg_x550(hw,
1916 IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
1917 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1919 /* This device does not fully support AN. */
1920 hw->fc.disable_fc_autoneg = true;
1925 /** ixgbe_enter_lplu_x550em - Transition to low power states
1926 * @hw: pointer to hardware structure
1928 * Configures Low Power Link Up on transition to low power states
1929 * (from D0 to non-D0). Link is required to enter LPLU so avoid resetting
1930 * the X557 PHY immediately prior to entering LPLU.
1932 static s32 ixgbe_enter_lplu_t_x550em(struct ixgbe_hw *hw)
1934 u16 an_10g_cntl_reg, autoneg_reg, speed;
1936 ixgbe_link_speed lcd_speed;
1940 /* If blocked by MNG FW, then don't restart AN */
1941 if (ixgbe_check_reset_blocked(hw))
1944 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
1948 status = hw->eeprom.ops.read(hw, NVM_INIT_CTRL_3,
1949 &hw->eeprom.ctrl_word_3);
1953 /* If link is down, LPLU disabled in NVM, WoL disabled, or
1954 * manageability disabled, then force link down by entering
1957 if (!link_up || !(hw->eeprom.ctrl_word_3 & NVM_INIT_CTRL_3_LPLU) ||
1958 !(hw->wol_enabled || ixgbe_mng_present(hw)))
1959 return ixgbe_set_copper_phy_power(hw, false);
1962 status = ixgbe_get_lcd_t_x550em(hw, &lcd_speed);
1966 /* If no valid LCD link speed, then force link down and exit. */
1967 if (lcd_speed == IXGBE_LINK_SPEED_UNKNOWN)
1968 return ixgbe_set_copper_phy_power(hw, false);
1970 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_STAT,
1971 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
1976 /* If no link now, speed is invalid so take link down */
1977 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
1979 return ixgbe_set_copper_phy_power(hw, false);
1981 /* clear everything but the speed bits */
1982 speed &= IXGBE_MDIO_AUTO_NEG_VEN_STAT_SPEED_MASK;
1984 /* If current speed is already LCD, then exit. */
1985 if (((speed == IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_1GB) &&
1986 (lcd_speed == IXGBE_LINK_SPEED_1GB_FULL)) ||
1987 ((speed == IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_10GB) &&
1988 (lcd_speed == IXGBE_LINK_SPEED_10GB_FULL)))
1991 /* Clear AN completed indication */
1992 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_TX_ALARM,
1993 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
1998 status = hw->phy.ops.read_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
1999 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
2004 status = hw->phy.ops.read_reg(hw,
2005 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
2006 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
2011 save_autoneg = hw->phy.autoneg_advertised;
2013 /* Setup link at least common link speed */
2014 status = hw->mac.ops.setup_link(hw, lcd_speed, false);
2016 /* restore autoneg from before setting lplu speed */
2017 hw->phy.autoneg_advertised = save_autoneg;
2022 /** ixgbe_init_phy_ops_X550em - PHY/SFP specific init
2023 * @hw: pointer to hardware structure
2025 * Initialize any function pointers that were not able to be
2026 * set during init_shared_code because the PHY/SFP type was
2027 * not known. Perform the SFP init if necessary.
2029 static s32 ixgbe_init_phy_ops_X550em(struct ixgbe_hw *hw)
2031 struct ixgbe_phy_info *phy = &hw->phy;
2034 hw->mac.ops.set_lan_id(hw);
2036 if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) {
2037 phy->phy_semaphore_mask = IXGBE_GSSR_SHARED_I2C_SM;
2038 ixgbe_setup_mux_ctl(hw);
2040 /* Save NW management interface connected on board. This is used
2041 * to determine internal PHY mode.
2043 phy->nw_mng_if_sel = IXGBE_READ_REG(hw, IXGBE_NW_MNG_IF_SEL);
2046 /* Identify the PHY or SFP module */
2047 ret_val = phy->ops.identify(hw);
2049 /* Setup function pointers based on detected hardware */
2050 ixgbe_init_mac_link_ops_X550em(hw);
2051 if (phy->sfp_type != ixgbe_sfp_type_unknown)
2052 phy->ops.reset = NULL;
2054 /* Set functions pointers based on phy type */
2055 switch (hw->phy.type) {
2056 case ixgbe_phy_x550em_kx4:
2057 phy->ops.setup_link = ixgbe_setup_kx4_x550em;
2058 phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
2059 phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
2061 case ixgbe_phy_x550em_kr:
2062 phy->ops.setup_link = ixgbe_setup_kr_x550em;
2063 phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
2064 phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
2066 case ixgbe_phy_x550em_ext_t:
2067 /* Save NW management interface connected on board. This is used
2068 * to determine internal PHY mode
2070 phy->nw_mng_if_sel = IXGBE_READ_REG(hw, IXGBE_NW_MNG_IF_SEL);
2072 /* If internal link mode is XFI, then setup iXFI internal link,
2073 * else setup KR now.
2075 phy->ops.setup_internal_link =
2076 ixgbe_setup_internal_phy_t_x550em;
2078 /* setup SW LPLU only for first revision */
2079 if (hw->mac.type == ixgbe_mac_X550EM_x &&
2080 !(IXGBE_READ_REG(hw, IXGBE_FUSES0_GROUP(0)) &
2081 IXGBE_FUSES0_REV_MASK))
2082 phy->ops.enter_lplu = ixgbe_enter_lplu_t_x550em;
2084 phy->ops.handle_lasi = ixgbe_handle_lasi_ext_t_x550em;
2085 phy->ops.reset = ixgbe_reset_phy_t_X550em;
2094 /** ixgbe_get_media_type_X550em - Get media type
2095 * @hw: pointer to hardware structure
2097 * Returns the media type (fiber, copper, backplane)
2100 static enum ixgbe_media_type ixgbe_get_media_type_X550em(struct ixgbe_hw *hw)
2102 enum ixgbe_media_type media_type;
2104 /* Detect if there is a copper PHY attached. */
2105 switch (hw->device_id) {
2106 case IXGBE_DEV_ID_X550EM_X_KR:
2107 case IXGBE_DEV_ID_X550EM_X_KX4:
2108 media_type = ixgbe_media_type_backplane;
2110 case IXGBE_DEV_ID_X550EM_X_SFP:
2111 media_type = ixgbe_media_type_fiber;
2113 case IXGBE_DEV_ID_X550EM_X_1G_T:
2114 case IXGBE_DEV_ID_X550EM_X_10G_T:
2115 media_type = ixgbe_media_type_copper;
2118 media_type = ixgbe_media_type_unknown;
2124 /** ixgbe_init_ext_t_x550em - Start (unstall) the external Base T PHY.
2125 ** @hw: pointer to hardware structure
2127 static s32 ixgbe_init_ext_t_x550em(struct ixgbe_hw *hw)
2132 status = hw->phy.ops.read_reg(hw,
2133 IXGBE_MDIO_TX_VENDOR_ALARMS_3,
2134 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
2139 /* If PHY FW reset completed bit is set then this is the first
2140 * SW instance after a power on so the PHY FW must be un-stalled.
2142 if (reg & IXGBE_MDIO_TX_VENDOR_ALARMS_3_RST_MASK) {
2143 status = hw->phy.ops.read_reg(hw,
2144 IXGBE_MDIO_GLOBAL_RES_PR_10,
2145 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
2150 reg &= ~IXGBE_MDIO_POWER_UP_STALL;
2152 status = hw->phy.ops.write_reg(hw,
2153 IXGBE_MDIO_GLOBAL_RES_PR_10,
2154 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
2163 /** ixgbe_reset_hw_X550em - Perform hardware reset
2164 ** @hw: pointer to hardware structure
2166 ** Resets the hardware by resetting the transmit and receive units, masks
2167 ** and clears all interrupts, perform a PHY reset, and perform a link (MAC)
2170 static s32 ixgbe_reset_hw_X550em(struct ixgbe_hw *hw)
2172 ixgbe_link_speed link_speed;
2177 bool link_up = false;
2179 /* Call adapter stop to disable Tx/Rx and clear interrupts */
2180 status = hw->mac.ops.stop_adapter(hw);
2184 /* flush pending Tx transactions */
2185 ixgbe_clear_tx_pending(hw);
2187 /* PHY ops must be identified and initialized prior to reset */
2189 /* Identify PHY and related function pointers */
2190 status = hw->phy.ops.init(hw);
2192 /* start the external PHY */
2193 if (hw->phy.type == ixgbe_phy_x550em_ext_t) {
2194 status = ixgbe_init_ext_t_x550em(hw);
2199 /* Setup SFP module if there is one present. */
2200 if (hw->phy.sfp_setup_needed) {
2201 status = hw->mac.ops.setup_sfp(hw);
2202 hw->phy.sfp_setup_needed = false;
2206 if (!hw->phy.reset_disable && hw->phy.ops.reset)
2207 hw->phy.ops.reset(hw);
2210 /* Issue global reset to the MAC. Needs to be SW reset if link is up.
2211 * If link reset is used when link is up, it might reset the PHY when
2212 * mng is using it. If link is down or the flag to force full link
2213 * reset is set, then perform link reset.
2215 ctrl = IXGBE_CTRL_LNK_RST;
2217 if (!hw->force_full_reset) {
2218 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
2220 ctrl = IXGBE_CTRL_RST;
2223 ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL);
2224 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
2225 IXGBE_WRITE_FLUSH(hw);
2226 usleep_range(1000, 1200);
2228 /* Poll for reset bit to self-clear meaning reset is complete */
2229 for (i = 0; i < 10; i++) {
2230 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
2231 if (!(ctrl & IXGBE_CTRL_RST_MASK))
2236 if (ctrl & IXGBE_CTRL_RST_MASK) {
2237 status = IXGBE_ERR_RESET_FAILED;
2238 hw_dbg(hw, "Reset polling failed to complete.\n");
2243 /* Double resets are required for recovery from certain error
2244 * clear the multicast table. Also reset num_rar_entries to 128,
2245 * since we modify this value when programming the SAN MAC address.
2247 if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
2248 hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
2252 /* Store the permanent mac address */
2253 hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
2255 /* Store MAC address from RAR0, clear receive address registers, and
2256 * clear the multicast table. Also reset num_rar_entries to 128,
2257 * since we modify this value when programming the SAN MAC address.
2259 hw->mac.num_rar_entries = 128;
2260 hw->mac.ops.init_rx_addrs(hw);
2262 if (hw->device_id == IXGBE_DEV_ID_X550EM_X_10G_T) {
2263 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
2264 hlreg0 &= ~IXGBE_HLREG0_MDCSPD;
2265 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
2268 if (hw->device_id == IXGBE_DEV_ID_X550EM_X_SFP)
2269 ixgbe_setup_mux_ctl(hw);
2274 /** ixgbe_set_ethertype_anti_spoofing_X550 - Enable/Disable Ethertype
2276 * @hw: pointer to hardware structure
2277 * @enable: enable or disable switch for Ethertype anti-spoofing
2278 * @vf: Virtual Function pool - VF Pool to set for Ethertype anti-spoofing
2280 static void ixgbe_set_ethertype_anti_spoofing_X550(struct ixgbe_hw *hw,
2281 bool enable, int vf)
2283 int vf_target_reg = vf >> 3;
2284 int vf_target_shift = vf % 8 + IXGBE_SPOOF_ETHERTYPEAS_SHIFT;
2287 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
2289 pfvfspoof |= (1 << vf_target_shift);
2291 pfvfspoof &= ~(1 << vf_target_shift);
2293 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
2296 /** ixgbe_set_source_address_pruning_X550 - Enable/Disbale src address pruning
2297 * @hw: pointer to hardware structure
2298 * @enable: enable or disable source address pruning
2299 * @pool: Rx pool to set source address pruning for
2301 static void ixgbe_set_source_address_pruning_X550(struct ixgbe_hw *hw,
2307 /* max rx pool is 63 */
2311 pfflp = (u64)IXGBE_READ_REG(hw, IXGBE_PFFLPL);
2312 pfflp |= (u64)IXGBE_READ_REG(hw, IXGBE_PFFLPH) << 32;
2315 pfflp |= (1ULL << pool);
2317 pfflp &= ~(1ULL << pool);
2319 IXGBE_WRITE_REG(hw, IXGBE_PFFLPL, (u32)pfflp);
2320 IXGBE_WRITE_REG(hw, IXGBE_PFFLPH, (u32)(pfflp >> 32));
2324 * ixgbe_set_mux - Set mux for port 1 access with CS4227
2325 * @hw: pointer to hardware structure
2326 * @state: set mux if 1, clear if 0
2328 static void ixgbe_set_mux(struct ixgbe_hw *hw, u8 state)
2332 if (!hw->bus.lan_id)
2334 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
2336 esdp |= IXGBE_ESDP_SDP1;
2338 esdp &= ~IXGBE_ESDP_SDP1;
2339 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
2340 IXGBE_WRITE_FLUSH(hw);
2344 * ixgbe_acquire_swfw_sync_X550em - Acquire SWFW semaphore
2345 * @hw: pointer to hardware structure
2346 * @mask: Mask to specify which semaphore to acquire
2348 * Acquires the SWFW semaphore and sets the I2C MUX
2350 static s32 ixgbe_acquire_swfw_sync_X550em(struct ixgbe_hw *hw, u32 mask)
2354 status = ixgbe_acquire_swfw_sync_X540(hw, mask);
2358 if (mask & IXGBE_GSSR_I2C_MASK)
2359 ixgbe_set_mux(hw, 1);
2365 * ixgbe_release_swfw_sync_X550em - Release SWFW semaphore
2366 * @hw: pointer to hardware structure
2367 * @mask: Mask to specify which semaphore to release
2369 * Releases the SWFW semaphore and sets the I2C MUX
2371 static void ixgbe_release_swfw_sync_X550em(struct ixgbe_hw *hw, u32 mask)
2373 if (mask & IXGBE_GSSR_I2C_MASK)
2374 ixgbe_set_mux(hw, 0);
2376 ixgbe_release_swfw_sync_X540(hw, mask);
2379 #define X550_COMMON_MAC \
2380 .init_hw = &ixgbe_init_hw_generic, \
2381 .start_hw = &ixgbe_start_hw_X540, \
2382 .clear_hw_cntrs = &ixgbe_clear_hw_cntrs_generic, \
2383 .enable_rx_dma = &ixgbe_enable_rx_dma_generic, \
2384 .get_mac_addr = &ixgbe_get_mac_addr_generic, \
2385 .get_device_caps = &ixgbe_get_device_caps_generic, \
2386 .stop_adapter = &ixgbe_stop_adapter_generic, \
2387 .set_lan_id = &ixgbe_set_lan_id_multi_port_pcie, \
2388 .read_analog_reg8 = NULL, \
2389 .write_analog_reg8 = NULL, \
2390 .set_rxpba = &ixgbe_set_rxpba_generic, \
2391 .check_link = &ixgbe_check_mac_link_generic, \
2392 .led_on = &ixgbe_led_on_generic, \
2393 .led_off = &ixgbe_led_off_generic, \
2394 .blink_led_start = &ixgbe_blink_led_start_X540, \
2395 .blink_led_stop = &ixgbe_blink_led_stop_X540, \
2396 .set_rar = &ixgbe_set_rar_generic, \
2397 .clear_rar = &ixgbe_clear_rar_generic, \
2398 .set_vmdq = &ixgbe_set_vmdq_generic, \
2399 .set_vmdq_san_mac = &ixgbe_set_vmdq_san_mac_generic, \
2400 .clear_vmdq = &ixgbe_clear_vmdq_generic, \
2401 .init_rx_addrs = &ixgbe_init_rx_addrs_generic, \
2402 .update_mc_addr_list = &ixgbe_update_mc_addr_list_generic, \
2403 .enable_mc = &ixgbe_enable_mc_generic, \
2404 .disable_mc = &ixgbe_disable_mc_generic, \
2405 .clear_vfta = &ixgbe_clear_vfta_generic, \
2406 .set_vfta = &ixgbe_set_vfta_generic, \
2407 .fc_enable = &ixgbe_fc_enable_generic, \
2408 .set_fw_drv_ver = &ixgbe_set_fw_drv_ver_generic, \
2409 .init_uta_tables = &ixgbe_init_uta_tables_generic, \
2410 .set_mac_anti_spoofing = &ixgbe_set_mac_anti_spoofing, \
2411 .set_vlan_anti_spoofing = &ixgbe_set_vlan_anti_spoofing, \
2412 .set_source_address_pruning = \
2413 &ixgbe_set_source_address_pruning_X550, \
2414 .set_ethertype_anti_spoofing = \
2415 &ixgbe_set_ethertype_anti_spoofing_X550, \
2416 .disable_rx_buff = &ixgbe_disable_rx_buff_generic, \
2417 .enable_rx_buff = &ixgbe_enable_rx_buff_generic, \
2418 .get_thermal_sensor_data = NULL, \
2419 .init_thermal_sensor_thresh = NULL, \
2420 .enable_rx = &ixgbe_enable_rx_generic, \
2421 .disable_rx = &ixgbe_disable_rx_x550, \
2423 static const struct ixgbe_mac_operations mac_ops_X550 = {
2425 .reset_hw = &ixgbe_reset_hw_X540,
2426 .get_media_type = &ixgbe_get_media_type_X540,
2427 .get_san_mac_addr = &ixgbe_get_san_mac_addr_generic,
2428 .get_wwn_prefix = &ixgbe_get_wwn_prefix_generic,
2429 .setup_link = &ixgbe_setup_mac_link_X540,
2430 .get_link_capabilities = &ixgbe_get_copper_link_capabilities_generic,
2431 .get_bus_info = &ixgbe_get_bus_info_generic,
2433 .acquire_swfw_sync = &ixgbe_acquire_swfw_sync_X540,
2434 .release_swfw_sync = &ixgbe_release_swfw_sync_X540,
2435 .prot_autoc_read = prot_autoc_read_generic,
2436 .prot_autoc_write = prot_autoc_write_generic,
2437 .setup_fc = ixgbe_setup_fc_generic,
2440 static const struct ixgbe_mac_operations mac_ops_X550EM_x = {
2442 .reset_hw = &ixgbe_reset_hw_X550em,
2443 .get_media_type = &ixgbe_get_media_type_X550em,
2444 .get_san_mac_addr = NULL,
2445 .get_wwn_prefix = NULL,
2446 .setup_link = NULL, /* defined later */
2447 .get_link_capabilities = &ixgbe_get_link_capabilities_X550em,
2448 .get_bus_info = &ixgbe_get_bus_info_X550em,
2449 .setup_sfp = ixgbe_setup_sfp_modules_X550em,
2450 .acquire_swfw_sync = &ixgbe_acquire_swfw_sync_X550em,
2451 .release_swfw_sync = &ixgbe_release_swfw_sync_X550em,
2452 .setup_fc = NULL, /* defined later */
2455 #define X550_COMMON_EEP \
2456 .read = &ixgbe_read_ee_hostif_X550, \
2457 .read_buffer = &ixgbe_read_ee_hostif_buffer_X550, \
2458 .write = &ixgbe_write_ee_hostif_X550, \
2459 .write_buffer = &ixgbe_write_ee_hostif_buffer_X550, \
2460 .validate_checksum = &ixgbe_validate_eeprom_checksum_X550, \
2461 .update_checksum = &ixgbe_update_eeprom_checksum_X550, \
2462 .calc_checksum = &ixgbe_calc_eeprom_checksum_X550, \
2464 static const struct ixgbe_eeprom_operations eeprom_ops_X550 = {
2466 .init_params = &ixgbe_init_eeprom_params_X550,
2469 static const struct ixgbe_eeprom_operations eeprom_ops_X550EM_x = {
2471 .init_params = &ixgbe_init_eeprom_params_X540,
2474 #define X550_COMMON_PHY \
2475 .identify_sfp = &ixgbe_identify_module_generic, \
2477 .setup_link_speed = &ixgbe_setup_phy_link_speed_generic, \
2478 .read_i2c_byte = &ixgbe_read_i2c_byte_generic, \
2479 .write_i2c_byte = &ixgbe_write_i2c_byte_generic, \
2480 .read_i2c_sff8472 = &ixgbe_read_i2c_sff8472_generic, \
2481 .read_i2c_eeprom = &ixgbe_read_i2c_eeprom_generic, \
2482 .write_i2c_eeprom = &ixgbe_write_i2c_eeprom_generic, \
2483 .read_reg = &ixgbe_read_phy_reg_generic, \
2484 .write_reg = &ixgbe_write_phy_reg_generic, \
2485 .setup_link = &ixgbe_setup_phy_link_generic, \
2486 .set_phy_power = NULL, \
2487 .check_overtemp = &ixgbe_tn_check_overtemp, \
2488 .get_firmware_version = &ixgbe_get_phy_firmware_version_generic,
2490 static const struct ixgbe_phy_operations phy_ops_X550 = {
2493 .identify = &ixgbe_identify_phy_generic,
2496 static const struct ixgbe_phy_operations phy_ops_X550EM_x = {
2498 .init = &ixgbe_init_phy_ops_X550em,
2499 .identify = &ixgbe_identify_phy_x550em,
2500 .read_i2c_combined = &ixgbe_read_i2c_combined_generic,
2501 .write_i2c_combined = &ixgbe_write_i2c_combined_generic,
2502 .read_i2c_combined_unlocked = &ixgbe_read_i2c_combined_generic_unlocked,
2503 .write_i2c_combined_unlocked =
2504 &ixgbe_write_i2c_combined_generic_unlocked,
2507 static const u32 ixgbe_mvals_X550[IXGBE_MVALS_IDX_LIMIT] = {
2508 IXGBE_MVALS_INIT(X550)
2511 static const u32 ixgbe_mvals_X550EM_x[IXGBE_MVALS_IDX_LIMIT] = {
2512 IXGBE_MVALS_INIT(X550EM_x)
2515 const struct ixgbe_info ixgbe_X550_info = {
2516 .mac = ixgbe_mac_X550,
2517 .get_invariants = &ixgbe_get_invariants_X540,
2518 .mac_ops = &mac_ops_X550,
2519 .eeprom_ops = &eeprom_ops_X550,
2520 .phy_ops = &phy_ops_X550,
2521 .mbx_ops = &mbx_ops_generic,
2522 .mvals = ixgbe_mvals_X550,
2525 const struct ixgbe_info ixgbe_X550EM_x_info = {
2526 .mac = ixgbe_mac_X550EM_x,
2527 .get_invariants = &ixgbe_get_invariants_X550_x,
2528 .mac_ops = &mac_ops_X550EM_x,
2529 .eeprom_ops = &eeprom_ops_X550EM_x,
2530 .phy_ops = &phy_ops_X550EM_x,
2531 .mbx_ops = &mbx_ops_generic,
2532 .mvals = ixgbe_mvals_X550EM_x,