Kaynağa Gözat

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 yıl önce
ebeveyn
işleme
f77815f2b1

+ 2
- 2
src/arch/i386/drivers/net/undinet.c Dosyayı Görüntüle

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

+ 0
- 45
src/core/hotplug.c Dosyayı Görüntüle

@@ -1,45 +0,0 @@
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 Dosyayı Görüntüle

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

+ 7
- 9
src/drivers/net/pnic.c Dosyayı Görüntüle

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

+ 14
- 21
src/drivers/net/rtl8139.c Dosyayı Görüntüle

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

+ 0
- 3
src/include/gpxe/aoe.h Dosyayı Görüntüle

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

+ 2
- 3
src/include/gpxe/dhcp.h Dosyayı Görüntüle

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

+ 0
- 58
src/include/gpxe/hotplug.h Dosyayı Görüntüle

@@ -1,58 +0,0 @@
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 Dosyayı Görüntüle

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

+ 25
- 4
src/include/gpxe/netdevice.h Dosyayı Görüntüle

@@ -10,7 +10,7 @@
10 10
 #include <stdint.h>
11 11
 #include <gpxe/list.h>
12 12
 #include <gpxe/tables.h>
13
-#include <gpxe/hotplug.h>
13
+#include <gpxe/refcnt.h>
14 14
 
15 15
 struct io_buffer;
16 16
 struct net_device;
@@ -137,14 +137,14 @@ struct ll_protocol {
137 137
  * not just an Ethernet device.
138 138
  */
139 139
 struct net_device {
140
+	/** Reference counter */
141
+	struct refcnt refcnt;
140 142
 	/** List of network devices */
141 143
 	struct list_head list;
142 144
 	/** Name of this network device */
143 145
 	char name[8];
144 146
 	/** Underlying hardware device */
145 147
 	struct device *dev;
146
-	/** List of persistent reference holders */
147
-	struct list_head references;
148 148
 
149 149
 	/** Open network device
150 150
 	 *
@@ -251,6 +251,28 @@ static inline int have_netdevs ( void ) {
251 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 276
 extern int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf );
255 277
 void netdev_tx_complete ( struct net_device *netdev, struct io_buffer *iobuf );
256 278
 void netdev_tx_complete_next ( struct net_device *netdev );
@@ -262,7 +284,6 @@ extern int register_netdev ( struct net_device *netdev );
262 284
 extern int netdev_open ( struct net_device *netdev );
263 285
 extern void netdev_close ( struct net_device *netdev );
264 286
 extern void unregister_netdev ( struct net_device *netdev );
265
-extern void free_netdev ( struct net_device *netdev );
266 287
 struct net_device * find_netdev ( const char *name );
267 288
 struct net_device * find_pci_netdev ( unsigned int busdevfn );
268 289
 

+ 0
- 17
src/net/aoe.c Dosyayı Görüntüle

@@ -265,19 +265,6 @@ struct net_protocol aoe_protocol __net_protocol = {
265 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 269
  * Open AoE session
283 270
  *
@@ -288,8 +275,6 @@ void aoe_open ( struct aoe_session *aoe ) {
288 275
 		 sizeof ( aoe->target ) );
289 276
 	aoe->tag = AOE_TAG_MAGIC;
290 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 278
 	list_add ( &aoe->list, &aoe_sessions );
294 279
 }
295 280
 
@@ -299,8 +284,6 @@ void aoe_open ( struct aoe_session *aoe ) {
299 284
  * @v aoe		AoE session
300 285
  */
301 286
 void aoe_close ( struct aoe_session *aoe ) {
302
-	if ( aoe->netdev )
303
-		ref_del ( &aoe->netdev_ref );
304 287
 	list_del ( &aoe->list );
305 288
 }
306 289
 

+ 2
- 20
src/net/ipv4.c Dosyayı Görüntüle

@@ -30,8 +30,6 @@ struct list_head ipv4_miniroutes = LIST_HEAD_INIT ( ipv4_miniroutes );
30 30
 /** List of fragment reassembly buffers */
31 31
 static LIST_HEAD ( frag_buffers );
32 32
 
33
-static void ipv4_forget_netdev ( struct reference *ref );
34
-
35 33
 /**
36 34
  * Add IPv4 minirouting table entry
37 35
  *
@@ -61,7 +59,7 @@ static struct ipv4_miniroute * add_ipv4_miniroute ( struct net_device *netdev,
61 59
 	}
62 60
 
63 61
 	/* Record routing information */
64
-	miniroute->netdev = netdev;
62
+	miniroute->netdev = netdev_get ( netdev );
65 63
 	miniroute->address = address;
66 64
 	miniroute->netmask = netmask;
67 65
 	miniroute->gateway = gateway;
@@ -75,10 +73,6 @@ static struct ipv4_miniroute * add_ipv4_miniroute ( struct net_device *netdev,
75 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 76
 	return miniroute;
83 77
 }
84 78
 
@@ -95,23 +89,11 @@ static void del_ipv4_miniroute ( struct ipv4_miniroute *miniroute ) {
95 89
 		DBG ( "gw %s ", inet_ntoa ( miniroute->gateway ) );
96 90
 	DBG ( "via %s\n", miniroute->netdev->name );
97 91
 
98
-	ref_del ( &miniroute->netdev_ref );
92
+	netdev_put ( miniroute->netdev );
99 93
 	list_del ( &miniroute->list );
100 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 98
  * Add IPv4 interface
117 99
  *

+ 2
- 22
src/net/ipv6.c Dosyayı Görüntüle

@@ -32,8 +32,6 @@ struct ipv6_miniroute {
32 32
 
33 33
 	/* Network device */
34 34
 	struct net_device *netdev;
35
-	/** Reference to network device */
36
-	struct reference netdev_ref;
37 35
 
38 36
 	/* Destination prefix */
39 37
 	struct in6_addr prefix;
@@ -48,8 +46,6 @@ struct ipv6_miniroute {
48 46
 /** List of IPv6 miniroutes */
49 47
 static LIST_HEAD ( miniroutes );
50 48
 
51
-static void ipv6_forget_netdev ( struct reference *ref );
52
-
53 49
 /**
54 50
  * Add IPv6 minirouting table entry
55 51
  *
@@ -69,7 +65,7 @@ static struct ipv6_miniroute * add_ipv6_miniroute ( struct net_device *netdev,
69 65
 	miniroute = malloc ( sizeof ( *miniroute ) );
70 66
 	if ( miniroute ) {
71 67
 		/* Record routing information */
72
-		miniroute->netdev = netdev;
68
+		miniroute->netdev = netdev_get ( netdev );
73 69
 		miniroute->prefix = prefix;
74 70
 		miniroute->prefix_len = prefix_len;
75 71
 		miniroute->address = address;
@@ -81,10 +77,6 @@ static struct ipv6_miniroute * add_ipv6_miniroute ( struct net_device *netdev,
81 77
 		} else {
82 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 82
 	return miniroute;
@@ -96,23 +88,11 @@ static struct ipv6_miniroute * add_ipv6_miniroute ( struct net_device *netdev,
96 88
  * @v miniroute		Routing table entry
97 89
  */
98 90
 static void del_ipv6_miniroute ( struct ipv6_miniroute *miniroute ) {
99
-	ref_del ( &miniroute->netdev_ref );
91
+	netdev_put ( miniroute->netdev );
100 92
 	list_del ( &miniroute->list );
101 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 97
  * Add IPv6 interface
118 98
  *

+ 49
- 25
src/net/netdevice.c Dosyayı Görüntüle

@@ -115,6 +115,19 @@ void netdev_tx_complete_next ( struct net_device *netdev ) {
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 132
  * Add packet to receive queue
120 133
  *
@@ -168,6 +181,36 @@ struct io_buffer * netdev_rx_dequeue ( struct net_device *netdev ) {
168 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 215
  * Allocate network device
173 216
  *
@@ -184,7 +227,7 @@ struct net_device * alloc_netdev ( size_t priv_size ) {
184 227
 	netdev = malloc ( total_len );
185 228
 	if ( netdev ) {
186 229
 		memset ( netdev, 0, total_len );
187
-		INIT_LIST_HEAD ( &netdev->references );
230
+		netdev->refcnt.free = free_netdev;
188 231
 		INIT_LIST_HEAD ( &netdev->tx_queue );
189 232
 		INIT_LIST_HEAD ( &netdev->rx_queue );
190 233
 		netdev->priv = ( ( ( void * ) netdev ) + sizeof ( *netdev ) );
@@ -209,6 +252,7 @@ int register_netdev ( struct net_device *netdev ) {
209 252
 		   ifindex++ );
210 253
 
211 254
 	/* Add to device list */
255
+	netdev_get ( netdev );
212 256
 	list_add_tail ( &netdev->list, &net_devices );
213 257
 	DBGC ( netdev, "NETDEV %p registered as %s (phys %s hwaddr %s)\n",
214 258
 	       netdev, netdev->name, netdev->dev->name,
@@ -247,7 +291,6 @@ int netdev_open ( struct net_device *netdev ) {
247 291
  * @v netdev		Network device
248 292
  */
249 293
 void netdev_close ( struct net_device *netdev ) {
250
-	struct io_buffer *iobuf;
251 294
 
252 295
 	/* Do nothing if device is already closed */
253 296
 	if ( ! ( netdev->state & NETDEV_OPEN ) )
@@ -258,17 +301,9 @@ void netdev_close ( struct net_device *netdev ) {
258 301
 	/* Close the device */
259 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 308
 	/* Mark as closed */
274 309
 	netdev->state &= ~NETDEV_OPEN;
@@ -286,23 +321,12 @@ void unregister_netdev ( struct net_device *netdev ) {
286 321
 	/* Ensure device is closed */
287 322
 	netdev_close ( netdev );
288 323
 
289
-	/* Kill off any persistent references to this device */
290
-	forget_references ( &netdev->references );
291
-
292 324
 	/* Remove from device list */
293 325
 	list_del ( &netdev->list );
326
+	netdev_put ( netdev );
294 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 331
  * Get network device by name
308 332
  *

+ 1
- 1
src/net/udp.c Dosyayı Görüntüle

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

+ 5
- 20
src/net/udp/dhcp.c Dosyayı Görüntüle

@@ -493,6 +493,8 @@ udp_to_dhcp ( struct udp_connection *conn ) {
493 493
 	return container_of ( conn, struct dhcp_session, udp );
494 494
 }
495 495
 
496
+#if 0
497
+
496 498
 /**
497 499
  * Mark DHCP session as complete
498 500
  *
@@ -515,9 +517,6 @@ static void dhcp_done ( struct dhcp_session *dhcp, int rc ) {
515 517
 	/* Close UDP connection */
516 518
 	udp_close ( &dhcp->udp );
517 519
 
518
-	/* Release reference on net device */
519
-	ref_del ( &dhcp->netdev_ref );
520
-
521 520
 	/* Mark async operation as complete */
522 521
 	async_done ( &dhcp->async, rc );
523 522
 }
@@ -705,19 +704,6 @@ static struct udp_operations dhcp_udp_operations = {
705 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 708
  * Initiate DHCP on a network interface
723 709
  *
@@ -742,13 +728,12 @@ int start_dhcp ( struct dhcp_session *dhcp, struct async *parent ) {
742 728
 	if ( ( rc = udp_open ( &dhcp->udp, htons ( BOOTPC_PORT ) ) ) != 0 )
743 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 731
 	/* Proof of concept: just send a single DHCPDISCOVER */
750 732
 	dhcp_send_request ( dhcp );
751 733
 
752 734
 	async_init ( &dhcp->async, &default_async_operations, parent );
753 735
 	return 0;
754 736
 }
737
+
738
+
739
+#endif

Loading…
İptal
Kaydet