The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/em/e1000_ich8lan.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*******************************************************************************
    2 
    3   Copyright (c) 2001-2007, Intel Corporation 
    4   All rights reserved.
    5   
    6   Redistribution and use in source and binary forms, with or without 
    7   modification, are permitted provided that the following conditions are met:
    8   
    9    1. Redistributions of source code must retain the above copyright notice, 
   10       this list of conditions and the following disclaimer.
   11   
   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.
   15   
   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.
   19   
   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.
   31 
   32 *******************************************************************************/
   33 /* $FreeBSD$ */
   34 
   35 
   36 /* e1000_ich8lan
   37  * e1000_ich9lan
   38  */
   39 
   40 #include "e1000_api.h"
   41 #include "e1000_ich8lan.h"
   42 
   43 void e1000_init_function_pointers_ich8lan(struct e1000_hw *hw);
   44 
   45 STATIC s32  e1000_init_phy_params_ich8lan(struct e1000_hw *hw);
   46 STATIC s32  e1000_init_nvm_params_ich8lan(struct e1000_hw *hw);
   47 STATIC s32  e1000_init_mac_params_ich8lan(struct e1000_hw *hw);
   48 STATIC s32  e1000_acquire_swflag_ich8lan(struct e1000_hw *hw);
   49 STATIC void e1000_release_swflag_ich8lan(struct e1000_hw *hw);
   50 STATIC bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw);
   51 STATIC s32  e1000_check_polarity_ife_ich8lan(struct e1000_hw *hw);
   52 STATIC s32  e1000_check_reset_block_ich8lan(struct e1000_hw *hw);
   53 STATIC s32  e1000_phy_force_speed_duplex_ich8lan(struct e1000_hw *hw);
   54 STATIC s32  e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw);
   55 STATIC s32  e1000_get_phy_info_ich8lan(struct e1000_hw *hw);
   56 STATIC s32  e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw,
   57                                             bool active);
   58 STATIC s32  e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw,
   59                                             bool active);
   60 STATIC s32  e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset,
   61                                    u16 words, u16 *data);
   62 STATIC s32  e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset,
   63                                     u16 words, u16 *data);
   64 STATIC s32  e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw);
   65 STATIC s32  e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw);
   66 STATIC s32  e1000_valid_led_default_ich8lan(struct e1000_hw *hw,
   67                                             u16 *data);
   68 STATIC s32  e1000_get_bus_info_ich8lan(struct e1000_hw *hw);
   69 STATIC s32  e1000_reset_hw_ich8lan(struct e1000_hw *hw);
   70 STATIC s32  e1000_init_hw_ich8lan(struct e1000_hw *hw);
   71 STATIC s32  e1000_setup_link_ich8lan(struct e1000_hw *hw);
   72 STATIC s32  e1000_setup_copper_link_ich8lan(struct e1000_hw *hw);
   73 STATIC s32  e1000_get_link_up_info_ich8lan(struct e1000_hw *hw,
   74                                            u16 *speed, u16 *duplex);
   75 STATIC s32  e1000_cleanup_led_ich8lan(struct e1000_hw *hw);
   76 STATIC s32  e1000_led_on_ich8lan(struct e1000_hw *hw);
   77 STATIC s32  e1000_led_off_ich8lan(struct e1000_hw *hw);
   78 STATIC void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw);
   79 STATIC s32  e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank);
   80 static s32  e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout);
   81 static s32  e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw);
   82 static s32  e1000_get_phy_info_ife_ich8lan(struct e1000_hw *hw);
   83 static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw);
   84 static s32  e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw);
   85 static s32  e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
   86                                           u8 size, u16* data);
   87 STATIC s32  e1000_read_flash_word_ich8lan(struct e1000_hw *hw,
   88                                           u32 offset, u16 *data);
   89 static s32  e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw,
   90                                                  u32 offset, u8 byte);
   91 STATIC s32  e1000_write_flash_byte_ich8lan(struct e1000_hw *hw,
   92                                            u32 offset, u8 data);
   93 static s32  e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
   94                                            u8 size, u16 data);
   95 STATIC s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw);
   96 
   97 /* ICH GbE Flash Hardware Sequencing Flash Status Register bit breakdown */
   98 /* Offset 04h HSFSTS */
   99 union ich8_hws_flash_status {
  100         struct ich8_hsfsts {
  101                 u16 flcdone    :1; /* bit 0 Flash Cycle Done */
  102                 u16 flcerr     :1; /* bit 1 Flash Cycle Error */
  103                 u16 dael       :1; /* bit 2 Direct Access error Log */
  104                 u16 berasesz   :2; /* bit 4:3 Sector Erase Size */
  105                 u16 flcinprog  :1; /* bit 5 flash cycle in Progress */
  106                 u16 reserved1  :2; /* bit 13:6 Reserved */
  107                 u16 reserved2  :6; /* bit 13:6 Reserved */
  108                 u16 fldesvalid :1; /* bit 14 Flash Descriptor Valid */
  109                 u16 flockdn    :1; /* bit 15 Flash Config Lock-Down */
  110         } hsf_status;
  111         u16 regval;
  112 };
  113 
  114 /* ICH GbE Flash Hardware Sequencing Flash control Register bit breakdown */
  115 /* Offset 06h FLCTL */
  116 union ich8_hws_flash_ctrl {
  117         struct ich8_hsflctl {
  118                 u16 flcgo      :1;   /* 0 Flash Cycle Go */
  119                 u16 flcycle    :2;   /* 2:1 Flash Cycle */
  120                 u16 reserved   :5;   /* 7:3 Reserved  */
  121                 u16 fldbcount  :2;   /* 9:8 Flash Data Byte Count */
  122                 u16 flockdn    :6;   /* 15:10 Reserved */
  123         } hsf_ctrl;
  124         u16 regval;
  125 };
  126 
  127 /* ICH Flash Region Access Permissions */
  128 union ich8_hws_flash_regacc {
  129         struct ich8_flracc {
  130                 u32 grra      :8; /* 0:7 GbE region Read Access */
  131                 u32 grwa      :8; /* 8:15 GbE region Write Access */
  132                 u32 gmrag     :8; /* 23:16 GbE Master Read Access Grant */
  133                 u32 gmwag     :8; /* 31:24 GbE Master Write Access Grant */
  134         } hsf_flregacc;
  135         u16 regval;
  136 };
  137 
  138 struct e1000_shadow_ram {
  139         u16  value;
  140         bool modified;
  141 };
  142 
  143 struct e1000_dev_spec_ich8lan {
  144         bool kmrn_lock_loss_workaround_enabled;
  145         struct e1000_shadow_ram shadow_ram[E1000_SHADOW_RAM_WORDS];
  146 };
  147 
  148 /**
  149  *  e1000_init_phy_params_ich8lan - Initialize PHY function pointers
  150  *  @hw: pointer to the HW structure
  151  *
  152  *  Initialize family-specific PHY parameters and function pointers.
  153  **/
  154 STATIC s32 e1000_init_phy_params_ich8lan(struct e1000_hw *hw)
  155 {
  156         struct e1000_phy_info *phy = &hw->phy;
  157         struct e1000_functions *func = &hw->func;
  158         s32 ret_val = E1000_SUCCESS;
  159         u16 i = 0;
  160 
  161         DEBUGFUNC("e1000_init_phy_params_ich8lan");
  162 
  163         phy->addr                       = 1;
  164         phy->reset_delay_us             = 100;
  165 
  166         func->acquire_phy               = e1000_acquire_swflag_ich8lan;
  167         func->check_polarity            = e1000_check_polarity_ife_ich8lan;
  168         func->check_reset_block         = e1000_check_reset_block_ich8lan;
  169         func->force_speed_duplex        = e1000_phy_force_speed_duplex_ich8lan;
  170         func->get_cable_length          = e1000_get_cable_length_igp_2;
  171         func->get_cfg_done              = e1000_get_cfg_done_ich8lan;
  172         func->get_phy_info              = e1000_get_phy_info_ich8lan;
  173         func->read_phy_reg              = e1000_read_phy_reg_igp;
  174         func->release_phy               = e1000_release_swflag_ich8lan;
  175         func->reset_phy                 = e1000_phy_hw_reset_ich8lan;
  176         func->set_d0_lplu_state         = e1000_set_d0_lplu_state_ich8lan;
  177         func->set_d3_lplu_state         = e1000_set_d3_lplu_state_ich8lan;
  178         func->write_phy_reg             = e1000_write_phy_reg_igp;
  179 
  180 
  181         phy->id = 0;
  182         while ((e1000_phy_unknown == e1000_get_phy_type_from_id(phy->id)) &&
  183                (i++ < 100)) {
  184                 msec_delay(1);
  185                 ret_val = e1000_get_phy_id(hw);
  186                 if (ret_val)
  187                         goto out;
  188         }
  189 
  190         /* Verify phy id */
  191         switch (phy->id) {
  192         case IGP03E1000_E_PHY_ID:
  193                 phy->type = e1000_phy_igp_3;
  194                 phy->autoneg_mask = AUTONEG_ADVERTISE_SPEED_DEFAULT;
  195                 break;
  196         case IFE_E_PHY_ID:
  197         case IFE_PLUS_E_PHY_ID:
  198         case IFE_C_E_PHY_ID:
  199                 phy->type = e1000_phy_ife;
  200                 phy->autoneg_mask = E1000_ALL_NOT_GIG;
  201                 break;
  202         default:
  203                 ret_val = -E1000_ERR_PHY;
  204                 goto out;
  205         }
  206 
  207 out:
  208         return ret_val;
  209 }
  210 
  211 /**
  212  *  e1000_init_nvm_params_ich8lan - Initialize NVM function pointers
  213  *  @hw: pointer to the HW structure
  214  *
  215  *  Initialize family-specific NVM parameters and function
  216  *  pointers.
  217  **/
  218 STATIC s32 e1000_init_nvm_params_ich8lan(struct e1000_hw *hw)
  219 {
  220         struct e1000_nvm_info *nvm = &hw->nvm;
  221         struct e1000_functions *func = &hw->func;
  222         struct e1000_dev_spec_ich8lan *dev_spec;
  223         u32 gfpreg, sector_base_addr, sector_end_addr;
  224         s32 ret_val = E1000_SUCCESS;
  225         u16 i;
  226 
  227         DEBUGFUNC("e1000_init_nvm_params_ich8lan");
  228 
  229         /* Can't read flash registers if the register set isn't mapped. */
  230         if (!hw->flash_address) {
  231                 DEBUGOUT("ERROR: Flash registers not mapped\n");
  232                 ret_val = -E1000_ERR_CONFIG;
  233                 goto out;
  234         }
  235 
  236         nvm->type               = e1000_nvm_flash_sw;
  237 
  238         gfpreg = E1000_READ_FLASH_REG(hw, ICH_FLASH_GFPREG);
  239 
  240         /*
  241          * sector_X_addr is a "sector"-aligned address (4096 bytes)
  242          * Add 1 to sector_end_addr since this sector is included in
  243          * the overall size.
  244          */
  245         sector_base_addr = gfpreg & FLASH_GFPREG_BASE_MASK;
  246         sector_end_addr = ((gfpreg >> 16) & FLASH_GFPREG_BASE_MASK) + 1;
  247 
  248         /* flash_base_addr is byte-aligned */
  249         nvm->flash_base_addr    = sector_base_addr << FLASH_SECTOR_ADDR_SHIFT;
  250 
  251         /*
  252          * find total size of the NVM, then cut in half since the total
  253          * size represents two separate NVM banks.
  254          */
  255         nvm->flash_bank_size    = (sector_end_addr - sector_base_addr)
  256                                   << FLASH_SECTOR_ADDR_SHIFT;
  257         nvm->flash_bank_size    /= 2;
  258         /* Adjust to word count */
  259         nvm->flash_bank_size    /= sizeof(u16);
  260 
  261         nvm->word_size          = E1000_SHADOW_RAM_WORDS;
  262 
  263         dev_spec = (struct e1000_dev_spec_ich8lan *)hw->dev_spec;
  264 
  265         if (!dev_spec) {
  266                 DEBUGOUT("dev_spec pointer is set to NULL.\n");
  267                 ret_val = -E1000_ERR_CONFIG;
  268                 goto out;
  269         }
  270 
  271         /* Clear shadow ram */
  272         for (i = 0; i < nvm->word_size; i++) {
  273                 dev_spec->shadow_ram[i].modified = FALSE;
  274                 dev_spec->shadow_ram[i].value    = 0xFFFF;
  275         }
  276 
  277         /* Function Pointers */
  278         func->acquire_nvm       = e1000_acquire_swflag_ich8lan;
  279         func->read_nvm          = e1000_read_nvm_ich8lan;
  280         func->release_nvm       = e1000_release_swflag_ich8lan;
  281         func->update_nvm        = e1000_update_nvm_checksum_ich8lan;
  282         func->valid_led_default = e1000_valid_led_default_ich8lan;
  283         func->validate_nvm      = e1000_validate_nvm_checksum_ich8lan;
  284         func->write_nvm         = e1000_write_nvm_ich8lan;
  285 
  286 out:
  287         return ret_val;
  288 }
  289 
  290 /**
  291  *  e1000_init_mac_params_ich8lan - Initialize MAC function pointers
  292  *  @hw: pointer to the HW structure
  293  *
  294  *  Initialize family-specific MAC parameters and function
  295  *  pointers.
  296  **/
  297 STATIC s32 e1000_init_mac_params_ich8lan(struct e1000_hw *hw)
  298 {
  299         struct e1000_mac_info *mac = &hw->mac;
  300         struct e1000_functions *func = &hw->func;
  301         s32 ret_val = E1000_SUCCESS;
  302 
  303         DEBUGFUNC("e1000_init_mac_params_ich8lan");
  304 
  305         /* Set media type function pointer */
  306         hw->phy.media_type = e1000_media_type_copper;
  307 
  308         /* Set mta register count */
  309         mac->mta_reg_count = 32;
  310         /* Set rar entry count */
  311         mac->rar_entry_count = E1000_ICH_RAR_ENTRIES;
  312         if (mac->type == e1000_ich8lan)
  313                 mac->rar_entry_count--;
  314         /* Set if part includes ASF firmware */
  315         mac->asf_firmware_present = TRUE;
  316         /* Set if manageability features are enabled. */
  317         mac->arc_subsystem_valid = TRUE;
  318 
  319         /* Function pointers */
  320 
  321         /* bus type/speed/width */
  322         func->get_bus_info = e1000_get_bus_info_ich8lan;
  323         /* reset */
  324         func->reset_hw = e1000_reset_hw_ich8lan;
  325         /* hw initialization */
  326         func->init_hw = e1000_init_hw_ich8lan;
  327         /* link setup */
  328         func->setup_link = e1000_setup_link_ich8lan;
  329         /* physical interface setup */
  330         func->setup_physical_interface = e1000_setup_copper_link_ich8lan;
  331         /* check for link */
  332         func->check_for_link = e1000_check_for_copper_link_generic;
  333         /* check management mode */
  334         func->check_mng_mode = e1000_check_mng_mode_ich8lan;
  335         /* link info */
  336         func->get_link_up_info = e1000_get_link_up_info_ich8lan;
  337         /* multicast address update */
  338         func->update_mc_addr_list = e1000_update_mc_addr_list_generic;
  339         /* setting MTA */
  340         func->mta_set = e1000_mta_set_generic;
  341         /* blink LED */
  342         func->blink_led = e1000_blink_led_generic;
  343         /* setup LED */
  344         func->setup_led = e1000_setup_led_generic;
  345         /* cleanup LED */
  346         func->cleanup_led = e1000_cleanup_led_ich8lan;
  347         /* turn on/off LED */
  348         func->led_on = e1000_led_on_ich8lan;
  349         func->led_off = e1000_led_off_ich8lan;
  350         /* remove device */
  351         func->remove_device = e1000_remove_device_generic;
  352         /* clear hardware counters */
  353         func->clear_hw_cntrs = e1000_clear_hw_cntrs_ich8lan;
  354 
  355         hw->dev_spec_size = sizeof(struct e1000_dev_spec_ich8lan);
  356 
  357         /* Device-specific structure allocation */
  358         ret_val = e1000_alloc_zeroed_dev_spec_struct(hw, hw->dev_spec_size);
  359         if (ret_val)
  360                 goto out;
  361 
  362         /* Enable PCS Lock-loss workaround for ICH8 */
  363         if (mac->type == e1000_ich8lan)
  364                 e1000_set_kmrn_lock_loss_workaround_ich8lan(hw, TRUE);
  365 
  366 
  367 out:
  368         return ret_val;
  369 }
  370 
  371 /**
  372  *  e1000_init_function_pointers_ich8lan - Initialize ICH8 function pointers
  373  *  @hw: pointer to the HW structure
  374  *
  375  *  Initialize family-specific function pointers for PHY, MAC, and NVM.
  376  **/
  377 void e1000_init_function_pointers_ich8lan(struct e1000_hw *hw)
  378 {
  379         DEBUGFUNC("e1000_init_function_pointers_ich8lan");
  380 
  381         hw->func.init_mac_params = e1000_init_mac_params_ich8lan;
  382         hw->func.init_nvm_params = e1000_init_nvm_params_ich8lan;
  383         hw->func.init_phy_params = e1000_init_phy_params_ich8lan;
  384 }
  385 
  386 /**
  387  *  e1000_acquire_swflag_ich8lan - Acquire software control flag
  388  *  @hw: pointer to the HW structure
  389  *
  390  *  Acquires the software control flag for performing NVM and PHY
  391  *  operations.  This is a function pointer entry point only called by
  392  *  read/write routines for the PHY and NVM parts.
  393  **/
  394 STATIC s32 e1000_acquire_swflag_ich8lan(struct e1000_hw *hw)
  395 {
  396         u32 extcnf_ctrl, timeout = PHY_CFG_TIMEOUT;
  397         s32 ret_val = E1000_SUCCESS;
  398 
  399         DEBUGFUNC("e1000_acquire_swflag_ich8lan");
  400 
  401         while (timeout) {
  402                 extcnf_ctrl = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
  403                 extcnf_ctrl |= E1000_EXTCNF_CTRL_SWFLAG;
  404                 E1000_WRITE_REG(hw, E1000_EXTCNF_CTRL, extcnf_ctrl);
  405 
  406                 extcnf_ctrl = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
  407                 if (extcnf_ctrl & E1000_EXTCNF_CTRL_SWFLAG)
  408                         break;
  409                 msec_delay_irq(1);
  410                 timeout--;
  411         }
  412 
  413         if (!timeout) {
  414                 DEBUGOUT("FW or HW has locked the resource for too long.\n");
  415                 extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
  416                 E1000_WRITE_REG(hw, E1000_EXTCNF_CTRL, extcnf_ctrl);
  417                 ret_val = -E1000_ERR_CONFIG;
  418                 goto out;
  419         }
  420 
  421 out:
  422         return ret_val;
  423 }
  424 
  425 /**
  426  *  e1000_release_swflag_ich8lan - Release software control flag
  427  *  @hw: pointer to the HW structure
  428  *
  429  *  Releases the software control flag for performing NVM and PHY operations.
  430  *  This is a function pointer entry point only called by read/write
  431  *  routines for the PHY and NVM parts.
  432  **/
  433 STATIC void e1000_release_swflag_ich8lan(struct e1000_hw *hw)
  434 {
  435         u32 extcnf_ctrl;
  436 
  437         DEBUGFUNC("e1000_release_swflag_ich8lan");
  438 
  439         extcnf_ctrl = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
  440         extcnf_ctrl &= ~E1000_EXTCNF_CTRL_SWFLAG;
  441         E1000_WRITE_REG(hw, E1000_EXTCNF_CTRL, extcnf_ctrl);
  442 
  443         return;
  444 }
  445 
  446 /**
  447  *  e1000_check_mng_mode_ich8lan - Checks management mode
  448  *  @hw: pointer to the HW structure
  449  *
  450  *  This checks if the adapter has manageability enabled.
  451  *  This is a function pointer entry point only called by read/write
  452  *  routines for the PHY and NVM parts.
  453  **/
  454 STATIC bool e1000_check_mng_mode_ich8lan(struct e1000_hw *hw)
  455 {
  456         u32 fwsm;
  457 
  458         DEBUGFUNC("e1000_check_mng_mode_ich8lan");
  459 
  460         fwsm = E1000_READ_REG(hw, E1000_FWSM);
  461 
  462         return ((fwsm & E1000_FWSM_MODE_MASK) ==
  463                 (E1000_ICH_MNG_IAMT_MODE << E1000_FWSM_MODE_SHIFT));
  464 }
  465 
  466 /**
  467  *  e1000_check_reset_block_ich8lan - Check if PHY reset is blocked
  468  *  @hw: pointer to the HW structure
  469  *
  470  *  Checks if firmware is blocking the reset of the PHY.
  471  *  This is a function pointer entry point only called by
  472  *  reset routines.
  473  **/
  474 STATIC s32 e1000_check_reset_block_ich8lan(struct e1000_hw *hw)
  475 {
  476         u32 fwsm;
  477 
  478         DEBUGFUNC("e1000_check_reset_block_ich8lan");
  479 
  480         fwsm = E1000_READ_REG(hw, E1000_FWSM);
  481 
  482         return (fwsm & E1000_ICH_FWSM_RSPCIPHY) ? E1000_SUCCESS
  483                                                 : E1000_BLK_PHY_RESET;
  484 }
  485 
  486 /**
  487  *  e1000_phy_force_speed_duplex_ich8lan - Force PHY speed & duplex
  488  *  @hw: pointer to the HW structure
  489  *
  490  *  Forces the speed and duplex settings of the PHY.
  491  *  This is a function pointer entry point only called by
  492  *  PHY setup routines.
  493  **/
  494 STATIC s32 e1000_phy_force_speed_duplex_ich8lan(struct e1000_hw *hw)
  495 {
  496         struct e1000_phy_info *phy = &hw->phy;
  497         s32 ret_val;
  498         u16 data;
  499         bool link;
  500 
  501         DEBUGFUNC("e1000_phy_force_speed_duplex_ich8lan");
  502 
  503         if (phy->type != e1000_phy_ife) {
  504                 ret_val = e1000_phy_force_speed_duplex_igp(hw);
  505                 goto out;
  506         }
  507 
  508         ret_val = e1000_read_phy_reg(hw, PHY_CONTROL, &data);
  509         if (ret_val)
  510                 goto out;
  511 
  512         e1000_phy_force_speed_duplex_setup(hw, &data);
  513 
  514         ret_val = e1000_write_phy_reg(hw, PHY_CONTROL, data);
  515         if (ret_val)
  516                 goto out;
  517 
  518         /* Disable MDI-X support for 10/100 */
  519         ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &data);
  520         if (ret_val)
  521                 goto out;
  522 
  523         data &= ~IFE_PMC_AUTO_MDIX;
  524         data &= ~IFE_PMC_FORCE_MDIX;
  525 
  526         ret_val = e1000_write_phy_reg(hw, IFE_PHY_MDIX_CONTROL, data);
  527         if (ret_val)
  528                 goto out;
  529 
  530         DEBUGOUT1("IFE PMC: %X\n", data);
  531 
  532         usec_delay(1);
  533 
  534         if (phy->autoneg_wait_to_complete) {
  535                 DEBUGOUT("Waiting for forced speed/duplex link on IFE phy.\n");
  536 
  537                 ret_val = e1000_phy_has_link_generic(hw,
  538                                                      PHY_FORCE_LIMIT,
  539                                                      100000,
  540                                                      &link);
  541                 if (ret_val)
  542                         goto out;
  543 
  544                 if (!link) {
  545                         DEBUGOUT("Link taking longer than expected.\n");
  546                 }
  547 
  548                 /* Try once more */
  549                 ret_val = e1000_phy_has_link_generic(hw,
  550                                                      PHY_FORCE_LIMIT,
  551                                                      100000,
  552                                                      &link);
  553                 if (ret_val)
  554                         goto out;
  555         }
  556 
  557 out:
  558         return ret_val;
  559 }
  560 
  561 /**
  562  *  e1000_phy_hw_reset_ich8lan - Performs a PHY reset
  563  *  @hw: pointer to the HW structure
  564  *
  565  *  Resets the PHY
  566  *  This is a function pointer entry point called by drivers
  567  *  or other shared routines.
  568  **/
  569 STATIC s32 e1000_phy_hw_reset_ich8lan(struct e1000_hw *hw)
  570 {
  571         struct e1000_phy_info *phy = &hw->phy;
  572         u32 i, data, cnf_size, cnf_base_addr, sw_cfg_mask;
  573         s32 ret_val;
  574         u16 loop = E1000_ICH8_LAN_INIT_TIMEOUT;
  575         u16 word_addr, reg_data, reg_addr, phy_page = 0;
  576 
  577         DEBUGFUNC("e1000_phy_hw_reset_ich8lan");
  578 
  579         ret_val = e1000_phy_hw_reset_generic(hw);
  580         if (ret_val)
  581                 goto out;
  582 
  583         /*
  584          * Initialize the PHY from the NVM on ICH platforms.  This
  585          * is needed due to an issue where the NVM configuration is
  586          * not properly autoloaded after power transitions.
  587          * Therefore, after each PHY reset, we will load the
  588          * configuration data out of the NVM manually.
  589          */
  590         if (hw->mac.type == e1000_ich8lan && phy->type == e1000_phy_igp_3) {
  591                 /* Check if SW needs configure the PHY */
  592                 if ((hw->device_id == E1000_DEV_ID_ICH8_IGP_M_AMT) ||
  593                     (hw->device_id == E1000_DEV_ID_ICH8_IGP_M))
  594                         sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG_ICH8M;
  595                 else
  596                         sw_cfg_mask = E1000_FEXTNVM_SW_CONFIG;
  597 
  598                 data = E1000_READ_REG(hw, E1000_FEXTNVM);
  599                 if (!(data & sw_cfg_mask))
  600                         goto out;
  601 
  602                 /* Wait for basic configuration completes before proceeding*/
  603                 do {
  604                         data = E1000_READ_REG(hw, E1000_STATUS);
  605                         data &= E1000_STATUS_LAN_INIT_DONE;
  606                         usec_delay(100);
  607                 } while ((!data) && --loop);
  608 
  609                 /*
  610                  * If basic configuration is incomplete before the above loop
  611                  * count reaches 0, loading the configuration from NVM will
  612                  * leave the PHY in a bad state possibly resulting in no link.
  613                  */
  614                 if (loop == 0) {
  615                         DEBUGOUT("LAN_INIT_DONE not set, increase timeout\n");
  616                 }
  617 
  618                 /* Clear the Init Done bit for the next init event */
  619                 data = E1000_READ_REG(hw, E1000_STATUS);
  620                 data &= ~E1000_STATUS_LAN_INIT_DONE;
  621                 E1000_WRITE_REG(hw, E1000_STATUS, data);
  622 
  623                 /*
  624                  * Make sure HW does not configure LCD from PHY
  625                  * extended configuration before SW configuration
  626                  */
  627                 data = E1000_READ_REG(hw, E1000_EXTCNF_CTRL);
  628                 if (data & E1000_EXTCNF_CTRL_LCD_WRITE_ENABLE)
  629                         goto out;
  630 
  631                 cnf_size = E1000_READ_REG(hw, E1000_EXTCNF_SIZE);
  632                 cnf_size &= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_MASK;
  633                 cnf_size >>= E1000_EXTCNF_SIZE_EXT_PCIE_LENGTH_SHIFT;
  634                 if (!cnf_size)
  635                         goto out;
  636 
  637                 cnf_base_addr = data & E1000_EXTCNF_CTRL_EXT_CNF_POINTER_MASK;
  638                 cnf_base_addr >>= E1000_EXTCNF_CTRL_EXT_CNF_POINTER_SHIFT;
  639 
  640                 /*
  641                  * Configure LCD from extended configuration
  642                  * region.
  643                  */
  644 
  645                 /* cnf_base_addr is in DWORD */
  646                 word_addr = (u16)(cnf_base_addr << 1);
  647 
  648                 for (i = 0; i < cnf_size; i++) {
  649                         ret_val = e1000_read_nvm(hw,
  650                                                 (word_addr + i * 2),
  651                                                 1,
  652                                                 &reg_data);
  653                         if (ret_val)
  654                                 goto out;
  655 
  656                         ret_val = e1000_read_nvm(hw,
  657                                                 (word_addr + i * 2 + 1),
  658                                                 1,
  659                                                 &reg_addr);
  660                         if (ret_val)
  661                                 goto out;
  662 
  663                         /* Save off the PHY page for future writes. */
  664                         if (reg_addr == IGP01E1000_PHY_PAGE_SELECT) {
  665                                 phy_page = reg_data;
  666                                 continue;
  667                         }
  668 
  669                         reg_addr |= phy_page;
  670 
  671                         ret_val = e1000_write_phy_reg(hw,
  672                                                      (u32)reg_addr,
  673                                                      reg_data);
  674                         if (ret_val)
  675                                 goto out;
  676                 }
  677         }
  678 
  679 out:
  680         return ret_val;
  681 }
  682 
  683 /**
  684  *  e1000_get_phy_info_ich8lan - Calls appropriate PHY type get_phy_info
  685  *  @hw: pointer to the HW structure
  686  *
  687  *  Wrapper for calling the get_phy_info routines for the appropriate phy type.
  688  *  This is a function pointer entry point called by drivers
  689  *  or other shared routines.
  690  **/
  691 STATIC s32 e1000_get_phy_info_ich8lan(struct e1000_hw *hw)
  692 {
  693         s32 ret_val = -E1000_ERR_PHY_TYPE;
  694 
  695         DEBUGFUNC("e1000_get_phy_info_ich8lan");
  696 
  697         switch (hw->phy.type) {
  698         case e1000_phy_ife:
  699                 ret_val = e1000_get_phy_info_ife_ich8lan(hw);
  700                 break;
  701         case e1000_phy_igp_3:
  702                 ret_val = e1000_get_phy_info_igp(hw);
  703                 break;
  704         default:
  705                 break;
  706         }
  707 
  708         return ret_val;
  709 }
  710 
  711 /**
  712  *  e1000_get_phy_info_ife_ich8lan - Retrieves various IFE PHY states
  713  *  @hw: pointer to the HW structure
  714  *
  715  *  Populates "phy" structure with various feature states.
  716  *  This function is only called by other family-specific
  717  *  routines.
  718  **/
  719 static s32 e1000_get_phy_info_ife_ich8lan(struct e1000_hw *hw)
  720 {
  721         struct e1000_phy_info *phy = &hw->phy;
  722         s32 ret_val;
  723         u16 data;
  724         bool link;
  725 
  726         DEBUGFUNC("e1000_get_phy_info_ife_ich8lan");
  727 
  728         ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
  729         if (ret_val)
  730                 goto out;
  731 
  732         if (!link) {
  733                 DEBUGOUT("Phy info is only valid if link is up\n");
  734                 ret_val = -E1000_ERR_CONFIG;
  735                 goto out;
  736         }
  737 
  738         ret_val = e1000_read_phy_reg(hw, IFE_PHY_SPECIAL_CONTROL, &data);
  739         if (ret_val)
  740                 goto out;
  741         phy->polarity_correction = (data & IFE_PSC_AUTO_POLARITY_DISABLE)
  742                                    ? FALSE : TRUE;
  743 
  744         if (phy->polarity_correction) {
  745                 ret_val = e1000_check_polarity_ife_ich8lan(hw);
  746                 if (ret_val)
  747                         goto out;
  748         } else {
  749                 /* Polarity is forced */
  750                 phy->cable_polarity = (data & IFE_PSC_FORCE_POLARITY)
  751                                       ? e1000_rev_polarity_reversed
  752                                       : e1000_rev_polarity_normal;
  753         }
  754 
  755         ret_val = e1000_read_phy_reg(hw, IFE_PHY_MDIX_CONTROL, &data);
  756         if (ret_val)
  757                 goto out;
  758 
  759         phy->is_mdix = (data & IFE_PMC_MDIX_STATUS) ? TRUE : FALSE;
  760 
  761         /* The following parameters are undefined for 10/100 operation. */
  762         phy->cable_length = E1000_CABLE_LENGTH_UNDEFINED;
  763         phy->local_rx = e1000_1000t_rx_status_undefined;
  764         phy->remote_rx = e1000_1000t_rx_status_undefined;
  765 
  766 out:
  767         return ret_val;
  768 }
  769 
  770 /**
  771  *  e1000_check_polarity_ife_ich8lan - Check cable polarity for IFE PHY
  772  *  @hw: pointer to the HW structure
  773  *
  774  *  Polarity is determined on the polarity reveral feature being enabled.
  775  *  This function is only called by other family-specific
  776  *  routines.
  777  **/
  778 STATIC s32 e1000_check_polarity_ife_ich8lan(struct e1000_hw *hw)
  779 {
  780         struct e1000_phy_info *phy = &hw->phy;
  781         s32 ret_val;
  782         u16 phy_data, offset, mask;
  783 
  784         DEBUGFUNC("e1000_check_polarity_ife_ich8lan");
  785 
  786         /*
  787          * Polarity is determined based on the reversal feature
  788          * being enabled.
  789          */
  790         if (phy->polarity_correction) {
  791                 offset  = IFE_PHY_EXTENDED_STATUS_CONTROL;
  792                 mask    = IFE_PESC_POLARITY_REVERSED;
  793         } else {
  794                 offset  = IFE_PHY_SPECIAL_CONTROL;
  795                 mask    = IFE_PSC_FORCE_POLARITY;
  796         }
  797 
  798         ret_val = e1000_read_phy_reg(hw, offset, &phy_data);
  799 
  800         if (!ret_val)
  801                 phy->cable_polarity = (phy_data & mask)
  802                                       ? e1000_rev_polarity_reversed
  803                                       : e1000_rev_polarity_normal;
  804 
  805         return ret_val;
  806 }
  807 
  808 /**
  809  *  e1000_set_d0_lplu_state_ich8lan - Set Low Power Linkup D0 state
  810  *  @hw: pointer to the HW structure
  811  *  @active: TRUE to enable LPLU, FALSE to disable
  812  *
  813  *  Sets the LPLU D0 state according to the active flag.  When
  814  *  activating LPLU this function also disables smart speed
  815  *  and vice versa.  LPLU will not be activated unless the
  816  *  device autonegotiation advertisement meets standards of
  817  *  either 10 or 10/100 or 10/100/1000 at all duplexes.
  818  *  This is a function pointer entry point only called by
  819  *  PHY setup routines.
  820  **/
  821 STATIC s32 e1000_set_d0_lplu_state_ich8lan(struct e1000_hw *hw,
  822                                            bool active)
  823 {
  824         struct e1000_phy_info *phy = &hw->phy;
  825         u32 phy_ctrl;
  826         s32 ret_val = E1000_SUCCESS;
  827         u16 data;
  828 
  829         DEBUGFUNC("e1000_set_d0_lplu_state_ich8lan");
  830 
  831         if (phy->type == e1000_phy_ife)
  832                 goto out;
  833 
  834         phy_ctrl = E1000_READ_REG(hw, E1000_PHY_CTRL);
  835 
  836         if (active) {
  837                 phy_ctrl |= E1000_PHY_CTRL_D0A_LPLU;
  838                 E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
  839 
  840                 /*
  841                  * Call gig speed drop workaround on LPLU before accessing
  842                  * any PHY registers
  843                  */
  844                 if ((hw->mac.type == e1000_ich8lan) &&
  845                     (hw->phy.type == e1000_phy_igp_3))
  846                         e1000_gig_downshift_workaround_ich8lan(hw);
  847 
  848                 /* When LPLU is enabled, we should disable SmartSpeed */
  849                 ret_val = e1000_read_phy_reg(hw,
  850                                             IGP01E1000_PHY_PORT_CONFIG,
  851                                             &data);
  852                 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  853                 ret_val = e1000_write_phy_reg(hw,
  854                                              IGP01E1000_PHY_PORT_CONFIG,
  855                                              data);
  856                 if (ret_val)
  857                         goto out;
  858         } else {
  859                 phy_ctrl &= ~E1000_PHY_CTRL_D0A_LPLU;
  860                 E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
  861 
  862                 /*
  863                  * LPLU and SmartSpeed are mutually exclusive.  LPLU is used
  864                  * during Dx states where the power conservation is most
  865                  * important.  During driver activity we should enable
  866                  * SmartSpeed, so performance is maintained.
  867                  */
  868                 if (phy->smart_speed == e1000_smart_speed_on) {
  869                         ret_val = e1000_read_phy_reg(hw,
  870                                                     IGP01E1000_PHY_PORT_CONFIG,
  871                                                     &data);
  872                         if (ret_val)
  873                                 goto out;
  874 
  875                         data |= IGP01E1000_PSCFR_SMART_SPEED;
  876                         ret_val = e1000_write_phy_reg(hw,
  877                                                      IGP01E1000_PHY_PORT_CONFIG,
  878                                                      data);
  879                         if (ret_val)
  880                                 goto out;
  881                 } else if (phy->smart_speed == e1000_smart_speed_off) {
  882                         ret_val = e1000_read_phy_reg(hw,
  883                                                     IGP01E1000_PHY_PORT_CONFIG,
  884                                                     &data);
  885                         if (ret_val)
  886                                 goto out;
  887 
  888                         data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  889                         ret_val = e1000_write_phy_reg(hw,
  890                                                      IGP01E1000_PHY_PORT_CONFIG,
  891                                                      data);
  892                         if (ret_val)
  893                                 goto out;
  894                 }
  895         }
  896 
  897 out:
  898         return ret_val;
  899 }
  900 
  901 /**
  902  *  e1000_set_d3_lplu_state_ich8lan - Set Low Power Linkup D3 state
  903  *  @hw: pointer to the HW structure
  904  *  @active: TRUE to enable LPLU, FALSE to disable
  905  *
  906  *  Sets the LPLU D3 state according to the active flag.  When
  907  *  activating LPLU this function also disables smart speed
  908  *  and vice versa.  LPLU will not be activated unless the
  909  *  device autonegotiation advertisement meets standards of
  910  *  either 10 or 10/100 or 10/100/1000 at all duplexes.
  911  *  This is a function pointer entry point only called by
  912  *  PHY setup routines.
  913  **/
  914 STATIC s32 e1000_set_d3_lplu_state_ich8lan(struct e1000_hw *hw,
  915                                            bool active)
  916 {
  917         struct e1000_phy_info *phy = &hw->phy;
  918         u32 phy_ctrl;
  919         s32 ret_val = E1000_SUCCESS;
  920         u16 data;
  921 
  922         DEBUGFUNC("e1000_set_d3_lplu_state_ich8lan");
  923 
  924         phy_ctrl = E1000_READ_REG(hw, E1000_PHY_CTRL);
  925 
  926         if (!active) {
  927                 phy_ctrl &= ~E1000_PHY_CTRL_NOND0A_LPLU;
  928                 E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
  929                 /*
  930                  * LPLU and SmartSpeed are mutually exclusive.  LPLU is used
  931                  * during Dx states where the power conservation is most
  932                  * important.  During driver activity we should enable
  933                  * SmartSpeed, so performance is maintained.
  934                  */
  935                 if (phy->smart_speed == e1000_smart_speed_on) {
  936                         ret_val = e1000_read_phy_reg(hw,
  937                                                     IGP01E1000_PHY_PORT_CONFIG,
  938                                                     &data);
  939                         if (ret_val)
  940                                 goto out;
  941 
  942                         data |= IGP01E1000_PSCFR_SMART_SPEED;
  943                         ret_val = e1000_write_phy_reg(hw,
  944                                                      IGP01E1000_PHY_PORT_CONFIG,
  945                                                      data);
  946                         if (ret_val)
  947                                 goto out;
  948                 } else if (phy->smart_speed == e1000_smart_speed_off) {
  949                         ret_val = e1000_read_phy_reg(hw,
  950                                                     IGP01E1000_PHY_PORT_CONFIG,
  951                                                     &data);
  952                         if (ret_val)
  953                                 goto out;
  954 
  955                         data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  956                         ret_val = e1000_write_phy_reg(hw,
  957                                                      IGP01E1000_PHY_PORT_CONFIG,
  958                                                      data);
  959                         if (ret_val)
  960                                 goto out;
  961                 }
  962         } else if ((phy->autoneg_advertised == E1000_ALL_SPEED_DUPLEX) ||
  963                    (phy->autoneg_advertised == E1000_ALL_NOT_GIG) ||
  964                    (phy->autoneg_advertised == E1000_ALL_10_SPEED)) {
  965                 phy_ctrl |= E1000_PHY_CTRL_NOND0A_LPLU;
  966                 E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
  967 
  968                 /*
  969                  * Call gig speed drop workaround on LPLU before accessing
  970                  * any PHY registers
  971                  */
  972                 if ((hw->mac.type == e1000_ich8lan) &&
  973                     (hw->phy.type == e1000_phy_igp_3))
  974                         e1000_gig_downshift_workaround_ich8lan(hw);
  975 
  976                 /* When LPLU is enabled, we should disable SmartSpeed */
  977                 ret_val = e1000_read_phy_reg(hw,
  978                                             IGP01E1000_PHY_PORT_CONFIG,
  979                                             &data);
  980                 if (ret_val)
  981                         goto out;
  982 
  983                 data &= ~IGP01E1000_PSCFR_SMART_SPEED;
  984                 ret_val = e1000_write_phy_reg(hw,
  985                                              IGP01E1000_PHY_PORT_CONFIG,
  986                                              data);
  987         }
  988 
  989 out:
  990         return ret_val;
  991 }
  992 
  993 /**
  994  *  e1000_read_nvm_ich8lan - Read word(s) from the NVM
  995  *  @hw: pointer to the HW structure
  996  *  @offset: The offset (in bytes) of the word(s) to read.
  997  *  @words: Size of data to read in words
  998  *  @data: Pointer to the word(s) to read at offset.
  999  *
 1000  *  Reads a word(s) from the NVM using the flash access registers.
 1001  **/
 1002 STATIC s32 e1000_read_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
 1003                                   u16 *data)
 1004 {
 1005         struct e1000_nvm_info *nvm = &hw->nvm;
 1006         struct e1000_dev_spec_ich8lan *dev_spec;
 1007         u32 act_offset;
 1008         s32 ret_val = E1000_SUCCESS;
 1009         u16 i, word;
 1010 
 1011         DEBUGFUNC("e1000_read_nvm_ich8lan");
 1012 
 1013         dev_spec = (struct e1000_dev_spec_ich8lan *)hw->dev_spec;
 1014 
 1015         if (!dev_spec) {
 1016                 DEBUGOUT("dev_spec pointer is set to NULL.\n");
 1017                 ret_val = -E1000_ERR_CONFIG;
 1018                 goto out;
 1019         }
 1020 
 1021         if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
 1022             (words == 0)) {
 1023                 DEBUGOUT("nvm parameter(s) out of bounds\n");
 1024                 ret_val = -E1000_ERR_NVM;
 1025                 goto out;
 1026         }
 1027 
 1028         ret_val = e1000_acquire_nvm(hw);
 1029         if (ret_val)
 1030                 goto out;
 1031 
 1032         /* Start with the bank offset, then add the relative offset. */
 1033         act_offset = (E1000_READ_REG(hw, E1000_EECD) & E1000_EECD_SEC1VAL)
 1034                      ? nvm->flash_bank_size
 1035                      : 0;
 1036         act_offset += offset;
 1037 
 1038         for (i = 0; i < words; i++) {
 1039                 if ((dev_spec->shadow_ram) &&
 1040                     (dev_spec->shadow_ram[offset+i].modified)) {
 1041                         data[i] = dev_spec->shadow_ram[offset+i].value;
 1042                 } else {
 1043                         ret_val = e1000_read_flash_word_ich8lan(hw,
 1044                                                                 act_offset + i,
 1045                                                                 &word);
 1046                         if (ret_val)
 1047                                 break;
 1048                         data[i] = word;
 1049                 }
 1050         }
 1051 
 1052         e1000_release_nvm(hw);
 1053 
 1054 out:
 1055         return ret_val;
 1056 }
 1057 
 1058 /**
 1059  *  e1000_flash_cycle_init_ich8lan - Initialize flash
 1060  *  @hw: pointer to the HW structure
 1061  *
 1062  *  This function does initial flash setup so that a new read/write/erase cycle
 1063  *  can be started.
 1064  **/
 1065 static s32 e1000_flash_cycle_init_ich8lan(struct e1000_hw *hw)
 1066 {
 1067         union ich8_hws_flash_status hsfsts;
 1068         s32 ret_val = -E1000_ERR_NVM;
 1069         s32 i = 0;
 1070 
 1071         DEBUGFUNC("e1000_flash_cycle_init_ich8lan");
 1072 
 1073         hsfsts.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
 1074 
 1075         /* Check if the flash descriptor is valid */
 1076         if (hsfsts.hsf_status.fldesvalid == 0) {
 1077                 DEBUGOUT("Flash descriptor invalid.  "
 1078                          "SW Sequencing must be used.");
 1079                 goto out;
 1080         }
 1081 
 1082         /* Clear FCERR and DAEL in hw status by writing 1 */
 1083         hsfsts.hsf_status.flcerr = 1;
 1084         hsfsts.hsf_status.dael = 1;
 1085 
 1086         E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
 1087 
 1088         /*
 1089          * Either we should have a hardware SPI cycle in progress
 1090          * bit to check against, in order to start a new cycle or
 1091          * FDONE bit should be changed in the hardware so that it
 1092          * is 1 after harware reset, which can then be used as an
 1093          * indication whether a cycle is in progress or has been
 1094          * completed.
 1095          */
 1096 
 1097         if (hsfsts.hsf_status.flcinprog == 0) {
 1098                 /*
 1099                  * There is no cycle running at present,
 1100                  * so we can start a cycle.
 1101                  * Begin by setting Flash Cycle Done.
 1102                  */
 1103                 hsfsts.hsf_status.flcdone = 1;
 1104                 E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFSTS, hsfsts.regval);
 1105                 ret_val = E1000_SUCCESS;
 1106         } else {
 1107                 /*
 1108                  * Otherwise poll for sometime so the current
 1109                  * cycle has a chance to end before giving up.
 1110                  */
 1111                 for (i = 0; i < ICH_FLASH_READ_COMMAND_TIMEOUT; i++) {
 1112                         hsfsts.regval = E1000_READ_FLASH_REG16(hw,
 1113                                                               ICH_FLASH_HSFSTS);
 1114                         if (hsfsts.hsf_status.flcinprog == 0) {
 1115                                 ret_val = E1000_SUCCESS;
 1116                                 break;
 1117                         }
 1118                         usec_delay(1);
 1119                 }
 1120                 if (ret_val == E1000_SUCCESS) {
 1121                         /*
 1122                          * Successful in waiting for previous cycle to timeout,
 1123                          * now set the Flash Cycle Done.
 1124                          */
 1125                         hsfsts.hsf_status.flcdone = 1;
 1126                         E1000_WRITE_FLASH_REG16(hw,
 1127                                                 ICH_FLASH_HSFSTS,
 1128                                                 hsfsts.regval);
 1129                 } else {
 1130                         DEBUGOUT("Flash controller busy, cannot get access");
 1131                 }
 1132         }
 1133 
 1134 out:
 1135         return ret_val;
 1136 }
 1137 
 1138 /**
 1139  *  e1000_flash_cycle_ich8lan - Starts flash cycle (read/write/erase)
 1140  *  @hw: pointer to the HW structure
 1141  *  @timeout: maximum time to wait for completion
 1142  *
 1143  *  This function starts a flash cycle and waits for its completion.
 1144  **/
 1145 static s32 e1000_flash_cycle_ich8lan(struct e1000_hw *hw, u32 timeout)
 1146 {
 1147         union ich8_hws_flash_ctrl hsflctl;
 1148         union ich8_hws_flash_status hsfsts;
 1149         s32 ret_val = -E1000_ERR_NVM;
 1150         u32 i = 0;
 1151 
 1152         DEBUGFUNC("e1000_flash_cycle_ich8lan");
 1153 
 1154         /* Start a cycle by writing 1 in Flash Cycle Go in Hw Flash Control */
 1155         hsflctl.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
 1156         hsflctl.hsf_ctrl.flcgo = 1;
 1157         E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
 1158 
 1159         /* wait till FDONE bit is set to 1 */
 1160         do {
 1161                 hsfsts.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
 1162                 if (hsfsts.hsf_status.flcdone == 1)
 1163                         break;
 1164                 usec_delay(1);
 1165         } while (i++ < timeout);
 1166 
 1167         if (hsfsts.hsf_status.flcdone == 1 && hsfsts.hsf_status.flcerr == 0)
 1168                 ret_val = E1000_SUCCESS;
 1169 
 1170         return ret_val;
 1171 }
 1172 
 1173 /**
 1174  *  e1000_read_flash_word_ich8lan - Read word from flash
 1175  *  @hw: pointer to the HW structure
 1176  *  @offset: offset to data location
 1177  *  @data: pointer to the location for storing the data
 1178  *
 1179  *  Reads the flash word at offset into data.  Offset is converted
 1180  *  to bytes before read.
 1181  **/
 1182 STATIC s32 e1000_read_flash_word_ich8lan(struct e1000_hw *hw, u32 offset,
 1183                                          u16 *data)
 1184 {
 1185         s32 ret_val;
 1186 
 1187         DEBUGFUNC("e1000_read_flash_word_ich8lan");
 1188 
 1189         if (!data) {
 1190                 ret_val = -E1000_ERR_NVM;
 1191                 goto out;
 1192         }
 1193 
 1194         /* Must convert offset into bytes. */
 1195         offset <<= 1;
 1196 
 1197         ret_val = e1000_read_flash_data_ich8lan(hw, offset, 2, data);
 1198 
 1199 out:
 1200         return ret_val;
 1201 }
 1202 
 1203 /**
 1204  *  e1000_read_flash_data_ich8lan - Read byte or word from NVM
 1205  *  @hw: pointer to the HW structure
 1206  *  @offset: The offset (in bytes) of the byte or word to read.
 1207  *  @size: Size of data to read, 1=byte 2=word
 1208  *  @data: Pointer to the word to store the value read.
 1209  *
 1210  *  Reads a byte or word from the NVM using the flash access registers.
 1211  **/
 1212 static s32 e1000_read_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
 1213                                          u8 size, u16* data)
 1214 {
 1215         union ich8_hws_flash_status hsfsts;
 1216         union ich8_hws_flash_ctrl hsflctl;
 1217         u32 flash_linear_addr;
 1218         u32 flash_data = 0;
 1219         s32 ret_val = -E1000_ERR_NVM;
 1220         u8 count = 0;
 1221 
 1222         DEBUGFUNC("e1000_read_flash_data_ich8lan");
 1223 
 1224         if (size < 1  || size > 2 || offset > ICH_FLASH_LINEAR_ADDR_MASK)
 1225                 goto out;
 1226 
 1227         flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
 1228                             hw->nvm.flash_base_addr;
 1229 
 1230         do {
 1231                 usec_delay(1);
 1232                 /* Steps */
 1233                 ret_val = e1000_flash_cycle_init_ich8lan(hw);
 1234                 if (ret_val != E1000_SUCCESS)
 1235                         break;
 1236 
 1237                 hsflctl.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
 1238                 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
 1239                 hsflctl.hsf_ctrl.fldbcount = size - 1;
 1240                 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_READ;
 1241                 E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
 1242 
 1243                 E1000_WRITE_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_addr);
 1244 
 1245                 ret_val = e1000_flash_cycle_ich8lan(hw,
 1246                                                 ICH_FLASH_READ_COMMAND_TIMEOUT);
 1247 
 1248                 /*
 1249                  * Check if FCERR is set to 1, if set to 1, clear it
 1250                  * and try the whole sequence a few more times, else
 1251                  * read in (shift in) the Flash Data0, the order is
 1252                  * least significant byte first msb to lsb
 1253                  */
 1254                 if (ret_val == E1000_SUCCESS) {
 1255                         flash_data = E1000_READ_FLASH_REG(hw, ICH_FLASH_FDATA0);
 1256                         if (size == 1) {
 1257                                 *data = (u8)(flash_data & 0x000000FF);
 1258                         } else if (size == 2) {
 1259                                 *data = (u16)(flash_data & 0x0000FFFF);
 1260                         }
 1261                         break;
 1262                 } else {
 1263                         /*
 1264                          * If we've gotten here, then things are probably
 1265                          * completely hosed, but if the error condition is
 1266                          * detected, it won't hurt to give it another try...
 1267                          * ICH_FLASH_CYCLE_REPEAT_COUNT times.
 1268                          */
 1269                         hsfsts.regval = E1000_READ_FLASH_REG16(hw,
 1270                                                               ICH_FLASH_HSFSTS);
 1271                         if (hsfsts.hsf_status.flcerr == 1) {
 1272                                 /* Repeat for some time before giving up. */
 1273                                 continue;
 1274                         } else if (hsfsts.hsf_status.flcdone == 0) {
 1275                                 DEBUGOUT("Timeout error - flash cycle "
 1276                                          "did not complete.");
 1277                                 break;
 1278                         }
 1279                 }
 1280         } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
 1281 
 1282 out:
 1283         return ret_val;
 1284 }
 1285 
 1286 /**
 1287  *  e1000_write_nvm_ich8lan - Write word(s) to the NVM
 1288  *  @hw: pointer to the HW structure
 1289  *  @offset: The offset (in bytes) of the word(s) to write.
 1290  *  @words: Size of data to write in words
 1291  *  @data: Pointer to the word(s) to write at offset.
 1292  *
 1293  *  Writes a byte or word to the NVM using the flash access registers.
 1294  **/
 1295 STATIC s32 e1000_write_nvm_ich8lan(struct e1000_hw *hw, u16 offset, u16 words,
 1296                                    u16 *data)
 1297 {
 1298         struct e1000_nvm_info *nvm = &hw->nvm;
 1299         struct e1000_dev_spec_ich8lan *dev_spec;
 1300         s32 ret_val = E1000_SUCCESS;
 1301         u16 i;
 1302 
 1303         DEBUGFUNC("e1000_write_nvm_ich8lan");
 1304 
 1305         dev_spec = (struct e1000_dev_spec_ich8lan *)hw->dev_spec;
 1306 
 1307         if (!dev_spec) {
 1308                 DEBUGOUT("dev_spec pointer is set to NULL.\n");
 1309                 ret_val = -E1000_ERR_CONFIG;
 1310                 goto out;
 1311         }
 1312 
 1313         if ((offset >= nvm->word_size) || (words > nvm->word_size - offset) ||
 1314             (words == 0)) {
 1315                 DEBUGOUT("nvm parameter(s) out of bounds\n");
 1316                 ret_val = -E1000_ERR_NVM;
 1317                 goto out;
 1318         }
 1319 
 1320         ret_val = e1000_acquire_nvm(hw);
 1321         if (ret_val)
 1322                 goto out;
 1323 
 1324         for (i = 0; i < words; i++) {
 1325                 dev_spec->shadow_ram[offset+i].modified = TRUE;
 1326                 dev_spec->shadow_ram[offset+i].value = data[i];
 1327         }
 1328 
 1329         e1000_release_nvm(hw);
 1330 
 1331 out:
 1332         return ret_val;
 1333 }
 1334 
 1335 /**
 1336  *  e1000_update_nvm_checksum_ich8lan - Update the checksum for NVM
 1337  *  @hw: pointer to the HW structure
 1338  *
 1339  *  The NVM checksum is updated by calling the generic update_nvm_checksum,
 1340  *  which writes the checksum to the shadow ram.  The changes in the shadow
 1341  *  ram are then committed to the EEPROM by processing each bank at a time
 1342  *  checking for the modified bit and writing only the pending changes.
 1343  *  After a succesful commit, the shadow ram is cleared and is ready for
 1344  *  future writes.
 1345  **/
 1346 STATIC s32 e1000_update_nvm_checksum_ich8lan(struct e1000_hw *hw)
 1347 {
 1348         struct e1000_nvm_info *nvm = &hw->nvm;
 1349         struct e1000_dev_spec_ich8lan *dev_spec;
 1350         u32 i, act_offset, new_bank_offset, old_bank_offset;
 1351         s32 ret_val;
 1352         u16 data;
 1353 
 1354         DEBUGFUNC("e1000_update_nvm_checksum_ich8lan");
 1355 
 1356         dev_spec = (struct e1000_dev_spec_ich8lan *)hw->dev_spec;
 1357 
 1358         ret_val = e1000_update_nvm_checksum_generic(hw);
 1359         if (ret_val)
 1360                 goto out;
 1361 
 1362         if (nvm->type != e1000_nvm_flash_sw)
 1363                 goto out;
 1364 
 1365         ret_val = e1000_acquire_nvm(hw);
 1366         if (ret_val)
 1367                 goto out;
 1368 
 1369         /*
 1370          * We're writing to the opposite bank so if we're on bank 1,
 1371          * write to bank 0 etc.  We also need to erase the segment that
 1372          * is going to be written
 1373          */
 1374         if (!(E1000_READ_REG(hw, E1000_EECD) & E1000_EECD_SEC1VAL)) {
 1375                 new_bank_offset = nvm->flash_bank_size;
 1376                 old_bank_offset = 0;
 1377                 e1000_erase_flash_bank_ich8lan(hw, 1);
 1378         } else {
 1379                 old_bank_offset = nvm->flash_bank_size;
 1380                 new_bank_offset = 0;
 1381                 e1000_erase_flash_bank_ich8lan(hw, 0);
 1382         }
 1383 
 1384         for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
 1385                 /*
 1386                  * Determine whether to write the value stored
 1387                  * in the other NVM bank or a modified value stored
 1388                  * in the shadow RAM
 1389                  */
 1390                 if (dev_spec->shadow_ram[i].modified) {
 1391                         data = dev_spec->shadow_ram[i].value;
 1392                 } else {
 1393                         e1000_read_flash_word_ich8lan(hw,
 1394                                                       i + old_bank_offset,
 1395                                                       &data);
 1396                 }
 1397 
 1398                 /*
 1399                  * If the word is 0x13, then make sure the signature bits
 1400                  * (15:14) are 11b until the commit has completed.
 1401                  * This will allow us to write 10b which indicates the
 1402                  * signature is valid.  We want to do this after the write
 1403                  * has completed so that we don't mark the segment valid
 1404                  * while the write is still in progress
 1405                  */
 1406                 if (i == E1000_ICH_NVM_SIG_WORD)
 1407                         data |= E1000_ICH_NVM_SIG_MASK;
 1408 
 1409                 /* Convert offset to bytes. */
 1410                 act_offset = (i + new_bank_offset) << 1;
 1411 
 1412                 usec_delay(100);
 1413                 /* Write the bytes to the new bank. */
 1414                 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
 1415                                                                act_offset,
 1416                                                                (u8)data);
 1417                 if (ret_val)
 1418                         break;
 1419 
 1420                 usec_delay(100);
 1421                 ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
 1422                                                           act_offset + 1,
 1423                                                           (u8)(data >> 8));
 1424                 if (ret_val)
 1425                         break;
 1426         }
 1427 
 1428         /*
 1429          * Don't bother writing the segment valid bits if sector
 1430          * programming failed.
 1431          */
 1432         if (ret_val) {
 1433                 DEBUGOUT("Flash commit failed.\n");
 1434                 e1000_release_nvm(hw);
 1435                 goto out;
 1436         }
 1437 
 1438         /*
 1439          * Finally validate the new segment by setting bit 15:14
 1440          * to 10b in word 0x13 , this can be done without an
 1441          * erase as well since these bits are 11 to start with
 1442          * and we need to change bit 14 to 0b
 1443          */
 1444         act_offset = new_bank_offset + E1000_ICH_NVM_SIG_WORD;
 1445         e1000_read_flash_word_ich8lan(hw, act_offset, &data);
 1446         data &= 0xBFFF;
 1447         ret_val = e1000_retry_write_flash_byte_ich8lan(hw,
 1448                                                        act_offset * 2 + 1,
 1449                                                        (u8)(data >> 8));
 1450         if (ret_val) {
 1451                 e1000_release_nvm(hw);
 1452                 goto out;
 1453         }
 1454 
 1455         /*
 1456          * And invalidate the previously valid segment by setting
 1457          * its signature word (0x13) high_byte to 0b. This can be
 1458          * done without an erase because flash erase sets all bits
 1459          * to 1's. We can write 1's to 0's without an erase
 1460          */
 1461         act_offset = (old_bank_offset + E1000_ICH_NVM_SIG_WORD) * 2 + 1;
 1462         ret_val = e1000_retry_write_flash_byte_ich8lan(hw, act_offset, 0);
 1463         if (ret_val) {
 1464                 e1000_release_nvm(hw);
 1465                 goto out;
 1466         }
 1467 
 1468         /* Great!  Everything worked, we can now clear the cached entries. */
 1469         for (i = 0; i < E1000_SHADOW_RAM_WORDS; i++) {
 1470                 dev_spec->shadow_ram[i].modified = FALSE;
 1471                 dev_spec->shadow_ram[i].value = 0xFFFF;
 1472         }
 1473 
 1474         e1000_release_nvm(hw);
 1475 
 1476         /*
 1477          * Reload the EEPROM, or else modifications will not appear
 1478          * until after the next adapter reset.
 1479          */
 1480         e1000_reload_nvm(hw);
 1481         msec_delay(10);
 1482 
 1483 out:
 1484         return ret_val;
 1485 }
 1486 
 1487 /**
 1488  *  e1000_validate_nvm_checksum_ich8lan - Validate EEPROM checksum
 1489  *  @hw: pointer to the HW structure
 1490  *
 1491  *  Check to see if checksum needs to be fixed by reading bit 6 in word 0x19.
 1492  *  If the bit is 0, that the EEPROM had been modified, but the checksum was not
 1493  *  calculated, in which case we need to calculate the checksum and set bit 6.
 1494  **/
 1495 STATIC s32 e1000_validate_nvm_checksum_ich8lan(struct e1000_hw *hw)
 1496 {
 1497         s32 ret_val = E1000_SUCCESS;
 1498         u16 data;
 1499 
 1500         DEBUGFUNC("e1000_validate_nvm_checksum_ich8lan");
 1501 
 1502         /*
 1503          * Read 0x19 and check bit 6.  If this bit is 0, the checksum
 1504          * needs to be fixed.  This bit is an indication that the NVM
 1505          * was prepared by OEM software and did not calculate the
 1506          * checksum...a likely scenario.
 1507          */
 1508         ret_val = e1000_read_nvm(hw, 0x19, 1, &data);
 1509         if (ret_val)
 1510                 goto out;
 1511 
 1512         if ((data & 0x40) == 0) {
 1513                 data |= 0x40;
 1514                 ret_val = e1000_write_nvm(hw, 0x19, 1, &data);
 1515                 if (ret_val)
 1516                         goto out;
 1517                 ret_val = e1000_update_nvm_checksum(hw);
 1518                 if (ret_val)
 1519                         goto out;
 1520         }
 1521 
 1522         ret_val = e1000_validate_nvm_checksum_generic(hw);
 1523 
 1524 out:
 1525         return ret_val;
 1526 }
 1527 
 1528 /**
 1529  *  e1000_write_flash_data_ich8lan - Writes bytes to the NVM
 1530  *  @hw: pointer to the HW structure
 1531  *  @offset: The offset (in bytes) of the byte/word to read.
 1532  *  @size: Size of data to read, 1=byte 2=word
 1533  *  @data: The byte(s) to write to the NVM.
 1534  *
 1535  *  Writes one/two bytes to the NVM using the flash access registers.
 1536  **/
 1537 static s32 e1000_write_flash_data_ich8lan(struct e1000_hw *hw, u32 offset,
 1538                                           u8 size, u16 data)
 1539 {
 1540         union ich8_hws_flash_status hsfsts;
 1541         union ich8_hws_flash_ctrl hsflctl;
 1542         u32 flash_linear_addr;
 1543         u32 flash_data = 0;
 1544         s32 ret_val = -E1000_ERR_NVM;
 1545         u8 count = 0;
 1546 
 1547         DEBUGFUNC("e1000_write_ich8_data");
 1548 
 1549         if (size < 1 || size > 2 || data > size * 0xff ||
 1550             offset > ICH_FLASH_LINEAR_ADDR_MASK)
 1551                 goto out;
 1552 
 1553         flash_linear_addr = (ICH_FLASH_LINEAR_ADDR_MASK & offset) +
 1554                             hw->nvm.flash_base_addr;
 1555 
 1556         do {
 1557                 usec_delay(1);
 1558                 /* Steps */
 1559                 ret_val = e1000_flash_cycle_init_ich8lan(hw);
 1560                 if (ret_val != E1000_SUCCESS)
 1561                         break;
 1562 
 1563                 hsflctl.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFCTL);
 1564                 /* 0b/1b corresponds to 1 or 2 byte size, respectively. */
 1565                 hsflctl.hsf_ctrl.fldbcount = size -1;
 1566                 hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_WRITE;
 1567                 E1000_WRITE_FLASH_REG16(hw, ICH_FLASH_HSFCTL, hsflctl.regval);
 1568 
 1569                 E1000_WRITE_FLASH_REG(hw, ICH_FLASH_FADDR, flash_linear_addr);
 1570 
 1571                 if (size == 1)
 1572                         flash_data = (u32)data & 0x00FF;
 1573                 else
 1574                         flash_data = (u32)data;
 1575 
 1576                 E1000_WRITE_FLASH_REG(hw, ICH_FLASH_FDATA0, flash_data);
 1577 
 1578                 /*
 1579                  * check if FCERR is set to 1 , if set to 1, clear it
 1580                  * and try the whole sequence a few more times else done
 1581                  */
 1582                 ret_val = e1000_flash_cycle_ich8lan(hw,
 1583                                                ICH_FLASH_WRITE_COMMAND_TIMEOUT);
 1584                 if (ret_val == E1000_SUCCESS) {
 1585                         break;
 1586                 } else {
 1587                         /*
 1588                          * If we're here, then things are most likely
 1589                          * completely hosed, but if the error condition
 1590                          * is detected, it won't hurt to give it another
 1591                          * try...ICH_FLASH_CYCLE_REPEAT_COUNT times.
 1592                          */
 1593                         hsfsts.regval = E1000_READ_FLASH_REG16(hw,
 1594                                                               ICH_FLASH_HSFSTS);
 1595                         if (hsfsts.hsf_status.flcerr == 1) {
 1596                                 /* Repeat for some time before giving up. */
 1597                                 continue;
 1598                         } else if (hsfsts.hsf_status.flcdone == 0) {
 1599                                 DEBUGOUT("Timeout error - flash cycle "
 1600                                          "did not complete.");
 1601                                 break;
 1602                         }
 1603                 }
 1604         } while (count++ < ICH_FLASH_CYCLE_REPEAT_COUNT);
 1605 
 1606 out:
 1607         return ret_val;
 1608 }
 1609 
 1610 /**
 1611  *  e1000_write_flash_byte_ich8lan - Write a single byte to NVM
 1612  *  @hw: pointer to the HW structure
 1613  *  @offset: The index of the byte to read.
 1614  *  @data: The byte to write to the NVM.
 1615  *
 1616  *  Writes a single byte to the NVM using the flash access registers.
 1617  **/
 1618 STATIC s32 e1000_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
 1619                                           u8 data)
 1620 {
 1621         u16 word = (u16)data;
 1622 
 1623         DEBUGFUNC("e1000_write_flash_byte_ich8lan");
 1624 
 1625         return e1000_write_flash_data_ich8lan(hw, offset, 1, word);
 1626 }
 1627 
 1628 /**
 1629  *  e1000_retry_write_flash_byte_ich8lan - Writes a single byte to NVM
 1630  *  @hw: pointer to the HW structure
 1631  *  @offset: The offset of the byte to write.
 1632  *  @byte: The byte to write to the NVM.
 1633  *
 1634  *  Writes a single byte to the NVM using the flash access registers.
 1635  *  Goes through a retry algorithm before giving up.
 1636  **/
 1637 static s32 e1000_retry_write_flash_byte_ich8lan(struct e1000_hw *hw, u32 offset,
 1638                                                 u8 byte)
 1639 {
 1640         s32 ret_val;
 1641         u16 program_retries;
 1642 
 1643         DEBUGFUNC("e1000_retry_write_flash_byte_ich8lan");
 1644 
 1645         ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
 1646         if (ret_val == E1000_SUCCESS)
 1647                 goto out;
 1648 
 1649         for (program_retries = 0; program_retries < 100; program_retries++) {
 1650                 DEBUGOUT2("Retrying Byte %2.2X at offset %u\n", byte, offset);
 1651                 usec_delay(100);
 1652                 ret_val = e1000_write_flash_byte_ich8lan(hw, offset, byte);
 1653                 if (ret_val == E1000_SUCCESS)
 1654                         break;
 1655         }
 1656         if (program_retries == 100) {
 1657                 ret_val = -E1000_ERR_NVM;
 1658                 goto out;
 1659         }
 1660 
 1661 out:
 1662         return ret_val;
 1663 }
 1664 
 1665 /**
 1666  *  e1000_erase_flash_bank_ich8lan - Erase a bank (4k) from NVM
 1667  *  @hw: pointer to the HW structure
 1668  *  @bank: 0 for first bank, 1 for second bank, etc.
 1669  *
 1670  *  Erases the bank specified. Each bank is a 4k block. Banks are 0 based.
 1671  *  bank N is 4096 * N + flash_reg_addr.
 1672  **/
 1673 STATIC s32 e1000_erase_flash_bank_ich8lan(struct e1000_hw *hw, u32 bank)
 1674 {
 1675         struct e1000_nvm_info *nvm = &hw->nvm;
 1676         union ich8_hws_flash_status hsfsts;
 1677         union ich8_hws_flash_ctrl hsflctl;
 1678         u32 flash_linear_addr;
 1679         /* bank size is in 16bit words - adjust to bytes */
 1680         u32 flash_bank_size = nvm->flash_bank_size * 2;
 1681         s32  ret_val = E1000_SUCCESS;
 1682         s32  count = 0;
 1683         s32  j, iteration, sector_size;
 1684 
 1685         DEBUGFUNC("e1000_erase_flash_bank_ich8lan");
 1686 
 1687         hsfsts.regval = E1000_READ_FLASH_REG16(hw, ICH_FLASH_HSFSTS);
 1688 
 1689         /*
 1690          * Determine HW Sector size: Read BERASE bits of hw flash status
 1691          * register
 1692          * 00: The Hw sector is 256 bytes, hence we need to erase 16
 1693          *     consecutive sectors.  The start index for the nth Hw sector
 1694          *     can be calculated as = bank * 4096 + n * 256
 1695          * 01: The Hw sector is 4K bytes, hence we need to erase 1 sector.
 1696          *     The start index for the nth Hw sector can be calculated
 1697          *     as = bank * 4096
 1698          * 10: The Hw sector is 8K bytes, nth sector = bank * 8192
 1699          *     (ich9 only, otherwise error condition)
 1700          * 11: The Hw sector is 64K bytes, nth sector = bank * 65536
 1701          */
 1702         switch (hsfsts.hsf_status.berasesz) {
 1703         case 0:
 1704                 /* Hw sector size 256 */
 1705                 sector_size = ICH_FLASH_SEG_SIZE_256;
 1706                 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_256;
 1707                 break;
 1708         case 1:
 1709                 sector_size = ICH_FLASH_SEG_SIZE_4K;
 1710                 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_4K;
 1711                 break;
 1712         case 2:
 1713                 if (hw->mac.type == e1000_ich9lan) {
 1714                         sector_size = ICH_FLASH_SEG_SIZE_8K;
 1715                         iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_8K;
 1716                 } else {
 1717                         ret_val = -E1000_ERR_NVM;
 1718                         goto out;
 1719                 }
 1720                 break;
 1721         case 3:
 1722                 sector_size = ICH_FLASH_SEG_SIZE_64K;
 1723                 iteration = flash_bank_size / ICH_FLASH_SEG_SIZE_64K;
 1724                 break;
 1725         default:
 1726                 ret_val = -E1000_ERR_NVM;
 1727                 goto out;
 1728         }
 1729 
 1730         /* Start with the base address, then add the sector offset. */
 1731         flash_linear_addr = hw->nvm.flash_base_addr;
 1732         flash_linear_addr += (bank) ? (sector_size * iteration) : 0;
 1733 
 1734         for (j = 0; j < iteration ; j++) {
 1735                 do {
 1736                         /* Steps */
 1737                         ret_val = e1000_flash_cycle_init_ich8lan(hw);
 1738                         if (ret_val)
 1739                                 goto out;
 1740 
 1741                         /*
 1742                          * Write a value 11 (block Erase) in Flash
 1743                          * Cycle field in hw flash control
 1744                          */
 1745                         hsflctl.regval = E1000_READ_FLASH_REG16(hw,
 1746                                                               ICH_FLASH_HSFCTL);
 1747                         hsflctl.hsf_ctrl.flcycle = ICH_CYCLE_ERASE;
 1748                         E1000_WRITE_FLASH_REG16(hw,
 1749                                                 ICH_FLASH_HSFCTL,
 1750                                                 hsflctl.regval);
 1751 
 1752                         /*
 1753                          * Write the last 24 bits of an index within the
 1754                          * block into Flash Linear address field in Flash
 1755                          * Address.
 1756                          */
 1757                         flash_linear_addr += (j * sector_size);
 1758                         E1000_WRITE_FLASH_REG(hw,
 1759                                               ICH_FLASH_FADDR,
 1760                                               flash_linear_addr);
 1761 
 1762                         ret_val = e1000_flash_cycle_ich8lan(hw,
 1763                                                ICH_FLASH_ERASE_COMMAND_TIMEOUT);
 1764                         if (ret_val == E1000_SUCCESS) {
 1765                                 break;
 1766                         } else {
 1767                                 /*
 1768                                  * Check if FCERR is set to 1.  If 1,
 1769                                  * clear it and try the whole sequence
 1770                                  * a few more times else Done
 1771                                  */
 1772                                 hsfsts.regval = E1000_READ_FLASH_REG16(hw,
 1773                                                               ICH_FLASH_HSFSTS);
 1774                                 if (hsfsts.hsf_status.flcerr == 1) {
 1775                                         /*
 1776                                          * repeat for some time before
 1777                                          * giving up
 1778                                          */
 1779                                         continue;
 1780                                 } else if (hsfsts.hsf_status.flcdone == 0)
 1781                                         goto out;
 1782                         }
 1783                 } while (++count < ICH_FLASH_CYCLE_REPEAT_COUNT);
 1784         }
 1785 
 1786 out:
 1787         return ret_val;
 1788 }
 1789 
 1790 /**
 1791  *  e1000_valid_led_default_ich8lan - Set the default LED settings
 1792  *  @hw: pointer to the HW structure
 1793  *  @data: Pointer to the LED settings
 1794  *
 1795  *  Reads the LED default settings from the NVM to data.  If the NVM LED
 1796  *  settings is all 0's or F's, set the LED default to a valid LED default
 1797  *  setting.
 1798  **/
 1799 STATIC s32 e1000_valid_led_default_ich8lan(struct e1000_hw *hw, u16 *data)
 1800 {
 1801         s32 ret_val;
 1802 
 1803         DEBUGFUNC("e1000_valid_led_default_ich8lan");
 1804 
 1805         ret_val = e1000_read_nvm(hw, NVM_ID_LED_SETTINGS, 1, data);
 1806         if (ret_val) {
 1807                 DEBUGOUT("NVM Read Error\n");
 1808                 goto out;
 1809         }
 1810 
 1811         if (*data == ID_LED_RESERVED_0000 ||
 1812             *data == ID_LED_RESERVED_FFFF)
 1813                 *data = ID_LED_DEFAULT_ICH8LAN;
 1814 
 1815 out:
 1816         return ret_val;
 1817 }
 1818 
 1819 /**
 1820  *  e1000_get_bus_info_ich8lan - Get/Set the bus type and width
 1821  *  @hw: pointer to the HW structure
 1822  *
 1823  *  ICH8 use the PCI Express bus, but does not contain a PCI Express Capability
 1824  *  register, so the the bus width is hard coded.
 1825  **/
 1826 STATIC s32 e1000_get_bus_info_ich8lan(struct e1000_hw *hw)
 1827 {
 1828         struct e1000_bus_info *bus = &hw->bus;
 1829         s32 ret_val;
 1830 
 1831         DEBUGFUNC("e1000_get_bus_info_ich8lan");
 1832 
 1833         ret_val = e1000_get_bus_info_pcie_generic(hw);
 1834 
 1835         /*
 1836          * ICH devices are "PCI Express"-ish.  They have
 1837          * a configuration space, but do not contain
 1838          * PCI Express Capability registers, so bus width
 1839          * must be hardcoded.
 1840          */
 1841         if (bus->width == e1000_bus_width_unknown)
 1842                 bus->width = e1000_bus_width_pcie_x1;
 1843 
 1844         return ret_val;
 1845 }
 1846 
 1847 /**
 1848  *  e1000_reset_hw_ich8lan - Reset the hardware
 1849  *  @hw: pointer to the HW structure
 1850  *
 1851  *  Does a full reset of the hardware which includes a reset of the PHY and
 1852  *  MAC.
 1853  **/
 1854 STATIC s32 e1000_reset_hw_ich8lan(struct e1000_hw *hw)
 1855 {
 1856         u32 ctrl, icr, kab;
 1857         s32 ret_val;
 1858 
 1859         DEBUGFUNC("e1000_reset_hw_ich8lan");
 1860 
 1861         /*
 1862          * Prevent the PCI-E bus from sticking if there is no TLP connection
 1863          * on the last TLP read/write transaction when MAC is reset.
 1864          */
 1865         ret_val = e1000_disable_pcie_master_generic(hw);
 1866         if (ret_val) {
 1867                 DEBUGOUT("PCI-E Master disable polling has failed.\n");
 1868         }
 1869 
 1870         DEBUGOUT("Masking off all interrupts\n");
 1871         E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
 1872 
 1873         /*
 1874          * Disable the Transmit and Receive units.  Then delay to allow
 1875          * any pending transactions to complete before we hit the MAC
 1876          * with the global reset.
 1877          */
 1878         E1000_WRITE_REG(hw, E1000_RCTL, 0);
 1879         E1000_WRITE_REG(hw, E1000_TCTL, E1000_TCTL_PSP);
 1880         E1000_WRITE_FLUSH(hw);
 1881 
 1882         msec_delay(10);
 1883 
 1884         /* Workaround for ICH8 bit corruption issue in FIFO memory */
 1885         if (hw->mac.type == e1000_ich8lan) {
 1886                 /* Set Tx and Rx buffer allocation to 8k apiece. */
 1887                 E1000_WRITE_REG(hw, E1000_PBA, E1000_PBA_8K);
 1888                 /* Set Packet Buffer Size to 16k. */
 1889                 E1000_WRITE_REG(hw, E1000_PBS, E1000_PBS_16K);
 1890         }
 1891 
 1892         ctrl = E1000_READ_REG(hw, E1000_CTRL);
 1893 
 1894         if (!e1000_check_reset_block(hw) && !hw->phy.reset_disable) {
 1895                 /*
 1896                  * PHY HW reset requires MAC CORE reset at the same
 1897                  * time to make sure the interface between MAC and the
 1898                  * external PHY is reset.
 1899                  */
 1900                 ctrl |= E1000_CTRL_PHY_RST;
 1901         }
 1902         ret_val = e1000_acquire_swflag_ich8lan(hw);
 1903         DEBUGOUT("Issuing a global reset to ich8lan");
 1904         E1000_WRITE_REG(hw, E1000_CTRL, (ctrl | E1000_CTRL_RST));
 1905         msec_delay(20);
 1906 
 1907         ret_val = e1000_get_auto_rd_done_generic(hw);
 1908         if (ret_val) {
 1909                 /*
 1910                  * When auto config read does not complete, do not
 1911                  * return with an error. This can happen in situations
 1912                  * where there is no eeprom and prevents getting link.
 1913                  */
 1914                 DEBUGOUT("Auto Read Done did not complete\n");
 1915         }
 1916 
 1917         E1000_WRITE_REG(hw, E1000_IMC, 0xffffffff);
 1918         icr = E1000_READ_REG(hw, E1000_ICR);
 1919 
 1920         kab = E1000_READ_REG(hw, E1000_KABGTXD);
 1921         kab |= E1000_KABGTXD_BGSQLBIAS;
 1922         E1000_WRITE_REG(hw, E1000_KABGTXD, kab);
 1923 
 1924         return ret_val;
 1925 }
 1926 
 1927 /**
 1928  *  e1000_init_hw_ich8lan - Initialize the hardware
 1929  *  @hw: pointer to the HW structure
 1930  *
 1931  *  Prepares the hardware for transmit and receive by doing the following:
 1932  *   - initialize hardware bits
 1933  *   - initialize LED identification
 1934  *   - setup receive address registers
 1935  *   - setup flow control
 1936  *   - setup transmit discriptors
 1937  *   - clear statistics
 1938  **/
 1939 STATIC s32 e1000_init_hw_ich8lan(struct e1000_hw *hw)
 1940 {
 1941         struct e1000_mac_info *mac = &hw->mac;
 1942         u32 ctrl_ext, txdctl, snoop;
 1943         s32 ret_val;
 1944         u16 i;
 1945 
 1946         DEBUGFUNC("e1000_init_hw_ich8lan");
 1947 
 1948         e1000_initialize_hw_bits_ich8lan(hw);
 1949 
 1950         /* Initialize identification LED */
 1951         ret_val = e1000_id_led_init_generic(hw);
 1952         if (ret_val) {
 1953                 DEBUGOUT("Error initializing identification LED\n");
 1954                 /* This is not fatal and we should not stop init due to this */
 1955         }
 1956 
 1957         /* Setup the receive address. */
 1958         e1000_init_rx_addrs_generic(hw, mac->rar_entry_count);
 1959 
 1960         /* Zero out the Multicast HASH table */
 1961         DEBUGOUT("Zeroing the MTA\n");
 1962         for (i = 0; i < mac->mta_reg_count; i++)
 1963                 E1000_WRITE_REG_ARRAY(hw, E1000_MTA, i, 0);
 1964 
 1965         /* Setup link and flow control */
 1966         ret_val = e1000_setup_link(hw);
 1967 
 1968         /* Set the transmit descriptor write-back policy for both queues */
 1969         txdctl = E1000_READ_REG(hw, E1000_TXDCTL(0));
 1970         txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
 1971                  E1000_TXDCTL_FULL_TX_DESC_WB;
 1972         txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
 1973                  E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
 1974         E1000_WRITE_REG(hw, E1000_TXDCTL(0), txdctl);
 1975         txdctl = E1000_READ_REG(hw, E1000_TXDCTL(1));
 1976         txdctl = (txdctl & ~E1000_TXDCTL_WTHRESH) |
 1977                  E1000_TXDCTL_FULL_TX_DESC_WB;
 1978         txdctl = (txdctl & ~E1000_TXDCTL_PTHRESH) |
 1979                  E1000_TXDCTL_MAX_TX_DESC_PREFETCH;
 1980         E1000_WRITE_REG(hw, E1000_TXDCTL(1), txdctl);
 1981 
 1982         /*
 1983          * ICH8 has opposite polarity of no_snoop bits.
 1984          * By default, we should use snoop behavior.
 1985          */
 1986         if (mac->type == e1000_ich8lan)
 1987                 snoop = PCIE_ICH8_SNOOP_ALL;
 1988         else
 1989                 snoop = (u32)~(PCIE_NO_SNOOP_ALL);
 1990         e1000_set_pcie_no_snoop_generic(hw, snoop);
 1991 
 1992         ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
 1993         ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
 1994         E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
 1995 
 1996         /*
 1997          * Clear all of the statistics registers (clear on read).  It is
 1998          * important that we do this after we have tried to establish link
 1999          * because the symbol error count will increment wildly if there
 2000          * is no link.
 2001          */
 2002         e1000_clear_hw_cntrs_ich8lan(hw);
 2003 
 2004         return ret_val;
 2005 }
 2006 /**
 2007  *  e1000_initialize_hw_bits_ich8lan - Initialize required hardware bits
 2008  *  @hw: pointer to the HW structure
 2009  *
 2010  *  Sets/Clears required hardware bits necessary for correctly setting up the
 2011  *  hardware for transmit and receive.
 2012  **/
 2013 static void e1000_initialize_hw_bits_ich8lan(struct e1000_hw *hw)
 2014 {
 2015         u32 reg;
 2016 
 2017         DEBUGFUNC("e1000_initialize_hw_bits_ich8lan");
 2018 
 2019         if (hw->mac.disable_hw_init_bits)
 2020                 goto out;
 2021 
 2022         /* Extended Device Control */
 2023         reg = E1000_READ_REG(hw, E1000_CTRL_EXT);
 2024         reg |= (1 << 22);
 2025         E1000_WRITE_REG(hw, E1000_CTRL_EXT, reg);
 2026 
 2027         /* Transmit Descriptor Control 0 */
 2028         reg = E1000_READ_REG(hw, E1000_TXDCTL(0));
 2029         reg |= (1 << 22);
 2030         E1000_WRITE_REG(hw, E1000_TXDCTL(0), reg);
 2031 
 2032         /* Transmit Descriptor Control 1 */
 2033         reg = E1000_READ_REG(hw, E1000_TXDCTL(1));
 2034         reg |= (1 << 22);
 2035         E1000_WRITE_REG(hw, E1000_TXDCTL(1), reg);
 2036 
 2037         /* Transmit Arbitration Control 0 */
 2038         reg = E1000_READ_REG(hw, E1000_TARC(0));
 2039         if (hw->mac.type == e1000_ich8lan)
 2040                 reg |= (1 << 28) | (1 << 29);
 2041         reg |= (1 << 23) | (1 << 24) | (1 << 26) | (1 << 27);
 2042         E1000_WRITE_REG(hw, E1000_TARC(0), reg);
 2043 
 2044         /* Transmit Arbitration Control 1 */
 2045         reg = E1000_READ_REG(hw, E1000_TARC(1));
 2046         if (E1000_READ_REG(hw, E1000_TCTL) & E1000_TCTL_MULR)
 2047                 reg &= ~(1 << 28);
 2048         else
 2049                 reg |= (1 << 28);
 2050         reg |= (1 << 24) | (1 << 26) | (1 << 30);
 2051         E1000_WRITE_REG(hw, E1000_TARC(1), reg);
 2052 
 2053         /* Device Status */
 2054         if (hw->mac.type == e1000_ich8lan) {
 2055                 reg = E1000_READ_REG(hw, E1000_STATUS);
 2056                 reg &= ~(1 << 31);
 2057                 E1000_WRITE_REG(hw, E1000_STATUS, reg);
 2058         }
 2059 
 2060 out:
 2061         return;
 2062 }
 2063 
 2064 /**
 2065  *  e1000_setup_link_ich8lan - Setup flow control and link settings
 2066  *  @hw: pointer to the HW structure
 2067  *
 2068  *  Determines which flow control settings to use, then configures flow
 2069  *  control.  Calls the appropriate media-specific link configuration
 2070  *  function.  Assuming the adapter has a valid link partner, a valid link
 2071  *  should be established.  Assumes the hardware has previously been reset
 2072  *  and the transmitter and receiver are not enabled.
 2073  **/
 2074 STATIC s32 e1000_setup_link_ich8lan(struct e1000_hw *hw)
 2075 {
 2076         struct e1000_functions *func = &hw->func;
 2077         s32 ret_val = E1000_SUCCESS;
 2078 
 2079         DEBUGFUNC("e1000_setup_link_ich8lan");
 2080 
 2081         if (e1000_check_reset_block(hw))
 2082                 goto out;
 2083 
 2084         /*
 2085          * ICH parts do not have a word in the NVM to determine
 2086          * the default flow control setting, so we explicitly
 2087          * set it to full.
 2088          */
 2089         if (hw->fc.type == e1000_fc_default)
 2090                 hw->fc.type = e1000_fc_full;
 2091 
 2092         hw->fc.original_type = hw->fc.type;
 2093 
 2094         DEBUGOUT1("After fix-ups FlowControl is now = %x\n", hw->fc.type);
 2095 
 2096         /* Continue to configure the copper link. */
 2097         ret_val = func->setup_physical_interface(hw);
 2098         if (ret_val)
 2099                 goto out;
 2100 
 2101         E1000_WRITE_REG(hw, E1000_FCTTV, hw->fc.pause_time);
 2102 
 2103         ret_val = e1000_set_fc_watermarks_generic(hw);
 2104 
 2105 out:
 2106         return ret_val;
 2107 }
 2108 
 2109 /**
 2110  *  e1000_setup_copper_link_ich8lan - Configure MAC/PHY interface
 2111  *  @hw: pointer to the HW structure
 2112  *
 2113  *  Configures the kumeran interface to the PHY to wait the appropriate time
 2114  *  when polling the PHY, then call the generic setup_copper_link to finish
 2115  *  configuring the copper link.
 2116  **/
 2117 STATIC s32 e1000_setup_copper_link_ich8lan(struct e1000_hw *hw)
 2118 {
 2119         u32 ctrl;
 2120         s32 ret_val;
 2121         u16 reg_data;
 2122 
 2123         DEBUGFUNC("e1000_setup_copper_link_ich8lan");
 2124 
 2125         ctrl = E1000_READ_REG(hw, E1000_CTRL);
 2126         ctrl |= E1000_CTRL_SLU;
 2127         ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
 2128         E1000_WRITE_REG(hw, E1000_CTRL, ctrl);
 2129 
 2130         /*
 2131          * Set the mac to wait the maximum time between each iteration
 2132          * and increase the max iterations when polling the phy;
 2133          * this fixes erroneous timeouts at 10Mbps.
 2134          */
 2135         ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 4), 0xFFFF);
 2136         if (ret_val)
 2137                 goto out;
 2138         ret_val = e1000_read_kmrn_reg(hw, GG82563_REG(0x34, 9), &reg_data);
 2139         if (ret_val)
 2140                 goto out;
 2141         reg_data |= 0x3F;
 2142         ret_val = e1000_write_kmrn_reg(hw, GG82563_REG(0x34, 9), reg_data);
 2143         if (ret_val)
 2144                 goto out;
 2145 
 2146         if (hw->phy.type == e1000_phy_igp_3) {
 2147                 ret_val = e1000_copper_link_setup_igp(hw);
 2148                 if (ret_val)
 2149                         goto out;
 2150         }
 2151 
 2152         ret_val = e1000_setup_copper_link_generic(hw);
 2153 
 2154 out:
 2155         return ret_val;
 2156 }
 2157 
 2158 /**
 2159  *  e1000_get_link_up_info_ich8lan - Get current link speed and duplex
 2160  *  @hw: pointer to the HW structure
 2161  *  @speed: pointer to store current link speed
 2162  *  @duplex: pointer to store the current link duplex
 2163  *
 2164  *  Calls the generic get_speed_and_duplex to retreive the current link
 2165  *  information and then calls the Kumeran lock loss workaround for links at
 2166  *  gigabit speeds.
 2167  **/
 2168 STATIC s32 e1000_get_link_up_info_ich8lan(struct e1000_hw *hw, u16 *speed,
 2169                                           u16 *duplex)
 2170 {
 2171         s32 ret_val;
 2172 
 2173         DEBUGFUNC("e1000_get_link_up_info_ich8lan");
 2174 
 2175         ret_val = e1000_get_speed_and_duplex_copper_generic(hw, speed, duplex);
 2176         if (ret_val)
 2177                 goto out;
 2178 
 2179         if ((hw->mac.type == e1000_ich8lan) &&
 2180             (hw->phy.type == e1000_phy_igp_3) &&
 2181             (*speed == SPEED_1000)) {
 2182                 ret_val = e1000_kmrn_lock_loss_workaround_ich8lan(hw);
 2183         }
 2184 
 2185 out:
 2186         return ret_val;
 2187 }
 2188 
 2189 /**
 2190  *  e1000_kmrn_lock_loss_workaround_ich8lan - Kumeran workaround
 2191  *  @hw: pointer to the HW structure
 2192  *
 2193  *  Work-around for 82566 Kumeran PCS lock loss:
 2194  *  On link status change (i.e. PCI reset, speed change) and link is up and
 2195  *  speed is gigabit-
 2196  *    0) if workaround is optionally disabled do nothing
 2197  *    1) wait 1ms for Kumeran link to come up
 2198  *    2) check Kumeran Diagnostic register PCS lock loss bit
 2199  *    3) if not set the link is locked (all is good), otherwise...
 2200  *    4) reset the PHY
 2201  *    5) repeat up to 10 times
 2202  *  Note: this is only called for IGP3 copper when speed is 1gb.
 2203  **/
 2204 static s32 e1000_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw)
 2205 {
 2206         struct e1000_dev_spec_ich8lan *dev_spec;
 2207         u32 phy_ctrl;
 2208         s32 ret_val = E1000_SUCCESS;
 2209         u16 i, data;
 2210         bool link;
 2211 
 2212         DEBUGFUNC("e1000_kmrn_lock_loss_workaround_ich8lan");
 2213 
 2214         dev_spec = (struct e1000_dev_spec_ich8lan *)hw->dev_spec;
 2215 
 2216         if (!dev_spec) {
 2217                 DEBUGOUT("dev_spec pointer is set to NULL.\n");
 2218                 ret_val = -E1000_ERR_CONFIG;
 2219                 goto out;
 2220         }
 2221 
 2222         if (!(dev_spec->kmrn_lock_loss_workaround_enabled))
 2223                 goto out;
 2224 
 2225         /*
 2226          * Make sure link is up before proceeding.  If not just return.
 2227          * Attempting this while link is negotiating fouled up link
 2228          * stability
 2229          */
 2230         ret_val = e1000_phy_has_link_generic(hw, 1, 0, &link);
 2231         if (!link) {
 2232                 ret_val = E1000_SUCCESS;
 2233                 goto out;
 2234         }
 2235 
 2236         for (i = 0; i < 10; i++) {
 2237                 /* read once to clear */
 2238                 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &data);
 2239                 if (ret_val)
 2240                         goto out;
 2241                 /* and again to get new status */
 2242                 ret_val = e1000_read_phy_reg(hw, IGP3_KMRN_DIAG, &data);
 2243                 if (ret_val)
 2244                         goto out;
 2245 
 2246                 /* check for PCS lock */
 2247                 if (!(data & IGP3_KMRN_DIAG_PCS_LOCK_LOSS)) {
 2248                         ret_val = E1000_SUCCESS;
 2249                         goto out;
 2250                 }
 2251 
 2252                 /* Issue PHY reset */
 2253                 e1000_phy_hw_reset(hw);
 2254                 msec_delay_irq(5);
 2255         }
 2256         /* Disable GigE link negotiation */
 2257         phy_ctrl = E1000_READ_REG(hw, E1000_PHY_CTRL);
 2258         phy_ctrl |= (E1000_PHY_CTRL_GBE_DISABLE |
 2259                      E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
 2260         E1000_WRITE_REG(hw, E1000_PHY_CTRL, phy_ctrl);
 2261 
 2262         /*
 2263          * Call gig speed drop workaround on Giga disable before accessing
 2264          * any PHY registers
 2265          */
 2266         e1000_gig_downshift_workaround_ich8lan(hw);
 2267 
 2268         /* unable to acquire PCS lock */
 2269         ret_val = -E1000_ERR_PHY;
 2270 
 2271 out:
 2272         return ret_val;
 2273 }
 2274 
 2275 /**
 2276  *  e1000_set_kmrn_lock_loss_workaound_ich8lan - Set Kumeran workaround state
 2277  *  @hw: pointer to the HW structure
 2278  *  @state: boolean value used to set the current Kumaran workaround state
 2279  *
 2280  *  If ICH8, set the current Kumeran workaround state (enabled - TRUE
 2281  *  /disabled - FALSE).
 2282  **/
 2283 void e1000_set_kmrn_lock_loss_workaround_ich8lan(struct e1000_hw *hw,
 2284                                                  bool state)
 2285 {
 2286         struct e1000_dev_spec_ich8lan *dev_spec;
 2287 
 2288         DEBUGFUNC("e1000_set_kmrn_lock_loss_workaround_ich8lan");
 2289 
 2290         if (hw->mac.type != e1000_ich8lan) {
 2291                 DEBUGOUT("Workaround applies to ICH8 only.\n");
 2292                 goto out;
 2293         }
 2294 
 2295         dev_spec = (struct e1000_dev_spec_ich8lan *)hw->dev_spec;
 2296 
 2297         if (!dev_spec) {
 2298                 DEBUGOUT("dev_spec pointer is set to NULL.\n");
 2299                 goto out;
 2300         }
 2301 
 2302         dev_spec->kmrn_lock_loss_workaround_enabled = state;
 2303 
 2304 out:
 2305         return;
 2306 }
 2307 
 2308 /**
 2309  *  e1000_ipg3_phy_powerdown_workaround_ich8lan - Power down workaround on D3
 2310  *  @hw: pointer to the HW structure
 2311  *
 2312  *  Workaround for 82566 power-down on D3 entry:
 2313  *    1) disable gigabit link
 2314  *    2) write VR power-down enable
 2315  *    3) read it back
 2316  *  Continue if successful, else issue LCD reset and repeat
 2317  **/
 2318 void e1000_igp3_phy_powerdown_workaround_ich8lan(struct e1000_hw *hw)
 2319 {
 2320         u32 reg;
 2321         u16 data;
 2322         u8  retry = 0;
 2323 
 2324         DEBUGFUNC("e1000_igp3_phy_powerdown_workaround_ich8lan");
 2325 
 2326         if (hw->phy.type != e1000_phy_igp_3)
 2327                 goto out;
 2328 
 2329         /* Try the workaround twice (if needed) */
 2330         do {
 2331                 /* Disable link */
 2332                 reg = E1000_READ_REG(hw, E1000_PHY_CTRL);
 2333                 reg |= (E1000_PHY_CTRL_GBE_DISABLE |
 2334                         E1000_PHY_CTRL_NOND0A_GBE_DISABLE);
 2335                 E1000_WRITE_REG(hw, E1000_PHY_CTRL, reg);
 2336 
 2337                 /*
 2338                  * Call gig speed drop workaround on Giga disable before
 2339                  * accessing any PHY registers
 2340                  */
 2341                 if (hw->mac.type == e1000_ich8lan)
 2342                         e1000_gig_downshift_workaround_ich8lan(hw);
 2343 
 2344                 /* Write VR power-down enable */
 2345                 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &data);
 2346                 data &= ~IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
 2347                 e1000_write_phy_reg(hw,
 2348                                    IGP3_VR_CTRL,
 2349                                    data | IGP3_VR_CTRL_MODE_SHUTDOWN);
 2350 
 2351                 /* Read it back and test */
 2352                 e1000_read_phy_reg(hw, IGP3_VR_CTRL, &data);
 2353                 data &= IGP3_VR_CTRL_DEV_POWERDOWN_MODE_MASK;
 2354                 if ((data == IGP3_VR_CTRL_MODE_SHUTDOWN) || retry)
 2355                         break;
 2356 
 2357                 /* Issue PHY reset and repeat at most one more time */
 2358                 reg = E1000_READ_REG(hw, E1000_CTRL);
 2359                 E1000_WRITE_REG(hw, E1000_CTRL, reg | E1000_CTRL_PHY_RST);
 2360                 retry++;
 2361         } while (retry);
 2362 
 2363 out:
 2364         return;
 2365 }
 2366 
 2367 /**
 2368  *  e1000_gig_downshift_workaround_ich8lan - WoL from S5 stops working
 2369  *  @hw: pointer to the HW structure
 2370  *
 2371  *  Steps to take when dropping from 1Gb/s (eg. link cable removal (LSC),
 2372  *  LPLU, Giga disable, MDIC PHY reset):
 2373  *    1) Set Kumeran Near-end loopback
 2374  *    2) Clear Kumeran Near-end loopback
 2375  *  Should only be called for ICH8[m] devices with IGP_3 Phy.
 2376  **/
 2377 void e1000_gig_downshift_workaround_ich8lan(struct e1000_hw *hw)
 2378 {
 2379         s32 ret_val = E1000_SUCCESS;
 2380         u16 reg_data;
 2381 
 2382         DEBUGFUNC("e1000_gig_downshift_workaround_ich8lan");
 2383 
 2384         if ((hw->mac.type != e1000_ich8lan) ||
 2385             (hw->phy.type != e1000_phy_igp_3))
 2386                 goto out;
 2387 
 2388         ret_val = e1000_read_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
 2389                                       &reg_data);
 2390         if (ret_val)
 2391                 goto out;
 2392         reg_data |= E1000_KMRNCTRLSTA_DIAG_NELPBK;
 2393         ret_val = e1000_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
 2394                                        reg_data);
 2395         if (ret_val)
 2396                 goto out;
 2397         reg_data &= ~E1000_KMRNCTRLSTA_DIAG_NELPBK;
 2398         ret_val = e1000_write_kmrn_reg(hw, E1000_KMRNCTRLSTA_DIAG_OFFSET,
 2399                                        reg_data);
 2400 out:
 2401         return;
 2402 }
 2403 
 2404 /**
 2405  *  e1000_cleanup_led_ich8lan - Restore the default LED operation
 2406  *  @hw: pointer to the HW structure
 2407  *
 2408  *  Return the LED back to the default configuration.
 2409  **/
 2410 STATIC s32 e1000_cleanup_led_ich8lan(struct e1000_hw *hw)
 2411 {
 2412         s32 ret_val = E1000_SUCCESS;
 2413 
 2414         DEBUGFUNC("e1000_cleanup_led_ich8lan");
 2415 
 2416         if (hw->phy.type == e1000_phy_ife)
 2417                 ret_val = e1000_write_phy_reg(hw,
 2418                                                 IFE_PHY_SPECIAL_CONTROL_LED,
 2419                                                 0);
 2420         else
 2421                 E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_default);
 2422 
 2423         return ret_val;
 2424 }
 2425 
 2426 /**
 2427  *  e1000_led_on_ich8lan - Turn LED's on
 2428  *  @hw: pointer to the HW structure
 2429  *
 2430  *  Turn on the LED's.
 2431  **/
 2432 STATIC s32 e1000_led_on_ich8lan(struct e1000_hw *hw)
 2433 {
 2434         s32 ret_val = E1000_SUCCESS;
 2435 
 2436         DEBUGFUNC("e1000_led_on_ich8lan");
 2437 
 2438         if (hw->phy.type == e1000_phy_ife)
 2439                 ret_val = e1000_write_phy_reg(hw,
 2440                                 IFE_PHY_SPECIAL_CONTROL_LED,
 2441                                 (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_ON));
 2442         else
 2443                 E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode2);
 2444 
 2445         return ret_val;
 2446 }
 2447 
 2448 /**
 2449  *  e1000_led_off_ich8lan - Turn LED's off
 2450  *  @hw: pointer to the HW structure
 2451  *
 2452  *  Turn off the LED's.
 2453  **/
 2454 STATIC s32 e1000_led_off_ich8lan(struct e1000_hw *hw)
 2455 {
 2456         s32 ret_val = E1000_SUCCESS;
 2457 
 2458         DEBUGFUNC("e1000_led_off_ich8lan");
 2459 
 2460         if (hw->phy.type == e1000_phy_ife)
 2461                 ret_val = e1000_write_phy_reg(hw,
 2462                                IFE_PHY_SPECIAL_CONTROL_LED,
 2463                                (IFE_PSCL_PROBE_MODE | IFE_PSCL_PROBE_LEDS_OFF));
 2464         else
 2465                 E1000_WRITE_REG(hw, E1000_LEDCTL, hw->mac.ledctl_mode1);
 2466 
 2467         return ret_val;
 2468 }
 2469 
 2470 /**
 2471  *  e1000_get_cfg_done_ich8lan - Read config done bit
 2472  *  @hw: pointer to the HW structure
 2473  *
 2474  *  Read the management control register for the config done bit for
 2475  *  completion status.  NOTE: silicon which is EEPROM-less will fail trying
 2476  *  to read the config done bit, so an error is *ONLY* logged and returns
 2477  *  E1000_SUCCESS.  If we were to return with error, EEPROM-less silicon
 2478  *  would not be able to be reset or change link.
 2479  **/
 2480 STATIC s32 e1000_get_cfg_done_ich8lan(struct e1000_hw *hw)
 2481 {
 2482         e1000_get_cfg_done_generic(hw);
 2483 
 2484         /* If EEPROM is not marked present, init the IGP 3 PHY manually */
 2485         if (((E1000_READ_REG(hw, E1000_EECD) & E1000_EECD_PRES) == 0) &&
 2486             (hw->phy.type == e1000_phy_igp_3)) {
 2487                 e1000_phy_init_script_igp3(hw);
 2488         }
 2489 
 2490         return E1000_SUCCESS;
 2491 }
 2492 
 2493 /**
 2494  *  e1000_clear_hw_cntrs_ich8lan - Clear statistical counters
 2495  *  @hw: pointer to the HW structure
 2496  *
 2497  *  Clears hardware counters specific to the silicon family and calls
 2498  *  clear_hw_cntrs_generic to clear all general purpose counters.
 2499  **/
 2500 STATIC void e1000_clear_hw_cntrs_ich8lan(struct e1000_hw *hw)
 2501 {
 2502         volatile u32 temp;
 2503 
 2504         DEBUGFUNC("e1000_clear_hw_cntrs_ich8lan");
 2505 
 2506         e1000_clear_hw_cntrs_base_generic(hw);
 2507 
 2508         temp = E1000_READ_REG(hw, E1000_ALGNERRC);
 2509         temp = E1000_READ_REG(hw, E1000_RXERRC);
 2510         temp = E1000_READ_REG(hw, E1000_TNCRS);
 2511         temp = E1000_READ_REG(hw, E1000_CEXTERR);
 2512         temp = E1000_READ_REG(hw, E1000_TSCTC);
 2513         temp = E1000_READ_REG(hw, E1000_TSCTFC);
 2514 
 2515         temp = E1000_READ_REG(hw, E1000_MGTPRC);
 2516         temp = E1000_READ_REG(hw, E1000_MGTPDC);
 2517         temp = E1000_READ_REG(hw, E1000_MGTPTC);
 2518 
 2519         temp = E1000_READ_REG(hw, E1000_IAC);
 2520         temp = E1000_READ_REG(hw, E1000_ICRXOC);
 2521 }
 2522 

Cache object: 09761840293344c62d25f596fc89be95


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.