1
/*******************************************************************************
3
Intel PRO/1000 Linux driver
4
Copyright(c) 1999 - 2009 Intel Corporation.
6
This program is free software; you can redistribute it and/or modify it
7
under the terms and conditions of the GNU General Public License,
8
version 2, as published by the Free Software Foundation.
10
This program is distributed in the hope it will be useful, but WITHOUT
11
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
You should have received a copy of the GNU General Public License along with
16
this program; if not, write to the Free Software Foundation, Inc.,
17
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19
The full GNU General Public License is included in this distribution in
20
the file called "COPYING".
23
Linux NICS <linux.nics@intel.com>
24
e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25
Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27
*******************************************************************************/
29
FILE_LICENCE ( GPL2_OR_LATER );
33
static void e1000e_stop_nvm(struct e1000_hw *hw);
34
static void e1000e_reload_nvm(struct e1000_hw *hw);
37
* e1000e_init_nvm_ops_generic - Initialize NVM function pointers
38
* @hw: pointer to the HW structure
40
* Setups up the function pointers to no-op functions
42
void e1000e_init_nvm_ops_generic(struct e1000_hw *hw)
44
struct e1000_nvm_info *nvm = &hw->nvm;
45
/* Initialize function pointers */
46
nvm->ops.reload = e1000e_reload_nvm;
50
* e1000e_raise_eec_clk - Raise EEPROM clock
51
* @hw: pointer to the HW structure
52
* @eecd: pointer to the EEPROM
54
* Enable/Raise the EEPROM clock bit.
56
static void e1000e_raise_eec_clk(struct e1000_hw *hw, u32 *eecd)
58
*eecd = *eecd | E1000_EECD_SK;
61
udelay(hw->nvm.delay_usec);
65
* e1000e_lower_eec_clk - Lower EEPROM clock
66
* @hw: pointer to the HW structure
67
* @eecd: pointer to the EEPROM
69
* Clear/Lower the EEPROM clock bit.
71
static void e1000e_lower_eec_clk(struct e1000_hw *hw, u32 *eecd)
73
*eecd = *eecd & ~E1000_EECD_SK;
76
udelay(hw->nvm.delay_usec);
80
* e1000e_shift_out_eec_bits - Shift data bits our to the EEPROM
81
* @hw: pointer to the HW structure
82
* @data: data to send to the EEPROM
83
* @count: number of bits to shift out
85
* We need to shift 'count' bits out to the EEPROM. So, the value in the
86
* "data" parameter will be shifted out to the EEPROM one bit at a time.
87
* In order to do this, "data" must be broken down into bits.
89
static void e1000e_shift_out_eec_bits(struct e1000_hw *hw, u16 data, u16 count)
91
struct e1000_nvm_info *nvm = &hw->nvm;
92
u32 eecd = er32(EECD);
95
mask = 0x01 << (count - 1);
96
if (nvm->type == e1000_nvm_eeprom_spi)
97
eecd |= E1000_EECD_DO;
100
eecd &= ~E1000_EECD_DI;
103
eecd |= E1000_EECD_DI;
108
udelay(nvm->delay_usec);
110
e1000e_raise_eec_clk(hw, &eecd);
111
e1000e_lower_eec_clk(hw, &eecd);
116
eecd &= ~E1000_EECD_DI;
121
* e1000e_shift_in_eec_bits - Shift data bits in from the EEPROM
122
* @hw: pointer to the HW structure
123
* @count: number of bits to shift in
125
* In order to read a register from the EEPROM, we need to shift 'count' bits
126
* in from the EEPROM. Bits are "shifted in" by raising the clock input to
127
* the EEPROM (setting the SK bit), and then reading the value of the data out
128
* "DO" bit. During this "shifting in" process the data in "DI" bit should
131
static u16 e1000e_shift_in_eec_bits(struct e1000_hw *hw, u16 count)
138
eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
141
for (i = 0; i < count; i++) {
143
e1000e_raise_eec_clk(hw, &eecd);
147
eecd &= ~E1000_EECD_DI;
148
if (eecd & E1000_EECD_DO)
151
e1000e_lower_eec_clk(hw, &eecd);
158
* e1000e_poll_eerd_eewr_done - Poll for EEPROM read/write completion
159
* @hw: pointer to the HW structure
160
* @ee_reg: EEPROM flag for polling
162
* Polls the EEPROM status bit for either read or write completion based
163
* upon the value of 'ee_reg'.
165
s32 e1000e_poll_eerd_eewr_done(struct e1000_hw *hw, int ee_reg)
167
u32 attempts = 100000;
169
s32 ret_val = -E1000_ERR_NVM;
171
for (i = 0; i < attempts; i++) {
172
if (ee_reg == E1000_NVM_POLL_READ)
177
if (reg & E1000_NVM_RW_REG_DONE) {
178
ret_val = E1000_SUCCESS;
189
* e1000e_acquire_nvm - Generic request for access to EEPROM
190
* @hw: pointer to the HW structure
192
* Set the EEPROM access request bit and wait for EEPROM access grant bit.
193
* Return successful if access grant bit set, else clear the request for
194
* EEPROM access and return -E1000_ERR_NVM (-1).
196
s32 e1000e_acquire_nvm(struct e1000_hw *hw)
198
u32 eecd = er32(EECD);
199
s32 timeout = E1000_NVM_GRANT_ATTEMPTS;
200
s32 ret_val = E1000_SUCCESS;
202
ew32(EECD, eecd | E1000_EECD_REQ);
205
if (eecd & E1000_EECD_GNT)
213
eecd &= ~E1000_EECD_REQ;
215
e_dbg("Could not acquire NVM grant\n");
216
ret_val = -E1000_ERR_NVM;
223
* e1000e_standby_nvm - Return EEPROM to standby state
224
* @hw: pointer to the HW structure
226
* Return the EEPROM to a standby state.
228
static void e1000e_standby_nvm(struct e1000_hw *hw)
230
struct e1000_nvm_info *nvm = &hw->nvm;
231
u32 eecd = er32(EECD);
233
if (nvm->type == e1000_nvm_eeprom_spi) {
234
/* Toggle CS to flush commands */
235
eecd |= E1000_EECD_CS;
238
udelay(nvm->delay_usec);
239
eecd &= ~E1000_EECD_CS;
242
udelay(nvm->delay_usec);
247
* e1000e_stop_nvm - Terminate EEPROM command
248
* @hw: pointer to the HW structure
250
* Terminates the current command by inverting the EEPROM's chip select pin.
252
static void e1000e_stop_nvm(struct e1000_hw *hw)
257
if (hw->nvm.type == e1000_nvm_eeprom_spi) {
259
eecd |= E1000_EECD_CS;
260
e1000e_lower_eec_clk(hw, &eecd);
265
* e1000e_release_nvm - Release exclusive access to EEPROM
266
* @hw: pointer to the HW structure
268
* Stop any current commands to the EEPROM and clear the EEPROM request bit.
270
void e1000e_release_nvm(struct e1000_hw *hw)
277
eecd &= ~E1000_EECD_REQ;
282
* e1000e_ready_nvm_eeprom - Prepares EEPROM for read/write
283
* @hw: pointer to the HW structure
285
* Setups the EEPROM for reading and writing.
287
static s32 e1000e_ready_nvm_eeprom(struct e1000_hw *hw)
289
struct e1000_nvm_info *nvm = &hw->nvm;
290
u32 eecd = er32(EECD);
291
s32 ret_val = E1000_SUCCESS;
295
if (nvm->type == e1000_nvm_eeprom_spi) {
296
/* Clear SK and CS */
297
eecd &= ~(E1000_EECD_CS | E1000_EECD_SK);
300
timeout = NVM_MAX_RETRY_SPI;
303
* Read "Status Register" repeatedly until the LSB is cleared.
304
* The EEPROM will signal that the command has been completed
305
* by clearing bit 0 of the internal status register. If it's
306
* not cleared within 'timeout', then error out.
309
e1000e_shift_out_eec_bits(hw, NVM_RDSR_OPCODE_SPI,
310
hw->nvm.opcode_bits);
311
spi_stat_reg = (u8)e1000e_shift_in_eec_bits(hw, 8);
312
if (!(spi_stat_reg & NVM_STATUS_RDY_SPI))
316
e1000e_standby_nvm(hw);
321
e_dbg("SPI NVM Status error\n");
322
ret_val = -E1000_ERR_NVM;
332
* e1000e_read_nvm_eerd - Reads EEPROM using EERD register
333
* @hw: pointer to the HW structure
334
* @offset: offset of word in the EEPROM to read
335
* @words: number of words to read
336
* @data: word read from the EEPROM
338
* Reads a 16 bit word from the EEPROM using the EERD register.
340
s32 e1000e_read_nvm_eerd(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
342
struct e1000_nvm_info *nvm = &hw->nvm;
344
s32 ret_val = E1000_SUCCESS;
347
* A check for invalid values: offset too large, too many words,
348
* too many words for the offset, and not enough words.
350
if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
352
e_dbg("nvm parameter(s) out of bounds\n");
353
ret_val = -E1000_ERR_NVM;
357
for (i = 0; i < words; i++) {
358
eerd = ((offset+i) << E1000_NVM_RW_ADDR_SHIFT) +
359
E1000_NVM_RW_REG_START;
362
ret_val = e1000e_poll_eerd_eewr_done(hw, E1000_NVM_POLL_READ);
366
data[i] = (er32(EERD) >>
367
E1000_NVM_RW_REG_DATA);
375
* e1000e_write_nvm_spi - Write to EEPROM using SPI
376
* @hw: pointer to the HW structure
377
* @offset: offset within the EEPROM to be written to
378
* @words: number of words to write
379
* @data: 16 bit word(s) to be written to the EEPROM
381
* Writes data to EEPROM at offset using SPI interface.
383
* If e1000e_update_nvm_checksum is not called after this function , the
384
* EEPROM will most likely contain an invalid checksum.
386
s32 e1000e_write_nvm_spi(struct e1000_hw *hw, u16 offset, u16 words, u16 *data)
388
struct e1000_nvm_info *nvm = &hw->nvm;
393
* A check for invalid values: offset too large, too many words,
394
* and not enough words.
396
if ((offset >= nvm->word_size) || (words > (nvm->word_size - offset)) ||
398
e_dbg("nvm parameter(s) out of bounds\n");
399
ret_val = -E1000_ERR_NVM;
403
ret_val = nvm->ops.acquire(hw);
407
while (widx < words) {
408
u8 write_opcode = NVM_WRITE_OPCODE_SPI;
410
ret_val = e1000e_ready_nvm_eeprom(hw);
414
e1000e_standby_nvm(hw);
416
/* Send the WRITE ENABLE command (8 bit opcode) */
417
e1000e_shift_out_eec_bits(hw, NVM_WREN_OPCODE_SPI,
420
e1000e_standby_nvm(hw);
423
* Some SPI eeproms use the 8th address bit embedded in the
426
if ((nvm->address_bits == 8) && (offset >= 128))
427
write_opcode |= NVM_A8_OPCODE_SPI;
429
/* Send the Write command (8-bit opcode + addr) */
430
e1000e_shift_out_eec_bits(hw, write_opcode, nvm->opcode_bits);
431
e1000e_shift_out_eec_bits(hw, (u16)((offset + widx) * 2),
434
/* Loop to allow for up to whole page write of eeprom */
435
while (widx < words) {
436
u16 word_out = data[widx];
437
word_out = (word_out >> 8) | (word_out << 8);
438
e1000e_shift_out_eec_bits(hw, word_out, 16);
441
if ((((offset + widx) * 2) % nvm->page_size) == 0) {
442
e1000e_standby_nvm(hw);
450
nvm->ops.release(hw);
457
* e1000e_read_pba_num - Read device part number
458
* @hw: pointer to the HW structure
459
* @pba_num: pointer to device part number
461
* Reads the product board assembly (PBA) number from the EEPROM and stores
462
* the value in pba_num.
464
s32 e1000e_read_pba_num(struct e1000_hw *hw, u32 *pba_num)
469
ret_val = e1000e_read_nvm(hw, NVM_PBA_OFFSET_0, 1, &nvm_data);
471
e_dbg("NVM Read Error\n");
474
*pba_num = (u32)(nvm_data << 16);
476
ret_val = e1000e_read_nvm(hw, NVM_PBA_OFFSET_1, 1, &nvm_data);
478
e_dbg("NVM Read Error\n");
481
*pba_num |= nvm_data;
488
* e1000e_read_mac_addr_generic - Read device MAC address
489
* @hw: pointer to the HW structure
491
* Reads the device MAC address from the EEPROM and stores the value.
492
* Since devices with two ports use the same EEPROM, we increment the
493
* last bit in the MAC address for the second port.
495
s32 e1000e_read_mac_addr_generic(struct e1000_hw *hw)
501
rar_high = er32(RAH(0));
502
rar_low = er32(RAL(0));
504
for (i = 0; i < E1000_RAL_MAC_ADDR_LEN; i++)
505
hw->mac.perm_addr[i] = (u8)(rar_low >> (i*8));
507
for (i = 0; i < E1000_RAH_MAC_ADDR_LEN; i++)
508
hw->mac.perm_addr[i+4] = (u8)(rar_high >> (i*8));
510
for (i = 0; i < ETH_ADDR_LEN; i++)
511
hw->mac.addr[i] = hw->mac.perm_addr[i];
513
return E1000_SUCCESS;
517
* e1000e_validate_nvm_checksum_generic - Validate EEPROM checksum
518
* @hw: pointer to the HW structure
520
* Calculates the EEPROM checksum by reading/adding each word of the EEPROM
521
* and then verifies that the sum of the EEPROM is equal to 0xBABA.
523
s32 e1000e_validate_nvm_checksum_generic(struct e1000_hw *hw)
525
s32 ret_val = E1000_SUCCESS;
529
for (i = 0; i < (NVM_CHECKSUM_REG + 1); i++) {
530
ret_val = e1000e_read_nvm(hw, i, 1, &nvm_data);
532
e_dbg("NVM Read Error\n");
535
checksum += nvm_data;
538
if (checksum != (u16) NVM_SUM) {
539
e_dbg("NVM Checksum Invalid\n");
540
ret_val = -E1000_ERR_NVM;
549
* e1000e_update_nvm_checksum_generic - Update EEPROM checksum
550
* @hw: pointer to the HW structure
552
* Updates the EEPROM checksum by reading/adding each word of the EEPROM
553
* up to the checksum. Then calculates the EEPROM checksum and writes the
554
* value to the EEPROM.
556
s32 e1000e_update_nvm_checksum_generic(struct e1000_hw *hw)
562
for (i = 0; i < NVM_CHECKSUM_REG; i++) {
563
ret_val = e1000e_read_nvm(hw, i, 1, &nvm_data);
565
e_dbg("NVM Read Error while updating checksum.\n");
568
checksum += nvm_data;
570
checksum = (u16) NVM_SUM - checksum;
571
ret_val = e1000e_write_nvm(hw, NVM_CHECKSUM_REG, 1, &checksum);
573
e_dbg("NVM Write Error while updating checksum.\n");
580
* e1000e_reload_nvm - Reloads EEPROM
581
* @hw: pointer to the HW structure
583
* Reloads the EEPROM by setting the "Reinitialize from EEPROM" bit in the
584
* extended control register.
586
static void e1000e_reload_nvm(struct e1000_hw *hw)
591
ctrl_ext = er32(CTRL_EXT);
592
ctrl_ext |= E1000_CTRL_EXT_EE_RST;
593
ew32(CTRL_EXT, ctrl_ext);