From patchwork Thu Aug 19 09:07:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 500088 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EC83C432BE for ; Thu, 19 Aug 2021 09:07:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 122F861131 for ; Thu, 19 Aug 2021 09:07:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237366AbhHSJII (ORCPT ); Thu, 19 Aug 2021 05:08:08 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:36568 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233610AbhHSJIF (ORCPT ); Thu, 19 Aug 2021 05:08:05 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id DC89F1FD81; Thu, 19 Aug 2021 09:07:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1629364048; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vzVADz+Kf84Em2VIqSo+kGQ/+/AN5K492O7aD2WADc0=; b=CBEz2Ryvq55TkvnUCcAYmIYrI7Ix93aJbi0Pp19/HnE6FiCLzXVJSyd7FSicUlfCMdR/SW O+qJl5dRGqa4Of0oEwaSQFfmM1CiFwjITeJWcI67Y07QmoVtZJmtbJXyGakZ36hWLOF6bN /SlKsmoRhSNwljwqc+MmGnjz0LvuvOc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1629364048; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vzVADz+Kf84Em2VIqSo+kGQ/+/AN5K492O7aD2WADc0=; b=YTBQz2OTgJruAmBIiFGcp32n7l5dBE4nW3tUuba60MSfTYXF/H3nBAPF6eGbuw7GVhBawJ BLCKvQlNKsbSluDg== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 1F30AA3BA7; Thu, 19 Aug 2021 09:07:19 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id C5B11518D275; Thu, 19 Aug 2021 11:07:28 +0200 (CEST) From: Hannes Reinecke To: "Martin K. Petersen" Cc: Christoph Hellwig , James Bottomley , Matthew Wilcox , linux-scsi@vger.kernel.org, Hannes Reinecke Subject: [PATCH 1/4] sym53c8xx_2: move PCI EEH handling to host reset Date: Thu, 19 Aug 2021 11:07:13 +0200 Message-Id: <20210819090716.94049-2-hare@suse.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210819090716.94049-1-hare@suse.de> References: <20210819090716.94049-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org When PCI EEH is active the entire card will be reset; which means that we _have_ to do the equivalent of a eh_host_reset(). So trying to do it from other EH callbacks is pointless, and we should delegate it to eh_host_reset(). Signed-off-by: Hannes Reinecke Reviewed-by: Christoph Hellwig --- drivers/scsi/sym53c8xx_2/sym_glue.c | 97 ++++++++++++++++++----------- 1 file changed, 60 insertions(+), 37 deletions(-) diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c index 16b65fc4405c..dafdab5869fa 100644 --- a/drivers/scsi/sym53c8xx_2/sym_glue.c +++ b/drivers/scsi/sym53c8xx_2/sym_glue.c @@ -569,12 +569,11 @@ static void sym53c8xx_timer(struct timer_list *t) * Generic method for our eh processing. * The 'op' argument tells what we have to do. */ -static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd) +static int sym_eh_handler(struct Scsi_Host *shost, int op, + char *opname, struct scsi_cmnd *cmd) { struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd); - struct Scsi_Host *shost = cmd->device->host; struct sym_data *sym_data = shost_priv(shost); - struct pci_dev *pdev = sym_data->pdev; struct sym_hcb *np = sym_data->ncb; SYM_QUEHEAD *qp; int cmd_queued = 0; @@ -583,36 +582,6 @@ static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd) scmd_printk(KERN_WARNING, cmd, "%s operation started\n", opname); - /* We may be in an error condition because the PCI bus - * went down. In this case, we need to wait until the - * PCI bus is reset, the card is reset, and only then - * proceed with the scsi error recovery. There's no - * point in hurrying; take a leisurely wait. - */ -#define WAIT_FOR_PCI_RECOVERY 35 - if (pci_channel_offline(pdev)) { - int finished_reset = 0; - init_completion(&eh_done); - spin_lock_irq(shost->host_lock); - /* Make sure we didn't race */ - if (pci_channel_offline(pdev)) { - BUG_ON(sym_data->io_reset); - sym_data->io_reset = &eh_done; - } else { - finished_reset = 1; - } - spin_unlock_irq(shost->host_lock); - if (!finished_reset) - finished_reset = wait_for_completion_timeout - (sym_data->io_reset, - WAIT_FOR_PCI_RECOVERY*HZ); - spin_lock_irq(shost->host_lock); - sym_data->io_reset = NULL; - spin_unlock_irq(shost->host_lock); - if (!finished_reset) - return SCSI_FAILED; - } - spin_lock_irq(shost->host_lock); /* This one is queued in some place -> to wait for completion */ FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) { @@ -672,22 +641,76 @@ static int sym_eh_handler(int op, char *opname, struct scsi_cmnd *cmd) */ static int sym53c8xx_eh_abort_handler(struct scsi_cmnd *cmd) { - return sym_eh_handler(SYM_EH_ABORT, "ABORT", cmd); + struct Scsi_Host *shost = cmd->device->host; + struct sym_data *sym_data = shost_priv(shost); + struct pci_dev *pdev = sym_data->pdev; + + if (pci_channel_offline(pdev)) + return FAILED; + return sym_eh_handler(shost, SYM_EH_ABORT, "ABORT", cmd); } static int sym53c8xx_eh_device_reset_handler(struct scsi_cmnd *cmd) { - return sym_eh_handler(SYM_EH_DEVICE_RESET, "DEVICE RESET", cmd); + struct Scsi_Host *shost = cmd->device->host; + struct sym_data *sym_data = shost_priv(shost); + struct pci_dev *pdev = sym_data->pdev; + + if (pci_channel_offline(pdev)) + return FAILED; + return sym_eh_handler(shost, SYM_EH_DEVICE_RESET, "DEVICE RESET", cmd); } static int sym53c8xx_eh_bus_reset_handler(struct scsi_cmnd *cmd) { - return sym_eh_handler(SYM_EH_BUS_RESET, "BUS RESET", cmd); + struct Scsi_Host *shost = cmd->device->host; + struct sym_data *sym_data = shost_priv(shost); + struct pci_dev *pdev = sym_data->pdev; + + if (pci_channel_offline(pdev)) + return FAILED; + return sym_eh_handler(shost, SYM_EH_BUS_RESET, "BUS RESET", cmd); } static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd *cmd) { - return sym_eh_handler(SYM_EH_HOST_RESET, "HOST RESET", cmd); + struct Scsi_Host *shost = cmd->device->host; + struct sym_data *sym_data = shost_priv(shost); + struct pci_dev *pdev = sym_data->pdev; + + /* We may be in an error condition because the PCI bus + * went down. In this case, we need to wait until the + * PCI bus is reset, the card is reset, and only then + * proceed with the scsi error recovery. There's no + * point in hurrying; take a leisurely wait. + */ +#define WAIT_FOR_PCI_RECOVERY 35 + if (pci_channel_offline(pdev)) { + struct completion eh_done; + int finished_reset = 0; + + init_completion(&eh_done); + spin_lock_irq(shost->host_lock); + /* Make sure we didn't race */ + if (pci_channel_offline(pdev)) { + BUG_ON(sym_data->io_reset); + sym_data->io_reset = &eh_done; + } else { + finished_reset = 1; + } + spin_unlock_irq(shost->host_lock); + if (!finished_reset) + finished_reset = wait_for_completion_timeout + (sym_data->io_reset, + WAIT_FOR_PCI_RECOVERY*HZ); + spin_lock_irq(shost->host_lock); + sym_data->io_reset = NULL; + spin_unlock_irq(shost->host_lock); + if (!finished_reset) + return SCSI_FAILED; + } + + return sym_eh_handler(shost, SYM_EH_HOST_RESET, "HOST RESET", cmd); } /* From patchwork Thu Aug 19 09:07:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 500784 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDEC6C4338F for ; Thu, 19 Aug 2021 09:07:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C79EE61158 for ; Thu, 19 Aug 2021 09:07:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236796AbhHSJIR (ORCPT ); Thu, 19 Aug 2021 05:08:17 -0400 Received: from smtp-out2.suse.de ([195.135.220.29]:36574 "EHLO smtp-out2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236203AbhHSJIF (ORCPT ); Thu, 19 Aug 2021 05:08:05 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id E26FC1FD82; Thu, 19 Aug 2021 09:07:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1629364048; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c1PVoZnm72z63Pj+wvu55uGHBd3Y0RSTl4RzZxajjSY=; b=mPGoZi/epaGu6jVxgtmfidGywlkpylEXBfSBbdrNgejx+hRE7pHY8/6sGwga9vl8DM1Wh5 jvzrViLQsrRcOMz/kBjsIno0oXg056/EL73UjAsmxmrgepFoPfZWpcahS8Uvjdnlb34Dqc kjGkqJAEwhbL7tqniiSgZbjHJzVQHz8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1629364048; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c1PVoZnm72z63Pj+wvu55uGHBd3Y0RSTl4RzZxajjSY=; b=Q9fQ3oJDmQMsHXaSnHdDvgEew1Cw2F/EXFSv+pZBN3TNkkyP/2rMZPC84Cw5vaM4Bl0hIS M42gGIOAhMf5tgDw== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 236E7A3BA9; Thu, 19 Aug 2021 09:07:19 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id CA50F518D277; Thu, 19 Aug 2021 11:07:28 +0200 (CEST) From: Hannes Reinecke To: "Martin K. Petersen" Cc: Christoph Hellwig , James Bottomley , Matthew Wilcox , linux-scsi@vger.kernel.org, Hannes Reinecke Subject: [PATCH 2/4] sym53c8xx_2: split off host reset from sym_eh_handler() Date: Thu, 19 Aug 2021 11:07:14 +0200 Message-Id: <20210819090716.94049-3-hare@suse.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210819090716.94049-1-hare@suse.de> References: <20210819090716.94049-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org For host reset we need to wait for all pending command to complete; there might be more than one command queued and we'll need to wait for all of them. So split off the host reset functionality from sym_eh_handler() and add a wait loop for all commands. Signed-off-by: Hannes Reinecke --- drivers/scsi/sym53c8xx_2/sym_glue.c | 42 ++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c index dafdab5869fa..86cba915b62d 100644 --- a/drivers/scsi/sym53c8xx_2/sym_glue.c +++ b/drivers/scsi/sym53c8xx_2/sym_glue.c @@ -563,7 +563,27 @@ static void sym53c8xx_timer(struct timer_list *t) #define SYM_EH_ABORT 0 #define SYM_EH_DEVICE_RESET 1 #define SYM_EH_BUS_RESET 2 -#define SYM_EH_HOST_RESET 3 + +static int sym_eh_wait_for_commands(struct Scsi_Host *shost) +{ + struct sym_data *sym_data = shost_priv(shost); + struct sym_hcb *np = sym_data->ncb; + int rval = SUCCESS, count = 10; /* 5 seconds */ + + /* Wait for any queued commands to complete */ + spin_lock_irq(shost->host_lock); + while (!sym_que_empty(&np->busy_ccbq)) { + if (--count == 0) { + rval = FAILED; + break; + } + spin_unlock_irq(shost->host_lock); + msleep(500); + spin_lock_irq(shost->host_lock); + } + spin_unlock_irq(shost->host_lock); + return rval; +} /* * Generic method for our eh processing. @@ -605,11 +625,6 @@ static int sym_eh_handler(struct Scsi_Host *shost, int op, sym_reset_scsi_bus(np, 1); sts = 0; break; - case SYM_EH_HOST_RESET: - sym_reset_scsi_bus(np, 0); - sym_start_up(shost, 1); - sts = 0; - break; default: break; } @@ -677,6 +692,10 @@ static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd *cmd) struct Scsi_Host *shost = cmd->device->host; struct sym_data *sym_data = shost_priv(shost); struct pci_dev *pdev = sym_data->pdev; + struct sym_hcb *np = sym_data->ncb; + int rval = SUCCESS; + + shost_printk(KERN_WARNING, shost, "HOST RESET operation started\n"); /* We may be in an error condition because the PCI bus * went down. In this case, we need to wait until the @@ -710,7 +729,16 @@ static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd *cmd) return SCSI_FAILED; } - return sym_eh_handler(shost, SYM_EH_HOST_RESET, "HOST RESET", cmd); + spin_lock_irq(shost->host_lock); + sym_reset_scsi_bus(np, 0); + sym_start_up(shost, 1); + spin_unlock_irq(shost->host_lock); + + rval = sym_eh_wait_for_commands(shost); + + shost_printk(KERN_WARNING, shost, "HOST RESET operation %s.\n", + rval == SUCCESS ? "complete" : "failed"); + return rval; } /* From patchwork Thu Aug 19 09:07:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 500783 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ACB66C432BE for ; Thu, 19 Aug 2021 09:07:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92B3F6113C for ; Thu, 19 Aug 2021 09:07:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234640AbhHSJIT (ORCPT ); Thu, 19 Aug 2021 05:08:19 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:60248 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236661AbhHSJIF (ORCPT ); Thu, 19 Aug 2021 05:08:05 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id EC5FC220BD; Thu, 19 Aug 2021 09:07:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1629364048; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZFUnIWTuLS7lVSUfq5t4Rg4TGq+Tdn43GGf7cSylo24=; b=xaOYxFPTfcKvFk9DJKcXtgPV9LzPtarZ9IOXyoZk/HJiSQWfVWWKQ5FkE/jT098KCLGmw2 7GZGNIcauE9CZFvuoVPw9pk8AJIB9W5jF3Nq1IZ5PKN0xu2ARPuaGaAwhasa9BbMzPrvDs 5fe7rUs+hKkUc5ieKC+LN/b4BPsib5M= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1629364048; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZFUnIWTuLS7lVSUfq5t4Rg4TGq+Tdn43GGf7cSylo24=; b=mwQV43pvZYKtbC/moZ0ld+IGIvH3IlQ1wgN4WJyafCNCFSJY6d/0vWaR3mlwivr6vc2098 CCSIezsoWa6LTlCA== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 25C9EA3BAA; Thu, 19 Aug 2021 09:07:19 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id CFD15518D279; Thu, 19 Aug 2021 11:07:28 +0200 (CEST) From: Hannes Reinecke To: "Martin K. Petersen" Cc: Christoph Hellwig , James Bottomley , Matthew Wilcox , linux-scsi@vger.kernel.org, Hannes Reinecke Subject: [PATCH 3/4] sym53c8xx_2: split off bus reset from sym_eh_handler() Date: Thu, 19 Aug 2021 11:07:15 +0200 Message-Id: <20210819090716.94049-4-hare@suse.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210819090716.94049-1-hare@suse.de> References: <20210819090716.94049-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Bus reset is similar to host reset, and we also need to wait for all commands to complete. So split off bus reset from sym_eh_handler() and wait for all commands to complete after resetting the SCSI bus. Signed-off-by: Hannes Reinecke --- drivers/scsi/sym53c8xx_2/sym_glue.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c index 86cba915b62d..817b2584b4aa 100644 --- a/drivers/scsi/sym53c8xx_2/sym_glue.c +++ b/drivers/scsi/sym53c8xx_2/sym_glue.c @@ -562,7 +562,6 @@ static void sym53c8xx_timer(struct timer_list *t) */ #define SYM_EH_ABORT 0 #define SYM_EH_DEVICE_RESET 1 -#define SYM_EH_BUS_RESET 2 static int sym_eh_wait_for_commands(struct Scsi_Host *shost) { @@ -621,10 +620,6 @@ static int sym_eh_handler(struct Scsi_Host *shost, int op, case SYM_EH_DEVICE_RESET: sts = sym_reset_scsi_target(np, cmd->device->id); break; - case SYM_EH_BUS_RESET: - sym_reset_scsi_bus(np, 1); - sts = 0; - break; default: break; } @@ -681,10 +676,26 @@ static int sym53c8xx_eh_bus_reset_handler(struct scsi_cmnd *cmd) struct Scsi_Host *shost = cmd->device->host; struct sym_data *sym_data = shost_priv(shost); struct pci_dev *pdev = sym_data->pdev; + struct sym_hcb *np = sym_data->ncb; + int rval = SUCCESS; if (pci_channel_offline(pdev)) return FAILED; - return sym_eh_handler(shost, SYM_EH_BUS_RESET, "BUS RESET", cmd); + + shost_printk(KERN_WARNING, shost, "BUS RESET operation started\n"); + + spin_lock_irq(shost->host_lock); + if (sym_reset_scsi_bus(np, 1)) + rval = FAILED; + spin_unlock_irq(shost->host_lock); + + if (rval == SUCCESS) + rval = sym_eh_wait_for_commands(shost); + + shost_printk(KERN_WARNING, shost, "BUS RESET operation %s.\n", + rval == SUCCESS ? "complete" : "failed"); + + return rval; } static int sym53c8xx_eh_host_reset_handler(struct scsi_cmnd *cmd) From patchwork Thu Aug 19 09:07:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hannes Reinecke X-Patchwork-Id: 500087 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 17686C4320E for ; Thu, 19 Aug 2021 09:07:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0191161151 for ; Thu, 19 Aug 2021 09:07:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236661AbhHSJIU (ORCPT ); Thu, 19 Aug 2021 05:08:20 -0400 Received: from smtp-out1.suse.de ([195.135.220.28]:60242 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235475AbhHSJIF (ORCPT ); Thu, 19 Aug 2021 05:08:05 -0400 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id E9DED21BDD; Thu, 19 Aug 2021 09:07:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1629364048; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fXnMvkw0hihOFWADfDSWmtHiZimH6I6lGU6S4XzOVKU=; b=K1GjPK8mSFP2+pgYoJSbU+Ou2bzN1onJFC2iLuFQ0w32siLn4ps45tarNmTDwmRx+LT7Hj qszm1EJk1msHjvIW0HEUuL7UivdK7KOyv+8BfEl1647L1IwBLxf+6GeedyVqqPQhUdf2n6 Jo2rmjuBX6XEU+5dP1BOvfbRZmctKBQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1629364048; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fXnMvkw0hihOFWADfDSWmtHiZimH6I6lGU6S4XzOVKU=; b=/H/ERfLRHNi+EUAUWP0ANv4mm7HnM+Pzn+j5Ar82gNytfhSRt3UotV00SrxaSBVStYx/il wC63NIjBC4CBt6BQ== Received: from adalid.arch.suse.de (adalid.arch.suse.de [10.161.8.13]) by relay2.suse.de (Postfix) with ESMTP id 29177A3BAB; Thu, 19 Aug 2021 09:07:19 +0000 (UTC) Received: by adalid.arch.suse.de (Postfix, from userid 16045) id D58C5518D27B; Thu, 19 Aug 2021 11:07:28 +0200 (CEST) From: Hannes Reinecke To: "Martin K. Petersen" Cc: Christoph Hellwig , James Bottomley , Matthew Wilcox , linux-scsi@vger.kernel.org, Hannes Reinecke , Hannes Reinecke Subject: [PATCH 4/4] sym53c8xx_2: rework reset handling Date: Thu, 19 Aug 2021 11:07:16 +0200 Message-Id: <20210819090716.94049-5-hare@suse.de> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210819090716.94049-1-hare@suse.de> References: <20210819090716.94049-1-hare@suse.de> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Split off the combined abort and device reset handling into distinct functions. And the current device reset handler really is a target reset, so rename it. Signed-off-by: Hannes Reinecke --- drivers/scsi/sym53c8xx_2/sym_glue.c | 86 ++++++++++++++++------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/drivers/scsi/sym53c8xx_2/sym_glue.c b/drivers/scsi/sym53c8xx_2/sym_glue.c index 817b2584b4aa..8773fbdfd559 100644 --- a/drivers/scsi/sym53c8xx_2/sym_glue.c +++ b/drivers/scsi/sym53c8xx_2/sym_glue.c @@ -585,13 +585,12 @@ static int sym_eh_wait_for_commands(struct Scsi_Host *shost) } /* - * Generic method for our eh processing. - * The 'op' argument tells what we have to do. + * Error handlers called from the eh thread (one thread per HBA). */ -static int sym_eh_handler(struct Scsi_Host *shost, int op, - char *opname, struct scsi_cmnd *cmd) +static int sym53c8xx_eh_abort_handler(struct scsi_cmnd *cmd) { struct sym_ucmd *ucmd = SYM_UCMD_PTR(cmd); + struct Scsi_Host *shost = cmd->device->host; struct sym_data *sym_data = shost_priv(shost); struct sym_hcb *np = sym_data->ncb; SYM_QUEHEAD *qp; @@ -599,7 +598,7 @@ static int sym_eh_handler(struct Scsi_Host *shost, int op, int sts = -1; struct completion eh_done; - scmd_printk(KERN_WARNING, cmd, "%s operation started\n", opname); + scmd_printk(KERN_WARNING, cmd, "ABORT operation started\n"); spin_lock_irq(shost->host_lock); /* This one is queued in some place -> to wait for completion */ @@ -611,19 +610,7 @@ static int sym_eh_handler(struct Scsi_Host *shost, int op, } } - /* Try to proceed the operation we have been asked for */ - sts = -1; - switch(op) { - case SYM_EH_ABORT: - sts = sym_abort_scsiio(np, cmd, 1); - break; - case SYM_EH_DEVICE_RESET: - sts = sym_reset_scsi_target(np, cmd->device->id); - break; - default: - break; - } - + sts = sym_abort_scsiio(np, cmd, 1); /* On error, restore everything and cross fingers :) */ if (sts) cmd_queued = 0; @@ -640,35 +627,60 @@ static int sym_eh_handler(struct Scsi_Host *shost, int op, spin_unlock_irq(shost->host_lock); } - dev_warn(&cmd->device->sdev_gendev, "%s operation %s.\n", opname, + dev_warn(&cmd->device->sdev_gendev, "ABORT operation %s.\n", sts==0 ? "complete" :sts==-2 ? "timed-out" : "failed"); return sts ? SCSI_FAILED : SCSI_SUCCESS; } - -/* - * Error handlers called from the eh thread (one thread per HBA). - */ -static int sym53c8xx_eh_abort_handler(struct scsi_cmnd *cmd) +static int sym53c8xx_eh_target_reset_handler(struct scsi_cmnd *cmd) { - struct Scsi_Host *shost = cmd->device->host; + struct scsi_target *starget = scsi_target(cmd->device); + struct Scsi_Host *shost = dev_to_shost(starget->dev.parent); struct sym_data *sym_data = shost_priv(shost); struct pci_dev *pdev = sym_data->pdev; + struct sym_hcb *np = sym_data->ncb; + SYM_QUEHEAD *qp; + int sts; + struct completion eh_done; + starget_printk(KERN_WARNING, starget, + "TARGET RESET operation started\n"); + + /* + * Escalate to host reset if the PCI bus went down + */ if (pci_channel_offline(pdev)) - return FAILED; - return sym_eh_handler(shost, SYM_EH_ABORT, "ABORT", cmd); -} + return SCSI_FAILED; -static int sym53c8xx_eh_device_reset_handler(struct scsi_cmnd *cmd) -{ - struct Scsi_Host *shost = cmd->device->host; - struct sym_data *sym_data = shost_priv(shost); - struct pci_dev *pdev = sym_data->pdev; + spin_lock_irq(shost->host_lock); + sts = sym_reset_scsi_target(np, starget->id); + if (!sts) { + FOR_EACH_QUEUED_ELEMENT(&np->busy_ccbq, qp) { + struct sym_ccb *cp = sym_que_entry(qp, struct sym_ccb, + link_ccbq); + struct scsi_cmnd *cmd = cp->cmd; + struct sym_ucmd *ucmd; + + if (!cmd || cmd->device->channel != starget->channel || + cmd->device->id != starget->id) + continue; - if (pci_channel_offline(pdev)) - return FAILED; - return sym_eh_handler(shost, SYM_EH_DEVICE_RESET, "DEVICE RESET", cmd); + ucmd = SYM_UCMD_PTR(cmd); + init_completion(&eh_done); + ucmd->eh_done = &eh_done; + spin_unlock_irq(shost->host_lock); + if (!wait_for_completion_timeout(&eh_done, 5*HZ)) { + ucmd->eh_done = NULL; + sts = -2; + } + spin_lock_irq(shost->host_lock); + } + } + spin_unlock_irq(shost->host_lock); + + starget_printk(KERN_WARNING, starget, "TARGET RESET operation %s.\n", + sts==0 ? "complete" :sts==-2 ? "timed-out" : "failed"); + return SCSI_SUCCESS; } static int sym53c8xx_eh_bus_reset_handler(struct scsi_cmnd *cmd) @@ -1699,7 +1711,7 @@ static struct scsi_host_template sym2_template = { .slave_configure = sym53c8xx_slave_configure, .slave_destroy = sym53c8xx_slave_destroy, .eh_abort_handler = sym53c8xx_eh_abort_handler, - .eh_device_reset_handler = sym53c8xx_eh_device_reset_handler, + .eh_target_reset_handler = sym53c8xx_eh_target_reset_handler, .eh_bus_reset_handler = sym53c8xx_eh_bus_reset_handler, .eh_host_reset_handler = sym53c8xx_eh_host_reset_handler, .this_id = 7,