From patchwork Mon Jun 3 06:49:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: FUJITA Tomonori X-Patchwork-Id: 13683341 X-Patchwork-Delegate: kuba@kernel.org Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.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 980303C48E for ; Mon, 3 Jun 2024 06:53:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717397586; cv=none; b=TIRKrLqHHHi1NDheKPCdBJDtFfMDxgsfa01XrduTkz4b6T/IhkFSokTLajg/X5HIcWWRH6KEX86UAnDedWCZnl6vY1Q6giA6dFmFMN4FWuDf7AZujAG9sLRTCTVNhw4NIyqeyaXGhi0yLdfCkcaMnOVP9WH55vxn49EojceMGfM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717397586; c=relaxed/simple; bh=lxSuDzxelluWrkd/dPcXHFbht9L7RLB/Kl2OdvIB1Uo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=anE9XYkb7RE96tfTGk7KfPK+e9tIXR3tVpVef1fME732XblC3y2jkUP30BAgiId8YGXvoI3QMp5ZlBj02cccfkMOhkdhDxX3ZBRXrlkkeq5K6OI7WCrbZiSuK+DLnuNq2ZZjI5sZDme92zJd0Tm2k/XnYfEo1rZOo0K34E3++qg= 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=GcJKGMFh; arc=none smtp.client-ip=209.85.216.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="GcJKGMFh" Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-2c1b39ba2afso507719a91.2 for ; Sun, 02 Jun 2024 23:53:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1717397583; x=1718002383; 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=3mwLofIuNdNOYFG0yFnssUhQZu+hUGmWMor0bSOpq3c=; b=GcJKGMFhm+Jj1q291r4z8f0jYgaLX3awBr4hYKVaGghDsHsJJhS5XXDNIMiC5ptdKQ jARIReEdXlq73Z1DvRYiw1aIbNkFF+7APLhTWZAMx2WY1MdtFl3PjnFUcOsHILNKzq3N j4XjGgsIyR7G+7QbxoC9f59uKHwkHwVea9TJbonikuj0aS0FFK+Lt/itntcv6YQnu2/0 qpUW0yPHPzOXfZjyL7NJof3dDi2AobcD1b7kEvrliHdEo2ulgsjpeLv3mIhpTVZfu09I 96ocul3nwIl8BeYX/y02GeYHJdFSk0fkmK9svE3b0EvqEidzGGypC0WmdFWG8fzLbxEr BDzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717397583; x=1718002383; 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=3mwLofIuNdNOYFG0yFnssUhQZu+hUGmWMor0bSOpq3c=; b=knZkngVOFS0hUp1YsibN8yMchh2O6P/zZfBb5lTBVYHbr7z61tj+HZqbUAkkNDmyL/ HnTl5lxS/K+Xp/lZfZbKxSihYYHcBbpN6WElpYYXf1lOBASF6qyO/s+SMmFE+s5j4TyM U5J+a295JQTWG0byMdHNNMFMSVeB21pviUUIAJn/32WdCg8i+lVWYjLDIj5YVthv4PGQ BVOQmHCN1Odgotc1n1t6ZzZalZm/xQiuErFfX7tHCnu7RnnO/w1Z1wiGf/Ioz4P5iAXu acgM85IbuqlAGIflggVDNtqptzvsRrLbMAA4+qGbocfgb3OodO2BBMox6f/A6p4M9xvd NOeQ== X-Gm-Message-State: AOJu0Yz4sabaUtGLgzLDCYbt5TXbxyhgR8w++n1BwYFIMDYLToAm9Y+g 6W8pbNo6l6z4nu4/f2JGpGQIC0k1F5bZ+xdspST9WFhH8qQbiVIYQnIN1gbU X-Google-Smtp-Source: AGHT+IGir90fDB1Ixet3eGYK6nAywOKuV1H9ShhGI0o4w/WCr+EK4ZFTctC/oC2/kVTL4mYUqpEhWA== X-Received: by 2002:a17:90b:151:b0:2bd:76ee:48c2 with SMTP id 98e67ed59e1d1-2c1dc4b2954mr7258301a91.0.1717397583475; Sun, 02 Jun 2024 23:53:03 -0700 (PDT) Received: from rpi.. (p5261226-ipxg23801hodogaya.kanagawa.ocn.ne.jp. [180.15.241.226]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2c1c27e293csm5448263a91.28.2024.06.02.23.53.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 02 Jun 2024 23:53:03 -0700 (PDT) From: FUJITA Tomonori To: netdev@vger.kernel.org Cc: andrew@lunn.ch, horms@kernel.org, kuba@kernel.org, jiri@resnulli.us, pabeni@redhat.com, linux@armlinux.org.uk, hfdevel@gmx.net, naveenm@marvell.com, jdamato@fastly.com Subject: [PATCH net-next v8 6/6] net: tn40xx: add phylink support Date: Mon, 3 Jun 2024 15:49:55 +0900 Message-Id: <20240603064955.58327-7-fujita.tomonori@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240603064955.58327-1-fujita.tomonori@gmail.com> References: <20240603064955.58327-1-fujita.tomonori@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 This patch adds supports for multiple PHY hardware with phylink. The adapters with TN40xx chips use multiple PHY hardware; AMCC QT2025, TI TLK10232, Aqrate AQR105, and Marvell 88X3120, 88X3310, and MV88E2010. For now, the PCI ID table of this driver enables adapters using only QT2025 PHY. I've tested this driver and the QT2025 PHY driver (SFP+ 10G SR) with Edimax EN-9320 10G adapter. Signed-off-by: FUJITA Tomonori --- drivers/net/ethernet/tehuti/Kconfig | 1 + drivers/net/ethernet/tehuti/Makefile | 2 +- drivers/net/ethernet/tehuti/tn40.c | 33 ++++++++++- drivers/net/ethernet/tehuti/tn40.h | 8 +++ drivers/net/ethernet/tehuti/tn40_phy.c | 76 ++++++++++++++++++++++++++ 5 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 drivers/net/ethernet/tehuti/tn40_phy.c diff --git a/drivers/net/ethernet/tehuti/Kconfig b/drivers/net/ethernet/tehuti/Kconfig index 2b3b5a8c7fbf..6db2c9817445 100644 --- a/drivers/net/ethernet/tehuti/Kconfig +++ b/drivers/net/ethernet/tehuti/Kconfig @@ -28,6 +28,7 @@ config TEHUTI_TN40 depends on PCI select PAGE_POOL select FW_LOADER + select PHYLINK help This driver supports 10G Ethernet adapters using Tehuti Networks TN40xx chips. Currently, adapters with Applied Micro Circuits diff --git a/drivers/net/ethernet/tehuti/Makefile b/drivers/net/ethernet/tehuti/Makefile index 7a0fe586a243..0d4f4d63a65c 100644 --- a/drivers/net/ethernet/tehuti/Makefile +++ b/drivers/net/ethernet/tehuti/Makefile @@ -5,5 +5,5 @@ obj-$(CONFIG_TEHUTI) += tehuti.o -tn40xx-y := tn40.o tn40_mdio.o +tn40xx-y := tn40.o tn40_mdio.o tn40_phy.o obj-$(CONFIG_TEHUTI_TN40) += tn40xx.o diff --git a/drivers/net/ethernet/tehuti/tn40.c b/drivers/net/ethernet/tehuti/tn40.c index 52e2adfed4b3..4bfa29be69aa 100644 --- a/drivers/net/ethernet/tehuti/tn40.c +++ b/drivers/net/ethernet/tehuti/tn40.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -944,7 +945,7 @@ static void tn40_tx_push_desc_safe(struct tn40_priv *priv, void *data, int size) } } -static int tn40_set_link_speed(struct tn40_priv *priv, u32 speed) +int tn40_set_link_speed(struct tn40_priv *priv, u32 speed) { u32 val; int i; @@ -1374,6 +1375,10 @@ static void tn40_stop(struct tn40_priv *priv) static int tn40_close(struct net_device *ndev) { struct tn40_priv *priv = netdev_priv(ndev); + + phylink_stop(priv->phylink); + phylink_disconnect_phy(priv->phylink); + napi_disable(&priv->napi); netif_napi_del(&priv->napi); tn40_stop(priv); @@ -1392,6 +1397,14 @@ static int tn40_open(struct net_device *dev) return ret; } napi_enable(&priv->napi); + ret = phylink_connect_phy(priv->phylink, priv->phydev); + if (ret) { + napi_disable(&priv->napi); + tn40_stop(priv); + netdev_err(dev, "failed to connect to phy %d\n", ret); + return ret; + } + phylink_start(priv->phylink); netif_start_queue(priv->ndev); return 0; } @@ -1668,6 +1681,12 @@ static int tn40_probe(struct pci_dev *pdev, const struct pci_device_id *ent) goto err_unset_drvdata; } + ret = tn40_mdiobus_init(priv); + if (ret) { + dev_err(&pdev->dev, "failed to initialize mdio bus.\n"); + goto err_free_irq; + } + priv->stats_flag = ((tn40_read_reg(priv, TN40_FPGA_VER) & 0xFFF) != 308); @@ -1676,19 +1695,26 @@ static int tn40_probe(struct pci_dev *pdev, const struct pci_device_id *ent) TN40_IR_TMR1; tn40_mac_init(priv); + ret = tn40_phy_register(priv); + if (ret) { + dev_err(&pdev->dev, "failed to set up PHY.\n"); + goto err_free_irq; + } ret = tn40_priv_init(priv); if (ret) { dev_err(&pdev->dev, "failed to initialize tn40_priv.\n"); - goto err_free_irq; + goto err_unregister_phydev; } ret = register_netdev(ndev); if (ret) { dev_err(&pdev->dev, "failed to register netdev.\n"); - goto err_free_irq; + goto err_unregister_phydev; } return 0; +err_unregister_phydev: + tn40_phy_unregister(priv); err_free_irq: pci_free_irq_vectors(pdev); err_unset_drvdata: @@ -1709,6 +1735,7 @@ static void tn40_remove(struct pci_dev *pdev) unregister_netdev(ndev); + tn40_phy_unregister(priv); pci_free_irq_vectors(priv->pdev); pci_set_drvdata(pdev, NULL); iounmap(priv->regs); diff --git a/drivers/net/ethernet/tehuti/tn40.h b/drivers/net/ethernet/tehuti/tn40.h index 05a9adf9fe5a..fbdc62612f1f 100644 --- a/drivers/net/ethernet/tehuti/tn40.h +++ b/drivers/net/ethernet/tehuti/tn40.h @@ -143,6 +143,9 @@ struct tn40_priv { char *b0_va; /* Virtual address of buffer */ struct mii_bus *mdio; + struct phy_device *phydev; + struct phylink *phylink; + struct phylink_config phylink_config; }; /* RX FREE descriptor - 64bit */ @@ -220,6 +223,11 @@ static inline void tn40_write_reg(struct tn40_priv *priv, u32 reg, u32 val) writel(val, priv->regs + reg); } +int tn40_set_link_speed(struct tn40_priv *priv, u32 speed); + int tn40_mdiobus_init(struct tn40_priv *priv); +int tn40_phy_register(struct tn40_priv *priv); +void tn40_phy_unregister(struct tn40_priv *priv); + #endif /* _TN40XX_H */ diff --git a/drivers/net/ethernet/tehuti/tn40_phy.c b/drivers/net/ethernet/tehuti/tn40_phy.c new file mode 100644 index 000000000000..4a498ef8dcac --- /dev/null +++ b/drivers/net/ethernet/tehuti/tn40_phy.c @@ -0,0 +1,76 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* Copyright (c) Tehuti Networks Ltd. */ + +#include +#include +#include + +#include "tn40.h" + +static struct tn40_priv *tn40_config_to_priv(struct phylink_config *config) +{ + return container_of(config, struct tn40_priv, phylink_config); +} + +static void tn40_link_up(struct phylink_config *config, struct phy_device *phy, + unsigned int mode, phy_interface_t interface, + int speed, int duplex, bool tx_pause, bool rx_pause) +{ + struct tn40_priv *priv = tn40_config_to_priv(config); + + tn40_set_link_speed(priv, speed); + netif_wake_queue(priv->ndev); +} + +static void tn40_link_down(struct phylink_config *config, unsigned int mode, + phy_interface_t interface) +{ + struct tn40_priv *priv = tn40_config_to_priv(config); + + netif_stop_queue(priv->ndev); + tn40_set_link_speed(priv, 0); +} + +static void tn40_mac_config(struct phylink_config *config, unsigned int mode, + const struct phylink_link_state *state) +{ +} + +static const struct phylink_mac_ops tn40_mac_ops = { + .mac_config = tn40_mac_config, + .mac_link_up = tn40_link_up, + .mac_link_down = tn40_link_down, +}; + +int tn40_phy_register(struct tn40_priv *priv) +{ + struct phylink_config *config; + struct phy_device *phydev; + struct phylink *phylink; + + phydev = phy_find_first(priv->mdio); + if (!phydev) { + dev_err(&priv->pdev->dev, "PHY isn't found\n"); + return -1; + } + + config = &priv->phylink_config; + config->dev = &priv->ndev->dev; + config->type = PHYLINK_NETDEV; + config->mac_capabilities = MAC_10000FD; + __set_bit(PHY_INTERFACE_MODE_XAUI, config->supported_interfaces); + + phylink = phylink_create(config, NULL, PHY_INTERFACE_MODE_XAUI, + &tn40_mac_ops); + if (IS_ERR(phylink)) + return PTR_ERR(phylink); + + priv->phydev = phydev; + priv->phylink = phylink; + return 0; +} + +void tn40_phy_unregister(struct tn40_priv *priv) +{ + phylink_destroy(priv->phylink); +}