• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _GPXE_RETRY_H
2 #define _GPXE_RETRY_H
3 
4 /** @file
5  *
6  * Retry timers
7  *
8  */
9 
10 FILE_LICENCE ( GPL2_OR_LATER );
11 
12 #include <gpxe/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 };
53 
54 extern void start_timer ( struct retry_timer *timer );
55 extern void start_timer_fixed ( struct retry_timer *timer,
56 				unsigned long timeout );
57 extern void stop_timer ( struct retry_timer *timer );
58 
59 /**
60  * Start timer with no delay
61  *
62  * @v timer		Retry timer
63  *
64  * This starts the timer running with a zero timeout value.
65  */
start_timer_nodelay(struct retry_timer * timer)66 static inline void start_timer_nodelay ( struct retry_timer *timer ) {
67 	start_timer_fixed ( timer, 0 );
68 }
69 
70 /**
71  * Test to see if timer is currently running
72  *
73  * @v timer		Retry timer
74  * @ret running		Non-zero if timer is running
75  */
76 static inline __attribute__ (( always_inline )) unsigned long
timer_running(struct retry_timer * timer)77 timer_running ( struct retry_timer *timer ) {
78 	return ( timer->running );
79 }
80 
81 #endif /* _GPXE_RETRY_H */
82