Home | History | Annotate | Line # | Download | only in igc
igc_i225.c revision 1.1
      1  1.1  rin /*	$OpenBSD: igc_i225.c,v 1.4 2023/02/03 11:31:52 mbuhl Exp $	*/
      2  1.1  rin /*-
      3  1.1  rin  * Copyright 2021 Intel Corp
      4  1.1  rin  * Copyright 2021 Rubicon Communications, LLC (Netgate)
      5  1.1  rin  * SPDX-License-Identifier: BSD-3-Clause
      6  1.1  rin  */
      7  1.1  rin 
      8  1.1  rin #include <dev/pci/igc_api.h>
      9  1.1  rin 
     10  1.1  rin int	igc_init_nvm_params_i225(struct igc_hw *);
     11  1.1  rin int	igc_init_mac_params_i225(struct igc_hw *);
     12  1.1  rin int	igc_init_phy_params_i225(struct igc_hw *);
     13  1.1  rin int	igc_reset_hw_i225(struct igc_hw *);
     14  1.1  rin int	igc_acquire_nvm_i225(struct igc_hw *);
     15  1.1  rin void	igc_release_nvm_i225(struct igc_hw *);
     16  1.1  rin int	igc_get_hw_semaphore_i225(struct igc_hw *);
     17  1.1  rin int	__igc_write_nvm_srwr(struct igc_hw *, uint16_t, uint16_t, uint16_t *);
     18  1.1  rin int	igc_pool_flash_update_done_i225(struct igc_hw *);
     19  1.1  rin 
     20  1.1  rin /**
     21  1.1  rin  *  igc_init_nvm_params_i225 - Init NVM func ptrs.
     22  1.1  rin  *  @hw: pointer to the HW structure
     23  1.1  rin  **/
     24  1.1  rin int
     25  1.1  rin igc_init_nvm_params_i225(struct igc_hw *hw)
     26  1.1  rin {
     27  1.1  rin 	struct igc_nvm_info *nvm = &hw->nvm;
     28  1.1  rin 	uint32_t eecd = IGC_READ_REG(hw, IGC_EECD);
     29  1.1  rin 	uint16_t size;
     30  1.1  rin 
     31  1.1  rin 	DEBUGFUNC("igc_init_nvm_params_i225");
     32  1.1  rin 
     33  1.1  rin 	size = (uint16_t)((eecd & IGC_EECD_SIZE_EX_MASK) >>
     34  1.1  rin 	    IGC_EECD_SIZE_EX_SHIFT);
     35  1.1  rin 	/*
     36  1.1  rin 	 * Added to a constant, "size" becomes the left-shift value
     37  1.1  rin 	 * for setting word_size.
     38  1.1  rin 	 */
     39  1.1  rin 	size += NVM_WORD_SIZE_BASE_SHIFT;
     40  1.1  rin 
     41  1.1  rin 	/* Just in case size is out of range, cap it to the largest
     42  1.1  rin 	 * EEPROM size supported.
     43  1.1  rin 	 */
     44  1.1  rin 	if (size > 15)
     45  1.1  rin 		size = 15;
     46  1.1  rin 
     47  1.1  rin 	nvm->word_size = 1 << size;
     48  1.1  rin 	nvm->opcode_bits = 8;
     49  1.1  rin 	nvm->delay_usec = 1;
     50  1.1  rin 	nvm->type = igc_nvm_eeprom_spi;
     51  1.1  rin 
     52  1.1  rin 	nvm->page_size = eecd & IGC_EECD_ADDR_BITS ? 32 : 8;
     53  1.1  rin 	nvm->address_bits = eecd & IGC_EECD_ADDR_BITS ? 16 : 8;
     54  1.1  rin 
     55  1.1  rin 	if (nvm->word_size == (1 << 15))
     56  1.1  rin 		nvm->page_size = 128;
     57  1.1  rin 
     58  1.1  rin 	nvm->ops.acquire = igc_acquire_nvm_i225;
     59  1.1  rin 	nvm->ops.release = igc_release_nvm_i225;
     60  1.1  rin 	if (igc_get_flash_presence_i225(hw)) {
     61  1.1  rin 		hw->nvm.type = igc_nvm_flash_hw;
     62  1.1  rin 		nvm->ops.read = igc_read_nvm_srrd_i225;
     63  1.1  rin 		nvm->ops.write = igc_write_nvm_srwr_i225;
     64  1.1  rin 		nvm->ops.validate = igc_validate_nvm_checksum_i225;
     65  1.1  rin 		nvm->ops.update = igc_update_nvm_checksum_i225;
     66  1.1  rin 	} else {
     67  1.1  rin 		hw->nvm.type = igc_nvm_invm;
     68  1.1  rin 		nvm->ops.write = igc_null_write_nvm;
     69  1.1  rin 		nvm->ops.validate = igc_null_ops_generic;
     70  1.1  rin 		nvm->ops.update = igc_null_ops_generic;
     71  1.1  rin 	}
     72  1.1  rin 
     73  1.1  rin 	return IGC_SUCCESS;
     74  1.1  rin }
     75  1.1  rin 
     76  1.1  rin /**
     77  1.1  rin  *  igc_init_mac_params_i225 - Init MAC func ptrs.
     78  1.1  rin  *  @hw: pointer to the HW structure
     79  1.1  rin  **/
     80  1.1  rin int
     81  1.1  rin igc_init_mac_params_i225(struct igc_hw *hw)
     82  1.1  rin {
     83  1.1  rin 	struct igc_mac_info *mac = &hw->mac;
     84  1.1  rin 	struct igc_dev_spec_i225 *dev_spec = &hw->dev_spec._i225;
     85  1.1  rin 
     86  1.1  rin 	DEBUGFUNC("igc_init_mac_params_i225");
     87  1.1  rin 
     88  1.1  rin 	/* Initialize function pointer */
     89  1.1  rin 	igc_init_mac_ops_generic(hw);
     90  1.1  rin 
     91  1.1  rin 	/* Set media type */
     92  1.1  rin 	hw->phy.media_type = igc_media_type_copper;
     93  1.1  rin 	/* Set mta register count */
     94  1.1  rin 	mac->mta_reg_count = 128;
     95  1.1  rin 	/* Set rar entry count */
     96  1.1  rin 	mac->rar_entry_count = IGC_RAR_ENTRIES_BASE;
     97  1.1  rin 
     98  1.1  rin 	/* reset */
     99  1.1  rin 	mac->ops.reset_hw = igc_reset_hw_i225;
    100  1.1  rin 	/* hw initialization */
    101  1.1  rin 	mac->ops.init_hw = igc_init_hw_i225;
    102  1.1  rin 	/* link setup */
    103  1.1  rin 	mac->ops.setup_link = igc_setup_link_generic;
    104  1.1  rin 	/* check for link */
    105  1.1  rin 	mac->ops.check_for_link = igc_check_for_link_i225;
    106  1.1  rin 	/* link info */
    107  1.1  rin 	mac->ops.get_link_up_info = igc_get_speed_and_duplex_copper_generic;
    108  1.1  rin 	/* acquire SW_FW sync */
    109  1.1  rin 	mac->ops.acquire_swfw_sync = igc_acquire_swfw_sync_i225;
    110  1.1  rin 	/* release SW_FW sync */
    111  1.1  rin 	mac->ops.release_swfw_sync = igc_release_swfw_sync_i225;
    112  1.1  rin 
    113  1.1  rin 	/* Allow a single clear of the SW semaphore on I225 */
    114  1.1  rin 	dev_spec->clear_semaphore_once = true;
    115  1.1  rin 	mac->ops.setup_physical_interface = igc_setup_copper_link_i225;
    116  1.1  rin 
    117  1.1  rin 	/* Set if part includes ASF firmware */
    118  1.1  rin 	mac->asf_firmware_present = true;
    119  1.1  rin 
    120  1.1  rin 	/* multicast address update */
    121  1.1  rin 	mac->ops.update_mc_addr_list = igc_update_mc_addr_list_generic;
    122  1.1  rin 
    123  1.1  rin 	mac->ops.write_vfta = igc_write_vfta_generic;
    124  1.1  rin 
    125  1.1  rin 	return IGC_SUCCESS;
    126  1.1  rin }
    127  1.1  rin 
    128  1.1  rin /**
    129  1.1  rin  *  igc_init_phy_params_i225 - Init PHY func ptrs.
    130  1.1  rin  *  @hw: pointer to the HW structure
    131  1.1  rin  **/
    132  1.1  rin int
    133  1.1  rin igc_init_phy_params_i225(struct igc_hw *hw)
    134  1.1  rin {
    135  1.1  rin 	struct igc_phy_info *phy = &hw->phy;
    136  1.1  rin 	int ret_val = IGC_SUCCESS;
    137  1.1  rin 
    138  1.1  rin 	DEBUGFUNC("igc_init_phy_params_i225");
    139  1.1  rin 
    140  1.1  rin 	if (hw->phy.media_type != igc_media_type_copper) {
    141  1.1  rin 		phy->type = igc_phy_none;
    142  1.1  rin 		goto out;
    143  1.1  rin 	}
    144  1.1  rin 
    145  1.1  rin 	phy->ops.power_up = igc_power_up_phy_copper;
    146  1.1  rin 	phy->ops.power_down = igc_power_down_phy_copper_base;
    147  1.1  rin 	phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT_2500;
    148  1.1  rin 	phy->reset_delay_us = 100;
    149  1.1  rin 	phy->ops.acquire = igc_acquire_phy_base;
    150  1.1  rin 	phy->ops.check_reset_block = igc_check_reset_block_generic;
    151  1.1  rin 	phy->ops.release = igc_release_phy_base;
    152  1.1  rin 	phy->ops.reset = igc_phy_hw_reset_generic;
    153  1.1  rin 	phy->ops.read_reg = igc_read_phy_reg_gpy;
    154  1.1  rin 	phy->ops.write_reg = igc_write_phy_reg_gpy;
    155  1.1  rin 
    156  1.1  rin 	/* Make sure the PHY is in a good state. Several people have reported
    157  1.1  rin 	 * firmware leaving the PHY's page select register set to something
    158  1.1  rin 	 * other than the default of zero, which causes the PHY ID read to
    159  1.1  rin 	 * access something other than the intended register.
    160  1.1  rin 	 */
    161  1.1  rin 	ret_val = hw->phy.ops.reset(hw);
    162  1.1  rin 	if (ret_val)
    163  1.1  rin 		goto out;
    164  1.1  rin 
    165  1.1  rin 	ret_val = igc_get_phy_id(hw);
    166  1.1  rin 	phy->type = igc_phy_i225;
    167  1.1  rin 
    168  1.1  rin out:
    169  1.1  rin 	return ret_val;
    170  1.1  rin }
    171  1.1  rin 
    172  1.1  rin /**
    173  1.1  rin  *  igc_reset_hw_i225 - Reset hardware
    174  1.1  rin  *  @hw: pointer to the HW structure
    175  1.1  rin  *
    176  1.1  rin  *  This resets the hardware into a known state.
    177  1.1  rin  **/
    178  1.1  rin int
    179  1.1  rin igc_reset_hw_i225(struct igc_hw *hw)
    180  1.1  rin {
    181  1.1  rin 	uint32_t ctrl;
    182  1.1  rin 	int ret_val;
    183  1.1  rin 
    184  1.1  rin 	DEBUGFUNC("igc_reset_hw_i225");
    185  1.1  rin 
    186  1.1  rin 	/*
    187  1.1  rin 	 * Prevent the PCI-E bus from sticking if there is no TLP connection
    188  1.1  rin 	 * on the last TLP read/write transaction when MAC is reset.
    189  1.1  rin 	 */
    190  1.1  rin 	ret_val = igc_disable_pcie_master_generic(hw);
    191  1.1  rin 	if (ret_val)
    192  1.1  rin 		DEBUGOUT("PCI-E Master disable polling has failed.\n");
    193  1.1  rin 
    194  1.1  rin 	DEBUGOUT("Masking off all interrupts\n");
    195  1.1  rin 	IGC_WRITE_REG(hw, IGC_IMC, 0xffffffff);
    196  1.1  rin 
    197  1.1  rin 	IGC_WRITE_REG(hw, IGC_RCTL, 0);
    198  1.1  rin 	IGC_WRITE_REG(hw, IGC_TCTL, IGC_TCTL_PSP);
    199  1.1  rin 	IGC_WRITE_FLUSH(hw);
    200  1.1  rin 
    201  1.1  rin 	msec_delay(10);
    202  1.1  rin 
    203  1.1  rin 	ctrl = IGC_READ_REG(hw, IGC_CTRL);
    204  1.1  rin 
    205  1.1  rin 	DEBUGOUT("Issuing a global reset to MAC\n");
    206  1.1  rin 	IGC_WRITE_REG(hw, IGC_CTRL, ctrl | IGC_CTRL_DEV_RST);
    207  1.1  rin 
    208  1.1  rin 	ret_val = igc_get_auto_rd_done_generic(hw);
    209  1.1  rin 	if (ret_val) {
    210  1.1  rin 		/*
    211  1.1  rin 		 * When auto config read does not complete, do not
    212  1.1  rin 		 * return with an error. This can happen in situations
    213  1.1  rin 		 * where there is no eeprom and prevents getting link.
    214  1.1  rin 		 */
    215  1.1  rin 		DEBUGOUT("Auto Read Done did not complete\n");
    216  1.1  rin 	}
    217  1.1  rin 
    218  1.1  rin 	/* Clear any pending interrupt events. */
    219  1.1  rin 	IGC_WRITE_REG(hw, IGC_IMC, 0xffffffff);
    220  1.1  rin 	IGC_READ_REG(hw, IGC_ICR);
    221  1.1  rin 
    222  1.1  rin 	/* Install any alternate MAC address into RAR0 */
    223  1.1  rin 	ret_val = igc_check_alt_mac_addr_generic(hw);
    224  1.1  rin 
    225  1.1  rin 	return ret_val;
    226  1.1  rin }
    227  1.1  rin 
    228  1.1  rin /* igc_acquire_nvm_i225 - Request for access to EEPROM
    229  1.1  rin  * @hw: pointer to the HW structure
    230  1.1  rin  *
    231  1.1  rin  * Acquire the necessary semaphores for exclusive access to the EEPROM.
    232  1.1  rin  * Set the EEPROM access request bit and wait for EEPROM access grant bit.
    233  1.1  rin  * Return successful if access grant bit set, else clear the request for
    234  1.1  rin  * EEPROM access and return -IGC_ERR_NVM (-1).
    235  1.1  rin  */
    236  1.1  rin int
    237  1.1  rin igc_acquire_nvm_i225(struct igc_hw *hw)
    238  1.1  rin {
    239  1.1  rin 	int ret_val;
    240  1.1  rin 
    241  1.1  rin 	DEBUGFUNC("igc_acquire_nvm_i225");
    242  1.1  rin 
    243  1.1  rin 	ret_val = igc_acquire_swfw_sync_i225(hw, IGC_SWFW_EEP_SM);
    244  1.1  rin 
    245  1.1  rin 	return ret_val;
    246  1.1  rin }
    247  1.1  rin 
    248  1.1  rin /* igc_release_nvm_i225 - Release exclusive access to EEPROM
    249  1.1  rin  * @hw: pointer to the HW structure
    250  1.1  rin  *
    251  1.1  rin  * Stop any current commands to the EEPROM and clear the EEPROM request bit,
    252  1.1  rin  * then release the semaphores acquired.
    253  1.1  rin  */
    254  1.1  rin void
    255  1.1  rin igc_release_nvm_i225(struct igc_hw *hw)
    256  1.1  rin {
    257  1.1  rin 	DEBUGFUNC("igc_release_nvm_i225");
    258  1.1  rin 
    259  1.1  rin 	igc_release_swfw_sync_i225(hw, IGC_SWFW_EEP_SM);
    260  1.1  rin }
    261  1.1  rin 
    262  1.1  rin /* igc_acquire_swfw_sync_i225 - Acquire SW/FW semaphore
    263  1.1  rin  * @hw: pointer to the HW structure
    264  1.1  rin  * @mask: specifies which semaphore to acquire
    265  1.1  rin  *
    266  1.1  rin  * Acquire the SW/FW semaphore to access the PHY or NVM.  The mask
    267  1.1  rin  * will also specify which port we're acquiring the lock for.
    268  1.1  rin  */
    269  1.1  rin int
    270  1.1  rin igc_acquire_swfw_sync_i225(struct igc_hw *hw, uint16_t mask)
    271  1.1  rin {
    272  1.1  rin 	uint32_t swfw_sync;
    273  1.1  rin 	uint32_t swmask = mask;
    274  1.1  rin 	uint32_t fwmask = mask << 16;
    275  1.1  rin 	int ret_val = IGC_SUCCESS;
    276  1.1  rin 	int i = 0, timeout = 200;	/* FIXME: find real value to use here */
    277  1.1  rin 
    278  1.1  rin 	DEBUGFUNC("igc_acquire_swfw_sync_i225");
    279  1.1  rin 
    280  1.1  rin 	while (i < timeout) {
    281  1.1  rin 		if (igc_get_hw_semaphore_i225(hw)) {
    282  1.1  rin 			ret_val = -IGC_ERR_SWFW_SYNC;
    283  1.1  rin 			goto out;
    284  1.1  rin 		}
    285  1.1  rin 
    286  1.1  rin 		swfw_sync = IGC_READ_REG(hw, IGC_SW_FW_SYNC);
    287  1.1  rin 		if (!(swfw_sync & (fwmask | swmask)))
    288  1.1  rin 			break;
    289  1.1  rin 
    290  1.1  rin 		/* Firmware currently using resource (fwmask)
    291  1.1  rin 		 * or other software thread using resource (swmask)
    292  1.1  rin 		 */
    293  1.1  rin 		igc_put_hw_semaphore_generic(hw);
    294  1.1  rin 		msec_delay(5);
    295  1.1  rin 		i++;
    296  1.1  rin 	}
    297  1.1  rin 
    298  1.1  rin 	if (i == timeout) {
    299  1.1  rin 		DEBUGOUT("Driver can't access resource, SW_FW_SYNC timeout.\n");
    300  1.1  rin 		ret_val = -IGC_ERR_SWFW_SYNC;
    301  1.1  rin 		goto out;
    302  1.1  rin 	}
    303  1.1  rin 
    304  1.1  rin 	swfw_sync |= swmask;
    305  1.1  rin 	IGC_WRITE_REG(hw, IGC_SW_FW_SYNC, swfw_sync);
    306  1.1  rin 
    307  1.1  rin 	igc_put_hw_semaphore_generic(hw);
    308  1.1  rin 
    309  1.1  rin out:
    310  1.1  rin 	return ret_val;
    311  1.1  rin }
    312  1.1  rin 
    313  1.1  rin /* igc_release_swfw_sync_i225 - Release SW/FW semaphore
    314  1.1  rin  * @hw: pointer to the HW structure
    315  1.1  rin  * @mask: specifies which semaphore to acquire
    316  1.1  rin  *
    317  1.1  rin  * Release the SW/FW semaphore used to access the PHY or NVM.  The mask
    318  1.1  rin  * will also specify which port we're releasing the lock for.
    319  1.1  rin  */
    320  1.1  rin void
    321  1.1  rin igc_release_swfw_sync_i225(struct igc_hw *hw, uint16_t mask)
    322  1.1  rin {
    323  1.1  rin 	uint32_t swfw_sync;
    324  1.1  rin 
    325  1.1  rin 	DEBUGFUNC("igc_release_swfw_sync_i225");
    326  1.1  rin 
    327  1.1  rin 	while (igc_get_hw_semaphore_i225(hw) != IGC_SUCCESS)
    328  1.1  rin 		; /* Empty */
    329  1.1  rin 
    330  1.1  rin 	swfw_sync = IGC_READ_REG(hw, IGC_SW_FW_SYNC);
    331  1.1  rin 	swfw_sync &= ~mask;
    332  1.1  rin 	IGC_WRITE_REG(hw, IGC_SW_FW_SYNC, swfw_sync);
    333  1.1  rin 
    334  1.1  rin 	igc_put_hw_semaphore_generic(hw);
    335  1.1  rin }
    336  1.1  rin 
    337  1.1  rin /*
    338  1.1  rin  * igc_setup_copper_link_i225 - Configure copper link settings
    339  1.1  rin  * @hw: pointer to the HW structure
    340  1.1  rin  *
    341  1.1  rin  * Configures the link for auto-neg or forced speed and duplex.  Then we check
    342  1.1  rin  * for link, once link is established calls to configure collision distance
    343  1.1  rin  * and flow control are called.
    344  1.1  rin  */
    345  1.1  rin int
    346  1.1  rin igc_setup_copper_link_i225(struct igc_hw *hw)
    347  1.1  rin {
    348  1.1  rin 	uint32_t ctrl, phpm_reg;
    349  1.1  rin 	int ret_val;
    350  1.1  rin 
    351  1.1  rin 	DEBUGFUNC("igc_setup_copper_link_i225");
    352  1.1  rin 
    353  1.1  rin 	ctrl = IGC_READ_REG(hw, IGC_CTRL);
    354  1.1  rin 	ctrl |= IGC_CTRL_SLU;
    355  1.1  rin 	ctrl &= ~(IGC_CTRL_FRCSPD | IGC_CTRL_FRCDPX);
    356  1.1  rin 	IGC_WRITE_REG(hw, IGC_CTRL, ctrl);
    357  1.1  rin 
    358  1.1  rin 	phpm_reg = IGC_READ_REG(hw, IGC_I225_PHPM);
    359  1.1  rin 	phpm_reg &= ~IGC_I225_PHPM_GO_LINKD;
    360  1.1  rin 	IGC_WRITE_REG(hw, IGC_I225_PHPM, phpm_reg);
    361  1.1  rin 
    362  1.1  rin 	ret_val = igc_setup_copper_link_generic(hw);
    363  1.1  rin 
    364  1.1  rin 	return ret_val;
    365  1.1  rin }
    366  1.1  rin 
    367  1.1  rin /* igc_get_hw_semaphore_i225 - Acquire hardware semaphore
    368  1.1  rin  * @hw: pointer to the HW structure
    369  1.1  rin  *
    370  1.1  rin  * Acquire the HW semaphore to access the PHY or NVM
    371  1.1  rin  */
    372  1.1  rin int
    373  1.1  rin igc_get_hw_semaphore_i225(struct igc_hw *hw)
    374  1.1  rin {
    375  1.1  rin 	uint32_t swsm;
    376  1.1  rin 	int timeout = hw->nvm.word_size + 1;
    377  1.1  rin 	int i = 0;
    378  1.1  rin 
    379  1.1  rin 	DEBUGFUNC("igc_get_hw_semaphore_i225");
    380  1.1  rin 
    381  1.1  rin 	/* Get the SW semaphore */
    382  1.1  rin 	while (i < timeout) {
    383  1.1  rin 		swsm = IGC_READ_REG(hw, IGC_SWSM);
    384  1.1  rin 		if (!(swsm & IGC_SWSM_SMBI))
    385  1.1  rin 			break;
    386  1.1  rin 
    387  1.1  rin 		DELAY(50);
    388  1.1  rin 		i++;
    389  1.1  rin 	}
    390  1.1  rin 
    391  1.1  rin 	if (i == timeout) {
    392  1.1  rin 		/* In rare circumstances, the SW semaphore may already be held
    393  1.1  rin 		 * unintentionally. Clear the semaphore once before giving up.
    394  1.1  rin 		 */
    395  1.1  rin 		if (hw->dev_spec._i225.clear_semaphore_once) {
    396  1.1  rin 			hw->dev_spec._i225.clear_semaphore_once = false;
    397  1.1  rin 			igc_put_hw_semaphore_generic(hw);
    398  1.1  rin 			for (i = 0; i < timeout; i++) {
    399  1.1  rin 				swsm = IGC_READ_REG(hw, IGC_SWSM);
    400  1.1  rin 				if (!(swsm & IGC_SWSM_SMBI))
    401  1.1  rin 					break;
    402  1.1  rin 
    403  1.1  rin 				DELAY(50);
    404  1.1  rin 			}
    405  1.1  rin 		}
    406  1.1  rin 
    407  1.1  rin 		/* If we do not have the semaphore here, we have to give up. */
    408  1.1  rin 		if (i == timeout) {
    409  1.1  rin 			DEBUGOUT("Driver can't access device -\n");
    410  1.1  rin 			DEBUGOUT("SMBI bit is set.\n");
    411  1.1  rin 			return -IGC_ERR_NVM;
    412  1.1  rin 		}
    413  1.1  rin 	}
    414  1.1  rin 
    415  1.1  rin 	/* Get the FW semaphore. */
    416  1.1  rin 	for (i = 0; i < timeout; i++) {
    417  1.1  rin 		swsm = IGC_READ_REG(hw, IGC_SWSM);
    418  1.1  rin 		IGC_WRITE_REG(hw, IGC_SWSM, swsm | IGC_SWSM_SWESMBI);
    419  1.1  rin 
    420  1.1  rin 		/* Semaphore acquired if bit latched */
    421  1.1  rin 		if (IGC_READ_REG(hw, IGC_SWSM) & IGC_SWSM_SWESMBI)
    422  1.1  rin 			break;
    423  1.1  rin 
    424  1.1  rin 		DELAY(50);
    425  1.1  rin 	}
    426  1.1  rin 
    427  1.1  rin 	if (i == timeout) {
    428  1.1  rin 		/* Release semaphores */
    429  1.1  rin 		igc_put_hw_semaphore_generic(hw);
    430  1.1  rin 		DEBUGOUT("Driver can't access the NVM\n");
    431  1.1  rin 		return -IGC_ERR_NVM;
    432  1.1  rin 	}
    433  1.1  rin 
    434  1.1  rin 	return IGC_SUCCESS;
    435  1.1  rin }
    436  1.1  rin 
    437  1.1  rin /* igc_read_nvm_srrd_i225 - Reads Shadow Ram using EERD register
    438  1.1  rin  * @hw: pointer to the HW structure
    439  1.1  rin  * @offset: offset of word in the Shadow Ram to read
    440  1.1  rin  * @words: number of words to read
    441  1.1  rin  * @data: word read from the Shadow Ram
    442  1.1  rin  *
    443  1.1  rin  * Reads a 16 bit word from the Shadow Ram using the EERD register.
    444  1.1  rin  * Uses necessary synchronization semaphores.
    445  1.1  rin  */
    446  1.1  rin int
    447  1.1  rin igc_read_nvm_srrd_i225(struct igc_hw *hw, uint16_t offset, uint16_t words,
    448  1.1  rin     uint16_t *data)
    449  1.1  rin {
    450  1.1  rin 	uint16_t i, count;
    451  1.1  rin 	int status = IGC_SUCCESS;
    452  1.1  rin 
    453  1.1  rin 	DEBUGFUNC("igc_read_nvm_srrd_i225");
    454  1.1  rin 
    455  1.1  rin 	/* We cannot hold synchronization semaphores for too long,
    456  1.1  rin 	 * because of forceful takeover procedure. However it is more efficient
    457  1.1  rin 	 * to read in bursts than synchronizing access for each word.
    458  1.1  rin 	 */
    459  1.1  rin 	for (i = 0; i < words; i += IGC_EERD_EEWR_MAX_COUNT) {
    460  1.1  rin 		count = (words - i) / IGC_EERD_EEWR_MAX_COUNT > 0 ?
    461  1.1  rin 		    IGC_EERD_EEWR_MAX_COUNT : (words - i);
    462  1.1  rin 		if (hw->nvm.ops.acquire(hw) == IGC_SUCCESS) {
    463  1.1  rin 			status = igc_read_nvm_eerd(hw, offset, count, data + i);
    464  1.1  rin 			hw->nvm.ops.release(hw);
    465  1.1  rin 		} else {
    466  1.1  rin 			status = IGC_ERR_SWFW_SYNC;
    467  1.1  rin 		}
    468  1.1  rin 
    469  1.1  rin 		if (status != IGC_SUCCESS)
    470  1.1  rin 			break;
    471  1.1  rin 	}
    472  1.1  rin 
    473  1.1  rin 	return status;
    474  1.1  rin }
    475  1.1  rin 
    476  1.1  rin /* igc_write_nvm_srwr_i225 - Write to Shadow RAM using EEWR
    477  1.1  rin  * @hw: pointer to the HW structure
    478  1.1  rin  * @offset: offset within the Shadow RAM to be written to
    479  1.1  rin  * @words: number of words to write
    480  1.1  rin  * @data: 16 bit word(s) to be written to the Shadow RAM
    481  1.1  rin  *
    482  1.1  rin  * Writes data to Shadow RAM at offset using EEWR register.
    483  1.1  rin  *
    484  1.1  rin  * If igc_update_nvm_checksum is not called after this function , the
    485  1.1  rin  * data will not be committed to FLASH and also Shadow RAM will most likely
    486  1.1  rin  * contain an invalid checksum.
    487  1.1  rin  *
    488  1.1  rin  * If error code is returned, data and Shadow RAM may be inconsistent - buffer
    489  1.1  rin  * partially written.
    490  1.1  rin  */
    491  1.1  rin int
    492  1.1  rin igc_write_nvm_srwr_i225(struct igc_hw *hw, uint16_t offset, uint16_t words,
    493  1.1  rin     uint16_t *data)
    494  1.1  rin {
    495  1.1  rin 	uint16_t i, count;
    496  1.1  rin 	int status = IGC_SUCCESS;
    497  1.1  rin 
    498  1.1  rin 	DEBUGFUNC("igc_write_nvm_srwr_i225");
    499  1.1  rin 
    500  1.1  rin 	/* We cannot hold synchronization semaphores for too long,
    501  1.1  rin 	 * because of forceful takeover procedure. However it is more efficient
    502  1.1  rin 	 * to write in bursts than synchronizing access for each word.
    503  1.1  rin 	 */
    504  1.1  rin 	for (i = 0; i < words; i += IGC_EERD_EEWR_MAX_COUNT) {
    505  1.1  rin 		count = (words - i) / IGC_EERD_EEWR_MAX_COUNT > 0 ?
    506  1.1  rin 		    IGC_EERD_EEWR_MAX_COUNT : (words - i);
    507  1.1  rin 		if (hw->nvm.ops.acquire(hw) == IGC_SUCCESS) {
    508  1.1  rin 			status = __igc_write_nvm_srwr(hw, offset, count,
    509  1.1  rin 			    data + i);
    510  1.1  rin 			hw->nvm.ops.release(hw);
    511  1.1  rin 		} else
    512  1.1  rin 			status = IGC_ERR_SWFW_SYNC;
    513  1.1  rin 
    514  1.1  rin 		if (status != IGC_SUCCESS)
    515  1.1  rin 			break;
    516  1.1  rin 	}
    517  1.1  rin 
    518  1.1  rin 	return status;
    519  1.1  rin }
    520  1.1  rin 
    521  1.1  rin /* __igc_write_nvm_srwr - Write to Shadow Ram using EEWR
    522  1.1  rin  * @hw: pointer to the HW structure
    523  1.1  rin  * @offset: offset within the Shadow Ram to be written to
    524  1.1  rin  * @words: number of words to write
    525  1.1  rin  * @data: 16 bit word(s) to be written to the Shadow Ram
    526  1.1  rin  *
    527  1.1  rin  * Writes data to Shadow Ram at offset using EEWR register.
    528  1.1  rin  *
    529  1.1  rin  * If igc_update_nvm_checksum is not called after this function , the
    530  1.1  rin  * Shadow Ram will most likely contain an invalid checksum.
    531  1.1  rin  */
    532  1.1  rin int
    533  1.1  rin __igc_write_nvm_srwr(struct igc_hw *hw, uint16_t offset, uint16_t words,
    534  1.1  rin     uint16_t *data)
    535  1.1  rin {
    536  1.1  rin 	struct igc_nvm_info *nvm = &hw->nvm;
    537  1.1  rin 	uint32_t i, k, eewr = 0;
    538  1.1  rin 	uint32_t attempts = 100000;
    539  1.1  rin 	int ret_val = IGC_SUCCESS;
    540  1.1  rin 
    541  1.1  rin 	DEBUGFUNC("__igc_write_nvm_srwr");
    542  1.1  rin 
    543  1.1  rin 	/* A check for invalid values:  offset too large, too many words,
    544  1.1  rin 	 * too many words for the offset, and not enough words.
    545  1.1  rin 	 */
    546  1.1  rin 	if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
    547  1.1  rin 	    (words == 0)) {
    548  1.1  rin 		DEBUGOUT("nvm parameter(s) out of bounds\n");
    549  1.1  rin 		ret_val = -IGC_ERR_NVM;
    550  1.1  rin 		goto out;
    551  1.1  rin 	}
    552  1.1  rin 
    553  1.1  rin 	for (i = 0; i < words; i++) {
    554  1.1  rin 		eewr = ((offset + i) << IGC_NVM_RW_ADDR_SHIFT) |
    555  1.1  rin 		    (data[i] << IGC_NVM_RW_REG_DATA) | IGC_NVM_RW_REG_START;
    556  1.1  rin 
    557  1.1  rin 		IGC_WRITE_REG(hw, IGC_SRWR, eewr);
    558  1.1  rin 
    559  1.1  rin 		for (k = 0; k < attempts; k++) {
    560  1.1  rin 			if (IGC_NVM_RW_REG_DONE & IGC_READ_REG(hw, IGC_SRWR)) {
    561  1.1  rin 				ret_val = IGC_SUCCESS;
    562  1.1  rin 				break;
    563  1.1  rin 			}
    564  1.1  rin 			DELAY(5);
    565  1.1  rin 		}
    566  1.1  rin 
    567  1.1  rin 		if (ret_val != IGC_SUCCESS) {
    568  1.1  rin 			DEBUGOUT("Shadow RAM write EEWR timed out\n");
    569  1.1  rin 			break;
    570  1.1  rin 		}
    571  1.1  rin 	}
    572  1.1  rin 
    573  1.1  rin out:
    574  1.1  rin 	return ret_val;
    575  1.1  rin }
    576  1.1  rin 
    577  1.1  rin /* igc_validate_nvm_checksum_i225 - Validate EEPROM checksum
    578  1.1  rin  * @hw: pointer to the HW structure
    579  1.1  rin  *
    580  1.1  rin  * Calculates the EEPROM checksum by reading/adding each word of the EEPROM
    581  1.1  rin  * and then verifies that the sum of the EEPROM is equal to 0xBABA.
    582  1.1  rin  */
    583  1.1  rin int
    584  1.1  rin igc_validate_nvm_checksum_i225(struct igc_hw *hw)
    585  1.1  rin {
    586  1.1  rin 	int status = IGC_SUCCESS;
    587  1.1  rin 	int (*read_op_ptr)(struct igc_hw *, uint16_t, uint16_t, uint16_t *);
    588  1.1  rin 
    589  1.1  rin 	DEBUGFUNC("igc_validate_nvm_checksum_i225");
    590  1.1  rin 
    591  1.1  rin 	if (hw->nvm.ops.acquire(hw) == IGC_SUCCESS) {
    592  1.1  rin 		/* Replace the read function with semaphore grabbing with
    593  1.1  rin 		 * the one that skips this for a while.
    594  1.1  rin 		 * We have semaphore taken already here.
    595  1.1  rin 		 */
    596  1.1  rin 		read_op_ptr = hw->nvm.ops.read;
    597  1.1  rin 		hw->nvm.ops.read = igc_read_nvm_eerd;
    598  1.1  rin 
    599  1.1  rin 		status = igc_validate_nvm_checksum_generic(hw);
    600  1.1  rin 
    601  1.1  rin 		/* Revert original read operation. */
    602  1.1  rin 		hw->nvm.ops.read = read_op_ptr;
    603  1.1  rin 
    604  1.1  rin 		hw->nvm.ops.release(hw);
    605  1.1  rin 	} else {
    606  1.1  rin 		status = IGC_ERR_SWFW_SYNC;
    607  1.1  rin 	}
    608  1.1  rin 
    609  1.1  rin 	return status;
    610  1.1  rin }
    611  1.1  rin 
    612  1.1  rin /* igc_update_nvm_checksum_i225 - Update EEPROM checksum
    613  1.1  rin  * @hw: pointer to the HW structure
    614  1.1  rin  *
    615  1.1  rin  * Updates the EEPROM checksum by reading/adding each word of the EEPROM
    616  1.1  rin  * up to the checksum.  Then calculates the EEPROM checksum and writes the
    617  1.1  rin  * value to the EEPROM. Next commit EEPROM data onto the Flash.
    618  1.1  rin  */
    619  1.1  rin int
    620  1.1  rin igc_update_nvm_checksum_i225(struct igc_hw *hw)
    621  1.1  rin {
    622  1.1  rin 	uint16_t checksum = 0;
    623  1.1  rin 	uint16_t i, nvm_data;
    624  1.1  rin 	int ret_val;
    625  1.1  rin 
    626  1.1  rin 	DEBUGFUNC("igc_update_nvm_checksum_i225");
    627  1.1  rin 
    628  1.1  rin 	/* Read the first word from the EEPROM. If this times out or fails, do
    629  1.1  rin 	 * not continue or we could be in for a very long wait while every
    630  1.1  rin 	 * EEPROM read fails
    631  1.1  rin 	 */
    632  1.1  rin 	ret_val = igc_read_nvm_eerd(hw, 0, 1, &nvm_data);
    633  1.1  rin 	if (ret_val != IGC_SUCCESS) {
    634  1.1  rin 		DEBUGOUT("EEPROM read failed\n");
    635  1.1  rin 		goto out;
    636  1.1  rin 	}
    637  1.1  rin 
    638  1.1  rin 	if (hw->nvm.ops.acquire(hw) == IGC_SUCCESS) {
    639  1.1  rin 		/* Do not use hw->nvm.ops.write, hw->nvm.ops.read
    640  1.1  rin 		 * because we do not want to take the synchronization
    641  1.1  rin 		 * semaphores twice here.
    642  1.1  rin 		 */
    643  1.1  rin 
    644  1.1  rin 		for (i = 0; i < NVM_CHECKSUM_REG; i++) {
    645  1.1  rin 			ret_val = igc_read_nvm_eerd(hw, i, 1, &nvm_data);
    646  1.1  rin 			if (ret_val) {
    647  1.1  rin 				hw->nvm.ops.release(hw);
    648  1.1  rin 				DEBUGOUT("NVM Read Error while updating\n");
    649  1.1  rin 				DEBUGOUT("checksum.\n");
    650  1.1  rin 				goto out;
    651  1.1  rin 			}
    652  1.1  rin 			checksum += nvm_data;
    653  1.1  rin 		}
    654  1.1  rin 		checksum = (uint16_t)NVM_SUM - checksum;
    655  1.1  rin 		ret_val = __igc_write_nvm_srwr(hw, NVM_CHECKSUM_REG, 1,
    656  1.1  rin 		    &checksum);
    657  1.1  rin 		if (ret_val != IGC_SUCCESS) {
    658  1.1  rin 			hw->nvm.ops.release(hw);
    659  1.1  rin 			DEBUGOUT("NVM Write Error while updating checksum.\n");
    660  1.1  rin 			goto out;
    661  1.1  rin 		}
    662  1.1  rin 
    663  1.1  rin 		hw->nvm.ops.release(hw);
    664  1.1  rin 
    665  1.1  rin 		ret_val = igc_update_flash_i225(hw);
    666  1.1  rin 	} else {
    667  1.1  rin 		ret_val = IGC_ERR_SWFW_SYNC;
    668  1.1  rin 	}
    669  1.1  rin out:
    670  1.1  rin 	return ret_val;
    671  1.1  rin }
    672  1.1  rin 
    673  1.1  rin /* igc_get_flash_presence_i225 - Check if flash device is detected.
    674  1.1  rin  * @hw: pointer to the HW structure
    675  1.1  rin  */
    676  1.1  rin bool
    677  1.1  rin igc_get_flash_presence_i225(struct igc_hw *hw)
    678  1.1  rin {
    679  1.1  rin 	uint32_t eec = 0;
    680  1.1  rin 	bool ret_val = false;
    681  1.1  rin 
    682  1.1  rin 	DEBUGFUNC("igc_get_flash_presence_i225");
    683  1.1  rin 
    684  1.1  rin 	eec = IGC_READ_REG(hw, IGC_EECD);
    685  1.1  rin 
    686  1.1  rin 	if (eec & IGC_EECD_FLASH_DETECTED_I225)
    687  1.1  rin 		ret_val = true;
    688  1.1  rin 
    689  1.1  rin 	return ret_val;
    690  1.1  rin }
    691  1.1  rin 
    692  1.1  rin /* igc_set_flsw_flash_burst_counter_i225 - sets FLSW NVM Burst
    693  1.1  rin  * Counter in FLSWCNT register.
    694  1.1  rin  *
    695  1.1  rin  * @hw: pointer to the HW structure
    696  1.1  rin  * @burst_counter: size in bytes of the Flash burst to read or write
    697  1.1  rin  */
    698  1.1  rin int
    699  1.1  rin igc_set_flsw_flash_burst_counter_i225(struct igc_hw *hw, uint32_t burst_counter)
    700  1.1  rin {
    701  1.1  rin 	int ret_val = IGC_SUCCESS;
    702  1.1  rin 
    703  1.1  rin 	DEBUGFUNC("igc_set_flsw_flash_burst_counter_i225");
    704  1.1  rin 
    705  1.1  rin 	/* Validate input data */
    706  1.1  rin 	if (burst_counter < IGC_I225_SHADOW_RAM_SIZE) {
    707  1.1  rin 		/* Write FLSWCNT - burst counter */
    708  1.1  rin 		IGC_WRITE_REG(hw, IGC_I225_FLSWCNT, burst_counter);
    709  1.1  rin 	} else {
    710  1.1  rin 		ret_val = IGC_ERR_INVALID_ARGUMENT;
    711  1.1  rin 	}
    712  1.1  rin 
    713  1.1  rin 	return ret_val;
    714  1.1  rin }
    715  1.1  rin 
    716  1.1  rin 
    717  1.1  rin /* igc_write_erase_flash_command_i225 - write/erase to a sector
    718  1.1  rin  * region on a given address.
    719  1.1  rin  *
    720  1.1  rin  * @hw: pointer to the HW structure
    721  1.1  rin  * @opcode: opcode to be used for the write command
    722  1.1  rin  * @address: the offset to write into the FLASH image
    723  1.1  rin  */
    724  1.1  rin int
    725  1.1  rin igc_write_erase_flash_command_i225(struct igc_hw *hw, uint32_t opcode,
    726  1.1  rin     uint32_t address)
    727  1.1  rin {
    728  1.1  rin 	uint32_t flswctl = 0;
    729  1.1  rin 	int timeout = IGC_NVM_GRANT_ATTEMPTS;
    730  1.1  rin 	int ret_val = IGC_SUCCESS;
    731  1.1  rin 
    732  1.1  rin 	DEBUGFUNC("igc_write_erase_flash_command_i225");
    733  1.1  rin 
    734  1.1  rin 	flswctl = IGC_READ_REG(hw, IGC_I225_FLSWCTL);
    735  1.1  rin 	/* Polling done bit on FLSWCTL register */
    736  1.1  rin 	while (timeout) {
    737  1.1  rin 		if (flswctl & IGC_FLSWCTL_DONE)
    738  1.1  rin 			break;
    739  1.1  rin 		DELAY(5);
    740  1.1  rin 		flswctl = IGC_READ_REG(hw, IGC_I225_FLSWCTL);
    741  1.1  rin 		timeout--;
    742  1.1  rin 	}
    743  1.1  rin 
    744  1.1  rin 	if (!timeout) {
    745  1.1  rin 		DEBUGOUT("Flash transaction was not done\n");
    746  1.1  rin 		return -IGC_ERR_NVM;
    747  1.1  rin 	}
    748  1.1  rin 
    749  1.1  rin 	/* Build and issue command on FLSWCTL register */
    750  1.1  rin 	flswctl = address | opcode;
    751  1.1  rin 	IGC_WRITE_REG(hw, IGC_I225_FLSWCTL, flswctl);
    752  1.1  rin 
    753  1.1  rin 	/* Check if issued command is valid on FLSWCTL register */
    754  1.1  rin 	flswctl = IGC_READ_REG(hw, IGC_I225_FLSWCTL);
    755  1.1  rin 	if (!(flswctl & IGC_FLSWCTL_CMDV)) {
    756  1.1  rin 		DEBUGOUT("Write flash command failed\n");
    757  1.1  rin 		ret_val = IGC_ERR_INVALID_ARGUMENT;
    758  1.1  rin 	}
    759  1.1  rin 
    760  1.1  rin 	return ret_val;
    761  1.1  rin }
    762  1.1  rin 
    763  1.1  rin /* igc_update_flash_i225 - Commit EEPROM to the flash
    764  1.1  rin  * if fw_valid_bit is set, FW is active. setting FLUPD bit in EEC
    765  1.1  rin  * register makes the FW load the internal shadow RAM into the flash.
    766  1.1  rin  * Otherwise, fw_valid_bit is 0. if FL_SECU.block_prtotected_sw = 0
    767  1.1  rin  * then FW is not active so the SW is responsible shadow RAM dump.
    768  1.1  rin  *
    769  1.1  rin  * @hw: pointer to the HW structure
    770  1.1  rin  */
    771  1.1  rin int
    772  1.1  rin igc_update_flash_i225(struct igc_hw *hw)
    773  1.1  rin {
    774  1.1  rin 	uint32_t block_sw_protect = 1;
    775  1.1  rin 	uint32_t i, flup, fw_valid_bit;
    776  1.1  rin 	uint16_t current_offset;
    777  1.1  rin 	uint16_t base_address = 0x0;
    778  1.1  rin 	uint16_t current_offset_data = 0;
    779  1.1  rin 	int ret_val = 0;
    780  1.1  rin 
    781  1.1  rin 	DEBUGFUNC("igc_update_flash_i225");
    782  1.1  rin 
    783  1.1  rin 	block_sw_protect = IGC_READ_REG(hw, IGC_I225_FLSECU) &
    784  1.1  rin 	    IGC_FLSECU_BLK_SW_ACCESS_I225;
    785  1.1  rin 
    786  1.1  rin 	fw_valid_bit = IGC_READ_REG(hw, IGC_FWSM) & IGC_FWSM_FW_VALID_I225;
    787  1.1  rin 	if (fw_valid_bit) {
    788  1.1  rin 		ret_val = igc_pool_flash_update_done_i225(hw);
    789  1.1  rin 		if (ret_val == -IGC_ERR_NVM) {
    790  1.1  rin 			DEBUGOUT("Flash update time out\n");
    791  1.1  rin 			goto out;
    792  1.1  rin 		}
    793  1.1  rin 
    794  1.1  rin 		flup = IGC_READ_REG(hw, IGC_EECD) | IGC_EECD_FLUPD_I225;
    795  1.1  rin 		IGC_WRITE_REG(hw, IGC_EECD, flup);
    796  1.1  rin 
    797  1.1  rin 		ret_val = igc_pool_flash_update_done_i225(hw);
    798  1.1  rin 		if (ret_val == IGC_SUCCESS)
    799  1.1  rin 			DEBUGOUT("Flash update complete\n");
    800  1.1  rin 		else
    801  1.1  rin 			DEBUGOUT("Flash update time out\n");
    802  1.1  rin 	} else if (!block_sw_protect) {
    803  1.1  rin 		/* FW is not active and security protection is disabled.
    804  1.1  rin 		 * therefore, SW is in charge of shadow RAM dump.
    805  1.1  rin 		 * Check which sector is valid. if sector 0 is valid,
    806  1.1  rin 		 * base address remains 0x0. otherwise, sector 1 is
    807  1.1  rin 		 * valid and its base address is 0x1000
    808  1.1  rin 		 */
    809  1.1  rin 		if (IGC_READ_REG(hw, IGC_EECD) & IGC_EECD_SEC1VAL_I225)
    810  1.1  rin 			base_address = 0x1000;
    811  1.1  rin 
    812  1.1  rin 		/* Valid sector erase */
    813  1.1  rin 		ret_val = igc_write_erase_flash_command_i225(hw,
    814  1.1  rin 		    IGC_I225_ERASE_CMD_OPCODE, base_address);
    815  1.1  rin 		if (!ret_val) {
    816  1.1  rin 			DEBUGOUT("Sector erase failed\n");
    817  1.1  rin 			goto out;
    818  1.1  rin 		}
    819  1.1  rin 
    820  1.1  rin 		current_offset = base_address;
    821  1.1  rin 
    822  1.1  rin 		/* Write */
    823  1.1  rin 		for (i = 0; i < IGC_I225_SHADOW_RAM_SIZE / 2; i++) {
    824  1.1  rin 			/* Set burst write length */
    825  1.1  rin 			ret_val = igc_set_flsw_flash_burst_counter_i225(hw,
    826  1.1  rin 			    0x2);
    827  1.1  rin 			if (ret_val != IGC_SUCCESS)
    828  1.1  rin 				break;
    829  1.1  rin 
    830  1.1  rin 			/* Set address and opcode */
    831  1.1  rin 			ret_val = igc_write_erase_flash_command_i225(hw,
    832  1.1  rin 			    IGC_I225_WRITE_CMD_OPCODE, 2 * current_offset);
    833  1.1  rin 			if (ret_val != IGC_SUCCESS)
    834  1.1  rin 				break;
    835  1.1  rin 
    836  1.1  rin 			ret_val = igc_read_nvm_eerd(hw, current_offset, 1,
    837  1.1  rin 			    &current_offset_data);
    838  1.1  rin 			if (ret_val) {
    839  1.1  rin 				DEBUGOUT("Failed to read from EEPROM\n");
    840  1.1  rin 				goto out;
    841  1.1  rin 			}
    842  1.1  rin 
    843  1.1  rin 			/* Write CurrentOffseData to FLSWDATA register */
    844  1.1  rin 			IGC_WRITE_REG(hw, IGC_I225_FLSWDATA,
    845  1.1  rin 			    current_offset_data);
    846  1.1  rin 			current_offset++;
    847  1.1  rin 
    848  1.1  rin 			/* Wait till operation has finished */
    849  1.1  rin 			ret_val = igc_poll_eerd_eewr_done(hw,
    850  1.1  rin 			    IGC_NVM_POLL_READ);
    851  1.1  rin 			if (ret_val)
    852  1.1  rin 				break;
    853  1.1  rin 
    854  1.1  rin 			DELAY(1000);
    855  1.1  rin 		}
    856  1.1  rin 	}
    857  1.1  rin out:
    858  1.1  rin 	return ret_val;
    859  1.1  rin }
    860  1.1  rin 
    861  1.1  rin /* igc_pool_flash_update_done_i225 - Pool FLUDONE status.
    862  1.1  rin  * @hw: pointer to the HW structure
    863  1.1  rin  */
    864  1.1  rin int
    865  1.1  rin igc_pool_flash_update_done_i225(struct igc_hw *hw)
    866  1.1  rin {
    867  1.1  rin 	uint32_t i, reg;
    868  1.1  rin 	int ret_val = -IGC_ERR_NVM;
    869  1.1  rin 
    870  1.1  rin 	DEBUGFUNC("igc_pool_flash_update_done_i225");
    871  1.1  rin 
    872  1.1  rin 	for (i = 0; i < IGC_FLUDONE_ATTEMPTS; i++) {
    873  1.1  rin 		reg = IGC_READ_REG(hw, IGC_EECD);
    874  1.1  rin 		if (reg & IGC_EECD_FLUDONE_I225) {
    875  1.1  rin 			ret_val = IGC_SUCCESS;
    876  1.1  rin 			break;
    877  1.1  rin 		}
    878  1.1  rin 		DELAY(5);
    879  1.1  rin 	}
    880  1.1  rin 
    881  1.1  rin 	return ret_val;
    882  1.1  rin }
    883  1.1  rin 
    884  1.1  rin /* igc_set_ltr_i225 - Set Latency Tolerance Reporting thresholds.
    885  1.1  rin  * @hw: pointer to the HW structure
    886  1.1  rin  * @link: bool indicating link status
    887  1.1  rin  *
    888  1.1  rin  * Set the LTR thresholds based on the link speed (Mbps), EEE, and DMAC
    889  1.1  rin  * settings, otherwise specify that there is no LTR requirement.
    890  1.1  rin  */
    891  1.1  rin int
    892  1.1  rin igc_set_ltr_i225(struct igc_hw *hw, bool link)
    893  1.1  rin {
    894  1.1  rin 	uint16_t speed, duplex;
    895  1.1  rin 	uint32_t tw_system, ltrc, ltrv, ltr_min, ltr_max, scale_min, scale_max;
    896  1.1  rin 	int size;
    897  1.1  rin 
    898  1.1  rin 	DEBUGFUNC("igc_set_ltr_i225");
    899  1.1  rin 
    900  1.1  rin 	/* If we do not have link, LTR thresholds are zero. */
    901  1.1  rin 	if (link) {
    902  1.1  rin 		hw->mac.ops.get_link_up_info(hw, &speed, &duplex);
    903  1.1  rin 
    904  1.1  rin 		/* Check if using copper interface with EEE enabled or if the
    905  1.1  rin 		 * link speed is 10 Mbps.
    906  1.1  rin 		 */
    907  1.1  rin 		if ((hw->phy.media_type == igc_media_type_copper) &&
    908  1.1  rin 		    !(hw->dev_spec._i225.eee_disable) &&
    909  1.1  rin 		     (speed != SPEED_10)) {
    910  1.1  rin 			/* EEE enabled, so send LTRMAX threshold. */
    911  1.1  rin 			ltrc = IGC_READ_REG(hw, IGC_LTRC) | IGC_LTRC_EEEMS_EN;
    912  1.1  rin 			IGC_WRITE_REG(hw, IGC_LTRC, ltrc);
    913  1.1  rin 
    914  1.1  rin 			/* Calculate tw_system (nsec). */
    915  1.1  rin 			if (speed == SPEED_100) {
    916  1.1  rin 				tw_system = ((IGC_READ_REG(hw, IGC_EEE_SU) &
    917  1.1  rin 				    IGC_TW_SYSTEM_100_MASK) >>
    918  1.1  rin 				    IGC_TW_SYSTEM_100_SHIFT) * 500;
    919  1.1  rin 			} else {
    920  1.1  rin 				tw_system = (IGC_READ_REG(hw, IGC_EEE_SU) &
    921  1.1  rin 				    IGC_TW_SYSTEM_1000_MASK) * 500;
    922  1.1  rin 				}
    923  1.1  rin 		} else {
    924  1.1  rin 			tw_system = 0;
    925  1.1  rin 			}
    926  1.1  rin 
    927  1.1  rin 		/* Get the Rx packet buffer size. */
    928  1.1  rin 		size = IGC_READ_REG(hw, IGC_RXPBS) & IGC_RXPBS_SIZE_I225_MASK;
    929  1.1  rin 
    930  1.1  rin 		/* Calculations vary based on DMAC settings. */
    931  1.1  rin 		if (IGC_READ_REG(hw, IGC_DMACR) & IGC_DMACR_DMAC_EN) {
    932  1.1  rin 			size -= (IGC_READ_REG(hw, IGC_DMACR) &
    933  1.1  rin 			    IGC_DMACR_DMACTHR_MASK) >> IGC_DMACR_DMACTHR_SHIFT;
    934  1.1  rin 			/* Convert size to bits. */
    935  1.1  rin 			size *= 1024 * 8;
    936  1.1  rin 		} else {
    937  1.1  rin 			/* Convert size to bytes, subtract the MTU, and then
    938  1.1  rin 			 * convert the size to bits.
    939  1.1  rin 			 */
    940  1.1  rin 			size *= 1024;
    941  1.1  rin 			size -= hw->dev_spec._i225.mtu;
    942  1.1  rin 			size *= 8;
    943  1.1  rin 		}
    944  1.1  rin 
    945  1.1  rin 		if (size < 0) {
    946  1.1  rin 			DEBUGOUT1("Invalid effective Rx buffer size %d\n",
    947  1.1  rin 			    size);
    948  1.1  rin 			return -IGC_ERR_CONFIG;
    949  1.1  rin 		}
    950  1.1  rin 
    951  1.1  rin 		/* Calculate the thresholds. Since speed is in Mbps, simplify
    952  1.1  rin 		 * the calculation by multiplying size/speed by 1000 for result
    953  1.1  rin 		 * to be in nsec before dividing by the scale in nsec. Set the
    954  1.1  rin 		 * scale such that the LTR threshold fits in the register.
    955  1.1  rin 		 */
    956  1.1  rin 		ltr_min = (1000 * size) / speed;
    957  1.1  rin 		ltr_max = ltr_min + tw_system;
    958  1.1  rin 		scale_min = (ltr_min / 1024) < 1024 ? IGC_LTRMINV_SCALE_1024 :
    959  1.1  rin 		    IGC_LTRMINV_SCALE_32768;
    960  1.1  rin 		scale_max = (ltr_max / 1024) < 1024 ? IGC_LTRMAXV_SCALE_1024 :
    961  1.1  rin 		    IGC_LTRMAXV_SCALE_32768;
    962  1.1  rin 		ltr_min /= scale_min == IGC_LTRMINV_SCALE_1024 ? 1024 : 32768;
    963  1.1  rin 		ltr_max /= scale_max == IGC_LTRMAXV_SCALE_1024 ? 1024 : 32768;
    964  1.1  rin 
    965  1.1  rin 		/* Only write the LTR thresholds if they differ from before. */
    966  1.1  rin 		ltrv = IGC_READ_REG(hw, IGC_LTRMINV);
    967  1.1  rin 		if (ltr_min != (ltrv & IGC_LTRMINV_LTRV_MASK)) {
    968  1.1  rin 			ltrv = IGC_LTRMINV_LSNP_REQ | ltr_min |
    969  1.1  rin 			    (scale_min << IGC_LTRMINV_SCALE_SHIFT);
    970  1.1  rin 			IGC_WRITE_REG(hw, IGC_LTRMINV, ltrv);
    971  1.1  rin 		}
    972  1.1  rin 
    973  1.1  rin 		ltrv = IGC_READ_REG(hw, IGC_LTRMAXV);
    974  1.1  rin 		if (ltr_max != (ltrv & IGC_LTRMAXV_LTRV_MASK)) {
    975  1.1  rin 			ltrv = IGC_LTRMAXV_LSNP_REQ | ltr_max |
    976  1.1  rin 			    (scale_min << IGC_LTRMAXV_SCALE_SHIFT);
    977  1.1  rin 			IGC_WRITE_REG(hw, IGC_LTRMAXV, ltrv);
    978  1.1  rin 		}
    979  1.1  rin 	}
    980  1.1  rin 
    981  1.1  rin 	return IGC_SUCCESS;
    982  1.1  rin }
    983  1.1  rin 
    984  1.1  rin /* igc_check_for_link_i225 - Check for link
    985  1.1  rin  * @hw: pointer to the HW structure
    986  1.1  rin  *
    987  1.1  rin  * Checks to see of the link status of the hardware has changed.  If a
    988  1.1  rin  * change in link status has been detected, then we read the PHY registers
    989  1.1  rin  * to get the current speed/duplex if link exists.
    990  1.1  rin  */
    991  1.1  rin int
    992  1.1  rin igc_check_for_link_i225(struct igc_hw *hw)
    993  1.1  rin {
    994  1.1  rin 	struct igc_mac_info *mac = &hw->mac;
    995  1.1  rin 	int ret_val;
    996  1.1  rin 	bool link = false;
    997  1.1  rin 
    998  1.1  rin 	DEBUGFUNC("igc_check_for_link_i225");
    999  1.1  rin 
   1000  1.1  rin 	/* We only want to go out to the PHY registers to see if
   1001  1.1  rin 	 * Auto-Neg has completed and/or if our link status has
   1002  1.1  rin 	 * changed.  The get_link_status flag is set upon receiving
   1003  1.1  rin 	 * a Link Status Change or Rx Sequence Error interrupt.
   1004  1.1  rin 	 */
   1005  1.1  rin 	if (!mac->get_link_status) {
   1006  1.1  rin 		ret_val = IGC_SUCCESS;
   1007  1.1  rin 		goto out;
   1008  1.1  rin 	}
   1009  1.1  rin 
   1010  1.1  rin 	/* First we want to see if the MII Status Register reports
   1011  1.1  rin 	 * link.  If so, then we want to get the current speed/duplex
   1012  1.1  rin 	 * of the PHY.
   1013  1.1  rin 	 */
   1014  1.1  rin 	ret_val = igc_phy_has_link_generic(hw, 1, 0, &link);
   1015  1.1  rin 	if (ret_val)
   1016  1.1  rin 		goto out;
   1017  1.1  rin 
   1018  1.1  rin 	if (!link)
   1019  1.1  rin 		goto out; /* No link detected */
   1020  1.1  rin 
   1021  1.1  rin 	/* First we want to see if the MII Status Register reports
   1022  1.1  rin 	 * link.  If so, then we want to get the current speed/duplex
   1023  1.1  rin 	 * of the PHY.
   1024  1.1  rin 	 */
   1025  1.1  rin 	ret_val = igc_phy_has_link_generic(hw, 1, 0, &link);
   1026  1.1  rin 	if (ret_val)
   1027  1.1  rin 		goto out;
   1028  1.1  rin 
   1029  1.1  rin 	if (!link)
   1030  1.1  rin 		goto out; /* No link detected */
   1031  1.1  rin 
   1032  1.1  rin 	mac->get_link_status = false;
   1033  1.1  rin 
   1034  1.1  rin 	/* Check if there was DownShift, must be checked
   1035  1.1  rin 	 * immediately after link-up
   1036  1.1  rin 	 */
   1037  1.1  rin 	igc_check_downshift_generic(hw);
   1038  1.1  rin 
   1039  1.1  rin 	/* If we are forcing speed/duplex, then we simply return since
   1040  1.1  rin 	 * we have already determined whether we have link or not.
   1041  1.1  rin 	 */
   1042  1.1  rin 	if (!mac->autoneg)
   1043  1.1  rin 		goto out;
   1044  1.1  rin 
   1045  1.1  rin 	/* Auto-Neg is enabled.  Auto Speed Detection takes care
   1046  1.1  rin 	 * of MAC speed/duplex configuration.  So we only need to
   1047  1.1  rin 	 * configure Collision Distance in the MAC.
   1048  1.1  rin 	 */
   1049  1.1  rin 	mac->ops.config_collision_dist(hw);
   1050  1.1  rin 
   1051  1.1  rin 	/* Configure Flow Control now that Auto-Neg has completed.
   1052  1.1  rin 	 * First, we need to restore the desired flow control
   1053  1.1  rin 	 * settings because we may have had to re-autoneg with a
   1054  1.1  rin 	 * different link partner.
   1055  1.1  rin 	 */
   1056  1.1  rin 	ret_val = igc_config_fc_after_link_up_generic(hw);
   1057  1.1  rin 	if (ret_val)
   1058  1.1  rin 		DEBUGOUT("Error configuring flow control\n");
   1059  1.1  rin out:
   1060  1.1  rin 	/* Now that we are aware of our link settings, we can set the LTR
   1061  1.1  rin 	 * thresholds.
   1062  1.1  rin 	 */
   1063  1.1  rin 	ret_val = igc_set_ltr_i225(hw, link);
   1064  1.1  rin 
   1065  1.1  rin 	return ret_val;
   1066  1.1  rin }
   1067  1.1  rin 
   1068  1.1  rin /* igc_init_function_pointers_i225 - Init func ptrs.
   1069  1.1  rin  * @hw: pointer to the HW structure
   1070  1.1  rin  *
   1071  1.1  rin  * Called to initialize all function pointers and parameters.
   1072  1.1  rin  */
   1073  1.1  rin void
   1074  1.1  rin igc_init_function_pointers_i225(struct igc_hw *hw)
   1075  1.1  rin {
   1076  1.1  rin 	igc_init_mac_ops_generic(hw);
   1077  1.1  rin 	igc_init_phy_ops_generic(hw);
   1078  1.1  rin 	igc_init_nvm_ops_generic(hw);
   1079  1.1  rin 	hw->mac.ops.init_params = igc_init_mac_params_i225;
   1080  1.1  rin 	hw->nvm.ops.init_params = igc_init_nvm_params_i225;
   1081  1.1  rin 	hw->phy.ops.init_params = igc_init_phy_params_i225;
   1082  1.1  rin }
   1083  1.1  rin 
   1084  1.1  rin /* igc_init_hw_i225 - Init hw for I225
   1085  1.1  rin  * @hw: pointer to the HW structure
   1086  1.1  rin  *
   1087  1.1  rin  * Called to initialize hw for i225 hw family.
   1088  1.1  rin  */
   1089  1.1  rin int
   1090  1.1  rin igc_init_hw_i225(struct igc_hw *hw)
   1091  1.1  rin {
   1092  1.1  rin 	int ret_val;
   1093  1.1  rin 
   1094  1.1  rin 	DEBUGFUNC("igc_init_hw_i225");
   1095  1.1  rin 
   1096  1.1  rin 	ret_val = igc_init_hw_base(hw);
   1097  1.1  rin 	return ret_val;
   1098  1.1  rin }
   1099  1.1  rin 
   1100  1.1  rin /**
   1101  1.1  rin  *  igc_set_eee_i225 - Enable/disable EEE support
   1102  1.1  rin  *  @hw: pointer to the HW structure
   1103  1.1  rin  *  @adv2p5G: boolean flag enabling 2.5G EEE advertisement
   1104  1.1  rin  *  @adv1G: boolean flag enabling 1G EEE advertisement
   1105  1.1  rin  *  @adv100M: boolean flag enabling 100M EEE advertisement
   1106  1.1  rin  *
   1107  1.1  rin  *  Enable/disable EEE based on setting in dev_spec structure.
   1108  1.1  rin  *
   1109  1.1  rin  **/
   1110  1.1  rin int
   1111  1.1  rin igc_set_eee_i225(struct igc_hw *hw, bool adv2p5G, bool adv1G,
   1112  1.1  rin     bool adv100M)
   1113  1.1  rin {
   1114  1.1  rin 	uint32_t ipcnfg, eeer;
   1115  1.1  rin 
   1116  1.1  rin 	DEBUGFUNC("igc_set_eee_i225");
   1117  1.1  rin 
   1118  1.1  rin 	if (hw->mac.type != igc_i225 ||
   1119  1.1  rin 	    hw->phy.media_type != igc_media_type_copper)
   1120  1.1  rin 		goto out;
   1121  1.1  rin 	ipcnfg = IGC_READ_REG(hw, IGC_IPCNFG);
   1122  1.1  rin 	eeer = IGC_READ_REG(hw, IGC_EEER);
   1123  1.1  rin 
   1124  1.1  rin 	/* enable or disable per user setting */
   1125  1.1  rin 	if (!(hw->dev_spec._i225.eee_disable)) {
   1126  1.1  rin 		uint32_t eee_su = IGC_READ_REG(hw, IGC_EEE_SU);
   1127  1.1  rin 
   1128  1.1  rin 		if (adv100M)
   1129  1.1  rin 			ipcnfg |= IGC_IPCNFG_EEE_100M_AN;
   1130  1.1  rin 		else
   1131  1.1  rin 			ipcnfg &= ~IGC_IPCNFG_EEE_100M_AN;
   1132  1.1  rin 
   1133  1.1  rin 		if (adv1G)
   1134  1.1  rin 			ipcnfg |= IGC_IPCNFG_EEE_1G_AN;
   1135  1.1  rin 		else
   1136  1.1  rin 			ipcnfg &= ~IGC_IPCNFG_EEE_1G_AN;
   1137  1.1  rin 
   1138  1.1  rin 		if (adv2p5G)
   1139  1.1  rin 			ipcnfg |= IGC_IPCNFG_EEE_2_5G_AN;
   1140  1.1  rin 		else
   1141  1.1  rin 			ipcnfg &= ~IGC_IPCNFG_EEE_2_5G_AN;
   1142  1.1  rin 
   1143  1.1  rin 		eeer |= (IGC_EEER_TX_LPI_EN | IGC_EEER_RX_LPI_EN |
   1144  1.1  rin 			IGC_EEER_LPI_FC);
   1145  1.1  rin 
   1146  1.1  rin 		/* This bit should not be set in normal operation. */
   1147  1.1  rin 		if (eee_su & IGC_EEE_SU_LPI_CLK_STP)
   1148  1.1  rin 			DEBUGOUT("LPI Clock Stop Bit should not be set!\n");
   1149  1.1  rin 	} else {
   1150  1.1  rin 		ipcnfg &= ~(IGC_IPCNFG_EEE_2_5G_AN | IGC_IPCNFG_EEE_1G_AN |
   1151  1.1  rin 			IGC_IPCNFG_EEE_100M_AN);
   1152  1.1  rin 		eeer &= ~(IGC_EEER_TX_LPI_EN | IGC_EEER_RX_LPI_EN |
   1153  1.1  rin 			IGC_EEER_LPI_FC);
   1154  1.1  rin 	}
   1155  1.1  rin 	IGC_WRITE_REG(hw, IGC_IPCNFG, ipcnfg);
   1156  1.1  rin 	IGC_WRITE_REG(hw, IGC_EEER, eeer);
   1157  1.1  rin 	IGC_READ_REG(hw, IGC_IPCNFG);
   1158  1.1  rin 	IGC_READ_REG(hw, IGC_EEER);
   1159  1.1  rin out:
   1160  1.1  rin 
   1161  1.1  rin 	return IGC_SUCCESS;
   1162  1.1  rin }
   1163