162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright (c) 2016 Hisilicon Limited.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * This software is available to you under a choice of one of two
562306a36Sopenharmony_ci * licenses.  You may choose to be licensed under the terms of the GNU
662306a36Sopenharmony_ci * General Public License (GPL) Version 2, available from the file
762306a36Sopenharmony_ci * COPYING in the main directory of this source tree, or the
862306a36Sopenharmony_ci * OpenIB.org BSD license below:
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci *     Redistribution and use in source and binary forms, with or
1162306a36Sopenharmony_ci *     without modification, are permitted provided that the following
1262306a36Sopenharmony_ci *     conditions are met:
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci *      - Redistributions of source code must retain the above
1562306a36Sopenharmony_ci *        copyright notice, this list of conditions and the following
1662306a36Sopenharmony_ci *        disclaimer.
1762306a36Sopenharmony_ci *
1862306a36Sopenharmony_ci *      - Redistributions in binary form must reproduce the above
1962306a36Sopenharmony_ci *        copyright notice, this list of conditions and the following
2062306a36Sopenharmony_ci *        disclaimer in the documentation and/or other materials
2162306a36Sopenharmony_ci *        provided with the distribution.
2262306a36Sopenharmony_ci *
2362306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2462306a36Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2562306a36Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
2662306a36Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
2762306a36Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
2862306a36Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
2962306a36Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3062306a36Sopenharmony_ci * SOFTWARE.
3162306a36Sopenharmony_ci */
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#ifndef _HNS_ROCE_COMMON_H
3462306a36Sopenharmony_ci#define _HNS_ROCE_COMMON_H
3562306a36Sopenharmony_ci#include <linux/bitfield.h>
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci#define roce_write(dev, reg, val)	writel((val), (dev)->reg_base + (reg))
3862306a36Sopenharmony_ci#define roce_read(dev, reg)		readl((dev)->reg_base + (reg))
3962306a36Sopenharmony_ci#define roce_raw_write(value, addr) \
4062306a36Sopenharmony_ci	__raw_writel((__force u32)cpu_to_le32(value), (addr))
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#define roce_get_field(origin, mask, shift)                                    \
4362306a36Sopenharmony_ci	((le32_to_cpu(origin) & (mask)) >> (u32)(shift))
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci#define roce_get_bit(origin, shift) \
4662306a36Sopenharmony_ci	roce_get_field((origin), (1ul << (shift)), (shift))
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_ci#define roce_set_field(origin, mask, shift, val)                               \
4962306a36Sopenharmony_ci	do {                                                                   \
5062306a36Sopenharmony_ci		(origin) &= ~cpu_to_le32(mask);                                \
5162306a36Sopenharmony_ci		(origin) |=                                                    \
5262306a36Sopenharmony_ci			cpu_to_le32(((u32)(val) << (u32)(shift)) & (mask));    \
5362306a36Sopenharmony_ci	} while (0)
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci#define roce_set_bit(origin, shift, val)                                       \
5662306a36Sopenharmony_ci	roce_set_field((origin), (1ul << (shift)), (shift), (val))
5762306a36Sopenharmony_ci
5862306a36Sopenharmony_ci#define FIELD_LOC(field_type, field_h, field_l) field_type, field_h, field_l
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci#define _hr_reg_enable(ptr, field_type, field_h, field_l)                      \
6162306a36Sopenharmony_ci	({                                                                     \
6262306a36Sopenharmony_ci		const field_type *_ptr = ptr;                                  \
6362306a36Sopenharmony_ci		*((__le32 *)_ptr + (field_h) / 32) |= cpu_to_le32(             \
6462306a36Sopenharmony_ci			BIT((field_l) % 32) +                                  \
6562306a36Sopenharmony_ci			BUILD_BUG_ON_ZERO((field_h) != (field_l)));            \
6662306a36Sopenharmony_ci	})
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci#define hr_reg_enable(ptr, field) _hr_reg_enable(ptr, field)
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci#define _hr_reg_clear(ptr, field_type, field_h, field_l)                       \
7162306a36Sopenharmony_ci	({                                                                     \
7262306a36Sopenharmony_ci		const field_type *_ptr = ptr;                                  \
7362306a36Sopenharmony_ci		BUILD_BUG_ON(((field_h) / 32) != ((field_l) / 32));            \
7462306a36Sopenharmony_ci		*((__le32 *)_ptr + (field_h) / 32) &=                          \
7562306a36Sopenharmony_ci			~cpu_to_le32(GENMASK((field_h) % 32, (field_l) % 32)); \
7662306a36Sopenharmony_ci	})
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci#define hr_reg_clear(ptr, field) _hr_reg_clear(ptr, field)
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci#define _hr_reg_write_bool(ptr, field_type, field_h, field_l, val)             \
8162306a36Sopenharmony_ci	({                                                                     \
8262306a36Sopenharmony_ci		(val) ? _hr_reg_enable(ptr, field_type, field_h, field_l) :    \
8362306a36Sopenharmony_ci			_hr_reg_clear(ptr, field_type, field_h, field_l);      \
8462306a36Sopenharmony_ci	})
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci#define hr_reg_write_bool(ptr, field, val) _hr_reg_write_bool(ptr, field, val)
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci#define _hr_reg_write(ptr, field_type, field_h, field_l, val)                  \
8962306a36Sopenharmony_ci	({                                                                     \
9062306a36Sopenharmony_ci		_hr_reg_clear(ptr, field_type, field_h, field_l);              \
9162306a36Sopenharmony_ci		*((__le32 *)ptr + (field_h) / 32) |= cpu_to_le32(FIELD_PREP(   \
9262306a36Sopenharmony_ci			GENMASK((field_h) % 32, (field_l) % 32), val));        \
9362306a36Sopenharmony_ci	})
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ci#define hr_reg_write(ptr, field, val) _hr_reg_write(ptr, field, val)
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ci#define _hr_reg_read(ptr, field_type, field_h, field_l)                        \
9862306a36Sopenharmony_ci	({                                                                     \
9962306a36Sopenharmony_ci		const field_type *_ptr = ptr;                                  \
10062306a36Sopenharmony_ci		BUILD_BUG_ON(((field_h) / 32) != ((field_l) / 32));            \
10162306a36Sopenharmony_ci		FIELD_GET(GENMASK((field_h) % 32, (field_l) % 32),             \
10262306a36Sopenharmony_ci			  le32_to_cpu(*((__le32 *)_ptr + (field_h) / 32)));    \
10362306a36Sopenharmony_ci	})
10462306a36Sopenharmony_ci
10562306a36Sopenharmony_ci#define hr_reg_read(ptr, field) _hr_reg_read(ptr, field)
10662306a36Sopenharmony_ci
10762306a36Sopenharmony_ci/*************ROCEE_REG DEFINITION****************/
10862306a36Sopenharmony_ci#define ROCEE_VENDOR_ID_REG			0x0
10962306a36Sopenharmony_ci#define ROCEE_VENDOR_PART_ID_REG		0x4
11062306a36Sopenharmony_ci
11162306a36Sopenharmony_ci#define ROCEE_SYS_IMAGE_GUID_L_REG		0xC
11262306a36Sopenharmony_ci#define ROCEE_SYS_IMAGE_GUID_H_REG		0x10
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci#define ROCEE_PORT_GID_L_0_REG			0x50
11562306a36Sopenharmony_ci#define ROCEE_PORT_GID_ML_0_REG			0x54
11662306a36Sopenharmony_ci#define ROCEE_PORT_GID_MH_0_REG			0x58
11762306a36Sopenharmony_ci#define ROCEE_PORT_GID_H_0_REG			0x5C
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci#define ROCEE_BT_CMD_H_REG			0x204
12062306a36Sopenharmony_ci
12162306a36Sopenharmony_ci#define ROCEE_SMAC_L_0_REG			0x240
12262306a36Sopenharmony_ci#define ROCEE_SMAC_H_0_REG			0x244
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci#define ROCEE_QP1C_CFG3_0_REG			0x27C
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci#define ROCEE_CAEP_AEQE_CONS_IDX_REG		0x3AC
12762306a36Sopenharmony_ci#define ROCEE_CAEP_CEQC_CONS_IDX_0_REG		0x3BC
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci#define ROCEE_ECC_UCERR_ALM1_REG		0xB38
13062306a36Sopenharmony_ci#define ROCEE_ECC_UCERR_ALM2_REG		0xB3C
13162306a36Sopenharmony_ci#define ROCEE_ECC_CERR_ALM1_REG			0xB44
13262306a36Sopenharmony_ci#define ROCEE_ECC_CERR_ALM2_REG			0xB48
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci#define ROCEE_ACK_DELAY_REG			0x14
13562306a36Sopenharmony_ci#define ROCEE_GLB_CFG_REG			0x18
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci#define ROCEE_DMAE_USER_CFG1_REG		0x40
13862306a36Sopenharmony_ci#define ROCEE_DMAE_USER_CFG2_REG		0x44
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ci#define ROCEE_DB_SQ_WL_REG			0x154
14162306a36Sopenharmony_ci#define ROCEE_DB_OTHERS_WL_REG			0x158
14262306a36Sopenharmony_ci#define ROCEE_RAQ_WL_REG			0x15C
14362306a36Sopenharmony_ci#define ROCEE_WRMS_POL_TIME_INTERVAL_REG	0x160
14462306a36Sopenharmony_ci#define ROCEE_EXT_DB_SQ_REG			0x164
14562306a36Sopenharmony_ci#define ROCEE_EXT_DB_SQ_H_REG			0x168
14662306a36Sopenharmony_ci#define ROCEE_EXT_DB_OTH_REG			0x16C
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci#define ROCEE_EXT_DB_OTH_H_REG			0x170
14962306a36Sopenharmony_ci#define ROCEE_EXT_DB_SQ_WL_EMPTY_REG		0x174
15062306a36Sopenharmony_ci#define ROCEE_EXT_DB_SQ_WL_REG			0x178
15162306a36Sopenharmony_ci#define ROCEE_EXT_DB_OTHERS_WL_EMPTY_REG	0x17C
15262306a36Sopenharmony_ci#define ROCEE_EXT_DB_OTHERS_WL_REG		0x180
15362306a36Sopenharmony_ci#define ROCEE_EXT_RAQ_REG			0x184
15462306a36Sopenharmony_ci#define ROCEE_EXT_RAQ_H_REG			0x188
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ci#define ROCEE_CAEP_CE_INTERVAL_CFG_REG		0x190
15762306a36Sopenharmony_ci#define ROCEE_CAEP_CE_BURST_NUM_CFG_REG		0x194
15862306a36Sopenharmony_ci#define ROCEE_BT_CMD_L_REG			0x200
15962306a36Sopenharmony_ci
16062306a36Sopenharmony_ci#define ROCEE_MB1_REG				0x210
16162306a36Sopenharmony_ci#define ROCEE_MB6_REG				0x224
16262306a36Sopenharmony_ci#define ROCEE_DB_SQ_L_0_REG			0x230
16362306a36Sopenharmony_ci#define ROCEE_DB_OTHERS_L_0_REG			0x238
16462306a36Sopenharmony_ci#define ROCEE_QP1C_CFG0_0_REG			0x270
16562306a36Sopenharmony_ci
16662306a36Sopenharmony_ci#define ROCEE_CAEP_AEQC_AEQE_SHIFT_REG		0x3A0
16762306a36Sopenharmony_ci#define ROCEE_CAEP_CEQC_SHIFT_0_REG		0x3B0
16862306a36Sopenharmony_ci#define ROCEE_CAEP_CE_IRQ_MASK_0_REG		0x3C0
16962306a36Sopenharmony_ci#define ROCEE_CAEP_CEQ_ALM_OVF_0_REG		0x3C4
17062306a36Sopenharmony_ci#define ROCEE_CAEP_AE_MASK_REG			0x6C8
17162306a36Sopenharmony_ci#define ROCEE_CAEP_AE_ST_REG			0x6CC
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci#define ROCEE_CAEP_CQE_WCMD_EMPTY		0x850
17462306a36Sopenharmony_ci#define ROCEE_SCAEP_WR_CQE_CNT			0x8D0
17562306a36Sopenharmony_ci#define ROCEE_ECC_UCERR_ALM0_REG		0xB34
17662306a36Sopenharmony_ci#define ROCEE_ECC_CERR_ALM0_REG			0xB40
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci/* V2 ROCEE REG */
17962306a36Sopenharmony_ci#define ROCEE_TX_CMQ_BASEADDR_L_REG		0x07000
18062306a36Sopenharmony_ci#define ROCEE_TX_CMQ_BASEADDR_H_REG		0x07004
18162306a36Sopenharmony_ci#define ROCEE_TX_CMQ_DEPTH_REG			0x07008
18262306a36Sopenharmony_ci#define ROCEE_TX_CMQ_PI_REG			0x07010
18362306a36Sopenharmony_ci#define ROCEE_TX_CMQ_CI_REG			0x07014
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci#define ROCEE_RX_CMQ_BASEADDR_L_REG		0x07018
18662306a36Sopenharmony_ci#define ROCEE_RX_CMQ_BASEADDR_H_REG		0x0701c
18762306a36Sopenharmony_ci#define ROCEE_RX_CMQ_DEPTH_REG			0x07020
18862306a36Sopenharmony_ci#define ROCEE_RX_CMQ_TAIL_REG			0x07024
18962306a36Sopenharmony_ci#define ROCEE_RX_CMQ_HEAD_REG			0x07028
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ci#define ROCEE_VF_EQ_DB_CFG0_REG			0x238
19262306a36Sopenharmony_ci#define ROCEE_VF_EQ_DB_CFG1_REG			0x23C
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ci#define ROCEE_VF_ABN_INT_CFG_REG		0x13000
19562306a36Sopenharmony_ci#define ROCEE_VF_ABN_INT_ST_REG			0x13004
19662306a36Sopenharmony_ci#define ROCEE_VF_ABN_INT_EN_REG			0x13008
19762306a36Sopenharmony_ci#define ROCEE_VF_EVENT_INT_EN_REG		0x1300c
19862306a36Sopenharmony_ci
19962306a36Sopenharmony_ci#endif /* _HNS_ROCE_COMMON_H */
200