Skip to content

Commit

Permalink
fpga: Add netdev layer to testbenches
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Forencich <[email protected]>
  • Loading branch information
alexforencich committed Feb 22, 2024
1 parent a990b04 commit 7bc7aae
Show file tree
Hide file tree
Showing 39 changed files with 3,877 additions and 1,332 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -439,25 +439,23 @@ async def run_test_nic(dut):
tb.log.info("Init driver")
await tb.driver.init_pcie_dev(tb.rc.find_device(tb.dev.functions[0].pcie_id))
for interface in tb.driver.interfaces:
await interface.open()
await interface.ndevs[0].open()

# wait for all writes to complete
await tb.driver.hw_regs.read_dword(0)
tb.log.info("Init complete")

tb.log.info("Send and receive single packet")

for interface in tb.driver.interfaces:
data = bytearray([x % 256 for x in range(1024)])

await interface.start_xmit(data, 0)
await interface.ndevs[0].start_xmit(data, 0)

pkt = await tb.port_mac[interface.index*interface.port_count].tx.recv()
tb.log.info("Packet: %s", pkt)

await tb.port_mac[interface.index*interface.port_count].rx.send(pkt)

pkt = await interface.recv()
pkt = await interface.ndevs[0].recv()

tb.log.info("Packet: %s", pkt)
if interface.if_feature_rx_csum:
Expand All @@ -475,16 +473,16 @@ async def run_test_nic(dut):
test_pkt2 = test_pkt.copy()
test_pkt2[UDP].chksum = scapy.utils.checksum(bytes(test_pkt2[UDP]))

await tb.driver.interfaces[0].start_xmit(test_pkt2.build(), 0, 34, 6)
await tb.driver.interfaces[0].ndevs[0].start_xmit(test_pkt2.build(), 0, 34, 6)
else:
await tb.driver.interfaces[0].start_xmit(test_pkt.build(), 0)
await tb.driver.interfaces[0].ndevs[0].start_xmit(test_pkt.build(), 0)

pkt = await tb.port_mac[0].tx.recv()
tb.log.info("Packet: %s", pkt)

await tb.port_mac[0].rx.send(pkt)

pkt = await tb.driver.interfaces[0].recv()
pkt = await tb.driver.interfaces[0].ndevs[0].recv()

tb.log.info("Packet: %s", pkt)
if tb.driver.interfaces[0].if_feature_rx_csum:
Expand All @@ -498,20 +496,20 @@ async def run_test_nic(dut):
tb.loopback_enable = True

for k in range(4):
await tb.driver.interfaces[0].set_rx_queue_map_indir_table(0, 0, tb.driver.interfaces[0].rxq[k].index)
await tb.driver.interfaces[0].set_rx_queue_map_indir_table(0, 0, tb.driver.interfaces[0].ndevs[0].rxq[k].index)

await tb.driver.interfaces[0].start_xmit(data, 0)
await tb.driver.interfaces[0].ndevs[0].start_xmit(data, 0)

pkt = await tb.driver.interfaces[0].recv()
pkt = await tb.driver.interfaces[0].ndevs[0].recv()

tb.log.info("Packet: %s", pkt)
if tb.driver.interfaces[0].if_feature_rx_csum:
assert pkt.rx_checksum == ~scapy.utils.checksum(bytes(pkt.data[14:])) & 0xffff
assert pkt.queue == tb.driver.interfaces[0].rxq[k].index
assert pkt.queue == tb.driver.interfaces[0].ndevs[0].rxq[k].index

tb.loopback_enable = False

await tb.driver.interfaces[0].update_rx_queue_map_indir_table(0)
await tb.driver.interfaces[0].ndevs[0].update_rx_queue_map_indir_table()

tb.log.info("Queue mapping RSS mask test")

Expand All @@ -532,12 +530,12 @@ async def run_test_nic(dut):
test_pkt2 = test_pkt.copy()
test_pkt2[UDP].chksum = scapy.utils.checksum(bytes(test_pkt2[UDP]))

await tb.driver.interfaces[0].start_xmit(test_pkt2.build(), 0, 34, 6)
await tb.driver.interfaces[0].ndevs[0].start_xmit(test_pkt2.build(), 0, 34, 6)
else:
await tb.driver.interfaces[0].start_xmit(test_pkt.build(), 0)
await tb.driver.interfaces[0].ndevs[0].start_xmit(test_pkt.build(), 0)

for k in range(64):
pkt = await tb.driver.interfaces[0].recv()
pkt = await tb.driver.interfaces[0].ndevs[0].recv()

tb.log.info("Packet: %s", pkt)
if tb.driver.interfaces[0].if_feature_rx_csum:
Expand All @@ -560,10 +558,10 @@ async def run_test_nic(dut):
tb.loopback_enable = True

for p in pkts:
await tb.driver.interfaces[0].start_xmit(p, 0)
await tb.driver.interfaces[0].ndevs[0].start_xmit(p, 0)

for k in range(count):
pkt = await tb.driver.interfaces[0].recv()
pkt = await tb.driver.interfaces[0].ndevs[0].recv()

tb.log.info("Packet: %s", pkt)
assert pkt.data == pkts[k]
Expand All @@ -572,6 +570,26 @@ async def run_test_nic(dut):

tb.loopback_enable = False

tb.log.info("Multiple TX queues")

count = 1024

pkts = [bytearray([(x+k) % 256 for x in range(60)]) for k in range(count)]

tb.loopback_enable = True

for k in range(len(pkts)):
await tb.driver.interfaces[0].ndevs[0].start_xmit(pkts[k], k % tb.driver.interfaces[0].ndevs[0].txq_count)

for k in range(count):
pkt = await tb.driver.interfaces[0].ndevs[0].recv()

tb.log.info("Packet: %s", pkt)
if tb.driver.interfaces[0].if_feature_rx_csum:
assert pkt.rx_checksum == ~scapy.utils.checksum(bytes(pkt.data[14:])) & 0xffff

tb.loopback_enable = False

tb.log.info("Multiple large packets")

count = 64
Expand All @@ -581,10 +599,10 @@ async def run_test_nic(dut):
tb.loopback_enable = True

for p in pkts:
await tb.driver.interfaces[0].start_xmit(p, 0)
await tb.driver.interfaces[0].ndevs[0].start_xmit(p, 0)

for k in range(count):
pkt = await tb.driver.interfaces[0].recv()
pkt = await tb.driver.interfaces[0].ndevs[0].recv()

tb.log.info("Packet: %s", pkt)
assert pkt.data == pkts[k]
Expand All @@ -602,10 +620,10 @@ async def run_test_nic(dut):
tb.loopback_enable = True

for p in pkts:
await tb.driver.interfaces[0].start_xmit(p, 0)
await tb.driver.interfaces[0].ndevs[0].start_xmit(p, 0)

for k in range(count):
pkt = await tb.driver.interfaces[0].recv()
pkt = await tb.driver.interfaces[0].ndevs[0].recv()

tb.log.info("Packet: %s", pkt)
assert pkt.data == pkts[k]
Expand All @@ -624,10 +642,10 @@ async def run_test_nic(dut):
tb.loopback_enable = True

for k, p in enumerate(pkts):
await tb.driver.interfaces[k % len(tb.driver.interfaces)].start_xmit(p, 0)
await tb.driver.interfaces[k % len(tb.driver.interfaces)].ndevs[0].start_xmit(p, 0)

for k in range(count):
pkt = await tb.driver.interfaces[k % len(tb.driver.interfaces)].recv()
pkt = await tb.driver.interfaces[k % len(tb.driver.interfaces)].ndevs[0].recv()

tb.log.info("Packet: %s", pkt)
assert pkt.data == pkts[k]
Expand All @@ -636,21 +654,12 @@ async def run_test_nic(dut):

tb.loopback_enable = False

if len(tb.driver.interfaces[0].sched_blocks) > 1:
tb.log.info("All interface 0 scheduler blocks")
if len(tb.driver.interfaces[0].ndevs) > 1:
tb.log.info("All interface 0 netdevs")

for block in tb.driver.interfaces[0].sched_blocks:
await block.schedulers[0].set_ctrl(1)
await block.interface.set_rx_queue_map_rss_mask(block.index, 0x00000000)
await block.interface.set_rx_queue_map_indir_table(block.index, 0, block.interface.rxq[block.index].index)
for k in range(len(block.interface.txq)):
if k % len(block.interface.sched_blocks) == block.index:
await block.schedulers[0].hw_regs.write_dword(4*k, 0x00000003)
else:
await block.schedulers[0].hw_regs.write_dword(4*k, 0x00000000)

await block.interface.ports[block.index].set_tx_ctrl(mqnic.MQNIC_PORT_TX_CTRL_EN)
await block.interface.ports[block.index].set_rx_ctrl(mqnic.MQNIC_PORT_RX_CTRL_EN)
for ndev in tb.driver.interfaces[0].ndevs:
if not ndev.port_up:
await ndev.open()

count = 64

Expand All @@ -661,26 +670,18 @@ async def run_test_nic(dut):
queues = set()

for k, p in enumerate(pkts):
await tb.driver.interfaces[0].start_xmit(p, k % len(tb.driver.interfaces[0].sched_blocks))
await tb.driver.interfaces[0].ndevs[k % len(tb.driver.interfaces[0].ndevs)].start_xmit(p, 0)

for k in range(count):
pkt = await tb.driver.interfaces[0].recv()
pkt = await tb.driver.interfaces[0].ndevs[k % len(tb.driver.interfaces[0].ndevs)].recv()

tb.log.info("Packet: %s", pkt)
# assert pkt.data == pkts[k]
assert pkt.data == pkts[k]
if tb.driver.interfaces[0].if_feature_rx_csum:
assert pkt.rx_checksum == ~scapy.utils.checksum(bytes(pkt.data[14:])) & 0xffff

queues.add(pkt.queue)

assert len(queues) == len(tb.driver.interfaces[0].sched_blocks)

tb.loopback_enable = False

for block in tb.driver.interfaces[0].sched_blocks[1:]:
await block.schedulers[0].set_ctrl(0)
await tb.driver.interfaces[0].set_rx_queue_map_rss_mask(0, 0xffffffff)

if tb.driver.interfaces[0].if_feature_lfc:
tb.log.info("Test LFC pause frame RX")

Expand All @@ -698,10 +699,10 @@ async def run_test_nic(dut):
tb.loopback_enable = True

for p in pkts:
await tb.driver.interfaces[0].start_xmit(p, 0)
await tb.driver.interfaces[0].ndevs[0].start_xmit(p, 0)

for k in range(count):
pkt = await tb.driver.interfaces[0].recv()
pkt = await tb.driver.interfaces[0].ndevs[0].recv()

tb.log.info("Packet: %s", pkt)
assert pkt.data == pkts[k]
Expand Down
Loading

0 comments on commit 7bc7aae

Please sign in to comment.