Changeset View
Changeset View
Standalone View
Standalone View
sys/boot/uboot/lib/net.c
/*- | /*- | ||||
* Copyright (c) 2000-2001 Benno Rice | * Copyright (c) 2000-2001 Benno Rice | ||||
* Copyright (c) 2007 Semihalf, Rafal Jaworowski <raj@semihalf.com> | * Copyright (c) 2007 Semihalf, Rafal Jaworowski <raj@semihalf.com> | ||||
* Copyright (c) 2016 Vladimir Belian <fate10@gmail.com> | |||||
* All rights reserved. | * All rights reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer. | * notice, this list of conditions and the following disclaimer. | ||||
* 2. Redistributions in binary form must reproduce the above copyright | * 2. Redistributions in binary form must reproduce the above copyright | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | struct netif_driver uboot_net = { | ||||
NENTS(net_ifs) /* netif_nifs */ | NENTS(net_ifs) /* netif_nifs */ | ||||
}; | }; | ||||
struct uboot_softc { | struct uboot_softc { | ||||
uint32_t sc_pad; | uint32_t sc_pad; | ||||
uint8_t sc_rxbuf[ETHER_MAX_LEN]; | uint8_t sc_rxbuf[ETHER_MAX_LEN]; | ||||
uint8_t sc_txbuf[ETHER_MAX_LEN + PKTALIGN]; | uint8_t sc_txbuf[ETHER_MAX_LEN + PKTALIGN]; | ||||
uint8_t *sc_txbufp; | uint8_t *sc_txbufp; | ||||
int sc_handle; /* device handle for ub_dev_xxx */ | struct device_info *sc_dinfo; /* device handle for ub_dev_xxx */ | ||||
}; | }; | ||||
static struct uboot_softc uboot_softc; | static struct uboot_softc uboot_softc; | ||||
/* | /* | ||||
* get_env_net_params() | * get_env_net_params() | ||||
* | * | ||||
* Attempt to obtain all the parms we need for netbooting from the U-Boot | * Attempt to obtain all the parms we need for netbooting from the U-Boot | ||||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Lines | net_match(struct netif *nif, void *machdep_hint) | ||||
printf("net_match: could not match network device\n"); | printf("net_match: could not match network device\n"); | ||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
net_probe(struct netif *nif, void *machdep_hint) | net_probe(struct netif *nif, void *machdep_hint) | ||||
{ | { | ||||
struct device_info *di; | int i = 0; | ||||
int i; | |||||
for (i = 0; i < devs_no; i++) | if ((uboot_softc.sc_dinfo = ub_dev_get(DEV_TYP_NET, &i)) == NULL) | ||||
if ((di = ub_dev_get(i)) != NULL) | |||||
if (di->type == DEV_TYP_NET) | |||||
break; | |||||
if (i == devs_no) { | |||||
printf("net_probe: no network devices found, maybe not" | printf("net_probe: no network devices found, maybe not" | ||||
" enumerated yet..?\n"); | " enumerated yet..?\n"); | ||||
return (-1); | return (-1); | ||||
} | |||||
#if defined(NETIF_DEBUG) | #if defined(NETIF_DEBUG) | ||||
printf("net_probe: network device found: %d\n", i); | printf("net_probe: network device found: %d\n", i - 1); | ||||
#endif | #endif | ||||
uboot_softc.sc_handle = i; | |||||
return (0); | return (0); | ||||
} | } | ||||
static int | static int | ||||
net_put(struct iodesc *desc, void *pkt, size_t len) | net_put(struct iodesc *desc, void *pkt, size_t len) | ||||
{ | { | ||||
struct netif *nif = desc->io_netif; | struct netif *nif = desc->io_netif; | ||||
struct uboot_softc *sc = nif->nif_devdata; | struct uboot_softc *sc = nif->nif_devdata; | ||||
Show All 13 Lines | #endif | ||||
if (len < ETHER_MIN_LEN - ETHER_CRC_LEN) { | if (len < ETHER_MIN_LEN - ETHER_CRC_LEN) { | ||||
sendlen = ETHER_MIN_LEN - ETHER_CRC_LEN; | sendlen = ETHER_MIN_LEN - ETHER_CRC_LEN; | ||||
bzero(sc->sc_txbufp, sendlen); | bzero(sc->sc_txbufp, sendlen); | ||||
} else | } else | ||||
sendlen = len; | sendlen = len; | ||||
memcpy(sc->sc_txbufp, pkt, len); | memcpy(sc->sc_txbufp, pkt, len); | ||||
rv = ub_dev_send(sc->sc_handle, sc->sc_txbufp, sendlen); | rv = ub_dev_send(sc->sc_dinfo, sc->sc_txbufp, sendlen); | ||||
#if defined(NETIF_DEBUG) | #if defined(NETIF_DEBUG) | ||||
printf("net_put: ub_send returned %d\n", rv); | printf("net_put: ub_send returned %d\n", rv); | ||||
#endif | #endif | ||||
if (rv == 0) | if (rv == 0) | ||||
rv = len; | rv = len; | ||||
else | else | ||||
rv = -1; | rv = -1; | ||||
Show All 9 Lines | net_get(struct iodesc *desc, void *pkt, size_t len, time_t timeout) | ||||
time_t t; | time_t t; | ||||
int err, rlen; | int err, rlen; | ||||
#if defined(NETIF_DEBUG) | #if defined(NETIF_DEBUG) | ||||
printf("net_get: pkt %p, len %d, timeout %d\n", pkt, len, timeout); | printf("net_get: pkt %p, len %d, timeout %d\n", pkt, len, timeout); | ||||
#endif | #endif | ||||
t = getsecs(); | t = getsecs(); | ||||
do { | do { | ||||
err = ub_dev_recv(sc->sc_handle, sc->sc_rxbuf, len, &rlen); | err = ub_dev_recv(sc->sc_dinfo, sc->sc_rxbuf, len, &rlen); | ||||
if (err != 0) { | if (err != 0) { | ||||
printf("net_get: ub_dev_recv() failed, error=%d\n", | printf("net_get: ub_dev_recv() failed, error=%d\n", | ||||
err); | err); | ||||
rlen = 0; | rlen = 0; | ||||
break; | break; | ||||
} | } | ||||
} while ((rlen == -1 || rlen == 0) && (getsecs() - t < timeout)); | } while ((rlen == -1 || rlen == 0) && (getsecs() - t < timeout)); | ||||
Show All 15 Lines | #endif | ||||
return (-1); | return (-1); | ||||
} | } | ||||
static void | static void | ||||
net_init(struct iodesc *desc, void *machdep_hint) | net_init(struct iodesc *desc, void *machdep_hint) | ||||
{ | { | ||||
struct netif *nif = desc->io_netif; | struct netif *nif = desc->io_netif; | ||||
struct uboot_softc *sc; | struct uboot_softc *sc; | ||||
struct device_info *di; | |||||
int err; | int err; | ||||
sc = nif->nif_devdata = &uboot_softc; | sc = nif->nif_devdata = &uboot_softc; | ||||
if ((err = ub_dev_open(sc->sc_handle)) != 0) | if ((err = ub_dev_open(sc->sc_dinfo)) != 0) | ||||
panic("%s%d: initialisation failed with error %d\n", | 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 */ | /* Get MAC address */ | ||||
di = ub_dev_get(sc->sc_handle); | memcpy(desc->myea, sc->sc_dinfo->di_net.hwaddr, 6); | ||||
memcpy(desc->myea, di->di_net.hwaddr, 6); | |||||
if (memcmp (desc->myea, "\0\0\0\0\0\0", 6) == 0) { | if (memcmp (desc->myea, "\0\0\0\0\0\0", 6) == 0) { | ||||
panic("%s%d: empty ethernet address!", | panic("%s%d: empty ethernet address!", | ||||
nif->nif_driver->netif_bname, nif->nif_unit); | nif->nif_driver->netif_bname, nif->nif_unit); | ||||
} | } | ||||
/* Attempt to get netboot params from the u-boot env. */ | /* Attempt to get netboot params from the u-boot env. */ | ||||
get_env_net_params(); | get_env_net_params(); | ||||
if (myip.s_addr != 0) | if (myip.s_addr != 0) | ||||
Show All 12 Lines | |||||
} | } | ||||
static void | static void | ||||
net_end(struct netif *nif) | net_end(struct netif *nif) | ||||
{ | { | ||||
struct uboot_softc *sc = nif->nif_devdata; | struct uboot_softc *sc = nif->nif_devdata; | ||||
int err; | int err; | ||||
if ((err = ub_dev_close(sc->sc_handle)) != 0) | if ((err = ub_dev_close(sc->sc_dinfo)) != 0) | ||||
panic("%s%d: net_end failed with error %d\n", | 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); | ||||
} | } |