From patchwork Wed Jul 31 10:33:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13748441 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 DB0391A8C02; Wed, 31 Jul 2024 10:34:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722422064; cv=none; b=M1ob4B5YnsBT95ZiBw7GqXK70NbdaV1pOnzq9RoEs6Y4i/g2BzLmII2E+oFr1m+IgOoQQ6ZI6H+WiLhk19jigpgE2hxSQPItYdR/fTTALrrjxxszdfXxI1/3JOZOGQ5RTLfgVPc1/l0zBDilC9Korv3uzPk2p0yT5SuurFdNgJI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722422064; c=relaxed/simple; bh=MNnLV25K6YhULXYYlXhNI0BKUG+LUYqABdwm34GgDDM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VYhU5ebSFNc/TJ98UxXljC7RfMyL3EqOqAmMqbAJQwjnUDzmTzy+bCwISxKjncQMOBWI2CrKLc4CuBkgKR8t2NaUINvgEVRF2XE35Z8m2YQHRAedUhtyWkc+FDCNocS8N3QyxV3CTyca+TXnpSZ/HGThHWSHLDJW/oEw8BTI4eo= 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=jYfjLDQ7; arc=none smtp.client-ip=209.85.218.54 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="jYfjLDQ7" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a7a9e25008aso735473466b.0; Wed, 31 Jul 2024 03:34:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722422061; x=1723026861; 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=jYfjLDQ7qKOAEw4ElEf+oOMHNTqC4MfWkaCcNhsNXxEVk0qcNRy69TnA+A5fCt4gdO eNrtwZ9A/2XEbi7hwkRwpGV6w6i+5A+ZzP8eQpYM5TqkrNsu/ZORJpuu1mr/9WavfiGN XUXZGryjTxQcG/zqt8YFoAxlpaQYBgnLFxipN+Cq2aw+WCWriVxywo8GeYDu+YgWFFmr ejKoWM2cWDM8pY0uW3PTnHQQirBOjuHLCzy+K4xx3QbA9gL1rivaKZXSEZTzQZ97yv+3 oDLCb32i38Xtion9gGiiEWKrc/ljbtzuSyz2RoOzh4URT1W0oX0p7uQ6TNYXFOByFN0q nWmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722422061; x=1723026861; 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=jkkhrTXl6k6GrweKd2CdHRyUK7K2rImh7xh6N5SvtF5YBORgp+hCjFZnooheeiaamh c3Xx1MX8svNCq3RYVDfC0m0w7KeNuVFmRrW1SgRLLPwbFEd/K7BnglMOW0ann1fzmrfM eTB0hi+KS6C8vZDMfmA0CkMnh7qXH/Z9ERnnpnH9YgnsMQwUE6P3O4GnKpUy6uZKNMiy /8RxPg6g6TtpG8uCJeZ92iKMQoDLJMIY+PlIkoEz5mHPeOkWhJxNJbr+Hd/a0d9MRLlH fSUElZYqSCpsmqQTVj5udpD9tShx8CmBpaoYb68RaLOXJBwnEuE2rR6gj3FHegQ28xmN cycQ== X-Forwarded-Encrypted: i=1; AJvYcCWbgB5PFxqN38dp8+zaXDclL3WyD7EkrhbmPmRZCGjLxk+i0dLHXQKqI5f1U7po6JDZg8fCA6h0pEraLrk78xMAtPt6ENzk X-Gm-Message-State: AOJu0YxzaTPCshmvL77PLOlqtXpMG09DRd6un6fAn3lM2DI8l/1dqBSQ edACwJdbXS/qVvPTkqeBem3NOsUWGOhTjB7VqcIcGRlQ332KvAYW1zrbEr1kN50= X-Google-Smtp-Source: AGHT+IEtZ6tfEm94p6eOzRNSJdNYUZJex2SG/sBK5ogFhgi92f77rWYUDdkelf/mNPiEkDTIfZkjLQ== X-Received: by 2002:a17:906:dc95:b0:a7a:ae85:f245 with SMTP id a640c23a62f3a-a7d400e1eddmr989629366b.38.1722422060867; Wed, 31 Jul 2024 03:34: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 a640c23a62f3a-a7acadb807dsm751930766b.201.2024.07.31.03.34.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jul 2024 03:34:20 -0700 (PDT) From: vtpieter@gmail.com To: devicetree@vger.kernel.org, woojung.huh@microchip.com, UNGLinuxDriver@microchip.com, netdev@vger.kernel.org Cc: o.rempel@pengutronix.de, Pieter Van Trappen , Rob Herring Subject: [PATCH net-next v2 1/5] dt-bindings: net: dsa: microchip: add microchip,pme-active-high flag Date: Wed, 31 Jul 2024 12:33:59 +0200 Message-ID: <20240731103403.407818-2-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240731103403.407818-1-vtpieter@gmail.com> References: <20240731103403.407818-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 Wed Jul 31 10:34:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13748442 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f51.google.com (mail-ej1-f51.google.com [209.85.218.51]) (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 8CFC11AC429; Wed, 31 Jul 2024 10:34:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722422065; cv=none; b=ov/CFFFJk0wB8n1seroO3XaUlXTaDiGV7xOOgokdv9YhDDDuZpV9AUsbRov1mE7g5JFfQ4t7+9vSa7WTOc9ltUDvYmiNOZ0KD7T/6q5bad7TAnnRdhEZIROO1sk8c4j4rz+Ay5SNDEJ72dbPniMJbwBzXqv9AJDwVmFqWkAHOKU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722422065; c=relaxed/simple; bh=njutdzAmXk9uHToXKqCBo2PRfv8kPIV7SO0dqnHd/Rs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NqGr5vmcqpklnnbZO7MODShi+efC4DzD6vB2eKL4Ve38kJtICyHK2RhJdulVXR638QnDH+Ysv92TQjx/fV9FktOskE2RICio8ytNdbJwMHE5bOFyRVaqBfXoRe6F/vm+AaKVlNGIHJDyz9OuBcyBHf9o3voogx/bJPivBjs6pgc= 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=e4Au/2/W; arc=none smtp.client-ip=209.85.218.51 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="e4Au/2/W" Received: by mail-ej1-f51.google.com with SMTP id a640c23a62f3a-a7aa4ca9d72so700737966b.0; Wed, 31 Jul 2024 03:34:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722422062; x=1723026862; 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=N7kFiZURtEQ2k6BXwI0rXSHgwvGZFX9E3/aYRIy4da8=; b=e4Au/2/WKqgxy32rYGjqWuK3TdOvSYGVA7W09PI9VOjgUOQZbJ0SObaRfSWo0Pwt/5 LIimGzwraYeZZwa+UNd9cQD8m0TCNPl5fCDKcPDJxiKjT0B9Lr76VidcUj2bAPzyfpOz Up1wA/29Er/xinTGWXgreBFGfLf3jCZMpRKzsuLfAymZiV41WKbCPrWM00g46AM6zrdp fkALRsa94Gbg/BuQ+0m5RW8ZPSCR952rTvxDKqWzM8qP6hurQ80b6rMB80RlLIG0orjP uP6S5eax1wZFFq7Apuv1TEfzkRgIIYWu4ms1fSoQiXUn8/R6MEc9wZKQcmvAVJ9yYBfF 96SQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722422062; x=1723026862; 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=N7kFiZURtEQ2k6BXwI0rXSHgwvGZFX9E3/aYRIy4da8=; b=Jn52eItwlwApPlOtD5+CzknQTzlpSovZ/dWr4/brMetFkQCQ9rF7NyUKLIYc33Gy4Y lA66AX0pLMdO3e+PwjCFUmkSzIVh6L9YMOV8Tn2zBlRrOeAJdUrinG67B/+iY3p5NzK1 MHf/peaDN9gpr+cZ1VX3OSeGZUaldDJXrQF5SIAb0IiOSOVj7ORhTlGXPMmcq1MQt891 ba+vee9zpx17KvfPq1XlnqVR+VZnclKYBn1ERE+JUY9pBOZWookHNw4h7VM/KlqPv2oo fqhiPDpbKnVxEEbc0n3zSdDlfioUIVzT0cR3wTAFTbLC1nRd0YsE7ktcINcSfoHFnPJ8 kUNQ== X-Forwarded-Encrypted: i=1; AJvYcCVG0cgQDWhC6bRTFhdfpd0CWjIUIX/GwoUIXafpNCipN63A9lhNqSKQLjEM5Z+T3ur6nNpk4nCDAsvqS2XlKpS+afmuUQQl X-Gm-Message-State: AOJu0YxEU0Tz4wd3eMopRWNYMLf7nDf9PFuX1OwZ2Rosm7ppYo+DBBgQ CfiyT64AC9ErtVlV5eGCNFDSqUlHKFtMh0CoHo0UPFjftHuWd+2mxEioD01eksE= X-Google-Smtp-Source: AGHT+IFBhmv1d14eI6rgQ42K+GoLmMLgfdbvddLFGHNmnBz0MWoTvzX4Ohu+HxDoyM+ZlQsl0WGDjA== X-Received: by 2002:a17:907:3f8d:b0:a77:e55a:9e89 with SMTP id a640c23a62f3a-a7d4016100emr834628866b.52.1722422061591; Wed, 31 Jul 2024 03:34:21 -0700 (PDT) Received: from lapsy144.cern.ch (lapsy144.ipv6.cern.ch. [2001:1458:202:99::100:4b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7acadb807dsm751930766b.201.2024.07.31.03.34.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jul 2024 03:34:21 -0700 (PDT) From: vtpieter@gmail.com To: devicetree@vger.kernel.org, woojung.huh@microchip.com, UNGLinuxDriver@microchip.com, netdev@vger.kernel.org Cc: o.rempel@pengutronix.de, Pieter Van Trappen Subject: [PATCH net-next v2 2/5] net: dsa: microchip: move KSZ9477 WoL functions to ksz_common Date: Wed, 31 Jul 2024 12:34:00 +0200 Message-ID: <20240731103403.407818-3-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240731103403.407818-1-vtpieter@gmail.com> References: <20240731103403.407818-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 --- drivers/net/dsa/microchip/ksz9477.c | 181 ------------------------- drivers/net/dsa/microchip/ksz_common.c | 181 +++++++++++++++++++++++++ 2 files changed, 181 insertions(+), 181 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/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index b074b4bb0629..41f89e2c6b2d 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -3740,6 +3740,44 @@ static void ksz_get_wol(struct dsa_switch *ds, int port, dev->dev_ops->get_wol(dev, port, wol); } +/** + * 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 +3789,149 @@ 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_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_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) { From patchwork Wed Jul 31 10:34:01 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13748443 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f49.google.com (mail-ed1-f49.google.com [209.85.208.49]) (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 386C61AC442; Wed, 31 Jul 2024 10:34:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722422066; cv=none; b=gdSDN49U2w7GAQVqtkpweDKJUYciMn2i4la+G3kFxK0ugf1HJI3Q4CfxMAqPaMBitwSj2p4P+iTW2lgPDvplROEmVFehDEXMqd/akdmKLzMB17PTDJlWnDka9608552RoiIWYiBLI+CKaD2Vo9UD58cC7P0rNKzsPTOKaQ8mIes= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722422066; c=relaxed/simple; bh=shQAxURtObxQF2nmVVSMuLETLoLLe+vY1CQbbZjBe58=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SQ8p3N+KnBerDALP5r7TPZY1p0qKalN3g7bb+17raGz3N2t37rIqMy7YkEzbNbN1bHuRtu2Ex3T1wCdf+DihQ453g52fFUgv8SMniZnmdoMs9iMpRKf98aa4EwCntBfcNlrSezzpYEyzvRhNjsXtRG+uz7oYWn7ljUBJHAtlwFs= 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=RRlP5rR2; arc=none smtp.client-ip=209.85.208.49 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="RRlP5rR2" Received: by mail-ed1-f49.google.com with SMTP id 4fb4d7f45d1cf-5a1337cfbb5so9328128a12.3; Wed, 31 Jul 2024 03:34:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722422062; x=1723026862; 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=c4dFelj6i6c61Qb4LmI4Gp6oBM5ubDua8A0L3kUdVr4=; b=RRlP5rR2UrOwVnDVuBa+61J0DjgDFi8DRdNT9ge+GH5oYqF0ne/pKdu+JC/cxLlgfV 4XW6luYa3N7fq5lSed2A+SKthIwUoC6GbZ3WFVm+tsv+zCzoj6dZ73yPNgKa+tl6SQK8 TjTvl1pfXpaaWL64APSX50DcxiFGeJ359JaOxljE5JvIj/VIfnFd4FulxN5fqilgTJqR nvaprX97HT5oSVyoOCvhR0mRiTbWjfxhA3sMcN/3MPSx6BESTbvkcYhRH3BRuIO5Uil8 QHirtwcA9V8WXayR+2mlGFsvA78v6UBZsJkFfq/gXES7lXAdFxkAKGa0IjUM37E5Ryl0 Dp9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722422062; x=1723026862; 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=c4dFelj6i6c61Qb4LmI4Gp6oBM5ubDua8A0L3kUdVr4=; b=EZKgaGbDbM7G0lhuw2tVMnP+CB9ftMOxtvXZHvwKG8OW3+O8nrkJ7YLbOne54xmqt6 MDIUyxCj3SSJF1uadPSIMlJyaXH2tIEueHuGt56EhIdzVDzfrL1hNLvdfZznfE4F6GBw np0wXaHT2Ut6BEMA3J+eGabafgO5ouUDaC5Pqasmb/DrssgONDIDY1sQ8Hc/XyJYpTFF Lazz2xYijUqvIzLgzthWUIEbDTJCSuflMTme5REsJRugoEQ4czM2keAsulPEGrX8cePh F8z3EFC5Uq9JIBLZF6G9rQ5/UofurTSyV0QXJNbgmcYyjgYhsG0YjXLSKrD9ZQZHixJN zJ+w== X-Forwarded-Encrypted: i=1; AJvYcCUcvJhVKJ43hqOa1VnD/lyK3LA9g/g10fqD3YHsmCa6U5rD9HyufMY6iclgBJmyLqXm25SM9l5Fl6HOF/gIDv7SeM4E9O6Q X-Gm-Message-State: AOJu0YxoqNnCDd4+OmN8yrPbFFiNBpbnHBgCyfVaneLnOHqGWIOcZ87O 4hsigCIkoLaAyDGyf/uN2vrtmDsG80kRAYhbFnc9ihIXYJmbf2id5cG774KPIHs= X-Google-Smtp-Source: AGHT+IEVEeWQbCs1YfGKSWEF3Ktqvnh9M7Vc7HbxzRiJiNlIIgLGFSy8Mrwji2Y6+ma3iyNJHkw8ag== X-Received: by 2002:a17:907:3f1f:b0:a7a:a801:12b3 with SMTP id a640c23a62f3a-a7d400afc30mr1030967266b.40.1722422062354; Wed, 31 Jul 2024 03:34:22 -0700 (PDT) Received: from lapsy144.cern.ch (lapsy144.ipv6.cern.ch. [2001:1458:202:99::100:4b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7acadb807dsm751930766b.201.2024.07.31.03.34.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jul 2024 03:34:22 -0700 (PDT) From: vtpieter@gmail.com To: devicetree@vger.kernel.org, woojung.huh@microchip.com, UNGLinuxDriver@microchip.com, netdev@vger.kernel.org Cc: o.rempel@pengutronix.de, Pieter Van Trappen Subject: [PATCH net-next v2 3/5] net: dsa: microchip: generalize KSZ9477 WoL functions at ksz_common Date: Wed, 31 Jul 2024 12:34:01 +0200 Message-ID: <20240731103403.407818-4-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240731103403.407818-1-vtpieter@gmail.com> References: <20240731103403.407818-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 --- drivers/net/dsa/microchip/ksz9477.c | 14 +-- drivers/net/dsa/microchip/ksz9477.h | 5 -- drivers/net/dsa/microchip/ksz9477_reg.h | 12 --- drivers/net/dsa/microchip/ksz_common.c | 109 ++++++++++++------------ drivers/net/dsa/microchip/ksz_common.h | 27 ++++-- 5 files changed, 86 insertions(+), 81 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 071d953a17e9..a454a2e14a6b 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,11 +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); + ksz_write8(dev, regs[REG_SW_PME_CTRL], 0); return 0; } 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 41f89e2c6b2d..e5358da8cbeb 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,31 +3734,27 @@ 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_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; @@ -3768,7 +3767,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; @@ -3778,35 +3778,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; @@ -3814,10 +3805,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; @@ -3826,7 +3820,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; @@ -3849,7 +3844,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); @@ -3860,7 +3856,7 @@ int ksz9477_set_wol(struct ksz_device *dev, int port, } /** - * 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. * @@ -3872,12 +3868,14 @@ int ksz9477_set_wol(struct ksz_device *dev, int port, * * Return: 0 on success, or an error code on failure. */ -static int ksz9477_handle_wake_reason(struct ksz_device *dev, int port) +int ksz_handle_wake_reason(struct ksz_device *dev, int port) { + const u16 *regs = dev->info->regs; u8 pme_status; int ret; - ret = ksz_pread8(dev, port, REG_PORT_PME_STATUS, &pme_status); + ret = dev->dev_ops->pme_pread8(dev, port, regs[REG_PORT_PME_STATUS], + &pme_status); if (ret) return ret; @@ -3889,11 +3887,12 @@ static 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 dev->dev_ops->pme_pwrite8(dev, port, regs[REG_PORT_PME_STATUS], + pme_status); } /** - * ksz9477_wol_pre_shutdown - Prepares the switch device for shutdown while + * 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 @@ -3904,32 +3903,37 @@ static int ksz9477_handle_wake_reason(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 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 = dev->dev_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); + dev->dev_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 +4241,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 5f0a628b9849..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,6 +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 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) @@ -629,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 || @@ -695,6 +704,14 @@ 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 PME_WOL_MAGICPKT BIT(2) +#define PME_WOL_LINKUP BIT(1) +#define PME_WOL_ENERGY BIT(0) + +#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 Wed Jul 31 10:34:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13748444 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (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 DFED21A8C0C; Wed, 31 Jul 2024 10:34:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722422066; cv=none; b=GbxIFif5lTqoVkhj+YBr9vFkdE4zmvPkMK5gOQ9H0FZOvLAlZQxHNiYQd5Ptk0PMF7Rru/opOPp9reYn6HJq5MEfTT+si5PLlZS4P02bRVrPQ7+uElnRXgqWr8+5bEy6z+s3XV4UKX0Y9RJUPuDXrJF+H2XmWJzDVHsWQSxAsSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722422066; c=relaxed/simple; bh=yDH4Bsjg/RtmJcPOiV89UQcWprC1s5pnRTk6ElHf9Fo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qNAyYRkx+9OWSyiKTJhL+r3R0fjNro8fSIbiWDO2c8To3Ku9lgrC0DGUl/IBowZT5YR5iresVj7gEtt25WpCfK5Cgl8US2Ampj7rlLx+ozcGiStwnfogcjOjTyMZqnoryZ0+UFZoD0s4K2AS06KiT+X4u/qM5ftF9UP/jtPX/kw= 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=V8L5ogCa; arc=none smtp.client-ip=209.85.218.54 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="V8L5ogCa" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a7a9e25008aso735479966b.0; Wed, 31 Jul 2024 03:34:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722422063; x=1723026863; 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=0yx7z6YHRCHQ0GpltuRt0NVqpjHgJTOjWN1OtVJ6pBc=; b=V8L5ogCaTFArgfbshYDtQbCR9PraClkX5D9LNBTxdH5lUUvn1/nxhujjcSbmoQauL2 2ZD42iCTd6u8V/tzz8/eR6exf5e5c/rdZIuYqVYyBWZmLWZ4nPvtn3tlrC3/QipCq/ME mt7oouRzNusiCdfWQbwHVSg1ToYORTgn3bY2WzcnxZ6phuQJILHwXMZSUAGuIpqPqIus 4POVU0UaoTAPt2C9Do60BV8TSWCNt5gZzQ21Cy7ln60Ywrg8O1y0tQUNwQ00+8VaWCso yxhsc5dJFcweLxgNk2yczwgTdoCu6Gt2mCEtALIiruQCwaBu0B7D4BYpUkEWAodTkhIn MnMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722422063; x=1723026863; 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=0yx7z6YHRCHQ0GpltuRt0NVqpjHgJTOjWN1OtVJ6pBc=; b=qipekOjsz+ARvgMWEoX7Qj19asezeaKSAebMZutk+w6iX3oVCK4o85c1YskdT09E7i uSr8BCcWUM3k1bYMmYKSYziZN/ArYpdb/ESpLzaDb8CGxehIbf6Djebabzvhwde+lPCn 3PCxVUVVtl/Ot2RQebd9NeOeiq7G7RA14fFTYE6j+E8EL4/DxtbjamCWh7jr2c74xcbM L6f7X+6gkujutnWEiPcYN7x8tPuHfQa//kXzcsvD6szfwIF1jj3hVAX6tsRBIaOrcl/c Pfk5lla5t1DORNbHNIXJhBvNBtOFnJCC2GhmKQ3Ndcyk9RtoS/p+iJF6hCrLGJWBbfbs PkpQ== X-Forwarded-Encrypted: i=1; AJvYcCVW/oZsrTzGM5950Am3S8qqwG7+MrC2E/iMQ2J4MXrRinSJqiGObVaX5p3uS0qa4waeDjuOQJ2mAPeIloHD7sASESX3h+lE X-Gm-Message-State: AOJu0YzRymmFDhM/VK6c3nKH3tUtGbcb/3TMXFJIV6ADqK3N8Pi/yIUR zZpmurSK1sD0n40R0SKe2ZfKFiBhd8jm8Qy5sX6z9mmfxI4CAau3QSvS6mHblAs= X-Google-Smtp-Source: AGHT+IFOzfWfsW6jhyg75QTkvg7n0B854WoDvmkyeltDqsgvmz/+o6PI+nF48JvOUQOzg+yCeqFLvA== X-Received: by 2002:a17:907:9694:b0:a77:cb8b:7a2d with SMTP id a640c23a62f3a-a7d4016612fmr1084721366b.49.1722422063133; Wed, 31 Jul 2024 03:34:23 -0700 (PDT) Received: from lapsy144.cern.ch (lapsy144.ipv6.cern.ch. [2001:1458:202:99::100:4b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7acadb807dsm751930766b.201.2024.07.31.03.34.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jul 2024 03:34:22 -0700 (PDT) From: vtpieter@gmail.com To: devicetree@vger.kernel.org, woojung.huh@microchip.com, UNGLinuxDriver@microchip.com, netdev@vger.kernel.org Cc: o.rempel@pengutronix.de, Pieter Van Trappen Subject: [PATCH net-next v2 4/5] net: dsa: microchip: add WoL support for KSZ87xx family Date: Wed, 31 Jul 2024 12:34:02 +0200 Message-ID: <20240731103403.407818-5-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240731103403.407818-1-vtpieter@gmail.com> References: <20240731103403.407818-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 | 86 ++++++++++++++++++++++++++ drivers/net/dsa/microchip/ksz_common.c | 29 ++++++--- drivers/net/dsa/microchip/ksz_common.h | 4 ++ 4 files changed, 115 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..8fe423044109 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,6 +1865,7 @@ int ksz8_enable_stp_addr(struct ksz_device *dev) int ksz8_setup(struct dsa_switch *ds) { struct ksz_device *dev = ds->priv; + const u16 *regs = dev->info->regs; int i; ds->mtu_enforcement_ingress = true; @@ -1829,6 +1905,16 @@ int ksz8_setup(struct dsa_switch *ds) for (i = 0; i < (dev->info->num_vlans / 4); i++) ksz8_r_vlan_entries(dev, i); + /* 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)) { + ksz8_pme_write8(dev, regs[REG_SW_PME_CTRL], 0); + ksz_rmw8(dev, REG_INT_ENABLE, INT_PME, 0); + } + return ksz8_handle_global_errata(ds); } diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index e5358da8cbeb..02595ac10934 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[] = { @@ -3752,7 +3758,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) @@ -3805,7 +3811,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) @@ -3905,13 +3911,15 @@ int ksz_handle_wake_reason(struct ksz_device *dev, int port) */ 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) @@ -3920,8 +3928,8 @@ static void ksz_wol_pre_shutdown(struct ksz_device *dev, bool *wol_enabled) dsa_switch_for_each_user_port(dp, dev->ds) { u8 pme_ctrl = 0; - ret = dev->dev_ops->pme_pread8(dev, dp->index, - regs[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; @@ -3932,8 +3940,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) - dev->dev_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, @@ -4643,6 +4656,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 Wed Jul 31 10:34:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13748445 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 843531AC45D; Wed, 31 Jul 2024 10:34:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722422067; cv=none; b=KC7Xhrsh6c6URr1PFbkl7vrnqdQ9ucgDxfXTxIi+vx/Jm4uZFLoL9LI0Y1zWEB6hySl0lIntDgeiZI5r2oQ6dxoAfMYpW34Wf2MEPOaDZPOERmFR1OCNg3j2KpeV622mOmrwdUxHlVcl38ue7Vi9KRgD3Y6yD0szhQehLipmd9g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722422067; c=relaxed/simple; bh=5Sey1WJ5331kZ/cuoYVNbnE0u0kbTfsMiS5RuMAl0Jc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=S1TB7rUUeuc09PkKbnGMn4h1njAhww3Hzj5vA2A66vSU6mBS5b/hkBEGwz21n7xj+ZwXkCznetogkT0EVDObXaqTn9Oyg7jCGFWnFcVh1rhff9V7yCkg3Aef2h8gYAse5awIkuch96PFHisZ7ZT057tFydoyScpf5Tpc9iz+ISg= 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=i4zgWYS0; arc=none smtp.client-ip=209.85.218.45 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="i4zgWYS0" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a7a94478a4eso151773666b.1; Wed, 31 Jul 2024 03:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722422064; x=1723026864; 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=HQCKyqTCal9KZI20i//lzBe86huK8vRGAy9oESd4Jd8=; b=i4zgWYS0/pXTUr7r+siR2CkMoslGA0VIfSb0m8Ea243mOaQNaCPtyMmxuI8HyP9uik a26dEep/GqiZ6TvM6Z981eC3YR2CrgXmQhe3PHQEQrYXRlg/aD/w68uf/g5i7X7ZQf1D oZqPqCxvrFsKiecsxzrQBDLF8suRzMNkty34Uv8qJPWgD5ANKPDjsA53f5ze5m6BjMXq K7277Pq6IXfFMkZ/aenL7w61k4jEosaXvgCqO/pHyVml2mvOWRnsMUTEobTyv0FbPUDA TG7tJvJWdzFRwtZJwDuVR13DQfuJG+q7+7bz9YsMFVxfT+5qJ8bTc+8liiEseBnLKzbj 8mew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722422064; x=1723026864; 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=HQCKyqTCal9KZI20i//lzBe86huK8vRGAy9oESd4Jd8=; b=dC9R4g2oK+FhzWtkRqFwz4YhyhAhS/OA2mMzVYgz099PWk8+eyU3c+ADqZCu4AtWnP O/FNFjV2/m9J8VQV+c+VzfVUdOtHU/+mgfZHG/K0RjByhI+XqlfymUaBdjtQV+NM8WYI WUGASP8XO/drOJ9/sUc70LBZcKodK1p365M1cBuwi4d+QU0AweA9kkUrfVyDdOf2k2Oj myXbmWrymcNmR2qAthaS2b7cxI52cIFc1Mvn0MCEVQcXbCStk9m2kz6aTFpWDUbP4SdN hUhynC0In3qmi4xTnjs/IBLL4O94I6c0JZYp9NFrad4+FYsGZ+pd9VxJ9OpB6/E5UKJa 3Sdw== X-Forwarded-Encrypted: i=1; AJvYcCU0aDSCWL3YjZ2B/j142u0GXetQ0G1RX6Jl5j7fdNSyJnzY3tfpLwcpypVvE8SgS7Wfyl0fYoeGs+xZkV/0ZapNUcEgdeGN X-Gm-Message-State: AOJu0YxydrDlHsv3Uj/JtzuwrGdY7L6wYDBqea0snLAowfVRKQSwU3K+ +vI0TydlxyBg1idCACdEQrJKYtTyV6PJyslUeIabMghPnt4cLSXflGvWrzvPVUY= X-Google-Smtp-Source: AGHT+IG9/DYN3ZNTEtYoo6FQiWuOpopKp1+FN2RYfpMC1UxIUPmjb+EIxfbD23l/kL5wgIJ4EoQkbQ== X-Received: by 2002:a17:907:1c19:b0:a7a:b561:356d with SMTP id a640c23a62f3a-a7d85a62d9cmr474210566b.26.1722422063829; Wed, 31 Jul 2024 03:34:23 -0700 (PDT) Received: from lapsy144.cern.ch (lapsy144.ipv6.cern.ch. [2001:1458:202:99::100:4b]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a7acadb807dsm751930766b.201.2024.07.31.03.34.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Jul 2024 03:34:23 -0700 (PDT) From: vtpieter@gmail.com To: devicetree@vger.kernel.org, woojung.huh@microchip.com, UNGLinuxDriver@microchip.com, netdev@vger.kernel.org Cc: o.rempel@pengutronix.de, Pieter Van Trappen Subject: [PATCH net-next v2 5/5] net: dsa: microchip: check erratum workaround through indirect register read Date: Wed, 31 Jul 2024 12:34:03 +0200 Message-ID: <20240731103403.407818-6-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240731103403.407818-1-vtpieter@gmail.com> References: <20240731103403.407818-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 Check the erratum workaround application which ensures in addition that indirect register write and read work as expected. Commit b7fb7729c94f ("net: dsa: microchip: fix register write order in ksz8_ind_write8()") would have been found faster like this. Also fix the register naming as in the datasheet. Signed-off-by: Pieter Van Trappen Nacked-by: Oleksij Rempel --- drivers/net/dsa/microchip/ksz8795.c | 13 +++++++++++-- drivers/net/dsa/microchip/ksz8795_reg.h | 4 ++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c index 8fe423044109..187301fe94c9 100644 --- a/drivers/net/dsa/microchip/ksz8795.c +++ b/drivers/net/dsa/microchip/ksz8795.c @@ -1834,6 +1834,7 @@ void ksz8_phylink_mac_link_up(struct phylink_config *config, static int ksz8_handle_global_errata(struct dsa_switch *ds) { struct ksz_device *dev = ds->priv; + u8 data = 0xff; int ret = 0; /* KSZ87xx Errata DS80000687C. @@ -1842,8 +1843,16 @@ static int ksz8_handle_global_errata(struct dsa_switch *ds) * KSZ879x/KSZ877x/KSZ876x and some EEE link partners may result in * the link dropping. */ - if (dev->info->ksz87xx_eee_link_erratum) - ret = ksz8_ind_write8(dev, TABLE_EEE, REG_IND_EEE_GLOB2_HI, 0); + if (dev->info->ksz87xx_eee_link_erratum) { + ret = ksz8_ind_write8(dev, TABLE_EEE, REG_IND_EEE_GLOB2_LO, 0); + if (!ret) + ret = ksz8_ind_read8(dev, TABLE_EEE, REG_IND_EEE_GLOB2_LO, &data); + } + + if (!ret && data) { + dev_err(dev->dev, "failed to disable EEE next page exchange (erratum)\n"); + return -EIO; + } return ret; } diff --git a/drivers/net/dsa/microchip/ksz8795_reg.h b/drivers/net/dsa/microchip/ksz8795_reg.h index 69566a5d9cda..cc6cac97c369 100644 --- a/drivers/net/dsa/microchip/ksz8795_reg.h +++ b/drivers/net/dsa/microchip/ksz8795_reg.h @@ -764,8 +764,8 @@ #define IND_ACC_TABLE(table) ((table) << 8) /* */ -#define REG_IND_EEE_GLOB2_LO 0x34 -#define REG_IND_EEE_GLOB2_HI 0x35 +#define REG_IND_EEE_GLOB2_HI 0x34 +#define REG_IND_EEE_GLOB2_LO 0x35 /** * MIB_COUNTER_VALUE 00-00000000-3FFFFFFF