From patchwork Tue Dec 5 01:31:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ching Huang X-Patchwork-Id: 10092551 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id B5AA56035E for ; Tue, 5 Dec 2017 09:32:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ABDC7284B9 for ; Tue, 5 Dec 2017 09:32:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A08522888F; Tue, 5 Dec 2017 09:32:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.4 required=2.0 tests=BAYES_00, DATE_IN_PAST_06_12, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D2B1B284B9 for ; Tue, 5 Dec 2017 09:32:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753057AbdLEJcM (ORCPT ); Tue, 5 Dec 2017 04:32:12 -0500 Received: from mail-it0-f66.google.com ([209.85.214.66]:44743 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752856AbdLEJcJ (ORCPT ); Tue, 5 Dec 2017 04:32:09 -0500 Received: by mail-it0-f66.google.com with SMTP id b5so19952363itc.3 for ; Tue, 05 Dec 2017 01:32:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=areca-com-tw.20150623.gappssmtp.com; s=20150623; h=subject:from:to:cc:date:message-id:mime-version :content-transfer-encoding; bh=VD+aQmTIeVI4M2fQzLUUQGLevoqtEjanzPnuTVMUuvo=; b=SK11KK7wy8sXUJ/6FgCKk1ELJhzcpwyqWwyVpYM5NKxdVMPWzMNeD9GzrtzXeauQ9p 0JbnkZCenzLUVJJuiLJB+iqsWAV91zgH0+kwLmc7huYCfk307eOu7lml7ibc5r1Si3yu zrdU3G3C1d0xPA/VV/BZ8hOuAlc1z0s9ZupS5c+6e9Q50U62V8FIComdj3o2y7lWIBTh Y+2xAbx2A/UhVdP6D9GTSc6h5jQOYVJFEQ0SouMJmVWigFd7NR4s3pQjDe4upvHuc1oy BaDUct4pzq4tTwXq4x+R9/7gfmm9F8nqqURZKh36F4d6JoImn1LH3KNXeRut27jK1zdq 57bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:from:to:cc:date:message-id:mime-version :content-transfer-encoding; bh=VD+aQmTIeVI4M2fQzLUUQGLevoqtEjanzPnuTVMUuvo=; b=rJ8NGVLPS7pi1dRBwptBXDcpbJnKjAGZK7IGzg/49EcM3tfBlEs2MEhUiofA/iMG0s lkN+R03Y6Cm4+iAPk1Jl/9KPVlC7NpeV68aJ092+m7bFTqPLc+QnYGebQHMyFmY8exR4 b4Ff/ExS2zRVzeKUH3U07RIgP6gp1ZQRWCssydL/d9tHIm795HvjUOEGMnBryUKAiYO5 6ZU0i9BoXyiu9P+3xiJyEGEBp1qD5KxNZ705UXFRapvM91kWACKYdkDMYy19JYLulVcS VqmL+lZV0vcfkVT8Y7b8sT8iROkuGeJ3MBnE9KF2yq7l87mzEmXEXWMsLNWJSRAP9QgO u6Xg== X-Gm-Message-State: AJaThX5K/mkkcGTBAUQCephw9xyy0Mgph7N7uVGT2BAq4B4TQwBLm9VQ fQ826ucc4lEfZd6VMW2mntTh/Q== X-Google-Smtp-Source: AGs4zMa+knNxNj3xXpa5hmhWMNV5joPYIUdGpYOFCn3gzQ6QUDCu3wjhplyOCjInIYThozRBCdYtQQ== X-Received: by 10.107.81.24 with SMTP id f24mr27076376iob.63.1512466328564; Tue, 05 Dec 2017 01:32:08 -0800 (PST) Received: from [192.168.0.105] (60-248-88-209.HINET-IP.hinet.net. [60.248.88.209]) by smtp.gmail.com with ESMTPSA id y19sm7072274iod.46.2017.12.05.01.32.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Dec 2017 01:32:07 -0800 (PST) Subject: [PATCH 2/17] scsi: arcmsr: simplify arcmsr_iop_init function From: Ching Huang To: martin.petersen@oracle.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: James.Bottomley@HansenPartnership.com, sfr@canb.auug.org.au Date: Tue, 05 Dec 2017 09:31:59 +0800 Message-ID: <1512437519.4577.34.camel@Centos6.3-64> Mime-Version: 1.0 X-Mailer: Evolution 2.32.3 (2.32.3-37.el6) Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Ching Huang simplify arcmsr_iop_init function Signed-off-by: Ching Huang diff -uprN a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c --- a/drivers/scsi/arcmsr/arcmsr_hba.c 2017-12-05 11:47:40.000000000 +0800 +++ b/drivers/scsi/arcmsr/arcmsr_hba.c 2017-12-05 11:47:28.000000000 +0800 @@ -3671,6 +3671,39 @@ static void arcmsr_hardware_reset(struct msleep(1000); return; } + +static bool arcmsr_reset_in_progress(struct AdapterControlBlock *acb) +{ + bool rtn = true; + + switch(acb->adapter_type) { + case ACB_ADAPTER_TYPE_A:{ + struct MessageUnit_A __iomem *reg = acb->pmuA; + rtn = ((readl(®->outbound_msgaddr1) & + ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK) == 0) ? true : false; + } + break; + case ACB_ADAPTER_TYPE_B:{ + struct MessageUnit_B *reg = acb->pmuB; + rtn = ((readl(reg->iop2drv_doorbell) & + ARCMSR_MESSAGE_FIRMWARE_OK) == 0) ? true : false; + } + break; + case ACB_ADAPTER_TYPE_C:{ + struct MessageUnit_C __iomem *reg = acb->pmuC; + rtn = (readl(®->host_diagnostic) & 0x04) ? true : false; + } + break; + case ACB_ADAPTER_TYPE_D:{ + struct MessageUnit_D *reg = acb->pmuD; + rtn = ((readl(reg->sample_at_reset) & 0x80) == 0) ? + true : false; + } + break; + } + return rtn; +} + static void arcmsr_iop_init(struct AdapterControlBlock *acb) { uint32_t intmask_org; @@ -3725,197 +3758,55 @@ static uint8_t arcmsr_iop_reset(struct A static int arcmsr_bus_reset(struct scsi_cmnd *cmd) { struct AdapterControlBlock *acb; - uint32_t intmask_org, outbound_doorbell; int retry_count = 0; int rtn = FAILED; acb = (struct AdapterControlBlock *) cmd->device->host->hostdata; - printk(KERN_ERR "arcmsr: executing bus reset eh.....num_resets = %d, num_aborts = %d \n", acb->num_resets, acb->num_aborts); + pr_notice("arcmsr: executing bus reset eh.....num_resets = %d," + " num_aborts = %d \n", acb->num_resets, acb->num_aborts); acb->num_resets++; - switch(acb->adapter_type){ - case ACB_ADAPTER_TYPE_A:{ - if (acb->acb_flags & ACB_F_BUS_RESET){ - long timeout; - printk(KERN_ERR "arcmsr: there is an bus reset eh proceeding.......\n"); - timeout = wait_event_timeout(wait_q, (acb->acb_flags & ACB_F_BUS_RESET) == 0, 220*HZ); - if (timeout) { - return SUCCESS; - } - } - acb->acb_flags |= ACB_F_BUS_RESET; - if (!arcmsr_iop_reset(acb)) { - struct MessageUnit_A __iomem *reg; - reg = acb->pmuA; - arcmsr_hardware_reset(acb); - acb->acb_flags &= ~ACB_F_IOP_INITED; -sleep_again: - ssleep(ARCMSR_SLEEPTIME); - if ((readl(®->outbound_msgaddr1) & ARCMSR_OUTBOUND_MESG1_FIRMWARE_OK) == 0) { - printk(KERN_ERR "arcmsr%d: waiting for hw bus reset return, retry=%d\n", acb->host->host_no, retry_count); - if (retry_count > ARCMSR_RETRYCOUNT) { - acb->fw_flag = FW_DEADLOCK; - printk(KERN_ERR "arcmsr%d: waiting for hw bus reset return, RETRY TERMINATED!!\n", acb->host->host_no); - return FAILED; - } - retry_count++; - goto sleep_again; - } - acb->acb_flags |= ACB_F_IOP_INITED; - /* disable all outbound interrupt */ - intmask_org = arcmsr_disable_outbound_ints(acb); - arcmsr_get_firmware_spec(acb); - arcmsr_start_adapter_bgrb(acb); - /* clear Qbuffer if door bell ringed */ - outbound_doorbell = readl(®->outbound_doorbell); - writel(outbound_doorbell, ®->outbound_doorbell); /*clear interrupt */ - writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK, ®->inbound_doorbell); - /* enable outbound Post Queue,outbound doorbell Interrupt */ - arcmsr_enable_outbound_ints(acb, intmask_org); - atomic_set(&acb->rq_map_token, 16); - atomic_set(&acb->ante_token_value, 16); - acb->fw_flag = FW_NORMAL; - mod_timer(&acb->eternal_timer, jiffies + msecs_to_jiffies(6 * HZ)); - acb->acb_flags &= ~ACB_F_BUS_RESET; - rtn = SUCCESS; - printk(KERN_ERR "arcmsr: scsi bus reset eh returns with success\n"); - } else { - acb->acb_flags &= ~ACB_F_BUS_RESET; - atomic_set(&acb->rq_map_token, 16); - atomic_set(&acb->ante_token_value, 16); - acb->fw_flag = FW_NORMAL; - mod_timer(&acb->eternal_timer, jiffies + msecs_to_jiffies(6*HZ)); - rtn = SUCCESS; - } - break; - } - case ACB_ADAPTER_TYPE_B:{ - acb->acb_flags |= ACB_F_BUS_RESET; - if (!arcmsr_iop_reset(acb)) { - acb->acb_flags &= ~ACB_F_BUS_RESET; - rtn = FAILED; - } else { - acb->acb_flags &= ~ACB_F_BUS_RESET; - atomic_set(&acb->rq_map_token, 16); - atomic_set(&acb->ante_token_value, 16); - acb->fw_flag = FW_NORMAL; - mod_timer(&acb->eternal_timer, jiffies + msecs_to_jiffies(6 * HZ)); - rtn = SUCCESS; - } - break; - } - case ACB_ADAPTER_TYPE_C:{ - if (acb->acb_flags & ACB_F_BUS_RESET) { - long timeout; - printk(KERN_ERR "arcmsr: there is an bus reset eh proceeding.......\n"); - timeout = wait_event_timeout(wait_q, (acb->acb_flags & ACB_F_BUS_RESET) == 0, 220*HZ); - if (timeout) { - return SUCCESS; - } - } - acb->acb_flags |= ACB_F_BUS_RESET; - if (!arcmsr_iop_reset(acb)) { - struct MessageUnit_C __iomem *reg; - reg = acb->pmuC; - arcmsr_hardware_reset(acb); - acb->acb_flags &= ~ACB_F_IOP_INITED; -sleep: - ssleep(ARCMSR_SLEEPTIME); - if ((readl(®->host_diagnostic) & 0x04) != 0) { - printk(KERN_ERR "arcmsr%d: waiting for hw bus reset return, retry=%d\n", acb->host->host_no, retry_count); - if (retry_count > ARCMSR_RETRYCOUNT) { - acb->fw_flag = FW_DEADLOCK; - printk(KERN_ERR "arcmsr%d: waiting for hw bus reset return, RETRY TERMINATED!!\n", acb->host->host_no); - return FAILED; - } - retry_count++; - goto sleep; - } - acb->acb_flags |= ACB_F_IOP_INITED; - /* disable all outbound interrupt */ - intmask_org = arcmsr_disable_outbound_ints(acb); - arcmsr_get_firmware_spec(acb); - arcmsr_start_adapter_bgrb(acb); - /* clear Qbuffer if door bell ringed */ - arcmsr_clear_doorbell_queue_buffer(acb); - /* enable outbound Post Queue,outbound doorbell Interrupt */ - arcmsr_enable_outbound_ints(acb, intmask_org); - atomic_set(&acb->rq_map_token, 16); - atomic_set(&acb->ante_token_value, 16); - acb->fw_flag = FW_NORMAL; - mod_timer(&acb->eternal_timer, jiffies + msecs_to_jiffies(6 * HZ)); - acb->acb_flags &= ~ACB_F_BUS_RESET; - rtn = SUCCESS; - printk(KERN_ERR "arcmsr: scsi bus reset eh returns with success\n"); - } else { - acb->acb_flags &= ~ACB_F_BUS_RESET; - atomic_set(&acb->rq_map_token, 16); - atomic_set(&acb->ante_token_value, 16); - acb->fw_flag = FW_NORMAL; - mod_timer(&acb->eternal_timer, jiffies + msecs_to_jiffies(6*HZ)); - rtn = SUCCESS; - } - break; - } - case ACB_ADAPTER_TYPE_D: { - if (acb->acb_flags & ACB_F_BUS_RESET) { - long timeout; - pr_notice("arcmsr: there is an bus reset" - " eh proceeding.......\n"); - timeout = wait_event_timeout(wait_q, (acb->acb_flags - & ACB_F_BUS_RESET) == 0, 220 * HZ); - if (timeout) - return SUCCESS; - } - acb->acb_flags |= ACB_F_BUS_RESET; - if (!arcmsr_iop_reset(acb)) { - struct MessageUnit_D *reg; - reg = acb->pmuD; - arcmsr_hardware_reset(acb); - acb->acb_flags &= ~ACB_F_IOP_INITED; - nap: - ssleep(ARCMSR_SLEEPTIME); - if ((readl(reg->sample_at_reset) & 0x80) != 0) { - pr_err("arcmsr%d: waiting for " - "hw bus reset return, retry=%d\n", - acb->host->host_no, retry_count); - if (retry_count > ARCMSR_RETRYCOUNT) { - acb->fw_flag = FW_DEADLOCK; - pr_err("arcmsr%d: waiting for hw bus" - " reset return, " - "RETRY TERMINATED!!\n", - acb->host->host_no); - return FAILED; - } - retry_count++; - goto nap; - } - acb->acb_flags |= ACB_F_IOP_INITED; - /* disable all outbound interrupt */ - intmask_org = arcmsr_disable_outbound_ints(acb); - arcmsr_get_firmware_spec(acb); - arcmsr_start_adapter_bgrb(acb); - arcmsr_clear_doorbell_queue_buffer(acb); - arcmsr_enable_outbound_ints(acb, intmask_org); - atomic_set(&acb->rq_map_token, 16); - atomic_set(&acb->ante_token_value, 16); - acb->fw_flag = FW_NORMAL; - mod_timer(&acb->eternal_timer, - jiffies + msecs_to_jiffies(6 * HZ)); - acb->acb_flags &= ~ACB_F_BUS_RESET; - rtn = SUCCESS; - pr_err("arcmsr: scsi bus reset " - "eh returns with success\n"); - } else { - acb->acb_flags &= ~ACB_F_BUS_RESET; - atomic_set(&acb->rq_map_token, 16); - atomic_set(&acb->ante_token_value, 16); - acb->fw_flag = FW_NORMAL; - mod_timer(&acb->eternal_timer, - jiffies + msecs_to_jiffies(6 * HZ)); - rtn = SUCCESS; - } - break; - } + if (acb->acb_flags & ACB_F_BUS_RESET) { + long timeout; + pr_notice("arcmsr: there is an bus reset eh proceeding...\n"); + timeout = wait_event_timeout(wait_q, (acb->acb_flags + & ACB_F_BUS_RESET) == 0, 220 * HZ); + if (timeout) + return SUCCESS; + } + acb->acb_flags |= ACB_F_BUS_RESET; + if (!arcmsr_iop_reset(acb)) { + arcmsr_hardware_reset(acb); + acb->acb_flags &= ~ACB_F_IOP_INITED; +wait_reset_done: + ssleep(ARCMSR_SLEEPTIME); + if (arcmsr_reset_in_progress(acb)) { + if (retry_count > ARCMSR_RETRYCOUNT) { + acb->fw_flag = FW_DEADLOCK; + pr_notice("arcmsr%d: waiting for hw bus reset" + " return, RETRY TERMINATED!!\n", + acb->host->host_no); + return FAILED; + } + retry_count++; + goto wait_reset_done; + } + arcmsr_iop_init(acb); + atomic_set(&acb->rq_map_token, 16); + atomic_set(&acb->ante_token_value, 16); + acb->fw_flag = FW_NORMAL; + mod_timer(&acb->eternal_timer, jiffies + + msecs_to_jiffies(6 * HZ)); + acb->acb_flags &= ~ACB_F_BUS_RESET; + rtn = SUCCESS; + pr_notice("arcmsr: scsi bus reset eh returns with success\n"); + } else { + acb->acb_flags &= ~ACB_F_BUS_RESET; + atomic_set(&acb->rq_map_token, 16); + atomic_set(&acb->ante_token_value, 16); + acb->fw_flag = FW_NORMAL; + mod_timer(&acb->eternal_timer, jiffies + + msecs_to_jiffies(6 * HZ)); + rtn = SUCCESS; } return rtn; }