From aace975de13fdd71472fd4aaeddb866d37b885e7 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Sat, 20 Jun 2015 09:05:28 -0400 Subject: [PATCH] RTEMS: probe for PCI varient of NE2000 NIC Provided by QEMU --- src/libCom/RTEMS/Makefile | 4 +++ src/libCom/RTEMS/ne2kpci.c | 58 ++++++++++++++++++++++++++++++ src/libCom/RTEMS/rtems_netconfig.c | 10 +++++- 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 src/libCom/RTEMS/ne2kpci.c diff --git a/src/libCom/RTEMS/Makefile b/src/libCom/RTEMS/Makefile index 8652c669b..8d467b260 100644 --- a/src/libCom/RTEMS/Makefile +++ b/src/libCom/RTEMS/Makefile @@ -21,6 +21,10 @@ rtemsCom_SRCS += epicsRtemsInitHookPre.c rtemsCom_SRCS += epicsRtemsInitHookPost.c rtemsCom_SRCS += epicsMemFs.c +ifeq ($(T_A),RTEMS-pc386) +rtemsCom_SRCS += ne2kpci.c +endif + LIBRARY_RTEMS = rtemsCom include $(TOP)/configure/RULES diff --git a/src/libCom/RTEMS/ne2kpci.c b/src/libCom/RTEMS/ne2kpci.c new file mode 100644 index 000000000..909d885f1 --- /dev/null +++ b/src/libCom/RTEMS/ne2kpci.c @@ -0,0 +1,58 @@ +/*************************************************************************\ +* Copyright (c) 2015 Brookhaven Science Associates, as Operator of +* Brookhaven National Laboratory. +* EPICS BASE is distributed subject to a Software License Agreement found +* in file LICENSE that is included with this distribution. +\*************************************************************************/ +/* + * Wrapper around the ISA ne2000 driver to support detection of the PCI variant. + * Can be used with the ne2k_pci device provided by QEMU. + * + * eg. "qemu-system-i386 ... -net nic,model=ne2k_pci" + */ + +#include +#include +#include +#include +#include + +/* The plain ISA driver attach() + * which doesn't (can't?) do any test to see if + * the HW is really present + */ +extern int +rtems_ne_driver_attach (struct rtems_bsdnet_ifconfig *config, int attach); + +int +rtems_ne2kpci_driver_attach (struct rtems_bsdnet_ifconfig *config, int attach) +{ + uint8_t irq; + uint32_t bar0; + int B, D, F, ret; + printk("Probing for NE2000 on PCI (aka. Realtek 8029)\n"); + + if(pci_find_device(PCI_VENDOR_ID_REALTEK, PCI_DEVICE_ID_REALTEK_8029, 0, &B, &D, &F)) + { + printk("Not found\n"); + return 0; + } + + printk("Found %d:%d.%d\n", B, D, F); + + ret = pci_read_config_dword(B, D, F, PCI_BASE_ADDRESS_0, &bar0); + ret|= pci_read_config_byte(B, D, F, PCI_INTERRUPT_LINE, &irq); + + if(ret || (bar0&PCI_BASE_ADDRESS_SPACE)!=PCI_BASE_ADDRESS_SPACE_IO) + { + printk("Failed reading card config\n"); + return 0; + } + + config->irno = irq; + config->port = bar0&PCI_BASE_ADDRESS_IO_MASK; + + printk("Using port=0x%x irq=%u\n", (unsigned)config->port, config->irno); + + return rtems_ne_driver_attach(config, attach); +} diff --git a/src/libCom/RTEMS/rtems_netconfig.c b/src/libCom/RTEMS/rtems_netconfig.c index 832a6646b..d0c500c92 100644 --- a/src/libCom/RTEMS/rtems_netconfig.c +++ b/src/libCom/RTEMS/rtems_netconfig.c @@ -36,11 +36,19 @@ static struct rtems_bsdnet_ifconfig loopback_config = { * application directory and make the appropriate changes. */ #if defined(__i386__) + +extern int +rtems_ne2kpci_driver_attach (struct rtems_bsdnet_ifconfig *config, int attach); +static struct rtems_bsdnet_ifconfig ne2k_driver_config = { + "ne2", /* name */ + rtems_ne2kpci_driver_attach, /* attach function */ + &loopback_config, /* link to next interface */ +}; extern int rtems_fxp_attach (struct rtems_bsdnet_ifconfig *, int); static struct rtems_bsdnet_ifconfig fxp_driver_config = { "fxp1", /* name */ rtems_fxp_attach, /* attach function */ - &loopback_config, /* link to next interface */ + &ne2k_driver_config, /* link to next interface */ }; extern int rtems_3c509_driver_attach (struct rtems_bsdnet_ifconfig *, int); static struct rtems_bsdnet_ifconfig e3c509_driver_config = {