Commit e3faa2481e832568d13dfa3a52d17525b322cb8f

Authored by Bartlomiej Zolnierkiewicz
1 parent 51509eec34

ide-floppy: remove needless parens

Cc: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>

Showing 1 changed file with 16 additions and 11 deletions Inline Diff

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