mirror of
https://github.com/opnsense/src.git
synced 2026-05-28 04:12:45 -04:00
Eliminate artificial increasing of 'netdev_opens' counter in loader's net_open().
This was introduced as a workaround long time ago for some Alpha firmware
(which is now gone), and actually prevented net_close() to ever be
called.
Certain firmwares (U-Boot) need local shutdown operations to be performed on a
network controller upon transaction end: such platform-specific hooks are
supposed to be called via netif_close() (from within net_close()).
This change effectively reverts the following CVS commit:
sys/boot/common/dev_net.c
revision 1.7
date: 2000/05/13 15:40:46; author: dfr; state: Exp; lines: +2 -1
Only probe network settings on the first open of the network device.
The alpha firmware takes a seriously long time to open the network device
the first time.
Also suppress excessive output while netbooting via loader, unless debugging.
While there, make sys/boot/uboot more style(9) compliant.
Reviewed by: imp
Approved by: cognet (mentor)
This commit is contained in:
parent
484202faab
commit
7572ed5a08
7 changed files with 101 additions and 87 deletions
|
|
@ -144,7 +144,6 @@ net_open(struct open_file *f, ...)
|
|||
return (error);
|
||||
}
|
||||
}
|
||||
netdev_opens++;
|
||||
}
|
||||
netdev_opens++;
|
||||
f->f_devdata = &netdev_sock;
|
||||
|
|
@ -245,7 +244,8 @@ net_getparams(sock)
|
|||
printf("net_open: bootparam/whoami RPC failed\n");
|
||||
return (EIO);
|
||||
}
|
||||
printf("net_open: client name: %s\n", hostname);
|
||||
if (debug)
|
||||
printf("net_open: client name: %s\n", hostname);
|
||||
|
||||
/*
|
||||
* Ignore the gateway from whoami (unreliable).
|
||||
|
|
@ -259,10 +259,11 @@ net_getparams(sock)
|
|||
}
|
||||
if (smask) {
|
||||
netmask = smask;
|
||||
printf("net_open: subnet mask: %s\n", intoa(netmask));
|
||||
if (debug)
|
||||
printf("net_open: subnet mask: %s\n", intoa(netmask));
|
||||
}
|
||||
if (gateip.s_addr)
|
||||
printf("net_open: net gateway: %s\n", inet_ntoa(gateip));
|
||||
if (gateip.s_addr && debug)
|
||||
printf("net_open: net gateway: %s\n", inet_ntoa(gateip));
|
||||
|
||||
/* Get the root server and pathname. */
|
||||
if (bp_getfile(sock, "root", &rootip, rootpath)) {
|
||||
|
|
@ -270,7 +271,7 @@ net_getparams(sock)
|
|||
return (EIO);
|
||||
}
|
||||
exit:
|
||||
/*
|
||||
/*
|
||||
* If present, strip the server's address off of the rootpath
|
||||
* before passing it along. This allows us to be compatible with
|
||||
* the kernel's diskless (BOOTP_NFSROOT) booting conventions
|
||||
|
|
@ -285,8 +286,10 @@ net_getparams(sock)
|
|||
bcopy(&rootpath[i], &temp[0], strlen(&rootpath[i])+1);
|
||||
bcopy(&temp[0], &rootpath[0], strlen(&rootpath[i])+1);
|
||||
}
|
||||
printf("net_open: server addr: %s\n", inet_ntoa(rootip));
|
||||
printf("net_open: server path: %s\n", rootpath);
|
||||
if (debug) {
|
||||
printf("net_open: server addr: %s\n", inet_ntoa(rootip));
|
||||
printf("net_open: server path: %s\n", rootpath);
|
||||
}
|
||||
|
||||
d = socktodesc(sock);
|
||||
sprintf(temp, "%6D", d->myea, ":");
|
||||
|
|
|
|||
|
|
@ -52,18 +52,21 @@ struct console uboot_console = {
|
|||
static void
|
||||
uboot_cons_probe(struct console *cp)
|
||||
{
|
||||
|
||||
cp->c_flags |= (C_PRESENTIN | C_PRESENTOUT);
|
||||
}
|
||||
|
||||
static int
|
||||
uboot_cons_init(int arg)
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
uboot_cons_putchar(int c)
|
||||
{
|
||||
|
||||
if (c == '\n')
|
||||
ub_putc('\r');
|
||||
|
||||
|
|
@ -73,11 +76,13 @@ uboot_cons_putchar(int c)
|
|||
static int
|
||||
uboot_cons_getchar()
|
||||
{
|
||||
|
||||
return (ub_getc());
|
||||
}
|
||||
|
||||
static int
|
||||
uboot_cons_poll()
|
||||
{
|
||||
|
||||
return (ub_tstc());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ __FBSDID("$FreeBSD$");
|
|||
ssize_t
|
||||
uboot_copyin(const void *src, vm_offset_t dest, const size_t len)
|
||||
{
|
||||
|
||||
bcopy(src, (void *)dest, len);
|
||||
return (len);
|
||||
}
|
||||
|
|
@ -46,6 +47,7 @@ uboot_copyin(const void *src, vm_offset_t dest, const size_t len)
|
|||
ssize_t
|
||||
uboot_copyout(const vm_offset_t src, void *dest, const size_t len)
|
||||
{
|
||||
|
||||
bcopy((void *)src, dest, len);
|
||||
return (len);
|
||||
}
|
||||
|
|
@ -53,5 +55,6 @@ uboot_copyout(const vm_offset_t src, void *dest, const size_t len)
|
|||
ssize_t
|
||||
uboot_readin(const int fd, vm_offset_t dest, const size_t len)
|
||||
{
|
||||
|
||||
return (read(fd, (void *) dest, len));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ static int valid_sig(struct api_signature *sig)
|
|||
struct api_signature s;
|
||||
|
||||
if (sig == NULL)
|
||||
return 0;
|
||||
return (0);
|
||||
/*
|
||||
* Clear the checksum field (in the local copy) so as to calculate the
|
||||
* CRC with the same initial contents as at the time when the sig was
|
||||
|
|
@ -124,9 +124,9 @@ static int valid_sig(struct api_signature *sig)
|
|||
checksum = crc32((void *)&s, sizeof(struct api_signature));
|
||||
|
||||
if (checksum != sig->checksum)
|
||||
return 0;
|
||||
return (0);
|
||||
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -139,7 +139,7 @@ int api_search_sig(struct api_signature **sig) {
|
|||
unsigned char *sp, *spend;
|
||||
|
||||
if (sig == NULL)
|
||||
return 0;
|
||||
return (0);
|
||||
|
||||
if (uboot_address == 0)
|
||||
uboot_address = 255 * 1024 * 1024;
|
||||
|
|
@ -150,13 +150,13 @@ int api_search_sig(struct api_signature **sig) {
|
|||
if (!bcmp(sp, API_SIG_MAGIC, API_SIG_MAGLEN)) {
|
||||
*sig = (struct api_signature *)sp;
|
||||
if (valid_sig(*sig))
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
sp += API_SIG_MAGLEN;
|
||||
}
|
||||
|
||||
*sig = NULL;
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/****************************************
|
||||
|
|
@ -170,8 +170,8 @@ int ub_getc(void)
|
|||
int c;
|
||||
|
||||
if (!syscall(API_GETC, NULL, (uint32_t)&c))
|
||||
return -1;
|
||||
|
||||
return (-1);
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
|
|
@ -180,7 +180,7 @@ int ub_tstc(void)
|
|||
int t;
|
||||
|
||||
if (!syscall(API_TSTC, NULL, (uint32_t)&t))
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
|
@ -221,7 +221,7 @@ struct sys_info * ub_get_sys_info(void)
|
|||
memset(&mr, 0, sizeof(mr));
|
||||
|
||||
if (!syscall(API_GET_SYS_INFO, &err, (u_int32_t)&si))
|
||||
return NULL;
|
||||
return (NULL);
|
||||
|
||||
return ((err) ? NULL : &si);
|
||||
}
|
||||
|
|
@ -232,9 +232,10 @@ struct sys_info * ub_get_sys_info(void)
|
|||
* timing
|
||||
*
|
||||
****************************************/
|
||||
|
||||
|
||||
void ub_udelay(unsigned long usec)
|
||||
{
|
||||
|
||||
syscall(API_UDELAY, NULL, &usec);
|
||||
}
|
||||
|
||||
|
|
@ -243,9 +244,9 @@ unsigned long ub_get_timer(unsigned long base)
|
|||
unsigned long cur;
|
||||
|
||||
if (!syscall(API_GET_TIMER, NULL, &cur, &base))
|
||||
return 0;
|
||||
return (0);
|
||||
|
||||
return cur;
|
||||
return (cur);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -281,7 +282,7 @@ int ub_dev_enum(void)
|
|||
di = &devices[0];
|
||||
|
||||
if (!syscall(API_DEV_ENUM, NULL, di))
|
||||
return 0;
|
||||
return (0);
|
||||
|
||||
while (di->cookie != NULL) {
|
||||
|
||||
|
|
@ -296,9 +297,9 @@ int ub_dev_enum(void)
|
|||
|
||||
if (!syscall(API_DEV_ENUM, NULL, di))
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return n;
|
||||
return (n);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -313,13 +314,13 @@ int ub_dev_open(int handle)
|
|||
int err = 0;
|
||||
|
||||
if (handle < 0 || handle >= MAX_DEVS)
|
||||
return API_EINVAL;
|
||||
return (API_EINVAL);
|
||||
|
||||
di = &devices[handle];
|
||||
if (!syscall(API_DEV_OPEN, &err, di))
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
return err;
|
||||
return (err);
|
||||
}
|
||||
|
||||
int ub_dev_close(int handle)
|
||||
|
|
@ -327,13 +328,13 @@ int ub_dev_close(int handle)
|
|||
struct device_info *di;
|
||||
|
||||
if (handle < 0 || handle >= MAX_DEVS)
|
||||
return API_EINVAL;
|
||||
return (API_EINVAL);
|
||||
|
||||
di = &devices[handle];
|
||||
if (!syscall(API_DEV_CLOSE, NULL, di))
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -346,24 +347,26 @@ int ub_dev_close(int handle)
|
|||
*/
|
||||
static int dev_valid(int handle)
|
||||
{
|
||||
|
||||
if (handle < 0 || handle >= MAX_DEVS)
|
||||
return 0;
|
||||
return (0);
|
||||
|
||||
if (devices[handle].state != DEV_STA_OPEN)
|
||||
return 0;
|
||||
return (0);
|
||||
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int dev_stor_valid(int handle)
|
||||
{
|
||||
|
||||
if (!dev_valid(handle))
|
||||
return 0;
|
||||
return (0);
|
||||
|
||||
if (!(devices[handle].type & DEV_TYP_STOR))
|
||||
return 0;
|
||||
return (0);
|
||||
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
|
||||
int ub_dev_read(int handle, void *buf, lbasize_t len, lbastart_t start)
|
||||
|
|
@ -373,30 +376,31 @@ int ub_dev_read(int handle, void *buf, lbasize_t len, lbastart_t start)
|
|||
int err = 0;
|
||||
|
||||
if (!dev_stor_valid(handle))
|
||||
return API_ENODEV;
|
||||
return (API_ENODEV);
|
||||
|
||||
di = &devices[handle];
|
||||
if (!syscall(API_DEV_READ, &err, di, buf, &len, &start, &act_len))
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
if (err)
|
||||
return err;
|
||||
if (err)
|
||||
return (err);
|
||||
|
||||
if (act_len != len)
|
||||
return API_EIO;
|
||||
return (API_EIO);
|
||||
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int dev_net_valid(int handle)
|
||||
{
|
||||
|
||||
if (!dev_valid(handle))
|
||||
return 0;
|
||||
return (0);
|
||||
|
||||
if (devices[handle].type != DEV_TYP_NET)
|
||||
return 0;
|
||||
return (0);
|
||||
|
||||
return 1;
|
||||
return (1);
|
||||
}
|
||||
|
||||
int ub_dev_recv(int handle, void *buf, int len)
|
||||
|
|
@ -405,16 +409,16 @@ int ub_dev_recv(int handle, void *buf, int len)
|
|||
int err = 0, act_len;
|
||||
|
||||
if (!dev_net_valid(handle))
|
||||
return API_ENODEV;
|
||||
return (API_ENODEV);
|
||||
|
||||
di = &devices[handle];
|
||||
if (!syscall(API_DEV_READ, &err, di, buf, &len, &act_len))
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
if (err)
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
return act_len;
|
||||
return (act_len);
|
||||
}
|
||||
|
||||
int ub_dev_send(int handle, void *buf, int len)
|
||||
|
|
@ -423,13 +427,13 @@ int ub_dev_send(int handle, void *buf, int len)
|
|||
int err = 0;
|
||||
|
||||
if (!dev_net_valid(handle))
|
||||
return API_ENODEV;
|
||||
return (API_ENODEV);
|
||||
|
||||
di = &devices[handle];
|
||||
if (!syscall(API_DEV_WRITE, &err, di, buf, &len))
|
||||
return -1;
|
||||
return (-1);
|
||||
|
||||
return err;
|
||||
return (err);
|
||||
}
|
||||
|
||||
/****************************************
|
||||
|
|
@ -443,13 +447,14 @@ char * ub_env_get(const char *name)
|
|||
char *value;
|
||||
|
||||
if (!syscall(API_ENV_GET, NULL, (uint32_t)name, (uint32_t)&value))
|
||||
return NULL;
|
||||
return (NULL);
|
||||
|
||||
return value;
|
||||
return (value);
|
||||
}
|
||||
|
||||
void ub_env_set(const char *name, char *value)
|
||||
{
|
||||
|
||||
syscall(API_ENV_SET, NULL, (uint32_t)name, (uint32_t)value);
|
||||
}
|
||||
|
||||
|
|
@ -469,11 +474,11 @@ const char * ub_env_enum(const char *last)
|
|||
* internally, which handles such case
|
||||
*/
|
||||
if (!syscall(API_ENV_ENUM, NULL, (uint32_t)last, (uint32_t)&env))
|
||||
return NULL;
|
||||
return (NULL);
|
||||
|
||||
if (!env)
|
||||
/* no more env. variables to enumerate */
|
||||
return NULL;
|
||||
return (NULL);
|
||||
#if 0
|
||||
if (last && strncmp(env, last, strlen(last)) == 0);
|
||||
/* error, trying to enumerate non existing env. variable */
|
||||
|
|
@ -487,5 +492,5 @@ const char * ub_env_enum(const char *last)
|
|||
|
||||
env_name[i] = '\0';
|
||||
|
||||
return env_name;
|
||||
return (env_name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,18 +34,16 @@
|
|||
*/
|
||||
struct uboot_devdesc
|
||||
{
|
||||
struct devsw *d_dev;
|
||||
int d_type;
|
||||
int d_unit;
|
||||
union
|
||||
{
|
||||
struct
|
||||
{
|
||||
void *data;
|
||||
int slice;
|
||||
int partition;
|
||||
} disk;
|
||||
} d_kind;
|
||||
struct devsw *d_dev;
|
||||
int d_type;
|
||||
int d_unit;
|
||||
union {
|
||||
struct {
|
||||
void *data;
|
||||
int slice;
|
||||
int partition;
|
||||
} disk;
|
||||
} d_kind;
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -98,10 +98,10 @@ net_match(struct netif *nif, void *machdep_hint)
|
|||
char **a = (char **)machdep_hint;
|
||||
|
||||
if (memcmp("net", *a, 3) == 0)
|
||||
return 1;
|
||||
|
||||
return (1);
|
||||
|
||||
printf("net_match: could not match network device\n");
|
||||
return 0;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -116,16 +116,16 @@ net_probe(struct netif *nif, void *machdep_hint)
|
|||
break;
|
||||
if (i == devs_no) {
|
||||
printf("net_probe: no network devices found, maybe not\
|
||||
enumerated yet..?\n");
|
||||
return -1;
|
||||
enumerated yet..?\n");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
#if defined(NETIF_DEBUG)
|
||||
printf("net_probe: network device found: %d\n", i);
|
||||
#endif
|
||||
uboot_softc.sc_handle = i;
|
||||
|
||||
return 0;
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -164,7 +164,7 @@ net_put(struct iodesc *desc, void *pkt, size_t len)
|
|||
else
|
||||
rv = -1;
|
||||
|
||||
return rv;
|
||||
return (rv);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -177,8 +177,7 @@ net_get(struct iodesc *desc, void *pkt, size_t len, time_t timeout)
|
|||
int length;
|
||||
|
||||
#if defined(NETIF_DEBUG)
|
||||
printf("net_get: pkt %x, len %d, timeout %d\n", pkt, len,
|
||||
timeout);
|
||||
printf("net_get: pkt %x, len %d, timeout %d\n", pkt, len, timeout);
|
||||
#endif
|
||||
|
||||
t = getsecs();
|
||||
|
|
@ -198,10 +197,10 @@ net_get(struct iodesc *desc, void *pkt, size_t len, time_t timeout)
|
|||
printf("net_get: len %x, length %x\n", len, length);
|
||||
#endif
|
||||
}
|
||||
return length;
|
||||
return (length);
|
||||
}
|
||||
|
||||
return -1;
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -217,26 +216,25 @@ net_init(struct iodesc *desc, void *machdep_hint)
|
|||
|
||||
if (err = ub_dev_open(sc->sc_handle))
|
||||
panic("%s%d: initialisation failed with error %d\n",
|
||||
nif->nif_driver->netif_bname, nif->nif_unit, err);
|
||||
nif->nif_driver->netif_bname, nif->nif_unit, err);
|
||||
|
||||
/* Get MAC address */
|
||||
di = ub_dev_get(sc->sc_handle);
|
||||
memcpy(desc->myea, di->di_net.hwaddr, 6);
|
||||
if (memcmp (desc->myea, "\0\0\0\0\0\0", 6) == 0) {
|
||||
panic("%s%d: empty ethernet address!",
|
||||
nif->nif_driver->netif_bname, nif->nif_unit);
|
||||
nif->nif_driver->netif_bname, nif->nif_unit);
|
||||
}
|
||||
|
||||
#if defined(NETIF_DEBUG)
|
||||
printf("network: %s%d attached to %s\n", nif->nif_driver->netif_bname,
|
||||
nif->nif_unit, ether_sprintf(desc->myea));
|
||||
nif->nif_unit, ether_sprintf(desc->myea));
|
||||
#endif
|
||||
|
||||
/* Set correct alignment for TX packets */
|
||||
sc->sc_txbufp = sc->sc_txbuf;
|
||||
if ((unsigned long)sc->sc_txbufp % PKTALIGN)
|
||||
sc->sc_txbufp += PKTALIGN -
|
||||
(unsigned long)sc->sc_txbufp % PKTALIGN;
|
||||
sc->sc_txbufp += PKTALIGN - (unsigned long)sc->sc_txbufp % PKTALIGN;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -248,5 +246,5 @@ net_end(struct netif *nif)
|
|||
|
||||
if (err = ub_dev_close(sc->sc_handle))
|
||||
panic("%s%d: net_end failed with error %d\n",
|
||||
nif->nif_driver->netif_bname, nif->nif_unit, err);
|
||||
nif->nif_driver->netif_bname, nif->nif_unit, err);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@ time(time_t *tloc)
|
|||
int
|
||||
getsecs()
|
||||
{
|
||||
|
||||
return (time(NULL));
|
||||
}
|
||||
|
||||
|
|
@ -57,5 +58,6 @@ getsecs()
|
|||
void
|
||||
delay(int usecs)
|
||||
{
|
||||
|
||||
ub_udelay(usecs);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue