Lines Matching full:fs

208 #define swim3_err(fmt, arg...)	dev_err(&fs->mdev->ofdev.dev, "[fd%d] " fmt, fs->index, arg)
209 #define swim3_warn(fmt, arg...) dev_warn(&fs->mdev->ofdev.dev, "[fd%d] " fmt, fs->index, arg)
210 #define swim3_info(fmt, arg...) dev_info(&fs->mdev->ofdev.dev, "[fd%d] " fmt, fs->index, arg)
213 #define swim3_dbg(fmt, arg...) dev_dbg(&fs->mdev->ofdev.dev, "[fd%d] " fmt, fs->index, arg)
236 static void seek_track(struct floppy_state *fs, int n);
238 static void act(struct floppy_state *fs);
245 static int grab_drive(struct floppy_state *fs, enum swim_state state,
247 static void release_drive(struct floppy_state *fs);
248 static int fd_eject(struct floppy_state *fs);
257 static bool swim3_end_request(struct floppy_state *fs, blk_status_t err, unsigned int nr_bytes) in swim3_end_request() argument
259 struct request *req = fs->cur_req; in swim3_end_request()
269 fs->cur_req = NULL; in swim3_end_request()
273 static void swim3_select(struct floppy_state *fs, int sel) in swim3_select() argument
275 struct swim3 __iomem *sw = fs->swim3; in swim3_select()
285 static void swim3_action(struct floppy_state *fs, int action) in swim3_action() argument
287 struct swim3 __iomem *sw = fs->swim3; in swim3_action()
289 swim3_select(fs, action); in swim3_action()
297 static int swim3_readbit(struct floppy_state *fs, int bit) in swim3_readbit() argument
299 struct swim3 __iomem *sw = fs->swim3; in swim3_readbit()
302 swim3_select(fs, bit); in swim3_readbit()
311 struct floppy_state *fs = hctx->queue->queuedata; in swim3_queue_rq() local
316 if (fs->cur_req || fs->state != idle) { in swim3_queue_rq()
321 fs->cur_req = req; in swim3_queue_rq()
322 if (fs->mdev->media_bay && in swim3_queue_rq()
323 check_media_bay(fs->mdev->media_bay) != MB_FD) { in swim3_queue_rq()
325 swim3_end_request(fs, BLK_STS_IOERR, 0); in swim3_queue_rq()
328 if (fs->ejected) { in swim3_queue_rq()
330 swim3_end_request(fs, BLK_STS_IOERR, 0); in swim3_queue_rq()
334 if (fs->write_prot < 0) in swim3_queue_rq()
335 fs->write_prot = swim3_readbit(fs, WRITE_PROT); in swim3_queue_rq()
336 if (fs->write_prot) { in swim3_queue_rq()
338 swim3_end_request(fs, BLK_STS_IOERR, 0); in swim3_queue_rq()
348 fs->req_cyl = ((long)blk_rq_pos(req)) / fs->secpercyl; in swim3_queue_rq()
349 x = ((long)blk_rq_pos(req)) % fs->secpercyl; in swim3_queue_rq()
350 fs->head = x / fs->secpertrack; in swim3_queue_rq()
351 fs->req_sector = x % fs->secpertrack + 1; in swim3_queue_rq()
352 fs->state = do_transfer; in swim3_queue_rq()
353 fs->retries = 0; in swim3_queue_rq()
355 act(fs); in swim3_queue_rq()
362 static void set_timeout(struct floppy_state *fs, int nticks, in set_timeout() argument
365 if (fs->timeout_pending) in set_timeout()
366 del_timer(&fs->timeout); in set_timeout()
367 fs->timeout.expires = jiffies + nticks; in set_timeout()
368 fs->timeout.function = proc; in set_timeout()
369 add_timer(&fs->timeout); in set_timeout()
370 fs->timeout_pending = 1; in set_timeout()
373 static inline void scan_track(struct floppy_state *fs) in scan_track() argument
375 struct swim3 __iomem *sw = fs->swim3; in scan_track()
377 swim3_select(fs, READ_DATA_0); in scan_track()
383 set_timeout(fs, HZ, scan_timeout); /* enable timeout */ in scan_track()
386 static inline void seek_track(struct floppy_state *fs, int n) in seek_track() argument
388 struct swim3 __iomem *sw = fs->swim3; in seek_track()
391 swim3_action(fs, SEEK_POSITIVE); in seek_track()
394 swim3_action(fs, SEEK_NEGATIVE); in seek_track()
397 fs->expect_cyl = (fs->cur_cyl >= 0)? fs->cur_cyl + n: -1; in seek_track()
398 swim3_select(fs, STEP); in seek_track()
403 set_timeout(fs, 3*HZ, seek_timeout); /* enable timeout */ in seek_track()
404 fs->settle_time = 0; in seek_track()
416 static inline void setup_transfer(struct floppy_state *fs) in setup_transfer() argument
419 struct swim3 __iomem *sw = fs->swim3; in setup_transfer()
420 struct dbdma_cmd *cp = fs->dma_cmd; in setup_transfer()
421 struct dbdma_regs __iomem *dr = fs->dma; in setup_transfer()
422 struct request *req = fs->cur_req; in setup_transfer()
431 n = fs->secpertrack - fs->req_sector + 1; in setup_transfer()
437 fs->req_sector, fs->secpertrack, fs->head, n); in setup_transfer()
439 fs->scount = n; in setup_transfer()
440 swim3_select(fs, fs->head? READ_DATA_1: READ_DATA_0); in setup_transfer()
441 out_8(&sw->sector, fs->req_sector); in setup_transfer()
467 set_timeout(fs, 2*HZ, xfer_timeout); /* enable timeout */ in setup_transfer()
470 static void act(struct floppy_state *fs) in act() argument
474 fs->state, fs->req_cyl, fs->cur_cyl); in act()
476 switch (fs->state) { in act()
481 if (swim3_readbit(fs, TRACK_ZERO)) { in act()
483 fs->cur_cyl = 0; in act()
484 if (fs->req_cyl == 0) in act()
485 fs->state = do_transfer; in act()
487 fs->state = seeking; in act()
490 scan_track(fs); in act()
494 if (fs->cur_cyl < 0) { in act()
495 fs->expect_cyl = -1; in act()
496 fs->state = locating; in act()
499 if (fs->req_cyl == fs->cur_cyl) { in act()
501 fs->state = do_transfer; in act()
504 seek_track(fs, fs->req_cyl - fs->cur_cyl); in act()
509 fs->settle_time = (HZ + 32) / 33; in act()
510 set_timeout(fs, fs->settle_time, settle_timeout); in act()
514 if (fs->cur_cyl != fs->req_cyl) { in act()
515 if (fs->retries > 5) { in act()
517 fs->req_cyl, fs->cur_cyl); in act()
518 swim3_end_request(fs, BLK_STS_IOERR, 0); in act()
519 fs->state = idle; in act()
522 fs->state = seeking; in act()
525 setup_transfer(fs); in act()
529 seek_track(fs, -5); in act()
533 swim3_err("Unknown state %d\n", fs->state); in act()
541 struct floppy_state *fs = from_timer(fs, t, timeout); in scan_timeout() local
542 struct swim3 __iomem *sw = fs->swim3; in scan_timeout()
545 swim3_dbg("* scan timeout, state=%d\n", fs->state); in scan_timeout()
548 fs->timeout_pending = 0; in scan_timeout()
552 fs->cur_cyl = -1; in scan_timeout()
553 if (fs->retries > 5) { in scan_timeout()
554 swim3_end_request(fs, BLK_STS_IOERR, 0); in scan_timeout()
555 fs->state = idle; in scan_timeout()
557 fs->state = jogging; in scan_timeout()
558 act(fs); in scan_timeout()
565 struct floppy_state *fs = from_timer(fs, t, timeout); in seek_timeout() local
566 struct swim3 __iomem *sw = fs->swim3; in seek_timeout()
569 swim3_dbg("* seek timeout, state=%d\n", fs->state); in seek_timeout()
572 fs->timeout_pending = 0; in seek_timeout()
577 swim3_end_request(fs, BLK_STS_IOERR, 0); in seek_timeout()
578 fs->state = idle; in seek_timeout()
584 struct floppy_state *fs = from_timer(fs, t, timeout); in settle_timeout() local
585 struct swim3 __iomem *sw = fs->swim3; in settle_timeout()
588 swim3_dbg("* settle timeout, state=%d\n", fs->state); in settle_timeout()
591 fs->timeout_pending = 0; in settle_timeout()
592 if (swim3_readbit(fs, SEEK_COMPLETE)) { in settle_timeout()
594 fs->state = locating; in settle_timeout()
595 act(fs); in settle_timeout()
599 if (fs->settle_time < 2*HZ) { in settle_timeout()
600 ++fs->settle_time; in settle_timeout()
601 set_timeout(fs, 1, settle_timeout); in settle_timeout()
605 swim3_end_request(fs, BLK_STS_IOERR, 0); in settle_timeout()
606 fs->state = idle; in settle_timeout()
613 struct floppy_state *fs = from_timer(fs, t, timeout); in xfer_timeout() local
614 struct swim3 __iomem *sw = fs->swim3; in xfer_timeout()
615 struct dbdma_regs __iomem *dr = fs->dma; in xfer_timeout()
619 swim3_dbg("* xfer timeout, state=%d\n", fs->state); in xfer_timeout()
622 fs->timeout_pending = 0; in xfer_timeout()
631 (rq_data_dir(fs->cur_req)==WRITE? "writ": "read"), in xfer_timeout()
632 (long)blk_rq_pos(fs->cur_req)); in xfer_timeout()
633 swim3_end_request(fs, BLK_STS_IOERR, 0); in xfer_timeout()
634 fs->state = idle; in xfer_timeout()
640 struct floppy_state *fs = (struct floppy_state *) dev_id; in swim3_interrupt() local
641 struct swim3 __iomem *sw = fs->swim3; in swim3_interrupt()
647 struct request *req = fs->cur_req; in swim3_interrupt()
649 swim3_dbg("* interrupt, state=%d\n", fs->state); in swim3_interrupt()
654 if ((intr & ERROR_INTR) && fs->state != do_transfer) in swim3_interrupt()
656 fs->state, rq_data_dir(req), intr, err); in swim3_interrupt()
657 switch (fs->state) { in swim3_interrupt()
663 del_timer(&fs->timeout); in swim3_interrupt()
664 fs->timeout_pending = 0; in swim3_interrupt()
667 fs->cur_cyl = -1; in swim3_interrupt()
668 if (fs->retries > 5) { in swim3_interrupt()
669 swim3_end_request(fs, BLK_STS_IOERR, 0); in swim3_interrupt()
670 fs->state = idle; in swim3_interrupt()
672 fs->state = jogging; in swim3_interrupt()
673 act(fs); in swim3_interrupt()
677 fs->cur_cyl = sw->ctrack; in swim3_interrupt()
678 fs->cur_sector = sw->csect; in swim3_interrupt()
679 if (fs->expect_cyl != -1 && fs->expect_cyl != fs->cur_cyl) in swim3_interrupt()
681 fs->expect_cyl, fs->cur_cyl); in swim3_interrupt()
682 fs->state = do_transfer; in swim3_interrupt()
683 act(fs); in swim3_interrupt()
692 del_timer(&fs->timeout); in swim3_interrupt()
693 fs->timeout_pending = 0; in swim3_interrupt()
694 if (fs->state == seeking) in swim3_interrupt()
695 ++fs->retries; in swim3_interrupt()
696 fs->state = settling; in swim3_interrupt()
697 act(fs); in swim3_interrupt()
702 del_timer(&fs->timeout); in swim3_interrupt()
703 fs->timeout_pending = 0; in swim3_interrupt()
704 act(fs); in swim3_interrupt()
712 del_timer(&fs->timeout); in swim3_interrupt()
713 fs->timeout_pending = 0; in swim3_interrupt()
714 dr = fs->dma; in swim3_interrupt()
715 cp = fs->dma_cmd; in swim3_interrupt()
739 n = fs->scount - 1 - resid / 512; in swim3_interrupt()
742 fs->req_sector += n; in swim3_interrupt()
744 if (fs->retries < 5) { in swim3_interrupt()
745 ++fs->retries; in swim3_interrupt()
746 act(fs); in swim3_interrupt()
751 swim3_end_request(fs, BLK_STS_IOERR, 0); in swim3_interrupt()
752 fs->state = idle; in swim3_interrupt()
759 fs->state, rq_data_dir(req), intr, err); in swim3_interrupt()
760 swim3_end_request(fs, BLK_STS_IOERR, 0); in swim3_interrupt()
761 fs->state = idle; in swim3_interrupt()
764 fs->retries = 0; in swim3_interrupt()
765 if (swim3_end_request(fs, 0, fs->scount << 9)) { in swim3_interrupt()
766 fs->req_sector += fs->scount; in swim3_interrupt()
767 if (fs->req_sector > fs->secpertrack) { in swim3_interrupt()
768 fs->req_sector -= fs->secpertrack; in swim3_interrupt()
769 if (++fs->head > 1) { in swim3_interrupt()
770 fs->head = 0; in swim3_interrupt()
771 ++fs->req_cyl; in swim3_interrupt()
774 act(fs); in swim3_interrupt()
776 fs->state = idle; in swim3_interrupt()
780 swim3_err("Don't know what to do in state %d\n", fs->state); in swim3_interrupt()
793 static int grab_drive(struct floppy_state *fs, enum swim_state state, in grab_drive() argument
801 if (fs->state != idle && fs->state != available) { in grab_drive()
802 ++fs->wanted; in grab_drive()
805 wait_event_lock_irq(fs->wait, in grab_drive()
806 fs->state == available, in grab_drive()
808 else if (wait_event_interruptible_lock_irq(fs->wait, in grab_drive()
809 fs->state == available, in grab_drive()
811 --fs->wanted; in grab_drive()
815 --fs->wanted; in grab_drive()
817 fs->state = state; in grab_drive()
823 static void release_drive(struct floppy_state *fs) in release_drive() argument
825 struct request_queue *q = disks[fs->index]->queue; in release_drive()
831 fs->state = idle; in release_drive()
840 static int fd_eject(struct floppy_state *fs) in fd_eject() argument
844 err = grab_drive(fs, ejecting, 1); in fd_eject()
847 swim3_action(fs, EJECT); in fd_eject()
853 swim3_select(fs, RELAX); in fd_eject()
855 if (swim3_readbit(fs, DISK_IN) == 0) in fd_eject()
858 swim3_select(fs, RELAX); in fd_eject()
860 fs->ejected = 1; in fd_eject()
861 release_drive(fs); in fd_eject()
871 struct floppy_state *fs = bdev->bd_disk->private_data; in floppy_locked_ioctl() local
877 if (fs->mdev->media_bay && in floppy_locked_ioctl()
878 check_media_bay(fs->mdev->media_bay) != MB_FD) in floppy_locked_ioctl()
883 if (fs->ref_count != 1) in floppy_locked_ioctl()
885 err = fd_eject(fs); in floppy_locked_ioctl()
910 struct floppy_state *fs = bdev->bd_disk->private_data; in floppy_open() local
911 struct swim3 __iomem *sw = fs->swim3; in floppy_open()
914 if (fs->ref_count == 0) { in floppy_open()
915 if (fs->mdev->media_bay && in floppy_open()
916 check_media_bay(fs->mdev->media_bay) != MB_FD) in floppy_open()
924 swim3_action(fs, MOTOR_ON); in floppy_open()
925 fs->write_prot = -1; in floppy_open()
926 fs->cur_cyl = -1; in floppy_open()
928 if (n >= HZ/30 && swim3_readbit(fs, SEEK_COMPLETE)) in floppy_open()
934 swim3_select(fs, RELAX); in floppy_open()
937 if (err == 0 && (swim3_readbit(fs, SEEK_COMPLETE) == 0 in floppy_open()
938 || swim3_readbit(fs, DISK_IN) == 0)) in floppy_open()
940 swim3_action(fs, SETMFM); in floppy_open()
941 swim3_select(fs, RELAX); in floppy_open()
943 } else if (fs->ref_count == -1 || mode & FMODE_EXCL) in floppy_open()
950 if (fs->ejected) in floppy_open()
955 if (fs->write_prot < 0) in floppy_open()
956 fs->write_prot = swim3_readbit(fs, WRITE_PROT); in floppy_open()
957 if (fs->write_prot) in floppy_open()
962 if (fs->ref_count == 0) { in floppy_open()
963 swim3_action(fs, MOTOR_OFF); in floppy_open()
965 swim3_select(fs, RELAX); in floppy_open()
971 fs->ref_count = -1; in floppy_open()
973 ++fs->ref_count; in floppy_open()
991 struct floppy_state *fs = disk->private_data; in floppy_release() local
992 struct swim3 __iomem *sw = fs->swim3; in floppy_release()
995 if (fs->ref_count > 0) in floppy_release()
996 --fs->ref_count; in floppy_release()
997 else if (fs->ref_count == -1) in floppy_release()
998 fs->ref_count = 0; in floppy_release()
999 if (fs->ref_count == 0) { in floppy_release()
1000 swim3_action(fs, MOTOR_OFF); in floppy_release()
1002 swim3_select(fs, RELAX); in floppy_release()
1010 struct floppy_state *fs = disk->private_data; in floppy_check_events() local
1011 return fs->ejected ? DISK_EVENT_MEDIA_CHANGE : 0; in floppy_check_events()
1016 struct floppy_state *fs = disk->private_data; in floppy_revalidate() local
1020 if (fs->mdev->media_bay && in floppy_revalidate()
1021 check_media_bay(fs->mdev->media_bay) != MB_FD) in floppy_revalidate()
1024 sw = fs->swim3; in floppy_revalidate()
1025 grab_drive(fs, revalidating, 0); in floppy_revalidate()
1028 swim3_action(fs, MOTOR_ON); /* necessary? */ in floppy_revalidate()
1029 fs->write_prot = -1; in floppy_revalidate()
1030 fs->cur_cyl = -1; in floppy_revalidate()
1033 if (swim3_readbit(fs, SEEK_COMPLETE)) in floppy_revalidate()
1037 swim3_select(fs, RELAX); in floppy_revalidate()
1040 ret = swim3_readbit(fs, SEEK_COMPLETE) == 0 in floppy_revalidate()
1041 || swim3_readbit(fs, DISK_IN) == 0; in floppy_revalidate()
1043 swim3_action(fs, MOTOR_OFF); in floppy_revalidate()
1045 fs->ejected = 0; in floppy_revalidate()
1046 swim3_action(fs, SETMFM); in floppy_revalidate()
1048 swim3_select(fs, RELAX); in floppy_revalidate()
1050 release_drive(fs); in floppy_revalidate()
1067 struct floppy_state *fs = macio_get_drvdata(mdev); in swim3_mb_event() local
1070 if (!fs) in swim3_mb_event()
1073 sw = fs->swim3; in swim3_mb_event()
1087 struct floppy_state *fs = &floppy_states[index]; in swim3_add_device() local
1090 fs->mdev = mdev; in swim3_add_device()
1091 fs->index = index; in swim3_add_device()
1111 dev_set_drvdata(&mdev->ofdev.dev, fs); in swim3_add_device()
1116 fs->state = idle; in swim3_add_device()
1117 fs->swim3 = (struct swim3 __iomem *) in swim3_add_device()
1119 if (fs->swim3 == NULL) { in swim3_add_device()
1124 fs->dma = (struct dbdma_regs __iomem *) in swim3_add_device()
1126 if (fs->dma == NULL) { in swim3_add_device()
1128 iounmap(fs->swim3); in swim3_add_device()
1132 fs->swim3_intr = macio_irq(mdev, 0); in swim3_add_device()
1133 fs->dma_intr = macio_irq(mdev, 1); in swim3_add_device()
1134 fs->cur_cyl = -1; in swim3_add_device()
1135 fs->cur_sector = -1; in swim3_add_device()
1136 fs->secpercyl = 36; in swim3_add_device()
1137 fs->secpertrack = 18; in swim3_add_device()
1138 fs->total_secs = 2880; in swim3_add_device()
1139 init_waitqueue_head(&fs->wait); in swim3_add_device()
1141 fs->dma_cmd = (struct dbdma_cmd *) DBDMA_ALIGN(fs->dbdma_cmd_space); in swim3_add_device()
1142 memset(fs->dma_cmd, 0, 2 * sizeof(struct dbdma_cmd)); in swim3_add_device()
1143 fs->dma_cmd[1].command = cpu_to_le16(DBDMA_STOP); in swim3_add_device()
1148 if (request_irq(fs->swim3_intr, swim3_interrupt, 0, "SWIM3", fs)) { in swim3_add_device()
1154 timer_setup(&fs->timeout, NULL, 0); in swim3_add_device()
1162 iounmap(fs->dma); in swim3_add_device()
1163 iounmap(fs->swim3); in swim3_add_device()
1175 struct floppy_state *fs; in swim3_attach() local
1194 fs = &floppy_states[floppy_count]; in swim3_attach()
1195 memset(fs, 0, sizeof(*fs)); in swim3_attach()
1197 disk->queue = blk_mq_init_sq_queue(&fs->tag_set, &swim3_mq_ops, 2, in swim3_attach()
1205 disk->queue->queuedata = fs; in swim3_attach()
1214 disk->private_data = fs; in swim3_attach()
1227 blk_mq_free_tag_set(&fs->tag_set); in swim3_attach()