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()
392 struct gendisk *disk; in set_next_request() local
397 disk = pd[pd_queue].gd; in set_next_request()
398 q = disk ? disk->queue : NULL; in set_next_request()
607 static void pd_init_dev_parms(struct pd_unit *disk) in pd_init_dev_parms() argument
609 pd_wait_for(disk, 0, DBMSG("before init_dev_parms")); in pd_init_dev_parms()
610 pd_send_command(disk, disk->sectors, 0, disk->heads - 1, 0, 0, in pd_init_dev_parms()
613 pd_wait_for(disk, 0, "Initialise device parameters"); in pd_init_dev_parms()
616 static enum action pd_door_lock(struct pd_unit *disk) in pd_door_lock() argument
618 if (!(pd_wait_for(disk, STAT_READY, "Lock") & STAT_ERR)) { in pd_door_lock()
619 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_DOORLOCK); in pd_door_lock()
620 pd_wait_for(disk, STAT_READY, "Lock done"); in pd_door_lock()
625 static enum action pd_door_unlock(struct pd_unit *disk) in pd_door_unlock() argument
627 if (!(pd_wait_for(disk, STAT_READY, "Lock") & STAT_ERR)) { in pd_door_unlock()
628 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_DOORUNLOCK); in pd_door_unlock()
629 pd_wait_for(disk, STAT_READY, "Lock done"); in pd_door_unlock()
634 static enum action pd_eject(struct pd_unit *disk) in pd_eject() argument
636 pd_wait_for(disk, 0, DBMSG("before unlock on eject")); in pd_eject()
637 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_DOORUNLOCK); in pd_eject()
638 pd_wait_for(disk, 0, DBMSG("after unlock on eject")); in pd_eject()
639 pd_wait_for(disk, 0, DBMSG("before eject")); in pd_eject()
640 pd_send_command(disk, 0, 0, 0, 0, 0, IDE_EJECT); in pd_eject()
641 pd_wait_for(disk, 0, DBMSG("after eject")); in pd_eject()
645 static enum action pd_media_check(struct pd_unit *disk) in pd_media_check() argument
647 int r = pd_wait_for(disk, STAT_READY, DBMSG("before media_check")); in pd_media_check()
649 pd_send_command(disk, 1, 1, 0, 0, 0, IDE_READ_VRFY); in pd_media_check()
650 r = pd_wait_for(disk, STAT_READY, DBMSG("RDY after READ_VRFY")); in pd_media_check()
652 disk->changed = 1; /* say changed if other error */ in pd_media_check()
654 disk->changed = 1; in pd_media_check()
655 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_ACKCHANGE); in pd_media_check()
656 pd_wait_for(disk, STAT_READY, DBMSG("RDY after ACKCHANGE")); in pd_media_check()
657 pd_send_command(disk, 1, 1, 0, 0, 0, IDE_READ_VRFY); in pd_media_check()
658 r = pd_wait_for(disk, STAT_READY, DBMSG("RDY after VRFY")); in pd_media_check()
663 static void pd_standby_off(struct pd_unit *disk) in pd_standby_off() argument
665 pd_wait_for(disk, 0, DBMSG("before STANDBY")); in pd_standby_off()
666 pd_send_command(disk, 0, 0, 0, 0, 0, IDE_STANDBY); in pd_standby_off()
667 pd_wait_for(disk, 0, DBMSG("after STANDBY")); in pd_standby_off()
670 static enum action pd_identify(struct pd_unit *disk) in pd_identify() argument
681 if (disk->drive == 0) in pd_identify()
682 pd_reset(disk); in pd_identify()
684 write_reg(disk, 6, DRIVE(disk)); in pd_identify()
685 pd_wait_for(disk, 0, DBMSG("before IDENT")); in pd_identify()
686 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_IDENTIFY); in pd_identify()
688 if (pd_wait_for(disk, STAT_DRQ, DBMSG("IDENT DRQ")) & STAT_ERR) in pd_identify()
690 pi_read_block(disk->pi, pd_scratch, 512); in pd_identify()
691 disk->can_lba = pd_scratch[99] & 2; in pd_identify()
692 disk->sectors = le16_to_cpu(*(__le16 *) (pd_scratch + 12)); in pd_identify()
693 disk->heads = le16_to_cpu(*(__le16 *) (pd_scratch + 6)); in pd_identify()
694 disk->cylinders = le16_to_cpu(*(__le16 *) (pd_scratch + 2)); in pd_identify()
695 if (disk->can_lba) in pd_identify()
696 disk->capacity = le32_to_cpu(*(__le32 *) (pd_scratch + 120)); in pd_identify()
698 disk->capacity = disk->sectors * disk->heads * disk->cylinders; in pd_identify()
708 disk->removable = pd_scratch[0] & 0x80; in pd_identify()
711 disk->name, id, in pd_identify()
712 disk->drive ? "slave" : "master", in pd_identify()
713 disk->capacity, disk->capacity / 2048, in pd_identify()
714 disk->cylinders, disk->heads, disk->sectors, in pd_identify()
715 disk->removable ? "removable" : "fixed"); in pd_identify()
717 if (disk->capacity) in pd_identify()
718 pd_init_dev_parms(disk); in pd_identify()
719 if (!disk->standby) in pd_identify()
720 pd_standby_off(disk); in pd_identify()
738 static int pd_special_command(struct pd_unit *disk, in pd_special_command() argument
739 enum action (*func)(struct pd_unit *disk)) in pd_special_command() argument
743 rq = blk_get_request(disk->gd->queue, REQ_OP_DRV_IN, __GFP_RECLAIM); in pd_special_command()
748 blk_execute_rq(disk->gd->queue, disk->gd, rq, 0); in pd_special_command()
757 struct pd_unit *disk = bdev->bd_disk->private_data; in pd_open() local
760 disk->access++; in pd_open()
762 if (disk->removable) { in pd_open()
763 pd_special_command(disk, pd_media_check); in pd_open()
764 pd_special_command(disk, pd_door_lock); in pd_open()
772 struct pd_unit *disk = bdev->bd_disk->private_data; in pd_getgeo() local
774 if (disk->alt_geom) { in pd_getgeo()
777 geo->cylinders = disk->capacity / (geo->heads * geo->sectors); in pd_getgeo()
779 geo->heads = disk->heads; in pd_getgeo()
780 geo->sectors = disk->sectors; in pd_getgeo()
781 geo->cylinders = disk->cylinders; in pd_getgeo()
790 struct pd_unit *disk = bdev->bd_disk->private_data; in pd_ioctl() local
795 if (disk->access == 1) in pd_ioctl()
796 pd_special_command(disk, pd_eject); in pd_ioctl()
806 struct pd_unit *disk = p->private_data; in pd_release() local
809 if (!--disk->access && disk->removable) in pd_release()
810 pd_special_command(disk, pd_door_unlock); in pd_release()
816 struct pd_unit *disk = p->private_data; in pd_check_events() local
818 if (!disk->removable) in pd_check_events()
820 pd_special_command(disk, pd_media_check); in pd_check_events()
821 r = disk->changed; in pd_check_events()
822 disk->changed = 0; in pd_check_events()
828 struct pd_unit *disk = p->private_data; in pd_revalidate() local
829 if (pd_special_command(disk, pd_identify) == 0) in pd_revalidate()
830 set_capacity(p, disk->capacity); in pd_revalidate()
848 static void pd_probe_drive(struct pd_unit *disk) in pd_probe_drive() argument
853 strcpy(p->disk_name, disk->name); in pd_probe_drive()
856 p->first_minor = (disk - pd) << PD_BITS; in pd_probe_drive()
857 disk->gd = p; in pd_probe_drive()
858 p->private_data = disk; in pd_probe_drive()
861 disk->gd = NULL; in pd_probe_drive()
868 if (disk->drive == -1) { in pd_probe_drive()
869 for (disk->drive = 0; disk->drive <= 1; disk->drive++) in pd_probe_drive()
870 if (pd_special_command(disk, pd_identify) == 0) in pd_probe_drive()
872 } else if (pd_special_command(disk, pd_identify) == 0) in pd_probe_drive()
874 disk->gd = NULL; in pd_probe_drive()
881 struct pd_unit *disk; in pd_detect() local
885 struct pd_unit *disk = pd + unit; in pd_detect() local
886 disk->pi = &disk->pia; in pd_detect()
887 disk->access = 0; in pd_detect()
888 disk->changed = 1; in pd_detect()
889 disk->capacity = 0; in pd_detect()
890 disk->drive = parm[D_SLV]; in pd_detect()
891 snprintf(disk->name, PD_NAMELEN, "%s%c", name, 'a'+unit); in pd_detect()
892 disk->alt_geom = parm[D_GEO]; in pd_detect()
893 disk->standby = parm[D_SBY]; in pd_detect()
905 disk = pd; in pd_detect()
906 if (pi_init(disk->pi, 1, -1, -1, -1, -1, -1, pd_scratch, in pd_detect()
907 PI_PD, verbose, disk->name)) { in pd_detect()
908 pd_probe_drive(disk); in pd_detect()
909 if (!disk->gd) in pd_detect()
910 pi_release(disk->pi); in pd_detect()
914 for (unit = 0, disk = pd; unit < PD_UNITS; unit++, disk++) { in pd_detect()
918 if (pi_init(disk->pi, 0, parm[D_PRT], parm[D_MOD], in pd_detect()
920 pd_scratch, PI_PD, verbose, disk->name)) { in pd_detect()
921 pd_probe_drive(disk); in pd_detect()
922 if (!disk->gd) in pd_detect()
923 pi_release(disk->pi); in pd_detect()
927 for (unit = 0, disk = pd; unit < PD_UNITS; unit++, disk++) { in pd_detect()
928 if (disk->gd) { in pd_detect()
929 set_capacity(disk->gd, disk->capacity); in pd_detect()
930 add_disk(disk->gd); in pd_detect()
964 struct pd_unit *disk; in pd_exit() local
967 for (unit = 0, disk = pd; unit < PD_UNITS; unit++, disk++) { in pd_exit()
968 struct gendisk *p = disk->gd; in pd_exit()
970 disk->gd = NULL; in pd_exit()
974 pi_release(disk->pi); in pd_exit()