All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kenji Kaneshige <kaneshige.kenji@jp.fujitsu.com>
To: linux-hotplug@vger.kernel.org
Subject: Re: [PATCH] Set PCIE maxpayload for card during hotplug insertion
Date: Fri, 25 Mar 2011 01:06:41 +0000	[thread overview]
Message-ID: <4D8BEAA1.4010003@jp.fujitsu.com> (raw)
In-Reply-To: <1301005267-31006-1-git-send-email-jordan_hargrave@dell.com>

(2011/03/25 7:21), Jordan Hargrave wrote:
> Reference: http://marc.info/?l=linux-hotplug&m\x128932324625063&w=2
>
> The following patch sets the MaxPayload setting to match the parent reading when inserting
> a PCIE card into a hotplug slot.  On our system, the upstream bridge is set to 256, but when
> inserting a card, the card setting defaults to 128.  As soon as I/O is performed to the card
> it starts receiving errors since the payload size is too small.
>
> Signed-off-by: Jordan_Hargrave@dell.com
>
> ---
>   drivers/pci/hotplug/pcihp_slot.c |   45 ++++++++++++++++++++++++++++++++++++++
>   1 files changed, 45 insertions(+), 0 deletions(-)
>
> diff --git a/drivers/pci/hotplug/pcihp_slot.c b/drivers/pci/hotplug/pcihp_slot.c
> index 80b461c..912d55b 100644
> --- a/drivers/pci/hotplug/pcihp_slot.c
> +++ b/drivers/pci/hotplug/pcihp_slot.c
> @@ -158,6 +158,47 @@ static void program_hpp_type2(struct pci_dev *dev, struct hpp_type2 *hpp)
>   	 */
>   }
>
> +/* Program PCIE MaxPayload setting on device: ensure parent maxpayload<= device */
> +static int pci_set_payload(struct pci_dev *dev)
> +{
> +	int pos, ppos;
> +	u16 pctl, psz;
> +	u16 dctl, dsz, dcap, dmax;
> +	struct pci_dev *parent;
> +
> +	parent = dev->bus->self;
> +	pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
> +	if (!pos)
> +		return 0;

You can use pci_pcie_cap(), which just returns dev->pcie_cap, instead of pci_find_capability().

> +
> +	/* Read Device MaxPayload capability and setting */
> +	pci_read_config_word(dev, pos + PCI_EXP_DEVCTL,&dctl);
> +	pci_read_config_word(dev, pos + PCI_EXP_DEVCAP,&dcap);
> +	dsz = (dctl&  PCI_EXP_DEVCTL_PAYLOAD)>>  5;
> +	dmax = (dcap&  PCI_EXP_DEVCAP_PAYLOAD);
> +
> +	/* Read Parent MaxPayload setting */
> +	ppos = pci_find_capability(parent, PCI_CAP_ID_EXP);
> +	if (!ppos)
> +		return 0;

Ditto.

> +	pci_read_config_word(parent, ppos + PCI_EXP_DEVCTL,&pctl);
> +	psz = (pctl&   PCI_EXP_DEVCTL_PAYLOAD)>>  5;
> +
> +	/* If parent payload>  device max payload ->  error
> +	 * If parent payload>  device payload ->  set speed
> +	 * If parent payload<= device payload ->  do nothing
> +	 */
> +	if (psz>  dmax)
> +		return -1;
> +	else if (psz>  dsz) {

Maybe just "if" (not "else if") here is easier to read.

> +		dev_info(&dev->dev, "Setting MaxPayload to %d\n", 128<<  psz);
> +		pci_write_config_word(dev, pos + PCI_EXP_DEVCTL,
> +				      (dctl&  ~PCI_EXP_DEVCTL_PAYLOAD) +
> +				      (psz<<  5));

What about

	dctrl = (dctrl & ~PCI_EXP_DEVCTL_PAYLOAD) | (psz << 5);
	pci_write_config_word(dev, pos + PCI_EXP_DEVCTL, dctrl);

?

Regards,
Kenji Kaneshige


  reply	other threads:[~2011-03-25  1:06 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-24 22:21 [PATCH] Set PCIE maxpayload for card during hotplug insertion Jordan Hargrave
2011-03-25  1:06 ` Kenji Kaneshige [this message]
2011-03-28  7:52 ` Jordan_Hargrave
2011-03-29 21:42 ` Jordan_Hargrave
2011-04-12 16:08 ` Jesse Barnes
2011-05-04 18:42 ` Jordan_Hargrave
2011-05-09 19:18 ` Jesse Barnes
2011-05-10 22:13 ` Kenji Kaneshige

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=4D8BEAA1.4010003@jp.fujitsu.com \
    --to=kaneshige.kenji@jp.fujitsu.com \
    --cc=linux-hotplug@vger.kernel.org \
    /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.