blob: aef55f42bea4ed0a59977d9b3455c11833341054 [file] [log] [blame]
Steve Wisecfdda9d2010-04-21 15:30:06 -07001/*
2 * Copyright (c) 2009-2010 Chelsio, Inc. All rights reserved.
3 *
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 * - Redistributions in binary form must reproduce the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer in the documentation and/or other materials
20 * provided with the distribution.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
26 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 * SOFTWARE.
30 */
31#ifndef __T4_H__
32#define __T4_H__
33
34#include "t4_hw.h"
35#include "t4_regs.h"
36#include "t4_msg.h"
37#include "t4fw_ri_api.h"
38
Steve Wisecfdda9d2010-04-21 15:30:06 -070039#define T4_QID_BASE 1024
40#define T4_MAX_QIDS 256
41#define T4_MAX_NUM_QP (1<<16)
42#define T4_MAX_NUM_CQ (1<<15)
43#define T4_MAX_NUM_PD (1<<15)
Steve Wisef64b8842010-05-20 16:58:05 -050044#define T4_EQ_STATUS_ENTRIES (L1_CACHE_BYTES > 64 ? 2 : 1)
45#define T4_MAX_EQ_SIZE (65520 - T4_EQ_STATUS_ENTRIES)
46#define T4_MAX_IQ_SIZE (65520 - 1)
47#define T4_MAX_RQ_SIZE (8192 - T4_EQ_STATUS_ENTRIES)
48#define T4_MAX_SQ_SIZE (T4_MAX_EQ_SIZE - 1)
49#define T4_MAX_QP_DEPTH (T4_MAX_RQ_SIZE - 1)
50#define T4_MAX_CQ_DEPTH (T4_MAX_IQ_SIZE - 1)
Steve Wisecfdda9d2010-04-21 15:30:06 -070051#define T4_MAX_NUM_STAG (1<<15)
52#define T4_MAX_MR_SIZE (~0ULL - 1)
53#define T4_PAGESIZE_MASK 0xffff000 /* 4KB-128MB */
54#define T4_STAG_UNSET 0xffffffff
55#define T4_FW_MAJ 0
56#define T4_EQ_STATUS_ENTRIES (L1_CACHE_BYTES > 64 ? 2 : 1)
57
58struct t4_status_page {
59 __be32 rsvd1; /* flit 0 - hw owns */
60 __be16 rsvd2;
61 __be16 qid;
62 __be16 cidx;
63 __be16 pidx;
64 u8 qp_err; /* flit 1 - sw owns */
65 u8 db_off;
66};
67
Steve Wised37ac312010-06-10 19:03:00 +000068#define T4_EQ_ENTRY_SIZE 64
Steve Wisecfdda9d2010-04-21 15:30:06 -070069
70#define T4_SQ_NUM_SLOTS 4
Steve Wised37ac312010-06-10 19:03:00 +000071#define T4_SQ_NUM_BYTES (T4_EQ_ENTRY_SIZE * T4_SQ_NUM_SLOTS)
Steve Wisecfdda9d2010-04-21 15:30:06 -070072#define T4_MAX_SEND_SGE ((T4_SQ_NUM_BYTES - sizeof(struct fw_ri_send_wr) - \
73 sizeof(struct fw_ri_isgl)) / sizeof(struct fw_ri_sge))
74#define T4_MAX_SEND_INLINE ((T4_SQ_NUM_BYTES - sizeof(struct fw_ri_send_wr) - \
75 sizeof(struct fw_ri_immd)))
76#define T4_MAX_WRITE_INLINE ((T4_SQ_NUM_BYTES - \
77 sizeof(struct fw_ri_rdma_write_wr) - \
78 sizeof(struct fw_ri_immd)))
79#define T4_MAX_WRITE_SGE ((T4_SQ_NUM_BYTES - \
80 sizeof(struct fw_ri_rdma_write_wr) - \
81 sizeof(struct fw_ri_isgl)) / sizeof(struct fw_ri_sge))
82#define T4_MAX_FR_IMMD ((T4_SQ_NUM_BYTES - sizeof(struct fw_ri_fr_nsmr_wr) - \
83 sizeof(struct fw_ri_immd)))
Steve Wisef64b8842010-05-20 16:58:05 -050084#define T4_MAX_FR_DEPTH (T4_MAX_FR_IMMD / sizeof(u64))
Steve Wisecfdda9d2010-04-21 15:30:06 -070085
86#define T4_RQ_NUM_SLOTS 2
Steve Wised37ac312010-06-10 19:03:00 +000087#define T4_RQ_NUM_BYTES (T4_EQ_ENTRY_SIZE * T4_RQ_NUM_SLOTS)
Steve Wisef64b8842010-05-20 16:58:05 -050088#define T4_MAX_RECV_SGE 4
Steve Wisecfdda9d2010-04-21 15:30:06 -070089
90union t4_wr {
91 struct fw_ri_res_wr res;
92 struct fw_ri_wr ri;
93 struct fw_ri_rdma_write_wr write;
94 struct fw_ri_send_wr send;
95 struct fw_ri_rdma_read_wr read;
96 struct fw_ri_bind_mw_wr bind;
97 struct fw_ri_fr_nsmr_wr fr;
98 struct fw_ri_inv_lstag_wr inv;
99 struct t4_status_page status;
Steve Wised37ac312010-06-10 19:03:00 +0000100 __be64 flits[T4_EQ_ENTRY_SIZE / sizeof(__be64) * T4_SQ_NUM_SLOTS];
Steve Wisecfdda9d2010-04-21 15:30:06 -0700101};
102
103union t4_recv_wr {
104 struct fw_ri_recv_wr recv;
105 struct t4_status_page status;
Steve Wised37ac312010-06-10 19:03:00 +0000106 __be64 flits[T4_EQ_ENTRY_SIZE / sizeof(__be64) * T4_RQ_NUM_SLOTS];
Steve Wisecfdda9d2010-04-21 15:30:06 -0700107};
108
109static inline void init_wr_hdr(union t4_wr *wqe, u16 wrid,
110 enum fw_wr_opcodes opcode, u8 flags, u8 len16)
111{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700112 wqe->send.opcode = (u8)opcode;
113 wqe->send.flags = flags;
114 wqe->send.wrid = wrid;
115 wqe->send.r1[0] = 0;
116 wqe->send.r1[1] = 0;
117 wqe->send.r1[2] = 0;
118 wqe->send.len16 = len16;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700119}
120
121/* CQE/AE status codes */
122#define T4_ERR_SUCCESS 0x0
123#define T4_ERR_STAG 0x1 /* STAG invalid: either the */
124 /* STAG is offlimt, being 0, */
125 /* or STAG_key mismatch */
126#define T4_ERR_PDID 0x2 /* PDID mismatch */
127#define T4_ERR_QPID 0x3 /* QPID mismatch */
128#define T4_ERR_ACCESS 0x4 /* Invalid access right */
129#define T4_ERR_WRAP 0x5 /* Wrap error */
130#define T4_ERR_BOUND 0x6 /* base and bounds voilation */
131#define T4_ERR_INVALIDATE_SHARED_MR 0x7 /* attempt to invalidate a */
132 /* shared memory region */
133#define T4_ERR_INVALIDATE_MR_WITH_MW_BOUND 0x8 /* attempt to invalidate a */
134 /* shared memory region */
135#define T4_ERR_ECC 0x9 /* ECC error detected */
136#define T4_ERR_ECC_PSTAG 0xA /* ECC error detected when */
137 /* reading PSTAG for a MW */
138 /* Invalidate */
139#define T4_ERR_PBL_ADDR_BOUND 0xB /* pbl addr out of bounds: */
140 /* software error */
141#define T4_ERR_SWFLUSH 0xC /* SW FLUSHED */
142#define T4_ERR_CRC 0x10 /* CRC error */
143#define T4_ERR_MARKER 0x11 /* Marker error */
144#define T4_ERR_PDU_LEN_ERR 0x12 /* invalid PDU length */
145#define T4_ERR_OUT_OF_RQE 0x13 /* out of RQE */
146#define T4_ERR_DDP_VERSION 0x14 /* wrong DDP version */
147#define T4_ERR_RDMA_VERSION 0x15 /* wrong RDMA version */
148#define T4_ERR_OPCODE 0x16 /* invalid rdma opcode */
149#define T4_ERR_DDP_QUEUE_NUM 0x17 /* invalid ddp queue number */
150#define T4_ERR_MSN 0x18 /* MSN error */
151#define T4_ERR_TBIT 0x19 /* tag bit not set correctly */
152#define T4_ERR_MO 0x1A /* MO not 0 for TERMINATE */
153 /* or READ_REQ */
154#define T4_ERR_MSN_GAP 0x1B
155#define T4_ERR_MSN_RANGE 0x1C
156#define T4_ERR_IRD_OVERFLOW 0x1D
157#define T4_ERR_RQE_ADDR_BOUND 0x1E /* RQE addr out of bounds: */
158 /* software error */
159#define T4_ERR_INTERNAL_ERR 0x1F /* internal error (opcode */
160 /* mismatch) */
161/*
162 * CQE defs
163 */
164struct t4_cqe {
165 __be32 header;
166 __be32 len;
167 union {
168 struct {
169 __be32 stag;
170 __be32 msn;
171 } rcqe;
172 struct {
173 u32 nada1;
174 u16 nada2;
175 u16 cidx;
176 } scqe;
177 struct {
178 __be32 wrid_hi;
179 __be32 wrid_low;
180 } gen;
181 } u;
182 __be64 reserved;
183 __be64 bits_type_ts;
184};
185
186/* macros for flit 0 of the cqe */
187
188#define S_CQE_QPID 12
189#define M_CQE_QPID 0xFFFFF
190#define G_CQE_QPID(x) ((((x) >> S_CQE_QPID)) & M_CQE_QPID)
191#define V_CQE_QPID(x) ((x)<<S_CQE_QPID)
192
193#define S_CQE_SWCQE 11
194#define M_CQE_SWCQE 0x1
195#define G_CQE_SWCQE(x) ((((x) >> S_CQE_SWCQE)) & M_CQE_SWCQE)
196#define V_CQE_SWCQE(x) ((x)<<S_CQE_SWCQE)
197
198#define S_CQE_STATUS 5
199#define M_CQE_STATUS 0x1F
200#define G_CQE_STATUS(x) ((((x) >> S_CQE_STATUS)) & M_CQE_STATUS)
201#define V_CQE_STATUS(x) ((x)<<S_CQE_STATUS)
202
203#define S_CQE_TYPE 4
204#define M_CQE_TYPE 0x1
205#define G_CQE_TYPE(x) ((((x) >> S_CQE_TYPE)) & M_CQE_TYPE)
206#define V_CQE_TYPE(x) ((x)<<S_CQE_TYPE)
207
208#define S_CQE_OPCODE 0
209#define M_CQE_OPCODE 0xF
210#define G_CQE_OPCODE(x) ((((x) >> S_CQE_OPCODE)) & M_CQE_OPCODE)
211#define V_CQE_OPCODE(x) ((x)<<S_CQE_OPCODE)
212
213#define SW_CQE(x) (G_CQE_SWCQE(be32_to_cpu((x)->header)))
214#define CQE_QPID(x) (G_CQE_QPID(be32_to_cpu((x)->header)))
215#define CQE_TYPE(x) (G_CQE_TYPE(be32_to_cpu((x)->header)))
216#define SQ_TYPE(x) (CQE_TYPE((x)))
217#define RQ_TYPE(x) (!CQE_TYPE((x)))
218#define CQE_STATUS(x) (G_CQE_STATUS(be32_to_cpu((x)->header)))
219#define CQE_OPCODE(x) (G_CQE_OPCODE(be32_to_cpu((x)->header)))
220
221#define CQE_SEND_OPCODE(x)( \
222 (G_CQE_OPCODE(be32_to_cpu((x)->header)) == FW_RI_SEND) || \
223 (G_CQE_OPCODE(be32_to_cpu((x)->header)) == FW_RI_SEND_WITH_SE) || \
224 (G_CQE_OPCODE(be32_to_cpu((x)->header)) == FW_RI_SEND_WITH_INV) || \
225 (G_CQE_OPCODE(be32_to_cpu((x)->header)) == FW_RI_SEND_WITH_SE_INV))
226
227#define CQE_LEN(x) (be32_to_cpu((x)->len))
228
229/* used for RQ completion processing */
230#define CQE_WRID_STAG(x) (be32_to_cpu((x)->u.rcqe.stag))
231#define CQE_WRID_MSN(x) (be32_to_cpu((x)->u.rcqe.msn))
232
233/* used for SQ completion processing */
234#define CQE_WRID_SQ_IDX(x) ((x)->u.scqe.cidx)
235
236/* generic accessor macros */
237#define CQE_WRID_HI(x) ((x)->u.gen.wrid_hi)
238#define CQE_WRID_LOW(x) ((x)->u.gen.wrid_low)
239
240/* macros for flit 3 of the cqe */
241#define S_CQE_GENBIT 63
242#define M_CQE_GENBIT 0x1
243#define G_CQE_GENBIT(x) (((x) >> S_CQE_GENBIT) & M_CQE_GENBIT)
244#define V_CQE_GENBIT(x) ((x)<<S_CQE_GENBIT)
245
246#define S_CQE_OVFBIT 62
247#define M_CQE_OVFBIT 0x1
248#define G_CQE_OVFBIT(x) ((((x) >> S_CQE_OVFBIT)) & M_CQE_OVFBIT)
249
250#define S_CQE_IQTYPE 60
251#define M_CQE_IQTYPE 0x3
252#define G_CQE_IQTYPE(x) ((((x) >> S_CQE_IQTYPE)) & M_CQE_IQTYPE)
253
254#define M_CQE_TS 0x0fffffffffffffffULL
255#define G_CQE_TS(x) ((x) & M_CQE_TS)
256
257#define CQE_OVFBIT(x) ((unsigned)G_CQE_OVFBIT(be64_to_cpu((x)->bits_type_ts)))
258#define CQE_GENBIT(x) ((unsigned)G_CQE_GENBIT(be64_to_cpu((x)->bits_type_ts)))
259#define CQE_TS(x) (G_CQE_TS(be64_to_cpu((x)->bits_type_ts)))
260
261struct t4_swsqe {
262 u64 wr_id;
263 struct t4_cqe cqe;
264 int read_len;
265 int opcode;
266 int complete;
267 int signaled;
268 u16 idx;
269};
270
271struct t4_sq {
272 union t4_wr *queue;
273 dma_addr_t dma_addr;
FUJITA Tomonorif38926a2010-06-03 05:37:50 +0000274 DEFINE_DMA_UNMAP_ADDR(mapping);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700275 struct t4_swsqe *sw_sq;
276 struct t4_swsqe *oldest_read;
277 u64 udb;
278 size_t memsize;
279 u32 qid;
280 u16 in_use;
281 u16 size;
282 u16 cidx;
283 u16 pidx;
Steve Wised37ac312010-06-10 19:03:00 +0000284 u16 wq_pidx;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700285};
286
287struct t4_swrqe {
288 u64 wr_id;
289};
290
291struct t4_rq {
292 union t4_recv_wr *queue;
293 dma_addr_t dma_addr;
FUJITA Tomonorif38926a2010-06-03 05:37:50 +0000294 DEFINE_DMA_UNMAP_ADDR(mapping);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700295 struct t4_swrqe *sw_rq;
296 u64 udb;
297 size_t memsize;
298 u32 qid;
299 u32 msn;
300 u32 rqt_hwaddr;
301 u16 rqt_size;
302 u16 in_use;
303 u16 size;
304 u16 cidx;
305 u16 pidx;
Steve Wised37ac312010-06-10 19:03:00 +0000306 u16 wq_pidx;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700307};
308
309struct t4_wq {
310 struct t4_sq sq;
311 struct t4_rq rq;
312 void __iomem *db;
313 void __iomem *gts;
314 struct c4iw_rdev *rdev;
315};
316
317static inline int t4_rqes_posted(struct t4_wq *wq)
318{
319 return wq->rq.in_use;
320}
321
322static inline int t4_rq_empty(struct t4_wq *wq)
323{
324 return wq->rq.in_use == 0;
325}
326
327static inline int t4_rq_full(struct t4_wq *wq)
328{
329 return wq->rq.in_use == (wq->rq.size - 1);
330}
331
332static inline u32 t4_rq_avail(struct t4_wq *wq)
333{
334 return wq->rq.size - 1 - wq->rq.in_use;
335}
336
Steve Wised37ac312010-06-10 19:03:00 +0000337static inline void t4_rq_produce(struct t4_wq *wq, u8 len16)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700338{
339 wq->rq.in_use++;
340 if (++wq->rq.pidx == wq->rq.size)
341 wq->rq.pidx = 0;
Steve Wised37ac312010-06-10 19:03:00 +0000342 wq->rq.wq_pidx += DIV_ROUND_UP(len16*16, T4_EQ_ENTRY_SIZE);
343 if (wq->rq.wq_pidx >= wq->rq.size * T4_RQ_NUM_SLOTS)
344 wq->rq.wq_pidx %= wq->rq.size * T4_RQ_NUM_SLOTS;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700345}
346
347static inline void t4_rq_consume(struct t4_wq *wq)
348{
349 wq->rq.in_use--;
350 wq->rq.msn++;
351 if (++wq->rq.cidx == wq->rq.size)
352 wq->rq.cidx = 0;
353}
354
355static inline int t4_sq_empty(struct t4_wq *wq)
356{
357 return wq->sq.in_use == 0;
358}
359
360static inline int t4_sq_full(struct t4_wq *wq)
361{
362 return wq->sq.in_use == (wq->sq.size - 1);
363}
364
365static inline u32 t4_sq_avail(struct t4_wq *wq)
366{
367 return wq->sq.size - 1 - wq->sq.in_use;
368}
369
Steve Wised37ac312010-06-10 19:03:00 +0000370static inline void t4_sq_produce(struct t4_wq *wq, u8 len16)
Steve Wisecfdda9d2010-04-21 15:30:06 -0700371{
372 wq->sq.in_use++;
373 if (++wq->sq.pidx == wq->sq.size)
374 wq->sq.pidx = 0;
Steve Wised37ac312010-06-10 19:03:00 +0000375 wq->sq.wq_pidx += DIV_ROUND_UP(len16*16, T4_EQ_ENTRY_SIZE);
376 if (wq->sq.wq_pidx >= wq->sq.size * T4_SQ_NUM_SLOTS)
377 wq->sq.wq_pidx %= wq->sq.size * T4_SQ_NUM_SLOTS;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700378}
379
380static inline void t4_sq_consume(struct t4_wq *wq)
381{
382 wq->sq.in_use--;
383 if (++wq->sq.cidx == wq->sq.size)
384 wq->sq.cidx = 0;
385}
386
387static inline void t4_ring_sq_db(struct t4_wq *wq, u16 inc)
388{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700389 wmb();
390 writel(QID(wq->sq.qid) | PIDX(inc), wq->db);
391}
392
393static inline void t4_ring_rq_db(struct t4_wq *wq, u16 inc)
394{
Steve Wisecfdda9d2010-04-21 15:30:06 -0700395 wmb();
396 writel(QID(wq->rq.qid) | PIDX(inc), wq->db);
397}
398
399static inline int t4_wq_in_error(struct t4_wq *wq)
400{
401 return wq->sq.queue[wq->sq.size].status.qp_err;
402}
403
404static inline void t4_set_wq_in_error(struct t4_wq *wq)
405{
406 wq->sq.queue[wq->sq.size].status.qp_err = 1;
407 wq->rq.queue[wq->rq.size].status.qp_err = 1;
408}
409
410static inline void t4_disable_wq_db(struct t4_wq *wq)
411{
412 wq->sq.queue[wq->sq.size].status.db_off = 1;
413 wq->rq.queue[wq->rq.size].status.db_off = 1;
414}
415
416static inline void t4_enable_wq_db(struct t4_wq *wq)
417{
418 wq->sq.queue[wq->sq.size].status.db_off = 0;
419 wq->rq.queue[wq->rq.size].status.db_off = 0;
420}
421
422static inline int t4_wq_db_enabled(struct t4_wq *wq)
423{
424 return !wq->sq.queue[wq->sq.size].status.db_off;
425}
426
427struct t4_cq {
428 struct t4_cqe *queue;
429 dma_addr_t dma_addr;
FUJITA Tomonorif38926a2010-06-03 05:37:50 +0000430 DEFINE_DMA_UNMAP_ADDR(mapping);
Steve Wisecfdda9d2010-04-21 15:30:06 -0700431 struct t4_cqe *sw_queue;
432 void __iomem *gts;
433 struct c4iw_rdev *rdev;
434 u64 ugts;
435 size_t memsize;
Steve Wise84172de2010-05-20 16:57:43 -0500436 __be64 bits_type_ts;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700437 u32 cqid;
438 u16 size; /* including status page */
439 u16 cidx;
440 u16 sw_pidx;
441 u16 sw_cidx;
442 u16 sw_in_use;
443 u16 cidx_inc;
444 u8 gen;
445 u8 error;
446};
447
448static inline int t4_arm_cq(struct t4_cq *cq, int se)
449{
450 u32 val;
451
Steve Wise7ec45b92010-05-20 16:57:49 -0500452 while (cq->cidx_inc > CIDXINC_MASK) {
453 val = SEINTARM(0) | CIDXINC(CIDXINC_MASK) | TIMERREG(7) |
454 INGRESSQID(cq->cqid);
Roland Dreierbe4c9ba2010-05-05 14:45:40 -0700455 writel(val, cq->gts);
Steve Wise7ec45b92010-05-20 16:57:49 -0500456 cq->cidx_inc -= CIDXINC_MASK;
457 }
458 val = SEINTARM(se) | CIDXINC(cq->cidx_inc) | TIMERREG(6) |
459 INGRESSQID(cq->cqid);
460 writel(val, cq->gts);
461 cq->cidx_inc = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700462 return 0;
463}
464
465static inline void t4_swcq_produce(struct t4_cq *cq)
466{
467 cq->sw_in_use++;
468 if (++cq->sw_pidx == cq->size)
469 cq->sw_pidx = 0;
470}
471
472static inline void t4_swcq_consume(struct t4_cq *cq)
473{
474 cq->sw_in_use--;
475 if (++cq->sw_cidx == cq->size)
476 cq->sw_cidx = 0;
477}
478
479static inline void t4_hwcq_consume(struct t4_cq *cq)
480{
Steve Wise84172de2010-05-20 16:57:43 -0500481 cq->bits_type_ts = cq->queue[cq->cidx].bits_type_ts;
Steve Wise7ec45b92010-05-20 16:57:49 -0500482 if (++cq->cidx_inc == cq->size)
483 cq->cidx_inc = 0;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700484 if (++cq->cidx == cq->size) {
485 cq->cidx = 0;
486 cq->gen ^= 1;
487 }
488}
489
490static inline int t4_valid_cqe(struct t4_cq *cq, struct t4_cqe *cqe)
491{
492 return (CQE_GENBIT(cqe) == cq->gen);
493}
494
495static inline int t4_next_hw_cqe(struct t4_cq *cq, struct t4_cqe **cqe)
496{
Steve Wise84172de2010-05-20 16:57:43 -0500497 int ret;
498 u16 prev_cidx;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700499
Steve Wise84172de2010-05-20 16:57:43 -0500500 if (cq->cidx == 0)
501 prev_cidx = cq->size - 1;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700502 else
Steve Wise84172de2010-05-20 16:57:43 -0500503 prev_cidx = cq->cidx - 1;
504
505 if (cq->queue[prev_cidx].bits_type_ts != cq->bits_type_ts) {
506 ret = -EOVERFLOW;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700507 cq->error = 1;
Steve Wise84172de2010-05-20 16:57:43 -0500508 printk(KERN_ERR MOD "cq overflow cqid %u\n", cq->cqid);
509 } else if (t4_valid_cqe(cq, &cq->queue[cq->cidx])) {
510 *cqe = &cq->queue[cq->cidx];
511 ret = 0;
512 } else
513 ret = -ENODATA;
Steve Wisecfdda9d2010-04-21 15:30:06 -0700514 return ret;
515}
516
517static inline struct t4_cqe *t4_next_sw_cqe(struct t4_cq *cq)
518{
519 if (cq->sw_in_use)
520 return &cq->sw_queue[cq->sw_cidx];
521 return NULL;
522}
523
524static inline int t4_next_cqe(struct t4_cq *cq, struct t4_cqe **cqe)
525{
526 int ret = 0;
527
528 if (cq->error)
529 ret = -ENODATA;
530 else if (cq->sw_in_use)
531 *cqe = &cq->sw_queue[cq->sw_cidx];
532 else
533 ret = t4_next_hw_cqe(cq, cqe);
534 return ret;
535}
536
537static inline int t4_cq_in_error(struct t4_cq *cq)
538{
539 return ((struct t4_status_page *)&cq->queue[cq->size])->qp_err;
540}
541
542static inline void t4_set_cq_in_error(struct t4_cq *cq)
543{
544 ((struct t4_status_page *)&cq->queue[cq->size])->qp_err = 1;
545}
546#endif