My Kernel v0.1.0
ethernet.h
Go to the documentation of this file.
1
13#ifndef KERNEL_DEVICES_ETHERNET_H
14#define KERNEL_DEVICES_ETHERNET_H
15
16#include <kernel/devices/driver.h>
17#include <kernel/net/ethernet.h>
18#include <kernel/types.h>
19
20#include <libalgo/linked_list.h>
21#include <libalgo/queue.h>
22#include <utils/compiler.h>
23#include <utils/container_of.h>
24#include <utils/math.h>
25
26struct ethernet_device;
27struct net_interface;
28
31 ETHERNET_CAP_BROADCAST,
33};
34
37 error_t (*send_packet)(struct ethernet_device *, struct packet *);
38 error_t (*enable_capability)(struct ethernet_device *,
39 enum ethernet_capability, bool enable);
40};
41
51 struct device device;
55 size_t mtu;
58 uint32_t capabilities;
59
60 struct net_interface *interface;
61 LLIST_NODE(this);
63 struct worker *worker;
64 queue_t rx_queue;
65};
66
68#define ETHERNET_DEVICE_PRIV_ALIGNMENT sizeof(uint64_t)
69
76struct ethernet_device *ethernet_device_alloc(size_t priv_size);
77
80
83
86
89
90static inline void *ethernet_device_priv(struct ethernet_device *dev)
91{
92 return (void *)(dev) +
94}
95
97static inline void
98ethernet_device_set_name(struct ethernet_device *dev, const char *name)
99{
100 device_set_name(&dev->device, name);
101}
102
104static inline const char *ethernet_device_name(struct ethernet_device *dev)
105{
106 return device_name(&dev->device);
107}
108
111
112#endif /* KERNEL_DEVICES_ETHERNET_H */
113
static const char * ethernet_device_name(struct ethernet_device *dev)
Definition: ethernet.h:104
void ethernet_device_free(struct ethernet_device *)
De-allocate an ethernet device.
Definition: ethernet.c:32
#define ETHERNET_DEVICE_PRIV_ALIGNMENT
Boundary onto which the ethernet device's private data must be aligned.
Definition: ethernet.h:68
ethernet_capability
Ethernet device capabilities.
Definition: ethernet.h:30
struct ethernet_device * ethernet_device_find_by_mac(mac_address_t)
Definition: ethernet.c:108
static void ethernet_device_set_name(struct ethernet_device *dev, const char *name)
Set the name of the device.
Definition: ethernet.h:98
struct ethernet_device * ethernet_device_alloc(size_t priv_size)
Allocate a new ethernet device.
Definition: ethernet.c:17
error_t ethernet_device_register(struct ethernet_device *)
Register a new ethernet device.
Definition: ethernet.c:37
struct ethernet_device * ethernet_device_find_by_name(const char *)
Definition: ethernet.c:98
void ethernet_device_receive_packet(struct ethernet_device *, struct packet *)
Process a packet received by an ethernet network device.
Definition: ethernet.c:141
@ ETHERNET_CAP_MULTICAST
Device supports broadcast packets.
Definition: ethernet.h:32
static void device_set_name(struct device *dev, const char *name)
Set the name of the device.
Definition: device.h:112
static const char * device_name(struct device *dev)
Definition: device.h:118
uint8_t mac_address_t[ETHERNET_ADDR_SIZE]
Represents an ethernet MAC address.
Definition: ethernet.h:29
#define align_up(_value, _power)
Align _value to the next multiple of _power.
Definition: math.h:47
Represents a device inside the kernel.
Definition: device.h:78
An ethernet device.
Definition: ethernet.h:50
struct ethernet_operations * ops
The underlying generic device.
Definition: ethernet.h:52
mac_address_t mac
The ethernet operation vtable.
Definition: ethernet.h:53
uint32_t capabilities
Maximum transmittable packet size.
Definition: ethernet.h:58
struct worker * worker
Node inside the linked list of registered devices.
Definition: ethernet.h:63
size_t mtu
The device's mac address.
Definition: ethernet.h:55
LLIST_NODE(this)
The netdevice's interface.
Operations that can be performed on an ethernet device.
Definition: ethernet.h:36
The head of a doubly linked list.
Definition: linked_list.h:43
A network interface.
Definition: interface.h:39
A network packet.
Definition: packet.h:51
Worker thread.
Definition: worker.h:53