Skip to content

Commit f24be42

Browse files
Christophe Lombardmpe
authored andcommitted
cxl: Add psl9 specific code
The new Coherent Accelerator Interface Architecture, level 2, for the IBM POWER9 brings new content and features: - POWER9 Service Layer - Registers - Radix mode - Process element entry - Dedicated-Shared Process Programming Model - Translation Fault Handling - CAPP - Memory Context ID If a valid mm_struct is found the memory context id is used for each transaction associated with the process handle. The PSL uses the context ID to find the corresponding process element. Signed-off-by: Christophe Lombard <[email protected]> Acked-by: Frederic Barrat <[email protected]> [mpe: Fixup comment formatting, unsplit long strings] Signed-off-by: Michael Ellerman <[email protected]>
1 parent abd1d99 commit f24be42

File tree

10 files changed

+764
-76
lines changed

10 files changed

+764
-76
lines changed

Documentation/powerpc/cxl.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Introduction
2121
Hardware overview
2222
=================
2323

24-
POWER8 FPGA
24+
POWER8/9 FPGA
2525
+----------+ +---------+
2626
| | | |
2727
| CPU | | AFU |
@@ -34,7 +34,7 @@ Hardware overview
3434
| | CAPP |<------>| |
3535
+---+------+ PCIE +---------+
3636

37-
The POWER8 chip has a Coherently Attached Processor Proxy (CAPP)
37+
The POWER8/9 chip has a Coherently Attached Processor Proxy (CAPP)
3838
unit which is part of the PCIe Host Bridge (PHB). This is managed
3939
by Linux by calls into OPAL. Linux doesn't directly program the
4040
CAPP.
@@ -59,6 +59,17 @@ Hardware overview
5959
the fault. The context to which this fault is serviced is based on
6060
who owns that acceleration function.
6161

62+
POWER8 <-----> PSL Version 8 is compliant to the CAIA Version 1.0.
63+
POWER9 <-----> PSL Version 9 is compliant to the CAIA Version 2.0.
64+
This PSL Version 9 provides new features such as:
65+
* Interaction with the nest MMU on the P9 chip.
66+
* Native DMA support.
67+
* Supports sending ASB_Notify messages for host thread wakeup.
68+
* Supports Atomic operations.
69+
* ....
70+
71+
Cards with a PSL9 won't work on a POWER8 system and cards with a
72+
PSL8 won't work on a POWER9 system.
6273

6374
AFU Modes
6475
=========

drivers/misc/cxl/context.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,13 +188,26 @@ int cxl_context_iomap(struct cxl_context *ctx, struct vm_area_struct *vma)
188188
if (ctx->afu->current_mode == CXL_MODE_DEDICATED) {
189189
if (start + len > ctx->afu->adapter->ps_size)
190190
return -EINVAL;
191+
192+
if (cxl_is_psl9(ctx->afu)) {
193+
/*
194+
* Make sure there is a valid problem state
195+
* area space for this AFU.
196+
*/
197+
if (ctx->master && !ctx->afu->psa) {
198+
pr_devel("AFU doesn't support mmio space\n");
199+
return -EINVAL;
200+
}
201+
202+
/* Can't mmap until the AFU is enabled */
203+
if (!ctx->afu->enabled)
204+
return -EBUSY;
205+
}
191206
} else {
192207
if (start + len > ctx->psn_size)
193208
return -EINVAL;
194-
}
195209

196-
if (ctx->afu->current_mode != CXL_MODE_DEDICATED) {
197-
/* make sure there is a valid per process space for this AFU */
210+
/* Make sure there is a valid per process space for this AFU */
198211
if ((ctx->master && !ctx->afu->psa) || (!ctx->afu->pp_psa)) {
199212
pr_devel("AFU doesn't support mmio space\n");
200213
return -EINVAL;

drivers/misc/cxl/cxl.h

Lines changed: 120 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ typedef struct {
6363
/* Memory maps. Ref CXL Appendix A */
6464

6565
/* PSL Privilege 1 Memory Map */
66-
/* Configuration and Control area */
66+
/* Configuration and Control area - CAIA 1&2 */
6767
static const cxl_p1_reg_t CXL_PSL_CtxTime = {0x0000};
6868
static const cxl_p1_reg_t CXL_PSL_ErrIVTE = {0x0008};
6969
static const cxl_p1_reg_t CXL_PSL_KEY1 = {0x0010};
@@ -98,11 +98,29 @@ static const cxl_p1_reg_t CXL_XSL_Timebase = {0x0100};
9898
static const cxl_p1_reg_t CXL_XSL_TB_CTLSTAT = {0x0108};
9999
static const cxl_p1_reg_t CXL_XSL_FEC = {0x0158};
100100
static const cxl_p1_reg_t CXL_XSL_DSNCTL = {0x0168};
101+
/* PSL registers - CAIA 2 */
102+
static const cxl_p1_reg_t CXL_PSL9_CONTROL = {0x0020};
103+
static const cxl_p1_reg_t CXL_XSL9_DSNCTL = {0x0168};
104+
static const cxl_p1_reg_t CXL_PSL9_FIR1 = {0x0300};
105+
static const cxl_p1_reg_t CXL_PSL9_FIR2 = {0x0308};
106+
static const cxl_p1_reg_t CXL_PSL9_Timebase = {0x0310};
107+
static const cxl_p1_reg_t CXL_PSL9_DEBUG = {0x0320};
108+
static const cxl_p1_reg_t CXL_PSL9_FIR_CNTL = {0x0348};
109+
static const cxl_p1_reg_t CXL_PSL9_DSNDCTL = {0x0350};
110+
static const cxl_p1_reg_t CXL_PSL9_TB_CTLSTAT = {0x0340};
111+
static const cxl_p1_reg_t CXL_PSL9_TRACECFG = {0x0368};
112+
static const cxl_p1_reg_t CXL_PSL9_APCDEDALLOC = {0x0378};
113+
static const cxl_p1_reg_t CXL_PSL9_APCDEDTYPE = {0x0380};
114+
static const cxl_p1_reg_t CXL_PSL9_TNR_ADDR = {0x0388};
115+
static const cxl_p1_reg_t CXL_PSL9_GP_CT = {0x0398};
116+
static const cxl_p1_reg_t CXL_XSL9_IERAT = {0x0588};
117+
static const cxl_p1_reg_t CXL_XSL9_ILPP = {0x0590};
118+
101119
/* 0x7F00:7FFF Reserved PCIe MSI-X Pending Bit Array area */
102120
/* 0x8000:FFFF Reserved PCIe MSI-X Table Area */
103121

104122
/* PSL Slice Privilege 1 Memory Map */
105-
/* Configuration Area */
123+
/* Configuration Area - CAIA 1&2 */
106124
static const cxl_p1n_reg_t CXL_PSL_SR_An = {0x00};
107125
static const cxl_p1n_reg_t CXL_PSL_LPID_An = {0x08};
108126
static const cxl_p1n_reg_t CXL_PSL_AMBAR_An = {0x10};
@@ -111,17 +129,18 @@ static const cxl_p1n_reg_t CXL_PSL_ID_An = {0x20};
111129
static const cxl_p1n_reg_t CXL_PSL_SERR_An = {0x28};
112130
/* Memory Management and Lookaside Buffer Management - CAIA 1*/
113131
static const cxl_p1n_reg_t CXL_PSL_SDR_An = {0x30};
132+
/* Memory Management and Lookaside Buffer Management - CAIA 1&2 */
114133
static const cxl_p1n_reg_t CXL_PSL_AMOR_An = {0x38};
115-
/* Pointer Area */
134+
/* Pointer Area - CAIA 1&2 */
116135
static const cxl_p1n_reg_t CXL_HAURP_An = {0x80};
117136
static const cxl_p1n_reg_t CXL_PSL_SPAP_An = {0x88};
118137
static const cxl_p1n_reg_t CXL_PSL_LLCMD_An = {0x90};
119-
/* Control Area */
138+
/* Control Area - CAIA 1&2 */
120139
static const cxl_p1n_reg_t CXL_PSL_SCNTL_An = {0xA0};
121140
static const cxl_p1n_reg_t CXL_PSL_CtxTime_An = {0xA8};
122141
static const cxl_p1n_reg_t CXL_PSL_IVTE_Offset_An = {0xB0};
123142
static const cxl_p1n_reg_t CXL_PSL_IVTE_Limit_An = {0xB8};
124-
/* 0xC0:FF Implementation Dependent Area */
143+
/* 0xC0:FF Implementation Dependent Area - CAIA 1&2 */
125144
static const cxl_p1n_reg_t CXL_PSL_FIR_SLICE_An = {0xC0};
126145
static const cxl_p1n_reg_t CXL_AFU_DEBUG_An = {0xC8};
127146
/* 0xC0:FF Implementation Dependent Area - CAIA 1 */
@@ -131,7 +150,7 @@ static const cxl_p1n_reg_t CXL_PSL_RXCTL_A = {0xE0};
131150
static const cxl_p1n_reg_t CXL_PSL_SLICE_TRACE = {0xE8};
132151

133152
/* PSL Slice Privilege 2 Memory Map */
134-
/* Configuration and Control Area */
153+
/* Configuration and Control Area - CAIA 1&2 */
135154
static const cxl_p2n_reg_t CXL_PSL_PID_TID_An = {0x000};
136155
static const cxl_p2n_reg_t CXL_CSRP_An = {0x008};
137156
/* Configuration and Control Area - CAIA 1 */
@@ -145,17 +164,17 @@ static const cxl_p2n_reg_t CXL_PSL_AMR_An = {0x030};
145164
static const cxl_p2n_reg_t CXL_SLBIE_An = {0x040};
146165
static const cxl_p2n_reg_t CXL_SLBIA_An = {0x048};
147166
static const cxl_p2n_reg_t CXL_SLBI_Select_An = {0x050};
148-
/* Interrupt Registers */
167+
/* Interrupt Registers - CAIA 1&2 */
149168
static const cxl_p2n_reg_t CXL_PSL_DSISR_An = {0x060};
150169
static const cxl_p2n_reg_t CXL_PSL_DAR_An = {0x068};
151170
static const cxl_p2n_reg_t CXL_PSL_DSR_An = {0x070};
152171
static const cxl_p2n_reg_t CXL_PSL_TFC_An = {0x078};
153172
static const cxl_p2n_reg_t CXL_PSL_PEHandle_An = {0x080};
154173
static const cxl_p2n_reg_t CXL_PSL_ErrStat_An = {0x088};
155-
/* AFU Registers */
174+
/* AFU Registers - CAIA 1&2 */
156175
static const cxl_p2n_reg_t CXL_AFU_Cntl_An = {0x090};
157176
static const cxl_p2n_reg_t CXL_AFU_ERR_An = {0x098};
158-
/* Work Element Descriptor */
177+
/* Work Element Descriptor - CAIA 1&2 */
159178
static const cxl_p2n_reg_t CXL_PSL_WED_An = {0x0A0};
160179
/* 0x0C0:FFF Implementation Dependent Area */
161180

@@ -182,6 +201,10 @@ static const cxl_p2n_reg_t CXL_PSL_WED_An = {0x0A0};
182201
#define CXL_PSL_SR_An_SF MSR_SF /* 64bit */
183202
#define CXL_PSL_SR_An_TA (1ull << (63-1)) /* Tags active, GA1: 0 */
184203
#define CXL_PSL_SR_An_HV MSR_HV /* Hypervisor, GA1: 0 */
204+
#define CXL_PSL_SR_An_XLAT_hpt (0ull << (63-6))/* Hashed page table (HPT) mode */
205+
#define CXL_PSL_SR_An_XLAT_roh (2ull << (63-6))/* Radix on HPT mode */
206+
#define CXL_PSL_SR_An_XLAT_ror (3ull << (63-6))/* Radix on Radix mode */
207+
#define CXL_PSL_SR_An_BOT (1ull << (63-10)) /* Use the in-memory segment table */
185208
#define CXL_PSL_SR_An_PR MSR_PR /* Problem state, GA1: 1 */
186209
#define CXL_PSL_SR_An_ISL (1ull << (63-53)) /* Ignore Segment Large Page */
187210
#define CXL_PSL_SR_An_TC (1ull << (63-54)) /* Page Table secondary hash */
@@ -298,12 +321,39 @@ static const cxl_p2n_reg_t CXL_PSL_WED_An = {0x0A0};
298321
#define CXL_PSL_DSISR_An_S DSISR_ISSTORE /* Access was afu_wr or afu_zero */
299322
#define CXL_PSL_DSISR_An_K DSISR_KEYFAULT /* Access not permitted by virtual page class key protection */
300323

324+
/****** CXL_PSL_DSISR_An - CAIA 2 ****************************************************/
325+
#define CXL_PSL9_DSISR_An_TF (1ull << (63-3)) /* Translation fault */
326+
#define CXL_PSL9_DSISR_An_PE (1ull << (63-4)) /* PSL Error (implementation specific) */
327+
#define CXL_PSL9_DSISR_An_AE (1ull << (63-5)) /* AFU Error */
328+
#define CXL_PSL9_DSISR_An_OC (1ull << (63-6)) /* OS Context Warning */
329+
#define CXL_PSL9_DSISR_An_S (1ull << (63-38)) /* TF for a write operation */
330+
#define CXL_PSL9_DSISR_PENDING (CXL_PSL9_DSISR_An_TF | CXL_PSL9_DSISR_An_PE | CXL_PSL9_DSISR_An_AE | CXL_PSL9_DSISR_An_OC)
331+
/*
332+
* NOTE: Bits 56:63 (Checkout Response Status) are valid when DSISR_An[TF] = 1
333+
* Status (0:7) Encoding
334+
*/
335+
#define CXL_PSL9_DSISR_An_CO_MASK 0x00000000000000ffULL
336+
#define CXL_PSL9_DSISR_An_SF 0x0000000000000080ULL /* Segment Fault 0b10000000 */
337+
#define CXL_PSL9_DSISR_An_PF_SLR 0x0000000000000088ULL /* PTE not found (Single Level Radix) 0b10001000 */
338+
#define CXL_PSL9_DSISR_An_PF_RGC 0x000000000000008CULL /* PTE not found (Radix Guest (child)) 0b10001100 */
339+
#define CXL_PSL9_DSISR_An_PF_RGP 0x0000000000000090ULL /* PTE not found (Radix Guest (parent)) 0b10010000 */
340+
#define CXL_PSL9_DSISR_An_PF_HRH 0x0000000000000094ULL /* PTE not found (HPT/Radix Host) 0b10010100 */
341+
#define CXL_PSL9_DSISR_An_PF_STEG 0x000000000000009CULL /* PTE not found (STEG VA) 0b10011100 */
342+
301343
/****** CXL_PSL_TFC_An ******************************************************/
302344
#define CXL_PSL_TFC_An_A (1ull << (63-28)) /* Acknowledge non-translation fault */
303345
#define CXL_PSL_TFC_An_C (1ull << (63-29)) /* Continue (abort transaction) */
304346
#define CXL_PSL_TFC_An_AE (1ull << (63-30)) /* Restart PSL with address error */
305347
#define CXL_PSL_TFC_An_R (1ull << (63-31)) /* Restart PSL transaction */
306348

349+
/****** CXL_XSL9_IERAT_ERAT - CAIA 2 **********************************/
350+
#define CXL_XSL9_IERAT_MLPID (1ull << (63-0)) /* Match LPID */
351+
#define CXL_XSL9_IERAT_MPID (1ull << (63-1)) /* Match PID */
352+
#define CXL_XSL9_IERAT_PRS (1ull << (63-4)) /* PRS bit for Radix invalidations */
353+
#define CXL_XSL9_IERAT_INVR (1ull << (63-3)) /* Invalidate Radix */
354+
#define CXL_XSL9_IERAT_IALL (1ull << (63-8)) /* Invalidate All */
355+
#define CXL_XSL9_IERAT_IINPROG (1ull << (63-63)) /* Invalidate in progress */
356+
307357
/* cxl_process_element->software_status */
308358
#define CXL_PE_SOFTWARE_STATE_V (1ul << (31 - 0)) /* Valid */
309359
#define CXL_PE_SOFTWARE_STATE_C (1ul << (31 - 29)) /* Complete */
@@ -654,25 +704,38 @@ int cxl_pci_reset(struct cxl *adapter);
654704
void cxl_pci_release_afu(struct device *dev);
655705
ssize_t cxl_pci_read_adapter_vpd(struct cxl *adapter, void *buf, size_t len);
656706

657-
/* common == phyp + powernv */
707+
/* common == phyp + powernv - CAIA 1&2 */
658708
struct cxl_process_element_common {
659709
__be32 tid;
660710
__be32 pid;
661711
__be64 csrp;
662-
__be64 aurp0;
663-
__be64 aurp1;
664-
__be64 sstp0;
665-
__be64 sstp1;
712+
union {
713+
struct {
714+
__be64 aurp0;
715+
__be64 aurp1;
716+
__be64 sstp0;
717+
__be64 sstp1;
718+
} psl8; /* CAIA 1 */
719+
struct {
720+
u8 reserved2[8];
721+
u8 reserved3[8];
722+
u8 reserved4[8];
723+
u8 reserved5[8];
724+
} psl9; /* CAIA 2 */
725+
} u;
666726
__be64 amr;
667-
u8 reserved3[4];
727+
u8 reserved6[4];
668728
__be64 wed;
669729
} __packed;
670730

671-
/* just powernv */
731+
/* just powernv - CAIA 1&2 */
672732
struct cxl_process_element {
673733
__be64 sr;
674734
__be64 SPOffset;
675-
__be64 sdr;
735+
union {
736+
__be64 sdr; /* CAIA 1 */
737+
u8 reserved1[8]; /* CAIA 2 */
738+
} u;
676739
__be64 haurp;
677740
__be32 ctxtime;
678741
__be16 ivte_offsets[4];
@@ -761,13 +824,30 @@ static inline bool cxl_is_power8(void)
761824
return false;
762825
}
763826

827+
static inline bool cxl_is_power9(void)
828+
{
829+
/* intermediate solution */
830+
if (!cxl_is_power8() &&
831+
(cpu_has_feature(CPU_FTRS_POWER9) ||
832+
cpu_has_feature(CPU_FTR_POWER9_DD1)))
833+
return true;
834+
return false;
835+
}
836+
764837
static inline bool cxl_is_psl8(struct cxl_afu *afu)
765838
{
766839
if (afu->adapter->caia_major == 1)
767840
return true;
768841
return false;
769842
}
770843

844+
static inline bool cxl_is_psl9(struct cxl_afu *afu)
845+
{
846+
if (afu->adapter->caia_major == 2)
847+
return true;
848+
return false;
849+
}
850+
771851
ssize_t cxl_pci_afu_read_err_buffer(struct cxl_afu *afu, char *buf,
772852
loff_t off, size_t count);
773853

@@ -794,7 +874,6 @@ int cxl_update_properties(struct device_node *dn, struct property *new_prop);
794874

795875
void cxl_remove_adapter_nr(struct cxl *adapter);
796876

797-
int cxl_alloc_spa(struct cxl_afu *afu);
798877
void cxl_release_spa(struct cxl_afu *afu);
799878

800879
dev_t cxl_get_dev(void);
@@ -832,9 +911,13 @@ int afu_register_irqs(struct cxl_context *ctx, u32 count);
832911
void afu_release_irqs(struct cxl_context *ctx, void *cookie);
833912
void afu_irq_name_free(struct cxl_context *ctx);
834913

914+
int cxl_attach_afu_directed_psl9(struct cxl_context *ctx, u64 wed, u64 amr);
835915
int cxl_attach_afu_directed_psl8(struct cxl_context *ctx, u64 wed, u64 amr);
916+
int cxl_activate_dedicated_process_psl9(struct cxl_afu *afu);
836917
int cxl_activate_dedicated_process_psl8(struct cxl_afu *afu);
918+
int cxl_attach_dedicated_process_psl9(struct cxl_context *ctx, u64 wed, u64 amr);
837919
int cxl_attach_dedicated_process_psl8(struct cxl_context *ctx, u64 wed, u64 amr);
920+
void cxl_update_dedicated_ivtes_psl9(struct cxl_context *ctx);
838921
void cxl_update_dedicated_ivtes_psl8(struct cxl_context *ctx);
839922

840923
#ifdef CONFIG_DEBUG_FS
@@ -845,9 +928,12 @@ int cxl_debugfs_adapter_add(struct cxl *adapter);
845928
void cxl_debugfs_adapter_remove(struct cxl *adapter);
846929
int cxl_debugfs_afu_add(struct cxl_afu *afu);
847930
void cxl_debugfs_afu_remove(struct cxl_afu *afu);
931+
void cxl_stop_trace_psl9(struct cxl *cxl);
848932
void cxl_stop_trace_psl8(struct cxl *cxl);
933+
void cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter, struct dentry *dir);
849934
void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter, struct dentry *dir);
850935
void cxl_debugfs_add_adapter_regs_xsl(struct cxl *adapter, struct dentry *dir);
936+
void cxl_debugfs_add_afu_regs_psl9(struct cxl_afu *afu, struct dentry *dir);
851937
void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir);
852938

853939
#else /* CONFIG_DEBUG_FS */
@@ -879,10 +965,19 @@ static inline void cxl_debugfs_afu_remove(struct cxl_afu *afu)
879965
{
880966
}
881967

968+
static inline void cxl_stop_trace_psl9(struct cxl *cxl)
969+
{
970+
}
971+
882972
static inline void cxl_stop_trace_psl8(struct cxl *cxl)
883973
{
884974
}
885975

976+
static inline void cxl_debugfs_add_adapter_regs_psl9(struct cxl *adapter,
977+
struct dentry *dir)
978+
{
979+
}
980+
886981
static inline void cxl_debugfs_add_adapter_regs_psl8(struct cxl *adapter,
887982
struct dentry *dir)
888983
{
@@ -893,6 +988,10 @@ static inline void cxl_debugfs_add_adapter_regs_xsl(struct cxl *adapter,
893988
{
894989
}
895990

991+
static inline void cxl_debugfs_add_afu_regs_psl9(struct cxl_afu *afu, struct dentry *dir)
992+
{
993+
}
994+
896995
static inline void cxl_debugfs_add_afu_regs_psl8(struct cxl_afu *afu, struct dentry *dir)
897996
{
898997
}
@@ -938,7 +1037,9 @@ struct cxl_irq_info {
9381037
};
9391038

9401039
void cxl_assign_psn_space(struct cxl_context *ctx);
1040+
int cxl_invalidate_all_psl9(struct cxl *adapter);
9411041
int cxl_invalidate_all_psl8(struct cxl *adapter);
1042+
irqreturn_t cxl_irq_psl9(int irq, struct cxl_context *ctx, struct cxl_irq_info *irq_info);
9421043
irqreturn_t cxl_irq_psl8(int irq, struct cxl_context *ctx, struct cxl_irq_info *irq_info);
9431044
irqreturn_t cxl_fail_irq_psl(struct cxl_afu *afu, struct cxl_irq_info *irq_info);
9441045
int cxl_register_one_irq(struct cxl *adapter, irq_handler_t handler,
@@ -951,6 +1052,7 @@ int cxl_data_cache_flush(struct cxl *adapter);
9511052
int cxl_afu_disable(struct cxl_afu *afu);
9521053
int cxl_psl_purge(struct cxl_afu *afu);
9531054

1055+
void cxl_native_irq_dump_regs_psl9(struct cxl_context *ctx);
9541056
void cxl_native_irq_dump_regs_psl8(struct cxl_context *ctx);
9551057
void cxl_native_err_irq_dump_regs(struct cxl *adapter);
9561058
int cxl_pci_vphb_add(struct cxl_afu *afu);

0 commit comments

Comments
 (0)