embox

Форк
0
106 строк · 2.1 Кб
1
/**
2
 * @file
3
 * @brief Usermode ethernet driver (supported by emvisor)
4
 *
5
 * @author  Anton Kozlov
6
 * @date    31.03.2013
7
 */
8

9
#include <errno.h>
10
#include <string.h>
11
#include <kernel/irq.h>
12
#include <net/l2/ethernet.h>
13
#include <net/netdevice.h>
14
#include <net/inetdevice.h>
15
#include <arpa/inet.h>
16
#include <net/skbuff.h>
17
#include <embox/unit.h>
18
#include <net/l0/net_entry.h>
19

20
#include <kernel/printk.h>
21
#include <kernel/host.h>
22

23
EMBOX_UNIT_INIT(umether_init);
24

25
static int umether_xmit(struct net_device *dev, struct sk_buff *skb) {
26
	struct host_net_adp *hnet = netdev_priv(dev);
27

28
	host_net_tx(hnet, skb->mac.raw, skb->len);
29
	skb_free(skb);
30

31
	return 0;
32
}
33

34
static int umether_start(struct net_device *dev) {
35
	struct host_net_adp *hnet = netdev_priv(dev);
36

37
	return host_net_cfg(hnet, HOST_NET_START);
38
}
39

40
static int umether_stop(struct net_device *dev) {
41
	struct host_net_adp *hnet = netdev_priv(dev);
42

43
	return host_net_cfg(hnet, HOST_NET_STOP);
44
}
45

46
static int umether_setmac(struct net_device *dev, const void *addr) {
47
	return ENOERR;
48
}
49

50
static irq_return_t umether_irq(unsigned int irq_num, void *dev_id) {
51
	struct net_device *dev = (struct net_device *) dev_id;
52
	struct host_net_adp *hnet = netdev_priv(dev);
53
	struct sk_buff *skb;
54
	int len;
55

56
	while ((len = host_net_rx_count(hnet))) {
57
		if (!(skb = skb_alloc(len))) {
58
			return IRQ_NONE;
59
		}
60

61
		host_net_rx(hnet, skb->mac.raw, len);
62
		skb->dev = dev;
63

64
		netif_rx(skb);
65
	}
66

67
	return IRQ_NONE;
68
}
69

70
static const struct net_driver umether_drv_ops = {
71
	.xmit = umether_xmit,
72
	.start = umether_start,
73
	.stop = umether_stop,
74
	.set_macaddr = umether_setmac,
75
};
76

77
static int umether_init(void) {
78
	int res = 0;
79
	struct net_device *nic;
80
	struct host_net_adp *hnet;
81

82
	nic = etherdev_alloc(sizeof(struct host_net_adp));
83
	if (nic == NULL) {
84
		return -ENOMEM;
85
	}
86

87
	nic->drv_ops = &umether_drv_ops;
88
	nic->irq = HOST_NET_IRQ;
89

90
	hnet = netdev_priv(nic);
91

92
	res = host_net_cfg(hnet, HOST_NET_INIT);
93
	if (res < 0) {
94
		etherdev_free(nic);
95
		printk("usermode: can't init network: %s\n", strerror(-res));
96
		return 0;
97
	}
98

99
	res = irq_attach(HOST_NET_IRQ, umether_irq, IF_SHARESUP, nic,
100
			"umether");
101
	if (res < 0) {
102
		return res;
103
	}
104

105
	return inetdev_register_dev(nic);
106
}
107

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.