18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright 2014 Cisco Systems, Inc.  All rights reserved.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * This program is free software; you may redistribute it and/or modify
58c2ecf20Sopenharmony_ci * it under the terms of the GNU General Public License as published by
68c2ecf20Sopenharmony_ci * the Free Software Foundation; version 2 of the License.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
98c2ecf20Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
108c2ecf20Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
118c2ecf20Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
128c2ecf20Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
138c2ecf20Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
148c2ecf20Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
158c2ecf20Sopenharmony_ci * SOFTWARE.
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#ifndef _CQ_DESC_H_
198c2ecf20Sopenharmony_ci#define _CQ_DESC_H_
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/*
228c2ecf20Sopenharmony_ci * Completion queue descriptor types
238c2ecf20Sopenharmony_ci */
248c2ecf20Sopenharmony_cienum cq_desc_types {
258c2ecf20Sopenharmony_ci	CQ_DESC_TYPE_WQ_ENET = 0,
268c2ecf20Sopenharmony_ci	CQ_DESC_TYPE_DESC_COPY = 1,
278c2ecf20Sopenharmony_ci	CQ_DESC_TYPE_WQ_EXCH = 2,
288c2ecf20Sopenharmony_ci	CQ_DESC_TYPE_RQ_ENET = 3,
298c2ecf20Sopenharmony_ci	CQ_DESC_TYPE_RQ_FCP = 4,
308c2ecf20Sopenharmony_ci};
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci/* Completion queue descriptor: 16B
338c2ecf20Sopenharmony_ci *
348c2ecf20Sopenharmony_ci * All completion queues have this basic layout.  The
358c2ecf20Sopenharmony_ci * type_specific area is unique for each completion
368c2ecf20Sopenharmony_ci * queue type.
378c2ecf20Sopenharmony_ci */
388c2ecf20Sopenharmony_cistruct cq_desc {
398c2ecf20Sopenharmony_ci	__le16 completed_index;
408c2ecf20Sopenharmony_ci	__le16 q_number;
418c2ecf20Sopenharmony_ci	u8 type_specific[11];
428c2ecf20Sopenharmony_ci	u8 type_color;
438c2ecf20Sopenharmony_ci};
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci#define CQ_DESC_TYPE_BITS        4
468c2ecf20Sopenharmony_ci#define CQ_DESC_TYPE_MASK        ((1 << CQ_DESC_TYPE_BITS) - 1)
478c2ecf20Sopenharmony_ci#define CQ_DESC_COLOR_MASK       1
488c2ecf20Sopenharmony_ci#define CQ_DESC_COLOR_SHIFT      7
498c2ecf20Sopenharmony_ci#define CQ_DESC_Q_NUM_BITS       10
508c2ecf20Sopenharmony_ci#define CQ_DESC_Q_NUM_MASK       ((1 << CQ_DESC_Q_NUM_BITS) - 1)
518c2ecf20Sopenharmony_ci#define CQ_DESC_COMP_NDX_BITS    12
528c2ecf20Sopenharmony_ci#define CQ_DESC_COMP_NDX_MASK    ((1 << CQ_DESC_COMP_NDX_BITS) - 1)
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistatic inline void cq_desc_dec(const struct cq_desc *desc_arg,
558c2ecf20Sopenharmony_ci	u8 *type, u8 *color, u16 *q_number, u16 *completed_index)
568c2ecf20Sopenharmony_ci{
578c2ecf20Sopenharmony_ci	const struct cq_desc *desc = desc_arg;
588c2ecf20Sopenharmony_ci	const u8 type_color = desc->type_color;
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci	*color = (type_color >> CQ_DESC_COLOR_SHIFT) & CQ_DESC_COLOR_MASK;
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	/*
638c2ecf20Sopenharmony_ci	 * Make sure color bit is read from desc *before* other fields
648c2ecf20Sopenharmony_ci	 * are read from desc.  Hardware guarantees color bit is last
658c2ecf20Sopenharmony_ci	 * bit (byte) written.  Adding the rmb() prevents the compiler
668c2ecf20Sopenharmony_ci	 * and/or CPU from reordering the reads which would potentially
678c2ecf20Sopenharmony_ci	 * result in reading stale values.
688c2ecf20Sopenharmony_ci	 */
698c2ecf20Sopenharmony_ci	rmb();
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	*type = type_color & CQ_DESC_TYPE_MASK;
728c2ecf20Sopenharmony_ci	*q_number = le16_to_cpu(desc->q_number) & CQ_DESC_Q_NUM_MASK;
738c2ecf20Sopenharmony_ci	*completed_index = le16_to_cpu(desc->completed_index) &
748c2ecf20Sopenharmony_ci		CQ_DESC_COMP_NDX_MASK;
758c2ecf20Sopenharmony_ci}
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci#endif /* _CQ_DESC_H_ */
78