Ver código fonte

First sketch

tags/v0.9.3
Michael Brown 19 anos atrás
pai
commit
0b561ce972
1 arquivos alterados com 126 adições e 0 exclusões
  1. 126
    0
      src/include/gpxe/netdevice.h

+ 126
- 0
src/include/gpxe/netdevice.h Ver arquivo

@@ -0,0 +1,126 @@
1
+#ifndef _NETDEVICE_H
2
+#define _NETDEVICE_H
3
+
4
+/** @file
5
+ *
6
+ * Net device interface
7
+ *
8
+ */
9
+
10
+#include <stdint.h>
11
+#include <gpxe/llh.h>
12
+
13
+struct net_device;
14
+struct pk_buff;
15
+
16
+/**
17
+ * A network device
18
+ *
19
+ * Note that this structure must represent a generic network device,
20
+ * not just an Ethernet device.
21
+ */
22
+struct net_device {
23
+	/** Build media-specific link-layer header
24
+	 *
25
+	 * @v netdev	Network device
26
+	 * @v pkb	Packet buffer
27
+	 * @ret rc	Return status code
28
+	 *
29
+	 * This method should convert the packet buffer's generic
30
+	 * link-layer header (a struct gpxehdr) into a media-specific
31
+	 * link-layer header (e.g. a struct ethhdr).  The generic
32
+	 * header should be removed from the buffer (via pkb_pull())
33
+	 * and the media-specific header should be prepended (via
34
+	 * pkb_push()) in its place.
35
+	 *
36
+	 * If a link-layer header cannot be constructed (e.g. because
37
+	 * of a missing ARP cache entry), then this method should
38
+	 * replace the contents of the packet buffer with an
39
+	 * appropriate ARP request or equivalent, and return -ENOENT.
40
+	 */
41
+	int ( * make_media_header ) ( struct net_device *netdev,
42
+				      struct pk_buff *pkb );
43
+	/** Transmit packet
44
+	 *
45
+	 * @v netdev	Network device
46
+	 * @v pkb	Packet buffer
47
+	 * @ret rc	Return status code
48
+	 *
49
+	 * This method should cause the hardware to initiate
50
+	 * transmission of the packet buffer.  The buffer may be
51
+	 * reused immediately after the method returns, and so the
52
+	 * method should either wait for packet transmission to
53
+	 * complete, or take a copy of the buffer contents.
54
+	 */
55
+	int ( * transmit ) ( struct net_device *netdev,
56
+			     struct pk_buff *pkb );
57
+	/** Poll for received packet
58
+	 *
59
+	 * @v netdev	Network device
60
+	 * @v retrieve	Flag indicating whether or not to retrieve packet
61
+	 * @v pkb	Packet buffer to contain received packet
62
+	 * @ret rc	Return status code
63
+	 *
64
+	 * This method should cause the hardware to check for a
65
+	 * received packet.  If no packet is available, the method
66
+	 * should return -EAGAIN (i.e. this method is *always*
67
+	 * considered to be a non-blocking read).  If a packet is
68
+	 * available, but @c retrieve is false, the method should
69
+	 * return zero for success.  If a packet is available and @c
70
+	 * retrieve is true, the method should fill the packet buffer
71
+	 * and return zero for success.
72
+	 */
73
+	int ( * poll ) ( struct net_device *netdev, int retrieve,
74
+			 struct pk_buff *pkb );
75
+	/** Parse link-layer header
76
+	 *
77
+	 * @v netdev	Network device
78
+	 * @v pkb	Packet buffer
79
+	 * @ret rc	Return status code
80
+	 *
81
+	 * This method should convert the packet buffer's
82
+	 * media-specific link-layer header (e.g. a struct ethhdr)
83
+	 * into a generic link-layer header (a struct gpxehdr).  It
84
+	 * performs the converse function of make_media_header().
85
+	 *
86
+	 * Note that the gpxehdr::addr and gpxehdr::addrlen fields
87
+	 * will not be filled in by this function, since doing so
88
+	 * would require understanding the network-layer header.
89
+	 */
90
+	int ( * make_generic_header ) ( struct net_device *netdev,
91
+					struct pk_buff *pkb );
92
+	/** Link-layer protocol
93
+	 *
94
+	 * This is an ARPHRD_XXX constant, in network-byte order.
95
+	 */
96
+	uint16_t ll_proto;
97
+	/** Link-layer address length */
98
+	uint8_t ll_addr_len;
99
+	/** Link-layer address
100
+	 *
101
+	 * For Ethernet, this is the MAC address.
102
+	 */
103
+	uint8_t ll_addr[MAX_LLH_ADDR_LEN];
104
+	/** Driver private data */
105
+	void *priv;
106
+};
107
+
108
+extern struct net_device static_single_netdev;
109
+
110
+/* Must be a macro because priv_data[] is of variable size */
111
+#define alloc_netdevice( priv_size ) ( {		\
112
+	static char priv_data[priv_size];		\
113
+	static_single_netdev.priv = priv_data;	\
114
+	&static_single_netdev; } )
115
+
116
+extern int register_netdevice ( struct net_device *netdev );
117
+
118
+static inline void unregister_netdevice ( struct net_device *netdev __unused ){
119
+	/* Do nothing */
120
+}
121
+
122
+static inline void free_netdevice ( struct net_device *netdev __unused ) {
123
+	/* Do nothing */
124
+}
125
+
126
+#endif /* _NETDEVICE_H */

Carregando…
Cancelar
Salvar