From patchwork Mon Feb 22 12:04:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Chiou X-Patchwork-Id: 8376031 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 2953CC0553 for ; Mon, 22 Feb 2016 12:04:50 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2E3A9204DE for ; Mon, 22 Feb 2016 12:04:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1B33E204E3 for ; Mon, 22 Feb 2016 12:04:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754556AbcBVMEe (ORCPT ); Mon, 22 Feb 2016 07:04:34 -0500 Received: from mail-pf0-f196.google.com ([209.85.192.196]:34177 "EHLO mail-pf0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751666AbcBVMEd (ORCPT ); Mon, 22 Feb 2016 07:04:33 -0500 Received: by mail-pf0-f196.google.com with SMTP id 71so7005064pfv.1; Mon, 22 Feb 2016 04:04:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=6h1GhUJ683eTFKQblyDpaRPn0IZobKFaoJoTzBj99Bc=; b=ex6CTOS+DMdOU0TLCRTTIeNhtnTP8ZMyzPlP0uQ/M0GqNZC3hsg2sEHn1KsXELwtlZ au4Oq+06HEvPnZOCcZeytXjnKq+IH4YSeWV8yzPXA+KkjNs2JwNHyq+CNmrM8C44M6hU 91vQMAtU1lG2jSaT6l41PznPKGc+r94ga6pZNugqImEDxZap9ujD4QhqdfC8xjxMkxqa cWf8yMRX77JtjDhZL0nxjAKRWShavPLBN0+BhNm5scYnc7xz9gg1PZDSuLw0kdzP8FDm k4S6Qja8JwoixQUpjxklTT6O1RZPxloduN9QqOJWxdhmGnmMhjo5VykNmLyXpU0nDqvV Fzgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=6h1GhUJ683eTFKQblyDpaRPn0IZobKFaoJoTzBj99Bc=; b=VkWyvXlE/QmUNoMc87ov1JMITzoc+fnK9zJqcqkhisv54fBOGdnqDFTT89++SmLP7z d67ZnfqC1OUEKGmryi8g1uVE75L1xpcFFX68N2bwDDN0w9rAMGMm8PoSDpZrKL++qC1X xzHZK19UXSuef2Qen37tLPJ/6lAPbsGhoztsNfCYlpD1i42RXeSPTEFwmTx3/b6dQ5me vf2udI5tsAKJOVZrFRHECUgWGfQJA2D2jD+QlyMrLPj4XtdFVL9fO3GmGdgUvZj48rXk xst4/Pg/aKg5W4f30pZMSadF5z2Vy0eT1yh+/Hz75EDK1QmkrrE0c8NJ3joDpRDzUsfR U7kQ== X-Gm-Message-State: AG10YOQDRY4/teXAjvrT82jVJaWzX5YXeeWbEflrqgnxmksvBmN32Te927zcutiy/TgjaA== X-Received: by 10.98.64.202 with SMTP id f71mr37455507pfd.113.1456142672475; Mon, 22 Feb 2016 04:04:32 -0800 (PST) Received: from charles-desktop.promise.com.tw (vpn.promise.com.tw. [61.222.81.253]) by smtp.gmail.com with ESMTPSA id to9sm36754478pab.3.2016.02.22.04.04.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Feb 2016 04:04:31 -0800 (PST) From: Charles Chiou To: JBottomley@parallels.com, martin.petersen@oracle.com, jthumshirn@suse.de, hch@infradead.org, oneukum@suse.de, linus.chen@tw.promise.com, grace.chang@tw.promise.com, victor.p@promise.com, eva.cheng@tw.promise.com, charles.chiou@tw.promise.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [v2 PATCH 2/3] scsi:stex.c Add hotplug support Date: Mon, 22 Feb 2016 20:04:25 +0800 Message-Id: <1456142665-25327-1-git-send-email-ch1102chiou@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Charles 1. Add hotplug support. Pegasus support surprise removal. To this end, I use return_abnormal_state function to return DID_NO_CONNECT for all commands which sent to driver. 2. Remove stex_hba_stop in stex_remove because we cannot send command to device after hotplug. 3. Add new device status: MU_STATE_STOP, MU_STATE_NOCONNECT, MU_STATE_STOP. MU_STATE_STOP is currently not referenced. MU_STATE_NOCONNECT represent that device is plugged out from the host. 4. Use return_abnormal_function() to substitute part of code in stex_do_reset. Signed-off-by: Charles Chiou Reviewed-by: Johannes Thumshirn --- drivers/scsi/stex.c | 53 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 19 deletions(-) diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c index 495d632..1994603 100644 --- a/drivers/scsi/stex.c +++ b/drivers/scsi/stex.c @@ -84,6 +84,8 @@ enum { MU_STATE_STARTED = 2, MU_STATE_RESETTING = 3, MU_STATE_FAILED = 4, + MU_STATE_STOP = 5, + MU_STATE_NOCONNECT = 6, MU_MAX_DELAY = 120, MU_HANDSHAKE_SIGNATURE = 0x55aaaa55, @@ -537,6 +539,27 @@ stex_ss_send_cmd(struct st_hba *hba, struct req_msg *req, u16 tag) readl(hba->mmio_base + YH2I_REQ); /* flush */ } +static void return_abnormal_state(struct st_hba *hba, int status) +{ + struct st_ccb *ccb; + unsigned long flags; + u16 tag; + + spin_lock_irqsave(hba->host->host_lock, flags); + for (tag = 0; tag < hba->host->can_queue; tag++) { + ccb = &hba->ccb[tag]; + if (ccb->req == NULL) + continue; + ccb->req = NULL; + if (ccb->cmd) { + scsi_dma_unmap(ccb->cmd); + ccb->cmd->result = status << 16; + ccb->cmd->scsi_done(ccb->cmd); + ccb->cmd = NULL; + } + } + spin_unlock_irqrestore(hba->host->host_lock, flags); +} static int stex_slave_config(struct scsi_device *sdev) { @@ -560,8 +583,12 @@ stex_queuecommand_lck(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *)) id = cmd->device->id; lun = cmd->device->lun; hba = (struct st_hba *) &host->hostdata[0]; - - if (unlikely(hba->mu_status == MU_STATE_RESETTING)) + if (hba->mu_status == MU_STATE_NOCONNECT) { + cmd->result = DID_NO_CONNECT; + done(cmd); + return 0; + } + if (unlikely(hba->mu_status != MU_STATE_STARTED)) return SCSI_MLQUEUE_HOST_BUSY; switch (cmd->cmnd[0]) { @@ -1260,10 +1287,8 @@ static void stex_ss_reset(struct st_hba *hba) static int stex_do_reset(struct st_hba *hba) { - struct st_ccb *ccb; unsigned long flags; unsigned int mu_status = MU_STATE_RESETTING; - u16 tag; spin_lock_irqsave(hba->host->host_lock, flags); if (hba->mu_status == MU_STATE_STARTING) { @@ -1297,20 +1322,8 @@ static int stex_do_reset(struct st_hba *hba) else if (hba->cardtype == st_yel) stex_ss_reset(hba); - spin_lock_irqsave(hba->host->host_lock, flags); - for (tag = 0; tag < hba->host->can_queue; tag++) { - ccb = &hba->ccb[tag]; - if (ccb->req == NULL) - continue; - ccb->req = NULL; - if (ccb->cmd) { - scsi_dma_unmap(ccb->cmd); - ccb->cmd->result = DID_RESET << 16; - ccb->cmd->scsi_done(ccb->cmd); - ccb->cmd = NULL; - } - } - spin_unlock_irqrestore(hba->host->host_lock, flags); + + return_abnormal_state(hba, DID_RESET); if (stex_handshake(hba) == 0) return 0; @@ -1771,9 +1784,11 @@ static void stex_remove(struct pci_dev *pdev) { struct st_hba *hba = pci_get_drvdata(pdev); + hba->mu_status = MU_STATE_NOCONNECT; + return_abnormal_state(hba, DID_NO_CONNECT); scsi_remove_host(hba->host); - stex_hba_stop(hba); + scsi_block_requests(hba->host); stex_hba_free(hba);