Skip to content

Commit

Permalink
add more tests and make sure they pass, add stop() support to app
Browse files Browse the repository at this point in the history
  • Loading branch information
petebristow committed Mar 3, 2019
1 parent ee2c688 commit 19b6164
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 48 deletions.
2 changes: 2 additions & 0 deletions src/apps/intel_avf/README.md
Expand Up @@ -40,3 +40,5 @@ echo 2 > /sys/bus/pci/devices/0000\:03\:00.1/sriov_numvfs
ip link set up dev enp3s0f1
ip link set enp3s0f1 vf 0 mac 02:00:00:00:00:01
ip link set enp3s0f1 vf 0 vlan 10

A more complete example can be found in apps/intel_avf/tests/setup.sh
37 changes: 30 additions & 7 deletions src/apps/intel_avf/intel_avf.lua
Expand Up @@ -294,6 +294,7 @@ function Intel_avf:mbox_setup_txq()
self.r.VF_ATQH(0)
self.r.VF_ATQT(0)
self.mbox.next_send_idx = 0
C.full_memory_barrier()

-- set length and enable the queue
self.r.VF_ATQLEN(bits({ ENABLE = 31 }) + self.mbox.q_len)
Expand Down Expand Up @@ -471,7 +472,6 @@ end

function Intel_avf:mbox_send(opcode, datalen)
local idx = self.mbox.next_send_idx
self.mbox.tmp_idx = idx
self.mbox.next_send_idx = ( idx + 1 ) % self.mbox.q_len

self.mbox.txq[idx].flags0 = 0
Expand All @@ -482,23 +482,28 @@ function Intel_avf:mbox_send(opcode, datalen)
self.mbox.txq[idx].flags0 =
bit.bor(self.mbox.txq[idx].flags0, bits({ LARGE_BUFFER = 1 }))
end
self.mbox.txq[idx].flags1
= bits({ INDIRECT_BUFFER = 2, BUFFER = 4, NO_INTERRUPTS = 5 })
if datalen > 0 then
self.mbox.txq[idx].flags1
= bits({ INDIRECT_BUFFER = 2, BUFFER = 4, NO_INTERRUPTS = 5 })
self.mbox.txq[idx].data_addr_high = tophysical(self.mbox.send_buf) / 2^32
self.mbox.txq[idx].data_addr_low = tophysical(self.mbox.send_buf) % 2^32
else
self.mbox.txq[idx].flags1 = bits({ NO_INTERRUPTS = 5 })
end
self.mbox.txq[idx].datalen = datalen
self.mbox.txq[idx].cookie_high = opcode
self.mbox.txq[idx].data_addr_high = tophysical(self.mbox.send_buf) / 2^32
self.mbox.txq[idx].data_addr_low = tophysical(self.mbox.send_buf) % 2^32

C.full_memory_barrier()

self.r.VF_ATQT(self.mbox.next_send_idx)

local idx = self.mbox.tmp_idx
self.mbox.tmp_idx = nil
lib.waitfor(function()
return self.r.VF_ATQT() == self.mbox.next_send_idx
end)
lib.waitfor(function()
-- 1 == bits({ DescriptorDone = 0 })
-- 2 == bits({ Complete = 1 })

return band(self.mbox.txq[idx].flags0, 1) == 1 and
band(self.mbox.txq[idx].flags0, 2) == 2
end)
Expand Down Expand Up @@ -639,8 +644,19 @@ function Intel_avf:new(conf)
pci.set_bus_master(self.pciaddress, true)
pci.disable_bus_master_cleanup(self.pciaddress)

-- wait for the nic to be ready, setup the mailbox and then reset it
-- that way it doesn't matter what state you where given the card
self:wait_for_vfgen_rstat()
self:mbox_setup()
self:stop()

-- FIXME
-- I haven't worked out why the sleep is required but without it
-- self_mbox_set_version hangs indefinitely
C.sleep(1)

-- setup the nic for real
self:mbox_setup()
self:mbox_sr_version()
self:mbox_sr_caps()
self:init_tx_q()
Expand All @@ -655,6 +671,13 @@ function Intel_avf:new(conf)
return self
end

function Intel_avf:stop()
self:mbox_send(self.mbox.opcodes['VIRTCHNL_OP_RESET_VF'], 0)
self.r.VF_ARQLEN(0)
self.r.VF_ATQLEN(0)
self:wait_for_vfgen_rstat()
end

function Intel_avf:init_irq()
local intv = bit.lshift(20, 5)
local v = bit.bor(bits({ ENABLE = 0, CLEARPBA = 1, ITR0 = 3, ITR1 = 4}), intv)
Expand Down
26 changes: 16 additions & 10 deletions src/apps/intel_avf/tests/back2back/test.snabb
@@ -1,9 +1,9 @@
#!../../../../snabb snsh
local vf0 = os.getenv("SNABB_AVF_VF0")
local vf1 = os.getenv("SNABB_AVF_VF1")
local vf0 = os.getenv("SNABB_AVF_PF0_VF0")
local vf1 = os.getenv("SNABB_AVF_PF1_VF0")

assert(vf0 ~= nil, "SNABB_AVF_VF0 is nil")
assert(vf1 ~= nil, "SNABB_AVF_VF0 is nil")
assert(vf0 ~= nil, "SNABB_AVF_PF0_VF0 is nil")
assert(vf1 ~= nil, "SNABB_AVF_PF1_VF0 is nil")

-- 1001 is an important test case, descriptors are written back in sets of 4
-- 1001, exercises the interrupt driven write back
Expand All @@ -18,7 +18,7 @@ local counter = require("core.counter")

local c = config.new()
local src="02:00:00:00:00:00"
local dst="02:00:00:00:00:01"
local dst="02:00:00:00:00:10"
config.app(c, "synth", synth.Synth, {
sizes = {64,128,192,256,384,512,1024},
src=src,
Expand All @@ -44,17 +44,23 @@ engine.main({duration = 3, report = false})
function rx(l1, l2)
return counter.read(engine.link_table[l1 .. " -> " .. l2].stats.rxpackets)
end
assert(rx("tee.output1", "nic0.input") ==
rx("nic1.output", "match.rx"), "packets sent != packets recv")
function assert_eq(a,b,msg)
local an = tonumber(a)
local bn = tonumber(b)
assert(an == bn, msg .. " " .. an .. " ~= " .. bn)
end

local s = rx("tee.output1", "nic0.input")
local r = rx("nic1.output", "match.rx")
assert_eq(s, r, "packets_sr_1")

local n0 = engine.app_table['nic0']
local n1 = engine.app_table['nic1']
n0:mbox_sr_stats()
n1:mbox_sr_stats()

assert(counter.read(n0.shm.tx_unicast) == counter.read(n1.shm.rx_unicast), "mbox_sr_stats counters dont match")
assert(counter.read(n0.shm.tx_unicast) == packet_count, "mbox_sr_stats.tx_unicast != packet_count")
assert_eq(counter.read(n0.shm.tx_unicast), counter.read(n1.shm.rx_unicast), "mxbox_sr_stats_1")
assert_eq(counter.read(n0.shm.tx_unicast), packet_count, "mbox_sr_stats_2")

local c = config.new()
config.app(c, "synth", synth.Synth, {
Expand All @@ -76,5 +82,5 @@ while true do
end
engine.main({ duration = 1, no_report = true })
end

engine.stop()
main.exit(0)
68 changes: 37 additions & 31 deletions src/apps/intel_avf/tests/setup.sh
@@ -1,38 +1,44 @@
#!/bin/bash

PFIDX=0
function setup(){
local pciid=$1
local mac=$2
if [ -z "$pciid" ]; then
echo pciid must be defined
exit -1
fi
local pfdir="/sys/bus/pci/devices/$pciid"
local drv=$( readlink -f $pfdir/driver)
if [ -e "$drv" ]; then
echo $pciid > $drv/unbind
else
drv=/sys/bus/pci/drivers/i40e
echo "pciid" unbound trying $drv
fi
sleep 1
echo $pciid > $drv/bind
nic=$( ls $pfdir/net )
ip link set up dev $nic
echo 1 > "$pfdir/sriov_numvfs"
sleep 1
local pciid=$1
local mac=$2
if [ -z "$pciid" ]; then
echo pciid must be defined
exit -1
fi
local pfdir="/sys/bus/pci/devices/$pciid"
local drv=$( readlink -f $pfdir/driver)
if [ -e "$drv" ]; then
echo $pciid > $drv/unbind
else
drv=/sys/bus/pci/drivers/i40e
echo "pciid" unbound trying $drv
fi
sleep 1
echo $pciid > $drv/bind
nic=$( ls $pfdir/net )
ip link set up dev $nic
echo $(( $# - 1 )) > "$pfdir/sriov_numvfs"
sleep 1

local vfdir=$( readlink -f $pfdir/virtfn0 )
local vfnic=$( ls $vfdir/net )
local loop=0
for i in ${@:2}; do
local vfdir=$( readlink -f $pfdir/virtfn$loop )
local vfnic=$( ls $vfdir/net )

ip link set $nic vf 0 mac $mac
local vfid=$( basename $( readlink -f $vfdir ) )
echo $vfid > $vfdir/driver/unbind
echo $vfid
ip link set $nic vf $loop mac $i
ip link set $nic vf $loop spoofchk off
ip link set $nic vf $loop trust on

local vfid=$( basename $( readlink -f $vfdir ) )
echo $vfid > $vfdir/driver/unbind
echo "export SNABB_AVF_PF${PFIDX}_VF${loop}=$vfid"
loop=$(( loop + 1 ))
done
PFIDX=$(( VFIDX + 1 ))
}

SNABB_AVF_VF0=$(setup $SNABB_AVF_PF0 02:00:00:00:00:00)
SNABB_AVF_VF1=$(setup $SNABB_AVF_PF1 02:00:00:00:00:01)
sleep 3
echo export SNABB_AVF_VF0=$SNABB_AVF_VF0
echo export SNABB_AVF_VF1=$SNABB_AVF_VF1
setup $SNABB_AVF_PF0 02:00:00:00:00:00 02:00:00:00:00:01 02:00:00:00:00:02 02:00:00:00:00:03
setup $SNABB_AVF_PF1 02:00:00:00:00:10 02:00:00:00:00:11 02:00:00:00:00:12 02:00:00:00:00:13

0 comments on commit 19b6164

Please sign in to comment.