Add phylink support for GDM2/3/4 port that require configuration of the
PCS to make the external PHY or attached SFP cage work.
These needs to be defined in the GDM port node using the pcs-handle
property.
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
drivers/net/ethernet/airoha/airoha_eth.c | 138 ++++++++++++++++++++++
drivers/net/ethernet/airoha/airoha_eth.h | 3 +
drivers/net/ethernet/airoha/airoha_regs.h | 12 ++
3 files changed, 153 insertions(+)
diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
index 16c7896f931f..17521be820b5 100644
--- a/drivers/net/ethernet/airoha/airoha_eth.c
+++ b/drivers/net/ethernet/airoha/airoha_eth.c
@@ -7,6 +7,7 @@
#include <linux/of_net.h>
#include <linux/platform_device.h>
#include <linux/tcp.h>
+#include <linux/pcs/pcs.h>
#include <linux/u64_stats_sync.h>
#include <net/dst_metadata.h>
#include <net/page_pool/helpers.h>
@@ -79,6 +80,11 @@ static bool airhoa_is_lan_gdm_port(struct airoha_gdm_port *port)
return port->id == 1;
}
+static bool airhoa_is_phy_external(struct airoha_gdm_port *port)
+{
+ return port->id != 1;
+}
+
static void airoha_set_macaddr(struct airoha_gdm_port *port, const u8 *addr)
{
struct airoha_eth *eth = port->qdma->eth;
@@ -1613,6 +1619,17 @@ static int airoha_dev_open(struct net_device *dev)
struct airoha_gdm_port *port = netdev_priv(dev);
struct airoha_qdma *qdma = port->qdma;
+ if (airhoa_is_phy_external(port)) {
+ err = phylink_of_phy_connect(port->phylink, dev->dev.of_node, 0);
+ if (err) {
+ netdev_err(dev, "%s: could not attach PHY: %d\n", __func__,
+ err);
+ return err;
+ }
+
+ phylink_start(port->phylink);
+ }
+
netif_tx_start_all_queues(dev);
err = airoha_set_vip_for_gdm_port(port, true);
if (err)
@@ -1665,6 +1682,11 @@ static int airoha_dev_stop(struct net_device *dev)
}
}
+ if (airhoa_is_phy_external(port)) {
+ phylink_stop(port->phylink);
+ phylink_disconnect_phy(port->phylink);
+ }
+
return 0;
}
@@ -2795,6 +2817,110 @@ bool airoha_is_valid_gdm_port(struct airoha_eth *eth,
return false;
}
+static void airoha_mac_link_up(struct phylink_config *config, struct phy_device *phy,
+ unsigned int mode, phy_interface_t interface,
+ int speed, int duplex, bool tx_pause, bool rx_pause)
+{
+ struct airoha_gdm_port *port = container_of(config, struct airoha_gdm_port,
+ phylink_config);
+ struct airoha_qdma *qdma = port->qdma;
+ struct airoha_eth *eth = qdma->eth;
+ u32 frag_size_tx, frag_size_rx;
+
+ switch (speed) {
+ case SPEED_10000:
+ case SPEED_5000:
+ frag_size_tx = 8;
+ frag_size_rx = 8;
+ break;
+ case SPEED_2500:
+ frag_size_tx = 2;
+ frag_size_rx = 1;
+ break;
+ default:
+ frag_size_tx = 1;
+ frag_size_rx = 0;
+ }
+
+ /* Configure TX/RX frag based on speed */
+ if (port->id == 4) {
+ airoha_fe_rmw(eth, REG_GDMA4_TMBI_FRAG, GDMA4_SGMII0_TX_FRAG_SIZE,
+ FIELD_PREP(GDMA4_SGMII0_TX_FRAG_SIZE, frag_size_tx));
+
+ airoha_fe_rmw(eth, REG_GDMA4_RMBI_FRAG, GDMA4_SGMII0_RX_FRAG_SIZE,
+ FIELD_PREP(GDMA4_SGMII0_RX_FRAG_SIZE, frag_size_rx));
+ }
+}
+
+static const struct phylink_mac_ops airoha_phylink_ops = {
+ .mac_link_up = airoha_mac_link_up,
+};
+
+static int airoha_setup_phylink(struct net_device *dev)
+{
+ struct airoha_gdm_port *port = netdev_priv(dev);
+ struct device_node *np = dev->dev.of_node;
+ struct phylink_pcs **available_pcs;
+ phy_interface_t phy_mode;
+ struct phylink *phylink;
+ unsigned int num_pcs;
+ int err;
+
+ err = of_get_phy_mode(np, &phy_mode);
+ if (err) {
+ dev_err(&dev->dev, "incorrect phy-mode\n");
+ return err;
+ }
+
+ port->phylink_config.dev = &dev->dev;
+ port->phylink_config.type = PHYLINK_NETDEV;
+ port->phylink_config.mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
+ MAC_10 | MAC_100 | MAC_1000 | MAC_2500FD |
+ MAC_5000FD | MAC_10000FD;
+
+ err = fwnode_phylink_pcs_parse(dev_fwnode(&dev->dev), NULL, &num_pcs);
+ if (err)
+ return err;
+
+ available_pcs = kcalloc(num_pcs, sizeof(*available_pcs), GFP_KERNEL);
+ if (!available_pcs)
+ return -ENOMEM;
+
+ err = fwnode_phylink_pcs_parse(dev_fwnode(&dev->dev), available_pcs,
+ &num_pcs);
+ if (err)
+ goto out;
+
+ port->phylink_config.available_pcs = available_pcs;
+ port->phylink_config.num_available_pcs = num_pcs;
+
+ __set_bit(PHY_INTERFACE_MODE_SGMII,
+ port->phylink_config.supported_interfaces);
+ __set_bit(PHY_INTERFACE_MODE_1000BASEX,
+ port->phylink_config.supported_interfaces);
+ __set_bit(PHY_INTERFACE_MODE_2500BASEX,
+ port->phylink_config.supported_interfaces);
+ __set_bit(PHY_INTERFACE_MODE_USXGMII,
+ port->phylink_config.supported_interfaces);
+
+ phy_interface_copy(port->phylink_config.pcs_interfaces,
+ port->phylink_config.supported_interfaces);
+
+ phylink = phylink_create(&port->phylink_config,
+ of_fwnode_handle(np),
+ phy_mode, &airoha_phylink_ops);
+ if (IS_ERR(phylink)) {
+ err = PTR_ERR(phylink);
+ goto out;
+ }
+
+ port->phylink = phylink;
+out:
+ kfree(available_pcs);
+
+ return err;
+}
+
static int airoha_alloc_gdm_port(struct airoha_eth *eth,
struct device_node *np, int index)
{
@@ -2873,6 +2999,12 @@ static int airoha_alloc_gdm_port(struct airoha_eth *eth,
if (err)
return err;
+ if (airhoa_is_phy_external(port)) {
+ err = airoha_setup_phylink(dev);
+ if (err)
+ return err;
+ }
+
return register_netdev(dev);
}
@@ -2967,6 +3099,9 @@ static int airoha_probe(struct platform_device *pdev)
struct airoha_gdm_port *port = eth->ports[i];
if (port && port->dev->reg_state == NETREG_REGISTERED) {
+ if (airhoa_is_phy_external(port))
+ phylink_destroy(port->phylink);
+
unregister_netdev(port->dev);
airoha_metadata_dst_free(port);
}
@@ -2994,6 +3129,9 @@ static void airoha_remove(struct platform_device *pdev)
continue;
airoha_dev_stop(port->dev);
+ if (airhoa_is_phy_external(port))
+ phylink_destroy(port->phylink);
+
unregister_netdev(port->dev);
airoha_metadata_dst_free(port);
}
diff --git a/drivers/net/ethernet/airoha/airoha_eth.h b/drivers/net/ethernet/airoha/airoha_eth.h
index 53f39083a8b0..73a500474076 100644
--- a/drivers/net/ethernet/airoha/airoha_eth.h
+++ b/drivers/net/ethernet/airoha/airoha_eth.h
@@ -498,6 +498,9 @@ struct airoha_gdm_port {
struct net_device *dev;
int id;
+ struct phylink *phylink;
+ struct phylink_config phylink_config;
+
struct airoha_hw_stats stats;
DECLARE_BITMAP(qos_sq_bmap, AIROHA_NUM_QOS_CHANNELS);
diff --git a/drivers/net/ethernet/airoha/airoha_regs.h b/drivers/net/ethernet/airoha/airoha_regs.h
index d931530fc96f..71c63108f0a8 100644
--- a/drivers/net/ethernet/airoha/airoha_regs.h
+++ b/drivers/net/ethernet/airoha/airoha_regs.h
@@ -357,6 +357,18 @@
#define IP_FRAGMENT_PORT_MASK GENMASK(8, 5)
#define IP_FRAGMENT_NBQ_MASK GENMASK(4, 0)
+#define REG_GDMA4_TMBI_FRAG 0x2028
+#define GDMA4_SGMII1_TX_WEIGHT GENMASK(31, 26)
+#define GDMA4_SGMII1_TX_FRAG_SIZE GENMASK(25, 16)
+#define GDMA4_SGMII0_TX_WEIGHT GENMASK(15, 10)
+#define GDMA4_SGMII0_TX_FRAG_SIZE GENMASK(9, 0)
+
+#define REG_GDMA4_RMBI_FRAG 0x202c
+#define GDMA4_SGMII1_RX_WEIGHT GENMASK(31, 26)
+#define GDMA4_SGMII1_RX_FRAG_SIZE GENMASK(25, 16)
+#define GDMA4_SGMII0_RX_WEIGHT GENMASK(15, 10)
+#define GDMA4_SGMII0_RX_FRAG_SIZE GENMASK(9, 0)
+
#define REG_MC_VLAN_EN 0x2100
#define MC_VLAN_EN_MASK BIT(0)
--
2.48.1
Hi Christian,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Christian-Marangi/net-phylink-keep-and-use-MAC-supported_interfaces-in-phylink-struct/20250510-182833
base: net-next/main
patch link: https://lore.kernel.org/r/20250510102348.14134-12-ansuelsmth%40gmail.com
patch subject: [net-next PATCH v3 11/11] net: airoha: add phylink support for GDM2/3/4
config: sh-randconfig-002-20250510 (https://download.01.org/0day-ci/archive/20250511/202505110156.WGym4cxS-lkp@intel.com/config)
compiler: sh4-linux-gcc (GCC) 11.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250511/202505110156.WGym4cxS-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202505110156.WGym4cxS-lkp@intel.com/
All warnings (new ones prefixed by >>):
In file included from drivers/net/ethernet/airoha/airoha_eth.c:10:
>> include/linux/pcs/pcs.h:90:1: warning: 'fwnode_phylink_pcs_get_from_fwnode' defined but not used [-Wunused-function]
90 | fwnode_phylink_pcs_get_from_fwnode(struct fwnode_handle *fwnode,
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>> include/linux/pcs/pcs.h:78:12: warning: 'register_fwnode_pcs_notifier' defined but not used [-Wunused-function]
78 | static int register_fwnode_pcs_notifier(struct notifier_block *nb)
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
vim +/fwnode_phylink_pcs_get_from_fwnode +90 include/linux/pcs/pcs.h
91110a42083f1a Christian Marangi 2025-05-10 24
90fbe52edd2a1f Christian Marangi 2025-05-10 25 /**
90fbe52edd2a1f Christian Marangi 2025-05-10 26 * fwnode_pcs_get - Retrieves a PCS from a firmware node
90fbe52edd2a1f Christian Marangi 2025-05-10 27 * @fwnode: firmware node
90fbe52edd2a1f Christian Marangi 2025-05-10 28 * @index: index fwnode PCS handle in firmware node
90fbe52edd2a1f Christian Marangi 2025-05-10 29 *
90fbe52edd2a1f Christian Marangi 2025-05-10 30 * Get a PCS from the firmware node at index.
90fbe52edd2a1f Christian Marangi 2025-05-10 31 *
90fbe52edd2a1f Christian Marangi 2025-05-10 32 * Returns a pointer to the phylink_pcs or a negative
90fbe52edd2a1f Christian Marangi 2025-05-10 33 * error pointer. Can return -EPROBE_DEFER if the PCS is not
90fbe52edd2a1f Christian Marangi 2025-05-10 34 * present in global providers list (either due to driver
90fbe52edd2a1f Christian Marangi 2025-05-10 35 * still needs to be probed or it failed to probe/removed)
90fbe52edd2a1f Christian Marangi 2025-05-10 36 */
90fbe52edd2a1f Christian Marangi 2025-05-10 37 struct phylink_pcs *fwnode_pcs_get(struct fwnode_handle *fwnode,
90fbe52edd2a1f Christian Marangi 2025-05-10 38 int index);
90fbe52edd2a1f Christian Marangi 2025-05-10 39
91110a42083f1a Christian Marangi 2025-05-10 40 /**
91110a42083f1a Christian Marangi 2025-05-10 41 * fwnode_phylink_pcs_get_from_fwnode - Retrieves the PCS provided
91110a42083f1a Christian Marangi 2025-05-10 42 * by the firmware node from a
91110a42083f1a Christian Marangi 2025-05-10 43 * firmware node
91110a42083f1a Christian Marangi 2025-05-10 44 * @fwnode: firmware node
91110a42083f1a Christian Marangi 2025-05-10 45 * @pcs_fwnode: PCS firmware node
91110a42083f1a Christian Marangi 2025-05-10 46 *
91110a42083f1a Christian Marangi 2025-05-10 47 * Parse 'pcs-handle' in 'fwnode' and get the PCS that match
91110a42083f1a Christian Marangi 2025-05-10 48 * 'pcs_fwnode' firmware node.
91110a42083f1a Christian Marangi 2025-05-10 49 *
91110a42083f1a Christian Marangi 2025-05-10 50 * Returns a pointer to the phylink_pcs or a negative
91110a42083f1a Christian Marangi 2025-05-10 51 * error pointer. Can return -EPROBE_DEFER if the PCS is not
91110a42083f1a Christian Marangi 2025-05-10 52 * present in global providers list (either due to driver
91110a42083f1a Christian Marangi 2025-05-10 53 * still needs to be probed or it failed to probe/removed)
91110a42083f1a Christian Marangi 2025-05-10 54 */
91110a42083f1a Christian Marangi 2025-05-10 55 struct phylink_pcs *
91110a42083f1a Christian Marangi 2025-05-10 56 fwnode_phylink_pcs_get_from_fwnode(struct fwnode_handle *fwnode,
91110a42083f1a Christian Marangi 2025-05-10 57 struct fwnode_handle *pcs_fwnode);
91110a42083f1a Christian Marangi 2025-05-10 58
90fbe52edd2a1f Christian Marangi 2025-05-10 59 /**
90fbe52edd2a1f Christian Marangi 2025-05-10 60 * fwnode_phylink_pcs_parse - generic PCS parse for fwnode PCS provider
90fbe52edd2a1f Christian Marangi 2025-05-10 61 * @fwnode: firmware node
90fbe52edd2a1f Christian Marangi 2025-05-10 62 * @available_pcs: pointer to preallocated array of PCS
90fbe52edd2a1f Christian Marangi 2025-05-10 63 * @num_pcs: where to store count of parsed PCS
90fbe52edd2a1f Christian Marangi 2025-05-10 64 *
90fbe52edd2a1f Christian Marangi 2025-05-10 65 * Generic helper function to fill available_pcs array with PCS parsed
90fbe52edd2a1f Christian Marangi 2025-05-10 66 * from a "pcs-handle" fwnode property defined in firmware node up to
90fbe52edd2a1f Christian Marangi 2025-05-10 67 * passed num_pcs.
90fbe52edd2a1f Christian Marangi 2025-05-10 68 *
90fbe52edd2a1f Christian Marangi 2025-05-10 69 * If available_pcs is NULL, num_pcs is updated with the count of the
90fbe52edd2a1f Christian Marangi 2025-05-10 70 * parsed PCS.
90fbe52edd2a1f Christian Marangi 2025-05-10 71 *
90fbe52edd2a1f Christian Marangi 2025-05-10 72 * Returns 0 or a negative error.
90fbe52edd2a1f Christian Marangi 2025-05-10 73 */
90fbe52edd2a1f Christian Marangi 2025-05-10 74 int fwnode_phylink_pcs_parse(struct fwnode_handle *fwnode,
90fbe52edd2a1f Christian Marangi 2025-05-10 75 struct phylink_pcs **available_pcs,
90fbe52edd2a1f Christian Marangi 2025-05-10 76 unsigned int *num_pcs);
90fbe52edd2a1f Christian Marangi 2025-05-10 77 #else
91110a42083f1a Christian Marangi 2025-05-10 @78 static int register_fwnode_pcs_notifier(struct notifier_block *nb)
91110a42083f1a Christian Marangi 2025-05-10 79 {
91110a42083f1a Christian Marangi 2025-05-10 80 return -EOPNOTSUPP;
91110a42083f1a Christian Marangi 2025-05-10 81 }
91110a42083f1a Christian Marangi 2025-05-10 82
90fbe52edd2a1f Christian Marangi 2025-05-10 83 static inline struct phylink_pcs *fwnode_pcs_get(struct fwnode_handle *fwnode,
90fbe52edd2a1f Christian Marangi 2025-05-10 84 int index)
90fbe52edd2a1f Christian Marangi 2025-05-10 85 {
90fbe52edd2a1f Christian Marangi 2025-05-10 86 return ERR_PTR(-ENOENT);
90fbe52edd2a1f Christian Marangi 2025-05-10 87 }
90fbe52edd2a1f Christian Marangi 2025-05-10 88
91110a42083f1a Christian Marangi 2025-05-10 89 static struct phylink_pcs *
91110a42083f1a Christian Marangi 2025-05-10 @90 fwnode_phylink_pcs_get_from_fwnode(struct fwnode_handle *fwnode,
91110a42083f1a Christian Marangi 2025-05-10 91 struct fwnode_handle *pcs_fwnode)
91110a42083f1a Christian Marangi 2025-05-10 92 {
91110a42083f1a Christian Marangi 2025-05-10 93 return ERR_PTR(-ENOENT);
91110a42083f1a Christian Marangi 2025-05-10 94 }
91110a42083f1a Christian Marangi 2025-05-10 95
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
> Add phylink support for GDM2/3/4 port that require configuration of the
> PCS to make the external PHY or attached SFP cage work.
>
> These needs to be defined in the GDM port node using the pcs-handle
> property.
Hi Christian,
thx for the patch. Some comments inline.
Regards,
Lorenzo
>
> Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
> ---
> drivers/net/ethernet/airoha/airoha_eth.c | 138 ++++++++++++++++++++++
> drivers/net/ethernet/airoha/airoha_eth.h | 3 +
> drivers/net/ethernet/airoha/airoha_regs.h | 12 ++
> 3 files changed, 153 insertions(+)
>
> diff --git a/drivers/net/ethernet/airoha/airoha_eth.c b/drivers/net/ethernet/airoha/airoha_eth.c
> index 16c7896f931f..17521be820b5 100644
> --- a/drivers/net/ethernet/airoha/airoha_eth.c
> +++ b/drivers/net/ethernet/airoha/airoha_eth.c
> @@ -7,6 +7,7 @@
> #include <linux/of_net.h>
> #include <linux/platform_device.h>
> #include <linux/tcp.h>
> +#include <linux/pcs/pcs.h>
> #include <linux/u64_stats_sync.h>
> #include <net/dst_metadata.h>
> #include <net/page_pool/helpers.h>
> @@ -79,6 +80,11 @@ static bool airhoa_is_lan_gdm_port(struct airoha_gdm_port *port)
> return port->id == 1;
> }
>
> +static bool airhoa_is_phy_external(struct airoha_gdm_port *port)
> +{
> + return port->id != 1;
> +}
> +
> static void airoha_set_macaddr(struct airoha_gdm_port *port, const u8 *addr)
> {
> struct airoha_eth *eth = port->qdma->eth;
> @@ -1613,6 +1619,17 @@ static int airoha_dev_open(struct net_device *dev)
> struct airoha_gdm_port *port = netdev_priv(dev);
> struct airoha_qdma *qdma = port->qdma;
>
> + if (airhoa_is_phy_external(port)) {
> + err = phylink_of_phy_connect(port->phylink, dev->dev.of_node, 0);
> + if (err) {
> + netdev_err(dev, "%s: could not attach PHY: %d\n", __func__,
> + err);
> + return err;
> + }
> +
> + phylink_start(port->phylink);
> + }
> +
> netif_tx_start_all_queues(dev);
> err = airoha_set_vip_for_gdm_port(port, true);
> if (err)
> @@ -1665,6 +1682,11 @@ static int airoha_dev_stop(struct net_device *dev)
> }
> }
>
> + if (airhoa_is_phy_external(port)) {
> + phylink_stop(port->phylink);
> + phylink_disconnect_phy(port->phylink);
> + }
> +
> return 0;
> }
>
> @@ -2795,6 +2817,110 @@ bool airoha_is_valid_gdm_port(struct airoha_eth *eth,
> return false;
> }
>
> +static void airoha_mac_link_up(struct phylink_config *config, struct phy_device *phy,
> + unsigned int mode, phy_interface_t interface,
> + int speed, int duplex, bool tx_pause, bool rx_pause)
> +{
> + struct airoha_gdm_port *port = container_of(config, struct airoha_gdm_port,
> + phylink_config);
> + struct airoha_qdma *qdma = port->qdma;
> + struct airoha_eth *eth = qdma->eth;
> + u32 frag_size_tx, frag_size_rx;
I guess we can just return here if port->id != 4 and avoid setting
frag_size_tx/frag_size_rx
> +
> + switch (speed) {
> + case SPEED_10000:
> + case SPEED_5000:
> + frag_size_tx = 8;
> + frag_size_rx = 8;
> + break;
> + case SPEED_2500:
> + frag_size_tx = 2;
> + frag_size_rx = 1;
> + break;
> + default:
> + frag_size_tx = 1;
> + frag_size_rx = 0;
> + }
> +
> + /* Configure TX/RX frag based on speed */
> + if (port->id == 4) {
> + airoha_fe_rmw(eth, REG_GDMA4_TMBI_FRAG, GDMA4_SGMII0_TX_FRAG_SIZE,
> + FIELD_PREP(GDMA4_SGMII0_TX_FRAG_SIZE, frag_size_tx));
> +
> + airoha_fe_rmw(eth, REG_GDMA4_RMBI_FRAG, GDMA4_SGMII0_RX_FRAG_SIZE,
> + FIELD_PREP(GDMA4_SGMII0_RX_FRAG_SIZE, frag_size_rx));
> + }
> +}
> +
> +static const struct phylink_mac_ops airoha_phylink_ops = {
> + .mac_link_up = airoha_mac_link_up,
> +};
> +
> +static int airoha_setup_phylink(struct net_device *dev)
> +{
> + struct airoha_gdm_port *port = netdev_priv(dev);
> + struct device_node *np = dev->dev.of_node;
> + struct phylink_pcs **available_pcs;
> + phy_interface_t phy_mode;
> + struct phylink *phylink;
> + unsigned int num_pcs;
> + int err;
> +
> + err = of_get_phy_mode(np, &phy_mode);
> + if (err) {
> + dev_err(&dev->dev, "incorrect phy-mode\n");
> + return err;
> + }
> +
> + port->phylink_config.dev = &dev->dev;
> + port->phylink_config.type = PHYLINK_NETDEV;
> + port->phylink_config.mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
> + MAC_10 | MAC_100 | MAC_1000 | MAC_2500FD |
> + MAC_5000FD | MAC_10000FD;
> +
> + err = fwnode_phylink_pcs_parse(dev_fwnode(&dev->dev), NULL, &num_pcs);
> + if (err)
> + return err;
> +
> + available_pcs = kcalloc(num_pcs, sizeof(*available_pcs), GFP_KERNEL);
> + if (!available_pcs)
> + return -ENOMEM;
since airoha_setup_phylink() is just run in the following path:
airoha_probe() -> airoha_alloc_gdm_port()
we can use devm_kcalloc() and get rid of the kfree and the end of the routine.
> +
> + err = fwnode_phylink_pcs_parse(dev_fwnode(&dev->dev), available_pcs,
> + &num_pcs);
> + if (err)
> + goto out;
> +
> + port->phylink_config.available_pcs = available_pcs;
> + port->phylink_config.num_available_pcs = num_pcs;
> +
> + __set_bit(PHY_INTERFACE_MODE_SGMII,
> + port->phylink_config.supported_interfaces);
> + __set_bit(PHY_INTERFACE_MODE_1000BASEX,
> + port->phylink_config.supported_interfaces);
> + __set_bit(PHY_INTERFACE_MODE_2500BASEX,
> + port->phylink_config.supported_interfaces);
> + __set_bit(PHY_INTERFACE_MODE_USXGMII,
> + port->phylink_config.supported_interfaces);
> +
> + phy_interface_copy(port->phylink_config.pcs_interfaces,
> + port->phylink_config.supported_interfaces);
> +
> + phylink = phylink_create(&port->phylink_config,
> + of_fwnode_handle(np),
> + phy_mode, &airoha_phylink_ops);
> + if (IS_ERR(phylink)) {
> + err = PTR_ERR(phylink);
> + goto out;
> + }
> +
> + port->phylink = phylink;
> +out:
> + kfree(available_pcs);
> +
> + return err;
> +}
> +
> static int airoha_alloc_gdm_port(struct airoha_eth *eth,
> struct device_node *np, int index)
> {
> @@ -2873,6 +2999,12 @@ static int airoha_alloc_gdm_port(struct airoha_eth *eth,
> if (err)
> return err;
>
> + if (airhoa_is_phy_external(port)) {
> + err = airoha_setup_phylink(dev);
> + if (err)
> + return err;
> + }
> +
> return register_netdev(dev);
we should run phylink_destroy() if register_netdev() fails. Please take a
look to:
https://lore.kernel.org/netdev/aB8MPkMYXWvoaA03@lore-desk/T/#m0a036b0759384a38d2518025db46306858b5707b
> }
>
> @@ -2967,6 +3099,9 @@ static int airoha_probe(struct platform_device *pdev)
> struct airoha_gdm_port *port = eth->ports[i];
>
> if (port && port->dev->reg_state == NETREG_REGISTERED) {
> + if (airhoa_is_phy_external(port))
> + phylink_destroy(port->phylink);
> +
> unregister_netdev(port->dev);
> airoha_metadata_dst_free(port);
> }
> @@ -2994,6 +3129,9 @@ static void airoha_remove(struct platform_device *pdev)
> continue;
>
> airoha_dev_stop(port->dev);
> + if (airhoa_is_phy_external(port))
> + phylink_destroy(port->phylink);
> +
> unregister_netdev(port->dev);
> airoha_metadata_dst_free(port);
> }
> diff --git a/drivers/net/ethernet/airoha/airoha_eth.h b/drivers/net/ethernet/airoha/airoha_eth.h
> index 53f39083a8b0..73a500474076 100644
> --- a/drivers/net/ethernet/airoha/airoha_eth.h
> +++ b/drivers/net/ethernet/airoha/airoha_eth.h
> @@ -498,6 +498,9 @@ struct airoha_gdm_port {
> struct net_device *dev;
> int id;
>
> + struct phylink *phylink;
> + struct phylink_config phylink_config;
> +
> struct airoha_hw_stats stats;
>
> DECLARE_BITMAP(qos_sq_bmap, AIROHA_NUM_QOS_CHANNELS);
> diff --git a/drivers/net/ethernet/airoha/airoha_regs.h b/drivers/net/ethernet/airoha/airoha_regs.h
> index d931530fc96f..71c63108f0a8 100644
> --- a/drivers/net/ethernet/airoha/airoha_regs.h
> +++ b/drivers/net/ethernet/airoha/airoha_regs.h
> @@ -357,6 +357,18 @@
> #define IP_FRAGMENT_PORT_MASK GENMASK(8, 5)
> #define IP_FRAGMENT_NBQ_MASK GENMASK(4, 0)
>
> +#define REG_GDMA4_TMBI_FRAG 0x2028
> +#define GDMA4_SGMII1_TX_WEIGHT GENMASK(31, 26)
> +#define GDMA4_SGMII1_TX_FRAG_SIZE GENMASK(25, 16)
> +#define GDMA4_SGMII0_TX_WEIGHT GENMASK(15, 10)
> +#define GDMA4_SGMII0_TX_FRAG_SIZE GENMASK(9, 0)
in order to be consistent with the codebase, can you please add _MASK suffix
here?
> +
> +#define REG_GDMA4_RMBI_FRAG 0x202c
> +#define GDMA4_SGMII1_RX_WEIGHT GENMASK(31, 26)
> +#define GDMA4_SGMII1_RX_FRAG_SIZE GENMASK(25, 16)
> +#define GDMA4_SGMII0_RX_WEIGHT GENMASK(15, 10)
> +#define GDMA4_SGMII0_RX_FRAG_SIZE GENMASK(9, 0)
> +
> #define REG_MC_VLAN_EN 0x2100
> #define MC_VLAN_EN_MASK BIT(0)
>
> --
> 2.48.1
>
© 2016 - 2026 Red Hat, Inc.