aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/mvebu/patches-4.19/405-net-phy-marvell10g-add-SFP-support.patch
blob: 9624b6cd812755c41f7f4e2a451f3a820a00e06c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
From 5f3ac54810055fec0cc667bb04c16f783830abff Mon Sep 17 00:00:00 2001
From: Russell King <rmk+kernel@armlinux.org.uk>
Date: Fri, 14 Apr 2017 14:21:25 +0100
Subject: [PATCH] net: phy: marvell10g: add SFP+ support

Add support for SFP+ cages to the Marvell 10G PHY driver. This is
slightly complicated by the way phylib works in that we need to use
a multi-step process to attach the SFP bus, and we also need to track
the phylink state machine to know when the module's transmit disable
signal should change state.

With appropriate DT changes, this allows the SFP+ canges on the
Macchiatobin platform to be functional.

Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
---
 drivers/net/phy/marvell10g.c | 80 ++++++++++++++++++++++++++++++++++++
 1 file changed, 80 insertions(+)

--- a/drivers/net/phy/marvell10g.c
+++ b/drivers/net/phy/marvell10g.c
@@ -25,6 +25,8 @@
 #include <linux/hwmon.h>
 #include <linux/marvell_phy.h>
 #include <linux/phy.h>
+#include <linux/property.h>
+#include <linux/sfp.h>
 
 enum {
 	MV_PMA_BOOT		= 0xc050,
@@ -56,6 +58,11 @@ enum {
 };
 
 struct mv3310_priv {
+	struct fwnode_handle *sfp_fwnode;
+	struct sfp_bus *sfp_bus;
+	enum phy_state state;
+	bool running;
+
 	struct device *hwmon_dev;
 	char *hwmon_name;
 };
@@ -219,6 +226,27 @@ static int mv3310_hwmon_probe(struct phy
 }
 #endif
 
+static int mv3310_sfp_insert(void *upstream, const struct sfp_eeprom_id *id)
+{
+	struct phy_device *phydev = upstream;
+	struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev);
+	__ETHTOOL_DECLARE_LINK_MODE_MASK(support) = { 0, };
+	phy_interface_t iface;
+
+	sfp_parse_support(priv->sfp_bus, id, support);
+	iface = sfp_select_interface(priv->sfp_bus, id, support);
+
+	if (iface != PHY_INTERFACE_MODE_10GKR) {
+		dev_err(&phydev->mdio.dev, "incompatible SFP module inserted\n");
+		return -EINVAL;
+	}
+	return 0;
+}
+
+static const struct sfp_upstream_ops mv3310_sfp_ops = {
+	.module_insert = mv3310_sfp_insert,
+};
+
 static int mv3310_probe(struct phy_device *phydev)
 {
 	struct mv3310_priv *priv;
@@ -249,9 +277,30 @@ static int mv3310_probe(struct phy_devic
 	if (ret)
 		return ret;
 
+	if (phydev->mdio.dev.fwnode) {
+		struct fwnode_reference_args ref;
+		int ret;
+
+		ret = fwnode_property_get_reference_args(phydev->mdio.dev.fwnode,
+							 "sfp", NULL, 0, 0,
+							 &ref);
+		if (ret == 0)
+			priv->sfp_fwnode = ref.fwnode;
+	}
+
 	return 0;
 }
 
+static void mv3310_remove(struct phy_device *phydev)
+{
+	struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev);
+
+	if (priv->sfp_bus)
+		sfp_unregister_upstream(priv->sfp_bus);
+
+	fwnode_handle_put(priv->sfp_fwnode);
+}
+
 static int mv3310_suspend(struct phy_device *phydev)
 {
 	return 0;
@@ -262,8 +311,29 @@ static int mv3310_resume(struct phy_devi
 	return mv3310_hwmon_config(phydev, true);
 }
 
+static void mv3310_link_change_notify(struct phy_device *phydev)
+{
+	struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev);
+	enum phy_state state = phydev->state;
+	bool running;
+
+	if (priv->sfp_bus && priv->state != state) {
+		priv->state = state;
+
+		running = state >= PHY_UP && state < PHY_HALTED;
+		if (priv->running != running) {
+			priv->running = running;
+			if (running)
+				sfp_upstream_start(priv->sfp_bus);
+			else
+				sfp_upstream_stop(priv->sfp_bus);
+		}
+	}
+}
+
 static int mv3310_config_init(struct phy_device *phydev)
 {
+	struct mv3310_priv *priv = dev_get_drvdata(&phydev->mdio.dev);
 	__ETHTOOL_DECLARE_LINK_MODE_MASK(supported) = { 0, };
 	u32 mask;
 	int val;
@@ -357,6 +427,14 @@ static int mv3310_config_init(struct phy
 	phydev->supported &= mask;
 	phydev->advertising &= phydev->supported;
 
+	/* Would be nice to do this in the probe function, but unfortunately,
+	 * phylib doesn't have phydev->attached_dev set there.
+	 */
+	if (priv->sfp_fwnode && !priv->sfp_bus)
+		priv->sfp_bus = sfp_register_upstream(priv->sfp_fwnode,
+						      phydev->attached_dev,
+						      phydev, &mv3310_sfp_ops);
+
 	return 0;
 }
 
@@ -566,6 +644,8 @@ static struct phy_driver mv3310_drivers[
 		.config_aneg	= mv3310_config_aneg,
 		.aneg_done	= mv3310_aneg_done,
 		.read_status	= mv3310_read_status,
+		.remove		= mv3310_remove,
+		.link_change_notify = mv3310_link_change_notify,
 	},
 };