Lines Matching refs:kcs

125 static unsigned int init_kcs_data(struct si_sm_data *kcs,  in init_kcs_data()  argument
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()
143 static inline unsigned char read_status(struct si_sm_data *kcs) in read_status() argument
145 return kcs->io->inputb(kcs->io, 1); in read_status()
148 static inline unsigned char read_data(struct si_sm_data *kcs) in read_data() argument
150 return kcs->io->inputb(kcs->io, 0); in read_data()
153 static inline void write_cmd(struct si_sm_data *kcs, unsigned char data) in write_cmd() argument
155 kcs->io->outputb(kcs->io, 1, data); in write_cmd()
158 static inline void write_data(struct si_sm_data *kcs, unsigned char data) in write_data() argument
160 kcs->io->outputb(kcs->io, 0, data); in write_data()
180 static inline void write_next_byte(struct si_sm_data *kcs) in write_next_byte() argument
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()
187 static inline void start_error_recovery(struct si_sm_data *kcs, char *reason) in start_error_recovery() argument
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()
201 static inline void read_next_byte(struct si_sm_data *kcs) in read_next_byte() argument
203 if (kcs->read_pos >= MAX_KCS_READ_SIZE) { in read_next_byte()
205 read_data(kcs); 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()
211 write_data(kcs, KCS_READ_BYTE); in read_next_byte()
214 static inline int check_ibf(struct si_sm_data *kcs, unsigned char status, in check_ibf() argument
218 kcs->ibf_timeout -= time; in check_ibf()
219 if (kcs->ibf_timeout < 0) { in check_ibf()
220 start_error_recovery(kcs, "IBF not ready in time"); in check_ibf()
221 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in check_ibf()
226 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in check_ibf()
230 static inline int check_obf(struct si_sm_data *kcs, unsigned char status, in check_obf() argument
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()
237 start_error_recovery(kcs, "OBF not ready in time"); in check_obf()
242 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in check_obf()
246 static void clear_obf(struct si_sm_data *kcs, unsigned char status) in clear_obf() argument
249 read_data(kcs); in clear_obf()
252 static void restart_kcs_transaction(struct si_sm_data *kcs) in restart_kcs_transaction() argument
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()
260 write_cmd(kcs, KCS_WRITE_START); in restart_kcs_transaction()
263 static int start_kcs_transaction(struct si_sm_data *kcs, unsigned char *data, in start_kcs_transaction() argument
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()
296 static int get_kcs_result(struct si_sm_data *kcs, unsigned char *data, in get_kcs_result() argument
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()
330 static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time) in kcs_event() argument
335 status = read_status(kcs); in kcs_event()
338 dev_dbg(kcs->io->dev, in kcs_event()
339 "KCS: State = %d, %x\n", kcs->state, status); in kcs_event()
342 if (!check_ibf(kcs, status, time)) in kcs_event()
348 switch (kcs->state) { in kcs_event()
351 clear_obf(kcs, status); in kcs_event()
360 start_error_recovery(kcs, in kcs_event()
365 clear_obf(kcs, status); in kcs_event()
366 write_cmd(kcs, KCS_WRITE_START); in kcs_event()
367 kcs->state = KCS_WAIT_WRITE_START; in kcs_event()
373 kcs, in kcs_event()
377 read_data(kcs); in kcs_event()
378 if (kcs->write_count == 1) { in kcs_event()
379 write_cmd(kcs, KCS_WRITE_END); in kcs_event()
380 kcs->state = KCS_WAIT_WRITE_END; in kcs_event()
382 write_next_byte(kcs); in kcs_event()
383 kcs->state = KCS_WAIT_WRITE; in kcs_event()
389 start_error_recovery(kcs, in kcs_event()
393 clear_obf(kcs, status); in kcs_event()
394 if (kcs->write_count == 1) { in kcs_event()
395 write_cmd(kcs, KCS_WRITE_END); in kcs_event()
396 kcs->state = KCS_WAIT_WRITE_END; in kcs_event()
398 write_next_byte(kcs); in kcs_event()
404 start_error_recovery(kcs, in kcs_event()
409 clear_obf(kcs, status); in kcs_event()
410 write_next_byte(kcs); in kcs_event()
411 kcs->state = KCS_WAIT_READ; in kcs_event()
417 kcs, in kcs_event()
423 if (!check_obf(kcs, status, time)) in kcs_event()
425 read_next_byte(kcs); in kcs_event()
436 clear_obf(kcs, status); in kcs_event()
437 kcs->orig_write_count = 0; in kcs_event()
438 kcs->state = KCS_IDLE; in kcs_event()
444 clear_obf(kcs, status); in kcs_event()
445 status = read_status(kcs); in kcs_event()
448 if (time_before(jiffies, kcs->error0_timeout)) in kcs_event()
450 write_cmd(kcs, KCS_GET_STATUS_ABORT); in kcs_event()
451 kcs->state = KCS_ERROR1; in kcs_event()
455 clear_obf(kcs, status); in kcs_event()
456 write_data(kcs, 0); in kcs_event()
457 kcs->state = KCS_ERROR2; in kcs_event()
462 start_error_recovery(kcs, in kcs_event()
466 if (!check_obf(kcs, status, time)) in kcs_event()
469 clear_obf(kcs, status); in kcs_event()
470 write_data(kcs, KCS_READ_BYTE); in kcs_event()
471 kcs->state = KCS_ERROR3; in kcs_event()
476 start_error_recovery(kcs, in kcs_event()
481 if (!check_obf(kcs, status, time)) in kcs_event()
484 clear_obf(kcs, status); in kcs_event()
485 if (kcs->orig_write_count) { in kcs_event()
486 restart_kcs_transaction(kcs); 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()
510 static int kcs_detect(struct si_sm_data *kcs) in kcs_detect() argument
518 if (read_status(kcs) == 0xff) in kcs_detect()
524 static void kcs_cleanup(struct si_sm_data *kcs) in kcs_cleanup() argument