Changeset View
Changeset View
Standalone View
Standalone View
head/stand/efi/libefi/efinet.c
Show All 34 Lines | |||||
#include <stand.h> | #include <stand.h> | ||||
#include <net.h> | #include <net.h> | ||||
#include <netif.h> | #include <netif.h> | ||||
#include <efi.h> | #include <efi.h> | ||||
#include <efilib.h> | #include <efilib.h> | ||||
#include "dev_net.h" | |||||
static EFI_GUID sn_guid = EFI_SIMPLE_NETWORK_PROTOCOL; | static EFI_GUID sn_guid = EFI_SIMPLE_NETWORK_PROTOCOL; | ||||
static void efinet_end(struct netif *); | static void efinet_end(struct netif *); | ||||
static ssize_t efinet_get(struct iodesc *, void **, time_t); | static ssize_t efinet_get(struct iodesc *, void **, time_t); | ||||
static void efinet_init(struct iodesc *, void *); | static void efinet_init(struct iodesc *, void *); | ||||
static int efinet_match(struct netif *, void *); | static int efinet_match(struct netif *, void *); | ||||
static int efinet_probe(struct netif *, void *); | static int efinet_probe(struct netif *, void *); | ||||
static ssize_t efinet_put(struct iodesc *, void *, size_t); | static ssize_t efinet_put(struct iodesc *, void *, size_t); | ||||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | if (status != EFI_NOT_READY) | ||||
break; | break; | ||||
} | } | ||||
if (ret == -1) | if (ret == -1) | ||||
free(buf); | free(buf); | ||||
return (ret); | return (ret); | ||||
} | } | ||||
/* | |||||
* Loader uses BOOTP/DHCP and also uses RARP as a fallback to populate | |||||
* network parameters and problems with DHCP servers can cause the loader | |||||
* to fail to populate them. Allow the device to ask about the basic | |||||
* network parameters and if present use them. | |||||
*/ | |||||
static void | static void | ||||
efi_env_net_params(struct iodesc *desc) | |||||
{ | |||||
char *envstr; | |||||
in_addr_t ipaddr, mask, gwaddr, serveraddr; | |||||
n_long rootaddr; | |||||
if ((envstr = getenv("rootpath")) != NULL) | |||||
strlcpy(rootpath, envstr, sizeof(rootpath)); | |||||
/* | |||||
* Get network parameters. | |||||
*/ | |||||
envstr = getenv("ipaddr"); | |||||
ipaddr = (envstr != NULL) ? inet_addr(envstr) : 0; | |||||
envstr = getenv("netmask"); | |||||
mask = (envstr != NULL) ? inet_addr(envstr) : 0; | |||||
envstr = getenv("gatewayip"); | |||||
gwaddr = (envstr != NULL) ? inet_addr(envstr) : 0; | |||||
envstr = getenv("serverip"); | |||||
serveraddr = (envstr != NULL) ? inet_addr(envstr) : 0; | |||||
/* No network params. */ | |||||
if (ipaddr == 0 && mask == 0 && gwaddr == 0 && serveraddr == 0) | |||||
return; | |||||
/* Partial network params. */ | |||||
if (ipaddr == 0 || mask == 0 || gwaddr == 0 || serveraddr == 0) { | |||||
printf("Incomplete network settings from U-Boot\n"); | |||||
return; | |||||
} | |||||
/* | |||||
* Set network parameters. | |||||
*/ | |||||
myip.s_addr = ipaddr; | |||||
netmask = mask; | |||||
gateip.s_addr = gwaddr; | |||||
servip.s_addr = serveraddr; | |||||
/* | |||||
* There must be a rootpath. It may be ip:/path or it may be just the | |||||
* path in which case the ip needs to be serverip. | |||||
*/ | |||||
rootaddr = net_parse_rootpath(); | |||||
if (rootaddr == INADDR_NONE) | |||||
rootaddr = serveraddr; | |||||
rootip.s_addr = rootaddr; | |||||
#ifdef EFINET_DEBUG | |||||
printf("%s: ip=%s\n", __func__, inet_ntoa(myip)); | |||||
printf("%s: mask=%s\n", __func__, intoa(netmask)); | |||||
printf("%s: gateway=%s\n", __func__, inet_ntoa(gateip)); | |||||
printf("%s: server=%s\n", __func__, inet_ntoa(servip)); | |||||
#endif | |||||
desc->myip = myip; | |||||
} | |||||
static void | |||||
efinet_init(struct iodesc *desc, void *machdep_hint) | efinet_init(struct iodesc *desc, void *machdep_hint) | ||||
{ | { | ||||
struct netif *nif = desc->io_netif; | struct netif *nif = desc->io_netif; | ||||
EFI_SIMPLE_NETWORK *net; | EFI_SIMPLE_NETWORK *net; | ||||
EFI_HANDLE h; | EFI_HANDLE h; | ||||
EFI_STATUS status; | EFI_STATUS status; | ||||
UINT32 mask; | UINT32 mask; | ||||
/* Attempt to get netboot params from env */ | |||||
efi_env_net_params(desc); | |||||
if (nif->nif_driver->netif_ifs[nif->nif_unit].dif_unit < 0) { | if (nif->nif_driver->netif_ifs[nif->nif_unit].dif_unit < 0) { | ||||
printf("Invalid network interface %d\n", nif->nif_unit); | printf("Invalid network interface %d\n", nif->nif_unit); | ||||
return; | return; | ||||
} | } | ||||
h = nif->nif_driver->netif_ifs[nif->nif_unit].dif_private; | h = nif->nif_driver->netif_ifs[nif->nif_unit].dif_private; | ||||
status = BS->HandleProtocol(h, &sn_guid, (VOID **)&nif->nif_devdata); | status = BS->HandleProtocol(h, &sn_guid, (VOID **)&nif->nif_devdata); | ||||
▲ Show 20 Lines • Show All 176 Lines • Show Last 20 Lines |