From patchwork Mon Aug 7 07:43:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 9884633 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 71B53603FA for ; Mon, 7 Aug 2017 07:46:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 605F9285C6 for ; Mon, 7 Aug 2017 07:46:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55258285E3; Mon, 7 Aug 2017 07:46:53 +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 1DEC1285CF for ; Mon, 7 Aug 2017 07:46:50 +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 1dechU-0005Q5-RG; Mon, 07 Aug 2017 07:43:44 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dechT-0005O8-Gm for xen-devel@lists.xen.org; Mon, 07 Aug 2017 07:43:43 +0000 Received: from [85.158.139.211] by server-4.bemta-5.messagelabs.com id 07/A9-02184-E2A18895; Mon, 07 Aug 2017 07:43:42 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrIIsWRWlGSWpSXmKPExsVyMfS6o66mVEe kwYE2AYslHxezODB6HN39mymAMYo1My8pvyKBNaNj53qWggfSFQu/d7A0MH4W72Lk4hAS6GeU ePvpPBuIwyLwkkVi27srLCCOhEA/q8TSNetYuxg5gJw4id9nnLoYOYHMcokDe66wg9hCAooSX 59NZ4KYtJJJYs6vK4wgCTYBI4nlN36wgNgiAhESxx5/YAOxmQVKJW7sn8MMYgsLOEu8eXELzG YRUJWYdnUj2FBeASeJ1ctWM0Isk5O4ea4TrIYTqP78+TVg9wgB1Zx4lTqBUWABI8MqRo3i1KK y1CJdQ2O9pKLM9IyS3MTMHF1DA1O93NTi4sT01JzEpGK95PzcTYzAwGIAgh2M/7Z5HmKU5GBS EuWNX9EWKcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mC955ER6SQYFFqempFWmYOMMRh0hIcPEoiv KtB0rzFBYm5xZnpEKlTjPYcV66s+8LEsWH1eiA55cB2IPlqwv9vTEIsefl5qVLivPNB2gRA2j JK8+CGwmLyEqOslDAvI9CZQjwFqUW5mSWo8q8YxTkYlYR5n4JM4cnMK4Hb/QroLCags94ktoK cVZKIkJJqYFQyO/9GiOFf/TsB9VNXZ30yPSAffcOwxn6FFcMGa2c7ngNLcu0nPzPtd9r8+3J3 wVUOhZmCd6+5vYuoijY5fOvLhDruSomcDcx8bFanWHu7e7QObPv2n+UR76P5fCwqT+VZxV2i7 z8+otNwrunw7pNdD1Lv75Y20b8v/P7OGY47dy8Ly01rK1JiKc5INNRiLipOBADGM4b4xAIAAA == X-Env-Sender: andr2000@gmail.com X-Msg-Ref: server-6.tower-206.messagelabs.com!1502091816!103282600!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 1042 invoked from network); 7 Aug 2017 07:43:37 -0000 Received: from mail-lf0-f65.google.com (HELO mail-lf0-f65.google.com) (209.85.215.65) by server-6.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 7 Aug 2017 07:43:37 -0000 Received: by mail-lf0-f65.google.com with SMTP id 65so4871839lfa.0 for ; Mon, 07 Aug 2017 00:43:37 -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=X1lQwsqeKIU2OXom/Mf2JNZdwjIT1XEHYp/swnNFEkKSuSJoD2qYfqap1YaiJgX+Ja 1CQs5JZImsFWuX03vnuao9DCq2jdbcLCswHVUEtS8Rjc3l0lU9iTi29TRVFtg3pmACbK S7XyLtlJobL9xgQ7QyJnvs8JHBKO93jI9HrNYUaeOSK91nRhOziMCVbHJkzjUn+Q0Qyy 78DpxIE/8j18hU1Jq8ra/BdiuKS4az8i07ScBp8dRhQCZXmX0K3/ZFRo4VFtoTzpFF8E aSqLhZDOhX8MV4AFBMKoBhiknyP28wIEOYsd/d7TzYUTAFZ1CsRoMUEhgJOLrXNQA5v7 Y8zQ== 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=EC7vhZazlBND41rOFhMR0DFyJv5gFUr92Eb2i07kyzeIsYjLwnSBGFnUNzs7RnxFQM hEOdzw+m4JcmUZySVlqw8REIrRJjN3ax8RDwcqQfQH33u2FKCkCaLIXgjC89Pr6IT9PJ ppsjOiD2XNFPZu2owUB1coF7lcR873/86jHBMat2ex1IpdKOomMS1ZtgDFebSDHEMka3 6TqqXmmJe00To6eqmwY/IQIHat0VEWcTtLUIZPuCYqTao92S94NtsWNYZ6e2AHLmCFR4 ySpgJ5tfc6+MKvQM0oGHwXSAyZekeK99CBYLTxz8zXf4sy3yRC3b2g2tePFoXO0hQMfx ADrA== X-Gm-Message-State: AHYfb5hEbmzMXr3OGeQLqwycnvFfebFrzPL/mNpHqtUKhvzuXjAElQCq zzmx0CForhXn4Q== X-Received: by 10.46.77.84 with SMTP id a81mr3498529ljb.24.1502091816554; Mon, 07 Aug 2017 00:43:36 -0700 (PDT) Received: from a2k-HP-ProDesk-600-G2-SFF.kyiv.epam.com (ll-52.209.223.85.sovam.net.ua. [85.223.209.52]) by smtp.gmail.com with ESMTPSA id f136sm399062lff.34.2017.08.07.00.43.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Aug 2017 00:43:36 -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 10:43:07 +0300 Message-Id: <1502091796-14413-3-git-send-email-andr2000@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502091796-14413-1-git-send-email-andr2000@gmail.com> References: <1502091796-14413-1-git-send-email-andr2000@gmail.com> Cc: andr2000@gmail.com, Oleksandr Andrushchenko , tiwai@suse.com, perex@perex.cz Subject: [Xen-devel] [PATCH 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);