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