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