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