From owner-svn-src-all@freebsd.org Mon Jul 29 10:44:05 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id C0A40A5B0F; Mon, 29 Jul 2019 10:44:05 +0000 (UTC) (envelope-from arybchik@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 9FD7577266; Mon, 29 Jul 2019 10:44:05 +0000 (UTC) (envelope-from arybchik@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 699A92702E; Mon, 29 Jul 2019 10:44:05 +0000 (UTC) (envelope-from arybchik@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x6TAi5x9047682; Mon, 29 Jul 2019 10:44:05 GMT (envelope-from arybchik@FreeBSD.org) Received: (from arybchik@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x6TAi4Yn047680; Mon, 29 Jul 2019 10:44:04 GMT (envelope-from arybchik@FreeBSD.org) Message-Id: <201907291044.x6TAi4Yn047680@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: arybchik set sender to arybchik@FreeBSD.org using -f From: Andrew Rybchenko Date: Mon, 29 Jul 2019 10:44:04 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r350412 - stable/11/sys/dev/sfxge/common X-SVN-Group: stable-11 X-SVN-Commit-Author: arybchik X-SVN-Commit-Paths: stable/11/sys/dev/sfxge/common X-SVN-Commit-Revision: 350412 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 9FD7577266 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.94 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.99)[-0.993,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.95)[-0.950,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Jul 2019 10:44:05 -0000 Author: arybchik Date: Mon Jul 29 10:44:04 2019 New Revision: 350412 URL: https://svnweb.freebsd.org/changeset/base/350412 Log: MFC r350371 sfxge(4): unify power of 2 alignment check macro Substitute driver-defined IS_P2ALIGNED() with EFX_IS_P2ALIGNED() defined in libefx. Add type argument and cast value and alignment to one specified type. Reported by: Andrea Valsania Sponsored by: Solarflare Communications, Inc. Modified: stable/11/sys/dev/sfxge/common/efsys.h stable/11/sys/dev/sfxge/common/efx.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/sfxge/common/efsys.h ============================================================================== --- stable/11/sys/dev/sfxge/common/efsys.h Mon Jul 29 10:42:21 2019 (r350411) +++ stable/11/sys/dev/sfxge/common/efsys.h Mon Jul 29 10:44:04 2019 (r350412) @@ -87,10 +87,6 @@ extern "C" { #define B_TRUE TRUE #endif -#ifndef IS_P2ALIGNED -#define IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0) -#endif - #ifndef IS2P #define ISP2(x) (((x) & ((x) - 1)) == 0) #endif @@ -392,7 +388,8 @@ typedef struct efsys_mem_s { uint32_t *addr; \ \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_dword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_dword_t)), \ ("not power of 2 aligned")); \ \ addr = (void *)((_esmp)->esm_base + (_offset)); \ @@ -411,7 +408,8 @@ typedef struct efsys_mem_s { uint64_t *addr; \ \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_qword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_qword_t)), \ ("not power of 2 aligned")); \ \ addr = (void *)((_esmp)->esm_base + (_offset)); \ @@ -430,7 +428,8 @@ typedef struct efsys_mem_s { uint32_t *addr; \ \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_qword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_qword_t)), \ ("not power of 2 aligned")); \ \ addr = (void *)((_esmp)->esm_base + (_offset)); \ @@ -452,7 +451,8 @@ typedef struct efsys_mem_s { uint64_t *addr; \ \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_oword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_oword_t)), \ ("not power of 2 aligned")); \ \ addr = (void *)((_esmp)->esm_base + (_offset)); \ @@ -474,7 +474,8 @@ typedef struct efsys_mem_s { uint32_t *addr; \ \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_oword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_oword_t)), \ ("not power of 2 aligned")); \ \ addr = (void *)((_esmp)->esm_base + (_offset)); \ @@ -499,7 +500,8 @@ typedef struct efsys_mem_s { uint32_t *addr; \ \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_dword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_dword_t)), \ ("not power of 2 aligned")); \ \ EFSYS_PROBE2(mem_writed, unsigned int, (_offset), \ @@ -518,7 +520,8 @@ typedef struct efsys_mem_s { uint64_t *addr; \ \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_qword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_qword_t)), \ ("not power of 2 aligned")); \ \ EFSYS_PROBE3(mem_writeq, unsigned int, (_offset), \ @@ -538,7 +541,8 @@ typedef struct efsys_mem_s { uint32_t *addr; \ \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_qword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_qword_t)), \ ("not power of 2 aligned")); \ \ EFSYS_PROBE3(mem_writeq, unsigned int, (_offset), \ @@ -560,7 +564,8 @@ typedef struct efsys_mem_s { uint64_t *addr; \ \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_oword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_oword_t)), \ ("not power of 2 aligned")); \ \ EFSYS_PROBE5(mem_writeo, unsigned int, (_offset), \ @@ -582,7 +587,8 @@ typedef struct efsys_mem_s { uint32_t *addr; \ \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_oword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_oword_t)), \ ("not power of 2 aligned")); \ \ EFSYS_PROBE5(mem_writeo, unsigned int, (_offset), \ @@ -640,7 +646,8 @@ typedef struct efsys_bar_s { #define EFSYS_BAR_READD(_esbp, _offset, _edp, _lock) \ do { \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_dword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_dword_t)), \ ("not power of 2 aligned")); \ \ _NOTE(CONSTANTCONDITION) \ @@ -664,7 +671,8 @@ typedef struct efsys_bar_s { #define EFSYS_BAR_READQ(_esbp, _offset, _eqp) \ do { \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_qword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_qword_t)), \ ("not power of 2 aligned")); \ \ SFXGE_BAR_LOCK(_esbp); \ @@ -684,7 +692,8 @@ typedef struct efsys_bar_s { #define EFSYS_BAR_READO(_esbp, _offset, _eop, _lock) \ do { \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_oword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_oword_t)), \ ("not power of 2 aligned")); \ \ _NOTE(CONSTANTCONDITION) \ @@ -714,7 +723,8 @@ typedef struct efsys_bar_s { #define EFSYS_BAR_READQ(_esbp, _offset, _eqp) \ do { \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_qword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_qword_t)), \ ("not power of 2 aligned")); \ \ SFXGE_BAR_LOCK(_esbp); \ @@ -737,7 +747,8 @@ typedef struct efsys_bar_s { #define EFSYS_BAR_READO(_esbp, _offset, _eop, _lock) \ do { \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_oword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_oword_t)), \ ("not power of 2 aligned")); \ \ _NOTE(CONSTANTCONDITION) \ @@ -773,7 +784,8 @@ typedef struct efsys_bar_s { #define EFSYS_BAR_WRITED(_esbp, _offset, _edp, _lock) \ do { \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_dword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_dword_t)), \ ("not power of 2 aligned")); \ \ _NOTE(CONSTANTCONDITION) \ @@ -805,7 +817,8 @@ typedef struct efsys_bar_s { #define EFSYS_BAR_WRITEQ(_esbp, _offset, _eqp) \ do { \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_qword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_qword_t)), \ ("not power of 2 aligned")); \ \ SFXGE_BAR_LOCK(_esbp); \ @@ -833,7 +846,8 @@ typedef struct efsys_bar_s { #define EFSYS_BAR_WRITEQ(_esbp, _offset, _eqp) \ do { \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_qword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_qword_t)), \ ("not power of 2 aligned")); \ \ SFXGE_BAR_LOCK(_esbp); \ @@ -877,7 +891,8 @@ typedef struct efsys_bar_s { #define EFSYS_BAR_WC_WRITEQ(_esbp, _offset, _eqp) \ do { \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_qword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_qword_t)), \ ("not power of 2 aligned")); \ \ (void) (_esbp); \ @@ -892,7 +907,8 @@ typedef struct efsys_bar_s { #define EFSYS_BAR_WRITEO(_esbp, _offset, _eop, _lock) \ do { \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_oword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_oword_t)), \ ("not power of 2 aligned")); \ \ _NOTE(CONSTANTCONDITION) \ @@ -938,7 +954,8 @@ typedef struct efsys_bar_s { #define EFSYS_BAR_WRITEO(_esbp, _offset, _eop, _lock) \ do { \ _NOTE(CONSTANTCONDITION) \ - KASSERT(IS_P2ALIGNED(_offset, sizeof (efx_oword_t)), \ + KASSERT(EFX_IS_P2ALIGNED(size_t, _offset, \ + sizeof (efx_oword_t)), \ ("not power of 2 aligned")); \ \ _NOTE(CONSTANTCONDITION) \ Modified: stable/11/sys/dev/sfxge/common/efx.h ============================================================================== --- stable/11/sys/dev/sfxge/common/efx.h Mon Jul 29 10:42:21 2019 (r350411) +++ stable/11/sys/dev/sfxge/common/efx.h Mon Jul 29 10:44:04 2019 (r350412) @@ -58,6 +58,10 @@ extern "C" { #define EFX_P2ALIGN(_type, _value, _align) \ ((_type)(_value) & -(_type)(_align)) +/* Test if value is power of 2 aligned. */ +#define EFX_IS_P2ALIGNED(_type, _value, _align) \ + ((((_type)(_value)) & ((_type)(_align) - 1)) == 0) + /* Return codes */ typedef __success(return == 0) int efx_rc_t;