Date: Mon, 19 Oct 2015 12:44:41 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r289580 - head/sys/ofed/include/linux Message-ID: <201510191244.t9JCifFH084363@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hselasky Date: Mon Oct 19 12:44:41 2015 New Revision: 289580 URL: https://svnweb.freebsd.org/changeset/base/289580 Log: Merge LinuxKPI changes from DragonflyBSD: - Redefine DIV_ROUND_UP as a function macro taking two arguments instead of none. - Implement more Linux kernel functions related to various forms of DELAY() and basic mathematical operations. Sponsored by: Mellanox Technologies Modified: head/sys/ofed/include/linux/delay.h head/sys/ofed/include/linux/kernel.h Modified: head/sys/ofed/include/linux/delay.h ============================================================================== --- head/sys/ofed/include/linux/delay.h Mon Oct 19 12:33:09 2015 (r289579) +++ head/sys/ofed/include/linux/delay.h Mon Oct 19 12:44:41 2015 (r289580) @@ -2,7 +2,8 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. - * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. + * Copyright (c) 2013-2015 Mellanox Technologies, Ltd. + * Copyright (c) 2014 François Tigeot * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -31,6 +32,7 @@ #define _LINUX_DELAY_H_ #include <linux/jiffies.h> +#include <sys/systm.h> static inline void linux_msleep(int ms) @@ -41,4 +43,25 @@ linux_msleep(int ms) #undef msleep #define msleep linux_msleep +#define udelay(t) DELAY(t) + +static inline void +mdelay(unsigned long msecs) +{ + while (msecs--) + DELAY(1000); +} + +static inline void +ndelay(unsigned long x) +{ + DELAY(howmany(x, 1000)); +} + +static inline void +usleep_range(unsigned long min, unsigned long max) +{ + DELAY(min); +} + #endif /* _LINUX_DELAY_H_ */ Modified: head/sys/ofed/include/linux/kernel.h ============================================================================== --- head/sys/ofed/include/linux/kernel.h Mon Oct 19 12:33:09 2015 (r289579) +++ head/sys/ofed/include/linux/kernel.h Mon Oct 19 12:44:41 2015 (r289580) @@ -2,7 +2,8 @@ * Copyright (c) 2010 Isilon Systems, Inc. * Copyright (c) 2010 iX Systems, Inc. * Copyright (c) 2010 Panasas, Inc. - * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. + * Copyright (c) 2013-2015 Mellanox Technologies, Ltd. + * Copyright (c) 2014-2015 François Tigeot * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -69,7 +70,8 @@ #define ALIGN(x, y) roundup2((x), (y)) #undef PTR_ALIGN #define PTR_ALIGN(p, a) ((__typeof(p))ALIGN((uintptr_t)(p), (a))) -#define DIV_ROUND_UP howmany +#define DIV_ROUND_UP(x, n) howmany(x, n) +#define DIV_ROUND_UP_ULL(x, n) DIV_ROUND_UP((unsigned long long)(x), (n)) #define FIELD_SIZEOF(t, f) sizeof(((t *)0)->f) #define printk(X...) printf(X) @@ -90,9 +92,6 @@ ({ if (0) log(LOG_DEBUG, pr_fmt(fmt), ##__VA_ARGS__); 0; }) #endif -#define udelay(t) DELAY(t) -#define usleep_range(min,max) DELAY(min) - #ifndef pr_fmt #define pr_fmt(fmt) fmt #endif @@ -164,9 +163,16 @@ #define min(x, y) ((x) < (y) ? (x) : (y)) #define max(x, y) ((x) > (y) ? (x) : (y)) + +#define min3(a, b, c) min(a, min(b,c)) +#define max3(a, b, c) max(a, max(b,c)) + #define min_t(type, _x, _y) ((type)(_x) < (type)(_y) ? (type)(_x) : (type)(_y)) #define max_t(type, _x, _y) ((type)(_x) > (type)(_y) ? (type)(_x) : (type)(_y)) +#define clamp_t(type, _x, min, max) min_t(type, max_t(type, _x, min), max) +#define clamp(x, lo, hi) min( max(x,lo), hi) + /* * This looks more complex than it should be. But we need to * get the type for the ~ right in round_down (it needs to be @@ -184,4 +190,28 @@ typedef struct pm_message { int event; } pm_message_t; +/* Swap values of a and b */ +#define swap(a, b) do { \ + typeof(a) _swap_tmp = a; \ + a = b; \ + b = _swap_tmp; \ +} while (0) + +#define DIV_ROUND_CLOSEST(x, divisor) (((x) + ((divisor) / 2)) / (divisor)) + +static inline uintmax_t +mult_frac(uintmax_t x, uintmax_t multiplier, uintmax_t divisor) +{ + uintmax_t q = (x / divisor); + uintmax_t r = (x % divisor); + + return ((q * multiplier) + ((r * multiplier) / divisor)); +} + +static inline int64_t +abs64(int64_t x) +{ + return (x < 0 ? -x : x); +} + #endif /* _LINUX_KERNEL_H_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201510191244.t9JCifFH084363>