Linux PCI Non-Transparent Bridge framework and drivers
 help / color / mirror / Atom feed
From: "Allen Hubbe" <Allen.Hubbe@emc.com>
To: 'Jon Mason' <jdmason@kudzu.us>,
	"'Yu, Xiangliang'" <Xiangliang.Yu@amd.com>
Cc: 'Dave Jiang' <dave.jiang@intel.com>,
	linux-ntb@googlegroups.com,
	'linux-kernel' <linux-kernel@vger.kernel.org>,
	'SPG_Linux_Kernel' <SPG_Linux_Kernel@amd.com>
Subject: RE: [PATCH V2 1/3] NTB: Add AMD PCI-Express NTB driver
Date: Fri, 8 Jan 2016 10:39:24 -0500	[thread overview]
Message-ID: <000d01d14a2a$c0879d50$4196d7f0$@emc.com> (raw)
In-Reply-To: <CAPoiz9zqbgTvTA7hgKEQQGAuCbodH3D3dwmvNwkzRQPM1GA=aw@mail.gmail.com>

From: Jon Mason <jdmason@kudzu.us>
> On Wed, Jan 6, 2016 at 9:50 PM, Yu, Xiangliang <Xiangliang.Yu@amd.com>
> wrote:
> >> > +#define NTB_READ_REG(base, r) (ioread32(base + AMD_ ## r ##
> >> _OFFSET))
> >> > +#define NTB_WRITE_REG(base, val, r) (iowrite32(val, base +     \
> >> > +                                               AMD_ ## r ##
> _OFFSET))
> >> > +#define NTB_READ_OFFSET(base, r, of) (ioread32(base + of +
> \
> >> > +                                               AMD_ ## r ##
> _OFFSET))
> >> > +#define NTB_WRITE_OFFSET(base, val, r, of) (iowrite32(val, base +
> \
> >> > +                                               of + AMD_ ## r ##
> _OFFSET))
> >>
> >> Please do not use marcos to hide ioread/iowrite.  Call iorwad/iowrite
> directly.
> >
> > I don't see any wrong to hide ioread/iowrite, and I think the macros
> can make code readable and easy to maintain.
> 
> I disagree.  It is an unnecessary layer and can add to confusion.
> Please make the change.

I don't like AMD_##r##_OFFSET in these macros.  It hides the use of a globally named constant like AMD_FOO_OFFSET, since one would read only FOO in the code.  It makes cross referencing difficult, since the reader needs to know FOO is really AMD_FOO_OFFSET.  This would defeat automatic cross referencing like cscope and lxr.

#define AMD_FOO_OFFSET 0xc0ff33
vs
NTB_READ_OFFSET(dev->foo_base, FOO, offset_in_foo)
// Where is FOO defined?

This macro would have at least been better written without ##; so cross referencing would still work.

NTB_READ_OFFSET(dev->foo_base, FOO, offset_in_foo)
vs
NTB_READ_OFFSET(dev->foo_base, AMD_FOO_OFFSET, offset_in_foo)
// AMD_FOO_OFFSET is 0xcoff33 (obviously)

But without ##, the macro is just the addition of its parameters.  Change the commas to addition, and the macro to ioread, and you'll see there is no benefit for having this macro any more.

NTB_READ_OFFSET(dev->foo_base, AMD_FOO_OFFSET, offset_in_foo)
vs
ioread32(dev->foo_base + AMD_FOO_OFFSET + offset_in_foo)

I second Jon's opinion.  Please make the change.  This would be better as simply ioread/write in the code.

Allen


  reply	other threads:[~2016-01-08 15:39 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-23 13:42 [PATCH V2 1/3] NTB: Add AMD PCI-Express NTB driver Xiangliang Yu
2015-12-23  9:29 ` Christoph Hellwig
2015-12-23 15:09   ` Allen Hubbe
2015-12-23 15:51     ` Raghu
2016-01-06 15:05 ` Jon Mason
2016-01-06 16:52   ` Hubbe, Allen
2016-01-06 17:48     ` Jon Mason
2016-01-07  2:53       ` Yu, Xiangliang
2016-01-07  2:50   ` Yu, Xiangliang
2016-01-08 15:01     ` Jon Mason
2016-01-08 15:39       ` Allen Hubbe [this message]
2016-01-11  7:07         ` Yu, Xiangliang
2016-01-08  3:14   ` Yu, Xiangliang

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='000d01d14a2a$c0879d50$4196d7f0$@emc.com' \
    --to=allen.hubbe@emc.com \
    --cc=SPG_Linux_Kernel@amd.com \
    --cc=Xiangliang.Yu@amd.com \
    --cc=dave.jiang@intel.com \
    --cc=jdmason@kudzu.us \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-ntb@googlegroups.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox