xref: /freebsd/sys/compat/linuxkpi/common/include/linux/timer.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
18d59ecb2SHans Petter Selasky /*-
28d59ecb2SHans Petter Selasky  * Copyright (c) 2010 Isilon Systems, Inc.
38d59ecb2SHans Petter Selasky  * Copyright (c) 2010 iX Systems, Inc.
48d59ecb2SHans Petter Selasky  * Copyright (c) 2010 Panasas, Inc.
58d59ecb2SHans Petter Selasky  * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
68d59ecb2SHans Petter Selasky  * All rights reserved.
78d59ecb2SHans Petter Selasky  *
88d59ecb2SHans Petter Selasky  * Redistribution and use in source and binary forms, with or without
98d59ecb2SHans Petter Selasky  * modification, are permitted provided that the following conditions
108d59ecb2SHans Petter Selasky  * are met:
118d59ecb2SHans Petter Selasky  * 1. Redistributions of source code must retain the above copyright
128d59ecb2SHans Petter Selasky  *    notice unmodified, this list of conditions, and the following
138d59ecb2SHans Petter Selasky  *    disclaimer.
148d59ecb2SHans Petter Selasky  * 2. Redistributions in binary form must reproduce the above copyright
158d59ecb2SHans Petter Selasky  *    notice, this list of conditions and the following disclaimer in the
168d59ecb2SHans Petter Selasky  *    documentation and/or other materials provided with the distribution.
178d59ecb2SHans Petter Selasky  *
188d59ecb2SHans Petter Selasky  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
198d59ecb2SHans Petter Selasky  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
208d59ecb2SHans Petter Selasky  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
218d59ecb2SHans Petter Selasky  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
228d59ecb2SHans Petter Selasky  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
238d59ecb2SHans Petter Selasky  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
248d59ecb2SHans Petter Selasky  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
258d59ecb2SHans Petter Selasky  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
268d59ecb2SHans Petter Selasky  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
278d59ecb2SHans Petter Selasky  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
288d59ecb2SHans Petter Selasky  */
29307f78f3SVladimir Kondratyev #ifndef _LINUXKPI_LINUX_TIMER_H_
30307f78f3SVladimir Kondratyev #define	_LINUXKPI_LINUX_TIMER_H_
318d59ecb2SHans Petter Selasky 
328d59ecb2SHans Petter Selasky #include <linux/types.h>
338d59ecb2SHans Petter Selasky 
348d59ecb2SHans Petter Selasky #include <sys/param.h>
358d59ecb2SHans Petter Selasky #include <sys/kernel.h>
368d59ecb2SHans Petter Selasky #include <sys/callout.h>
378d59ecb2SHans Petter Selasky 
388d59ecb2SHans Petter Selasky struct timer_list {
399555cfd2SHans Petter Selasky 	struct callout callout;
40f446b7caSHans Petter Selasky 	union {
41f446b7caSHans Petter Selasky 		void (*function) (unsigned long);	/* < v4.15 */
42f446b7caSHans Petter Selasky 		void (*function_415) (struct timer_list *);
43f446b7caSHans Petter Selasky 	};
448d59ecb2SHans Petter Selasky 	unsigned long data;
45f6800be3SHans Petter Selasky 	int expires;
468d59ecb2SHans Petter Selasky };
478d59ecb2SHans Petter Selasky 
488d59ecb2SHans Petter Selasky extern unsigned long linux_timer_hz_mask;
498d59ecb2SHans Petter Selasky 
50c0589825SMark Johnston #define	TIMER_IRQSAFE	0x0001
51c0589825SMark Johnston 
52f446b7caSHans Petter Selasky #define	from_timer(var, arg, field)					\
53f446b7caSHans Petter Selasky         container_of(arg, typeof(*(var)), field)
54f446b7caSHans Petter Selasky 
55f446b7caSHans Petter Selasky #define	timer_setup(timer, func, flags) do {				\
56f446b7caSHans Petter Selasky 	CTASSERT(((flags) & ~TIMER_IRQSAFE) == 0);			\
57f446b7caSHans Petter Selasky 	(timer)->function_415 = (func);					\
58f446b7caSHans Petter Selasky 	(timer)->data = (unsigned long)(timer);				\
59f446b7caSHans Petter Selasky 	callout_init(&(timer)->callout, 1);				\
60f446b7caSHans Petter Selasky } while (0)
61f446b7caSHans Petter Selasky 
62c0589825SMark Johnston #define	setup_timer(timer, func, dat) do {				\
638d59ecb2SHans Petter Selasky 	(timer)->function = (func);					\
648d59ecb2SHans Petter Selasky 	(timer)->data = (dat);						\
659555cfd2SHans Petter Selasky 	callout_init(&(timer)->callout, 1);			\
668d59ecb2SHans Petter Selasky } while (0)
678d59ecb2SHans Petter Selasky 
68c0589825SMark Johnston #define	__setup_timer(timer, func, dat, flags) do {			\
69c0589825SMark Johnston 	CTASSERT(((flags) & ~TIMER_IRQSAFE) == 0);			\
70c0589825SMark Johnston 	setup_timer(timer, func, dat);					\
71c0589825SMark Johnston } while (0)
72c0589825SMark Johnston 
73c0589825SMark Johnston #define	init_timer(timer) do {						\
748d59ecb2SHans Petter Selasky 	(timer)->function = NULL;					\
758d59ecb2SHans Petter Selasky 	(timer)->data = 0;						\
769555cfd2SHans Petter Selasky 	callout_init(&(timer)->callout, 1);			\
778d59ecb2SHans Petter Selasky } while (0)
788d59ecb2SHans Petter Selasky 
7942f0f394SEmmanuel Vadot extern int mod_timer(struct timer_list *, int);
808d59ecb2SHans Petter Selasky extern void add_timer(struct timer_list *);
81def277d3SHans Petter Selasky extern void add_timer_on(struct timer_list *, int cpu);
8202927c76SJohannes Lundberg extern int del_timer(struct timer_list *);
8342f0f394SEmmanuel Vadot extern int del_timer_sync(struct timer_list *);
84*2e07e885SBjoern A. Zeeb extern int timer_delete_sync(struct timer_list *);
85*2e07e885SBjoern A. Zeeb extern int timer_shutdown_sync(struct timer_list *);
868d59ecb2SHans Petter Selasky 
879555cfd2SHans Petter Selasky #define	timer_pending(timer)	callout_pending(&(timer)->callout)
888d59ecb2SHans Petter Selasky #define	round_jiffies(j)	\
89f6800be3SHans Petter Selasky 	((int)(((j) + linux_timer_hz_mask) & ~linux_timer_hz_mask))
90c0589825SMark Johnston #define	round_jiffies_relative(j) round_jiffies(j)
91c0589825SMark Johnston #define	round_jiffies_up(j)	round_jiffies(j)
92c0589825SMark Johnston #define	round_jiffies_up_relative(j) round_jiffies_up(j)
938d59ecb2SHans Petter Selasky 
94307f78f3SVladimir Kondratyev #endif					/* _LINUXKPI_LINUX_TIMER_H_ */
95