Lines Matching refs:ms

186 static void mesh_done(struct mesh_state *ms, int start_next);
187 static void mesh_interrupt(struct mesh_state *ms);
188 static void cmd_complete(struct mesh_state *ms);
189 static void set_dma_cmds(struct mesh_state *ms, struct scsi_cmnd *cmd);
190 static void halt_dma(struct mesh_state *ms);
191 static void phase_mismatch(struct mesh_state *ms);
213 static void dlog(struct mesh_state *ms, char *fmt, int a) in dlog() argument
215 struct mesh_target *tp = &ms->tgts[ms->conn_tgt]; in dlog()
219 slp = &ms->log[ms->log_ix]; in dlog()
222 tlp->phase = (ms->msgphase << 4) + ms->phase; in dlog()
223 tlp->bs0 = ms->mesh->bus_status0; in dlog()
224 tlp->bs1 = ms->mesh->bus_status1; in dlog()
225 tlp->tgt = ms->conn_tgt; in dlog()
232 if (++ms->log_ix >= N_DBG_SLOG) in dlog()
233 ms->log_ix = 0; in dlog()
234 if (ms->n_log < N_DBG_SLOG) in dlog()
235 ++ms->n_log; in dlog()
238 static void dumplog(struct mesh_state *ms, int t) in dumplog() argument
240 struct mesh_target *tp = &ms->tgts[t]; in dumplog()
264 static void dumpslog(struct mesh_state *ms) in dumpslog() argument
269 if (ms->n_log == 0) in dumpslog()
271 i = ms->log_ix - ms->n_log; in dumpslog()
274 ms->n_log = 0; in dumpslog()
276 lp = &ms->log[i]; in dumpslog()
286 } while (i != ms->log_ix); in dumpslog()
291 static inline void dlog(struct mesh_state *ms, char *fmt, int a) in dlog() argument
293 static inline void dumplog(struct mesh_state *ms, int tgt) in dumplog() argument
295 static inline void dumpslog(struct mesh_state *ms) in dumpslog() argument
303 mesh_dump_regs(struct mesh_state *ms) in mesh_dump_regs() argument
305 volatile struct mesh_regs __iomem *mr = ms->mesh; in mesh_dump_regs()
306 volatile struct dbdma_regs __iomem *md = ms->dma; in mesh_dump_regs()
311 ms, mr, md); in mesh_dump_regs()
323 ms->phase, ms->msgphase, ms->conn_tgt, ms->data_ptr); in mesh_dump_regs()
325 ms->dma_started, ms->dma_count, ms->n_msgout); in mesh_dump_regs()
327 tp = &ms->tgts[t]; in mesh_dump_regs()
348 static void mesh_completed(struct mesh_state *ms, struct scsi_cmnd *cmd) in mesh_completed() argument
358 static void mesh_init(struct mesh_state *ms) in mesh_init() argument
360 volatile struct mesh_regs __iomem *mr = ms->mesh; in mesh_init()
361 volatile struct dbdma_regs __iomem *md = ms->dma; in mesh_init()
374 out_8(&mr->source_id, ms->host->this_id); in mesh_init()
400 ms->phase = idle; in mesh_init()
401 ms->msgphase = msg_none; in mesh_init()
405 static void mesh_start_cmd(struct mesh_state *ms, struct scsi_cmnd *cmd) in mesh_start_cmd() argument
407 volatile struct mesh_regs __iomem *mr = ms->mesh; in mesh_start_cmd()
411 ms->current_req = cmd; in mesh_start_cmd()
412 ms->tgts[id].data_goes_out = cmd->sc_data_direction == DMA_TO_DEVICE; in mesh_start_cmd()
413 ms->tgts[id].current_req = cmd; in mesh_start_cmd()
425 if (ms->dma_started) in mesh_start_cmd()
428 ms->phase = arbitrating; in mesh_start_cmd()
429 ms->msgphase = msg_none; in mesh_start_cmd()
430 ms->data_ptr = 0; in mesh_start_cmd()
431 ms->dma_started = 0; in mesh_start_cmd()
432 ms->n_msgout = 0; in mesh_start_cmd()
433 ms->last_n_msgout = 0; in mesh_start_cmd()
434 ms->expect_reply = 0; in mesh_start_cmd()
435 ms->conn_tgt = id; in mesh_start_cmd()
436 ms->tgts[id].saved_ptr = 0; in mesh_start_cmd()
437 ms->stat = DID_OK; in mesh_start_cmd()
438 ms->aborting = 0; in mesh_start_cmd()
440 ms->tgts[id].n_log = 0; in mesh_start_cmd()
441 dlog(ms, "start cmd=%x", (int) cmd); in mesh_start_cmd()
445 dlog(ms, "about to arb, intr/exc/err/fc=%.8x", in mesh_start_cmd()
457 dlog(ms, "busy b4 arb, intr/exc/err/fc=%.8x", in mesh_start_cmd()
464 dlog(ms, "intr b4 arb, intr/exc/err/fc=%.8x", in mesh_start_cmd()
467 mesh_interrupt(ms); in mesh_start_cmd()
468 if (ms->phase != arbitrating) in mesh_start_cmd()
475 ms->stat = DID_BUS_BUSY; in mesh_start_cmd()
476 ms->phase = idle; in mesh_start_cmd()
477 mesh_done(ms, 0); in mesh_start_cmd()
502 dlog(ms, "intr after disresel, intr/exc/err/fc=%.8x", in mesh_start_cmd()
505 mesh_interrupt(ms); in mesh_start_cmd()
506 if (ms->phase != arbitrating) in mesh_start_cmd()
508 dlog(ms, "after intr after disresel, intr/exc/err/fc=%.8x", in mesh_start_cmd()
520 dlog(ms, "after arb, intr/exc/err/fc=%.8x", in mesh_start_cmd()
525 dlog(ms, "resel? after arb, intr/exc/err/fc=%.8x", in mesh_start_cmd()
536 dlog(ms, "tried reset after arb, intr/exc/err/fc=%.8x", in mesh_start_cmd()
558 static void mesh_start(struct mesh_state *ms) in mesh_start() argument
562 if (ms->phase != idle || ms->current_req != NULL) { in mesh_start()
564 ms->phase, ms); in mesh_start()
568 while (ms->phase == idle) { in mesh_start()
570 for (cmd = ms->request_q; ; cmd = (struct scsi_cmnd *) cmd->host_scribble) { in mesh_start()
573 if (ms->tgts[cmd->device->id].current_req == NULL) in mesh_start()
579 ms->request_q = next; in mesh_start()
583 ms->request_qtail = prev; in mesh_start()
585 mesh_start_cmd(ms, cmd); in mesh_start()
589 static void mesh_done(struct mesh_state *ms, int start_next) in mesh_done() argument
592 struct mesh_target *tp = &ms->tgts[ms->conn_tgt]; in mesh_done()
594 cmd = ms->current_req; in mesh_done()
595 ms->current_req = NULL; in mesh_done()
598 cmd->result = (ms->stat << 16) | cmd->SCp.Status; in mesh_done()
599 if (ms->stat == DID_OK) in mesh_done()
603 cmd->result, ms->data_ptr, scsi_bufflen(cmd)); in mesh_done()
614 cmd->SCp.this_residual -= ms->data_ptr; in mesh_done()
615 mesh_completed(ms, cmd); in mesh_done()
618 out_8(&ms->mesh->sequence, SEQ_ENBRESEL); in mesh_done()
619 mesh_flush_io(ms->mesh); in mesh_done()
621 ms->phase = idle; in mesh_done()
622 mesh_start(ms); in mesh_done()
626 static inline void add_sdtr_msg(struct mesh_state *ms) in add_sdtr_msg() argument
628 int i = ms->n_msgout; in add_sdtr_msg()
630 ms->msgout[i] = EXTENDED_MESSAGE; in add_sdtr_msg()
631 ms->msgout[i+1] = 3; in add_sdtr_msg()
632 ms->msgout[i+2] = EXTENDED_SDTR; in add_sdtr_msg()
633 ms->msgout[i+3] = mesh_sync_period/4; in add_sdtr_msg()
634 ms->msgout[i+4] = (ALLOW_SYNC(ms->conn_tgt)? mesh_sync_offset: 0); in add_sdtr_msg()
635 ms->n_msgout = i + 5; in add_sdtr_msg()
638 static void set_sdtr(struct mesh_state *ms, int period, int offset) in set_sdtr() argument
640 struct mesh_target *tp = &ms->tgts[ms->conn_tgt]; in set_sdtr()
641 volatile struct mesh_regs __iomem *mr = ms->mesh; in set_sdtr()
649 ms->conn_tgt); in set_sdtr()
658 v = (ms->clk_freq / 5000) * period; in set_sdtr()
663 tr = (ms->clk_freq + 250000) / 500000; in set_sdtr()
669 tr = ((ms->clk_freq / (v + 2)) + 199999) / 200000; in set_sdtr()
676 ms->conn_tgt, tr/10, tr%10); in set_sdtr()
679 static void start_phase(struct mesh_state *ms) in start_phase() argument
682 volatile struct mesh_regs __iomem *mr = ms->mesh; in start_phase()
683 volatile struct dbdma_regs __iomem *md = ms->dma; in start_phase()
684 struct scsi_cmnd *cmd = ms->current_req; in start_phase()
685 struct mesh_target *tp = &ms->tgts[ms->conn_tgt]; in start_phase()
687 dlog(ms, "start_phase nmo/exc/fc/seq = %.8x", in start_phase()
688 MKWORD(ms->n_msgout, mr->exception, mr->fifo_count, mr->sequence)); in start_phase()
690 seq = use_active_neg + (ms->n_msgout? SEQ_ATN: 0); in start_phase()
691 switch (ms->msgphase) { in start_phase()
699 ms->n_msgin = 0; in start_phase()
708 if (ms->n_msgout <= 0) { in start_phase()
710 ms->n_msgout); in start_phase()
711 mesh_dump_regs(ms); in start_phase()
712 ms->msgphase = msg_none; in start_phase()
715 if (ALLOW_DEBUG(ms->conn_tgt)) { in start_phase()
717 ms->n_msgout); in start_phase()
718 for (i = 0; i < ms->n_msgout; ++i) in start_phase()
719 printk(" %x", ms->msgout[i]); in start_phase()
722 dlog(ms, "msgout msg=%.8x", MKWORD(ms->n_msgout, ms->msgout[0], in start_phase()
723 ms->msgout[1], ms->msgout[2])); in start_phase()
733 dlog(ms, "bus0 was %.2x explicitly asserting ATN", mr->bus_status0); in start_phase()
740 dlog(ms,"hace: after explicit ATN bus0=%.2x",mr->bus_status0); in start_phase()
742 if (ms->n_msgout == 1) { in start_phase()
749 cmd_complete(ms); in start_phase()
751 out_8(&mr->count_lo, ms->n_msgout - 1); in start_phase()
753 for (i = 0; i < ms->n_msgout - 1; ++i) in start_phase()
754 out_8(&mr->fifo, ms->msgout[i]); in start_phase()
760 ms->msgphase); in start_phase()
763 switch (ms->phase) { in start_phase()
765 out_8(&mr->dest_id, ms->conn_tgt); in start_phase()
785 if (!ms->dma_started) { in start_phase()
786 set_dma_cmds(ms, cmd); in start_phase()
787 out_le32(&md->cmdptr, virt_to_phys(ms->dma_cmds)); in start_phase()
789 ms->dma_started = 1; in start_phase()
791 nb = ms->dma_count; in start_phase()
794 ms->dma_count -= nb; in start_phase()
795 ms->data_ptr += nb; in start_phase()
811 dlog(ms, "enbresel intr/exc/err/fc=%.8x", in start_phase()
818 ms->phase); in start_phase()
819 dumpslog(ms); in start_phase()
824 static inline void get_msgin(struct mesh_state *ms) in get_msgin() argument
826 volatile struct mesh_regs __iomem *mr = ms->mesh; in get_msgin()
831 i = ms->n_msgin; in get_msgin()
832 ms->n_msgin = i + n; in get_msgin()
834 ms->msgin[i++] = in_8(&mr->fifo); in get_msgin()
838 static inline int msgin_length(struct mesh_state *ms) in msgin_length() argument
843 if (ms->n_msgin > 0) { in msgin_length()
844 b = ms->msgin[0]; in msgin_length()
847 n = ms->n_msgin < 2? 2: ms->msgin[1] + 2; in msgin_length()
856 static void reselected(struct mesh_state *ms) in reselected() argument
858 volatile struct mesh_regs __iomem *mr = ms->mesh; in reselected()
863 switch (ms->phase) { in reselected()
867 if ((cmd = ms->current_req) != NULL) { in reselected()
869 cmd->host_scribble = (void *) ms->request_q; in reselected()
870 if (ms->request_q == NULL) in reselected()
871 ms->request_qtail = cmd; in reselected()
872 ms->request_q = cmd; in reselected()
873 tp = &ms->tgts[cmd->device->id]; in reselected()
878 ms->phase = reselecting; in reselected()
879 mesh_done(ms, 0); in reselected()
885 ms->msgphase, ms->phase, ms->conn_tgt); in reselected()
886 dumplog(ms, ms->conn_tgt); in reselected()
887 dumpslog(ms); in reselected()
890 if (ms->dma_started) { in reselected()
892 halt_dma(ms); in reselected()
894 ms->current_req = NULL; in reselected()
895 ms->phase = dataing; in reselected()
896 ms->msgphase = msg_in; in reselected()
897 ms->n_msgout = 0; in reselected()
898 ms->last_n_msgout = 0; in reselected()
899 prev = ms->conn_tgt; in reselected()
913 dlog(ms, "extra resel err/exc/fc = %.6x", in reselected()
929 ms->conn_tgt = ms->host->this_id; in reselected()
935 dlog(ms, "reseldata %x", b); in reselected()
938 if ((b & (1 << t)) != 0 && t != ms->host->this_id) in reselected()
940 if (b != (1 << t) + (1 << ms->host->this_id)) { in reselected()
942 ms->conn_tgt = ms->host->this_id; in reselected()
950 ms->conn_tgt = t; in reselected()
951 tp = &ms->tgts[t]; in reselected()
958 ms->current_req = tp->current_req; in reselected()
963 ms->data_ptr = tp->saved_ptr; in reselected()
964 dlog(ms, "resel prev tgt=%d", prev); in reselected()
965 dlog(ms, "resel err/exc=%.4x", MKWORD(0, 0, mr->error, mr->exception)); in reselected()
966 start_phase(ms); in reselected()
970 dumplog(ms, ms->conn_tgt); in reselected()
971 dumpslog(ms); in reselected()
972 ms->data_ptr = 0; in reselected()
973 ms->aborting = 1; in reselected()
974 start_phase(ms); in reselected()
977 static void do_abort(struct mesh_state *ms) in do_abort() argument
979 ms->msgout[0] = ABORT; in do_abort()
980 ms->n_msgout = 1; in do_abort()
981 ms->aborting = 1; in do_abort()
982 ms->stat = DID_ABORT; in do_abort()
983 dlog(ms, "abort", 0); in do_abort()
986 static void handle_reset(struct mesh_state *ms) in handle_reset() argument
991 volatile struct mesh_regs __iomem *mr = ms->mesh; in handle_reset()
994 tp = &ms->tgts[tgt]; in handle_reset()
998 mesh_completed(ms, cmd); in handle_reset()
1000 ms->tgts[tgt].sdtr_state = do_sdtr; in handle_reset()
1001 ms->tgts[tgt].sync_params = ASYNC_PARAMS; in handle_reset()
1003 ms->current_req = NULL; in handle_reset()
1004 while ((cmd = ms->request_q) != NULL) { in handle_reset()
1005 ms->request_q = (struct scsi_cmnd *) cmd->host_scribble; in handle_reset()
1007 mesh_completed(ms, cmd); in handle_reset()
1009 ms->phase = idle; in handle_reset()
1010 ms->msgphase = msg_none; in handle_reset()
1022 struct mesh_state *ms = dev_id; in do_mesh_interrupt() local
1023 struct Scsi_Host *dev = ms->host; in do_mesh_interrupt()
1026 mesh_interrupt(ms); in do_mesh_interrupt()
1031 static void handle_error(struct mesh_state *ms) in handle_error() argument
1034 volatile struct mesh_regs __iomem *mr = ms->mesh; in handle_error()
1039 dlog(ms, "error err/exc/fc/cl=%.8x", in handle_error()
1048 handle_reset(ms); in handle_error()
1055 reselected(ms); in handle_error()
1058 if (!ms->aborting) { in handle_error()
1060 ms->conn_tgt); in handle_error()
1061 dumplog(ms, ms->conn_tgt); in handle_error()
1062 dumpslog(ms); in handle_error()
1065 ms->stat = DID_ABORT; in handle_error()
1066 mesh_done(ms, 1); in handle_error()
1070 if (ms->msgphase == msg_in) { in handle_error()
1072 ms->conn_tgt); in handle_error()
1073 ms->msgout[0] = MSG_PARITY_ERROR; in handle_error()
1074 ms->n_msgout = 1; in handle_error()
1075 ms->msgphase = msg_in_bad; in handle_error()
1076 cmd_complete(ms); in handle_error()
1079 if (ms->stat == DID_OK) { in handle_error()
1081 ms->conn_tgt); in handle_error()
1082 ms->stat = DID_PARITY; in handle_error()
1086 cmd_complete(ms); in handle_error()
1099 reselected(ms); in handle_error()
1105 phase_mismatch(ms); in handle_error()
1113 mesh_dump_regs(ms); in handle_error()
1114 dumplog(ms, ms->conn_tgt); in handle_error()
1115 if (ms->phase > selecting && (in_8(&mr->bus_status1) & BS1_BSY)) { in handle_error()
1117 do_abort(ms); in handle_error()
1118 phase_mismatch(ms); in handle_error()
1121 ms->stat = DID_ERROR; in handle_error()
1122 mesh_done(ms, 1); in handle_error()
1125 static void handle_exception(struct mesh_state *ms) in handle_exception() argument
1128 volatile struct mesh_regs __iomem *mr = ms->mesh; in handle_exception()
1135 reselected(ms); in handle_exception()
1138 ms->stat = DID_BUS_BUSY; in handle_exception()
1139 mesh_done(ms, 1); in handle_exception()
1142 ms->stat = DID_BAD_TARGET; in handle_exception()
1143 mesh_done(ms, 1); in handle_exception()
1147 phase_mismatch(ms); in handle_exception()
1150 mesh_dump_regs(ms); in handle_exception()
1151 dumplog(ms, ms->conn_tgt); in handle_exception()
1152 do_abort(ms); in handle_exception()
1153 phase_mismatch(ms); in handle_exception()
1157 static void handle_msgin(struct mesh_state *ms) in handle_msgin() argument
1160 struct scsi_cmnd *cmd = ms->current_req; in handle_msgin()
1161 struct mesh_target *tp = &ms->tgts[ms->conn_tgt]; in handle_msgin()
1163 if (ms->n_msgin == 0) in handle_msgin()
1165 code = ms->msgin[0]; in handle_msgin()
1166 if (ALLOW_DEBUG(ms->conn_tgt)) { in handle_msgin()
1167 printk(KERN_DEBUG "got %d message bytes:", ms->n_msgin); in handle_msgin()
1168 for (i = 0; i < ms->n_msgin; ++i) in handle_msgin()
1169 printk(" %x", ms->msgin[i]); in handle_msgin()
1172 dlog(ms, "msgin msg=%.8x", in handle_msgin()
1173 MKWORD(ms->n_msgin, code, ms->msgin[1], ms->msgin[2])); in handle_msgin()
1175 ms->expect_reply = 0; in handle_msgin()
1176 ms->n_msgout = 0; in handle_msgin()
1177 if (ms->n_msgin < msgin_length(ms)) in handle_msgin()
1185 switch (ms->msgin[2]) { in handle_msgin()
1187 ms->data_ptr += (ms->msgin[3] << 24) + ms->msgin[6] in handle_msgin()
1188 + (ms->msgin[4] << 16) + (ms->msgin[5] << 8); in handle_msgin()
1193 add_sdtr_msg(ms); in handle_msgin()
1196 if (ms->msgout[3] < ms->msgin[3]) in handle_msgin()
1197 ms->msgout[3] = ms->msgin[3]; in handle_msgin()
1198 if (ms->msgout[4] > ms->msgin[4]) in handle_msgin()
1199 ms->msgout[4] = ms->msgin[4]; in handle_msgin()
1200 set_sdtr(ms, ms->msgout[3], ms->msgout[4]); in handle_msgin()
1201 ms->msgphase = msg_out; in handle_msgin()
1203 set_sdtr(ms, ms->msgin[3], ms->msgin[4]); in handle_msgin()
1211 tp->saved_ptr = ms->data_ptr; in handle_msgin()
1214 ms->data_ptr = tp->saved_ptr; in handle_msgin()
1217 ms->phase = disconnecting; in handle_msgin()
1223 set_sdtr(ms, 0, 0); in handle_msgin()
1230 do_abort(ms); in handle_msgin()
1231 ms->msgphase = msg_out; in handle_msgin()
1236 cmd->device->lun, ms->conn_tgt); in handle_msgin()
1246 ms->conn_tgt); in handle_msgin()
1247 for (i = 0; i < ms->n_msgin; ++i) in handle_msgin()
1248 printk(" %x", ms->msgin[i]); in handle_msgin()
1250 ms->msgout[0] = MESSAGE_REJECT; in handle_msgin()
1251 ms->n_msgout = 1; in handle_msgin()
1252 ms->msgphase = msg_out; in handle_msgin()
1258 static void set_dma_cmds(struct mesh_state *ms, struct scsi_cmnd *cmd) in set_dma_cmds() argument
1264 dma_cmd = ms->tgts[ms->conn_tgt].data_goes_out? in set_dma_cmds()
1266 dcmds = ms->dma_cmds; in set_dma_cmds()
1278 off = ms->data_ptr; in set_dma_cmds()
1316 ms->dma_count = dtot; in set_dma_cmds()
1319 static void halt_dma(struct mesh_state *ms) in halt_dma() argument
1321 volatile struct dbdma_regs __iomem *md = ms->dma; in halt_dma()
1322 volatile struct mesh_regs __iomem *mr = ms->mesh; in halt_dma()
1323 struct scsi_cmnd *cmd = ms->current_req; in halt_dma()
1326 if (!ms->tgts[ms->conn_tgt].data_goes_out) { in halt_dma()
1337 dlog(ms, "halt_dma fc/count=%.6x", in halt_dma()
1339 if (ms->tgts[ms->conn_tgt].data_goes_out) in halt_dma()
1343 ms->data_ptr -= nb; in halt_dma()
1344 dlog(ms, "data_ptr %x", ms->data_ptr); in halt_dma()
1345 if (ms->data_ptr < 0) { in halt_dma()
1347 ms->data_ptr, nb, ms); in halt_dma()
1348 ms->data_ptr = 0; in halt_dma()
1350 dumplog(ms, ms->conn_tgt); in halt_dma()
1351 dumpslog(ms); in halt_dma()
1354 ms->data_ptr > scsi_bufflen(cmd)) { in halt_dma()
1357 ms->conn_tgt, ms->data_ptr, scsi_bufflen(cmd), in halt_dma()
1358 ms->tgts[ms->conn_tgt].data_goes_out); in halt_dma()
1361 ms->dma_started = 0; in halt_dma()
1364 static void phase_mismatch(struct mesh_state *ms) in phase_mismatch() argument
1366 volatile struct mesh_regs __iomem *mr = ms->mesh; in phase_mismatch()
1369 dlog(ms, "phasemm ch/cl/seq/fc=%.8x", in phase_mismatch()
1372 if (ms->msgphase == msg_out_xxx && phase == BP_MSGOUT) { in phase_mismatch()
1378 out_8(&mr->fifo, ms->msgout[ms->n_msgout-1]); in phase_mismatch()
1379 ms->msgphase = msg_out_last; in phase_mismatch()
1383 if (ms->msgphase == msg_in) { in phase_mismatch()
1384 get_msgin(ms); in phase_mismatch()
1385 if (ms->n_msgin) in phase_mismatch()
1386 handle_msgin(ms); in phase_mismatch()
1389 if (ms->dma_started) in phase_mismatch()
1390 halt_dma(ms); in phase_mismatch()
1397 ms->msgphase = msg_none; in phase_mismatch()
1400 ms->tgts[ms->conn_tgt].data_goes_out = 0; in phase_mismatch()
1401 ms->phase = dataing; in phase_mismatch()
1404 ms->tgts[ms->conn_tgt].data_goes_out = 1; in phase_mismatch()
1405 ms->phase = dataing; in phase_mismatch()
1408 ms->phase = commanding; in phase_mismatch()
1411 ms->phase = statusing; in phase_mismatch()
1414 ms->msgphase = msg_in; in phase_mismatch()
1415 ms->n_msgin = 0; in phase_mismatch()
1418 ms->msgphase = msg_out; in phase_mismatch()
1419 if (ms->n_msgout == 0) { in phase_mismatch()
1420 if (ms->aborting) { in phase_mismatch()
1421 do_abort(ms); in phase_mismatch()
1423 if (ms->last_n_msgout == 0) { in phase_mismatch()
1426 ms->msgout[0] = NOP; in phase_mismatch()
1427 ms->last_n_msgout = 1; in phase_mismatch()
1429 ms->n_msgout = ms->last_n_msgout; in phase_mismatch()
1435 ms->stat = DID_ERROR; in phase_mismatch()
1436 mesh_done(ms, 1); in phase_mismatch()
1440 start_phase(ms); in phase_mismatch()
1443 static void cmd_complete(struct mesh_state *ms) in cmd_complete() argument
1445 volatile struct mesh_regs __iomem *mr = ms->mesh; in cmd_complete()
1446 struct scsi_cmnd *cmd = ms->current_req; in cmd_complete()
1447 struct mesh_target *tp = &ms->tgts[ms->conn_tgt]; in cmd_complete()
1450 dlog(ms, "cmd_complete fc=%x", mr->fifo_count); in cmd_complete()
1451 seq = use_active_neg + (ms->n_msgout? SEQ_ATN: 0); in cmd_complete()
1452 switch (ms->msgphase) { in cmd_complete()
1455 ms->n_msgin = 0; in cmd_complete()
1456 ms->msgphase = msg_in; in cmd_complete()
1461 get_msgin(ms); in cmd_complete()
1462 n = msgin_length(ms); in cmd_complete()
1463 if (ms->n_msgin < n) { in cmd_complete()
1464 out_8(&mr->count_lo, n - ms->n_msgin); in cmd_complete()
1467 ms->msgphase = msg_none; in cmd_complete()
1468 handle_msgin(ms); in cmd_complete()
1469 start_phase(ms); in cmd_complete()
1498 dlog(ms, "last_mbyte err/exc/fc/cl=%.8x", in cmd_complete()
1503 ms->last_n_msgout = ms->n_msgout; in cmd_complete()
1504 ms->n_msgout = 0; in cmd_complete()
1508 handle_error(ms); in cmd_complete()
1517 handle_exception(ms); in cmd_complete()
1524 out_8(&mr->fifo, ms->msgout[ms->n_msgout-1]); in cmd_complete()
1525 ms->msgphase = msg_out_last; in cmd_complete()
1528 ms->msgphase = msg_out_xxx; in cmd_complete()
1533 ms->last_n_msgout = ms->n_msgout; in cmd_complete()
1534 ms->n_msgout = 0; in cmd_complete()
1535 ms->msgphase = ms->expect_reply? msg_in: msg_none; in cmd_complete()
1536 start_phase(ms); in cmd_complete()
1540 switch (ms->phase) { in cmd_complete()
1543 dumpslog(ms); in cmd_complete()
1546 dlog(ms, "Selecting phase at command completion",0); in cmd_complete()
1547 ms->msgout[0] = IDENTIFY(ALLOW_RESEL(ms->conn_tgt), in cmd_complete()
1549 ms->n_msgout = 1; in cmd_complete()
1550 ms->expect_reply = 0; in cmd_complete()
1551 if (ms->aborting) { in cmd_complete()
1552 ms->msgout[0] = ABORT; in cmd_complete()
1553 ms->n_msgout++; in cmd_complete()
1556 add_sdtr_msg(ms); in cmd_complete()
1557 ms->expect_reply = 1; in cmd_complete()
1560 ms->msgphase = msg_out; in cmd_complete()
1571 dlog(ms, "impatient for req", ms->n_msgout); in cmd_complete()
1572 ms->msgphase = msg_none; in cmd_complete()
1579 if (ms->dma_count != 0) { in cmd_complete()
1580 start_phase(ms); in cmd_complete()
1596 halt_dma(ms); in cmd_complete()
1605 ms->msgphase = msg_in; in cmd_complete()
1608 mesh_done(ms, 1); in cmd_complete()
1611 ms->current_req = NULL; in cmd_complete()
1612 ms->phase = idle; in cmd_complete()
1613 mesh_start(ms); in cmd_complete()
1618 ++ms->phase; in cmd_complete()
1619 start_phase(ms); in cmd_complete()
1631 struct mesh_state *ms; in mesh_queue_lck() local
1636 ms = (struct mesh_state *) cmd->device->host->hostdata; in mesh_queue_lck()
1638 if (ms->request_q == NULL) in mesh_queue_lck()
1639 ms->request_q = cmd; in mesh_queue_lck()
1641 ms->request_qtail->host_scribble = (void *) cmd; in mesh_queue_lck()
1642 ms->request_qtail = cmd; in mesh_queue_lck()
1644 if (ms->phase == idle) in mesh_queue_lck()
1645 mesh_start(ms); in mesh_queue_lck()
1657 static void mesh_interrupt(struct mesh_state *ms) in DEF_SCSI_QCMD()
1659 volatile struct mesh_regs __iomem *mr = ms->mesh; in DEF_SCSI_QCMD()
1663 if (ALLOW_DEBUG(ms->conn_tgt)) in DEF_SCSI_QCMD()
1667 ms->phase, ms->msgphase); in DEF_SCSI_QCMD()
1670 dlog(ms, "interrupt intr/err/exc/seq=%.8x", in DEF_SCSI_QCMD()
1673 handle_error(ms); in DEF_SCSI_QCMD()
1675 handle_exception(ms); in DEF_SCSI_QCMD()
1678 cmd_complete(ms); in DEF_SCSI_QCMD()
1689 struct mesh_state *ms = (struct mesh_state *) cmd->device->host->hostdata; in mesh_abort() local
1692 mesh_dump_regs(ms); in mesh_abort()
1693 dumplog(ms, cmd->device->id); in mesh_abort()
1694 dumpslog(ms); in mesh_abort()
1706 struct mesh_state *ms = (struct mesh_state *) cmd->device->host->hostdata; in mesh_host_reset() local
1707 volatile struct mesh_regs __iomem *mr = ms->mesh; in mesh_host_reset()
1708 volatile struct dbdma_regs __iomem *md = ms->dma; in mesh_host_reset()
1713 spin_lock_irqsave(ms->host->host_lock, flags); in mesh_host_reset()
1723 out_8(&mr->source_id, ms->host->this_id); in mesh_host_reset()
1734 handle_reset(ms); in mesh_host_reset()
1736 spin_unlock_irqrestore(ms->host->host_lock, flags); in mesh_host_reset()
1740 static void set_mesh_power(struct mesh_state *ms, int state) in set_mesh_power() argument
1745 pmac_call_feature(PMAC_FTR_MESH_ENABLE, macio_get_of_node(ms->mdev), 0, 1); in set_mesh_power()
1748 pmac_call_feature(PMAC_FTR_MESH_ENABLE, macio_get_of_node(ms->mdev), 0, 0); in set_mesh_power()
1757 struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev); in mesh_suspend() local
1768 if (ms->phase == sleeping) in mesh_suspend()
1771 scsi_block_requests(ms->host); in mesh_suspend()
1772 spin_lock_irqsave(ms->host->host_lock, flags); in mesh_suspend()
1773 while(ms->phase != idle) { in mesh_suspend()
1774 spin_unlock_irqrestore(ms->host->host_lock, flags); in mesh_suspend()
1776 spin_lock_irqsave(ms->host->host_lock, flags); in mesh_suspend()
1778 ms->phase = sleeping; in mesh_suspend()
1779 spin_unlock_irqrestore(ms->host->host_lock, flags); in mesh_suspend()
1780 disable_irq(ms->meshintr); in mesh_suspend()
1781 set_mesh_power(ms, 0); in mesh_suspend()
1788 struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev); in mesh_resume() local
1791 if (ms->phase != sleeping) in mesh_resume()
1794 set_mesh_power(ms, 1); in mesh_resume()
1795 mesh_init(ms); in mesh_resume()
1796 spin_lock_irqsave(ms->host->host_lock, flags); in mesh_resume()
1797 mesh_start(ms); in mesh_resume()
1798 spin_unlock_irqrestore(ms->host->host_lock, flags); in mesh_resume()
1799 enable_irq(ms->meshintr); in mesh_resume()
1800 scsi_unblock_requests(ms->host); in mesh_resume()
1814 struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev); in mesh_shutdown() local
1819 spin_lock_irqsave(ms->host->host_lock, flags); in mesh_shutdown()
1820 mr = ms->mesh; in mesh_shutdown()
1827 spin_unlock_irqrestore(ms->host->host_lock, flags); in mesh_shutdown()
1851 struct mesh_state *ms; in mesh_probe() local
1890 ms = (struct mesh_state *) mesh_host->hostdata; in mesh_probe()
1891 macio_set_drvdata(mdev, ms); in mesh_probe()
1892 ms->host = mesh_host; in mesh_probe()
1893 ms->mdev = mdev; in mesh_probe()
1894 ms->pdev = pdev; in mesh_probe()
1896 ms->mesh = ioremap(macio_resource_start(mdev, 0), 0x1000); in mesh_probe()
1897 if (ms->mesh == NULL) { in mesh_probe()
1901 ms->dma = ioremap(macio_resource_start(mdev, 1), 0x1000); in mesh_probe()
1902 if (ms->dma == NULL) { in mesh_probe()
1904 iounmap(ms->mesh); in mesh_probe()
1908 ms->meshintr = macio_irq(mdev, 0); in mesh_probe()
1909 ms->dmaintr = macio_irq(mdev, 1); in mesh_probe()
1914 ms->dma_cmd_size = (mesh_host->sg_tablesize + 2) * sizeof(struct dbdma_cmd); in mesh_probe()
1920 ms->dma_cmd_size, &dma_cmd_bus, in mesh_probe()
1927 ms->dma_cmds = (struct dbdma_cmd *) DBDMA_ALIGN(dma_cmd_space); in mesh_probe()
1928 ms->dma_cmd_space = dma_cmd_space; in mesh_probe()
1929 ms->dma_cmd_bus = dma_cmd_bus + ((unsigned long)ms->dma_cmds) in mesh_probe()
1931 ms->current_req = NULL; in mesh_probe()
1933 ms->tgts[tgt].sdtr_state = do_sdtr; in mesh_probe()
1934 ms->tgts[tgt].sync_params = ASYNC_PARAMS; in mesh_probe()
1935 ms->tgts[tgt].current_req = NULL; in mesh_probe()
1939 ms->clk_freq = *cfp; in mesh_probe()
1942 ms->clk_freq = 50000000; in mesh_probe()
1948 minper = 1000000000 / (ms->clk_freq / 5); /* ns */ in mesh_probe()
1953 set_mesh_power(ms, 1); in mesh_probe()
1956 mesh_init(ms); in mesh_probe()
1959 if (request_irq(ms->meshintr, do_mesh_interrupt, 0, "MESH", ms)) { in mesh_probe()
1960 printk(KERN_ERR "MESH: can't get irq %d\n", ms->meshintr); in mesh_probe()
1972 free_irq(ms->meshintr, ms); in mesh_probe()
1978 set_mesh_power(ms, 0); in mesh_probe()
1979 dma_free_coherent(&macio_get_pci_dev(mdev)->dev, ms->dma_cmd_size, in mesh_probe()
1980 ms->dma_cmd_space, ms->dma_cmd_bus); in mesh_probe()
1982 iounmap(ms->dma); in mesh_probe()
1983 iounmap(ms->mesh); in mesh_probe()
1994 struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev); in mesh_remove() local
1995 struct Scsi_Host *mesh_host = ms->host; in mesh_remove()
1999 free_irq(ms->meshintr, ms); in mesh_remove()
2005 set_mesh_power(ms, 0); in mesh_remove()
2008 iounmap(ms->mesh); in mesh_remove()
2009 iounmap(ms->dma); in mesh_remove()
2012 dma_free_coherent(&macio_get_pci_dev(mdev)->dev, ms->dma_cmd_size, in mesh_remove()
2013 ms->dma_cmd_space, ms->dma_cmd_bus); in mesh_remove()