ia64/xen-unstable

view linux-2.6-xen-sparse/arch/xen/kernel/skbuff.c @ 6538:84ee014ebd41

Merge xen-vtx-unstable.hg
author adsharma@los-vmm.sc.intel.com
date Wed Aug 17 12:34:38 2005 -0800 (2005-08-17)
parents 23979fb12c49 7bd1a40ae2bd
children 99914b54f7bf
line source
2 #include <linux/config.h>
3 #include <linux/module.h>
4 #include <linux/version.h>
5 #include <linux/kernel.h>
6 #include <linux/sched.h>
7 #include <linux/slab.h>
8 #include <linux/netdevice.h>
9 #include <linux/inetdevice.h>
10 #include <linux/etherdevice.h>
11 #include <linux/skbuff.h>
12 #include <linux/init.h>
13 #include <asm/io.h>
14 #include <asm/page.h>
15 #include <asm-xen/hypervisor.h>
17 /* Referenced in netback.c. */
18 /*static*/ kmem_cache_t *skbuff_cachep;
20 #define MAX_SKBUFF_ORDER 2
21 static kmem_cache_t *skbuff_order_cachep[MAX_SKBUFF_ORDER + 1];
23 struct sk_buff *__dev_alloc_skb(unsigned int length, int gfp_mask)
24 {
25 struct sk_buff *skb;
26 int order;
28 length = SKB_DATA_ALIGN(length + 16);
29 order = get_order(length + sizeof(struct skb_shared_info));
30 if (order > MAX_SKBUFF_ORDER) {
31 printk(KERN_ALERT "Attempt to allocate order %d skbuff. "
32 "Increase MAX_SKBUFF_ORDER.\n", order);
33 return NULL;
34 }
36 skb = alloc_skb_from_cache(
37 skbuff_order_cachep[order], length, gfp_mask);
38 if (skb != NULL)
39 skb_reserve(skb, 16);
41 return skb;
42 }
44 static void skbuff_ctor(void *buf, kmem_cache_t *cachep, unsigned long unused)
45 {
46 int order = 0;
48 while (skbuff_order_cachep[order] != cachep)
49 order++;
51 if (order != 0)
52 xen_create_contiguous_region((unsigned long)buf, order);
54 scrub_pages(buf, 1 << order);
55 }
57 static void skbuff_dtor(void *buf, kmem_cache_t *cachep, unsigned long unused)
58 {
59 int order = 0;
61 while (skbuff_order_cachep[order] != cachep)
62 order++;
64 if (order != 0)
65 xen_destroy_contiguous_region((unsigned long)buf, order);
66 }
68 static int __init skbuff_init(void)
69 {
70 static char name[MAX_SKBUFF_ORDER + 1][20];
71 unsigned long size;
72 int order;
74 for (order = 0; order <= MAX_SKBUFF_ORDER; order++) {
75 size = PAGE_SIZE << order;
76 sprintf(name[order], "xen-skb-%lu", size);
77 skbuff_order_cachep[order] = kmem_cache_create(
78 name[order], size, size, 0, skbuff_ctor, skbuff_dtor);
79 }
81 skbuff_cachep = skbuff_order_cachep[0];
83 return 0;
84 }
85 __initcall(skbuff_init);
87 EXPORT_SYMBOL(__dev_alloc_skb);
89 /*
90 * Local variables:
91 * c-file-style: "linux"
92 * indent-tabs-mode: t
93 * c-indent-level: 8
94 * c-basic-offset: 8
95 * tab-width: 8
96 * End:
97 */