Lines Matching defs:fdc
430 establish_chip_type(struct fdc_softc *fdc,
475 fdc->sc_flags |= FDC_82077;
488 * the drive). If `fdc' is not NULL, the drive was found but was not
494 fdprint(void *aux, const char *fdc)
498 if (!fdc)
504 * Configure several parameters and features on the FDC.
508 fdconf(struct fdc_softc *fdc)
512 if (fdc_wrfifo(fdc, NE7CMD_DUMPREG) || fdcresult(fdc) != 10)
519 if ((vroom = fdc->sc_status[7]) == 0)
523 if (fdc_wrfifo(fdc, NE7CMD_CFG) != 0)
525 if (fdc_wrfifo(fdc, vroom) != 0)
527 if (fdc_wrfifo(fdc, fdc->sc_cfg) != 0)
529 if (fdc_wrfifo(fdc, 0) != 0) /* PRETRK */
533 if ((fdc
535 if (fdc_wrfifo(fdc, NE7CMD_LOCK | CFG_LOCK) != 0 ||
536 fdcresult(fdc) != 1) {
546 if (fdc_wrfifo(fdc, NE7CMD_VERSION) == 0 &&
547 fdcresult(fdc) == 1 && fdc->sc_status[0] == 0x90) {
557 struct fdc_softc *fdc = device_private(self);
560 fdc->sc_dev = self;
561 fdc->sc_bustag = ma->ma_bustag;
568 &fdc->sc_handle) != 0) {
573 establish_chip_type(fdc,
577 fdc->sc_handle);
579 if (fdcattach(fdc, ma->ma_pri) != 0)
580 bus_space_unmap(ma->ma_bustag, fdc->sc_handle, ma->ma_size);
586 struct fdc_softc *fdc = device_private(self);
595 fdc->sc_dev = self;
596 fdc->sc_bustag = sa->sa_bustag;
600 BUS_SPACE_MAP_LINEAR, &fdc->sc_handle) != 0) {
606 establish_chip_type(fdc,
610 fdc->sc_handle);
617 if (fdcattach(fdc, sa->sa_pri) != 0)
618 bus_space_unmap(sa->sa_bustag, fdc->sc_handle, sa->sa_size);
622 fdcattach(struct fdc_softc *fdc, int pri)
628 callout_init(&fdc->sc_timo_ch, 0);
629 callout_init(&fdc->sc_intr_ch, 0);
631 fdc->sc_state = DEVIDLE;
632 fdc->sc_itask = FDC_ITASK_NONE;
633 fdc->sc_istatus = FDC_ISTATUS_NONE;
634 fdc->sc_flags |= FDC_EIS;
635 TAILQ_INIT(&fdc->sc_drives);
637 if ((fdc->sc_flags & FDC_82077) != 0) {
638 fdc->sc_reg_msr = FDREG77_MSR;
639 fdc->sc_reg_fifo = FDREG77_FIFO;
640 fdc->sc_reg_dor = FDREG77_DOR;
641 fdc->sc_reg_dir = FDREG77_DIR;
643 fdc->sc_flags |= FDC_NEEDMOTORWAIT;
645 fdc->sc_reg_msr = FDREG72_MSR;
646 fdc->sc_reg_fifo = FDREG72_FIFO;
647 fdc->sc_reg_dor = 0;
655 fdc->sc_cfg = CFG_EIS|/*CFG_EFIFO|*/CFG_POLL|(8 & CFG_THRHLD_MASK);
656 if (fdconf(fdc) != 0) {
661 fdciop = &fdc->sc_io;
662 if (bus_intr_establish2(fdc->sc_bustag, pri, 0,
663 fdc_c_hwintr, fdc,
671 device_xname(fdc->sc_dev));
675 fdc->sc_sicookie = softint_establish(SOFTINT_BIO, fdcswintr, fdc);
676 if (fdc->sc_sicookie == NULL) {
678 device_xname(fdc->sc_dev));
683 evcnt_attach_dynamic(&fdc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
684 device_xname(fdc->sc_dev), "intr");
691 if (config_found(fdc->sc_dev, (void *)&fa, fdprint,
707 struct fdc_softc *fdc = device_private(parent);
708 bus_space_tag_t t = fdc->sc_bustag;
709 bus_space_handle_t h = fdc->sc_handle;
718 if ((fdc->sc_flags & FDC_82077) != 0) {
720 bus_space_write_1(t, h, fdc->sc_reg_dor,
727 fdc->sc_nstat = 0;
728 fdc_wrfifo(fdc, NE7CMD_RECAL);
729 fdc_wrfifo(fdc, drive);
736 v = bus_space_read_1(t, h, fdc->sc_reg_msr);
740 if (fdc_wrfifo(fdc, NE7CMD_SENSEI))
742 if (fdcresult(fdc) == 1 && fdc->sc_status[0] == 0x80)
752 n = fdc->sc_nstat;
758 printf(" 0x%x", fdc->sc_status[i]);
762 ok = (n == 2 && (fdc->sc_status[0] & 0xf8) == 0x20) ? 1 : 0;
765 if ((fdc->sc_flags & FDC_82077) != 0) {
767 bus_space_write_1(t, h, fdc->sc_reg_dor, FDO_FRST | FDO_DS);
781 struct fdc_softc *fdc = device_private(parent);
804 fdc->sc_fd[drive] = fd;
806 fdc_wrfifo(fdc, NE7CMD_SPECIFY);
807 fdc_wrfifo(fdc, type->steprate);
809 fdc_wrfifo(fdc, 6 | NE7_SPECIFY_NODMA);
913 struct fdc_softc *fdc = device_private(device_parent(fd->sc_dv));
914 if (fdc->sc_state == DEVIDLE) {
916 fdcstart(fdc);
931 struct fdc_softc *fdc = device_private(device_parent(fd->sc_dv));
932 int active = fdc->sc_drives.tqh_first != 0;
936 TAILQ_INSERT_TAIL(&fdc->sc_drives, fd, sc_drivechain);
940 fdcstart(fdc);
946 struct fdc_softc *fdc = device_private(device_parent(fd->sc_dv));
957 TAILQ_REMOVE(&fdc->sc_drives, fd, sc_drivechain);
959 TAILQ_INSERT_TAIL(&fdc->sc_drives, fd, sc_drivechain);
969 fdc->sc_state = DEVIDLE;
973 fdc_reset(struct fdc_softc *fdc)
975 bus_space_tag_t t = fdc->sc_bustag;
976 bus_space_handle_t h = fdc->sc_handle;
978 if ((fdc->sc_flags & FDC_82077) != 0) {
979 bus_space_write_1(t, h, fdc->sc_reg_dor,
983 bus_space_write_1(t, h, fdc->sc_reg_drs, DRS_RESET);
985 bus_space_write_1(t, h, fdc->sc_reg_drs, 0);
987 if ((fdc->sc_flags & FDC_82077) != 0) {
988 bus_space_write_1(t, h, fdc->sc_reg_dor,
993 printf("fdc reset\n");
998 fd_set_motor(struct fdc_softc *fdc)
1004 if ((fdc->sc_flags & FDC_82077) != 0) {
1006 if ((fd = fdc->sc_drives.tqh_first) != NULL)
1010 if ((fd = fdc->sc_fd[n]) && (fd->sc_flags & FD_MOTOR))
1012 bus_space_write_1(fdc->sc_bustag, fdc->sc_handle,
1013 fdc->sc_reg_dor, status);
1017 if ((fd = fdc->sc_fd[n]) != NULL &&
1043 struct fdc_softc *fdc = device_private(device_parent(fd->sc_dv));
1048 if ((fdc->sc_drives.tqh_first == fd) && (fdc->sc_state == MOTORWAIT))
1049 (void) fdcstate(fdc);
1054 * Get status bytes off the FDC after a command has finished
1059 fdcresult(struct fdc_softc *fdc)
1061 bus_space_tag_t t = fdc->sc_bustag;
1062 bus_space_handle_t h = fdc->sc_handle;
1066 uint8_t v = bus_space_read_1(t, h, fdc->sc_reg_msr);
1069 return (fdc->sc_nstat = n);
1071 if (n >= sizeof(fdc->sc_status)) {
1075 fdc->sc_status[n++] =
1076 bus_space_read_1(t, h, fdc->sc_reg_fifo);
1082 return (fdc->sc_nstat = -1);
1086 * Write a command byte to the FDC.
1090 fdc_wrfifo(struct fdc_softc *fdc, uint8_t x)
1092 bus_space_tag_t t = fdc->sc_bustag;
1093 bus_space_handle_t h = fdc->sc_handle;
1097 uint8_t v = bus_space_read_1(t, h, fdc->sc_reg_msr);
1100 bus_space_write_1(t, h, fdc->sc_reg_fifo, x);
1109 fdc_diskchange(struct fdc_softc *fdc)
1112 if (CPU_ISSUN4M && (fdc->sc_flags & FDC_82077) != 0) {
1113 bus_space_tag_t t = fdc->sc_bustag;
1114 bus_space_handle_t h = fdc->sc_handle;
1115 uint8_t v = bus_space_read_1(t, h, fdc->sc_reg_dir);
1208 fdcstart(struct fdc_softc *fdc)
1214 if (fdc->sc_state != DEVIDLE) {
1219 (void) fdcstate(fdc);
1223 fdcpstatus(int n, struct fdc_softc *fdc)
1232 snprintb(bits, sizeof(bits), NE7_ST0BITS, fdc->sc_status[0]);
1233 printf(" (st0 %s cyl %d)\n", bits, fdc->sc_status[1]);
1236 snprintb(bits, sizeof(bits), NE7_ST0BITS, fdc->sc_status[0]);
1238 snprintb(bits, sizeof(bits), NE7_ST1BITS, fdc->sc_status[1]);
1240 snprintb(bits, sizeof(bits), NE7_ST2BITS, fdc->sc_status[2]);
1243 fdc->sc_status[3], fdc->sc_status[4], fdc->sc_status[5]);
1254 fdcstatus(struct fdc_softc *fdc, const char *s)
1256 struct fd_softc *fd = fdc->sc_drives.tqh_first;
1260 n = fdc->sc_nstat;
1267 if (n == 0 && (fdc->sc_flags & FDC_82077) != 0) {
1268 fdc_wrfifo(fdc, NE7CMD_SENSEI);
1269 (void) fdcresult(fdc);
1275 fd ? device_xname(fd->sc_dv) : "fdc", s, fdc->sc_state);
1277 fdcpstatus(n, fdc);
1283 struct fdc_softc *fdc = arg;
1288 fd = fdc->sc_drives.tqh_first;
1291 device_xname(fdc->sc_dev),
1292 fdc->sc_state, fdc->sc_istatus);
1293 fdc->sc_state = DEVIDLE;
1298 fdc->sc_state++;
1300 fdc->sc_state = DEVIDLE;
1302 (void) fdcstate(fdc);
1311 struct fdc_softc *fdc = arg;
1316 (void) fdcstate(fdc);
1331 struct fdc_softc *fdc = arg;
1332 bus_space_tag_t t = fdc->sc_bustag;
1333 bus_space_handle_t h = fdc->sc_handle;
1335 switch (fdc->sc_itask) {
1339 if (fdc_wrfifo(fdc, NE7CMD_SENSEI) != 0 || fdcresult(fdc) == -1)
1340 fdc->sc_istatus = FDC_ISTATUS_ERROR;
1342 fdc->sc_istatus = FDC_ISTATUS_DONE;
1343 softint_schedule(fdc->sc_sicookie);
1346 if (fdcresult(fdc) == -1)
1347 fdc->sc_istatus = FDC_ISTATUS_ERROR;
1349 fdc->sc_istatus = FDC_ISTATUS_DONE;
1350 softint_schedule(fdc->sc_sicookie);
1356 printf("fdc: stray hard interrupt: itask=%d\n", fdc->sc_itask);
1357 fdc->sc_istatus = FDC_ISTATUS_SPURIOUS;
1358 softint_schedule(fdc->sc_sicookie);
1368 msr = bus_space_read_1(t, h, fdc->sc_reg_msr);
1376 fdcresult(fdc);
1377 fdc->sc_istatus = FDC_ISTATUS_DONE;
1378 softint_schedule(fdc->sc_sicookie);
1382 if (fdc->sc_tc == 0)
1385 panic("fdc: overrun");
1389 *fdc->sc_data =
1390 bus_space_read_1(t, h, fdc->sc_reg_fifo);
1392 bus_space_write_1(t, h, fdc->sc_reg_fifo,
1393 *fdc->sc_data);
1395 fdc->sc_data++;
1396 if (--fdc->sc_tc == 0) {
1407 struct fdc_softc *fdc = arg;
1409 if (fdc->sc_istatus == FDC_ISTATUS_NONE)
1413 switch (fdc->sc_istatus) {
1415 printf("fdc: ierror status: state %d\n", fdc->sc_state);
1418 printf("fdc: spurious interrupt: state %d\n", fdc->sc_state);
1422 fdcstate(fdc);
1427 fdcstate(struct fdc_softc *fdc)
1430 #define st0 fdc->sc_status[0]
1431 #define st1 fdc->sc_status[1]
1432 #define cyl fdc->sc_status[1]
1433 #define FDC_WRFIFO(fdc, c) do { \
1434 if (fdc_wrfifo(fdc, (c))) { \
1445 if (fdc->sc_istatus == FDC_ISTATUS_ERROR) {
1447 if (fdc->sc_state != RESETCOMPLETE &&
1448 fdc->sc_state != RECALWAIT &&
1449 fdc->sc_state != RECALCOMPLETE)
1450 fdc->sc_state = DORESET;
1454 fdc->sc_istatus = FDC_ISTATUS_NONE;
1455 fdc->sc_itask = FDC_ITASK_NONE;
1459 fd = fdc->sc_drives.tqh_first;
1461 fdc->sc_state = DEVIDLE;
1469 TAILQ_REMOVE(&fdc->sc_drives, fd, sc_drivechain);
1477 switch (fdc->sc_state) {
1479 fdc->sc_errors = 0;
1485 fdc->sc_state = MOTORWAIT;
1490 struct fd_softc *ofd = fdc->sc_fd[fd->sc_drive ^ 1];
1496 fd_set_motor(fdc);
1497 fdc->sc_state = MOTORWAIT;
1498 if ((fdc->sc_flags & FDC_NEEDMOTORWAIT) != 0) { /*XXX*/
1509 fd_set_motor(fdc);
1511 if (fdc_diskchange(fdc))
1517 if ((fdc->sc_flags & FDC_EIS) &&
1528 fdc->sc_state = SEEKWAIT;
1529 fdc->sc_nstat = 0;
1534 callout_reset(&fdc->sc_timo_ch, 4 * hz, fdctimeout, fdc);
1537 FDC_WRFIFO(fdc, NE7CMD_SPECIFY);
1538 FDC_WRFIFO(fdc, fd->sc_type->steprate);
1540 FDC_WRFIFO(fdc, 6 | NE7_SPECIFY_NODMA);
1542 fdc->sc_itask = FDC_ITASK_SENSEI;
1544 FDC_WRFIFO(fdc, NE7CMD_SEEK);
1545 FDC_WRFIFO(fdc, fd->sc_drive); /* drive number */
1546 FDC_WRFIFO(fdc, bp->b_cylinder * fd->sc_type->step);
1556 callout_reset(&fdc->sc_timo_ch, 4 * hz, fdctimeout, fdc);
1558 fdc->sc_nstat = 0;
1559 fdc->sc_state = DSKCHGWAIT;
1561 fdc->sc_itask = FDC_ITASK_SENSEI;
1563 FDC_WRFIFO(fdc, NE7CMD_SEEK);
1564 FDC_WRFIFO(fdc, fd->sc_drive); /* drive number */
1565 FDC_WRFIFO(fdc, 1 * fd->sc_type->step);
1569 callout_stop(&fdc->sc_timo_ch);
1571 if (fdc->sc_nstat != 2 || (st0 & 0xf8) != 0x20 ||
1573 fdcstatus(fdc, "dskchg seek failed");
1574 fdc->sc_state = DORESET;
1576 fdc->sc_state = DORECAL;
1578 if (fdc_diskchange(fdc)) {
1580 device_xname(fdc->sc_dev));
1581 fdc->sc_state = DORESET;
1612 fdc->sc_data = (char *)bp->b_data + fd->sc_skip;
1613 fdc->sc_tc = fd->sc_nbytes;
1615 bus_space_write_1(fdc->sc_bustag, fdc->sc_handle,
1616 fdc->sc_reg_drs, type->rate);
1625 fdc->sc_state = IOCOMPLETE;
1626 fdc->sc_itask = FDC_ITASK_DMA;
1627 fdc->sc_nstat = 0;
1632 callout_reset(&fdc->sc_timo_ch, 3 * hz, fdctimeout, fdc);
1636 FDC_WRFIFO(fdc, NE7CMD_FORMAT);
1637 FDC_WRFIFO(fdc, (head << 2) | fd->sc_drive);
1638 FDC_WRFIFO(fdc, finfo->fd_formb_secshift);
1639 FDC_WRFIFO(fdc, finfo->fd_formb_nsecs);
1640 FDC_WRFIFO(fdc, finfo->fd_formb_gaplen);
1641 FDC_WRFIFO(fdc, finfo->fd_formb_fillbyte);
1644 FDC_WRFIFO(fdc, NE7CMD_READ);
1646 FDC_WRFIFO(fdc, NE7CMD_WRITE);
1647 FDC_WRFIFO(fdc, (head << 2) | fd->sc_drive);
1648 FDC_WRFIFO(fdc, fd->sc_cylin); /*track*/
1649 FDC_WRFIFO(fdc, head);
1650 FDC_WRFIFO(fdc, sec + 1); /*sector+1*/
1651 FDC_WRFIFO(fdc, type->secsize);/*sector size*/
1652 FDC_WRFIFO(fdc, type->sectrac);/*secs/track*/
1653 FDC_WRFIFO(fdc, type->gap1); /*gap1 size*/
1654 FDC_WRFIFO(fdc, type->datalen);/*data length*/
1660 callout_stop(&fdc->sc_timo_ch);
1661 fdc->sc_state = SEEKCOMPLETE;
1662 if (fdc->sc_flags & FDC_NEEDHEADSETTLE) {
1664 callout_reset(&fdc->sc_intr_ch, hz / 50,
1665 fdcpseudointr, fdc);
1674 if (fdc->sc_nstat != 2 || (st0 & 0xf8) != 0x20 ||
1678 fdcstatus(fdc, "seek failed");
1680 fdcretry(fdc);
1692 fdc->sc_itask = FDC_ITASK_RESULT;
1693 fdc->sc_state = IOCLEANUPWAIT;
1694 fdc->sc_nstat = 0;
1696 callout_reset(&fdc->sc_timo_ch, hz / 10, fdctimeout, fdc);
1705 fdcstatus(fdc, "timeout");
1708 fdcretry(fdc);
1711 fdc->sc_state = DORESET;
1715 callout_stop(&fdc->sc_timo_ch);
1718 fdcretry(fdc);
1722 callout_stop(&fdc->sc_timo_ch);
1727 if (fdc->sc_nstat != 7 || st1 != 0 ||
1729 ((st0 & 0xf8) != 0x20 || (fdc->sc_cfg & CFG_EIS) == 0))) {
1732 fdcstatus(fdc,
1737 fdc->sc_nstat, fdc->sc_tc);
1740 if (fdc->sc_nstat == 7 &&
1747 int thr = fdc->sc_cfg & CFG_THRHLD_MASK;
1750 fdc->sc_cfg &= ~CFG_THRHLD_MASK;
1751 fdc->sc_cfg |= (thr & CFG_THRHLD_MASK);
1754 printf("fdc: %d -> threshold\n", thr);
1756 fdconf(fdc);
1757 fdc->sc_overruns = 0;
1759 if (++fdc->sc_overruns < 3) {
1760 fdc->sc_state = DOIO;
1764 fdcretry(fdc);
1767 if (fdc->sc_errors) {
1772 fdc->sc_errors = 0;
1774 if (--fdc->sc_overruns < -20) {
1775 int thr = fdc->sc_cfg & CFG_THRHLD_MASK;
1778 fdc->sc_cfg &= ~CFG_THRHLD_MASK;
1779 fdc->sc_cfg |= (thr & CFG_THRHLD_MASK);
1782 printf("fdc: %d -> threshold\n", thr);
1784 fdconf(fdc);
1786 fdc->sc_overruns = 0;
1801 fd_set_motor(fdc);
1803 fdc->sc_nstat = 0;
1804 fdc->sc_itask = FDC_ITASK_SENSEI;
1805 fdc->sc_state = RESETCOMPLETE;
1806 callout_reset(&fdc->sc_timo_ch, hz / 2, fdctimeout, fdc);
1807 fdc_reset(fdc);
1811 callout_stop(&fdc->sc_timo_ch);
1812 fdconf(fdc);
1816 fdc->sc_state = RECALWAIT;
1817 fdc->sc_itask = FDC_ITASK_SENSEI;
1818 fdc->sc_nstat = 0;
1819 callout_reset(&fdc->sc_timo_ch, 5 * hz, fdctimeout, fdc);
1821 FDC_WRFIFO(fdc, NE7CMD_RECAL);
1822 FDC_WRFIFO(fdc, fd->sc_drive);
1826 callout_stop(&fdc->sc_timo_ch);
1827 fdc->sc_state = RECALCOMPLETE;
1828 if (fdc->sc_flags & FDC_NEEDHEADSETTLE) {
1830 callout_reset(&fdc->sc_intr_ch, hz / 30,
1831 fdcpseudointr, fdc);
1836 if (fdc->sc_nstat != 2 || (st0 & 0xf8) != 0x20 || cyl != 0) {
1839 fdcstatus(fdc, "recalibrate failed");
1841 fdcretry(fdc);
1853 fdcstatus(fdc, "stray interrupt");
1865 callout_stop(&fdc->sc_timo_ch);
1866 fdcretry(fdc);
1867 (fdc)->sc_state = DORESET;
1876 fdcretry(struct fdc_softc *fdc)
1882 fd = fdc->sc_drives.tqh_first;
1885 fdc->sc_overruns = 0;
1889 switch (fdc->sc_errors) {
1891 if (fdc->sc_nstat == 7 &&
1892 (fdc->sc_status[0] & 0xd8) == 0x40 &&
1893 (fdc->sc_status[1] & 0x2) == 0x2) {
1900 fdc->sc_state =
1901 (fdc->sc_flags & FDC_EIS) ? DOIO : DOSEEK;
1906 fdc->sc_state = DORECAL;
1910 if (fdc->sc_nstat == 7 &&
1911 fdc->sc_status[0] == 0 &&
1912 fdc->sc_status[1] == 0 &&
1913 fdc->sc_status[2] == 0) {
1927 fdc->sc_state = DORESET;
1937 fdcstatus(fdc, "controller status");
1944 fdc->sc_errors++;
1952 struct fdc_softc *fdc;
1968 fdc = device_private(device_parent(fd->sc_dv));
2145 fdc_wrfifo(fdc, NE7CMD_DUMPREG);
2146 fdcresult(fdc);
2147 printf("fdc: dumpreg(%d regs): <", fdc->sc_nstat);
2148 for (i = 0; i < fdc->sc_nstat; i++)
2149 printf(" 0x%x", fdc->sc_status[i]);
2154 fdc->sc_cfg &= ~CFG_THRHLD_MASK;
2155 fdc->sc_cfg |= (*(int *)addr & CFG_THRHLD_MASK);
2156 fdconf(fdc);
2160 fdc_wrfifo(fdc, NE7CMD_SENSEI);
2161 fdcresult(fdc);
2162 printf("fdc: sensei(%d regs): <", fdc->sc_nstat);
2163 for (i=0; i< fdc->sc_nstat; i++)
2164 printf(" 0x%x", fdc->sc_status[i]);
2306 struct fdc_softc *fdc = device_private(device_parent(fd->sc_dv));
2314 if (CPU_ISSUN4M && (fdc->sc_flags & FDC_82077) != 0) {
2315 bus_space_tag_t t = fdc->sc_bustag;
2316 bus_space_handle_t h = fdc->sc_handle;
2319 bus_space_write_1(t, h, fdc->sc_reg_dor, dor | FDO_EJ);
2321 bus_space_write_1(t, h, fdc->sc_reg_dor, FDO_FRST | FDO_DS);