aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-10-10 16:39:37 -0400
committerBartlomiej Zolnierkiewicz <bzolnier@gmail.com>2008-10-10 16:39:37 -0400
commit7bf7420a318978cd6042e5a5da34b7cfa18ae559 (patch)
tree7498ae013e3603dc66628873eaa2647fd001fe98
parent385a4b8787c70b708688bee65139f15b0f79f144 (diff)
ide: add ide_init_pc() helper
* Add IDE_PC_BUFFER_SIZE define. * Add ide_init_pc() and convert ide-{floppy,tape}.c to use it instead of ide*_init_pc(). * Remove no longer used IDE*_PC_BUFFER_SIZE and ide*_init_pc(). There should be no functional changes caused by this patch. Acked-by: Borislav Petkov <petkovbb@gmail.com> Acked-by: Sergei Shtylyov <sshtylyov@ru.mvista.com> Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
-rw-r--r--drivers/ide/ide-atapi.c8
-rw-r--r--drivers/ide/ide-floppy.c31
-rw-r--r--drivers/ide/ide-tape.c44
-rw-r--r--include/linux/ide.h10
4 files changed, 39 insertions, 54 deletions
diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c
index 3d44b45650f6..8f0842ce77f5 100644
--- a/drivers/ide/ide-atapi.c
+++ b/drivers/ide/ide-atapi.c
@@ -111,6 +111,14 @@ int ide_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
111} 111}
112EXPORT_SYMBOL_GPL(ide_io_buffers); 112EXPORT_SYMBOL_GPL(ide_io_buffers);
113 113
114void ide_init_pc(struct ide_atapi_pc *pc)
115{
116 memset(pc, 0, sizeof(*pc));
117 pc->buf = pc->pc_buf;
118 pc->buf_size = IDE_PC_BUFFER_SIZE;
119}
120EXPORT_SYMBOL_GPL(ide_init_pc);
121
114/* TODO: unify the code thus making some arguments go away */ 122/* TODO: unify the code thus making some arguments go away */
115ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc, 123ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
116 ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry, 124 ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry,
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c
index 4bab0932c94a..e04eaa49a8bf 100644
--- a/drivers/ide/ide-floppy.c
+++ b/drivers/ide/ide-floppy.c
@@ -69,12 +69,6 @@
69 */ 69 */
70#define IDEFLOPPY_MAX_PC_RETRIES 3 70#define IDEFLOPPY_MAX_PC_RETRIES 3
71 71
72/*
73 * With each packet command, we allocate a buffer of IDEFLOPPY_PC_BUFFER_SIZE
74 * bytes.
75 */
76#define IDEFLOPPY_PC_BUFFER_SIZE 256
77
78/* format capacities descriptor codes */ 72/* format capacities descriptor codes */
79#define CAPACITY_INVALID 0x00 73#define CAPACITY_INVALID 0x00
80#define CAPACITY_UNFORMATTED 0x01 74#define CAPACITY_UNFORMATTED 0x01
@@ -274,16 +268,9 @@ static void ide_floppy_callback(ide_drive_t *drive)
274 idefloppy_end_request(drive, uptodate, 0); 268 idefloppy_end_request(drive, uptodate, 0);
275} 269}
276 270
277static void idefloppy_init_pc(struct ide_atapi_pc *pc)
278{
279 memset(pc, 0, sizeof(*pc));
280 pc->buf = pc->pc_buf;
281 pc->buf_size = IDEFLOPPY_PC_BUFFER_SIZE;
282}
283
284static void idefloppy_create_request_sense_cmd(struct ide_atapi_pc *pc) 271static void idefloppy_create_request_sense_cmd(struct ide_atapi_pc *pc)
285{ 272{
286 idefloppy_init_pc(pc); 273 ide_init_pc(pc);
287 pc->c[0] = GPCMD_REQUEST_SENSE; 274 pc->c[0] = GPCMD_REQUEST_SENSE;
288 pc->c[4] = 255; 275 pc->c[4] = 255;
289 pc->req_xfer = 18; 276 pc->req_xfer = 18;
@@ -413,14 +400,14 @@ static void idefloppy_create_prevent_cmd(struct ide_atapi_pc *pc, int prevent)
413{ 400{
414 debug_log("creating prevent removal command, prevent = %d\n", prevent); 401 debug_log("creating prevent removal command, prevent = %d\n", prevent);
415 402
416 idefloppy_init_pc(pc); 403 ide_init_pc(pc);
417 pc->c[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL; 404 pc->c[0] = GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL;
418 pc->c[4] = prevent; 405 pc->c[4] = prevent;
419} 406}
420 407
421static void idefloppy_create_read_capacity_cmd(struct ide_atapi_pc *pc) 408static void idefloppy_create_read_capacity_cmd(struct ide_atapi_pc *pc)
422{ 409{
423 idefloppy_init_pc(pc); 410 ide_init_pc(pc);
424 pc->c[0] = GPCMD_READ_FORMAT_CAPACITIES; 411 pc->c[0] = GPCMD_READ_FORMAT_CAPACITIES;
425 pc->c[7] = 255; 412 pc->c[7] = 255;
426 pc->c[8] = 255; 413 pc->c[8] = 255;
@@ -430,7 +417,7 @@ static void idefloppy_create_read_capacity_cmd(struct ide_atapi_pc *pc)
430static void idefloppy_create_format_unit_cmd(struct ide_atapi_pc *pc, int b, 417static void idefloppy_create_format_unit_cmd(struct ide_atapi_pc *pc, int b,
431 int l, int flags) 418 int l, int flags)
432{ 419{
433 idefloppy_init_pc(pc); 420 ide_init_pc(pc);
434 pc->c[0] = GPCMD_FORMAT_UNIT; 421 pc->c[0] = GPCMD_FORMAT_UNIT;
435 pc->c[1] = 0x17; 422 pc->c[1] = 0x17;
436 423
@@ -454,7 +441,7 @@ static void idefloppy_create_mode_sense_cmd(struct ide_atapi_pc *pc,
454{ 441{
455 u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */ 442 u16 length = 8; /* sizeof(Mode Parameter Header) = 8 Bytes */
456 443
457 idefloppy_init_pc(pc); 444 ide_init_pc(pc);
458 pc->c[0] = GPCMD_MODE_SENSE_10; 445 pc->c[0] = GPCMD_MODE_SENSE_10;
459 pc->c[1] = 0; 446 pc->c[1] = 0;
460 pc->c[2] = page_code; 447 pc->c[2] = page_code;
@@ -476,7 +463,7 @@ static void idefloppy_create_mode_sense_cmd(struct ide_atapi_pc *pc,
476 463
477static void idefloppy_create_start_stop_cmd(struct ide_atapi_pc *pc, int start) 464static void idefloppy_create_start_stop_cmd(struct ide_atapi_pc *pc, int start)
478{ 465{
479 idefloppy_init_pc(pc); 466 ide_init_pc(pc);
480 pc->c[0] = GPCMD_START_STOP_UNIT; 467 pc->c[0] = GPCMD_START_STOP_UNIT;
481 pc->c[4] = start; 468 pc->c[4] = start;
482} 469}
@@ -492,7 +479,7 @@ static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
492 debug_log("create_rw10_cmd: block == %d, blocks == %d\n", 479 debug_log("create_rw10_cmd: block == %d, blocks == %d\n",
493 block, blocks); 480 block, blocks);
494 481
495 idefloppy_init_pc(pc); 482 ide_init_pc(pc);
496 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10; 483 pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10;
497 put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]); 484 put_unaligned(cpu_to_be16(blocks), (unsigned short *)&pc->c[7]);
498 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]); 485 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[2]);
@@ -511,7 +498,7 @@ static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
511static void idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy, 498static void idefloppy_blockpc_cmd(idefloppy_floppy_t *floppy,
512 struct ide_atapi_pc *pc, struct request *rq) 499 struct ide_atapi_pc *pc, struct request *rq)
513{ 500{
514 idefloppy_init_pc(pc); 501 ide_init_pc(pc);
515 memcpy(pc->c, rq->cmd, sizeof(pc->c)); 502 memcpy(pc->c, rq->cmd, sizeof(pc->c));
516 pc->rq = rq; 503 pc->rq = rq;
517 pc->b_count = 0; 504 pc->b_count = 0;
@@ -1071,7 +1058,7 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
1071 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS; 1058 drive->atapi_flags &= ~IDE_AFLAG_FORMAT_IN_PROGRESS;
1072 /* Just in case */ 1059 /* Just in case */
1073 1060
1074 idefloppy_init_pc(&pc); 1061 ide_init_pc(&pc);
1075 pc.c[0] = GPCMD_TEST_UNIT_READY; 1062 pc.c[0] = GPCMD_TEST_UNIT_READY;
1076 1063
1077 if (idefloppy_queue_pc_tail(drive, &pc)) { 1064 if (idefloppy_queue_pc_tail(drive, &pc)) {
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index 26d5b0576f0a..5c879fbcca87 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -81,12 +81,6 @@ enum {
81#define IDETAPE_MAX_PC_RETRIES 3 81#define IDETAPE_MAX_PC_RETRIES 3
82 82
83/* 83/*
84 * With each packet command, we allocate a buffer of IDETAPE_PC_BUFFER_SIZE
85 * bytes. This is used for several packet commands (Not for READ/WRITE commands)
86 */
87#define IDETAPE_PC_BUFFER_SIZE 256
88
89/*
90 * Some drives (for example, Seagate STT3401A Travan) require a very long 84 * Some drives (for example, Seagate STT3401A Travan) require a very long
91 * timeout, because they don't return an interrupt or clear their busy bit 85 * timeout, because they don't return an interrupt or clear their busy bit
92 * until after the command completes (even retension commands). 86 * until after the command completes (even retension commands).
@@ -610,21 +604,9 @@ static void ide_tape_callback(ide_drive_t *drive)
610 idetape_end_request(drive, uptodate, 0); 604 idetape_end_request(drive, uptodate, 0);
611} 605}
612 606
613static void idetape_init_pc(struct ide_atapi_pc *pc)
614{
615 memset(pc->c, 0, 12);
616 pc->retries = 0;
617 pc->flags = 0;
618 pc->req_xfer = 0;
619 pc->buf = pc->pc_buf;
620 pc->buf_size = IDETAPE_PC_BUFFER_SIZE;
621 pc->bh = NULL;
622 pc->b_data = NULL;
623}
624
625static void idetape_create_request_sense_cmd(struct ide_atapi_pc *pc) 607static void idetape_create_request_sense_cmd(struct ide_atapi_pc *pc)
626{ 608{
627 idetape_init_pc(pc); 609 ide_init_pc(pc);
628 pc->c[0] = REQUEST_SENSE; 610 pc->c[0] = REQUEST_SENSE;
629 pc->c[4] = 20; 611 pc->c[4] = 20;
630 pc->req_xfer = 20; 612 pc->req_xfer = 20;
@@ -816,7 +798,7 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
816/* A mode sense command is used to "sense" tape parameters. */ 798/* A mode sense command is used to "sense" tape parameters. */
817static void idetape_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code) 799static void idetape_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code)
818{ 800{
819 idetape_init_pc(pc); 801 ide_init_pc(pc);
820 pc->c[0] = MODE_SENSE; 802 pc->c[0] = MODE_SENSE;
821 if (page_code != IDETAPE_BLOCK_DESCRIPTOR) 803 if (page_code != IDETAPE_BLOCK_DESCRIPTOR)
822 /* DBD = 1 - Don't return block descriptors */ 804 /* DBD = 1 - Don't return block descriptors */
@@ -875,7 +857,7 @@ static void ide_tape_create_rw_cmd(idetape_tape_t *tape,
875 struct idetape_bh *bh = (struct idetape_bh *)rq->special; 857 struct idetape_bh *bh = (struct idetape_bh *)rq->special;
876 unsigned int length = rq->current_nr_sectors; 858 unsigned int length = rq->current_nr_sectors;
877 859
878 idetape_init_pc(pc); 860 ide_init_pc(pc);
879 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]); 861 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
880 pc->c[1] = 1; 862 pc->c[1] = 1;
881 pc->bh = bh; 863 pc->bh = bh;
@@ -1165,7 +1147,7 @@ static void idetape_init_merge_buffer(idetape_tape_t *tape)
1165static void idetape_create_write_filemark_cmd(ide_drive_t *drive, 1147static void idetape_create_write_filemark_cmd(ide_drive_t *drive,
1166 struct ide_atapi_pc *pc, int write_filemark) 1148 struct ide_atapi_pc *pc, int write_filemark)
1167{ 1149{
1168 idetape_init_pc(pc); 1150 ide_init_pc(pc);
1169 pc->c[0] = WRITE_FILEMARKS; 1151 pc->c[0] = WRITE_FILEMARKS;
1170 pc->c[4] = write_filemark; 1152 pc->c[4] = write_filemark;
1171 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1153 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
@@ -1173,7 +1155,7 @@ static void idetape_create_write_filemark_cmd(ide_drive_t *drive,
1173 1155
1174static void idetape_create_test_unit_ready_cmd(struct ide_atapi_pc *pc) 1156static void idetape_create_test_unit_ready_cmd(struct ide_atapi_pc *pc)
1175{ 1157{
1176 idetape_init_pc(pc); 1158 ide_init_pc(pc);
1177 pc->c[0] = TEST_UNIT_READY; 1159 pc->c[0] = TEST_UNIT_READY;
1178} 1160}
1179 1161
@@ -1200,7 +1182,7 @@ static int idetape_queue_pc_tail(ide_drive_t *drive, struct ide_atapi_pc *pc)
1200static void idetape_create_load_unload_cmd(ide_drive_t *drive, 1182static void idetape_create_load_unload_cmd(ide_drive_t *drive,
1201 struct ide_atapi_pc *pc, int cmd) 1183 struct ide_atapi_pc *pc, int cmd)
1202{ 1184{
1203 idetape_init_pc(pc); 1185 ide_init_pc(pc);
1204 pc->c[0] = START_STOP; 1186 pc->c[0] = START_STOP;
1205 pc->c[4] = cmd; 1187 pc->c[4] = cmd;
1206 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1188 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
@@ -1252,7 +1234,7 @@ static int idetape_flush_tape_buffers(ide_drive_t *drive)
1252 1234
1253static void idetape_create_read_position_cmd(struct ide_atapi_pc *pc) 1235static void idetape_create_read_position_cmd(struct ide_atapi_pc *pc)
1254{ 1236{
1255 idetape_init_pc(pc); 1237 ide_init_pc(pc);
1256 pc->c[0] = READ_POSITION; 1238 pc->c[0] = READ_POSITION;
1257 pc->req_xfer = 20; 1239 pc->req_xfer = 20;
1258} 1240}
@@ -1276,7 +1258,7 @@ static void idetape_create_locate_cmd(ide_drive_t *drive,
1276 struct ide_atapi_pc *pc, 1258 struct ide_atapi_pc *pc,
1277 unsigned int block, u8 partition, int skip) 1259 unsigned int block, u8 partition, int skip)
1278{ 1260{
1279 idetape_init_pc(pc); 1261 ide_init_pc(pc);
1280 pc->c[0] = POSITION_TO_ELEMENT; 1262 pc->c[0] = POSITION_TO_ELEMENT;
1281 pc->c[1] = 2; 1263 pc->c[1] = 2;
1282 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]); 1264 put_unaligned(cpu_to_be32(block), (unsigned int *) &pc->c[3]);
@@ -1293,7 +1275,7 @@ static int idetape_create_prevent_cmd(ide_drive_t *drive,
1293 if (!(tape->caps[6] & 0x01)) 1275 if (!(tape->caps[6] & 0x01))
1294 return 0; 1276 return 0;
1295 1277
1296 idetape_init_pc(pc); 1278 ide_init_pc(pc);
1297 pc->c[0] = ALLOW_MEDIUM_REMOVAL; 1279 pc->c[0] = ALLOW_MEDIUM_REMOVAL;
1298 pc->c[4] = prevent; 1280 pc->c[4] = prevent;
1299 return 1; 1281 return 1;
@@ -1408,7 +1390,7 @@ static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks,
1408 1390
1409static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc) 1391static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc)
1410{ 1392{
1411 idetape_init_pc(pc); 1393 ide_init_pc(pc);
1412 pc->c[0] = INQUIRY; 1394 pc->c[0] = INQUIRY;
1413 pc->c[4] = 254; 1395 pc->c[4] = 254;
1414 pc->req_xfer = 254; 1396 pc->req_xfer = 254;
@@ -1417,14 +1399,14 @@ static void idetape_create_inquiry_cmd(struct ide_atapi_pc *pc)
1417static void idetape_create_rewind_cmd(ide_drive_t *drive, 1399static void idetape_create_rewind_cmd(ide_drive_t *drive,
1418 struct ide_atapi_pc *pc) 1400 struct ide_atapi_pc *pc)
1419{ 1401{
1420 idetape_init_pc(pc); 1402 ide_init_pc(pc);
1421 pc->c[0] = REZERO_UNIT; 1403 pc->c[0] = REZERO_UNIT;
1422 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1404 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
1423} 1405}
1424 1406
1425static void idetape_create_erase_cmd(struct ide_atapi_pc *pc) 1407static void idetape_create_erase_cmd(struct ide_atapi_pc *pc)
1426{ 1408{
1427 idetape_init_pc(pc); 1409 ide_init_pc(pc);
1428 pc->c[0] = ERASE; 1410 pc->c[0] = ERASE;
1429 pc->c[1] = 1; 1411 pc->c[1] = 1;
1430 pc->flags |= PC_FLAG_WAIT_FOR_DSC; 1412 pc->flags |= PC_FLAG_WAIT_FOR_DSC;
@@ -1432,7 +1414,7 @@ static void idetape_create_erase_cmd(struct ide_atapi_pc *pc)
1432 1414
1433static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd) 1415static void idetape_create_space_cmd(struct ide_atapi_pc *pc, int count, u8 cmd)
1434{ 1416{
1435 idetape_init_pc(pc); 1417 ide_init_pc(pc);
1436 pc->c[0] = SPACE; 1418 pc->c[0] = SPACE;
1437 put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]); 1419 put_unaligned(cpu_to_be32(count), (unsigned int *) &pc->c[1]);
1438 pc->c[1] = cmd; 1420 pc->c[1] = cmd;
diff --git a/include/linux/ide.h b/include/linux/ide.h
index 03dc2157a2b5..bba2f73b99a0 100644
--- a/include/linux/ide.h
+++ b/include/linux/ide.h
@@ -724,6 +724,12 @@ enum {
724 PC_FLAG_TIMEDOUT = (1 << 7), 724 PC_FLAG_TIMEDOUT = (1 << 7),
725}; 725};
726 726
727/*
728 * With each packet command, we allocate a buffer of IDE_PC_BUFFER_SIZE bytes.
729 * This is used for several packet commands (not for READ/WRITE commands).
730 */
731#define IDE_PC_BUFFER_SIZE 256
732
727struct ide_atapi_pc { 733struct ide_atapi_pc {
728 /* actual packet bytes */ 734 /* actual packet bytes */
729 u8 c[12]; 735 u8 c[12];
@@ -753,7 +759,7 @@ struct ide_atapi_pc {
753 * those are more or less driver-specific and some of them are subject 759 * those are more or less driver-specific and some of them are subject
754 * to change/removal later. 760 * to change/removal later.
755 */ 761 */
756 u8 pc_buf[256]; 762 u8 pc_buf[IDE_PC_BUFFER_SIZE];
757 763
758 /* idetape only */ 764 /* idetape only */
759 struct idetape_bh *bh; 765 struct idetape_bh *bh;
@@ -1113,6 +1119,8 @@ void ide_pktcmd_tf_load(ide_drive_t *, u32, u16, u8);
1113 1119
1114int ide_check_atapi_device(ide_drive_t *, const char *); 1120int ide_check_atapi_device(ide_drive_t *, const char *);
1115 1121
1122void ide_init_pc(struct ide_atapi_pc *);
1123
1116ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc, 1124ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
1117 ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry, 1125 ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry,
1118 void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *), 1126 void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *),