net.c (182723) | net.c (183598) |
---|---|
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 182723 2008-09-03 15:39:50Z raj $"); | 29__FBSDID("$FreeBSD: head/sys/boot/uboot/lib/net.c 183598 2008-10-04 13:10:38Z 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> --- 130 unchanged lines hidden (view full) --- 168} 169 170static int 171net_get(struct iodesc *desc, void *pkt, size_t len, time_t timeout) 172{ 173 struct netif *nif = desc->io_netif; 174 struct uboot_softc *sc = nif->nif_devdata; 175 time_t t; | 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> --- 130 unchanged lines hidden (view full) --- 168} 169 170static int 171net_get(struct iodesc *desc, void *pkt, size_t len, time_t timeout) 172{ 173 struct netif *nif = desc->io_netif; 174 struct uboot_softc *sc = nif->nif_devdata; 175 time_t t; |
176 int length; | 176 int err, rlen; |
177 178#if defined(NETIF_DEBUG) 179 printf("net_get: pkt %x, len %d, timeout %d\n", pkt, len, timeout); 180#endif 181 t = getsecs(); 182 do { | 177 178#if defined(NETIF_DEBUG) 179 printf("net_get: pkt %x, len %d, timeout %d\n", pkt, len, timeout); 180#endif 181 t = getsecs(); 182 do { |
183 length = ub_dev_recv(sc->sc_handle, sc->sc_rxbuf, len); 184 } while ((length == -1 || length == 0) && 185 (getsecs() - t < timeout)); | 183 err = ub_dev_recv(sc->sc_handle, sc->sc_rxbuf, len, &rlen); |
186 | 184 |
185 if (err != 0) { 186 printf("net_get: ub_dev_recv() failed, error=%d\n", 187 err); 188 rlen = 0; 189 break; 190 } 191 } while ((rlen == -1 || rlen == 0) && (getsecs() - t < timeout)); 192 |
|
187#if defined(NETIF_DEBUG) | 193#if defined(NETIF_DEBUG) |
188 printf("net_get: received len %d (%x)\n", length, length); | 194 printf("net_get: received len %d (%x)\n", rlen, rlen); |
189#endif 190 | 195#endif 196 |
191 if (length > 0) { 192 memcpy(pkt, sc->sc_rxbuf, MIN(len, length)); 193 if (length != len) { | 197 if (rlen > 0) { 198 memcpy(pkt, sc->sc_rxbuf, MIN(len, rlen)); 199 if (rlen != len) { |
194#if defined(NETIF_DEBUG) | 200#if defined(NETIF_DEBUG) |
195 printf("net_get: len %x, length %x\n", len, length); | 201 printf("net_get: len %x, rlen %x\n", len, rlen); |
196#endif 197 } | 202#endif 203 } |
198 return (length); | 204 return (rlen); |
199 } 200 201 return (-1); 202} 203 | 205 } 206 207 return (-1); 208} 209 |
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; 212 --- 37 unchanged lines hidden --- | 210static void 211net_init(struct iodesc *desc, void *machdep_hint) 212{ 213 struct netif *nif = desc->io_netif; 214 struct uboot_softc *sc; 215 struct device_info *di; 216 int err; 217 --- 37 unchanged lines hidden --- |