18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (C) 2016 Cavium, Inc. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef __CPT_COMMON_H 78c2ecf20Sopenharmony_ci#define __CPT_COMMON_H 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <asm/byteorder.h> 108c2ecf20Sopenharmony_ci#include <linux/delay.h> 118c2ecf20Sopenharmony_ci#include <linux/pci.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include "cpt_hw_types.h" 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci/* Device ID */ 168c2ecf20Sopenharmony_ci#define CPT_81XX_PCI_PF_DEVICE_ID 0xa040 178c2ecf20Sopenharmony_ci#define CPT_81XX_PCI_VF_DEVICE_ID 0xa041 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/* flags to indicate the features supported */ 208c2ecf20Sopenharmony_ci#define CPT_FLAG_SRIOV_ENABLED BIT(1) 218c2ecf20Sopenharmony_ci#define CPT_FLAG_VF_DRIVER BIT(2) 228c2ecf20Sopenharmony_ci#define CPT_FLAG_DEVICE_READY BIT(3) 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#define cpt_sriov_enabled(cpt) ((cpt)->flags & CPT_FLAG_SRIOV_ENABLED) 258c2ecf20Sopenharmony_ci#define cpt_vf_driver(cpt) ((cpt)->flags & CPT_FLAG_VF_DRIVER) 268c2ecf20Sopenharmony_ci#define cpt_device_ready(cpt) ((cpt)->flags & CPT_FLAG_DEVICE_READY) 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#define CPT_MBOX_MSG_TYPE_ACK 1 298c2ecf20Sopenharmony_ci#define CPT_MBOX_MSG_TYPE_NACK 2 308c2ecf20Sopenharmony_ci#define CPT_MBOX_MSG_TIMEOUT 2000 318c2ecf20Sopenharmony_ci#define VF_STATE_DOWN 0 328c2ecf20Sopenharmony_ci#define VF_STATE_UP 1 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci/* 358c2ecf20Sopenharmony_ci * CPT Registers map for 81xx 368c2ecf20Sopenharmony_ci */ 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci/* PF registers */ 398c2ecf20Sopenharmony_ci#define CPTX_PF_CONSTANTS(a) (0x0ll + ((u64)(a) << 36)) 408c2ecf20Sopenharmony_ci#define CPTX_PF_RESET(a) (0x100ll + ((u64)(a) << 36)) 418c2ecf20Sopenharmony_ci#define CPTX_PF_DIAG(a) (0x120ll + ((u64)(a) << 36)) 428c2ecf20Sopenharmony_ci#define CPTX_PF_BIST_STATUS(a) (0x160ll + ((u64)(a) << 36)) 438c2ecf20Sopenharmony_ci#define CPTX_PF_ECC0_CTL(a) (0x200ll + ((u64)(a) << 36)) 448c2ecf20Sopenharmony_ci#define CPTX_PF_ECC0_FLIP(a) (0x210ll + ((u64)(a) << 36)) 458c2ecf20Sopenharmony_ci#define CPTX_PF_ECC0_INT(a) (0x220ll + ((u64)(a) << 36)) 468c2ecf20Sopenharmony_ci#define CPTX_PF_ECC0_INT_W1S(a) (0x230ll + ((u64)(a) << 36)) 478c2ecf20Sopenharmony_ci#define CPTX_PF_ECC0_ENA_W1S(a) (0x240ll + ((u64)(a) << 36)) 488c2ecf20Sopenharmony_ci#define CPTX_PF_ECC0_ENA_W1C(a) (0x250ll + ((u64)(a) << 36)) 498c2ecf20Sopenharmony_ci#define CPTX_PF_MBOX_INTX(a, b) \ 508c2ecf20Sopenharmony_ci (0x400ll + ((u64)(a) << 36) + ((b) << 3)) 518c2ecf20Sopenharmony_ci#define CPTX_PF_MBOX_INT_W1SX(a, b) \ 528c2ecf20Sopenharmony_ci (0x420ll + ((u64)(a) << 36) + ((b) << 3)) 538c2ecf20Sopenharmony_ci#define CPTX_PF_MBOX_ENA_W1CX(a, b) \ 548c2ecf20Sopenharmony_ci (0x440ll + ((u64)(a) << 36) + ((b) << 3)) 558c2ecf20Sopenharmony_ci#define CPTX_PF_MBOX_ENA_W1SX(a, b) \ 568c2ecf20Sopenharmony_ci (0x460ll + ((u64)(a) << 36) + ((b) << 3)) 578c2ecf20Sopenharmony_ci#define CPTX_PF_EXEC_INT(a) (0x500ll + 0x1000000000ll * ((a) & 0x1)) 588c2ecf20Sopenharmony_ci#define CPTX_PF_EXEC_INT_W1S(a) (0x520ll + ((u64)(a) << 36)) 598c2ecf20Sopenharmony_ci#define CPTX_PF_EXEC_ENA_W1C(a) (0x540ll + ((u64)(a) << 36)) 608c2ecf20Sopenharmony_ci#define CPTX_PF_EXEC_ENA_W1S(a) (0x560ll + ((u64)(a) << 36)) 618c2ecf20Sopenharmony_ci#define CPTX_PF_GX_EN(a, b) \ 628c2ecf20Sopenharmony_ci (0x600ll + ((u64)(a) << 36) + ((b) << 3)) 638c2ecf20Sopenharmony_ci#define CPTX_PF_EXEC_INFO(a) (0x700ll + ((u64)(a) << 36)) 648c2ecf20Sopenharmony_ci#define CPTX_PF_EXEC_BUSY(a) (0x800ll + ((u64)(a) << 36)) 658c2ecf20Sopenharmony_ci#define CPTX_PF_EXEC_INFO0(a) (0x900ll + ((u64)(a) << 36)) 668c2ecf20Sopenharmony_ci#define CPTX_PF_EXEC_INFO1(a) (0x910ll + ((u64)(a) << 36)) 678c2ecf20Sopenharmony_ci#define CPTX_PF_INST_REQ_PC(a) (0x10000ll + ((u64)(a) << 36)) 688c2ecf20Sopenharmony_ci#define CPTX_PF_INST_LATENCY_PC(a) \ 698c2ecf20Sopenharmony_ci (0x10020ll + ((u64)(a) << 36)) 708c2ecf20Sopenharmony_ci#define CPTX_PF_RD_REQ_PC(a) (0x10040ll + ((u64)(a) << 36)) 718c2ecf20Sopenharmony_ci#define CPTX_PF_RD_LATENCY_PC(a) (0x10060ll + ((u64)(a) << 36)) 728c2ecf20Sopenharmony_ci#define CPTX_PF_RD_UC_PC(a) (0x10080ll + ((u64)(a) << 36)) 738c2ecf20Sopenharmony_ci#define CPTX_PF_ACTIVE_CYCLES_PC(a) (0x10100ll + ((u64)(a) << 36)) 748c2ecf20Sopenharmony_ci#define CPTX_PF_EXE_CTL(a) (0x4000000ll + ((u64)(a) << 36)) 758c2ecf20Sopenharmony_ci#define CPTX_PF_EXE_STATUS(a) (0x4000008ll + ((u64)(a) << 36)) 768c2ecf20Sopenharmony_ci#define CPTX_PF_EXE_CLK(a) (0x4000010ll + ((u64)(a) << 36)) 778c2ecf20Sopenharmony_ci#define CPTX_PF_EXE_DBG_CTL(a) (0x4000018ll + ((u64)(a) << 36)) 788c2ecf20Sopenharmony_ci#define CPTX_PF_EXE_DBG_DATA(a) (0x4000020ll + ((u64)(a) << 36)) 798c2ecf20Sopenharmony_ci#define CPTX_PF_EXE_BIST_STATUS(a) (0x4000028ll + ((u64)(a) << 36)) 808c2ecf20Sopenharmony_ci#define CPTX_PF_EXE_REQ_TIMER(a) (0x4000030ll + ((u64)(a) << 36)) 818c2ecf20Sopenharmony_ci#define CPTX_PF_EXE_MEM_CTL(a) (0x4000038ll + ((u64)(a) << 36)) 828c2ecf20Sopenharmony_ci#define CPTX_PF_EXE_PERF_CTL(a) (0x4001000ll + ((u64)(a) << 36)) 838c2ecf20Sopenharmony_ci#define CPTX_PF_EXE_DBG_CNTX(a, b) \ 848c2ecf20Sopenharmony_ci (0x4001100ll + ((u64)(a) << 36) + ((b) << 3)) 858c2ecf20Sopenharmony_ci#define CPTX_PF_EXE_PERF_EVENT_CNT(a) (0x4001180ll + ((u64)(a) << 36)) 868c2ecf20Sopenharmony_ci#define CPTX_PF_EXE_EPCI_INBX_CNT(a, b) \ 878c2ecf20Sopenharmony_ci (0x4001200ll + ((u64)(a) << 36) + ((b) << 3)) 888c2ecf20Sopenharmony_ci#define CPTX_PF_EXE_EPCI_OUTBX_CNT(a, b) \ 898c2ecf20Sopenharmony_ci (0x4001240ll + ((u64)(a) << 36) + ((b) << 3)) 908c2ecf20Sopenharmony_ci#define CPTX_PF_ENGX_UCODE_BASE(a, b) \ 918c2ecf20Sopenharmony_ci (0x4002000ll + ((u64)(a) << 36) + ((b) << 3)) 928c2ecf20Sopenharmony_ci#define CPTX_PF_QX_CTL(a, b) \ 938c2ecf20Sopenharmony_ci (0x8000000ll + ((u64)(a) << 36) + ((b) << 20)) 948c2ecf20Sopenharmony_ci#define CPTX_PF_QX_GMCTL(a, b) \ 958c2ecf20Sopenharmony_ci (0x8000020ll + ((u64)(a) << 36) + ((b) << 20)) 968c2ecf20Sopenharmony_ci#define CPTX_PF_QX_CTL2(a, b) \ 978c2ecf20Sopenharmony_ci (0x8000100ll + ((u64)(a) << 36) + ((b) << 20)) 988c2ecf20Sopenharmony_ci#define CPTX_PF_VFX_MBOXX(a, b, c) \ 998c2ecf20Sopenharmony_ci (0x8001000ll + ((u64)(a) << 36) + ((b) << 20) + ((c) << 8)) 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci/* VF registers */ 1028c2ecf20Sopenharmony_ci#define CPTX_VQX_CTL(a, b) (0x100ll + ((u64)(a) << 36) + ((b) << 20)) 1038c2ecf20Sopenharmony_ci#define CPTX_VQX_SADDR(a, b) (0x200ll + ((u64)(a) << 36) + ((b) << 20)) 1048c2ecf20Sopenharmony_ci#define CPTX_VQX_DONE_WAIT(a, b) (0x400ll + ((u64)(a) << 36) + ((b) << 20)) 1058c2ecf20Sopenharmony_ci#define CPTX_VQX_INPROG(a, b) (0x410ll + ((u64)(a) << 36) + ((b) << 20)) 1068c2ecf20Sopenharmony_ci#define CPTX_VQX_DONE(a, b) (0x420ll + ((u64)(a) << 36) + ((b) << 20)) 1078c2ecf20Sopenharmony_ci#define CPTX_VQX_DONE_ACK(a, b) (0x440ll + ((u64)(a) << 36) + ((b) << 20)) 1088c2ecf20Sopenharmony_ci#define CPTX_VQX_DONE_INT_W1S(a, b) (0x460ll + ((u64)(a) << 36) + ((b) << 20)) 1098c2ecf20Sopenharmony_ci#define CPTX_VQX_DONE_INT_W1C(a, b) (0x468ll + ((u64)(a) << 36) + ((b) << 20)) 1108c2ecf20Sopenharmony_ci#define CPTX_VQX_DONE_ENA_W1S(a, b) (0x470ll + ((u64)(a) << 36) + ((b) << 20)) 1118c2ecf20Sopenharmony_ci#define CPTX_VQX_DONE_ENA_W1C(a, b) (0x478ll + ((u64)(a) << 36) + ((b) << 20)) 1128c2ecf20Sopenharmony_ci#define CPTX_VQX_MISC_INT(a, b) (0x500ll + ((u64)(a) << 36) + ((b) << 20)) 1138c2ecf20Sopenharmony_ci#define CPTX_VQX_MISC_INT_W1S(a, b) (0x508ll + ((u64)(a) << 36) + ((b) << 20)) 1148c2ecf20Sopenharmony_ci#define CPTX_VQX_MISC_ENA_W1S(a, b) (0x510ll + ((u64)(a) << 36) + ((b) << 20)) 1158c2ecf20Sopenharmony_ci#define CPTX_VQX_MISC_ENA_W1C(a, b) (0x518ll + ((u64)(a) << 36) + ((b) << 20)) 1168c2ecf20Sopenharmony_ci#define CPTX_VQX_DOORBELL(a, b) (0x600ll + ((u64)(a) << 36) + ((b) << 20)) 1178c2ecf20Sopenharmony_ci#define CPTX_VFX_PF_MBOXX(a, b, c) \ 1188c2ecf20Sopenharmony_ci (0x1000ll + ((u64)(a) << 36) + ((b) << 20) + ((c) << 3)) 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_cienum vftype { 1218c2ecf20Sopenharmony_ci AE_TYPES = 1, 1228c2ecf20Sopenharmony_ci SE_TYPES = 2, 1238c2ecf20Sopenharmony_ci BAD_CPT_TYPES, 1248c2ecf20Sopenharmony_ci}; 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci/* Max CPT devices supported */ 1278c2ecf20Sopenharmony_cienum cpt_mbox_opcode { 1288c2ecf20Sopenharmony_ci CPT_MSG_VF_UP = 1, 1298c2ecf20Sopenharmony_ci CPT_MSG_VF_DOWN, 1308c2ecf20Sopenharmony_ci CPT_MSG_READY, 1318c2ecf20Sopenharmony_ci CPT_MSG_QLEN, 1328c2ecf20Sopenharmony_ci CPT_MSG_QBIND_GRP, 1338c2ecf20Sopenharmony_ci CPT_MSG_VQ_PRIORITY, 1348c2ecf20Sopenharmony_ci}; 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci/* CPT mailbox structure */ 1378c2ecf20Sopenharmony_cistruct cpt_mbox { 1388c2ecf20Sopenharmony_ci u64 msg; /* Message type MBOX[0] */ 1398c2ecf20Sopenharmony_ci u64 data;/* Data MBOX[1] */ 1408c2ecf20Sopenharmony_ci}; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci/* Register read/write APIs */ 1438c2ecf20Sopenharmony_cistatic inline void cpt_write_csr64(u8 __iomem *hw_addr, u64 offset, 1448c2ecf20Sopenharmony_ci u64 val) 1458c2ecf20Sopenharmony_ci{ 1468c2ecf20Sopenharmony_ci writeq(val, hw_addr + offset); 1478c2ecf20Sopenharmony_ci} 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_cistatic inline u64 cpt_read_csr64(u8 __iomem *hw_addr, u64 offset) 1508c2ecf20Sopenharmony_ci{ 1518c2ecf20Sopenharmony_ci return readq(hw_addr + offset); 1528c2ecf20Sopenharmony_ci} 1538c2ecf20Sopenharmony_ci#endif /* __CPT_COMMON_H */ 154