1*8d59ecb2SHans Petter Selasky /*-
2*8d59ecb2SHans Petter Selasky  * Copyright (c) 2010 Isilon Systems, Inc.
3*8d59ecb2SHans Petter Selasky  * Copyright (c) 2010 iX Systems, Inc.
4*8d59ecb2SHans Petter Selasky  * Copyright (c) 2010 Panasas, Inc.
5*8d59ecb2SHans Petter Selasky  * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
6*8d59ecb2SHans Petter Selasky  * All rights reserved.
7*8d59ecb2SHans Petter Selasky  *
8*8d59ecb2SHans Petter Selasky  * Redistribution and use in source and binary forms, with or without
9*8d59ecb2SHans Petter Selasky  * modification, are permitted provided that the following conditions
10*8d59ecb2SHans Petter Selasky  * are met:
11*8d59ecb2SHans Petter Selasky  * 1. Redistributions of source code must retain the above copyright
12*8d59ecb2SHans Petter Selasky  *    notice unmodified, this list of conditions, and the following
13*8d59ecb2SHans Petter Selasky  *    disclaimer.
14*8d59ecb2SHans Petter Selasky  * 2. Redistributions in binary form must reproduce the above copyright
15*8d59ecb2SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer in the
16*8d59ecb2SHans Petter Selasky  *    documentation and/or other materials provided with the distribution.
17*8d59ecb2SHans Petter Selasky  *
18*8d59ecb2SHans Petter Selasky  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19*8d59ecb2SHans Petter Selasky  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20*8d59ecb2SHans Petter Selasky  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21*8d59ecb2SHans Petter Selasky  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22*8d59ecb2SHans Petter Selasky  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23*8d59ecb2SHans Petter Selasky  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24*8d59ecb2SHans Petter Selasky  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25*8d59ecb2SHans Petter Selasky  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26*8d59ecb2SHans Petter Selasky  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27*8d59ecb2SHans Petter Selasky  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*8d59ecb2SHans Petter Selasky  *
29*8d59ecb2SHans Petter Selasky  * $FreeBSD$
30*8d59ecb2SHans Petter Selasky  */
31*8d59ecb2SHans Petter Selasky #ifndef _LINUX_TIMER_H_
32*8d59ecb2SHans Petter Selasky #define	_LINUX_TIMER_H_
33*8d59ecb2SHans Petter Selasky 
34*8d59ecb2SHans Petter Selasky #include <linux/types.h>
35*8d59ecb2SHans Petter Selasky 
36*8d59ecb2SHans Petter Selasky #include <sys/param.h>
37*8d59ecb2SHans Petter Selasky #include <sys/kernel.h>
38*8d59ecb2SHans Petter Selasky #include <sys/callout.h>
39*8d59ecb2SHans Petter Selasky 
40*8d59ecb2SHans Petter Selasky struct timer_list {
41*8d59ecb2SHans Petter Selasky 	struct callout timer_callout;
42*8d59ecb2SHans Petter Selasky 	void    (*function) (unsigned long);
43*8d59ecb2SHans Petter Selasky 	unsigned long data;
44*8d59ecb2SHans Petter Selasky 	unsigned long expires;
45*8d59ecb2SHans Petter Selasky };
46*8d59ecb2SHans Petter Selasky 
47*8d59ecb2SHans Petter Selasky extern unsigned long linux_timer_hz_mask;
48*8d59ecb2SHans Petter Selasky 
49*8d59ecb2SHans Petter Selasky #define	setup_timer(timer, func, dat)					\
50*8d59ecb2SHans Petter Selasky do {									\
51*8d59ecb2SHans Petter Selasky 	(timer)->function = (func);					\
52*8d59ecb2SHans Petter Selasky 	(timer)->data = (dat);						\
53*8d59ecb2SHans Petter Selasky 	callout_init(&(timer)->timer_callout, 1);			\
54*8d59ecb2SHans Petter Selasky } while (0)
55*8d59ecb2SHans Petter Selasky 
56*8d59ecb2SHans Petter Selasky #define	init_timer(timer)						\
57*8d59ecb2SHans Petter Selasky do {									\
58*8d59ecb2SHans Petter Selasky 	(timer)->function = NULL;					\
59*8d59ecb2SHans Petter Selasky 	(timer)->data = 0;						\
60*8d59ecb2SHans Petter Selasky 	callout_init(&(timer)->timer_callout, 1);			\
61*8d59ecb2SHans Petter Selasky } while (0)
62*8d59ecb2SHans Petter Selasky 
63*8d59ecb2SHans Petter Selasky extern void mod_timer(struct timer_list *, unsigned long);
64*8d59ecb2SHans Petter Selasky extern void add_timer(struct timer_list *);
65*8d59ecb2SHans Petter Selasky 
66*8d59ecb2SHans Petter Selasky #define	del_timer(timer)	callout_stop(&(timer)->timer_callout)
67*8d59ecb2SHans Petter Selasky #define	del_timer_sync(timer)	callout_drain(&(timer)->timer_callout)
68*8d59ecb2SHans Petter Selasky #define	timer_pending(timer)	callout_pending(&(timer)->timer_callout)
69*8d59ecb2SHans Petter Selasky #define	round_jiffies(j) \
70*8d59ecb2SHans Petter Selasky 	((unsigned long)(((j) + linux_timer_hz_mask) & ~linux_timer_hz_mask))
71*8d59ecb2SHans Petter Selasky #define	round_jiffies_relative(j) \
72*8d59ecb2SHans Petter Selasky 	round_jiffies(j)
73*8d59ecb2SHans Petter Selasky 
74*8d59ecb2SHans Petter Selasky #endif					/* _LINUX_TIMER_H_ */
75