From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4D421C4332F for ; Thu, 7 Apr 2022 07:14:55 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F333083DBD; Thu, 7 Apr 2022 09:13:52 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1649315633; bh=Hwa0tp4tzAIYLGRt44x74J2DNPT+xVa8X4crIS/frKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=DeCPaSjWmSkxrtv0dIEmZawxAwPgFXBQBP4WWevOL1ImzAZsx7ta47k7+SkANvEAs YYZVVZDG0pMz/fLVwQ94xtiH2kTo7VEmm6aY3a2cU6c4Cpib8ja1mVsTdufcSWGKxf s8yEKdJ5ntpREu7PLcTmDOQkTbwLHd/b+GI/JcE48rxCQG/hFOLxfmJcPWKjoj+hKv 8Kd6GPja07Zu39sPBVL+rcE/uecWgcc1flgrgKZ4yMhnKmtWxfRQYjXRJ4CAx5D5Vt poY+3Qpih/fGTn9AGNKq/prWU4iNC/q9ffXvVoW1g0Dt4FZl2eKn9XXJGRf3NElzWS 3DfRgwAd7FxQQ== Received: by phobos.denx.de (Postfix, from userid 109) id C1F4783B2D; Thu, 7 Apr 2022 09:13:18 +0200 (CEST) Received: from mout-u-204.mailbox.org (mout-u-204.mailbox.org [IPv6:2001:67c:2050:1::465:204]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 49ABB83C06 for ; Thu, 7 Apr 2022 09:12:06 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=sr@denx.de Received: from smtp2.mailbox.org (smtp2.mailbox.org [IPv6:2001:67c:2050:105:465:1:2:0]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-u-204.mailbox.org (Postfix) with ESMTPS id 4KYsyG02W9z9sZk; Thu, 7 Apr 2022 09:12:06 +0200 (CEST) From: Stefan Roese To: u-boot@lists.denx.de Cc: daniel.schwierzeck@gmail.com, awilliams@marvell.com, cchavva@marvell.com Subject: [PATCH v2 18/52] mips: octeon: Add cvmx-helper-pko.c Date: Thu, 7 Apr 2022 09:11:20 +0200 Message-Id: <20220407071154.51997-19-sr@denx.de> In-Reply-To: <20220407071154.51997-1-sr@denx.de> References: <20220407071154.51997-1-sr@denx.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean From: Aaron Williams Import cvmx-helper-pko.c from 2013 U-Boot. It will be used by the later added drivers to support networking on the MIPS Octeon II / III platforms. Signed-off-by: Aaron Williams Signed-off-by: Stefan Roese --- arch/mips/mach-octeon/cvmx-helper-pko.c | 203 ++++++++++++++++++++++++ 1 file changed, 203 insertions(+) create mode 100644 arch/mips/mach-octeon/cvmx-helper-pko.c diff --git a/arch/mips/mach-octeon/cvmx-helper-pko.c b/arch/mips/mach-octeon/cvmx-helper-pko.c new file mode 100644 index 000000000000..b9ac22cf0081 --- /dev/null +++ b/arch/mips/mach-octeon/cvmx-helper-pko.c @@ -0,0 +1,203 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2018-2022 Marvell International Ltd. + * + * Helper Functions for the PKO + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include + +static s64 pko_fpa_config_pool = -1; +static u64 pko_fpa_config_size = 1024; + +/** + * cvmx_override_pko_queue_priority(int pko_port, u64 + * priorities[16]) is a function pointer. It is meant to allow + * customization of the PKO queue priorities based on the port + * number. Users should set this pointer to a function before + * calling any cvmx-helper operations. + */ +void (*cvmx_override_pko_queue_priority)(int ipd_port, + uint8_t *priorities) = NULL; + +int64_t cvmx_fpa_get_pko_pool(void) +{ + return pko_fpa_config_pool; +} + +/** + * Gets the buffer size of pko pool + */ +u64 cvmx_fpa_get_pko_pool_block_size(void) +{ + return pko_fpa_config_size; +} + +/** + * Initialize PKO command queue buffer pool + */ +static int cvmx_helper_pko_pool_init(void) +{ + u8 pool; + unsigned int buf_count; + unsigned int pkt_buf_count; + int rc; + + /* Reserve pool */ + pool = cvmx_fpa_get_pko_pool(); + + /* Avoid redundant pool creation */ + if (cvmx_fpa_get_block_size(pool) > 0) { +#ifdef DEBUG + debug("WARNING: %s: pool %d already initialized\n", __func__, + pool); +#endif + /* It is up to the app to have sufficient buffer count */ + return pool; + } + + /* Calculate buffer count: one per queue + 3-word-cmds * max_pkts */ + pkt_buf_count = cvmx_fpa_get_packet_pool_buffer_count(); + buf_count = CVMX_PKO_MAX_OUTPUT_QUEUES + (pkt_buf_count * 3) / 8; + + /* Allocate pools for pko command queues */ + rc = __cvmx_helper_initialize_fpa_pool(pool, + cvmx_fpa_get_pko_pool_block_size(), + buf_count, "PKO Cmd-bufs"); + + if (rc < 0) + debug("%s: ERROR: in PKO buffer pool\n", __func__); + + pool = rc; + return pool; +} + +/** + * Initialize the PKO + * + */ +int cvmx_helper_pko_init(void) +{ + int rc; + + rc = cvmx_helper_pko_pool_init(); + if (rc < 0) + return rc; + + __cvmx_helper_init_port_config_data(0); + + cvmx_pko_hw_init(cvmx_fpa_get_pko_pool(), + cvmx_fpa_get_pko_pool_block_size()); + return 0; +} + +/** + * @INTERNAL + * Setup the PKO for the ports on an interface. The number of + * queues per port and the priority of each PKO output queue + * is set here. PKO must be disabled when this function is called. + * + * @param interface to setup PKO for + * + * @return Zero on success, negative on failure + * + * @note This is for PKO1/PKO2, and is not used for PKO3. + */ +int __cvmx_helper_interface_setup_pko(int interface) +{ + /* + * Each packet output queue has an associated priority. The + * higher the priority, the more often it can send a packet. A + * priority of 8 means it can send in all 8 rounds of + * contention. We're going to make each queue one less than + * the last. The vector of priorities has been extended to + * support CN5xxx CPUs, where up to 16 queues can be + * associated to a port. To keep backward compatibility we + * don't change the initial 8 priorities and replicate them in + * the second half. With per-core PKO queues (PKO lockless + * operation) all queues have the same priority. + */ + /* uint8_t priorities[16] = {8,7,6,5,4,3,2,1,8,7,6,5,4,3,2,1}; */ + u8 priorities[16] = { [0 ... 15] = 8 }; + + /* + * Setup the IPD/PIP and PKO for the ports discovered + * above. Here packet classification, tagging and output + * priorities are set. + */ + int num_ports = cvmx_helper_ports_on_interface(interface); + + while (num_ports--) { + int ipd_port; + + if (!cvmx_helper_is_port_valid(interface, num_ports)) + continue; + + ipd_port = cvmx_helper_get_ipd_port(interface, num_ports); + /* + * Give the user a chance to override the per queue + * priorities. + */ + if (cvmx_override_pko_queue_priority) + cvmx_override_pko_queue_priority(ipd_port, priorities); + + cvmx_pko_config_port(ipd_port, + cvmx_pko_get_base_queue(ipd_port), + cvmx_pko_get_num_queues(ipd_port), + priorities); + ipd_port++; + } + return 0; + /* NOTE: + * Now this function is called for all chips including 68xx, + * but on the 68xx it does not enable multiple pko_iports per + * eport, while before it was doing 3 pko_iport per eport + * buf the reason for that is not clear. + */ +} -- 2.35.1