Author: arybchik
Date: Sat Jul 27 09:36:45 2019
New Revision: 350371
URL: https://svnweb.freebsd.org/changeset/base/350371

Log:
  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>
  Reviewed by:    philip
  Sponsored by:   Solarflare Communications, Inc.
  MFC after:      2 days
  Differential Revision:  https://reviews.freebsd.org/D21076

Modified:
  head/sys/dev/sfxge/common/ef10_rx.c
  head/sys/dev/sfxge/common/efsys.h
  head/sys/dev/sfxge/common/efx.h

Modified: head/sys/dev/sfxge/common/ef10_rx.c
==============================================================================
--- head/sys/dev/sfxge/common/ef10_rx.c Sat Jul 27 09:36:36 2019        
(r350370)
+++ head/sys/dev/sfxge/common/ef10_rx.c Sat Jul 27 09:36:45 2019        
(r350371)
@@ -1131,12 +1131,12 @@ ef10_rx_qcreate(
                        rc = ENOTSUP;
                        goto fail9;
                }
-               if (!IS_P2ALIGNED(es_max_dma_len,
+               if (!EFX_IS_P2ALIGNED(uint32_t, es_max_dma_len,
                            EFX_RX_ES_SUPER_BUFFER_BUF_ALIGNMENT)) {
                        rc = EINVAL;
                        goto fail10;
                }
-               if (!IS_P2ALIGNED(es_buf_stride,
+               if (!EFX_IS_P2ALIGNED(uint32_t, es_buf_stride,
                            EFX_RX_ES_SUPER_BUFFER_BUF_ALIGNMENT)) {
                        rc = EINVAL;
                        goto fail11;

Modified: head/sys/dev/sfxge/common/efsys.h
==============================================================================
--- head/sys/dev/sfxge/common/efsys.h   Sat Jul 27 09:36:36 2019        
(r350370)
+++ head/sys/dev/sfxge/common/efsys.h   Sat Jul 27 09:36:45 2019        
(r350371)
@@ -84,10 +84,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
@@ -375,7 +371,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));         \
@@ -394,7 +391,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));         \
@@ -413,7 +411,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));         \
@@ -435,7 +434,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));         \
@@ -457,7 +457,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));         \
@@ -482,7 +483,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),       \
@@ -501,7 +503,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),       \
@@ -521,7 +524,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),       \
@@ -543,7 +547,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),       \
@@ -565,7 +570,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),       \
@@ -617,7 +623,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)                                \
@@ -641,7 +648,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);                                  \
@@ -661,7 +669,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)                                \
@@ -691,7 +700,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);                                  \
@@ -714,7 +724,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)                                \
@@ -750,7 +761,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)                                \
@@ -782,7 +794,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);                                  \
@@ -810,7 +823,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);                                  \
@@ -854,7 +868,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);                                         \
@@ -869,7 +884,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)                                \
@@ -915,7 +931,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: head/sys/dev/sfxge/common/efx.h
==============================================================================
--- head/sys/dev/sfxge/common/efx.h     Sat Jul 27 09:36:36 2019        
(r350370)
+++ head/sys/dev/sfxge/common/efx.h     Sat Jul 27 09:36:45 2019        
(r350371)
@@ -64,6 +64,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;
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to