Skip to content

Commit

Permalink
Merge branch 'net-tn40xx-add-support-for-aqr105-based-cards'
Browse files Browse the repository at this point in the history
Hans-Frieder Vogt says:

====================
net: tn40xx: add support for AQR105 based cards

This patch series adds support to the Tehuti tn40xx driver for TN9510 cards
which combine a TN4010 MAC with an Aquantia AQR105.
It is an update of the patch series "net: tn40xx: add support for AQR105
based cards", addressing review comments and generally cleaning up the series.

The patch was tested on a Tehuti TN9510 card (1fc9:4025:1fc9:3015).

v6: https://lore.kernel.org/20250318-tn9510-v3a-v6-0-808a9089d24b@gmx.net
v5: https://lore.kernel.org/20250222-tn9510-v3a-v5-0-99365047e309@gmx.net
v4: https://lore.kernel.org/20241221-tn9510-v3a-v4-0-dafff89ba7a7@gmx.net
v3: https://lore.kernel.org/20241217-tn9510-v3a-v3-0-4d5ef6f686e0@gmx.net
v2: https://lore.kernel.org/trinity-602c050f-bc76-4557-9824-252b0de48659-1726429697171@3c-app-gmx-bap07
v1: https://lore.kernel.org/trinity-33332a4a-1c44-46b7-8526-b53b1a94ffc2-1726082106356@3c-app-gmx-bs04
====================

Link: https://patch.msgid.link/20250322-tn9510-v3a-v7-0-672a9a3d8628@gmx.net
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Jakub Kicinski committed Mar 25, 2025
2 parents e2ac75a + 53377b5 commit b6f61a3
Show file tree
Hide file tree
Showing 6 changed files with 378 additions and 9 deletions.
9 changes: 8 additions & 1 deletion drivers/net/ethernet/tehuti/tn40.c
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ static int tn40_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
ret = tn40_phy_register(priv);
if (ret) {
dev_err(&pdev->dev, "failed to set up PHY.\n");
goto err_free_irq;
goto err_cleanup_swnodes;
}

ret = tn40_priv_init(priv);
Expand All @@ -1795,6 +1795,8 @@ static int tn40_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
return 0;
err_unregister_phydev:
tn40_phy_unregister(priv);
err_cleanup_swnodes:
tn40_swnodes_cleanup(priv);
err_free_irq:
pci_free_irq_vectors(pdev);
err_unset_drvdata:
Expand All @@ -1816,6 +1818,7 @@ static void tn40_remove(struct pci_dev *pdev)
unregister_netdev(ndev);

tn40_phy_unregister(priv);
tn40_swnodes_cleanup(priv);
pci_free_irq_vectors(priv->pdev);
pci_set_drvdata(pdev, NULL);
iounmap(priv->regs);
Expand All @@ -1832,6 +1835,10 @@ static const struct pci_device_id tn40_id_table[] = {
PCI_VENDOR_ID_ASUSTEK, 0x8709) },
{ PCI_DEVICE_SUB(PCI_VENDOR_ID_TEHUTI, 0x4022,
PCI_VENDOR_ID_EDIMAX, 0x8103) },
{ PCI_DEVICE_SUB(PCI_VENDOR_ID_TEHUTI, PCI_DEVICE_ID_TEHUTI_TN9510,
PCI_VENDOR_ID_TEHUTI, 0x3015) },
{ PCI_DEVICE_SUB(PCI_VENDOR_ID_TEHUTI, PCI_DEVICE_ID_TEHUTI_TN9510,
PCI_VENDOR_ID_EDIMAX, 0x8102) },
{ }
};

Expand Down
33 changes: 33 additions & 0 deletions drivers/net/ethernet/tehuti/tn40.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
#ifndef _TN40_H_
#define _TN40_H_

#include <linux/property.h>
#include "tn40_regs.h"

#define TN40_DRV_NAME "tn40xx"

#define PCI_DEVICE_ID_TEHUTI_TN9510 0x4025

#define TN40_MDIO_SPEED_1MHZ (1)
#define TN40_MDIO_SPEED_6MHZ (6)

Expand Down Expand Up @@ -102,10 +105,39 @@ struct tn40_txdb {
int size; /* Number of elements in the db */
};

#define NODE_PROP(_NAME, _PROP) ( \
(const struct software_node) { \
.name = _NAME, \
.properties = _PROP, \
})

#define NODE_PAR_PROP(_NAME, _PAR, _PROP) ( \
(const struct software_node) { \
.name = _NAME, \
.parent = _PAR, \
.properties = _PROP, \
})

enum tn40_swnodes {
SWNODE_MDIO,
SWNODE_PHY,
SWNODE_MAX
};

struct tn40_nodes {
char phy_name[32];
char mdio_name[32];
struct property_entry phy_props[3];
struct software_node swnodes[SWNODE_MAX];
const struct software_node *group[SWNODE_MAX + 1];
};

struct tn40_priv {
struct net_device *ndev;
struct pci_dev *pdev;

struct tn40_nodes nodes;

struct napi_struct napi;
/* RX FIFOs: 1 for data (full) descs, and 2 for free descs */
struct tn40_rxd_fifo rxd_fifo0;
Expand Down Expand Up @@ -225,6 +257,7 @@ static inline void tn40_write_reg(struct tn40_priv *priv, u32 reg, u32 val)

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

void tn40_swnodes_cleanup(struct tn40_priv *priv);
int tn40_mdiobus_init(struct tn40_priv *priv);

int tn40_phy_register(struct tn40_priv *priv);
Expand Down
84 changes: 81 additions & 3 deletions drivers/net/ethernet/tehuti/tn40_mdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
(FIELD_PREP(TN40_MDIO_PRTAD_MASK, (port))))
#define TN40_MDIO_CMD_READ BIT(15)

#define AQR105_FIRMWARE "tehuti/aqr105-tn40xx.cld"

static void tn40_mdio_set_speed(struct tn40_priv *priv, u32 speed)
{
void __iomem *regs = priv->regs;
Expand Down Expand Up @@ -111,6 +113,56 @@ static int tn40_mdio_write_c45(struct mii_bus *mii_bus, int addr, int devnum,
return tn40_mdio_write(mii_bus->priv, addr, devnum, regnum, val);
}

/* registers an mdio node and an aqr105 PHY at address 1
* tn40_mdio-%id {
* ethernet-phy@1 {
* compatible = "ethernet-phy-id03a1.b4a3";
* reg = <1>;
* firmware-name = AQR105_FIRMWARE;
* };
* };
*/
static int tn40_swnodes_register(struct tn40_priv *priv)
{
struct tn40_nodes *nodes = &priv->nodes;
struct pci_dev *pdev = priv->pdev;
struct software_node *swnodes;
u32 id;

id = pci_dev_id(pdev);

snprintf(nodes->phy_name, sizeof(nodes->phy_name), "ethernet-phy@1");
snprintf(nodes->mdio_name, sizeof(nodes->mdio_name), "tn40_mdio-%x",
id);

swnodes = nodes->swnodes;

swnodes[SWNODE_MDIO] = NODE_PROP(nodes->mdio_name, NULL);

nodes->phy_props[0] = PROPERTY_ENTRY_STRING("compatible",
"ethernet-phy-id03a1.b4a3");
nodes->phy_props[1] = PROPERTY_ENTRY_U32("reg", 1);
nodes->phy_props[2] = PROPERTY_ENTRY_STRING("firmware-name",
AQR105_FIRMWARE);
swnodes[SWNODE_PHY] = NODE_PAR_PROP(nodes->phy_name,
&swnodes[SWNODE_MDIO],
nodes->phy_props);

nodes->group[SWNODE_PHY] = &swnodes[SWNODE_PHY];
nodes->group[SWNODE_MDIO] = &swnodes[SWNODE_MDIO];
return software_node_register_node_group(nodes->group);
}

void tn40_swnodes_cleanup(struct tn40_priv *priv)
{
/* cleanup of swnodes is only needed for AQR105-based cards */
if (priv->pdev->device == PCI_DEVICE_ID_TEHUTI_TN9510) {
fwnode_handle_put(dev_fwnode(&priv->mdio->dev));
device_remove_software_node(&priv->mdio->dev);
software_node_unregister_node_group(priv->nodes.group);
}
}

int tn40_mdiobus_init(struct tn40_priv *priv)
{
struct pci_dev *pdev = priv->pdev;
Expand All @@ -129,14 +181,40 @@ int tn40_mdiobus_init(struct tn40_priv *priv)

bus->read_c45 = tn40_mdio_read_c45;
bus->write_c45 = tn40_mdio_write_c45;
priv->mdio = bus;

/* provide swnodes for AQR105-based cards only */
if (pdev->device == PCI_DEVICE_ID_TEHUTI_TN9510) {
ret = tn40_swnodes_register(priv);
if (ret) {
pr_err("swnodes failed\n");
return ret;
}

ret = device_add_software_node(&bus->dev,
priv->nodes.group[SWNODE_MDIO]);
if (ret) {
dev_err(&pdev->dev,
"device_add_software_node failed: %d\n", ret);
goto err_swnodes_unregister;
}
}

tn40_mdio_set_speed(priv, TN40_MDIO_SPEED_6MHZ);
ret = devm_mdiobus_register(&pdev->dev, bus);
if (ret) {
dev_err(&pdev->dev, "failed to register mdiobus %d %u %u\n",
ret, bus->state, MDIOBUS_UNREGISTERED);
return ret;
goto err_swnodes_cleanup;
}
tn40_mdio_set_speed(priv, TN40_MDIO_SPEED_6MHZ);
priv->mdio = bus;
return 0;

err_swnodes_unregister:
software_node_unregister_node_group(priv->nodes.group);
return ret;
err_swnodes_cleanup:
tn40_swnodes_cleanup(priv);
return ret;
}

MODULE_FIRMWARE(AQR105_FIRMWARE);
7 changes: 4 additions & 3 deletions drivers/net/phy/aquantia/aquantia_firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,11 @@ static int aqr_firmware_load_fs(struct phy_device *phydev)
const char *fw_name;
int ret;

ret = of_property_read_string(dev->of_node, "firmware-name",
&fw_name);
if (ret)
ret = device_property_read_string(dev, "firmware-name", &fw_name);
if (ret) {
phydev_err(phydev, "failed to read firmware-name: %d\n", ret);
return ret;
}

ret = request_firmware(&fw, fw_name, dev);
if (ret) {
Expand Down
Loading

0 comments on commit b6f61a3

Please sign in to comment.