mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] scsi: esp_scsi: report the residual byte count
@ 2026-11-18  0:37 Tim Douglas
  2026-11-18  4:11 ` Finn Thain
  0 siblings, 1 reply; 3+ messages in thread
From: Tim Douglas @ 2026-11-18  0:37 UTC (permalink / raw)
  To: mkp, James.Bottomley; +Cc: linux-scsi, linux-kernel

The ESP core tracks the number of bytes left to transfer in tot_residue
but does not report that count to the SCSI midlayer. As a result, SG_IO
returns a residual of zero even when a target transfers fewer bytes than
requested, as can happen with INQUIRY and MODE SENSE.

Report tot_residue with scsi_set_resid() when a command with a data
buffer completes with DID_OK. Initialize the scatterlist DMA length
on the identity-mapped PIO/pseudo-DMA path so the residual starts
from the buffer length on architectures with a separate DMA length.

On a Performa 6200CD with an out-of-tree ESP front end, an SG_IO
INQUIRY with an allocation length of 255 returns 36 bytes from the
internal CD-ROM drive. The residual is 219 with the fix and 0 before it.

AI assistance was used to investigate ESP transfer accounting and draft
the fix.

Signed-off-by: Tim Douglas <me@timdoug.com>
---
 drivers/scsi/esp_scsi.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
index 9993b0ae9..162f8fe14 100644
--- a/drivers/scsi/esp_scsi.c
+++ b/drivers/scsi/esp_scsi.c
@@ -388,6 +388,7 @@ static void esp_map_dma(struct esp *esp, struct scsi_cmnd *cmd)
 
 		scsi_for_each_sg(cmd, s, spriv->num_sg, i) {
 			s->dma_address = (uintptr_t)sg_virt(s);
+			sg_dma_len(s) = s->length;
 			total += sg_dma_len(s);
 		}
 	} else {
@@ -907,8 +908,11 @@ static void esp_cmd_is_done(struct esp *esp, struct esp_cmd_entry *ent,
 	esp_free_lun_tag(ent, dev->hostdata);
 	cmd->result = 0;
 	set_host_byte(cmd, host_byte);
-	if (host_byte == DID_OK)
+	if (host_byte == DID_OK) {
 		set_status_byte(cmd, ent->status);
+		if (cmd->sc_data_direction != DMA_NONE)
+			scsi_set_resid(cmd, ESP_CMD_PRIV(cmd)->tot_residue);
+	}
 
 	if (ent->eh_done) {
 		complete(ent->eh_done);

base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
-- 
2.39.5


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: esp_scsi: report the residual byte count
  2026-11-18  0:37 [PATCH] scsi: esp_scsi: report the residual byte count Tim Douglas
@ 2026-11-18  4:11 ` Finn Thain
  2026-11-18  5:13   ` Tim Douglas
  0 siblings, 1 reply; 3+ messages in thread
From: Finn Thain @ 2026-11-18  4:11 UTC (permalink / raw)
  To: Tim Douglas; +Cc: mkp, James.Bottomley, linux-scsi, linux-kernel


On Tue, 17 Nov 2026, Tim Douglas wrote:

> The ESP core tracks the number of bytes left to transfer in tot_residue
> but does not report that count to the SCSI midlayer. As a result, SG_IO
> returns a residual of zero even when a target transfers fewer bytes than
> requested, as can happen with INQUIRY and MODE SENSE.
> 
> Report tot_residue with scsi_set_resid() when a command with a data
> buffer completes with DID_OK. Initialize the scatterlist DMA length
> on the identity-mapped PIO/pseudo-DMA path so the residual starts
> from the buffer length on architectures with a separate DMA length.
> 
> On a Performa 6200CD with an out-of-tree ESP front end, an SG_IO
> INQUIRY with an allocation length of 255 returns 36 bytes from the
> internal CD-ROM drive. The residual is 219 with the fix and 0 before it.
> 
> AI assistance was used to investigate ESP transfer accounting and draft
> the fix.
> 
> Signed-off-by: Tim Douglas <me@timdoug.com>

Tested-by: Finn Thain <fthain@linux-m68k.org>

Regarding that front-end for the esp_scsi driver, do you think it can 
replace the mac53c94 driver? Has your driver been published yet?

> ---
>  drivers/scsi/esp_scsi.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c
> index 9993b0ae9..162f8fe14 100644
> --- a/drivers/scsi/esp_scsi.c
> +++ b/drivers/scsi/esp_scsi.c
> @@ -388,6 +388,7 @@ static void esp_map_dma(struct esp *esp, struct scsi_cmnd *cmd)
>  
>  		scsi_for_each_sg(cmd, s, spriv->num_sg, i) {
>  			s->dma_address = (uintptr_t)sg_virt(s);
> +			sg_dma_len(s) = s->length;
>  			total += sg_dma_len(s);
>  		}
>  	} else {
> @@ -907,8 +908,11 @@ static void esp_cmd_is_done(struct esp *esp, struct esp_cmd_entry *ent,
>  	esp_free_lun_tag(ent, dev->hostdata);
>  	cmd->result = 0;
>  	set_host_byte(cmd, host_byte);
> -	if (host_byte == DID_OK)
> +	if (host_byte == DID_OK) {
>  		set_status_byte(cmd, ent->status);
> +		if (cmd->sc_data_direction != DMA_NONE)
> +			scsi_set_resid(cmd, ESP_CMD_PRIV(cmd)->tot_residue);
> +	}
>  
>  	if (ent->eh_done) {
>  		complete(ent->eh_done);
> 
> base-commit: aebb7274476403040d582c61478df8f4a7bf9cd3
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scsi: esp_scsi: report the residual byte count
  2026-11-18  4:11 ` Finn Thain
@ 2026-11-18  5:13   ` Tim Douglas
  0 siblings, 0 replies; 3+ messages in thread
From: Tim Douglas @ 2026-11-18  5:13 UTC (permalink / raw)
  To: Finn Thain; +Cc: mkp, James.Bottomley, linux-scsi, linux-kernel

On Tue, Nov 17, 2026, at 11:11 PM, Finn Thain wrote:
> Regarding that front-end for the esp_scsi driver, do you think it can 
> replace the mac53c94 driver? Has your driver been published yet?

Thanks for testing! Probably not. The front end uses PrimeTime
pseudo-DMA like mac_esp, and a replacement for mac53c94 would need
DBDMA support. (The "cordyceps" Performa 52xx/62xx family is a bit of
an odd duck, essentially a PowerPC bolted onto Quadra-style IO.)

The driver is still in my local tree, happy to share the patch if
you’d like to take a look.

-Tim

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-18  5:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18  0:37 [PATCH] scsi: esp_scsi: report the residual byte count Tim Douglas
2026-11-18  4:11 ` Finn Thain
2026-11-18  5:13   ` Tim Douglas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®