ia64/xen-unstable

changeset 3375:553a6dd82045

bitkeeper revision 1.1159.1.528 (41d83186uvNJ8388x-d-fqkRrnEx5Q)

Merge tempest.cl.cam.ac.uk:/auto/groups/xeno-xenod/BK/xeno.bk
into tempest.cl.cam.ac.uk:/local/scratch/smh22/xen-unstable.bk
author smh22@tempest.cl.cam.ac.uk
date Sun Jan 02 17:38:14 2005 +0000 (2005-01-02)
parents 7cbc6c9823eb 2abc9e0c7f87
children 0451cbfd268d
files linux-2.6.10-xen-sparse/drivers/xen/netback/common.h linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c linux-2.6.10-xen-sparse/drivers/xen/netback/netback.c linux-2.6.10-xen-sparse/drivers/xen/netfront/netfront.c tools/examples/vif-bridge
line diff
     1.1 --- a/linux-2.6.10-xen-sparse/drivers/xen/netback/common.h	Fri Dec 31 19:23:11 2004 +0000
     1.2 +++ b/linux-2.6.10-xen-sparse/drivers/xen/netback/common.h	Sun Jan 02 17:38:14 2005 +0000
     1.3 @@ -59,6 +59,7 @@ typedef struct netif_st {
     1.4  
     1.5      /* Miscellaneous private stuff. */
     1.6      enum { DISCONNECTED, DISCONNECTING, CONNECTED } status;
     1.7 +    int active;
     1.8      /*
     1.9       * DISCONNECT response is deferred until pending requests are ack'ed.
    1.10       * We therefore need to store the id from the original request.
    1.11 @@ -67,7 +68,6 @@ typedef struct netif_st {
    1.12      struct netif_st *hash_next;
    1.13      struct list_head list;  /* scheduling list */
    1.14      atomic_t         refcnt;
    1.15 -    spinlock_t       rx_lock, tx_lock;
    1.16      struct net_device *dev;
    1.17      struct net_device_stats stats;
    1.18  
    1.19 @@ -90,7 +90,8 @@ netif_t *netif_find_by_handle(domid_t do
    1.20  void netif_interface_init(void);
    1.21  void netif_ctrlif_init(void);
    1.22  
    1.23 -void netif_deschedule(netif_t *netif);
    1.24 +void netif_schedule_work(netif_t *netif);
    1.25 +void netif_deschedule_work(netif_t *netif);
    1.26  
    1.27  int netif_be_start_xmit(struct sk_buff *skb, struct net_device *dev);
    1.28  struct net_device_stats *netif_be_get_stats(struct net_device *dev);
     2.1 --- a/linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c	Fri Dec 31 19:23:11 2004 +0000
     2.2 +++ b/linux-2.6.10-xen-sparse/drivers/xen/netback/interface.c	Sun Jan 02 17:38:14 2005 +0000
     2.3 @@ -27,6 +27,44 @@ netif_t *netif_find_by_handle(domid_t do
     2.4      return netif;
     2.5  }
     2.6  
     2.7 +static void __netif_up(netif_t *netif)
     2.8 +{
     2.9 +    struct net_device *dev = netif->dev;
    2.10 +    spin_lock_bh(&dev->xmit_lock);
    2.11 +    netif->active = 1;
    2.12 +    spin_unlock_bh(&dev->xmit_lock);
    2.13 +    (void)request_irq(netif->irq, netif_be_int, 0, dev->name, netif);
    2.14 +    netif_schedule_work(netif);
    2.15 +}
    2.16 +
    2.17 +static void __netif_down(netif_t *netif)
    2.18 +{
    2.19 +    struct net_device *dev = netif->dev;
    2.20 +    spin_lock_bh(&dev->xmit_lock);
    2.21 +    netif->active = 0;
    2.22 +    spin_unlock_bh(&dev->xmit_lock);
    2.23 +    free_irq(netif->irq, netif);
    2.24 +    netif_deschedule_work(netif);
    2.25 +}
    2.26 +
    2.27 +static int net_open(struct net_device *dev)
    2.28 +{
    2.29 +    netif_t *netif = netdev_priv(dev);
    2.30 +    if ( netif->status == CONNECTED )
    2.31 +        __netif_up(netif);
    2.32 +    netif_start_queue(dev);
    2.33 +    return 0;
    2.34 +}
    2.35 +
    2.36 +static int net_close(struct net_device *dev)
    2.37 +{
    2.38 +    netif_t *netif = netdev_priv(dev);
    2.39 +    netif_stop_queue(dev);
    2.40 +    if ( netif->status == CONNECTED )
    2.41 +        __netif_down(netif);
    2.42 +    return 0;
    2.43 +}
    2.44 +
    2.45  static void __netif_disconnect_complete(void *arg)
    2.46  {
    2.47      netif_t              *netif = (netif_t *)arg;
    2.48 @@ -40,9 +78,6 @@ static void __netif_disconnect_complete(
    2.49       */
    2.50      unbind_evtchn_from_irq(netif->evtchn);
    2.51      vfree(netif->tx); /* Frees netif->rx as well. */
    2.52 -    rtnl_lock();
    2.53 -    (void)dev_close(netif->dev);
    2.54 -    rtnl_unlock();
    2.55  
    2.56      /* Construct the deferred response message. */
    2.57      cmsg.type         = CMSG_NETIF_BE;
    2.58 @@ -95,13 +130,11 @@ void netif_create(netif_be_create_t *cre
    2.59          return;
    2.60      }
    2.61  
    2.62 -    netif = dev->priv;
    2.63 +    netif = netdev_priv(dev);
    2.64      memset(netif, 0, sizeof(*netif));
    2.65      netif->domid  = domid;
    2.66      netif->handle = handle;
    2.67      netif->status = DISCONNECTED;
    2.68 -    spin_lock_init(&netif->rx_lock);
    2.69 -    spin_lock_init(&netif->tx_lock);
    2.70      atomic_set(&netif->refcnt, 0);
    2.71      netif->dev = dev;
    2.72  
    2.73 @@ -124,6 +157,8 @@ void netif_create(netif_be_create_t *cre
    2.74  
    2.75      dev->hard_start_xmit = netif_be_start_xmit;
    2.76      dev->get_stats       = netif_be_get_stats;
    2.77 +    dev->open            = net_open;
    2.78 +    dev->stop            = net_close;
    2.79  
    2.80      /* Disable queuing. */
    2.81      dev->tx_queue_len = 0;
    2.82 @@ -136,7 +171,11 @@ void netif_create(netif_be_create_t *cre
    2.83      memset(dev->dev_addr, 0xFF, ETH_ALEN);
    2.84      dev->dev_addr[0] &= ~0x01;
    2.85  
    2.86 -    if ( (err = register_netdev(dev)) != 0 )
    2.87 +    rtnl_lock();
    2.88 +    err = register_netdevice(dev);
    2.89 +    rtnl_unlock();
    2.90 +
    2.91 +    if ( err != 0 )
    2.92      {
    2.93          DPRINTK("Could not register new net device %s: err=%d\n",
    2.94                  dev->name, err);
    2.95 @@ -249,18 +288,17 @@ void netif_connect(netif_be_connect_t *c
    2.96          (netif_tx_interface_t *)vma->addr;
    2.97      netif->rx             = 
    2.98          (netif_rx_interface_t *)((char *)vma->addr + PAGE_SIZE);
    2.99 -    netif->status         = CONNECTED;
   2.100 +    netif->tx->resp_prod = netif->rx->resp_prod = 0;
   2.101      netif_get(netif);
   2.102 -
   2.103 -    netif->tx->resp_prod = netif->rx->resp_prod = 0;
   2.104 +    wmb(); /* Other CPUs see new state before interface is started. */
   2.105  
   2.106      rtnl_lock();
   2.107 -    (void)dev_open(netif->dev);
   2.108 +    netif->status = CONNECTED;
   2.109 +    wmb();
   2.110 +    if ( netif_running(netif->dev) )
   2.111 +        __netif_up(netif);
   2.112      rtnl_unlock();
   2.113  
   2.114 -    (void)request_irq(netif->irq, netif_be_int, 0, netif->dev->name, netif);
   2.115 -    netif_start_queue(netif->dev);
   2.116 -
   2.117      connect->status = NETIF_BE_STATUS_OKAY;
   2.118  }
   2.119  
   2.120 @@ -281,12 +319,13 @@ int netif_disconnect(netif_be_disconnect
   2.121  
   2.122      if ( netif->status == CONNECTED )
   2.123      {
   2.124 +        rtnl_lock();
   2.125          netif->status = DISCONNECTING;
   2.126          netif->disconnect_rspid = rsp_id;
   2.127 -        wmb(); /* Let other CPUs see the status change. */
   2.128 -        netif_stop_queue(netif->dev);
   2.129 -        free_irq(netif->irq, netif);
   2.130 -        netif_deschedule(netif);
   2.131 +        wmb();
   2.132 +        if ( netif_running(netif->dev) )
   2.133 +            __netif_down(netif);
   2.134 +        rtnl_unlock();
   2.135          netif_put(netif);
   2.136          return 0; /* Caller should not send response message. */
   2.137      }
     3.1 --- a/linux-2.6.10-xen-sparse/drivers/xen/netback/netback.c	Fri Dec 31 19:23:11 2004 +0000
     3.2 +++ b/linux-2.6.10-xen-sparse/drivers/xen/netback/netback.c	Sun Jan 02 17:38:14 2005 +0000
     3.3 @@ -59,7 +59,6 @@ static PEND_RING_IDX pending_prod, pendi
     3.4  
     3.5  /* Freed TX SKBs get batched on this ring before return to pending_ring. */
     3.6  static u16 dealloc_ring[MAX_PENDING_REQS];
     3.7 -static spinlock_t dealloc_lock = SPIN_LOCK_UNLOCKED;
     3.8  static PEND_RING_IDX dealloc_prod, dealloc_cons;
     3.9  
    3.10  static struct sk_buff_head tx_queue;
    3.11 @@ -123,12 +122,13 @@ static inline int is_xen_skb(struct sk_b
    3.12  
    3.13  int netif_be_start_xmit(struct sk_buff *skb, struct net_device *dev)
    3.14  {
    3.15 -    netif_t *netif = (netif_t *)dev->priv;
    3.16 +    netif_t *netif = netdev_priv(dev);
    3.17  
    3.18      ASSERT(skb->dev == dev);
    3.19  
    3.20      /* Drop the packet if the target domain has no receive buffers. */
    3.21 -    if ( (netif->rx_req_cons == netif->rx->req_prod) ||
    3.22 +    if ( !netif->active || 
    3.23 +         (netif->rx_req_cons == netif->rx->req_prod) ||
    3.24           ((netif->rx_req_cons-netif->rx_resp_prod) == NETIF_RX_RING_SIZE) )
    3.25          goto drop;
    3.26  
    3.27 @@ -154,6 +154,7 @@ int netif_be_start_xmit(struct sk_buff *
    3.28      }
    3.29  
    3.30      netif->rx_req_cons++;
    3.31 +    netif_get(netif);
    3.32  
    3.33      skb_queue_tail(&rx_queue, skb);
    3.34      tasklet_schedule(&net_rx_tasklet);
    3.35 @@ -204,7 +205,7 @@ static void net_rx_action(unsigned long 
    3.36      mmu = rx_mmu;
    3.37      while ( (skb = skb_dequeue(&rx_queue)) != NULL )
    3.38      {
    3.39 -        netif   = (netif_t *)skb->dev->priv;
    3.40 +        netif   = netdev_priv(skb->dev);
    3.41          vdata   = (unsigned long)skb->data;
    3.42          mdata   = virt_to_machine(vdata);
    3.43  
    3.44 @@ -214,6 +215,7 @@ static void net_rx_action(unsigned long 
    3.45              if ( net_ratelimit() )
    3.46                  printk(KERN_WARNING "Memory squeeze in netback driver.\n");
    3.47              mod_timer(&net_timer, jiffies + HZ);
    3.48 +            skb_queue_head(&rx_queue, skb);
    3.49              break;
    3.50          }
    3.51  
    3.52 @@ -261,7 +263,7 @@ static void net_rx_action(unsigned long 
    3.53      mmu = rx_mmu;
    3.54      while ( (skb = __skb_dequeue(&rxq)) != NULL )
    3.55      {
    3.56 -        netif   = (netif_t *)skb->dev->priv;
    3.57 +        netif   = netdev_priv(skb->dev);
    3.58          size    = skb->tail - skb->data;
    3.59  
    3.60          /* Rederive the machine addresses. */
    3.61 @@ -298,6 +300,7 @@ static void net_rx_action(unsigned long 
    3.62              notify_list[notify_nr++] = evtchn;
    3.63          }
    3.64  
    3.65 +        netif_put(netif);
    3.66          dev_kfree_skb(skb);
    3.67  
    3.68          mcl += 2;
    3.69 @@ -327,7 +330,7 @@ static void net_alarm(unsigned long unus
    3.70  
    3.71  struct net_device_stats *netif_be_get_stats(struct net_device *dev)
    3.72  {
    3.73 -    netif_t *netif = dev->priv;
    3.74 +    netif_t *netif = netdev_priv(dev);
    3.75      return &netif->stats;
    3.76  }
    3.77  
    3.78 @@ -354,7 +357,7 @@ static void add_to_net_schedule_list_tai
    3.79          return;
    3.80  
    3.81      spin_lock_irq(&net_schedule_list_lock);
    3.82 -    if ( !__on_net_schedule_list(netif) && (netif->status == CONNECTED) )
    3.83 +    if ( !__on_net_schedule_list(netif) && netif->active )
    3.84      {
    3.85          list_add_tail(&netif->list, &net_schedule_list);
    3.86          netif_get(netif);
    3.87 @@ -362,7 +365,7 @@ static void add_to_net_schedule_list_tai
    3.88      spin_unlock_irq(&net_schedule_list_lock);
    3.89  }
    3.90  
    3.91 -static inline void netif_schedule_work(netif_t *netif)
    3.92 +void netif_schedule_work(netif_t *netif)
    3.93  {
    3.94      if ( (netif->tx_req_cons != netif->tx->req_prod) &&
    3.95           ((netif->tx_req_cons-netif->tx_resp_prod) != NETIF_TX_RING_SIZE) )
    3.96 @@ -372,7 +375,7 @@ static inline void netif_schedule_work(n
    3.97      }
    3.98  }
    3.99  
   3.100 -void netif_deschedule(netif_t *netif)
   3.101 +void netif_deschedule_work(netif_t *netif)
   3.102  {
   3.103      remove_from_net_schedule_list(netif);
   3.104  }
   3.105 @@ -427,10 +430,8 @@ static void net_tx_action(unsigned long 
   3.106  
   3.107          netif = pending_tx_info[pending_idx].netif;
   3.108  
   3.109 -        spin_lock(&netif->tx_lock);
   3.110          make_tx_response(netif, pending_tx_info[pending_idx].req.id, 
   3.111                           NETIF_RSP_OKAY);
   3.112 -        spin_unlock(&netif->tx_lock);
   3.113          
   3.114          pending_ring[MASK_PEND_IDX(pending_prod++)] = pending_idx;
   3.115  
   3.116 @@ -631,11 +632,12 @@ static void net_tx_action(unsigned long 
   3.117  
   3.118  static void netif_idx_release(u16 pending_idx)
   3.119  {
   3.120 +    static spinlock_t _lock = SPIN_LOCK_UNLOCKED;
   3.121      unsigned long flags;
   3.122  
   3.123 -    spin_lock_irqsave(&dealloc_lock, flags);
   3.124 +    spin_lock_irqsave(&_lock, flags);
   3.125      dealloc_ring[MASK_PEND_IDX(dealloc_prod++)] = pending_idx;
   3.126 -    spin_unlock_irqrestore(&dealloc_lock, flags);
   3.127 +    spin_unlock_irqrestore(&_lock, flags);
   3.128  
   3.129      tasklet_schedule(&net_tx_tasklet);
   3.130  }
   3.131 @@ -658,46 +660,6 @@ static void netif_skb_release(struct sk_
   3.132      netif_idx_release(pending_idx);
   3.133  }
   3.134  
   3.135 -#if 0
   3.136 -long flush_bufs_for_netif(netif_t *netif)
   3.137 -{
   3.138 -    NETIF_RING_IDX i;
   3.139 -
   3.140 -    /* Return any outstanding receive buffers to the guest OS. */
   3.141 -    spin_lock(&netif->rx_lock);
   3.142 -    for ( i = netif->rx_req_cons; 
   3.143 -          (i != netif->rx->req_prod) &&
   3.144 -              ((i-netif->rx_resp_prod) != NETIF_RX_RING_SIZE);
   3.145 -          i++ )
   3.146 -    {
   3.147 -        make_rx_response(netif,
   3.148 -                         netif->rx->ring[MASK_NETIF_RX_IDX(i)].req.id,
   3.149 -                         NETIF_RSP_DROPPED, 0, 0);
   3.150 -    }
   3.151 -    netif->rx_req_cons = i;
   3.152 -    spin_unlock(&netif->rx_lock);
   3.153 -
   3.154 -    /*
   3.155 -     * Flush pending transmit buffers. The guest may still have to wait for
   3.156 -     * buffers that are queued at a physical NIC.
   3.157 -     */
   3.158 -    spin_lock(&netif->tx_lock);
   3.159 -    for ( i = netif->tx_req_cons; 
   3.160 -          (i != netif->tx->req_prod) &&
   3.161 -              ((i-netif->tx_resp_prod) != NETIF_TX_RING_SIZE);
   3.162 -          i++ )
   3.163 -    {
   3.164 -        make_tx_response(netif,
   3.165 -                         netif->tx->ring[MASK_NETIF_TX_IDX(i)].req.id,
   3.166 -                         NETIF_RSP_DROPPED);
   3.167 -    }
   3.168 -    netif->tx_req_cons = i;
   3.169 -    spin_unlock(&netif->tx_lock);
   3.170 -
   3.171 -    return 0;
   3.172 -}
   3.173 -#endif
   3.174 -
   3.175  irqreturn_t netif_be_int(int irq, void *dev_id, struct pt_regs *regs)
   3.176  {
   3.177      netif_t *netif = dev_id;
     4.1 --- a/linux-2.6.10-xen-sparse/drivers/xen/netfront/netfront.c	Fri Dec 31 19:23:11 2004 +0000
     4.2 +++ b/linux-2.6.10-xen-sparse/drivers/xen/netfront/netfront.c	Sun Jan 02 17:38:14 2005 +0000
     4.3 @@ -277,7 +277,7 @@ static int vif_wake(struct net_device *d
     4.4  
     4.5  static int network_open(struct net_device *dev)
     4.6  {
     4.7 -    struct net_private *np = dev->priv;
     4.8 +    struct net_private *np = netdev_priv(dev);
     4.9  
    4.10      memset(&np->stats, 0, sizeof(np->stats));
    4.11  
    4.12 @@ -295,7 +295,7 @@ static void network_tx_buf_gc(struct net
    4.13  {
    4.14      NETIF_RING_IDX i, prod;
    4.15      unsigned short id;
    4.16 -    struct net_private *np = dev->priv;
    4.17 +    struct net_private *np = netdev_priv(dev);
    4.18      struct sk_buff *skb;
    4.19  
    4.20      if ( np->backend_state != BEST_CONNECTED )
    4.21 @@ -342,7 +342,7 @@ static void network_tx_buf_gc(struct net
    4.22  static void network_alloc_rx_buffers(struct net_device *dev)
    4.23  {
    4.24      unsigned short id;
    4.25 -    struct net_private *np = dev->priv;
    4.26 +    struct net_private *np = netdev_priv(dev);
    4.27      struct sk_buff *skb;
    4.28      int i, batch_target;
    4.29      NETIF_RING_IDX req_prod = np->rx->req_prod;
    4.30 @@ -433,7 +433,7 @@ static void network_alloc_rx_buffers(str
    4.31  static int network_start_xmit(struct sk_buff *skb, struct net_device *dev)
    4.32  {
    4.33      unsigned short id;
    4.34 -    struct net_private *np = (struct net_private *)dev->priv;
    4.35 +    struct net_private *np = netdev_priv(dev);
    4.36      netif_tx_request_t *tx;
    4.37      NETIF_RING_IDX i;
    4.38  
    4.39 @@ -509,7 +509,7 @@ static int network_start_xmit(struct sk_
    4.40  static irqreturn_t netif_int(int irq, void *dev_id, struct pt_regs *ptregs)
    4.41  {
    4.42      struct net_device *dev = dev_id;
    4.43 -    struct net_private *np = dev->priv;
    4.44 +    struct net_private *np = netdev_priv(dev);
    4.45      unsigned long flags;
    4.46  
    4.47      spin_lock_irqsave(&np->tx_lock, flags);
    4.48 @@ -526,7 +526,7 @@ static irqreturn_t netif_int(int irq, vo
    4.49  
    4.50  static int netif_poll(struct net_device *dev, int *pbudget)
    4.51  {
    4.52 -    struct net_private *np = dev->priv;
    4.53 +    struct net_private *np = netdev_priv(dev);
    4.54      struct sk_buff *skb, *nskb;
    4.55      netif_rx_response_t *rx;
    4.56      NETIF_RING_IDX i, rp;
    4.57 @@ -704,7 +704,7 @@ static int netif_poll(struct net_device 
    4.58  
    4.59  static int network_close(struct net_device *dev)
    4.60  {
    4.61 -    struct net_private *np = dev->priv;
    4.62 +    struct net_private *np = netdev_priv(dev);
    4.63      np->user_state = UST_CLOSED;
    4.64      netif_stop_queue(np->dev);
    4.65      return 0;
    4.66 @@ -713,7 +713,7 @@ static int network_close(struct net_devi
    4.67  
    4.68  static struct net_device_stats *network_get_stats(struct net_device *dev)
    4.69  {
    4.70 -    struct net_private *np = (struct net_private *)dev->priv;
    4.71 +    struct net_private *np = netdev_priv(dev);
    4.72      return &np->stats;
    4.73  }
    4.74  
    4.75 @@ -725,7 +725,7 @@ static void network_connect(struct net_d
    4.76      int i, requeue_idx;
    4.77      netif_tx_request_t *tx;
    4.78  
    4.79 -    np = dev->priv;
    4.80 +    np = netdev_priv(dev);
    4.81      spin_lock_irq(&np->tx_lock);
    4.82      spin_lock(&np->rx_lock);
    4.83  
    4.84 @@ -889,7 +889,8 @@ static void vif_close(struct net_private
    4.85   * Allocates tx/rx pages.
    4.86   * Sends connect message to xend.
    4.87   */
    4.88 -static void vif_disconnect(struct net_private *np){
    4.89 +static void vif_disconnect(struct net_private *np)
    4.90 +{
    4.91      DPRINTK(">\n");
    4.92      if(np->tx) free_page((unsigned long)np->tx);
    4.93      if(np->rx) free_page((unsigned long)np->rx);
    4.94 @@ -967,7 +968,7 @@ static int create_netdev(int handle, str
    4.95          goto exit;
    4.96      }
    4.97  
    4.98 -    np                = dev->priv;
    4.99 +    np                = netdev_priv(dev);
   4.100      np->backend_state = BEST_CLOSED;
   4.101      np->user_state    = UST_CLOSED;
   4.102      np->handle        = handle;
   4.103 @@ -1046,7 +1047,7 @@ target_vif(
   4.104  
   4.105    exit:
   4.106      if ( np != NULL )
   4.107 -        *np = ((dev && !err) ? dev->priv : NULL);
   4.108 +        *np = ((dev && !err) ? netdev_priv(dev) : NULL);
   4.109      DPRINTK("< err=%d\n", err);
   4.110      return err;
   4.111  }
     5.1 --- a/tools/examples/vif-bridge	Fri Dec 31 19:23:11 2004 +0000
     5.2 +++ b/tools/examples/vif-bridge	Sun Jan 02 17:38:14 2005 +0000
     5.3 @@ -76,6 +76,7 @@ fi
     5.4  
     5.5  # Add/remove vif to/from bridge.
     5.6  brctl ${brcmd} ${bridge} ${vif}
     5.7 +ifconfig ${vif} $OP
     5.8  
     5.9  if [ ${ip} ] ; then
    5.10