Skip to content

Instantly share code, notes, and snippets.

@eugeneia
Created November 3, 2016 19:49
Show Gist options
  • Save eugeneia/f581a1e689bd29218a1daaf31941c6ba to your computer and use it in GitHub Desktop.
Save eugeneia/f581a1e689bd29218a1daaf31941c6ba to your computer and use it in GitHub Desktop.
-- Use of this source code is governed by the Apache 2.0 license; see COPYING.
-- IOControl and IO macro apps that implement the following interface:
--
-- config.app("ctrl", IOControl,
-- {pciaddr="01:00.0",
-- queues = {{id="a", mac="10:10:10:10:10:10", vlan=42, buckets=2},
-- {id="b", mac="20:20:20:20:20:20", vlan=43}}})
--
-- config.app("io", IO, {pciaddr="01:00.0", queue = "a", bucket = 1})
--
-- `pciaddr' is optional and `softio' can be used instead, which defaults to
-- the "SoftIO" bridge.
--
-- All keys except `queues', `id', `buckets', `queue', and `bucket' are driver
-- specific, and possibly optional.
--
-- To add support for new drivers it must be registered in lib.hardware.pci. If
-- a control app is required for queue setup, the driver must expose a
-- `control' variable that contains the respective app (like `driver' contains
-- the driver app), which must accept the configuration argument passed to
-- IOControl. Additionally, a configuration formula for the driver must be
-- defined. See how the formula table is populated below.
--
-- Note that `buckets' and `bucket' must default to 1.
module(..., package.seeall)
local lib = require("core.lib")
local pci = require("lib.hardware.pci")
local FloodingBridge = require("apps.bridge.flooding").bridge
local basic_apps = require("apps.basic.basic_apps")
local Synth = require("apps.test.synth").Synth
-- local QueueEmu = require("apps.emu.queue")
IOControl = {
config = {
pciaddr = {}, softio = {}, queues = {required=true}
}
}
local default_softio = "SoftIO"
local queues = {}
local bridges = {}
function IOControl:configure (c, name, conf)
queues[conf.pciaddr or conf.softio or default_softio] = conf.queues
if conf.pciaddr then
local module = require(pci.device_info(io.pci).driver)
if module.control then
config.app(c, name, module.control, conf)
end
else
bridges[conf.softio] = name
local bridge_ports = {}
for _, queue in ipairs(conf.queues) do
assert(queue.id, "Queue of "..conf.softio.." has no id: "..queue)
table.insert(bridge_ports, queue.id)
end
config.app(c, name, FloodingBridge, {ports = bridge_ports})
end
end
IO = {
config = {
pciaddr = {}, softio = {}, queue = {required=true}, bucket = {}
}
}
local formula = {}
function IOControl:configure (c, name, conf)
if conf.pciaddr then
local driver = pci.device_info(conf.pciaddr).driver
formula[driver](c, name, require(driver).driver,
conf.pciaddr, conf.queue, conf.bucket)
else
-- Create emu app on bridge conf.softio for queues[conf.softio]
-- config.app(c, QeueEmu, conf.queue)
-- local bridge_port = bridges[conf.softio].."."..conf.queue.id
-- config.link(c, bridge_port.." -> "..name..".rx")
-- config.link(c, name..".tx -> "..bridge_port)
end
end
formula['apps.intel.intel_app'] = function (c, name, driver, pciaddr, queue)
local config
for _, queuespec in ipairs(queues[pciaddr]) do
if queuespec.id = queue then
config = lib.deepcopy(queuespec)
config.pciaddr = pciaddr
break
end
end
config.app(c, name, driver, config)
end
formula['apps.solarflare.solarflare'] = formula['apps.intel.intel_app']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment