Browse Source

[netdevice] Allow non-completion TX errors to be recorded

Allow TX errors to be recorded against a network device even when the
packet didn't make it as far as netdev_tx().

Inspired-by: Dominik Russenberger <dominik.russenberger@terreactive.ch>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
d6115c91cf
2 changed files with 27 additions and 7 deletions
  1. 2
    0
      src/include/ipxe/netdevice.h
  2. 25
    7
      src/net/netdevice.c

+ 2
- 0
src/include/ipxe/netdevice.h View File

@@ -586,6 +586,8 @@ netdev_rx_frozen ( struct net_device *netdev ) {
586 586
 extern void netdev_link_err ( struct net_device *netdev, int rc );
587 587
 extern void netdev_link_down ( struct net_device *netdev );
588 588
 extern int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf );
589
+extern void netdev_tx_err ( struct net_device *netdev,
590
+			    struct io_buffer *iobuf, int rc );
589 591
 extern void netdev_tx_complete_err ( struct net_device *netdev,
590 592
 				 struct io_buffer *iobuf, int rc );
591 593
 extern void netdev_tx_complete_next_err ( struct net_device *netdev, int rc );

+ 25
- 7
src/net/netdevice.c View File

@@ -194,16 +194,17 @@ int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf ) {
194 194
 }
195 195
 
196 196
 /**
197
- * Complete network transmission
197
+ * Discard transmitted packet
198 198
  *
199 199
  * @v netdev		Network device
200
- * @v iobuf		I/O buffer
200
+ * @v iobuf		I/O buffer, or NULL
201 201
  * @v rc		Packet status code
202 202
  *
203
- * The packet must currently be in the network device's TX queue.
203
+ * The packet is discarded and a TX error is recorded.  This function
204
+ * takes ownership of the I/O buffer.
204 205
  */
205
-void netdev_tx_complete_err ( struct net_device *netdev,
206
-			      struct io_buffer *iobuf, int rc ) {
206
+void netdev_tx_err ( struct net_device *netdev,
207
+		     struct io_buffer *iobuf, int rc ) {
207 208
 
208 209
 	/* Update statistics counter */
209 210
 	netdev_record_stat ( &netdev->tx_stats, rc );
@@ -215,12 +216,28 @@ void netdev_tx_complete_err ( struct net_device *netdev,
215 216
 		       netdev->name, iobuf, strerror ( rc ) );
216 217
 	}
217 218
 
219
+	/* Discard packet */
220
+	free_iob ( iobuf );
221
+}
222
+
223
+/**
224
+ * Complete network transmission
225
+ *
226
+ * @v netdev		Network device
227
+ * @v iobuf		I/O buffer
228
+ * @v rc		Packet status code
229
+ *
230
+ * The packet must currently be in the network device's TX queue.
231
+ */
232
+void netdev_tx_complete_err ( struct net_device *netdev,
233
+			      struct io_buffer *iobuf, int rc ) {
234
+
218 235
 	/* Catch data corruption as early as possible */
219 236
 	list_check_contains ( iobuf, &netdev->tx_queue, list );
220 237
 
221 238
 	/* Dequeue and free I/O buffer */
222 239
 	list_del ( &iobuf->list );
223
-	free_iob ( iobuf );
240
+	netdev_tx_err ( netdev, iobuf, rc );
224 241
 }
225 242
 
226 243
 /**
@@ -644,7 +661,8 @@ int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
644 661
 	/* Add link-layer header */
645 662
 	if ( ( rc = ll_protocol->push ( netdev, iobuf, ll_dest, ll_source,
646 663
 					net_protocol->net_proto ) ) != 0 ) {
647
-		free_iob ( iobuf );
664
+		/* Record error for diagnosis */
665
+		netdev_tx_err ( netdev, iobuf, rc );
648 666
 		return rc;
649 667
 	}
650 668
 

Loading…
Cancel
Save