Browse Source

[netdevice] Add a generic concept of a "blocked link"

When Spanning Tree Protocol (STP) is used, there may be a substantial
delay (tens of seconds) from the time that the link goes up to the
time that the port starts forwarding packets.

Add a generic concept of a "blocked link" (i.e. a link which is up but
which is not expected to communicate successfully), and allow "ifstat"
to indicate when a link is blocked.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9 years ago
parent
commit
f3812395a2
3 changed files with 70 additions and 2 deletions
  1. 17
    0
      src/include/ipxe/netdevice.h
  2. 51
    1
      src/net/netdevice.c
  3. 2
    1
      src/usr/ifmgmt.c

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

@@ -15,6 +15,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
15 15
 #include <ipxe/refcnt.h>
16 16
 #include <ipxe/settings.h>
17 17
 #include <ipxe/interface.h>
18
+#include <ipxe/retry.h>
18 19
 
19 20
 struct io_buffer;
20 21
 struct net_device;
@@ -392,6 +393,8 @@ struct net_device {
392 393
 	 * indicates the error preventing link-up.
393 394
 	 */
394 395
 	int link_rc;
396
+	/** Link block timer */
397
+	struct retry_timer link_block;
395 398
 	/** Maximum packet length
396 399
 	 *
397 400
 	 * This length includes any link-layer headers.
@@ -613,6 +616,17 @@ netdev_link_ok ( struct net_device *netdev ) {
613 616
 	return ( netdev->link_rc == 0 );
614 617
 }
615 618
 
619
+/**
620
+ * Check link block state of network device
621
+ *
622
+ * @v netdev		Network device
623
+ * @ret link_blocked	Link is blocked
624
+ */
625
+static inline __attribute__ (( always_inline )) int
626
+netdev_link_blocked ( struct net_device *netdev ) {
627
+	return ( timer_running ( &netdev->link_block ) );
628
+}
629
+
616 630
 /**
617 631
  * Check whether or not network device is open
618 632
  *
@@ -661,6 +675,9 @@ extern void netdev_rx_freeze ( struct net_device *netdev );
661 675
 extern void netdev_rx_unfreeze ( struct net_device *netdev );
662 676
 extern void netdev_link_err ( struct net_device *netdev, int rc );
663 677
 extern void netdev_link_down ( struct net_device *netdev );
678
+extern void netdev_link_block ( struct net_device *netdev,
679
+				unsigned long timeout );
680
+extern void netdev_link_unblock ( struct net_device *netdev );
664 681
 extern int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf );
665 682
 extern void netdev_tx_defer ( struct net_device *netdev,
666 683
 			      struct io_buffer *iobuf );

+ 51
- 1
src/net/netdevice.c View File

@@ -161,6 +161,9 @@ void netdev_rx_unfreeze ( struct net_device *netdev ) {
161 161
  */
162 162
 void netdev_link_err ( struct net_device *netdev, int rc ) {
163 163
 
164
+	/* Stop link block timer */
165
+	stop_timer ( &netdev->link_block );
166
+
164 167
 	/* Record link state */
165 168
 	netdev->link_rc = rc;
166 169
 	if ( netdev->link_rc == 0 ) {
@@ -190,6 +193,50 @@ void netdev_link_down ( struct net_device *netdev ) {
190 193
 	}
191 194
 }
192 195
 
196
+/**
197
+ * Mark network device link as being blocked
198
+ *
199
+ * @v netdev		Network device
200
+ * @v timeout		Timeout (in ticks)
201
+ */
202
+void netdev_link_block ( struct net_device *netdev, unsigned long timeout ) {
203
+
204
+	/* Start link block timer */
205
+	if ( ! netdev_link_blocked ( netdev ) ) {
206
+		DBGC ( netdev, "NETDEV %s link blocked for %ld ticks\n",
207
+		       netdev->name, timeout );
208
+	}
209
+	start_timer_fixed ( &netdev->link_block, timeout );
210
+}
211
+
212
+/**
213
+ * Mark network device link as being unblocked
214
+ *
215
+ * @v netdev		Network device
216
+ */
217
+void netdev_link_unblock ( struct net_device *netdev ) {
218
+
219
+	/* Stop link block timer */
220
+	if ( netdev_link_blocked ( netdev ) )
221
+		DBGC ( netdev, "NETDEV %s link unblocked\n", netdev->name );
222
+	stop_timer ( &netdev->link_block );
223
+}
224
+
225
+/**
226
+ * Handle network device link block timer expiry
227
+ *
228
+ * @v timer		Link block timer
229
+ * @v fail		Failure indicator
230
+ */
231
+static void netdev_link_block_expired ( struct retry_timer *timer,
232
+					int fail __unused ) {
233
+	struct net_device *netdev =
234
+		container_of ( timer, struct net_device, link_block );
235
+
236
+	/* Assume link is no longer blocked */
237
+	DBGC ( netdev, "NETDEV %s link block expired\n", netdev->name );
238
+}
239
+
193 240
 /**
194 241
  * Record network device statistic
195 242
  *
@@ -545,7 +592,8 @@ static struct interface_descriptor netdev_config_desc =
545 592
 static void free_netdev ( struct refcnt *refcnt ) {
546 593
 	struct net_device *netdev =
547 594
 		container_of ( refcnt, struct net_device, refcnt );
548
-	
595
+
596
+	stop_timer ( &netdev->link_block );
549 597
 	netdev_tx_flush ( netdev );
550 598
 	netdev_rx_flush ( netdev );
551 599
 	clear_settings ( netdev_settings ( netdev ) );
@@ -575,6 +623,8 @@ struct net_device * alloc_netdev ( size_t priv_len ) {
575 623
 	if ( netdev ) {
576 624
 		ref_init ( &netdev->refcnt, free_netdev );
577 625
 		netdev->link_rc = -EUNKNOWN_LINK_STATUS;
626
+		timer_init ( &netdev->link_block, netdev_link_block_expired,
627
+			     &netdev->refcnt );
578 628
 		INIT_LIST_HEAD ( &netdev->tx_queue );
579 629
 		INIT_LIST_HEAD ( &netdev->tx_deferred );
580 630
 		INIT_LIST_HEAD ( &netdev->rx_queue );

+ 2
- 1
src/usr/ifmgmt.c View File

@@ -103,11 +103,12 @@ static void ifstat_errors ( struct net_device_stats *stats,
103 103
  */
104 104
 void ifstat ( struct net_device *netdev ) {
105 105
 	printf ( "%s: %s using %s on %s (%s)\n"
106
-		 "  [Link:%s, TX:%d TXE:%d RX:%d RXE:%d]\n",
106
+		 "  [Link:%s%s, TX:%d TXE:%d RX:%d RXE:%d]\n",
107 107
 		 netdev->name, netdev_addr ( netdev ),
108 108
 		 netdev->dev->driver_name, netdev->dev->name,
109 109
 		 ( netdev_is_open ( netdev ) ? "open" : "closed" ),
110 110
 		 ( netdev_link_ok ( netdev ) ? "up" : "down" ),
111
+		 ( netdev_link_blocked ( netdev ) ? " (blocked)" : "" ),
111 112
 		 netdev->tx_stats.good, netdev->tx_stats.bad,
112 113
 		 netdev->rx_stats.good, netdev->rx_stats.bad );
113 114
 	if ( ! netdev_link_ok ( netdev ) ) {

Loading…
Cancel
Save