From patchwork Tue Aug 6 13:25:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13754860 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D9D61D1F4E; Tue, 6 Aug 2024 13:28:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722950911; cv=none; b=mXDJMTORwOAwiK/jSfdD7jvLDxye5kHlt0kPZ7pIVhZ2tIiSAwi/6EiT+ynQWen8b+M1ggjGp2sUARg17TGuTsj8CwGIBthhpJwcmG8yj//VvvMupNASDzog4mDyC0iSpnlgnWG/92/eFFc27Lqh74iAVUtinqzA9sDHre4Z0eI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722950911; c=relaxed/simple; bh=MNnLV25K6YhULXYYlXhNI0BKUG+LUYqABdwm34GgDDM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eEAe1iSHf+kprRrgQWp8Qs45jT8e0VGE7DdXE9pT8p/KDdw4tX1AXVbVyKlmvW+Vjt7993l+ku3dpCDLprpEyR6wTYE1GmplFc/cDVkno4zj1YrELQgFCCI7L6jGHGtfc69bQX41AHPErcdQwf/KATtVLP/+AHcShVGVHAcQwcI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WlQcBWCV; arc=none smtp.client-ip=209.85.208.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WlQcBWCV" Received: by mail-ed1-f43.google.com with SMTP id 4fb4d7f45d1cf-5a1c496335aso312501a12.1; Tue, 06 Aug 2024 06:28:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722950908; x=1723555708; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=t11NvRdsE6tRyZHoH+rh9Stx+kDJmXVz4PuKIrvrxow=; b=WlQcBWCVLG5gb+cTZ4+XDR00I9JrxHrTpIPL1Xs3CPrDreFcvziEBBnKGnyJ8RFqay KICOGOvuPVnRYfu1asUOG4Tk0y3Ks+IwlUH8OpbPLy1HKP49b48MnA6B/vc948MqXLBo WSQZ2iRfGQPC8RGJDcwcQQei2BHj2US379PpRu97f7ILdeT7PZPWwGvk7uw9ORUrb6ux nPdLFxPO6Px3+HOMfmjY1pW/ROhK4P63YrQYiPv1klcfdb9EvkbQzPttI0UgEoc2SZce xS3w0sqbIkCkbgnKdRUqz0RrHCrpz30Ee08jg94VQyyMBNy4+e+NhNQL49zEhilVWA2G nvFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722950908; x=1723555708; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=t11NvRdsE6tRyZHoH+rh9Stx+kDJmXVz4PuKIrvrxow=; b=Ndd25x2ktqdw16ZSapjh+949yuTLY9QfgRtz9nkg0AZuk3PamQ6OxQEBr/4FpVCrCK N9Jpi8N375esF8+292Qn6GwqTjmTDk9l1Y2Wyvce2imv7dLaw/jK4REHyCrvG8GQWjNt jj1jmDPYzro9o7HUuoMIxsJUDnDZJovE0TegzJ4faYmli0XGW9+0qv2/VIlSvkGHvh18 5Aci+sH0O7Uh0Qb7hncb5YDB3O8qIqtmS8vX49WyazMic+Zbaoya/mjbDUJdxqFglquu LHRsrInTZj125PrIjAxiH2olbmhHttCSlc0Hb2CuleA8Hmi97txR1CqXsaskgGn3UgXZ fepw== X-Forwarded-Encrypted: i=1; AJvYcCU6oSaB3MU4NhWABKj/Kx0QgrswtqXQlOm/wjz4sCEa9Aer5XWHTxaqHzNQFYvp0qHqcrZomlAgtUdu@vger.kernel.org, AJvYcCUQXcPwnmmxL+S0+YL6QnRMQi1N7/FmM2mbACe6VlWSL+m7uybZ+5Ww4yavkLIK8rwFVunKb51m/XZlh5qF@vger.kernel.org, AJvYcCVhyCAedyXIhdD/gKx5dQfY2eDW/GYW542zExejAYqFufFzv/VrcU5wR5iHviReOVgocPvkwvWP@vger.kernel.org X-Gm-Message-State: AOJu0YxUAB2taL8BpP7KgySvwhAJSbgKnp5tjdliULNQgMnqAkYcBW7U oIfIivdYkxDuhIrRwg61aboc9avHYR2k3gU1GQ5aerXeBBsD5oKe X-Google-Smtp-Source: AGHT+IFoADXb3aIb0ygPnlnU2NZzG/iHbz8BzpZLTJYMTElblwboYJGK63zl4KoMM/0u6YlD487YkQ== X-Received: by 2002:aa7:cc81:0:b0:5a7:464a:abf with SMTP id 4fb4d7f45d1cf-5b7f521e6a4mr13748702a12.24.1722950908185; Tue, 06 Aug 2024 06:28:28 -0700 (PDT) Received: from lapsy144.cern.ch ([2001:1458:204:1::102:a6a]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5b83a153f77sm5910172a12.53.2024.08.06.06.28.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 06:28:27 -0700 (PDT) From: vtpieter@gmail.com To: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Florian Fainelli , Vladimir Oltean , David S Miller , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Marek Vasut Cc: Woojung Huh , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Pieter Van Trappen , Oleksij Rempel Subject: [PATCH net-next v3 1/5] dt-bindings: net: dsa: microchip: add microchip,pme-active-high flag Date: Tue, 6 Aug 2024 15:25:53 +0200 Message-ID: <20240806132606.1438953-2-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240806132606.1438953-1-vtpieter@gmail.com> References: <20240806132606.1438953-1-vtpieter@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Pieter Van Trappen Add microchip,pme-active-high property to set the PME (Power Management Event) pin polarity for Wake on Lan interrupts. Note that the polarity is active-low by default. Signed-off-by: Pieter Van Trappen Reviewed-by: Rob Herring (Arm) Reviewed-by: Oleksij Rempel --- Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml b/Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml index 52acc15ebcbf..c589ebc2c7be 100644 --- a/Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml +++ b/Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml @@ -51,6 +51,11 @@ properties: Set if the output SYNCLKO clock should be disabled. Do not mix with microchip,synclko-125. + microchip,pme-active-high: + $ref: /schemas/types.yaml#/definitions/flag + description: + Indicates if the PME pin polarity is active-high. + microchip,io-drive-strength-microamp: description: IO Pad Drive Strength From patchwork Tue Aug 6 13:25:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13754861 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 72C8F1D1F4E; Tue, 6 Aug 2024 13:28:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722950918; cv=none; b=lYcV7ZJbB7Cg0BngKUId8+Zy4S461yUzysIplIaSM/9VGhNUCN33oogozzMSTDnQmzSEG+ECSmqSE46+WMUBKV8ooDqYk28LwoRl0GFyxgP+BQGyAvhS7X9MwbwbswHxufy2KGw8ho6T+86DvKEqAWdVDnmMwPO0SXAfWXpi5f8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722950918; c=relaxed/simple; bh=Frwqk6NSEs7lG01B9dEfQKQl8UB9zNOVLB5mcyrHtOY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UnRYpMNw5vBYKjJ2Yg7HQl25moK29y8DfvW+FketP9dAmYVpD2oTlN9iY+Lsc7vYrfLF4aMp90dJxyI0V2ZPmGDORT1S6aF6U2YORPwqTIwRa4w6/WCBqe0RmzS5WwpHdLA2uzaaz1n/nVhg2BjD0UhWdwTGORq9y4E/mkBvK+4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=VPW5H1Xe; arc=none smtp.client-ip=209.85.208.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VPW5H1Xe" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5b8c2a6135dso992878a12.1; Tue, 06 Aug 2024 06:28:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722950915; x=1723555715; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=J8UI01DTINAyVuDQJb9qJI6xEuB4xVDUsc3vnutKq5Q=; b=VPW5H1XeVP8TUJwyT4gHCPfo7VSW65+egiMg+WaUZoS0ZV4JJ9KcPR9oMh7kxTD8A2 QR4JdZN25kHzcYJdIM5gt4eVyTJixfTE37rQADn4WPWp1AbrGL8ymKy1jWn5zt8E+Mlh ZzvK3zcoBz9uVgP9Ro+U/0ACDokG/GOV1zJ+bigCoQLrq9ngmbzLg96PKHbozaxDlh0U pQtfyBpT/F+zE0LHIbYa8FyC/yRC88ZJPDVVIyYq7YcG2O0splgfKoeVgI6bXdDNkcVS unjiK/kiopOZxu1x+3XavUrDtCwyZi849I5CccRRm9X7qQ0X9vcgT4TTMQVulsDMu6/F hNmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722950915; x=1723555715; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=J8UI01DTINAyVuDQJb9qJI6xEuB4xVDUsc3vnutKq5Q=; b=gs4dECIMlT6kJhprE8TDg2K/YXoJK1ehelb8IM6010tjrJaxjFy7tn+qdx71nvNDAC Lab4QohcvlDarSyu5r/YBDi2NpbtvQ7w1LkA0si9BVRGEBLD/mJMaD3+nDwT1rOGv/Ew HhADS0Ks4qzrkRvArwJlPrN9uoJmJVncf5mV2xlVuiMGQ1Gd5hus6s+VI/YLMsPT8Uxd Kvy12xfegT8Y+KoZYU8fwDhVeSb9putMwIGtOZNG+JMkMaHLsgEkL5xW44SR/WQJ2TIp r7Cg6fk5YFuY4sZCpzhDe9bsJ+skcFShvK3q1ypvUFbt8gywILKW/x+gGlR7TEZGotC/ UdcA== X-Forwarded-Encrypted: i=1; AJvYcCWl5LKGWcN7Xrlt/0LIVGDFlfrpFSVbpgLjfmhAFobgJpoZk8jh20A1YyXwgre04XEhIh4wS0vGOO5DGAsgh0gu2AT52aByNYv5Vej6bi90pupF+5Jf2KfVoQQaYg3YAKgHG2L55eFrlEnso29+D4PUem5egJuJSoUHH8CqKOEf4w== X-Gm-Message-State: AOJu0Ywio+99LqfFLw4mXWZcRQFvEQXuJY2FDQkk0vENN7wL7pd6KsG4 axIgdC69ek52Xbuegr3BrZu37Cicyb2LTj6FEGclsx7ir4Q3xslx X-Google-Smtp-Source: AGHT+IEyKsQYGznSxl3WVlLekkpnyIGIspd/ssaUyT4P+DgA/rfVAkCqtUk4UZ7r1HfaYMJITkE9WA== X-Received: by 2002:a05:6402:18c:b0:5af:c82a:7f6d with SMTP id 4fb4d7f45d1cf-5b7f3faf475mr9975005a12.20.1722950914292; Tue, 06 Aug 2024 06:28:34 -0700 (PDT) Received: from lapsy144.cern.ch ([2001:1458:204:1::102:a6a]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5b83a153f77sm5910172a12.53.2024.08.06.06.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 06:28:33 -0700 (PDT) From: vtpieter@gmail.com To: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Florian Fainelli , Vladimir Oltean , David S Miller , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Marek Vasut Cc: Woojung Huh , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Pieter Van Trappen Subject: [PATCH net-next v3 2/5] net: dsa: microchip: move KSZ9477 WoL functions to ksz_common Date: Tue, 6 Aug 2024 15:25:54 +0200 Message-ID: <20240806132606.1438953-3-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240806132606.1438953-1-vtpieter@gmail.com> References: <20240806132606.1438953-1-vtpieter@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Pieter Van Trappen Move KSZ9477 WoL functions to ksz_common, in preparation for adding KSZ87xx family support. Signed-off-by: Pieter Van Trappen Acked-by: Arun Ramadoss --- drivers/net/dsa/microchip/ksz9477.c | 181 ------------------------ drivers/net/dsa/microchip/ksz9477.h | 5 - drivers/net/dsa/microchip/ksz9477_reg.h | 12 -- drivers/net/dsa/microchip/ksz_common.c | 181 ++++++++++++++++++++++++ drivers/net/dsa/microchip/ksz_common.h | 19 +++ 5 files changed, 200 insertions(+), 198 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 425e20daf1e9..071d953a17e9 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -56,187 +56,6 @@ int ksz9477_change_mtu(struct ksz_device *dev, int port, int mtu) REG_SW_MTU_MASK, frame_size); } -/** - * ksz9477_handle_wake_reason - Handle wake reason on a specified port. - * @dev: The device structure. - * @port: The port number. - * - * This function reads the PME (Power Management Event) status register of a - * specified port to determine the wake reason. If there is no wake event, it - * returns early. Otherwise, it logs the wake reason which could be due to a - * "Magic Packet", "Link Up", or "Energy Detect" event. The PME status register - * is then cleared to acknowledge the handling of the wake event. - * - * Return: 0 on success, or an error code on failure. - */ -static int ksz9477_handle_wake_reason(struct ksz_device *dev, int port) -{ - u8 pme_status; - int ret; - - ret = ksz_pread8(dev, port, REG_PORT_PME_STATUS, &pme_status); - if (ret) - return ret; - - if (!pme_status) - return 0; - - dev_dbg(dev->dev, "Wake event on port %d due to:%s%s%s\n", port, - pme_status & PME_WOL_MAGICPKT ? " \"Magic Packet\"" : "", - pme_status & PME_WOL_LINKUP ? " \"Link Up\"" : "", - pme_status & PME_WOL_ENERGY ? " \"Energy detect\"" : ""); - - return ksz_pwrite8(dev, port, REG_PORT_PME_STATUS, pme_status); -} - -/** - * ksz9477_get_wol - Get Wake-on-LAN settings for a specified port. - * @dev: The device structure. - * @port: The port number. - * @wol: Pointer to ethtool Wake-on-LAN settings structure. - * - * This function checks the PME Pin Control Register to see if PME Pin Output - * Enable is set, indicating PME is enabled. If enabled, it sets the supported - * and active WoL flags. - */ -void ksz9477_get_wol(struct ksz_device *dev, int port, - struct ethtool_wolinfo *wol) -{ - u8 pme_ctrl; - int ret; - - if (!dev->wakeup_source) - return; - - wol->supported = WAKE_PHY; - - /* Check if the current MAC address on this port can be set - * as global for WAKE_MAGIC support. The result may vary - * dynamically based on other ports configurations. - */ - if (ksz_is_port_mac_global_usable(dev->ds, port)) - wol->supported |= WAKE_MAGIC; - - ret = ksz_pread8(dev, port, REG_PORT_PME_CTRL, &pme_ctrl); - if (ret) - return; - - if (pme_ctrl & PME_WOL_MAGICPKT) - wol->wolopts |= WAKE_MAGIC; - if (pme_ctrl & (PME_WOL_LINKUP | PME_WOL_ENERGY)) - wol->wolopts |= WAKE_PHY; -} - -/** - * ksz9477_set_wol - Set Wake-on-LAN settings for a specified port. - * @dev: The device structure. - * @port: The port number. - * @wol: Pointer to ethtool Wake-on-LAN settings structure. - * - * This function configures Wake-on-LAN (WoL) settings for a specified port. - * It validates the provided WoL options, checks if PME is enabled via the - * switch's PME Pin Control Register, clears any previous wake reasons, - * and sets the Magic Packet flag in the port's PME control register if - * specified. - * - * Return: 0 on success, or other error codes on failure. - */ -int ksz9477_set_wol(struct ksz_device *dev, int port, - struct ethtool_wolinfo *wol) -{ - u8 pme_ctrl = 0, pme_ctrl_old = 0; - bool magic_switched_off; - bool magic_switched_on; - int ret; - - if (wol->wolopts & ~(WAKE_PHY | WAKE_MAGIC)) - return -EINVAL; - - if (!dev->wakeup_source) - return -EOPNOTSUPP; - - ret = ksz9477_handle_wake_reason(dev, port); - if (ret) - return ret; - - if (wol->wolopts & WAKE_MAGIC) - pme_ctrl |= PME_WOL_MAGICPKT; - if (wol->wolopts & WAKE_PHY) - pme_ctrl |= PME_WOL_LINKUP | PME_WOL_ENERGY; - - ret = ksz_pread8(dev, port, REG_PORT_PME_CTRL, &pme_ctrl_old); - if (ret) - return ret; - - if (pme_ctrl_old == pme_ctrl) - return 0; - - magic_switched_off = (pme_ctrl_old & PME_WOL_MAGICPKT) && - !(pme_ctrl & PME_WOL_MAGICPKT); - magic_switched_on = !(pme_ctrl_old & PME_WOL_MAGICPKT) && - (pme_ctrl & PME_WOL_MAGICPKT); - - /* To keep reference count of MAC address, we should do this - * operation only on change of WOL settings. - */ - if (magic_switched_on) { - ret = ksz_switch_macaddr_get(dev->ds, port, NULL); - if (ret) - return ret; - } else if (magic_switched_off) { - ksz_switch_macaddr_put(dev->ds); - } - - ret = ksz_pwrite8(dev, port, REG_PORT_PME_CTRL, pme_ctrl); - if (ret) { - if (magic_switched_on) - ksz_switch_macaddr_put(dev->ds); - return ret; - } - - return 0; -} - -/** - * ksz9477_wol_pre_shutdown - Prepares the switch device for shutdown while - * considering Wake-on-LAN (WoL) settings. - * @dev: The switch device structure. - * @wol_enabled: Pointer to a boolean which will be set to true if WoL is - * enabled on any port. - * - * This function prepares the switch device for a safe shutdown while taking - * into account the Wake-on-LAN (WoL) settings on the user ports. It updates - * the wol_enabled flag accordingly to reflect whether WoL is active on any - * port. - */ -void ksz9477_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled) -{ - struct dsa_port *dp; - int ret; - - *wol_enabled = false; - - if (!dev->wakeup_source) - return; - - dsa_switch_for_each_user_port(dp, dev->ds) { - u8 pme_ctrl = 0; - - ret = ksz_pread8(dev, dp->index, REG_PORT_PME_CTRL, &pme_ctrl); - if (!ret && pme_ctrl) - *wol_enabled = true; - - /* make sure there are no pending wake events which would - * prevent the device from going to sleep/shutdown. - */ - ksz9477_handle_wake_reason(dev, dp->index); - } - - /* Now we are save to enable PME pin. */ - if (*wol_enabled) - ksz_write8(dev, REG_SW_PME_CTRL, PME_ENABLE); -} - static int ksz9477_wait_vlan_ctrl_ready(struct ksz_device *dev) { unsigned int val; diff --git a/drivers/net/dsa/microchip/ksz9477.h b/drivers/net/dsa/microchip/ksz9477.h index 239a281da10b..d2166b0d881e 100644 --- a/drivers/net/dsa/microchip/ksz9477.h +++ b/drivers/net/dsa/microchip/ksz9477.h @@ -60,11 +60,6 @@ void ksz9477_switch_exit(struct ksz_device *dev); void ksz9477_port_queue_split(struct ksz_device *dev, int port); void ksz9477_hsr_join(struct dsa_switch *ds, int port, struct net_device *hsr); void ksz9477_hsr_leave(struct dsa_switch *ds, int port, struct net_device *hsr); -void ksz9477_get_wol(struct ksz_device *dev, int port, - struct ethtool_wolinfo *wol); -int ksz9477_set_wol(struct ksz_device *dev, int port, - struct ethtool_wolinfo *wol); -void ksz9477_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled); int ksz9477_port_acl_init(struct ksz_device *dev, int port); void ksz9477_port_acl_free(struct ksz_device *dev, int port); diff --git a/drivers/net/dsa/microchip/ksz9477_reg.h b/drivers/net/dsa/microchip/ksz9477_reg.h index d5354c600ea1..04235c22bf40 100644 --- a/drivers/net/dsa/microchip/ksz9477_reg.h +++ b/drivers/net/dsa/microchip/ksz9477_reg.h @@ -38,11 +38,6 @@ #define SWITCH_REVISION_S 4 #define SWITCH_RESET 0x01 -#define REG_SW_PME_CTRL 0x0006 - -#define PME_ENABLE BIT(1) -#define PME_POLARITY BIT(0) - #define REG_GLOBAL_OPTIONS 0x000F #define SW_GIGABIT_ABLE BIT(6) @@ -807,13 +802,6 @@ #define REG_PORT_AVB_SR_1_TYPE 0x0008 #define REG_PORT_AVB_SR_2_TYPE 0x000A -#define REG_PORT_PME_STATUS 0x0013 -#define REG_PORT_PME_CTRL 0x0017 - -#define PME_WOL_MAGICPKT BIT(2) -#define PME_WOL_LINKUP BIT(1) -#define PME_WOL_ENERGY BIT(0) - #define REG_PORT_INT_STATUS 0x001B #define REG_PORT_INT_MASK 0x001F diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index b074b4bb0629..6ff39243443f 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -3740,6 +3740,77 @@ static void ksz_get_wol(struct dsa_switch *ds, int port, dev->dev_ops->get_wol(dev, port, wol); } +/** + * ksz9477_handle_wake_reason - Handle wake reason on a specified port. + * @dev: The device structure. + * @port: The port number. + * + * This function reads the PME (Power Management Event) status register of a + * specified port to determine the wake reason. If there is no wake event, it + * returns early. Otherwise, it logs the wake reason which could be due to a + * "Magic Packet", "Link Up", or "Energy Detect" event. The PME status register + * is then cleared to acknowledge the handling of the wake event. + * + * Return: 0 on success, or an error code on failure. + */ +int ksz9477_handle_wake_reason(struct ksz_device *dev, int port) +{ + u8 pme_status; + int ret; + + ret = ksz_pread8(dev, port, REG_PORT_PME_STATUS, &pme_status); + if (ret) + return ret; + + if (!pme_status) + return 0; + + dev_dbg(dev->dev, "Wake event on port %d due to:%s%s%s\n", port, + pme_status & PME_WOL_MAGICPKT ? " \"Magic Packet\"" : "", + pme_status & PME_WOL_LINKUP ? " \"Link Up\"" : "", + pme_status & PME_WOL_ENERGY ? " \"Energy detect\"" : ""); + + return ksz_pwrite8(dev, port, REG_PORT_PME_STATUS, pme_status); +} + +/** + * ksz9477_get_wol - Get Wake-on-LAN settings for a specified port. + * @dev: The device structure. + * @port: The port number. + * @wol: Pointer to ethtool Wake-on-LAN settings structure. + * + * This function checks the PME Pin Control Register to see if PME Pin Output + * Enable is set, indicating PME is enabled. If enabled, it sets the supported + * and active WoL flags. + */ +void ksz9477_get_wol(struct ksz_device *dev, int port, + struct ethtool_wolinfo *wol) +{ + u8 pme_ctrl; + int ret; + + if (!dev->wakeup_source) + return; + + wol->supported = WAKE_PHY; + + /* Check if the current MAC address on this port can be set + * as global for WAKE_MAGIC support. The result may vary + * dynamically based on other ports configurations. + */ + if (ksz_is_port_mac_global_usable(dev->ds, port)) + wol->supported |= WAKE_MAGIC; + + ret = ksz_pread8(dev, port, REG_PORT_PME_CTRL, &pme_ctrl); + if (ret) + return; + + if (pme_ctrl & PME_WOL_MAGICPKT) + wol->wolopts |= WAKE_MAGIC; + if (pme_ctrl & (PME_WOL_LINKUP | PME_WOL_ENERGY)) + wol->wolopts |= WAKE_PHY; +} + static int ksz_set_wol(struct dsa_switch *ds, int port, struct ethtool_wolinfo *wol) { @@ -3751,6 +3822,116 @@ static int ksz_set_wol(struct dsa_switch *ds, int port, return -EOPNOTSUPP; } +/** + * ksz9477_set_wol - Set Wake-on-LAN settings for a specified port. + * @dev: The device structure. + * @port: The port number. + * @wol: Pointer to ethtool Wake-on-LAN settings structure. + * + * This function configures Wake-on-LAN (WoL) settings for a specified port. + * It validates the provided WoL options, checks if PME is enabled via the + * switch's PME Pin Control Register, clears any previous wake reasons, + * and sets the Magic Packet flag in the port's PME control register if + * specified. + * + * Return: 0 on success, or other error codes on failure. + */ +int ksz9477_set_wol(struct ksz_device *dev, int port, + struct ethtool_wolinfo *wol) +{ + u8 pme_ctrl = 0, pme_ctrl_old = 0; + bool magic_switched_off; + bool magic_switched_on; + int ret; + + if (wol->wolopts & ~(WAKE_PHY | WAKE_MAGIC)) + return -EINVAL; + + if (!dev->wakeup_source) + return -EOPNOTSUPP; + + ret = ksz9477_handle_wake_reason(dev, port); + if (ret) + return ret; + + if (wol->wolopts & WAKE_MAGIC) + pme_ctrl |= PME_WOL_MAGICPKT; + if (wol->wolopts & WAKE_PHY) + pme_ctrl |= PME_WOL_LINKUP | PME_WOL_ENERGY; + + ret = ksz_pread8(dev, port, REG_PORT_PME_CTRL, &pme_ctrl_old); + if (ret) + return ret; + + if (pme_ctrl_old == pme_ctrl) + return 0; + + magic_switched_off = (pme_ctrl_old & PME_WOL_MAGICPKT) && + !(pme_ctrl & PME_WOL_MAGICPKT); + magic_switched_on = !(pme_ctrl_old & PME_WOL_MAGICPKT) && + (pme_ctrl & PME_WOL_MAGICPKT); + + /* To keep reference count of MAC address, we should do this + * operation only on change of WOL settings. + */ + if (magic_switched_on) { + ret = ksz_switch_macaddr_get(dev->ds, port, NULL); + if (ret) + return ret; + } else if (magic_switched_off) { + ksz_switch_macaddr_put(dev->ds); + } + + ret = ksz_pwrite8(dev, port, REG_PORT_PME_CTRL, pme_ctrl); + if (ret) { + if (magic_switched_on) + ksz_switch_macaddr_put(dev->ds); + return ret; + } + + return 0; +} + +/** + * ksz9477_wol_pre_shutdown - Prepares the switch device for shutdown while + * considering Wake-on-LAN (WoL) settings. + * @dev: The switch device structure. + * @wol_enabled: Pointer to a boolean which will be set to true if WoL is + * enabled on any port. + * + * This function prepares the switch device for a safe shutdown while taking + * into account the Wake-on-LAN (WoL) settings on the user ports. It updates + * the wol_enabled flag accordingly to reflect whether WoL is active on any + * port. + */ +void ksz9477_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled) +{ + struct dsa_port *dp; + int ret; + + *wol_enabled = false; + + if (!dev->wakeup_source) + return; + + dsa_switch_for_each_user_port(dp, dev->ds) { + u8 pme_ctrl = 0; + + ret = ksz_pread8(dev, dp->index, REG_PORT_PME_CTRL, &pme_ctrl); + if (!ret && pme_ctrl) + *wol_enabled = true; + + /* make sure there are no pending wake events which would + * prevent the device from going to sleep/shutdown. + */ + ksz9477_handle_wake_reason(dev, dp->index); + } + + /* Now we are save to enable PME pin. */ + if (*wol_enabled) + ksz_write8(dev, REG_SW_PME_CTRL, PME_ENABLE); +} + static int ksz_port_set_mac_address(struct dsa_switch *ds, int port, const unsigned char *addr) { diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index 5f0a628b9849..e35caca96f89 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -391,6 +391,12 @@ int ksz_switch_macaddr_get(struct dsa_switch *ds, int port, struct netlink_ext_ack *extack); void ksz_switch_macaddr_put(struct dsa_switch *ds); void ksz_switch_shutdown(struct ksz_device *dev); +int ksz9477_handle_wake_reason(struct ksz_device *dev, int port); +void ksz9477_get_wol(struct ksz_device *dev, int port, + struct ethtool_wolinfo *wol); +int ksz9477_set_wol(struct ksz_device *dev, int port, + struct ethtool_wolinfo *wol); +void ksz9477_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled); /* Common register access functions */ static inline struct regmap *ksz_regmap_8(struct ksz_device *dev) @@ -695,6 +701,19 @@ static inline bool is_lan937x_tx_phy(struct ksz_device *dev, int port) #define P_MII_MAC_MODE BIT(2) #define P_MII_SEL_M 0x3 +/* KSZ9477, KSZ8795 Wake-on-LAN (WoL) masks */ +#define REG_PORT_PME_STATUS 0x0013 +#define REG_PORT_PME_CTRL 0x0017 + +#define PME_WOL_MAGICPKT BIT(2) +#define PME_WOL_LINKUP BIT(1) +#define PME_WOL_ENERGY BIT(0) + +#define REG_SW_PME_CTRL 0x0006 + +#define PME_ENABLE BIT(1) +#define PME_POLARITY BIT(0) + /* Interrupt */ #define REG_SW_PORT_INT_STATUS__1 0x001B #define REG_SW_PORT_INT_MASK__1 0x001F From patchwork Tue Aug 6 13:25:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13754862 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BDC721D27B6; Tue, 6 Aug 2024 13:28:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722950924; cv=none; b=qQAZHLM4iB3dhBzntEjpQ0CiIgjY+p/XEHks2yS7IoO9nHuUZnzFAN4QP0iF0NmMy3bo+J+WQouBl4I2cdzrXRkYKbpqPcWOYGmzDqBByrGo3GFjosm/7AYuXWc3KfSuNGBZ4KfSUxNgA6bVTLu9e5OcvCS2XAC2bLrGSpBw248= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722950924; c=relaxed/simple; bh=ZdkDVS74o9bNUcZEn5g+ANt4mqKi/o6W/iQFS1M8oVE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=myD3M6L+mrzLX+s5SmIE2W2Ghnbc5E8UocDePly3jPh1YSLHvJhfd6xqXcpntEb+9ynYw0zmLf9IyvxRi4xhaZ0UBKHorVpCHWk7DcuDvsVW/BVG89KwX2OG/O8SmfyHi0W5qcXDnhn5pGOqFU1y9v3jeFZ8mw3jMZmiuaacegw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Dug+4lWo; arc=none smtp.client-ip=209.85.208.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Dug+4lWo" Received: by mail-ed1-f53.google.com with SMTP id 4fb4d7f45d1cf-5b5b67d0024so987251a12.0; Tue, 06 Aug 2024 06:28:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722950921; x=1723555721; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+xiGgUec/pXE+XZcgNMAzZ1p/6egC1HLYv29gEB5wTs=; b=Dug+4lWoM6X/irJ8ihUQI5TX2LRhkZHKwWKau2sCHD5QhSeU6K0sYA0CUs4SUkKsfE zYtI9esbttQZ3JgUCcACQ+hTZJUbzgHvwbBgoumyzMIB6QC41G2LhuOlcKe/cf2DZJbs ys72v/o37Zhr36CIgqaElsoQp2bh3daUdkZJOUGMlx4F4b8o1GZuPWOkqdy8nIqsuuMu zpz8chY6gaQtEve1CtFsO/NsAlqwtXEO2TWEPLhRt0CL/rNr64elwazAv/oMo17QJs65 ZbBzckqEOdjGdpOau1EgIZWEQ0s9GdqXAEvq1L8aO55lMoTIMcWJbBbHtIrManUiYoVM ztGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722950921; x=1723555721; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+xiGgUec/pXE+XZcgNMAzZ1p/6egC1HLYv29gEB5wTs=; b=rznbobBggiiTRgQr4xTC9nI475drA7gjPCfBLOFIntO7UqCqk17LjFNu1t5/0aaxck GC3w+cIVqFxfQjdNAwEa/0fT0BqtQ5Ubuj1Vh4KE+T337VlFiGf3L2og6IHBeJD8uGm9 aefprq7aiBTG+1A8b6pL9oEKzfSea7QzxkDzH7BR6V5tDggwugOzkM8at+ss2Rz2tkCs g4/uzolvAib4QLwAxdHWHxIgDtlp79ngzqpNBKwc/KzJpHCwL1fndL16XUBpMu49O5uB x96Y98Q3bGA6F1sJUuiy9m7qdxZ9O+aPLetZhtxD/v9edrTpibbTKoZ3ET4zwfhyTdA+ M8XQ== X-Forwarded-Encrypted: i=1; AJvYcCWyOIGFm2P/BXK4FAK2s6wD8qCyzt5dtT62CQm5T2xL5bxggeImg6RHpbOnABuqco2vJJ7VVsHIneG0xOMdjWUoO/lwnq9Ls4yVE6LsR6/Lu+bf3EiNy+miuF2bEM0FC5x5fasJml+CowcsEQJA2TyFz4cWdsLxyCEHVL25e++6bw== X-Gm-Message-State: AOJu0YxL1VooTKkPzn+2RI7rRcJRoKDdPLkxT85JZhJ1hxaoZHdxAm4g QojbGVOQwk4r5Nb2uXxgsGZvUYhW8bujLh6taMsdPYvwLEqogGrZ X-Google-Smtp-Source: AGHT+IElwtDdG7YTimrhssS220Humer3PundPkh3agRl//wkfZJ6jzbEAgrhYGBCEjdbeYVqCn2WCQ== X-Received: by 2002:a05:6402:148c:b0:5b9:3846:8bb9 with SMTP id 4fb4d7f45d1cf-5b9384693abmr7483754a12.10.1722950920916; Tue, 06 Aug 2024 06:28:40 -0700 (PDT) Received: from lapsy144.cern.ch ([2001:1458:204:1::102:a6a]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5b83a153f77sm5910172a12.53.2024.08.06.06.28.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 06:28:40 -0700 (PDT) From: vtpieter@gmail.com To: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Florian Fainelli , Vladimir Oltean , David S Miller , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Marek Vasut , Russell King Cc: Woojung Huh , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Pieter Van Trappen Subject: [PATCH net-next v3 3/5] net: dsa: microchip: generalize KSZ9477 WoL functions at ksz_common Date: Tue, 6 Aug 2024 15:25:55 +0200 Message-ID: <20240806132606.1438953-4-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240806132606.1438953-1-vtpieter@gmail.com> References: <20240806132606.1438953-1-vtpieter@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Pieter Van Trappen Generalize KSZ9477 WoL functions at ksz_common. Move dedicated registers and generic masks to existing structures & defines for that purpose. Introduction of PME (port) read/write helper functions, which happen to be the generic read/write for KSZ9477 but not for the incoming KSZ87xx patch. Signed-off-by: Pieter Van Trappen Acked-by: Arun Ramadoss --- drivers/net/dsa/microchip/ksz9477.c | 16 ++-- drivers/net/dsa/microchip/ksz_common.c | 113 +++++++++++++------------ drivers/net/dsa/microchip/ksz_common.h | 30 +++---- 3 files changed, 81 insertions(+), 78 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 071d953a17e9..db40b187a36d 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -1007,6 +1007,7 @@ void ksz9477_port_queue_split(struct ksz_device *dev, int port) void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port) { + const u16 *regs = dev->info->regs; struct dsa_switch *ds = dev->ds; u16 data16; u8 member; @@ -1051,12 +1052,12 @@ void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port) ksz9477_port_acl_init(dev, port); /* clear pending wake flags */ - ksz9477_handle_wake_reason(dev, port); + ksz_handle_wake_reason(dev, port); /* Disable all WoL options by default. Otherwise * ksz_switch_macaddr_get/put logic will not work properly. */ - ksz_pwrite8(dev, port, REG_PORT_PME_CTRL, 0); + ksz_pwrite8(dev, port, regs[REG_PORT_PME_CTRL], 0); } void ksz9477_config_cpu_port(struct dsa_switch *ds) @@ -1153,6 +1154,7 @@ int ksz9477_enable_stp_addr(struct ksz_device *dev) int ksz9477_setup(struct dsa_switch *ds) { struct ksz_device *dev = ds->priv; + const u16 *regs = dev->info->regs; int ret = 0; ds->mtu_enforcement_ingress = true; @@ -1183,13 +1185,11 @@ int ksz9477_setup(struct dsa_switch *ds) /* enable global MIB counter freeze function */ ksz_cfg(dev, REG_SW_MAC_CTRL_6, SW_MIB_COUNTER_FREEZE, true); - /* Make sure PME (WoL) is not enabled. If requested, it will be - * enabled by ksz9477_wol_pre_shutdown(). Otherwise, some PMICs do not - * like PME events changes before shutdown. + /* Make sure PME (WoL) is not enabled. If requested, it will + * be enabled by ksz_wol_pre_shutdown(). Otherwise, some PMICs + * do not like PME events changes before shutdown. */ - ksz_write8(dev, REG_SW_PME_CTRL, 0); - - return 0; + return ksz_write8(dev, regs[REG_SW_PME_CTRL], 0); } u32 ksz9477_get_port_addr(int port, int offset) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 6ff39243443f..d8b8c17f979c 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -348,9 +348,9 @@ static const struct ksz_dev_ops ksz9477_dev_ops = { .mdb_add = ksz9477_mdb_add, .mdb_del = ksz9477_mdb_del, .change_mtu = ksz9477_change_mtu, - .get_wol = ksz9477_get_wol, - .set_wol = ksz9477_set_wol, - .wol_pre_shutdown = ksz9477_wol_pre_shutdown, + .pme_write8 = ksz_write8, + .pme_pread8 = ksz_pread8, + .pme_pwrite8 = ksz_pwrite8, .config_cpu_port = ksz9477_config_cpu_port, .tc_cbs_set_cinc = ksz9477_tc_cbs_set_cinc, .enable_stp_addr = ksz9477_enable_stp_addr, @@ -539,6 +539,9 @@ static const u16 ksz9477_regs[] = { [S_MULTICAST_CTRL] = 0x0331, [P_XMII_CTRL_0] = 0x0300, [P_XMII_CTRL_1] = 0x0301, + [REG_SW_PME_CTRL] = 0x0006, + [REG_PORT_PME_STATUS] = 0x0013, + [REG_PORT_PME_CTRL] = 0x0017, }; static const u32 ksz9477_masks[] = { @@ -3731,17 +3734,8 @@ static int ksz_setup_tc(struct dsa_switch *ds, int port, } } -static void ksz_get_wol(struct dsa_switch *ds, int port, - struct ethtool_wolinfo *wol) -{ - struct ksz_device *dev = ds->priv; - - if (dev->dev_ops->get_wol) - dev->dev_ops->get_wol(dev, port, wol); -} - /** - * ksz9477_handle_wake_reason - Handle wake reason on a specified port. + * ksz_handle_wake_reason - Handle wake reason on a specified port. * @dev: The device structure. * @port: The port number. * @@ -3753,12 +3747,15 @@ static void ksz_get_wol(struct dsa_switch *ds, int port, * * Return: 0 on success, or an error code on failure. */ -int ksz9477_handle_wake_reason(struct ksz_device *dev, int port) +int ksz_handle_wake_reason(struct ksz_device *dev, int port) { + const struct ksz_dev_ops *ops = dev->dev_ops; + const u16 *regs = dev->info->regs; u8 pme_status; int ret; - ret = ksz_pread8(dev, port, REG_PORT_PME_STATUS, &pme_status); + ret = ops->pme_pread8(dev, port, regs[REG_PORT_PME_STATUS], + &pme_status); if (ret) return ret; @@ -3770,25 +3767,31 @@ int ksz9477_handle_wake_reason(struct ksz_device *dev, int port) pme_status & PME_WOL_LINKUP ? " \"Link Up\"" : "", pme_status & PME_WOL_ENERGY ? " \"Energy detect\"" : ""); - return ksz_pwrite8(dev, port, REG_PORT_PME_STATUS, pme_status); + return ops->pme_pwrite8(dev, port, regs[REG_PORT_PME_STATUS], + pme_status); } /** - * ksz9477_get_wol - Get Wake-on-LAN settings for a specified port. - * @dev: The device structure. + * ksz_get_wol - Get Wake-on-LAN settings for a specified port. + * @ds: The dsa_switch structure. * @port: The port number. * @wol: Pointer to ethtool Wake-on-LAN settings structure. * - * This function checks the PME Pin Control Register to see if PME Pin Output - * Enable is set, indicating PME is enabled. If enabled, it sets the supported - * and active WoL flags. + * This function checks the device PME wakeup_source flag and chip_id. + * If enabled and supported, it sets the supported and active WoL + * flags. */ -void ksz9477_get_wol(struct ksz_device *dev, int port, - struct ethtool_wolinfo *wol) +static void ksz_get_wol(struct dsa_switch *ds, int port, + struct ethtool_wolinfo *wol) { + struct ksz_device *dev = ds->priv; + const u16 *regs = dev->info->regs; u8 pme_ctrl; int ret; + if (!is_ksz9477(dev)) + return; + if (!dev->wakeup_source) return; @@ -3801,7 +3804,8 @@ void ksz9477_get_wol(struct ksz_device *dev, int port, if (ksz_is_port_mac_global_usable(dev->ds, port)) wol->supported |= WAKE_MAGIC; - ret = ksz_pread8(dev, port, REG_PORT_PME_CTRL, &pme_ctrl); + ret = dev->dev_ops->pme_pread8(dev, port, regs[REG_PORT_PME_CTRL], + &pme_ctrl); if (ret) return; @@ -3811,35 +3815,26 @@ void ksz9477_get_wol(struct ksz_device *dev, int port, wol->wolopts |= WAKE_PHY; } -static int ksz_set_wol(struct dsa_switch *ds, int port, - struct ethtool_wolinfo *wol) -{ - struct ksz_device *dev = ds->priv; - - if (dev->dev_ops->set_wol) - return dev->dev_ops->set_wol(dev, port, wol); - - return -EOPNOTSUPP; -} - /** - * ksz9477_set_wol - Set Wake-on-LAN settings for a specified port. - * @dev: The device structure. + * ksz_set_wol - Set Wake-on-LAN settings for a specified port. + * @ds: The dsa_switch structure. * @port: The port number. * @wol: Pointer to ethtool Wake-on-LAN settings structure. * - * This function configures Wake-on-LAN (WoL) settings for a specified port. - * It validates the provided WoL options, checks if PME is enabled via the - * switch's PME Pin Control Register, clears any previous wake reasons, - * and sets the Magic Packet flag in the port's PME control register if + * This function configures Wake-on-LAN (WoL) settings for a specified + * port. It validates the provided WoL options, checks if PME is + * enabled and supported, clears any previous wake reasons, and sets + * the Magic Packet flag in the port's PME control register if * specified. * * Return: 0 on success, or other error codes on failure. */ -int ksz9477_set_wol(struct ksz_device *dev, int port, - struct ethtool_wolinfo *wol) +static int ksz_set_wol(struct dsa_switch *ds, int port, + struct ethtool_wolinfo *wol) { u8 pme_ctrl = 0, pme_ctrl_old = 0; + struct ksz_device *dev = ds->priv; + const u16 *regs = dev->info->regs; bool magic_switched_off; bool magic_switched_on; int ret; @@ -3847,10 +3842,13 @@ int ksz9477_set_wol(struct ksz_device *dev, int port, if (wol->wolopts & ~(WAKE_PHY | WAKE_MAGIC)) return -EINVAL; + if (!is_ksz9477(dev)) + return -EOPNOTSUPP; + if (!dev->wakeup_source) return -EOPNOTSUPP; - ret = ksz9477_handle_wake_reason(dev, port); + ret = ksz_handle_wake_reason(dev, port); if (ret) return ret; @@ -3859,7 +3857,8 @@ int ksz9477_set_wol(struct ksz_device *dev, int port, if (wol->wolopts & WAKE_PHY) pme_ctrl |= PME_WOL_LINKUP | PME_WOL_ENERGY; - ret = ksz_pread8(dev, port, REG_PORT_PME_CTRL, &pme_ctrl_old); + ret = dev->dev_ops->pme_pread8(dev, port, regs[REG_PORT_PME_CTRL], + &pme_ctrl_old); if (ret) return ret; @@ -3882,7 +3881,8 @@ int ksz9477_set_wol(struct ksz_device *dev, int port, ksz_switch_macaddr_put(dev->ds); } - ret = ksz_pwrite8(dev, port, REG_PORT_PME_CTRL, pme_ctrl); + ret = dev->dev_ops->pme_pwrite8(dev, port, regs[REG_PORT_PME_CTRL], + pme_ctrl); if (ret) { if (magic_switched_on) ksz_switch_macaddr_put(dev->ds); @@ -3893,8 +3893,8 @@ int ksz9477_set_wol(struct ksz_device *dev, int port, } /** - * ksz9477_wol_pre_shutdown - Prepares the switch device for shutdown while - * considering Wake-on-LAN (WoL) settings. + * ksz_wol_pre_shutdown - Prepares the switch device for shutdown while + * considering Wake-on-LAN (WoL) settings. * @dev: The switch device structure. * @wol_enabled: Pointer to a boolean which will be set to true if WoL is * enabled on any port. @@ -3904,32 +3904,38 @@ int ksz9477_set_wol(struct ksz_device *dev, int port, * the wol_enabled flag accordingly to reflect whether WoL is active on any * port. */ -void ksz9477_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled) +static void ksz_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled) { + const struct ksz_dev_ops *ops = dev->dev_ops; + const u16 *regs = dev->info->regs; struct dsa_port *dp; int ret; *wol_enabled = false; + if (!is_ksz9477(dev)) + return; + if (!dev->wakeup_source) return; dsa_switch_for_each_user_port(dp, dev->ds) { u8 pme_ctrl = 0; - ret = ksz_pread8(dev, dp->index, REG_PORT_PME_CTRL, &pme_ctrl); + ret = ops->pme_pread8(dev, dp->index, + regs[REG_PORT_PME_CTRL], &pme_ctrl); if (!ret && pme_ctrl) *wol_enabled = true; /* make sure there are no pending wake events which would * prevent the device from going to sleep/shutdown. */ - ksz9477_handle_wake_reason(dev, dp->index); + ksz_handle_wake_reason(dev, dp->index); } /* Now we are save to enable PME pin. */ if (*wol_enabled) - ksz_write8(dev, REG_SW_PME_CTRL, PME_ENABLE); + ops->pme_write8(dev, regs[REG_SW_PME_CTRL], PME_ENABLE); } static int ksz_port_set_mac_address(struct dsa_switch *ds, int port, @@ -4237,8 +4243,7 @@ void ksz_switch_shutdown(struct ksz_device *dev) { bool wol_enabled = false; - if (dev->dev_ops->wol_pre_shutdown) - dev->dev_ops->wol_pre_shutdown(dev, &wol_enabled); + ksz_wol_pre_shutdown(dev, &wol_enabled); if (dev->dev_ops->reset && !wol_enabled) dev->dev_ops->reset(dev); diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index e35caca96f89..c60c218afa64 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -235,6 +235,9 @@ enum ksz_regs { S_MULTICAST_CTRL, P_XMII_CTRL_0, P_XMII_CTRL_1, + REG_SW_PME_CTRL, + REG_PORT_PME_STATUS, + REG_PORT_PME_CTRL, }; enum ksz_masks { @@ -354,6 +357,11 @@ struct ksz_dev_ops { void (*get_caps)(struct ksz_device *dev, int port, struct phylink_config *config); int (*change_mtu)(struct ksz_device *dev, int port, int mtu); + int (*pme_write8)(struct ksz_device *dev, u32 reg, u8 value); + int (*pme_pread8)(struct ksz_device *dev, int port, int offset, + u8 *data); + int (*pme_pwrite8)(struct ksz_device *dev, int port, int offset, + u8 data); void (*freeze_mib)(struct ksz_device *dev, int port, bool freeze); void (*port_init_cnt)(struct ksz_device *dev, int port); void (*phylink_mac_link_up)(struct ksz_device *dev, int port, @@ -363,11 +371,6 @@ struct ksz_dev_ops { int duplex, bool tx_pause, bool rx_pause); void (*setup_rgmii_delay)(struct ksz_device *dev, int port); int (*tc_cbs_set_cinc)(struct ksz_device *dev, int port, u32 val); - void (*get_wol)(struct ksz_device *dev, int port, - struct ethtool_wolinfo *wol); - int (*set_wol)(struct ksz_device *dev, int port, - struct ethtool_wolinfo *wol); - void (*wol_pre_shutdown)(struct ksz_device *dev, bool *wol_enabled); void (*config_cpu_port)(struct dsa_switch *ds); int (*enable_stp_addr)(struct ksz_device *dev); int (*reset)(struct ksz_device *dev); @@ -391,12 +394,7 @@ int ksz_switch_macaddr_get(struct dsa_switch *ds, int port, struct netlink_ext_ack *extack); void ksz_switch_macaddr_put(struct dsa_switch *ds); void ksz_switch_shutdown(struct ksz_device *dev); -int ksz9477_handle_wake_reason(struct ksz_device *dev, int port); -void ksz9477_get_wol(struct ksz_device *dev, int port, - struct ethtool_wolinfo *wol); -int ksz9477_set_wol(struct ksz_device *dev, int port, - struct ethtool_wolinfo *wol); -void ksz9477_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled); +int ksz_handle_wake_reason(struct ksz_device *dev, int port); /* Common register access functions */ static inline struct regmap *ksz_regmap_8(struct ksz_device *dev) @@ -635,6 +633,11 @@ static inline bool is_ksz8(struct ksz_device *dev) return ksz_is_ksz87xx(dev) || ksz_is_ksz88x3(dev); } +static inline bool is_ksz9477(struct ksz_device *dev) +{ + return dev->chip_id == KSZ9477_CHIP_ID; +} + static inline int is_lan937x(struct ksz_device *dev) { return dev->chip_id == LAN9370_CHIP_ID || @@ -702,15 +705,10 @@ static inline bool is_lan937x_tx_phy(struct ksz_device *dev, int port) #define P_MII_SEL_M 0x3 /* KSZ9477, KSZ8795 Wake-on-LAN (WoL) masks */ -#define REG_PORT_PME_STATUS 0x0013 -#define REG_PORT_PME_CTRL 0x0017 - #define PME_WOL_MAGICPKT BIT(2) #define PME_WOL_LINKUP BIT(1) #define PME_WOL_ENERGY BIT(0) -#define REG_SW_PME_CTRL 0x0006 - #define PME_ENABLE BIT(1) #define PME_POLARITY BIT(0) From patchwork Tue Aug 6 13:25:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13754863 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2ED3B1D54EB; Tue, 6 Aug 2024 13:28:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.48 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722950930; cv=none; b=WX8L5YtcU5e+zdwEfkKxfqo6JBeprd7il/74ysLIgkUpvVqOOyZSFJAum562GddIFlQOIF025l+K9xlKzCJ3MSgkItT18GeaLBXE7xe97XozMKP+5ykrkvz+Pqdekeg+Q48DTDFPqW6qylHGfIZQobYuZXYAkpnPxRxt+eMTer0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722950930; c=relaxed/simple; bh=WmMvoB68U8Wc4O3qdg22EDFbwce9VHJjnsUkElzQmSI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ulL/8istfAKCbCzSOjTjJuFZQcg/5Ivg4wWNHjeaRCvDw8xq5pLuBw2fL17HRiQ5TiKEn25i1ZJXc26ivG3vy5/EkftzMHFBeSoGuhz07u+h03RX1i4S6lw6b4mD+FI4WJ+HyCMPpqieDCK2n53n9WZxImmIuxDVlYu1EStLjE0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=S0oIYBFb; arc=none smtp.client-ip=209.85.208.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="S0oIYBFb" Received: by mail-ed1-f48.google.com with SMTP id 4fb4d7f45d1cf-5b8c2a6135dso993128a12.1; Tue, 06 Aug 2024 06:28:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722950926; x=1723555726; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=N9bw0YKI65JJ5pW22paW2wmKi5k1PnotCTNp69g0vuI=; b=S0oIYBFbJ8doFLVFh+3toku49DV1UffKHw3scmvHcuy3QH6ZIKZMXhVB5JQblJpn8P k/fKGnogqaM9md8iNOyfTOenMqrY+W8RyeVPJD8YvkvMIpYQEyvkgc2iqw+EXSwZiyo7 b7DOWgDHRue1UrAKAWvqdSzTUqOBp8p0Cy34YFZpIw1qs+RGShl48iryz5OsAImHT9OE 410QFh8V7DwwNpL2I7yvN5CVty9PxDunIrq0tZl7AevE5ARHDyNR23xLXa6jeR8joakV y/mYMLe9wBNNCQ74jtV7mpOljGztjJcooSUAdHLyhzBs+YMYg9vDXs3j1cMw1zKwfnpW kVsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722950926; x=1723555726; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=N9bw0YKI65JJ5pW22paW2wmKi5k1PnotCTNp69g0vuI=; b=ctqwymgCqPClQd4+4RitQB/UYotZxDo2VMXZyUm4tWSZqrJcd/139BrStEoz68ZNVG ahQaFGVOrNlF80pxt0iwGWr0Lj+bxwfUMeNud048Ha05bplmX9nrQb9lrXBUed2UN9mH 0Wq9ZYsgPSsTSVsdd9Aich2id9El7NsmVkj5zbqhYTMxYOqegCz2JZ9iYHIwe35atpYA OAf58RgfP2heDuGlXtQtSt+MCVBN0NZp21BAI5+GK+FfnM1myJwLdjMk7hYfkxyFSBji 8Tcc61aHmTJWx1DuQT3OeuQjxZ1v8rKbKagVPpVywvhvlFKwOMANXPcAQdfHrlykHhkI Y5vA== X-Forwarded-Encrypted: i=1; AJvYcCUKurWunJBqNrsoaHjRnc59uc6xWRiIkT/7bI8noyoK653DrB/Fuq9+YQxPc0nKCjJaf6hVjq8oaY/RrF0bUMJXcR3/SsWRo/ORUr21waUNZfc0Tx7URQmtM2uynpsGOE2GuFAtzbxczb6mXSHCnpOQH08iW2/Rlav/KnkaC4WaLQ== X-Gm-Message-State: AOJu0YyNlJHlQoc2eUCfJBsdZp+hM3IfElkbAOFbPBxYWVckLYkAjmYW uoojtBuHNnY8FugtgVp1VRpqescjRDgOOhcJ/8Yg1HzZ984gul0Y X-Google-Smtp-Source: AGHT+IHQFBQsVITBptXjIo37uHZKCljUTfn9V777LG4wPRLMoR59hiz7CQaxJ86WsKJ9q9uMtGJk+Q== X-Received: by 2002:aa7:d552:0:b0:5b6:d0f1:2947 with SMTP id 4fb4d7f45d1cf-5b7f57f4238mr10692274a12.34.1722950926341; Tue, 06 Aug 2024 06:28:46 -0700 (PDT) Received: from lapsy144.cern.ch ([2001:1458:204:1::102:a6a]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5b83a153f77sm5910172a12.53.2024.08.06.06.28.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 06:28:46 -0700 (PDT) From: vtpieter@gmail.com To: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Florian Fainelli , Vladimir Oltean , David S Miller , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Marek Vasut , Russell King Cc: Woojung Huh , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Pieter Van Trappen Subject: [PATCH net-next v3 4/5] net: dsa: microchip: add WoL support for KSZ87xx family Date: Tue, 6 Aug 2024 15:25:56 +0200 Message-ID: <20240806132606.1438953-5-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240806132606.1438953-1-vtpieter@gmail.com> References: <20240806132606.1438953-1-vtpieter@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Pieter Van Trappen Add WoL support for KSZ87xx family of switches. This code was tested with a KSZ8794 chip. Implement ksz_common usage of the new device-tree property 'microchip,pme-active-high'. Make use of the now generalized ksz_common WoL functions, adding an additional interrupt register write for KSZ87xx. Add helper functions to convert from PME (port) read/writes to indirect register read/writes in the dedicated ksz8795 sources. Add initial configuration during (port) setup as per KSZ9477. Signed-off-by: Pieter Van Trappen --- drivers/net/dsa/microchip/ksz8.h | 3 + drivers/net/dsa/microchip/ksz8795.c | 94 +++++++++++++++++++++++++- drivers/net/dsa/microchip/ksz_common.c | 24 +++++-- drivers/net/dsa/microchip/ksz_common.h | 4 ++ 4 files changed, 118 insertions(+), 7 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8.h b/drivers/net/dsa/microchip/ksz8.h index ae43077e76c3..e1c79ff97123 100644 --- a/drivers/net/dsa/microchip/ksz8.h +++ b/drivers/net/dsa/microchip/ksz8.h @@ -54,6 +54,9 @@ int ksz8_reset_switch(struct ksz_device *dev); int ksz8_switch_init(struct ksz_device *dev); void ksz8_switch_exit(struct ksz_device *dev); int ksz8_change_mtu(struct ksz_device *dev, int port, int mtu); +int ksz8_pme_write8(struct ksz_device *dev, u32 reg, u8 value); +int ksz8_pme_pread8(struct ksz_device *dev, int port, int offset, u8 *data); +int ksz8_pme_pwrite8(struct ksz_device *dev, int port, int offset, u8 data); void ksz8_phylink_mac_link_up(struct phylink_config *config, struct phy_device *phydev, unsigned int mode, phy_interface_t interface, int speed, int duplex, diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index d27b9c36d73f..a01079297a8c 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -38,6 +38,20 @@ static void ksz_port_cfg(struct ksz_device *dev, int port, int offset, u8 bits, bits, set ? bits : 0); } +/** + * ksz8_ind_write8 - EEE/ACL/PME indirect register write + * @dev: The device structure. + * @table: Function & table select, register 110. + * @addr: Indirect access control, register 111. + * @data: The data to be written. + * + * This function performs an indirect register write for EEE, ACL or + * PME switch functionalities. Both 8-bit registers 110 and 111 are + * written at once with ksz_write16, using the serial multiple write + * functionality. + * + * Return: 0 on success, or an error code on failure. + */ static int ksz8_ind_write8(struct ksz_device *dev, u8 table, u16 addr, u8 data) { const u16 *regs; @@ -58,6 +72,59 @@ static int ksz8_ind_write8(struct ksz_device *dev, u8 table, u16 addr, u8 data) return ret; } +/** + * ksz8_ind_read8 - EEE/ACL/PME indirect register read + * @dev: The device structure. + * @table: Function & table select, register 110. + * @addr: Indirect access control, register 111. + * @val: The value read. + * + * This function performs an indirect register read for EEE, ACL or + * PME switch functionalities. Both 8-bit registers 110 and 111 are + * written at once with ksz_write16, using the serial multiple write + * functionality. + * + * Return: 0 on success, or an error code on failure. + */ +static int ksz8_ind_read8(struct ksz_device *dev, u8 table, u16 addr, u8 *val) +{ + const u16 *regs; + u16 ctrl_addr; + int ret = 0; + + regs = dev->info->regs; + + mutex_lock(&dev->alu_mutex); + + ctrl_addr = IND_ACC_TABLE(table | TABLE_READ) | addr; + ret = ksz_write16(dev, regs[REG_IND_CTRL_0], ctrl_addr); + if (!ret) + ret = ksz_read8(dev, regs[REG_IND_BYTE], val); + + mutex_unlock(&dev->alu_mutex); + + return ret; +} + +int ksz8_pme_write8(struct ksz_device *dev, u32 reg, u8 value) +{ + return ksz8_ind_write8(dev, (u8)(reg >> 8), (u8)(reg), value); +} + +int ksz8_pme_pread8(struct ksz_device *dev, int port, int offset, u8 *data) +{ + u8 table = (u8)(offset >> 8 | (port + 1)); + + return ksz8_ind_read8(dev, table, (u8)(offset), data); +} + +int ksz8_pme_pwrite8(struct ksz_device *dev, int port, int offset, u8 data) +{ + u8 table = (u8)(offset >> 8 | (port + 1)); + + return ksz8_ind_write8(dev, table, (u8)(offset), data); +} + int ksz8_reset_switch(struct ksz_device *dev) { if (ksz_is_ksz88x3(dev)) { @@ -1545,6 +1612,7 @@ static void ksz8795_cpu_interface_select(struct ksz_device *dev, int port) void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port) { + const u16 *regs = dev->info->regs; struct dsa_switch *ds = dev->ds; const u32 *masks; int queues; @@ -1575,6 +1643,13 @@ void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port) member = BIT(dsa_upstream_port(ds, port)); ksz8_cfg_port_member(dev, port, member); + + /* Disable all WoL options by default. Otherwise + * ksz_switch_macaddr_get/put logic will not work properly. + * CPU port 4 has no WoL functionality. + */ + if (ksz_is_ksz87xx(dev) && !cpu_port) + ksz8_pme_pwrite8(dev, port, regs[REG_PORT_PME_CTRL], 0); } static void ksz88x3_config_rmii_clk(struct ksz_device *dev) @@ -1790,7 +1865,8 @@ int ksz8_enable_stp_addr(struct ksz_device *dev) int ksz8_setup(struct dsa_switch *ds) { struct ksz_device *dev = ds->priv; - int i; + const u16 *regs = dev->info->regs; + int i, ret = 0; ds->mtu_enforcement_ingress = true; @@ -1829,7 +1905,21 @@ int ksz8_setup(struct dsa_switch *ds) for (i = 0; i < (dev->info->num_vlans / 4); i++) ksz8_r_vlan_entries(dev, i); - return ksz8_handle_global_errata(ds); + /* Make sure PME (WoL) is not enabled. If requested, it will + * be enabled by ksz_wol_pre_shutdown(). Otherwise, some PMICs + * do not like PME events changes before shutdown. PME only + * available on KSZ87xx family. + */ + if (ksz_is_ksz87xx(dev)) { + ret = ksz8_pme_write8(dev, regs[REG_SW_PME_CTRL], 0); + if (!ret) + ret = ksz_rmw8(dev, REG_INT_ENABLE, INT_PME, 0); + } + + if (!ret) + return ksz8_handle_global_errata(ds); + else + return ret; } void ksz8_get_caps(struct ksz_device *dev, int port, diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index d8b8c17f979c..c2079e39fbd5 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -307,6 +307,9 @@ static const struct ksz_dev_ops ksz8_dev_ops = { .init = ksz8_switch_init, .exit = ksz8_switch_exit, .change_mtu = ksz8_change_mtu, + .pme_write8 = ksz8_pme_write8, + .pme_pread8 = ksz8_pme_pread8, + .pme_pwrite8 = ksz8_pme_pwrite8, }; static void ksz9477_phylink_mac_link_up(struct phylink_config *config, @@ -423,6 +426,9 @@ static const u16 ksz8795_regs[] = { [S_MULTICAST_CTRL] = 0x04, [P_XMII_CTRL_0] = 0x06, [P_XMII_CTRL_1] = 0x06, + [REG_SW_PME_CTRL] = 0x8003, + [REG_PORT_PME_STATUS] = 0x8003, + [REG_PORT_PME_CTRL] = 0x8007, }; static const u32 ksz8795_masks[] = { @@ -3789,7 +3795,7 @@ static void ksz_get_wol(struct dsa_switch *ds, int port, u8 pme_ctrl; int ret; - if (!is_ksz9477(dev)) + if (!is_ksz9477(dev) && !ksz_is_ksz87xx(dev)) return; if (!dev->wakeup_source) @@ -3842,7 +3848,7 @@ static int ksz_set_wol(struct dsa_switch *ds, int port, if (wol->wolopts & ~(WAKE_PHY | WAKE_MAGIC)) return -EINVAL; - if (!is_ksz9477(dev)) + if (!is_ksz9477(dev) && !ksz_is_ksz87xx(dev)) return -EOPNOTSUPP; if (!dev->wakeup_source) @@ -3908,12 +3914,13 @@ static void ksz_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled) { const struct ksz_dev_ops *ops = dev->dev_ops; const u16 *regs = dev->info->regs; + u8 pme_pin_en = PME_ENABLE; struct dsa_port *dp; int ret; *wol_enabled = false; - if (!is_ksz9477(dev)) + if (!is_ksz9477(dev) && !ksz_is_ksz87xx(dev)) return; if (!dev->wakeup_source) @@ -3934,8 +3941,13 @@ static void ksz_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled) } /* Now we are save to enable PME pin. */ - if (*wol_enabled) - ops->pme_write8(dev, regs[REG_SW_PME_CTRL], PME_ENABLE); + if (*wol_enabled) { + if (dev->pme_active_high) + pme_pin_en |= PME_POLARITY; + ops->pme_write8(dev, regs[REG_SW_PME_CTRL], pme_pin_en); + if (ksz_is_ksz87xx(dev)) + ksz_write8(dev, KSZ8795_REG_INT_EN, KSZ8795_INT_PME_MASK); + } } static int ksz_port_set_mac_address(struct dsa_switch *ds, int port, @@ -4645,6 +4657,8 @@ int ksz_switch_register(struct ksz_device *dev) dev->wakeup_source = of_property_read_bool(dev->dev->of_node, "wakeup-source"); + dev->pme_active_high = of_property_read_bool(dev->dev->of_node, + "microchip,pme-active-high"); } ret = dsa_register_switch(dev->ds); diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h index c60c218afa64..c0b93825726d 100644 --- a/drivers/net/dsa/microchip/ksz_common.h +++ b/drivers/net/dsa/microchip/ksz_common.h @@ -174,6 +174,7 @@ struct ksz_device { bool synclko_125; bool synclko_disable; bool wakeup_source; + bool pme_active_high; struct vlan_table *vlan_cache; @@ -712,6 +713,9 @@ static inline bool is_lan937x_tx_phy(struct ksz_device *dev, int port) #define PME_ENABLE BIT(1) #define PME_POLARITY BIT(0) +#define KSZ8795_REG_INT_EN 0x7D +#define KSZ8795_INT_PME_MASK BIT(4) + /* Interrupt */ #define REG_SW_PORT_INT_STATUS__1 0x001B #define REG_SW_PORT_INT_MASK__1 0x001F From patchwork Tue Aug 6 13:25:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13754864 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF4F31D2F4E; Tue, 6 Aug 2024 13:28:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722950936; cv=none; b=ivKW+jfFJz586pUDthyeIZlrRtC/y0LnUyN6lrXp23VyCMZjsH9OabVXmIHR27oqWdE2UujJoE78ZMYWskAhfxmBOJE9WKgAQumUWfgoyyukzI3V+RsYIVGoPbXkLLcwk3ocndVjdFPFzyXoFSwKvPE+CY9kUrpiTOBFFBnP/MM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722950936; c=relaxed/simple; bh=Oy5VK+J9SJzFKJSgznA+kp9C9cF+F9I7pfuj42UXu6M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=liFrpEkBB8QskIifBHCKIAkJHE0MlGDzpmahCQ84Lr8kQskKTQNOpNwzLmPSPNyWBZw9S1TI25blHBrEggGUMbiojsKSbsrfiBr1RSoGW3RpQOBmx8J7sgYQFjiAq9VY0zIP6KyeZQNA1a2Tb7hG1GBvdBLhgCKZq8+SGSvjaU4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eIdxqp1N; arc=none smtp.client-ip=209.85.208.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eIdxqp1N" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-5b7b6a30454so1008481a12.2; Tue, 06 Aug 2024 06:28:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722950933; x=1723555733; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=w49WuvPRHENEHIOBXjssOrgW46Ua4jNhfekHObaq3gM=; b=eIdxqp1Nno7bRCkExM1tPO9zw7R5TrjXDK/scjolfVyVquWLkTtBGGDziKkq/MMeDd MH46IPg2hVD2D1n9MJQSjUX95Rfr61Mns6q8mq20JFrXznucPa8G8k3xUgI1RfYAoM5H VgxT1Av8CxK9Br4UFLPGni6JojEOrsJQltVDD9zC9Q8B61xMncDnWISoL1TTczvS1bs2 QcmZIRorHoK645Ks0LiSk4des+W6C49ENFDjrLYlFaMLErq1PofMcYqL0LBsEZMxH5LD lIe4z45jpebnvL61gpmb+dT9m8lLS3ULBhVTzCwkfoHr2eVaOpjWcrRgwZ2wuvLB7W0O KhDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722950933; x=1723555733; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=w49WuvPRHENEHIOBXjssOrgW46Ua4jNhfekHObaq3gM=; b=IZ2S7s4S229sXVXC6lcCmAqCdtz0ZmoghlJ2wp4SSuvCVSoQhQkWItcCyydZA5VfxY xBL7xUqTCfy2xGYDZVxN0Bj0VEz0NqIMQFVzzjOaxjhEnqA0UsCbVkbOg11SBOPyUFHQ ibKIj0V0OCZjNCz/hY/gHn55BmKMgtUVD/n+Fh5tqD0nU/affqC3hQgpkbtGUQF3wbPw qxRwqQ0wIthg08ktRZ0YknjSDlCCSkU/slsq2AA1spdaKsoQzJeVWPbyHk4AR7tmnkc9 auXnMzKekIcOLQVdBv5WlEIH5dZ7J8Q8isLGt0Mpsj91rMJMIr1JIX2f1pZdtfRTgP6q vV7w== X-Forwarded-Encrypted: i=1; AJvYcCWn2qQ5loNHlqp+t8R175kdtFQZR7KovBrxD7jGGmsxa4wGguDYNYmwEk4VPYKH6b9MMWTx3AicN7eIfTzlI6QcQH9yGo1BjfuCWr3d4BM2zbM4enP8JAEqGvak0eUZx/ullTyV6yXd2LThFGO2tpKM6f+h3mtKb+m7tr24K/JqBg== X-Gm-Message-State: AOJu0YwCJiqM5+vrXb6mYaYA1C8hSFyh0bJRrse9o3Rny9EqpbT9Ez31 2uVc8fZL/x+nlXLGDzkgWXFcwzXUSo9NadrOddHsRhJZOCFWE9Qj X-Google-Smtp-Source: AGHT+IGxV+ISuGgORGRSPMwY7Nw46x5tF8+NUOXAr5pk0dni48nHLr/FmB62p3Ie8N8c7CQuNmEZTw== X-Received: by 2002:a05:6402:1244:b0:5a1:225b:4233 with SMTP id 4fb4d7f45d1cf-5b7f531468amr10906863a12.23.1722950932990; Tue, 06 Aug 2024 06:28:52 -0700 (PDT) Received: from lapsy144.cern.ch ([2001:1458:204:1::102:a6a]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5b83a153f77sm5910172a12.53.2024.08.06.06.28.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Aug 2024 06:28:52 -0700 (PDT) From: vtpieter@gmail.com To: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Florian Fainelli , Vladimir Oltean , David S Miller , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Marek Vasut , Russell King Cc: Woojung Huh , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Pieter Van Trappen Subject: [PATCH net-next v3 5/5] net: dsa: microchip: apply KSZ87xx family fixes wrt datasheet Date: Tue, 6 Aug 2024 15:25:57 +0200 Message-ID: <20240806132606.1438953-6-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240806132606.1438953-1-vtpieter@gmail.com> References: <20240806132606.1438953-1-vtpieter@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Patchwork-Delegate: kuba@kernel.org From: Pieter Van Trappen The KSZ87xx switches have 32 entries and not 8. This fixes -ENOSPC errors from ksz8_add_sta_mac when configured as a bridge. Add a new ksz87xx_dev_ops structure to be able to use the ksz_r_mib_stat64 pointer for this family; this corrects a wrong mib->counters cast to ksz88xx_stats_raw. This fixes iproute2 statistics. Signed-off-by: Pieter Van Trappen --- drivers/net/dsa/microchip/ksz_common.c | 47 ++++++++++++++++++++++---- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index c2079e39fbd5..dd141a31b26d 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -312,6 +312,41 @@ static const struct ksz_dev_ops ksz8_dev_ops = { .pme_pwrite8 = ksz8_pme_pwrite8, }; +static const struct ksz_dev_ops ksz87xx_dev_ops = { + .setup = ksz8_setup, + .get_port_addr = ksz8_get_port_addr, + .cfg_port_member = ksz8_cfg_port_member, + .flush_dyn_mac_table = ksz8_flush_dyn_mac_table, + .port_setup = ksz8_port_setup, + .r_phy = ksz8_r_phy, + .w_phy = ksz8_w_phy, + .r_mib_cnt = ksz8_r_mib_cnt, + .r_mib_pkt = ksz8_r_mib_pkt, + .r_mib_stat64 = ksz_r_mib_stats64, + .freeze_mib = ksz8_freeze_mib, + .port_init_cnt = ksz8_port_init_cnt, + .fdb_dump = ksz8_fdb_dump, + .fdb_add = ksz8_fdb_add, + .fdb_del = ksz8_fdb_del, + .mdb_add = ksz8_mdb_add, + .mdb_del = ksz8_mdb_del, + .vlan_filtering = ksz8_port_vlan_filtering, + .vlan_add = ksz8_port_vlan_add, + .vlan_del = ksz8_port_vlan_del, + .mirror_add = ksz8_port_mirror_add, + .mirror_del = ksz8_port_mirror_del, + .get_caps = ksz8_get_caps, + .config_cpu_port = ksz8_config_cpu_port, + .enable_stp_addr = ksz8_enable_stp_addr, + .reset = ksz8_reset_switch, + .init = ksz8_switch_init, + .exit = ksz8_switch_exit, + .change_mtu = ksz8_change_mtu, + .pme_write8 = ksz8_pme_write8, + .pme_pread8 = ksz8_pme_pread8, + .pme_pwrite8 = ksz8_pme_pwrite8, +}; + static void ksz9477_phylink_mac_link_up(struct phylink_config *config, struct phy_device *phydev, unsigned int mode, @@ -1262,12 +1297,12 @@ const struct ksz_chip_data ksz_switch_chips[] = { .dev_name = "KSZ8795", .num_vlans = 4096, .num_alus = 0, - .num_statics = 8, + .num_statics = 32, .cpu_ports = 0x10, /* can be configured as cpu port */ .port_cnt = 5, /* total cpu and user ports */ .num_tx_queues = 4, .num_ipms = 4, - .ops = &ksz8_dev_ops, + .ops = &ksz87xx_dev_ops, .phylink_mac_ops = &ksz8_phylink_mac_ops, .ksz87xx_eee_link_erratum = true, .mib_names = ksz9477_mib_names, @@ -1303,12 +1338,12 @@ const struct ksz_chip_data ksz_switch_chips[] = { .dev_name = "KSZ8794", .num_vlans = 4096, .num_alus = 0, - .num_statics = 8, + .num_statics = 32, .cpu_ports = 0x10, /* can be configured as cpu port */ .port_cnt = 5, /* total cpu and user ports */ .num_tx_queues = 4, .num_ipms = 4, - .ops = &ksz8_dev_ops, + .ops = &ksz87xx_dev_ops, .phylink_mac_ops = &ksz8_phylink_mac_ops, .ksz87xx_eee_link_erratum = true, .mib_names = ksz9477_mib_names, @@ -1330,12 +1365,12 @@ const struct ksz_chip_data ksz_switch_chips[] = { .dev_name = "KSZ8765", .num_vlans = 4096, .num_alus = 0, - .num_statics = 8, + .num_statics = 32, .cpu_ports = 0x10, /* can be configured as cpu port */ .port_cnt = 5, /* total cpu and user ports */ .num_tx_queues = 4, .num_ipms = 4, - .ops = &ksz8_dev_ops, + .ops = &ksz87xx_dev_ops, .phylink_mac_ops = &ksz8_phylink_mac_ops, .ksz87xx_eee_link_erratum = true, .mib_names = ksz9477_mib_names,