Lines Matching refs:fd

1 /*	$NetBSD: fd.c,v 1.52 2023/08/29 21:55:11 andvar Exp $	*/
2 /* $OpenBSD: fd.c,v 1.6 1998/10/03 21:18:57 millert Exp $ */
3 /* NetBSD: fd.c,v 1.78 1995/07/04 07:23:09 mycroft Exp */
65 * @(#)fd.c 7.4 (Berkeley) 5/25/91
69 __KERNEL_RCSID(0, "$NetBSD: fd.c,v 1.52 2023/08/29 21:55:11 andvar Exp $");
180 CFATTACH_DECL_NEW(fd, sizeof(struct fd_softc), fdprobe, fdattach, NULL, NULL);
337 struct fd_softc *fd = device_private(self);
342 fd->sc_dev = self;
344 callout_init(&fd->sc_motoron_ch, 0);
345 callout_init(&fd->sc_motoroff_ch, 0);
355 bufq_alloc(&fd->sc_q, "disksort", BUFQ_SORT_CYLINDER);
356 fd->sc_cylin = -1;
357 fd->sc_drive = drive;
358 fd->sc_deftype = type;
359 fdc->sc_fd[drive] = fd;
364 disk_init(&fd->sc_dk, device_xname(fd->sc_dev), &fddkdriver);
365 disk_attach(&fd->sc_dk);
368 mountroothook_establish(fd_mountroot_hook, fd->sc_dev);
378 struct fd_softc *fd;
380 fd = device_private(self);
381 fd_motor_off(fd);
424 fd_dev_to_type(struct fd_softc *fd, dev_t dev)
430 return type ? &fd_types[type - 1] : fd->sc_deftype;
436 struct fd_softc *fd = device_lookup_private(&fd_cd, FDUNIT(bp->b_dev));
453 if (bp->b_blkno + sz > fd->sc_type->size) {
454 sz = fd->sc_type->size - bp->b_blkno;
470 bp->b_blkno / (FDC_BSIZE / DEV_BSIZE) / fd->sc_type->seccyl;
475 bp->b_blkno, bp->b_bcount, fd->sc_blkno, bp->b_cylinder, sz);
480 bufq_put(fd->sc_q, bp);
481 callout_stop(&fd->sc_motoroff_ch); /* a good idea */
482 if (fd->sc_active == 0)
483 fdstart(fd);
487 device_private(device_parent(fd->sc_dev));
504 fdstart(struct fd_softc *fd)
506 struct fdc_softc *fdc = device_private(device_parent(fd->sc_dev));
510 fd->sc_active = 1;
511 TAILQ_INSERT_TAIL(&fdc->sc_drives, fd, sc_drivechain);
519 fdfinish(struct fd_softc *fd, struct buf *bp)
521 struct fdc_softc *fdc = device_private(device_parent(fd->sc_dev));
529 (void)bufq_get(fd->sc_q);
530 if (TAILQ_NEXT(fd, sc_drivechain) && ++fd->sc_ops >= 8) {
531 fd->sc_ops = 0;
532 TAILQ_REMOVE(&fdc->sc_drives, fd, sc_drivechain);
533 if (bufq_peek(fd->sc_q) != NULL)
534 TAILQ_INSERT_TAIL(&fdc->sc_drives, fd, sc_drivechain);
536 fd->sc_active = 0;
538 bp->b_resid = fd->sc_bcount;
539 fd->sc_skip = 0;
542 callout_reset(&fd->sc_motoroff_ch, 5 * hz, fd_motor_off, fd);
563 struct fd_softc *fd;
567 if ((fd = TAILQ_FIRST(&fdc->sc_drives)) != NULL)
568 status = fd->sc_drive;
574 if ((fd = fdc->sc_fd[n]) && (fd->sc_flags & FD_MOTOR))
582 struct fd_softc *fd = arg;
583 struct fdc_softc *fdc = device_private(device_parent(fd->sc_dev));
587 fd->sc_flags &= ~(FD_MOTOR | FD_MOTOR_WAIT);
595 struct fd_softc *fd = arg;
596 struct fdc_softc *fdc = device_private(device_parent(fd->sc_dev));
600 fd->sc_flags &= ~FD_MOTOR_WAIT;
601 if ((TAILQ_FIRST(&fdc->sc_drives) == fd) &&
652 struct fd_softc *fd;
655 fd = device_lookup_private(&fd_cd, FDUNIT(dev));
656 if (fd == NULL)
659 type = fd_dev_to_type(fd, dev);
663 if ((fd->sc_flags & FD_OPEN) != 0 &&
664 memcmp(fd->sc_type, type, sizeof(*type)))
667 fd->sc_type_copy = *type;
668 fd->sc_type = &fd->sc_type_copy;
669 fd->sc_cylin = -1;
670 fd->sc_flags |= FD_OPEN;
678 struct fd_softc *fd = device_lookup_private(&fd_cd, FDUNIT(dev));
680 fd->sc_flags &= ~FD_OPEN;
749 struct fd_softc *fd = TAILQ_FIRST(&fdc->sc_drives);
756 fdcstatus(fd->sc_dev, 0, "timeout");
758 if (bufq_peek(fd->sc_q) != NULL)
784 struct fd_softc *fd;
793 fd = TAILQ_FIRST(&fdc->sc_drives);
794 if (fd == NULL) {
800 bp = bufq_peek(fd->sc_q);
802 fd->sc_ops = 0;
803 TAILQ_REMOVE(&fdc->sc_drives, fd, sc_drivechain);
804 fd->sc_active = 0;
811 fd->sc_skip = 0;
812 fd->sc_bcount = bp->b_bcount;
813 fd->sc_blkno = bp->b_blkno / (FDC_BSIZE / DEV_BSIZE);
814 callout_stop(&fd->sc_motoroff_ch);
815 if ((fd->sc_flags & FD_MOTOR_WAIT) != 0) {
819 if ((fd->sc_flags & FD_MOTOR) == 0) {
821 struct fd_softc *ofd = fdc->sc_fd[fd->sc_drive ^ 1];
826 fd->sc_flags |= FD_MOTOR | FD_MOTOR_WAIT;
830 callout_reset(&fd->sc_motoron_ch, hz / 4,
831 fd_motor_on, fd);
840 if (fd->sc_cylin == bp->b_cylinder)
844 out_fdc(iot, ioh, fd->sc_type->steprate);
848 out_fdc(iot, ioh, fd->sc_drive); /* drive number */
849 out_fdc(iot, ioh, bp->b_cylinder * fd->sc_type->step);
851 fd->sc_cylin = -1;
854 iostat_seek(fd->sc_dk.dk_stats);
855 disk_busy(&fd->sc_dk);
862 type = fd->sc_type;
863 sec = fd->sc_blkno % type->seccyl;
865 nblks = uimin(nblks, fd->sc_bcount / FDC_BSIZE);
867 fd->sc_nblks = nblks;
868 fd->sc_nbytes = nblks * FDC_BSIZE;
874 block = (fd->sc_cylin * type->heads + head) *
876 if (block != fd->sc_blkno) {
878 "\n", __func__, block, fd->sc_blkno);
886 FDCDMA_START(fdc, (uint8_t *)bp->b_data + fd->sc_skip,
887 fd->sc_nbytes, read);
891 __func__, read ? "read" : "write", fd->sc_drive,
892 fd->sc_cylin, head, sec, nblks);
898 out_fdc(iot, ioh, (head << 2) | fd->sc_drive);
899 out_fdc(iot, ioh, fd->sc_cylin); /* track */
908 disk_busy(&fd->sc_dk);
922 disk_unbusy(&fd->sc_dk, 0, 0);
927 cyl != bp->b_cylinder * fd->sc_type->step) {
929 fdcstatus(fd->sc_dev, 2, "seek failed");
934 fd->sc_cylin = bp->b_cylinder;
949 disk_unbusy(&fd->sc_dk, (bp->b_bcount - bp->b_resid),
956 fdcstatus(fd->sc_dev, 7, bp->b_flags & B_READ ?
959 fd->sc_blkno, fd->sc_nblks);
966 diskerr(bp, "fd", "soft error (corrected)", LOG_PRINTF,
967 fd->sc_skip / FDC_BSIZE, NULL);
971 fd->sc_blkno += fd->sc_nblks;
972 fd->sc_skip += fd->sc_nbytes;
973 fd->sc_bcount -= fd->sc_nbytes;
974 if (fd->sc_bcount > 0) {
975 bp->b_cylinder = fd->sc_blkno / fd->sc_type->seccyl;
978 fdfinish(fd, bp);
1001 out_fdc(iot, ioh, fd->sc_drive);
1017 fdcstatus(fd->sc_dev, 2, "recalibrate failed");
1022 fd->sc_cylin = 0;
1026 if (fd->sc_flags & FD_MOTOR_WAIT)
1031 fdcstatus(fd->sc_dev, 0, "stray interrupt");
1044 struct fd_softc *fd;
1047 fd = TAILQ_FIRST(&fdc->sc_drives);
1048 bp = bufq_peek(fd->sc_q);
1069 diskerr(bp, "fd", "hard error", LOG_PRINTF,
1070 fd->sc_skip / FDC_BSIZE, (struct disklabel *)NULL);
1074 fdfinish(fd, bp);
1082 struct fd_softc *fd = device_lookup_private(&fd_cd, FDUNIT(dev));
1090 buffer.d_secpercyl = fd->sc_type->seccyl;