From owner-svn-src-all@freebsd.org Mon Oct 19 12:44:42 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5F249A18D37; Mon, 19 Oct 2015 12:44:42 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 38DF7111C; Mon, 19 Oct 2015 12:44:42 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t9JCifue084365; Mon, 19 Oct 2015 12:44:41 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t9JCifFH084363; Mon, 19 Oct 2015 12:44:41 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201510191244.t9JCifFH084363@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Mon, 19 Oct 2015 12:44:41 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r289580 - head/sys/ofed/include/linux X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Oct 2015 12:44:42 -0000 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 +#include 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_ */