These changes are the raw update to qemu-2.6.
[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_OR_UBDL );
11
12 #include <ipxe/list.h>
13
14 /** Default minimum timeout value (in ticks) */
15 #define DEFAULT_MIN_TIMEOUT ( TICKS_PER_SEC / 4 )
16
17 /** Default maximum timeout value (in ticks) */
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), or zero to use default
29          *
30          * The timeout will never be reduced below this value.
31          */
32         unsigned long min;
33         /** Maximum timeout value (in ticks), or zero to use default
34          *
35          * The timeout will be deemed permanent (according to the
36          * failure indicator passed to expired()) when it exceeds this
37          * value.
38          */
39         unsigned long max;
40         /** Start time (in ticks) */
41         unsigned long start;
42         /** Retry count */
43         unsigned int count;
44         /** Timer expired callback
45          *
46          * @v timer     Retry timer
47          * @v fail      Failure indicator
48          *
49          * The timer will already be stopped when this method is
50          * called.  The failure indicator will be True if the retry
51          * timeout has already exceeded @c max_timeout.
52          */
53         void ( * expired ) ( struct retry_timer *timer, int over );
54         /** Reference counter
55          *
56          * If this interface is not part of a reference-counted
57          * object, this field may be NULL.
58          */
59         struct refcnt *refcnt;
60 };
61
62 /**
63  * Initialise a timer
64  *
65  * @v timer             Retry timer
66  * @v expired           Timer expired callback
67  * @v refcnt            Reference counter, or NULL
68  */
69 static inline __attribute__ (( always_inline )) void
70 timer_init ( struct retry_timer *timer,
71              void ( * expired ) ( struct retry_timer *timer, int over ),
72              struct refcnt *refcnt ) {
73         timer->expired = expired;
74         timer->refcnt = refcnt;
75 }
76
77 /**
78  * Initialise a static timer
79  *
80  * @v expired_fn        Timer expired callback
81  */
82 #define TIMER_INIT( expired_fn ) {                      \
83                 .expired = (expired_fn),                \
84         }
85
86 extern void start_timer ( struct retry_timer *timer );
87 extern void start_timer_fixed ( struct retry_timer *timer,
88                                 unsigned long timeout );
89 extern void stop_timer ( struct retry_timer *timer );
90 extern void retry_poll ( void );
91
92 /**
93  * Start timer with no delay
94  *
95  * @v timer             Retry timer
96  *
97  * This starts the timer running with a zero timeout value.
98  */
99 static inline void start_timer_nodelay ( struct retry_timer *timer ) {
100         start_timer_fixed ( timer, 0 );
101 }
102
103 /**
104  * Test to see if timer is currently running
105  *
106  * @v timer             Retry timer
107  * @ret running         Non-zero if timer is running
108  */
109 static inline __attribute__ (( always_inline )) unsigned long
110 timer_running ( struct retry_timer *timer ) {
111         return ( timer->running );
112 }
113
114 /**
115  * Set minimum and maximum timeouts
116  *
117  * @v timer             Retry timer
118  * @v min               Minimum timeout (in ticks), or zero to use default
119  * @v max               Maximum timeout (in ticks), or zero to use default
120  */
121 static inline __attribute__ (( always_inline )) void
122 set_timer_limits ( struct retry_timer *timer, unsigned long min,
123                    unsigned long max ) {
124         timer->min = min;
125         timer->max = max;
126 }
127
128 #endif /* _IPXE_RETRY_H */