e1000_nvm.c

Go to the documentation of this file.
00001 /*******************************************************************************
00002 
00003   Intel PRO/1000 Linux driver
00004   Copyright(c) 1999 - 2008 Intel Corporation.
00005 
00006   This program is free software; you can redistribute it and/or modify it
00007   under the terms and conditions of the GNU General Public License,
00008   version 2, as published by the Free Software Foundation.
00009 
00010   This program is distributed in the hope it will be useful, but WITHOUT
00011   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
00013   more details.
00014 
00015   You should have received a copy of the GNU General Public License along with
00016   this program; if not, write to the Free Software Foundation, Inc.,
00017   51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
00018 
00019   The full GNU General Public License is included in this distribution in
00020   the file called "COPYING".
00021 
00022   Contact Information:
00023   Linux NICS <linux.nics@intel.com>
00024   e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
00025   Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
00026 
00027 *******************************************************************************/
00028 
00029 FILE_LICENCE ( GPL2_OR_LATER );
00030 
00031 #include "e1000_api.h"
00032 
00033 static void e1000_reload_nvm_generic(struct e1000_hw *hw);
00034 
00035 /**
00036  *  e1000_init_nvm_ops_generic - Initialize NVM function pointers
00037  *  @hw: pointer to the HW structure
00038  *
00039  *  Setups up the function pointers to no-op functions
00040  **/
00041 void e1000_init_nvm_ops_generic(struct e1000_hw *hw)
00042 {
00043         struct e1000_nvm_info *nvm = &hw->nvm;
00044         DEBUGFUNC("e1000_init_nvm_ops_generic");
00045 
00046         /* Initialize function pointers */
00047         nvm->ops.init_params = e1000_null_ops_generic;
00048         nvm->ops.acquire = e1000_null_ops_generic;
00049         nvm->ops.read = e1000_null_read_nvm;
00050         nvm->ops.release = e1000_null_nvm_generic;
00051         nvm->ops.reload = e1000_reload_nvm_generic;
00052         nvm->ops.update = e1000_null_ops_generic;
00053         nvm->ops.valid_led_default = e1000_null_led_default;
00054         nvm->ops.validate = e1000_null_ops_generic;
00055         nvm->ops.write = e1000_null_write_nvm;
00056 }
00057 
00058 /**
00059  *  e1000_null_nvm_read - No-op function, return 0
00060  *  @hw: pointer to the HW structure
00061  **/
00062 s32 e1000_null_read_nvm(struct e1000_hw *hw __unused, u16 a __unused,
00063                         u16 b __unused, u16 *c __unused)
00064 {
00065         DEBUGFUNC("e1000_null_read_nvm");
00066         return E1000_SUCCESS;
00067 }
00068 
00069 /**
00070  *  e1000_null_nvm_generic - No-op function, return void
00071  *  @hw: pointer to the HW structure
00072  **/
00073 void e1000_null_nvm_generic(struct e1000_hw *hw __unused)
00074 {
00075         DEBUGFUNC("e1000_null_nvm_generic");
00076         return;
00077 }
00078 
00079 /**
00080  *  e1000_null_led_default - No-op function, return 0
00081  *  @hw: pointer to the HW structure
00082  **/
00083 s32 e1000_null_led_default(struct e1000_hw *hw __unused,
00084                            u16 *data __unused)
00085 {
00086         DEBUGFUNC("e1000_null_led_default");
00087         return E1000_SUCCESS;
00088 }
00089 
00090 /**
00091  *  e1000_null_write_nvm - No-op function, return 0
00092  *  @hw: pointer to the HW structure
00093  **/
00094 s32 e1000_null_write_nvm(struct e1000_hw *hw __unused, u16 a __unused,
00095                          u16 b __unused, u16 *c __unused)
00096 {
00097         DEBUGFUNC("e1000_null_write_nvm");
00098         return E1000_SUCCESS;
00099 }
00100 
00101 /**
00102  *  e1000_raise_eec_clk - Raise EEPROM clock
00103  *  @hw: pointer to the HW structure
00104  *  @eecd: pointer to the EEPROM
00105  *
00106  *  Enable/Raise the EEPROM clock bit.
00107  **/
00108 static void e1000_raise_eec_clk(struct e1000_hw *hw, u32 *eecd)
00109 {
00110         *eecd = *eecd | E1000_EECD_SK;
00111         E1000_WRITE_REG(hw, E1000_EECD, *eecd);
00112         E1000_WRITE_FLUSH(hw);
00113         usec_delay(hw->nvm.delay_usec);
00114 }
00115 
00116 /**
00117  *  e1000_lower_eec_clk - Lower EEPROM clock
00118  *  @hw: pointer to the HW structure
00119  *  @eecd: pointer to the EEPROM
00120  *
00121  *  Clear/Lower the EEPROM clock bit.
00122  **/
00123 static void e1000_lower_eec_clk(struct e1000_hw *hw, u32 *eecd)
00124 {
00125         *eecd = *eecd & ~E1000_EECD_SK;
00126         E1000_WRITE_REG(hw, E1000_EECD, *eecd);
00127         E1000_WRITE_FLUSH(hw);
00128         usec_delay(hw->nvm.delay_usec);
00129 }
00130 
00131 /**
00132  *  e1000_shift_out_eec_bits - Shift data bits our to the EEPROM
00133  *  @hw: pointer to the HW structure
00134  *  @data: data to send to the EEPROM
00135  *  @count: number of bits to shift out
00136  *
00137  *  We need to shift 'count' bits out to the EEPROM.  So, the value in the
00138  *  "data" parameter will be shifted out to the EEPROM one bit at a time.
00139  *  In order to do this, "data" must be broken down into bits.
00140  **/
00141 static void e1000_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count)
00142 {
00143         struct e1000_nvm_info *nvm = &hw->nvm;
00144         u32 eecd = E1000_READ_REG(hw, E1000_EECD);
00145         u32 mask;
00146 
00147         DEBUGFUNC("e1000_shift_out_eec_bits");
00148 
00149         mask = 0x01 << (count - 1);
00150         if (nvm->type == e1000_nvm_eeprom_microwire)
00151                 eecd &= ~E1000_EECD_DO;
00152         else
00153         if (nvm->type == e1000_nvm_eeprom_spi)
00154                 eecd |= E1000_EECD_DO;
00155 
00156         do {
00157                 eecd &= ~E1000_EECD_DI;
00158 
00159                 if (data & mask)
00160                         eecd |= E1000_EECD_DI;
00161 
00162                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
00163                 E1000_WRITE_FLUSH(hw);
00164 
00165                 usec_delay(nvm->delay_usec);
00166 
00167                 e1000_raise_eec_clk(hw, &eecd);
00168                 e1000_lower_eec_clk(hw, &eecd);
00169 
00170                 mask >>= 1;
00171         } while (mask);
00172 
00173         eecd &= ~E1000_EECD_DI;
00174         E1000_WRITE_REG(hw, E1000_EECD, eecd);
00175 }
00176 
00177 /**
00178  *  e1000_shift_in_eec_bits - Shift data bits in from the EEPROM
00179  *  @hw: pointer to the HW structure
00180  *  @count: number of bits to shift in
00181  *
00182  *  In order to read a register from the EEPROM, we need to shift 'count' bits
00183  *  in from the EEPROM.  Bits are "shifted in" by raising the clock input to
00184  *  the EEPROM (setting the SK bit), and then reading the value of the data out
00185  *  "DO" bit.  During this "shifting in" process the data in "DI" bit should
00186  *  always be clear.
00187  **/
00188 static u16 e1000_shift_in_eec_bits(struct e1000_hw *hw, u16 count)
00189 {
00190         u32 eecd;
00191         u32 i;
00192         u16 data;
00193 
00194         DEBUGFUNC("e1000_shift_in_eec_bits");
00195 
00196         eecd = E1000_READ_REG(hw, E1000_EECD);
00197 
00198         eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
00199         data = 0;
00200 
00201         for (i = 0; i < count; i++) {
00202                 data <<= 1;
00203                 e1000_raise_eec_clk(hw, &eecd);
00204 
00205                 eecd = E1000_READ_REG(hw, E1000_EECD);
00206 
00207                 eecd &= ~E1000_EECD_DI;
00208                 if (eecd & E1000_EECD_DO)
00209                         data |= 1;
00210 
00211                 e1000_lower_eec_clk(hw, &eecd);
00212         }
00213 
00214         return data;
00215 }
00216 
00217 /**
00218  *  e1000_poll_eerd_eewr_done - Poll for EEPROM read/write completion
00219  *  @hw: pointer to the HW structure
00220  *  @ee_reg: EEPROM flag for polling
00221  *
00222  *  Polls the EEPROM status bit for either read or write completion based
00223  *  upon the value of 'ee_reg'.
00224  **/
00225 s32 e1000_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg)
00226 {
00227         u32 attempts = 100000;
00228         u32 i, reg = 0;
00229         s32 ret_val = -E1000_ERR_NVM;
00230 
00231         DEBUGFUNC("e1000_poll_eerd_eewr_done");
00232 
00233         for (i = 0; i < attempts; i++) {
00234                 if (ee_reg == E1000_NVM_POLL_READ)
00235                         reg = E1000_READ_REG(hw, E1000_EERD);
00236                 else
00237                         reg = E1000_READ_REG(hw, E1000_EEWR);
00238 
00239                 if (reg & E1000_NVM_RW_REG_DONE) {
00240                         ret_val = E1000_SUCCESS;
00241                         break;
00242                 }
00243 
00244                 usec_delay(5);
00245         }
00246 
00247         return ret_val;
00248 }
00249 
00250 /**
00251  *  e1000_acquire_nvm_generic - Generic request for access to EEPROM
00252  *  @hw: pointer to the HW structure
00253  *
00254  *  Set the EEPROM access request bit and wait for EEPROM access grant bit.
00255  *  Return successful if access grant bit set, else clear the request for
00256  *  EEPROM access and return -E1000_ERR_NVM (-1).
00257  **/
00258 s32 e1000_acquire_nvm_generic(struct e1000_hw *hw)
00259 {
00260         u32 eecd = E1000_READ_REG(hw, E1000_EECD);
00261         s32 timeout = E1000_NVM_GRANT_ATTEMPTS;
00262         s32 ret_val = E1000_SUCCESS;
00263 
00264         DEBUGFUNC("e1000_acquire_nvm_generic");
00265 
00266         E1000_WRITE_REG(hw, E1000_EECD, eecd | E1000_EECD_REQ);
00267         eecd = E1000_READ_REG(hw, E1000_EECD);
00268 
00269         while (timeout) {
00270                 if (eecd & E1000_EECD_GNT)
00271                         break;
00272                 usec_delay(5);
00273                 eecd = E1000_READ_REG(hw, E1000_EECD);
00274                 timeout--;
00275         }
00276 
00277         if (!timeout) {
00278                 eecd &= ~E1000_EECD_REQ;
00279                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
00280                 DEBUGOUT("Could not acquire NVM grant\n");
00281                 ret_val = -E1000_ERR_NVM;
00282         }
00283 
00284         return ret_val;
00285 }
00286 
00287 /**
00288  *  e1000_standby_nvm - Return EEPROM to standby state
00289  *  @hw: pointer to the HW structure
00290  *
00291  *  Return the EEPROM to a standby state.
00292  **/
00293 static void e1000_standby_nvm(struct e1000_hw *hw)
00294 {
00295         struct e1000_nvm_info *nvm = &hw->nvm;
00296         u32 eecd = E1000_READ_REG(hw, E1000_EECD);
00297 
00298         DEBUGFUNC("e1000_standby_nvm");
00299 
00300         if (nvm->type == e1000_nvm_eeprom_microwire) {
00301                 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
00302                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
00303                 E1000_WRITE_FLUSH(hw);
00304                 usec_delay(nvm->delay_usec);
00305 
00306                 e1000_raise_eec_clk(hw, &eecd);
00307 
00308                 /* Select EEPROM */
00309                 eecd |= E1000_EECD_CS;
00310                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
00311                 E1000_WRITE_FLUSH(hw);
00312                 usec_delay(nvm->delay_usec);
00313 
00314                 e1000_lower_eec_clk(hw, &eecd);
00315         } else
00316         if (nvm->type == e1000_nvm_eeprom_spi) {
00317                 /* Toggle CS to flush commands */
00318                 eecd |= E1000_EECD_CS;
00319                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
00320                 E1000_WRITE_FLUSH(hw);
00321                 usec_delay(nvm->delay_usec);
00322                 eecd &= ~E1000_EECD_CS;
00323                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
00324                 E1000_WRITE_FLUSH(hw);
00325                 usec_delay(nvm->delay_usec);
00326         }
00327 }
00328 
00329 /**
00330  *  e1000_stop_nvm - Terminate EEPROM command
00331  *  @hw: pointer to the HW structure
00332  *
00333  *  Terminates the current command by inverting the EEPROM's chip select pin.
00334  **/
00335 void e1000_stop_nvm(struct e1000_hw *hw)
00336 {
00337         u32 eecd;
00338 
00339         DEBUGFUNC("e1000_stop_nvm");
00340 
00341         eecd = E1000_READ_REG(hw, E1000_EECD);
00342         if (hw->nvm.type == e1000_nvm_eeprom_spi) {
00343                 /* Pull CS high */
00344                 eecd |= E1000_EECD_CS;
00345                 e1000_lower_eec_clk(hw, &eecd);
00346         } else if (hw->nvm.type == e1000_nvm_eeprom_microwire) {
00347                 /* CS on Microwire is active-high */
00348                 eecd &= ~(E1000_EECD_CS | E1000_EECD_DI);
00349                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
00350                 e1000_raise_eec_clk(hw, &eecd);
00351                 e1000_lower_eec_clk(hw, &eecd);
00352         }
00353 }
00354 
00355 /**
00356  *  e1000_release_nvm_generic - Release exclusive access to EEPROM
00357  *  @hw: pointer to the HW structure
00358  *
00359  *  Stop any current commands to the EEPROM and clear the EEPROM request bit.
00360  **/
00361 void e1000_release_nvm_generic(struct e1000_hw *hw)
00362 {
00363         u32 eecd;
00364 
00365         DEBUGFUNC("e1000_release_nvm_generic");
00366 
00367         e1000_stop_nvm(hw);
00368 
00369         eecd = E1000_READ_REG(hw, E1000_EECD);
00370         eecd &= ~E1000_EECD_REQ;
00371         E1000_WRITE_REG(hw, E1000_EECD, eecd);
00372 }
00373 
00374 /**
00375  *  e1000_ready_nvm_eeprom - Prepares EEPROM for read/write
00376  *  @hw: pointer to the HW structure
00377  *
00378  *  Setups the EEPROM for reading and writing.
00379  **/
00380 static s32 e1000_ready_nvm_eeprom(struct e1000_hw *hw)
00381 {
00382         struct e1000_nvm_info *nvm = &hw->nvm;
00383         u32 eecd = E1000_READ_REG(hw, E1000_EECD);
00384         s32 ret_val = E1000_SUCCESS;
00385         u16 timeout = 0;
00386         u8 spi_stat_reg;
00387 
00388         DEBUGFUNC("e1000_ready_nvm_eeprom");
00389 
00390         if (nvm->type == e1000_nvm_eeprom_microwire) {
00391                 /* Clear SK and DI */
00392                 eecd &= ~(E1000_EECD_DI | E1000_EECD_SK);
00393                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
00394                 /* Set CS */
00395                 eecd |= E1000_EECD_CS;
00396                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
00397         } else
00398         if (nvm->type == e1000_nvm_eeprom_spi) {
00399                 /* Clear SK and CS */
00400                 eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
00401                 E1000_WRITE_REG(hw, E1000_EECD, eecd);
00402                 usec_delay(1);
00403                 timeout = NVM_MAX_RETRY_SPI;
00404 
00405                 /*
00406                  * Read "Status Register" repeatedly until the LSB is cleared.
00407                  * The EEPROM will signal that the command has been completed
00408                  * by clearing bit 0 of the internal status register.  If it's
00409                  * not cleared within 'timeout', then error out.
00410                  */
00411                 while (timeout) {
00412                         e1000_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI,
00413                                                  hw->nvm.opcode_bits);
00414                         spi_stat_reg = (u8)e1000_shift_in_eec_bits(hw, 8);
00415                         if (!(spi_stat_reg & NVM_STATUS_RDY_SPI))
00416                                 break;
00417 
00418                         usec_delay(5);
00419                         e1000_standby_nvm(hw);
00420                         timeout--;
00421                 }
00422 
00423                 if (!timeout) {
00424                         DEBUGOUT("SPI NVM Status error\n");
00425                         ret_val = -E1000_ERR_NVM;
00426                         goto out;
00427                 }
00428         }
00429 
00430 out:
00431         return ret_val;
00432 }
00433 
00434 /**
00435  *  e1000_read_nvm_spi - Read EEPROM's using SPI
00436  *  @hw: pointer to the HW structure
00437  *  @offset: offset of word in the EEPROM to read
00438  *  @words: number of words to read
00439  *  @data: word read from the EEPROM
00440  *
00441  *  Reads a 16 bit word from the EEPROM.
00442  **/
00443 s32 e1000_read_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
00444 {
00445         struct e1000_nvm_info *nvm = &hw->nvm;
00446         u32 i = 0;
00447         s32 ret_val;
00448         u16 word_in;
00449         u8 read_opcode = NVM_READ_OPCODE_SPI;
00450 
00451         DEBUGFUNC("e1000_read_nvm_spi");
00452 
00453         /*
00454          * A check for invalid values:  offset too large, too many words,
00455          * and not enough words.
00456          */
00457         if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
00458             (words == 0)) {
00459                 DEBUGOUT("nvm parameter(s) out of bounds\n");
00460                 ret_val = -E1000_ERR_NVM;
00461                 goto out;
00462         }
00463 
00464         ret_val = nvm->ops.acquire(hw);
00465         if (ret_val)
00466                 goto out;
00467 
00468         ret_val = e1000_ready_nvm_eeprom(hw);
00469         if (ret_val)
00470                 goto release;
00471 
00472         e1000_standby_nvm(hw);
00473 
00474         if ((nvm->address_bits == 8) && (offset >= 128))
00475                 read_opcode |= NVM_A8_OPCODE_SPI;
00476 
00477         /* Send the READ command (opcode + addr) */
00478         e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits);
00479         e1000_shift_out_eec_bits(hw, (u16)(offset*2), nvm->address_bits);
00480 
00481         /*
00482          * Read the data.  SPI NVMs increment the address with each byte
00483          * read and will roll over if reading beyond the end.  This allows
00484          * us to read the whole NVM from any offset
00485          */
00486         for (i = 0; i < words; i++) {
00487                 word_in = e1000_shift_in_eec_bits(hw, 16);
00488                 data[i] = (word_in >> 8) | (word_in << 8);
00489         }
00490 
00491 release:
00492         nvm->ops.release(hw);
00493 
00494 out:
00495         return ret_val;
00496 }
00497 
00498 /**
00499  *  e1000_read_nvm_microwire - Reads EEPROM's using microwire
00500  *  @hw: pointer to the HW structure
00501  *  @offset: offset of word in the EEPROM to read
00502  *  @words: number of words to read
00503  *  @data: word read from the EEPROM
00504  *
00505  *  Reads a 16 bit word from the EEPROM.
00506  **/
00507 s32 e1000_read_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words,
00508                              u16 *data)
00509 {
00510         struct e1000_nvm_info *nvm = &hw->nvm;
00511         u32 i = 0;
00512         s32 ret_val;
00513         u8 read_opcode = NVM_READ_OPCODE_MICROWIRE;
00514 
00515         DEBUGFUNC("e1000_read_nvm_microwire");
00516 
00517         /*
00518          * A check for invalid values:  offset too large, too many words,
00519          * and not enough words.
00520          */
00521         if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
00522             (words == 0)) {
00523                 DEBUGOUT("nvm parameter(s) out of bounds\n");
00524                 ret_val = -E1000_ERR_NVM;
00525                 goto out;
00526         }
00527 
00528         ret_val = nvm->ops.acquire(hw);
00529         if (ret_val)
00530                 goto out;
00531 
00532         ret_val = e1000_ready_nvm_eeprom(hw);
00533         if (ret_val)
00534                 goto release;
00535 
00536         for (i = 0; i < words; i++) {
00537                 /* Send the READ command (opcode + addr) */
00538                 e1000_shift_out_eec_bits(hw, read_opcode, nvm->opcode_bits);
00539                 e1000_shift_out_eec_bits(hw, (u16)(offset + i),
00540                                         nvm->address_bits);
00541 
00542                 /*
00543                  * Read the data.  For microwire, each word requires the
00544                  * overhead of setup and tear-down.
00545                  */
00546                 data[i] = e1000_shift_in_eec_bits(hw, 16);
00547                 e1000_standby_nvm(hw);
00548         }
00549 
00550 release:
00551         nvm->ops.release(hw);
00552 
00553 out:
00554         return ret_val;
00555 }
00556 
00557 /**
00558  *  e1000_read_nvm_eerd - Reads EEPROM using EERD register
00559  *  @hw: pointer to the HW structure
00560  *  @offset: offset of word in the EEPROM to read
00561  *  @words: number of words to read
00562  *  @data: word read from the EEPROM
00563  *
00564  *  Reads a 16 bit word from the EEPROM using the EERD register.
00565  **/
00566 s32 e1000_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
00567 {
00568         struct e1000_nvm_info *nvm = &hw->nvm;
00569         u32 i, eerd = 0;
00570         s32 ret_val = E1000_SUCCESS;
00571 
00572         DEBUGFUNC("e1000_read_nvm_eerd");
00573 
00574         /*
00575          * A check for invalid values:  offset too large, too many words,
00576          * too many words for the offset, and not enough words.
00577          */
00578         if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
00579             (words == 0)) {
00580                 DEBUGOUT("nvm parameter(s) out of bounds\n");
00581                 ret_val = -E1000_ERR_NVM;
00582                 goto out;
00583         }
00584 
00585         for (i = 0; i < words; i++) {
00586                 eerd = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) +
00587                        E1000_NVM_RW_REG_START;
00588 
00589                 E1000_WRITE_REG(hw, E1000_EERD, eerd);
00590                 ret_val = e1000_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ);
00591                 if (ret_val)
00592                         break;
00593 
00594                 data[i] = (E1000_READ_REG(hw, E1000_EERD) >>
00595                            E1000_NVM_RW_REG_DATA);
00596         }
00597 
00598 out:
00599         return ret_val;
00600 }
00601 
00602 /**
00603  *  e1000_write_nvm_spi - Write to EEPROM using SPI
00604  *  @hw: pointer to the HW structure
00605  *  @offset: offset within the EEPROM to be written to
00606  *  @words: number of words to write
00607  *  @data: 16 bit word(s) to be written to the EEPROM
00608  *
00609  *  Writes data to EEPROM at offset using SPI interface.
00610  *
00611  *  If e1000_update_nvm_checksum is not called after this function , the
00612  *  EEPROM will most likely contain an invalid checksum.
00613  **/
00614 s32 e1000_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
00615 {
00616         struct e1000_nvm_info *nvm = &hw->nvm;
00617         s32 ret_val;
00618         u16 widx = 0;
00619 
00620         DEBUGFUNC("e1000_write_nvm_spi");
00621 
00622         /*
00623          * A check for invalid values:  offset too large, too many words,
00624          * and not enough words.
00625          */
00626         if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
00627             (words == 0)) {
00628                 DEBUGOUT("nvm parameter(s) out of bounds\n");
00629                 ret_val = -E1000_ERR_NVM;
00630                 goto out;
00631         }
00632 
00633         ret_val = nvm->ops.acquire(hw);
00634         if (ret_val)
00635                 goto out;
00636 
00637         while (widx < words) {
00638                 u8 write_opcode = NVM_WRITE_OPCODE_SPI;
00639 
00640                 ret_val = e1000_ready_nvm_eeprom(hw);
00641                 if (ret_val)
00642                         goto release;
00643 
00644                 e1000_standby_nvm(hw);
00645 
00646                 /* Send the WRITE ENABLE command (8 bit opcode) */
00647                 e1000_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI,
00648                                          nvm->opcode_bits);
00649 
00650                 e1000_standby_nvm(hw);
00651 
00652                 /*
00653                  * Some SPI eeproms use the 8th address bit embedded in the
00654                  * opcode
00655                  */
00656                 if ((nvm->address_bits == 8) && (offset >= 128))
00657                         write_opcode |= NVM_A8_OPCODE_SPI;
00658 
00659                 /* Send the Write command (8-bit opcode + addr) */
00660                 e1000_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits);
00661                 e1000_shift_out_eec_bits(hw, (u16)((offset + widx) * 2),
00662                                          nvm->address_bits);
00663 
00664                 /* Loop to allow for up to whole page write of eeprom */
00665                 while (widx < words) {
00666                         u16 word_out = data[widx];
00667                         word_out = (word_out >> 8) | (word_out << 8);
00668                         e1000_shift_out_eec_bits(hw, word_out, 16);
00669                         widx++;
00670 
00671                         if ((((offset + widx) * 2) % nvm->page_size) == 0) {
00672                                 e1000_standby_nvm(hw);
00673                                 break;
00674                         }
00675                 }
00676         }
00677 
00678         msec_delay(10);
00679 release:
00680         nvm->ops.release(hw);
00681 
00682 out:
00683         return ret_val;
00684 }
00685 
00686 /**
00687  *  e1000_write_nvm_microwire - Writes EEPROM using microwire
00688  *  @hw: pointer to the HW structure
00689  *  @offset: offset within the EEPROM to be written to
00690  *  @words: number of words to write
00691  *  @data: 16 bit word(s) to be written to the EEPROM
00692  *
00693  *  Writes data to EEPROM at offset using microwire interface.
00694  *
00695  *  If e1000_update_nvm_checksum is not called after this function , the
00696  *  EEPROM will most likely contain an invalid checksum.
00697  **/
00698 s32 e1000_write_nvm_microwire(struct e1000_hw *hw, u16 offset, u16 words,
00699                               u16 *data)
00700 {
00701         struct e1000_nvm_info *nvm = &hw->nvm;
00702         s32  ret_val;
00703         u32 eecd;
00704         u16 words_written = 0;
00705         u16 widx = 0;
00706 
00707         DEBUGFUNC("e1000_write_nvm_microwire");
00708 
00709         /*
00710          * A check for invalid values:  offset too large, too many words,
00711          * and not enough words.
00712          */
00713         if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
00714             (words == 0)) {
00715                 DEBUGOUT("nvm parameter(s) out of bounds\n");
00716                 ret_val = -E1000_ERR_NVM;
00717                 goto out;
00718         }
00719 
00720         ret_val = nvm->ops.acquire(hw);
00721         if (ret_val)
00722                 goto out;
00723 
00724         ret_val = e1000_ready_nvm_eeprom(hw);
00725         if (ret_val)
00726                 goto release;
00727 
00728         e1000_shift_out_eec_bits(hw, NVM_EWEN_OPCODE_MICROWIRE,
00729                                  (u16)(nvm->opcode_bits + 2));
00730 
00731         e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2));
00732 
00733         e1000_standby_nvm(hw);
00734 
00735         while (words_written < words) {
00736                 e1000_shift_out_eec_bits(hw, NVM_WRITE_OPCODE_MICROWIRE,
00737                                          nvm->opcode_bits);
00738 
00739                 e1000_shift_out_eec_bits(hw, (u16)(offset + words_written),
00740                                          nvm->address_bits);
00741 
00742                 e1000_shift_out_eec_bits(hw, data[words_written], 16);
00743 
00744                 e1000_standby_nvm(hw);
00745 
00746                 for (widx = 0; widx < 200; widx++) {
00747                         eecd = E1000_READ_REG(hw, E1000_EECD);
00748                         if (eecd & E1000_EECD_DO)
00749                                 break;
00750                         usec_delay(50);
00751                 }
00752 
00753                 if (widx == 200) {
00754                         DEBUGOUT("NVM Write did not complete\n");
00755                         ret_val = -E1000_ERR_NVM;
00756                         goto release;
00757                 }
00758 
00759                 e1000_standby_nvm(hw);
00760 
00761                 words_written++;
00762         }
00763 
00764         e1000_shift_out_eec_bits(hw, NVM_EWDS_OPCODE_MICROWIRE,
00765                                  (u16)(nvm->opcode_bits + 2));
00766 
00767         e1000_shift_out_eec_bits(hw, 0, (u16)(nvm->address_bits - 2));
00768 
00769 release:
00770         nvm->ops.release(hw);
00771 
00772 out:
00773         return ret_val;
00774 }
00775 
00776 /**
00777  *  e1000_read_pba_num_generic - Read device part number
00778  *  @hw: pointer to the HW structure
00779  *  @pba_num: pointer to device part number
00780  *
00781  *  Reads the product board assembly (PBA) number from the EEPROM and stores
00782  *  the value in pba_num.
00783  **/
00784 s32 e1000_read_pba_num_generic(struct e1000_hw *hw, u32 *pba_num)
00785 {
00786         s32  ret_val;
00787         u16 nvm_data;
00788 
00789         DEBUGFUNC("e1000_read_pba_num_generic");
00790 
00791         ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
00792         if (ret_val) {
00793                 DEBUGOUT("NVM Read Error\n");
00794                 goto out;
00795         }
00796         *pba_num = (u32)(nvm_data << 16);
00797 
00798         ret_val = hw->nvm.ops.read(hw, NVM_PBA_OFFSET_1, 1, &nvm_data);
00799         if (ret_val) {
00800                 DEBUGOUT("NVM Read Error\n");
00801                 goto out;
00802         }
00803         *pba_num |= nvm_data;
00804 
00805 out:
00806         return ret_val;
00807 }
00808 
00809 /**
00810  *  e1000_read_mac_addr_generic - Read device MAC address
00811  *  @hw: pointer to the HW structure
00812  *
00813  *  Reads the device MAC address from the EEPROM and stores the value.
00814  *  Since devices with two ports use the same EEPROM, we increment the
00815  *  last bit in the MAC address for the second port.
00816  **/
00817 s32 e1000_read_mac_addr_generic(struct e1000_hw *hw)
00818 {
00819         u32 rar_high;
00820         u32 rar_low;
00821         u16 i;
00822 
00823         rar_high = E1000_READ_REG(hw, E1000_RAH(0));
00824         rar_low = E1000_READ_REG(hw, E1000_RAL(0));
00825 
00826         for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++)
00827                 hw->mac.perm_addr[i] = (u8)(rar_low >> (i*8));
00828 
00829         for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++)
00830                 hw->mac.perm_addr[i+4] = (u8)(rar_high >> (i*8));
00831 
00832         for (i = 0; i < ETH_ADDR_LEN; i++)
00833                 hw->mac.addr[i] = hw->mac.perm_addr[i];
00834 
00835         return E1000_SUCCESS;
00836 }
00837 
00838 /**
00839  *  e1000_validate_nvm_checksum_generic - Validate EEPROM checksum
00840  *  @hw: pointer to the HW structure
00841  *
00842  *  Calculates the EEPROM checksum by reading/adding each word of the EEPROM
00843  *  and then verifies that the sum of the EEPROM is equal to 0xBABA.
00844  **/
00845 s32 e1000_validate_nvm_checksum_generic(struct e1000_hw *hw)
00846 {
00847         s32 ret_val = E1000_SUCCESS;
00848         u16 checksum = 0;
00849         u16 i, nvm_data;
00850 
00851         DEBUGFUNC("e1000_validate_nvm_checksum_generic");
00852 
00853         for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
00854                 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
00855                 if (ret_val) {
00856                         DEBUGOUT("NVM Read Error\n");
00857                         goto out;
00858                 }
00859                 checksum += nvm_data;
00860         }
00861 
00862         if (checksum != (u16) NVM_SUM) {
00863                 DEBUGOUT("NVM Checksum Invalid\n");
00864                 ret_val = -E1000_ERR_NVM;
00865                 goto out;
00866         }
00867 
00868 out:
00869         return ret_val;
00870 }
00871 
00872 /**
00873  *  e1000_update_nvm_checksum_generic - Update EEPROM checksum
00874  *  @hw: pointer to the HW structure
00875  *
00876  *  Updates the EEPROM checksum by reading/adding each word of the EEPROM
00877  *  up to the checksum.  Then calculates the EEPROM checksum and writes the
00878  *  value to the EEPROM.
00879  **/
00880 s32 e1000_update_nvm_checksum_generic(struct e1000_hw *hw)
00881 {
00882         s32  ret_val;
00883         u16 checksum = 0;
00884         u16 i, nvm_data;
00885 
00886         DEBUGFUNC("e1000_update_nvm_checksum");
00887 
00888         for (i = 0; i < NVM_CHECKSUM_REG; i++) {
00889                 ret_val = hw->nvm.ops.read(hw, i, 1, &nvm_data);
00890                 if (ret_val) {
00891                         DEBUGOUT("NVM Read Error while updating checksum.\n");
00892                         goto out;
00893                 }
00894                 checksum += nvm_data;
00895         }
00896         checksum = (u16) NVM_SUM - checksum;
00897         ret_val = hw->nvm.ops.write(hw, NVM_CHECKSUM_REG, 1, &checksum);
00898         if (ret_val)
00899                 DEBUGOUT("NVM Write Error while updating checksum.\n");
00900 
00901 out:
00902         return ret_val;
00903 }
00904 
00905 /**
00906  *  e1000_reload_nvm_generic - Reloads EEPROM
00907  *  @hw: pointer to the HW structure
00908  *
00909  *  Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the
00910  *  extended control register.
00911  **/
00912 static void e1000_reload_nvm_generic(struct e1000_hw *hw)
00913 {
00914         u32 ctrl_ext;
00915 
00916         DEBUGFUNC("e1000_reload_nvm_generic");
00917 
00918         usec_delay(10);
00919         ctrl_ext = E1000_READ_REG(hw, E1000_CTRL_EXT);
00920         ctrl_ext |= E1000_CTRL_EXT_EE_RST;
00921         E1000_WRITE_REG(hw, E1000_CTRL_EXT, ctrl_ext);
00922         E1000_WRITE_FLUSH(hw);
00923 }

Generated on Tue Apr 6 20:00:57 2010 for gPXE by  doxygen 1.5.7.1