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 | |
Borislav Petkov | fc6c5bc | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 18 | #define IDEFLOPPY_VERSION "1.00" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/module.h> |
| 21 | #include <linux/types.h> |
| 22 | #include <linux/string.h> |
| 23 | #include <linux/kernel.h> |
| 24 | #include <linux/delay.h> |
| 25 | #include <linux/timer.h> |
| 26 | #include <linux/mm.h> |
| 27 | #include <linux/interrupt.h> |
| 28 | #include <linux/major.h> |
| 29 | #include <linux/errno.h> |
| 30 | #include <linux/genhd.h> |
| 31 | #include <linux/slab.h> |
| 32 | #include <linux/cdrom.h> |
| 33 | #include <linux/ide.h> |
| 34 | #include <linux/bitops.h> |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 35 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Bartlomiej Zolnierkiewicz | 89636af | 2007-07-20 01:11:59 +0200 | [diff] [blame] | 37 | #include <scsi/scsi_ioctl.h> |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <asm/byteorder.h> |
Borislav Petkov | 7e8b163 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 40 | #include <linux/irq.h> |
| 41 | #include <linux/uaccess.h> |
| 42 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <asm/unaligned.h> |
| 44 | |
Borislav Petkov | f373bd8 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 45 | /* define to see debug info */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | #define IDEFLOPPY_DEBUG_LOG 0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
| 48 | /* #define IDEFLOPPY_DEBUG(fmt, args...) printk(KERN_INFO fmt, ## args) */ |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 49 | #define IDEFLOPPY_DEBUG(fmt, args...) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | |
| 51 | #if IDEFLOPPY_DEBUG_LOG |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 52 | #define debug_log(fmt, args...) \ |
| 53 | printk(KERN_INFO "ide-floppy: " fmt, ## args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | #else |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 55 | #define debug_log(fmt, args...) do {} while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | #endif |
| 57 | |
| 58 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 59 | /* Some drives require a longer irq timeout. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #define IDEFLOPPY_WAIT_CMD (5 * WAIT_CMD) |
| 61 | |
| 62 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 63 | * After each failed packet command we issue a request sense command and retry |
| 64 | * the packet command IDEFLOPPY_MAX_PC_RETRIES times. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | */ |
| 66 | #define IDEFLOPPY_MAX_PC_RETRIES 3 |
| 67 | |
| 68 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 69 | * With each packet command, we allocate a buffer of IDEFLOPPY_PC_BUFFER_SIZE |
| 70 | * bytes. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | */ |
| 72 | #define IDEFLOPPY_PC_BUFFER_SIZE 256 |
| 73 | |
| 74 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 75 | * In various places in the driver, we need to allocate storage for packet |
| 76 | * commands and requests, which will remain valid while we leave the driver to |
| 77 | * wait for an interrupt or a timeout event. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | */ |
| 79 | #define IDEFLOPPY_PC_STACK (10 + IDEFLOPPY_MAX_PC_RETRIES) |
| 80 | |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 81 | /* Packet command flag bits. */ |
| 82 | enum { |
| 83 | /* 1 when we prefer to use DMA if possible */ |
| 84 | PC_FLAG_DMA_RECOMMENDED = (1 << 0), |
| 85 | /* 1 while DMA in progress */ |
| 86 | PC_FLAG_DMA_IN_PROGRESS = (1 << 1), |
| 87 | /* 1 when encountered problem during DMA */ |
| 88 | PC_FLAG_DMA_ERROR = (1 << 2), |
| 89 | /* Data direction */ |
| 90 | PC_FLAG_WRITING = (1 << 3), |
| 91 | /* Suppress error reporting */ |
| 92 | PC_FLAG_SUPPRESS_ERROR = (1 << 4), |
| 93 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 95 | /* format capacities descriptor codes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | #define CAPACITY_INVALID 0x00 |
| 97 | #define CAPACITY_UNFORMATTED 0x01 |
| 98 | #define CAPACITY_CURRENT 0x02 |
| 99 | #define CAPACITY_NO_CARTRIDGE 0x03 |
| 100 | |
| 101 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 102 | * Most of our global data which we need to save even as we leave the driver |
| 103 | * due to an interrupt or a timer event is stored in a variable of type |
| 104 | * idefloppy_floppy_t, defined below. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | */ |
| 106 | typedef struct ide_floppy_obj { |
| 107 | ide_drive_t *drive; |
| 108 | ide_driver_t *driver; |
| 109 | struct gendisk *disk; |
| 110 | struct kref kref; |
Bartlomiej Zolnierkiewicz | c94964a | 2007-02-17 02:40:24 +0100 | [diff] [blame] | 111 | unsigned int openers; /* protected by BKL for now */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
| 113 | /* Current packet command */ |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 114 | struct ide_atapi_pc *pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | /* Last failed packet command */ |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 116 | struct ide_atapi_pc *failed_pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | /* Packet command stack */ |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 118 | struct ide_atapi_pc pc_stack[IDEFLOPPY_PC_STACK]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | /* Next free packet command storage space */ |
| 120 | int pc_stack_index; |
| 121 | struct request rq_stack[IDEFLOPPY_PC_STACK]; |
| 122 | /* We implement a circular array */ |
| 123 | int rq_stack_index; |
| 124 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 125 | /* Last error information */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | u8 sense_key, asc, ascq; |
| 127 | /* delay this long before sending packet command */ |
| 128 | u8 ticks; |
| 129 | int progress_indication; |
| 130 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 131 | /* Device information */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | /* Current format */ |
| 133 | int blocks, block_size, bs_factor; |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 134 | /* Last format capacity descriptor */ |
| 135 | u8 cap_desc[8]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | /* Copy of the flexible disk page */ |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 137 | u8 flexible_disk_page[32]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | /* Write protect */ |
| 139 | int wp; |
| 140 | /* Supports format progress report */ |
| 141 | int srfp; |
| 142 | /* Status/Action flags */ |
| 143 | unsigned long flags; |
| 144 | } idefloppy_floppy_t; |
| 145 | |
Bartlomiej Zolnierkiewicz | c40d3d3 | 2005-08-18 22:09:21 +0200 | [diff] [blame] | 146 | #define IDEFLOPPY_TICKS_DELAY HZ/20 /* default delay for ZIP 100 (50ms) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 148 | /* Floppy flag bits values. */ |
| 149 | enum { |
| 150 | /* DRQ interrupt device */ |
| 151 | IDEFLOPPY_FLAG_DRQ_INTERRUPT = (1 << 0), |
| 152 | /* Media may have changed */ |
| 153 | IDEFLOPPY_FLAG_MEDIA_CHANGED = (1 << 1), |
| 154 | /* Format in progress */ |
| 155 | IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS = (1 << 2), |
| 156 | /* Avoid commands not supported in Clik drive */ |
| 157 | IDEFLOPPY_FLAG_CLIK_DRIVE = (1 << 3), |
| 158 | /* Requires BH algorithm for packets */ |
| 159 | IDEFLOPPY_FLAG_ZIP_DRIVE = (1 << 4), |
| 160 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 162 | /* Defines for the MODE SENSE command */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | #define MODE_SENSE_CURRENT 0x00 |
| 164 | #define MODE_SENSE_CHANGEABLE 0x01 |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 165 | #define MODE_SENSE_DEFAULT 0x02 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | #define MODE_SENSE_SAVED 0x03 |
| 167 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 168 | /* IOCTLs used in low-level formatting. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | #define IDEFLOPPY_IOCTL_FORMAT_SUPPORTED 0x4600 |
| 170 | #define IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY 0x4601 |
| 171 | #define IDEFLOPPY_IOCTL_FORMAT_START 0x4602 |
| 172 | #define IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS 0x4603 |
| 173 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 174 | /* 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] | 175 | #define IDEFLOPPY_ERROR_GENERAL 101 |
| 176 | |
| 177 | /* |
Borislav Petkov | 948391d | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 178 | * Pages of the SELECT SENSE / MODE SENSE packet commands. |
| 179 | * See SFF-8070i spec. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | */ |
| 181 | #define IDEFLOPPY_CAPABILITIES_PAGE 0x1b |
| 182 | #define IDEFLOPPY_FLEXIBLE_DISK_PAGE 0x05 |
| 183 | |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 184 | static DEFINE_MUTEX(idefloppy_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | |
| 186 | #define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref) |
| 187 | |
| 188 | #define ide_floppy_g(disk) \ |
| 189 | container_of((disk)->private_data, struct ide_floppy_obj, driver) |
| 190 | |
| 191 | static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk) |
| 192 | { |
| 193 | struct ide_floppy_obj *floppy = NULL; |
| 194 | |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 195 | mutex_lock(&idefloppy_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | floppy = ide_floppy_g(disk); |
| 197 | if (floppy) |
| 198 | kref_get(&floppy->kref); |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 199 | mutex_unlock(&idefloppy_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | return floppy; |
| 201 | } |
| 202 | |
Borislav Petkov | 9a24b63 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 203 | static void idefloppy_cleanup_obj(struct kref *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
| 205 | static void ide_floppy_put(struct ide_floppy_obj *floppy) |
| 206 | { |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 207 | mutex_lock(&idefloppy_ref_mutex); |
Borislav Petkov | 9a24b63 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 208 | kref_put(&floppy->kref, idefloppy_cleanup_obj); |
Arjan van de Ven | cf8b897 | 2006-03-23 03:00:45 -0800 | [diff] [blame] | 209 | mutex_unlock(&idefloppy_ref_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | } |
| 211 | |
| 212 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 213 | * Used to finish servicing a request. For read/write requests, we will call |
| 214 | * ide_end_request to pass to the next buffer. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | */ |
| 216 | static int idefloppy_do_end_request(ide_drive_t *drive, int uptodate, int nsecs) |
| 217 | { |
| 218 | idefloppy_floppy_t *floppy = drive->driver_data; |
| 219 | struct request *rq = HWGROUP(drive)->rq; |
| 220 | int error; |
| 221 | |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 222 | debug_log("Reached %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
| 224 | switch (uptodate) { |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 225 | case 0: error = IDEFLOPPY_ERROR_GENERAL; break; |
| 226 | case 1: error = 0; break; |
| 227 | default: error = uptodate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | } |
| 229 | if (error) |
| 230 | floppy->failed_pc = NULL; |
| 231 | /* Why does this happen? */ |
| 232 | if (!rq) |
| 233 | return 0; |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 234 | if (!blk_special_request(rq)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | /* our real local end request function */ |
| 236 | ide_end_request(drive, uptodate, nsecs); |
| 237 | return 0; |
| 238 | } |
| 239 | rq->errors = error; |
| 240 | /* fixme: need to move this local also */ |
| 241 | ide_end_drive_cmd(drive, 0, 0); |
| 242 | return 0; |
| 243 | } |
| 244 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 245 | static void ide_floppy_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc, |
Borislav Petkov | 32925e1 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 246 | unsigned int bcount, int direction) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
| 248 | struct request *rq = pc->rq; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 249 | struct req_iterator iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | struct bio_vec *bvec; |
| 251 | unsigned long flags; |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 252 | int count, done = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | char *data; |
| 254 | |
NeilBrown | 5705f70 | 2007-09-25 12:35:59 +0200 | [diff] [blame] | 255 | rq_for_each_segment(bvec, rq, iter) { |
Jens Axboe | 6c92e69 | 2007-08-16 13:43:12 +0200 | [diff] [blame] | 256 | if (!bcount) |
| 257 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
Jens Axboe | 6c92e69 | 2007-08-16 13:43:12 +0200 | [diff] [blame] | 259 | count = min(bvec->bv_len, bcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
Jens Axboe | 6c92e69 | 2007-08-16 13:43:12 +0200 | [diff] [blame] | 261 | data = bvec_kmap_irq(bvec, &flags); |
Borislav Petkov | 32925e1 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 262 | if (direction) |
| 263 | drive->hwif->atapi_output_bytes(drive, data, count); |
| 264 | else |
| 265 | drive->hwif->atapi_input_bytes(drive, data, count); |
Jens Axboe | 6c92e69 | 2007-08-16 13:43:12 +0200 | [diff] [blame] | 266 | bvec_kunmap_irq(data, &flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | |
Jens Axboe | 6c92e69 | 2007-08-16 13:43:12 +0200 | [diff] [blame] | 268 | bcount -= count; |
| 269 | pc->b_count += count; |
| 270 | done += count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | idefloppy_do_end_request(drive, 1, done >> 9); |
| 274 | |
| 275 | if (bcount) { |
Borislav Petkov | 32925e1 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 276 | printk(KERN_ERR "%s: leftover data in %s, bcount == %d\n", |
| 277 | drive->name, __func__, bcount); |
| 278 | if (direction) |
Bartlomiej Zolnierkiewicz | 7616c0a | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 279 | ide_atapi_write_zeros(drive, bcount); |
Borislav Petkov | 32925e1 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 280 | else |
Bartlomiej Zolnierkiewicz | 7616c0a | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 281 | ide_atapi_discard_data(drive, bcount); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 285 | static void idefloppy_update_buffers(ide_drive_t *drive, |
| 286 | struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | { |
| 288 | struct request *rq = pc->rq; |
| 289 | struct bio *bio = rq->bio; |
| 290 | |
| 291 | while ((bio = rq->bio) != NULL) |
| 292 | idefloppy_do_end_request(drive, 1, 0); |
| 293 | } |
| 294 | |
| 295 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 296 | * Generate a new packet command request in front of the request queue, before |
| 297 | * the current request so that it will be processed immediately, on the next |
| 298 | * pass through the driver. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | */ |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 300 | static void idefloppy_queue_pc_head(ide_drive_t *drive, struct ide_atapi_pc *pc, |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 301 | struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | { |
| 303 | struct ide_floppy_obj *floppy = drive->driver_data; |
| 304 | |
| 305 | ide_init_drive_cmd(rq); |
| 306 | rq->buffer = (char *) pc; |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 307 | rq->cmd_type = REQ_TYPE_SPECIAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | rq->rq_disk = floppy->disk; |
| 309 | (void) ide_do_drive_cmd(drive, rq, ide_preempt); |
| 310 | } |
| 311 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 312 | static struct ide_atapi_pc *idefloppy_next_pc_storage(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | { |
| 314 | idefloppy_floppy_t *floppy = drive->driver_data; |
| 315 | |
| 316 | if (floppy->pc_stack_index == IDEFLOPPY_PC_STACK) |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 317 | floppy->pc_stack_index = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | return (&floppy->pc_stack[floppy->pc_stack_index++]); |
| 319 | } |
| 320 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 321 | static struct request *idefloppy_next_rq_storage(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | { |
| 323 | idefloppy_floppy_t *floppy = drive->driver_data; |
| 324 | |
| 325 | if (floppy->rq_stack_index == IDEFLOPPY_PC_STACK) |
| 326 | floppy->rq_stack_index = 0; |
| 327 | return (&floppy->rq_stack[floppy->rq_stack_index++]); |
| 328 | } |
| 329 | |
Borislav Petkov | a6ff2d3 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 330 | static void idefloppy_request_sense_callback(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | { |
| 332 | idefloppy_floppy_t *floppy = drive->driver_data; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 333 | u8 *buf = floppy->pc->buf; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 335 | debug_log("Reached %s\n", __func__); |
| 336 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | if (!floppy->pc->error) { |
Borislav Petkov | a6ff2d3 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 338 | floppy->sense_key = buf[2] & 0x0F; |
| 339 | floppy->asc = buf[12]; |
| 340 | floppy->ascq = buf[13]; |
| 341 | floppy->progress_indication = buf[15] & 0x80 ? |
| 342 | (u16)get_unaligned((u16 *)&buf[16]) : 0x10000; |
| 343 | |
| 344 | if (floppy->failed_pc) |
| 345 | debug_log("pc = %x, sense key = %x, asc = %x," |
| 346 | " ascq = %x\n", |
| 347 | floppy->failed_pc->c[0], |
| 348 | floppy->sense_key, |
| 349 | floppy->asc, |
| 350 | floppy->ascq); |
| 351 | else |
| 352 | debug_log("sense key = %x, asc = %x, ascq = %x\n", |
| 353 | floppy->sense_key, |
| 354 | floppy->asc, |
| 355 | floppy->ascq); |
| 356 | |
| 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | idefloppy_do_end_request(drive, 1, 0); |
| 359 | } else { |
Borislav Petkov | a6ff2d3 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 360 | printk(KERN_ERR "Error in REQUEST SENSE itself - Aborting" |
| 361 | " request!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | idefloppy_do_end_request(drive, 0, 0); |
| 363 | } |
| 364 | } |
| 365 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 366 | /* General packet command callback function. */ |
| 367 | static void idefloppy_pc_callback(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | { |
| 369 | idefloppy_floppy_t *floppy = drive->driver_data; |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 370 | |
| 371 | debug_log("Reached %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
| 373 | idefloppy_do_end_request(drive, floppy->pc->error ? 0 : 1, 0); |
| 374 | } |
| 375 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 376 | static void idefloppy_init_pc(struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | { |
| 378 | memset(pc->c, 0, 12); |
| 379 | pc->retries = 0; |
| 380 | pc->flags = 0; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 381 | pc->req_xfer = 0; |
| 382 | pc->buf = pc->pc_buf; |
| 383 | pc->buf_size = IDEFLOPPY_PC_BUFFER_SIZE; |
| 384 | pc->idefloppy_callback = &idefloppy_pc_callback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | } |
| 386 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 387 | static void idefloppy_create_request_sense_cmd(struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | { |
Borislav Petkov | 30d6709 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 389 | idefloppy_init_pc(pc); |
| 390 | pc->c[0] = GPCMD_REQUEST_SENSE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | pc->c[4] = 255; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 392 | pc->req_xfer = 18; |
| 393 | pc->idefloppy_callback = &idefloppy_request_sense_callback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 397 | * Called when an error was detected during the last packet command. We queue a |
| 398 | * request sense packet command in the head of the request list. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | */ |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 400 | static void idefloppy_retry_pc(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | { |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 402 | struct ide_atapi_pc *pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | struct request *rq; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | |
Bartlomiej Zolnierkiewicz | 64a57fe | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 405 | (void)ide_read_error(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | pc = idefloppy_next_pc_storage(drive); |
| 407 | rq = idefloppy_next_rq_storage(drive); |
| 408 | idefloppy_create_request_sense_cmd(pc); |
| 409 | idefloppy_queue_pc_head(drive, pc, rq); |
| 410 | } |
| 411 | |
Borislav Petkov | 0eea645 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 412 | /* The usual interrupt handler called during a packet command. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | static ide_startstop_t idefloppy_pc_intr (ide_drive_t *drive) |
| 414 | { |
| 415 | idefloppy_floppy_t *floppy = drive->driver_data; |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 416 | ide_hwif_t *hwif = drive->hwif; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 417 | struct ide_atapi_pc *pc = floppy->pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | struct request *rq = pc->rq; |
Borislav Petkov | 0eea645 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 419 | xfer_func_t *xferfunc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | unsigned int temp; |
Borislav Petkov | d30a7fb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 421 | int dma_error = 0; |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 422 | u16 bcount; |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 423 | u8 stat, ireason; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 425 | debug_log("Reached %s interrupt handler\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 427 | if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) { |
Borislav Petkov | d30a7fb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 428 | dma_error = hwif->ide_dma_end(drive); |
| 429 | if (dma_error) { |
| 430 | printk(KERN_ERR "%s: DMA %s error\n", drive->name, |
| 431 | rq_data_dir(rq) ? "write" : "read"); |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 432 | pc->flags |= PC_FLAG_DMA_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | } else { |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 434 | pc->xferred = pc->req_xfer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | idefloppy_update_buffers(drive, pc); |
| 436 | } |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 437 | debug_log("DMA finished\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | /* Clear the interrupt */ |
Bartlomiej Zolnierkiewicz | c47137a | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 441 | stat = ide_read_status(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 443 | /* No more interrupts */ |
| 444 | if ((stat & DRQ_STAT) == 0) { |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 445 | debug_log("Packet command completed, %d bytes transferred\n", |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 446 | pc->xferred); |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 447 | pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
Ingo Molnar | 366c7f5 | 2006-07-03 00:25:25 -0700 | [diff] [blame] | 449 | local_irq_enable_in_hardirq(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 451 | if ((stat & ERR_STAT) || (pc->flags & PC_FLAG_DMA_ERROR)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | /* Error detected */ |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 453 | debug_log("%s: I/O error\n", drive->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | rq->errors++; |
Borislav Petkov | 30d6709 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 455 | if (pc->c[0] == GPCMD_REQUEST_SENSE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | printk(KERN_ERR "ide-floppy: I/O error in " |
| 457 | "request sense command\n"); |
| 458 | return ide_do_reset(drive); |
| 459 | } |
| 460 | /* Retry operation */ |
| 461 | idefloppy_retry_pc(drive); |
| 462 | /* queued, but not started */ |
| 463 | return ide_stopped; |
| 464 | } |
| 465 | pc->error = 0; |
| 466 | if (floppy->failed_pc == pc) |
| 467 | floppy->failed_pc = NULL; |
| 468 | /* Command finished - Call the callback function */ |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 469 | pc->idefloppy_callback(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | return ide_stopped; |
| 471 | } |
| 472 | |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 473 | if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) { |
| 474 | pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | printk(KERN_ERR "ide-floppy: The floppy wants to issue " |
| 476 | "more interrupts in DMA mode\n"); |
Bartlomiej Zolnierkiewicz | 7469aaf | 2007-02-17 02:40:26 +0100 | [diff] [blame] | 477 | ide_dma_off(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | return ide_do_reset(drive); |
| 479 | } |
| 480 | |
| 481 | /* Get the number of bytes to transfer */ |
Bartlomiej Zolnierkiewicz | 23579a2 | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 482 | bcount = (hwif->INB(hwif->io_ports[IDE_BCOUNTH_OFFSET]) << 8) | |
| 483 | hwif->INB(hwif->io_ports[IDE_BCOUNTL_OFFSET]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | /* on this interrupt */ |
Bartlomiej Zolnierkiewicz | 23579a2 | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 485 | ireason = hwif->INB(hwif->io_ports[IDE_IREASON_OFFSET]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 487 | if (ireason & CD) { |
Borislav Petkov | 0eea645 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 488 | printk(KERN_ERR "ide-floppy: CoD != 0 in %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | return ide_do_reset(drive); |
| 490 | } |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 491 | if (((ireason & IO) == IO) == !!(pc->flags & PC_FLAG_WRITING)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | /* Hopefully, we will never get here */ |
| 493 | printk(KERN_ERR "ide-floppy: We wanted to %s, ", |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 494 | (ireason & IO) ? "Write" : "Read"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | printk(KERN_ERR "but the floppy wants us to %s !\n", |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 496 | (ireason & IO) ? "Read" : "Write"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | return ide_do_reset(drive); |
| 498 | } |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 499 | if (!(pc->flags & PC_FLAG_WRITING)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | /* Reading - Check that we have enough space */ |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 501 | temp = pc->xferred + bcount; |
| 502 | if (temp > pc->req_xfer) { |
| 503 | if (temp > pc->buf_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | printk(KERN_ERR "ide-floppy: The floppy wants " |
| 505 | "to send us more data than expected " |
| 506 | "- discarding data\n"); |
Bartlomiej Zolnierkiewicz | 7616c0a | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 507 | ide_atapi_discard_data(drive, bcount); |
Borislav Petkov | 0078df2 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | ide_set_handler(drive, |
| 510 | &idefloppy_pc_intr, |
| 511 | IDEFLOPPY_WAIT_CMD, |
| 512 | NULL); |
| 513 | return ide_started; |
| 514 | } |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 515 | debug_log("The floppy wants to send us more data than" |
| 516 | " expected - allowing transfer\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | } |
| 518 | } |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 519 | if (pc->flags & PC_FLAG_WRITING) |
Borislav Petkov | 0eea645 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 520 | xferfunc = hwif->atapi_output_bytes; |
Borislav Petkov | 32925e1 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 521 | else |
Borislav Petkov | 0eea645 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 522 | xferfunc = hwif->atapi_input_bytes; |
Borislav Petkov | 0eea645 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 523 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 524 | if (pc->buf) |
| 525 | xferfunc(drive, pc->cur_pos, bcount); |
Borislav Petkov | 0eea645 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 526 | else |
Borislav Petkov | 32925e1 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 527 | ide_floppy_io_buffers(drive, pc, bcount, |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 528 | !!(pc->flags & PC_FLAG_WRITING)); |
Borislav Petkov | 0eea645 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | /* Update the current position */ |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 531 | pc->xferred += bcount; |
| 532 | pc->cur_pos += bcount; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
Borislav Petkov | 32925e1 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 534 | /* And set the interrupt handler again */ |
| 535 | ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | return ide_started; |
| 537 | } |
| 538 | |
| 539 | /* |
| 540 | * This is the original routine that did the packet transfer. |
| 541 | * It fails at high speeds on the Iomega ZIP drive, so there's a slower version |
| 542 | * for that drive below. The algorithm is chosen based on drive type |
| 543 | */ |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 544 | static ide_startstop_t idefloppy_transfer_pc(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | { |
Bartlomiej Zolnierkiewicz | 23579a2 | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 546 | ide_hwif_t *hwif = drive->hwif; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | ide_startstop_t startstop; |
| 548 | idefloppy_floppy_t *floppy = drive->driver_data; |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 549 | u8 ireason; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | |
| 551 | if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) { |
| 552 | printk(KERN_ERR "ide-floppy: Strange, packet command " |
| 553 | "initiated yet DRQ isn't asserted\n"); |
| 554 | return startstop; |
| 555 | } |
Bartlomiej Zolnierkiewicz | 23579a2 | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 556 | ireason = hwif->INB(hwif->io_ports[IDE_IREASON_OFFSET]); |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 557 | if ((ireason & CD) == 0 || (ireason & IO)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | printk(KERN_ERR "ide-floppy: (IO,CoD) != (0,1) while " |
| 559 | "issuing a packet command\n"); |
| 560 | return ide_do_reset(drive); |
| 561 | } |
Borislav Petkov | 0078df2 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | /* Set the interrupt routine */ |
| 564 | ide_set_handler(drive, &idefloppy_pc_intr, IDEFLOPPY_WAIT_CMD, NULL); |
| 565 | /* Send the actual packet */ |
| 566 | HWIF(drive)->atapi_output_bytes(drive, floppy->pc->c, 12); |
| 567 | return ide_started; |
| 568 | } |
| 569 | |
| 570 | |
| 571 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 572 | * What we have here is a classic case of a top half / bottom half interrupt |
| 573 | * service routine. In interrupt mode, the device sends an interrupt to signal |
| 574 | * that it is ready to receive a packet. However, we need to delay about 2-3 |
| 575 | * ticks before issuing the packet or we gets in trouble. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | * |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 577 | * So, follow carefully. transfer_pc1 is called as an interrupt (or directly). |
| 578 | * In either case, when the device says it's ready for a packet, we schedule |
| 579 | * the packet transfer to occur about 2-3 ticks later in transfer_pc2. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | */ |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 581 | static int idefloppy_transfer_pc2(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | { |
| 583 | idefloppy_floppy_t *floppy = drive->driver_data; |
| 584 | |
| 585 | /* Send the actual packet */ |
| 586 | HWIF(drive)->atapi_output_bytes(drive, floppy->pc->c, 12); |
| 587 | /* Timeout for the packet command */ |
| 588 | return IDEFLOPPY_WAIT_CMD; |
| 589 | } |
| 590 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 591 | static ide_startstop_t idefloppy_transfer_pc1(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | { |
Bartlomiej Zolnierkiewicz | 23579a2 | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 593 | ide_hwif_t *hwif = drive->hwif; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | idefloppy_floppy_t *floppy = drive->driver_data; |
| 595 | ide_startstop_t startstop; |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 596 | u8 ireason; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
| 598 | if (ide_wait_stat(&startstop, drive, DRQ_STAT, BUSY_STAT, WAIT_READY)) { |
| 599 | printk(KERN_ERR "ide-floppy: Strange, packet command " |
| 600 | "initiated yet DRQ isn't asserted\n"); |
| 601 | return startstop; |
| 602 | } |
Bartlomiej Zolnierkiewicz | 23579a2 | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 603 | ireason = hwif->INB(hwif->io_ports[IDE_IREASON_OFFSET]); |
Bartlomiej Zolnierkiewicz | 8e7657a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 604 | if ((ireason & CD) == 0 || (ireason & IO)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | printk(KERN_ERR "ide-floppy: (IO,CoD) != (0,1) " |
| 606 | "while issuing a packet command\n"); |
| 607 | return ide_do_reset(drive); |
| 608 | } |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 609 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | * The following delay solves a problem with ATAPI Zip 100 drives |
| 611 | * where the Busy flag was apparently being deasserted before the |
| 612 | * unit was ready to receive data. This was happening on a |
| 613 | * 1200 MHz Athlon system. 10/26/01 25msec is too short, |
| 614 | * 40 and 50msec work well. idefloppy_pc_intr will not be actually |
| 615 | * used until after the packet is moved in about 50 msec. |
| 616 | */ |
Borislav Petkov | 0078df2 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 617 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 618 | ide_set_handler(drive, &idefloppy_pc_intr, floppy->ticks, |
| 619 | &idefloppy_transfer_pc2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | return ide_started; |
| 621 | } |
| 622 | |
Borislav Petkov | d652c13 | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 623 | static void ide_floppy_report_error(idefloppy_floppy_t *floppy, |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 624 | struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | { |
Borislav Petkov | d652c13 | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 626 | /* supress error messages resulting from Medium not present */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | if (floppy->sense_key == 0x02 && |
| 628 | floppy->asc == 0x3a && |
| 629 | floppy->ascq == 0x00) |
Borislav Petkov | d652c13 | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 630 | return; |
| 631 | |
| 632 | printk(KERN_ERR "ide-floppy: %s: I/O error, pc = %2x, key = %2x, " |
| 633 | "asc = %2x, ascq = %2x\n", |
| 634 | floppy->drive->name, pc->c[0], floppy->sense_key, |
| 635 | floppy->asc, floppy->ascq); |
| 636 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | } |
| 638 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 639 | static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive, |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 640 | struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | { |
| 642 | idefloppy_floppy_t *floppy = drive->driver_data; |
| 643 | ide_hwif_t *hwif = drive->hwif; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | ide_handler_t *pkt_xfer_routine; |
Bartlomiej Zolnierkiewicz | 790d123 | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 645 | u16 bcount; |
Bartlomiej Zolnierkiewicz | e5f9f5a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 646 | u8 dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | if (floppy->failed_pc == NULL && |
Borislav Petkov | 30d6709 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 649 | pc->c[0] != GPCMD_REQUEST_SENSE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | floppy->failed_pc = pc; |
| 651 | /* Set the current packet command */ |
| 652 | floppy->pc = pc; |
| 653 | |
Borislav Petkov | 757ced8 | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 654 | if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) { |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 655 | if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR)) |
Borislav Petkov | 757ced8 | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 656 | ide_floppy_report_error(floppy, pc); |
| 657 | /* Giving up */ |
| 658 | pc->error = IDEFLOPPY_ERROR_GENERAL; |
| 659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | floppy->failed_pc = NULL; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 661 | pc->idefloppy_callback(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | return ide_stopped; |
| 663 | } |
| 664 | |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 665 | debug_log("Retry number - %d\n", pc->retries); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
| 667 | pc->retries++; |
| 668 | /* We haven't transferred any data yet */ |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 669 | pc->xferred = 0; |
| 670 | pc->cur_pos = pc->buf; |
| 671 | bcount = min(pc->req_xfer, 63 * 1024); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 673 | if (pc->flags & PC_FLAG_DMA_ERROR) { |
| 674 | pc->flags &= ~PC_FLAG_DMA_ERROR; |
Bartlomiej Zolnierkiewicz | 7469aaf | 2007-02-17 02:40:26 +0100 | [diff] [blame] | 675 | ide_dma_off(drive); |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 676 | } |
Bartlomiej Zolnierkiewicz | e5f9f5a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 677 | dma = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 679 | if ((pc->flags & PC_FLAG_DMA_RECOMMENDED) && drive->using_dma) |
Bartlomiej Zolnierkiewicz | e5f9f5a | 2008-01-25 22:17:12 +0100 | [diff] [blame] | 680 | dma = !hwif->dma_setup(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | |
Bartlomiej Zolnierkiewicz | 2fc5738 | 2008-01-25 22:17:13 +0100 | [diff] [blame] | 682 | ide_pktcmd_tf_load(drive, IDE_TFLAG_NO_SELECT_MASK | |
| 683 | IDE_TFLAG_OUT_DEVICE, bcount, dma); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 685 | if (dma) { |
| 686 | /* Begin DMA, if necessary */ |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 687 | pc->flags |= PC_FLAG_DMA_IN_PROGRESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | hwif->dma_start(drive); |
| 689 | } |
| 690 | |
| 691 | /* Can we transfer the packet when we get the interrupt or wait? */ |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 692 | if (floppy->flags & IDEFLOPPY_FLAG_ZIP_DRIVE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | /* wait */ |
| 694 | pkt_xfer_routine = &idefloppy_transfer_pc1; |
| 695 | } else { |
| 696 | /* immediate */ |
| 697 | pkt_xfer_routine = &idefloppy_transfer_pc; |
| 698 | } |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 699 | |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 700 | if (floppy->flags & IDEFLOPPY_FLAG_DRQ_INTERRUPT) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | /* Issue the packet command */ |
| 702 | ide_execute_command(drive, WIN_PACKETCMD, |
| 703 | pkt_xfer_routine, |
| 704 | IDEFLOPPY_WAIT_CMD, |
| 705 | NULL); |
| 706 | return ide_started; |
| 707 | } else { |
| 708 | /* Issue the packet command */ |
Bartlomiej Zolnierkiewicz | 23579a2 | 2008-04-18 00:46:26 +0200 | [diff] [blame] | 709 | hwif->OUTB(WIN_PACKETCMD, hwif->io_ports[IDE_COMMAND_OFFSET]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 | return (*pkt_xfer_routine) (drive); |
| 711 | } |
| 712 | } |
| 713 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 714 | static void idefloppy_rw_callback(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | { |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 716 | debug_log("Reached %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | |
| 718 | idefloppy_do_end_request(drive, 1, 0); |
| 719 | return; |
| 720 | } |
| 721 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 722 | 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] | 723 | { |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 724 | debug_log("creating prevent removal command, prevent = %d\n", prevent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | |
| 726 | idefloppy_init_pc(pc); |
Borislav Petkov | 30d6709 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 727 | pc->c[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | pc->c[4] = prevent; |
| 729 | } |
| 730 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 731 | static void idefloppy_create_read_capacity_cmd(struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | { |
| 733 | idefloppy_init_pc(pc); |
Borislav Petkov | 30d6709 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 734 | pc->c[0] = GPCMD_READ_FORMAT_CAPACITIES; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | pc->c[7] = 255; |
| 736 | pc->c[8] = 255; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 737 | pc->req_xfer = 255; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | } |
| 739 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 740 | static void idefloppy_create_format_unit_cmd(struct ide_atapi_pc *pc, int b, |
| 741 | int l, int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | { |
| 743 | idefloppy_init_pc(pc); |
Borislav Petkov | 30d6709 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 744 | pc->c[0] = GPCMD_FORMAT_UNIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | pc->c[1] = 0x17; |
| 746 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 747 | memset(pc->buf, 0, 12); |
| 748 | pc->buf[1] = 0xA2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 749 | /* Default format list header, u8 1: FOV/DCRT/IMM bits set */ |
| 750 | |
| 751 | if (flags & 1) /* Verify bit on... */ |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 752 | pc->buf[1] ^= 0x20; /* ... turn off DCRT bit */ |
| 753 | pc->buf[3] = 8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 755 | put_unaligned(cpu_to_be32(b), (unsigned int *)(&pc->buf[4])); |
| 756 | put_unaligned(cpu_to_be32(l), (unsigned int *)(&pc->buf[8])); |
| 757 | pc->buf_size = 12; |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 758 | pc->flags |= PC_FLAG_WRITING; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | } |
| 760 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 761 | /* A mode sense command is used to "sense" floppy parameters. */ |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 762 | static void idefloppy_create_mode_sense_cmd(struct ide_atapi_pc *pc, |
| 763 | u8 page_code, u8 type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | { |
Borislav Petkov | 24a5d70 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 765 | u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */ |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 766 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | idefloppy_init_pc(pc); |
Borislav Petkov | 30d6709 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 768 | pc->c[0] = GPCMD_MODE_SENSE_10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | pc->c[1] = 0; |
| 770 | pc->c[2] = page_code + (type << 6); |
| 771 | |
| 772 | switch (page_code) { |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 773 | case IDEFLOPPY_CAPABILITIES_PAGE: |
| 774 | length += 12; |
| 775 | break; |
| 776 | case IDEFLOPPY_FLEXIBLE_DISK_PAGE: |
| 777 | length += 32; |
| 778 | break; |
| 779 | default: |
| 780 | printk(KERN_ERR "ide-floppy: unsupported page code " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | "in create_mode_sense_cmd\n"); |
| 782 | } |
Borislav Petkov | 8f62243 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 783 | put_unaligned(cpu_to_be16(length), (u16 *) &pc->c[7]); |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 784 | pc->req_xfer = length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | } |
| 786 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 787 | 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] | 788 | { |
| 789 | idefloppy_init_pc(pc); |
Borislav Petkov | 30d6709 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 790 | pc->c[0] = GPCMD_START_STOP_UNIT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | pc->c[4] = start; |
| 792 | } |
| 793 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 794 | static void idefloppy_create_test_unit_ready_cmd(struct ide_atapi_pc *pc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | { |
| 796 | idefloppy_init_pc(pc); |
Borislav Petkov | 30d6709 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 797 | pc->c[0] = GPCMD_TEST_UNIT_READY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | } |
| 799 | |
Borislav Petkov | ae7e8dd | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 800 | static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy, |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 801 | struct ide_atapi_pc *pc, struct request *rq, |
Borislav Petkov | ae7e8dd | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 802 | unsigned long sector) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | { |
| 804 | int block = sector / floppy->bs_factor; |
| 805 | int blocks = rq->nr_sectors / floppy->bs_factor; |
| 806 | int cmd = rq_data_dir(rq); |
| 807 | |
Borislav Petkov | ae7e8dd | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 808 | debug_log("create_rw10_cmd: block == %d, blocks == %d\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | block, blocks); |
| 810 | |
| 811 | idefloppy_init_pc(pc); |
Borislav Petkov | ae7e8dd | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 812 | pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10; |
| 813 | put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]); |
Borislav Petkov | 8f62243 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 814 | put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]); |
Borislav Petkov | ae7e8dd | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 815 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 816 | pc->idefloppy_callback = &idefloppy_rw_callback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | pc->rq = rq; |
| 818 | pc->b_count = cmd == READ ? 0 : rq->bio->bi_size; |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 819 | if (rq->cmd_flags & REQ_RW) |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 820 | pc->flags |= PC_FLAG_WRITING; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 821 | pc->buf = NULL; |
| 822 | pc->req_xfer = pc->buf_size = blocks * floppy->block_size; |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 823 | pc->flags |= PC_FLAG_DMA_RECOMMENDED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | } |
| 825 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 826 | static void idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy, |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 827 | struct ide_atapi_pc *pc, struct request *rq) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | idefloppy_init_pc(pc); |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 830 | pc->idefloppy_callback = &idefloppy_rw_callback; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | memcpy(pc->c, rq->cmd, sizeof(pc->c)); |
Jens Axboe | 3d6392c | 2007-07-09 12:38:05 +0200 | [diff] [blame] | 832 | pc->rq = rq; |
| 833 | pc->b_count = rq->data_len; |
| 834 | if (rq->data_len && rq_data_dir(rq) == WRITE) |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 835 | pc->flags |= PC_FLAG_WRITING; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 836 | pc->buf = rq->data; |
Jens Axboe | 3d6392c | 2007-07-09 12:38:05 +0200 | [diff] [blame] | 837 | if (rq->bio) |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 838 | pc->flags |= PC_FLAG_DMA_RECOMMENDED; |
Jens Axboe | 3d6392c | 2007-07-09 12:38:05 +0200 | [diff] [blame] | 839 | /* |
| 840 | * possibly problematic, doesn't look like ide-floppy correctly |
| 841 | * handled scattered requests if dma fails... |
| 842 | */ |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 843 | pc->req_xfer = pc->buf_size = rq->data_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | } |
| 845 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 846 | static ide_startstop_t idefloppy_do_request(ide_drive_t *drive, |
| 847 | struct request *rq, sector_t block_s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | { |
| 849 | idefloppy_floppy_t *floppy = drive->driver_data; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 850 | struct ide_atapi_pc *pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | unsigned long block = (unsigned long)block_s; |
| 852 | |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 853 | debug_log("dev: %s, cmd_type: %x, errors: %d\n", |
Randy Dunlap | 18cddac | 2006-06-25 05:48:56 -0700 | [diff] [blame] | 854 | rq->rq_disk ? rq->rq_disk->disk_name : "?", |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 855 | rq->cmd_type, rq->errors); |
| 856 | debug_log("sector: %ld, nr_sectors: %ld, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | "current_nr_sectors: %d\n", (long)rq->sector, |
| 858 | rq->nr_sectors, rq->current_nr_sectors); |
| 859 | |
| 860 | if (rq->errors >= ERROR_MAX) { |
Borislav Petkov | d652c13 | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 861 | if (floppy->failed_pc) |
| 862 | ide_floppy_report_error(floppy, floppy->failed_pc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | else |
| 864 | printk(KERN_ERR "ide-floppy: %s: I/O error\n", |
| 865 | drive->name); |
| 866 | idefloppy_do_end_request(drive, 0, 0); |
| 867 | return ide_stopped; |
| 868 | } |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 869 | if (blk_fs_request(rq)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | if (((long)rq->sector % floppy->bs_factor) || |
| 871 | (rq->nr_sectors % floppy->bs_factor)) { |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 872 | printk(KERN_ERR "%s: unsupported r/w request size\n", |
| 873 | drive->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | idefloppy_do_end_request(drive, 0, 0); |
| 875 | return ide_stopped; |
| 876 | } |
| 877 | pc = idefloppy_next_pc_storage(drive); |
| 878 | idefloppy_create_rw_cmd(floppy, pc, rq, block); |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 879 | } else if (blk_special_request(rq)) { |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 880 | pc = (struct ide_atapi_pc *) rq->buffer; |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 881 | } else if (blk_pc_request(rq)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | pc = idefloppy_next_pc_storage(drive); |
Jens Axboe | 3d6392c | 2007-07-09 12:38:05 +0200 | [diff] [blame] | 883 | idefloppy_blockpc_cmd(floppy, pc, rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | } else { |
| 885 | blk_dump_rq_flags(rq, |
| 886 | "ide-floppy: unsupported command in queue"); |
| 887 | idefloppy_do_end_request(drive, 0, 0); |
| 888 | return ide_stopped; |
| 889 | } |
| 890 | |
| 891 | pc->rq = rq; |
| 892 | return idefloppy_issue_pc(drive, pc); |
| 893 | } |
| 894 | |
| 895 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 896 | * Add a special packet command request to the tail of the request queue, |
| 897 | * and wait for it to be serviced. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | */ |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 899 | 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] | 900 | { |
| 901 | struct ide_floppy_obj *floppy = drive->driver_data; |
| 902 | struct request rq; |
| 903 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 904 | ide_init_drive_cmd(&rq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | rq.buffer = (char *) pc; |
Jens Axboe | 4aff5e2 | 2006-08-10 08:44:47 +0200 | [diff] [blame] | 906 | rq.cmd_type = REQ_TYPE_SPECIAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | rq.rq_disk = floppy->disk; |
| 908 | |
| 909 | return ide_do_drive_cmd(drive, &rq, ide_wait); |
| 910 | } |
| 911 | |
| 912 | /* |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 913 | * Look at the flexible disk page parameters. We ignore the CHS capacity |
| 914 | * parameters and use the LBA parameters instead. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 915 | */ |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 916 | static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | { |
| 918 | idefloppy_floppy_t *floppy = drive->driver_data; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 919 | struct ide_atapi_pc pc; |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 920 | u8 *page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | int capacity, lba_capacity; |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 922 | u16 transfer_rate, sector_size, cyls, rpm; |
| 923 | u8 heads, sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 925 | idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE, |
| 926 | MODE_SENSE_CURRENT); |
| 927 | |
| 928 | if (idefloppy_queue_pc_tail(drive, &pc)) { |
| 929 | printk(KERN_ERR "ide-floppy: Can't get flexible disk page" |
| 930 | " parameters\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | return 1; |
| 932 | } |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 933 | floppy->wp = !!(pc.buf[3] & 0x80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | set_disk_ro(floppy->disk, floppy->wp); |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 935 | page = &pc.buf[8]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 937 | transfer_rate = be16_to_cpu(*(u16 *)&pc.buf[8 + 2]); |
| 938 | sector_size = be16_to_cpu(*(u16 *)&pc.buf[8 + 6]); |
| 939 | cyls = be16_to_cpu(*(u16 *)&pc.buf[8 + 8]); |
| 940 | rpm = be16_to_cpu(*(u16 *)&pc.buf[8 + 28]); |
| 941 | heads = pc.buf[8 + 4]; |
| 942 | sectors = pc.buf[8 + 5]; |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 943 | |
| 944 | capacity = cyls * heads * sectors * sector_size; |
| 945 | |
| 946 | if (memcmp(page, &floppy->flexible_disk_page, 32)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | printk(KERN_INFO "%s: %dkB, %d/%d/%d CHS, %d kBps, " |
| 948 | "%d sector size, %d rpm\n", |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 949 | drive->name, capacity / 1024, cyls, heads, |
| 950 | sectors, transfer_rate / 8, sector_size, rpm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 952 | memcpy(&floppy->flexible_disk_page, page, 32); |
| 953 | drive->bios_cyl = cyls; |
| 954 | drive->bios_head = heads; |
| 955 | drive->bios_sect = sectors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | lba_capacity = floppy->blocks * floppy->block_size; |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 957 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | if (capacity < lba_capacity) { |
| 959 | printk(KERN_NOTICE "%s: The disk reports a capacity of %d " |
| 960 | "bytes, but the drive only handles %d\n", |
| 961 | drive->name, lba_capacity, capacity); |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 962 | floppy->blocks = floppy->block_size ? |
| 963 | capacity / floppy->block_size : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | } |
| 965 | return 0; |
| 966 | } |
| 967 | |
Borislav Petkov | 948391d | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 968 | static int idefloppy_get_sfrp_bit(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | { |
| 970 | idefloppy_floppy_t *floppy = drive->driver_data; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 971 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | |
| 973 | floppy->srfp = 0; |
| 974 | idefloppy_create_mode_sense_cmd(&pc, IDEFLOPPY_CAPABILITIES_PAGE, |
| 975 | MODE_SENSE_CURRENT); |
| 976 | |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 977 | pc.flags |= PC_FLAG_SUPPRESS_ERROR; |
Borislav Petkov | 948391d | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 978 | if (idefloppy_queue_pc_tail(drive, &pc)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 981 | floppy->srfp = pc.buf[8 + 2] & 0x40; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | return (0); |
| 983 | } |
| 984 | |
| 985 | /* |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 986 | * Determine if a media is present in the floppy drive, and if so, its LBA |
| 987 | * capacity. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | */ |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 989 | static int ide_floppy_get_capacity(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | { |
| 991 | idefloppy_floppy_t *floppy = drive->driver_data; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 992 | struct ide_atapi_pc pc; |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 993 | u8 *cap_desc; |
| 994 | u8 header_len, desc_cnt; |
| 995 | int i, rc = 1, blocks, length; |
| 996 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | drive->bios_cyl = 0; |
| 998 | drive->bios_head = drive->bios_sect = 0; |
Alan Cox | fdb77da | 2007-02-17 02:40:20 +0100 | [diff] [blame] | 999 | floppy->blocks = 0; |
| 1000 | floppy->bs_factor = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | set_capacity(floppy->disk, 0); |
| 1002 | |
| 1003 | idefloppy_create_read_capacity_cmd(&pc); |
| 1004 | if (idefloppy_queue_pc_tail(drive, &pc)) { |
| 1005 | printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); |
| 1006 | return 1; |
| 1007 | } |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1008 | header_len = pc.buf[3]; |
| 1009 | cap_desc = &pc.buf[4]; |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1010 | desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1012 | for (i = 0; i < desc_cnt; i++) { |
| 1013 | unsigned int desc_start = 4 + i*8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1015 | blocks = be32_to_cpu(*(u32 *)&pc.buf[desc_start]); |
| 1016 | length = be16_to_cpu(*(u16 *)&pc.buf[desc_start + 6]); |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1017 | |
| 1018 | debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n", |
| 1019 | i, blocks * length / 1024, blocks, length); |
| 1020 | |
| 1021 | if (i) |
| 1022 | continue; |
| 1023 | /* |
| 1024 | * the code below is valid only for the 1st descriptor, ie i=0 |
| 1025 | */ |
| 1026 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1027 | switch (pc.buf[desc_start + 4] & 0x03) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | /* Clik! drive returns this instead of CAPACITY_CURRENT */ |
| 1029 | case CAPACITY_UNFORMATTED: |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 1030 | if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE)) |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1031 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | * If it is not a clik drive, break out |
| 1033 | * (maintains previous driver behaviour) |
| 1034 | */ |
| 1035 | break; |
| 1036 | case CAPACITY_CURRENT: |
| 1037 | /* Normal Zip/LS-120 disks */ |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1038 | if (memcmp(cap_desc, &floppy->cap_desc, 8)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1039 | printk(KERN_INFO "%s: %dkB, %d blocks, %d " |
| 1040 | "sector size\n", drive->name, |
| 1041 | blocks * length / 1024, blocks, length); |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1042 | memcpy(&floppy->cap_desc, cap_desc, 8); |
| 1043 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | if (!length || length % 512) { |
| 1045 | printk(KERN_NOTICE "%s: %d bytes block size " |
| 1046 | "not supported\n", drive->name, length); |
| 1047 | } else { |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1048 | floppy->blocks = blocks; |
| 1049 | floppy->block_size = length; |
| 1050 | floppy->bs_factor = length / 512; |
| 1051 | if (floppy->bs_factor != 1) |
| 1052 | printk(KERN_NOTICE "%s: warning: non " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | "512 bytes block size not " |
| 1054 | "fully supported\n", |
| 1055 | drive->name); |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1056 | rc = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | } |
| 1058 | break; |
| 1059 | case CAPACITY_NO_CARTRIDGE: |
| 1060 | /* |
| 1061 | * This is a KERN_ERR so it appears on screen |
| 1062 | * for the user to see |
| 1063 | */ |
| 1064 | printk(KERN_ERR "%s: No disk in drive\n", drive->name); |
| 1065 | break; |
| 1066 | case CAPACITY_INVALID: |
| 1067 | printk(KERN_ERR "%s: Invalid capacity for disk " |
| 1068 | "in drive\n", drive->name); |
| 1069 | break; |
| 1070 | } |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1071 | debug_log("Descriptor 0 Code: %d\n", |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1072 | pc.buf[desc_start + 4] & 0x03); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | /* Clik! disk does not support get_flexible_disk_page */ |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 1076 | if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE)) |
Borislav Petkov | 8e81bbb | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1077 | (void) ide_floppy_get_flexible_disk_page(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | |
| 1079 | set_capacity(floppy->disk, floppy->blocks * floppy->bs_factor); |
| 1080 | return rc; |
| 1081 | } |
| 1082 | |
| 1083 | /* |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1084 | * Obtain the list of formattable capacities. |
| 1085 | * Very similar to ide_floppy_get_capacity, except that we push the capacity |
| 1086 | * descriptors to userland, instead of our own structures. |
| 1087 | * |
| 1088 | * Userland gives us the following structure: |
| 1089 | * |
| 1090 | * struct idefloppy_format_capacities { |
| 1091 | * int nformats; |
| 1092 | * struct { |
| 1093 | * int nblocks; |
| 1094 | * int blocksize; |
| 1095 | * } formats[]; |
| 1096 | * }; |
| 1097 | * |
| 1098 | * userland initializes nformats to the number of allocated formats[] records. |
| 1099 | * On exit we set nformats to the number of records we've actually initialized. |
| 1100 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1102 | 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] | 1103 | { |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1104 | struct ide_atapi_pc pc; |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1105 | u8 header_len, desc_cnt; |
| 1106 | int i, blocks, length, u_array_size, u_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1107 | int __user *argp; |
| 1108 | |
| 1109 | if (get_user(u_array_size, arg)) |
| 1110 | return (-EFAULT); |
| 1111 | |
| 1112 | if (u_array_size <= 0) |
| 1113 | return (-EINVAL); |
| 1114 | |
| 1115 | idefloppy_create_read_capacity_cmd(&pc); |
| 1116 | if (idefloppy_queue_pc_tail(drive, &pc)) { |
| 1117 | printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n"); |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1118 | return (-EIO); |
| 1119 | } |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1120 | header_len = pc.buf[3]; |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1121 | desc_cnt = header_len / 8; /* capacity descriptor of 8 bytes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | |
| 1123 | u_index = 0; |
| 1124 | argp = arg + 1; |
| 1125 | |
| 1126 | /* |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1127 | * We always skip the first capacity descriptor. That's the current |
| 1128 | * capacity. We are interested in the remaining descriptors, the |
| 1129 | * formattable capacities. |
| 1130 | */ |
| 1131 | for (i = 1; i < desc_cnt; i++) { |
| 1132 | unsigned int desc_start = 4 + i*8; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1134 | if (u_index >= u_array_size) |
| 1135 | break; /* User-supplied buffer too small */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1137 | blocks = be32_to_cpu(*(u32 *)&pc.buf[desc_start]); |
| 1138 | length = be16_to_cpu(*(u16 *)&pc.buf[desc_start + 6]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | |
| 1140 | if (put_user(blocks, argp)) |
| 1141 | return(-EFAULT); |
| 1142 | ++argp; |
| 1143 | |
| 1144 | if (put_user(length, argp)) |
| 1145 | return (-EFAULT); |
| 1146 | ++argp; |
| 1147 | |
| 1148 | ++u_index; |
| 1149 | } |
| 1150 | |
| 1151 | if (put_user(u_index, arg)) |
| 1152 | return (-EFAULT); |
| 1153 | return (0); |
| 1154 | } |
| 1155 | |
| 1156 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1157 | * Get ATAPI_FORMAT_UNIT progress indication. |
| 1158 | * |
| 1159 | * Userland gives a pointer to an int. The int is set to a progress |
| 1160 | * indicator 0-65536, with 65536=100%. |
| 1161 | * |
| 1162 | * If the drive does not support format progress indication, we just check |
| 1163 | * the dsc bit, and return either 0 or 65536. |
| 1164 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | |
| 1166 | static int idefloppy_get_format_progress(ide_drive_t *drive, int __user *arg) |
| 1167 | { |
| 1168 | idefloppy_floppy_t *floppy = drive->driver_data; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1169 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1170 | int progress_indication = 0x10000; |
| 1171 | |
| 1172 | if (floppy->srfp) { |
| 1173 | idefloppy_create_request_sense_cmd(&pc); |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1174 | if (idefloppy_queue_pc_tail(drive, &pc)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | return (-EIO); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | |
| 1177 | if (floppy->sense_key == 2 && |
| 1178 | floppy->asc == 4 && |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1179 | floppy->ascq == 4) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | progress_indication = floppy->progress_indication; |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1181 | |
| 1182 | /* Else assume format_unit has finished, and we're at 0x10000 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | unsigned long flags; |
Bartlomiej Zolnierkiewicz | 22c525b | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 1185 | u8 stat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
| 1187 | local_irq_save(flags); |
Bartlomiej Zolnierkiewicz | c47137a | 2008-02-06 02:57:51 +0100 | [diff] [blame] | 1188 | stat = ide_read_status(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | local_irq_restore(flags); |
| 1190 | |
Bartlomiej Zolnierkiewicz | 22c525b | 2008-01-25 22:17:11 +0100 | [diff] [blame] | 1191 | progress_indication = ((stat & SEEK_STAT) == 0) ? 0 : 0x10000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | } |
| 1193 | if (put_user(progress_indication, arg)) |
| 1194 | return (-EFAULT); |
| 1195 | |
| 1196 | return (0); |
| 1197 | } |
| 1198 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1199 | static sector_t idefloppy_capacity(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | { |
| 1201 | idefloppy_floppy_t *floppy = drive->driver_data; |
| 1202 | unsigned long capacity = floppy->blocks * floppy->bs_factor; |
| 1203 | |
| 1204 | return capacity; |
| 1205 | } |
| 1206 | |
| 1207 | /* |
Borislav Petkov | f373bd8 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 1208 | * Check whether we can support a drive, based on the ATAPI IDENTIFY command |
| 1209 | * results. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | */ |
Borislav Petkov | f373bd8 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 1211 | static int idefloppy_identify_device(ide_drive_t *drive, struct hd_driveid *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1212 | { |
Borislav Petkov | 3ad6776 | 2008-04-18 00:46:25 +0200 | [diff] [blame] | 1213 | u8 gcw[2]; |
| 1214 | u8 device_type, protocol, removable, drq_type, packet_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | |
| 1216 | *((u16 *) &gcw) = id->config; |
| 1217 | |
Borislav Petkov | 3ad6776 | 2008-04-18 00:46:25 +0200 | [diff] [blame] | 1218 | device_type = gcw[1] & 0x1F; |
| 1219 | removable = (gcw[0] & 0x80) >> 7; |
| 1220 | protocol = (gcw[1] & 0xC0) >> 6; |
| 1221 | drq_type = (gcw[0] & 0x60) >> 5; |
| 1222 | packet_size = gcw[0] & 0x03; |
| 1223 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | #ifdef CONFIG_PPC |
| 1225 | /* kludge for Apple PowerBook internal zip */ |
Borislav Petkov | 3ad6776 | 2008-04-18 00:46:25 +0200 | [diff] [blame] | 1226 | if (device_type == 5 && |
| 1227 | !strstr(id->model, "CD-ROM") && strstr(id->model, "ZIP")) |
| 1228 | device_type = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | #endif |
| 1230 | |
Borislav Petkov | 3ad6776 | 2008-04-18 00:46:25 +0200 | [diff] [blame] | 1231 | if (protocol != 2) |
Borislav Petkov | f373bd8 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 1232 | printk(KERN_ERR "ide-floppy: Protocol (0x%02x) is not ATAPI\n", |
Borislav Petkov | 3ad6776 | 2008-04-18 00:46:25 +0200 | [diff] [blame] | 1233 | protocol); |
| 1234 | else if (device_type != 0) |
Borislav Petkov | f373bd8 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 1235 | printk(KERN_ERR "ide-floppy: Device type (0x%02x) is not set " |
Borislav Petkov | 3ad6776 | 2008-04-18 00:46:25 +0200 | [diff] [blame] | 1236 | "to floppy\n", device_type); |
| 1237 | else if (!removable) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | printk(KERN_ERR "ide-floppy: The removable flag is not set\n"); |
Borislav Petkov | 3ad6776 | 2008-04-18 00:46:25 +0200 | [diff] [blame] | 1239 | else if (drq_type == 3) |
Borislav Petkov | f373bd8 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 1240 | printk(KERN_ERR "ide-floppy: Sorry, DRQ type (0x%02x) not " |
Borislav Petkov | 3ad6776 | 2008-04-18 00:46:25 +0200 | [diff] [blame] | 1241 | "supported\n", drq_type); |
| 1242 | else if (packet_size != 0) |
Borislav Petkov | f373bd8 | 2008-02-02 19:56:36 +0100 | [diff] [blame] | 1243 | printk(KERN_ERR "ide-floppy: Packet size (0x%02x) is not 12 " |
Borislav Petkov | 3ad6776 | 2008-04-18 00:46:25 +0200 | [diff] [blame] | 1244 | "bytes\n", packet_size); |
| 1245 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | return 1; |
| 1247 | return 0; |
| 1248 | } |
| 1249 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1250 | #ifdef CONFIG_IDE_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | static void idefloppy_add_settings(ide_drive_t *drive) |
| 1252 | { |
| 1253 | idefloppy_floppy_t *floppy = drive->driver_data; |
| 1254 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1255 | ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 1023, 1, 1, |
| 1256 | &drive->bios_cyl, NULL); |
| 1257 | ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, |
| 1258 | &drive->bios_head, NULL); |
| 1259 | ide_add_setting(drive, "bios_sect", SETTING_RW, TYPE_BYTE, 0, 63, 1, 1, |
| 1260 | &drive->bios_sect, NULL); |
| 1261 | ide_add_setting(drive, "ticks", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, |
| 1262 | &floppy->ticks, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | } |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1264 | #else |
| 1265 | static inline void idefloppy_add_settings(ide_drive_t *drive) { ; } |
| 1266 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1268 | static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | { |
Borislav Petkov | 3ad6776 | 2008-04-18 00:46:25 +0200 | [diff] [blame] | 1270 | u8 gcw[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | |
| 1272 | *((u16 *) &gcw) = drive->id->config; |
| 1273 | floppy->pc = floppy->pc_stack; |
Borislav Petkov | 3ad6776 | 2008-04-18 00:46:25 +0200 | [diff] [blame] | 1274 | |
| 1275 | if (((gcw[0] & 0x60) >> 5) == 1) |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 1276 | floppy->flags |= IDEFLOPPY_FLAG_DRQ_INTERRUPT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1278 | * We used to check revisions here. At this point however I'm giving up. |
| 1279 | * Just assume they are all broken, its easier. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | * |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1281 | * The actual reason for the workarounds was likely a driver bug after |
| 1282 | * all rather than a firmware bug, and the workaround below used to hide |
| 1283 | * it. It should be fixed as of version 1.9, but to be on the safe side |
| 1284 | * we'll leave the limitation below for the 2.2.x tree. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | if (!strncmp(drive->id->model, "IOMEGA ZIP 100 ATAPI", 20)) { |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 1287 | floppy->flags |= IDEFLOPPY_FLAG_ZIP_DRIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | /* This value will be visible in the /proc/ide/hdx/settings */ |
| 1289 | floppy->ticks = IDEFLOPPY_TICKS_DELAY; |
| 1290 | blk_queue_max_sectors(drive->queue, 64); |
| 1291 | } |
| 1292 | |
| 1293 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1294 | * Guess what? The IOMEGA Clik! drive also needs the above fix. It makes |
| 1295 | * nasty clicking noises without it, so please don't remove this. |
| 1296 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | if (strncmp(drive->id->model, "IOMEGA Clik!", 11) == 0) { |
| 1298 | blk_queue_max_sectors(drive->queue, 64); |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 1299 | floppy->flags |= IDEFLOPPY_FLAG_CLIK_DRIVE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | } |
| 1301 | |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1302 | (void) ide_floppy_get_capacity(drive); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | idefloppy_add_settings(drive); |
| 1304 | } |
| 1305 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 1306 | static void ide_floppy_remove(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | { |
| 1308 | idefloppy_floppy_t *floppy = drive->driver_data; |
| 1309 | struct gendisk *g = floppy->disk; |
| 1310 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1311 | ide_proc_unregister_driver(drive, floppy->driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | |
| 1313 | del_gendisk(g); |
| 1314 | |
| 1315 | ide_floppy_put(floppy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
Borislav Petkov | 9a24b63 | 2008-02-02 19:56:33 +0100 | [diff] [blame] | 1318 | static void idefloppy_cleanup_obj(struct kref *kref) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | { |
| 1320 | struct ide_floppy_obj *floppy = to_ide_floppy(kref); |
| 1321 | ide_drive_t *drive = floppy->drive; |
| 1322 | struct gendisk *g = floppy->disk; |
| 1323 | |
| 1324 | drive->driver_data = NULL; |
| 1325 | g->private_data = NULL; |
| 1326 | put_disk(g); |
| 1327 | kfree(floppy); |
| 1328 | } |
| 1329 | |
Bartlomiej Zolnierkiewicz | ecfd80e | 2007-05-10 00:01:09 +0200 | [diff] [blame] | 1330 | #ifdef CONFIG_IDE_PROC_FS |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1331 | static int proc_idefloppy_read_capacity(char *page, char **start, off_t off, |
| 1332 | int count, int *eof, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | { |
| 1334 | ide_drive_t*drive = (ide_drive_t *)data; |
| 1335 | int len; |
| 1336 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1337 | len = sprintf(page, "%llu\n", (long long)idefloppy_capacity(drive)); |
| 1338 | PROC_IDE_READ_RETURN(page, start, off, count, eof, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1339 | } |
| 1340 | |
| 1341 | static ide_proc_entry_t idefloppy_proc[] = { |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1342 | { "capacity", S_IFREG|S_IRUGO, proc_idefloppy_read_capacity, NULL }, |
| 1343 | { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1344 | { NULL, 0, NULL, NULL } |
| 1345 | }; |
Bartlomiej Zolnierkiewicz | ecfd80e | 2007-05-10 00:01:09 +0200 | [diff] [blame] | 1346 | #endif /* CONFIG_IDE_PROC_FS */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 1348 | static int ide_floppy_probe(ide_drive_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | static ide_driver_t idefloppy_driver = { |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1351 | .gen_driver = { |
Laurent Riffard | 4ef3b8f | 2005-11-18 22:15:40 +0100 | [diff] [blame] | 1352 | .owner = THIS_MODULE, |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1353 | .name = "ide-floppy", |
| 1354 | .bus = &ide_bus_type, |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1355 | }, |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 1356 | .probe = ide_floppy_probe, |
| 1357 | .remove = ide_floppy_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | .version = IDEFLOPPY_VERSION, |
| 1359 | .media = ide_floppy, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | .supports_dsc_overlap = 0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1361 | .do_request = idefloppy_do_request, |
| 1362 | .end_request = idefloppy_do_end_request, |
| 1363 | .error = __ide_error, |
| 1364 | .abort = __ide_abort, |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1365 | #ifdef CONFIG_IDE_PROC_FS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | .proc = idefloppy_proc, |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1367 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | }; |
| 1369 | |
| 1370 | static int idefloppy_open(struct inode *inode, struct file *filp) |
| 1371 | { |
| 1372 | struct gendisk *disk = inode->i_bdev->bd_disk; |
| 1373 | struct ide_floppy_obj *floppy; |
| 1374 | ide_drive_t *drive; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1375 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | int ret = 0; |
| 1377 | |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 1378 | debug_log("Reached %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1379 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1380 | floppy = ide_floppy_get(disk); |
| 1381 | if (!floppy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | return -ENXIO; |
| 1383 | |
| 1384 | drive = floppy->drive; |
| 1385 | |
Bartlomiej Zolnierkiewicz | c94964a | 2007-02-17 02:40:24 +0100 | [diff] [blame] | 1386 | floppy->openers++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | |
Bartlomiej Zolnierkiewicz | c94964a | 2007-02-17 02:40:24 +0100 | [diff] [blame] | 1388 | if (floppy->openers == 1) { |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 1389 | floppy->flags &= ~IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | /* Just in case */ |
| 1391 | |
| 1392 | idefloppy_create_test_unit_ready_cmd(&pc); |
| 1393 | if (idefloppy_queue_pc_tail(drive, &pc)) { |
| 1394 | idefloppy_create_start_stop_cmd(&pc, 1); |
| 1395 | (void) idefloppy_queue_pc_tail(drive, &pc); |
| 1396 | } |
| 1397 | |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1398 | if (ide_floppy_get_capacity(drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | && (filp->f_flags & O_NDELAY) == 0 |
| 1400 | /* |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1401 | * Allow O_NDELAY to open a drive without a disk, or with an |
| 1402 | * unreadable disk, so that we can get the format capacity |
| 1403 | * of the drive or begin the format - Sam |
| 1404 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | ) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | ret = -EIO; |
| 1407 | goto out_put_floppy; |
| 1408 | } |
| 1409 | |
| 1410 | if (floppy->wp && (filp->f_mode & 2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | ret = -EROFS; |
| 1412 | goto out_put_floppy; |
| 1413 | } |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 1414 | floppy->flags |= IDEFLOPPY_FLAG_MEDIA_CHANGED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | /* IOMEGA Clik! drives do not support lock/unlock commands */ |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 1416 | if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | idefloppy_create_prevent_cmd(&pc, 1); |
| 1418 | (void) idefloppy_queue_pc_tail(drive, &pc); |
| 1419 | } |
| 1420 | check_disk_change(inode->i_bdev); |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 1421 | } else if (floppy->flags & IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | ret = -EBUSY; |
| 1423 | goto out_put_floppy; |
| 1424 | } |
| 1425 | return 0; |
| 1426 | |
| 1427 | out_put_floppy: |
Bartlomiej Zolnierkiewicz | c94964a | 2007-02-17 02:40:24 +0100 | [diff] [blame] | 1428 | floppy->openers--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1429 | ide_floppy_put(floppy); |
| 1430 | return ret; |
| 1431 | } |
| 1432 | |
| 1433 | static int idefloppy_release(struct inode *inode, struct file *filp) |
| 1434 | { |
| 1435 | struct gendisk *disk = inode->i_bdev->bd_disk; |
| 1436 | struct ide_floppy_obj *floppy = ide_floppy_g(disk); |
| 1437 | ide_drive_t *drive = floppy->drive; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1438 | struct ide_atapi_pc pc; |
Borislav Petkov | bcc77d9 | 2008-02-02 19:56:34 +0100 | [diff] [blame] | 1439 | |
| 1440 | debug_log("Reached %s\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | |
Bartlomiej Zolnierkiewicz | c94964a | 2007-02-17 02:40:24 +0100 | [diff] [blame] | 1442 | if (floppy->openers == 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1443 | /* IOMEGA Clik! drives do not support lock/unlock commands */ |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 1444 | if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | idefloppy_create_prevent_cmd(&pc, 0); |
| 1446 | (void) idefloppy_queue_pc_tail(drive, &pc); |
| 1447 | } |
| 1448 | |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 1449 | floppy->flags &= ~IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | } |
Bartlomiej Zolnierkiewicz | c94964a | 2007-02-17 02:40:24 +0100 | [diff] [blame] | 1451 | |
| 1452 | floppy->openers--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | |
| 1454 | ide_floppy_put(floppy); |
| 1455 | |
| 1456 | return 0; |
| 1457 | } |
| 1458 | |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 1459 | static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo) |
| 1460 | { |
| 1461 | struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk); |
| 1462 | ide_drive_t *drive = floppy->drive; |
| 1463 | |
| 1464 | geo->heads = drive->bios_head; |
| 1465 | geo->sectors = drive->bios_sect; |
| 1466 | geo->cylinders = (u16)drive->bios_cyl; /* truncate */ |
| 1467 | return 0; |
| 1468 | } |
| 1469 | |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1470 | static int ide_floppy_lockdoor(idefloppy_floppy_t *floppy, |
| 1471 | struct ide_atapi_pc *pc, unsigned long arg, unsigned int cmd) |
Borislav Petkov | 20bf7bd | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1472 | { |
| 1473 | if (floppy->openers > 1) |
| 1474 | return -EBUSY; |
| 1475 | |
| 1476 | /* The IOMEGA Clik! Drive doesn't support this command - |
| 1477 | * no room for an eject mechanism */ |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 1478 | if (!(floppy->flags & IDEFLOPPY_FLAG_CLIK_DRIVE)) { |
Borislav Petkov | 20bf7bd | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1479 | int prevent = arg ? 1 : 0; |
| 1480 | |
| 1481 | if (cmd == CDROMEJECT) |
| 1482 | prevent = 0; |
| 1483 | |
| 1484 | idefloppy_create_prevent_cmd(pc, prevent); |
| 1485 | (void) idefloppy_queue_pc_tail(floppy->drive, pc); |
| 1486 | } |
| 1487 | |
| 1488 | if (cmd == CDROMEJECT) { |
| 1489 | idefloppy_create_start_stop_cmd(pc, 2); |
| 1490 | (void) idefloppy_queue_pc_tail(floppy->drive, pc); |
| 1491 | } |
| 1492 | |
| 1493 | return 0; |
| 1494 | } |
| 1495 | |
| 1496 | static int ide_floppy_format_unit(idefloppy_floppy_t *floppy, |
| 1497 | int __user *arg) |
| 1498 | { |
| 1499 | int blocks, length, flags, err = 0; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1500 | struct ide_atapi_pc pc; |
Borislav Petkov | 20bf7bd | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1501 | |
| 1502 | if (floppy->openers > 1) { |
| 1503 | /* Don't format if someone is using the disk */ |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 1504 | floppy->flags &= ~IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS; |
Borislav Petkov | 20bf7bd | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1505 | return -EBUSY; |
| 1506 | } |
| 1507 | |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 1508 | floppy->flags |= IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS; |
Borislav Petkov | 20bf7bd | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1509 | |
| 1510 | /* |
| 1511 | * Send ATAPI_FORMAT_UNIT to the drive. |
| 1512 | * |
| 1513 | * Userland gives us the following structure: |
| 1514 | * |
| 1515 | * struct idefloppy_format_command { |
| 1516 | * int nblocks; |
| 1517 | * int blocksize; |
| 1518 | * int flags; |
| 1519 | * } ; |
| 1520 | * |
| 1521 | * flags is a bitmask, currently, the only defined flag is: |
| 1522 | * |
| 1523 | * 0x01 - verify media after format. |
| 1524 | */ |
| 1525 | if (get_user(blocks, arg) || |
| 1526 | get_user(length, arg+1) || |
| 1527 | get_user(flags, arg+2)) { |
| 1528 | err = -EFAULT; |
| 1529 | goto out; |
| 1530 | } |
| 1531 | |
| 1532 | (void) idefloppy_get_sfrp_bit(floppy->drive); |
| 1533 | idefloppy_create_format_unit_cmd(&pc, blocks, length, flags); |
| 1534 | |
| 1535 | if (idefloppy_queue_pc_tail(floppy->drive, &pc)) |
| 1536 | err = -EIO; |
| 1537 | |
| 1538 | out: |
| 1539 | if (err) |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 1540 | floppy->flags &= ~IDEFLOPPY_FLAG_FORMAT_IN_PROGRESS; |
Borislav Petkov | 20bf7bd | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1541 | return err; |
| 1542 | } |
| 1543 | |
| 1544 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | static int idefloppy_ioctl(struct inode *inode, struct file *file, |
| 1546 | unsigned int cmd, unsigned long arg) |
| 1547 | { |
| 1548 | struct block_device *bdev = inode->i_bdev; |
| 1549 | struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk); |
| 1550 | ide_drive_t *drive = floppy->drive; |
Borislav Petkov | 8e55512 | 2008-04-18 00:46:27 +0200 | [diff] [blame] | 1551 | struct ide_atapi_pc pc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1552 | void __user *argp = (void __user *)arg; |
Ondrej Zary | 07203f6 | 2005-11-10 00:25:15 +0100 | [diff] [blame] | 1553 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | |
| 1555 | switch (cmd) { |
| 1556 | case CDROMEJECT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | /* fall through */ |
| 1558 | case CDROM_LOCKDOOR: |
Borislav Petkov | 20bf7bd | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1559 | return ide_floppy_lockdoor(floppy, &pc, arg, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED: |
| 1561 | return 0; |
| 1562 | case IDEFLOPPY_IOCTL_FORMAT_GET_CAPACITY: |
Borislav Petkov | 194ec0c | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1563 | return ide_floppy_get_format_capacities(drive, argp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | case IDEFLOPPY_IOCTL_FORMAT_START: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | if (!(file->f_mode & 2)) |
| 1566 | return -EPERM; |
| 1567 | |
Borislav Petkov | 20bf7bd | 2008-02-02 19:56:35 +0100 | [diff] [blame] | 1568 | return ide_floppy_format_unit(floppy, (int __user *)arg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1569 | case IDEFLOPPY_IOCTL_FORMAT_GET_PROGRESS: |
| 1570 | return idefloppy_get_format_progress(drive, argp); |
| 1571 | } |
Bartlomiej Zolnierkiewicz | 89636af | 2007-07-20 01:11:59 +0200 | [diff] [blame] | 1572 | |
| 1573 | /* |
| 1574 | * skip SCSI_IOCTL_SEND_COMMAND (deprecated) |
| 1575 | * and CDROM_SEND_PACKET (legacy) ioctls |
| 1576 | */ |
| 1577 | if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND) |
| 1578 | err = scsi_cmd_ioctl(file, bdev->bd_disk->queue, |
| 1579 | bdev->bd_disk, cmd, argp); |
| 1580 | else |
| 1581 | err = -ENOTTY; |
| 1582 | |
| 1583 | if (err == -ENOTTY) |
| 1584 | err = generic_ide_ioctl(drive, file, bdev, cmd, arg); |
| 1585 | |
| 1586 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | static int idefloppy_media_changed(struct gendisk *disk) |
| 1590 | { |
| 1591 | struct ide_floppy_obj *floppy = ide_floppy_g(disk); |
| 1592 | ide_drive_t *drive = floppy->drive; |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 1593 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | |
| 1595 | /* do not scan partitions twice if this is a removable device */ |
| 1596 | if (drive->attach) { |
| 1597 | drive->attach = 0; |
| 1598 | return 0; |
| 1599 | } |
Borislav Petkov | 6e5fa7b | 2008-02-02 19:56:37 +0100 | [diff] [blame] | 1600 | ret = !!(floppy->flags & IDEFLOPPY_FLAG_MEDIA_CHANGED); |
| 1601 | floppy->flags &= ~IDEFLOPPY_FLAG_MEDIA_CHANGED; |
| 1602 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | } |
| 1604 | |
| 1605 | static int idefloppy_revalidate_disk(struct gendisk *disk) |
| 1606 | { |
| 1607 | struct ide_floppy_obj *floppy = ide_floppy_g(disk); |
| 1608 | set_capacity(disk, idefloppy_capacity(floppy->drive)); |
| 1609 | return 0; |
| 1610 | } |
| 1611 | |
| 1612 | static struct block_device_operations idefloppy_ops = { |
| 1613 | .owner = THIS_MODULE, |
| 1614 | .open = idefloppy_open, |
| 1615 | .release = idefloppy_release, |
| 1616 | .ioctl = idefloppy_ioctl, |
Christoph Hellwig | a885c8c | 2006-01-08 01:02:50 -0800 | [diff] [blame] | 1617 | .getgeo = idefloppy_getgeo, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | .media_changed = idefloppy_media_changed, |
| 1619 | .revalidate_disk= idefloppy_revalidate_disk |
| 1620 | }; |
| 1621 | |
Russell King | 4031bbe | 2006-01-06 11:41:00 +0000 | [diff] [blame] | 1622 | static int ide_floppy_probe(ide_drive_t *drive) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | { |
| 1624 | idefloppy_floppy_t *floppy; |
| 1625 | struct gendisk *g; |
| 1626 | |
| 1627 | if (!strstr("ide-floppy", drive->driver_req)) |
| 1628 | goto failed; |
| 1629 | if (!drive->present) |
| 1630 | goto failed; |
| 1631 | if (drive->media != ide_floppy) |
| 1632 | goto failed; |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1633 | if (!idefloppy_identify_device(drive, drive->id)) { |
| 1634 | printk(KERN_ERR "ide-floppy: %s: not supported by this version" |
| 1635 | " of ide-floppy\n", drive->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | goto failed; |
| 1637 | } |
| 1638 | if (drive->scsi) { |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1639 | printk(KERN_INFO "ide-floppy: passing drive %s to ide-scsi" |
| 1640 | " emulation.\n", drive->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | goto failed; |
| 1642 | } |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1643 | floppy = kzalloc(sizeof(idefloppy_floppy_t), GFP_KERNEL); |
| 1644 | if (!floppy) { |
| 1645 | printk(KERN_ERR "ide-floppy: %s: Can't allocate a floppy" |
| 1646 | " structure\n", drive->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | goto failed; |
| 1648 | } |
| 1649 | |
| 1650 | g = alloc_disk(1 << PARTN_BITS); |
| 1651 | if (!g) |
| 1652 | goto out_free_floppy; |
| 1653 | |
| 1654 | ide_init_disk(g, drive); |
| 1655 | |
Bartlomiej Zolnierkiewicz | 7662d04 | 2007-05-10 00:01:10 +0200 | [diff] [blame] | 1656 | ide_proc_register_driver(drive, &idefloppy_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | kref_init(&floppy->kref); |
| 1659 | |
| 1660 | floppy->drive = drive; |
| 1661 | floppy->driver = &idefloppy_driver; |
| 1662 | floppy->disk = g; |
| 1663 | |
| 1664 | g->private_data = &floppy->driver; |
| 1665 | |
| 1666 | drive->driver_data = floppy; |
| 1667 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1668 | idefloppy_setup(drive, floppy); |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | g->minors = 1 << PARTN_BITS; |
| 1671 | g->driverfs_dev = &drive->gendev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1672 | g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0; |
| 1673 | g->fops = &idefloppy_ops; |
| 1674 | drive->attach = 1; |
| 1675 | add_disk(g); |
| 1676 | return 0; |
| 1677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | out_free_floppy: |
| 1679 | kfree(floppy); |
| 1680 | failed: |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1681 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | } |
| 1683 | |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1684 | static void __exit idefloppy_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | { |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1686 | driver_unregister(&idefloppy_driver.gen_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | } |
| 1688 | |
Bartlomiej Zolnierkiewicz | 17514e8 | 2005-11-19 22:24:35 +0100 | [diff] [blame] | 1689 | static int __init idefloppy_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | { |
| 1691 | printk("ide-floppy driver " IDEFLOPPY_VERSION "\n"); |
Bartlomiej Zolnierkiewicz | 8604aff | 2005-05-26 14:55:34 +0200 | [diff] [blame] | 1692 | return driver_register(&idefloppy_driver.gen_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | } |
| 1694 | |
Kay Sievers | 263756e | 2005-12-12 18:03:44 +0100 | [diff] [blame] | 1695 | MODULE_ALIAS("ide:*m-floppy*"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | module_init(idefloppy_init); |
| 1697 | module_exit(idefloppy_exit); |
| 1698 | MODULE_LICENSE("GPL"); |
Borislav Petkov | 0571c7a | 2008-02-02 19:56:38 +0100 | [diff] [blame] | 1699 | MODULE_DESCRIPTION("ATAPI FLOPPY Driver"); |
| 1700 | |