Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Bartlomiej Zolnierkiewicz | 59bca8c | 2008-02-01 23:09:33 +0100 | [diff] [blame] | 2 | * Copyright (C) 1994-1998 Linus Torvalds & authors (see below) |
| 3 | * Copyright (C) 1998-2002 Linux ATA Development |
| 4 | * Andre Hedrick <andre@linux-ide.org> |
| 5 | * Copyright (C) 2003 Red Hat <alan@redhat.com> |
| 6 | * Copyright (C) 2003-2005, 2007 Bartlomiej Zolnierkiewicz |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | /* |
| 10 | * Mostly written by Mark Lord <mlord@pobox.com> |
| 11 | * and Gadi Oxman <gadio@netvision.net.il> |
| 12 | * and Andre Hedrick <andre@linux-ide.org> |
| 13 | * |
| 14 | * This is the IDE/ATA disk driver, as evolved from hd.c and ide.c. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #define IDEDISK_VERSION "1.18" |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/module.h> |
| 20 | #include <linux/types.h> |
| 21 | #include <linux/string.h> |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/timer.h> |
| 24 | #include <linux/mm.h> |
| 25 | #include <linux/interrupt.h> |
| 26 | #include <linux/major.h> |
| 27 | #include <linux/errno.h> |
| 28 | #include <linux/genhd.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/delay.h> |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 31 | #include <linux/mutex.h> |
Richard Purdie | 2bfb646 | 2006-03-31 02:31:16 -0800 | [diff] [blame] | 32 | #include <linux/leds.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <linux/ide.h> |
Bartlomiej Zolnierkiewicz | 3ceca72 | 2008-10-10 22:39:27 +0200 | [diff] [blame] | 34 | #include <linux/hdreg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | #include <asm/byteorder.h> |
| 37 | #include <asm/irq.h> |
| 38 | #include <asm/uaccess.h> |
| 39 | #include <asm/io.h> |
| 40 | #include <asm/div64.h> |
| 41 | |
Tejun Heo | 870d665 | 2008-08-25 19:47:25 +0900 | [diff] [blame] | 42 | #if !defined(CONFIG_DEBUG_BLOCK_EXT_DEVT) |
Tejun Heo | 689d6fa | 2008-08-25 19:56:16 +0900 | [diff] [blame] | 43 | #define IDE_DISK_MINORS (1 << PARTN_BITS) |
Tejun Heo | 870d665 | 2008-08-25 19:47:25 +0900 | [diff] [blame] | 44 | #else |
Tejun Heo | 3e1a7ff | 2008-08-25 19:56:17 +0900 | [diff] [blame] | 45 | #define IDE_DISK_MINORS 0 |
Tejun Heo | 870d665 | 2008-08-25 19:47:25 +0900 | [diff] [blame] | 46 | #endif |
| 47 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | struct ide_disk_obj { |
| 49 | ide_drive_t *drive; |
| 50 | ide_driver_t *driver; |
| 51 | struct gendisk *disk; |
| 52 | struct kref kref; |
Bartlomiej Zolnierkiewicz | c94964a | 2007-02-17 02:40:24 +0100 | [diff] [blame] | 53 | unsigned int openers; /* protected by BKL for now */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 56 | static DEFINE_MUTEX(idedisk_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
| 58 | #define to_ide_disk(obj) container_of(obj, struct ide_disk_obj, kref) |
| 59 | |
| 60 | #define ide_disk_g(disk) \ |
| 61 | container_of((disk)->private_data, struct ide_disk_obj, driver) |
| 62 | |
Bartlomiej Zolnierkiewicz | 08da591 | 2008-07-24 22:53:15 +0200 | [diff] [blame] | 63 | static void ide_disk_release(struct kref *); |
| 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | static struct ide_disk_obj *ide_disk_get(struct gendisk *disk) |
| 66 | { |
| 67 | struct ide_disk_obj *idkp = NULL; |
| 68 | |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 69 | mutex_lock(&idedisk_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | idkp = ide_disk_g(disk); |
Bartlomiej Zolnierkiewicz | 08da591 | 2008-07-24 22:53:15 +0200 | [diff] [blame] | 71 | if (idkp) { |
Bartlomiej Zolnierkiewicz | d3e33ff | 2008-08-05 18:16:59 +0200 | [diff] [blame] | 72 | if (ide_device_get(idkp->drive)) |
Bartlomiej Zolnierkiewicz | 08da591 | 2008-07-24 22:53:15 +0200 | [diff] [blame] | 73 | idkp = NULL; |
Bartlomiej Zolnierkiewicz | d3e33ff | 2008-08-05 18:16:59 +0200 | [diff] [blame] | 74 | else |
| 75 | kref_get(&idkp->kref); |
Bartlomiej Zolnierkiewicz | 08da591 | 2008-07-24 22:53:15 +0200 | [diff] [blame] | 76 | } |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 77 | mutex_unlock(&idedisk_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | return idkp; |
| 79 | } |
| 80 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | static void ide_disk_put(struct ide_disk_obj *idkp) |
| 82 | { |
Bartlomiej Zolnierkiewicz | d3e33ff | 2008-08-05 18:16:59 +0200 | [diff] [blame] | 83 | ide_drive_t *drive = idkp->drive; |
| 84 | |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 85 | mutex_lock(&idedisk_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | kref_put(&idkp->kref, ide_disk_release); |
Bartlomiej Zolnierkiewicz | d3e33ff | 2008-08-05 18:16:59 +0200 | [diff] [blame] | 87 | ide_device_put(drive); |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 88 | mutex_unlock(&idedisk_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Bartlomiej Zolnierkiewicz | ba76ae3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 91 | static const u8 ide_rw_cmds[] = { |
Bartlomiej Zolnierkiewicz | aaaade3 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 92 | ATA_CMD_READ_MULTI, |
| 93 | ATA_CMD_WRITE_MULTI, |
| 94 | ATA_CMD_READ_MULTI_EXT, |
| 95 | ATA_CMD_WRITE_MULTI_EXT, |
| 96 | ATA_CMD_PIO_READ, |
| 97 | ATA_CMD_PIO_WRITE, |
| 98 | ATA_CMD_PIO_READ_EXT, |
| 99 | ATA_CMD_PIO_WRITE_EXT, |
| 100 | ATA_CMD_READ, |
| 101 | ATA_CMD_WRITE, |
| 102 | ATA_CMD_READ_EXT, |
| 103 | ATA_CMD_WRITE_EXT, |
Bartlomiej Zolnierkiewicz | ba76ae3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 104 | }; |
| 105 | |
| 106 | static const u8 ide_data_phases[] = { |
| 107 | TASKFILE_MULTI_IN, |
| 108 | TASKFILE_MULTI_OUT, |
| 109 | TASKFILE_IN, |
| 110 | TASKFILE_OUT, |
| 111 | TASKFILE_IN_DMA, |
| 112 | TASKFILE_OUT_DMA, |
| 113 | }; |
| 114 | |
| 115 | static void ide_tf_set_cmd(ide_drive_t *drive, ide_task_t *task, u8 dma) |
| 116 | { |
| 117 | u8 index, lba48, write; |
| 118 | |
| 119 | lba48 = (task->tf_flags & IDE_TFLAG_LBA48) ? 2 : 0; |
| 120 | write = (task->tf_flags & IDE_TFLAG_WRITE) ? 1 : 0; |
| 121 | |
| 122 | if (dma) |
Bartlomiej Zolnierkiewicz | ba4b2e6 | 2008-07-23 19:55:55 +0200 | [diff] [blame] | 123 | index = 8; |
Bartlomiej Zolnierkiewicz | ba76ae3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 124 | else |
| 125 | index = drive->mult_count ? 0 : 4; |
| 126 | |
| 127 | task->tf.command = ide_rw_cmds[index + lba48 + write]; |
| 128 | |
| 129 | if (dma) |
| 130 | index = 8; /* fixup index */ |
| 131 | |
| 132 | task->data_phase = ide_data_phases[index / 2 + write]; |
| 133 | } |
| 134 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | /* |
| 136 | * __ide_do_rw_disk() issues READ and WRITE commands to a disk, |
| 137 | * using LBA if supported, or CHS otherwise, to address sectors. |
| 138 | */ |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 139 | static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq, |
| 140 | sector_t block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | { |
| 142 | ide_hwif_t *hwif = HWIF(drive); |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 143 | u16 nsectors = (u16)rq->nr_sectors; |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 144 | u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48); |
| 145 | u8 dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA); |
Bartlomiej Zolnierkiewicz | 9e42237 | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 146 | ide_task_t task; |
| 147 | struct ide_taskfile *tf = &task.tf; |
Bartlomiej Zolnierkiewicz | f6e29e3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 148 | ide_startstop_t rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
Bartlomiej Zolnierkiewicz | 238e4f1 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 150 | if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) && lba48 && dma) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | if (block + rq->nr_sectors > 1ULL << 28) |
| 152 | dma = 0; |
| 153 | else |
| 154 | lba48 = 0; |
| 155 | } |
| 156 | |
| 157 | if (!dma) { |
| 158 | ide_init_sg_cmd(drive, rq); |
| 159 | ide_map_sg(drive, rq); |
| 160 | } |
| 161 | |
Bartlomiej Zolnierkiewicz | 9e42237 | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 162 | memset(&task, 0, sizeof(task)); |
Bartlomiej Zolnierkiewicz | 9a410e7 | 2008-07-15 21:21:48 +0200 | [diff] [blame] | 163 | task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; |
Bartlomiej Zolnierkiewicz | 2bd06b2 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 164 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | if (drive->select.b.lba) { |
| 166 | if (lba48) { |
Michael Richardson | c2f8311 | 2006-02-07 12:58:33 -0800 | [diff] [blame] | 167 | pr_debug("%s: LBA=0x%012llx\n", drive->name, |
| 168 | (unsigned long long)block); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 170 | tf->hob_nsect = (nsectors >> 8) & 0xff; |
Bartlomiej Zolnierkiewicz | 2bd06b2 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 171 | tf->hob_lbal = (u8)(block >> 24); |
| 172 | if (sizeof(block) != 4) { |
| 173 | tf->hob_lbam = (u8)((u64)block >> 32); |
| 174 | tf->hob_lbah = (u8)((u64)block >> 40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } |
Bartlomiej Zolnierkiewicz | 2bd06b2 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 176 | |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 177 | tf->nsect = nsectors & 0xff; |
Bartlomiej Zolnierkiewicz | 2bd06b2 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 178 | tf->lbal = (u8) block; |
| 179 | tf->lbam = (u8)(block >> 8); |
| 180 | tf->lbah = (u8)(block >> 16); |
Bartlomiej Zolnierkiewicz | 6dd9b83 | 2008-01-26 20:13:03 +0100 | [diff] [blame] | 181 | |
Bartlomiej Zolnierkiewicz | 657cc1a | 2008-01-26 20:13:10 +0100 | [diff] [blame] | 182 | task.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_HOB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | } else { |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 184 | tf->nsect = nsectors & 0xff; |
Bartlomiej Zolnierkiewicz | 2bd06b2 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 185 | tf->lbal = block; |
| 186 | tf->lbam = block >>= 8; |
| 187 | tf->lbah = block >>= 8; |
| 188 | tf->device = (block >> 8) & 0xf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | } |
| 190 | } else { |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 191 | unsigned int sect, head, cyl, track; |
| 192 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | track = (int)block / drive->sect; |
| 194 | sect = (int)block % drive->sect + 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | head = track % drive->head; |
| 196 | cyl = track / drive->head; |
| 197 | |
| 198 | pr_debug("%s: CHS=%u/%u/%u\n", drive->name, cyl, head, sect); |
| 199 | |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 200 | tf->nsect = nsectors & 0xff; |
Bartlomiej Zolnierkiewicz | 2bd06b2 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 201 | tf->lbal = sect; |
| 202 | tf->lbam = cyl; |
| 203 | tf->lbah = cyl >> 8; |
| 204 | tf->device = head; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Bartlomiej Zolnierkiewicz | ba76ae3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 207 | if (rq_data_dir(rq)) |
| 208 | task.tf_flags |= IDE_TFLAG_WRITE; |
| 209 | |
| 210 | ide_tf_set_cmd(drive, &task, dma); |
Bartlomiej Zolnierkiewicz | f6e29e3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 211 | if (!dma) |
| 212 | hwif->data_phase = task.data_phase; |
| 213 | task.rq = rq; |
Bartlomiej Zolnierkiewicz | ba76ae3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 214 | |
Bartlomiej Zolnierkiewicz | f6e29e3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 215 | rc = do_rw_taskfile(drive, &task); |
Bartlomiej Zolnierkiewicz | 2bd06b2 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 216 | |
Bartlomiej Zolnierkiewicz | f6e29e3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 217 | if (rc == ide_stopped && dma) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | /* fallback to PIO */ |
Bartlomiej Zolnierkiewicz | f6e29e3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 219 | task.tf_flags |= IDE_TFLAG_DMA_PIO_FALLBACK; |
Bartlomiej Zolnierkiewicz | ba76ae3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 220 | ide_tf_set_cmd(drive, &task, 0); |
Bartlomiej Zolnierkiewicz | f6e29e3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 221 | hwif->data_phase = task.data_phase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | ide_init_sg_cmd(drive, rq); |
Bartlomiej Zolnierkiewicz | f6e29e3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 223 | rc = do_rw_taskfile(drive, &task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Bartlomiej Zolnierkiewicz | f6e29e3 | 2008-01-25 22:17:16 +0100 | [diff] [blame] | 226 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | /* |
| 230 | * 268435455 == 137439 MB or 28bit limit |
| 231 | * 320173056 == 163929 MB or 48bit addressing |
| 232 | * 1073741822 == 549756 MB or 48bit addressing fake drive |
| 233 | */ |
| 234 | |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 235 | static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq, |
| 236 | sector_t block) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | { |
| 238 | ide_hwif_t *hwif = HWIF(drive); |
| 239 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 240 | BUG_ON(drive->dev_flags & IDE_DFLAG_BLOCKED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
| 242 | if (!blk_fs_request(rq)) { |
| 243 | blk_dump_rq_flags(rq, "ide_do_rw_disk - bad command"); |
| 244 | ide_end_request(drive, 0, 0); |
| 245 | return ide_stopped; |
| 246 | } |
| 247 | |
Richard Purdie | 2bfb646 | 2006-03-31 02:31:16 -0800 | [diff] [blame] | 248 | ledtrig_ide_activity(); |
| 249 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | pr_debug("%s: %sing: block=%llu, sectors=%lu, buffer=0x%08lx\n", |
| 251 | drive->name, rq_data_dir(rq) == READ ? "read" : "writ", |
Michael Richardson | c2f8311 | 2006-02-07 12:58:33 -0800 | [diff] [blame] | 252 | (unsigned long long)block, rq->nr_sectors, |
| 253 | (unsigned long)rq->buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | |
| 255 | if (hwif->rw_disk) |
| 256 | hwif->rw_disk(drive, rq); |
| 257 | |
| 258 | return __ide_do_rw_disk(drive, rq, block); |
| 259 | } |
| 260 | |
| 261 | /* |
| 262 | * Queries for true maximum capacity of the drive. |
| 263 | * Returns maximum LBA address (> 0) of the drive, 0 if failed. |
| 264 | */ |
Bartlomiej Zolnierkiewicz | 7a3b751 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 265 | static u64 idedisk_read_native_max_address(ide_drive_t *drive, int lba48) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | { |
| 267 | ide_task_t args; |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 268 | struct ide_taskfile *tf = &args.tf; |
Bartlomiej Zolnierkiewicz | 7a3b751 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 269 | u64 addr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
| 271 | /* Create IDE/ATA command request structure */ |
| 272 | memset(&args, 0, sizeof(ide_task_t)); |
Bartlomiej Zolnierkiewicz | 7a3b751 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 273 | if (lba48) |
Bartlomiej Zolnierkiewicz | aaaade3 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 274 | tf->command = ATA_CMD_READ_NATIVE_MAX_EXT; |
Bartlomiej Zolnierkiewicz | 7a3b751 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 275 | else |
Bartlomiej Zolnierkiewicz | aaaade3 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 276 | tf->command = ATA_CMD_READ_NATIVE_MAX; |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 277 | tf->device = ATA_LBA; |
Bartlomiej Zolnierkiewicz | 657cc1a | 2008-01-26 20:13:10 +0100 | [diff] [blame] | 278 | args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; |
Bartlomiej Zolnierkiewicz | a3bbb9d | 2008-01-25 22:17:10 +0100 | [diff] [blame] | 279 | if (lba48) |
Bartlomiej Zolnierkiewicz | 657cc1a | 2008-01-26 20:13:10 +0100 | [diff] [blame] | 280 | args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_HOB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | /* submit command request */ |
Bartlomiej Zolnierkiewicz | 9a3c49b | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 282 | ide_no_data_taskfile(drive, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | |
| 284 | /* if OK, compute maximum address value */ |
Bartlomiej Zolnierkiewicz | a501633 | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 285 | if ((tf->status & 0x01) == 0) |
| 286 | addr = ide_get_lba_addr(tf, lba48) + 1; |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | return addr; |
| 289 | } |
| 290 | |
| 291 | /* |
| 292 | * Sets maximum virtual LBA address of the drive. |
| 293 | * Returns new maximum virtual LBA address (> 0) or 0 on failure. |
| 294 | */ |
Bartlomiej Zolnierkiewicz | 7a3b751 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 295 | static u64 idedisk_set_max_address(ide_drive_t *drive, u64 addr_req, int lba48) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | { |
| 297 | ide_task_t args; |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 298 | struct ide_taskfile *tf = &args.tf; |
Bartlomiej Zolnierkiewicz | 7a3b751 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 299 | u64 addr_set = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | |
| 301 | addr_req--; |
| 302 | /* Create IDE/ATA command request structure */ |
| 303 | memset(&args, 0, sizeof(ide_task_t)); |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 304 | tf->lbal = (addr_req >> 0) & 0xff; |
| 305 | tf->lbam = (addr_req >>= 8) & 0xff; |
| 306 | tf->lbah = (addr_req >>= 8) & 0xff; |
Bartlomiej Zolnierkiewicz | 7a3b751 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 307 | if (lba48) { |
| 308 | tf->hob_lbal = (addr_req >>= 8) & 0xff; |
| 309 | tf->hob_lbam = (addr_req >>= 8) & 0xff; |
| 310 | tf->hob_lbah = (addr_req >>= 8) & 0xff; |
Bartlomiej Zolnierkiewicz | aaaade3 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 311 | tf->command = ATA_CMD_SET_MAX_EXT; |
Bartlomiej Zolnierkiewicz | 7a3b751 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 312 | } else { |
| 313 | tf->device = (addr_req >>= 8) & 0x0f; |
Bartlomiej Zolnierkiewicz | aaaade3 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 314 | tf->command = ATA_CMD_SET_MAX; |
Bartlomiej Zolnierkiewicz | 7a3b751 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 315 | } |
| 316 | tf->device |= ATA_LBA; |
Bartlomiej Zolnierkiewicz | 657cc1a | 2008-01-26 20:13:10 +0100 | [diff] [blame] | 317 | args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; |
Bartlomiej Zolnierkiewicz | a3bbb9d | 2008-01-25 22:17:10 +0100 | [diff] [blame] | 318 | if (lba48) |
Bartlomiej Zolnierkiewicz | 657cc1a | 2008-01-26 20:13:10 +0100 | [diff] [blame] | 319 | args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_HOB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | /* submit command request */ |
Bartlomiej Zolnierkiewicz | 9a3c49b | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 321 | ide_no_data_taskfile(drive, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | /* if OK, compute maximum address value */ |
Bartlomiej Zolnierkiewicz | a501633 | 2008-01-25 22:17:17 +0100 | [diff] [blame] | 323 | if ((tf->status & 0x01) == 0) |
| 324 | addr_set = ide_get_lba_addr(tf, lba48) + 1; |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | return addr_set; |
| 327 | } |
| 328 | |
| 329 | static unsigned long long sectors_to_MB(unsigned long long n) |
| 330 | { |
| 331 | n <<= 9; /* make it bytes */ |
| 332 | do_div(n, 1000000); /* make it MB */ |
| 333 | return n; |
| 334 | } |
| 335 | |
| 336 | /* |
Bartlomiej Zolnierkiewicz | b0244a0 | 2007-08-20 22:42:57 +0200 | [diff] [blame] | 337 | * Some disks report total number of sectors instead of |
| 338 | * maximum sector address. We list them here. |
| 339 | */ |
| 340 | static const struct drive_list_entry hpa_list[] = { |
| 341 | { "ST340823A", NULL }, |
Jorge Juan Chico | 7062cdc | 2007-09-17 12:35:30 +0200 | [diff] [blame] | 342 | { "ST320413A", NULL }, |
Mikko Rapeli | b152fcd | 2008-02-19 01:41:25 +0100 | [diff] [blame] | 343 | { "ST310211A", NULL }, |
Bartlomiej Zolnierkiewicz | b0244a0 | 2007-08-20 22:42:57 +0200 | [diff] [blame] | 344 | { NULL, NULL } |
| 345 | }; |
| 346 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame] | 347 | static void idedisk_check_hpa(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | { |
| 349 | unsigned long long capacity, set_max; |
Bartlomiej Zolnierkiewicz | 942dcd8 | 2008-10-10 22:39:30 +0200 | [diff] [blame] | 350 | int lba48 = ata_id_lba48_enabled(drive->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | |
| 352 | capacity = drive->capacity64; |
Bartlomiej Zolnierkiewicz | 7a3b751 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 353 | |
| 354 | set_max = idedisk_read_native_max_address(drive, lba48); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | |
Bartlomiej Zolnierkiewicz | b0244a0 | 2007-08-20 22:42:57 +0200 | [diff] [blame] | 356 | if (ide_in_drive_list(drive->id, hpa_list)) { |
| 357 | /* |
| 358 | * Since we are inclusive wrt to firmware revisions do this |
| 359 | * extra check and apply the workaround only when needed. |
| 360 | */ |
| 361 | if (set_max == capacity + 1) |
| 362 | set_max--; |
| 363 | } |
| 364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | if (set_max <= capacity) |
| 366 | return; |
| 367 | |
| 368 | printk(KERN_INFO "%s: Host Protected Area detected.\n" |
| 369 | "\tcurrent capacity is %llu sectors (%llu MB)\n" |
| 370 | "\tnative capacity is %llu sectors (%llu MB)\n", |
| 371 | drive->name, |
| 372 | capacity, sectors_to_MB(capacity), |
| 373 | set_max, sectors_to_MB(set_max)); |
| 374 | |
Bartlomiej Zolnierkiewicz | 7a3b751 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 375 | set_max = idedisk_set_max_address(drive, set_max, lba48); |
| 376 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | if (set_max) { |
| 378 | drive->capacity64 = set_max; |
| 379 | printk(KERN_INFO "%s: Host Protected Area disabled.\n", |
| 380 | drive->name); |
| 381 | } |
| 382 | } |
| 383 | |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 384 | static void init_idedisk_capacity(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | { |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 386 | u16 *id = drive->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | /* |
| 388 | * If this drive supports the Host Protected Area feature set, |
| 389 | * then we may need to change our opinion about the drive's capacity. |
| 390 | */ |
Bartlomiej Zolnierkiewicz | f41891c | 2008-10-10 22:39:20 +0200 | [diff] [blame] | 391 | int hpa = ata_id_hpa_enabled(id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | |
Bartlomiej Zolnierkiewicz | 942dcd8 | 2008-10-10 22:39:30 +0200 | [diff] [blame] | 393 | if (ata_id_lba48_enabled(id)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | /* drive speaks 48-bit LBA */ |
| 395 | drive->select.b.lba = 1; |
Bartlomiej Zolnierkiewicz | 48fb268 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 396 | drive->capacity64 = ata_id_u64(id, ATA_ID_LBA_CAPACITY_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | if (hpa) |
| 398 | idedisk_check_hpa(drive); |
Bartlomiej Zolnierkiewicz | a02227c | 2008-10-10 22:39:31 +0200 | [diff] [blame] | 399 | } else if (ata_id_has_lba(id) && ata_id_is_lba_capacity_ok(id)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | /* drive speaks 28-bit LBA */ |
| 401 | drive->select.b.lba = 1; |
Bartlomiej Zolnierkiewicz | 48fb268 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 402 | drive->capacity64 = ata_id_u32(id, ATA_ID_LBA_CAPACITY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | if (hpa) |
| 404 | idedisk_check_hpa(drive); |
| 405 | } else { |
| 406 | /* drive speaks boring old 28-bit CHS */ |
| 407 | drive->capacity64 = drive->cyl * drive->head * drive->sect; |
| 408 | } |
| 409 | } |
| 410 | |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 411 | static sector_t idedisk_capacity(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | { |
Bartlomiej Zolnierkiewicz | 3c619ff | 2008-10-10 22:39:22 +0200 | [diff] [blame] | 413 | return drive->capacity64; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Bartlomiej Zolnierkiewicz | ecfd80e | 2007-05-10 00:01:09 +0200 | [diff] [blame] | 416 | #ifdef CONFIG_IDE_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | static int smart_enable(ide_drive_t *drive) |
| 418 | { |
| 419 | ide_task_t args; |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 420 | struct ide_taskfile *tf = &args.tf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
| 422 | memset(&args, 0, sizeof(ide_task_t)); |
Bartlomiej Zolnierkiewicz | aaaade3 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 423 | tf->feature = ATA_SMART_ENABLE; |
| 424 | tf->lbam = ATA_SMART_LBAM_PASS; |
| 425 | tf->lbah = ATA_SMART_LBAH_PASS; |
| 426 | tf->command = ATA_CMD_SMART; |
Bartlomiej Zolnierkiewicz | 657cc1a | 2008-01-26 20:13:10 +0100 | [diff] [blame] | 427 | args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; |
Bartlomiej Zolnierkiewicz | 9a3c49b | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 428 | return ide_no_data_taskfile(drive, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Bartlomiej Zolnierkiewicz | 43e7c0c | 2007-10-20 00:32:37 +0200 | [diff] [blame] | 431 | static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | { |
| 433 | ide_task_t args; |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 434 | struct ide_taskfile *tf = &args.tf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
| 436 | memset(&args, 0, sizeof(ide_task_t)); |
Bartlomiej Zolnierkiewicz | 650d841 | 2008-01-25 22:17:06 +0100 | [diff] [blame] | 437 | tf->feature = sub_cmd; |
| 438 | tf->nsect = 0x01; |
Bartlomiej Zolnierkiewicz | aaaade3 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 439 | tf->lbam = ATA_SMART_LBAM_PASS; |
| 440 | tf->lbah = ATA_SMART_LBAH_PASS; |
| 441 | tf->command = ATA_CMD_SMART; |
Bartlomiej Zolnierkiewicz | 657cc1a | 2008-01-26 20:13:10 +0100 | [diff] [blame] | 442 | args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; |
Bartlomiej Zolnierkiewicz | ac026ff | 2008-01-25 22:17:14 +0100 | [diff] [blame] | 443 | args.data_phase = TASKFILE_IN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | (void) smart_enable(drive); |
Bartlomiej Zolnierkiewicz | ac026ff | 2008-01-25 22:17:14 +0100 | [diff] [blame] | 445 | return ide_raw_taskfile(drive, &args, buf, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | static int proc_idedisk_read_cache |
| 449 | (char *page, char **start, off_t off, int count, int *eof, void *data) |
| 450 | { |
| 451 | ide_drive_t *drive = (ide_drive_t *) data; |
| 452 | char *out = page; |
| 453 | int len; |
| 454 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 455 | if (drive->dev_flags & IDE_DFLAG_ID_READ) |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 456 | len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | else |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 458 | len = sprintf(out, "(none)\n"); |
| 459 | |
| 460 | PROC_IDE_READ_RETURN(page, start, off, count, eof, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | static int proc_idedisk_read_capacity |
| 464 | (char *page, char **start, off_t off, int count, int *eof, void *data) |
| 465 | { |
| 466 | ide_drive_t*drive = (ide_drive_t *)data; |
| 467 | int len; |
| 468 | |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 469 | len = sprintf(page, "%llu\n", (long long)idedisk_capacity(drive)); |
| 470 | |
| 471 | PROC_IDE_READ_RETURN(page, start, off, count, eof, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Bartlomiej Zolnierkiewicz | 799ee57 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 474 | static int proc_idedisk_read_smart(char *page, char **start, off_t off, |
| 475 | int count, int *eof, void *data, u8 sub_cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | { |
| 477 | ide_drive_t *drive = (ide_drive_t *)data; |
| 478 | int len = 0, i = 0; |
| 479 | |
Bartlomiej Zolnierkiewicz | 799ee57 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 480 | if (get_smart_data(drive, page, sub_cmd) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | unsigned short *val = (unsigned short *) page; |
Bartlomiej Zolnierkiewicz | 151a670 | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 482 | char *out = (char *)val + SECTOR_SIZE; |
| 483 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | page = out; |
| 485 | do { |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 486 | out += sprintf(out, "%04x%c", le16_to_cpu(*val), |
| 487 | (++i & 7) ? ' ' : '\n'); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | val += 1; |
Bartlomiej Zolnierkiewicz | 151a670 | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 489 | } while (i < SECTOR_SIZE / 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | len = out - page; |
| 491 | } |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 492 | |
| 493 | PROC_IDE_READ_RETURN(page, start, off, count, eof, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Bartlomiej Zolnierkiewicz | 799ee57 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 496 | static int proc_idedisk_read_sv |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | (char *page, char **start, off_t off, int count, int *eof, void *data) |
| 498 | { |
Bartlomiej Zolnierkiewicz | 799ee57 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 499 | return proc_idedisk_read_smart(page, start, off, count, eof, data, |
Bartlomiej Zolnierkiewicz | aaaade3 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 500 | ATA_SMART_READ_VALUES); |
Bartlomiej Zolnierkiewicz | 799ee57 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 501 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
Bartlomiej Zolnierkiewicz | 799ee57 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 503 | static int proc_idedisk_read_st |
| 504 | (char *page, char **start, off_t off, int count, int *eof, void *data) |
| 505 | { |
| 506 | return proc_idedisk_read_smart(page, start, off, count, eof, data, |
Bartlomiej Zolnierkiewicz | aaaade3 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 507 | ATA_SMART_READ_THRESHOLDS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | static ide_proc_entry_t idedisk_proc[] = { |
Bartlomiej Zolnierkiewicz | 799ee57 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 511 | { "cache", S_IFREG|S_IRUGO, proc_idedisk_read_cache, NULL }, |
| 512 | { "capacity", S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL }, |
| 513 | { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL }, |
| 514 | { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_sv, NULL }, |
| 515 | { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_st, NULL }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | { NULL, 0, NULL, NULL } |
| 517 | }; |
Bartlomiej Zolnierkiewicz | ecfd80e | 2007-05-10 00:01:09 +0200 | [diff] [blame] | 518 | #endif /* CONFIG_IDE_PROC_FS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | |
Jens Axboe | 165125e | 2007-07-24 09:28:11 +0200 | [diff] [blame] | 520 | static void idedisk_prepare_flush(struct request_queue *q, struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | { |
| 522 | ide_drive_t *drive = q->queuedata; |
Bartlomiej Zolnierkiewicz | 395d8ef | 2008-02-11 00:32:14 +0100 | [diff] [blame] | 523 | ide_task_t *task = kmalloc(sizeof(*task), GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
Bartlomiej Zolnierkiewicz | 395d8ef | 2008-02-11 00:32:14 +0100 | [diff] [blame] | 525 | /* FIXME: map struct ide_taskfile on rq->cmd[] */ |
| 526 | BUG_ON(task == NULL); |
| 527 | |
| 528 | memset(task, 0, sizeof(*task)); |
Bartlomiej Zolnierkiewicz | ff2779b | 2008-10-10 22:39:31 +0200 | [diff] [blame] | 529 | if (ata_id_flush_ext_enabled(drive->id) && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | (drive->capacity64 >= (1UL << 28))) |
Bartlomiej Zolnierkiewicz | aaaade3 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 531 | task->tf.command = ATA_CMD_FLUSH_EXT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | else |
Bartlomiej Zolnierkiewicz | aaaade3 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 533 | task->tf.command = ATA_CMD_FLUSH; |
Bartlomiej Zolnierkiewicz | 395d8ef | 2008-02-11 00:32:14 +0100 | [diff] [blame] | 534 | task->tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE | |
| 535 | IDE_TFLAG_DYN; |
| 536 | task->data_phase = TASKFILE_NO_DATA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | |
Bartlomiej Zolnierkiewicz | 813a0eb | 2008-01-25 22:17:10 +0100 | [diff] [blame] | 538 | rq->cmd_type = REQ_TYPE_ATA_TASKFILE; |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 539 | rq->cmd_flags |= REQ_SOFTBARRIER; |
Bartlomiej Zolnierkiewicz | 395d8ef | 2008-02-11 00:32:14 +0100 | [diff] [blame] | 540 | rq->special = task; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | } |
| 542 | |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 543 | ide_devset_get(multcount, mult_count); |
| 544 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | /* |
| 546 | * This is tightly woven into the driver->do_special can not touch. |
| 547 | * DON'T do it again until a total personality rewrite is committed. |
| 548 | */ |
| 549 | static int set_multcount(ide_drive_t *drive, int arg) |
| 550 | { |
FUJITA Tomonori | dd47087 | 2008-07-15 21:21:43 +0200 | [diff] [blame] | 551 | struct request *rq; |
| 552 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
Bartlomiej Zolnierkiewicz | 48fb268 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 554 | if (arg < 0 || arg > (drive->id[ATA_ID_MAX_MULTSECT] & 0xff)) |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 555 | return -EINVAL; |
| 556 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | if (drive->special.b.set_multmode) |
| 558 | return -EBUSY; |
Bartlomiej Zolnierkiewicz | 852738f | 2008-01-26 20:13:12 +0100 | [diff] [blame] | 559 | |
FUJITA Tomonori | dd47087 | 2008-07-15 21:21:43 +0200 | [diff] [blame] | 560 | rq = blk_get_request(drive->queue, READ, __GFP_WAIT); |
| 561 | rq->cmd_type = REQ_TYPE_ATA_TASKFILE; |
Bartlomiej Zolnierkiewicz | 852738f | 2008-01-26 20:13:12 +0100 | [diff] [blame] | 562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | drive->mult_req = arg; |
| 564 | drive->special.b.set_multmode = 1; |
FUJITA Tomonori | dd47087 | 2008-07-15 21:21:43 +0200 | [diff] [blame] | 565 | error = blk_execute_rq(drive->queue, NULL, rq, 0); |
| 566 | blk_put_request(rq); |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | return (drive->mult_count == arg) ? 0 : -EIO; |
| 569 | } |
| 570 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 571 | ide_devset_get_flag(nowerr, IDE_DFLAG_NOWERR); |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 572 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | static int set_nowerr(ide_drive_t *drive, int arg) |
| 574 | { |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 575 | if (arg < 0 || arg > 1) |
| 576 | return -EINVAL; |
| 577 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 578 | if (arg) |
| 579 | drive->dev_flags |= IDE_DFLAG_NOWERR; |
| 580 | else |
| 581 | drive->dev_flags &= ~IDE_DFLAG_NOWERR; |
| 582 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | drive->bad_wstat = arg ? BAD_R_STAT : BAD_W_STAT; |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | return 0; |
| 586 | } |
| 587 | |
Bartlomiej Zolnierkiewicz | be3c096 | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 588 | static int ide_do_setfeature(ide_drive_t *drive, u8 feature, u8 nsect) |
| 589 | { |
| 590 | ide_task_t task; |
| 591 | |
| 592 | memset(&task, 0, sizeof(task)); |
| 593 | task.tf.feature = feature; |
| 594 | task.tf.nsect = nsect; |
| 595 | task.tf.command = ATA_CMD_SET_FEATURES; |
| 596 | task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; |
| 597 | |
| 598 | return ide_no_data_taskfile(drive, &task); |
| 599 | } |
| 600 | |
Tejun Heo | 3e087b5 | 2006-01-06 09:57:31 +0100 | [diff] [blame] | 601 | static void update_ordered(ide_drive_t *drive) |
| 602 | { |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 603 | u16 *id = drive->id; |
Tejun Heo | 3e087b5 | 2006-01-06 09:57:31 +0100 | [diff] [blame] | 604 | unsigned ordered = QUEUE_ORDERED_NONE; |
| 605 | prepare_flush_fn *prep_fn = NULL; |
Tejun Heo | 3e087b5 | 2006-01-06 09:57:31 +0100 | [diff] [blame] | 606 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 607 | if (drive->dev_flags & IDE_DFLAG_WCACHE) { |
Tejun Heo | 3e087b5 | 2006-01-06 09:57:31 +0100 | [diff] [blame] | 608 | unsigned long long capacity; |
| 609 | int barrier; |
| 610 | /* |
| 611 | * We must avoid issuing commands a drive does not |
| 612 | * understand or we may crash it. We check flush cache |
| 613 | * is supported. We also check we have the LBA48 flush |
| 614 | * cache if the drive capacity is too large. By this |
| 615 | * time we have trimmed the drive capacity if LBA48 is |
| 616 | * not available so we don't need to recheck that. |
| 617 | */ |
| 618 | capacity = idedisk_capacity(drive); |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 619 | barrier = ata_id_flush_enabled(id) && |
| 620 | (drive->dev_flags & IDE_DFLAG_NOFLUSH) == 0 && |
| 621 | ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 || |
| 622 | capacity <= (1ULL << 28) || |
Bartlomiej Zolnierkiewicz | ff2779b | 2008-10-10 22:39:31 +0200 | [diff] [blame] | 623 | ata_id_flush_ext_enabled(id)); |
Tejun Heo | 3e087b5 | 2006-01-06 09:57:31 +0100 | [diff] [blame] | 624 | |
| 625 | printk(KERN_INFO "%s: cache flushes %ssupported\n", |
Jean Delvare | f7ad836 | 2006-02-03 03:04:57 -0800 | [diff] [blame] | 626 | drive->name, barrier ? "" : "not "); |
Tejun Heo | 3e087b5 | 2006-01-06 09:57:31 +0100 | [diff] [blame] | 627 | |
| 628 | if (barrier) { |
| 629 | ordered = QUEUE_ORDERED_DRAIN_FLUSH; |
| 630 | prep_fn = idedisk_prepare_flush; |
Tejun Heo | 3e087b5 | 2006-01-06 09:57:31 +0100 | [diff] [blame] | 631 | } |
| 632 | } else |
| 633 | ordered = QUEUE_ORDERED_DRAIN; |
| 634 | |
| 635 | blk_queue_ordered(drive->queue, ordered, prep_fn); |
Tejun Heo | 3e087b5 | 2006-01-06 09:57:31 +0100 | [diff] [blame] | 636 | } |
| 637 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 638 | ide_devset_get_flag(wcache, IDE_DFLAG_WCACHE); |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 639 | |
| 640 | static int set_wcache(ide_drive_t *drive, int arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | { |
Tejun Heo | 3e087b5 | 2006-01-06 09:57:31 +0100 | [diff] [blame] | 642 | int err = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 644 | if (arg < 0 || arg > 1) |
| 645 | return -EINVAL; |
| 646 | |
Bartlomiej Zolnierkiewicz | 4b58f17 | 2008-10-10 22:39:30 +0200 | [diff] [blame] | 647 | if (ata_id_flush_enabled(drive->id)) { |
Bartlomiej Zolnierkiewicz | be3c096 | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 648 | err = ide_do_setfeature(drive, |
| 649 | arg ? SETFEATURES_WC_ON : SETFEATURES_WC_OFF, 0); |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 650 | if (err == 0) { |
| 651 | if (arg) |
| 652 | drive->dev_flags |= IDE_DFLAG_WCACHE; |
| 653 | else |
| 654 | drive->dev_flags &= ~IDE_DFLAG_WCACHE; |
| 655 | } |
Tejun Heo | 3e087b5 | 2006-01-06 09:57:31 +0100 | [diff] [blame] | 656 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | |
Tejun Heo | 3e087b5 | 2006-01-06 09:57:31 +0100 | [diff] [blame] | 658 | update_ordered(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | |
Tejun Heo | 3e087b5 | 2006-01-06 09:57:31 +0100 | [diff] [blame] | 660 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | } |
| 662 | |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 663 | static int do_idedisk_flushcache(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | { |
| 665 | ide_task_t args; |
| 666 | |
| 667 | memset(&args, 0, sizeof(ide_task_t)); |
Bartlomiej Zolnierkiewicz | ff2779b | 2008-10-10 22:39:31 +0200 | [diff] [blame] | 668 | if (ata_id_flush_ext_enabled(drive->id)) |
Bartlomiej Zolnierkiewicz | aaaade3 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 669 | args.tf.command = ATA_CMD_FLUSH_EXT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | else |
Bartlomiej Zolnierkiewicz | aaaade3 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 671 | args.tf.command = ATA_CMD_FLUSH; |
Bartlomiej Zolnierkiewicz | 657cc1a | 2008-01-26 20:13:10 +0100 | [diff] [blame] | 672 | args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; |
Bartlomiej Zolnierkiewicz | 9a3c49b | 2008-01-25 22:17:07 +0100 | [diff] [blame] | 673 | return ide_no_data_taskfile(drive, &args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | } |
| 675 | |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 676 | ide_devset_get(acoustic, acoustic); |
| 677 | |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 678 | static int set_acoustic(ide_drive_t *drive, int arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | { |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 680 | if (arg < 0 || arg > 254) |
| 681 | return -EINVAL; |
| 682 | |
Bartlomiej Zolnierkiewicz | be3c096 | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 683 | ide_do_setfeature(drive, |
| 684 | arg ? SETFEATURES_AAM_ON : SETFEATURES_AAM_OFF, arg); |
| 685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | drive->acoustic = arg; |
Bartlomiej Zolnierkiewicz | be3c096 | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 687 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | return 0; |
| 689 | } |
| 690 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 691 | ide_devset_get_flag(addressing, IDE_DFLAG_LBA48); |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 692 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | /* |
| 694 | * drive->addressing: |
| 695 | * 0: 28-bit |
| 696 | * 1: 48-bit |
| 697 | * 2: 48-bit capable doing 28-bit |
| 698 | */ |
Bartlomiej Zolnierkiewicz | aa768773 | 2008-10-10 22:39:33 +0200 | [diff] [blame] | 699 | static int set_addressing(ide_drive_t *drive, int arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | { |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 701 | if (arg < 0 || arg > 2) |
| 702 | return -EINVAL; |
| 703 | |
Bartlomiej Zolnierkiewicz | 35c1375 | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 704 | if (arg && ((drive->hwif->host_flags & IDE_HFLAG_NO_LBA48) || |
| 705 | ata_id_lba48_enabled(drive->id) == 0)) |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 706 | return -EIO; |
Bartlomiej Zolnierkiewicz | 942dcd8 | 2008-10-10 22:39:30 +0200 | [diff] [blame] | 707 | |
Bartlomiej Zolnierkiewicz | 35c1375 | 2008-10-13 21:39:36 +0200 | [diff] [blame] | 708 | if (arg == 2) |
| 709 | arg = 0; |
| 710 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 711 | if (arg) |
| 712 | drive->dev_flags |= IDE_DFLAG_LBA48; |
| 713 | else |
| 714 | drive->dev_flags &= ~IDE_DFLAG_LBA48; |
Bartlomiej Zolnierkiewicz | 942dcd8 | 2008-10-10 22:39:30 +0200 | [diff] [blame] | 715 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | return 0; |
| 717 | } |
| 718 | |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 719 | ide_devset_rw(acoustic, acoustic); |
| 720 | ide_devset_rw(address, addressing); |
| 721 | ide_devset_rw(multcount, multcount); |
| 722 | ide_devset_rw(wcache, wcache); |
| 723 | |
| 724 | ide_devset_rw_sync(nowerr, nowerr); |
| 725 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 726 | #ifdef CONFIG_IDE_PROC_FS |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 727 | ide_devset_rw_field(bios_cyl, bios_cyl); |
| 728 | ide_devset_rw_field(bios_head, bios_head); |
| 729 | ide_devset_rw_field(bios_sect, bios_sect); |
| 730 | ide_devset_rw_field(failures, failures); |
| 731 | ide_devset_rw_field(lun, lun); |
| 732 | ide_devset_rw_field(max_failures, max_failures); |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 733 | |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 734 | static const struct ide_proc_devset idedisk_settings[] = { |
| 735 | IDE_PROC_DEVSET(acoustic, 0, 254), |
| 736 | IDE_PROC_DEVSET(address, 0, 2), |
| 737 | IDE_PROC_DEVSET(bios_cyl, 0, 65535), |
| 738 | IDE_PROC_DEVSET(bios_head, 0, 255), |
| 739 | IDE_PROC_DEVSET(bios_sect, 0, 63), |
| 740 | IDE_PROC_DEVSET(failures, 0, 65535), |
| 741 | IDE_PROC_DEVSET(lun, 0, 7), |
| 742 | IDE_PROC_DEVSET(max_failures, 0, 65535), |
| 743 | IDE_PROC_DEVSET(multcount, 0, 16), |
| 744 | IDE_PROC_DEVSET(nowerr, 0, 1), |
| 745 | IDE_PROC_DEVSET(wcache, 0, 1), |
| 746 | { 0 }, |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 747 | }; |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 748 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 750 | static void idedisk_setup(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | { |
Bartlomiej Zolnierkiewicz | 1e874f4 | 2008-10-10 22:39:27 +0200 | [diff] [blame] | 752 | struct ide_disk_obj *idkp = drive->driver_data; |
Bartlomiej Zolnierkiewicz | 238e4f1 | 2007-10-19 00:30:07 +0200 | [diff] [blame] | 753 | ide_hwif_t *hwif = drive->hwif; |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 754 | u16 *id = drive->id; |
| 755 | char *m = (char *)&id[ATA_ID_PROD]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | unsigned long long capacity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | |
Bartlomiej Zolnierkiewicz | 1e874f4 | 2008-10-10 22:39:27 +0200 | [diff] [blame] | 758 | ide_proc_register_driver(drive, idkp->driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 760 | if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | return; |
| 762 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 763 | if (drive->dev_flags & IDE_DFLAG_REMOVABLE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | /* |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 765 | * Removable disks (eg. SYQUEST); ignore 'WD' drives |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | */ |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 767 | if (m[0] != 'W' || m[1] != 'D') |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 768 | drive->dev_flags |= IDE_DFLAG_DOORLOCKING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | } |
| 770 | |
Bartlomiej Zolnierkiewicz | aa768773 | 2008-10-10 22:39:33 +0200 | [diff] [blame] | 771 | (void)set_addressing(drive, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 773 | if (drive->dev_flags & IDE_DFLAG_LBA48) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | int max_s = 2048; |
| 775 | |
| 776 | if (max_s > hwif->rqsize) |
| 777 | max_s = hwif->rqsize; |
| 778 | |
| 779 | blk_queue_max_sectors(drive->queue, max_s); |
| 780 | } |
| 781 | |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 782 | printk(KERN_INFO "%s: max request size: %dKiB\n", drive->name, |
| 783 | drive->queue->max_sectors / 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 784 | |
| 785 | /* calculate drive capacity, and select LBA if possible */ |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 786 | init_idedisk_capacity(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
| 788 | /* limit drive capacity to 137GB if LBA48 cannot be used */ |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 789 | if ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 && |
| 790 | drive->capacity64 > 1ULL << 28) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | printk(KERN_WARNING "%s: cannot use LBA48 - full capacity " |
| 792 | "%llu sectors (%llu MB)\n", |
| 793 | drive->name, (unsigned long long)drive->capacity64, |
| 794 | sectors_to_MB(drive->capacity64)); |
| 795 | drive->capacity64 = 1ULL << 28; |
| 796 | } |
| 797 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 798 | if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) && |
| 799 | (drive->dev_flags & IDE_DFLAG_LBA48)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | if (drive->capacity64 > 1ULL << 28) { |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 801 | printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode" |
| 802 | " will be used for accessing sectors " |
| 803 | "> %u\n", drive->name, 1 << 28); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | } else |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 805 | drive->dev_flags &= ~IDE_DFLAG_LBA48; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | /* |
| 809 | * if possible, give fdisk access to more of the drive, |
| 810 | * by correcting bios_cyls: |
| 811 | */ |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 812 | capacity = idedisk_capacity(drive); |
| 813 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 814 | if ((drive->dev_flags & IDE_DFLAG_FORCED_GEOM) == 0) { |
Bartlomiej Zolnierkiewicz | 942dcd8 | 2008-10-10 22:39:30 +0200 | [diff] [blame] | 815 | if (ata_id_lba48_enabled(drive->id)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | /* compatibility */ |
| 817 | drive->bios_sect = 63; |
| 818 | drive->bios_head = 255; |
| 819 | } |
| 820 | |
| 821 | if (drive->bios_sect && drive->bios_head) { |
| 822 | unsigned int cap0 = capacity; /* truncate to 32 bits */ |
| 823 | unsigned int cylsz, cyl; |
| 824 | |
| 825 | if (cap0 != capacity) |
| 826 | drive->bios_cyl = 65535; |
| 827 | else { |
| 828 | cylsz = drive->bios_sect * drive->bios_head; |
| 829 | cyl = cap0 / cylsz; |
| 830 | if (cyl > 65535) |
| 831 | cyl = 65535; |
| 832 | if (cyl > drive->bios_cyl) |
| 833 | drive->bios_cyl = cyl; |
| 834 | } |
| 835 | } |
| 836 | } |
| 837 | printk(KERN_INFO "%s: %llu sectors (%llu MB)", |
| 838 | drive->name, capacity, sectors_to_MB(capacity)); |
| 839 | |
| 840 | /* Only print cache size when it was specified */ |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 841 | if (id[ATA_ID_BUF_SIZE]) |
| 842 | printk(KERN_CONT " w/%dKiB Cache", id[ATA_ID_BUF_SIZE] / 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
Bartlomiej Zolnierkiewicz | 3ab7efe | 2007-12-12 23:31:58 +0100 | [diff] [blame] | 844 | printk(KERN_CONT ", CHS=%d/%d/%d\n", |
| 845 | drive->bios_cyl, drive->bios_head, drive->bios_sect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | /* write cache enabled? */ |
Bartlomiej Zolnierkiewicz | 8a089c6 | 2008-10-10 22:39:20 +0200 | [diff] [blame] | 848 | if ((id[ATA_ID_CSFO] & 1) || ata_id_wcache_enabled(id)) |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 849 | drive->dev_flags |= IDE_DFLAG_WCACHE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 851 | set_wcache(drive, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | static void ide_cacheflush_p(ide_drive_t *drive) |
| 855 | { |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 856 | if (ata_id_flush_enabled(drive->id) == 0 || |
| 857 | (drive->dev_flags & IDE_DFLAG_WCACHE) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 858 | return; |
| 859 | |
| 860 | if (do_idedisk_flushcache(drive)) |
| 861 | printk(KERN_INFO "%s: wcache flush failed!\n", drive->name); |
| 862 | } |
| 863 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 864 | static void ide_disk_remove(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | { |
| 866 | struct ide_disk_obj *idkp = drive->driver_data; |
| 867 | struct gendisk *g = idkp->disk; |
| 868 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 869 | ide_proc_unregister_driver(drive, idkp->driver); |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 870 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | del_gendisk(g); |
| 872 | |
Bartlomiej Zolnierkiewicz | d36fef6 | 2005-12-15 02:19:20 +0100 | [diff] [blame] | 873 | ide_cacheflush_p(drive); |
| 874 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | ide_disk_put(idkp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | static void ide_disk_release(struct kref *kref) |
| 879 | { |
| 880 | struct ide_disk_obj *idkp = to_ide_disk(kref); |
| 881 | ide_drive_t *drive = idkp->drive; |
| 882 | struct gendisk *g = idkp->disk; |
| 883 | |
| 884 | drive->driver_data = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | g->private_data = NULL; |
| 886 | put_disk(g); |
| 887 | kfree(idkp); |
| 888 | } |
| 889 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 890 | static int ide_disk_probe(ide_drive_t *drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | |
Lee Trager | 0d2157f | 2007-06-08 15:14:30 +0200 | [diff] [blame] | 892 | /* |
| 893 | * On HPA drives the capacity needs to be |
| 894 | * reinitilized on resume otherwise the disk |
| 895 | * can not be used and a hard reset is required |
| 896 | */ |
| 897 | static void ide_disk_resume(ide_drive_t *drive) |
| 898 | { |
Bartlomiej Zolnierkiewicz | f41891c | 2008-10-10 22:39:20 +0200 | [diff] [blame] | 899 | if (ata_id_hpa_enabled(drive->id)) |
Lee Trager | 0d2157f | 2007-06-08 15:14:30 +0200 | [diff] [blame] | 900 | init_idedisk_capacity(drive); |
| 901 | } |
| 902 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 903 | static void ide_device_shutdown(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | #ifdef CONFIG_ALPHA |
| 906 | /* On Alpha, halt(8) doesn't actually turn the machine off, |
| 907 | it puts you into the sort of firmware monitor. Typically, |
| 908 | it's used to boot another kernel image, so it's not much |
| 909 | different from reboot(8). Therefore, we don't need to |
| 910 | spin down the disk in this case, especially since Alpha |
| 911 | firmware doesn't handle disks in standby mode properly. |
| 912 | On the other hand, it's reasonably safe to turn the power |
| 913 | off when the shutdown process reaches the firmware prompt, |
| 914 | as the firmware initialization takes rather long time - |
| 915 | at least 10 seconds, which should be sufficient for |
| 916 | the disk to expire its write cache. */ |
| 917 | if (system_state != SYSTEM_POWER_OFF) { |
| 918 | #else |
| 919 | if (system_state == SYSTEM_RESTART) { |
| 920 | #endif |
| 921 | ide_cacheflush_p(drive); |
| 922 | return; |
| 923 | } |
| 924 | |
Bartlomiej Zolnierkiewicz | d12faa2 | 2008-02-26 21:50:36 +0100 | [diff] [blame] | 925 | printk(KERN_INFO "Shutdown: %s\n", drive->name); |
| 926 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 927 | drive->gendev.bus->suspend(&drive->gendev, PMSG_SUSPEND); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | } |
| 929 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | static ide_driver_t idedisk_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | .gen_driver = { |
Laurent Riffard | 4ef3b8f | 2005-11-18 22:15:40 +0100 | [diff] [blame] | 932 | .owner = THIS_MODULE, |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 933 | .name = "ide-disk", |
| 934 | .bus = &ide_bus_type, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | }, |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 936 | .probe = ide_disk_probe, |
| 937 | .remove = ide_disk_remove, |
Lee Trager | 0d2157f | 2007-06-08 15:14:30 +0200 | [diff] [blame] | 938 | .resume = ide_disk_resume, |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 939 | .shutdown = ide_device_shutdown, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | .version = IDEDISK_VERSION, |
| 941 | .media = ide_disk, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 942 | .do_request = ide_do_rw_disk, |
| 943 | .end_request = ide_end_request, |
| 944 | .error = __ide_error, |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 945 | #ifdef CONFIG_IDE_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | .proc = idedisk_proc, |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 947 | .settings = idedisk_settings, |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 948 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | }; |
| 950 | |
Bartlomiej Zolnierkiewicz | 29ec683 | 2008-01-26 20:12:59 +0100 | [diff] [blame] | 951 | static int idedisk_set_doorlock(ide_drive_t *drive, int on) |
| 952 | { |
| 953 | ide_task_t task; |
| 954 | |
| 955 | memset(&task, 0, sizeof(task)); |
Bartlomiej Zolnierkiewicz | aaaade3 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 956 | task.tf.command = on ? ATA_CMD_MEDIA_LOCK : ATA_CMD_MEDIA_UNLOCK; |
Bartlomiej Zolnierkiewicz | 657cc1a | 2008-01-26 20:13:10 +0100 | [diff] [blame] | 957 | task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; |
Bartlomiej Zolnierkiewicz | 29ec683 | 2008-01-26 20:12:59 +0100 | [diff] [blame] | 958 | |
| 959 | return ide_no_data_taskfile(drive, &task); |
| 960 | } |
| 961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 962 | static int idedisk_open(struct inode *inode, struct file *filp) |
| 963 | { |
| 964 | struct gendisk *disk = inode->i_bdev->bd_disk; |
| 965 | struct ide_disk_obj *idkp; |
| 966 | ide_drive_t *drive; |
| 967 | |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 968 | idkp = ide_disk_get(disk); |
| 969 | if (idkp == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 970 | return -ENXIO; |
| 971 | |
| 972 | drive = idkp->drive; |
| 973 | |
Bartlomiej Zolnierkiewicz | c94964a | 2007-02-17 02:40:24 +0100 | [diff] [blame] | 974 | idkp->openers++; |
| 975 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 976 | if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | check_disk_change(inode->i_bdev); |
| 978 | /* |
| 979 | * Ignore the return code from door_lock, |
| 980 | * since the open() has already succeeded, |
| 981 | * and the door_lock is irrelevant at this point. |
| 982 | */ |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 983 | if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) && |
| 984 | idedisk_set_doorlock(drive, 1)) |
| 985 | drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 986 | } |
| 987 | return 0; |
| 988 | } |
| 989 | |
| 990 | static int idedisk_release(struct inode *inode, struct file *filp) |
| 991 | { |
| 992 | struct gendisk *disk = inode->i_bdev->bd_disk; |
| 993 | struct ide_disk_obj *idkp = ide_disk_g(disk); |
| 994 | ide_drive_t *drive = idkp->drive; |
| 995 | |
Bartlomiej Zolnierkiewicz | c94964a | 2007-02-17 02:40:24 +0100 | [diff] [blame] | 996 | if (idkp->openers == 1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | ide_cacheflush_p(drive); |
Bartlomiej Zolnierkiewicz | c94964a | 2007-02-17 02:40:24 +0100 | [diff] [blame] | 998 | |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 999 | if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) { |
| 1000 | if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) && |
| 1001 | idedisk_set_doorlock(drive, 0)) |
| 1002 | drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | } |
Bartlomiej Zolnierkiewicz | c94964a | 2007-02-17 02:40:24 +0100 | [diff] [blame] | 1004 | |
| 1005 | idkp->openers--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1006 | |
| 1007 | ide_disk_put(idkp); |
| 1008 | |
| 1009 | return 0; |
| 1010 | } |
| 1011 | |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 1012 | static int idedisk_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
| 1013 | { |
| 1014 | struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk); |
| 1015 | ide_drive_t *drive = idkp->drive; |
| 1016 | |
| 1017 | geo->heads = drive->bios_head; |
| 1018 | geo->sectors = drive->bios_sect; |
| 1019 | geo->cylinders = (u16)drive->bios_cyl; /* truncate */ |
| 1020 | return 0; |
| 1021 | } |
| 1022 | |
Bartlomiej Zolnierkiewicz | aa768773 | 2008-10-10 22:39:33 +0200 | [diff] [blame] | 1023 | static const struct ide_ioctl_devset ide_disk_ioctl_settings[] = { |
Elias Oltmanns | 92f1f8f | 2008-10-10 22:39:40 +0200 | [diff] [blame] | 1024 | { HDIO_GET_ADDRESS, HDIO_SET_ADDRESS, &ide_devset_address }, |
| 1025 | { HDIO_GET_MULTCOUNT, HDIO_SET_MULTCOUNT, &ide_devset_multcount }, |
| 1026 | { HDIO_GET_NOWERR, HDIO_SET_NOWERR, &ide_devset_nowerr }, |
| 1027 | { HDIO_GET_WCACHE, HDIO_SET_WCACHE, &ide_devset_wcache }, |
| 1028 | { HDIO_GET_ACOUSTIC, HDIO_SET_ACOUSTIC, &ide_devset_acoustic }, |
Bartlomiej Zolnierkiewicz | aa768773 | 2008-10-10 22:39:33 +0200 | [diff] [blame] | 1029 | { 0 } |
| 1030 | }; |
| 1031 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | static int idedisk_ioctl(struct inode *inode, struct file *file, |
| 1033 | unsigned int cmd, unsigned long arg) |
| 1034 | { |
| 1035 | struct block_device *bdev = inode->i_bdev; |
| 1036 | struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk); |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1037 | ide_drive_t *drive = idkp->drive; |
Bartlomiej Zolnierkiewicz | aa768773 | 2008-10-10 22:39:33 +0200 | [diff] [blame] | 1038 | int err; |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1039 | |
Bartlomiej Zolnierkiewicz | aa768773 | 2008-10-10 22:39:33 +0200 | [diff] [blame] | 1040 | err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings); |
| 1041 | if (err != -EOPNOTSUPP) |
| 1042 | return err; |
Bartlomiej Zolnierkiewicz | 1497943 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1043 | |
| 1044 | return generic_ide_ioctl(drive, file, bdev, cmd, arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | static int idedisk_media_changed(struct gendisk *disk) |
| 1048 | { |
| 1049 | struct ide_disk_obj *idkp = ide_disk_g(disk); |
| 1050 | ide_drive_t *drive = idkp->drive; |
| 1051 | |
| 1052 | /* do not scan partitions twice if this is a removable device */ |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 1053 | if (drive->dev_flags & IDE_DFLAG_ATTACH) { |
| 1054 | drive->dev_flags &= ~IDE_DFLAG_ATTACH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1055 | return 0; |
| 1056 | } |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 1057 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | /* if removable, always assume it was changed */ |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 1059 | return !!(drive->dev_flags & IDE_DFLAG_REMOVABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | static int idedisk_revalidate_disk(struct gendisk *disk) |
| 1063 | { |
| 1064 | struct ide_disk_obj *idkp = ide_disk_g(disk); |
| 1065 | set_capacity(disk, idedisk_capacity(idkp->drive)); |
| 1066 | return 0; |
| 1067 | } |
| 1068 | |
| 1069 | static struct block_device_operations idedisk_ops = { |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 1070 | .owner = THIS_MODULE, |
| 1071 | .open = idedisk_open, |
| 1072 | .release = idedisk_release, |
| 1073 | .ioctl = idedisk_ioctl, |
| 1074 | .getgeo = idedisk_getgeo, |
| 1075 | .media_changed = idedisk_media_changed, |
| 1076 | .revalidate_disk = idedisk_revalidate_disk |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | }; |
| 1078 | |
| 1079 | MODULE_DESCRIPTION("ATA DISK Driver"); |
| 1080 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 1081 | static int ide_disk_probe(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1082 | { |
| 1083 | struct ide_disk_obj *idkp; |
| 1084 | struct gendisk *g; |
| 1085 | |
| 1086 | /* strstr("foo", "") is non-NULL */ |
| 1087 | if (!strstr("ide-disk", drive->driver_req)) |
| 1088 | goto failed; |
Bartlomiej Zolnierkiewicz | 2a92466 | 2008-10-10 22:39:24 +0200 | [diff] [blame] | 1089 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | if (drive->media != ide_disk) |
| 1091 | goto failed; |
| 1092 | |
Deepak Saxena | f5e3c2f | 2005-11-07 01:01:25 -0800 | [diff] [blame] | 1093 | idkp = kzalloc(sizeof(*idkp), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1094 | if (!idkp) |
| 1095 | goto failed; |
| 1096 | |
Tejun Heo | 689d6fa | 2008-08-25 19:56:16 +0900 | [diff] [blame] | 1097 | g = alloc_disk_node(IDE_DISK_MINORS, hwif_to_node(drive->hwif)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | if (!g) |
| 1099 | goto out_free_idkp; |
| 1100 | |
| 1101 | ide_init_disk(g, drive); |
| 1102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | kref_init(&idkp->kref); |
| 1104 | |
| 1105 | idkp->drive = drive; |
| 1106 | idkp->driver = &idedisk_driver; |
| 1107 | idkp->disk = g; |
| 1108 | |
| 1109 | g->private_data = &idkp->driver; |
| 1110 | |
| 1111 | drive->driver_data = idkp; |
| 1112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | idedisk_setup(drive); |
| 1114 | if ((!drive->head || drive->head > 16) && !drive->select.b.lba) { |
| 1115 | printk(KERN_ERR "%s: INVALID GEOMETRY: %d PHYSICAL HEADS?\n", |
| 1116 | drive->name, drive->head); |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 1117 | drive->dev_flags &= ~IDE_DFLAG_ATTACH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | } else |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 1119 | drive->dev_flags |= IDE_DFLAG_ATTACH; |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1120 | |
Tejun Heo | f615b48 | 2008-08-25 19:47:24 +0900 | [diff] [blame] | 1121 | g->minors = IDE_DISK_MINORS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | g->driverfs_dev = &drive->gendev; |
Tejun Heo | 689d6fa | 2008-08-25 19:56:16 +0900 | [diff] [blame] | 1123 | g->flags |= GENHD_FL_EXT_DEVT; |
Bartlomiej Zolnierkiewicz | 97100fc | 2008-10-13 21:39:36 +0200 | [diff] [blame^] | 1124 | if (drive->dev_flags & IDE_DFLAG_REMOVABLE) |
| 1125 | g->flags = GENHD_FL_REMOVABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | set_capacity(g, idedisk_capacity(drive)); |
| 1127 | g->fops = &idedisk_ops; |
| 1128 | add_disk(g); |
| 1129 | return 0; |
| 1130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | out_free_idkp: |
| 1132 | kfree(idkp); |
| 1133 | failed: |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1134 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1135 | } |
| 1136 | |
Bartlomiej Zolnierkiewicz | 9841654 | 2008-04-26 17:36:37 +0200 | [diff] [blame] | 1137 | static void __exit idedisk_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | { |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1139 | driver_unregister(&idedisk_driver.gen_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | } |
| 1141 | |
Bartlomiej Zolnierkiewicz | 17514e8 | 2005-11-19 22:24:35 +0100 | [diff] [blame] | 1142 | static int __init idedisk_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | { |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1144 | return driver_register(&idedisk_driver.gen_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
Kay Sievers | 263756e | 2005-12-12 18:03:44 +0100 | [diff] [blame] | 1147 | MODULE_ALIAS("ide:*m-disk*"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | module_init(idedisk_init); |
| 1149 | module_exit(idedisk_exit); |
| 1150 | MODULE_LICENSE("GPL"); |