From patchwork Mon Aug 12 08:49:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13760309 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 6232A14C5AA; Mon, 12 Aug 2024 08:51:00 +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=1723452662; cv=none; b=da1COSA1wUNWiR1b7x6zJeSmhEfx4vdlW2tJnu0l/eiqMoo33O61rDWwWtZfmxzaTPgLoqTPHFYPLe/yJfY5hD8/2bYAiTMu+Qkvr9GMTqQsU7ckS+MEvIbA6/UDWvy6fq2kx334Y5k9TI7gqqnzeZnvOju9OfumO55Z5KCa9B0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723452662; c=relaxed/simple; bh=MNnLV25K6YhULXYYlXhNI0BKUG+LUYqABdwm34GgDDM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e7QgFAk1rql0Bb89khRB2gne0dx/npuJ2s5AluMcqOCMwNuwOHUjp/hF8Un+7TxYXpCBVqQVqWjhpz0OIqw5Ao4NwND2aoP1ScLVdvb2PCI3jYvoQOlpSEAXxpbtQO+v1Kj/r4O0wBJol5pc33PpfUXMBYRPOqQAhE7NRmthbvY= 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=YqFiQLgO; 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="YqFiQLgO" Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-5a156556fb4so4689013a12.3; Mon, 12 Aug 2024 01:51:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723452659; x=1724057459; 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=YqFiQLgOla/ZOeWkRIfZaxnI5Zz91yhVPWFu/DFK6NetJQbs1i813NeS00hiPb7K8d 6TEgTbJOkdOL69OnJ8JD9nz+QpInqTSNoqYYOc/Vg4jfNpqsDsL2EAMVJ1+Pbqd022JL Ma5gwAaUozdz0dc7pf4Pw8YxbXu913lUMKEPOmCgtXm+G3mgEx0XG/JbLh5+RDVGQNW+ IbwmM8jBgqO5KKjQURwTdzKvGwRuJkiVqzsw+fozaPPNNgGivag9MhqULRyCBzCZs+Zz p44Gn1Ki+fcvhiqt88nTdTThhYiPhSDYv0SPSQAzcO415V1qFLbArVonDmM1G9msZ9Xu W3Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723452659; x=1724057459; 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=EtPdhyGz0VIXK0l9iWAvALTuDPMIKSsAiFg9t9zqIzoBg36j5Ibnp1Ek3UhlV/Wbao FiDUA+0x1IBFm4m4XTUEBn1ulprLpezVnaIvCfFcRAx6GLuYobpsR/QThIo8wDLp6zLa J/YaMpZ2F8FxMkanWVR/EbC5FH+JLVNxuLCnPvI8+4YUE8e3RvZd3wUVSn+DcHfl/0fi suaD6lwMzkX9eG+4YN+eERfXxwgz8oIp8aOWqsdjZC7HbA0eaVlH3xszuZhqj1uwLsIr 3a1/m0o+1tyv3dRWAMD4xFnU6UOYQUJIiMC4LCXW68Xr6N0LPRuUrFa+EwJkOi0k6Lf/ jL0Q== X-Forwarded-Encrypted: i=1; AJvYcCWGTddkcsn5CVexk4CXSHrhMLChGC1eYVwmrGwatdTH2GPA2/bxF0IfurKc/uMBoffSwVYj4eXb2pVLF5c1V3fv4u0Y9GpJl5Q/LQKavME3Z4/QWuYix98jiIPmetmb7FERxYEMruDZQMgiM0btw4rvyAWWsyEbvRpU8ldmFbU9zg== X-Gm-Message-State: AOJu0YwNgsQgr0rLAcEN2X7PFl3wHbn5qOU3PA6u9C5ToZlF75odKjwZ imHGc6wdIYQ9+YcOrbRWnGgl8W9Bder19aLl+H4puy6WGN/5Dco6 X-Google-Smtp-Source: AGHT+IHLCVOMzv0vEY/GpKmVn04Peavjh3TrqrMdmstDm6b5xf6DXYMu/Lh318dEPLgfAAsXTntZ4A== X-Received: by 2002:a05:6402:1d52:b0:5a2:c1b1:4cc with SMTP id 4fb4d7f45d1cf-5bd0a617c06mr6709406a12.26.1723452658153; Mon, 12 Aug 2024 01:50:58 -0700 (PDT) Received: from lapsy144.cern.ch (lapsy144.ipv6.cern.ch. [2001:1458:202:99::100:4b]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bd187f517dsm2094761a12.4.2024.08.12.01.50.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 01:50:57 -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 v4 1/5] dt-bindings: net: dsa: microchip: add microchip,pme-active-high flag Date: Mon, 12 Aug 2024 10:49:32 +0200 Message-ID: <20240812084945.578993-2-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812084945.578993-1-vtpieter@gmail.com> References: <20240812084945.578993-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 Mon Aug 12 08:49:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13760310 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f41.google.com (mail-ej1-f41.google.com [209.85.218.41]) (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 CDE0314C5AA; Mon, 12 Aug 2024 08:51:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723452667; cv=none; b=YE0ZN6wmYifp2JS8ndZ6Iicil8inLf6gzKHWBilbqS+NEn/KB0yPteX7UKAC2bL5vYHg8YUhCdUtjdhf2MFrLFAy/p6Ymo9B44pomjbsgQmbWXbOPEspWEvyp3oEiQWRgKvR0NmJEHePd1Fk673Yg968EJwDMs6unMO1D9UNr6A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723452667; c=relaxed/simple; bh=cI6omaOq9q4KhDAhVFNb9BhAcM5gxFkHis/LHpaLAfM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DwYe74YlO7GvrwRvQx9iKkuu8Cxh5qozuUKdhQ3k7sPYCFWBoCtG64ieg81eTDJtS6wMQ5MJ9xagiZya3eVWDP5XO8sSw2KwjPYKfMVQY7MBSrvp336PRjc5xi6OkTgeLdTUhcBOCzjogxpAw5T6g27qS95/zg7Hlv9TlWWISvY= 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=JLRJx7j5; arc=none smtp.client-ip=209.85.218.41 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="JLRJx7j5" Received: by mail-ej1-f41.google.com with SMTP id a640c23a62f3a-a80ea7084e9so2284466b.0; Mon, 12 Aug 2024 01:51:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723452664; x=1724057464; 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=QtypSQS+aXP13D2w8C4F/ewwCPIeElIJUsVeuF/Dd8g=; b=JLRJx7j56K6cx/dfLZYZ3H0yms7vvzm8Ad1xrY8R2Rw3qWieAz0X/FdNMHfCJI67f8 OO6X0YiZLHNIgRWVH55tNJBJiKaLbNAokzgmc7StSpuI+oen6WIG/5YBpvXDMl4AVgoN Ya9gZ6izrPyiKl5mUbePd8dNwJsoYr1zC4fH5eiB4iwBKWEWp1ODJHTPs+Ixv788yXkc 4x4BbK/icZsdWhpFkobCkJepjdTRl2X2W+W7aNa2n1uCbrd08k29XV4VBdTq7GlgoMs0 aaSxEkSFIAHSiVeTPBy4sznnEtk3ui89N1Z1mi6I9bLKyeTrCoLlqpWBIjGgU1EeieqP lxnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723452664; x=1724057464; 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=QtypSQS+aXP13D2w8C4F/ewwCPIeElIJUsVeuF/Dd8g=; b=n1/phh5Ghk7yJBDnLPZcNH6HQKSqyq+Sti5cx2g9OCTrSe/i04r0NpBp6OkMwGmz5g zA1c/Kn3l1Hr5Q1NngsZoIeGyPwiS/awWDRT4l0+DKTb755EyxU5wn3p1FzvzkH4m4v+ SQx2Kvw7MnQR2xxrnC6iGB2tn4/994wJGkhGA2Z0bcriZLCQSMSByC7PwQBXwQQ44uFq 2bZ6TzRK/RuLm5CQg2P3SfJE7uYJmrBN39dMe17dh4kg+5w1dB6vZqdWn7WVXWG6jjWD ct5EdTEz2E85gaIdGuleMgc3zSFHFCtMQK0YXIvqJjOkhdGCRTX2EMpRJoHG9r0F0OBK lFuQ== X-Forwarded-Encrypted: i=1; AJvYcCVgs4CooJE3jtcQahci1j4Efo9KrS/c6Mr6nfOZosVkcro8Oza4owI0XBv3SLideUXfInXvmzPwt5AWOg67y+Y0kzj1xymISrg5Kobv32aPRKz7MbWjIUv527l5chiIOWgy3/curGb3xJSaXxcbNUJ16ENBLh+MTA/DdaXVEz9GzQ== X-Gm-Message-State: AOJu0Yy4Rs8ZRpabc0MhEIzQ+pq9kXCnu0QNKDbDFBUIqK6b3JH7OdKm J0nqWw255PyIpSGvJDdhuIPRlh/H7PzMGMuHAzn4SObgdXgFRkVw X-Google-Smtp-Source: AGHT+IGMgJOsI+kMgIJFHgsys+4N5gJ/RJrOCHPbWhrRDxHLMFF3dapiPf2Tol0BoTzptJu9eBMGyA== X-Received: by 2002:a05:6402:2750:b0:5a3:8077:3c90 with SMTP id 4fb4d7f45d1cf-5bd0a645599mr8636761a12.33.1723452664006; Mon, 12 Aug 2024 01:51:04 -0700 (PDT) Received: from lapsy144.cern.ch (lapsy144.ipv6.cern.ch. [2001:1458:202:99::100:4b]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bd187f517dsm2094761a12.4.2024.08.12.01.51.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 01:51:03 -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 , Arun Ramadoss Subject: [PATCH net-next v4 2/5] net: dsa: microchip: move KSZ9477 WoL functions to ksz_common Date: Mon, 12 Aug 2024 10:49:33 +0200 Message-ID: <20240812084945.578993-3-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812084945.578993-1-vtpieter@gmail.com> References: <20240812084945.578993-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 1e2293aa00dc..4defa7c03176 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 1491099528be..7afe958d0e21 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -3751,6 +3751,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) { @@ -3762,6 +3833,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 Mon Aug 12 08:49:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13760311 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (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 A415316D9BB; Mon, 12 Aug 2024 08:51:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723452673; cv=none; b=r+AkMAq44bkU4wu8f2tvYC3g6vPjN0WSWp/ifeO+Ca54OyQ1kMLEWo6E/D18fjFxXXJEPhdw1nk5Jz+puTXpeVjfwJbZzSj90Q+HkBAENVZsnNOnvXptWuIPs8rcg37JPHH1S+GJGe6hOKJoWt2/9LGy248LLxEce/bAVC26d6o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723452673; c=relaxed/simple; bh=yVbLiwXp3y3vlxhRVcrg1Am12yF0nslL3Naf9OUa0cg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DkQ4mANRNfChxld6s4k/xhRnkn9KuXYIhXZQ14DZidoQbW2jjX3qvcQXVY0rHNU64klzO3wM2azEnFed8nPZdJ/gldlVUCst4z8xlXSCPHiykOefkDK8dbVR/Ca+DovtEDsn6woMBn6yhU2IA5FeHGn0uYazlxOQi/rWGVrnew4= 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=FCNDMpiy; arc=none smtp.client-ip=209.85.208.41 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="FCNDMpiy" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5af6a1afa63so4762086a12.0; Mon, 12 Aug 2024 01:51:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723452670; x=1724057470; 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=WAqVEaOgKR65yWeYLOQFhIc3DZnyI4OyFbvhtsEiZV0=; b=FCNDMpiys1Yt9ti0xHiRWnyqWGBO6Ez1aEo8hqW1ZqZRHh4c5Upf00RT+Xgk65VPcZ HzNkQZThVzfKVfy9IAmQ8vX9PtcqVVF3xQaGf7SiFqZiDKVTvOCvSNKclfCIdYwRqqgD ZGUfPZe9TturIjhANYpAJZLhJWv01PwyAOVhExNPS1MDLTdhWgFosy832NQjXwnnrvjO 7iBDATG6xN0SIdyuNVXateCEf1X/blSsILx4+sHWtihYMy02WsSiwc0s2cUeTIjTcCWv rRahBRZKv8KgzeSxXg3JpYnMrNxwep7adZE0xRTf0t8wGb/hJEmMr6Nid1kb5GSFl7Rr dKUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723452670; x=1724057470; 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=WAqVEaOgKR65yWeYLOQFhIc3DZnyI4OyFbvhtsEiZV0=; b=lTdR+WM4ohh+PcNOcbGULWLw2NG2DAeQ1baUVt3u0oaHl1I0/UYnua1PsMUhEmv3ii s4+ag1nui9OZeP0h7x218Pwk7Q4ZhGZbM/+NFx+/cmJcnMFAGXX6byFgXYbuFjbfkdgt BthMp9yiOs2opRlM0Yh7lUl2RA02Mks4S6EBI00iiO3HAQALcjhJiHbfrotG+c4oWVcd L29RLrbPgFWWbe0YT7oeeHV5fajkkgJVUFH3KcWvB/qm8FYiMpvoG55pHE3IuxdCmdzQ LweNFbsq9RNXsJi2KJw/ZD7Fnm8cxhPLELpLD4UemFU91dvxDAiETU/guxX5PtBQhNnp as+Q== X-Forwarded-Encrypted: i=1; AJvYcCUkCkqB3jE4ij4T7H50/YkcWRIJlCnQ2GBm/m6HYnfoKJ1erFYBuFLOKbS+GBWxgvHc7oF7wSHJmmxzzrfYyzR+EY3Yv4oJkush3cdJCybfFW2401D0BRyx6kF+i1hDkH2ftdVfRyvdabxNvd3nbRg87iuGh4IjnWy4MokE2h4VWQ== X-Gm-Message-State: AOJu0Yy3/Q1bJlrD+5j6KCgZCY4Ufh7IQGMfmtO6UH2qOROmunbMwNrj ATJxJ1S4UVGslc0JIU75sk2/AauYhR4ruqxEfIm2oJ0fzurNt4JA X-Google-Smtp-Source: AGHT+IFsJYPOcuI9ydZlawcyXDRr+gzVVU6hupBESisC03Reo7S1FXKAvetY+JSNWP8Ka/in0CtA5w== X-Received: by 2002:a05:6402:2708:b0:5a3:5218:5d80 with SMTP id 4fb4d7f45d1cf-5bd0a5f9e5emr6587249a12.21.1723452669805; Mon, 12 Aug 2024 01:51:09 -0700 (PDT) Received: from lapsy144.cern.ch (lapsy144.ipv6.cern.ch. [2001:1458:202:99::100:4b]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bd187f517dsm2094761a12.4.2024.08.12.01.51.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 01:51:09 -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 , Arun Ramadoss Subject: [PATCH net-next v4 3/5] net: dsa: microchip: generalize KSZ9477 WoL functions at ksz_common Date: Mon, 12 Aug 2024 10:49:34 +0200 Message-ID: <20240812084945.578993-4-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812084945.578993-1-vtpieter@gmail.com> References: <20240812084945.578993-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 4defa7c03176..741b4f2dd8d2 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -1024,6 +1024,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; @@ -1068,12 +1069,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) @@ -1170,6 +1171,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; @@ -1200,13 +1202,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 7afe958d0e21..e2a9a652c41a 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[] = { @@ -3742,17 +3745,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. * @@ -3764,12 +3758,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; @@ -3781,25 +3778,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; @@ -3812,7 +3815,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; @@ -3822,35 +3826,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; @@ -3858,10 +3853,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; @@ -3870,7 +3868,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; @@ -3893,7 +3892,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); @@ -3904,8 +3904,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. @@ -3915,32 +3915,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, @@ -4253,8 +4259,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 Mon Aug 12 08:49:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13760312 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) (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 6E27316D9D1; Mon, 12 Aug 2024 08:51:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723452678; cv=none; b=hNe9dTrbV/E95vd7FtD8YoO5frhA2YXIky8NHDPiBc6KehSFd6wn2mlNf+LCOjlQgPfiUFUaShMUVSmKdXE90lmfkGHCKPznUZCX1qfHCAgUhzZwfw/OQnPyK5NbZS/00P6Ceqqhwu7/jvDfO+Mazdr1xXSSQT2oF/U6LlHG7QY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723452678; c=relaxed/simple; bh=rNmG89Qy5miNahIWpw0H5nE3pPDUeZUveZPrzbbdAEw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dugN8SZJA4w5dB699/CVDMhX/lvc6J6EJXQVLanoBsmZP4TmQAgWhDM+D56fcx94NitijhGtsm72b8/6GYdprNixoiH2x63bY+6wkm6ctpH4nGxQXpNO5Gk56Tm3dC1MQO6c7AV/3Oaw7HK8gtddpz0rDtMd8/Y7ZYW4NfL2VEU= 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=iniYRbqm; arc=none smtp.client-ip=209.85.208.44 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="iniYRbqm" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-5a15692b6f6so4547788a12.0; Mon, 12 Aug 2024 01:51:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723452675; x=1724057475; 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=OR5cwr8eMtysOo82K3MmrFLWUZvfDE7Pm1Jb07nDi3g=; b=iniYRbqmyxiCx04dsgCAu3G+bKGw9lAmivJk5Qv8ZtBAOgSM0F6c1yAixSYd2u2va5 GKYXEsCZ+n4ivvQ6oFzzEUajmusIhcvvfcsnfSb2GzCnPnpS+QlVOEp2rDnTHtH30RPV qVswhzdh8cJasHsHs8I/7xLQz/Sha+QllS5PBZYLeALOeRUbWTbR6GDVvRcEs4FihHE7 JXM1XGsSo7Nu/JLvvg/OOnHfeTh+AZvwmWoY+GbIJCTInd3yPMYB3wWWOBEyha76Xasl hZTwM4D7yLaSFGMHE7lknZO1+IhHSM8GqxUma0/4jy6hjNuCbN2Bml8NzG4K77NlLz/I DF5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723452675; x=1724057475; 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=OR5cwr8eMtysOo82K3MmrFLWUZvfDE7Pm1Jb07nDi3g=; b=e+4sV1uuyKhPiUPssMGbavj0yfEZL2wGExJcUam0xKVX9m0r4QehYSYxQPO6NTbAfd 9/9g+TI2ITNBv2/wXM7oygQcCwM6RnCJ2zfsyHsseQuAwYB+QXYRrZun2fvAqPeioIUp Jcr+r4iFE0yjZc5V3gpFdEF+Po2TiKZjHCnWVvx/NZZBOb0DC+OGK4SIYir+TLmV+n3a CKUMfX1v9/qmH9v0wj4I1PtFOBztEG/XenlNvfqGcX+uou4ubeRUwR5X6LRWtbnw+Ver s/m0OJOLhUQPVjQQ5kat9Tby0kIfjyyOtJ/vgZHmdxcDM6CO9ix/UWKnO4+dx4BSLzAC /anQ== X-Forwarded-Encrypted: i=1; AJvYcCU7S04EamURGxVqHmW1zBf3jHBssVDOdxobGpEhZOGVUum6NMPpog/CmxHmoKhXnzo8Z6+yiheKkzcUCpwtL6mfwdq2S1VWmiRSPDEk4syeVkyeKhy+/1NrnVpEuBZasJnwKsQO4awHuA2a7aVC+1xhDVOW2aXsbUCqfm+Y2pqBWQ== X-Gm-Message-State: AOJu0YwIXMqOHS4L1K++VSWbeaxCCswhNZOYtHAQ/iCFuOe5UMrG1Vsg UOS4A+SfYcoZ9etE0aQcQ3KbQovkgZioRrS0Q+fxyiHa1gOQefTJ X-Google-Smtp-Source: AGHT+IFBUKW48uMte9U0qyq2g6BIwrUOzGzJBd0uAvpe8Bfd6nc5pgs2EniLxh29YWRcR4iYLqwkig== X-Received: by 2002:a05:6402:274a:b0:5a1:c496:2447 with SMTP id 4fb4d7f45d1cf-5bd0a598098mr6680686a12.21.1723452674278; Mon, 12 Aug 2024 01:51:14 -0700 (PDT) Received: from lapsy144.cern.ch (lapsy144.ipv6.cern.ch. [2001:1458:202:99::100:4b]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bd187f517dsm2094761a12.4.2024.08.12.01.51.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 01:51:13 -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 v4 4/5] net: dsa: microchip: add WoL support for KSZ87xx family Date: Mon, 12 Aug 2024 10:49:35 +0200 Message-ID: <20240812084945.578993-5-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812084945.578993-1-vtpieter@gmail.com> References: <20240812084945.578993-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 Acked-by: Arun Ramadoss --- 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 | 6 +- 4 files changed, 119 insertions(+), 8 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 e2a9a652c41a..3f3230d181d8 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[] = { @@ -3800,7 +3806,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) @@ -3853,7 +3859,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) @@ -3919,12 +3925,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) @@ -3945,8 +3952,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, KSZ87XX_REG_INT_EN, KSZ87XX_INT_PME_MASK); + } } static int ksz_port_set_mac_address(struct dsa_switch *ds, int port, @@ -4661,6 +4673,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..8094d90d6ca4 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; @@ -704,7 +705,7 @@ 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 */ +/* KSZ9477, KSZ87xx Wake-on-LAN (WoL) masks */ #define PME_WOL_MAGICPKT BIT(2) #define PME_WOL_LINKUP BIT(1) #define PME_WOL_ENERGY BIT(0) @@ -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 KSZ87XX_REG_INT_EN 0x7D +#define KSZ87XX_INT_PME_MASK BIT(4) + /* Interrupt */ #define REG_SW_PORT_INT_STATUS__1 0x001B #define REG_SW_PORT_INT_MASK__1 0x001F From patchwork Mon Aug 12 08:49:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13760313 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f47.google.com (mail-ed1-f47.google.com [209.85.208.47]) (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 6193616DEAA; Mon, 12 Aug 2024 08:51:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723452684; cv=none; b=MEPHthlhc7XH/YK4YpNO7b5wZ5C5wCrIe5MMcHlF+lP+uOs2IYMS+2JWg/x3VNgnOjwJzg8iVf+bRVoYgbzi89qGJEtm0Ol5HkIXuBoC81n0oDOV9Y8lxrTIqbV5GkXJhtG4A3tgcqFRiuO2THhnVKMjVCQx1T3WHy9yQpQDkvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723452684; c=relaxed/simple; bh=nFEnDoSdVTo4lzMLYHEaOnWJFN+6tarTe+JLia11nOE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NJSVuuAuM/f2MzTGcJ0hzpJnAldE5e50wdMm7FpOnqlteQcqMy8L02y/TZgi1EQttXMKIjZoZS+0JtxmVvKwioX/5KFtNaJ5JiuIIBl57h/hAPB5+rpDmEWrCYn7lPkMDd13yv+1aRcRO15c3mAUG+e6IXo9c1TiGLb65qN8lDg= 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=JH4HDJdA; arc=none smtp.client-ip=209.85.208.47 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="JH4HDJdA" Received: by mail-ed1-f47.google.com with SMTP id 4fb4d7f45d1cf-5bba25c1e15so4884888a12.2; Mon, 12 Aug 2024 01:51:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723452681; x=1724057481; 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=mCfmZ4fWtBZIWANIT9oaDcYlZvEgthqm6GmK6t7+ids=; b=JH4HDJdAN0L4EAhZg0+IwBaPauwRAlhQ67TO0Fe1KL8AJmGc+38e8uTpTGgtbz6nKh +GBq9e0xjroW8Du2uBrARb9GGOeaESJZqXUky8OEpSein6iiU/D2EBJCUNVNrus5q5lQ QDLhizGfqxVVK2Pjm6VKcRd/pL3wRF5xXxv0tkQOFM2YMXe50z5fHXxQi3xqXovToaGj Bd3rdq30y6pJXA8GAqf5v+OHqtPdpalX8nuBa3YnhNdflDibYE8bwQlk88CDaTJfNZPb +TfnB66UMVSojIw7gjnH687RIr4ocXrqv5butCs9nddgnnRDlauQdwriNv0Hbi5RNQPo K8tQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723452681; x=1724057481; 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=mCfmZ4fWtBZIWANIT9oaDcYlZvEgthqm6GmK6t7+ids=; b=mqgdBOZXwlSHPFM2erwe0fRBm71StMn5WdTq0b/RgH3ieUOuDVuLCUKRPpXUiRGBh8 uiMvFkcwCNEtS/cwe6zxtGgPuBrmRDe06rRY+HheI+cy2Bs/LLGiSTzoU7BAXi9Un+D0 s5OcB7HPLFQthrkH5fQT7zQ4xCFDr4yscITHpsXjyRbnDI9IPZpJZFpzojpt6CiWy4Wo TJUlnsRh1nj31wth950yGx2W3GUwcfi/q+TqRW0mLkGRScdb6ywAap4/bpkD0HRmt/2o TlhnLpEARrk2abzJ6A4wa72eP+6jPbH/93MXL+I7lTGLa/70txSUEQrC2dTvOoXNPsq7 5UCA== X-Forwarded-Encrypted: i=1; AJvYcCXdh8rHs8fSCDcHo1N8gm5vshXkiL6OiGhl1rvNd2hcmGsJHRzmU2CAklb8/nzZCZtNowGRmypI6hDlVotRroL1K3cRUiPpLYDVAZkUvdui9N1LXullbCQ+/7BFuWh1rGGFpnXR5fsi8p6tVz1wMYdfUeLMiAvMMC2HZ+mdMPLbUA== X-Gm-Message-State: AOJu0YzMbdPLdkxKYL2ODcSStxCu7dAwxzyg1LCH98d8ODApfJemZS+5 7PMDIuhqQ70nbguUoSTWthgF1Pk89ymOeClnJ6ayrAzwiHL49Ezc X-Google-Smtp-Source: AGHT+IGp6x2YaGrS4Z1BAvHuDLKBmlWiI5u/tEqLJZOWYC1JTJQJ40uHnZLg9oYh/SIQIIAVUE8EiA== X-Received: by 2002:a05:6402:90e:b0:59e:65d1:a56b with SMTP id 4fb4d7f45d1cf-5bd0a6668camr7573182a12.34.1723452680593; Mon, 12 Aug 2024 01:51:20 -0700 (PDT) Received: from lapsy144.cern.ch (lapsy144.ipv6.cern.ch. [2001:1458:202:99::100:4b]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5bd187f517dsm2094761a12.4.2024.08.12.01.51.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 01:51:20 -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 v4 5/5] net: dsa: microchip: apply KSZ87xx family fixes wrt datasheet Date: Mon, 12 Aug 2024 10:49:36 +0200 Message-ID: <20240812084945.578993-6-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812084945.578993-1-vtpieter@gmail.com> References: <20240812084945.578993-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 static MAC address table entries and not 8. This fixes -ENOSPC non-critical 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. Rename ksz8_dev_ops structure to ksz88x3_dev_ops, in line with ksz_is_* naming conventions from ksz_common.h. Fix the tag_ksz egress mask, the port is encoded in the two and not three LSB. This fix is for completeness, bit 2 must be 0 in most if not all cases because it works without it for the KSZ8794. Signed-off-by: Pieter Van Trappen --- drivers/net/dsa/microchip/ksz_common.c | 51 ++++++++++++++++++++++---- net/dsa/tag_ksz.c | 2 +- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 3f3230d181d8..cd3991792b69 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -277,7 +277,7 @@ static const struct phylink_mac_ops ksz8_phylink_mac_ops = { .mac_link_up = ksz8_phylink_mac_link_up, }; -static const struct ksz_dev_ops ksz8_dev_ops = { +static const struct ksz_dev_ops ksz88x3_dev_ops = { .setup = ksz8_setup, .get_port_addr = ksz8_get_port_addr, .cfg_port_member = ksz8_cfg_port_member, @@ -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, @@ -1362,7 +1397,7 @@ const struct ksz_chip_data ksz_switch_chips[] = { .port_cnt = 3, .num_tx_queues = 4, .num_ipms = 4, - .ops = &ksz8_dev_ops, + .ops = &ksz88x3_dev_ops, .phylink_mac_ops = &ksz8830_phylink_mac_ops, .mib_names = ksz88xx_mib_names, .mib_cnt = ARRAY_SIZE(ksz88xx_mib_names), diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c index ee7b272ab715..a0f9965de027 100644 --- a/net/dsa/tag_ksz.c +++ b/net/dsa/tag_ksz.c @@ -141,7 +141,7 @@ static struct sk_buff *ksz8795_rcv(struct sk_buff *skb, struct net_device *dev) { u8 *tag = skb_tail_pointer(skb) - KSZ_EGRESS_TAG_LEN; - return ksz_common_rcv(skb, dev, tag[0] & 7, KSZ_EGRESS_TAG_LEN); + return ksz_common_rcv(skb, dev, tag[0] & 3, KSZ_EGRESS_TAG_LEN); } static const struct dsa_device_ops ksz8795_netdev_ops = {