Skip to content

Commit

Permalink
Shorten D(estination)A(ddress) and S(ource)A(ddress), Filtering -> Fi…
Browse files Browse the repository at this point in the history
…lter
  • Loading branch information
datdenkikniet committed Jan 3, 2023
1 parent fdb5d45 commit 8f6e9bc
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 66 deletions.
6 changes: 3 additions & 3 deletions examples/arp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use cortex_m_rt::{entry, exception};
use cortex_m::interrupt::Mutex;
use stm32_eth::{
mac::{
frame_filtering::{FrameFiltering, FrameFilteringMode, Mac},
frame_filter::{Filter, FilterConfig, Mac},
phy::BarePhy,
Phy,
},
Expand Down Expand Up @@ -63,12 +63,12 @@ fn main() -> ! {

let some_mac = if eth_dma.tx_is_running() { 1 } else { 0 };

let frame_filtering = FrameFiltering::filter_destinations(
let filter_config = FilterConfig::filter_destinations(
Mac::new([some_mac, some_mac, some_mac, some_mac, some_mac, some_mac]),
&[],
);

eth_mac.configure_filtering(&FrameFilteringMode::Filter(frame_filtering));
eth_mac.configure_frame_filter(&Filter::Filter(filter_config));

let mut last_link_up = false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// on received control frames,
#[derive(Debug, Clone)]

pub enum ControlFrameFiltering {
pub enum ControlFrameFilter {
/// Prevent all control frames from reaching
/// the application.
BlockAll,
Expand All @@ -16,15 +16,15 @@ pub enum ControlFrameFiltering {
AddressFilter,
}

impl ControlFrameFiltering {
/// Create a new [`ControlFrameFiltering`] that filters out
impl ControlFrameFilter {
/// Create a new [`ControlFrameFilter`] that filters out
/// all control frames.
pub const fn new() -> Self {
Self::BlockAll
}
}

impl Default for ControlFrameFiltering {
impl Default for ControlFrameFilter {
fn default() -> Self {
Self::new()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
/// The type of filtering that the MAC should apply to
/// frames that are to be transmitted.
/// The type of destination address filtering that
/// the MAC should apply to incoming frames.
#[derive(Debug, Clone)]
pub struct DestinationAddressFiltering {
pub struct DaFilter {
/// Filtering to be performed based on perfect address matches.
pub perfect_filtering: PerfectDestinationAddressFilteringMode,
pub perfect_filtering: PerfectDaFilterMode,
/// Enable or disable hash table filtering for destination
/// addresses.
pub hash_table_filtering: bool,
}

impl DestinationAddressFiltering {
/// Create a new [`DestinationAddressFiltering`] that does
impl DaFilter {
/// Create a new [`DaFilter`] that does
/// not filter any frames.
pub const fn new() -> Self {
Self {
perfect_filtering: PerfectDestinationAddressFilteringMode::new(),
perfect_filtering: PerfectDaFilterMode::new(),
hash_table_filtering: false,
}
}
}

impl Default for DestinationAddressFiltering {
impl Default for DaFilter {
fn default() -> Self {
Self::new()
}
}

/// The type of destination address filtering that
/// the MAC should apply to frames.
/// the MAC should apply to incoming frames.
#[derive(Debug, Clone)]

pub enum PerfectDestinationAddressFilteringMode {
pub enum PerfectDaFilterMode {
/// Filter frames by their Destination Address, based on
/// the addresses configured with [`AddressFilterType::Destination`].
///
Expand All @@ -44,15 +44,15 @@ pub enum PerfectDestinationAddressFilteringMode {
Inverse,
}

impl PerfectDestinationAddressFilteringMode {
/// Create a new [`PerfectDestinationAddressFilteringMode`] that filters
impl PerfectDaFilterMode {
/// Create a new [`PerfectDaFilterMode`] that filters
/// out all frames.
pub const fn new() -> Self {
Self::Normal
}
}

impl Default for PerfectDestinationAddressFilteringMode {
impl Default for PerfectDaFilterMode {
fn default() -> Self {
Self::new()
}
Expand Down
File renamed without changes.
64 changes: 32 additions & 32 deletions src/mac/frame_filtering/mod.rs → src/mac/frame_filter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ pub use control::*;
/// The frame filtering that the MAC should apply to
/// received Ethernet frames.
#[derive(Debug, Clone)]
pub enum FrameFilteringMode {
pub enum Filter {
/// No frame filtering on any frames.
Promiscuous,
/// Perform frame filtering based on the provided
/// configuration.
Filter(FrameFiltering),
Filter(FilterConfig),
}

impl Default for FrameFilteringMode {
impl Default for Filter {
fn default() -> Self {
Self::Promiscuous
}
}

impl FrameFilteringMode {
impl Filter {
pub(crate) fn configure(&self, eth_mac: &ETHERNET_MAC) {
match self {
FrameFilteringMode::Promiscuous => eth_mac.macffr.write(|w| w.pm().set_bit()),
FrameFilteringMode::Filter(config) => config.configure(eth_mac),
Filter::Promiscuous => eth_mac.macffr.write(|w| w.pm().set_bit()),
Filter::Filter(config) => config.configure(eth_mac),
}
}
}
Expand All @@ -49,7 +49,7 @@ impl FrameFilteringMode {
/// The total amount of [`MacAddressFilter`]s in this configuration object may
/// be at most 3.
#[derive(Debug, Clone)]
pub struct FrameFiltering {
pub struct FilterConfig {
/// The MAC address of this station. This address is always
/// used for Destination Address filtering.
pub base_address: Mac,
Expand All @@ -59,18 +59,18 @@ pub struct FrameFiltering {

/// Frame filtering applied to frames based on
/// their destination address.
pub destination_address_filter: DestinationAddressFiltering,
pub destination_address_filter: DaFilter,

/// Frame filtering applied to frames based on
/// their source address.
pub source_address_filter: SourceAddressFiltering,
pub source_address_filter: SaFilter,

/// Frame filtering applied to frames based on
/// whether they have a multicast address or not.
pub multicast_address_filter: MulticastAddressFiltering,
pub multicast_address_filter: MulticastAddressFilter,

/// Control frame filtering mode,
pub control_filter: ControlFrameFiltering,
pub control_filter: ControlFrameFilter,

/// Hash table configuration.
pub hash_table_value: HashTableValue,
Expand All @@ -89,8 +89,8 @@ pub struct FrameFiltering {
pub receive_all: bool,
}

impl FrameFiltering {
/// Create a new basic [`FrameFiltering`] that:
impl FilterConfig {
/// Create a new basic [`FilterConfig`] that:
/// * Does not filter out frames destined for `station_addr` or an address
/// contained in `extra_address`.
/// * Does not filter out multicast frames.
Expand All @@ -115,24 +115,24 @@ impl FrameFiltering {
}
}

FrameFiltering {
FilterConfig {
base_address: station_addr,
address_filters,
destination_address_filter: DestinationAddressFiltering {
perfect_filtering: PerfectDestinationAddressFilteringMode::Normal,
destination_address_filter: DaFilter {
perfect_filtering: PerfectDaFilterMode::Normal,
hash_table_filtering: false,
},
source_address_filter: SourceAddressFiltering::Ignore,
multicast_address_filter: MulticastAddressFiltering::PassAll,
control_filter: ControlFrameFiltering::BlockAll,
source_address_filter: SaFilter::Ignore,
multicast_address_filter: MulticastAddressFilter::PassAll,
control_filter: ControlFrameFilter::BlockAll,
hash_table_value: HashTableValue::new(),
filter_broadcast: false,
receive_all: false,
}
}

fn configure(&self, eth_mac: &ETHERNET_MAC) {
let FrameFiltering {
let FilterConfig {
base_address,
address_filters,
destination_address_filter,
Expand All @@ -152,28 +152,28 @@ impl FrameFiltering {
.write(|w| w.maca0l().bits(base_address.low()));

let daif = match &destination_address_filter.perfect_filtering {
PerfectDestinationAddressFilteringMode::Normal => false,
PerfectDestinationAddressFilteringMode::Inverse => true,
PerfectDaFilterMode::Normal => false,
PerfectDaFilterMode::Inverse => true,
};
let hu = destination_address_filter.hash_table_filtering;

let (saf, saif) = match &source_address_filter {
SourceAddressFiltering::Ignore => (false, false),
SourceAddressFiltering::Normal => (true, false),
SourceAddressFiltering::Inverse => (true, true),
SaFilter::Ignore => (false, false),
SaFilter::Normal => (true, false),
SaFilter::Inverse => (true, true),
};

let (pam, hm) = match &multicast_address_filter {
MulticastAddressFiltering::PassAll => (true, false),
MulticastAddressFiltering::DestinationAddressHash => (false, true),
MulticastAddressFiltering::DestinationAddress => (false, false),
MulticastAddressFilter::PassAll => (true, false),
MulticastAddressFilter::DestinationAddressHash => (false, true),
MulticastAddressFilter::DestinationAddress => (false, false),
};

let pcf = match &control_filter {
ControlFrameFiltering::BlockAll => 0b00,
ControlFrameFiltering::NoPause => 0b01,
ControlFrameFiltering::AllowAll => 0b10,
ControlFrameFiltering::AddressFilter => 0b11,
ControlFrameFilter::BlockAll => 0b00,
ControlFrameFilter::NoPause => 0b01,
ControlFrameFilter::AllowAll => 0b10,
ControlFrameFilter::AddressFilter => 0b11,
};

macro_rules! next_addr_reg {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// Multicast address filtering
#[derive(Debug, Clone)]
pub enum MulticastAddressFiltering {
pub enum MulticastAddressFilter {
/// All received multicast frames are passed to the
/// application.
PassAll,
Expand All @@ -14,15 +14,15 @@ pub enum MulticastAddressFiltering {
DestinationAddress,
}

impl MulticastAddressFiltering {
impl MulticastAddressFilter {
/// Create a new MulticastAddressFiltering that does not
/// filter any multicast frames.
pub const fn new() -> Self {
Self::PassAll
}
}

impl Default for MulticastAddressFiltering {
impl Default for MulticastAddressFilter {
fn default() -> Self {
Self::new()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/// The type of frame filtering that the MAC should perform
/// on received frames.
/// The type of source address frame filtering that
/// the MAC should perform to received frames.
#[derive(Debug, Clone)]

pub enum SourceAddressFiltering {
pub enum SaFilter {
/// Source address filtering never fails.
Ignore,
/// Filter frames by their Source Address, based on
Expand All @@ -17,15 +17,15 @@ pub enum SourceAddressFiltering {
Inverse,
}

impl SourceAddressFiltering {
/// Create a new [`SourceAddressFiltering`] that
impl SaFilter {
/// Create a new [`SaFilter`] that
/// does not filter any frames.
pub const fn new() -> Self {
Self::Inverse
}
}

impl Default for SourceAddressFiltering {
impl Default for SaFilter {
fn default() -> Self {
Self::new()
}
Expand Down
10 changes: 5 additions & 5 deletions src/mac/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
mod miim;
pub use miim::*;

pub mod frame_filtering;
pub mod frame_filter;

/// Speeds at which this MAC can be configured
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
Expand Down Expand Up @@ -39,7 +39,7 @@ mod consts {
/* For HCLK over 150 MHz */
pub const ETH_MACMIIAR_CR_HCLK_DIV_102: u8 = 4;
}
use self::{consts::*, frame_filtering::FrameFilteringMode};
use self::{consts::*, frame_filter::Filter};

/// HCLK must be at least 25MHz to use the ethernet peripheral.
/// This (empty) struct is returned to indicate that it is not set
Expand Down Expand Up @@ -139,7 +139,7 @@ impl EthernetMAC {
.mmctimr
.modify(|r, w| unsafe { w.bits(r.bits() | (1 << 21)) });

FrameFilteringMode::Promiscuous.configure(&eth_mac);
Filter::Promiscuous.configure(&eth_mac);

let mut me = Self { eth_mac };

Expand Down Expand Up @@ -207,8 +207,8 @@ impl EthernetMAC {

/// Configure the frame filtering performed by this MAC.
#[inline(always)]
pub fn configure_filtering(&self, filtering_config: &FrameFilteringMode) {
filtering_config.configure(&self.eth_mac);
pub fn configure_frame_filter(&self, filter_config: &Filter) {
filter_config.configure(&self.eth_mac);
}
}

Expand Down

0 comments on commit 8f6e9bc

Please sign in to comment.