9
0
Fork 0

net: remove switch/case in NetLoop()

Instead of having a big switch/case for every protocol, do
the right things in the individual functions before callong
NetLoop().

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Sascha Hauer 2009-08-19 15:00:06 +02:00
parent 8fe37b4e2e
commit a3a5927110
8 changed files with 31 additions and 61 deletions

View File

@ -145,6 +145,7 @@ U_BOOT_CMD_END
* after loading?
* @note This command is available only, if enabled in the menuconfig.
*/
extern void DhcpRequest(void);
#ifdef CONFIG_NET_DHCP
static int do_dhcp (cmd_tbl_t *cmdtp, int argc, char *argv[])
@ -154,7 +155,10 @@ static int do_dhcp (cmd_tbl_t *cmdtp, int argc, char *argv[])
if (NetLoopInit(DHCP) < 0)
return 1;
if ((size = NetLoop(DHCP)) < 0)
NetOurIP = 0;
DhcpRequest(); /* Basically same as BOOTP */
if ((size = NetLoop()) < 0)
return 1;
/* NetLoop ok, update environment */
@ -192,6 +196,9 @@ U_BOOT_CMD_END
int net_store_fd;
extern void TftpStart(void); /* Begin TFTP get */
extern void NfsStart(void);
static int
netboot_common (proto_t proto, cmd_tbl_t *cmdtp, int argc, char *argv[])
{
@ -223,7 +230,17 @@ netboot_common (proto_t proto, cmd_tbl_t *cmdtp, int argc, char *argv[])
if (NetLoopInit(proto) < 0)
goto out;
if ((size = NetLoop(proto)) < 0) {
switch (proto) {
case TFTP:
TftpStart();
break;
case NFS:
NfsStart();
default:
break;
}
if ((size = NetLoop()) < 0) {
rcode = size;
goto out;
}
@ -265,7 +282,7 @@ static int do_cdp (cmd_tbl_t *cmdtp, int argc, char *argv[])
if (NetLoopInit(CDP) < 0)
return 1;
r = NetLoop(CDP);
r = NetLoop();
if (r < 0) {
printf("cdp failed; perhaps not a CISCO switch?\n");
return 1;

View File

@ -318,7 +318,7 @@ extern int NetTimeOffset; /* offset time from UTC */
int NetLoopInit(proto_t);
/* Do the work */
int NetLoop(proto_t);
int NetLoop(void);
/* Shutdown adapters and cleanup */
void NetStop(void);

View File

@ -67,7 +67,6 @@ ulong seed1, seed2; /* seed for random BOOTP delay */
extern void BootpRequest (void);
/****************** DHCP Support *********************/
extern void DhcpRequest(void);
/* DHCP States */
typedef enum { INIT,

View File

@ -299,7 +299,7 @@ int NetLoopInit(proto_t protocol)
return ret;
}
int NetLoop(proto_t protocol)
int NetLoop(void)
{
/*
* Start the ball rolling with the given start function. From
@ -307,56 +307,6 @@ int NetLoop(proto_t protocol)
* packets and timer events.
*/
switch (protocol) {
#ifdef CONFIG_NET_TFTP
case TFTP:
/* always use ARP to get server ethernet address */
TftpStart();
break;
#endif
#ifdef CONFIG_NET_DHCP
case DHCP:
/* Start with a clean slate... */
NetOurIP = 0;
DhcpRequest(); /* Basically same as BOOTP */
break;
#endif
#ifdef CONFIG_NET_BOOTP
case BOOTP:
BootpRequest ();
break;
#endif
#ifdef CONFIG_NET_RARP
case RARP:
NetOurIP = 0;
RarpTry = 0;
RarpRequest ();
break;
#endif
#ifdef CONFIG_NET_PING
case PING:
PingStart();
break;
#endif
#ifdef CONFIG_NET_NFS
case NFS:
NfsStart();
break;
#endif
#ifdef CONFIG_NETCONSOLE
case NETCONS:
NcStart();
break;
#endif
#ifdef CONFIG_NET_SNTP
case SNTP:
SntpStart();
break;
#endif
default:
break;
}
NetBootFileXferSize = 0;
/*

View File

@ -100,7 +100,9 @@ int do_ping (cmd_tbl_t *cmdtp, int argc, char *argv[])
if (NetLoopInit(PING) < 0)
return 1;
if (NetLoop(PING) < 0) {
PingStart();
if (NetLoop() < 0) {
printf("ping failed; host %s is not alive\n", argv[1]);
return 1;
}

View File

@ -71,6 +71,9 @@ RarpRequest (void)
uchar *pkt;
ARP_t * rarp;
NetOurIP = 0;
RarpTry = 0;
printf("RARP broadcast %d\n", ++RarpTry);
pkt = NetTxPacket;

View File

@ -113,7 +113,9 @@ int do_sntp (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
if (NetLoopInit(SNTP) < 0)
return 1;
if (NetLoop(SNTP) < 0) {
SntpStart();
if (NetLoop() < 0) {
printf("SNTP failed: host %s not responding\n", argv[1]);
return 1;
}

View File

@ -13,9 +13,6 @@
* Global functions and variables.
*/
/* tftp.c */
extern void TftpStart (void); /* Begin TFTP get */
/**********************************************************************/
#endif /* __TFTP_H__ */