Browse Source

Kill off hotplug.h and just make net devices normal reference-counted

structures.

DHCP still broken and #if 0'd out.
tags/v0.9.3
Michael Brown 17 years ago
parent
commit
f77815f2b1

+ 2
- 2
src/arch/i386/drivers/net/undinet.c View File

675
 	undinet_call ( undinic, PXENV_STOP_UNDI, &stop_undi,
675
 	undinet_call ( undinic, PXENV_STOP_UNDI, &stop_undi,
676
 		       sizeof ( stop_undi ) );
676
 		       sizeof ( stop_undi ) );
677
  err_start_undi:
677
  err_start_undi:
678
-	free_netdev ( netdev );
678
+	netdev_put ( netdev );
679
 	undi_set_drvdata ( undi, NULL );
679
 	undi_set_drvdata ( undi, NULL );
680
 	return rc;
680
 	return rc;
681
 }
681
 }
710
 	undi->flags &= ~UNDI_FL_STARTED;
710
 	undi->flags &= ~UNDI_FL_STARTED;
711
 
711
 
712
 	/* Free network device */
712
 	/* Free network device */
713
-	free_netdev ( netdev );
713
+	netdev_put ( netdev );
714
 
714
 
715
 	DBGC ( undinic, "UNDINIC %p removed\n", undinic );
715
 	DBGC ( undinic, "UNDINIC %p removed\n", undinic );
716
 }
716
 }

+ 0
- 45
src/core/hotplug.c View File

1
-/*
2
- * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
3
- *
4
- * This program is free software; you can redistribute it and/or
5
- * modify it under the terms of the GNU General Public License as
6
- * published by the Free Software Foundation; either version 2 of the
7
- * License, or any later version.
8
- *
9
- * This program is distributed in the hope that it will be useful, but
10
- * WITHOUT ANY WARRANTY; without even the implied warranty of
11
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
- * General Public License for more details.
13
- *
14
- * You should have received a copy of the GNU General Public License
15
- * along with this program; if not, write to the Free Software
16
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
- */
18
-
19
-#include <assert.h>
20
-#include <gpxe/hotplug.h>
21
-
22
-/** @file
23
- *
24
- * Hotplug support
25
- *
26
- */
27
-
28
-/**
29
- * Forget all persistent references to an object
30
- *
31
- * @v list		List of persistent references
32
- */
33
-void forget_references ( struct list_head *list ) {
34
-	struct reference *ref;
35
-	struct reference *ref_tmp;
36
-
37
-	list_for_each_entry_safe ( ref, ref_tmp, list, list ) {
38
-		ref->forget ( ref );
39
-	}
40
-
41
-	/* The list had really better be empty by now, otherwise we're
42
-	 * screwed.
43
-	 */
44
-	assert ( list_empty ( list ) );
45
-}

+ 3
- 3
src/drivers/net/legacy.c View File

90
 	nic.node_addr = netdev->ll_addr;
90
 	nic.node_addr = netdev->ll_addr;
91
 
91
 
92
 	if ( ! probe ( &nic, hwdev ) ) {
92
 	if ( ! probe ( &nic, hwdev ) ) {
93
-		free_netdev ( netdev );
93
+		netdev_put ( netdev );
94
 		return -ENODEV;
94
 		return -ENODEV;
95
 	}
95
 	}
96
 
96
 
97
 	if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
97
 	if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
98
 		disable ( &nic, hwdev );
98
 		disable ( &nic, hwdev );
99
-		free_netdev ( netdev );
99
+		netdev_put ( netdev );
100
 		return rc;
100
 		return rc;
101
 	}
101
 	}
102
 
102
 
116
 
116
 
117
 	unregister_netdev ( netdev );
117
 	unregister_netdev ( netdev );
118
 	disable ( nic, hwdev );
118
 	disable ( nic, hwdev );
119
-	free_netdev ( netdev );
119
+	netdev_put ( netdev );
120
 	legacy_registered = 0;
120
 	legacy_registered = 0;
121
 }
121
 }
122
 
122
 

+ 7
- 9
src/drivers/net/pnic.c View File

206
 
206
 
207
 	unregister_netdev ( netdev );
207
 	unregister_netdev ( netdev );
208
 	pnic_command ( pnic, PNIC_CMD_RESET, NULL, 0, NULL, 0, NULL );
208
 	pnic_command ( pnic, PNIC_CMD_RESET, NULL, 0, NULL, 0, NULL );
209
-	free_netdev ( netdev );
209
+	netdev_put ( netdev );
210
 }
210
 }
211
 
211
 
212
 /**************************************************************************
212
 /**************************************************************************
220
 	uint16_t status;
220
 	uint16_t status;
221
 	int rc;
221
 	int rc;
222
 
222
 
223
-	/* Fix up PCI device */
224
-	adjust_pci_device ( pci );
225
-	
226
 	/* Allocate net device */
223
 	/* Allocate net device */
227
 	netdev = alloc_etherdev ( sizeof ( *pnic ) );
224
 	netdev = alloc_etherdev ( sizeof ( *pnic ) );
228
-	if ( ! netdev ) {
229
-		rc = -ENOMEM;
230
-		goto err;
231
-	}
225
+	if ( ! netdev )
226
+		return -ENOMEM;
232
 	pnic = netdev->priv;
227
 	pnic = netdev->priv;
233
 	pci_set_drvdata ( pci, netdev );
228
 	pci_set_drvdata ( pci, netdev );
234
 	netdev->dev = &pci->dev;
229
 	netdev->dev = &pci->dev;
235
 	pnic->ioaddr = pci->ioaddr;
230
 	pnic->ioaddr = pci->ioaddr;
236
 
231
 
232
+	/* Fix up PCI device */
233
+	adjust_pci_device ( pci );
234
+	
237
 	/* API version check */
235
 	/* API version check */
238
 	status = pnic_command_quiet ( pnic, PNIC_CMD_API_VER, NULL, 0,
236
 	status = pnic_command_quiet ( pnic, PNIC_CMD_API_VER, NULL, 0,
239
 				      &api_version,
237
 				      &api_version,
264
 
262
 
265
  err:
263
  err:
266
 	/* Free net device */
264
 	/* Free net device */
267
-	free_netdev ( netdev );
265
+	netdev_put ( netdev );
268
 	return rc;
266
 	return rc;
269
 }
267
 }
270
 
268
 

+ 14
- 21
src/drivers/net/rtl8139.c View File

501
 static int rtl_probe ( struct pci_device *pci,
501
 static int rtl_probe ( struct pci_device *pci,
502
 		       const struct pci_device_id *id __unused ) {
502
 		       const struct pci_device_id *id __unused ) {
503
 	struct net_device *netdev;
503
 	struct net_device *netdev;
504
-	struct rtl8139_nic *rtl = NULL;
505
-	int registered_netdev = 0;
504
+	struct rtl8139_nic *rtl;
506
 	int rc;
505
 	int rc;
507
 
506
 
508
-	/* Fix up PCI device */
509
-	adjust_pci_device ( pci );
510
-
511
 	/* Allocate net device */
507
 	/* Allocate net device */
512
 	netdev = alloc_etherdev ( sizeof ( *rtl ) );
508
 	netdev = alloc_etherdev ( sizeof ( *rtl ) );
513
-	if ( ! netdev ) {
514
-		rc = -ENOMEM;
515
-		goto err;
516
-	}
509
+	if ( ! netdev )
510
+		return -ENOMEM;
517
 	rtl = netdev->priv;
511
 	rtl = netdev->priv;
518
 	pci_set_drvdata ( pci, netdev );
512
 	pci_set_drvdata ( pci, netdev );
519
 	netdev->dev = &pci->dev;
513
 	netdev->dev = &pci->dev;
520
 	memset ( rtl, 0, sizeof ( *rtl ) );
514
 	memset ( rtl, 0, sizeof ( *rtl ) );
521
 	rtl->ioaddr = pci->ioaddr;
515
 	rtl->ioaddr = pci->ioaddr;
522
 
516
 
517
+	/* Fix up PCI device */
518
+	adjust_pci_device ( pci );
519
+
523
 	/* Reset the NIC, set up EEPROM access and read MAC address */
520
 	/* Reset the NIC, set up EEPROM access and read MAC address */
524
 	rtl_reset ( rtl );
521
 	rtl_reset ( rtl );
525
 	rtl_init_eeprom ( rtl );
522
 	rtl_init_eeprom ( rtl );
533
 
530
 
534
 	/* Register network device */
531
 	/* Register network device */
535
 	if ( ( rc = register_netdev ( netdev ) ) != 0 )
532
 	if ( ( rc = register_netdev ( netdev ) ) != 0 )
536
-		goto err;
537
-	registered_netdev = 1;
533
+		goto err_register_netdev;
538
 
534
 
539
 	/* Register non-volatile storage */
535
 	/* Register non-volatile storage */
540
 	if ( rtl->nvo.nvs ) {
536
 	if ( rtl->nvo.nvs ) {
541
 		if ( ( rc = nvo_register ( &rtl->nvo ) ) != 0 )
537
 		if ( ( rc = nvo_register ( &rtl->nvo ) ) != 0 )
542
-			goto err;
538
+			goto err_register_nvo;
543
 	}
539
 	}
544
 
540
 
545
 	return 0;
541
 	return 0;
546
 
542
 
547
- err:
548
-	/* Disable NIC */
549
-	if ( rtl )
550
-		rtl_reset ( rtl );
551
-	if ( registered_netdev )
552
-		unregister_netdev ( netdev );
553
-	/* Free net device */
554
-	free_netdev ( netdev );
543
+ err_register_nvo:
544
+	unregister_netdev ( netdev );
545
+ err_register_netdev:
546
+	rtl_reset ( rtl );
547
+	netdev_put ( netdev );
555
 	return rc;
548
 	return rc;
556
 }
549
 }
557
 
550
 
568
 		nvo_unregister ( &rtl->nvo );
561
 		nvo_unregister ( &rtl->nvo );
569
 	unregister_netdev ( netdev );
562
 	unregister_netdev ( netdev );
570
 	rtl_reset ( rtl );
563
 	rtl_reset ( rtl );
571
-	free_netdev ( netdev );
564
+	netdev_put ( netdev );
572
 }
565
 }
573
 
566
 
574
 static struct pci_device_id rtl8139_nics[] = {
567
 static struct pci_device_id rtl8139_nics[] = {

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

13
 #include <gpxe/retry.h>
13
 #include <gpxe/retry.h>
14
 #include <gpxe/async.h>
14
 #include <gpxe/async.h>
15
 #include <gpxe/ata.h>
15
 #include <gpxe/ata.h>
16
-#include <gpxe/hotplug.h>
17
 
16
 
18
 /** An AoE ATA command */
17
 /** An AoE ATA command */
19
 struct aoecmd {
18
 struct aoecmd {
87
 
86
 
88
 	/** Network device */
87
 	/** Network device */
89
 	struct net_device *netdev;
88
 	struct net_device *netdev;
90
-	/** Reference to network device */
91
-	struct reference netdev_ref;
92
 
89
 
93
 	/** Major number */
90
 	/** Major number */
94
 	uint16_t major;
91
 	uint16_t major;

+ 2
- 3
src/include/gpxe/dhcp.h View File

13
 #include <gpxe/udp.h>
13
 #include <gpxe/udp.h>
14
 #include <gpxe/async.h>
14
 #include <gpxe/async.h>
15
 #include <gpxe/retry.h>
15
 #include <gpxe/retry.h>
16
-#include <gpxe/hotplug.h>
17
 
16
 
18
 /** BOOTP/DHCP server port */
17
 /** BOOTP/DHCP server port */
19
 #define BOOTPS_PORT 67
18
 #define BOOTPS_PORT 67
449
 	struct dhcp_option_block options[NUM_OPT_BLOCKS];
448
 	struct dhcp_option_block options[NUM_OPT_BLOCKS];
450
 };
449
 };
451
 
450
 
451
+struct udp_connection {};
452
+
452
 /** A DHCP session */
453
 /** A DHCP session */
453
 struct dhcp_session {
454
 struct dhcp_session {
454
 	/** UDP connection for this session */
455
 	/** UDP connection for this session */
456
 
457
 
457
 	/** Network device being configured */
458
 	/** Network device being configured */
458
 	struct net_device *netdev;
459
 	struct net_device *netdev;
459
-	/** Persistent reference to network device */
460
-	struct reference netdev_ref;
461
 
460
 
462
 	/** Options obtained from server */
461
 	/** Options obtained from server */
463
 	struct dhcp_option_block *options;
462
 	struct dhcp_option_block *options;

+ 0
- 58
src/include/gpxe/hotplug.h View File

1
-#ifndef _GPXE_HOTPLUG_H
2
-#define _GPXE_HOTPLUG_H
3
-
4
-/** @file
5
- *
6
- * Hotplug support
7
- *
8
- */
9
-
10
-#include <gpxe/list.h>
11
-
12
-/**
13
- * A persistent reference to another data structure
14
- *
15
- * This data structure should be embedded within any data structure
16
- * (the referrer) which holds a persistent reference to a separate,
17
- * volatile data structure (the referee).
18
- */
19
-struct reference {
20
-	/** List of persistent references */
21
-	struct list_head list;
22
-	/** Forget persistent reference
23
-	 *
24
-	 * @v ref		Persistent reference
25
-	 *
26
-	 * This method is called immediately before the referred-to
27
-	 * data structure is destroyed.  The reference holder must
28
-	 * forget all references to the referee before returning from
29
-	 * this method.
30
-	 *
31
-	 * This method must also call ref_del() to remove the
32
-	 * reference.
33
-	 */
34
-	void ( * forget ) ( struct reference *ref );
35
-};
36
-
37
-/**
38
- * Add persistent reference
39
- *
40
- * @v ref		Persistent reference
41
- * @v list		List of persistent references
42
- */
43
-static inline void ref_add ( struct reference *ref, struct list_head *list ) {
44
-	list_add ( &ref->list, list );
45
-}
46
-
47
-/**
48
- * Remove persistent reference
49
- *
50
- * @v ref		Persistent reference
51
- */
52
-static inline void ref_del ( struct reference *ref ) {
53
-	list_del ( &ref->list );
54
-}
55
-
56
-extern void forget_references ( struct list_head *list );
57
-
58
-#endif /* _GPXE_HOTPLUG_H */

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

9
 
9
 
10
 #include <ip.h>
10
 #include <ip.h>
11
 #include <gpxe/retry.h>
11
 #include <gpxe/retry.h>
12
-#include <gpxe/hotplug.h>
13
 
12
 
14
 /* IP constants */
13
 /* IP constants */
15
 
14
 
44
 
43
 
45
 	/** Network device */
44
 	/** Network device */
46
 	struct net_device *netdev;
45
 	struct net_device *netdev;
47
-	/** Reference to network device */
48
-	struct reference netdev_ref;
49
 
46
 
50
 	/** IPv4 address */
47
 	/** IPv4 address */
51
 	struct in_addr address;
48
 	struct in_addr address;

+ 25
- 4
src/include/gpxe/netdevice.h View File

10
 #include <stdint.h>
10
 #include <stdint.h>
11
 #include <gpxe/list.h>
11
 #include <gpxe/list.h>
12
 #include <gpxe/tables.h>
12
 #include <gpxe/tables.h>
13
-#include <gpxe/hotplug.h>
13
+#include <gpxe/refcnt.h>
14
 
14
 
15
 struct io_buffer;
15
 struct io_buffer;
16
 struct net_device;
16
 struct net_device;
137
  * not just an Ethernet device.
137
  * not just an Ethernet device.
138
  */
138
  */
139
 struct net_device {
139
 struct net_device {
140
+	/** Reference counter */
141
+	struct refcnt refcnt;
140
 	/** List of network devices */
142
 	/** List of network devices */
141
 	struct list_head list;
143
 	struct list_head list;
142
 	/** Name of this network device */
144
 	/** Name of this network device */
143
 	char name[8];
145
 	char name[8];
144
 	/** Underlying hardware device */
146
 	/** Underlying hardware device */
145
 	struct device *dev;
147
 	struct device *dev;
146
-	/** List of persistent reference holders */
147
-	struct list_head references;
148
 
148
 
149
 	/** Open network device
149
 	/** Open network device
150
 	 *
150
 	 *
251
 	return ( ! list_empty ( &net_devices ) );
251
 	return ( ! list_empty ( &net_devices ) );
252
 }
252
 }
253
 
253
 
254
+/**
255
+ * Get reference to network device
256
+ *
257
+ * @v netdev		Network device
258
+ * @ret netdev		Network device
259
+ */
260
+static inline __attribute__ (( always_inline )) struct net_device *
261
+netdev_get ( struct net_device *netdev ) {
262
+	ref_get ( &netdev->refcnt );
263
+	return netdev;
264
+}
265
+
266
+/**
267
+ * Drop reference to network device
268
+ *
269
+ * @v netdev		Network device
270
+ */
271
+static inline __attribute__ (( always_inline )) void
272
+netdev_put ( struct net_device *netdev ) {
273
+	ref_put ( &netdev->refcnt );
274
+}
275
+
254
 extern int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf );
276
 extern int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf );
255
 void netdev_tx_complete ( struct net_device *netdev, struct io_buffer *iobuf );
277
 void netdev_tx_complete ( struct net_device *netdev, struct io_buffer *iobuf );
256
 void netdev_tx_complete_next ( struct net_device *netdev );
278
 void netdev_tx_complete_next ( struct net_device *netdev );
262
 extern int netdev_open ( struct net_device *netdev );
284
 extern int netdev_open ( struct net_device *netdev );
263
 extern void netdev_close ( struct net_device *netdev );
285
 extern void netdev_close ( struct net_device *netdev );
264
 extern void unregister_netdev ( struct net_device *netdev );
286
 extern void unregister_netdev ( struct net_device *netdev );
265
-extern void free_netdev ( struct net_device *netdev );
266
 struct net_device * find_netdev ( const char *name );
287
 struct net_device * find_netdev ( const char *name );
267
 struct net_device * find_pci_netdev ( unsigned int busdevfn );
288
 struct net_device * find_pci_netdev ( unsigned int busdevfn );
268
 
289
 

+ 0
- 17
src/net/aoe.c View File

265
 	.rx = aoe_rx,
265
 	.rx = aoe_rx,
266
 };
266
 };
267
 
267
 
268
-/**
269
- * Forget reference to net_device
270
- *
271
- * @v ref		Persistent reference
272
- */
273
-static void aoe_forget_netdev ( struct reference *ref ) {
274
-	struct aoe_session *aoe
275
-		= container_of ( ref, struct aoe_session, netdev_ref );
276
-
277
-	aoe->netdev = NULL;
278
-	ref_del ( &aoe->netdev_ref );
279
-}
280
-
281
 /**
268
 /**
282
  * Open AoE session
269
  * Open AoE session
283
  *
270
  *
288
 		 sizeof ( aoe->target ) );
275
 		 sizeof ( aoe->target ) );
289
 	aoe->tag = AOE_TAG_MAGIC;
276
 	aoe->tag = AOE_TAG_MAGIC;
290
 	aoe->timer.expired = aoe_timer_expired;
277
 	aoe->timer.expired = aoe_timer_expired;
291
-	aoe->netdev_ref.forget = aoe_forget_netdev;
292
-	ref_add ( &aoe->netdev_ref, &aoe->netdev->references );
293
 	list_add ( &aoe->list, &aoe_sessions );
278
 	list_add ( &aoe->list, &aoe_sessions );
294
 }
279
 }
295
 
280
 
299
  * @v aoe		AoE session
284
  * @v aoe		AoE session
300
  */
285
  */
301
 void aoe_close ( struct aoe_session *aoe ) {
286
 void aoe_close ( struct aoe_session *aoe ) {
302
-	if ( aoe->netdev )
303
-		ref_del ( &aoe->netdev_ref );
304
 	list_del ( &aoe->list );
287
 	list_del ( &aoe->list );
305
 }
288
 }
306
 
289
 

+ 2
- 20
src/net/ipv4.c View File

30
 /** List of fragment reassembly buffers */
30
 /** List of fragment reassembly buffers */
31
 static LIST_HEAD ( frag_buffers );
31
 static LIST_HEAD ( frag_buffers );
32
 
32
 
33
-static void ipv4_forget_netdev ( struct reference *ref );
34
-
35
 /**
33
 /**
36
  * Add IPv4 minirouting table entry
34
  * Add IPv4 minirouting table entry
37
  *
35
  *
61
 	}
59
 	}
62
 
60
 
63
 	/* Record routing information */
61
 	/* Record routing information */
64
-	miniroute->netdev = netdev;
62
+	miniroute->netdev = netdev_get ( netdev );
65
 	miniroute->address = address;
63
 	miniroute->address = address;
66
 	miniroute->netmask = netmask;
64
 	miniroute->netmask = netmask;
67
 	miniroute->gateway = gateway;
65
 	miniroute->gateway = gateway;
75
 		list_add ( &miniroute->list, &ipv4_miniroutes );
73
 		list_add ( &miniroute->list, &ipv4_miniroutes );
76
 	}
74
 	}
77
 
75
 
78
-	/* Record reference to net_device */
79
-	miniroute->netdev_ref.forget = ipv4_forget_netdev;
80
-	ref_add ( &miniroute->netdev_ref, &netdev->references );
81
-
82
 	return miniroute;
76
 	return miniroute;
83
 }
77
 }
84
 
78
 
95
 		DBG ( "gw %s ", inet_ntoa ( miniroute->gateway ) );
89
 		DBG ( "gw %s ", inet_ntoa ( miniroute->gateway ) );
96
 	DBG ( "via %s\n", miniroute->netdev->name );
90
 	DBG ( "via %s\n", miniroute->netdev->name );
97
 
91
 
98
-	ref_del ( &miniroute->netdev_ref );
92
+	netdev_put ( miniroute->netdev );
99
 	list_del ( &miniroute->list );
93
 	list_del ( &miniroute->list );
100
 	free ( miniroute );
94
 	free ( miniroute );
101
 }
95
 }
102
 
96
 
103
-/**
104
- * Forget reference to net_device
105
- *
106
- * @v ref		Persistent reference
107
- */
108
-static void ipv4_forget_netdev ( struct reference *ref ) {
109
-	struct ipv4_miniroute *miniroute
110
-		= container_of ( ref, struct ipv4_miniroute, netdev_ref );
111
-
112
-	del_ipv4_miniroute ( miniroute );
113
-}
114
-
115
 /**
97
 /**
116
  * Add IPv4 interface
98
  * Add IPv4 interface
117
  *
99
  *

+ 2
- 22
src/net/ipv6.c View File

32
 
32
 
33
 	/* Network device */
33
 	/* Network device */
34
 	struct net_device *netdev;
34
 	struct net_device *netdev;
35
-	/** Reference to network device */
36
-	struct reference netdev_ref;
37
 
35
 
38
 	/* Destination prefix */
36
 	/* Destination prefix */
39
 	struct in6_addr prefix;
37
 	struct in6_addr prefix;
48
 /** List of IPv6 miniroutes */
46
 /** List of IPv6 miniroutes */
49
 static LIST_HEAD ( miniroutes );
47
 static LIST_HEAD ( miniroutes );
50
 
48
 
51
-static void ipv6_forget_netdev ( struct reference *ref );
52
-
53
 /**
49
 /**
54
  * Add IPv6 minirouting table entry
50
  * Add IPv6 minirouting table entry
55
  *
51
  *
69
 	miniroute = malloc ( sizeof ( *miniroute ) );
65
 	miniroute = malloc ( sizeof ( *miniroute ) );
70
 	if ( miniroute ) {
66
 	if ( miniroute ) {
71
 		/* Record routing information */
67
 		/* Record routing information */
72
-		miniroute->netdev = netdev;
68
+		miniroute->netdev = netdev_get ( netdev );
73
 		miniroute->prefix = prefix;
69
 		miniroute->prefix = prefix;
74
 		miniroute->prefix_len = prefix_len;
70
 		miniroute->prefix_len = prefix_len;
75
 		miniroute->address = address;
71
 		miniroute->address = address;
81
 		} else {
77
 		} else {
82
 			list_add ( &miniroute->list, &miniroutes );
78
 			list_add ( &miniroute->list, &miniroutes );
83
 		}
79
 		}
84
-
85
-		/* Record reference to net_device */
86
-		miniroute->netdev_ref.forget = ipv6_forget_netdev;
87
-		ref_add ( &miniroute->netdev_ref, &netdev->references );
88
 	}
80
 	}
89
 
81
 
90
 	return miniroute;
82
 	return miniroute;
96
  * @v miniroute		Routing table entry
88
  * @v miniroute		Routing table entry
97
  */
89
  */
98
 static void del_ipv6_miniroute ( struct ipv6_miniroute *miniroute ) {
90
 static void del_ipv6_miniroute ( struct ipv6_miniroute *miniroute ) {
99
-	ref_del ( &miniroute->netdev_ref );
91
+	netdev_put ( miniroute->netdev );
100
 	list_del ( &miniroute->list );
92
 	list_del ( &miniroute->list );
101
 	free ( miniroute );
93
 	free ( miniroute );
102
 }
94
 }
103
 
95
 
104
-/**
105
- * Forget reference to net_device
106
- *
107
- * @v ref		Persistent reference
108
- */
109
-static void ipv6_forget_netdev ( struct reference *ref ) {
110
-	struct ipv6_miniroute *miniroute
111
-		= container_of ( ref, struct ipv6_miniroute, netdev_ref );
112
-
113
-	del_ipv6_miniroute ( miniroute );
114
-}
115
-
116
 /**
96
 /**
117
  * Add IPv6 interface
97
  * Add IPv6 interface
118
  *
98
  *

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

115
 	}
115
 	}
116
 }
116
 }
117
 
117
 
118
+/**
119
+ * Flush device's transmit queue
120
+ *
121
+ * @v netdev		Network device
122
+ */
123
+static void netdev_tx_flush ( struct net_device *netdev ) {
124
+
125
+	/* Discard any packets in the TX queue */
126
+	while ( ! list_empty ( &netdev->tx_queue ) ) {
127
+		netdev_tx_complete_next ( netdev );
128
+	}
129
+}
130
+
118
 /**
131
 /**
119
  * Add packet to receive queue
132
  * Add packet to receive queue
120
  *
133
  *
168
 	return NULL;
181
 	return NULL;
169
 }
182
 }
170
 
183
 
184
+/**
185
+ * Flush device's receive queue
186
+ *
187
+ * @v netdev		Network device
188
+ */
189
+static void netdev_rx_flush ( struct net_device *netdev ) {
190
+	struct io_buffer *iobuf;
191
+
192
+	/* Discard any packets in the RX queue */
193
+	while ( ( iobuf = netdev_rx_dequeue ( netdev ) ) ) {
194
+		DBGC ( netdev, "NETDEV %p discarding received %p\n",
195
+		       netdev, iobuf );
196
+		free_iob ( iobuf );
197
+	}
198
+}
199
+
200
+/**
201
+ * Free network device
202
+ *
203
+ * @v refcnt		Network device reference counter
204
+ */
205
+static void free_netdev ( struct refcnt *refcnt ) {
206
+	struct net_device *netdev =
207
+		container_of ( refcnt, struct net_device, refcnt );
208
+	
209
+	netdev_tx_flush ( netdev );
210
+	netdev_rx_flush ( netdev );
211
+	free ( netdev );
212
+}
213
+
171
 /**
214
 /**
172
  * Allocate network device
215
  * Allocate network device
173
  *
216
  *
184
 	netdev = malloc ( total_len );
227
 	netdev = malloc ( total_len );
185
 	if ( netdev ) {
228
 	if ( netdev ) {
186
 		memset ( netdev, 0, total_len );
229
 		memset ( netdev, 0, total_len );
187
-		INIT_LIST_HEAD ( &netdev->references );
230
+		netdev->refcnt.free = free_netdev;
188
 		INIT_LIST_HEAD ( &netdev->tx_queue );
231
 		INIT_LIST_HEAD ( &netdev->tx_queue );
189
 		INIT_LIST_HEAD ( &netdev->rx_queue );
232
 		INIT_LIST_HEAD ( &netdev->rx_queue );
190
 		netdev->priv = ( ( ( void * ) netdev ) + sizeof ( *netdev ) );
233
 		netdev->priv = ( ( ( void * ) netdev ) + sizeof ( *netdev ) );
209
 		   ifindex++ );
252
 		   ifindex++ );
210
 
253
 
211
 	/* Add to device list */
254
 	/* Add to device list */
255
+	netdev_get ( netdev );
212
 	list_add_tail ( &netdev->list, &net_devices );
256
 	list_add_tail ( &netdev->list, &net_devices );
213
 	DBGC ( netdev, "NETDEV %p registered as %s (phys %s hwaddr %s)\n",
257
 	DBGC ( netdev, "NETDEV %p registered as %s (phys %s hwaddr %s)\n",
214
 	       netdev, netdev->name, netdev->dev->name,
258
 	       netdev, netdev->name, netdev->dev->name,
247
  * @v netdev		Network device
291
  * @v netdev		Network device
248
  */
292
  */
249
 void netdev_close ( struct net_device *netdev ) {
293
 void netdev_close ( struct net_device *netdev ) {
250
-	struct io_buffer *iobuf;
251
 
294
 
252
 	/* Do nothing if device is already closed */
295
 	/* Do nothing if device is already closed */
253
 	if ( ! ( netdev->state & NETDEV_OPEN ) )
296
 	if ( ! ( netdev->state & NETDEV_OPEN ) )
258
 	/* Close the device */
301
 	/* Close the device */
259
 	netdev->close ( netdev );
302
 	netdev->close ( netdev );
260
 
303
 
261
-	/* Discard any packets in the TX queue */
262
-	while ( ! list_empty ( &netdev->tx_queue ) ) {
263
-		netdev_tx_complete_next ( netdev );
264
-	}
265
-
266
-	/* Discard any packets in the RX queue */
267
-	while ( ( iobuf = netdev_rx_dequeue ( netdev ) ) ) {
268
-		DBGC ( netdev, "NETDEV %p discarding received %p\n",
269
-		       netdev, iobuf );
270
-		free_iob ( iobuf );
271
-	}
304
+	/* Flush TX and RX queues */
305
+	netdev_tx_flush ( netdev );
306
+	netdev_rx_flush ( netdev );
272
 
307
 
273
 	/* Mark as closed */
308
 	/* Mark as closed */
274
 	netdev->state &= ~NETDEV_OPEN;
309
 	netdev->state &= ~NETDEV_OPEN;
286
 	/* Ensure device is closed */
321
 	/* Ensure device is closed */
287
 	netdev_close ( netdev );
322
 	netdev_close ( netdev );
288
 
323
 
289
-	/* Kill off any persistent references to this device */
290
-	forget_references ( &netdev->references );
291
-
292
 	/* Remove from device list */
324
 	/* Remove from device list */
293
 	list_del ( &netdev->list );
325
 	list_del ( &netdev->list );
326
+	netdev_put ( netdev );
294
 	DBGC ( netdev, "NETDEV %p unregistered\n", netdev );
327
 	DBGC ( netdev, "NETDEV %p unregistered\n", netdev );
295
 }
328
 }
296
 
329
 
297
-/**
298
- * Free network device
299
- *
300
- * @v netdev		Network device
301
- */
302
-void free_netdev ( struct net_device *netdev ) {
303
-	free ( netdev );
304
-}
305
-
306
 /**
330
 /**
307
  * Get network device by name
331
  * Get network device by name
308
  *
332
  *

+ 1
- 1
src/net/udp.c View File

140
  * @ret rc		Return status code
140
  * @ret rc		Return status code
141
  */
141
  */
142
 int udp_open ( struct xfer_interface *xfer, struct sockaddr *peer,
142
 int udp_open ( struct xfer_interface *xfer, struct sockaddr *peer,
143
-		      struct sockaddr *local ) {
143
+	       struct sockaddr *local ) {
144
 	return udp_open_common ( xfer, peer, local, 0 );
144
 	return udp_open_common ( xfer, peer, local, 0 );
145
 }
145
 }
146
 
146
 

+ 5
- 20
src/net/udp/dhcp.c View File

493
 	return container_of ( conn, struct dhcp_session, udp );
493
 	return container_of ( conn, struct dhcp_session, udp );
494
 }
494
 }
495
 
495
 
496
+#if 0
497
+
496
 /**
498
 /**
497
  * Mark DHCP session as complete
499
  * Mark DHCP session as complete
498
  *
500
  *
515
 	/* Close UDP connection */
517
 	/* Close UDP connection */
516
 	udp_close ( &dhcp->udp );
518
 	udp_close ( &dhcp->udp );
517
 
519
 
518
-	/* Release reference on net device */
519
-	ref_del ( &dhcp->netdev_ref );
520
-
521
 	/* Mark async operation as complete */
520
 	/* Mark async operation as complete */
522
 	async_done ( &dhcp->async, rc );
521
 	async_done ( &dhcp->async, rc );
523
 }
522
 }
705
 	.newdata	= dhcp_newdata,
704
 	.newdata	= dhcp_newdata,
706
 };
705
 };
707
 
706
 
708
-/**
709
- * Forget reference to net_device
710
- *
711
- * @v ref		Persistent reference
712
- */
713
-static void dhcp_forget_netdev ( struct reference *ref ) {
714
-	struct dhcp_session *dhcp
715
-		= container_of ( ref, struct dhcp_session, netdev_ref );
716
-
717
-	/* Kill DHCP session immediately */
718
-	dhcp_done ( dhcp, -ENETUNREACH );
719
-}
720
-
721
 /**
707
 /**
722
  * Initiate DHCP on a network interface
708
  * Initiate DHCP on a network interface
723
  *
709
  *
742
 	if ( ( rc = udp_open ( &dhcp->udp, htons ( BOOTPC_PORT ) ) ) != 0 )
728
 	if ( ( rc = udp_open ( &dhcp->udp, htons ( BOOTPC_PORT ) ) ) != 0 )
743
 		return rc;
729
 		return rc;
744
 
730
 
745
-	/* Add persistent reference to net device */
746
-	dhcp->netdev_ref.forget = dhcp_forget_netdev;
747
-	ref_add ( &dhcp->netdev_ref, &dhcp->netdev->references );
748
-
749
 	/* Proof of concept: just send a single DHCPDISCOVER */
731
 	/* Proof of concept: just send a single DHCPDISCOVER */
750
 	dhcp_send_request ( dhcp );
732
 	dhcp_send_request ( dhcp );
751
 
733
 
752
 	async_init ( &dhcp->async, &default_async_operations, parent );
734
 	async_init ( &dhcp->async, &default_async_operations, parent );
753
 	return 0;
735
 	return 0;
754
 }
736
 }
737
+
738
+
739
+#endif

Loading…
Cancel
Save