blob: de760e9f1cc6d3116499180f94ab08ec8bf6df4c [file] [log] [blame]
Steve Wiseb038ced2007-02-12 16:16:18 -08001/*
2 * Copyright (c) 2006 Chelsio, Inc. All rights reserved.
Steve Wiseb038ced2007-02-12 16:16:18 -08003 *
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
9 *
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
12 * conditions are met:
13 *
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer.
17 *
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
22 *
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
30 * SOFTWARE.
31 */
32#ifndef __CXIO_WR_H__
33#define __CXIO_WR_H__
34
35#include <asm/io.h>
36#include <linux/pci.h>
37#include <linux/timer.h>
38#include "firmware_exports.h"
39
40#define T3_MAX_SGE 4
Steve Wise1860cdf2007-04-26 15:21:09 -050041#define T3_MAX_INLINE 64
Steve Wiseb038ced2007-02-12 16:16:18 -080042
43#define Q_EMPTY(rptr,wptr) ((rptr)==(wptr))
44#define Q_FULL(rptr,wptr,size_log2) ( (((wptr)-(rptr))>>(size_log2)) && \
45 ((rptr)!=(wptr)) )
46#define Q_GENBIT(ptr,size_log2) (!(((ptr)>>size_log2)&0x1))
47#define Q_FREECNT(rptr,wptr,size_log2) ((1UL<<size_log2)-((wptr)-(rptr)))
48#define Q_COUNT(rptr,wptr) ((wptr)-(rptr))
49#define Q_PTR2IDX(ptr,size_log2) (ptr & ((1UL<<size_log2)-1))
50
51static inline void ring_doorbell(void __iomem *doorbell, u32 qpid)
52{
53 writel(((1<<31) | qpid), doorbell);
54}
55
56#define SEQ32_GE(x,y) (!( (((u32) (x)) - ((u32) (y))) & 0x80000000 ))
57
58enum t3_wr_flags {
59 T3_COMPLETION_FLAG = 0x01,
60 T3_NOTIFY_FLAG = 0x02,
61 T3_SOLICITED_EVENT_FLAG = 0x04,
62 T3_READ_FENCE_FLAG = 0x08,
63 T3_LOCAL_FENCE_FLAG = 0x10
64} __attribute__ ((packed));
65
66enum t3_wr_opcode {
67 T3_WR_BP = FW_WROPCODE_RI_BYPASS,
68 T3_WR_SEND = FW_WROPCODE_RI_SEND,
69 T3_WR_WRITE = FW_WROPCODE_RI_RDMA_WRITE,
70 T3_WR_READ = FW_WROPCODE_RI_RDMA_READ,
71 T3_WR_INV_STAG = FW_WROPCODE_RI_LOCAL_INV,
72 T3_WR_BIND = FW_WROPCODE_RI_BIND_MW,
73 T3_WR_RCV = FW_WROPCODE_RI_RECEIVE,
74 T3_WR_INIT = FW_WROPCODE_RI_RDMA_INIT,
Steve Wisee7e55822008-07-14 23:48:45 -070075 T3_WR_QP_MOD = FW_WROPCODE_RI_MODIFY_QP,
76 T3_WR_FASTREG = FW_WROPCODE_RI_FASTREGISTER_MR
Steve Wiseb038ced2007-02-12 16:16:18 -080077} __attribute__ ((packed));
78
79enum t3_rdma_opcode {
80 T3_RDMA_WRITE, /* IETF RDMAP v1.0 ... */
81 T3_READ_REQ,
82 T3_READ_RESP,
83 T3_SEND,
84 T3_SEND_WITH_INV,
85 T3_SEND_WITH_SE,
86 T3_SEND_WITH_SE_INV,
87 T3_TERMINATE,
88 T3_RDMA_INIT, /* CHELSIO RI specific ... */
89 T3_BIND_MW,
90 T3_FAST_REGISTER,
91 T3_LOCAL_INV,
92 T3_QP_MOD,
Steve Wisee7e55822008-07-14 23:48:45 -070093 T3_BYPASS,
94 T3_RDMA_READ_REQ_WITH_INV,
Steve Wiseb038ced2007-02-12 16:16:18 -080095} __attribute__ ((packed));
96
97static inline enum t3_rdma_opcode wr2opcode(enum t3_wr_opcode wrop)
98{
99 switch (wrop) {
100 case T3_WR_BP: return T3_BYPASS;
101 case T3_WR_SEND: return T3_SEND;
102 case T3_WR_WRITE: return T3_RDMA_WRITE;
103 case T3_WR_READ: return T3_READ_REQ;
104 case T3_WR_INV_STAG: return T3_LOCAL_INV;
105 case T3_WR_BIND: return T3_BIND_MW;
106 case T3_WR_INIT: return T3_RDMA_INIT;
107 case T3_WR_QP_MOD: return T3_QP_MOD;
Steve Wisee7e55822008-07-14 23:48:45 -0700108 case T3_WR_FASTREG: return T3_FAST_REGISTER;
Steve Wiseb038ced2007-02-12 16:16:18 -0800109 default: break;
110 }
111 return -1;
112}
113
114
115/* Work request id */
116union t3_wrid {
117 struct {
118 u32 hi;
119 u32 low;
120 } id0;
121 u64 id1;
122};
123
124#define WRID(wrid) (wrid.id1)
125#define WRID_GEN(wrid) (wrid.id0.wr_gen)
126#define WRID_IDX(wrid) (wrid.id0.wr_idx)
127#define WRID_LO(wrid) (wrid.id0.wr_lo)
128
129struct fw_riwrh {
130 __be32 op_seop_flags;
131 __be32 gen_tid_len;
132};
133
134#define S_FW_RIWR_OP 24
135#define M_FW_RIWR_OP 0xff
136#define V_FW_RIWR_OP(x) ((x) << S_FW_RIWR_OP)
137#define G_FW_RIWR_OP(x) ((((x) >> S_FW_RIWR_OP)) & M_FW_RIWR_OP)
138
139#define S_FW_RIWR_SOPEOP 22
140#define M_FW_RIWR_SOPEOP 0x3
141#define V_FW_RIWR_SOPEOP(x) ((x) << S_FW_RIWR_SOPEOP)
142
143#define S_FW_RIWR_FLAGS 8
144#define M_FW_RIWR_FLAGS 0x3fffff
145#define V_FW_RIWR_FLAGS(x) ((x) << S_FW_RIWR_FLAGS)
146#define G_FW_RIWR_FLAGS(x) ((((x) >> S_FW_RIWR_FLAGS)) & M_FW_RIWR_FLAGS)
147
148#define S_FW_RIWR_TID 8
149#define V_FW_RIWR_TID(x) ((x) << S_FW_RIWR_TID)
150
151#define S_FW_RIWR_LEN 0
152#define V_FW_RIWR_LEN(x) ((x) << S_FW_RIWR_LEN)
153
154#define S_FW_RIWR_GEN 31
155#define V_FW_RIWR_GEN(x) ((x) << S_FW_RIWR_GEN)
156
157struct t3_sge {
158 __be32 stag;
159 __be32 len;
160 __be64 to;
161};
162
163/* If num_sgle is zero, flit 5+ contains immediate data.*/
164struct t3_send_wr {
165 struct fw_riwrh wrh; /* 0 */
166 union t3_wrid wrid; /* 1 */
167
168 u8 rdmaop; /* 2 */
169 u8 reserved[3];
170 __be32 rem_stag;
171 __be32 plen; /* 3 */
172 __be32 num_sgle;
173 struct t3_sge sgl[T3_MAX_SGE]; /* 4+ */
174};
175
Steve Wisee7e55822008-07-14 23:48:45 -0700176#define T3_MAX_FASTREG_DEPTH 24
177#define T3_MAX_FASTREG_FRAG 10
178
179struct t3_fastreg_wr {
180 struct fw_riwrh wrh; /* 0 */
181 union t3_wrid wrid; /* 1 */
182 __be32 stag; /* 2 */
183 __be32 len;
184 __be32 va_base_hi; /* 3 */
185 __be32 va_base_lo_fbo;
186 __be32 page_type_perms; /* 4 */
187 __be32 reserved1;
188 __be64 pbl_addrs[0]; /* 5+ */
189};
190
191/*
192 * If a fastreg wr spans multiple wqes, then the 2nd fragment look like this.
193 */
194struct t3_pbl_frag {
195 struct fw_riwrh wrh; /* 0 */
196 __be64 pbl_addrs[14]; /* 1..14 */
197};
198
199#define S_FR_PAGE_COUNT 24
200#define M_FR_PAGE_COUNT 0xff
201#define V_FR_PAGE_COUNT(x) ((x) << S_FR_PAGE_COUNT)
202#define G_FR_PAGE_COUNT(x) ((((x) >> S_FR_PAGE_COUNT)) & M_FR_PAGE_COUNT)
203
204#define S_FR_PAGE_SIZE 16
205#define M_FR_PAGE_SIZE 0x1f
206#define V_FR_PAGE_SIZE(x) ((x) << S_FR_PAGE_SIZE)
207#define G_FR_PAGE_SIZE(x) ((((x) >> S_FR_PAGE_SIZE)) & M_FR_PAGE_SIZE)
208
209#define S_FR_TYPE 8
210#define M_FR_TYPE 0x1
211#define V_FR_TYPE(x) ((x) << S_FR_TYPE)
212#define G_FR_TYPE(x) ((((x) >> S_FR_TYPE)) & M_FR_TYPE)
213
214#define S_FR_PERMS 0
215#define M_FR_PERMS 0xff
216#define V_FR_PERMS(x) ((x) << S_FR_PERMS)
217#define G_FR_PERMS(x) ((((x) >> S_FR_PERMS)) & M_FR_PERMS)
218
Steve Wiseb038ced2007-02-12 16:16:18 -0800219struct t3_local_inv_wr {
220 struct fw_riwrh wrh; /* 0 */
221 union t3_wrid wrid; /* 1 */
222 __be32 stag; /* 2 */
Steve Wisee7e55822008-07-14 23:48:45 -0700223 __be32 reserved;
Steve Wiseb038ced2007-02-12 16:16:18 -0800224};
225
226struct t3_rdma_write_wr {
227 struct fw_riwrh wrh; /* 0 */
228 union t3_wrid wrid; /* 1 */
229 u8 rdmaop; /* 2 */
230 u8 reserved[3];
231 __be32 stag_sink;
232 __be64 to_sink; /* 3 */
233 __be32 plen; /* 4 */
234 __be32 num_sgle;
235 struct t3_sge sgl[T3_MAX_SGE]; /* 5+ */
236};
237
238struct t3_rdma_read_wr {
239 struct fw_riwrh wrh; /* 0 */
240 union t3_wrid wrid; /* 1 */
241 u8 rdmaop; /* 2 */
Steve Wisee7e55822008-07-14 23:48:45 -0700242 u8 local_inv;
243 u8 reserved[2];
Steve Wiseb038ced2007-02-12 16:16:18 -0800244 __be32 rem_stag;
245 __be64 rem_to; /* 3 */
246 __be32 local_stag; /* 4 */
247 __be32 local_len;
248 __be64 local_to; /* 5 */
249};
250
Steve Wiseb038ced2007-02-12 16:16:18 -0800251struct t3_bind_mw_wr {
252 struct fw_riwrh wrh; /* 0 */
253 union t3_wrid wrid; /* 1 */
254 u16 reserved; /* 2 */
255 u8 type;
256 u8 perms;
257 __be32 mr_stag;
258 __be32 mw_stag; /* 3 */
259 __be32 mw_len;
260 __be64 mw_va; /* 4 */
261 __be32 mr_pbl_addr; /* 5 */
262 u8 reserved2[3];
263 u8 mr_pagesz;
264};
265
266struct t3_receive_wr {
267 struct fw_riwrh wrh; /* 0 */
268 union t3_wrid wrid; /* 1 */
269 u8 pagesz[T3_MAX_SGE];
270 __be32 num_sgle; /* 2 */
271 struct t3_sge sgl[T3_MAX_SGE]; /* 3+ */
272 __be32 pbl_addr[T3_MAX_SGE];
273};
274
275struct t3_bypass_wr {
276 struct fw_riwrh wrh;
277 union t3_wrid wrid; /* 1 */
278};
279
280struct t3_modify_qp_wr {
281 struct fw_riwrh wrh; /* 0 */
282 union t3_wrid wrid; /* 1 */
283 __be32 flags; /* 2 */
284 __be32 quiesce; /* 2 */
285 __be32 max_ird; /* 3 */
286 __be32 max_ord; /* 3 */
287 __be64 sge_cmd; /* 4 */
288 __be64 ctx1; /* 5 */
289 __be64 ctx0; /* 6 */
290};
291
292enum t3_modify_qp_flags {
293 MODQP_QUIESCE = 0x01,
294 MODQP_MAX_IRD = 0x02,
295 MODQP_MAX_ORD = 0x04,
296 MODQP_WRITE_EC = 0x08,
297 MODQP_READ_EC = 0x10,
298};
299
300
301enum t3_mpa_attrs {
302 uP_RI_MPA_RX_MARKER_ENABLE = 0x1,
303 uP_RI_MPA_TX_MARKER_ENABLE = 0x2,
304 uP_RI_MPA_CRC_ENABLE = 0x4,
305 uP_RI_MPA_IETF_ENABLE = 0x8
306} __attribute__ ((packed));
307
308enum t3_qp_caps {
309 uP_RI_QP_RDMA_READ_ENABLE = 0x01,
310 uP_RI_QP_RDMA_WRITE_ENABLE = 0x02,
311 uP_RI_QP_BIND_ENABLE = 0x04,
312 uP_RI_QP_FAST_REGISTER_ENABLE = 0x08,
313 uP_RI_QP_STAG0_ENABLE = 0x10
314} __attribute__ ((packed));
315
Steve Wisef8b0dfd2008-04-29 13:46:52 -0700316enum rdma_init_rtr_types {
317 RTR_READ = 1,
318 RTR_WRITE = 2,
319 RTR_SEND = 3,
320};
321
322#define S_RTR_TYPE 2
323#define M_RTR_TYPE 0x3
324#define V_RTR_TYPE(x) ((x) << S_RTR_TYPE)
325#define G_RTR_TYPE(x) ((((x) >> S_RTR_TYPE)) & M_RTR_TYPE)
326
Steve Wiseb038ced2007-02-12 16:16:18 -0800327struct t3_rdma_init_attr {
328 u32 tid;
329 u32 qpid;
330 u32 pdid;
331 u32 scqid;
332 u32 rcqid;
333 u32 rq_addr;
334 u32 rq_size;
335 enum t3_mpa_attrs mpaattrs;
336 enum t3_qp_caps qpcaps;
337 u16 tcp_emss;
338 u32 ord;
339 u32 ird;
340 u64 qp_dma_addr;
341 u32 qp_dma_size;
Steve Wisef8b0dfd2008-04-29 13:46:52 -0700342 enum rdma_init_rtr_types rtr_type;
343 u16 flags;
344 u16 rqe_count;
Steve Wisede3d3532007-05-14 13:27:27 -0500345 u32 irs;
Steve Wiseb038ced2007-02-12 16:16:18 -0800346};
347
348struct t3_rdma_init_wr {
349 struct fw_riwrh wrh; /* 0 */
350 union t3_wrid wrid; /* 1 */
351 __be32 qpid; /* 2 */
352 __be32 pdid;
353 __be32 scqid; /* 3 */
354 __be32 rcqid;
355 __be32 rq_addr; /* 4 */
356 __be32 rq_size;
357 u8 mpaattrs; /* 5 */
358 u8 qpcaps;
359 __be16 ulpdu_size;
Steve Wisef8b0dfd2008-04-29 13:46:52 -0700360 __be16 flags_rtr_type;
361 __be16 rqe_count;
Steve Wiseb038ced2007-02-12 16:16:18 -0800362 __be32 ord; /* 6 */
363 __be32 ird;
364 __be64 qp_dma_addr; /* 7 */
365 __be32 qp_dma_size; /* 8 */
Roland Dreier1d6e6582008-01-25 14:15:42 -0800366 __be32 irs;
Steve Wiseb038ced2007-02-12 16:16:18 -0800367};
368
369struct t3_genbit {
370 u64 flit[15];
371 __be64 genbit;
372};
373
Steve Wisee7e55822008-07-14 23:48:45 -0700374struct t3_wq_in_err {
375 u64 flit[13];
376 u64 err;
377};
378
Steve Wiseb038ced2007-02-12 16:16:18 -0800379enum rdma_init_wr_flags {
Steve Wisef8b0dfd2008-04-29 13:46:52 -0700380 MPA_INITIATOR = (1<<0),
Steve Wisec6b5b502008-01-21 14:42:13 -0600381 PRIV_QP = (1<<1),
Steve Wiseb038ced2007-02-12 16:16:18 -0800382};
383
384union t3_wr {
385 struct t3_send_wr send;
386 struct t3_rdma_write_wr write;
387 struct t3_rdma_read_wr read;
388 struct t3_receive_wr recv;
Steve Wisee7e55822008-07-14 23:48:45 -0700389 struct t3_fastreg_wr fastreg;
390 struct t3_pbl_frag pbl_frag;
Steve Wiseb038ced2007-02-12 16:16:18 -0800391 struct t3_local_inv_wr local_inv;
392 struct t3_bind_mw_wr bind;
393 struct t3_bypass_wr bypass;
394 struct t3_rdma_init_wr init;
395 struct t3_modify_qp_wr qp_mod;
396 struct t3_genbit genbit;
Steve Wisee7e55822008-07-14 23:48:45 -0700397 struct t3_wq_in_err wq_in_err;
398 __be64 flit[16];
Steve Wiseb038ced2007-02-12 16:16:18 -0800399};
400
401#define T3_SQ_CQE_FLIT 13
402#define T3_SQ_COOKIE_FLIT 14
403
404#define T3_RQ_COOKIE_FLIT 13
405#define T3_RQ_CQE_FLIT 14
406
407static inline enum t3_wr_opcode fw_riwrh_opcode(struct fw_riwrh *wqe)
408{
409 return G_FW_RIWR_OP(be32_to_cpu(wqe->op_seop_flags));
410}
411
Steve Wisee7e55822008-07-14 23:48:45 -0700412enum t3_wr_hdr_bits {
413 T3_EOP = 1,
414 T3_SOP = 2,
415 T3_SOPEOP = T3_EOP|T3_SOP,
416};
417
Steve Wiseb038ced2007-02-12 16:16:18 -0800418static inline void build_fw_riwrh(struct fw_riwrh *wqe, enum t3_wr_opcode op,
419 enum t3_wr_flags flags, u8 genbit, u32 tid,
Steve Wisee7e55822008-07-14 23:48:45 -0700420 u8 len, u8 sopeop)
Steve Wiseb038ced2007-02-12 16:16:18 -0800421{
422 wqe->op_seop_flags = cpu_to_be32(V_FW_RIWR_OP(op) |
Steve Wisee7e55822008-07-14 23:48:45 -0700423 V_FW_RIWR_SOPEOP(sopeop) |
Steve Wiseb038ced2007-02-12 16:16:18 -0800424 V_FW_RIWR_FLAGS(flags));
425 wmb();
426 wqe->gen_tid_len = cpu_to_be32(V_FW_RIWR_GEN(genbit) |
427 V_FW_RIWR_TID(tid) |
428 V_FW_RIWR_LEN(len));
429 /* 2nd gen bit... */
430 ((union t3_wr *)wqe)->genbit.genbit = cpu_to_be64(genbit);
431}
432
433/*
434 * T3 ULP2_TX commands
435 */
436enum t3_utx_mem_op {
437 T3_UTX_MEM_READ = 2,
438 T3_UTX_MEM_WRITE = 3
439};
440
441/* T3 MC7 RDMA TPT entry format */
442
443enum tpt_mem_type {
444 TPT_NON_SHARED_MR = 0x0,
445 TPT_SHARED_MR = 0x1,
446 TPT_MW = 0x2,
447 TPT_MW_RELAXED_PROTECTION = 0x3
448};
449
450enum tpt_addr_type {
451 TPT_ZBTO = 0,
452 TPT_VATO = 1
453};
454
455enum tpt_mem_perm {
Steve Wisee7e55822008-07-14 23:48:45 -0700456 TPT_MW_BIND = 0x10,
Steve Wiseb038ced2007-02-12 16:16:18 -0800457 TPT_LOCAL_READ = 0x8,
458 TPT_LOCAL_WRITE = 0x4,
459 TPT_REMOTE_READ = 0x2,
460 TPT_REMOTE_WRITE = 0x1
461};
462
463struct tpt_entry {
464 __be32 valid_stag_pdid;
465 __be32 flags_pagesize_qpid;
466
467 __be32 rsvd_pbl_addr;
468 __be32 len;
469 __be32 va_hi;
470 __be32 va_low_or_fbo;
471
472 __be32 rsvd_bind_cnt_or_pstag;
473 __be32 rsvd_pbl_size;
474};
475
476#define S_TPT_VALID 31
477#define V_TPT_VALID(x) ((x) << S_TPT_VALID)
478#define F_TPT_VALID V_TPT_VALID(1U)
479
480#define S_TPT_STAG_KEY 23
481#define M_TPT_STAG_KEY 0xFF
482#define V_TPT_STAG_KEY(x) ((x) << S_TPT_STAG_KEY)
483#define G_TPT_STAG_KEY(x) (((x) >> S_TPT_STAG_KEY) & M_TPT_STAG_KEY)
484
485#define S_TPT_STAG_STATE 22
486#define V_TPT_STAG_STATE(x) ((x) << S_TPT_STAG_STATE)
487#define F_TPT_STAG_STATE V_TPT_STAG_STATE(1U)
488
489#define S_TPT_STAG_TYPE 20
490#define M_TPT_STAG_TYPE 0x3
491#define V_TPT_STAG_TYPE(x) ((x) << S_TPT_STAG_TYPE)
492#define G_TPT_STAG_TYPE(x) (((x) >> S_TPT_STAG_TYPE) & M_TPT_STAG_TYPE)
493
494#define S_TPT_PDID 0
495#define M_TPT_PDID 0xFFFFF
496#define V_TPT_PDID(x) ((x) << S_TPT_PDID)
497#define G_TPT_PDID(x) (((x) >> S_TPT_PDID) & M_TPT_PDID)
498
499#define S_TPT_PERM 28
500#define M_TPT_PERM 0xF
501#define V_TPT_PERM(x) ((x) << S_TPT_PERM)
502#define G_TPT_PERM(x) (((x) >> S_TPT_PERM) & M_TPT_PERM)
503
504#define S_TPT_REM_INV_DIS 27
505#define V_TPT_REM_INV_DIS(x) ((x) << S_TPT_REM_INV_DIS)
506#define F_TPT_REM_INV_DIS V_TPT_REM_INV_DIS(1U)
507
508#define S_TPT_ADDR_TYPE 26
509#define V_TPT_ADDR_TYPE(x) ((x) << S_TPT_ADDR_TYPE)
510#define F_TPT_ADDR_TYPE V_TPT_ADDR_TYPE(1U)
511
512#define S_TPT_MW_BIND_ENABLE 25
513#define V_TPT_MW_BIND_ENABLE(x) ((x) << S_TPT_MW_BIND_ENABLE)
514#define F_TPT_MW_BIND_ENABLE V_TPT_MW_BIND_ENABLE(1U)
515
516#define S_TPT_PAGE_SIZE 20
517#define M_TPT_PAGE_SIZE 0x1F
518#define V_TPT_PAGE_SIZE(x) ((x) << S_TPT_PAGE_SIZE)
519#define G_TPT_PAGE_SIZE(x) (((x) >> S_TPT_PAGE_SIZE) & M_TPT_PAGE_SIZE)
520
521#define S_TPT_PBL_ADDR 0
522#define M_TPT_PBL_ADDR 0x1FFFFFFF
523#define V_TPT_PBL_ADDR(x) ((x) << S_TPT_PBL_ADDR)
524#define G_TPT_PBL_ADDR(x) (((x) >> S_TPT_PBL_ADDR) & M_TPT_PBL_ADDR)
525
526#define S_TPT_QPID 0
527#define M_TPT_QPID 0xFFFFF
528#define V_TPT_QPID(x) ((x) << S_TPT_QPID)
529#define G_TPT_QPID(x) (((x) >> S_TPT_QPID) & M_TPT_QPID)
530
531#define S_TPT_PSTAG 0
532#define M_TPT_PSTAG 0xFFFFFF
533#define V_TPT_PSTAG(x) ((x) << S_TPT_PSTAG)
534#define G_TPT_PSTAG(x) (((x) >> S_TPT_PSTAG) & M_TPT_PSTAG)
535
536#define S_TPT_PBL_SIZE 0
537#define M_TPT_PBL_SIZE 0xFFFFF
538#define V_TPT_PBL_SIZE(x) ((x) << S_TPT_PBL_SIZE)
539#define G_TPT_PBL_SIZE(x) (((x) >> S_TPT_PBL_SIZE) & M_TPT_PBL_SIZE)
540
541/*
542 * CQE defs
543 */
544struct t3_cqe {
545 __be32 header;
546 __be32 len;
547 union {
548 struct {
549 __be32 stag;
550 __be32 msn;
551 } rcqe;
552 struct {
553 u32 wrid_hi;
554 u32 wrid_low;
555 } scqe;
556 } u;
557};
558
559#define S_CQE_OOO 31
560#define M_CQE_OOO 0x1
561#define G_CQE_OOO(x) ((((x) >> S_CQE_OOO)) & M_CQE_OOO)
562#define V_CEQ_OOO(x) ((x)<<S_CQE_OOO)
563
564#define S_CQE_QPID 12
565#define M_CQE_QPID 0x7FFFF
566#define G_CQE_QPID(x) ((((x) >> S_CQE_QPID)) & M_CQE_QPID)
567#define V_CQE_QPID(x) ((x)<<S_CQE_QPID)
568
569#define S_CQE_SWCQE 11
570#define M_CQE_SWCQE 0x1
571#define G_CQE_SWCQE(x) ((((x) >> S_CQE_SWCQE)) & M_CQE_SWCQE)
572#define V_CQE_SWCQE(x) ((x)<<S_CQE_SWCQE)
573
574#define S_CQE_GENBIT 10
575#define M_CQE_GENBIT 0x1
576#define G_CQE_GENBIT(x) (((x) >> S_CQE_GENBIT) & M_CQE_GENBIT)
577#define V_CQE_GENBIT(x) ((x)<<S_CQE_GENBIT)
578
579#define S_CQE_STATUS 5
580#define M_CQE_STATUS 0x1F
581#define G_CQE_STATUS(x) ((((x) >> S_CQE_STATUS)) & M_CQE_STATUS)
582#define V_CQE_STATUS(x) ((x)<<S_CQE_STATUS)
583
584#define S_CQE_TYPE 4
585#define M_CQE_TYPE 0x1
586#define G_CQE_TYPE(x) ((((x) >> S_CQE_TYPE)) & M_CQE_TYPE)
587#define V_CQE_TYPE(x) ((x)<<S_CQE_TYPE)
588
589#define S_CQE_OPCODE 0
590#define M_CQE_OPCODE 0xF
591#define G_CQE_OPCODE(x) ((((x) >> S_CQE_OPCODE)) & M_CQE_OPCODE)
592#define V_CQE_OPCODE(x) ((x)<<S_CQE_OPCODE)
593
594#define SW_CQE(x) (G_CQE_SWCQE(be32_to_cpu((x).header)))
595#define CQE_OOO(x) (G_CQE_OOO(be32_to_cpu((x).header)))
596#define CQE_QPID(x) (G_CQE_QPID(be32_to_cpu((x).header)))
597#define CQE_GENBIT(x) (G_CQE_GENBIT(be32_to_cpu((x).header)))
598#define CQE_TYPE(x) (G_CQE_TYPE(be32_to_cpu((x).header)))
599#define SQ_TYPE(x) (CQE_TYPE((x)))
600#define RQ_TYPE(x) (!CQE_TYPE((x)))
601#define CQE_STATUS(x) (G_CQE_STATUS(be32_to_cpu((x).header)))
602#define CQE_OPCODE(x) (G_CQE_OPCODE(be32_to_cpu((x).header)))
603
604#define CQE_LEN(x) (be32_to_cpu((x).len))
605
606/* used for RQ completion processing */
607#define CQE_WRID_STAG(x) (be32_to_cpu((x).u.rcqe.stag))
608#define CQE_WRID_MSN(x) (be32_to_cpu((x).u.rcqe.msn))
609
610/* used for SQ completion processing */
611#define CQE_WRID_SQ_WPTR(x) ((x).u.scqe.wrid_hi)
612#define CQE_WRID_WPTR(x) ((x).u.scqe.wrid_low)
613
614/* generic accessor macros */
615#define CQE_WRID_HI(x) ((x).u.scqe.wrid_hi)
616#define CQE_WRID_LOW(x) ((x).u.scqe.wrid_low)
617
618#define TPT_ERR_SUCCESS 0x0
619#define TPT_ERR_STAG 0x1 /* STAG invalid: either the */
620 /* STAG is offlimt, being 0, */
621 /* or STAG_key mismatch */
622#define TPT_ERR_PDID 0x2 /* PDID mismatch */
623#define TPT_ERR_QPID 0x3 /* QPID mismatch */
624#define TPT_ERR_ACCESS 0x4 /* Invalid access right */
625#define TPT_ERR_WRAP 0x5 /* Wrap error */
626#define TPT_ERR_BOUND 0x6 /* base and bounds voilation */
627#define TPT_ERR_INVALIDATE_SHARED_MR 0x7 /* attempt to invalidate a */
628 /* shared memory region */
629#define TPT_ERR_INVALIDATE_MR_WITH_MW_BOUND 0x8 /* attempt to invalidate a */
630 /* shared memory region */
631#define TPT_ERR_ECC 0x9 /* ECC error detected */
632#define TPT_ERR_ECC_PSTAG 0xA /* ECC error detected when */
633 /* reading PSTAG for a MW */
634 /* Invalidate */
635#define TPT_ERR_PBL_ADDR_BOUND 0xB /* pbl addr out of bounds: */
636 /* software error */
637#define TPT_ERR_SWFLUSH 0xC /* SW FLUSHED */
638#define TPT_ERR_CRC 0x10 /* CRC error */
639#define TPT_ERR_MARKER 0x11 /* Marker error */
640#define TPT_ERR_PDU_LEN_ERR 0x12 /* invalid PDU length */
641#define TPT_ERR_OUT_OF_RQE 0x13 /* out of RQE */
642#define TPT_ERR_DDP_VERSION 0x14 /* wrong DDP version */
643#define TPT_ERR_RDMA_VERSION 0x15 /* wrong RDMA version */
644#define TPT_ERR_OPCODE 0x16 /* invalid rdma opcode */
645#define TPT_ERR_DDP_QUEUE_NUM 0x17 /* invalid ddp queue number */
646#define TPT_ERR_MSN 0x18 /* MSN error */
647#define TPT_ERR_TBIT 0x19 /* tag bit not set correctly */
648#define TPT_ERR_MO 0x1A /* MO not 0 for TERMINATE */
649 /* or READ_REQ */
650#define TPT_ERR_MSN_GAP 0x1B
651#define TPT_ERR_MSN_RANGE 0x1C
652#define TPT_ERR_IRD_OVERFLOW 0x1D
653#define TPT_ERR_RQE_ADDR_BOUND 0x1E /* RQE addr out of bounds: */
654 /* software error */
655#define TPT_ERR_INTERNAL_ERR 0x1F /* internal error (opcode */
656 /* mismatch) */
657
658struct t3_swsq {
659 __u64 wr_id;
660 struct t3_cqe cqe;
661 __u32 sq_wptr;
662 __be32 read_len;
663 int opcode;
664 int complete;
665 int signaled;
666};
667
668/*
669 * A T3 WQ implements both the SQ and RQ.
670 */
671struct t3_wq {
672 union t3_wr *queue; /* DMA accessable memory */
673 dma_addr_t dma_addr; /* DMA address for HW */
674 DECLARE_PCI_UNMAP_ADDR(mapping) /* unmap kruft */
675 u32 error; /* 1 once we go to ERROR */
676 u32 qpid;
677 u32 wptr; /* idx to next available WR slot */
678 u32 size_log2; /* total wq size */
679 struct t3_swsq *sq; /* SW SQ */
680 struct t3_swsq *oldest_read; /* tracks oldest pending read */
681 u32 sq_wptr; /* sq_wptr - sq_rptr == count of */
682 u32 sq_rptr; /* pending wrs */
683 u32 sq_size_log2; /* sq size */
684 u64 *rq; /* SW RQ (holds consumer wr_ids */
685 u32 rq_wptr; /* rq_wptr - rq_rptr == count of */
686 u32 rq_rptr; /* pending wrs */
687 u64 *rq_oldest_wr; /* oldest wr on the SW RQ */
688 u32 rq_size_log2; /* rq size */
689 u32 rq_addr; /* rq adapter address */
690 void __iomem *doorbell; /* kernel db */
691 u64 udb; /* user db if any */
692};
693
694struct t3_cq {
695 u32 cqid;
696 u32 rptr;
697 u32 wptr;
698 u32 size_log2;
699 dma_addr_t dma_addr;
700 DECLARE_PCI_UNMAP_ADDR(mapping)
701 struct t3_cqe *queue;
702 struct t3_cqe *sw_queue;
703 u32 sw_rptr;
704 u32 sw_wptr;
705};
706
707#define CQ_VLD_ENTRY(ptr,size_log2,cqe) (Q_GENBIT(ptr,size_log2) == \
708 CQE_GENBIT(*cqe))
709
710static inline void cxio_set_wq_in_error(struct t3_wq *wq)
711{
Steve Wisee7e55822008-07-14 23:48:45 -0700712 wq->queue->wq_in_err.err = 1;
Steve Wiseb038ced2007-02-12 16:16:18 -0800713}
714
715static inline struct t3_cqe *cxio_next_hw_cqe(struct t3_cq *cq)
716{
717 struct t3_cqe *cqe;
718
719 cqe = cq->queue + (Q_PTR2IDX(cq->rptr, cq->size_log2));
720 if (CQ_VLD_ENTRY(cq->rptr, cq->size_log2, cqe))
721 return cqe;
722 return NULL;
723}
724
725static inline struct t3_cqe *cxio_next_sw_cqe(struct t3_cq *cq)
726{
727 struct t3_cqe *cqe;
728
729 if (!Q_EMPTY(cq->sw_rptr, cq->sw_wptr)) {
730 cqe = cq->sw_queue + (Q_PTR2IDX(cq->sw_rptr, cq->size_log2));
731 return cqe;
732 }
733 return NULL;
734}
735
736static inline struct t3_cqe *cxio_next_cqe(struct t3_cq *cq)
737{
738 struct t3_cqe *cqe;
739
740 if (!Q_EMPTY(cq->sw_rptr, cq->sw_wptr)) {
741 cqe = cq->sw_queue + (Q_PTR2IDX(cq->sw_rptr, cq->size_log2));
742 return cqe;
743 }
744 cqe = cq->queue + (Q_PTR2IDX(cq->rptr, cq->size_log2));
745 if (CQ_VLD_ENTRY(cq->rptr, cq->size_log2, cqe))
746 return cqe;
747 return NULL;
748}
749
750#endif