Received: by 10.192.165.156 with SMTP id m28csp804000imm; Thu, 19 Apr 2018 07:50:57 -0700 (PDT) X-Google-Smtp-Source: AIpwx48D2Ebod7h8RQrJUSEf5qLSW8E0c9nxEKbIRLymn1cxnwEI9yfqQajrzZL6jWKrPkBFMLTj X-Received: by 10.99.183.11 with SMTP id t11mr3129888pgf.193.1524149457707; Thu, 19 Apr 2018 07:50:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524149457; cv=none; d=google.com; s=arc-20160816; b=1Be631HOWC5fplWArwj4VsP6cLl0cp68kuX28SYkKYzhQDvoMhy4MdhrsBRQxs/BmN QBYWmRIyDPY+vZ5aufRp8Rwqo9avKD/IiiO4HACRNhh3JV5XLq+3WsvkMuSmlYzvuOea mIMFpgcRwAsCsPNQ3mDeqUaB4UjImN3XEl3735oT2BO59r2efNZ4OhTZmcXYgobjclQZ tayjq+rcd62z8QYYRwbv1zTqVvEYBgmRkrgGDXzh/Bce9uyrZY2oTXJREMt0LD/4BQC5 aEFFUsKGUW7CPTFyYAQwPkx+dE7rAgEXjLmlTIO9HgKesemR4yRRi+HheR+wUogvqjVb miLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=nEVCkDp7EH6Ke+aLSk/86Zm4I9802ixAnVWP4OOUWoI=; b=YklhLRAl73YAkGKlHGQ+VV+11t7VRX6s2/iHOLHf+qswjsR/FQUGTsVGsuLllsBCvI KlSqQ4LaHryt7D52jTR9N2wRN9YAirMYxjOqAw12/dG/lHDCaQ/aPs2SmZ3/nFV/hxd1 lgDaJcCP8oVcuhTbDFxAHM0xkjkFOeOJ96PtqgI69OlcLZfoFGZGDgQeu09BIqbbmGej dJNr8NgXBEtl7xBwJTGO7LFJKw7rEMV6Rq112+5qBg+RZHXoupEc0FwJCV7BGLVQ9ljw pubg7k0dHMUceTYUqkD4fNwxRI/cYbMwTM7DLqQf6i//Yxf2rcZ62kK0l1Ne2SJDQNAI XVIw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m15si3076213pgu.98.2018.04.19.07.50.43; Thu, 19 Apr 2018 07:50:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753241AbeDSOsg (ORCPT + 99 others); Thu, 19 Apr 2018 10:48:36 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:43820 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752848AbeDSOsd (ORCPT ); Thu, 19 Apr 2018 10:48:33 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3JEmIAI072903 for ; Thu, 19 Apr 2018 10:48:32 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 2heuvc4krj-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Thu, 19 Apr 2018 10:48:29 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 19 Apr 2018 15:48:26 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 19 Apr 2018 15:48:23 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3JEmMH912124584; Thu, 19 Apr 2018 14:48:22 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 245345203F; Thu, 19 Apr 2018 14:39:09 +0100 (BST) Received: from morel-ThinkPad-W530.boeblingen.de.ibm.com (unknown [9.152.224.146]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTP id D47525205A; Thu, 19 Apr 2018 14:39:08 +0100 (BST) From: Pierre Morel To: pasic@linux.vnet.ibm.com, bjsdjshi@linux.vnet.ibm.com Cc: linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, cohuck@redhat.com Subject: [PATCH 07/10] vfio: ccw: Introduce the INIT event Date: Thu, 19 Apr 2018 16:48:10 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524149293-12658-1-git-send-email-pmorel@linux.vnet.ibm.com> References: <1524149293-12658-1-git-send-email-pmorel@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18041914-0040-0000-0000-0000044F5B4D X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041914-0041-0000-0000-000020F3B1AE Message-Id: <1524149293-12658-8-git-send-email-pmorel@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-04-19_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1804190131 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The VFIO_CCW_EVENT_INIT event allows to export the initial state into the FSM. Signed-off-by: Pierre Morel --- drivers/s390/cio/vfio_ccw_drv.c | 26 +++++++++++--------------- drivers/s390/cio/vfio_ccw_fsm.c | 21 +++++++++++++++++++++ drivers/s390/cio/vfio_ccw_ops.c | 11 ----------- drivers/s390/cio/vfio_ccw_private.h | 1 + 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/drivers/s390/cio/vfio_ccw_drv.c b/drivers/s390/cio/vfio_ccw_drv.c index 1c9422a..f6e7def1 100644 --- a/drivers/s390/cio/vfio_ccw_drv.c +++ b/drivers/s390/cio/vfio_ccw_drv.c @@ -116,31 +116,27 @@ static int vfio_ccw_sch_probe(struct subchannel *sch) private = kzalloc(sizeof(*private), GFP_KERNEL | GFP_DMA); if (!private) return -ENOMEM; + private->sch = sch; dev_set_drvdata(&sch->dev, private); mutex_init(&private->state_mutex); - - spin_lock_irq(sch->lock); - private->state = VFIO_CCW_STATE_NOT_OPER; - sch->isc = VFIO_CCW_ISC; - ret = cio_enable_subchannel(sch, (u32)(unsigned long)sch); - spin_unlock_irq(sch->lock); - if (ret) - goto out_free; + INIT_WORK(&private->io_work, vfio_ccw_sch_io_todo); + INIT_WORK(&private->event_work, vfio_ccw_sch_event_todo); + atomic_set(&private->avail, 1); ret = vfio_ccw_mdev_reg(sch); if (ret) - goto out_disable; + goto out_free; - INIT_WORK(&private->io_work, vfio_ccw_sch_io_todo); - INIT_WORK(&private->event_work, vfio_ccw_sch_event_todo); - atomic_set(&private->avail, 1); - private->state = VFIO_CCW_STATE_STANDBY; + vfio_ccw_fsm_event(private, VFIO_CCW_EVENT_INIT); + ret = -EFAULT; + if (private->state != VFIO_CCW_STATE_STANDBY) + goto out_unreg; return 0; -out_disable: - cio_disable_subchannel(sch); +out_unreg: + vfio_ccw_mdev_unreg(sch); out_free: dev_set_drvdata(&sch->dev, NULL); kfree(private); diff --git a/drivers/s390/cio/vfio_ccw_fsm.c b/drivers/s390/cio/vfio_ccw_fsm.c index d85bcfc..e8fe1e6 100644 --- a/drivers/s390/cio/vfio_ccw_fsm.c +++ b/drivers/s390/cio/vfio_ccw_fsm.c @@ -9,6 +9,7 @@ #include #include +#include #include "ioasm.h" #include "vfio_ccw_private.h" @@ -167,35 +168,55 @@ static int fsm_sch_event(struct vfio_ccw_private *private) return ret; } +static int fsm_init(struct vfio_ccw_private *private) +{ + struct subchannel *sch = private->sch; + int ret = VFIO_CCW_STATE_STANDBY; + + spin_lock_irq(sch->lock); + sch->isc = VFIO_CCW_ISC; + if (cio_enable_subchannel(sch, (u32)(unsigned long)sch)) + ret = VFIO_CCW_STATE_NOT_OPER; + spin_unlock_irq(sch->lock); + + return ret; +} + + /* * Device statemachine */ fsm_func_t *vfio_ccw_jumptable[NR_VFIO_CCW_STATES][NR_VFIO_CCW_EVENTS] = { [VFIO_CCW_STATE_NOT_OPER] = { + [VFIO_CCW_EVENT_INIT] = fsm_init, [VFIO_CCW_EVENT_NOT_OPER] = fsm_nop, [VFIO_CCW_EVENT_SSCH_REQ] = fsm_io_error, [VFIO_CCW_EVENT_INTERRUPT] = fsm_disabled_irq, [VFIO_CCW_EVENT_SCH_EVENT] = fsm_nop, }, [VFIO_CCW_STATE_STANDBY] = { + [VFIO_CCW_EVENT_INIT] = fsm_nop, [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, [VFIO_CCW_EVENT_SSCH_REQ] = fsm_io_error, [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, [VFIO_CCW_EVENT_SCH_EVENT] = fsm_sch_event, }, [VFIO_CCW_STATE_IDLE] = { + [VFIO_CCW_EVENT_INIT] = fsm_nop, [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, [VFIO_CCW_EVENT_SSCH_REQ] = fsm_io_request, [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, [VFIO_CCW_EVENT_SCH_EVENT] = fsm_sch_event, }, [VFIO_CCW_STATE_BOXED] = { + [VFIO_CCW_EVENT_INIT] = fsm_nop, [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, [VFIO_CCW_EVENT_SSCH_REQ] = fsm_io_busy, [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, [VFIO_CCW_EVENT_SCH_EVENT] = fsm_sch_event, }, [VFIO_CCW_STATE_BUSY] = { + [VFIO_CCW_EVENT_INIT] = fsm_nop, [VFIO_CCW_EVENT_NOT_OPER] = fsm_notoper, [VFIO_CCW_EVENT_SSCH_REQ] = fsm_io_busy, [VFIO_CCW_EVENT_INTERRUPT] = fsm_irq, diff --git a/drivers/s390/cio/vfio_ccw_ops.c b/drivers/s390/cio/vfio_ccw_ops.c index dac8ce4..78d1925 100644 --- a/drivers/s390/cio/vfio_ccw_ops.c +++ b/drivers/s390/cio/vfio_ccw_ops.c @@ -111,14 +111,10 @@ static int vfio_ccw_mdev_create(struct kobject *kobj, struct mdev_device *mdev) struct vfio_ccw_private *private = dev_get_drvdata(mdev_parent_dev(mdev)); - if (private->state == VFIO_CCW_STATE_NOT_OPER) - return -ENODEV; - if (atomic_dec_if_positive(&private->avail) < 0) return -EPERM; private->mdev = mdev; - private->state = VFIO_CCW_STATE_IDLE; return 0; } @@ -128,13 +124,6 @@ static int vfio_ccw_mdev_remove(struct mdev_device *mdev) struct vfio_ccw_private *private = dev_get_drvdata(mdev_parent_dev(mdev)); - if ((private->state != VFIO_CCW_STATE_NOT_OPER) && - (private->state != VFIO_CCW_STATE_STANDBY)) { - if (!vfio_ccw_mdev_reset(mdev)) - private->state = VFIO_CCW_STATE_STANDBY; - /* The state will be NOT_OPER on error. */ - } - private->mdev = NULL; atomic_inc(&private->avail); diff --git a/drivers/s390/cio/vfio_ccw_private.h b/drivers/s390/cio/vfio_ccw_private.h index cf197cf..cacf677 100644 --- a/drivers/s390/cio/vfio_ccw_private.h +++ b/drivers/s390/cio/vfio_ccw_private.h @@ -76,6 +76,7 @@ enum vfio_ccw_state { * Asynchronous events of the device statemachine. */ enum vfio_ccw_event { + VFIO_CCW_EVENT_INIT, VFIO_CCW_EVENT_NOT_OPER, VFIO_CCW_EVENT_SSCH_REQ, VFIO_CCW_EVENT_INTERRUPT, -- 2.7.4