diff options
author | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2008-10-10 16:39:36 -0400 |
---|---|---|
committer | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2008-10-10 16:39:36 -0400 |
commit | acaa0f5f675ccf6b8a3a11a933419068b1ea1f46 (patch) | |
tree | 8afee71c69bf765a5edd0de82c98c6470905ec20 /drivers/ide | |
parent | c860f955681ebd83df4a03089f1910fc4b54651f (diff) |
ide: add ide_io_buffers() helper
* Make ->io_buffers method return number of bytes transferred.
* Use ide_end_request() instead of idefloppy_end_request()
in ide_floppy_io_buffers() and then move the call out to
ide_pc_intr().
* Add ide_io_buffers() helper and convert ide-{floppy,scsi}.c
to use it instead of ide*_io_buffers().
There should be no functional changes caused by this patch.
Acked-by: Borislav Petkov <petkovbb@gmail.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers/ide')
-rw-r--r-- | drivers/ide/ide-atapi.c | 63 | ||||
-rw-r--r-- | drivers/ide/ide-floppy.c | 47 | ||||
-rw-r--r-- | drivers/ide/ide-tape.c | 4 |
3 files changed, 63 insertions, 51 deletions
diff --git a/drivers/ide/ide-atapi.c b/drivers/ide/ide-atapi.c index 61c52fb665ca..3d44b45650f6 100644 --- a/drivers/ide/ide-atapi.c +++ b/drivers/ide/ide-atapi.c | |||
@@ -61,12 +61,62 @@ int ide_check_atapi_device(ide_drive_t *drive, const char *s) | |||
61 | } | 61 | } |
62 | EXPORT_SYMBOL_GPL(ide_check_atapi_device); | 62 | EXPORT_SYMBOL_GPL(ide_check_atapi_device); |
63 | 63 | ||
64 | /* PIO data transfer routine using the scatter gather table. */ | ||
65 | int ide_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc, | ||
66 | unsigned int bcount, int write) | ||
67 | { | ||
68 | ide_hwif_t *hwif = drive->hwif; | ||
69 | const struct ide_tp_ops *tp_ops = hwif->tp_ops; | ||
70 | xfer_func_t *xf = write ? tp_ops->output_data : tp_ops->input_data; | ||
71 | struct scatterlist *sg = pc->sg; | ||
72 | char *buf; | ||
73 | int count, done = 0; | ||
74 | |||
75 | while (bcount) { | ||
76 | count = min(sg->length - pc->b_count, bcount); | ||
77 | |||
78 | if (PageHighMem(sg_page(sg))) { | ||
79 | unsigned long flags; | ||
80 | |||
81 | local_irq_save(flags); | ||
82 | buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset; | ||
83 | xf(drive, NULL, buf + pc->b_count, count); | ||
84 | kunmap_atomic(buf - sg->offset, KM_IRQ0); | ||
85 | local_irq_restore(flags); | ||
86 | } else { | ||
87 | buf = sg_virt(sg); | ||
88 | xf(drive, NULL, buf + pc->b_count, count); | ||
89 | } | ||
90 | |||
91 | bcount -= count; | ||
92 | pc->b_count += count; | ||
93 | done += count; | ||
94 | |||
95 | if (pc->b_count == sg->length) { | ||
96 | if (!--pc->sg_cnt) | ||
97 | break; | ||
98 | pc->sg = sg = sg_next(sg); | ||
99 | pc->b_count = 0; | ||
100 | } | ||
101 | } | ||
102 | |||
103 | if (bcount) { | ||
104 | printk(KERN_ERR "%s: %d leftover bytes, %s\n", drive->name, | ||
105 | bcount, write ? "padding with zeros" | ||
106 | : "discarding data"); | ||
107 | ide_pad_transfer(drive, write, bcount); | ||
108 | } | ||
109 | |||
110 | return done; | ||
111 | } | ||
112 | EXPORT_SYMBOL_GPL(ide_io_buffers); | ||
113 | |||
64 | /* TODO: unify the code thus making some arguments go away */ | 114 | /* TODO: unify the code thus making some arguments go away */ |
65 | ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc, | 115 | ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc, |
66 | ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry, | 116 | ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry, |
67 | void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *), | 117 | void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *), |
68 | void (*retry_pc)(ide_drive_t *), void (*dsc_handle)(ide_drive_t *), | 118 | void (*retry_pc)(ide_drive_t *), void (*dsc_handle)(ide_drive_t *), |
69 | void (*io_buffers)(ide_drive_t *, struct ide_atapi_pc *, unsigned, int)) | 119 | int (*io_buffers)(ide_drive_t *, struct ide_atapi_pc *, unsigned, int)) |
70 | { | 120 | { |
71 | ide_hwif_t *hwif = drive->hwif; | 121 | ide_hwif_t *hwif = drive->hwif; |
72 | struct request *rq = hwif->hwgroup->rq; | 122 | struct request *rq = hwif->hwgroup->rq; |
@@ -219,9 +269,14 @@ cmd_finished: | |||
219 | 269 | ||
220 | if ((drive->media == ide_floppy && !scsi && !pc->buf) || | 270 | if ((drive->media == ide_floppy && !scsi && !pc->buf) || |
221 | (drive->media == ide_tape && !scsi && pc->bh) || | 271 | (drive->media == ide_tape && !scsi && pc->bh) || |
222 | (scsi && pc->sg)) | 272 | (scsi && pc->sg)) { |
223 | io_buffers(drive, pc, bcount, !!(pc->flags & PC_FLAG_WRITING)); | 273 | int done = io_buffers(drive, pc, bcount, |
224 | else | 274 | !!(pc->flags & PC_FLAG_WRITING)); |
275 | |||
276 | /* FIXME: don't do partial completions */ | ||
277 | if (drive->media == ide_floppy && !scsi) | ||
278 | ide_end_request(drive, 1, done >> 9); | ||
279 | } else | ||
225 | xferfunc(drive, NULL, pc->cur_pos, bcount); | 280 | xferfunc(drive, NULL, pc->cur_pos, bcount); |
226 | 281 | ||
227 | /* Update the current position */ | 282 | /* Update the current position */ |
diff --git a/drivers/ide/ide-floppy.c b/drivers/ide/ide-floppy.c index a0a8ad3a3038..38dca45ffd11 100644 --- a/drivers/ide/ide-floppy.c +++ b/drivers/ide/ide-floppy.c | |||
@@ -208,51 +208,6 @@ static int idefloppy_end_request(ide_drive_t *drive, int uptodate, int nsecs) | |||
208 | return 0; | 208 | return 0; |
209 | } | 209 | } |
210 | 210 | ||
211 | static void ide_floppy_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc, | ||
212 | unsigned int bcount, int direction) | ||
213 | { | ||
214 | ide_hwif_t *hwif = drive->hwif; | ||
215 | const struct ide_tp_ops *tp_ops = hwif->tp_ops; | ||
216 | xfer_func_t *xf = direction ? tp_ops->output_data : tp_ops->input_data; | ||
217 | struct scatterlist *sg = pc->sg; | ||
218 | char *buf; | ||
219 | int count, done = 0; | ||
220 | |||
221 | while (bcount) { | ||
222 | count = min(sg->length - pc->b_count, bcount); | ||
223 | if (PageHighMem(sg_page(sg))) { | ||
224 | unsigned long flags; | ||
225 | |||
226 | local_irq_save(flags); | ||
227 | buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset; | ||
228 | xf(drive, NULL, buf + pc->b_count, count); | ||
229 | kunmap_atomic(buf - sg->offset, KM_IRQ0); | ||
230 | local_irq_restore(flags); | ||
231 | } else { | ||
232 | buf = sg_virt(sg); | ||
233 | xf(drive, NULL, buf + pc->b_count, count); | ||
234 | } | ||
235 | bcount -= count; | ||
236 | pc->b_count += count; | ||
237 | done += count; | ||
238 | |||
239 | if (pc->b_count == sg->length) { | ||
240 | if (!--pc->sg_cnt) | ||
241 | break; | ||
242 | pc->sg = sg = sg_next(sg); | ||
243 | pc->b_count = 0; | ||
244 | } | ||
245 | } | ||
246 | |||
247 | idefloppy_end_request(drive, 1, done >> 9); | ||
248 | |||
249 | if (bcount) { | ||
250 | printk(KERN_ERR "%s: leftover data in %s, bcount == %d\n", | ||
251 | drive->name, __func__, bcount); | ||
252 | ide_pad_transfer(drive, direction, bcount); | ||
253 | } | ||
254 | } | ||
255 | |||
256 | static void idefloppy_update_buffers(ide_drive_t *drive, | 211 | static void idefloppy_update_buffers(ide_drive_t *drive, |
257 | struct ide_atapi_pc *pc) | 212 | struct ide_atapi_pc *pc) |
258 | { | 213 | { |
@@ -356,7 +311,7 @@ static ide_startstop_t idefloppy_pc_intr(ide_drive_t *drive) | |||
356 | 311 | ||
357 | return ide_pc_intr(drive, floppy->pc, idefloppy_pc_intr, | 312 | return ide_pc_intr(drive, floppy->pc, idefloppy_pc_intr, |
358 | IDEFLOPPY_WAIT_CMD, NULL, idefloppy_update_buffers, | 313 | IDEFLOPPY_WAIT_CMD, NULL, idefloppy_update_buffers, |
359 | idefloppy_retry_pc, NULL, ide_floppy_io_buffers); | 314 | idefloppy_retry_pc, NULL, ide_io_buffers); |
360 | } | 315 | } |
361 | 316 | ||
362 | /* | 317 | /* |
diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c index ba05e03f482b..d4a9c471dd13 100644 --- a/drivers/ide/ide-tape.c +++ b/drivers/ide/ide-tape.c | |||
@@ -693,13 +693,15 @@ static void ide_tape_handle_dsc(ide_drive_t *drive) | |||
693 | idetape_postpone_request(drive); | 693 | idetape_postpone_request(drive); |
694 | } | 694 | } |
695 | 695 | ||
696 | static void ide_tape_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc, | 696 | static int ide_tape_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc, |
697 | unsigned int bcount, int write) | 697 | unsigned int bcount, int write) |
698 | { | 698 | { |
699 | if (write) | 699 | if (write) |
700 | idetape_output_buffers(drive, pc, bcount); | 700 | idetape_output_buffers(drive, pc, bcount); |
701 | else | 701 | else |
702 | idetape_input_buffers(drive, pc, bcount); | 702 | idetape_input_buffers(drive, pc, bcount); |
703 | |||
704 | return bcount; | ||
703 | } | 705 | } |
704 | 706 | ||
705 | /* | 707 | /* |