Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3515799pxa; Wed, 26 Aug 2020 02:29:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz4bpM9tRhpmY3/3nSFt0/uF+zsr0EzNm553K3yCWz/9WDgZBVWwm87vMcAT8Vz47xPYQBb X-Received: by 2002:a05:6402:b9c:: with SMTP id cf28mr3897764edb.274.1598434173231; Wed, 26 Aug 2020 02:29:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598434173; cv=none; d=google.com; s=arc-20160816; b=kltdx/7001k9+aK/GOUTdFydm439Mvvj0AdUvmH5tZ/n3/vyjwmOHISNOPhk2KzFvO yJkjmKP+KbksM4H62gjAF6aTcpoyN8knn9YTv7UP+2Jw+l9xh4NQ0uW7SoYFewUswz1V cNMnVxRwCHK/a07zXyru/PPHhCwPTOnEZyCVFAiJiYmW20ek4MO65uNUKtP7lctdG7Jd dvW+WCu61yevFPCTTRVMq2tL8NyveW2cZI2xcd92EV++uWPahNXvI3gpxIByB1982ANa AS1CbvrnoS8Szd7cH2fx0DbauswBCHjKxK01BNDj2oHt3hlpQIuHEGUrYYnxGmf6neSQ YQYg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=wV1ctCfTafETCE/oBZxdiGpSKZZdtDXC4lSzecUAFSU=; b=zwerS7eubn2cI/5aaMJeX3uF/tuN0CL7pv1HgNAlwzuBwvT52sq7JWYyKIJ+c9oOcc xG7BIrYKBvcTIkLp6DAgDcI98LBl3mms3oD6w5XV59uHWVgZyrqyxysMXpDsTOs+azxk qU3sJg/QywjCIYK7V1lzI6p1ncOm2L9aK3qQbMf5423QptjXZPO/xFcRsZaC0ooRO30O lmF+aj7hAiYTDH9W7oQXVkN132dOEe3ZHAh1uoF4eMVeHFh/koTo+MzXP/NZDg6V0dUP UrnHNCFvADKkTYUtaD7LCpfbrlhQUV+jApLC03oytnNTB0xL+NkGFN2uLACxqodCtdJE R34A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g13si1202441ejs.545.2020.08.26.02.29.10; Wed, 26 Aug 2020 02:29:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728203AbgHZJ13 (ORCPT + 99 others); Wed, 26 Aug 2020 05:27:29 -0400 Received: from inva020.nxp.com ([92.121.34.13]:56396 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727998AbgHZJ0I (ORCPT ); Wed, 26 Aug 2020 05:26:08 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id B64351A08F2; Wed, 26 Aug 2020 11:26:04 +0200 (CEST) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id A84761A08B7; Wed, 26 Aug 2020 11:26:04 +0200 (CEST) Received: from fsr-ub1864-111.ea.freescale.net (fsr-ub1864-111.ea.freescale.net [10.171.82.141]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id 4B94B202CA; Wed, 26 Aug 2020 11:26:04 +0200 (CEST) From: Diana Craciun To: linux-kernel@vger.kernel.org, laurentiu.tudor@nxp.com Cc: stuyoder@gmail.com, leoyang.li@nxp.com, gregkh@linuxfoundation.org, linux-arm-kernel@lists.infradead.org, bharatb.linux@gmail.com, Bharat Bhushan , Diana Craciun Subject: [PATCH v4 06/13] bus/fsl-mc: Add dprc-reset-container support Date: Wed, 26 Aug 2020 12:25:20 +0300 Message-Id: <20200826092527.4992-7-diana.craciun@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200826092527.4992-1-diana.craciun@oss.nxp.com> References: <20200826092527.4992-1-diana.craciun@oss.nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bharat Bhushan DPRC reset is required by VFIO-mc in order to stop a device to further generate DMA transactions. Signed-off-by: Bharat Bhushan Signed-off-by: Laurentiu Tudor Signed-off-by: Diana Craciun --- drivers/bus/fsl-mc/dprc.c | 71 +++++++++++++++++++++++++++++ drivers/bus/fsl-mc/fsl-mc-private.h | 7 +++ include/linux/fsl/mc.h | 7 +++ 3 files changed, 85 insertions(+) diff --git a/drivers/bus/fsl-mc/dprc.c b/drivers/bus/fsl-mc/dprc.c index e76f2c76f4c8..2448a723eb28 100644 --- a/drivers/bus/fsl-mc/dprc.c +++ b/drivers/bus/fsl-mc/dprc.c @@ -80,6 +80,77 @@ int dprc_close(struct fsl_mc_io *mc_io, } EXPORT_SYMBOL_GPL(dprc_close); +/** + * dprc_reset_container - Reset child container. + * @mc_io: Pointer to MC portal's I/O object + * @cmd_flags: Command flags; one or more of 'MC_CMD_FLAG_' + * @token: Token of DPRC object + * @child_container_id: ID of the container to reset + * @options: 32 bit options: + * - 0 (no bits set) - all the objects inside the container are + * reset. The child containers are entered recursively and the + * objects reset. All the objects (including the child containers) + * are closed. + * - bit 0 set - all the objects inside the container are reset. + * However the child containers are not entered recursively. + * This option is supported for API versions >= 6.5 + * In case a software context crashes or becomes non-responsive, the parent + * may wish to reset its resources container before the software context is + * restarted. + * + * This routine informs all objects assigned to the child container that the + * container is being reset, so they may perform any cleanup operations that are + * needed. All objects handles that were owned by the child container shall be + * closed. + * + * Note that such request may be submitted even if the child software context + * has not crashed, but the resulting object cleanup operations will not be + * aware of that. + * + * Return: '0' on Success; Error code otherwise. + */ +int dprc_reset_container(struct fsl_mc_io *mc_io, + u32 cmd_flags, + u16 token, + int child_container_id, + u32 options) +{ + struct fsl_mc_command cmd = { 0 }; + struct dprc_cmd_reset_container *cmd_params; + u32 cmdid = DPRC_CMDID_RESET_CONT; + int err; + + /* + * If the DPRC object version was not yet cached, cache it now. + * Otherwise use the already cached value. + */ + if (!dprc_major_ver && !dprc_minor_ver) { + err = dprc_get_api_version(mc_io, 0, + &dprc_major_ver, + &dprc_minor_ver); + if (err) + return err; + } + + /* + * MC API 6.5 introduced a new field in the command used to pass + * some flags. + * Bit 0 indicates that the child containers are not recursively reset. + */ + if (dprc_major_ver > 6 || (dprc_major_ver == 6 && dprc_minor_ver >= 5)) + cmdid = DPRC_CMDID_RESET_CONT_V2; + + /* prepare command */ + cmd.header = mc_encode_cmd_header(cmdid, cmd_flags, token); + cmd_params = (struct dprc_cmd_reset_container *)cmd.params; + cmd_params->child_container_id = cpu_to_le32(child_container_id); + cmd_params->options = cpu_to_le32(options); + + /* send command to mc*/ + return mc_send_command(mc_io, &cmd); +} +EXPORT_SYMBOL_GPL(dprc_reset_container); + /** * dprc_set_irq() - Set IRQ information for the DPRC to trigger an interrupt. * @mc_io: Pointer to MC portal's I/O object diff --git a/drivers/bus/fsl-mc/fsl-mc-private.h b/drivers/bus/fsl-mc/fsl-mc-private.h index 9f200731b274..5f7e762d517c 100644 --- a/drivers/bus/fsl-mc/fsl-mc-private.h +++ b/drivers/bus/fsl-mc/fsl-mc-private.h @@ -91,6 +91,8 @@ int dpmcp_reset(struct fsl_mc_io *mc_io, #define DPRC_CMDID_GET_API_VERSION DPRC_CMD(0xa05) #define DPRC_CMDID_GET_ATTR DPRC_CMD(0x004) +#define DPRC_CMDID_RESET_CONT DPRC_CMD(0x005) +#define DPRC_CMDID_RESET_CONT_V2 DPRC_CMD_V2(0x005) #define DPRC_CMDID_SET_IRQ DPRC_CMD(0x010) #define DPRC_CMDID_SET_IRQ_ENABLE DPRC_CMD(0x012) @@ -111,6 +113,11 @@ struct dprc_cmd_open { __le32 container_id; }; +struct dprc_cmd_reset_container { + __le32 child_container_id; + __le32 options; +}; + struct dprc_cmd_set_irq { /* cmd word 0 */ __le32 irq_val; diff --git a/include/linux/fsl/mc.h b/include/linux/fsl/mc.h index 03a5d16dde73..1d8800acf21f 100644 --- a/include/linux/fsl/mc.h +++ b/include/linux/fsl/mc.h @@ -524,6 +524,13 @@ static inline bool is_fsl_mc_bus_dpdmai(const struct fsl_mc_device *mc_dev) return mc_dev->dev.type == &fsl_mc_bus_dpdmai_type; } +#define DPRC_RESET_OPTION_NON_RECURSIVE 0x00000001 +int dprc_reset_container(struct fsl_mc_io *mc_io, + u32 cmd_flags, + u16 token, + int child_container_id, + u32 options); + /* * Data Path Buffer Pool (DPBP) API * Contains initialization APIs and runtime control APIs for DPBP -- 2.17.1