18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * CXL Flash Device Driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Written by: Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
68c2ecf20Sopenharmony_ci *	       Uma Krishnan <ukrishn@linux.vnet.ibm.com>, IBM Corporation
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Copyright (C) 2018 IBM Corporation
98c2ecf20Sopenharmony_ci */
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#define OCXL_MAX_IRQS	4	/* Max interrupts per process */
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_cistruct ocxlflash_irqs {
148c2ecf20Sopenharmony_ci	int hwirq;
158c2ecf20Sopenharmony_ci	u32 virq;
168c2ecf20Sopenharmony_ci	void __iomem *vtrig;
178c2ecf20Sopenharmony_ci};
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci/* OCXL hardware AFU associated with the host */
208c2ecf20Sopenharmony_cistruct ocxl_hw_afu {
218c2ecf20Sopenharmony_ci	struct ocxlflash_context *ocxl_ctx; /* Host context */
228c2ecf20Sopenharmony_ci	struct pci_dev *pdev;		/* PCI device */
238c2ecf20Sopenharmony_ci	struct device *dev;		/* Generic device */
248c2ecf20Sopenharmony_ci	bool perst_same_image;		/* Same image loaded on perst */
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci	struct ocxl_fn_config fcfg;	/* DVSEC config of the function */
278c2ecf20Sopenharmony_ci	struct ocxl_afu_config acfg;	/* AFU configuration data */
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci	int fn_actag_base;		/* Function acTag base */
308c2ecf20Sopenharmony_ci	int fn_actag_enabled;		/* Function acTag number enabled */
318c2ecf20Sopenharmony_ci	int afu_actag_base;		/* AFU acTag base */
328c2ecf20Sopenharmony_ci	int afu_actag_enabled;		/* AFU acTag number enabled */
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci	phys_addr_t ppmmio_phys;	/* Per process MMIO space */
358c2ecf20Sopenharmony_ci	phys_addr_t gmmio_phys;		/* Global AFU MMIO space */
368c2ecf20Sopenharmony_ci	void __iomem *gmmio_virt;	/* Global MMIO map */
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci	void *link_token;		/* Link token for the SPA */
398c2ecf20Sopenharmony_ci	struct idr idr;			/* IDR to manage contexts */
408c2ecf20Sopenharmony_ci	int max_pasid;			/* Maximum number of contexts */
418c2ecf20Sopenharmony_ci	bool is_present;		/* Function has AFUs defined */
428c2ecf20Sopenharmony_ci};
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cienum ocxlflash_ctx_state {
458c2ecf20Sopenharmony_ci	CLOSED,
468c2ecf20Sopenharmony_ci	OPENED,
478c2ecf20Sopenharmony_ci	STARTED
488c2ecf20Sopenharmony_ci};
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_cistruct ocxlflash_context {
518c2ecf20Sopenharmony_ci	struct ocxl_hw_afu *hw_afu;	/* HW AFU back pointer */
528c2ecf20Sopenharmony_ci	struct address_space *mapping;	/* Mapping for pseudo filesystem */
538c2ecf20Sopenharmony_ci	bool master;			/* Whether this is a master context */
548c2ecf20Sopenharmony_ci	int pe;				/* Process element */
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_ci	phys_addr_t psn_phys;		/* Process mapping */
578c2ecf20Sopenharmony_ci	u64 psn_size;			/* Process mapping size */
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	spinlock_t slock;		/* Protects irq/fault/event updates */
608c2ecf20Sopenharmony_ci	wait_queue_head_t wq;		/* Wait queue for poll and interrupts */
618c2ecf20Sopenharmony_ci	struct mutex state_mutex;	/* Mutex to update context state */
628c2ecf20Sopenharmony_ci	enum ocxlflash_ctx_state state;	/* Context state */
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci	struct ocxlflash_irqs *irqs;	/* Pointer to array of structures */
658c2ecf20Sopenharmony_ci	int num_irqs;			/* Number of interrupts */
668c2ecf20Sopenharmony_ci	bool pending_irq;		/* Pending interrupt on the context */
678c2ecf20Sopenharmony_ci	ulong irq_bitmap;		/* Bits indicating pending irq num */
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci	u64 fault_addr;			/* Address that triggered the fault */
708c2ecf20Sopenharmony_ci	u64 fault_dsisr;		/* Value of dsisr register at fault */
718c2ecf20Sopenharmony_ci	bool pending_fault;		/* Pending translation fault */
728c2ecf20Sopenharmony_ci};
73