ia64/xen-unstable

changeset 178:9c0353a9fa74

bitkeeper revision 1.44 (3e4e65159dO6gZq2mxyfYFsgJFKbtw)

dev.c, vif.h, network.c:
Fixed network transmit. Update consumer index *after* packet is transmitted :-)
author kaf24@labyrinth.cl.cam.ac.uk
date Sat Feb 15 16:04:37 2003 +0000 (2003-02-15)
parents bc7bbe93a3f2
children 2bfb4f917fea
files xen-2.4.16/common/network.c xen-2.4.16/include/xeno/vif.h xen-2.4.16/net/dev.c
line diff
     1.1 --- a/xen-2.4.16/common/network.c	Sat Feb 15 15:50:48 2003 +0000
     1.2 +++ b/xen-2.4.16/common/network.c	Sat Feb 15 16:04:37 2003 +0000
     1.3 @@ -65,22 +65,18 @@ net_vif_t *create_net_vif(int domain)
     1.4      new_ring = dom_task->net_ring_base + dom_task->num_net_vifs;
     1.5      memset(new_ring, 0, sizeof(net_ring_t));
     1.6  
     1.7 -    // allocate the shadow ring.  
     1.8 -    // maybe these should be kmem_cache instead of kmalloc?
     1.9 -    
    1.10      shadow_ring = kmalloc(sizeof(net_shadow_ring_t), GFP_KERNEL);
    1.11      if (shadow_ring == NULL) goto fail;
    1.12      
    1.13 -    shadow_ring->tx_ring = kmalloc(TX_RING_SIZE 
    1.14 -                    * sizeof(tx_shadow_entry_t), GFP_KERNEL);
    1.15      shadow_ring->rx_ring = kmalloc(RX_RING_SIZE
    1.16                      * sizeof(rx_shadow_entry_t), GFP_KERNEL);
    1.17 -    if ((shadow_ring->tx_ring == NULL) || (shadow_ring->rx_ring == NULL))
    1.18 +    if ( shadow_ring->rx_ring == NULL )
    1.19              goto fail;
    1.20  
    1.21      shadow_ring->rx_prod = shadow_ring->rx_cons = shadow_ring->rx_idx = 0;
    1.22 +    shadow_ring->tx_cons = 0;
    1.23      
    1.24 -    // fill in the new vif struct.
    1.25 +    /* Fill in the new vif struct. */
    1.26      
    1.27      new_vif->net_ring = new_ring;
    1.28      new_vif->shadow_ring = shadow_ring;
    1.29 @@ -127,7 +123,6 @@ void destroy_net_vif(struct task_struct 
    1.30      sys_vif_list[p->net_vif_list[i]->id] = NULL; // system vif list not gc'ed
    1.31      write_unlock(&sys_vif_lock);        
    1.32     
    1.33 -    kfree(p->net_vif_list[i]->shadow_ring->tx_ring);
    1.34      kfree(p->net_vif_list[i]->shadow_ring->rx_ring);
    1.35      kfree(p->net_vif_list[i]->shadow_ring);
    1.36      kmem_cache_free(net_vif_cache, p->net_vif_list[i]);
    1.37 @@ -297,21 +292,23 @@ int net_find_rule(u8 nproto, u8 tproto, 
    1.38      
    1.39      while (ent)
    1.40      {
    1.41 -        if (    (    (ent->r.src_interface == src_vif) 
    1.42 -                  || (ent->r.src_interface == VIF_ANY_INTERFACE) )
    1.43 -
    1.44 -             && (!((ent->r.src_addr ^ src_addr) & ent->r.src_addr_mask ))
    1.45 -             && (!((ent->r.dst_addr ^ dst_addr) & ent->r.dst_addr_mask ))
    1.46 -             && (!((ent->r.src_port ^ src_port) & ent->r.src_port_mask ))
    1.47 -             && (!((ent->r.dst_port ^ dst_port) & ent->r.dst_port_mask ))
    1.48 +        if ( ((ent->r.src_interface == src_vif)
    1.49 +              || (ent->r.src_interface == VIF_ANY_INTERFACE)) &&
    1.50  
    1.51 -             && (
    1.52 -                     (ent->r.proto == NETWORK_PROTO_ANY)
    1.53 -                  || ((ent->r.proto == NETWORK_PROTO_IP)  && (nproto == (u8)ETH_P_IP))
    1.54 -                  || ((ent->r.proto == NETWORK_PROTO_ARP) && (nproto == (u8)ETH_P_ARP))
    1.55 -                  || ((ent->r.proto == NETWORK_PROTO_TCP) && (tproto == IPPROTO_TCP))
    1.56 -                  || ((ent->r.proto == NETWORK_PROTO_UDP) && (tproto == IPPROTO_UDP))
    1.57 -                )
    1.58 +             (!((ent->r.src_addr ^ src_addr) & ent->r.src_addr_mask )) &&
    1.59 +             (!((ent->r.dst_addr ^ dst_addr) & ent->r.dst_addr_mask )) &&
    1.60 +             (!((ent->r.src_port ^ src_port) & ent->r.src_port_mask )) &&
    1.61 +             (!((ent->r.dst_port ^ dst_port) & ent->r.dst_port_mask )) &&
    1.62 +             
    1.63 +             ((ent->r.proto == NETWORK_PROTO_ANY) ||
    1.64 +              ((ent->r.proto == NETWORK_PROTO_IP)  &&
    1.65 +               (nproto == (u8)ETH_P_IP)) ||
    1.66 +              ((ent->r.proto == NETWORK_PROTO_ARP) &&
    1.67 +               (nproto == (u8)ETH_P_ARP)) ||
    1.68 +              ((ent->r.proto == NETWORK_PROTO_TCP) &&
    1.69 +               (tproto == IPPROTO_TCP)) ||
    1.70 +              ((ent->r.proto == NETWORK_PROTO_UDP) &&
    1.71 +               (tproto == IPPROTO_UDP)))
    1.72             )
    1.73          {
    1.74              break;
    1.75 @@ -358,40 +355,34 @@ int __net_get_target_vif(u8 *data, unsig
    1.76      case ETH_P_ARP:
    1.77          if ( len < 28 ) goto drop;
    1.78          target = net_find_rule((u8)ETH_P_ARP, 0, ntohl(*(u32 *)(nh_raw + 14)),
    1.79 -                        ntohl(*(u32 *)(nh_raw + 24)), 0, 0, 
    1.80 -                        src_vif);
    1.81 +                               ntohl(*(u32 *)(nh_raw + 24)), 0, 0, 
    1.82 +                               src_vif);
    1.83          break;
    1.84  
    1.85      case ETH_P_IP:
    1.86          if ( len < 20 ) goto drop;
    1.87          h_raw =  data + ((*(unsigned char *)(nh_raw)) & 0x0f) * 4;
    1.88 -        switch ( *(unsigned char *)(nh_raw + 9) )
    1.89 -        {
    1.90 -        case IPPROTO_UDP:
    1.91 -        case IPPROTO_TCP:
    1.92 -            target = net_find_rule((u8)ETH_P_IP,  *(u8 *)(nh_raw + 9),
    1.93 -                    ntohl(*(u32 *)(nh_raw + 12)),
    1.94 -                    ntohl(*(u32 *)(nh_raw + 16)),
    1.95 -                    ntohs(*(u16 *)(h_raw)),
    1.96 -                    ntohs(*(u16 *)(h_raw + 2)), 
    1.97 -                    src_vif);
    1.98 -            break;
    1.99 -
   1.100 -        default: // ip-based protocol where we don't have ports.
   1.101 -            target = net_find_rule((u8)ETH_P_IP,  *(u8 *)(data + 9),
   1.102 -                    ntohl(*(u32 *)(nh_raw + 12)),
   1.103 -                    ntohl(*(u32 *)(nh_raw + 16)),
   1.104 -                    0,
   1.105 -                    0, 
   1.106 -                    src_vif);
   1.107 -        }
   1.108 -        break;
   1.109 -
   1.110 +        
   1.111 +        /* XXX For now, we ignore ports. */
   1.112 +#if 0
   1.113 +        target = net_find_rule((u8)ETH_P_IP,  *(u8 *)(nh_raw + 9),
   1.114 +                               ntohl(*(u32 *)(nh_raw + 12)),
   1.115 +                               ntohl(*(u32 *)(nh_raw + 16)),
   1.116 +                               ntohs(*(u16 *)(h_raw)),
   1.117 +                               ntohs(*(u16 *)(h_raw + 2)), 
   1.118 +                               src_vif);
   1.119 +#else
   1.120 +        target = net_find_rule((u8)ETH_P_IP,  *(u8 *)(data + 9),
   1.121 +                               ntohl(*(u32 *)(nh_raw + 12)),
   1.122 +                               ntohl(*(u32 *)(nh_raw + 16)),
   1.123 +                               0,
   1.124 +                               0, 
   1.125 +                               src_vif);
   1.126 +#endif
   1.127      }
   1.128      return target;
   1.129      
   1.130 -    drop:
   1.131 -//printk("Drop case!\n");
   1.132 + drop:
   1.133      return VIF_DROP;
   1.134  }
   1.135  
     2.1 --- a/xen-2.4.16/include/xeno/vif.h	Sat Feb 15 15:50:48 2003 +0000
     2.2 +++ b/xen-2.4.16/include/xeno/vif.h	Sat Feb 15 16:04:37 2003 +0000
     2.3 @@ -25,13 +25,6 @@
     2.4   * TX_RING_SIZE and RX_RING_SIZE are defined in the shared network.h.
     2.5   */
     2.6  
     2.7 -typedef struct tx_shadow_entry_st {
     2.8 -    unsigned long addr;
     2.9 -    unsigned long size;
    2.10 -    int           status;
    2.11 -    unsigned long flush_count;
    2.12 -} tx_shadow_entry_t;
    2.13 -
    2.14  typedef struct rx_shadow_entry_st {
    2.15      unsigned long addr;
    2.16      unsigned long size;
    2.17 @@ -40,9 +33,9 @@ typedef struct rx_shadow_entry_st {
    2.18  } rx_shadow_entry_t;
    2.19  
    2.20  typedef struct net_shadow_ring_st {
    2.21 -    tx_shadow_entry_t *tx_ring;
    2.22      rx_shadow_entry_t *rx_ring;
    2.23      unsigned int rx_prod, rx_cons, rx_idx;
    2.24 +    unsigned int tx_cons; /* ahead of shared tx_cons */
    2.25  } net_shadow_ring_t;
    2.26  
    2.27  typedef struct net_vif_st {
     3.1 --- a/xen-2.4.16/net/dev.c	Sat Feb 15 15:50:48 2003 +0000
     3.2 +++ b/xen-2.4.16/net/dev.c	Sat Feb 15 16:04:37 2003 +0000
     3.3 @@ -2003,6 +2003,7 @@ inline int init_tx_header(u8 *data, unsi
     3.4          return 0;
     3.5  }
     3.6  
     3.7 +
     3.8  /* 
     3.9   * tx_skb_release
    3.10   *
    3.11 @@ -2017,11 +2018,21 @@ void tx_skb_release(struct sk_buff *skb)
    3.12  {
    3.13      int i;
    3.14      
    3.15 -    for (i= 0; i < skb_shinfo(skb)->nr_frags; i++)
    3.16 +    for ( i = 0; i < skb_shinfo(skb)->nr_frags; i++ )
    3.17          skb_shinfo(skb)->frags[i].page->tot_count--;
    3.18      
    3.19      skb_shinfo(skb)->nr_frags = 0; 
    3.20 +
    3.21 +    /*
    3.22 +     * XXX This assumes that, per vif, SKBs are processed in-order!
    3.23 +     * Also, like lots of code in here -- we assume direct access to the
    3.24 +     * consumer and producer indexes. This is likely safe for the
    3.25 +     * forseeable future.
    3.26 +     */
    3.27 +    sys_vif_list[skb->src_vif]->net_ring->tx_cons = 
    3.28 +        TX_RING_INC(sys_vif_list[skb->src_vif]->net_ring->tx_cons);
    3.29  }
    3.30 +
    3.31      
    3.32  /*
    3.33   * do_net_update:
    3.34 @@ -2045,8 +2056,7 @@ long do_net_update(void)
    3.35      rx_shadow_entry_t *rx;
    3.36      unsigned long pfn;
    3.37      struct pfn_info *page;
    3.38 -    unsigned long *g_pte;
    3.39 -    
    3.40 +    unsigned long *g_pte;    
    3.41      
    3.42      for ( j = 0; j < current->num_net_vifs; j++)
    3.43      {
    3.44 @@ -2056,12 +2066,13 @@ long do_net_update(void)
    3.45  
    3.46          current_vif = current->net_vif_list[j];
    3.47          net_ring = current_vif->net_ring;
    3.48 +        shadow_ring = current_vif->shadow_ring;
    3.49          
    3.50          /*
    3.51           * PHASE 1 -- TRANSMIT RING
    3.52           */
    3.53  
    3.54 -        for ( i = net_ring->tx_cons; 
    3.55 +        for ( i = shadow_ring->tx_cons; 
    3.56                i != net_ring->tx_prod; 
    3.57                i = TX_RING_INC(i) )
    3.58          {
    3.59 @@ -2176,14 +2187,12 @@ long do_net_update(void)
    3.60                  unmap_domain_mem(g_data);
    3.61              }
    3.62          }
    3.63 -        net_ring->tx_cons = i;
    3.64 +        shadow_ring->tx_cons = i;
    3.65  
    3.66          /*
    3.67           * PHASE 2 -- RECEIVE RING
    3.68           */
    3.69  
    3.70 -        shadow_ring = current_vif->shadow_ring;
    3.71 -
    3.72          for ( i = shadow_ring->rx_prod; 
    3.73                i != net_ring->rx_prod; 
    3.74                i = RX_RING_INC(i) )