xref: /OK3568_Linux_fs/kernel/drivers/char/ipmi/ipmi_si_sm.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0+ */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * ipmi_si_sm.h
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * State machine interface for low-level IPMI system management
6*4882a593Smuzhiyun  * interface state machines.  This code is the interface between
7*4882a593Smuzhiyun  * the ipmi_smi code (that handles the policy of a KCS, SMIC, or
8*4882a593Smuzhiyun  * BT interface) and the actual low-level state machine.
9*4882a593Smuzhiyun  *
10*4882a593Smuzhiyun  * Author: MontaVista Software, Inc.
11*4882a593Smuzhiyun  *         Corey Minyard <minyard@mvista.com>
12*4882a593Smuzhiyun  *         source@mvista.com
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * Copyright 2002 MontaVista Software Inc.
15*4882a593Smuzhiyun  */
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun #ifndef __IPMI_SI_SM_H__
18*4882a593Smuzhiyun #define __IPMI_SI_SM_H__
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun #include "ipmi_si.h"
21*4882a593Smuzhiyun 
22*4882a593Smuzhiyun /*
23*4882a593Smuzhiyun  * This is defined by the state machines themselves, it is an opaque
24*4882a593Smuzhiyun  * data type for them to use.
25*4882a593Smuzhiyun  */
26*4882a593Smuzhiyun struct si_sm_data;
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun /* Results of SMI events. */
29*4882a593Smuzhiyun enum si_sm_result {
30*4882a593Smuzhiyun 	SI_SM_CALL_WITHOUT_DELAY, /* Call the driver again immediately */
31*4882a593Smuzhiyun 	SI_SM_CALL_WITH_DELAY,	/* Delay some before calling again. */
32*4882a593Smuzhiyun 	SI_SM_CALL_WITH_TICK_DELAY,/* Delay >=1 tick before calling again. */
33*4882a593Smuzhiyun 	SI_SM_TRANSACTION_COMPLETE, /* A transaction is finished. */
34*4882a593Smuzhiyun 	SI_SM_IDLE,		/* The SM is in idle state. */
35*4882a593Smuzhiyun 	SI_SM_HOSED,		/* The hardware violated the state machine. */
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun 	/*
38*4882a593Smuzhiyun 	 * The hardware is asserting attn and the state machine is
39*4882a593Smuzhiyun 	 * idle.
40*4882a593Smuzhiyun 	 */
41*4882a593Smuzhiyun 	SI_SM_ATTN
42*4882a593Smuzhiyun };
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun /* Handlers for the SMI state machine. */
45*4882a593Smuzhiyun struct si_sm_handlers {
46*4882a593Smuzhiyun 	/*
47*4882a593Smuzhiyun 	 * Put the version number of the state machine here so the
48*4882a593Smuzhiyun 	 * upper layer can print it.
49*4882a593Smuzhiyun 	 */
50*4882a593Smuzhiyun 	char *version;
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun 	/*
53*4882a593Smuzhiyun 	 * Initialize the data and return the amount of I/O space to
54*4882a593Smuzhiyun 	 * reserve for the space.
55*4882a593Smuzhiyun 	 */
56*4882a593Smuzhiyun 	unsigned int (*init_data)(struct si_sm_data *smi,
57*4882a593Smuzhiyun 				  struct si_sm_io   *io);
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun 	/*
60*4882a593Smuzhiyun 	 * Start a new transaction in the state machine.  This will
61*4882a593Smuzhiyun 	 * return -2 if the state machine is not idle, -1 if the size
62*4882a593Smuzhiyun 	 * is invalid (to large or too small), or 0 if the transaction
63*4882a593Smuzhiyun 	 * is successfully completed.
64*4882a593Smuzhiyun 	 */
65*4882a593Smuzhiyun 	int (*start_transaction)(struct si_sm_data *smi,
66*4882a593Smuzhiyun 				 unsigned char *data, unsigned int size);
67*4882a593Smuzhiyun 
68*4882a593Smuzhiyun 	/*
69*4882a593Smuzhiyun 	 * Return the results after the transaction.  This will return
70*4882a593Smuzhiyun 	 * -1 if the buffer is too small, zero if no transaction is
71*4882a593Smuzhiyun 	 * present, or the actual length of the result data.
72*4882a593Smuzhiyun 	 */
73*4882a593Smuzhiyun 	int (*get_result)(struct si_sm_data *smi,
74*4882a593Smuzhiyun 			  unsigned char *data, unsigned int length);
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun 	/*
77*4882a593Smuzhiyun 	 * Call this periodically (for a polled interface) or upon
78*4882a593Smuzhiyun 	 * receiving an interrupt (for a interrupt-driven interface).
79*4882a593Smuzhiyun 	 * If interrupt driven, you should probably poll this
80*4882a593Smuzhiyun 	 * periodically when not in idle state.  This should be called
81*4882a593Smuzhiyun 	 * with the time that passed since the last call, if it is
82*4882a593Smuzhiyun 	 * significant.  Time is in microseconds.
83*4882a593Smuzhiyun 	 */
84*4882a593Smuzhiyun 	enum si_sm_result (*event)(struct si_sm_data *smi, long time);
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun 	/*
87*4882a593Smuzhiyun 	 * Attempt to detect an SMI.  Returns 0 on success or nonzero
88*4882a593Smuzhiyun 	 * on failure.
89*4882a593Smuzhiyun 	 */
90*4882a593Smuzhiyun 	int (*detect)(struct si_sm_data *smi);
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun 	/* The interface is shutting down, so clean it up. */
93*4882a593Smuzhiyun 	void (*cleanup)(struct si_sm_data *smi);
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun 	/* Return the size of the SMI structure in bytes. */
96*4882a593Smuzhiyun 	int (*size)(void);
97*4882a593Smuzhiyun };
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun /* Current state machines that we can use. */
100*4882a593Smuzhiyun extern const struct si_sm_handlers kcs_smi_handlers;
101*4882a593Smuzhiyun extern const struct si_sm_handlers smic_smi_handlers;
102*4882a593Smuzhiyun extern const struct si_sm_handlers bt_smi_handlers;
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun #endif /* __IPMI_SI_SM_H__ */
105