+// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2015 National Instruments
*
* (C) Copyright 2015
* Joe Hershberger <joe.hershberger@ni.com>
- *
- * SPDX-License-Identifier: GPL-2.0
*/
#include <common.h>
#include <dm.h>
#include <malloc.h>
#include <net.h>
+#include <asm/test.h>
DECLARE_GLOBAL_DATA_PTR;
*/
struct eth_sandbox_priv {
uchar fake_host_hwaddr[ARP_HLEN];
- IPaddr_t fake_host_ipaddr;
+ struct in_addr fake_host_ipaddr;
uchar *recv_packet_buffer;
int recv_packet_length;
};
+static bool disabled[8] = {false};
+static bool skip_timeout;
+
+/*
+ * sandbox_eth_disable_response()
+ *
+ * index - The alias index (also DM seq number)
+ * disable - If non-zero, ignore sent packets and don't send mock response
+ */
+void sandbox_eth_disable_response(int index, bool disable)
+{
+ disabled[index] = disable;
+}
+
+/*
+ * sandbox_eth_skip_timeout()
+ *
+ * When the first packet read is attempted, fast-forward time
+ */
+void sandbox_eth_skip_timeout(void)
+{
+ skip_timeout = true;
+}
+
static int sb_eth_start(struct udevice *dev)
{
struct eth_sandbox_priv *priv = dev_get_priv(dev);
debug("eth_sandbox: Start\n");
- fdtdec_get_byte_array(gd->fdt_blob, dev->of_offset, "fake-host-hwaddr",
- priv->fake_host_hwaddr, ARP_HLEN);
+ fdtdec_get_byte_array(gd->fdt_blob, dev_of_offset(dev),
+ "fake-host-hwaddr", priv->fake_host_hwaddr,
+ ARP_HLEN);
priv->recv_packet_buffer = net_rx_packets[0];
return 0;
}
debug("eth_sandbox: Send packet %d\n", length);
+ if (dev->seq >= 0 && dev->seq < ARRAY_SIZE(disabled) &&
+ disabled[dev->seq])
+ return 0;
+
if (ntohs(eth->et_protlen) == PROT_ARP) {
struct arp_hdr *arp = packet + ETHER_HDR_SIZE;
struct arp_hdr *arp_recv;
/* store this as the assumed IP of the fake host */
- priv->fake_host_ipaddr = NetReadIP(&arp->ar_tpa);
+ priv->fake_host_ipaddr = net_read_ip(&arp->ar_tpa);
/* Formulate a fake response */
eth_recv = (void *)priv->recv_packet_buffer;
memcpy(eth_recv->et_dest, eth->et_src, ARP_HLEN);
arp_recv->ar_op = htons(ARPOP_REPLY);
memcpy(&arp_recv->ar_sha, priv->fake_host_hwaddr,
ARP_HLEN);
- NetWriteIP(&arp_recv->ar_spa, priv->fake_host_ipaddr);
+ net_write_ip(&arp_recv->ar_spa, priv->fake_host_ipaddr);
memcpy(&arp_recv->ar_tha, &arp->ar_sha, ARP_HLEN);
- NetCopyIP(&arp_recv->ar_tpa, &arp->ar_spa);
+ net_copy_ip(&arp_recv->ar_tpa, &arp->ar_spa);
priv->recv_packet_length = ETHER_HDR_SIZE +
ARP_HDR_SIZE;
ARP_HLEN);
ipr->ip_sum = 0;
ipr->ip_off = 0;
- NetCopyIP((void *)&ipr->ip_dst, &ip->ip_src);
- NetWriteIP((void *)&ipr->ip_src,
- priv->fake_host_ipaddr);
+ net_copy_ip((void *)&ipr->ip_dst, &ip->ip_src);
+ net_write_ip((void *)&ipr->ip_src,
+ priv->fake_host_ipaddr);
ipr->ip_sum = compute_ip_checksum(ipr,
IP_HDR_SIZE);
return 0;
}
-static int sb_eth_recv(struct udevice *dev, uchar **packetp)
+static int sb_eth_recv(struct udevice *dev, int flags, uchar **packetp)
{
struct eth_sandbox_priv *priv = dev_get_priv(dev);
+ if (skip_timeout) {
+ sandbox_timer_add_offset(11000UL);
+ skip_timeout = false;
+ }
+
if (priv->recv_packet_length) {
int lcl_recv_packet_length = priv->recv_packet_length;
{
struct eth_pdata *pdata = dev_get_platdata(dev);
- pdata->iobase = dev_get_addr(dev);
+ pdata->iobase = devfdt_get_addr(dev);
return 0;
}