17 #include <linux/types.h>
18 #include <linux/string.h>
19 #include <linux/kernel.h>
24 #include <linux/errno.h>
26 #include <linux/slab.h>
32 #include <asm/byteorder.h>
34 #include <asm/uaccess.h>
36 #include <asm/div64.h>
40 static const u8 ide_rw_cmds[] = {
74 cmd->
tf.command = ide_rw_cmds[index + lba48 +
write];
85 u16 nsectors = (
u16)blk_rq_sectors(rq);
93 if (block + blk_rq_sectors(rq) > 1ULL << 28)
99 memset(&cmd, 0,
sizeof(cmd));
106 (
unsigned long long)block);
108 tf->
nsect = nsectors & 0xff;
110 tf->
lbam = (
u8)(block >> 8);
111 tf->
lbah = (
u8)(block >> 16);
115 tf->
nsect = (nsectors >> 8) & 0xff;
116 tf->
lbal = (
u8)(block >> 24);
117 if (
sizeof(block) != 4) {
126 tf->
nsect = nsectors & 0xff;
128 tf->
lbam = block >>= 8;
129 tf->
lbah = block >>= 8;
135 track = (
int)block / drive->
sect;
136 sect = (
int)block % drive->
sect + 1;
137 head = track % drive->
head;
138 cyl = track / drive->
head;
140 pr_debug(
"%s: CHS=%u/%u/%u\n", drive->
name, cyl, head, sect);
142 tf->
nsect = nsectors & 0xff;
154 ide_tf_set_cmd(drive, &cmd, dma);
167 ide_tf_set_cmd(drive, &cmd, 0);
187 BUG_ON(rq->cmd_type != REQ_TYPE_FS);
191 pr_debug(
"%s: %sing: block=%llu, sectors=%u, buffer=0x%08lx\n",
192 drive->
name, rq_data_dir(rq) ==
READ ?
"read" :
"writ",
193 (
unsigned long long)block, blk_rq_sectors(rq),
194 (
unsigned long)rq->buffer);
199 return __ide_do_rw_disk(drive, rq, block);
206 static u64 idedisk_read_native_max_address(
ide_drive_t *drive,
int lba48)
212 memset(&cmd, 0,
sizeof(cmd));
248 memset(&cmd, 0,
sizeof(cmd));
249 tf->
lbal = (addr_req >> 0) & 0xff;
250 tf->
lbam = (addr_req >>= 8) & 0xff;
251 tf->
lbah = (addr_req >>= 8) & 0xff;
253 cmd.
hob.lbal = (addr_req >>= 8) & 0xff;
254 cmd.
hob.lbam = (addr_req >>= 8) & 0xff;
255 cmd.
hob.lbah = (addr_req >>= 8) & 0xff;
258 tf->
device = (addr_req >>= 8) & 0x0f;
280 static unsigned long long sectors_to_MB(
unsigned long long n)
292 {
"ST340823A",
NULL },
293 {
"ST320413A",
NULL },
294 {
"ST310211A",
NULL },
298 static u64 ide_disk_hpa_get_native_capacity(
ide_drive_t *drive,
int lba48)
303 set_max = idedisk_read_native_max_address(drive, lba48);
310 if (set_max == capacity + 1)
319 set_max = idedisk_set_max_address(drive, set_max, lba48);
329 int lba48 = ata_id_lba48_enabled(drive->
id);
332 set_max = ide_disk_hpa_get_native_capacity(drive, lba48);
334 if (set_max <= capacity)
340 "\tcurrent capacity is %llu sectors (%llu MB)\n"
341 "\tnative capacity is %llu sectors (%llu MB)\n",
343 capacity, sectors_to_MB(capacity),
344 set_max, sectors_to_MB(set_max));
349 set_max = ide_disk_hpa_set_capacity(drive, set_max, lba48);
355 static int ide_disk_get_capacity(
ide_drive_t *drive)
360 if (ata_id_lba48_enabled(
id)) {
383 if (ata_id_hpa_enabled(
id))
384 idedisk_check_hpa(drive);
391 "%llu sectors (%llu MB)\n",
401 " will be used for accessing sectors "
402 "> %u\n", drive->
name, 1 << 28);
410 static void ide_disk_unlock_native_capacity(
ide_drive_t *drive)
413 int lba48 = ata_id_lba48_enabled(
id);
416 ata_id_hpa_enabled(
id) == 0)
423 if (!ide_disk_hpa_get_native_capacity(drive, lba48))
440 memset(cmd, 0,
sizeof(*cmd));
448 if (ata_id_flush_ext_enabled(drive->
id) &&
457 rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
482 rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
496 if (arg < 0 || arg > 1)
513 memset(&cmd, 0,
sizeof(cmd));
540 barrier = ata_id_flush_enabled(
id) &&
543 capacity <= (1ULL << 28) ||
544 ata_id_flush_ext_enabled(
id));
547 drive->
name, barrier ?
"" :
"not ");
564 if (arg < 0 || arg > 1)
567 if (ata_id_flush_enabled(drive->
id)) {
568 err = ide_do_setfeature(drive,
583 static int do_idedisk_flushcache(
ide_drive_t *drive)
587 memset(&cmd, 0,
sizeof(cmd));
588 if (ata_id_flush_ext_enabled(drive->
id))
600 static int set_acoustic(
ide_drive_t *drive,
int arg)
602 if (arg < 0 || arg > 254)
605 ide_do_setfeature(drive,
621 static int set_addressing(
ide_drive_t *drive,
int arg)
623 if (arg < 0 || arg > 2)
627 ata_id_lba48_enabled(drive->
id) == 0))
648 static int ide_disk_check(
ide_drive_t *drive,
const char *
s)
671 if (m[0] !=
'W' || m[1] !=
'D')
675 (
void)set_addressing(drive, 1);
687 queue_max_sectors(q) / 2);
689 if (ata_id_is_ssd(
id))
690 queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q);
693 ide_disk_get_capacity(drive);
702 if (ata_id_lba48_enabled(drive->
id)) {
710 unsigned int cylsz,
cyl;
712 if (cap0 != capacity)
725 drive->
name, capacity, sectors_to_MB(capacity));
735 if ((
id[
ATA_ID_CSFO] & 1) || ata_id_wcache_enabled(
id))
738 set_wcache(drive, 1);
741 (drive->
head == 0 || drive->
head > 16)) {
751 if (ata_id_flush_enabled(drive->
id) == 0 ||
755 if (do_idedisk_flushcache(drive))
759 static int ide_disk_init_media(
ide_drive_t *drive,
struct gendisk *disk)
764 static int ide_disk_set_doorlock(
ide_drive_t *drive,
struct gendisk *disk,
773 memset(&cmd, 0,
sizeof(cmd));
787 .check = ide_disk_check,
788 .unlock_native_capacity = ide_disk_unlock_native_capacity,
789 .get_capacity = ide_disk_get_capacity,
790 .setup = ide_disk_setup,
791 .flush = ide_disk_flush,
792 .init_media = ide_disk_init_media,
793 .set_doorlock = ide_disk_set_doorlock,
794 .do_request = ide_do_rw_disk,