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
This commit is contained in:
Andrew Rybchenko 2019-07-27 09:36:45 +00:00
parent e561c5fe44
commit 7daf1fed80
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=350371
3 changed files with 48 additions and 27 deletions

View file

@ -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;

View file

@ -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) \

View file

@ -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;