Re: [PATCH 09/13] Core WQE/CQE Types

2006-11-17 Thread Steve Wise
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_ta:8;
uint32_tb:24;
uint32_tc:16;
uint32_td:8;
uint32_te:8;
};

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

struct bits {
#if 0 /* BE */
uint32_ta:4;
uint32_tb:4;
#else /* LE */
uint32_tb:4;
uint32_ta:4;
#endif
uint32_tc:8;
uint32_td:8;
uint32_te: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; i8; 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; i8; 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; i4; i++)
printf(%02x, *cp++);
printf(\n);
}




-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 09/13] Core WQE/CQE Types

2006-11-16 Thread Roland Dreier
  +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+ */
  +};
-
To unsubscribe from this list: send the line unsubscribe netdev in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 09/13] Core WQE/CQE Types

2006-11-15 Thread Steve Wise

T3 WQE and CQE structures, defines, etc...

Signed-off-by: Steve Wise [EMAIL PROTECTED]
---

 drivers/infiniband/hw/cxgb3/core/cxio_wr.h |  658 
 1 files changed, 658 insertions(+), 0 deletions(-)

diff --git a/drivers/infiniband/hw/cxgb3/core/cxio_wr.h 
b/drivers/infiniband/hw/cxgb3/core/cxio_wr.h
new file mode 100644
index 000..ad84708
--- /dev/null
+++ b/drivers/infiniband/hw/cxgb3/core/cxio_wr.h
@@ -0,0 +1,658 @@
+/*
+ * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2006 Open Grid Computing, Inc. All rights reserved.
+ *
+ * This software is available to you under a choice of one of two
+ * licenses.  You may choose to be licensed under the terms of the GNU
+ * General Public License (GPL) Version 2, available from the file
+ * COPYING in the main directory of this source tree, or the
+ * OpenIB.org BSD license below:
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ *  - Redistributions of source code must retain the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer.
+ *
+ *  - Redistributions in binary form must reproduce the above
+ *copyright notice, this list of conditions and the following
+ *disclaimer in the documentation and/or other materials
+ *provided with the distribution.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+#ifndef __CXIO_WR_H__
+#define __CXIO_WR_H__
+
+#include asm/io.h
+#include linux/pci.h
+#include linux/timer.h
+#include firmware_exports.h
+
+#define T3_MAX_SGE  4
+
+#define Q_EMPTY(rptr,wptr) ((rptr)==(wptr))
+#define Q_FULL(rptr,wptr,size_log2)  ( (((wptr)-(rptr))(size_log2))  \
+  ((rptr)!=(wptr)) )
+#define Q_GENBIT(ptr,size_log2) (!(((ptr)size_log2)0x1))
+#define Q_FREECNT(rptr,wptr,size_log2) ((1ULsize_log2)-((wptr)-(rptr)))
+#define Q_COUNT(rptr,wptr) ((wptr)-(rptr))
+#define Q_PTR2IDX(ptr,size_log2) (ptr  ((1ULsize_log2)-1))
+#define RING_DOORBELL(doorbell, QPID) { \
+   (writel(((131) | (QPID)), doorbell)); \
+}
+
+#define SEQ32_GE(x,y) (!( (((u32) (x)) - ((u32) (y)))  0x8000 ))
+
+enum t3_wr_flags {
+   T3_COMPLETION_FLAG = 0x01,
+   T3_NOTIFY_FLAG = 0x02,
+   T3_SOLICITED_EVENT_FLAG = 0x04,
+   T3_READ_FENCE_FLAG = 0x08,
+   T3_LOCAL_FENCE_FLAG = 0x10
+} __attribute__ ((packed));
+
+enum t3_wr_opcode {
+   T3_WR_BP = FW_WROPCODE_RI_BYPASS,
+   T3_WR_SEND = FW_WROPCODE_RI_SEND,
+   T3_WR_WRITE = FW_WROPCODE_RI_RDMA_WRITE,
+   T3_WR_READ = FW_WROPCODE_RI_RDMA_READ,
+   T3_WR_INV_STAG = FW_WROPCODE_RI_LOCAL_INV,
+   T3_WR_BIND = FW_WROPCODE_RI_BIND_MW,
+   T3_WR_RCV = FW_WROPCODE_RI_RECEIVE,
+   T3_WR_INIT = FW_WROPCODE_RI_RDMA_INIT,
+   T3_WR_QP_MOD = FW_WROPCODE_RI_MODIFY_QP
+} __attribute__ ((packed));
+
+enum t3_rdma_opcode {
+   T3_RDMA_WRITE,  /* IETF RDMAP v1.0 ... */
+   T3_READ_REQ,
+   T3_READ_RESP,
+   T3_SEND,
+   T3_SEND_WITH_INV,
+   T3_SEND_WITH_SE,
+   T3_SEND_WITH_SE_INV,
+   T3_TERMINATE,
+   T3_RDMA_INIT,   /* CHELSIO RI specific ... */
+   T3_BIND_MW,
+   T3_FAST_REGISTER,
+   T3_LOCAL_INV,
+   T3_QP_MOD,
+   T3_BYPASS
+} __attribute__ ((packed));
+
+static inline enum t3_rdma_opcode wr2opcode(enum t3_wr_opcode wrop)
+{
+   switch (wrop) {
+   case T3_WR_BP: return T3_BYPASS;
+   case T3_WR_SEND: return T3_SEND;
+   case T3_WR_WRITE: return T3_RDMA_WRITE;
+   case T3_WR_READ: return T3_READ_REQ;
+   case T3_WR_INV_STAG: return T3_LOCAL_INV;
+   case T3_WR_BIND: return T3_BIND_MW;
+   case T3_WR_INIT: return T3_RDMA_INIT;
+   case T3_WR_QP_MOD: return T3_QP_MOD;
+   default: break;
+   }
+   return -1;
+}
+
+
+/* Work request id */
+union t3_wrid {
+   struct {
+   u32 hi:32;
+   u32 low:32;
+   } id0;
+   u64 id1;
+};
+
+#define WRID(wrid) (wrid.id1)
+#define WRID_GEN(wrid) (wrid.id0.wr_gen)
+#define WRID_IDX(wrid) (wrid.id0.wr_idx)
+#define WRID_LO(wrid)  (wrid.id0.wr_lo)
+
+struct fw_riwrh {
+   u32 op_seop_flags;
+   u32 gen_tid_len;
+};
+
+#define S_FW_RIWR_OP   24
+#define M_FW_RIWR_OP   0xff
+#define V_FW_RIWR_OP(x)((x)