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