Skip to content

Commit

Permalink
connectx4.lua: use a factory to create HCAs
Browse files Browse the repository at this point in the history
A HCA is tied to an initialization segment (i.e. device). The previous
commit mishandled the case when multiple devices are run in the same
process.  This is fixed by creating a factory for HCAs per device.
  • Loading branch information
alexandergall committed Jul 20, 2018
1 parent 22af847 commit a949245
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/apps/mellanox/connectx4.lua
Expand Up @@ -206,8 +206,8 @@ function ConnectX4:new (conf)
--
local mmio, fd = pci.map_pci_memory(pciaddress, 0, true)
local init_seg = InitializationSegment:new(mmio)
HCA:init(init_seg)
local hca = HCA:new()
local hca_factory = HCA_factory(init_seg)
local hca = hca_factory:new()

-- Makes enable_hca() hang with ConnectX5
-- init_seg:reset()
Expand Down Expand Up @@ -394,7 +394,7 @@ function ConnectX4:new (conf)
},
}
for _, req in ipairs(self.stats_reqs) do
req.hca = HCA:new()
req.hca = hca_factory:new()
-- Post command
req.start_fn(req.hca)
end
Expand Down Expand Up @@ -505,9 +505,12 @@ end
-- hca object is the main interface towards the NIC firmware.
HCA = {}

-- Allocate array of Command Queue Entries. Must be called prior to
-- HCA:new()
function HCA:init (init_seg, cmdq_size)
-- Create a factory for HCAs for the given Initialization Segment
-- (i.e. device). Application of the new() method to the returned
-- object allocates a new HCA for the next available Command Queue
-- Entry.
function HCA_factory (init_seg, cmdq_size)
local self = {}
self.size = 2^init_seg:log_cmdq_size()
self.stride = 2^init_seg:log_cmdq_stride()
self.init_seg = init_seg
Expand All @@ -519,6 +522,7 @@ function HCA:init (init_seg, cmdq_size)
local entries, entries_phy = memory.dma_alloc(cmdq_size * self.stride, 4096)
self.entries = ffi.cast(cmdq_t, entries)
init_seg:cmdq_phy_addr(entries_phy)
return setmetatable(self, { __index = HCA })
end

---------------------------------------------------------------
Expand Down Expand Up @@ -1620,6 +1624,8 @@ local data_per_mailbox = 0x200 -- Bytes of input/output data in a mailbox

-- Create a command queue with dedicated/reusable DMA memory.
function HCA:new ()
-- Must only be called from a factory created by HCA_factory()
assert(self ~= HCA)
local q = self.nextq
assert(q < self.size)
self.nextq = self.nextq + 1
Expand All @@ -1634,7 +1640,7 @@ function HCA:new ()
inboxes = inboxes,
outboxes = outboxes,
q = q},
{__index = HCA})
{__index = self})
end

-- Reset all data structures to zero values.
Expand Down

0 comments on commit a949245

Please sign in to comment.