core/arp: Add CHECK_REQUEST state to generate failed response if so and simplify FSM.

This commit is contained in:
Florent Kermarrec 2023-07-31 11:45:13 +02:00
parent 538a4e407c
commit f33d5b5959
1 changed files with 17 additions and 13 deletions

View File

@ -171,7 +171,7 @@ class LiteEthARPTable(LiteXModule):
request_counter = Signal(max=max_requests) request_counter = Signal(max=max_requests)
request_ip_address = Signal(32, reset_less=True) request_ip_address = Signal(32, reset_less=True)
self.request_timer = WaitTimer(int(100e-3*clk_freq)) self.request_timer = WaitTimer(100e-3*clk_freq)
self.comb += self.request_timer.wait.eq(request_pending) self.comb += self.request_timer.wait.eq(request_pending)
# Note: Store only 1 IP/MAC couple, can be improved with a real # Note: Store only 1 IP/MAC couple, can be improved with a real
@ -181,7 +181,7 @@ class LiteEthARPTable(LiteXModule):
cached_valid = Signal() cached_valid = Signal()
cached_ip_address = Signal(32, reset_less=True) cached_ip_address = Signal(32, reset_less=True)
cached_mac_address = Signal(48, reset_less=True) cached_mac_address = Signal(48, reset_less=True)
cached_timer = WaitTimer(int(100e-3*clk_freq)) cached_timer = WaitTimer(100e-3*clk_freq)
self.submodules += cached_timer self.submodules += cached_timer
self.sync += [ self.sync += [
If(cached_update, If(cached_update,
@ -198,16 +198,14 @@ class LiteEthARPTable(LiteXModule):
self.fsm = fsm = FSM(reset_state="IDLE") self.fsm = fsm = FSM(reset_state="IDLE")
fsm.act("IDLE", fsm.act("IDLE",
# Note: for simplicicy, if ARP table is busy response from arp_rx # Note: for simplicicy, if ARP table is busy response from arp_rx is lost. This is
# is lost. This is compensated by the protocol (retries) # compensated by the protocol (retries)
If(sink.valid & sink.request, If(sink.valid & sink.request,
NextState("SEND_REPLY") NextState("SEND_REPLY")
).Elif(sink.valid & sink.reply & request_pending, ).Elif(sink.valid & sink.reply & request_pending,
NextState("UPDATE_TABLE"), NextState("UPDATE_TABLE"),
).Elif(request_counter == (max_requests - 1),
NextState("PRESENT_RESPONSE")
).Elif(request.valid | self.request_timer.done, ).Elif(request.valid | self.request_timer.done,
NextState("CHECK_TABLE") NextState("CHECK_REQUEST")
) )
) )
fsm.act("SEND_REPLY", fsm.act("SEND_REPLY",
@ -222,7 +220,17 @@ class LiteEthARPTable(LiteXModule):
fsm.act("UPDATE_TABLE", fsm.act("UPDATE_TABLE",
NextValue(request_pending, 0), NextValue(request_pending, 0),
cached_update.eq(1), cached_update.eq(1),
NextState("CHECK_TABLE") NextState("CHECK_REQUEST")
)
fsm.act("CHECK_REQUEST",
If(request_counter == (max_requests - 1),
NextValue(response.failed, 1),
NextValue(request_counter, 0),
NextValue(request_pending, 0),
NextState("PRESENT_RESPONSE")
).Else(
NextState("CHECK_TABLE")
)
) )
fsm.act("CHECK_TABLE", fsm.act("CHECK_TABLE",
If(cached_valid, If(cached_valid,
@ -264,12 +272,8 @@ class LiteEthARPTable(LiteXModule):
fsm.act("PRESENT_RESPONSE", fsm.act("PRESENT_RESPONSE",
response.valid.eq(1), response.valid.eq(1),
response.mac_address.eq(cached_mac_address), response.mac_address.eq(cached_mac_address),
If(request_counter == (max_requests - 1),
response.failed.eq(1),
NextValue(request_counter, 0),
NextValue(request_pending, 0),
),
If(response.ready, If(response.ready,
NextValue(response.failed, 0),
NextState("IDLE") NextState("IDLE")
) )
) )