From: mike.marciniszyn@gmail.com
To: Alexander Duyck <alexanderduyck@fb.com>,
Jakub Kicinski <kuba@kernel.org>,
kernel-team@meta.com, Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Paolo Abeni <pabeni@redhat.com>,
Jiawen Wu <jiawenwu@trustnetic.com>,
Mengyuan Lou <mengyuanlou@net-swift.com>,
Heiner Kallweit <hkallweit1@gmail.com>,
Russell King <linux@armlinux.org.uk>,
Mohsin Bashir <mohsin.bashr@gmail.com>,
Kees Cook <kees@kernel.org>, Andrew Lunn <andrew@lunn.ch>
Cc: mike.marciniszyn@gmail.com, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: [PATCH net-next v3 2/4] net: pcs: xpcs: Allow for multiple addr in creation
Date: Tue, 26 May 2026 20:09:56 -0400 [thread overview]
Message-ID: <20260527000958.81108-3-mike.marciniszyn@gmail.com> (raw)
In-Reply-To: <20260527000958.81108-1-mike.marciniszyn@gmail.com>
From: "Mike Marciniszyn (Meta)" <mike.marciniszyn@gmail.com>
The DW channel 10g-100g IP builds the PCS out of multiple addr
mdio addresses.
Add xpcs_create_mdiodevs() and xpcs_create_pcs_mdiodevs calls so that a
driver using the above part can tell xpcs the addr values in one call.
xpcs_create_data(), xpcs_create(), and xpcs_free_data() are extended
to accept a variable number of mdio devices. Existing singleton
interfaces are re-cast as a having an array pointing to a single
mdio device.
Reviewed-by: Alexander Duyck <alexanderduyck@fb.com>
Signed-off-by: Mike Marciniszyn (Meta) <mike.marciniszyn@gmail.com>
---
v3:
- New to series
- use new call to xpcs_create_pcs_mdiodevs() in fbnic
- Add xpcs_mdev_write_ch()
- Add doc comments for xpcs_create_mdiodevs()
v2.2:
- New to series
.../net/ethernet/meta/fbnic/fbnic_phylink.c | 4 +-
drivers/net/pcs/pcs-xpcs.c | 103 +++++++++++++++---
drivers/net/pcs/pcs-xpcs.h | 1 +
include/linux/pcs/pcs-xpcs.h | 5 +-
4 files changed, 93 insertions(+), 20 deletions(-)
diff --git a/drivers/net/ethernet/meta/fbnic/fbnic_phylink.c b/drivers/net/ethernet/meta/fbnic/fbnic_phylink.c
index 09c5225111be..88fc78d55c7a 100644
--- a/drivers/net/ethernet/meta/fbnic/fbnic_phylink.c
+++ b/drivers/net/ethernet/meta/fbnic/fbnic_phylink.c
@@ -200,9 +200,11 @@ int fbnic_phylink_create(struct net_device *netdev)
struct fbnic_dev *fbd = fbn->fbd;
struct phylink_pcs *pcs;
struct phylink *phylink;
+ /* See fbnic_mdio.c addr usage */
+ int addrs[] = { 0, 1 };
int err;
- pcs = xpcs_create_pcs_mdiodev(fbd->mdio_bus, 0);
+ pcs = xpcs_create_pcs_mdiodevs(fbd->mdio_bus, addrs, ARRAY_SIZE(addrs));
if (IS_ERR(pcs)) {
err = PTR_ERR(pcs);
dev_err(fbd->dev, "Failed to create PCS device: %d\n", err);
diff --git a/drivers/net/pcs/pcs-xpcs.c b/drivers/net/pcs/pcs-xpcs.c
index 3c11c9552b60..d59ba99c3764 100644
--- a/drivers/net/pcs/pcs-xpcs.c
+++ b/drivers/net/pcs/pcs-xpcs.c
@@ -214,9 +214,15 @@ int xpcs_read(struct dw_xpcs *xpcs, int dev, u32 reg)
return mdiodev_c45_read(xpcs->mdiodev[0], dev, reg);
}
+static int
+xpcs_mdev_write_ch(struct dw_xpcs *xpcs, int ch, int dev, u32 reg, u16 val)
+{
+ return mdiodev_c45_write(xpcs->mdiodev[ch], dev, reg, val);
+}
+
int xpcs_write(struct dw_xpcs *xpcs, int dev, u32 reg, u16 val)
{
- return mdiodev_c45_write(xpcs->mdiodev[0], dev, reg, val);
+ return xpcs_mdev_write_ch(xpcs, 0, dev, reg, val);
}
int xpcs_modify(struct dw_xpcs *xpcs, int dev, u32 reg, u16 mask, u16 set)
@@ -1524,16 +1530,21 @@ static int xpcs_identify(struct dw_xpcs *xpcs)
return -ENODEV;
}
-static struct dw_xpcs *xpcs_create_data(struct mdio_device *mdiodev)
+static struct dw_xpcs *
+xpcs_create_data(struct mdio_device **mdiodev, int channels)
{
struct dw_xpcs *xpcs;
+ int i;
xpcs = kzalloc_obj(*xpcs);
if (!xpcs)
return ERR_PTR(-ENOMEM);
- mdio_device_get(mdiodev);
- xpcs->mdiodev[0] = mdiodev;
+ xpcs->channels = channels;
+ for (i = 0; i < channels; i++) {
+ mdio_device_get(mdiodev[i]);
+ xpcs->mdiodev[i] = mdiodev[i];
+ }
xpcs->pcs.ops = &xpcs_phylink_ops;
xpcs->pcs.poll = true;
@@ -1542,7 +1553,10 @@ static struct dw_xpcs *xpcs_create_data(struct mdio_device *mdiodev)
static void xpcs_free_data(struct dw_xpcs *xpcs)
{
- mdio_device_put(xpcs->mdiodev[0]);
+ int i;
+
+ for (i = 0; i < xpcs->channels; i++)
+ mdio_device_put(xpcs->mdiodev[i]);
kfree(xpcs);
}
@@ -1591,12 +1605,12 @@ static int xpcs_init_id(struct dw_xpcs *xpcs)
return xpcs_identify(xpcs);
}
-static struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev)
+static struct dw_xpcs *xpcs_create(struct mdio_device **mdiodev, int channels)
{
struct dw_xpcs *xpcs;
int ret;
- xpcs = xpcs_create_data(mdiodev);
+ xpcs = xpcs_create_data(mdiodev, channels);
if (IS_ERR(xpcs))
return xpcs;
@@ -1628,24 +1642,34 @@ static struct dw_xpcs *xpcs_create(struct mdio_device *mdiodev)
}
/**
- * xpcs_create_mdiodev() - create a DW xPCS instance with the MDIO @addr
+ * xpcs_create_mdiodevs() - create a DW xPCS instance with multiple @addrs
* @bus: pointer to the MDIO-bus descriptor for the device to be looked at
- * @addr: device MDIO-bus ID
+ * @addrs: an array of int
+ * @channels: the number of addrs items or channels
*
- * Return: a pointer to the DW XPCS handle if successful, otherwise -ENODEV if
+ * Return: a pointer to the DW XPCS handle if successful, -EINVAL if the
+ * addrs is NULL or channels is out of bounds, otherwise -ENODEV if
* the PCS device couldn't be found on the bus and other negative errno related
* to the data allocation and MDIO-bus communications.
*/
-struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr)
+struct dw_xpcs *
+xpcs_create_mdiodevs(struct mii_bus *bus, const int *addrs, int channels)
{
- struct mdio_device *mdiodev;
+ struct mdio_device *mdiodev[DW_XPCS_MAX_CHANNELS], *rval;
struct dw_xpcs *xpcs;
+ int i;
+
+ if (!addrs || channels <= 0 || channels > DW_XPCS_MAX_CHANNELS)
+ return ERR_PTR(-EINVAL);
- mdiodev = mdio_device_create(bus, addr);
- if (IS_ERR(mdiodev))
- return ERR_CAST(mdiodev);
+ for (i = 0; i < channels; i++) {
+ rval = mdio_device_create(bus, addrs[i]);
+ if (IS_ERR(rval))
+ goto out_nomem;
+ mdiodev[i] = rval;
+ }
- xpcs = xpcs_create(mdiodev);
+ xpcs = xpcs_create(mdiodev, channels);
/* xpcs_create() has taken a refcount on the mdiodev if it was
* successful. If xpcs_create() fails, this will free the mdio
@@ -1653,9 +1677,52 @@ struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr)
* anymore, and putting it here will allow mdio_device_put() in
* xpcs_destroy() to automatically free the mdio device.
*/
- mdio_device_put(mdiodev);
+ for (i = 0; i < channels; i++)
+ mdio_device_put(mdiodev[i]);
return xpcs;
+out_nomem:
+ while (i--)
+ mdio_device_free(mdiodev[i]);
+ return ERR_CAST(rval);
+}
+EXPORT_SYMBOL_GPL(xpcs_create_mdiodevs);
+
+/**
+ * xpcs_create_pcs_mdiodevs() - create a DW xPCS instance with multiple @addrs
+ * @bus: pointer to the MDIO-bus descriptor for the device to be looked at
+ * @addrs: an array of int
+ * @channels: the number of addrs items or channels
+ *
+ * Return: a pointer to the DW XPCS handle if successful, otherwise -ENODEV if
+ * the PCS device couldn't be found on the bus and other negative errno related
+ * to the data allocation and MDIO-bus communications.
+ */
+struct phylink_pcs *
+xpcs_create_pcs_mdiodevs(struct mii_bus *bus, const int *addrs, int channels)
+{
+ struct dw_xpcs *xpcs;
+
+ xpcs = xpcs_create_mdiodevs(bus, addrs, channels);
+ if (IS_ERR(xpcs))
+ return ERR_CAST(xpcs);
+
+ return &xpcs->pcs;
+}
+EXPORT_SYMBOL_GPL(xpcs_create_pcs_mdiodevs);
+
+/**
+ * xpcs_create_mdiodev() - create a DW xPCS instance with the MDIO @addr
+ * @bus: pointer to the MDIO-bus descriptor for the device to be looked at
+ * @addr: device MDIO-bus ID
+ *
+ * Return: a pointer to the DW XPCS handle if successful, otherwise -ENODEV if
+ * the PCS device couldn't be found on the bus and other negative errno related
+ * to the data allocation and MDIO-bus communications.
+ */
+struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr)
+{
+ return xpcs_create_mdiodevs(bus, &addr, 1);
}
EXPORT_SYMBOL_GPL(xpcs_create_mdiodev);
@@ -1693,7 +1760,7 @@ struct dw_xpcs *xpcs_create_fwnode(struct fwnode_handle *fwnode)
if (!mdiodev)
return ERR_PTR(-EPROBE_DEFER);
- xpcs = xpcs_create(mdiodev);
+ xpcs = xpcs_create(&mdiodev, 1);
/* xpcs_create() has taken a refcount on the mdiodev if it was
* successful. If xpcs_create() fails, this will free the mdio
diff --git a/drivers/net/pcs/pcs-xpcs.h b/drivers/net/pcs/pcs-xpcs.h
index 5c804cfd47d3..36f4906e689a 100644
--- a/drivers/net/pcs/pcs-xpcs.h
+++ b/drivers/net/pcs/pcs-xpcs.h
@@ -114,6 +114,7 @@ struct dw_xpcs {
struct mdio_device *mdiodev[DW_XPCS_MAX_CHANNELS];
struct clk_bulk_data clks[DW_XPCS_NUM_CLKS];
struct phylink_pcs pcs;
+ int channels;
phy_interface_t interface;
bool need_reset;
u8 eee_mult_fact;
diff --git a/include/linux/pcs/pcs-xpcs.h b/include/linux/pcs/pcs-xpcs.h
index 36073f7b6bb4..6afa8a2aac69 100644
--- a/include/linux/pcs/pcs-xpcs.h
+++ b/include/linux/pcs/pcs-xpcs.h
@@ -53,10 +53,13 @@ struct dw_xpcs;
struct phylink_pcs *xpcs_to_phylink_pcs(struct dw_xpcs *xpcs);
int xpcs_get_an_mode(struct dw_xpcs *xpcs, phy_interface_t interface);
void xpcs_config_eee_mult_fact(struct dw_xpcs *xpcs, u8 mult_fact);
+struct dw_xpcs *
+xpcs_create_mdiodevs(struct mii_bus *bus, const int *addrs, int channels);
struct dw_xpcs *xpcs_create_mdiodev(struct mii_bus *bus, int addr);
struct dw_xpcs *xpcs_create_fwnode(struct fwnode_handle *fwnode);
void xpcs_destroy(struct dw_xpcs *xpcs);
-
+struct phylink_pcs *
+xpcs_create_pcs_mdiodevs(struct mii_bus *bus, const int *addrs, int channels);
struct phylink_pcs *xpcs_create_pcs_mdiodev(struct mii_bus *bus, int addr);
void xpcs_destroy_pcs(struct phylink_pcs *pcs);
--
2.43.0
next prev parent reply other threads:[~2026-05-27 0:10 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-27 0:09 [PATCH net-next v3 0/4] second series for xpcs based rsfec configuratio mike.marciniszyn
2026-05-27 0:09 ` [PATCH net-next v3 1/4] net: pcs: xpcs: Expand mdiodev member as an array mike.marciniszyn
2026-05-27 0:09 ` mike.marciniszyn [this message]
2026-05-27 0:09 ` [PATCH net-next v3 3/4] net: pcs: xpcs: Add hooks for xpcs configuration of rsfec mike.marciniszyn
2026-05-27 0:09 ` [PATCH net-next v3 4/4] net: pcs: xpcs: Add handling for 4 channel rsfec device mike.marciniszyn
2026-06-02 14:20 ` [PATCH net-next v3 0/4] second series for xpcs based rsfec configuratio Simon Horman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260527000958.81108-3-mike.marciniszyn@gmail.com \
--to=mike.marciniszyn@gmail.com \
--cc=alexanderduyck@fb.com \
--cc=andrew+netdev@lunn.ch \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=jiawenwu@trustnetic.com \
--cc=kees@kernel.org \
--cc=kernel-team@meta.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=mengyuanlou@net-swift.com \
--cc=mohsin.bashr@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®