Hi:
[NET] back: Replace netif->status with netif_carrier_ok
The connection status to the frontend can be represented using
netif_carrier_ok instead of netif->status. As a result, we delay
the construction of the dev qdisc until the carrier comes on. This
is a prerequisite for adding a tx queue.
By the same token, netif->active is now simply the conjunction of
netif_running and netif_carrier_ok so it too can be removed.
Because netif_carrier_off/netif_carrier_on and rtnl_lock all entail
memory barriers, there is no need to have extra memory barriers around
them.
Signed-off-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx>
Cheers,
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@xxxxxxxxxxxxxxxxxxx>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
diff -r 7bf12da8a6ed -r c42c1f4bd148
linux-2.6-xen-sparse/drivers/xen/netback/common.h
--- a/linux-2.6-xen-sparse/drivers/xen/netback/common.h Fri Jul 28 17:51:32
2006 +1000
+++ b/linux-2.6-xen-sparse/drivers/xen/netback/common.h Fri Jul 28 18:11:09
2006 +1000
@@ -86,8 +86,6 @@ typedef struct netif_st {
struct timer_list credit_timeout;
/* Miscellaneous private stuff. */
- enum { DISCONNECTED, DISCONNECTING, CONNECTED } status;
- int active;
struct list_head list; /* scheduling list */
atomic_t refcnt;
struct net_device *dev;
diff -r 7bf12da8a6ed -r c42c1f4bd148
linux-2.6-xen-sparse/drivers/xen/netback/interface.c
--- a/linux-2.6-xen-sparse/drivers/xen/netback/interface.c Fri Jul 28
17:51:32 2006 +1000
+++ b/linux-2.6-xen-sparse/drivers/xen/netback/interface.c Fri Jul 28
18:11:09 2006 +1000
@@ -36,28 +36,20 @@
static void __netif_up(netif_t *netif)
{
- struct net_device *dev = netif->dev;
- netif_tx_lock_bh(dev);
- netif->active = 1;
- netif_tx_unlock_bh(dev);
enable_irq(netif->irq);
netif_schedule_work(netif);
}
static void __netif_down(netif_t *netif)
{
- struct net_device *dev = netif->dev;
disable_irq(netif->irq);
- netif_tx_lock_bh(dev);
- netif->active = 0;
- netif_tx_unlock_bh(dev);
netif_deschedule_work(netif);
}
static int net_open(struct net_device *dev)
{
netif_t *netif = netdev_priv(dev);
- if (netif->status == CONNECTED)
+ if (netif_carrier_ok(dev))
__netif_up(netif);
netif_start_queue(dev);
return 0;
@@ -67,7 +59,7 @@ static int net_close(struct net_device *
{
netif_t *netif = netdev_priv(dev);
netif_stop_queue(dev);
- if (netif->status == CONNECTED)
+ if (netif_carrier_ok(dev))
__netif_down(netif);
return 0;
}
@@ -93,11 +85,12 @@ netif_t *netif_alloc(domid_t domid, unsi
return ERR_PTR(-ENOMEM);
}
+ netif_carrier_off(dev);
+
netif = netdev_priv(dev);
memset(netif, 0, sizeof(*netif));
netif->domid = domid;
netif->handle = handle;
- netif->status = DISCONNECTED;
atomic_set(&netif->refcnt, 1);
init_waitqueue_head(&netif->waiting_to_free);
netif->dev = dev;
@@ -256,11 +249,9 @@ int netif_map(netif_t *netif, unsigned l
netif->rx_req_cons_peek = 0;
netif_get(netif);
- wmb(); /* Other CPUs see new state before interface is started. */
rtnl_lock();
- netif->status = CONNECTED;
- wmb();
+ netif_carrier_on(netif->dev);
if (netif_running(netif->dev))
__netif_up(netif);
rtnl_unlock();
@@ -296,20 +287,13 @@ static void netif_free(netif_t *netif)
void netif_disconnect(netif_t *netif)
{
- switch (netif->status) {
- case CONNECTED:
+ if (netif_carrier_ok(netif->dev)) {
rtnl_lock();
- netif->status = DISCONNECTING;
- wmb();
+ netif_carrier_off(netif->dev);
if (netif_running(netif->dev))
__netif_down(netif);
rtnl_unlock();
netif_put(netif);
- /* fall through */
- case DISCONNECTED:
- netif_free(netif);
- break;
- default:
- BUG();
- }
-}
+ }
+ netif_free(netif);
+}
diff -r 7bf12da8a6ed -r c42c1f4bd148
linux-2.6-xen-sparse/drivers/xen/netback/netback.c
--- a/linux-2.6-xen-sparse/drivers/xen/netback/netback.c Fri Jul 28
17:51:32 2006 +1000
+++ b/linux-2.6-xen-sparse/drivers/xen/netback/netback.c Fri Jul 28
18:11:09 2006 +1000
@@ -143,7 +143,7 @@ int netif_be_start_xmit(struct sk_buff *
BUG_ON(skb->dev != dev);
/* Drop the packet if the target domain has no receive buffers. */
- if (!netif->active ||
+ if (unlikely(!netif_running(dev) || !netif_carrier_ok(dev)) ||
(netif->rx_req_cons_peek == netif->rx.sring->req_prod) ||
((netif->rx_req_cons_peek - netif->rx.rsp_prod_pvt) ==
NET_RX_RING_SIZE))
@@ -404,7 +404,9 @@ static void add_to_net_schedule_list_tai
return;
spin_lock_irq(&net_schedule_list_lock);
- if (!__on_net_schedule_list(netif) && netif->active) {
+ if (!__on_net_schedule_list(netif) &&
+ likely(netif_running(netif->dev) &&
+ netif_carrier_ok(netif->dev))) {
list_add_tail(&netif->list, &net_schedule_list);
netif_get(netif);
}
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel
|