xref: /openbmc/u-boot/arch/sandbox/include/asm/eth.h (revision 9cbe5972c3c00e974482181cd4062d9229a9b7d5)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (c) 2015 National Instruments
4  *
5  * (C) Copyright 2015
6  * Joe Hershberger <joe.hershberger@ni.com>
7  */
8 
9 #ifndef __ETH_H
10 #define __ETH_H
11 
12 void sandbox_eth_disable_response(int index, bool disable);
13 
14 void sandbox_eth_skip_timeout(void);
15 
16 /*
17  * sandbox_eth_arp_req_to_reply()
18  *
19  * Check for an arp request to be sent. If so, inject a reply
20  *
21  * @dev: device that received the packet
22  * @packet: pointer to the received pacaket buffer
23  * @len: length of received packet
24  * @return 0 if injected, -EAGAIN if not
25  */
26 int sandbox_eth_arp_req_to_reply(struct udevice *dev, void *packet,
27 				 unsigned int len);
28 
29 /*
30  * sandbox_eth_ping_req_to_reply()
31  *
32  * Check for a ping request to be sent. If so, inject a reply
33  *
34  * @dev: device that received the packet
35  * @packet: pointer to the received pacaket buffer
36  * @len: length of received packet
37  * @return 0 if injected, -EAGAIN if not
38  */
39 int sandbox_eth_ping_req_to_reply(struct udevice *dev, void *packet,
40 				  unsigned int len);
41 
42 /**
43  * A packet handler
44  *
45  * dev - device pointer
46  * pkt - pointer to the "sent" packet
47  * len - packet length
48  */
49 typedef int sandbox_eth_tx_hand_f(struct udevice *dev, void *pkt,
50 				   unsigned int len);
51 
52 /**
53  * struct eth_sandbox_priv - memory for sandbox mock driver
54  *
55  * fake_host_hwaddr - MAC address of mocked machine
56  * fake_host_ipaddr - IP address of mocked machine
57  * disabled - Will not respond
58  * recv_packet_buffer - buffers of the packet returned as received
59  * recv_packet_length - lengths of the packet returned as received
60  * recv_packets - number of packets returned
61  * tx_handler - function to generate responses to sent packets
62  * priv - a pointer to some structure a test may want to keep track of
63  */
64 struct eth_sandbox_priv {
65 	uchar fake_host_hwaddr[ARP_HLEN];
66 	struct in_addr fake_host_ipaddr;
67 	bool disabled;
68 	uchar * recv_packet_buffer[PKTBUFSRX];
69 	int recv_packet_length[PKTBUFSRX];
70 	int recv_packets;
71 	sandbox_eth_tx_hand_f *tx_handler;
72 	void *priv;
73 };
74 
75 /*
76  * Set packet handler
77  *
78  * handler - The func ptr to call on send. If NULL, set to default handler
79  */
80 void sandbox_eth_set_tx_handler(int index, sandbox_eth_tx_hand_f *handler);
81 
82 /*
83  * Set priv ptr
84  *
85  * priv - priv void ptr to store in the device
86  */
87 void sandbox_eth_set_priv(int index, void *priv);
88 
89 #endif /* __ETH_H */
90