From patchwork Mon Aug 12 15:29:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13760764 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.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 BA202F9E8; Mon, 12 Aug 2024 15:30:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723476632; cv=none; b=ZDvKm99z71BLuLNPrXySoCv4rmZEAOuNVfEZoGugu9Uzb3IazdI/UNzX4dBueleTbul0CamkM1UjiLAQLSBzATYIkLn8aBM921r3Bw44ie6ICi0wVvv+IZb2c/IzsVknD6JHfeJ0lHzxPfU7LumJ95W02mZ0Vs8xlpSDPURejDc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723476632; c=relaxed/simple; bh=MNnLV25K6YhULXYYlXhNI0BKUG+LUYqABdwm34GgDDM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GmMmF8qEtNOXX3XkWyQNO8qeTRbjiupUiknHrPU3oeldkb2OJ9ICwMPMvKj45pUYQnq6fF78958hJ+SPu+0lxUjeUMN6L9TsuAEHF5OSwmHnvNOi4/c61Q0Cc6UQH2ifKhon7iuzdf8dI/uC5yobXUBnBekWEB/3e2QKUrBMDCs= 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=FZeMzpCA; arc=none smtp.client-ip=209.85.208.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="FZeMzpCA" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-5b391c8abd7so5238946a12.2; Mon, 12 Aug 2024 08:30:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723476629; x=1724081429; 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=FZeMzpCAxtdTy7imaAhSTx8X3HQD3YKQGC7Xw6DCk7RdVNRVEeahR0a9yzQmRvKFjt OkmISCUOL13G7UOw7seUNdgnLG0oo9H6u9vr/5GGunwT3JYIL7fGtUu6ZiCRlrL+SFpn f9ZQLI1Xbh9e0vnwqYC5tJgMASYbVKn0jPAggDKjnSImASgHFcArgutFofkLTBOUpXt4 aHFdCK1nBp5VReMKCh+IYVfrb6FEdniLv8BwIhOaxVgP0qw7TgwcPkoX1DYp/5fi8oBv MLG7GeTbRTBfV7oLDyft4ver2S3JOoB06lDOX9MNRdOh8q3KjXb2oOCwr5CbQF+QJsqh IoLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723476629; x=1724081429; 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=mulodPTyznbzJXI599Z32Tcwf5KtiK3gt+bLAgX4yk0lb+dyvd/c2Uz20rSSjT3Mdf tBKQ4qSAC9NY2ScJ1Q1QxNzG+uNnRjFqWVovO12iH42rn7IE6+dM1LEqQzJeUwiifSFB eyxNvtO4Kc0AwrC0WSPPpzFfgUGxxOSxQ/FE4N+6eUATyPbpgml5g67t0++CWrLOzECj /PHnqecu+1sQR+6UAjHTdDfwzUwadMYrS1REA9MZD35Wk5tKoGaPPf55CJjXwgznBqP9 +hGGMox5lDPJWFdVPZYUsL1823yu/efKiH2CIe64xoTCMOdwFLbIkaI+4dOPQtoLx7SH ScLw== X-Forwarded-Encrypted: i=1; AJvYcCUb2kVdAr5tn8QL5i5y4pJAh8oiJkRo1vigUMz0yR8J2I3zxUaBcMOwR7zYLh1QpprYyQy+YhCju7OorAsksPBMf+QboCeigkPLbawan8GlfNImUErg3wuPIE2J6Bv3KsRWeu91p+CFtenKgP4MRijXlK1gWoFU7trPibXIMEmr7w== X-Gm-Message-State: AOJu0YyBkBIadDgIXZRtsHZbB33OHjyws64PJ8QId4ULupv/VhaQd39Z TZjvOTEO9H4PAkrka4LGKLoOkMA/QsKRGy5LBLUTS4qos2eoWl3uzJA9YonCs3IjHw== X-Google-Smtp-Source: AGHT+IHjRNP5SFuA3gr0sUZ7f/+SsH0QSenGJcjH+uF0+Gm9+RG7u7LycnRzr8D05BpL9b4YJrVGzA== X-Received: by 2002:a05:6402:354f:b0:5a1:7570:8914 with SMTP id 4fb4d7f45d1cf-5bd44c27370mr531327a12.11.1723476628660; Mon, 12 Aug 2024 08:30:28 -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-5bd196a666fsm2192535a12.46.2024.08.12.08.30.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 08:30:28 -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 v5 1/6] dt-bindings: net: dsa: microchip: add microchip,pme-active-high flag Date: Mon, 12 Aug 2024 17:29:52 +0200 Message-ID: <20240812153015.653044-2-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812153015.653044-1-vtpieter@gmail.com> References: <20240812153015.653044-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 15:29:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13760765 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 2612DF9E8; Mon, 12 Aug 2024 15:30:35 +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=1723476638; cv=none; b=M9Z3Z5PJmge0ZIRJ0wBLfBk24NFgYv/f+UciRON34b7GejVY5DXCKOToFAEzU5mmPutinJyX6gsfDuvO1qZ+D99eHvulcz4PGquBVdq/y/OV4CXryilOQAv12xyfKJa4JmcNjjqadeM3Jl9SE2g7bSbF6ajdiSxMtC+MF1JARFA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723476638; c=relaxed/simple; bh=cI6omaOq9q4KhDAhVFNb9BhAcM5gxFkHis/LHpaLAfM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ERArR7iju30qh/cNhIkq7DzquLgqpAbz5XlDYLO3E/4Y3zEIr6HFMCgCEID1s0hh18FU7nEsxfn0T+tZU5rwqImsYZN5Hh2jGGOM8V7lIt/tvszzQbHe0zgpCAETrKsPKMett6rAX5wosVAXuI5i9byfTNDQPptMcGWPLnYFgr4= 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=c/lMyIeo; 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="c/lMyIeo" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-5b8c2a6135eso593955a12.0; Mon, 12 Aug 2024 08:30:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723476634; x=1724081434; 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=c/lMyIeoTmZzm/5IqZ3FV/jckrU89H5SNu2tPO28SfI8NfE9OQdULohC9K8afdItOx yY0VaCav5MnULGX/mvjTWmIuJEKbdudGzlC/d13lyENwyRSQOzlMrpZGlT/KsYJ215OG CdEo4tm2pr/rO8lO6qPF2LTrv1hV43gNNgx6M34cmf3V/ZkGDyZm9ztga4MATu5VwZd5 IlWvCNLj+8neAd6KsLGiPgfDJeLKuCakO1//38WcWNGO+xqllohd/4inL2zAe8lPg/ZQ EVgj7qq1GHZ/E7ANDXJxYjpZsLLltrUrioiyj8MIbrom4Y207FTCpbMmE9oU70/t8Wy3 /MUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723476634; x=1724081434; 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=gYG3JS54OHVdG9qdya9XDqz7D/Y7R525zBYinUwXAjryO1D92R0gPvE/sYDuFEbz+F vjNKd2C22Xsh6HCAoYZsb4D//FDaUATK9dPb9BkGnjJAKZG/4/eOgakTVeuy/7jwoLZF KKxFsfHyGtZjLySzzGtI+lT7yXuK2j2yCY8AxbmGKb05dqUtb2EOson3Y1ojtYRJe7Vb 6Q+D4zbov5tjTU6FG2QCs2Aaypc2XVEuOH6S4PKJCTpBUArhDIcBj2VHjd9gHED+0cGL FrMREdMiqOfRptE6nScf4Rhv/Gg8EMUJqZrcfwsqSsBpCS8dPJFfGi4iFtg0TJP+xg2V L+QA== X-Forwarded-Encrypted: i=1; AJvYcCXKvK9xg1bkPra6UCxJio6KNX6viViB4iHZg/au7v4VZpo/0ATrF5Mdn/0kh4FchC6B7e53ejibATlkZKm4LbFI7MF7TWCHtb56aGlXI66R3hKALvOLCUcQ5z5MYLTV3hO3JOVVpqCjr5giTfQqkCPhNdGDOZ0kjIHHB0C/9RA7Dw== X-Gm-Message-State: AOJu0YwPNWfZ9WT2p4LVC9ERljD/mGwYJ7JuMXobiSK2Yuj4DsrE4x+W jIdt+WRoONGkwIRFD2Nz2HDT1RvxrpMRa9nh4uN4d7sXnLVobSLb X-Google-Smtp-Source: AGHT+IHyD+FvepXnBme4we9jXhH9UK7n/D7hUhPpwA0rrdvImrsZrxpsYlRtJZJTD0fVMCueiZCmKw== X-Received: by 2002:a05:6402:190e:b0:58b:bb69:763e with SMTP id 4fb4d7f45d1cf-5bd4619735amr20848a12.7.1723476634228; Mon, 12 Aug 2024 08:30:34 -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-5bd196a666fsm2192535a12.46.2024.08.12.08.30.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 08:30:33 -0700 (PDT) From: vtpieter@gmail.com To: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Florian Fainelli , Vladimir Oltean , David S Miller , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Marek Vasut Cc: Woojung Huh , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Pieter Van Trappen , Arun Ramadoss Subject: [PATCH net-next v5 2/6] net: dsa: microchip: move KSZ9477 WoL functions to ksz_common Date: Mon, 12 Aug 2024 17:29:53 +0200 Message-ID: <20240812153015.653044-3-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812153015.653044-1-vtpieter@gmail.com> References: <20240812153015.653044-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 15:29:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13760766 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 64292186E5A; Mon, 12 Aug 2024 15:30:41 +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=1723476643; cv=none; b=qJqr1dqEK4fs9ji6t9k9M3J/5KCi9+uJm20p2h//h6BCy938dSxCiJIhKih5ETmTd/ywiOxomMm9ymFCKD11sXKK2E61XkS33F5yA/uTNUZvNEbTWhqp9EdVe4CCxrJGZ2hjoZ1vpoiX3WYEyshK6J/la6UyH1+IEWUArFHZHo8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723476643; c=relaxed/simple; bh=yVbLiwXp3y3vlxhRVcrg1Am12yF0nslL3Naf9OUa0cg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=stXA5nohpxj8cfFl18Fi7ZsczS4WuX74sFTlnkjCt7OQfspf5A8a9bluA+e6pP2Pf/DN9DafmLN3LE3StJckPFN175K3bV0jW9HiViejPVbdwic0pDFiwdA8F265C9h6FdFf3aKdmqMp0JZa6zv/fL57sgZQQMP3J1e9iQAMskA= 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=e1WH5Dmt; 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="e1WH5Dmt" Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-5a108354819so5832466a12.0; Mon, 12 Aug 2024 08:30:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723476640; x=1724081440; 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=e1WH5DmtR/tTLa1vMxILZi69xwf65UmaQnpMaEOoew+TRJ3TeSvR2DgvsoY7m8Lwst 4YRvoF+JRCCfFlTVnay4sSk8aMXc8R0TB5dDeERIhk9QyPzWXcAHqcWT8qPeJ7ADW3pU ih+oWS8GEu/wXlmvYfqv1S70wvk3m32n0O85RAU697tyoZHYVR3LBOwTzQdye+IXAkKu A8++pQqRxXYeo6UeOX6pgMnUNCWp0YDMzf8KzNsy94K0fxJdXC23K64p9R9uER6K2zMp eMR6zobAYMNn9lQs+UIak1n6PkVaFOeITKnbzO0G+bESrtAGfyFIXOBIjuETsTpZ+wey IKzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723476640; x=1724081440; 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=ZCI09gOlQgKZlvWkjFAgfwIIe0ibZtwQs9qvhry63FV4dVC7EUv+7fWs1ewOlRWk7F gYxQYjT2m5S3qikDsMi9oqG9XAfEDmUXefcsXv6m/h/TAA+SP8pQT+CVXTRndju2nfaC 76nVEpy/aFj3dyLAT87MCvQDWzx1f6cUISx3qZzMib6twq94d6J52F2fjJQawRIJZBOz 6YPsHDwG/TosMx9y4XPwImW6IwgDM5YJOI8RF8bFlF7qgR84s07924lNFqEJpVVZJ6oA Gsmy1OthgF3lWPnIurBsY9JaXD7HkNSAa6QzrJUR6a+Oib70+Q9CgAqJ35CZbAqW2tKq v35A== X-Forwarded-Encrypted: i=1; AJvYcCXOPzT1HHtxr7giwStC/AZnUj39rV5+IcGKqaTJQCcX8exoZHKOb7aMy2E2/SUGbeUADy+dgAjVJ6Tsw0uOFOdjqh/ahoPug88G7tDmMdROT9T6FKx+xOwcw7wXSFYlHFm/p3M2B1mpGrJDJ5UfhUTE+V1It8vXzlzmxxoTGtYc2g== X-Gm-Message-State: AOJu0YxaXbQp+/3EeWF3utGBBavU8r0PoGzCJwL8l91MaNTMXOFAEmB1 pKZZDEMG9EHqKwv8s+1/Gj1GcYUFkadAdAN1D+QTz/uKLDZ+4xy9 X-Google-Smtp-Source: AGHT+IFivwePYSVFwsULnxCMfRnNxBtqQnZzhk8ZLskbtMCj4iwdknsY5kTsql6wS3Enm+qJ/hXmOg== X-Received: by 2002:a05:6402:320b:b0:5a1:e92b:acb5 with SMTP id 4fb4d7f45d1cf-5bd44c295d8mr523413a12.11.1723476639206; Mon, 12 Aug 2024 08:30:39 -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-5bd196a666fsm2192535a12.46.2024.08.12.08.30.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 08:30:38 -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 v5 3/6] net: dsa: microchip: generalize KSZ9477 WoL functions at ksz_common Date: Mon, 12 Aug 2024 17:29:54 +0200 Message-ID: <20240812153015.653044-4-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812153015.653044-1-vtpieter@gmail.com> References: <20240812153015.653044-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 15:29:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13760767 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) (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 07020187339; Mon, 12 Aug 2024 15:30:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723476648; cv=none; b=XEc0CsmrsNI9CPLeoFGV18baMWJ8ZwebZkMN5t9+7CaV+dAQebxR/bJjmhKTKmKoARfjUS87K74IeCP+uK28bJPt85v48FYznjTvp2mdsh5mYGaGaFuJ6dB3QFF+RSLvoN9NK/NL4xMVzJLrJpZ7cxmbGmEH4mLGqpPevldkHgQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723476648; c=relaxed/simple; bh=aoGG5sVhLE9ME+bAQqIWjm3N0qUkcvEkfW51zHhShbA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TOPEDlNTcrzsGi+YpH/ripFD9lzBvxf92+j0dIuZyU5HAjDrN+nq63KPMBA11vbVDVyNj5fMiT1rcCoTH8fojC76nSdX9Aa8l3ej3sA7ZKHHdhpjCuF2q7AKcP5/Opm1J2AqJDcA9TNtofT26VHMhvkZHQY9M2q3yw+H3k/YI+M= 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=PUWIAAcA; arc=none smtp.client-ip=209.85.208.52 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="PUWIAAcA" Received: by mail-ed1-f52.google.com with SMTP id 4fb4d7f45d1cf-5b3fff87e6bso5016556a12.0; Mon, 12 Aug 2024 08:30:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723476644; x=1724081444; 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=Q0dC3mF4X+wKSKxy8Scoq+dO1j2v1I2jrAKLTICnCSQ=; b=PUWIAAcAFQNu91REBHJXO72QDWP4lP5L0IGl1c2QmiHn1JlJsVWCJMsXBS+TRH4UpT AZyNlhOqBgijbzeq19KrpIJB0MCW9sPRl/JhW4XmkbLdWvPYmvTtpqlHokbc7uK7JiqN qgNAc4fhqtZty1qFtUubnx0UhXYnXDWk+CZ3HJOkYrXvUd9VdOjOBaegfE0NMRfX+pX2 /Hg9b2ZWdsxE73ZIka9fnbGcEoClflIVXilgDLIl57fCtMOaFjbkvicBSP99mYAA/9PV UGfhvIIa4SMfdz7/Ot5hx9spEk20dG/25Fcl6QHbSI0S9M63/6NoHp8tCIUp5M1rc+vH 1YpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723476644; x=1724081444; 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=Q0dC3mF4X+wKSKxy8Scoq+dO1j2v1I2jrAKLTICnCSQ=; b=ky/ATqGwv+ehdDynwruJIXZoPdYzZcQFK1wXGCJYDgSn6D6RVcCRq26cJNr/ZTsmkA H4FEJvxa2x3YAd90+U5k6CqulsYlLx/uupO7KpSe/WiKQdcoulBQOuIQC+GrtkItWeNz 8I5Rzu/IfTQBoTzRXu65RiwJTXxn/WIaWGOKIwkc0LtEVtk78ffGx5FH8E0EtX0UbFl2 pRwQ/RG1QapKgePr/mof6orm2i7rGHyp7uY8YbD7Nmx3E2A7Jthahfe8vTzRtvGeWVME +1u0xKzIjt/hw3Kn+qZvAq4/30k09weQHofaT1K7cIM2YdxolRj+LGvjATOPCGAd3PYi IU1Q== X-Forwarded-Encrypted: i=1; AJvYcCXFAVrwP6PrrXpHI++URTEgr0gdMs3NFmmyKQfyoZKd1Xax3G0Zp+h7BnRU+5nt0L5Vvs0HDKtygLFry9fDocRqmzwYc9oJsKkXdwZpOemm3S9vlFjwYuLXSX5PkWPO8cyZcDpGKeD7nxUxIAuL2MnoHDVaPhpQZqr1usDUpPsyhw== X-Gm-Message-State: AOJu0Yy3YPw1NJm9juYjSyqoh/KlFaIbWrKvTHjcNlPLXhdbSfYsQLFH tNNGO7OK8CEp9v02HefuDYaHRASmIrTOTBjw6RSi4wmBZ6hE7Ig8CKegUCPlVzz/dg== X-Google-Smtp-Source: AGHT+IGc7Ax6Rx/zx7X/Z5EkMCe3vExcPsgjvqIe734zHii7qlFLAVkadO98nekw6OtHVqAmpi/Grg== X-Received: by 2002:a05:6402:d06:b0:5a2:2654:7fd1 with SMTP id 4fb4d7f45d1cf-5bd44c78c9bmr398115a12.36.1723476644075; Mon, 12 Aug 2024 08:30:44 -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-5bd196a666fsm2192535a12.46.2024.08.12.08.30.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 08:30:43 -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 v5 4/6] net: dsa: microchip: add WoL support for KSZ87xx family Date: Mon, 12 Aug 2024 17:29:55 +0200 Message-ID: <20240812153015.653044-5-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812153015.653044-1-vtpieter@gmail.com> References: <20240812153015.653044-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 15:29:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13760768 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f45.google.com (mail-ed1-f45.google.com [209.85.208.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 CE4C618756D; Mon, 12 Aug 2024 15:30:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723476650; cv=none; b=L/uxF7M6oi8M8jiiHfjmQ87mSeckJVSNwcPy9mc/cbMopM4leGVNg0ILoeU7CmvMTzOeo3HMy8A+Wg9zSAotKy7WlzD+sTFhYDduFfkGfFGZeZS6Ep7G3urJ7fy5LVRw/oYC2oW2x8lz4FXqDj5/IUG+/Inu8gITT0PmhxJ73Xw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723476650; c=relaxed/simple; bh=YN4VF9eogqlyEemrlDUeUUfXNQS8CprZhceY24IX5uc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g2Tmc9b4CZAno5/jzN3BCNvZs3Sr1/O1qng31GeOZLP/NVgz++KyGoZE7QHJ6winUr0yoaCdgiEepJnvbDk3bsyfWTDsKbJe/tg8OWJfC9nEIYrC7v0vcjk9UgJrDtC0jm8JbutpCUlvlq9Nv6qEzDNkk90ea2xxTuyigTta+54= 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=MgMn7bdZ; arc=none smtp.client-ip=209.85.208.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="MgMn7bdZ" Received: by mail-ed1-f45.google.com with SMTP id 4fb4d7f45d1cf-5b01af9b0c9so4681328a12.3; Mon, 12 Aug 2024 08:30:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723476647; x=1724081447; 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=BLmRpZ1aG/lzex3h1BqdyLB+WcZHwCjcjuUeIyDowBA=; b=MgMn7bdZpqjEE9Ln3DTgqapiObVfaRhhwF0VGxUXAxgrAi5B/XYzzyGHgihgRkJUMh qIxYKsROMhXq7C8rjrYV0GK+R0WY1oUgtEPaR3ddGaB2nYQspC2jMUxM1VwL0cNm5XsZ N8HrRPkd+k9oD0guFfNCo3GfTWbb0T/4DNp0C83oWkg8y6sGOt26PSlnPlbXg/o7RRqP qNKYJk8z7vkl03+PwKWMkwr7Au+SW2n5q7rmQ2k3jVZ/lqkQde4sWeob6nuXT86Ue/aO bCgIPE0DEYwUMY4kmwMve8ayCd/6F5ACw1OjnDsY7KDor/TxlgOEJeAc4jcez5jMWHzr MB+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723476647; x=1724081447; 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=BLmRpZ1aG/lzex3h1BqdyLB+WcZHwCjcjuUeIyDowBA=; b=D3AbvfjBQu9foLMZzCU3LW2rYJGtPwLcPScM+UHuAW3zKdj234gk2qMwB27xIlHkYZ SoZMK+Pg/sMe9u+29t3IoPbdFT9ysQRZPsno87TYUBGtNO68KwO1LhX+y1Wq5o7UuF3V dhvwKmGzYylTBVadX7JAsGo3DaTT3ElgizAsHBmlyJpJzpTwPw7w+0cgUKOu2xFpX2o/ 8jTTwBSQrxxFfyR1IWcoOKN7PTnGwU5UwHJ87vDgwx/QJSY5RtCEnMS7QSTbMCxug68v BgK0QQ9/LDb0FYq2M0ZPP9H6HQJl18xbXbTApNOMI+5eaBgDchefLwtWVIfnsI3bh+yd /vFg== X-Forwarded-Encrypted: i=1; AJvYcCUGyhTUwIHc9RvAOqukpQYtqdqcAw804pSN8qWDJZyqDtgALTrfIUHhycg/NpDCFQ4h6lVZd2q2RY1fvWzZRY7vXVZQXgiCDIpbRzDoFPCwOrKQhLNIzWcZHDEUp2MfuWpmuR1rZtTIOcXPsLrYEjP/nlXct+TGSfgpu/541RGgpg== X-Gm-Message-State: AOJu0YzBwxHAyotQgJA0gTcdxcTZs3+IRcGthGWrmH8qYdddqCNdsOfL JUdP78Y9K2Oqo3xCLOXf6SLm+SxQbLkD4Thotx2gGsWpvk+F/fej X-Google-Smtp-Source: AGHT+IEnTXS7AVSc649zDQ+487fyDcpGFVy2Df4beudLFabvjF2dpgvjXDR8HEvOKyWMW9xzs5UYHg== X-Received: by 2002:a05:6402:3587:b0:5bb:9ae0:4a46 with SMTP id 4fb4d7f45d1cf-5bd44c0cff8mr579891a12.5.1723476646900; Mon, 12 Aug 2024 08:30:46 -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-5bd196a666fsm2192535a12.46.2024.08.12.08.30.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 08:30:46 -0700 (PDT) From: vtpieter@gmail.com To: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Florian Fainelli , Vladimir Oltean , David S Miller , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Marek Vasut , Russell King Cc: Woojung Huh , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Pieter Van Trappen Subject: [PATCH net-next v5 5/6] net: dsa: microchip: fix KSZ87xx family structure wrt the datasheet Date: Mon, 12 Aug 2024 17:29:56 +0200 Message-ID: <20240812153015.653044-6-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812153015.653044-1-vtpieter@gmail.com> References: <20240812153015.653044-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. Signed-off-by: Pieter Van Trappen Acked-by: Arun Ramadoss --- drivers/net/dsa/microchip/ksz_common.c | 51 ++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 8 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), From patchwork Mon Aug 12 15:29:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pieter X-Patchwork-Id: 13760769 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.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 38FB3187877; Mon, 12 Aug 2024 15:30:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723476652; cv=none; b=hJSTg2OLv2zplFBSft/AB0QxRsih2isZbrTtR6pcsfZXXMGE7d0h+LLgOUxBnpZe8+y8/zig9Xd3a4ca+xcoArHEegyyTrnwxKHuHdOX5Dj5pGYFCTp2J3mifKGkTkO/IEEjOU/hlqf1/EbgEapqMjWU3bsNbknS2scFweDZTYk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1723476652; c=relaxed/simple; bh=/694xjNaYe75aY6C7Vr2retEXvVxynOW1pGlj6x4h6k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XDZ1gN/1ZclH2Wxdyb27mRmZ/jXGaGepQf0iuHJpf89PwKXUMeD3n1b3qX7d61T4Nivgjrc2rH5cIzRHINL0PT8K7WKb0rW5ib8mZkG/UOERpXfYN16IkSpYrcY9i9V1ZJm1e4Bp0qzCDNR9nY4/YoDXE41eXYLzVlv9iDsGZiY= 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=hYWQGqAs; arc=none smtp.client-ip=209.85.208.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="hYWQGqAs" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-5af6a1afa7bso5328825a12.1; Mon, 12 Aug 2024 08:30:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723476649; x=1724081449; 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=B3mEpl3gemolhJql0kO9GZwMm0STDd9PPdpHVFTjscQ=; b=hYWQGqAs63JxwWQGieZpom404OZpS7GLIEuwBg+VmsGd7VFGbPR9vBr4kEZpYItdZp sz0EV1lERI0sAM/UZgT2Jwz/JktWqmhuqwsDD0VgBY2qtKsodikKl2n1g1f2KswSk/Ru YuPwRYNcsZa5UZ+2MmeQspgRrXqQbInJTo5UXwJpOpAvaKVi3GVAVTRaPoM0KiurbXhj 2g72GROXfYI8t6VuJXU/unIGL+fnXUm98SC5xxaDzQj2k1GQi4aOkO0HjTHkPB5/3HrC rpwlYBOevRCwRCdtPQ3k/yxJjB4KZymkbSs3i6AwmC50IQqKzjuvGkiFYG4mfzIbo+zW /bIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723476649; x=1724081449; 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=B3mEpl3gemolhJql0kO9GZwMm0STDd9PPdpHVFTjscQ=; b=dRMtLZj68oKKf6ET8OJdKmojzGUF8vAdREKqzHrwzi6D6/lbUBd7qtvfSA8qLeiyjy K7S6DYey9yWuRtdVoL8lJOqMa+J2p/gumDr2AsnxTOenDcDTSF7Fh6RS+fM/F35Mpt+V KLucfR4Lmh5yff9FlecF2Mvqkzi+rCYeW41mBiZjY6un4MqpqjCaq/8sZByGDzlhrkHJ Ab7oX3+Ai7prQDufqCxcjtJ8uy6qpl3XVLbJZ0KHECjT2mtxWJTs1TUMpPD3W9TPfUle RKJLRFrtLY7dUtqa7mQXo80jg3d8OoGeLR3keM9498kmXYDHIA3q5iPv/3sfndxB/Wnk 7L1g== X-Forwarded-Encrypted: i=1; AJvYcCXjVVL6sUzfI41eipB56eKjKOIZn0D5RUcA5ShBsn6Btm3aSC3uXH7Uz2OedJc4bCTQOHgGEtlzVqWsWnOEXAEjcv6dZm7gQ9+RcnhmGiHgzBVAOV7t4shqEwVARyt72Zq71jcM287ETYpp6zQUdsyZCYJd65lxzAvfVdPMrlWz9Q== X-Gm-Message-State: AOJu0Yy/OzxyaKNd0xgTKeDnfI6RFs+mwGzIEsAEYe6I4jzqV65UXSN2 vTiTcxLTn38dUrxAZMoqbWTEcr+5FDNrmlHdJ7hLrGs5pmZgDuKG X-Google-Smtp-Source: AGHT+IHXfYbGN3gzx5xZ7yyca+anhNkEk7uILr9vttqcEULcdYoakS4nVxw2xsawcVcgF5/um0lldA== X-Received: by 2002:a05:6402:1911:b0:5a1:c7d1:ec5f with SMTP id 4fb4d7f45d1cf-5bd44c7c5f5mr431154a12.35.1723476649472; Mon, 12 Aug 2024 08:30:49 -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-5bd196a666fsm2192535a12.46.2024.08.12.08.30.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Aug 2024 08:30:49 -0700 (PDT) From: vtpieter@gmail.com To: Woojung Huh , UNGLinuxDriver@microchip.com, Andrew Lunn , Florian Fainelli , Vladimir Oltean , David S Miller , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Marek Vasut Cc: Woojung Huh , netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Pieter Van Trappen Subject: [PATCH net-next v5 6/6] net: dsa: microchip: fix tag_ksz egress mask for KSZ8795 family Date: Mon, 12 Aug 2024 17:29:57 +0200 Message-ID: <20240812153015.653044-7-vtpieter@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240812153015.653044-1-vtpieter@gmail.com> References: <20240812153015.653044-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 Fix the tag_ksz egress mask for DSA_TAG_PROTO_KSZ8795, the port is encoded in the two and not three LSB. This fix is for completeness, for example the bug doesn't manifest itself on the KSZ8794 because bit 2 seems to be always zero. Signed-off-by: Pieter Van Trappen --- net/dsa/tag_ksz.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c index ee7b272ab715..15d9f8d28ffc 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] & GENMASK(1, 0), KSZ_EGRESS_TAG_LEN); } static const struct dsa_device_ops ksz8795_netdev_ops = {