Lines Matching refs:fdc

91 #include <dev/fdc/fdcvar.h>
291 struct fdc_data *fdc; /* pointer to controller structure */
324 static SYSCTL_NODE(_debug, OID_AUTO, fdc, CTLFLAG_RW, 0, "fdc driver");
380 fdregwr(struct fdc_data *fdc, int reg, uint8_t v)
383 bus_space_write_1(fdc->iot, fdc->ioh[reg], fdc->ioff[reg], v);
387 fdregrd(struct fdc_data *fdc, int reg)
390 return bus_space_read_1(fdc->iot, fdc->ioh[reg], fdc->ioff[reg]);
394 fdctl_wr(struct fdc_data *fdc, u_int8_t v)
397 fdregwr(fdc, FDCTL, v);
402 fdout_wr(struct fdc_data *fdc, u_int8_t v)
405 fdregwr(fdc, FDOUT, v);
410 fdsts_rd(struct fdc_data *fdc)
413 return fdregrd(fdc, FDSTS);
418 fddsr_wr(struct fdc_data *fdc, u_int8_t v)
421 fdregwr(fdc, FDDSR, v);
426 fddata_wr(struct fdc_data *fdc, u_int8_t v)
429 fdregwr(fdc, FDDATA, v);
433 fddata_rd(struct fdc_data *fdc)
436 return fdregrd(fdc, FDDATA);
441 fdin_rd(struct fdc_data *fdc)
444 return fdregrd(fdc, FDCTL);
453 fdbcdr_wr(struct fdc_data *fdc, int iswrite, uint16_t count)
455 fdregwr(fdc, FDBCDR, (count - 1) & 0xff);
456 fdregwr(fdc, FDBCDR + 1,
461 fdc_err(struct fdc_data *fdc, const char *s)
463 fdc->fdc_errs++;
465 if (fdc->fdc_errs < FDC_ERRMAX)
466 device_printf(fdc->fdc_dev, "%s", s);
467 else if (fdc->fdc_errs == FDC_ERRMAX)
468 device_printf(fdc->fdc_dev, "too many errors, not "
484 fdc_in(struct fdc_data *fdc, int *ptr)
490 i = fdsts_rd(fdc) & (NE7_DIO | NE7_RQM);
492 i = fddata_rd(fdc);
498 return (fdc_err(fdc, "ready for output in input\n"));
502 return (fdc_err(fdc, bootverbose? "input ready timeout\n": 0));
506 fdc_out(struct fdc_data *fdc, int x)
512 i = fdsts_rd(fdc) & (NE7_DIO | NE7_RQM);
514 fddata_wr(fdc, x);
518 return (fdc_err(fdc, "ready for input in output\n"));
522 return (fdc_err(fdc, bootverbose? "output ready timeout\n": 0));
534 fdc_cmd(struct fdc_data *fdc, int n_out, ...)
546 if (fdc_out(fdc, i) < 0) {
551 fdc->flags |= FDC_NEEDS_RESET;
553 return fdc_err(fdc, msg);
559 if (fdc_in(fdc, ptr) < 0) {
564 fdc->flags |= FDC_NEEDS_RESET;
566 return fdc_err(fdc, msg);
580 set_density(struct fdc_data *fdc)
583 fdregwr(fdc, FDP, (pc98_trans != 1 ? FDP_FDDEXC : 0) | FDP_PORTEXC);
585 fdctl_wr(fdc, FDC_RST | FDC_DMAE);
592 struct fdc_data *fdc = fd->fdc;
598 fdc_out(fdc, NE7CMD_SENSED); /* Sense Drive Status */
600 fdc_out(fdc, fdu); /* Drive number */
602 if ((fdc_in(fdc, &status) == 0) && (status & NE7_ST3_RD)) {
603 fdctl_wr(fdc, FDC_DMAE | FDC_MTON);
614 struct fdc_data *fdc;
619 fdc = fd->fdc;
629 fdregwr(fdc, FDEM, (unit << 5) | 0x10);
630 if (!(fdregrd(fdc, FDEM) & 0x01)) {
643 fdc_reset(struct fdc_data *fdc)
648 set_density(fdc);
650 fdctl_wr(fdc, FDC_RST | FDC_RDY | FDC_DD | FDC_MTON);
652 fdctl_wr(fdc, FDC_RST | FDC_RDY | FDC_DMAE | FDC_MTON);
654 fdctl_wr(fdc, FDC_DMAE | FDC_MTON);
657 if (fdc->fdct == FDC_ENHANCED) {
659 fddsr_wr(fdc, I8207X_DSR_SR);
662 fdout_wr(fdc, fdc->fdout & ~(FDO_FRST|FDO_FDMAEN));
665 fdout_wr(fdc, fdc->fdout & ~FDO_FDMAEN);
668 fdout_wr(fdc, fdc->fdout);
672 if (fdc_cmd(fdc, 3, NE7CMD_SPECIFY, spec1, spec2, 0))
673 device_printf(fdc->fdc_dev, " SPECIFY failed in reset\n");
675 if (fdc->fdct == FDC_ENHANCED) {
676 if (fdc_cmd(fdc, 4,
685 device_printf(fdc->fdc_dev,
688 if (fdc_cmd(fdc, 1,
692 device_printf(fdc->fdc_dev,
702 fdc_sense_drive(struct fdc_data *fdc, int *st3p)
706 if (fdc_cmd(fdc, 2, NE7CMD_SENSED, fdc->fd->fdsu, 1, &st3))
707 return (fdc_err(fdc, "Sense Drive Status failed\n"));
714 fdc_sense_int(struct fdc_data *fdc, int *st0p, int *cylp)
718 ret = fdc_cmd(fdc, 1, NE7CMD_SENSEI, 1, &st0);
720 (void)fdc_err(fdc, "sense intr err reading stat reg 0\n");
734 if (fdc_in(fdc, &cyl) < 0)
735 return fdc_err(fdc, "can't get cyl num\n");
744 fdc_read_status(struct fdc_data *fdc)
749 ret = fdc_in(fdc, &status);
750 fdc->status[i] = status;
756 fdc->flags |= FDC_STAT_VALID;
758 fdc->flags &= ~FDC_STAT_VALID;
770 struct fdc_data *fdc;
773 fdc = fd->fdc;
774 fdc->fdout &= ~FDO_FDSEL;
775 fdc->fdout |= FDO_FDMAEN | FDO_FRST | fd->fdsu;
776 fdout_wr(fdc, fdc->fdout);
787 mtx_assert(&fd->fdc->fdc_mtx, MA_OWNED);
795 bioq_disksort(&fd->fdc->head, bp);
799 wakeup(&fd->fdc->head);
806 struct fdc_data *fdc;
808 fdc = fd->fdc;
810 mtx_assert(&fdc->fdc_mtx, MA_OWNED);
813 fdregwr(fdc, FDP, (pc98_trans != 1 ? FDP_FDDEXC : 0) | FDP_PORTEXC);
815 fdctl_wr(fdc, FDC_DMAE | FDC_MTON);
819 fdc->fdout |= (FDO_MOEN0 << fd->fdsu);
824 fdc->fdout &= ~(FDO_MOEN0 << fd->fdsu);
826 fdout_wr(fdc, fdc->fdout);
835 mtx_assert(&fd->fdc->fdc_mtx, MA_OWNED);
862 fdc_pio(struct fdc_data *fdc)
868 bp = fdc->bp;
869 cptr = fdc->fd->fd_ioptr;
870 count = fdc->fd->fd_iosize;
873 fdbcdr_wr(fdc, 0, count);
874 bus_space_read_multi_1(fdc->iot, fdc->ioh[FD_YE_DATAPORT],
875 fdc->ioff[FD_YE_DATAPORT], cptr, count);
877 bus_space_write_multi_1(fdc->iot, fdc->ioh[FD_YE_DATAPORT],
878 fdc->ioff[FD_YE_DATAPORT], cptr, count);
879 fdbcdr_wr(fdc, 0, count); /* needed? */
884 fdc_biodone(struct fdc_data *fdc, int error)
889 fd = fdc->fd;
890 bp = fdc->bp;
892 mtx_lock(&fdc->fdc_mtx);
895 fdc->bp = NULL;
896 fdc->fd = NULL;
897 mtx_unlock(&fdc->fdc_mtx);
899 if ((debugflags & 2) && fd->fdc->retry > 0)
900 printf("retries: %d\n", fd->fdc->retry);
913 fdc_worker(struct fdc_data *fdc)
928 bp = fdc->bp;
929 fd = fdc->fd;
931 (fdc->retry >= retries || (fd->options & FDOPT_NORETRY))) {
934 if (fdc->flags & FDC_NEEDS_RESET) {
935 mtx_lock(&fdc->fdc_mtx);
937 mtx_unlock(&fdc->fdc_mtx);
939 return (fdc_biodone(fdc, EIO));
946 fd->fd_ioptr, fd->fd_iosize, fdc->dmachan);
947 mtx_lock(&fdc->fdc_mtx);
949 mtx_unlock(&fdc->fdc_mtx);
953 if (fdc->flags & FDC_NEEDS_RESET) {
954 fdc->flags &= ~FDC_NEEDS_RESET;
955 fdc_reset(fdc);
959 tsleep(fdc, PRIBIO, "fdcrst", hz);
962 fdc_sense_int(fdc, &st0, &cyl);
968 if (fdc->bp == NULL) {
969 mtx_lock(&fdc->fdc_mtx);
971 fdc->bp = bioq_takefirst(&fdc->head);
972 if (fdc->bp == NULL)
973 msleep(&fdc->head, &fdc->fdc_mtx,
975 } while (fdc->bp == NULL &&
976 (fdc->flags & FDC_KTHREAD_EXIT) == 0);
977 mtx_unlock(&fdc->fdc_mtx);
979 if (fdc->bp == NULL)
986 bp = fdc->bp;
987 fd = fdc->fd = bp->bio_driver1;
988 fdc->retry = 0;
1003 set_density(fdc);
1012 fdregwr(fdc, FDEM,
1022 if (fdc->fdct == FDC_ENHANCED)
1023 fddsr_wr(fdc, fd->ft->trans);
1025 fdctl_wr(fdc, fd->ft->trans);
1031 !(fdin_rd(fdc) & FDI_DCHG) &&
1035 return (fdc_biodone(fdc, 0));
1043 return (fdc_biodone(fdc, ENXIO));
1047 if (fdin_rd(fdc) & FDI_DCHG) {
1050 mtx_lock(&fdc->fdc_mtx);
1053 mtx_unlock(&fdc->fdc_mtx);
1061 return (fdc_biodone(fdc, ENXIO));
1068 if(fdc_sense_drive(fdc, &st3) != 0)
1071 return (fdc_biodone(fdc, EROFS));
1085 if (fdc->retry == 0 &&
1097 fdc->retry > 2) {
1102 if (fdc_cmd(fdc, 2, NE7CMD_RECAL, fd->fdsu, 0))
1104 tsleep(fdc, PRIBIO, "fdrecal", hz);
1106 if (fdc_sense_int(fdc, &st0, &cyl) == FD_NOT_VALID)
1115 tsleep(fdc->fd, PRIBIO, "fdhdstl", settle);
1126 if (fdc_cmd(fdc, 3, NE7CMD_SEEK, fd->fdsu, descyl, 0))
1128 tsleep(fdc, PRIBIO, "fdseek", hz);
1130 if (fdc_sense_int(fdc, &st0, &cyl) == FD_NOT_VALID)
1139 tsleep(fdc->fd, PRIBIO, "fdhdstl", settle);
1146 fd->fd_ioptr, fdc->retry);
1152 && !(fdc->flags & FDC_NODMA)) {
1155 fd->fd_ioptr, fd->fd_iosize, fdc->dmachan);
1156 mtx_lock(&fdc->fdc_mtx);
1158 mtx_unlock(&fdc->fdc_mtx);
1162 if (fdc->flags & FDC_NODMA) {
1166 fdbcdr_wr(fdc, 1, fd->fd_iosize);
1169 fdc_pio(fdc);
1177 if (fdc_cmd(fdc, 6,
1188 if (fdc_cmd(fdc, 2,
1195 if (fdc_cmd(fdc, 9,
1210 if (fdc_cmd(fdc, 9,
1228 i = tsleep(fdc, PRIBIO, "fddata", hz);
1231 if (i == 0 && (fdc->flags & FDC_NODMA) && (bp->bio_cmd == BIO_READ))
1232 fdc_pio(fdc);
1238 fd->fd_ioptr, fd->fd_iosize, fdc->dmachan);
1239 mtx_lock(&fdc->fdc_mtx);
1241 mtx_unlock(&fdc->fdc_mtx);
1255 fdc->flags |= FDC_NEEDS_RESET;
1260 if (fdc_read_status(fdc))
1265 fdc->status[0], fdc->status[1],
1266 fdc->status[2], fdc->status[3]);
1268 st0 = fdc->status[0] & NE7_ST0_IC;
1271 if (st0 == NE7_ST0_IC_AT && fdc->status[1] & NE7_ST1_OR) {
1281 fdc->flags |= FDC_NEEDS_RESET;
1285 if(st0 == NE7_ST0_IC_AT && fdc->status[2] & NE7_ST2_WC) {
1291 fdc->status[0], fdc->status[1], fdc->status[2],
1292 fdc->status[3], fdc->status[4], fdc->status[5]);
1305 idp->cyl = fdc->status[3];
1306 idp->head = fdc->status[4];
1307 idp->sec = fdc->status[5];
1308 idp->secshift = fdc->status[6];
1325 fdc->retry = 0;
1333 return (fdc_biodone(fdc, 0));
1339 struct fdc_data *fdc;
1341 fdc = arg;
1344 mtx_lock(&fdc->fdc_mtx);
1345 fdc->flags |= FDC_KTHREAD_ALIVE;
1346 while ((fdc->flags & FDC_KTHREAD_EXIT) == 0) {
1347 mtx_unlock(&fdc->fdc_mtx);
1348 i = fdc_worker(fdc);
1350 if (fdc->bp != NULL) {
1351 g_print_bio(fdc->bp);
1356 fdc->retry += i;
1357 mtx_lock(&fdc->fdc_mtx);
1359 fdc->flags &= ~(FDC_KTHREAD_EXIT | FDC_KTHREAD_ALIVE);
1360 mtx_unlock(&fdc->fdc_mtx);
1371 struct fdc_data *fdc;
1375 fdc = fd->fdc;
1376 mtx_lock(&fdc->fdc_mtx);
1382 bioq_disksort(&fdc->head, bp);
1383 wakeup(&fdc->head);
1390 mtx_unlock(&fdc->fdc_mtx);
1399 struct fdc_data *fdc;
1403 fdc = fd->fdc;
1414 mtx_lock(&fdc->fdc_mtx);
1416 mtx_unlock(&fdc->fdc_mtx);
1417 if (fdc_cmd(fdc, 2, NE7CMD_RECAL, fd->fdsu, 0))
1419 tsleep(fdc, PRIBIO, "fdrecal", hz);
1420 if (fdc_sense_int(fdc, &st0, &cyl) == FD_NOT_VALID)
1426 if (fdc_cmd(fdc, 3, NE7CMD_SEEK, fd->fdsu, 1, 0))
1428 tsleep(fdc, PRIBIO, "fdseek", hz);
1429 if (fdc_sense_int(fdc, &st0, &cyl) == FD_NOT_VALID)
1433 if (fdin_rd(fdc) & FDI_DCHG) {
1436 mtx_lock(&fdc->fdc_mtx);
1438 mtx_unlock(&fdc->fdc_mtx);
1443 if (fdc_sense_drive(fdc, &st3) != 0)
1447 mtx_lock(&fdc->fdc_mtx);
1453 mtx_unlock(&fdc->fdc_mtx);
1610 struct fdc_data *fdc;
1615 fdc = fd->fdc;
1647 mtx_lock(&fdc->fdc_mtx);
1649 mtx_unlock(&fdc->fdc_mtx);
1652 mtx_lock(&fdc->fdc_mtx);
1654 mtx_unlock(&fdc->fdc_mtx);
1675 struct fdc_data * fdc;
1679 fdc = fd->fdc;
1747 fd->fdc->fdc_errs = 0;
1752 if ((fd->fdc->flags & FDC_STAT_VALID) == 0)
1754 memcpy(fsp->status, fd->fdc->status, 7 * sizeof(u_int));
1768 mtx_lock(&fd->fdc->fdc_mtx);
1770 mtx_unlock(&fd->fdc->fdc_mtx);
1810 fdc_release_resources(struct fdc_data *fdc)
1816 dev = fdc->fdc_dev;
1817 if (fdc->fdc_intr)
1818 bus_teardown_intr(dev, fdc->res_irq, fdc->fdc_intr);
1819 fdc->fdc_intr = NULL;
1820 if (fdc->res_irq != NULL)
1821 bus_release_resource(dev, SYS_RES_IRQ, fdc->rid_irq,
1822 fdc->res_irq);
1823 fdc->res_irq = NULL;
1826 if (fdc->resio[i] != NULL && fdc->resio[i] != last) {
1828 fdc->ridio[i], fdc->resio[i]);
1829 last = fdc->resio[i];
1830 fdc->resio[i] = NULL;
1833 if (fdc->res_drq != NULL)
1834 bus_release_resource(dev, SYS_RES_DRQ, fdc->rid_drq,
1835 fdc->res_drq);
1836 fdc->res_drq = NULL;
1876 fdc_initial_reset(device_t dev, struct fdc_data *fdc)
1882 if (fdc_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(4, 240),
1890 if (fdsts_rd(fdc) == 0xff)
1897 fdout_wr(fdc, 0);
1898 fdout_wr(fdc, 0);
1899 if (fdsts_rd(fdc) != 0)
1905 fdout_wr(fdc, FDO_FRST);
1907 if (fdsts_rd(fdc) != 0x80)
1911 if (fdc_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(6, 240),
1925 if (fdc_cmd(fdc, 1, NE7CMD_VERSION, 1, &ic_type))
1927 if (fdc_cmd(fdc, 1, 0x18, 1, &part_id))
1935 fdc->fdct = FDC_NE765;
1941 fdc->fdct = FDC_ENHANCED;
1945 fdc->fdct = FDC_UNKNOWN;
1954 struct fdc_data *fdc;
1957 fdc = device_get_softc(dev);
1963 if (fdc->fdc_intr)
1964 bus_teardown_intr(dev, fdc->res_irq, fdc->fdc_intr);
1965 fdc->fdc_intr = NULL;
1968 mtx_lock(&fdc->fdc_mtx);
1969 fdc->flags |= FDC_KTHREAD_EXIT;
1970 wakeup(&fdc->head);
1971 while ((fdc->flags & FDC_KTHREAD_ALIVE) != 0)
1972 msleep(fdc->fdc_thread, &fdc->fdc_mtx, PRIBIO, "fdcdet", 0);
1973 mtx_unlock(&fdc->fdc_mtx);
1977 fdc_reset(fdc);
1979 fdout_wr(fdc, 0);
1982 if (!(fdc->flags & FDC_NODMA))
1983 isa_dma_release(fdc->dmachan);
1984 fdc_release_resources(fdc);
1985 mtx_destroy(&fdc->fdc_mtx);
1990 * Add a child device to the fdc controller. It will then be probed etc.
2017 struct fdc_data *fdc;
2020 fdc = device_get_softc(dev);
2021 fdc->fdc_dev = dev;
2022 error = fdc_initial_reset(dev, fdc);
2027 error = bus_setup_intr(dev, fdc->res_irq,
2029 ((fdc->flags & FDC_NOFAST) ? INTR_MPSAFE : 0),
2030 ((fdc->flags & FDC_NOFAST) ? NULL : fdc_intr_fast),
2031 ((fdc->flags & FDC_NOFAST) ? fdc_intr : NULL),
2032 fdc, &fdc->fdc_intr);
2037 if (!(fdc->flags & FDC_NODMA)) {
2038 error = isa_dma_acquire(fdc->dmachan);
2040 error = isa_dma_init(fdc->dmachan,
2043 isa_dma_release(fdc->dmachan);
2048 fdc->fdcu = device_get_unit(dev);
2049 fdc->flags |= FDC_NEEDS_RESET;
2051 mtx_init(&fdc->fdc_mtx, "fdc lock", NULL, MTX_DEF);
2055 fdc_reset(fdc);
2057 fdout_wr(fdc, fdc->fdout = 0);
2059 bioq_init(&fdc->head);
2069 struct fdc_data *fdc;
2071 fdc = device_get_softc(dev);
2072 kproc_create(fdc_thread, fdc, &fdc->fdc_thread, 0, 0,
2073 "fdc%d", device_get_unit(dev));
2125 struct fdc_data *fdc;
2131 fdc = device_get_softc(device_get_parent(dev));
2135 fd->fdc = fdc;
2168 mtx_lock(&fdc->fdc_mtx);
2173 fdc->fd = fd;
2174 fdc_reset(fdc); /* XXX reset, then unreset, etc. */
2179 if ((fdc_sense_drive(fdc, &st3) == 0) &&
2182 if (fdc_cmd(fdc, 3, NE7CMD_SEEK, fdsu, 10, 0) == 0) {
2186 fdc_sense_int(fdc, NULL, NULL);
2198 if (fdc_cmd(fdc, 2, NE7CMD_RECAL, fdsu, 0) == 0) {
2203 if (fdc_sense_int(fdc, &st0, NULL) == 0 &&
2211 fdc->fd = NULL;
2212 mtx_unlock(&fdc->fdc_mtx);
2250 fd->fdc = fdc;
2256 callout_init_mtx(&fd->toffhandle, &fd->fdc->fdc_mtx, 0);
2342 DRIVER_MODULE(fd, fdc, fd_driver, fd_devclass, fdc_modevent, 0);