[PATCH v2 net-next 05/10] phy: add phy_get_rx_polarity() and phy_get_tx_polarity()
Vladimir Oltean
vladimir.oltean at nxp.com
Sat Jan 10 10:04:33 PST 2026
Hi Bjørn,
On Wed, Jan 07, 2026 at 09:12:28AM +0100, Bjørn Mork wrote:
> Vladimir Oltean <vladimir.oltean at nxp.com> writes:
>
> > +static int fwnode_get_u32_prop_for_name(struct fwnode_handle *fwnode,
> > + const char *name,
> > + const char *props_title,
> > + const char *names_title,
> > + unsigned int default_val,
> > + unsigned int *val)
> > +{
> > + int err, n_props, n_names, idx = -1;
> > + u32 *props;
> > +
> > + if (!name) {
> > + pr_err("Lookup key inside \"%s\" is mandatory\n", names_title);
> > + return -EINVAL;
> > + }
> > +
> > + if (!fwnode) {
> > + *val = default_val;
> > + return 0;
> > + }
> > +
> > + err = fwnode_property_count_u32(fwnode, props_title);
> > + if (err < 0)
> > + return err;
> > + if (err == 0) {
> > + *val = default_val;
> > + return 0;
> > + }
> > + n_props = err;
>
> I tried using this in the air_en8811h driver and started wondering if I
> have misunderstood something.
>
> The problem I have is that fwnode_property_count_u32() returns -EINVAL
> if props_title is missing. So if you have a node with the legacy
> "airoha,pnswap-rx" property instead of "rx-polarity", or more common: no
> polariy property at all, then we see -EINVAL returned from
> phy_get_rx_polarity(). Which is propagated back to config_init() and
> the phy fails to attach. That can't be the intention?
>
> The behaviour I expected is described by this test:
>
>
> /* Test: tx-polarity property is missing */
> static void phy_test_tx_polarity_is_missing(struct kunit *test)
> {
> static const struct property_entry entries[] = {
> {}
> };
> struct fwnode_handle *node;
> unsigned int val;
> int ret;
>
> node = fwnode_create_software_node(entries, NULL);
> KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
>
> ret = phy_get_manual_tx_polarity(node, "sgmi", &val);
> KUNIT_EXPECT_EQ(test, ret, 0);
> KUNIT_EXPECT_EQ(test, val, PHY_POL_NORMAL);
>
> fwnode_remove_software_node(node);
> }
Thanks for debugging and for the test! This is a regression from v1,
where I just checked the fwnode_property_count_u32() return code for
being <= 0.
I've integrated your test and added one more for RX. Do you have any
further comments, or shall I send an updated v3?
More information about the linux-phy
mailing list