162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2016 Cavium, Inc.
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci
662306a36Sopenharmony_ci#ifndef __CPT_COMMON_H
762306a36Sopenharmony_ci#define __CPT_COMMON_H
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include <asm/byteorder.h>
1062306a36Sopenharmony_ci#include <linux/delay.h>
1162306a36Sopenharmony_ci#include <linux/pci.h>
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#include "cpt_hw_types.h"
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci/* Device ID */
1662306a36Sopenharmony_ci#define CPT_81XX_PCI_PF_DEVICE_ID 0xa040
1762306a36Sopenharmony_ci#define CPT_81XX_PCI_VF_DEVICE_ID 0xa041
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci/* flags to indicate the features supported */
2062306a36Sopenharmony_ci#define CPT_FLAG_SRIOV_ENABLED BIT(1)
2162306a36Sopenharmony_ci#define CPT_FLAG_VF_DRIVER BIT(2)
2262306a36Sopenharmony_ci#define CPT_FLAG_DEVICE_READY BIT(3)
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ci#define cpt_sriov_enabled(cpt) ((cpt)->flags & CPT_FLAG_SRIOV_ENABLED)
2562306a36Sopenharmony_ci#define cpt_vf_driver(cpt) ((cpt)->flags & CPT_FLAG_VF_DRIVER)
2662306a36Sopenharmony_ci#define cpt_device_ready(cpt) ((cpt)->flags & CPT_FLAG_DEVICE_READY)
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci#define CPT_MBOX_MSG_TYPE_ACK 1
2962306a36Sopenharmony_ci#define CPT_MBOX_MSG_TYPE_NACK 2
3062306a36Sopenharmony_ci#define CPT_MBOX_MSG_TIMEOUT 2000
3162306a36Sopenharmony_ci#define VF_STATE_DOWN 0
3262306a36Sopenharmony_ci#define VF_STATE_UP 1
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci/*
3562306a36Sopenharmony_ci * CPT Registers map for 81xx
3662306a36Sopenharmony_ci */
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci/* PF registers */
3962306a36Sopenharmony_ci#define CPTX_PF_CONSTANTS(a) (0x0ll + ((u64)(a) << 36))
4062306a36Sopenharmony_ci#define CPTX_PF_RESET(a) (0x100ll + ((u64)(a) << 36))
4162306a36Sopenharmony_ci#define CPTX_PF_DIAG(a) (0x120ll + ((u64)(a) << 36))
4262306a36Sopenharmony_ci#define CPTX_PF_BIST_STATUS(a) (0x160ll + ((u64)(a) << 36))
4362306a36Sopenharmony_ci#define CPTX_PF_ECC0_CTL(a) (0x200ll + ((u64)(a) << 36))
4462306a36Sopenharmony_ci#define CPTX_PF_ECC0_FLIP(a) (0x210ll + ((u64)(a) << 36))
4562306a36Sopenharmony_ci#define CPTX_PF_ECC0_INT(a) (0x220ll + ((u64)(a) << 36))
4662306a36Sopenharmony_ci#define CPTX_PF_ECC0_INT_W1S(a) (0x230ll + ((u64)(a) << 36))
4762306a36Sopenharmony_ci#define CPTX_PF_ECC0_ENA_W1S(a)	(0x240ll + ((u64)(a) << 36))
4862306a36Sopenharmony_ci#define CPTX_PF_ECC0_ENA_W1C(a)	(0x250ll + ((u64)(a) << 36))
4962306a36Sopenharmony_ci#define CPTX_PF_MBOX_INTX(a, b)	\
5062306a36Sopenharmony_ci	(0x400ll + ((u64)(a) << 36) + ((b) << 3))
5162306a36Sopenharmony_ci#define CPTX_PF_MBOX_INT_W1SX(a, b) \
5262306a36Sopenharmony_ci	(0x420ll + ((u64)(a) << 36) + ((b) << 3))
5362306a36Sopenharmony_ci#define CPTX_PF_MBOX_ENA_W1CX(a, b) \
5462306a36Sopenharmony_ci	(0x440ll + ((u64)(a) << 36) + ((b) << 3))
5562306a36Sopenharmony_ci#define CPTX_PF_MBOX_ENA_W1SX(a, b) \
5662306a36Sopenharmony_ci	(0x460ll + ((u64)(a) << 36) + ((b) << 3))
5762306a36Sopenharmony_ci#define CPTX_PF_EXEC_INT(a) (0x500ll + 0x1000000000ll * ((a) & 0x1))
5862306a36Sopenharmony_ci#define CPTX_PF_EXEC_INT_W1S(a)	(0x520ll + ((u64)(a) << 36))
5962306a36Sopenharmony_ci#define CPTX_PF_EXEC_ENA_W1C(a)	(0x540ll + ((u64)(a) << 36))
6062306a36Sopenharmony_ci#define CPTX_PF_EXEC_ENA_W1S(a)	(0x560ll + ((u64)(a) << 36))
6162306a36Sopenharmony_ci#define CPTX_PF_GX_EN(a, b) \
6262306a36Sopenharmony_ci	(0x600ll + ((u64)(a) << 36) + ((b) << 3))
6362306a36Sopenharmony_ci#define CPTX_PF_EXEC_INFO(a) (0x700ll + ((u64)(a) << 36))
6462306a36Sopenharmony_ci#define CPTX_PF_EXEC_BUSY(a) (0x800ll + ((u64)(a) << 36))
6562306a36Sopenharmony_ci#define CPTX_PF_EXEC_INFO0(a) (0x900ll + ((u64)(a) << 36))
6662306a36Sopenharmony_ci#define CPTX_PF_EXEC_INFO1(a) (0x910ll + ((u64)(a) << 36))
6762306a36Sopenharmony_ci#define CPTX_PF_INST_REQ_PC(a) (0x10000ll + ((u64)(a) << 36))
6862306a36Sopenharmony_ci#define CPTX_PF_INST_LATENCY_PC(a) \
6962306a36Sopenharmony_ci	(0x10020ll + ((u64)(a) << 36))
7062306a36Sopenharmony_ci#define CPTX_PF_RD_REQ_PC(a) (0x10040ll + ((u64)(a) << 36))
7162306a36Sopenharmony_ci#define CPTX_PF_RD_LATENCY_PC(a) (0x10060ll + ((u64)(a) << 36))
7262306a36Sopenharmony_ci#define CPTX_PF_RD_UC_PC(a) (0x10080ll + ((u64)(a) << 36))
7362306a36Sopenharmony_ci#define CPTX_PF_ACTIVE_CYCLES_PC(a) (0x10100ll + ((u64)(a) << 36))
7462306a36Sopenharmony_ci#define CPTX_PF_EXE_CTL(a) (0x4000000ll + ((u64)(a) << 36))
7562306a36Sopenharmony_ci#define CPTX_PF_EXE_STATUS(a) (0x4000008ll + ((u64)(a) << 36))
7662306a36Sopenharmony_ci#define CPTX_PF_EXE_CLK(a) (0x4000010ll + ((u64)(a) << 36))
7762306a36Sopenharmony_ci#define CPTX_PF_EXE_DBG_CTL(a) (0x4000018ll + ((u64)(a) << 36))
7862306a36Sopenharmony_ci#define CPTX_PF_EXE_DBG_DATA(a)	(0x4000020ll + ((u64)(a) << 36))
7962306a36Sopenharmony_ci#define CPTX_PF_EXE_BIST_STATUS(a) (0x4000028ll + ((u64)(a) << 36))
8062306a36Sopenharmony_ci#define CPTX_PF_EXE_REQ_TIMER(a) (0x4000030ll + ((u64)(a) << 36))
8162306a36Sopenharmony_ci#define CPTX_PF_EXE_MEM_CTL(a) (0x4000038ll + ((u64)(a) << 36))
8262306a36Sopenharmony_ci#define CPTX_PF_EXE_PERF_CTL(a)	(0x4001000ll + ((u64)(a) << 36))
8362306a36Sopenharmony_ci#define CPTX_PF_EXE_DBG_CNTX(a, b) \
8462306a36Sopenharmony_ci	(0x4001100ll + ((u64)(a) << 36) + ((b) << 3))
8562306a36Sopenharmony_ci#define CPTX_PF_EXE_PERF_EVENT_CNT(a) (0x4001180ll + ((u64)(a) << 36))
8662306a36Sopenharmony_ci#define CPTX_PF_EXE_EPCI_INBX_CNT(a, b) \
8762306a36Sopenharmony_ci	(0x4001200ll + ((u64)(a) << 36) + ((b) << 3))
8862306a36Sopenharmony_ci#define CPTX_PF_EXE_EPCI_OUTBX_CNT(a, b) \
8962306a36Sopenharmony_ci	(0x4001240ll + ((u64)(a) << 36) + ((b) << 3))
9062306a36Sopenharmony_ci#define CPTX_PF_ENGX_UCODE_BASE(a, b) \
9162306a36Sopenharmony_ci	(0x4002000ll + ((u64)(a) << 36) + ((b) << 3))
9262306a36Sopenharmony_ci#define CPTX_PF_QX_CTL(a, b) \
9362306a36Sopenharmony_ci	(0x8000000ll + ((u64)(a) << 36) + ((b) << 20))
9462306a36Sopenharmony_ci#define CPTX_PF_QX_GMCTL(a, b) \
9562306a36Sopenharmony_ci	(0x8000020ll + ((u64)(a) << 36) + ((b) << 20))
9662306a36Sopenharmony_ci#define CPTX_PF_QX_CTL2(a, b) \
9762306a36Sopenharmony_ci	(0x8000100ll + ((u64)(a) << 36) + ((b) << 20))
9862306a36Sopenharmony_ci#define CPTX_PF_VFX_MBOXX(a, b, c) \
9962306a36Sopenharmony_ci	(0x8001000ll + ((u64)(a) << 36) + ((b) << 20) + ((c) << 8))
10062306a36Sopenharmony_ci
10162306a36Sopenharmony_ci/* VF registers */
10262306a36Sopenharmony_ci#define CPTX_VQX_CTL(a, b) (0x100ll + ((u64)(a) << 36) + ((b) << 20))
10362306a36Sopenharmony_ci#define CPTX_VQX_SADDR(a, b) (0x200ll + ((u64)(a) << 36) + ((b) << 20))
10462306a36Sopenharmony_ci#define CPTX_VQX_DONE_WAIT(a, b) (0x400ll + ((u64)(a) << 36) + ((b) << 20))
10562306a36Sopenharmony_ci#define CPTX_VQX_INPROG(a, b) (0x410ll + ((u64)(a) << 36) + ((b) << 20))
10662306a36Sopenharmony_ci#define CPTX_VQX_DONE(a, b) (0x420ll + ((u64)(a) << 36) + ((b) << 20))
10762306a36Sopenharmony_ci#define CPTX_VQX_DONE_ACK(a, b) (0x440ll + ((u64)(a) << 36) + ((b) << 20))
10862306a36Sopenharmony_ci#define CPTX_VQX_DONE_INT_W1S(a, b) (0x460ll + ((u64)(a) << 36) + ((b) << 20))
10962306a36Sopenharmony_ci#define CPTX_VQX_DONE_INT_W1C(a, b) (0x468ll + ((u64)(a) << 36) + ((b) << 20))
11062306a36Sopenharmony_ci#define CPTX_VQX_DONE_ENA_W1S(a, b) (0x470ll + ((u64)(a) << 36) + ((b) << 20))
11162306a36Sopenharmony_ci#define CPTX_VQX_DONE_ENA_W1C(a, b) (0x478ll + ((u64)(a) << 36) + ((b) << 20))
11262306a36Sopenharmony_ci#define CPTX_VQX_MISC_INT(a, b)	(0x500ll + ((u64)(a) << 36) + ((b) << 20))
11362306a36Sopenharmony_ci#define CPTX_VQX_MISC_INT_W1S(a, b) (0x508ll + ((u64)(a) << 36) + ((b) << 20))
11462306a36Sopenharmony_ci#define CPTX_VQX_MISC_ENA_W1S(a, b) (0x510ll + ((u64)(a) << 36) + ((b) << 20))
11562306a36Sopenharmony_ci#define CPTX_VQX_MISC_ENA_W1C(a, b) (0x518ll + ((u64)(a) << 36) + ((b) << 20))
11662306a36Sopenharmony_ci#define CPTX_VQX_DOORBELL(a, b) (0x600ll + ((u64)(a) << 36) + ((b) << 20))
11762306a36Sopenharmony_ci#define CPTX_VFX_PF_MBOXX(a, b, c) \
11862306a36Sopenharmony_ci	(0x1000ll + ((u64)(a) << 36) + ((b) << 20) + ((c) << 3))
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_cienum vftype {
12162306a36Sopenharmony_ci	AE_TYPES = 1,
12262306a36Sopenharmony_ci	SE_TYPES = 2,
12362306a36Sopenharmony_ci	BAD_CPT_TYPES,
12462306a36Sopenharmony_ci};
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ci/* Max CPT devices supported */
12762306a36Sopenharmony_cienum cpt_mbox_opcode {
12862306a36Sopenharmony_ci	CPT_MSG_VF_UP = 1,
12962306a36Sopenharmony_ci	CPT_MSG_VF_DOWN,
13062306a36Sopenharmony_ci	CPT_MSG_READY,
13162306a36Sopenharmony_ci	CPT_MSG_QLEN,
13262306a36Sopenharmony_ci	CPT_MSG_QBIND_GRP,
13362306a36Sopenharmony_ci	CPT_MSG_VQ_PRIORITY,
13462306a36Sopenharmony_ci};
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci/* CPT mailbox structure */
13762306a36Sopenharmony_cistruct cpt_mbox {
13862306a36Sopenharmony_ci	u64 msg; /* Message type MBOX[0] */
13962306a36Sopenharmony_ci	u64 data;/* Data         MBOX[1] */
14062306a36Sopenharmony_ci};
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci/* Register read/write APIs */
14362306a36Sopenharmony_cistatic inline void cpt_write_csr64(u8 __iomem *hw_addr, u64 offset,
14462306a36Sopenharmony_ci				   u64 val)
14562306a36Sopenharmony_ci{
14662306a36Sopenharmony_ci	writeq(val, hw_addr + offset);
14762306a36Sopenharmony_ci}
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_cistatic inline u64 cpt_read_csr64(u8 __iomem *hw_addr, u64 offset)
15062306a36Sopenharmony_ci{
15162306a36Sopenharmony_ci	return readq(hw_addr + offset);
15262306a36Sopenharmony_ci}
15362306a36Sopenharmony_ci#endif /* __CPT_COMMON_H */
154