From patchwork Thu Mar 15 06:33:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: ching Huang X-Patchwork-Id: 10283933 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 C62B6602C2 for ; Thu, 15 Mar 2018 06:33:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7AD52887B for ; Thu, 15 Mar 2018 06:33:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AC6F828880; Thu, 15 Mar 2018 06:33:55 +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=-6.9 required=2.0 tests=BAYES_00,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 49B8C2887B for ; Thu, 15 Mar 2018 06:33:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751672AbeCOGdm (ORCPT ); Thu, 15 Mar 2018 02:33:42 -0400 Received: from mail-it0-f65.google.com ([209.85.214.65]:55421 "EHLO mail-it0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751390AbeCOGdl (ORCPT ); Thu, 15 Mar 2018 02:33:41 -0400 Received: by mail-it0-f65.google.com with SMTP id e195-v6so2975341ita.5 for ; Wed, 14 Mar 2018 23:33:41 -0700 (PDT) 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=gGm1B0RvKdq5QzdOigWH+8U0YO7FHj0CeiA4iJBhZGM=; b=eCVWBTM6/0JzdBdBPdUXUdbWNz1yjvofsBK7clr0Pqj+1ADYyviG4gQTI4OOIVBdKS YYMb+/dkexX1SV/JF2iHdjeTPkMA3ng8R6obCkSYlr8vSj4MnddF7ikjFHONulaQNECp Tle0SHhR1kDaRcniVlpb0RZ0QaVeGbPihFcpc8851Ebw1L/+9pp/OFZ/YftctID7pFwB zNr5+iqonu9i965uK8REGmX1xPa2rnMbjgVRylBCj0FhihasFfICFILhHiJZcyuF128y HlGL/zNmk9zalmy7G88CtMPxW4CjejrA8VrWYFQrQmyi7JfCxaQDwDqqHZi2+5cMDBgi mEWA== 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=gGm1B0RvKdq5QzdOigWH+8U0YO7FHj0CeiA4iJBhZGM=; b=KsJtxIq0LO6C3DLODhNy2UwheYnhpZmy1GfohIqNM4q1ITNdKUUU2RtwTBADfppYyu AAJdF4NSAsXIC6MobjrmtV3Kmyc3IIwuglEYbum629Bw0wGcdrzvGvWNnZaIeyhUm3Uh f4qWA/XsJnhxI3eK/u/M9VMrko7cJ0xjxKQmIp64KZQKvLI1oeUTSh79GjGRNyeKTI5z ihNUbb7ntGiWsBCLGM++e9gAM3m3xE4+JAJLyUi32onmryfcSNyIRIRfR6cpWBLqSgBQ WtTa/24lEns3pZKxluPJZ8wZgS1WnWgBxcwzq9xrJBh8/U3BvpbbJNhqHMjREM7EiUAF w+NA== X-Gm-Message-State: AElRT7EF/KAD3Yigydx3E2MT05CSz4GX01aRLJiIjMb3kP19SmRv8SRP XRhtFXxPh7QchH2/pUZyun0+/w== X-Google-Smtp-Source: AG47ELtABCsaExmYJLMxs59egnHc+pAMH3fcooQv5TzgcvIcGsURvYwAkMx/qrTSnH/4/GWKQzUCzQ== X-Received: by 10.36.151.134 with SMTP id k128mr11992ite.79.1521095620874; Wed, 14 Mar 2018 23:33:40 -0700 (PDT) Received: from [192.168.0.124] (60-248-88-209.HINET-IP.hinet.net. [60.248.88.209]) by smtp.gmail.com with ESMTPSA id 100sm2628304ios.61.2018.03.14.23.33.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Mar 2018 23:33:39 -0700 (PDT) Subject: [PATCH 2/4] scsi: arcmsr: Handle adapter removed due to thunderbolt cable disconnection. From: Ching Huang To: martin.petersen@oracle.com, James.Bottomley@HansenPartnership.com, linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: dan.carpenter@oracle.com, hch@infradead.org, colin.king@canonical.com Date: Thu, 15 Mar 2018 14:33:36 +0800 Message-ID: <1521095616.31371.30.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 Handle adapter removed due to thunderbolt cable disconnection. Signed-off-by: Ching Huang diff --git a/drivers/scsi/arcmsr/arcmsr_hba.c b/drivers/scsi/arcmsr/arcmsr_hba.c index 75e828b..2f52c53 100755 --- a/drivers/scsi/arcmsr/arcmsr_hba.c +++ b/drivers/scsi/arcmsr/arcmsr_hba.c @@ -1446,12 +1446,80 @@ static void arcmsr_done4abort_postqueue(struct AdapterControlBlock *acb) } } +static void arcmsr_remove_scsi_devices(struct AdapterControlBlock *acb) +{ + char *acb_dev_map = (char *)acb->device_map; + int target, lun, i; + struct scsi_device *psdev; + struct CommandControlBlock *ccb; + char temp; + + for (i = 0; i < acb->maxFreeCCB; i++) { + ccb = acb->pccb_pool[i]; + if (ccb->startdone == ARCMSR_CCB_START) { + ccb->pcmd->result = DID_NO_CONNECT << 16; + arcmsr_pci_unmap_dma(ccb); + ccb->pcmd->scsi_done(ccb->pcmd); + } + } + for (target = 0; target < ARCMSR_MAX_TARGETID; target++) { + temp = *acb_dev_map; + if (temp) { + for (lun = 0; lun < ARCMSR_MAX_TARGETLUN; lun++) { + if (temp & 1) { + psdev = scsi_device_lookup(acb->host, + 0, target, lun); + if (psdev != NULL) { + scsi_remove_device(psdev); + scsi_device_put(psdev); + } + } + temp >>= 1; + } + *acb_dev_map = 0; + } + acb_dev_map++; + } +} + +static void arcmsr_free_pcidev(struct AdapterControlBlock *acb) +{ + struct pci_dev *pdev; + struct Scsi_Host *host; + + host = acb->host; + arcmsr_free_sysfs_attr(acb); + scsi_remove_host(host); + flush_work(&acb->arcmsr_do_message_isr_bh); + del_timer_sync(&acb->eternal_timer); + if (set_date_time) + del_timer_sync(&acb->refresh_timer); + pdev = acb->pdev; + arcmsr_free_irq(pdev, acb); + arcmsr_free_ccb_pool(acb); + arcmsr_free_mu(acb); + arcmsr_unmap_pciregion(acb); + pci_release_regions(pdev); + scsi_host_put(host); + pci_disable_device(pdev); +} + static void arcmsr_remove(struct pci_dev *pdev) { struct Scsi_Host *host = pci_get_drvdata(pdev); struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; int poll_count = 0; + uint16_t dev_id; + + pci_read_config_word(pdev, PCI_DEVICE_ID, &dev_id); + if (dev_id == 0xffff) { + acb->acb_flags &= ~ACB_F_IOP_INITED; + acb->acb_flags |= ACB_F_ADAPTER_REMOVED; + arcmsr_remove_scsi_devices(acb); + arcmsr_free_pcidev(acb); + return; + } arcmsr_free_sysfs_attr(acb); scsi_remove_host(host); flush_work(&acb->arcmsr_do_message_isr_bh); @@ -1499,6 +1567,8 @@ static void arcmsr_shutdown(struct pci_dev *pdev) struct Scsi_Host *host = pci_get_drvdata(pdev); struct AdapterControlBlock *acb = (struct AdapterControlBlock *)host->hostdata; + if (acb->acb_flags & ACB_F_ADAPTER_REMOVED) + return; del_timer_sync(&acb->eternal_timer); if (set_date_time) del_timer_sync(&acb->refresh_timer); @@ -2931,6 +3001,12 @@ static int arcmsr_queue_command_lck(struct scsi_cmnd *cmd, struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; struct CommandControlBlock *ccb; int target = cmd->device->id; + + if (acb->acb_flags & ACB_F_ADAPTER_REMOVED) { + cmd->result = (DID_NO_CONNECT << 16); + cmd->scsi_done(cmd); + return 0; + } cmd->scsi_done = done; cmd->host_scribble = NULL; cmd->result = 0; @@ -4177,6 +4253,8 @@ static int arcmsr_bus_reset(struct scsi_cmnd *cmd) int retry_count = 0; int rtn = FAILED; acb = (struct AdapterControlBlock *) cmd->device->host->hostdata; + if (acb->acb_flags & ACB_F_ADAPTER_REMOVED) + return SUCCESS; pr_notice("arcmsr: executing bus reset eh.....num_resets = %d," " num_aborts = %d \n", acb->num_resets, acb->num_aborts); acb->num_resets++; @@ -4243,6 +4321,8 @@ static int arcmsr_abort(struct scsi_cmnd *cmd) int rtn = FAILED; uint32_t intmask_org; + if (acb->acb_flags & ACB_F_ADAPTER_REMOVED) + return SUCCESS; printk(KERN_NOTICE "arcmsr%d: abort device command of scsi id = %d lun = %d\n", acb->host->host_no, cmd->device->id, (u32)cmd->device->lun);