Lines Matching refs:disk
252 static inline int status_reg(struct pd_unit *disk) in status_reg() argument
254 return pi_read_regr(disk->pi, 1, 6); in status_reg()
257 static inline int read_reg(struct pd_unit *disk, int reg) in read_reg() argument
259 return pi_read_regr(disk->pi, 0, reg); in read_reg()
262 static inline void write_status(struct pd_unit *disk, int val) in write_status() argument
264 pi_write_regr(disk->pi, 1, 6, val); in write_status()
267 static inline void write_reg(struct pd_unit *disk, int reg, int val) in write_reg() argument
269 pi_write_regr(disk->pi, 0, reg, val); in write_reg()
272 static inline u8 DRIVE(struct pd_unit *disk) in DRIVE() argument
274 return 0xa0+0x10*disk->drive; in DRIVE()
279 static void pd_print_error(struct pd_unit *disk, char *msg, int status) in pd_print_error() argument
283 printk("%s: %s: status = 0x%x =", disk->name, msg, status); in pd_print_error()
290 static void pd_reset(struct pd_unit *disk) in pd_reset() argument
292 write_status(disk, 4); in pd_reset()
294 write_status(disk, 0); in pd_reset()
300 static int pd_wait_for(struct pd_unit *disk, int w, char *msg) in pd_wait_for() argument
306 r = status_reg(disk); in pd_wait_for()
312 e = (read_reg(disk, 1) << 8) + read_reg(disk, 7); in pd_wait_for()
316 pd_print_error(disk, msg, e); in pd_wait_for()
320 static void pd_send_command(struct pd_unit *disk, int n, int s, int h, int c0, int c1, int func) in pd_send_command() argument
322 write_reg(disk, 6, DRIVE(disk) + h); in pd_send_command()
323 write_reg(disk, 1, 0); /* the IDE task file */ in pd_send_command()
324 write_reg(disk, 2, n); in pd_send_command()
325 write_reg(disk, 3, s); in pd_send_command()
326 write_reg(disk, 4, c0); in pd_send_command()
327 write_reg(disk, 5, c1); in pd_send_command()
328 write_reg(disk, 7, func); in pd_send_command()
333 static void pd_ide_command(struct pd_unit *disk, int func, int block, int count) in pd_ide_command() argument
337 if (disk->can_lba) { in pd_ide_command()
343 s = (block % disk->sectors) + 1; in pd_ide_command()
344 h = (block /= disk->sectors) % disk->heads; in pd_ide_command()
345 c0 = (block /= disk->heads) % 256; in pd_ide_command()
348 pd_send_command(disk, count, s, h, c0, c1, func); in pd_ide_command()
589 static void pd_init_dev_parms(struct pd_unit *disk) in pd_init_dev_parms() argument
591 pd_wait_for(disk, 0, DBMSG("before init_dev_parms")); in pd_init_dev_parms()
592 pd_send_command(disk, disk->sectors, 0, disk->heads - 1, 0, 0, in pd_init_dev_parms()
595 pd_wait_for(disk, 0, "Initialise device parameters"); in pd_init_dev_parms()
598 static enum action pd_door_lock(struct pd_unit *disk) in pd_door_lock() argument
600 if (!(pd_wait_for(disk, STAT_READY, "Lock") & STAT_ERR)) { in pd_door_lock()
601 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_DOORLOCK); in pd_door_lock()
602 pd_wait_for(disk, STAT_READY, "Lock done"); in pd_door_lock()
607 static enum action pd_door_unlock(struct pd_unit *disk) in pd_door_unlock() argument
609 if (!(pd_wait_for(disk, STAT_READY, "Lock") & STAT_ERR)) { in pd_door_unlock()
610 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_DOORUNLOCK); in pd_door_unlock()
611 pd_wait_for(disk, STAT_READY, "Lock done"); in pd_door_unlock()
616 static enum action pd_eject(struct pd_unit *disk) in pd_eject() argument
618 pd_wait_for(disk, 0, DBMSG("before unlock on eject")); in pd_eject()
619 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_DOORUNLOCK); in pd_eject()
620 pd_wait_for(disk, 0, DBMSG("after unlock on eject")); in pd_eject()
621 pd_wait_for(disk, 0, DBMSG("before eject")); in pd_eject()
622 pd_send_command(disk, 0, 0, 0, 0, 0, IDE_EJECT); in pd_eject()
623 pd_wait_for(disk, 0, DBMSG("after eject")); in pd_eject()
627 static enum action pd_media_check(struct pd_unit *disk) in pd_media_check() argument
629 int r = pd_wait_for(disk, STAT_READY, DBMSG("before media_check")); in pd_media_check()
631 pd_send_command(disk, 1, 1, 0, 0, 0, IDE_READ_VRFY); in pd_media_check()
632 r = pd_wait_for(disk, STAT_READY, DBMSG("RDY after READ_VRFY")); in pd_media_check()
634 disk->changed = 1; /* say changed if other error */ in pd_media_check()
636 disk->changed = 1; in pd_media_check()
637 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_ACKCHANGE); in pd_media_check()
638 pd_wait_for(disk, STAT_READY, DBMSG("RDY after ACKCHANGE")); in pd_media_check()
639 pd_send_command(disk, 1, 1, 0, 0, 0, IDE_READ_VRFY); in pd_media_check()
640 r = pd_wait_for(disk, STAT_READY, DBMSG("RDY after VRFY")); in pd_media_check()
645 static void pd_standby_off(struct pd_unit *disk) in pd_standby_off() argument
647 pd_wait_for(disk, 0, DBMSG("before STANDBY")); in pd_standby_off()
648 pd_send_command(disk, 0, 0, 0, 0, 0, IDE_STANDBY); in pd_standby_off()
649 pd_wait_for(disk, 0, DBMSG("after STANDBY")); in pd_standby_off()
652 static enum action pd_identify(struct pd_unit *disk) in pd_identify() argument
663 if (disk->drive == 0) in pd_identify()
664 pd_reset(disk); in pd_identify()
666 write_reg(disk, 6, DRIVE(disk)); in pd_identify()
667 pd_wait_for(disk, 0, DBMSG("before IDENT")); in pd_identify()
668 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_IDENTIFY); in pd_identify()
670 if (pd_wait_for(disk, STAT_DRQ, DBMSG("IDENT DRQ")) & STAT_ERR) in pd_identify()
672 pi_read_block(disk->pi, pd_scratch, 512); in pd_identify()
673 disk->can_lba = pd_scratch[99] & 2; in pd_identify()
674 disk->sectors = le16_to_cpu(*(__le16 *) (pd_scratch + 12)); in pd_identify()
675 disk->heads = le16_to_cpu(*(__le16 *) (pd_scratch + 6)); in pd_identify()
676 disk->cylinders = le16_to_cpu(*(__le16 *) (pd_scratch + 2)); in pd_identify()
677 if (disk->can_lba) in pd_identify()
678 disk->capacity = le32_to_cpu(*(__le32 *) (pd_scratch + 120)); in pd_identify()
680 disk->capacity = disk->sectors * disk->heads * disk->cylinders; in pd_identify()
690 disk->removable = pd_scratch[0] & 0x80; in pd_identify()
693 disk->name, id, in pd_identify()
694 disk->drive ? "slave" : "master", in pd_identify()
695 disk->capacity, disk->capacity / 2048, in pd_identify()
696 disk->cylinders, disk->heads, disk->sectors, in pd_identify()
697 disk->removable ? "removable" : "fixed"); in pd_identify()
699 if (disk->capacity) in pd_identify()
700 pd_init_dev_parms(disk); in pd_identify()
701 if (!disk->standby) in pd_identify()
702 pd_standby_off(disk); in pd_identify()
720 static int pd_special_command(struct pd_unit *disk, in pd_special_command() argument
721 enum action (*func)(struct pd_unit *disk)) in pd_special_command() argument
726 rq = blk_get_request(disk->gd->queue, READ, __GFP_RECLAIM); in pd_special_command()
733 err = blk_execute_rq(disk->gd->queue, disk->gd, rq, 0); in pd_special_command()
743 struct pd_unit *disk = bdev->bd_disk->private_data; in pd_open() local
746 disk->access++; in pd_open()
748 if (disk->removable) { in pd_open()
749 pd_special_command(disk, pd_media_check); in pd_open()
750 pd_special_command(disk, pd_door_lock); in pd_open()
758 struct pd_unit *disk = bdev->bd_disk->private_data; in pd_getgeo() local
760 if (disk->alt_geom) { in pd_getgeo()
763 geo->cylinders = disk->capacity / (geo->heads * geo->sectors); in pd_getgeo()
765 geo->heads = disk->heads; in pd_getgeo()
766 geo->sectors = disk->sectors; in pd_getgeo()
767 geo->cylinders = disk->cylinders; in pd_getgeo()
776 struct pd_unit *disk = bdev->bd_disk->private_data; in pd_ioctl() local
781 if (disk->access == 1) in pd_ioctl()
782 pd_special_command(disk, pd_eject); in pd_ioctl()
792 struct pd_unit *disk = p->private_data; in pd_release() local
795 if (!--disk->access && disk->removable) in pd_release()
796 pd_special_command(disk, pd_door_unlock); in pd_release()
802 struct pd_unit *disk = p->private_data; in pd_check_events() local
804 if (!disk->removable) in pd_check_events()
806 pd_special_command(disk, pd_media_check); in pd_check_events()
807 r = disk->changed; in pd_check_events()
808 disk->changed = 0; in pd_check_events()
814 struct pd_unit *disk = p->private_data; in pd_revalidate() local
815 if (pd_special_command(disk, pd_identify) == 0) in pd_revalidate()
816 set_capacity(p, disk->capacity); in pd_revalidate()
834 static void pd_probe_drive(struct pd_unit *disk) in pd_probe_drive() argument
839 strcpy(p->disk_name, disk->name); in pd_probe_drive()
842 p->first_minor = (disk - pd) << PD_BITS; in pd_probe_drive()
843 disk->gd = p; in pd_probe_drive()
844 p->private_data = disk; in pd_probe_drive()
847 if (disk->drive == -1) { in pd_probe_drive()
848 for (disk->drive = 0; disk->drive <= 1; disk->drive++) in pd_probe_drive()
849 if (pd_special_command(disk, pd_identify) == 0) in pd_probe_drive()
851 } else if (pd_special_command(disk, pd_identify) == 0) in pd_probe_drive()
853 disk->gd = NULL; in pd_probe_drive()
860 struct pd_unit *disk; in pd_detect() local
864 struct pd_unit *disk = pd + unit; in pd_detect() local
865 disk->pi = &disk->pia; in pd_detect()
866 disk->access = 0; in pd_detect()
867 disk->changed = 1; in pd_detect()
868 disk->capacity = 0; in pd_detect()
869 disk->drive = parm[D_SLV]; in pd_detect()
870 snprintf(disk->name, PD_NAMELEN, "%s%c", name, 'a'+unit); in pd_detect()
871 disk->alt_geom = parm[D_GEO]; in pd_detect()
872 disk->standby = parm[D_SBY]; in pd_detect()
884 disk = pd; in pd_detect()
885 if (pi_init(disk->pi, 1, -1, -1, -1, -1, -1, pd_scratch, in pd_detect()
886 PI_PD, verbose, disk->name)) { in pd_detect()
887 pd_probe_drive(disk); in pd_detect()
888 if (!disk->gd) in pd_detect()
889 pi_release(disk->pi); in pd_detect()
893 for (unit = 0, disk = pd; unit < PD_UNITS; unit++, disk++) { in pd_detect()
897 if (pi_init(disk->pi, 0, parm[D_PRT], parm[D_MOD], in pd_detect()
899 pd_scratch, PI_PD, verbose, disk->name)) { in pd_detect()
900 pd_probe_drive(disk); in pd_detect()
901 if (!disk->gd) in pd_detect()
902 pi_release(disk->pi); in pd_detect()
906 for (unit = 0, disk = pd; unit < PD_UNITS; unit++, disk++) { in pd_detect()
907 if (disk->gd) { in pd_detect()
908 set_capacity(disk->gd, disk->capacity); in pd_detect()
909 add_disk(disk->gd); in pd_detect()
951 struct pd_unit *disk; in pd_exit() local
954 for (unit = 0, disk = pd; unit < PD_UNITS; unit++, disk++) { in pd_exit()
955 struct gendisk *p = disk->gd; in pd_exit()
957 disk->gd = NULL; in pd_exit()
960 pi_release(disk->pi); in pd_exit()