summaryrefslogtreecommitdiffstats
path: root/src/drivers/net/realtek.c
diff options
context:
space:
mode:
authorMichael Brown2013-04-28 19:50:10 +0200
committerMichael Brown2013-04-28 19:59:09 +0200
commitd90fc3156c57ba90156ceb4e33fda4a6a19ca382 (patch)
treed6bf81fe4ebbe22e7db8cae60ce79ab9ea2f0565 /src/drivers/net/realtek.c
parent[build] Default to short wchar_t in stddef.h (diff)
downloadipxe-d90fc3156c57ba90156ceb4e33fda4a6a19ca382.tar.gz
ipxe-d90fc3156c57ba90156ceb4e33fda4a6a19ca382.tar.xz
ipxe-d90fc3156c57ba90156ceb4e33fda4a6a19ca382.zip
[realtek] Use ID word to detect EEPROM presence
Some onboard RTL8169 NICs seem to leave the EEPROM pins disconnected. The existing is_valid_ether_addr() test will not necessarily catch this, since it expects a missing EEPROM to show up as a MAC address of 00:00:00:00:00:00 or ff:ff:ff:ff:ff:ff. When the EEPROM pins are floating the MAC address may read as e.g. 00:00:00:00:0f:00, which will not be detected as invalid. Check the ID word in the first two bytes of the EEPROM (which should have the value 0x8129 for all RTL8139 and RTL8169 chips), and use this to determine whether or not an EEPROM is present. Reported-by: Carl Karsten <carl@nextdayvideo.com> Tested-by: Carl Karsten <carl@nextdayvideo.com> Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/drivers/net/realtek.c')
-rw-r--r--src/drivers/net/realtek.c52
1 files changed, 36 insertions, 16 deletions
diff --git a/src/drivers/net/realtek.c b/src/drivers/net/realtek.c
index 011822ec..d7c4d29d 100644
--- a/src/drivers/net/realtek.c
+++ b/src/drivers/net/realtek.c
@@ -144,9 +144,12 @@ static struct bit_basher_operations realtek_basher_ops = {
* Initialise EEPROM
*
* @v netdev Network device
+ * @ret rc Return status code
*/
-static void realtek_init_eeprom ( struct net_device *netdev ) {
+static int realtek_init_eeprom ( struct net_device *netdev ) {
struct realtek_nic *rtl = netdev->priv;
+ uint16_t id;
+ int rc;
/* Initialise SPI bit-bashing interface */
rtl->spibit.basher.op = &realtek_basher_ops;
@@ -163,6 +166,22 @@ static void realtek_init_eeprom ( struct net_device *netdev ) {
}
rtl->eeprom.bus = &rtl->spibit.bus;
+ /* Check for EEPROM presence. Some onboard NICs will have no
+ * EEPROM connected, with the BIOS being responsible for
+ * programming the initial register values.
+ */
+ if ( ( rc = nvs_read ( &rtl->eeprom.nvs, RTL_EEPROM_ID,
+ &id, sizeof ( id ) ) ) != 0 ) {
+ DBGC ( rtl, "REALTEK %p could not read EEPROM ID: %s\n",
+ rtl, strerror ( rc ) );
+ return rc;
+ }
+ if ( id != cpu_to_le16 ( RTL_EEPROM_ID_MAGIC ) ) {
+ DBGC ( rtl, "REALTEK %p EEPROM ID incorrect (%#04x); assuming "
+ "no EEPROM\n", rtl, le16_to_cpu ( id ) );
+ return -ENODEV;
+ }
+
/* Initialise space for non-volatile options, if available
*
* We use offset 0x40 (i.e. address 0x20), length 0x40. This
@@ -176,6 +195,8 @@ static void realtek_init_eeprom ( struct net_device *netdev ) {
nvo_init ( &rtl->nvo, &rtl->eeprom.nvs, RTL_EEPROM_VPD,
RTL_EEPROM_VPD_LEN, NULL, &netdev->refcnt );
}
+
+ return 0;
}
/******************************************************************************
@@ -1045,23 +1066,22 @@ static int realtek_probe ( struct pci_device *pci ) {
realtek_detect ( rtl );
/* Initialise EEPROM */
- realtek_init_eeprom ( netdev );
+ if ( ( rc = realtek_init_eeprom ( netdev ) ) == 0 ) {
+
+ /* Read MAC address from EEPROM */
+ if ( ( rc = nvs_read ( &rtl->eeprom.nvs, RTL_EEPROM_MAC,
+ netdev->hw_addr, ETH_ALEN ) ) != 0 ) {
+ DBGC ( rtl, "REALTEK %p could not read MAC address: "
+ "%s\n", rtl, strerror ( rc ) );
+ goto err_nvs_read;
+ }
- /* Read MAC address from EEPROM */
- if ( ( rc = nvs_read ( &rtl->eeprom.nvs, RTL_EEPROM_MAC,
- netdev->hw_addr, ETH_ALEN ) ) != 0 ) {
- DBGC ( rtl, "REALTEK %p could not read MAC address: %s\n",
- rtl, strerror ( rc ) );
- goto err_nvs_read;
- }
+ } else {
- /* The EEPROM may not be present for onboard NICs. Fall back
- * to reading the current ID register value, which will
- * hopefully have been programmed by the platform firmware.
- */
- if ( ! is_valid_ether_addr ( netdev->hw_addr ) ) {
- DBGC ( rtl, "REALTEK %p seems to have no EEPROM (MAC %s)\n",
- rtl, eth_ntoa ( netdev->hw_addr ) );
+ /* EEPROM not present. Fall back to reading the
+ * current ID register value, which will hopefully
+ * have been programmed by the platform firmware.
+ */
for ( i = 0 ; i < ETH_ALEN ; i++ )
netdev->hw_addr[i] = readb ( rtl->regs + RTL_IDR0 + i );
}