Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp618974pxf; Wed, 24 Mar 2021 11:41:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzhbo+Hb1uz5HNchp3Zzr4HDCB8FpvZD/Wv4UMP7gvQRj5Gav7I25gi9iWTlau7XtZbmk7o X-Received: by 2002:a05:6402:4395:: with SMTP id o21mr4966131edc.22.1616611308364; Wed, 24 Mar 2021 11:41:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616611308; cv=none; d=google.com; s=arc-20160816; b=tzZ6zA9DiXrPO+9wbBgSVqyNTuHykMhgpToCiYPQeslZiov0OgXqVAZvmRpZF0+8VA r3nQSAuqhy4UC3xJ2j4u/NrdTU/GUd3LbCaPC/LzBxeW/qEjB0Bz7bbRfuJY41LAKohk mvCbYrE01+y8ahx3k99L8KIVvmkD6yYwZ4+SOFjk+Re9zKiGp1nhFhkTOTxJjbJueS9A DH2P6zxVKcdMwapVgVmHEPGsTiJ40jX3VYeD7ebehrt8ZvDMIKURvqtQ7XAIZpwsfY6D XV8DLHJguETUSzkPG1S01A54aC8ydRg09zdoU1CMHkx+BWCNDGwnmXOXOnk0WcLgyPYf lL8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=Nlb4J8QfOelwlnVhnuVeazNsV5VWmoHRE4rjQ7vnHyk=; b=r08rxb+a51ehMUmi1td/5SMI18HSfczVY+AydsAmI5OJruV7m4eu8TYha1yHmfpd/d +CXvoxyf6WzAsC+5dEFk8A8o30Y7qlKJmedfKurByc6QoJRikq/w3Miuh9OdAhFpG052 tuiB91BNs0eHS/EzllLCJnC/b/jgilJ9SCGD3VGlWOkMdz1t5FGG/hRyYU3vMWwtK/Qo nt7nGBeyhU6RsDfpC03SEMb3kNimkLBL5cO869+7p1x0OXtsl2tailMNspofeEKoYQ/E Nnr4/YrZChNMdSUKoQXMbVCqhO5cz1qZ0oXLSshACUY8Wfd2+6lgKUqjizAqQdvMzNT8 zEqA== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h18si2498204ejd.89.2021.03.24.11.41.24; Wed, 24 Mar 2021 11:41:48 -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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237677AbhCXSik (ORCPT + 99 others); Wed, 24 Mar 2021 14:38:40 -0400 Received: from mga09.intel.com ([134.134.136.24]:17716 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237345AbhCXSiU (ORCPT ); Wed, 24 Mar 2021 14:38:20 -0400 IronPort-SDR: Rt3sDtS/xnGEIVuQSicl0FLQDGVQZOgbm22/geWAJBxyy1vo4Jyatx/uzrVl7yatNA6jAi6cHh TDt8WEC1q/9g== X-IronPort-AV: E=McAfee;i="6000,8403,9933"; a="190859485" X-IronPort-AV: E=Sophos;i="5.81,275,1610438400"; d="scan'208";a="190859485" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2021 11:38:20 -0700 IronPort-SDR: 81diljX1HUvwqyM9rtcMEq5phDKGfuuxRsO9qKVI4/fL8E1YJ7VdTFxX1csr5YvEaxMxapqunv TwCitVVYwb/A== X-IronPort-AV: E=Sophos;i="5.81,275,1610438400"; d="scan'208";a="608203746" Received: from gna-dev.igk.intel.com ([10.102.80.34]) by fmsmga005-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Mar 2021 11:38:17 -0700 From: Maciej Kwapulinski To: Greg Kroah-Hartman , Arnd Bergmann , Jonathan Corbet , Derek Kiernan , Dragan Cvetic , Andy Shevchenko Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Maciej Kwapulinski , Tomasz Jankowski , Savo Novakovic , Jianxun Zhang Subject: [PATCH v2 02/13] intel_gna: add component of hardware operation Date: Wed, 24 Mar 2021 19:35:59 +0100 Message-Id: <20210324183610.4574-3-maciej.kwapulinski@linux.intel.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20210324183610.4574-1-maciej.kwapulinski@linux.intel.com> References: <20210324183610.4574-1-maciej.kwapulinski@linux.intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tomasz Jankowski Add definitions and utilities to interact with the hardware device. Signed-off-by: Tomasz Jankowski Tested-by: Savo Novakovic Co-developed-by: Jianxun Zhang Signed-off-by: Jianxun Zhang Co-developed-by: Maciej Kwapulinski Signed-off-by: Maciej Kwapulinski --- drivers/misc/intel/gna/Kbuild | 2 +- drivers/misc/intel/gna/gna_device.h | 4 + drivers/misc/intel/gna/gna_hw.c | 125 ++++++++++++++++++++++++++++ drivers/misc/intel/gna/gna_hw.h | 62 ++++++++++++++ 4 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 drivers/misc/intel/gna/gna_hw.c create mode 100644 drivers/misc/intel/gna/gna_hw.h diff --git a/drivers/misc/intel/gna/Kbuild b/drivers/misc/intel/gna/Kbuild index 5d3becc71683..0cf083bb211a 100644 --- a/drivers/misc/intel/gna/Kbuild +++ b/drivers/misc/intel/gna/Kbuild @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0-only -intel_gna-y := gna_device.o gna_driver.o +intel_gna-y := gna_device.o gna_driver.o gna_hw.o obj-$(CONFIG_INTEL_GNA) += intel_gna.o diff --git a/drivers/misc/intel/gna/gna_device.h b/drivers/misc/intel/gna/gna_device.h index d0b47f75f47f..39dc03d53feb 100644 --- a/drivers/misc/intel/gna/gna_device.h +++ b/drivers/misc/intel/gna/gna_device.h @@ -6,6 +6,8 @@ #include +#include "gna_hw.h" + struct gna_driver_private; struct pci_device_id; struct pci_dev; @@ -17,6 +19,8 @@ struct gna_drv_info { u32 num_page_entries; u32 max_layer_count; u64 max_hw_mem; + + struct gna_desc_info desc_info; }; struct gna_private { diff --git a/drivers/misc/intel/gna/gna_hw.c b/drivers/misc/intel/gna/gna_hw.c new file mode 100644 index 000000000000..7d2f4ef00136 --- /dev/null +++ b/drivers/misc/intel/gna/gna_hw.c @@ -0,0 +1,125 @@ +// SPDX-License-Identifier: GPL-2.0-only +// Copyright(c) 2017-2021 Intel Corporation + +#include + +#include + +#include "gna_device.h" +#include "gna_driver.h" +#include "gna_hw.h" + +int gna_parse_hw_status(struct gna_private *gna_priv, u32 hw_status) +{ + int status; + + if (hw_status & GNA_ERROR) { + dev_dbg(&gna_priv->pdev->dev, "GNA completed with errors: %#x\n", hw_status); + status = -EIO; + } else if (hw_status & GNA_STS_SCORE_COMPLETED) { + status = 0; + dev_dbg(&gna_priv->pdev->dev, "GNA completed successfully: %#x\n", hw_status); + } else { + dev_err(&gna_priv->pdev->dev, "GNA not completed, status: %#x\n", hw_status); + status = -ENODATA; + } + + return status; +} + +void gna_print_error_status(struct gna_private *gna_priv, u32 hw_status) +{ + if (hw_status & GNA_STS_PARAM_OOR) + dev_dbg(&gna_priv->pdev->dev, "GNA error: Param Out Range Error\n"); + + if (hw_status & GNA_STS_VA_OOR) + dev_dbg(&gna_priv->pdev->dev, "GNA error: VA Out of Range Error\n"); + + if (hw_status & GNA_STS_PCI_MMU_ERR) + dev_dbg(&gna_priv->pdev->dev, "GNA error: PCI MMU Error\n"); + + if (hw_status & GNA_STS_PCI_DMA_ERR) + dev_dbg(&gna_priv->pdev->dev, "GNA error: PCI MMU Error\n"); + + if (hw_status & GNA_STS_PCI_UNEXCOMPL_ERR) + dev_dbg(&gna_priv->pdev->dev, "GNA error: PCI Unexpected Completion Error\n"); + + if (hw_status & GNA_STS_SATURATE) + dev_dbg(&gna_priv->pdev->dev, "GNA error: Saturation Reached !\n"); +} + +bool gna_hw_perf_enabled(struct gna_private *gna_priv) +{ + void __iomem *addr = gna_priv->bar0_base; + u32 ctrl = gna_reg_read(addr, GNA_MMIO_CTRL); + + return FIELD_GET(GNA_CTRL_COMP_STATS_EN, ctrl) ? true : false; +} + +void gna_start_scoring(struct gna_private *gna_priv, void __iomem *addr, + struct gna_compute_cfg *compute_cfg) +{ + u32 ctrl = gna_reg_read(addr, GNA_MMIO_CTRL); + + ctrl |= GNA_CTRL_START_ACCEL | GNA_CTRL_COMP_INT_EN | GNA_CTRL_ERR_INT_EN; + + ctrl &= ~GNA_CTRL_COMP_STATS_EN; + ctrl |= FIELD_PREP(GNA_CTRL_COMP_STATS_EN, + compute_cfg->hw_perf_encoding & FIELD_MAX(GNA_CTRL_COMP_STATS_EN)); + + ctrl &= ~GNA_CTRL_ACTIVE_LIST_EN; + ctrl |= FIELD_PREP(GNA_CTRL_ACTIVE_LIST_EN, + compute_cfg->active_list_on & FIELD_MAX(GNA_CTRL_ACTIVE_LIST_EN)); + + ctrl &= ~GNA_CTRL_OP_MODE; + ctrl |= FIELD_PREP(GNA_CTRL_OP_MODE, + compute_cfg->gna_mode & FIELD_MAX(GNA_CTRL_OP_MODE)); + + gna_reg_write(addr, GNA_MMIO_CTRL, ctrl); + + dev_dbg(&gna_priv->pdev->dev, "scoring started...\n"); +} + +static void gna_clear_saturation(struct gna_private *gna_priv) +{ + void __iomem *addr = gna_priv->bar0_base; + u32 val; + + val = gna_reg_read(addr, GNA_MMIO_STS); + if (val & GNA_STS_SATURATE) { + dev_dbg(&gna_priv->pdev->dev, "saturation reached\n"); + dev_dbg(&gna_priv->pdev->dev, "status: %#x\n", val); + + val = val & GNA_STS_SATURATE; + gna_reg_write(addr, GNA_MMIO_STS, val); + } +} + +void gna_abort_hw(struct gna_private *gna_priv) +{ + void __iomem *addr = gna_priv->bar0_base; + u32 val; + int i; + + /* saturation bit in the GNA status register needs + * to be explicitly cleared. + */ + gna_clear_saturation(gna_priv); + + val = gna_reg_read(addr, GNA_MMIO_STS); + dev_dbg(&gna_priv->pdev->dev, "status before abort: %#x\n", val); + + val = gna_reg_read(addr, GNA_MMIO_CTRL); + val |= GNA_CTRL_ABORT_CLR_ACCEL; + gna_reg_write(addr, GNA_MMIO_CTRL, val); + + i = 100; + do { + val = gna_reg_read(addr, GNA_MMIO_STS); + if ((val & 0x1) == 0) + break; + } while (--i); + + if (i == 0) + dev_err(&gna_priv->pdev->dev, "abort did not complete\n"); +} diff --git a/drivers/misc/intel/gna/gna_hw.h b/drivers/misc/intel/gna/gna_hw.h new file mode 100644 index 000000000000..dd682f95094e --- /dev/null +++ b/drivers/misc/intel/gna/gna_hw.h @@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright(c) 2017-2021 Intel Corporation */ + +#ifndef __GNA_HW_H__ +#define __GNA_HW_H__ + +#include +#include +#include +#include + +/* GNA MMIO registers */ +#define GNA_MMIO_STS 0x80 +#define GNA_MMIO_CTRL 0x84 +#define GNA_MMIO_PTC 0x8C +#define GNA_MMIO_PSC 0x90 +#define GNA_MMIO_DESBASE 0xB0 +#define GNA_MMIO_IBUFFS 0xB4 + +#define GNA_PT_ENTRY_SIZE 4 +/* there are up to 1024 32-bit pointers in one page in Page Table (L1) */ +#define GNA_PT_LENGTH (PAGE_SIZE / GNA_PT_ENTRY_SIZE) + +#define GNA_PGDIRN_LEN 64 +#define GNA_PGDIR_ENTRIES 1024 /* 32-bit page addresses */ +#define GNA_PGDIR_INVALID 1 + +#define GNA_CTRL_START_ACCEL BIT(0) +#define GNA_CTRL_ACTIVE_LIST_EN BIT(1) +#define GNA_CTRL_ABORT_CLR_ACCEL BIT(2) +#define GNA_CTRL_OP_MODE GENMASK(6, 5) +#define GNA_CTRL_COMP_INT_EN BIT(8) +#define GNA_CTRL_ERR_INT_EN BIT(10) +#define GNA_CTRL_COMP_STATS_EN GENMASK(15, 12) + +struct gna_mmu_info { + u32 vamax_size; + u32 rsvd_size; + u32 pd_size; +}; + +struct gna_desc_info { + u32 rsvd_size; + u32 cfg_size; + u32 desc_size; + struct gna_mmu_info mmu_info; +}; + +struct gna_private; +struct gna_compute_cfg; + +void gna_abort_hw(struct gna_private *gna_priv); +bool gna_hw_perf_enabled(struct gna_private *gna_priv); +int gna_parse_hw_status(struct gna_private *gna_priv, u32 hw_status); +void gna_print_error_status(struct gna_private *gna_priv, u32 hw_status); +void gna_start_scoring(struct gna_private *gna_priv, void __iomem *addr, + struct gna_compute_cfg *compute_cfg); + +#define gna_reg_read(addr, offset) readl((addr) + (offset)) +#define gna_reg_write(addr, offset, value) writel((value), (addr) + (offset)) + +#endif // __GNA_HW_H__ -- 2.28.0