Use bus_dmamem_alloc(9) KPI instead of contigmalloc(9).
I suppose it should make this code NUMA-aware with recent NUMA drop-in, trying to allocate shared memory buffers from domain closer to NT-bridge. MFC after: 2 weeks
This commit is contained in:
parent
47940d8594
commit
3986af1f65
|
@ -182,6 +182,8 @@ struct ntb_transport_mw {
|
||||||
size_t xlat_size;
|
size_t xlat_size;
|
||||||
size_t buff_size;
|
size_t buff_size;
|
||||||
/* Rx buff is off virt_addr / dma_addr */
|
/* Rx buff is off virt_addr / dma_addr */
|
||||||
|
bus_dma_tag_t dma_tag;
|
||||||
|
bus_dmamap_t dma_map;
|
||||||
caddr_t virt_addr;
|
caddr_t virt_addr;
|
||||||
bus_addr_t dma_addr;
|
bus_addr_t dma_addr;
|
||||||
};
|
};
|
||||||
|
@ -1147,10 +1149,25 @@ out:
|
||||||
NTB_LINK_DOWN_TIMEOUT * hz / 1000, ntb_transport_link_work, nt);
|
NTB_LINK_DOWN_TIMEOUT * hz / 1000, ntb_transport_link_work, nt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ntb_load_cb_args {
|
||||||
|
bus_addr_t addr;
|
||||||
|
int error;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void
|
||||||
|
ntb_load_cb(void *xsc, bus_dma_segment_t *segs, int nsegs, int error)
|
||||||
|
{
|
||||||
|
struct ntb_load_cb_args *cba = (struct ntb_load_cb_args *)xsc;
|
||||||
|
|
||||||
|
if (!(cba->error = error))
|
||||||
|
cba->addr = segs[0].ds_addr;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw, size_t size)
|
ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw, size_t size)
|
||||||
{
|
{
|
||||||
struct ntb_transport_mw *mw = &nt->mw_vec[num_mw];
|
struct ntb_transport_mw *mw = &nt->mw_vec[num_mw];
|
||||||
|
struct ntb_load_cb_args cba;
|
||||||
size_t xlat_size, buff_size;
|
size_t xlat_size, buff_size;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
@ -1171,30 +1188,36 @@ ntb_set_mw(struct ntb_transport_ctx *nt, int num_mw, size_t size)
|
||||||
mw->xlat_size = xlat_size;
|
mw->xlat_size = xlat_size;
|
||||||
mw->buff_size = buff_size;
|
mw->buff_size = buff_size;
|
||||||
|
|
||||||
mw->virt_addr = contigmalloc(mw->buff_size, M_NTB_T, M_ZERO, 0,
|
if (bus_dma_tag_create(bus_get_dma_tag(nt->dev), mw->xlat_align, 0,
|
||||||
mw->addr_limit, mw->xlat_align, 0);
|
mw->addr_limit, BUS_SPACE_MAXADDR,
|
||||||
if (mw->virt_addr == NULL) {
|
NULL, NULL, mw->buff_size, 1, mw->buff_size,
|
||||||
|
0, NULL, NULL, &mw->dma_tag)) {
|
||||||
|
ntb_printf(0, "Unable to create MW tag of size %zu/%zu\n",
|
||||||
|
mw->buff_size, mw->xlat_size);
|
||||||
|
mw->xlat_size = 0;
|
||||||
|
mw->buff_size = 0;
|
||||||
|
return (ENOMEM);
|
||||||
|
}
|
||||||
|
if (bus_dmamem_alloc(mw->dma_tag, (void **)&mw->virt_addr,
|
||||||
|
BUS_DMA_WAITOK | BUS_DMA_ZERO, &mw->dma_map)) {
|
||||||
|
bus_dma_tag_destroy(mw->dma_tag);
|
||||||
ntb_printf(0, "Unable to allocate MW buffer of size %zu/%zu\n",
|
ntb_printf(0, "Unable to allocate MW buffer of size %zu/%zu\n",
|
||||||
mw->buff_size, mw->xlat_size);
|
mw->buff_size, mw->xlat_size);
|
||||||
mw->xlat_size = 0;
|
mw->xlat_size = 0;
|
||||||
mw->buff_size = 0;
|
mw->buff_size = 0;
|
||||||
return (ENOMEM);
|
return (ENOMEM);
|
||||||
}
|
}
|
||||||
/* TODO: replace with bus_space_* functions */
|
if (bus_dmamap_load(mw->dma_tag, mw->dma_map, mw->virt_addr,
|
||||||
mw->dma_addr = vtophys(mw->virt_addr);
|
mw->buff_size, ntb_load_cb, &cba, BUS_DMA_NOWAIT) || cba.error) {
|
||||||
|
bus_dmamem_free(mw->dma_tag, mw->virt_addr, mw->dma_map);
|
||||||
/*
|
bus_dma_tag_destroy(mw->dma_tag);
|
||||||
* Ensure that the allocation from contigmalloc is aligned as
|
ntb_printf(0, "Unable to load MW buffer of size %zu/%zu\n",
|
||||||
* requested. XXX: This may not be needed -- brought in for parity
|
mw->buff_size, mw->xlat_size);
|
||||||
* with the Linux driver.
|
mw->xlat_size = 0;
|
||||||
*/
|
mw->buff_size = 0;
|
||||||
if (mw->dma_addr % mw->xlat_align != 0) {
|
|
||||||
ntb_printf(0,
|
|
||||||
"DMA memory 0x%jx not aligned to BAR size 0x%zx\n",
|
|
||||||
(uintmax_t)mw->dma_addr, size);
|
|
||||||
ntb_free_mw(nt, num_mw);
|
|
||||||
return (ENOMEM);
|
return (ENOMEM);
|
||||||
}
|
}
|
||||||
|
mw->dma_addr = cba.addr;
|
||||||
|
|
||||||
/* Notify HW the memory location of the receive buffer */
|
/* Notify HW the memory location of the receive buffer */
|
||||||
rc = ntb_mw_set_trans(nt->dev, num_mw, mw->dma_addr, mw->xlat_size);
|
rc = ntb_mw_set_trans(nt->dev, num_mw, mw->dma_addr, mw->xlat_size);
|
||||||
|
@ -1216,7 +1239,9 @@ ntb_free_mw(struct ntb_transport_ctx *nt, int num_mw)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ntb_mw_clear_trans(nt->dev, num_mw);
|
ntb_mw_clear_trans(nt->dev, num_mw);
|
||||||
contigfree(mw->virt_addr, mw->xlat_size, M_NTB_T);
|
bus_dmamap_unload(mw->dma_tag, mw->dma_map);
|
||||||
|
bus_dmamem_free(mw->dma_tag, mw->virt_addr, mw->dma_map);
|
||||||
|
bus_dma_tag_destroy(mw->dma_tag);
|
||||||
mw->xlat_size = 0;
|
mw->xlat_size = 0;
|
||||||
mw->buff_size = 0;
|
mw->buff_size = 0;
|
||||||
mw->virt_addr = NULL;
|
mw->virt_addr = NULL;
|
||||||
|
|
Loading…
Reference in New Issue