diff options
| author | René van Dorst <[email protected]> | 2023-08-26 00:21:01 +0200 |
|---|---|---|
| committer | René van Dorst <[email protected]> | 2023-08-27 10:37:45 +0200 |
| commit | 7f7256050cd8a4f1cb1bb270ee39cb9c8dfdafb2 (patch) | |
| tree | 9a590ebbefebab40b2b7189520ccf0d3bc8f1f57 /embassy-net-adin1110 | |
| parent | 4b6538c8a86947c64a0cf22fadeac847923f16e2 (diff) | |
Don't let the MAC add FCS when it is done by app
The application can append FSC to outgoing packets and the MAC can detect
and report when a bitflip has occurred.
But the MAC can also add FSC if we want, but we can´t do both.
When adding FSC by the application and MAC results in the packet drop by
the MAC when the TX packet size > (MTU - 4).
Having the application append the FSC is preferred.
So set the right config bits.
Diffstat (limited to 'embassy-net-adin1110')
| -rw-r--r-- | embassy-net-adin1110/src/lib.rs | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/embassy-net-adin1110/src/lib.rs b/embassy-net-adin1110/src/lib.rs index 8e5fef701..4042bd73c 100644 --- a/embassy-net-adin1110/src/lib.rs +++ b/embassy-net-adin1110/src/lib.rs | |||
| @@ -58,9 +58,11 @@ const TURN_AROUND_BYTE: u8 = 0x00; | |||
| 58 | 58 | ||
| 59 | /// Packet minimal frame/packet length | 59 | /// Packet minimal frame/packet length |
| 60 | const ETH_MIN_LEN: usize = 64; | 60 | const ETH_MIN_LEN: usize = 64; |
| 61 | |||
| 62 | /// Ethernet `Frame Check Sequence` length | 61 | /// Ethernet `Frame Check Sequence` length |
| 63 | const FSC_LEN: usize = 4; | 62 | const FSC_LEN: usize = 4; |
| 63 | /// Packet minimal frame/packet length without `Frame Check Sequence` length | ||
| 64 | const ETH_MIN_WITHOUT_FSC_LEN: usize = ETH_MIN_LEN - FSC_LEN; | ||
| 65 | |||
| 64 | /// SPI Header, contains SPI action and register id. | 66 | /// SPI Header, contains SPI action and register id. |
| 65 | const SPI_HEADER_LEN: usize = 2; | 67 | const SPI_HEADER_LEN: usize = 2; |
| 66 | /// SPI Header CRC length | 68 | /// SPI Header CRC length |
| @@ -283,8 +285,8 @@ impl<SPI: SpiDevice> ADIN1110<SPI> { | |||
| 283 | 285 | ||
| 284 | // ADIN1110 MAC and PHY don´t accept ethernet packet smaller than 64 bytes. | 286 | // ADIN1110 MAC and PHY don´t accept ethernet packet smaller than 64 bytes. |
| 285 | // So padded the data minus the FCS, FCS is automatilly added to by the MAC. | 287 | // So padded the data minus the FCS, FCS is automatilly added to by the MAC. |
| 286 | if let Some(pad_len) = (ETH_MIN_LEN - FSC_LEN).checked_sub(frame.len()) { | 288 | if frame.len() < ETH_MIN_WITHOUT_FSC_LEN { |
| 287 | let _ = tail_data.resize(pad_len, 0x00); | 289 | let _ = tail_data.resize(ETH_MIN_WITHOUT_FSC_LEN - frame.len(), 0x00); |
| 288 | frame_fcs = frame_fcs.update(&tail_data); | 290 | frame_fcs = frame_fcs.update(&tail_data); |
| 289 | } | 291 | } |
| 290 | 292 | ||
| @@ -294,15 +296,18 @@ impl<SPI: SpiDevice> ADIN1110<SPI> { | |||
| 294 | 296 | ||
| 295 | // len = frame_size + optional padding + 2 bytes Frame header | 297 | // len = frame_size + optional padding + 2 bytes Frame header |
| 296 | let send_len_orig = frame.len() + tail_data.len() + FRAME_HEADER_LEN; | 298 | let send_len_orig = frame.len() + tail_data.len() + FRAME_HEADER_LEN; |
| 297 | let spi_pad_len = send_len_orig.next_multiple_of(4); | 299 | |
| 298 | let send_len = u32::try_from(send_len_orig).map_err(|_| AdinError::PACKET_TOO_BIG)?; | 300 | let send_len = u32::try_from(send_len_orig).map_err(|_| AdinError::PACKET_TOO_BIG)?; |
| 299 | 301 | ||
| 300 | // Packet read of write to the MAC packet buffer must be a multipul of 4 bytes! | 302 | // Packet read of write to the MAC packet buffer must be a multipul of 4 bytes! |
| 301 | if spi_pad_len != send_len_orig { | 303 | let pad_len = send_len_orig & 0x03; |
| 302 | let spi_pad_len = spi_pad_len - send_len_orig; | 304 | if pad_len != 0 { |
| 303 | let _ = tail_data.extend_from_slice(&[DONT_CARE_BYTE, DONT_CARE_BYTE, DONT_CARE_BYTE][..spi_pad_len]); | 305 | let spi_pad_len = 4 - pad_len + tail_data.len(); |
| 306 | let _ = tail_data.resize(spi_pad_len, DONT_CARE_BYTE); | ||
| 304 | } | 307 | } |
| 305 | 308 | ||
| 309 | self.write_reg(sr::TX_FSIZE, send_len).await?; | ||
| 310 | |||
| 306 | #[cfg(feature = "defmt")] | 311 | #[cfg(feature = "defmt")] |
| 307 | defmt::trace!( | 312 | defmt::trace!( |
| 308 | "TX: hdr {} [{}] {:02x}-{:02x}-{:02x} SIZE: {}", | 313 | "TX: hdr {} [{}] {:02x}-{:02x}-{:02x} SIZE: {}", |
| @@ -314,8 +319,6 @@ impl<SPI: SpiDevice> ADIN1110<SPI> { | |||
| 314 | send_len, | 319 | send_len, |
| 315 | ); | 320 | ); |
| 316 | 321 | ||
| 317 | self.write_reg(sr::TX_FSIZE, send_len).await?; | ||
| 318 | |||
| 319 | let mut transaction = [ | 322 | let mut transaction = [ |
| 320 | Operation::Write(head_data.as_slice()), | 323 | Operation::Write(head_data.as_slice()), |
| 321 | Operation::Write(frame), | 324 | Operation::Write(frame), |
| @@ -439,7 +442,12 @@ impl<'d, SPI: SpiDevice, INT: Wait, RST: OutputPin> Runner<'d, SPI, INT, RST> { | |||
| 439 | Err(e) => match e { | 442 | Err(e) => match e { |
| 440 | AdinError::PACKET_TOO_BIG => { | 443 | AdinError::PACKET_TOO_BIG => { |
| 441 | #[cfg(feature = "defmt")] | 444 | #[cfg(feature = "defmt")] |
| 442 | defmt::error!("RX Packet to big, DROP"); | 445 | defmt::error!("RX Packet too big, DROP"); |
| 446 | self.mac.write_reg(sr::FIFO_CLR, 1).await.unwrap(); | ||
| 447 | } | ||
| 448 | AdinError::PACKET_TOO_SMALL => { | ||
| 449 | #[cfg(feature = "defmt")] | ||
| 450 | defmt::error!("RX Packet too small, DROP"); | ||
| 443 | self.mac.write_reg(sr::FIFO_CLR, 1).await.unwrap(); | 451 | self.mac.write_reg(sr::FIFO_CLR, 1).await.unwrap(); |
| 444 | } | 452 | } |
| 445 | AdinError::Spi(_) => { | 453 | AdinError::Spi(_) => { |
| @@ -622,9 +630,18 @@ pub async fn new<const N_RX: usize, const N_TX: usize, SPI: SpiDevice, INT: Wait | |||
| 622 | .unwrap(); | 630 | .unwrap(); |
| 623 | } | 631 | } |
| 624 | 632 | ||
| 625 | // Config2: CRC_APPEND | 633 | // Check if the FCS is valid in the TX path. |
| 634 | let tx_fsc_validation_enable = true; | ||
| 635 | |||
| 636 | // Config0 | ||
| 637 | let mut config0 = Config0(0x0000_0006); | ||
| 638 | config0.set_txfcsve(tx_fsc_validation_enable); | ||
| 639 | mac.write_reg(sr::CONFIG0, config0.0).await.unwrap(); | ||
| 640 | |||
| 641 | // Config2 | ||
| 626 | let mut config2 = Config2(0x0000_0800); | 642 | let mut config2 = Config2(0x0000_0800); |
| 627 | config2.set_crc_append(true); | 643 | // crc_append must be disable if tx_fsc_validation_enable is true! |
| 644 | config2.set_crc_append(!tx_fsc_validation_enable); | ||
| 628 | mac.write_reg(sr::CONFIG2, config2.0).await.unwrap(); | 645 | mac.write_reg(sr::CONFIG2, config2.0).await.unwrap(); |
| 629 | 646 | ||
| 630 | // Pin Mux Config 1 | 647 | // Pin Mux Config 1 |
