xref: /openbmc/linux/drivers/scsi/cxlflash/superpipe.h (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*2874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
265be2c79SMatthew R. Ochs /*
365be2c79SMatthew R. Ochs  * CXL Flash Device Driver
465be2c79SMatthew R. Ochs  *
565be2c79SMatthew R. Ochs  * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
665be2c79SMatthew R. Ochs  *             Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
765be2c79SMatthew R. Ochs  *
865be2c79SMatthew R. Ochs  * Copyright (C) 2015 IBM Corporation
965be2c79SMatthew R. Ochs  */
1065be2c79SMatthew R. Ochs 
1165be2c79SMatthew R. Ochs #ifndef _CXLFLASH_SUPERPIPE_H
1265be2c79SMatthew R. Ochs #define _CXLFLASH_SUPERPIPE_H
1365be2c79SMatthew R. Ochs 
1465be2c79SMatthew R. Ochs extern struct cxlflash_global global;
1565be2c79SMatthew R. Ochs 
1665be2c79SMatthew R. Ochs /*
1765be2c79SMatthew R. Ochs  * Terminology: use afu (and not adapter) to refer to the HW.
1865be2c79SMatthew R. Ochs  * Adapter is the entire slot and includes PSL out of which
1965be2c79SMatthew R. Ochs  * only the AFU is visible to user space.
2065be2c79SMatthew R. Ochs  */
2165be2c79SMatthew R. Ochs 
2265be2c79SMatthew R. Ochs /* Chunk size parms: note sislite minimum chunk size is
23fcc87e74SMatthew R. Ochs  * 0x10000 LBAs corresponding to a NMASK or 16.
2465be2c79SMatthew R. Ochs  */
2565be2c79SMatthew R. Ochs #define MC_CHUNK_SIZE     (1 << MC_RHT_NMASK)	/* in LBAs */
2665be2c79SMatthew R. Ochs 
27471a5a60SManoj Kumar #define CMD_TIMEOUT 30  /* 30 secs */
283ebf2030SManoj Kumar #define CMD_RETRIES 5   /* 5 retries for scsi_execute */
293ebf2030SManoj Kumar 
303ebf2030SManoj Kumar #define MAX_SECTOR_UNIT  512 /* max_sector is in 512 byte multiples */
3165be2c79SMatthew R. Ochs 
3265be2c79SMatthew R. Ochs enum lun_mode {
3365be2c79SMatthew R. Ochs 	MODE_NONE = 0,
342cb79266SMatthew R. Ochs 	MODE_VIRTUAL,
3565be2c79SMatthew R. Ochs 	MODE_PHYSICAL
3665be2c79SMatthew R. Ochs };
3765be2c79SMatthew R. Ochs 
3865be2c79SMatthew R. Ochs /* Global (entire driver, spans adapters) lun_info structure */
3965be2c79SMatthew R. Ochs struct glun_info {
4065be2c79SMatthew R. Ochs 	u64 max_lba;		/* from read cap(16) */
4165be2c79SMatthew R. Ochs 	u32 blk_len;		/* from read cap(16) */
422cb79266SMatthew R. Ochs 	enum lun_mode mode;	/* NONE, VIRTUAL, PHYSICAL */
4365be2c79SMatthew R. Ochs 	int users;		/* Number of users w/ references to LUN */
4465be2c79SMatthew R. Ochs 
4565be2c79SMatthew R. Ochs 	u8 wwid[16];
4665be2c79SMatthew R. Ochs 
4765be2c79SMatthew R. Ochs 	struct mutex mutex;
4865be2c79SMatthew R. Ochs 
492cb79266SMatthew R. Ochs 	struct blka blka;
5065be2c79SMatthew R. Ochs 	struct list_head list;
5165be2c79SMatthew R. Ochs };
5265be2c79SMatthew R. Ochs 
5365be2c79SMatthew R. Ochs /* Local (per-adapter) lun_info structure */
5465be2c79SMatthew R. Ochs struct llun_info {
5578ae028eSMatthew R. Ochs 	u64 lun_id[MAX_FC_PORTS]; /* from REPORT_LUNS */
5665be2c79SMatthew R. Ochs 	u32 lun_index;		/* Index in the LUN table */
5765be2c79SMatthew R. Ochs 	u32 host_no;		/* host_no from Scsi_host */
5865be2c79SMatthew R. Ochs 	u32 port_sel;		/* What port to use for this LUN */
592cb79266SMatthew R. Ochs 	bool in_table;		/* Whether a LUN table entry was created */
6065be2c79SMatthew R. Ochs 
6165be2c79SMatthew R. Ochs 	u8 wwid[16];		/* Keep a duplicate copy here? */
6265be2c79SMatthew R. Ochs 
6365be2c79SMatthew R. Ochs 	struct glun_info *parent; /* Pointer to entry in global LUN structure */
6465be2c79SMatthew R. Ochs 	struct scsi_device *sdev;
6565be2c79SMatthew R. Ochs 	struct list_head list;
6665be2c79SMatthew R. Ochs };
6765be2c79SMatthew R. Ochs 
6865be2c79SMatthew R. Ochs struct lun_access {
6965be2c79SMatthew R. Ochs 	struct llun_info *lli;
7065be2c79SMatthew R. Ochs 	struct scsi_device *sdev;
7165be2c79SMatthew R. Ochs 	struct list_head list;
7265be2c79SMatthew R. Ochs };
7365be2c79SMatthew R. Ochs 
7465be2c79SMatthew R. Ochs enum ctx_ctrl {
7565be2c79SMatthew R. Ochs 	CTX_CTRL_CLONE		= (1 << 1),
7665be2c79SMatthew R. Ochs 	CTX_CTRL_ERR		= (1 << 2),
7765be2c79SMatthew R. Ochs 	CTX_CTRL_ERR_FALLBACK	= (1 << 3),
7865be2c79SMatthew R. Ochs 	CTX_CTRL_NOPID		= (1 << 4),
7965be2c79SMatthew R. Ochs 	CTX_CTRL_FILE		= (1 << 5)
8065be2c79SMatthew R. Ochs };
8165be2c79SMatthew R. Ochs 
82a76df368SMatthew R. Ochs #define ENCODE_CTXID(_ctx, _id)	(((((u64)_ctx) & 0xFFFFFFFF0ULL) << 28) | _id)
8365be2c79SMatthew R. Ochs #define DECODE_CTXID(_val)	(_val & 0xFFFFFFFF)
8465be2c79SMatthew R. Ochs 
8565be2c79SMatthew R. Ochs struct ctx_info {
861786f4a0SMatthew R. Ochs 	struct sisl_ctrl_map __iomem *ctrl_map; /* initialized at startup */
8765be2c79SMatthew R. Ochs 	struct sisl_rht_entry *rht_start; /* 1 page (req'd for alignment),
88fcc87e74SMatthew R. Ochs 					   * alloc/free on attach/detach
89fcc87e74SMatthew R. Ochs 					   */
9065be2c79SMatthew R. Ochs 	u32 rht_out;		/* Number of checked out RHT entries */
9165be2c79SMatthew R. Ochs 	u32 rht_perms;		/* User-defined permissions for RHT entries */
9265be2c79SMatthew R. Ochs 	struct llun_info **rht_lun;       /* Mapping of RHT entries to LUNs */
93e568e23fSMatthew R. Ochs 	u8 *rht_needs_ws;	/* User-desired write-same function per RHTE */
9465be2c79SMatthew R. Ochs 
9565be2c79SMatthew R. Ochs 	u64 ctxid;
96af2047ecSMatthew R. Ochs 	u64 irqs; /* Number of interrupts requested for context */
9765be2c79SMatthew R. Ochs 	pid_t pid;
985e6632d1SMatthew R. Ochs 	bool initialized;
9965be2c79SMatthew R. Ochs 	bool unavail;
10065be2c79SMatthew R. Ochs 	bool err_recovery_active;
10165be2c79SMatthew R. Ochs 	struct mutex mutex; /* Context protection */
102888baf06SMatthew R. Ochs 	struct kref kref;
103b070545dSUma Krishnan 	void *ctx;
10444ef38f9SMatthew R. Ochs 	struct cxlflash_cfg *cfg;
10565be2c79SMatthew R. Ochs 	struct list_head luns;	/* LUNs attached to this context */
10665be2c79SMatthew R. Ochs 	const struct vm_operations_struct *cxl_mmap_vmops;
10765be2c79SMatthew R. Ochs 	struct file *file;
10865be2c79SMatthew R. Ochs 	struct list_head list; /* Link contexts in error recovery */
10965be2c79SMatthew R. Ochs };
11065be2c79SMatthew R. Ochs 
11165be2c79SMatthew R. Ochs struct cxlflash_global {
11265be2c79SMatthew R. Ochs 	struct mutex mutex;
11365be2c79SMatthew R. Ochs 	struct list_head gluns;/* list of glun_info structs */
11465be2c79SMatthew R. Ochs 	struct page *err_page; /* One page of all 0xF for error notification */
11565be2c79SMatthew R. Ochs };
11665be2c79SMatthew R. Ochs 
117fcc87e74SMatthew R. Ochs int cxlflash_vlun_resize(struct scsi_device *sdev,
118fcc87e74SMatthew R. Ochs 			 struct dk_cxlflash_resize *resize);
119fcc87e74SMatthew R. Ochs int _cxlflash_vlun_resize(struct scsi_device *sdev, struct ctx_info *ctxi,
120fcc87e74SMatthew R. Ochs 			  struct dk_cxlflash_resize *resize);
1212cb79266SMatthew R. Ochs 
122fcc87e74SMatthew R. Ochs int cxlflash_disk_release(struct scsi_device *sdev,
123fcc87e74SMatthew R. Ochs 			  struct dk_cxlflash_release *release);
124fcc87e74SMatthew R. Ochs int _cxlflash_disk_release(struct scsi_device *sdev, struct ctx_info *ctxi,
125fcc87e74SMatthew R. Ochs 			   struct dk_cxlflash_release *release);
12665be2c79SMatthew R. Ochs 
127fcc87e74SMatthew R. Ochs int cxlflash_disk_clone(struct scsi_device *sdev,
128fcc87e74SMatthew R. Ochs 			struct dk_cxlflash_clone *clone);
1292cb79266SMatthew R. Ochs 
130fcc87e74SMatthew R. Ochs int cxlflash_disk_virtual_open(struct scsi_device *sdev, void *arg);
1312cb79266SMatthew R. Ochs 
132fcc87e74SMatthew R. Ochs int cxlflash_lun_attach(struct glun_info *gli, enum lun_mode mode, bool locked);
133fcc87e74SMatthew R. Ochs void cxlflash_lun_detach(struct glun_info *gli);
13465be2c79SMatthew R. Ochs 
135fcc87e74SMatthew R. Ochs struct ctx_info *get_context(struct cxlflash_cfg *cfg, u64 rctxit, void *arg,
136fcc87e74SMatthew R. Ochs 			     enum ctx_ctrl ctrl);
137fcc87e74SMatthew R. Ochs void put_context(struct ctx_info *ctxi);
13865be2c79SMatthew R. Ochs 
139fcc87e74SMatthew R. Ochs struct sisl_rht_entry *get_rhte(struct ctx_info *ctxi, res_hndl_t rhndl,
140fcc87e74SMatthew R. Ochs 				struct llun_info *lli);
14165be2c79SMatthew R. Ochs 
142fcc87e74SMatthew R. Ochs struct sisl_rht_entry *rhte_checkout(struct ctx_info *ctxi,
143fcc87e74SMatthew R. Ochs 				     struct llun_info *lli);
144fcc87e74SMatthew R. Ochs void rhte_checkin(struct ctx_info *ctxi, struct sisl_rht_entry *rhte);
14565be2c79SMatthew R. Ochs 
146fcc87e74SMatthew R. Ochs void cxlflash_ba_terminate(struct ba_lun *ba_lun);
1472cb79266SMatthew R. Ochs 
148fcc87e74SMatthew R. Ochs int cxlflash_manage_lun(struct scsi_device *sdev,
149fcc87e74SMatthew R. Ochs 			struct dk_cxlflash_manage_lun *manage);
15065be2c79SMatthew R. Ochs 
151fcc87e74SMatthew R. Ochs int check_state(struct cxlflash_cfg *cfg);
152aacb4ff6SMatthew R. Ochs 
15365be2c79SMatthew R. Ochs #endif /* ifndef _CXLFLASH_SUPERPIPE_H */
154