diff options
Diffstat (limited to 'sys/ofed/include/linux')
82 files changed, 1188 insertions, 234 deletions
diff --git a/sys/ofed/include/linux/atomic.h b/sys/ofed/include/linux/atomic.h deleted file mode 100644 index 0d689c1d4b72..000000000000 --- a/sys/ofed/include/linux/atomic.h +++ /dev/null @@ -1,53 +0,0 @@ -#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> - -/* Shahar Klein: atomic_inc_not_zero_hint do we need it? */ -#if 0 - -/** - * 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 - -//#endif /* (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,36)) */ - -#endif /* _COMPAT_LINUX_ATOMIC_H */ diff --git a/sys/ofed/include/linux/bitmap.h b/sys/ofed/include/linux/bitmap.h deleted file mode 100644 index 66059ac86c86..000000000000 --- a/sys/ofed/include/linux/bitmap.h +++ /dev/null @@ -1,34 +0,0 @@ -/*- - * Copyright (c) 2010 Isilon Systems, Inc. - * Copyright (c) 2010 iX Systems, Inc. - * Copyright (c) 2010 Panasas, Inc. - * All rights reserved. - * - * 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 unmodified, this list of conditions, and the following - * disclaimer. - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - */ -#ifndef _LINUX_BITMAP_H_ -#define _LINUX_BITMAP_H_ - -#include <linux/bitops.h> -#include <linux/string.h> - -#endif /* _LINUX_BITMAP_H_ */ diff --git a/sys/ofed/include/linux/bitops.h b/sys/ofed/include/linux/bitops.h index 04bd5e6607ec..93a3aa93a157 100644 --- a/sys/ofed/include/linux/bitops.h +++ b/sys/ofed/include/linux/bitops.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,6 +38,8 @@ #define BITS_TO_LONGS(n) howmany((n), BITS_PER_LONG) #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) +#define BITS_PER_BYTE 8 + static inline int __ffs(int mask) { @@ -463,6 +466,27 @@ bitmap_find_free_region(unsigned long *bitmap, int bits, int order) } /** + * bitmap_allocate_region - allocate bitmap region + * @bitmap: array of unsigned longs corresponding to the bitmap + * @pos: beginning of bit region to allocate + * @order: region size (log base 2 of number of bits) to allocate + * + * Allocate (set bits in) a specified region of a bitmap. + * + * Return 0 on success, or %-EBUSY if specified region wasn't + * free (not all bits were zero). + */ + +static inline int +bitmap_allocate_region(unsigned long *bitmap, int pos, int order) +{ + if (!__reg_op(bitmap, pos, order, REG_OP_ISFREE)) + return -EBUSY; + __reg_op(bitmap, pos, order, REG_OP_ALLOC); + return 0; +} + +/** * bitmap_release_region - release allocated bitmap region * @bitmap: array of unsigned longs corresponding to the bitmap * @pos: beginning of bit region to release @@ -480,4 +504,9 @@ bitmap_release_region(unsigned long *bitmap, int pos, int order) } +#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)) + #endif /* _LINUX_BITOPS_H_ */ diff --git a/sys/ofed/include/linux/stddef.h b/sys/ofed/include/linux/cache.h index 22bf93887b5f..e4a9d0924639 100644 --- a/sys/ofed/include/linux/stddef.h +++ b/sys/ofed/include/linux/cache.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,9 +27,11 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _LINUX_STDDEF_H_ -#define _LINUX_STDDEF_H_ +#ifndef _LINUX_CACHE_H_ +#define _LINUX_CACHE_H_ -#include <sys/stddef.h> -#endif /* _LINUX_STDDEF_H_ */ +#define cache_line_size() CACHE_LINE_SIZE + + +#endif /* _LINUX_CACHE_H_ */ diff --git a/sys/ofed/include/linux/cdev.h b/sys/ofed/include/linux/cdev.h index ea48334067eb..986f8197a43d 100644 --- a/sys/ofed/include/linux/cdev.h +++ b/sys/ofed/include/linux/cdev.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/clocksource.h b/sys/ofed/include/linux/clocksource.h index e74cc62e78ec..c6ded280e574 100644 --- a/sys/ofed/include/linux/clocksource.h +++ b/sys/ofed/include/linux/clocksource.h @@ -1,12 +1,32 @@ -/* linux/include/linux/clocksource.h +/*- + * Copyright (c) 2010 Isilon Systems, Inc. + * Copyright (c) 2010 iX Systems, Inc. + * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. + * All rights reserved. * - * MLX4_CORE_PORT + * 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 unmodified, this list of conditions, and the following + * disclaimer. + * 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. * - * This file contains the structure definitions for clocksources. - * - * If you are not a clocksource, or timekeeping code, you should - * not be including this file! + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. */ + #ifndef _LINUX_CLOCKSOURCE_H #define _LINUX_CLOCKSOURCE_H diff --git a/sys/ofed/include/linux/compat.h b/sys/ofed/include/linux/compat.h index 7af826c717bd..a8929f30291c 100644 --- a/sys/ofed/include/linux/compat.h +++ b/sys/ofed/include/linux/compat.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/compiler.h b/sys/ofed/include/linux/compiler.h index 12938ba49b20..9b1a5ad47d6e 100644 --- a/sys/ofed/include/linux/compiler.h +++ b/sys/ofed/include/linux/compiler.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/completion.h b/sys/ofed/include/linux/completion.h index 59f36b0b3f23..1ef23ea0009b 100644 --- a/sys/ofed/include/linux/completion.h +++ b/sys/ofed/include/linux/completion.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,12 +26,11 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _LINUX_COMPLETION_H_ -#define _LINUX_COMPLETION_H_ + +#ifndef _FBSD_COMPLETION_H_ +#define _FBSD_COMPLETION_H_ #include <linux/errno.h> -#include <linux/sched.h> -#include <linux/wait.h> #include <sys/param.h> #include <sys/systm.h> diff --git a/sys/ofed/include/linux/delay.h b/sys/ofed/include/linux/delay.h index 019ef8ad861e..ac9e46de3419 100644 --- a/sys/ofed/include/linux/delay.h +++ b/sys/ofed/include/linux/delay.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/device.h b/sys/ofed/include/linux/device.h index 37a772065baa..f7bb0fb646da 100644 --- a/sys/ofed/include/linux/device.h +++ b/sys/ofed/include/linux/device.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -51,6 +52,7 @@ struct class { devclass_t bsdclass; void (*class_release)(struct class *class); void (*dev_release)(struct device *dev); + char * (*devnode)(struct device *dev, umode_t *mode); }; struct device { @@ -72,10 +74,12 @@ extern struct device linux_rootdev; extern struct kobject class_root; struct class_attribute { - struct attribute attr; - ssize_t (*show)(struct class *, char *); - ssize_t (*store)(struct class *, const char *, size_t); + struct attribute attr; + ssize_t (*show)(struct class *, struct class_attribute *, char *); + ssize_t (*store)(struct class *, struct class_attribute *, const char *, size_t); + const void *(*namespace)(struct class *, const struct class_attribute *); }; + #define CLASS_ATTR(_name, _mode, _show, _store) \ struct class_attribute class_attr_##_name = \ { { #_name, NULL, _mode }, _show, _store } @@ -83,16 +87,38 @@ struct class_attribute { struct device_attribute { struct attribute attr; ssize_t (*show)(struct device *, - struct device_attribute *, char *); + struct device_attribute *, char *); ssize_t (*store)(struct device *, - struct device_attribute *, const char *, - size_t); + struct device_attribute *, const char *, + size_t); }; #define DEVICE_ATTR(_name, _mode, _show, _store) \ struct device_attribute dev_attr_##_name = \ { { #_name, NULL, _mode }, _show, _store } +/* Simple class attribute that is just a static string */ +struct class_attribute_string { + struct class_attribute attr; + char *str; +}; + +static inline ssize_t +show_class_attr_string(struct class *class, + struct class_attribute *attr, char *buf) +{ + struct class_attribute_string *cs; + cs = container_of(attr, struct class_attribute_string, attr); + return snprintf(buf, PAGE_SIZE, "%s\n", cs->str); +} + +/* Currently read-only only */ +#define _CLASS_ATTR_STRING(_name, _mode, _str) \ + { __ATTR(_name, _mode, show_class_attr_string, NULL), _str } +#define CLASS_ATTR_STRING(_name, _mode, _str) \ + struct class_attribute_string class_attr_##_name = \ + _CLASS_ATTR_STRING(_name, _mode, _str) + #define dev_err(dev, fmt, ...) device_printf((dev)->bsddev, fmt, ##__VA_ARGS__) #define dev_warn(dev, fmt, ...) device_printf((dev)->bsddev, fmt, ##__VA_ARGS__) #define dev_info(dev, fmt, ...) device_printf((dev)->bsddev, fmt, ##__VA_ARGS__) @@ -151,7 +177,7 @@ class_show(struct kobject *kobj, struct attribute *attr, char *buf) error = -EIO; if (dattr->show) error = dattr->show(container_of(kobj, struct class, kobj), - buf); + dattr, buf); return (error); } @@ -166,7 +192,7 @@ class_store(struct kobject *kobj, struct attribute *attr, const char *buf, error = -EIO; if (dattr->store) error = dattr->store(container_of(kobj, struct class, kobj), - buf, count); + dattr, buf, count); return (error); } @@ -390,5 +416,32 @@ static inline int dev_to_node(struct device *dev) return -1; } +static inline char *kvasprintf(gfp_t gfp, const char *fmt, va_list ap) +{ + unsigned int len; + char *p = NULL; + va_list aq; + + va_copy(aq, ap); + len = vsnprintf(NULL, 0, fmt, aq); + va_end(aq); + + vsnprintf(p, len+1, fmt, ap); + + return p; +} + +static inline char *kasprintf(gfp_t gfp, const char *fmt, ...) +{ + va_list ap; + char *p; + + va_start(ap, fmt); + p = kvasprintf(gfp, fmt, ap); + va_end(ap); + + return p; +} + #endif /* _LINUX_DEVICE_H_ */ diff --git a/sys/ofed/include/linux/dma-attrs.h b/sys/ofed/include/linux/dma-attrs.h index 9e625bd1cd8c..a379e17534c9 100644 --- a/sys/ofed/include/linux/dma-attrs.h +++ b/sys/ofed/include/linux/dma-attrs.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/dma-mapping.h b/sys/ofed/include/linux/dma-mapping.h index 065745cbfa80..2f0762b430be 100644 --- a/sys/ofed/include/linux/dma-mapping.h +++ b/sys/ofed/include/linux/dma-mapping.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/dmapool.h b/sys/ofed/include/linux/dmapool.h index 3b58164c9afd..a6486db722ce 100644 --- a/sys/ofed/include/linux/dmapool.h +++ b/sys/ofed/include/linux/dmapool.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/err.h b/sys/ofed/include/linux/err.h index 858931d2bbf9..fe6b71d2a84b 100644 --- a/sys/ofed/include/linux/err.h +++ b/sys/ofed/include/linux/err.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -57,4 +58,15 @@ ERR_CAST(void *ptr) return (void *)ptr; } +static inline int +PTR_ERR_OR_ZERO(const void *ptr) +{ + if (IS_ERR(ptr)) + return PTR_ERR(ptr); + else + return 0; +} + +#define PTR_RET(p) PTR_ERR_OR_ZERO(p) + #endif /* _LINUX_ERR_H_ */ diff --git a/sys/ofed/include/linux/errno.h b/sys/ofed/include/linux/errno.h index b107c45ccad0..55e192b9878c 100644 --- a/sys/ofed/include/linux/errno.h +++ b/sys/ofed/include/linux/errno.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,9 +32,11 @@ #include <sys/errno.h> -#define ECOMM ESTALE -#define ENODATA ECONNREFUSED -#define ENOIOCTLCMD ENOIOCTL /* XXX this is negative */ -#define ERESTARTSYS ERESTART /* XXX this is negative */ +#define ECOMM ESTALE +#define ENODATA ECONNREFUSED +#define ENOIOCTLCMD ENOIOCTL +#define ERESTARTSYS ERESTART +#define ENOTSUPP EOPNOTSUPP +#define ENONET EHOSTDOWN -#endif /* _LINUX_ERRNO_H_ */ +#endif /* _LINUX_ERRNO_H_ */ diff --git a/sys/ofed/include/linux/etherdevice.h b/sys/ofed/include/linux/etherdevice.h new file mode 100644 index 000000000000..43bc1f29dacd --- /dev/null +++ b/sys/ofed/include/linux/etherdevice.h @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2014 Mellanox Technologies, Ltd. All rights reserved. + * + * This software is available to you under a choice of one of two + * licenses. You may choose to be licensed under the terms of the GNU + * General Public License (GPL) Version 2, available from the file + * COPYING in the main directory of this source tree, or the + * OpenIB.org BSD license below: + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * + * - 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. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + + +#ifndef _LINUX_ETHERDEVICE +#define _LINUX_ETHERDEVICE + +#include <linux/types.h> + +/** + * is_zero_ether_addr - Determine if give Ethernet address is all zeros. + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Return true if the address is all zeroes. + */ +static inline bool is_zero_ether_addr(const u8 *addr) +{ + return !(addr[0] | addr[1] | addr[2] | addr[3] | addr[4] | addr[5]); +} + + + +/** + * is_multicast_ether_addr - Determine if the Ethernet address is a multicast. + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Return true if the address is a multicast address. + * By definition the broadcast address is also a multicast address. + */ +static inline bool is_multicast_ether_addr(const u8 *addr) +{ + return (0x01 & addr[0]); +} + +/** + * is_broadcast_ether_addr - Determine if the Ethernet address is broadcast + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Return true if the address is the broadcast address. + */ +static inline bool is_broadcast_ether_addr(const u8 *addr) +{ + return (addr[0] & addr[1] & addr[2] & addr[3] & addr[4] & addr[5]) == 0xff; +} + +/** + * is_valid_ether_addr - Determine if the given Ethernet address is valid + * @addr: Pointer to a six-byte array containing the Ethernet address + * + * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is not + * a multicast address, and is not FF:FF:FF:FF:FF:FF. + * + * Return true if the address is valid. + **/ +static inline bool is_valid_ether_addr(const u8 *addr) +{ + /* FF:FF:FF:FF:FF:FF is a multicast address so we don't need to + ** explicitly check for it here. */ + return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr); +} + + + +#endif /* _LINUX_ETHERDEVICE */ diff --git a/sys/ofed/include/linux/ethtool.h b/sys/ofed/include/linux/ethtool.h index a26720921891..016b1a5445e5 100644 --- a/sys/ofed/include/linux/ethtool.h +++ b/sys/ofed/include/linux/ethtool.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/file.h b/sys/ofed/include/linux/file.h index bb9d58d50f8d..6576cd029ccd 100644 --- a/sys/ofed/include/linux/file.h +++ b/sys/ofed/include/linux/file.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -106,12 +107,12 @@ get_unused_fd(void) } static inline struct linux_file * -_alloc_file(int mode, const struct file_operations *fops) +alloc_file(int mode, const struct file_operations *fops) { struct linux_file *filp; filp = kzalloc(sizeof(*filp), GFP_KERNEL); - if (filp == NULL) + if (filp == NULL) return (NULL); filp->f_op = fops; filp->f_mode = mode; @@ -119,7 +120,20 @@ _alloc_file(int mode, const struct file_operations *fops) return filp; } -#define alloc_file(mnt, root, mode, fops) _alloc_file((mode), (fops)) +struct fd { + struct linux_file *linux_file; +}; + +static inline void fdput(struct fd fd) +{ + fput(fd.linux_file); +} + +static inline struct fd fdget(unsigned int fd) +{ + struct linux_file *f = linux_fget(fd); + return (struct fd){f}; +} #define file linux_file #define fget linux_fget diff --git a/sys/ofed/include/linux/fs.h b/sys/ofed/include/linux/fs.h index 6c81c6384f7c..bc07bfb82191 100644 --- a/sys/ofed/include/linux/fs.h +++ b/sys/ofed/include/linux/fs.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -106,6 +107,12 @@ struct file_operations { int (*open)(struct inode *, struct file *); int (*release)(struct inode *, struct file *); int (*fasync)(int, struct file *, int); + +/* Although not supported in FreeBSD, to align with Linux code + * we are adding llseek() only when it is mapped to no_llseek which returns + * an illegal seek error + */ + loff_t (*llseek)(struct file *, loff_t, int); #if 0 /* We do not support these methods. Don't permit them to compile. */ loff_t (*llseek)(struct file *, loff_t, int); @@ -154,6 +161,21 @@ unregister_chrdev_region(dev_t dev, unsigned range) return; } +static inline int +alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count, + const char *name) +{ + + return 0; +} + +/* No current support for seek op in FreeBSD */ +static inline int +nonseekable_open(struct inode *inode, struct file *filp) +{ + return 0; +} + static inline dev_t iminor(struct inode *inode) { @@ -180,4 +202,10 @@ iput(struct inode *inode) vrele(inode); } -#endif /* _LINUX_FS_H_ */ +static inline loff_t +no_llseek(struct file *file, loff_t offset, int whence) +{ + return -ESPIPE; +} + +#endif /* _LINUX_FS_H_ */ diff --git a/sys/ofed/include/linux/gfp.h b/sys/ofed/include/linux/gfp.h index f974956bb69f..af30faacab64 100644 --- a/sys/ofed/include/linux/gfp.h +++ b/sys/ofed/include/linux/gfp.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/hardirq.h b/sys/ofed/include/linux/hardirq.h index 4c3aeba1de14..af78ac4ef360 100644 --- a/sys/ofed/include/linux/hardirq.h +++ b/sys/ofed/include/linux/hardirq.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/idr.h b/sys/ofed/include/linux/idr.h index b778e64ccfc9..207d7f7f45d0 100644 --- a/sys/ofed/include/linux/idr.h +++ b/sys/ofed/include/linux/idr.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/if_arp.h b/sys/ofed/include/linux/if_arp.h index c82a2c5c1b00..96946908f821 100644 --- a/sys/ofed/include/linux/if_arp.h +++ b/sys/ofed/include/linux/if_arp.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/if_ether.h b/sys/ofed/include/linux/if_ether.h index f10df2edcb23..fae7a7694686 100644 --- a/sys/ofed/include/linux/if_ether.h +++ b/sys/ofed/include/linux/if_ether.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,9 +35,16 @@ #define ETH_P_8021Q ETHERTYPE_VLAN +#define ETH_HLEN ETHER_HDR_LEN /* Total octets in header. */ +#ifndef ETH_ALEN +#define ETH_ALEN ETHER_ADDR_LEN +#endif +#define ETH_FCS_LEN 4 /* Octets in the FCS */ +#define VLAN_HLEN 4 /* The additional bytes (on top of the Ethernet header) + * that VLAN requires. */ /* * defined Ethernet Protocol ID's. */ -#define ETH_P_IP 0x0800 /* Internet Protocol packet */ +#define ETH_P_IP 0x0800 /* Internet Protocol packet */ #endif /* _LINUX_IF_ETHER_H_ */ diff --git a/sys/ofed/include/linux/if_vlan.h b/sys/ofed/include/linux/if_vlan.h index bb7eee0654b6..8b0cd29c0e0d 100644 --- a/sys/ofed/include/linux/if_vlan.h +++ b/sys/ofed/include/linux/if_vlan.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,7 +30,11 @@ #ifndef _LINUX_IF_VLAN_H_ #define _LINUX_IF_VLAN_H_ +#include <sys/socket.h> +#include <net/if.h> #include <net/ethernet.h> #include <net/if_vlan_var.h> +#define VLAN_N_VID 4096 + #endif /* _LINUX_IF_VLAN_H_ */ diff --git a/sys/ofed/include/linux/in.h b/sys/ofed/include/linux/in.h index 803ef2b02880..963e93e10c66 100644 --- a/sys/ofed/include/linux/in.h +++ b/sys/ofed/include/linux/in.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/in6.h b/sys/ofed/include/linux/in6.h index 2032b6179594..2740142100e3 100644 --- a/sys/ofed/include/linux/in6.h +++ b/sys/ofed/include/linux/in6.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/inet.h b/sys/ofed/include/linux/inet.h index 07fcc73a0b6d..cca8b60860af 100644 --- a/sys/ofed/include/linux/inet.h +++ b/sys/ofed/include/linux/inet.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/inetdevice.h b/sys/ofed/include/linux/inetdevice.h index c7fe1d2bbe8a..554348cadb8e 100644 --- a/sys/ofed/include/linux/inetdevice.h +++ b/sys/ofed/include/linux/inetdevice.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/init.h b/sys/ofed/include/linux/init.h deleted file mode 100644 index d7c2bb13caab..000000000000 --- a/sys/ofed/include/linux/init.h +++ /dev/null @@ -1,31 +0,0 @@ -/*- - * Copyright (c) 2010 Isilon Systems, Inc. - * Copyright (c) 2010 iX Systems, Inc. - * Copyright (c) 2010 Panasas, Inc. - * All rights reserved. - * - * 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 unmodified, this list of conditions, and the following - * disclaimer. - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - */ -#ifndef _LINUX_INIT_H_ -#define _LINUX_INIT_H_ - -#endif /* _LINUX_INIT_H_ */ diff --git a/sys/ofed/include/linux/interrupt.h b/sys/ofed/include/linux/interrupt.h index e35882c9b4e5..d97d6a9018eb 100644 --- a/sys/ofed/include/linux/interrupt.h +++ b/sys/ofed/include/linux/interrupt.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/io-mapping.h b/sys/ofed/include/linux/io-mapping.h index 0753bbc5f1b0..ea62a734b5a2 100644 --- a/sys/ofed/include/linux/io-mapping.h +++ b/sys/ofed/include/linux/io-mapping.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/io.h b/sys/ofed/include/linux/io.h index f1686f7acabc..2fc25b567eb0 100644 --- a/sys/ofed/include/linux/io.h +++ b/sys/ofed/include/linux/io.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/ioctl.h b/sys/ofed/include/linux/ioctl.h index 9e00b7f2a807..289a296f423d 100644 --- a/sys/ofed/include/linux/ioctl.h +++ b/sys/ofed/include/linux/ioctl.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/jiffies.h b/sys/ofed/include/linux/jiffies.h index 7ca63375ec61..ede36b4fb86e 100644 --- a/sys/ofed/include/linux/jiffies.h +++ b/sys/ofed/include/linux/jiffies.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -44,7 +45,10 @@ msecs_to_jiffies(int msec) return (tvtohz(&tv)); } -#define jiffies ticks + +#define jiffies ticks +#define jiffies_to_msecs(x) (((int64_t)(x)) * 1000 / hz) + #define time_after(a, b) ((long)(b) - (long)(a) < 0) #define time_before(a, b) time_after(b,a) diff --git a/sys/ofed/include/linux/kdev_t.h b/sys/ofed/include/linux/kdev_t.h index 4b4f43ef6f5e..8aaca2d73ee9 100644 --- a/sys/ofed/include/linux/kdev_t.h +++ b/sys/ofed/include/linux/kdev_t.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/kernel.h b/sys/ofed/include/linux/kernel.h index 55b71f61fe0d..e1bc220eccfc 100644 --- a/sys/ofed/include/linux/kernel.h +++ b/sys/ofed/include/linux/kernel.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,18 +34,16 @@ #include <sys/libkern.h> #include <sys/stat.h> #include <sys/smp.h> +#include <sys/stddef.h> #include <linux/bitops.h> #include <linux/compiler.h> #include <linux/errno.h> -#include <linux/stddef.h> #include <linux/kthread.h> #include <linux/types.h> #include <linux/jiffies.h> #include <linux/wait.h> -#include <linux/fs.h> -#include <linux/notifier.h> -#include <linux/log2.h> +#include <linux/log2.h> #include <asm/byteorder.h> #define KERN_CONT "" @@ -102,6 +101,8 @@ printk(KERN_NOTICE pr_fmt(fmt), ##__VA_ARGS__) #define pr_info(fmt, ...) \ printk(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) +#define pr_info_once(fmt, ...) \ + printk_once(KERN_INFO pr_fmt(fmt), ##__VA_ARGS__) #define pr_cont(fmt, ...) \ printk(KERN_CONT fmt, ##__VA_ARGS__) @@ -133,6 +134,7 @@ #define simple_strtoul strtoul #define simple_strtol strtol +#define kstrtol(a,b,c) ({*(c) = strtol(a,0,b);}) #define min(x, y) (x < y ? x : y) #define max(x, y) (x > y ? x : y) diff --git a/sys/ofed/include/linux/ctype.h b/sys/ofed/include/linux/kmod.h index 3ed41379f9ce..1ce17a497f10 100644 --- a/sys/ofed/include/linux/ctype.h +++ b/sys/ofed/include/linux/kmod.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,9 +27,25 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _LINUX_CTYPE_H_ -#define _LINUX_CTYPE_H_ +#ifndef _LINUX_KMOD_H_ +#define _LINUX_KMOD_H_ -#include <sys/ctype.h> +#include <sys/types.h> +#include <sys/syscallsubr.h> +#include <sys/refcount.h> +#include <sys/sbuf.h> +#include <machine/stdarg.h> +#include <sys/proc.h> -#endif /* _LINUX_CTYPE_H_ */ +#define request_module(...) \ +({\ + char modname[128]; \ + int fileid; \ + snprintf(modname, sizeof(modname), __VA_ARGS__); \ + kern_kldload(curthread, modname, &fileid); \ +}) + +#define request_module_nowait request_module + + +#endif /* _LINUX_KMOD_H_ */ diff --git a/sys/ofed/include/linux/kobject.h b/sys/ofed/include/linux/kobject.h index 5872c05e09f4..159f07131720 100644 --- a/sys/ofed/include/linux/kobject.h +++ b/sys/ofed/include/linux/kobject.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -54,6 +55,8 @@ struct kobject { struct sysctl_oid *oidp; }; +extern struct kobject *mm_kobj; + static inline void kobject_init(struct kobject *kobj, struct kobj_type *ktype) { @@ -150,4 +153,17 @@ int kobject_set_name(struct kobject *kobj, const char *fmt, ...); int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype, struct kobject *parent, const char *fmt, ...); +/* sysfs.h calles for 'kobject' which is defined here, + * so we need to add the include only after the 'kobject' def. + */ +#include <linux/sysfs.h> + +struct kobj_attribute { + struct attribute attr; + ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr, + char *buf); + ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr, + const char *buf, size_t count); +}; + #endif /* _LINUX_KOBJECT_H_ */ diff --git a/sys/ofed/include/linux/kref.h b/sys/ofed/include/linux/kref.h index 14346c1941c4..ee94cd0a8784 100644 --- a/sys/ofed/include/linux/kref.h +++ b/sys/ofed/include/linux/kref.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -59,4 +60,4 @@ kref_put(struct kref *kref, void (*rel)(struct kref *kref)) return 0; } -#endif /* _KREF_H_ */ +#endif /* _LINUX_KREF_H_ */ diff --git a/sys/ofed/include/linux/kthread.h b/sys/ofed/include/linux/kthread.h index e288295821df..fb8160d15d24 100644 --- a/sys/ofed/include/linux/kthread.h +++ b/sys/ofed/include/linux/kthread.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/ktime.h b/sys/ofed/include/linux/ktime.h new file mode 100644 index 000000000000..c59c7b9dacd4 --- /dev/null +++ b/sys/ofed/include/linux/ktime.h @@ -0,0 +1,291 @@ +/*- + * Copyright (c) 2014 Mellanox Technologies, Ltd. + * All rights reserved. + * + * 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 unmodified, this list of conditions, and the following + * disclaimer. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#ifndef _LINUX_KTIME_H +#define _LINUX_KTIME_H + +#include <sys/time.h> +#include <linux/types.h> +#include <linux/jiffies.h> + + +/* Get the monotonic time in timespec format: */ +#define ktime_get_ts getnanouptime + +#define NSEC_PER_USEC 1000L +#define NSEC_PER_SEC 1000000000L + +/* + * ktime_t: + * + * On 64-bit CPUs a single 64-bit variable is used to store the hrtimers + * internal representation of time values in scalar nanoseconds. The + * design plays out best on 64-bit CPUs, where most conversions are + * NOPs and most arithmetic ktime_t operations are plain arithmetic + * operations. + * + * On 32-bit CPUs an optimized representation of the timespec structure + * is used to avoid expensive conversions from and to timespecs. The + * endian-aware order of the tv struct members is chosen to allow + * mathematical operations on the tv64 member of the union too, which + * for certain operations produces better code. + * + * For architectures with efficient support for 64/32-bit conversions the + * plain scalar nanosecond based representation can be selected by the + * config switch CONFIG_KTIME_SCALAR. + */ +union ktime { + s64 tv64; +#if BITS_PER_LONG != 64 && !defined(CONFIG_KTIME_SCALAR) + struct { +# ifdef __BIG_ENDIAN + s32 sec, nsec; +# else + s32 nsec, sec; +# endif + } tv; +#endif +}; + +typedef union ktime ktime_t; /* Kill this */ + +#define KTIME_MAX ((s64)~((u64)1 << 63)) +#define KTIME_SEC_MAX (KTIME_MAX / NSEC_PER_SEC) + +/* + * ktime_t definitions when using the 64-bit scalar representation: + */ + +#if (BITS_PER_LONG == 64) || defined(CONFIG_KTIME_SCALAR) + +/** + * ktime_set - Set a ktime_t variable from a seconds/nanoseconds value + * @secs: seconds to set + * @nsecs: nanoseconds to set + * + * Return the ktime_t representation of the value + */ +static inline ktime_t ktime_set(const long secs, const unsigned long nsecs) +{ +#if (BITS_PER_LONG == 64) + if (unlikely(secs >= KTIME_SEC_MAX)) + return (ktime_t){ .tv64 = KTIME_MAX }; +#endif + return (ktime_t) { .tv64 = (s64)secs * NSEC_PER_SEC + (s64)nsecs }; +} + +/* Subtract two ktime_t variables. rem = lhs -rhs: */ +#define ktime_sub(lhs, rhs) \ + ({ (ktime_t){ .tv64 = (lhs).tv64 - (rhs).tv64 }; }) + +/* Add two ktime_t variables. res = lhs + rhs: */ +#define ktime_add(lhs, rhs) \ + ({ (ktime_t){ .tv64 = (lhs).tv64 + (rhs).tv64 }; }) + +/* + * Add a ktime_t variable and a scalar nanosecond value. + * res = kt + nsval: + */ +#define ktime_add_ns(kt, nsval) \ + ({ (ktime_t){ .tv64 = (kt).tv64 + (nsval) }; }) + +/* + * Subtract a scalar nanosecod from a ktime_t variable + * res = kt - nsval: + */ +#define ktime_sub_ns(kt, nsval) \ + ({ (ktime_t){ .tv64 = (kt).tv64 - (nsval) }; }) + +/* convert a timespec to ktime_t format: */ +static inline ktime_t timespec_to_ktime(struct timespec ts) +{ + return ktime_set(ts.tv_sec, ts.tv_nsec); +} + +/* convert a timeval to ktime_t format: */ +static inline ktime_t timeval_to_ktime(struct timeval tv) +{ + return ktime_set(tv.tv_sec, tv.tv_usec * NSEC_PER_USEC); +} + +/* Map the ktime_t to timespec conversion to ns_to_timespec function */ +#define ktime_to_timespec(kt) ns_to_timespec((kt).tv64) + +/* Map the ktime_t to timeval conversion to ns_to_timeval function */ +#define ktime_to_timeval(kt) ns_to_timeval((kt).tv64) + +/* Convert ktime_t to nanoseconds - NOP in the scalar storage format: */ +#define ktime_to_ns(kt) ((kt).tv64) + +#else /* !((BITS_PER_LONG == 64) || defined(CONFIG_KTIME_SCALAR)) */ + +/* + * Helper macros/inlines to get the ktime_t math right in the timespec + * representation. The macros are sometimes ugly - their actual use is + * pretty okay-ish, given the circumstances. We do all this for + * performance reasons. The pure scalar nsec_t based code was nice and + * simple, but created too many 64-bit / 32-bit conversions and divisions. + * + * Be especially aware that negative values are represented in a way + * that the tv.sec field is negative and the tv.nsec field is greater + * or equal to zero but less than nanoseconds per second. This is the + * same representation which is used by timespecs. + * + * tv.sec < 0 and 0 >= tv.nsec < NSEC_PER_SEC + */ + +/* Set a ktime_t variable to a value in sec/nsec representation: */ +static inline ktime_t ktime_set(const long secs, const unsigned long nsecs) +{ + return (ktime_t) { .tv = { .sec = secs, .nsec = nsecs } }; +} + +/** + * ktime_sub - subtract two ktime_t variables + * @lhs: minuend + * @rhs: subtrahend + * + * Returns the remainder of the subtraction + */ +static inline ktime_t ktime_sub(const ktime_t lhs, const ktime_t rhs) +{ + ktime_t res; + + res.tv64 = lhs.tv64 - rhs.tv64; + if (res.tv.nsec < 0) + res.tv.nsec += NSEC_PER_SEC; + + return res; +} + +/** + * ktime_add - add two ktime_t variables + * @add1: addend1 + * @add2: addend2 + * + * Returns the sum of @add1 and @add2. + */ +static inline ktime_t ktime_add(const ktime_t add1, const ktime_t add2) +{ + ktime_t res; + + res.tv64 = add1.tv64 + add2.tv64; + /* + * performance trick: the (u32) -NSEC gives 0x00000000Fxxxxxxx + * so we subtract NSEC_PER_SEC and add 1 to the upper 32 bit. + * + * it's equivalent to: + * tv.nsec -= NSEC_PER_SEC + * tv.sec ++; + */ + if (res.tv.nsec >= NSEC_PER_SEC) + res.tv64 += (u32)-NSEC_PER_SEC; + + return res; +} + +/** + * ktime_add_ns - Add a scalar nanoseconds value to a ktime_t variable + * @kt: addend + * @nsec: the scalar nsec value to add + * + * Returns the sum of @kt and @nsec in ktime_t format + */ +extern ktime_t ktime_add_ns(const ktime_t kt, u64 nsec); + +/** + * ktime_sub_ns - Subtract a scalar nanoseconds value from a ktime_t variable + * @kt: minuend + * @nsec: the scalar nsec value to subtract + * + * Returns the subtraction of @nsec from @kt in ktime_t format + */ +extern ktime_t ktime_sub_ns(const ktime_t kt, u64 nsec); + +/** + * timespec_to_ktime - convert a timespec to ktime_t format + * @ts: the timespec variable to convert + * + * Returns a ktime_t variable with the converted timespec value + */ +static inline ktime_t timespec_to_ktime(const struct timespec ts) +{ + return (ktime_t) { .tv = { .sec = (s32)ts.tv_sec, + .nsec = (s32)ts.tv_nsec } }; +} + +/** + * timeval_to_ktime - convert a timeval to ktime_t format + * @tv: the timeval variable to convert + * + * Returns a ktime_t variable with the converted timeval value + */ +static inline ktime_t timeval_to_ktime(const struct timeval tv) +{ + return (ktime_t) { .tv = { .sec = (s32)tv.tv_sec, + .nsec = (s32)(tv.tv_usec * + NSEC_PER_USEC) } }; +} + +/** + * ktime_to_timespec - convert a ktime_t variable to timespec format + * @kt: the ktime_t variable to convert + * + * Returns the timespec representation of the ktime value + */ +static inline struct timespec ktime_to_timespec(const ktime_t kt) +{ + return (struct timespec) { .tv_sec = (time_t) kt.tv.sec, + .tv_nsec = (long) kt.tv.nsec }; +} + +/** + * ktime_to_timeval - convert a ktime_t variable to timeval format + * @kt: the ktime_t variable to convert + * + * Returns the timeval representation of the ktime value + */ +static inline struct timeval ktime_to_timeval(const ktime_t kt) +{ + return (struct timeval) { + .tv_sec = (time_t) kt.tv.sec, + .tv_usec = (suseconds_t) (kt.tv.nsec / NSEC_PER_USEC) }; +} + +/** + * ktime_to_ns - convert a ktime_t variable to scalar nanoseconds + * @kt: the ktime_t variable to convert + * + * Returns the scalar nanoseconds representation of @kt + */ +static inline s64 ktime_to_ns(const ktime_t kt) +{ + return (s64) kt.tv.sec * NSEC_PER_SEC + kt.tv.nsec; +} + +#endif /* !((BITS_PER_LONG == 64) || defined(CONFIG_KTIME_SCALAR)) */ + +#endif /* _LINUX_KTIME_H */ diff --git a/sys/ofed/include/linux/linux_compat.c b/sys/ofed/include/linux/linux_compat.c index 01c95e8884e8..e8e73c065403 100644 --- a/sys/ofed/include/linux/linux_compat.c +++ b/sys/ofed/include/linux/linux_compat.c @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -160,10 +161,17 @@ kobject_release(struct kref *kref) static void kobject_kfree(struct kobject *kobj) { - kfree(kobj); } +static void +kobject_kfree_name(struct kobject *kobj) +{ + if (kobj) { + kfree(kobj->name); + } +} + struct kobj_type kfree_type = { .release = kobject_kfree }; struct device * @@ -701,3 +709,12 @@ linux_compat_init(void) } SYSINIT(linux_compat, SI_SUB_DRIVERS, SI_ORDER_SECOND, linux_compat_init, NULL); + +static void +linux_compat_uninit(void) +{ + kobject_kfree_name(&class_root); + kobject_kfree_name(&linux_rootdev.kobj); + kobject_kfree_name(&miscclass.kobj); +} +SYSUNINIT(linux_compat, SI_SUB_DRIVERS, SI_ORDER_SECOND, linux_compat_uninit, NULL); diff --git a/sys/ofed/include/linux/linux_idr.c b/sys/ofed/include/linux/linux_idr.c index b6f5d01888d6..0238c8e3c439 100644 --- a/sys/ofed/include/linux/linux_idr.c +++ b/sys/ofed/include/linux/linux_idr.c @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/linux_radix.c b/sys/ofed/include/linux/linux_radix.c index 1e387efb692d..9197b18d3adf 100644 --- a/sys/ofed/include/linux/linux_radix.c +++ b/sys/ofed/include/linux/linux_radix.c @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/list.h b/sys/ofed/include/linux/list.h index f02deadf6c46..2c3628239ab2 100644 --- a/sys/ofed/include/linux/list.h +++ b/sys/ofed/include/linux/list.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -308,6 +309,66 @@ hlist_move_list(struct hlist_head *old, struct hlist_head *new) new->first->pprev = &new->first; old->first = NULL; } + +/** + * list_is_singular - tests whether a list has just one entry. + * @head: the list to test. + */ +static inline int list_is_singular(const struct list_head *head) +{ + return !list_empty(head) && (head->next == head->prev); +} + +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; +} + +/** + * list_cut_position - cut a list into two + * @list: a new list to add all removed entries + * @head: a list with entries + * @entry: an entry within head, could be the head itself + * and if so we won't cut the list + * + * This helper moves the initial part of @head, up to and + * including @entry, from @head to @list. You should + * pass on @entry an element you know is on @head. @list + * should be an empty list or a list you do not care about + * losing its data. + * + */ +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); +} + +/** + * list_is_last - tests whether @list is the last entry in list @head + * @list: the entry to test + * @head: the head of the list + */ +static inline int list_is_last(const struct list_head *list, + const struct list_head *head) +{ + return list->next == head; +} #define hlist_entry(ptr, type, field) container_of(ptr, type, field) @@ -328,9 +389,10 @@ hlist_move_list(struct hlist_head *old, struct hlist_head *new) #define hlist_for_each_entry_from(tp, p, field) \ for (; p ? (tp = hlist_entry(p, typeof(*tp), field)): NULL; p = p->next) -#define hlist_for_each_entry_safe(tp, p, n, head, field) \ - for (p = (head)->first; p ? \ - (n = p->next) | (tp = hlist_entry(p, typeof(*tp), field)) : \ - NULL; p = n) +#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \ + for (pos = (head)->first; \ + (pos) != 0 && ({ n = (pos)->next; \ + tpos = hlist_entry((pos), typeof(*(tpos)), member); 1;}); \ + pos = (n)) #endif /* _LINUX_LIST_H_ */ diff --git a/sys/ofed/include/linux/lockdep.h b/sys/ofed/include/linux/lockdep.h index 8ddb079cb3c8..bdfa6486e0c5 100644 --- a/sys/ofed/include/linux/lockdep.h +++ b/sys/ofed/include/linux/lockdep.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,4 +35,6 @@ struct lock_class_key { #define lockdep_set_class(lock, key) -#endif /* _LINUX_LOCKDEP_H_ */ +#define lockdep_set_class_and_name(lock, key, name) + +#endif /* _LINUX_LOCKDEP_H_ */ diff --git a/sys/ofed/include/linux/log2.h b/sys/ofed/include/linux/log2.h index 8c2a05b64b96..ffc1fdb64cf5 100644 --- a/sys/ofed/include/linux/log2.h +++ b/sys/ofed/include/linux/log2.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/math64.h b/sys/ofed/include/linux/math64.h new file mode 100644 index 000000000000..cc3d946deff9 --- /dev/null +++ b/sys/ofed/include/linux/math64.h @@ -0,0 +1,133 @@ +/*- + * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2014 Mellanox Technologies, Ltd. All rights reserved. + * All rights reserved. + * + * 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 unmodified, this list of conditions, and the following + * disclaimer. + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + */ + +#ifndef _LINUX_MATH64_H +#define _LINUX_MATH64_H + +#include <linux/types.h> +#include <linux/bitops.h> + +#if BITS_PER_LONG == 64 + +# define do_div(n, base) ({ \ + uint32_t __base = (base); \ + uint32_t __rem; \ + __rem = ((uint64_t)(n)) % __base; \ + (n) = ((uint64_t)(n)) / __base; \ + __rem; \ +}) + +/** +* div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder +* +* This is commonly provided by 32bit archs to provide an optimized 64bit +* divide. +*/ +static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder) +{ + *remainder = dividend % divisor; + return dividend / divisor; +} + + +#elif BITS_PER_LONG == 32 + +static uint32_t __div64_32(uint64_t *n, uint32_t base) +{ + uint64_t rem = *n; + uint64_t b = base; + uint64_t res, d = 1; + uint32_t high = rem >> 32; + + /* Reduce the thing a bit first */ + res = 0; + if (high >= base) { + high /= base; + res = (uint64_t) high << 32; + rem -= (uint64_t) (high*base) << 32; + } + + while ((int64_t)b > 0 && b < rem) { + b = b+b; + d = d+d; + } + + do { + if (rem >= b) { + rem -= b; + res += d; + } + b >>= 1; + d >>= 1; + } while (d); + + *n = res; + return rem; +} + +# define do_div(n, base) ({ \ + uint32_t __base = (base); \ + uint32_t __rem; \ + (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \ + if (likely(((n) >> 32) == 0)) { \ + __rem = (uint32_t)(n) % __base; \ + (n) = (uint32_t)(n) / __base; \ + } else \ + __rem = __div64_32(&(n), __base); \ + __rem; \ +}) + +#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 */ + + + +/** + ** div_u64 - unsigned 64bit divide with 32bit divisor + ** + ** This is the most common 64bit divide and should be used if possible, + ** as many 32bit archs can optimize this variant better than a full 64bit + ** divide. + * */ +#ifndef div_u64 + +static inline u64 div_u64(u64 dividend, u32 divisor) +{ + u32 remainder; + return div_u64_rem(dividend, divisor, &remainder); +} +#endif + +#endif /* _LINUX_MATH64_H */ diff --git a/sys/ofed/include/linux/miscdevice.h b/sys/ofed/include/linux/miscdevice.h index e6a443557469..1be903dfd3e2 100644 --- a/sys/ofed/include/linux/miscdevice.h +++ b/sys/ofed/include/linux/miscdevice.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -40,6 +41,8 @@ struct miscdevice { const struct file_operations *fops; struct cdev *cdev; int minor; + const char *nodename; + umode_t mode; }; extern struct class miscclass; diff --git a/sys/ofed/include/linux/mm.h b/sys/ofed/include/linux/mm.h index 13b749bdae15..80d59e8c3a29 100644 --- a/sys/ofed/include/linux/mm.h +++ b/sys/ofed/include/linux/mm.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/module.h b/sys/ofed/include/linux/module.h index fc9d530676dd..da2c4877fc5a 100644 --- a/sys/ofed/include/linux/module.h +++ b/sys/ofed/include/linux/module.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -37,7 +38,10 @@ #define MODULE_AUTHOR(name) #define MODULE_DESCRIPTION(name) #define MODULE_LICENSE(name) -#define MODULE_VERSION(name) + +#ifndef MODULE_VERSION +#define MODULE_VERSION(name) +#endif #define THIS_MODULE ((struct module *)0) @@ -75,15 +79,18 @@ _module_run(void *arg) #define module_init(fn) \ SYSINIT(fn, SI_SUB_OFED_MODINIT, SI_ORDER_FIRST, _module_run, (fn)) +#define module_exit(fn) \ + SYSUNINIT(fn, SI_SUB_OFED_MODINIT, SI_ORDER_SECOND, _module_run, (fn)) + /* - * XXX This is a freebsdism designed to work around not having a module - * load order resolver built in. + * The following two macros are a workaround for not having a module + * load and unload order resolver: */ #define module_init_order(fn, order) \ SYSINIT(fn, SI_SUB_OFED_MODINIT, (order), _module_run, (fn)) -#define module_exit(fn) \ - SYSUNINIT(fn, SI_SUB_OFED_MODINIT, SI_ORDER_FIRST, _module_run, (fn)) +#define module_exit_order(fn, order) \ + SYSUNINIT(fn, SI_SUB_OFED_MODINIT, (order), _module_run, (fn)) #define module_get(module) #define module_put(module) diff --git a/sys/ofed/include/linux/moduleparam.h b/sys/ofed/include/linux/moduleparam.h index e8534c7cdbbb..439237d8630a 100644 --- a/sys/ofed/include/linux/moduleparam.h +++ b/sys/ofed/include/linux/moduleparam.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,6 +26,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + #ifndef _LINUX_MODULEPARAM_H_ #define _LINUX_MODULEPARAM_H_ @@ -81,6 +83,8 @@ param_sysinit(struct kernel_param *param) SYSINIT(name##_param_sysinit, SI_SUB_DRIVERS, SI_ORDER_FIRST, \ param_sysinit, &__param_##name); +#define module_param_string(name, string, len, perm) + #define module_param_named(name, var, type, mode) \ module_param_call(name, param_set_##type, param_get_##type, &var, mode) diff --git a/sys/ofed/include/linux/mount.h b/sys/ofed/include/linux/mount.h index 33db94e477ec..a4451398c62d 100644 --- a/sys/ofed/include/linux/mount.h +++ b/sys/ofed/include/linux/mount.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/mutex.h b/sys/ofed/include/linux/mutex.h index ef658164c383..0ffc72921acb 100644 --- a/sys/ofed/include/linux/mutex.h +++ b/sys/ofed/include/linux/mutex.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/net.h b/sys/ofed/include/linux/net.h index f84dee20919c..db90f94368bc 100644 --- a/sys/ofed/include/linux/net.h +++ b/sys/ofed/include/linux/net.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/netdevice.h b/sys/ofed/include/linux/netdevice.h index b02a9dd6e086..f6165f5f75ef 100644 --- a/sys/ofed/include/linux/netdevice.h +++ b/sys/ofed/include/linux/netdevice.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -97,6 +98,24 @@ _handle_ifnet_departure_event(void *arg, struct ifnet *ifp) nb->notifier_call(nb, NETDEV_UNREGISTER, ifp); } +static inline void +_handle_iflladdr_event(void *arg, struct ifnet *ifp) +{ + struct notifier_block *nb; + + nb = arg; + nb->notifier_call(nb, NETDEV_CHANGEADDR, ifp); +} + +static inline void +_handle_ifaddr_event(void *arg, struct ifnet *ifp) +{ + struct notifier_block *nb; + + nb = arg; + nb->notifier_call(nb, NETDEV_CHANGEIFADDR, ifp); +} + static inline int register_netdevice_notifier(struct notifier_block *nb) { @@ -107,10 +126,22 @@ register_netdevice_notifier(struct notifier_block *nb) ifnet_arrival_event, _handle_ifnet_arrival_event, nb, 0); nb->tags[NETDEV_UNREGISTER] = EVENTHANDLER_REGISTER( ifnet_departure_event, _handle_ifnet_departure_event, nb, 0); + nb->tags[NETDEV_CHANGEADDR] = EVENTHANDLER_REGISTER( + iflladdr_event, _handle_iflladdr_event, nb, 0); + return (0); } static inline int +register_inetaddr_notifier(struct notifier_block *nb) +{ + + nb->tags[NETDEV_CHANGEIFADDR] = EVENTHANDLER_REGISTER( + ifaddr_event, _handle_ifaddr_event, nb, 0); + return (0); +} + +static inline int unregister_netdevice_notifier(struct notifier_block *nb) { @@ -118,9 +149,23 @@ unregister_netdevice_notifier(struct notifier_block *nb) EVENTHANDLER_DEREGISTER(ifnet_arrival_event, nb->tags[NETDEV_REGISTER]); EVENTHANDLER_DEREGISTER(ifnet_departure_event, nb->tags[NETDEV_UNREGISTER]); + EVENTHANDLER_DEREGISTER(iflladdr_event, + nb->tags[NETDEV_CHANGEADDR]); + return (0); } +static inline int +unregister_inetaddr_notifier(struct notifier_block *nb) +{ + + EVENTHANDLER_DEREGISTER(ifaddr_event, + nb->tags[NETDEV_CHANGEIFADDR]); + + return (0); +} + + #define rtnl_lock() #define rtnl_unlock() diff --git a/sys/ofed/include/linux/notifier.h b/sys/ofed/include/linux/notifier.h index eeef8e7035fe..291c26734df8 100644 --- a/sys/ofed/include/linux/notifier.h +++ b/sys/ofed/include/linux/notifier.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,7 +36,7 @@ * Max number of FreeBSD events to map to Linux events per notify type. */ #define NOTIFY_DONE 0 -#define _NOTIFY_COUNT 5 +#define _NOTIFY_COUNT 7 struct notifier_block { int (*notifier_call)(struct notifier_block *, unsigned long, void *); @@ -49,6 +50,8 @@ struct notifier_block { #define NETDEV_DOWN 0x0002 #define NETDEV_REGISTER 0x0003 #define NETDEV_UNREGISTER 0x0004 +#define NETDEV_CHANGEADDR 0x0005 +#define NETDEV_CHANGEIFADDR 0x0006 #endif /* _LINUX_NOTIFIER_H_ */ diff --git a/sys/ofed/include/linux/page.h b/sys/ofed/include/linux/page.h index 748014cc9d81..1ce153161fae 100644 --- a/sys/ofed/include/linux/page.h +++ b/sys/ofed/include/linux/page.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/pci.h b/sys/ofed/include/linux/pci.h index 0948445f8400..fd91a5c7e5f7 100644 --- a/sys/ofed/include/linux/pci.h +++ b/sys/ofed/include/linux/pci.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -43,7 +44,6 @@ #include <machine/resource.h> -#include <linux/init.h> #include <linux/list.h> #include <linux/dmapool.h> #include <linux/dma-mapping.h> @@ -85,10 +85,35 @@ struct pci_device_id { #define to_pci_dev(n) container_of(n, struct pci_dev, dev) -#define PCI_VENDOR_ID PCIR_DEVVENDOR -#define PCI_COMMAND PCIR_COMMAND -#define PCI_EXP_DEVCTL PCIER_DEVICE_CTL -#define PCI_EXP_LNKCTL PCIER_LINK_CTL +#define PCI_VENDOR_ID PCIR_DEVVENDOR +#define PCI_COMMAND PCIR_COMMAND +#define PCI_EXP_DEVCTL PCIER_DEVICE_CTL /* Device Control */ +#define PCI_EXP_LNKCTL PCIER_LINK_CTL /* Link Control */ +#define PCI_EXP_FLAGS_TYPE PCIEM_FLAGS_TYPE /* Device/Port type */ +#define PCI_EXP_DEVCAP PCIER_DEVICE_CAP /* Device capabilities */ +#define PCI_EXP_DEVSTA PCIER_DEVICE_STA /* Device Status */ +#define PCI_EXP_LNKCAP PCIER_LINK_CAP /* Link Capabilities */ +#define PCI_EXP_LNKSTA PCIER_LINK_STA /* Link Status */ +#define PCI_EXP_SLTCAP PCIER_SLOT_CAP /* Slot Capabilities */ +#define PCI_EXP_SLTCTL PCIER_SLOT_CTL /* Slot Control */ +#define PCI_EXP_SLTSTA PCIER_SLOT_STA /* Slot Status */ +#define PCI_EXP_RTCTL PCIER_ROOT_CTL /* Root Control */ +#define PCI_EXP_RTCAP PCIER_ROOT_CAP /* Root Capabilities */ +#define PCI_EXP_RTSTA PCIER_ROOT_STA /* Root Status */ +#define PCI_EXP_DEVCAP2 PCIER_DEVICE_CAP2 /* Device Capabilities 2 */ +#define PCI_EXP_DEVCTL2 PCIER_DEVICE_CTL2 /* Device Control 2 */ +#define PCI_EXP_LNKCAP2 PCIER_LINK_CAP2 /* Link Capabilities 2 */ +#define PCI_EXP_LNKCTL2 PCIER_LINK_CTL2 /* Link Control 2 */ +#define PCI_EXP_LNKSTA2 PCIER_LINK_STA2 /* Link Status 2 */ +#define PCI_EXP_FLAGS PCIER_FLAGS /* Capabilities register */ +#define PCI_EXP_FLAGS_VERS PCIEM_FLAGS_VERSION /* Capability version */ +#define PCI_EXP_TYPE_ROOT_PORT PCIEM_TYPE_ROOT_PORT /* Root Port */ +#define PCI_EXP_TYPE_ENDPOINT PCIEM_TYPE_ENDPOINT /* Express Endpoint */ +#define PCI_EXP_TYPE_LEG_END PCIEM_TYPE_LEGACY_ENDPOINT /* Legacy Endpoint */ +#define PCI_EXP_TYPE_DOWNSTREAM PCIEM_TYPE_DOWNSTREAM_PORT /* Downstream Port */ +#define PCI_EXP_FLAGS_SLOT PCIEM_FLAGS_SLOT /* Slot implemented */ +#define PCI_EXP_TYPE_RC_EC PCIEM_TYPE_ROOT_EC /* Root Complex Event Collector */ + #define IORESOURCE_MEM SYS_RES_MEMORY #define IORESOURCE_IO SYS_RES_IOPORT @@ -100,14 +125,14 @@ struct pci_dev; struct pci_driver { struct list_head links; char *name; - struct pci_device_id *id_table; + const struct pci_device_id *id_table; int (*probe)(struct pci_dev *dev, const struct pci_device_id *id); void (*remove)(struct pci_dev *dev); int (*suspend) (struct pci_dev *dev, pm_message_t state); /* Device suspended */ int (*resume) (struct pci_dev *dev); /* Device woken up */ driver_t driver; devclass_t bsdclass; - struct pci_error_handlers *err_handler; + const struct pci_error_handlers *err_handler; }; extern struct list_head pci_drivers; @@ -386,9 +411,9 @@ pci_write_config_dword(struct pci_dev *pdev, int where, u32 val) } static struct pci_driver * -linux_pci_find(device_t dev, struct pci_device_id **idp) +linux_pci_find(device_t dev, const struct pci_device_id **idp) { - struct pci_device_id *id; + const struct pci_device_id *id; struct pci_driver *pdrv; uint16_t vendor; uint16_t device; @@ -413,7 +438,7 @@ linux_pci_find(device_t dev, struct pci_device_id **idp) static inline int linux_pci_probe(device_t dev) { - struct pci_device_id *id; + const struct pci_device_id *id; struct pci_driver *pdrv; if ((pdrv = linux_pci_find(dev, &id)) == NULL) @@ -430,7 +455,7 @@ linux_pci_attach(device_t dev) struct resource_list_entry *rle; struct pci_dev *pdev; struct pci_driver *pdrv; - struct pci_device_id *id; + const struct pci_device_id *id; int error; pdrv = linux_pci_find(dev, &id); @@ -688,6 +713,122 @@ struct pci_error_handlers { void (*resume)(struct pci_dev *dev); }; +/* freeBSD does not support SRIOV - yet */ +static inline struct pci_dev *pci_physfn(struct pci_dev *dev) +{ + return dev; +} + +static inline bool pci_is_pcie(struct pci_dev *dev) +{ + return !!pci_pcie_cap(dev); +} + +static inline u16 pcie_flags_reg(struct pci_dev *dev) +{ + int pos; + u16 reg16; + + pos = pci_find_capability(dev, PCI_CAP_ID_EXP); + if (!pos) + return 0; + + pci_read_config_word(dev, pos + PCI_EXP_FLAGS, ®16); + + return reg16; +} + + +static inline int pci_pcie_type(struct pci_dev *dev) +{ + return (pcie_flags_reg(dev) & PCI_EXP_FLAGS_TYPE) >> 4; +} + +static inline int pcie_cap_version(struct pci_dev *dev) +{ + return pcie_flags_reg(dev) & PCI_EXP_FLAGS_VERS; +} + +static inline bool pcie_cap_has_lnkctl(struct pci_dev *dev) +{ + int type = pci_pcie_type(dev); + + return pcie_cap_version(dev) > 1 || + type == PCI_EXP_TYPE_ROOT_PORT || + type == PCI_EXP_TYPE_ENDPOINT || + type == PCI_EXP_TYPE_LEG_END; +} + +static inline bool pcie_cap_has_devctl(const struct pci_dev *dev) +{ + return true; +} + +static inline bool pcie_cap_has_sltctl(struct pci_dev *dev) +{ + int type = pci_pcie_type(dev); + + return pcie_cap_version(dev) > 1 || + type == PCI_EXP_TYPE_ROOT_PORT || + (type == PCI_EXP_TYPE_DOWNSTREAM && + pcie_flags_reg(dev) & PCI_EXP_FLAGS_SLOT); +} + +static inline bool pcie_cap_has_rtctl(struct pci_dev *dev) +{ + int type = pci_pcie_type(dev); + + return pcie_cap_version(dev) > 1 || + type == PCI_EXP_TYPE_ROOT_PORT || + type == PCI_EXP_TYPE_RC_EC; +} + +static bool pcie_capability_reg_implemented(struct pci_dev *dev, int pos) +{ + if (!pci_is_pcie(dev)) + return false; + + switch (pos) { + case PCI_EXP_FLAGS_TYPE: + return true; + case PCI_EXP_DEVCAP: + case PCI_EXP_DEVCTL: + case PCI_EXP_DEVSTA: + return pcie_cap_has_devctl(dev); + case PCI_EXP_LNKCAP: + case PCI_EXP_LNKCTL: + case PCI_EXP_LNKSTA: + return pcie_cap_has_lnkctl(dev); + case PCI_EXP_SLTCAP: + case PCI_EXP_SLTCTL: + case PCI_EXP_SLTSTA: + return pcie_cap_has_sltctl(dev); + case PCI_EXP_RTCTL: + case PCI_EXP_RTCAP: + case PCI_EXP_RTSTA: + return pcie_cap_has_rtctl(dev); + case PCI_EXP_DEVCAP2: + case PCI_EXP_DEVCTL2: + case PCI_EXP_LNKCAP2: + case PCI_EXP_LNKCTL2: + case PCI_EXP_LNKSTA2: + return pcie_cap_version(dev) > 1; + default: + return false; + } +} + + +static inline int pcie_capability_write_word(struct pci_dev *dev, int pos, u16 val) +{ + if (pos & 1) + return -EINVAL; + + if (!pcie_capability_reg_implemented(dev, pos)) + return 0; + + return pci_write_config_word(dev, pci_pcie_cap(dev) + pos, val); +} #endif /* _LINUX_PCI_H_ */ diff --git a/sys/ofed/include/linux/poll.h b/sys/ofed/include/linux/poll.h index 5b7f34e67192..79d582c06015 100644 --- a/sys/ofed/include/linux/poll.h +++ b/sys/ofed/include/linux/poll.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/radix-tree.h b/sys/ofed/include/linux/radix-tree.h index a02a90f7458d..444332975fb4 100644 --- a/sys/ofed/include/linux/radix-tree.h +++ b/sys/ofed/include/linux/radix-tree.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/random.h b/sys/ofed/include/linux/random.h index 84a24c8079e3..0dac9faaff61 100644 --- a/sys/ofed/include/linux/random.h +++ b/sys/ofed/include/linux/random.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/rbtree.h b/sys/ofed/include/linux/rbtree.h index ea9afc3fb8d7..d0db2ab47018 100644 --- a/sys/ofed/include/linux/rbtree.h +++ b/sys/ofed/include/linux/rbtree.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/rtnetlink.h b/sys/ofed/include/linux/rtnetlink.h deleted file mode 100644 index e5d814ee3407..000000000000 --- a/sys/ofed/include/linux/rtnetlink.h +++ /dev/null @@ -1,27 +0,0 @@ -/*- - * Copyright (c) 2010 Isilon Systems, Inc. - * Copyright (c) 2010 iX Systems, Inc. - * Copyright (c) 2010 Panasas, Inc. - * All rights reserved. - * - * 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 unmodified, this list of conditions, and the following - * disclaimer. - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - */ diff --git a/sys/ofed/include/linux/rwlock.h b/sys/ofed/include/linux/rwlock.h index 01624558be02..969f93ee2b0a 100644 --- a/sys/ofed/include/linux/rwlock.h +++ b/sys/ofed/include/linux/rwlock.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/rwsem.h b/sys/ofed/include/linux/rwsem.h index f87c9d98809b..d0392e563d1e 100644 --- a/sys/ofed/include/linux/rwsem.h +++ b/sys/ofed/include/linux/rwsem.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/scatterlist.h b/sys/ofed/include/linux/scatterlist.h index 49dc31def1af..eada862e6bc3 100644 --- a/sys/ofed/include/linux/scatterlist.h +++ b/sys/ofed/include/linux/scatterlist.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -25,10 +26,10 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ + #ifndef _LINUX_SCATTERLIST_H_ #define _LINUX_SCATTERLIST_H_ -#include <linux/string.h> #include <linux/page.h> struct scatterlist { @@ -42,6 +43,12 @@ struct scatterlist { uint32_t flags; }; +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_dma_address(sg) (sg)->address #define sg_dma_len(sg) (sg)->length #define sg_page(sg) (sg)->sl_un.page diff --git a/sys/ofed/include/linux/sched.h b/sys/ofed/include/linux/sched.h index 414b0acf2534..da25359456fe 100644 --- a/sys/ofed/include/linux/sched.h +++ b/sys/ofed/include/linux/sched.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/semaphore.h b/sys/ofed/include/linux/semaphore.h index 4b9fd5672ad0..31967a647420 100644 --- a/sys/ofed/include/linux/semaphore.h +++ b/sys/ofed/include/linux/semaphore.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/slab.h b/sys/ofed/include/linux/slab.h index 5e7e608bd867..1d373ce0322e 100644 --- a/sys/ofed/include/linux/slab.h +++ b/sys/ofed/include/linux/slab.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -38,11 +39,16 @@ MALLOC_DECLARE(M_KMALLOC); -#define kmalloc(size, flags) malloc((size), M_KMALLOC, (flags)) -#define kzalloc(size, flags) kmalloc((size), (flags) | M_ZERO) -#define kfree(ptr) free(__DECONST(void *, (ptr)), M_KMALLOC) -#define krealloc(ptr, size, flags) realloc((ptr), (size), M_KMALLOC, (flags)) -#define kcalloc(n, size, flags) kmalloc((n) * (size), flags | M_ZERO) +#define kmalloc(size, flags) malloc((size), M_KMALLOC, (flags)) +#define kzalloc(size, flags) kmalloc((size), (flags) | M_ZERO) +#define kzalloc_node(size, flags, node) kzalloc(size, flags) +#define kfree(ptr) free(__DECONST(void *, (ptr)), M_KMALLOC) +#define krealloc(ptr, size, flags) realloc((ptr), (size), M_KMALLOC, (flags)) +#define kcalloc(n, size, flags) kmalloc((n) * (size), flags | M_ZERO) +#define vzalloc(size) kzalloc(size, GFP_KERNEL | __GFP_NOWARN) +#define vfree(arg) kfree(arg) +#define vmalloc(size) kmalloc(size, GFP_KERNEL) +#define vmalloc_node(size, node) kmalloc(size, GFP_KERNEL) struct kmem_cache { uma_zone_t cache_zone; diff --git a/sys/ofed/include/linux/socket.h b/sys/ofed/include/linux/socket.h index e14c982a818e..a3b0efcaf0af 100644 --- a/sys/ofed/include/linux/socket.h +++ b/sys/ofed/include/linux/socket.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/spinlock.h b/sys/ofed/include/linux/spinlock.h index 4b972f49f2e3..ad709eccc3a0 100644 --- a/sys/ofed/include/linux/spinlock.h +++ b/sys/ofed/include/linux/spinlock.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,7 +36,6 @@ #include <linux/compiler.h> #include <linux/kernel.h> -#include <linux/lockdep.h> #include <linux/rwlock.h> typedef struct { diff --git a/sys/ofed/include/linux/string.h b/sys/ofed/include/linux/string.h index b14a5c684105..710ad0ae09bc 100644 --- a/sys/ofed/include/linux/string.h +++ b/sys/ofed/include/linux/string.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,6 +36,9 @@ #include <sys/libkern.h> +#define strnicmp strncasecmp + + static inline void * kmemdup(const void *src, size_t len, gfp_t gfp) { diff --git a/sys/ofed/include/linux/sysfs.h b/sys/ofed/include/linux/sysfs.h index 3e99f3f13fe7..a4e7d7786a40 100644 --- a/sys/ofed/include/linux/sysfs.h +++ b/sys/ofed/include/linux/sysfs.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/timer.h b/sys/ofed/include/linux/timer.h index a497334d8e3a..7a948d751161 100644 --- a/sys/ofed/include/linux/timer.h +++ b/sys/ofed/include/linux/timer.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -86,4 +87,6 @@ round_jiffies(unsigned long j) return roundup(j, hz); } +#define round_jiffies_relative(j) round_jiffies(j) + #endif /* _LINUX_TIMER_H_ */ diff --git a/sys/ofed/include/linux/types.h b/sys/ofed/include/linux/types.h index 65568ca9e400..9fff0ec919f9 100644 --- a/sys/ofed/include/linux/types.h +++ b/sys/ofed/include/linux/types.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,29 +31,35 @@ #include <sys/cdefs.h> #include <sys/types.h> +#include <sys/param.h> +#include <sys/systm.h> #include <linux/compiler.h> #include <asm/types.h> -typedef __u16 __le16; -typedef __u16 __be16; -typedef __u32 __le32; -typedef __u32 __be32; -typedef __u64 __le64; -typedef __u64 __be64; -#ifndef __bool_true_false_are_defined -typedef _Bool bool; -#define true TRUE -#define false FALSE +#define __read_mostly __attribute__((__section__(".data.read_mostly"))) + +#ifndef __bitwise__ +#ifdef __CHECKER__ +#define __bitwise__ __attribute__((bitwise)) +#else +#define __bitwise__ +#endif #endif -typedef u64 phys_addr_t; +typedef uint16_t __le16; +typedef uint16_t __be16; +typedef uint32_t __le32; +typedef uint32_t __be32; +typedef uint64_t __le64; +typedef uint64_t __be64; -typedef unsigned long kernel_ulong_t; typedef unsigned int uint; typedef unsigned gfp_t; typedef uint64_t loff_t; typedef vm_paddr_t resource_size_t; +typedef u64 phys_addr_t; + #define DECLARE_BITMAP(n, bits) \ unsigned long n[howmany(bits, sizeof(long) * 8)] diff --git a/sys/ofed/include/linux/uaccess.h b/sys/ofed/include/linux/uaccess.h index 9015b1e039d4..6ba34f7025b0 100644 --- a/sys/ofed/include/linux/uaccess.h +++ b/sys/ofed/include/linux/uaccess.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/vmalloc.h b/sys/ofed/include/linux/vmalloc.h index 4a94a5c949bf..1cb208ba3cb2 100644 --- a/sys/ofed/include/linux/vmalloc.h +++ b/sys/ofed/include/linux/vmalloc.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/wait.h b/sys/ofed/include/linux/wait.h index b02014ebba6d..80047f2e5d8b 100644 --- a/sys/ofed/include/linux/wait.h +++ b/sys/ofed/include/linux/wait.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/ofed/include/linux/workqueue.h b/sys/ofed/include/linux/workqueue.h index b895bd32ed20..38cd2feddb60 100644 --- a/sys/ofed/include/linux/workqueue.h +++ b/sys/ofed/include/linux/workqueue.h @@ -2,6 +2,7 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. + * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -90,11 +91,12 @@ do { \ #define flush_scheduled_work() flush_taskqueue(taskqueue_thread) -#define queue_work(q, work) \ -do { \ - (work)->taskqueue = (q)->taskqueue; \ - taskqueue_enqueue((q)->taskqueue, &(work)->work_task); \ -} while (0) +static inline int queue_work (struct workqueue_struct *q, struct work_struct *work) +{ + (work)->taskqueue = (q)->taskqueue; + /* Return opposite val to align with Linux logic */ + return !taskqueue_enqueue((q)->taskqueue, &(work)->work_task); +} static inline void _delayed_work_fn(void *arg) @@ -209,4 +211,13 @@ cancel_delayed_work_sync(struct delayed_work *work) return 0; } +static inline bool +mod_delayed_work(struct workqueue_struct *wq, struct delayed_work *dwork, + unsigned long delay) +{ + cancel_delayed_work(dwork); + queue_delayed_work(wq, dwork, delay); + return false; +} + #endif /* _LINUX_WORKQUEUE_H_ */ |
