Lines Matching refs:disk

233 	int changed;		/* Have we seen a disk change ? */
250 static inline int status_reg(struct pd_unit *disk)
252 return pi_read_regr(disk->pi, 1, 6);
255 static inline int read_reg(struct pd_unit *disk, int reg)
257 return pi_read_regr(disk->pi, 0, reg);
260 static inline void write_status(struct pd_unit *disk, int val)
262 pi_write_regr(disk->pi, 1, 6, val);
265 static inline void write_reg(struct pd_unit *disk, int reg, int val)
267 pi_write_regr(disk->pi, 0, reg, val);
270 static inline u8 DRIVE(struct pd_unit *disk)
272 return 0xa0+0x10*disk->drive;
277 static void pd_print_error(struct pd_unit *disk, char *msg, int status)
281 printk("%s: %s: status = 0x%x =", disk->name, msg, status);
288 static void pd_reset(struct pd_unit *disk)
290 write_status(disk, 4);
292 write_status(disk, 0);
298 static int pd_wait_for(struct pd_unit *disk, int w, char *msg)
304 r = status_reg(disk);
310 e = (read_reg(disk, 1) << 8) + read_reg(disk, 7);
314 pd_print_error(disk, msg, e);
318 static void pd_send_command(struct pd_unit *disk, int n, int s, int h, int c0, int c1, int func)
320 write_reg(disk, 6, DRIVE(disk) + h);
321 write_reg(disk, 1, 0); /* the IDE task file */
322 write_reg(disk, 2, n);
323 write_reg(disk, 3, s);
324 write_reg(disk, 4, c0);
325 write_reg(disk, 5, c1);
326 write_reg(disk, 7, func);
331 static void pd_ide_command(struct pd_unit *disk, int func, int block, int count)
335 if (disk->can_lba) {
341 s = (block % disk->sectors) + 1;
342 h = (block /= disk->sectors) % disk->heads;
343 c0 = (block /= disk->heads) % 256;
346 pd_send_command(disk, count, s, h, c0, c1, func);
587 static void pd_init_dev_parms(struct pd_unit *disk)
589 pd_wait_for(disk, 0, DBMSG("before init_dev_parms"));
590 pd_send_command(disk, disk->sectors, 0, disk->heads - 1, 0, 0,
593 pd_wait_for(disk, 0, "Initialise device parameters");
596 static enum action pd_door_lock(struct pd_unit *disk)
598 if (!(pd_wait_for(disk, STAT_READY, "Lock") & STAT_ERR)) {
599 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_DOORLOCK);
600 pd_wait_for(disk, STAT_READY, "Lock done");
605 static enum action pd_door_unlock(struct pd_unit *disk)
607 if (!(pd_wait_for(disk, STAT_READY, "Lock") & STAT_ERR)) {
608 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_DOORUNLOCK);
609 pd_wait_for(disk, STAT_READY, "Lock done");
614 static enum action pd_eject(struct pd_unit *disk)
616 pd_wait_for(disk, 0, DBMSG("before unlock on eject"));
617 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_DOORUNLOCK);
618 pd_wait_for(disk, 0, DBMSG("after unlock on eject"));
619 pd_wait_for(disk, 0, DBMSG("before eject"));
620 pd_send_command(disk, 0, 0, 0, 0, 0, IDE_EJECT);
621 pd_wait_for(disk, 0, DBMSG("after eject"));
625 static enum action pd_media_check(struct pd_unit *disk)
627 int r = pd_wait_for(disk, STAT_READY, DBMSG("before media_check"));
629 pd_send_command(disk, 1, 1, 0, 0, 0, IDE_READ_VRFY);
630 r = pd_wait_for(disk, STAT_READY, DBMSG("RDY after READ_VRFY"));
632 disk->changed = 1; /* say changed if other error */
634 disk->changed = 1;
635 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_ACKCHANGE);
636 pd_wait_for(disk, STAT_READY, DBMSG("RDY after ACKCHANGE"));
637 pd_send_command(disk, 1, 1, 0, 0, 0, IDE_READ_VRFY);
638 r = pd_wait_for(disk, STAT_READY, DBMSG("RDY after VRFY"));
643 static void pd_standby_off(struct pd_unit *disk)
645 pd_wait_for(disk, 0, DBMSG("before STANDBY"));
646 pd_send_command(disk, 0, 0, 0, 0, 0, IDE_STANDBY);
647 pd_wait_for(disk, 0, DBMSG("after STANDBY"));
650 static enum action pd_identify(struct pd_unit *disk)
661 if (disk->drive == 0)
662 pd_reset(disk);
664 write_reg(disk, 6, DRIVE(disk));
665 pd_wait_for(disk, 0, DBMSG("before IDENT"));
666 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_IDENTIFY);
668 if (pd_wait_for(disk, STAT_DRQ, DBMSG("IDENT DRQ")) & STAT_ERR)
670 pi_read_block(disk->pi, pd_scratch, 512);
671 disk->can_lba = pd_scratch[99] & 2;
672 disk->sectors = le16_to_cpu(*(__le16 *) (pd_scratch + 12));
673 disk->heads = le16_to_cpu(*(__le16 *) (pd_scratch + 6));
674 disk->cylinders = le16_to_cpu(*(__le16 *) (pd_scratch + 2));
675 if (disk->can_lba)
676 disk->capacity = le32_to_cpu(*(__le32 *) (pd_scratch + 120));
678 disk->capacity = disk->sectors * disk->heads * disk->cylinders;
688 disk->removable = pd_scratch[0] & 0x80;
691 disk->name, id,
692 disk->drive ? "slave" : "master",
693 disk->capacity, disk->capacity / 2048,
694 disk->cylinders, disk->heads, disk->sectors,
695 disk->removable ? "removable" : "fixed");
697 if (disk->capacity)
698 pd_init_dev_parms(disk);
699 if (!disk->standby)
700 pd_standby_off(disk);
718 static int pd_special_command(struct pd_unit *disk,
719 enum action (*func)(struct pd_unit *disk))
724 rq = blk_get_request(disk->gd->queue, READ, __GFP_WAIT);
729 err = blk_execute_rq(disk->gd->queue, disk->gd, rq, 0);
739 struct pd_unit *disk = bdev->bd_disk->private_data;
742 disk->access++;
744 if (disk->removable) {
745 pd_special_command(disk, pd_media_check);
746 pd_special_command(disk, pd_door_lock);
754 struct pd_unit *disk = bdev->bd_disk->private_data;
756 if (disk->alt_geom) {
759 geo->cylinders = disk->capacity / (geo->heads * geo->sectors);
761 geo->heads = disk->heads;
762 geo->sectors = disk->sectors;
763 geo->cylinders = disk->cylinders;
772 struct pd_unit *disk = bdev->bd_disk->private_data;
777 if (disk->access == 1)
778 pd_special_command(disk, pd_eject);
788 struct pd_unit *disk = p->private_data;
791 if (!--disk->access && disk->removable)
792 pd_special_command(disk, pd_door_unlock);
800 struct pd_unit *disk = p->private_data;
802 if (!disk->removable)
804 pd_special_command(disk, pd_media_check);
805 r = disk->changed;
806 disk->changed = 0;
812 struct pd_unit *disk = p->private_data;
813 if (pd_special_command(disk, pd_identify) == 0)
814 set_capacity(p, disk->capacity);
832 static void pd_probe_drive(struct pd_unit *disk)
837 strcpy(p->disk_name, disk->name);
840 p->first_minor = (disk - pd) << PD_BITS;
841 disk->gd = p;
842 p->private_data = disk;
845 if (disk->drive == -1) {
846 for (disk->drive = 0; disk->drive <= 1; disk->drive++)
847 if (pd_special_command(disk, pd_identify) == 0)
849 } else if (pd_special_command(disk, pd_identify) == 0)
851 disk->gd = NULL;
858 struct pd_unit *disk;
862 struct pd_unit *disk = pd + unit;
863 disk->pi = &disk->pia;
864 disk->access = 0;
865 disk->changed = 1;
866 disk->capacity = 0;
867 disk->drive = parm[D_SLV];
868 snprintf(disk->name, PD_NAMELEN, "%s%c", name, 'a'+unit);
869 disk->alt_geom = parm[D_GEO];
870 disk->standby = parm[D_SBY];
876 disk = pd;
877 if (pi_init(disk->pi, 1, -1, -1, -1, -1, -1, pd_scratch,
878 PI_PD, verbose, disk->name)) {
879 pd_probe_drive(disk);
880 if (!disk->gd)
881 pi_release(disk->pi);
885 for (unit = 0, disk = pd; unit < PD_UNITS; unit++, disk++) {
889 if (pi_init(disk->pi, 0, parm[D_PRT], parm[D_MOD],
891 pd_scratch, PI_PD, verbose, disk->name)) {
892 pd_probe_drive(disk);
893 if (!disk->gd)
894 pi_release(disk->pi);
898 for (unit = 0, disk = pd; unit < PD_UNITS; unit++, disk++) {
899 if (disk->gd) {
900 set_capacity(disk->gd, disk->capacity);
901 add_disk(disk->gd);
941 struct pd_unit *disk;
944 for (unit = 0, disk = pd; unit < PD_UNITS; unit++, disk++) {
945 struct gendisk *p = disk->gd;
947 disk->gd = NULL;
950 pi_release(disk->pi);