Lines Matching defs:fdc

87 #include <dev/fdc/fdcreg.h>
88 #include <dev/fdc/fdcvar.h>
94 /* configuration flags for fdc */
232 struct fdc_data *fdc; /* pointer to controller structure */
282 * fdc is a pointer to the fdc_data struct for the controller
301 static int enable_fifo(fdc_p fdc);
349 fdout_wr(fdc_p fdc, u_int8_t v)
351 bus_space_write_1(fdc->portt, fdc->porth, FDOUT+fdc->port_off, v);
356 fdsts_rd(fdc_p fdc)
358 return bus_space_read_1(fdc->portt, fdc->porth, FDSTS+fdc->port_off);
362 fddata_wr(fdc_p fdc, u_int8_t v)
364 bus_space_write_1(fdc->portt, fdc->porth, FDDATA+fdc->port_off, v);
368 fddata_rd(fdc_p fdc)
370 return bus_space_read_1(fdc->portt, fdc->porth, FDDATA+fdc->port_off);
375 fdctl_wr(fdc_p fdc, u_int8_t v)
377 bus_space_write_1(fdc->portt, fdc->porth, FDCTL, v);
383 fdin_rd(fdc_p fdc)
385 return bus_space_read_1(fdc->portt, fdc->porth, FDIN);
406 fdc_err(struct fdc_data *fdc, const char *s)
408 fdc->fdc_errs++;
410 if (fdc->fdc_errs < FDC_ERRMAX)
411 device_printf(fdc->fdc_dev, "%s", s);
412 else if (fdc->fdc_errs == FDC_ERRMAX)
413 device_printf(fdc->fdc_dev, "too many errors, not "
427 fd_cmd(struct fdc_data *fdc, int n_out, ...)
440 if (out_fdc(fdc, va_arg(ap, int)) < 0)
446 return fdc_err(fdc, msg);
453 if (fd_in(fdc, ptr) < 0)
459 return fdc_err(fdc, msg);
467 enable_fifo(fdc_p fdc)
471 if ((fdc->flags & FDC_HAS_FIFO) == 0) {
479 if (out_fdc(fdc, I8207X_CONFIG) < 0)
480 return fdc_err(fdc, "Enable FIFO failed\n");
484 while ((i = fdsts_rd(fdc) & (NE7_DIO | NE7_RQM))
487 fdc_reset(fdc);
493 fd_cmd(fdc, 3,
495 fdc_reset(fdc);
496 return fdc_err(fdc, "Enable FIFO failed\n");
498 fdc->flags |= FDC_HAS_FIFO;
501 if (fd_cmd(fdc, 4,
503 return fdc_err(fdc, "Re-enable FIFO failed\n");
508 fd_sense_drive_status(fdc_p fdc, int *st3p)
512 if (fd_cmd(fdc, 2, NE7CMD_SENSED, fdc->fdu, 1, &st3))
514 return fdc_err(fdc, "Sense Drive Status failed\n");
523 fd_sense_int(fdc_p fdc, int *st0p, int *cylp)
527 ret = fd_cmd(fdc, 1, NE7CMD_SENSEI, 1, &st0);
529 (void)fdc_err(fdc,
544 if (fd_in(fdc, &cyl) < 0) {
545 return fdc_err(fdc, "can't get cyl num\n");
556 fd_read_status(fdc_p fdc)
563 * from the hardware, but fdc->status[] wants u_ints and
568 ret = fd_in(fdc, &status);
569 fdc->status[i] = status;
575 fdc->flags |= FDC_STAT_VALID;
577 fdc->flags &= ~FDC_STAT_VALID;
586 static void set_density(fdc_p fdc)
589 bus_space_write_1(fdc->sc_fdsiot, fdc->sc_fdsioh, 0,
592 fdctl_wr(fdc, FDC_RST | FDC_DMAE);
599 struct fdc_data *fdc = fd->fdc;
603 set_motor(fdc, fd->fdsu, TURNON);
604 out_fdc(fdc, NE7CMD_SENSED); /* Sense Drive Status */
606 out_fdc(fdc, fdu); /* Drive number */
608 if ((fd_in(fdc, &status) == 0) && (status & NE7_ST3_RD)) {
609 fdctl_wr(fdc, FDC_DMAE | FDC_MTON);
619 struct fdc_data *fdc;
624 fdc = fd->fdc;
634 bus_space_write_1(fdc->sc_fdemsiot, fdc->sc_fdemsioh, 0,
636 if (!(bus_space_read_1(fdc->sc_fdemsiot, fdc->sc_fdemsioh, 0) &
650 fdc_release_resources(struct fdc_data *fdc)
654 dev = fdc->fdc_dev;
655 if (fdc->fdc_intr) {
656 bus_teardown_intr(dev, fdc->res_irq, fdc->fdc_intr);
657 fdc->fdc_intr = NULL;
659 if (fdc->res_irq != 0) {
660 bus_release_resource(dev, SYS_RES_IRQ, fdc->rid_irq,
661 fdc->res_irq);
662 fdc->res_irq = NULL;
665 if (fdc->res_ctl != 0) {
666 bus_release_resource(dev, SYS_RES_IOPORT, fdc->rid_ctl,
667 fdc->res_ctl);
668 fdc->res_ctl = NULL;
672 if (fdc->res_fdsio != 0) {
673 bus_release_resource(dev, SYS_RES_IOPORT, 3, fdc->res_fdsio);
674 fdc->res_fdsio = NULL;
676 if (fdc->res_fdemsio != 0) {
677 bus_release_resource(dev, SYS_RES_IOPORT, 4, fdc->res_fdemsio);
678 fdc->res_fdemsio = NULL;
681 if (fdc->res_ioport != 0) {
682 bus_release_resource(dev, SYS_RES_IOPORT, fdc->rid_ioport,
683 fdc->res_ioport);
684 fdc->res_ioport = NULL;
686 if (fdc->res_drq != 0) {
687 bus_release_resource(dev, SYS_RES_DRQ, fdc->rid_drq,
688 fdc->res_drq);
689 fdc->res_drq = NULL;
734 fdc_initial_reset(struct fdc_data *fdc)
738 if (fd_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(4, 240),
743 fdout_wr(fdc, 0);
745 fdout_wr(fdc, FDO_FRST);
748 if (fd_cmd(fdc, 3, NE7CMD_SPECIFY, NE7_SPEC_1(3, 240),
758 struct fdc_data *fdc;
761 fdc = device_get_softc(dev);
769 fdc_reset(fdc);
772 fdout_wr(fdc, 0);
775 fdc_release_resources(fdc);
780 * Add a child device to the fdc controller. It will then be probed etc.
807 struct fdc_data *fdc;
810 fdc = device_get_softc(dev);
811 fdc->fdc_dev = dev;
812 error = bus_setup_intr(dev, fdc->res_irq,
813 INTR_TYPE_BIO | INTR_ENTROPY, NULL, fdc_intr, fdc,
814 &fdc->fdc_intr);
819 fdc->fdcu = device_get_unit(dev);
820 fdc->flags |= FDC_NEEDS_RESET;
822 fdc->state = DEVIDLE;
826 fdc_reset(fdc);
829 fdout_wr(fdc, fdc->fdout = 0);
831 bioq_init(&fdc->head);
884 struct fdc_data *fdc;
890 fdc = device_get_softc(device_get_parent(dev));
894 fd->fdc = fdc;
921 if ((fdc->flags & FDC_ISPCMCIA))
946 set_motor(fdc, fdsu, TURNON);
947 fdc_reset(fdc); /* XXX reset, then unreset, etc. */
952 if ((fd_sense_drive_status(fdc, &st3) == 0) &&
955 if (fd_cmd(fdc, 3, NE7CMD_SEEK, fdsu, 10, 0) == 0) {
959 fd_sense_int(fdc, 0, 0);
971 if (fd_cmd(fdc, 2, NE7CMD_RECAL, fdsu, 0) == 0) {
976 if (fd_sense_int(fdc, &st0, 0) == 0 &&
983 set_motor(fdc, fdsu, TURNOFF);
993 if ((fdc->flags & FDC_HAS_FIFO) == 0 &&
994 fdc->fdct == FDC_ENHANCED &&
995 (device_get_flags(fdc->fdc_dev) & FDC_NO_FIFO) == 0 &&
996 enable_fifo(fdc) == 0) {
1035 fd->fdc = fdc;
1104 DRIVER_MODULE(fd, fdc, fd_driver, fd_devclass, 0, 0);
1114 set_motor(struct fdc_data *fdc, int fdsu, int turnon)
1117 bus_space_write_1(fdc->sc_fdsiot, fdc->sc_fdsioh, 0,
1120 fdctl_wr(fdc, FDC_DMAE | FDC_MTON);
1124 fdout = fdc->fdout;
1130 fdc->fdout = fdout;
1131 fdout_wr(fdc, fdout);
1153 if (fd->fdc->state != DEVIDLE && fd->fdc->fdu == fd->fdu) {
1154 fdc_intr(fd->fdc);
1160 set_motor(fd->fdc, fd->fdsu, TURNOFF);
1172 if((fd->fdc->fd == fd) && (fd->fdc->state == MOTORWAIT))
1174 fdc_intr(fd->fdc);
1185 set_motor(fd->fdc, fd->fdsu, TURNON);
1191 fdc_reset(fdc_p fdc)
1195 set_density(fdc);
1197 fdctl_wr(fdc, FDC_RST | FDC_RDY | FDC_DD | FDC_MTON);
1199 fdctl_wr(fdc, FDC_RST | FDC_RDY | FDC_DMAE | FDC_MTON);
1201 fdctl_wr(fdc, FDC_DMAE | FDC_MTON);
1204 fdout_wr(fdc, fdc->fdout & ~(FDO_FRST|FDO_FDMAEN));
1205 TRACE1("[0x%x->FDOUT]", fdc->fdout & ~(FDO_FRST|FDO_FDMAEN));
1208 fdout_wr(fdc, fdc->fdout & ~FDO_FDMAEN);
1209 TRACE1("[0x%x->FDOUT]", fdc->fdout & ~FDO_FDMAEN);
1211 fdout_wr(fdc, fdc->fdout);
1212 TRACE1("[0x%x->FDOUT]", fdc->fdout);
1217 (void)fd_cmd(fdc, 3, NE7CMD_SPECIFY,
1221 (void)fd_cmd(fdc, 3, NE7CMD_SPECIFY,
1225 if (fdc->flags & FDC_HAS_FIFO)
1226 (void) enable_fifo(fdc);
1240 fd_in(struct fdc_data *fdc, int *ptr)
1245 (i = fdsts_rd(fdc) & (NE7_DIO|NE7_RQM)) != (NE7_DIO|NE7_RQM) &&
1249 return (fdc_err(fdc, "ready for output in input\n"));
1255 return (fdc_err(fdc, bootverbose? "input ready timeout\n": 0));
1257 i = fddata_rd(fdc);
1262 i = fddata_rd(fdc);
1270 out_fdc(struct fdc_data *fdc, int x)
1275 (i = fdsts_rd(fdc) & (NE7_DIO|NE7_RQM)) != NE7_RQM &&
1279 return (fdc_err(fdc, "ready for input in output\n"));
1285 return (fdc_err(fdc, bootverbose? "output ready timeout\n": 0));
1288 fddata_wr(fdc, x);
1301 fdc_p fdc;
1310 fdc = fd->fdc;
1311 if ((fdc == NULL) || (fd->type == FDT_NONE))
1373 } else if (fdc->fdout & (FDO_MOEN0 | FDO_MOEN1 |
1375 if ((fdc->fdout & FDO_FDSEL) == fd->fdsu)
1376 unitattn = fdin_rd(fdc) & FDI_DCHG;
1380 set_motor(fdc, fd->fdsu, TURNON);
1381 unitattn = fdin_rd(fdc) & FDI_DCHG;
1382 set_motor(fdc, fd->fdsu, TURNOFF);
1390 if ((fdc->flags & FDC_NODMA) == 0) {
1391 if (fdc->dmacnt++ == 0) {
1392 isa_dma_acquire(fdc->dmachan);
1393 isa_dmainit(fdc->dmachan, MAX_SEC_SIZE);
1408 fdc->dma_overruns = 0;
1417 fdc_p fdc;
1420 fdc = fd->fdc;
1424 if ((fdc->flags & FDC_NODMA) == 0)
1425 if (--fdc->dmacnt == 0)
1426 isa_dma_release(fdc->dmachan);
1437 fdc_p fdc;
1443 fdc = fd->fdc;
1499 bioq_disksort(&fdc->head, bp);
1503 fdstart(fdc);
1523 fdstart(struct fdc_data *fdc)
1528 if(fdc->state == DEVIDLE)
1530 fdc_intr(fdc);
1538 fdc_p fdc;
1541 fdc = xfdc;
1542 TRACE1("fd%d[fd_iotimeout()]", fdc->fdu);
1556 fdc->status[0] = NE7_ST0_IC_IV;
1557 fdc->flags &= ~FDC_STAT_VALID;
1558 fdc->state = IOTIMEDOUT;
1559 fdc_intr(fdc);
1583 fdc_p fdc = xfdc;
1584 while(fdstate(fdc))
1592 #define SET_BCDR(fdc,wr,cnt,port) \
1593 bus_space_write_1(fdc->portt, fdc->porth, fdc->port_off + port, \
1595 bus_space_write_1(fdc->portt, fdc->porth, fdc->port_off + port + 1, \
1602 fdcpio(fdc_p fdc, long flags, caddr_t addr, u_int count)
1607 if (fdc->state != PIOREAD) {
1608 fdc->state = PIOREAD;
1611 SET_BCDR(fdc, 0, count, 0);
1612 bus_space_read_multi_1(fdc->portt, fdc->porth, fdc->port_off +
1615 bus_space_write_multi_1(fdc->portt, fdc->porth, fdc->port_off +
1617 SET_BCDR(fdc, 0, count, 0);
1733 fdstate(fdc_p fdc)
1739 fdu_t fdu = fdc->fdu;
1745 bp = fdc->bp;
1747 bp = bioq_takefirst(&fdc->head);
1749 fdc->bp = bp;
1756 fdc->state = DEVIDLE;
1757 if (fdc->fd) {
1758 device_printf(fdc->fdc_dev,
1760 fdc->fd = (fd_p) 0;
1761 fdc->fdu = -1;
1763 TRACE1("[fdc%d IDLE]", fdc->fdcu);
1769 if (fdc->fd && (fd != fdc->fd))
1783 TRACE1("[%s]", fdstates[fdc->state]);
1787 switch (fdc->state)
1791 fdc->retry = 0;
1793 fdc->fd = fd;
1794 fdc->fdu = fdu;
1799 set_density(fdc);
1808 bus_space_write_1(fdc->sc_fdemsiot,
1809 fdc->sc_fdemsioh,
1819 fdc->fdctl_wr(fdc, fd->ft->trans);
1827 fdc->state = MOTORWAIT;
1835 fdc->state = MOTORWAIT;
1841 set_motor(fdc, fd->fdsu, TURNON);
1843 if (fdc->flags & FDC_NEEDS_RESET) {
1844 fdc->state = RESETCTLR;
1845 fdc->flags &= ~FDC_NEEDS_RESET;
1847 fdc->state = DOSEEK;
1855 fdc->state = SEEKCOMPLETE;
1861 if (fd_cmd(fdc, 3, NE7CMD_SEEK,
1868 fdc->retry = 6; /* try a reset */
1869 return(retrier(fdc));
1872 fdc->state = SEEKWAIT;
1877 timeout(fd_pseudointr, fdc, hz / 16);
1878 fdc->state = SEEKCOMPLETE;
1910 if (fd_sense_int(fdc, &st0, &cyl)
1913 if(fdc->fdct == FDC_NE765
1924 if (fd_sense_drive_status(fdc, &st3))
1934 if(fdc->retry < 3)
1935 fdc->retry = 3;
1936 return (retrier(fdc));
1944 if (fdc->retry < 3)
1945 fdc->retry = 3;
1946 return (retrier(fdc));
1954 if (!rdsectid && !(fdc->flags & FDC_NODMA))
1956 format ? bp->bio_bcount : fdblk, fdc->dmachan);
1969 if(fd_sense_drive_status(fdc, &st3) != 0)
1972 if (!(fdc->flags & FDC_NODMA))
1976 fdc->dmachan);
1977 fdc->retry = 6; /* reset the beast */
1978 return (retrier(fdc));
1989 fdc->status[0] = NE7_ST0_IC_AT;
1990 fdc->status[1] = NE7_ST1_NW;
1991 fdc->status[2] = 0;
1992 fdc->status[3] = fd->track;
1993 fdc->status[4] = head;
1994 fdc->status[5] = sec;
1995 fdc->retry = 8; /* break out immediately */
1996 fdc->state = IOTIMEDOUT; /* not really... */
2003 if (fdc->flags & FDC_NODMA) {
2016 SET_BCDR(fdc, 1, bp->bio_bcount, 0);
2018 (void)fdcpio(fdc,bp->bio_cmd,
2024 if(fd_cmd(fdc, 6, ne7cmd, head << 2 | fdu,
2030 if (!(fdc->flags & FDC_NODMA))
2034 fdc->dmachan);
2035 fdc->retry = 6;
2036 return (retrier(fdc));
2040 if (fd_cmd(fdc, 2, ne7cmd, head << 2 | fdu, 0)) {
2042 fdc->retry = 6;
2043 return (retrier(fdc));
2048 if (fdc->flags & FDC_NODMA) {
2053 SET_BCDR(fdc, 1, fdblk, 0);
2060 (void)fdcpio(fdc,bp->bio_cmd,
2064 if (fd_cmd(fdc, 9,
2076 if (!(fdc->flags & FDC_NODMA))
2080 fdc->dmachan);
2081 fdc->retry = 6;
2082 return (retrier(fdc));
2085 if (!rdsectid && (fdc->flags & FDC_NODMA))
2090 if (read && !fdcpio(fdc,bp->bio_cmd,
2092 fd->tohandle = timeout(fd_iotimeout, fdc, hz);
2100 fdc->state = IOCOMPLETE;
2101 fd->tohandle = timeout(fd_iotimeout, fdc, hz);
2109 (void)fdcpio(fdc,bp->bio_cmd,bp->bio_data+fd->skip,fdblk);
2110 fdc->state = IOCOMPLETE;
2113 untimeout(fd_iotimeout, fdc, fd->tohandle);
2115 if (fd_read_status(fdc)) {
2116 if (!rdsectid && !(fdc->flags & FDC_NODMA))
2119 fdc->dmachan);
2120 if (fdc->retry < 6)
2121 fdc->retry = 6; /* force a reset */
2122 return (retrier(fdc));
2125 fdc->state = IOTIMEDOUT;
2129 if (!rdsectid && !(fdc->flags & FDC_NODMA))
2131 format ? bp->bio_bcount : fdblk, fdc->dmachan);
2132 if (fdc->status[0] & NE7_ST0_IC) {
2133 if ((fdc->status[0] & NE7_ST0_IC) == NE7_ST0_IC_AT
2134 && fdc->status[1] & NE7_ST1_OR) {
2147 if (fdc->dma_overruns++ < FDC_DMAOV_MAX) {
2148 fdc->state = SEEKCOMPLETE;
2152 if((fdc->status[0] & NE7_ST0_IC) == NE7_ST0_IC_IV
2153 && fdc->retry < 6)
2154 fdc->retry = 6; /* force a reset */
2155 else if((fdc->status[0] & NE7_ST0_IC) == NE7_ST0_IC_AT
2156 && fdc->status[2] & NE7_ST2_WC
2157 && fdc->retry < 3)
2158 fdc->retry = 3; /* force recalibrate */
2159 return (retrier(fdc));
2165 idp->cyl = fdc->status[3];
2166 idp->head = fdc->status[4];
2167 idp->sec = fdc->status[5];
2168 idp->secshift = fdc->status[6];
2171 fdc->dma_overruns = 0;
2175 fdc->state = DOSEEK;
2180 fdc->bp = NULL;
2183 fdc->fd = (fd_p) 0;
2184 fdc->fdu = -1;
2185 fdc->state = FINDWORK;
2190 fdc_reset(fdc);
2191 fdc->retry++;
2192 fdc->state = RESETCOMPLETE;
2201 (void)fd_sense_int(fdc, &st0, &cyl);
2202 fdc->state = STARTRECAL;
2208 if(fd_cmd(fdc, 2, NE7CMD_RECAL, fdu, 0)) {
2210 fdc->retry = 6;
2211 return (retrier(fdc));
2213 fdc->state = RECALWAIT;
2218 timeout(fd_pseudointr, fdc, hz / 8);
2219 fdc->state = RECALCOMPLETE;
2227 if (fd_sense_int(fdc, &st0, &cyl) == FD_NOT_VALID)
2229 if(fdc->fdct == FDC_NE765
2235 if(fdc->retry > 3)
2246 if(fdc->retry < 3) fdc->retry = 3;
2247 return (retrier(fdc));
2251 fdc->state = DOSEEK;
2259 if (fdc->flags & FDC_NEEDS_RESET) {
2260 fdc->state = RESETCTLR;
2261 fdc->flags &= ~FDC_NEEDS_RESET;
2263 fdc->state = DOSEEK;
2267 device_printf(fdc->fdc_dev, "unexpected FD int->");
2268 if (fd_read_status(fdc) == 0)
2270 fdc->status[0],
2271 fdc->status[1],
2272 fdc->status[2],
2273 fdc->status[3],
2274 fdc->status[4],
2275 fdc->status[5],
2276 fdc->status[6] );
2279 if (fd_sense_int(fdc, &st0, &cyl) != 0)
2291 retrier(struct fdc_data *fdc)
2297 bp = fdc->bp;
2305 switch (fdc->retry) {
2307 fdc->state = SEEKCOMPLETE;
2310 fdc->state = STARTRECAL;
2313 fdc->state = RESETCTLR;
2321 fdc->fd->skip / DEV_BSIZE, 0);
2322 if (fdc->flags & FDC_STAT_VALID) {
2325 fdc->status[0], NE7_ST0BITS,
2326 fdc->status[1], NE7_ST1BITS,
2327 fdc->status[2], NE7_ST2BITS,
2328 fdc->status[3], fdc->status[4],
2329 fdc->status[5]);
2337 bp->bio_resid = bp->bio_bcount - fdc->fd->skip;
2340 fdc->bp = NULL;
2341 fdc->fd->skip = 0;
2343 biofinish(bp, fdc->fd->device_stats, 0);
2344 fdc->state = FINDWORK;
2345 fdc->flags |= FDC_NEEDS_RESET;
2346 fdc->fd = (fd_p) 0;
2347 fdc->fdu = -1;
2350 fdc->retry++;
2506 fd->fdc->fdc_errs = 0;
2511 if ((fd->fdc->flags & FDC_STAT_VALID) == 0)
2513 memcpy(fsp->status, fd->fdc->status, 7 * sizeof(u_int));
2574 fd->fdc->fdc_errs = 0;
2579 if ((fd->fdc->flags & FDC_STAT_VALID) == 0)
2581 memcpy(fsp->status, fd->fdc->status, 7 * sizeof(u_int));