diff options
author | root <root@artemis.panaceas.org> | 2015-12-25 15:00:15 +0000 |
---|---|---|
committer | root <root@artemis.panaceas.org> | 2015-12-25 15:00:15 +0000 |
commit | ddd86436f4e3643c04b797f858dab95d5f2e4de9 (patch) | |
tree | bfe7a780cf9a2f4fc33aec32c82e625e79dece1f /backport-include | |
download | backports-3.10.19-1-master.tar.gz backports-3.10.19-1-master.tar.bz2 backports-3.10.19-1-master.zip |
Diffstat (limited to 'backport-include')
153 files changed, 10873 insertions, 0 deletions
diff --git a/backport-include/asm-generic/bug.h b/backport-include/asm-generic/bug.h new file mode 100644 index 0000000..4e9e05f --- /dev/null +++ b/backport-include/asm-generic/bug.h @@ -0,0 +1,39 @@ +#ifndef __BACKPORT_ASM_GENERIC_BUG_H +#define __BACKPORT_ASM_GENERIC_BUG_H +#include_next <asm-generic/bug.h> + +#ifndef __WARN +#define __WARN(foo) dump_stack() +#endif + +#ifndef WARN_ONCE +#define WARN_ONCE(condition, format...) ({ \ + static int __warned; \ + int __ret_warn_once = !!(condition); \ + \ + if (unlikely(__ret_warn_once)) \ + if (WARN(!__warned, format)) \ + __warned = 1; \ + unlikely(__ret_warn_once); \ +}) +#endif + +#ifndef __WARN_printf +/* + * To port this properly we'd have to port warn_slowpath_null(), + * which I'm lazy to do so just do a regular print for now. If you + * want to port this read kernel/panic.c + */ +#define __WARN_printf(arg...) do { printk(arg); __WARN(); } while (0) +#endif + +#ifndef WARN +#define WARN(condition, format...) ({ \ + int __ret_warn_on = !!(condition); \ + if (unlikely(__ret_warn_on)) \ + __WARN_printf(format); \ + unlikely(__ret_warn_on); \ +}) +#endif + +#endif /* __BACKPORT_ASM_GENERIC_BUG_H */ diff --git a/backport-include/asm-generic/pci-dma-compat.h b/backport-include/asm-generic/pci-dma-compat.h new file mode 100644 index 0000000..aa61f4d --- /dev/null +++ b/backport-include/asm-generic/pci-dma-compat.h @@ -0,0 +1,17 @@ +#ifndef __BACKPORT_ASM_PCI_DMA_COMPAT_H +#define __BACKPORT_ASM_PCI_DMA_COMPAT_H +#include_next <asm-generic/pci-dma-compat.h> +#include <linux/version.h> + + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) +#include <backport/magic.h> + +#define pci_dma_mapping_error1(dma_addr) dma_mapping_error1(dma_addr) +#define pci_dma_mapping_error2(pdev, dma_addr) dma_mapping_error2(pdev, dma_addr) +#undef pci_dma_mapping_error +#define pci_dma_mapping_error(...) \ + macro_dispatcher(pci_dma_mapping_error, __VA_ARGS__)(__VA_ARGS__) +#endif + +#endif /* __BACKPORT_ASM_PCI_DMA_COMPAT_H */ diff --git a/backport-include/asm/atomic.h b/backport-include/asm/atomic.h new file mode 100644 index 0000000..cabdcfd --- /dev/null +++ b/backport-include/asm/atomic.h @@ -0,0 +1,37 @@ +#ifndef __BACKPORT_ASM_ATOMIC_H +#define __BACKPORT_ASM_ATOMIC_H +#include_next <asm/atomic.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0) +/* + * In many versions, several architectures do not seem to include an + * atomic64_t implementation, and do not include the software emulation from + * asm-generic/atomic64_t. + * Detect and handle this here. + */ +#include <asm/atomic.h> + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31)) && !defined(ATOMIC64_INIT) && !defined(CONFIG_X86) && !((LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33)) && defined(CONFIG_ARM) && !defined(CONFIG_GENERIC_ATOMIC64)) +#include <asm-generic/atomic64.h> +#endif +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31) +#ifndef CONFIG_64BIT + +typedef struct { + long long counter; +} atomic64_t; + +#define atomic64_read LINUX_BACKPORT(atomic64_read) +extern long long atomic64_read(const atomic64_t *v); +#define atomic64_add_return LINUX_BACKPORT(atomic64_add_return) +extern long long atomic64_add_return(long long a, atomic64_t *v); + +#define atomic64_inc_return(v) atomic64_add_return(1LL, (v)) + +#endif +#endif + +#endif /* __BACKPORT_ASM_ATOMIC_H */ diff --git a/backport-include/asm/dma-mapping.h b/backport-include/asm/dma-mapping.h new file mode 100644 index 0000000..844fe3b --- /dev/null +++ b/backport-include/asm/dma-mapping.h @@ -0,0 +1,27 @@ +#ifndef __BACKPORT_ASM_DMA_MAPPING_H +#define __BACKPORT_ASM_DMA_MAPPING_H +#include_next <asm/dma-mapping.h> +#include <linux/version.h> + +#if defined(CPTCFG_BACKPORT_BUILD_DMA_SHARED_HELPERS) +#define dma_common_get_sgtable LINUX_BACKPORT(dma_common_get_sgtable) +int +dma_common_get_sgtable(struct device *dev, struct sg_table *sgt, + void *cpu_addr, dma_addr_t dma_addr, size_t size); +#endif /* defined(CPTCFG_BACKPORT_BUILD_DMA_SHARED_HELPERS) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0) + +#define dma_get_sgtable_attrs LINUX_BACKPORT(dma_get_sgtable_attrs) +struct dma_attrs; +static inline int +dma_get_sgtable_attrs(struct device *dev, struct sg_table *sgt, void *cpu_addr, + dma_addr_t dma_addr, size_t size, struct dma_attrs *attrs) +{ + return dma_common_get_sgtable(dev, sgt, cpu_addr, dma_addr, size); +} + +#define dma_get_sgtable(d, t, v, h, s) dma_get_sgtable_attrs(d, t, v, h, s, NULL) +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0) */ + +#endif /* __BACKPORT_ASM_DMA_MAPPING_H */ diff --git a/backport-include/asm/errno.h b/backport-include/asm/errno.h new file mode 100644 index 0000000..0a730b7 --- /dev/null +++ b/backport-include/asm/errno.h @@ -0,0 +1,23 @@ +#ifndef __BACKPORT_ASM_ERRNO_H +#define __BACKPORT_ASM_ERRNO_H +#include_next <asm/errno.h> + +#ifndef ERFKILL +#if !defined(CONFIG_ALPHA) && !defined(CONFIG_MIPS) && !defined(CONFIG_PARISC) && !defined(CONFIG_SPARC) +#define ERFKILL 132 /* Operation not possible due to RF-kill */ +#endif +#ifdef CONFIG_ALPHA +#define ERFKILL 138 /* Operation not possible due to RF-kill */ +#endif +#ifdef CONFIG_MIPS +#define ERFKILL 167 /* Operation not possible due to RF-kill */ +#endif +#ifdef CONFIG_PARISC +#define ERFKILL 256 /* Operation not possible due to RF-kill */ +#endif +#ifdef CONFIG_SPARC +#define ERFKILL 134 /* Operation not possible due to RF-kill */ +#endif +#endif + +#endif /* __BACKPORT_ASM_ERRNO_H */ diff --git a/backport-include/asm/ioctls.h b/backport-include/asm/ioctls.h new file mode 100644 index 0000000..72c2f0a --- /dev/null +++ b/backport-include/asm/ioctls.h @@ -0,0 +1,9 @@ +#ifndef __BACKPORT_ASM_IOCTLS_H +#define __BACKPORT_ASM_IOCTLS_H +#include_next <asm/ioctls.h> + +#ifndef TIOCPKT_IOCTL +#define TIOCPKT_IOCTL 64 +#endif + +#endif /* __BACKPORT_ASM_IOCTLS_H */ diff --git a/backport-include/asm/unaligned.h b/backport-include/asm/unaligned.h new file mode 100644 index 0000000..7f552b8 --- /dev/null +++ b/backport-include/asm/unaligned.h @@ -0,0 +1,213 @@ +#ifndef __BACKPORT_ASM_UNALIGNED_H +#define __BACKPORT_ASM_UNALIGNED_H +#include_next <asm/unaligned.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) +/* + * 2.6.26 added its own unaligned API which the + * new drivers can use. Lets port it here by including it in older + * kernels and also deal with the architecture handling here. + */ +#ifdef CONFIG_ALPHA + +#include <linux/unaligned/be_struct.h> +#include <linux/unaligned/le_byteshift.h> +#include <linux/unaligned/generic.h> + +#endif /* alpha */ +#ifdef CONFIG_ARM + +/* arm */ +#include <linux/unaligned/le_byteshift.h> +#include <linux/unaligned/be_byteshift.h> +#include <linux/unaligned/generic.h> + +#endif /* arm */ +#ifdef CONFIG_AVR32 + +/* + * AVR32 can handle some unaligned accesses, depending on the + * implementation. The AVR32 AP implementation can handle unaligned + * words, but halfwords must be halfword-aligned, and doublewords must + * be word-aligned. + * + * However, swapped word loads must be word-aligned so we can't + * optimize word loads in general. + */ + +#include <linux/unaligned/be_struct.h> +#include <linux/unaligned/le_byteshift.h> +#include <linux/unaligned/generic.h> + +#endif +#ifdef CONFIG_BLACKFIN + +#include <linux/unaligned/le_struct.h> +#include <linux/unaligned/be_byteshift.h> +#include <linux/unaligned/generic.h> + +#endif /* blackfin */ +#ifdef CONFIG_CRIS + +/* + * CRIS can do unaligned accesses itself. + */ +#include <linux/unaligned/access_ok.h> +#include <linux/unaligned/generic.h> + +#endif /* cris */ +#ifdef CONFIG_FRV + +#include <linux/unaligned/le_byteshift.h> +#include <linux/unaligned/be_byteshift.h> +#include <linux/unaligned/generic.h> + +#endif /* frv */ +#ifdef CONFIG_H8300 + +#include <linux/unaligned/be_memmove.h> +#include <linux/unaligned/le_byteshift.h> +#include <linux/unaligned/generic.h> + +#endif /* h8300 */ +#ifdef CONFIG_IA64 + +#include <linux/unaligned/le_struct.h> +#include <linux/unaligned/be_byteshift.h> +#include <linux/unaligned/generic.h> + +#endif /* ia64 */ +#ifdef CONFIG_M32R + +#if defined(__LITTLE_ENDIAN__) +# include <linux/unaligned/le_memmove.h> +# include <linux/unaligned/be_byteshift.h> +# include <linux/unaligned/generic.h> +#else +# include <linux/unaligned/be_memmove.h> +# include <linux/unaligned/le_byteshift.h> +# include <linux/unaligned/generic.h> +#endif + +#endif /* m32r */ +#ifdef CONFIG_M68K /* this handles both m68k and m68knommu */ + +#ifdef CONFIG_COLDFIRE +#include <linux/unaligned/be_struct.h> +#include <linux/unaligned/le_byteshift.h> +#include <linux/unaligned/generic.h> +#else + +/* + * The m68k can do unaligned accesses itself. + */ +#include <linux/unaligned/access_ok.h> +#include <linux/unaligned/generic.h> +#endif + +#endif /* m68k and m68knommu */ +#ifdef CONFIG_MIPS + +#if defined(__MIPSEB__) +# include <linux/unaligned/be_struct.h> +# include <linux/unaligned/le_byteshift.h> +# include <linux/unaligned/generic.h> +# define get_unaligned __get_unaligned_be +# define put_unaligned __put_unaligned_be +#elif defined(__MIPSEL__) +# include <linux/unaligned/le_struct.h> +# include <linux/unaligned/be_byteshift.h> +# include <linux/unaligned/generic.h> +#endif + +#endif /* mips */ +#ifdef CONFIG_MN10300 + +#include <linux/unaligned/access_ok.h> +#include <linux/unaligned/generic.h> + +#endif /* mn10300 */ +#ifdef CONFIG_PARISC + +#include <linux/unaligned/be_struct.h> +#include <linux/unaligned/le_byteshift.h> +#include <linux/unaligned/generic.h> + +#endif /* parisc */ +#ifdef CONFIG_PPC +/* + * The PowerPC can do unaligned accesses itself in big endian mode. + */ +#include <linux/unaligned/access_ok.h> +#include <linux/unaligned/generic.h> + +#endif /* ppc */ +#ifdef CONFIG_S390 + +/* + * The S390 can do unaligned accesses itself. + */ +#include <linux/unaligned/access_ok.h> +#include <linux/unaligned/generic.h> + +#endif /* s390 */ +#ifdef CONFIG_SUPERH + +/* SH can't handle unaligned accesses. */ +#ifdef __LITTLE_ENDIAN__ +# include <linux/unaligned/le_struct.h> +# include <linux/unaligned/be_byteshift.h> +# include <linux/unaligned/generic.h> +#else +# include <linux/unaligned/be_struct.h> +# include <linux/unaligned/le_byteshift.h> +# include <linux/unaligned/generic.h> +#endif + +#endif /* sh - SUPERH */ +#ifdef CONFIG_SPARC + +/* sparc and sparc64 */ +#include <linux/unaligned/be_struct.h> +#include <linux/unaligned/le_byteshift.h> +#include <linux/unaligned/generic.h> + +#endif /* sparc */ +#ifdef CONFIG_UML + +#include "asm/arch/unaligned.h" + +#endif /* um - uml */ +#ifdef CONFIG_V850 + +#include <linux/unaligned/be_byteshift.h> +#include <linux/unaligned/le_byteshift.h> +#include <linux/unaligned/generic.h> + +#endif /* v850 */ +#ifdef CONFIG_X86 +/* + * The x86 can do unaligned accesses itself. + */ +#include <linux/unaligned/access_ok.h> +#include <linux/unaligned/generic.h> + +#endif /* x86 */ +#ifdef CONFIG_XTENSA + +#ifdef __XTENSA_EL__ +# include <linux/unaligned/le_memmove.h> +# include <linux/unaligned/be_byteshift.h> +# include <linux/unaligned/generic.h> +#elif defined(__XTENSA_EB__) +# include <linux/unaligned/be_memmove.h> +# include <linux/unaligned/le_byteshift.h> +# include <linux/unaligned/generic.h> +#else +# error processor byte order undefined! +#endif + +#endif /* xtensa */ +#endif /* < 2.6.26 */ + +#endif /* __BACKPORT_ASM_UNALIGNED_H */ diff --git a/backport-include/backport/backport.h b/backport-include/backport/backport.h new file mode 100644 index 0000000..7cf21aa --- /dev/null +++ b/backport-include/backport/backport.h @@ -0,0 +1,11 @@ +#ifndef __BACKPORT_H +#define __BACKPORT_H +#include <backport/autoconf.h> +#include <linux/kconfig.h> + +#ifndef __ASSEMBLY__ +#define LINUX_BACKPORT(__sym) backport_ ##__sym +#include <backport/checks.h> +#endif + +#endif /* __BACKPORT_H */ diff --git a/backport-include/backport/checks.h b/backport-include/backport/checks.h new file mode 100644 index 0000000..0633459 --- /dev/null +++ b/backport-include/backport/checks.h @@ -0,0 +1,16 @@ +#ifndef __BACKPORT_CHECKS +#define __BACKPORT_CHECKS + +#if defined(CPTCFG_BACKPORT_KERNEL_2_6_28) && defined(CONFIG_DYNAMIC_FTRACE) +#error "You can't build on a 2.6.27 or older kernel with dynamic ftrace, it's broken" +#endif + +#if defined(CPTCFG_MAC80211) && defined(CPTCFG_MAC80211) +#error "You must not have mac80211 built into your kernel if you want to enable it" +#endif + +#if defined(CPTCFG_CFG80211) && defined(CPTCFG_CFG80211) +#error "You must not have cfg80211 built into your kernel if you want to enable it" +#endif + +#endif /* __BACKPORT_CHECKS */ diff --git a/backport-include/backport/leds-disabled.h b/backport-include/backport/leds-disabled.h new file mode 100644 index 0000000..1a9abec --- /dev/null +++ b/backport-include/backport/leds-disabled.h @@ -0,0 +1,155 @@ +#ifndef __BACKPORT_LED_DISABLED_SUPPORT +#define __BACKPORT_LED_DISABLED_SUPPORT + +/* + * LED support is strange, with the NEW_LEDS, LEDS_CLASS and LEDS_TRIGGERS + * Kconfig symbols ... If any of them are not defined, we build our + * "compatibility" code that really just makes it all non-working but + * allows compilation. + */ + +#ifdef CPTCFG_BACKPORT_BUILD_LEDS +#include <linux/list.h> +#include <linux/spinlock.h> +#include <linux/rwsem.h> +#include <linux/workqueue.h> + +#define led_classdev LINUX_BACKPORT(led_classdev) +#define led_trigger LINUX_BACKPORT(led_trigger) + +struct led_classdev { + const char *name; + int brightness; + int max_brightness; + int flags; + + /* Lower 16 bits reflect status */ +#ifndef LED_SUSPENDED +#define LED_SUSPENDED (1 << 0) + /* Upper 16 bits reflect control information */ +#define LED_CORE_SUSPENDRESUME (1 << 16) +#define LED_BLINK_ONESHOT (1 << 17) +#define LED_BLINK_ONESHOT_STOP (1 << 18) +#define LED_BLINK_INVERT (1 << 19) +#endif + + /* Set LED brightness level */ + /* Must not sleep, use a workqueue if needed */ + void (*brightness_set)(struct led_classdev *led_cdev, + enum led_brightness brightness); + /* Get LED brightness level */ + enum led_brightness (*brightness_get)(struct led_classdev *led_cdev); + + /* + * Activate hardware accelerated blink, delays are in milliseconds + * and if both are zero then a sensible default should be chosen. + * The call should adjust the timings in that case and if it can't + * match the values specified exactly. + * Deactivate blinking again when the brightness is set to a fixed + * value via the brightness_set() callback. + */ + int (*blink_set)(struct led_classdev *led_cdev, + unsigned long *delay_on, + unsigned long *delay_off); + + struct device *dev; + struct list_head node; /* LED Device list */ + const char *default_trigger; /* Trigger to use */ + + unsigned long blink_delay_on, blink_delay_off; + struct timer_list blink_timer; + int blink_brightness; + + struct work_struct set_brightness_work; + int delayed_set_value; + + /* Protects the trigger data below */ + struct rw_semaphore trigger_lock; + + struct led_trigger *trigger; + struct list_head trig_list; + void *trigger_data; + /* true if activated - deactivate routine uses it to do cleanup */ + bool activated; +}; + +struct led_trigger { + const char *name; + void (*activate)(struct led_classdev *led_cdev); + void (*deactivate)(struct led_classdev *led_cdev); + rwlock_t leddev_list_lock; + struct list_head led_cdevs; + struct list_head next_trig; +}; + +#undef led_classdev_register +#define led_classdev_register LINUX_BACKPORT(led_classdev_register) +#undef led_classdev_unregister +#define led_classdev_unregister LINUX_BACKPORT(led_classdev_unregister) +#undef led_blink_set +#define led_blink_set LINUX_BACKPORT(led_blink_set) +#undef led_set_brightness +#define led_set_brightness LINUX_BACKPORT(led_set_brightness) +#undef led_classdev_suspend +#define led_classdev_suspend LINUX_BACKPORT(led_classdev_suspend) +#undef led_classdev_resume +#define led_classdev_resume LINUX_BACKPORT(led_classdev_resume) + +#undef led_trigger_register +#define led_trigger_register LINUX_BACKPORT(led_trigger_register) +#undef led_trigger_unregister +#define led_trigger_unregister LINUX_BACKPORT(led_trigger_unregister) +#undef led_trigger_event +#define led_trigger_event LINUX_BACKPORT(led_trigger_event) + +#undef DEFINE_LED_TRIGGER +#define DEFINE_LED_TRIGGER(x) static struct led_trigger *x; + +static inline int led_classdev_register(struct device *parent, + struct led_classdev *led_cdev) +{ + return 0; +} + +static inline void led_classdev_unregister(struct led_classdev *led_cdev) +{ +} + +static inline void led_blink_set(struct led_classdev *led_cdev, + unsigned long *delay_on, + unsigned long *delay_off) +{ +} + +static inline void led_set_brightness(struct led_classdev *led_cdev, + enum led_brightness brightness) +{ +} + +static inline void led_classdev_suspend(struct led_classdev *led_cdev) +{ +} + +static inline void led_classdev_resume(struct led_classdev *led_cdev) +{ +} + +static inline int led_trigger_register(struct led_trigger *trigger) +{ + INIT_LIST_HEAD(&trigger->led_cdevs); + INIT_LIST_HEAD(&trigger->next_trig); + rwlock_init(&trigger->leddev_list_lock); + return 0; +} + +static inline void led_trigger_unregister(struct led_trigger *trigger) +{ +} + +static inline void led_trigger_event(struct led_trigger *trigger, + enum led_brightness event) +{ +} +#endif + +#endif /* __BACKPORT_LED_DISABLED_SUPPORT */ diff --git a/backport-include/backport/magic.h b/backport-include/backport/magic.h new file mode 100644 index 0000000..222e025 --- /dev/null +++ b/backport-include/backport/magic.h @@ -0,0 +1,16 @@ +/* + * These tricks are taken from + * http://efesx.com/2010/07/17/variadic-macro-to-count-number-of-arguments/ + * and + * http://efesx.com/2010/08/31/overloading-macros/ + */ + +#define VA_NUM_ARGS(...) VA_NUM_ARGS_IMPL(__VA_ARGS__, 5,4,3,2,1) +#define VA_NUM_ARGS_IMPL(_1,_2,_3,_4,_5,N,...) N + +#define macro_dispatcher(func, ...) \ + macro_dispatcher_(func, VA_NUM_ARGS(__VA_ARGS__)) +#define macro_dispatcher_(func, nargs) \ + macro_dispatcher__(func, nargs) +#define macro_dispatcher__(func, nargs) \ + func ## nargs diff --git a/backport-include/crypto/aes.h b/backport-include/crypto/aes.h new file mode 100644 index 0000000..8031a54 --- /dev/null +++ b/backport-include/crypto/aes.h @@ -0,0 +1,21 @@ +#ifndef _COMPAT_CRYPTO_AES_H +#define _COMPAT_CRYPTO_AES_H + +#include <linux/version.h> + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,24)) +#include_next <crypto/aes.h> +#else + +#define AES_MIN_KEY_SIZE 16 +#define AES_MAX_KEY_SIZE 32 +#define AES_KEYSIZE_128 16 +#define AES_KEYSIZE_192 24 +#define AES_KEYSIZE_256 32 +#define AES_BLOCK_SIZE 16 +#define AES_MAX_KEYLENGTH (15 * 16) +#define AES_MAX_KEYLENGTH_U32 (AES_MAX_KEYLENGTH / sizeof(u32)) + +#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,24)) */ + +#endif diff --git a/backport-include/linux/atomic.h b/backport-include/linux/atomic.h new file mode 100644 index 0000000..378b748 --- /dev/null +++ b/backport-include/linux/atomic.h @@ -0,0 +1,46 @@ +#ifndef _COMPAT_LINUX_ATOMIC_H +#define _COMPAT_LINUX_ATOMIC_H 1 + +#include <linux/version.h> + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,36)) +#include_next <linux/atomic.h> +#else + +#include <asm/atomic.h> + +/** + * atomic_inc_not_zero_hint - increment if not null + * @v: pointer of type atomic_t + * @hint: probable value of the atomic before the increment + * + * This version of atomic_inc_not_zero() gives a hint of probable + * value of the atomic. This helps processor to not read the memory + * before doing the atomic read/modify/write cycle, lowering + * number of bus transactions on some arches. + * + * Returns: 0 if increment was not done, 1 otherwise. + */ +#ifndef atomic_inc_not_zero_hint +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint) +{ + int val, c = hint; + + /* sanity test, should be removed by compiler if hint is a constant */ + if (!hint) + return atomic_inc_not_zero(v); + + do { + val = atomic_cmpxchg(v, c, c + 1); + if (val == c) + return 1; + c = val; + } while (c); + + return 0; +} +#endif + +#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,36)) */ + +#endif /* _COMPAT_LINUX_ATOMIC_H */ diff --git a/backport-include/linux/bitops.h b/backport-include/linux/bitops.h new file mode 100644 index 0000000..aa76af1 --- /dev/null +++ b/backport-include/linux/bitops.h @@ -0,0 +1,211 @@ +#ifndef _LINUX_BITOPS_H +#define _LINUX_BITOPS_H +#include <asm/types.h> + +#ifdef __KERNEL__ +#define BIT(nr) (1UL << (nr)) +#define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) +#define BIT_WORD(nr) ((nr) / BITS_PER_LONG) +#define BITS_PER_BYTE 8 +#ifndef BITS_TO_LONGS /* Older kernels define this already */ +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long)) +#endif +#endif + +extern unsigned int __sw_hweight8(unsigned int w); +extern unsigned int __sw_hweight16(unsigned int w); +extern unsigned int __sw_hweight32(unsigned int w); +extern unsigned long __sw_hweight64(__u64 w); + +/* + * Include this here because some architectures need generic_ffs/fls in + * scope + */ +#include <asm/bitops.h> + +#define for_each_set_bit(bit, addr, size) \ + for ((bit) = find_first_bit((addr), (size)); \ + (bit) < (size); \ + (bit) = find_next_bit((addr), (size), (bit) + 1)) + +static __inline__ int get_bitmask_order(unsigned int count) +{ + int order; + + order = fls(count); + return order; /* We could be slightly more clever with -1 here... */ +} + +static __inline__ int get_count_order(unsigned int count) +{ + int order; + + order = fls(count) - 1; + if (count & (count - 1)) + order++; + return order; +} + +static inline unsigned long hweight_long(unsigned long w) +{ + return sizeof(w) == 4 ? hweight32(w) : hweight64(w); +} + +/** + * rol32 - rotate a 32-bit value left + * @word: value to rotate + * @shift: bits to roll + */ +static inline __u32 rol32(__u32 word, unsigned int shift) +{ + return (word << shift) | (word >> (32 - shift)); +} + +/** + * ror32 - rotate a 32-bit value right + * @word: value to rotate + * @shift: bits to roll + */ +static inline __u32 ror32(__u32 word, unsigned int shift) +{ + return (word >> shift) | (word << (32 - shift)); +} + +/** + * rol16 - rotate a 16-bit value left + * @word: value to rotate + * @shift: bits to roll + */ +static inline __u16 rol16(__u16 word, unsigned int shift) +{ + return (word << shift) | (word >> (16 - shift)); +} + +/** + * ror16 - rotate a 16-bit value right + * @word: value to rotate + * @shift: bits to roll + */ +static inline __u16 ror16(__u16 word, unsigned int shift) +{ + return (word >> shift) | (word << (16 - shift)); +} + +/** + * rol8 - rotate an 8-bit value left + * @word: value to rotate + * @shift: bits to roll + */ +static inline __u8 rol8(__u8 word, unsigned int shift) +{ + return (word << shift) | (word >> (8 - shift)); +} + +/** + * ror8 - rotate an 8-bit value right + * @word: value to rotate + * @shift: bits to roll + */ +static inline __u8 ror8(__u8 word, unsigned int shift) +{ + return (word >> shift) | (word << (8 - shift)); +} + +/** + * sign_extend32 - sign extend a 32-bit value using specified bit as sign-bit + * @value: value to sign extend + * @index: 0 based bit index (0<=index<32) to sign bit + */ +static inline __s32 sign_extend32(__u32 value, int index) +{ + __u8 shift = 31 - index; + return (__s32)(value << shift) >> shift; +} + +static inline unsigned fls_long(unsigned long l) +{ + if (sizeof(l) == 4) + return fls(l); + return fls64(l); +} + +/** + * __ffs64 - find first set bit in a 64 bit word + * @word: The 64 bit word + * + * On 64 bit arches this is a synomyn for __ffs + * The result is not defined if no bits are set, so check that @word + * is non-zero before calling this. + */ +static inline unsigned long __ffs64(u64 word) +{ +#if BITS_PER_LONG == 32 + if (((u32)word) == 0UL) + return __ffs((u32)(word >> 32)) + 32; +#elif BITS_PER_LONG != 64 +#error BITS_PER_LONG not 32 or 64 +#endif + return __ffs((unsigned long)word); +} + +#ifdef __KERNEL__ +#ifdef CONFIG_GENERIC_FIND_FIRST_BIT + +/** + * find_first_bit - find the first set bit in a memory region + * @addr: The address to start the search at + * @size: The maximum size to search + * + * Returns the bit number of the first set bit. + */ +extern unsigned long find_first_bit(const unsigned long *addr, + unsigned long size); + +/** + * find_first_zero_bit - find the first cleared bit in a memory region + * @addr: The address to start the search at + * @size: The maximum size to search + * + * Returns the bit number of the first cleared bit. + */ +extern unsigned long find_first_zero_bit(const unsigned long *addr, + unsigned long size); +#endif /* CONFIG_GENERIC_FIND_FIRST_BIT */ + +#ifdef CONFIG_GENERIC_FIND_LAST_BIT +/** + * find_last_bit - find the last set bit in a memory region + * @addr: The address to start the search at + * @size: The maximum size to search + * + * Returns the bit number of the first set bit, or size. + */ +extern unsigned long find_last_bit(const unsigned long *addr, + unsigned long size); +#endif /* CONFIG_GENERIC_FIND_LAST_BIT */ + +#ifdef CONFIG_GENERIC_FIND_NEXT_BIT + +/** + * find_next_bit - find the next set bit in a memory region + * @addr: The address to base the search on + * @offset: The bitnumber to start searching at + * @size: The bitmap size in bits + */ +extern unsigned long find_next_bit(const unsigned long *addr, + unsigned long size, unsigned long offset); + +/** + * find_next_zero_bit - find the next cleared bit in a memory region + * @addr: The address to base the search on + * @offset: The bitnumber to start searching at + * @size: The bitmap size in bits + */ + +extern unsigned long find_next_zero_bit(const unsigned long *addr, + unsigned long size, + unsigned long offset); + +#endif /* CONFIG_GENERIC_FIND_NEXT_BIT */ +#endif /* __KERNEL__ */ +#endif diff --git a/backport-include/linux/bug.h b/backport-include/linux/bug.h new file mode 100644 index 0000000..22c91aa --- /dev/null +++ b/backport-include/linux/bug.h @@ -0,0 +1,45 @@ +#ifndef __BACKPORT_LINUX_BUG_H +#define __BACKPORT_LINUX_BUG_H +#include_next <linux/bug.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) +/* is defined there for older kernels */ +#include <linux/kernel.h> +/* Backport of: + * + * commit 7ef88ad561457c0346355dfd1f53e503ddfde719 + * Author: Rusty Russell <rusty@rustcorp.com.au> + * Date: Mon Jan 24 14:45:10 2011 -0600 + * + * BUILD_BUG_ON: make it handle more cases + */ +#undef BUILD_BUG_ON +/** + * BUILD_BUG_ON - break compile if a condition is true. + * @condition: the condition which the compiler should know is false. + * + * If you have some code which relies on certain constants being equal, or + * other compile-time-evaluated condition, you should use BUILD_BUG_ON to + * detect if someone changes it. + * + * The implementation uses gcc's reluctance to create a negative array, but + * gcc (as of 4.4) only emits that error for obvious cases (eg. not arguments + * to inline functions). So as a fallback we use the optimizer; if it can't + * prove the condition is false, it will cause a link error on the undefined + * "__build_bug_on_failed". This error message can be harder to track down + * though, hence the two different methods. + */ +#ifndef __OPTIMIZE__ +#define BUILD_BUG_ON(condition) ((void)sizeof(char[1 - 2*!!(condition)])) +#else +extern int __build_bug_on_failed; +#define BUILD_BUG_ON(condition) \ + do { \ + ((void)sizeof(char[1 - 2*!!(condition)])); \ + if (condition) __build_bug_on_failed = 1; \ + } while(0) +#endif +#endif /* < 2.6.38 */ + +#endif /* __BACKPORT_LINUX_BUG_H */ diff --git a/backport-include/linux/byteorder/generic.h b/backport-include/linux/byteorder/generic.h new file mode 100644 index 0000000..005a92f --- /dev/null +++ b/backport-include/linux/byteorder/generic.h @@ -0,0 +1,52 @@ +#ifndef __BACKPORT_BYTEORDER_GENERIC_H +#define __BACKPORT_BYTEORDER_GENERIC_H +#include_next <linux/byteorder/generic.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) +/* The patch: + * commit 8b5f6883683c91ad7e1af32b7ceeb604d68e2865 + * Author: Marcin Slusarz <marcin.slusarz@gmail.com> + * Date: Fri Feb 8 04:20:12 2008 -0800 + * + * byteorder: move le32_add_cpu & friends from OCFS2 to core + * + * moves le*_add_cpu and be*_add_cpu functions from OCFS2 to core + * header (1st) and converted some existing code to it. We port + * it here as later kernels will most likely use it. + */ +static inline void le16_add_cpu(__le16 *var, u16 val) +{ + *var = cpu_to_le16(le16_to_cpu(*var) + val); +} + +static inline void le32_add_cpu(__le32 *var, u32 val) +{ + *var = cpu_to_le32(le32_to_cpu(*var) + val); +} + +static inline void le64_add_cpu(__le64 *var, u64 val) +{ + *var = cpu_to_le64(le64_to_cpu(*var) + val); +} + +static inline void be16_add_cpu(__be16 *var, u16 val) +{ + u16 v = be16_to_cpu(*var); + *var = cpu_to_be16(v + val); +} + +static inline void be32_add_cpu(__be32 *var, u32 val) +{ + u32 v = be32_to_cpu(*var); + *var = cpu_to_be32(v + val); +} + +static inline void be64_add_cpu(__be64 *var, u64 val) +{ + u64 v = be64_to_cpu(*var); + *var = cpu_to_be64(v + val); +} +#endif + +#endif /* __BACKPORT_BYTEORDER_GENERIC_H */ diff --git a/backport-include/linux/compat.h b/backport-include/linux/compat.h new file mode 100644 index 0000000..22db9b0 --- /dev/null +++ b/backport-include/linux/compat.h @@ -0,0 +1,16 @@ +#ifndef __BACKPORT_COMPAT_H +#define __BACKPORT_COMPAT_H + +#include_next <linux/compat.h> +#include <linux/version.h> + +#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0)) +#ifdef CONFIG_X86_X32_ABI +#define COMPAT_USE_64BIT_TIME \ + (!!(task_pt_regs(current)->orig_ax & __X32_SYSCALL_BIT)) +#else +#define COMPAT_USE_64BIT_TIME 0 +#endif +#endif + +#endif /* __BACKPORT_COMPAT_H */ diff --git a/backport-include/linux/compiler.h b/backport-include/linux/compiler.h new file mode 100644 index 0000000..0f5dfe4 --- /dev/null +++ b/backport-include/linux/compiler.h @@ -0,0 +1,17 @@ +#ifndef __BACKPORT_LINUX_COMPILER_H +#define __BACKPORT_LINUX_COMPILER_H +#include_next <linux/compiler.h> + +#ifndef __rcu +#define __rcu +#endif + +#ifndef __always_unused +#ifdef __GNUC__ +#define __always_unused __attribute__((unused)) +#else +#define __always_unused /* unimplemented */ +#endif +#endif + +#endif /* __BACKPORT_LINUX_COMPILER_H */ diff --git a/backport-include/linux/cordic.h b/backport-include/linux/cordic.h new file mode 100644 index 0000000..7f27b00 --- /dev/null +++ b/backport-include/linux/cordic.h @@ -0,0 +1,60 @@ +#ifndef _BACKPORT_LINUX_CORDIC_H +#define _BACKPORT_LINUX_CORDIC_H 1 + +#include <linux/version.h> + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(3,1,0)) +#include_next <linux/cordic.h> +#else + +/* + * Copyright (c) 2011 Broadcom Corporation + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#ifndef __CORDIC_H_ +#define __CORDIC_H_ + +#include <linux/types.h> + +/** + * struct cordic_iq - i/q coordinate. + * + * @i: real part of coordinate (in phase). + * @q: imaginary part of coordinate (quadrature). + */ +struct cordic_iq { + s32 i; + s32 q; +}; + +/** + * cordic_calc_iq() - calculates the i/q coordinate for given angle. + * + * @theta: angle in degrees for which i/q coordinate is to be calculated. + * @coord: function output parameter holding the i/q coordinate. + * + * The function calculates the i/q coordinate for a given angle using + * cordic algorithm. The coordinate consists of a real (i) and an + * imaginary (q) part. The real part is essentially the cosine of the + * angle and the imaginary part is the sine of the angle. The returned + * values are scaled by 2^16 for precision. The range for theta is + * for -180 degrees to +180 degrees. Passed values outside this range are + * converted before doing the actual calculation. + */ +#define cordic_calc_iq LINUX_BACKPORT(cordic_calc_iq) +struct cordic_iq cordic_calc_iq(s32 theta); + +#endif /* __CORDIC_H_ */ +#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(3,1,0)) */ +#endif /* _BACKPORT_LINUX_CORDIC_H */ diff --git a/backport-include/linux/cpufreq.h b/backport-include/linux/cpufreq.h new file mode 100644 index 0000000..dbf234d --- /dev/null +++ b/backport-include/linux/cpufreq.h @@ -0,0 +1,13 @@ +#ifndef __BACKPORT_INCLUDE_CPUFREQ_H +#define __BACKPORT_INCLUDE_CPUFREQ_H +#include_next <linux/cpufreq.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0) +#ifdef CONFIG_CPU_FREQ +#define cpufreq_quick_get_max LINUX_BACKPORT(cpufreq_quick_get_max) +unsigned int cpufreq_quick_get_max(unsigned int cpu); +#endif +#endif + +#endif /* __BACKPORT_INCLUDE_CPUFREQ_H */ diff --git a/backport-include/linux/cpumask.h b/backport-include/linux/cpumask.h new file mode 100644 index 0000000..7df3457 --- /dev/null +++ b/backport-include/linux/cpumask.h @@ -0,0 +1,10 @@ +#ifndef __BACKPORT_LINUX_CPUMASK_H +#define __BACKPORT_LINUX_CPUMASK_H +#include_next <linux/cpumask.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) +typedef struct cpumask { DECLARE_BITMAP(bits, NR_CPUS); } compat_cpumask_t; +#endif + +#endif /* __BACKPORT_LINUX_CPUMASK_H */ diff --git a/backport-include/linux/crc8.h b/backport-include/linux/crc8.h new file mode 100644 index 0000000..611ba0d --- /dev/null +++ b/backport-include/linux/crc8.h @@ -0,0 +1,109 @@ +/* + * Copyright (c) 2011 Broadcom Corporation + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ +#ifndef CPTCFG_BACKPORT_BUILD_CRC8_MODULE +#include_next <linux/crc8.h> +#else + +#ifndef __CRC8_H_ +#define __CRC8_H_ + +#include <linux/types.h> + +/* see usage of this value in crc8() description */ +#define CRC8_INIT_VALUE 0xFF + +/* + * Return value of crc8() indicating valid message+crc. This is true + * if a CRC is inverted before transmission. The CRC computed over the + * whole received bitstream is _table[x], where x is the bit pattern + * of the modification (almost always 0xff). + */ +#define CRC8_GOOD_VALUE(_table) (_table[0xFF]) + +/* required table size for crc8 algorithm */ +#define CRC8_TABLE_SIZE 256 + +/* helper macro assuring right table size is used */ +#define DECLARE_CRC8_TABLE(_table) \ + static u8 _table[CRC8_TABLE_SIZE] + +/** + * crc8_populate_lsb - fill crc table for given polynomial in regular bit order. + * + * @table: table to be filled. + * @polynomial: polynomial for which table is to be filled. + * + * This function fills the provided table according the polynomial provided for + * regular bit order (lsb first). Polynomials in CRC algorithms are typically + * represented as shown below. + * + * poly = x^8 + x^7 + x^6 + x^4 + x^2 + 1 + * + * For lsb first direction x^7 maps to the lsb. So the polynomial is as below. + * + * - lsb first: poly = 10101011(1) = 0xAB + */ +#define crc8_populate_lsb LINUX_BACKPORT(crc8_populate_lsb) +void crc8_populate_lsb(u8 table[CRC8_TABLE_SIZE], u8 polynomial); + +/** + * crc8_populate_msb - fill crc table for given polynomial in reverse bit order. + * + * @table: table to be filled. + * @polynomial: polynomial for which table is to be filled. + * + * This function fills the provided table according the polynomial provided for + * reverse bit order (msb first). Polynomials in CRC algorithms are typically + * represented as shown below. + * + * poly = x^8 + x^7 + x^6 + x^4 + x^2 + 1 + * + * For msb first direction x^7 maps to the msb. So the polynomial is as below. + * + * - msb first: poly = (1)11010101 = 0xD5 + */ +#define crc8_populate_msb LINUX_BACKPORT(crc8_populate_msb) +void crc8_populate_msb(u8 table[CRC8_TABLE_SIZE], u8 polynomial); + +/** + * crc8() - calculate a crc8 over the given input data. + * + * @table: crc table used for calculation. + * @pdata: pointer to data buffer. + * @nbytes: number of bytes in data buffer. + * @crc: previous returned crc8 value. + * + * The CRC8 is calculated using the polynomial given in crc8_populate_msb() + * or crc8_populate_lsb(). + * + * The caller provides the initial value (either %CRC8_INIT_VALUE + * or the previous returned value) to allow for processing of + * discontiguous blocks of data. When generating the CRC the + * caller is responsible for complementing the final return value + * and inserting it into the byte stream. When validating a byte + * stream (including CRC8), a final return value of %CRC8_GOOD_VALUE + * indicates the byte stream data can be considered valid. + * + * Reference: + * "A Painless Guide to CRC Error Detection Algorithms", ver 3, Aug 1993 + * Williams, Ross N., ross<at>ross.net + * (see URL http://www.ross.net/crc/download/crc_v3.txt). + */ +#define crc8 LINUX_BACKPORT(crc8) +u8 crc8(const u8 table[CRC8_TABLE_SIZE], u8 *pdata, size_t nbytes, u8 crc); + +#endif /* __CRC8_H_ */ +#endif /* BACKPORT_BUILD_CRC8_MODULE */ diff --git a/backport-include/linux/debugfs.h b/backport-include/linux/debugfs.h new file mode 100644 index 0000000..16604e3 --- /dev/null +++ b/backport-include/linux/debugfs.h @@ -0,0 +1,18 @@ +#ifndef __BACKPORT_LINUX_DEBUGFS_H +#define __BACKPORT_LINUX_DEBUGFS_H +#include_next <linux/debugfs.h> +#include <linux/version.h> + + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) +#define debugfs_remove_recursive LINUX_BACKPORT(debugfs_remove_recursive) + +#if defined(CONFIG_DEBUG_FS) +void debugfs_remove_recursive(struct dentry *dentry); +#else +static inline void debugfs_remove_recursive(struct dentry *dentry) +{ } +#endif +#endif /* < 2.6.27 */ + +#endif /* __BACKPORT_LINUX_DEBUGFS_H */ diff --git a/backport-include/linux/delay.h b/backport-include/linux/delay.h new file mode 100644 index 0000000..1f46f58 --- /dev/null +++ b/backport-include/linux/delay.h @@ -0,0 +1,10 @@ +#ifndef __BACKPORT_LINUX_DELAY_H +#define __BACKPORT_LINUX_DELAY_H +#include_next <linux/delay.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) +#define usleep_range(_min, _max) msleep((_max) / 1000) +#endif + +#endif /* __BACKPORT_LINUX_DELAY_H */ diff --git a/backport-include/linux/device.h b/backport-include/linux/device.h new file mode 100644 index 0000000..4c0adb7 --- /dev/null +++ b/backport-include/linux/device.h @@ -0,0 +1,179 @@ +#ifndef __BACKPORT_DEVICE_H +#define __BACKPORT_DEVICE_H +#include <linux/export.h> +#include_next <linux/device.h> + +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0) +/* backport + * commit 9f3b795a626ee79574595e06d1437fe0c7d51d29 + * Author: MichaÅ‚ MirosÅ‚aw <mirq-linux@rere.qmqm.pl> + * Date: Fri Feb 1 20:40:17 2013 +0100 + * + * driver-core: constify data for class_find_device() + */ +typedef int (backport_device_find_function_t)(struct device *, void *); +#define class_find_device(cls, start, idx, fun) \ + class_find_device((cls), (start), (idx),\ + (backport_device_find_function_t *)(fun)) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) +#define dev_emerg(dev, format, arg...) \ + dev_printk(KERN_EMERG , dev , format , ## arg) +#define dev_alert(dev, format, arg...) \ + dev_printk(KERN_ALERT , dev , format , ## arg) +#define dev_crit(dev, format, arg...) \ + dev_printk(KERN_CRIT , dev , format , ## arg) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) +/** + * module_driver() - Helper macro for drivers that don't do anything + * special in module init/exit. This eliminates a lot of boilerplate. + * Each module may only use this macro once, and calling it replaces + * module_init() and module_exit(). + * + * Use this macro to construct bus specific macros for registering + * drivers, and do not use it on its own. + */ +#define module_driver(__driver, __register, __unregister) \ +static int __init __driver##_init(void) \ +{ \ + return __register(&(__driver)); \ +} \ +module_init(__driver##_init); \ +static void __exit __driver##_exit(void) \ +{ \ + __unregister(&(__driver)); \ +} \ +module_exit(__driver##_exit); +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0) +#define devm_ioremap_resource LINUX_BACKPORT(devm_ioremap_resource) +void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res); +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0) && \ + LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0) +#define devres_release LINUX_BACKPORT(devres_release) +extern int devres_release(struct device *dev, dr_release_t release, + dr_match_t match, void *match_data); +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0) && \ + LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) +#include <linux/ratelimit.h> + +#define dev_level_ratelimited(dev_level, dev, fmt, ...) \ +do { \ + static DEFINE_RATELIMIT_STATE(_rs, \ + DEFAULT_RATELIMIT_INTERVAL, \ + DEFAULT_RATELIMIT_BURST); \ + if (__ratelimit(&_rs)) \ + dev_level(dev, fmt, ##__VA_ARGS__); \ +} while (0) + +#define dev_emerg_ratelimited(dev, fmt, ...) \ + dev_level_ratelimited(dev_emerg, dev, fmt, ##__VA_ARGS__) +#define dev_alert_ratelimited(dev, fmt, ...) \ + dev_level_ratelimited(dev_alert, dev, fmt, ##__VA_ARGS__) + + +#if defined(CONFIG_DYNAMIC_DEBUG) || defined(DEBUG) +#define dev_dbg_ratelimited(dev, fmt, ...) \ +do { \ + static DEFINE_RATELIMIT_STATE(_rs, \ + DEFAULT_RATELIMIT_INTERVAL, \ + DEFAULT_RATELIMIT_BURST); \ + DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \ + if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \ + __ratelimit(&_rs)) \ + __dynamic_pr_debug(&descriptor, pr_fmt(fmt), \ + ##__VA_ARGS__); \ +} while (0) +#else +#define dev_dbg_ratelimited(dev, fmt, ...) \ + no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) +#endif /* dynamic debug */ +#endif /* 2.6.27 <= version <= 3.5 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) +#define device_rename(dev, new_name) device_rename(dev, (char *)new_name) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) +/* + * This belongs into pm_wakeup.h but that isn't included directly. + * Note that on 2.6.36, this was defined but not exported, so we + * need to override it. + */ +#define pm_wakeup_event LINUX_BACKPORT(pm_wakeup_event) +static inline void pm_wakeup_event(struct device *dev, unsigned int msec) {} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) +static inline void device_lock(struct device *dev) +{ +#if defined(CONFIG_PREEMPT_RT) || defined(CONFIG_PREEMPT_DESKTOP) + mutex_lock(&dev->mutex); +#else + down(&dev->sem); +#endif +} + +static inline int device_trylock(struct device *dev) +{ +#if defined(CONFIG_PREEMPT_RT) || defined(CONFIG_PREEMPT_DESKTOP) + return mutex_trylock(&dev->mutex); +#else + return down_trylock(&dev->sem); +#endif +} + +static inline void device_unlock(struct device *dev) +{ +#if defined(CONFIG_PREEMPT_RT) || defined(CONFIG_PREEMPT_DESKTOP) + mutex_unlock(&dev->mutex); +#else + up(&dev->sem); +#endif +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) +static inline const char *dev_name(struct device *dev) +{ + /* will be changed into kobject_name(&dev->kobj) in the near future */ + return dev->bus_id; +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) +static inline void dev_set_uevent_suppress(struct device *dev, int val) +{ + dev->uevent_suppress = val; +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) +#define device_create(cls, parent, devt, drvdata, fmt, ...) \ +({ \ + struct device *_dev; \ + _dev = (device_create)(cls, parent, devt, fmt, __VA_ARGS__); \ + dev_set_drvdata(_dev, drvdata); \ + _dev; \ +}) + +#define dev_name(dev) dev_name((struct device *)dev) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) +#define dev_set_name LINUX_BACKPORT(dev_set_name) +extern int dev_set_name(struct device *dev, const char *name, ...) + __attribute__((format(printf, 2, 3))); +#endif + +#endif /* __BACKPORT_DEVICE_H */ diff --git a/backport-include/linux/dma-attrs.h b/backport-include/linux/dma-attrs.h new file mode 100644 index 0000000..ee4cd5f --- /dev/null +++ b/backport-include/linux/dma-attrs.h @@ -0,0 +1,6 @@ +#ifndef __BACKPORT_DMA_ATTR_H +#define __BACKPORT_DMA_ATTR_H +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26) +#include_next <linux/dma-attrs.h> +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26) */ +#endif /* __BACKPORT_DMA_ATTR_H */ diff --git a/backport-include/linux/dma-mapping.h b/backport-include/linux/dma-mapping.h new file mode 100644 index 0000000..e5d1d3e --- /dev/null +++ b/backport-include/linux/dma-mapping.h @@ -0,0 +1,92 @@ +#ifndef __BACKPORT_LINUX_DMA_MAPPING_H +#define __BACKPORT_LINUX_DMA_MAPPING_H +#include_next <linux/dma-mapping.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0) +static inline void *dma_zalloc_coherent(struct device *dev, size_t size, + dma_addr_t *dma_handle, gfp_t flag) +{ + void *ret = dma_alloc_coherent(dev, size, dma_handle, flag); + if (ret) + memset(ret, 0, size); + return ret; +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) +/* only include this if DEFINE_DMA_UNMAP_ADDR is not set as debian squeeze also backports this */ +#ifndef DEFINE_DMA_UNMAP_ADDR +#ifdef CONFIG_NEED_DMA_MAP_STATE +#define DEFINE_DMA_UNMAP_ADDR(ADDR_NAME) dma_addr_t ADDR_NAME +#define DEFINE_DMA_UNMAP_LEN(LEN_NAME) __u32 LEN_NAME +#define dma_unmap_addr(PTR, ADDR_NAME) ((PTR)->ADDR_NAME) +#define dma_unmap_addr_set(PTR, ADDR_NAME, VAL) (((PTR)->ADDR_NAME) = (VAL)) +#define dma_unmap_len(PTR, LEN_NAME) ((PTR)->LEN_NAME) +#define dma_unmap_len_set(PTR, LEN_NAME, VAL) (((PTR)->LEN_NAME) = (VAL)) +#else +#define DEFINE_DMA_UNMAP_ADDR(ADDR_NAME) +#define DEFINE_DMA_UNMAP_LEN(LEN_NAME) +#define dma_unmap_addr(PTR, ADDR_NAME) (0) +#define dma_unmap_addr_set(PTR, ADDR_NAME, VAL) do { } while (0) +#define dma_unmap_len(PTR, LEN_NAME) (0) +#define dma_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0) +#endif +#endif + +/* mask dma_set_coherent_mask as debian squeeze also backports this */ +#define dma_set_coherent_mask LINUX_BACKPORT(dma_set_coherent_mask) + +static inline int dma_set_coherent_mask(struct device *dev, u64 mask) +{ + if (!dma_supported(dev, mask)) + return -EIO; + dev->coherent_dma_mask = mask; + return 0; +} +#endif /* < 2.6.34 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) +#include <backport/magic.h> +/* These really belong to asm/dma-mapping.h but it doesn't really matter */ +/* On 2.6.27 a second argument was added, on older kernels we ignore it */ +static inline int dma_mapping_error1(dma_addr_t dma_addr) +{ + /* use an inline to grab the old definition */ + return dma_mapping_error(dma_addr); +} + +#define dma_mapping_error2(pdef, dma_addr) \ + dma_mapping_error1(dma_addr) + +#undef dma_mapping_error +#define dma_mapping_error(...) \ + macro_dispatcher(dma_mapping_error, __VA_ARGS__)(__VA_ARGS__) + +/* This kinda belongs into asm/dma-mapping.h or so, but doesn't matter */ +#ifdef CONFIG_ARM + +/* + * The caller asks to handle a range between offset and offset + size, + * but we process a larger range from 0 to offset + size due to lack of + * offset support. + */ + +static inline void dma_sync_single_range_for_cpu(struct device *dev, + dma_addr_t handle, unsigned long offset, size_t size, + enum dma_data_direction dir) +{ + dma_sync_single_for_cpu(dev, handle, offset + size, dir); +} + +static inline void dma_sync_single_range_for_device(struct device *dev, + dma_addr_t handle, unsigned long offset, size_t size, + enum dma_data_direction dir) +{ + dma_sync_single_for_device(dev, handle, offset + size, dir); +} + +#endif /* arm */ +#endif + +#endif /* __BACKPORT_LINUX_DMA_MAPPING_H */ diff --git a/backport-include/linux/dynamic_debug.h b/backport-include/linux/dynamic_debug.h new file mode 100644 index 0000000..00ab160 --- /dev/null +++ b/backport-include/linux/dynamic_debug.h @@ -0,0 +1,25 @@ +#ifndef __BACKPORT_LINUX_DYNAMIC_DEBUG_H +#define __BACKPORT_LINUX_DYNAMIC_DEBUG_H +#include <linux/version.h> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30) +#include_next <linux/dynamic_debug.h> +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0) +/* backports 07613b0b */ +#if defined(CONFIG_DYNAMIC_DEBUG) +#define DEFINE_DYNAMIC_DEBUG_METADATA(name, fmt) \ + static struct _ddebug __used __aligned(8) \ + __attribute__((section("__verbose"))) name = { \ + .modname = KBUILD_MODNAME, \ + .function = __func__, \ + .filename = __FILE__, \ + .format = (fmt), \ + .lineno = __LINE__, \ + .flags = _DPRINTK_FLAGS_DEFAULT, \ + .enabled = false, \ + } +#endif /* defined(CONFIG_DYNAMIC_DEBUG) */ +#endif /* < 3.2 */ + +#endif /* __BACKPORT_LINUX_DYNAMIC_DEBUG_H */ diff --git a/backport-include/linux/efi.h b/backport-include/linux/efi.h new file mode 100644 index 0000000..2fc40e5 --- /dev/null +++ b/backport-include/linux/efi.h @@ -0,0 +1,66 @@ +#ifndef __BACKPORT_EFI_H +#define __BACKPORT_EFI_H +#include_next <linux/efi.h> +#include <linux/version.h> + +#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0)) + +/* This backports: + * + * commit 83e68189745ad931c2afd45d8ee3303929233e7f + * Author: Matt Fleming <matt.fleming@intel.com> + * Date: Wed Nov 14 09:42:35 2012 +0000 + * + * efi: Make 'efi_enabled' a function to query EFI facilities + * + */ +/* check first if this was already backported */ +#ifndef EFI_BOOT +/* + * We play games with efi_enabled so that the compiler will, if + * possible, remove EFI-related code altogether. + */ +#define EFI_BOOT 0 /* Were we booted from EFI? */ +#define EFI_SYSTEM_TABLES 1 /* Can we use EFI system tables? */ +#define EFI_CONFIG_TABLES 2 /* Can we use EFI config tables? */ +#define EFI_RUNTIME_SERVICES 3 /* Can we use runtime services? */ +#define EFI_MEMMAP 4 /* Can we use EFI memory map? */ +#define EFI_64BIT 5 /* Is the firmware 64-bit? */ + +#ifdef CONFIG_EFI +# ifdef CONFIG_X86 +static inline int compat_efi_enabled(int facility) +{ + switch (facility) { + case EFI_BOOT: + return efi_enabled; +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)) + case EFI_64BIT: + return efi_64bit; +#endif + default: + printk(KERN_ERR "can not translate efi_enabled() to old values completly\n"); + return efi_enabled; + } +} +# else +static inline int compat_efi_enabled(int facility) +{ + return 1; +} +# endif +#else +static inline int compat_efi_enabled(int facility) +{ + return 0; +} +#endif +#ifdef efi_enabled +#undef efi_enabled +#endif +#define efi_enabled(facility) compat_efi_enabled(facility) +#endif /* EFI_BOOT */ + +#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0)) */ + +#endif /* __BACKPORT_EFI_H */ diff --git a/backport-include/linux/err.h b/backport-include/linux/err.h new file mode 100644 index 0000000..f62e3bf --- /dev/null +++ b/backport-include/linux/err.h @@ -0,0 +1,26 @@ +#ifndef __BACKPORT_LINUX_ERR_H +#define __BACKPORT_LINUX_ERR_H +#include_next <linux/err.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39) +static inline int __must_check PTR_RET(const void *ptr) +{ + if (IS_ERR(ptr)) + return PTR_ERR(ptr); + else + return 0; +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33) +/* mask IS_ERR_OR_NULL as debian squeeze also backports this */ +#define IS_ERR_OR_NULL LINUX_BACKPORT(IS_ERR_OR_NULL) + +static inline long __must_check IS_ERR_OR_NULL(const void *ptr) +{ + return !ptr || IS_ERR_VALUE((unsigned long)ptr); +} +#endif + +#endif /* __BACKPORT_LINUX_ERR_H */ diff --git a/backport-include/linux/etherdevice.h b/backport-include/linux/etherdevice.h new file mode 100644 index 0000000..9baa197 --- /dev/null +++ b/backport-include/linux/etherdevice.h @@ -0,0 +1,128 @@ +#ifndef _BACKPORT_LINUX_ETHERDEVICE_H +#define _BACKPORT_LINUX_ETHERDEVICE_H +#include_next <linux/etherdevice.h> +#include <linux/version.h> +/* + * newer kernels include this already and some + * users rely on getting this indirectly + */ +#include <asm/unaligned.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,12) +#define eth_hw_addr_random LINUX_BACKPORT(eth_hw_addr_random) +static inline void eth_hw_addr_random(struct net_device *dev) +{ +#error eth_hw_addr_random() needs to be implemented for < 2.6.12 +} +#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31) +#define eth_hw_addr_random LINUX_BACKPORT(eth_hw_addr_random) +static inline void eth_hw_addr_random(struct net_device *dev) +{ + get_random_bytes(dev->dev_addr, ETH_ALEN); + dev->dev_addr[0] &= 0xfe; /* clear multicast bit */ + dev->dev_addr[0] |= 0x02; /* set local assignment bit (IEEE802) */ +} +#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) +/* So this is 2.6.31..2.6.35 */ + +/* Just have the flags present, they won't really mean anything though */ +#define NET_ADDR_PERM 0 /* address is permanent (default) */ +#define NET_ADDR_RANDOM 1 /* address is generated randomly */ +#define NET_ADDR_STOLEN 2 /* address is stolen from other device */ + +#define eth_hw_addr_random LINUX_BACKPORT(eth_hw_addr_random) +static inline void eth_hw_addr_random(struct net_device *dev) +{ + random_ether_addr(dev->dev_addr); +} + +#elif LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0) +#define eth_hw_addr_random LINUX_BACKPORT(eth_hw_addr_random) +static inline void eth_hw_addr_random(struct net_device *dev) +{ + dev_hw_addr_random(dev, dev->dev_addr); +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0) +#include <linux/random.h> +/** + * eth_broadcast_addr - Assign broadcast address + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Assign the broadcast address to the given address array. + */ +static inline void eth_broadcast_addr(u8 *addr) +{ + memset(addr, 0xff, ETH_ALEN); +} + +/** + * eth_random_addr - Generate software assigned random Ethernet address + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Generate a random Ethernet address (MAC) that is not multicast + * and has the local assigned bit set. + */ +static inline void eth_random_addr(u8 *addr) +{ + get_random_bytes(addr, ETH_ALEN); + addr[0] &= 0xfe; /* clear multicast bit */ + addr[0] |= 0x02; /* set local assignment bit (IEEE802) */ +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0) + +/* This backports: + * + * commit 6d57e9078e880a3dd232d579f42ac437a8f1ef7b + * Author: Duan Jiong <djduanjiong@gmail.com> + * Date: Sat Sep 8 16:32:28 2012 +0000 + * + * etherdevice: introduce help function eth_zero_addr() + */ +static inline void eth_zero_addr(u8 *addr) +{ + memset(addr, 0x00, ETH_ALEN); +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0) +static inline bool ether_addr_equal(const u8 *addr1, const u8 *addr2) +{ + return !compare_ether_addr(addr1, addr2); +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) +#define alloc_etherdev_mqs(sizeof_priv, tx_q, rx_q) alloc_etherdev_mq(sizeof_priv, tx_q) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) +/** + * is_unicast_ether_addr - Determine if the Ethernet address is unicast + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Return true if the address is a unicast address. + */ +static inline int is_unicast_ether_addr(const u8 *addr) +{ + return !is_multicast_ether_addr(addr); +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) +#define eth_mac_addr LINUX_BACKPORT(eth_mac_addr) +extern int eth_mac_addr(struct net_device *dev, void *p); +#define eth_change_mtu LINUX_BACKPORT(eth_change_mtu) +extern int eth_change_mtu(struct net_device *dev, int new_mtu); +#define eth_validate_addr LINUX_BACKPORT(eth_validate_addr) +extern int eth_validate_addr(struct net_device *dev); +#endif /* < 2.6.29 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) +#define netdev_hw_addr dev_mc_list +#endif + +#endif /* _BACKPORT_LINUX_ETHERDEVICE_H */ diff --git a/backport-include/linux/ethtool.h b/backport-include/linux/ethtool.h new file mode 100644 index 0000000..732a0db --- /dev/null +++ b/backport-include/linux/ethtool.h @@ -0,0 +1,52 @@ +#ifndef __BACKPORT_LINUX_ETHTOOL_H +#define __BACKPORT_LINUX_ETHTOOL_H +#include_next <linux/ethtool.h> +#include <linux/version.h> + +#ifndef SPEED_UNKNOWN +#define SPEED_UNKNOWN -1 +#endif /* SPEED_UNKNOWN */ + +#ifndef DUPLEX_UNKNOWN +#define DUPLEX_UNKNOWN 0xff +#endif /* DUPLEX_UNKNOWN */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) +static inline u32 ethtool_rxfh_indir_default(u32 index, u32 n_rx_rings) +{ + return index % n_rx_rings; +} +#endif + +#ifndef ETHTOOL_FWVERS_LEN +#define ETHTOOL_FWVERS_LEN 32 +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31) +#define SUPPORTED_Backplane (1 << 16) +#define SUPPORTED_1000baseKX_Full (1 << 17) +#define SUPPORTED_10000baseKX4_Full (1 << 18) +#define SUPPORTED_10000baseKR_Full (1 << 19) +#define SUPPORTED_10000baseR_FEC (1 << 20) + +#define ADVERTISED_Backplane (1 << 16) +#define ADVERTISED_1000baseKX_Full (1 << 17) +#define ADVERTISED_10000baseKX4_Full (1 << 18) +#define ADVERTISED_10000baseKR_Full (1 << 19) +#define ADVERTISED_10000baseR_FEC (1 << 20) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) +static inline void ethtool_cmd_speed_set(struct ethtool_cmd *ep, + __u32 speed) +{ + ep->speed = (__u16)speed; +} + +static inline __u32 ethtool_cmd_speed(const struct ethtool_cmd *ep) +{ + return ep->speed; +} +#endif + +#endif /* __BACKPORT_LINUX_ETHTOOL_H */ diff --git a/backport-include/linux/export.h b/backport-include/linux/export.h new file mode 100644 index 0000000..3686197 --- /dev/null +++ b/backport-include/linux/export.h @@ -0,0 +1,19 @@ +#ifndef _COMPAT_LINUX_EXPORT_H +#define _COMPAT_LINUX_EXPORT_H 1 + +#include <linux/version.h> + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0)) +#include_next <linux/export.h> +#else +#ifndef pr_fmt +#define backport_undef_pr_fmt +#endif +#include <linux/module.h> +#ifdef backport_undef_pr_fmt +#undef pr_fmt +#undef backport_undef_pr_fmt +#endif +#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0)) */ + +#endif /* _COMPAT_LINUX_EXPORT_H */ diff --git a/backport-include/linux/fb.h b/backport-include/linux/fb.h new file mode 100644 index 0000000..4522e25 --- /dev/null +++ b/backport-include/linux/fb.h @@ -0,0 +1,48 @@ +#ifndef __BACKPORT_FB_H +#define __BACKPORT_FB_H +#include_next <linux/fb.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) +/* + * This is a linux-next data structure element collateral evolution, + * we use a wrapper to avoid #ifdef hell to backport it. This allows + * us to use a simple fb_info_skip_vt_switch() replacement for when + * the new data structure element is used. If coccinelle SmPL grammar + * could be used to express the transformation for us on compat-drivers + * it means we'd need to express it only once. If the structure element + * collateral evolution were to be used *at development* time and we'd + * have a way to express the inverse through SmPL we'd be able to + * backport this collateral evolution automatically for any new driver + * that used it. We'd use coccinelle to look for it and do the + * transformations for us based on the original commit (maybe SmPL + * would be listed on the commit log. + * + * We may need the LINUX_BACKPORT() call that adds the backport_ + * prefix for older kernels than 3.10 if distros decide to + * add this same static inline themselves (although unlikely). + */ +#define fb_enable_skip_vt_switch LINUX_BACKPORT(fb_enable_skip_vt_switch) +static inline void fb_enable_skip_vt_switch(struct fb_info *info) +{ +} +#else /* kernel is >= 3.10 */ +/* + * We'd delete this upstream ever got this, we use our + * backport_ prefix with LINUX_BACKPORT() so that if this + * does get upstream we would not have to add another ifdef + * here for the kernels in between v3.10.. up to the point + * the routine would have gotten added, we'd just delete this + * #else condition completely. If we didn't have this and + * say 3.12 added the static inline upstream, we'd have a + * clash on the backport for 3.12 as the routine would + * already be defined *but* we'd need it for 3.11. + */ +#define fb_enable_skip_vt_switch LINUX_BACKPORT(fb_enable_skip_vt_switch) +static inline void fb_enable_skip_vt_switch(struct fb_info *info) +{ + info->skip_vt_switch = true; +} +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) */ + +#endif /* __BACKPORT_FB_H */ diff --git a/backport-include/linux/firmware.h b/backport-include/linux/firmware.h new file mode 100644 index 0000000..8db0953 --- /dev/null +++ b/backport-include/linux/firmware.h @@ -0,0 +1,29 @@ +#ifndef __BACKPORT_LINUX_FIRMWARE_H +#define __BACKPORT_LINUX_FIRMWARE_H +#include_next <linux/firmware.h> +#include <linux/version.h> + +#if defined(CPTCFG_BACKPORT_BUILD_FW_LOADER_MODULE) +#define request_firmware_nowait LINUX_BACKPORT(request_firmware_nowait) +#define request_firmware LINUX_BACKPORT(request_firmware) +#define release_firmware LINUX_BACKPORT(release_firmware) + +int request_firmware(const struct firmware **fw, const char *name, + struct device *device); +int request_firmware_nowait( + struct module *module, int uevent, + const char *name, struct device *device, gfp_t gfp, void *context, + void (*cont)(const struct firmware *fw, void *context)); + +void release_firmware(const struct firmware *fw); +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) +struct builtin_fw { + char *name; + void *data; + unsigned long size; +}; +#endif + +#endif /* __BACKPORT_LINUX_FIRMWARE_H */ diff --git a/backport-include/linux/fs.h b/backport-include/linux/fs.h new file mode 100644 index 0000000..9de5109 --- /dev/null +++ b/backport-include/linux/fs.h @@ -0,0 +1,41 @@ +#ifndef _COMPAT_LINUX_FS_H +#define _COMPAT_LINUX_FS_H +#include_next <linux/fs.h> +#include <linux/version.h> +/* + * some versions don't have this and thus don't + * include it from the original fs.h + */ +#include <linux/uidgid.h> + +#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0)) +#define simple_open LINUX_BACKPORT(simple_open) +extern int simple_open(struct inode *inode, struct file *file); +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0) +/** + * backport of: + * + * commit 496ad9aa8ef448058e36ca7a787c61f2e63f0f54 + * Author: Al Viro <viro@zeniv.linux.org.uk> + * Date: Wed Jan 23 17:07:38 2013 -0500 + * + * new helper: file_inode(file) + */ +static inline struct inode *file_inode(struct file *f) +{ + return f->f_path.dentry->d_inode; +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) +#define noop_llseek LINUX_BACKPORT(noop_llseek) +extern loff_t noop_llseek(struct file *file, loff_t offset, int origin); + +#define simple_write_to_buffer LINUX_BACKPORT(simple_write_to_buffer) +extern ssize_t simple_write_to_buffer(void *to, size_t available, loff_t *ppos, + const void __user *from, size_t count); +#endif + +#endif /* _COMPAT_LINUX_FS_H */ diff --git a/backport-include/linux/genetlink.h b/backport-include/linux/genetlink.h new file mode 100644 index 0000000..afd1f67 --- /dev/null +++ b/backport-include/linux/genetlink.h @@ -0,0 +1,18 @@ +#ifndef __BACKPORT_LINUX_GENETLINK_H +#define __BACKPORT_LINUX_GENETLINK_H +#include_next <linux/genetlink.h> + +/* This backports: + * + * commit e9412c37082b5c932e83364aaed0c38c2ce33acb + * Author: Neil Horman <nhorman@tuxdriver.com> + * Date: Tue May 29 09:30:41 2012 +0000 + * + * genetlink: Build a generic netlink family module alias + */ +#ifndef MODULE_ALIAS_GENL_FAMILY +#define MODULE_ALIAS_GENL_FAMILY(family)\ + MODULE_ALIAS_NET_PF_PROTO_NAME(PF_NETLINK, NETLINK_GENERIC, "-family-" family) +#endif + +#endif /* __BACKPORT_LINUX_GENETLINK_H */ diff --git a/backport-include/linux/gpio.h b/backport-include/linux/gpio.h new file mode 100644 index 0000000..d31e14e --- /dev/null +++ b/backport-include/linux/gpio.h @@ -0,0 +1,10 @@ +#ifndef _COMPAT_LINUX_GPIO_H +#define _COMPAT_LINUX_GPIO_H 1 + +#include <linux/version.h> + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)) +#include_next <linux/gpio.h> +#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)) */ + +#endif /* _COMPAT_LINUX_GPIO_H */ diff --git a/backport-include/linux/hid.h b/backport-include/linux/hid.h new file mode 100644 index 0000000..555ec2b --- /dev/null +++ b/backport-include/linux/hid.h @@ -0,0 +1,42 @@ +#ifndef __BACKPORT_HID_H +#define __BACKPORT_HID_H +#include_next <linux/hid.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) +#define hid_ignore LINUX_BACKPORT(hid_ignore) +extern bool hid_ignore(struct hid_device *); +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0) +#define HID_TYPE_USBNONE 2 +#endif + +#ifndef HID_QUIRK_NO_IGNORE +#define HID_QUIRK_NO_IGNORE 0x40000000 +#endif + +#ifndef HID_QUIRK_HIDDEV_FORCE +#define HID_QUIRK_HIDDEV_FORCE 0x00000010 +#endif + +#ifndef HID_QUIRK_IGNORE +#define HID_QUIRK_IGNORE 0x00000004 +#endif + +#ifndef HID_USB_DEVICE +#define HID_USB_DEVICE(ven, prod) \ + .bus = BUS_USB, .vendor = (ven), .product = (prod) +#endif + +#ifndef HID_BLUETOOTH_DEVICE +#define HID_BLUETOOTH_DEVICE(ven, prod) \ + .bus = BUS_BLUETOOTH, .vendor = (ven), .product = (prod) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) +#define hid_alloc_report_buf LINUX_BACKPORT(hid_alloc_report_buf) +u8 *hid_alloc_report_buf(struct hid_report *report, gfp_t flags); +#endif + +#endif /* __BACKPORT_HID_H */ diff --git a/backport-include/linux/hrtimer.h b/backport-include/linux/hrtimer.h new file mode 100644 index 0000000..c099dd4 --- /dev/null +++ b/backport-include/linux/hrtimer.h @@ -0,0 +1,11 @@ +#ifndef __BACKPORT_LINUX_HRTIMER_H +#define __BACKPORT_LINUX_HRTIMER_H +#include_next <linux/hrtimer.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0) +#define ktime_get_monotonic_offset LINUX_BACKPORT(ktime_get_monotonic_offset) +extern ktime_t ktime_get_monotonic_offset(void); +#endif + +#endif /* __BACKPORT_LINUX_HRTIMER_H */ diff --git a/backport-include/linux/i2c-algo-bit.h b/backport-include/linux/i2c-algo-bit.h new file mode 100644 index 0000000..643e0c7 --- /dev/null +++ b/backport-include/linux/i2c-algo-bit.h @@ -0,0 +1,12 @@ +#ifndef __BACKPORT_LINUX_I2C_ALGO_BIT_H +#define __BACKPORT_LINUX_I2C_ALGO_BIT_H +#include_next <linux/i2c-algo-bit.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0) && \ + LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34) +#define i2c_bit_algo LINUX_BACKPORT(i2c_bit_algo) +extern const struct i2c_algorithm i2c_bit_algo; +#endif + +#endif /* __BACKPORT_LINUX_I2C_ALGO_BIT_H */ diff --git a/backport-include/linux/i2c.h b/backport-include/linux/i2c.h new file mode 100644 index 0000000..ffa9027 --- /dev/null +++ b/backport-include/linux/i2c.h @@ -0,0 +1,41 @@ +#ifndef __BACKPORT_LINUX_I2C_H +#define __BACKPORT_LINUX_I2C_H +#include_next <linux/i2c.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0) && \ + LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0) +#include <linux/i2c.h> +/* Unlocked flavor */ +#define __i2c_transfer LINUX_BACKPORT(__i2c_transfer) +extern int __i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, + int num); +#endif + +/* This backports + * + * commit 14674e70119ea01549ce593d8901a797f8a90f74 + * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> + * Date: Wed May 30 10:55:34 2012 +0200 + * + * i2c: Split I2C_M_NOSTART support out of I2C_FUNC_PROTOCOL_MANGLING + */ +#ifndef I2C_FUNC_NOSTART +#define I2C_FUNC_NOSTART 0x00000010 /* I2C_M_NOSTART */ +#endif + +/* This backports: + * + * commit 7c92784a546d2945b6d6973a30f7134be78eb7a4 + * Author: Lars-Peter Clausen <lars@metafoo.de> + * Date: Wed Nov 16 10:13:36 2011 +0100 + * + * I2C: Add helper macro for i2c_driver boilerplate + */ +#ifndef module_i2c_driver +#define module_i2c_driver(__i2c_driver) \ + module_driver(__i2c_driver, i2c_add_driver, \ + i2c_del_driver) +#endif + +#endif /* __BACKPORT_LINUX_I2C_H */ diff --git a/backport-include/linux/idr.h b/backport-include/linux/idr.h new file mode 100644 index 0000000..737632b --- /dev/null +++ b/backport-include/linux/idr.h @@ -0,0 +1,59 @@ +#ifndef __BACKPORT_IDR_H +#define __BACKPORT_IDR_H +/* some versions have a broken idr header */ +#include <linux/spinlock.h> +#include_next <linux/idr.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0) +#define ida_simple_get LINUX_BACKPORT(ida_simple_get) +int ida_simple_get(struct ida *ida, unsigned int start, unsigned int end, + gfp_t gfp_mask); + +#define ida_simple_remove LINUX_BACKPORT(ida_simple_remove) +void ida_simple_remove(struct ida *ida, unsigned int id); +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0) +#include <linux/errno.h> +/** + * backport of idr idr_alloc() usage + * + * This backports a patch series send by Tejun Heo: + * https://lkml.org/lkml/2013/2/2/159 + */ +static inline void compat_idr_destroy(struct idr *idp) +{ + idr_remove_all(idp); + idr_destroy(idp); +} +#define idr_destroy(idp) compat_idr_destroy(idp) + +static inline int idr_alloc(struct idr *idr, void *ptr, int start, int end, + gfp_t gfp_mask) +{ + int id, ret; + + do { + if (!idr_pre_get(idr, gfp_mask)) + return -ENOMEM; + ret = idr_get_new_above(idr, ptr, start, &id); + if (!ret && id > end) { + idr_remove(idr, id); + ret = -ENOSPC; + } + } while (ret == -EAGAIN); + + return ret ? ret : id; +} + +static inline void idr_preload(gfp_t gfp_mask) +{ +} + +static inline void idr_preload_end(void) +{ +} +#endif + +#endif /* __BACKPORT_IDR_H */ diff --git a/backport-include/linux/if.h b/backport-include/linux/if.h new file mode 100644 index 0000000..7926082 --- /dev/null +++ b/backport-include/linux/if.h @@ -0,0 +1,32 @@ +#ifndef _BACKPORT_LINUX_IF_H +#define _BACKPORT_LINUX_IF_H +#include_next <linux/if.h> +#include <linux/version.h> + +/* mask IFF_DONT_BRIDGE as RHEL6 backports this */ +#if !defined(IFF_DONT_BRIDGE) +#define IFF_DONT_BRIDGE 0x800 /* disallow bridging this ether dev */ +#endif + +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36)) +#define br_port_exists(dev) (dev->br_port) +#else +/* + * This is not part of The 2.6.37 kernel yet but we + * we use it to optimize the backport code we + * need to implement. Instead of using ifdefs + * to check what version of the check we use + * we just replace all checks on current code + * with this. I'll submit this upstream too, that + * way all we'd have to do is to implement this + * for older kernels, then we would not have to + * edit the upstrema code for backport efforts. + */ +#define br_port_exists(dev) (dev->priv_flags & IFF_BRIDGE_PORT) +#endif + +#ifndef IFF_TX_SKB_SHARING +#define IFF_TX_SKB_SHARING 0x10000 +#endif + +#endif /* _BACKPORT_LINUX_IF_H */ diff --git a/backport-include/linux/if_ether.h b/backport-include/linux/if_ether.h new file mode 100644 index 0000000..8581283 --- /dev/null +++ b/backport-include/linux/if_ether.h @@ -0,0 +1,34 @@ +#ifndef __BACKPORT_IF_ETHER_H +#define __BACKPORT_IF_ETHER_H +#include_next <linux/if_ether.h> + +/* + * backport of: + * commit e5c5d22e8dcf7c2d430336cbf8e180bd38e8daf1 + * Author: Simon Horman <horms@verge.net.au> + * Date: Thu Mar 28 13:38:25 2013 +0900 + * + * net: add ETH_P_802_3_MIN + */ +#ifndef ETH_P_802_3_MIN +#define ETH_P_802_3_MIN 0x0600 +#endif + +#ifndef ETH_P_TDLS +#define ETH_P_TDLS 0x890D /* TDLS */ +#endif + +#ifndef ETH_P_LINK_CTL +#define ETH_P_LINK_CTL 0x886c +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0) +#define mac_pton LINUX_BACKPORT(mac_pton) +int mac_pton(const char *s, u8 *mac); +#endif + +#ifndef ETH_P_PAE +#define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */ +#endif + +#endif /* __BACKPORT_IF_ETHER_H */ diff --git a/backport-include/linux/if_vlan.h b/backport-include/linux/if_vlan.h new file mode 100644 index 0000000..fea0acc --- /dev/null +++ b/backport-include/linux/if_vlan.h @@ -0,0 +1,20 @@ +#ifndef __BACKPORT_LINUX_IF_VLAN_H_ +#define __BACKPORT_LINUX_IF_VLAN_H_ +#include_next <linux/if_vlan.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) +#define vlan_insert_tag(__skb, __vlan_proto, __vlan_tci) vlan_insert_tag(__skb, __vlan_tci) +#define __vlan_put_tag(__skb, __vlan_proto, __vlan_tci) __vlan_put_tag(__skb, __vlan_tci) +#define vlan_put_tag(__skb, __vlan_proto, __vlan_tci) vlan_put_tag(__skb, __vlan_tci) +#define __vlan_hwaccel_put_tag(__skb, __vlan_proto, __vlan_tag) __vlan_hwaccel_put_tag(__skb, __vlan_tag) + +static inline bool vlan_hw_offload_capable(netdev_features_t features, + __be16 proto) +{ + if (proto == htons(ETH_P_8021Q) && features & NETIF_F_HW_VLAN_CTAG_TX) + return true; + return false; +} +#endif + +#endif /* __BACKPORT_LINUX_IF_VLAN_H_ */ diff --git a/backport-include/linux/in.h b/backport-include/linux/in.h new file mode 100644 index 0000000..f019e0a --- /dev/null +++ b/backport-include/linux/in.h @@ -0,0 +1,94 @@ +#ifndef __BACKPORT_IN_H +#define __BACKPORT_IN_H +#include_next <linux/in.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) +/* + * backports 2658fa803111dae1353602e7f586de8e537803e2 + */ + +static inline bool ipv4_is_loopback(__be32 addr) +{ + return (addr & htonl(0xff000000)) == htonl(0x7f000000); +} + +static inline bool ipv4_is_multicast(__be32 addr) +{ + return (addr & htonl(0xf0000000)) == htonl(0xe0000000); +} + +static inline bool ipv4_is_local_multicast(__be32 addr) +{ + return (addr & htonl(0xffffff00)) == htonl(0xe0000000); +} + +static inline bool ipv4_is_lbcast(__be32 addr) +{ + /* limited broadcast */ + return addr == htonl(INADDR_BROADCAST); +} + +static inline bool ipv4_is_zeronet(__be32 addr) +{ + return (addr & htonl(0xff000000)) == htonl(0x00000000); +} + +/* Special-Use IPv4 Addresses (RFC3330) */ + +static inline bool ipv4_is_private_10(__be32 addr) +{ + return (addr & htonl(0xff000000)) == htonl(0x0a000000); +} + +static inline bool ipv4_is_private_172(__be32 addr) +{ + return (addr & htonl(0xfff00000)) == htonl(0xac100000); +} + +static inline bool ipv4_is_private_192(__be32 addr) +{ + return (addr & htonl(0xffff0000)) == htonl(0xc0a80000); +} + +static inline bool ipv4_is_linklocal_169(__be32 addr) +{ + return (addr & htonl(0xffff0000)) == htonl(0xa9fe0000); +} + +static inline bool ipv4_is_anycast_6to4(__be32 addr) +{ + return (addr & htonl(0xffffff00)) == htonl(0xc0586300); +} + +static inline bool ipv4_is_test_192(__be32 addr) +{ + return (addr & htonl(0xffffff00)) == htonl(0xc0000200); +} + +static inline bool ipv4_is_test_198(__be32 addr) +{ + return (addr & htonl(0xfffe0000)) == htonl(0xc6120000); +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) +static inline int proto_ports_offset(int proto) +{ + switch (proto) { + case IPPROTO_TCP: + case IPPROTO_UDP: + case IPPROTO_DCCP: + case IPPROTO_ESP: /* SPI */ + case IPPROTO_SCTP: + case IPPROTO_UDPLITE: + return 0; + case IPPROTO_AH: /* SPI */ + return 4; + default: + return -EINVAL; + } +} +#endif + +#endif /* __BACKPORT_IN_H */ diff --git a/backport-include/linux/init.h b/backport-include/linux/init.h new file mode 100644 index 0000000..a835e33 --- /dev/null +++ b/backport-include/linux/init.h @@ -0,0 +1,19 @@ +#ifndef __BACKPORT_INIT_H +#define __BACKPORT_INIT_H +#include_next <linux/init.h> + +/* + * Backports 312b1485fb509c9bc32eda28ad29537896658cb8 + * Author: Sam Ravnborg <sam@ravnborg.org> + * Date: Mon Jan 28 20:21:15 2008 +0100 + * + * Introduce new section reference annotations tags: __ref, __refdata, __refconst + */ +#ifndef __ref +#define __ref __init_refok +#endif +#ifndef __refdata +#define __refdata __initdata_refok +#endif + +#endif /* __BACKPORT_INIT_H */ diff --git a/backport-include/linux/input.h b/backport-include/linux/input.h new file mode 100644 index 0000000..3442db0 --- /dev/null +++ b/backport-include/linux/input.h @@ -0,0 +1,21 @@ +#ifndef __BACKPORT_INPUT_H +#define __BACKPORT_INPUT_H +#include_next <linux/input.h> + +#ifndef KEY_WIMAX +#define KEY_WIMAX 246 +#endif + +#ifndef KEY_WPS_BUTTON +#define KEY_WPS_BUTTON 0x211 +#endif + +#ifndef KEY_RFKILL +#define KEY_RFKILL 247 +#endif + +#ifndef SW_RFKILL_ALL +#define SW_RFKILL_ALL 0x03 +#endif + +#endif /* __BACKPORT_INPUT_H */ diff --git a/backport-include/linux/interrupt.h b/backport-include/linux/interrupt.h new file mode 100644 index 0000000..1729567 --- /dev/null +++ b/backport-include/linux/interrupt.h @@ -0,0 +1,116 @@ +#ifndef __BACKPORT_LINUX_INTERRUPT_H +#define __BACKPORT_LINUX_INTERRUPT_H +#include_next <linux/interrupt.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39) +static inline int irq_set_irq_wake(unsigned int irq, unsigned int on) +{ + return set_irq_wake(irq, on); +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) +#include <linux/cpumask.h> +/* mask irq_set_affinity_hint as RHEL6 backports this */ +#define irq_set_affinity_hint LINUX_BACKPORT(irq_set_affinity_hint) +/* + * We cannot backport this guy as the IRQ data structure + * was modified in the kernel itself to support this. We + * treat the system as uni-processor in this case. + */ +static inline int irq_set_affinity_hint(unsigned int irq, + const struct cpumask *m) +{ + return -EINVAL; +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) +#define IRQ_WAKE_THREAD (2) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31) +struct compat_threaded_irq { + unsigned int irq; + irq_handler_t handler; + irq_handler_t thread_fn; + void *dev_id; + char wq_name[64]; + struct workqueue_struct *wq; + struct work_struct work; +}; + +static inline +void compat_irq_work(struct work_struct *work) +{ + struct compat_threaded_irq *comp = container_of(work, struct compat_threaded_irq, work); + comp->thread_fn(comp->irq, comp->dev_id); +} + +static inline +irqreturn_t compat_irq_dispatcher(int irq, void *dev_id) +{ + struct compat_threaded_irq *comp = dev_id; + irqreturn_t res; + + res = comp->handler(irq, comp->dev_id); + if (res == IRQ_WAKE_THREAD) { + queue_work(comp->wq, &comp->work); + res = IRQ_HANDLED; + } + + return res; +} + +static inline +int compat_request_threaded_irq(struct compat_threaded_irq *comp, + unsigned int irq, + irq_handler_t handler, + irq_handler_t thread_fn, + unsigned long flags, + const char *name, + void *dev_id) +{ + comp->irq = irq; + comp->handler = handler; + comp->thread_fn = thread_fn; + comp->dev_id = dev_id; + INIT_WORK(&comp->work, compat_irq_work); + + if (!comp->wq) { + snprintf(comp->wq_name, sizeof(comp->wq_name), + "compirq/%u-%s", irq, name); + comp->wq = create_singlethread_workqueue(comp->wq_name); + if (!comp->wq) { + printk(KERN_ERR "Failed to create compat-threaded-IRQ workqueue %s\n", + comp->wq_name); + return -ENOMEM; + } + } + return request_irq(irq, compat_irq_dispatcher, flags, name, comp); +} + +static inline +void compat_free_threaded_irq(struct compat_threaded_irq *comp) +{ + free_irq(comp->irq, comp); +} + +static inline +void compat_destroy_threaded_irq(struct compat_threaded_irq *comp) +{ + if (comp->wq) + destroy_workqueue(comp->wq); + comp->wq = NULL; +} + +static inline +void compat_synchronize_threaded_irq(struct compat_threaded_irq *comp) +{ + synchronize_irq(comp->irq); + cancel_work_sync(&comp->work); +} +#endif + +#endif /* __BACKPORT_LINUX_INTERRUPT_H */ diff --git a/backport-include/linux/ioport.h b/backport-include/linux/ioport.h new file mode 100644 index 0000000..3424401 --- /dev/null +++ b/backport-include/linux/ioport.h @@ -0,0 +1,9 @@ +#ifndef __BACKPORT_LINUX_IOPORT_H +#define __BACKPORT_LINUX_IOPORT_H +#include_next <linux/ioport.h> + +#ifndef IORESOURCE_REG +#define IORESOURCE_REG 0x00000300 +#endif + +#endif /* __BACKPORT_LINUX_IOPORT_H */ diff --git a/backport-include/linux/irq.h b/backport-include/linux/irq.h new file mode 100644 index 0000000..357d688 --- /dev/null +++ b/backport-include/linux/irq.h @@ -0,0 +1,85 @@ +#ifndef __BACKPORT_LINUX_IRQ_H +#define __BACKPORT_LINUX_IRQ_H +#include_next <linux/irq.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39) +static inline int irq_set_chip(unsigned int irq, struct irq_chip *chip) +{ + return set_irq_chip(irq, chip); +} +static inline int irq_set_handler_data(unsigned int irq, void *data) +{ + return set_irq_data(irq, data); +} +static inline int irq_set_chip_data(unsigned int irq, void *data) +{ + return set_irq_chip_data(irq, data); +} +static inline int irq_set_irq_type(unsigned int irq, unsigned int type) +{ + return set_irq_type(irq, type); +} +static inline int irq_set_msi_desc(unsigned int irq, struct msi_desc *entry) +{ + return set_irq_msi(irq, entry); +} +static inline struct irq_chip *irq_get_chip(unsigned int irq) +{ + return get_irq_chip(irq); +} +static inline void *irq_get_chip_data(unsigned int irq) +{ + return get_irq_chip_data(irq); +} +static inline void *irq_get_handler_data(unsigned int irq) +{ + return get_irq_data(irq); +} + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37)) +static inline void *irq_data_get_irq_handler_data(struct irq_data *d) +{ + return irq_data_get_irq_data(d); +} +#endif + +static inline struct msi_desc *irq_get_msi_desc(unsigned int irq) +{ + return get_irq_msi(irq); +} + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)) +static inline void irq_set_noprobe(unsigned int irq) +{ + set_irq_noprobe(irq); +} +static inline void irq_set_probe(unsigned int irq) +{ + set_irq_probe(irq); +} +#endif +#endif + +/* This is really in irqdesc.h, but nothing includes that directly */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39) && \ + LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29) +static inline struct irq_chip *irq_desc_get_chip(struct irq_desc *desc) +{ + return get_irq_desc_chip(desc); +} +static inline void *irq_desc_get_handler_data(struct irq_desc *desc) +{ + return get_irq_desc_data(desc); +} +static inline void *irq_desc_get_chip_data(struct irq_desc *desc) +{ + return get_irq_desc_chip_data(desc); +} +static inline struct msi_desc *irq_desc_get_msi_desc(struct irq_desc *desc) +{ + return get_irq_desc_msi(desc); +} +#endif + +#endif /* __BACKPORT_LINUX_IRQ_H */ diff --git a/backport-include/linux/jiffies.h b/backport-include/linux/jiffies.h new file mode 100644 index 0000000..9e74e6a --- /dev/null +++ b/backport-include/linux/jiffies.h @@ -0,0 +1,21 @@ +#ifndef __BACKPORT_LNIUX_JIFFIES_H +#define __BACKPORT_LNIUX_JIFFIES_H +#include_next <linux/jiffies.h> + +#ifndef time_is_before_jiffies +#define time_is_before_jiffies(a) time_after(jiffies, a) +#endif + +#ifndef time_is_after_jiffies +#define time_is_after_jiffies(a) time_before(jiffies, a) +#endif + +#ifndef time_is_before_eq_jiffies +#define time_is_before_eq_jiffies(a) time_after_eq(jiffies, a) +#endif + +#ifndef time_is_after_eq_jiffies +#define time_is_after_eq_jiffies(a) time_before_eq(jiffies, a) +#endif + +#endif /* __BACKPORT_LNIUX_JIFFIES_H */ diff --git a/backport-include/linux/kconfig.h b/backport-include/linux/kconfig.h new file mode 100644 index 0000000..d5c483d --- /dev/null +++ b/backport-include/linux/kconfig.h @@ -0,0 +1,24 @@ +#ifndef __BACKPORT_LINUX_KCONFIG_H +#define __BACKPORT_LINUX_KCONFIG_H +#include <linux/version.h> +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,1,0) +#include_next <linux/kconfig.h> +#endif + +#ifndef __ARG_PLACEHOLDER_1 +#define __ARG_PLACEHOLDER_1 0, +#define config_enabled(cfg) _config_enabled(cfg) +#define _config_enabled(value) __config_enabled(__ARG_PLACEHOLDER_##value) +#define __config_enabled(arg1_or_junk) ___config_enabled(arg1_or_junk 1, 0) +#define ___config_enabled(__ignored, val, ...) val + +/* + * 3.1 - 3.3 had a broken version of this, so undef + * (they didn't have __ARG_PLACEHOLDER_1) + */ +#undef IS_ENABLED +#define IS_ENABLED(option) \ + (config_enabled(option) || config_enabled(option##_MODULE)) +#endif + +#endif diff --git a/backport-include/linux/kernel.h b/backport-include/linux/kernel.h new file mode 100644 index 0000000..df344eb --- /dev/null +++ b/backport-include/linux/kernel.h @@ -0,0 +1,255 @@ +#ifndef __BACKPORT_KERNEL_H +#define __BACKPORT_KERNEL_H +#include_next <linux/kernel.h> +#include <linux/version.h> +/* + * some older kernels don't have this and thus don't + * include it from kernel.h like new kernels + */ +#include <linux/printk.h> + +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)) +/** + * The following things are out of ./include/linux/kernel.h + * The new iwlwifi driver is using them. + */ +#define strict_strtoul LINUX_BACKPORT(strict_strtoul) +extern int strict_strtoul(const char *, unsigned int, unsigned long *); +#define strict_strtol LINUX_BACKPORT(strict_strtol) +extern int strict_strtol(const char *, unsigned int, long *); +#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)) */ + +/* + * This backports: + * + * From a3860c1c5dd1137db23d7786d284939c5761d517 Mon Sep 17 00:00:00 2001 + * From: Xi Wang <xi.wang@gmail.com> + * Date: Thu, 31 May 2012 16:26:04 -0700 + * Subject: [PATCH] introduce SIZE_MAX + */ +#ifndef SIZE_MAX +#define SIZE_MAX (~(size_t)0) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) +extern const char hex_asc[]; +#endif + +#ifndef hex_asc_hi +#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4] +#endif +#ifndef hex_asc_lo +#define hex_asc_lo(x) hex_asc[((x) & 0x0f)] +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0) +static inline char *hex_byte_pack(char *buf, u8 byte) +{ + *buf++ = hex_asc_hi(byte); + *buf++ = hex_asc_lo(byte); + return buf; +} +#endif + +/* This backports: + * + * commit 36a26c69b4c70396ef569c3452690fba0c1dec08 + * Author: Nicholas Bellinger <nab@linux-iscsi.org> + * Date: Tue Jul 26 00:35:26 2011 -0700 + * + * kernel.h: Add DIV_ROUND_UP_ULL and DIV_ROUND_UP_SECTOR_T macro usage + */ +#ifndef DIV_ROUND_UP_ULL +#define DIV_ROUND_UP_ULL(ll,d) \ + ({ unsigned long long _tmp = (ll)+(d)-1; do_div(_tmp, d); _tmp; }) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0) +int __must_check kstrtoull_from_user(const char __user *s, size_t count, unsigned int base, unsigned long long *res); +int __must_check kstrtoll_from_user(const char __user *s, size_t count, unsigned int base, long long *res); +int __must_check kstrtoul_from_user(const char __user *s, size_t count, unsigned int base, unsigned long *res); +int __must_check kstrtol_from_user(const char __user *s, size_t count, unsigned int base, long *res); +int __must_check kstrtouint_from_user(const char __user *s, size_t count, unsigned int base, unsigned int *res); +int __must_check kstrtoint_from_user(const char __user *s, size_t count, unsigned int base, int *res); +int __must_check kstrtou16_from_user(const char __user *s, size_t count, unsigned int base, u16 *res); +int __must_check kstrtos16_from_user(const char __user *s, size_t count, unsigned int base, s16 *res); +int __must_check kstrtou8_from_user(const char __user *s, size_t count, unsigned int base, u8 *res); +int __must_check kstrtos8_from_user(const char __user *s, size_t count, unsigned int base, s8 *res); + +static inline int __must_check kstrtou64_from_user(const char __user *s, size_t count, unsigned int base, u64 *res) +{ + return kstrtoull_from_user(s, count, base, res); +} + +static inline int __must_check kstrtos64_from_user(const char __user *s, size_t count, unsigned int base, s64 *res) +{ + return kstrtoll_from_user(s, count, base, res); +} + +static inline int __must_check kstrtou32_from_user(const char __user *s, size_t count, unsigned int base, u32 *res) +{ + return kstrtouint_from_user(s, count, base, res); +} + +static inline int __must_check kstrtos32_from_user(const char __user *s, size_t count, unsigned int base, s32 *res) +{ + return kstrtoint_from_user(s, count, base, res); +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39) +/* + * kstrto* was included in kernel 2.6.38.4 and causes conflicts with the + * version included in compat-drivers. We use strict_strtol to check if + * kstrto* is already available. + */ +#ifndef strict_strtoull +/* Internal, do not use. */ +int __must_check _kstrtoul(const char *s, unsigned int base, unsigned long *res); +int __must_check _kstrtol(const char *s, unsigned int base, long *res); + +int __must_check kstrtoull(const char *s, unsigned int base, unsigned long long *res); +int __must_check kstrtoll(const char *s, unsigned int base, long long *res); +static inline int __must_check kstrtoul(const char *s, unsigned int base, unsigned long *res) +{ + /* + * We want to shortcut function call, but + * __builtin_types_compatible_p(unsigned long, unsigned long long) = 0. + */ + if (sizeof(unsigned long) == sizeof(unsigned long long) && + __alignof__(unsigned long) == __alignof__(unsigned long long)) + return kstrtoull(s, base, (unsigned long long *)res); + else + return _kstrtoul(s, base, res); +} + +static inline int __must_check kstrtol(const char *s, unsigned int base, long *res) +{ + /* + * We want to shortcut function call, but + * __builtin_types_compatible_p(long, long long) = 0. + */ + if (sizeof(long) == sizeof(long long) && + __alignof__(long) == __alignof__(long long)) + return kstrtoll(s, base, (long long *)res); + else + return _kstrtol(s, base, res); +} + +int __must_check kstrtouint(const char *s, unsigned int base, unsigned int *res); +int __must_check kstrtoint(const char *s, unsigned int base, int *res); + +static inline int __must_check kstrtou64(const char *s, unsigned int base, u64 *res) +{ + return kstrtoull(s, base, res); +} + +static inline int __must_check kstrtos64(const char *s, unsigned int base, s64 *res) +{ + return kstrtoll(s, base, res); +} + +static inline int __must_check kstrtou32(const char *s, unsigned int base, u32 *res) +{ + return kstrtouint(s, base, res); +} + +static inline int __must_check kstrtos32(const char *s, unsigned int base, s32 *res) +{ + return kstrtoint(s, base, res); +} + +int __must_check kstrtou16(const char *s, unsigned int base, u16 *res); +int __must_check kstrtos16(const char *s, unsigned int base, s16 *res); +int __must_check kstrtou8(const char *s, unsigned int base, u8 *res); +int __must_check kstrtos8(const char *s, unsigned int base, s8 *res); +#endif /* ifndef strict_strtol */ + +#endif /* < 2.6.39 */ + +#ifndef USHRT_MAX +#define USHRT_MAX ((u16)(~0U)) +#endif + +#ifndef SHRT_MAX +#define SHRT_MAX ((s16)(USHRT_MAX>>1)) +#endif + +#ifndef SHRT_MIN +#define SHRT_MIN ((s16)(-SHRT_MAX - 1)) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) +#define hex_to_bin LINUX_BACKPORT(hex_to_bin) +int hex_to_bin(char ch); +#endif + +#ifndef __round_mask +#define __round_mask(x, y) ((__typeof__(x))((y)-1)) +#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) +#define round_down(x, y) ((x) & ~__round_mask(x, y)) +#endif + +#ifndef DIV_ROUND_CLOSEST +#define DIV_ROUND_CLOSEST(x, divisor) ({ \ + typeof(divisor) __divisor = divisor; \ + (((x) + ((__divisor) / 2)) / (__divisor)); \ +}) +#endif + +#ifndef swap +#define swap(a, b) \ + do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0) +#endif + +#ifndef lower_32_bits +#define lower_32_bits(n) ((u32)(n)) +#endif + +#ifndef USHORT_MAX +#define USHORT_MAX ((u16)(~0U)) +#define SHORT_MAX ((s16)(USHORT_MAX>>1)) +#define SHORT_MIN (-SHORT_MAX - 1) +#endif + +#ifndef clamp +#define clamp(val, min, max) ({ \ + typeof(val) __val = (val); \ + typeof(min) __min = (min); \ + typeof(max) __max = (max); \ + (void) (&__val == &__min); \ + (void) (&__val == &__max); \ + __val = __val < __min ? __min: __val; \ + __val > __max ? __max: __val; }) +#endif + +#ifndef clamp_t +#define clamp_t(type, val, min, max) ({ \ + type __val = (val); \ + type __min = (min); \ + type __max = (max); \ + __val = __val < __min ? __min: __val; \ + __val > __max ? __max: __val; }) +#endif + +#ifndef clamp_val +#define clamp_val(val, min, max) ({ \ + typeof(val) __val = (val); \ + typeof(val) __min = (min); \ + typeof(val) __max = (max); \ + __val = __val < __min ? __min: __val; \ + __val > __max ? __max: __val; }) +#endif + +#endif /* __BACKPORT_KERNEL_H */ + +/* + * We have to do this outside the include guard, because + * out own header (linux/export.h) has to include kernel.h + * indirectly (through module.h) and then undef's pr_fmt. + * Then, when the real kernel.h gets included again, it's + * not defined and we get problems ... + */ +#ifndef pr_fmt +#define pr_fmt(msg) msg +#endif diff --git a/backport-include/linux/kfifo.h b/backport-include/linux/kfifo.h new file mode 100644 index 0000000..398b00d --- /dev/null +++ b/backport-include/linux/kfifo.h @@ -0,0 +1,877 @@ +#include <linux/version.h> +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)) +#include_next <linux/kfifo.h> +#else +/* + * A generic kernel FIFO implementation + * + * Copyright (C) 2009/2010 Stefani Seibold <stefani@seibold.net> + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#ifndef _LINUX_KFIFO_H +#define _LINUX_KFIFO_H + +/* + * How to porting drivers to the new generic FIFO API: + * + * - Modify the declaration of the "struct kfifo *" object into a + * in-place "struct kfifo" object + * - Init the in-place object with kfifo_alloc() or kfifo_init() + * Note: The address of the in-place "struct kfifo" object must be + * passed as the first argument to this functions + * - Replace the use of __kfifo_put into kfifo_in and __kfifo_get + * into kfifo_out + * - Replace the use of kfifo_put into kfifo_in_spinlocked and kfifo_get + * into kfifo_out_spinlocked + * Note: the spinlock pointer formerly passed to kfifo_init/kfifo_alloc + * must be passed now to the kfifo_in_spinlocked and kfifo_out_spinlocked + * as the last parameter + * - The formerly __kfifo_* functions are renamed into kfifo_* + */ + +/* + * Note about locking : There is no locking required until only * one reader + * and one writer is using the fifo and no kfifo_reset() will be * called + * kfifo_reset_out() can be safely used, until it will be only called + * in the reader thread. + * For multiple writer and one reader there is only a need to lock the writer. + * And vice versa for only one writer and multiple reader there is only a need + * to lock the reader. + */ + +#include <linux/kernel.h> +#include <linux/spinlock.h> +#include <linux/stddef.h> +#include <linux/scatterlist.h> + +struct __kfifo { + unsigned int in; + unsigned int out; + unsigned int mask; + unsigned int esize; + void *data; +}; + +#define __STRUCT_KFIFO_COMMON(datatype, recsize, ptrtype) \ + union { \ + struct __kfifo kfifo; \ + datatype *type; \ + char (*rectype)[recsize]; \ + ptrtype *ptr; \ + const ptrtype *ptr_const; \ + } + +#define __STRUCT_KFIFO(type, size, recsize, ptrtype) \ +{ \ + __STRUCT_KFIFO_COMMON(type, recsize, ptrtype); \ + type buf[((size < 2) || (size & (size - 1))) ? -1 : size]; \ +} + +#define STRUCT_KFIFO(type, size) \ + struct __STRUCT_KFIFO(type, size, 0, type) + +#define __STRUCT_KFIFO_PTR(type, recsize, ptrtype) \ +{ \ + __STRUCT_KFIFO_COMMON(type, recsize, ptrtype); \ + type buf[0]; \ +} + +#define STRUCT_KFIFO_PTR(type) \ + struct __STRUCT_KFIFO_PTR(type, 0, type) + +/* + * define compatibility "struct kfifo" for dynamic allocated fifos + */ +struct kfifo __STRUCT_KFIFO_PTR(unsigned char, 0, void); + +#define STRUCT_KFIFO_REC_1(size) \ + struct __STRUCT_KFIFO(unsigned char, size, 1, void) + +#define STRUCT_KFIFO_REC_2(size) \ + struct __STRUCT_KFIFO(unsigned char, size, 2, void) + +/* + * define kfifo_rec types + */ +struct kfifo_rec_ptr_1 __STRUCT_KFIFO_PTR(unsigned char, 1, void); +struct kfifo_rec_ptr_2 __STRUCT_KFIFO_PTR(unsigned char, 2, void); + +/* + * helper macro to distinguish between real in place fifo where the fifo + * array is a part of the structure and the fifo type where the array is + * outside of the fifo structure. + */ +#define __is_kfifo_ptr(fifo) (sizeof(*fifo) == sizeof(struct __kfifo)) + +/** + * DECLARE_KFIFO_PTR - macro to declare a fifo pointer object + * @fifo: name of the declared fifo + * @type: type of the fifo elements + */ +#define DECLARE_KFIFO_PTR(fifo, type) STRUCT_KFIFO_PTR(type) fifo + +/** + * DECLARE_KFIFO - macro to declare a fifo object + * @fifo: name of the declared fifo + * @type: type of the fifo elements + * @size: the number of elements in the fifo, this must be a power of 2 + */ +#define DECLARE_KFIFO(fifo, type, size) STRUCT_KFIFO(type, size) fifo + +/** + * INIT_KFIFO - Initialize a fifo declared by DECLARE_KFIFO + * @fifo: name of the declared fifo datatype + */ +#define INIT_KFIFO(fifo) \ +(void)({ \ + typeof(&(fifo)) __tmp = &(fifo); \ + struct __kfifo *__kfifo = &__tmp->kfifo; \ + __kfifo->in = 0; \ + __kfifo->out = 0; \ + __kfifo->mask = __is_kfifo_ptr(__tmp) ? 0 : ARRAY_SIZE(__tmp->buf) - 1;\ + __kfifo->esize = sizeof(*__tmp->buf); \ + __kfifo->data = __is_kfifo_ptr(__tmp) ? NULL : __tmp->buf; \ +}) + +/** + * DEFINE_KFIFO - macro to define and initialize a fifo + * @fifo: name of the declared fifo datatype + * @type: type of the fifo elements + * @size: the number of elements in the fifo, this must be a power of 2 + * + * Note: the macro can be used for global and local fifo data type variables. + */ +#define DEFINE_KFIFO(fifo, type, size) \ + DECLARE_KFIFO(fifo, type, size) = \ + (typeof(fifo)) { \ + { \ + { \ + .in = 0, \ + .out = 0, \ + .mask = __is_kfifo_ptr(&(fifo)) ? \ + 0 : \ + ARRAY_SIZE((fifo).buf) - 1, \ + .esize = sizeof(*(fifo).buf), \ + .data = __is_kfifo_ptr(&(fifo)) ? \ + NULL : \ + (fifo).buf, \ + } \ + } \ + } + + +static inline unsigned int __must_check +__kfifo_uint_must_check_helper(unsigned int val) +{ + return val; +} + +static inline int __must_check +__kfifo_int_must_check_helper(int val) +{ + return val; +} + +#define __kfifo_alloc LINUX_BACKPORT(__kfifo_alloc) +extern int __kfifo_alloc(struct __kfifo *fifo, unsigned int size, + size_t esize, gfp_t gfp_mask); +#define __kfifo_free LINUX_BACKPORT(__kfifo_free) +extern void __kfifo_free(struct __kfifo *fifo); + +#define __kfifo_init LINUX_BACKPORT(__kfifo_init) +extern int __kfifo_init(struct __kfifo *fifo, void *buffer, + unsigned int size, size_t esize); + +#define __kfifo_in LINUX_BACKPORT(__kfifo_in) +extern unsigned int __kfifo_in(struct __kfifo *fifo, + const void *buf, unsigned int len); + +#define __kfifo_out LINUX_BACKPORT(__kfifo_out) +extern unsigned int __kfifo_out(struct __kfifo *fifo, + void *buf, unsigned int len); + +#define __kfifo_from_user LINUX_BACKPORT(__kfifo_from_user) +extern int __kfifo_from_user(struct __kfifo *fifo, + const void __user *from, unsigned long len, unsigned int *copied); + +#define __kfifo_to_user LINUX_BACKPORT(__kfifo_to_user) +extern int __kfifo_to_user(struct __kfifo *fifo, + void __user *to, unsigned long len, unsigned int *copied); + +#define __kfifo_dma_in_prepare LINUX_BACKPORT(__kfifo_dma_in_prepare) +extern unsigned int __kfifo_dma_in_prepare(struct __kfifo *fifo, + struct scatterlist *sgl, int nents, unsigned int len); + +#define __kfifo_dma_out_prepare LINUX_BACKPORT(__kfifo_dma_out_prepare) +extern unsigned int __kfifo_dma_out_prepare(struct __kfifo *fifo, + struct scatterlist *sgl, int nents, unsigned int len); + +#define __kfifo_out_peek LINUX_BACKPORT(__kfifo_out_peek) +extern unsigned int __kfifo_out_peek(struct __kfifo *fifo, + void *buf, unsigned int len); + +#define __kfifo_in_r LINUX_BACKPORT(__kfifo_in_r) +extern unsigned int __kfifo_in_r(struct __kfifo *fifo, + const void *buf, unsigned int len, size_t recsize); + +#define __kfifo_out_r LINUX_BACKPORT(__kfifo_out_r) +extern unsigned int __kfifo_out_r(struct __kfifo *fifo, + void *buf, unsigned int len, size_t recsize); + +#define __kfifo_from_user_r LINUX_BACKPORT(__kfifo_from_user_r) +extern int __kfifo_from_user_r(struct __kfifo *fifo, + const void __user *from, unsigned long len, unsigned int *copied, + size_t recsize); + +#define __kfifo_to_user_r LINUX_BACKPORT(__kfifo_to_user_r) +extern int __kfifo_to_user_r(struct __kfifo *fifo, void __user *to, + unsigned long len, unsigned int *copied, size_t recsize); + +#define __kfifo_dma_in_prepare_r LINUX_BACKPORT(__kfifo_dma_in_prepare_r) +extern unsigned int __kfifo_dma_in_prepare_r(struct __kfifo *fifo, + struct scatterlist *sgl, int nents, unsigned int len, size_t recsize); + +#define __kfifo_dma_in_finish_r LINUX_BACKPORT(__kfifo_dma_in_finish_r) +extern void __kfifo_dma_in_finish_r(struct __kfifo *fifo, + unsigned int len, size_t recsize); + +#define __kfifo_dma_out_prepare_r LINUX_BACKPORT(__kfifo_dma_out_prepare_r) +extern unsigned int __kfifo_dma_out_prepare_r(struct __kfifo *fifo, + struct scatterlist *sgl, int nents, unsigned int len, size_t recsize); + +#define __kfifo_dma_out_finish_r LINUX_BACKPORT(__kfifo_dma_out_finish_r) +extern void __kfifo_dma_out_finish_r(struct __kfifo *fifo, size_t recsize); + +#define __kfifo_len_r LINUX_BACKPORT(__kfifo_len_r) +extern unsigned int __kfifo_len_r(struct __kfifo *fifo, size_t recsize); + +#define __kfifo_skip_r LINUX_BACKPORT(__kfifo_skip_r) +extern void __kfifo_skip_r(struct __kfifo *fifo, size_t recsize); + +#define __kfifo_out_peek_r LINUX_BACKPORT(__kfifo_out_peek_r) +extern unsigned int __kfifo_out_peek_r(struct __kfifo *fifo, + void *buf, unsigned int len, size_t recsize); + +#define __kfifo_max_r LINUX_BACKPORT(__kfifo_max_r) +extern unsigned int __kfifo_max_r(unsigned int len, size_t recsize); + +/** + * kfifo_initialized - Check if the fifo is initialized + * @fifo: address of the fifo to check + * + * Return %true if fifo is initialized, otherwise %false. + * Assumes the fifo was 0 before. + */ +#define kfifo_initialized(fifo) ((fifo)->kfifo.mask) + +/** + * kfifo_esize - returns the size of the element managed by the fifo + * @fifo: address of the fifo to be used + */ +#define kfifo_esize(fifo) ((fifo)->kfifo.esize) + +/** + * kfifo_recsize - returns the size of the record length field + * @fifo: address of the fifo to be used + */ +#define kfifo_recsize(fifo) (sizeof(*(fifo)->rectype)) + +/** + * kfifo_size - returns the size of the fifo in elements + * @fifo: address of the fifo to be used + */ +#define kfifo_size(fifo) ((fifo)->kfifo.mask + 1) + +/** + * kfifo_reset - removes the entire fifo content + * @fifo: address of the fifo to be used + * + * Note: usage of kfifo_reset() is dangerous. It should be only called when the + * fifo is exclusived locked or when it is secured that no other thread is + * accessing the fifo. + */ +#define kfifo_reset(fifo) \ +(void)({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + __tmp->kfifo.in = __tmp->kfifo.out = 0; \ +}) + +/** + * kfifo_reset_out - skip fifo content + * @fifo: address of the fifo to be used + * + * Note: The usage of kfifo_reset_out() is safe until it will be only called + * from the reader thread and there is only one concurrent reader. Otherwise + * it is dangerous and must be handled in the same way as kfifo_reset(). + */ +#define kfifo_reset_out(fifo) \ +(void)({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + __tmp->kfifo.out = __tmp->kfifo.in; \ +}) + +/** + * kfifo_len - returns the number of used elements in the fifo + * @fifo: address of the fifo to be used + */ +#define kfifo_len(fifo) \ +({ \ + typeof((fifo) + 1) __tmpl = (fifo); \ + __tmpl->kfifo.in - __tmpl->kfifo.out; \ +}) + +/** + * kfifo_is_empty - returns true if the fifo is empty + * @fifo: address of the fifo to be used + */ +#define kfifo_is_empty(fifo) \ +({ \ + typeof((fifo) + 1) __tmpq = (fifo); \ + __tmpq->kfifo.in == __tmpq->kfifo.out; \ +}) + +/** + * kfifo_is_full - returns true if the fifo is full + * @fifo: address of the fifo to be used + */ +#define kfifo_is_full(fifo) \ +({ \ + typeof((fifo) + 1) __tmpq = (fifo); \ + kfifo_len(__tmpq) > __tmpq->kfifo.mask; \ +}) + +/** + * kfifo_avail - returns the number of unused elements in the fifo + * @fifo: address of the fifo to be used + */ +#define kfifo_avail(fifo) \ +__kfifo_uint_must_check_helper( \ +({ \ + typeof((fifo) + 1) __tmpq = (fifo); \ + const size_t __recsize = sizeof(*__tmpq->rectype); \ + unsigned int __avail = kfifo_size(__tmpq) - kfifo_len(__tmpq); \ + (__recsize) ? ((__avail <= __recsize) ? 0 : \ + __kfifo_max_r(__avail - __recsize, __recsize)) : \ + __avail; \ +}) \ +) + +/** + * kfifo_skip - skip output data + * @fifo: address of the fifo to be used + */ +#define kfifo_skip(fifo) \ +(void)({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + const size_t __recsize = sizeof(*__tmp->rectype); \ + struct __kfifo *__kfifo = &__tmp->kfifo; \ + if (__recsize) \ + __kfifo_skip_r(__kfifo, __recsize); \ + else \ + __kfifo->out++; \ +}) + +/** + * kfifo_peek_len - gets the size of the next fifo record + * @fifo: address of the fifo to be used + * + * This function returns the size of the next fifo record in number of bytes. + */ +#define kfifo_peek_len(fifo) \ +__kfifo_uint_must_check_helper( \ +({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + const size_t __recsize = sizeof(*__tmp->rectype); \ + struct __kfifo *__kfifo = &__tmp->kfifo; \ + (!__recsize) ? kfifo_len(__tmp) * sizeof(*__tmp->type) : \ + __kfifo_len_r(__kfifo, __recsize); \ +}) \ +) + +/** + * kfifo_alloc - dynamically allocates a new fifo buffer + * @fifo: pointer to the fifo + * @size: the number of elements in the fifo, this must be a power of 2 + * @gfp_mask: get_free_pages mask, passed to kmalloc() + * + * This macro dynamically allocates a new fifo buffer. + * + * The numer of elements will be rounded-up to a power of 2. + * The fifo will be release with kfifo_free(). + * Return 0 if no error, otherwise an error code. + */ +#define kfifo_alloc(fifo, size, gfp_mask) \ +__kfifo_int_must_check_helper( \ +({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + struct __kfifo *__kfifo = &__tmp->kfifo; \ + __is_kfifo_ptr(__tmp) ? \ + __kfifo_alloc(__kfifo, size, sizeof(*__tmp->type), gfp_mask) : \ + -EINVAL; \ +}) \ +) + +/** + * kfifo_free - frees the fifo + * @fifo: the fifo to be freed + */ +#define kfifo_free(fifo) \ +({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + struct __kfifo *__kfifo = &__tmp->kfifo; \ + if (__is_kfifo_ptr(__tmp)) \ + __kfifo_free(__kfifo); \ +}) + +/** + * kfifo_init - initialize a fifo using a preallocated buffer + * @fifo: the fifo to assign the buffer + * @buffer: the preallocated buffer to be used + * @size: the size of the internal buffer, this have to be a power of 2 + * + * This macro initialize a fifo using a preallocated buffer. + * + * The numer of elements will be rounded-up to a power of 2. + * Return 0 if no error, otherwise an error code. + */ +#define kfifo_init(fifo, buffer, size) \ +({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + struct __kfifo *__kfifo = &__tmp->kfifo; \ + __is_kfifo_ptr(__tmp) ? \ + __kfifo_init(__kfifo, buffer, size, sizeof(*__tmp->type)) : \ + -EINVAL; \ +}) + +/** + * kfifo_put - put data into the fifo + * @fifo: address of the fifo to be used + * @val: the data to be added + * + * This macro copies the given value into the fifo. + * It returns 0 if the fifo was full. Otherwise it returns the number + * processed elements. + * + * Note that with only one concurrent reader and one concurrent + * writer, you don't need extra locking to use these macro. + */ +#define kfifo_put(fifo, val) \ +({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + typeof((val) + 1) __val = (val); \ + unsigned int __ret; \ + const size_t __recsize = sizeof(*__tmp->rectype); \ + struct __kfifo *__kfifo = &__tmp->kfifo; \ + if (0) { \ + typeof(__tmp->ptr_const) __dummy __attribute__ ((unused)); \ + __dummy = (typeof(__val))NULL; \ + } \ + if (__recsize) \ + __ret = __kfifo_in_r(__kfifo, __val, sizeof(*__val), \ + __recsize); \ + else { \ + __ret = !kfifo_is_full(__tmp); \ + if (__ret) { \ + (__is_kfifo_ptr(__tmp) ? \ + ((typeof(__tmp->type))__kfifo->data) : \ + (__tmp->buf) \ + )[__kfifo->in & __tmp->kfifo.mask] = \ + *(typeof(__tmp->type))__val; \ + smp_wmb(); \ + __kfifo->in++; \ + } \ + } \ + __ret; \ +}) + +/** + * kfifo_get - get data from the fifo + * @fifo: address of the fifo to be used + * @val: the var where to store the data to be added + * + * This macro reads the data from the fifo. + * It returns 0 if the fifo was empty. Otherwise it returns the number + * processed elements. + * + * Note that with only one concurrent reader and one concurrent + * writer, you don't need extra locking to use these macro. + */ +#define kfifo_get(fifo, val) \ +__kfifo_uint_must_check_helper( \ +({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + typeof((val) + 1) __val = (val); \ + unsigned int __ret; \ + const size_t __recsize = sizeof(*__tmp->rectype); \ + struct __kfifo *__kfifo = &__tmp->kfifo; \ + if (0) \ + __val = (typeof(__tmp->ptr))0; \ + if (__recsize) \ + __ret = __kfifo_out_r(__kfifo, __val, sizeof(*__val), \ + __recsize); \ + else { \ + __ret = !kfifo_is_empty(__tmp); \ + if (__ret) { \ + *(typeof(__tmp->type))__val = \ + (__is_kfifo_ptr(__tmp) ? \ + ((typeof(__tmp->type))__kfifo->data) : \ + (__tmp->buf) \ + )[__kfifo->out & __tmp->kfifo.mask]; \ + smp_wmb(); \ + __kfifo->out++; \ + } \ + } \ + __ret; \ +}) \ +) + +/** + * kfifo_peek - get data from the fifo without removing + * @fifo: address of the fifo to be used + * @val: the var where to store the data to be added + * + * This reads the data from the fifo without removing it from the fifo. + * It returns 0 if the fifo was empty. Otherwise it returns the number + * processed elements. + * + * Note that with only one concurrent reader and one concurrent + * writer, you don't need extra locking to use these macro. + */ +#define kfifo_peek(fifo, val) \ +__kfifo_uint_must_check_helper( \ +({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + typeof((val) + 1) __val = (val); \ + unsigned int __ret; \ + const size_t __recsize = sizeof(*__tmp->rectype); \ + struct __kfifo *__kfifo = &__tmp->kfifo; \ + if (0) \ + __val = (typeof(__tmp->ptr))NULL; \ + if (__recsize) \ + __ret = __kfifo_out_peek_r(__kfifo, __val, sizeof(*__val), \ + __recsize); \ + else { \ + __ret = !kfifo_is_empty(__tmp); \ + if (__ret) { \ + *(typeof(__tmp->type))__val = \ + (__is_kfifo_ptr(__tmp) ? \ + ((typeof(__tmp->type))__kfifo->data) : \ + (__tmp->buf) \ + )[__kfifo->out & __tmp->kfifo.mask]; \ + smp_wmb(); \ + } \ + } \ + __ret; \ +}) \ +) + +/** + * kfifo_in - put data into the fifo + * @fifo: address of the fifo to be used + * @buf: the data to be added + * @n: number of elements to be added + * + * This macro copies the given buffer into the fifo and returns the + * number of copied elements. + * + * Note that with only one concurrent reader and one concurrent + * writer, you don't need extra locking to use these macro. + */ +#define kfifo_in(fifo, buf, n) \ +({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + typeof((buf) + 1) __buf = (buf); \ + unsigned long __n = (n); \ + const size_t __recsize = sizeof(*__tmp->rectype); \ + struct __kfifo *__kfifo = &__tmp->kfifo; \ + if (0) { \ + typeof(__tmp->ptr_const) __dummy __attribute__ ((unused)); \ + __dummy = (typeof(__buf))NULL; \ + } \ + (__recsize) ?\ + __kfifo_in_r(__kfifo, __buf, __n, __recsize) : \ + __kfifo_in(__kfifo, __buf, __n); \ +}) + +/** + * kfifo_in_spinlocked - put data into the fifo using a spinlock for locking + * @fifo: address of the fifo to be used + * @buf: the data to be added + * @n: number of elements to be added + * @lock: pointer to the spinlock to use for locking + * + * This macro copies the given values buffer into the fifo and returns the + * number of copied elements. + */ +#define kfifo_in_spinlocked(fifo, buf, n, lock) \ +({ \ + unsigned long __flags; \ + unsigned int __ret; \ + spin_lock_irqsave(lock, __flags); \ + __ret = kfifo_in(fifo, buf, n); \ + spin_unlock_irqrestore(lock, __flags); \ + __ret; \ +}) + +/* alias for kfifo_in_spinlocked, will be removed in a future release */ +#define kfifo_in_locked(fifo, buf, n, lock) \ + kfifo_in_spinlocked(fifo, buf, n, lock) + +/** + * kfifo_out - get data from the fifo + * @fifo: address of the fifo to be used + * @buf: pointer to the storage buffer + * @n: max. number of elements to get + * + * This macro get some data from the fifo and return the numbers of elements + * copied. + * + * Note that with only one concurrent reader and one concurrent + * writer, you don't need extra locking to use these macro. + */ +#define kfifo_out(fifo, buf, n) \ +__kfifo_uint_must_check_helper( \ +({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + typeof((buf) + 1) __buf = (buf); \ + unsigned long __n = (n); \ + const size_t __recsize = sizeof(*__tmp->rectype); \ + struct __kfifo *__kfifo = &__tmp->kfifo; \ + if (0) { \ + typeof(__tmp->ptr) __dummy = NULL; \ + __buf = __dummy; \ + } \ + (__recsize) ?\ + __kfifo_out_r(__kfifo, __buf, __n, __recsize) : \ + __kfifo_out(__kfifo, __buf, __n); \ +}) \ +) + +/** + * kfifo_out_spinlocked - get data from the fifo using a spinlock for locking + * @fifo: address of the fifo to be used + * @buf: pointer to the storage buffer + * @n: max. number of elements to get + * @lock: pointer to the spinlock to use for locking + * + * This macro get the data from the fifo and return the numbers of elements + * copied. + */ +#define kfifo_out_spinlocked(fifo, buf, n, lock) \ +__kfifo_uint_must_check_helper( \ +({ \ + unsigned long __flags; \ + unsigned int __ret; \ + spin_lock_irqsave(lock, __flags); \ + __ret = kfifo_out(fifo, buf, n); \ + spin_unlock_irqrestore(lock, __flags); \ + __ret; \ +}) \ +) + +/* alias for kfifo_out_spinlocked, will be removed in a future release */ +#define kfifo_out_locked(fifo, buf, n, lock) \ + kfifo_out_spinlocked(fifo, buf, n, lock) + +/** + * kfifo_from_user - puts some data from user space into the fifo + * @fifo: address of the fifo to be used + * @from: pointer to the data to be added + * @len: the length of the data to be added + * @copied: pointer to output variable to store the number of copied bytes + * + * This macro copies at most @len bytes from the @from into the + * fifo, depending of the available space and returns -EFAULT/0. + * + * Note that with only one concurrent reader and one concurrent + * writer, you don't need extra locking to use these macro. + */ +#define kfifo_from_user(fifo, from, len, copied) \ +__kfifo_uint_must_check_helper( \ +({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + const void __user *__from = (from); \ + unsigned int __len = (len); \ + unsigned int *__copied = (copied); \ + const size_t __recsize = sizeof(*__tmp->rectype); \ + struct __kfifo *__kfifo = &__tmp->kfifo; \ + (__recsize) ? \ + __kfifo_from_user_r(__kfifo, __from, __len, __copied, __recsize) : \ + __kfifo_from_user(__kfifo, __from, __len, __copied); \ +}) \ +) + +/** + * kfifo_to_user - copies data from the fifo into user space + * @fifo: address of the fifo to be used + * @to: where the data must be copied + * @len: the size of the destination buffer + * @copied: pointer to output variable to store the number of copied bytes + * + * This macro copies at most @len bytes from the fifo into the + * @to buffer and returns -EFAULT/0. + * + * Note that with only one concurrent reader and one concurrent + * writer, you don't need extra locking to use these macro. + */ +#define kfifo_to_user(fifo, to, len, copied) \ +__kfifo_uint_must_check_helper( \ +({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + void __user *__to = (to); \ + unsigned int __len = (len); \ + unsigned int *__copied = (copied); \ + const size_t __recsize = sizeof(*__tmp->rectype); \ + struct __kfifo *__kfifo = &__tmp->kfifo; \ + (__recsize) ? \ + __kfifo_to_user_r(__kfifo, __to, __len, __copied, __recsize) : \ + __kfifo_to_user(__kfifo, __to, __len, __copied); \ +}) \ +) + +/** + * kfifo_dma_in_prepare - setup a scatterlist for DMA input + * @fifo: address of the fifo to be used + * @sgl: pointer to the scatterlist array + * @nents: number of entries in the scatterlist array + * @len: number of elements to transfer + * + * This macro fills a scatterlist for DMA input. + * It returns the number entries in the scatterlist array. + * + * Note that with only one concurrent reader and one concurrent + * writer, you don't need extra locking to use these macros. + */ +#define kfifo_dma_in_prepare(fifo, sgl, nents, len) \ +({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + struct scatterlist *__sgl = (sgl); \ + int __nents = (nents); \ + unsigned int __len = (len); \ + const size_t __recsize = sizeof(*__tmp->rectype); \ + struct __kfifo *__kfifo = &__tmp->kfifo; \ + (__recsize) ? \ + __kfifo_dma_in_prepare_r(__kfifo, __sgl, __nents, __len, __recsize) : \ + __kfifo_dma_in_prepare(__kfifo, __sgl, __nents, __len); \ +}) + +/** + * kfifo_dma_in_finish - finish a DMA IN operation + * @fifo: address of the fifo to be used + * @len: number of bytes to received + * + * This macro finish a DMA IN operation. The in counter will be updated by + * the len parameter. No error checking will be done. + * + * Note that with only one concurrent reader and one concurrent + * writer, you don't need extra locking to use these macros. + */ +#define kfifo_dma_in_finish(fifo, len) \ +(void)({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + unsigned int __len = (len); \ + const size_t __recsize = sizeof(*__tmp->rectype); \ + struct __kfifo *__kfifo = &__tmp->kfifo; \ + if (__recsize) \ + __kfifo_dma_in_finish_r(__kfifo, __len, __recsize); \ + else \ + __kfifo->in += __len / sizeof(*__tmp->type); \ +}) + +/** + * kfifo_dma_out_prepare - setup a scatterlist for DMA output + * @fifo: address of the fifo to be used + * @sgl: pointer to the scatterlist array + * @nents: number of entries in the scatterlist array + * @len: number of elements to transfer + * + * This macro fills a scatterlist for DMA output which at most @len bytes + * to transfer. + * It returns the number entries in the scatterlist array. + * A zero means there is no space available and the scatterlist is not filled. + * + * Note that with only one concurrent reader and one concurrent + * writer, you don't need extra locking to use these macros. + */ +#define kfifo_dma_out_prepare(fifo, sgl, nents, len) \ +({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + struct scatterlist *__sgl = (sgl); \ + int __nents = (nents); \ + unsigned int __len = (len); \ + const size_t __recsize = sizeof(*__tmp->rectype); \ + struct __kfifo *__kfifo = &__tmp->kfifo; \ + (__recsize) ? \ + __kfifo_dma_out_prepare_r(__kfifo, __sgl, __nents, __len, __recsize) : \ + __kfifo_dma_out_prepare(__kfifo, __sgl, __nents, __len); \ +}) + +/** + * kfifo_dma_out_finish - finish a DMA OUT operation + * @fifo: address of the fifo to be used + * @len: number of bytes transferd + * + * This macro finish a DMA OUT operation. The out counter will be updated by + * the len parameter. No error checking will be done. + * + * Note that with only one concurrent reader and one concurrent + * writer, you don't need extra locking to use these macros. + */ +#define kfifo_dma_out_finish(fifo, len) \ +(void)({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + unsigned int __len = (len); \ + const size_t __recsize = sizeof(*__tmp->rectype); \ + struct __kfifo *__kfifo = &__tmp->kfifo; \ + if (__recsize) \ + __kfifo_dma_out_finish_r(__kfifo, __recsize); \ + else \ + __kfifo->out += __len / sizeof(*__tmp->type); \ +}) + +/** + * kfifo_out_peek - gets some data from the fifo + * @fifo: address of the fifo to be used + * @buf: pointer to the storage buffer + * @n: max. number of elements to get + * + * This macro get the data from the fifo and return the numbers of elements + * copied. The data is not removed from the fifo. + * + * Note that with only one concurrent reader and one concurrent + * writer, you don't need extra locking to use these macro. + */ +#define kfifo_out_peek(fifo, buf, n) \ +__kfifo_uint_must_check_helper( \ +({ \ + typeof((fifo) + 1) __tmp = (fifo); \ + typeof((buf) + 1) __buf = (buf); \ + unsigned long __n = (n); \ + const size_t __recsize = sizeof(*__tmp->rectype); \ + struct __kfifo *__kfifo = &__tmp->kfifo; \ + if (0) { \ + typeof(__tmp->ptr) __dummy __attribute__ ((unused)) = NULL; \ + __buf = __dummy; \ + } \ + (__recsize) ? \ + __kfifo_out_peek_r(__kfifo, __buf, __n, __recsize) : \ + __kfifo_out_peek(__kfifo, __buf, __n); \ +}) \ +) +#endif +#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,36)) */ diff --git a/backport-include/linux/kmemleak.h b/backport-include/linux/kmemleak.h new file mode 100644 index 0000000..99fff66 --- /dev/null +++ b/backport-include/linux/kmemleak.h @@ -0,0 +1,24 @@ +#include <linux/version.h> + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,30)) +#include_next <linux/kmemleak.h> +#else +/* + * kmemleak was introduced on 2.6.31, since older kernels do not have + * we simply ignore its tuning. + */ +static inline void kmemleak_ignore(const void *ptr) +{ + return; +} + +static inline void kmemleak_not_leak(const void *ptr) +{ + return; +} + +static inline void kmemleak_no_scan(const void *ptr) +{ + return; +} +#endif diff --git a/backport-include/linux/kref.h b/backport-include/linux/kref.h new file mode 100644 index 0000000..d7b6381 --- /dev/null +++ b/backport-include/linux/kref.h @@ -0,0 +1,26 @@ +#ifndef __BACKPORT_KREF_H +#define __BACKPORT_KREF_H +#include_next <linux/kref.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) +#include <linux/atomic.h> + +/* This was backported to some kernels (e.g. 3.2.44 and 3.4.41), mask it */ +#define kref_get_unless_zero LINUX_BACKPORT(kref_get_unless_zero) + +/* This backports: + * + * commit 4b20db3de8dab005b07c74161cb041db8c5ff3a7 + * Author: Thomas Hellstrom <thellstrom@vmware.com> + * Date: Tue Nov 6 11:31:49 2012 +0000 + * + * kref: Implement kref_get_unless_zero v3 + */ +static inline int __must_check kref_get_unless_zero(struct kref *kref) +{ + return atomic_add_unless(&kref->refcount, 1, 0); +} +#endif + +#endif /* __BACKPORT_KREF_H */ diff --git a/backport-include/linux/leds.h b/backport-include/linux/leds.h new file mode 100644 index 0000000..b8a9e2a --- /dev/null +++ b/backport-include/linux/leds.h @@ -0,0 +1,45 @@ +#ifndef __BACKPORT_LINUX_LEDS_H +#define __BACKPORT_LINUX_LEDS_H +#include_next <linux/leds.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0) +/* + * Backports + * + * commit 959d62fa865d2e616b61a509e1cc5b88741f065e + * Author: Shuah Khan <shuahkhan@gmail.com> + * Date: Thu Jun 14 04:34:30 2012 +0800 + * + * leds: Rename led_brightness_set() to led_set_brightness() + * + * Rename leds external interface led_brightness_set() to led_set_brightness(). + * This is the second phase of the change to reduce confusion between the + * leds internal and external interfaces that set brightness. With this change, + * now the external interface is led_set_brightness(). The first phase renamed + * the internal interface led_set_brightness() to __led_set_brightness(). + * There are no changes to the interface implementations. + * + * Signed-off-by: Shuah Khan <shuahkhan@gmail.com> + * Signed-off-by: Bryan Wu <bryan.wu@canonical.com> + */ +#define led_set_brightness(_dev, _switch) led_brightness_set(_dev, _switch) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) && \ + !defined(CPTCFG_BACKPORT_BUILD_LEDS) +extern void led_blink_set(struct led_classdev *led_cdev, + unsigned long *delay_on, + unsigned long *delay_off); + +#define led_classdev_unregister compat_led_classdev_unregister +extern void compat_led_classdev_unregister(struct led_classdev *led_cdev); + +#define led_brightness_set compat_led_brightness_set +extern void compat_led_brightness_set(struct led_classdev *led_cdev, + enum led_brightness brightness); +#endif + +#include <backport/leds-disabled.h> + +#endif /* __BACKPORT_LINUX_LEDS_H */ diff --git a/backport-include/linux/list.h b/backport-include/linux/list.h new file mode 100644 index 0000000..fb5ee4b --- /dev/null +++ b/backport-include/linux/list.h @@ -0,0 +1,118 @@ +#ifndef __BACKPORT_LIST_H +#define __BACKPORT_LIST_H +#include_next <linux/list.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0) +/** + * backport: + * + * commit 0bbacca7c3911451cea923b0ad6389d58e3d9ce9 + * Author: Sasha Levin <sasha.levin@oracle.com> + * Date: Thu Feb 7 12:32:18 2013 +1100 + * + * hlist: drop the node parameter from iterators + */ +#include <backport/magic.h> + +#undef hlist_entry_safe +#define hlist_entry_safe(ptr, type, member) \ + (ptr) ? hlist_entry(ptr, type, member) : NULL + +#define hlist_for_each_entry4(tpos, pos, head, member) \ + for (pos = (head)->first; \ + pos && \ + ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;});\ + pos = pos->next) + +#define hlist_for_each_entry_safe5(tpos, pos, n, head, member) \ + for (pos = (head)->first; \ + pos && ({ n = pos->next; 1; }) && \ + ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;});\ + pos = n) + +#define hlist_for_each_entry3(pos, head, member) \ + for (pos = hlist_entry_safe((head)->first, typeof(*(pos)), member); \ + pos; \ + pos = hlist_entry_safe((pos)->member.next, typeof(*(pos)), member)) + +#define hlist_for_each_entry_safe4(pos, n, head, member) \ + for (pos = hlist_entry_safe((head)->first, typeof(*pos), member); \ + pos && ({ n = pos->member.next; 1; }); \ + pos = hlist_entry_safe(n, typeof(*pos), member)) + +#undef hlist_for_each_entry +#define hlist_for_each_entry(...) \ + macro_dispatcher(hlist_for_each_entry, __VA_ARGS__)(__VA_ARGS__) +#undef hlist_for_each_entry_safe +#define hlist_for_each_entry_safe(...) \ + macro_dispatcher(hlist_for_each_entry_safe, __VA_ARGS__)(__VA_ARGS__) + +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) +static inline int list_is_singular(const struct list_head *head) +{ + return !list_empty(head) && (head->next == head->prev); +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) +static inline void __list_cut_position(struct list_head *list, + struct list_head *head, struct list_head *entry) +{ + struct list_head *new_first = entry->next; + list->next = head->next; + list->next->prev = list; + list->prev = entry; + entry->next = list; + head->next = new_first; + new_first->prev = head; +} + +static inline void list_cut_position(struct list_head *list, + struct list_head *head, struct list_head *entry) +{ + if (list_empty(head)) + return; + if (list_is_singular(head) && + (head->next != entry && head != entry)) + return; + if (entry == head) + INIT_LIST_HEAD(list); + else + __list_cut_position(list, head, entry); +} + +static inline void __compat_list_splice_new_27(const struct list_head *list, + struct list_head *prev, + struct list_head *next) +{ + struct list_head *first = list->next; + struct list_head *last = list->prev; + + first->prev = prev; + prev->next = first; + + last->next = next; + next->prev = last; +} + +static inline void list_splice_tail(struct list_head *list, + struct list_head *head) +{ + if (!list_empty(list)) + __compat_list_splice_new_27(list, head->prev, head); +} + +static inline void list_splice_tail_init(struct list_head *list, + struct list_head *head) +{ + if (!list_empty(list)) { + __compat_list_splice_new_27(list, head->prev, head); + INIT_LIST_HEAD(list); + } +} +#endif + +#endif /* __BACKPORT_LIST_H */ diff --git a/backport-include/linux/lockdep.h b/backport-include/linux/lockdep.h new file mode 100644 index 0000000..c194713 --- /dev/null +++ b/backport-include/linux/lockdep.h @@ -0,0 +1,54 @@ +#ifndef __BACKPORT_LINUX_LOCKDEP_H +#define __BACKPORT_LINUX_LOCKDEP_H +#include_next <linux/lockdep.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) +/* Backport of: + * + * commit e159489baa717dbae70f9903770a6a4990865887 + * Author: Tejun Heo <tj@kernel.org> + * Date: Sun Jan 9 23:32:15 2011 +0100 + * + * workqueue: relax lockdep annotation on flush_work() + */ +#ifdef CONFIG_DEBUG_LOCK_ALLOC +# ifdef CONFIG_PROVE_LOCKING +# define lock_map_acquire_read(l) lock_acquire(l, 0, 0, 2, 2, NULL, _THIS_IP_) +# else +# define lock_map_acquire_read(l) lock_acquire(l, 0, 0, 2, 1, NULL, _THIS_IP_) +# endif +#else +# define lock_map_acquire_read(l) do { } while (0) +#endif + +#endif /* < 2.6.38 */ + +#ifndef lockdep_assert_held +#define lockdep_assert_held(l) do { } while (0) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) +/* Backport of: + * + * commit 3295f0ef9ff048a4619ede597ad9ec9cab725654 + * Author: Ingo Molnar <mingo@elte.hu> + * Date: Mon Aug 11 10:30:30 2008 +0200 + * + * lockdep: rename map_[acquire|release]() => lock_map_[acquire|release]() + */ +#ifdef CONFIG_DEBUG_LOCK_ALLOC +# ifdef CONFIG_PROVE_LOCKING +# define lock_map_acquire(l) lock_acquire(l, 0, 0, 0, 2, NULL, _THIS_IP_) +# else +# define lock_map_acquire(l) lock_acquire(l, 0, 0, 0, 1, NULL, _THIS_IP_) +# endif +# define lock_map_release(l) lock_release(l, 1, _THIS_IP_) +#else +# define lock_map_acquire(l) do { } while (0) +# define lock_map_release(l) do { } while (0) +#endif + +#endif /* < 2.6.27 */ + +#endif /* __BACKPORT_LINUX_LOCKDEP_H */ diff --git a/backport-include/linux/math64.h b/backport-include/linux/math64.h new file mode 100644 index 0000000..7f3a81b --- /dev/null +++ b/backport-include/linux/math64.h @@ -0,0 +1,41 @@ +#ifndef _COMPAT_LINUX_MATH64_H +#define _COMPAT_LINUX_MATH64_H 1 + +#include <linux/version.h> + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,25)) +#include_next <linux/math64.h> +#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,25)) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) +#if BITS_PER_LONG == 64 + +static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder) +{ + *remainder = dividend % divisor; + return dividend / divisor; +} + +#elif BITS_PER_LONG == 32 + +#ifndef div_u64_rem +static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder) +{ + *remainder = do_div(dividend, divisor); + return dividend; +} +#endif + +#endif /* BITS_PER_LONG */ + +#ifndef div_u64 +static inline u64 div_u64(u64 dividend, u32 divisor) +{ + u32 remainder; + return div_u64_rem(dividend, divisor, &remainder); +} +#endif + +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) */ + +#endif /* _COMPAT_LINUX_MATH64_H */ diff --git a/backport-include/linux/mdio.h b/backport-include/linux/mdio.h new file mode 100644 index 0000000..888bfee --- /dev/null +++ b/backport-include/linux/mdio.h @@ -0,0 +1,17 @@ +#ifndef __BACKPORT_LINUX_MDIO_H +#define __BACKPORT_LINUX_MDIO_H +#include_next <linux/mdio.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31) +#define mdio45_probe LINUX_BACKPORT(mdio45_probe) +#define mdio_set_flag LINUX_BACKPORT(mdio_set_flag) +#define mdio45_links_ok LINUX_BACKPORT(mdio45_links_ok) +#define mdio45_nway_restart LINUX_BACKPORT(mdio45_nway_restart) + +#define mdio45_ethtool_gset_npage LINUX_BACKPORT(mdio45_ethtool_gset_npage) +#define mdio45_ethtool_spauseparam_an LINUX_BACKPORT(mdio45_ethtool_spauseparam_an) +#define mdio_mii_ioctl LINUX_BACKPORT(mdio_mii_ioctl) +#endif + +#endif /* __BACKPORT_LINUX_MDIO_H */ diff --git a/backport-include/linux/mii.h b/backport-include/linux/mii.h new file mode 100644 index 0000000..9ce5700 --- /dev/null +++ b/backport-include/linux/mii.h @@ -0,0 +1,147 @@ +#ifndef __BACKPORT_LINUX_MII_H +#define __BACKPORT_LINUX_MII_H +#include_next <linux/mii.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) +#include <linux/ethtool.h> + +#define ethtool_adv_to_mii_adv_t LINUX_BACKPORT(ethtool_adv_to_mii_adv_t) +static inline u32 ethtool_adv_to_mii_adv_t(u32 ethadv) +{ + u32 result = 0; + + if (ethadv & ADVERTISED_10baseT_Half) + result |= ADVERTISE_10HALF; + if (ethadv & ADVERTISED_10baseT_Full) + result |= ADVERTISE_10FULL; + if (ethadv & ADVERTISED_100baseT_Half) + result |= ADVERTISE_100HALF; + if (ethadv & ADVERTISED_100baseT_Full) + result |= ADVERTISE_100FULL; + if (ethadv & ADVERTISED_Pause) + result |= ADVERTISE_PAUSE_CAP; + if (ethadv & ADVERTISED_Asym_Pause) + result |= ADVERTISE_PAUSE_ASYM; + + return result; +} + +#define mii_adv_to_ethtool_adv_t LINUX_BACKPORT(mii_adv_to_ethtool_adv_t) +static inline u32 mii_adv_to_ethtool_adv_t(u32 adv) +{ + u32 result = 0; + + if (adv & ADVERTISE_10HALF) + result |= ADVERTISED_10baseT_Half; + if (adv & ADVERTISE_10FULL) + result |= ADVERTISED_10baseT_Full; + if (adv & ADVERTISE_100HALF) + result |= ADVERTISED_100baseT_Half; + if (adv & ADVERTISE_100FULL) + result |= ADVERTISED_100baseT_Full; + if (adv & ADVERTISE_PAUSE_CAP) + result |= ADVERTISED_Pause; + if (adv & ADVERTISE_PAUSE_ASYM) + result |= ADVERTISED_Asym_Pause; + + return result; +} + +#define ethtool_adv_to_mii_ctrl1000_t LINUX_BACKPORT(ethtool_adv_to_mii_ctrl1000_t) +static inline u32 ethtool_adv_to_mii_ctrl1000_t(u32 ethadv) +{ + u32 result = 0; + + if (ethadv & ADVERTISED_1000baseT_Half) + result |= ADVERTISE_1000HALF; + if (ethadv & ADVERTISED_1000baseT_Full) + result |= ADVERTISE_1000FULL; + + return result; +} + +#define mii_ctrl1000_to_ethtool_adv_t LINUX_BACKPORT(mii_ctrl1000_to_ethtool_adv_t) +static inline u32 mii_ctrl1000_to_ethtool_adv_t(u32 adv) +{ + u32 result = 0; + + if (adv & ADVERTISE_1000HALF) + result |= ADVERTISED_1000baseT_Half; + if (adv & ADVERTISE_1000FULL) + result |= ADVERTISED_1000baseT_Full; + + return result; +} + +#define mii_lpa_to_ethtool_lpa_t LINUX_BACKPORT(mii_lpa_to_ethtool_lpa_t) +static inline u32 mii_lpa_to_ethtool_lpa_t(u32 lpa) +{ + u32 result = 0; + + if (lpa & LPA_LPACK) + result |= ADVERTISED_Autoneg; + + return result | mii_adv_to_ethtool_adv_t(lpa); +} + +#define mii_stat1000_to_ethtool_lpa_t LINUX_BACKPORT(mii_stat1000_to_ethtool_lpa_t) +static inline u32 mii_stat1000_to_ethtool_lpa_t(u32 lpa) +{ + u32 result = 0; + + if (lpa & LPA_1000HALF) + result |= ADVERTISED_1000baseT_Half; + if (lpa & LPA_1000FULL) + result |= ADVERTISED_1000baseT_Full; + + return result; +} + +#define ethtool_adv_to_mii_adv_x LINUX_BACKPORT(ethtool_adv_to_mii_adv_x) +static inline u32 ethtool_adv_to_mii_adv_x(u32 ethadv) +{ + u32 result = 0; + + if (ethadv & ADVERTISED_1000baseT_Half) + result |= ADVERTISE_1000XHALF; + if (ethadv & ADVERTISED_1000baseT_Full) + result |= ADVERTISE_1000XFULL; + if (ethadv & ADVERTISED_Pause) + result |= ADVERTISE_1000XPAUSE; + if (ethadv & ADVERTISED_Asym_Pause) + result |= ADVERTISE_1000XPSE_ASYM; + + return result; +} + +#define mii_adv_to_ethtool_adv_x LINUX_BACKPORT(mii_adv_to_ethtool_adv_x) +static inline u32 mii_adv_to_ethtool_adv_x(u32 adv) +{ + u32 result = 0; + + if (adv & ADVERTISE_1000XHALF) + result |= ADVERTISED_1000baseT_Half; + if (adv & ADVERTISE_1000XFULL) + result |= ADVERTISED_1000baseT_Full; + if (adv & ADVERTISE_1000XPAUSE) + result |= ADVERTISED_Pause; + if (adv & ADVERTISE_1000XPSE_ASYM) + result |= ADVERTISED_Asym_Pause; + + return result; +} + +#define mii_lpa_to_ethtool_lpa_x LINUX_BACKPORT(mii_lpa_to_ethtool_lpa_x) +static inline u32 mii_lpa_to_ethtool_lpa_x(u32 lpa) +{ + u32 result = 0; + + if (lpa & LPA_LPACK) + result |= ADVERTISED_Autoneg; + + return result | mii_adv_to_ethtool_adv_x(lpa); +} +#endif + +#endif /* __BACKPORT_LINUX_MII_H */ diff --git a/backport-include/linux/mm.h b/backport-include/linux/mm.h new file mode 100644 index 0000000..9ba1f00 --- /dev/null +++ b/backport-include/linux/mm.h @@ -0,0 +1,23 @@ +#ifndef __BACKPORT_MM_H +#define __BACKPORT_MM_H +#include_next <linux/mm.h> + +#ifndef VM_NODUMP +/* + * defined here to allow things to compile but technically + * using this for memory regions will yield in a no-op on newer + * kernels but on older kernels (v3.3 and older) this bit was used + * for VM_ALWAYSDUMP. The goal was to remove this bit moving forward + * and since we can't skip the core dump on old kernels we just make + * this bit name now a no-op. + * + * For details see commits: 909af7 accb61fe cdaaa7003 + */ +#define VM_NODUMP 0x0 +#endif + +#ifndef VM_DONTDUMP +#define VM_DONTDUMP VM_NODUMP +#endif + +#endif /* __BACKPORT_MM_H */ diff --git a/backport-include/linux/mmc/core.h b/backport-include/linux/mmc/core.h new file mode 100644 index 0000000..02d7a98 --- /dev/null +++ b/backport-include/linux/mmc/core.h @@ -0,0 +1,12 @@ +#ifndef __BACKPORT_MMC_CORE_H +#define __BACKPORT_MMC_CORE_H +#include <linux/version.h> +#include_next <linux/mmc/core.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) && \ + LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) +#define mmc_align_data_size LINUX_BACKPORT(mmc_align_data_size) +extern unsigned int mmc_align_data_size(struct mmc_card *, unsigned int); +#endif /* 2.6.24 - 2.6.26 */ + +#endif /* __BACKPORT_MMC_CORE_H */ diff --git a/backport-include/linux/mmc/host.h b/backport-include/linux/mmc/host.h new file mode 100644 index 0000000..49ca5c2 --- /dev/null +++ b/backport-include/linux/mmc/host.h @@ -0,0 +1,11 @@ +#ifndef __BACKPORT_MMC_HOST_H +#define __BACKPORT_MMC_HOST_H +#include <linux/version.h> +#include_next <linux/mmc/host.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) +/* rename member in struct mmc_host */ +#define max_segs max_hw_segs +#endif + +#endif /* __BACKPORT_MMC_HOST_H */ diff --git a/backport-include/linux/mmc/sdio.h b/backport-include/linux/mmc/sdio.h new file mode 100644 index 0000000..31d8833 --- /dev/null +++ b/backport-include/linux/mmc/sdio.h @@ -0,0 +1,21 @@ +#ifndef __BACKPORT_MMC_SDIO_H +#define __BACKPORT_MMC_SDIO_H +#include <linux/version.h> +#include_next <linux/mmc/sdio.h> + +/* backports b4625dab */ +#ifndef SDIO_CCCR_REV_3_00 +#define SDIO_CCCR_REV_3_00 3 /* CCCR/FBR Version 3.00 */ +#endif +#ifndef SDIO_SDIO_REV_3_00 +#define SDIO_SDIO_REV_3_00 4 /* SDIO Spec Version 3.00 */ +#endif + +#ifndef SDIO_BUS_ECSI +#define SDIO_BUS_ECSI 0x20 /* Enable continuous SPI interrupt */ +#endif +#ifndef SDIO_BUS_SCSI +#define SDIO_BUS_SCSI 0x40 /* Support continuous SPI interrupt */ +#endif + +#endif /* __BACKPORT_MMC_SDIO_H */ diff --git a/backport-include/linux/mmc/sdio_func.h b/backport-include/linux/mmc/sdio_func.h new file mode 100644 index 0000000..f32cafc --- /dev/null +++ b/backport-include/linux/mmc/sdio_func.h @@ -0,0 +1,40 @@ +#ifndef __BACKPORT_MMC_SDIO_FUNC_H +#define __BACKPORT_MMC_SDIO_FUNC_H +#include <linux/version.h> +#include_next <linux/mmc/sdio_func.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) +#define sdio_writeb_readb(func, write_byte, addr, err_ret) sdio_readb(func, addr, err_ret) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) +/* + * Backports da68c4eb25 + * sdio: introduce API for special power management features + * + * We simply carry around the data structures and flags, and + * make the host return no flags set by the driver. + * + * This is declared in mmc/pm.h upstream, but that files + * didn't exist before this commit and isn't included directly. + */ +typedef unsigned int mmc_pm_flag_t; + +#define MMC_PM_KEEP_POWER (1 << 0) /* preserve card power during suspend */ +#define MMC_PM_WAKE_SDIO_IRQ (1 << 1) /* wake up host system on SDIO IRQ assertion */ + +extern mmc_pm_flag_t sdio_get_host_pm_caps(struct sdio_func *func); +extern int sdio_set_host_pm_flags(struct sdio_func *func, mmc_pm_flag_t flags); +#endif + +#ifndef dev_to_sdio_func +#define dev_to_sdio_func(d) container_of(d, struct sdio_func, dev) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) && \ + LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24) +#define sdio_align_size LINUX_BACKPORT(sdio_align_size) +extern unsigned int sdio_align_size(struct sdio_func *func, unsigned int sz); +#endif /* 2.6.24 - 2.6.26 */ + +#endif /* __BACKPORT_MMC_SDIO_FUNC_H */ diff --git a/backport-include/linux/mmc/sdio_ids.h b/backport-include/linux/mmc/sdio_ids.h new file mode 100644 index 0000000..64fe8ec --- /dev/null +++ b/backport-include/linux/mmc/sdio_ids.h @@ -0,0 +1,14 @@ +#ifndef __BACKPORT_MMC_SDIO_IDS_H +#define __BACKPORT_MMC_SDIO_IDS_H +#include <linux/version.h> +#include_next <linux/mmc/sdio_ids.h> + +#ifndef SDIO_CLASS_BT_AMP +#define SDIO_CLASS_BT_AMP 0x09 /* Type-A Bluetooth AMP interface */ +#endif + +#ifndef SDIO_DEVICE_ID_MARVELL_8688WLAN +#define SDIO_DEVICE_ID_MARVELL_8688WLAN 0x9104 +#endif + +#endif /* __BACKPORT_MMC_SDIO_IDS_H */ diff --git a/backport-include/linux/mod_devicetable.h b/backport-include/linux/mod_devicetable.h new file mode 100644 index 0000000..1f85ce6 --- /dev/null +++ b/backport-include/linux/mod_devicetable.h @@ -0,0 +1,49 @@ +#ifndef __BACKPORT_MOD_DEVICETABLE_H +#define __BACKPORT_MOD_DEVICETABLE_H +#include_next <linux/mod_devicetable.h> + +#ifndef HID_BUS_ANY +#define HID_BUS_ANY 0xffff +#endif + +#ifndef HID_GROUP_ANY +#define HID_GROUP_ANY 0x0000 +#endif + +#ifndef HID_ANY_ID +#define HID_ANY_ID (~0) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) +struct hid_device_id { + __u16 bus; + __u32 vendor; + __u32 product; + kernel_ulong_t driver_data + __attribute__((aligned(sizeof(kernel_ulong_t)))); +}; +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0) +#ifndef BCMA_CORE +/* Broadcom's specific AMBA core, see drivers/bcma/ */ +struct bcma_device_id { + __u16 manuf; + __u16 id; + __u8 rev; + __u8 class; +}; +#define BCMA_CORE(_manuf, _id, _rev, _class) \ + { .manuf = _manuf, .id = _id, .rev = _rev, .class = _class, } +#define BCMA_CORETABLE_END \ + { 0, }, + +#define BCMA_ANY_MANUF 0xFFFF +#define BCMA_ANY_ID 0xFFFF +#define BCMA_ANY_REV 0xFF +#define BCMA_ANY_CLASS 0xFF +#endif /* BCMA_CORE */ + +#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0)) */ + +#endif /* __BACKPORT_MOD_DEVICETABLE_H */ diff --git a/backport-include/linux/module.h b/backport-include/linux/module.h new file mode 100644 index 0000000..82c96bd --- /dev/null +++ b/backport-include/linux/module.h @@ -0,0 +1,67 @@ +#ifndef __BACKPORT_LINUX_MODULE_H +#define __BACKPORT_LINUX_MODULE_H +#include_next <linux/module.h> +#include <linux/rcupdate.h> + +/* + * The define overwriting module_init is based on the original module_init + * which looks like this: + * #define module_init(initfn) \ + * static inline initcall_t __inittest(void) \ + * { return initfn; } \ + * int init_module(void) __attribute__((alias(#initfn))); + * + * To the call to the initfn we added the symbol dependency on compat + * to make sure that compat.ko gets loaded for any compat modules. + */ +extern void backport_dependency_symbol(void); + +#ifdef BACKPORTS_GIT_TRACKED +#define BACKPORT_MOD_VERSIONS MODULE_VERSION(BACKPORTS_GIT_TRACKED); +#else +#define BACKPORT_MOD_VERSIONS \ + MODULE_VERSION("backported from " BACKPORTED_KERNEL_NAME \ + " (" BACKPORTED_KERNEL_VERSION ")" \ + " using backports " BACKPORTS_VERSION); +#endif + +#undef module_init +#define module_init(initfn) \ + static int __init __init_backport(void) \ + { \ + backport_dependency_symbol(); \ + return initfn(); \ + } \ + int init_module(void) __attribute__((alias("__init_backport")));\ + BACKPORT_MOD_VERSIONS + +/* + * The define overwriting module_exit is based on the original module_exit + * which looks like this: + * #define module_exit(exitfn) \ + * static inline exitcall_t __exittest(void) \ + * { return exitfn; } \ + * void cleanup_module(void) __attribute__((alias(#exitfn))); + * + * We replaced the call to the actual function exitfn() with a call to our + * function which calls the original exitfn() and then rcu_barrier() + * + * As a module will not be unloaded that ofter it should not have a big + * performance impact when rcu_barrier() is called on every module exit, + * also when no kfree_rcu() backport is used in that module. + */ +#undef module_exit +#define module_exit(exitfn) \ + static void __exit __exit_compat(void) \ + { \ + exitfn(); \ + rcu_barrier(); \ + } \ + void cleanup_module(void) __attribute__((alias("__exit_compat"))); + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) +#undef param_check_bool +#define param_check_bool(name, p) __param_check(name, p, bool) +#endif + +#endif /* __BACKPORT_LINUX_MODULE_H */ diff --git a/backport-include/linux/moduleparam.h b/backport-include/linux/moduleparam.h new file mode 100644 index 0000000..517f50f --- /dev/null +++ b/backport-include/linux/moduleparam.h @@ -0,0 +1,12 @@ +#ifndef __BACKPORT_LINUX_MODULEPARAM_H +#define __BACKPORT_LINUX_MODULEPARAM_H +#include_next <linux/moduleparam.h> + +#ifndef kparam_block_sysfs_write +#define kparam_block_sysfs_write(a) +#endif +#ifndef kparam_unblock_sysfs_write +#define kparam_unblock_sysfs_write(a) +#endif + +#endif /* __BACKPORT_LINUX_MODULEPARAM_H */ diff --git a/backport-include/linux/net.h b/backport-include/linux/net.h new file mode 100644 index 0000000..9d7cbf5 --- /dev/null +++ b/backport-include/linux/net.h @@ -0,0 +1,44 @@ +#ifndef __BACKPORT_LINUX_NET_H +#define __BACKPORT_LINUX_NET_H +#include_next <linux/net.h> + +/* This backports: + * + * commit 2033e9bf06f07e049bbc77e9452856df846714cc + * Author: Neil Horman <nhorman@tuxdriver.com> + * Date: Tue May 29 09:30:40 2012 +0000 + * + * net: add MODULE_ALIAS_NET_PF_PROTO_NAME + */ +#ifndef MODULE_ALIAS_NET_PF_PROTO_NAME +#define MODULE_ALIAS_NET_PF_PROTO_NAME(pf, proto, name) \ + MODULE_ALIAS("net-pf-" __stringify(pf) "-proto-" __stringify(proto) \ + name) +#endif + +#ifndef net_ratelimited_function +#define net_ratelimited_function(function, ...) \ +do { \ + if (net_ratelimit()) \ + function(__VA_ARGS__); \ +} while (0) + +#define net_emerg_ratelimited(fmt, ...) \ + net_ratelimited_function(pr_emerg, fmt, ##__VA_ARGS__) +#define net_alert_ratelimited(fmt, ...) \ + net_ratelimited_function(pr_alert, fmt, ##__VA_ARGS__) +#define net_crit_ratelimited(fmt, ...) \ + net_ratelimited_function(pr_crit, fmt, ##__VA_ARGS__) +#define net_err_ratelimited(fmt, ...) \ + net_ratelimited_function(pr_err, fmt, ##__VA_ARGS__) +#define net_notice_ratelimited(fmt, ...) \ + net_ratelimited_function(pr_notice, fmt, ##__VA_ARGS__) +#define net_warn_ratelimited(fmt, ...) \ + net_ratelimited_function(pr_warn, fmt, ##__VA_ARGS__) +#define net_info_ratelimited(fmt, ...) \ + net_ratelimited_function(pr_info, fmt, ##__VA_ARGS__) +#define net_dbg_ratelimited(fmt, ...) \ + net_ratelimited_function(pr_debug, fmt, ##__VA_ARGS__) +#endif + +#endif /* __BACKPORT_LINUX_NET_H */ diff --git a/backport-include/linux/netdev_features.h b/backport-include/linux/netdev_features.h new file mode 100644 index 0000000..3826e55 --- /dev/null +++ b/backport-include/linux/netdev_features.h @@ -0,0 +1,42 @@ +#ifndef __BACKPORT_NETDEV_FEATURES_H +#define __BACKPORT_NETDEV_FEATURES_H + +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) +#include <linux/netdevice.h> +#include <linux/types.h> + +/* added via 9356b8fc */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,14) +#define NETIF_F_HW_VLAN_CTAG_RX NETIF_F_HW_VLAN_RX +#define NETIF_F_HW_VLAN_CTAG_TX NETIF_F_HW_VLAN_TX +#endif + +/* added via d314774c */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29) +#define NETIF_F_HW_VLAN_CTAG_FILTER NETIF_F_HW_VLAN_FILTER +#endif + +typedef u32 netdev_features_t; +#else +#include_next <linux/netdev_features.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) +/* See commit f646968f8f on next-20130423 */ +#define NETIF_F_HW_VLAN_CTAG_TX_BIT NETIF_F_HW_VLAN_TX_BIT +#define NETIF_F_HW_VLAN_CTAG_RX_BIT NETIF_F_HW_VLAN_RX_BIT +#define NETIF_F_HW_VLAN_CTAG_FILTER_BIT NETIF_F_HW_VLAN_FILTER_BIT + +#define NETIF_F_HW_VLAN_CTAG_FILTER NETIF_F_HW_VLAN_FILTER +#define NETIF_F_HW_VLAN_CTAG_RX NETIF_F_HW_VLAN_RX +#define NETIF_F_HW_VLAN_CTAG_TX NETIF_F_HW_VLAN_TX +#endif + +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) */ + +#if !defined(NETIF_F_RXCSUM) +#define NETIF_F_RXCSUM 0 +#endif + +#endif /* __BACKPORT_NETDEV_FEATURES_H */ diff --git a/backport-include/linux/netdevice.h b/backport-include/linux/netdevice.h new file mode 100644 index 0000000..815c8b4 --- /dev/null +++ b/backport-include/linux/netdevice.h @@ -0,0 +1,470 @@ +#ifndef __BACKPORT_NETDEVICE_H +#define __BACKPORT_NETDEVICE_H +#include_next <linux/netdevice.h> +#include <linux/netdev_features.h> +#include <linux/version.h> + +/* + * This is declared implicitly in newer kernels by netdevice.h using + * this pointer in struct net_device, but declare it here anyway so + * pointers to it are accepted as function arguments without warning. + */ +struct inet6_dev; + +/* older kernels don't include this here, we need it */ +#include <linux/ethtool.h> +#include <linux/rculist.h> +/* + * new kernels include <net/netprio_cgroup.h> which + * has this ... and some drivers rely on it :-( + */ +#include <linux/hardirq.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) +#define dev_change_net_namespace(a, b, c) (-EOPNOTSUPP) + +static inline void SET_NETDEV_DEVTYPE(struct net_device *dev, void *type) +{ + /* nothing */ +} + +typedef int netdev_tx_t; +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) +/* + * Older kernels do not have struct net_device_ops but what we can + * do is just define the data structure and use a caller to let us + * set the data structure's routines onto the old netdev, essentially + * doing it the old way. This avoids huge deltas on our backports. + */ +#define HAVE_NET_DEVICE_OPS +struct net_device_ops { + int (*ndo_init)(struct net_device *dev); + void (*ndo_uninit)(struct net_device *dev); + int (*ndo_open)(struct net_device *dev); + int (*ndo_stop)(struct net_device *dev); + netdev_tx_t (*ndo_start_xmit) (struct sk_buff *skb, + struct net_device *dev); + u16 (*ndo_select_queue)(struct net_device *dev, + struct sk_buff *skb); + void (*ndo_change_rx_flags)(struct net_device *dev, + int flags); + void (*ndo_set_rx_mode)(struct net_device *dev); + void (*ndo_set_multicast_list)(struct net_device *dev); + int (*ndo_set_mac_address)(struct net_device *dev, + void *addr); + int (*ndo_validate_addr)(struct net_device *dev); + int (*ndo_do_ioctl)(struct net_device *dev, + struct ifreq *ifr, int cmd); + int (*ndo_set_config)(struct net_device *dev, + struct ifmap *map); + int (*ndo_change_mtu)(struct net_device *dev, + int new_mtu); + int (*ndo_neigh_setup)(struct net_device *dev, + struct neigh_parms *); + void (*ndo_tx_timeout) (struct net_device *dev); + + struct net_device_stats* (*ndo_get_stats)(struct net_device *dev); + + void (*ndo_vlan_rx_register)(struct net_device *dev, + struct vlan_group *grp); + void (*ndo_vlan_rx_add_vid)(struct net_device *dev, + unsigned short vid); + void (*ndo_vlan_rx_kill_vid)(struct net_device *dev, + unsigned short vid); +#ifdef CONFIG_NET_POLL_CONTROLLER + void (*ndo_poll_controller)(struct net_device *dev); +#endif + int (*ndo_set_vf_mac)(struct net_device *dev, + int queue, u8 *mac); + int (*ndo_set_vf_vlan)(struct net_device *dev, + int queue, u16 vlan, u8 qos); + int (*ndo_set_vf_tx_rate)(struct net_device *dev, + int vf, int rate); +#if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE) + int (*ndo_fcoe_enable)(struct net_device *dev); + int (*ndo_fcoe_disable)(struct net_device *dev); + int (*ndo_fcoe_ddp_setup)(struct net_device *dev, + u16 xid, + struct scatterlist *sgl, + unsigned int sgc); + int (*ndo_fcoe_ddp_done)(struct net_device *dev, + u16 xid); +#define NETDEV_FCOE_WWNN 0 +#define NETDEV_FCOE_WWPN 1 + int (*ndo_fcoe_get_wwn)(struct net_device *dev, + u64 *wwn, int type); +#endif +}; + +static inline struct net_device_stats *dev_get_stats(struct net_device *dev) +{ + return dev->get_stats(dev); +} + +#define init_dummy_netdev LINUX_BACKPORT(init_dummy_netdev) +extern int init_dummy_netdev(struct net_device *dev); + +#define napi_gro_receive(napi, skb) netif_receive_skb(skb) +#endif /* < 2.6.29 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,7,8) +#define netdev_set_default_ethtool_ops LINUX_BACKPORT(netdev_set_default_ethtool_ops) +extern void netdev_set_default_ethtool_ops(struct net_device *dev, + const struct ethtool_ops *ops); +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) +#define __dev_addr_sync LINUX_BACKPORT(__dev_addr_sync) +extern int __dev_addr_sync(struct dev_addr_list **to, int *to_count, struct dev_addr_list **from, int *from_count); +#define __dev_addr_unsync LINUX_BACKPORT(__dev_addr_unsync) +extern void __dev_addr_unsync(struct dev_addr_list **to, int *to_count, struct dev_addr_list **from, int *from_count); +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) +#define netdev_attach_ops LINUX_BACKPORT(netdev_attach_ops) +void netdev_attach_ops(struct net_device *dev, + const struct net_device_ops *ops); + +static inline int ndo_do_ioctl(struct net_device *dev, + struct ifreq *ifr, + int cmd) +{ + if (dev->do_ioctl) + return dev->do_ioctl(dev, ifr, cmd); + return -EOPNOTSUPP; +} +#else +/* XXX: this can probably just go upstream ! */ +static inline void netdev_attach_ops(struct net_device *dev, + const struct net_device_ops *ops) +{ + dev->netdev_ops = ops; +} + +/* XXX: this can probably just go upstream! */ +static inline int ndo_do_ioctl(struct net_device *dev, + struct ifreq *ifr, + int cmd) +{ + if (dev->netdev_ops && dev->netdev_ops->ndo_do_ioctl) + return dev->netdev_ops->ndo_do_ioctl(dev, ifr, cmd); + return -EOPNOTSUPP; +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) +/* + * BQL was added as of v3.3 but some Linux distributions + * have backported BQL to their v3.2 kernels or older. To + * address this we assume that they also enabled CONFIG_BQL + * and test for that here and simply avoid adding the static + * inlines if it was defined + */ +#ifndef CONFIG_BQL +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26)) +static inline void netdev_tx_sent_queue(struct netdev_queue *dev_queue, + unsigned int bytes) +{ +} +#endif + +static inline void netdev_sent_queue(struct net_device *dev, unsigned int bytes) +{ +} + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26)) +static inline void netdev_tx_completed_queue(struct netdev_queue *dev_queue, + unsigned pkts, unsigned bytes) +{ +} +#endif + +static inline void netdev_completed_queue(struct net_device *dev, + unsigned pkts, unsigned bytes) +{ +} + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,26)) +static inline void netdev_tx_reset_queue(struct netdev_queue *q) +{ +} +#endif + +static inline void netdev_reset_queue(struct net_device *dev_queue) +{ +} +#endif /* CONFIG_BQL */ +#endif /* < 3.3 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0) +/* + * since commit 1c5cae815d19ffe02bdfda1260949ef2b1806171 + * "net: call dev_alloc_name from register_netdevice" dev_alloc_name is + * called automatically. This is not implemented in older kernel + * versions so it will result in device wrong names. + */ +static inline int register_netdevice_name(struct net_device *dev) +{ + int err; + + if (strchr(dev->name, '%')) { + err = dev_alloc_name(dev, dev->name); + if (err < 0) + return err; + } + + return register_netdevice(dev); +} + +#define register_netdevice(dev) register_netdevice_name(dev) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) +#define alloc_netdev_mqs(sizeof_priv, name, setup, txqs, rxqs) \ + alloc_netdev_mq(sizeof_priv, name, setup, \ + max_t(unsigned int, txqs, rxqs)) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) +#define netdev_refcnt_read(a) atomic_read(&a->refcnt) + +#define net_ns_type_operations LINUX_BACKPORT(net_ns_type_operations) +extern struct kobj_ns_type_operations net_ns_type_operations; + +#ifdef CONFIG_RPS +extern int netif_set_real_num_rx_queues(struct net_device *dev, + unsigned int rxq); +#else +static inline int netif_set_real_num_rx_queues(struct net_device *dev, + unsigned int rxq) +{ + return 0; +} +#endif +#endif /* < 2.6.37 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) +/* + * etherdevice.h requires netdev_hw_addr to not have been redefined, + * so while generally we shouldn't/wouldn't include unrelated header + * files here it's unavoidable. However, if we got included through + * it, then we let it sort out the netdev_hw_addr define so that it + * still gets the correct one later ... + */ +#include <linux/etherdevice.h> +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) +#define netif_set_real_num_tx_queues LINUX_BACKPORT(netif_set_real_num_tx_queues) +extern int netif_set_real_num_tx_queues(struct net_device *dev, + unsigned int txq); +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) +#define netdev_mc_count(dev) ((dev)->mc_count) +#define netdev_mc_empty(dev) (netdev_mc_count(dev) == 0) + +/* mask netdev_for_each_mc_addr as RHEL6 backports this */ +#ifndef netdev_for_each_mc_addr +#define netdev_for_each_mc_addr(mclist, dev) \ + for (mclist = dev->mc_list; mclist; mclist = mclist->next) +#endif + +#ifndef netdev_name +#define netdev_name(__dev) \ + ((__dev->reg_state != NETREG_REGISTERED) ? \ + "(unregistered net_device)" : __dev->name) +#endif + +#define netdev_printk(level, netdev, format, args...) \ + dev_printk(level, (netdev)->dev.parent, \ + "%s: " format, \ + netdev_name(netdev), ##args) + +#define netdev_emerg(dev, format, args...) \ + netdev_printk(KERN_EMERG, dev, format, ##args) +#define netdev_alert(dev, format, args...) \ + netdev_printk(KERN_ALERT, dev, format, ##args) +#define netdev_crit(dev, format, args...) \ + netdev_printk(KERN_CRIT, dev, format, ##args) +#define netdev_err(dev, format, args...) \ + netdev_printk(KERN_ERR, dev, format, ##args) +#define netdev_warn(dev, format, args...) \ + netdev_printk(KERN_WARNING, dev, format, ##args) +#define netdev_notice(dev, format, args...) \ + netdev_printk(KERN_NOTICE, dev, format, ##args) +#define netdev_info(dev, format, args...) \ + netdev_printk(KERN_INFO, dev, format, ##args) + +/* mask netdev_dbg as RHEL6 backports this */ +#if !defined(netdev_dbg) + +#if defined(DEBUG) +#define netdev_dbg(__dev, format, args...) \ + netdev_printk(KERN_DEBUG, __dev, format, ##args) +#elif defined(CONFIG_DYNAMIC_DEBUG) +#define netdev_dbg(__dev, format, args...) \ +do { \ + dynamic_dev_dbg((__dev)->dev.parent, "%s: " format, \ + netdev_name(__dev), ##args); \ +} while (0) +#else +#define netdev_dbg(__dev, format, args...) \ +({ \ + if (0) \ + netdev_printk(KERN_DEBUG, __dev, format, ##args); \ + 0; \ +}) +#endif + +#endif + +/* mask netdev_vdbg as RHEL6 backports this */ +#if !defined(netdev_dbg) + +#if defined(VERBOSE_DEBUG) +#define netdev_vdbg netdev_dbg +#else + +#define netdev_vdbg(dev, format, args...) \ +({ \ + if (0) \ + netdev_printk(KERN_DEBUG, dev, format, ##args); \ + 0; \ +}) +#endif + +#endif + +/* + * netdev_WARN() acts like dev_printk(), but with the key difference + * of using a WARN/WARN_ON to get the message out, including the + * file/line information and a backtrace. + */ +#define netdev_WARN(dev, format, args...) \ + WARN(1, "netdevice: %s\n" format, netdev_name(dev), ##args); + +/* netif printk helpers, similar to netdev_printk */ + +#define netif_printk(priv, type, level, dev, fmt, args...) \ +do { \ + if (netif_msg_##type(priv)) \ + netdev_printk(level, (dev), fmt, ##args); \ +} while (0) + +#define netif_emerg(priv, type, dev, fmt, args...) \ + netif_printk(priv, type, KERN_EMERG, dev, fmt, ##args) +#define netif_alert(priv, type, dev, fmt, args...) \ + netif_printk(priv, type, KERN_ALERT, dev, fmt, ##args) +#define netif_crit(priv, type, dev, fmt, args...) \ + netif_printk(priv, type, KERN_CRIT, dev, fmt, ##args) +#define netif_err(priv, type, dev, fmt, args...) \ + netif_printk(priv, type, KERN_ERR, dev, fmt, ##args) +#define netif_warn(priv, type, dev, fmt, args...) \ + netif_printk(priv, type, KERN_WARNING, dev, fmt, ##args) +#define netif_notice(priv, type, dev, fmt, args...) \ + netif_printk(priv, type, KERN_NOTICE, dev, fmt, ##args) +#define netif_info(priv, type, dev, fmt, args...) \ + netif_printk(priv, type, KERN_INFO, (dev), fmt, ##args) + +/* mask netif_dbg as RHEL6 backports this */ +#if !defined(netif_dbg) + +#if defined(DEBUG) +#define netif_dbg(priv, type, dev, format, args...) \ + netif_printk(priv, type, KERN_DEBUG, dev, format, ##args) +#elif defined(CONFIG_DYNAMIC_DEBUG) +#define netif_dbg(priv, type, netdev, format, args...) \ +do { \ + if (netif_msg_##type(priv)) \ + dynamic_dev_dbg((netdev)->dev.parent, \ + "%s: " format, \ + netdev_name(netdev), ##args); \ +} while (0) +#else +#define netif_dbg(priv, type, dev, format, args...) \ +({ \ + if (0) \ + netif_printk(priv, type, KERN_DEBUG, dev, format, ##args); \ + 0; \ +}) +#endif + +#endif + +/* mask netif_vdbg as RHEL6 backports this */ +#if !defined(netif_vdbg) + +#if defined(VERBOSE_DEBUG) +#define netif_vdbg netdev_dbg +#else +#define netif_vdbg(priv, type, dev, format, args...) \ +({ \ + if (0) \ + netif_printk(KERN_DEBUG, dev, format, ##args); \ + 0; \ +}) +#endif +#endif + +#endif /* < 2.6.34 */ + +/* mask NETDEV_POST_INIT as RHEL6 backports this */ +/* this will never happen on older kernels */ +#ifndef NETDEV_POST_INIT +#define NETDEV_POST_INIT 0xffff +#endif + +#ifndef NETDEV_PRE_UP +#define NETDEV_PRE_UP 0x000D +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) +/* + * On older kernels we do not have net_device Multi Queue support, but + * since we no longer use MQ on mac80211 we can simply use the 0 queue. + * Note that if other fullmac drivers make use of this they then need + * to be backported somehow or deal with just 1 queue from MQ. + */ +static inline void netif_tx_wake_all_queues(struct net_device *dev) +{ + netif_wake_queue(dev); +} +static inline void netif_tx_start_all_queues(struct net_device *dev) +{ + netif_start_queue(dev); +} +static inline void netif_tx_stop_all_queues(struct net_device *dev) +{ + netif_stop_queue(dev); +} + +/* + * The net_device has a spin_lock on newer kernels, on older kernels we're out of luck + */ +#define netif_addr_lock_bh(dev) +#define netif_addr_unlock_bh(dev) + +#define netif_wake_subqueue netif_start_subqueue +#endif /* < 2.6.27 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) +static inline +struct net *dev_net(const struct net_device *dev) +{ +#ifdef CONFIG_NET_NS + /* + * compat-wirelss backport note: + * For older kernels we may just need to always return init_net, + * not sure when we added dev->nd_net. + */ + return dev->nd_net; +#else + return &init_net; +#endif +} +#endif + +#endif /* __BACKPORT_NETDEVICE_H */ diff --git a/backport-include/linux/netlink.h b/backport-include/linux/netlink.h new file mode 100644 index 0000000..2058a90 --- /dev/null +++ b/backport-include/linux/netlink.h @@ -0,0 +1,15 @@ +#ifndef __BACKPORT_LINUX_NETLINK_H +#define __BACKPORT_LINUX_NETLINK_H +#include_next <linux/netlink.h> +#include <linux/version.h> + +/* this is for patches we apply */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0) +#define netlink_notify_portid(__notify) (__notify->pid) +#define NETLINK_CB_PORTID(__skb) NETLINK_CB(cb->skb).pid +#else +#define netlink_notify_portid(__notify) (__notify->portid) +#define NETLINK_CB_PORTID(__skb) NETLINK_CB(cb->skb).portid +#endif + +#endif /* __BACKPORT_LINUX_NETLINK_H */ diff --git a/backport-include/linux/nl80211.h b/backport-include/linux/nl80211.h new file mode 100644 index 0000000..fcb0b8b --- /dev/null +++ b/backport-include/linux/nl80211.h @@ -0,0 +1,10 @@ +#ifndef __BACKPORT_LINUX_NL80211_H +#define __BACKPORT_LINUX_NL80211_H +#include_next <linux/nl80211.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) +#define NL80211_FEATURE_SK_TX_STATUS 0 +#endif + +#endif /* __BACKPORT_LINUX_NL80211_H */ diff --git a/backport-include/linux/of.h b/backport-include/linux/of.h new file mode 100644 index 0000000..c5dc87c --- /dev/null +++ b/backport-include/linux/of.h @@ -0,0 +1,16 @@ +#ifndef _COMPAT_LINUX_OF_H +#define _COMPAT_LINUX_OF_H 1 + +#include <linux/version.h> + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34)) +#include_next <linux/of.h> +#else + +#ifdef CONFIG_OF +#include_next <linux/of.h> +#endif /* CONFIG_OF */ + +#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34)) */ + +#endif /* _COMPAT_LINUX_OF_H */ diff --git a/backport-include/linux/olpc-ec.h b/backport-include/linux/olpc-ec.h new file mode 100644 index 0000000..a5b932a --- /dev/null +++ b/backport-include/linux/olpc-ec.h @@ -0,0 +1,10 @@ +#ifndef _COMPAT_LINUX_OLPC_EC_H +#define _COMPAT_LINUX_OLPC_EC_H + +#include <linux/version.h> + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0)) +#include_next <linux/olpc-ec.h> +#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(3,6,0)) */ + +#endif /* _COMPAT_LINUX_OLPC_EC_H */ diff --git a/backport-include/linux/pagemap.h b/backport-include/linux/pagemap.h new file mode 100644 index 0000000..19d72de --- /dev/null +++ b/backport-include/linux/pagemap.h @@ -0,0 +1,76 @@ +#ifndef __BACKPORT_LINUX_PAGEMAP_H +#define __BACKPORT_LINUX_PAGEMAP_H +#include_next <linux/pagemap.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0) +#include <asm/uaccess.h> +/* + * This backports: + * + * commit f56f821feb7b36223f309e0ec05986bb137ce418 + * Author: Daniel Vetter <daniel.vetter@ffwll.ch> + * Date: Sun Mar 25 19:47:41 2012 +0200 + * + * mm: extend prefault helpers to fault in more than PAGE_SIZE + * + * The new functions are used by drm/i915 driver. + * + */ + +static inline int fault_in_multipages_writeable(char __user *uaddr, int size) +{ + int ret = 0; + char __user *end = uaddr + size - 1; + + if (unlikely(size == 0)) + return ret; + + /* + * Writing zeroes into userspace here is OK, because we know that if + * the zero gets there, we'll be overwriting it. + */ + while (uaddr <= end) { + ret = __put_user(0, uaddr); + if (ret != 0) + return ret; + uaddr += PAGE_SIZE; + } + + /* Check whether the range spilled into the next page. */ + if (((unsigned long)uaddr & PAGE_MASK) == + ((unsigned long)end & PAGE_MASK)) + ret = __put_user(0, end); + + return ret; +} + +static inline int fault_in_multipages_readable(const char __user *uaddr, + int size) +{ + volatile char c; + int ret = 0; + const char __user *end = uaddr + size - 1; + + if (unlikely(size == 0)) + return ret; + + while (uaddr <= end) { + ret = __get_user(c, uaddr); + if (ret != 0) + return ret; + uaddr += PAGE_SIZE; + } + + /* Check whether the range spilled into the next page. */ + if (((unsigned long)uaddr & PAGE_MASK) == + ((unsigned long)end & PAGE_MASK)) { + ret = __get_user(c, end); + (void)c; + } + + return ret; +} +#endif /* < 3.5 */ + +#endif /* __BACKPORT_LINUX_PAGEMAP_H */ diff --git a/backport-include/linux/pci-aspm.h b/backport-include/linux/pci-aspm.h new file mode 100644 index 0000000..367112e --- /dev/null +++ b/backport-include/linux/pci-aspm.h @@ -0,0 +1,15 @@ +#include <linux/version.h> + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,25)) +#include_next <linux/pci-aspm.h> +#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,25)) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) +#define PCIE_LINK_STATE_L0S 1 +#define PCIE_LINK_STATE_L1 2 +#define PCIE_LINK_STATE_CLKPM 4 + +static inline void pci_disable_link_state(struct pci_dev *pdev, int state) +{ +} +#endif diff --git a/backport-include/linux/pci.h b/backport-include/linux/pci.h new file mode 100644 index 0000000..b223879 --- /dev/null +++ b/backport-include/linux/pci.h @@ -0,0 +1,181 @@ +#ifndef _BACKPORT_LINUX_PCI_H +#define _BACKPORT_LINUX_PCI_H +#include_next <linux/pci.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) +/* Backports b718989da7 */ +#define pci_enable_device_mem LINUX_BACKPORT(pci_enable_device_mem) +int __must_check pci_enable_device_mem(struct pci_dev *dev); + +#define DEFINE_PCI_DEVICE_TABLE(_table) \ + const struct pci_device_id _table[] __devinitdata +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) +#define compat_pci_suspend(fn) \ + int fn##_compat(struct pci_dev *pdev, pm_message_t state) \ + { \ + int r; \ + \ + r = fn(&pdev->dev); \ + if (r) \ + return r; \ + \ + pci_save_state(pdev); \ + pci_disable_device(pdev); \ + pci_set_power_state(pdev, PCI_D3hot); \ + \ + return 0; \ + } + +#define compat_pci_resume(fn) \ + int fn##_compat(struct pci_dev *pdev) \ + { \ + int r; \ + \ + pci_set_power_state(pdev, PCI_D0); \ + r = pci_enable_device(pdev); \ + if (r) \ + return r; \ + pci_restore_state(pdev); \ + \ + return fn(&pdev->dev); \ + } +#elif LINUX_VERSION_CODE == KERNEL_VERSION(2,6,29) +#define compat_pci_suspend(fn) \ + int fn##_compat(struct device *dev) \ + { \ + struct pci_dev *pdev = to_pci_dev(dev); \ + int r; \ + \ + r = fn(&pdev->dev); \ + if (r) \ + return r; \ + \ + pci_save_state(pdev); \ + pci_disable_device(pdev); \ + pci_set_power_state(pdev, PCI_D3hot); \ + \ + return 0; \ + } + +#define compat_pci_resume(fn) \ + int fn##_compat(struct device *dev) \ + { \ + struct pci_dev *pdev = to_pci_dev(dev); \ + int r; \ + \ + pci_set_power_state(pdev, PCI_D0); \ + r = pci_enable_device(pdev); \ + if (r) \ + return r; \ + pci_restore_state(pdev); \ + \ + return fn(&pdev->dev); \ + } +#else +#define compat_pci_suspend(fn) +#define compat_pci_resume(fn) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0) +/** + * module_pci_driver() - Helper macro for registering a PCI driver + * @__pci_driver: pci_driver struct + * + * Helper macro for PCI drivers which do not do anything special in module + * init/exit. This eliminates a lot of boilerplate. Each module may only + * use this macro once, and calling it replaces module_init() and module_exit() + */ +#define module_pci_driver(__pci_driver) \ + module_driver(__pci_driver, pci_register_driver, \ + pci_unregister_driver) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0) +#define pcie_capability_read_word LINUX_BACKPORT(pcie_capability_read_word) +int pcie_capability_read_word(struct pci_dev *dev, int pos, u16 *val); +#define pcie_capability_read_dword LINUX_BACKPORT(pcie_capability_read_dword) +int pcie_capability_read_dword(struct pci_dev *dev, int pos, u32 *val); +#define pcie_capability_write_word LINUX_BACKPORT(pcie_capability_write_word) +int pcie_capability_write_word(struct pci_dev *dev, int pos, u16 val); +#define pcie_capability_write_dword LINUX_BACKPORT(pcie_capability_write_dword) +int pcie_capability_write_dword(struct pci_dev *dev, int pos, u32 val); +#define pcie_capability_clear_and_set_word LINUX_BACKPORT(pcie_capability_clear_and_set_word) +int pcie_capability_clear_and_set_word(struct pci_dev *dev, int pos, + u16 clear, u16 set); +#define pcie_capability_clear_and_set_dword LINUX_BACKPORT(pcie_capability_clear_and_set_dword) +int pcie_capability_clear_and_set_dword(struct pci_dev *dev, int pos, + u32 clear, u32 set); + +static inline int pcie_capability_set_word(struct pci_dev *dev, int pos, + u16 set) +{ + return pcie_capability_clear_and_set_word(dev, pos, 0, set); +} + +static inline int pcie_capability_set_dword(struct pci_dev *dev, int pos, + u32 set) +{ + return pcie_capability_clear_and_set_dword(dev, pos, 0, set); +} + +static inline int pcie_capability_clear_word(struct pci_dev *dev, int pos, + u16 clear) +{ + return pcie_capability_clear_and_set_word(dev, pos, clear, 0); +} + +static inline int pcie_capability_clear_dword(struct pci_dev *dev, int pos, + u32 clear) +{ + return pcie_capability_clear_and_set_dword(dev, pos, clear, 0); +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0) +/* + * DRM requires this, but we can't really backport it well + */ +static inline void __iomem *pci_platform_rom(struct pci_dev *pdev, size_t *size) +{ + printk(KERN_WARNING "compat: not providing pci_platform_rom!\n"); + return NULL; +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33) +/* mask pci_pcie_cap as debian squeeze also backports this */ +#define pci_pcie_cap LINUX_BACKPORT(pci_pcie_cap) +static inline int pci_pcie_cap(struct pci_dev *dev) +{ + return pci_find_capability(dev, PCI_CAP_ID_EXP); +} + +/* mask pci_is_pcie as RHEL6 backports this */ +#define pci_is_pcie LINUX_BACKPORT(pci_is_pcie) +static inline bool pci_is_pcie(struct pci_dev *dev) +{ +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,24)) + return dev->is_pcie; +#else + return !!pci_pcie_cap(dev); +#endif +} +#endif /* < 2.6.33 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) +#define pci_ioremap_bar LINUX_BACKPORT(pci_ioremap_bar) +void __iomem *pci_ioremap_bar(struct pci_dev *pdev, int bar); + +#define pci_wake_from_d3 LINUX_BACKPORT(pci_wake_from_d3) +int pci_wake_from_d3(struct pci_dev *dev, bool enable); +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) +#define pci_pme_capable LINUX_BACKPORT(pci_pme_capable) +bool pci_pme_capable(struct pci_dev *dev, pci_power_t state); +#endif + +#endif /* _BACKPORT_LINUX_PCI_H */ diff --git a/backport-include/linux/pci_regs.h b/backport-include/linux/pci_regs.h new file mode 100644 index 0000000..5cfa742 --- /dev/null +++ b/backport-include/linux/pci_regs.h @@ -0,0 +1,128 @@ +#ifndef __BACKPORT_UAPI_PCI_REGS_H +#define __BACKPORT_UAPI_PCI_REGS_H +#include_next <linux/pci_regs.h> + +#ifndef PCI_EXP_LNKCTL_ASPM_L0S +#define PCI_EXP_LNKCTL_ASPM_L0S 0x01 /* L0s Enable */ +#endif + +#ifndef PCI_EXP_LNKCTL_ASPM_L1 +#define PCI_EXP_LNKCTL_ASPM_L1 0x02 /* L1 Enable */ +#endif + +/* This backports: + * + * commit 130f1b8f35f14d27c43da755f3c9226318c17f57 + * Author: Bjorn Helgaas <bhelgaas@google.com> + * Date: Wed Dec 26 10:39:23 2012 -0700 + * + * PCI: Add PCIe Link Capability link speed and width names + */ +#ifndef PCI_EXP_LNKCAP_SLS_2_5GB +#define PCI_EXP_LNKCAP_SLS_2_5GB 0x1 /* LNKCAP2 SLS Vector bit 0 (2.5GT/s) */ +#endif + +#ifndef PCI_EXP_LNKCAP_SLS_5_0GB +#define PCI_EXP_LNKCAP_SLS_5_0GB 0x2 /* LNKCAP2 SLS Vector bit 1 (5.0GT/s) */ +#endif + +#ifndef PCI_EXP_LNKSTA2 +#define PCI_EXP_LNKSTA2 50 /* Link Status 2 */ +#endif + +/** + * Backports + * + * commit cdcac9cd7741af2c2b9255cbf060f772596907bb + * Author: Dave Airlie <airlied@redhat.com> + * Date: Wed Jun 27 08:35:52 2012 +0100 + * + * pci_regs: define LNKSTA2 pcie cap + bits. + * + * We need these for detecting the max link speed for drm drivers. + * + * Acked-by: Bjorn Helgaas <bhelgass@google.com> + * Signed-off-by: Dave Airlie <airlied@redhat.com> + */ +#ifndef PCI_EXP_LNKCAP2 +#define PCI_EXP_LNKCAP2 44 /* Link Capability 2 */ +#endif + +#ifndef PCI_EXP_LNKCAP2_SLS_2_5GB +#define PCI_EXP_LNKCAP2_SLS_2_5GB 0x01 /* Current Link Speed 2.5GT/s */ +#endif + +#ifndef PCI_EXP_LNKCAP2_SLS_5_0GB +#define PCI_EXP_LNKCAP2_SLS_5_0GB 0x02 /* Current Link Speed 5.0GT/s */ +#endif + +#ifndef PCI_EXP_LNKCAP2_SLS_8_0GB +#define PCI_EXP_LNKCAP2_SLS_8_0GB 0x04 /* Current Link Speed 8.0GT/s */ +#endif + +#ifndef PCI_EXP_LNKCAP2_CROSSLINK +#define PCI_EXP_LNKCAP2_CROSSLINK 0x100 /* Crosslink supported */ +#endif + +/* + * PCI_EXP_TYPE_RC_EC was added via 1b6b8ce2 on v2.6.30-rc4~20 : + * + * mcgrof@frijol ~/linux-next (git::master)$ git describe --contains 1b6b8ce2 + * v2.6.30-rc4~20^2 + * + * but the fix for its definition was merged on v3.3-rc1~101^2~67 + * + * mcgrof@frijol ~/linux-next (git::master)$ git describe --contains 1830ea91 + * v3.3-rc1~101^2~67 + * + * while we can assume it got merged and backported on v3.2.28 (which it did + * see c1c3cd9) we cannot assume every kernel has it fixed so lets just undef + * it here and redefine it. + */ +#undef PCI_EXP_TYPE_RC_EC +#define PCI_EXP_TYPE_RC_EC 0xa /* Root Complex Event Collector */ + +#ifndef PCI_MSIX_ENTRY_CTRL_MASKBIT +#define PCI_MSIX_ENTRY_CTRL_MASKBIT 1 +#endif + +/* MSI-X entry's format */ +#ifndef PCI_MSIX_ENTRY_SIZE +#define PCI_MSIX_ENTRY_SIZE 16 +#define PCI_MSIX_ENTRY_LOWER_ADDR 0 +#define PCI_MSIX_ENTRY_UPPER_ADDR 4 +#define PCI_MSIX_ENTRY_DATA 8 +#define PCI_MSIX_ENTRY_VECTOR_CTRL 12 +#endif + +#ifndef PCI_EXP_LNKCTL2 +#define PCI_EXP_LNKCTL2 48 /* Link Control 2 */ +#endif + +#ifndef PCI_EXP_SLTCTL2 +#define PCI_EXP_SLTCTL2 56 /* Slot Control 2 */ +#endif + +#ifndef PCI_EXP_LNKCTL_ES +#define PCI_EXP_LNKCTL_ES 0x0080 /* Extended Synch */ +#endif + +#ifndef PCI_EXP_SLTSTA_PDS +#define PCI_EXP_SLTSTA_PDS 0x0040 /* Presence Detect State */ +#endif + +#ifndef PCI_EXP_DEVCAP2 +#define PCI_EXP_DEVCAP2 36 /* Device Capabilities 2 */ +#define PCI_EXP_DEVCAP2_ARI 0x20 /* Alternative Routing-ID */ +#endif + +#ifndef PCI_EXP_DEVCTL2 +#define PCI_EXP_DEVCTL2 40 /* Device Control 2 */ +#define PCI_EXP_DEVCTL2_ARI 0x20 /* Alternative Routing-ID */ +#endif + +#ifndef PCI_PM_CAP_PME_SHIFT +#define PCI_PM_CAP_PME_SHIFT 11 +#endif + +#endif /* __BACKPORT_UAPI_PCI_REGS_H */ diff --git a/backport-include/linux/pkt_sched.h b/backport-include/linux/pkt_sched.h new file mode 100644 index 0000000..40ed863 --- /dev/null +++ b/backport-include/linux/pkt_sched.h @@ -0,0 +1,106 @@ +#ifndef __BACKPORT_LINUX_PKT_SCHED_H +#define __BACKPORT_LINUX_PKT_SCHED_H +#include_next <linux/pkt_sched.h> +#include <linux/version.h> + +/* + * This backports: + * + * From 76e3cc126bb223013a6b9a0e2a51238d1ef2e409 Mon Sep 17 00:00:00 2001 + * From: Eric Dumazet <edumazet@google.com> + * Date: Thu, 10 May 2012 07:51:25 +0000 + * Subject: [PATCH] codel: Controlled Delay AQM + */ +#ifndef TCA_CODEL_MAX +/* CODEL */ + +#define COMPAT_CODEL_BACKPORT + +enum { + TCA_CODEL_UNSPEC, + TCA_CODEL_TARGET, + TCA_CODEL_LIMIT, + TCA_CODEL_INTERVAL, + TCA_CODEL_ECN, + __TCA_CODEL_MAX +}; + +#define TCA_CODEL_MAX (__TCA_CODEL_MAX - 1) + +struct tc_codel_xstats { + __u32 maxpacket; /* largest packet we've seen so far */ + __u32 count; /* how many drops we've done since the last time we + * entered dropping state + */ + __u32 lastcount; /* count at entry to dropping state */ + __u32 ldelay; /* in-queue delay seen by most recently dequeued packet */ + __s32 drop_next; /* time to drop next packet */ + __u32 drop_overlimit; /* number of time max qdisc packet limit was hit */ + __u32 ecn_mark; /* number of packets we ECN marked instead of dropped */ + __u32 dropping; /* are we in dropping state ? */ +}; + +/* This backports: + * + * commit 4b549a2ef4bef9965d97cbd992ba67930cd3e0fe + * Author: Eric Dumazet <edumazet@google.com> + * Date: Fri May 11 09:30:50 2012 +0000 + * fq_codel: Fair Queue Codel AQM + */ + +/* FQ_CODEL */ + +enum { + TCA_FQ_CODEL_UNSPEC, + TCA_FQ_CODEL_TARGET, + TCA_FQ_CODEL_LIMIT, + TCA_FQ_CODEL_INTERVAL, + TCA_FQ_CODEL_ECN, + TCA_FQ_CODEL_FLOWS, + TCA_FQ_CODEL_QUANTUM, + __TCA_FQ_CODEL_MAX +}; + +#define TCA_FQ_CODEL_MAX (__TCA_FQ_CODEL_MAX - 1) + +enum { + TCA_FQ_CODEL_XSTATS_QDISC, + TCA_FQ_CODEL_XSTATS_CLASS, +}; + +struct tc_fq_codel_qd_stats { + __u32 maxpacket; /* largest packet we've seen so far */ + __u32 drop_overlimit; /* number of time max qdisc + * packet limit was hit + */ + __u32 ecn_mark; /* number of packets we ECN marked + * instead of being dropped + */ + __u32 new_flow_count; /* number of time packets + * created a 'new flow' + */ + __u32 new_flows_len; /* count of flows in new list */ + __u32 old_flows_len; /* count of flows in old list */ +}; + +struct tc_fq_codel_cl_stats { + __s32 deficit; + __u32 ldelay; /* in-queue delay seen by most recently + * dequeued packet + */ + __u32 count; + __u32 lastcount; + __u32 dropping; + __s32 drop_next; +}; + +struct tc_fq_codel_xstats { + __u32 type; + union { + struct tc_fq_codel_qd_stats qdisc_stats; + struct tc_fq_codel_cl_stats class_stats; + }; +}; +#endif /* TCA_CODEL_MAX */ + +#endif /* __BACKPORT_LINUX_PKT_SCHED_H */ diff --git a/backport-include/linux/platform_device.h b/backport-include/linux/platform_device.h new file mode 100644 index 0000000..d93f04b --- /dev/null +++ b/backport-include/linux/platform_device.h @@ -0,0 +1,42 @@ +#ifndef __BACKPORT_PLATFORM_DEVICE_H +#define __BACKPORT_PLATFORM_DEVICE_H + +#include_next <linux/platform_device.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0) +#define module_platform_driver_probe(__platform_driver, __platform_probe) \ +static int __init __platform_driver##_init(void) \ +{ \ + return platform_driver_probe(&(__platform_driver), \ + __platform_probe); \ +} \ +module_init(__platform_driver##_init); \ +static void __exit __platform_driver##_exit(void) \ +{ \ + platform_driver_unregister(&(__platform_driver)); \ +} \ +module_exit(__platform_driver##_exit); +#endif + +#ifndef PLATFORM_DEVID_NONE +#define PLATFORM_DEVID_NONE (-1) +#endif + +#ifndef PLATFORM_DEVID_AUTO +#define PLATFORM_DEVID_AUTO (-1) +#endif + +#ifndef module_platform_driver +#define module_platform_driver(__platform_driver) \ + module_driver(__platform_driver, platform_driver_register, \ + platform_driver_unregister) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) +#define platform_device_register_data LINUX_BACKPORT(platform_device_register_data) +extern struct platform_device *platform_device_register_data(struct device *, + const char *, int, const void *, size_t); +#endif + +#endif /* __BACKPORT_PLATFORM_DEVICE_H */ diff --git a/backport-include/linux/pm.h b/backport-include/linux/pm.h new file mode 100644 index 0000000..70f3a21 --- /dev/null +++ b/backport-include/linux/pm.h @@ -0,0 +1,70 @@ +#ifndef __BACKPORT_PM_H +#define __BACKPORT_PM_H +#include_next <linux/pm.h> + +#ifndef PM_EVENT_SLEEP +#define PM_EVENT_SLEEP (PM_EVENT_SUSPEND) +#endif + +#ifndef PMSG_IS_AUTO +#define PMSG_IS_AUTO(msg) (((msg).event & PM_EVENT_AUTO) != 0) +#endif + +#if LINUX_VERSION_CODE == KERNEL_VERSION(2,6,32) +#undef SIMPLE_DEV_PM_OPS +#define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \ +const struct dev_pm_ops name = { \ + .suspend = suspend_fn, \ + .resume = resume_fn, \ + .freeze = suspend_fn, \ + .thaw = resume_fn, \ + .poweroff = suspend_fn, \ + .restore = resume_fn, \ +} +#endif /* 2.6.32 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) +/* + * dev_pm_ops is only available on kernels >= 2.6.29, for + * older kernels we rely on reverting the work to old + * power management style stuff. On 2.6.29 the pci calls + * weren't included yet though, so include them here. + */ +#if LINUX_VERSION_CODE == KERNEL_VERSION(2,6,29) +#define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \ +struct dev_pm_ops name = { \ + .suspend = suspend_fn ## _compat, \ + .resume = resume_fn ## _compat, \ + .freeze = suspend_fn ## _compat, \ + .thaw = resume_fn ## _compat, \ + .poweroff = suspend_fn ## _compat, \ + .restore = resume_fn ## _compat, \ +} +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30) +#define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \ +struct dev_pm_ops name = { \ + .suspend = suspend_fn, \ + .resume = resume_fn, \ + .freeze = suspend_fn, \ + .thaw = resume_fn, \ + .poweroff = suspend_fn, \ + .restore = resume_fn, \ +} +#else +#define ___BACKPORT_PASTE(a, b) a##b +#define __BACKPORT_PASTE(a, b) ___BACKPORT_PASTE(a,b) +#define SIMPLE_DEV_PM_OPS(name, suspend_fn, resume_fn) \ + struct {} __maybe_unused __BACKPORT_PASTE(__backport_avoid_warning_, __LINE__) +#endif /* >= 2.6.29 */ +#endif /* < 2.6.32 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,30) +enum dpm_order { + DPM_ORDER_NONE, + DPM_ORDER_DEV_AFTER_PARENT, + DPM_ORDER_PARENT_BEFORE_DEV, + DPM_ORDER_DEV_LAST, +}; +#endif + +#endif /* __BACKPORT_PM_H */ diff --git a/backport-include/linux/pm_qos.h b/backport-include/linux/pm_qos.h new file mode 100644 index 0000000..96a600f --- /dev/null +++ b/backport-include/linux/pm_qos.h @@ -0,0 +1,96 @@ +#ifndef _COMPAT_LINUX_PM_QOS_H +#define _COMPAT_LINUX_PM_QOS_H 1 + +#include <linux/version.h> + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)) +/* + * Kernels >= 2.6.25 have pm-qos and its initialized as part of + * the bootup process + */ +static inline int backport_pm_qos_power_init(void) +{ + return 0; +} + +static inline int backport_pm_qos_power_deinit(void) +{ + return 0; +} +#else +/* + * Backport work for QoS dependencies (kernel/pm_qos_params.c) + * pm-qos stuff written by mark gross mgross@linux.intel.com. + * + * ipw2100 now makes use of: + * + * pm_qos_add_requirement(), + * pm_qos_update_requirement() and + * pm_qos_remove_requirement() from it + * + * mac80211 uses the network latency to determine if to enable or not + * dynamic PS. mac80211 also and registers a notifier for when + * the latency changes. Since older kernels do no thave pm-qos stuff + * we just implement it completley here and register it upon cfg80211 + * init. I haven't tested ipw2100 on 2.6.24 though. + * + * This pm-qos implementation is copied verbatim from the kernel + * written by mark gross mgross@linux.intel.com. You don't have + * to do anythinig to use pm-qos except use the same exported + * routines as used in newer kernels. The backport_pm_qos_power_init() + * defned below is used by the compat module to initialize pm-qos. + */ +int backport_pm_qos_power_init(void); +int backport_pm_qos_power_deinit(void); +#endif + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0)) +#include_next <linux/pm_qos.h> +#else +#include <linux/pm_qos_params.h> +#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0)) */ + +#ifndef PM_QOS_DEFAULT_VALUE +#define PM_QOS_DEFAULT_VALUE -1 +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) +struct pm_qos_request_list { + u32 qos; + void *request; +}; + +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35)) + +#define pm_qos_add_request(_req, _class, _value) do { \ + (_req)->request = #_req; \ + (_req)->qos = _class; \ + pm_qos_add_requirement((_class), (_req)->request, (_value)); \ + } while(0) + +#define pm_qos_update_request(_req, _value) \ + pm_qos_update_requirement((_req)->qos, (_req)->request, (_value)) + +#define pm_qos_remove_request(_req) \ + pm_qos_remove_requirement((_req)->qos, (_req)->request) + +#else + +#define pm_qos_add_request(_req, _class, _value) do { \ + (_req)->request = pm_qos_add_request((_class), (_value)); \ + } while (0) + +#define pm_qos_update_request(_req, _value) \ + pm_qos_update_request((_req)->request, (_value)) + +#define pm_qos_remove_request(_req) \ + pm_qos_remove_request((_req)->request) + +#endif /* < 2.6.35 */ +#endif /* < 2.6.36 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) +#define pm_qos_request(_qos) pm_qos_requirement(_qos) +#endif + +#endif /* _COMPAT_LINUX_PM_QOS_H */ diff --git a/backport-include/linux/pm_qos_params.h b/backport-include/linux/pm_qos_params.h new file mode 100644 index 0000000..c591753 --- /dev/null +++ b/backport-include/linux/pm_qos_params.h @@ -0,0 +1,41 @@ +#ifndef __COMPAT_LINUX_PM_QOS_PARAMS_H +#define __COMPAT_LINUX_PM_QOS_PARAMS_H +#include <linux/version.h> + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)) +#include_next <linux/pm_qos_params.h> +#else +/* interface for the pm_qos_power infrastructure of the linux kernel. + * + * Mark Gross <mgross@linux.intel.com> + */ +#include <linux/list.h> +#include <linux/notifier.h> +#include <linux/miscdevice.h> + +#define PM_QOS_RESERVED 0 +#define PM_QOS_CPU_DMA_LATENCY 1 +#define PM_QOS_NETWORK_LATENCY 2 +#define PM_QOS_NETWORK_THROUGHPUT 3 +#define PM_QOS_SYSTEM_BUS_FREQ 4 + +#define PM_QOS_NUM_CLASSES 5 +#define PM_QOS_DEFAULT_VALUE -1 + +#define pm_qos_add_requirement LINUX_BACKPORT(pm_qos_add_requirement) +int pm_qos_add_requirement(int qos, char *name, s32 value); +#define pm_qos_update_requirement LINUX_BACKPORT(pm_qos_update_requirement) +int pm_qos_update_requirement(int qos, char *name, s32 new_value); +#define pm_qos_remove_requirement LINUX_BACKPORT(pm_qos_remove_requirement) +void pm_qos_remove_requirement(int qos, char *name); + +#define pm_qos_requirement LINUX_BACKPORT(pm_qos_requirement) +int pm_qos_requirement(int qos); + +#define pm_qos_add_notifier LINUX_BACKPORT(pm_qos_add_notifier) +int pm_qos_add_notifier(int qos, struct notifier_block *notifier); +#define pm_qos_remove_notifier LINUX_BACKPORT(pm_qos_remove_notifier) +int pm_qos_remove_notifier(int qos, struct notifier_block *notifier); +#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25)) */ + +#endif diff --git a/backport-include/linux/pm_runtime.h b/backport-include/linux/pm_runtime.h new file mode 100644 index 0000000..31cfde9 --- /dev/null +++ b/backport-include/linux/pm_runtime.h @@ -0,0 +1,65 @@ +#include <linux/version.h> + +#ifndef __COMPAT_LINUX_PM_RUNTIME_H +#define __COMPAT_LINUX_PM_RUNTIME_H + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)) +#include_next <linux/pm_runtime.h> +#else + +static inline void pm_runtime_enable(struct device *dev) {} + +#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) +/* + * Backports 5e928f77a09a07f9dd595bb8a489965d69a83458 + * run-time power management cannot really be backported + * given that the implementation added bus specific + * callbacks that we won't have on older kernels. If + * you really want run-time power management or good + * power management upgrade your kernel. We'll just + * compile this out as if run-time power management was + * disabled just as the kernel disables run-time power management + * when CONFIG_PM_RUNTIME is disabled. + */ +static inline void pm_runtime_init(struct device *dev) {} +static inline void pm_runtime_remove(struct device *dev) {} +static inline int pm_runtime_get(struct device *dev) +{ + return 0; +} + +static inline int pm_runtime_get_sync(struct device *dev) +{ + return 0; +} + +static inline int pm_runtime_put(struct device *dev) +{ + return 0; +} + +static inline int pm_runtime_put_sync(struct device *dev) +{ + return 0; +} + +static inline int pm_runtime_set_active(struct device *dev) +{ + return 0; +} + +static inline void pm_runtime_set_suspended(struct device *dev) +{ +} + +static inline void pm_runtime_disable(struct device *dev) +{ +} + +static inline void pm_runtime_put_noidle(struct device *dev) {} +static inline void pm_runtime_get_noresume(struct device *dev) {} +#endif + +#endif diff --git a/backport-include/linux/poll.h b/backport-include/linux/poll.h new file mode 100644 index 0000000..978b95c --- /dev/null +++ b/backport-include/linux/poll.h @@ -0,0 +1,21 @@ +#ifndef __BACKPORT_LINUX_POLL_H +#define __BACKPORT_LINUX_POLL_H +#include_next <linux/poll.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0) && \ + LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31) +#define poll_does_not_wait LINUX_BACKPORT(poll_does_not_wait) +static inline bool poll_does_not_wait(const poll_table *p) +{ + return p == NULL || p->qproc == NULL; +} + +#define poll_requested_events LINUX_BACKPORT(poll_requested_events) +static inline unsigned long poll_requested_events(const poll_table *p) +{ + return p ? p->key : ~0UL; +} +#endif /* 2.6.31 <= version < 3.4 */ + +#endif /* __BACKPORT_LINUX_POLL_H */ diff --git a/backport-include/linux/printk.h b/backport-include/linux/printk.h new file mode 100644 index 0000000..6bc9931 --- /dev/null +++ b/backport-include/linux/printk.h @@ -0,0 +1,105 @@ +#ifndef _COMPAT_LINUX_PRINTK_H +#define _COMPAT_LINUX_PRINTK_H 1 + +#include <linux/version.h> + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,36)) +#include_next <linux/printk.h> +#else +#include <linux/kernel.h> +#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35)) */ + +/* see pr_fmt at end of file */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0) +/* backports 7a555613 */ +#if defined(CONFIG_DYNAMIC_DEBUG) +#define dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) \ +do { \ + DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, \ + __builtin_constant_p(prefix_str) ? prefix_str : "hexdump");\ + if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT)) \ + print_hex_dump(KERN_DEBUG, prefix_str, \ + prefix_type, rowsize, groupsize, \ + buf, len, ascii); \ +} while (0) +#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) \ + dynamic_hex_dump(prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) +#else +#define print_hex_dump_debug(prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) \ + print_hex_dump(KERN_DEBUG, prefix_str, prefix_type, rowsize, \ + groupsize, buf, len, ascii) +#endif /* defined(CONFIG_DYNAMIC_DEBUG) */ + +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0) */ + +#ifndef pr_warn +#define pr_warn pr_warning +#endif + +#ifndef printk_once +#define printk_once(x...) ({ \ + static bool __print_once; \ + \ + if (!__print_once) { \ + __print_once = true; \ + printk(x); \ + } \ +}) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) +#define pr_emerg_once(fmt, ...) \ + printk_once(KERN_EMERG pr_fmt(fmt), ##__VA_ARGS__) +#define pr_alert_once(fmt, ...) \ + printk_once(KERN_ALERT pr_fmt(fmt), ##__VA_ARGS__) +#define pr_crit_once(fmt, ...) \ + printk_once(KERN_CRIT pr_fmt(fmt), ##__VA_ARGS__) +#define pr_err_once(fmt, ...) \ + printk_once(KERN_ERR pr_fmt(fmt), ##__VA_ARGS__) +#define pr_warn_once(fmt, ...) \ + printk_once(KERN_WARNING pr_fmt(fmt), ##__VA_ARGS__) +#define pr_notice_once(fmt, ...) \ + printk_once(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) +#define pr_info_once(fmt, ...) \ + printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) +#define pr_cont_once(fmt, ...) \ + printk_once(KERN_CONT pr_fmt(fmt), ##__VA_ARGS__) +#if defined(DEBUG) +#define pr_debug_once(fmt, ...) \ + printk_once(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) +#else +#define pr_debug_once(fmt, ...) \ + no_printk(KERN_DEBUG pr_fmt(fmt), ##__VA_ARGS__) +#endif +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) +/* mask va_format as RHEL6 backports this */ +#define va_format LINUX_BACKPORT(va_format) + +struct va_format { + const char *fmt; + va_list *va; +}; + +/* + * Dummy printk for disabled debugging statements to use whilst maintaining + * gcc's format and side-effect checking. + */ +/* mask no_printk as RHEL6 backports this */ +#define no_printk LINUX_BACKPORT(no_printk) +static inline __attribute__ ((format (printf, 1, 2))) +int no_printk(const char *s, ...) { return 0; } +#endif + +#endif /* _COMPAT_LINUX_PRINTK_H */ + +/* This must be outside -- see also kernel.h */ +#ifndef pr_fmt +#define pr_fmt(fmt) fmt +#endif diff --git a/backport-include/linux/proc_fs.h b/backport-include/linux/proc_fs.h new file mode 100644 index 0000000..05851d2 --- /dev/null +++ b/backport-include/linux/proc_fs.h @@ -0,0 +1,27 @@ +#ifndef __BACKPORT_PROC_FS_H +#define __BACKPORT_PROC_FS_H +#include_next <linux/proc_fs.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) + +#ifdef CONFIG_PROC_FS +/* + * backport of: + * procfs: new helper - PDE_DATA(inode) + */ +static inline void *PDE_DATA(const struct inode *inode) +{ + return PROC_I(inode)->pde->data; +} +extern void proc_set_size(struct proc_dir_entry *, loff_t); +extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t); +#else +static inline void *PDE_DATA(const struct inode *inode) {BUG(); return NULL;} +static inline void proc_set_size(struct proc_dir_entry *de, loff_t size) {} +static inline void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) {} +#endif /* CONFIG_PROC_FS */ + +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) */ + +#endif /* __BACKPORT_PROC_FS_H */ diff --git a/backport-include/linux/radix-tree.h b/backport-include/linux/radix-tree.h new file mode 100644 index 0000000..6ca7c05 --- /dev/null +++ b/backport-include/linux/radix-tree.h @@ -0,0 +1,218 @@ +/* + * Copyright (C) 2013 Konstantin Khlebnikov + * Copyright (C) 2013 Luis R. Rodriguez <mcgrof@do-not-panic.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, or (at + * your option) any later version. + * + */ +#ifndef BACKPORT_LINUX_RADIX_TREE_H +#define BACKPORT_LINUX_RADIX_TREE_H + +#include_next <linux/radix-tree.h> + +#ifdef CPTCFG_BACKPORT_BUILD_RADIX_HELPERS + +/** + * struct radix_tree_iter - radix tree iterator state + * + * @index: index of current slot + * @next_index: next-to-last index for this chunk + * @tags: bit-mask for tag-iterating + * + * This radix tree iterator works in terms of "chunks" of slots. A chunk is a + * subinterval of slots contained within one radix tree leaf node. It is + * described by a pointer to its first slot and a struct radix_tree_iter + * which holds the chunk's position in the tree and its size. For tagged + * iteration radix_tree_iter also holds the slots' bit-mask for one chosen + * radix tree tag. + */ +struct radix_tree_iter { + unsigned long index; + unsigned long next_index; + unsigned long tags; +}; + +#define RADIX_TREE_ITER_TAG_MASK 0x00FF /* tag index in lower byte */ +#define RADIX_TREE_ITER_TAGGED 0x0100 /* lookup tagged slots */ +#define RADIX_TREE_ITER_CONTIG 0x0200 /* stop at first hole */ + +/** + * radix_tree_iter_init - initialize radix tree iterator + * + * @iter: pointer to iterator state + * @start: iteration starting index + * Returns: NULL + */ +static __always_inline void ** +radix_tree_iter_init(struct radix_tree_iter *iter, unsigned long start) +{ + /* + * Leave iter->tags uninitialized. radix_tree_next_chunk() will fill it + * in the case of a successful tagged chunk lookup. If the lookup was + * unsuccessful or non-tagged then nobody cares about ->tags. + * + * Set index to zero to bypass next_index overflow protection. + * See the comment in radix_tree_next_chunk() for details. + */ + iter->index = 0; + iter->next_index = start; + return NULL; +} + +/** + * radix_tree_next_chunk - find next chunk of slots for iteration + * + * @root: radix tree root + * @iter: iterator state + * @flags: RADIX_TREE_ITER_* flags and tag index + * Returns: pointer to chunk first slot, or NULL if there no more left + * + * This function looks up the next chunk in the radix tree starting from + * @iter->next_index. It returns a pointer to the chunk's first slot. + * Also it fills @iter with data about chunk: position in the tree (index), + * its end (next_index), and constructs a bit mask for tagged iterating (tags). + */ +void **radix_tree_next_chunk(struct radix_tree_root *root, + struct radix_tree_iter *iter, unsigned flags); + +/** + * radix_tree_chunk_size - get current chunk size + * + * @iter: pointer to radix tree iterator + * Returns: current chunk size + */ +static __always_inline unsigned +radix_tree_chunk_size(struct radix_tree_iter *iter) +{ + return iter->next_index - iter->index; +} + +/** + * radix_tree_next_slot - find next slot in chunk + * + * @slot: pointer to current slot + * @iter: pointer to interator state + * @flags: RADIX_TREE_ITER_*, should be constant + * Returns: pointer to next slot, or NULL if there no more left + * + * This function updates @iter->index in the case of a successful lookup. + * For tagged lookup it also eats @iter->tags. + */ +static __always_inline void ** +radix_tree_next_slot(void **slot, struct radix_tree_iter *iter, unsigned flags) +{ + if (flags & RADIX_TREE_ITER_TAGGED) { + iter->tags >>= 1; + if (likely(iter->tags & 1ul)) { + iter->index++; + return slot + 1; + } + if (!(flags & RADIX_TREE_ITER_CONTIG) && likely(iter->tags)) { + unsigned offset = __ffs(iter->tags); + + iter->tags >>= offset; + iter->index += offset + 1; + return slot + offset + 1; + } + } else { + unsigned size = radix_tree_chunk_size(iter) - 1; + + while (size--) { + slot++; + iter->index++; + if (likely(*slot)) + return slot; + if (flags & RADIX_TREE_ITER_CONTIG) { + /* forbid switching to the next chunk */ + iter->next_index = 0; + break; + } + } + } + return NULL; +} + +/** + * radix_tree_for_each_chunk - iterate over chunks + * + * @slot: the void** variable for pointer to chunk first slot + * @root: the struct radix_tree_root pointer + * @iter: the struct radix_tree_iter pointer + * @start: iteration starting index + * @flags: RADIX_TREE_ITER_* and tag index + * + * Locks can be released and reacquired between iterations. + */ +#define radix_tree_for_each_chunk(slot, root, iter, start, flags) \ + for (slot = radix_tree_iter_init(iter, start) ; \ + (slot = radix_tree_next_chunk(root, iter, flags)) ;) + +/** + * radix_tree_for_each_chunk_slot - iterate over slots in one chunk + * + * @slot: the void** variable, at the beginning points to chunk first slot + * @iter: the struct radix_tree_iter pointer + * @flags: RADIX_TREE_ITER_*, should be constant + * + * This macro is designed to be nested inside radix_tree_for_each_chunk(). + * @slot points to the radix tree slot, @iter->index contains its index. + */ +#define radix_tree_for_each_chunk_slot(slot, iter, flags) \ + for (; slot ; slot = radix_tree_next_slot(slot, iter, flags)) + +/** + * radix_tree_for_each_slot - iterate over non-empty slots + * + * @slot: the void** variable for pointer to slot + * @root: the struct radix_tree_root pointer + * @iter: the struct radix_tree_iter pointer + * @start: iteration starting index + * + * @slot points to radix tree slot, @iter->index contains its index. + */ +#define radix_tree_for_each_slot(slot, root, iter, start) \ + for (slot = radix_tree_iter_init(iter, start) ; \ + slot || (slot = radix_tree_next_chunk(root, iter, 0)) ; \ + slot = radix_tree_next_slot(slot, iter, 0)) + +/** + * radix_tree_for_each_contig - iterate over contiguous slots + * + * @slot: the void** variable for pointer to slot + * @root: the struct radix_tree_root pointer + * @iter: the struct radix_tree_iter pointer + * @start: iteration starting index + * + * @slot points to radix tree slot, @iter->index contains its index. + */ +#define radix_tree_for_each_contig(slot, root, iter, start) \ + for (slot = radix_tree_iter_init(iter, start) ; \ + slot || (slot = radix_tree_next_chunk(root, iter, \ + RADIX_TREE_ITER_CONTIG)) ; \ + slot = radix_tree_next_slot(slot, iter, \ + RADIX_TREE_ITER_CONTIG)) + +/** + * radix_tree_for_each_tagged - iterate over tagged slots + * + * @slot: the void** variable for pointer to slot + * @root: the struct radix_tree_root pointer + * @iter: the struct radix_tree_iter pointer + * @start: iteration starting index + * @tag: tag index + * + * @slot points to radix tree slot, @iter->index contains its index. + */ +#define radix_tree_for_each_tagged(slot, root, iter, start, tag) \ + for (slot = radix_tree_iter_init(iter, start) ; \ + slot || (slot = radix_tree_next_chunk(root, iter, \ + RADIX_TREE_ITER_TAGGED | tag)) ; \ + slot = radix_tree_next_slot(slot, iter, \ + RADIX_TREE_ITER_TAGGED)) + +#endif /* CPTCFG_BACKPORT_BUILD_RADIX_HELPERS */ + +#endif /* BACKPORT_LINUX_RADIX_TREE_H */ diff --git a/backport-include/linux/random.h b/backport-include/linux/random.h new file mode 100644 index 0000000..812ce7f --- /dev/null +++ b/backport-include/linux/random.h @@ -0,0 +1,13 @@ +#ifndef __BACKPORT_RANDOM_H +#define __BACKPORT_RANDOM_H +#include_next <linux/random.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0) +/* backports 496f2f9 */ +#define prandom_seed(_seed) srandom32(_seed) +#define prandom_u32() random32() +#define prandom_u32_state(_state) prandom32(_state) +#endif + +#endif /* __BACKPORT_RANDOM_H */ diff --git a/backport-include/linux/rculist.h b/backport-include/linux/rculist.h new file mode 100644 index 0000000..73c47df --- /dev/null +++ b/backport-include/linux/rculist.h @@ -0,0 +1,54 @@ +#ifndef __BACKPORT_RCULIST_H +#define __BACKPORT_RCULIST_H +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,26) +#include_next <linux/rculist.h> +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0) +#include <backport/magic.h> +#define hlist_for_each_entry_rcu4(tpos, pos, head, member) \ + for (pos = rcu_dereference_raw(hlist_first_rcu(head)); \ + pos && \ + ({ tpos = hlist_entry(pos, typeof(*tpos), member); 1; });\ + pos = rcu_dereference_raw(hlist_next_rcu(pos))) + +#define hlist_for_each_entry_rcu3(pos, head, member) \ + for (pos = hlist_entry_safe (rcu_dereference_raw(hlist_first_rcu(head)),\ + typeof(*(pos)), member); \ + pos; \ + pos = hlist_entry_safe(rcu_dereference_raw(hlist_next_rcu( \ + &(pos)->member)), typeof(*(pos)), member)) + +#undef hlist_for_each_entry_rcu +#define hlist_for_each_entry_rcu(...) \ + macro_dispatcher(hlist_for_each_entry_rcu, __VA_ARGS__)(__VA_ARGS__) +#endif /* < 3.9 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) +/** + * backport: + * + * commit 67bdbffd696f29a0b68aa8daa285783a06651583 + * Author: Arnd Bergmann <arnd@arndb.de> + * Date: Thu Feb 25 16:55:13 2010 +0100 + * + * rculist: avoid __rcu annotations + */ +#define hlist_first_rcu(head) (*((struct hlist_node __rcu **)(&(head)->first))) +#define hlist_next_rcu(node) (*((struct hlist_node __rcu **)(&(node)->next))) + +#endif /* < 2.6.37 */ + +#ifndef list_for_each_entry_continue_rcu +#define list_for_each_entry_continue_rcu(pos, head, member) \ + for (pos = list_entry_rcu(pos->member.next, typeof(*pos), member); \ + prefetch(pos->member.next), &pos->member != (head); \ + pos = list_entry_rcu(pos->member.next, typeof(*pos), member)) +#endif + +#ifndef list_entry_rcu +#define list_entry_rcu(ptr, type, member) \ + container_of(rcu_dereference(ptr), type, member) +#endif + +#endif /* __BACKPORT_RCULIST_H */ diff --git a/backport-include/linux/rcupdate.h b/backport-include/linux/rcupdate.h new file mode 100644 index 0000000..d6d9262 --- /dev/null +++ b/backport-include/linux/rcupdate.h @@ -0,0 +1,51 @@ +#ifndef __BACKPORT_LINUX_RCUPDATE_H +#define __BACKPORT_LINUX_RCUPDATE_H +#include_next <linux/rcupdate.h> + +/* + * This adds a nested function everywhere kfree_rcu() was called. This + * function frees the memory and is given as a function to call_rcu(). + * The rcu callback could happen every time also after the module was + * unloaded and this will cause problems. To address that problem, we + * put rcu_barrier() into each module_exit() in module.h. + */ +#if !defined(kfree_rcu) +#define kfree_rcu(data, rcuhead) do { \ + void __kfree_rcu_fn(struct rcu_head *rcu_head) \ + { \ + void *___ptr; \ + ___ptr = container_of(rcu_head, typeof(*(data)), rcuhead);\ + kfree(___ptr); \ + } \ + call_rcu(&(data)->rcuhead, __kfree_rcu_fn); \ + } while (0) +#endif + +#ifndef RCU_INIT_POINTER +#define RCU_INIT_POINTER(p, v) \ + p = (typeof(*v) __force __rcu *)(v) +#endif + +#ifndef rcu_dereference_check +#define rcu_dereference_check(p, c) rcu_dereference(p) +#endif + +#ifndef rcu_dereference_protected +#define rcu_dereference_protected(p, c) (p) +#endif +#ifndef rcu_access_pointer +#define rcu_access_pointer(p) ACCESS_ONCE(p) +#endif + +#ifndef rcu_dereference_raw +#define rcu_dereference_raw(p) rcu_dereference(p) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) +static inline int rcu_read_lock_held(void) +{ + return 1; +} +#endif + +#endif /* __BACKPORT_LINUX_RCUPDATE_H */ diff --git a/backport-include/linux/regmap.h b/backport-include/linux/regmap.h new file mode 100644 index 0000000..ac6a3f2 --- /dev/null +++ b/backport-include/linux/regmap.h @@ -0,0 +1,56 @@ +#ifndef __BACKPORT_LINUX_REGMAP_H +#define __BACKPORT_LINUX_REGMAP_H +#include_next <linux/regmap.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0) && \ + LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0) +#define dev_get_regmap LINUX_BACKPORT(dev_get_regmap) +static inline +struct regmap *dev_get_regmap(struct device *dev, const char *name) +{ + return NULL; +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0) && \ + LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,0) +#if defined(CONFIG_REGMAP) +#define devm_regmap_init LINUX_BACKPORT(devm_regmap_init) +struct regmap *devm_regmap_init(struct device *dev, + const struct regmap_bus *bus, + const struct regmap_config *config); +#if defined(CONFIG_REGMAP_I2C) +#define devm_regmap_init_i2c LINUX_BACKPORT(devm_regmap_init_i2c) +struct regmap *devm_regmap_init_i2c(struct i2c_client *i2c, + const struct regmap_config *config); +#endif /* defined(CONFIG_REGMAP_I2C) */ +#if defined(CONFIG_REGMAP_SPI) +#define devm_regmap_init_spi LINUX_BACKPORT(devm_regmap_init_spi) +struct regmap *devm_regmap_init_spi(struct spi_device *dev, + const struct regmap_config *config); +#endif /* defined(CONFIG_REGMAP_SPI) */ + +/* + * We can't backport these unless we try to backport + * the full regmap into core so warn if used. + * No drivers are using this yet anyway. + */ +#define regmap_raw_write_async LINUX_BACKPORT(regmap_raw_write_async) +static inline int regmap_raw_write_async(struct regmap *map, unsigned int reg, + const void *val, size_t val_len) +{ + WARN_ONCE(1, "regmap API is disabled"); + return -EINVAL; +} + +#define regmap_async_complete LINUX_BACKPORT(regmap_async_complete) +static inline void regmap_async_complete(struct regmap *map) +{ + WARN_ONCE(1, "regmap API is disabled"); +} + +#endif /* defined(CONFIG_REGMAP) */ +#endif /* 3.2 <= version < 3.4 */ + +#endif /* __BACKPORT_LINUX_REGMAP_H */ diff --git a/backport-include/linux/regulator/driver.h b/backport-include/linux/regulator/driver.h new file mode 100644 index 0000000..fbd9845 --- /dev/null +++ b/backport-include/linux/regulator/driver.h @@ -0,0 +1,26 @@ +/* + * driver.h -- SoC Regulator driver support. + * + * Copyright (C) 2007, 2008 Wolfson Microelectronics PLC. + * + * Author: Liam Girdwood <lrg@slimlogic.co.uk> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * Regulator Driver Interface. + */ + +#ifndef __BACKPORT_LINUX_REGULATOR_DRIVER_H_ +#define __BACKPORT_LINUX_REGULATOR_DRIVER_H_ + +#include <linux/version.h> +#include_next <linux/regulator/driver.h> + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0)) +int regulator_map_voltage_ascend(struct regulator_dev *rdev, + int min_uV, int max_uV); +#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0)) */ + +#endif /* __BACKPORT_LINUX_REGULATOR_DRIVER_H_ */ diff --git a/backport-include/linux/rfkill.h b/backport-include/linux/rfkill.h new file mode 100644 index 0000000..188a23b --- /dev/null +++ b/backport-include/linux/rfkill.h @@ -0,0 +1,179 @@ +#ifndef __COMPAT_RFKILL_H +#define __COMPAT_RFKILL_H +#include <linux/version.h> + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,10,0) +#include_next <linux/rfkill.h> +#else +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,33) +/* API only slightly changed since then */ +#define rfkill_type old_rfkill_type +#define RFKILL_TYPE_ALL OLD_RFKILL_TYPE_ALL +#define RFKILL_TYPE_WLAN OLD_RFKILL_TYPE_WLAN +#define RFKILL_TYPE_BLUETOOTH OLD_RFKILL_TYPE_BLUETOOTH +#define RFKILL_TYPE_UWB OLD_RFKILL_TYPE_UWB +#define RFKILL_TYPE_WIMAX OLD_RFKILL_TYPE_WIMAX +#define RFKILL_TYPE_WWAN OLD_RFKILL_TYPE_WWAN +#define RFKILL_TYPE_GPS OLD_RFKILL_TYPE_GPS +#define RFKILL_TYPE_FM OLD_RFKILL_TYPE_FM +#define RFKILL_TYPE_NFC OLD_RFKILL_TYPE_NFC +#define NUM_RFKILL_TYPES OLD_NUM_RFKILL_TYPES +#include_next <linux/rfkill.h> +#undef rfkill_type +#undef RFKILL_TYPE_ALL +#undef RFKILL_TYPE_WLAN +#undef RFKILL_TYPE_BLUETOOTH +#undef RFKILL_TYPE_UWB +#undef RFKILL_TYPE_WIMAX +#undef RFKILL_TYPE_WWAN +#undef RFKILL_TYPE_GPS +#undef RFKILL_TYPE_FM +#undef RFKILL_TYPE_NFC +#undef NUM_RFKILL_TYPES +#define HAVE_OLD_RFKILL +#else +#undef HAVE_OLD_RFKILL +#include <linux/device.h> +struct rfkill; + +struct rfkill_ops { + void (*poll)(struct rfkill *rfkill, void *data); + void (*query)(struct rfkill *rfkill, void *data); + int (*set_block)(void *data, bool blocked); +}; +#endif + +/* this changes infrequently, backport manually */ +enum rfkill_type { + RFKILL_TYPE_ALL = 0, + RFKILL_TYPE_WLAN, + RFKILL_TYPE_BLUETOOTH, + RFKILL_TYPE_UWB, + RFKILL_TYPE_WIMAX, + RFKILL_TYPE_WWAN, + RFKILL_TYPE_GPS, + RFKILL_TYPE_FM, + RFKILL_TYPE_NFC, + NUM_RFKILL_TYPES, +}; + +static inline struct rfkill * __must_check +backport_rfkill_alloc(const char *name, + struct device *parent, + const enum rfkill_type type, + const struct rfkill_ops *ops, + void *ops_data) +{ +#ifdef HAVE_OLD_RFKILL + if ((unsigned int)type >= (unsigned int)OLD_NUM_RFKILL_TYPES) + return ERR_PTR(-ENODEV); + return rfkill_alloc(name, parent, (enum old_rfkill_type)type, + ops, ops_data); +#else + return ERR_PTR(-ENODEV); +#endif +} +#define rfkill_alloc backport_rfkill_alloc + +static inline int __must_check backport_rfkill_register(struct rfkill *rfkill) +{ + if (rfkill == ERR_PTR(-ENODEV)) + return 0; +#ifdef HAVE_OLD_RFKILL + return rfkill_register(rfkill); +#else + return -EINVAL; +#endif +} +#define rfkill_register backport_rfkill_register + +static inline void backport_rfkill_pause_polling(struct rfkill *rfkill) +{ +#ifdef HAVE_OLD_RFKILL + rfkill_pause_polling(rfkill); +#endif +} +#define rfkill_pause_polling backport_rfkill_pause_polling + +static inline void backport_rfkill_resume_polling(struct rfkill *rfkill) +{ +#ifdef HAVE_OLD_RFKILL + rfkill_resume_polling(rfkill); +#endif +} +#define rfkill_resume_polling backport_rfkill_resume_polling + +static inline void backport_rfkill_unregister(struct rfkill *rfkill) +{ +#ifdef HAVE_OLD_RFKILL + if (rfkill == ERR_PTR(-ENODEV)) + return; + rfkill_unregister(rfkill); +#endif +} +#define rfkill_unregister backport_rfkill_unregister + +static inline void backport_rfkill_destroy(struct rfkill *rfkill) +{ +#ifdef HAVE_OLD_RFKILL + if (rfkill == ERR_PTR(-ENODEV)) + return; + rfkill_destroy(rfkill); +#endif +} +#define rfkill_destroy backport_rfkill_destroy + +static inline bool backport_rfkill_set_hw_state(struct rfkill *rfkill, + bool blocked) +{ +#ifdef HAVE_OLD_RFKILL + if (rfkill != ERR_PTR(-ENODEV)) + return rfkill_set_hw_state(rfkill, blocked); +#endif + return blocked; +} +#define rfkill_set_hw_state backport_rfkill_set_hw_state + +static inline bool backport_rfkill_set_sw_state(struct rfkill *rfkill, + bool blocked) +{ +#ifdef HAVE_OLD_RFKILL + if (rfkill != ERR_PTR(-ENODEV)) + return rfkill_set_sw_state(rfkill, blocked); +#endif + return blocked; +} +#define rfkill_set_sw_state backport_rfkill_set_sw_state + +static inline void backport_rfkill_init_sw_state(struct rfkill *rfkill, + bool blocked) +{ +#ifdef HAVE_OLD_RFKILL + if (rfkill != ERR_PTR(-ENODEV)) + rfkill_init_sw_state(rfkill, blocked); +#endif +} +#define rfkill_init_sw_state backport_rfkill_init_sw_state + +static inline void backport_rfkill_set_states(struct rfkill *rfkill, + bool sw, bool hw) +{ +#ifdef HAVE_OLD_RFKILL + if (rfkill != ERR_PTR(-ENODEV)) + rfkill_set_states(rfkill, sw, hw); +#endif +} +#define rfkill_set_states backport_rfkill_set_states + +static inline bool backport_rfkill_blocked(struct rfkill *rfkill) +{ +#ifdef HAVE_OLD_RFKILL + if (rfkill != ERR_PTR(-ENODEV)) + return rfkill_blocked(rfkill); +#endif + return false; +} +#define rfkill_blocked backport_rfkill_blocked +#endif + +#endif diff --git a/backport-include/linux/rtnetlink.h b/backport-include/linux/rtnetlink.h new file mode 100644 index 0000000..56ba9f6 --- /dev/null +++ b/backport-include/linux/rtnetlink.h @@ -0,0 +1,24 @@ +#ifndef __BACKPORT_LINUX_RTNETLINK_H +#define __BACKPORT_LINUX_RTNETLINK_H +#include_next <linux/rtnetlink.h> + +#ifndef rtnl_dereference +#define rtnl_dereference(p) \ + rcu_dereference_protected(p, lockdep_rtnl_is_held()) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) +#ifdef CONFIG_PROVE_LOCKING +/* + * Obviously, this is wrong. But the base kernel will have rtnl_mutex + * declared static, with no way to access it. I think this is the best + * we can do... + */ +static inline int lockdep_rtnl_is_held(void) +{ + return 1; +} +#endif /* #ifdef CONFIG_PROVE_LOCKING */ +#endif /* < 2.6.34 */ + +#endif /* __BACKPORT_LINUX_RTNETLINK_H */ diff --git a/backport-include/linux/scatterlist.h b/backport-include/linux/scatterlist.h new file mode 100644 index 0000000..448730f --- /dev/null +++ b/backport-include/linux/scatterlist.h @@ -0,0 +1,112 @@ +#ifndef __BACKPORT_SCATTERLIST_H +#define __BACKPORT_SCATTERLIST_H +#include_next <linux/scatterlist.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) +struct sg_table { + struct scatterlist *sgl; /* the list */ + unsigned int nents; /* number of mapped entries */ + unsigned int orig_nents; /* original size of list */ +}; + +#define sg_alloc_fn LINUX_BACKPORT(sg_alloc_fn) +typedef struct scatterlist *(sg_alloc_fn)(unsigned int, gfp_t); + +#define sg_free_fn LINUX_BACKPORT(sg_free_fn) +typedef void (sg_free_fn)(struct scatterlist *, unsigned int); + +#define __sg_free_table LINUX_BACKPORT(__sg_free_table) +void __sg_free_table(struct sg_table *table, unsigned int max_ents, + sg_free_fn *free_fn); +#define sg_free_table LINUX_BACKPORT(sg_free_table) +void sg_free_table(struct sg_table *); +#define __sg_alloc_table LINUX_BACKPORT(__sg_alloc_table) +int __sg_alloc_table(struct sg_table *table, unsigned int nents, + unsigned int max_ents, gfp_t gfp_mask, + sg_alloc_fn *alloc_fn); +#define sg_alloc_table LINUX_BACKPORT(sg_alloc_table) +int sg_alloc_table(struct sg_table *table, unsigned int nents, gfp_t gfp_mask); + +#define SG_MAX_SINGLE_ALLOC (PAGE_SIZE / sizeof(struct scatterlist)) +#endif + +#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0)) +/* backports efc42bc9 */ +#define sg_alloc_table_from_pages LINUX_BACKPORT(sg_alloc_table_from_pages) +int sg_alloc_table_from_pages(struct sg_table *sgt, + struct page **pages, unsigned int n_pages, + unsigned long offset, unsigned long size, + gfp_t gfp_mask); +#endif /* < 3.6 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0) + +/* Lets expect distributions might backport this */ +#ifndef for_each_sg_page +/* + * sg page iterator + * + * Iterates over sg entries page-by-page. On each successful iteration, + * @piter->page points to the current page, @piter->sg to the sg holding this + * page and @piter->sg_pgoffset to the page's page offset within the sg. The + * iteration will stop either when a maximum number of sg entries was reached + * or a terminating sg (sg_last(sg) == true) was reached. + */ +struct sg_page_iter { + struct page *page; /* current page */ + struct scatterlist *sg; /* sg holding the page */ + unsigned int sg_pgoffset; /* page offset within the sg */ + + /* these are internal states, keep away */ + unsigned int __nents; /* remaining sg entries */ + int __pg_advance; /* nr pages to advance at the + * next step */ +}; + +#define __sg_page_iter_next LINUX_BACKPORT(__sg_page_iter_next) +bool __sg_page_iter_next(struct sg_page_iter *piter); +#define __sg_page_iter_start LINUX_BACKPORT(__sg_page_iter_start) +void __sg_page_iter_start(struct sg_page_iter *piter, + struct scatterlist *sglist, unsigned int nents, + unsigned long pgoffset); + +/** + * for_each_sg_page - iterate over the pages of the given sg list + * @sglist: sglist to iterate over + * @piter: page iterator to hold current page, sg, sg_pgoffset + * @nents: maximum number of sg entries to iterate over + * @pgoffset: starting page offset + */ +#define for_each_sg_page(sglist, piter, nents, pgoffset) \ + for (__sg_page_iter_start((piter), (sglist), (nents), (pgoffset)); \ + __sg_page_iter_next(piter);) + +#endif /* for_each_sg_page assumption */ +#endif /* version < 3.9 */ + +#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)) + +#define sg_page_iter_page LINUX_BACKPORT(sg_page_iter_page) +/** + * sg_page_iter_page - get the current page held by the page iterator + * @piter: page iterator holding the page + */ +static inline struct page *sg_page_iter_page(struct sg_page_iter *piter) +{ + return nth_page(sg_page(piter->sg), piter->sg_pgoffset); +} + +#define sg_page_iter_dma_address LINUX_BACKPORT(sg_page_iter_dma_address) +/** + * sg_page_iter_dma_address - get the dma address of the current page held by + * the page iterator. + * @piter: page iterator holding the page + */ +static inline dma_addr_t sg_page_iter_dma_address(struct sg_page_iter *piter) +{ + return sg_dma_address(piter->sg) + (piter->sg_pgoffset << PAGE_SHIFT); +} +#endif /* version < 3.10 */ + +#endif /* __BACKPORT_SCATTERLIST_H */ diff --git a/backport-include/linux/security.h b/backport-include/linux/security.h new file mode 100644 index 0000000..af95e25 --- /dev/null +++ b/backport-include/linux/security.h @@ -0,0 +1,18 @@ +#ifndef __BACKPORT_LINUX_SECURITY_H +#define __BACKPORT_LINUX_SECURITY_H +#include_next <linux/security.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0) +/* + * This has been defined in include/linux/security.h for some time, but was + * only given an EXPORT_SYMBOL for 3.1. Add a compat_* definition to avoid + * breaking the compile. + */ +#define security_sk_clone(a, b) compat_security_sk_clone(a, b) + +static inline void security_sk_clone(const struct sock *sk, struct sock *newsk) +{ +} +#endif + +#endif /* __BACKPORT_LINUX_SECURITY_H */ diff --git a/backport-include/linux/semaphore.h b/backport-include/linux/semaphore.h new file mode 100644 index 0000000..78af4db --- /dev/null +++ b/backport-include/linux/semaphore.h @@ -0,0 +1,12 @@ +#ifndef _COMPAT_LINUX_SEMAPHORE_H +#define _COMPAT_LINUX_SEMAPHORE_H 1 + +#include <linux/version.h> + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,25)) +#include_next <linux/semaphore.h> +#else +#include <asm/semaphore.h> +#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,25)) */ + +#endif /* _COMPAT_LINUX_SEMAPHORE_H */ diff --git a/backport-include/linux/seq_file.h b/backport-include/linux/seq_file.h new file mode 100644 index 0000000..17f7b3d --- /dev/null +++ b/backport-include/linux/seq_file.h @@ -0,0 +1,44 @@ +#ifndef __BACKPORT_SEQ_FILE_H +#define __BACKPORT_SEQ_FILE_H +#include_next <linux/seq_file.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0) +#include <linux/user_namespace.h> +#include <linux/file.h> +#include <linux/fs.h> +#ifdef CONFIG_USER_NS +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38) +static inline struct user_namespace *seq_user_ns(struct seq_file *seq) +{ + struct file *f = container_of((void *) seq, struct file, private_data); + + return f->f_cred->user_ns; +} +#else +static inline struct user_namespace *seq_user_ns(struct seq_file *seq) +{ + return current_user_ns(); +} +#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,38)) */ + +#else +static inline struct user_namespace *seq_user_ns(struct seq_file *seq) +{ + extern struct user_namespace init_user_ns; + return &init_user_ns; +} +#endif /* CONFIG_USER_NS */ +#endif /* < 3.7 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) +#define seq_hlist_start_head LINUX_BACKPORT(seq_hlist_start_head) +extern struct hlist_node *seq_hlist_start_head(struct hlist_head *head, + loff_t pos); + +#define seq_hlist_next LINUX_BACKPORT(seq_hlist_next) +extern struct hlist_node *seq_hlist_next(void *v, struct hlist_head *head, + loff_t *ppos); +#endif + +#endif /* __BACKPORT_SEQ_FILE_H */ diff --git a/backport-include/linux/shmem_fs.h b/backport-include/linux/shmem_fs.h new file mode 100644 index 0000000..f32de7a --- /dev/null +++ b/backport-include/linux/shmem_fs.h @@ -0,0 +1,37 @@ +#ifndef __BACKPORT_LINUX_SHMEM_FS_H +#define __BACKPORT_LINUX_SHMEM_FS_H +#include_next <linux/shmem_fs.h> + + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0) +/* This pulls-in a lot of non-exported symbol backports + * on kernels older than 2.6.32. There's no harm for not + * making this available on kernels < 2.6.32. */ +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)) +#include <linux/pagemap.h> +/* This backports the 2nd part of: + * + * commit d9d90e5eb70e09903dadff42099b6c948f814050 + * Author: Hugh Dickins <hughd@google.com> + * Date: Mon Jun 27 16:18:04 2011 -0700 + * + * tmpfs: add shmem_read_mapping_page_gfp + * + * First part is in compat-3.0.c. + */ +#define shmem_read_mapping_page_gfp LINUX_BACKPORT(shmem_read_mapping_page_gfp) +extern struct page *shmem_read_mapping_page_gfp(struct address_space *mapping, + pgoff_t index, gfp_t gfp); + + +#define shmem_read_mapping_page LINUX_BACKPORT(shmem_read_mapping_page) +static inline struct page *shmem_read_mapping_page( + struct address_space *mapping, pgoff_t index) +{ + return shmem_read_mapping_page_gfp(mapping, index, + mapping_gfp_mask(mapping)); +} +#endif +#endif + +#endif /* __BACKPORT_LINUX_SHMEM_FS_H */ diff --git a/backport-include/linux/skbuff.h b/backport-include/linux/skbuff.h new file mode 100644 index 0000000..d34378e --- /dev/null +++ b/backport-include/linux/skbuff.h @@ -0,0 +1,220 @@ +#ifndef __BACKPORT_SKBUFF_H +#define __BACKPORT_SKBUFF_H +#include_next <linux/skbuff.h> +#include <linux/version.h> + +#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28)) +extern void v2_6_28_skb_add_rx_frag(struct sk_buff *skb, int i, + struct page *page, + int off, int size); + +#define skb_add_rx_frag(skb, i, page, off, size, truesize) \ + v2_6_28_skb_add_rx_frag(skb, i, page, off, size) +#elif (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0)) +#define skb_add_rx_frag(skb, i, page, off, size, truesize) \ + skb_add_rx_frag(skb, i, page, off, size) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) +#define __pskb_copy LINUX_BACKPORT(__pskb_copy) +extern struct sk_buff *__pskb_copy(struct sk_buff *skb, + int headroom, gfp_t gfp_mask); + +static inline void skb_complete_wifi_ack(struct sk_buff *skb, bool acked) +{ + WARN_ON(1); +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0) +#include <linux/dma-mapping.h> + +/* mask skb_frag_page as RHEL6 backports this */ +#define skb_frag_page LINUX_BACKPORT(skb_frag_page) +static inline struct page *skb_frag_page(const skb_frag_t *frag) +{ + return frag->page; +} + +#define skb_frag_size LINUX_BACKPORT(skb_frag_size) +static inline unsigned int skb_frag_size(const skb_frag_t *frag) +{ + return frag->size; +} + +/* mask skb_frag_dma_map as RHEL6 backports this */ +#define skb_frag_dma_map LINUX_BACKPORT(skb_frag_dma_map) +static inline dma_addr_t skb_frag_dma_map(struct device *dev, + const skb_frag_t *frag, + size_t offset, size_t size, + enum dma_data_direction dir) +{ + return dma_map_page(dev, skb_frag_page(frag), + frag->page_offset + offset, size, dir); +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0) +/* mask __netdev_alloc_skb_ip_align as RHEL6 backports this */ +#define __netdev_alloc_skb_ip_align(a,b,c) compat__netdev_alloc_skb_ip_align(a,b,c) +static inline struct sk_buff *__netdev_alloc_skb_ip_align(struct net_device *dev, + unsigned int length, gfp_t gfp) +{ + struct sk_buff *skb = __netdev_alloc_skb(dev, length + NET_IP_ALIGN, gfp); + + if (NET_IP_ALIGN && skb) + skb_reserve(skb, NET_IP_ALIGN); + return skb; +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) +static inline int skb_checksum_start_offset(const struct sk_buff *skb) +{ + return skb->csum_start - skb_headroom(skb); +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) +static inline bool skb_has_frag_list(const struct sk_buff *skb) +{ + return skb_shinfo(skb)->frag_list != NULL; +} + +#define skb_checksum_none_assert LINUX_BACKPORT(skb_checksum_none_assert) + +static inline void skb_checksum_none_assert(struct sk_buff *skb) +{ +#ifdef DEBUG + BUG_ON(skb->ip_summed != CHECKSUM_NONE); +#endif +} +#endif /* < 2.6.37 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) +static inline bool skb_defer_rx_timestamp(struct sk_buff *skb) +{ + return false; +} + +static inline void skb_tx_timestamp(struct sk_buff *skb) +{ +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33) +/* mask netdev_alloc_skb_ip_align as debian squeeze also backports this */ +#define netdev_alloc_skb_ip_align LINUX_BACKPORT(netdev_alloc_skb_ip_align) + +static inline struct sk_buff *netdev_alloc_skb_ip_align(struct net_device *dev, + unsigned int length) +{ + struct sk_buff *skb = netdev_alloc_skb(dev, length + NET_IP_ALIGN); + + if (NET_IP_ALIGN && skb) + skb_reserve(skb, NET_IP_ALIGN); + return skb; +} +#endif + +#ifndef skb_walk_frags +#define skb_walk_frags(skb, iter) \ + for (iter = skb_shinfo(skb)->frag_list; iter; iter = iter->next) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) +static inline bool skb_queue_is_first(const struct sk_buff_head *list, + const struct sk_buff *skb) +{ + return (skb->prev == (struct sk_buff *) list); +} + +static inline struct sk_buff *skb_queue_prev(const struct sk_buff_head *list, + const struct sk_buff *skb) +{ + BUG_ON(skb_queue_is_first(list, skb)); + return skb->prev; +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) +static inline bool skb_queue_is_last(const struct sk_buff_head *list, + const struct sk_buff *skb) +{ + return (skb->next == (struct sk_buff *) list); +} + +static inline struct sk_buff *skb_queue_next(const struct sk_buff_head *list, + const struct sk_buff *skb) +{ + /* This BUG_ON may seem severe, but if we just return then we + * are going to dereference garbage. + */ + BUG_ON(skb_queue_is_last(list, skb)); + return skb->next; +} + +static inline void __skb_queue_head_init(struct sk_buff_head *list) +{ + list->prev = list->next = (struct sk_buff *)list; + list->qlen = 0; +} + +static inline void __skb_queue_splice(const struct sk_buff_head *list, + struct sk_buff *prev, + struct sk_buff *next) +{ + struct sk_buff *first = list->next; + struct sk_buff *last = list->prev; + + first->prev = prev; + prev->next = first; + + last->next = next; + next->prev = last; +} + +static inline void skb_queue_splice(const struct sk_buff_head *list, + struct sk_buff_head *head) +{ + if (!skb_queue_empty(list)) { + __skb_queue_splice(list, (struct sk_buff *) head, head->next); + head->qlen += list->qlen; + } +} + +static inline void skb_queue_splice_init(struct sk_buff_head *list, + struct sk_buff_head *head) +{ + if (!skb_queue_empty(list)) { + __skb_queue_splice(list, (struct sk_buff *) head, head->next); + head->qlen += list->qlen; + __skb_queue_head_init(list); + } +} + +static inline void skb_queue_splice_tail_init(struct sk_buff_head *list, + struct sk_buff_head *head) +{ + if (!skb_queue_empty(list)) { + __skb_queue_splice(list, head->prev, (struct sk_buff *) head); + head->qlen += list->qlen; + __skb_queue_head_init(list); + } +} + +static inline void skb_queue_splice_tail(const struct sk_buff_head *list, + struct sk_buff_head *head) +{ + if (!skb_queue_empty(list)) { + __skb_queue_splice(list, head->prev, (struct sk_buff *) head); + head->qlen += list->qlen; + } +} + +#define skb_queue_walk_from(queue, skb) \ + for (; skb != (struct sk_buff *)(queue); \ + skb = skb->next) +#endif /* < 2.6.28 */ + +#endif /* __BACKPORT_SKBUFF_H */ diff --git a/backport-include/linux/slab.h b/backport-include/linux/slab.h new file mode 100644 index 0000000..850020b --- /dev/null +++ b/backport-include/linux/slab.h @@ -0,0 +1,27 @@ +#ifndef __BACKPORT_SLAB_H +#define __BACKPORT_SLAB_H +#include_next <linux/slab.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0) +/* This backports: + * + * commit a8203725dfded5c1f79dca3368a4a273e24b59bb + * Author: Xi Wang <xi.wang@gmail.com> + * Date: Mon Mar 5 15:14:41 2012 -0800 + * + * slab: introduce kmalloc_array() + */ + +#include <linux/kernel.h> /* for SIZE_MAX */ + +#define kmalloc_array LINUX_BACKPORT(kmalloc_array) +static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags) +{ + if (size != 0 && n > SIZE_MAX / size) + return NULL; + return __kmalloc(n * size, flags); +} +#endif + +#endif /* __BACKPORT_SLAB_H */ diff --git a/backport-include/linux/socket.h b/backport-include/linux/socket.h new file mode 100644 index 0000000..4187af2 --- /dev/null +++ b/backport-include/linux/socket.h @@ -0,0 +1,13 @@ +#ifndef __BACKPORT_SOCKET_H +#define __BACKPORT_SOCKET_H +#include_next <linux/socket.h> + +#ifndef SOL_NFC +/* + * backport SOL_NFC -- see commit: + * NFC: llcp: Implement socket options + */ +#define SOL_NFC 280 +#endif + +#endif /* __BACKPORT_SOCKET_H */ diff --git a/backport-include/linux/string.h b/backport-include/linux/string.h new file mode 100644 index 0000000..819d141 --- /dev/null +++ b/backport-include/linux/string.h @@ -0,0 +1,11 @@ +#ifndef __BACKPORT_LINUX_STRING_H +#define __BACKPORT_LINUX_STRING_H +#include_next <linux/string.h> +#include <linux/version.h> + +#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0)) +#define memweight LINUX_BACKPORT(memweight) +extern size_t memweight(const void *ptr, size_t bytes); +#endif + +#endif /* __BACKPORT_LINUX_STRING_H */ diff --git a/backport-include/linux/sysfs.h b/backport-include/linux/sysfs.h new file mode 100644 index 0000000..a2ef73f --- /dev/null +++ b/backport-include/linux/sysfs.h @@ -0,0 +1,34 @@ +#ifndef __BACKPORT_LINUX_SYSFS_H +#define __BACKPORT_LINUX_SYSFS_H +#include_next <linux/sysfs.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) +#ifdef CONFIG_DEBUG_LOCK_ALLOC +#define sysfs_attr_init(attr) \ +do { \ + static struct lock_class_key __key; \ + \ + (attr)->key = &__key; \ +} while(0) +#else +#define sysfs_attr_init(attr) do {} while(0) +#endif + +/* mask sysfs_bin_attr_init as RHEL6 backports this */ +#if !defined(sysfs_bin_attr_init) +/** + * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute + * @attr: struct bin_attribute to initialize + * + * Initialize a dynamically allocated struct bin_attribute so we + * can make lockdep happy. This is a new requirement for + * attributes and initially this is only needed when lockdep is + * enabled. Lockdep gives a nice error when your attribute is + * added to sysfs if you don't have this. + */ +#define sysfs_bin_attr_init(bin_attr) sysfs_attr_init(&(bin_attr)->attr) +#endif +#endif + +#endif /* __BACKPORT_LINUX_SYSFS_H */ diff --git a/backport-include/linux/time.h b/backport-include/linux/time.h new file mode 100644 index 0000000..0bc12de --- /dev/null +++ b/backport-include/linux/time.h @@ -0,0 +1,27 @@ +#ifndef __BACKPORT_LINUX_TIME_H +#define __BACKPORT_LINUX_TIME_H +#include_next <linux/time.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) +/* + * Similar to the struct tm in userspace <time.h>, but it needs to be here so + * that the kernel source is self contained. + */ +struct tm { + int tm_sec; + int tm_min; + int tm_hour; + int tm_mday; + int tm_mon; + long tm_year; + int tm_wday; + int tm_yday; +}; + +#define time_to_tm LINUX_BACKPORT(time_to_tm) +void time_to_tm(time_t totalsecs, int offset, struct tm *result); + +#endif /* < 2.6.32 */ + +#endif /* __BACKPORT_LINUX_TIME_H */ diff --git a/backport-include/linux/timer.h b/backport-include/linux/timer.h new file mode 100644 index 0000000..2720584 --- /dev/null +++ b/backport-include/linux/timer.h @@ -0,0 +1,10 @@ +#ifndef __BACKPORT_LINUX_TIMER_H +#define __BACKPORT_LINUX_TIMER_H +#include_next <linux/timer.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) +#define round_jiffies_up LINUX_BACKPORT(round_jiffies_up) +unsigned long round_jiffies_up(unsigned long j); +#endif + +#endif /* __BACKPORT_LINUX_TIMER_H */ diff --git a/backport-include/linux/tracepoint.h b/backport-include/linux/tracepoint.h new file mode 100644 index 0000000..f67d8d3 --- /dev/null +++ b/backport-include/linux/tracepoint.h @@ -0,0 +1,46 @@ +#ifndef _COMPAT_LINUX_TRACEPOINT_H +#define _COMPAT_LINUX_TRACEPOINT_H 1 + +#include <linux/version.h> + +#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,32)) +/* + * Disable all tracing for older kernels + * < 2.6.27 had no tracing + * 2.6.27 had broken tracing + * 2.6.28-2.6.32 didn't have anything like DECLARE_EVENT_CLASS + * and faking it would be extremely difficult + */ +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,28)) +/* + * For 2.6.28+ include the original tracepoint.h (for kernel header + * files that require it to work) but override the defines the code + * uses to disable tracing completely. + */ +#include_next <linux/tracepoint.h> +#endif + +#undef CREATE_TRACE_POINTS + +#undef TRACE_EVENT +#define TRACE_EVENT(name, proto, ...) \ +static inline void trace_ ## name(proto) {} +#undef DECLARE_EVENT_CLASS +#define DECLARE_EVENT_CLASS(...) +#undef DEFINE_EVENT +#define DEFINE_EVENT(evt_class, name, proto, ...) \ +static inline void trace_ ## name(proto) {} +#undef EXPORT_TRACEPOINT_SYMBOL +#define EXPORT_TRACEPOINT_SYMBOL(...) + +#define TP_PROTO(args...) args +#define TP_ARGS(args...) args +#define TP_CONDITION(args...) args + +#else +/* since 2.6.33, tracing hasn't changed, so just include the kernel's file */ +#include_next <linux/tracepoint.h> + +#endif /* (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,32)) */ + +#endif /* _COMPAT_LINUX_TRACEPOINT_H */ diff --git a/backport-include/linux/tty.h b/backport-include/linux/tty.h new file mode 100644 index 0000000..b102645 --- /dev/null +++ b/backport-include/linux/tty.h @@ -0,0 +1,51 @@ +#ifndef __BACKPORT_LINUX_TTY_H +#define __BACKPORT_LINUX_TTY_H +#include_next <linux/tty.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39) && \ + LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) +#define tty_set_termios LINUX_BACKPORT(tty_set_termios) +extern int tty_set_termios(struct tty_struct *tty, struct ktermios *kt); +#endif + +/* + * This really belongs into uapi/asm-generic/termbits.h but + * that doesn't usually get included directly. + */ +#ifndef EXTPROC +#define EXTPROC 0200000 +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) +#include <linux/smp_lock.h> +static inline void tty_lock(void) __acquires(kernel_lock) +{ +#ifdef CONFIG_LOCK_KERNEL + /* kernel_locked is 1 for !CONFIG_LOCK_KERNEL */ + WARN_ON(kernel_locked()); +#endif + lock_kernel(); +} +static inline void tty_unlock(void) __releases(kernel_lock) +{ + unlock_kernel(); +} +#define tty_locked() (kernel_locked()) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) +#define n_tty_ioctl_helper LINUX_BACKPORT(n_tty_ioctl_helper) +extern int n_tty_ioctl_helper(struct tty_struct *tty, struct file *file, + unsigned int cmd, unsigned long arg); +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0) +/* Backports tty_lock: Localise the lock */ +#define tty_lock(__tty) tty_lock() +#define tty_unlock(__tty) tty_unlock() + +#define tty_port_register_device(port, driver, index, device) \ + tty_register_device(driver, index, device) +#endif + +#endif /* __BACKPORT_LINUX_TTY_H */ diff --git a/backport-include/linux/tty_flip.h b/backport-include/linux/tty_flip.h new file mode 100644 index 0000000..67ecd61 --- /dev/null +++ b/backport-include/linux/tty_flip.h @@ -0,0 +1,11 @@ +#ifndef __BACKPORT_TTY_FLIP_H +#define __BACKPORT_TTY_FLIP_H +#include_next <linux/tty_flip.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0) +#define tty_flip_buffer_push(port) tty_flip_buffer_push((port)->tty) +#define tty_insert_flip_string(port, chars, size) tty_insert_flip_string((port)->tty, chars, size) +#endif + +#endif /* __BACKPORT_TTY_FLIP_H */ diff --git a/backport-include/linux/types.h b/backport-include/linux/types.h new file mode 100644 index 0000000..1dd187a --- /dev/null +++ b/backport-include/linux/types.h @@ -0,0 +1,61 @@ +#ifndef __BACKPORT_TYPES_H +#define __BACKPORT_TYPES_H +#include_next <linux/types.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) +#if defined(CONFIG_X86) || defined(CONFIG_X86_64) + +#if defined(CONFIG_64BIT) || defined(CONFIG_X86_PAE) || defined(CONFIG_PHYS_64BIT) +typedef u64 phys_addr_t; +#else +typedef u32 phys_addr_t; +#endif + +#endif /* x86 */ +#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) /* < 2.6.25 */ + +#if defined(CONFIG_X86) || defined(CONFIG_X86_64) || defined(CONFIG_PPC) +/* + * CONFIG_PHYS_ADDR_T_64BIT was added as new to all architectures + * as of 2.6.28 but x86 and ppc had it already. + */ +#else +#if defined(CONFIG_64BIT) || defined(CONFIG_X86_PAE) || defined(CONFIG_PPC64) || defined(CONFIG_PHYS_64BIT) +#define CONFIG_PHYS_ADDR_T_64BIT 1 +typedef u64 phys_addr_t; +#else +typedef u32 phys_addr_t; +#endif + +#endif /* non x86 and ppc */ + +#endif /* < 2.6.28 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) && \ + (defined(CONFIG_ALPHA) || defined(CONFIG_AVR32) || \ + defined(CONFIG_BLACKFIN) || defined(CONFIG_CRIS) || \ + defined(CONFIG_H8300) || defined(CONFIG_IA64) || \ + defined(CONFIG_M68K) || defined(CONFIG_MIPS) || \ + defined(CONFIG_PARISC) || defined(CONFIG_S390) || \ + defined(CONFIG_PPC64) || defined(CONFIG_PPC32) || \ + defined(CONFIG_SUPERH) || defined(CONFIG_SPARC) || \ + defined(CONFIG_FRV) || defined(CONFIG_X86) || \ + defined(CONFIG_M32R) || defined(CONFIG_M68K) || \ + defined(CONFIG_MN10300) || defined(CONFIG_XTENSA) || \ + defined(CONFIG_ARM)) +#include <asm/atomic.h> +#elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) +typedef struct { + volatile int counter; +} atomic_t; + +#ifdef CONFIG_64BIT +typedef struct { + volatile long counter; +} atomic64_t; +#endif /* CONFIG_64BIT */ + +#endif + +#endif /* __BACKPORT_TYPES_H */ diff --git a/backport-include/linux/u64_stats_sync.h b/backport-include/linux/u64_stats_sync.h new file mode 100644 index 0000000..f15116c --- /dev/null +++ b/backport-include/linux/u64_stats_sync.h @@ -0,0 +1,144 @@ +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0)) +#include_next <linux/u64_stats_sync.h> +#else +#ifndef _LINUX_U64_STATS_SYNC_H +#define _LINUX_U64_STATS_SYNC_H + +/* + * To properly implement 64bits network statistics on 32bit and 64bit hosts, + * we provide a synchronization point, that is a noop on 64bit or UP kernels. + * + * Key points : + * 1) Use a seqcount on SMP 32bits, with low overhead. + * 2) Whole thing is a noop on 64bit arches or UP kernels. + * 3) Write side must ensure mutual exclusion or one seqcount update could + * be lost, thus blocking readers forever. + * If this synchronization point is not a mutex, but a spinlock or + * spinlock_bh() or disable_bh() : + * 3.1) Write side should not sleep. + * 3.2) Write side should not allow preemption. + * 3.3) If applicable, interrupts should be disabled. + * + * 4) If reader fetches several counters, there is no guarantee the whole values + * are consistent (remember point 1) : this is a noop on 64bit arches anyway) + * + * 5) readers are allowed to sleep or be preempted/interrupted : They perform + * pure reads. But if they have to fetch many values, it's better to not allow + * preemptions/interruptions to avoid many retries. + * + * 6) If counter might be written by an interrupt, readers should block interrupts. + * (On UP, there is no seqcount_t protection, a reader allowing interrupts could + * read partial values) + * + * 7) For softirq uses, readers can use u64_stats_fetch_begin_bh() and + * u64_stats_fetch_retry_bh() helpers + * + * Usage : + * + * Stats producer (writer) should use following template granted it already got + * an exclusive access to counters (a lock is already taken, or per cpu + * data is used [in a non preemptable context]) + * + * spin_lock_bh(...) or other synchronization to get exclusive access + * ... + * u64_stats_update_begin(&stats->syncp); + * stats->bytes64 += len; // non atomic operation + * stats->packets64++; // non atomic operation + * u64_stats_update_end(&stats->syncp); + * + * While a consumer (reader) should use following template to get consistent + * snapshot for each variable (but no guarantee on several ones) + * + * u64 tbytes, tpackets; + * unsigned int start; + * + * do { + * start = u64_stats_fetch_begin(&stats->syncp); + * tbytes = stats->bytes64; // non atomic operation + * tpackets = stats->packets64; // non atomic operation + * } while (u64_stats_fetch_retry(&stats->syncp, start)); + * + * + * Example of use in drivers/net/loopback.c, using per_cpu containers, + * in BH disabled context. + */ +#include <linux/seqlock.h> + +struct u64_stats_sync { +#if BITS_PER_LONG==32 && defined(CONFIG_SMP) + seqcount_t seq; +#endif +}; + +static inline void u64_stats_update_begin(struct u64_stats_sync *syncp) +{ +#if BITS_PER_LONG==32 && defined(CONFIG_SMP) + write_seqcount_begin(&syncp->seq); +#endif +} + +static inline void u64_stats_update_end(struct u64_stats_sync *syncp) +{ +#if BITS_PER_LONG==32 && defined(CONFIG_SMP) + write_seqcount_end(&syncp->seq); +#endif +} + +static inline unsigned int u64_stats_fetch_begin(const struct u64_stats_sync *syncp) +{ +#if BITS_PER_LONG==32 && defined(CONFIG_SMP) + return read_seqcount_begin(&syncp->seq); +#else +#if BITS_PER_LONG==32 + preempt_disable(); +#endif + return 0; +#endif +} + +static inline bool u64_stats_fetch_retry(const struct u64_stats_sync *syncp, + unsigned int start) +{ +#if BITS_PER_LONG==32 && defined(CONFIG_SMP) + return read_seqcount_retry(&syncp->seq, start); +#else +#if BITS_PER_LONG==32 + preempt_enable(); +#endif + return false; +#endif +} + +/* + * In case softirq handlers can update u64 counters, readers can use following helpers + * - SMP 32bit arches use seqcount protection, irq safe. + * - UP 32bit must disable BH. + * - 64bit have no problem atomically reading u64 values, irq safe. + */ +static inline unsigned int u64_stats_fetch_begin_bh(const struct u64_stats_sync *syncp) +{ +#if BITS_PER_LONG==32 && defined(CONFIG_SMP) + return read_seqcount_begin(&syncp->seq); +#else +#if BITS_PER_LONG==32 + local_bh_disable(); +#endif + return 0; +#endif +} + +static inline bool u64_stats_fetch_retry_bh(const struct u64_stats_sync *syncp, + unsigned int start) +{ +#if BITS_PER_LONG==32 && defined(CONFIG_SMP) + return read_seqcount_retry(&syncp->seq, start); +#else +#if BITS_PER_LONG==32 + local_bh_enable(); +#endif + return false; +#endif +} + +#endif /* _LINUX_U64_STATS_SYNC_H */ +#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,6,0)) */ diff --git a/backport-include/linux/uidgid.h b/backport-include/linux/uidgid.h new file mode 100644 index 0000000..ae1ed80 --- /dev/null +++ b/backport-include/linux/uidgid.h @@ -0,0 +1,221 @@ +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)) +#include_next <linux/uidgid.h> +#else + +#ifndef _LINUX_UIDGID_H +#define _LINUX_UIDGID_H + +/* + * A set of types for the internal kernel types representing uids and gids. + * + * The types defined in this header allow distinguishing which uids and gids in + * the kernel are values used by userspace and which uid and gid values are + * the internal kernel values. With the addition of user namespaces the values + * can be different. Using the type system makes it possible for the compiler + * to detect when we overlook these differences. + * + */ +#include <linux/types.h> +#include <linux/highuid.h> + +struct user_namespace; +extern struct user_namespace init_user_ns; + +#ifdef CONFIG_UIDGID_STRICT_TYPE_CHECKS + +typedef struct { + uid_t val; +} kuid_t; + + +typedef struct { + gid_t val; +} kgid_t; + +#define KUIDT_INIT(value) (kuid_t){ value } +#define KGIDT_INIT(value) (kgid_t){ value } + +static inline uid_t __kuid_val(kuid_t uid) +{ + return uid.val; +} + +static inline gid_t __kgid_val(kgid_t gid) +{ + return gid.val; +} + +#else + +typedef uid_t kuid_t; +typedef gid_t kgid_t; + +static inline uid_t __kuid_val(kuid_t uid) +{ + return uid; +} + +static inline gid_t __kgid_val(kgid_t gid) +{ + return gid; +} + +#define KUIDT_INIT(value) ((kuid_t) value ) +#define KGIDT_INIT(value) ((kgid_t) value ) + +#endif + +#define GLOBAL_ROOT_UID KUIDT_INIT(0) +#define GLOBAL_ROOT_GID KGIDT_INIT(0) + +#define INVALID_UID KUIDT_INIT(-1) +#define INVALID_GID KGIDT_INIT(-1) + +static inline bool uid_eq(kuid_t left, kuid_t right) +{ + return __kuid_val(left) == __kuid_val(right); +} + +static inline bool gid_eq(kgid_t left, kgid_t right) +{ + return __kgid_val(left) == __kgid_val(right); +} + +static inline bool uid_gt(kuid_t left, kuid_t right) +{ + return __kuid_val(left) > __kuid_val(right); +} + +static inline bool gid_gt(kgid_t left, kgid_t right) +{ + return __kgid_val(left) > __kgid_val(right); +} + +static inline bool uid_gte(kuid_t left, kuid_t right) +{ + return __kuid_val(left) >= __kuid_val(right); +} + +static inline bool gid_gte(kgid_t left, kgid_t right) +{ + return __kgid_val(left) >= __kgid_val(right); +} + +static inline bool uid_lt(kuid_t left, kuid_t right) +{ + return __kuid_val(left) < __kuid_val(right); +} + +static inline bool gid_lt(kgid_t left, kgid_t right) +{ + return __kgid_val(left) < __kgid_val(right); +} + +static inline bool uid_lte(kuid_t left, kuid_t right) +{ + return __kuid_val(left) <= __kuid_val(right); +} + +static inline bool gid_lte(kgid_t left, kgid_t right) +{ + return __kgid_val(left) <= __kgid_val(right); +} + +static inline bool uid_valid(kuid_t uid) +{ + return !uid_eq(uid, INVALID_UID); +} + +static inline bool gid_valid(kgid_t gid) +{ + return !gid_eq(gid, INVALID_GID); +} + +#ifdef CONFIG_USER_NS + +#define make_kuid LINUX_BACKPORT(make_kuid) +extern kuid_t make_kuid(struct user_namespace *from, uid_t uid); +#define make_kgid LINUX_BACKPORT(make_kgid) +extern kgid_t make_kgid(struct user_namespace *from, gid_t gid); + +#define from_kuid LINUX_BACKPORT(from_kuid) +extern uid_t from_kuid(struct user_namespace *to, kuid_t uid); +#define from_kgid LINUX_BACKPORT(from_kgid) +extern gid_t from_kgid(struct user_namespace *to, kgid_t gid); +#define from_kuid_munged LINUX_BACKPORT(from_kuid_munged) +extern uid_t from_kuid_munged(struct user_namespace *to, kuid_t uid); +#define from_kgid_munged LINUX_BACKPORT(from_kgid_munged) +extern gid_t from_kgid_munged(struct user_namespace *to, kgid_t gid); + +#define kuid_has_mapping LINUX_BACKPORT(kuid_has_mapping) +static inline bool kuid_has_mapping(struct user_namespace *ns, kuid_t uid) +{ + return from_kuid(ns, uid) != (uid_t) -1; +} + +#define kgid_has_mapping LINUX_BACKPORT(kgid_has_mapping) +static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid) +{ + return from_kgid(ns, gid) != (gid_t) -1; +} + +#else + +#define make_kuid LINUX_BACKPORT(make_kuid) +static inline kuid_t make_kuid(struct user_namespace *from, uid_t uid) +{ + return KUIDT_INIT(uid); +} + +#define make_kgid LINUX_BACKPORT(make_kgid) +static inline kgid_t make_kgid(struct user_namespace *from, gid_t gid) +{ + return KGIDT_INIT(gid); +} + +#define from_kuid LINUX_BACKPORT(from_kuid) +static inline uid_t from_kuid(struct user_namespace *to, kuid_t kuid) +{ + return __kuid_val(kuid); +} + +#define from_kgid LINUX_BACKPORT(from_kgid) +static inline gid_t from_kgid(struct user_namespace *to, kgid_t kgid) +{ + return __kgid_val(kgid); +} + +#define from_kuid_munged LINUX_BACKPORT(from_kuid_munged) +static inline uid_t from_kuid_munged(struct user_namespace *to, kuid_t kuid) +{ + uid_t uid = from_kuid(to, kuid); + if (uid == (uid_t)-1) + uid = overflowuid; + return uid; +} + +#define from_kgid_munged LINUX_BACKPORT(from_kgid_munged) +static inline gid_t from_kgid_munged(struct user_namespace *to, kgid_t kgid) +{ + gid_t gid = from_kgid(to, kgid); + if (gid == (gid_t)-1) + gid = overflowgid; + return gid; +} + +#define kuid_has_mapping LINUX_BACKPORT(kuid_has_mapping) +static inline bool kuid_has_mapping(struct user_namespace *ns, kuid_t uid) +{ + return true; +} + +#define kgid_has_mapping LINUX_BACKPORT(kgid_has_mapping) +static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid) +{ + return true; +} + +#endif /* CONFIG_USER_NS */ + +#endif /* _LINUX_UIDGID_H */ +#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) */ diff --git a/backport-include/linux/unaligned/access_ok.h b/backport-include/linux/unaligned/access_ok.h new file mode 100644 index 0000000..99c1b4d --- /dev/null +++ b/backport-include/linux/unaligned/access_ok.h @@ -0,0 +1,67 @@ +#ifndef _LINUX_UNALIGNED_ACCESS_OK_H +#define _LINUX_UNALIGNED_ACCESS_OK_H + +#include <linux/kernel.h> +#include <asm/byteorder.h> + +static inline u16 get_unaligned_le16(const void *p) +{ + return le16_to_cpup((__le16 *)p); +} + +static inline u32 get_unaligned_le32(const void *p) +{ + return le32_to_cpup((__le32 *)p); +} + +static inline u64 get_unaligned_le64(const void *p) +{ + return le64_to_cpup((__le64 *)p); +} + +static inline u16 get_unaligned_be16(const void *p) +{ + return be16_to_cpup((__be16 *)p); +} + +static inline u32 get_unaligned_be32(const void *p) +{ + return be32_to_cpup((__be32 *)p); +} + +static inline u64 get_unaligned_be64(const void *p) +{ + return be64_to_cpup((__be64 *)p); +} + +static inline void put_unaligned_le16(u16 val, void *p) +{ + *((__le16 *)p) = cpu_to_le16(val); +} + +static inline void put_unaligned_le32(u32 val, void *p) +{ + *((__le32 *)p) = cpu_to_le32(val); +} + +static inline void put_unaligned_le64(u64 val, void *p) +{ + *((__le64 *)p) = cpu_to_le64(val); +} + +static inline void put_unaligned_be16(u16 val, void *p) +{ + *((__be16 *)p) = cpu_to_be16(val); +} + +static inline void put_unaligned_be32(u32 val, void *p) +{ + *((__be32 *)p) = cpu_to_be32(val); +} + +static inline void put_unaligned_be64(u64 val, void *p) +{ + *((__be64 *)p) = cpu_to_be64(val); +} + +#endif /* _LINUX_UNALIGNED_ACCESS_OK_H */ diff --git a/backport-include/linux/unaligned/be_byteshift.h b/backport-include/linux/unaligned/be_byteshift.h new file mode 100644 index 0000000..9356b24 --- /dev/null +++ b/backport-include/linux/unaligned/be_byteshift.h @@ -0,0 +1,70 @@ +#ifndef _LINUX_UNALIGNED_BE_BYTESHIFT_H +#define _LINUX_UNALIGNED_BE_BYTESHIFT_H + +#include <linux/types.h> + +static inline u16 __get_unaligned_be16(const u8 *p) +{ + return p[0] << 8 | p[1]; +} + +static inline u32 __get_unaligned_be32(const u8 *p) +{ + return p[0] << 24 | p[1] << 16 | p[2] << 8 | p[3]; +} + +static inline u64 __get_unaligned_be64(const u8 *p) +{ + return (u64)__get_unaligned_be32(p) << 32 | + __get_unaligned_be32(p + 4); +} + +static inline void __put_unaligned_be16(u16 val, u8 *p) +{ + *p++ = val >> 8; + *p++ = val; +} + +static inline void __put_unaligned_be32(u32 val, u8 *p) +{ + __put_unaligned_be16(val >> 16, p); + __put_unaligned_be16(val, p + 2); +} + +static inline void __put_unaligned_be64(u64 val, u8 *p) +{ + __put_unaligned_be32(val >> 32, p); + __put_unaligned_be32(val, p + 4); +} + +static inline u16 get_unaligned_be16(const void *p) +{ + return __get_unaligned_be16((const u8 *)p); +} + +static inline u32 get_unaligned_be32(const void *p) +{ + return __get_unaligned_be32((const u8 *)p); +} + +static inline u64 get_unaligned_be64(const void *p) +{ + return __get_unaligned_be64((const u8 *)p); +} + +static inline void put_unaligned_be16(u16 val, void *p) +{ + __put_unaligned_be16(val, p); +} + +static inline void put_unaligned_be32(u32 val, void *p) +{ + __put_unaligned_be32(val, p); +} + +static inline void put_unaligned_be64(u64 val, void *p) +{ + __put_unaligned_be64(val, p); +} + +#endif /* _LINUX_UNALIGNED_BE_BYTESHIFT_H */ diff --git a/backport-include/linux/unaligned/be_memmove.h b/backport-include/linux/unaligned/be_memmove.h new file mode 100644 index 0000000..c2a76c5 --- /dev/null +++ b/backport-include/linux/unaligned/be_memmove.h @@ -0,0 +1,36 @@ +#ifndef _LINUX_UNALIGNED_BE_MEMMOVE_H +#define _LINUX_UNALIGNED_BE_MEMMOVE_H + +#include <linux/unaligned/memmove.h> + +static inline u16 get_unaligned_be16(const void *p) +{ + return __get_unaligned_memmove16((const u8 *)p); +} + +static inline u32 get_unaligned_be32(const void *p) +{ + return __get_unaligned_memmove32((const u8 *)p); +} + +static inline u64 get_unaligned_be64(const void *p) +{ + return __get_unaligned_memmove64((const u8 *)p); +} + +static inline void put_unaligned_be16(u16 val, void *p) +{ + __put_unaligned_memmove16(val, p); +} + +static inline void put_unaligned_be32(u32 val, void *p) +{ + __put_unaligned_memmove32(val, p); +} + +static inline void put_unaligned_be64(u64 val, void *p) +{ + __put_unaligned_memmove64(val, p); +} + +#endif /* _LINUX_UNALIGNED_LE_MEMMOVE_H */ diff --git a/backport-include/linux/unaligned/be_struct.h b/backport-include/linux/unaligned/be_struct.h new file mode 100644 index 0000000..1324158 --- /dev/null +++ b/backport-include/linux/unaligned/be_struct.h @@ -0,0 +1,36 @@ +#ifndef _LINUX_UNALIGNED_BE_STRUCT_H +#define _LINUX_UNALIGNED_BE_STRUCT_H + +#include <linux/unaligned/packed_struct.h> + +static inline u16 get_unaligned_be16(const void *p) +{ + return __get_unaligned_cpu16((const u8 *)p); +} + +static inline u32 get_unaligned_be32(const void *p) +{ + return __get_unaligned_cpu32((const u8 *)p); +} + +static inline u64 get_unaligned_be64(const void *p) +{ + return __get_unaligned_cpu64((const u8 *)p); +} + +static inline void put_unaligned_be16(u16 val, void *p) +{ + __put_unaligned_cpu16(val, p); +} + +static inline void put_unaligned_be32(u32 val, void *p) +{ + __put_unaligned_cpu32(val, p); +} + +static inline void put_unaligned_be64(u64 val, void *p) +{ + __put_unaligned_cpu64(val, p); +} + +#endif /* _LINUX_UNALIGNED_BE_STRUCT_H */ diff --git a/backport-include/linux/unaligned/generic.h b/backport-include/linux/unaligned/generic.h new file mode 100644 index 0000000..02d97ff --- /dev/null +++ b/backport-include/linux/unaligned/generic.h @@ -0,0 +1,68 @@ +#ifndef _LINUX_UNALIGNED_GENERIC_H +#define _LINUX_UNALIGNED_GENERIC_H + +/* + * Cause a link-time error if we try an unaligned access other than + * 1,2,4 or 8 bytes long + */ +extern void __bad_unaligned_access_size(void); + +#define __get_unaligned_le(ptr) ((__force typeof(*(ptr)))({ \ + __builtin_choose_expr(sizeof(*(ptr)) == 1, *(ptr), \ + __builtin_choose_expr(sizeof(*(ptr)) == 2, get_unaligned_le16((ptr)), \ + __builtin_choose_expr(sizeof(*(ptr)) == 4, get_unaligned_le32((ptr)), \ + __builtin_choose_expr(sizeof(*(ptr)) == 8, get_unaligned_le64((ptr)), \ + __bad_unaligned_access_size())))); \ + })) + +#define __get_unaligned_be(ptr) ((__force typeof(*(ptr)))({ \ + __builtin_choose_expr(sizeof(*(ptr)) == 1, *(ptr), \ + __builtin_choose_expr(sizeof(*(ptr)) == 2, get_unaligned_be16((ptr)), \ + __builtin_choose_expr(sizeof(*(ptr)) == 4, get_unaligned_be32((ptr)), \ + __builtin_choose_expr(sizeof(*(ptr)) == 8, get_unaligned_be64((ptr)), \ + __bad_unaligned_access_size())))); \ + })) + +#define __put_unaligned_le(val, ptr) ({ \ + void *__gu_p = (ptr); \ + switch (sizeof(*(ptr))) { \ + case 1: \ + *(u8 *)__gu_p = (__force u8)(val); \ + break; \ + case 2: \ + put_unaligned_le16((__force u16)(val), __gu_p); \ + break; \ + case 4: \ + put_unaligned_le32((__force u32)(val), __gu_p); \ + break; \ + case 8: \ + put_unaligned_le64((__force u64)(val), __gu_p); \ + break; \ + default: \ + __bad_unaligned_access_size(); \ + break; \ + } \ + (void)0; }) + +#define __put_unaligned_be(val, ptr) ({ \ + void *__gu_p = (ptr); \ + switch (sizeof(*(ptr))) { \ + case 1: \ + *(u8 *)__gu_p = (__force u8)(val); \ + break; \ + case 2: \ + put_unaligned_be16((__force u16)(val), __gu_p); \ + break; \ + case 4: \ + put_unaligned_be32((__force u32)(val), __gu_p); \ + break; \ + case 8: \ + put_unaligned_be64((__force u64)(val), __gu_p); \ + break; \ + default: \ + __bad_unaligned_access_size(); \ + break; \ + } \ + (void)0; }) + +#endif /* _LINUX_UNALIGNED_GENERIC_H */ diff --git a/backport-include/linux/unaligned/le_byteshift.h b/backport-include/linux/unaligned/le_byteshift.h new file mode 100644 index 0000000..be376fb --- /dev/null +++ b/backport-include/linux/unaligned/le_byteshift.h @@ -0,0 +1,70 @@ +#ifndef _LINUX_UNALIGNED_LE_BYTESHIFT_H +#define _LINUX_UNALIGNED_LE_BYTESHIFT_H + +#include <linux/types.h> + +static inline u16 __get_unaligned_le16(const u8 *p) +{ + return p[0] | p[1] << 8; +} + +static inline u32 __get_unaligned_le32(const u8 *p) +{ + return p[0] | p[1] << 8 | p[2] << 16 | p[3] << 24; +} + +static inline u64 __get_unaligned_le64(const u8 *p) +{ + return (u64)__get_unaligned_le32(p + 4) << 32 | + __get_unaligned_le32(p); +} + +static inline void __put_unaligned_le16(u16 val, u8 *p) +{ + *p++ = val; + *p++ = val >> 8; +} + +static inline void __put_unaligned_le32(u32 val, u8 *p) +{ + __put_unaligned_le16(val >> 16, p + 2); + __put_unaligned_le16(val, p); +} + +static inline void __put_unaligned_le64(u64 val, u8 *p) +{ + __put_unaligned_le32(val >> 32, p + 4); + __put_unaligned_le32(val, p); +} + +static inline u16 get_unaligned_le16(const void *p) +{ + return __get_unaligned_le16((const u8 *)p); +} + +static inline u32 get_unaligned_le32(const void *p) +{ + return __get_unaligned_le32((const u8 *)p); +} + +static inline u64 get_unaligned_le64(const void *p) +{ + return __get_unaligned_le64((const u8 *)p); +} + +static inline void put_unaligned_le16(u16 val, void *p) +{ + __put_unaligned_le16(val, p); +} + +static inline void put_unaligned_le32(u32 val, void *p) +{ + __put_unaligned_le32(val, p); +} + +static inline void put_unaligned_le64(u64 val, void *p) +{ + __put_unaligned_le64(val, p); +} + +#endif /* _LINUX_UNALIGNED_LE_BYTESHIFT_H */ diff --git a/backport-include/linux/unaligned/le_memmove.h b/backport-include/linux/unaligned/le_memmove.h new file mode 100644 index 0000000..269849b --- /dev/null +++ b/backport-include/linux/unaligned/le_memmove.h @@ -0,0 +1,36 @@ +#ifndef _LINUX_UNALIGNED_LE_MEMMOVE_H +#define _LINUX_UNALIGNED_LE_MEMMOVE_H + +#include <linux/unaligned/memmove.h> + +static inline u16 get_unaligned_le16(const void *p) +{ + return __get_unaligned_memmove16((const u8 *)p); +} + +static inline u32 get_unaligned_le32(const void *p) +{ + return __get_unaligned_memmove32((const u8 *)p); +} + +static inline u64 get_unaligned_le64(const void *p) +{ + return __get_unaligned_memmove64((const u8 *)p); +} + +static inline void put_unaligned_le16(u16 val, void *p) +{ + __put_unaligned_memmove16(val, p); +} + +static inline void put_unaligned_le32(u32 val, void *p) +{ + __put_unaligned_memmove32(val, p); +} + +static inline void put_unaligned_le64(u64 val, void *p) +{ + __put_unaligned_memmove64(val, p); +} + +#endif /* _LINUX_UNALIGNED_LE_MEMMOVE_H */ diff --git a/backport-include/linux/unaligned/le_struct.h b/backport-include/linux/unaligned/le_struct.h new file mode 100644 index 0000000..088c457 --- /dev/null +++ b/backport-include/linux/unaligned/le_struct.h @@ -0,0 +1,36 @@ +#ifndef _LINUX_UNALIGNED_LE_STRUCT_H +#define _LINUX_UNALIGNED_LE_STRUCT_H + +#include <linux/unaligned/packed_struct.h> + +static inline u16 get_unaligned_le16(const void *p) +{ + return __get_unaligned_cpu16((const u8 *)p); +} + +static inline u32 get_unaligned_le32(const void *p) +{ + return __get_unaligned_cpu32((const u8 *)p); +} + +static inline u64 get_unaligned_le64(const void *p) +{ + return __get_unaligned_cpu64((const u8 *)p); +} + +static inline void put_unaligned_le16(u16 val, void *p) +{ + __put_unaligned_cpu16(val, p); +} + +static inline void put_unaligned_le32(u32 val, void *p) +{ + __put_unaligned_cpu32(val, p); +} + +static inline void put_unaligned_le64(u64 val, void *p) +{ + __put_unaligned_cpu64(val, p); +} + +#endif /* _LINUX_UNALIGNED_LE_STRUCT_H */ diff --git a/backport-include/linux/unaligned/memmove.h b/backport-include/linux/unaligned/memmove.h new file mode 100644 index 0000000..eeb5a77 --- /dev/null +++ b/backport-include/linux/unaligned/memmove.h @@ -0,0 +1,45 @@ +#ifndef _LINUX_UNALIGNED_MEMMOVE_H +#define _LINUX_UNALIGNED_MEMMOVE_H + +#include <linux/kernel.h> +#include <linux/string.h> + +/* Use memmove here, so gcc does not insert a __builtin_memcpy. */ + +static inline u16 __get_unaligned_memmove16(const void *p) +{ + u16 tmp; + memmove(&tmp, p, 2); + return tmp; +} + +static inline u32 __get_unaligned_memmove32(const void *p) +{ + u32 tmp; + memmove(&tmp, p, 4); + return tmp; +} + +static inline u64 __get_unaligned_memmove64(const void *p) +{ + u64 tmp; + memmove(&tmp, p, 8); + return tmp; +} + +static inline void __put_unaligned_memmove16(u16 val, void *p) +{ + memmove(p, &val, 2); +} + +static inline void __put_unaligned_memmove32(u32 val, void *p) +{ + memmove(p, &val, 4); +} + +static inline void __put_unaligned_memmove64(u64 val, void *p) +{ + memmove(p, &val, 8); +} + +#endif /* _LINUX_UNALIGNED_MEMMOVE_H */ diff --git a/backport-include/linux/unaligned/packed_struct.h b/backport-include/linux/unaligned/packed_struct.h new file mode 100644 index 0000000..2498bb9 --- /dev/null +++ b/backport-include/linux/unaligned/packed_struct.h @@ -0,0 +1,46 @@ +#ifndef _LINUX_UNALIGNED_PACKED_STRUCT_H +#define _LINUX_UNALIGNED_PACKED_STRUCT_H + +#include <linux/kernel.h> + +struct __una_u16 { u16 x __attribute__((packed)); }; +struct __una_u32 { u32 x __attribute__((packed)); }; +struct __una_u64 { u64 x __attribute__((packed)); }; + +static inline u16 __get_unaligned_cpu16(const void *p) +{ + const struct __una_u16 *ptr = (const struct __una_u16 *)p; + return ptr->x; +} + +static inline u32 __get_unaligned_cpu32(const void *p) +{ + const struct __una_u32 *ptr = (const struct __una_u32 *)p; + return ptr->x; +} + +static inline u64 __get_unaligned_cpu64(const void *p) +{ + const struct __una_u64 *ptr = (const struct __una_u64 *)p; + return ptr->x; +} + +static inline void __put_unaligned_cpu16(u16 val, void *p) +{ + struct __una_u16 *ptr = (struct __una_u16 *)p; + ptr->x = val; +} + +static inline void __put_unaligned_cpu32(u32 val, void *p) +{ + struct __una_u32 *ptr = (struct __una_u32 *)p; + ptr->x = val; +} + +static inline void __put_unaligned_cpu64(u64 val, void *p) +{ + struct __una_u64 *ptr = (struct __una_u64 *)p; + ptr->x = val; +} + +#endif /* _LINUX_UNALIGNED_PACKED_STRUCT_H */ diff --git a/backport-include/linux/usb.h b/backport-include/linux/usb.h new file mode 100644 index 0000000..a217d16 --- /dev/null +++ b/backport-include/linux/usb.h @@ -0,0 +1,149 @@ +#ifndef __BACKPORT_USB_H +#define __BACKPORT_USB_H + +#include_next <linux/usb.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) +/** + * module_usb_driver() - Helper macro for registering a USB driver + * @__usb_driver: usb_driver struct + * + * Helper macro for USB drivers which do not do anything special in module + * init/exit. This eliminates a lot of boilerplate. Each module may only + * use this macro once, and calling it replaces module_init() and module_exit() + */ +#define module_usb_driver(__usb_driver) \ + module_driver(__usb_driver, usb_register, \ + usb_deregister) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,6,0) +/** + * Backports + * + * commit d81a5d1956731c453b85c141458d4ff5d6cc5366 + * Author: Gustavo Padovan <gustavo.padovan@collabora.co.uk> + * Date: Tue Jul 10 19:10:06 2012 -0300 + * + * USB: add USB_VENDOR_AND_INTERFACE_INFO() macro + */ +#include <linux/usb.h> +#define USB_VENDOR_AND_INTERFACE_INFO(vend, cl, sc, pr) \ + .match_flags = USB_DEVICE_ID_MATCH_INT_INFO \ + | USB_DEVICE_ID_MATCH_VENDOR, \ + .idVendor = (vend), \ + .bInterfaceClass = (cl), \ + .bInterfaceSubClass = (sc), \ + .bInterfaceProtocol = (pr) +#endif + +#ifndef USB_DEVICE_INTERFACE_NUMBER +/** + * USB_DEVICE_INTERFACE_NUMBER - describe a usb device with a specific interface number + * @vend: the 16 bit USB Vendor ID + * @prod: the 16 bit USB Product ID + * @num: bInterfaceNumber value + * + * This macro is used to create a struct usb_device_id that matches a + * specific interface number of devices. + */ +#define USB_DEVICE_INTERFACE_NUMBER(vend, prod, num) \ + .match_flags = USB_DEVICE_ID_MATCH_DEVICE, \ + .idVendor = (vend), \ + .idProduct = (prod) +#endif /* USB_DEVICE_INTERFACE_NUMBER */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) +#ifdef CPTCFG_BACKPORT_OPTION_USB_URB_THREAD_FIX +#define usb_scuttle_anchored_urbs LINUX_BACKPORT(usb_scuttle_anchored_urbs) +#define usb_get_from_anchor LINUX_BACKPORT(usb_get_from_anchor) +#define usb_unlink_anchored_urbs LINUX_BACKPORT(usb_unlink_anchored_urbs) + +extern void usb_unlink_anchored_urbs(struct usb_anchor *anchor); +extern struct urb *usb_get_from_anchor(struct usb_anchor *anchor); +extern void usb_scuttle_anchored_urbs(struct usb_anchor *anchor); +#endif +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) +/* mask usb_pipe_endpoint as RHEL6 backports this */ +#define usb_pipe_endpoint LINUX_BACKPORT(usb_pipe_endpoint) + +static inline struct usb_host_endpoint * +usb_pipe_endpoint(struct usb_device *dev, unsigned int pipe) +{ + struct usb_host_endpoint **eps; + eps = usb_pipein(pipe) ? dev->ep_in : dev->ep_out; + return eps[usb_pipeendpoint(pipe)]; +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) +#define usb_alloc_coherent(dev, size, mem_flags, dma) usb_buffer_alloc(dev, size, mem_flags, dma) +#define usb_free_coherent(dev, size, addr, dma) usb_buffer_free(dev, size, addr, dma) + +/* USB autosuspend and autoresume */ +static inline int usb_enable_autosuspend(struct usb_device *udev) +{ return 0; } +static inline int usb_disable_autosuspend(struct usb_device *udev) +{ return 0; } +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33) +#define usb_autopm_get_interface_no_resume LINUX_BACKPORT(usb_autopm_get_interface_no_resume) +#define usb_autopm_put_interface_no_suspend LINUX_BACKPORT(usb_autopm_put_interface_no_suspend) +#ifdef CONFIG_USB_SUSPEND +extern void usb_autopm_get_interface_no_resume(struct usb_interface *intf); +extern void usb_autopm_put_interface_no_suspend(struct usb_interface *intf); +#else +static inline void usb_autopm_get_interface_no_resume(struct usb_interface *intf) +{ +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)) + atomic_inc(&intf->pm_usage_cnt); +#else + intf->pm_usage_cnt++; +#endif +} +static inline void usb_autopm_put_interface_no_suspend(struct usb_interface *intf) +{ +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)) + atomic_dec(&intf->pm_usage_cnt); +#else + intf->pm_usage_cnt--; +#endif +} +#endif /* CONFIG_USB_SUSPEND */ +#endif /* < 2.6.33 */ + +#ifndef USB_SUBCLASS_VENDOR_SPEC +/* this is defined in usb/ch9.h, but we only need it through here */ +#define USB_SUBCLASS_VENDOR_SPEC 0xff +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) +static inline void usb_autopm_put_interface_async(struct usb_interface *intf) +{ } +static inline int usb_autopm_get_interface_async(struct usb_interface *intf) +{ return 0; } +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) && \ + LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23) +#if defined(CONFIG_USB) || defined(CONFIG_USB_MODULE) +#define usb_unpoison_anchored_urbs LINUX_BACKPORT(usb_unpoison_anchored_urbs) +extern void usb_unpoison_anchored_urbs(struct usb_anchor *anchor); +#endif /* CONFIG_USB */ +#endif /* 2.6.23 - 2.6.28 */ + +/* USB anchors were added as of 2.6.23 */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) && \ + LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23) +#define usb_unpoison_urb LINUX_BACKPORT(usb_unpoison_urb) +extern void usb_unpoison_urb(struct urb *urb); + +#define usb_anchor_empty LINUX_BACKPORT(usb_anchor_empty) +extern int usb_anchor_empty(struct usb_anchor *anchor); +#endif /* 2.6.23-2.6.27 */ + +#endif /* __BACKPORT_USB_H */ diff --git a/backport-include/linux/vga_switcheroo.h b/backport-include/linux/vga_switcheroo.h new file mode 100644 index 0000000..698f3f7 --- /dev/null +++ b/backport-include/linux/vga_switcheroo.h @@ -0,0 +1,43 @@ +#ifndef __BACKPORT_VGA_SWITCHEROO_H +#define __BACKPORT_VGA_SWITCHEROO_H +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,34) +#include_next <linux/vga_switcheroo.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0) +/* + * This backports: + * + * From 26ec685ff9d9c16525d8ec4c97e52fcdb187b302 Mon Sep 17 00:00:00 2001 + * From: Takashi Iwai <tiwai@suse.de> + * Date: Fri, 11 May 2012 07:51:17 +0200 + * Subject: [PATCH] vga_switcheroo: Introduce struct vga_switcheroo_client_ops + * + */ + +struct vga_switcheroo_client_ops { + void (*set_gpu_state)(struct pci_dev *dev, enum vga_switcheroo_state); + void (*reprobe)(struct pci_dev *dev); + bool (*can_switch)(struct pci_dev *dev); +}; + +/* Wrap around the old code and redefine vga_switcheroo_register_client() + * for older kernels < 3.5.0. + */ +static inline int compat_vga_switcheroo_register_client(struct pci_dev *dev, + const struct vga_switcheroo_client_ops *ops) { + + return vga_switcheroo_register_client(dev, + ops->set_gpu_state, +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,38)) + ops->reprobe, +#endif + ops->can_switch); +} + +#define vga_switcheroo_register_client(_dev, _ops) \ + compat_vga_switcheroo_register_client(_dev, _ops) + +#endif /* < 3.5 */ + +#endif /* >= 2.6.34 */ +#endif /* __BACKPORT_VGA_SWITCHEROO_H */ diff --git a/backport-include/linux/vgaarb.h b/backport-include/linux/vgaarb.h new file mode 100644 index 0000000..92f5a72 --- /dev/null +++ b/backport-include/linux/vgaarb.h @@ -0,0 +1,10 @@ +#ifndef __BACKPORT_LINUX_VGAARB_H +#define __BACKPORT_LINUX_VGAARB_H +#include <linux/version.h> +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0) +struct pci_dev; +#endif +#include <video/vga.h> +#include_next <linux/vgaarb.h> + +#endif /* __BACKPORT_LINUX_VGAARB_H */ diff --git a/backport-include/linux/vmalloc.h b/backport-include/linux/vmalloc.h new file mode 100644 index 0000000..9e8ff3b --- /dev/null +++ b/backport-include/linux/vmalloc.h @@ -0,0 +1,17 @@ +#ifndef __BACKPORT_LINUX_VMALLOC_H +#define __BACKPORT_LINUX_VMALLOC_H +#include_next <linux/vmalloc.h> +#include <linux/version.h> + +/* avoid warnings due to b3bdda02aa547a0753b4fdbc105e86ef9046b30b */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25) +#define vfree(ptr) vfree((void *)(ptr)) +#define vunmap(ptr) vunmap((void *)(ptr)) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) +#define vzalloc LINUX_BACKPORT(vzalloc) +extern void *vzalloc(unsigned long size); +#endif + +#endif /* __BACKPORT_LINUX_VMALLOC_H */ diff --git a/backport-include/linux/wait.h b/backport-include/linux/wait.h new file mode 100644 index 0000000..7ada8bc --- /dev/null +++ b/backport-include/linux/wait.h @@ -0,0 +1,24 @@ +#ifndef __BACKPORT_LINUX_WAIT_H +#define __BACKPORT_LINUX_WAIT_H +#include_next <linux/wait.h> + +/* This backports: + * + * commit 63b2001169e75cd71e917ec953fdab572e3f944a + * Author: Thomas Gleixner <tglx@linutronix.de> + * Date: Thu Dec 1 00:04:00 2011 +0100 + * + * sched/wait: Add __wake_up_all_locked() API + */ + +#ifndef wake_up_all_locked +extern void compat_wake_up_locked(wait_queue_head_t *q, unsigned int mode, int nr); +#define wake_up_all_locked(x) compat_wake_up_locked((x), TASK_NORMAL, 0) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) +#define wake_up_interruptible_poll(x, m) \ + __wake_up(x, TASK_INTERRUPTIBLE, 1, (void *) (m)) +#endif + +#endif /* __BACKPORT_LINUX_WAIT_H */ diff --git a/backport-include/linux/watchdog.h b/backport-include/linux/watchdog.h new file mode 100644 index 0000000..4aae6bb --- /dev/null +++ b/backport-include/linux/watchdog.h @@ -0,0 +1,10 @@ +#ifndef __BACKPORT_WATCHDOG_H +#define __BACKPORT_WATCHDOG_H +#include_next <linux/watchdog.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0) +struct watchdog_device { +}; +#endif + +#endif /* __BACKPORT_WATCHDOG_H */ diff --git a/backport-include/linux/wireless.h b/backport-include/linux/wireless.h new file mode 100644 index 0000000..4395b28 --- /dev/null +++ b/backport-include/linux/wireless.h @@ -0,0 +1,1162 @@ +/* + * This file define a set of standard wireless extensions + * + * Version : 22 16.3.07 + * + * Authors : Jean Tourrilhes - HPL - <jt@hpl.hp.com> + * Copyright (c) 1997-2007 Jean Tourrilhes, All Rights Reserved. + */ + +#ifndef _LINUX_WIRELESS_H +#define _LINUX_WIRELESS_H + +/************************** DOCUMENTATION **************************/ +/* + * Initial APIs (1996 -> onward) : + * ----------------------------- + * Basically, the wireless extensions are for now a set of standard ioctl + * call + /proc/net/wireless + * + * The entry /proc/net/wireless give statistics and information on the + * driver. + * This is better than having each driver having its entry because + * its centralised and we may remove the driver module safely. + * + * Ioctl are used to configure the driver and issue commands. This is + * better than command line options of insmod because we may want to + * change dynamically (while the driver is running) some parameters. + * + * The ioctl mechanimsm are copied from standard devices ioctl. + * We have the list of command plus a structure descibing the + * data exchanged... + * Note that to add these ioctl, I was obliged to modify : + * # net/core/dev.c (two place + add include) + * # net/ipv4/af_inet.c (one place + add include) + * + * /proc/net/wireless is a copy of /proc/net/dev. + * We have a structure for data passed from the driver to /proc/net/wireless + * Too add this, I've modified : + * # net/core/dev.c (two other places) + * # include/linux/netdevice.h (one place) + * # include/linux/proc_fs.h (one place) + * + * New driver API (2002 -> onward) : + * ------------------------------- + * This file is only concerned with the user space API and common definitions. + * The new driver API is defined and documented in : + * # include/net/iw_handler.h + * + * Note as well that /proc/net/wireless implementation has now moved in : + * # net/core/wireless.c + * + * Wireless Events (2002 -> onward) : + * -------------------------------- + * Events are defined at the end of this file, and implemented in : + * # net/core/wireless.c + * + * Other comments : + * -------------- + * Do not add here things that are redundant with other mechanisms + * (drivers init, ifconfig, /proc/net/dev, ...) and with are not + * wireless specific. + * + * These wireless extensions are not magic : each driver has to provide + * support for them... + * + * IMPORTANT NOTE : As everything in the kernel, this is very much a + * work in progress. Contact me if you have ideas of improvements... + */ + +/***************************** INCLUDES *****************************/ + +#include <linux/types.h> /* for __u* and __s* typedefs */ +#include <linux/socket.h> /* for "struct sockaddr" et al */ +#include <linux/if.h> /* for IFNAMSIZ and co... */ + +/***************************** VERSION *****************************/ +/* + * This constant is used to know the availability of the wireless + * extensions and to know which version of wireless extensions it is + * (there is some stuff that will be added in the future...) + * I just plan to increment with each new version. + */ +#define WIRELESS_EXT 22 + +/* + * Changes : + * + * V2 to V3 + * -------- + * Alan Cox start some incompatibles changes. I've integrated a bit more. + * - Encryption renamed to Encode to avoid US regulation problems + * - Frequency changed from float to struct to avoid problems on old 386 + * + * V3 to V4 + * -------- + * - Add sensitivity + * + * V4 to V5 + * -------- + * - Missing encoding definitions in range + * - Access points stuff + * + * V5 to V6 + * -------- + * - 802.11 support (ESSID ioctls) + * + * V6 to V7 + * -------- + * - define IW_ESSID_MAX_SIZE and IW_MAX_AP + * + * V7 to V8 + * -------- + * - Changed my e-mail address + * - More 802.11 support (nickname, rate, rts, frag) + * - List index in frequencies + * + * V8 to V9 + * -------- + * - Support for 'mode of operation' (ad-hoc, managed...) + * - Support for unicast and multicast power saving + * - Change encoding to support larger tokens (>64 bits) + * - Updated iw_params (disable, flags) and use it for NWID + * - Extracted iw_point from iwreq for clarity + * + * V9 to V10 + * --------- + * - Add PM capability to range structure + * - Add PM modifier : MAX/MIN/RELATIVE + * - Add encoding option : IW_ENCODE_NOKEY + * - Add TxPower ioctls (work like TxRate) + * + * V10 to V11 + * ---------- + * - Add WE version in range (help backward/forward compatibility) + * - Add retry ioctls (work like PM) + * + * V11 to V12 + * ---------- + * - Add SIOCSIWSTATS to get /proc/net/wireless programatically + * - Add DEV PRIVATE IOCTL to avoid collisions in SIOCDEVPRIVATE space + * - Add new statistics (frag, retry, beacon) + * - Add average quality (for user space calibration) + * + * V12 to V13 + * ---------- + * - Document creation of new driver API. + * - Extract union iwreq_data from struct iwreq (for new driver API). + * - Rename SIOCSIWNAME as SIOCSIWCOMMIT + * + * V13 to V14 + * ---------- + * - Wireless Events support : define struct iw_event + * - Define additional specific event numbers + * - Add "addr" and "param" fields in union iwreq_data + * - AP scanning stuff (SIOCSIWSCAN and friends) + * + * V14 to V15 + * ---------- + * - Add IW_PRIV_TYPE_ADDR for struct sockaddr private arg + * - Make struct iw_freq signed (both m & e), add explicit padding + * - Add IWEVCUSTOM for driver specific event/scanning token + * - Add IW_MAX_GET_SPY for driver returning a lot of addresses + * - Add IW_TXPOW_RANGE for range of Tx Powers + * - Add IWEVREGISTERED & IWEVEXPIRED events for Access Points + * - Add IW_MODE_MONITOR for passive monitor + * + * V15 to V16 + * ---------- + * - Increase the number of bitrates in iw_range to 32 (for 802.11g) + * - Increase the number of frequencies in iw_range to 32 (for 802.11b+a) + * - Reshuffle struct iw_range for increases, add filler + * - Increase IW_MAX_AP to 64 for driver returning a lot of addresses + * - Remove IW_MAX_GET_SPY because conflict with enhanced spy support + * - Add SIOCSIWTHRSPY/SIOCGIWTHRSPY and "struct iw_thrspy" + * - Add IW_ENCODE_TEMP and iw_range->encoding_login_index + * + * V16 to V17 + * ---------- + * - Add flags to frequency -> auto/fixed + * - Document (struct iw_quality *)->updated, add new flags (INVALID) + * - Wireless Event capability in struct iw_range + * - Add support for relative TxPower (yick !) + * + * V17 to V18 (From Jouni Malinen <j@w1.fi>) + * ---------- + * - Add support for WPA/WPA2 + * - Add extended encoding configuration (SIOCSIWENCODEEXT and + * SIOCGIWENCODEEXT) + * - Add SIOCSIWGENIE/SIOCGIWGENIE + * - Add SIOCSIWMLME + * - Add SIOCSIWPMKSA + * - Add struct iw_range bit field for supported encoding capabilities + * - Add optional scan request parameters for SIOCSIWSCAN + * - Add SIOCSIWAUTH/SIOCGIWAUTH for setting authentication and WPA + * related parameters (extensible up to 4096 parameter values) + * - Add wireless events: IWEVGENIE, IWEVMICHAELMICFAILURE, + * IWEVASSOCREQIE, IWEVASSOCRESPIE, IWEVPMKIDCAND + * + * V18 to V19 + * ---------- + * - Remove (struct iw_point *)->pointer from events and streams + * - Remove header includes to help user space + * - Increase IW_ENCODING_TOKEN_MAX from 32 to 64 + * - Add IW_QUAL_ALL_UPDATED and IW_QUAL_ALL_INVALID macros + * - Add explicit flag to tell stats are in dBm : IW_QUAL_DBM + * - Add IW_IOCTL_IDX() and IW_EVENT_IDX() macros + * + * V19 to V20 + * ---------- + * - RtNetlink requests support (SET/GET) + * + * V20 to V21 + * ---------- + * - Remove (struct net_device *)->get_wireless_stats() + * - Change length in ESSID and NICK to strlen() instead of strlen()+1 + * - Add IW_RETRY_SHORT/IW_RETRY_LONG retry modifiers + * - Power/Retry relative values no longer * 100000 + * - Add explicit flag to tell stats are in 802.11k RCPI : IW_QUAL_RCPI + * + * V21 to V22 + * ---------- + * - Prevent leaking of kernel space in stream on 64 bits. + */ + +/**************************** CONSTANTS ****************************/ + +/* -------------------------- IOCTL LIST -------------------------- */ + +/* Wireless Identification */ +#define SIOCSIWCOMMIT 0x8B00 /* Commit pending changes to driver */ +#define SIOCGIWNAME 0x8B01 /* get name == wireless protocol */ +/* SIOCGIWNAME is used to verify the presence of Wireless Extensions. + * Common values : "IEEE 802.11-DS", "IEEE 802.11-FH", "IEEE 802.11b"... + * Don't put the name of your driver there, it's useless. */ + +/* Basic operations */ +#define SIOCSIWNWID 0x8B02 /* set network id (pre-802.11) */ +#define SIOCGIWNWID 0x8B03 /* get network id (the cell) */ +#define SIOCSIWFREQ 0x8B04 /* set channel/frequency (Hz) */ +#define SIOCGIWFREQ 0x8B05 /* get channel/frequency (Hz) */ +#define SIOCSIWMODE 0x8B06 /* set operation mode */ +#define SIOCGIWMODE 0x8B07 /* get operation mode */ +#define SIOCSIWSENS 0x8B08 /* set sensitivity (dBm) */ +#define SIOCGIWSENS 0x8B09 /* get sensitivity (dBm) */ + +/* Informative stuff */ +#define SIOCSIWRANGE 0x8B0A /* Unused */ +#define SIOCGIWRANGE 0x8B0B /* Get range of parameters */ +#define SIOCSIWPRIV 0x8B0C /* Unused */ +#define SIOCGIWPRIV 0x8B0D /* get private ioctl interface info */ +#define SIOCSIWSTATS 0x8B0E /* Unused */ +#define SIOCGIWSTATS 0x8B0F /* Get /proc/net/wireless stats */ +/* SIOCGIWSTATS is strictly used between user space and the kernel, and + * is never passed to the driver (i.e. the driver will never see it). */ + +/* Spy support (statistics per MAC address - used for Mobile IP support) */ +#define SIOCSIWSPY 0x8B10 /* set spy addresses */ +#define SIOCGIWSPY 0x8B11 /* get spy info (quality of link) */ +#define SIOCSIWTHRSPY 0x8B12 /* set spy threshold (spy event) */ +#define SIOCGIWTHRSPY 0x8B13 /* get spy threshold */ + +/* Access Point manipulation */ +#define SIOCSIWAP 0x8B14 /* set access point MAC addresses */ +#define SIOCGIWAP 0x8B15 /* get access point MAC addresses */ +#define SIOCGIWAPLIST 0x8B17 /* Deprecated in favor of scanning */ +#define SIOCSIWSCAN 0x8B18 /* trigger scanning (list cells) */ +#define SIOCGIWSCAN 0x8B19 /* get scanning results */ + +/* 802.11 specific support */ +#define SIOCSIWESSID 0x8B1A /* set ESSID (network name) */ +#define SIOCGIWESSID 0x8B1B /* get ESSID */ +#define SIOCSIWNICKN 0x8B1C /* set node name/nickname */ +#define SIOCGIWNICKN 0x8B1D /* get node name/nickname */ +/* As the ESSID and NICKN are strings up to 32 bytes long, it doesn't fit + * within the 'iwreq' structure, so we need to use the 'data' member to + * point to a string in user space, like it is done for RANGE... */ + +/* Other parameters useful in 802.11 and some other devices */ +#define SIOCSIWRATE 0x8B20 /* set default bit rate (bps) */ +#define SIOCGIWRATE 0x8B21 /* get default bit rate (bps) */ +#define SIOCSIWRTS 0x8B22 /* set RTS/CTS threshold (bytes) */ +#define SIOCGIWRTS 0x8B23 /* get RTS/CTS threshold (bytes) */ +#define SIOCSIWFRAG 0x8B24 /* set fragmentation thr (bytes) */ +#define SIOCGIWFRAG 0x8B25 /* get fragmentation thr (bytes) */ +#define SIOCSIWTXPOW 0x8B26 /* set transmit power (dBm) */ +#define SIOCGIWTXPOW 0x8B27 /* get transmit power (dBm) */ +#define SIOCSIWRETRY 0x8B28 /* set retry limits and lifetime */ +#define SIOCGIWRETRY 0x8B29 /* get retry limits and lifetime */ + +/* Encoding stuff (scrambling, hardware security, WEP...) */ +#define SIOCSIWENCODE 0x8B2A /* set encoding token & mode */ +#define SIOCGIWENCODE 0x8B2B /* get encoding token & mode */ +/* Power saving stuff (power management, unicast and multicast) */ +#define SIOCSIWPOWER 0x8B2C /* set Power Management settings */ +#define SIOCGIWPOWER 0x8B2D /* get Power Management settings */ + +/* WPA : Generic IEEE 802.11 informatiom element (e.g., for WPA/RSN/WMM). + * This ioctl uses struct iw_point and data buffer that includes IE id and len + * fields. More than one IE may be included in the request. Setting the generic + * IE to empty buffer (len=0) removes the generic IE from the driver. Drivers + * are allowed to generate their own WPA/RSN IEs, but in these cases, drivers + * are required to report the used IE as a wireless event, e.g., when + * associating with an AP. */ +#define SIOCSIWGENIE 0x8B30 /* set generic IE */ +#define SIOCGIWGENIE 0x8B31 /* get generic IE */ + +/* WPA : IEEE 802.11 MLME requests */ +#define SIOCSIWMLME 0x8B16 /* request MLME operation; uses + * struct iw_mlme */ +/* WPA : Authentication mode parameters */ +#define SIOCSIWAUTH 0x8B32 /* set authentication mode params */ +#define SIOCGIWAUTH 0x8B33 /* get authentication mode params */ + +/* WPA : Extended version of encoding configuration */ +#define SIOCSIWENCODEEXT 0x8B34 /* set encoding token & mode */ +#define SIOCGIWENCODEEXT 0x8B35 /* get encoding token & mode */ + +/* WPA2 : PMKSA cache management */ +#define SIOCSIWPMKSA 0x8B36 /* PMKSA cache operation */ + +/* -------------------- DEV PRIVATE IOCTL LIST -------------------- */ + +/* These 32 ioctl are wireless device private, for 16 commands. + * Each driver is free to use them for whatever purpose it chooses, + * however the driver *must* export the description of those ioctls + * with SIOCGIWPRIV and *must* use arguments as defined below. + * If you don't follow those rules, DaveM is going to hate you (reason : + * it make mixed 32/64bit operation impossible). + */ +#define SIOCIWFIRSTPRIV 0x8BE0 +#define SIOCIWLASTPRIV 0x8BFF +/* Previously, we were using SIOCDEVPRIVATE, but we now have our + * separate range because of collisions with other tools such as + * 'mii-tool'. + * We now have 32 commands, so a bit more space ;-). + * Also, all 'even' commands are only usable by root and don't return the + * content of ifr/iwr to user (but you are not obliged to use the set/get + * convention, just use every other two command). More details in iwpriv.c. + * And I repeat : you are not forced to use them with iwpriv, but you + * must be compliant with it. + */ + +/* ------------------------- IOCTL STUFF ------------------------- */ + +/* The first and the last (range) */ +#define SIOCIWFIRST 0x8B00 +#define SIOCIWLAST SIOCIWLASTPRIV /* 0x8BFF */ +#define IW_IOCTL_IDX(cmd) ((cmd) - SIOCIWFIRST) +#define IW_HANDLER(id, func) \ + [IW_IOCTL_IDX(id)] = func + +/* Odd : get (world access), even : set (root access) */ +#define IW_IS_SET(cmd) (!((cmd) & 0x1)) +#define IW_IS_GET(cmd) ((cmd) & 0x1) + +/* ----------------------- WIRELESS EVENTS ----------------------- */ +/* Those are *NOT* ioctls, do not issue request on them !!! */ +/* Most events use the same identifier as ioctl requests */ + +#define IWEVTXDROP 0x8C00 /* Packet dropped to excessive retry */ +#define IWEVQUAL 0x8C01 /* Quality part of statistics (scan) */ +#define IWEVCUSTOM 0x8C02 /* Driver specific ascii string */ +#define IWEVREGISTERED 0x8C03 /* Discovered a new node (AP mode) */ +#define IWEVEXPIRED 0x8C04 /* Expired a node (AP mode) */ +#define IWEVGENIE 0x8C05 /* Generic IE (WPA, RSN, WMM, ..) + * (scan results); This includes id and + * length fields. One IWEVGENIE may + * contain more than one IE. Scan + * results may contain one or more + * IWEVGENIE events. */ +#define IWEVMICHAELMICFAILURE 0x8C06 /* Michael MIC failure + * (struct iw_michaelmicfailure) + */ +#define IWEVASSOCREQIE 0x8C07 /* IEs used in (Re)Association Request. + * The data includes id and length + * fields and may contain more than one + * IE. This event is required in + * Managed mode if the driver + * generates its own WPA/RSN IE. This + * should be sent just before + * IWEVREGISTERED event for the + * association. */ +#define IWEVASSOCRESPIE 0x8C08 /* IEs used in (Re)Association + * Response. The data includes id and + * length fields and may contain more + * than one IE. This may be sent + * between IWEVASSOCREQIE and + * IWEVREGISTERED events for the + * association. */ +#define IWEVPMKIDCAND 0x8C09 /* PMKID candidate for RSN + * pre-authentication + * (struct iw_pmkid_cand) */ + +#define IWEVFIRST 0x8C00 +#define IW_EVENT_IDX(cmd) ((cmd) - IWEVFIRST) + +/* ------------------------- PRIVATE INFO ------------------------- */ +/* + * The following is used with SIOCGIWPRIV. It allow a driver to define + * the interface (name, type of data) for its private ioctl. + * Privates ioctl are SIOCIWFIRSTPRIV -> SIOCIWLASTPRIV + */ + +#define IW_PRIV_TYPE_MASK 0x7000 /* Type of arguments */ +#define IW_PRIV_TYPE_NONE 0x0000 +#define IW_PRIV_TYPE_BYTE 0x1000 /* Char as number */ +#define IW_PRIV_TYPE_CHAR 0x2000 /* Char as character */ +#define IW_PRIV_TYPE_INT 0x4000 /* 32 bits int */ +#define IW_PRIV_TYPE_FLOAT 0x5000 /* struct iw_freq */ +#define IW_PRIV_TYPE_ADDR 0x6000 /* struct sockaddr */ + +#define IW_PRIV_SIZE_FIXED 0x0800 /* Variable or fixed number of args */ + +#define IW_PRIV_SIZE_MASK 0x07FF /* Max number of those args */ + +/* + * Note : if the number of args is fixed and the size < 16 octets, + * instead of passing a pointer we will put args in the iwreq struct... + */ + +/* ----------------------- OTHER CONSTANTS ----------------------- */ + +/* Maximum frequencies in the range struct */ +#define IW_MAX_FREQUENCIES 32 +/* Note : if you have something like 80 frequencies, + * don't increase this constant and don't fill the frequency list. + * The user will be able to set by channel anyway... */ + +/* Maximum bit rates in the range struct */ +#define IW_MAX_BITRATES 32 + +/* Maximum tx powers in the range struct */ +#define IW_MAX_TXPOWER 8 +/* Note : if you more than 8 TXPowers, just set the max and min or + * a few of them in the struct iw_range. */ + +/* Maximum of address that you may set with SPY */ +#define IW_MAX_SPY 8 + +/* Maximum of address that you may get in the + list of access points in range */ +#define IW_MAX_AP 64 + +/* Maximum size of the ESSID and NICKN strings */ +#define IW_ESSID_MAX_SIZE 32 + +/* Modes of operation */ +#define IW_MODE_AUTO 0 /* Let the driver decides */ +#define IW_MODE_ADHOC 1 /* Single cell network */ +#define IW_MODE_INFRA 2 /* Multi cell network, roaming, ... */ +#define IW_MODE_MASTER 3 /* Synchronisation master or Access Point */ +#define IW_MODE_REPEAT 4 /* Wireless Repeater (forwarder) */ +#define IW_MODE_SECOND 5 /* Secondary master/repeater (backup) */ +#define IW_MODE_MONITOR 6 /* Passive monitor (listen only) */ +#define IW_MODE_MESH 7 /* Mesh (IEEE 802.11s) network */ + +/* Statistics flags (bitmask in updated) */ +#define IW_QUAL_QUAL_UPDATED 0x01 /* Value was updated since last read */ +#define IW_QUAL_LEVEL_UPDATED 0x02 +#define IW_QUAL_NOISE_UPDATED 0x04 +#define IW_QUAL_ALL_UPDATED 0x07 +#define IW_QUAL_DBM 0x08 /* Level + Noise are dBm */ +#define IW_QUAL_QUAL_INVALID 0x10 /* Driver doesn't provide value */ +#define IW_QUAL_LEVEL_INVALID 0x20 +#define IW_QUAL_NOISE_INVALID 0x40 +#define IW_QUAL_RCPI 0x80 /* Level + Noise are 802.11k RCPI */ +#define IW_QUAL_ALL_INVALID 0x70 + +/* Frequency flags */ +#define IW_FREQ_AUTO 0x00 /* Let the driver decides */ +#define IW_FREQ_FIXED 0x01 /* Force a specific value */ + +/* Maximum number of size of encoding token available + * they are listed in the range structure */ +#define IW_MAX_ENCODING_SIZES 8 + +/* Maximum size of the encoding token in bytes */ +#define IW_ENCODING_TOKEN_MAX 64 /* 512 bits (for now) */ + +/* Flags for encoding (along with the token) */ +#define IW_ENCODE_INDEX 0x00FF /* Token index (if needed) */ +#define IW_ENCODE_FLAGS 0xFF00 /* Flags defined below */ +#define IW_ENCODE_MODE 0xF000 /* Modes defined below */ +#define IW_ENCODE_DISABLED 0x8000 /* Encoding disabled */ +#define IW_ENCODE_ENABLED 0x0000 /* Encoding enabled */ +#define IW_ENCODE_RESTRICTED 0x4000 /* Refuse non-encoded packets */ +#define IW_ENCODE_OPEN 0x2000 /* Accept non-encoded packets */ +#define IW_ENCODE_NOKEY 0x0800 /* Key is write only, so not present */ +#define IW_ENCODE_TEMP 0x0400 /* Temporary key */ + +/* Power management flags available (along with the value, if any) */ +#define IW_POWER_ON 0x0000 /* No details... */ +#define IW_POWER_TYPE 0xF000 /* Type of parameter */ +#define IW_POWER_PERIOD 0x1000 /* Value is a period/duration of */ +#define IW_POWER_TIMEOUT 0x2000 /* Value is a timeout (to go asleep) */ +#define IW_POWER_MODE 0x0F00 /* Power Management mode */ +#define IW_POWER_UNICAST_R 0x0100 /* Receive only unicast messages */ +#define IW_POWER_MULTICAST_R 0x0200 /* Receive only multicast messages */ +#define IW_POWER_ALL_R 0x0300 /* Receive all messages though PM */ +#define IW_POWER_FORCE_S 0x0400 /* Force PM procedure for sending unicast */ +#define IW_POWER_REPEATER 0x0800 /* Repeat broadcast messages in PM period */ +#define IW_POWER_MODIFIER 0x000F /* Modify a parameter */ +#define IW_POWER_MIN 0x0001 /* Value is a minimum */ +#define IW_POWER_MAX 0x0002 /* Value is a maximum */ +#define IW_POWER_RELATIVE 0x0004 /* Value is not in seconds/ms/us */ + +/* Transmit Power flags available */ +#define IW_TXPOW_TYPE 0x00FF /* Type of value */ +#define IW_TXPOW_DBM 0x0000 /* Value is in dBm */ +#define IW_TXPOW_MWATT 0x0001 /* Value is in mW */ +#define IW_TXPOW_RELATIVE 0x0002 /* Value is in arbitrary units */ +#define IW_TXPOW_RANGE 0x1000 /* Range of value between min/max */ + +/* Retry limits and lifetime flags available */ +#define IW_RETRY_ON 0x0000 /* No details... */ +#define IW_RETRY_TYPE 0xF000 /* Type of parameter */ +#define IW_RETRY_LIMIT 0x1000 /* Maximum number of retries*/ +#define IW_RETRY_LIFETIME 0x2000 /* Maximum duration of retries in us */ +#define IW_RETRY_MODIFIER 0x00FF /* Modify a parameter */ +#define IW_RETRY_MIN 0x0001 /* Value is a minimum */ +#define IW_RETRY_MAX 0x0002 /* Value is a maximum */ +#define IW_RETRY_RELATIVE 0x0004 /* Value is not in seconds/ms/us */ +#define IW_RETRY_SHORT 0x0010 /* Value is for short packets */ +#define IW_RETRY_LONG 0x0020 /* Value is for long packets */ + +/* Scanning request flags */ +#define IW_SCAN_DEFAULT 0x0000 /* Default scan of the driver */ +#define IW_SCAN_ALL_ESSID 0x0001 /* Scan all ESSIDs */ +#define IW_SCAN_THIS_ESSID 0x0002 /* Scan only this ESSID */ +#define IW_SCAN_ALL_FREQ 0x0004 /* Scan all Frequencies */ +#define IW_SCAN_THIS_FREQ 0x0008 /* Scan only this Frequency */ +#define IW_SCAN_ALL_MODE 0x0010 /* Scan all Modes */ +#define IW_SCAN_THIS_MODE 0x0020 /* Scan only this Mode */ +#define IW_SCAN_ALL_RATE 0x0040 /* Scan all Bit-Rates */ +#define IW_SCAN_THIS_RATE 0x0080 /* Scan only this Bit-Rate */ +/* struct iw_scan_req scan_type */ +#define IW_SCAN_TYPE_ACTIVE 0 +#define IW_SCAN_TYPE_PASSIVE 1 +/* Maximum size of returned data */ +#define IW_SCAN_MAX_DATA 4096 /* In bytes */ + +/* Scan capability flags - in (struct iw_range *)->scan_capa */ +#define IW_SCAN_CAPA_NONE 0x00 +#define IW_SCAN_CAPA_ESSID 0x01 +#define IW_SCAN_CAPA_BSSID 0x02 +#define IW_SCAN_CAPA_CHANNEL 0x04 +#define IW_SCAN_CAPA_MODE 0x08 +#define IW_SCAN_CAPA_RATE 0x10 +#define IW_SCAN_CAPA_TYPE 0x20 +#define IW_SCAN_CAPA_TIME 0x40 + +/* Max number of char in custom event - use multiple of them if needed */ +#define IW_CUSTOM_MAX 256 /* In bytes */ + +/* Generic information element */ +#define IW_GENERIC_IE_MAX 1024 + +/* MLME requests (SIOCSIWMLME / struct iw_mlme) */ +#define IW_MLME_DEAUTH 0 +#define IW_MLME_DISASSOC 1 +#define IW_MLME_AUTH 2 +#define IW_MLME_ASSOC 3 + +/* SIOCSIWAUTH/SIOCGIWAUTH struct iw_param flags */ +#define IW_AUTH_INDEX 0x0FFF +#define IW_AUTH_FLAGS 0xF000 +/* SIOCSIWAUTH/SIOCGIWAUTH parameters (0 .. 4095) + * (IW_AUTH_INDEX mask in struct iw_param flags; this is the index of the + * parameter that is being set/get to; value will be read/written to + * struct iw_param value field) */ +#define IW_AUTH_WPA_VERSION 0 +#define IW_AUTH_CIPHER_PAIRWISE 1 +#define IW_AUTH_CIPHER_GROUP 2 +#define IW_AUTH_KEY_MGMT 3 +#define IW_AUTH_TKIP_COUNTERMEASURES 4 +#define IW_AUTH_DROP_UNENCRYPTED 5 +#define IW_AUTH_80211_AUTH_ALG 6 +#define IW_AUTH_WPA_ENABLED 7 +#define IW_AUTH_RX_UNENCRYPTED_EAPOL 8 +#define IW_AUTH_ROAMING_CONTROL 9 +#define IW_AUTH_PRIVACY_INVOKED 10 +#define IW_AUTH_CIPHER_GROUP_MGMT 11 +#define IW_AUTH_MFP 12 + +/* IW_AUTH_WPA_VERSION values (bit field) */ +#define IW_AUTH_WPA_VERSION_DISABLED 0x00000001 +#define IW_AUTH_WPA_VERSION_WPA 0x00000002 +#define IW_AUTH_WPA_VERSION_WPA2 0x00000004 + +/* IW_AUTH_PAIRWISE_CIPHER, IW_AUTH_GROUP_CIPHER, and IW_AUTH_CIPHER_GROUP_MGMT + * values (bit field) */ +#define IW_AUTH_CIPHER_NONE 0x00000001 +#define IW_AUTH_CIPHER_WEP40 0x00000002 +#define IW_AUTH_CIPHER_TKIP 0x00000004 +#define IW_AUTH_CIPHER_CCMP 0x00000008 +#define IW_AUTH_CIPHER_WEP104 0x00000010 +#define IW_AUTH_CIPHER_AES_CMAC 0x00000020 + +/* IW_AUTH_KEY_MGMT values (bit field) */ +#define IW_AUTH_KEY_MGMT_802_1X 1 +#define IW_AUTH_KEY_MGMT_PSK 2 + +/* IW_AUTH_80211_AUTH_ALG values (bit field) */ +#define IW_AUTH_ALG_OPEN_SYSTEM 0x00000001 +#define IW_AUTH_ALG_SHARED_KEY 0x00000002 +#define IW_AUTH_ALG_LEAP 0x00000004 + +/* IW_AUTH_ROAMING_CONTROL values */ +#define IW_AUTH_ROAMING_ENABLE 0 /* driver/firmware based roaming */ +#define IW_AUTH_ROAMING_DISABLE 1 /* user space program used for roaming + * control */ + +/* IW_AUTH_MFP (management frame protection) values */ +#define IW_AUTH_MFP_DISABLED 0 /* MFP disabled */ +#define IW_AUTH_MFP_OPTIONAL 1 /* MFP optional */ +#define IW_AUTH_MFP_REQUIRED 2 /* MFP required */ + +/* SIOCSIWENCODEEXT definitions */ +#define IW_ENCODE_SEQ_MAX_SIZE 8 +/* struct iw_encode_ext ->alg */ +#define IW_ENCODE_ALG_NONE 0 +#define IW_ENCODE_ALG_WEP 1 +#define IW_ENCODE_ALG_TKIP 2 +#define IW_ENCODE_ALG_CCMP 3 +#define IW_ENCODE_ALG_PMK 4 +#define IW_ENCODE_ALG_AES_CMAC 5 +/* struct iw_encode_ext ->ext_flags */ +#define IW_ENCODE_EXT_TX_SEQ_VALID 0x00000001 +#define IW_ENCODE_EXT_RX_SEQ_VALID 0x00000002 +#define IW_ENCODE_EXT_GROUP_KEY 0x00000004 +#define IW_ENCODE_EXT_SET_TX_KEY 0x00000008 + +/* IWEVMICHAELMICFAILURE : struct iw_michaelmicfailure ->flags */ +#define IW_MICFAILURE_KEY_ID 0x00000003 /* Key ID 0..3 */ +#define IW_MICFAILURE_GROUP 0x00000004 +#define IW_MICFAILURE_PAIRWISE 0x00000008 +#define IW_MICFAILURE_STAKEY 0x00000010 +#define IW_MICFAILURE_COUNT 0x00000060 /* 1 or 2 (0 = count not supported) + */ + +/* Bit field values for enc_capa in struct iw_range */ +#define IW_ENC_CAPA_WPA 0x00000001 +#define IW_ENC_CAPA_WPA2 0x00000002 +#define IW_ENC_CAPA_CIPHER_TKIP 0x00000004 +#define IW_ENC_CAPA_CIPHER_CCMP 0x00000008 +#define IW_ENC_CAPA_4WAY_HANDSHAKE 0x00000010 + +/* Event capability macros - in (struct iw_range *)->event_capa + * Because we have more than 32 possible events, we use an array of + * 32 bit bitmasks. Note : 32 bits = 0x20 = 2^5. */ +#define IW_EVENT_CAPA_BASE(cmd) ((cmd >= SIOCIWFIRSTPRIV) ? \ + (cmd - SIOCIWFIRSTPRIV + 0x60) : \ + (cmd - SIOCIWFIRST)) +#define IW_EVENT_CAPA_INDEX(cmd) (IW_EVENT_CAPA_BASE(cmd) >> 5) +#define IW_EVENT_CAPA_MASK(cmd) (1 << (IW_EVENT_CAPA_BASE(cmd) & 0x1F)) +/* Event capability constants - event autogenerated by the kernel + * This list is valid for most 802.11 devices, customise as needed... */ +#define IW_EVENT_CAPA_K_0 (IW_EVENT_CAPA_MASK(0x8B04) | \ + IW_EVENT_CAPA_MASK(0x8B06) | \ + IW_EVENT_CAPA_MASK(0x8B1A)) +#define IW_EVENT_CAPA_K_1 (IW_EVENT_CAPA_MASK(0x8B2A)) +/* "Easy" macro to set events in iw_range (less efficient) */ +#define IW_EVENT_CAPA_SET(event_capa, cmd) (event_capa[IW_EVENT_CAPA_INDEX(cmd)] |= IW_EVENT_CAPA_MASK(cmd)) +#define IW_EVENT_CAPA_SET_KERNEL(event_capa) {event_capa[0] |= IW_EVENT_CAPA_K_0; event_capa[1] |= IW_EVENT_CAPA_K_1; } + + +/****************************** TYPES ******************************/ + +/* --------------------------- SUBTYPES --------------------------- */ +/* + * Generic format for most parameters that fit in an int + */ +struct iw_param +{ + __s32 value; /* The value of the parameter itself */ + __u8 fixed; /* Hardware should not use auto select */ + __u8 disabled; /* Disable the feature */ + __u16 flags; /* Various specifc flags (if any) */ +}; + +/* + * For all data larger than 16 octets, we need to use a + * pointer to memory allocated in user space. + */ +struct iw_point +{ + void __user *pointer; /* Pointer to the data (in user space) */ + __u16 length; /* number of fields or size in bytes */ + __u16 flags; /* Optional params */ +}; + +#ifdef __KERNEL__ +#ifdef CONFIG_COMPAT + +#include <linux/compat.h> + +struct compat_iw_point { + compat_caddr_t pointer; + __u16 length; + __u16 flags; +}; +#endif +#endif + +/* + * A frequency + * For numbers lower than 10^9, we encode the number in 'm' and + * set 'e' to 0 + * For number greater than 10^9, we divide it by the lowest power + * of 10 to get 'm' lower than 10^9, with 'm'= f / (10^'e')... + * The power of 10 is in 'e', the result of the division is in 'm'. + */ +struct iw_freq +{ + __s32 m; /* Mantissa */ + __s16 e; /* Exponent */ + __u8 i; /* List index (when in range struct) */ + __u8 flags; /* Flags (fixed/auto) */ +}; + +/* + * Quality of the link + */ +struct iw_quality +{ + __u8 qual; /* link quality (%retries, SNR, + %missed beacons or better...) */ + __u8 level; /* signal level (dBm) */ + __u8 noise; /* noise level (dBm) */ + __u8 updated; /* Flags to know if updated */ +}; + +/* + * Packet discarded in the wireless adapter due to + * "wireless" specific problems... + * Note : the list of counter and statistics in net_device_stats + * is already pretty exhaustive, and you should use that first. + * This is only additional stats... + */ +struct iw_discarded +{ + __u32 nwid; /* Rx : Wrong nwid/essid */ + __u32 code; /* Rx : Unable to code/decode (WEP) */ + __u32 fragment; /* Rx : Can't perform MAC reassembly */ + __u32 retries; /* Tx : Max MAC retries num reached */ + __u32 misc; /* Others cases */ +}; + +/* + * Packet/Time period missed in the wireless adapter due to + * "wireless" specific problems... + */ +struct iw_missed +{ + __u32 beacon; /* Missed beacons/superframe */ +}; + +/* + * Quality range (for spy threshold) + */ +struct iw_thrspy +{ + struct sockaddr addr; /* Source address (hw/mac) */ + struct iw_quality qual; /* Quality of the link */ + struct iw_quality low; /* Low threshold */ + struct iw_quality high; /* High threshold */ +}; + +/* + * Optional data for scan request + * + * Note: these optional parameters are controlling parameters for the + * scanning behavior, these do not apply to getting scan results + * (SIOCGIWSCAN). Drivers are expected to keep a local BSS table and + * provide a merged results with all BSSes even if the previous scan + * request limited scanning to a subset, e.g., by specifying an SSID. + * Especially, scan results are required to include an entry for the + * current BSS if the driver is in Managed mode and associated with an AP. + */ +struct iw_scan_req +{ + __u8 scan_type; /* IW_SCAN_TYPE_{ACTIVE,PASSIVE} */ + __u8 essid_len; + __u8 num_channels; /* num entries in channel_list; + * 0 = scan all allowed channels */ + __u8 flags; /* reserved as padding; use zero, this may + * be used in the future for adding flags + * to request different scan behavior */ + struct sockaddr bssid; /* ff:ff:ff:ff:ff:ff for broadcast BSSID or + * individual address of a specific BSS */ + + /* + * Use this ESSID if IW_SCAN_THIS_ESSID flag is used instead of using + * the current ESSID. This allows scan requests for specific ESSID + * without having to change the current ESSID and potentially breaking + * the current association. + */ + __u8 essid[IW_ESSID_MAX_SIZE]; + + /* + * Optional parameters for changing the default scanning behavior. + * These are based on the MLME-SCAN.request from IEEE Std 802.11. + * TU is 1.024 ms. If these are set to 0, driver is expected to use + * reasonable default values. min_channel_time defines the time that + * will be used to wait for the first reply on each channel. If no + * replies are received, next channel will be scanned after this. If + * replies are received, total time waited on the channel is defined by + * max_channel_time. + */ + __u32 min_channel_time; /* in TU */ + __u32 max_channel_time; /* in TU */ + + struct iw_freq channel_list[IW_MAX_FREQUENCIES]; +}; + +/* ------------------------- WPA SUPPORT ------------------------- */ + +/* + * Extended data structure for get/set encoding (this is used with + * SIOCSIWENCODEEXT/SIOCGIWENCODEEXT. struct iw_point and IW_ENCODE_* + * flags are used in the same way as with SIOCSIWENCODE/SIOCGIWENCODE and + * only the data contents changes (key data -> this structure, including + * key data). + * + * If the new key is the first group key, it will be set as the default + * TX key. Otherwise, default TX key index is only changed if + * IW_ENCODE_EXT_SET_TX_KEY flag is set. + * + * Key will be changed with SIOCSIWENCODEEXT in all cases except for + * special "change TX key index" operation which is indicated by setting + * key_len = 0 and ext_flags |= IW_ENCODE_EXT_SET_TX_KEY. + * + * tx_seq/rx_seq are only used when respective + * IW_ENCODE_EXT_{TX,RX}_SEQ_VALID flag is set in ext_flags. Normal + * TKIP/CCMP operation is to set RX seq with SIOCSIWENCODEEXT and start + * TX seq from zero whenever key is changed. SIOCGIWENCODEEXT is normally + * used only by an Authenticator (AP or an IBSS station) to get the + * current TX sequence number. Using TX_SEQ_VALID for SIOCSIWENCODEEXT and + * RX_SEQ_VALID for SIOCGIWENCODEEXT are optional, but can be useful for + * debugging/testing. + */ +struct iw_encode_ext +{ + __u32 ext_flags; /* IW_ENCODE_EXT_* */ + __u8 tx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */ + __u8 rx_seq[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */ + struct sockaddr addr; /* ff:ff:ff:ff:ff:ff for broadcast/multicast + * (group) keys or unicast address for + * individual keys */ + __u16 alg; /* IW_ENCODE_ALG_* */ + __u16 key_len; + __u8 key[0]; +}; + +/* SIOCSIWMLME data */ +struct iw_mlme +{ + __u16 cmd; /* IW_MLME_* */ + __u16 reason_code; + struct sockaddr addr; +}; + +/* SIOCSIWPMKSA data */ +#define IW_PMKSA_ADD 1 +#define IW_PMKSA_REMOVE 2 +#define IW_PMKSA_FLUSH 3 + +#define IW_PMKID_LEN 16 + +struct iw_pmksa +{ + __u32 cmd; /* IW_PMKSA_* */ + struct sockaddr bssid; + __u8 pmkid[IW_PMKID_LEN]; +}; + +/* IWEVMICHAELMICFAILURE data */ +struct iw_michaelmicfailure +{ + __u32 flags; + struct sockaddr src_addr; + __u8 tsc[IW_ENCODE_SEQ_MAX_SIZE]; /* LSB first */ +}; + +/* IWEVPMKIDCAND data */ +#define IW_PMKID_CAND_PREAUTH 0x00000001 /* RNS pre-authentication enabled */ +struct iw_pmkid_cand +{ + __u32 flags; /* IW_PMKID_CAND_* */ + __u32 index; /* the smaller the index, the higher the + * priority */ + struct sockaddr bssid; +}; + +/* ------------------------ WIRELESS STATS ------------------------ */ +/* + * Wireless statistics (used for /proc/net/wireless) + */ +struct iw_statistics +{ + __u16 status; /* Status + * - device dependent for now */ + + struct iw_quality qual; /* Quality of the link + * (instant/mean/max) */ + struct iw_discarded discard; /* Packet discarded counts */ + struct iw_missed miss; /* Packet missed counts */ +}; + +/* ------------------------ IOCTL REQUEST ------------------------ */ +/* + * This structure defines the payload of an ioctl, and is used + * below. + * + * Note that this structure should fit on the memory footprint + * of iwreq (which is the same as ifreq), which mean a max size of + * 16 octets = 128 bits. Warning, pointers might be 64 bits wide... + * You should check this when increasing the structures defined + * above in this file... + */ +union iwreq_data +{ + /* Config - generic */ + char name[IFNAMSIZ]; + /* Name : used to verify the presence of wireless extensions. + * Name of the protocol/provider... */ + + struct iw_point essid; /* Extended network name */ + struct iw_param nwid; /* network id (or domain - the cell) */ + struct iw_freq freq; /* frequency or channel : + * 0-1000 = channel + * > 1000 = frequency in Hz */ + + struct iw_param sens; /* signal level threshold */ + struct iw_param bitrate; /* default bit rate */ + struct iw_param txpower; /* default transmit power */ + struct iw_param rts; /* RTS threshold threshold */ + struct iw_param frag; /* Fragmentation threshold */ + __u32 mode; /* Operation mode */ + struct iw_param retry; /* Retry limits & lifetime */ + + struct iw_point encoding; /* Encoding stuff : tokens */ + struct iw_param power; /* PM duration/timeout */ + struct iw_quality qual; /* Quality part of statistics */ + + struct sockaddr ap_addr; /* Access point address */ + struct sockaddr addr; /* Destination address (hw/mac) */ + + struct iw_param param; /* Other small parameters */ + struct iw_point data; /* Other large parameters */ +}; + +/* + * The structure to exchange data for ioctl. + * This structure is the same as 'struct ifreq', but (re)defined for + * convenience... + * Do I need to remind you about structure size (32 octets) ? + */ +struct iwreq +{ + union + { + char ifrn_name[IFNAMSIZ]; /* if name, e.g. "eth0" */ + } ifr_ifrn; + + /* Data part (defined just above) */ + union iwreq_data u; +}; + +/* -------------------------- IOCTL DATA -------------------------- */ +/* + * For those ioctl which want to exchange mode data that what could + * fit in the above structure... + */ + +/* + * Range of parameters + */ + +struct iw_range +{ + /* Informative stuff (to choose between different interface) */ + __u32 throughput; /* To give an idea... */ + /* In theory this value should be the maximum benchmarked + * TCP/IP throughput, because with most of these devices the + * bit rate is meaningless (overhead an co) to estimate how + * fast the connection will go and pick the fastest one. + * I suggest people to play with Netperf or any benchmark... + */ + + /* NWID (or domain id) */ + __u32 min_nwid; /* Minimal NWID we are able to set */ + __u32 max_nwid; /* Maximal NWID we are able to set */ + + /* Old Frequency (backward compat - moved lower ) */ + __u16 old_num_channels; + __u8 old_num_frequency; + + /* Scan capabilities */ + __u8 scan_capa; /* IW_SCAN_CAPA_* bit field */ + + /* Wireless event capability bitmasks */ + __u32 event_capa[6]; + + /* signal level threshold range */ + __s32 sensitivity; + + /* Quality of link & SNR stuff */ + /* Quality range (link, level, noise) + * If the quality is absolute, it will be in the range [0 ; max_qual], + * if the quality is dBm, it will be in the range [max_qual ; 0]. + * Don't forget that we use 8 bit arithmetics... */ + struct iw_quality max_qual; /* Quality of the link */ + /* This should contain the average/typical values of the quality + * indicator. This should be the threshold between a "good" and + * a "bad" link (example : monitor going from green to orange). + * Currently, user space apps like quality monitors don't have any + * way to calibrate the measurement. With this, they can split + * the range between 0 and max_qual in different quality level + * (using a geometric subdivision centered on the average). + * I expect that people doing the user space apps will feedback + * us on which value we need to put in each driver... */ + struct iw_quality avg_qual; /* Quality of the link */ + + /* Rates */ + __u8 num_bitrates; /* Number of entries in the list */ + __s32 bitrate[IW_MAX_BITRATES]; /* list, in bps */ + + /* RTS threshold */ + __s32 min_rts; /* Minimal RTS threshold */ + __s32 max_rts; /* Maximal RTS threshold */ + + /* Frag threshold */ + __s32 min_frag; /* Minimal frag threshold */ + __s32 max_frag; /* Maximal frag threshold */ + + /* Power Management duration & timeout */ + __s32 min_pmp; /* Minimal PM period */ + __s32 max_pmp; /* Maximal PM period */ + __s32 min_pmt; /* Minimal PM timeout */ + __s32 max_pmt; /* Maximal PM timeout */ + __u16 pmp_flags; /* How to decode max/min PM period */ + __u16 pmt_flags; /* How to decode max/min PM timeout */ + __u16 pm_capa; /* What PM options are supported */ + + /* Encoder stuff */ + __u16 encoding_size[IW_MAX_ENCODING_SIZES]; /* Different token sizes */ + __u8 num_encoding_sizes; /* Number of entry in the list */ + __u8 max_encoding_tokens; /* Max number of tokens */ + /* For drivers that need a "login/passwd" form */ + __u8 encoding_login_index; /* token index for login token */ + + /* Transmit power */ + __u16 txpower_capa; /* What options are supported */ + __u8 num_txpower; /* Number of entries in the list */ + __s32 txpower[IW_MAX_TXPOWER]; /* list, in bps */ + + /* Wireless Extension version info */ + __u8 we_version_compiled; /* Must be WIRELESS_EXT */ + __u8 we_version_source; /* Last update of source */ + + /* Retry limits and lifetime */ + __u16 retry_capa; /* What retry options are supported */ + __u16 retry_flags; /* How to decode max/min retry limit */ + __u16 r_time_flags; /* How to decode max/min retry life */ + __s32 min_retry; /* Minimal number of retries */ + __s32 max_retry; /* Maximal number of retries */ + __s32 min_r_time; /* Minimal retry lifetime */ + __s32 max_r_time; /* Maximal retry lifetime */ + + /* Frequency */ + __u16 num_channels; /* Number of channels [0; num - 1] */ + __u8 num_frequency; /* Number of entry in the list */ + struct iw_freq freq[IW_MAX_FREQUENCIES]; /* list */ + /* Note : this frequency list doesn't need to fit channel numbers, + * because each entry contain its channel index */ + + __u32 enc_capa; /* IW_ENC_CAPA_* bit field */ +}; + +/* + * Private ioctl interface information + */ + +struct iw_priv_args +{ + __u32 cmd; /* Number of the ioctl to issue */ + __u16 set_args; /* Type and number of args */ + __u16 get_args; /* Type and number of args */ + char name[IFNAMSIZ]; /* Name of the extension */ +}; + +/* ----------------------- WIRELESS EVENTS ----------------------- */ +/* + * Wireless events are carried through the rtnetlink socket to user + * space. They are encapsulated in the IFLA_WIRELESS field of + * a RTM_NEWLINK message. + */ + +/* + * A Wireless Event. Contains basically the same data as the ioctl... + */ +struct iw_event +{ + __u16 len; /* Real length of this stuff */ + __u16 cmd; /* Wireless IOCTL */ + union iwreq_data u; /* IOCTL fixed payload */ +}; + +/* Size of the Event prefix (including padding and alignement junk) */ +#define IW_EV_LCP_LEN (sizeof(struct iw_event) - sizeof(union iwreq_data)) +/* Size of the various events */ +#define IW_EV_CHAR_LEN (IW_EV_LCP_LEN + IFNAMSIZ) +#define IW_EV_UINT_LEN (IW_EV_LCP_LEN + sizeof(__u32)) +#define IW_EV_FREQ_LEN (IW_EV_LCP_LEN + sizeof(struct iw_freq)) +#define IW_EV_PARAM_LEN (IW_EV_LCP_LEN + sizeof(struct iw_param)) +#define IW_EV_ADDR_LEN (IW_EV_LCP_LEN + sizeof(struct sockaddr)) +#define IW_EV_QUAL_LEN (IW_EV_LCP_LEN + sizeof(struct iw_quality)) + +/* iw_point events are special. First, the payload (extra data) come at + * the end of the event, so they are bigger than IW_EV_POINT_LEN. Second, + * we omit the pointer, so start at an offset. */ +#define IW_EV_POINT_OFF (((char *) &(((struct iw_point *) NULL)->length)) - \ + (char *) NULL) +#define IW_EV_POINT_LEN (IW_EV_LCP_LEN + sizeof(struct iw_point) - \ + IW_EV_POINT_OFF) + +#ifdef __KERNEL__ +#ifdef CONFIG_COMPAT +struct __compat_iw_event { + __u16 len; /* Real length of this stuff */ + __u16 cmd; /* Wireless IOCTL */ + compat_caddr_t pointer; +}; +#define IW_EV_COMPAT_LCP_LEN offsetof(struct __compat_iw_event, pointer) +#define IW_EV_COMPAT_POINT_OFF offsetof(struct compat_iw_point, length) + +/* Size of the various events for compat */ +#define IW_EV_COMPAT_CHAR_LEN (IW_EV_COMPAT_LCP_LEN + IFNAMSIZ) +#define IW_EV_COMPAT_UINT_LEN (IW_EV_COMPAT_LCP_LEN + sizeof(__u32)) +#define IW_EV_COMPAT_FREQ_LEN (IW_EV_COMPAT_LCP_LEN + sizeof(struct iw_freq)) +#define IW_EV_COMPAT_PARAM_LEN (IW_EV_COMPAT_LCP_LEN + sizeof(struct iw_param)) +#define IW_EV_COMPAT_ADDR_LEN (IW_EV_COMPAT_LCP_LEN + sizeof(struct sockaddr)) +#define IW_EV_COMPAT_QUAL_LEN (IW_EV_COMPAT_LCP_LEN + sizeof(struct iw_quality)) +#define IW_EV_COMPAT_POINT_LEN \ + (IW_EV_COMPAT_LCP_LEN + sizeof(struct compat_iw_point) - \ + IW_EV_COMPAT_POINT_OFF) +#endif +#endif + +/* Size of the Event prefix when packed in stream */ +#define IW_EV_LCP_PK_LEN (4) +/* Size of the various events when packed in stream */ +#define IW_EV_CHAR_PK_LEN (IW_EV_LCP_PK_LEN + IFNAMSIZ) +#define IW_EV_UINT_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(__u32)) +#define IW_EV_FREQ_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(struct iw_freq)) +#define IW_EV_PARAM_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(struct iw_param)) +#define IW_EV_ADDR_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(struct sockaddr)) +#define IW_EV_QUAL_PK_LEN (IW_EV_LCP_PK_LEN + sizeof(struct iw_quality)) +#define IW_EV_POINT_PK_LEN (IW_EV_LCP_PK_LEN + 4) + +#endif /* _LINUX_WIRELESS_H */ diff --git a/backport-include/linux/workqueue.h b/backport-include/linux/workqueue.h new file mode 100644 index 0000000..9958715 --- /dev/null +++ b/backport-include/linux/workqueue.h @@ -0,0 +1,99 @@ +#ifndef __BACKPORT_LINUX_WORKQUEUE_H +#define __BACKPORT_LINUX_WORKQUEUE_H +#include_next <linux/workqueue.h> +#include <linux/version.h> + +#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0)) +#define mod_delayed_work LINUX_BACKPORT(mod_delayed_work) +bool mod_delayed_work(struct workqueue_struct *wq, struct delayed_work *dwork, + unsigned long delay); +#endif + +#ifndef create_freezable_workqueue +/* note freez_a_ble -> freez_ea_able */ +#define create_freezable_workqueue create_freezeable_workqueue +#endif + +#ifndef alloc_ordered_workqueue +#define alloc_ordered_workqueue(name, flags) create_singlethread_workqueue(name) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) +#define alloc_workqueue(name, flags, max_active) __create_workqueue(name, flags, max_active) +#endif + +#ifndef alloc_workqueue +#define alloc_workqueue(name, flags, max_active) __create_workqueue(name, flags, max_active, 0) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) +#define system_wq LINUX_BACKPORT(system_wq) +extern struct workqueue_struct *system_wq; +#define system_long_wq LINUX_BACKPORT(system_long_wq) +extern struct workqueue_struct *system_long_wq; +#define system_nrt_wq LINUX_BACKPORT(system_nrt_wq) +extern struct workqueue_struct *system_nrt_wq; + +void backport_system_workqueue_create(void); +void backport_system_workqueue_destroy(void); + +#define schedule_work LINUX_BACKPORT(schedule_work) +int schedule_work(struct work_struct *work); +#define schedule_work_on LINUX_BACKPORT(schedule_work_on) +int schedule_work_on(int cpu, struct work_struct *work); +#define schedule_delayed_work LINUX_BACKPORT(schedule_delayed_work) +int schedule_delayed_work(struct delayed_work *dwork, + unsigned long delay); +#define schedule_delayed_work_on LINUX_BACKPORT(schedule_delayed_work_on) +int schedule_delayed_work_on(int cpu, + struct delayed_work *dwork, + unsigned long delay); +#define flush_scheduled_work LINUX_BACKPORT(flush_scheduled_work) +void flush_scheduled_work(void); + +enum { + /* bit mask for work_busy() return values */ + WORK_BUSY_PENDING = 1 << 0, + WORK_BUSY_RUNNING = 1 << 1, +}; + +#define work_busy LINUX_BACKPORT(work_busy) +extern unsigned int work_busy(struct work_struct *work); + +#else + +static inline void backport_system_workqueue_create(void) +{ +} + +static inline void backport_system_workqueue_destroy(void) +{ +} +#endif /* < 2.6.36 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) +/* I can't find a more suitable replacement... */ +#define flush_work(work) cancel_work_sync(work) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) +static inline void flush_delayed_work(struct delayed_work *dwork) +{ + if (del_timer_sync(&dwork->timer)) { + /* + * This is what would happen on 2.6.32 but since we don't have + * access to the singlethread_cpu we can't really backport this, + * so avoid really *flush*ing the work... Oh well. Any better ideas? + + struct cpu_workqueue_struct *cwq; + cwq = wq_per_cpu(keventd_wq, get_cpu()); + __queue_work(cwq, &dwork->work); + put_cpu(); + + */ + } + flush_work(&dwork->work); +} +#endif + +#endif /* __BACKPORT_LINUX_WORKQUEUE_H */ diff --git a/backport-include/net/codel.h b/backport-include/net/codel.h new file mode 100644 index 0000000..eee0359 --- /dev/null +++ b/backport-include/net/codel.h @@ -0,0 +1,363 @@ +#include <linux/version.h> +#include <linux/pkt_sched.h> + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0)) || (defined(TCA_CODEL_MAX) && !defined(COMPAT_CODEL_BACKPORT)) +#include_next <net/codel.h> +#else + +#ifndef __NET_SCHED_CODEL_H +#define __NET_SCHED_CODEL_H + +/* + * Codel - The Controlled-Delay Active Queue Management algorithm + * + * Copyright (C) 2011-2012 Kathleen Nichols <nichols@pollere.com> + * Copyright (C) 2011-2012 Van Jacobson <van@pollere.net> + * Copyright (C) 2012 Michael D. Taht <dave.taht@bufferbloat.net> + * Copyright (C) 2012 Eric Dumazet <edumazet@google.com> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer, + * without modification. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The names of the authors may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * Alternatively, provided that this notice is retained in full, this + * software may be distributed under the terms of the GNU General + * Public License ("GPL") version 2, in which case the provisions of the + * GPL apply INSTEAD OF those given above. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + */ + +#include <linux/types.h> +#include <linux/ktime.h> +#include <linux/skbuff.h> +#include <net/pkt_sched.h> +#include <net/inet_ecn.h> +#include <linux/reciprocal_div.h> + +/* Controlling Queue Delay (CoDel) algorithm + * ========================================= + * Source : Kathleen Nichols and Van Jacobson + * http://queue.acm.org/detail.cfm?id=2209336 + * + * Implemented on linux by Dave Taht and Eric Dumazet + */ + + +/* CoDel uses a 1024 nsec clock, encoded in u32 + * This gives a range of 2199 seconds, because of signed compares + */ +typedef u32 codel_time_t; +typedef s32 codel_tdiff_t; +#define CODEL_SHIFT 10 +#define MS2TIME(a) ((a * NSEC_PER_MSEC) >> CODEL_SHIFT) + +static inline codel_time_t codel_get_time(void) +{ + u64 ns = ktime_to_ns(ktime_get()); + + return ns >> CODEL_SHIFT; +} + +#define codel_time_after(a, b) ((s32)(a) - (s32)(b) > 0) +#define codel_time_after_eq(a, b) ((s32)(a) - (s32)(b) >= 0) +#define codel_time_before(a, b) ((s32)(a) - (s32)(b) < 0) +#define codel_time_before_eq(a, b) ((s32)(a) - (s32)(b) <= 0) + +/* Qdiscs using codel plugin must use codel_skb_cb in their own cb[] */ +struct codel_skb_cb { + codel_time_t enqueue_time; +}; + +static struct codel_skb_cb *get_codel_cb(const struct sk_buff *skb) +{ + qdisc_cb_private_validate(skb, sizeof(struct codel_skb_cb)); +#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,37)) + return (struct codel_skb_cb *)qdisc_skb_cb((struct sk_buff *) skb)->data; +#else + return (struct codel_skb_cb *)qdisc_skb_cb(skb)->data; +#endif +} + +static codel_time_t codel_get_enqueue_time(const struct sk_buff *skb) +{ + return get_codel_cb(skb)->enqueue_time; +} + +static void codel_set_enqueue_time(struct sk_buff *skb) +{ + get_codel_cb(skb)->enqueue_time = codel_get_time(); +} + +static inline u32 codel_time_to_us(codel_time_t val) +{ + u64 valns = ((u64)val << CODEL_SHIFT); + + do_div(valns, NSEC_PER_USEC); + return (u32)valns; +} + +/** + * struct codel_params - contains codel parameters + * @target: target queue size (in time units) + * @interval: width of moving time window + * @ecn: is Explicit Congestion Notification enabled + */ +struct codel_params { + codel_time_t target; + codel_time_t interval; + bool ecn; +}; + +/** + * struct codel_vars - contains codel variables + * @count: how many drops we've done since the last time we + * entered dropping state + * @lastcount: count at entry to dropping state + * @dropping: set to true if in dropping state + * @rec_inv_sqrt: reciprocal value of sqrt(count) >> 1 + * @first_above_time: when we went (or will go) continuously above target + * for interval + * @drop_next: time to drop next packet, or when we dropped last + * @ldelay: sojourn time of last dequeued packet + */ +struct codel_vars { + u32 count; + u32 lastcount; + bool dropping; + u16 rec_inv_sqrt; + codel_time_t first_above_time; + codel_time_t drop_next; + codel_time_t ldelay; +}; + +#define REC_INV_SQRT_BITS (8 * sizeof(u16)) /* or sizeof_in_bits(rec_inv_sqrt) */ +/* needed shift to get a Q0.32 number from rec_inv_sqrt */ +#define REC_INV_SQRT_SHIFT (32 - REC_INV_SQRT_BITS) + +/** + * struct codel_stats - contains codel shared variables and stats + * @maxpacket: largest packet we've seen so far + * @drop_count: temp count of dropped packets in dequeue() + * ecn_mark: number of packets we ECN marked instead of dropping + */ +struct codel_stats { + u32 maxpacket; + u32 drop_count; + u32 ecn_mark; +}; + +static void codel_params_init(struct codel_params *params) +{ + params->interval = MS2TIME(100); + params->target = MS2TIME(5); + params->ecn = false; +} + +static void codel_vars_init(struct codel_vars *vars) +{ + memset(vars, 0, sizeof(*vars)); +} + +static void codel_stats_init(struct codel_stats *stats) +{ + stats->maxpacket = 256; +} + +/* + * http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Iterative_methods_for_reciprocal_square_roots + * new_invsqrt = (invsqrt / 2) * (3 - count * invsqrt^2) + * + * Here, invsqrt is a fixed point number (< 1.0), 32bit mantissa, aka Q0.32 + */ +static void codel_Newton_step(struct codel_vars *vars) +{ + u32 invsqrt = ((u32)vars->rec_inv_sqrt) << REC_INV_SQRT_SHIFT; + u32 invsqrt2 = ((u64)invsqrt * invsqrt) >> 32; + u64 val = (3LL << 32) - ((u64)vars->count * invsqrt2); + + val >>= 2; /* avoid overflow in following multiply */ + val = (val * invsqrt) >> (32 - 2 + 1); + + vars->rec_inv_sqrt = val >> REC_INV_SQRT_SHIFT; +} + +/* + * CoDel control_law is t + interval/sqrt(count) + * We maintain in rec_inv_sqrt the reciprocal value of sqrt(count) to avoid + * both sqrt() and divide operation. + */ +static codel_time_t codel_control_law(codel_time_t t, + codel_time_t interval, + u32 rec_inv_sqrt) +{ + return t + reciprocal_divide(interval, rec_inv_sqrt << REC_INV_SQRT_SHIFT); +} + + +static bool codel_should_drop(const struct sk_buff *skb, + struct Qdisc *sch, + struct codel_vars *vars, + struct codel_params *params, + struct codel_stats *stats, + codel_time_t now) +{ + bool ok_to_drop; + + if (!skb) { + vars->first_above_time = 0; + return false; + } + + vars->ldelay = now - codel_get_enqueue_time(skb); +#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,37)) + sch->qstats.backlog -= qdisc_pkt_len((struct sk_buff *)skb); +#else + sch->qstats.backlog -= qdisc_pkt_len(skb); +#endif + +#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,37)) + if (unlikely(qdisc_pkt_len((struct sk_buff *)skb) > stats->maxpacket)) + stats->maxpacket = qdisc_pkt_len((struct sk_buff *)skb); +#else + if (unlikely(qdisc_pkt_len(skb) > stats->maxpacket)) + stats->maxpacket = qdisc_pkt_len(skb); +#endif + + if (codel_time_before(vars->ldelay, params->target) || + sch->qstats.backlog <= stats->maxpacket) { + /* went below - stay below for at least interval */ + vars->first_above_time = 0; + return false; + } + ok_to_drop = false; + if (vars->first_above_time == 0) { + /* just went above from below. If we stay above + * for at least interval we'll say it's ok to drop + */ + vars->first_above_time = now + params->interval; + } else if (codel_time_after(now, vars->first_above_time)) { + ok_to_drop = true; + } + return ok_to_drop; +} + +typedef struct sk_buff * (*codel_skb_dequeue_t)(struct codel_vars *vars, + struct Qdisc *sch); + +static struct sk_buff *codel_dequeue(struct Qdisc *sch, + struct codel_params *params, + struct codel_vars *vars, + struct codel_stats *stats, + codel_skb_dequeue_t dequeue_func) +{ + struct sk_buff *skb = dequeue_func(vars, sch); + codel_time_t now; + bool drop; + + if (!skb) { + vars->dropping = false; + return skb; + } + now = codel_get_time(); + drop = codel_should_drop(skb, sch, vars, params, stats, now); + if (vars->dropping) { + if (!drop) { + /* sojourn time below target - leave dropping state */ + vars->dropping = false; + } else if (codel_time_after_eq(now, vars->drop_next)) { + /* It's time for the next drop. Drop the current + * packet and dequeue the next. The dequeue might + * take us out of dropping state. + * If not, schedule the next drop. + * A large backlog might result in drop rates so high + * that the next drop should happen now, + * hence the while loop. + */ + while (vars->dropping && + codel_time_after_eq(now, vars->drop_next)) { + vars->count++; /* dont care of possible wrap + * since there is no more divide + */ + codel_Newton_step(vars); + if (params->ecn && INET_ECN_set_ce(skb)) { + stats->ecn_mark++; + vars->drop_next = + codel_control_law(vars->drop_next, + params->interval, + vars->rec_inv_sqrt); + goto end; + } + qdisc_drop(skb, sch); + stats->drop_count++; + skb = dequeue_func(vars, sch); + if (!codel_should_drop(skb, sch, + vars, params, stats, now)) { + /* leave dropping state */ + vars->dropping = false; + } else { + /* and schedule the next drop */ + vars->drop_next = + codel_control_law(vars->drop_next, + params->interval, + vars->rec_inv_sqrt); + } + } + } + } else if (drop) { + if (params->ecn && INET_ECN_set_ce(skb)) { + stats->ecn_mark++; + } else { + qdisc_drop(skb, sch); + stats->drop_count++; + + skb = dequeue_func(vars, sch); + drop = codel_should_drop(skb, sch, vars, params, + stats, now); + } + vars->dropping = true; + /* if min went above target close to when we last went below it + * assume that the drop rate that controlled the queue on the + * last cycle is a good starting point to control it now. + */ + if (codel_time_before(now - vars->drop_next, + 16 * params->interval)) { + vars->count = (vars->count - vars->lastcount) | 1; + /* we dont care if rec_inv_sqrt approximation + * is not very precise : + * Next Newton steps will correct it quadratically. + */ + codel_Newton_step(vars); + } else { + vars->count = 1; + vars->rec_inv_sqrt = ~0U >> REC_INV_SQRT_SHIFT; + } + vars->lastcount = vars->count; + vars->drop_next = codel_control_law(now, params->interval, + vars->rec_inv_sqrt); + } +end: + return skb; +} +#endif +#endif diff --git a/backport-include/net/dst.h b/backport-include/net/dst.h new file mode 100644 index 0000000..e4e3d8f --- /dev/null +++ b/backport-include/net/dst.h @@ -0,0 +1,35 @@ +#ifndef __BACKPORT_NET_DST_H +#define __BACKPORT_NET_DST_H +#include_next <net/dst.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31) +/* + * Added via adf30907d63893e4208dfe3f5c88ae12bc2f25d5 + * + * There is no _sk_dst on older kernels, so just set the + * old dst to NULL and release it directly. + */ +static inline void skb_dst_drop(struct sk_buff *skb) +{ + dst_release(skb->dst); + skb->dst = NULL; +} + +static inline struct dst_entry *skb_dst(const struct sk_buff *skb) +{ + return (struct dst_entry *)skb->dst; +} + +static inline void skb_dst_set(struct sk_buff *skb, struct dst_entry *dst) +{ + skb->dst = dst; +} + +static inline struct rtable *skb_rtable(const struct sk_buff *skb) +{ + return (struct rtable *)skb_dst(skb); +} +#endif + +#endif /* __BACKPORT_NET_DST_H */ diff --git a/backport-include/net/flow_keys.h b/backport-include/net/flow_keys.h new file mode 100644 index 0000000..a875ee6 --- /dev/null +++ b/backport-include/net/flow_keys.h @@ -0,0 +1,21 @@ +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0)) +#include_next <net/flow_keys.h> +#else + +#ifndef _NET_FLOW_KEYS_H +#define _NET_FLOW_KEYS_H + +struct flow_keys { + /* (src,dst) must be grouped, in the same way than in IP header */ + __be32 src; + __be32 dst; + union { + __be32 ports; + __be16 port16[2]; + }; + u8 ip_proto; +}; + +extern bool skb_flow_dissect(const struct sk_buff *skb, struct flow_keys *flow); +#endif +#endif diff --git a/backport-include/net/genetlink.h b/backport-include/net/genetlink.h new file mode 100644 index 0000000..4458a10 --- /dev/null +++ b/backport-include/net/genetlink.h @@ -0,0 +1,101 @@ +#ifndef __BACKPORT_NET_GENETLINK_H +#define __BACKPORT_NET_GENETLINK_H +#include_next <net/genetlink.h> + +/* this is for patches we apply */ +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0) +#define genl_info_snd_portid(__genl_info) (__genl_info->snd_pid) +#else +#define genl_info_snd_portid(__genl_info) (__genl_info->snd_portid) +#endif + +#ifndef GENLMSG_DEFAULT_SIZE +#define GENLMSG_DEFAULT_SIZE (NLMSG_DEFAULT_SIZE - GENL_HDRLEN) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0) +#define genl_dump_check_consistent(cb, user_hdr, family) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) +struct compat_genl_info { + struct genl_info *info; + + u32 snd_seq; + u32 snd_pid; + struct genlmsghdr *genlhdr; + struct nlattr **attrs; + void *user_ptr[2]; +}; +#define genl_info compat_genl_info + +struct compat_genl_ops { + struct genl_ops ops; + + u8 cmd; + u8 internal_flags; + unsigned int flags; + const struct nla_policy *policy; + + int (*doit)(struct sk_buff *skb, struct genl_info *info); + int (*dumpit)(struct sk_buff *skb, struct netlink_callback *cb); + int (*done)(struct netlink_callback *cb); +}; +#define genl_ops compat_genl_ops + +struct compat_genl_family { + struct genl_family family; + + struct list_head list; + + unsigned int id, hdrsize, version, maxattr; + const char *name; + bool netnsok; + + struct nlattr **attrbuf; + + int (*pre_doit)(struct genl_ops *ops, struct sk_buff *skb, + struct genl_info *info); + + void (*post_doit)(struct genl_ops *ops, struct sk_buff *skb, + struct genl_info *info); +}; + +#define genl_family compat_genl_family + +#define genl_register_family_with_ops compat_genl_register_family_with_ops + +int genl_register_family_with_ops(struct genl_family *family, + struct genl_ops *ops, size_t n_ops); + +#define genl_unregister_family compat_genl_unregister_family + +int genl_unregister_family(struct genl_family *family); + +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,32)) +#define genl_info_net(_info) genl_info_net((_info)->info) +#endif + +#define genlmsg_reply(_msg, _info) genlmsg_reply(_msg, (_info)->info) +#define genlmsg_put(_skb, _pid, _seq, _fam, _flags, _cmd) genlmsg_put(_skb, _pid, _seq, &(_fam)->family, _flags, _cmd) +#define genl_register_mc_group(_fam, _grp) genl_register_mc_group(&(_fam)->family, _grp) +#define genl_unregister_mc_group(_fam, _grp) genl_unregister_mc_group(&(_fam)->family, _grp) +#endif /* < 2.6.37 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) +/* + * struct genl_multicast_group was made netns aware through + * patch "genetlink: make netns aware" by johannes, we just + * force this to always use the default init_net + */ +#define genl_info_net(x) &init_net +/* Just use init_net for older kernels */ +#define get_net_ns_by_pid(x) &init_net + +/* net namespace is lost */ +#define genlmsg_multicast_netns(a, b, c, d, e) genlmsg_multicast(b, c, d, e) +#define genlmsg_multicast_allns(a, b, c, d) genlmsg_multicast(a, b, c, d) +#define genlmsg_unicast(net, skb, pid) genlmsg_unicast(skb, pid) +#endif + +#endif /* __BACKPORT_NET_GENETLINK_H */ diff --git a/backport-include/net/ip.h b/backport-include/net/ip.h new file mode 100644 index 0000000..909e603 --- /dev/null +++ b/backport-include/net/ip.h @@ -0,0 +1,14 @@ +#ifndef __BACKPORT_NET_IP_H +#define __BACKPORT_NET_IP_H +#include_next <net/ip.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0) +/* Backports 56f8a75c */ +static inline bool ip_is_fragment(const struct iphdr *iph) +{ + return (iph->frag_off & htons(IP_MF | IP_OFFSET)) != 0; +} +#endif + +#endif /* __BACKPORT_NET_IP_H */ diff --git a/backport-include/net/iw_handler.h b/backport-include/net/iw_handler.h new file mode 100644 index 0000000..c418d7d --- /dev/null +++ b/backport-include/net/iw_handler.h @@ -0,0 +1,27 @@ +#ifndef __BACKPORT_NET_IW_HANDLER_H +#define __BACKPORT_NET_IW_HANDLER_H +#include_next <net/iw_handler.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) +#define wireless_send_event(a, b, c, d) wireless_send_event(a, b, c, (char * ) d) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) +#define iwe_stream_add_value(info, event, value, ends, iwe, event_len) iwe_stream_add_value(event, value, ends, iwe, event_len) +#define iwe_stream_add_point(info, stream, ends, iwe, extra) iwe_stream_add_point(stream, ends, iwe, extra) +#define iwe_stream_add_event(info, stream, ends, iwe, event_len) iwe_stream_add_event(stream, ends, iwe, event_len) + +#define IW_REQUEST_FLAG_COMPAT 0x0001 /* Compat ioctl call */ + +static inline int iwe_stream_lcp_len(struct iw_request_info *info) +{ +#ifdef CONFIG_COMPAT + if (info->flags & IW_REQUEST_FLAG_COMPAT) + return IW_EV_COMPAT_LCP_LEN; +#endif + return IW_EV_LCP_LEN; +} +#endif + +#endif /* __BACKPORT_NET_IW_HANDLER_H */ diff --git a/backport-include/net/mac80211.h b/backport-include/net/mac80211.h new file mode 100644 index 0000000..c31b462 --- /dev/null +++ b/backport-include/net/mac80211.h @@ -0,0 +1,8 @@ +#ifndef __BACKPORT_NET_MAC80211_H +#define __BACKPORT_NET_MAC80211_H + +/* on some kernels, libipw also uses this, so override */ +#define ieee80211_rx mac80211_ieee80211_rx +#include_next <net/mac80211.h> + +#endif /* __BACKPORT_NET_MAC80211_H */ diff --git a/backport-include/net/net_namespace.h b/backport-include/net/net_namespace.h new file mode 100644 index 0000000..f23702f --- /dev/null +++ b/backport-include/net/net_namespace.h @@ -0,0 +1,63 @@ +#ifndef _COMPAT_NET_NET_NAMESPACE_H +#define _COMPAT_NET_NET_NAMESPACE_H 1 + +#include <linux/version.h> + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,23)) +#include_next <net/net_namespace.h> +#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,23)) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) +#ifdef CONFIG_NET_NS +static inline void write_pnet(struct net **pnet, struct net *net) +{ + *pnet = net; +} + +static inline struct net *read_pnet(struct net * const *pnet) +{ + return *pnet; +} + +#else +#define write_pnet(pnet, net) do { (void)(net);} while (0) +#define read_pnet(pnet) (&init_net) +#endif +#endif /* < 2.6.29 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) +#ifdef CONFIG_NET_NS +static inline +int net_eq(const struct net *net1, const struct net *net2) +{ + return net1 == net2; +} +#else +static inline +int net_eq(const struct net *net1, const struct net *net2) +{ + return 1; +} +#endif + +static inline +void dev_net_set(struct net_device *dev, struct net *net) +{ +#ifdef CONFIG_NET_NS + release_net(dev->nd_net); + dev->nd_net = hold_net(net); +#endif +} + +static inline +struct net *sock_net(const struct sock *sk) +{ +#ifdef CONFIG_NET_NS + return sk->sk_net; +#else + return &init_net; +#endif +} +#endif /* < 2.6.26 */ + +#endif /* _COMPAT_NET_NET_NAMESPACE_H */ diff --git a/backport-include/net/netlink.h b/backport-include/net/netlink.h new file mode 100644 index 0000000..39e0149 --- /dev/null +++ b/backport-include/net/netlink.h @@ -0,0 +1,122 @@ +#ifndef __BACKPORT_NET_NETLINK_H +#define __BACKPORT_NET_NETLINK_H +#include_next <net/netlink.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0) +/** + * nla_put_s8 - Add a s8 netlink attribute to a socket buffer + * @skb: socket buffer to add attribute to + * @attrtype: attribute type + * @value: numeric value + */ +static inline int nla_put_s8(struct sk_buff *skb, int attrtype, s8 value) +{ + return nla_put(skb, attrtype, sizeof(s8), &value); +} + +/** + * nla_put_s16 - Add a s16 netlink attribute to a socket buffer + * @skb: socket buffer to add attribute to + * @attrtype: attribute type + * @value: numeric value + */ +static inline int nla_put_s16(struct sk_buff *skb, int attrtype, s16 value) +{ + return nla_put(skb, attrtype, sizeof(s16), &value); +} + +/** + * nla_put_s32 - Add a s32 netlink attribute to a socket buffer + * @skb: socket buffer to add attribute to + * @attrtype: attribute type + * @value: numeric value + */ +static inline int nla_put_s32(struct sk_buff *skb, int attrtype, s32 value) +{ + return nla_put(skb, attrtype, sizeof(s32), &value); +} + +/** + * nla_put_s64 - Add a s64 netlink attribute to a socket buffer + * @skb: socket buffer to add attribute to + * @attrtype: attribute type + * @value: numeric value + */ +static inline int nla_put_s64(struct sk_buff *skb, int attrtype, s64 value) +{ + return nla_put(skb, attrtype, sizeof(s64), &value); +} + +/** + * nla_get_s32 - return payload of s32 attribute + * @nla: s32 netlink attribute + */ +static inline s32 nla_get_s32(const struct nlattr *nla) +{ + return *(s32 *) nla_data(nla); +} + +/** + * nla_get_s16 - return payload of s16 attribute + * @nla: s16 netlink attribute + */ +static inline s16 nla_get_s16(const struct nlattr *nla) +{ + return *(s16 *) nla_data(nla); +} + +/** + * nla_get_s8 - return payload of s8 attribute + * @nla: s8 netlink attribute + */ +static inline s8 nla_get_s8(const struct nlattr *nla) +{ + return *(s8 *) nla_data(nla); +} + +/** + * nla_get_s64 - return payload of s64 attribute + * @nla: s64 netlink attribute + */ +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29)) +static inline s64 nla_get_s64(const struct nlattr *nla) +#else +static inline s64 nla_get_s64(struct nlattr *nla) +#endif +{ + s64 tmp; + + nla_memcpy(&tmp, nla, sizeof(tmp)); + + return tmp; +} +#endif /* < 3.7.0 */ + +#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0)) +/* + * This backports: + * commit 569a8fc38367dfafd87454f27ac646c8e6b54bca + * Author: David S. Miller <davem@davemloft.net> + * Date: Thu Mar 29 23:18:53 2012 -0400 + * + * netlink: Add nla_put_be{16,32,64}() helpers. + */ + +static inline int nla_put_be16(struct sk_buff *skb, int attrtype, __be16 value) +{ + return nla_put(skb, attrtype, sizeof(__be16), &value); +} + +static inline int nla_put_be32(struct sk_buff *skb, int attrtype, __be32 value) +{ + return nla_put(skb, attrtype, sizeof(__be32), &value); +} + +static inline int nla_put_be64(struct sk_buff *skb, int attrtype, __be64 value) +{ + return nla_put(skb, attrtype, sizeof(__be64), &value); +} +#endif /* < 3.5 */ + +#endif /* __BACKPORT_NET_NETLINK_H */ diff --git a/backport-include/net/sch_generic.h b/backport-include/net/sch_generic.h new file mode 100644 index 0000000..04997c7 --- /dev/null +++ b/backport-include/net/sch_generic.h @@ -0,0 +1,132 @@ +#ifndef __BACKPORT_NET_SCH_GENERIC_H +#define __BACKPORT_NET_SCH_GENERIC_H +#include_next <net/sch_generic.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) +#if !((LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,9) && LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0)) || (LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,23) && LINUX_VERSION_CODE < KERNEL_VERSION(3,1,0))) +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,37) +/* mask qdisc_cb_private_validate as RHEL6 backports this */ +#define qdisc_cb_private_validate(a,b) compat_qdisc_cb_private_validate(a,b) +static inline void qdisc_cb_private_validate(const struct sk_buff *skb, int sz) +{ + BUILD_BUG_ON(sizeof(skb->cb) < sizeof(struct qdisc_skb_cb) + sz); +} +#else +/* mask qdisc_cb_private_validate as RHEL6 backports this */ +#define qdisc_cb_private_validate(a,b) compat_qdisc_cb_private_validate(a,b) +static inline void qdisc_cb_private_validate(const struct sk_buff *skb, int sz) +{ + /* XXX ? */ +} +#endif +#endif +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) +static inline struct net_device *qdisc_dev(const struct Qdisc *qdisc) +{ + return qdisc->dev; +} + +/* + * Backports 378a2f09 and c27f339a + * This may need a bit more work. + */ +enum net_xmit_qdisc_t { + __NET_XMIT_STOLEN = 0x00010000, + __NET_XMIT_BYPASS = 0x00020000, +}; + +struct qdisc_skb_cb { + unsigned int pkt_len; + char data[]; +}; + +static inline struct qdisc_skb_cb *qdisc_skb_cb(struct sk_buff *skb) +{ + return (struct qdisc_skb_cb *)skb->cb; +} + +static inline unsigned int qdisc_pkt_len(struct sk_buff *skb) +{ + return qdisc_skb_cb(skb)->pkt_len; +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,38) +#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,30) +static inline void bstats_update(struct gnet_stats_basic_packed *bstats, + const struct sk_buff *skb) +{ + bstats->bytes += qdisc_pkt_len((struct sk_buff *) skb); + bstats->packets += skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 1; +} +static inline void qdisc_bstats_update(struct Qdisc *sch, + const struct sk_buff *skb) +{ + bstats_update(&sch->bstats, skb); +} +#else +/* + * kernels <= 2.6.30 do not pass a const skb to qdisc_pkt_len, and + * gnet_stats_basic_packed did not exist (see c1a8f1f1c8) + */ +static inline void bstats_update(struct gnet_stats_basic *bstats, + struct sk_buff *skb) +{ + bstats->bytes += qdisc_pkt_len(skb); + bstats->packets += skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 1; +} +static inline void qdisc_bstats_update(struct Qdisc *sch, + struct sk_buff *skb) +{ + bstats_update(&sch->bstats, skb); +} +#endif +#endif /* < 2.6.38 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) + +#define qdisc_reset_all_tx_gt LINUX_BACKPORT(qdisc_reset_all_tx_gt) + +/* Reset all TX qdiscs greater then index of a device. */ +static inline void qdisc_reset_all_tx_gt(struct net_device *dev, unsigned int i) +{ + struct Qdisc *qdisc; + + for (; i < dev->num_tx_queues; i++) { + qdisc = netdev_get_tx_queue(dev, i)->qdisc; + if (qdisc) { + spin_lock_bh(qdisc_lock(qdisc)); + qdisc_reset(qdisc); + spin_unlock_bh(qdisc_lock(qdisc)); + } + } +} +#else +static inline void qdisc_reset_all_tx_gt(struct net_device *dev, unsigned int i) +{ +} +#endif /* >= 2.6.27 */ +#endif /* < 2.6.35 */ + +#ifndef TCQ_F_CAN_BYPASS +#define TCQ_F_CAN_BYPASS 4 +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,32) +static inline int qdisc_qlen(const struct Qdisc *q) +{ + return q->q.qlen; +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) +static inline bool qdisc_all_tx_empty(const struct net_device *dev) +{ + return skb_queue_empty(&dev->qdisc->q); +} +#endif + +#endif /* __BACKPORT_NET_SCH_GENERIC_H */ diff --git a/backport-include/net/sock.h b/backport-include/net/sock.h new file mode 100644 index 0000000..b4f3e6a --- /dev/null +++ b/backport-include/net/sock.h @@ -0,0 +1,76 @@ +#ifndef __BACKPORT_NET_SOCK_H +#define __BACKPORT_NET_SOCK_H +#include_next <net/sock.h> +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0) +#include <backport/magic.h> + +#define sk_for_each3(__sk, node, list) \ + hlist_for_each_entry(__sk, node, list, sk_node) + +#define sk_for_each_safe4(__sk, node, tmp, list) \ + hlist_for_each_entry_safe(__sk, node, tmp, list, sk_node) + +#define sk_for_each2(__sk, list) \ + hlist_for_each_entry(__sk, list, sk_node) + +#define sk_for_each_safe3(__sk, tmp, list) \ + hlist_for_each_entry_safe(__sk, tmp, list, sk_node) + +#undef sk_for_each +#define sk_for_each(...) \ + macro_dispatcher(sk_for_each, __VA_ARGS__)(__VA_ARGS__) +#undef sk_for_each_safe +#define sk_for_each_safe(...) \ + macro_dispatcher(sk_for_each_safe, __VA_ARGS__)(__VA_ARGS__) + +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) +/* + * backport SOCK_SELECT_ERR_QUEUE -- see commit + * "net: add option to enable error queue packets waking select" + * + * Adding 14 to SOCK_QUEUE_SHRUNK will reach a bet that can't be + * set on older kernels, so sock_flag() will always return false. + */ +#define SOCK_SELECT_ERR_QUEUE (SOCK_QUEUE_SHRUNK + 14) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,35) +static inline wait_queue_head_t *sk_sleep(struct sock *sk) +{ + return sk->sk_sleep; +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) +static inline struct sock *sk_entry(const struct hlist_node *node) +{ + return hlist_entry(node, struct sock, sk_node); +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33) +#define sock_recv_ts_and_drops(msg, sk, skb) sock_recv_timestamp(msg, sk, skb) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31) +static inline int sk_rmem_alloc_get(const struct sock *sk) +{ + return atomic_read(&sk->sk_rmem_alloc); +} + +static inline int sk_wmem_alloc_get(const struct sock *sk) +{ + return atomic_read(&sk->sk_wmem_alloc) - 1; +} + +static inline bool sk_has_allocations(const struct sock *sk) +{ + return sk_wmem_alloc_get(sk) || sk_rmem_alloc_get(sk); +} +#endif + +#endif /* __BACKPORT_NET_SOCK_H */ diff --git a/backport-include/pcmcia/cistpl.h b/backport-include/pcmcia/cistpl.h new file mode 100644 index 0000000..789dc59 --- /dev/null +++ b/backport-include/pcmcia/cistpl.h @@ -0,0 +1,10 @@ +#include <linux/version.h> + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) +#include <pcmcia/cs_types.h> +#endif +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) +#include <pcmcia/cs.h> +#endif + +#include_next <pcmcia/cistpl.h> diff --git a/backport-include/pcmcia/device_id.h b/backport-include/pcmcia/device_id.h new file mode 100644 index 0000000..908af50 --- /dev/null +++ b/backport-include/pcmcia/device_id.h @@ -0,0 +1,23 @@ +#ifndef __BACKPORT_PCMCIA_DEVICE_ID_H +#define __BACKPORT_PCMCIA_DEVICE_ID_H +#include_next <pcmcia/device_id.h> + +#ifndef PCMCIA_DEVICE_MANF_CARD_PROD_ID3 +#define PCMCIA_DEVICE_MANF_CARD_PROD_ID3(manf, card, v3, vh3) { \ + .match_flags = PCMCIA_DEV_ID_MATCH_MANF_ID| \ + PCMCIA_DEV_ID_MATCH_CARD_ID| \ + PCMCIA_DEV_ID_MATCH_PROD_ID3, \ + .manf_id = (manf), \ + .card_id = (card), \ + .prod_id = { NULL, NULL, (v3), NULL }, \ + .prod_id_hash = { 0, 0, (vh3), 0 }, } +#endif + +#ifndef PCMCIA_DEVICE_PROD_ID3 +#define PCMCIA_DEVICE_PROD_ID3(v3, vh3) { \ + .match_flags = PCMCIA_DEV_ID_MATCH_PROD_ID3, \ + .prod_id = { NULL, NULL, (v3), NULL }, \ + .prod_id_hash = { 0, 0, (vh3), 0 }, } +#endif + +#endif /* __BACKPORT_PCMCIA_DEVICE_ID_H */ diff --git a/backport-include/pcmcia/ds.h b/backport-include/pcmcia/ds.h new file mode 100644 index 0000000..0e317cd --- /dev/null +++ b/backport-include/pcmcia/ds.h @@ -0,0 +1,87 @@ +#ifndef __BACKPORT_PCMCIA_DS_H +#define __BACKPORT_PCMCIA_DS_H +#include_next <pcmcia/ds.h> + +#ifndef module_pcmcia_driver +/** + * backport of: + * + * commit 6ed7ffddcf61f668114edb676417e5fb33773b59 + * Author: H Hartley Sweeten <hsweeten@visionengravers.com> + * Date: Wed Mar 6 11:24:44 2013 -0700 + * + * pcmcia/ds.h: introduce helper for pcmcia_driver module boilerplate + */ + +/** + * module_pcmcia_driver() - Helper macro for registering a pcmcia driver + * @__pcmcia_driver: pcmcia_driver struct + * + * Helper macro for pcmcia drivers which do not do anything special in module + * init/exit. This eliminates a lot of boilerplate. Each module may only use + * this macro once, and calling it replaces module_init() and module_exit(). + */ +#define module_pcmcia_driver(__pcmcia_driver) \ + module_driver(__pcmcia_driver, pcmcia_register_driver, \ + pcmcia_unregister_driver) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,37) +#define pcmcia_enable_device(link) pcmcia_request_configuration(link, &link->conf) +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) +static inline int pcmcia_read_config_byte(struct pcmcia_device *p_dev, off_t where, u8 *val) +{ + int ret; + conf_reg_t reg = { 0, CS_READ, where, 0 }; + ret = pcmcia_access_configuration_register(p_dev, ®); + *val = reg.Value; + return ret; +} + +static inline int pcmcia_write_config_byte(struct pcmcia_device *p_dev, off_t where, u8 val) +{ + conf_reg_t reg = { 0, CS_WRITE, where, val }; + return pcmcia_access_configuration_register(p_dev, ®); +} +#endif + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33) +#define pcmcia_request_window(a, b, c) pcmcia_request_window(&a, b, c) +#define pcmcia_map_mem_page(a, b, c) pcmcia_map_mem_page(b, c) + +#define pcmcia_loop_tuple LINUX_BACKPORT(pcmcia_loop_tuple) +int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code, + int (*loop_tuple) (struct pcmcia_device *p_dev, + tuple_t *tuple, + void *priv_data), + void *priv_data); + +#define pccard_loop_tuple LINUX_BACKPORT(pccard_loop_tuple) +int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function, + cisdata_t code, cisparse_t *parse, void *priv_data, + int (*loop_tuple) (tuple_t *tuple, + cisparse_t *parse, + void *priv_data)); +#endif /* < 2.6.33 */ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) +#ifdef pcmcia_parse_tuple +#undef pcmcia_parse_tuple +#define pcmcia_parse_tuple(tuple, parse) pccard_parse_tuple(tuple, parse) +#endif + +/* From : include/pcmcia/ds.h */ +/* loop CIS entries for valid configuration */ +#define pcmcia_loop_config LINUX_BACKPORT(pcmcia_loop_config) +int pcmcia_loop_config(struct pcmcia_device *p_dev, + int (*conf_check) (struct pcmcia_device *p_dev, + cistpl_cftable_entry_t *cfg, + cistpl_cftable_entry_t *dflt, + unsigned int vcc, + void *priv_data), + void *priv_data); +#endif + +#endif /* __BACKPORT_PCMCIA_DS_H */ diff --git a/backport-include/trace/define_trace.h b/backport-include/trace/define_trace.h new file mode 100644 index 0000000..0b40727 --- /dev/null +++ b/backport-include/trace/define_trace.h @@ -0,0 +1,5 @@ +#include <linux/version.h> + +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32)) +#include_next <trace/define_trace.h> +#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32)) */ diff --git a/backport-include/uapi/linux/v4l2-mediabus.h b/backport-include/uapi/linux/v4l2-mediabus.h new file mode 100644 index 0000000..9979c23 --- /dev/null +++ b/backport-include/uapi/linux/v4l2-mediabus.h @@ -0,0 +1,39 @@ +#ifndef __BACKPORT_LINUX_V4L2_MEDIABUS_H +#define __BACKPORT_LINUX_V4L2_MEDIABUS_H +#include <linux/version.h> + +/* + * SOC_CAMERA is only enabled on 3.4 as it depends on some + * newer regulator functionality, however there are some SOC + * cameras that can rely on the 3.3 regulatory built-in core + * and the 3.3 SOC_CAMERA module however two routines are + * not exported in that version of SOC_CAMERA that newer + * SOC cameras do require. Backport that functionality. + * + * Technically this should go into <media/soc_camera.h> + * given that is where its where its exported on linux-next + * but in practice only placing it here actually fixes linking + * errors for 3.3 for all SOC camera drivers we make available + * for 3.3. + */ +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0)) +#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0)) +#if defined(CPTCFG_VIDEO_DEV_MODULE) + +struct soc_camera_subdev_desc; + +#define soc_camera_power_on LINUX_BACKPORT(soc_camera_power_on) +int soc_camera_power_on(struct device *dev, + struct soc_camera_subdev_desc *ssdd); + +#define soc_camera_power_off LINUX_BACKPORT(soc_camera_power_off) +int soc_camera_power_off(struct device *dev, + struct soc_camera_subdev_desc *ssdd); + +#endif /* defined(CPTCFG_VIDEO_DEV_MODULE) */ +#endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0)) */ +#endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,3,0)) */ + +#include_next <linux/v4l2-mediabus.h> + +#endif /* __BACKPORT_LINUX_V4L2_MEDIABUS_H */ |