/* --- Main FDC dispatcher --- */ static void fdc_execute(FDC_765 *self) { /* This code to dump out FDC commands as they are received is very useful * in debugging * * */ int NC; fdc_dprintf(5, "FDC: "); for (NC = 0; NC < bytes_in_cmd[self->fdc_cmd_buf[0] & 0x1F]; NC++) fdc_dprintf(5, "%02x ", self->fdc_cmd_buf[NC]); fdc_dprintf(5, "\n"); /* */ /* Check if the DOR (ugh!) is being used to force us to a different drive. */ fdc_dorcheck(self); /* Reset "seek finished" flag */ self->fdc_st0 &= 0xBF; switch(self->fdc_cmd_buf[0] & 0x1F) { case 2: fdc_read_track(self); break; /* 2: READ TRACK */ case 3: fdc_specify(self); break; /* 3: SPECIFY */ case 4: fdc_sense_drive(self); break; /* 4: SENSE DRV STATUS*/ case 5: fdc_write(self, 0); break; /* 5: WRITE */ case 6: fdc_read(self, 0); break; /* 6: READ */ case 7: fdc_recalibrate(self); break; /* 7: RECALIBRATE */ case 8: fdc_sense_int(self); break; /* 8: SENSE INT STATUS*/ case 9: fdc_write(self, 1); break; /* 9: WRITE DELETED */ case 10:fdc_read_id(self); break; /*10: READ ID */ case 12:fdc_read(self, 1); break; /*12: READ DELETED */ case 13:fdc_format(self); break; /*13: FORMAT TRACK */ case 15:fdc_seek(self); break; /*15: SEEK */ case 17: /*17: SCAN EQUAL */ case 25: /*25: SCAN LOW/EQUAL */ case 30:fdc_scan(self); break; /*30: SCAN HIGH/EQUAL*/ default: fdc_dprintf(2, "Unknown FDC command %d\n", self->fdc_cmd_buf[0] & 0x1F); fdc_error(self); break; } }
/* Input a res_len long result string from the FDC. * The FDC should be ready to send the result or an error * (EBUSY or ETIME) will occur. */ int fdc_result(__u8 * res_data, int res_len) { int result = 0; unsigned long flags; int count = res_len; int retry = 0; TRACE_FUN(ft_t_any); save_flags(flags); cli(); fdc_status = inb(fdc.msr); if ((fdc_status & FDC_DATA_READY_MASK) != FDC_DATA_OUT_READY) { TRACE(ft_t_err, "fdc not ready"); result = -EBUSY; } else while (count) { if (!(fdc_status & FDC_BUSY)) { restore_flags(flags); TRACE_ABORT(-EIO, ft_t_err, "premature end of result phase"); } result = fdc_read(res_data); if (result < 0) { TRACE(ft_t_fdc_dma, "fdc_mode = %02x, status = %02x at index %d", (int) fdc_mode, (int) fdc_status, res_len - count); if (++retry <= 3) { TRACE(ft_t_warn, "fdc_read timeout, retry"); } else { TRACE(ft_t_err, "fdc_read timeout, fatal"); /* recover ??? */ break; ++retry; } } else { --count; ++res_data; } } restore_flags(flags); fdc_usec_wait(FT_RQM_DELAY); /* allow FDC to negate BSY */ TRACE_EXIT result; }
/* If no request is currently being processed and there's new requests in the queue, process the first one. This can be called from an interrupt or the normal kernel context. */ void do_request(blkreq_t *req) { fd_dev_t *dev; u_long track, sect, cyl, head, big_sect, sects; u_long flags; int i; save_flags(flags); /* This label is used to eliminate tail-recursion. */ top: cli(); if(current_req != NULL) { if(req != NULL) append_node(&fd_reqs, &req->node); load_flags(flags); return; } for(i = 0; i < 2; i++) { if(fd_devs[i].recalibrate) { fdc_recal(&fd_devs[i]); if(req != NULL) append_node(&fd_reqs, &req->node); load_flags(flags); return; } } if(req == NULL) { if(!list_empty_p(&fd_reqs)) { req = (blkreq_t *)fd_reqs.head; remove_node(&req->node); } else { load_flags(flags); return; } } current_req = req; #if 0 req->retries = 0; #endif load_flags(flags); dev = REQ_FD_DEV(req); DB(("fd:do_request: req=%p drive=%d block=%d nblocks=%d cmd=%d buf=%p\n", req, dev->drvno, req->block, req->nblocks, req->command, req->buf)); switch(req->command) { case FD_CMD_SEEK: /* We wanna MOVE DA HEAD! */ /* Do da seek. */ if(fdc_seek(dev, req->block) == FALSE) { handle_error("FD_CMD_SEEK, seek"); goto top; break; } /* Then Sense Interrupt Status */ if(fdc_sense() == FALSE) { handle_error("FD_CMD_SEEK, fdc_sense"); goto top; break; } /* and now we have to Read the ID */ if(fdc_read_id(dev) == FALSE) { handle_error("FD_CMD_SEEK, read_id"); goto top; break; } fd_end_request(0); req = NULL; goto top; case FD_CMD_TIMER: fd_end_request(0); req = NULL; goto top; } if(req->block >= dev->total_blocks) { kprintf("fd: Device %s (%p) doesn't have a block %d!\n", dev->name, dev, req->block); fd_end_request(-1); req = NULL; goto top; } big_sect = req->block; sects = req->nblocks; track = big_sect / dev->disk_p->sectors; sect = big_sect % dev->disk_p->sectors + 1; head = track % dev->disk_p->heads; cyl = track / dev->disk_p->heads; DB(("fd:do_request: cyl=%d sect=%d head=%d sects=%d\n", cyl, sect, head, sects)); switch(req->command) { case FD_CMD_READ: /* We wanna READ the floppy! */ #if 0 fd_end_request(0); req = NULL; goto top; #endif /* We need to seek to the right cylinder. */ if(fdc_seek(dev, cyl) == FALSE) { handle_error("FD_CMD_READ, seek"); goto top; break; } /* Then Sense Interrupt Status */ if(fdc_sense() == FALSE) { handle_error("FD_CMD_READ, fdc_sense"); goto top; break; } /* and now we have to Read the ID */ if(fdc_read_id(dev) == FALSE) { handle_error("FD_CMD_READ, read_id"); goto top; break; } #define TPA(XX) ((u_long)TO_PHYSICAL(XX)) /* Tell the DMA what to do, and hope for the best! */ /* Should move this inside fdc, in fdc_read() i think */ DMAbuf.Buffer = track_buf; DMAbuf.Page = (u_int8)((TPA(track_buf) >> 16) & 0xff); DMAbuf.Offset = (u_int16)(TPA(track_buf) & 0xffff); DMAbuf.Len = (u_int16)(dev->disk_p->sectors * dev->disk_p->heads * FD_SECTSIZ) - 1; DMAbuf.Chan = FLOPPY_DMA; kernel->setup_dma(&DMAbuf, DMA_READ); /* Now we issue a read command. */ if(fdc_read(dev, cyl) == FALSE) { handle_error("FD_CMD_READ, read"); goto top; break; } break; case FD_CMD_WRITE: /* We wanna WRITE it too! */ fd_end_request(0); req = NULL; goto top; default: kprintf("fd:do_request: Unknown command in fd_req, %d\n", req->command); fd_end_request(-1); req = NULL; goto top; } }