Lines Matching refs:drive

56 static void ide_tf_set_cmd(ide_drive_t *drive, struct ide_cmd *cmd, u8 dma)
68 if (drive->mult_count) {
82 static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
85 ide_hwif_t *hwif = drive->hwif;
87 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
88 u8 dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
104 if (drive->dev_flags & IDE_DFLAG_LBA) {
106 pr_debug("%s: LBA=0x%012llx\n", drive->name,
136 track = (int)block / drive->sect;
137 sect = (int)block % drive->sect + 1;
138 head = track % drive->head;
139 cyl = track / drive->head;
141 pr_debug("%s: CHS=%u/%u/%u\n", drive->name, cyl, head, sect);
155 ide_tf_set_cmd(drive, &cmd, dma);
160 ide_map_sg(drive, &cmd);
163 rc = do_rw_taskfile(drive, &cmd);
168 ide_tf_set_cmd(drive, &cmd, 0);
170 rc = do_rw_taskfile(drive, &cmd);
179 * 1073741822 == 549756 MB or 48bit addressing fake drive
182 static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
185 ide_hwif_t *hwif = drive->hwif;
187 BUG_ON(drive->dev_flags & IDE_DFLAG_BLOCKED);
193 drive->name, rq_data_dir(rq) == READ ? "read" : "writ",
197 hwif->rw_disk(drive, rq);
199 return __ide_do_rw_disk(drive, rq, block);
203 * Queries for true maximum capacity of the drive.
204 * Returns maximum LBA address (> 0) of the drive, 0 if failed.
206 static u64 idedisk_read_native_max_address(ide_drive_t *drive, int lba48)
227 ide_no_data_taskfile(drive, &cmd);
237 * Sets maximum virtual LBA address of the drive.
240 static u64 idedisk_set_max_address(ide_drive_t *drive, u64 addr_req, int lba48)
271 ide_no_data_taskfile(drive, &cmd);
298 static u64 ide_disk_hpa_get_native_capacity(ide_drive_t *drive, int lba48)
302 capacity = drive->capacity64;
303 set_max = idedisk_read_native_max_address(drive, lba48);
305 if (ide_in_drive_list(drive->id, hpa_list)) {
317 static u64 ide_disk_hpa_set_capacity(ide_drive_t *drive, u64 set_max, int lba48)
319 set_max = idedisk_set_max_address(drive, set_max, lba48);
321 drive->capacity64 = set_max;
326 static void idedisk_check_hpa(ide_drive_t *drive)
329 int lba48 = ata_id_lba48_enabled(drive->id);
331 capacity = drive->capacity64;
332 set_max = ide_disk_hpa_get_native_capacity(drive, lba48);
337 drive->probed_capacity = set_max;
342 drive->name,
346 if ((drive->dev_flags & IDE_DFLAG_NOHPA) == 0)
349 set_max = ide_disk_hpa_set_capacity(drive, set_max, lba48);
352 drive->name);
355 static int ide_disk_get_capacity(ide_drive_t *drive)
357 u16 *id = drive->id;
361 /* drive speaks 48-bit LBA */
363 drive->capacity64 = ata_id_u64(id, ATA_ID_LBA_CAPACITY_2);
365 /* drive speaks 28-bit LBA */
367 drive->capacity64 = ata_id_u32(id, ATA_ID_LBA_CAPACITY);
369 /* drive speaks boring old 28-bit CHS */
371 drive->capacity64 = drive->cyl * drive->head * drive->sect;
374 drive->probed_capacity = drive->capacity64;
377 drive->dev_flags |= IDE_DFLAG_LBA;
384 idedisk_check_hpa(drive);
387 /* limit drive capacity to 137GB if LBA48 cannot be used */
388 if ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 &&
389 drive->capacity64 > 1ULL << 28) {
392 drive->name, (unsigned long long)drive->capacity64,
393 sectors_to_MB(drive->capacity64));
394 drive->probed_capacity = drive->capacity64 = 1ULL << 28;
397 if ((drive->hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) &&
398 (drive->dev_flags & IDE_DFLAG_LBA48)) {
399 if (drive->capacity64 > 1ULL << 28) {
402 "> %u\n", drive->name, 1 << 28);
404 drive->dev_flags &= ~IDE_DFLAG_LBA48;
410 static void ide_disk_unlock_native_capacity(ide_drive_t *drive)
412 u16 *id = drive->id;
415 if ((drive->dev_flags & IDE_DFLAG_LBA) == 0 ||
423 if (!ide_disk_hpa_get_native_capacity(drive, lba48))
426 if (ide_disk_hpa_set_capacity(drive, drive->probed_capacity, lba48))
427 drive->dev_flags |= IDE_DFLAG_NOHPA; /* disable HPA on resume */
430 static bool idedisk_prep_rq(ide_drive_t *drive, struct request *rq)
447 if (ata_id_flush_ext_enabled(drive->id) &&
448 (drive->capacity64 >= (1UL << 28)))
470 static int set_multcount(ide_drive_t *drive, int arg)
474 if (arg < 0 || arg > (drive->id[ATA_ID_MAX_MULTSECT] & 0xff))
477 if (drive->special_flags & IDE_SFLAG_SET_MULTMODE)
480 rq = blk_get_request(drive->queue, REQ_OP_DRV_IN, 0);
483 drive->mult_req = arg;
484 drive->special_flags |= IDE_SFLAG_SET_MULTMODE;
485 blk_execute_rq(drive->queue, NULL, rq, 0);
488 return (drive->mult_count == arg) ? 0 : -EIO;
493 static int set_nowerr(ide_drive_t *drive, int arg)
499 drive->dev_flags |= IDE_DFLAG_NOWERR;
501 drive->dev_flags &= ~IDE_DFLAG_NOWERR;
503 drive->bad_wstat = arg ? BAD_R_STAT : BAD_W_STAT;
508 static int ide_do_setfeature(ide_drive_t *drive, u8 feature, u8 nsect)
519 return ide_no_data_taskfile(drive, &cmd);
522 static void update_flush(ide_drive_t *drive)
524 u16 *id = drive->id;
527 if (drive->dev_flags & IDE_DFLAG_WCACHE) {
531 * We must avoid issuing commands a drive does not
534 * cache if the drive capacity is too large. By this
535 * time we have trimmed the drive capacity if LBA48 is
538 capacity = ide_gd_capacity(drive);
540 (drive->dev_flags & IDE_DFLAG_NOFLUSH) == 0 &&
541 ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 ||
546 drive->name, barrier ? "" : "not ");
550 drive->prep_rq = idedisk_prep_rq;
554 blk_queue_write_cache(drive->queue, wc, false);
559 static int set_wcache(ide_drive_t *drive, int arg)
566 if (ata_id_flush_enabled(drive->id)) {
567 err = ide_do_setfeature(drive,
571 drive->dev_flags |= IDE_DFLAG_WCACHE;
573 drive->dev_flags &= ~IDE_DFLAG_WCACHE;
577 update_flush(drive);
582 static int do_idedisk_flushcache(ide_drive_t *drive)
587 if (ata_id_flush_ext_enabled(drive->id))
594 return ide_no_data_taskfile(drive, &cmd);
599 static int set_acoustic(ide_drive_t *drive, int arg)
604 ide_do_setfeature(drive,
607 drive->acoustic = arg;
615 * drive->addressing:
620 static int set_addressing(ide_drive_t *drive, int arg)
625 if (arg && ((drive->hwif->host_flags & IDE_HFLAG_NO_LBA48) ||
626 ata_id_lba48_enabled(drive->id) == 0))
633 drive->dev_flags |= IDE_DFLAG_LBA48;
635 drive->dev_flags &= ~IDE_DFLAG_LBA48;
647 static int ide_disk_check(ide_drive_t *drive, const char *s)
652 static void ide_disk_setup(ide_drive_t *drive)
654 struct ide_disk_obj *idkp = drive->driver_data;
655 struct request_queue *q = drive->queue;
656 ide_hwif_t *hwif = drive->hwif;
657 u16 *id = drive->id;
661 ide_proc_register_driver(drive, idkp->driver);
663 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0)
666 if (drive->dev_flags & IDE_DFLAG_REMOVABLE) {
671 drive->dev_flags |= IDE_DFLAG_DOORLOCKING;
674 (void)set_addressing(drive, 1);
676 if (drive->dev_flags & IDE_DFLAG_LBA48) {
685 printk(KERN_INFO "%s: max request size: %dKiB\n", drive->name,
693 /* calculate drive capacity, and select LBA if possible */
694 ide_disk_get_capacity(drive);
697 * if possible, give fdisk access to more of the drive,
700 capacity = ide_gd_capacity(drive);
702 if ((drive->dev_flags & IDE_DFLAG_FORCED_GEOM) == 0) {
703 if (ata_id_lba48_enabled(drive->id)) {
705 drive->bios_sect = 63;
706 drive->bios_head = 255;
709 if (drive->bios_sect && drive->bios_head) {
714 drive->bios_cyl = 65535;
716 cylsz = drive->bios_sect * drive->bios_head;
720 if (cyl > drive->bios_cyl)
721 drive->bios_cyl = cyl;
726 drive->name, capacity, sectors_to_MB(capacity));
733 drive->bios_cyl, drive->bios_head, drive->bios_sect);
737 drive->dev_flags |= IDE_DFLAG_WCACHE;
739 set_wcache(drive, 1);
741 if ((drive->dev_flags & IDE_DFLAG_LBA) == 0 &&
742 (drive->head == 0 || drive->head > 16))
744 drive->name, drive->head);
747 static void ide_disk_flush(ide_drive_t *drive)
749 if (ata_id_flush_enabled(drive->id) == 0 ||
750 (drive->dev_flags & IDE_DFLAG_WCACHE) == 0)
753 if (do_idedisk_flushcache(drive))
754 printk(KERN_INFO "%s: wcache flush failed!\n", drive->name);
757 static int ide_disk_init_media(ide_drive_t *drive, struct gendisk *disk)
762 static int ide_disk_set_doorlock(ide_drive_t *drive, struct gendisk *disk,
768 if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) == 0)
776 ret = ide_no_data_taskfile(drive, &cmd);
779 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;