|
@@ -74,9 +74,7 @@ int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf ) {
|
74
|
74
|
return 0;
|
75
|
75
|
|
76
|
76
|
err:
|
77
|
|
- DBGC ( netdev, "NETDEV %p transmission %p failed: %s\n",
|
78
|
|
- netdev, iobuf, strerror ( rc ) );
|
79
|
|
- netdev_tx_complete ( netdev, iobuf );
|
|
77
|
+ netdev_tx_complete_err ( netdev, iobuf, rc );
|
80
|
78
|
return rc;
|
81
|
79
|
}
|
82
|
80
|
|
|
@@ -85,11 +83,23 @@ int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf ) {
|
85
|
83
|
*
|
86
|
84
|
* @v netdev Network device
|
87
|
85
|
* @v iobuf I/O buffer
|
|
86
|
+ * @v rc Packet status code
|
88
|
87
|
*
|
89
|
88
|
* The packet must currently be in the network device's TX queue.
|
90
|
89
|
*/
|
91
|
|
-void netdev_tx_complete ( struct net_device *netdev, struct io_buffer *iobuf ) {
|
92
|
|
- DBGC ( netdev, "NETDEV %p transmission %p complete\n", netdev, iobuf );
|
|
90
|
+void netdev_tx_complete_err ( struct net_device *netdev,
|
|
91
|
+ struct io_buffer *iobuf, int rc ) {
|
|
92
|
+
|
|
93
|
+ /* Update statistics counter */
|
|
94
|
+ if ( rc == 0 ) {
|
|
95
|
+ netdev->stats.tx_ok++;
|
|
96
|
+ DBGC ( netdev, "NETDEV %p transmission %p complete\n",
|
|
97
|
+ netdev, iobuf );
|
|
98
|
+ } else {
|
|
99
|
+ netdev->stats.tx_err++;
|
|
100
|
+ DBGC ( netdev, "NETDEV %p transmission %p failed: %s\n",
|
|
101
|
+ netdev, iobuf, strerror ( rc ) );
|
|
102
|
+ }
|
93
|
103
|
|
94
|
104
|
/* Catch data corruption as early as possible */
|
95
|
105
|
assert ( iobuf->list.next != NULL );
|
|
@@ -98,23 +108,21 @@ void netdev_tx_complete ( struct net_device *netdev, struct io_buffer *iobuf ) {
|
98
|
108
|
/* Dequeue and free I/O buffer */
|
99
|
109
|
list_del ( &iobuf->list );
|
100
|
110
|
free_iob ( iobuf );
|
101
|
|
-
|
102
|
|
- /* Update statistics counter */
|
103
|
|
- netdev->stats.tx_count++;
|
104
|
111
|
}
|
105
|
112
|
|
106
|
113
|
/**
|
107
|
114
|
* Complete network transmission
|
108
|
115
|
*
|
109
|
116
|
* @v netdev Network device
|
|
117
|
+ * @v rc Packet status code
|
110
|
118
|
*
|
111
|
119
|
* Completes the oldest outstanding packet in the TX queue.
|
112
|
120
|
*/
|
113
|
|
-void netdev_tx_complete_next ( struct net_device *netdev ) {
|
|
121
|
+void netdev_tx_complete_next_err ( struct net_device *netdev, int rc ) {
|
114
|
122
|
struct io_buffer *iobuf;
|
115
|
123
|
|
116
|
124
|
list_for_each_entry ( iobuf, &netdev->tx_queue, list ) {
|
117
|
|
- netdev_tx_complete ( netdev, iobuf );
|
|
125
|
+ netdev_tx_complete_err ( netdev, iobuf, rc );
|
118
|
126
|
return;
|
119
|
127
|
}
|
120
|
128
|
}
|
|
@@ -128,7 +136,7 @@ static void netdev_tx_flush ( struct net_device *netdev ) {
|
128
|
136
|
|
129
|
137
|
/* Discard any packets in the TX queue */
|
130
|
138
|
while ( ! list_empty ( &netdev->tx_queue ) ) {
|
131
|
|
- netdev_tx_complete_next ( netdev );
|
|
139
|
+ netdev_tx_complete_next_err ( netdev, -ECANCELED );
|
132
|
140
|
}
|
133
|
141
|
}
|
134
|
142
|
|
|
@@ -136,12 +144,13 @@ static void netdev_tx_flush ( struct net_device *netdev ) {
|
136
|
144
|
* Add packet to receive queue
|
137
|
145
|
*
|
138
|
146
|
* @v netdev Network device
|
139
|
|
- * @v iobuf I/O buffer
|
|
147
|
+ * @v iobuf I/O buffer, or NULL
|
140
|
148
|
*
|
141
|
149
|
* The packet is added to the network device's RX queue. This
|
142
|
150
|
* function takes ownership of the I/O buffer.
|
143
|
151
|
*/
|
144
|
152
|
void netdev_rx ( struct net_device *netdev, struct io_buffer *iobuf ) {
|
|
153
|
+
|
145
|
154
|
DBGC ( netdev, "NETDEV %p received %p (%p+%zx)\n",
|
146
|
155
|
netdev, iobuf, iobuf->data, iob_len ( iobuf ) );
|
147
|
156
|
|
|
@@ -149,7 +158,32 @@ void netdev_rx ( struct net_device *netdev, struct io_buffer *iobuf ) {
|
149
|
158
|
list_add_tail ( &iobuf->list, &netdev->rx_queue );
|
150
|
159
|
|
151
|
160
|
/* Update statistics counter */
|
152
|
|
- netdev->stats.rx_count++;
|
|
161
|
+ netdev->stats.rx_ok++;
|
|
162
|
+}
|
|
163
|
+
|
|
164
|
+/**
|
|
165
|
+ * Discard received packet
|
|
166
|
+ *
|
|
167
|
+ * @v netdev Network device
|
|
168
|
+ * @v iobuf I/O buffer, or NULL
|
|
169
|
+ * @v rc Packet status code
|
|
170
|
+ *
|
|
171
|
+ * The packet is discarded and an RX error is recorded. This function
|
|
172
|
+ * takes ownership of the I/O buffer. @c iobuf may be NULL if, for
|
|
173
|
+ * example, the net device wishes to report an error due to being
|
|
174
|
+ * unable to allocate an I/O buffer.
|
|
175
|
+ */
|
|
176
|
+void netdev_rx_err ( struct net_device *netdev,
|
|
177
|
+ struct io_buffer *iobuf, int rc ) {
|
|
178
|
+
|
|
179
|
+ DBGC ( netdev, "NETDEV %p failed to receive %p: %s\n",
|
|
180
|
+ netdev, iobuf, strerror ( rc ) );
|
|
181
|
+
|
|
182
|
+ /* Discard packet */
|
|
183
|
+ free_iob ( iobuf );
|
|
184
|
+
|
|
185
|
+ /* Update statistics counter */
|
|
186
|
+ netdev->stats.rx_err++;
|
153
|
187
|
}
|
154
|
188
|
|
155
|
189
|
/**
|
|
@@ -200,9 +234,7 @@ static void netdev_rx_flush ( struct net_device *netdev ) {
|
200
|
234
|
|
201
|
235
|
/* Discard any packets in the RX queue */
|
202
|
236
|
while ( ( iobuf = netdev_rx_dequeue ( netdev ) ) ) {
|
203
|
|
- DBGC ( netdev, "NETDEV %p discarding received %p\n",
|
204
|
|
- netdev, iobuf );
|
205
|
|
- free_iob ( iobuf );
|
|
237
|
+ netdev_rx_err ( netdev, iobuf, -ECANCELED );
|
206
|
238
|
}
|
207
|
239
|
}
|
208
|
240
|
|