From owner-svn-src-all@freebsd.org Mon Jul 29 09:34:48 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 278E8A424A; Mon, 29 Jul 2019 09:34:48 +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 08AD57089D; Mon, 29 Jul 2019 09:34:48 +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 C693A2638C; Mon, 29 Jul 2019 09:34:47 +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 x6T9YleM006325; Mon, 29 Jul 2019 09:34:47 GMT (envelope-from arybchik@FreeBSD.org) Received: (from arybchik@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x6T9Yl0m006324; Mon, 29 Jul 2019 09:34:47 GMT (envelope-from arybchik@FreeBSD.org) Message-Id: <201907290934.x6T9Yl0m006324@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 09:34:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r350407 - stable/12/sys/dev/sfxge/common X-SVN-Group: stable-12 X-SVN-Commit-Author: arybchik X-SVN-Commit-Paths: stable/12/sys/dev/sfxge/common X-SVN-Commit-Revision: 350407 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 08AD57089D X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.99)[-0.993,0]; NEURAL_HAM_SHORT(-0.96)[-0.956,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] 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 09:34:48 -0000 Author: arybchik Date: Mon Jul 29 09:34:47 2019 New Revision: 350407 URL: https://svnweb.freebsd.org/changeset/base/350407 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/12/sys/dev/sfxge/common/efsys.h stable/12/sys/dev/sfxge/common/efx.h Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/dev/sfxge/common/efsys.h ============================================================================== --- stable/12/sys/dev/sfxge/common/efsys.h Mon Jul 29 09:26:55 2019 (r350406) +++ stable/12/sys/dev/sfxge/common/efsys.h Mon Jul 29 09:34:47 2019 (r350407) @@ -89,10 +89,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 @@ -394,7 +390,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)); \ @@ -413,7 +410,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)); \ @@ -432,7 +430,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)); \ @@ -454,7 +453,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)); \ @@ -476,7 +476,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)); \ @@ -501,7 +502,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), \ @@ -520,7 +522,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), \ @@ -540,7 +543,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), \ @@ -562,7 +566,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), \ @@ -584,7 +589,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), \ @@ -642,7 +648,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) \ @@ -666,7 +673,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); \ @@ -686,7 +694,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) \ @@ -716,7 +725,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); \ @@ -739,7 +749,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) \ @@ -775,7 +786,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) \ @@ -807,7 +819,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); \ @@ -835,7 +848,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); \ @@ -879,7 +893,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); \ @@ -894,7 +909,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) \ @@ -940,7 +956,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/12/sys/dev/sfxge/common/efx.h ============================================================================== --- stable/12/sys/dev/sfxge/common/efx.h Mon Jul 29 09:26:55 2019 (r350406) +++ stable/12/sys/dev/sfxge/common/efx.h Mon Jul 29 09:34:47 2019 (r350407) @@ -60,6 +60,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;