aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/ntb/if_ntb/if_ntb.c
diff options
context:
space:
mode:
authorConrad Meyer <cem@FreeBSD.org>2015-10-14 23:47:52 +0000
committerConrad Meyer <cem@FreeBSD.org>2015-10-14 23:47:52 +0000
commitd957796cb56850c2e77642bbb3af017ef49e78bb (patch)
tree8a975632ca65785948f31e3cee49ec47715f83d1 /sys/dev/ntb/if_ntb/if_ntb.c
parentfe9621016e1540855e77cc21090000959049db18 (diff)
downloadsrc-d957796cb56850c2e77642bbb3af017ef49e78bb.tar.gz
src-d957796cb56850c2e77642bbb3af017ef49e78bb.zip
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
Notes
Notes: svn path=/head/; revision=289346
Diffstat (limited to 'sys/dev/ntb/if_ntb/if_ntb.c')
-rw-r--r--sys/dev/ntb/if_ntb/if_ntb.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/sys/dev/ntb/if_ntb/if_ntb.c b/sys/dev/ntb/if_ntb/if_ntb.c
index 13c77fab70d2..169296564d74 100644
--- a/sys/dev/ntb/if_ntb/if_ntb.c
+++ b/sys/dev/ntb/if_ntb/if_ntb.c
@@ -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);