* [PATCH net-next 1/7] net: lan743x: Create separate PCS power reset function
2023-07-21 6:00 [PATCH net-next 0/7] Add support to PHYLINK and SFP for PCI11x1x chips Raju Lakkaraju
@ 2023-07-21 6:00 ` Raju Lakkaraju
2023-07-22 20:24 ` Simon Horman
2023-07-21 6:00 ` [PATCH net-next 2/7] net: lan743x: Create separate Link Speed Duplex state function Raju Lakkaraju
` (5 subsequent siblings)
6 siblings, 1 reply; 15+ messages in thread
From: Raju Lakkaraju @ 2023-07-21 6:00 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, linux-kernel, bryan.whitehead, andrew, linux,
UNGLinuxDriver
Create separate PCS power reset function from lan743x_sgmii_config () to use
as subroutine.
Signed-off-by: Raju Lakkaraju <Raju.Lakkaraju@microchip.com>
---
drivers/net/ethernet/microchip/lan743x_main.c | 54 ++++++++++---------
1 file changed, 29 insertions(+), 25 deletions(-)
diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c
index a36f6369f132..dba5576a933b 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.c
+++ b/drivers/net/ethernet/microchip/lan743x_main.c
@@ -1145,6 +1145,34 @@ static int lan743x_pcs_seq_state(struct lan743x_adapter *adapter, u8 state)
return 0;
}
+static int lan743x_pcs_power_reset(struct lan743x_adapter *adapter)
+{
+ int mii_ctl;
+ int ret;
+
+ /* SGMII/1000/2500BASE-X PCS power down */
+ mii_ctl = lan743x_sgmii_read(adapter, MDIO_MMD_VEND2, MII_BMCR);
+ if (mii_ctl < 0)
+ return mii_ctl;
+
+ mii_ctl |= BMCR_PDOWN;
+ ret = lan743x_sgmii_write(adapter, MDIO_MMD_VEND2, MII_BMCR, mii_ctl);
+ if (ret < 0)
+ return ret;
+
+ ret = lan743x_pcs_seq_state(adapter, PCS_POWER_STATE_DOWN);
+ if (ret < 0)
+ return ret;
+
+ /* SGMII/1000/2500BASE-X PCS power up */
+ mii_ctl &= ~BMCR_PDOWN;
+ ret = lan743x_sgmii_write(adapter, MDIO_MMD_VEND2, MII_BMCR, mii_ctl);
+ if (ret < 0)
+ return ret;
+
+ return lan743x_pcs_seq_state(adapter, PCS_POWER_STATE_UP);
+}
+
static int lan743x_sgmii_config(struct lan743x_adapter *adapter)
{
struct net_device *netdev = adapter->netdev;
@@ -1207,31 +1235,7 @@ static int lan743x_sgmii_config(struct lan743x_adapter *adapter)
netif_dbg(adapter, drv, adapter->netdev,
"SGMII 1G mode enable\n");
- /* SGMII/1000/2500BASE-X PCS power down */
- mii_ctl = lan743x_sgmii_read(adapter, MDIO_MMD_VEND2, MII_BMCR);
- if (mii_ctl < 0)
- return mii_ctl;
-
- mii_ctl |= BMCR_PDOWN;
- ret = lan743x_sgmii_write(adapter, MDIO_MMD_VEND2, MII_BMCR, mii_ctl);
- if (ret < 0)
- return ret;
-
- ret = lan743x_pcs_seq_state(adapter, PCS_POWER_STATE_DOWN);
- if (ret < 0)
- return ret;
-
- /* SGMII/1000/2500BASE-X PCS power up */
- mii_ctl &= ~BMCR_PDOWN;
- ret = lan743x_sgmii_write(adapter, MDIO_MMD_VEND2, MII_BMCR, mii_ctl);
- if (ret < 0)
- return ret;
-
- ret = lan743x_pcs_seq_state(adapter, PCS_POWER_STATE_UP);
- if (ret < 0)
- return ret;
-
- return 0;
+ return lan743x_pcs_power_reset(adapter);
}
static void lan743x_mac_set_address(struct lan743x_adapter *adapter,
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH net-next 1/7] net: lan743x: Create separate PCS power reset function
2023-07-21 6:00 ` [PATCH net-next 1/7] net: lan743x: Create separate PCS power reset function Raju Lakkaraju
@ 2023-07-22 20:24 ` Simon Horman
0 siblings, 0 replies; 15+ messages in thread
From: Simon Horman @ 2023-07-22 20:24 UTC (permalink / raw)
To: Raju Lakkaraju
Cc: netdev, davem, kuba, linux-kernel, bryan.whitehead, andrew, linux,
UNGLinuxDriver
On Fri, Jul 21, 2023 at 11:30:13AM +0530, Raju Lakkaraju wrote:
> Create separate PCS power reset function from lan743x_sgmii_config () to use
> as subroutine.
>
> Signed-off-by: Raju Lakkaraju <Raju.Lakkaraju@microchip.com>
> ---
> drivers/net/ethernet/microchip/lan743x_main.c | 54 ++++++++++---------
> 1 file changed, 29 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c
> index a36f6369f132..dba5576a933b 100644
> --- a/drivers/net/ethernet/microchip/lan743x_main.c
> +++ b/drivers/net/ethernet/microchip/lan743x_main.c
...
> static int lan743x_sgmii_config(struct lan743x_adapter *adapter)
> {
> struct net_device *netdev = adapter->netdev;
> @@ -1207,31 +1235,7 @@ static int lan743x_sgmii_config(struct lan743x_adapter *adapter)
> netif_dbg(adapter, drv, adapter->netdev,
> "SGMII 1G mode enable\n");
>
> - /* SGMII/1000/2500BASE-X PCS power down */
> - mii_ctl = lan743x_sgmii_read(adapter, MDIO_MMD_VEND2, MII_BMCR);
> - if (mii_ctl < 0)
> - return mii_ctl;
> -
> - mii_ctl |= BMCR_PDOWN;
> - ret = lan743x_sgmii_write(adapter, MDIO_MMD_VEND2, MII_BMCR, mii_ctl);
> - if (ret < 0)
> - return ret;
> -
> - ret = lan743x_pcs_seq_state(adapter, PCS_POWER_STATE_DOWN);
> - if (ret < 0)
> - return ret;
> -
> - /* SGMII/1000/2500BASE-X PCS power up */
> - mii_ctl &= ~BMCR_PDOWN;
> - ret = lan743x_sgmii_write(adapter, MDIO_MMD_VEND2, MII_BMCR, mii_ctl);
> - if (ret < 0)
> - return ret;
> -
> - ret = lan743x_pcs_seq_state(adapter, PCS_POWER_STATE_UP);
> - if (ret < 0)
> - return ret;
> -
> - return 0;
> + return lan743x_pcs_power_reset(adapter);
Hi Raju,
It appears that the local variable mii_ctl is now unused
in lan743x_sgmii_config() and can be removed.
> }
>
> static void lan743x_mac_set_address(struct lan743x_adapter *adapter,
> --
> 2.25.1
>
>
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH net-next 2/7] net: lan743x: Create separate Link Speed Duplex state function
2023-07-21 6:00 [PATCH net-next 0/7] Add support to PHYLINK and SFP for PCI11x1x chips Raju Lakkaraju
2023-07-21 6:00 ` [PATCH net-next 1/7] net: lan743x: Create separate PCS power reset function Raju Lakkaraju
@ 2023-07-21 6:00 ` Raju Lakkaraju
2023-07-21 6:00 ` [PATCH net-next 3/7] net: lan743x: Add SFP support check flag Raju Lakkaraju
` (4 subsequent siblings)
6 siblings, 0 replies; 15+ messages in thread
From: Raju Lakkaraju @ 2023-07-21 6:00 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, linux-kernel, bryan.whitehead, andrew, linux,
UNGLinuxDriver
Create separate Link Speed Duplex (LSD) update state function from
lan743x_sgmii_config () to use as subroutine.
Signed-off-by: Raju Lakkaraju <Raju.Lakkaraju@microchip.com>
---
drivers/net/ethernet/microchip/lan743x_main.c | 76 +++++++++++--------
drivers/net/ethernet/microchip/lan743x_main.h | 1 +
2 files changed, 46 insertions(+), 31 deletions(-)
diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c
index dba5576a933b..e8dd272a591a 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.c
+++ b/drivers/net/ethernet/microchip/lan743x_main.c
@@ -990,6 +990,42 @@ static int lan743x_sgmii_write(struct lan743x_adapter *adapter,
return ret;
}
+int lan743x_lsd_update(int speed, int duplex, u8 mss)
+{
+ enum lan743x_sgmii_lsd lsd = POWER_DOWN;
+
+ switch (speed) {
+ case SPEED_2500:
+ if (mss == MASTER_SLAVE_STATE_SLAVE)
+ lsd = LINK_2500_SLAVE;
+ else
+ lsd = LINK_2500_MASTER;
+ break;
+ case SPEED_1000:
+ if (mss == MASTER_SLAVE_STATE_SLAVE)
+ lsd = LINK_1000_SLAVE;
+ else
+ lsd = LINK_1000_MASTER;
+ break;
+ case SPEED_100:
+ if (duplex == DUPLEX_FULL)
+ lsd = LINK_100FD;
+ else
+ lsd = LINK_100HD;
+ break;
+ case SPEED_10:
+ if (duplex == DUPLEX_FULL)
+ lsd = LINK_10FD;
+ else
+ lsd = LINK_10HD;
+ break;
+ default:
+ return -EINVAL;
+ }
+
+ return lsd;
+}
+
static int lan743x_sgmii_mpll_set(struct lan743x_adapter *adapter,
u16 baud)
{
@@ -1177,43 +1213,21 @@ static int lan743x_sgmii_config(struct lan743x_adapter *adapter)
{
struct net_device *netdev = adapter->netdev;
struct phy_device *phydev = netdev->phydev;
- enum lan743x_sgmii_lsd lsd = POWER_DOWN;
- int mii_ctl;
bool status;
int ret;
- switch (phydev->speed) {
- case SPEED_2500:
- if (phydev->master_slave_state == MASTER_SLAVE_STATE_MASTER)
- lsd = LINK_2500_MASTER;
- else
- lsd = LINK_2500_SLAVE;
- break;
- case SPEED_1000:
- if (phydev->master_slave_state == MASTER_SLAVE_STATE_MASTER)
- lsd = LINK_1000_MASTER;
- else
- lsd = LINK_1000_SLAVE;
- break;
- case SPEED_100:
- if (phydev->duplex)
- lsd = LINK_100FD;
- else
- lsd = LINK_100HD;
- break;
- case SPEED_10:
- if (phydev->duplex)
- lsd = LINK_10FD;
- else
- lsd = LINK_10HD;
- break;
- default:
+ ret = lan743x_lsd_update(phydev->speed, phydev->duplex,
+ phydev->master_slave_state);
+ if (ret < 0) {
netif_err(adapter, drv, adapter->netdev,
- "Invalid speed %d\n", phydev->speed);
- return -EINVAL;
+ "error %d link-speed-duplex(LSD) invalid\n", ret);
+ return ret;
}
- adapter->sgmii_lsd = lsd;
+ adapter->sgmii_lsd = ret;
+ netif_dbg(adapter, drv, adapter->netdev,
+ "Link Speed Duplex (lsd) : 0x%X\n", adapter->sgmii_lsd);
+
ret = lan743x_sgmii_aneg_update(adapter);
if (ret < 0) {
netif_err(adapter, drv, adapter->netdev,
diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h
index 52609fc13ad9..0cd3fe71dfad 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.h
+++ b/drivers/net/ethernet/microchip/lan743x_main.h
@@ -1163,5 +1163,6 @@ void lan743x_hs_syslock_release(struct lan743x_adapter *adapter);
void lan743x_mac_flow_ctrl_set_enables(struct lan743x_adapter *adapter,
bool tx_enable, bool rx_enable);
int lan743x_sgmii_read(struct lan743x_adapter *adapter, u8 mmd, u16 addr);
+int lan743x_lsd_update(int speed, int duplex, u8 mss);
#endif /* _LAN743X_H */
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH net-next 3/7] net: lan743x: Add SFP support check flag
2023-07-21 6:00 [PATCH net-next 0/7] Add support to PHYLINK and SFP for PCI11x1x chips Raju Lakkaraju
2023-07-21 6:00 ` [PATCH net-next 1/7] net: lan743x: Create separate PCS power reset function Raju Lakkaraju
2023-07-21 6:00 ` [PATCH net-next 2/7] net: lan743x: Create separate Link Speed Duplex state function Raju Lakkaraju
@ 2023-07-21 6:00 ` Raju Lakkaraju
2023-07-21 6:00 ` [PATCH net-next 4/7] net: lan743x: Add support to software-nodes for SFP and PHYLINK Raju Lakkaraju
` (3 subsequent siblings)
6 siblings, 0 replies; 15+ messages in thread
From: Raju Lakkaraju @ 2023-07-21 6:00 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, linux-kernel, bryan.whitehead, andrew, linux,
UNGLinuxDriver
PCI11x1x chip support the Pluggable module (SFP) depend on Board requirement.
SFP support information programmed in EEPROM.
Flag "is_sfp_support_en" update on "STRAP" register.
Signed-off-by: Raju Lakkaraju <Raju.Lakkaraju@microchip.com>
---
drivers/net/ethernet/microchip/lan743x_main.c | 10 ++++++++++
drivers/net/ethernet/microchip/lan743x_main.h | 3 +++
2 files changed, 13 insertions(+)
diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c
index e8dd272a591a..822576b088a9 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.c
+++ b/drivers/net/ethernet/microchip/lan743x_main.c
@@ -52,6 +52,11 @@ static void pci11x1x_strap_get_status(struct lan743x_adapter *adapter)
adapter->is_sgmii_en = true;
else
adapter->is_sgmii_en = false;
+
+ if ((strap & STRAP_SFP_USE_EN_) && (strap & STRAP_SFP_EN_))
+ adapter->is_sfp_support_en = true;
+ else
+ adapter->is_sfp_support_en = false;
} else {
chip_rev = lan743x_csr_read(adapter, FPGA_REV);
if (chip_rev) {
@@ -63,8 +68,12 @@ static void pci11x1x_strap_get_status(struct lan743x_adapter *adapter)
adapter->is_sgmii_en = false;
}
}
+
netif_dbg(adapter, drv, adapter->netdev,
"SGMII I/F %sable\n", adapter->is_sgmii_en ? "En" : "Dis");
+ netif_dbg(adapter, drv, adapter->netdev,
+ "SFP support %sable\n", adapter->is_sfp_support_en ?
+ "En" : "Dis");
}
static bool is_pci11x1x_chip(struct lan743x_adapter *adapter)
@@ -3408,6 +3417,7 @@ static int lan743x_pcidev_probe(struct pci_dev *pdev,
NETIF_MSG_LINK | NETIF_MSG_IFUP |
NETIF_MSG_IFDOWN | NETIF_MSG_TX_QUEUED;
netdev->max_mtu = LAN743X_MAX_FRAME_SIZE;
+ adapter->is_sfp_support_en = false;
of_get_mac_address(pdev->dev.of_node, adapter->mac_address);
diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h
index 0cd3fe71dfad..3889bb20a524 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.h
+++ b/drivers/net/ethernet/microchip/lan743x_main.h
@@ -34,6 +34,8 @@
#define STRAP_READ (0x0C)
#define STRAP_READ_USE_SGMII_EN_ BIT(22)
+#define STRAP_SFP_USE_EN_ BIT(31)
+#define STRAP_SFP_EN_ BIT(15)
#define STRAP_READ_SGMII_EN_ BIT(6)
#define STRAP_READ_SGMII_REFCLK_ BIT(5)
#define STRAP_READ_SGMII_2_5G_ BIT(4)
@@ -1038,6 +1040,7 @@ struct lan743x_adapter {
u8 max_tx_channels;
u8 used_tx_channels;
u8 max_vector_count;
+ bool is_sfp_support_en;
#define LAN743X_ADAPTER_FLAG_OTP BIT(0)
u32 flags;
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH net-next 4/7] net: lan743x: Add support to software-nodes for SFP and PHYLINK
2023-07-21 6:00 [PATCH net-next 0/7] Add support to PHYLINK and SFP for PCI11x1x chips Raju Lakkaraju
` (2 preceding siblings ...)
2023-07-21 6:00 ` [PATCH net-next 3/7] net: lan743x: Add SFP support check flag Raju Lakkaraju
@ 2023-07-21 6:00 ` Raju Lakkaraju
2023-07-21 6:00 ` [PATCH net-next 5/7] net: lan743x: Add support to the Phylink framework Raju Lakkaraju
` (2 subsequent siblings)
6 siblings, 0 replies; 15+ messages in thread
From: Raju Lakkaraju @ 2023-07-21 6:00 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, linux-kernel, bryan.whitehead, andrew, linux,
UNGLinuxDriver
Register software nodes and define the device properties.
software-node contains following properties.
- GPIO pin details
- I2C bus information
- SFP signals
- phylink modes
Signed-off-by: Raju Lakkaraju <Raju.Lakkaraju@microchip.com>
---
drivers/net/ethernet/microchip/Kconfig | 2 +
drivers/net/ethernet/microchip/lan743x_main.c | 214 +++++++++++++++++-
drivers/net/ethernet/microchip/lan743x_main.h | 31 +++
3 files changed, 244 insertions(+), 3 deletions(-)
diff --git a/drivers/net/ethernet/microchip/Kconfig b/drivers/net/ethernet/microchip/Kconfig
index 329e374b9539..b1d361b412d1 100644
--- a/drivers/net/ethernet/microchip/Kconfig
+++ b/drivers/net/ethernet/microchip/Kconfig
@@ -49,6 +49,8 @@ config LAN743X
select FIXED_PHY
select CRC16
select CRC32
+ select I2C_PCI1XXXX
+ select GP_PCI1XXXX
help
Support for the Microchip LAN743x PCI Express Gigabit Ethernet chip
diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c
index 822576b088a9..aef64747a952 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.c
+++ b/drivers/net/ethernet/microchip/lan743x_main.c
@@ -15,6 +15,9 @@
#include <linux/rtnetlink.h>
#include <linux/iopoll.h>
#include <linux/crc16.h>
+#include <linux/gpio/machine.h>
+#include <linux/i2c.h>
+#include "../../../misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.h"
#include "lan743x_main.h"
#include "lan743x_ethtool.h"
@@ -24,6 +27,30 @@
#define MMD_ACCESS_READ_INC 3
#define PCS_POWER_STATE_DOWN 0x6
#define PCS_POWER_STATE_UP 0x4
+#define PCI1XXXX_VENDOR_ID 0x1055
+#define PCI1XXXX_BR_PERIF_ID 0xA00C
+#define PCI1XXXX_PERIF_I2C_ID 0xA003
+#define PCI1XXXX_PERIF_GPIO_ID 0xA005
+#define PCI1XXXX_DEV_MASK GENMASK(7, 4)
+
+#define NODE_PROP(_NAME, _PROP) \
+ ((const struct software_node) { \
+ .name = _NAME, \
+ .properties = _PROP, \
+ })
+
+struct pci1xxxx_i2c {
+ struct completion i2c_xfer_done;
+ bool i2c_xfer_in_progress;
+ struct i2c_adapter adap;
+ void __iomem *i2c_base;
+ u32 freq;
+ u32 flags;
+};
+
+struct aux_bus_device {
+ struct auxiliary_device_wrapper *aux_device_wrapper[2];
+};
static void pci11x1x_strap_get_status(struct lan743x_adapter *adapter)
{
@@ -96,6 +123,91 @@ static void lan743x_pci_cleanup(struct lan743x_adapter *adapter)
pci_disable_device(adapter->pdev);
}
+static void *pci1xxxx_perif_drvdata_get(struct lan743x_adapter *adapter,
+ u16 perif_id)
+{
+ struct pci_dev *pdev = adapter->pdev;
+ struct pci_bus *perif_bus;
+ struct pci_dev *perif_dev;
+ struct pci_dev *br_dev;
+ struct pci_bus *br_bus;
+ struct pci_dev *dev;
+
+ /* PCI11x1x devices' PCIe topology consists of a top level pcie
+ * switch with up to four downstream ports, some of which have
+ * integrated endpoints connected to them. One of the downstream ports
+ * has an embedded single function pcie ethernet controller which is
+ * handled by this driver. Another downstream port has an
+ * embedded multifunction pcie endpoint, with four pcie functions
+ * (the "peripheral controllers": I2C controller, GPIO controller,
+ * UART controllers, SPIcontrollers)
+ * The code below navigates the PCI11x1x topology
+ * to find (by matching its PCI device ID) the peripheral controller
+ * that should be paired to the embedded ethernet controller.
+ */
+ br_dev = pci_upstream_bridge(pdev);
+ if (!br_dev) {
+ netif_err(adapter, drv, adapter->netdev,
+ "upstream bridge not found\n");
+ return br_dev;
+ }
+
+ br_bus = br_dev->bus;
+ list_for_each_entry(dev, &br_bus->devices, bus_list) {
+ if (dev->vendor == PCI1XXXX_VENDOR_ID &&
+ (dev->device & ~PCI1XXXX_DEV_MASK) ==
+ PCI1XXXX_BR_PERIF_ID) {
+ perif_bus = dev->subordinate;
+ list_for_each_entry(perif_dev, &perif_bus->devices,
+ bus_list) {
+ if (perif_dev->vendor == PCI1XXXX_VENDOR_ID &&
+ (perif_dev->device & ~PCI1XXXX_DEV_MASK) ==
+ perif_id)
+ return pci_get_drvdata(perif_dev);
+ }
+ }
+ }
+
+ netif_err(adapter, drv, adapter->netdev,
+ "pci1xxxx peripheral (0x%X) device not found\n", perif_id);
+
+ return NULL;
+}
+
+static int pci1xxxx_i2c_adapter_get(struct lan743x_adapter *adapter)
+{
+ struct pci1xxxx_i2c *i2c_drvdata;
+
+ i2c_drvdata = pci1xxxx_perif_drvdata_get(adapter, PCI1XXXX_PERIF_I2C_ID);
+ if (!i2c_drvdata)
+ return -EPROBE_DEFER;
+
+ adapter->i2c_adap = &i2c_drvdata->adap;
+ snprintf(adapter->nodes->i2c_name, sizeof(adapter->nodes->i2c_name),
+ adapter->i2c_adap->name);
+ netif_dbg(adapter, drv, adapter->netdev, "Found %s\n",
+ adapter->i2c_adap->name);
+
+ return 0;
+}
+
+static int pci1xxxx_gpio_dev_get(struct lan743x_adapter *adapter)
+{
+ struct aux_bus_device *aux_bus;
+ struct device *gpio_dev;
+
+ aux_bus = pci1xxxx_perif_drvdata_get(adapter, PCI1XXXX_PERIF_GPIO_ID);
+ if (!aux_bus)
+ return -EPROBE_DEFER;
+
+ gpio_dev = &aux_bus->aux_device_wrapper[1]->aux_dev.dev;
+ snprintf(adapter->nodes->gpio_name, sizeof(adapter->nodes->gpio_name),
+ dev_name(gpio_dev));
+ netif_dbg(adapter, drv, adapter->netdev, "Found %s\n",
+ adapter->nodes->gpio_name);
+ return 0;
+}
+
static int lan743x_pci_init(struct lan743x_adapter *adapter,
struct pci_dev *pdev)
{
@@ -3030,6 +3142,85 @@ static int lan743x_rx_open(struct lan743x_rx *rx)
return ret;
}
+static int lan743x_swnodes_register(struct lan743x_adapter *adapter)
+{
+ struct pci_dev *pdev = adapter->pdev;
+ struct lan743x_sw_nodes *nodes;
+ struct software_node *swnodes;
+ int ret;
+ u32 id;
+
+ nodes = kzalloc(sizeof(*nodes), GFP_KERNEL);
+ if (!nodes)
+ return -ENOMEM;
+
+ adapter->nodes = nodes;
+
+ ret = pci1xxxx_gpio_dev_get(adapter);
+ if (ret < 0)
+ return ret;
+
+ ret = pci1xxxx_i2c_adapter_get(adapter);
+ if (ret < 0)
+ return ret;
+
+ id = (pdev->bus->number << 8) | pdev->devfn;
+ snprintf(nodes->sfp_name, sizeof(nodes->sfp_name),
+ "sfp-%x", id);
+ snprintf(nodes->phylink_name, sizeof(nodes->phylink_name),
+ "mchp-pci1xxxx-phylink-%x", id);
+
+ swnodes = nodes->swnodes;
+
+ nodes->gpio_props[0] = PROPERTY_ENTRY_STRING("pinctrl-names",
+ "default");
+ swnodes[SWNODE_GPIO] = NODE_PROP(nodes->gpio_name, nodes->gpio_props);
+
+ nodes->tx_fault_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO],
+ 46, GPIO_ACTIVE_HIGH);
+ nodes->tx_disable_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO],
+ 47, GPIO_ACTIVE_HIGH);
+ nodes->mod_def0_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO],
+ 51, GPIO_ACTIVE_LOW);
+ nodes->los_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO],
+ 49, GPIO_ACTIVE_HIGH);
+ nodes->rate_select0_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_GPIO],
+ 48, GPIO_ACTIVE_HIGH);
+
+ nodes->i2c_props[0] = PROPERTY_ENTRY_STRING("pinctrl-names", "default");
+ swnodes[SWNODE_I2C] = NODE_PROP(nodes->i2c_name, nodes->i2c_props);
+ nodes->i2c_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_I2C]);
+
+ nodes->sfp_props[0] = PROPERTY_ENTRY_STRING("compatible", "sff,sfp");
+ nodes->sfp_props[1] = PROPERTY_ENTRY_REF_ARRAY("i2c-bus",
+ nodes->i2c_ref);
+ nodes->sfp_props[2] = PROPERTY_ENTRY_REF_ARRAY("tx-fault-gpios",
+ nodes->tx_fault_ref);
+ nodes->sfp_props[3] = PROPERTY_ENTRY_REF_ARRAY("tx-disable-gpios",
+ nodes->tx_disable_ref);
+ nodes->sfp_props[4] = PROPERTY_ENTRY_REF_ARRAY("mod-def0-gpios",
+ nodes->mod_def0_ref);
+ nodes->sfp_props[5] = PROPERTY_ENTRY_REF_ARRAY("los-gpios",
+ nodes->los_ref);
+ nodes->sfp_props[6] = PROPERTY_ENTRY_REF_ARRAY("rate-select0-gpios",
+ nodes->rate_select0_ref);
+ swnodes[SWNODE_SFP] = NODE_PROP(nodes->sfp_name, nodes->sfp_props);
+ nodes->sfp_ref[0] = SOFTWARE_NODE_REFERENCE(&swnodes[SWNODE_SFP]);
+ nodes->phylink_props[0] = PROPERTY_ENTRY_STRING("managed",
+ "in-band-status");
+ nodes->phylink_props[1] = PROPERTY_ENTRY_REF_ARRAY("sfp",
+ nodes->sfp_ref);
+ swnodes[SWNODE_PHYLINK] = NODE_PROP(nodes->phylink_name,
+ nodes->phylink_props);
+
+ nodes->group[SWNODE_GPIO] = &swnodes[SWNODE_GPIO];
+ nodes->group[SWNODE_I2C] = &swnodes[SWNODE_I2C];
+ nodes->group[SWNODE_SFP] = &swnodes[SWNODE_SFP];
+ nodes->group[SWNODE_PHYLINK] = &swnodes[SWNODE_PHYLINK];
+
+ return software_node_register_node_group(nodes->group);
+}
+
static int lan743x_netdev_close(struct net_device *netdev)
{
struct lan743x_adapter *adapter = netdev_priv(netdev);
@@ -3233,6 +3424,14 @@ static const struct net_device_ops lan743x_netdev_ops = {
static void lan743x_hardware_cleanup(struct lan743x_adapter *adapter)
{
+ if (adapter->i2c_adap)
+ adapter->i2c_adap = NULL;
+
+ if (adapter->nodes)
+ software_node_unregister_node_group(adapter->nodes->group);
+
+ kfree(adapter->nodes);
+
lan743x_csr_write(adapter, INT_EN_CLR, 0xFFFFFFFF);
}
@@ -3282,9 +3481,18 @@ static int lan743x_hardware_init(struct lan743x_adapter *adapter,
if (ret)
return ret;
- ret = lan743x_phy_init(adapter);
- if (ret)
- return ret;
+ if (adapter->is_sfp_support_en) {
+ ret = lan743x_swnodes_register(adapter);
+ if (ret) {
+ netdev_err(adapter->netdev,
+ "failed to register software nodes\n");
+ return ret;
+ }
+ } else {
+ ret = lan743x_phy_init(adapter);
+ if (ret)
+ return ret;
+ }
ret = lan743x_ptp_init(adapter);
if (ret)
diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h
index 3889bb20a524..7f1c5673bc61 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.h
+++ b/drivers/net/ethernet/microchip/lan743x_main.h
@@ -5,6 +5,7 @@
#define _LAN743X_H
#include <linux/phy.h>
+#include <linux/property.h>
#include "lan743x_ptp.h"
#define DRIVER_AUTHOR "Bryan Whitehead <Bryan.Whitehead@microchip.com>"
@@ -1008,6 +1009,34 @@ enum lan743x_sgmii_lsd {
LINK_2500_SLAVE
};
+enum lan743x_swnodes {
+ SWNODE_GPIO = 0,
+ SWNODE_I2C,
+ SWNODE_SFP,
+ SWNODE_PHYLINK,
+ SWNODE_MAX
+};
+
+struct lan743x_sw_nodes {
+ char gpio_name[32];
+ char i2c_name[48];
+ char sfp_name[32];
+ char phylink_name[32];
+ struct property_entry gpio_props[1];
+ struct property_entry i2c_props[1];
+ struct property_entry sfp_props[8];
+ struct property_entry phylink_props[2];
+ struct software_node_ref_args i2c_ref[1];
+ struct software_node_ref_args tx_fault_ref[1];
+ struct software_node_ref_args tx_disable_ref[1];
+ struct software_node_ref_args mod_def0_ref[1];
+ struct software_node_ref_args los_ref[1];
+ struct software_node_ref_args rate_select0_ref[1];
+ struct software_node_ref_args sfp_ref[1];
+ struct software_node swnodes[SWNODE_MAX];
+ const struct software_node *group[SWNODE_MAX + 1];
+};
+
struct lan743x_adapter {
struct net_device *netdev;
struct mii_bus *mdiobus;
@@ -1046,6 +1075,8 @@ struct lan743x_adapter {
u32 flags;
u32 hw_cfg;
phy_interface_t phy_interface;
+ struct lan743x_sw_nodes *nodes;
+ struct i2c_adapter *i2c_adap;
};
#define LAN743X_COMPONENT_FLAG_RX(channel) BIT(20 + (channel))
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread* [PATCH net-next 5/7] net: lan743x: Add support to the Phylink framework
2023-07-21 6:00 [PATCH net-next 0/7] Add support to PHYLINK and SFP for PCI11x1x chips Raju Lakkaraju
` (3 preceding siblings ...)
2023-07-21 6:00 ` [PATCH net-next 4/7] net: lan743x: Add support to software-nodes for SFP and PHYLINK Raju Lakkaraju
@ 2023-07-21 6:00 ` Raju Lakkaraju
2023-07-21 8:49 ` Russell King (Oracle)
2023-07-22 20:27 ` Simon Horman
2023-07-21 6:00 ` [PATCH net-next 6/7] net: lan743x: Add support to ethtool phylink get and set settings Raju Lakkaraju
2023-07-21 6:00 ` [PATCH net-next 7/7] net: lan743x: Register the platform device for sfp pluggable module Raju Lakkaraju
6 siblings, 2 replies; 15+ messages in thread
From: Raju Lakkaraju @ 2023-07-21 6:00 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, linux-kernel, bryan.whitehead, andrew, linux,
UNGLinuxDriver
The phylink framework will be helpful in the future for boards using this
controller with SFP cages.
Signed-off-by: Raju Lakkaraju <Raju.Lakkaraju@microchip.com>
---
drivers/net/ethernet/microchip/Kconfig | 2 +-
drivers/net/ethernet/microchip/lan743x_main.c | 314 +++++++++++++++++-
drivers/net/ethernet/microchip/lan743x_main.h | 6 +
3 files changed, 314 insertions(+), 8 deletions(-)
diff --git a/drivers/net/ethernet/microchip/Kconfig b/drivers/net/ethernet/microchip/Kconfig
index b1d361b412d1..1c947e3437b7 100644
--- a/drivers/net/ethernet/microchip/Kconfig
+++ b/drivers/net/ethernet/microchip/Kconfig
@@ -46,7 +46,7 @@ config LAN743X
tristate "LAN743x support"
depends on PCI
depends on PTP_1588_CLOCK_OPTIONAL
- select FIXED_PHY
+ select PHYLINK
select CRC16
select CRC32
select I2C_PCI1XXXX
diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c
index aef64747a952..9b6326d035a8 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.c
+++ b/drivers/net/ethernet/microchip/lan743x_main.c
@@ -1618,7 +1618,11 @@ static void lan743x_phy_interface_select(struct lan743x_adapter *adapter)
data = lan743x_csr_read(adapter, MAC_CR);
id_rev = adapter->csr.id_rev & ID_REV_ID_MASK_;
- if (adapter->is_pci11x1x && adapter->is_sgmii_en)
+ if (adapter->is_pci11x1x &&
+ adapter->is_sgmii_en &&
+ adapter->is_sfp_support_en)
+ adapter->phy_interface = PHY_INTERFACE_MODE_2500BASEX;
+ else if (adapter->is_pci11x1x && adapter->is_sgmii_en)
adapter->phy_interface = PHY_INTERFACE_MODE_SGMII;
else if (id_rev == ID_REV_ID_LAN7430_)
adapter->phy_interface = PHY_INTERFACE_MODE_GMII;
@@ -1626,6 +1630,9 @@ static void lan743x_phy_interface_select(struct lan743x_adapter *adapter)
adapter->phy_interface = PHY_INTERFACE_MODE_MII;
else
adapter->phy_interface = PHY_INTERFACE_MODE_RGMII;
+
+ netif_dbg(adapter, drv, adapter->netdev,
+ "selected phy interface: 0x%X\n", adapter->phy_interface);
}
static int lan743x_phy_open(struct lan743x_adapter *adapter)
@@ -3221,6 +3228,266 @@ static int lan743x_swnodes_register(struct lan743x_adapter *adapter)
return software_node_register_node_group(nodes->group);
}
+static void lan743x_mac_cfg_update(struct lan743x_adapter *adapter, bool link,
+ int speed, const unsigned long *advertise)
+{
+ int mac_cr;
+
+ mac_cr = lan743x_csr_read(adapter, MAC_CR);
+ mac_cr &= ~(MAC_CR_CFG_H_ | MAC_CR_CFG_L_);
+ if (link) {
+ if (speed == SPEED_2500)
+ mac_cr |= (MAC_CR_CFG_H_ | MAC_CR_CFG_L_);
+ else if (speed == SPEED_1000)
+ mac_cr |= (MAC_CR_CFG_H_);
+ else if (speed == SPEED_100)
+ mac_cr |= (MAC_CR_CFG_L_);
+ } else if (test_bit(ETHTOOL_LINK_MODE_2500baseT_Full_BIT, advertise) ||
+ test_bit(ETHTOOL_LINK_MODE_2500baseX_Full_BIT, advertise)) {
+ mac_cr |= (MAC_CR_CFG_H_ | MAC_CR_CFG_L_);
+ adapter->sgmii_lsd = LINK_2500_MASTER;
+ } else if (test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT, advertise) ||
+ test_bit(ETHTOOL_LINK_MODE_1000baseX_Full_BIT, advertise)) {
+ mac_cr |= (MAC_CR_CFG_H_);
+ adapter->sgmii_lsd = LINK_1000_MASTER;
+ } else if (test_bit(ETHTOOL_LINK_MODE_100baseT_Full_BIT, advertise) ||
+ test_bit(ETHTOOL_LINK_MODE_100baseT_Half_BIT, advertise) ||
+ test_bit(ETHTOOL_LINK_MODE_100baseFX_Full_BIT, advertise) ||
+ test_bit(ETHTOOL_LINK_MODE_100baseFX_Half_BIT, advertise)) {
+ mac_cr |= (MAC_CR_CFG_L_);
+ adapter->sgmii_lsd = LINK_1000_MASTER;
+ } else {
+ adapter->sgmii_lsd = LINK_1000_MASTER;
+ }
+
+ lan743x_csr_write(adapter, MAC_CR, mac_cr);
+}
+
+static void lan743x_phylink_mac_config(struct phylink_config *config,
+ unsigned int link_an_mode,
+ const struct phylink_link_state *state)
+{
+ struct net_device *netdev = to_net_dev(config->dev);
+ struct lan743x_adapter *adapter = netdev_priv(netdev);
+ bool status;
+ int ret;
+
+ lan743x_mac_cfg_update(adapter, state->link, state->speed,
+ state->advertising);
+
+ if (!state->link && adapter->is_sgmii_en) {
+ ret = lan743x_sgmii_aneg_update(adapter);
+ if (ret < 0) {
+ netif_err(adapter, drv, adapter->netdev,
+ "error %d SGMII cfg failed\n", ret);
+ return;
+ }
+
+ ret = lan743x_is_sgmii_2_5G_mode(adapter, &status);
+ if (ret < 0) {
+ netif_err(adapter, drv, adapter->netdev,
+ "erro %d SGMII get mode failed\n", ret);
+ return;
+ }
+
+ if (status)
+ netif_dbg(adapter, drv, adapter->netdev,
+ "SGMII 2.5G mode enable\n");
+ else
+ netif_dbg(adapter, drv, adapter->netdev,
+ "SGMII 1G mode enable\n");
+
+ ret = lan743x_pcs_power_reset(adapter);
+ if (ret < 0) {
+ netif_err(adapter, drv, adapter->netdev,
+ "error %d pcs power reset failed\n", ret);
+ return;
+ }
+
+ phylink_mac_change(adapter->phylink, state->link);
+ }
+}
+
+static void lan743x_phylink_mac_link_down(struct phylink_config *config,
+ unsigned int link_an_mode,
+ phy_interface_t interface)
+{
+ netif_tx_stop_all_queues(to_net_dev(config->dev));
+}
+
+static void lan743x_phylink_mac_link_up(struct phylink_config *config,
+ struct phy_device *phydev,
+ unsigned int link_an_mode,
+ phy_interface_t interface,
+ int speed, int duplex,
+ bool tx_pause, bool rx_pause)
+{
+ netif_tx_wake_all_queues(to_net_dev(config->dev));
+}
+
+static void lan743x_phylink_mac_pcs_get_state(struct phylink_config *config,
+ struct phylink_link_state *state)
+{
+ struct net_device *netdev = to_net_dev(config->dev);
+ struct lan743x_adapter *adapter = netdev_priv(netdev);
+ int intr_sts;
+ int wait_cnt;
+ bool status;
+ int mii_sts;
+ bool link;
+ int ret;
+
+ wait_cnt = 0;
+ link = false;
+ while (wait_cnt++ < 10) {
+ mii_sts = lan743x_sgmii_read(adapter, MDIO_MMD_VEND2, MII_BMSR);
+ if (mii_sts < 0) {
+ netif_err(adapter, drv, adapter->netdev,
+ "erro %d MMD VEND2 MII BMSR read failed\n",
+ mii_sts);
+ return;
+ }
+
+ mii_sts = lan743x_sgmii_read(adapter, MDIO_MMD_VEND2, MII_BMSR);
+ if (mii_sts < 0) {
+ netif_err(adapter, drv, adapter->netdev,
+ "erro %d MMD VEND2 MII BMSR read failed\n",
+ mii_sts);
+ return;
+ }
+
+ if (mii_sts & SR_MII_STS_LINK_STS_) {
+ link = true;
+ break;
+ }
+
+ usleep_range(1000, 2000);
+ }
+
+ state->speed = SPEED_UNKNOWN;
+ state->duplex = DUPLEX_UNKNOWN;
+ if (link) {
+ int speed = SPEED_UNKNOWN;
+ int duplex = DUPLEX_UNKNOWN;
+
+ intr_sts = lan743x_sgmii_read(adapter, MDIO_MMD_VEND2,
+ VR_MII_AN_INTR_STS);
+ if (intr_sts < 0) {
+ netif_err(adapter, drv, adapter->netdev,
+ "erro %d VR_MII_AN_INTR_STS read failed\n",
+ intr_sts);
+ return;
+ }
+
+ if ((intr_sts & VR_MII_AN_INTR_STS_SPEED_MASK_) !=
+ VR_MII_AN_INTR_STS_SPEED_MASK_) {
+ if (intr_sts & VR_MII_AN_INTR_STS_1000_MBPS_)
+ speed = SPEED_1000;
+ else if (intr_sts & VR_MII_AN_INTR_STS_100_MBPS_)
+ speed = SPEED_100;
+ else
+ speed = SPEED_10;
+ }
+
+ if (intr_sts & VR_MII_AN_INTR_STS_FDX_)
+ duplex = DUPLEX_FULL;
+ else
+ duplex = DUPLEX_HALF;
+
+ ret = lan743x_is_sgmii_2_5G_mode(adapter, &status);
+ if (ret < 0) {
+ netif_err(adapter, drv, adapter->netdev,
+ "erro %d SGMII get mode failed\n", ret);
+ return;
+ }
+
+ if (adapter->is_sgmii_en && status) {
+ state->speed = SPEED_2500;
+ state->duplex = DUPLEX_FULL;
+ } else if (adapter->is_sgmii_en) {
+ state->speed = speed;
+ state->duplex = duplex;
+ }
+ }
+
+ state->link = link;
+
+ netif_dbg(adapter, drv, adapter->netdev,
+ "Link: %s, Speed:%d, %s Duplex\n",
+ state->link ? "Up" : "Down",
+ state->speed, (state->duplex == DUPLEX_FULL ? "Full" :
+ (state->duplex == DUPLEX_HALF ? "Half" : "Unknown")));
+}
+
+static const struct phylink_mac_ops lan743x_phylink_mac_ops = {
+ .validate = phylink_generic_validate,
+ .mac_config = lan743x_phylink_mac_config,
+ .mac_link_down = lan743x_phylink_mac_link_down,
+ .mac_link_up = lan743x_phylink_mac_link_up,
+ .mac_pcs_get_state = lan743x_phylink_mac_pcs_get_state,
+};
+
+static int lan743x_phylink_create(struct net_device *netdev)
+{
+ struct lan743x_adapter *adapter = netdev_priv(netdev);
+ struct fwnode_handle *fwnode;
+ struct phylink *phylink;
+ int ret;
+
+ adapter->phylink_config.dev = &netdev->dev;
+ adapter->phylink_config.type = PHYLINK_NETDEV;
+ adapter->phylink_config.mac_managed_pm = true;
+ /* This driver makes use of state->speed in mac_config */
+ adapter->phylink_config.legacy_pre_march2020 = true;
+
+ adapter->phylink_config.mac_capabilities = MAC_ASYM_PAUSE |
+ MAC_SYM_PAUSE | MAC_10 | MAC_100 | MAC_1000FD | MAC_2500FD;
+
+ /* Config serdes Interface */
+ lan743x_phy_interface_select(adapter);
+
+ if (adapter->is_sgmii_en) {
+ __set_bit(PHY_INTERFACE_MODE_SGMII,
+ adapter->phylink_config.supported_interfaces);
+ __set_bit(PHY_INTERFACE_MODE_1000BASEX,
+ adapter->phylink_config.supported_interfaces);
+ __set_bit(PHY_INTERFACE_MODE_2500BASEX,
+ adapter->phylink_config.supported_interfaces);
+ }
+
+ fwnode = software_node_fwnode(adapter->nodes->group[SWNODE_PHYLINK]);
+ if (!fwnode)
+ return -ENODEV;
+
+ phylink = phylink_create(&adapter->phylink_config,
+ fwnode,
+ adapter->phy_interface,
+ &lan743x_phylink_mac_ops);
+
+ if (IS_ERR(phylink)) {
+ ret = PTR_ERR(phylink);
+ netdev_err(netdev, "Could not create phylink (%pe)\n", phylink);
+ return ret;
+ }
+
+ adapter->phylink = phylink;
+ netdev_dbg(netdev, "lan743x phylink created");
+
+ return 0;
+}
+
+static int lan743x_phylink_connect(struct lan743x_adapter *adapter)
+{
+ phylink_start(adapter->phylink);
+
+ return 0;
+}
+
+static void lan743x_phylink_close(struct lan743x_adapter *adapter)
+{
+ phylink_stop(adapter->phylink);
+}
+
static int lan743x_netdev_close(struct net_device *netdev)
{
struct lan743x_adapter *adapter = netdev_priv(netdev);
@@ -3234,7 +3501,10 @@ static int lan743x_netdev_close(struct net_device *netdev)
lan743x_ptp_close(adapter);
- lan743x_phy_close(adapter);
+ if (adapter->phylink)
+ lan743x_phylink_close(adapter);
+ else
+ lan743x_phy_close(adapter);
lan743x_mac_close(adapter);
@@ -3257,9 +3527,15 @@ static int lan743x_netdev_open(struct net_device *netdev)
if (ret)
goto close_intr;
- ret = lan743x_phy_open(adapter);
- if (ret)
- goto close_mac;
+ if (adapter->phylink) {
+ ret = lan743x_phylink_connect(adapter);
+ if (ret)
+ goto close_mac;
+ } else {
+ ret = lan743x_phy_open(adapter);
+ if (ret)
+ goto close_mac;
+ }
ret = lan743x_ptp_open(adapter);
if (ret)
@@ -3294,7 +3570,10 @@ static int lan743x_netdev_open(struct net_device *netdev)
lan743x_ptp_close(adapter);
close_phy:
- lan743x_phy_close(adapter);
+ if (adapter->phylink)
+ lan743x_phylink_close(adapter);
+ else
+ lan743x_phy_close(adapter);
close_mac:
lan743x_mac_close(adapter);
@@ -3323,10 +3602,16 @@ static netdev_tx_t lan743x_netdev_xmit_frame(struct sk_buff *skb,
static int lan743x_netdev_ioctl(struct net_device *netdev,
struct ifreq *ifr, int cmd)
{
+ struct lan743x_adapter *adapter = netdev_priv(netdev);
+
if (!netif_running(netdev))
return -EINVAL;
if (cmd == SIOCSHWTSTAMP)
return lan743x_ptp_ioctl(netdev, ifr, cmd);
+
+ if (adapter->phylink)
+ return phylink_mii_ioctl(adapter->phylink, ifr, cmd);
+
return phy_mii_ioctl(netdev->phydev, ifr, cmd);
}
@@ -3427,6 +3712,9 @@ static void lan743x_hardware_cleanup(struct lan743x_adapter *adapter)
if (adapter->i2c_adap)
adapter->i2c_adap = NULL;
+ if (adapter->phylink)
+ phylink_destroy(adapter->phylink);
+
if (adapter->nodes)
software_node_unregister_node_group(adapter->nodes->group);
@@ -3650,9 +3938,21 @@ static int lan743x_pcidev_probe(struct pci_dev *pdev,
adapter->netdev->features = NETIF_F_SG | NETIF_F_TSO |
NETIF_F_HW_CSUM | NETIF_F_RXCSUM;
adapter->netdev->hw_features = adapter->netdev->features;
+ /* Default Link-Speed-Duplex (LSD) state */
+ adapter->sgmii_lsd = LINK_2500_MASTER;
+
+ if (adapter->is_sfp_support_en) {
+ ret = lan743x_phylink_create(adapter->netdev);
+ if (ret) {
+ netif_err(adapter, probe, netdev,
+ "failed to setup phylink (%d)\n", ret);
+ goto cleanup_hardware;
+ }
+ }
/* carrier off reporting is important to ethtool even BEFORE open */
- netif_carrier_off(netdev);
+ if (!adapter->phylink)
+ netif_carrier_off(netdev);
ret = register_netdev(adapter->netdev);
if (ret < 0)
diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h
index 7f1c5673bc61..6b94d0e93cbb 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.h
+++ b/drivers/net/ethernet/microchip/lan743x_main.h
@@ -6,6 +6,7 @@
#include <linux/phy.h>
#include <linux/property.h>
+#include <linux/phylink.h>
#include "lan743x_ptp.h"
#define DRIVER_AUTHOR "Bryan Whitehead <Bryan.Whitehead@microchip.com>"
@@ -317,6 +318,9 @@
/* Vendor Specific SGMII MMD details */
#define SR_VSMMD_PCS_ID1 0x0004
#define SR_VSMMD_PCS_ID2 0x0005
+#define SR_MII_CTRL MII_BMCR
+#define SR_MII_STS MII_BMSR
+#define SR_MII_STS_LINK_STS_ BIT(2)
#define SR_VSMMD_STS 0x0008
#define SR_VSMMD_CTRL 0x0009
@@ -1077,6 +1081,8 @@ struct lan743x_adapter {
phy_interface_t phy_interface;
struct lan743x_sw_nodes *nodes;
struct i2c_adapter *i2c_adap;
+ struct phylink *phylink;
+ struct phylink_config phylink_config;
};
#define LAN743X_COMPONENT_FLAG_RX(channel) BIT(20 + (channel))
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH net-next 5/7] net: lan743x: Add support to the Phylink framework
2023-07-21 6:00 ` [PATCH net-next 5/7] net: lan743x: Add support to the Phylink framework Raju Lakkaraju
@ 2023-07-21 8:49 ` Russell King (Oracle)
2023-07-21 11:57 ` Russell King (Oracle)
2023-07-22 20:27 ` Simon Horman
1 sibling, 1 reply; 15+ messages in thread
From: Russell King (Oracle) @ 2023-07-21 8:49 UTC (permalink / raw)
To: Raju Lakkaraju
Cc: netdev, davem, kuba, linux-kernel, bryan.whitehead, andrew,
UNGLinuxDriver
On Fri, Jul 21, 2023 at 11:30:17AM +0530, Raju Lakkaraju wrote:
> +static void lan743x_phylink_mac_config(struct phylink_config *config,
> + unsigned int link_an_mode,
> + const struct phylink_link_state *state)
> +{
> + struct net_device *netdev = to_net_dev(config->dev);
> + struct lan743x_adapter *adapter = netdev_priv(netdev);
> + bool status;
> + int ret;
> +
> + lan743x_mac_cfg_update(adapter, state->link, state->speed,
> + state->advertising);
Please, no new state->speed users in mac_config().
> +
> + if (!state->link && adapter->is_sgmii_en) {
> + ret = lan743x_sgmii_aneg_update(adapter);
> + if (ret < 0) {
> + netif_err(adapter, drv, adapter->netdev,
> + "error %d SGMII cfg failed\n", ret);
> + return;
> + }
> +
> + ret = lan743x_is_sgmii_2_5G_mode(adapter, &status);
> + if (ret < 0) {
> + netif_err(adapter, drv, adapter->netdev,
> + "erro %d SGMII get mode failed\n", ret);
> + return;
> + }
> +
> + if (status)
> + netif_dbg(adapter, drv, adapter->netdev,
> + "SGMII 2.5G mode enable\n");
> + else
> + netif_dbg(adapter, drv, adapter->netdev,
> + "SGMII 1G mode enable\n");
> +
> + ret = lan743x_pcs_power_reset(adapter);
> + if (ret < 0) {
> + netif_err(adapter, drv, adapter->netdev,
> + "error %d pcs power reset failed\n", ret);
> + return;
> + }
> +
> + phylink_mac_change(adapter->phylink, state->link);
Sorry but no, this is not what the function is for.
> + }
> +}
> +
> +static void lan743x_phylink_mac_link_down(struct phylink_config *config,
> + unsigned int link_an_mode,
> + phy_interface_t interface)
> +{
> + netif_tx_stop_all_queues(to_net_dev(config->dev));
> +}
> +
> +static void lan743x_phylink_mac_link_up(struct phylink_config *config,
> + struct phy_device *phydev,
> + unsigned int link_an_mode,
> + phy_interface_t interface,
> + int speed, int duplex,
> + bool tx_pause, bool rx_pause)
> +{
> + netif_tx_wake_all_queues(to_net_dev(config->dev));
Also rubbish. This is where you're supposed to be configuring the
hardware for the results of negotiation. It seems to me to be a
complete waste of time writing phylink documentation when rubbish
like this gets submitted.
> +}
> +
> +static void lan743x_phylink_mac_pcs_get_state(struct phylink_config *config,
> + struct phylink_link_state *state)
> +{
> + struct net_device *netdev = to_net_dev(config->dev);
> + struct lan743x_adapter *adapter = netdev_priv(netdev);
> + int intr_sts;
> + int wait_cnt;
> + bool status;
> + int mii_sts;
> + bool link;
> + int ret;
> +
> + wait_cnt = 0;
> + link = false;
> + while (wait_cnt++ < 10) {
> + mii_sts = lan743x_sgmii_read(adapter, MDIO_MMD_VEND2, MII_BMSR);
> + if (mii_sts < 0) {
> + netif_err(adapter, drv, adapter->netdev,
> + "erro %d MMD VEND2 MII BMSR read failed\n",
> + mii_sts);
> + return;
> + }
> +
> + mii_sts = lan743x_sgmii_read(adapter, MDIO_MMD_VEND2, MII_BMSR);
> + if (mii_sts < 0) {
> + netif_err(adapter, drv, adapter->netdev,
> + "erro %d MMD VEND2 MII BMSR read failed\n",
> + mii_sts);
> + return;
> + }
> +
> + if (mii_sts & SR_MII_STS_LINK_STS_) {
> + link = true;
> + break;
> + }
> +
> + usleep_range(1000, 2000);
> + }
> +
> + state->speed = SPEED_UNKNOWN;
> + state->duplex = DUPLEX_UNKNOWN;
> + if (link) {
> + int speed = SPEED_UNKNOWN;
> + int duplex = DUPLEX_UNKNOWN;
> +
> + intr_sts = lan743x_sgmii_read(adapter, MDIO_MMD_VEND2,
> + VR_MII_AN_INTR_STS);
> + if (intr_sts < 0) {
> + netif_err(adapter, drv, adapter->netdev,
> + "erro %d VR_MII_AN_INTR_STS read failed\n",
> + intr_sts);
> + return;
> + }
> +
> + if ((intr_sts & VR_MII_AN_INTR_STS_SPEED_MASK_) !=
> + VR_MII_AN_INTR_STS_SPEED_MASK_) {
> + if (intr_sts & VR_MII_AN_INTR_STS_1000_MBPS_)
> + speed = SPEED_1000;
> + else if (intr_sts & VR_MII_AN_INTR_STS_100_MBPS_)
> + speed = SPEED_100;
> + else
> + speed = SPEED_10;
> + }
> +
> + if (intr_sts & VR_MII_AN_INTR_STS_FDX_)
> + duplex = DUPLEX_FULL;
> + else
> + duplex = DUPLEX_HALF;
> +
> + ret = lan743x_is_sgmii_2_5G_mode(adapter, &status);
> + if (ret < 0) {
> + netif_err(adapter, drv, adapter->netdev,
> + "erro %d SGMII get mode failed\n", ret);
> + return;
> + }
> +
> + if (adapter->is_sgmii_en && status) {
> + state->speed = SPEED_2500;
> + state->duplex = DUPLEX_FULL;
> + } else if (adapter->is_sgmii_en) {
> + state->speed = speed;
> + state->duplex = duplex;
> + }
> + }
> +
> + state->link = link;
> +
> + netif_dbg(adapter, drv, adapter->netdev,
> + "Link: %s, Speed:%d, %s Duplex\n",
> + state->link ? "Up" : "Down",
> + state->speed, (state->duplex == DUPLEX_FULL ? "Full" :
> + (state->duplex == DUPLEX_HALF ? "Half" : "Unknown")));
Please port to phylink_pcs.
> +}
> +
> +static const struct phylink_mac_ops lan743x_phylink_mac_ops = {
> + .validate = phylink_generic_validate,
> + .mac_config = lan743x_phylink_mac_config,
> + .mac_link_down = lan743x_phylink_mac_link_down,
> + .mac_link_up = lan743x_phylink_mac_link_up,
> + .mac_pcs_get_state = lan743x_phylink_mac_pcs_get_state,
> +};
> +
> +static int lan743x_phylink_create(struct net_device *netdev)
> +{
> + struct lan743x_adapter *adapter = netdev_priv(netdev);
> + struct fwnode_handle *fwnode;
> + struct phylink *phylink;
> + int ret;
> +
> + adapter->phylink_config.dev = &netdev->dev;
> + adapter->phylink_config.type = PHYLINK_NETDEV;
> + adapter->phylink_config.mac_managed_pm = true;
> + /* This driver makes use of state->speed in mac_config */
> + adapter->phylink_config.legacy_pre_march2020 = true;
Sorry, but no new users of legacy features.
> +
> + adapter->phylink_config.mac_capabilities = MAC_ASYM_PAUSE |
> + MAC_SYM_PAUSE | MAC_10 | MAC_100 | MAC_1000FD | MAC_2500FD;
> +
> + /* Config serdes Interface */
> + lan743x_phy_interface_select(adapter);
> +
> + if (adapter->is_sgmii_en) {
> + __set_bit(PHY_INTERFACE_MODE_SGMII,
> + adapter->phylink_config.supported_interfaces);
> + __set_bit(PHY_INTERFACE_MODE_1000BASEX,
> + adapter->phylink_config.supported_interfaces);
> + __set_bit(PHY_INTERFACE_MODE_2500BASEX,
> + adapter->phylink_config.supported_interfaces);
> + }
> +
> + fwnode = software_node_fwnode(adapter->nodes->group[SWNODE_PHYLINK]);
> + if (!fwnode)
> + return -ENODEV;
> +
> + phylink = phylink_create(&adapter->phylink_config,
> + fwnode,
> + adapter->phy_interface,
> + &lan743x_phylink_mac_ops);
> +
> + if (IS_ERR(phylink)) {
> + ret = PTR_ERR(phylink);
> + netdev_err(netdev, "Could not create phylink (%pe)\n", phylink);
> + return ret;
> + }
> +
> + adapter->phylink = phylink;
> + netdev_dbg(netdev, "lan743x phylink created");
> +
> + return 0;
> +}
> +
> +static int lan743x_phylink_connect(struct lan743x_adapter *adapter)
> +{
> + phylink_start(adapter->phylink);
> +
> + return 0;
> +}
> +
> +static void lan743x_phylink_close(struct lan743x_adapter *adapter)
> +{
> + phylink_stop(adapter->phylink);
> +}
> +
> static int lan743x_netdev_close(struct net_device *netdev)
> {
> struct lan743x_adapter *adapter = netdev_priv(netdev);
> @@ -3234,7 +3501,10 @@ static int lan743x_netdev_close(struct net_device *netdev)
>
> lan743x_ptp_close(adapter);
>
> - lan743x_phy_close(adapter);
> + if (adapter->phylink)
> + lan743x_phylink_close(adapter);
> + else
> + lan743x_phy_close(adapter);
Why this conditional? Why not go the full distance and do the conversion
detailed in the phylink documentation from phylib to phylink?
>
> lan743x_mac_close(adapter);
>
> @@ -3257,9 +3527,15 @@ static int lan743x_netdev_open(struct net_device *netdev)
> if (ret)
> goto close_intr;
>
> - ret = lan743x_phy_open(adapter);
> - if (ret)
> - goto close_mac;
> + if (adapter->phylink) {
> + ret = lan743x_phylink_connect(adapter);
> + if (ret)
> + goto close_mac;
> + } else {
> + ret = lan743x_phy_open(adapter);
> + if (ret)
> + goto close_mac;
> + }
>
> ret = lan743x_ptp_open(adapter);
> if (ret)
> @@ -3294,7 +3570,10 @@ static int lan743x_netdev_open(struct net_device *netdev)
> lan743x_ptp_close(adapter);
>
> close_phy:
> - lan743x_phy_close(adapter);
> + if (adapter->phylink)
> + lan743x_phylink_close(adapter);
> + else
> + lan743x_phy_close(adapter);
>
> close_mac:
> lan743x_mac_close(adapter);
> @@ -3323,10 +3602,16 @@ static netdev_tx_t lan743x_netdev_xmit_frame(struct sk_buff *skb,
> static int lan743x_netdev_ioctl(struct net_device *netdev,
> struct ifreq *ifr, int cmd)
> {
> + struct lan743x_adapter *adapter = netdev_priv(netdev);
> +
> if (!netif_running(netdev))
> return -EINVAL;
> if (cmd == SIOCSHWTSTAMP)
> return lan743x_ptp_ioctl(netdev, ifr, cmd);
> +
> + if (adapter->phylink)
> + return phylink_mii_ioctl(adapter->phylink, ifr, cmd);
> +
> return phy_mii_ioctl(netdev->phydev, ifr, cmd);
> }
>
> @@ -3427,6 +3712,9 @@ static void lan743x_hardware_cleanup(struct lan743x_adapter *adapter)
> if (adapter->i2c_adap)
> adapter->i2c_adap = NULL;
>
> + if (adapter->phylink)
> + phylink_destroy(adapter->phylink);
> +
> if (adapter->nodes)
> software_node_unregister_node_group(adapter->nodes->group);
>
> @@ -3650,9 +3938,21 @@ static int lan743x_pcidev_probe(struct pci_dev *pdev,
> adapter->netdev->features = NETIF_F_SG | NETIF_F_TSO |
> NETIF_F_HW_CSUM | NETIF_F_RXCSUM;
> adapter->netdev->hw_features = adapter->netdev->features;
> + /* Default Link-Speed-Duplex (LSD) state */
> + adapter->sgmii_lsd = LINK_2500_MASTER;
> +
> + if (adapter->is_sfp_support_en) {
> + ret = lan743x_phylink_create(adapter->netdev);
> + if (ret) {
> + netif_err(adapter, probe, netdev,
> + "failed to setup phylink (%d)\n", ret);
> + goto cleanup_hardware;
> + }
> + }
>
> /* carrier off reporting is important to ethtool even BEFORE open */
> - netif_carrier_off(netdev);
> + if (!adapter->phylink)
> + netif_carrier_off(netdev);
>
> ret = register_netdev(adapter->netdev);
> if (ret < 0)
> diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h
> index 7f1c5673bc61..6b94d0e93cbb 100644
> --- a/drivers/net/ethernet/microchip/lan743x_main.h
> +++ b/drivers/net/ethernet/microchip/lan743x_main.h
> @@ -6,6 +6,7 @@
>
> #include <linux/phy.h>
> #include <linux/property.h>
> +#include <linux/phylink.h>
> #include "lan743x_ptp.h"
>
> #define DRIVER_AUTHOR "Bryan Whitehead <Bryan.Whitehead@microchip.com>"
> @@ -317,6 +318,9 @@
> /* Vendor Specific SGMII MMD details */
> #define SR_VSMMD_PCS_ID1 0x0004
> #define SR_VSMMD_PCS_ID2 0x0005
> +#define SR_MII_CTRL MII_BMCR
> +#define SR_MII_STS MII_BMSR
> +#define SR_MII_STS_LINK_STS_ BIT(2)
> #define SR_VSMMD_STS 0x0008
> #define SR_VSMMD_CTRL 0x0009
>
> @@ -1077,6 +1081,8 @@ struct lan743x_adapter {
> phy_interface_t phy_interface;
> struct lan743x_sw_nodes *nodes;
> struct i2c_adapter *i2c_adap;
> + struct phylink *phylink;
> + struct phylink_config phylink_config;
> };
>
> #define LAN743X_COMPONENT_FLAG_RX(channel) BIT(20 + (channel))
> --
> 2.25.1
>
>
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH net-next 5/7] net: lan743x: Add support to the Phylink framework
2023-07-21 8:49 ` Russell King (Oracle)
@ 2023-07-21 11:57 ` Russell King (Oracle)
2023-07-24 8:24 ` Raju Lakkaraju
0 siblings, 1 reply; 15+ messages in thread
From: Russell King (Oracle) @ 2023-07-21 11:57 UTC (permalink / raw)
To: Raju Lakkaraju
Cc: netdev, davem, kuba, linux-kernel, bryan.whitehead, andrew,
UNGLinuxDriver
On Fri, Jul 21, 2023 at 09:49:06AM +0100, Russell King (Oracle) wrote:
> On Fri, Jul 21, 2023 at 11:30:17AM +0530, Raju Lakkaraju wrote:
> > +static void lan743x_phylink_mac_config(struct phylink_config *config,
> > + unsigned int link_an_mode,
> > + const struct phylink_link_state *state)
> > +{
> > + struct net_device *netdev = to_net_dev(config->dev);
> > + struct lan743x_adapter *adapter = netdev_priv(netdev);
> > + bool status;
> > + int ret;
> > +
> > + lan743x_mac_cfg_update(adapter, state->link, state->speed,
> > + state->advertising);
>
> Please, no new state->speed users in mac_config().
I have just submitted a patch series that results in state->speed always
being set to SPEED_UNKNOWN when this function is called to prevent
future uses of this struct member.
> > + adapter->phylink_config.dev = &netdev->dev;
> > + adapter->phylink_config.type = PHYLINK_NETDEV;
> > + adapter->phylink_config.mac_managed_pm = true;
> > + /* This driver makes use of state->speed in mac_config */
> > + adapter->phylink_config.legacy_pre_march2020 = true;
>
> Sorry, but no new users of legacy features.
... and which totally strips out the legacy phylink code, which I've
been wanting to remove for the last three years.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH net-next 5/7] net: lan743x: Add support to the Phylink framework
2023-07-21 11:57 ` Russell King (Oracle)
@ 2023-07-24 8:24 ` Raju Lakkaraju
2023-08-01 14:36 ` Russell King (Oracle)
0 siblings, 1 reply; 15+ messages in thread
From: Raju Lakkaraju @ 2023-07-24 8:24 UTC (permalink / raw)
To: Russell King (Oracle)
Cc: netdev, davem, kuba, linux-kernel, bryan.whitehead, andrew,
UNGLinuxDriver
Hi Russell King,
Thank you for review comments.
The 07/21/2023 12:57, Russell King (Oracle) wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
>
> On Fri, Jul 21, 2023 at 09:49:06AM +0100, Russell King (Oracle) wrote:
> > On Fri, Jul 21, 2023 at 11:30:17AM +0530, Raju Lakkaraju wrote:
> > > +static void lan743x_phylink_mac_config(struct phylink_config *config,
> > > + unsigned int link_an_mode,
> > > + const struct phylink_link_state *state)
> > > +{
> > > + struct net_device *netdev = to_net_dev(config->dev);
> > > + struct lan743x_adapter *adapter = netdev_priv(netdev);
> > > + bool status;
> > > + int ret;
> > > +
> > > + lan743x_mac_cfg_update(adapter, state->link, state->speed,
> > > + state->advertising);
> >
> > Please, no new state->speed users in mac_config().
>
> I have just submitted a patch series that results in state->speed always
> being set to SPEED_UNKNOWN when this function is called to prevent
> future uses of this struct member.
Still, these changes are not available in "net-next" branch.
I will check and fix.
>
> > > + adapter->phylink_config.dev = &netdev->dev;
> > > + adapter->phylink_config.type = PHYLINK_NETDEV;
> > > + adapter->phylink_config.mac_managed_pm = true;
> > > + /* This driver makes use of state->speed in mac_config */
> > > + adapter->phylink_config.legacy_pre_march2020 = true;
> >
> > Sorry, but no new users of legacy features.
>
> ... and which totally strips out the legacy phylink code, which I've
> been wanting to remove for the last three years.
>
> --
> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
> FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
--
Thanks,
Raju
^ permalink raw reply [flat|nested] 15+ messages in thread* Re: [PATCH net-next 5/7] net: lan743x: Add support to the Phylink framework
2023-07-24 8:24 ` Raju Lakkaraju
@ 2023-08-01 14:36 ` Russell King (Oracle)
0 siblings, 0 replies; 15+ messages in thread
From: Russell King (Oracle) @ 2023-08-01 14:36 UTC (permalink / raw)
To: Raju Lakkaraju
Cc: netdev, davem, kuba, linux-kernel, bryan.whitehead, andrew,
UNGLinuxDriver
On Mon, Jul 24, 2023 at 01:54:49PM +0530, Raju Lakkaraju wrote:
> The 07/21/2023 12:57, Russell King (Oracle) wrote:
> > EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> >
> > On Fri, Jul 21, 2023 at 09:49:06AM +0100, Russell King (Oracle) wrote:
> > > On Fri, Jul 21, 2023 at 11:30:17AM +0530, Raju Lakkaraju wrote:
> > > > + lan743x_mac_cfg_update(adapter, state->link, state->speed,
> > > > + state->advertising);
> > >
> > > Please, no new state->speed users in mac_config().
> >
> > I have just submitted a patch series that results in state->speed always
> > being set to SPEED_UNKNOWN when this function is called to prevent
> > future uses of this struct member.
>
> Still, these changes are not available in "net-next" branch.
> I will check and fix.
The changes went in last week, which means phylink no longer supports
the legacy mode stuff, nor use of the above.
Please respin your changes to use the modern approach.
Thanks.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 15+ messages in thread
* Re: [PATCH net-next 5/7] net: lan743x: Add support to the Phylink framework
2023-07-21 6:00 ` [PATCH net-next 5/7] net: lan743x: Add support to the Phylink framework Raju Lakkaraju
2023-07-21 8:49 ` Russell King (Oracle)
@ 2023-07-22 20:27 ` Simon Horman
1 sibling, 0 replies; 15+ messages in thread
From: Simon Horman @ 2023-07-22 20:27 UTC (permalink / raw)
To: Raju Lakkaraju
Cc: netdev, davem, kuba, linux-kernel, bryan.whitehead, andrew, linux,
UNGLinuxDriver
On Fri, Jul 21, 2023 at 11:30:17AM +0530, Raju Lakkaraju wrote:
...
> +static void lan743x_phylink_mac_config(struct phylink_config *config,
> + unsigned int link_an_mode,
> + const struct phylink_link_state *state)
> +{
> + struct net_device *netdev = to_net_dev(config->dev);
> + struct lan743x_adapter *adapter = netdev_priv(netdev);
> + bool status;
> + int ret;
> +
> + lan743x_mac_cfg_update(adapter, state->link, state->speed,
> + state->advertising);
> +
> + if (!state->link && adapter->is_sgmii_en) {
> + ret = lan743x_sgmii_aneg_update(adapter);
> + if (ret < 0) {
> + netif_err(adapter, drv, adapter->netdev,
> + "error %d SGMII cfg failed\n", ret);
Hi Raju,
Maybe "error" is appropriate here and in other similar error messages
in this patch.
> + return;
> + }
...
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH net-next 6/7] net: lan743x: Add support to ethtool phylink get and set settings
2023-07-21 6:00 [PATCH net-next 0/7] Add support to PHYLINK and SFP for PCI11x1x chips Raju Lakkaraju
` (4 preceding siblings ...)
2023-07-21 6:00 ` [PATCH net-next 5/7] net: lan743x: Add support to the Phylink framework Raju Lakkaraju
@ 2023-07-21 6:00 ` Raju Lakkaraju
2023-07-21 8:53 ` Russell King (Oracle)
2023-07-21 6:00 ` [PATCH net-next 7/7] net: lan743x: Register the platform device for sfp pluggable module Raju Lakkaraju
6 siblings, 1 reply; 15+ messages in thread
From: Raju Lakkaraju @ 2023-07-21 6:00 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, linux-kernel, bryan.whitehead, andrew, linux,
UNGLinuxDriver
Add support to ethtool phylink get/set settings for the network interface via
ethtool like speed, duplex etc.
Signed-off-by: Raju Lakkaraju <Raju.Lakkaraju@microchip.com>
---
.../net/ethernet/microchip/lan743x_ethtool.c | 34 +++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/microchip/lan743x_ethtool.c b/drivers/net/ethernet/microchip/lan743x_ethtool.c
index 2db5949b4c7e..3004863bebf8 100644
--- a/drivers/net/ethernet/microchip/lan743x_ethtool.c
+++ b/drivers/net/ethernet/microchip/lan743x_ethtool.c
@@ -1134,6 +1134,36 @@ static int lan743x_ethtool_set_eee(struct net_device *netdev,
return phy_ethtool_set_eee(phydev, eee);
}
+static int lan743x_ethtool_set_link_ksettings(struct net_device *netdev,
+ const struct ethtool_link_ksettings *cmd)
+{
+ struct lan743x_adapter *adapter = netdev_priv(netdev);
+ int ret;
+
+ if (adapter->phylink) {
+ ret = lan743x_lsd_update(cmd->base.speed, cmd->base.duplex,
+ cmd->base.master_slave_state);
+ if (ret < 0)
+ return ret;
+
+ adapter->sgmii_lsd = ret;
+ return phylink_ethtool_ksettings_set(adapter->phylink, cmd);
+ }
+
+ return phy_ethtool_set_link_ksettings(netdev, cmd);
+}
+
+static int lan743x_ethtool_get_link_ksettings(struct net_device *netdev,
+ struct ethtool_link_ksettings *cmd)
+{
+ struct lan743x_adapter *adapter = netdev_priv(netdev);
+
+ if (adapter->phylink)
+ return phylink_ethtool_ksettings_get(adapter->phylink, cmd);
+
+ return phy_ethtool_get_link_ksettings(netdev, cmd);
+}
+
#ifdef CONFIG_PM
static void lan743x_ethtool_get_wol(struct net_device *netdev,
struct ethtool_wolinfo *wol)
@@ -1400,8 +1430,8 @@ const struct ethtool_ops lan743x_ethtool_ops = {
.get_ts_info = lan743x_ethtool_get_ts_info,
.get_eee = lan743x_ethtool_get_eee,
.set_eee = lan743x_ethtool_set_eee,
- .get_link_ksettings = phy_ethtool_get_link_ksettings,
- .set_link_ksettings = phy_ethtool_set_link_ksettings,
+ .get_link_ksettings = lan743x_ethtool_get_link_ksettings,
+ .set_link_ksettings = lan743x_ethtool_set_link_ksettings,
.get_regs_len = lan743x_get_regs_len,
.get_regs = lan743x_get_regs,
.get_pauseparam = lan743x_get_pauseparam,
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread* Re: [PATCH net-next 6/7] net: lan743x: Add support to ethtool phylink get and set settings
2023-07-21 6:00 ` [PATCH net-next 6/7] net: lan743x: Add support to ethtool phylink get and set settings Raju Lakkaraju
@ 2023-07-21 8:53 ` Russell King (Oracle)
0 siblings, 0 replies; 15+ messages in thread
From: Russell King (Oracle) @ 2023-07-21 8:53 UTC (permalink / raw)
To: Raju Lakkaraju
Cc: netdev, davem, kuba, linux-kernel, bryan.whitehead, andrew,
UNGLinuxDriver
On Fri, Jul 21, 2023 at 11:30:18AM +0530, Raju Lakkaraju wrote:
> Add support to ethtool phylink get/set settings for the network interface via
> ethtool like speed, duplex etc.
>
> Signed-off-by: Raju Lakkaraju <Raju.Lakkaraju@microchip.com>
> ---
> .../net/ethernet/microchip/lan743x_ethtool.c | 34 +++++++++++++++++--
> 1 file changed, 32 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/microchip/lan743x_ethtool.c b/drivers/net/ethernet/microchip/lan743x_ethtool.c
> index 2db5949b4c7e..3004863bebf8 100644
> --- a/drivers/net/ethernet/microchip/lan743x_ethtool.c
> +++ b/drivers/net/ethernet/microchip/lan743x_ethtool.c
> @@ -1134,6 +1134,36 @@ static int lan743x_ethtool_set_eee(struct net_device *netdev,
> return phy_ethtool_set_eee(phydev, eee);
> }
>
> +static int lan743x_ethtool_set_link_ksettings(struct net_device *netdev,
> + const struct ethtool_link_ksettings *cmd)
> +{
> + struct lan743x_adapter *adapter = netdev_priv(netdev);
> + int ret;
> +
> + if (adapter->phylink) {
> + ret = lan743x_lsd_update(cmd->base.speed, cmd->base.duplex,
> + cmd->base.master_slave_state);
> + if (ret < 0)
> + return ret;
> +
> + adapter->sgmii_lsd = ret;
I guess this is how you are hacking SGMII to do what you want - using
the ethtool master_slave_state to control whether SGMII is operating as
a "host" or a "PHY", and I would say it's a hack to make stuff work the
way you want it to, so you can run SGMII over a DAC cable at speeds
such as 100M. I really don't see what the point of that is.
In any case, doing this is buggy. You update state, and then call
into phylink. What if phylink returns an error? You've updated the
state which may take effect if the link goes up/down but maybe the
settings were rejected by phylink.
Sorry, but no, this to me is a gross hack.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 15+ messages in thread
* [PATCH net-next 7/7] net: lan743x: Register the platform device for sfp pluggable module
2023-07-21 6:00 [PATCH net-next 0/7] Add support to PHYLINK and SFP for PCI11x1x chips Raju Lakkaraju
` (5 preceding siblings ...)
2023-07-21 6:00 ` [PATCH net-next 6/7] net: lan743x: Add support to ethtool phylink get and set settings Raju Lakkaraju
@ 2023-07-21 6:00 ` Raju Lakkaraju
6 siblings, 0 replies; 15+ messages in thread
From: Raju Lakkaraju @ 2023-07-21 6:00 UTC (permalink / raw)
To: netdev
Cc: davem, kuba, linux-kernel, bryan.whitehead, andrew, linux,
UNGLinuxDriver
Add support for SFP pluggable module as platform device handle the GPIO
input and output signals and i2c bus access the SFP EEPROM data.
Signed-off-by: Raju Lakkaraju <Raju.Lakkaraju@microchip.com>
---
drivers/net/ethernet/microchip/lan743x_main.c | 39 +++++++++++++++++++
drivers/net/ethernet/microchip/lan743x_main.h | 1 +
2 files changed, 40 insertions(+)
diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c
index 9b6326d035a8..2dd0965982fb 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.c
+++ b/drivers/net/ethernet/microchip/lan743x_main.c
@@ -17,6 +17,7 @@
#include <linux/crc16.h>
#include <linux/gpio/machine.h>
#include <linux/i2c.h>
+#include <linux/platform_device.h>
#include "../../../misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.h"
#include "lan743x_main.h"
#include "lan743x_ethtool.h"
@@ -3228,6 +3229,31 @@ static int lan743x_swnodes_register(struct lan743x_adapter *adapter)
return software_node_register_node_group(nodes->group);
}
+static int lan743x_sfp_register(struct lan743x_adapter *adapter)
+{
+ struct pci_dev *pdev = adapter->pdev;
+ struct platform_device_info sfp_info;
+ struct platform_device *sfp_dev;
+
+ memset(&sfp_info, 0, sizeof(sfp_info));
+ sfp_info.parent = &adapter->pdev->dev;
+ sfp_info.fwnode = software_node_fwnode(adapter->nodes->group[SWNODE_SFP]);
+ sfp_info.name = "sfp";
+ sfp_info.id = (pdev->bus->number << 8) | pdev->devfn;
+ sfp_dev = platform_device_register_full(&sfp_info);
+ if (IS_ERR(sfp_dev)) {
+ netif_err(adapter, drv, adapter->netdev,
+ "Failed to register SFP device\n");
+ return PTR_ERR(sfp_dev);
+ }
+
+ adapter->sfp_dev = sfp_dev;
+ netif_dbg(adapter, drv, adapter->netdev,
+ "SFP platform device registered");
+
+ return 0;
+}
+
static void lan743x_mac_cfg_update(struct lan743x_adapter *adapter, bool link,
int speed, const unsigned long *advertise)
{
@@ -3715,6 +3741,9 @@ static void lan743x_hardware_cleanup(struct lan743x_adapter *adapter)
if (adapter->phylink)
phylink_destroy(adapter->phylink);
+ if (adapter->sfp_dev)
+ platform_device_unregister(adapter->sfp_dev);
+
if (adapter->nodes)
software_node_unregister_node_group(adapter->nodes->group);
@@ -3942,6 +3971,16 @@ static int lan743x_pcidev_probe(struct pci_dev *pdev,
adapter->sgmii_lsd = LINK_2500_MASTER;
if (adapter->is_sfp_support_en) {
+ adapter->i2c_adap->dev.fwnode =
+ software_node_fwnode(adapter->nodes->group[SWNODE_I2C]);
+
+ ret = lan743x_sfp_register(adapter);
+ if (ret < 0) {
+ netif_err(adapter, probe, netdev,
+ "failed to sfp register (%d)\n", ret);
+ goto cleanup_hardware;
+ }
+
ret = lan743x_phylink_create(adapter->netdev);
if (ret) {
netif_err(adapter, probe, netdev,
diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h
index 6b94d0e93cbb..d23cf1ca888c 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.h
+++ b/drivers/net/ethernet/microchip/lan743x_main.h
@@ -1083,6 +1083,7 @@ struct lan743x_adapter {
struct i2c_adapter *i2c_adap;
struct phylink *phylink;
struct phylink_config phylink_config;
+ struct platform_device *sfp_dev;
};
#define LAN743X_COMPONENT_FLAG_RX(channel) BIT(20 + (channel))
--
2.25.1
^ permalink raw reply related [flat|nested] 15+ messages in thread