Lines Matching +full:wait +full:- +full:state
1 // SPDX-License-Identifier: GPL-2.0+
5 * State machine for handling IPMI KCS interfaces.
15 * This state machine is taken from the state machine in the IPMI spec,
30 /* kcs_debug is a bit-field
31 * KCS_DEBUG_ENABLE - turned on for now
32 * KCS_DEBUG_MSG - commands and their responses
33 * KCS_DEBUG_STATES - state machine
51 * was added to the state machine in the spec to wait for the
72 * State to transition to the error handler, this was added to
73 * the state machine in the spec to be sure IBF was there.
78 * First stage error handler, wait for the interface to
84 * The abort cmd has been written, wait for the interface to
90 * We wrote some data to the interface, wait for it to switch
95 /* The hardware failed to follow the state machine. */
109 enum kcs_states state; member
126 struct si_sm_io *io, enum kcs_states state) in init_kcs_data_with_state() argument
128 kcs->state = state; in init_kcs_data_with_state()
129 kcs->io = io; in init_kcs_data_with_state()
130 kcs->write_pos = 0; in init_kcs_data_with_state()
131 kcs->write_count = 0; in init_kcs_data_with_state()
132 kcs->orig_write_count = 0; in init_kcs_data_with_state()
133 kcs->read_pos = 0; in init_kcs_data_with_state()
134 kcs->error_retries = 0; in init_kcs_data_with_state()
135 kcs->truncated = 0; in init_kcs_data_with_state()
136 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in init_kcs_data_with_state()
137 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in init_kcs_data_with_state()
151 return kcs->io->inputb(kcs->io, 1); in read_status()
156 return kcs->io->inputb(kcs->io, 0); in read_data()
161 kcs->io->outputb(kcs->io, 1, data); in write_cmd()
166 kcs->io->outputb(kcs->io, 0, data); in write_data()
188 write_data(kcs, kcs->write_data[kcs->write_pos]); in write_next_byte()
189 (kcs->write_pos)++; in write_next_byte()
190 (kcs->write_count)--; in write_next_byte()
195 (kcs->error_retries)++; in start_error_recovery()
196 if (kcs->error_retries > MAX_ERROR_RETRIES) { in start_error_recovery()
198 dev_dbg(kcs->io->dev, "ipmi_kcs_sm: kcs hosed: %s\n", in start_error_recovery()
200 kcs->state = KCS_HOSED; in start_error_recovery()
202 kcs->error0_timeout = jiffies + ERROR0_OBF_WAIT_JIFFIES; in start_error_recovery()
203 kcs->state = KCS_ERROR0; in start_error_recovery()
209 if (kcs->read_pos >= MAX_KCS_READ_SIZE) { in read_next_byte()
212 kcs->truncated = 1; in read_next_byte()
214 kcs->read_data[kcs->read_pos] = read_data(kcs); in read_next_byte()
215 (kcs->read_pos)++; in read_next_byte()
224 kcs->ibf_timeout -= time; in check_ibf()
225 if (kcs->ibf_timeout < 0) { in check_ibf()
227 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in check_ibf()
232 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in check_ibf()
240 kcs->obf_timeout -= time; in check_obf()
241 if (kcs->obf_timeout < 0) { in check_obf()
242 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in check_obf()
248 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in check_obf()
260 kcs->write_count = kcs->orig_write_count; in restart_kcs_transaction()
261 kcs->write_pos = 0; in restart_kcs_transaction()
262 kcs->read_pos = 0; in restart_kcs_transaction()
263 kcs->state = KCS_WAIT_WRITE_START; in restart_kcs_transaction()
264 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in restart_kcs_transaction()
265 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in restart_kcs_transaction()
279 if (kcs->state != KCS_IDLE) { in start_kcs_transaction()
280 dev_warn(kcs->io->dev, "KCS in invalid state %d\n", kcs->state); in start_kcs_transaction()
285 dev_dbg(kcs->io->dev, "%s -", __func__); in start_kcs_transaction()
290 kcs->error_retries = 0; in start_kcs_transaction()
291 memcpy(kcs->write_data, data, size); in start_kcs_transaction()
292 kcs->write_count = size; in start_kcs_transaction()
293 kcs->orig_write_count = size; in start_kcs_transaction()
294 kcs->write_pos = 0; in start_kcs_transaction()
295 kcs->read_pos = 0; in start_kcs_transaction()
296 kcs->state = KCS_START_OP; in start_kcs_transaction()
297 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in start_kcs_transaction()
298 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in start_kcs_transaction()
305 if (length < kcs->read_pos) { in get_kcs_result()
306 kcs->read_pos = length; in get_kcs_result()
307 kcs->truncated = 1; in get_kcs_result()
310 memcpy(data, kcs->read_data, kcs->read_pos); in get_kcs_result()
312 if ((length >= 3) && (kcs->read_pos < 3)) { in get_kcs_result()
316 kcs->read_pos = 3; in get_kcs_result()
318 if (kcs->truncated) { in get_kcs_result()
325 kcs->truncated = 0; in get_kcs_result()
328 return kcs->read_pos; in get_kcs_result()
332 * This implements the state machine defined in the IPMI manual, see
334 * sections delimited by "Wait for IBF" and this will become clear.
339 unsigned char state; in kcs_event() local
344 dev_dbg(kcs->io->dev, in kcs_event()
345 "KCS: State = %d, %x\n", kcs->state, status); in kcs_event()
347 /* All states wait for ibf, so just do it here. */ in kcs_event()
351 /* Just about everything looks at the KCS state, so grab that, too. */ in kcs_event()
352 state = GET_STATUS_STATE(status); in kcs_event()
354 switch (kcs->state) { in kcs_event()
365 if (state != KCS_IDLE_STATE) { in kcs_event()
367 "State machine not idle at start"); in kcs_event()
373 kcs->state = KCS_WAIT_WRITE_START; in kcs_event()
377 if (state != KCS_WRITE_STATE) { in kcs_event()
380 "Not in write state at write start"); in kcs_event()
384 if (kcs->write_count == 1) { in kcs_event()
386 kcs->state = KCS_WAIT_WRITE_END; in kcs_event()
389 kcs->state = KCS_WAIT_WRITE; in kcs_event()
394 if (state != KCS_WRITE_STATE) { in kcs_event()
396 "Not in write state for write"); in kcs_event()
400 if (kcs->write_count == 1) { in kcs_event()
402 kcs->state = KCS_WAIT_WRITE_END; in kcs_event()
409 if (state != KCS_WRITE_STATE) { in kcs_event()
411 "Not in write state" in kcs_event()
417 kcs->state = KCS_WAIT_READ; in kcs_event()
421 if ((state != KCS_READ_STATE) && (state != KCS_IDLE_STATE)) { in kcs_event()
424 "Not in read or idle in read state"); in kcs_event()
428 if (state == KCS_READ_STATE) { in kcs_event()
434 * We don't implement this exactly like the state in kcs_event()
439 * handle clearing out obf in idle state if it in kcs_event()
443 kcs->orig_write_count = 0; in kcs_event()
444 kcs->state = KCS_IDLE; in kcs_event()
454 if (time_before(jiffies, kcs->error0_timeout)) in kcs_event()
457 kcs->state = KCS_ERROR1; in kcs_event()
463 kcs->state = KCS_ERROR2; in kcs_event()
467 if (state != KCS_READ_STATE) { in kcs_event()
469 "Not in read state for error2"); in kcs_event()
477 kcs->state = KCS_ERROR3; in kcs_event()
481 if (state != KCS_IDLE_STATE) { in kcs_event()
483 "Not in idle state for error3"); in kcs_event()
491 if (kcs->orig_write_count) { in kcs_event()
494 kcs->state = KCS_IDLE; in kcs_event()
503 if (kcs->state == KCS_HOSED) { in kcs_event()
504 init_kcs_data_with_state(kcs, kcs->io, KCS_ERROR0); in kcs_event()
520 * (assuming a properly functioning, self-initialized BMC) in kcs_detect()