ia64/xen-unstable

changeset 1372:5a6113c65ead

bitkeeper revision 1.891.1.12 (40a248b0WTGoOa9206iWkyGN0mTPNw)

Allow forcing of IRQ trigger-type to edge or level
(NB. DANGEROUS!).
author kaf24@scramble.cl.cam.ac.uk
date Wed May 12 15:54:24 2004 +0000 (2004-05-12)
parents c8859d41ea6c
children b38d20334c58
files .rootkeys xen/arch/i386/io_apic.c xen/arch/i386/irq.c xen/common/kernel.c xen/common/physdev.c xen/include/hypervisor-ifs/physdev.h xenolinux-2.4.26-sparse/arch/xen/drivers/netif/backend/main.c xenolinux-2.4.26-sparse/arch/xen/kernel/evtchn.c xenolinux-2.4.26-sparse/include/linux/skbuff.h
line diff
     1.1 --- a/.rootkeys	Wed May 12 15:53:05 2004 +0000
     1.2 +++ b/.rootkeys	Wed May 12 15:54:24 2004 +0000
     1.3 @@ -753,6 +753,7 @@ 40659defgWA92arexpMGn8X3QMDj3w xenolinux
     1.4  3f056927gMHl7mWB89rb73JahbhQIA xenolinux-2.4.26-sparse/include/linux/blk.h
     1.5  3e5a4e68WLX3B8owTvktP3HHOtznPQ xenolinux-2.4.26-sparse/include/linux/major.h
     1.6  401c0590D_kwJDU59X8NyvqSv_Cl2A xenolinux-2.4.26-sparse/include/linux/sched.h
     1.7 +40a248afgI0_JKthdYAe8beVfXSTpQ xenolinux-2.4.26-sparse/include/linux/skbuff.h
     1.8  3e5a4e686V0nioX2ZpFf056sgvdiQw xenolinux-2.4.26-sparse/include/linux/sunrpc/debug.h
     1.9  401c0592pLrp_aCbQRo9GXiYQQaVVA xenolinux-2.4.26-sparse/include/linux/timer.h
    1.10  3e5a4e68W_hpMlM3u_-QOKMp3gzcwQ xenolinux-2.4.26-sparse/init/do_mounts.c
     2.1 --- a/xen/arch/i386/io_apic.c	Wed May 12 15:53:05 2004 +0000
     2.2 +++ b/xen/arch/i386/io_apic.c	Wed May 12 15:54:24 2004 +0000
     2.3 @@ -208,7 +208,11 @@ static void set_ioapic_affinity (unsigne
     2.4  	spin_unlock_irqrestore(&ioapic_lock, flags);
     2.5  }
     2.6  
     2.7 -#if CONFIG_SMP
     2.8 +/*
     2.9 + * In new I/O model, the interrupt is pinned to the CPU of the first
    2.10 + * device-driver domain that attaches. Dynamic balancing is pointless.
    2.11 + */
    2.12 +#if defined(CONFIG_SMP) && !defined(NO_DEVICES_IN_XEN)
    2.13  
    2.14  typedef struct {
    2.15  	unsigned int cpu;
    2.16 @@ -220,8 +224,6 @@ static irq_balance_t irq_balance[NR_IRQS
    2.17  
    2.18  extern unsigned long irq_affinity [NR_IRQS];
    2.19  
    2.20 -#endif
    2.21 -
    2.22  #define IDLE_ENOUGH(cpu,now) \
    2.23  		(idle_cpu(cpu) && ((now) - irq_stat[(cpu)].idle_timestamp > 1))
    2.24  
    2.25 @@ -256,7 +258,6 @@ inside:
    2.26  
    2.27  static inline void balance_irq(int irq)
    2.28  {
    2.29 -#if CONFIG_SMP
    2.30  	irq_balance_t *entry = irq_balance + irq;
    2.31  	unsigned long now = jiffies;
    2.32  
    2.33 @@ -272,8 +273,13 @@ static inline void balance_irq(int irq)
    2.34  		entry->cpu = move(entry->cpu, allowed_mask, now, random_number);
    2.35  		set_ioapic_affinity(irq, apicid_to_phys_cpu_present(entry->cpu));
    2.36  	}
    2.37 +}
    2.38 +
    2.39 +#else
    2.40 +
    2.41 +#define balance_irq(_irq) ((void)0)
    2.42 +
    2.43  #endif
    2.44 -}
    2.45  
    2.46  /*
    2.47   * support for broken MP BIOSs, enables hand-redirection of PIRQ0-7 to
    2.48 @@ -883,6 +889,7 @@ void __init UNEXPECTED_IO_APIC(void)
    2.49  
    2.50  void __init print_IO_APIC(void)
    2.51  {
    2.52 +#ifndef NDEBUG
    2.53  	int apic, i;
    2.54  	struct IO_APIC_reg_00 reg_00;
    2.55  	struct IO_APIC_reg_01 reg_01;
    2.56 @@ -1019,9 +1026,11 @@ void __init print_IO_APIC(void)
    2.57  	}
    2.58  
    2.59  	printk(KERN_INFO ".................................... done.\n");
    2.60 +#endif
    2.61 +}
    2.62  
    2.63 -	return;
    2.64 -}
    2.65 +
    2.66 +#if 0 /* Maybe useful for debugging, but not currently used anywhere. */
    2.67  
    2.68  static void print_APIC_bitfield (int base)
    2.69  {
    2.70 @@ -1041,6 +1050,7 @@ static void print_APIC_bitfield (int bas
    2.71  	}
    2.72  }
    2.73  
    2.74 +
    2.75  void /*__init*/ print_local_APIC(void * dummy)
    2.76  {
    2.77  	unsigned int v, ver, maxlvt;
    2.78 @@ -1156,6 +1166,9 @@ void /*__init*/ print_PIC(void)
    2.79  	printk(KERN_DEBUG "... PIC ELCR: %04x\n", v);
    2.80  }
    2.81  
    2.82 +#endif /* 0 */
    2.83 +
    2.84 +
    2.85  static void __init enable_IO_APIC(void)
    2.86  {
    2.87  	struct IO_APIC_reg_01 reg_01;
    2.88 @@ -1874,7 +1887,7 @@ int io_apic_set_pci_routing (int ioapic,
    2.89  		mp_ioapics[ioapic].mpc_apicid, pin, entry.vector, irq, edge_level, active_high_low);
    2.90  
    2.91  	if (edge_level) {
    2.92 -	irq_desc[irq].handler = &ioapic_level_irq_type;
    2.93 +		irq_desc[irq].handler = &ioapic_level_irq_type;
    2.94  	} else {
    2.95  		irq_desc[irq].handler = &ioapic_edge_irq_type;
    2.96  	}
    2.97 @@ -1893,3 +1906,110 @@ int io_apic_set_pci_routing (int ioapic,
    2.98  }
    2.99  
   2.100  #endif /*CONFIG_ACPI_BOOT*/
   2.101 +
   2.102 +extern char opt_leveltrigger[], opt_edgetrigger[];
   2.103 +
   2.104 +static int __init ioapic_trigger_setup(void)
   2.105 +{
   2.106 +    char       *p;
   2.107 +    irq_desc_t *desc;
   2.108 +    long        irq;
   2.109 +
   2.110 +    p = opt_leveltrigger;
   2.111 +    while ( *p != '\0' )
   2.112 +    {
   2.113 +        irq = simple_strtol(p, &p, 10);
   2.114 +        if ( (irq <= 0) || (irq >= NR_IRQS) )
   2.115 +        {
   2.116 +            printk("IRQ '%ld' out of range in level-trigger list '%s'\n",
   2.117 +                   irq, opt_leveltrigger);
   2.118 +            break;
   2.119 +        }
   2.120 +
   2.121 +        printk("Forcing IRQ %ld to level-trigger: ", irq);
   2.122 +
   2.123 +        desc = &irq_desc[irq];
   2.124 +        spin_lock_irq(&desc->lock);
   2.125 +
   2.126 +        if ( desc->handler == &ioapic_level_irq_type )
   2.127 +        {
   2.128 +            printk("already level-triggered (no force applied).\n");
   2.129 +        }
   2.130 +        else if ( desc->handler != &ioapic_edge_irq_type )
   2.131 +        {
   2.132 +            printk("cannot force (can only force IO-APIC-edge IRQs).\n");
   2.133 +        }
   2.134 +        else
   2.135 +        {
   2.136 +            desc->handler = &ioapic_level_irq_type;
   2.137 +            __mask_IO_APIC_irq(irq);
   2.138 +            __level_IO_APIC_irq(irq);        
   2.139 +            printk("done.\n");
   2.140 +        }
   2.141 +
   2.142 +        spin_unlock_irq(&desc->lock);
   2.143 +
   2.144 +        if ( *p == '\0' )
   2.145 +            break;
   2.146 +
   2.147 +        if ( *p != ',' )
   2.148 +        {
   2.149 +            printk("Unexpected character '%c' in level-trigger list '%s'\n",
   2.150 +                   *p, opt_leveltrigger);
   2.151 +            break;
   2.152 +        }
   2.153 +
   2.154 +        p++;
   2.155 +    }
   2.156 +
   2.157 +    p = opt_edgetrigger;
   2.158 +    while ( *p != '\0' )
   2.159 +    {
   2.160 +        irq = simple_strtol(p, &p, 10);
   2.161 +        if ( (irq <= 0) || (irq >= NR_IRQS) )
   2.162 +        {
   2.163 +            printk("IRQ '%ld' out of range in edge-trigger list '%s'\n",
   2.164 +                   irq, opt_edgetrigger);
   2.165 +            break;
   2.166 +        }
   2.167 +
   2.168 +        printk("Forcing IRQ %ld to edge-trigger: ", irq);
   2.169 +
   2.170 +        desc = &irq_desc[irq];
   2.171 +        spin_lock_irq(&desc->lock);
   2.172 +
   2.173 +        if ( desc->handler == &ioapic_edge_irq_type )
   2.174 +        {
   2.175 +            printk("already edge-triggered (no force applied).\n");
   2.176 +        }
   2.177 +        else if ( desc->handler != &ioapic_level_irq_type )
   2.178 +        {
   2.179 +            printk("cannot force (can only force IO-APIC-level IRQs).\n");
   2.180 +        }
   2.181 +        else
   2.182 +        {
   2.183 +            desc->handler = &ioapic_edge_irq_type;
   2.184 +            __edge_IO_APIC_irq(irq);        
   2.185 +            desc->status |= IRQ_PENDING; /* may have lost a masked edge */
   2.186 +            printk("done.\n");
   2.187 +        }
   2.188 +
   2.189 +        spin_unlock_irq(&desc->lock);
   2.190 +
   2.191 +        if ( *p == '\0' )
   2.192 +            break;
   2.193 +
   2.194 +        if ( *p != ',' )
   2.195 +        {
   2.196 +            printk("Unexpected character '%c' in edge-trigger list '%s'\n",
   2.197 +                   *p, opt_edgetrigger);
   2.198 +            break;
   2.199 +        }
   2.200 +
   2.201 +        p++;
   2.202 +    }
   2.203 +
   2.204 +    return 0;
   2.205 +}
   2.206 +
   2.207 +__initcall(ioapic_trigger_setup);
     3.1 --- a/xen/arch/i386/irq.c	Wed May 12 15:53:05 2004 +0000
     3.2 +++ b/xen/arch/i386/irq.c	Wed May 12 15:54:24 2004 +0000
     3.3 @@ -39,6 +39,7 @@
     3.4  #include <xen/delay.h>
     3.5  #include <xen/timex.h>
     3.6  #include <xen/perfc.h>
     3.7 +#include <asm/smpboot.h>
     3.8  
     3.9  /*
    3.10   * Linux has a controller-independent x86 interrupt architecture.
    3.11 @@ -1034,6 +1035,11 @@ int pirq_guest_bind(struct task_struct *
    3.12          desc->status |= IRQ_GUEST;
    3.13          desc->status &= ~(IRQ_DISABLED | IRQ_AUTODETECT | IRQ_WAITING);
    3.14          desc->handler->startup(irq);
    3.15 +
    3.16 +        /* Attempt to bind the interrupt target to the correct CPU. */
    3.17 +        if ( desc->handler->set_affinity != NULL )
    3.18 +            desc->handler->set_affinity(
    3.19 +                irq, apicid_to_phys_cpu_present(p->processor));
    3.20      }
    3.21      else if ( !will_share || !action->shareable )
    3.22      {
     4.1 --- a/xen/common/kernel.c	Wed May 12 15:53:05 2004 +0000
     4.2 +++ b/xen/common/kernel.c	Wed May 12 15:54:24 2004 +0000
     4.3 @@ -74,31 +74,37 @@ unsigned char opt_pdb[10] = "none";
     4.4  unsigned int opt_tbuf_size = 1;
     4.5  /* opt_sched: scheduler - default to Borrowed Virtual Time */
     4.6  char opt_sched[10] = "bvt";
     4.7 -/* opt_physdev_dom0_hide: list of PCI slots to hide from dom0
     4.8 - * Should have the format '(%02x:%02x.%1x)(%02x:%02x.%1x)...etc' */
     4.9 -char opt_physdev_dom0_hide[20] = "";
    4.10 +/* opt_physdev_dom0_hide: list of PCI slots to hide from domain 0. */
    4.11 +/* Format is '(%02x:%02x.%1x)(%02x:%02x.%1x)' and so on. */
    4.12 +char opt_physdev_dom0_hide[200] = "";
    4.13 +/* opt_leveltrigger, opt_edgetrigger: Force an IO-APIC-routed IRQ to be */
    4.14 +/*                                    level- or edge-triggered.         */
    4.15 +/* Example: 'leveltrigger=4,5,6,20 edgetrigger=21'. */
    4.16 +char opt_leveltrigger[30] = "", opt_edgetrigger[30] = "";
    4.17  
    4.18  static struct {
    4.19      unsigned char *name;
    4.20      enum { OPT_IP, OPT_STR, OPT_UINT, OPT_BOOL } type;
    4.21      void *var;
    4.22  } opts[] = {
    4.23 -    { "console",          OPT_STR,  &opt_console },
    4.24 -    { "ser_baud",         OPT_UINT, &opt_ser_baud },
    4.25 -    { "com1",             OPT_STR,  &opt_com1 },
    4.26 -    { "com2",             OPT_STR,  &opt_com2 },
    4.27 -    { "dom0_mem",         OPT_UINT, &opt_dom0_mem }, 
    4.28 -    { "ifname",           OPT_STR,  &opt_ifname },
    4.29 -    { "noht",             OPT_BOOL, &opt_noht },
    4.30 -    { "noacpi",           OPT_BOOL, &opt_noacpi },
    4.31 -    { "nosmp",            OPT_BOOL, &opt_nosmp },
    4.32 -    { "noreboot",         OPT_BOOL, &opt_noreboot },
    4.33 -    { "ignorebiostables", OPT_BOOL, &opt_ignorebiostables },
    4.34 -    { "watchdog",         OPT_BOOL, &opt_watchdog },
    4.35 -    { "pdb",              OPT_STR,  &opt_pdb },
    4.36 -    { "tbuf_size",        OPT_UINT, &opt_tbuf_size },
    4.37 -    { "sched",            OPT_STR,  &opt_sched },
    4.38 -    { "physdev_dom0_hide",OPT_STR,  &opt_physdev_dom0_hide },
    4.39 +    { "console",           OPT_STR,  &opt_console },
    4.40 +    { "ser_baud",          OPT_UINT, &opt_ser_baud },
    4.41 +    { "com1",              OPT_STR,  &opt_com1 },
    4.42 +    { "com2",              OPT_STR,  &opt_com2 },
    4.43 +    { "dom0_mem",          OPT_UINT, &opt_dom0_mem }, 
    4.44 +    { "ifname",            OPT_STR,  &opt_ifname },
    4.45 +    { "noht",              OPT_BOOL, &opt_noht },
    4.46 +    { "noacpi",            OPT_BOOL, &opt_noacpi },
    4.47 +    { "nosmp",             OPT_BOOL, &opt_nosmp },
    4.48 +    { "noreboot",          OPT_BOOL, &opt_noreboot },
    4.49 +    { "ignorebiostables",  OPT_BOOL, &opt_ignorebiostables },
    4.50 +    { "watchdog",          OPT_BOOL, &opt_watchdog },
    4.51 +    { "pdb",               OPT_STR,  &opt_pdb },
    4.52 +    { "tbuf_size",         OPT_UINT, &opt_tbuf_size },
    4.53 +    { "sched",             OPT_STR,  &opt_sched },
    4.54 +    { "physdev_dom0_hide", OPT_STR,  &opt_physdev_dom0_hide },
    4.55 +    { "leveltrigger",      OPT_STR,  &opt_leveltrigger },
    4.56 +    { "edgetrigger",       OPT_STR,  &opt_edgetrigger },
    4.57      { NULL,               0,        NULL     }
    4.58  };
    4.59  
     5.1 --- a/xen/common/physdev.c	Wed May 12 15:53:05 2004 +0000
     5.2 +++ b/xen/common/physdev.c	Wed May 12 15:54:24 2004 +0000
     5.3 @@ -634,9 +634,10 @@ static long pci_probe_root_buses(u32 *bu
     5.4   */
     5.5  long do_physdev_op(physdev_op_t *uop)
     5.6  {
     5.7 -    phys_dev_t *pdev;
     5.8 +    phys_dev_t  *pdev;
     5.9      physdev_op_t op;
    5.10 -    long ret;
    5.11 +    long         ret;
    5.12 +    int          irq;
    5.13  
    5.14      if ( unlikely(copy_from_user(&op, uop, sizeof(op)) != 0) )
    5.15          return -EFAULT;
    5.16 @@ -674,10 +675,22 @@ long do_physdev_op(physdev_op_t *uop)
    5.17          ret = pci_probe_root_buses(op.u.pci_probe_root_buses.busmask);
    5.18          break;
    5.19  
    5.20 -    case PHYSDEVOP_UNMASK_IRQ:
    5.21 +    case PHYSDEVOP_IRQ_UNMASK_NOTIFY:
    5.22          ret = pirq_guest_unmask(current);
    5.23          break;
    5.24  
    5.25 +    case PHYSDEVOP_IRQ_STATUS_QUERY:
    5.26 +        irq = op.u.irq_status_query.irq;
    5.27 +        ret = -EINVAL;
    5.28 +        if ( (irq < 0) || (irq >= NR_IRQS) )
    5.29 +            break;
    5.30 +        op.u.irq_status_query.flags = 0;
    5.31 +        /* Edge-triggered interrupts don't need an explicit unmask downcall. */
    5.32 +        if ( strstr(irq_desc[irq].handler->typename, "edge") == NULL )
    5.33 +            op.u.irq_status_query.flags |= PHYSDEVOP_IRQ_NEEDS_UNMASK_NOTIFY;
    5.34 +        ret = 0;
    5.35 +        break;
    5.36 +
    5.37      default:
    5.38          ret = -EINVAL;
    5.39          break;
     6.1 --- a/xen/include/hypervisor-ifs/physdev.h	Wed May 12 15:53:05 2004 +0000
     6.2 +++ b/xen/include/hypervisor-ifs/physdev.h	Wed May 12 15:54:24 2004 +0000
     6.3 @@ -14,44 +14,55 @@
     6.4  #define PHYSDEVOP_PCI_CFGREG_WRITE      1
     6.5  #define PHYSDEVOP_PCI_INITIALISE_DEVICE 2
     6.6  #define PHYSDEVOP_PCI_PROBE_ROOT_BUSES  3
     6.7 -#define PHYSDEVOP_UNMASK_IRQ            4
     6.8 +#define PHYSDEVOP_IRQ_UNMASK_NOTIFY     4
     6.9 +#define PHYSDEVOP_IRQ_STATUS_QUERY      5
    6.10  
    6.11  /* Read from PCI configuration space. */
    6.12 -typedef struct physdevop_pci_cfgreg_read_st
    6.13 -{
    6.14 -    int bus;        /* IN */
    6.15 -    int dev;        /* IN */
    6.16 -    int func;       /* IN */
    6.17 -    int reg;        /* IN */
    6.18 -    int len;        /* IN */
    6.19 -    u32 value;      /* OUT */
    6.20 +typedef struct {
    6.21 +    /* IN */
    6.22 +    int bus;
    6.23 +    int dev;
    6.24 +    int func;
    6.25 +    int reg;
    6.26 +    int len;
    6.27 +    /* OUT */
    6.28 +    u32 value;
    6.29  } physdevop_pci_cfgreg_read_t;
    6.30  
    6.31  /* Write to PCI configuration space. */
    6.32 -typedef struct physdevop_pci_cfgreg_write_st
    6.33 -{
    6.34 -    int bus;        /* IN */
    6.35 -    int dev;        /* IN */
    6.36 -    int func;       /* IN */
    6.37 -    int reg;        /* IN */
    6.38 -    int len;        /* IN */
    6.39 -    u32 value;      /* IN */
    6.40 +typedef struct {
    6.41 +    /* IN */
    6.42 +    int bus;
    6.43 +    int dev;
    6.44 +    int func;
    6.45 +    int reg;
    6.46 +    int len;
    6.47 +    u32 value;
    6.48  } physdevop_pci_cfgreg_write_t;
    6.49  
    6.50  /* Do final initialisation of a PCI device (e.g., last-moment IRQ routing). */
    6.51 -typedef struct physdevop_pci_initialise_device_st
    6.52 -{
    6.53 -    int bus;      /* IN */
    6.54 -    int dev;      /* IN */
    6.55 -    int func;     /* IN */
    6.56 +typedef struct {
    6.57 +    /* IN */
    6.58 +    int bus;
    6.59 +    int dev;
    6.60 +    int func;
    6.61  } physdevop_pci_initialise_device_t;
    6.62  
    6.63  /* Find the root buses for subsequent scanning. */
    6.64 -typedef struct physdevop_pci_probe_root_buses_st
    6.65 -{
    6.66 -    u32 busmask[256/32]; /* OUT */
    6.67 +typedef struct {
    6.68 +    /* OUT */
    6.69 +    u32 busmask[256/32];
    6.70  } physdevop_pci_probe_root_buses_t;
    6.71  
    6.72 +typedef struct {
    6.73 +    /* IN */
    6.74 +    int irq;
    6.75 +    /* OUT */
    6.76 +/* Need to call PHYSDEVOP_IRQ_UNMASK_NOTIFY when the IRQ has been serviced? */
    6.77 +#define PHYSDEVOP_IRQ_NEEDS_UNMASK_NOTIFY (1<<0)
    6.78 +    unsigned long flags;
    6.79 +} physdevop_irq_status_query_t;
    6.80 +
    6.81  typedef struct _physdev_op_st 
    6.82  {
    6.83      unsigned long cmd;
    6.84 @@ -61,6 +72,7 @@ typedef struct _physdev_op_st
    6.85          physdevop_pci_cfgreg_write_t      pci_cfgreg_write;
    6.86          physdevop_pci_initialise_device_t pci_initialise_device;
    6.87          physdevop_pci_probe_root_buses_t  pci_probe_root_buses;
    6.88 +        physdevop_irq_status_query_t      irq_status_query;
    6.89      } u;
    6.90  } physdev_op_t;
    6.91  
     7.1 --- a/xenolinux-2.4.26-sparse/arch/xen/drivers/netif/backend/main.c	Wed May 12 15:53:05 2004 +0000
     7.2 +++ b/xenolinux-2.4.26-sparse/arch/xen/drivers/netif/backend/main.c	Wed May 12 15:54:24 2004 +0000
     7.3 @@ -116,12 +116,14 @@ int netif_be_start_xmit(struct sk_buff *
     7.4   
     7.5      /*
     7.6       * We do not copy the packet unless:
     7.7 -     *  1. It is fragmented; or
     7.8 +     *  1. The data is shared; or
     7.9       *  2. It spans a page boundary; or
    7.10       *  3. We cannot be sure the whole data page is allocated.
    7.11       * The copying method is taken from skb_copy().
    7.12 +     * NB. We also couldn't cope with fragmented packets, but we won't get
    7.13 +     *     any because we not advertise the NETIF_F_SG feature.
    7.14       */
    7.15 -    if ( (skb_shinfo(skb)->nr_frags != 0) ||
    7.16 +    if ( skb_shared(skb) || skb_cloned(skb) || 
    7.17           (((unsigned long)skb->end ^ (unsigned long)skb->head) & PAGE_MASK) ||
    7.18           ((skb->end - skb->head) < (PAGE_SIZE/2)) )
    7.19      {
     8.1 --- a/xenolinux-2.4.26-sparse/arch/xen/kernel/evtchn.c	Wed May 12 15:53:05 2004 +0000
     8.2 +++ b/xenolinux-2.4.26-sparse/arch/xen/kernel/evtchn.c	Wed May 12 15:54:24 2004 +0000
     8.3 @@ -36,6 +36,9 @@ static int virq_to_irq[NR_VIRQS];
     8.4  /* Reference counts for bindings to IRQs. */
     8.5  static int irq_bindcount[NR_IRQS];
     8.6  
     8.7 +/* Bitmap indicating which PIRQs require Xen to be notified on unmask. */
     8.8 +static unsigned long pirq_needs_unmask_notify[NR_PIRQS/sizeof(unsigned long)];
     8.9 +
    8.10  /* Upcall to generic IRQ layer. */
    8.11  extern asmlinkage unsigned int do_IRQ(int irq, struct pt_regs *regs);
    8.12  
    8.13 @@ -234,8 +237,22 @@ static struct hw_interrupt_type dynirq_t
    8.14  static inline void pirq_unmask_notify(int pirq)
    8.15  {
    8.16      physdev_op_t op;
    8.17 -    op.cmd = PHYSDEVOP_UNMASK_IRQ;
    8.18 +    if ( unlikely(test_bit(pirq, &pirq_needs_unmask_notify[0])) )
    8.19 +    {
    8.20 +        op.cmd = PHYSDEVOP_IRQ_UNMASK_NOTIFY;
    8.21 +        (void)HYPERVISOR_physdev_op(&op);
    8.22 +    }
    8.23 +}
    8.24 +
    8.25 +static inline void pirq_query_unmask(int pirq)
    8.26 +{
    8.27 +    physdev_op_t op;
    8.28 +    op.cmd = PHYSDEVOP_IRQ_STATUS_QUERY;
    8.29 +    op.u.irq_status_query.irq = pirq;
    8.30      (void)HYPERVISOR_physdev_op(&op);
    8.31 +    clear_bit(pirq, &pirq_needs_unmask_notify[0]);
    8.32 +    if ( op.u.irq_status_query.flags & PHYSDEVOP_IRQ_NEEDS_UNMASK_NOTIFY )
    8.33 +        set_bit(pirq, &pirq_needs_unmask_notify[0]);
    8.34  }
    8.35  
    8.36  /*
    8.37 @@ -261,6 +278,8 @@ static unsigned int startup_pirq(unsigne
    8.38      }
    8.39      evtchn = op.u.bind_pirq.port;
    8.40  
    8.41 +    pirq_query_unmask(irq_to_pirq(irq));
    8.42 +
    8.43      evtchn_to_irq[evtchn] = irq;
    8.44      irq_to_evtchn[irq]    = evtchn;
    8.45  
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/xenolinux-2.4.26-sparse/include/linux/skbuff.h	Wed May 12 15:54:24 2004 +0000
     9.3 @@ -0,0 +1,1174 @@
     9.4 +/*
     9.5 + *	Definitions for the 'struct sk_buff' memory handlers.
     9.6 + *
     9.7 + *	Authors:
     9.8 + *		Alan Cox, <gw4pts@gw4pts.ampr.org>
     9.9 + *		Florian La Roche, <rzsfl@rz.uni-sb.de>
    9.10 + *
    9.11 + *	This program is free software; you can redistribute it and/or
    9.12 + *	modify it under the terms of the GNU General Public License
    9.13 + *	as published by the Free Software Foundation; either version
    9.14 + *	2 of the License, or (at your option) any later version.
    9.15 + */
    9.16 + 
    9.17 +#ifndef _LINUX_SKBUFF_H
    9.18 +#define _LINUX_SKBUFF_H
    9.19 +
    9.20 +#include <linux/config.h>
    9.21 +#include <linux/kernel.h>
    9.22 +#include <linux/sched.h>
    9.23 +#include <linux/time.h>
    9.24 +#include <linux/cache.h>
    9.25 +
    9.26 +#include <asm/atomic.h>
    9.27 +#include <asm/types.h>
    9.28 +#include <linux/spinlock.h>
    9.29 +#include <linux/mm.h>
    9.30 +#include <linux/highmem.h>
    9.31 +
    9.32 +#define HAVE_ALLOC_SKB		/* For the drivers to know */
    9.33 +#define HAVE_ALIGNABLE_SKB	/* Ditto 8)		   */
    9.34 +#define SLAB_SKB 		/* Slabified skbuffs 	   */
    9.35 +
    9.36 +#define CHECKSUM_NONE 0
    9.37 +#define CHECKSUM_HW 1
    9.38 +#define CHECKSUM_UNNECESSARY 2
    9.39 +
    9.40 +#define SKB_DATA_ALIGN(X)	(((X) + (SMP_CACHE_BYTES-1)) & ~(SMP_CACHE_BYTES-1))
    9.41 +#define SKB_MAX_ORDER(X,ORDER)	(((PAGE_SIZE<<(ORDER)) - (X) - sizeof(struct skb_shared_info))&~(SMP_CACHE_BYTES-1))
    9.42 +#define SKB_MAX_HEAD(X)		(SKB_MAX_ORDER((X),0))
    9.43 +#define SKB_MAX_ALLOC		(SKB_MAX_ORDER(0,2))
    9.44 +
    9.45 +/* A. Checksumming of received packets by device.
    9.46 + *
    9.47 + *	NONE: device failed to checksum this packet.
    9.48 + *		skb->csum is undefined.
    9.49 + *
    9.50 + *	UNNECESSARY: device parsed packet and wouldbe verified checksum.
    9.51 + *		skb->csum is undefined.
    9.52 + *	      It is bad option, but, unfortunately, many of vendors do this.
    9.53 + *	      Apparently with secret goal to sell you new device, when you
    9.54 + *	      will add new protocol to your host. F.e. IPv6. 8)
    9.55 + *
    9.56 + *	HW: the most generic way. Device supplied checksum of _all_
    9.57 + *	    the packet as seen by netif_rx in skb->csum.
    9.58 + *	    NOTE: Even if device supports only some protocols, but
    9.59 + *	    is able to produce some skb->csum, it MUST use HW,
    9.60 + *	    not UNNECESSARY.
    9.61 + *
    9.62 + * B. Checksumming on output.
    9.63 + *
    9.64 + *	NONE: skb is checksummed by protocol or csum is not required.
    9.65 + *
    9.66 + *	HW: device is required to csum packet as seen by hard_start_xmit
    9.67 + *	from skb->h.raw to the end and to record the checksum
    9.68 + *	at skb->h.raw+skb->csum.
    9.69 + *
    9.70 + *	Device must show its capabilities in dev->features, set
    9.71 + *	at device setup time.
    9.72 + *	NETIF_F_HW_CSUM	- it is clever device, it is able to checksum
    9.73 + *			  everything.
    9.74 + *	NETIF_F_NO_CSUM - loopback or reliable single hop media.
    9.75 + *	NETIF_F_IP_CSUM - device is dumb. It is able to csum only
    9.76 + *			  TCP/UDP over IPv4. Sigh. Vendors like this
    9.77 + *			  way by an unknown reason. Though, see comment above
    9.78 + *			  about CHECKSUM_UNNECESSARY. 8)
    9.79 + *
    9.80 + *	Any questions? No questions, good. 		--ANK
    9.81 + */
    9.82 +
    9.83 +#ifdef __i386__
    9.84 +#define NET_CALLER(arg) (*(((void**)&arg)-1))
    9.85 +#else
    9.86 +#define NET_CALLER(arg) __builtin_return_address(0)
    9.87 +#endif
    9.88 +
    9.89 +#ifdef CONFIG_NETFILTER
    9.90 +struct nf_conntrack {
    9.91 +	atomic_t use;
    9.92 +	void (*destroy)(struct nf_conntrack *);
    9.93 +};
    9.94 +
    9.95 +struct nf_ct_info {
    9.96 +	struct nf_conntrack *master;
    9.97 +};
    9.98 +#endif
    9.99 +
   9.100 +struct sk_buff_head {
   9.101 +	/* These two members must be first. */
   9.102 +	struct sk_buff	* next;
   9.103 +	struct sk_buff	* prev;
   9.104 +
   9.105 +	__u32		qlen;
   9.106 +	spinlock_t	lock;
   9.107 +};
   9.108 +
   9.109 +struct sk_buff;
   9.110 +
   9.111 +#define MAX_SKB_FRAGS 6
   9.112 +
   9.113 +typedef struct skb_frag_struct skb_frag_t;
   9.114 +
   9.115 +struct skb_frag_struct
   9.116 +{
   9.117 +	struct page *page;
   9.118 +	__u16 page_offset;
   9.119 +	__u16 size;
   9.120 +};
   9.121 +
   9.122 +/* This data is invariant across clones and lives at
   9.123 + * the end of the header data, ie. at skb->end.
   9.124 + */
   9.125 +struct skb_shared_info {
   9.126 +	atomic_t	dataref;
   9.127 +	unsigned int	nr_frags;
   9.128 +	struct sk_buff	*frag_list;
   9.129 +	skb_frag_t	frags[MAX_SKB_FRAGS];
   9.130 +};
   9.131 +
   9.132 +struct sk_buff {
   9.133 +	/* These two members must be first. */
   9.134 +	struct sk_buff	* next;			/* Next buffer in list 				*/
   9.135 +	struct sk_buff	* prev;			/* Previous buffer in list 			*/
   9.136 +
   9.137 +	struct sk_buff_head * list;		/* List we are on				*/
   9.138 +	struct sock	*sk;			/* Socket we are owned by 			*/
   9.139 +	struct timeval	stamp;			/* Time we arrived				*/
   9.140 +	struct net_device	*dev;		/* Device we arrived on/are leaving by		*/
   9.141 +	struct net_device	*real_dev;	/* For support of point to point protocols 
   9.142 +						   (e.g. 802.3ad) over bonding, we must save the
   9.143 +						   physical device that got the packet before
   9.144 +						   replacing skb->dev with the virtual device.  */
   9.145 +
   9.146 +	/* Transport layer header */
   9.147 +	union
   9.148 +	{
   9.149 +		struct tcphdr	*th;
   9.150 +		struct udphdr	*uh;
   9.151 +		struct icmphdr	*icmph;
   9.152 +		struct igmphdr	*igmph;
   9.153 +		struct iphdr	*ipiph;
   9.154 +		struct spxhdr	*spxh;
   9.155 +		unsigned char	*raw;
   9.156 +	} h;
   9.157 +
   9.158 +	/* Network layer header */
   9.159 +	union
   9.160 +	{
   9.161 +		struct iphdr	*iph;
   9.162 +		struct ipv6hdr	*ipv6h;
   9.163 +		struct arphdr	*arph;
   9.164 +		struct ipxhdr	*ipxh;
   9.165 +		unsigned char	*raw;
   9.166 +	} nh;
   9.167 +  
   9.168 +	/* Link layer header */
   9.169 +	union 
   9.170 +	{	
   9.171 +	  	struct ethhdr	*ethernet;
   9.172 +	  	unsigned char 	*raw;
   9.173 +	} mac;
   9.174 +
   9.175 +	struct  dst_entry *dst;
   9.176 +
   9.177 +	/* 
   9.178 +	 * This is the control buffer. It is free to use for every
   9.179 +	 * layer. Please put your private variables there. If you
   9.180 +	 * want to keep them across layers you have to do a skb_clone()
   9.181 +	 * first. This is owned by whoever has the skb queued ATM.
   9.182 +	 */ 
   9.183 +	char		cb[48];	 
   9.184 +
   9.185 +	unsigned int 	len;			/* Length of actual data			*/
   9.186 + 	unsigned int 	data_len;
   9.187 +	unsigned int	csum;			/* Checksum 					*/
   9.188 +	unsigned char 	__unused,		/* Dead field, may be reused			*/
   9.189 +			cloned, 		/* head may be cloned (check refcnt to be sure). */
   9.190 +  			pkt_type,		/* Packet class					*/
   9.191 +  			ip_summed;		/* Driver fed us an IP checksum			*/
   9.192 +	__u32		priority;		/* Packet queueing priority			*/
   9.193 +	atomic_t	users;			/* User count - see datagram.c,tcp.c 		*/
   9.194 +	unsigned short	protocol;		/* Packet protocol from driver. 		*/
   9.195 +	unsigned short	security;		/* Security level of packet			*/
   9.196 +	unsigned int	truesize;		/* Buffer size 					*/
   9.197 +
   9.198 +	unsigned char	*head;			/* Head of buffer 				*/
   9.199 +	unsigned char	*data;			/* Data head pointer				*/
   9.200 +	unsigned char	*tail;			/* Tail pointer					*/
   9.201 +	unsigned char 	*end;			/* End pointer					*/
   9.202 +
   9.203 +	void 		(*destructor)(struct sk_buff *);	/* Destruct function		*/
   9.204 +#ifdef CONFIG_NETFILTER
   9.205 +	/* Can be used for communication between hooks. */
   9.206 +        unsigned long	nfmark;
   9.207 +	/* Cache info */
   9.208 +	__u32		nfcache;
   9.209 +	/* Associated connection, if any */
   9.210 +	struct nf_ct_info *nfct;
   9.211 +#ifdef CONFIG_NETFILTER_DEBUG
   9.212 +        unsigned int nf_debug;
   9.213 +#endif
   9.214 +#endif /*CONFIG_NETFILTER*/
   9.215 +
   9.216 +#if defined(CONFIG_HIPPI)
   9.217 +	union{
   9.218 +		__u32	ifield;
   9.219 +	} private;
   9.220 +#endif
   9.221 +
   9.222 +#ifdef CONFIG_NET_SCHED
   9.223 +       __u32           tc_index;               /* traffic control index */
   9.224 +#endif
   9.225 +};
   9.226 +
   9.227 +#ifdef __KERNEL__
   9.228 +/*
   9.229 + *	Handling routines are only of interest to the kernel
   9.230 + */
   9.231 +#include <linux/slab.h>
   9.232 +
   9.233 +#include <asm/system.h>
   9.234 +
   9.235 +extern void			__kfree_skb(struct sk_buff *skb);
   9.236 +extern struct sk_buff *		alloc_skb(unsigned int size, int priority);
   9.237 +extern void			kfree_skbmem(struct sk_buff *skb);
   9.238 +extern struct sk_buff *		skb_clone(struct sk_buff *skb, int priority);
   9.239 +extern struct sk_buff *		skb_copy(const struct sk_buff *skb, int priority);
   9.240 +extern struct sk_buff *		pskb_copy(struct sk_buff *skb, int gfp_mask);
   9.241 +extern int			pskb_expand_head(struct sk_buff *skb, int nhead, int ntail, int gfp_mask);
   9.242 +extern struct sk_buff *		skb_realloc_headroom(struct sk_buff *skb, unsigned int headroom);
   9.243 +extern struct sk_buff *		skb_copy_expand(const struct sk_buff *skb, 
   9.244 +						int newheadroom,
   9.245 +						int newtailroom,
   9.246 +						int priority);
   9.247 +extern struct sk_buff *		skb_pad(struct sk_buff *skb, int pad);
   9.248 +#define dev_kfree_skb(a)	kfree_skb(a)
   9.249 +extern void	skb_over_panic(struct sk_buff *skb, int len, void *here);
   9.250 +extern void	skb_under_panic(struct sk_buff *skb, int len, void *here);
   9.251 +
   9.252 +/* Internal */
   9.253 +#define skb_shinfo(SKB)		((struct skb_shared_info *)((SKB)->end))
   9.254 +
   9.255 +/**
   9.256 + *	skb_queue_empty - check if a queue is empty
   9.257 + *	@list: queue head
   9.258 + *
   9.259 + *	Returns true if the queue is empty, false otherwise.
   9.260 + */
   9.261 + 
   9.262 +static inline int skb_queue_empty(struct sk_buff_head *list)
   9.263 +{
   9.264 +	return (list->next == (struct sk_buff *) list);
   9.265 +}
   9.266 +
   9.267 +/**
   9.268 + *	skb_get - reference buffer
   9.269 + *	@skb: buffer to reference
   9.270 + *
   9.271 + *	Makes another reference to a socket buffer and returns a pointer
   9.272 + *	to the buffer.
   9.273 + */
   9.274 + 
   9.275 +static inline struct sk_buff *skb_get(struct sk_buff *skb)
   9.276 +{
   9.277 +	atomic_inc(&skb->users);
   9.278 +	return skb;
   9.279 +}
   9.280 +
   9.281 +/*
   9.282 + * If users==1, we are the only owner and are can avoid redundant
   9.283 + * atomic change.
   9.284 + */
   9.285 + 
   9.286 +/**
   9.287 + *	kfree_skb - free an sk_buff
   9.288 + *	@skb: buffer to free
   9.289 + *
   9.290 + *	Drop a reference to the buffer and free it if the usage count has
   9.291 + *	hit zero.
   9.292 + */
   9.293 + 
   9.294 +static inline void kfree_skb(struct sk_buff *skb)
   9.295 +{
   9.296 +	if (atomic_read(&skb->users) == 1 || atomic_dec_and_test(&skb->users))
   9.297 +		__kfree_skb(skb);
   9.298 +}
   9.299 +
   9.300 +/* Use this if you didn't touch the skb state [for fast switching] */
   9.301 +static inline void kfree_skb_fast(struct sk_buff *skb)
   9.302 +{
   9.303 +	if (atomic_read(&skb->users) == 1 || atomic_dec_and_test(&skb->users))
   9.304 +		kfree_skbmem(skb);	
   9.305 +}
   9.306 +
   9.307 +/**
   9.308 + *	skb_cloned - is the buffer a clone
   9.309 + *	@skb: buffer to check
   9.310 + *
   9.311 + *	Returns true if the buffer was generated with skb_clone() and is
   9.312 + *	one of multiple shared copies of the buffer. Cloned buffers are
   9.313 + *	shared data so must not be written to under normal circumstances.
   9.314 + */
   9.315 +
   9.316 +static inline int skb_cloned(struct sk_buff *skb)
   9.317 +{
   9.318 +	return skb->cloned && atomic_read(&skb_shinfo(skb)->dataref) != 1;
   9.319 +}
   9.320 +
   9.321 +/**
   9.322 + *	skb_shared - is the buffer shared
   9.323 + *	@skb: buffer to check
   9.324 + *
   9.325 + *	Returns true if more than one person has a reference to this
   9.326 + *	buffer.
   9.327 + */
   9.328 + 
   9.329 +static inline int skb_shared(struct sk_buff *skb)
   9.330 +{
   9.331 +	return (atomic_read(&skb->users) != 1);
   9.332 +}
   9.333 +
   9.334 +/** 
   9.335 + *	skb_share_check - check if buffer is shared and if so clone it
   9.336 + *	@skb: buffer to check
   9.337 + *	@pri: priority for memory allocation
   9.338 + *	
   9.339 + *	If the buffer is shared the buffer is cloned and the old copy
   9.340 + *	drops a reference. A new clone with a single reference is returned.
   9.341 + *	If the buffer is not shared the original buffer is returned. When
   9.342 + *	being called from interrupt status or with spinlocks held pri must
   9.343 + *	be GFP_ATOMIC.
   9.344 + *
   9.345 + *	NULL is returned on a memory allocation failure.
   9.346 + */
   9.347 + 
   9.348 +static inline struct sk_buff *skb_share_check(struct sk_buff *skb, int pri)
   9.349 +{
   9.350 +	if (skb_shared(skb)) {
   9.351 +		struct sk_buff *nskb;
   9.352 +		nskb = skb_clone(skb, pri);
   9.353 +		kfree_skb(skb);
   9.354 +		return nskb;
   9.355 +	}
   9.356 +	return skb;
   9.357 +}
   9.358 +
   9.359 +
   9.360 +/*
   9.361 + *	Copy shared buffers into a new sk_buff. We effectively do COW on
   9.362 + *	packets to handle cases where we have a local reader and forward
   9.363 + *	and a couple of other messy ones. The normal one is tcpdumping
   9.364 + *	a packet thats being forwarded.
   9.365 + */
   9.366 + 
   9.367 +/**
   9.368 + *	skb_unshare - make a copy of a shared buffer
   9.369 + *	@skb: buffer to check
   9.370 + *	@pri: priority for memory allocation
   9.371 + *
   9.372 + *	If the socket buffer is a clone then this function creates a new
   9.373 + *	copy of the data, drops a reference count on the old copy and returns
   9.374 + *	the new copy with the reference count at 1. If the buffer is not a clone
   9.375 + *	the original buffer is returned. When called with a spinlock held or
   9.376 + *	from interrupt state @pri must be %GFP_ATOMIC
   9.377 + *
   9.378 + *	%NULL is returned on a memory allocation failure.
   9.379 + */
   9.380 + 
   9.381 +static inline struct sk_buff *skb_unshare(struct sk_buff *skb, int pri)
   9.382 +{
   9.383 +	struct sk_buff *nskb;
   9.384 +	if(!skb_cloned(skb))
   9.385 +		return skb;
   9.386 +	nskb=skb_copy(skb, pri);
   9.387 +	kfree_skb(skb);		/* Free our shared copy */
   9.388 +	return nskb;
   9.389 +}
   9.390 +
   9.391 +/**
   9.392 + *	skb_peek
   9.393 + *	@list_: list to peek at
   9.394 + *
   9.395 + *	Peek an &sk_buff. Unlike most other operations you _MUST_
   9.396 + *	be careful with this one. A peek leaves the buffer on the
   9.397 + *	list and someone else may run off with it. You must hold
   9.398 + *	the appropriate locks or have a private queue to do this.
   9.399 + *
   9.400 + *	Returns %NULL for an empty list or a pointer to the head element.
   9.401 + *	The reference count is not incremented and the reference is therefore
   9.402 + *	volatile. Use with caution.
   9.403 + */
   9.404 + 
   9.405 +static inline struct sk_buff *skb_peek(struct sk_buff_head *list_)
   9.406 +{
   9.407 +	struct sk_buff *list = ((struct sk_buff *)list_)->next;
   9.408 +	if (list == (struct sk_buff *)list_)
   9.409 +		list = NULL;
   9.410 +	return list;
   9.411 +}
   9.412 +
   9.413 +/**
   9.414 + *	skb_peek_tail
   9.415 + *	@list_: list to peek at
   9.416 + *
   9.417 + *	Peek an &sk_buff. Unlike most other operations you _MUST_
   9.418 + *	be careful with this one. A peek leaves the buffer on the
   9.419 + *	list and someone else may run off with it. You must hold
   9.420 + *	the appropriate locks or have a private queue to do this.
   9.421 + *
   9.422 + *	Returns %NULL for an empty list or a pointer to the tail element.
   9.423 + *	The reference count is not incremented and the reference is therefore
   9.424 + *	volatile. Use with caution.
   9.425 + */
   9.426 +
   9.427 +static inline struct sk_buff *skb_peek_tail(struct sk_buff_head *list_)
   9.428 +{
   9.429 +	struct sk_buff *list = ((struct sk_buff *)list_)->prev;
   9.430 +	if (list == (struct sk_buff *)list_)
   9.431 +		list = NULL;
   9.432 +	return list;
   9.433 +}
   9.434 +
   9.435 +/**
   9.436 + *	skb_queue_len	- get queue length
   9.437 + *	@list_: list to measure
   9.438 + *
   9.439 + *	Return the length of an &sk_buff queue. 
   9.440 + */
   9.441 + 
   9.442 +static inline __u32 skb_queue_len(struct sk_buff_head *list_)
   9.443 +{
   9.444 +	return(list_->qlen);
   9.445 +}
   9.446 +
   9.447 +static inline void skb_queue_head_init(struct sk_buff_head *list)
   9.448 +{
   9.449 +	spin_lock_init(&list->lock);
   9.450 +	list->prev = (struct sk_buff *)list;
   9.451 +	list->next = (struct sk_buff *)list;
   9.452 +	list->qlen = 0;
   9.453 +}
   9.454 +
   9.455 +/*
   9.456 + *	Insert an sk_buff at the start of a list.
   9.457 + *
   9.458 + *	The "__skb_xxxx()" functions are the non-atomic ones that
   9.459 + *	can only be called with interrupts disabled.
   9.460 + */
   9.461 +
   9.462 +/**
   9.463 + *	__skb_queue_head - queue a buffer at the list head
   9.464 + *	@list: list to use
   9.465 + *	@newsk: buffer to queue
   9.466 + *
   9.467 + *	Queue a buffer at the start of a list. This function takes no locks
   9.468 + *	and you must therefore hold required locks before calling it.
   9.469 + *
   9.470 + *	A buffer cannot be placed on two lists at the same time.
   9.471 + */	
   9.472 + 
   9.473 +static inline void __skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)
   9.474 +{
   9.475 +	struct sk_buff *prev, *next;
   9.476 +
   9.477 +	newsk->list = list;
   9.478 +	list->qlen++;
   9.479 +	prev = (struct sk_buff *)list;
   9.480 +	next = prev->next;
   9.481 +	newsk->next = next;
   9.482 +	newsk->prev = prev;
   9.483 +	next->prev = newsk;
   9.484 +	prev->next = newsk;
   9.485 +}
   9.486 +
   9.487 +
   9.488 +/**
   9.489 + *	skb_queue_head - queue a buffer at the list head
   9.490 + *	@list: list to use
   9.491 + *	@newsk: buffer to queue
   9.492 + *
   9.493 + *	Queue a buffer at the start of the list. This function takes the
   9.494 + *	list lock and can be used safely with other locking &sk_buff functions
   9.495 + *	safely.
   9.496 + *
   9.497 + *	A buffer cannot be placed on two lists at the same time.
   9.498 + */	
   9.499 +
   9.500 +static inline void skb_queue_head(struct sk_buff_head *list, struct sk_buff *newsk)
   9.501 +{
   9.502 +	unsigned long flags;
   9.503 +
   9.504 +	spin_lock_irqsave(&list->lock, flags);
   9.505 +	__skb_queue_head(list, newsk);
   9.506 +	spin_unlock_irqrestore(&list->lock, flags);
   9.507 +}
   9.508 +
   9.509 +/**
   9.510 + *	__skb_queue_tail - queue a buffer at the list tail
   9.511 + *	@list: list to use
   9.512 + *	@newsk: buffer to queue
   9.513 + *
   9.514 + *	Queue a buffer at the end of a list. This function takes no locks
   9.515 + *	and you must therefore hold required locks before calling it.
   9.516 + *
   9.517 + *	A buffer cannot be placed on two lists at the same time.
   9.518 + */	
   9.519 + 
   9.520 +
   9.521 +static inline void __skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
   9.522 +{
   9.523 +	struct sk_buff *prev, *next;
   9.524 +
   9.525 +	newsk->list = list;
   9.526 +	list->qlen++;
   9.527 +	next = (struct sk_buff *)list;
   9.528 +	prev = next->prev;
   9.529 +	newsk->next = next;
   9.530 +	newsk->prev = prev;
   9.531 +	next->prev = newsk;
   9.532 +	prev->next = newsk;
   9.533 +}
   9.534 +
   9.535 +/**
   9.536 + *	skb_queue_tail - queue a buffer at the list tail
   9.537 + *	@list: list to use
   9.538 + *	@newsk: buffer to queue
   9.539 + *
   9.540 + *	Queue a buffer at the tail of the list. This function takes the
   9.541 + *	list lock and can be used safely with other locking &sk_buff functions
   9.542 + *	safely.
   9.543 + *
   9.544 + *	A buffer cannot be placed on two lists at the same time.
   9.545 + */	
   9.546 +
   9.547 +static inline void skb_queue_tail(struct sk_buff_head *list, struct sk_buff *newsk)
   9.548 +{
   9.549 +	unsigned long flags;
   9.550 +
   9.551 +	spin_lock_irqsave(&list->lock, flags);
   9.552 +	__skb_queue_tail(list, newsk);
   9.553 +	spin_unlock_irqrestore(&list->lock, flags);
   9.554 +}
   9.555 +
   9.556 +/**
   9.557 + *	__skb_dequeue - remove from the head of the queue
   9.558 + *	@list: list to dequeue from
   9.559 + *
   9.560 + *	Remove the head of the list. This function does not take any locks
   9.561 + *	so must be used with appropriate locks held only. The head item is
   9.562 + *	returned or %NULL if the list is empty.
   9.563 + */
   9.564 +
   9.565 +static inline struct sk_buff *__skb_dequeue(struct sk_buff_head *list)
   9.566 +{
   9.567 +	struct sk_buff *next, *prev, *result;
   9.568 +
   9.569 +	prev = (struct sk_buff *) list;
   9.570 +	next = prev->next;
   9.571 +	result = NULL;
   9.572 +	if (next != prev) {
   9.573 +		result = next;
   9.574 +		next = next->next;
   9.575 +		list->qlen--;
   9.576 +		next->prev = prev;
   9.577 +		prev->next = next;
   9.578 +		result->next = NULL;
   9.579 +		result->prev = NULL;
   9.580 +		result->list = NULL;
   9.581 +	}
   9.582 +	return result;
   9.583 +}
   9.584 +
   9.585 +/**
   9.586 + *	skb_dequeue - remove from the head of the queue
   9.587 + *	@list: list to dequeue from
   9.588 + *
   9.589 + *	Remove the head of the list. The list lock is taken so the function
   9.590 + *	may be used safely with other locking list functions. The head item is
   9.591 + *	returned or %NULL if the list is empty.
   9.592 + */
   9.593 +
   9.594 +static inline struct sk_buff *skb_dequeue(struct sk_buff_head *list)
   9.595 +{
   9.596 +	unsigned long flags;
   9.597 +	struct sk_buff *result;
   9.598 +
   9.599 +	spin_lock_irqsave(&list->lock, flags);
   9.600 +	result = __skb_dequeue(list);
   9.601 +	spin_unlock_irqrestore(&list->lock, flags);
   9.602 +	return result;
   9.603 +}
   9.604 +
   9.605 +/*
   9.606 + *	Insert a packet on a list.
   9.607 + */
   9.608 +
   9.609 +static inline void __skb_insert(struct sk_buff *newsk,
   9.610 +	struct sk_buff * prev, struct sk_buff *next,
   9.611 +	struct sk_buff_head * list)
   9.612 +{
   9.613 +	newsk->next = next;
   9.614 +	newsk->prev = prev;
   9.615 +	next->prev = newsk;
   9.616 +	prev->next = newsk;
   9.617 +	newsk->list = list;
   9.618 +	list->qlen++;
   9.619 +}
   9.620 +
   9.621 +/**
   9.622 + *	skb_insert	-	insert a buffer
   9.623 + *	@old: buffer to insert before
   9.624 + *	@newsk: buffer to insert
   9.625 + *
   9.626 + *	Place a packet before a given packet in a list. The list locks are taken
   9.627 + *	and this function is atomic with respect to other list locked calls
   9.628 + *	A buffer cannot be placed on two lists at the same time.
   9.629 + */
   9.630 +
   9.631 +static inline void skb_insert(struct sk_buff *old, struct sk_buff *newsk)
   9.632 +{
   9.633 +	unsigned long flags;
   9.634 +
   9.635 +	spin_lock_irqsave(&old->list->lock, flags);
   9.636 +	__skb_insert(newsk, old->prev, old, old->list);
   9.637 +	spin_unlock_irqrestore(&old->list->lock, flags);
   9.638 +}
   9.639 +
   9.640 +/*
   9.641 + *	Place a packet after a given packet in a list.
   9.642 + */
   9.643 +
   9.644 +static inline void __skb_append(struct sk_buff *old, struct sk_buff *newsk)
   9.645 +{
   9.646 +	__skb_insert(newsk, old, old->next, old->list);
   9.647 +}
   9.648 +
   9.649 +/**
   9.650 + *	skb_append	-	append a buffer
   9.651 + *	@old: buffer to insert after
   9.652 + *	@newsk: buffer to insert
   9.653 + *
   9.654 + *	Place a packet after a given packet in a list. The list locks are taken
   9.655 + *	and this function is atomic with respect to other list locked calls.
   9.656 + *	A buffer cannot be placed on two lists at the same time.
   9.657 + */
   9.658 +
   9.659 +
   9.660 +static inline void skb_append(struct sk_buff *old, struct sk_buff *newsk)
   9.661 +{
   9.662 +	unsigned long flags;
   9.663 +
   9.664 +	spin_lock_irqsave(&old->list->lock, flags);
   9.665 +	__skb_append(old, newsk);
   9.666 +	spin_unlock_irqrestore(&old->list->lock, flags);
   9.667 +}
   9.668 +
   9.669 +/*
   9.670 + * remove sk_buff from list. _Must_ be called atomically, and with
   9.671 + * the list known..
   9.672 + */
   9.673 + 
   9.674 +static inline void __skb_unlink(struct sk_buff *skb, struct sk_buff_head *list)
   9.675 +{
   9.676 +	struct sk_buff * next, * prev;
   9.677 +
   9.678 +	list->qlen--;
   9.679 +	next = skb->next;
   9.680 +	prev = skb->prev;
   9.681 +	skb->next = NULL;
   9.682 +	skb->prev = NULL;
   9.683 +	skb->list = NULL;
   9.684 +	next->prev = prev;
   9.685 +	prev->next = next;
   9.686 +}
   9.687 +
   9.688 +/**
   9.689 + *	skb_unlink	-	remove a buffer from a list
   9.690 + *	@skb: buffer to remove
   9.691 + *
   9.692 + *	Place a packet after a given packet in a list. The list locks are taken
   9.693 + *	and this function is atomic with respect to other list locked calls
   9.694 + *	
   9.695 + *	Works even without knowing the list it is sitting on, which can be 
   9.696 + *	handy at times. It also means that THE LIST MUST EXIST when you 
   9.697 + *	unlink. Thus a list must have its contents unlinked before it is
   9.698 + *	destroyed.
   9.699 + */
   9.700 +
   9.701 +static inline void skb_unlink(struct sk_buff *skb)
   9.702 +{
   9.703 +	struct sk_buff_head *list = skb->list;
   9.704 +
   9.705 +	if(list) {
   9.706 +		unsigned long flags;
   9.707 +
   9.708 +		spin_lock_irqsave(&list->lock, flags);
   9.709 +		if(skb->list == list)
   9.710 +			__skb_unlink(skb, skb->list);
   9.711 +		spin_unlock_irqrestore(&list->lock, flags);
   9.712 +	}
   9.713 +}
   9.714 +
   9.715 +/* XXX: more streamlined implementation */
   9.716 +
   9.717 +/**
   9.718 + *	__skb_dequeue_tail - remove from the tail of the queue
   9.719 + *	@list: list to dequeue from
   9.720 + *
   9.721 + *	Remove the tail of the list. This function does not take any locks
   9.722 + *	so must be used with appropriate locks held only. The tail item is
   9.723 + *	returned or %NULL if the list is empty.
   9.724 + */
   9.725 +
   9.726 +static inline struct sk_buff *__skb_dequeue_tail(struct sk_buff_head *list)
   9.727 +{
   9.728 +	struct sk_buff *skb = skb_peek_tail(list); 
   9.729 +	if (skb)
   9.730 +		__skb_unlink(skb, list);
   9.731 +	return skb;
   9.732 +}
   9.733 +
   9.734 +/**
   9.735 + *	skb_dequeue - remove from the head of the queue
   9.736 + *	@list: list to dequeue from
   9.737 + *
   9.738 + *	Remove the head of the list. The list lock is taken so the function
   9.739 + *	may be used safely with other locking list functions. The tail item is
   9.740 + *	returned or %NULL if the list is empty.
   9.741 + */
   9.742 +
   9.743 +static inline struct sk_buff *skb_dequeue_tail(struct sk_buff_head *list)
   9.744 +{
   9.745 +	unsigned long flags;
   9.746 +	struct sk_buff *result;
   9.747 +
   9.748 +	spin_lock_irqsave(&list->lock, flags);
   9.749 +	result = __skb_dequeue_tail(list);
   9.750 +	spin_unlock_irqrestore(&list->lock, flags);
   9.751 +	return result;
   9.752 +}
   9.753 +
   9.754 +static inline int skb_is_nonlinear(const struct sk_buff *skb)
   9.755 +{
   9.756 +	return skb->data_len;
   9.757 +}
   9.758 +
   9.759 +static inline unsigned int skb_headlen(const struct sk_buff *skb)
   9.760 +{
   9.761 +	return skb->len - skb->data_len;
   9.762 +}
   9.763 +
   9.764 +#define SKB_PAGE_ASSERT(skb) do { if (skb_shinfo(skb)->nr_frags) out_of_line_bug(); } while (0)
   9.765 +#define SKB_FRAG_ASSERT(skb) do { if (skb_shinfo(skb)->frag_list) out_of_line_bug(); } while (0)
   9.766 +#define SKB_LINEAR_ASSERT(skb) do { if (skb_is_nonlinear(skb)) out_of_line_bug(); } while (0)
   9.767 +
   9.768 +/*
   9.769 + *	Add data to an sk_buff
   9.770 + */
   9.771 + 
   9.772 +static inline unsigned char *__skb_put(struct sk_buff *skb, unsigned int len)
   9.773 +{
   9.774 +	unsigned char *tmp=skb->tail;
   9.775 +	SKB_LINEAR_ASSERT(skb);
   9.776 +	skb->tail+=len;
   9.777 +	skb->len+=len;
   9.778 +	return tmp;
   9.779 +}
   9.780 +
   9.781 +/**
   9.782 + *	skb_put - add data to a buffer
   9.783 + *	@skb: buffer to use 
   9.784 + *	@len: amount of data to add
   9.785 + *
   9.786 + *	This function extends the used data area of the buffer. If this would
   9.787 + *	exceed the total buffer size the kernel will panic. A pointer to the
   9.788 + *	first byte of the extra data is returned.
   9.789 + */
   9.790 + 
   9.791 +static inline unsigned char *skb_put(struct sk_buff *skb, unsigned int len)
   9.792 +{
   9.793 +	unsigned char *tmp=skb->tail;
   9.794 +	SKB_LINEAR_ASSERT(skb);
   9.795 +	skb->tail+=len;
   9.796 +	skb->len+=len;
   9.797 +	if(skb->tail>skb->end) {
   9.798 +		skb_over_panic(skb, len, current_text_addr());
   9.799 +	}
   9.800 +	return tmp;
   9.801 +}
   9.802 +
   9.803 +static inline unsigned char *__skb_push(struct sk_buff *skb, unsigned int len)
   9.804 +{
   9.805 +	skb->data-=len;
   9.806 +	skb->len+=len;
   9.807 +	return skb->data;
   9.808 +}
   9.809 +
   9.810 +/**
   9.811 + *	skb_push - add data to the start of a buffer
   9.812 + *	@skb: buffer to use 
   9.813 + *	@len: amount of data to add
   9.814 + *
   9.815 + *	This function extends the used data area of the buffer at the buffer
   9.816 + *	start. If this would exceed the total buffer headroom the kernel will
   9.817 + *	panic. A pointer to the first byte of the extra data is returned.
   9.818 + */
   9.819 +
   9.820 +static inline unsigned char *skb_push(struct sk_buff *skb, unsigned int len)
   9.821 +{
   9.822 +	skb->data-=len;
   9.823 +	skb->len+=len;
   9.824 +	if(skb->data<skb->head) {
   9.825 +		skb_under_panic(skb, len, current_text_addr());
   9.826 +	}
   9.827 +	return skb->data;
   9.828 +}
   9.829 +
   9.830 +static inline char *__skb_pull(struct sk_buff *skb, unsigned int len)
   9.831 +{
   9.832 +	skb->len-=len;
   9.833 +	if (skb->len < skb->data_len)
   9.834 +		out_of_line_bug();
   9.835 +	return 	skb->data+=len;
   9.836 +}
   9.837 +
   9.838 +/**
   9.839 + *	skb_pull - remove data from the start of a buffer
   9.840 + *	@skb: buffer to use 
   9.841 + *	@len: amount of data to remove
   9.842 + *
   9.843 + *	This function removes data from the start of a buffer, returning
   9.844 + *	the memory to the headroom. A pointer to the next data in the buffer
   9.845 + *	is returned. Once the data has been pulled future pushes will overwrite
   9.846 + *	the old data.
   9.847 + */
   9.848 +
   9.849 +static inline unsigned char * skb_pull(struct sk_buff *skb, unsigned int len)
   9.850 +{	
   9.851 +	if (len > skb->len)
   9.852 +		return NULL;
   9.853 +	return __skb_pull(skb,len);
   9.854 +}
   9.855 +
   9.856 +extern unsigned char * __pskb_pull_tail(struct sk_buff *skb, int delta);
   9.857 +
   9.858 +static inline char *__pskb_pull(struct sk_buff *skb, unsigned int len)
   9.859 +{
   9.860 +	if (len > skb_headlen(skb) &&
   9.861 +	    __pskb_pull_tail(skb, len-skb_headlen(skb)) == NULL)
   9.862 +		return NULL;
   9.863 +	skb->len -= len;
   9.864 +	return 	skb->data += len;
   9.865 +}
   9.866 +
   9.867 +static inline unsigned char * pskb_pull(struct sk_buff *skb, unsigned int len)
   9.868 +{	
   9.869 +	if (len > skb->len)
   9.870 +		return NULL;
   9.871 +	return __pskb_pull(skb,len);
   9.872 +}
   9.873 +
   9.874 +static inline int pskb_may_pull(struct sk_buff *skb, unsigned int len)
   9.875 +{
   9.876 +	if (len <= skb_headlen(skb))
   9.877 +		return 1;
   9.878 +	if (len > skb->len)
   9.879 +		return 0;
   9.880 +	return (__pskb_pull_tail(skb, len-skb_headlen(skb)) != NULL);
   9.881 +}
   9.882 +
   9.883 +/**
   9.884 + *	skb_headroom - bytes at buffer head
   9.885 + *	@skb: buffer to check
   9.886 + *
   9.887 + *	Return the number of bytes of free space at the head of an &sk_buff.
   9.888 + */
   9.889 + 
   9.890 +static inline int skb_headroom(const struct sk_buff *skb)
   9.891 +{
   9.892 +	return skb->data-skb->head;
   9.893 +}
   9.894 +
   9.895 +/**
   9.896 + *	skb_tailroom - bytes at buffer end
   9.897 + *	@skb: buffer to check
   9.898 + *
   9.899 + *	Return the number of bytes of free space at the tail of an sk_buff
   9.900 + */
   9.901 +
   9.902 +static inline int skb_tailroom(const struct sk_buff *skb)
   9.903 +{
   9.904 +	return skb_is_nonlinear(skb) ? 0 : skb->end-skb->tail;
   9.905 +}
   9.906 +
   9.907 +/**
   9.908 + *	skb_reserve - adjust headroom
   9.909 + *	@skb: buffer to alter
   9.910 + *	@len: bytes to move
   9.911 + *
   9.912 + *	Increase the headroom of an empty &sk_buff by reducing the tail
   9.913 + *	room. This is only allowed for an empty buffer.
   9.914 + */
   9.915 +
   9.916 +static inline void skb_reserve(struct sk_buff *skb, unsigned int len)
   9.917 +{
   9.918 +	skb->data+=len;
   9.919 +	skb->tail+=len;
   9.920 +}
   9.921 +
   9.922 +extern int ___pskb_trim(struct sk_buff *skb, unsigned int len, int realloc);
   9.923 +
   9.924 +static inline void __skb_trim(struct sk_buff *skb, unsigned int len)
   9.925 +{
   9.926 +	if (!skb->data_len) {
   9.927 +		skb->len = len;
   9.928 +		skb->tail = skb->data+len;
   9.929 +	} else {
   9.930 +		___pskb_trim(skb, len, 0);
   9.931 +	}
   9.932 +}
   9.933 +
   9.934 +/**
   9.935 + *	skb_trim - remove end from a buffer
   9.936 + *	@skb: buffer to alter
   9.937 + *	@len: new length
   9.938 + *
   9.939 + *	Cut the length of a buffer down by removing data from the tail. If
   9.940 + *	the buffer is already under the length specified it is not modified.
   9.941 + */
   9.942 +
   9.943 +static inline void skb_trim(struct sk_buff *skb, unsigned int len)
   9.944 +{
   9.945 +	if (skb->len > len) {
   9.946 +		__skb_trim(skb, len);
   9.947 +	}
   9.948 +}
   9.949 +
   9.950 +
   9.951 +static inline int __pskb_trim(struct sk_buff *skb, unsigned int len)
   9.952 +{
   9.953 +	if (!skb->data_len) {
   9.954 +		skb->len = len;
   9.955 +		skb->tail = skb->data+len;
   9.956 +		return 0;
   9.957 +	} else {
   9.958 +		return ___pskb_trim(skb, len, 1);
   9.959 +	}
   9.960 +}
   9.961 +
   9.962 +static inline int pskb_trim(struct sk_buff *skb, unsigned int len)
   9.963 +{
   9.964 +	if (len < skb->len)
   9.965 +		return __pskb_trim(skb, len);
   9.966 +	return 0;
   9.967 +}
   9.968 +
   9.969 +/**
   9.970 + *	skb_orphan - orphan a buffer
   9.971 + *	@skb: buffer to orphan
   9.972 + *
   9.973 + *	If a buffer currently has an owner then we call the owner's
   9.974 + *	destructor function and make the @skb unowned. The buffer continues
   9.975 + *	to exist but is no longer charged to its former owner.
   9.976 + */
   9.977 +
   9.978 +
   9.979 +static inline void skb_orphan(struct sk_buff *skb)
   9.980 +{
   9.981 +	if (skb->destructor)
   9.982 +		skb->destructor(skb);
   9.983 +	skb->destructor = NULL;
   9.984 +	skb->sk = NULL;
   9.985 +}
   9.986 +
   9.987 +/**
   9.988 + *	skb_purge - empty a list
   9.989 + *	@list: list to empty
   9.990 + *
   9.991 + *	Delete all buffers on an &sk_buff list. Each buffer is removed from
   9.992 + *	the list and one reference dropped. This function takes the list
   9.993 + *	lock and is atomic with respect to other list locking functions.
   9.994 + */
   9.995 +
   9.996 +
   9.997 +static inline void skb_queue_purge(struct sk_buff_head *list)
   9.998 +{
   9.999 +	struct sk_buff *skb;
  9.1000 +	while ((skb=skb_dequeue(list))!=NULL)
  9.1001 +		kfree_skb(skb);
  9.1002 +}
  9.1003 +
  9.1004 +/**
  9.1005 + *	__skb_purge - empty a list
  9.1006 + *	@list: list to empty
  9.1007 + *
  9.1008 + *	Delete all buffers on an &sk_buff list. Each buffer is removed from
  9.1009 + *	the list and one reference dropped. This function does not take the
  9.1010 + *	list lock and the caller must hold the relevant locks to use it.
  9.1011 + */
  9.1012 +
  9.1013 +
  9.1014 +static inline void __skb_queue_purge(struct sk_buff_head *list)
  9.1015 +{
  9.1016 +	struct sk_buff *skb;
  9.1017 +	while ((skb=__skb_dequeue(list))!=NULL)
  9.1018 +		kfree_skb(skb);
  9.1019 +}
  9.1020 +
  9.1021 +/**
  9.1022 + *	__dev_alloc_skb - allocate an skbuff for sending
  9.1023 + *	@length: length to allocate
  9.1024 + *	@gfp_mask: get_free_pages mask, passed to alloc_skb
  9.1025 + *
  9.1026 + *	Allocate a new &sk_buff and assign it a usage count of one. The
  9.1027 + *	buffer has unspecified headroom built in. Users should allocate
  9.1028 + *	the headroom they think they need without accounting for the
  9.1029 + *	built in space. The built in space is used for optimisations.
  9.1030 + *
  9.1031 + *	%NULL is returned in there is no free memory.
  9.1032 + */
  9.1033 + 
  9.1034 +static inline struct sk_buff *__dev_alloc_skb(unsigned int length,
  9.1035 +					      int gfp_mask)
  9.1036 +{
  9.1037 +	struct sk_buff *skb;
  9.1038 +#if defined(CONFIG_XEN)
  9.1039 +	length = (PAGE_SIZE/2)+1; /* force slab allocater to give us a page */
  9.1040 +#endif
  9.1041 +	skb = alloc_skb(length+16, gfp_mask);
  9.1042 +	if (skb)
  9.1043 +		skb_reserve(skb,16);
  9.1044 +	return skb;
  9.1045 +}
  9.1046 +
  9.1047 +/**
  9.1048 + *	dev_alloc_skb - allocate an skbuff for sending
  9.1049 + *	@length: length to allocate
  9.1050 + *
  9.1051 + *	Allocate a new &sk_buff and assign it a usage count of one. The
  9.1052 + *	buffer has unspecified headroom built in. Users should allocate
  9.1053 + *	the headroom they think they need without accounting for the
  9.1054 + *	built in space. The built in space is used for optimisations.
  9.1055 + *
  9.1056 + *	%NULL is returned in there is no free memory. Although this function
  9.1057 + *	allocates memory it can be called from an interrupt.
  9.1058 + */
  9.1059 + 
  9.1060 +static inline struct sk_buff *dev_alloc_skb(unsigned int length)
  9.1061 +{
  9.1062 +	return __dev_alloc_skb(length, GFP_ATOMIC);
  9.1063 +}
  9.1064 +
  9.1065 +/**
  9.1066 + *	skb_cow - copy header of skb when it is required
  9.1067 + *	@skb: buffer to cow
  9.1068 + *	@headroom: needed headroom
  9.1069 + *
  9.1070 + *	If the skb passed lacks sufficient headroom or its data part
  9.1071 + *	is shared, data is reallocated. If reallocation fails, an error
  9.1072 + *	is returned and original skb is not changed.
  9.1073 + *
  9.1074 + *	The result is skb with writable area skb->head...skb->tail
  9.1075 + *	and at least @headroom of space at head.
  9.1076 + */
  9.1077 +
  9.1078 +static inline int
  9.1079 +skb_cow(struct sk_buff *skb, unsigned int headroom)
  9.1080 +{
  9.1081 +	int delta = (headroom > 16 ? headroom : 16) - skb_headroom(skb);
  9.1082 +
  9.1083 +	if (delta < 0)
  9.1084 +		delta = 0;
  9.1085 +
  9.1086 +	if (delta || skb_cloned(skb))
  9.1087 +		return pskb_expand_head(skb, (delta+15)&~15, 0, GFP_ATOMIC);
  9.1088 +	return 0;
  9.1089 +}
  9.1090 +
  9.1091 +/**
  9.1092 + *	skb_padto	- pad an skbuff up to a minimal size
  9.1093 + *	@skb: buffer to pad
  9.1094 + *	@len: minimal length
  9.1095 + *
  9.1096 + *	Pads up a buffer to ensure the trailing bytes exist and are
  9.1097 + *	blanked. If the buffer already contains sufficient data it
  9.1098 + *	is untouched. Returns the buffer, which may be a replacement
  9.1099 + *	for the original, or NULL for out of memory - in which case
  9.1100 + *	the original buffer is still freed.
  9.1101 + */
  9.1102 + 
  9.1103 +static inline struct sk_buff *skb_padto(struct sk_buff *skb, unsigned int len)
  9.1104 +{
  9.1105 +	unsigned int size = skb->len;
  9.1106 +	if(likely(size >= len))
  9.1107 +		return skb;
  9.1108 +	return skb_pad(skb, len-size);
  9.1109 +}
  9.1110 +
  9.1111 +/**
  9.1112 + *	skb_linearize - convert paged skb to linear one
  9.1113 + *	@skb: buffer to linarize
  9.1114 + *	@gfp: allocation mode
  9.1115 + *
  9.1116 + *	If there is no free memory -ENOMEM is returned, otherwise zero
  9.1117 + *	is returned and the old skb data released.  */
  9.1118 +int skb_linearize(struct sk_buff *skb, int gfp);
  9.1119 +
  9.1120 +static inline void *kmap_skb_frag(const skb_frag_t *frag)
  9.1121 +{
  9.1122 +#ifdef CONFIG_HIGHMEM
  9.1123 +	if (in_irq())
  9.1124 +		out_of_line_bug();
  9.1125 +
  9.1126 +	local_bh_disable();
  9.1127 +#endif
  9.1128 +	return kmap_atomic(frag->page, KM_SKB_DATA_SOFTIRQ);
  9.1129 +}
  9.1130 +
  9.1131 +static inline void kunmap_skb_frag(void *vaddr)
  9.1132 +{
  9.1133 +	kunmap_atomic(vaddr, KM_SKB_DATA_SOFTIRQ);
  9.1134 +#ifdef CONFIG_HIGHMEM
  9.1135 +	local_bh_enable();
  9.1136 +#endif
  9.1137 +}
  9.1138 +
  9.1139 +#define skb_queue_walk(queue, skb) \
  9.1140 +		for (skb = (queue)->next;			\
  9.1141 +		     (skb != (struct sk_buff *)(queue));	\
  9.1142 +		     skb=skb->next)
  9.1143 +
  9.1144 +
  9.1145 +extern struct sk_buff *		skb_recv_datagram(struct sock *sk,unsigned flags,int noblock, int *err);
  9.1146 +extern unsigned int		datagram_poll(struct file *file, struct socket *sock, struct poll_table_struct *wait);
  9.1147 +extern int			skb_copy_datagram(const struct sk_buff *from, int offset, char *to,int size);
  9.1148 +extern int			skb_copy_datagram_iovec(const struct sk_buff *from, int offset, struct iovec *to,int size);
  9.1149 +extern int			skb_copy_and_csum_datagram(const struct sk_buff *skb, int offset, u8 *to, int len, unsigned int *csump);
  9.1150 +extern int			skb_copy_and_csum_datagram_iovec(const struct sk_buff *skb, int hlen, struct iovec *iov);
  9.1151 +extern void			skb_free_datagram(struct sock * sk, struct sk_buff *skb);
  9.1152 +
  9.1153 +extern unsigned int		skb_checksum(const struct sk_buff *skb, int offset, int len, unsigned int csum);
  9.1154 +extern int			skb_copy_bits(const struct sk_buff *skb, int offset, void *to, int len);
  9.1155 +extern unsigned int		skb_copy_and_csum_bits(const struct sk_buff *skb, int offset, u8 *to, int len, unsigned int csum);
  9.1156 +extern void			skb_copy_and_csum_dev(const struct sk_buff *skb, u8 *to);
  9.1157 +
  9.1158 +extern void skb_init(void);
  9.1159 +extern void skb_add_mtu(int mtu);
  9.1160 +
  9.1161 +#ifdef CONFIG_NETFILTER
  9.1162 +static inline void
  9.1163 +nf_conntrack_put(struct nf_ct_info *nfct)
  9.1164 +{
  9.1165 +	if (nfct && atomic_dec_and_test(&nfct->master->use))
  9.1166 +		nfct->master->destroy(nfct->master);
  9.1167 +}
  9.1168 +static inline void
  9.1169 +nf_conntrack_get(struct nf_ct_info *nfct)
  9.1170 +{
  9.1171 +	if (nfct)
  9.1172 +		atomic_inc(&nfct->master->use);
  9.1173 +}
  9.1174 +#endif
  9.1175 +
  9.1176 +#endif	/* __KERNEL__ */
  9.1177 +#endif	/* _LINUX_SKBUFF_H */