From patchwork Mon Aug 7 11:50:36 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 9885161 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 71B3260363 for ; Mon, 7 Aug 2017 11:53:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6495B28514 for ; Mon, 7 Aug 2017 11:53:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5966B28621; Mon, 7 Aug 2017 11:53:31 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DA09B28514 for ; Mon, 7 Aug 2017 11:53:30 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1degYk-0003wU-TH; Mon, 07 Aug 2017 11:50:58 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1degYj-0003wB-5o for xen-devel@lists.xen.org; Mon, 07 Aug 2017 11:50:57 +0000 Received: from [85.158.143.35] by server-11.bemta-6.messagelabs.com id 4E/96-03612-02458895; Mon, 07 Aug 2017 11:50:56 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrIIsWRWlGSWpSXmKPExsVyMfS6o658SEe kweULRhZLPi5mcWD0OLr7N1MAYxRrZl5SfkUCa0bHzvUsBQ+kKxZ+72BpYPws3sXIySEk0M8o 8fhnQBcjFweLwEsWiY3rTrKCOBIC/awSjVufMINUSQjESTy9sgzKLpeYvH4OG0S3osTXZ9OZQ BqEBFYySXRvWMcEkmATMJJYfuMHC4gtIhAhcezxB7AGZoFSiRv754ANEhbwkrj3cxWYzSKgKv Hv43R2EJtXwFHi6v5bUMvkJG6e6wSyOTg4BZwkWpdWQOx1lLi7ezb7BEaBBYwMqxg1ilOLylK LdA3N9ZKKMtMzSnITM3N0DQ3M9HJTi4sT01NzEpOK9ZLzczcxAgOLAQh2MN7eGHCIUZKDSUmU N35FW6QQX1J+SmVGYnFGfFFpTmrxIUYZDg4lCd79QR2RQoJFqempFWmZOcAQh0lLcPAoifBmg 6R5iwsSc4sz0yFSpxjtOa5cWfeFiWPD6vVAcsqB7UDy1YT/35iEWPLy81KlxHnXg7QJgLRllO bBDYXF5CVGWSlhXkagM4V4ClKLcjNLUOVfMYpzMCoJ8z4AmcKTmVcCt/sV0FlMQGe9SWwFOas kESEl1cDoIGkcdU7Qxuq4g+sOsXLdTWFOnkobs/c77p/WxBQ4t3QdM8OmDXvL+1i+Kc288NiB i2f21pNxCZrvdsyc5tRZ96BUfuG2qrJY1TMeM9aoWnCXCuSa7Ba7ffyumIBfM7PQpGnH7X9X7 QvekSB7S5r1/YFwV79X3xpvz+FYvkG0cL9ccmhZfqESS3FGoqEWc1FxIgAaJJZoxAIAAA== X-Env-Sender: andr2000@gmail.com X-Msg-Ref: server-10.tower-21.messagelabs.com!1502106655!70142740!1 X-Originating-IP: [209.85.215.65] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 32582 invoked from network); 7 Aug 2017 11:50:55 -0000 Received: from mail-lf0-f65.google.com (HELO mail-lf0-f65.google.com) (209.85.215.65) by server-10.tower-21.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 7 Aug 2017 11:50:55 -0000 Received: by mail-lf0-f65.google.com with SMTP id x16so154249lfb.4 for ; Mon, 07 Aug 2017 04:50:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=+7QWsVvVYvOb2WNcyS+d3MCS+b7eG7EA7+tRwI7YygE=; b=ajhC4ZGiJuzXTRPvR6QaYorPp3qpY45WP7i71xHM1b+oNNG5ewlIj1Sp214jbP4kne edfdrb9imfPO8Ac4EHaqGh+EHgne9J5i06y125UqvubejQAbpa6TQ6h7pPyyUrTAxWd3 wK6XwEuXR6S8ZUUB5DvDNXo/zuVJyeF3tGzuSWhC3Qx6zo2n1o0NhtWaRmvEEgZrls10 DoG0vjnyeijC36Gb9EdmPX9yiSAmnqV17H36wJ8wcOUvkNe8kD3AMrFyj/JrgI0ZNwOr tokdcd3oq1rExHTGsDwnTJqebOeEE7LSpjperInF5lZID+LkJEc0ivCXi9xotVT8sJRn YOnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+7QWsVvVYvOb2WNcyS+d3MCS+b7eG7EA7+tRwI7YygE=; b=MxTj+UW0ufoYveUDPPMYa2h9a/l4TnItGFGNQgR0snp4RKA6W8WsT6xOAzVwUhGvAG rVCh1IGl+9OscUWB+IfU8Q2fUD16qhXnIU9f1EImC+GnHj3UJXJIBTQB8mBnUOhtlcAL ljLeIrClRv3eEf0SChiGwsoo/mu6j2Ocb2M6I1Z9dD2Xwklx0YR2OXtEEfz5jv/yS7me kzP9r+eqNniMmvsI6JyRz6neiRmwtGss/jCWYXICKXI++WiuUDEeUrfhwIwfOy9v3dxy Bprr96bSGl2xD1s0kgYevSIrw6pRLWtjwITdmxewd1uCtNwR7dakzkOqYnByN79Ftc1x yIZQ== X-Gm-Message-State: AHYfb5jbBIfXNeEbapXUgXLRI5REL0AiK+cByQlQUPVFKUNvgUSvR8ki JBOiAGmWNxMvWw== X-Received: by 10.25.223.87 with SMTP id q23mr90042lfj.192.1502106655083; Mon, 07 Aug 2017 04:50:55 -0700 (PDT) Received: from a2k-HP-ProDesk-600-G2-SFF.kyiv.epam.com (ll-51.209.223.85.sovam.net.ua. [85.223.209.51]) by smtp.gmail.com with ESMTPSA id n88sm2844587lja.43.2017.08.07.04.50.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Aug 2017 04:50:54 -0700 (PDT) From: Oleksandr Andrushchenko To: alsa-devel@alsa-project.org, xen-devel@lists.xen.org, linux-kernel@vger.kernel.org Date: Mon, 7 Aug 2017 14:50:36 +0300 Message-Id: <1502106645-6731-3-git-send-email-andr2000@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502106645-6731-1-git-send-email-andr2000@gmail.com> References: <1502106645-6731-1-git-send-email-andr2000@gmail.com> Cc: andr2000@gmail.com, Oleksandr Andrushchenko , tiwai@suse.com, perex@perex.cz Subject: [Xen-devel] [PATCH RESEND 02/11] ALSA: vsnd: Implement Xen bus state handling X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Oleksandr Andrushchenko Initial handling for Xen bus states: implement Xen bus state machine for the front driver according to the state diagram and recovery flow from sound para-virtualized protocol: xen/interface/io/sndif.h. Signed-off-by: Oleksandr Andrushchenko --- sound/drivers/xen-front.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/sound/drivers/xen-front.c b/sound/drivers/xen-front.c index 8c5de7b0e7b5..c4fd21cac3a7 100644 --- a/sound/drivers/xen-front.c +++ b/sound/drivers/xen-front.c @@ -36,9 +36,99 @@ static void xdrv_remove_internal(struct xdrv_info *drv_info) { } +static int xdrv_be_on_initwait(struct xdrv_info *drv_info) +{ + return 0; +} + +static inline int xdrv_be_on_connected(struct xdrv_info *drv_info) +{ + return 0; +} + +static inline void xdrv_be_on_disconnected(struct xdrv_info *drv_info) +{ + xdrv_remove_internal(drv_info); +} + static void xdrv_be_on_changed(struct xenbus_device *xb_dev, enum xenbus_state backend_state) { + struct xdrv_info *drv_info = dev_get_drvdata(&xb_dev->dev); + int ret; + + switch (backend_state) { + case XenbusStateReconfiguring: + /* fall through */ + case XenbusStateReconfigured: + /* fall through */ + case XenbusStateInitialised: + /* fall through */ + break; + + case XenbusStateInitialising: + if (xb_dev->state == XenbusStateInitialising) + break; + + /* recovering after backend unexpected closure */ + mutex_lock(&drv_info->mutex); + xdrv_be_on_disconnected(drv_info); + mutex_unlock(&drv_info->mutex); + xenbus_switch_state(xb_dev, XenbusStateInitialising); + break; + + case XenbusStateInitWait: + if (xb_dev->state != XenbusStateInitialising) + break; + + mutex_lock(&drv_info->mutex); + ret = xdrv_be_on_initwait(drv_info); + mutex_unlock(&drv_info->mutex); + if (ret < 0) { + xenbus_dev_fatal(xb_dev, ret, + "initializing " XENSND_DRIVER_NAME); + break; + } + + xenbus_switch_state(xb_dev, XenbusStateInitialised); + break; + + case XenbusStateConnected: + if (xb_dev->state != XenbusStateInitialised) + break; + + mutex_lock(&drv_info->mutex); + ret = xdrv_be_on_connected(drv_info); + mutex_unlock(&drv_info->mutex); + if (ret < 0) { + xenbus_dev_fatal(xb_dev, ret, + "connecting " XENSND_DRIVER_NAME); + break; + } + + xenbus_switch_state(xb_dev, XenbusStateConnected); + break; + + case XenbusStateClosing: + /* + * in this state backend starts freeing resources, + * so let it go into closed state first, so we can also + * remove ours + */ + break; + + case XenbusStateUnknown: + /* fall through */ + case XenbusStateClosed: + if (xb_dev->state == XenbusStateClosed) + break; + + mutex_lock(&drv_info->mutex); + xdrv_be_on_disconnected(drv_info); + mutex_unlock(&drv_info->mutex); + xenbus_switch_state(xb_dev, XenbusStateInitialising); + break; + } } static int xdrv_probe(struct xenbus_device *xb_dev, @@ -56,6 +146,7 @@ static int xdrv_probe(struct xenbus_device *xb_dev, spin_lock_init(&drv_info->io_lock); mutex_init(&drv_info->mutex); dev_set_drvdata(&xb_dev->dev, drv_info); + xenbus_switch_state(xb_dev, XenbusStateInitialising); return 0; } @@ -63,6 +154,7 @@ static int xdrv_remove(struct xenbus_device *dev) { struct xdrv_info *drv_info = dev_get_drvdata(&dev->dev); + xenbus_switch_state(dev, XenbusStateClosed); mutex_lock(&drv_info->mutex); xdrv_remove_internal(drv_info); mutex_unlock(&drv_info->mutex);