xref: /openbmc/linux/drivers/scsi/cxlflash/superpipe.h (revision 78ae028e823701148e4915759459ee79597ea8ec)
165be2c79SMatthew R. Ochs /*
265be2c79SMatthew R. Ochs  * CXL Flash Device Driver
365be2c79SMatthew R. Ochs  *
465be2c79SMatthew R. Ochs  * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
565be2c79SMatthew R. Ochs  *             Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
665be2c79SMatthew R. Ochs  *
765be2c79SMatthew R. Ochs  * Copyright (C) 2015 IBM Corporation
865be2c79SMatthew R. Ochs  *
965be2c79SMatthew R. Ochs  * This program is free software; you can redistribute it and/or
1065be2c79SMatthew R. Ochs  * modify it under the terms of the GNU General Public License
1165be2c79SMatthew R. Ochs  * as published by the Free Software Foundation; either version
1265be2c79SMatthew R. Ochs  * 2 of the License, or (at your option) any later version.
1365be2c79SMatthew R. Ochs  */
1465be2c79SMatthew R. Ochs 
1565be2c79SMatthew R. Ochs #ifndef _CXLFLASH_SUPERPIPE_H
1665be2c79SMatthew R. Ochs #define _CXLFLASH_SUPERPIPE_H
1765be2c79SMatthew R. Ochs 
1865be2c79SMatthew R. Ochs extern struct cxlflash_global global;
1965be2c79SMatthew R. Ochs 
2065be2c79SMatthew R. Ochs /*
2165be2c79SMatthew R. Ochs  * Terminology: use afu (and not adapter) to refer to the HW.
2265be2c79SMatthew R. Ochs  * Adapter is the entire slot and includes PSL out of which
2365be2c79SMatthew R. Ochs  * only the AFU is visible to user space.
2465be2c79SMatthew R. Ochs  */
2565be2c79SMatthew R. Ochs 
2665be2c79SMatthew R. Ochs /* Chunk size parms: note sislite minimum chunk size is
2765be2c79SMatthew R. Ochs    0x10000 LBAs corresponding to a NMASK or 16.
2865be2c79SMatthew R. Ochs */
2965be2c79SMatthew R. Ochs #define MC_CHUNK_SIZE     (1 << MC_RHT_NMASK)	/* in LBAs */
3065be2c79SMatthew R. Ochs 
31471a5a60SManoj Kumar #define CMD_TIMEOUT 30  /* 30 secs */
323ebf2030SManoj Kumar #define CMD_RETRIES 5   /* 5 retries for scsi_execute */
333ebf2030SManoj Kumar 
343ebf2030SManoj Kumar #define MAX_SECTOR_UNIT  512 /* max_sector is in 512 byte multiples */
3565be2c79SMatthew R. Ochs 
3665be2c79SMatthew R. Ochs #define CHAN2PORT(_x)	((_x) + 1)
372cb79266SMatthew R. Ochs #define PORT2CHAN(_x)	((_x) - 1)
3865be2c79SMatthew R. Ochs 
3965be2c79SMatthew R. Ochs enum lun_mode {
4065be2c79SMatthew R. Ochs 	MODE_NONE = 0,
412cb79266SMatthew R. Ochs 	MODE_VIRTUAL,
4265be2c79SMatthew R. Ochs 	MODE_PHYSICAL
4365be2c79SMatthew R. Ochs };
4465be2c79SMatthew R. Ochs 
4565be2c79SMatthew R. Ochs /* Global (entire driver, spans adapters) lun_info structure */
4665be2c79SMatthew R. Ochs struct glun_info {
4765be2c79SMatthew R. Ochs 	u64 max_lba;		/* from read cap(16) */
4865be2c79SMatthew R. Ochs 	u32 blk_len;		/* from read cap(16) */
492cb79266SMatthew R. Ochs 	enum lun_mode mode;	/* NONE, VIRTUAL, PHYSICAL */
5065be2c79SMatthew R. Ochs 	int users;		/* Number of users w/ references to LUN */
5165be2c79SMatthew R. Ochs 
5265be2c79SMatthew R. Ochs 	u8 wwid[16];
5365be2c79SMatthew R. Ochs 
5465be2c79SMatthew R. Ochs 	struct mutex mutex;
5565be2c79SMatthew R. Ochs 
562cb79266SMatthew R. Ochs 	struct blka blka;
5765be2c79SMatthew R. Ochs 	struct list_head list;
5865be2c79SMatthew R. Ochs };
5965be2c79SMatthew R. Ochs 
6065be2c79SMatthew R. Ochs /* Local (per-adapter) lun_info structure */
6165be2c79SMatthew R. Ochs struct llun_info {
62*78ae028eSMatthew R. Ochs 	u64 lun_id[MAX_FC_PORTS]; /* from REPORT_LUNS */
6365be2c79SMatthew R. Ochs 	u32 lun_index;		/* Index in the LUN table */
6465be2c79SMatthew R. Ochs 	u32 host_no;		/* host_no from Scsi_host */
6565be2c79SMatthew R. Ochs 	u32 port_sel;		/* What port to use for this LUN */
662cb79266SMatthew R. Ochs 	bool in_table;		/* Whether a LUN table entry was created */
6765be2c79SMatthew R. Ochs 
6865be2c79SMatthew R. Ochs 	u8 wwid[16];		/* Keep a duplicate copy here? */
6965be2c79SMatthew R. Ochs 
7065be2c79SMatthew R. Ochs 	struct glun_info *parent; /* Pointer to entry in global LUN structure */
7165be2c79SMatthew R. Ochs 	struct scsi_device *sdev;
7265be2c79SMatthew R. Ochs 	struct list_head list;
7365be2c79SMatthew R. Ochs };
7465be2c79SMatthew R. Ochs 
7565be2c79SMatthew R. Ochs struct lun_access {
7665be2c79SMatthew R. Ochs 	struct llun_info *lli;
7765be2c79SMatthew R. Ochs 	struct scsi_device *sdev;
7865be2c79SMatthew R. Ochs 	struct list_head list;
7965be2c79SMatthew R. Ochs };
8065be2c79SMatthew R. Ochs 
8165be2c79SMatthew R. Ochs enum ctx_ctrl {
8265be2c79SMatthew R. Ochs 	CTX_CTRL_CLONE		= (1 << 1),
8365be2c79SMatthew R. Ochs 	CTX_CTRL_ERR		= (1 << 2),
8465be2c79SMatthew R. Ochs 	CTX_CTRL_ERR_FALLBACK	= (1 << 3),
8565be2c79SMatthew R. Ochs 	CTX_CTRL_NOPID		= (1 << 4),
8665be2c79SMatthew R. Ochs 	CTX_CTRL_FILE		= (1 << 5)
8765be2c79SMatthew R. Ochs };
8865be2c79SMatthew R. Ochs 
89a76df368SMatthew R. Ochs #define ENCODE_CTXID(_ctx, _id)	(((((u64)_ctx) & 0xFFFFFFFF0ULL) << 28) | _id)
9065be2c79SMatthew R. Ochs #define DECODE_CTXID(_val)	(_val & 0xFFFFFFFF)
9165be2c79SMatthew R. Ochs 
9265be2c79SMatthew R. Ochs struct ctx_info {
931786f4a0SMatthew R. Ochs 	struct sisl_ctrl_map __iomem *ctrl_map; /* initialized at startup */
9465be2c79SMatthew R. Ochs 	struct sisl_rht_entry *rht_start; /* 1 page (req'd for alignment),
9565be2c79SMatthew R. Ochs 					     alloc/free on attach/detach */
9665be2c79SMatthew R. Ochs 	u32 rht_out;		/* Number of checked out RHT entries */
9765be2c79SMatthew R. Ochs 	u32 rht_perms;		/* User-defined permissions for RHT entries */
9865be2c79SMatthew R. Ochs 	struct llun_info **rht_lun;       /* Mapping of RHT entries to LUNs */
99e568e23fSMatthew R. Ochs 	u8 *rht_needs_ws;	/* User-desired write-same function per RHTE */
10065be2c79SMatthew R. Ochs 
10165be2c79SMatthew R. Ochs 	struct cxl_ioctl_start_work work;
10265be2c79SMatthew R. Ochs 	u64 ctxid;
10365be2c79SMatthew R. Ochs 	pid_t pid;
1045e6632d1SMatthew R. Ochs 	bool initialized;
10565be2c79SMatthew R. Ochs 	bool unavail;
10665be2c79SMatthew R. Ochs 	bool err_recovery_active;
10765be2c79SMatthew R. Ochs 	struct mutex mutex; /* Context protection */
108888baf06SMatthew R. Ochs 	struct kref kref;
10965be2c79SMatthew R. Ochs 	struct cxl_context *ctx;
11044ef38f9SMatthew R. Ochs 	struct cxlflash_cfg *cfg;
11165be2c79SMatthew R. Ochs 	struct list_head luns;	/* LUNs attached to this context */
11265be2c79SMatthew R. Ochs 	const struct vm_operations_struct *cxl_mmap_vmops;
11365be2c79SMatthew R. Ochs 	struct file *file;
11465be2c79SMatthew R. Ochs 	struct list_head list; /* Link contexts in error recovery */
11565be2c79SMatthew R. Ochs };
11665be2c79SMatthew R. Ochs 
11765be2c79SMatthew R. Ochs struct cxlflash_global {
11865be2c79SMatthew R. Ochs 	struct mutex mutex;
11965be2c79SMatthew R. Ochs 	struct list_head gluns;/* list of glun_info structs */
12065be2c79SMatthew R. Ochs 	struct page *err_page; /* One page of all 0xF for error notification */
12165be2c79SMatthew R. Ochs };
12265be2c79SMatthew R. Ochs 
1232cb79266SMatthew R. Ochs int cxlflash_vlun_resize(struct scsi_device *, struct dk_cxlflash_resize *);
1242cb79266SMatthew R. Ochs int _cxlflash_vlun_resize(struct scsi_device *, struct ctx_info *,
1252cb79266SMatthew R. Ochs 			  struct dk_cxlflash_resize *);
1262cb79266SMatthew R. Ochs 
12765be2c79SMatthew R. Ochs int cxlflash_disk_release(struct scsi_device *, struct dk_cxlflash_release *);
12865be2c79SMatthew R. Ochs int _cxlflash_disk_release(struct scsi_device *, struct ctx_info *,
12965be2c79SMatthew R. Ochs 			   struct dk_cxlflash_release *);
13065be2c79SMatthew R. Ochs 
1312cb79266SMatthew R. Ochs int cxlflash_disk_clone(struct scsi_device *, struct dk_cxlflash_clone *);
1322cb79266SMatthew R. Ochs 
1332cb79266SMatthew R. Ochs int cxlflash_disk_virtual_open(struct scsi_device *, void *);
1342cb79266SMatthew R. Ochs 
13565be2c79SMatthew R. Ochs int cxlflash_lun_attach(struct glun_info *, enum lun_mode, bool);
13665be2c79SMatthew R. Ochs void cxlflash_lun_detach(struct glun_info *);
13765be2c79SMatthew R. Ochs 
13865be2c79SMatthew R. Ochs struct ctx_info *get_context(struct cxlflash_cfg *, u64, void *, enum ctx_ctrl);
13965be2c79SMatthew R. Ochs void put_context(struct ctx_info *);
14065be2c79SMatthew R. Ochs 
14165be2c79SMatthew R. Ochs struct sisl_rht_entry *get_rhte(struct ctx_info *, res_hndl_t,
14265be2c79SMatthew R. Ochs 				struct llun_info *);
14365be2c79SMatthew R. Ochs 
14465be2c79SMatthew R. Ochs struct sisl_rht_entry *rhte_checkout(struct ctx_info *, struct llun_info *);
14565be2c79SMatthew R. Ochs void rhte_checkin(struct ctx_info *, struct sisl_rht_entry *);
14665be2c79SMatthew R. Ochs 
1472cb79266SMatthew R. Ochs void cxlflash_ba_terminate(struct ba_lun *);
1482cb79266SMatthew R. Ochs 
14965be2c79SMatthew R. Ochs int cxlflash_manage_lun(struct scsi_device *, struct dk_cxlflash_manage_lun *);
15065be2c79SMatthew R. Ochs 
151aacb4ff6SMatthew R. Ochs int check_state(struct cxlflash_cfg *);
152aacb4ff6SMatthew R. Ochs 
15365be2c79SMatthew R. Ochs #endif /* ifndef _CXLFLASH_SUPERPIPE_H */
154