From: "Yajun Deng" <yajun.deng@linux.dev>
To: "Andrew Lunn" <andrew@lunn.ch>
Cc: hkallweit1@gmail.com, linux@armlinux.org.uk, davem@davemloft.net,
edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH RESEND net-next v2] net: phy: Add c45_phy_ids sysfs directory entry
Date: Fri, 13 Jun 2025 02:06:45 +0000 [thread overview]
Message-ID: <2d5322bce3f450da329e5e146bf0a850afa55fe4@linux.dev> (raw)
In-Reply-To: <737294c1-258f-4780-80f8-e7a72e887f8b@lunn.ch>
June 12, 2025 at 11:31 PM, "Andrew Lunn" <andrew@lunn.ch> wrote:
>
> >
> > +#define MMD_INDICES \
> >
> > + _(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)
> >
>
> Is 0 not valid?
>
Yes, the MMD starts at 1. See "include/uapi/linux/mdio.h".
> >
> > +#define MMD_DEVICE_ID_ATTR(n) \
> >
> > +static ssize_t mmd##n##_device_id_show(struct device *dev, \
> >
> > + struct device_attribute *attr, char *buf) \
> >
> > +{ \
> >
> > + struct phy_device *phydev = to_phy_device(dev); \
> >
> > + return sysfs_emit(buf, "0x%.8lx\n", \
> >
> > + (unsigned long)phydev->c45_ids.device_ids[n]); \
> >
> > +} \
> >
> > +static DEVICE_ATTR_RO(mmd##n##_device_id)
> >
>
> This macro magic i can follow, you see this quite a bit in the kernel.
>
Okay.
> >
> > +
> >
> > +#define _(x) MMD_DEVICE_ID_ATTR(x);
> >
> > +MMD_INDICES
> >
> > +#undef _
> >
> > +
> >
> > +static struct attribute *phy_mmd_attrs[] = {
> >
> > + #define _(x) &dev_attr_mmd##x##_device_id.attr,
> >
> > + MMD_INDICES
> >
> > + #undef _
> >
> > + NULL
> >
> > +};
> >
>
> If i squint at this enough, i can work it out, but generally a much
>
> more readable KISS approach is taken, of just invoking a macro 32
>
> times. See mdio_bus.c as an example.
>
Okay.
> Andrew
>
> ---
>
> pw-bot: cr
>
prev parent reply other threads:[~2025-06-13 2:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-12 14:35 [PATCH RESEND net-next v2] net: phy: Add c45_phy_ids sysfs directory entry Yajun Deng
2025-06-12 15:31 ` Andrew Lunn
2025-06-13 2:06 ` Yajun Deng [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2d5322bce3f450da329e5e146bf0a850afa55fe4@linux.dev \
--to=yajun.deng@linux.dev \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.