Lines Matching refs:kcs
123 static unsigned int init_kcs_data(struct si_sm_data *kcs,
126 kcs->state = KCS_IDLE;
127 kcs->io = io;
128 kcs->write_pos = 0;
129 kcs->write_count = 0;
130 kcs->orig_write_count = 0;
131 kcs->read_pos = 0;
132 kcs->error_retries = 0;
133 kcs->truncated = 0;
134 kcs->ibf_timeout = IBF_RETRY_TIMEOUT;
135 kcs->obf_timeout = OBF_RETRY_TIMEOUT;
141 static inline unsigned char read_status(struct si_sm_data *kcs)
143 return kcs->io->inputb(kcs->io, 1);
146 static inline unsigned char read_data(struct si_sm_data *kcs)
148 return kcs->io->inputb(kcs->io, 0);
151 static inline void write_cmd(struct si_sm_data *kcs, unsigned char data)
153 kcs->io->outputb(kcs->io, 1, data);
156 static inline void write_data(struct si_sm_data *kcs, unsigned char data)
158 kcs->io->outputb(kcs->io, 0, data);
178 static inline void write_next_byte(struct si_sm_data *kcs)
180 write_data(kcs, kcs->write_data[kcs->write_pos]);
181 (kcs->write_pos)++;
182 (kcs->write_count)--;
185 static inline void start_error_recovery(struct si_sm_data *kcs, char *reason)
187 (kcs->error_retries)++;
188 if (kcs->error_retries > MAX_ERROR_RETRIES) {
190 printk(KERN_DEBUG "ipmi_kcs_sm: kcs hosed: %s\n", reason);
191 kcs->state = KCS_HOSED;
193 kcs->error0_timeout = jiffies + ERROR0_OBF_WAIT_JIFFIES;
194 kcs->state = KCS_ERROR0;
198 static inline void read_next_byte(struct si_sm_data *kcs)
200 if (kcs->read_pos >= MAX_KCS_READ_SIZE) {
202 read_data(kcs);
203 kcs->truncated = 1;
205 kcs->read_data[kcs->read_pos] = read_data(kcs);
206 (kcs->read_pos)++;
208 write_data(kcs, KCS_READ_BYTE);
211 static inline int check_ibf(struct si_sm_data *kcs, unsigned char status,
215 kcs->ibf_timeout -= time;
216 if (kcs->ibf_timeout < 0) {
217 start_error_recovery(kcs, "IBF not ready in time");
218 kcs->ibf_timeout = IBF_RETRY_TIMEOUT;
223 kcs->ibf_timeout = IBF_RETRY_TIMEOUT;
227 static inline int check_obf(struct si_sm_data *kcs, unsigned char status,
231 kcs->obf_timeout -= time;
232 if (kcs->obf_timeout < 0) {
233 start_error_recovery(kcs, "OBF not ready in time");
238 kcs->obf_timeout = OBF_RETRY_TIMEOUT;
242 static void clear_obf(struct si_sm_data *kcs, unsigned char status)
245 read_data(kcs);
248 static void restart_kcs_transaction(struct si_sm_data *kcs)
250 kcs->write_count = kcs->orig_write_count;
251 kcs->write_pos = 0;
252 kcs->read_pos = 0;
253 kcs->state = KCS_WAIT_WRITE_START;
254 kcs->ibf_timeout = IBF_RETRY_TIMEOUT;
255 kcs->obf_timeout = OBF_RETRY_TIMEOUT;
256 write_cmd(kcs, KCS_WRITE_START);
259 static int start_kcs_transaction(struct si_sm_data *kcs, unsigned char *data,
269 if ((kcs->state != KCS_IDLE) && (kcs->state != KCS_HOSED))
279 kcs->error_retries = 0;
280 memcpy(kcs->write_data, data, size);
281 kcs->write_count = size;
282 kcs->orig_write_count = size;
283 kcs->write_pos = 0;
284 kcs->read_pos = 0;
285 kcs->state = KCS_START_OP;
286 kcs->ibf_timeout = IBF_RETRY_TIMEOUT;
287 kcs->obf_timeout = OBF_RETRY_TIMEOUT;
291 static int get_kcs_result(struct si_sm_data *kcs, unsigned char *data,
294 if (length < kcs->read_pos) {
295 kcs->read_pos = length;
296 kcs->truncated = 1;
299 memcpy(data, kcs->read_data, kcs->read_pos);
301 if ((length >= 3) && (kcs->read_pos < 3)) {
305 kcs->read_pos = 3;
307 if (kcs->truncated) {
312 kcs->truncated = 0;
315 return kcs->read_pos;
321 static enum si_sm_result kcs_event(struct si_sm_data *kcs, long time)
326 status = read_status(kcs);
329 printk(KERN_DEBUG "KCS: State = %d, %x\n", kcs->state, status);
332 if (!check_ibf(kcs, status, time))
338 switch (kcs->state) {
341 clear_obf(kcs, status);
350 start_error_recovery(kcs,
355 clear_obf(kcs, status);
356 write_cmd(kcs, KCS_WRITE_START);
357 kcs->state = KCS_WAIT_WRITE_START;
363 kcs,
367 read_data(kcs);
368 if (kcs->write_count == 1) {
369 write_cmd(kcs, KCS_WRITE_END);
370 kcs->state = KCS_WAIT_WRITE_END;
372 write_next_byte(kcs);
373 kcs->state = KCS_WAIT_WRITE;
379 start_error_recovery(kcs,
383 clear_obf(kcs, status);
384 if (kcs->write_count == 1) {
385 write_cmd(kcs, KCS_WRITE_END);
386 kcs->state = KCS_WAIT_WRITE_END;
388 write_next_byte(kcs);
394 start_error_recovery(kcs,
398 clear_obf(kcs, status);
399 write_next_byte(kcs);
400 kcs->state = KCS_WAIT_READ;
406 kcs,
412 if (!check_obf(kcs, status, time))
414 read_next_byte(kcs);
423 clear_obf(kcs, status);
424 kcs->orig_write_count = 0;
425 kcs->state = KCS_IDLE;
431 clear_obf(kcs, status);
432 status = read_status(kcs);
434 if (time_before(jiffies, kcs->error0_timeout))
436 write_cmd(kcs, KCS_GET_STATUS_ABORT);
437 kcs->state = KCS_ERROR1;
441 clear_obf(kcs, status);
442 write_data(kcs, 0);
443 kcs->state = KCS_ERROR2;
448 start_error_recovery(kcs,
452 if (!check_obf(kcs, status, time))
455 clear_obf(kcs, status);
456 write_data(kcs, KCS_READ_BYTE);
457 kcs->state = KCS_ERROR3;
462 start_error_recovery(kcs,
467 if (!check_obf(kcs, status, time))
470 clear_obf(kcs, status);
471 if (kcs->orig_write_count) {
472 restart_kcs_transaction(kcs);
474 kcs->state = KCS_IDLE;
483 if (kcs->state == KCS_HOSED) {
484 init_kcs_data(kcs, kcs->io);
496 static int kcs_detect(struct si_sm_data *kcs)
502 if (read_status(kcs) == 0xff)
508 static void kcs_cleanup(struct si_sm_data *kcs)