netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Steve Wise" <swise@opengridcomputing.com>
To: "Roland Dreier" <rdreier@cisco.com>
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	openib-general@openib.org
Subject: Re: [PATCH  09/13] Core WQE/CQE Types
Date: Fri, 17 Nov 2006 11:02:44 -0600	[thread overview]
Message-ID: <1163782964.8457.35.camel@stevo-desktop> (raw)
In-Reply-To: <adaveleof4f.fsf@cisco.com>

On Thu, 2006-11-16 at 20:45 -0800, Roland Dreier wrote:
>  > +struct t3_send_wr {
>  > +	struct fw_riwrh wrh;	/* 0 */
>  > +	union t3_wrid wrid;	/* 1 */
>  > +
>  > +	enum t3_rdma_opcode rdmaop:8;
>  > +	u32 reserved:24;	/* 2 */
> 
> Does this do the right thing wrt endianness?  I'd be more comfortable
> with something like
> 
> 	u8 rdmaop;
>         u8 reserved[3];
> 
> (although the __attribute__((packed)) on enum t3_rdma_opcode does make
> it OK to use here, I guess)
> 
>  > +	u32 rem_stag;		/* 2 */
>  > +	u32 plen;		/* 3 */
>  > +	u32 num_sgle;
>  > +	struct t3_sge sgl[T3_MAX_SGE];	/* 4+ */
>  > +};


I don't really like the bit fields either. I inherited these structs and
I'm not adverse to changing them as you suggest to get rid of bit
fields.  But I think they are correct wrt endianness.  I wrote a test
program and on a LE machine it put the u8 first in memory followed by
the 24 bit reserved.  However, I think if you use bit fields less than 8
bits its not endian safe.

BTW:  I don't have a PPC system (yet) to test this code on BE...

Here's a dumb program that plays around with bit fields...

#include <sys/types.h>
#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>

struct foo {
	uint32_t 	a:8;
	uint32_t 	b:24;
	uint32_t	c:16;
	uint32_t	d:8;
	uint32_t	e:8;
};

struct bar {
	uint8_t		a;
	uint8_t		b[3];
	uint16_t	c;
	uint8_t		d;
	uint8_t		e;
};

struct bits {
#if 0 /* BE */
	uint32_t	a:4;
	uint32_t	b:4;
#else /* LE */
	uint32_t	b:4;
	uint32_t	a:4;
#endif
	uint32_t	c:8;
	uint32_t	d:8;
	uint32_t	e:8;
};

main()
{
	struct foo foo;
	struct bar bar;
	struct bits bits;
	uint8_t *cp;
	int i;

	foo.a = 0x01;
	foo.b = 0x020304;
	foo.c = 0x0506;
	foo.d = 0x07;
	foo.e = 0x08;

	printf("foo cpu: 0x%" PRIx64 "\n", *(uint64_t *)&foo);
	printf("foo mem: ");
	cp = (uint8_t *)&foo;
	for (i=0; i<8; i++)
		printf("%02x", *cp++);
	printf("\n");

	bar.a = 0x01;
	bar.b[0] = 0x02;
	bar.b[1] = 0x03;
	bar.b[2] = 0x04;
	bar.c = 0x0506;
	bar.d = 0x07;
	bar.e = 0x08;

	printf("bar cpu: 0x%" PRIx64 "\n", *(uint64_t *)&bar);
	printf("bar mem: ");
	cp = (uint8_t *)&bar;
	for (i=0; i<8; i++)
		printf("%02x", *cp++);
	printf("\n");


	bits.a = 0x1;
	bits.b = 0x2;
	bits.c = 0x3;
	bits.d = 0x4;
	bits.e = 0x5;
	
	printf("bits cpu: 0x%08x\n", *(uint32_t *)&bits);
	printf("bar mem: ");
	cp = (uint8_t *)&bits;
	for (i=0; i<4; i++)
		printf("%02x", *cp++);
	printf("\n");
}

  reply	other threads:[~2006-11-17 17:02 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-11-16  3:58 [PATCH 00/13] Chelsio T3 RDMA Driver Steve Wise
2006-11-16  3:58 ` [PATCH 01/13] Linux RDMA Core Changes Steve Wise
2006-11-16 19:41   ` Roland Dreier
2006-11-16  3:58 ` [PATCH 02/13] Device Discovery and ULLD Linkage Steve Wise
2006-11-17 17:53   ` [openib-general] " Bryan O'Sullivan
2006-11-17 17:59     ` Steve Wise
2006-11-16  3:58 ` [PATCH 03/13] Provider Methods and Data Structures Steve Wise
2006-11-16  3:58 ` [PATCH 04/13] Connection Manager Steve Wise
2006-11-17 18:07   ` [openib-general] " Bryan O'Sullivan
2006-11-17 18:26     ` Steve Wise
2006-11-16  3:58 ` [PATCH 05/13] Queue Pairs Steve Wise
2006-11-16  3:58 ` [PATCH 06/13] Completion Queues Steve Wise
2006-11-16  3:59 ` [PATCH 07/13] Async Event Handler Steve Wise
2006-11-16  3:59 ` [PATCH 08/13] Memory Registration Steve Wise
2006-11-16  3:59 ` [PATCH 09/13] Core WQE/CQE Types Steve Wise
2006-11-17  4:45   ` Roland Dreier
2006-11-17 17:02     ` Steve Wise [this message]
2006-11-17 18:19   ` [openib-general] " Bryan O'Sullivan
2006-11-17 18:32     ` Steve Wise
2006-11-17 18:45       ` Bryan O'Sullivan
2006-11-16  3:59 ` [PATCH 10/13] Core HAL Steve Wise
2006-11-16  3:59 ` [PATCH 11/13] Core Resource Allocation Steve Wise
2006-11-17 16:54   ` Roland Dreier
2006-11-17 17:25     ` Steve Wise
2006-11-17 20:37       ` Roland Dreier
2006-11-16  3:59 ` [PATCH 12/13] Core Debug functions Steve Wise
2006-11-16  3:59 ` [PATCH 13/13] Kconfig/Makefile Steve Wise

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=1163782964.8457.35.camel@stevo-desktop \
    --to=swise@opengridcomputing.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=openib-general@openib.org \
    --cc=rdreier@cisco.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).