Lines Matching refs:fs

209 #define swim3_err(fmt, arg...)	dev_err(&fs->mdev->ofdev.dev, "[fd%d] " fmt, fs->index, arg)
210 #define swim3_warn(fmt, arg...) dev_warn(&fs->mdev->ofdev.dev, "[fd%d] " fmt, fs->index, arg)
211 #define swim3_info(fmt, arg...) dev_info(&fs->mdev->ofdev.dev, "[fd%d] " fmt, fs->index, arg)
214 #define swim3_dbg(fmt, arg...) dev_dbg(&fs->mdev->ofdev.dev, "[fd%d] " fmt, fs->index, arg)
237 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);
256 static bool swim3_end_request(struct floppy_state *fs, blk_status_t err, unsigned int nr_bytes) in swim3_end_request() argument
258 struct request *req = fs->cur_req; in swim3_end_request()
268 fs->cur_req = NULL; in swim3_end_request()
272 static void swim3_select(struct floppy_state *fs, int sel) in swim3_select() argument
274 struct swim3 __iomem *sw = fs->swim3; in swim3_select()
284 static void swim3_action(struct floppy_state *fs, int action) in swim3_action() argument
286 struct swim3 __iomem *sw = fs->swim3; in swim3_action()
288 swim3_select(fs, action); in swim3_action()
296 static int swim3_readbit(struct floppy_state *fs, int bit) in swim3_readbit() argument
298 struct swim3 __iomem *sw = fs->swim3; in swim3_readbit()
301 swim3_select(fs, bit); in swim3_readbit()
310 struct floppy_state *fs = hctx->queue->queuedata; in swim3_queue_rq() local
315 if (fs->cur_req || fs->state != idle) { in swim3_queue_rq()
320 fs->cur_req = req; in swim3_queue_rq()
321 if (fs->mdev->media_bay && in swim3_queue_rq()
322 check_media_bay(fs->mdev->media_bay) != MB_FD) { in swim3_queue_rq()
324 swim3_end_request(fs, BLK_STS_IOERR, 0); in swim3_queue_rq()
327 if (fs->ejected) { in swim3_queue_rq()
329 swim3_end_request(fs, BLK_STS_IOERR, 0); in swim3_queue_rq()
333 if (fs->write_prot < 0) in swim3_queue_rq()
334 fs->write_prot = swim3_readbit(fs, WRITE_PROT); in swim3_queue_rq()
335 if (fs->write_prot) { in swim3_queue_rq()
337 swim3_end_request(fs, BLK_STS_IOERR, 0); in swim3_queue_rq()
347 fs->req_cyl = ((long)blk_rq_pos(req)) / fs->secpercyl; in swim3_queue_rq()
348 x = ((long)blk_rq_pos(req)) % fs->secpercyl; in swim3_queue_rq()
349 fs->head = x / fs->secpertrack; in swim3_queue_rq()
350 fs->req_sector = x % fs->secpertrack + 1; in swim3_queue_rq()
351 fs->state = do_transfer; in swim3_queue_rq()
352 fs->retries = 0; in swim3_queue_rq()
354 act(fs); in swim3_queue_rq()
361 static void set_timeout(struct floppy_state *fs, int nticks, in set_timeout() argument
364 if (fs->timeout_pending) in set_timeout()
365 del_timer(&fs->timeout); in set_timeout()
366 fs->timeout.expires = jiffies + nticks; in set_timeout()
367 fs->timeout.function = proc; in set_timeout()
368 add_timer(&fs->timeout); in set_timeout()
369 fs->timeout_pending = 1; in set_timeout()
372 static inline void scan_track(struct floppy_state *fs) in scan_track() argument
374 struct swim3 __iomem *sw = fs->swim3; in scan_track()
376 swim3_select(fs, READ_DATA_0); in scan_track()
382 set_timeout(fs, HZ, scan_timeout); /* enable timeout */ in scan_track()
385 static inline void seek_track(struct floppy_state *fs, int n) in seek_track() argument
387 struct swim3 __iomem *sw = fs->swim3; in seek_track()
390 swim3_action(fs, SEEK_POSITIVE); in seek_track()
393 swim3_action(fs, SEEK_NEGATIVE); in seek_track()
396 fs->expect_cyl = (fs->cur_cyl >= 0)? fs->cur_cyl + n: -1; in seek_track()
397 swim3_select(fs, STEP); in seek_track()
402 set_timeout(fs, 3*HZ, seek_timeout); /* enable timeout */ in seek_track()
403 fs->settle_time = 0; in seek_track()
431 static inline void setup_transfer(struct floppy_state *fs) in setup_transfer() argument
434 struct swim3 __iomem *sw = fs->swim3; in setup_transfer()
435 struct dbdma_cmd *cp = fs->dma_cmd; in setup_transfer()
436 struct dbdma_regs __iomem *dr = fs->dma; in setup_transfer()
437 struct request *req = fs->cur_req; in setup_transfer()
446 n = fs->secpertrack - fs->req_sector + 1; in setup_transfer()
452 fs->req_sector, fs->secpertrack, fs->head, n); in setup_transfer()
454 fs->scount = n; in setup_transfer()
455 swim3_select(fs, fs->head? READ_DATA_1: READ_DATA_0); in setup_transfer()
456 out_8(&sw->sector, fs->req_sector); in setup_transfer()
484 set_timeout(fs, 2*HZ, xfer_timeout); /* enable timeout */ in setup_transfer()
487 static void act(struct floppy_state *fs) in act() argument
491 fs->state, fs->req_cyl, fs->cur_cyl); in act()
493 switch (fs->state) { in act()
498 if (swim3_readbit(fs, TRACK_ZERO)) { in act()
500 fs->cur_cyl = 0; in act()
501 if (fs->req_cyl == 0) in act()
502 fs->state = do_transfer; in act()
504 fs->state = seeking; in act()
507 scan_track(fs); in act()
511 if (fs->cur_cyl < 0) { in act()
512 fs->expect_cyl = -1; in act()
513 fs->state = locating; in act()
516 if (fs->req_cyl == fs->cur_cyl) { in act()
518 fs->state = do_transfer; in act()
521 seek_track(fs, fs->req_cyl - fs->cur_cyl); in act()
526 fs->settle_time = (HZ + 32) / 33; in act()
527 set_timeout(fs, fs->settle_time, settle_timeout); in act()
531 if (fs->cur_cyl != fs->req_cyl) { in act()
532 if (fs->retries > 5) { in act()
534 fs->req_cyl, fs->cur_cyl); in act()
535 swim3_end_request(fs, BLK_STS_IOERR, 0); in act()
536 fs->state = idle; in act()
539 fs->state = seeking; in act()
542 setup_transfer(fs); in act()
546 seek_track(fs, -5); in act()
550 swim3_err("Unknown state %d\n", fs->state); in act()
558 struct floppy_state *fs = from_timer(fs, t, timeout); in scan_timeout() local
559 struct swim3 __iomem *sw = fs->swim3; in scan_timeout()
562 swim3_dbg("* scan timeout, state=%d\n", fs->state); in scan_timeout()
565 fs->timeout_pending = 0; in scan_timeout()
569 fs->cur_cyl = -1; in scan_timeout()
570 if (fs->retries > 5) { in scan_timeout()
571 swim3_end_request(fs, BLK_STS_IOERR, 0); in scan_timeout()
572 fs->state = idle; in scan_timeout()
574 fs->state = jogging; in scan_timeout()
575 act(fs); in scan_timeout()
582 struct floppy_state *fs = from_timer(fs, t, timeout); in seek_timeout() local
583 struct swim3 __iomem *sw = fs->swim3; in seek_timeout()
586 swim3_dbg("* seek timeout, state=%d\n", fs->state); in seek_timeout()
589 fs->timeout_pending = 0; in seek_timeout()
594 swim3_end_request(fs, BLK_STS_IOERR, 0); in seek_timeout()
595 fs->state = idle; in seek_timeout()
601 struct floppy_state *fs = from_timer(fs, t, timeout); in settle_timeout() local
602 struct swim3 __iomem *sw = fs->swim3; in settle_timeout()
605 swim3_dbg("* settle timeout, state=%d\n", fs->state); in settle_timeout()
608 fs->timeout_pending = 0; in settle_timeout()
609 if (swim3_readbit(fs, SEEK_COMPLETE)) { in settle_timeout()
611 fs->state = locating; in settle_timeout()
612 act(fs); in settle_timeout()
616 if (fs->settle_time < 2*HZ) { in settle_timeout()
617 ++fs->settle_time; in settle_timeout()
618 set_timeout(fs, 1, settle_timeout); in settle_timeout()
622 swim3_end_request(fs, BLK_STS_IOERR, 0); in settle_timeout()
623 fs->state = idle; in settle_timeout()
630 struct floppy_state *fs = from_timer(fs, t, timeout); in xfer_timeout() local
631 struct swim3 __iomem *sw = fs->swim3; in xfer_timeout()
632 struct dbdma_regs __iomem *dr = fs->dma; in xfer_timeout()
636 swim3_dbg("* xfer timeout, state=%d\n", fs->state); in xfer_timeout()
639 fs->timeout_pending = 0; in xfer_timeout()
648 (rq_data_dir(fs->cur_req)==WRITE? "writ": "read"), in xfer_timeout()
649 (long)blk_rq_pos(fs->cur_req)); in xfer_timeout()
650 swim3_end_request(fs, BLK_STS_IOERR, 0); in xfer_timeout()
651 fs->state = idle; in xfer_timeout()
657 struct floppy_state *fs = (struct floppy_state *) dev_id; in swim3_interrupt() local
658 struct swim3 __iomem *sw = fs->swim3; in swim3_interrupt()
664 struct request *req = fs->cur_req; in swim3_interrupt()
666 swim3_dbg("* interrupt, state=%d\n", fs->state); in swim3_interrupt()
671 if ((intr & ERROR_INTR) && fs->state != do_transfer) in swim3_interrupt()
673 fs->state, rq_data_dir(req), intr, err); in swim3_interrupt()
674 switch (fs->state) { in swim3_interrupt()
680 del_timer(&fs->timeout); in swim3_interrupt()
681 fs->timeout_pending = 0; in swim3_interrupt()
684 fs->cur_cyl = -1; in swim3_interrupt()
685 if (fs->retries > 5) { in swim3_interrupt()
686 swim3_end_request(fs, BLK_STS_IOERR, 0); in swim3_interrupt()
687 fs->state = idle; in swim3_interrupt()
689 fs->state = jogging; in swim3_interrupt()
690 act(fs); in swim3_interrupt()
694 fs->cur_cyl = sw->ctrack; in swim3_interrupt()
695 fs->cur_sector = sw->csect; in swim3_interrupt()
696 if (fs->expect_cyl != -1 && fs->expect_cyl != fs->cur_cyl) in swim3_interrupt()
698 fs->expect_cyl, fs->cur_cyl); in swim3_interrupt()
699 fs->state = do_transfer; in swim3_interrupt()
700 act(fs); in swim3_interrupt()
709 del_timer(&fs->timeout); in swim3_interrupt()
710 fs->timeout_pending = 0; in swim3_interrupt()
711 if (fs->state == seeking) in swim3_interrupt()
712 ++fs->retries; in swim3_interrupt()
713 fs->state = settling; in swim3_interrupt()
714 act(fs); in swim3_interrupt()
719 del_timer(&fs->timeout); in swim3_interrupt()
720 fs->timeout_pending = 0; in swim3_interrupt()
721 act(fs); in swim3_interrupt()
729 del_timer(&fs->timeout); in swim3_interrupt()
730 fs->timeout_pending = 0; in swim3_interrupt()
731 dr = fs->dma; in swim3_interrupt()
732 cp = fs->dma_cmd; in swim3_interrupt()
756 n = fs->scount - 1 - resid / 512; in swim3_interrupt()
759 fs->req_sector += n; in swim3_interrupt()
761 if (fs->retries < 5) { in swim3_interrupt()
762 ++fs->retries; in swim3_interrupt()
763 act(fs); in swim3_interrupt()
768 swim3_end_request(fs, BLK_STS_IOERR, 0); in swim3_interrupt()
769 fs->state = idle; in swim3_interrupt()
776 fs->state, rq_data_dir(req), intr, err); in swim3_interrupt()
777 swim3_end_request(fs, BLK_STS_IOERR, 0); in swim3_interrupt()
778 fs->state = idle; in swim3_interrupt()
781 fs->retries = 0; in swim3_interrupt()
782 if (swim3_end_request(fs, 0, fs->scount << 9)) { in swim3_interrupt()
783 fs->req_sector += fs->scount; in swim3_interrupt()
784 if (fs->req_sector > fs->secpertrack) { in swim3_interrupt()
785 fs->req_sector -= fs->secpertrack; in swim3_interrupt()
786 if (++fs->head > 1) { in swim3_interrupt()
787 fs->head = 0; in swim3_interrupt()
788 ++fs->req_cyl; in swim3_interrupt()
791 act(fs); in swim3_interrupt()
793 fs->state = idle; in swim3_interrupt()
797 swim3_err("Don't know what to do in state %d\n", fs->state); in swim3_interrupt()
810 static int grab_drive(struct floppy_state *fs, enum swim_state state, in grab_drive() argument
818 if (fs->state != idle && fs->state != available) { in grab_drive()
819 ++fs->wanted; in grab_drive()
822 wait_event_lock_irq(fs->wait, in grab_drive()
823 fs->state == available, in grab_drive()
825 else if (wait_event_interruptible_lock_irq(fs->wait, in grab_drive()
826 fs->state == available, in grab_drive()
828 --fs->wanted; in grab_drive()
832 --fs->wanted; in grab_drive()
834 fs->state = state; in grab_drive()
840 static void release_drive(struct floppy_state *fs) in release_drive() argument
842 struct request_queue *q = disks[fs->index]->queue; in release_drive()
848 fs->state = idle; in release_drive()
857 static int fd_eject(struct floppy_state *fs) in fd_eject() argument
861 err = grab_drive(fs, ejecting, 1); in fd_eject()
864 swim3_action(fs, EJECT); in fd_eject()
870 swim3_select(fs, RELAX); in fd_eject()
872 if (swim3_readbit(fs, DISK_IN) == 0) in fd_eject()
875 swim3_select(fs, RELAX); in fd_eject()
877 fs->ejected = 1; in fd_eject()
878 release_drive(fs); in fd_eject()
888 struct floppy_state *fs = bdev->bd_disk->private_data; in floppy_locked_ioctl() local
894 if (fs->mdev->media_bay && in floppy_locked_ioctl()
895 check_media_bay(fs->mdev->media_bay) != MB_FD) in floppy_locked_ioctl()
900 if (fs->ref_count != 1) in floppy_locked_ioctl()
902 err = fd_eject(fs); in floppy_locked_ioctl()
927 struct floppy_state *fs = disk->private_data; in floppy_open() local
928 struct swim3 __iomem *sw = fs->swim3; in floppy_open()
931 if (fs->ref_count == 0) { in floppy_open()
932 if (fs->mdev->media_bay && in floppy_open()
933 check_media_bay(fs->mdev->media_bay) != MB_FD) in floppy_open()
941 swim3_action(fs, MOTOR_ON); in floppy_open()
942 fs->write_prot = -1; in floppy_open()
943 fs->cur_cyl = -1; in floppy_open()
945 if (n >= HZ/30 && swim3_readbit(fs, SEEK_COMPLETE)) in floppy_open()
951 swim3_select(fs, RELAX); in floppy_open()
954 if (err == 0 && (swim3_readbit(fs, SEEK_COMPLETE) == 0 in floppy_open()
955 || swim3_readbit(fs, DISK_IN) == 0)) in floppy_open()
957 swim3_action(fs, SETMFM); in floppy_open()
958 swim3_select(fs, RELAX); in floppy_open()
960 } else if (fs->ref_count == -1 || mode & BLK_OPEN_EXCL) in floppy_open()
967 if (fs->ejected) in floppy_open()
972 if (fs->write_prot < 0) in floppy_open()
973 fs->write_prot = swim3_readbit(fs, WRITE_PROT); in floppy_open()
974 if (fs->write_prot) in floppy_open()
979 if (fs->ref_count == 0) { in floppy_open()
980 swim3_action(fs, MOTOR_OFF); in floppy_open()
982 swim3_select(fs, RELAX); in floppy_open()
988 fs->ref_count = -1; in floppy_open()
990 ++fs->ref_count; in floppy_open()
1008 struct floppy_state *fs = disk->private_data; in floppy_release() local
1009 struct swim3 __iomem *sw = fs->swim3; in floppy_release()
1012 if (fs->ref_count > 0) in floppy_release()
1013 --fs->ref_count; in floppy_release()
1014 else if (fs->ref_count == -1) in floppy_release()
1015 fs->ref_count = 0; in floppy_release()
1016 if (fs->ref_count == 0) { in floppy_release()
1017 swim3_action(fs, MOTOR_OFF); in floppy_release()
1019 swim3_select(fs, RELAX); in floppy_release()
1027 struct floppy_state *fs = disk->private_data; in floppy_check_events() local
1028 return fs->ejected ? DISK_EVENT_MEDIA_CHANGE : 0; in floppy_check_events()
1033 struct floppy_state *fs = disk->private_data; in floppy_revalidate() local
1037 if (fs->mdev->media_bay && in floppy_revalidate()
1038 check_media_bay(fs->mdev->media_bay) != MB_FD) in floppy_revalidate()
1041 sw = fs->swim3; in floppy_revalidate()
1042 grab_drive(fs, revalidating, 0); in floppy_revalidate()
1045 swim3_action(fs, MOTOR_ON); /* necessary? */ in floppy_revalidate()
1046 fs->write_prot = -1; in floppy_revalidate()
1047 fs->cur_cyl = -1; in floppy_revalidate()
1050 if (swim3_readbit(fs, SEEK_COMPLETE)) in floppy_revalidate()
1054 swim3_select(fs, RELAX); in floppy_revalidate()
1057 ret = swim3_readbit(fs, SEEK_COMPLETE) == 0 in floppy_revalidate()
1058 || swim3_readbit(fs, DISK_IN) == 0; in floppy_revalidate()
1060 swim3_action(fs, MOTOR_OFF); in floppy_revalidate()
1062 fs->ejected = 0; in floppy_revalidate()
1063 swim3_action(fs, SETMFM); in floppy_revalidate()
1065 swim3_select(fs, RELAX); in floppy_revalidate()
1067 release_drive(fs); in floppy_revalidate()
1084 struct floppy_state *fs = macio_get_drvdata(mdev); in swim3_mb_event() local
1087 if (!fs) in swim3_mb_event()
1090 sw = fs->swim3; in swim3_mb_event()
1104 struct floppy_state *fs = &floppy_states[index]; in swim3_add_device() local
1107 fs->mdev = mdev; in swim3_add_device()
1108 fs->index = index; in swim3_add_device()
1128 dev_set_drvdata(&mdev->ofdev.dev, fs); in swim3_add_device()
1133 fs->state = idle; in swim3_add_device()
1134 fs->swim3 = (struct swim3 __iomem *) in swim3_add_device()
1136 if (fs->swim3 == NULL) { in swim3_add_device()
1141 fs->dma = (struct dbdma_regs __iomem *) in swim3_add_device()
1143 if (fs->dma == NULL) { in swim3_add_device()
1145 iounmap(fs->swim3); in swim3_add_device()
1149 fs->swim3_intr = macio_irq(mdev, 0); in swim3_add_device()
1150 fs->dma_intr = macio_irq(mdev, 1); in swim3_add_device()
1151 fs->cur_cyl = -1; in swim3_add_device()
1152 fs->cur_sector = -1; in swim3_add_device()
1153 fs->secpercyl = 36; in swim3_add_device()
1154 fs->secpertrack = 18; in swim3_add_device()
1155 fs->total_secs = 2880; in swim3_add_device()
1156 init_waitqueue_head(&fs->wait); in swim3_add_device()
1158 fs->dma_cmd = (struct dbdma_cmd *) DBDMA_ALIGN(fs->dbdma_cmd_space); in swim3_add_device()
1159 memset(fs->dma_cmd, 0, 2 * sizeof(struct dbdma_cmd)); in swim3_add_device()
1160 fs->dma_cmd[1].command = cpu_to_le16(DBDMA_STOP); in swim3_add_device()
1165 if (request_irq(fs->swim3_intr, swim3_interrupt, 0, "SWIM3", fs)) { in swim3_add_device()
1171 timer_setup(&fs->timeout, NULL, 0); in swim3_add_device()
1179 iounmap(fs->dma); in swim3_add_device()
1180 iounmap(fs->swim3); in swim3_add_device()
1192 struct floppy_state *fs; in swim3_attach() local
1205 fs = &floppy_states[floppy_count]; in swim3_attach()
1206 memset(fs, 0, sizeof(*fs)); in swim3_attach()
1208 rc = blk_mq_alloc_sq_tag_set(&fs->tag_set, &swim3_mq_ops, 2, in swim3_attach()
1213 disk = blk_mq_alloc_disk(&fs->tag_set, fs); in swim3_attach()
1227 disk->private_data = fs; in swim3_attach()
1242 blk_mq_free_tag_set(&fs->tag_set); in swim3_attach()