Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Borislav Petkov | d3f2084 | 2008-02-01 23:09:33 +0100 | [diff] [blame] | 2 | * IDE ATAPI floppy driver. |
| 3 | * |
Bartlomiej Zolnierkiewicz | 59bca8c | 2008-02-01 23:09:33 +0100 | [diff] [blame] | 4 | * Copyright (C) 1996-1999 Gadi Oxman <gadio@netvision.net.il> |
| 5 | * Copyright (C) 2000-2002 Paul Bristow <paul@paulbristow.net> |
| 6 | * Copyright (C) 2005 Bartlomiej Zolnierkiewicz |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 7 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | * This driver supports the following IDE floppy drives: |
| 9 | * |
| 10 | * LS-120/240 SuperDisk |
| 11 | * Iomega Zip 100/250 |
| 12 | * Iomega PC Card Clik!/PocketZip |
| 13 | * |
Borislav Petkov | d3f2084 | 2008-02-01 23:09:33 +0100 | [diff] [blame] | 14 | * For a historical changelog see |
| 15 | * Documentation/ide/ChangeLog.ide-floppy.1996-2002 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
Bartlomiej Zolnierkiewicz | 51509ee | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 18 | #define DRV_NAME "ide-floppy" |
| 19 | |
Borislav Petkov | fc6c5bc | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 20 | #define IDEFLOPPY_VERSION "1.00" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include <linux/module.h> |
| 23 | #include <linux/types.h> |
| 24 | #include <linux/string.h> |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/delay.h> |
| 27 | #include <linux/timer.h> |
| 28 | #include <linux/mm.h> |
| 29 | #include <linux/interrupt.h> |
| 30 | #include <linux/major.h> |
| 31 | #include <linux/errno.h> |
| 32 | #include <linux/genhd.h> |
| 33 | #include <linux/slab.h> |
| 34 | #include <linux/cdrom.h> |
| 35 | #include <linux/ide.h> |
Bartlomiej Zolnierkiewicz | 3ceca72 | 2008-10-10 22:39:27 +0200 | [diff] [blame] | 36 | #include <linux/hdreg.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/bitops.h> |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 38 | #include <linux/mutex.h> |
Borislav Petkov | b98b340 | 2008-10-10 22:39:35 +0200 | [diff] [blame] | 39 | #include <linux/scatterlist.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
Bartlomiej Zolnierkiewicz | 89636af | 2007-07-20 01:11:59 +0200 | [diff] [blame] | 41 | #include <scsi/scsi_ioctl.h> |
| 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <asm/byteorder.h> |
Borislav Petkov | 7e8b163 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 44 | #include <linux/irq.h> |
| 45 | #include <linux/uaccess.h> |
| 46 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #include <asm/unaligned.h> |
| 48 | |
Borislav Petkov | f373bd8 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 49 | /* define to see debug info */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #define IDEFLOPPY_DEBUG_LOG 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | /* #define IDEFLOPPY_DEBUG(fmt, args...) printk(KERN_INFO fmt, ## args) */ |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 53 | #define IDEFLOPPY_DEBUG(fmt, args...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | #if IDEFLOPPY_DEBUG_LOG |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 56 | #define debug_log(fmt, args...) \ |
| 57 | printk(KERN_INFO "ide-floppy: " fmt, ## args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | #else |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 59 | #define debug_log(fmt, args...) do {} while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #endif |
| 61 | |
| 62 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 63 | /* Some drives require a longer irq timeout. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | #define IDEFLOPPY_WAIT_CMD (5 * WAIT_CMD) |
| 65 | |
| 66 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 67 | * After each failed packet command we issue a request sense command and retry |
| 68 | * the packet command IDEFLOPPY_MAX_PC_RETRIES times. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | */ |
| 70 | #define IDEFLOPPY_MAX_PC_RETRIES 3 |
| 71 | |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 72 | /* format capacities descriptor codes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #define CAPACITY_INVALID 0x00 |
| 74 | #define CAPACITY_UNFORMATTED 0x01 |
| 75 | #define CAPACITY_CURRENT 0x02 |
| 76 | #define CAPACITY_NO_CARTRIDGE 0x03 |
| 77 | |
| 78 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 79 | * Most of our global data which we need to save even as we leave the driver |
| 80 | * due to an interrupt or a timer event is stored in a variable of type |
| 81 | * idefloppy_floppy_t, defined below. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | */ |
| 83 | typedef struct ide_floppy_obj { |
| 84 | ide_drive_t *drive; |
| 85 | ide_driver_t *driver; |
| 86 | struct gendisk *disk; |
| 87 | struct kref kref; |
Bartlomiej Zolnierkiewicz | c94964a | 2007-02-17 02:40:24 +0100 | [diff] [blame] | 88 | unsigned int openers; /* protected by BKL for now */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
| 90 | /* Current packet command */ |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 91 | struct ide_atapi_pc *pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | /* Last failed packet command */ |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 93 | struct ide_atapi_pc *failed_pc; |
Bartlomiej Zolnierkiewicz | 2e8a6f8 | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 94 | /* used for blk_{fs,pc}_request() requests */ |
| 95 | struct ide_atapi_pc queued_pc; |
Bartlomiej Zolnierkiewicz | 394a4c2 | 2008-10-10 22:39:35 +0200 | [diff] [blame] | 96 | |
Bartlomiej Zolnierkiewicz | 2e8a6f8 | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 97 | struct ide_atapi_pc request_sense_pc; |
Bartlomiej Zolnierkiewicz | 394a4c2 | 2008-10-10 22:39:35 +0200 | [diff] [blame] | 98 | struct request request_sense_rq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 100 | /* Last error information */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | u8 sense_key, asc, ascq; |
| 102 | /* delay this long before sending packet command */ |
| 103 | u8 ticks; |
| 104 | int progress_indication; |
| 105 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 106 | /* Device information */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | /* Current format */ |
| 108 | int blocks, block_size, bs_factor; |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 109 | /* Last format capacity descriptor */ |
| 110 | u8 cap_desc[8]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | /* Copy of the flexible disk page */ |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 112 | u8 flexible_disk_page[32]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | /* Write protect */ |
| 114 | int wp; |
| 115 | /* Supports format progress report */ |
| 116 | int srfp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } idefloppy_floppy_t; |
| 118 | |
Bartlomiej Zolnierkiewicz | c40d3d3 | 2005-08-18 22:09:21 +0200 | [diff] [blame] | 119 | #define IDEFLOPPY_TICKS_DELAY HZ/20 /* default delay for ZIP 100 (50ms) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 121 | /* IOCTLs used in low-level formatting. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | #define IDEFLOPPY_IOCTL_FORMAT_SUPPORTED 0x4600 |
| 123 | #define IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY 0x4601 |
| 124 | #define IDEFLOPPY_IOCTL_FORMAT_START 0x4602 |
| 125 | #define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603 |
| 126 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 127 | /* Error code returned in rq->errors to the higher part of the driver. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | #define IDEFLOPPY_ERROR_GENERAL 101 |
| 129 | |
| 130 | /* |
Borislav Petkov | 948391d | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 131 | * Pages of the SELECT SENSE / MODE SENSE packet commands. |
| 132 | * See SFF-8070i spec. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | */ |
| 134 | #define IDEFLOPPY_CAPABILITIES_PAGE 0x1b |
| 135 | #define IDEFLOPPY_FLEXIBLE_DISK_PAGE 0x05 |
| 136 | |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 137 | static DEFINE_MUTEX(idefloppy_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
| 139 | #define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref) |
| 140 | |
| 141 | #define ide_floppy_g(disk) \ |
| 142 | container_of((disk)->private_data, struct ide_floppy_obj, driver) |
| 143 | |
Bartlomiej Zolnierkiewicz | 08da591 | 2008-07-24 22:53:15 +0200 | [diff] [blame] | 144 | static void idefloppy_cleanup_obj(struct kref *); |
| 145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk) |
| 147 | { |
| 148 | struct ide_floppy_obj *floppy = NULL; |
| 149 | |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 150 | mutex_lock(&idefloppy_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | floppy = ide_floppy_g(disk); |
Bartlomiej Zolnierkiewicz | 08da591 | 2008-07-24 22:53:15 +0200 | [diff] [blame] | 152 | if (floppy) { |
Bartlomiej Zolnierkiewicz | d3e33ff | 2008-08-05 18:16:59 +0200 | [diff] [blame] | 153 | if (ide_device_get(floppy->drive)) |
Bartlomiej Zolnierkiewicz | 08da591 | 2008-07-24 22:53:15 +0200 | [diff] [blame] | 154 | floppy = NULL; |
Bartlomiej Zolnierkiewicz | d3e33ff | 2008-08-05 18:16:59 +0200 | [diff] [blame] | 155 | else |
| 156 | kref_get(&floppy->kref); |
Bartlomiej Zolnierkiewicz | 08da591 | 2008-07-24 22:53:15 +0200 | [diff] [blame] | 157 | } |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 158 | mutex_unlock(&idefloppy_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | return floppy; |
| 160 | } |
| 161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | static void ide_floppy_put(struct ide_floppy_obj *floppy) |
| 163 | { |
Bartlomiej Zolnierkiewicz | d3e33ff | 2008-08-05 18:16:59 +0200 | [diff] [blame] | 164 | ide_drive_t *drive = floppy->drive; |
| 165 | |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 166 | mutex_lock(&idefloppy_ref_mutex); |
Borislav Petkov | 9a24b63 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 167 | kref_put(&floppy->kref, idefloppy_cleanup_obj); |
Bartlomiej Zolnierkiewicz | d3e33ff | 2008-08-05 18:16:59 +0200 | [diff] [blame] | 168 | ide_device_put(drive); |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 169 | mutex_unlock(&idefloppy_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 173 | * Used to finish servicing a request. For read/write requests, we will call |
| 174 | * ide_end_request to pass to the next buffer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | */ |
Borislav Petkov | c2b2b29 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 176 | static int idefloppy_end_request(ide_drive_t *drive, int uptodate, int nsecs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | { |
| 178 | idefloppy_floppy_t *floppy = drive->driver_data; |
| 179 | struct request *rq = HWGROUP(drive)->rq; |
| 180 | int error; |
| 181 | |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 182 | debug_log("Reached %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
| 184 | switch (uptodate) { |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 185 | case 0: error = IDEFLOPPY_ERROR_GENERAL; break; |
| 186 | case 1: error = 0; break; |
| 187 | default: error = uptodate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } |
| 189 | if (error) |
| 190 | floppy->failed_pc = NULL; |
| 191 | /* Why does this happen? */ |
| 192 | if (!rq) |
| 193 | return 0; |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 194 | if (!blk_special_request(rq)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | /* our real local end request function */ |
| 196 | ide_end_request(drive, uptodate, nsecs); |
| 197 | return 0; |
| 198 | } |
| 199 | rq->errors = error; |
| 200 | /* fixme: need to move this local also */ |
| 201 | ide_end_drive_cmd(drive, 0, 0); |
| 202 | return 0; |
| 203 | } |
| 204 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 205 | static void idefloppy_update_buffers(ide_drive_t *drive, |
| 206 | struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | { |
| 208 | struct request *rq = pc->rq; |
| 209 | struct bio *bio = rq->bio; |
| 210 | |
| 211 | while ((bio = rq->bio) != NULL) |
Borislav Petkov | c2b2b29 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 212 | idefloppy_end_request(drive, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } |
| 214 | |
Borislav Petkov | 81f4938 | 2008-07-15 21:21:56 +0200 | [diff] [blame] | 215 | static void ide_floppy_callback(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | { |
| 217 | idefloppy_floppy_t *floppy = drive->driver_data; |
Borislav Petkov | 81f4938 | 2008-07-15 21:21:56 +0200 | [diff] [blame] | 218 | struct ide_atapi_pc *pc = floppy->pc; |
| 219 | int uptodate = pc->error ? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 221 | debug_log("Reached %s\n", __func__); |
| 222 | |
Bartlomiej Zolnierkiewicz | dd2e9a0 | 2008-07-15 21:22:01 +0200 | [diff] [blame] | 223 | if (floppy->failed_pc == pc) |
| 224 | floppy->failed_pc = NULL; |
| 225 | |
Borislav Petkov | 81f4938 | 2008-07-15 21:21:56 +0200 | [diff] [blame] | 226 | if (pc->c[0] == GPCMD_READ_10 || pc->c[0] == GPCMD_WRITE_10 || |
| 227 | (pc->rq && blk_pc_request(pc->rq))) |
| 228 | uptodate = 1; /* FIXME */ |
| 229 | else if (pc->c[0] == GPCMD_REQUEST_SENSE) { |
| 230 | u8 *buf = floppy->pc->buf; |
Borislav Petkov | a6ff2d3 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 231 | |
Borislav Petkov | 81f4938 | 2008-07-15 21:21:56 +0200 | [diff] [blame] | 232 | if (!pc->error) { |
| 233 | floppy->sense_key = buf[2] & 0x0F; |
| 234 | floppy->asc = buf[12]; |
| 235 | floppy->ascq = buf[13]; |
| 236 | floppy->progress_indication = buf[15] & 0x80 ? |
| 237 | (u16)get_unaligned((u16 *)&buf[16]) : 0x10000; |
| 238 | |
| 239 | if (floppy->failed_pc) |
| 240 | debug_log("pc = %x, ", floppy->failed_pc->c[0]); |
| 241 | |
Borislav Petkov | a6ff2d3 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 242 | debug_log("sense key = %x, asc = %x, ascq = %x\n", |
Borislav Petkov | 81f4938 | 2008-07-15 21:21:56 +0200 | [diff] [blame] | 243 | floppy->sense_key, floppy->asc, floppy->ascq); |
| 244 | } else |
| 245 | printk(KERN_ERR "Error in REQUEST SENSE itself - " |
| 246 | "Aborting request!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
Borislav Petkov | 81f4938 | 2008-07-15 21:21:56 +0200 | [diff] [blame] | 249 | idefloppy_end_request(drive, uptodate, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 252 | static void idefloppy_create_request_sense_cmd(struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | { |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 254 | ide_init_pc(pc); |
Borislav Petkov | 30d6709 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 255 | pc->c[0] = GPCMD_REQUEST_SENSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | pc->c[4] = 255; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 257 | pc->req_xfer = 18; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 261 | * Called when an error was detected during the last packet command. We queue a |
| 262 | * request sense packet command in the head of the request list. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | */ |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 264 | static void idefloppy_retry_pc(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | { |
Bartlomiej Zolnierkiewicz | 394a4c2 | 2008-10-10 22:39:35 +0200 | [diff] [blame] | 266 | struct ide_floppy_obj *floppy = drive->driver_data; |
| 267 | struct request *rq = &floppy->request_sense_rq; |
Bartlomiej Zolnierkiewicz | 2e8a6f8 | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 268 | struct ide_atapi_pc *pc = &floppy->request_sense_pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Bartlomiej Zolnierkiewicz | 64a57fe | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 270 | (void)ide_read_error(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | idefloppy_create_request_sense_cmd(pc); |
Bartlomiej Zolnierkiewicz | 7645c15 | 2008-10-10 22:39:37 +0200 | [diff] [blame^] | 272 | ide_queue_pc_head(drive, floppy->disk, pc, rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | } |
| 274 | |
Borislav Petkov | 0eea645 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 275 | /* The usual interrupt handler called during a packet command. */ |
Paolo Ciarrocchi | 52d3ccf | 2008-04-26 17:36:41 +0200 | [diff] [blame] | 276 | static ide_startstop_t idefloppy_pc_intr(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | { |
| 278 | idefloppy_floppy_t *floppy = drive->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 280 | return ide_pc_intr(drive, floppy->pc, idefloppy_pc_intr, |
| 281 | IDEFLOPPY_WAIT_CMD, NULL, idefloppy_update_buffers, |
Bartlomiej Zolnierkiewicz | acaa0f5 | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 282 | idefloppy_retry_pc, NULL, ide_io_buffers); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 286 | * What we have here is a classic case of a top half / bottom half interrupt |
| 287 | * service routine. In interrupt mode, the device sends an interrupt to signal |
| 288 | * that it is ready to receive a packet. However, we need to delay about 2-3 |
| 289 | * ticks before issuing the packet or we gets in trouble. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | */ |
Borislav Petkov | cbbc4e8 | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 291 | static int idefloppy_transfer_pc(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | { |
| 293 | idefloppy_floppy_t *floppy = drive->driver_data; |
| 294 | |
| 295 | /* Send the actual packet */ |
Bartlomiej Zolnierkiewicz | 374e042 | 2008-07-23 19:55:56 +0200 | [diff] [blame] | 296 | drive->hwif->tp_ops->output_data(drive, NULL, floppy->pc->c, 12); |
Bartlomiej Zolnierkiewicz | 9567b34 | 2008-04-28 23:44:36 +0200 | [diff] [blame] | 297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | /* Timeout for the packet command */ |
| 299 | return IDEFLOPPY_WAIT_CMD; |
| 300 | } |
| 301 | |
Borislav Petkov | cbbc4e8 | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 302 | |
| 303 | /* |
| 304 | * Called as an interrupt (or directly). When the device says it's ready for a |
| 305 | * packet, we schedule the packet transfer to occur about 2-3 ticks later in |
| 306 | * transfer_pc. |
| 307 | */ |
| 308 | static ide_startstop_t idefloppy_start_pc_transfer(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | { |
| 310 | idefloppy_floppy_t *floppy = drive->driver_data; |
Bartlomiej Zolnierkiewicz | 6ffb6641 | 2008-07-15 21:21:56 +0200 | [diff] [blame] | 311 | struct ide_atapi_pc *pc = floppy->pc; |
Bartlomiej Zolnierkiewicz | 0b2eea4 | 2008-07-15 21:21:54 +0200 | [diff] [blame] | 312 | ide_expiry_t *expiry; |
| 313 | unsigned int timeout; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 315 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | * The following delay solves a problem with ATAPI Zip 100 drives |
| 317 | * where the Busy flag was apparently being deasserted before the |
| 318 | * unit was ready to receive data. This was happening on a |
| 319 | * 1200 MHz Athlon system. 10/26/01 25msec is too short, |
| 320 | * 40 and 50msec work well. idefloppy_pc_intr will not be actually |
| 321 | * used until after the packet is moved in about 50 msec. |
| 322 | */ |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 323 | if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) { |
Bartlomiej Zolnierkiewicz | 0b2eea4 | 2008-07-15 21:21:54 +0200 | [diff] [blame] | 324 | timeout = floppy->ticks; |
Borislav Petkov | cbbc4e8 | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 325 | expiry = &idefloppy_transfer_pc; |
Bartlomiej Zolnierkiewicz | 0b2eea4 | 2008-07-15 21:21:54 +0200 | [diff] [blame] | 326 | } else { |
| 327 | timeout = IDEFLOPPY_WAIT_CMD; |
| 328 | expiry = NULL; |
| 329 | } |
Borislav Petkov | 0078df2 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 330 | |
Bartlomiej Zolnierkiewicz | 594c16d | 2008-07-15 21:21:58 +0200 | [diff] [blame] | 331 | return ide_transfer_pc(drive, pc, idefloppy_pc_intr, timeout, expiry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | } |
| 333 | |
Borislav Petkov | d652c13 | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 334 | static void ide_floppy_report_error(idefloppy_floppy_t *floppy, |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 335 | struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | { |
Borislav Petkov | d652c13 | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 337 | /* supress error messages resulting from Medium not present */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | if (floppy->sense_key == 0x02 && |
| 339 | floppy->asc == 0x3a && |
| 340 | floppy->ascq == 0x00) |
Borislav Petkov | d652c13 | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 341 | return; |
| 342 | |
| 343 | printk(KERN_ERR "ide-floppy: %s: I/O error, pc = %2x, key = %2x, " |
| 344 | "asc = %2x, ascq = %2x\n", |
| 345 | floppy->drive->name, pc->c[0], floppy->sense_key, |
| 346 | floppy->asc, floppy->ascq); |
| 347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 350 | static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive, |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 351 | struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | { |
| 353 | idefloppy_floppy_t *floppy = drive->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | if (floppy->failed_pc == NULL && |
Borislav Petkov | 30d6709 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 356 | pc->c[0] != GPCMD_REQUEST_SENSE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | floppy->failed_pc = pc; |
| 358 | /* Set the current packet command */ |
| 359 | floppy->pc = pc; |
| 360 | |
Borislav Petkov | 757ced8 | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 361 | if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) { |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 362 | if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR)) |
Borislav Petkov | 757ced8 | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 363 | ide_floppy_report_error(floppy, pc); |
| 364 | /* Giving up */ |
| 365 | pc->error = IDEFLOPPY_ERROR_GENERAL; |
| 366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | floppy->failed_pc = NULL; |
Borislav Petkov | 2207fa5 | 2008-07-23 19:55:59 +0200 | [diff] [blame] | 368 | drive->pc_callback(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | return ide_stopped; |
| 370 | } |
| 371 | |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 372 | debug_log("Retry number - %d\n", pc->retries); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
| 374 | pc->retries++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | |
Borislav Petkov | cbbc4e8 | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 376 | return ide_issue_pc(drive, pc, idefloppy_start_pc_transfer, |
Bartlomiej Zolnierkiewicz | 6bf1641 | 2008-07-15 21:22:00 +0200 | [diff] [blame] | 377 | IDEFLOPPY_WAIT_CMD, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | } |
| 379 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 380 | static void idefloppy_create_prevent_cmd(struct ide_atapi_pc *pc, int prevent) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | { |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 382 | debug_log("creating prevent removal command, prevent = %d\n", prevent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 384 | ide_init_pc(pc); |
Borislav Petkov | 30d6709 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 385 | pc->c[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | pc->c[4] = prevent; |
| 387 | } |
| 388 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 389 | static void idefloppy_create_read_capacity_cmd(struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | { |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 391 | ide_init_pc(pc); |
Borislav Petkov | 30d6709 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 392 | pc->c[0] = GPCMD_READ_FORMAT_CAPACITIES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | pc->c[7] = 255; |
| 394 | pc->c[8] = 255; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 395 | pc->req_xfer = 255; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } |
| 397 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 398 | static void idefloppy_create_format_unit_cmd(struct ide_atapi_pc *pc, int b, |
| 399 | int l, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | { |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 401 | ide_init_pc(pc); |
Borislav Petkov | 30d6709 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 402 | pc->c[0] = GPCMD_FORMAT_UNIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | pc->c[1] = 0x17; |
| 404 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 405 | memset(pc->buf, 0, 12); |
| 406 | pc->buf[1] = 0xA2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | /* Default format list header, u8 1: FOV/DCRT/IMM bits set */ |
| 408 | |
| 409 | if (flags & 1) /* Verify bit on... */ |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 410 | pc->buf[1] ^= 0x20; /* ... turn off DCRT bit */ |
| 411 | pc->buf[3] = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 413 | put_unaligned(cpu_to_be32(b), (unsigned int *)(&pc->buf[4])); |
| 414 | put_unaligned(cpu_to_be32(l), (unsigned int *)(&pc->buf[8])); |
| 415 | pc->buf_size = 12; |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 416 | pc->flags |= PC_FLAG_WRITING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 419 | /* A mode sense command is used to "sense" floppy parameters. */ |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 420 | static void idefloppy_create_mode_sense_cmd(struct ide_atapi_pc *pc, |
Bartlomiej Zolnierkiewicz | 4de4b9e | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 421 | u8 page_code) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | { |
Borislav Petkov | 24a5d70 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 423 | u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */ |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 424 | |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 425 | ide_init_pc(pc); |
Borislav Petkov | 30d6709 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 426 | pc->c[0] = GPCMD_MODE_SENSE_10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | pc->c[1] = 0; |
Bartlomiej Zolnierkiewicz | 4de4b9e | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 428 | pc->c[2] = page_code; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
| 430 | switch (page_code) { |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 431 | case IDEFLOPPY_CAPABILITIES_PAGE: |
| 432 | length += 12; |
| 433 | break; |
| 434 | case IDEFLOPPY_FLEXIBLE_DISK_PAGE: |
| 435 | length += 32; |
| 436 | break; |
| 437 | default: |
| 438 | printk(KERN_ERR "ide-floppy: unsupported page code " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | "in create_mode_sense_cmd\n"); |
| 440 | } |
Borislav Petkov | 8f62243 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 441 | put_unaligned(cpu_to_be16(length), (u16 *) &pc->c[7]); |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 442 | pc->req_xfer = length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 445 | static void idefloppy_create_start_stop_cmd(struct ide_atapi_pc *pc, int start) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | { |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 447 | ide_init_pc(pc); |
Borislav Petkov | 30d6709 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 448 | pc->c[0] = GPCMD_START_STOP_UNIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | pc->c[4] = start; |
| 450 | } |
| 451 | |
Borislav Petkov | ae7e8dd | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 452 | static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy, |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 453 | struct ide_atapi_pc *pc, struct request *rq, |
Borislav Petkov | ae7e8dd | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 454 | unsigned long sector) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | { |
| 456 | int block = sector / floppy->bs_factor; |
| 457 | int blocks = rq->nr_sectors / floppy->bs_factor; |
| 458 | int cmd = rq_data_dir(rq); |
| 459 | |
Borislav Petkov | ae7e8dd | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 460 | debug_log("create_rw10_cmd: block == %d, blocks == %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | block, blocks); |
| 462 | |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 463 | ide_init_pc(pc); |
Borislav Petkov | ae7e8dd | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 464 | pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10; |
| 465 | put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]); |
Borislav Petkov | 8f62243 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 466 | put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]); |
Borislav Petkov | ae7e8dd | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 467 | |
Borislav Petkov | 20cd93be67 | 2008-07-23 19:56:00 +0200 | [diff] [blame] | 468 | memcpy(rq->cmd, pc->c, 12); |
| 469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | pc->rq = rq; |
Borislav Petkov | b98b340 | 2008-10-10 22:39:35 +0200 | [diff] [blame] | 471 | pc->b_count = 0; |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 472 | if (rq->cmd_flags & REQ_RW) |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 473 | pc->flags |= PC_FLAG_WRITING; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 474 | pc->buf = NULL; |
| 475 | pc->req_xfer = pc->buf_size = blocks * floppy->block_size; |
Bartlomiej Zolnierkiewicz | 5e33109 | 2008-07-15 21:21:56 +0200 | [diff] [blame] | 476 | pc->flags |= PC_FLAG_DMA_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | } |
| 478 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 479 | static void idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy, |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 480 | struct ide_atapi_pc *pc, struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | { |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 482 | ide_init_pc(pc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | memcpy(pc->c, rq->cmd, sizeof(pc->c)); |
Jens Axboe | 3d6392c | 2007-07-09 12:38:05 +0200 | [diff] [blame] | 484 | pc->rq = rq; |
Borislav Petkov | b98b340 | 2008-10-10 22:39:35 +0200 | [diff] [blame] | 485 | pc->b_count = 0; |
Jens Axboe | 3d6392c | 2007-07-09 12:38:05 +0200 | [diff] [blame] | 486 | if (rq->data_len && rq_data_dir(rq) == WRITE) |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 487 | pc->flags |= PC_FLAG_WRITING; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 488 | pc->buf = rq->data; |
Jens Axboe | 3d6392c | 2007-07-09 12:38:05 +0200 | [diff] [blame] | 489 | if (rq->bio) |
Bartlomiej Zolnierkiewicz | 5e33109 | 2008-07-15 21:21:56 +0200 | [diff] [blame] | 490 | pc->flags |= PC_FLAG_DMA_OK; |
Jens Axboe | 3d6392c | 2007-07-09 12:38:05 +0200 | [diff] [blame] | 491 | /* |
| 492 | * possibly problematic, doesn't look like ide-floppy correctly |
| 493 | * handled scattered requests if dma fails... |
| 494 | */ |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 495 | pc->req_xfer = pc->buf_size = rq->data_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 498 | static ide_startstop_t idefloppy_do_request(ide_drive_t *drive, |
| 499 | struct request *rq, sector_t block_s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | { |
| 501 | idefloppy_floppy_t *floppy = drive->driver_data; |
Borislav Petkov | b98b340 | 2008-10-10 22:39:35 +0200 | [diff] [blame] | 502 | ide_hwif_t *hwif = drive->hwif; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 503 | struct ide_atapi_pc *pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | unsigned long block = (unsigned long)block_s; |
| 505 | |
Borislav Petkov | b98b340 | 2008-10-10 22:39:35 +0200 | [diff] [blame] | 506 | debug_log("%s: dev: %s, cmd: 0x%x, cmd_type: %x, errors: %d\n", |
| 507 | __func__, rq->rq_disk ? rq->rq_disk->disk_name : "?", |
| 508 | rq->cmd[0], rq->cmd_type, rq->errors); |
| 509 | |
| 510 | debug_log("%s: sector: %ld, nr_sectors: %ld, current_nr_sectors: %d\n", |
| 511 | __func__, (long)rq->sector, rq->nr_sectors, |
| 512 | rq->current_nr_sectors); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | |
| 514 | if (rq->errors >= ERROR_MAX) { |
Borislav Petkov | d652c13 | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 515 | if (floppy->failed_pc) |
| 516 | ide_floppy_report_error(floppy, floppy->failed_pc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | else |
| 518 | printk(KERN_ERR "ide-floppy: %s: I/O error\n", |
| 519 | drive->name); |
Borislav Petkov | c2b2b29 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 520 | idefloppy_end_request(drive, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | return ide_stopped; |
| 522 | } |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 523 | if (blk_fs_request(rq)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | if (((long)rq->sector % floppy->bs_factor) || |
| 525 | (rq->nr_sectors % floppy->bs_factor)) { |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 526 | printk(KERN_ERR "%s: unsupported r/w request size\n", |
| 527 | drive->name); |
Borislav Petkov | c2b2b29 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 528 | idefloppy_end_request(drive, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | return ide_stopped; |
| 530 | } |
Bartlomiej Zolnierkiewicz | 2e8a6f8 | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 531 | pc = &floppy->queued_pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | idefloppy_create_rw_cmd(floppy, pc, rq, block); |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 533 | } else if (blk_special_request(rq)) { |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 534 | pc = (struct ide_atapi_pc *) rq->buffer; |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 535 | } else if (blk_pc_request(rq)) { |
Bartlomiej Zolnierkiewicz | 2e8a6f8 | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 536 | pc = &floppy->queued_pc; |
Jens Axboe | 3d6392c | 2007-07-09 12:38:05 +0200 | [diff] [blame] | 537 | idefloppy_blockpc_cmd(floppy, pc, rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | } else { |
| 539 | blk_dump_rq_flags(rq, |
| 540 | "ide-floppy: unsupported command in queue"); |
Borislav Petkov | c2b2b29 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 541 | idefloppy_end_request(drive, 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | return ide_stopped; |
| 543 | } |
| 544 | |
Borislav Petkov | b98b340 | 2008-10-10 22:39:35 +0200 | [diff] [blame] | 545 | ide_init_sg_cmd(drive, rq); |
| 546 | ide_map_sg(drive, rq); |
| 547 | |
| 548 | pc->sg = hwif->sg_table; |
| 549 | pc->sg_cnt = hwif->sg_nents; |
| 550 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | pc->rq = rq; |
Bartlomiej Zolnierkiewicz | 5d41893 | 2008-07-15 21:21:57 +0200 | [diff] [blame] | 552 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | return idefloppy_issue_pc(drive, pc); |
| 554 | } |
| 555 | |
| 556 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 557 | * Add a special packet command request to the tail of the request queue, |
| 558 | * and wait for it to be serviced. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | */ |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 560 | static int idefloppy_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | { |
| 562 | struct ide_floppy_obj *floppy = drive->driver_data; |
FUJITA Tomonori | 6fe1623 | 2008-07-15 21:21:43 +0200 | [diff] [blame] | 563 | struct request *rq; |
| 564 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
FUJITA Tomonori | 6fe1623 | 2008-07-15 21:21:43 +0200 | [diff] [blame] | 566 | rq = blk_get_request(drive->queue, READ, __GFP_WAIT); |
| 567 | rq->buffer = (char *) pc; |
| 568 | rq->cmd_type = REQ_TYPE_SPECIAL; |
Borislav Petkov | 20cd93be67 | 2008-07-23 19:56:00 +0200 | [diff] [blame] | 569 | memcpy(rq->cmd, pc->c, 12); |
FUJITA Tomonori | 6fe1623 | 2008-07-15 21:21:43 +0200 | [diff] [blame] | 570 | error = blk_execute_rq(drive->queue, floppy->disk, rq, 0); |
| 571 | blk_put_request(rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
FUJITA Tomonori | 6fe1623 | 2008-07-15 21:21:43 +0200 | [diff] [blame] | 573 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | /* |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 577 | * Look at the flexible disk page parameters. We ignore the CHS capacity |
| 578 | * parameters and use the LBA parameters instead. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | */ |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 580 | static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | { |
| 582 | idefloppy_floppy_t *floppy = drive->driver_data; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 583 | struct ide_atapi_pc pc; |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 584 | u8 *page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | int capacity, lba_capacity; |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 586 | u16 transfer_rate, sector_size, cyls, rpm; |
| 587 | u8 heads, sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | |
Bartlomiej Zolnierkiewicz | 4de4b9e | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 589 | idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE); |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 590 | |
| 591 | if (idefloppy_queue_pc_tail(drive, &pc)) { |
| 592 | printk(KERN_ERR "ide-floppy: Can't get flexible disk page" |
| 593 | " parameters\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | return 1; |
| 595 | } |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 596 | floppy->wp = !!(pc.buf[3] & 0x80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | set_disk_ro(floppy->disk, floppy->wp); |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 598 | page = &pc.buf[8]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
Harvey Harrison | 85ae98a3 | 2008-07-16 20:33:47 +0200 | [diff] [blame] | 600 | transfer_rate = be16_to_cpup((__be16 *)&pc.buf[8 + 2]); |
| 601 | sector_size = be16_to_cpup((__be16 *)&pc.buf[8 + 6]); |
| 602 | cyls = be16_to_cpup((__be16 *)&pc.buf[8 + 8]); |
| 603 | rpm = be16_to_cpup((__be16 *)&pc.buf[8 + 28]); |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 604 | heads = pc.buf[8 + 4]; |
| 605 | sectors = pc.buf[8 + 5]; |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 606 | |
| 607 | capacity = cyls * heads * sectors * sector_size; |
| 608 | |
| 609 | if (memcmp(page, &floppy->flexible_disk_page, 32)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | printk(KERN_INFO "%s: %dkB, %d/%d/%d CHS, %d kBps, " |
| 611 | "%d sector size, %d rpm\n", |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 612 | drive->name, capacity / 1024, cyls, heads, |
| 613 | sectors, transfer_rate / 8, sector_size, rpm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 615 | memcpy(&floppy->flexible_disk_page, page, 32); |
| 616 | drive->bios_cyl = cyls; |
| 617 | drive->bios_head = heads; |
| 618 | drive->bios_sect = sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | lba_capacity = floppy->blocks * floppy->block_size; |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 620 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | if (capacity < lba_capacity) { |
| 622 | printk(KERN_NOTICE "%s: The disk reports a capacity of %d " |
| 623 | "bytes, but the drive only handles %d\n", |
| 624 | drive->name, lba_capacity, capacity); |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 625 | floppy->blocks = floppy->block_size ? |
| 626 | capacity / floppy->block_size : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | } |
| 628 | return 0; |
| 629 | } |
| 630 | |
Borislav Petkov | 948391d | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 631 | static int idefloppy_get_sfrp_bit(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | { |
| 633 | idefloppy_floppy_t *floppy = drive->driver_data; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 634 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | |
| 636 | floppy->srfp = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
Bartlomiej Zolnierkiewicz | 4de4b9e | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 638 | idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_CAPABILITIES_PAGE); |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 639 | pc.flags |= PC_FLAG_SUPPRESS_ERROR; |
Bartlomiej Zolnierkiewicz | 4de4b9e | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 640 | |
Borislav Petkov | 948391d | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 641 | if (idefloppy_queue_pc_tail(drive, &pc)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 644 | floppy->srfp = pc.buf[8 + 2] & 0x40; |
Bartlomiej Zolnierkiewicz | e3faa24 | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 645 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | /* |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 649 | * Determine if a media is present in the floppy drive, and if so, its LBA |
| 650 | * capacity. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | */ |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 652 | static int ide_floppy_get_capacity(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | { |
| 654 | idefloppy_floppy_t *floppy = drive->driver_data; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 655 | struct ide_atapi_pc pc; |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 656 | u8 *cap_desc; |
| 657 | u8 header_len, desc_cnt; |
| 658 | int i, rc = 1, blocks, length; |
| 659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | drive->bios_cyl = 0; |
| 661 | drive->bios_head = drive->bios_sect = 0; |
Alan Cox | fdb77da | 2007-02-17 02:40:20 +0100 | [diff] [blame] | 662 | floppy->blocks = 0; |
| 663 | floppy->bs_factor = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | set_capacity(floppy->disk, 0); |
| 665 | |
| 666 | idefloppy_create_read_capacity_cmd(&pc); |
| 667 | if (idefloppy_queue_pc_tail(drive, &pc)) { |
| 668 | printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); |
| 669 | return 1; |
| 670 | } |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 671 | header_len = pc.buf[3]; |
| 672 | cap_desc = &pc.buf[4]; |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 673 | desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 675 | for (i = 0; i < desc_cnt; i++) { |
| 676 | unsigned int desc_start = 4 + i*8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | |
Harvey Harrison | 85ae98a3 | 2008-07-16 20:33:47 +0200 | [diff] [blame] | 678 | blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]); |
| 679 | length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]); |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 680 | |
| 681 | debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n", |
| 682 | i, blocks * length / 1024, blocks, length); |
| 683 | |
| 684 | if (i) |
| 685 | continue; |
| 686 | /* |
| 687 | * the code below is valid only for the 1st descriptor, ie i=0 |
| 688 | */ |
| 689 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 690 | switch (pc.buf[desc_start + 4] & 0x03) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | /* Clik! drive returns this instead of CAPACITY_CURRENT */ |
| 692 | case CAPACITY_UNFORMATTED: |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 693 | if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 694 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | * If it is not a clik drive, break out |
| 696 | * (maintains previous driver behaviour) |
| 697 | */ |
| 698 | break; |
| 699 | case CAPACITY_CURRENT: |
| 700 | /* Normal Zip/LS-120 disks */ |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 701 | if (memcmp(cap_desc, &floppy->cap_desc, 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | printk(KERN_INFO "%s: %dkB, %d blocks, %d " |
| 703 | "sector size\n", drive->name, |
| 704 | blocks * length / 1024, blocks, length); |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 705 | memcpy(&floppy->cap_desc, cap_desc, 8); |
| 706 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | if (!length || length % 512) { |
| 708 | printk(KERN_NOTICE "%s: %d bytes block size " |
| 709 | "not supported\n", drive->name, length); |
| 710 | } else { |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 711 | floppy->blocks = blocks; |
| 712 | floppy->block_size = length; |
| 713 | floppy->bs_factor = length / 512; |
| 714 | if (floppy->bs_factor != 1) |
| 715 | printk(KERN_NOTICE "%s: warning: non " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | "512 bytes block size not " |
| 717 | "fully supported\n", |
| 718 | drive->name); |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 719 | rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | } |
| 721 | break; |
| 722 | case CAPACITY_NO_CARTRIDGE: |
| 723 | /* |
| 724 | * This is a KERN_ERR so it appears on screen |
| 725 | * for the user to see |
| 726 | */ |
| 727 | printk(KERN_ERR "%s: No disk in drive\n", drive->name); |
| 728 | break; |
| 729 | case CAPACITY_INVALID: |
| 730 | printk(KERN_ERR "%s: Invalid capacity for disk " |
| 731 | "in drive\n", drive->name); |
| 732 | break; |
| 733 | } |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 734 | debug_log("Descriptor 0 Code: %d\n", |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 735 | pc.buf[desc_start + 4] & 0x03); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | } |
| 737 | |
| 738 | /* Clik! disk does not support get_flexible_disk_page */ |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 739 | if (!(drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE)) |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 740 | (void) ide_floppy_get_flexible_disk_page(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | |
| 742 | set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor); |
| 743 | return rc; |
| 744 | } |
| 745 | |
| 746 | /* |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 747 | * Obtain the list of formattable capacities. |
| 748 | * Very similar to ide_floppy_get_capacity, except that we push the capacity |
| 749 | * descriptors to userland, instead of our own structures. |
| 750 | * |
| 751 | * Userland gives us the following structure: |
| 752 | * |
| 753 | * struct idefloppy_format_capacities { |
| 754 | * int nformats; |
| 755 | * struct { |
| 756 | * int nblocks; |
| 757 | * int blocksize; |
| 758 | * } formats[]; |
| 759 | * }; |
| 760 | * |
| 761 | * userland initializes nformats to the number of allocated formats[] records. |
| 762 | * On exit we set nformats to the number of records we've actually initialized. |
| 763 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 765 | static int ide_floppy_get_format_capacities(ide_drive_t *drive, int __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | { |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 767 | struct ide_atapi_pc pc; |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 768 | u8 header_len, desc_cnt; |
| 769 | int i, blocks, length, u_array_size, u_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | int __user *argp; |
| 771 | |
| 772 | if (get_user(u_array_size, arg)) |
Bartlomiej Zolnierkiewicz | e3faa24 | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 773 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
| 775 | if (u_array_size <= 0) |
Bartlomiej Zolnierkiewicz | e3faa24 | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 776 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
| 778 | idefloppy_create_read_capacity_cmd(&pc); |
| 779 | if (idefloppy_queue_pc_tail(drive, &pc)) { |
| 780 | printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); |
Bartlomiej Zolnierkiewicz | e3faa24 | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 781 | return -EIO; |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 782 | } |
Bartlomiej Zolnierkiewicz | e3faa24 | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 783 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 784 | header_len = pc.buf[3]; |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 785 | desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
| 787 | u_index = 0; |
| 788 | argp = arg + 1; |
| 789 | |
| 790 | /* |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 791 | * We always skip the first capacity descriptor. That's the current |
| 792 | * capacity. We are interested in the remaining descriptors, the |
| 793 | * formattable capacities. |
| 794 | */ |
| 795 | for (i = 1; i < desc_cnt; i++) { |
| 796 | unsigned int desc_start = 4 + i*8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | if (u_index >= u_array_size) |
| 799 | break; /* User-supplied buffer too small */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | |
Harvey Harrison | 85ae98a3 | 2008-07-16 20:33:47 +0200 | [diff] [blame] | 801 | blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]); |
| 802 | length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | |
| 804 | if (put_user(blocks, argp)) |
Bartlomiej Zolnierkiewicz | e3faa24 | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 805 | return -EFAULT; |
| 806 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | ++argp; |
| 808 | |
| 809 | if (put_user(length, argp)) |
Bartlomiej Zolnierkiewicz | e3faa24 | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 810 | return -EFAULT; |
| 811 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | ++argp; |
| 813 | |
| 814 | ++u_index; |
| 815 | } |
| 816 | |
| 817 | if (put_user(u_index, arg)) |
Bartlomiej Zolnierkiewicz | e3faa24 | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 818 | return -EFAULT; |
| 819 | |
| 820 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 824 | * Get ATAPI_FORMAT_UNIT progress indication. |
| 825 | * |
| 826 | * Userland gives a pointer to an int. The int is set to a progress |
| 827 | * indicator 0-65536, with 65536=100%. |
| 828 | * |
| 829 | * If the drive does not support format progress indication, we just check |
| 830 | * the dsc bit, and return either 0 or 65536. |
| 831 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | |
Bartlomiej Zolnierkiewicz | d56c99e | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 833 | static int ide_floppy_get_format_progress(ide_drive_t *drive, int __user *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | { |
| 835 | idefloppy_floppy_t *floppy = drive->driver_data; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 836 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | int progress_indication = 0x10000; |
| 838 | |
| 839 | if (floppy->srfp) { |
| 840 | idefloppy_create_request_sense_cmd(&pc); |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 841 | if (idefloppy_queue_pc_tail(drive, &pc)) |
Bartlomiej Zolnierkiewicz | e3faa24 | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 842 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | |
| 844 | if (floppy->sense_key == 2 && |
| 845 | floppy->asc == 4 && |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 846 | floppy->ascq == 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | progress_indication = floppy->progress_indication; |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 848 | |
| 849 | /* Else assume format_unit has finished, and we're at 0x10000 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | } else { |
Bartlomiej Zolnierkiewicz | b73c7ee | 2008-07-23 19:55:52 +0200 | [diff] [blame] | 851 | ide_hwif_t *hwif = drive->hwif; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | unsigned long flags; |
Bartlomiej Zolnierkiewicz | 22c525b | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 853 | u8 stat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | |
| 855 | local_irq_save(flags); |
Bartlomiej Zolnierkiewicz | 374e042 | 2008-07-23 19:55:56 +0200 | [diff] [blame] | 856 | stat = hwif->tp_ops->read_status(hwif); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | local_irq_restore(flags); |
| 858 | |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 859 | progress_indication = ((stat & ATA_DSC) == 0) ? 0 : 0x10000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | |
Bartlomiej Zolnierkiewicz | e3faa24 | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 862 | if (put_user(progress_indication, arg)) |
| 863 | return -EFAULT; |
| 864 | |
| 865 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | } |
| 867 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 868 | static sector_t idefloppy_capacity(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | { |
| 870 | idefloppy_floppy_t *floppy = drive->driver_data; |
| 871 | unsigned long capacity = floppy->blocks * floppy->bs_factor; |
| 872 | |
| 873 | return capacity; |
| 874 | } |
| 875 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 876 | #ifdef CONFIG_IDE_PROC_FS |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 877 | ide_devset_rw(bios_cyl, 0, 1023, bios_cyl); |
| 878 | ide_devset_rw(bios_head, 0, 255, bios_head); |
| 879 | ide_devset_rw(bios_sect, 0, 63, bios_sect); |
| 880 | |
| 881 | static int get_ticks(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | { |
| 883 | idefloppy_floppy_t *floppy = drive->driver_data; |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 884 | return floppy->ticks; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | } |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 886 | |
| 887 | static int set_ticks(ide_drive_t *drive, int arg) |
| 888 | { |
| 889 | idefloppy_floppy_t *floppy = drive->driver_data; |
| 890 | floppy->ticks = arg; |
| 891 | return 0; |
| 892 | } |
| 893 | |
| 894 | IDE_DEVSET(ticks, S_RW, 0, 255, get_ticks, set_ticks); |
| 895 | |
| 896 | static const struct ide_devset *idefloppy_settings[] = { |
| 897 | &ide_devset_bios_cyl, |
| 898 | &ide_devset_bios_head, |
| 899 | &ide_devset_bios_sect, |
| 900 | &ide_devset_ticks, |
| 901 | NULL |
| 902 | }; |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 903 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 905 | static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | { |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 907 | u16 *id = drive->id; |
Borislav Petkov | 3ad6776 | 2008-04-18 00:46:25 +0200 | [diff] [blame] | 908 | u8 gcw[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 910 | *((u16 *)&gcw) = id[ATA_ID_CONFIG]; |
Bartlomiej Zolnierkiewicz | 2e8a6f8 | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 911 | |
Borislav Petkov | 2207fa5 | 2008-07-23 19:55:59 +0200 | [diff] [blame] | 912 | drive->pc_callback = ide_floppy_callback; |
Borislav Petkov | 3ad6776 | 2008-04-18 00:46:25 +0200 | [diff] [blame] | 913 | |
| 914 | if (((gcw[0] & 0x60) >> 5) == 1) |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 915 | drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 917 | * We used to check revisions here. At this point however I'm giving up. |
| 918 | * Just assume they are all broken, its easier. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | * |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 920 | * The actual reason for the workarounds was likely a driver bug after |
| 921 | * all rather than a firmware bug, and the workaround below used to hide |
| 922 | * it. It should be fixed as of version 1.9, but to be on the safe side |
| 923 | * we'll leave the limitation below for the 2.2.x tree. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | */ |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 925 | if (!strncmp((char *)&id[ATA_ID_PROD], "IOMEGA ZIP 100 ATAPI", 20)) { |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 926 | drive->atapi_flags |= IDE_AFLAG_ZIP_DRIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | /* This value will be visible in the /proc/ide/hdx/settings */ |
| 928 | floppy->ticks = IDEFLOPPY_TICKS_DELAY; |
| 929 | blk_queue_max_sectors(drive->queue, 64); |
| 930 | } |
| 931 | |
| 932 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 933 | * Guess what? The IOMEGA Clik! drive also needs the above fix. It makes |
| 934 | * nasty clicking noises without it, so please don't remove this. |
| 935 | */ |
Bartlomiej Zolnierkiewicz | 4dde449 | 2008-10-10 22:39:19 +0200 | [diff] [blame] | 936 | if (strncmp((char *)&id[ATA_ID_PROD], "IOMEGA Clik!", 11) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | blk_queue_max_sectors(drive->queue, 64); |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 938 | drive->atapi_flags |= IDE_AFLAG_CLIK_DRIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 939 | } |
| 940 | |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 941 | (void) ide_floppy_get_capacity(drive); |
Bartlomiej Zolnierkiewicz | 1e874f4 | 2008-10-10 22:39:27 +0200 | [diff] [blame] | 942 | |
| 943 | ide_proc_register_driver(drive, floppy->driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 944 | } |
| 945 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 946 | static void ide_floppy_remove(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | { |
| 948 | idefloppy_floppy_t *floppy = drive->driver_data; |
| 949 | struct gendisk *g = floppy->disk; |
| 950 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 951 | ide_proc_unregister_driver(drive, floppy->driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | |
| 953 | del_gendisk(g); |
| 954 | |
| 955 | ide_floppy_put(floppy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | } |
| 957 | |
Borislav Petkov | 9a24b63 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 958 | static void idefloppy_cleanup_obj(struct kref *kref) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | { |
| 960 | struct ide_floppy_obj *floppy = to_ide_floppy(kref); |
| 961 | ide_drive_t *drive = floppy->drive; |
| 962 | struct gendisk *g = floppy->disk; |
| 963 | |
| 964 | drive->driver_data = NULL; |
| 965 | g->private_data = NULL; |
| 966 | put_disk(g); |
| 967 | kfree(floppy); |
| 968 | } |
| 969 | |
Bartlomiej Zolnierkiewicz | ecfd80e | 2007-05-10 00:01:09 +0200 | [diff] [blame] | 970 | #ifdef CONFIG_IDE_PROC_FS |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 971 | static int proc_idefloppy_read_capacity(char *page, char **start, off_t off, |
| 972 | int count, int *eof, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | { |
| 974 | ide_drive_t*drive = (ide_drive_t *)data; |
| 975 | int len; |
| 976 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 977 | len = sprintf(page, "%llu\n", (long long)idefloppy_capacity(drive)); |
| 978 | PROC_IDE_READ_RETURN(page, start, off, count, eof, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | } |
| 980 | |
| 981 | static ide_proc_entry_t idefloppy_proc[] = { |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 982 | { "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL }, |
| 983 | { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | { NULL, 0, NULL, NULL } |
| 985 | }; |
Bartlomiej Zolnierkiewicz | ecfd80e | 2007-05-10 00:01:09 +0200 | [diff] [blame] | 986 | #endif /* CONFIG_IDE_PROC_FS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 988 | static int ide_floppy_probe(ide_drive_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | static ide_driver_t idefloppy_driver = { |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 991 | .gen_driver = { |
Laurent Riffard | 4ef3b8f | 2005-11-18 22:15:40 +0100 | [diff] [blame] | 992 | .owner = THIS_MODULE, |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 993 | .name = "ide-floppy", |
| 994 | .bus = &ide_bus_type, |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 995 | }, |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 996 | .probe = ide_floppy_probe, |
| 997 | .remove = ide_floppy_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | .version = IDEFLOPPY_VERSION, |
| 999 | .media = ide_floppy, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | .do_request = idefloppy_do_request, |
Borislav Petkov | c2b2b29 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1001 | .end_request = idefloppy_end_request, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | .error = __ide_error, |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1003 | #ifdef CONFIG_IDE_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | .proc = idefloppy_proc, |
Bartlomiej Zolnierkiewicz | 8185d5a | 2008-10-10 22:39:28 +0200 | [diff] [blame] | 1005 | .settings = idefloppy_settings, |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1006 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | }; |
| 1008 | |
Bartlomiej Zolnierkiewicz | e996fc8 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 1009 | static void ide_floppy_set_media_lock(ide_drive_t *drive, int on) |
| 1010 | { |
| 1011 | struct ide_atapi_pc pc; |
| 1012 | |
| 1013 | /* IOMEGA Clik! drives do not support lock/unlock commands */ |
| 1014 | if ((drive->atapi_flags & IDE_AFLAG_CLIK_DRIVE) == 0) { |
| 1015 | idefloppy_create_prevent_cmd(&pc, on); |
| 1016 | (void)idefloppy_queue_pc_tail(drive, &pc); |
| 1017 | } |
| 1018 | } |
| 1019 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | static int idefloppy_open(struct inode *inode, struct file *filp) |
| 1021 | { |
| 1022 | struct gendisk *disk = inode->i_bdev->bd_disk; |
| 1023 | struct ide_floppy_obj *floppy; |
| 1024 | ide_drive_t *drive; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1025 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | int ret = 0; |
| 1027 | |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 1028 | debug_log("Reached %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1030 | floppy = ide_floppy_get(disk); |
| 1031 | if (!floppy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | return -ENXIO; |
| 1033 | |
| 1034 | drive = floppy->drive; |
| 1035 | |
Bartlomiej Zolnierkiewicz | c94964a | 2007-02-17 02:40:24 +0100 | [diff] [blame] | 1036 | floppy->openers++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
Bartlomiej Zolnierkiewicz | c94964a | 2007-02-17 02:40:24 +0100 | [diff] [blame] | 1038 | if (floppy->openers == 1) { |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 1039 | drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | /* Just in case */ |
| 1041 | |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 1042 | ide_init_pc(&pc); |
Borislav Petkov | c96a7df | 2008-07-16 20:33:46 +0200 | [diff] [blame] | 1043 | pc.c[0] = GPCMD_TEST_UNIT_READY; |
| 1044 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | if (idefloppy_queue_pc_tail(drive, &pc)) { |
| 1046 | idefloppy_create_start_stop_cmd(&pc, 1); |
| 1047 | (void) idefloppy_queue_pc_tail(drive, &pc); |
| 1048 | } |
| 1049 | |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1050 | if (ide_floppy_get_capacity(drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1051 | && (filp->f_flags & O_NDELAY) == 0 |
| 1052 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1053 | * Allow O_NDELAY to open a drive without a disk, or with an |
| 1054 | * unreadable disk, so that we can get the format capacity |
| 1055 | * of the drive or begin the format - Sam |
| 1056 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | ret = -EIO; |
| 1059 | goto out_put_floppy; |
| 1060 | } |
| 1061 | |
| 1062 | if (floppy->wp && (filp->f_mode & 2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1063 | ret = -EROFS; |
| 1064 | goto out_put_floppy; |
| 1065 | } |
Bartlomiej Zolnierkiewicz | e996fc8 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 1066 | |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 1067 | drive->atapi_flags |= IDE_AFLAG_MEDIA_CHANGED; |
Bartlomiej Zolnierkiewicz | e996fc8 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 1068 | ide_floppy_set_media_lock(drive, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | check_disk_change(inode->i_bdev); |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 1070 | } else if (drive->atapi_flags & IDE_AFLAG_FORMAT_IN_PROGRESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | ret = -EBUSY; |
| 1072 | goto out_put_floppy; |
| 1073 | } |
| 1074 | return 0; |
| 1075 | |
| 1076 | out_put_floppy: |
Bartlomiej Zolnierkiewicz | c94964a | 2007-02-17 02:40:24 +0100 | [diff] [blame] | 1077 | floppy->openers--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | ide_floppy_put(floppy); |
| 1079 | return ret; |
| 1080 | } |
| 1081 | |
| 1082 | static int idefloppy_release(struct inode *inode, struct file *filp) |
| 1083 | { |
| 1084 | struct gendisk *disk = inode->i_bdev->bd_disk; |
| 1085 | struct ide_floppy_obj *floppy = ide_floppy_g(disk); |
| 1086 | ide_drive_t *drive = floppy->drive; |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 1087 | |
| 1088 | debug_log("Reached %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | |
Bartlomiej Zolnierkiewicz | c94964a | 2007-02-17 02:40:24 +0100 | [diff] [blame] | 1090 | if (floppy->openers == 1) { |
Bartlomiej Zolnierkiewicz | e996fc8 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 1091 | ide_floppy_set_media_lock(drive, 0); |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 1092 | drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | } |
Bartlomiej Zolnierkiewicz | c94964a | 2007-02-17 02:40:24 +0100 | [diff] [blame] | 1094 | |
| 1095 | floppy->openers--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | |
| 1097 | ide_floppy_put(floppy); |
| 1098 | |
| 1099 | return 0; |
| 1100 | } |
| 1101 | |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 1102 | static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
| 1103 | { |
| 1104 | struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk); |
| 1105 | ide_drive_t *drive = floppy->drive; |
| 1106 | |
| 1107 | geo->heads = drive->bios_head; |
| 1108 | geo->sectors = drive->bios_sect; |
| 1109 | geo->cylinders = (u16)drive->bios_cyl; /* truncate */ |
| 1110 | return 0; |
| 1111 | } |
| 1112 | |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 1113 | static int ide_floppy_lockdoor(ide_drive_t *drive, struct ide_atapi_pc *pc, |
| 1114 | unsigned long arg, unsigned int cmd) |
Borislav Petkov | 20bf7bd | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1115 | { |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 1116 | idefloppy_floppy_t *floppy = drive->driver_data; |
Bartlomiej Zolnierkiewicz | e996fc8 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 1117 | int prevent = (arg && cmd != CDROMEJECT) ? 1 : 0; |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 1118 | |
Borislav Petkov | 20bf7bd | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1119 | if (floppy->openers > 1) |
| 1120 | return -EBUSY; |
| 1121 | |
Bartlomiej Zolnierkiewicz | e996fc8 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 1122 | ide_floppy_set_media_lock(drive, prevent); |
Borislav Petkov | 20bf7bd | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1123 | |
| 1124 | if (cmd == CDROMEJECT) { |
| 1125 | idefloppy_create_start_stop_cmd(pc, 2); |
| 1126 | (void) idefloppy_queue_pc_tail(floppy->drive, pc); |
| 1127 | } |
| 1128 | |
| 1129 | return 0; |
| 1130 | } |
| 1131 | |
Bartlomiej Zolnierkiewicz | d56c99e | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 1132 | static int ide_floppy_format_unit(ide_drive_t *drive, int __user *arg) |
Borislav Petkov | 20bf7bd | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1133 | { |
Bartlomiej Zolnierkiewicz | d56c99e | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 1134 | idefloppy_floppy_t *floppy = drive->driver_data; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1135 | struct ide_atapi_pc pc; |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 1136 | int blocks, length, flags, err = 0; |
Borislav Petkov | 20bf7bd | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1137 | |
| 1138 | if (floppy->openers > 1) { |
| 1139 | /* Don't format if someone is using the disk */ |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 1140 | drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS; |
Borislav Petkov | 20bf7bd | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1141 | return -EBUSY; |
| 1142 | } |
| 1143 | |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 1144 | drive->atapi_flags |= IDE_AFLAG_FORMAT_IN_PROGRESS; |
Borislav Petkov | 20bf7bd | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1145 | |
| 1146 | /* |
| 1147 | * Send ATAPI_FORMAT_UNIT to the drive. |
| 1148 | * |
| 1149 | * Userland gives us the following structure: |
| 1150 | * |
| 1151 | * struct idefloppy_format_command { |
| 1152 | * int nblocks; |
| 1153 | * int blocksize; |
| 1154 | * int flags; |
| 1155 | * } ; |
| 1156 | * |
| 1157 | * flags is a bitmask, currently, the only defined flag is: |
| 1158 | * |
| 1159 | * 0x01 - verify media after format. |
| 1160 | */ |
| 1161 | if (get_user(blocks, arg) || |
| 1162 | get_user(length, arg+1) || |
| 1163 | get_user(flags, arg+2)) { |
| 1164 | err = -EFAULT; |
| 1165 | goto out; |
| 1166 | } |
| 1167 | |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 1168 | (void) idefloppy_get_sfrp_bit(drive); |
Borislav Petkov | 20bf7bd | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1169 | idefloppy_create_format_unit_cmd(&pc, blocks, length, flags); |
| 1170 | |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 1171 | if (idefloppy_queue_pc_tail(drive, &pc)) |
Borislav Petkov | 20bf7bd | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1172 | err = -EIO; |
| 1173 | |
| 1174 | out: |
| 1175 | if (err) |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 1176 | drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS; |
Borislav Petkov | 20bf7bd | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1177 | return err; |
| 1178 | } |
| 1179 | |
Bartlomiej Zolnierkiewicz | d56c99e | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 1180 | static int ide_floppy_format_ioctl(ide_drive_t *drive, struct file *file, |
| 1181 | unsigned int cmd, void __user *argp) |
| 1182 | { |
| 1183 | switch (cmd) { |
| 1184 | case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED: |
| 1185 | return 0; |
| 1186 | case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY: |
| 1187 | return ide_floppy_get_format_capacities(drive, argp); |
| 1188 | case IDEFLOPPY_IOCTL_FORMAT_START: |
| 1189 | if (!(file->f_mode & 2)) |
| 1190 | return -EPERM; |
| 1191 | return ide_floppy_format_unit(drive, (int __user *)argp); |
| 1192 | case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS: |
| 1193 | return ide_floppy_get_format_progress(drive, argp); |
| 1194 | default: |
| 1195 | return -ENOTTY; |
| 1196 | } |
| 1197 | } |
Borislav Petkov | 20bf7bd | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1198 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | static int idefloppy_ioctl(struct inode *inode, struct file *file, |
| 1200 | unsigned int cmd, unsigned long arg) |
| 1201 | { |
| 1202 | struct block_device *bdev = inode->i_bdev; |
| 1203 | struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk); |
| 1204 | ide_drive_t *drive = floppy->drive; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1205 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | void __user *argp = (void __user *)arg; |
Ondrej Zary | 07203f6 | 2005-11-10 00:25:15 +0100 | [diff] [blame] | 1207 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | |
Bartlomiej Zolnierkiewicz | d56c99e | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 1209 | if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR) |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 1210 | return ide_floppy_lockdoor(drive, &pc, arg, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | |
Bartlomiej Zolnierkiewicz | d56c99e | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 1212 | err = ide_floppy_format_ioctl(drive, file, cmd, argp); |
| 1213 | if (err != -ENOTTY) |
| 1214 | return err; |
Bartlomiej Zolnierkiewicz | 89636af | 2007-07-20 01:11:59 +0200 | [diff] [blame] | 1215 | |
| 1216 | /* |
| 1217 | * skip SCSI_IOCTL_SEND_COMMAND (deprecated) |
| 1218 | * and CDROM_SEND_PACKET (legacy) ioctls |
| 1219 | */ |
| 1220 | if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND) |
| 1221 | err = scsi_cmd_ioctl(file, bdev->bd_disk->queue, |
| 1222 | bdev->bd_disk, cmd, argp); |
Bartlomiej Zolnierkiewicz | 89636af | 2007-07-20 01:11:59 +0200 | [diff] [blame] | 1223 | |
| 1224 | if (err == -ENOTTY) |
| 1225 | err = generic_ide_ioctl(drive, file, bdev, cmd, arg); |
| 1226 | |
| 1227 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | } |
| 1229 | |
| 1230 | static int idefloppy_media_changed(struct gendisk *disk) |
| 1231 | { |
| 1232 | struct ide_floppy_obj *floppy = ide_floppy_g(disk); |
| 1233 | ide_drive_t *drive = floppy->drive; |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 1234 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | |
| 1236 | /* do not scan partitions twice if this is a removable device */ |
| 1237 | if (drive->attach) { |
| 1238 | drive->attach = 0; |
| 1239 | return 0; |
| 1240 | } |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 1241 | ret = !!(drive->atapi_flags & IDE_AFLAG_MEDIA_CHANGED); |
| 1242 | drive->atapi_flags &= ~IDE_AFLAG_MEDIA_CHANGED; |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 1243 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | } |
| 1245 | |
| 1246 | static int idefloppy_revalidate_disk(struct gendisk *disk) |
| 1247 | { |
| 1248 | struct ide_floppy_obj *floppy = ide_floppy_g(disk); |
| 1249 | set_capacity(disk, idefloppy_capacity(floppy->drive)); |
| 1250 | return 0; |
| 1251 | } |
| 1252 | |
| 1253 | static struct block_device_operations idefloppy_ops = { |
Paolo Ciarrocchi | 52d3ccf | 2008-04-26 17:36:41 +0200 | [diff] [blame] | 1254 | .owner = THIS_MODULE, |
| 1255 | .open = idefloppy_open, |
| 1256 | .release = idefloppy_release, |
| 1257 | .ioctl = idefloppy_ioctl, |
| 1258 | .getgeo = idefloppy_getgeo, |
| 1259 | .media_changed = idefloppy_media_changed, |
| 1260 | .revalidate_disk = idefloppy_revalidate_disk |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | }; |
| 1262 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 1263 | static int ide_floppy_probe(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | { |
| 1265 | idefloppy_floppy_t *floppy; |
| 1266 | struct gendisk *g; |
| 1267 | |
| 1268 | if (!strstr("ide-floppy", drive->driver_req)) |
| 1269 | goto failed; |
Bartlomiej Zolnierkiewicz | 2a92466 | 2008-10-10 22:39:24 +0200 | [diff] [blame] | 1270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | if (drive->media != ide_floppy) |
| 1272 | goto failed; |
Bartlomiej Zolnierkiewicz | 2a92466 | 2008-10-10 22:39:24 +0200 | [diff] [blame] | 1273 | |
Bartlomiej Zolnierkiewicz | 51509ee | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 1274 | if (!ide_check_atapi_device(drive, DRV_NAME)) { |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1275 | printk(KERN_ERR "ide-floppy: %s: not supported by this version" |
| 1276 | " of ide-floppy\n", drive->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | goto failed; |
| 1278 | } |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1279 | floppy = kzalloc(sizeof(idefloppy_floppy_t), GFP_KERNEL); |
| 1280 | if (!floppy) { |
| 1281 | printk(KERN_ERR "ide-floppy: %s: Can't allocate a floppy" |
| 1282 | " structure\n", drive->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1283 | goto failed; |
| 1284 | } |
| 1285 | |
| 1286 | g = alloc_disk(1 << PARTN_BITS); |
| 1287 | if (!g) |
| 1288 | goto out_free_floppy; |
| 1289 | |
| 1290 | ide_init_disk(g, drive); |
| 1291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | kref_init(&floppy->kref); |
| 1293 | |
| 1294 | floppy->drive = drive; |
| 1295 | floppy->driver = &idefloppy_driver; |
| 1296 | floppy->disk = g; |
| 1297 | |
| 1298 | g->private_data = &floppy->driver; |
| 1299 | |
| 1300 | drive->driver_data = floppy; |
| 1301 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1302 | idefloppy_setup(drive, floppy); |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | g->minors = 1 << PARTN_BITS; |
| 1305 | g->driverfs_dev = &drive->gendev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1306 | g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0; |
| 1307 | g->fops = &idefloppy_ops; |
| 1308 | drive->attach = 1; |
| 1309 | add_disk(g); |
| 1310 | return 0; |
| 1311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | out_free_floppy: |
| 1313 | kfree(floppy); |
| 1314 | failed: |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1315 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1318 | static void __exit idefloppy_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | { |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1320 | driver_unregister(&idefloppy_driver.gen_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1321 | } |
| 1322 | |
Bartlomiej Zolnierkiewicz | 17514e8 | 2005-11-19 22:24:35 +0100 | [diff] [blame] | 1323 | static int __init idefloppy_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | { |
| 1325 | printk("ide-floppy driver " IDEFLOPPY_VERSION "\n"); |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1326 | return driver_register(&idefloppy_driver.gen_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
Kay Sievers | 263756e | 2005-12-12 18:03:44 +0100 | [diff] [blame] | 1329 | MODULE_ALIAS("ide:*m-floppy*"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | module_init(idefloppy_init); |
| 1331 | module_exit(idefloppy_exit); |
| 1332 | MODULE_LICENSE("GPL"); |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1333 | MODULE_DESCRIPTION("ATAPI FLOPPY Driver"); |
| 1334 | |