From owner-svn-src-head@freebsd.org Wed Nov 18 22:20:23 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 54EADA32A4C; Wed, 18 Nov 2015 22:20:23 +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 2EBC71217; Wed, 18 Nov 2015 22:20:23 +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 tAIMKMrJ084253; Wed, 18 Nov 2015 22:20:22 GMT (envelope-from cem@FreeBSD.org) Received: (from cem@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tAIMKMh7084251; Wed, 18 Nov 2015 22:20:22 GMT (envelope-from cem@FreeBSD.org) Message-Id: <201511182220.tAIMKMh7084251@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: cem set sender to cem@FreeBSD.org using -f From: "Conrad E. Meyer" Date: Wed, 18 Nov 2015 22:20:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r291031 - head/sys/dev/ntb/ntb_hw 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, 18 Nov 2015 22:20:23 -0000 Author: cem Date: Wed Nov 18 22:20:21 2015 New Revision: 291031 URL: https://svnweb.freebsd.org/changeset/base/291031 Log: ntb_hw: Add programmatic interface to enable/disable WC Enable users to enable/disable WC on memory windows programmatically. Sponsored by: EMC / Isilon Storage Division Modified: head/sys/dev/ntb/ntb_hw/ntb_hw.c head/sys/dev/ntb/ntb_hw/ntb_hw.h Modified: head/sys/dev/ntb/ntb_hw/ntb_hw.c ============================================================================== --- head/sys/dev/ntb/ntb_hw/ntb_hw.c Wed Nov 18 22:20:13 2015 (r291030) +++ head/sys/dev/ntb/ntb_hw/ntb_hw.c Wed Nov 18 22:20:21 2015 (r291031) @@ -113,6 +113,7 @@ struct ntb_pci_bar_info { vm_paddr_t pbase; caddr_t vbase; vm_size_t size; + bool mapped_wc : 1; /* Configuration register offsets */ uint32_t psz_off; @@ -777,14 +778,15 @@ map_memory_window_bar(struct ntb_softc * /* Mark bar region as write combining to improve performance. */ rc = pmap_change_attr((vm_offset_t)bar->vbase, bar->size, VM_MEMATTR_WRITE_COMBINING); - if (rc == 0) + if (rc == 0) { + bar->mapped_wc = true; device_printf(ntb->device, "Marked BAR%d v:[%p-%p] p:[%p-%p] as " "WRITE_COMBINING.\n", PCI_RID2BAR(bar->pci_resource_id), bar->vbase, (char *)bar->vbase + bar->size - 1, (void *)bar->pbase, (void *)(bar->pbase + bar->size - 1)); - else + } else device_printf(ntb->device, "Unable to mark BAR%d v:[%p-%p] p:[%p-%p] as " "WRITE_COMBINING: %d\n", @@ -2629,6 +2631,60 @@ ntb_mw_clear_trans(struct ntb_softc *ntb return (ntb_mw_set_trans(ntb, mw_idx, 0, 0)); } +/* + * ntb_mw_get_wc - Get the write-combine status of a memory window + * + * Returns: Zero on success, setting *wc; otherwise an error number (e.g. if + * idx is an invalid memory window). + */ +int +ntb_mw_get_wc(struct ntb_softc *ntb, unsigned idx, bool *wc) +{ + struct ntb_pci_bar_info *bar; + + if (idx >= ntb_mw_count(ntb)) + return (EINVAL); + + bar = &ntb->bar_info[ntb_mw_to_bar(ntb, idx)]; + *wc = bar->mapped_wc; + return (0); +} + +/* + * ntb_mw_set_wc - Set the write-combine status of a memory window + * + * If 'wc' matches the current status, this does nothing and succeeds. + * + * Returns: Zero on success, setting the caching attribute on the virtual + * mapping of the BAR; otherwise an error number (e.g. if idx is an invalid + * memory window, or if changing the caching attribute fails). + */ +int +ntb_mw_set_wc(struct ntb_softc *ntb, unsigned idx, bool wc) +{ + struct ntb_pci_bar_info *bar; + vm_memattr_t attr; + int rc; + + if (idx >= ntb_mw_count(ntb)) + return (EINVAL); + + bar = &ntb->bar_info[ntb_mw_to_bar(ntb, idx)]; + if (bar->mapped_wc == wc) + return (0); + + if (wc) + attr = VM_MEMATTR_WRITE_COMBINING; + else + attr = VM_MEMATTR_DEFAULT; + + rc = pmap_change_attr((vm_offset_t)bar->vbase, bar->size, attr); + if (rc == 0) + bar->mapped_wc = wc; + + return (rc); +} + /** * ntb_peer_db_set() - Set the doorbell on the secondary/external side * @ntb: pointer to ntb_softc instance Modified: head/sys/dev/ntb/ntb_hw/ntb_hw.h ============================================================================== --- head/sys/dev/ntb/ntb_hw/ntb_hw.h Wed Nov 18 22:20:13 2015 (r291030) +++ head/sys/dev/ntb/ntb_hw/ntb_hw.h Wed Nov 18 22:20:21 2015 (r291031) @@ -81,6 +81,9 @@ int ntb_mw_get_range(struct ntb_softc *, int ntb_mw_set_trans(struct ntb_softc *, unsigned mw_idx, bus_addr_t, size_t); int ntb_mw_clear_trans(struct ntb_softc *, unsigned mw_idx); +int ntb_mw_get_wc(struct ntb_softc *, unsigned mw_idx, bool *wc); +int ntb_mw_set_wc(struct ntb_softc *, unsigned mw_idx, bool wc); + uint8_t ntb_get_max_spads(struct ntb_softc *ntb); int ntb_spad_write(struct ntb_softc *ntb, unsigned int idx, uint32_t val); int ntb_spad_read(struct ntb_softc *ntb, unsigned int idx, uint32_t *val);