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