From owner-svn-src-head@freebsd.org Wed Oct 14 23:47:53 2015 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id CBA4BA15CB2; Wed, 14 Oct 2015 23:47:53 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7C4B5C2A; Wed, 14 Oct 2015 23:47:53 +0000 (UTC) (envelope-from cem@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t9ENlqh1050757; Wed, 14 Oct 2015 23:47:52 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t9ENlqLM050756; Wed, 14 Oct 2015 23:47:52 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201510142347.t9ENlqLM050756@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: "Conrad E. Meyer" Date: Wed, 14 Oct 2015 23:47:52 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r289346 - head/sys/dev/ntb/if_ntb X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 14 Oct 2015 23:47:53 -0000 Author: cem Date: Wed Oct 14 23:47:52 2015 New Revision: 289346 URL: https://svnweb.freebsd.org/changeset/base/289346 Log: 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 Modified: head/sys/dev/ntb/if_ntb/if_ntb.c Modified: head/sys/dev/ntb/if_ntb/if_ntb.c ============================================================================== --- head/sys/dev/ntb/if_ntb/if_ntb.c Wed Oct 14 23:47:35 2015 (r289345) +++ head/sys/dev/ntb/if_ntb/if_ntb.c Wed Oct 14 23:47:52 2015 (r289346) @@ -1163,13 +1163,26 @@ ntb_set_mw(struct ntb_netdev *nt, int nu 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);