[coreboot-gerrit] Patch set updated for coreboot: drivers/net/r8168: Add driver for realtek nic
Damien Zammit (damien@zamaudio.com)
gerrit at coreboot.org
Mon May 23 08:13:23 CEST 2016
Damien Zammit (damien at zamaudio.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/14927
-gerrit
commit da0a499c40eb84e3ad523eb079a59d63b6dc651a
Author: Damien Zammit <damien at zamaudio.com>
Date: Sat May 21 02:24:19 2016 +1000
drivers/net/r8168: Add driver for realtek nic
One thing that is vital to this patch is the MAC address setting
in case the EEPROM is missing/unable to be read.
While at it, I did a software reset of the NIC for good measure
to reset the defaults.
Unfortunately, there is still something missing because the NIC
MAC address is corrupted on booting into GNU/Linux.
The only workaround currently for GA-G41M-ES2L is to hardcode the
MAC address in the IP set-up within the operating system.
Change-Id: I32e070b545b4c6369686a7087b7ff838d00764e3
Signed-off-by: Damien Zammit <damien at zamaudio.com>
---
src/drivers/net/Kconfig | 5 +++
src/drivers/net/Makefile.inc | 1 +
src/drivers/net/r8168.c | 79 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 85 insertions(+)
diff --git a/src/drivers/net/Kconfig b/src/drivers/net/Kconfig
new file mode 100644
index 0000000..b4bafd2
--- /dev/null
+++ b/src/drivers/net/Kconfig
@@ -0,0 +1,5 @@
+config REALTEK_8168_RESET
+ bool "Realtek 8168 reset"
+ help
+ This forces a realtek 10ec:8168 card to reset to ensure power state
+ is correct at boot.
diff --git a/src/drivers/net/Makefile.inc b/src/drivers/net/Makefile.inc
index 9b3008d..e435d48 100644
--- a/src/drivers/net/Makefile.inc
+++ b/src/drivers/net/Makefile.inc
@@ -1,2 +1,3 @@
romstage-$(CONFIG_CONSOLE_NE2K) += ne2k.c
ramstage-$(CONFIG_CONSOLE_NE2K) += ne2k.c
+ramstage-$(CONFIG_REALTEK_8168_RESET) += r8168.c
diff --git a/src/drivers/net/r8168.c b/src/drivers/net/r8168.c
new file mode 100644
index 0000000..cbd2573
--- /dev/null
+++ b/src/drivers/net/r8168.c
@@ -0,0 +1,79 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2016 Damien Zammit <damien at zamaudio.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that 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 more details.
+ */
+
+/*
+ * This driver forces the 10ec:8168 device to reset so that it goes
+ * into a proper power state, also programs a default MAC address
+ * so that if the EEPROM is missing it still has a default address.
+ */
+
+#include <arch/io.h>
+#include <device/device.h>
+#include <device/pci.h>
+#include <device/pci_ops.h>
+#include <device/pci_def.h>
+#include <delay.h>
+#include <console/console.h>
+
+#define CMD_REG 0x37
+#define NIC_RESET 0x10
+#define NIC_TIMEOUT 1000
+
+static void r8168_init(struct device *dev)
+{
+ u32 i;
+
+ /* Get the resource of the NIC mmio */
+ struct resource *nic_res = find_resource(dev, PCI_BASE_ADDRESS_0);
+ u16 nic_port = (u16)nic_res->base;
+
+ /* Set bus master */
+ pci_write_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER
+ | PCI_COMMAND_MEMORY | PCI_COMMAND_IO);
+
+ /* Reset NIC */
+ printk(BIOS_DEBUG, "r8168: Resetting NIC...");
+ outb(NIC_RESET, nic_port + CMD_REG);
+
+ i = 0;
+ /* Poll for reset, with 1s timeout */
+ while (i < NIC_TIMEOUT && (inb(nic_port + CMD_REG) & NIC_RESET)) {
+ udelay(1000);
+ if (++i >= NIC_TIMEOUT)
+ printk(BIOS_DEBUG, "timeout waiting for nic to reset\n");
+ }
+ if (i < NIC_TIMEOUT)
+ printk(BIOS_DEBUG, "done\n");
+
+ /* Use default realtek MAC identifier 00:e0:4c:00:c0:b0
+ * NB: only 4-byte write accesses allowed
+ */
+ outl(0x00e04c00, nic_port + 0);
+ outl(0x4c00c0b0, nic_port + 2);
+}
+
+static struct device_operations r8168_ops = {
+ .read_resources = pci_dev_read_resources,
+ .set_resources = pci_dev_set_resources,
+ .enable_resources = pci_dev_enable_resources,
+ .init = r8168_init,
+ .scan_bus = 0,
+};
+
+static const struct pci_driver r8168_driver __pci_driver = {
+ .ops = &r8168_ops,
+ .vendor = 0x10ec,
+ .device = 0x8168,
+};
More information about the coreboot-gerrit
mailing list