net.c (177152) | net.c (182723) |
---|---|
1/*- 2 * Copyright (c) 2000-2001 Benno Rice 3 * Copyright (c) 2007 Semihalf, Rafal Jaworowski <raj@semihalf.com> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2000-2001 Benno Rice 3 * Copyright (c) 2007 Semihalf, Rafal Jaworowski <raj@semihalf.com> 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: --- 12 unchanged lines hidden (view full) --- 21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 */ 27 28#include <sys/cdefs.h> |
29__FBSDID("$FreeBSD: head/sys/boot/uboot/lib/net.c 177152 2008-03-13 17:54:21Z obrien $"); | 29__FBSDID("$FreeBSD: head/sys/boot/uboot/lib/net.c 182723 2008-09-03 15:39:50Z raj $"); |
30 31#include <sys/param.h> 32#include <sys/types.h> 33#include <sys/socket.h> 34 35#include <net/if.h> 36#include <netinet/in.h> 37#include <netinet/in_systm.h> 38#include <netinet/if_ether.h> 39#include <netinet/ip.h> 40 41#include <stand.h> 42#include <net.h> 43#include <netif.h> 44 45#include "api_public.h" | 30 31#include <sys/param.h> 32#include <sys/types.h> 33#include <sys/socket.h> 34 35#include <net/if.h> 36#include <netinet/in.h> 37#include <netinet/in_systm.h> 38#include <netinet/if_ether.h> 39#include <netinet/ip.h> 40 41#include <stand.h> 42#include <net.h> 43#include <netif.h> 44 45#include "api_public.h" |
46#include "glue.h" |
|
46#include "libuboot.h" 47 48#define NETIF_DEBUG 49#define NETIF_VERBOSE_DEBUG 50#undef NETIF_DEBUG 51#undef NETIF_VERBOSE_DEBUG 52 53 54static int net_probe(struct netif *, void *); 55static int net_match(struct netif *, void *); 56static void net_init(struct iodesc *, void *); 57static int net_get(struct iodesc *, void *, size_t, time_t); 58static int net_put(struct iodesc *, void *, size_t); 59static void net_end(struct netif *); 60 | 47#include "libuboot.h" 48 49#define NETIF_DEBUG 50#define NETIF_VERBOSE_DEBUG 51#undef NETIF_DEBUG 52#undef NETIF_VERBOSE_DEBUG 53 54 55static int net_probe(struct netif *, void *); 56static int net_match(struct netif *, void *); 57static void net_init(struct iodesc *, void *); 58static int net_get(struct iodesc *, void *, size_t, time_t); 59static int net_put(struct iodesc *, void *, size_t); 60static void net_end(struct netif *); 61 |
61struct device_info * ub_dev_get(int i); 62 | |
63extern int devs_no; 64extern struct netif_stats net_stats[]; 65 66struct netif_dif net_ifs[] = { 67 /* dif_unit dif_nsel dif_stats dif_private */ 68 { 0, 1, &net_stats[0], 0, }, 69}; 70 --- 31 unchanged lines hidden (view full) --- 102 103 printf("net_match: could not match network device\n"); 104 return (0); 105} 106 107static int 108net_probe(struct netif *nif, void *machdep_hint) 109{ | 62extern int devs_no; 63extern struct netif_stats net_stats[]; 64 65struct netif_dif net_ifs[] = { 66 /* dif_unit dif_nsel dif_stats dif_private */ 67 { 0, 1, &net_stats[0], 0, }, 68}; 69 --- 31 unchanged lines hidden (view full) --- 101 102 printf("net_match: could not match network device\n"); 103 return (0); 104} 105 106static int 107net_probe(struct netif *nif, void *machdep_hint) 108{ |
110 struct device_info *di; 111 int i; | 109 struct device_info *di; 110 int i; |
112 113 for (i = 0; i < devs_no; i++) | 111 112 for (i = 0; i < devs_no; i++) |
114 if (di = ub_dev_get(i)) | 113 if ((di = ub_dev_get(i)) != NULL) |
115 if (di->type == DEV_TYP_NET) 116 break; | 114 if (di->type == DEV_TYP_NET) 115 break; |
116 |
|
117 if (i == devs_no) { 118 printf("net_probe: no network devices found, maybe not" 119 " enumerated yet..?\n"); 120 return (-1); 121 } 122 123#if defined(NETIF_DEBUG) 124 printf("net_probe: network device found: %d\n", i); 125#endif 126 uboot_softc.sc_handle = i; 127 128 return (0); 129} 130 131static int 132net_put(struct iodesc *desc, void *pkt, size_t len) 133{ | 117 if (i == devs_no) { 118 printf("net_probe: no network devices found, maybe not" 119 " enumerated yet..?\n"); 120 return (-1); 121 } 122 123#if defined(NETIF_DEBUG) 124 printf("net_probe: network device found: %d\n", i); 125#endif 126 uboot_softc.sc_handle = i; 127 128 return (0); 129} 130 131static int 132net_put(struct iodesc *desc, void *pkt, size_t len) 133{ |
134 struct netif *nif = desc->io_netif; 135 struct uboot_softc *sc = nif->nif_devdata; | 134 struct netif *nif = desc->io_netif; 135 struct uboot_softc *sc = nif->nif_devdata; 136 size_t sendlen; 137 ssize_t rv; |
136 | 138 |
137 struct ether_header *eh; 138 size_t sendlen; 139 ssize_t rv; 140 | |
141#if defined(NETIF_DEBUG) | 139#if defined(NETIF_DEBUG) |
140 struct ether_header *eh; 141 |
|
142 printf("net_put: desc 0x%x, pkt 0x%x, len %d\n", desc, pkt, len); 143 eh = pkt; 144 printf("dst: %s ", ether_sprintf(eh->ether_dhost)); 145 printf("src: %s ", ether_sprintf(eh->ether_shost)); 146 printf("type: 0x%x\n", eh->ether_type & 0xffff); 147#endif 148 149 if (len < ETHER_MIN_LEN - ETHER_CRC_LEN) { --- 50 unchanged lines hidden (view full) --- 200 201 return (-1); 202} 203 204 205static void 206net_init(struct iodesc *desc, void *machdep_hint) 207{ | 142 printf("net_put: desc 0x%x, pkt 0x%x, len %d\n", desc, pkt, len); 143 eh = pkt; 144 printf("dst: %s ", ether_sprintf(eh->ether_dhost)); 145 printf("src: %s ", ether_sprintf(eh->ether_shost)); 146 printf("type: 0x%x\n", eh->ether_type & 0xffff); 147#endif 148 149 if (len < ETHER_MIN_LEN - ETHER_CRC_LEN) { --- 50 unchanged lines hidden (view full) --- 200 201 return (-1); 202} 203 204 205static void 206net_init(struct iodesc *desc, void *machdep_hint) 207{ |
208 struct netif *nif = desc->io_netif; 209 struct uboot_softc *sc; 210 struct device_info *di; 211 int err, i; | 208 struct netif *nif = desc->io_netif; 209 struct uboot_softc *sc; 210 struct device_info *di; 211 int err; |
212 213 sc = nif->nif_devdata = &uboot_softc; 214 | 212 213 sc = nif->nif_devdata = &uboot_softc; 214 |
215 if (err = ub_dev_open(sc->sc_handle)) | 215 if ((err = ub_dev_open(sc->sc_handle)) != 0) |
216 panic("%s%d: initialisation failed with error %d\n", 217 nif->nif_driver->netif_bname, nif->nif_unit, err); 218 219 /* Get MAC address */ 220 di = ub_dev_get(sc->sc_handle); 221 memcpy(desc->myea, di->di_net.hwaddr, 6); 222 if (memcmp (desc->myea, "\0\0\0\0\0\0", 6) == 0) { 223 panic("%s%d: empty ethernet address!", --- 11 unchanged lines hidden (view full) --- 235 sc->sc_txbufp += PKTALIGN - 236 (unsigned long)sc->sc_txbufp % PKTALIGN; 237} 238 239 240static void 241net_end(struct netif *nif) 242{ | 216 panic("%s%d: initialisation failed with error %d\n", 217 nif->nif_driver->netif_bname, nif->nif_unit, err); 218 219 /* Get MAC address */ 220 di = ub_dev_get(sc->sc_handle); 221 memcpy(desc->myea, di->di_net.hwaddr, 6); 222 if (memcmp (desc->myea, "\0\0\0\0\0\0", 6) == 0) { 223 panic("%s%d: empty ethernet address!", --- 11 unchanged lines hidden (view full) --- 235 sc->sc_txbufp += PKTALIGN - 236 (unsigned long)sc->sc_txbufp % PKTALIGN; 237} 238 239 240static void 241net_end(struct netif *nif) 242{ |
243 struct uboot_softc *sc = nif->nif_devdata; 244 int err; | 243 struct uboot_softc *sc = nif->nif_devdata; 244 int err; |
245 | 245 |
246 if (err = ub_dev_close(sc->sc_handle)) | 246 if ((err = ub_dev_close(sc->sc_handle)) != 0) |
247 panic("%s%d: net_end failed with error %d\n", 248 nif->nif_driver->netif_bname, nif->nif_unit, err); 249} | 247 panic("%s%d: net_end failed with error %d\n", 248 nif->nif_driver->netif_bname, nif->nif_unit, err); 249} |