Skip to content

Commit 25b6a6d

Browse files
Hans-Frieder Vogtkuba-moo
authored andcommitted
net: tn40xx: create swnode for mdio and aqr105 phy and add to mdiobus
In case of an AQR105-based device, create a software node for the mdio function, with a child node for the Aquantia AQR105 PHY, providing a firmware-name (and a bit more, which may be used for future checks) to allow the PHY to load a MAC specific firmware from the file system. The name of the PHY software node follows the naming convention suggested in the patch for the mdiobus_scan function (in the same patch series). Signed-off-by: Hans-Frieder Vogt <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent e31e67f commit 25b6a6d

File tree

3 files changed

+117
-3
lines changed

3 files changed

+117
-3
lines changed

drivers/net/ethernet/tehuti/tn40.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,7 +1778,7 @@ static int tn40_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
17781778
ret = tn40_phy_register(priv);
17791779
if (ret) {
17801780
dev_err(&pdev->dev, "failed to set up PHY.\n");
1781-
goto err_free_irq;
1781+
goto err_cleanup_swnodes;
17821782
}
17831783

17841784
ret = tn40_priv_init(priv);
@@ -1795,6 +1795,8 @@ static int tn40_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
17951795
return 0;
17961796
err_unregister_phydev:
17971797
tn40_phy_unregister(priv);
1798+
err_cleanup_swnodes:
1799+
tn40_swnodes_cleanup(priv);
17981800
err_free_irq:
17991801
pci_free_irq_vectors(pdev);
18001802
err_unset_drvdata:
@@ -1816,6 +1818,7 @@ static void tn40_remove(struct pci_dev *pdev)
18161818
unregister_netdev(ndev);
18171819

18181820
tn40_phy_unregister(priv);
1821+
tn40_swnodes_cleanup(priv);
18191822
pci_free_irq_vectors(priv->pdev);
18201823
pci_set_drvdata(pdev, NULL);
18211824
iounmap(priv->regs);

drivers/net/ethernet/tehuti/tn40.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@
44
#ifndef _TN40_H_
55
#define _TN40_H_
66

7+
#include <linux/property.h>
78
#include "tn40_regs.h"
89

910
#define TN40_DRV_NAME "tn40xx"
1011

12+
#define PCI_DEVICE_ID_TEHUTI_TN9510 0x4025
13+
1114
#define TN40_MDIO_SPEED_1MHZ (1)
1215
#define TN40_MDIO_SPEED_6MHZ (6)
1316

@@ -102,10 +105,39 @@ struct tn40_txdb {
102105
int size; /* Number of elements in the db */
103106
};
104107

108+
#define NODE_PROP(_NAME, _PROP) ( \
109+
(const struct software_node) { \
110+
.name = _NAME, \
111+
.properties = _PROP, \
112+
})
113+
114+
#define NODE_PAR_PROP(_NAME, _PAR, _PROP) ( \
115+
(const struct software_node) { \
116+
.name = _NAME, \
117+
.parent = _PAR, \
118+
.properties = _PROP, \
119+
})
120+
121+
enum tn40_swnodes {
122+
SWNODE_MDIO,
123+
SWNODE_PHY,
124+
SWNODE_MAX
125+
};
126+
127+
struct tn40_nodes {
128+
char phy_name[32];
129+
char mdio_name[32];
130+
struct property_entry phy_props[3];
131+
struct software_node swnodes[SWNODE_MAX];
132+
const struct software_node *group[SWNODE_MAX + 1];
133+
};
134+
105135
struct tn40_priv {
106136
struct net_device *ndev;
107137
struct pci_dev *pdev;
108138

139+
struct tn40_nodes nodes;
140+
109141
struct napi_struct napi;
110142
/* RX FIFOs: 1 for data (full) descs, and 2 for free descs */
111143
struct tn40_rxd_fifo rxd_fifo0;
@@ -225,6 +257,7 @@ static inline void tn40_write_reg(struct tn40_priv *priv, u32 reg, u32 val)
225257

226258
int tn40_set_link_speed(struct tn40_priv *priv, u32 speed);
227259

260+
void tn40_swnodes_cleanup(struct tn40_priv *priv);
228261
int tn40_mdiobus_init(struct tn40_priv *priv);
229262

230263
int tn40_phy_register(struct tn40_priv *priv);

drivers/net/ethernet/tehuti/tn40_mdio.c

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
(FIELD_PREP(TN40_MDIO_PRTAD_MASK, (port))))
1515
#define TN40_MDIO_CMD_READ BIT(15)
1616

17+
#define AQR105_FIRMWARE "tehuti/aqr105-tn40xx.cld"
18+
1719
static void tn40_mdio_set_speed(struct tn40_priv *priv, u32 speed)
1820
{
1921
void __iomem *regs = priv->regs;
@@ -111,6 +113,56 @@ static int tn40_mdio_write_c45(struct mii_bus *mii_bus, int addr, int devnum,
111113
return tn40_mdio_write(mii_bus->priv, addr, devnum, regnum, val);
112114
}
113115

116+
/* registers an mdio node and an aqr105 PHY at address 1
117+
* tn40_mdio-%id {
118+
* ethernet-phy@1 {
119+
* compatible = "ethernet-phy-id03a1.b4a3";
120+
* reg = <1>;
121+
* firmware-name = AQR105_FIRMWARE;
122+
* };
123+
* };
124+
*/
125+
static int tn40_swnodes_register(struct tn40_priv *priv)
126+
{
127+
struct tn40_nodes *nodes = &priv->nodes;
128+
struct pci_dev *pdev = priv->pdev;
129+
struct software_node *swnodes;
130+
u32 id;
131+
132+
id = pci_dev_id(pdev);
133+
134+
snprintf(nodes->phy_name, sizeof(nodes->phy_name), "ethernet-phy@1");
135+
snprintf(nodes->mdio_name, sizeof(nodes->mdio_name), "tn40_mdio-%x",
136+
id);
137+
138+
swnodes = nodes->swnodes;
139+
140+
swnodes[SWNODE_MDIO] = NODE_PROP(nodes->mdio_name, NULL);
141+
142+
nodes->phy_props[0] = PROPERTY_ENTRY_STRING("compatible",
143+
"ethernet-phy-id03a1.b4a3");
144+
nodes->phy_props[1] = PROPERTY_ENTRY_U32("reg", 1);
145+
nodes->phy_props[2] = PROPERTY_ENTRY_STRING("firmware-name",
146+
AQR105_FIRMWARE);
147+
swnodes[SWNODE_PHY] = NODE_PAR_PROP(nodes->phy_name,
148+
&swnodes[SWNODE_MDIO],
149+
nodes->phy_props);
150+
151+
nodes->group[SWNODE_PHY] = &swnodes[SWNODE_PHY];
152+
nodes->group[SWNODE_MDIO] = &swnodes[SWNODE_MDIO];
153+
return software_node_register_node_group(nodes->group);
154+
}
155+
156+
void tn40_swnodes_cleanup(struct tn40_priv *priv)
157+
{
158+
/* cleanup of swnodes is only needed for AQR105-based cards */
159+
if (priv->pdev->device == PCI_DEVICE_ID_TEHUTI_TN9510) {
160+
fwnode_handle_put(dev_fwnode(&priv->mdio->dev));
161+
device_remove_software_node(&priv->mdio->dev);
162+
software_node_unregister_node_group(priv->nodes.group);
163+
}
164+
}
165+
114166
int tn40_mdiobus_init(struct tn40_priv *priv)
115167
{
116168
struct pci_dev *pdev = priv->pdev;
@@ -129,14 +181,40 @@ int tn40_mdiobus_init(struct tn40_priv *priv)
129181

130182
bus->read_c45 = tn40_mdio_read_c45;
131183
bus->write_c45 = tn40_mdio_write_c45;
184+
priv->mdio = bus;
185+
186+
/* provide swnodes for AQR105-based cards only */
187+
if (pdev->device == PCI_DEVICE_ID_TEHUTI_TN9510) {
188+
ret = tn40_swnodes_register(priv);
189+
if (ret) {
190+
pr_err("swnodes failed\n");
191+
return ret;
192+
}
193+
194+
ret = device_add_software_node(&bus->dev,
195+
priv->nodes.group[SWNODE_MDIO]);
196+
if (ret) {
197+
dev_err(&pdev->dev,
198+
"device_add_software_node failed: %d\n", ret);
199+
goto err_swnodes_unregister;
200+
}
201+
}
132202

133203
ret = devm_mdiobus_register(&pdev->dev, bus);
134204
if (ret) {
135205
dev_err(&pdev->dev, "failed to register mdiobus %d %u %u\n",
136206
ret, bus->state, MDIOBUS_UNREGISTERED);
137-
return ret;
207+
goto err_swnodes_cleanup;
138208
}
139209
tn40_mdio_set_speed(priv, TN40_MDIO_SPEED_6MHZ);
140-
priv->mdio = bus;
141210
return 0;
211+
212+
err_swnodes_unregister:
213+
software_node_unregister_node_group(priv->nodes.group);
214+
return ret;
215+
err_swnodes_cleanup:
216+
tn40_swnodes_cleanup(priv);
217+
return ret;
142218
}
219+
220+
MODULE_FIRMWARE(AQR105_FIRMWARE);

0 commit comments

Comments
 (0)