All of lore.kernel.org
 help / color / mirror / Atom feed
From: Boaz Harrosh <bharrosh@panasas.com>
To: Chris Leech <christopher.leech@intel.com>
Cc: linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org,
	devel@open-fcoe.org, Harvey Harrison <harvey.harrison@gmail.com>
Subject: Re: [PATCH 1/3] 24-bit types: typedef and macros for accessing 3-byte arrays as integers
Date: Sun, 07 Sep 2008 12:36:41 +0300	[thread overview]
Message-ID: <48C3A0A9.3000206@panasas.com> (raw)
In-Reply-To: <20080905165732.16689.50256.stgit@localhost.localdomain>

Chris Leech wrote:
> Both iSCSI and Fibre Channel make use of 24-bit big-endian values in
> frame headers.  This patch defines __be24 and __le24 typedefs for a
> structure wrapped around a 3-byte array, and macros to convert back and
> forth to a 32-bit integer.
> 
> The undefs in iscsi_proto.h are because of the different calling
> convention for the existing hton24 macro in the iSCSI code.  iSCSI will
> be converted in a subsequent patch.
> 
> Signed-off-by: Chris Leech <christopher.leech@intel.com>

I like what this patch wants to accomplish, but I disagree with the
implementation.

First why is the double definition, one in include/linux/byteorder.h
and one in include/linux/byteorder/generic.h ?

Second and most important, in both these files all routines are inline's
not MACROs, and rightly so. There is no place for a macro and the MACRO
works bad for these. One - the definition of a local variable in a {} scope
in the middle of anywhere. Second - type safety.

I CC: Harvey Harrison which did lots of work in these area's.

For me this patch is totally unacceptable.

Thanks for working on this
Boaz
> ---
> 
>  include/linux/byteorder.h         |   56 ++++++++++++++++++++++++++++++++++++
>  include/linux/byteorder/generic.h |   57 +++++++++++++++++++++++++++++++++++++
>  include/linux/types.h             |    2 +
>  include/scsi/iscsi_proto.h        |    2 +
>  4 files changed, 117 insertions(+), 0 deletions(-)
> 
> 
> diff --git a/include/linux/byteorder.h b/include/linux/byteorder.h
> index 29f002d..e41c17b 100644
> --- a/include/linux/byteorder.h
> +++ b/include/linux/byteorder.h
> @@ -62,6 +62,54 @@
>  # define __cpu_to_le64(x) ((__force __le64)__swab64(x))
>  #endif
>  
> +/**
> + * __le24_to_cpu - read a 3-byte array as a 24-bit little-endian integer
> + * @x: __le24, a structure wrapper around a 3-byte array
> + *
> + * Evaluates to a __u32 integer type
> + */
> +#define __le24_to_cpu(x) \
> +({ \
> +	__le24 _x = (x); \
> +	(__u32) ((_x.b[2] << 16) | (_x.b[1] << 8) | (_x.b[0])); \
> +})
> +
> +/**
> + * __cpu_to_le24 - store a value in a 3-byte array in little-endian format
> + * @x: __u32, there is no checking to ensure only the lower 24 bits are set
> + *
> + * Evaluates to an __le24 compound literal
> + */
> +#define __cpu_to_le24(x) \
> +({ \
> +	__u32 _x = (x); \
> +	(__le24) { .b = { _x & 0xff, (_x >> 8) & 0xff, (_x >> 16) & 0xff } }; \
> +})
> +
> +/**
> + * __be24_to_cpu - read a 3-byte array as a 24-bit big-endian integer
> + * @x: __be24, a structure wrapper around a 3-byte array
> + *
> + * Evaluates to a __u32 integer type
> + */
> +#define __be24_to_cpu(x) \
> +({ \
> +	__be24 _x = (x); \
> +	(__u32) ((_x.b[0] << 16) | (_x.b[1] << 8) | (_x.b[2])); \
> +})
> +
> +/**
> + * __cpu_to_be24 - store a value in a 3-byte array in big-endian format
> + * @x: __u32, there is no checking to ensure only the lower 24 bits are set
> + *
> + * Evaluates to an __be24 compound literal
> + */
> +#define __cpu_to_be24(x) \
> +({ \
> +	__u32 _x = (x); \
> +	(__be24) { .b = { (_x >> 16) & 0xff, (_x >> 8) & 0xff, _x & 0xff } }; \
> +})
> +
>  /*
>   * These helpers could be phased out over time as the base version
>   * handles constant folding.
> @@ -280,15 +328,19 @@ static inline __be64 __cpu_to_be64p(const __u64 *p)
>  #ifdef __KERNEL__
>  
>  # define le16_to_cpu __le16_to_cpu
> +# define le24_to_cpu __le24_to_cpu
>  # define le32_to_cpu __le32_to_cpu
>  # define le64_to_cpu __le64_to_cpu
>  # define be16_to_cpu __be16_to_cpu
> +# define be24_to_cpu __be24_to_cpu
>  # define be32_to_cpu __be32_to_cpu
>  # define be64_to_cpu __be64_to_cpu
>  # define cpu_to_le16 __cpu_to_le16
> +# define cpu_to_le24 __cpu_to_le24
>  # define cpu_to_le32 __cpu_to_le32
>  # define cpu_to_le64 __cpu_to_le64
>  # define cpu_to_be16 __cpu_to_be16
> +# define cpu_to_be24 __cpu_to_be24
>  # define cpu_to_be32 __cpu_to_be32
>  # define cpu_to_be64 __cpu_to_be64
>  
> @@ -332,11 +384,15 @@ static inline __be64 __cpu_to_be64p(const __u64 *p)
>  # define ___htons(x) __cpu_to_be16(x)
>  # define ___ntohl(x) __be32_to_cpu(x)
>  # define ___ntohs(x) __be16_to_cpu(x)
> +# define ___hton24(x) __cpu_to_be24(x)
> +# define ___ntoh24(x) __be24_to_cpu(x)
>  
>  # define htonl(x) ___htonl(x)
>  # define ntohl(x) ___ntohl(x)
>  # define htons(x) ___htons(x)
>  # define ntohs(x) ___ntohs(x)
> +# define hton24(x) ___hton24(x)
> +# define ntoh24(x) ___ntoh24(x)
>  
>  static inline void le16_add_cpu(__le16 *var, u16 val)
>  {
> diff --git a/include/linux/byteorder/generic.h b/include/linux/byteorder/generic.h
> index 0846e6b..a57fbc3 100644
> --- a/include/linux/byteorder/generic.h
> +++ b/include/linux/byteorder/generic.h
> @@ -119,6 +119,59 @@
>  #define cpu_to_be16s __cpu_to_be16s
>  #define be16_to_cpus __be16_to_cpus
>  
> +/**
> + * __le24_to_cpu - read a 3-byte array as a 24-bit little-endian integer
> + * @x: __le24, a structure wrapper around a 3-byte array
> + *
> + * Evaluates to a __u32 integer type
> + */
> +#define __le24_to_cpu(x) \
> +({ \
> +	__le24 _x = (x); \
> +	(__u32) ((_x.b[2] << 16) | (_x.b[1] << 8) | (_x.b[0])); \
> +})
> +
> +/**
> + * __cpu_to_le24 - store a value in a 3-byte array in little-endian format
> + * @x: __u32, there is no checking to ensure only the lower 24 bits are set
> + *
> + * Evaluates to an __le24 compound literal
> + */
> +#define __cpu_to_le24(x) \
> +({ \
> +	__u32 _x = (x); \
> +	(__le24) { .b = { _x & 0xff, (_x >> 8) & 0xff, (_x >> 16) & 0xff } }; \
> +})
> +
> +/**
> + * __be24_to_cpu - read a 3-byte array as a 24-bit big-endian integer
> + * @x: __be24, a structure wrapper around a 3-byte array
> + *
> + * Evaluates to a __u32 integer type
> + */
> +#define __be24_to_cpu(x) \
> +({ \
> +	__be24 _x = (x); \
> +	(__u32) ((_x.b[0] << 16) | (_x.b[1] << 8) | (_x.b[2])); \
> +})
> +
> +/**
> + * __cpu_to_be24 - store a value in a 3-byte array in big-endian format
> + * @x: __u32, there is no checking to ensure only the lower 24 bits are set
> + *
> + * Evaluates to an __be24 compound literal
> + */
> +#define __cpu_to_be24(x) \
> +({ \
> +	__u32 _x = (x); \
> +	(__be24) { .b = { (_x >> 16) & 0xff, (_x >> 8) & 0xff, _x & 0xff } }; \
> +})
> +
> +#define le24_to_cpu __le24_to_cpu
> +#define cpu_to_le24 __cpu_to_le24
> +#define be24_to_cpu __be24_to_cpu
> +#define cpu_to_be24 __cpu_to_be24
> +
>  /*
>   * They have to be macros in order to do the constant folding
>   * correctly - if the argument passed into a inline function
> @@ -134,11 +187,15 @@
>  #define ___htons(x) __cpu_to_be16(x)
>  #define ___ntohl(x) __be32_to_cpu(x)
>  #define ___ntohs(x) __be16_to_cpu(x)
> +#define ___hton24(x) __cpu_to_be24(x)
> +#define ___ntoh24(x) __be24_to_cpu(x)
>  
>  #define htonl(x) ___htonl(x)
>  #define ntohl(x) ___ntohl(x)
>  #define htons(x) ___htons(x)
>  #define ntohs(x) ___ntohs(x)
> +#define hton24(x) ___hton24(x)
> +#define ntoh24(x) ___ntoh24(x)
>  
>  static inline void le16_add_cpu(__le16 *var, u16 val)
>  {
> diff --git a/include/linux/types.h b/include/linux/types.h
> index d4a9ce6..85fcff7 100644
> --- a/include/linux/types.h
> +++ b/include/linux/types.h
> @@ -188,6 +188,8 @@ typedef __u64 __bitwise __be64;
>  typedef __u16 __bitwise __sum16;
>  typedef __u32 __bitwise __wsum;
>  
> +typedef struct { __u8 b[3]; } __be24, __le24;
> +
>  #ifdef __KERNEL__
>  typedef unsigned __bitwise__ gfp_t;
>  
> diff --git a/include/scsi/iscsi_proto.h b/include/scsi/iscsi_proto.h
> index f2a2c11..429c5ff 100644
> --- a/include/scsi/iscsi_proto.h
> +++ b/include/scsi/iscsi_proto.h
> @@ -35,6 +35,8 @@
>  /*
>   * useful common(control and data pathes) macro
>   */
> +#undef ntoh24
> +#undef hton24
>  #define ntoh24(p) (((p)[0] << 16) | ((p)[1] << 8) | ((p)[2]))
>  #define hton24(p, v) { \
>          p[0] = (((v) >> 16) & 0xFF); \
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


  parent reply	other threads:[~2008-09-07  9:37 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-05 16:57 [PATCH 1/3] 24-bit types: typedef and macros for accessing 3-byte arrays as integers Chris Leech
2008-09-05 16:57 ` Chris Leech
     [not found] ` <20080905165732.16689.50256.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2008-09-05 16:57   ` [PATCH 2/3] 24-bit types: convert iSCSI to use the __be24 type and macros Chris Leech
2008-09-05 16:57     ` Chris Leech
     [not found]     ` <20080905165738.16689.31487.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/Bob@public.gmane.org>
2008-09-05 17:03       ` Mike Christie
2008-09-05 17:03         ` [Open-FCoE] " Mike Christie
2008-09-05 16:57   ` [PATCH 3/3] 24-bit types: Convert Open-FCoE to use " Chris Leech
2008-09-05 16:57     ` Chris Leech
2008-09-07  9:36 ` Boaz Harrosh [this message]
2008-09-07 15:56   ` [PATCH 1/3] 24-bit types: typedef and macros for accessing 3-byte arrays as integers Chris Leech
2008-09-07 17:21     ` Boaz Harrosh
2008-09-07 17:52       ` Chris Leech
2008-09-09 22:59         ` [PATCH] 24-bit types: typedef and functions " Chris Leech
2008-09-10 12:57           ` Boaz Harrosh
2008-09-07  9:57 ` [PATCH 1/3] 24-bit types: typedef and macros " Boaz Harrosh
2008-09-10 14:07 ` Christoph Hellwig
2008-09-10 15:40   ` Dave Kleikamp
2008-09-10 16:11     ` [PATCH " Boaz Harrosh
2008-09-10 16:25       ` Boaz Harrosh
     [not found]       ` <48C7F19D.3080507-C4P08NqkoRlBDgjK7y7TUQ@public.gmane.org>
2008-09-10 19:20         ` Dave Kleikamp
2008-09-10 19:20           ` Dave Kleikamp
2008-09-11  8:30           ` Boaz Harrosh
2008-09-11  1:51       ` Chris Leech
2008-09-10 16:25     ` Chris Leech
2008-09-10 17:45       ` [Open-FCoE] " Chris Leech
2008-09-10 18:04         ` Boaz Harrosh
2008-09-10 18:04           ` Boaz Harrosh
2008-09-10 18:23         ` Dave Kleikamp

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48C3A0A9.3000206@panasas.com \
    --to=bharrosh@panasas.com \
    --cc=christopher.leech@intel.com \
    --cc=devel@open-fcoe.org \
    --cc=harvey.harrison@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.