blob: 435b8745c38fea2ecb2b3a062c68deec5e607586 [file] [log] [blame]
Joe Hershbergera346ca72015-03-22 17:09:21 -05001/*
2 * Copyright (c) 2015 National Instruments
3 *
4 * (C) Copyright 2015
5 * Joe Hershberger <joe.hershberger@ni.com>
6 *
7 * SPDX-License-Identifier: GPL-2.0
8 */
9
10#include <asm/eth-raw-os.h>
11#include <common.h>
12#include <dm.h>
13#include <malloc.h>
14#include <net.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
18
19static int sb_eth_raw_start(struct udevice *dev)
20{
21 struct eth_sandbox_raw_priv *priv = dev_get_priv(dev);
22 struct eth_pdata *pdata = dev_get_platdata(dev);
23 const char *interface;
24
25 debug("eth_sandbox_raw: Start\n");
26
27 interface = fdt_getprop(gd->fdt_blob, dev->of_offset,
28 "host-raw-interface", NULL);
29 if (interface == NULL)
30 return -EINVAL;
31
32 return sandbox_eth_raw_os_start(interface, pdata->enetaddr, priv);
33}
34
35static int sb_eth_raw_send(struct udevice *dev, void *packet, int length)
36{
37 struct eth_sandbox_raw_priv *priv = dev_get_priv(dev);
38
39 debug("eth_sandbox_raw: Send packet %d\n", length);
40
41 return sandbox_eth_raw_os_send(packet, length, priv);
42}
43
44static int sb_eth_raw_recv(struct udevice *dev, uchar **packetp)
45{
46 struct eth_sandbox_raw_priv *priv = dev_get_priv(dev);
47 int retval;
48 int length;
49
50 retval = sandbox_eth_raw_os_recv(net_rx_packets[0], &length, priv);
51
52 if (!retval && length) {
53 debug("eth_sandbox_raw: received packet %d\n",
54 length);
55 *packetp = net_rx_packets[0];
56 return length;
57 }
58 return retval;
59}
60
61static void sb_eth_raw_stop(struct udevice *dev)
62{
63 struct eth_sandbox_raw_priv *priv = dev_get_priv(dev);
64
65 debug("eth_sandbox_raw: Stop\n");
66
67 sandbox_eth_raw_os_stop(priv);
68}
69
70static const struct eth_ops sb_eth_raw_ops = {
71 .start = sb_eth_raw_start,
72 .send = sb_eth_raw_send,
73 .recv = sb_eth_raw_recv,
74 .stop = sb_eth_raw_stop,
75};
76
77static int sb_eth_raw_ofdata_to_platdata(struct udevice *dev)
78{
79 struct eth_pdata *pdata = dev_get_platdata(dev);
80
81 pdata->iobase = dev_get_addr(dev);
82 return 0;
83}
84
85static const struct udevice_id sb_eth_raw_ids[] = {
86 { .compatible = "sandbox,eth-raw" },
87 { }
88};
89
90U_BOOT_DRIVER(eth_sandbox_raw) = {
91 .name = "eth_sandbox_raw",
92 .id = UCLASS_ETH,
93 .of_match = sb_eth_raw_ids,
94 .ofdata_to_platdata = sb_eth_raw_ofdata_to_platdata,
95 .ops = &sb_eth_raw_ops,
96 .priv_auto_alloc_size = sizeof(struct eth_sandbox_raw_priv),
97 .platdata_auto_alloc_size = sizeof(struct eth_pdata),
98};