xref: /minix/minix/drivers/net/rtl8139/liveupdate.c (revision 7f5f010b)
1 #include "rtl8139.h"
2 
3 /* State management variables. */
4 EXTERN re_t re_state;
5 
6 /* Custom states definition. */
7 #define RL_STATE_READ_PROTOCOL_FREE     (SEF_LU_STATE_CUSTOM_BASE + 0)
8 #define RL_STATE_WRITE_PROTOCOL_FREE    (SEF_LU_STATE_CUSTOM_BASE + 1)
9 #define RL_STATE_IS_CUSTOM(s) \
10     ((s) >= RL_STATE_READ_PROTOCOL_FREE && (s) <= RL_STATE_WRITE_PROTOCOL_FREE)
11 
12 /* State management helpers. */
13 static int is_reading;
14 static int is_writing;
15 
16 static void load_state_info(void)
17 {
18   re_t *rep;
19 
20   /* Check if we are reading or writing. */
21   rep = &re_state;
22 
23   is_reading = !!(rep->re_flags & REF_READING);
24   is_writing = !!(rep->re_flags & REF_SEND_AVAIL);
25 }
26 
27 /*===========================================================================*
28  *       			 sef_cb_lu_prepare 	 	             *
29  *===========================================================================*/
30 int sef_cb_lu_prepare(int state)
31 {
32   int is_ready;
33 
34   /* Load state information. */
35   load_state_info();
36 
37   /* Check if we are ready for the target state. */
38   is_ready = FALSE;
39   switch(state) {
40       /* Standard states. */
41       case SEF_LU_STATE_REQUEST_FREE:
42           is_ready = TRUE;
43       break;
44 
45       case SEF_LU_STATE_PROTOCOL_FREE:
46           is_ready = (!is_reading && !is_writing);
47       break;
48 
49       /* Custom states. */
50       case RL_STATE_READ_PROTOCOL_FREE:
51           is_ready = (!is_reading);
52       break;
53 
54       case RL_STATE_WRITE_PROTOCOL_FREE:
55           is_ready = (!is_writing);
56       break;
57   }
58 
59   /* Tell SEF if we are ready. */
60   return is_ready ? OK : ENOTREADY;
61 }
62 
63 /*===========================================================================*
64  *      		  sef_cb_lu_state_isvalid		             *
65  *===========================================================================*/
66 int sef_cb_lu_state_isvalid(int state)
67 {
68   return SEF_LU_STATE_IS_STANDARD(state) || RL_STATE_IS_CUSTOM(state);
69 }
70 
71 /*===========================================================================*
72  *      		   sef_cb_lu_state_dump         	             *
73  *===========================================================================*/
74 void sef_cb_lu_state_dump(int state)
75 {
76   /* Load state information. */
77   load_state_info();
78 
79   sef_lu_dprint("rtl8139: live update state = %d\n", state);
80   sef_lu_dprint("rtl8139: is_reading = %d\n", is_reading);
81   sef_lu_dprint("rtl8139: is_writing = %d\n", is_writing);
82 
83   sef_lu_dprint("rtl8139: SEF_LU_STATE_WORK_FREE(%d) reached = %d\n",
84       SEF_LU_STATE_WORK_FREE, TRUE);
85   sef_lu_dprint("rtl8139: SEF_LU_STATE_REQUEST_FREE(%d) reached = %d\n",
86       SEF_LU_STATE_REQUEST_FREE, TRUE);
87   sef_lu_dprint("rtl8139: SEF_LU_STATE_PROTOCOL_FREE(%d) reached = %d\n",
88       SEF_LU_STATE_PROTOCOL_FREE, (!is_reading && !is_writing));
89   sef_lu_dprint("rtl8139: RL_STATE_READ_PROTOCOL_FREE(%d) reached = %d\n",
90       RL_STATE_READ_PROTOCOL_FREE, (!is_reading));
91   sef_lu_dprint("rtl8139: RL_STATE_WRITE_PROTOCOL_FREE(%d) reached = %d\n",
92       RL_STATE_WRITE_PROTOCOL_FREE, (!is_writing));
93 }
94 
95