Skip to content

Commit 81f80e4

Browse files
committed
Fix CIC bits in TX descriptor & enable more interrupts
1 parent 261a476 commit 81f80e4

File tree

4 files changed

+37
-23
lines changed

4 files changed

+37
-23
lines changed

src/dma/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,15 @@ impl<'rx, 'tx> EthernetDMA<'rx, 'tx> {
257257
// Transmit Interrupt Enable
258258
.tie()
259259
.set_bit()
260+
// Abnormal Interrupt Summary enable
261+
.aie()
262+
.set_bit()
263+
// Receive Buffer Unavailable
264+
.rbue()
265+
.set_bit()
266+
// Transmit Buffer Unavailable
267+
.tbue()
268+
.set_bit()
260269
});
261270

262271
// Enable ethernet interrupts
@@ -429,6 +438,10 @@ fn eth_interrupt_handler_impl(eth_dma: &ETHERNET_DMA) -> InterruptReasonSummary
429438
.set_bit()
430439
.ri()
431440
.set_bit()
441+
.rbu()
442+
.set_bit()
443+
.tbu()
444+
.set_bit()
432445
});
433446

434447
(

src/dma/rx/h_desc.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ mod consts {
5555
pub const RXDESC_3_LT_MASK: u32 = 0b111 << RXDESC_3_LT_SHIFT;
5656
/// Length/Type Field
5757
#[allow(non_camel_case_types)]
58-
#[repr(u8)]
58+
#[repr(u32)]
5959
pub enum RXDESC_3_LT {
60-
Length = 0b000,
61-
Type = 0b001,
62-
Reserved = 0b010,
63-
ArpRequest = 0b011,
64-
TypeWithVlan = 0b100,
65-
TypeWIthDoubleVlan = 0b101,
66-
MacControl = 0b110,
67-
Oam = 0b111,
60+
Length = 0b000 << RXDESC_3_LT_SHIFT,
61+
Type = 0b001 << RXDESC_3_LT_SHIFT,
62+
Reserved = 0b010 << RXDESC_3_LT_SHIFT,
63+
ArpRequest = 0b011 << RXDESC_3_LT_SHIFT,
64+
TypeWithVlan = 0b100 << RXDESC_3_LT_SHIFT,
65+
TypeWIthDoubleVlan = 0b101 << RXDESC_3_LT_SHIFT,
66+
MacControl = 0b110 << RXDESC_3_LT_SHIFT,
67+
Oam = 0b111 << RXDESC_3_LT_SHIFT,
6868
}
6969

7070
/// Error Summary
@@ -162,10 +162,6 @@ impl RxDescriptor {
162162
.modify(3, |w| w | RXDESC_3_OWN | RXDESC_3_IOC);
163163
}
164164

165-
cortex_m::asm::dsb();
166-
167-
assert!(self.is_owned());
168-
169165
// Used to flush the store buffer as fast as possible to make the buffer available for the
170166
// DMA.
171167
#[cfg(feature = "fence")]

src/dma/rx/mod.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ impl<'data> RxRing<'data, Running> {
216216

217217
let entry = self.next_entry;
218218
let entries_len = self.ring.len();
219+
219220
let (descriptor, buffer) = self.ring.get(entry);
220221

221222
let mut res = descriptor.take_received(packet_id, buffer);
@@ -226,20 +227,18 @@ impl<'data> RxRing<'data, Running> {
226227

227228
#[cfg(all(feature = "ptp", feature = "stm32h7xx-hal"))]
228229
let (timestamp, descriptor, buffer) = {
229-
if res.as_mut().err() != Some(&mut RxError::WouldBlock) {
230+
if res.is_ok() {
230231
let desc_has_timestamp = descriptor.has_timestamp();
231232

232233
drop(descriptor);
233234
drop(buffer);
234235

235236
// On H7's, the timestamp is stored in the next Context
236237
// descriptor.
238+
let (ctx_descriptor, ctx_des_buffer) = self.ring.get(self.next_entry);
239+
237240
let timestamp = if desc_has_timestamp {
238-
let (ctx_descriptor, ctx_des_buffer) = self.ring.get(self.next_entry);
239241
if let Some(timestamp) = ctx_descriptor.read_timestamp() {
240-
ctx_descriptor.set_owned(ctx_des_buffer);
241-
// Advance over this buffer
242-
self.next_entry = (self.next_entry + 1) % entries_len;
243242
Some(timestamp)
244243
} else {
245244
None
@@ -248,6 +247,12 @@ impl<'data> RxRing<'data, Running> {
248247
None
249248
};
250249

250+
if !ctx_descriptor.is_owned() {
251+
// Advance over this buffer
252+
self.next_entry = (self.next_entry + 1) % entries_len;
253+
ctx_descriptor.set_owned(&ctx_des_buffer);
254+
}
255+
251256
let (descriptor, buffer) = self.ring.get(entry);
252257

253258
descriptor.attach_timestamp(timestamp);

src/dma/tx/h_desc.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@ mod consts {
6868
#[repr(u32)]
6969
#[allow(non_camel_case_types)]
7070
pub enum TXDESC_3_CIC {
71-
Disabled = 0b00,
72-
IpHeaderOnly = 0b01,
73-
IpHeaderAndPayloadOnly = 0b10,
74-
IpHeaderAndPayloadAndPseudoHeader = 0b11,
71+
Disabled = 0b00 << TXDESC_3_CIC_SHIFT,
72+
IpHeaderOnly = 0b01 << TXDESC_3_CIC_SHIFT,
73+
IpHeaderAndPayloadOnly = 0b10 << TXDESC_3_CIC_SHIFT,
74+
IpHeaderAndPayloadAndPseudoHeader = 0b11 << TXDESC_3_CIC_SHIFT,
7575
}
7676
/// Checksum Insertion Control mask
7777
pub const TXDESC_3_CIC_MASK: u32 = 0b11 << TXDESC_3_CIC_SHIFT;
@@ -192,7 +192,7 @@ impl TxDescriptor {
192192

193193
self.inner_raw.modify(3, |w| {
194194
w | TXDESC_3_OWN
195-
| TXDESC_3_CIC::IpHeaderAndPayloadOnly as u32
195+
| TXDESC_3_CIC::IpHeaderAndPayloadAndPseudoHeader as u32
196196
| TXDESC_3_FD
197197
| TXDESC_3_LD
198198
| tx_len

0 commit comments

Comments
 (0)