xref: /minix3/minix/drivers/net/rtl8139/liveupdate.c (revision e1f889d228433d65d3faae8729e4eb0a2fa3338e)
14081bff6SDavid van Moolenbroek /* Code left here for historical purposes only. TODO: move into libnetdriver */
24081bff6SDavid van Moolenbroek 
3433d6423SLionel Sambuc #include "rtl8139.h"
4433d6423SLionel Sambuc 
5433d6423SLionel Sambuc /* State management variables. */
6433d6423SLionel Sambuc EXTERN re_t re_state;
7433d6423SLionel Sambuc 
8433d6423SLionel Sambuc /* Custom states definition. */
9433d6423SLionel Sambuc #define RL_STATE_READ_PROTOCOL_FREE     (SEF_LU_STATE_CUSTOM_BASE + 0)
10433d6423SLionel Sambuc #define RL_STATE_WRITE_PROTOCOL_FREE    (SEF_LU_STATE_CUSTOM_BASE + 1)
11433d6423SLionel Sambuc #define RL_STATE_IS_CUSTOM(s) \
12433d6423SLionel Sambuc     ((s) >= RL_STATE_READ_PROTOCOL_FREE && (s) <= RL_STATE_WRITE_PROTOCOL_FREE)
13433d6423SLionel Sambuc 
14433d6423SLionel Sambuc /* State management helpers. */
15433d6423SLionel Sambuc static int is_reading;
16433d6423SLionel Sambuc static int is_writing;
17433d6423SLionel Sambuc 
load_state_info(void)18433d6423SLionel Sambuc static void load_state_info(void)
19433d6423SLionel Sambuc {
20433d6423SLionel Sambuc   re_t *rep;
21433d6423SLionel Sambuc 
22433d6423SLionel Sambuc   /* Check if we are reading or writing. */
23433d6423SLionel Sambuc   rep = &re_state;
24433d6423SLionel Sambuc 
25433d6423SLionel Sambuc   is_reading = !!(rep->re_flags & REF_READING);
26433d6423SLionel Sambuc   is_writing = !!(rep->re_flags & REF_SEND_AVAIL);
27433d6423SLionel Sambuc }
28433d6423SLionel Sambuc 
29433d6423SLionel Sambuc /*===========================================================================*
30433d6423SLionel Sambuc  *       			 sef_cb_lu_prepare 	 	             *
31433d6423SLionel Sambuc  *===========================================================================*/
sef_cb_lu_prepare(int state)32433d6423SLionel Sambuc int sef_cb_lu_prepare(int state)
33433d6423SLionel Sambuc {
34433d6423SLionel Sambuc   int is_ready;
35433d6423SLionel Sambuc 
36433d6423SLionel Sambuc   /* Load state information. */
37433d6423SLionel Sambuc   load_state_info();
38433d6423SLionel Sambuc 
39433d6423SLionel Sambuc   /* Check if we are ready for the target state. */
40433d6423SLionel Sambuc   is_ready = FALSE;
41433d6423SLionel Sambuc   switch(state) {
42433d6423SLionel Sambuc       /* Standard states. */
43433d6423SLionel Sambuc       case SEF_LU_STATE_REQUEST_FREE:
44433d6423SLionel Sambuc           is_ready = TRUE;
45433d6423SLionel Sambuc       break;
46433d6423SLionel Sambuc 
47433d6423SLionel Sambuc       case SEF_LU_STATE_PROTOCOL_FREE:
48433d6423SLionel Sambuc           is_ready = (!is_reading && !is_writing);
49433d6423SLionel Sambuc       break;
50433d6423SLionel Sambuc 
51433d6423SLionel Sambuc       /* Custom states. */
52433d6423SLionel Sambuc       case RL_STATE_READ_PROTOCOL_FREE:
53433d6423SLionel Sambuc           is_ready = (!is_reading);
54433d6423SLionel Sambuc       break;
55433d6423SLionel Sambuc 
56433d6423SLionel Sambuc       case RL_STATE_WRITE_PROTOCOL_FREE:
57433d6423SLionel Sambuc           is_ready = (!is_writing);
58433d6423SLionel Sambuc       break;
59433d6423SLionel Sambuc   }
60433d6423SLionel Sambuc 
61433d6423SLionel Sambuc   /* Tell SEF if we are ready. */
62433d6423SLionel Sambuc   return is_ready ? OK : ENOTREADY;
63433d6423SLionel Sambuc }
64433d6423SLionel Sambuc 
65433d6423SLionel Sambuc /*===========================================================================*
66433d6423SLionel Sambuc  *      		  sef_cb_lu_state_isvalid		             *
67433d6423SLionel Sambuc  *===========================================================================*/
sef_cb_lu_state_isvalid(int state,int UNUSED (flags))68*e1f889d2SCristiano Giuffrida int sef_cb_lu_state_isvalid(int state, int UNUSED(flags))
69433d6423SLionel Sambuc {
70433d6423SLionel Sambuc   return SEF_LU_STATE_IS_STANDARD(state) || RL_STATE_IS_CUSTOM(state);
71433d6423SLionel Sambuc }
72433d6423SLionel Sambuc 
73433d6423SLionel Sambuc /*===========================================================================*
74433d6423SLionel Sambuc  *      		   sef_cb_lu_state_dump         	             *
75433d6423SLionel Sambuc  *===========================================================================*/
sef_cb_lu_state_dump(int state)76433d6423SLionel Sambuc void sef_cb_lu_state_dump(int state)
77433d6423SLionel Sambuc {
78433d6423SLionel Sambuc   /* Load state information. */
79433d6423SLionel Sambuc   load_state_info();
80433d6423SLionel Sambuc 
81433d6423SLionel Sambuc   sef_lu_dprint("rtl8139: live update state = %d\n", state);
82433d6423SLionel Sambuc   sef_lu_dprint("rtl8139: is_reading = %d\n", is_reading);
83433d6423SLionel Sambuc   sef_lu_dprint("rtl8139: is_writing = %d\n", is_writing);
84433d6423SLionel Sambuc 
85433d6423SLionel Sambuc   sef_lu_dprint("rtl8139: SEF_LU_STATE_WORK_FREE(%d) reached = %d\n",
86433d6423SLionel Sambuc       SEF_LU_STATE_WORK_FREE, TRUE);
87433d6423SLionel Sambuc   sef_lu_dprint("rtl8139: SEF_LU_STATE_REQUEST_FREE(%d) reached = %d\n",
88433d6423SLionel Sambuc       SEF_LU_STATE_REQUEST_FREE, TRUE);
89433d6423SLionel Sambuc   sef_lu_dprint("rtl8139: SEF_LU_STATE_PROTOCOL_FREE(%d) reached = %d\n",
90433d6423SLionel Sambuc       SEF_LU_STATE_PROTOCOL_FREE, (!is_reading && !is_writing));
91433d6423SLionel Sambuc   sef_lu_dprint("rtl8139: RL_STATE_READ_PROTOCOL_FREE(%d) reached = %d\n",
92433d6423SLionel Sambuc       RL_STATE_READ_PROTOCOL_FREE, (!is_reading));
93433d6423SLionel Sambuc   sef_lu_dprint("rtl8139: RL_STATE_WRITE_PROTOCOL_FREE(%d) reached = %d\n",
94433d6423SLionel Sambuc       RL_STATE_WRITE_PROTOCOL_FREE, (!is_writing));
95433d6423SLionel Sambuc }
96433d6423SLionel Sambuc 
97