mcusim / freebsd-src

sys/dev/dpaa2 drivers work-in-progress
https://www.FreeBSD.org/
Other
4 stars 3 forks source link

DPAA2: properly set link state on startup #11

Closed bzfbd closed 2 years ago

bzfbd commented 2 years ago

Factor out the link-state change tracking from media_change into a new function dpaa2_ni_miibus_statchg(). There use mii information for the link state as ifp->if_linkstate only gets updated after other mii functions are called and thus lacks behind.

Add a new bus function to memac_mdio so we can set the dpni interface and call MIIBUS_STATCHG on the dpni and pass that through to dpaa2_ni_miibus_statchg().

It is a bit of a weird setup with two parallel device tress off ACPI as ideally memac_mdio0 would be a child of dpaa2_ni0. We will see how this will work with FDT at some point but at least the current way of doing is flexible enough. Currently we need to make sure MC0 can discover the memac_mdio via the ACPI reference upon attach and have a way for DPNI to query that. The new bus function now allows us to set a back-pointer in the other direction from dpaa2_ni_setup().

nexus0
  acpi0
    dpaa2_mc0
      dpaa2_rc0
        dpaa2_ni0
    memac_mdio0
      memacphy0
        miibus1
          atphy0
    memac_mdio1

Most importantly and not to be missed at the end of dpaa2_ni_init() make sure we initialize the link state as otherwise we will not see any interrupts. That can be observed by a hanging NFS Root mount for example, whereas with the previous code ifconfig would trigger a SIOCGIFMEDIA call (from multi-user at some point) which then indirectly and more by accident set the the MAC LINK STATE via DPAA2_CMD_MAC_SET_LINK_STATE() and got the interface started.

This fixes #7

dsalychev commented 2 years ago

It rocks :) I'll spend sometime reading it today evening and will merge.

dsalychev commented 2 years ago

It panicked on Ten64:

Feeding entropy: .
ELF ldconfig path: /lib /usr/lib /usr/lib/compat /usr/local/lib /usr/local/lib/compat/pkg /usr/local/lib/compat/pkg
Setting hostname: guardian.
lo0: link state changed to UP
Fatal data abort:
  x0: ffff0000bd1f6000 (crypto_dev + bba96f40)
  x1: ffffa00019d18000
  x2: ffff00000090ef7c (digits + 20334)
  x3:              909
  x4: ffff0000007eb2cc (dpaa2_ni_media_tick + 0)
  x5: ffff0000bd1f6000 (crypto_dev + bba96f40)
  x6:                0
  x7:              100
  x8:                0
  x9:                0
 x10:                0
 x11: ffff000000ec8ca8 (w_locklistdata + 3b5e0)
 x12:                1
 x13:                0
 x14:            10000
 x15:                1
 x16:                8
 x17:     13940853b160
 x18: ffff000103c313c0
 x19: ffff0000bd1f6000 (crypto_dev + bba96f40)
 x20: ffffa00001d0e800
 x21: ffff0000bd1f61c0 (crypto_dev + bba97100)
 x22: ffff00000090ef7c (digits + 20334)
 x23:                0
 x24:                0
 x25:         80206910
 x26: ffffa00001d0e800
 x27:                0
 x28:         80206910
 x29: ffff000103c313e0
  sp: ffff000103c313c0
  lr: ffff0000007e7f34 (dpaa2_ni_miibus_statchg + 28)
 elr: ffff0000007e7f3c (dpaa2_ni_miibus_statchg + 30)
spsr:         20000045
 far:               3c
 esr:         96000004
panic: vm_fault failed: ffff0000007e7f3c error 1
cpuid = 6
time = 6
KDB: stack backtrace:
db_trace_self() at db_trace_self
db_trace_self_wrapper() at db_trace_self_wrapper+0x30
vpanic() at vpanic+0x138
panic() at panic+0x44
data_abort() at data_abort+0x2f0
handle_el1h_sync() at handle_el1h_sync+0x10
--- exception, esr 0x96000004
dpaa2_ni_miibus_statchg() at dpaa2_ni_miibus_statchg+0x30
dpaa2_ni_ioctl() at dpaa2_ni_ioctl+0x224
ifhwioctl() at ifhwioctl+0xba0
ifioctl() at ifioctl+0x70c
kern_ioctl() at kern_ioctl+0x2e4
sys_ioctl() at sys_ioctl+0x144
do_el0_sync() at do_el0_sync+0x508
handle_el0_sync() at handle_el0_sync+0x40
--- exception, esr 0x56000000
KDB: enter: panic
[ thread pid 82747 tid 100350 ]
Stopped at      kdb_enter+0x40: undefined       f907c27f
db> 
dsalychev commented 2 years ago

I'll look into it later.

bzfbd commented 2 years ago

Oh, no mii there (yet).

if (sc->fixed_link) return;

dsalychev commented 2 years ago

Yeah, you're right. It helped.

dsalychev commented 2 years ago

Applied in 452939456bf79e68bef92becbe7b145b43764a9f. Thanks for that!