xref: /openbmc/linux/drivers/char/ipmi/ipmi_si_sm.h (revision 976e3645923bdd2fe7893aae33fd7a21098bfb28)
1243ac210SCorey Minyard /* SPDX-License-Identifier: GPL-2.0+ */
21da177e4SLinus Torvalds /*
31da177e4SLinus Torvalds  * ipmi_si_sm.h
41da177e4SLinus Torvalds  *
51da177e4SLinus Torvalds  * State machine interface for low-level IPMI system management
61da177e4SLinus Torvalds  * interface state machines.  This code is the interface between
71da177e4SLinus Torvalds  * the ipmi_smi code (that handles the policy of a KCS, SMIC, or
81da177e4SLinus Torvalds  * BT interface) and the actual low-level state machine.
91da177e4SLinus Torvalds  *
101da177e4SLinus Torvalds  * Author: MontaVista Software, Inc.
111da177e4SLinus Torvalds  *         Corey Minyard <minyard@mvista.com>
121da177e4SLinus Torvalds  *         source@mvista.com
131da177e4SLinus Torvalds  *
141da177e4SLinus Torvalds  * Copyright 2002 MontaVista Software Inc.
151da177e4SLinus Torvalds  */
161da177e4SLinus Torvalds 
17*104fb25fSCorey Minyard #ifndef __IPMI_SI_SM_H__
18*104fb25fSCorey Minyard #define __IPMI_SI_SM_H__
19*104fb25fSCorey Minyard 
20*104fb25fSCorey Minyard #include "ipmi_si.h"
21910840f2SCorey Minyard 
22c305e3d3SCorey Minyard /*
23c305e3d3SCorey Minyard  * This is defined by the state machines themselves, it is an opaque
24c305e3d3SCorey Minyard  * data type for them to use.
25c305e3d3SCorey Minyard  */
261da177e4SLinus Torvalds struct si_sm_data;
271da177e4SLinus Torvalds 
281da177e4SLinus Torvalds /* Results of SMI events. */
29c305e3d3SCorey Minyard enum si_sm_result {
301da177e4SLinus Torvalds 	SI_SM_CALL_WITHOUT_DELAY, /* Call the driver again immediately */
311da177e4SLinus Torvalds 	SI_SM_CALL_WITH_DELAY,	/* Delay some before calling again. */
32c305e3d3SCorey Minyard 	SI_SM_CALL_WITH_TICK_DELAY,/* Delay >=1 tick before calling again. */
331da177e4SLinus Torvalds 	SI_SM_TRANSACTION_COMPLETE, /* A transaction is finished. */
341da177e4SLinus Torvalds 	SI_SM_IDLE,		/* The SM is in idle state. */
351da177e4SLinus Torvalds 	SI_SM_HOSED,		/* The hardware violated the state machine. */
36c305e3d3SCorey Minyard 
37c305e3d3SCorey Minyard 	/*
38c305e3d3SCorey Minyard 	 * The hardware is asserting attn and the state machine is
39c305e3d3SCorey Minyard 	 * idle.
40c305e3d3SCorey Minyard 	 */
41c305e3d3SCorey Minyard 	SI_SM_ATTN
421da177e4SLinus Torvalds };
431da177e4SLinus Torvalds 
441da177e4SLinus Torvalds /* Handlers for the SMI state machine. */
45c305e3d3SCorey Minyard struct si_sm_handlers {
46c305e3d3SCorey Minyard 	/*
47c305e3d3SCorey Minyard 	 * Put the version number of the state machine here so the
48c305e3d3SCorey Minyard 	 * upper layer can print it.
49c305e3d3SCorey Minyard 	 */
501da177e4SLinus Torvalds 	char *version;
511da177e4SLinus Torvalds 
52c305e3d3SCorey Minyard 	/*
53c305e3d3SCorey Minyard 	 * Initialize the data and return the amount of I/O space to
54c305e3d3SCorey Minyard 	 * reserve for the space.
55c305e3d3SCorey Minyard 	 */
561da177e4SLinus Torvalds 	unsigned int (*init_data)(struct si_sm_data *smi,
571da177e4SLinus Torvalds 				  struct si_sm_io   *io);
581da177e4SLinus Torvalds 
59c305e3d3SCorey Minyard 	/*
60c305e3d3SCorey Minyard 	 * Start a new transaction in the state machine.  This will
61c305e3d3SCorey Minyard 	 * return -2 if the state machine is not idle, -1 if the size
62c305e3d3SCorey Minyard 	 * is invalid (to large or too small), or 0 if the transaction
63c305e3d3SCorey Minyard 	 * is successfully completed.
64c305e3d3SCorey Minyard 	 */
651da177e4SLinus Torvalds 	int (*start_transaction)(struct si_sm_data *smi,
661da177e4SLinus Torvalds 				 unsigned char *data, unsigned int size);
671da177e4SLinus Torvalds 
68c305e3d3SCorey Minyard 	/*
69c305e3d3SCorey Minyard 	 * Return the results after the transaction.  This will return
70c305e3d3SCorey Minyard 	 * -1 if the buffer is too small, zero if no transaction is
71c305e3d3SCorey Minyard 	 * present, or the actual length of the result data.
72c305e3d3SCorey Minyard 	 */
731da177e4SLinus Torvalds 	int (*get_result)(struct si_sm_data *smi,
741da177e4SLinus Torvalds 			  unsigned char *data, unsigned int length);
751da177e4SLinus Torvalds 
76c305e3d3SCorey Minyard 	/*
77c305e3d3SCorey Minyard 	 * Call this periodically (for a polled interface) or upon
78c305e3d3SCorey Minyard 	 * receiving an interrupt (for a interrupt-driven interface).
79c305e3d3SCorey Minyard 	 * If interrupt driven, you should probably poll this
80c305e3d3SCorey Minyard 	 * periodically when not in idle state.  This should be called
81c305e3d3SCorey Minyard 	 * with the time that passed since the last call, if it is
82c305e3d3SCorey Minyard 	 * significant.  Time is in microseconds.
83c305e3d3SCorey Minyard 	 */
841da177e4SLinus Torvalds 	enum si_sm_result (*event)(struct si_sm_data *smi, long time);
851da177e4SLinus Torvalds 
86c305e3d3SCorey Minyard 	/*
87c305e3d3SCorey Minyard 	 * Attempt to detect an SMI.  Returns 0 on success or nonzero
88c305e3d3SCorey Minyard 	 * on failure.
89c305e3d3SCorey Minyard 	 */
901da177e4SLinus Torvalds 	int (*detect)(struct si_sm_data *smi);
911da177e4SLinus Torvalds 
921da177e4SLinus Torvalds 	/* The interface is shutting down, so clean it up. */
931da177e4SLinus Torvalds 	void (*cleanup)(struct si_sm_data *smi);
941da177e4SLinus Torvalds 
951da177e4SLinus Torvalds 	/* Return the size of the SMI structure in bytes. */
961da177e4SLinus Torvalds 	int (*size)(void);
971da177e4SLinus Torvalds };
981da177e4SLinus Torvalds 
991da177e4SLinus Torvalds /* Current state machines that we can use. */
10081d02b7fSCorey Minyard extern const struct si_sm_handlers kcs_smi_handlers;
10181d02b7fSCorey Minyard extern const struct si_sm_handlers smic_smi_handlers;
10281d02b7fSCorey Minyard extern const struct si_sm_handlers bt_smi_handlers;
1031da177e4SLinus Torvalds 
104*104fb25fSCorey Minyard #endif /* __IPMI_SI_SM_H__ */
105