This is the mail archive of the
ecos-patches@sources.redhat.com
mailing list for the eCos project.
RedBoot - improve multiple device handling
- From: Gary Thomas <gary at mlbassoc dot com>
- To: eCos patches <ecos-patches at sources dot redhat dot com>
- Date: 09 Oct 2003 14:25:55 -0600
- Subject: RedBoot - improve multiple device handling
- Organization: MLB Associates
All devices will now be initialized and the appropriate one
chosen for I/O. This simplifies some things downstream, e.g.
Linux drivers can assume that RedBoot has set up the network
device (ESA) addresses and not have to bother with this.
--
Gary Thomas <gary@mlbassoc.com>
MLB Associates
Index: redboot/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/ChangeLog,v
retrieving revision 1.147
diff -u -5 -p -r1.147 ChangeLog
--- redboot/current/ChangeLog 6 Oct 2003 22:37:51 -0000 1.147
+++ redboot/current/ChangeLog 9 Oct 2003 20:21:55 -0000
@@ -1,5 +1,12 @@
+2003-10-09 Gary Thomas <gary@mlbassoc.com>
+
+ * src/net/net_io.c (net_init):
+ * include/net/net.h: Rework handling of multiple network devices. All
+ devices will now be initialized, with either the first or the default
+ device actually used for I/O.
+
2003-10-06 Gary Thomas <gary@mlbassoc.com>
* src/net/net_io.c:
* src/net/bootp.c: Fix some compile problems if GATEWAY support is disabled.
Index: redboot/current/include/net/net.h
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/include/net/net.h,v
retrieving revision 1.17
diff -u -5 -p -r1.17 net.h
--- redboot/current/include/net/net.h 15 Jul 2003 16:21:41 -0000 1.17
+++ redboot/current/include/net/net.h 9 Oct 2003 20:18:32 -0000
@@ -63,10 +63,11 @@
#include <string.h>
extern bool net_debug;
#ifdef CYGPKG_IO_ETH_DRIVERS
# include <pkgconf/io_eth_drivers.h>
+# include <cyg/io/eth/eth_drv.h> // Logical driver interfaces
# ifdef CYGDBG_IO_ETH_DRIVERS_DEBUG
extern int cyg_io_eth_net_debug;
# endif
#endif
@@ -347,13 +348,13 @@ typedef struct _tcp_socket {
dword seq;
char pktbuf[ETH_MAX_PKTLEN];
} tcp_socket_t;
/*
- * Our address.
+ * Address information for local device
*/
-extern enet_addr_t __local_enet_addr;
+#define __local_enet_addr __local_enet_sc->sc_arpcom.esa
extern ip_addr_t __local_ip_addr;
#ifdef CYGSEM_REDBOOT_NETWORKING_USE_GATEWAY
extern ip_addr_t __local_ip_gate;
extern ip_addr_t __local_ip_mask;
#endif
Index: redboot/current/src/net/net_io.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/redboot/current/src/net/net_io.c,v
retrieving revision 1.36
diff -u -5 -p -r1.36 net_io.c
--- redboot/current/src/net/net_io.c 6 Oct 2003 22:37:51 -0000 1.36
+++ redboot/current/src/net/net_io.c 9 Oct 2003 20:14:17 -0000
@@ -52,11 +52,10 @@
//####DESCRIPTIONEND####
//
//==========================================================================
#include <redboot.h>
-#include <cyg/io/eth/eth_drv.h> // Logical driver interfaces
#include <net/net.h>
#include <cyg/hal/hal_misc.h> // Helper functions
#include <cyg/hal/hal_if.h> // HAL I/O interfaces
#include <cyg/hal/drv_api.h>
#include <cyg/hal/hal_intr.h>
@@ -647,15 +646,29 @@ net_devindex(char *name)
if (!strcmp(name, devname))
return index;
return -1;
}
+static void
+show_eth_info(void)
+{
+ diag_printf("Ethernet %s: MAC address %02x:%02x:%02x:%02x:%02x:%02x\n",
+ __local_enet_sc->dev_name,
+ __local_enet_addr[0],
+ __local_enet_addr[1],
+ __local_enet_addr[2],
+ __local_enet_addr[3],
+ __local_enet_addr[4],
+ __local_enet_addr[5]);
+}
+
void
net_init(void)
{
cyg_netdevtab_entry_t *t;
unsigned index;
+ struct eth_drv_sc *primary_net = (struct eth_drv_sc *)0;
#if defined(CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
char *default_devname;
int default_index;
#endif
@@ -696,43 +709,31 @@ net_init(void)
have_net = false;
// Make sure the recv buffers are set up
eth_drv_buffers_init();
__pktbuf_init();
- // Initialize network device.
- // Try default device first, then others
-#ifdef CYGNUM_REDBOOT_DEFAULT_NETWORK_DEVICE
- default_devname = net_devname(CYGNUM_REDBOOT_DEFAULT_NETWORK_DEVICE);
-#endif
-
+ // Initialize network device(s).
#if defined(CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
default_index = net_devindex(default_devname);
if (default_index < 0)
default_index = 0;
- if ((t = net_devtab_entry(default_index)) != NULL) {
- if (t->init(t))
- t->status = CYG_NETDEVTAB_STATUS_AVAIL;
- else
#endif
- {
- for (index = 0; (t = net_devtab_entry(index)) != NULL; index++) {
+ for (index = 0; (t = net_devtab_entry(index)) != NULL; index++) {
+ if (t->init(t)) {
+ t->status = CYG_NETDEVTAB_STATUS_AVAIL;
+ if (primary_net == (struct eth_drv_sc *)0) {
+ primary_net = __local_enet_sc;
+ }
#if defined(CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
- if (index == default_index)
- continue;
+ if (index == default_index) {
+ primary_net = __local_enet_sc;
+ }
#endif
- if (t->init(t)) {
- t->status = CYG_NETDEVTAB_STATUS_AVAIL;
- break; // stop after first good device found
- } else {
- // What to do if device init fails?
- t->status = 0; // Device not [currently] available
- }
- }
- }
-#if defined(CYGHWR_NET_DRIVERS) && (CYGHWR_NET_DRIVERS > 1)
+ }
}
-#endif
+ __local_enet_sc = primary_net;
+
if (!__local_enet_sc) {
diag_printf("No network interfaces found\n");
return;
}
// Initialize the network [if present]
@@ -741,18 +742,11 @@ net_init(void)
have_net = true;
} else {
// Is it an unset address, or has it been set to a static addr
if (__local_ip_addr[0] == 0 && __local_ip_addr[1] == 0 &&
__local_ip_addr[2] == 0 && __local_ip_addr[3] == 0) {
- diag_printf("Ethernet %s: MAC address %02x:%02x:%02x:%02x:%02x:%02x\n",
- __local_enet_sc->dev_name,
- __local_enet_addr[0],
- __local_enet_addr[1],
- __local_enet_addr[2],
- __local_enet_addr[3],
- __local_enet_addr[4],
- __local_enet_addr[5]);
+ show_eth_info();
diag_printf("Can't get BOOTP info for device!\n");
} else {
diag_printf("Can't get BOOTP info, using default IP address\n");
have_net = true;
}
@@ -764,18 +758,11 @@ net_init(void)
if (__arp_request((ip_addr_t *)__local_ip_addr, &enet_addr, 1) >= 0) {
diag_printf("Warning: IP address %s in use\n", inet_ntoa((in_addr_t *)&__local_ip_addr));
}
}
if (have_net) {
- diag_printf("Ethernet %s: MAC address %02x:%02x:%02x:%02x:%02x:%02x\n",
- __local_enet_sc->dev_name,
- __local_enet_addr[0],
- __local_enet_addr[1],
- __local_enet_addr[2],
- __local_enet_addr[3],
- __local_enet_addr[4],
- __local_enet_addr[5]);
+ show_eth_info();
#ifdef CYGSEM_REDBOOT_FLASH_CONFIG
flash_get_IP("bootp_server_ip", &my_bootp_info.bp_siaddr);
#endif
#ifdef CYGPKG_REDBOOT_NETWORKING_DNS
Index: io/eth/current/ChangeLog
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/io/eth/current/ChangeLog,v
retrieving revision 1.45
diff -u -5 -p -r1.45 ChangeLog
--- io/eth/current/ChangeLog 19 Aug 2003 17:23:01 -0000 1.45
+++ io/eth/current/ChangeLog 9 Oct 2003 20:22:51 -0000
@@ -1,5 +1,10 @@
+2003-10-09 Gary Thomas <gary@mlbassoc.com>
+
+ * src/stand_alone/eth_drv.c: Obviate __local_enet_addr, since this
+ same information is already kept in the driver structure *__local_enet_sc
+
2003-08-19 Gary Thomas <gary@mlbassoc.com>
* src/stand_alone/eth_drv.c:
* src/net/eth_drv.c: Improve network speeds by reducing some
overhead and also the delay when sending a packet.
Index: io/eth/current/src/stand_alone/eth_drv.c
===================================================================
RCS file: /misc/cvsfiles/ecos/packages/io/eth/current/src/stand_alone/eth_drv.c,v
retrieving revision 1.19
diff -u -5 -p -r1.19 eth_drv.c
--- io/eth/current/src/stand_alone/eth_drv.c 19 Aug 2003 17:23:01 -0000 1.19
+++ io/eth/current/src/stand_alone/eth_drv.c 9 Oct 2003 20:16:02 -0000
@@ -84,11 +84,10 @@ int cyg_io_eth_net_debug = CYGDBG_IO_ETH
#else
#define DIAG_DUMP_BUF_HDR( a, b )
#define DIAG_DUMP_BUF_BDY( a, b )
#endif
-unsigned char __local_enet_addr[ETHER_ADDR_LEN+2];
struct eth_drv_sc *__local_enet_sc = NULL;
#ifdef CYGSEM_IO_ETH_DRIVERS_PASS_PACKETS
//
// Horrible hack: In order to allow the stand-alone networking code to work
@@ -225,11 +224,10 @@ eth_drv_init(struct eth_drv_sc *sc, unsi
{
// enaddr == 0 -> hardware init was incomplete (no ESA)
if (enaddr != 0) {
// Set up hardware address
memcpy(&sc->sc_arpcom.esa, enaddr, ETHER_ADDR_LEN);
- memcpy(__local_enet_addr, enaddr, ETHER_ADDR_LEN);
__local_enet_sc = sc;
eth_drv_start(sc);
}
}
@@ -278,11 +276,11 @@ eth_drv_write(char *eth_hdr, char *buf,
sc->funs->eth_drv_old = sc->funs->eth_drv;
sc->funs->eth_drv = ð_drv_funs; // Substitute stand-alone driver
old_state = sc->state;
if (!old_state & ETH_DRV_STATE_ACTIVE) {
// This interface not fully initialized, do it now
- (sc->funs->start)(sc, (unsigned char *)&__local_enet_addr, 0);
+ (sc->funs->start)(sc, (unsigned char *)sc->sc_arpcom.esa, 0);
sc->state |= ETH_DRV_STATE_ACTIVE;
}
}
}
@@ -390,11 +388,11 @@ eth_drv_read(char *eth_hdr, char *buf, i
sc->funs->eth_drv_old = sc->funs->eth_drv;
sc->funs->eth_drv = ð_drv_funs; // Substitute stand-alone driver
old_state = sc->state;
if (!old_state & ETH_DRV_STATE_ACTIVE) {
// This interface not fully initialized, do it now
- (sc->funs->start)(sc, (unsigned char *)&__local_enet_addr, 0);
+ (sc->funs->start)(sc, (unsigned char *)sc->sc_arpcom.esa, 0);
sc->state |= ETH_DRV_STATE_ACTIVE;
}
}
}
(sc->funs->poll)(sc); // Give the driver a chance to fetch packets