Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1403481imm; Fri, 12 Oct 2018 18:12:58 -0700 (PDT) X-Google-Smtp-Source: ACcGV63wpnN13gHQSxqhsxdscaGBpWdB8TUMROeaxDuu+c0f62srwjRspubWOEcjkGdzpS93ba47 X-Received: by 2002:a63:2703:: with SMTP id n3-v6mr7728006pgn.113.1539393178431; Fri, 12 Oct 2018 18:12:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539393178; cv=none; d=google.com; s=arc-20160816; b=mHmcNfUlq15G2hHiSXOBH1yQzfzieXVKj2hRKMM1D7hNZrgGT6tVnOvIMskAoN7xDW ALfNRUiMEXLQ/asuCzYk6wy+atD/V3atp+S4tunyEulU9YUan3VTiigAJ9UiZHnYOD7B 27r6dBH30BhKe1TcxRYOwfJIAIfAGijeF/0mL1ZrG8OzfY5pejWyjBt7OF2WlYckNbkN dDC5CdtQeyVKHM2KiXnZO9mJEPAbanOcL7eFIvVqArnl/a4E1M7trw8ZqzVwoKbE6FGP jnKvULWfdkZFh/ShYkllG2ptOoj008f6bgoQe0kSA6iRoBxNqzyWpb9q7iscvdHTtp5H y2vg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:subject:from:references:in-reply-to :message-id:cc:to; bh=Pbyp66A5UUX0OuiQwWKfYOPlR683Acs4OcKrq5L1Ops=; b=yCx/kXCWfIhRvPvvNRixJ6aGIZyzbNmoKrzFz/o7amPJlpQGLdF/ia8rp1QSjuC3c4 c9+xe4hTUH8bYTGTSHoTZPrB8AGPoNgeR5FcpjRv3eHdDaN+GffE9ZJn4KeJBCP9dfYv XTI2vIn9njn6glZNb0pRwsbmg8OkcAL3nWn/Kae90bmjw3btJjqd62O7tLH1ByumVOxu u7g0WA/nwy8dw3vPUg6nhD4UNYIRszSDPc1Wx0x0VipMAUBo7HM9gtz1QeGuGj6BKJTe B3Wel/zYVnSFPWh+nJs8ihhlnNR/4sGfkGw5GrnOB1Zl1AgH1xO8cDhOO0KMrZtEuipI gNXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j91-v6si3034575pld.181.2018.10.12.18.12.43; Fri, 12 Oct 2018 18:12:58 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727040AbeJMIqy (ORCPT + 99 others); Sat, 13 Oct 2018 04:46:54 -0400 Received: from kvm5.telegraphics.com.au ([98.124.60.144]:47194 "EHLO kvm5.telegraphics.com.au" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726814AbeJMIqx (ORCPT ); Sat, 13 Oct 2018 04:46:53 -0400 Received: by kvm5.telegraphics.com.au (Postfix, from userid 502) id B5CE229FC6; Fri, 12 Oct 2018 21:11:48 -0400 (EDT) To: "James E.J. Bottomley" , "Martin K. Petersen" Cc: Michael Schmitz , Hannes Reinecke , linux-scsi@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-kernel@vger.kernel.org Message-Id: In-Reply-To: References: From: Finn Thain Subject: [PATCH 2/6] esp_scsi: Track residual for PIO transfers Date: Sat, 13 Oct 2018 11:51:16 +1100 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org If a target disconnects during a PIO data transfer the command may fail when the target reconnects: scsi host1: DMA length is zero! scsi host1: cur adr[04380000] len[00000000] The scsi bus is then reset. This happens because the residual reached zero before the transfer was completed. The usual residual calculation relies on the Transfer Count registers which works for DMA transfers but not for PIO transfers. Fix the problem by storing the PIO transfer residual and using that to correctly calculate bytes_sent. Fixes: 6fe07aaffbf0 Tested-by: Stan Johnson Signed-off-by: Finn Thain --- drivers/scsi/esp_scsi.c | 1 + drivers/scsi/esp_scsi.h | 2 ++ drivers/scsi/mac_esp.c | 2 ++ 3 files changed, 5 insertions(+) diff --git a/drivers/scsi/esp_scsi.c b/drivers/scsi/esp_scsi.c index c3fc34b9964d..9e5d3f7d29ae 100644 --- a/drivers/scsi/esp_scsi.c +++ b/drivers/scsi/esp_scsi.c @@ -1338,6 +1338,7 @@ static int esp_data_bytes_sent(struct esp *esp, struct esp_cmd_entry *ent, bytes_sent = esp->data_dma_len; bytes_sent -= ecount; + bytes_sent -= esp->send_cmd_residual; /* * The am53c974 has a DMA 'pecularity'. The doc states: diff --git a/drivers/scsi/esp_scsi.h b/drivers/scsi/esp_scsi.h index 8163dca2071b..db4b6ea94caa 100644 --- a/drivers/scsi/esp_scsi.h +++ b/drivers/scsi/esp_scsi.h @@ -540,6 +540,8 @@ struct esp { void *dma; int dmarev; + + int send_cmd_residual; }; /* A front-end driver for the ESP chip should do the following in diff --git a/drivers/scsi/mac_esp.c b/drivers/scsi/mac_esp.c index eb551f3cc471..71879f2207e0 100644 --- a/drivers/scsi/mac_esp.c +++ b/drivers/scsi/mac_esp.c @@ -427,6 +427,8 @@ static void mac_esp_send_pio_cmd(struct esp *esp, u32 addr, u32 esp_count, scsi_esp_cmd(esp, ESP_CMD_TI); } } + + esp->send_cmd_residual = esp_count; } static int mac_esp_irq_pending(struct esp *esp) -- 2.16.4