Skip to content
Permalink
Browse files

ethernet/eth_e1000.c: change to new PCI(e) functions

Migrate from "legacy" PCI support (drivers/pci) to new PCI(e) support.

The e1000 driver is merely for testing with QEMU and so should not be
a model for the use of PCI(e) functions. Consult instead "real-world"
PCI(e) drivers like the NS16550 UART (drivers/serial/uart_ns16550.c).

Signed-off-by: Charles Youse <charles.youse@intel.com>
  • Loading branch information...
Charles Youse authored and andrewboie committed Apr 18, 2019
1 parent fdf973d commit 8e307a3ad9648035dcf84f05466c5bd9f6166c7a
@@ -8,7 +8,7 @@

menuconfig ETH_E1000
bool "Intel(R) PRO/1000 Gigabit Ethernet driver"
depends on PCI_ENUMERATION
depends on PCIE
help
Enable Intel(R) PRO/1000 Gigabit Ethernet driver.

@@ -12,7 +12,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
#include <zephyr.h>
#include <net/ethernet.h>
#include <ethernet/eth_stats.h>
#include <pci/pci.h>
#include <drivers/pcie/pcie.h>
#include "eth_e1000_priv.h"

static const char *e1000_reg_to_string(enum e1000_reg_t r)
@@ -132,24 +132,24 @@ static void e1000_isr(struct device *device)
}
}

#define PCI_VENDOR_ID_INTEL 0x8086
#define PCI_DEVICE_ID_I82540EM 0x100e

int e1000_probe(struct device *device)
{
const pcie_bdf_t bdf = PCIE_BDF(0, 3, 0);
struct e1000_dev *dev = device->driver_data;

pci_bus_scan_init();

if (pci_bus_scan(&dev->pci)) {

pci_enable_regs(&dev->pci);

pci_enable_bus_master(&dev->pci);

pci_show(&dev->pci);

return 0;
int retval = -ENODEV;

if (pcie_probe(bdf, PCIE_ID(PCI_VENDOR_ID_INTEL,
PCI_DEVICE_ID_I82540EM))) {
dev->address = pcie_get_mbar(bdf, 0);
pcie_set_cmd(bdf, PCIE_CONF_CMDSTAT_MEM |
PCIE_CONF_CMDSTAT_MASTER, true);
retval = 0;
}

return -ENODEV;
return retval;
}

static struct device DEVICE_NAME_GET(eth_e1000);
@@ -210,13 +210,7 @@ static void e1000_init(struct net_if *iface)
LOG_DBG("done");
}

#define PCI_VENDOR_ID_INTEL 0x8086
#define PCI_DEVICE_ID_I82540EM 0x100e

static struct e1000_dev e1000_dev = {
.pci.vendor_id = PCI_VENDOR_ID_INTEL,
.pci.device_id = PCI_DEVICE_ID_I82540EM,
};
static struct e1000_dev e1000_dev;

static const struct ethernet_api e1000_api = {
.iface_api.init = e1000_init,
@@ -77,7 +77,7 @@ struct e1000_rx {
struct e1000_dev {
volatile struct e1000_tx tx __aligned(16);
volatile struct e1000_rx rx __aligned(16);
struct pci_dev_info pci;
u32_t address;
struct net_if *iface;
u8_t mac[ETH_ALEN];
u8_t txb[NET_ETH_MTU];
@@ -88,13 +88,13 @@ static const char *e1000_reg_to_string(enum e1000_reg_t r)
__attribute__((unused));

#define iow32(_dev, _reg, _val) do { \
LOG_DBG("iow32 %s 0x%08x", e1000_reg_to_string(_reg), _val); \
sys_write32(_val, (_dev)->pci.addr + _reg); \
LOG_DBG("iow32 %s 0x%08x", e1000_reg_to_string(_reg), (_val)); \
sys_write32(_val, (_dev)->address + (_reg)); \
} while (0)

#define ior32(_dev, _reg) \
({ \
u32_t val = sys_read32((_dev)->pci.addr + (_reg)); \
u32_t val = sys_read32((_dev)->address + (_reg)); \
LOG_DBG("ior32 %s 0x%08x", e1000_reg_to_string(_reg), val); \
val; \
})
@@ -3,7 +3,6 @@ CONFIG_NET_QEMU_ETHERNET=y

CONFIG_ETH_E1000=y

CONFIG_PCI_ENUMERATION=y
CONFIG_PCI=y
CONFIG_PCIE=y

#CONFIG_ETHERNET_LOG_LEVEL_DBG=y
@@ -3,7 +3,6 @@ CONFIG_NET_QEMU_ETHERNET=y

CONFIG_ETH_E1000=y

CONFIG_PCI_ENUMERATION=y
CONFIG_PCI=y
CONFIG_PCIE=y

#CONFIG_ETHERNET_LOG_LEVEL_DBG=y
@@ -3,7 +3,6 @@ CONFIG_NET_QEMU_ETHERNET=y

CONFIG_ETH_E1000=y

CONFIG_PCI_ENUMERATION=y
CONFIG_PCI=y
CONFIG_PCIE=y

#CONFIG_ETHERNET_LOG_LEVEL_DBG=y
@@ -3,7 +3,6 @@ CONFIG_NET_QEMU_ETHERNET=y

CONFIG_ETH_E1000=y

CONFIG_PCI_ENUMERATION=y
CONFIG_PCI=y
CONFIG_PCIE=y

#CONFIG_ETHERNET_LOG_LEVEL_DBG=y

0 comments on commit 8e307a3

Please sign in to comment.
You can’t perform that action at this time.