162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * ipmi_si_sm.h
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * State machine interface for low-level IPMI system management
662306a36Sopenharmony_ci * interface state machines.  This code is the interface between
762306a36Sopenharmony_ci * the ipmi_smi code (that handles the policy of a KCS, SMIC, or
862306a36Sopenharmony_ci * BT interface) and the actual low-level state machine.
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci * Author: MontaVista Software, Inc.
1162306a36Sopenharmony_ci *         Corey Minyard <minyard@mvista.com>
1262306a36Sopenharmony_ci *         source@mvista.com
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci * Copyright 2002 MontaVista Software Inc.
1562306a36Sopenharmony_ci */
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci#ifndef __IPMI_SI_SM_H__
1862306a36Sopenharmony_ci#define __IPMI_SI_SM_H__
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci#include "ipmi_si.h"
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ci/*
2362306a36Sopenharmony_ci * This is defined by the state machines themselves, it is an opaque
2462306a36Sopenharmony_ci * data type for them to use.
2562306a36Sopenharmony_ci */
2662306a36Sopenharmony_cistruct si_sm_data;
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci/* Results of SMI events. */
2962306a36Sopenharmony_cienum si_sm_result {
3062306a36Sopenharmony_ci	SI_SM_CALL_WITHOUT_DELAY, /* Call the driver again immediately */
3162306a36Sopenharmony_ci	SI_SM_CALL_WITH_DELAY,	/* Delay some before calling again. */
3262306a36Sopenharmony_ci	SI_SM_CALL_WITH_TICK_DELAY,/* Delay >=1 tick before calling again. */
3362306a36Sopenharmony_ci	SI_SM_TRANSACTION_COMPLETE, /* A transaction is finished. */
3462306a36Sopenharmony_ci	SI_SM_IDLE,		/* The SM is in idle state. */
3562306a36Sopenharmony_ci	SI_SM_HOSED,		/* The hardware violated the state machine. */
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci	/*
3862306a36Sopenharmony_ci	 * The hardware is asserting attn and the state machine is
3962306a36Sopenharmony_ci	 * idle.
4062306a36Sopenharmony_ci	 */
4162306a36Sopenharmony_ci	SI_SM_ATTN
4262306a36Sopenharmony_ci};
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ci/* Handlers for the SMI state machine. */
4562306a36Sopenharmony_cistruct si_sm_handlers {
4662306a36Sopenharmony_ci	/*
4762306a36Sopenharmony_ci	 * Put the version number of the state machine here so the
4862306a36Sopenharmony_ci	 * upper layer can print it.
4962306a36Sopenharmony_ci	 */
5062306a36Sopenharmony_ci	char *version;
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci	/*
5362306a36Sopenharmony_ci	 * Initialize the data and return the amount of I/O space to
5462306a36Sopenharmony_ci	 * reserve for the space.
5562306a36Sopenharmony_ci	 */
5662306a36Sopenharmony_ci	unsigned int (*init_data)(struct si_sm_data *smi,
5762306a36Sopenharmony_ci				  struct si_sm_io   *io);
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci	/*
6062306a36Sopenharmony_ci	 * Start a new transaction in the state machine.  This will
6162306a36Sopenharmony_ci	 * return -2 if the state machine is not idle, -1 if the size
6262306a36Sopenharmony_ci	 * is invalid (to large or too small), or 0 if the transaction
6362306a36Sopenharmony_ci	 * is successfully completed.
6462306a36Sopenharmony_ci	 */
6562306a36Sopenharmony_ci	int (*start_transaction)(struct si_sm_data *smi,
6662306a36Sopenharmony_ci				 unsigned char *data, unsigned int size);
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci	/*
6962306a36Sopenharmony_ci	 * Return the results after the transaction.  This will return
7062306a36Sopenharmony_ci	 * -1 if the buffer is too small, zero if no transaction is
7162306a36Sopenharmony_ci	 * present, or the actual length of the result data.
7262306a36Sopenharmony_ci	 */
7362306a36Sopenharmony_ci	int (*get_result)(struct si_sm_data *smi,
7462306a36Sopenharmony_ci			  unsigned char *data, unsigned int length);
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci	/*
7762306a36Sopenharmony_ci	 * Call this periodically (for a polled interface) or upon
7862306a36Sopenharmony_ci	 * receiving an interrupt (for a interrupt-driven interface).
7962306a36Sopenharmony_ci	 * If interrupt driven, you should probably poll this
8062306a36Sopenharmony_ci	 * periodically when not in idle state.  This should be called
8162306a36Sopenharmony_ci	 * with the time that passed since the last call, if it is
8262306a36Sopenharmony_ci	 * significant.  Time is in microseconds.
8362306a36Sopenharmony_ci	 */
8462306a36Sopenharmony_ci	enum si_sm_result (*event)(struct si_sm_data *smi, long time);
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci	/*
8762306a36Sopenharmony_ci	 * Attempt to detect an SMI.  Returns 0 on success or nonzero
8862306a36Sopenharmony_ci	 * on failure.
8962306a36Sopenharmony_ci	 */
9062306a36Sopenharmony_ci	int (*detect)(struct si_sm_data *smi);
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci	/* The interface is shutting down, so clean it up. */
9362306a36Sopenharmony_ci	void (*cleanup)(struct si_sm_data *smi);
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci	/* Return the size of the SMI structure in bytes. */
9662306a36Sopenharmony_ci	int (*size)(void);
9762306a36Sopenharmony_ci};
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci/* Current state machines that we can use. */
10062306a36Sopenharmony_ciextern const struct si_sm_handlers kcs_smi_handlers;
10162306a36Sopenharmony_ciextern const struct si_sm_handlers smic_smi_handlers;
10262306a36Sopenharmony_ciextern const struct si_sm_handlers bt_smi_handlers;
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci#endif /* __IPMI_SI_SM_H__ */
105