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
128 kcs->state = KCS_IDLE; in init_kcs_data()
129 kcs->io = io; in init_kcs_data()
130 kcs->write_pos = 0; in init_kcs_data()
131 kcs->write_count = 0; in init_kcs_data()
132 kcs->orig_write_count = 0; in init_kcs_data()
133 kcs->read_pos = 0; in init_kcs_data()
134 kcs->error_retries = 0; in init_kcs_data()
135 kcs->truncated = 0; in init_kcs_data()
136 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in init_kcs_data()
137 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in init_kcs_data()
145 return kcs->io->inputb(kcs->io, 1); in read_status()
150 return kcs->io->inputb(kcs->io, 0); in read_data()
155 kcs->io->outputb(kcs->io, 1, data); in write_cmd()
160 kcs->io->outputb(kcs->io, 0, data); in write_data()
182 write_data(kcs, kcs->write_data[kcs->write_pos]); in write_next_byte()
183 (kcs->write_pos)++; in write_next_byte()
184 (kcs->write_count)--; in write_next_byte()
189 (kcs->error_retries)++; in start_error_recovery()
190 if (kcs->error_retries > MAX_ERROR_RETRIES) { in start_error_recovery()
192 dev_dbg(kcs->io->dev, "ipmi_kcs_sm: kcs hosed: %s\n", in start_error_recovery()
194 kcs->state = KCS_HOSED; in start_error_recovery()
196 kcs->error0_timeout = jiffies + ERROR0_OBF_WAIT_JIFFIES; in start_error_recovery()
197 kcs->state = KCS_ERROR0; in start_error_recovery()
203 if (kcs->read_pos >= MAX_KCS_READ_SIZE) { in read_next_byte()
206 kcs->truncated = 1; in read_next_byte()
208 kcs->read_data[kcs->read_pos] = read_data(kcs); in read_next_byte()
209 (kcs->read_pos)++; in read_next_byte()
218 kcs->ibf_timeout -= time; in check_ibf()
219 if (kcs->ibf_timeout < 0) { in check_ibf()
221 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in check_ibf()
226 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in check_ibf()
234 kcs->obf_timeout -= time; in check_obf()
235 if (kcs->obf_timeout < 0) { in check_obf()
236 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in check_obf()
242 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in check_obf()
254 kcs->write_count = kcs->orig_write_count; in restart_kcs_transaction()
255 kcs->write_pos = 0; in restart_kcs_transaction()
256 kcs->read_pos = 0; in restart_kcs_transaction()
257 kcs->state = KCS_WAIT_WRITE_START; in restart_kcs_transaction()
258 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in restart_kcs_transaction()
259 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in restart_kcs_transaction()
273 if ((kcs->state != KCS_IDLE) && (kcs->state != KCS_HOSED)) { in start_kcs_transaction()
274 dev_warn(kcs->io->dev, "KCS in invalid state %d\n", kcs->state); in start_kcs_transaction()
279 dev_dbg(kcs->io->dev, "%s -", __func__); in start_kcs_transaction()
284 kcs->error_retries = 0; in start_kcs_transaction()
285 memcpy(kcs->write_data, data, size); in start_kcs_transaction()
286 kcs->write_count = size; in start_kcs_transaction()
287 kcs->orig_write_count = size; in start_kcs_transaction()
288 kcs->write_pos = 0; in start_kcs_transaction()
289 kcs->read_pos = 0; in start_kcs_transaction()
290 kcs->state = KCS_START_OP; in start_kcs_transaction()
291 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in start_kcs_transaction()
292 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in start_kcs_transaction()
299 if (length < kcs->read_pos) { in get_kcs_result()
300 kcs->read_pos = length; in get_kcs_result()
301 kcs->truncated = 1; in get_kcs_result()
304 memcpy(data, kcs->read_data, kcs->read_pos); in get_kcs_result()
306 if ((length >= 3) && (kcs->read_pos < 3)) { in get_kcs_result()
310 kcs->read_pos = 3; in get_kcs_result()
312 if (kcs->truncated) { in get_kcs_result()
319 kcs->truncated = 0; in get_kcs_result()
322 return kcs->read_pos; in get_kcs_result()
326 * This implements the state machine defined in the IPMI manual, see
328 * sections delimited by "Wait for IBF" and this will become clear.
333 unsigned char state; in kcs_event() local
338 dev_dbg(kcs->io->dev, in kcs_event()
339 "KCS: State = %d, %x\n", kcs->state, status); in kcs_event()
341 /* All states wait for ibf, so just do it here. */ in kcs_event()
345 /* Just about everything looks at the KCS state, so grab that, too. */ in kcs_event()
346 state = GET_STATUS_STATE(status); in kcs_event()
348 switch (kcs->state) { in kcs_event()
359 if (state != KCS_IDLE_STATE) { in kcs_event()
361 "State machine not idle at start"); in kcs_event()
367 kcs->state = KCS_WAIT_WRITE_START; in kcs_event()
371 if (state != KCS_WRITE_STATE) { in kcs_event()
374 "Not in write state at write start"); in kcs_event()
378 if (kcs->write_count == 1) { in kcs_event()
380 kcs->state = KCS_WAIT_WRITE_END; in kcs_event()
383 kcs->state = KCS_WAIT_WRITE; in kcs_event()
388 if (state != KCS_WRITE_STATE) { in kcs_event()
390 "Not in write state for write"); in kcs_event()
394 if (kcs->write_count == 1) { in kcs_event()
396 kcs->state = KCS_WAIT_WRITE_END; in kcs_event()
403 if (state != KCS_WRITE_STATE) { in kcs_event()
405 "Not in write state" in kcs_event()
411 kcs->state = KCS_WAIT_READ; in kcs_event()
415 if ((state != KCS_READ_STATE) && (state != KCS_IDLE_STATE)) { in kcs_event()
418 "Not in read or idle in read state"); in kcs_event()
422 if (state == KCS_READ_STATE) { in kcs_event()
428 * We don't implement this exactly like the state in kcs_event()
433 * handle clearing out obf in idle state if it in kcs_event()
437 kcs->orig_write_count = 0; in kcs_event()
438 kcs->state = KCS_IDLE; in kcs_event()
448 if (time_before(jiffies, kcs->error0_timeout)) in kcs_event()
451 kcs->state = KCS_ERROR1; in kcs_event()
457 kcs->state = KCS_ERROR2; in kcs_event()
461 if (state != KCS_READ_STATE) { in kcs_event()
463 "Not in read state for error2"); in kcs_event()
471 kcs->state = KCS_ERROR3; in kcs_event()
475 if (state != KCS_IDLE_STATE) { in kcs_event()
477 "Not in idle state for error3"); in kcs_event()
485 if (kcs->orig_write_count) { in kcs_event()
488 kcs->state = KCS_IDLE; in kcs_event()
497 if (kcs->state == KCS_HOSED) { in kcs_event()
498 init_kcs_data(kcs, kcs->io); in kcs_event()
514 * (assuming a properly functioning, self-initialized BMC) in kcs_detect()