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: 9885133 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 EF2F260363 for ; Mon, 7 Aug 2017 11:52:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1E1328514 for ; Mon, 7 Aug 2017 11:52:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D613C2860D; Mon, 7 Aug 2017 11:52:36 +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=-1.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1706828514 for ; Mon, 7 Aug 2017 11:52:36 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id DCCA02671F4; Mon, 7 Aug 2017 13:51:10 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 44AB42671CF; Mon, 7 Aug 2017 13:51:07 +0200 (CEST) Received: from mail-lf0-f66.google.com (mail-lf0-f66.google.com [209.85.215.66]) by alsa0.perex.cz (Postfix) with ESMTP id B76E72669F6 for ; Mon, 7 Aug 2017 13:50:55 +0200 (CEST) Received: by mail-lf0-f66.google.com with SMTP id x16so154281lfb.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=OQOD8u52tMHhYiQsXzNPclzFWaUMm3yVoZoO4lBRGtI6mH4o0Q7Mj6AaDAMkflQ5w4 LH76ZvXBZKik4UZzpVIX7Mzn7noI49+XXfId30VM8tRVHSTI99sDDKDYX/PQNujX++ym 66jAvzU2LT6jJcL27a+ZrNpKPO7fB9ulmX6p54Qcl8umWKopGNI9bYy7assEhqM4QSBm 3ZMrYj9fiey8aFa5EI80F01c/bYysPbhTM3E3dQJ3S69SUMFP0sWdBXky42TjNHaDcFe kN48SzNVqfncuWqmktZM20GY4gVN51aOzO8ZXeBjbznBs8lYBGTOomfMzwv1JuJ2EFFb JbLQ== X-Gm-Message-State: AHYfb5iG/uGNUtVIQhDuD/S2qD3GtIjWVTmo8GRfC1bRn9FiqsFd41h2 KQFfY/wOzbsqAK+v 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 Subject: [alsa-devel] [PATCH RESEND 02/11] ALSA: vsnd: Implement Xen bus state handling X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org 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);