1 /******************************************************************************
3 Copyright (c) 2001-2015, Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
9 1. Redistributions of source code must retain the above copyright notice,
10 this list of conditions and the following disclaimer.
12 2. Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 3. Neither the name of the Intel Corporation nor the names of its
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
32 ******************************************************************************/
35 #include "ixgbe_x550.h"
36 #include "ixgbe_x540.h"
37 #include "ixgbe_type.h"
38 #include "ixgbe_api.h"
39 #include "ixgbe_common.h"
40 #include "ixgbe_phy.h"
42 static s32 ixgbe_setup_ixfi_x550em(struct ixgbe_hw *hw, ixgbe_link_speed *speed);
45 * ixgbe_init_ops_X550 - Inits func ptrs and MAC type
46 * @hw: pointer to hardware structure
48 * Initialize the function pointers and assign the MAC type for X550.
49 * Does not touch the hardware.
51 s32 ixgbe_init_ops_X550(struct ixgbe_hw *hw)
53 struct ixgbe_mac_info *mac = &hw->mac;
54 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
57 DEBUGFUNC("ixgbe_init_ops_X550");
59 ret_val = ixgbe_init_ops_X540(hw);
60 mac->ops.dmac_config = ixgbe_dmac_config_X550;
61 mac->ops.dmac_config_tcs = ixgbe_dmac_config_tcs_X550;
62 mac->ops.dmac_update_tcs = ixgbe_dmac_update_tcs_X550;
63 mac->ops.setup_eee = ixgbe_setup_eee_X550;
64 mac->ops.set_source_address_pruning =
65 ixgbe_set_source_address_pruning_X550;
66 mac->ops.set_ethertype_anti_spoofing =
67 ixgbe_set_ethertype_anti_spoofing_X550;
69 mac->ops.get_rtrup2tc = ixgbe_dcb_get_rtrup2tc_generic;
70 eeprom->ops.init_params = ixgbe_init_eeprom_params_X550;
71 eeprom->ops.calc_checksum = ixgbe_calc_eeprom_checksum_X550;
72 eeprom->ops.read = ixgbe_read_ee_hostif_X550;
73 eeprom->ops.read_buffer = ixgbe_read_ee_hostif_buffer_X550;
74 eeprom->ops.write = ixgbe_write_ee_hostif_X550;
75 eeprom->ops.write_buffer = ixgbe_write_ee_hostif_buffer_X550;
76 eeprom->ops.update_checksum = ixgbe_update_eeprom_checksum_X550;
77 eeprom->ops.validate_checksum = ixgbe_validate_eeprom_checksum_X550;
79 mac->ops.disable_mdd = ixgbe_disable_mdd_X550;
80 mac->ops.enable_mdd = ixgbe_enable_mdd_X550;
81 mac->ops.mdd_event = ixgbe_mdd_event_X550;
82 mac->ops.restore_mdd_vf = ixgbe_restore_mdd_vf_X550;
83 mac->ops.disable_rx = ixgbe_disable_rx_x550;
84 if (hw->device_id == IXGBE_DEV_ID_X550EM_X_10G_T) {
85 hw->mac.ops.led_on = ixgbe_led_on_t_X550em;
86 hw->mac.ops.led_off = ixgbe_led_off_t_X550em;
92 * ixgbe_read_cs4227 - Read CS4227 register
93 * @hw: pointer to hardware structure
94 * @reg: register number to write
95 * @value: pointer to receive value read
99 static s32 ixgbe_read_cs4227(struct ixgbe_hw *hw, u16 reg, u16 *value)
101 return ixgbe_read_i2c_combined_unlocked(hw, IXGBE_CS4227, reg, value);
105 * ixgbe_write_cs4227 - Write CS4227 register
106 * @hw: pointer to hardware structure
107 * @reg: register number to write
108 * @value: value to write to register
110 * Returns status code
112 static s32 ixgbe_write_cs4227(struct ixgbe_hw *hw, u16 reg, u16 value)
114 return ixgbe_write_i2c_combined_unlocked(hw, IXGBE_CS4227, reg, value);
118 * ixgbe_read_pe - Read register from port expander
119 * @hw: pointer to hardware structure
120 * @reg: register number to read
121 * @value: pointer to receive read value
123 * Returns status code
125 static s32 ixgbe_read_pe(struct ixgbe_hw *hw, u8 reg, u8 *value)
129 status = ixgbe_read_i2c_byte_unlocked(hw, reg, IXGBE_PE, value);
130 if (status != IXGBE_SUCCESS)
131 ERROR_REPORT2(IXGBE_ERROR_CAUTION,
132 "port expander access failed with %d\n", status);
137 * ixgbe_write_pe - Write register to port expander
138 * @hw: pointer to hardware structure
139 * @reg: register number to write
140 * @value: value to write
142 * Returns status code
144 static s32 ixgbe_write_pe(struct ixgbe_hw *hw, u8 reg, u8 value)
148 status = ixgbe_write_i2c_byte_unlocked(hw, reg, IXGBE_PE, value);
149 if (status != IXGBE_SUCCESS)
150 ERROR_REPORT2(IXGBE_ERROR_CAUTION,
151 "port expander access failed with %d\n", status);
156 * ixgbe_reset_cs4227 - Reset CS4227 using port expander
157 * @hw: pointer to hardware structure
159 * This function assumes that the caller has acquired the proper semaphore.
162 static s32 ixgbe_reset_cs4227(struct ixgbe_hw *hw)
169 /* Trigger hard reset. */
170 status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, ®);
171 if (status != IXGBE_SUCCESS)
173 reg |= IXGBE_PE_BIT1;
174 status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
175 if (status != IXGBE_SUCCESS)
178 status = ixgbe_read_pe(hw, IXGBE_PE_CONFIG, ®);
179 if (status != IXGBE_SUCCESS)
181 reg &= ~IXGBE_PE_BIT1;
182 status = ixgbe_write_pe(hw, IXGBE_PE_CONFIG, reg);
183 if (status != IXGBE_SUCCESS)
186 status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, ®);
187 if (status != IXGBE_SUCCESS)
189 reg &= ~IXGBE_PE_BIT1;
190 status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
191 if (status != IXGBE_SUCCESS)
194 usec_delay(IXGBE_CS4227_RESET_HOLD);
196 status = ixgbe_read_pe(hw, IXGBE_PE_OUTPUT, ®);
197 if (status != IXGBE_SUCCESS)
199 reg |= IXGBE_PE_BIT1;
200 status = ixgbe_write_pe(hw, IXGBE_PE_OUTPUT, reg);
201 if (status != IXGBE_SUCCESS)
204 /* Wait for the reset to complete. */
205 msec_delay(IXGBE_CS4227_RESET_DELAY);
206 for (retry = 0; retry < IXGBE_CS4227_RETRIES; retry++) {
207 status = ixgbe_read_cs4227(hw, IXGBE_CS4227_EFUSE_STATUS,
209 if (status == IXGBE_SUCCESS &&
210 value == IXGBE_CS4227_EEPROM_LOAD_OK)
212 msec_delay(IXGBE_CS4227_CHECK_DELAY);
214 if (retry == IXGBE_CS4227_RETRIES) {
215 ERROR_REPORT1(IXGBE_ERROR_INVALID_STATE,
216 "CS4227 reset did not complete.");
217 return IXGBE_ERR_PHY;
220 status = ixgbe_read_cs4227(hw, IXGBE_CS4227_EEPROM_STATUS, &value);
221 if (status != IXGBE_SUCCESS ||
222 !(value & IXGBE_CS4227_EEPROM_LOAD_OK)) {
223 ERROR_REPORT1(IXGBE_ERROR_INVALID_STATE,
224 "CS4227 EEPROM did not load successfully.");
225 return IXGBE_ERR_PHY;
228 return IXGBE_SUCCESS;
232 * ixgbe_check_cs4227 - Check CS4227 and reset as needed
233 * @hw: pointer to hardware structure
235 static void ixgbe_check_cs4227(struct ixgbe_hw *hw)
237 s32 status = IXGBE_SUCCESS;
238 u32 swfw_mask = hw->phy.phy_semaphore_mask;
242 for (retry = 0; retry < IXGBE_CS4227_RETRIES; retry++) {
243 status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
244 if (status != IXGBE_SUCCESS) {
245 ERROR_REPORT2(IXGBE_ERROR_CAUTION,
246 "semaphore failed with %d", status);
247 msec_delay(IXGBE_CS4227_CHECK_DELAY);
251 /* Get status of reset flow. */
252 status = ixgbe_read_cs4227(hw, IXGBE_CS4227_SCRATCH, &value);
254 if (status == IXGBE_SUCCESS &&
255 value == IXGBE_CS4227_RESET_COMPLETE)
258 if (status != IXGBE_SUCCESS ||
259 value != IXGBE_CS4227_RESET_PENDING)
262 /* Reset is pending. Wait and check again. */
263 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
264 msec_delay(IXGBE_CS4227_CHECK_DELAY);
267 /* If still pending, assume other instance failed. */
268 if (retry == IXGBE_CS4227_RETRIES) {
269 status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
270 if (status != IXGBE_SUCCESS) {
271 ERROR_REPORT2(IXGBE_ERROR_CAUTION,
272 "semaphore failed with %d", status);
277 /* Reset the CS4227. */
278 status = ixgbe_reset_cs4227(hw);
279 if (status != IXGBE_SUCCESS) {
280 ERROR_REPORT2(IXGBE_ERROR_INVALID_STATE,
281 "CS4227 reset failed: %d", status);
285 /* Reset takes so long, temporarily release semaphore in case the
286 * other driver instance is waiting for the reset indication.
288 ixgbe_write_cs4227(hw, IXGBE_CS4227_SCRATCH,
289 IXGBE_CS4227_RESET_PENDING);
290 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
292 status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
293 if (status != IXGBE_SUCCESS) {
294 ERROR_REPORT2(IXGBE_ERROR_CAUTION,
295 "semaphore failed with %d", status);
299 /* Record completion for next time. */
300 status = ixgbe_write_cs4227(hw, IXGBE_CS4227_SCRATCH,
301 IXGBE_CS4227_RESET_COMPLETE);
304 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
305 msec_delay(hw->eeprom.semaphore_delay);
309 * ixgbe_setup_mux_ctl - Setup ESDP register for I2C mux control
310 * @hw: pointer to hardware structure
312 static void ixgbe_setup_mux_ctl(struct ixgbe_hw *hw)
314 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
316 if (hw->bus.lan_id) {
317 esdp &= ~(IXGBE_ESDP_SDP1_NATIVE | IXGBE_ESDP_SDP1);
318 esdp |= IXGBE_ESDP_SDP1_DIR;
320 esdp &= ~(IXGBE_ESDP_SDP0_NATIVE | IXGBE_ESDP_SDP0_DIR);
321 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
322 IXGBE_WRITE_FLUSH(hw);
326 * ixgbe_identify_phy_x550em - Get PHY type based on device id
327 * @hw: pointer to hardware structure
331 static s32 ixgbe_identify_phy_x550em(struct ixgbe_hw *hw)
333 switch (hw->device_id) {
334 case IXGBE_DEV_ID_X550EM_X_SFP:
335 /* set up for CS4227 usage */
336 hw->phy.phy_semaphore_mask = IXGBE_GSSR_SHARED_I2C_SM;
337 ixgbe_setup_mux_ctl(hw);
338 ixgbe_check_cs4227(hw);
340 return ixgbe_identify_module_generic(hw);
342 case IXGBE_DEV_ID_X550EM_X_KX4:
343 hw->phy.type = ixgbe_phy_x550em_kx4;
345 case IXGBE_DEV_ID_X550EM_X_KR:
346 hw->phy.type = ixgbe_phy_x550em_kr;
348 case IXGBE_DEV_ID_X550EM_X_1G_T:
349 case IXGBE_DEV_ID_X550EM_X_10G_T:
350 return ixgbe_identify_phy_generic(hw);
354 return IXGBE_SUCCESS;
357 static s32 ixgbe_read_phy_reg_x550em(struct ixgbe_hw *hw, u32 reg_addr,
358 u32 device_type, u16 *phy_data)
360 UNREFERENCED_4PARAMETER(*hw, reg_addr, device_type, *phy_data);
361 return IXGBE_NOT_IMPLEMENTED;
364 static s32 ixgbe_write_phy_reg_x550em(struct ixgbe_hw *hw, u32 reg_addr,
365 u32 device_type, u16 phy_data)
367 UNREFERENCED_4PARAMETER(*hw, reg_addr, device_type, phy_data);
368 return IXGBE_NOT_IMPLEMENTED;
372 * ixgbe_init_ops_X550EM - Inits func ptrs and MAC type
373 * @hw: pointer to hardware structure
375 * Initialize the function pointers and for MAC type X550EM.
376 * Does not touch the hardware.
378 s32 ixgbe_init_ops_X550EM(struct ixgbe_hw *hw)
380 struct ixgbe_mac_info *mac = &hw->mac;
381 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
382 struct ixgbe_phy_info *phy = &hw->phy;
385 DEBUGFUNC("ixgbe_init_ops_X550EM");
387 /* Similar to X550 so start there. */
388 ret_val = ixgbe_init_ops_X550(hw);
390 /* Since this function eventually calls
391 * ixgbe_init_ops_540 by design, we are setting
392 * the pointers to NULL explicitly here to overwrite
393 * the values being set in the x540 function.
396 /* FCOE not supported in x550EM */
397 mac->ops.get_san_mac_addr = NULL;
398 mac->ops.set_san_mac_addr = NULL;
399 mac->ops.get_wwn_prefix = NULL;
400 mac->ops.get_fcoe_boot_status = NULL;
402 /* IPsec not supported in x550EM */
403 mac->ops.disable_sec_rx_path = NULL;
404 mac->ops.enable_sec_rx_path = NULL;
406 /* AUTOC register is not present in x550EM. */
407 mac->ops.prot_autoc_read = NULL;
408 mac->ops.prot_autoc_write = NULL;
410 /* X550EM bus type is internal*/
411 hw->bus.type = ixgbe_bus_type_internal;
412 mac->ops.get_bus_info = ixgbe_get_bus_info_X550em;
414 if (hw->mac.type == ixgbe_mac_X550EM_x) {
415 mac->ops.read_iosf_sb_reg = ixgbe_read_iosf_sb_reg_x550;
416 mac->ops.write_iosf_sb_reg = ixgbe_write_iosf_sb_reg_x550;
419 mac->ops.get_media_type = ixgbe_get_media_type_X550em;
420 mac->ops.setup_sfp = ixgbe_setup_sfp_modules_X550em;
421 mac->ops.get_link_capabilities = ixgbe_get_link_capabilities_X550em;
422 mac->ops.reset_hw = ixgbe_reset_hw_X550em;
423 mac->ops.get_supported_physical_layer =
424 ixgbe_get_supported_physical_layer_X550em;
426 if (mac->ops.get_media_type(hw) == ixgbe_media_type_copper)
427 mac->ops.setup_fc = ixgbe_setup_fc_generic;
429 mac->ops.setup_fc = ixgbe_setup_fc_X550em;
431 mac->ops.acquire_swfw_sync = ixgbe_acquire_swfw_sync_X550em;
432 mac->ops.release_swfw_sync = ixgbe_release_swfw_sync_X550em;
434 if (hw->device_id != IXGBE_DEV_ID_X550EM_X_KR)
435 mac->ops.setup_eee = NULL;
438 phy->ops.init = ixgbe_init_phy_ops_X550em;
439 phy->ops.identify = ixgbe_identify_phy_x550em;
440 if (mac->ops.get_media_type(hw) != ixgbe_media_type_copper)
441 phy->ops.set_phy_power = NULL;
445 eeprom->ops.init_params = ixgbe_init_eeprom_params_X540;
446 eeprom->ops.read = ixgbe_read_ee_hostif_X550;
447 eeprom->ops.read_buffer = ixgbe_read_ee_hostif_buffer_X550;
448 eeprom->ops.write = ixgbe_write_ee_hostif_X550;
449 eeprom->ops.write_buffer = ixgbe_write_ee_hostif_buffer_X550;
450 eeprom->ops.update_checksum = ixgbe_update_eeprom_checksum_X550;
451 eeprom->ops.validate_checksum = ixgbe_validate_eeprom_checksum_X550;
452 eeprom->ops.calc_checksum = ixgbe_calc_eeprom_checksum_X550;
458 * ixgbe_dmac_config_X550
459 * @hw: pointer to hardware structure
461 * Configure DMA coalescing. If enabling dmac, dmac is activated.
462 * When disabling dmac, dmac enable dmac bit is cleared.
464 s32 ixgbe_dmac_config_X550(struct ixgbe_hw *hw)
466 u32 reg, high_pri_tc;
468 DEBUGFUNC("ixgbe_dmac_config_X550");
470 /* Disable DMA coalescing before configuring */
471 reg = IXGBE_READ_REG(hw, IXGBE_DMACR);
472 reg &= ~IXGBE_DMACR_DMAC_EN;
473 IXGBE_WRITE_REG(hw, IXGBE_DMACR, reg);
475 /* Disable DMA Coalescing if the watchdog timer is 0 */
476 if (!hw->mac.dmac_config.watchdog_timer)
479 ixgbe_dmac_config_tcs_X550(hw);
481 /* Configure DMA Coalescing Control Register */
482 reg = IXGBE_READ_REG(hw, IXGBE_DMACR);
484 /* Set the watchdog timer in units of 40.96 usec */
485 reg &= ~IXGBE_DMACR_DMACWT_MASK;
486 reg |= (hw->mac.dmac_config.watchdog_timer * 100) / 4096;
488 reg &= ~IXGBE_DMACR_HIGH_PRI_TC_MASK;
489 /* If fcoe is enabled, set high priority traffic class */
490 if (hw->mac.dmac_config.fcoe_en) {
491 high_pri_tc = 1 << hw->mac.dmac_config.fcoe_tc;
492 reg |= ((high_pri_tc << IXGBE_DMACR_HIGH_PRI_TC_SHIFT) &
493 IXGBE_DMACR_HIGH_PRI_TC_MASK);
495 reg |= IXGBE_DMACR_EN_MNG_IND;
497 /* Enable DMA coalescing after configuration */
498 reg |= IXGBE_DMACR_DMAC_EN;
499 IXGBE_WRITE_REG(hw, IXGBE_DMACR, reg);
502 return IXGBE_SUCCESS;
506 * ixgbe_dmac_config_tcs_X550
507 * @hw: pointer to hardware structure
509 * Configure DMA coalescing threshold per TC. The dmac enable bit must
510 * be cleared before configuring.
512 s32 ixgbe_dmac_config_tcs_X550(struct ixgbe_hw *hw)
514 u32 tc, reg, pb_headroom, rx_pb_size, maxframe_size_kb;
516 DEBUGFUNC("ixgbe_dmac_config_tcs_X550");
518 /* Configure DMA coalescing enabled */
519 switch (hw->mac.dmac_config.link_speed) {
520 case IXGBE_LINK_SPEED_100_FULL:
521 pb_headroom = IXGBE_DMACRXT_100M;
523 case IXGBE_LINK_SPEED_1GB_FULL:
524 pb_headroom = IXGBE_DMACRXT_1G;
527 pb_headroom = IXGBE_DMACRXT_10G;
531 maxframe_size_kb = ((IXGBE_READ_REG(hw, IXGBE_MAXFRS) >>
532 IXGBE_MHADD_MFS_SHIFT) / 1024);
534 /* Set the per Rx packet buffer receive threshold */
535 for (tc = 0; tc < IXGBE_DCB_MAX_TRAFFIC_CLASS; tc++) {
536 reg = IXGBE_READ_REG(hw, IXGBE_DMCTH(tc));
537 reg &= ~IXGBE_DMCTH_DMACRXT_MASK;
539 if (tc < hw->mac.dmac_config.num_tcs) {
541 rx_pb_size = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(tc));
542 rx_pb_size = (rx_pb_size & IXGBE_RXPBSIZE_MASK) >>
543 IXGBE_RXPBSIZE_SHIFT;
545 /* Calculate receive buffer threshold in kilobytes */
546 if (rx_pb_size > pb_headroom)
547 rx_pb_size = rx_pb_size - pb_headroom;
551 /* Minimum of MFS shall be set for DMCTH */
552 reg |= (rx_pb_size > maxframe_size_kb) ?
553 rx_pb_size : maxframe_size_kb;
555 IXGBE_WRITE_REG(hw, IXGBE_DMCTH(tc), reg);
557 return IXGBE_SUCCESS;
561 * ixgbe_dmac_update_tcs_X550
562 * @hw: pointer to hardware structure
564 * Disables dmac, updates per TC settings, and then enables dmac.
566 s32 ixgbe_dmac_update_tcs_X550(struct ixgbe_hw *hw)
570 DEBUGFUNC("ixgbe_dmac_update_tcs_X550");
572 /* Disable DMA coalescing before configuring */
573 reg = IXGBE_READ_REG(hw, IXGBE_DMACR);
574 reg &= ~IXGBE_DMACR_DMAC_EN;
575 IXGBE_WRITE_REG(hw, IXGBE_DMACR, reg);
577 ixgbe_dmac_config_tcs_X550(hw);
579 /* Enable DMA coalescing after configuration */
580 reg = IXGBE_READ_REG(hw, IXGBE_DMACR);
581 reg |= IXGBE_DMACR_DMAC_EN;
582 IXGBE_WRITE_REG(hw, IXGBE_DMACR, reg);
584 return IXGBE_SUCCESS;
588 * ixgbe_init_eeprom_params_X550 - Initialize EEPROM params
589 * @hw: pointer to hardware structure
591 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
592 * ixgbe_hw struct in order to set up EEPROM access.
594 s32 ixgbe_init_eeprom_params_X550(struct ixgbe_hw *hw)
596 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
600 DEBUGFUNC("ixgbe_init_eeprom_params_X550");
602 if (eeprom->type == ixgbe_eeprom_uninitialized) {
603 eeprom->semaphore_delay = 10;
604 eeprom->type = ixgbe_flash;
606 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
607 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
608 IXGBE_EEC_SIZE_SHIFT);
609 eeprom->word_size = 1 << (eeprom_size +
610 IXGBE_EEPROM_WORD_SIZE_SHIFT);
612 DEBUGOUT2("Eeprom params: type = %d, size = %d\n",
613 eeprom->type, eeprom->word_size);
616 return IXGBE_SUCCESS;
620 * ixgbe_setup_eee_X550 - Enable/disable EEE support
621 * @hw: pointer to the HW structure
622 * @enable_eee: boolean flag to enable EEE
624 * Enable/disable EEE based on enable_eee flag.
625 * Auto-negotiation must be started after BASE-T EEE bits in PHY register 7.3C
629 s32 ixgbe_setup_eee_X550(struct ixgbe_hw *hw, bool enable_eee)
637 DEBUGFUNC("ixgbe_setup_eee_X550");
639 eeer = IXGBE_READ_REG(hw, IXGBE_EEER);
640 /* Enable or disable EEE per flag */
642 eeer |= (IXGBE_EEER_TX_LPI_EN | IXGBE_EEER_RX_LPI_EN);
644 if (hw->mac.type == ixgbe_mac_X550) {
645 /* Advertise EEE capability */
646 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_EEE_ADVT,
647 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_eee_reg);
649 autoneg_eee_reg |= (IXGBE_AUTO_NEG_10GBASE_EEE_ADVT |
650 IXGBE_AUTO_NEG_1000BASE_EEE_ADVT |
651 IXGBE_AUTO_NEG_100BASE_EEE_ADVT);
653 hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_EEE_ADVT,
654 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_eee_reg);
655 } else if (hw->device_id == IXGBE_DEV_ID_X550EM_X_KR) {
656 /* Not supported on first revision. */
657 fuse = IXGBE_READ_REG(hw, IXGBE_FUSES0_GROUP(0));
658 if (!(fuse & IXGBE_FUSES0_REV1))
659 return IXGBE_SUCCESS;
661 status = ixgbe_read_iosf_sb_reg_x550(hw,
662 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
663 IXGBE_SB_IOSF_TARGET_KR_PHY, &link_reg);
664 if (status != IXGBE_SUCCESS)
667 link_reg |= IXGBE_KRM_LINK_CTRL_1_TETH_EEE_CAP_KR |
668 IXGBE_KRM_LINK_CTRL_1_TETH_EEE_CAP_KX;
670 /* Don't advertise FEC capability when EEE enabled. */
671 link_reg &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_FEC;
673 status = ixgbe_write_iosf_sb_reg_x550(hw,
674 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
675 IXGBE_SB_IOSF_TARGET_KR_PHY, link_reg);
676 if (status != IXGBE_SUCCESS)
680 eeer &= ~(IXGBE_EEER_TX_LPI_EN | IXGBE_EEER_RX_LPI_EN);
682 if (hw->mac.type == ixgbe_mac_X550) {
683 /* Disable advertised EEE capability */
684 hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_EEE_ADVT,
685 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, &autoneg_eee_reg);
687 autoneg_eee_reg &= ~(IXGBE_AUTO_NEG_10GBASE_EEE_ADVT |
688 IXGBE_AUTO_NEG_1000BASE_EEE_ADVT |
689 IXGBE_AUTO_NEG_100BASE_EEE_ADVT);
691 hw->phy.ops.write_reg(hw, IXGBE_MDIO_AUTO_NEG_EEE_ADVT,
692 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, autoneg_eee_reg);
693 } else if (hw->device_id == IXGBE_DEV_ID_X550EM_X_KR) {
694 status = ixgbe_read_iosf_sb_reg_x550(hw,
695 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
696 IXGBE_SB_IOSF_TARGET_KR_PHY, &link_reg);
697 if (status != IXGBE_SUCCESS)
700 link_reg &= ~(IXGBE_KRM_LINK_CTRL_1_TETH_EEE_CAP_KR |
701 IXGBE_KRM_LINK_CTRL_1_TETH_EEE_CAP_KX);
703 /* Advertise FEC capability when EEE is disabled. */
704 link_reg |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_FEC;
706 status = ixgbe_write_iosf_sb_reg_x550(hw,
707 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
708 IXGBE_SB_IOSF_TARGET_KR_PHY, link_reg);
709 if (status != IXGBE_SUCCESS)
713 IXGBE_WRITE_REG(hw, IXGBE_EEER, eeer);
715 return IXGBE_SUCCESS;
719 * ixgbe_set_source_address_pruning_X550 - Enable/Disbale source address pruning
720 * @hw: pointer to hardware structure
721 * @enable: enable or disable source address pruning
722 * @pool: Rx pool to set source address pruning for
724 void ixgbe_set_source_address_pruning_X550(struct ixgbe_hw *hw, bool enable,
729 /* max rx pool is 63 */
733 pfflp = (u64)IXGBE_READ_REG(hw, IXGBE_PFFLPL);
734 pfflp |= (u64)IXGBE_READ_REG(hw, IXGBE_PFFLPH) << 32;
737 pfflp |= (1ULL << pool);
739 pfflp &= ~(1ULL << pool);
741 IXGBE_WRITE_REG(hw, IXGBE_PFFLPL, (u32)pfflp);
742 IXGBE_WRITE_REG(hw, IXGBE_PFFLPH, (u32)(pfflp >> 32));
746 * ixgbe_set_ethertype_anti_spoofing_X550 - Enable/Disable Ethertype anti-spoofing
747 * @hw: pointer to hardware structure
748 * @enable: enable or disable switch for Ethertype anti-spoofing
749 * @vf: Virtual Function pool - VF Pool to set for Ethertype anti-spoofing
752 void ixgbe_set_ethertype_anti_spoofing_X550(struct ixgbe_hw *hw,
755 int vf_target_reg = vf >> 3;
756 int vf_target_shift = vf % 8 + IXGBE_SPOOF_ETHERTYPEAS_SHIFT;
759 DEBUGFUNC("ixgbe_set_ethertype_anti_spoofing_X550");
761 pfvfspoof = IXGBE_READ_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg));
763 pfvfspoof |= (1 << vf_target_shift);
765 pfvfspoof &= ~(1 << vf_target_shift);
767 IXGBE_WRITE_REG(hw, IXGBE_PFVFSPOOF(vf_target_reg), pfvfspoof);
771 * ixgbe_iosf_wait - Wait for IOSF command completion
772 * @hw: pointer to hardware structure
773 * @ctrl: pointer to location to receive final IOSF control value
775 * Returns failing status on timeout
777 * Note: ctrl can be NULL if the IOSF control register value is not needed
779 static s32 ixgbe_iosf_wait(struct ixgbe_hw *hw, u32 *ctrl)
783 /* Check every 10 usec to see if the address cycle completed.
784 * The SB IOSF BUSY bit will clear when the operation is
787 for (i = 0; i < IXGBE_MDIO_COMMAND_TIMEOUT; i++) {
788 command = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL);
789 if ((command & IXGBE_SB_IOSF_CTRL_BUSY) == 0)
795 if (i == IXGBE_MDIO_COMMAND_TIMEOUT) {
796 ERROR_REPORT1(IXGBE_ERROR_POLLING, "Wait timed out\n");
797 return IXGBE_ERR_PHY;
800 return IXGBE_SUCCESS;
804 * ixgbe_write_iosf_sb_reg_x550 - Writes a value to specified register of the IOSF
806 * @hw: pointer to hardware structure
807 * @reg_addr: 32 bit PHY register to write
808 * @device_type: 3 bit device type
809 * @data: Data to write to the register
811 s32 ixgbe_write_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr,
812 u32 device_type, u32 data)
814 u32 gssr = IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_PHY0_SM;
818 ret = ixgbe_acquire_swfw_semaphore(hw, gssr);
819 if (ret != IXGBE_SUCCESS)
822 ret = ixgbe_iosf_wait(hw, NULL);
823 if (ret != IXGBE_SUCCESS)
826 command = ((reg_addr << IXGBE_SB_IOSF_CTRL_ADDR_SHIFT) |
827 (device_type << IXGBE_SB_IOSF_CTRL_TARGET_SELECT_SHIFT));
829 /* Write IOSF control register */
830 IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL, command);
832 /* Write IOSF data register */
833 IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_DATA, data);
835 ret = ixgbe_iosf_wait(hw, &command);
837 if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) {
838 error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >>
839 IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT;
840 ERROR_REPORT2(IXGBE_ERROR_POLLING,
841 "Failed to write, error %x\n", error);
846 ixgbe_release_swfw_semaphore(hw, gssr);
851 * ixgbe_read_iosf_sb_reg_x550 - Writes a value to specified register of the IOSF
853 * @hw: pointer to hardware structure
854 * @reg_addr: 32 bit PHY register to write
855 * @device_type: 3 bit device type
856 * @phy_data: Pointer to read data from the register
858 s32 ixgbe_read_iosf_sb_reg_x550(struct ixgbe_hw *hw, u32 reg_addr,
859 u32 device_type, u32 *data)
861 u32 gssr = IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_PHY0_SM;
865 ret = ixgbe_acquire_swfw_semaphore(hw, gssr);
866 if (ret != IXGBE_SUCCESS)
869 ret = ixgbe_iosf_wait(hw, NULL);
870 if (ret != IXGBE_SUCCESS)
873 command = ((reg_addr << IXGBE_SB_IOSF_CTRL_ADDR_SHIFT) |
874 (device_type << IXGBE_SB_IOSF_CTRL_TARGET_SELECT_SHIFT));
876 /* Write IOSF control register */
877 IXGBE_WRITE_REG(hw, IXGBE_SB_IOSF_INDIRECT_CTRL, command);
879 ret = ixgbe_iosf_wait(hw, &command);
881 if ((command & IXGBE_SB_IOSF_CTRL_RESP_STAT_MASK) != 0) {
882 error = (command & IXGBE_SB_IOSF_CTRL_CMPL_ERR_MASK) >>
883 IXGBE_SB_IOSF_CTRL_CMPL_ERR_SHIFT;
884 ERROR_REPORT2(IXGBE_ERROR_POLLING,
885 "Failed to read, error %x\n", error);
889 if (ret == IXGBE_SUCCESS)
890 *data = IXGBE_READ_REG(hw, IXGBE_SB_IOSF_INDIRECT_DATA);
893 ixgbe_release_swfw_semaphore(hw, gssr);
898 * ixgbe_disable_mdd_X550
899 * @hw: pointer to hardware structure
901 * Disable malicious driver detection
903 void ixgbe_disable_mdd_X550(struct ixgbe_hw *hw)
907 DEBUGFUNC("ixgbe_disable_mdd_X550");
909 /* Disable MDD for TX DMA and interrupt */
910 reg = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
911 reg &= ~(IXGBE_DMATXCTL_MDP_EN | IXGBE_DMATXCTL_MBINTEN);
912 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, reg);
914 /* Disable MDD for RX and interrupt */
915 reg = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
916 reg &= ~(IXGBE_RDRXCTL_MDP_EN | IXGBE_RDRXCTL_MBINTEN);
917 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, reg);
921 * ixgbe_enable_mdd_X550
922 * @hw: pointer to hardware structure
924 * Enable malicious driver detection
926 void ixgbe_enable_mdd_X550(struct ixgbe_hw *hw)
930 DEBUGFUNC("ixgbe_enable_mdd_X550");
932 /* Enable MDD for TX DMA and interrupt */
933 reg = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
934 reg |= (IXGBE_DMATXCTL_MDP_EN | IXGBE_DMATXCTL_MBINTEN);
935 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, reg);
937 /* Enable MDD for RX and interrupt */
938 reg = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
939 reg |= (IXGBE_RDRXCTL_MDP_EN | IXGBE_RDRXCTL_MBINTEN);
940 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, reg);
944 * ixgbe_restore_mdd_vf_X550
945 * @hw: pointer to hardware structure
948 * Restore VF that was disabled during malicious driver detection event
950 void ixgbe_restore_mdd_vf_X550(struct ixgbe_hw *hw, u32 vf)
952 u32 idx, reg, num_qs, start_q, bitmask;
954 DEBUGFUNC("ixgbe_restore_mdd_vf_X550");
956 /* Map VF to queues */
957 reg = IXGBE_READ_REG(hw, IXGBE_MRQC);
958 switch (reg & IXGBE_MRQC_MRQE_MASK) {
959 case IXGBE_MRQC_VMDQRT8TCEN:
960 num_qs = 8; /* 16 VFs / pools */
961 bitmask = 0x000000FF;
963 case IXGBE_MRQC_VMDQRSS32EN:
964 case IXGBE_MRQC_VMDQRT4TCEN:
965 num_qs = 4; /* 32 VFs / pools */
966 bitmask = 0x0000000F;
968 default: /* 64 VFs / pools */
970 bitmask = 0x00000003;
973 start_q = vf * num_qs;
975 /* Release vf's queues by clearing WQBR_TX and WQBR_RX (RW1C) */
978 reg |= (bitmask << (start_q % 32));
979 IXGBE_WRITE_REG(hw, IXGBE_WQBR_TX(idx), reg);
980 IXGBE_WRITE_REG(hw, IXGBE_WQBR_RX(idx), reg);
984 * ixgbe_mdd_event_X550
985 * @hw: pointer to hardware structure
986 * @vf_bitmap: vf bitmap of malicious vfs
988 * Handle malicious driver detection event.
990 void ixgbe_mdd_event_X550(struct ixgbe_hw *hw, u32 *vf_bitmap)
993 u32 i, j, reg, q, shift, vf, idx;
995 DEBUGFUNC("ixgbe_mdd_event_X550");
997 /* figure out pool size for mapping to vf's */
998 reg = IXGBE_READ_REG(hw, IXGBE_MRQC);
999 switch (reg & IXGBE_MRQC_MRQE_MASK) {
1000 case IXGBE_MRQC_VMDQRT8TCEN:
1001 shift = 3; /* 16 VFs / pools */
1003 case IXGBE_MRQC_VMDQRSS32EN:
1004 case IXGBE_MRQC_VMDQRT4TCEN:
1005 shift = 2; /* 32 VFs / pools */
1008 shift = 1; /* 64 VFs / pools */
1012 /* Read WQBR_TX and WQBR_RX and check for malicious queues */
1013 for (i = 0; i < 4; i++) {
1014 wqbr = IXGBE_READ_REG(hw, IXGBE_WQBR_TX(i));
1015 wqbr |= IXGBE_READ_REG(hw, IXGBE_WQBR_RX(i));
1020 /* Get malicious queue */
1021 for (j = 0; j < 32 && wqbr; j++) {
1023 if (!(wqbr & (1 << j)))
1026 /* Get queue from bitmask */
1029 /* Map queue to vf */
1032 /* Set vf bit in vf_bitmap */
1034 vf_bitmap[idx] |= (1 << (vf % 32));
1041 * ixgbe_get_media_type_X550em - Get media type
1042 * @hw: pointer to hardware structure
1044 * Returns the media type (fiber, copper, backplane)
1046 enum ixgbe_media_type ixgbe_get_media_type_X550em(struct ixgbe_hw *hw)
1048 enum ixgbe_media_type media_type;
1050 DEBUGFUNC("ixgbe_get_media_type_X550em");
1052 /* Detect if there is a copper PHY attached. */
1053 switch (hw->device_id) {
1054 case IXGBE_DEV_ID_X550EM_X_KR:
1055 case IXGBE_DEV_ID_X550EM_X_KX4:
1056 media_type = ixgbe_media_type_backplane;
1058 case IXGBE_DEV_ID_X550EM_X_SFP:
1059 media_type = ixgbe_media_type_fiber;
1061 case IXGBE_DEV_ID_X550EM_X_1G_T:
1062 case IXGBE_DEV_ID_X550EM_X_10G_T:
1063 media_type = ixgbe_media_type_copper;
1066 media_type = ixgbe_media_type_unknown;
1073 * ixgbe_supported_sfp_modules_X550em - Check if SFP module type is supported
1074 * @hw: pointer to hardware structure
1075 * @linear: TRUE if SFP module is linear
1077 static s32 ixgbe_supported_sfp_modules_X550em(struct ixgbe_hw *hw, bool *linear)
1079 DEBUGFUNC("ixgbe_supported_sfp_modules_X550em");
1081 switch (hw->phy.sfp_type) {
1082 case ixgbe_sfp_type_not_present:
1083 return IXGBE_ERR_SFP_NOT_PRESENT;
1084 case ixgbe_sfp_type_da_cu_core0:
1085 case ixgbe_sfp_type_da_cu_core1:
1088 case ixgbe_sfp_type_srlr_core0:
1089 case ixgbe_sfp_type_srlr_core1:
1090 case ixgbe_sfp_type_da_act_lmt_core0:
1091 case ixgbe_sfp_type_da_act_lmt_core1:
1092 case ixgbe_sfp_type_1g_sx_core0:
1093 case ixgbe_sfp_type_1g_sx_core1:
1094 case ixgbe_sfp_type_1g_lx_core0:
1095 case ixgbe_sfp_type_1g_lx_core1:
1098 case ixgbe_sfp_type_unknown:
1099 case ixgbe_sfp_type_1g_cu_core0:
1100 case ixgbe_sfp_type_1g_cu_core1:
1102 return IXGBE_ERR_SFP_NOT_SUPPORTED;
1105 return IXGBE_SUCCESS;
1109 * ixgbe_identify_sfp_module_X550em - Identifies SFP modules
1110 * @hw: pointer to hardware structure
1112 * Searches for and identifies the SFP module and assigns appropriate PHY type.
1114 s32 ixgbe_identify_sfp_module_X550em(struct ixgbe_hw *hw)
1119 DEBUGFUNC("ixgbe_identify_sfp_module_X550em");
1121 status = ixgbe_identify_module_generic(hw);
1123 if (status != IXGBE_SUCCESS)
1126 /* Check if SFP module is supported */
1127 status = ixgbe_supported_sfp_modules_X550em(hw, &linear);
1133 * ixgbe_setup_sfp_modules_X550em - Setup MAC link ops
1134 * @hw: pointer to hardware structure
1136 s32 ixgbe_setup_sfp_modules_X550em(struct ixgbe_hw *hw)
1141 DEBUGFUNC("ixgbe_setup_sfp_modules_X550em");
1143 /* Check if SFP module is supported */
1144 status = ixgbe_supported_sfp_modules_X550em(hw, &linear);
1146 if (status != IXGBE_SUCCESS)
1149 ixgbe_init_mac_link_ops_X550em(hw);
1150 hw->phy.ops.reset = NULL;
1152 return IXGBE_SUCCESS;
1156 * ixgbe_init_mac_link_ops_X550em - init mac link function pointers
1157 * @hw: pointer to hardware structure
1159 void ixgbe_init_mac_link_ops_X550em(struct ixgbe_hw *hw)
1161 struct ixgbe_mac_info *mac = &hw->mac;
1163 DEBUGFUNC("ixgbe_init_mac_link_ops_X550em");
1165 switch (hw->mac.ops.get_media_type(hw)) {
1166 case ixgbe_media_type_fiber:
1167 /* CS4227 does not support autoneg, so disable the laser control
1168 * functions for SFP+ fiber
1170 mac->ops.disable_tx_laser = NULL;
1171 mac->ops.enable_tx_laser = NULL;
1172 mac->ops.flap_tx_laser = NULL;
1173 mac->ops.setup_link = ixgbe_setup_mac_link_multispeed_fiber;
1174 mac->ops.setup_mac_link = ixgbe_setup_mac_link_sfp_x550em;
1175 mac->ops.set_rate_select_speed =
1176 ixgbe_set_soft_rate_select_speed;
1178 case ixgbe_media_type_copper:
1179 mac->ops.setup_link = ixgbe_setup_mac_link_t_X550em;
1180 mac->ops.check_link = ixgbe_check_link_t_X550em;
1188 * ixgbe_get_link_capabilities_x550em - Determines link capabilities
1189 * @hw: pointer to hardware structure
1190 * @speed: pointer to link speed
1191 * @autoneg: TRUE when autoneg or autotry is enabled
1193 s32 ixgbe_get_link_capabilities_X550em(struct ixgbe_hw *hw,
1194 ixgbe_link_speed *speed,
1197 DEBUGFUNC("ixgbe_get_link_capabilities_X550em");
1200 if (hw->phy.media_type == ixgbe_media_type_fiber) {
1202 /* CS4227 SFP must not enable auto-negotiation */
1205 /* Check if 1G SFP module. */
1206 if (hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core0 ||
1207 hw->phy.sfp_type == ixgbe_sfp_type_1g_sx_core1
1208 || hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core0 ||
1209 hw->phy.sfp_type == ixgbe_sfp_type_1g_lx_core1) {
1210 *speed = IXGBE_LINK_SPEED_1GB_FULL;
1211 return IXGBE_SUCCESS;
1214 /* Link capabilities are based on SFP */
1215 if (hw->phy.multispeed_fiber)
1216 *speed = IXGBE_LINK_SPEED_10GB_FULL |
1217 IXGBE_LINK_SPEED_1GB_FULL;
1219 *speed = IXGBE_LINK_SPEED_10GB_FULL;
1221 *speed = IXGBE_LINK_SPEED_10GB_FULL |
1222 IXGBE_LINK_SPEED_1GB_FULL;
1226 return IXGBE_SUCCESS;
1230 * ixgbe_get_lasi_ext_t_x550em - Determime external Base T PHY interrupt cause
1231 * @hw: pointer to hardware structure
1232 * @lsc: pointer to boolean flag which indicates whether external Base T
1233 * PHY interrupt is lsc
1235 * Determime if external Base T PHY interrupt cause is high temperature
1236 * failure alarm or link status change.
1238 * Return IXGBE_ERR_OVERTEMP if interrupt is high temperature
1239 * failure alarm, else return PHY access status.
1241 static s32 ixgbe_get_lasi_ext_t_x550em(struct ixgbe_hw *hw, bool *lsc)
1248 /* Vendor alarm triggered */
1249 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_CHIP_STD_INT_FLAG,
1250 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1253 if (status != IXGBE_SUCCESS ||
1254 !(reg & IXGBE_MDIO_GLOBAL_VEN_ALM_INT_EN))
1257 /* Vendor Auto-Neg alarm triggered or Global alarm 1 triggered */
1258 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_FLAG,
1259 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1262 if (status != IXGBE_SUCCESS ||
1263 !(reg & (IXGBE_MDIO_GLOBAL_AN_VEN_ALM_INT_EN |
1264 IXGBE_MDIO_GLOBAL_ALARM_1_INT)))
1267 /* Global alarm triggered */
1268 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_ALARM_1,
1269 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1272 if (status != IXGBE_SUCCESS)
1275 /* If high temperature failure, then return over temp error and exit */
1276 if (reg & IXGBE_MDIO_GLOBAL_ALM_1_HI_TMP_FAIL) {
1277 /* power down the PHY in case the PHY FW didn't already */
1278 ixgbe_set_copper_phy_power(hw, FALSE);
1279 return IXGBE_ERR_OVERTEMP;
1280 } else if (reg & IXGBE_MDIO_GLOBAL_ALM_1_DEV_FAULT) {
1281 /* device fault alarm triggered */
1282 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_FAULT_MSG,
1283 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1286 if (status != IXGBE_SUCCESS)
1289 /* if device fault was due to high temp alarm handle and exit */
1290 if (reg == IXGBE_MDIO_GLOBAL_FAULT_MSG_HI_TMP) {
1291 /* power down the PHY in case the PHY FW didn't */
1292 ixgbe_set_copper_phy_power(hw, FALSE);
1293 return IXGBE_ERR_OVERTEMP;
1297 /* Vendor alarm 2 triggered */
1298 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_CHIP_STD_INT_FLAG,
1299 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, ®);
1301 if (status != IXGBE_SUCCESS ||
1302 !(reg & IXGBE_MDIO_GLOBAL_STD_ALM2_INT))
1305 /* link connect/disconnect event occurred */
1306 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_TX_ALARM2,
1307 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, ®);
1309 if (status != IXGBE_SUCCESS)
1313 if (reg & IXGBE_MDIO_AUTO_NEG_VEN_LSC)
1316 return IXGBE_SUCCESS;
1320 * ixgbe_enable_lasi_ext_t_x550em - Enable external Base T PHY interrupts
1321 * @hw: pointer to hardware structure
1323 * Enable link status change and temperature failure alarm for the external
1326 * Returns PHY access status
1328 static s32 ixgbe_enable_lasi_ext_t_x550em(struct ixgbe_hw *hw)
1334 /* Clear interrupt flags */
1335 status = ixgbe_get_lasi_ext_t_x550em(hw, &lsc);
1337 /* Enable link status change alarm */
1338 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_PMA_TX_VEN_LASI_INT_MASK,
1339 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, ®);
1341 if (status != IXGBE_SUCCESS)
1344 reg |= IXGBE_MDIO_PMA_TX_VEN_LASI_INT_EN;
1346 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_PMA_TX_VEN_LASI_INT_MASK,
1347 IXGBE_MDIO_AUTO_NEG_DEV_TYPE, reg);
1349 if (status != IXGBE_SUCCESS)
1352 /* Enables high temperature failure alarm */
1353 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_MASK,
1354 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1357 if (status != IXGBE_SUCCESS)
1360 reg |= IXGBE_MDIO_GLOBAL_INT_HI_TEMP_EN;
1362 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_MASK,
1363 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1366 if (status != IXGBE_SUCCESS)
1369 /* Enable vendor Auto-Neg alarm and Global Interrupt Mask 1 alarm */
1370 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_MASK,
1371 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1374 if (status != IXGBE_SUCCESS)
1377 reg |= (IXGBE_MDIO_GLOBAL_AN_VEN_ALM_INT_EN |
1378 IXGBE_MDIO_GLOBAL_ALARM_1_INT);
1380 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_VEN_MASK,
1381 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1384 if (status != IXGBE_SUCCESS)
1387 /* Enable chip-wide vendor alarm */
1388 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_STD_MASK,
1389 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1392 if (status != IXGBE_SUCCESS)
1395 reg |= IXGBE_MDIO_GLOBAL_VEN_ALM_INT_EN;
1397 status = hw->phy.ops.write_reg(hw, IXGBE_MDIO_GLOBAL_INT_CHIP_STD_MASK,
1398 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1405 * ixgbe_setup_kr_speed_x550em - Configure the KR PHY for link speed.
1406 * @hw: pointer to hardware structure
1407 * @speed: link speed
1409 * Configures the integrated KR PHY.
1411 static s32 ixgbe_setup_kr_speed_x550em(struct ixgbe_hw *hw,
1412 ixgbe_link_speed speed)
1417 status = ixgbe_read_iosf_sb_reg_x550(hw,
1418 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1419 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
1423 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
1424 reg_val &= ~(IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR |
1425 IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX);
1427 /* Advertise 10G support. */
1428 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
1429 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KR;
1431 /* Advertise 1G support. */
1432 if (speed & IXGBE_LINK_SPEED_1GB_FULL)
1433 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_CAP_KX;
1435 /* Restart auto-negotiation. */
1436 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_RESTART;
1437 status = ixgbe_write_iosf_sb_reg_x550(hw,
1438 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1439 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1445 * ixgbe_init_phy_ops_X550em - PHY/SFP specific init
1446 * @hw: pointer to hardware structure
1448 * Initialize any function pointers that were not able to be
1449 * set during init_shared_code because the PHY/SFP type was
1450 * not known. Perform the SFP init if necessary.
1452 s32 ixgbe_init_phy_ops_X550em(struct ixgbe_hw *hw)
1454 struct ixgbe_phy_info *phy = &hw->phy;
1455 ixgbe_link_speed speed;
1458 DEBUGFUNC("ixgbe_init_phy_ops_X550em");
1460 hw->mac.ops.set_lan_id(hw);
1462 if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) {
1463 phy->phy_semaphore_mask = IXGBE_GSSR_SHARED_I2C_SM;
1464 ixgbe_setup_mux_ctl(hw);
1466 /* Save NW management interface connected on board. This is used
1467 * to determine internal PHY mode.
1469 phy->nw_mng_if_sel = IXGBE_READ_REG(hw, IXGBE_NW_MNG_IF_SEL);
1470 if (phy->nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_INT_PHY_MODE) {
1471 speed = IXGBE_LINK_SPEED_10GB_FULL |
1472 IXGBE_LINK_SPEED_1GB_FULL;
1474 phy->ops.identify_sfp = ixgbe_identify_sfp_module_X550em;
1477 /* Identify the PHY or SFP module */
1478 ret_val = phy->ops.identify(hw);
1479 if (ret_val == IXGBE_ERR_SFP_NOT_SUPPORTED)
1482 /* Setup function pointers based on detected hardware */
1483 ixgbe_init_mac_link_ops_X550em(hw);
1484 if (phy->sfp_type != ixgbe_sfp_type_unknown)
1485 phy->ops.reset = NULL;
1487 /* Set functions pointers based on phy type */
1488 switch (hw->phy.type) {
1489 case ixgbe_phy_x550em_kx4:
1490 phy->ops.setup_link = NULL;
1491 phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
1492 phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
1494 case ixgbe_phy_x550em_kr:
1495 phy->ops.setup_link = ixgbe_setup_kr_x550em;
1496 phy->ops.read_reg = ixgbe_read_phy_reg_x550em;
1497 phy->ops.write_reg = ixgbe_write_phy_reg_x550em;
1499 case ixgbe_phy_x550em_ext_t:
1500 /* Save NW management interface connected on board. This is used
1501 * to determine internal PHY mode
1503 phy->nw_mng_if_sel = IXGBE_READ_REG(hw, IXGBE_NW_MNG_IF_SEL);
1505 /* If internal link mode is XFI, then setup iXFI internal link,
1506 * else setup KR now.
1508 if (!(phy->nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_INT_PHY_MODE)) {
1509 phy->ops.setup_internal_link =
1510 ixgbe_setup_internal_phy_t_x550em;
1512 speed = IXGBE_LINK_SPEED_10GB_FULL |
1513 IXGBE_LINK_SPEED_1GB_FULL;
1514 ret_val = ixgbe_setup_kr_speed_x550em(hw, speed);
1517 /* setup SW LPLU only for first revision */
1518 if (!(IXGBE_FUSES0_REV1 & IXGBE_READ_REG(hw,
1519 IXGBE_FUSES0_GROUP(0))))
1520 phy->ops.enter_lplu = ixgbe_enter_lplu_t_x550em;
1522 phy->ops.handle_lasi = ixgbe_handle_lasi_ext_t_x550em;
1523 phy->ops.reset = ixgbe_reset_phy_t_X550em;
1532 * ixgbe_reset_hw_X550em - Perform hardware reset
1533 * @hw: pointer to hardware structure
1535 * Resets the hardware by resetting the transmit and receive units, masks
1536 * and clears all interrupts, perform a PHY reset, and perform a link (MAC)
1539 s32 ixgbe_reset_hw_X550em(struct ixgbe_hw *hw)
1541 ixgbe_link_speed link_speed;
1546 bool link_up = FALSE;
1548 DEBUGFUNC("ixgbe_reset_hw_X550em");
1550 /* Call adapter stop to disable Tx/Rx and clear interrupts */
1551 status = hw->mac.ops.stop_adapter(hw);
1552 if (status != IXGBE_SUCCESS)
1555 /* flush pending Tx transactions */
1556 ixgbe_clear_tx_pending(hw);
1558 if (hw->device_id == IXGBE_DEV_ID_X550EM_X_10G_T) {
1559 /* Config MDIO clock speed before the first MDIO PHY access */
1560 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
1561 hlreg0 &= ~IXGBE_HLREG0_MDCSPD;
1562 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
1565 /* PHY ops must be identified and initialized prior to reset */
1566 status = hw->phy.ops.init(hw);
1568 if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
1571 /* start the external PHY */
1572 if (hw->phy.type == ixgbe_phy_x550em_ext_t) {
1573 status = ixgbe_init_ext_t_x550em(hw);
1578 /* Setup SFP module if there is one present. */
1579 if (hw->phy.sfp_setup_needed) {
1580 status = hw->mac.ops.setup_sfp(hw);
1581 hw->phy.sfp_setup_needed = FALSE;
1584 if (status == IXGBE_ERR_SFP_NOT_SUPPORTED)
1588 if (!hw->phy.reset_disable && hw->phy.ops.reset)
1589 hw->phy.ops.reset(hw);
1592 /* Issue global reset to the MAC. Needs to be SW reset if link is up.
1593 * If link reset is used when link is up, it might reset the PHY when
1594 * mng is using it. If link is down or the flag to force full link
1595 * reset is set, then perform link reset.
1597 ctrl = IXGBE_CTRL_LNK_RST;
1598 if (!hw->force_full_reset) {
1599 hw->mac.ops.check_link(hw, &link_speed, &link_up, FALSE);
1601 ctrl = IXGBE_CTRL_RST;
1604 ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL);
1605 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
1606 IXGBE_WRITE_FLUSH(hw);
1608 /* Poll for reset bit to self-clear meaning reset is complete */
1609 for (i = 0; i < 10; i++) {
1611 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
1612 if (!(ctrl & IXGBE_CTRL_RST_MASK))
1616 if (ctrl & IXGBE_CTRL_RST_MASK) {
1617 status = IXGBE_ERR_RESET_FAILED;
1618 DEBUGOUT("Reset polling failed to complete.\n");
1623 /* Double resets are required for recovery from certain error
1624 * conditions. Between resets, it is necessary to stall to
1625 * allow time for any pending HW events to complete.
1627 if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
1628 hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
1632 /* Store the permanent mac address */
1633 hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
1635 /* Store MAC address from RAR0, clear receive address registers, and
1636 * clear the multicast table. Also reset num_rar_entries to 128,
1637 * since we modify this value when programming the SAN MAC address.
1639 hw->mac.num_rar_entries = 128;
1640 hw->mac.ops.init_rx_addrs(hw);
1642 if (hw->device_id == IXGBE_DEV_ID_X550EM_X_SFP)
1643 ixgbe_setup_mux_ctl(hw);
1649 * ixgbe_init_ext_t_x550em - Start (unstall) the external Base T PHY.
1650 * @hw: pointer to hardware structure
1652 s32 ixgbe_init_ext_t_x550em(struct ixgbe_hw *hw)
1657 status = hw->phy.ops.read_reg(hw,
1658 IXGBE_MDIO_TX_VENDOR_ALARMS_3,
1659 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
1662 if (status != IXGBE_SUCCESS)
1665 /* If PHY FW reset completed bit is set then this is the first
1666 * SW instance after a power on so the PHY FW must be un-stalled.
1668 if (reg & IXGBE_MDIO_TX_VENDOR_ALARMS_3_RST_MASK) {
1669 status = hw->phy.ops.read_reg(hw,
1670 IXGBE_MDIO_GLOBAL_RES_PR_10,
1671 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1674 if (status != IXGBE_SUCCESS)
1677 reg &= ~IXGBE_MDIO_POWER_UP_STALL;
1679 status = hw->phy.ops.write_reg(hw,
1680 IXGBE_MDIO_GLOBAL_RES_PR_10,
1681 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE,
1684 if (status != IXGBE_SUCCESS)
1692 * ixgbe_setup_kr_x550em - Configure the KR PHY.
1693 * @hw: pointer to hardware structure
1695 * Configures the integrated KR PHY.
1697 s32 ixgbe_setup_kr_x550em(struct ixgbe_hw *hw)
1699 return ixgbe_setup_kr_speed_x550em(hw, hw->phy.autoneg_advertised);
1703 * ixgbe_setup_mac_link_sfp_x550em - Setup internal/external the PHY for SFP
1704 * @hw: pointer to hardware structure
1706 * Configure the external PHY and the integrated KR PHY for SFP support.
1708 s32 ixgbe_setup_mac_link_sfp_x550em(struct ixgbe_hw *hw,
1709 ixgbe_link_speed speed,
1710 bool autoneg_wait_to_complete)
1713 u16 reg_slice, reg_val;
1714 bool setup_linear = FALSE;
1715 UNREFERENCED_1PARAMETER(autoneg_wait_to_complete);
1717 /* Check if SFP module is supported and linear */
1718 ret_val = ixgbe_supported_sfp_modules_X550em(hw, &setup_linear);
1720 /* If no SFP module present, then return success. Return success since
1721 * there is no reason to configure CS4227 and SFP not present error is
1722 * not excepted in the setup MAC link flow.
1724 if (ret_val == IXGBE_ERR_SFP_NOT_PRESENT)
1725 return IXGBE_SUCCESS;
1727 if (ret_val != IXGBE_SUCCESS)
1730 if (!(hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_INT_PHY_MODE)) {
1731 /* Configure CS4227 LINE side to 10G SR. */
1732 reg_slice = IXGBE_CS4227_LINE_SPARE22_MSB +
1733 (hw->bus.lan_id << 12);
1734 reg_val = IXGBE_CS4227_SPEED_10G;
1735 ret_val = ixgbe_write_i2c_combined(hw, IXGBE_CS4227, reg_slice,
1738 reg_slice = IXGBE_CS4227_LINE_SPARE24_LSB +
1739 (hw->bus.lan_id << 12);
1740 reg_val = (IXGBE_CS4227_EDC_MODE_SR << 1) | 0x1;
1741 ret_val = ixgbe_write_i2c_combined(hw, IXGBE_CS4227, reg_slice,
1744 /* Configure CS4227 for HOST connection rate then type. */
1745 reg_slice = IXGBE_CS4227_HOST_SPARE22_MSB +
1746 (hw->bus.lan_id << 12);
1747 reg_val = (speed & IXGBE_LINK_SPEED_10GB_FULL) ?
1748 IXGBE_CS4227_SPEED_10G : IXGBE_CS4227_SPEED_1G;
1749 ret_val = ixgbe_write_i2c_combined(hw, IXGBE_CS4227, reg_slice,
1752 reg_slice = IXGBE_CS4227_HOST_SPARE24_LSB +
1753 (hw->bus.lan_id << 12);
1755 reg_val = (IXGBE_CS4227_EDC_MODE_CX1 << 1) | 0x1;
1757 reg_val = (IXGBE_CS4227_EDC_MODE_SR << 1) | 0x1;
1758 ret_val = ixgbe_write_i2c_combined(hw, IXGBE_CS4227, reg_slice,
1761 /* Setup XFI internal link. */
1762 ret_val = ixgbe_setup_ixfi_x550em(hw, &speed);
1764 /* Configure internal PHY for KR/KX. */
1765 ixgbe_setup_kr_speed_x550em(hw, speed);
1767 /* Configure CS4227 LINE side to proper mode. */
1768 reg_slice = IXGBE_CS4227_LINE_SPARE24_LSB +
1769 (hw->bus.lan_id << 12);
1771 reg_val = (IXGBE_CS4227_EDC_MODE_CX1 << 1) | 0x1;
1773 reg_val = (IXGBE_CS4227_EDC_MODE_SR << 1) | 0x1;
1774 ret_val = ixgbe_write_i2c_combined(hw, IXGBE_CS4227, reg_slice,
1781 * ixgbe_setup_ixfi_x550em - Configure the KR PHY for iXFI mode.
1782 * @hw: pointer to hardware structure
1783 * @speed: the link speed to force
1785 * Configures the integrated KR PHY to use iXFI mode. Used to connect an
1786 * internal and external PHY at a specific speed, without autonegotiation.
1788 static s32 ixgbe_setup_ixfi_x550em(struct ixgbe_hw *hw, ixgbe_link_speed *speed)
1793 /* Disable AN and force speed to 10G Serial. */
1794 status = ixgbe_read_iosf_sb_reg_x550(hw,
1795 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1796 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
1797 if (status != IXGBE_SUCCESS)
1800 reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
1801 reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
1803 /* Select forced link speed for internal PHY. */
1805 case IXGBE_LINK_SPEED_10GB_FULL:
1806 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_10G;
1808 case IXGBE_LINK_SPEED_1GB_FULL:
1809 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_1G;
1812 /* Other link speeds are not supported by internal KR PHY. */
1813 return IXGBE_ERR_LINK_SETUP;
1816 status = ixgbe_write_iosf_sb_reg_x550(hw,
1817 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1818 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1819 if (status != IXGBE_SUCCESS)
1822 /* Disable training protocol FSM. */
1823 status = ixgbe_read_iosf_sb_reg_x550(hw,
1824 IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
1825 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
1826 if (status != IXGBE_SUCCESS)
1828 reg_val |= IXGBE_KRM_RX_TRN_LINKUP_CTRL_CONV_WO_PROTOCOL;
1829 status = ixgbe_write_iosf_sb_reg_x550(hw,
1830 IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
1831 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1832 if (status != IXGBE_SUCCESS)
1835 /* Disable Flex from training TXFFE. */
1836 status = ixgbe_read_iosf_sb_reg_x550(hw,
1837 IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id),
1838 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
1839 if (status != IXGBE_SUCCESS)
1841 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN;
1842 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN;
1843 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN;
1844 status = ixgbe_write_iosf_sb_reg_x550(hw,
1845 IXGBE_KRM_DSP_TXFFE_STATE_4(hw->bus.lan_id),
1846 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1847 if (status != IXGBE_SUCCESS)
1849 status = ixgbe_read_iosf_sb_reg_x550(hw,
1850 IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id),
1851 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
1852 if (status != IXGBE_SUCCESS)
1854 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_C0_EN;
1855 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CP1_CN1_EN;
1856 reg_val &= ~IXGBE_KRM_DSP_TXFFE_STATE_CO_ADAPT_EN;
1857 status = ixgbe_write_iosf_sb_reg_x550(hw,
1858 IXGBE_KRM_DSP_TXFFE_STATE_5(hw->bus.lan_id),
1859 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1860 if (status != IXGBE_SUCCESS)
1863 /* Enable override for coefficients. */
1864 status = ixgbe_read_iosf_sb_reg_x550(hw,
1865 IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id),
1866 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
1867 if (status != IXGBE_SUCCESS)
1869 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_OVRRD_EN;
1870 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CZERO_EN;
1871 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CPLUS1_OVRRD_EN;
1872 reg_val |= IXGBE_KRM_TX_COEFF_CTRL_1_CMINUS1_OVRRD_EN;
1873 status = ixgbe_write_iosf_sb_reg_x550(hw,
1874 IXGBE_KRM_TX_COEFF_CTRL_1(hw->bus.lan_id),
1875 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1876 if (status != IXGBE_SUCCESS)
1879 /* Toggle port SW reset by AN reset. */
1880 status = ixgbe_read_iosf_sb_reg_x550(hw,
1881 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1882 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
1883 if (status != IXGBE_SUCCESS)
1885 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_AN_RESTART;
1886 status = ixgbe_write_iosf_sb_reg_x550(hw,
1887 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
1888 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
1894 * ixgbe_ext_phy_t_x550em_get_link - Get ext phy link status
1895 * @hw: address of hardware structure
1896 * @link_up: address of boolean to indicate link status
1898 * Returns error code if unable to get link status.
1900 static s32 ixgbe_ext_phy_t_x550em_get_link(struct ixgbe_hw *hw, bool *link_up)
1907 /* read this twice back to back to indicate current status */
1908 ret = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
1909 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
1911 if (ret != IXGBE_SUCCESS)
1914 ret = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
1915 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
1917 if (ret != IXGBE_SUCCESS)
1920 *link_up = !!(autoneg_status & IXGBE_MDIO_AUTO_NEG_LINK_STATUS);
1922 return IXGBE_SUCCESS;
1926 * ixgbe_setup_internal_phy_t_x550em - Configure KR PHY to X557 link
1927 * @hw: point to hardware structure
1929 * Configures the link between the integrated KR PHY and the external X557 PHY
1930 * The driver will call this function when it gets a link status change
1931 * interrupt from the X557 PHY. This function configures the link speed
1932 * between the PHYs to match the link speed of the BASE-T link.
1934 * A return of a non-zero value indicates an error, and the base driver should
1935 * not report link up.
1937 s32 ixgbe_setup_internal_phy_t_x550em(struct ixgbe_hw *hw)
1939 ixgbe_link_speed force_speed;
1944 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
1945 return IXGBE_ERR_CONFIG;
1947 /* If link is not up, then there is no setup necessary so return */
1948 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
1949 if (status != IXGBE_SUCCESS)
1953 return IXGBE_SUCCESS;
1955 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_STAT,
1956 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
1958 if (status != IXGBE_SUCCESS)
1961 /* If link is not still up, then no setup is necessary so return */
1962 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
1963 if (status != IXGBE_SUCCESS)
1966 return IXGBE_SUCCESS;
1968 /* clear everything but the speed and duplex bits */
1969 speed &= IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_MASK;
1972 case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_10GB_FULL:
1973 force_speed = IXGBE_LINK_SPEED_10GB_FULL;
1975 case IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_1GB_FULL:
1976 force_speed = IXGBE_LINK_SPEED_1GB_FULL;
1979 /* Internal PHY does not support anything else */
1980 return IXGBE_ERR_INVALID_LINK_SETTINGS;
1983 return ixgbe_setup_ixfi_x550em(hw, &force_speed);
1987 * ixgbe_setup_phy_loopback_x550em - Configure the KR PHY for loopback.
1988 * @hw: pointer to hardware structure
1990 * Configures the integrated KR PHY to use internal loopback mode.
1992 s32 ixgbe_setup_phy_loopback_x550em(struct ixgbe_hw *hw)
1997 /* Disable AN and force speed to 10G Serial. */
1998 status = ixgbe_read_iosf_sb_reg_x550(hw,
1999 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
2000 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
2001 if (status != IXGBE_SUCCESS)
2003 reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_AN_ENABLE;
2004 reg_val &= ~IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_MASK;
2005 reg_val |= IXGBE_KRM_LINK_CTRL_1_TETH_FORCE_SPEED_10G;
2006 status = ixgbe_write_iosf_sb_reg_x550(hw,
2007 IXGBE_KRM_LINK_CTRL_1(hw->bus.lan_id),
2008 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
2009 if (status != IXGBE_SUCCESS)
2012 /* Set near-end loopback clocks. */
2013 status = ixgbe_read_iosf_sb_reg_x550(hw,
2014 IXGBE_KRM_PORT_CAR_GEN_CTRL(hw->bus.lan_id),
2015 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
2016 if (status != IXGBE_SUCCESS)
2018 reg_val |= IXGBE_KRM_PORT_CAR_GEN_CTRL_NELB_32B;
2019 reg_val |= IXGBE_KRM_PORT_CAR_GEN_CTRL_NELB_KRPCS;
2020 status = ixgbe_write_iosf_sb_reg_x550(hw,
2021 IXGBE_KRM_PORT_CAR_GEN_CTRL(hw->bus.lan_id),
2022 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
2023 if (status != IXGBE_SUCCESS)
2026 /* Set loopback enable. */
2027 status = ixgbe_read_iosf_sb_reg_x550(hw,
2028 IXGBE_KRM_PMD_DFX_BURNIN(hw->bus.lan_id),
2029 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
2030 if (status != IXGBE_SUCCESS)
2032 reg_val |= IXGBE_KRM_PMD_DFX_BURNIN_TX_RX_KR_LB_MASK;
2033 status = ixgbe_write_iosf_sb_reg_x550(hw,
2034 IXGBE_KRM_PMD_DFX_BURNIN(hw->bus.lan_id),
2035 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
2036 if (status != IXGBE_SUCCESS)
2039 /* Training bypass. */
2040 status = ixgbe_read_iosf_sb_reg_x550(hw,
2041 IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
2042 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
2043 if (status != IXGBE_SUCCESS)
2045 reg_val |= IXGBE_KRM_RX_TRN_LINKUP_CTRL_PROTOCOL_BYPASS;
2046 status = ixgbe_write_iosf_sb_reg_x550(hw,
2047 IXGBE_KRM_RX_TRN_LINKUP_CTRL(hw->bus.lan_id),
2048 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
2054 * ixgbe_read_ee_hostif_X550 - Read EEPROM word using a host interface command
2055 * assuming that the semaphore is already obtained.
2056 * @hw: pointer to hardware structure
2057 * @offset: offset of word in the EEPROM to read
2058 * @data: word read from the EEPROM
2060 * Reads a 16 bit word from the EEPROM using the hostif.
2062 s32 ixgbe_read_ee_hostif_data_X550(struct ixgbe_hw *hw, u16 offset,
2066 struct ixgbe_hic_read_shadow_ram buffer;
2068 DEBUGFUNC("ixgbe_read_ee_hostif_data_X550");
2069 buffer.hdr.req.cmd = FW_READ_SHADOW_RAM_CMD;
2070 buffer.hdr.req.buf_lenh = 0;
2071 buffer.hdr.req.buf_lenl = FW_READ_SHADOW_RAM_LEN;
2072 buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
2074 /* convert offset from words to bytes */
2075 buffer.address = IXGBE_CPU_TO_BE32(offset * 2);
2077 buffer.length = IXGBE_CPU_TO_BE16(sizeof(u16));
2079 status = ixgbe_host_interface_command(hw, (u32 *)&buffer,
2081 IXGBE_HI_COMMAND_TIMEOUT, FALSE);
2086 *data = (u16)IXGBE_READ_REG_ARRAY(hw, IXGBE_FLEX_MNG,
2087 FW_NVM_DATA_OFFSET);
2093 * ixgbe_read_ee_hostif_X550 - Read EEPROM word using a host interface command
2094 * @hw: pointer to hardware structure
2095 * @offset: offset of word in the EEPROM to read
2096 * @data: word read from the EEPROM
2098 * Reads a 16 bit word from the EEPROM using the hostif.
2100 s32 ixgbe_read_ee_hostif_X550(struct ixgbe_hw *hw, u16 offset,
2103 s32 status = IXGBE_SUCCESS;
2105 DEBUGFUNC("ixgbe_read_ee_hostif_X550");
2107 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
2109 status = ixgbe_read_ee_hostif_data_X550(hw, offset, data);
2110 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
2112 status = IXGBE_ERR_SWFW_SYNC;
2119 * ixgbe_read_ee_hostif_buffer_X550- Read EEPROM word(s) using hostif
2120 * @hw: pointer to hardware structure
2121 * @offset: offset of word in the EEPROM to read
2122 * @words: number of words
2123 * @data: word(s) read from the EEPROM
2125 * Reads a 16 bit word(s) from the EEPROM using the hostif.
2127 s32 ixgbe_read_ee_hostif_buffer_X550(struct ixgbe_hw *hw,
2128 u16 offset, u16 words, u16 *data)
2130 struct ixgbe_hic_read_shadow_ram buffer;
2131 u32 current_word = 0;
2136 DEBUGFUNC("ixgbe_read_ee_hostif_buffer_X550");
2138 /* Take semaphore for the entire operation. */
2139 status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
2141 DEBUGOUT("EEPROM read buffer - semaphore failed\n");
2145 if (words > FW_MAX_READ_BUFFER_SIZE / 2)
2146 words_to_read = FW_MAX_READ_BUFFER_SIZE / 2;
2148 words_to_read = words;
2150 buffer.hdr.req.cmd = FW_READ_SHADOW_RAM_CMD;
2151 buffer.hdr.req.buf_lenh = 0;
2152 buffer.hdr.req.buf_lenl = FW_READ_SHADOW_RAM_LEN;
2153 buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
2155 /* convert offset from words to bytes */
2156 buffer.address = IXGBE_CPU_TO_BE32((offset + current_word) * 2);
2157 buffer.length = IXGBE_CPU_TO_BE16(words_to_read * 2);
2159 status = ixgbe_host_interface_command(hw, (u32 *)&buffer,
2161 IXGBE_HI_COMMAND_TIMEOUT,
2165 DEBUGOUT("Host interface command failed\n");
2169 for (i = 0; i < words_to_read; i++) {
2170 u32 reg = IXGBE_FLEX_MNG + (FW_NVM_DATA_OFFSET << 2) +
2172 u32 value = IXGBE_READ_REG(hw, reg);
2174 data[current_word] = (u16)(value & 0xffff);
2177 if (i < words_to_read) {
2179 data[current_word] = (u16)(value & 0xffff);
2183 words -= words_to_read;
2187 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
2192 * ixgbe_write_ee_hostif_X550 - Write EEPROM word using hostif
2193 * @hw: pointer to hardware structure
2194 * @offset: offset of word in the EEPROM to write
2195 * @data: word write to the EEPROM
2197 * Write a 16 bit word to the EEPROM using the hostif.
2199 s32 ixgbe_write_ee_hostif_data_X550(struct ixgbe_hw *hw, u16 offset,
2203 struct ixgbe_hic_write_shadow_ram buffer;
2205 DEBUGFUNC("ixgbe_write_ee_hostif_data_X550");
2207 buffer.hdr.req.cmd = FW_WRITE_SHADOW_RAM_CMD;
2208 buffer.hdr.req.buf_lenh = 0;
2209 buffer.hdr.req.buf_lenl = FW_WRITE_SHADOW_RAM_LEN;
2210 buffer.hdr.req.checksum = FW_DEFAULT_CHECKSUM;
2213 buffer.length = IXGBE_CPU_TO_BE16(sizeof(u16));
2215 buffer.address = IXGBE_CPU_TO_BE32(offset * 2);
2217 status = ixgbe_host_interface_command(hw, (u32 *)&buffer,
2219 IXGBE_HI_COMMAND_TIMEOUT, FALSE);
2225 * ixgbe_write_ee_hostif_X550 - Write EEPROM word using hostif
2226 * @hw: pointer to hardware structure
2227 * @offset: offset of word in the EEPROM to write
2228 * @data: word write to the EEPROM
2230 * Write a 16 bit word to the EEPROM using the hostif.
2232 s32 ixgbe_write_ee_hostif_X550(struct ixgbe_hw *hw, u16 offset,
2235 s32 status = IXGBE_SUCCESS;
2237 DEBUGFUNC("ixgbe_write_ee_hostif_X550");
2239 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
2241 status = ixgbe_write_ee_hostif_data_X550(hw, offset, data);
2242 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
2244 DEBUGOUT("write ee hostif failed to get semaphore");
2245 status = IXGBE_ERR_SWFW_SYNC;
2252 * ixgbe_write_ee_hostif_buffer_X550 - Write EEPROM word(s) using hostif
2253 * @hw: pointer to hardware structure
2254 * @offset: offset of word in the EEPROM to write
2255 * @words: number of words
2256 * @data: word(s) write to the EEPROM
2258 * Write a 16 bit word(s) to the EEPROM using the hostif.
2260 s32 ixgbe_write_ee_hostif_buffer_X550(struct ixgbe_hw *hw,
2261 u16 offset, u16 words, u16 *data)
2263 s32 status = IXGBE_SUCCESS;
2266 DEBUGFUNC("ixgbe_write_ee_hostif_buffer_X550");
2268 /* Take semaphore for the entire operation. */
2269 status = hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
2270 if (status != IXGBE_SUCCESS) {
2271 DEBUGOUT("EEPROM write buffer - semaphore failed\n");
2275 for (i = 0; i < words; i++) {
2276 status = ixgbe_write_ee_hostif_data_X550(hw, offset + i,
2279 if (status != IXGBE_SUCCESS) {
2280 DEBUGOUT("Eeprom buffered write failed\n");
2285 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
2292 * ixgbe_checksum_ptr_x550 - Checksum one pointer region
2293 * @hw: pointer to hardware structure
2294 * @ptr: pointer offset in eeprom
2295 * @size: size of section pointed by ptr, if 0 first word will be used as size
2296 * @csum: address of checksum to update
2298 * Returns error status for any failure
2300 static s32 ixgbe_checksum_ptr_x550(struct ixgbe_hw *hw, u16 ptr,
2301 u16 size, u16 *csum, u16 *buffer,
2306 u16 length, bufsz, i, start;
2309 bufsz = sizeof(buf) / sizeof(buf[0]);
2311 /* Read a chunk at the pointer location */
2313 status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr, bufsz, buf);
2315 DEBUGOUT("Failed to read EEPROM image\n");
2320 if (buffer_size < ptr)
2321 return IXGBE_ERR_PARAM;
2322 local_buffer = &buffer[ptr];
2330 length = local_buffer[0];
2332 /* Skip pointer section if length is invalid. */
2333 if (length == 0xFFFF || length == 0 ||
2334 (ptr + length) >= hw->eeprom.word_size)
2335 return IXGBE_SUCCESS;
2338 if (buffer && ((u32)start + (u32)length > buffer_size))
2339 return IXGBE_ERR_PARAM;
2341 for (i = start; length; i++, length--) {
2342 if (i == bufsz && !buffer) {
2348 /* Read a chunk at the pointer location */
2349 status = ixgbe_read_ee_hostif_buffer_X550(hw, ptr,
2352 DEBUGOUT("Failed to read EEPROM image\n");
2356 *csum += local_buffer[i];
2358 return IXGBE_SUCCESS;
2362 * ixgbe_calc_checksum_X550 - Calculates and returns the checksum
2363 * @hw: pointer to hardware structure
2364 * @buffer: pointer to buffer containing calculated checksum
2365 * @buffer_size: size of buffer
2367 * Returns a negative error code on error, or the 16-bit checksum
2369 s32 ixgbe_calc_checksum_X550(struct ixgbe_hw *hw, u16 *buffer, u32 buffer_size)
2371 u16 eeprom_ptrs[IXGBE_EEPROM_LAST_WORD + 1];
2375 u16 pointer, i, size;
2377 DEBUGFUNC("ixgbe_calc_eeprom_checksum_X550");
2379 hw->eeprom.ops.init_params(hw);
2382 /* Read pointer area */
2383 status = ixgbe_read_ee_hostif_buffer_X550(hw, 0,
2384 IXGBE_EEPROM_LAST_WORD + 1,
2387 DEBUGOUT("Failed to read EEPROM image\n");
2390 local_buffer = eeprom_ptrs;
2392 if (buffer_size < IXGBE_EEPROM_LAST_WORD)
2393 return IXGBE_ERR_PARAM;
2394 local_buffer = buffer;
2398 * For X550 hardware include 0x0-0x41 in the checksum, skip the
2399 * checksum word itself
2401 for (i = 0; i <= IXGBE_EEPROM_LAST_WORD; i++)
2402 if (i != IXGBE_EEPROM_CHECKSUM)
2403 checksum += local_buffer[i];
2406 * Include all data from pointers 0x3, 0x6-0xE. This excludes the
2407 * FW, PHY module, and PCIe Expansion/Option ROM pointers.
2409 for (i = IXGBE_PCIE_ANALOG_PTR_X550; i < IXGBE_FW_PTR; i++) {
2410 if (i == IXGBE_PHY_PTR || i == IXGBE_OPTION_ROM_PTR)
2413 pointer = local_buffer[i];
2415 /* Skip pointer section if the pointer is invalid. */
2416 if (pointer == 0xFFFF || pointer == 0 ||
2417 pointer >= hw->eeprom.word_size)
2421 case IXGBE_PCIE_GENERAL_PTR:
2422 size = IXGBE_IXGBE_PCIE_GENERAL_SIZE;
2424 case IXGBE_PCIE_CONFIG0_PTR:
2425 case IXGBE_PCIE_CONFIG1_PTR:
2426 size = IXGBE_PCIE_CONFIG_SIZE;
2433 status = ixgbe_checksum_ptr_x550(hw, pointer, size, &checksum,
2434 buffer, buffer_size);
2439 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
2441 return (s32)checksum;
2445 * ixgbe_calc_eeprom_checksum_X550 - Calculates and returns the checksum
2446 * @hw: pointer to hardware structure
2448 * Returns a negative error code on error, or the 16-bit checksum
2450 s32 ixgbe_calc_eeprom_checksum_X550(struct ixgbe_hw *hw)
2452 return ixgbe_calc_checksum_X550(hw, NULL, 0);
2456 * ixgbe_validate_eeprom_checksum_X550 - Validate EEPROM checksum
2457 * @hw: pointer to hardware structure
2458 * @checksum_val: calculated checksum
2460 * Performs checksum calculation and validates the EEPROM checksum. If the
2461 * caller does not need checksum_val, the value can be NULL.
2463 s32 ixgbe_validate_eeprom_checksum_X550(struct ixgbe_hw *hw, u16 *checksum_val)
2467 u16 read_checksum = 0;
2469 DEBUGFUNC("ixgbe_validate_eeprom_checksum_X550");
2471 /* Read the first word from the EEPROM. If this times out or fails, do
2472 * not continue or we could be in for a very long wait while every
2475 status = hw->eeprom.ops.read(hw, 0, &checksum);
2477 DEBUGOUT("EEPROM read failed\n");
2481 status = hw->eeprom.ops.calc_checksum(hw);
2485 checksum = (u16)(status & 0xffff);
2487 status = ixgbe_read_ee_hostif_X550(hw, IXGBE_EEPROM_CHECKSUM,
2492 /* Verify read checksum from EEPROM is the same as
2493 * calculated checksum
2495 if (read_checksum != checksum) {
2496 status = IXGBE_ERR_EEPROM_CHECKSUM;
2497 ERROR_REPORT1(IXGBE_ERROR_INVALID_STATE,
2498 "Invalid EEPROM checksum");
2501 /* If the user cares, return the calculated checksum */
2503 *checksum_val = checksum;
2509 * ixgbe_update_eeprom_checksum_X550 - Updates the EEPROM checksum and flash
2510 * @hw: pointer to hardware structure
2512 * After writing EEPROM to shadow RAM using EEWR register, software calculates
2513 * checksum and updates the EEPROM and instructs the hardware to update
2516 s32 ixgbe_update_eeprom_checksum_X550(struct ixgbe_hw *hw)
2521 DEBUGFUNC("ixgbe_update_eeprom_checksum_X550");
2523 /* Read the first word from the EEPROM. If this times out or fails, do
2524 * not continue or we could be in for a very long wait while every
2527 status = ixgbe_read_ee_hostif_X550(hw, 0, &checksum);
2529 DEBUGOUT("EEPROM read failed\n");
2533 status = ixgbe_calc_eeprom_checksum_X550(hw);
2537 checksum = (u16)(status & 0xffff);
2539 status = ixgbe_write_ee_hostif_X550(hw, IXGBE_EEPROM_CHECKSUM,
2544 status = ixgbe_update_flash_X550(hw);
2550 * ixgbe_update_flash_X550 - Instruct HW to copy EEPROM to Flash device
2551 * @hw: pointer to hardware structure
2553 * Issue a shadow RAM dump to FW to copy EEPROM from shadow RAM to the flash.
2555 s32 ixgbe_update_flash_X550(struct ixgbe_hw *hw)
2557 s32 status = IXGBE_SUCCESS;
2558 union ixgbe_hic_hdr2 buffer;
2560 DEBUGFUNC("ixgbe_update_flash_X550");
2562 buffer.req.cmd = FW_SHADOW_RAM_DUMP_CMD;
2563 buffer.req.buf_lenh = 0;
2564 buffer.req.buf_lenl = FW_SHADOW_RAM_DUMP_LEN;
2565 buffer.req.checksum = FW_DEFAULT_CHECKSUM;
2567 status = ixgbe_host_interface_command(hw, (u32 *)&buffer,
2569 IXGBE_HI_COMMAND_TIMEOUT, FALSE);
2575 * ixgbe_get_supported_physical_layer_X550em - Returns physical layer type
2576 * @hw: pointer to hardware structure
2578 * Determines physical layer capabilities of the current configuration.
2580 u32 ixgbe_get_supported_physical_layer_X550em(struct ixgbe_hw *hw)
2582 u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
2583 u16 ext_ability = 0;
2585 DEBUGFUNC("ixgbe_get_supported_physical_layer_X550em");
2587 hw->phy.ops.identify(hw);
2589 switch (hw->phy.type) {
2590 case ixgbe_phy_x550em_kr:
2591 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KR |
2592 IXGBE_PHYSICAL_LAYER_1000BASE_KX;
2594 case ixgbe_phy_x550em_kx4:
2595 physical_layer = IXGBE_PHYSICAL_LAYER_10GBASE_KX4 |
2596 IXGBE_PHYSICAL_LAYER_1000BASE_KX;
2598 case ixgbe_phy_x550em_ext_t:
2599 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_EXT_ABILITY,
2600 IXGBE_MDIO_PMA_PMD_DEV_TYPE,
2602 if (ext_ability & IXGBE_MDIO_PHY_10GBASET_ABILITY)
2603 physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T;
2604 if (ext_ability & IXGBE_MDIO_PHY_1000BASET_ABILITY)
2605 physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T;
2611 if (hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber)
2612 physical_layer = ixgbe_get_supported_phy_sfp_layer_generic(hw);
2614 return physical_layer;
2618 * ixgbe_get_bus_info_x550em - Set PCI bus info
2619 * @hw: pointer to hardware structure
2621 * Sets bus link width and speed to unknown because X550em is
2624 s32 ixgbe_get_bus_info_X550em(struct ixgbe_hw *hw)
2627 DEBUGFUNC("ixgbe_get_bus_info_x550em");
2629 hw->bus.width = ixgbe_bus_width_unknown;
2630 hw->bus.speed = ixgbe_bus_speed_unknown;
2632 hw->mac.ops.set_lan_id(hw);
2634 return IXGBE_SUCCESS;
2638 * ixgbe_disable_rx_x550 - Disable RX unit
2640 * Enables the Rx DMA unit for x550
2642 void ixgbe_disable_rx_x550(struct ixgbe_hw *hw)
2644 u32 rxctrl, pfdtxgswc;
2646 struct ixgbe_hic_disable_rxen fw_cmd;
2648 DEBUGFUNC("ixgbe_enable_rx_dma_x550");
2650 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2651 if (rxctrl & IXGBE_RXCTRL_RXEN) {
2652 pfdtxgswc = IXGBE_READ_REG(hw, IXGBE_PFDTXGSWC);
2653 if (pfdtxgswc & IXGBE_PFDTXGSWC_VT_LBEN) {
2654 pfdtxgswc &= ~IXGBE_PFDTXGSWC_VT_LBEN;
2655 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, pfdtxgswc);
2656 hw->mac.set_lben = TRUE;
2658 hw->mac.set_lben = FALSE;
2661 fw_cmd.hdr.cmd = FW_DISABLE_RXEN_CMD;
2662 fw_cmd.hdr.buf_len = FW_DISABLE_RXEN_LEN;
2663 fw_cmd.hdr.checksum = FW_DEFAULT_CHECKSUM;
2664 fw_cmd.port_number = (u8)hw->bus.lan_id;
2666 status = ixgbe_host_interface_command(hw, (u32 *)&fw_cmd,
2667 sizeof(struct ixgbe_hic_disable_rxen),
2668 IXGBE_HI_COMMAND_TIMEOUT, TRUE);
2670 /* If we fail - disable RX using register write */
2672 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
2673 if (rxctrl & IXGBE_RXCTRL_RXEN) {
2674 rxctrl &= ~IXGBE_RXCTRL_RXEN;
2675 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl);
2682 * ixgbe_enter_lplu_x550em - Transition to low power states
2683 * @hw: pointer to hardware structure
2685 * Configures Low Power Link Up on transition to low power states
2686 * (from D0 to non-D0). Link is required to enter LPLU so avoid resetting the
2687 * X557 PHY immediately prior to entering LPLU.
2689 s32 ixgbe_enter_lplu_t_x550em(struct ixgbe_hw *hw)
2691 u16 an_10g_cntl_reg, autoneg_reg, speed;
2693 ixgbe_link_speed lcd_speed;
2697 /* SW LPLU not required on later HW revisions. */
2698 if (IXGBE_FUSES0_REV1 & IXGBE_READ_REG(hw, IXGBE_FUSES0_GROUP(0)))
2699 return IXGBE_SUCCESS;
2701 /* If blocked by MNG FW, then don't restart AN */
2702 if (ixgbe_check_reset_blocked(hw))
2703 return IXGBE_SUCCESS;
2705 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
2706 if (status != IXGBE_SUCCESS)
2709 status = ixgbe_read_eeprom(hw, NVM_INIT_CTRL_3, &hw->eeprom.ctrl_word_3);
2711 if (status != IXGBE_SUCCESS)
2714 /* If link is down, LPLU disabled in NVM, WoL disabled, or manageability
2715 * disabled, then force link down by entering low power mode.
2717 if (!link_up || !(hw->eeprom.ctrl_word_3 & NVM_INIT_CTRL_3_LPLU) ||
2718 !(hw->wol_enabled || ixgbe_mng_present(hw)))
2719 return ixgbe_set_copper_phy_power(hw, FALSE);
2722 status = ixgbe_get_lcd_t_x550em(hw, &lcd_speed);
2724 if (status != IXGBE_SUCCESS)
2727 /* If no valid LCD link speed, then force link down and exit. */
2728 if (lcd_speed == IXGBE_LINK_SPEED_UNKNOWN)
2729 return ixgbe_set_copper_phy_power(hw, FALSE);
2731 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_STAT,
2732 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
2735 if (status != IXGBE_SUCCESS)
2738 /* If no link now, speed is invalid so take link down */
2739 status = ixgbe_ext_phy_t_x550em_get_link(hw, &link_up);
2740 if (status != IXGBE_SUCCESS)
2741 return ixgbe_set_copper_phy_power(hw, FALSE);
2743 /* clear everything but the speed bits */
2744 speed &= IXGBE_MDIO_AUTO_NEG_VEN_STAT_SPEED_MASK;
2746 /* If current speed is already LCD, then exit. */
2747 if (((speed == IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_1GB) &&
2748 (lcd_speed == IXGBE_LINK_SPEED_1GB_FULL)) ||
2749 ((speed == IXGBE_MDIO_AUTO_NEG_VENDOR_STATUS_10GB) &&
2750 (lcd_speed == IXGBE_LINK_SPEED_10GB_FULL)))
2753 /* Clear AN completed indication */
2754 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_VENDOR_TX_ALARM,
2755 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
2758 if (status != IXGBE_SUCCESS)
2761 status = hw->phy.ops.read_reg(hw, IXGBE_MII_10GBASE_T_AUTONEG_CTRL_REG,
2762 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
2765 if (status != IXGBE_SUCCESS)
2768 status = hw->phy.ops.read_reg(hw,
2769 IXGBE_MII_AUTONEG_VENDOR_PROVISION_1_REG,
2770 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
2773 if (status != IXGBE_SUCCESS)
2776 save_autoneg = hw->phy.autoneg_advertised;
2778 /* Setup link at least common link speed */
2779 status = hw->mac.ops.setup_link(hw, lcd_speed, FALSE);
2781 /* restore autoneg from before setting lplu speed */
2782 hw->phy.autoneg_advertised = save_autoneg;
2788 * ixgbe_get_lcd_x550em - Determine lowest common denominator
2789 * @hw: pointer to hardware structure
2790 * @lcd_speed: pointer to lowest common link speed
2792 * Determine lowest common link speed with link partner.
2794 s32 ixgbe_get_lcd_t_x550em(struct ixgbe_hw *hw, ixgbe_link_speed *lcd_speed)
2798 u16 word = hw->eeprom.ctrl_word_3;
2800 *lcd_speed = IXGBE_LINK_SPEED_UNKNOWN;
2802 status = hw->phy.ops.read_reg(hw, IXGBE_AUTO_NEG_LP_STATUS,
2803 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
2806 if (status != IXGBE_SUCCESS)
2809 /* If link partner advertised 1G, return 1G */
2810 if (an_lp_status & IXGBE_AUTO_NEG_LP_1000BASE_CAP) {
2811 *lcd_speed = IXGBE_LINK_SPEED_1GB_FULL;
2815 /* If 10G disabled for LPLU via NVM D10GMP, then return no valid LCD */
2816 if ((hw->bus.lan_id && (word & NVM_INIT_CTRL_3_D10GMP_PORT1)) ||
2817 (word & NVM_INIT_CTRL_3_D10GMP_PORT0))
2820 /* Link partner not capable of lower speeds, return 10G */
2821 *lcd_speed = IXGBE_LINK_SPEED_10GB_FULL;
2826 * ixgbe_setup_fc_X550em - Set up flow control
2827 * @hw: pointer to hardware structure
2829 * Called at init time to set up flow control.
2831 s32 ixgbe_setup_fc_X550em(struct ixgbe_hw *hw)
2833 s32 ret_val = IXGBE_SUCCESS;
2834 u32 pause, asm_dir, reg_val;
2836 DEBUGFUNC("ixgbe_setup_fc_X550em");
2838 /* Validate the requested mode */
2839 if (hw->fc.strict_ieee && hw->fc.requested_mode == ixgbe_fc_rx_pause) {
2840 ERROR_REPORT1(IXGBE_ERROR_UNSUPPORTED,
2841 "ixgbe_fc_rx_pause not valid in strict IEEE mode\n");
2842 ret_val = IXGBE_ERR_INVALID_LINK_SETTINGS;
2846 /* 10gig parts do not have a word in the EEPROM to determine the
2847 * default flow control setting, so we explicitly set it to full.
2849 if (hw->fc.requested_mode == ixgbe_fc_default)
2850 hw->fc.requested_mode = ixgbe_fc_full;
2852 /* Determine PAUSE and ASM_DIR bits. */
2853 switch (hw->fc.requested_mode) {
2858 case ixgbe_fc_tx_pause:
2862 case ixgbe_fc_rx_pause:
2863 /* Rx Flow control is enabled and Tx Flow control is
2864 * disabled by software override. Since there really
2865 * isn't a way to advertise that we are capable of RX
2866 * Pause ONLY, we will advertise that we support both
2867 * symmetric and asymmetric Rx PAUSE, as such we fall
2868 * through to the fc_full statement. Later, we will
2869 * disable the adapter's ability to send PAUSE frames.
2876 ERROR_REPORT1(IXGBE_ERROR_ARGUMENT,
2877 "Flow control param set incorrectly\n");
2878 ret_val = IXGBE_ERR_CONFIG;
2882 if (hw->device_id == IXGBE_DEV_ID_X550EM_X_KR) {
2883 ret_val = ixgbe_read_iosf_sb_reg_x550(hw,
2884 IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
2885 IXGBE_SB_IOSF_TARGET_KR_PHY, ®_val);
2886 if (ret_val != IXGBE_SUCCESS)
2888 reg_val &= ~(IXGBE_KRM_AN_CNTL_1_SYM_PAUSE |
2889 IXGBE_KRM_AN_CNTL_1_ASM_PAUSE);
2891 reg_val |= IXGBE_KRM_AN_CNTL_1_SYM_PAUSE;
2893 reg_val |= IXGBE_KRM_AN_CNTL_1_ASM_PAUSE;
2894 ret_val = ixgbe_write_iosf_sb_reg_x550(hw,
2895 IXGBE_KRM_AN_CNTL_1(hw->bus.lan_id),
2896 IXGBE_SB_IOSF_TARGET_KR_PHY, reg_val);
2898 /* This device does not fully support AN. */
2899 hw->fc.disable_fc_autoneg = TRUE;
2907 * ixgbe_set_mux - Set mux for port 1 access with CS4227
2908 * @hw: pointer to hardware structure
2909 * @state: set mux if 1, clear if 0
2911 static void ixgbe_set_mux(struct ixgbe_hw *hw, u8 state)
2915 if (!hw->bus.lan_id)
2917 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
2919 esdp |= IXGBE_ESDP_SDP1;
2921 esdp &= ~IXGBE_ESDP_SDP1;
2922 IXGBE_WRITE_REG(hw, IXGBE_ESDP, esdp);
2923 IXGBE_WRITE_FLUSH(hw);
2927 * ixgbe_acquire_swfw_sync_X550em - Acquire SWFW semaphore
2928 * @hw: pointer to hardware structure
2929 * @mask: Mask to specify which semaphore to acquire
2931 * Acquires the SWFW semaphore and sets the I2C MUX
2933 s32 ixgbe_acquire_swfw_sync_X550em(struct ixgbe_hw *hw, u32 mask)
2937 DEBUGFUNC("ixgbe_acquire_swfw_sync_X550em");
2939 status = ixgbe_acquire_swfw_sync_X540(hw, mask);
2943 if (mask & IXGBE_GSSR_I2C_MASK)
2944 ixgbe_set_mux(hw, 1);
2946 return IXGBE_SUCCESS;
2950 * ixgbe_release_swfw_sync_X550em - Release SWFW semaphore
2951 * @hw: pointer to hardware structure
2952 * @mask: Mask to specify which semaphore to release
2954 * Releases the SWFW semaphore and sets the I2C MUX
2956 void ixgbe_release_swfw_sync_X550em(struct ixgbe_hw *hw, u32 mask)
2958 DEBUGFUNC("ixgbe_release_swfw_sync_X550em");
2960 if (mask & IXGBE_GSSR_I2C_MASK)
2961 ixgbe_set_mux(hw, 0);
2963 ixgbe_release_swfw_sync_X540(hw, mask);
2967 * ixgbe_handle_lasi_ext_t_x550em - Handle external Base T PHY interrupt
2968 * @hw: pointer to hardware structure
2970 * Handle external Base T PHY interrupt. If high temperature
2971 * failure alarm then return error, else if link status change
2972 * then setup internal/external PHY link
2974 * Return IXGBE_ERR_OVERTEMP if interrupt is high temperature
2975 * failure alarm, else return PHY access status.
2977 s32 ixgbe_handle_lasi_ext_t_x550em(struct ixgbe_hw *hw)
2982 status = ixgbe_get_lasi_ext_t_x550em(hw, &lsc);
2984 if (status != IXGBE_SUCCESS)
2988 return ixgbe_setup_internal_phy(hw);
2990 return IXGBE_SUCCESS;
2994 * ixgbe_setup_mac_link_t_X550em - Sets the auto advertised link speed
2995 * @hw: pointer to hardware structure
2996 * @speed: new link speed
2997 * @autoneg_wait_to_complete: TRUE when waiting for completion is needed
2999 * Setup internal/external PHY link speed based on link speed, then set
3000 * external PHY auto advertised link speed.
3002 * Returns error status for any failure
3004 s32 ixgbe_setup_mac_link_t_X550em(struct ixgbe_hw *hw,
3005 ixgbe_link_speed speed,
3006 bool autoneg_wait_to_complete)
3009 ixgbe_link_speed force_speed;
3011 DEBUGFUNC("ixgbe_setup_mac_link_t_X550em");
3013 /* Setup internal/external PHY link speed to iXFI (10G), unless
3014 * only 1G is auto advertised then setup KX link.
3016 if (speed & IXGBE_LINK_SPEED_10GB_FULL)
3017 force_speed = IXGBE_LINK_SPEED_10GB_FULL;
3019 force_speed = IXGBE_LINK_SPEED_1GB_FULL;
3021 /* If internal link mode is XFI, then setup XFI internal link. */
3022 if (!(hw->phy.nw_mng_if_sel & IXGBE_NW_MNG_IF_SEL_INT_PHY_MODE)) {
3023 status = ixgbe_setup_ixfi_x550em(hw, &force_speed);
3025 if (status != IXGBE_SUCCESS)
3029 return hw->phy.ops.setup_link_speed(hw, speed, autoneg_wait_to_complete);
3033 * ixgbe_check_link_t_X550em - Determine link and speed status
3034 * @hw: pointer to hardware structure
3035 * @speed: pointer to link speed
3036 * @link_up: TRUE when link is up
3037 * @link_up_wait_to_complete: bool used to wait for link up or not
3039 * Check that both the MAC and X557 external PHY have link.
3041 s32 ixgbe_check_link_t_X550em(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
3042 bool *link_up, bool link_up_wait_to_complete)
3047 if (hw->mac.ops.get_media_type(hw) != ixgbe_media_type_copper)
3048 return IXGBE_ERR_CONFIG;
3050 status = ixgbe_check_mac_link_generic(hw, speed, link_up,
3051 link_up_wait_to_complete);
3053 /* If check link fails or MAC link is not up, then return */
3054 if (status != IXGBE_SUCCESS || !(*link_up))
3057 /* MAC link is up, so check external PHY link.
3058 * Read this twice back to back to indicate current status.
3060 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
3061 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
3064 if (status != IXGBE_SUCCESS)
3067 status = hw->phy.ops.read_reg(hw, IXGBE_MDIO_AUTO_NEG_STATUS,
3068 IXGBE_MDIO_AUTO_NEG_DEV_TYPE,
3071 if (status != IXGBE_SUCCESS)
3074 /* If external PHY link is not up, then indicate link not up */
3075 if (!(autoneg_status & IXGBE_MDIO_AUTO_NEG_LINK_STATUS))
3078 return IXGBE_SUCCESS;
3082 * ixgbe_reset_phy_t_X550em - Performs X557 PHY reset and enables LASI
3083 * @hw: pointer to hardware structure
3085 s32 ixgbe_reset_phy_t_X550em(struct ixgbe_hw *hw)
3089 status = ixgbe_reset_phy_generic(hw);
3091 if (status != IXGBE_SUCCESS)
3094 /* Configure Link Status Alarm and Temperature Threshold interrupts */
3095 return ixgbe_enable_lasi_ext_t_x550em(hw);
3099 * ixgbe_led_on_t_X550em - Turns on the software controllable LEDs.
3100 * @hw: pointer to hardware structure
3101 * @led_idx: led number to turn on
3103 s32 ixgbe_led_on_t_X550em(struct ixgbe_hw *hw, u32 led_idx)
3107 DEBUGFUNC("ixgbe_led_on_t_X550em");
3109 if (led_idx >= IXGBE_X557_MAX_LED_INDEX)
3110 return IXGBE_ERR_PARAM;
3112 /* To turn on the LED, set mode to ON. */
3113 ixgbe_read_phy_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
3114 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE, &phy_data);
3115 phy_data |= IXGBE_X557_LED_MANUAL_SET_MASK;
3116 ixgbe_write_phy_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
3117 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE, phy_data);
3119 return IXGBE_SUCCESS;
3123 * ixgbe_led_off_t_X550em - Turns off the software controllable LEDs.
3124 * @hw: pointer to hardware structure
3125 * @led_idx: led number to turn off
3127 s32 ixgbe_led_off_t_X550em(struct ixgbe_hw *hw, u32 led_idx)
3131 DEBUGFUNC("ixgbe_led_off_t_X550em");
3133 if (led_idx >= IXGBE_X557_MAX_LED_INDEX)
3134 return IXGBE_ERR_PARAM;
3136 /* To turn on the LED, set mode to ON. */
3137 ixgbe_read_phy_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
3138 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE, &phy_data);
3139 phy_data &= ~IXGBE_X557_LED_MANUAL_SET_MASK;
3140 ixgbe_write_phy_reg(hw, IXGBE_X557_LED_PROVISIONING + led_idx,
3141 IXGBE_MDIO_VENDOR_SPECIFIC_1_DEV_TYPE, phy_data);
3143 return IXGBE_SUCCESS;