From b68fe3b5b4eb8aeca73008a3eafd31dd916344b2 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 13 May 2009 12:14:46 -0700 Subject: [PATCH] datapath: Fix build warnings and errors on Linux 2.6.15, 2.6.16, 2.6.17. --- datapath/datapath.c | 8 +- .../compat-2.6/include/linux/cpumask.h | 11 ++ .../linux-2.6/compat-2.6/include/linux/log2.h | 159 +----------------- .../compat-2.6/include/linux/mutex.h | 2 +- .../compat-2.6/include/linux/skbuff.h | 33 ++++ 5 files changed, 57 insertions(+), 156 deletions(-) create mode 100644 datapath/linux-2.6/compat-2.6/include/linux/cpumask.h diff --git a/datapath/datapath.c b/datapath/datapath.c index ac7219a0..25db7d4f 100644 --- a/datapath/datapath.c +++ b/datapath/datapath.c @@ -126,7 +126,6 @@ static int dp_fill_ifinfo(struct sk_buff *skb, const struct net_device *dev = port->dev; struct ifinfomsg *hdr; struct nlmsghdr *nlh; - u8 operstate = netif_running(dev) ? dev->operstate : IF_OPER_DOWN; nlh = nlmsg_put(skb, 0, 0, event, sizeof(*hdr), flags); if (nlh == NULL) @@ -143,7 +142,10 @@ static int dp_fill_ifinfo(struct sk_buff *skb, NLA_PUT_STRING(skb, IFLA_IFNAME, dev->name); NLA_PUT_U32(skb, IFLA_MASTER, dp->ports[ODPP_LOCAL]->dev->ifindex); NLA_PUT_U32(skb, IFLA_MTU, dev->mtu); - NLA_PUT_U8(skb, IFLA_OPERSTATE, operstate); +#ifdef IFLA_OPERSTATE + NLA_PUT_U8(skb, IFLA_OPERSTATE, + netif_running(dev) ? dev->operstate : IF_OPER_DOWN); +#endif if (dev->addr_len) NLA_PUT(skb, IFLA_ADDRESS, dev->addr_len, dev->dev_addr); @@ -1612,7 +1614,7 @@ static unsigned int openvswitch_poll(struct file *file, poll_table *wait) return mask; } -const struct file_operations openvswitch_fops = { +struct file_operations openvswitch_fops = { /* XXX .aio_read = openvswitch_aio_read, */ .read = openvswitch_read, .poll = openvswitch_poll, diff --git a/datapath/linux-2.6/compat-2.6/include/linux/cpumask.h b/datapath/linux-2.6/compat-2.6/include/linux/cpumask.h new file mode 100644 index 00000000..48c73aa8 --- /dev/null +++ b/datapath/linux-2.6/compat-2.6/include/linux/cpumask.h @@ -0,0 +1,11 @@ +#ifndef __LINUX_CPUMASK_WRAPPER_H +#define __LINUX_CPUMASK_WRAPPER_H + +#include_next + +/* for_each_cpu was renamed for_each_possible_cpu in 2.6.18. */ +#ifndef for_each_possible_cpu +#define for_each_possible_cpu for_each_cpu +#endif + +#endif /* linux/cpumask.h wrapper */ diff --git a/datapath/linux-2.6/compat-2.6/include/linux/log2.h b/datapath/linux-2.6/compat-2.6/include/linux/log2.h index d1a339f0..69abae5e 100644 --- a/datapath/linux-2.6/compat-2.6/include/linux/log2.h +++ b/datapath/linux-2.6/compat-2.6/include/linux/log2.h @@ -1,162 +1,17 @@ +#ifndef __LINUX_LOG2_WRAPPER +#define __LINUX_LOG2_WRAPPER + #ifdef HAVE_LOG2_H #include_next #else -/* Integer base 2 logarithm calculation - * - * Copyright (C) 2006, 2009 Red Hat, Inc. All Rights Reserved. - * Written by David Howells (dhowells@redhat.com) - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version - * 2 of the License, or (at your option) any later version. - */ - -#ifndef _LINUX_LOG2_H -#define _LINUX_LOG2_H - -#include -#include +/* This is very stripped down because log2.h has far too many dependencies. */ -/* - * deal with unrepresentable constant logarithms - */ extern __attribute__((const, noreturn)) int ____ilog2_NaN(void); -/* - * non-constant log of base 2 calculators - * - the arch may override these in asm/bitops.h if they can be implemented - * more efficiently than using fls() and fls64() - * - the arch is not required to handle n==0 if implementing the fallback - */ -#ifndef CONFIG_ARCH_HAS_ILOG2_U32 -static inline __attribute__((const)) -int __ilog2_u32(u32 n) -{ - return fls(n) - 1; -} -#endif - -#ifndef CONFIG_ARCH_HAS_ILOG2_U64 -static inline __attribute__((const)) -int __ilog2_u64(u64 n) -{ - return fls64(n) - 1; -} +#define ilog2(n) ((n) == 4 ? 2 : \ + (n) == 8 ? 3 : \ + ____ilog2_NaN()) #endif -/* - * round up to nearest power of two - */ -static inline __attribute__((const)) -unsigned long __roundup_pow_of_two(unsigned long n) -{ - return 1UL << fls_long(n - 1); -} - -/** - * ilog2 - log of base 2 of 32-bit or a 64-bit unsigned value - * @n - parameter - * - * constant-capable log of base 2 calculation - * - this can be used to initialise global variables from constant data, hence - * the massive ternary operator construction - * - * selects the appropriately-sized optimised version depending on sizeof(n) - */ -#define ilog2(n) \ -( \ - __builtin_constant_p(n) ? ( \ - (n) < 1 ? ____ilog2_NaN() : \ - (n) & (1ULL << 63) ? 63 : \ - (n) & (1ULL << 62) ? 62 : \ - (n) & (1ULL << 61) ? 61 : \ - (n) & (1ULL << 60) ? 60 : \ - (n) & (1ULL << 59) ? 59 : \ - (n) & (1ULL << 58) ? 58 : \ - (n) & (1ULL << 57) ? 57 : \ - (n) & (1ULL << 56) ? 56 : \ - (n) & (1ULL << 55) ? 55 : \ - (n) & (1ULL << 54) ? 54 : \ - (n) & (1ULL << 53) ? 53 : \ - (n) & (1ULL << 52) ? 52 : \ - (n) & (1ULL << 51) ? 51 : \ - (n) & (1ULL << 50) ? 50 : \ - (n) & (1ULL << 49) ? 49 : \ - (n) & (1ULL << 48) ? 48 : \ - (n) & (1ULL << 47) ? 47 : \ - (n) & (1ULL << 46) ? 46 : \ - (n) & (1ULL << 45) ? 45 : \ - (n) & (1ULL << 44) ? 44 : \ - (n) & (1ULL << 43) ? 43 : \ - (n) & (1ULL << 42) ? 42 : \ - (n) & (1ULL << 41) ? 41 : \ - (n) & (1ULL << 40) ? 40 : \ - (n) & (1ULL << 39) ? 39 : \ - (n) & (1ULL << 38) ? 38 : \ - (n) & (1ULL << 37) ? 37 : \ - (n) & (1ULL << 36) ? 36 : \ - (n) & (1ULL << 35) ? 35 : \ - (n) & (1ULL << 34) ? 34 : \ - (n) & (1ULL << 33) ? 33 : \ - (n) & (1ULL << 32) ? 32 : \ - (n) & (1ULL << 31) ? 31 : \ - (n) & (1ULL << 30) ? 30 : \ - (n) & (1ULL << 29) ? 29 : \ - (n) & (1ULL << 28) ? 28 : \ - (n) & (1ULL << 27) ? 27 : \ - (n) & (1ULL << 26) ? 26 : \ - (n) & (1ULL << 25) ? 25 : \ - (n) & (1ULL << 24) ? 24 : \ - (n) & (1ULL << 23) ? 23 : \ - (n) & (1ULL << 22) ? 22 : \ - (n) & (1ULL << 21) ? 21 : \ - (n) & (1ULL << 20) ? 20 : \ - (n) & (1ULL << 19) ? 19 : \ - (n) & (1ULL << 18) ? 18 : \ - (n) & (1ULL << 17) ? 17 : \ - (n) & (1ULL << 16) ? 16 : \ - (n) & (1ULL << 15) ? 15 : \ - (n) & (1ULL << 14) ? 14 : \ - (n) & (1ULL << 13) ? 13 : \ - (n) & (1ULL << 12) ? 12 : \ - (n) & (1ULL << 11) ? 11 : \ - (n) & (1ULL << 10) ? 10 : \ - (n) & (1ULL << 9) ? 9 : \ - (n) & (1ULL << 8) ? 8 : \ - (n) & (1ULL << 7) ? 7 : \ - (n) & (1ULL << 6) ? 6 : \ - (n) & (1ULL << 5) ? 5 : \ - (n) & (1ULL << 4) ? 4 : \ - (n) & (1ULL << 3) ? 3 : \ - (n) & (1ULL << 2) ? 2 : \ - (n) & (1ULL << 1) ? 1 : \ - (n) & (1ULL << 0) ? 0 : \ - ____ilog2_NaN() \ - ) : \ - (sizeof(n) <= 4) ? \ - __ilog2_u32(n) : \ - __ilog2_u64(n) \ - ) - -/** - * roundup_pow_of_two - round the given value up to nearest power of two - * @n - parameter - * - * round the given balue up to the nearest power of two - * - the result is undefined when n == 0 - * - this can be used to initialise global variables from constant data - */ -#define roundup_pow_of_two(n) \ -( \ - __builtin_constant_p(n) ? ( \ - (n == 1) ? 0 : \ - (1UL << (ilog2((n) - 1) + 1)) \ - ) : \ - __roundup_pow_of_two(n) \ - ) - -#endif /* _LINUX_LOG2_H */ - #endif diff --git a/datapath/linux-2.6/compat-2.6/include/linux/mutex.h b/datapath/linux-2.6/compat-2.6/include/linux/mutex.h index cb5b2738..93dfa3b2 100644 --- a/datapath/linux-2.6/compat-2.6/include/linux/mutex.h +++ b/datapath/linux-2.6/compat-2.6/include/linux/mutex.h @@ -11,7 +11,7 @@ struct mutex { struct semaphore sema; }; -#define mutex_init(mutex) init_MUTEX(&mutex->sema) +#define mutex_init(mutex) init_MUTEX(&(mutex)->sema) #define mutex_destroy(mutex) do { } while (0) #define __MUTEX_INITIALIZER(name) \ diff --git a/datapath/linux-2.6/compat-2.6/include/linux/skbuff.h b/datapath/linux-2.6/compat-2.6/include/linux/skbuff.h index 55d32eb1..666ef850 100644 --- a/datapath/linux-2.6/compat-2.6/include/linux/skbuff.h +++ b/datapath/linux-2.6/compat-2.6/include/linux/skbuff.h @@ -23,6 +23,24 @@ static inline void skb_copy_to_linear_data_offset(struct sk_buff *skb, #endif /* !HAVE_SKB_COPY_FROM_LINEAR_DATA_OFFSET */ +/* + * The networking layer reserves some headroom in skb data (via + * dev_alloc_skb). This is used to avoid having to reallocate skb data when + * the header has to grow. In the default case, if the header has to grow + * 16 bytes or less we avoid the reallocation. + * + * Unfortunately this headroom changes the DMA alignment of the resulting + * network packet. As for NET_IP_ALIGN, this unaligned DMA is expensive + * on some architectures. An architecture can override this value, + * perhaps setting it to a cacheline in size (since that will maintain + * cacheline alignment of the DMA). It must be a power of 2. + * + * Various parts of the networking layer expect at least 16 bytes of + * headroom, you should not reduce this. + */ +#ifndef NET_SKB_PAD +#define NET_SKB_PAD 16 +#endif #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) static inline int __skb_cow(struct sk_buff *skb, unsigned int headroom, @@ -134,4 +152,19 @@ static inline void skb_copy_to_linear_data(struct sk_buff *skb, } #endif /* !HAVE_SKBUFF_HEADER_HELPERS */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18) +#warning "TSO/UFO not supported on kernels earlier than 2.6.18" + +static inline int skb_is_gso(const struct sk_buff *skb) +{ + return 0; +} + +static inline struct sk_buff *skb_gso_segment(struct sk_buff *skb, + int features) +{ + return NULL; +} +#endif /* before 2.6.18 */ + #endif -- 2.30.2