Browse Source

[netdevice] Add netdev_is_open() wrapper function

Signed-off-by: Michael Brown <mcb30@etherboot.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
88e436376c

+ 1
- 1
src/arch/i386/hci/commands/pxe_cmd.c View File

6
 FILE_LICENCE ( GPL2_OR_LATER );
6
 FILE_LICENCE ( GPL2_OR_LATER );
7
 
7
 
8
 static int startpxe_payload ( struct net_device *netdev ) {
8
 static int startpxe_payload ( struct net_device *netdev ) {
9
-	if ( netdev->state & NETDEV_OPEN )
9
+	if ( netdev_is_open ( netdev ) )
10
 		pxe_activate ( netdev );
10
 		pxe_activate ( netdev );
11
 	return 0;
11
 	return 0;
12
 }
12
 }

+ 1
- 1
src/arch/i386/interface/pxe/pxe_undi.c View File

366
 	/* If adapter is open, the change will have no effect; return
366
 	/* If adapter is open, the change will have no effect; return
367
 	 * an error
367
 	 * an error
368
 	 */
368
 	 */
369
-	if ( pxe_netdev->state & NETDEV_OPEN ) {
369
+	if ( netdev_is_open ( pxe_netdev ) ) {
370
 		DBG ( " failed: netdev is open\n" );
370
 		DBG ( " failed: netdev is open\n" );
371
 		undi_set_station_address->Status =
371
 		undi_set_station_address->Status =
372
 			PXENV_STATUS_UNDI_INVALID_STATE;
372
 			PXENV_STATUS_UNDI_INVALID_STATE;

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

480
 	return ( netdev->link_rc == 0 );
480
 	return ( netdev->link_rc == 0 );
481
 }
481
 }
482
 
482
 
483
+/**
484
+ * Check whether or not network device is open
485
+ *
486
+ * @v netdev		Network device
487
+ * @v is_open		Network device is open
488
+ */
489
+static inline __attribute__ (( always_inline )) int
490
+netdev_is_open ( struct net_device *netdev ) {
491
+	return ( netdev->state & NETDEV_OPEN );
492
+}
493
+
483
 extern void netdev_link_down ( struct net_device *netdev );
494
 extern void netdev_link_down ( struct net_device *netdev );
484
 extern int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf );
495
 extern int netdev_tx ( struct net_device *netdev, struct io_buffer *iobuf );
485
 extern void netdev_tx_complete_err ( struct net_device *netdev,
496
 extern void netdev_tx_complete_err ( struct net_device *netdev,

+ 2
- 2
src/interface/efi/efi_snp.c View File

328
 	memcpy ( snpdev->netdev->ll_addr, new, ll_protocol->ll_addr_len );
328
 	memcpy ( snpdev->netdev->ll_addr, new, ll_protocol->ll_addr_len );
329
 
329
 
330
 	/* MAC address changes take effect only on netdev_open() */
330
 	/* MAC address changes take effect only on netdev_open() */
331
-	if ( snpdev->netdev->state & NETDEV_OPEN ) {
331
+	if ( netdev_is_open ( snpdev->netdev ) ) {
332
 		DBGC ( snpdev, "SNPDEV %p MAC address changed while net "
332
 		DBGC ( snpdev, "SNPDEV %p MAC address changed while net "
333
 		       "devive open\n", snpdev );
333
 		       "devive open\n", snpdev );
334
 	}
334
 	}
713
 	DBGCP ( snpdev, "SNPDEV %p WAIT_FOR_PACKET\n", snpdev );
713
 	DBGCP ( snpdev, "SNPDEV %p WAIT_FOR_PACKET\n", snpdev );
714
 
714
 
715
 	/* Do nothing unless the net device is open */
715
 	/* Do nothing unless the net device is open */
716
-	if ( ! ( snpdev->netdev->state & NETDEV_OPEN ) )
716
+	if ( ! netdev_is_open ( snpdev->netdev ) )
717
 		return;
717
 		return;
718
 
718
 
719
 	/* Poll the network device */
719
 	/* Poll the network device */

+ 6
- 6
src/net/80211/net80211.c View File

1304
 	if ( ! ctx )
1304
 	if ( ! ctx )
1305
 		return NULL;
1305
 		return NULL;
1306
 
1306
 
1307
-	assert ( dev->netdev->state & NETDEV_OPEN );
1307
+	assert ( netdev_is_open ( dev->netdev ) );
1308
 
1308
 
1309
 	ctx->dev = dev;
1309
 	ctx->dev = dev;
1310
 	ctx->old_keep_mgmt = net80211_keep_mgmt ( dev, 1 );
1310
 	ctx->old_keep_mgmt = net80211_keep_mgmt ( dev, 1 );
1908
 	int key_reassoc;
1908
 	int key_reassoc;
1909
 
1909
 
1910
 	list_for_each_entry ( dev, &net80211_devices, list ) {
1910
 	list_for_each_entry ( dev, &net80211_devices, list ) {
1911
-		if ( ! ( dev->netdev->state & NETDEV_OPEN ) )
1911
+		if ( ! netdev_is_open ( dev->netdev ) )
1912
 			continue;
1912
 			continue;
1913
 
1913
 
1914
 		key_reassoc = 0;
1914
 		key_reassoc = 0;
2012
  */
2012
  */
2013
 void net80211_set_rate_idx ( struct net80211_device *dev, int rate )
2013
 void net80211_set_rate_idx ( struct net80211_device *dev, int rate )
2014
 {
2014
 {
2015
-	assert ( dev->netdev->state & NETDEV_OPEN );
2015
+	assert ( netdev_is_open ( dev->netdev ) );
2016
 
2016
 
2017
 	if ( rate >= 0 && rate < dev->nr_rates && rate != dev->rate ) {
2017
 	if ( rate >= 0 && rate < dev->nr_rates && rate != dev->rate ) {
2018
 		DBGC2 ( dev, "802.11 %p changing rate from %d->%d Mbps\n",
2018
 		DBGC2 ( dev, "802.11 %p changing rate from %d->%d Mbps\n",
2035
 {
2035
 {
2036
 	int i, oldchan = dev->channel;
2036
 	int i, oldchan = dev->channel;
2037
 
2037
 
2038
-	assert ( dev->netdev->state & NETDEV_OPEN );
2038
+	assert ( netdev_is_open ( dev->netdev ) );
2039
 
2039
 
2040
 	for ( i = 0; i < dev->nr_channels; i++ ) {
2040
 	for ( i = 0; i < dev->nr_channels; i++ ) {
2041
 		if ( dev->channels[i].channel_nr == channel ) {
2041
 		if ( dev->channels[i].channel_nr == channel ) {
2064
 int net80211_prepare_probe ( struct net80211_device *dev, int band,
2064
 int net80211_prepare_probe ( struct net80211_device *dev, int band,
2065
 			     int active )
2065
 			     int active )
2066
 {
2066
 {
2067
-	assert ( dev->netdev->state & NETDEV_OPEN );
2067
+	assert ( netdev_is_open ( dev->netdev ) );
2068
 
2068
 
2069
 	if ( active && ( band & NET80211_BAND_BIT_5GHZ ) ) {
2069
 	if ( active && ( band & NET80211_BAND_BIT_5GHZ ) ) {
2070
 		DBGC ( dev, "802.11 %p cannot perform active scanning on "
2070
 		DBGC ( dev, "802.11 %p cannot perform active scanning on "
2124
 	struct net80211_handshaker *handshaker;
2124
 	struct net80211_handshaker *handshaker;
2125
 	int rc;
2125
 	int rc;
2126
 
2126
 
2127
-	assert ( dev->netdev->state & NETDEV_OPEN );
2127
+	assert ( netdev_is_open ( dev->netdev ) );
2128
 
2128
 
2129
 	net80211_set_state ( dev, NET80211_ASSOCIATED, 0, 0 );
2129
 	net80211_set_state ( dev, NET80211_ASSOCIATED, 0, 0 );
2130
 	memcpy ( dev->bssid, wlan->bssid, ETH_ALEN );
2130
 	memcpy ( dev->bssid, wlan->bssid, ETH_ALEN );

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

118
 
118
 
119
 	/* Find first usable route in routing table */
119
 	/* Find first usable route in routing table */
120
 	list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) {
120
 	list_for_each_entry ( miniroute, &ipv4_miniroutes, list ) {
121
-		if ( ! ( miniroute->netdev->state & NETDEV_OPEN ) )
121
+		if ( ! netdev_is_open ( miniroute->netdev ) )
122
 			continue;
122
 			continue;
123
 		local = ( ( ( dest->s_addr ^ miniroute->address.s_addr )
123
 		local = ( ( ( dest->s_addr ^ miniroute->address.s_addr )
124
 			    & miniroute->netmask.s_addr ) == 0 );
124
 			    & miniroute->netmask.s_addr ) == 0 );

+ 3
- 3
src/net/netdevice.c View File

130
 
130
 
131
 	list_add_tail ( &iobuf->list, &netdev->tx_queue );
131
 	list_add_tail ( &iobuf->list, &netdev->tx_queue );
132
 
132
 
133
-	if ( ! ( netdev->state & NETDEV_OPEN ) ) {
133
+	if ( ! netdev_is_open ( netdev ) ) {
134
 		rc = -ENETUNREACH;
134
 		rc = -ENETUNREACH;
135
 		goto err;
135
 		goto err;
136
 	}
136
 	}
263
  */
263
  */
264
 void netdev_poll ( struct net_device *netdev ) {
264
 void netdev_poll ( struct net_device *netdev ) {
265
 
265
 
266
-	if ( netdev->state & NETDEV_OPEN )
266
+	if ( netdev_is_open ( netdev ) )
267
 		netdev->op->poll ( netdev );
267
 		netdev->op->poll ( netdev );
268
 }
268
 }
269
 
269
 
509
 	struct net_device *netdev;
509
 	struct net_device *netdev;
510
 
510
 
511
 	list_for_each_entry ( netdev, &open_net_devices, open_list ) {
511
 	list_for_each_entry ( netdev, &open_net_devices, open_list ) {
512
-		assert ( netdev->state & NETDEV_OPEN );
512
+		assert ( netdev_is_open ( netdev ) );
513
 		return netdev;
513
 		return netdev;
514
 	}
514
 	}
515
 
515
 

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

90
 	printf ( "%s: %s on %s (%s)\n"
90
 	printf ( "%s: %s on %s (%s)\n"
91
 		 "  [Link:%s, TX:%d TXE:%d RX:%d RXE:%d]\n",
91
 		 "  [Link:%s, TX:%d TXE:%d RX:%d RXE:%d]\n",
92
 		 netdev->name, netdev_addr ( netdev ), netdev->dev->name,
92
 		 netdev->name, netdev_addr ( netdev ), netdev->dev->name,
93
-		 ( ( netdev->state & NETDEV_OPEN ) ? "open" : "closed" ),
93
+		 ( netdev_is_open ( netdev ) ? "open" : "closed" ),
94
 		 ( netdev_link_ok ( netdev ) ? "up" : "down" ),
94
 		 ( netdev_link_ok ( netdev ) ? "up" : "down" ),
95
 		 netdev->tx_stats.good, netdev->tx_stats.bad,
95
 		 netdev->tx_stats.good, netdev->tx_stats.bad,
96
 		 netdev->rx_stats.good, netdev->rx_stats.bad );
96
 		 netdev->rx_stats.good, netdev->rx_stats.bad );

+ 1
- 1
src/usr/iwmgmt.c View File

125
 	char ssid_buf[22];
125
 	char ssid_buf[22];
126
 	int rc;
126
 	int rc;
127
 	unsigned i;
127
 	unsigned i;
128
-	int was_opened = dev->netdev->state & NETDEV_OPEN;
128
+	int was_opened = netdev_is_open ( dev->netdev );
129
 	int was_channel = dev->channels[dev->channel].channel_nr;
129
 	int was_channel = dev->channels[dev->channel].channel_nr;
130
 
130
 
131
 	if ( ! was_opened ) {
131
 	if ( ! was_opened ) {

+ 1
- 1
src/usr/route.c View File

38
 		printf ( "%s", inet_ntoa ( miniroute->netmask ) );
38
 		printf ( "%s", inet_ntoa ( miniroute->netmask ) );
39
 		if ( miniroute->gateway.s_addr )
39
 		if ( miniroute->gateway.s_addr )
40
 			printf ( " gw %s", inet_ntoa ( miniroute->gateway ) );
40
 			printf ( " gw %s", inet_ntoa ( miniroute->gateway ) );
41
-		if ( ! ( miniroute->netdev->state & NETDEV_OPEN ) )
41
+		if ( ! netdev_is_open ( miniroute->netdev ) )
42
 			printf ( " (inaccessible)" );
42
 			printf ( " (inaccessible)" );
43
 		printf ( "\n" );
43
 		printf ( "\n" );
44
 	}
44
 	}

Loading…
Cancel
Save