if_ntb: MFV 3cc5ba19: Add alignment check to meet hardware requirement

Original Linux commit log:

The NTB translate register must have the value to be BAR size aligned.
This alignment check make sure that the DMA memory allocated has the
proper alignment. Another requirement for NTB to function properly with
memory window BAR size greater or equal to 4M is to use the CMA feature
in 3.16 kernel with the appropriate CONFIG_CMA_ALIGNMENT and
CONFIG_CMA_SIZE_MBYTES set.

Authored by:	Dave Jiang
Obtained from:	Linux (Dual BSD/GPL driver)
Sponsored by:	EMC / Isilon Storage Division
This commit is contained in:
cem 2015-10-14 23:47:52 +00:00
parent 1a9e30b488
commit 05fa2677c4

View File

@ -1163,13 +1163,26 @@ ntb_set_mw(struct ntb_netdev *nt, int num_mw, unsigned int size)
BUS_SPACE_MAXADDR, mw->size, 0);
if (mw->virt_addr == NULL) {
mw->size = 0;
printf("ntb: Unable to allocate MW buffer of size %d\n",
(int)mw->size);
printf("ntb: Unable to allocate MW buffer of size %zu\n",
mw->size);
return (ENOMEM);
}
/* TODO: replace with bus_space_* functions */
mw->dma_addr = vtophys(mw->virt_addr);
/*
* Ensure that the allocation from contigmalloc is aligned as
* requested. XXX: This may not be needed -- brought in for parity
* with the Linux driver.
*/
if (mw->dma_addr % size != 0) {
device_printf(ntb_get_device(nt->ntb),
"DMA memory 0x%jx not aligned to BAR size 0x%x\n",
(uintmax_t)mw->dma_addr, size);
ntb_free_mw(nt, num_mw);
return (ENOMEM);
}
/* Notify HW the memory location of the receive buffer */
ntb_set_mw_addr(nt->ntb, num_mw, mw->dma_addr);