From patchwork Mon Aug 7 12:22:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksandr Andrushchenko X-Patchwork-Id: 9885215 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 778BB60363 for ; Mon, 7 Aug 2017 12:23:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 691552858A for ; Mon, 7 Aug 2017 12:23:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E28328671; Mon, 7 Aug 2017 12:23:30 +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 AB2E92858A for ; Mon, 7 Aug 2017 12:23:29 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 0E6F026723C; Mon, 7 Aug 2017 14:23:14 +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 797F126723C; Mon, 7 Aug 2017 14:23:12 +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 70297267205 for ; Mon, 7 Aug 2017 14:23:07 +0200 (CEST) Received: by mail-lf0-f66.google.com with SMTP id t128so214146lff.3 for ; Mon, 07 Aug 2017 05:23:07 -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=vG8a5SU2BnYxjWJjYMzZ9mdayXVP6RgeYaaY1Wwhw3kc3x6C54XcLh11v+CHTsff03 Fil8ghVmdtvlqaEitUsQqxidI+5+Sr4DhDTxRJYfKrwYucr/al8orvJd4pqkwjeetd6u iVvJ9izrwAUXoqD1/FoDwLJ/lerLOPc6yRK8gaRw3ps66m33ybTJOLP3wnahZ8olrRlY JIVgTb6MmqF9ymZ8h2TbRlQdvnJKfWMBDueZKXwqBDwgq9Vcz2NPRt/v7evFTEFUCwBI ytMhmPjvI4SxUN24uBUcYdXJnZqreOTnv9nxhJYVskN9PBJJ7hqo98LmHf9qBqgO6GHo KolQ== 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=WB9pHgkJTfbddoTQpqqm2FQ/WIaSemxSslemi3OeEQEAuZlqwngXWaznpxgo9DGk1O XX0/c4LXAA608dXSq2sWva+L28caAdGhOwSx5CcaNf9IhNhh0YXeSGlpK5qo6cK66UFm tm9dC65XY+djoHiRGCEobn2CyECSTImA9Y1JTB0JHwJAhuGucxH10Y1+Q6OGhJnQKffO D7tguHruoFUqzoNVquhYC7Zpsk0KJoOTqCa9ByfFrMD8Fj4MdlYntOj2vJa1UguJI3KG J+3/qOVQi9UAvihW/Nh+oHwemgevKptWcp10gi1hC16gvVfGsQTEn/vZ7bNIkV6pfWfb SNNA== X-Gm-Message-State: AHYfb5i+GYHDv7PUbt/jEKNssvFfIkjcycmWMy+ohAyXZ17Nh0wFFif5 o4OcHxavLaabhMNJ X-Received: by 10.25.168.144 with SMTP id r138mr118263lfe.15.1502108586667; Mon, 07 Aug 2017 05:23:06 -0700 (PDT) Received: from a2k-HP-ProDesk-600-G2-SFF.kyiv.epam.com (ll-53.209.223.85.sovam.net.ua. [85.223.209.53]) by smtp.gmail.com with ESMTPSA id m143sm1031821lfm.77.2017.08.07.05.23.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 07 Aug 2017 05:23:06 -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 15:22:48 +0300 Message-Id: <1502108577-8099-4-git-send-email-andr2000@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1502108577-8099-1-git-send-email-andr2000@gmail.com> References: <1502108577-8099-1-git-send-email-andr2000@gmail.com> Cc: andr2000@gmail.com, Oleksandr Andrushchenko , tiwai@suse.com Subject: [alsa-devel] [PATCH RESEND1 03/12] 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);