Skip to contentSkip to conversation

r8169: implement SFP support

RFC PATCH In review Fabio Baltieri 2 participants 2 messages Apr 10

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH v2 1/1 r8169: implement SFP support

Implement support for reading the identification and diagnostic information on SFP modules for rtl8127atf devices.

This uses the sfp module, implements a GPIO devices for presence detection and loss of signal and i2c communication using the designware module.

---
Hi,

here's the rework of the v1 I sent as "r8169: implement get_module functions for rtl8127atf", this is now implementing sfp support using the kernel sfp module, using the support nodes as well, including reusing the designware driver for i2c.

Module presence detection seems to work correctly:

[  555.853597] sfp sfp.256: module removed
[  561.628005] sfp sfp.256: module QSFPTEK          QT-SFP+-SR       rev      sn QT8250805132     dc 250806  

Had to guess the gpio input register offset (the out of tree driver does not implement this), hopefully the realtek folks can chime in down the road and other functions can be implemented too.

This is largely a copy paste of the txgbe txgbe_phy.c code, though the pcs and phylink code is missing since as far as I understand it should be implemented separately, so the sfp module here just reports the status via hwmon and is stuck in:

Module state: waitdev

Just looking for early feedback, this is functional as is but I guess it'll have to wait for the phylink support to get implemented first and then rebase on top of it, and I guess a realtek specific variant of the wx,i2c-snps-model property.

Cheers,
Fabio

 drivers/net/ethernet/realtek/Kconfig      |   3 +
 drivers/net/ethernet/realtek/r8169_main.c | 302 +++++++++++++++++++++-
 2 files changed, 304 insertions(+), 1 deletion(-)
drivers/net/ethernet/realtek/Kconfig +3 -0
index 9b0f4f9631db..ae936e1586aa 100644
@@ -88,6 +88,9 @@ config R8169
 	select CRC32
 	select PHYLIB
 	select REALTEK_PHY
+	select REGMAP
+	select SFP
+	select GPIOLIB
 	help
 	  Say Y here if you have a Realtek Ethernet adapter belonging to
 	  the following families:
drivers/net/ethernet/realtek/r8169_main.c +301 -1

339 lines not on this page · raw message

Signature · 1 line
2.47.3
#1 lore raw
Quoted 6 lines · Fabio Baltieri

Implement support for reading the identification and diagnostic information on SFP modules for rtl8127atf devices.

This uses the sfp module, implements a GPIO devices for presence detection and loss of signal and i2c communication using the designware module.

I would probably break this up into smaller patches, GPIO, I2C, and the swnode.

It might be you need to Cc: the GPIO Maintainers, the I2C Maintainers for those patches.

Quoted 24 lines
drivers/net/ethernet/realtek/r8169_main.c +24 -0
+static int r8169_gpio_get(struct gpio_chip *chip, unsigned int offset)
+{
+	struct rtl8169_private *tp = gpiochip_get_data(chip);
+	int val;
+
+	val = r8168_mac_ocp_read(tp, 0xdc30);
+
+	return !!(val & BIT(offset));
+}
+
+static int r8169_gpio_init(struct rtl8169_private *tp)
+{
+	struct gpio_chip *gc;
+	struct pci_dev *pdev = tp->pci_dev;
+	struct device *dev;
+	int ret;
+
+	dev = &pdev->dev;
+
+	gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL);
+	if (!gc)
+		return -ENOMEM;
+
+	gc->label = devm_kasprintf(dev, GFP_KERNEL, "r8169_gpio-%x",

drivers/net/ethernet/realtek/r8169_main.c static int rtl8169_set_link_ksettings(struct net_device *ndev, · line 2543

Quoted 10 lines
drivers/net/ethernet/realtek/r8169_main.c +10 -0
+				   pci_dev_id(pdev));
+	if (!gc->label)
+		return -ENOMEM;
+
+	gc->base = -1;
+	gc->ngpio = 16;
+	gc->owner = THIS_MODULE;
+	gc->parent = dev;
+	gc->fwnode = software_node_fwnode(tp->nodes.group[SWNODE_GPIO]);
+	gc->get = r8169_gpio_get;

So there is no set? The SFP cage has a transmit enable which is generally connected to a GPIO output. You can use it to turn off the laser, which phylink will do when the interface is admin down.

Can you trace the lines from the SFP cage back to the chip? At least see if it connects back?

Are registers 0xdc30 +/- 4 used for anything? Maybe there is 16 GPI and 16 GPO? Although that sounds like a lot of pins. Or it could be there is a direction register, and an output register.

This looks quite good otherwise.

Andrew