1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2018
5 #include "ixgbe_x540.h"
6 #include "ixgbe_type.h"
8 #include "ixgbe_common.h"
11 #define IXGBE_X540_MAX_TX_QUEUES 128
12 #define IXGBE_X540_MAX_RX_QUEUES 128
13 #define IXGBE_X540_RAR_ENTRIES 128
14 #define IXGBE_X540_MC_TBL_SIZE 128
15 #define IXGBE_X540_VFT_TBL_SIZE 128
16 #define IXGBE_X540_RX_PB_SIZE 384
18 STATIC s32 ixgbe_poll_flash_update_done_X540(struct ixgbe_hw *hw);
19 STATIC s32 ixgbe_get_swfw_sync_semaphore(struct ixgbe_hw *hw);
20 STATIC void ixgbe_release_swfw_sync_semaphore(struct ixgbe_hw *hw);
23 * ixgbe_init_ops_X540 - Inits func ptrs and MAC type
24 * @hw: pointer to hardware structure
26 * Initialize the function pointers and assign the MAC type for X540.
27 * Does not touch the hardware.
29 s32 ixgbe_init_ops_X540(struct ixgbe_hw *hw)
31 struct ixgbe_mac_info *mac = &hw->mac;
32 struct ixgbe_phy_info *phy = &hw->phy;
33 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
36 DEBUGFUNC("ixgbe_init_ops_X540");
38 ret_val = ixgbe_init_phy_ops_generic(hw);
39 ret_val = ixgbe_init_ops_generic(hw);
43 eeprom->ops.init_params = ixgbe_init_eeprom_params_X540;
44 eeprom->ops.read = ixgbe_read_eerd_X540;
45 eeprom->ops.read_buffer = ixgbe_read_eerd_buffer_X540;
46 eeprom->ops.write = ixgbe_write_eewr_X540;
47 eeprom->ops.write_buffer = ixgbe_write_eewr_buffer_X540;
48 eeprom->ops.update_checksum = ixgbe_update_eeprom_checksum_X540;
49 eeprom->ops.validate_checksum = ixgbe_validate_eeprom_checksum_X540;
50 eeprom->ops.calc_checksum = ixgbe_calc_eeprom_checksum_X540;
53 phy->ops.init = ixgbe_init_phy_ops_generic;
54 phy->ops.reset = NULL;
55 phy->ops.set_phy_power = ixgbe_set_copper_phy_power;
58 mac->ops.reset_hw = ixgbe_reset_hw_X540;
59 mac->ops.enable_relaxed_ordering = ixgbe_enable_relaxed_ordering_gen2;
60 mac->ops.get_media_type = ixgbe_get_media_type_X540;
61 mac->ops.get_supported_physical_layer =
62 ixgbe_get_supported_physical_layer_X540;
63 mac->ops.read_analog_reg8 = NULL;
64 mac->ops.write_analog_reg8 = NULL;
65 mac->ops.start_hw = ixgbe_start_hw_X540;
66 mac->ops.get_san_mac_addr = ixgbe_get_san_mac_addr_generic;
67 mac->ops.set_san_mac_addr = ixgbe_set_san_mac_addr_generic;
68 mac->ops.get_device_caps = ixgbe_get_device_caps_generic;
69 mac->ops.get_wwn_prefix = ixgbe_get_wwn_prefix_generic;
70 mac->ops.get_fcoe_boot_status = ixgbe_get_fcoe_boot_status_generic;
71 mac->ops.acquire_swfw_sync = ixgbe_acquire_swfw_sync_X540;
72 mac->ops.release_swfw_sync = ixgbe_release_swfw_sync_X540;
73 mac->ops.init_swfw_sync = ixgbe_init_swfw_sync_X540;
74 mac->ops.disable_sec_rx_path = ixgbe_disable_sec_rx_path_generic;
75 mac->ops.enable_sec_rx_path = ixgbe_enable_sec_rx_path_generic;
77 /* RAR, Multicast, VLAN */
78 mac->ops.set_vmdq = ixgbe_set_vmdq_generic;
79 mac->ops.set_vmdq_san_mac = ixgbe_set_vmdq_san_mac_generic;
80 mac->ops.clear_vmdq = ixgbe_clear_vmdq_generic;
81 mac->ops.insert_mac_addr = ixgbe_insert_mac_addr_generic;
82 mac->rar_highwater = 1;
83 mac->ops.set_vfta = ixgbe_set_vfta_generic;
84 mac->ops.set_vlvf = ixgbe_set_vlvf_generic;
85 mac->ops.clear_vfta = ixgbe_clear_vfta_generic;
86 mac->ops.init_uta_tables = ixgbe_init_uta_tables_generic;
87 mac->ops.set_mac_anti_spoofing = ixgbe_set_mac_anti_spoofing;
88 mac->ops.set_vlan_anti_spoofing = ixgbe_set_vlan_anti_spoofing;
91 mac->ops.get_link_capabilities =
92 ixgbe_get_copper_link_capabilities_generic;
93 mac->ops.setup_link = ixgbe_setup_mac_link_X540;
94 mac->ops.setup_rxpba = ixgbe_set_rxpba_generic;
95 mac->ops.check_link = ixgbe_check_mac_link_generic;
98 mac->mcft_size = IXGBE_X540_MC_TBL_SIZE;
99 mac->vft_size = IXGBE_X540_VFT_TBL_SIZE;
100 mac->num_rar_entries = IXGBE_X540_RAR_ENTRIES;
101 mac->rx_pb_size = IXGBE_X540_RX_PB_SIZE;
102 mac->max_rx_queues = IXGBE_X540_MAX_RX_QUEUES;
103 mac->max_tx_queues = IXGBE_X540_MAX_TX_QUEUES;
104 mac->max_msix_vectors = ixgbe_get_pcie_msix_count_generic(hw);
108 * ARC supported; valid only if manageability features are
111 mac->arc_subsystem_valid = !!(IXGBE_READ_REG(hw, IXGBE_FWSM_BY_MAC(hw))
112 & IXGBE_FWSM_MODE_MASK);
114 hw->mbx.ops.init_params = ixgbe_init_mbx_params_pf;
117 mac->ops.blink_led_start = ixgbe_blink_led_start_X540;
118 mac->ops.blink_led_stop = ixgbe_blink_led_stop_X540;
120 /* Manageability interface */
121 mac->ops.set_fw_drv_ver = ixgbe_set_fw_drv_ver_generic;
123 mac->ops.get_rtrup2tc = ixgbe_dcb_get_rtrup2tc_generic;
129 * ixgbe_get_link_capabilities_X540 - Determines link capabilities
130 * @hw: pointer to hardware structure
131 * @speed: pointer to link speed
132 * @autoneg: true when autoneg or autotry is enabled
134 * Determines the link capabilities by reading the AUTOC register.
136 s32 ixgbe_get_link_capabilities_X540(struct ixgbe_hw *hw,
137 ixgbe_link_speed *speed,
140 ixgbe_get_copper_link_capabilities_generic(hw, speed, autoneg);
142 return IXGBE_SUCCESS;
146 * ixgbe_get_media_type_X540 - Get media type
147 * @hw: pointer to hardware structure
149 * Returns the media type (fiber, copper, backplane)
151 enum ixgbe_media_type ixgbe_get_media_type_X540(struct ixgbe_hw *hw)
153 UNREFERENCED_1PARAMETER(hw);
154 return ixgbe_media_type_copper;
158 * ixgbe_setup_mac_link_X540 - Sets the auto advertised capabilities
159 * @hw: pointer to hardware structure
160 * @speed: new link speed
161 * @autoneg_wait_to_complete: true when waiting for completion is needed
163 s32 ixgbe_setup_mac_link_X540(struct ixgbe_hw *hw,
164 ixgbe_link_speed speed,
165 bool autoneg_wait_to_complete)
167 DEBUGFUNC("ixgbe_setup_mac_link_X540");
168 return hw->phy.ops.setup_link_speed(hw, speed, autoneg_wait_to_complete);
172 * ixgbe_reset_hw_X540 - Perform hardware reset
173 * @hw: pointer to hardware structure
175 * Resets the hardware by resetting the transmit and receive units, masks
176 * and clears all interrupts, and perform a reset.
178 s32 ixgbe_reset_hw_X540(struct ixgbe_hw *hw)
182 u32 swfw_mask = hw->phy.phy_semaphore_mask;
184 DEBUGFUNC("ixgbe_reset_hw_X540");
186 /* Call adapter stop to disable tx/rx and clear interrupts */
187 status = hw->mac.ops.stop_adapter(hw);
188 if (status != IXGBE_SUCCESS)
191 /* flush pending Tx transactions */
192 ixgbe_clear_tx_pending(hw);
195 status = hw->mac.ops.acquire_swfw_sync(hw, swfw_mask);
196 if (status != IXGBE_SUCCESS) {
197 ERROR_REPORT2(IXGBE_ERROR_CAUTION,
198 "semaphore failed with %d", status);
199 return IXGBE_ERR_SWFW_SYNC;
201 ctrl = IXGBE_CTRL_RST;
202 ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL);
203 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
204 IXGBE_WRITE_FLUSH(hw);
205 hw->mac.ops.release_swfw_sync(hw, swfw_mask);
207 /* Poll for reset bit to self-clear indicating reset is complete */
208 for (i = 0; i < 10; i++) {
210 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
211 if (!(ctrl & IXGBE_CTRL_RST_MASK))
215 if (ctrl & IXGBE_CTRL_RST_MASK) {
216 status = IXGBE_ERR_RESET_FAILED;
217 ERROR_REPORT1(IXGBE_ERROR_POLLING,
218 "Reset polling failed to complete.\n");
223 * Double resets are required for recovery from certain error
224 * conditions. Between resets, it is necessary to stall to allow time
225 * for any pending HW events to complete.
227 if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
228 hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
232 /* Set the Rx packet buffer size. */
233 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0), 384 << IXGBE_RXPBSIZE_SHIFT);
235 /* Store the permanent mac address */
236 hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
239 * Store MAC address from RAR0, clear receive address registers, and
240 * clear the multicast table. Also reset num_rar_entries to 128,
241 * since we modify this value when programming the SAN MAC address.
243 hw->mac.num_rar_entries = 128;
244 hw->mac.ops.init_rx_addrs(hw);
246 /* Store the permanent SAN mac address */
247 hw->mac.ops.get_san_mac_addr(hw, hw->mac.san_addr);
249 /* Add the SAN MAC address to the RAR only if it's a valid address */
250 if (ixgbe_validate_mac_addr(hw->mac.san_addr) == 0) {
251 /* Save the SAN MAC RAR index */
252 hw->mac.san_mac_rar_index = hw->mac.num_rar_entries - 1;
254 hw->mac.ops.set_rar(hw, hw->mac.san_mac_rar_index,
255 hw->mac.san_addr, 0, IXGBE_RAH_AV);
257 /* clear VMDq pool/queue selection for this RAR */
258 hw->mac.ops.clear_vmdq(hw, hw->mac.san_mac_rar_index,
259 IXGBE_CLEAR_VMDQ_ALL);
261 /* Reserve the last RAR for the SAN MAC address */
262 hw->mac.num_rar_entries--;
265 /* Store the alternative WWNN/WWPN prefix */
266 hw->mac.ops.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
267 &hw->mac.wwpn_prefix);
274 * ixgbe_start_hw_X540 - Prepare hardware for Tx/Rx
275 * @hw: pointer to hardware structure
277 * Starts the hardware using the generic start_hw function
278 * and the generation start_hw function.
279 * Then performs revision-specific operations, if any.
281 s32 ixgbe_start_hw_X540(struct ixgbe_hw *hw)
283 s32 ret_val = IXGBE_SUCCESS;
285 DEBUGFUNC("ixgbe_start_hw_X540");
287 ret_val = ixgbe_start_hw_generic(hw);
288 if (ret_val != IXGBE_SUCCESS)
291 ret_val = ixgbe_start_hw_gen2(hw);
298 * ixgbe_get_supported_physical_layer_X540 - Returns physical layer type
299 * @hw: pointer to hardware structure
301 * Determines physical layer capabilities of the current configuration.
303 u64 ixgbe_get_supported_physical_layer_X540(struct ixgbe_hw *hw)
305 u64 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
308 DEBUGFUNC("ixgbe_get_supported_physical_layer_X540");
310 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_EXT_ABILITY,
311 IXGBE_MDIO_PMA_PMD_DEV_TYPE, &ext_ability);
312 if (ext_ability & IXGBE_MDIO_PHY_10GBASET_ABILITY)
313 physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T;
314 if (ext_ability & IXGBE_MDIO_PHY_1000BASET_ABILITY)
315 physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T;
316 if (ext_ability & IXGBE_MDIO_PHY_100BASETX_ABILITY)
317 physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX;
319 return physical_layer;
323 * ixgbe_init_eeprom_params_X540 - Initialize EEPROM params
324 * @hw: pointer to hardware structure
326 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
327 * ixgbe_hw struct in order to set up EEPROM access.
329 s32 ixgbe_init_eeprom_params_X540(struct ixgbe_hw *hw)
331 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
335 DEBUGFUNC("ixgbe_init_eeprom_params_X540");
337 if (eeprom->type == ixgbe_eeprom_uninitialized) {
338 eeprom->semaphore_delay = 10;
339 eeprom->type = ixgbe_flash;
341 eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
342 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
343 IXGBE_EEC_SIZE_SHIFT);
344 eeprom->word_size = 1 << (eeprom_size +
345 IXGBE_EEPROM_WORD_SIZE_SHIFT);
347 DEBUGOUT2("Eeprom params: type = %d, size = %d\n",
348 eeprom->type, eeprom->word_size);
351 return IXGBE_SUCCESS;
355 * ixgbe_read_eerd_X540- Read EEPROM word using EERD
356 * @hw: pointer to hardware structure
357 * @offset: offset of word in the EEPROM to read
358 * @data: word read from the EEPROM
360 * Reads a 16 bit word from the EEPROM using the EERD register.
362 s32 ixgbe_read_eerd_X540(struct ixgbe_hw *hw, u16 offset, u16 *data)
364 s32 status = IXGBE_SUCCESS;
366 DEBUGFUNC("ixgbe_read_eerd_X540");
367 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
369 status = ixgbe_read_eerd_generic(hw, offset, data);
370 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
372 status = IXGBE_ERR_SWFW_SYNC;
379 * ixgbe_read_eerd_buffer_X540- Read EEPROM word(s) using EERD
380 * @hw: pointer to hardware structure
381 * @offset: offset of word in the EEPROM to read
382 * @words: number of words
383 * @data: word(s) read from the EEPROM
385 * Reads a 16 bit word(s) from the EEPROM using the EERD register.
387 s32 ixgbe_read_eerd_buffer_X540(struct ixgbe_hw *hw,
388 u16 offset, u16 words, u16 *data)
390 s32 status = IXGBE_SUCCESS;
392 DEBUGFUNC("ixgbe_read_eerd_buffer_X540");
393 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
395 status = ixgbe_read_eerd_buffer_generic(hw, offset,
397 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
399 status = IXGBE_ERR_SWFW_SYNC;
406 * ixgbe_write_eewr_X540 - Write EEPROM word using EEWR
407 * @hw: pointer to hardware structure
408 * @offset: offset of word in the EEPROM to write
409 * @data: word write to the EEPROM
411 * Write a 16 bit word to the EEPROM using the EEWR register.
413 s32 ixgbe_write_eewr_X540(struct ixgbe_hw *hw, u16 offset, u16 data)
415 s32 status = IXGBE_SUCCESS;
417 DEBUGFUNC("ixgbe_write_eewr_X540");
418 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
420 status = ixgbe_write_eewr_generic(hw, offset, data);
421 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
423 status = IXGBE_ERR_SWFW_SYNC;
430 * ixgbe_write_eewr_buffer_X540 - Write EEPROM word(s) using EEWR
431 * @hw: pointer to hardware structure
432 * @offset: offset of word in the EEPROM to write
433 * @words: number of words
434 * @data: word(s) write to the EEPROM
436 * Write a 16 bit word(s) to the EEPROM using the EEWR register.
438 s32 ixgbe_write_eewr_buffer_X540(struct ixgbe_hw *hw,
439 u16 offset, u16 words, u16 *data)
441 s32 status = IXGBE_SUCCESS;
443 DEBUGFUNC("ixgbe_write_eewr_buffer_X540");
444 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
446 status = ixgbe_write_eewr_buffer_generic(hw, offset,
448 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
450 status = IXGBE_ERR_SWFW_SYNC;
457 * ixgbe_calc_eeprom_checksum_X540 - Calculates and returns the checksum
459 * This function does not use synchronization for EERD and EEWR. It can
460 * be used internally by function which utilize ixgbe_acquire_swfw_sync_X540.
462 * @hw: pointer to hardware structure
464 * Returns a negative error code on error, or the 16-bit checksum
466 s32 ixgbe_calc_eeprom_checksum_X540(struct ixgbe_hw *hw)
473 u16 ptr_start = IXGBE_PCIE_ANALOG_PTR;
475 /* Do not use hw->eeprom.ops.read because we do not want to take
476 * the synchronization semaphores here. Instead use
477 * ixgbe_read_eerd_generic
480 DEBUGFUNC("ixgbe_calc_eeprom_checksum_X540");
482 /* Include 0x0 up to IXGBE_EEPROM_CHECKSUM; do not include the
485 for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
486 if (ixgbe_read_eerd_generic(hw, i, &word)) {
487 DEBUGOUT("EEPROM read failed\n");
488 return IXGBE_ERR_EEPROM;
493 /* Include all data from pointers 0x3, 0x6-0xE. This excludes the
494 * FW, PHY module, and PCIe Expansion/Option ROM pointers.
496 for (i = ptr_start; i < IXGBE_FW_PTR; i++) {
497 if (i == IXGBE_PHY_PTR || i == IXGBE_OPTION_ROM_PTR)
500 if (ixgbe_read_eerd_generic(hw, i, &pointer)) {
501 DEBUGOUT("EEPROM read failed\n");
502 return IXGBE_ERR_EEPROM;
505 /* Skip pointer section if the pointer is invalid. */
506 if (pointer == 0xFFFF || pointer == 0 ||
507 pointer >= hw->eeprom.word_size)
510 if (ixgbe_read_eerd_generic(hw, pointer, &length)) {
511 DEBUGOUT("EEPROM read failed\n");
512 return IXGBE_ERR_EEPROM;
515 /* Skip pointer section if length is invalid. */
516 if (length == 0xFFFF || length == 0 ||
517 (pointer + length) >= hw->eeprom.word_size)
520 for (j = pointer + 1; j <= pointer + length; j++) {
521 if (ixgbe_read_eerd_generic(hw, j, &word)) {
522 DEBUGOUT("EEPROM read failed\n");
523 return IXGBE_ERR_EEPROM;
529 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
531 return (s32)checksum;
535 * ixgbe_validate_eeprom_checksum_X540 - Validate EEPROM checksum
536 * @hw: pointer to hardware structure
537 * @checksum_val: calculated checksum
539 * Performs checksum calculation and validates the EEPROM checksum. If the
540 * caller does not need checksum_val, the value can be NULL.
542 s32 ixgbe_validate_eeprom_checksum_X540(struct ixgbe_hw *hw,
547 u16 read_checksum = 0;
549 DEBUGFUNC("ixgbe_validate_eeprom_checksum_X540");
551 /* Read the first word from the EEPROM. If this times out or fails, do
552 * not continue or we could be in for a very long wait while every
555 status = hw->eeprom.ops.read(hw, 0, &checksum);
557 DEBUGOUT("EEPROM read failed\n");
561 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM))
562 return IXGBE_ERR_SWFW_SYNC;
564 status = hw->eeprom.ops.calc_checksum(hw);
568 checksum = (u16)(status & 0xffff);
570 /* Do not use hw->eeprom.ops.read because we do not want to take
571 * the synchronization semaphores twice here.
573 status = ixgbe_read_eerd_generic(hw, IXGBE_EEPROM_CHECKSUM,
578 /* Verify read checksum from EEPROM is the same as
579 * calculated checksum
581 if (read_checksum != checksum) {
582 ERROR_REPORT1(IXGBE_ERROR_INVALID_STATE,
583 "Invalid EEPROM checksum");
584 status = IXGBE_ERR_EEPROM_CHECKSUM;
587 /* If the user cares, return the calculated checksum */
589 *checksum_val = checksum;
592 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
598 * ixgbe_update_eeprom_checksum_X540 - Updates the EEPROM checksum and flash
599 * @hw: pointer to hardware structure
601 * After writing EEPROM to shadow RAM using EEWR register, software calculates
602 * checksum and updates the EEPROM and instructs the hardware to update
605 s32 ixgbe_update_eeprom_checksum_X540(struct ixgbe_hw *hw)
610 DEBUGFUNC("ixgbe_update_eeprom_checksum_X540");
612 /* Read the first word from the EEPROM. If this times out or fails, do
613 * not continue or we could be in for a very long wait while every
616 status = hw->eeprom.ops.read(hw, 0, &checksum);
618 DEBUGOUT("EEPROM read failed\n");
622 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM))
623 return IXGBE_ERR_SWFW_SYNC;
625 status = hw->eeprom.ops.calc_checksum(hw);
629 checksum = (u16)(status & 0xffff);
631 /* Do not use hw->eeprom.ops.write because we do not want to
632 * take the synchronization semaphores twice here.
634 status = ixgbe_write_eewr_generic(hw, IXGBE_EEPROM_CHECKSUM, checksum);
638 status = ixgbe_update_flash_X540(hw);
641 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
647 * ixgbe_update_flash_X540 - Instruct HW to copy EEPROM to Flash device
648 * @hw: pointer to hardware structure
650 * Set FLUP (bit 23) of the EEC register to instruct Hardware to copy
651 * EEPROM from shadow RAM to the flash device.
653 s32 ixgbe_update_flash_X540(struct ixgbe_hw *hw)
658 DEBUGFUNC("ixgbe_update_flash_X540");
660 status = ixgbe_poll_flash_update_done_X540(hw);
661 if (status == IXGBE_ERR_EEPROM) {
662 DEBUGOUT("Flash update time out\n");
666 flup = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw)) | IXGBE_EEC_FLUP;
667 IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), flup);
669 status = ixgbe_poll_flash_update_done_X540(hw);
670 if (status == IXGBE_SUCCESS)
671 DEBUGOUT("Flash update complete\n");
673 DEBUGOUT("Flash update time out\n");
675 if (hw->mac.type == ixgbe_mac_X540 && hw->revision_id == 0) {
676 flup = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
678 if (flup & IXGBE_EEC_SEC1VAL) {
679 flup |= IXGBE_EEC_FLUP;
680 IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), flup);
683 status = ixgbe_poll_flash_update_done_X540(hw);
684 if (status == IXGBE_SUCCESS)
685 DEBUGOUT("Flash update complete\n");
687 DEBUGOUT("Flash update time out\n");
694 * ixgbe_poll_flash_update_done_X540 - Poll flash update status
695 * @hw: pointer to hardware structure
697 * Polls the FLUDONE (bit 26) of the EEC Register to determine when the
698 * flash update is done.
700 STATIC s32 ixgbe_poll_flash_update_done_X540(struct ixgbe_hw *hw)
704 s32 status = IXGBE_ERR_EEPROM;
706 DEBUGFUNC("ixgbe_poll_flash_update_done_X540");
708 for (i = 0; i < IXGBE_FLUDONE_ATTEMPTS; i++) {
709 reg = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
710 if (reg & IXGBE_EEC_FLUDONE) {
711 status = IXGBE_SUCCESS;
717 if (i == IXGBE_FLUDONE_ATTEMPTS)
718 ERROR_REPORT1(IXGBE_ERROR_POLLING,
719 "Flash update status polling timed out");
725 * ixgbe_acquire_swfw_sync_X540 - Acquire SWFW semaphore
726 * @hw: pointer to hardware structure
727 * @mask: Mask to specify which semaphore to acquire
729 * Acquires the SWFW semaphore thought the SW_FW_SYNC register for
730 * the specified function (CSR, PHY0, PHY1, NVM, Flash)
732 s32 ixgbe_acquire_swfw_sync_X540(struct ixgbe_hw *hw, u32 mask)
734 u32 swmask = mask & IXGBE_GSSR_NVM_PHY_MASK;
735 u32 fwmask = swmask << 5;
736 u32 swi2c_mask = mask & IXGBE_GSSR_I2C_MASK;
742 DEBUGFUNC("ixgbe_acquire_swfw_sync_X540");
744 if (swmask & IXGBE_GSSR_EEP_SM)
745 hwmask |= IXGBE_GSSR_FLASH_SM;
747 /* SW only mask doesn't have FW bit pair */
748 if (mask & IXGBE_GSSR_SW_MNG_SM)
749 swmask |= IXGBE_GSSR_SW_MNG_SM;
751 swmask |= swi2c_mask;
752 fwmask |= swi2c_mask << 2;
753 if (hw->mac.type >= ixgbe_mac_X550)
756 for (i = 0; i < timeout; i++) {
757 /* SW NVM semaphore bit is used for access to all
758 * SW_FW_SYNC bits (not just NVM)
760 if (ixgbe_get_swfw_sync_semaphore(hw)) {
761 DEBUGOUT("Failed to get NVM access and register semaphore, returning IXGBE_ERR_SWFW_SYNC\n");
762 return IXGBE_ERR_SWFW_SYNC;
765 swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC_BY_MAC(hw));
766 if (!(swfw_sync & (fwmask | swmask | hwmask))) {
768 IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC_BY_MAC(hw),
770 ixgbe_release_swfw_sync_semaphore(hw);
771 return IXGBE_SUCCESS;
773 /* Firmware currently using resource (fwmask), hardware
774 * currently using resource (hwmask), or other software
775 * thread currently using resource (swmask)
777 ixgbe_release_swfw_sync_semaphore(hw);
781 /* If the resource is not released by the FW/HW the SW can assume that
782 * the FW/HW malfunctions. In that case the SW should set the SW bit(s)
783 * of the requested resource(s) while ignoring the corresponding FW/HW
784 * bits in the SW_FW_SYNC register.
786 if (ixgbe_get_swfw_sync_semaphore(hw)) {
787 DEBUGOUT("Failed to get NVM sempahore and register semaphore while forcefully ignoring FW sempahore bit(s) and setting SW semaphore bit(s), returning IXGBE_ERR_SWFW_SYNC\n");
788 return IXGBE_ERR_SWFW_SYNC;
790 swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC_BY_MAC(hw));
791 if (swfw_sync & (fwmask | hwmask)) {
793 IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC_BY_MAC(hw), swfw_sync);
794 ixgbe_release_swfw_sync_semaphore(hw);
796 return IXGBE_SUCCESS;
798 /* If the resource is not released by other SW the SW can assume that
799 * the other SW malfunctions. In that case the SW should clear all SW
800 * flags that it does not own and then repeat the whole process once
803 if (swfw_sync & swmask) {
804 u32 rmask = IXGBE_GSSR_EEP_SM | IXGBE_GSSR_PHY0_SM |
805 IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_MAC_CSR_SM |
806 IXGBE_GSSR_SW_MNG_SM;
809 rmask |= IXGBE_GSSR_I2C_MASK;
810 ixgbe_release_swfw_sync_X540(hw, rmask);
811 ixgbe_release_swfw_sync_semaphore(hw);
812 DEBUGOUT("Resource not released by other SW, returning IXGBE_ERR_SWFW_SYNC\n");
813 return IXGBE_ERR_SWFW_SYNC;
815 ixgbe_release_swfw_sync_semaphore(hw);
816 DEBUGOUT("Returning error IXGBE_ERR_SWFW_SYNC\n");
818 return IXGBE_ERR_SWFW_SYNC;
822 * ixgbe_release_swfw_sync_X540 - Release SWFW semaphore
823 * @hw: pointer to hardware structure
824 * @mask: Mask to specify which semaphore to release
826 * Releases the SWFW semaphore through the SW_FW_SYNC register
827 * for the specified function (CSR, PHY0, PHY1, EVM, Flash)
829 void ixgbe_release_swfw_sync_X540(struct ixgbe_hw *hw, u32 mask)
831 u32 swmask = mask & (IXGBE_GSSR_NVM_PHY_MASK | IXGBE_GSSR_SW_MNG_SM);
834 DEBUGFUNC("ixgbe_release_swfw_sync_X540");
836 if (mask & IXGBE_GSSR_I2C_MASK)
837 swmask |= mask & IXGBE_GSSR_I2C_MASK;
838 ixgbe_get_swfw_sync_semaphore(hw);
840 swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC_BY_MAC(hw));
841 swfw_sync &= ~swmask;
842 IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC_BY_MAC(hw), swfw_sync);
844 ixgbe_release_swfw_sync_semaphore(hw);
849 * ixgbe_get_swfw_sync_semaphore - Get hardware semaphore
850 * @hw: pointer to hardware structure
852 * Sets the hardware semaphores so SW/FW can gain control of shared resources
854 STATIC s32 ixgbe_get_swfw_sync_semaphore(struct ixgbe_hw *hw)
856 s32 status = IXGBE_ERR_EEPROM;
861 DEBUGFUNC("ixgbe_get_swfw_sync_semaphore");
863 /* Get SMBI software semaphore between device drivers first */
864 for (i = 0; i < timeout; i++) {
866 * If the SMBI bit is 0 when we read it, then the bit will be
867 * set and we have the semaphore
869 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM_BY_MAC(hw));
870 if (!(swsm & IXGBE_SWSM_SMBI)) {
871 status = IXGBE_SUCCESS;
877 /* Now get the semaphore between SW/FW through the REGSMP bit */
878 if (status == IXGBE_SUCCESS) {
879 for (i = 0; i < timeout; i++) {
880 swsm = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC_BY_MAC(hw));
881 if (!(swsm & IXGBE_SWFW_REGSMP))
888 * Release semaphores and return error if SW NVM semaphore
889 * was not granted because we don't have access to the EEPROM
892 ERROR_REPORT1(IXGBE_ERROR_POLLING,
893 "REGSMP Software NVM semaphore not granted.\n");
894 ixgbe_release_swfw_sync_semaphore(hw);
895 status = IXGBE_ERR_EEPROM;
898 ERROR_REPORT1(IXGBE_ERROR_POLLING,
899 "Software semaphore SMBI between device drivers "
907 * ixgbe_release_swfw_sync_semaphore - Release hardware semaphore
908 * @hw: pointer to hardware structure
910 * This function clears hardware semaphore bits.
912 STATIC void ixgbe_release_swfw_sync_semaphore(struct ixgbe_hw *hw)
916 DEBUGFUNC("ixgbe_release_swfw_sync_semaphore");
918 /* Release both semaphores by writing 0 to the bits REGSMP and SMBI */
920 swsm = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC_BY_MAC(hw));
921 swsm &= ~IXGBE_SWFW_REGSMP;
922 IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC_BY_MAC(hw), swsm);
924 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM_BY_MAC(hw));
925 swsm &= ~IXGBE_SWSM_SMBI;
926 IXGBE_WRITE_REG(hw, IXGBE_SWSM_BY_MAC(hw), swsm);
928 IXGBE_WRITE_FLUSH(hw);
932 * ixgbe_init_swfw_sync_X540 - Release hardware semaphore
933 * @hw: pointer to hardware structure
935 * This function reset hardware semaphore bits for a semaphore that may
936 * have be left locked due to a catastrophic failure.
938 void ixgbe_init_swfw_sync_X540(struct ixgbe_hw *hw)
942 /* First try to grab the semaphore but we don't need to bother
943 * looking to see whether we got the lock or not since we do
944 * the same thing regardless of whether we got the lock or not.
945 * We got the lock - we release it.
946 * We timeout trying to get the lock - we force its release.
948 ixgbe_get_swfw_sync_semaphore(hw);
949 ixgbe_release_swfw_sync_semaphore(hw);
951 /* Acquire and release all software resources. */
952 rmask = IXGBE_GSSR_EEP_SM | IXGBE_GSSR_PHY0_SM |
953 IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_MAC_CSR_SM |
954 IXGBE_GSSR_SW_MNG_SM;
956 rmask |= IXGBE_GSSR_I2C_MASK;
957 ixgbe_acquire_swfw_sync_X540(hw, rmask);
958 ixgbe_release_swfw_sync_X540(hw, rmask);
962 * ixgbe_blink_led_start_X540 - Blink LED based on index.
963 * @hw: pointer to hardware structure
964 * @index: led number to blink
966 * Devices that implement the version 2 interface:
969 s32 ixgbe_blink_led_start_X540(struct ixgbe_hw *hw, u32 index)
973 ixgbe_link_speed speed;
976 DEBUGFUNC("ixgbe_blink_led_start_X540");
979 return IXGBE_ERR_PARAM;
982 * Link should be up in order for the blink bit in the LED control
983 * register to work. Force link and speed in the MAC if link is down.
984 * This will be reversed when we stop the blinking.
986 hw->mac.ops.check_link(hw, &speed, &link_up, false);
987 if (link_up == false) {
988 macc_reg = IXGBE_READ_REG(hw, IXGBE_MACC);
989 macc_reg |= IXGBE_MACC_FLU | IXGBE_MACC_FSV_10G | IXGBE_MACC_FS;
990 IXGBE_WRITE_REG(hw, IXGBE_MACC, macc_reg);
992 /* Set the LED to LINK_UP + BLINK. */
993 ledctl_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
994 ledctl_reg &= ~IXGBE_LED_MODE_MASK(index);
995 ledctl_reg |= IXGBE_LED_BLINK(index);
996 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, ledctl_reg);
997 IXGBE_WRITE_FLUSH(hw);
999 return IXGBE_SUCCESS;
1003 * ixgbe_blink_led_stop_X540 - Stop blinking LED based on index.
1004 * @hw: pointer to hardware structure
1005 * @index: led number to stop blinking
1007 * Devices that implement the version 2 interface:
1010 s32 ixgbe_blink_led_stop_X540(struct ixgbe_hw *hw, u32 index)
1016 return IXGBE_ERR_PARAM;
1018 DEBUGFUNC("ixgbe_blink_led_stop_X540");
1020 /* Restore the LED to its default value. */
1021 ledctl_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
1022 ledctl_reg &= ~IXGBE_LED_MODE_MASK(index);
1023 ledctl_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
1024 ledctl_reg &= ~IXGBE_LED_BLINK(index);
1025 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, ledctl_reg);
1027 /* Unforce link and speed in the MAC. */
1028 macc_reg = IXGBE_READ_REG(hw, IXGBE_MACC);
1029 macc_reg &= ~(IXGBE_MACC_FLU | IXGBE_MACC_FSV_10G | IXGBE_MACC_FS);
1030 IXGBE_WRITE_REG(hw, IXGBE_MACC, macc_reg);
1031 IXGBE_WRITE_FLUSH(hw);
1033 return IXGBE_SUCCESS;