Browse Source

[netdevice] Provide function to retrieve the most recently opened net device

There are currently four places within the codebase that use a
heuristic to guess the "boot network device", with varying degrees of
success.  Add a feature to the net device core to maintain a list of
open network devices, in order of opening, and provide a function
last_opened_netdev() to retrieve the most recently opened net device.
This should do a better job than the current assortment of
guess_boot_netdev() functions.
tags/v0.9.6
Michael Brown 16 years ago
parent
commit
02a0215873
2 changed files with 29 additions and 0 deletions
  1. 3
    0
      src/include/gpxe/netdevice.h
  2. 26
    0
      src/net/netdevice.c

+ 3
- 0
src/include/gpxe/netdevice.h View File

229
 	struct refcnt refcnt;
229
 	struct refcnt refcnt;
230
 	/** List of network devices */
230
 	/** List of network devices */
231
 	struct list_head list;
231
 	struct list_head list;
232
+	/** List of open network devices */
233
+	struct list_head open_list;
232
 	/** Name of this network device */
234
 	/** Name of this network device */
233
 	char name[8];
235
 	char name[8];
234
 	/** Underlying hardware device */
236
 	/** Underlying hardware device */
424
 extern struct net_device * find_netdev ( const char *name );
426
 extern struct net_device * find_netdev ( const char *name );
425
 extern struct net_device * find_netdev_by_location ( unsigned int bus_type,
427
 extern struct net_device * find_netdev_by_location ( unsigned int bus_type,
426
 						     unsigned int location );
428
 						     unsigned int location );
429
+extern struct net_device * last_opened_netdev ( void );
427
 extern int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
430
 extern int net_tx ( struct io_buffer *iobuf, struct net_device *netdev,
428
 		    struct net_protocol *net_protocol, const void *ll_dest );
431
 		    struct net_protocol *net_protocol, const void *ll_dest );
429
 extern int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,
432
 extern int net_rx ( struct io_buffer *iobuf, struct net_device *netdev,

+ 26
- 0
src/net/netdevice.c View File

45
 /** List of network devices */
45
 /** List of network devices */
46
 struct list_head net_devices = LIST_HEAD_INIT ( net_devices );
46
 struct list_head net_devices = LIST_HEAD_INIT ( net_devices );
47
 
47
 
48
+/** List of open network devices, in reverse order of opening */
49
+struct list_head open_net_devices = LIST_HEAD_INIT ( open_net_devices );
50
+
48
 /**
51
 /**
49
  * Record network device statistic
52
  * Record network device statistic
50
  *
53
  *
368
 
371
 
369
 	/* Mark as opened */
372
 	/* Mark as opened */
370
 	netdev->state |= NETDEV_OPEN;
373
 	netdev->state |= NETDEV_OPEN;
374
+
375
+	/* Add to head of open devices list */
376
+	list_add ( &netdev->open_list, &open_net_devices );
377
+
371
 	return 0;
378
 	return 0;
372
 }
379
 }
373
 
380
 
393
 
400
 
394
 	/* Mark as closed */
401
 	/* Mark as closed */
395
 	netdev->state &= ~NETDEV_OPEN;
402
 	netdev->state &= ~NETDEV_OPEN;
403
+
404
+	/* Remove from open devices list */
405
+	list_del ( &netdev->open_list );
396
 }
406
 }
397
 
407
 
398
 /**
408
 /**
462
 	return NULL;	
472
 	return NULL;	
463
 }
473
 }
464
 
474
 
475
+/**
476
+ * Get most recently opened network device
477
+ *
478
+ * @ret netdev		Most recently opened network device, or NULL
479
+ */
480
+struct net_device * last_opened_netdev ( void ) {
481
+	struct net_device *netdev;
482
+
483
+	list_for_each_entry ( netdev, &open_net_devices, open_list ) {
484
+		assert ( netdev->state & NETDEV_OPEN );
485
+		return netdev;
486
+	}
487
+
488
+	return NULL;
489
+}
490
+
465
 /**
491
 /**
466
  * Transmit network-layer packet
492
  * Transmit network-layer packet
467
  *
493
  *

Loading…
Cancel
Save