aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ide-tape.c
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-07-15 15:21:55 -0400
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-07-15 15:21:55 -0400
commit5985e6abbd89f969c17fd80ab864c80f089827a3 (patch)
tree3268f44b3c45414aeddbfd2f2bee41560adc57a5 /drivers/ide/ide-tape.c
parent258ec4113081c2b63117dc2df6d94c3e484e9747 (diff)
ide-tape: merge callbacks
The appropriate functionality of the callback is established through querying the ATAPI packet command in pc->c[0]. While at it: - add uptodate variable + leave just one idetape_end_request() call - don't use HWGROUP() macro Cc: Borislav Petkov <petkovbb@gmail.com> Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide/ide-tape.c')
-rw-r--r--drivers/ide/ide-tape.c168
1 files changed, 64 insertions, 104 deletions
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 48fccf154f68..d387aaf0eb39 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -503,18 +503,6 @@ static struct request *idetape_next_rq_storage(ide_drive_t *drive)
503 return (&tape->rq_stack[tape->rq_stack_index++]); 503 return (&tape->rq_stack[tape->rq_stack_index++]);
504} 504}
505 505
506static void idetape_init_pc(struct ide_atapi_pc *pc)
507{
508 memset(pc->c, 0, 12);
509 pc->retries = 0;
510 pc->flags = 0;
511 pc->req_xfer = 0;
512 pc->buf = pc->pc_buf;
513 pc->buf_size = IDETAPE_PC_BUFFER_SIZE;
514 pc->bh = NULL;
515 pc->b_data = NULL;
516}
517
518/* 506/*
519 * called on each failed packet command retry to analyze the request sense. We 507 * called on each failed packet command retry to analyze the request sense. We
520 * currently do not utilize this information. 508 * currently do not utilize this information.
@@ -631,30 +619,85 @@ static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects)
631 return 0; 619 return 0;
632} 620}
633 621
634static ide_startstop_t idetape_request_sense_callback(ide_drive_t *drive) 622static ide_startstop_t ide_tape_callback(ide_drive_t *drive)
635{ 623{
636 idetape_tape_t *tape = drive->driver_data; 624 idetape_tape_t *tape = drive->driver_data;
625 struct ide_atapi_pc *pc = tape->pc;
626 int uptodate = pc->error ? 0 : 1;
637 627
638 debug_log(DBG_PROCS, "Enter %s\n", __func__); 628 debug_log(DBG_PROCS, "Enter %s\n", __func__);
639 629
640 if (!tape->pc->error) { 630 if (pc->c[0] == REQUEST_SENSE) {
641 idetape_analyze_error(drive, tape->pc->buf); 631 if (uptodate)
642 idetape_end_request(drive, 1, 0); 632 idetape_analyze_error(drive, pc->buf);
643 } else { 633 else
644 printk(KERN_ERR "ide-tape: Error in REQUEST SENSE itself - " 634 printk(KERN_ERR "ide-tape: Error in REQUEST SENSE "
645 "Aborting request!\n"); 635 "itself - Aborting request!\n");
646 idetape_end_request(drive, 0, 0); 636 } else if (pc->c[0] == READ_6 || pc->c[0] == WRITE_6) {
637 struct request *rq = drive->hwif->hwgroup->rq;
638 int blocks = pc->xferred / tape->blk_size;
639
640 tape->avg_size += blocks * tape->blk_size;
641
642 if (time_after_eq(jiffies, tape->avg_time + HZ)) {
643 tape->avg_speed = tape->avg_size * HZ /
644 (jiffies - tape->avg_time) / 1024;
645 tape->avg_size = 0;
646 tape->avg_time = jiffies;
647 }
648
649 tape->first_frame += blocks;
650 rq->current_nr_sectors -= blocks;
651
652 if (pc->error)
653 uptodate = pc->error;
654 } else if (pc->c[0] == READ_POSITION && uptodate) {
655 u8 *readpos = tape->pc->buf;
656
657 debug_log(DBG_SENSE, "BOP - %s\n",
658 (readpos[0] & 0x80) ? "Yes" : "No");
659 debug_log(DBG_SENSE, "EOP - %s\n",
660 (readpos[0] & 0x40) ? "Yes" : "No");
661
662 if (readpos[0] & 0x4) {
663 printk(KERN_INFO "ide-tape: Block location is unknown"
664 "to the tape\n");
665 clear_bit(IDETAPE_FLAG_ADDRESS_VALID, &tape->flags);
666 uptodate = 0;
667 } else {
668 debug_log(DBG_SENSE, "Block Location - %u\n",
669 be32_to_cpu(*(u32 *)&readpos[4]));
670
671 tape->partition = readpos[1];
672 tape->first_frame = be32_to_cpu(*(u32 *)&readpos[4]);
673 set_bit(IDETAPE_FLAG_ADDRESS_VALID, &tape->flags);
674 }
647 } 675 }
676
677 idetape_end_request(drive, uptodate, 0);
678
648 return ide_stopped; 679 return ide_stopped;
649} 680}
650 681
682static void idetape_init_pc(struct ide_atapi_pc *pc)
683{
684 memset(pc->c, 0, 12);
685 pc->retries = 0;
686 pc->flags = 0;
687 pc->req_xfer = 0;
688 pc->buf = pc->pc_buf;
689 pc->buf_size = IDETAPE_PC_BUFFER_SIZE;
690 pc->bh = NULL;
691 pc->b_data = NULL;
692 pc->idetape_callback = ide_tape_callback;
693}
694
651static void idetape_create_request_sense_cmd(struct ide_atapi_pc *pc) 695static void idetape_create_request_sense_cmd(struct ide_atapi_pc *pc)
652{ 696{
653 idetape_init_pc(pc); 697 idetape_init_pc(pc);
654 pc->c[0] = REQUEST_SENSE; 698 pc->c[0] = REQUEST_SENSE;
655 pc->c[4] = 20; 699 pc->c[4] = 20;
656 pc->req_xfer = 20; 700 pc->req_xfer = 20;
657 pc->idetape_callback = &idetape_request_sense_callback;
658} 701}
659 702
660static void idetape_init_rq(struct request *rq, u8 cmd) 703static void idetape_init_rq(struct request *rq, u8 cmd)
@@ -1025,16 +1068,6 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
1025 } 1068 }
1026} 1069}
1027 1070
1028static ide_startstop_t idetape_pc_callback(ide_drive_t *drive)
1029{
1030 idetape_tape_t *tape = drive->driver_data;
1031
1032 debug_log(DBG_PROCS, "Enter %s\n", __func__);
1033
1034 idetape_end_request(drive, tape->pc->error ? 0 : 1, 0);
1035 return ide_stopped;
1036}
1037
1038/* A mode sense command is used to "sense" tape parameters. */ 1071/* A mode sense command is used to "sense" tape parameters. */
1039static void idetape_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code) 1072static void idetape_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code)
1040{ 1073{
@@ -1060,7 +1093,6 @@ static void idetape_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code)
1060 pc->req_xfer = 24; 1093 pc->req_xfer = 24;
1061 else 1094 else
1062 pc->req_xfer = 50; 1095 pc->req_xfer = 50;
1063 pc->idetape_callback = &idetape_pc_callback;
1064} 1096}
1065 1097
1066static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive) 1098static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
@@ -1091,32 +1123,6 @@ static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
1091 return pc->idetape_callback(drive); 1123 return pc->idetape_callback(drive);
1092} 1124}
1093 1125
1094static ide_startstop_t idetape_rw_callback(ide_drive_t *drive)
1095{
1096 idetape_tape_t *tape = drive->driver_data;
1097 struct request *rq = HWGROUP(drive)->rq;
1098 int blocks = tape->pc->xferred / tape->blk_size;
1099
1100 tape->avg_size += blocks * tape->blk_size;
1101
1102 if (time_after_eq(jiffies, tape->avg_time + HZ)) {
1103 tape->avg_speed = tape->avg_size * HZ /
1104 (jiffies - tape->avg_time) / 1024;
1105 tape->avg_size = 0;
1106 tape->avg_time = jiffies;
1107 }
1108 debug_log(DBG_PROCS, "Enter %s\n", __func__);
1109
1110 tape->first_frame += blocks;
1111 rq->current_nr_sectors -= blocks;
1112
1113 if (!tape->pc->error)
1114 idetape_end_request(drive, 1, 0);
1115 else
1116 idetape_end_request(drive, tape->pc->error, 0);
1117 return ide_stopped;
1118}
1119
1120static void idetape_create_read_cmd(idetape_tape_t *tape, 1126static void idetape_create_read_cmd(idetape_tape_t *tape,
1121 struct ide_atapi_pc *pc, 1127 struct ide_atapi_pc *pc,
1122 unsigned int length, struct idetape_bh *bh) 1128 unsigned int length, struct idetape_bh *bh)
@@ -1125,7 +1131,6 @@ static void idetape_create_read_cmd(idetape_tape_t *tape,
1125 pc->c[0] = READ_6; 1131 pc->c[0] = READ_6;
1126 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]); 1132 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
1127 pc->c[1] = 1; 1133 pc->c[1] = 1;
1128 pc->idetape_callback = &idetape_rw_callback;
1129 pc->bh = bh; 1134 pc->bh = bh;
1130 atomic_set(&bh->b_count, 0); 1135 atomic_set(&bh->b_count, 0);
1131 pc->buf = NULL; 1136 pc->buf = NULL;
@@ -1143,7 +1148,6 @@ static void idetape_create_write_cmd(idetape_tape_t *tape,
1143 pc->c[0] = WRITE_6; 1148 pc->c[0] = WRITE_6;
1144 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]); 1149 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
1145 pc->c[1] = 1; 1150 pc->c[1] = 1;
1146 pc->idetape_callback = &idetape_rw_callback;
1147 pc->flags |= PC_FLAG_WRITING; 1151 pc->flags |= PC_FLAG_WRITING;
1148 pc->bh = bh; 1152 pc->bh = bh;
1149 pc->b_data = bh->b_data; 1153 pc->b_data = bh->b_data;
@@ -1412,40 +1416,6 @@ static void idetape_init_merge_buffer(idetape_tape_t *tape)
1412 } 1416 }
1413} 1417}
1414 1418
1415static ide_startstop_t idetape_read_position_callback(ide_drive_t *drive)
1416{
1417 idetape_tape_t *tape = drive->driver_data;
1418 u8 *readpos = tape->pc->buf;
1419
1420 debug_log(DBG_PROCS, "Enter %s\n", __func__);
1421
1422 if (!tape->pc->error) {
1423 debug_log(DBG_SENSE, "BOP - %s\n",
1424 (readpos[0] & 0x80) ? "Yes" : "No");
1425 debug_log(DBG_SENSE, "EOP - %s\n",
1426 (readpos[0] & 0x40) ? "Yes" : "No");
1427
1428 if (readpos[0] & 0x4) {
1429 printk(KERN_INFO "ide-tape: Block location is unknown"
1430 "to the tape\n");
1431 clear_bit(IDETAPE_FLAG_ADDRESS_VALID, &tape->flags);
1432 idetape_end_request(drive, 0, 0);
1433 } else {
1434 debug_log(DBG_SENSE, "Block Location - %u\n",
1435 be32_to_cpu(*(u32 *)&readpos[4]));
1436
1437 tape->partition = readpos[1];
1438 tape->first_frame =
1439 be32_to_cpu(*(u32 *)&readpos[4]);
1440 set_bit(IDETAPE_FLAG_ADDRESS_VALID, &tape->flags);
1441 idetape_end_request(drive, 1, 0);
1442 }
1443 } else {
1444 idetape_end_request(drive, 0, 0);
1445 }
1446 return ide_stopped;
1447}
1448
1449/* 1419/*
1450 * Write a filemark if write_filemark=1. Flush the device buffers without 1420 * Write a filemark if write_filemark=1. Flush the device buffers without
1451 * writing a filemark otherwise. 1421 * writing a filemark otherwise.
@@ -1457,14 +1427,12 @@ static void idetape_create_write_filemark_cmd(ide_drive_t *drive,
1457 pc->c[0] = WRITE_FILEMARKS; 1427 pc->c[0] = WRITE_FILEMARKS;
1458 pc->c[4] = write_filemark; 1428 pc->c[4] = write_filemark;
1459 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1429 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1460 pc->idetape_callback = &idetape_pc_callback;
1461} 1430}
1462 1431
1463static void idetape_create_test_unit_ready_cmd(struct ide_atapi_pc *pc) 1432static void idetape_create_test_unit_ready_cmd(struct ide_atapi_pc *pc)
1464{ 1433{
1465 idetape_init_pc(pc); 1434 idetape_init_pc(pc);
1466 pc->c[0] = TEST_UNIT_READY; 1435 pc->c[0] = TEST_UNIT_READY;
1467 pc->idetape_callback = &idetape_pc_callback;
1468} 1436}
1469 1437
1470/* 1438/*
@@ -1502,7 +1470,6 @@ static void idetape_create_load_unload_cmd(ide_drive_t *drive,
1502 pc->c[0] = START_STOP; 1470 pc->c[0] = START_STOP;
1503 pc->c[4] = cmd; 1471 pc->c[4] = cmd;
1504 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1472 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1505 pc->idetape_callback = &idetape_pc_callback;
1506} 1473}
1507 1474
1508static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout) 1475static int idetape_wait_ready(ide_drive_t *drive, unsigned long timeout)
@@ -1554,7 +1521,6 @@ static void idetape_create_read_position_cmd(struct ide_atapi_pc *pc)
1554 idetape_init_pc(pc); 1521 idetape_init_pc(pc);
1555 pc->c[0] = READ_POSITION; 1522 pc->c[0] = READ_POSITION;
1556 pc->req_xfer = 20; 1523 pc->req_xfer = 20;
1557 pc->idetape_callback = &idetape_read_position_callback;
1558} 1524}
1559 1525
1560static int idetape_read_position(ide_drive_t *drive) 1526static int idetape_read_position(ide_drive_t *drive)
@@ -1582,7 +1548,6 @@ static void idetape_create_locate_cmd(ide_drive_t *drive,
1582 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]); 1548 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]);
1583 pc->c[8] = partition; 1549 pc->c[8] = partition;
1584 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1550 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1585 pc->idetape_callback = &idetape_pc_callback;
1586} 1551}
1587 1552
1588static int idetape_create_prevent_cmd(ide_drive_t *drive, 1553static int idetape_create_prevent_cmd(ide_drive_t *drive,
@@ -1597,7 +1562,6 @@ static int idetape_create_prevent_cmd(ide_drive_t *drive,
1597 idetape_init_pc(pc); 1562 idetape_init_pc(pc);
1598 pc->c[0] = ALLOW_MEDIUM_REMOVAL; 1563 pc->c[0] = ALLOW_MEDIUM_REMOVAL;
1599 pc->c[4] = prevent; 1564 pc->c[4] = prevent;
1600 pc->idetape_callback = &idetape_pc_callback;
1601 return 1; 1565 return 1;
1602} 1566}
1603 1567
@@ -1704,7 +1668,6 @@ static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc)
1704 pc->c[0] = INQUIRY; 1668 pc->c[0] = INQUIRY;
1705 pc->c[4] = 254; 1669 pc->c[4] = 254;
1706 pc->req_xfer = 254; 1670 pc->req_xfer = 254;
1707 pc->idetape_callback = &idetape_pc_callback;
1708} 1671}
1709 1672
1710static void idetape_create_rewind_cmd(ide_drive_t *drive, 1673static void idetape_create_rewind_cmd(ide_drive_t *drive,
@@ -1713,7 +1676,6 @@ static void idetape_create_rewind_cmd(ide_drive_t *drive,
1713 idetape_init_pc(pc); 1676 idetape_init_pc(pc);
1714 pc->c[0] = REZERO_UNIT; 1677 pc->c[0] = REZERO_UNIT;
1715 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1678 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1716 pc->idetape_callback = &idetape_pc_callback;
1717} 1679}
1718 1680
1719static void idetape_create_erase_cmd(struct ide_atapi_pc *pc) 1681static void idetape_create_erase_cmd(struct ide_atapi_pc *pc)
@@ -1722,7 +1684,6 @@ static void idetape_create_erase_cmd(struct ide_atapi_pc *pc)
1722 pc->c[0] = ERASE; 1684 pc->c[0] = ERASE;
1723 pc->c[1] = 1; 1685 pc->c[1] = 1;
1724 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1686 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1725 pc->idetape_callback = &idetape_pc_callback;
1726} 1687}
1727 1688
1728static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd) 1689static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd)
@@ -1732,7 +1693,6 @@ static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd)
1732 put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]); 1693 put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]);
1733 pc->c[1] = cmd; 1694 pc->c[1] = cmd;
1734 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1695 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1735 pc->idetape_callback = &idetape_pc_callback;
1736} 1696}
1737 1697
1738/* Queue up a character device originated write request. */ 1698/* Queue up a character device originated write request. */