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 02DFCC433F5 for ; Thu, 7 Apr 2022 07:16:21 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 360D783DD1; Thu, 7 Apr 2022 09:14:38 +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=1649315678; bh=/bomS7Dp5wBuBTIuLMb+TZT3ZrVWxOWmM2M355U9nBg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=CzK/lI0bSi/75/f0BMthTWtTd2aBaa1n+BkHep/DsHPddSx9e9/S+k2r/9eyEgHfY N6wHRVRQ9TKzTgrl4hFq4bZpHhWkADbX/jYsg0/w7wKLNVthQlTikjCEUm22c+kryz v/rqVGRa36G2o0omzspv5Jshdp3W/4L8KOQAIUWxxIebmUcQ6qkCgZjVb2zcSFQLMY 0DNbtpE8G/0lKkdbq8oS/4aoF4KE6zArgILbxQ2i6BcLNq4mJCND4pCHLDgUvGIDvB M/NTmthPV1ANWVPflwzgwTL74FL9SX3RL6S7YADCs0J3KqeFbd43WrzWWuXo4qgcRb VXHNSnssHViEg== Received: by phobos.denx.de (Postfix, from userid 109) id A976B83DBF; Thu, 7 Apr 2022 09:13:38 +0200 (CEST) Received: from mout-u-107.mailbox.org (mout-u-107.mailbox.org [IPv6:2001:67c:2050:1::465:107]) (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 9A03883C11 for ; Thu, 7 Apr 2022 09:12:08 +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 (unknown [91.198.250.124]) (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-107.mailbox.org (Postfix) with ESMTPS id 4KYsyJ0H5Tz9sZs; Thu, 7 Apr 2022 09:12:08 +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 24/52] mips: octeon: Add cvmx-agl.c Date: Thu, 7 Apr 2022 09:11:26 +0200 Message-Id: <20220407071154.51997-25-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-agl.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-agl.c | 216 +++++++++++++++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100644 arch/mips/mach-octeon/cvmx-agl.c diff --git a/arch/mips/mach-octeon/cvmx-agl.c b/arch/mips/mach-octeon/cvmx-agl.c new file mode 100644 index 000000000000..9eea857e47c7 --- /dev/null +++ b/arch/mips/mach-octeon/cvmx-agl.c @@ -0,0 +1,216 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2018-2022 Marvell International Ltd. + * + * Functions for RGMII (MGMT) initialization, configuration, + * and monitoring. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +/* + * @param port to enable + * + * @return Zero on success, negative on failure + */ +int cvmx_agl_enable(int port) +{ + cvmx_agl_gmx_rxx_frm_ctl_t rxx_frm_ctl; + + rxx_frm_ctl.u64 = 0; + rxx_frm_ctl.s.pre_align = 1; + /* When set, disables the length check for non-min sized pkts with + * padding in the client data + */ + rxx_frm_ctl.s.pad_len = 1; + /* When set, disables the length check for VLAN pkts */ + rxx_frm_ctl.s.vlan_len = 1; + /* When set, PREAMBLE checking is less strict */ + rxx_frm_ctl.s.pre_free = 1; + /* Control Pause Frames can match station SMAC */ + rxx_frm_ctl.s.ctl_smac = 0; + /* Control Pause Frames can match globally assign Multicast address */ + rxx_frm_ctl.s.ctl_mcst = 1; + rxx_frm_ctl.s.ctl_bck = 1; /* Forward pause information to TX block */ + rxx_frm_ctl.s.ctl_drp = 1; /* Drop Control Pause Frames */ + rxx_frm_ctl.s.pre_strp = 1; /* Strip off the preamble */ + /* This port is configured to send PREAMBLE+SFD to begin every frame. + * GMX checks that the PREAMBLE is sent correctly + */ + rxx_frm_ctl.s.pre_chk = 1; + csr_wr(CVMX_AGL_GMX_RXX_FRM_CTL(port), rxx_frm_ctl.u64); + + return 0; +} + +cvmx_helper_link_info_t cvmx_agl_link_get(int port) +{ + cvmx_helper_link_info_t result; + int interface, port_index; + + /* Fake IPD port is used on some older models. */ + if (port < 0) + return __cvmx_helper_board_link_get(port); + + /* Simulator does not have PHY, use some defaults. */ + interface = cvmx_helper_get_interface_num(port); + port_index = cvmx_helper_get_interface_index_num(port); + if (cvmx_helper_get_port_force_link_up(interface, port_index)) { + result.u64 = 0; + result.s.full_duplex = 1; + result.s.link_up = 1; + result.s.speed = 1000; + return result; + } + + return __cvmx_helper_board_link_get(port); +} + +/* + * Set MII/RGMII link based on mode. + * + * @param port interface port to set the link. + * @param link_info Link status + * + * @return 0 on success and 1 on failure + */ +int cvmx_agl_link_set(int port, cvmx_helper_link_info_t link_info) +{ + cvmx_agl_gmx_prtx_cfg_t agl_gmx_prtx; + + /* Disable GMX before we make any changes. */ + agl_gmx_prtx.u64 = csr_rd(CVMX_AGL_GMX_PRTX_CFG(port)); + agl_gmx_prtx.s.en = 0; + agl_gmx_prtx.s.tx_en = 0; + agl_gmx_prtx.s.rx_en = 0; + csr_wr(CVMX_AGL_GMX_PRTX_CFG(port), agl_gmx_prtx.u64); + + if (OCTEON_IS_MODEL(OCTEON_CN6XXX) || OCTEON_IS_OCTEON3()) { + u64 one_second = 0x1000000; /* todo: this needs checking */ + + /* Wait for GMX to be idle */ + if (CVMX_WAIT_FOR_FIELD64(CVMX_AGL_GMX_PRTX_CFG(port), + cvmx_agl_gmx_prtx_cfg_t, rx_idle, ==, + 1, one_second) || + CVMX_WAIT_FOR_FIELD64(CVMX_AGL_GMX_PRTX_CFG(port), + cvmx_agl_gmx_prtx_cfg_t, tx_idle, ==, + 1, one_second)) { + debug("AGL%d: Timeout waiting for GMX to be idle\n", + port); + return -1; + } + } + + agl_gmx_prtx.u64 = csr_rd(CVMX_AGL_GMX_PRTX_CFG(port)); + + /* Set duplex mode */ + if (!link_info.s.link_up) + agl_gmx_prtx.s.duplex = 1; /* Force full duplex on down links */ + else + agl_gmx_prtx.s.duplex = link_info.s.full_duplex; + + switch (link_info.s.speed) { + case 10: + agl_gmx_prtx.s.speed = 0; + agl_gmx_prtx.s.slottime = 0; + if (OCTEON_IS_MODEL(OCTEON_CN6XXX) || OCTEON_IS_OCTEON3()) { + agl_gmx_prtx.s.speed_msb = 1; + agl_gmx_prtx.s.burst = 1; + } + break; + + case 100: + agl_gmx_prtx.s.speed = 0; + agl_gmx_prtx.s.slottime = 0; + if (OCTEON_IS_MODEL(OCTEON_CN6XXX) || OCTEON_IS_OCTEON3()) { + agl_gmx_prtx.s.speed_msb = 0; + agl_gmx_prtx.s.burst = 1; + } + break; + + case 1000: + /* 1000 MBits is only supported on 6XXX chips */ + if (OCTEON_IS_MODEL(OCTEON_CN6XXX) || OCTEON_IS_OCTEON3()) { + agl_gmx_prtx.s.speed_msb = 0; + agl_gmx_prtx.s.speed = 1; + agl_gmx_prtx.s.slottime = + 1; /* Only matters for half-duplex */ + agl_gmx_prtx.s.burst = agl_gmx_prtx.s.duplex; + } + break; + + /* No link */ + case 0: + default: + break; + } + + /* Write the new GMX setting with the port still disabled. */ + csr_wr(CVMX_AGL_GMX_PRTX_CFG(port), agl_gmx_prtx.u64); + + /* Read GMX CFG again to make sure the config is completed. */ + agl_gmx_prtx.u64 = csr_rd(CVMX_AGL_GMX_PRTX_CFG(port)); + + if (OCTEON_IS_MODEL(OCTEON_CN6XXX) || OCTEON_IS_OCTEON3()) { + cvmx_agl_gmx_txx_clk_t agl_clk; + cvmx_agl_prtx_ctl_t prt_ctl; + + prt_ctl.u64 = csr_rd(CVMX_AGL_PRTX_CTL(port)); + agl_clk.u64 = csr_rd(CVMX_AGL_GMX_TXX_CLK(port)); + /* MII (both speeds) and RGMII 1000 setting */ + agl_clk.s.clk_cnt = 1; + /* Check other speeds for RGMII mode */ + if (prt_ctl.s.mode == 0 || OCTEON_IS_OCTEON3()) { + if (link_info.s.speed == 10) + agl_clk.s.clk_cnt = 50; + else if (link_info.s.speed == 100) + agl_clk.s.clk_cnt = 5; + } + csr_wr(CVMX_AGL_GMX_TXX_CLK(port), agl_clk.u64); + } + + /* Enable transmit and receive ports */ + agl_gmx_prtx.s.tx_en = 1; + agl_gmx_prtx.s.rx_en = 1; + csr_wr(CVMX_AGL_GMX_PRTX_CFG(port), agl_gmx_prtx.u64); + + /* Enable the link. */ + agl_gmx_prtx.s.en = 1; + csr_wr(CVMX_AGL_GMX_PRTX_CFG(port), agl_gmx_prtx.u64); + + if (OCTEON_IS_OCTEON3()) { + union cvmx_agl_prtx_ctl agl_prtx_ctl; + /* Enable the interface, set clkrst */ + agl_prtx_ctl.u64 = csr_rd(CVMX_AGL_PRTX_CTL(port)); + agl_prtx_ctl.s.clkrst = 1; + csr_wr(CVMX_AGL_PRTX_CTL(port), agl_prtx_ctl.u64); + csr_rd(CVMX_AGL_PRTX_CTL(port)); + agl_prtx_ctl.s.enable = 1; + csr_wr(CVMX_AGL_PRTX_CTL(port), agl_prtx_ctl.u64); + /* Read the value back to force the previous write */ + csr_rd(CVMX_AGL_PRTX_CTL(port)); + } + + return 0; +} -- 2.35.1