qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Vivier <laurent@vivier.eu>
To: Greg Ungerer <gerg@uclinux.org>, qemu-devel@nongnu.org
Cc: Jason Wang <jasowang@redhat.com>
Subject: Re: [Qemu-devel] [PATCHv2] hw/net: implement MIB counters in mcf_fec driver
Date: Fri, 3 Feb 2017 09:40:49 +0100	[thread overview]
Message-ID: <0b4b09bc-30db-0ba0-1796-e7af18fd836b@vivier.eu> (raw)
In-Reply-To: <1484134214-32640-1-git-send-email-gerg@uclinux.org>

Add cc: to Network devices odd fixer.

Le 11/01/2017 à 12:30, Greg Ungerer a écrit :
> The FEC ethernet hardware module used on ColdFire SoC parts contains a
> block of RAM used to maintain hardware counters. This block is accessible
> via the usual FEC register address space. There is currently no support
> for this in the QEMU mcf_fec driver.
> 
> Add support for storing a MIB RAM block, and provide register level
> access to it. Also implement a basic set of stats collection functions
> to populate MIB data fields.
> 
> This support tested running a Linux target and using the net-tools
> "ethtool -S" option. As of linux-4.9 the kernels FEC driver makes
> accesses to the MIB counters during its initialization (which it never
> did before), and so this version of Linux will now fail with the QEMU
> error:
> 
>     qemu: hardware error: mcf_fec_read: Bad address 0x200
> 
> This MIB counter support fixes this problem.
> 
> Signed-off-by: Greg Ungerer <gerg@uclinux.org>
> ---
> 
> v2: fixed formatting problems picked up by checkpatch
> 
>  hw/net/mcf_fec.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 115 insertions(+)
> 
> diff --git a/hw/net/mcf_fec.c b/hw/net/mcf_fec.c
> index 4025eb3..c74804b 100644
> --- a/hw/net/mcf_fec.c
> +++ b/hw/net/mcf_fec.c
> @@ -25,6 +25,7 @@ do { printf("mcf_fec: " fmt , ## __VA_ARGS__); } while (0)
>  
>  #define FEC_MAX_DESC 1024
>  #define FEC_MAX_FRAME_SIZE 2032
> +#define FEC_MIB_SIZE 64
>  
>  typedef struct {
>      MemoryRegion *sysmem;
> @@ -48,6 +49,7 @@ typedef struct {
>      uint32_t erdsr;
>      uint32_t etdsr;
>      uint32_t emrbr;
> +    uint32_t mib[FEC_MIB_SIZE];
>  } mcf_fec_state;
>  
>  #define FEC_INT_HB   0x80000000
...
>  static void mcf_fec_do_tx(mcf_fec_state *s)
>  {
>      uint32_t addr;
> @@ -178,6 +262,7 @@ static void mcf_fec_do_tx(mcf_fec_state *s)
>              /* Last buffer in frame.  */
>              DPRINTF("Sending packet\n");
>              qemu_send_packet(qemu_get_queue(s->nic), frame, frame_size);
> +            mcf_fec_tx_stats(s, frame_size);
>              ptr = frame;
>              frame_size = 0;
>              s->eir |= FEC_INT_TXF;
> @@ -298,6 +383,7 @@ static uint64_t mcf_fec_read(void *opaque, hwaddr addr,
>      case 0x180: return s->erdsr;
>      case 0x184: return s->etdsr;
>      case 0x188: return s->emrbr;
> +    case 0x200 ... 0x2e0: return s->mib[(addr & 0x1ff) / 4];

As FEC_MIB_SIZE is 64 and 0x1ff / 4 is 127, you can have overflow here
and below.

>      default:
>          hw_error("mcf_fec_read: Bad address 0x%x\n", (int)addr);
>          return 0;
> @@ -395,12 +481,40 @@ static void mcf_fec_write(void *opaque, hwaddr addr,
>      case 0x188:
>          s->emrbr = value > 0 ? value & 0x7F0 : 0x7F0;
>          break;
> +    case 0x200 ... 0x2e0:
> +        s->mib[(addr & 0x1ff) / 4] = value;

overflow here again.

Thanks,
Laurent

  reply	other threads:[~2017-02-03  8:41 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-11 11:30 [Qemu-devel] [PATCHv2] hw/net: implement MIB counters in mcf_fec driver Greg Ungerer
2017-02-03  8:40 ` Laurent Vivier [this message]
2017-02-03  9:23   ` Laurent Vivier
  -- strict thread matches above, loose matches on Subject: below --
2017-03-13  4:56 Greg Ungerer
2017-03-13  6:17 ` Jason Wang

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=0b4b09bc-30db-0ba0-1796-e7af18fd836b@vivier.eu \
    --to=laurent@vivier.eu \
    --cc=gerg@uclinux.org \
    --cc=jasowang@redhat.com \
    --cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).