From: "Michael S. Tsirkin" <mst@redhat.com>
To: "Gabriel L. Somlo" <gsomlo@gmail.com>
Cc: pbonzini@redhat.com, Jason Wang <jasowang@redhat.com>,
qemu-devel@nongnu.org, stefanha@redhat.com, agraf@suse.de
Subject: Re: [Qemu-devel] [PATCH v3] e1000: clean up phyreg_writeops/set_phy_ctrl
Date: Wed, 2 Jul 2014 12:19:33 +0300 [thread overview]
Message-ID: <20140702091933.GA3461@redhat.com> (raw)
In-Reply-To: <20140702091230.GA3296@redhat.com>
On Wed, Jul 02, 2014 at 12:12:30PM +0300, Michael S. Tsirkin wrote:
> On Tue, Jul 01, 2014 at 03:03:48PM -0400, Gabriel L. Somlo wrote:
> > Make phyreg_writeops responsible for actually writing their
> > respective phy registers. The only current instance of
> > phyreg_writeops is set_phy_ctrl(), which we modify to actually
> > write the register, while also correctly handling reserved and
> > self-clearing bits.
> >
> > have_autoneg() does not need to check for MII_CR_RESTART_AUTO_NEG,
> > since the only time the flag comes into play is during set_phy_ctrl(),
> > and never actually gets written to the phy control register. We also
> > move it in front of set_phy_ctrl(), to avoid a forward declaration.
> >
> > Signed-off-by: Gabriel Somlo <somlo@cmu.edu>
> > ---
>
>
> Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
>
> Applied, thanks!
And just to clarify (I'd like to add this to the commit log)
we are fixing a minor bug here: MII_CR_RESTART_AUTO_NEG and MII_CR_RESET
aren't self-clearing as they should be, and low 5 bits aren't RO
as they should be.
> > Michael, Stefan:
> >
> > Here's a new version of this patch with slightly better (IMHO) formatting.
> > I think the merits are 1. handling bits which are reserved or self
> > clearing; and 2. eliminating the surprise of a "write op" that does not
> > actually write to its register :)
> >
> > Regarding the "sibling" patch originally accompanying this one (which
> > increased the timer delay for autonegotiation), I'll take a while
> > longer to figure out what's really going on, so I'll send out a separate
> > patch if/when that happens.
> >
> > Please apply (or review/critique) this one independently.
> >
> > Thanks,
> > Gabriel
> >
> > hw/net/e1000.c | 31 +++++++++++++++++--------------
> > 1 file changed, 17 insertions(+), 14 deletions(-)
> >
> > diff --git a/hw/net/e1000.c b/hw/net/e1000.c
> > index 0fc29a0..04c0f91 100644
> > --- a/hw/net/e1000.c
> > +++ b/hw/net/e1000.c
> > @@ -186,21 +186,31 @@ e1000_link_up(E1000State *s)
> > s->phy_reg[PHY_STATUS] |= MII_SR_LINK_STATUS;
> > }
> >
> > +static bool
> > +have_autoneg(E1000State *s)
> > +{
> > + return (s->compat_flags & E1000_FLAG_AUTONEG) &&
> > + (s->phy_reg[PHY_CTRL] & MII_CR_AUTO_NEG_EN);
> > +}
> > +
> > static void
> > set_phy_ctrl(E1000State *s, int index, uint16_t val)
> > {
> > + /* bits 0-5 reserved; MII_CR_[RESTART_AUTO_NEG,RESET] are self clearing */
> > + s->phy_reg[PHY_CTRL] = val & ~(0x3f |
> > + MII_CR_RESET |
> > + MII_CR_RESTART_AUTO_NEG);
> > +
> > /*
> > * QEMU 1.3 does not support link auto-negotiation emulation, so if we
> > * migrate during auto negotiation, after migration the link will be
> > * down.
> > */
> > - if (!(s->compat_flags & E1000_FLAG_AUTONEG)) {
> > - return;
> > - }
> > - if ((val & MII_CR_AUTO_NEG_EN) && (val & MII_CR_RESTART_AUTO_NEG)) {
> > + if (have_autoneg(s) && (val & MII_CR_RESTART_AUTO_NEG)) {
> > e1000_link_down(s);
> > DBGOUT(PHY, "Start link auto negotiation\n");
> > - timer_mod(s->autoneg_timer, qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 500);
> > + timer_mod(s->autoneg_timer,
> > + qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL) + 500);
> > }
> > }
> >
> > @@ -446,8 +456,9 @@ set_mdic(E1000State *s, int index, uint32_t val)
> > } else {
> > if (addr < NPHYWRITEOPS && phyreg_writeops[addr]) {
> > phyreg_writeops[addr](s, index, data);
> > + } else {
> > + s->phy_reg[addr] = data;
> > }
> > - s->phy_reg[addr] = data;
> > }
> > }
> > s->mac_reg[MDIC] = val | E1000_MDIC_READY;
> > @@ -848,14 +859,6 @@ receive_filter(E1000State *s, const uint8_t *buf, int size)
> > return 0;
> > }
> >
> > -static bool
> > -have_autoneg(E1000State *s)
> > -{
> > - return (s->compat_flags & E1000_FLAG_AUTONEG) &&
> > - (s->phy_reg[PHY_CTRL] & MII_CR_AUTO_NEG_EN) &&
> > - (s->phy_reg[PHY_CTRL] & MII_CR_RESTART_AUTO_NEG);
> > -}
> > -
> > static void
> > e1000_set_link_status(NetClientState *nc)
> > {
> > --
> > 1.9.3
prev parent reply other threads:[~2014-07-02 10:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-01 19:03 [Qemu-devel] [PATCH v3] e1000: clean up phyreg_writeops/set_phy_ctrl Gabriel L. Somlo
2014-07-02 9:12 ` Michael S. Tsirkin
2014-07-02 9:19 ` Michael S. Tsirkin [this message]
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=20140702091933.GA3461@redhat.com \
--to=mst@redhat.com \
--cc=agraf@suse.de \
--cc=gsomlo@gmail.com \
--cc=jasowang@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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;
as well as URLs for NNTP newsgroup(s).