liyujie
2025-08-28 b3810562527858a3b3d98ffa6e9c9c5b0f4a9a8e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright 2018 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
 
library zircon.ethernet;
 
using zx;
 
struct MacAddress {
    array<uint8>:6 octets;
};
 
const uint32 DEFAULT_BUFFER_SIZE = 2048; // bytes
/// When writing payload to a tx buffer, clients of a Device must skip this many bytes
/// so that lower-layer drivers can fill in additional headers in that space.
const uint32 MAC_HDR_MAX_SIZE    = 64;   // bytes, the closest power of 2 larger than 44, which is
                                         // DataFrameHeader::max_size(36) + LlcHeader::max_size(8)
 
// Info.features bits
const uint32 INFO_FEATURE_WLAN = 0x00000001;
const uint32 INFO_FEATURE_SYNTH = 0x00000002;
const uint32 INFO_FEATURE_LOOPBACK = 0x00000004;
 
struct Info {
    uint32 features;
    uint32 mtu;
    MacAddress mac;
};
 
struct Fifos {
    // handles for the rx and tx fifo
    handle<fifo> rx;
    handle<fifo> tx;
 
    // maximum number of items in rx and tx fifo
    uint32 rx_depth;
    uint32 tx_depth;
};
 
// Signal that is asserted on the RX fifo whenever the Device has a status
// change.  This is ZX_USER_SIGNAL_0.
// TODO(teisenbe/kulakowski): find a better way to represent this
const uint32 SIGNAL_STATUS = 0x01000000;
 
// device_status bits
const uint32 DEVICE_STATUS_ONLINE = 0x00000001;
 
// Max client name length
const uint32 MAX_CLIENT_NAME_LEN = 15;
 
// For compatibility with a past revision, allow one extra byte for an optional
// null-terminator.
const uint32 SET_CLIENT_NAME_MAX_LEN = 16;
 
// zircon/device/ethernet.h
[Layout = "Simple"]
interface Device {
    // Obtain information about device
    1: GetInfo() -> (Info info);
 
    // Obtain a pair of fifos for queueing tx and rx operations
    2: GetFifos() -> (zx.status status, Fifos? info);
 
    // Set the IO Buffer that will provide the data buffers for tx and rx operations
    3: SetIOBuffer(handle<vmo> h) -> (zx.status status);
 
    // Start transferring packets
    // Start will not succeed (ZX_ERR_BAD_STATE) until the fifos have been
    // obtained and an io buffer vmo has been registered.
    4: Start() -> (zx.status status);
 
    // Stop transferring packets
    5: Stop() -> ();
 
    // Start listening to the packets that we're transmitting
    // as well as the packets we're receiving.
    6: ListenStart() -> (zx.status status);
 
    // Stop listening to the packets that we're transmitting.
    7: ListenStop() -> ();
 
    8: SetClientName(string:SET_CLIENT_NAME_MAX_LEN name) -> (zx.status status);
 
    // Obtain the device status bits
    // When these change, the signal SIGNAL_STATUS is asserted on the rx fifo.
    // When these are read, the signal is deasserted.
    9: GetStatus() -> (uint32 device_status);
 
    10: SetPromiscuousMode(bool enabled) -> (zx.status status);
 
    11: ConfigMulticastAddMac(MacAddress addr) -> (zx.status status);
    12: ConfigMulticastDeleteMac(MacAddress addr) -> (zx.status status);
    13: ConfigMulticastSetPromiscuousMode(bool enabled) -> (zx.status status);
 
    // TODO(teisenbe): We should probably remove these?  They are only used for testing.
    14: ConfigMulticastTestFilter() -> (zx.status status);
    15: DumpRegisters() -> (zx.status status);
};
 
// Operation
//
// Packets are transmitted by writing data into the io_vmo and writing
// an FifoEntry referencing that data (offset + length) into the tx fifo.
// When the driver is done accessing the data, a FifoEntry with the same
// cookie value (opaque to the driver) will be readable from the tx fifo.
//
// Packets are received by writing a FifoEntry referencing an available
// buffer (offset + length) in the io vmo.  When a packet is received,
// a FifoEntry with the same cookie value (opaque to the driver) will be
// readable from the rx fifo.  The offset field will be the same as was
// sent.  The length field will reflect the actual size of the received
// packet.  The flags field will indicate success or a specific failure
// condition.
//
// IMPORTANT: The driver *will not* buffer response messages.  It is the
// client's responsibility to ensure that there is space in the reply side
// of each fifo for each outstanding tx or rx request.  The fifo sizes
// are returned along with the fifo handles from GetFifos().
 
// flags values for request messages
// - none -
 
// flags values for response messages
const uint16 FIFO_RX_OK   = 0x00000001; // packet received okay
const uint16 FIFO_TX_OK   = 0x00000001; // packet transmitted okay
const uint16 FIFO_INVALID = 0x00000002; // offset+length not within io_vmo bounds
const uint16 FIFO_RX_TX   = 0x00000004; // received our own tx packet (when Listen enabled)
 
struct FifoEntry {
    // offset from start of io vmo to packet data
    uint32 offset;
 
    // length of packet data to tx or rx
    uint16 length;
 
    // FIFO_* flags as above
    uint16 flags;
 
    // opaque cookie
    uint64 cookie;
};