Lines Matching +full:1 +full:ms

52 #if 1
82 #define ALLOW_SYNC(tgt) ((sync_targets >> (tgt)) & 1)
83 #define ALLOW_RESEL(tgt) ((resel_targets >> (tgt)) & 1)
84 #define ALLOW_DEBUG(tgt) ((debug_targets >> (tgt)) & 1)
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()
349 static void mesh_init(struct mesh_state *ms) in mesh_init() argument
351 volatile struct mesh_regs __iomem *mr = ms->mesh; in mesh_init()
352 volatile struct dbdma_regs __iomem *md = ms->dma; in mesh_init()
365 out_8(&mr->source_id, ms->host->this_id); in mesh_init()
366 out_8(&mr->sel_timeout, 25); /* 250ms */ in mesh_init()
387 udelay(1); in mesh_init()
391 ms->phase = idle; in mesh_init()
392 ms->msgphase = msg_none; in mesh_init()
396 static void mesh_start_cmd(struct mesh_state *ms, struct scsi_cmnd *cmd) in mesh_start_cmd() argument
398 volatile struct mesh_regs __iomem *mr = ms->mesh; in mesh_start_cmd()
402 ms->current_req = cmd; in mesh_start_cmd()
403 ms->tgts[id].data_goes_out = cmd->sc_data_direction == DMA_TO_DEVICE; in mesh_start_cmd()
404 ms->tgts[id].current_req = cmd; in mesh_start_cmd()
406 #if 1 in mesh_start_cmd()
416 if (ms->dma_started) in mesh_start_cmd()
419 ms->phase = arbitrating; in mesh_start_cmd()
420 ms->msgphase = msg_none; in mesh_start_cmd()
421 ms->data_ptr = 0; in mesh_start_cmd()
422 ms->dma_started = 0; in mesh_start_cmd()
423 ms->n_msgout = 0; in mesh_start_cmd()
424 ms->last_n_msgout = 0; in mesh_start_cmd()
425 ms->expect_reply = 0; in mesh_start_cmd()
426 ms->conn_tgt = id; in mesh_start_cmd()
427 ms->tgts[id].saved_ptr = 0; in mesh_start_cmd()
428 ms->stat = DID_OK; in mesh_start_cmd()
429 ms->aborting = 0; in mesh_start_cmd()
431 ms->tgts[id].n_log = 0; in mesh_start_cmd()
432 dlog(ms, "start cmd=%x", (int) cmd); in mesh_start_cmd()
436 dlog(ms, "about to arb, intr/exc/err/fc=%.8x", in mesh_start_cmd()
441 udelay(1); in mesh_start_cmd()
448 dlog(ms, "busy b4 arb, intr/exc/err/fc=%.8x", in mesh_start_cmd()
455 dlog(ms, "intr b4 arb, intr/exc/err/fc=%.8x", in mesh_start_cmd()
458 mesh_interrupt(ms); in mesh_start_cmd()
459 if (ms->phase != arbitrating) in mesh_start_cmd()
462 udelay(1); in mesh_start_cmd()
466 ms->stat = DID_BUS_BUSY; in mesh_start_cmd()
467 ms->phase = idle; in mesh_start_cmd()
468 mesh_done(ms, 0); in mesh_start_cmd()
493 dlog(ms, "intr after disresel, intr/exc/err/fc=%.8x", in mesh_start_cmd()
496 mesh_interrupt(ms); in mesh_start_cmd()
497 if (ms->phase != arbitrating) in mesh_start_cmd()
499 dlog(ms, "after intr after disresel, intr/exc/err/fc=%.8x", in mesh_start_cmd()
509 udelay(1); in mesh_start_cmd()
511 dlog(ms, "after arb, intr/exc/err/fc=%.8x", in mesh_start_cmd()
516 dlog(ms, "resel? after arb, intr/exc/err/fc=%.8x", in mesh_start_cmd()
526 udelay(1); in mesh_start_cmd()
527 dlog(ms, "tried reset after arb, intr/exc/err/fc=%.8x", in mesh_start_cmd()
549 static void mesh_start(struct mesh_state *ms) in mesh_start() argument
553 if (ms->phase != idle || ms->current_req != NULL) { in mesh_start()
554 printk(KERN_ERR "inappropriate mesh_start (phase=%d, ms=%p)", in mesh_start()
555 ms->phase, ms); in mesh_start()
559 while (ms->phase == idle) { in mesh_start()
561 for (cmd = ms->request_q; ; cmd = (struct scsi_cmnd *) cmd->host_scribble) { in mesh_start()
564 if (ms->tgts[cmd->device->id].current_req == NULL) in mesh_start()
570 ms->request_q = next; in mesh_start()
574 ms->request_qtail = prev; in mesh_start()
576 mesh_start_cmd(ms, cmd); in mesh_start()
580 static void mesh_done(struct mesh_state *ms, int start_next) in mesh_done() argument
583 struct mesh_target *tp = &ms->tgts[ms->conn_tgt]; in mesh_done()
585 cmd = ms->current_req; in mesh_done()
586 ms->current_req = NULL; in mesh_done()
591 set_host_byte(cmd, ms->stat); in mesh_done()
593 if (ms->stat == DID_OK) in mesh_done()
597 cmd->result, ms->data_ptr, scsi_bufflen(cmd)); in mesh_done()
604 b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]); in mesh_done()
608 mcmd->this_residual -= ms->data_ptr; in mesh_done()
612 out_8(&ms->mesh->sequence, SEQ_ENBRESEL); in mesh_done()
613 mesh_flush_io(ms->mesh); in mesh_done()
614 udelay(1); in mesh_done()
615 ms->phase = idle; in mesh_done()
616 mesh_start(ms); in mesh_done()
620 static inline void add_sdtr_msg(struct mesh_state *ms) in add_sdtr_msg() argument
622 int i = ms->n_msgout; in add_sdtr_msg()
624 ms->msgout[i] = EXTENDED_MESSAGE; in add_sdtr_msg()
625 ms->msgout[i+1] = 3; in add_sdtr_msg()
626 ms->msgout[i+2] = EXTENDED_SDTR; in add_sdtr_msg()
627 ms->msgout[i+3] = mesh_sync_period/4; in add_sdtr_msg()
628 ms->msgout[i+4] = (ALLOW_SYNC(ms->conn_tgt)? mesh_sync_offset: 0); in add_sdtr_msg()
629 ms->n_msgout = i + 5; in add_sdtr_msg()
632 static void set_sdtr(struct mesh_state *ms, int period, int offset) in set_sdtr() argument
634 struct mesh_target *tp = &ms->tgts[ms->conn_tgt]; in set_sdtr()
635 volatile struct mesh_regs __iomem *mr = ms->mesh; in set_sdtr()
643 ms->conn_tgt); in set_sdtr()
652 v = (ms->clk_freq / 5000) * period; in set_sdtr()
657 tr = (ms->clk_freq + 250000) / 500000; in set_sdtr()
663 tr = ((ms->clk_freq / (v + 2)) + 199999) / 200000; in set_sdtr()
670 ms->conn_tgt, tr/10, tr%10); in set_sdtr()
673 static void start_phase(struct mesh_state *ms) in start_phase() argument
676 volatile struct mesh_regs __iomem *mr = ms->mesh; in start_phase()
677 volatile struct dbdma_regs __iomem *md = ms->dma; in start_phase()
678 struct scsi_cmnd *cmd = ms->current_req; in start_phase()
679 struct mesh_target *tp = &ms->tgts[ms->conn_tgt]; in start_phase()
681 dlog(ms, "start_phase nmo/exc/fc/seq = %.8x", in start_phase()
682 MKWORD(ms->n_msgout, mr->exception, mr->fifo_count, mr->sequence)); in start_phase()
684 seq = use_active_neg + (ms->n_msgout? SEQ_ATN: 0); in start_phase()
685 switch (ms->msgphase) { in start_phase()
691 out_8(&mr->count_lo, 1); in start_phase()
693 ms->n_msgin = 0; in start_phase()
702 if (ms->n_msgout <= 0) { in start_phase()
704 ms->n_msgout); in start_phase()
705 mesh_dump_regs(ms); in start_phase()
706 ms->msgphase = msg_none; in start_phase()
709 if (ALLOW_DEBUG(ms->conn_tgt)) { in start_phase()
711 ms->n_msgout); in start_phase()
712 for (i = 0; i < ms->n_msgout; ++i) in start_phase()
713 printk(" %x", ms->msgout[i]); in start_phase()
716 dlog(ms, "msgout msg=%.8x", MKWORD(ms->n_msgout, ms->msgout[0], in start_phase()
717 ms->msgout[1], ms->msgout[2])); in start_phase()
721 udelay(1); in start_phase()
727 dlog(ms, "bus0 was %.2x explicitly asserting ATN", mr->bus_status0); in start_phase()
730 udelay(1); in start_phase()
731 out_8(&mr->count_lo, 1); in start_phase()
734 dlog(ms,"hace: after explicit ATN bus0=%.2x",mr->bus_status0); in start_phase()
736 if (ms->n_msgout == 1) { in start_phase()
743 cmd_complete(ms); in start_phase()
745 out_8(&mr->count_lo, ms->n_msgout - 1); in start_phase()
747 for (i = 0; i < ms->n_msgout - 1; ++i) in start_phase()
748 out_8(&mr->fifo, ms->msgout[i]); in start_phase()
754 ms->msgphase); in start_phase()
757 switch (ms->phase) { in start_phase()
759 out_8(&mr->dest_id, ms->conn_tgt); in start_phase()
779 if (!ms->dma_started) { in start_phase()
780 set_dma_cmds(ms, cmd); in start_phase()
781 out_le32(&md->cmdptr, virt_to_phys(ms->dma_cmds)); in start_phase()
783 ms->dma_started = 1; in start_phase()
785 nb = ms->dma_count; in start_phase()
788 ms->dma_count -= nb; in start_phase()
789 ms->data_ptr += nb; in start_phase()
797 out_8(&mr->count_lo, 1); in start_phase()
804 udelay(1); in start_phase()
805 dlog(ms, "enbresel intr/exc/err/fc=%.8x", in start_phase()
812 ms->phase); in start_phase()
813 dumpslog(ms); in start_phase()
818 static inline void get_msgin(struct mesh_state *ms) in get_msgin() argument
820 volatile struct mesh_regs __iomem *mr = ms->mesh; in get_msgin()
825 i = ms->n_msgin; in get_msgin()
826 ms->n_msgin = i + n; in get_msgin()
828 ms->msgin[i++] = in_8(&mr->fifo); in get_msgin()
832 static inline int msgin_length(struct mesh_state *ms) in msgin_length() argument
836 n = 1; in msgin_length()
837 if (ms->n_msgin > 0) { in msgin_length()
838 b = ms->msgin[0]; in msgin_length()
839 if (b == 1) { in msgin_length()
841 n = ms->n_msgin < 2? 2: ms->msgin[1] + 2; in msgin_length()
850 static void reselected(struct mesh_state *ms) in reselected() argument
852 volatile struct mesh_regs __iomem *mr = ms->mesh; in reselected()
857 switch (ms->phase) { in reselected()
861 if ((cmd = ms->current_req) != NULL) { in reselected()
863 cmd->host_scribble = (void *) ms->request_q; in reselected()
864 if (ms->request_q == NULL) in reselected()
865 ms->request_qtail = cmd; in reselected()
866 ms->request_q = cmd; in reselected()
867 tp = &ms->tgts[cmd->device->id]; in reselected()
872 ms->phase = reselecting; in reselected()
873 mesh_done(ms, 0); in reselected()
879 ms->msgphase, ms->phase, ms->conn_tgt); in reselected()
880 dumplog(ms, ms->conn_tgt); in reselected()
881 dumpslog(ms); in reselected()
884 if (ms->dma_started) { in reselected()
886 halt_dma(ms); in reselected()
888 ms->current_req = NULL; in reselected()
889 ms->phase = dataing; in reselected()
890 ms->msgphase = msg_in; in reselected()
891 ms->n_msgout = 0; in reselected()
892 ms->last_n_msgout = 0; in reselected()
893 prev = ms->conn_tgt; in reselected()
903 udelay(1); in reselected()
907 dlog(ms, "extra resel err/exc/fc = %.6x", in reselected()
912 udelay(1); in reselected()
915 udelay(1); in reselected()
923 ms->conn_tgt = ms->host->this_id; in reselected()
929 dlog(ms, "reseldata %x", b); in reselected()
932 if ((b & (1 << t)) != 0 && t != ms->host->this_id) in reselected()
934 if (b != (1 << t) + (1 << ms->host->this_id)) { in reselected()
936 ms->conn_tgt = ms->host->this_id; in reselected()
944 ms->conn_tgt = t; in reselected()
945 tp = &ms->tgts[t]; in reselected()
952 ms->current_req = tp->current_req; in reselected()
957 ms->data_ptr = tp->saved_ptr; in reselected()
958 dlog(ms, "resel prev tgt=%d", prev); in reselected()
959 dlog(ms, "resel err/exc=%.4x", MKWORD(0, 0, mr->error, mr->exception)); in reselected()
960 start_phase(ms); in reselected()
964 dumplog(ms, ms->conn_tgt); in reselected()
965 dumpslog(ms); in reselected()
966 ms->data_ptr = 0; in reselected()
967 ms->aborting = 1; in reselected()
968 start_phase(ms); in reselected()
971 static void do_abort(struct mesh_state *ms) in do_abort() argument
973 ms->msgout[0] = ABORT; in do_abort()
974 ms->n_msgout = 1; in do_abort()
975 ms->aborting = 1; in do_abort()
976 ms->stat = DID_ABORT; in do_abort()
977 dlog(ms, "abort", 0); in do_abort()
980 static void handle_reset(struct mesh_state *ms) in handle_reset() argument
985 volatile struct mesh_regs __iomem *mr = ms->mesh; in handle_reset()
988 tp = &ms->tgts[tgt]; in handle_reset()
994 ms->tgts[tgt].sdtr_state = do_sdtr; in handle_reset()
995 ms->tgts[tgt].sync_params = ASYNC_PARAMS; in handle_reset()
997 ms->current_req = NULL; in handle_reset()
998 while ((cmd = ms->request_q) != NULL) { in handle_reset()
999 ms->request_q = (struct scsi_cmnd *) cmd->host_scribble; in handle_reset()
1003 ms->phase = idle; in handle_reset()
1004 ms->msgphase = msg_none; in handle_reset()
1008 udelay(1); in handle_reset()
1016 struct mesh_state *ms = dev_id; in do_mesh_interrupt() local
1017 struct Scsi_Host *dev = ms->host; in do_mesh_interrupt()
1020 mesh_interrupt(ms); in do_mesh_interrupt()
1025 static void handle_error(struct mesh_state *ms) in handle_error() argument
1028 volatile struct mesh_regs __iomem *mr = ms->mesh; in handle_error()
1033 dlog(ms, "error err/exc/fc/cl=%.8x", in handle_error()
1040 udelay(1); in handle_error()
1042 if (ms->dma_started) in handle_error()
1043 halt_dma(ms); in handle_error()
1044 handle_reset(ms); in handle_error()
1051 reselected(ms); in handle_error()
1054 if (!ms->aborting) { in handle_error()
1056 ms->conn_tgt); in handle_error()
1057 dumplog(ms, ms->conn_tgt); in handle_error()
1058 dumpslog(ms); in handle_error()
1061 ms->stat = DID_ABORT; in handle_error()
1062 mesh_done(ms, 1); in handle_error()
1066 if (ms->msgphase == msg_in) { in handle_error()
1068 ms->conn_tgt); in handle_error()
1069 ms->msgout[0] = MSG_PARITY_ERROR; in handle_error()
1070 ms->n_msgout = 1; in handle_error()
1071 ms->msgphase = msg_in_bad; in handle_error()
1072 cmd_complete(ms); in handle_error()
1075 if (ms->stat == DID_OK) { in handle_error()
1077 ms->conn_tgt); in handle_error()
1078 ms->stat = DID_PARITY; in handle_error()
1082 cmd_complete(ms); in handle_error()
1095 reselected(ms); in handle_error()
1101 phase_mismatch(ms); in handle_error()
1109 mesh_dump_regs(ms); in handle_error()
1110 dumplog(ms, ms->conn_tgt); in handle_error()
1111 if (ms->phase > selecting && (in_8(&mr->bus_status1) & BS1_BSY)) { in handle_error()
1113 do_abort(ms); in handle_error()
1114 phase_mismatch(ms); in handle_error()
1117 ms->stat = DID_ERROR; in handle_error()
1118 mesh_done(ms, 1); in handle_error()
1121 static void handle_exception(struct mesh_state *ms) in handle_exception() argument
1124 volatile struct mesh_regs __iomem *mr = ms->mesh; in handle_exception()
1131 reselected(ms); in handle_exception()
1134 ms->stat = DID_BUS_BUSY; in handle_exception()
1135 mesh_done(ms, 1); in handle_exception()
1138 ms->stat = DID_BAD_TARGET; in handle_exception()
1139 mesh_done(ms, 1); in handle_exception()
1143 phase_mismatch(ms); in handle_exception()
1146 mesh_dump_regs(ms); in handle_exception()
1147 dumplog(ms, ms->conn_tgt); in handle_exception()
1148 do_abort(ms); in handle_exception()
1149 phase_mismatch(ms); in handle_exception()
1153 static void handle_msgin(struct mesh_state *ms) in handle_msgin() argument
1156 struct scsi_cmnd *cmd = ms->current_req; in handle_msgin()
1157 struct mesh_target *tp = &ms->tgts[ms->conn_tgt]; in handle_msgin()
1159 if (ms->n_msgin == 0) in handle_msgin()
1161 code = ms->msgin[0]; in handle_msgin()
1162 if (ALLOW_DEBUG(ms->conn_tgt)) { in handle_msgin()
1163 printk(KERN_DEBUG "got %d message bytes:", ms->n_msgin); in handle_msgin()
1164 for (i = 0; i < ms->n_msgin; ++i) in handle_msgin()
1165 printk(" %x", ms->msgin[i]); in handle_msgin()
1168 dlog(ms, "msgin msg=%.8x", in handle_msgin()
1169 MKWORD(ms->n_msgin, code, ms->msgin[1], ms->msgin[2])); in handle_msgin()
1171 ms->expect_reply = 0; in handle_msgin()
1172 ms->n_msgout = 0; in handle_msgin()
1173 if (ms->n_msgin < msgin_length(ms)) in handle_msgin()
1181 switch (ms->msgin[2]) { in handle_msgin()
1183 ms->data_ptr += (ms->msgin[3] << 24) + ms->msgin[6] in handle_msgin()
1184 + (ms->msgin[4] << 16) + (ms->msgin[5] << 8); in handle_msgin()
1189 add_sdtr_msg(ms); in handle_msgin()
1192 if (ms->msgout[3] < ms->msgin[3]) in handle_msgin()
1193 ms->msgout[3] = ms->msgin[3]; in handle_msgin()
1194 if (ms->msgout[4] > ms->msgin[4]) in handle_msgin()
1195 ms->msgout[4] = ms->msgin[4]; in handle_msgin()
1196 set_sdtr(ms, ms->msgout[3], ms->msgout[4]); in handle_msgin()
1197 ms->msgphase = msg_out; in handle_msgin()
1199 set_sdtr(ms, ms->msgin[3], ms->msgin[4]); in handle_msgin()
1207 tp->saved_ptr = ms->data_ptr; in handle_msgin()
1210 ms->data_ptr = tp->saved_ptr; in handle_msgin()
1213 ms->phase = disconnecting; in handle_msgin()
1219 set_sdtr(ms, 0, 0); in handle_msgin()
1226 do_abort(ms); in handle_msgin()
1227 ms->msgphase = msg_out; in handle_msgin()
1232 cmd->device->lun, ms->conn_tgt); in handle_msgin()
1242 ms->conn_tgt); in handle_msgin()
1243 for (i = 0; i < ms->n_msgin; ++i) in handle_msgin()
1244 printk(" %x", ms->msgin[i]); in handle_msgin()
1246 ms->msgout[0] = MESSAGE_REJECT; in handle_msgin()
1247 ms->n_msgout = 1; in handle_msgin()
1248 ms->msgphase = msg_out; in handle_msgin()
1254 static void set_dma_cmds(struct mesh_state *ms, struct scsi_cmnd *cmd) in set_dma_cmds() argument
1260 dma_cmd = ms->tgts[ms->conn_tgt].data_goes_out? in set_dma_cmds()
1262 dcmds = ms->dma_cmds; in set_dma_cmds()
1274 off = ms->data_ptr; in set_dma_cmds()
1309 dcmds[-1].command = cpu_to_le16(dma_cmd); in set_dma_cmds()
1312 ms->dma_count = dtot; in set_dma_cmds()
1315 static void halt_dma(struct mesh_state *ms) in halt_dma() argument
1317 volatile struct dbdma_regs __iomem *md = ms->dma; in halt_dma()
1318 volatile struct mesh_regs __iomem *mr = ms->mesh; in halt_dma()
1319 struct scsi_cmnd *cmd = ms->current_req; in halt_dma()
1322 if (!ms->tgts[ms->conn_tgt].data_goes_out) { in halt_dma()
1328 udelay(1); in halt_dma()
1333 dlog(ms, "halt_dma fc/count=%.6x", in halt_dma()
1335 if (ms->tgts[ms->conn_tgt].data_goes_out) in halt_dma()
1339 ms->data_ptr -= nb; in halt_dma()
1340 dlog(ms, "data_ptr %x", ms->data_ptr); in halt_dma()
1341 if (ms->data_ptr < 0) { in halt_dma()
1342 printk(KERN_ERR "mesh: halt_dma: data_ptr=%d (nb=%d, ms=%p)\n", in halt_dma()
1343 ms->data_ptr, nb, ms); in halt_dma()
1344 ms->data_ptr = 0; in halt_dma()
1346 dumplog(ms, ms->conn_tgt); in halt_dma()
1347 dumpslog(ms); in halt_dma()
1350 ms->data_ptr > scsi_bufflen(cmd)) { in halt_dma()
1353 ms->conn_tgt, ms->data_ptr, scsi_bufflen(cmd), in halt_dma()
1354 ms->tgts[ms->conn_tgt].data_goes_out); in halt_dma()
1358 ms->dma_started = 0; in halt_dma()
1361 static void phase_mismatch(struct mesh_state *ms) in phase_mismatch() argument
1363 volatile struct mesh_regs __iomem *mr = ms->mesh; in phase_mismatch()
1366 dlog(ms, "phasemm ch/cl/seq/fc=%.8x", in phase_mismatch()
1369 if (ms->msgphase == msg_out_xxx && phase == BP_MSGOUT) { in phase_mismatch()
1371 out_8(&mr->count_lo, 1); in phase_mismatch()
1374 udelay(1); in phase_mismatch()
1375 out_8(&mr->fifo, ms->msgout[ms->n_msgout-1]); in phase_mismatch()
1376 ms->msgphase = msg_out_last; in phase_mismatch()
1380 if (ms->msgphase == msg_in) { in phase_mismatch()
1381 get_msgin(ms); in phase_mismatch()
1382 if (ms->n_msgin) in phase_mismatch()
1383 handle_msgin(ms); in phase_mismatch()
1386 if (ms->dma_started) in phase_mismatch()
1387 halt_dma(ms); in phase_mismatch()
1391 udelay(1); in phase_mismatch()
1394 ms->msgphase = msg_none; in phase_mismatch()
1397 ms->tgts[ms->conn_tgt].data_goes_out = 0; in phase_mismatch()
1398 ms->phase = dataing; in phase_mismatch()
1401 ms->tgts[ms->conn_tgt].data_goes_out = 1; in phase_mismatch()
1402 ms->phase = dataing; in phase_mismatch()
1405 ms->phase = commanding; in phase_mismatch()
1408 ms->phase = statusing; in phase_mismatch()
1411 ms->msgphase = msg_in; in phase_mismatch()
1412 ms->n_msgin = 0; in phase_mismatch()
1415 ms->msgphase = msg_out; in phase_mismatch()
1416 if (ms->n_msgout == 0) { in phase_mismatch()
1417 if (ms->aborting) { in phase_mismatch()
1418 do_abort(ms); in phase_mismatch()
1420 if (ms->last_n_msgout == 0) { in phase_mismatch()
1423 ms->msgout[0] = NOP; in phase_mismatch()
1424 ms->last_n_msgout = 1; in phase_mismatch()
1426 ms->n_msgout = ms->last_n_msgout; in phase_mismatch()
1432 ms->stat = DID_ERROR; in phase_mismatch()
1433 mesh_done(ms, 1); in phase_mismatch()
1437 start_phase(ms); in phase_mismatch()
1440 static void cmd_complete(struct mesh_state *ms) in cmd_complete() argument
1442 volatile struct mesh_regs __iomem *mr = ms->mesh; in cmd_complete()
1443 struct scsi_cmnd *cmd = ms->current_req; in cmd_complete()
1444 struct mesh_target *tp = &ms->tgts[ms->conn_tgt]; in cmd_complete()
1447 dlog(ms, "cmd_complete fc=%x", mr->fifo_count); in cmd_complete()
1448 seq = use_active_neg + (ms->n_msgout? SEQ_ATN: 0); in cmd_complete()
1449 switch (ms->msgphase) { in cmd_complete()
1452 ms->n_msgin = 0; in cmd_complete()
1453 ms->msgphase = msg_in; in cmd_complete()
1458 get_msgin(ms); in cmd_complete()
1459 n = msgin_length(ms); in cmd_complete()
1460 if (ms->n_msgin < n) { in cmd_complete()
1461 out_8(&mr->count_lo, n - ms->n_msgin); in cmd_complete()
1464 ms->msgphase = msg_none; in cmd_complete()
1465 handle_msgin(ms); in cmd_complete()
1466 start_phase(ms); in cmd_complete()
1473 udelay(1); in cmd_complete()
1474 out_8(&mr->count_lo, 1); in cmd_complete()
1490 out_8(&mr->count_lo, 1); in cmd_complete()
1494 udelay(1); in cmd_complete()
1495 dlog(ms, "last_mbyte err/exc/fc/cl=%.8x", in cmd_complete()
1500 ms->last_n_msgout = ms->n_msgout; in cmd_complete()
1501 ms->n_msgout = 0; in cmd_complete()
1505 handle_error(ms); in cmd_complete()
1514 handle_exception(ms); in cmd_complete()
1520 udelay(1); in cmd_complete()
1521 out_8(&mr->fifo, ms->msgout[ms->n_msgout-1]); in cmd_complete()
1522 ms->msgphase = msg_out_last; in cmd_complete()
1525 ms->msgphase = msg_out_xxx; in cmd_complete()
1530 ms->last_n_msgout = ms->n_msgout; in cmd_complete()
1531 ms->n_msgout = 0; in cmd_complete()
1532 ms->msgphase = ms->expect_reply? msg_in: msg_none; in cmd_complete()
1533 start_phase(ms); in cmd_complete()
1537 switch (ms->phase) { in cmd_complete()
1540 dumpslog(ms); in cmd_complete()
1543 dlog(ms, "Selecting phase at command completion",0); in cmd_complete()
1544 ms->msgout[0] = IDENTIFY(ALLOW_RESEL(ms->conn_tgt), in cmd_complete()
1546 ms->n_msgout = 1; in cmd_complete()
1547 ms->expect_reply = 0; in cmd_complete()
1548 if (ms->aborting) { in cmd_complete()
1549 ms->msgout[0] = ABORT; in cmd_complete()
1550 ms->n_msgout++; in cmd_complete()
1553 add_sdtr_msg(ms); in cmd_complete()
1554 ms->expect_reply = 1; in cmd_complete()
1557 ms->msgphase = msg_out; in cmd_complete()
1568 dlog(ms, "impatient for req", ms->n_msgout); in cmd_complete()
1569 ms->msgphase = msg_none; in cmd_complete()
1572 udelay(1); in cmd_complete()
1576 if (ms->dma_count != 0) { in cmd_complete()
1577 start_phase(ms); in cmd_complete()
1593 halt_dma(ms); in cmd_complete()
1604 ms->msgphase = msg_in; in cmd_complete()
1607 mesh_done(ms, 1); in cmd_complete()
1610 ms->current_req = NULL; in cmd_complete()
1611 ms->phase = idle; in cmd_complete()
1612 mesh_start(ms); in cmd_complete()
1617 ++ms->phase; in cmd_complete()
1618 start_phase(ms); in cmd_complete()
1630 struct mesh_state *ms; in mesh_queue_lck() local
1634 ms = (struct mesh_state *) cmd->device->host->hostdata; in mesh_queue_lck()
1636 if (ms->request_q == NULL) in mesh_queue_lck()
1637 ms->request_q = cmd; in mesh_queue_lck()
1639 ms->request_qtail->host_scribble = (void *) cmd; in mesh_queue_lck()
1640 ms->request_qtail = cmd; in mesh_queue_lck()
1642 if (ms->phase == idle) in mesh_queue_lck()
1643 mesh_start(ms); in mesh_queue_lck()
1655 static void mesh_interrupt(struct mesh_state *ms) in DEF_SCSI_QCMD()
1657 volatile struct mesh_regs __iomem *mr = ms->mesh; in DEF_SCSI_QCMD()
1661 if (ALLOW_DEBUG(ms->conn_tgt)) in DEF_SCSI_QCMD()
1665 ms->phase, ms->msgphase); in DEF_SCSI_QCMD()
1668 dlog(ms, "interrupt intr/err/exc/seq=%.8x", in DEF_SCSI_QCMD()
1671 handle_error(ms); in DEF_SCSI_QCMD()
1673 handle_exception(ms); in DEF_SCSI_QCMD()
1676 cmd_complete(ms); in DEF_SCSI_QCMD()
1687 struct mesh_state *ms = (struct mesh_state *) cmd->device->host->hostdata; in mesh_abort() local
1690 mesh_dump_regs(ms); in mesh_abort()
1691 dumplog(ms, cmd->device->id); in mesh_abort()
1692 dumpslog(ms); in mesh_abort()
1704 struct mesh_state *ms = (struct mesh_state *) cmd->device->host->hostdata; in mesh_host_reset() local
1705 volatile struct mesh_regs __iomem *mr = ms->mesh; in mesh_host_reset()
1706 volatile struct dbdma_regs __iomem *md = ms->dma; in mesh_host_reset()
1711 spin_lock_irqsave(ms->host->host_lock, flags); in mesh_host_reset()
1713 if (ms->dma_started) in mesh_host_reset()
1714 halt_dma(ms); in mesh_host_reset()
1722 udelay(1); in mesh_host_reset()
1724 out_8(&mr->source_id, ms->host->this_id); in mesh_host_reset()
1725 out_8(&mr->sel_timeout, 25); /* 250ms */ in mesh_host_reset()
1735 handle_reset(ms); in mesh_host_reset()
1737 spin_unlock_irqrestore(ms->host->host_lock, flags); in mesh_host_reset()
1741 static void set_mesh_power(struct mesh_state *ms, int state) in set_mesh_power() argument
1746 pmac_call_feature(PMAC_FTR_MESH_ENABLE, macio_get_of_node(ms->mdev), 0, 1); in set_mesh_power()
1749 pmac_call_feature(PMAC_FTR_MESH_ENABLE, macio_get_of_node(ms->mdev), 0, 0); in set_mesh_power()
1758 struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev); in mesh_suspend() local
1769 if (ms->phase == sleeping) in mesh_suspend()
1772 scsi_block_requests(ms->host); in mesh_suspend()
1773 spin_lock_irqsave(ms->host->host_lock, flags); in mesh_suspend()
1774 while(ms->phase != idle) { in mesh_suspend()
1775 spin_unlock_irqrestore(ms->host->host_lock, flags); in mesh_suspend()
1777 spin_lock_irqsave(ms->host->host_lock, flags); in mesh_suspend()
1779 ms->phase = sleeping; in mesh_suspend()
1780 spin_unlock_irqrestore(ms->host->host_lock, flags); in mesh_suspend()
1781 disable_irq(ms->meshintr); in mesh_suspend()
1782 set_mesh_power(ms, 0); in mesh_suspend()
1789 struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev); in mesh_resume() local
1792 if (ms->phase != sleeping) in mesh_resume()
1795 set_mesh_power(ms, 1); in mesh_resume()
1796 mesh_init(ms); in mesh_resume()
1797 spin_lock_irqsave(ms->host->host_lock, flags); in mesh_resume()
1798 mesh_start(ms); in mesh_resume()
1799 spin_unlock_irqrestore(ms->host->host_lock, flags); in mesh_resume()
1800 enable_irq(ms->meshintr); in mesh_resume()
1801 scsi_unblock_requests(ms->host); in mesh_resume()
1815 struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev); in mesh_shutdown() local
1820 spin_lock_irqsave(ms->host->host_lock, flags); in mesh_shutdown()
1821 mr = ms->mesh; in mesh_shutdown()
1828 spin_unlock_irqrestore(ms->host->host_lock, flags); in mesh_shutdown()
1853 struct mesh_state *ms; in mesh_probe() local
1887 ms = (struct mesh_state *) mesh_host->hostdata; in mesh_probe()
1888 macio_set_drvdata(mdev, ms); in mesh_probe()
1889 ms->host = mesh_host; in mesh_probe()
1890 ms->mdev = mdev; in mesh_probe()
1891 ms->pdev = pdev; in mesh_probe()
1893 ms->mesh = ioremap(macio_resource_start(mdev, 0), 0x1000); in mesh_probe()
1894 if (ms->mesh == NULL) { in mesh_probe()
1898 ms->dma = ioremap(macio_resource_start(mdev, 1), 0x1000); in mesh_probe()
1899 if (ms->dma == NULL) { in mesh_probe()
1901 iounmap(ms->mesh); in mesh_probe()
1905 ms->meshintr = macio_irq(mdev, 0); in mesh_probe()
1906 ms->dmaintr = macio_irq(mdev, 1); in mesh_probe()
1908 /* Space for dma command list: +1 for stop command, in mesh_probe()
1909 * +1 to allow for aligning. in mesh_probe()
1911 ms->dma_cmd_size = (mesh_host->sg_tablesize + 2) * sizeof(struct dbdma_cmd); in mesh_probe()
1917 ms->dma_cmd_size, &dma_cmd_bus, in mesh_probe()
1924 ms->dma_cmds = (struct dbdma_cmd *) DBDMA_ALIGN(dma_cmd_space); in mesh_probe()
1925 ms->dma_cmd_space = dma_cmd_space; in mesh_probe()
1926 ms->dma_cmd_bus = dma_cmd_bus + ((unsigned long)ms->dma_cmds) in mesh_probe()
1928 ms->current_req = NULL; in mesh_probe()
1930 ms->tgts[tgt].sdtr_state = do_sdtr; in mesh_probe()
1931 ms->tgts[tgt].sync_params = ASYNC_PARAMS; in mesh_probe()
1932 ms->tgts[tgt].current_req = NULL; in mesh_probe()
1936 ms->clk_freq = *cfp; in mesh_probe()
1939 ms->clk_freq = 50000000; in mesh_probe()
1945 minper = 1000000000 / (ms->clk_freq / 5); /* ns */ in mesh_probe()
1950 set_mesh_power(ms, 1); in mesh_probe()
1953 mesh_init(ms); in mesh_probe()
1956 if (request_irq(ms->meshintr, do_mesh_interrupt, 0, "MESH", ms)) { in mesh_probe()
1957 printk(KERN_ERR "MESH: can't get irq %d\n", ms->meshintr); in mesh_probe()
1969 free_irq(ms->meshintr, ms); in mesh_probe()
1975 set_mesh_power(ms, 0); in mesh_probe()
1976 dma_free_coherent(&macio_get_pci_dev(mdev)->dev, ms->dma_cmd_size, in mesh_probe()
1977 ms->dma_cmd_space, ms->dma_cmd_bus); in mesh_probe()
1979 iounmap(ms->dma); in mesh_probe()
1980 iounmap(ms->mesh); in mesh_probe()
1991 struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev); in mesh_remove() local
1992 struct Scsi_Host *mesh_host = ms->host; in mesh_remove()
1996 free_irq(ms->meshintr, ms); in mesh_remove()
2002 set_mesh_power(ms, 0); in mesh_remove()
2005 iounmap(ms->mesh); in mesh_remove()
2006 iounmap(ms->dma); in mesh_remove()
2009 dma_free_coherent(&macio_get_pci_dev(mdev)->dev, ms->dma_cmd_size, in mesh_remove()
2010 ms->dma_cmd_space, ms->dma_cmd_bus); in mesh_remove()