All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bin Meng <bmeng.cn@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RESEND PATCHv4 9/9] dm: pci: add APIs for MPS and MRRS accessors
Date: Mon, 1 Apr 2019 15:31:43 +0800	[thread overview]
Message-ID: <CAEUhbmVkutWB6T8RNyzarQtX=hg2Kn9SJGp-JtT1sz=G9S_ydQ@mail.gmail.com> (raw)
In-Reply-To: <CAEUhbmX8wwcMkwv85XeDubvWaFPNSJWtMjsYn_RTPd48JcoXWg@mail.gmail.com>

On Mon, Apr 1, 2019 at 2:00 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> On Mon, Mar 25, 2019 at 10:24 AM Z.q. Hou <zhiqiang.hou@nxp.com> wrote:
> >
> > From: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
> >
> > This patch introduce APIs for getting and updating the MPS
> > and MRRS fields of Device capability Device control register.
> >
> > Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
> > ---
> > V4:
> >  - New patch
> >
> >  drivers/pci/pci-uclass.c | 92 ++++++++++++++++++++++++++++++++++++++++
> >  include/pci.h            | 13 ++++++
> >  2 files changed, 105 insertions(+)
> >
> > diff --git a/drivers/pci/pci-uclass.c b/drivers/pci/pci-uclass.c
> > index 4bb30f5d2b..b2d295435a 100644
> > --- a/drivers/pci/pci-uclass.c
> > +++ b/drivers/pci/pci-uclass.c
> > @@ -7,6 +7,7 @@
> >  #include <common.h>
> >  #include <dm.h>
> >  #include <errno.h>
> > +#include <linux/log2.h>
> >  #include <pci.h>
> >  #include <asm/io.h>
> >  #include <dm/device-internal.h>
> > @@ -1596,6 +1597,97 @@ int dm_pci_capability_clear_and_set_dword(struct udevice *dev, int cap,
> >                                                set, PCI_SIZE_32);
> >  }
> >
> > +/**
> > + * dm_pci_get_readrq - get PCI Express read request size
> > + * @dev: PCI device to query
> > + *
> > + * Returns maximum memory read request in bytes
> > + *    or appropriate error value.
> > + */
>
> Please move the comment block to pci.h
>
> > +int dm_pci_get_readrq(struct udevice *dev)
> > +{
> > +       u16 ctl;
> > +       int ret;
> > +
> > +       ret = dm_pci_capability_read_word(dev, PCI_CAP_ID_EXP,
> > +                                         PCI_EXP_DEVCTL, &ctl);
> > +       if (ret)
> > +               return ret;
> > +
> > +       return 128 << ((ctl & PCI_EXP_DEVCTL_READRQ) >> 12);
> > +}
> > +
> > +/**
> > + * dm_pci_set_readrq - set PCI Express maximum memory read request
> > + * @dev: PCI device to query
> > + * @rq: maximum memory read count in bytes
> > + *    valid values are 128, 256, 512, 1024, 2048, 4096
> > + */
> > +int dm_pci_set_readrq(struct udevice *dev, int rq)
> > +{
> > +       u16 val;
> > +
> > +       if (rq < 128 || rq > 4096 || !is_power_of_2(rq))
> > +               return -EINVAL;
> > +
> > +       val = (ffs(rq) - 8) << 12;
> > +
> > +       return dm_pci_capability_clear_and_set_word(dev, PCI_CAP_ID_EXP,
> > +                                                   PCI_EXP_DEVCTL,
> > +                                                   PCI_EXP_DEVCTL_READRQ,
> > +                                                   val);
> > +}
> > +
> > +/**
> > + * dm_pci_get_mps - get PCI Express maximum payload size
> > + * @dev: PCI device to query
> > + *
> > + * Returns maximum payload size in bytes
> > + */
> > +int dm_pci_get_mps(struct udevice *dev)
> > +{
> > +       u16 ctl;
> > +       int ret;
> > +
> > +       ret = dm_pci_capability_read_word(dev, PCI_CAP_ID_EXP,
> > +                                         PCI_EXP_DEVCTL, &ctl);
> > +       if (ret)
> > +               return ret;
> > +
> > +       return 128 << ((ctl & PCI_EXP_DEVCTL_PAYLOAD) >> 5);
> > +}
> > +
> > +/**
> > + * dm_pci_set_mps - set PCI Express maximum payload size
> > + * @dev: PCI device to query
> > + * @mps: maximum payload size in bytes
> > + *    valid values are 128, 256, 512, 1024, 2048, 4096
> > + */
> > +int dm_pci_set_mps(struct udevice *dev, int mps)
> > +{
> > +       u16 val, cap;
> > +       int ret;
> > +
> > +       if (mps < 128 || mps > 4096 || !is_power_of_2(mps))
> > +               return -EINVAL;
> > +
> > +       ret = dm_pci_capability_read_word(dev, PCI_CAP_ID_EXP,
> > +                                         PCI_EXP_DEVCAP, &cap);
> > +       if (ret)
> > +               return ret;
> > +
> > +       val = ffs(mps) - 8;
> > +       if (val > (cap & PCI_EXP_DEVCAP_PAYLOAD))
> > +               return -EINVAL;
> > +
> > +       val <<= 5;
> > +
> > +       return dm_pci_capability_clear_and_set_word(dev, PCI_CAP_ID_EXP,
> > +                                                   PCI_EXP_DEVCTL,
> > +                                                   PCI_EXP_DEVCTL_PAYLOAD,
> > +                                                   val);
> > +}
> > +
> >  UCLASS_DRIVER(pci) = {
> >         .id             = UCLASS_PCI,
> >         .name           = "pci",
> > diff --git a/include/pci.h b/include/pci.h
> > index d7b6d9f4ff..b48df8a363 100644
> > --- a/include/pci.h
> > +++ b/include/pci.h
> > @@ -414,6 +414,14 @@
> >  #define PCI_MAX_PCI_DEVICES    32
> >  #define PCI_MAX_PCI_FUNCTIONS  8
> >
> > +/* PCI Express capability registers */
> > +#define PCI_EXP_DEVCAP                 4       /* Device capabilities */
> > +#define  PCI_EXP_DEVCAP_PAYLOAD                0x0007  /* Max_Payload_Size */
> > +
> > +#define PCI_EXP_DEVCTL                 8       /* Device Control */
> > +#define  PCI_EXP_DEVCTL_PAYLOAD                0x00e0  /* Max_Payload_Size */
> > +#define  PCI_EXP_DEVCTL_READRQ         0x7000  /* Max_Read_Request_Size */
> > +
> >  #define PCI_FIND_CAP_TTL 0x48
> >  #define CAP_START_POS 0x40
> >
> > @@ -1425,6 +1433,11 @@ int dm_pci_capability_clear_and_set_word(struct udevice *dev, int cap,
> >  int dm_pci_capability_clear_and_set_dword(struct udevice *dev, int cap,
> >                                           int pos, u32 clear, u32 set);
> >
> > +int dm_pci_get_readrq(struct udevice *dev);
> > +int dm_pci_set_readrq(struct udevice *dev, int rq);
> > +int dm_pci_get_mps(struct udevice *dev);
> > +int dm_pci_set_mps(struct udevice *dev, int mps);
> > +
> >  #define dm_pci_virt_to_bus(dev, addr, flags) \
> >         dm_pci_phys_to_bus(dev, (virt_to_phys(addr)), (flags))
> >  #define dm_pci_bus_to_virt(dev, addr, flags, len, map_flags) \
> > --
>
> Please add test cases test/dm/pci.c::dm_test_pci_cap()

Zhiqiang, when you do new version patches, please split patch [8,9] to
a separate series, since it is not tightly coupled with other 7
patches, and can go separately.

Regards,
Bin

  reply	other threads:[~2019-04-01  7:31 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-25  2:24 [U-Boot] [RESEND PATCHv4 0/9] pci: Add PCIe Gen4 controller driver for NXP Layerscape SoCs Z.q. Hou
2019-03-25  2:24 ` [U-Boot] [RESEND PATCHv4 1/9] armv8: fsl-layerscpae: correct the PCIe controllers' region size Z.q. Hou
2019-04-01  3:22   ` Bin Meng
2019-04-01  3:48     ` Z.q. Hou
2019-03-25  2:24 ` [U-Boot] [RESEND PATCHv4 2/9] armv8: lx2160a: add MMU table entries for PCIe Z.q. Hou
2019-04-01  3:22   ` Bin Meng
2019-04-01  4:08     ` Z.q. Hou
2019-04-01  5:32       ` Bin Meng
2019-04-01  9:11         ` Z.q. Hou
2019-04-01  9:14           ` Bin Meng
2019-04-01  9:26             ` Z.q. Hou
2019-04-01  9:35               ` Bin Meng
2019-04-07 10:49   ` Prabhakar Kushwaha
2019-04-08  2:45     ` Z.q. Hou
2019-03-25  2:24 ` [U-Boot] [RESEND PATCHv4 3/9] pci: Add PCIe Gen4 controller driver for NXP Layerscape SoCs Z.q. Hou
2019-04-01  3:22   ` Bin Meng
2019-04-01  4:11     ` Z.q. Hou
2019-03-25  2:24 ` [U-Boot] [RESEND PATCHv4 4/9] kconfig: add dependency PCIE_LAYERSCAPE_GEN4 for FSL_PCIE_COMPAT Z.q. Hou
2019-04-01  3:22   ` Bin Meng
2019-04-01  4:12     ` Z.q. Hou
2019-03-25  2:24 ` [U-Boot] [RESEND PATCHv4 5/9] pci: ls_pcie_g4: add device tree fixups for PCI Stream IDs Z.q. Hou
2019-04-07 10:52   ` Prabhakar Kushwaha
2019-04-08  2:51     ` Z.q. Hou
2019-03-25  2:24 ` [U-Boot] [RESEND PATCHv4 6/9] armv8: lx2160a: add PCIe controller DT nodes Z.q. Hou
2019-04-01  3:22   ` Bin Meng
2019-04-01  4:12     ` Z.q. Hou
2019-03-25  2:24 ` [U-Boot] [RESEND PATCHv4 7/9] armv8: lx2160a: enable PCIe support Z.q. Hou
2019-04-01  3:22   ` Bin Meng
2019-04-01  4:18     ` Z.q. Hou
2019-04-07 10:52   ` Prabhakar Kushwaha
2019-04-08  2:52     ` Z.q. Hou
2019-03-25  2:24 ` [U-Boot] [RESEND PATCHv4 8/9] dm: pci: add APIs for capability accessors Z.q. Hou
2019-04-01  3:36   ` Bin Meng
2019-04-01  4:21     ` Z.q. Hou
2019-03-25  2:24 ` [U-Boot] [RESEND PATCHv4 9/9] dm: pci: add APIs for MPS and MRRS accessors Z.q. Hou
2019-04-01  6:00   ` Bin Meng
2019-04-01  7:31     ` Bin Meng [this message]
2019-04-01  9:14       ` Z.q. Hou
2019-04-01  9:13     ` Z.q. Hou

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='CAEUhbmVkutWB6T8RNyzarQtX=hg2Kn9SJGp-JtT1sz=G9S_ydQ@mail.gmail.com' \
    --to=bmeng.cn@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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.