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