public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Ben Hutchings <bhutchings@solarflare.com>
To: Peter Wu <lekensteyn@gmail.com>
Cc: <netdev@vger.kernel.org>, nic_swsd <nic_swsd@realtek.com>,
	Francois Romieu <romieu@fr.zoreil.com>
Subject: Re: [PATCH v2] r8169: fix invalid register dump
Date: Sat, 17 Aug 2013 12:27:38 +0200	[thread overview]
Message-ID: <1376735258.11042.102.camel@deadeye.wl.decadent.org.uk> (raw)
In-Reply-To: <1376730263-9352-1-git-send-email-lekensteyn@gmail.com>

On Sat, 2013-08-17 at 11:04 +0200, Peter Wu wrote:
> From: Peter Wu <lekensteyn@gmail.com>
> 
> For some reason, my PCIe RTL8111E onboard NIC on a GA-Z68X-UD3H-B3
> motherboard reads as FFs when reading from MMIO with a block size
> larger than 7. Therefore change to reading blocks of four bytes.
> 
> Thanks to Francois for a better implementation.
> 
> Signed-off-by: Peter Wu <lekensteyn@gmail.com>
> ---
>  drivers/net/ethernet/realtek/r8169.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
> index b5eb419..2943916 100644
> --- a/drivers/net/ethernet/realtek/r8169.c
> +++ b/drivers/net/ethernet/realtek/r8169.c
> @@ -1897,12 +1897,16 @@ static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs,
>  			     void *p)
>  {
>  	struct rtl8169_private *tp = netdev_priv(dev);
> +	u32 __iomem *data = tp->mmio_addr;
> +	u32 *dw = p;
> +	int i;
>  
>  	if (regs->len > R8169_REGS_SIZE)
>  		regs->len = R8169_REGS_SIZE;
>  
>  	rtl_lock_work(tp);
> -	memcpy_fromio(p, tp->mmio_addr, regs->len);
> +	for (i = regs->len; i > 0; i -= 4)
> +		memcpy_fromio(dw++, data++, min(4, i));

I would be very wary of accessing registers with any width other than
the usual (32 bits).

And as I said, the kernel buffer is always large enough for all your
registers, so this could just be:

	for (i = 0; i < R8169_REGS_SIZE; i += 4)
		memcpy_fromio(dw++, data++, 4);

Ben.

>  	rtl_unlock_work(tp);
>  }
>  

-- 
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.

  reply	other threads:[~2013-08-17 10:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-17  9:04 [PATCH v2] r8169: fix invalid register dump Peter Wu
2013-08-17 10:27 ` Ben Hutchings [this message]
2013-08-17 21:14   ` Francois Romieu

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=1376735258.11042.102.camel@deadeye.wl.decadent.org.uk \
    --to=bhutchings@solarflare.com \
    --cc=lekensteyn@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=nic_swsd@realtek.com \
    --cc=romieu@fr.zoreil.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