1 /******************************************************************************
3 Copyright (c) 2001-2017, 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_x540.h"
36 #include "ixgbe_type.h"
37 #include "ixgbe_api.h"
38 #include "ixgbe_common.h"
39 #include "ixgbe_phy.h"
41 #define IXGBE_X540_MAX_TX_QUEUES 128
42 #define IXGBE_X540_MAX_RX_QUEUES 128
43 #define IXGBE_X540_RAR_ENTRIES 128
44 #define IXGBE_X540_MC_TBL_SIZE 128
45 #define IXGBE_X540_VFT_TBL_SIZE 128
46 #define IXGBE_X540_RX_PB_SIZE 384
48 static s32 ixgbe_poll_flash_update_done_X540(struct ixgbe_hw *hw);
49 static s32 ixgbe_get_swfw_sync_semaphore(struct ixgbe_hw *hw);
50 static void ixgbe_release_swfw_sync_semaphore(struct ixgbe_hw *hw);
53 * ixgbe_init_ops_X540 - Inits func ptrs and MAC type
54 * @hw: pointer to hardware structure
56 * Initialize the function pointers and assign the MAC type for X540.
57 * Does not touch the hardware.
59 s32 ixgbe_init_ops_X540(struct ixgbe_hw *hw)
61 struct ixgbe_mac_info *mac = &hw->mac;
62 struct ixgbe_phy_info *phy = &hw->phy;
63 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
66 DEBUGFUNC("ixgbe_init_ops_X540");
68 ret_val = ixgbe_init_phy_ops_generic(hw);
69 ret_val = ixgbe_init_ops_generic(hw);
73 eeprom->ops.init_params = ixgbe_init_eeprom_params_X540;
74 eeprom->ops.read = ixgbe_read_eerd_X540;
75 eeprom->ops.read_buffer = ixgbe_read_eerd_buffer_X540;
76 eeprom->ops.write = ixgbe_write_eewr_X540;
77 eeprom->ops.write_buffer = ixgbe_write_eewr_buffer_X540;
78 eeprom->ops.update_checksum = ixgbe_update_eeprom_checksum_X540;
79 eeprom->ops.validate_checksum = ixgbe_validate_eeprom_checksum_X540;
80 eeprom->ops.calc_checksum = ixgbe_calc_eeprom_checksum_X540;
83 phy->ops.init = ixgbe_init_phy_ops_generic;
84 phy->ops.reset = NULL;
85 phy->ops.set_phy_power = ixgbe_set_copper_phy_power;
88 mac->ops.reset_hw = ixgbe_reset_hw_X540;
89 mac->ops.enable_relaxed_ordering = ixgbe_enable_relaxed_ordering_gen2;
90 mac->ops.get_media_type = ixgbe_get_media_type_X540;
91 mac->ops.get_supported_physical_layer =
92 ixgbe_get_supported_physical_layer_X540;
93 mac->ops.read_analog_reg8 = NULL;
94 mac->ops.write_analog_reg8 = NULL;
95 mac->ops.start_hw = ixgbe_start_hw_X540;
96 mac->ops.get_san_mac_addr = ixgbe_get_san_mac_addr_generic;
97 mac->ops.set_san_mac_addr = ixgbe_set_san_mac_addr_generic;
98 mac->ops.get_device_caps = ixgbe_get_device_caps_generic;
99 mac->ops.get_wwn_prefix = ixgbe_get_wwn_prefix_generic;
100 mac->ops.get_fcoe_boot_status = ixgbe_get_fcoe_boot_status_generic;
101 mac->ops.acquire_swfw_sync = ixgbe_acquire_swfw_sync_X540;
102 mac->ops.release_swfw_sync = ixgbe_release_swfw_sync_X540;
103 mac->ops.init_swfw_sync = ixgbe_init_swfw_sync_X540;
104 mac->ops.disable_sec_rx_path = ixgbe_disable_sec_rx_path_generic;
105 mac->ops.enable_sec_rx_path = ixgbe_enable_sec_rx_path_generic;
107 /* RAR, Multicast, VLAN */
108 mac->ops.set_vmdq = ixgbe_set_vmdq_generic;
109 mac->ops.set_vmdq_san_mac = ixgbe_set_vmdq_san_mac_generic;
110 mac->ops.clear_vmdq = ixgbe_clear_vmdq_generic;
111 mac->ops.insert_mac_addr = ixgbe_insert_mac_addr_generic;
112 mac->rar_highwater = 1;
113 mac->ops.set_vfta = ixgbe_set_vfta_generic;
114 mac->ops.set_vlvf = ixgbe_set_vlvf_generic;
115 mac->ops.clear_vfta = ixgbe_clear_vfta_generic;
116 mac->ops.init_uta_tables = ixgbe_init_uta_tables_generic;
117 mac->ops.set_mac_anti_spoofing = ixgbe_set_mac_anti_spoofing;
118 mac->ops.set_vlan_anti_spoofing = ixgbe_set_vlan_anti_spoofing;
121 mac->ops.get_link_capabilities =
122 ixgbe_get_copper_link_capabilities_generic;
123 mac->ops.setup_link = ixgbe_setup_mac_link_X540;
124 mac->ops.setup_rxpba = ixgbe_set_rxpba_generic;
125 mac->ops.check_link = ixgbe_check_mac_link_generic;
126 mac->ops.bypass_rw = ixgbe_bypass_rw_generic;
127 mac->ops.bypass_valid_rd = ixgbe_bypass_valid_rd_generic;
128 mac->ops.bypass_set = ixgbe_bypass_set_generic;
129 mac->ops.bypass_rd_eep = ixgbe_bypass_rd_eep_generic;
132 mac->mcft_size = IXGBE_X540_MC_TBL_SIZE;
133 mac->vft_size = IXGBE_X540_VFT_TBL_SIZE;
134 mac->num_rar_entries = IXGBE_X540_RAR_ENTRIES;
135 mac->rx_pb_size = IXGBE_X540_RX_PB_SIZE;
136 mac->max_rx_queues = IXGBE_X540_MAX_RX_QUEUES;
137 mac->max_tx_queues = IXGBE_X540_MAX_TX_QUEUES;
138 mac->max_msix_vectors = ixgbe_get_pcie_msix_count_generic(hw);
142 * ARC supported; valid only if manageability features are
145 mac->arc_subsystem_valid = !!(IXGBE_READ_REG(hw, IXGBE_FWSM_BY_MAC(hw))
146 & IXGBE_FWSM_MODE_MASK);
148 hw->mbx.ops.init_params = ixgbe_init_mbx_params_pf;
151 mac->ops.blink_led_start = ixgbe_blink_led_start_X540;
152 mac->ops.blink_led_stop = ixgbe_blink_led_stop_X540;
154 /* Manageability interface */
155 mac->ops.set_fw_drv_ver = ixgbe_set_fw_drv_ver_generic;
157 mac->ops.get_rtrup2tc = ixgbe_dcb_get_rtrup2tc_generic;
163 * ixgbe_get_link_capabilities_X540 - Determines link capabilities
164 * @hw: pointer to hardware structure
165 * @speed: pointer to link speed
166 * @autoneg: TRUE when autoneg or autotry is enabled
168 * Determines the link capabilities by reading the AUTOC register.
170 s32 ixgbe_get_link_capabilities_X540(struct ixgbe_hw *hw,
171 ixgbe_link_speed *speed,
174 ixgbe_get_copper_link_capabilities_generic(hw, speed, autoneg);
176 return IXGBE_SUCCESS;
180 * ixgbe_get_media_type_X540 - Get media type
181 * @hw: pointer to hardware structure
183 * Returns the media type (fiber, copper, backplane)
185 enum ixgbe_media_type ixgbe_get_media_type_X540(struct ixgbe_hw *hw)
187 UNREFERENCED_1PARAMETER(hw);
188 return ixgbe_media_type_copper;
192 * ixgbe_setup_mac_link_X540 - Sets the auto advertised capabilities
193 * @hw: pointer to hardware structure
194 * @speed: new link speed
195 * @autoneg_wait_to_complete: TRUE when waiting for completion is needed
197 s32 ixgbe_setup_mac_link_X540(struct ixgbe_hw *hw,
198 ixgbe_link_speed speed,
199 bool autoneg_wait_to_complete)
201 DEBUGFUNC("ixgbe_setup_mac_link_X540");
202 return hw->phy.ops.setup_link_speed(hw, speed, autoneg_wait_to_complete);
206 * ixgbe_reset_hw_X540 - Perform hardware reset
207 * @hw: pointer to hardware structure
209 * Resets the hardware by resetting the transmit and receive units, masks
210 * and clears all interrupts, and perform a reset.
212 s32 ixgbe_reset_hw_X540(struct ixgbe_hw *hw)
217 DEBUGFUNC("ixgbe_reset_hw_X540");
219 /* Call adapter stop to disable tx/rx and clear interrupts */
220 status = hw->mac.ops.stop_adapter(hw);
221 if (status != IXGBE_SUCCESS)
224 /* flush pending Tx transactions */
225 ixgbe_clear_tx_pending(hw);
228 ctrl = IXGBE_CTRL_RST;
229 ctrl |= IXGBE_READ_REG(hw, IXGBE_CTRL);
230 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
231 IXGBE_WRITE_FLUSH(hw);
233 /* Poll for reset bit to self-clear indicating reset is complete */
234 for (i = 0; i < 10; i++) {
236 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
237 if (!(ctrl & IXGBE_CTRL_RST_MASK))
241 if (ctrl & IXGBE_CTRL_RST_MASK) {
242 status = IXGBE_ERR_RESET_FAILED;
243 ERROR_REPORT1(IXGBE_ERROR_POLLING,
244 "Reset polling failed to complete.\n");
249 * Double resets are required for recovery from certain error
250 * conditions. Between resets, it is necessary to stall to allow time
251 * for any pending HW events to complete.
253 if (hw->mac.flags & IXGBE_FLAGS_DOUBLE_RESET_REQUIRED) {
254 hw->mac.flags &= ~IXGBE_FLAGS_DOUBLE_RESET_REQUIRED;
258 /* Set the Rx packet buffer size. */
259 IXGBE_WRITE_REG(hw, IXGBE_RXPBSIZE(0), 384 << IXGBE_RXPBSIZE_SHIFT);
261 /* Store the permanent mac address */
262 hw->mac.ops.get_mac_addr(hw, hw->mac.perm_addr);
265 * Store MAC address from RAR0, clear receive address registers, and
266 * clear the multicast table. Also reset num_rar_entries to 128,
267 * since we modify this value when programming the SAN MAC address.
269 hw->mac.num_rar_entries = 128;
270 hw->mac.ops.init_rx_addrs(hw);
272 /* Store the permanent SAN mac address */
273 hw->mac.ops.get_san_mac_addr(hw, hw->mac.san_addr);
275 /* Add the SAN MAC address to the RAR only if it's a valid address */
276 if (ixgbe_validate_mac_addr(hw->mac.san_addr) == 0) {
277 /* Save the SAN MAC RAR index */
278 hw->mac.san_mac_rar_index = hw->mac.num_rar_entries - 1;
280 hw->mac.ops.set_rar(hw, hw->mac.san_mac_rar_index,
281 hw->mac.san_addr, 0, IXGBE_RAH_AV);
283 /* clear VMDq pool/queue selection for this RAR */
284 hw->mac.ops.clear_vmdq(hw, hw->mac.san_mac_rar_index,
285 IXGBE_CLEAR_VMDQ_ALL);
287 /* Reserve the last RAR for the SAN MAC address */
288 hw->mac.num_rar_entries--;
291 /* Store the alternative WWNN/WWPN prefix */
292 hw->mac.ops.get_wwn_prefix(hw, &hw->mac.wwnn_prefix,
293 &hw->mac.wwpn_prefix);
300 * ixgbe_start_hw_X540 - Prepare hardware for Tx/Rx
301 * @hw: pointer to hardware structure
303 * Starts the hardware using the generic start_hw function
304 * and the generation start_hw function.
305 * Then performs revision-specific operations, if any.
307 s32 ixgbe_start_hw_X540(struct ixgbe_hw *hw)
309 s32 ret_val = IXGBE_SUCCESS;
311 DEBUGFUNC("ixgbe_start_hw_X540");
313 ret_val = ixgbe_start_hw_generic(hw);
314 if (ret_val != IXGBE_SUCCESS)
317 ret_val = ixgbe_start_hw_gen2(hw);
324 * ixgbe_get_supported_physical_layer_X540 - Returns physical layer type
325 * @hw: pointer to hardware structure
327 * Determines physical layer capabilities of the current configuration.
329 u32 ixgbe_get_supported_physical_layer_X540(struct ixgbe_hw *hw)
331 u32 physical_layer = IXGBE_PHYSICAL_LAYER_UNKNOWN;
334 DEBUGFUNC("ixgbe_get_supported_physical_layer_X540");
336 hw->phy.ops.read_reg(hw, IXGBE_MDIO_PHY_EXT_ABILITY,
337 IXGBE_MDIO_PMA_PMD_DEV_TYPE, &ext_ability);
338 if (ext_ability & IXGBE_MDIO_PHY_10GBASET_ABILITY)
339 physical_layer |= IXGBE_PHYSICAL_LAYER_10GBASE_T;
340 if (ext_ability & IXGBE_MDIO_PHY_1000BASET_ABILITY)
341 physical_layer |= IXGBE_PHYSICAL_LAYER_1000BASE_T;
342 if (ext_ability & IXGBE_MDIO_PHY_100BASETX_ABILITY)
343 physical_layer |= IXGBE_PHYSICAL_LAYER_100BASE_TX;
345 return physical_layer;
349 * ixgbe_init_eeprom_params_X540 - Initialize EEPROM params
350 * @hw: pointer to hardware structure
352 * Initializes the EEPROM parameters ixgbe_eeprom_info within the
353 * ixgbe_hw struct in order to set up EEPROM access.
355 s32 ixgbe_init_eeprom_params_X540(struct ixgbe_hw *hw)
357 struct ixgbe_eeprom_info *eeprom = &hw->eeprom;
361 DEBUGFUNC("ixgbe_init_eeprom_params_X540");
363 if (eeprom->type == ixgbe_eeprom_uninitialized) {
364 eeprom->semaphore_delay = 10;
365 eeprom->type = ixgbe_flash;
367 eec = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
368 eeprom_size = (u16)((eec & IXGBE_EEC_SIZE) >>
369 IXGBE_EEC_SIZE_SHIFT);
370 eeprom->word_size = 1 << (eeprom_size +
371 IXGBE_EEPROM_WORD_SIZE_SHIFT);
373 DEBUGOUT2("Eeprom params: type = %d, size = %d\n",
374 eeprom->type, eeprom->word_size);
377 return IXGBE_SUCCESS;
381 * ixgbe_read_eerd_X540- Read EEPROM word using EERD
382 * @hw: pointer to hardware structure
383 * @offset: offset of word in the EEPROM to read
384 * @data: word read from the EEPROM
386 * Reads a 16 bit word from the EEPROM using the EERD register.
388 s32 ixgbe_read_eerd_X540(struct ixgbe_hw *hw, u16 offset, u16 *data)
390 s32 status = IXGBE_SUCCESS;
392 DEBUGFUNC("ixgbe_read_eerd_X540");
393 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
395 status = ixgbe_read_eerd_generic(hw, offset, data);
396 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
398 status = IXGBE_ERR_SWFW_SYNC;
405 * ixgbe_read_eerd_buffer_X540- Read EEPROM word(s) using EERD
406 * @hw: pointer to hardware structure
407 * @offset: offset of word in the EEPROM to read
408 * @words: number of words
409 * @data: word(s) read from the EEPROM
411 * Reads a 16 bit word(s) from the EEPROM using the EERD register.
413 s32 ixgbe_read_eerd_buffer_X540(struct ixgbe_hw *hw,
414 u16 offset, u16 words, u16 *data)
416 s32 status = IXGBE_SUCCESS;
418 DEBUGFUNC("ixgbe_read_eerd_buffer_X540");
419 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
421 status = ixgbe_read_eerd_buffer_generic(hw, offset,
423 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
425 status = IXGBE_ERR_SWFW_SYNC;
432 * ixgbe_write_eewr_X540 - Write EEPROM word using EEWR
433 * @hw: pointer to hardware structure
434 * @offset: offset of word in the EEPROM to write
435 * @data: word write to the EEPROM
437 * Write a 16 bit word to the EEPROM using the EEWR register.
439 s32 ixgbe_write_eewr_X540(struct ixgbe_hw *hw, u16 offset, u16 data)
441 s32 status = IXGBE_SUCCESS;
443 DEBUGFUNC("ixgbe_write_eewr_X540");
444 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
446 status = ixgbe_write_eewr_generic(hw, offset, data);
447 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
449 status = IXGBE_ERR_SWFW_SYNC;
456 * ixgbe_write_eewr_buffer_X540 - Write EEPROM word(s) using EEWR
457 * @hw: pointer to hardware structure
458 * @offset: offset of word in the EEPROM to write
459 * @words: number of words
460 * @data: word(s) write to the EEPROM
462 * Write a 16 bit word(s) to the EEPROM using the EEWR register.
464 s32 ixgbe_write_eewr_buffer_X540(struct ixgbe_hw *hw,
465 u16 offset, u16 words, u16 *data)
467 s32 status = IXGBE_SUCCESS;
469 DEBUGFUNC("ixgbe_write_eewr_buffer_X540");
470 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM) ==
472 status = ixgbe_write_eewr_buffer_generic(hw, offset,
474 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
476 status = IXGBE_ERR_SWFW_SYNC;
483 * ixgbe_calc_eeprom_checksum_X540 - Calculates and returns the checksum
485 * This function does not use synchronization for EERD and EEWR. It can
486 * be used internally by function which utilize ixgbe_acquire_swfw_sync_X540.
488 * @hw: pointer to hardware structure
490 * Returns a negative error code on error, or the 16-bit checksum
492 s32 ixgbe_calc_eeprom_checksum_X540(struct ixgbe_hw *hw)
499 u16 ptr_start = IXGBE_PCIE_ANALOG_PTR;
501 /* Do not use hw->eeprom.ops.read because we do not want to take
502 * the synchronization semaphores here. Instead use
503 * ixgbe_read_eerd_generic
506 DEBUGFUNC("ixgbe_calc_eeprom_checksum_X540");
508 /* Include 0x0 up to IXGBE_EEPROM_CHECKSUM; do not include the
511 for (i = 0; i < IXGBE_EEPROM_CHECKSUM; i++) {
512 if (ixgbe_read_eerd_generic(hw, i, &word)) {
513 DEBUGOUT("EEPROM read failed\n");
514 return IXGBE_ERR_EEPROM;
519 /* Include all data from pointers 0x3, 0x6-0xE. This excludes the
520 * FW, PHY module, and PCIe Expansion/Option ROM pointers.
522 for (i = ptr_start; i < IXGBE_FW_PTR; i++) {
523 if (i == IXGBE_PHY_PTR || i == IXGBE_OPTION_ROM_PTR)
526 if (ixgbe_read_eerd_generic(hw, i, &pointer)) {
527 DEBUGOUT("EEPROM read failed\n");
528 return IXGBE_ERR_EEPROM;
531 /* Skip pointer section if the pointer is invalid. */
532 if (pointer == 0xFFFF || pointer == 0 ||
533 pointer >= hw->eeprom.word_size)
536 if (ixgbe_read_eerd_generic(hw, pointer, &length)) {
537 DEBUGOUT("EEPROM read failed\n");
538 return IXGBE_ERR_EEPROM;
541 /* Skip pointer section if length is invalid. */
542 if (length == 0xFFFF || length == 0 ||
543 (pointer + length) >= hw->eeprom.word_size)
546 for (j = pointer + 1; j <= pointer + length; j++) {
547 if (ixgbe_read_eerd_generic(hw, j, &word)) {
548 DEBUGOUT("EEPROM read failed\n");
549 return IXGBE_ERR_EEPROM;
555 checksum = (u16)IXGBE_EEPROM_SUM - checksum;
557 return (s32)checksum;
561 * ixgbe_validate_eeprom_checksum_X540 - Validate EEPROM checksum
562 * @hw: pointer to hardware structure
563 * @checksum_val: calculated checksum
565 * Performs checksum calculation and validates the EEPROM checksum. If the
566 * caller does not need checksum_val, the value can be NULL.
568 s32 ixgbe_validate_eeprom_checksum_X540(struct ixgbe_hw *hw,
573 u16 read_checksum = 0;
575 DEBUGFUNC("ixgbe_validate_eeprom_checksum_X540");
577 /* Read the first word from the EEPROM. If this times out or fails, do
578 * not continue or we could be in for a very long wait while every
581 status = hw->eeprom.ops.read(hw, 0, &checksum);
583 DEBUGOUT("EEPROM read failed\n");
587 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM))
588 return IXGBE_ERR_SWFW_SYNC;
590 status = hw->eeprom.ops.calc_checksum(hw);
594 checksum = (u16)(status & 0xffff);
596 /* Do not use hw->eeprom.ops.read because we do not want to take
597 * the synchronization semaphores twice here.
599 status = ixgbe_read_eerd_generic(hw, IXGBE_EEPROM_CHECKSUM,
604 /* Verify read checksum from EEPROM is the same as
605 * calculated checksum
607 if (read_checksum != checksum) {
608 ERROR_REPORT1(IXGBE_ERROR_INVALID_STATE,
609 "Invalid EEPROM checksum");
610 status = IXGBE_ERR_EEPROM_CHECKSUM;
613 /* If the user cares, return the calculated checksum */
615 *checksum_val = checksum;
618 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
624 * ixgbe_update_eeprom_checksum_X540 - Updates the EEPROM checksum and flash
625 * @hw: pointer to hardware structure
627 * After writing EEPROM to shadow RAM using EEWR register, software calculates
628 * checksum and updates the EEPROM and instructs the hardware to update
631 s32 ixgbe_update_eeprom_checksum_X540(struct ixgbe_hw *hw)
636 DEBUGFUNC("ixgbe_update_eeprom_checksum_X540");
638 /* Read the first word from the EEPROM. If this times out or fails, do
639 * not continue or we could be in for a very long wait while every
642 status = hw->eeprom.ops.read(hw, 0, &checksum);
644 DEBUGOUT("EEPROM read failed\n");
648 if (hw->mac.ops.acquire_swfw_sync(hw, IXGBE_GSSR_EEP_SM))
649 return IXGBE_ERR_SWFW_SYNC;
651 status = hw->eeprom.ops.calc_checksum(hw);
655 checksum = (u16)(status & 0xffff);
657 /* Do not use hw->eeprom.ops.write because we do not want to
658 * take the synchronization semaphores twice here.
660 status = ixgbe_write_eewr_generic(hw, IXGBE_EEPROM_CHECKSUM, checksum);
664 status = ixgbe_update_flash_X540(hw);
667 hw->mac.ops.release_swfw_sync(hw, IXGBE_GSSR_EEP_SM);
673 * ixgbe_update_flash_X540 - Instruct HW to copy EEPROM to Flash device
674 * @hw: pointer to hardware structure
676 * Set FLUP (bit 23) of the EEC register to instruct Hardware to copy
677 * EEPROM from shadow RAM to the flash device.
679 s32 ixgbe_update_flash_X540(struct ixgbe_hw *hw)
684 DEBUGFUNC("ixgbe_update_flash_X540");
686 status = ixgbe_poll_flash_update_done_X540(hw);
687 if (status == IXGBE_ERR_EEPROM) {
688 DEBUGOUT("Flash update time out\n");
692 flup = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw)) | IXGBE_EEC_FLUP;
693 IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), flup);
695 status = ixgbe_poll_flash_update_done_X540(hw);
696 if (status == IXGBE_SUCCESS)
697 DEBUGOUT("Flash update complete\n");
699 DEBUGOUT("Flash update time out\n");
701 if (hw->mac.type == ixgbe_mac_X540 && hw->revision_id == 0) {
702 flup = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
704 if (flup & IXGBE_EEC_SEC1VAL) {
705 flup |= IXGBE_EEC_FLUP;
706 IXGBE_WRITE_REG(hw, IXGBE_EEC_BY_MAC(hw), flup);
709 status = ixgbe_poll_flash_update_done_X540(hw);
710 if (status == IXGBE_SUCCESS)
711 DEBUGOUT("Flash update complete\n");
713 DEBUGOUT("Flash update time out\n");
720 * ixgbe_poll_flash_update_done_X540 - Poll flash update status
721 * @hw: pointer to hardware structure
723 * Polls the FLUDONE (bit 26) of the EEC Register to determine when the
724 * flash update is done.
726 static s32 ixgbe_poll_flash_update_done_X540(struct ixgbe_hw *hw)
730 s32 status = IXGBE_ERR_EEPROM;
732 DEBUGFUNC("ixgbe_poll_flash_update_done_X540");
734 for (i = 0; i < IXGBE_FLUDONE_ATTEMPTS; i++) {
735 reg = IXGBE_READ_REG(hw, IXGBE_EEC_BY_MAC(hw));
736 if (reg & IXGBE_EEC_FLUDONE) {
737 status = IXGBE_SUCCESS;
743 if (i == IXGBE_FLUDONE_ATTEMPTS)
744 ERROR_REPORT1(IXGBE_ERROR_POLLING,
745 "Flash update status polling timed out");
751 * ixgbe_acquire_swfw_sync_X540 - Acquire SWFW semaphore
752 * @hw: pointer to hardware structure
753 * @mask: Mask to specify which semaphore to acquire
755 * Acquires the SWFW semaphore thought the SW_FW_SYNC register for
756 * the specified function (CSR, PHY0, PHY1, NVM, Flash)
758 s32 ixgbe_acquire_swfw_sync_X540(struct ixgbe_hw *hw, u32 mask)
760 u32 swmask = mask & IXGBE_GSSR_NVM_PHY_MASK;
761 u32 fwmask = swmask << 5;
762 u32 swi2c_mask = mask & IXGBE_GSSR_I2C_MASK;
768 DEBUGFUNC("ixgbe_acquire_swfw_sync_X540");
770 if (swmask & IXGBE_GSSR_EEP_SM)
771 hwmask |= IXGBE_GSSR_FLASH_SM;
773 /* SW only mask doesn't have FW bit pair */
774 if (mask & IXGBE_GSSR_SW_MNG_SM)
775 swmask |= IXGBE_GSSR_SW_MNG_SM;
777 swmask |= swi2c_mask;
778 fwmask |= swi2c_mask << 2;
779 for (i = 0; i < timeout; i++) {
780 /* SW NVM semaphore bit is used for access to all
781 * SW_FW_SYNC bits (not just NVM)
783 if (ixgbe_get_swfw_sync_semaphore(hw)) {
784 DEBUGOUT("Failed to get NVM access and register semaphore, returning IXGBE_ERR_SWFW_SYNC\n");
785 return IXGBE_ERR_SWFW_SYNC;
788 swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC_BY_MAC(hw));
789 if (!(swfw_sync & (fwmask | swmask | hwmask))) {
791 IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC_BY_MAC(hw),
793 ixgbe_release_swfw_sync_semaphore(hw);
794 return IXGBE_SUCCESS;
796 /* Firmware currently using resource (fwmask), hardware
797 * currently using resource (hwmask), or other software
798 * thread currently using resource (swmask)
800 ixgbe_release_swfw_sync_semaphore(hw);
804 /* Failed to get SW only semaphore */
805 if (swmask == IXGBE_GSSR_SW_MNG_SM) {
806 ERROR_REPORT1(IXGBE_ERROR_POLLING,
807 "Failed to get SW only semaphore");
808 DEBUGOUT("Failed to get SW only semaphore, returning IXGBE_ERR_SWFW_SYNC\n");
809 return IXGBE_ERR_SWFW_SYNC;
812 /* If the resource is not released by the FW/HW the SW can assume that
813 * the FW/HW malfunctions. In that case the SW should set the SW bit(s)
814 * of the requested resource(s) while ignoring the corresponding FW/HW
815 * bits in the SW_FW_SYNC register.
817 if (ixgbe_get_swfw_sync_semaphore(hw)) {
818 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");
819 return IXGBE_ERR_SWFW_SYNC;
821 swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC_BY_MAC(hw));
822 if (swfw_sync & (fwmask | hwmask)) {
824 IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC_BY_MAC(hw), swfw_sync);
825 ixgbe_release_swfw_sync_semaphore(hw);
827 return IXGBE_SUCCESS;
829 /* If the resource is not released by other SW the SW can assume that
830 * the other SW malfunctions. In that case the SW should clear all SW
831 * flags that it does not own and then repeat the whole process once
834 if (swfw_sync & swmask) {
835 u32 rmask = IXGBE_GSSR_EEP_SM | IXGBE_GSSR_PHY0_SM |
836 IXGBE_GSSR_PHY1_SM | IXGBE_GSSR_MAC_CSR_SM;
839 rmask |= IXGBE_GSSR_I2C_MASK;
840 ixgbe_release_swfw_sync_X540(hw, rmask);
841 ixgbe_release_swfw_sync_semaphore(hw);
842 DEBUGOUT("Resource not released by other SW, returning IXGBE_ERR_SWFW_SYNC\n");
843 return IXGBE_ERR_SWFW_SYNC;
845 ixgbe_release_swfw_sync_semaphore(hw);
846 DEBUGOUT("Returning error IXGBE_ERR_SWFW_SYNC\n");
848 return IXGBE_ERR_SWFW_SYNC;
852 * ixgbe_release_swfw_sync_X540 - Release SWFW semaphore
853 * @hw: pointer to hardware structure
854 * @mask: Mask to specify which semaphore to release
856 * Releases the SWFW semaphore through the SW_FW_SYNC register
857 * for the specified function (CSR, PHY0, PHY1, EVM, Flash)
859 void ixgbe_release_swfw_sync_X540(struct ixgbe_hw *hw, u32 mask)
861 u32 swmask = mask & (IXGBE_GSSR_NVM_PHY_MASK | IXGBE_GSSR_SW_MNG_SM);
864 DEBUGFUNC("ixgbe_release_swfw_sync_X540");
866 if (mask & IXGBE_GSSR_I2C_MASK)
867 swmask |= mask & IXGBE_GSSR_I2C_MASK;
868 ixgbe_get_swfw_sync_semaphore(hw);
870 swfw_sync = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC_BY_MAC(hw));
871 swfw_sync &= ~swmask;
872 IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC_BY_MAC(hw), swfw_sync);
874 ixgbe_release_swfw_sync_semaphore(hw);
879 * ixgbe_get_swfw_sync_semaphore - Get hardware semaphore
880 * @hw: pointer to hardware structure
882 * Sets the hardware semaphores so SW/FW can gain control of shared resources
884 static s32 ixgbe_get_swfw_sync_semaphore(struct ixgbe_hw *hw)
886 s32 status = IXGBE_ERR_EEPROM;
891 DEBUGFUNC("ixgbe_get_swfw_sync_semaphore");
893 /* Get SMBI software semaphore between device drivers first */
894 for (i = 0; i < timeout; i++) {
896 * If the SMBI bit is 0 when we read it, then the bit will be
897 * set and we have the semaphore
899 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM_BY_MAC(hw));
900 if (!(swsm & IXGBE_SWSM_SMBI)) {
901 status = IXGBE_SUCCESS;
907 /* Now get the semaphore between SW/FW through the REGSMP bit */
908 if (status == IXGBE_SUCCESS) {
909 for (i = 0; i < timeout; i++) {
910 swsm = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC_BY_MAC(hw));
911 if (!(swsm & IXGBE_SWFW_REGSMP))
918 * Release semaphores and return error if SW NVM semaphore
919 * was not granted because we don't have access to the EEPROM
922 ERROR_REPORT1(IXGBE_ERROR_POLLING,
923 "REGSMP Software NVM semaphore not granted.\n");
924 ixgbe_release_swfw_sync_semaphore(hw);
925 status = IXGBE_ERR_EEPROM;
928 ERROR_REPORT1(IXGBE_ERROR_POLLING,
929 "Software semaphore SMBI between device drivers "
937 * ixgbe_release_swfw_sync_semaphore - Release hardware semaphore
938 * @hw: pointer to hardware structure
940 * This function clears hardware semaphore bits.
942 static void ixgbe_release_swfw_sync_semaphore(struct ixgbe_hw *hw)
946 DEBUGFUNC("ixgbe_release_swfw_sync_semaphore");
948 /* Release both semaphores by writing 0 to the bits REGSMP and SMBI */
950 swsm = IXGBE_READ_REG(hw, IXGBE_SWFW_SYNC_BY_MAC(hw));
951 swsm &= ~IXGBE_SWFW_REGSMP;
952 IXGBE_WRITE_REG(hw, IXGBE_SWFW_SYNC_BY_MAC(hw), swsm);
954 swsm = IXGBE_READ_REG(hw, IXGBE_SWSM_BY_MAC(hw));
955 swsm &= ~IXGBE_SWSM_SMBI;
956 IXGBE_WRITE_REG(hw, IXGBE_SWSM_BY_MAC(hw), swsm);
958 IXGBE_WRITE_FLUSH(hw);
962 * ixgbe_init_swfw_sync_X540 - Release hardware semaphore
963 * @hw: pointer to hardware structure
965 * This function reset hardware semaphore bits for a semaphore that may
966 * have be left locked due to a catastrophic failure.
968 void ixgbe_init_swfw_sync_X540(struct ixgbe_hw *hw)
970 /* First try to grab the semaphore but we don't need to bother
971 * looking to see whether we got the lock or not since we do
972 * the same thing regardless of whether we got the lock or not.
973 * We got the lock - we release it.
974 * We timeout trying to get the lock - we force its release.
976 ixgbe_get_swfw_sync_semaphore(hw);
977 ixgbe_release_swfw_sync_semaphore(hw);
981 * ixgbe_blink_led_start_X540 - Blink LED based on index.
982 * @hw: pointer to hardware structure
983 * @index: led number to blink
985 * Devices that implement the version 2 interface:
988 s32 ixgbe_blink_led_start_X540(struct ixgbe_hw *hw, u32 index)
992 ixgbe_link_speed speed;
995 DEBUGFUNC("ixgbe_blink_led_start_X540");
998 return IXGBE_ERR_PARAM;
1001 * Link should be up in order for the blink bit in the LED control
1002 * register to work. Force link and speed in the MAC if link is down.
1003 * This will be reversed when we stop the blinking.
1005 hw->mac.ops.check_link(hw, &speed, &link_up, FALSE);
1006 if (link_up == FALSE) {
1007 macc_reg = IXGBE_READ_REG(hw, IXGBE_MACC);
1008 macc_reg |= IXGBE_MACC_FLU | IXGBE_MACC_FSV_10G | IXGBE_MACC_FS;
1009 IXGBE_WRITE_REG(hw, IXGBE_MACC, macc_reg);
1011 /* Set the LED to LINK_UP + BLINK. */
1012 ledctl_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
1013 ledctl_reg &= ~IXGBE_LED_MODE_MASK(index);
1014 ledctl_reg |= IXGBE_LED_BLINK(index);
1015 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, ledctl_reg);
1016 IXGBE_WRITE_FLUSH(hw);
1018 return IXGBE_SUCCESS;
1022 * ixgbe_blink_led_stop_X540 - Stop blinking LED based on index.
1023 * @hw: pointer to hardware structure
1024 * @index: led number to stop blinking
1026 * Devices that implement the version 2 interface:
1029 s32 ixgbe_blink_led_stop_X540(struct ixgbe_hw *hw, u32 index)
1035 return IXGBE_ERR_PARAM;
1037 DEBUGFUNC("ixgbe_blink_led_stop_X540");
1039 /* Restore the LED to its default value. */
1040 ledctl_reg = IXGBE_READ_REG(hw, IXGBE_LEDCTL);
1041 ledctl_reg &= ~IXGBE_LED_MODE_MASK(index);
1042 ledctl_reg |= IXGBE_LED_LINK_ACTIVE << IXGBE_LED_MODE_SHIFT(index);
1043 ledctl_reg &= ~IXGBE_LED_BLINK(index);
1044 IXGBE_WRITE_REG(hw, IXGBE_LEDCTL, ledctl_reg);
1046 /* Unforce link and speed in the MAC. */
1047 macc_reg = IXGBE_READ_REG(hw, IXGBE_MACC);
1048 macc_reg &= ~(IXGBE_MACC_FLU | IXGBE_MACC_FSV_10G | IXGBE_MACC_FS);
1049 IXGBE_WRITE_REG(hw, IXGBE_MACC, macc_reg);
1050 IXGBE_WRITE_FLUSH(hw);
1052 return IXGBE_SUCCESS;