aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ide-tape.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2009-04-18 19:46:02 -0400
committerTejun Heo <tj@kernel.org>2009-04-18 19:46:02 -0400
commit21d9c5d227593d15630ae83a336d1519653e9b8a (patch)
tree00cae13e13a418768354b92bf5e48c2b85625a6d /drivers/ide/ide-tape.c
parent35ab8d3251833e4052aa64b09b08195e949518c7 (diff)
ide-tape: use standard data transfer mechanism
Impact: use standard way to transfer data ide-tape uses rq in an interesting way. For r/w requests, rq->special is used to carry a private buffer management structure idetape_bh and rq->nr_sectors and current_nr_sectors are initialized to the number of idetape blocks which isn't necessary 512 bytes. Also, rq->current_nr_sectors is used to report back the residual count in units of idetape blocks. This peculiarity taxes both block layer and ide. ide-atapi has different paths and hooks to accomodate it and what a rq means becomes quite confusing and making changes at the block layer becomes quite difficult and error-prone. This patch makes ide-tape use bio instead. With the previous patch, ide-tape currently is using single contiguos buffer so replacing it isn't difficult. Data buffer is mapped into bio using blk_rq_map_kern() in idetape_queue_rw_tail(). idetape_io_buffers() and idetape_update_buffers() are dropped and pc->bh is set to null to tell ide-atapi to use standard data transfer mechanism and idetape_bh byte counts are updated by the issuer on completion using the residual count. This change also nicely removes the FIXME in ide_pc_intr() where ide-tape rqs need to be completed using ide_rq_bytes() instead of blk_rq_bytes() (although this didn't really matter as the request didn't have bio). Signed-off-by: Tejun Heo <tj@kernel.org> Cc: Jens Axboe <jens.axboe@oracle.com>
Diffstat (limited to 'drivers/ide/ide-tape.c')
-rw-r--r--drivers/ide/ide-tape.c112
1 files changed, 23 insertions, 89 deletions
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c
index b2afbc7bcb6b..b373ac876352 100644
--- a/drivers/ide/ide-tape.c
+++ b/drivers/ide/ide-tape.c
@@ -292,65 +292,6 @@ static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i)
292 return tape; 292 return tape;
293} 293}
294 294
295static int idetape_input_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
296 unsigned int bcount)
297{
298 struct idetape_bh *bh = pc->bh;
299 int count;
300
301 if (bcount && bh) {
302 count = min(
303 (unsigned int)(bh->b_size - atomic_read(&bh->b_count)),
304 bcount);
305 drive->hwif->tp_ops->input_data(drive, NULL, bh->b_data +
306 atomic_read(&bh->b_count), count);
307 bcount -= count;
308 atomic_add(count, &bh->b_count);
309 if (atomic_read(&bh->b_count) == bh->b_size)
310 pc->bh = NULL;
311 }
312
313 return bcount;
314}
315
316static int idetape_output_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
317 unsigned int bcount)
318{
319 struct idetape_bh *bh = pc->bh;
320 int count;
321
322 if (bcount && bh) {
323 count = min((unsigned int)pc->b_count, (unsigned int)bcount);
324 drive->hwif->tp_ops->output_data(drive, NULL, pc->b_data, count);
325 bcount -= count;
326 pc->b_data += count;
327 pc->b_count -= count;
328 if (!pc->b_count)
329 pc->bh = NULL;
330 }
331
332 return bcount;
333}
334
335static void idetape_update_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc)
336{
337 struct idetape_bh *bh = pc->bh;
338 unsigned int bcount = pc->xferred;
339
340 if (pc->flags & PC_FLAG_WRITING)
341 return;
342 if (bcount) {
343 if (bh == NULL || bcount > bh->b_size) {
344 printk(KERN_ERR "ide-tape: bh == NULL in %s\n",
345 __func__);
346 return;
347 }
348 atomic_set(&bh->b_count, bcount);
349 if (atomic_read(&bh->b_count) == bh->b_size)
350 pc->bh = NULL;
351 }
352}
353
354/* 295/*
355 * called on each failed packet command retry to analyze the request sense. We 296 * called on each failed packet command retry to analyze the request sense. We
356 * currently do not utilize this information. 297 * currently do not utilize this information.
@@ -368,12 +309,10 @@ static void idetape_analyze_error(ide_drive_t *drive, u8 *sense)
368 pc->c[0], tape->sense_key, tape->asc, tape->ascq); 309 pc->c[0], tape->sense_key, tape->asc, tape->ascq);
369 310
370 /* Correct pc->xferred by asking the tape. */ 311 /* Correct pc->xferred by asking the tape. */
371 if (pc->flags & PC_FLAG_DMA_ERROR) { 312 if (pc->flags & PC_FLAG_DMA_ERROR)
372 pc->xferred = pc->req_xfer - 313 pc->xferred = pc->req_xfer -
373 tape->blk_size * 314 tape->blk_size *
374 get_unaligned_be32(&sense[3]); 315 get_unaligned_be32(&sense[3]);
375 idetape_update_buffers(drive, pc);
376 }
377 316
378 /* 317 /*
379 * If error was the result of a zero-length read or write command, 318 * If error was the result of a zero-length read or write command,
@@ -458,7 +397,7 @@ static int ide_tape_callback(ide_drive_t *drive, int dsc)
458 } 397 }
459 398
460 tape->first_frame += blocks; 399 tape->first_frame += blocks;
461 rq->current_nr_sectors -= blocks; 400 rq->data_len -= blocks * tape->blk_size;
462 401
463 if (pc->error) { 402 if (pc->error) {
464 uptodate = 0; 403 uptodate = 0;
@@ -520,19 +459,6 @@ static void ide_tape_handle_dsc(ide_drive_t *drive)
520 idetape_postpone_request(drive); 459 idetape_postpone_request(drive);
521} 460}
522 461
523static int ide_tape_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
524 unsigned int bcount, int write)
525{
526 unsigned int bleft;
527
528 if (write)
529 bleft = idetape_output_buffers(drive, pc, bcount);
530 else
531 bleft = idetape_input_buffers(drive, pc, bcount);
532
533 return bcount - bleft;
534}
535
536/* 462/*
537 * Packet Command Interface 463 * Packet Command Interface
538 * 464 *
@@ -683,7 +609,7 @@ static void ide_tape_create_rw_cmd(idetape_tape_t *tape,
683 ide_init_pc(pc); 609 ide_init_pc(pc);
684 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]); 610 put_unaligned(cpu_to_be32(length), (unsigned int *) &pc->c[1]);
685 pc->c[1] = 1; 611 pc->c[1] = 1;
686 pc->bh = bh; 612 pc->bh = NULL;
687 pc->buf = NULL; 613 pc->buf = NULL;
688 pc->buf_size = length * tape->blk_size; 614 pc->buf_size = length * tape->blk_size;
689 pc->req_xfer = pc->buf_size; 615 pc->req_xfer = pc->buf_size;
@@ -1063,10 +989,12 @@ static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks,
1063 struct idetape_bh *bh) 989 struct idetape_bh *bh)
1064{ 990{
1065 idetape_tape_t *tape = drive->driver_data; 991 idetape_tape_t *tape = drive->driver_data;
992 size_t size = blocks * tape->blk_size;
1066 struct request *rq; 993 struct request *rq;
1067 int ret, errors; 994 int ret;
1068 995
1069 debug_log(DBG_SENSE, "%s: cmd=%d\n", __func__, cmd); 996 debug_log(DBG_SENSE, "%s: cmd=%d\n", __func__, cmd);
997 BUG_ON(cmd != REQ_IDETAPE_READ && cmd != REQ_IDETAPE_WRITE);
1070 998
1071 rq = blk_get_request(drive->queue, READ, __GFP_WAIT); 999 rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
1072 rq->cmd_type = REQ_TYPE_SPECIAL; 1000 rq->cmd_type = REQ_TYPE_SPECIAL;
@@ -1074,21 +1002,29 @@ static int idetape_queue_rw_tail(ide_drive_t *drive, int cmd, int blocks,
1074 rq->rq_disk = tape->disk; 1002 rq->rq_disk = tape->disk;
1075 rq->special = (void *)bh; 1003 rq->special = (void *)bh;
1076 rq->sector = tape->first_frame; 1004 rq->sector = tape->first_frame;
1077 rq->nr_sectors = blocks; 1005
1078 rq->current_nr_sectors = blocks; 1006 if (size) {
1007 ret = blk_rq_map_kern(drive->queue, rq, bh->b_data, size,
1008 __GFP_WAIT);
1009 if (ret)
1010 goto out_put;
1011 }
1012
1079 blk_execute_rq(drive->queue, tape->disk, rq, 0); 1013 blk_execute_rq(drive->queue, tape->disk, rq, 0);
1080 1014
1081 errors = rq->errors; 1015 /* calculate the number of transferred bytes and update bh */
1082 ret = tape->blk_size * (blocks - rq->current_nr_sectors); 1016 size -= rq->data_len;
1083 blk_put_request(rq); 1017 if (cmd == REQ_IDETAPE_READ)
1018 atomic_add(size, &bh->b_count);
1084 1019
1085 if ((cmd & (REQ_IDETAPE_READ | REQ_IDETAPE_WRITE)) == 0) 1020 ret = size;
1086 return 0; 1021 if (rq->errors == IDE_DRV_ERROR_GENERAL)
1022 ret = -EIO;
1087 1023
1088 if (tape->merge_bh) 1024 if (tape->merge_bh)
1089 idetape_init_merge_buffer(tape); 1025 idetape_init_merge_buffer(tape);
1090 if (errors == IDE_DRV_ERROR_GENERAL) 1026out_put:
1091 return -EIO; 1027 blk_put_request(rq);
1092 return ret; 1028 return ret;
1093} 1029}
1094 1030
@@ -2034,8 +1970,6 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
2034 u16 *ctl = (u16 *)&tape->caps[12]; 1970 u16 *ctl = (u16 *)&tape->caps[12];
2035 1971
2036 drive->pc_callback = ide_tape_callback; 1972 drive->pc_callback = ide_tape_callback;
2037 drive->pc_update_buffers = idetape_update_buffers;
2038 drive->pc_io_buffers = ide_tape_io_buffers;
2039 1973
2040 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP; 1974 drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
2041 1975