Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp188283rdb; Tue, 5 Dec 2023 02:37:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IFeAV/9D9kbyyKZQ9gR0akF++VTd5e6rFlwCAXoHI2shc7rHV1Sa8+F7onJwQKxPKCzl+4x X-Received: by 2002:a17:902:ee4d:b0:1d0:5ac4:4959 with SMTP id 13-20020a170902ee4d00b001d05ac44959mr5083952plo.6.1701772629182; Tue, 05 Dec 2023 02:37:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701772629; cv=none; d=google.com; s=arc-20160816; b=LEIW0L+jposMRmkkTAzyXAtMamnmhS+spEe4HXHUANBnlCmNHavsBiQx9UMcq3X6DT xcl6dxsqavaYJkiIWUrgEAIm6qXekgv12hNzBUY40PaPO3NA3fbO6AIZ7IsJPd+i2VqB 57VjjiX6Kwonnn17HJ/uCv4/8nO9SCqK+zpmJJHQcV8qj9/6YJ7d/IgAwcMRZ5dTmoT7 /VgUzAO+h7F0F1zw+yPD3K18zRx6qg6erg516Auu/xXosTBWjDRipkgiyuAuZ30OU79/ gQYH4Uup77q8PmGHAo1pqpNSyZA8BkIO2JOivr4ZM1WsMXr+JmRuOiW+KGHA3AkLGgwn f+GQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fzWpHNK+8WZxV0Za4rmkABjOws2ounqa1/6k9XNQavs=; fh=NoYD4WQZNjSG2Bb9ocssXw4U79pWAZvdivFB0JgByN0=; b=DqiS9tBy4BLkEDTuEnBkudYeSx4Qy+PHzRN3pytjfFG3gKTY4O7ry1mdylTtbT/jLh m9vcMwirIq/YqcKwKSntGgsBrQxAS1IW0/lyP7ZKlCjuj2Z5heUI0sMnSkMFcPlwb6sn ddo5Fv9jJXB5rigI/X/Dbf8ceDF+5cipC4WZ90dQyYPcZvJ2LjvONc2xKOUOkdtjYkTA F1TGrRX/5/VW/Kb+hY/8wcWITNQSP3S/teC1rG9+QlXdXB4o2d/6j/iDigiKudv+CS8m FIdqvp7LkKwCgWZGDgxz3UX5NhLSHq6P05IsZvpXD4LMs/3lLy3ffekT2l9DJxqmBT8w LV4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Toqk7lDP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id w10-20020a170902a70a00b001b973681493si9039590plq.16.2023.12.05.02.37.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 02:37:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Toqk7lDP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 6B567804B113; Tue, 5 Dec 2023 02:37:01 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346686AbjLEKgZ (ORCPT + 99 others); Tue, 5 Dec 2023 05:36:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235148AbjLEKgO (ORCPT ); Tue, 5 Dec 2023 05:36:14 -0500 Received: from mail-lj1-x236.google.com (mail-lj1-x236.google.com [IPv6:2a00:1450:4864:20::236]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FD5B1B1; Tue, 5 Dec 2023 02:36:16 -0800 (PST) Received: by mail-lj1-x236.google.com with SMTP id 38308e7fff4ca-2c9f413d6b2so33424691fa.1; Tue, 05 Dec 2023 02:36:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701772574; x=1702377374; 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=fzWpHNK+8WZxV0Za4rmkABjOws2ounqa1/6k9XNQavs=; b=Toqk7lDPeI62bqsG6S+Ts1Hj65j5e5wanw8cW3J/cfIbwX6GYyJj7OE7UyUhKyzP9i GnL2oWYJU2pbTKA7LPrJK6fJo6zsrvvbOroTNwUgzxuhviU5jdCNU5EcditTiraFu2Ek 92330nX91CtfAGUWkSyfEwF7oEHxr9lunYFuVLdHtF3y5txHJb0Q4YWv8pwciYPp8YAO VTShj5UZFfmW3Z0omFcL0+PK0FHBaN289CNa6sNYTy43Bb0aS80HKy86sYEW7TqAaquU HC0HxnAjMFJsnq8NwXjSwKYjTxnGLXv7x1HMsocv2HsUQvtXQUzxpbmaJ1roq00A0q2z YsWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701772574; x=1702377374; 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=fzWpHNK+8WZxV0Za4rmkABjOws2ounqa1/6k9XNQavs=; b=jPELmRDnT0ek8rK3hNM/DcXrDbLNLrhCEK/Tl8OmZ6UUdXRX5UoXvW4wKJJdqaGRh/ X78aBWItPmjSa+YOINKJYcL2xwspS6A8OrIFyhExDE4wOHTr2BTXVvtSW9iWXcLsBCMM r2ircErYC3yX8EZzU7y4PdO7XlxMT43trNs0vDcDOxnD84MBqLRMBZlHmfMF2ZtPx9MJ 5gReMsO1ejzQ9LCXfkTW2g2wynx4/VZjuXvaj20Y3AejBODmcRvfyR7okrF59HkRVR5f fSmt+k+Hxu2TP+0WL6zvMa+nF1J4yh0UtPoKhqUr7MVKWTgJHFtyCY+k6kfs3nnjOb3z yTqA== X-Gm-Message-State: AOJu0YxEKVv4FaxoXhngvnoAZm/j2QikEbRVvQ4/TQb42svQYHqyElEh SfNVarEDLGyrDesWHERZmx4DiYApM2JV6g== X-Received: by 2002:a05:6512:2803:b0:50b:f8e6:caa2 with SMTP id cf3-20020a056512280300b0050bf8e6caa2mr1274366lfb.31.1701772574341; Tue, 05 Dec 2023 02:36:14 -0800 (PST) Received: from localhost ([178.176.56.174]) by smtp.gmail.com with ESMTPSA id y23-20020a197517000000b0050aaa716c15sm720366lfe.51.2023.12.05.02.36.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 02:36:13 -0800 (PST) From: Serge Semin To: Andrew Lunn , Heiner Kallweit , Russell King , Alexandre Torgue , Jose Abreu , Jose Abreu , Maxime Chevallier , Tomer Maimon , Rob Herring , Krzysztof Kozlowski , Conor Dooley , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Serge Semin , openbmc@lists.ozlabs.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 07/16] net: pcs: xpcs: Split up xpcs_create() content to sub-functions Date: Tue, 5 Dec 2023 13:35:28 +0300 Message-ID: <20231205103559.9605-8-fancer.lancer@gmail.com> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20231205103559.9605-1-fancer.lancer@gmail.com> References: <20231205103559.9605-1-fancer.lancer@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 05 Dec 2023 02:37:01 -0800 (PST) As a final preparation before adding the DW XPCS MDIO-device driver support let's split the xpcs_create() function code up to a set of small sub-functions. Thus the method implementation will get to look simpler and turn to be more coherent. Further updates will just touch the new methods a bit: add platform-specific device info, add device reference clock getting and enabling. This update implies the xpcs_create() to call the next static methods: xpcs_create_data() - create the DW XPCS device descriptor, xpcs_init_id() - find XPCS ID instance and save it in the device descriptor, xpcs_init_iface() - find MAC/PCS interface descriptor and perform basice initialization specific to it: soft-reset, disable polling. The update doesn't cause any semantic change but merely makes the code better looking and ready for adding new features support. Note in addition to that the xpcs_destroy() is moved to be below the xpcs_create_mdiodev() function as the driver now implies having the protagonist-then-antagonist functions definition order. Signed-off-by: Serge Semin --- drivers/net/pcs/pcs-xpcs.c | 102 +++++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 32 deletions(-) diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c index a53376472394..ea6f56339595 100644 --- a/drivers/net/pcs/pcs-xpcs.c +++ b/drivers/net/pcs/pcs-xpcs.c @@ -1365,70 +1365,97 @@ static const struct phylink_pcs_ops xpcs_phylink_ops = { .pcs_link_up = xpcs_link_up, }; -static struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev, - phy_interface_t interface) +static struct dw_xpcs *xpcs_create_data(struct mdio_device *mdiodev) { struct dw_xpcs *xpcs; - u32 xpcs_id; - int i, ret; xpcs = kzalloc(sizeof(*xpcs), GFP_KERNEL); if (!xpcs) return ERR_PTR(-ENOMEM); xpcs->mdiodev = mdiodev; + xpcs->pcs.ops = &xpcs_phylink_ops; + xpcs->pcs.neg_mode = true; + xpcs->pcs.poll = true; + + return xpcs; +} + +static void xpcs_free_data(struct dw_xpcs *xpcs) +{ + kfree(xpcs); +} + +static int xpcs_init_id(struct dw_xpcs *xpcs) +{ + u32 xpcs_id; + int i, ret; xpcs_id = xpcs_get_id(xpcs); for (i = 0; i < ARRAY_SIZE(xpcs_id_list); i++) { const struct xpcs_id *entry = &xpcs_id_list[i]; - const struct xpcs_compat *compat; if ((xpcs_id & entry->mask) != entry->id) continue; xpcs->id = entry; - compat = xpcs_find_compat(entry, interface); - if (!compat) { - ret = -ENODEV; - goto out; - } + break; + } - ret = xpcs_dev_flag(xpcs); - if (ret) - goto out; + if (!xpcs->id) + return -ENODEV; - xpcs->pcs.ops = &xpcs_phylink_ops; - xpcs->pcs.neg_mode = true; + ret = xpcs_dev_flag(xpcs); + if (ret < 0) + return ret; - if (xpcs->dev_flag != DW_DEV_TXGBE) { - xpcs->pcs.poll = true; + return 0; +} - ret = xpcs_soft_reset(xpcs, compat); - if (ret) - goto out; - } +static int xpcs_init_iface(struct dw_xpcs *xpcs, phy_interface_t interface) +{ + const struct xpcs_compat *compat; - return xpcs; + compat = xpcs_find_compat(xpcs->id, interface); + if (!compat) + return -EINVAL; + + if (xpcs->dev_flag == DW_DEV_TXGBE) { + xpcs->pcs.poll = false; + return 0; } - ret = -ENODEV; + return xpcs_soft_reset(xpcs, compat); +} + +static struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev, + phy_interface_t interface) +{ + struct dw_xpcs *xpcs; + int ret; + + xpcs = xpcs_create_data(mdiodev); + if (IS_ERR(xpcs)) + return xpcs; + + ret = xpcs_init_id(xpcs); + if (ret) + goto out; + + ret = xpcs_init_iface(xpcs, interface); + if (ret) + goto out; + + return xpcs; out: - kfree(xpcs); + xpcs_free_data(xpcs); return ERR_PTR(ret); } -void xpcs_destroy(struct dw_xpcs *xpcs) -{ - if (xpcs) - mdio_device_put(xpcs->mdiodev); - kfree(xpcs); -} -EXPORT_SYMBOL_GPL(xpcs_destroy); - struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr, phy_interface_t interface) { @@ -1455,4 +1482,15 @@ struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr, } EXPORT_SYMBOL_GPL(xpcs_create_mdiodev); +void xpcs_destroy(struct dw_xpcs *xpcs) +{ + if (!xpcs) + return; + + mdio_device_put(xpcs->mdiodev); + + xpcs_free_data(xpcs); +} +EXPORT_SYMBOL_GPL(xpcs_destroy); + MODULE_LICENSE("GPL v2"); -- 2.42.1