Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Jul 2019 10:44:04 +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-11@freebsd.org
Subject:   svn commit: r350412 - stable/11/sys/dev/sfxge/common
Message-ID:  <201907291044.x6TAi4Yn047680@repo.freebsd.org>

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



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