18 #include <linux/types.h>
19 #include <linux/string.h>
20 #include <linux/kernel.h>
26 #include <linux/errno.h>
28 #include <linux/cdrom.h>
31 #include <linux/bitops.h>
37 #include <asm/byteorder.h>
40 #include <asm/unaligned.h>
48 #define IDEFLOPPY_MAX_PC_RETRIES 3
51 #define CAPACITY_INVALID 0x00
52 #define CAPACITY_UNFORMATTED 0x01
53 #define CAPACITY_CURRENT 0x02
54 #define CAPACITY_NO_CARTRIDGE 0x03
60 #define IDEFLOPPY_PC_DELAY (HZ/20)
62 static int ide_floppy_callback(
ide_drive_t *drive,
int dsc)
67 int uptodate = pc->
error ? 0 : 1;
75 rq->cmd_type == REQ_TYPE_BLOCK_PC)
79 u8 *
buf = bio_data(rq->bio);
83 floppy->
asc = buf[12];
84 floppy->
ascq = buf[13];
97 "Aborting request!\n");
100 if (rq->cmd_type == REQ_TYPE_SPECIAL)
106 static void ide_floppy_report_error(
struct ide_disk_obj *floppy,
111 floppy->
asc == 0x3a &&
112 floppy->
ascq == 0x00)
116 "asc = %2x, ascq = %2x\n",
136 unsigned int done = blk_rq_bytes(drive->
hwif->rq);
139 ide_floppy_report_error(floppy, pc);
177 case IDEFLOPPY_CAPABILITIES_PAGE:
180 case IDEFLOPPY_FLEXIBLE_DISK_PAGE:
190 static void idefloppy_create_rw_cmd(
ide_drive_t *drive,
197 int cmd = rq_data_dir(rq);
215 static void idefloppy_blockpc_cmd(
struct ide_disk_obj *floppy,
219 memcpy(pc->
c, rq->cmd,
sizeof(pc->
c));
221 if (blk_rq_bytes(rq)) {
223 if (rq_data_dir(rq) ==
WRITE)
239 ? rq->rq_disk->disk_name
244 ide_floppy_report_error(floppy, drive->
failed_pc);
249 if (rq->cmd_type == REQ_TYPE_SPECIAL) {
257 switch (rq->cmd_type) {
259 if (((
long)blk_rq_pos(rq) % floppy->
bs_factor) ||
260 (blk_rq_sectors(rq) % floppy->
bs_factor)) {
266 idefloppy_create_rw_cmd(drive, pc, rq, (
unsigned long)block);
268 case REQ_TYPE_SPECIAL:
272 case REQ_TYPE_BLOCK_PC:
274 idefloppy_blockpc_cmd(floppy, pc, rq);
282 memset(&cmd, 0,
sizeof(cmd));
289 if (rq->cmd_type == REQ_TYPE_FS || blk_rq_bytes(rq)) {
296 return ide_floppy_issue_pc(drive, &cmd, pc);
299 if (rq->cmd_type != REQ_TYPE_FS && rq->errors == 0)
309 static int ide_floppy_get_flexible_disk_page(
ide_drive_t *drive,
313 struct gendisk *disk = floppy->
disk;
340 sectors = buf[8 + 5];
346 "%d sector size, %d rpm\n",
347 drive->
name, capacity / 1024, cyls, heads,
348 sectors, transfer_rate / 8, sector_size, rpm);
356 if (capacity < lba_capacity) {
358 "bytes, but the drive only handles %d\n",
359 drive->
name, lba_capacity, capacity);
372 static int ide_floppy_get_capacity(
ide_drive_t *drive)
375 struct gendisk *disk = floppy->
disk;
394 header_len = pc_buf[3];
395 cap_desc = &pc_buf[4];
396 desc_cnt = header_len / 8;
398 for (i = 0; i < desc_cnt; i++) {
399 unsigned int desc_start = 4 + i*8;
406 i, blocks * length / 1024,
415 switch (pc_buf[desc_start + 4] & 0x03) {
429 drive->
name, blocks * length / 1024,
433 if (!length || length % 512) {
435 " not supported\n", drive->
name, length);
442 "non 512 bytes block size not "
460 "in drive\n", drive->
name);
464 pc_buf[desc_start + 4] & 0x03);
469 (
void) ide_floppy_get_flexible_disk_page(drive, &pc);
501 if (
strncmp((
char *)&
id[ATA_ID_PROD],
"IOMEGA Clik!", 11) == 0) {
508 (
void) ide_floppy_get_capacity(drive);
519 static int ide_floppy_init_media(
ide_drive_t *drive,
struct gendisk *disk)
526 ret = ide_floppy_get_capacity(drive);
535 .get_capacity = ide_floppy_get_capacity,
536 .setup = ide_floppy_setup,
537 .flush = ide_floppy_flush,
538 .init_media = ide_floppy_init_media,
540 .do_request = ide_floppy_do_request,