Lines Matching refs:kcs
125 static unsigned int init_kcs_data_with_state(struct si_sm_data *kcs, 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()
143 static unsigned int init_kcs_data(struct si_sm_data *kcs, in init_kcs_data() argument
146 return init_kcs_data_with_state(kcs, io, KCS_IDLE); in init_kcs_data()
149 static inline unsigned char read_status(struct si_sm_data *kcs) in read_status() argument
151 return kcs->io->inputb(kcs->io, 1); in read_status()
154 static inline unsigned char read_data(struct si_sm_data *kcs) in read_data() argument
156 return kcs->io->inputb(kcs->io, 0); in read_data()
159 static inline void write_cmd(struct si_sm_data *kcs, unsigned char data) in write_cmd() argument
161 kcs->io->outputb(kcs->io, 1, data); in write_cmd()
164 static inline void write_data(struct si_sm_data *kcs, unsigned char data) in write_data() argument
166 kcs->io->outputb(kcs->io, 0, data); in write_data()
186 static inline void write_next_byte(struct si_sm_data *kcs) in write_next_byte() argument
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()
193 static inline void start_error_recovery(struct si_sm_data *kcs, char *reason) in start_error_recovery() argument
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()
207 static inline void read_next_byte(struct si_sm_data *kcs) in read_next_byte() argument
209 if (kcs->read_pos >= MAX_KCS_READ_SIZE) { in read_next_byte()
211 read_data(kcs); 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()
217 write_data(kcs, KCS_READ_BYTE); in read_next_byte()
220 static inline int check_ibf(struct si_sm_data *kcs, unsigned char status, in check_ibf() argument
224 kcs->ibf_timeout -= time; in check_ibf()
225 if (kcs->ibf_timeout < 0) { in check_ibf()
226 start_error_recovery(kcs, "IBF not ready in time"); in check_ibf()
227 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in check_ibf()
232 kcs->ibf_timeout = IBF_RETRY_TIMEOUT; in check_ibf()
236 static inline int check_obf(struct si_sm_data *kcs, unsigned char status, in check_obf() argument
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()
243 start_error_recovery(kcs, "OBF not ready in time"); in check_obf()
248 kcs->obf_timeout = OBF_RETRY_TIMEOUT; in check_obf()
252 static void clear_obf(struct si_sm_data *kcs, unsigned char status) in clear_obf() argument
255 read_data(kcs); in clear_obf()
258 static void restart_kcs_transaction(struct si_sm_data *kcs) in restart_kcs_transaction() argument
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()
266 write_cmd(kcs, KCS_WRITE_START); in restart_kcs_transaction()
269 static int start_kcs_transaction(struct si_sm_data *kcs, unsigned char *data, in start_kcs_transaction() argument
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()
302 static int get_kcs_result(struct si_sm_data *kcs, unsigned char *data, in get_kcs_result() argument
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()
336 static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time) in kcs_event() argument
341 status = read_status(kcs); in kcs_event()
344 dev_dbg(kcs->io->dev, in kcs_event()
345 "KCS: State = %d, %x\n", kcs->state, status); in kcs_event()
348 if (!check_ibf(kcs, status, time)) in kcs_event()
354 switch (kcs->state) { in kcs_event()
357 clear_obf(kcs, status); in kcs_event()
366 start_error_recovery(kcs, in kcs_event()
371 clear_obf(kcs, status); in kcs_event()
372 write_cmd(kcs, KCS_WRITE_START); in kcs_event()
373 kcs->state = KCS_WAIT_WRITE_START; in kcs_event()
379 kcs, in kcs_event()
383 read_data(kcs); in kcs_event()
384 if (kcs->write_count == 1) { in kcs_event()
385 write_cmd(kcs, KCS_WRITE_END); in kcs_event()
386 kcs->state = KCS_WAIT_WRITE_END; in kcs_event()
388 write_next_byte(kcs); in kcs_event()
389 kcs->state = KCS_WAIT_WRITE; in kcs_event()
395 start_error_recovery(kcs, in kcs_event()
399 clear_obf(kcs, status); in kcs_event()
400 if (kcs->write_count == 1) { in kcs_event()
401 write_cmd(kcs, KCS_WRITE_END); in kcs_event()
402 kcs->state = KCS_WAIT_WRITE_END; in kcs_event()
404 write_next_byte(kcs); in kcs_event()
410 start_error_recovery(kcs, in kcs_event()
415 clear_obf(kcs, status); in kcs_event()
416 write_next_byte(kcs); in kcs_event()
417 kcs->state = KCS_WAIT_READ; in kcs_event()
423 kcs, in kcs_event()
429 if (!check_obf(kcs, status, time)) in kcs_event()
431 read_next_byte(kcs); in kcs_event()
442 clear_obf(kcs, status); in kcs_event()
443 kcs->orig_write_count = 0; in kcs_event()
444 kcs->state = KCS_IDLE; in kcs_event()
450 clear_obf(kcs, status); in kcs_event()
451 status = read_status(kcs); in kcs_event()
454 if (time_before(jiffies, kcs->error0_timeout)) in kcs_event()
456 write_cmd(kcs, KCS_GET_STATUS_ABORT); in kcs_event()
457 kcs->state = KCS_ERROR1; in kcs_event()
461 clear_obf(kcs, status); in kcs_event()
462 write_data(kcs, 0); in kcs_event()
463 kcs->state = KCS_ERROR2; in kcs_event()
468 start_error_recovery(kcs, in kcs_event()
472 if (!check_obf(kcs, status, time)) in kcs_event()
475 clear_obf(kcs, status); in kcs_event()
476 write_data(kcs, KCS_READ_BYTE); in kcs_event()
477 kcs->state = KCS_ERROR3; in kcs_event()
482 start_error_recovery(kcs, in kcs_event()
487 if (!check_obf(kcs, status, time)) in kcs_event()
490 clear_obf(kcs, status); in kcs_event()
491 if (kcs->orig_write_count) { in kcs_event()
492 restart_kcs_transaction(kcs); 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()
516 static int kcs_detect(struct si_sm_data *kcs) in kcs_detect() argument
524 if (read_status(kcs) == 0xff) in kcs_detect()
530 static void kcs_cleanup(struct si_sm_data *kcs) in kcs_cleanup() argument