eth: Use shared counter for fractional part of pause quanta

Signed-off-by: Alex Forencich <alex@alexforencich.com>
This commit is contained in:
Alex Forencich
2025-04-26 20:02:35 -07:00
parent 3dc7e4821d
commit 8dc33f3a44
10 changed files with 75 additions and 47 deletions

View File

@@ -81,8 +81,11 @@ if (MCF_PARAMS_SIZE < (PFC_EN ? 18 : 2))
logic lfc_req_reg = 1'b0, lfc_req_next; logic lfc_req_reg = 1'b0, lfc_req_next;
logic [7:0] pfc_req_reg = 8'd0, pfc_req_next; logic [7:0] pfc_req_reg = 8'd0, pfc_req_next;
logic [QW+QFB-1:0] lfc_quanta_reg = '0, lfc_quanta_next; logic [QFB-1:0] quanta_cnt_reg = '0, quanta_cnt_next;
logic [QW+QFB-1:0] pfc_quanta_reg[0:7], pfc_quanta_next[0:7]; logic [1:0] quanta_inc_reg = '0, quanta_inc_next;
logic [QW-1:0] lfc_quanta_reg = '0, lfc_quanta_next;
logic [QW-1:0] pfc_quanta_reg[8], pfc_quanta_next[8];
logic stat_rx_lfc_pkt_reg = 1'b0, stat_rx_lfc_pkt_next; logic stat_rx_lfc_pkt_reg = 1'b0, stat_rx_lfc_pkt_next;
logic stat_rx_lfc_xon_reg = 1'b0, stat_rx_lfc_xon_next; logic stat_rx_lfc_xon_reg = 1'b0, stat_rx_lfc_xon_next;
@@ -117,9 +120,15 @@ always_comb begin
stat_rx_pfc_xon_next = '0; stat_rx_pfc_xon_next = '0;
stat_rx_pfc_xoff_next = '0; stat_rx_pfc_xoff_next = '0;
if (cfg_quanta_clk_en && rx_lfc_ack) begin quanta_cnt_next = quanta_cnt_reg;
if (lfc_quanta_reg > (QW+QFB)'(cfg_quanta_step)) begin quanta_inc_next = 0;
lfc_quanta_next = lfc_quanta_reg - (QW+QFB)'(cfg_quanta_step); if (cfg_quanta_clk_en) begin
{quanta_inc_next, quanta_cnt_next} = (2+QFB)'(quanta_cnt_reg) + cfg_quanta_step;
end
if (rx_lfc_ack) begin
if (lfc_quanta_reg >= QW'(quanta_inc_reg)) begin
lfc_quanta_next = lfc_quanta_reg - QW'(quanta_inc_reg);
end else begin end else begin
lfc_quanta_next = '0; lfc_quanta_next = '0;
end end
@@ -130,9 +139,9 @@ always_comb begin
lfc_req_next = (lfc_quanta_reg != 0) && rx_lfc_en && cfg_rx_lfc_en; lfc_req_next = (lfc_quanta_reg != 0) && rx_lfc_en && cfg_rx_lfc_en;
for (integer k = 0; k < 8; k = k + 1) begin for (integer k = 0; k < 8; k = k + 1) begin
if (cfg_quanta_clk_en && rx_pfc_ack[k]) begin if (rx_pfc_ack[k]) begin
if (pfc_quanta_reg[k] > (QW+QFB)'(cfg_quanta_step)) begin if (pfc_quanta_reg[k] >= QW'(quanta_inc_reg)) begin
pfc_quanta_next[k] = pfc_quanta_reg[k] - (QW+QFB)'(cfg_quanta_step); pfc_quanta_next[k] = pfc_quanta_reg[k] - QW'(quanta_inc_reg);
end else begin end else begin
pfc_quanta_next[k] = '0; pfc_quanta_next[k] = '0;
end end
@@ -148,14 +157,14 @@ always_comb begin
stat_rx_lfc_pkt_next = 1'b1; stat_rx_lfc_pkt_next = 1'b1;
stat_rx_lfc_xon_next = {mcf_params[7:0], mcf_params[15:8]} == 0; stat_rx_lfc_xon_next = {mcf_params[7:0], mcf_params[15:8]} == 0;
stat_rx_lfc_xoff_next = {mcf_params[7:0], mcf_params[15:8]} != 0; stat_rx_lfc_xoff_next = {mcf_params[7:0], mcf_params[15:8]} != 0;
lfc_quanta_next = {mcf_params[7:0], mcf_params[15:8], {QFB{1'b0}}}; lfc_quanta_next = {mcf_params[7:0], mcf_params[15:8]};
end else if (PFC_EN && mcf_opcode == cfg_rx_pfc_opcode && cfg_rx_pfc_en) begin end else if (PFC_EN && mcf_opcode == cfg_rx_pfc_opcode && cfg_rx_pfc_en) begin
stat_rx_pfc_pkt_next = 1'b1; stat_rx_pfc_pkt_next = 1'b1;
for (integer k = 0; k < 8; k = k + 1) begin for (integer k = 0; k < 8; k = k + 1) begin
if (mcf_params[k+8]) begin if (mcf_params[k+8]) begin
stat_rx_pfc_xon_next[k] = {mcf_params[16+(k*QW)+0 +: 8], mcf_params[16+(k*QW)+8 +: 8]} == 0; stat_rx_pfc_xon_next[k] = {mcf_params[16+(k*QW)+0 +: 8], mcf_params[16+(k*QW)+8 +: 8]} == 0;
stat_rx_pfc_xoff_next[k] = {mcf_params[16+(k*QW)+0 +: 8], mcf_params[16+(k*QW)+8 +: 8]} != 0; stat_rx_pfc_xoff_next[k] = {mcf_params[16+(k*QW)+0 +: 8], mcf_params[16+(k*QW)+8 +: 8]} != 0;
pfc_quanta_next[k] = {mcf_params[16+(k*QW)+0 +: 8], mcf_params[16+(k*QW)+8 +: 8], {QFB{1'b0}}}; pfc_quanta_next[k] = {mcf_params[16+(k*QW)+0 +: 8], mcf_params[16+(k*QW)+8 +: 8]};
end end
end end
end end
@@ -166,6 +175,9 @@ always_ff @(posedge clk) begin
lfc_req_reg <= lfc_req_next; lfc_req_reg <= lfc_req_next;
pfc_req_reg <= pfc_req_next; pfc_req_reg <= pfc_req_next;
quanta_cnt_reg <= quanta_cnt_next;
quanta_inc_reg <= quanta_inc_next;
lfc_quanta_reg <= lfc_quanta_next; lfc_quanta_reg <= lfc_quanta_next;
for (integer k = 0; k < 8; k = k + 1) begin for (integer k = 0; k < 8; k = k + 1) begin
pfc_quanta_reg[k] <= pfc_quanta_next[k]; pfc_quanta_reg[k] <= pfc_quanta_next[k];

View File

@@ -95,8 +95,11 @@ logic [7:0] pfc_act_reg = 8'd0, pfc_act_next;
logic [7:0] pfc_en_reg = 8'd0, pfc_en_next; logic [7:0] pfc_en_reg = 8'd0, pfc_en_next;
logic pfc_send_reg = 1'b0, pfc_send_next; logic pfc_send_reg = 1'b0, pfc_send_next;
logic [QW+QFB-1:0] lfc_refresh_reg = '0, lfc_refresh_next; logic [QFB-1:0] quanta_cnt_reg = '0, quanta_cnt_next;
logic [QW+QFB-1:0] pfc_refresh_reg[0:7], pfc_refresh_next[0:7]; logic [1:0] quanta_inc_reg = '0, quanta_inc_next;
logic [QW-1:0] lfc_refresh_reg = '0, lfc_refresh_next;
logic [QW-1:0] pfc_refresh_reg[8], pfc_refresh_next[8];
logic stat_tx_lfc_pkt_reg = 1'b0, stat_tx_lfc_pkt_next; logic stat_tx_lfc_pkt_reg = 1'b0, stat_tx_lfc_pkt_next;
logic stat_tx_lfc_xon_reg = 1'b0, stat_tx_lfc_xon_next; logic stat_tx_lfc_xon_reg = 1'b0, stat_tx_lfc_xon_next;
@@ -168,31 +171,29 @@ always_comb begin
stat_tx_pfc_xon_next = '0; stat_tx_pfc_xon_next = '0;
stat_tx_pfc_xoff_next = '0; stat_tx_pfc_xoff_next = '0;
quanta_cnt_next = quanta_cnt_reg;
quanta_inc_next = 0;
if (cfg_quanta_clk_en) begin if (cfg_quanta_clk_en) begin
if (lfc_refresh_reg > (QW+QFB)'(cfg_quanta_step)) begin {quanta_inc_next, quanta_cnt_next} = (2+QFB)'(quanta_cnt_reg) + cfg_quanta_step;
lfc_refresh_next = lfc_refresh_reg - (QW+QFB)'(cfg_quanta_step); end
end else begin
lfc_refresh_next = '0; if (lfc_refresh_reg >= QW'(quanta_inc_reg)) begin
if (lfc_req_reg) begin lfc_refresh_next = lfc_refresh_reg - QW'(quanta_inc_reg);
lfc_send_next = 1'b1;
end
end
end else begin end else begin
lfc_refresh_next = lfc_refresh_reg; lfc_refresh_next = '0;
if (lfc_req_reg) begin
lfc_send_next = 1'b1;
end
end end
for (integer k = 0; k < 8; k = k + 1) begin for (integer k = 0; k < 8; k = k + 1) begin
if (cfg_quanta_clk_en) begin if (pfc_refresh_reg[k] >= QW'(quanta_inc_reg)) begin
if (pfc_refresh_reg[k] > (QW+QFB)'(cfg_quanta_step)) begin pfc_refresh_next[k] = pfc_refresh_reg[k] - QW'(quanta_inc_reg);
pfc_refresh_next[k] = pfc_refresh_reg[k] - (QW+QFB)'(cfg_quanta_step);
end else begin
pfc_refresh_next[k] = 0;
if (pfc_req_reg[k]) begin
pfc_send_next = 1'b1;
end
end
end else begin end else begin
pfc_refresh_next[k] = pfc_refresh_reg[k]; pfc_refresh_next[k] = '0;
if (pfc_req_reg[k]) begin
pfc_send_next = 1'b1;
end
end end
end end
@@ -208,7 +209,7 @@ always_comb begin
mcf_pfc_sel_next = 1'b0; mcf_pfc_sel_next = 1'b0;
mcf_valid_next = lfc_act_reg; mcf_valid_next = lfc_act_reg;
lfc_act_next = lfc_req_reg; lfc_act_next = lfc_req_reg;
lfc_refresh_next = lfc_req_reg ? {cfg_tx_lfc_refresh, {QFB{1'b0}}} : '0; lfc_refresh_next = lfc_req_reg ? cfg_tx_lfc_refresh : '0;
lfc_send_next = 1'b0; lfc_send_next = 1'b0;
stat_tx_lfc_pkt_next = lfc_act_reg; stat_tx_lfc_pkt_next = lfc_act_reg;
@@ -232,7 +233,7 @@ always_comb begin
pfc_en_next = pfc_act_reg; pfc_en_next = pfc_act_reg;
pfc_act_next = pfc_req_reg; pfc_act_next = pfc_req_reg;
for (integer k = 0; k < 8; k = k + 1) begin for (integer k = 0; k < 8; k = k + 1) begin
pfc_refresh_next[k] = pfc_req_reg[k] ? {cfg_tx_pfc_refresh[k], {QFB{1'b0}}} : '0; pfc_refresh_next[k] = pfc_req_reg[k] ? cfg_tx_pfc_refresh[k] : '0;
end end
pfc_send_next = 1'b0; pfc_send_next = 1'b0;
@@ -256,6 +257,9 @@ always_ff @(posedge clk) begin
mcf_pfc_sel_reg <= mcf_pfc_sel_next; mcf_pfc_sel_reg <= mcf_pfc_sel_next;
mcf_valid_reg <= mcf_valid_next; mcf_valid_reg <= mcf_valid_next;
quanta_cnt_reg <= quanta_cnt_next;
quanta_inc_reg <= quanta_inc_next;
lfc_refresh_reg <= lfc_refresh_next; lfc_refresh_reg <= lfc_refresh_next;
for (integer k = 0; k < 8; k = k + 1) begin for (integer k = 0; k < 8; k = k + 1) begin
pfc_refresh_reg[k] <= pfc_refresh_next[k]; pfc_refresh_reg[k] <= pfc_refresh_next[k];

View File

@@ -607,6 +607,8 @@ async def run_test_pfc(dut, ifg=12):
test_frame = XgmiiFrame.from_payload(bytes(test_pkt)) test_frame = XgmiiFrame.from_payload(bytes(test_pkt))
await tb.xgmii_source.send(test_frame) await tb.xgmii_source.send(test_frame)
dut.rx_pfc_ack.value = 0xff
for i in range(8): for i in range(8):
for k in range(200): for k in range(200):
await RisingEdge(dut.tx_clk) await RisingEdge(dut.tx_clk)

View File

@@ -623,7 +623,7 @@ async def run_test_pfc(dut, ifg=12, enable_gen=None, mii_sel=True):
dut.tx_pfc_req.value = 0x00 dut.tx_pfc_req.value = 0x00
dut.tx_pfc_resend.value = 0 dut.tx_pfc_resend.value = 0
dut.rx_pfc_en.value = 0xff dut.rx_pfc_en.value = 0xff
dut.rx_pfc_ack.value = 0 dut.rx_pfc_ack.value = 0x00
dut.tx_lfc_pause_en.value = 0 dut.tx_lfc_pause_en.value = 0
dut.tx_pause_req.value = 0 dut.tx_pause_req.value = 0
@@ -682,6 +682,8 @@ async def run_test_pfc(dut, ifg=12, enable_gen=None, mii_sel=True):
test_frame = GmiiFrame.from_payload(bytes(test_pkt)) test_frame = GmiiFrame.from_payload(bytes(test_pkt))
await tb.gmii_source.send(test_frame) await tb.gmii_source.send(test_frame)
dut.rx_pfc_ack.value = 0xff
for i in range(8): for i in range(8):
for k in range(500): for k in range(500):
await RisingEdge(dut.tx_clk) await RisingEdge(dut.tx_clk)

View File

@@ -487,7 +487,7 @@ async def run_test_pfc(dut, ifg=12, speed=1000e6):
dut.tx_pfc_req.value = 0x00 dut.tx_pfc_req.value = 0x00
dut.tx_pfc_resend.value = 0 dut.tx_pfc_resend.value = 0
dut.rx_pfc_en.value = 0xff dut.rx_pfc_en.value = 0xff
dut.rx_pfc_ack.value = 0 dut.rx_pfc_ack.value = 0x00
dut.tx_lfc_pause_en.value = 0 dut.tx_lfc_pause_en.value = 0
dut.tx_pause_req.value = 0 dut.tx_pause_req.value = 0
@@ -546,6 +546,8 @@ async def run_test_pfc(dut, ifg=12, speed=1000e6):
test_frame = GmiiFrame.from_payload(bytes(test_pkt)) test_frame = GmiiFrame.from_payload(bytes(test_pkt))
await tb.gmii_phy.rx.send(test_frame) await tb.gmii_phy.rx.send(test_frame)
dut.rx_pfc_ack.value = 0xff
for i in range(8): for i in range(8):
for k in range(500): for k in range(500):
await RisingEdge(dut.tx_clk) await RisingEdge(dut.tx_clk)

View File

@@ -490,7 +490,7 @@ async def run_test_pfc(dut, ifg=12, speed=1000e6):
dut.tx_pfc_req.value = 0x00 dut.tx_pfc_req.value = 0x00
dut.tx_pfc_resend.value = 0 dut.tx_pfc_resend.value = 0
dut.rx_pfc_en.value = 0xff dut.rx_pfc_en.value = 0xff
dut.rx_pfc_ack.value = 0 dut.rx_pfc_ack.value = 0x00
dut.tx_lfc_pause_en.value = 0 dut.tx_lfc_pause_en.value = 0
dut.tx_pause_req.value = 0 dut.tx_pause_req.value = 0
@@ -549,6 +549,8 @@ async def run_test_pfc(dut, ifg=12, speed=1000e6):
test_frame = GmiiFrame.from_payload(bytes(test_pkt)) test_frame = GmiiFrame.from_payload(bytes(test_pkt))
await tb.rgmii_phy.rx.send(test_frame) await tb.rgmii_phy.rx.send(test_frame)
dut.rx_pfc_ack.value = 0xff
for i in range(8): for i in range(8):
for k in range(500): for k in range(500):
await RisingEdge(dut.rx_clk) await RisingEdge(dut.rx_clk)

View File

@@ -451,7 +451,7 @@ async def run_test_pfc(dut, ifg=12, speed=1000e6):
dut.tx_pfc_req.value = 0x00 dut.tx_pfc_req.value = 0x00
dut.tx_pfc_resend.value = 0 dut.tx_pfc_resend.value = 0
dut.rx_pfc_en.value = 0xff dut.rx_pfc_en.value = 0xff
dut.rx_pfc_ack.value = 0 dut.rx_pfc_ack.value = 0x00
dut.tx_lfc_pause_en.value = 0 dut.tx_lfc_pause_en.value = 0
dut.tx_pause_req.value = 0 dut.tx_pause_req.value = 0
@@ -510,6 +510,8 @@ async def run_test_pfc(dut, ifg=12, speed=1000e6):
test_frame = GmiiFrame.from_payload(bytes(test_pkt)) test_frame = GmiiFrame.from_payload(bytes(test_pkt))
await tb.mii_phy.rx.send(test_frame) await tb.mii_phy.rx.send(test_frame)
dut.rx_pfc_ack.value = 0xff
for i in range(8): for i in range(8):
for k in range(500): for k in range(500):
await RisingEdge(dut.tx_clk) await RisingEdge(dut.tx_clk)

View File

@@ -668,6 +668,8 @@ async def run_test_pfc(dut, ifg=12):
test_frame = XgmiiFrame.from_payload(bytes(test_pkt)) test_frame = XgmiiFrame.from_payload(bytes(test_pkt))
await tb.serdes_source.send(test_frame) await tb.serdes_source.send(test_frame)
dut.rx_pfc_ack.value = 0xff
for i in range(8): for i in range(8):
for k in range(200): for k in range(200):
await RisingEdge(dut.tx_clk) await RisingEdge(dut.tx_clk)

View File

@@ -121,7 +121,7 @@ async def run_test_lfc(dut):
tb.log.info("pause time : %g s", pause_time) tb.log.info("pause time : %g s", pause_time)
tb.log.info("pause quanta : %f", pause_quanta) tb.log.info("pause quanta : %f", pause_quanta)
assert round(pause_quanta) == 100 assert round(pause_quanta/4) == 100//4
tb.log.info("Test release time accuracy (with refresh)") tb.log.info("Test release time accuracy (with refresh)")
eth = Ether(src='5A:51:52:53:54:55', dst='01:80:C2:00:00:01', type=0x8808) eth = Ether(src='5A:51:52:53:54:55', dst='01:80:C2:00:00:01', type=0x8808)
@@ -151,7 +151,7 @@ async def run_test_lfc(dut):
tb.log.info("pause time : %g s", pause_time) tb.log.info("pause time : %g s", pause_time)
tb.log.info("pause quanta : %f", pause_quanta) tb.log.info("pause quanta : %f", pause_quanta)
assert round(pause_quanta) == 100 assert round(pause_quanta/4) == 100//4
tb.log.info("Test explicit release") tb.log.info("Test explicit release")
eth = Ether(src='5A:51:52:53:54:55', dst='01:80:C2:00:00:01', type=0x8808) eth = Ether(src='5A:51:52:53:54:55', dst='01:80:C2:00:00:01', type=0x8808)
@@ -230,7 +230,7 @@ async def run_test_pfc(dut):
tb.log.info("pause time : %g s", pause_time) tb.log.info("pause time : %g s", pause_time)
tb.log.info("pause quanta : %f", pause_quanta) tb.log.info("pause quanta : %f", pause_quanta)
assert round(pause_quanta) == 100 assert round(pause_quanta/4) == 100//4
tb.log.info("Test release time accuracy (with refresh)") tb.log.info("Test release time accuracy (with refresh)")
eth = Ether(src='5A:51:52:53:54:55', dst='01:80:C2:00:00:01', type=0x8808) eth = Ether(src='5A:51:52:53:54:55', dst='01:80:C2:00:00:01', type=0x8808)
@@ -260,7 +260,7 @@ async def run_test_pfc(dut):
tb.log.info("pause time : %g s", pause_time) tb.log.info("pause time : %g s", pause_time)
tb.log.info("pause quanta : %f", pause_quanta) tb.log.info("pause quanta : %f", pause_quanta)
assert round(pause_quanta) == 100 assert round(pause_quanta/4) == 100//4
tb.log.info("Test explicit release") tb.log.info("Test explicit release")
eth = Ether(src='5A:51:52:53:54:55', dst='01:80:C2:00:00:01', type=0x8808) eth = Ether(src='5A:51:52:53:54:55', dst='01:80:C2:00:00:01', type=0x8808)
@@ -316,7 +316,7 @@ async def run_test_pfc(dut):
tb.log.info("pause time : %g s", pause_time) tb.log.info("pause time : %g s", pause_time)
tb.log.info("pause quanta : %f", pause_quanta) tb.log.info("pause quanta : %f", pause_quanta)
assert round(pause_quanta) == (k+1)*10 assert round(pause_quanta/4) == (k+1)*10//4
dut.rx_pfc_ack.value = 0 dut.rx_pfc_ack.value = 0
@@ -358,7 +358,7 @@ async def run_test_pfc(dut):
tb.log.info("pause time : %g s", pause_time) tb.log.info("pause time : %g s", pause_time)
tb.log.info("pause quanta : %f", pause_quanta) tb.log.info("pause quanta : %f", pause_quanta)
assert round(pause_quanta) == 100 assert round(pause_quanta/4) == 100//4
await RisingEdge(dut.clk) await RisingEdge(dut.clk)
await RisingEdge(dut.clk) await RisingEdge(dut.clk)

View File

@@ -143,7 +143,7 @@ async def run_test_lfc(dut):
tb.log.info("refresh time : %g s", refresh_time) tb.log.info("refresh time : %g s", refresh_time)
tb.log.info("refresh quanta : %f", refresh_quanta) tb.log.info("refresh quanta : %f", refresh_quanta)
assert round(refresh_quanta) == 100 assert round(refresh_quanta/4) == 100//4
start_time = get_sim_time('sec') start_time = get_sim_time('sec')
@@ -216,7 +216,7 @@ async def run_test_pfc(dut):
tb.log.info("refresh time : %g s", refresh_time) tb.log.info("refresh time : %g s", refresh_time)
tb.log.info("refresh quanta : %f", refresh_quanta) tb.log.info("refresh quanta : %f", refresh_quanta)
assert round(refresh_quanta) == 100 assert round(refresh_quanta/4) == 100//4
start_time = get_sim_time('sec') start_time = get_sim_time('sec')
@@ -248,7 +248,7 @@ async def run_test_pfc(dut):
tb.log.info("refresh time : %g s", refresh_time) tb.log.info("refresh time : %g s", refresh_time)
tb.log.info("refresh quanta : %f", refresh_quanta) tb.log.info("refresh quanta : %f", refresh_quanta)
assert round(refresh_quanta) == 100 assert round(refresh_quanta/4) == 100//4
start_time = get_sim_time('sec') start_time = get_sim_time('sec')
@@ -301,7 +301,7 @@ async def run_test_pfc(dut):
tb.log.info("refresh time : %g s", refresh_time) tb.log.info("refresh time : %g s", refresh_time)
tb.log.info("refresh quanta : %f", refresh_quanta) tb.log.info("refresh quanta : %f", refresh_quanta)
assert round(refresh_quanta) == 100 assert round(refresh_quanta/4) == 100//4
start_time = get_sim_time('sec') start_time = get_sim_time('sec')