Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Jul 2019 09:34:47 +0000 (UTC)
From:      Andrew Rybchenko <arybchik@FreeBSD.org>
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
Message-ID:  <201907290934.x6T9Yl0m006324@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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 <andrea.valsania at answervad.it>
  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;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201907290934.x6T9Yl0m006324>