Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / include / ipxe / retry.h
1 #ifndef _IPXE_RETRY_H
2 #define _IPXE_RETRY_H
3
4 /** @file
5  *
6  * Retry timers
7  *
8  */
9
10 FILE_LICENCE ( GPL2_OR_LATER );
11
12 #include <ipxe/list.h>
13
14 /** Default timeout value */
15 #define DEFAULT_MIN_TIMEOUT ( TICKS_PER_SEC / 4 )
16
17 /** Limit after which the timeout will be deemed permanent */
18 #define DEFAULT_MAX_TIMEOUT ( 10 * TICKS_PER_SEC )
19
20 /** A retry timer */
21 struct retry_timer {
22         /** List of active timers */
23         struct list_head list;
24         /** Timer is currently running */
25         unsigned int running;
26         /** Timeout value (in ticks) */
27         unsigned long timeout;
28         /** Minimum timeout value (in ticks)
29          *
30          * A value of zero means "use default timeout."
31          */
32         unsigned long min_timeout;
33         /** Maximum timeout value before failure (in ticks)
34          *
35          * A value of zero means "use default timeout."
36          */
37         unsigned long max_timeout;
38         /** Start time (in ticks) */
39         unsigned long start;
40         /** Retry count */
41         unsigned int count;
42         /** Timer expired callback
43          *
44          * @v timer     Retry timer
45          * @v fail      Failure indicator
46          *
47          * The timer will already be stopped when this method is
48          * called.  The failure indicator will be True if the retry
49          * timeout has already exceeded @c MAX_TIMEOUT.
50          */
51         void ( * expired ) ( struct retry_timer *timer, int over );
52         /** Reference counter
53          *
54          * If this interface is not part of a reference-counted
55          * object, this field may be NULL.
56          */
57         struct refcnt *refcnt;
58 };
59
60 /**
61  * Initialise a timer
62  *
63  * @v timer             Retry timer
64  * @v expired           Timer expired callback
65  * @v refcnt            Reference counter, or NULL
66  */
67 static inline __attribute__ (( always_inline )) void
68 timer_init ( struct retry_timer *timer,
69              void ( * expired ) ( struct retry_timer *timer, int over ),
70              struct refcnt *refcnt ) {
71         timer->expired = expired;
72         timer->refcnt = refcnt;
73 }
74
75 /**
76  * Initialise a static timer
77  *
78  * @v expired_fn        Timer expired callback
79  */
80 #define TIMER_INIT( expired_fn ) {                      \
81                 .expired = (expired_fn),                \
82         }
83
84 extern void start_timer ( struct retry_timer *timer );
85 extern void start_timer_fixed ( struct retry_timer *timer,
86                                 unsigned long timeout );
87 extern void stop_timer ( struct retry_timer *timer );
88 extern void retry_poll ( void );
89
90 /**
91  * Start timer with no delay
92  *
93  * @v timer             Retry timer
94  *
95  * This starts the timer running with a zero timeout value.
96  */
97 static inline void start_timer_nodelay ( struct retry_timer *timer ) {
98         start_timer_fixed ( timer, 0 );
99 }
100
101 /**
102  * Test to see if timer is currently running
103  *
104  * @v timer             Retry timer
105  * @ret running         Non-zero if timer is running
106  */
107 static inline __attribute__ (( always_inline )) unsigned long
108 timer_running ( struct retry_timer *timer ) {
109         return ( timer->running );
110 }
111
112 #endif /* _IPXE_RETRY_H */