From fc9766d2fa4b694a183330d8a403035f4419b143 Mon Sep 17 00:00:00 2001 From: whitequark Date: Thu, 4 Jan 2018 11:37:52 +0000 Subject: [PATCH] firmware: reset ethphy before initializing smoltcp (fixes #884). --- artiq/firmware/bootloader/main.rs | 8 +++++--- artiq/firmware/libboard/ethmac.rs | 10 ++++++++++ artiq/firmware/runtime/main.rs | 10 ++++++---- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/artiq/firmware/bootloader/main.rs b/artiq/firmware/bootloader/main.rs index 87cdfb67d..2a9325fac 100644 --- a/artiq/firmware/bootloader/main.rs +++ b/artiq/firmware/bootloader/main.rs @@ -158,10 +158,12 @@ fn network_boot() { println!("Using MAC address {} and IP address {}", eth_addr, ip_addr); - let net_device = unsafe { ethmac::EthernetDevice::new() }; - let mut neighbor_cache_storage = [None; 2]; + let mut net_device = unsafe { ethmac::EthernetDevice::new() }; + net_device.reset(); + + let mut neighbor_map = [None; 2]; let neighbor_cache = - smoltcp::iface::NeighborCache::new(&mut neighbor_cache_storage[..]); + smoltcp::iface::NeighborCache::new(&mut neighbor_map[..]); let mut ip_addrs = [IpCidr::new(ip_addr, 0)]; let mut interface = smoltcp::iface::EthernetInterfaceBuilder::new(net_device) diff --git a/artiq/firmware/libboard/ethmac.rs b/artiq/firmware/libboard/ethmac.rs index 1a1f29272..ff9c1149e 100644 --- a/artiq/firmware/libboard/ethmac.rs +++ b/artiq/firmware/libboard/ethmac.rs @@ -4,6 +4,7 @@ use smoltcp::phy::{self, DeviceCapabilities, Device}; use csr; use mem::ETHMAC_BASE; +use clock; const RX_SLOTS: usize = csr::ETHMAC_RX_SLOTS as usize; const TX_SLOTS: usize = csr::ETHMAC_TX_SLOTS as usize; @@ -45,6 +46,15 @@ impl EthernetDevice { pub unsafe fn new() -> EthernetDevice { EthernetDevice(()) } + + pub fn reset(&mut self) { + unsafe { + csr::ethphy::crg_reset_write(1); + clock::spin_us(2_000); + csr::ethphy::crg_reset_write(0); + clock::spin_us(2_000); + } + } } impl<'a> Device<'a> for EthernetDevice { diff --git a/artiq/firmware/runtime/main.rs b/artiq/firmware/runtime/main.rs index 1d6e631f5..ad4863c03 100644 --- a/artiq/firmware/runtime/main.rs +++ b/artiq/firmware/runtime/main.rs @@ -130,18 +130,20 @@ fn startup_ethernet() { } } + let mut net_device = unsafe { ethmac::EthernetDevice::new() }; + net_device.reset(); + // fn _net_trace_writer(timestamp: u64, printer: smoltcp::wire::PrettyPrinter) // where U: smoltcp::wire::pretty_print::PrettyPrint { // let seconds = timestamp / 1000; // let micros = timestamp % 1000 * 1000; // print!("\x1b[37m[{:6}.{:06}s]\n{}\x1b[0m\n", seconds, micros, printer) // } - - let net_device = unsafe { ethmac::EthernetDevice::new() }; // let net_device = smoltcp::phy::EthernetTracer::new(net_device, _net_trace_writer); - let mut neighbor_cache_storage = [None; 8]; + + let mut neighbor_map = [None; 8]; let neighbor_cache = - smoltcp::iface::NeighborCache::new(&mut neighbor_cache_storage[..]); + smoltcp::iface::NeighborCache::new(&mut neighbor_map[..]); let mut interface = smoltcp::iface::EthernetInterfaceBuilder::new(net_device) .neighbor_cache(neighbor_cache)