18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  linux/drivers/net/ethernet/ibm/ehea/ehea_qmr.h
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  eHEA ethernet device driver for IBM eServer System p
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci *  (C) Copyright IBM Corp. 2006
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci *  Authors:
108c2ecf20Sopenharmony_ci *       Christoph Raisch <raisch@de.ibm.com>
118c2ecf20Sopenharmony_ci *       Jan-Bernd Themann <themann@de.ibm.com>
128c2ecf20Sopenharmony_ci *       Thomas Klein <tklein@de.ibm.com>
138c2ecf20Sopenharmony_ci */
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#ifndef __EHEA_QMR_H__
168c2ecf20Sopenharmony_ci#define __EHEA_QMR_H__
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#include <linux/prefetch.h>
198c2ecf20Sopenharmony_ci#include "ehea.h"
208c2ecf20Sopenharmony_ci#include "ehea_hw.h"
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci/*
238c2ecf20Sopenharmony_ci * page size of ehea hardware queues
248c2ecf20Sopenharmony_ci */
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define EHEA_PAGESHIFT         12
278c2ecf20Sopenharmony_ci#define EHEA_PAGESIZE          (1UL << EHEA_PAGESHIFT)
288c2ecf20Sopenharmony_ci#define EHEA_SECTSIZE          (1UL << 24)
298c2ecf20Sopenharmony_ci#define EHEA_PAGES_PER_SECTION (EHEA_SECTSIZE >> EHEA_PAGESHIFT)
308c2ecf20Sopenharmony_ci#define EHEA_HUGEPAGESHIFT     34
318c2ecf20Sopenharmony_ci#define EHEA_HUGEPAGE_SIZE     (1UL << EHEA_HUGEPAGESHIFT)
328c2ecf20Sopenharmony_ci#define EHEA_HUGEPAGE_PFN_MASK ((EHEA_HUGEPAGE_SIZE - 1) >> PAGE_SHIFT)
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#if ((1UL << SECTION_SIZE_BITS) < EHEA_SECTSIZE)
358c2ecf20Sopenharmony_ci#error eHEA module cannot work if kernel sectionsize < ehea sectionsize
368c2ecf20Sopenharmony_ci#endif
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/* Some abbreviations used here:
398c2ecf20Sopenharmony_ci *
408c2ecf20Sopenharmony_ci * WQE  - Work Queue Entry
418c2ecf20Sopenharmony_ci * SWQE - Send Work Queue Entry
428c2ecf20Sopenharmony_ci * RWQE - Receive Work Queue Entry
438c2ecf20Sopenharmony_ci * CQE  - Completion Queue Entry
448c2ecf20Sopenharmony_ci * EQE  - Event Queue Entry
458c2ecf20Sopenharmony_ci * MR   - Memory Region
468c2ecf20Sopenharmony_ci */
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/* Use of WR_ID field for EHEA */
498c2ecf20Sopenharmony_ci#define EHEA_WR_ID_COUNT   EHEA_BMASK_IBM(0, 19)
508c2ecf20Sopenharmony_ci#define EHEA_WR_ID_TYPE    EHEA_BMASK_IBM(20, 23)
518c2ecf20Sopenharmony_ci#define EHEA_SWQE2_TYPE    0x1
528c2ecf20Sopenharmony_ci#define EHEA_SWQE3_TYPE    0x2
538c2ecf20Sopenharmony_ci#define EHEA_RWQE2_TYPE    0x3
548c2ecf20Sopenharmony_ci#define EHEA_RWQE3_TYPE    0x4
558c2ecf20Sopenharmony_ci#define EHEA_WR_ID_INDEX   EHEA_BMASK_IBM(24, 47)
568c2ecf20Sopenharmony_ci#define EHEA_WR_ID_REFILL  EHEA_BMASK_IBM(48, 63)
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistruct ehea_vsgentry {
598c2ecf20Sopenharmony_ci	u64 vaddr;
608c2ecf20Sopenharmony_ci	u32 l_key;
618c2ecf20Sopenharmony_ci	u32 len;
628c2ecf20Sopenharmony_ci};
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/* maximum number of sg entries allowed in a WQE */
658c2ecf20Sopenharmony_ci#define EHEA_MAX_WQE_SG_ENTRIES  	252
668c2ecf20Sopenharmony_ci#define SWQE2_MAX_IMM            	(0xD0 - 0x30)
678c2ecf20Sopenharmony_ci#define SWQE3_MAX_IMM            	224
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci/* tx control flags for swqe */
708c2ecf20Sopenharmony_ci#define EHEA_SWQE_CRC                   0x8000
718c2ecf20Sopenharmony_ci#define EHEA_SWQE_IP_CHECKSUM           0x4000
728c2ecf20Sopenharmony_ci#define EHEA_SWQE_TCP_CHECKSUM          0x2000
738c2ecf20Sopenharmony_ci#define EHEA_SWQE_TSO                   0x1000
748c2ecf20Sopenharmony_ci#define EHEA_SWQE_SIGNALLED_COMPLETION  0x0800
758c2ecf20Sopenharmony_ci#define EHEA_SWQE_VLAN_INSERT           0x0400
768c2ecf20Sopenharmony_ci#define EHEA_SWQE_IMM_DATA_PRESENT      0x0200
778c2ecf20Sopenharmony_ci#define EHEA_SWQE_DESCRIPTORS_PRESENT   0x0100
788c2ecf20Sopenharmony_ci#define EHEA_SWQE_WRAP_CTL_REC          0x0080
798c2ecf20Sopenharmony_ci#define EHEA_SWQE_WRAP_CTL_FORCE        0x0040
808c2ecf20Sopenharmony_ci#define EHEA_SWQE_BIND                  0x0020
818c2ecf20Sopenharmony_ci#define EHEA_SWQE_PURGE                 0x0010
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci/* sizeof(struct ehea_swqe) less the union */
848c2ecf20Sopenharmony_ci#define SWQE_HEADER_SIZE		32
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_cistruct ehea_swqe {
878c2ecf20Sopenharmony_ci	u64 wr_id;
888c2ecf20Sopenharmony_ci	u16 tx_control;
898c2ecf20Sopenharmony_ci	u16 vlan_tag;
908c2ecf20Sopenharmony_ci	u8 reserved1;
918c2ecf20Sopenharmony_ci	u8 ip_start;
928c2ecf20Sopenharmony_ci	u8 ip_end;
938c2ecf20Sopenharmony_ci	u8 immediate_data_length;
948c2ecf20Sopenharmony_ci	u8 tcp_offset;
958c2ecf20Sopenharmony_ci	u8 reserved2;
968c2ecf20Sopenharmony_ci	u16 reserved2b;
978c2ecf20Sopenharmony_ci	u8 wrap_tag;
988c2ecf20Sopenharmony_ci	u8 descriptors;		/* number of valid descriptors in WQE */
998c2ecf20Sopenharmony_ci	u16 reserved3;
1008c2ecf20Sopenharmony_ci	u16 reserved4;
1018c2ecf20Sopenharmony_ci	u16 mss;
1028c2ecf20Sopenharmony_ci	u32 reserved5;
1038c2ecf20Sopenharmony_ci	union {
1048c2ecf20Sopenharmony_ci		/*  Send WQE Format 1 */
1058c2ecf20Sopenharmony_ci		struct {
1068c2ecf20Sopenharmony_ci			struct ehea_vsgentry sg_list[EHEA_MAX_WQE_SG_ENTRIES];
1078c2ecf20Sopenharmony_ci		} no_immediate_data;
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci		/*  Send WQE Format 2 */
1108c2ecf20Sopenharmony_ci		struct {
1118c2ecf20Sopenharmony_ci			struct ehea_vsgentry sg_entry;
1128c2ecf20Sopenharmony_ci			/* 0x30 */
1138c2ecf20Sopenharmony_ci			u8 immediate_data[SWQE2_MAX_IMM];
1148c2ecf20Sopenharmony_ci			/* 0xd0 */
1158c2ecf20Sopenharmony_ci			struct ehea_vsgentry sg_list[EHEA_MAX_WQE_SG_ENTRIES-1];
1168c2ecf20Sopenharmony_ci		} immdata_desc __packed;
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci		/*  Send WQE Format 3 */
1198c2ecf20Sopenharmony_ci		struct {
1208c2ecf20Sopenharmony_ci			u8 immediate_data[SWQE3_MAX_IMM];
1218c2ecf20Sopenharmony_ci		} immdata_nodesc;
1228c2ecf20Sopenharmony_ci	} u;
1238c2ecf20Sopenharmony_ci};
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_cistruct ehea_rwqe {
1268c2ecf20Sopenharmony_ci	u64 wr_id;		/* work request ID */
1278c2ecf20Sopenharmony_ci	u8 reserved1[5];
1288c2ecf20Sopenharmony_ci	u8 data_segments;
1298c2ecf20Sopenharmony_ci	u16 reserved2;
1308c2ecf20Sopenharmony_ci	u64 reserved3;
1318c2ecf20Sopenharmony_ci	u64 reserved4;
1328c2ecf20Sopenharmony_ci	struct ehea_vsgentry sg_list[EHEA_MAX_WQE_SG_ENTRIES];
1338c2ecf20Sopenharmony_ci};
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci#define EHEA_CQE_VLAN_TAG_XTRACT   0x0400
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci#define EHEA_CQE_TYPE_RQ           0x60
1388c2ecf20Sopenharmony_ci#define EHEA_CQE_STAT_ERR_MASK     0x700F
1398c2ecf20Sopenharmony_ci#define EHEA_CQE_STAT_FAT_ERR_MASK 0xF
1408c2ecf20Sopenharmony_ci#define EHEA_CQE_BLIND_CKSUM       0x8000
1418c2ecf20Sopenharmony_ci#define EHEA_CQE_STAT_ERR_TCP      0x4000
1428c2ecf20Sopenharmony_ci#define EHEA_CQE_STAT_ERR_IP       0x2000
1438c2ecf20Sopenharmony_ci#define EHEA_CQE_STAT_ERR_CRC      0x1000
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ci/* Defines which bad send cqe stati lead to a port reset */
1468c2ecf20Sopenharmony_ci#define EHEA_CQE_STAT_RESET_MASK   0x0002
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_cistruct ehea_cqe {
1498c2ecf20Sopenharmony_ci	u64 wr_id;		/* work request ID from WQE */
1508c2ecf20Sopenharmony_ci	u8 type;
1518c2ecf20Sopenharmony_ci	u8 valid;
1528c2ecf20Sopenharmony_ci	u16 status;
1538c2ecf20Sopenharmony_ci	u16 reserved1;
1548c2ecf20Sopenharmony_ci	u16 num_bytes_transfered;
1558c2ecf20Sopenharmony_ci	u16 vlan_tag;
1568c2ecf20Sopenharmony_ci	u16 inet_checksum_value;
1578c2ecf20Sopenharmony_ci	u8 reserved2;
1588c2ecf20Sopenharmony_ci	u8 header_length;
1598c2ecf20Sopenharmony_ci	u16 reserved3;
1608c2ecf20Sopenharmony_ci	u16 page_offset;
1618c2ecf20Sopenharmony_ci	u16 wqe_count;
1628c2ecf20Sopenharmony_ci	u32 qp_token;
1638c2ecf20Sopenharmony_ci	u32 timestamp;
1648c2ecf20Sopenharmony_ci	u32 reserved4;
1658c2ecf20Sopenharmony_ci	u64 reserved5[3];
1668c2ecf20Sopenharmony_ci};
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ci#define EHEA_EQE_VALID           EHEA_BMASK_IBM(0, 0)
1698c2ecf20Sopenharmony_ci#define EHEA_EQE_IS_CQE          EHEA_BMASK_IBM(1, 1)
1708c2ecf20Sopenharmony_ci#define EHEA_EQE_IDENTIFIER      EHEA_BMASK_IBM(2, 7)
1718c2ecf20Sopenharmony_ci#define EHEA_EQE_QP_CQ_NUMBER    EHEA_BMASK_IBM(8, 31)
1728c2ecf20Sopenharmony_ci#define EHEA_EQE_QP_TOKEN        EHEA_BMASK_IBM(32, 63)
1738c2ecf20Sopenharmony_ci#define EHEA_EQE_CQ_TOKEN        EHEA_BMASK_IBM(32, 63)
1748c2ecf20Sopenharmony_ci#define EHEA_EQE_KEY             EHEA_BMASK_IBM(32, 63)
1758c2ecf20Sopenharmony_ci#define EHEA_EQE_PORT_NUMBER     EHEA_BMASK_IBM(56, 63)
1768c2ecf20Sopenharmony_ci#define EHEA_EQE_EQ_NUMBER       EHEA_BMASK_IBM(48, 63)
1778c2ecf20Sopenharmony_ci#define EHEA_EQE_SM_ID           EHEA_BMASK_IBM(48, 63)
1788c2ecf20Sopenharmony_ci#define EHEA_EQE_SM_MECH_NUMBER  EHEA_BMASK_IBM(48, 55)
1798c2ecf20Sopenharmony_ci#define EHEA_EQE_SM_PORT_NUMBER  EHEA_BMASK_IBM(56, 63)
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci#define EHEA_AER_RESTYPE_QP  0x8
1828c2ecf20Sopenharmony_ci#define EHEA_AER_RESTYPE_CQ  0x4
1838c2ecf20Sopenharmony_ci#define EHEA_AER_RESTYPE_EQ  0x3
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci/* Defines which affiliated errors lead to a port reset */
1868c2ecf20Sopenharmony_ci#define EHEA_AER_RESET_MASK   0xFFFFFFFFFEFFFFFFULL
1878c2ecf20Sopenharmony_ci#define EHEA_AERR_RESET_MASK  0xFFFFFFFFFFFFFFFFULL
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_cistruct ehea_eqe {
1908c2ecf20Sopenharmony_ci	u64 entry;
1918c2ecf20Sopenharmony_ci};
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci#define ERROR_DATA_LENGTH  EHEA_BMASK_IBM(52, 63)
1948c2ecf20Sopenharmony_ci#define ERROR_DATA_TYPE    EHEA_BMASK_IBM(0, 7)
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_cistatic inline void *hw_qeit_calc(struct hw_queue *queue, u64 q_offset)
1978c2ecf20Sopenharmony_ci{
1988c2ecf20Sopenharmony_ci	struct ehea_page *current_page;
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci	if (q_offset >= queue->queue_length)
2018c2ecf20Sopenharmony_ci		q_offset -= queue->queue_length;
2028c2ecf20Sopenharmony_ci	current_page = (queue->queue_pages)[q_offset >> EHEA_PAGESHIFT];
2038c2ecf20Sopenharmony_ci	return &current_page->entries[q_offset & (EHEA_PAGESIZE - 1)];
2048c2ecf20Sopenharmony_ci}
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_cistatic inline void *hw_qeit_get(struct hw_queue *queue)
2078c2ecf20Sopenharmony_ci{
2088c2ecf20Sopenharmony_ci	return hw_qeit_calc(queue, queue->current_q_offset);
2098c2ecf20Sopenharmony_ci}
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_cistatic inline void hw_qeit_inc(struct hw_queue *queue)
2128c2ecf20Sopenharmony_ci{
2138c2ecf20Sopenharmony_ci	queue->current_q_offset += queue->qe_size;
2148c2ecf20Sopenharmony_ci	if (queue->current_q_offset >= queue->queue_length) {
2158c2ecf20Sopenharmony_ci		queue->current_q_offset = 0;
2168c2ecf20Sopenharmony_ci		/* toggle the valid flag */
2178c2ecf20Sopenharmony_ci		queue->toggle_state = (~queue->toggle_state) & 1;
2188c2ecf20Sopenharmony_ci	}
2198c2ecf20Sopenharmony_ci}
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_cistatic inline void *hw_qeit_get_inc(struct hw_queue *queue)
2228c2ecf20Sopenharmony_ci{
2238c2ecf20Sopenharmony_ci	void *retvalue = hw_qeit_get(queue);
2248c2ecf20Sopenharmony_ci	hw_qeit_inc(queue);
2258c2ecf20Sopenharmony_ci	return retvalue;
2268c2ecf20Sopenharmony_ci}
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_cistatic inline void *hw_qeit_get_inc_valid(struct hw_queue *queue)
2298c2ecf20Sopenharmony_ci{
2308c2ecf20Sopenharmony_ci	struct ehea_cqe *retvalue = hw_qeit_get(queue);
2318c2ecf20Sopenharmony_ci	u8 valid = retvalue->valid;
2328c2ecf20Sopenharmony_ci	void *pref;
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ci	if ((valid >> 7) == (queue->toggle_state & 1)) {
2358c2ecf20Sopenharmony_ci		/* this is a good one */
2368c2ecf20Sopenharmony_ci		hw_qeit_inc(queue);
2378c2ecf20Sopenharmony_ci		pref = hw_qeit_calc(queue, queue->current_q_offset);
2388c2ecf20Sopenharmony_ci		prefetch(pref);
2398c2ecf20Sopenharmony_ci		prefetch(pref + 128);
2408c2ecf20Sopenharmony_ci	} else
2418c2ecf20Sopenharmony_ci		retvalue = NULL;
2428c2ecf20Sopenharmony_ci	return retvalue;
2438c2ecf20Sopenharmony_ci}
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_cistatic inline void *hw_qeit_get_valid(struct hw_queue *queue)
2468c2ecf20Sopenharmony_ci{
2478c2ecf20Sopenharmony_ci	struct ehea_cqe *retvalue = hw_qeit_get(queue);
2488c2ecf20Sopenharmony_ci	void *pref;
2498c2ecf20Sopenharmony_ci	u8 valid;
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci	pref = hw_qeit_calc(queue, queue->current_q_offset);
2528c2ecf20Sopenharmony_ci	prefetch(pref);
2538c2ecf20Sopenharmony_ci	prefetch(pref + 128);
2548c2ecf20Sopenharmony_ci	prefetch(pref + 256);
2558c2ecf20Sopenharmony_ci	valid = retvalue->valid;
2568c2ecf20Sopenharmony_ci	if (!((valid >> 7) == (queue->toggle_state & 1)))
2578c2ecf20Sopenharmony_ci		retvalue = NULL;
2588c2ecf20Sopenharmony_ci	return retvalue;
2598c2ecf20Sopenharmony_ci}
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_cistatic inline void *hw_qeit_reset(struct hw_queue *queue)
2628c2ecf20Sopenharmony_ci{
2638c2ecf20Sopenharmony_ci	queue->current_q_offset = 0;
2648c2ecf20Sopenharmony_ci	return hw_qeit_get(queue);
2658c2ecf20Sopenharmony_ci}
2668c2ecf20Sopenharmony_ci
2678c2ecf20Sopenharmony_cistatic inline void *hw_qeit_eq_get_inc(struct hw_queue *queue)
2688c2ecf20Sopenharmony_ci{
2698c2ecf20Sopenharmony_ci	u64 last_entry_in_q = queue->queue_length - queue->qe_size;
2708c2ecf20Sopenharmony_ci	void *retvalue;
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_ci	retvalue = hw_qeit_get(queue);
2738c2ecf20Sopenharmony_ci	queue->current_q_offset += queue->qe_size;
2748c2ecf20Sopenharmony_ci	if (queue->current_q_offset > last_entry_in_q) {
2758c2ecf20Sopenharmony_ci		queue->current_q_offset = 0;
2768c2ecf20Sopenharmony_ci		queue->toggle_state = (~queue->toggle_state) & 1;
2778c2ecf20Sopenharmony_ci	}
2788c2ecf20Sopenharmony_ci	return retvalue;
2798c2ecf20Sopenharmony_ci}
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_cistatic inline void *hw_eqit_eq_get_inc_valid(struct hw_queue *queue)
2828c2ecf20Sopenharmony_ci{
2838c2ecf20Sopenharmony_ci	void *retvalue = hw_qeit_get(queue);
2848c2ecf20Sopenharmony_ci	u32 qe = *(u8 *)retvalue;
2858c2ecf20Sopenharmony_ci	if ((qe >> 7) == (queue->toggle_state & 1))
2868c2ecf20Sopenharmony_ci		hw_qeit_eq_get_inc(queue);
2878c2ecf20Sopenharmony_ci	else
2888c2ecf20Sopenharmony_ci		retvalue = NULL;
2898c2ecf20Sopenharmony_ci	return retvalue;
2908c2ecf20Sopenharmony_ci}
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_cistatic inline struct ehea_rwqe *ehea_get_next_rwqe(struct ehea_qp *qp,
2938c2ecf20Sopenharmony_ci						   int rq_nr)
2948c2ecf20Sopenharmony_ci{
2958c2ecf20Sopenharmony_ci	struct hw_queue *queue;
2968c2ecf20Sopenharmony_ci
2978c2ecf20Sopenharmony_ci	if (rq_nr == 1)
2988c2ecf20Sopenharmony_ci		queue = &qp->hw_rqueue1;
2998c2ecf20Sopenharmony_ci	else if (rq_nr == 2)
3008c2ecf20Sopenharmony_ci		queue = &qp->hw_rqueue2;
3018c2ecf20Sopenharmony_ci	else
3028c2ecf20Sopenharmony_ci		queue = &qp->hw_rqueue3;
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_ci	return hw_qeit_get_inc(queue);
3058c2ecf20Sopenharmony_ci}
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_cistatic inline struct ehea_swqe *ehea_get_swqe(struct ehea_qp *my_qp,
3088c2ecf20Sopenharmony_ci					      int *wqe_index)
3098c2ecf20Sopenharmony_ci{
3108c2ecf20Sopenharmony_ci	struct hw_queue *queue = &my_qp->hw_squeue;
3118c2ecf20Sopenharmony_ci	struct ehea_swqe *wqe_p;
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ci	*wqe_index = (queue->current_q_offset) >> (7 + EHEA_SG_SQ);
3148c2ecf20Sopenharmony_ci	wqe_p = hw_qeit_get_inc(&my_qp->hw_squeue);
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci	return wqe_p;
3178c2ecf20Sopenharmony_ci}
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_cistatic inline void ehea_post_swqe(struct ehea_qp *my_qp, struct ehea_swqe *swqe)
3208c2ecf20Sopenharmony_ci{
3218c2ecf20Sopenharmony_ci	iosync();
3228c2ecf20Sopenharmony_ci	ehea_update_sqa(my_qp, 1);
3238c2ecf20Sopenharmony_ci}
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_cistatic inline struct ehea_cqe *ehea_poll_rq1(struct ehea_qp *qp, int *wqe_index)
3268c2ecf20Sopenharmony_ci{
3278c2ecf20Sopenharmony_ci	struct hw_queue *queue = &qp->hw_rqueue1;
3288c2ecf20Sopenharmony_ci
3298c2ecf20Sopenharmony_ci	*wqe_index = (queue->current_q_offset) >> (7 + EHEA_SG_RQ1);
3308c2ecf20Sopenharmony_ci	return hw_qeit_get_valid(queue);
3318c2ecf20Sopenharmony_ci}
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_cistatic inline void ehea_inc_cq(struct ehea_cq *cq)
3348c2ecf20Sopenharmony_ci{
3358c2ecf20Sopenharmony_ci	hw_qeit_inc(&cq->hw_queue);
3368c2ecf20Sopenharmony_ci}
3378c2ecf20Sopenharmony_ci
3388c2ecf20Sopenharmony_cistatic inline void ehea_inc_rq1(struct ehea_qp *qp)
3398c2ecf20Sopenharmony_ci{
3408c2ecf20Sopenharmony_ci	hw_qeit_inc(&qp->hw_rqueue1);
3418c2ecf20Sopenharmony_ci}
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_cistatic inline struct ehea_cqe *ehea_poll_cq(struct ehea_cq *my_cq)
3448c2ecf20Sopenharmony_ci{
3458c2ecf20Sopenharmony_ci	return hw_qeit_get_valid(&my_cq->hw_queue);
3468c2ecf20Sopenharmony_ci}
3478c2ecf20Sopenharmony_ci
3488c2ecf20Sopenharmony_ci#define EHEA_CQ_REGISTER_ORIG 0
3498c2ecf20Sopenharmony_ci#define EHEA_EQ_REGISTER_ORIG 0
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_cienum ehea_eq_type {
3528c2ecf20Sopenharmony_ci	EHEA_EQ = 0,		/* event queue              */
3538c2ecf20Sopenharmony_ci	EHEA_NEQ		/* notification event queue */
3548c2ecf20Sopenharmony_ci};
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_cistruct ehea_eq *ehea_create_eq(struct ehea_adapter *adapter,
3578c2ecf20Sopenharmony_ci			       enum ehea_eq_type type,
3588c2ecf20Sopenharmony_ci			       const u32 length, const u8 eqe_gen);
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ciint ehea_destroy_eq(struct ehea_eq *eq);
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_cistruct ehea_eqe *ehea_poll_eq(struct ehea_eq *eq);
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_cistruct ehea_cq *ehea_create_cq(struct ehea_adapter *adapter, int cqe,
3658c2ecf20Sopenharmony_ci			       u64 eq_handle, u32 cq_token);
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ciint ehea_destroy_cq(struct ehea_cq *cq);
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_cistruct ehea_qp *ehea_create_qp(struct ehea_adapter *adapter, u32 pd,
3708c2ecf20Sopenharmony_ci			       struct ehea_qp_init_attr *init_attr);
3718c2ecf20Sopenharmony_ci
3728c2ecf20Sopenharmony_ciint ehea_destroy_qp(struct ehea_qp *qp);
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_ciint ehea_reg_kernel_mr(struct ehea_adapter *adapter, struct ehea_mr *mr);
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ciint ehea_gen_smr(struct ehea_adapter *adapter, struct ehea_mr *old_mr,
3778c2ecf20Sopenharmony_ci		 struct ehea_mr *shared_mr);
3788c2ecf20Sopenharmony_ci
3798c2ecf20Sopenharmony_ciint ehea_rem_mr(struct ehea_mr *mr);
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_ciu64 ehea_error_data(struct ehea_adapter *adapter, u64 res_handle,
3828c2ecf20Sopenharmony_ci		    u64 *aer, u64 *aerr);
3838c2ecf20Sopenharmony_ci
3848c2ecf20Sopenharmony_ciint ehea_add_sect_bmap(unsigned long pfn, unsigned long nr_pages);
3858c2ecf20Sopenharmony_ciint ehea_rem_sect_bmap(unsigned long pfn, unsigned long nr_pages);
3868c2ecf20Sopenharmony_ciint ehea_create_busmap(void);
3878c2ecf20Sopenharmony_civoid ehea_destroy_busmap(void);
3888c2ecf20Sopenharmony_ciu64 ehea_map_vaddr(void *caddr);
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci#endif	/* __EHEA_QMR_H__ */
391