Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1617587pxk; Fri, 2 Oct 2020 14:28:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfJEt92qY9BrYlreenXfpZBnAz8mjmHHCpW1VmciA+PpaNuAQ/fGYh5OpghGqCImURz7o6 X-Received: by 2002:a17:906:ce4b:: with SMTP id se11mr4068579ejb.386.1601674125002; Fri, 02 Oct 2020 14:28:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601674124; cv=none; d=google.com; s=arc-20160816; b=JPTCq10B2O3N0l075tEeQE1yrDBqQjYKJ2czskF5P/bRLUL5q7SYcDVkIaHhhptk6r +5ZPnvFOMem3//lkQMhV5Q5OkfutZD/mXj6Rf3NmCKBpgstudaBIlPz//mcPkd6xVD+3 r+y39uo1Cd8bzLvIHiBQtPEXzhHGOqeM+NO7fS+QKT0lBpxuK3ybRmyhr10tQQwh1hSa Fc+im0dCAAN+pNO8Ltt/2iHfpB+XclourZKrR4fupJ/dDo+h1fbeSREO3PeeUrCh0dTE rYjLW18N7hUa/3TaqKTREXmhnvsLNiENvH0wIp9BmzLiWw0wzhSHFoaPea9TGsZHtNad QeOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=bIg5vvYE5B6bZ2bVsaij6WdEml9a2ihWLSCsZGdkHO0=; b=pRxw3U4ueQuXKrcdgp5SoR5Gd2jn7YmT8dFDH0irdxWHaZ2ahqte4AJVvM8y64Or+D zmiZ2Ryi5SGwUOa/o4k3HunQLFJ05Zn8LcymSAEeL5r0l2WNIupEKpXCfvaCOEtWe+DR 8qWn7YYpTXGRXfGn9Z4f8ZZpZTMUBrUP0yf1ZvJmvGd4K/6sjk7sQkMGGJ43dGepeWL6 Xjqmd5+hhFTv/EuVUfDERSbFI2aLgIDUkrcqAczurPH7/5AuyqlMfUkf7qSp0w/EvTWM kXuWdEO65ynPgyyr0jIti3LZb3SL/JYGsxodxvMzyssiaaSmy4etueRmGQ2TFCFaG3FX mP+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@broadcom.com header.s=google header.b=BaeDTUPv; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qx20si1941146ejb.469.2020.10.02.14.28.22; Fri, 02 Oct 2020 14:28:44 -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; dkim=pass header.i=@broadcom.com header.s=google header.b=BaeDTUPv; 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=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=broadcom.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725830AbgJBVYp (ORCPT + 99 others); Fri, 2 Oct 2020 17:24:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725283AbgJBVYo (ORCPT ); Fri, 2 Oct 2020 17:24:44 -0400 Received: from mail-vs1-xe63.google.com (mail-vs1-xe63.google.com [IPv6:2607:f8b0:4864:20::e63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 85694C0613D0 for ; Fri, 2 Oct 2020 14:24:44 -0700 (PDT) Received: by mail-vs1-xe63.google.com with SMTP id a16so1267223vsp.12 for ; Fri, 02 Oct 2020 14:24:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bIg5vvYE5B6bZ2bVsaij6WdEml9a2ihWLSCsZGdkHO0=; b=BaeDTUPv5+cq0eW8EhHy4OP1S0ms0QcfSZRdbZZYVe+fRIy/NQKCC6Odsnynu9rshe D+vFR/OvXq4P+37Rt+9Im5Whh/g6eAt8ka8RZ66E1OtQEcRuJBWdqRMrm56xjSoVQClV pHvy9+V9rnvbiGDbfCfV/1FT60qStgr9KdSo8= 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=bIg5vvYE5B6bZ2bVsaij6WdEml9a2ihWLSCsZGdkHO0=; b=ScoH2uLz/NgP7fiZ+7fLpMpi6OKlyz1ppDaeGMIUBbxhcrASZ3HmIoSF1/1JSOMYy7 /5qowJfmz7YQwgI+baz7TA9LBD4P0yNglDW45e9Cbgqd10ARrKjoq0XqWn/rd9LunR/m NMp1jjRZGNWYEmzV91yWJ+/QQM86FpO8QzIhq0b+0EiZV0KgTWPZsHaZjHLf++h7nLn6 efXzTJ0LjNNIWHnqA+n1tJX+WM5kobLrc0tCPnYO6SuRjknZ8TzxIMhQFFID+/qB1O/a YlSQvgNPFNRvOPmRH6ebm+27VJCyYGQBa/XCGD9xIQy5v+l8ayZVntIQZIE1OIVRTndS LG7A== X-Gm-Message-State: AOAM532ZDR9/MeeguKHkwqLtieDlL4NaM+MoHUQzqJ3PvJmIxndHv8M7 Aeewpi8ddxKpBdOpa5j6X3tg8ySWxR7i7BnT8Mnc8hU00oGA X-Received: by 2002:a05:6102:10c2:: with SMTP id t2mr242993vsr.10.1601673883678; Fri, 02 Oct 2020 14:24:43 -0700 (PDT) Received: from lbrmn-lnxub113.broadcom.net ([192.19.228.250]) by smtp-relay.gmail.com with ESMTPS id x2sm327292vsn.4.2020.10.02.14.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Oct 2020 14:24:43 -0700 (PDT) X-Relaying-Domain: broadcom.com From: Scott Branden To: Arnd Bergmann , Greg Kroah-Hartman , Scott Branden , Desmond Yan Cc: Kees Cook , linux-kernel@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, Olof Johansson Subject: [PATCH v6 08/14] misc: bcm-vk: add get_card_info, peerlog_info, and proc_mon_info Date: Fri, 2 Oct 2020 14:23:21 -0700 Message-Id: <20201002212327.18393-9-scott.branden@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201002212327.18393-1-scott.branden@broadcom.com> References: <20201002212327.18393-1-scott.branden@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add support to get card_info (details about card), peerlog_info (to get details of peerlog on card), and proc_mon_info (process monitoring on card). This info is used for collection of logs via direct read of BAR space and by sysfs access (in a follow on commit). Co-developed-by: Desmond Yan Signed-off-by: Desmond Yan Signed-off-by: Scott Branden --- drivers/misc/bcm-vk/bcm_vk.h | 58 +++++++++++++++++++++ drivers/misc/bcm-vk/bcm_vk_dev.c | 87 ++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) diff --git a/drivers/misc/bcm-vk/bcm_vk.h b/drivers/misc/bcm-vk/bcm_vk.h index 726aab71bb6b..452333a32604 100644 --- a/drivers/misc/bcm-vk/bcm_vk.h +++ b/drivers/misc/bcm-vk/bcm_vk.h @@ -205,6 +205,21 @@ enum pci_barno { #define BCM_VK_NUM_TTY 2 +/* VK device max power state, supports 3, full, reduced and low */ +#define MAX_OPP 3 +#define MAX_CARD_INFO_TAG_SIZE 64 + +struct bcm_vk_card_info { + u32 version; + char os_tag[MAX_CARD_INFO_TAG_SIZE]; + char cmpt_tag[MAX_CARD_INFO_TAG_SIZE]; + u32 cpu_freq_mhz; + u32 cpu_scale[MAX_OPP]; + u32 ddr_freq_mhz; + u32 ddr_size_MB; + u32 video_core_freq_mhz; +}; + /* DAUTH related info */ struct bcm_vk_dauth_key { char store[VK_BAR1_DAUTH_STORE_SIZE]; @@ -215,10 +230,47 @@ struct bcm_vk_dauth_info { struct bcm_vk_dauth_key keys[VK_BAR1_DAUTH_MAX]; }; +/* + * Control structure of logging messages from the card. This + * buffer is for logmsg that comes from vk + */ +struct bcm_vk_peer_log { + u32 rd_idx; + u32 wr_idx; + u32 buf_size; + u32 mask; + char data[0]; +}; + +/* max size per line of peer log */ +#define BCM_VK_PEER_LOG_LINE_MAX 256 + +/* + * single entry for processing type + utilization + */ +#define BCM_VK_PROC_TYPE_TAG_LEN 8 +struct bcm_vk_proc_mon_entry_t { + char tag[BCM_VK_PROC_TYPE_TAG_LEN]; + u32 used; + u32 max; /**< max capacity */ +}; + +/** + * Structure for run time utilization + */ +#define BCM_VK_PROC_MON_MAX 8 /* max entries supported */ +struct bcm_vk_proc_mon_info { + u32 num; /**< no of entries */ + u32 entry_size; /**< per entry size */ + struct bcm_vk_proc_mon_entry_t entries[BCM_VK_PROC_MON_MAX]; +}; + struct bcm_vk { struct pci_dev *pdev; void __iomem *bar[MAX_BAR]; + struct bcm_vk_card_info card_info; + struct bcm_vk_proc_mon_info proc_mon_info; struct bcm_vk_dauth_info dauth_info; /* mutex to protect the ioctls */ @@ -240,6 +292,12 @@ struct bcm_vk { dma_addr_t tdma_addr; /* test dma segment bus addr */ struct notifier_block panic_nb; + + /* offset of the peer log control in BAR2 */ + u32 peerlog_off; + struct bcm_vk_peer_log peerlog_info; /* record of peer log info */ + /* offset of processing monitoring info in BAR2 */ + u32 proc_mon_off; }; /* wq offload work items bits definitions */ diff --git a/drivers/misc/bcm-vk/bcm_vk_dev.c b/drivers/misc/bcm-vk/bcm_vk_dev.c index c48e2329e547..6d476f1ac3c4 100644 --- a/drivers/misc/bcm-vk/bcm_vk_dev.c +++ b/drivers/misc/bcm-vk/bcm_vk_dev.c @@ -172,6 +172,86 @@ static inline int bcm_vk_wait(struct bcm_vk *vk, enum pci_barno bar, return 0; } +static void bcm_vk_get_card_info(struct bcm_vk *vk) +{ + struct device *dev = &vk->pdev->dev; + u32 offset; + int i; + u8 *dst; + struct bcm_vk_card_info *info = &vk->card_info; + + /* first read the offset from spare register */ + offset = vkread32(vk, BAR_0, BAR_CARD_STATIC_INFO); + offset &= (pci_resource_len(vk->pdev, BAR_2 * 2) - 1); + + /* based on the offset, read info to internal card info structure */ + dst = (u8 *)info; + for (i = 0; i < sizeof(*info); i++) + *dst++ = vkread8(vk, BAR_2, offset++); + +#define CARD_INFO_LOG_FMT "version : %x\n" \ + "os_tag : %s\n" \ + "cmpt_tag : %s\n" \ + "cpu_freq : %d MHz\n" \ + "cpu_scale : %d full, %d lowest\n" \ + "ddr_freq : %d MHz\n" \ + "ddr_size : %d MB\n" \ + "video_freq: %d MHz\n" + dev_dbg(dev, CARD_INFO_LOG_FMT, info->version, info->os_tag, + info->cmpt_tag, info->cpu_freq_mhz, info->cpu_scale[0], + info->cpu_scale[MAX_OPP - 1], info->ddr_freq_mhz, + info->ddr_size_MB, info->video_core_freq_mhz); + + /* + * get the peer log pointer, only need the offset, and get record + * of the log buffer information which would be used for checking + * before dump, in case the BAR2 memory has been corrupted. + */ + vk->peerlog_off = offset; + memcpy_fromio(&vk->peerlog_info, vk->bar[BAR_2] + vk->peerlog_off, + sizeof(vk->peerlog_info)); + dev_dbg(dev, "Peer log: Size 0x%x(0x%x), [Rd Wr] = [%d %d]\n", + vk->peerlog_info.buf_size, + vk->peerlog_info.mask, + vk->peerlog_info.rd_idx, + vk->peerlog_info.wr_idx); +} + +static void bcm_vk_get_proc_mon_info(struct bcm_vk *vk) +{ + struct device *dev = &vk->pdev->dev; + struct bcm_vk_proc_mon_info *mon = &vk->proc_mon_info; + u32 num, entry_size, offset, buf_size; + u8 *dst; + + /* calculate offset which is based on peerlog offset */ + buf_size = vkread32(vk, BAR_2, + vk->peerlog_off + + offsetof(struct bcm_vk_peer_log, buf_size)); + offset = vk->peerlog_off + sizeof(struct bcm_vk_peer_log) + + buf_size; + + /* first read the num and entry size */ + num = vkread32(vk, BAR_2, offset); + entry_size = vkread32(vk, BAR_2, offset + sizeof(num)); + + /* check for max allowed */ + if (num > BCM_VK_PROC_MON_MAX) { + dev_err(dev, "Processing monitoring entry %d exceeds max %d\n", + num, BCM_VK_PROC_MON_MAX); + return; + } + mon->num = num; + mon->entry_size = entry_size; + + vk->proc_mon_off = offset; + + /* read it once that will capture those static info */ + dst = (u8 *)&mon->entries[0]; + offset += sizeof(num) + sizeof(entry_size); + memcpy_fromio(dst, vk->bar[BAR_2] + offset, num * entry_size); +} + static int bcm_vk_sync_card_info(struct bcm_vk *vk) { u32 rdy_marker = vkread32(vk, BAR_1, VK_BAR1_MSGQ_DEF_RDY); @@ -193,6 +273,13 @@ static int bcm_vk_sync_card_info(struct bcm_vk *vk) vkwrite32(vk, nr_scratch_pages * PAGE_SIZE, BAR_1, VK_BAR1_SCRATCH_SZ_ADDR); } + + /* get static card info, only need to read once */ + bcm_vk_get_card_info(vk); + + /* get the proc mon info once */ + bcm_vk_get_proc_mon_info(vk); + return 0; } -- 2.17.1