On Wed, 23 Nov 2016, Mike Belopuhov wrote:
> This moves code that is supposed to be in init, but is in stop
> right now. Tested on qemu. OK?
The current code has some symmetry insofar that stop leaves the device in
the same state as it is after attach. With your diff, the first vio_init()
would find a different situation than the following calls. Not sure if one
of the two variants is better than the other.
>
> diff --git sys/dev/pci/if_vio.c sys/dev/pci/if_vio.c
> index d8c9798..68e6636 100644
> --- sys/dev/pci/if_vio.c
> +++ sys/dev/pci/if_vio.c
> @@ -662,14 +662,22 @@ vio_media_status(struct ifnet *ifp, struct ifmediareq
> *imr)
> */
> int
> vio_init(struct ifnet *ifp)
> {
> struct vio_softc *sc = ifp->if_softc;
> + struct virtio_softc *vsc = sc->sc_virtio;
>
> vio_stop(ifp, 0);
> if_rxr_init(>sc_rx_ring, 2 * ((ifp->if_hardmtu / MCLBYTES) + 1),
> sc->sc_vq[VQRX].vq_num);
> + virtio_reinit_start(vsc);
> + virtio_negotiate_features(vsc, vsc->sc_features, NULL);
> + virtio_start_vq_intr(vsc, >sc_vq[VQRX]);
> + virtio_stop_vq_intr(vsc, >sc_vq[VQTX]);
> + if (vsc->sc_nvqs >= 3)
> + virtio_start_vq_intr(vsc, >sc_vq[VQCTL]);
> + virtio_reinit_end(vsc);
> vio_populate_rx_mbufs(sc);
> ifp->if_flags |= IFF_RUNNING;
> ifq_clr_oactive(>if_snd);
> vio_iff(sc);
> vio_link_state(ifp);
> @@ -693,17 +701,10 @@ vio_stop(struct ifnet *ifp, int disable)
> vio_ctrleof(>sc_vq[VQCTL]);
> vio_tx_drain(sc);
> if (disable)
> vio_rx_drain(sc);
>
> - virtio_reinit_start(vsc);
> - virtio_negotiate_features(vsc, vsc->sc_features, NULL);
> - virtio_start_vq_intr(vsc, >sc_vq[VQRX]);
> - virtio_stop_vq_intr(vsc, >sc_vq[VQTX]);
> - if (vsc->sc_nvqs >= 3)
> - virtio_start_vq_intr(vsc, >sc_vq[VQCTL]);
> - virtio_reinit_end(vsc);
> if (vsc->sc_nvqs >= 3) {
> if (sc->sc_ctrl_inuse != FREE)
> sc->sc_ctrl_inuse = RESET;
> wakeup(>sc_ctrl_inuse);
> }
>
>