Lines Matching refs:disk

233 	int changed;		/* Have we seen a disk change ? */
247 enum action (*func)(struct pd_unit *disk);
259 static inline int status_reg(struct pd_unit *disk)
261 return pi_read_regr(disk->pi, 1, 6);
264 static inline int read_reg(struct pd_unit *disk, int reg)
266 return pi_read_regr(disk->pi, 0, reg);
269 static inline void write_status(struct pd_unit *disk, int val)
271 pi_write_regr(disk->pi, 1, 6, val);
274 static inline void write_reg(struct pd_unit *disk, int reg, int val)
276 pi_write_regr(disk->pi, 0, reg, val);
279 static inline u8 DRIVE(struct pd_unit *disk)
281 return 0xa0+0x10*disk->drive;
286 static void pd_print_error(struct pd_unit *disk, char *msg, int status)
290 printk("%s: %s: status = 0x%x =", disk->name, msg, status);
297 static void pd_reset(struct pd_unit *disk)
299 write_status(disk, 4);
301 write_status(disk, 0);
307 static int pd_wait_for(struct pd_unit *disk, int w, char *msg)
313 r = status_reg(disk);
319 e = (read_reg(disk, 1) << 8) + read_reg(disk, 7);
323 pd_print_error(disk, msg, e);
327 static void pd_send_command(struct pd_unit *disk, int n, int s, int h, int c0, int c1, int func)
329 write_reg(disk, 6, DRIVE(disk) + h);
330 write_reg(disk, 1, 0); /* the IDE task file */
331 write_reg(disk, 2, n);
332 write_reg(disk, 3, s);
333 write_reg(disk, 4, c0);
334 write_reg(disk, 5, c1);
335 write_reg(disk, 7, func);
340 static void pd_ide_command(struct pd_unit *disk, int func, int block, int count)
344 if (disk->can_lba) {
350 s = (block % disk->sectors) + 1;
351 h = (block /= disk->sectors) % disk->heads;
352 c0 = (block /= disk->heads) % 256;
355 pd_send_command(disk, count, s, h, c0, c1, func);
399 struct gendisk *disk;
404 disk = pd[pd_queue].gd;
405 q = disk ? disk->queue : NULL;
409 struct pd_unit *disk = q->queuedata;
411 if (list_empty(&disk->rq_list))
414 pd_req = list_first_entry(&disk->rq_list,
635 static void pd_init_dev_parms(struct pd_unit *disk)
637 pd_wait_for(disk, 0, DBMSG("before init_dev_parms"));
638 pd_send_command(disk, disk->sectors, 0, disk->heads - 1, 0, 0,
641 pd_wait_for(disk, 0, "Initialise device parameters");
644 static enum action pd_door_lock(struct pd_unit *disk)
646 if (!(pd_wait_for(disk, STAT_READY, "Lock") & STAT_ERR)) {
647 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_DOORLOCK);
648 pd_wait_for(disk, STAT_READY, "Lock done");
653 static enum action pd_door_unlock(struct pd_unit *disk)
655 if (!(pd_wait_for(disk, STAT_READY, "Lock") & STAT_ERR)) {
656 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_DOORUNLOCK);
657 pd_wait_for(disk, STAT_READY, "Lock done");
662 static enum action pd_eject(struct pd_unit *disk)
664 pd_wait_for(disk, 0, DBMSG("before unlock on eject"));
665 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_DOORUNLOCK);
666 pd_wait_for(disk, 0, DBMSG("after unlock on eject"));
667 pd_wait_for(disk, 0, DBMSG("before eject"));
668 pd_send_command(disk, 0, 0, 0, 0, 0, IDE_EJECT);
669 pd_wait_for(disk, 0, DBMSG("after eject"));
673 static enum action pd_media_check(struct pd_unit *disk)
675 int r = pd_wait_for(disk, STAT_READY, DBMSG("before media_check"));
677 pd_send_command(disk, 1, 1, 0, 0, 0, IDE_READ_VRFY);
678 r = pd_wait_for(disk, STAT_READY, DBMSG("RDY after READ_VRFY"));
680 disk->changed = 1; /* say changed if other error */
682 disk->changed = 1;
683 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_ACKCHANGE);
684 pd_wait_for(disk, STAT_READY, DBMSG("RDY after ACKCHANGE"));
685 pd_send_command(disk, 1, 1, 0, 0, 0, IDE_READ_VRFY);
686 r = pd_wait_for(disk, STAT_READY, DBMSG("RDY after VRFY"));
691 static void pd_standby_off(struct pd_unit *disk)
693 pd_wait_for(disk, 0, DBMSG("before STANDBY"));
694 pd_send_command(disk, 0, 0, 0, 0, 0, IDE_STANDBY);
695 pd_wait_for(disk, 0, DBMSG("after STANDBY"));
698 static enum action pd_identify(struct pd_unit *disk)
709 if (disk->drive == 0)
710 pd_reset(disk);
712 write_reg(disk, 6, DRIVE(disk));
713 pd_wait_for(disk, 0, DBMSG("before IDENT"));
714 pd_send_command(disk, 1, 0, 0, 0, 0, IDE_IDENTIFY);
716 if (pd_wait_for(disk, STAT_DRQ, DBMSG("IDENT DRQ")) & STAT_ERR)
718 pi_read_block(disk->pi, pd_scratch, 512);
719 disk->can_lba = pd_scratch[99] & 2;
720 disk->sectors = le16_to_cpu(*(__le16 *) (pd_scratch + 12));
721 disk->heads = le16_to_cpu(*(__le16 *) (pd_scratch + 6));
722 disk->cylinders = le16_to_cpu(*(__le16 *) (pd_scratch + 2));
723 if (disk->can_lba)
724 disk->capacity = le32_to_cpu(*(__le32 *) (pd_scratch + 120));
726 disk->capacity = disk->sectors * disk->heads * disk->cylinders;
736 disk->removable = pd_scratch[0] & 0x80;
739 disk->name, id,
740 disk->drive ? "slave" : "master",
741 disk->capacity, disk->capacity / 2048,
742 disk->cylinders, disk->heads, disk->sectors,
743 disk->removable ? "removable" : "fixed");
745 if (disk->capacity)
746 pd_init_dev_parms(disk);
747 if (!disk->standby)
748 pd_standby_off(disk);
758 struct pd_unit *disk = hctx->queue->queuedata;
765 list_add_tail(&bd->rq->queuelist, &disk->rq_list);
772 static int pd_special_command(struct pd_unit *disk,
773 enum action (*func)(struct pd_unit *disk))
778 rq = blk_get_request(disk->gd->queue, REQ_OP_DRV_IN, 0);
784 blk_execute_rq(disk->gd->queue, disk->gd, rq, 0);
793 struct pd_unit *disk = bdev->bd_disk->private_data;
796 disk->access++;
798 if (disk->removable) {
799 pd_special_command(disk, pd_media_check);
800 pd_special_command(disk, pd_door_lock);
808 struct pd_unit *disk = bdev->bd_disk->private_data;
810 if (disk->alt_geom) {
813 geo->cylinders = disk->capacity / (geo->heads * geo->sectors);
815 geo->heads = disk->heads;
816 geo->sectors = disk->sectors;
817 geo->cylinders = disk->cylinders;
826 struct pd_unit *disk = bdev->bd_disk->private_data;
831 if (disk->access == 1)
832 pd_special_command(disk, pd_eject);
842 struct pd_unit *disk = p->private_data;
845 if (!--disk->access && disk->removable)
846 pd_special_command(disk, pd_door_unlock);
852 struct pd_unit *disk = p->private_data;
854 if (!disk->removable)
856 pd_special_command(disk, pd_media_check);
857 r = disk->changed;
858 disk->changed = 0;
864 struct pd_unit *disk = p->private_data;
865 if (pd_special_command(disk, pd_identify) == 0)
866 set_capacity(p, disk->capacity);
889 static void pd_probe_drive(struct pd_unit *disk)
897 strcpy(p->disk_name, disk->name);
900 p->first_minor = (disk - pd) << PD_BITS;
902 disk->gd = p;
903 p->private_data = disk;
905 memset(&disk->tag_set, 0, sizeof(disk->tag_set));
906 disk->tag_set.ops = &pd_mq_ops;
907 disk->tag_set.cmd_size = sizeof(struct pd_req);
908 disk->tag_set.nr_hw_queues = 1;
909 disk->tag_set.nr_maps = 1;
910 disk->tag_set.queue_depth = 2;
911 disk->tag_set.numa_node = NUMA_NO_NODE;
912 disk->tag_set.flags = BLK_MQ_F_SHOULD_MERGE | BLK_MQ_F_BLOCKING;
914 if (blk_mq_alloc_tag_set(&disk->tag_set))
917 p->queue = blk_mq_init_queue(&disk->tag_set);
919 blk_mq_free_tag_set(&disk->tag_set);
924 p->queue->queuedata = disk;
928 if (disk->drive == -1) {
929 for (disk->drive = 0; disk->drive <= 1; disk->drive++)
930 if (pd_special_command(disk, pd_identify) == 0)
932 } else if (pd_special_command(disk, pd_identify) == 0)
934 disk->gd = NULL;
941 struct pd_unit *disk;
945 struct pd_unit *disk = pd + unit;
946 disk->pi = &disk->pia;
947 disk->access = 0;
948 disk->changed = 1;
949 disk->capacity = 0;
950 disk->drive = parm[D_SLV];
951 snprintf(disk->name, PD_NAMELEN, "%s%c", name, 'a'+unit);
952 disk->alt_geom = parm[D_GEO];
953 disk->standby = parm[D_SBY];
956 INIT_LIST_HEAD(&disk->rq_list);
966 disk = pd;
967 if (pi_init(disk->pi, 1, -1, -1, -1, -1, -1, pd_scratch,
968 PI_PD, verbose, disk->name)) {
969 pd_probe_drive(disk);
970 if (!disk->gd)
971 pi_release(disk->pi);
975 for (unit = 0, disk = pd; unit < PD_UNITS; unit++, disk++) {
979 if (pi_init(disk->pi, 0, parm[D_PRT], parm[D_MOD],
981 pd_scratch, PI_PD, verbose, disk->name)) {
982 pd_probe_drive(disk);
983 if (!disk->gd)
984 pi_release(disk->pi);
988 for (unit = 0, disk = pd; unit < PD_UNITS; unit++, disk++) {
989 if (disk->gd) {
990 set_capacity(disk->gd, disk->capacity);
991 add_disk(disk->gd);
1025 struct pd_unit *disk;
1028 for (unit = 0, disk = pd; unit < PD_UNITS; unit++, disk++) {
1029 struct gendisk *p = disk->gd;
1031 disk->gd = NULL;
1034 blk_mq_free_tag_set(&disk->tag_set);
1036 pi_release(disk->pi);