2005-04-17 06:20:36 +08:00
|
|
|
/*******************************************************************************
|
|
|
|
|
2006-09-28 03:53:14 +08:00
|
|
|
Intel PRO/10GbE Linux driver
|
2008-07-09 06:53:09 +08:00
|
|
|
Copyright(c) 1999 - 2008 Intel Corporation.
|
2006-09-28 03:53:14 +08:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms and conditions of the GNU General Public License,
|
|
|
|
version 2, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
2005-04-17 06:20:36 +08:00
|
|
|
more details.
|
2006-09-28 03:53:14 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
You should have received a copy of the GNU General Public License along with
|
2006-09-28 03:53:14 +08:00
|
|
|
this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
The full GNU General Public License is included in this distribution in
|
|
|
|
the file called "COPYING".
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
Contact Information:
|
|
|
|
Linux NICS <linux.nics@intel.com>
|
2006-09-28 03:53:14 +08:00
|
|
|
e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
|
2005-04-17 06:20:36 +08:00
|
|
|
Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
|
|
|
|
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2010-04-27 08:50:58 +08:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#include "ixgb_hw.h"
|
|
|
|
#include "ixgb_ee.h"
|
|
|
|
/* Local prototypes */
|
2008-04-04 01:06:25 +08:00
|
|
|
static u16 ixgb_shift_in_bits(struct ixgb_hw *hw);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static void ixgb_shift_out_bits(struct ixgb_hw *hw,
|
2008-04-04 01:06:25 +08:00
|
|
|
u16 data,
|
|
|
|
u16 count);
|
2005-04-17 06:20:36 +08:00
|
|
|
static void ixgb_standby_eeprom(struct ixgb_hw *hw);
|
|
|
|
|
2008-03-22 02:06:37 +08:00
|
|
|
static bool ixgb_wait_eeprom_command(struct ixgb_hw *hw);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
static void ixgb_cleanup_eeprom(struct ixgb_hw *hw);
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Raises the EEPROM's clock input.
|
|
|
|
*
|
|
|
|
* hw - Struct containing variables accessed by shared code
|
|
|
|
* eecd_reg - EECD's current value
|
|
|
|
*****************************************************************************/
|
|
|
|
static void
|
|
|
|
ixgb_raise_clock(struct ixgb_hw *hw,
|
2008-04-04 01:06:25 +08:00
|
|
|
u32 *eecd_reg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/* Raise the clock input to the EEPROM (by setting the SK bit), and then
|
|
|
|
* wait 50 microseconds.
|
|
|
|
*/
|
|
|
|
*eecd_reg = *eecd_reg | IXGB_EECD_SK;
|
|
|
|
IXGB_WRITE_REG(hw, EECD, *eecd_reg);
|
2011-07-20 08:56:21 +08:00
|
|
|
IXGB_WRITE_FLUSH(hw);
|
2005-04-17 06:20:36 +08:00
|
|
|
udelay(50);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Lowers the EEPROM's clock input.
|
|
|
|
*
|
|
|
|
* hw - Struct containing variables accessed by shared code
|
|
|
|
* eecd_reg - EECD's current value
|
|
|
|
*****************************************************************************/
|
|
|
|
static void
|
|
|
|
ixgb_lower_clock(struct ixgb_hw *hw,
|
2008-04-04 01:06:25 +08:00
|
|
|
u32 *eecd_reg)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
/* Lower the clock input to the EEPROM (by clearing the SK bit), and then
|
|
|
|
* wait 50 microseconds.
|
|
|
|
*/
|
|
|
|
*eecd_reg = *eecd_reg & ~IXGB_EECD_SK;
|
|
|
|
IXGB_WRITE_REG(hw, EECD, *eecd_reg);
|
2011-07-20 08:56:21 +08:00
|
|
|
IXGB_WRITE_FLUSH(hw);
|
2005-04-17 06:20:36 +08:00
|
|
|
udelay(50);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Shift data bits out to the EEPROM.
|
|
|
|
*
|
|
|
|
* hw - Struct containing variables accessed by shared code
|
|
|
|
* data - data to send to the EEPROM
|
|
|
|
* count - number of bits to shift out
|
|
|
|
*****************************************************************************/
|
|
|
|
static void
|
|
|
|
ixgb_shift_out_bits(struct ixgb_hw *hw,
|
2008-04-04 01:06:25 +08:00
|
|
|
u16 data,
|
|
|
|
u16 count)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-04 01:06:25 +08:00
|
|
|
u32 eecd_reg;
|
|
|
|
u32 mask;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* We need to shift "count" bits out to the EEPROM. So, value in the
|
|
|
|
* "data" parameter will be shifted out to the EEPROM one bit at a time.
|
|
|
|
* In order to do this, "data" must be broken down into bits.
|
|
|
|
*/
|
|
|
|
mask = 0x01 << (count - 1);
|
|
|
|
eecd_reg = IXGB_READ_REG(hw, EECD);
|
|
|
|
eecd_reg &= ~(IXGB_EECD_DO | IXGB_EECD_DI);
|
|
|
|
do {
|
|
|
|
/* A "1" is shifted out to the EEPROM by setting bit "DI" to a "1",
|
|
|
|
* and then raising and then lowering the clock (the SK bit controls
|
|
|
|
* the clock input to the EEPROM). A "0" is shifted out to the EEPROM
|
|
|
|
* by setting "DI" to "0" and then raising and then lowering the clock.
|
|
|
|
*/
|
|
|
|
eecd_reg &= ~IXGB_EECD_DI;
|
|
|
|
|
2008-07-09 06:52:13 +08:00
|
|
|
if (data & mask)
|
2005-04-17 06:20:36 +08:00
|
|
|
eecd_reg |= IXGB_EECD_DI;
|
|
|
|
|
|
|
|
IXGB_WRITE_REG(hw, EECD, eecd_reg);
|
2011-07-20 08:56:21 +08:00
|
|
|
IXGB_WRITE_FLUSH(hw);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
udelay(50);
|
|
|
|
|
|
|
|
ixgb_raise_clock(hw, &eecd_reg);
|
|
|
|
ixgb_lower_clock(hw, &eecd_reg);
|
|
|
|
|
|
|
|
mask = mask >> 1;
|
|
|
|
|
2008-07-09 06:52:18 +08:00
|
|
|
} while (mask);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* We leave the "DI" bit set to "0" when we leave this routine. */
|
|
|
|
eecd_reg &= ~IXGB_EECD_DI;
|
|
|
|
IXGB_WRITE_REG(hw, EECD, eecd_reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Shift data bits in from the EEPROM
|
|
|
|
*
|
|
|
|
* hw - Struct containing variables accessed by shared code
|
|
|
|
*****************************************************************************/
|
2008-04-04 01:06:25 +08:00
|
|
|
static u16
|
2005-04-17 06:20:36 +08:00
|
|
|
ixgb_shift_in_bits(struct ixgb_hw *hw)
|
|
|
|
{
|
2008-04-04 01:06:25 +08:00
|
|
|
u32 eecd_reg;
|
|
|
|
u32 i;
|
|
|
|
u16 data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* In order to read a register from the EEPROM, we need to shift 16 bits
|
|
|
|
* in from the EEPROM. Bits are "shifted in" by raising the clock input to
|
|
|
|
* the EEPROM (setting the SK bit), and then reading the value of the "DO"
|
|
|
|
* bit. During this "shifting in" process the "DI" bit should always be
|
|
|
|
* clear..
|
|
|
|
*/
|
|
|
|
|
|
|
|
eecd_reg = IXGB_READ_REG(hw, EECD);
|
|
|
|
|
|
|
|
eecd_reg &= ~(IXGB_EECD_DO | IXGB_EECD_DI);
|
|
|
|
data = 0;
|
|
|
|
|
2008-07-09 06:52:33 +08:00
|
|
|
for (i = 0; i < 16; i++) {
|
2005-04-17 06:20:36 +08:00
|
|
|
data = data << 1;
|
|
|
|
ixgb_raise_clock(hw, &eecd_reg);
|
|
|
|
|
|
|
|
eecd_reg = IXGB_READ_REG(hw, EECD);
|
|
|
|
|
|
|
|
eecd_reg &= ~(IXGB_EECD_DI);
|
2008-07-09 06:52:13 +08:00
|
|
|
if (eecd_reg & IXGB_EECD_DO)
|
2005-04-17 06:20:36 +08:00
|
|
|
data |= 1;
|
|
|
|
|
|
|
|
ixgb_lower_clock(hw, &eecd_reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Prepares EEPROM for access
|
|
|
|
*
|
|
|
|
* hw - Struct containing variables accessed by shared code
|
|
|
|
*
|
|
|
|
* Lowers EEPROM clock. Clears input pin. Sets the chip select pin. This
|
|
|
|
* function should be called before issuing a command to the EEPROM.
|
|
|
|
*****************************************************************************/
|
|
|
|
static void
|
|
|
|
ixgb_setup_eeprom(struct ixgb_hw *hw)
|
|
|
|
{
|
2008-04-04 01:06:25 +08:00
|
|
|
u32 eecd_reg;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
eecd_reg = IXGB_READ_REG(hw, EECD);
|
|
|
|
|
|
|
|
/* Clear SK and DI */
|
|
|
|
eecd_reg &= ~(IXGB_EECD_SK | IXGB_EECD_DI);
|
|
|
|
IXGB_WRITE_REG(hw, EECD, eecd_reg);
|
|
|
|
|
|
|
|
/* Set CS */
|
|
|
|
eecd_reg |= IXGB_EECD_CS;
|
|
|
|
IXGB_WRITE_REG(hw, EECD, eecd_reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Returns EEPROM to a "standby" state
|
|
|
|
*
|
|
|
|
* hw - Struct containing variables accessed by shared code
|
|
|
|
*****************************************************************************/
|
|
|
|
static void
|
|
|
|
ixgb_standby_eeprom(struct ixgb_hw *hw)
|
|
|
|
{
|
2008-04-04 01:06:25 +08:00
|
|
|
u32 eecd_reg;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
eecd_reg = IXGB_READ_REG(hw, EECD);
|
|
|
|
|
2008-07-09 06:52:28 +08:00
|
|
|
/* Deselect EEPROM */
|
2005-04-17 06:20:36 +08:00
|
|
|
eecd_reg &= ~(IXGB_EECD_CS | IXGB_EECD_SK);
|
|
|
|
IXGB_WRITE_REG(hw, EECD, eecd_reg);
|
2011-07-20 08:56:21 +08:00
|
|
|
IXGB_WRITE_FLUSH(hw);
|
2005-04-17 06:20:36 +08:00
|
|
|
udelay(50);
|
|
|
|
|
|
|
|
/* Clock high */
|
|
|
|
eecd_reg |= IXGB_EECD_SK;
|
|
|
|
IXGB_WRITE_REG(hw, EECD, eecd_reg);
|
2011-07-20 08:56:21 +08:00
|
|
|
IXGB_WRITE_FLUSH(hw);
|
2005-04-17 06:20:36 +08:00
|
|
|
udelay(50);
|
|
|
|
|
|
|
|
/* Select EEPROM */
|
|
|
|
eecd_reg |= IXGB_EECD_CS;
|
|
|
|
IXGB_WRITE_REG(hw, EECD, eecd_reg);
|
2011-07-20 08:56:21 +08:00
|
|
|
IXGB_WRITE_FLUSH(hw);
|
2005-04-17 06:20:36 +08:00
|
|
|
udelay(50);
|
|
|
|
|
|
|
|
/* Clock low */
|
|
|
|
eecd_reg &= ~IXGB_EECD_SK;
|
|
|
|
IXGB_WRITE_REG(hw, EECD, eecd_reg);
|
2011-07-20 08:56:21 +08:00
|
|
|
IXGB_WRITE_FLUSH(hw);
|
2005-04-17 06:20:36 +08:00
|
|
|
udelay(50);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Raises then lowers the EEPROM's clock pin
|
|
|
|
*
|
|
|
|
* hw - Struct containing variables accessed by shared code
|
|
|
|
*****************************************************************************/
|
|
|
|
static void
|
|
|
|
ixgb_clock_eeprom(struct ixgb_hw *hw)
|
|
|
|
{
|
2008-04-04 01:06:25 +08:00
|
|
|
u32 eecd_reg;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
eecd_reg = IXGB_READ_REG(hw, EECD);
|
|
|
|
|
|
|
|
/* Rising edge of clock */
|
|
|
|
eecd_reg |= IXGB_EECD_SK;
|
|
|
|
IXGB_WRITE_REG(hw, EECD, eecd_reg);
|
2011-07-20 08:56:21 +08:00
|
|
|
IXGB_WRITE_FLUSH(hw);
|
2005-04-17 06:20:36 +08:00
|
|
|
udelay(50);
|
|
|
|
|
|
|
|
/* Falling edge of clock */
|
|
|
|
eecd_reg &= ~IXGB_EECD_SK;
|
|
|
|
IXGB_WRITE_REG(hw, EECD, eecd_reg);
|
2011-07-20 08:56:21 +08:00
|
|
|
IXGB_WRITE_FLUSH(hw);
|
2005-04-17 06:20:36 +08:00
|
|
|
udelay(50);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Terminates a command by lowering the EEPROM's chip select pin
|
|
|
|
*
|
|
|
|
* hw - Struct containing variables accessed by shared code
|
|
|
|
*****************************************************************************/
|
|
|
|
static void
|
|
|
|
ixgb_cleanup_eeprom(struct ixgb_hw *hw)
|
|
|
|
{
|
2008-04-04 01:06:25 +08:00
|
|
|
u32 eecd_reg;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
eecd_reg = IXGB_READ_REG(hw, EECD);
|
|
|
|
|
|
|
|
eecd_reg &= ~(IXGB_EECD_CS | IXGB_EECD_DI);
|
|
|
|
|
|
|
|
IXGB_WRITE_REG(hw, EECD, eecd_reg);
|
|
|
|
|
|
|
|
ixgb_clock_eeprom(hw);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Waits for the EEPROM to finish the current command.
|
|
|
|
*
|
|
|
|
* hw - Struct containing variables accessed by shared code
|
|
|
|
*
|
|
|
|
* The command is done when the EEPROM's data out pin goes high.
|
|
|
|
*
|
|
|
|
* Returns:
|
2008-03-22 02:06:37 +08:00
|
|
|
* true: EEPROM data pin is high before timeout.
|
|
|
|
* false: Time expired.
|
2005-04-17 06:20:36 +08:00
|
|
|
*****************************************************************************/
|
2008-03-22 02:06:37 +08:00
|
|
|
static bool
|
2005-04-17 06:20:36 +08:00
|
|
|
ixgb_wait_eeprom_command(struct ixgb_hw *hw)
|
|
|
|
{
|
2008-04-04 01:06:25 +08:00
|
|
|
u32 eecd_reg;
|
|
|
|
u32 i;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Toggle the CS line. This in effect tells to EEPROM to actually execute
|
|
|
|
* the command in question.
|
|
|
|
*/
|
|
|
|
ixgb_standby_eeprom(hw);
|
|
|
|
|
2008-07-09 06:52:28 +08:00
|
|
|
/* Now read DO repeatedly until is high (equal to '1'). The EEPROM will
|
2005-04-17 06:20:36 +08:00
|
|
|
* signal that the command has been completed by raising the DO signal.
|
|
|
|
* If DO does not go high in 10 milliseconds, then error out.
|
|
|
|
*/
|
2008-07-09 06:52:33 +08:00
|
|
|
for (i = 0; i < 200; i++) {
|
2005-04-17 06:20:36 +08:00
|
|
|
eecd_reg = IXGB_READ_REG(hw, EECD);
|
|
|
|
|
2008-07-09 06:52:13 +08:00
|
|
|
if (eecd_reg & IXGB_EECD_DO)
|
2010-09-23 13:40:09 +08:00
|
|
|
return true;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
udelay(50);
|
|
|
|
}
|
|
|
|
ASSERT(0);
|
2010-09-23 13:40:09 +08:00
|
|
|
return false;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Verifies that the EEPROM has a valid checksum
|
|
|
|
*
|
|
|
|
* hw - Struct containing variables accessed by shared code
|
|
|
|
*
|
|
|
|
* Reads the first 64 16 bit words of the EEPROM and sums the values read.
|
2007-05-09 14:57:56 +08:00
|
|
|
* If the sum of the 64 16 bit words is 0xBABA, the EEPROM's checksum is
|
2005-04-17 06:20:36 +08:00
|
|
|
* valid.
|
|
|
|
*
|
|
|
|
* Returns:
|
2008-03-22 02:06:37 +08:00
|
|
|
* true: Checksum is valid
|
|
|
|
* false: Checksum is not valid.
|
2005-04-17 06:20:36 +08:00
|
|
|
*****************************************************************************/
|
2008-03-22 02:06:37 +08:00
|
|
|
bool
|
2005-04-17 06:20:36 +08:00
|
|
|
ixgb_validate_eeprom_checksum(struct ixgb_hw *hw)
|
|
|
|
{
|
2008-04-04 01:06:25 +08:00
|
|
|
u16 checksum = 0;
|
|
|
|
u16 i;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-07-09 06:52:33 +08:00
|
|
|
for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++)
|
2005-04-17 06:20:36 +08:00
|
|
|
checksum += ixgb_read_eeprom(hw, i);
|
|
|
|
|
2008-07-09 06:52:13 +08:00
|
|
|
if (checksum == (u16) EEPROM_SUM)
|
2010-09-23 13:40:09 +08:00
|
|
|
return true;
|
2005-04-17 06:20:36 +08:00
|
|
|
else
|
2010-09-23 13:40:09 +08:00
|
|
|
return false;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Calculates the EEPROM checksum and writes it to the EEPROM
|
|
|
|
*
|
|
|
|
* hw - Struct containing variables accessed by shared code
|
|
|
|
*
|
|
|
|
* Sums the first 63 16 bit words of the EEPROM. Subtracts the sum from 0xBABA.
|
|
|
|
* Writes the difference to word offset 63 of the EEPROM.
|
|
|
|
*****************************************************************************/
|
|
|
|
void
|
|
|
|
ixgb_update_eeprom_checksum(struct ixgb_hw *hw)
|
|
|
|
{
|
2008-04-04 01:06:25 +08:00
|
|
|
u16 checksum = 0;
|
|
|
|
u16 i;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-07-09 06:52:33 +08:00
|
|
|
for (i = 0; i < EEPROM_CHECKSUM_REG; i++)
|
2005-04-17 06:20:36 +08:00
|
|
|
checksum += ixgb_read_eeprom(hw, i);
|
|
|
|
|
2008-04-04 01:06:25 +08:00
|
|
|
checksum = (u16) EEPROM_SUM - checksum;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ixgb_write_eeprom(hw, EEPROM_CHECKSUM_REG, checksum);
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Writes a 16 bit word to a given offset in the EEPROM.
|
|
|
|
*
|
|
|
|
* hw - Struct containing variables accessed by shared code
|
|
|
|
* reg - offset within the EEPROM to be written to
|
2008-07-09 06:52:28 +08:00
|
|
|
* data - 16 bit word to be written to the EEPROM
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
|
|
|
* If ixgb_update_eeprom_checksum is not called after this function, the
|
|
|
|
* EEPROM will most likely contain an invalid checksum.
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
void
|
2008-04-04 01:06:25 +08:00
|
|
|
ixgb_write_eeprom(struct ixgb_hw *hw, u16 offset, u16 data)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct ixgb_ee_map_type *ee_map = (struct ixgb_ee_map_type *)hw->eeprom;
|
|
|
|
|
|
|
|
/* Prepare the EEPROM for writing */
|
|
|
|
ixgb_setup_eeprom(hw);
|
|
|
|
|
|
|
|
/* Send the 9-bit EWEN (write enable) command to the EEPROM (5-bit opcode
|
|
|
|
* plus 4-bit dummy). This puts the EEPROM into write/erase mode.
|
|
|
|
*/
|
|
|
|
ixgb_shift_out_bits(hw, EEPROM_EWEN_OPCODE, 5);
|
|
|
|
ixgb_shift_out_bits(hw, 0, 4);
|
|
|
|
|
|
|
|
/* Prepare the EEPROM */
|
|
|
|
ixgb_standby_eeprom(hw);
|
|
|
|
|
|
|
|
/* Send the Write command (3-bit opcode + 6-bit addr) */
|
|
|
|
ixgb_shift_out_bits(hw, EEPROM_WRITE_OPCODE, 3);
|
|
|
|
ixgb_shift_out_bits(hw, offset, 6);
|
|
|
|
|
|
|
|
/* Send the data */
|
|
|
|
ixgb_shift_out_bits(hw, data, 16);
|
|
|
|
|
|
|
|
ixgb_wait_eeprom_command(hw);
|
|
|
|
|
|
|
|
/* Recover from write */
|
|
|
|
ixgb_standby_eeprom(hw);
|
|
|
|
|
|
|
|
/* Send the 9-bit EWDS (write disable) command to the EEPROM (5-bit
|
|
|
|
* opcode plus 4-bit dummy). This takes the EEPROM out of write/erase
|
|
|
|
* mode.
|
|
|
|
*/
|
|
|
|
ixgb_shift_out_bits(hw, EEPROM_EWDS_OPCODE, 5);
|
|
|
|
ixgb_shift_out_bits(hw, 0, 4);
|
|
|
|
|
|
|
|
/* Done with writing */
|
|
|
|
ixgb_cleanup_eeprom(hw);
|
|
|
|
|
|
|
|
/* clear the init_ctrl_reg_1 to signify that the cache is invalidated */
|
2007-08-23 12:47:03 +08:00
|
|
|
ee_map->init_ctrl_reg_1 = cpu_to_le16(EEPROM_ICW1_SIGNATURE_CLEAR);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Reads a 16 bit word from the EEPROM.
|
|
|
|
*
|
|
|
|
* hw - Struct containing variables accessed by shared code
|
|
|
|
* offset - offset of 16 bit word in the EEPROM to read
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The 16-bit value read from the eeprom
|
|
|
|
*****************************************************************************/
|
2008-04-04 01:06:25 +08:00
|
|
|
u16
|
2005-04-17 06:20:36 +08:00
|
|
|
ixgb_read_eeprom(struct ixgb_hw *hw,
|
2008-04-04 01:06:25 +08:00
|
|
|
u16 offset)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-04-04 01:06:25 +08:00
|
|
|
u16 data;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* Prepare the EEPROM for reading */
|
|
|
|
ixgb_setup_eeprom(hw);
|
|
|
|
|
|
|
|
/* Send the READ command (opcode + addr) */
|
|
|
|
ixgb_shift_out_bits(hw, EEPROM_READ_OPCODE, 3);
|
|
|
|
/*
|
|
|
|
* We have a 64 word EEPROM, there are 6 address bits
|
|
|
|
*/
|
|
|
|
ixgb_shift_out_bits(hw, offset, 6);
|
|
|
|
|
|
|
|
/* Read the data */
|
|
|
|
data = ixgb_shift_in_bits(hw);
|
|
|
|
|
|
|
|
/* End this read operation */
|
|
|
|
ixgb_standby_eeprom(hw);
|
|
|
|
|
2010-09-23 13:40:09 +08:00
|
|
|
return data;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Reads eeprom and stores data in shared structure.
|
|
|
|
* Validates eeprom checksum and eeprom signature.
|
|
|
|
*
|
|
|
|
* hw - Struct containing variables accessed by shared code
|
|
|
|
*
|
|
|
|
* Returns:
|
2008-03-22 02:06:37 +08:00
|
|
|
* true: if eeprom read is successful
|
|
|
|
* false: otherwise.
|
2005-04-17 06:20:36 +08:00
|
|
|
*****************************************************************************/
|
2008-03-22 02:06:37 +08:00
|
|
|
bool
|
2005-04-17 06:20:36 +08:00
|
|
|
ixgb_get_eeprom_data(struct ixgb_hw *hw)
|
|
|
|
{
|
2008-04-04 01:06:25 +08:00
|
|
|
u16 i;
|
|
|
|
u16 checksum = 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
struct ixgb_ee_map_type *ee_map;
|
|
|
|
|
2010-04-27 08:50:58 +08:00
|
|
|
ENTER();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
ee_map = (struct ixgb_ee_map_type *)hw->eeprom;
|
|
|
|
|
2010-04-27 08:50:58 +08:00
|
|
|
pr_debug("Reading eeprom data\n");
|
2008-07-09 06:52:33 +08:00
|
|
|
for (i = 0; i < IXGB_EEPROM_SIZE ; i++) {
|
2008-04-04 01:06:25 +08:00
|
|
|
u16 ee_data;
|
2005-04-17 06:20:36 +08:00
|
|
|
ee_data = ixgb_read_eeprom(hw, i);
|
|
|
|
checksum += ee_data;
|
2007-08-23 12:47:03 +08:00
|
|
|
hw->eeprom[i] = cpu_to_le16(ee_data);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2008-04-04 01:06:25 +08:00
|
|
|
if (checksum != (u16) EEPROM_SUM) {
|
2010-04-27 08:50:58 +08:00
|
|
|
pr_debug("Checksum invalid\n");
|
2005-04-17 06:20:36 +08:00
|
|
|
/* clear the init_ctrl_reg_1 to signify that the cache is
|
|
|
|
* invalidated */
|
2007-08-23 12:47:03 +08:00
|
|
|
ee_map->init_ctrl_reg_1 = cpu_to_le16(EEPROM_ICW1_SIGNATURE_CLEAR);
|
2010-09-23 13:40:09 +08:00
|
|
|
return false;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2007-08-23 12:47:03 +08:00
|
|
|
if ((ee_map->init_ctrl_reg_1 & cpu_to_le16(EEPROM_ICW1_SIGNATURE_MASK))
|
|
|
|
!= cpu_to_le16(EEPROM_ICW1_SIGNATURE_VALID)) {
|
2010-04-27 08:50:58 +08:00
|
|
|
pr_debug("Signature invalid\n");
|
2010-09-23 13:40:09 +08:00
|
|
|
return false;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2010-09-23 13:40:09 +08:00
|
|
|
return true;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* Local function to check if the eeprom signature is good
|
|
|
|
* If the eeprom signature is good, calls ixgb)get_eeprom_data.
|
|
|
|
*
|
|
|
|
* hw - Struct containing variables accessed by shared code
|
|
|
|
*
|
|
|
|
* Returns:
|
2008-03-22 02:06:37 +08:00
|
|
|
* true: eeprom signature was good and the eeprom read was successful
|
|
|
|
* false: otherwise.
|
2005-04-17 06:20:36 +08:00
|
|
|
******************************************************************************/
|
2008-03-22 02:06:37 +08:00
|
|
|
static bool
|
2005-04-17 06:20:36 +08:00
|
|
|
ixgb_check_and_get_eeprom_data (struct ixgb_hw* hw)
|
|
|
|
{
|
|
|
|
struct ixgb_ee_map_type *ee_map = (struct ixgb_ee_map_type *)hw->eeprom;
|
|
|
|
|
2007-08-23 12:47:03 +08:00
|
|
|
if ((ee_map->init_ctrl_reg_1 & cpu_to_le16(EEPROM_ICW1_SIGNATURE_MASK))
|
|
|
|
== cpu_to_le16(EEPROM_ICW1_SIGNATURE_VALID)) {
|
2010-09-23 13:40:09 +08:00
|
|
|
return true;
|
2005-04-17 06:20:36 +08:00
|
|
|
} else {
|
|
|
|
return ixgb_get_eeprom_data(hw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* return a word from the eeprom
|
|
|
|
*
|
|
|
|
* hw - Struct containing variables accessed by shared code
|
|
|
|
* index - Offset of eeprom word
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Word at indexed offset in eeprom, if valid, 0 otherwise.
|
|
|
|
******************************************************************************/
|
2007-08-23 12:47:03 +08:00
|
|
|
__le16
|
2008-04-04 01:06:25 +08:00
|
|
|
ixgb_get_eeprom_word(struct ixgb_hw *hw, u16 index)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
|
2012-02-09 19:17:23 +08:00
|
|
|
if (index < IXGB_EEPROM_SIZE && ixgb_check_and_get_eeprom_data(hw))
|
|
|
|
return hw->eeprom[index];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-09-23 13:40:09 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* return the mac address from EEPROM
|
|
|
|
*
|
|
|
|
* hw - Struct containing variables accessed by shared code
|
|
|
|
* mac_addr - Ethernet Address if EEPROM contents are valid, 0 otherwise
|
|
|
|
*
|
|
|
|
* Returns: None.
|
|
|
|
******************************************************************************/
|
|
|
|
void
|
|
|
|
ixgb_get_ee_mac_addr(struct ixgb_hw *hw,
|
2008-04-04 01:06:25 +08:00
|
|
|
u8 *mac_addr)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
struct ixgb_ee_map_type *ee_map = (struct ixgb_ee_map_type *)hw->eeprom;
|
|
|
|
|
2010-04-27 08:50:58 +08:00
|
|
|
ENTER();
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2012-02-09 19:17:23 +08:00
|
|
|
if (ixgb_check_and_get_eeprom_data(hw)) {
|
2011-09-23 10:11:29 +08:00
|
|
|
for (i = 0; i < ETH_ALEN; i++) {
|
2005-04-17 06:20:36 +08:00
|
|
|
mac_addr[i] = ee_map->mac_addr[i];
|
|
|
|
}
|
2010-04-27 08:50:58 +08:00
|
|
|
pr_debug("eeprom mac address = %pM\n", mac_addr);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* return the Printed Board Assembly number from EEPROM
|
|
|
|
*
|
|
|
|
* hw - Struct containing variables accessed by shared code
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* PBA number if EEPROM contents are valid, 0 otherwise
|
|
|
|
******************************************************************************/
|
2008-04-04 01:06:25 +08:00
|
|
|
u32
|
2005-04-17 06:20:36 +08:00
|
|
|
ixgb_get_ee_pba_number(struct ixgb_hw *hw)
|
|
|
|
{
|
2012-02-09 19:17:23 +08:00
|
|
|
if (ixgb_check_and_get_eeprom_data(hw))
|
2010-09-23 13:40:09 +08:00
|
|
|
return le16_to_cpu(hw->eeprom[EEPROM_PBA_1_2_REG])
|
|
|
|
| (le16_to_cpu(hw->eeprom[EEPROM_PBA_3_4_REG])<<16);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-09-23 13:40:09 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************************
|
|
|
|
* return the Device Id from EEPROM
|
|
|
|
*
|
|
|
|
* hw - Struct containing variables accessed by shared code
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Device Id if EEPROM contents are valid, 0 otherwise
|
|
|
|
******************************************************************************/
|
2008-04-04 01:06:25 +08:00
|
|
|
u16
|
2005-04-17 06:20:36 +08:00
|
|
|
ixgb_get_ee_device_id(struct ixgb_hw *hw)
|
|
|
|
{
|
|
|
|
struct ixgb_ee_map_type *ee_map = (struct ixgb_ee_map_type *)hw->eeprom;
|
|
|
|
|
2012-02-09 19:17:23 +08:00
|
|
|
if (ixgb_check_and_get_eeprom_data(hw))
|
2010-09-23 13:40:09 +08:00
|
|
|
return le16_to_cpu(ee_map->device_id);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2010-09-23 13:40:09 +08:00
|
|
|
return 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|