[openib-general] [PATCH 9/10] Driver utility file - implements various utility macros

Bryan O'Sullivan bos at pathscale.com
Mon Oct 2 14:16:16 PDT 2006


Ramachandra K wrote:
>
> +#define PRINT(level, x, fmt, arg...)				\
> +	printk(level "%s: %s: %s, line %d: " fmt,			\
> +	       MODULE_NAME, x, __FILE__, __LINE__, ##arg)

Use dev_info and friends instead of printk.


> +#define hton8(x)	(x)
> +#define hton16(x)	__cpu_to_be16(x)
> +#define hton32(x)	__cpu_to_be32(x)
> +#define hton64(x)	__cpu_to_be64(x)

Drop these macros.

> +#define get_sksport(sk) inet_sk(sk)->sport
> +#define get_skdport(sk) inet_sk(sk)->dport

And these.

> +typedef unsigned long uintn;	/* __WORDSIZE/pointer sized integer */

And this typedef.

> +/* round down value to align, align must be a power of 2 */
> +#ifndef ROUNDDOWNP2
> +#define ROUNDDOWNP2(val, align)				\
> +	(((uintn)(val)) & (~((uintn)(align)-1)))
> +#endif

Perhaps introduce a generic ALIGN_DOWN macro here.

> +/* round up value to align, align must be a power of 2 */
> +#ifndef ROUNDUPP2
> +#define ROUNDUPP2(val, align)						\
> +	(((uintn)(val) + (uintn)(align) - 1) & (~((uintn)(align)-1)))
> +#endif

Use ALGIN instead of this macro.

> +#define BOOLEAN		u8
> +#define TRUE		1
> +#define FALSE		0

Yeuch.  These have to go.

> +#define MAXU32		0xffffffff
> +#define MAXU64		((u64)(~0ULL))

Drop these.

> +#if BITS_PER_LONG == 64
> +#define PTR64(what)	((u64)(what))
> +#define PTR(what)	((void *)(u64)(what))
> +#elif BITS_PER_LONG == 32
> +#define PTR64(what)	((u64)(u32)(what))
> +#define PTR(what)	((void *)(u32)(what))

And these.

> +#if BITS_PER_LONG == 64
> +#ifdef __ia64__
> +#define __PRI64_PREFIX	"l"
> +#else
> +#define __PRI64_PREFIX	"ll"
> +#endif
> +#define PRISZT "lu"
> +#elif BITS_PER_LONG == 32
> +#define __PRI64_PREFIX	"L"
> +#define PRISZT "u"
> +#else
> +#error "BITS_PER_LONG not 64 nor 32"
> +#endif
> +#define __PRIN_PREFIX	"l"

Just cast 64-bit values to unsigned long long, use %lld etc everywhere, 
and drop all of this.

> +/* source time is 100ths of a sec */
> +#define CONV2JIFFIES(time) (((time) * HZ) / 100)
> +#define CONV2USEC(time)    ((time) * 10000)
> +
> +#ifndef min
> +#define min(a,b)	((a)<(b)?(a):(b))
> +#endif

Use the standard macros for these.

	<b




More information about the general mailing list