Lines Matching refs:fs
211 #define swim3_err(fmt, arg...) dev_err(&fs->mdev->ofdev.dev, "[fd%d] " fmt, fs->index, arg)
212 #define swim3_warn(fmt, arg...) dev_warn(&fs->mdev->ofdev.dev, "[fd%d] " fmt, fs->index, arg)
213 #define swim3_info(fmt, arg...) dev_info(&fs->mdev->ofdev.dev, "[fd%d] " fmt, fs->index, arg)
216 #define swim3_dbg(fmt, arg...) dev_dbg(&fs->mdev->ofdev.dev, "[fd%d] " fmt, fs->index, arg)
239 static void seek_track(struct floppy_state *fs, int n);
241 static void act(struct floppy_state *fs);
248 static int grab_drive(struct floppy_state *fs, enum swim_state state,
250 static void release_drive(struct floppy_state *fs);
251 static int fd_eject(struct floppy_state *fs);
260 static bool swim3_end_request(struct floppy_state *fs, int err, unsigned int nr_bytes) in swim3_end_request() argument
262 struct request *req = fs->cur_req; in swim3_end_request()
273 fs->cur_req = NULL; in swim3_end_request()
277 static void swim3_select(struct floppy_state *fs, int sel) in swim3_select() argument
279 struct swim3 __iomem *sw = fs->swim3; in swim3_select()
289 static void swim3_action(struct floppy_state *fs, int action) in swim3_action() argument
291 struct swim3 __iomem *sw = fs->swim3; in swim3_action()
293 swim3_select(fs, action); in swim3_action()
301 static int swim3_readbit(struct floppy_state *fs, int bit) in swim3_readbit() argument
303 struct swim3 __iomem *sw = fs->swim3; in swim3_readbit()
306 swim3_select(fs, bit); in swim3_readbit()
312 static void start_request(struct floppy_state *fs) in start_request() argument
317 swim3_dbg("start request, initial state=%d\n", fs->state); in start_request()
319 if (fs->state == idle && fs->wanted) { in start_request()
320 fs->state = available; in start_request()
321 wake_up(&fs->wait); in start_request()
324 while (fs->state == idle) { in start_request()
325 swim3_dbg("start request, idle loop, cur_req=%p\n", fs->cur_req); in start_request()
326 if (!fs->cur_req) { in start_request()
327 fs->cur_req = blk_fetch_request(disks[fs->index]->queue); in start_request()
328 swim3_dbg(" fetched request %p\n", fs->cur_req); in start_request()
329 if (!fs->cur_req) in start_request()
332 req = fs->cur_req; in start_request()
334 if (fs->mdev->media_bay && in start_request()
335 check_media_bay(fs->mdev->media_bay) != MB_FD) { in start_request()
337 swim3_end_request(fs, -ENODEV, 0); in start_request()
350 if (blk_rq_pos(req) >= fs->total_secs) { in start_request()
352 (long)blk_rq_pos(req), (long)fs->total_secs); in start_request()
353 swim3_end_request(fs, -EIO, 0); in start_request()
356 if (fs->ejected) { in start_request()
358 swim3_end_request(fs, -EIO, 0); in start_request()
363 if (fs->write_prot < 0) in start_request()
364 fs->write_prot = swim3_readbit(fs, WRITE_PROT); in start_request()
365 if (fs->write_prot) { in start_request()
367 swim3_end_request(fs, -EIO, 0); in start_request()
378 fs->req_cyl = ((long)blk_rq_pos(req)) / fs->secpercyl; in start_request()
379 x = ((long)blk_rq_pos(req)) % fs->secpercyl; in start_request()
380 fs->head = x / fs->secpertrack; in start_request()
381 fs->req_sector = x % fs->secpertrack + 1; in start_request()
382 fs->state = do_transfer; in start_request()
383 fs->retries = 0; in start_request()
385 act(fs); in start_request()
394 static void set_timeout(struct floppy_state *fs, int nticks, in set_timeout() argument
397 if (fs->timeout_pending) in set_timeout()
398 del_timer(&fs->timeout); in set_timeout()
399 fs->timeout.expires = jiffies + nticks; in set_timeout()
400 fs->timeout.function = proc; in set_timeout()
401 fs->timeout.data = (unsigned long) fs; in set_timeout()
402 add_timer(&fs->timeout); in set_timeout()
403 fs->timeout_pending = 1; in set_timeout()
406 static inline void scan_track(struct floppy_state *fs) in scan_track() argument
408 struct swim3 __iomem *sw = fs->swim3; in scan_track()
410 swim3_select(fs, READ_DATA_0); in scan_track()
416 set_timeout(fs, HZ, scan_timeout); /* enable timeout */ in scan_track()
419 static inline void seek_track(struct floppy_state *fs, int n) in seek_track() argument
421 struct swim3 __iomem *sw = fs->swim3; in seek_track()
424 swim3_action(fs, SEEK_POSITIVE); in seek_track()
427 swim3_action(fs, SEEK_NEGATIVE); in seek_track()
430 fs->expect_cyl = (fs->cur_cyl >= 0)? fs->cur_cyl + n: -1; in seek_track()
431 swim3_select(fs, STEP); in seek_track()
436 set_timeout(fs, 3*HZ, seek_timeout); /* enable timeout */ in seek_track()
437 fs->settle_time = 0; in seek_track()
449 static inline void setup_transfer(struct floppy_state *fs) in setup_transfer() argument
452 struct swim3 __iomem *sw = fs->swim3; in setup_transfer()
453 struct dbdma_cmd *cp = fs->dma_cmd; in setup_transfer()
454 struct dbdma_regs __iomem *dr = fs->dma; in setup_transfer()
455 struct request *req = fs->cur_req; in setup_transfer()
464 n = fs->secpertrack - fs->req_sector + 1; in setup_transfer()
470 fs->req_sector, fs->secpertrack, fs->head, n); in setup_transfer()
472 fs->scount = n; in setup_transfer()
473 swim3_select(fs, fs->head? READ_DATA_1: READ_DATA_0); in setup_transfer()
474 out_8(&sw->sector, fs->req_sector); in setup_transfer()
500 set_timeout(fs, 2*HZ, xfer_timeout); /* enable timeout */ in setup_transfer()
503 static void act(struct floppy_state *fs) in act() argument
507 fs->state, fs->req_cyl, fs->cur_cyl); in act()
509 switch (fs->state) { in act()
514 if (swim3_readbit(fs, TRACK_ZERO)) { in act()
516 fs->cur_cyl = 0; in act()
517 if (fs->req_cyl == 0) in act()
518 fs->state = do_transfer; in act()
520 fs->state = seeking; in act()
523 scan_track(fs); in act()
527 if (fs->cur_cyl < 0) { in act()
528 fs->expect_cyl = -1; in act()
529 fs->state = locating; in act()
532 if (fs->req_cyl == fs->cur_cyl) { in act()
534 fs->state = do_transfer; in act()
537 seek_track(fs, fs->req_cyl - fs->cur_cyl); in act()
542 fs->settle_time = (HZ + 32) / 33; in act()
543 set_timeout(fs, fs->settle_time, settle_timeout); in act()
547 if (fs->cur_cyl != fs->req_cyl) { in act()
548 if (fs->retries > 5) { in act()
550 fs->req_cyl, fs->cur_cyl); in act()
551 swim3_end_request(fs, -EIO, 0); in act()
552 fs->state = idle; in act()
555 fs->state = seeking; in act()
558 setup_transfer(fs); in act()
562 seek_track(fs, -5); in act()
566 swim3_err("Unknown state %d\n", fs->state); in act()
574 struct floppy_state *fs = (struct floppy_state *) data; in scan_timeout() local
575 struct swim3 __iomem *sw = fs->swim3; in scan_timeout()
578 swim3_dbg("* scan timeout, state=%d\n", fs->state); in scan_timeout()
581 fs->timeout_pending = 0; in scan_timeout()
585 fs->cur_cyl = -1; in scan_timeout()
586 if (fs->retries > 5) { in scan_timeout()
587 swim3_end_request(fs, -EIO, 0); in scan_timeout()
588 fs->state = idle; in scan_timeout()
589 start_request(fs); in scan_timeout()
591 fs->state = jogging; in scan_timeout()
592 act(fs); in scan_timeout()
599 struct floppy_state *fs = (struct floppy_state *) data; in seek_timeout() local
600 struct swim3 __iomem *sw = fs->swim3; in seek_timeout()
603 swim3_dbg("* seek timeout, state=%d\n", fs->state); in seek_timeout()
606 fs->timeout_pending = 0; in seek_timeout()
611 swim3_end_request(fs, -EIO, 0); in seek_timeout()
612 fs->state = idle; in seek_timeout()
613 start_request(fs); in seek_timeout()
619 struct floppy_state *fs = (struct floppy_state *) data; in settle_timeout() local
620 struct swim3 __iomem *sw = fs->swim3; in settle_timeout()
623 swim3_dbg("* settle timeout, state=%d\n", fs->state); in settle_timeout()
626 fs->timeout_pending = 0; in settle_timeout()
627 if (swim3_readbit(fs, SEEK_COMPLETE)) { in settle_timeout()
629 fs->state = locating; in settle_timeout()
630 act(fs); in settle_timeout()
634 if (fs->settle_time < 2*HZ) { in settle_timeout()
635 ++fs->settle_time; in settle_timeout()
636 set_timeout(fs, 1, settle_timeout); in settle_timeout()
640 swim3_end_request(fs, -EIO, 0); in settle_timeout()
641 fs->state = idle; in settle_timeout()
642 start_request(fs); in settle_timeout()
649 struct floppy_state *fs = (struct floppy_state *) data; in xfer_timeout() local
650 struct swim3 __iomem *sw = fs->swim3; in xfer_timeout()
651 struct dbdma_regs __iomem *dr = fs->dma; in xfer_timeout()
655 swim3_dbg("* xfer timeout, state=%d\n", fs->state); in xfer_timeout()
658 fs->timeout_pending = 0; in xfer_timeout()
667 (rq_data_dir(fs->cur_req)==WRITE? "writ": "read"), in xfer_timeout()
668 (long)blk_rq_pos(fs->cur_req)); in xfer_timeout()
669 swim3_end_request(fs, -EIO, 0); in xfer_timeout()
670 fs->state = idle; in xfer_timeout()
671 start_request(fs); in xfer_timeout()
677 struct floppy_state *fs = (struct floppy_state *) dev_id; in swim3_interrupt() local
678 struct swim3 __iomem *sw = fs->swim3; in swim3_interrupt()
684 struct request *req = fs->cur_req; in swim3_interrupt()
686 swim3_dbg("* interrupt, state=%d\n", fs->state); in swim3_interrupt()
691 if ((intr & ERROR_INTR) && fs->state != do_transfer) in swim3_interrupt()
693 fs->state, rq_data_dir(req), intr, err); in swim3_interrupt()
694 switch (fs->state) { in swim3_interrupt()
700 del_timer(&fs->timeout); in swim3_interrupt()
701 fs->timeout_pending = 0; in swim3_interrupt()
704 fs->cur_cyl = -1; in swim3_interrupt()
705 if (fs->retries > 5) { in swim3_interrupt()
706 swim3_end_request(fs, -EIO, 0); in swim3_interrupt()
707 fs->state = idle; in swim3_interrupt()
708 start_request(fs); in swim3_interrupt()
710 fs->state = jogging; in swim3_interrupt()
711 act(fs); in swim3_interrupt()
715 fs->cur_cyl = sw->ctrack; in swim3_interrupt()
716 fs->cur_sector = sw->csect; in swim3_interrupt()
717 if (fs->expect_cyl != -1 && fs->expect_cyl != fs->cur_cyl) in swim3_interrupt()
719 fs->expect_cyl, fs->cur_cyl); in swim3_interrupt()
720 fs->state = do_transfer; in swim3_interrupt()
721 act(fs); in swim3_interrupt()
730 del_timer(&fs->timeout); in swim3_interrupt()
731 fs->timeout_pending = 0; in swim3_interrupt()
732 if (fs->state == seeking) in swim3_interrupt()
733 ++fs->retries; in swim3_interrupt()
734 fs->state = settling; in swim3_interrupt()
735 act(fs); in swim3_interrupt()
740 del_timer(&fs->timeout); in swim3_interrupt()
741 fs->timeout_pending = 0; in swim3_interrupt()
742 act(fs); in swim3_interrupt()
750 del_timer(&fs->timeout); in swim3_interrupt()
751 fs->timeout_pending = 0; in swim3_interrupt()
752 dr = fs->dma; in swim3_interrupt()
753 cp = fs->dma_cmd; in swim3_interrupt()
777 n = fs->scount - 1 - resid / 512; in swim3_interrupt()
780 fs->req_sector += n; in swim3_interrupt()
782 if (fs->retries < 5) { in swim3_interrupt()
783 ++fs->retries; in swim3_interrupt()
784 act(fs); in swim3_interrupt()
789 swim3_end_request(fs, -EIO, 0); in swim3_interrupt()
790 fs->state = idle; in swim3_interrupt()
797 fs->state, rq_data_dir(req), intr, err); in swim3_interrupt()
798 swim3_end_request(fs, -EIO, 0); in swim3_interrupt()
799 fs->state = idle; in swim3_interrupt()
800 start_request(fs); in swim3_interrupt()
803 fs->retries = 0; in swim3_interrupt()
804 if (swim3_end_request(fs, 0, fs->scount << 9)) { in swim3_interrupt()
805 fs->req_sector += fs->scount; in swim3_interrupt()
806 if (fs->req_sector > fs->secpertrack) { in swim3_interrupt()
807 fs->req_sector -= fs->secpertrack; in swim3_interrupt()
808 if (++fs->head > 1) { in swim3_interrupt()
809 fs->head = 0; in swim3_interrupt()
810 ++fs->req_cyl; in swim3_interrupt()
813 act(fs); in swim3_interrupt()
815 fs->state = idle; in swim3_interrupt()
817 if (fs->state == idle) in swim3_interrupt()
818 start_request(fs); in swim3_interrupt()
821 swim3_err("Don't know what to do in state %d\n", fs->state); in swim3_interrupt()
834 static int grab_drive(struct floppy_state *fs, enum swim_state state, in grab_drive() argument
842 if (fs->state != idle && fs->state != available) { in grab_drive()
843 ++fs->wanted; in grab_drive()
846 wait_event_lock_irq(fs->wait, in grab_drive()
847 fs->state == available, in grab_drive()
849 else if (wait_event_interruptible_lock_irq(fs->wait, in grab_drive()
850 fs->state == available, in grab_drive()
852 --fs->wanted; in grab_drive()
856 --fs->wanted; in grab_drive()
858 fs->state = state; in grab_drive()
864 static void release_drive(struct floppy_state *fs) in release_drive() argument
871 fs->state = idle; in release_drive()
872 start_request(fs); in release_drive()
876 static int fd_eject(struct floppy_state *fs) in fd_eject() argument
880 err = grab_drive(fs, ejecting, 1); in fd_eject()
883 swim3_action(fs, EJECT); in fd_eject()
889 swim3_select(fs, RELAX); in fd_eject()
891 if (swim3_readbit(fs, DISK_IN) == 0) in fd_eject()
894 swim3_select(fs, RELAX); in fd_eject()
896 fs->ejected = 1; in fd_eject()
897 release_drive(fs); in fd_eject()
907 struct floppy_state *fs = bdev->bd_disk->private_data; in floppy_locked_ioctl() local
913 if (fs->mdev->media_bay && in floppy_locked_ioctl()
914 check_media_bay(fs->mdev->media_bay) != MB_FD) in floppy_locked_ioctl()
919 if (fs->ref_count != 1) in floppy_locked_ioctl()
921 err = fd_eject(fs); in floppy_locked_ioctl()
946 struct floppy_state *fs = bdev->bd_disk->private_data; in floppy_open() local
947 struct swim3 __iomem *sw = fs->swim3; in floppy_open()
950 if (fs->ref_count == 0) { in floppy_open()
951 if (fs->mdev->media_bay && in floppy_open()
952 check_media_bay(fs->mdev->media_bay) != MB_FD) in floppy_open()
960 swim3_action(fs, MOTOR_ON); in floppy_open()
961 fs->write_prot = -1; in floppy_open()
962 fs->cur_cyl = -1; in floppy_open()
964 if (n >= HZ/30 && swim3_readbit(fs, SEEK_COMPLETE)) in floppy_open()
970 swim3_select(fs, RELAX); in floppy_open()
973 if (err == 0 && (swim3_readbit(fs, SEEK_COMPLETE) == 0 in floppy_open()
974 || swim3_readbit(fs, DISK_IN) == 0)) in floppy_open()
976 swim3_action(fs, SETMFM); in floppy_open()
977 swim3_select(fs, RELAX); in floppy_open()
979 } else if (fs->ref_count == -1 || mode & FMODE_EXCL) in floppy_open()
985 if (fs->ejected) in floppy_open()
990 if (fs->write_prot < 0) in floppy_open()
991 fs->write_prot = swim3_readbit(fs, WRITE_PROT); in floppy_open()
992 if (fs->write_prot) in floppy_open()
997 if (fs->ref_count == 0) { in floppy_open()
998 swim3_action(fs, MOTOR_OFF); in floppy_open()
1000 swim3_select(fs, RELAX); in floppy_open()
1006 fs->ref_count = -1; in floppy_open()
1008 ++fs->ref_count; in floppy_open()
1026 struct floppy_state *fs = disk->private_data; in floppy_release() local
1027 struct swim3 __iomem *sw = fs->swim3; in floppy_release()
1030 if (fs->ref_count > 0 && --fs->ref_count == 0) { in floppy_release()
1031 swim3_action(fs, MOTOR_OFF); in floppy_release()
1033 swim3_select(fs, RELAX); in floppy_release()
1041 struct floppy_state *fs = disk->private_data; in floppy_check_events() local
1042 return fs->ejected ? DISK_EVENT_MEDIA_CHANGE : 0; in floppy_check_events()
1047 struct floppy_state *fs = disk->private_data; in floppy_revalidate() local
1051 if (fs->mdev->media_bay && in floppy_revalidate()
1052 check_media_bay(fs->mdev->media_bay) != MB_FD) in floppy_revalidate()
1055 sw = fs->swim3; in floppy_revalidate()
1056 grab_drive(fs, revalidating, 0); in floppy_revalidate()
1059 swim3_action(fs, MOTOR_ON); /* necessary? */ in floppy_revalidate()
1060 fs->write_prot = -1; in floppy_revalidate()
1061 fs->cur_cyl = -1; in floppy_revalidate()
1064 if (swim3_readbit(fs, SEEK_COMPLETE)) in floppy_revalidate()
1068 swim3_select(fs, RELAX); in floppy_revalidate()
1071 ret = swim3_readbit(fs, SEEK_COMPLETE) == 0 in floppy_revalidate()
1072 || swim3_readbit(fs, DISK_IN) == 0; in floppy_revalidate()
1074 swim3_action(fs, MOTOR_OFF); in floppy_revalidate()
1076 fs->ejected = 0; in floppy_revalidate()
1077 swim3_action(fs, SETMFM); in floppy_revalidate()
1079 swim3_select(fs, RELAX); in floppy_revalidate()
1081 release_drive(fs); in floppy_revalidate()
1095 struct floppy_state *fs = macio_get_drvdata(mdev); in swim3_mb_event() local
1098 if (!fs) in swim3_mb_event()
1101 sw = fs->swim3; in swim3_mb_event()
1115 struct floppy_state *fs = &floppy_states[index]; in swim3_add_device() local
1119 memset(fs, 0, sizeof(*fs)); in swim3_add_device()
1120 fs->mdev = mdev; in swim3_add_device()
1121 fs->index = index; in swim3_add_device()
1141 dev_set_drvdata(&mdev->ofdev.dev, fs); in swim3_add_device()
1146 fs->state = idle; in swim3_add_device()
1147 fs->swim3 = (struct swim3 __iomem *) in swim3_add_device()
1149 if (fs->swim3 == NULL) { in swim3_add_device()
1154 fs->dma = (struct dbdma_regs __iomem *) in swim3_add_device()
1156 if (fs->dma == NULL) { in swim3_add_device()
1158 iounmap(fs->swim3); in swim3_add_device()
1162 fs->swim3_intr = macio_irq(mdev, 0); in swim3_add_device()
1163 fs->dma_intr = macio_irq(mdev, 1); in swim3_add_device()
1164 fs->cur_cyl = -1; in swim3_add_device()
1165 fs->cur_sector = -1; in swim3_add_device()
1166 fs->secpercyl = 36; in swim3_add_device()
1167 fs->secpertrack = 18; in swim3_add_device()
1168 fs->total_secs = 2880; in swim3_add_device()
1169 init_waitqueue_head(&fs->wait); in swim3_add_device()
1171 fs->dma_cmd = (struct dbdma_cmd *) DBDMA_ALIGN(fs->dbdma_cmd_space); in swim3_add_device()
1172 memset(fs->dma_cmd, 0, 2 * sizeof(struct dbdma_cmd)); in swim3_add_device()
1173 fs->dma_cmd[1].command = cpu_to_le16(DBDMA_STOP); in swim3_add_device()
1178 if (request_irq(fs->swim3_intr, swim3_interrupt, 0, "SWIM3", fs)) { in swim3_add_device()
1185 init_timer(&fs->timeout); in swim3_add_device()
1193 iounmap(fs->dma); in swim3_add_device()
1194 iounmap(fs->swim3); in swim3_add_device()