ide: add ide_pad_transfer() helper
PATCH 1/5 ide: add ide_pad_transfer() helper
* Add ide_pad_transfer() helper (which uses ->{in,out}put_data methods internally so the transfer is also padded to drive+host requirements) and use it instead of ide_atapi_{write_zeros,discard_data}().
* Remove no longer needed ide_atapi_{write_zeros,discard_data}().
--- drivers/ide/ide-floppy.c | 7 ++----- drivers/ide/ide-io.c | 15 +++++++++++++++ drivers/ide/ide-tape.c | 4 ++-- drivers/scsi/ide-scsi.c | 6 +++--- include/linux/ide.h | 25 ++----------------------- 5 files changed, 24 insertions(+), 33 deletions(-)
drivers/ide/ide-floppy.c +2 -5
@@ -262,10 +262,7 @@ static void ide_floppy_io_buffers(ide_drif (bcount) {printk (KERN_ERR "%s: leftover data in %s, bcount == %d\n" , drive->name, __func__, bcount); -if (direction) -ide_atapi_write_zeros (drive, bcount); -else -ide_atapi_discard_data (drive, bcount); +ide_pad_transfer (drive, direction, bcount); } }
@@ -491,7 +488,7 @@ static ide_startstop_t idefloppy_pc_intrprintk (KERN_ERR "ide-floppy: The floppy wants " "to send us more data than expected " "- discarding data\n" ); -ide_atapi_discard_data (drive, bcount); +ide_pad_transfer (drive,0 , bcount); ide_set_handler(drive, &idefloppy_pc_intr,
drivers/ide/ide-io.c +15 -0
@@ -1642,3 +1642,18 @@ void ide_pktcmd_tf_load(ide_drive_t *dri }EXPORT_SYMBOL_GPL (ide_pktcmd_tf_load); + +void ide_pad_transfer (ide_drive_t *drive,int write,int len) +{ +ide_hwif_t *hwif = drive->hwif; +u8 buf[4 ] = {0 }; + +while (len >0 ) { +if (write) + hwif->output_data (drive,NULL , buf,min (4 , len)); +else + hwif->input_data (drive,NULL , buf,min (4 , len)); + len -=4 ; + } +} +EXPORT_SYMBOL_GPL (ide_pad_transfer);
drivers/ide/ide-tape.c +2 -2
@@ -395,7 +395,7 @@ static void idetape_input_buffers(ide_drif (bh ==NULL ) {printk (KERN_ERR "ide-tape: bh == NULL in " "idetape_input_buffers\n" ); -ide_atapi_discard_data (drive, bcount); +ide_pad_transfer (drive,0 , bcount);return ; } count = min(
@@ -871,7 +871,7 @@ static ide_startstop_t idetape_pc_intr(iprintk (KERN_ERR "ide-tape: The tape wants to " "send us more data than expected " "- discarding data\n" ); -ide_atapi_discard_data (drive, bcount); +ide_pad_transfer (drive,0 , bcount);ide_set_handler (drive, &idetape_pc_intr,IDETAPE_WAIT_CMD ,NULL );return ide_started;
drivers/scsi/ide-scsi.c +3 -3
@@ -164,7 +164,7 @@ static void idescsi_input_buffers(ide_drif (bcount) {printk (KERN_ERR "ide-scsi: scatter gather table too small, discarding data\n" ); -ide_atapi_discard_data (drive, bcount); +ide_pad_transfer (drive,0 , bcount); } }
@@ -201,7 +201,7 @@ static void idescsi_output_buffers(ide_dif (bcount) {printk (KERN_ERR "ide-scsi: scatter gather table too small, padding with zeros\n" ); -ide_atapi_write_zeros (drive, bcount); +ide_pad_transfer (drive,1 , bcount); } }
@@ -438,7 +438,7 @@ static ide_startstop_t idescsi_pc_intr ( } pc->xferred += temp; pc->cur_pos += temp; -ide_atapi_discard_data (drive, bcount - temp); +ide_pad_transfer (drive,0 , bcount - temp);ide_set_handler (drive, &idescsi_pc_intr,get_timeout (pc), idescsi_expiry);return ide_started; }
include/linux/ide.h +2 -23
@@ -816,6 +816,8 @@ void ide_execute_command(ide_drive_t *,void ide_execute_pkt_cmd (ide_drive_t *); +void ide_pad_transfer (ide_drive_t *,int ,int ); +ide_startstop_t __ide_error (ide_drive_t *,struct request *,u8 ,u8 );ide_startstop_t ide_error (ide_drive_t *drive,const char *msg,byte stat);
@@ -1346,27 +1348,4 @@ static inline u8 ide_read_error(ide_driv return hwif->INB(hwif->io_ports.error_addr); } - -/* -* Too bad. The drive wants to send us data which we are not ready to accept. -* Just throw it away. -*/ -static inline void ide_atapi_discard_data (ide_drive_t *drive,unsigned bcount) -{ -ide_hwif_t *hwif = drive->hwif; - -/* FIXME: use ->input_data */ -while (bcount--) - (void )hwif->INB (hwif->io_ports.data_addr); -} - -static inline void ide_atapi_write_zeros (ide_drive_t *drive,unsigned bcount) -{ -ide_hwif_t *hwif = drive->hwif; - -/* FIXME: use ->output_data */ -while (bcount--) - hwif->OUTB (0 , hwif->io_ports.data_addr); -} -#endif /* _IDE_H */
Quoted 8 lines · Bartlomiej Zolnierkiewicz
* Add
ide_pad_transfer()helper (which uses ->{in,out}put_data methods internally so the transfer is also padded to drive+host requirements) and use it instead of ide_atapi_{write_zeros,discard_data}().* Remove no longer needed ide_atapi_{write_zeros,discard_data}().
Cc Borislav Petkov <[email protected]>Signed-off-by Bartlomiej Zolnierkiewicz <[email protected]>
Quoted 84 lines
Index:
b/drivers/ide/ide-tape.c
===================================================================drivers/ide/ide-tape.c +2
-2@@ -395,7 +395,7 @@ static void idetape_input_buffers(ide_drif (bh ==NULL ) {printk (KERN_ERR "ide-tape: bh == NULL in " "idetape_input_buffers\n" ); -ide_atapi_discard_data (drive, bcount); +ide_pad_transfer (drive,0 , bcount);return ; } count = min(@@ -871,7 +871,7 @@ static ide_startstop_t idetape_pc_intr(iprintk (KERN_ERR "ide-tape: The tape wants to " "send us more data than expected " "- discarding data\n" ); -ide_atapi_discard_data (drive, bcount); +ide_pad_transfer (drive,0 , bcount);ide_set_handler (drive, &idetape_pc_intr,IDETAPE_WAIT_CMD ,NULL );return ide_started;Index:
b/drivers/scsi/ide-scsi.c
===================================================================drivers/scsi/ide-scsi.c +3
-3@@ -164,7 +164,7 @@ static void idescsi_input_buffers(ide_drif (bcount) {printk (KERN_ERR "ide-scsi: scatter gather table too small, discarding data\n" ); -ide_atapi_discard_data (drive, bcount); +ide_pad_transfer (drive,0 , bcount); } }@@ -201,7 +201,7 @@ static void idescsi_output_buffers(ide_dif (bcount) {printk (KERN_ERR "ide-scsi: scatter gather table too small, padding with zeros\n" ); -ide_atapi_write_zeros (drive, bcount); +ide_pad_transfer (drive,1 , bcount); } }@@ -438,7 +438,7 @@ static ide_startstop_t idescsi_pc_intr ( } pc->xferred += temp; pc->cur_pos += temp; -ide_atapi_discard_data (drive, bcount - temp); +ide_pad_transfer (drive,0 , bcount - temp);ide_set_handler (drive, &idescsi_pc_intr,get_timeout (pc), idescsi_expiry);return ide_started; }Index:
b/include/linux/ide.h
===================================================================include/linux/ide.h +2
-14@@ -816,6 +816,8 @@ void ide_execute_command(ide_drive_t *,void ide_execute_pkt_cmd (ide_drive_t *); +void ide_pad_transfer (ide_drive_t *,int ,int ); +ide_startstop_t __ide_error (ide_drive_t *,struct request *,u8 ,u8 );ide_startstop_t ide_error (ide_drive_t *drive,const char *msg,byte stat);@@ -1346,27 +1348,4 @@ static inline u8 ide_read_error(ide_drivreturn hwif->INB (hwif->io_ports.error_addr); } - -/* -* Too bad. The drive wants to send us data which we are not ready to accept. -* Just throw it away. -*/ -static inline void ide_atapi_discard_data (ide_drive_t *drive,unsigned bcount) -{ -ide_hwif_t *hwif = drive->hwif; - -/* FIXME: use ->input_data */ -while (bcount--) - (void )hwif->INB (hwif->io_ports.data_addr); -} -
include/linux/ide.h static inline u8 ide_read_error(ide_driv · line 1351
Quoted 10 lines
include/linux/ide.h +0
-9-static inline void ide_atapi_write_zeros (ide_drive_t *drive,unsigned bcount) -{ -ide_hwif_t *hwif = drive->hwif; - -/* FIXME: use ->output_data */ -while (bcount--) - hwif->OUTB (0 , hwif->io_ports.data_addr); -} -#endif /* _IDE_H */
I doubt that these ever worked as expected since you can't hope that the
IDE data transfers are 8-bit if you use 8-bit I/O -- they will be 16-bit anyway. So, this patch is not just a cleanup, it's fixing a bug. :-)
MBR, Sergei