2 * Copyright (c) 2013-2015, Mellanox Technologies, Ltd. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS `AS IS' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <dev/mlx5/mlx5_ifc.h>
33 struct mlx5_wq_param {
40 struct mlx5_core_dev *mdev;
56 u32 cc; /* consumer counter */
72 int mlx5_wq_cyc_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
73 void *wqc, struct mlx5_wq_cyc *wq,
74 struct mlx5_wq_ctrl *wq_ctrl);
75 u32 mlx5_wq_cyc_get_size(struct mlx5_wq_cyc *wq);
77 int mlx5_cqwq_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
78 void *cqc, struct mlx5_cqwq *wq,
79 struct mlx5_wq_ctrl *wq_ctrl);
80 u32 mlx5_cqwq_get_size(struct mlx5_cqwq *wq);
82 int mlx5_wq_ll_create(struct mlx5_core_dev *mdev, struct mlx5_wq_param *param,
83 void *wqc, struct mlx5_wq_ll *wq,
84 struct mlx5_wq_ctrl *wq_ctrl);
85 u32 mlx5_wq_ll_get_size(struct mlx5_wq_ll *wq);
87 void mlx5_wq_destroy(struct mlx5_wq_ctrl *wq_ctrl);
89 static inline u16 mlx5_wq_cyc_ctr2ix(struct mlx5_wq_cyc *wq, u16 ctr)
91 return ctr & wq->sz_m1;
94 static inline void *mlx5_wq_cyc_get_wqe(struct mlx5_wq_cyc *wq, u16 ix)
96 return wq->buf + (ix << wq->log_stride);
99 static inline int mlx5_wq_cyc_cc_bigger(u16 cc1, u16 cc2)
101 int equal = (cc1 == cc2);
102 int smaller = 0x8000 & (cc1 - cc2);
104 return !equal && !smaller;
107 static inline u32 mlx5_cqwq_get_ci(struct mlx5_cqwq *wq)
109 return wq->cc & wq->sz_m1;
112 static inline void *mlx5_cqwq_get_wqe(struct mlx5_cqwq *wq, u32 ix)
114 return wq->buf + (ix << wq->log_stride);
117 static inline u32 mlx5_cqwq_get_wrap_cnt(struct mlx5_cqwq *wq)
119 return wq->cc >> wq->log_sz;
122 static inline void mlx5_cqwq_pop(struct mlx5_cqwq *wq)
127 static inline void mlx5_cqwq_update_db_record(struct mlx5_cqwq *wq)
129 *wq->db = cpu_to_be32(wq->cc & 0xffffff);
132 static inline int mlx5_wq_ll_is_full(struct mlx5_wq_ll *wq)
134 return wq->cur_sz == wq->sz_m1;
137 static inline int mlx5_wq_ll_is_empty(struct mlx5_wq_ll *wq)
142 static inline void mlx5_wq_ll_push(struct mlx5_wq_ll *wq, u16 head_next)
144 wq->head = head_next;
149 static inline void mlx5_wq_ll_pop(struct mlx5_wq_ll *wq, __be16 ix,
150 __be16 *next_tail_next)
153 wq->tail_next = next_tail_next;
156 static inline void mlx5_wq_ll_update_db_record(struct mlx5_wq_ll *wq)
158 *wq->db = cpu_to_be32(wq->wqe_ctr);
161 static inline void *mlx5_wq_ll_get_wqe(struct mlx5_wq_ll *wq, u16 ix)
163 return wq->buf + (ix << wq->log_stride);
166 #endif /* __MLX5_WQ_H__ */