From 93e82e2201469d07d51f78990cc6161ce4f5ea13 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Fri, 8 Jul 2022 17:55:57 +0800 Subject: [PATCH] Revert "Use new ip_addr_storage module instead of net_settings" This reverts commit 50dbda4f43d80725d1ccca9af3fcdfffbad121e1. --- artiq/firmware/libboard_misoc/net_settings.rs | 40 ++++++++++++++++++- artiq/firmware/runtime/ip_addr_storage.rs | 40 ------------------- artiq/firmware/runtime/main.rs | 4 +- artiq/firmware/runtime/sched.rs | 2 +- 4 files changed, 41 insertions(+), 45 deletions(-) delete mode 100644 artiq/firmware/runtime/ip_addr_storage.rs diff --git a/artiq/firmware/libboard_misoc/net_settings.rs b/artiq/firmware/libboard_misoc/net_settings.rs index 2b69d9262..20b204c80 100644 --- a/artiq/firmware/libboard_misoc/net_settings.rs +++ b/artiq/firmware/libboard_misoc/net_settings.rs @@ -1,13 +1,21 @@ use core::fmt; use core::fmt::{Display, Formatter}; use core::str::FromStr; +use smoltcp::iface::{Interface, InterfaceBuilder}; +use smoltcp::phy::Device; -use smoltcp::wire::{EthernetAddress, IpAddress, Ipv4Address}; +use smoltcp::wire::{EthernetAddress, IpAddress, IpCidr, Ipv4Address, Ipv4Cidr}; use config; #[cfg(soc_platform = "kasli")] use i2c_eeprom; + +const IPV4_INDEX: usize = 0; +const IPV6_LL_INDEX: usize = 1; +const IPV6_INDEX: usize = 2; +const IP_ADDRESS_STORAGE_SIZE: usize = 3; + pub enum Ipv4AddrConfig { UseDhcp, Static(Ipv4Address), @@ -101,3 +109,33 @@ pub fn get_adresses() -> NetAddresses { ipv6_addr: ipv6_addr } } + +pub trait InterfaceBuilderEx { + fn init_ip_addrs(self, net_addresses: &NetAddresses) -> Self; +} + +impl<'a, DeviceT: for<'d> Device<'d>> InterfaceBuilderEx for InterfaceBuilder<'a, DeviceT> { + fn init_ip_addrs(self, net_addresses: &NetAddresses) -> Self { + let mut storage = [ + IpCidr::new(IpAddress::Ipv4(Ipv4Address::UNSPECIFIED), 0); IP_ADDRESS_STORAGE_SIZE + ]; + if let Ipv4AddrConfig::Static(ipv4) = net_addresses.ipv4_addr { + storage[IPV4_INDEX] = IpCidr::new(IpAddress::Ipv4(ipv4), 0); + } + storage[IPV6_LL_INDEX] = IpCidr::new(net_addresses.ipv6_ll_addr, 0); + if let Some(ipv6) = net_addresses.ipv6_addr { + storage[IPV6_INDEX] = IpCidr::new(ipv6, 0); + } + self.ip_addrs(storage) + } +} + +pub trait InterfaceEx { + fn update_ipv4_addr(&mut self, addr: &Ipv4Cidr); +} + +impl<'a, DeviceT: for<'d> Device<'d>> InterfaceEx for Interface<'a, DeviceT> { + fn update_ipv4_addr(&mut self, addr: &Ipv4Cidr) { + self.update_ip_addrs(|storage| storage[IPV4_INDEX] = IpCidr::Ipv4(*addr)) + } +} diff --git a/artiq/firmware/runtime/ip_addr_storage.rs b/artiq/firmware/runtime/ip_addr_storage.rs deleted file mode 100644 index 310c21941..000000000 --- a/artiq/firmware/runtime/ip_addr_storage.rs +++ /dev/null @@ -1,40 +0,0 @@ -use smoltcp::iface::{Interface, InterfaceBuilder}; -use smoltcp::phy::Device; -use smoltcp::wire::{IpAddress, IpCidr, Ipv4Address, Ipv4Cidr}; -use board_misoc::net_settings::{Ipv4AddrConfig, NetAddresses}; - - -const IPV4_INDEX: usize = 0; -const IPV6_LL_INDEX: usize = 1; -const IPV6_INDEX: usize = 2; -const IP_ADDRESS_STORAGE_SIZE: usize = 3; - -pub trait InterfaceBuilderEx { - fn init_ip_addrs(self, net_addresses: &NetAddresses) -> Self; -} - -impl<'a, DeviceT: for<'d> Device<'d>> InterfaceBuilderEx for InterfaceBuilder<'a, DeviceT> { - fn init_ip_addrs(self, net_addresses: &NetAddresses) -> Self { - let mut storage = [ - IpCidr::new(IpAddress::Ipv4(Ipv4Address::UNSPECIFIED), 0); IP_ADDRESS_STORAGE_SIZE - ]; - if let Ipv4AddrConfig::Static(ipv4) = net_addresses.ipv4_addr { - storage[IPV4_INDEX] = IpCidr::new(IpAddress::Ipv4(ipv4), 0); - } - storage[IPV6_LL_INDEX] = IpCidr::new(net_addresses.ipv6_ll_addr, 0); - if let Some(ipv6) = net_addresses.ipv6_addr { - storage[IPV6_INDEX] = IpCidr::new(ipv6, 0); - } - self.ip_addrs(storage) - } -} - -pub trait InterfaceEx { - fn update_ipv4_addr(&mut self, addr: &Ipv4Cidr); -} - -impl<'a, DeviceT: for<'d> Device<'d>> InterfaceEx for Interface<'a, DeviceT> { - fn update_ipv4_addr(&mut self, addr: &Ipv4Cidr) { - self.update_ip_addrs(|storage| storage[IPV4_INDEX] = IpCidr::Ipv4(*addr)) - } -} diff --git a/artiq/firmware/runtime/main.rs b/artiq/firmware/runtime/main.rs index b36fd9251..f1e7e7108 100644 --- a/artiq/firmware/runtime/main.rs +++ b/artiq/firmware/runtime/main.rs @@ -32,7 +32,7 @@ use smoltcp::wire::HardwareAddress; use board_misoc::{csr, ident, clock, spiflash, config, net_settings, pmp, boot}; #[cfg(has_ethmac)] use board_misoc::ethmac; -use board_misoc::net_settings::{Ipv4AddrConfig}; +use board_misoc::net_settings::{Ipv4AddrConfig, InterfaceBuilderEx}; #[cfg(has_drtio)] use board_artiq::drtioaux; use board_artiq::drtio_routing; @@ -42,7 +42,6 @@ use proto_artiq::{mgmt_proto, moninj_proto, rpc_proto, session_proto, kernel_pro use proto_artiq::analyzer_proto; use riscv::register::{mcause, mepc, mtval}; -use ip_addr_storage::InterfaceBuilderEx; mod rtio_clocking; mod rtio_mgt; @@ -61,7 +60,6 @@ mod moninj; #[cfg(has_rtio_analyzer)] mod analyzer; mod dhcp; -mod ip_addr_storage; #[cfg(has_grabber)] fn grabber_thread(io: sched::Io) { diff --git a/artiq/firmware/runtime/sched.rs b/artiq/firmware/runtime/sched.rs index 1f9c79bc2..a31c6ec43 100644 --- a/artiq/firmware/runtime/sched.rs +++ b/artiq/firmware/runtime/sched.rs @@ -16,7 +16,7 @@ use board_misoc::clock; use urc::Urc; use board_misoc::ethmac::EthernetDevice; use smoltcp::phy::Tracer; -use ip_addr_storage::InterfaceEx; +use board_misoc::net_settings::InterfaceEx; #[derive(Fail, Debug)] pub enum Error {