From patchwork Mon Feb 22 12:07:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Chiou X-Patchwork-Id: 8376061 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 8DA54C0553 for ; Mon, 22 Feb 2016 12:07:35 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 996D42039E for ; Mon, 22 Feb 2016 12:07:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8A55920306 for ; Mon, 22 Feb 2016 12:07:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753989AbcBVMHR (ORCPT ); Mon, 22 Feb 2016 07:07:17 -0500 Received: from mail-pa0-f67.google.com ([209.85.220.67]:36188 "EHLO mail-pa0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753092AbcBVMHQ (ORCPT ); Mon, 22 Feb 2016 07:07:16 -0500 Received: by mail-pa0-f67.google.com with SMTP id a7so268297pax.3; Mon, 22 Feb 2016 04:07:15 -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=Qp1QOo0FLuDUMJKTXmZMqXK0iKMmqBlFAnWYJ5sMQ5M=; b=S3/G4ZdPmYXo78a5cDMeleq1p0VE75jUBoa3jRHiKzwj98S3zEGI6CL1yFHZT0xvEY 0IMh99a+LsKyPm6eqxLG9AXwzEjXEHT7TjXF3kIYzKcWE8cRzlW3AmLV+0OROI+p3Feq 2tWYdxZG1YTcc4kf7Qmm2DYb+iwUxIdy+3h9X9B0YatLKTUVfNTwKjXFq4g2HUG47/kO ARzo0Ak3Lwv8uNzkOnUmDkKBRmVBd5vTWsZW11eZVOilomopbv7oIX4MPU2qiWzMcmEN TW5Luw4R8zhTaot58Y1+hDXSnvBakfCpQq+8vhfpm81XSKUP1D1OB5d30g3tx+nxTTdh +NLA== 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=Qp1QOo0FLuDUMJKTXmZMqXK0iKMmqBlFAnWYJ5sMQ5M=; b=Ll8xjJ99q87N866IbKAW3DU1hBcPdY43FK4V2koWwBIrGW/wxCI/ehJTcQIGikNST2 pVlaxLMuEhQHCj8ApreIoUTQyeGTr51nN/kf+UWcqNNFc5wCmMJzOHTrXr8u6QQ8zDyZ yDcKPQz0n6NSkaWuvwzMllmjc1RyPpTK9KLuQsaQCZLEf103R+/Vvn6UbzVjQOMwZEaK OND/zXfp6BFZv+9tB4SEFlr35e2EJAMPwDKIVzr5ySXjzVue932cFIyT04x8CzeUitCo J4V866F6QnKwbtctNdatthbDQzkXHf3/Y7+HrZkrAGG+v9myayT52VWUK2cT9vk6QNTd OyHQ== X-Gm-Message-State: AG10YOTbm8Rt/7T4CPR6nZoSicbun8boas8/FcT8LiQEGHfMDbHQP0vnvSxCnz8HoGQbFg== X-Received: by 10.66.65.109 with SMTP id w13mr37404440pas.142.1456142835158; Mon, 22 Feb 2016 04:07:15 -0800 (PST) Received: from charles-desktop.promise.com.tw (vpn.promise.com.tw. [61.222.81.253]) by smtp.gmail.com with ESMTPSA id fl9sm36677873pab.30.2016.02.22.04.07.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Feb 2016 04:07:14 -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 3/3] scsi:stex.c Add S3/S4 support Date: Mon, 22 Feb 2016 20:07:09 +0800 Message-Id: <1456142829-25375-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 Add S3/S4 support, add .suspend and .resume function in pci_driver. In .suspend handler, driver send S3/S4 signal to the device. Signed-off-by: Charles Chiou Reviewed-by: Johannes Thumshirn --- drivers/scsi/stex.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 65 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/stex.c b/drivers/scsi/stex.c index 1994603..5b23175 100644 --- a/drivers/scsi/stex.c +++ b/drivers/scsi/stex.c @@ -167,6 +167,14 @@ enum { ST_ADDITIONAL_MEM = 0x200000, ST_ADDITIONAL_MEM_MIN = 0x80000, + PMIC_SHUTDOWN = 0x0D, + PMIC_REUMSE = 0x10, + ST_IGNORED = -1, + ST_NOTHANDLED = 7, + ST_S3 = 3, + ST_S4 = 4, + ST_S5 = 5, + ST_S6 = 6, }; struct st_sgitem { @@ -1718,7 +1726,7 @@ out_disable: return err; } -static void stex_hba_stop(struct st_hba *hba) +static void stex_hba_stop(struct st_hba *hba, int st_sleep_mic) { struct req_msg *req; struct st_msg_header *msg_h; @@ -1727,6 +1735,15 @@ static void stex_hba_stop(struct st_hba *hba) u16 tag = 0; spin_lock_irqsave(hba->host->host_lock, flags); + + if (hba->cardtype == st_yel && hba->supports_pm == 1) + { + if(st_sleep_mic == ST_NOTHANDLED) + { + spin_unlock_irqrestore(hba->host->host_lock, flags); + return; + } + } req = hba->alloc_rq(hba); if (hba->cardtype == st_yel) { msg_h = (struct st_msg_header *)req - 1; @@ -1734,11 +1751,18 @@ static void stex_hba_stop(struct st_hba *hba) } else memset(req, 0, hba->rq_size); - if (hba->cardtype == st_yosemite || hba->cardtype == st_yel) { + if ((hba->cardtype == st_yosemite || hba->cardtype == st_yel) + && st_sleep_mic == ST_IGNORED) { req->cdb[0] = MGT_CMD; req->cdb[1] = MGT_CMD_SIGNATURE; req->cdb[2] = CTLR_CONFIG_CMD; req->cdb[3] = CTLR_SHUTDOWN; + } else if (hba->cardtype == st_yel && st_sleep_mic != ST_IGNORED) { + req->cdb[0] = MGT_CMD; + req->cdb[1] = MGT_CMD_SIGNATURE; + req->cdb[2] = CTLR_CONFIG_CMD; + req->cdb[3] = PMIC_SHUTDOWN; + req->cdb[4] = st_sleep_mic; } else { req->cdb[0] = CONTROLLER_CMD; req->cdb[1] = CTLR_POWER_STATE_CHANGE; @@ -1758,10 +1782,12 @@ static void stex_hba_stop(struct st_hba *hba) while (hba->ccb[tag].req_type & PASSTHRU_REQ_TYPE) { if (time_after(jiffies, before + ST_INTERNAL_TIMEOUT * HZ)) { hba->ccb[tag].req_type = 0; + hba->mu_status = MU_STATE_STOP; return; } msleep(1); } + hba->mu_status = MU_STATE_STOP; } static void stex_hba_free(struct st_hba *hba) @@ -1801,9 +1827,43 @@ static void stex_shutdown(struct pci_dev *pdev) { struct st_hba *hba = pci_get_drvdata(pdev); - stex_hba_stop(hba); + if (hba->supports_pm == 0) + stex_hba_stop(hba, ST_IGNORED); + else + stex_hba_stop(hba, ST_S5); +} + +static int stex_choice_sleep_mic(pm_message_t state) +{ + switch (state.event) { + case PM_EVENT_SUSPEND: + return ST_S3; + case PM_EVENT_HIBERNATE: + return ST_S4; + default: + return ST_NOTHANDLED; + } } +static int stex_suspend(struct pci_dev *pdev, pm_message_t state) +{ + struct st_hba *hba = pci_get_drvdata(pdev); + + if (hba->cardtype == st_yel && hba->supports_pm == 1) + stex_hba_stop(hba, stex_choice_sleep_mic(state)); + else + stex_hba_stop(hba, ST_IGNORED); + return 0; +} + +static int stex_resume(struct pci_dev *pdev) +{ + struct st_hba *hba = pci_get_drvdata(pdev); + + hba->mu_status = MU_STATE_STARTING; + stex_handshake(hba); + return 0; +} MODULE_DEVICE_TABLE(pci, stex_pci_tbl); static struct pci_driver stex_pci_driver = { @@ -1812,6 +1872,8 @@ static struct pci_driver stex_pci_driver = { .probe = stex_probe, .remove = stex_remove, .shutdown = stex_shutdown, + .suspend = stex_suspend, + .resume = stex_resume, }; static int __init stex_init(void)