Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / scsi / cxlflash / superpipe.h
blob0e3b4596406691b23d1d4dc3173eadad1dc10e33
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * CXL Flash Device Driver
5 * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
6 * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
8 * Copyright (C) 2015 IBM Corporation
9 */
11 #ifndef _CXLFLASH_SUPERPIPE_H
12 #define _CXLFLASH_SUPERPIPE_H
14 extern struct cxlflash_global global;
17 * Terminology: use afu (and not adapter) to refer to the HW.
18 * Adapter is the entire slot and includes PSL out of which
19 * only the AFU is visible to user space.
22 /* Chunk size parms: note sislite minimum chunk size is
23 * 0x10000 LBAs corresponding to a NMASK or 16.
25 #define MC_CHUNK_SIZE (1 << MC_RHT_NMASK) /* in LBAs */
27 #define CMD_TIMEOUT 30 /* 30 secs */
28 #define CMD_RETRIES 5 /* 5 retries for scsi_execute */
30 #define MAX_SECTOR_UNIT 512 /* max_sector is in 512 byte multiples */
32 enum lun_mode {
33 MODE_NONE = 0,
34 MODE_VIRTUAL,
35 MODE_PHYSICAL
38 /* Global (entire driver, spans adapters) lun_info structure */
39 struct glun_info {
40 u64 max_lba; /* from read cap(16) */
41 u32 blk_len; /* from read cap(16) */
42 enum lun_mode mode; /* NONE, VIRTUAL, PHYSICAL */
43 int users; /* Number of users w/ references to LUN */
45 u8 wwid[16];
47 struct mutex mutex;
49 struct blka blka;
50 struct list_head list;
53 /* Local (per-adapter) lun_info structure */
54 struct llun_info {
55 u64 lun_id[MAX_FC_PORTS]; /* from REPORT_LUNS */
56 u32 lun_index; /* Index in the LUN table */
57 u32 host_no; /* host_no from Scsi_host */
58 u32 port_sel; /* What port to use for this LUN */
59 bool in_table; /* Whether a LUN table entry was created */
61 u8 wwid[16]; /* Keep a duplicate copy here? */
63 struct glun_info *parent; /* Pointer to entry in global LUN structure */
64 struct scsi_device *sdev;
65 struct list_head list;
68 struct lun_access {
69 struct llun_info *lli;
70 struct scsi_device *sdev;
71 struct list_head list;
74 enum ctx_ctrl {
75 CTX_CTRL_CLONE = (1 << 1),
76 CTX_CTRL_ERR = (1 << 2),
77 CTX_CTRL_ERR_FALLBACK = (1 << 3),
78 CTX_CTRL_NOPID = (1 << 4),
79 CTX_CTRL_FILE = (1 << 5)
82 #define ENCODE_CTXID(_ctx, _id) (((((u64)_ctx) & 0xFFFFFFFF0ULL) << 28) | _id)
83 #define DECODE_CTXID(_val) (_val & 0xFFFFFFFF)
85 struct ctx_info {
86 struct sisl_ctrl_map __iomem *ctrl_map; /* initialized at startup */
87 struct sisl_rht_entry *rht_start; /* 1 page (req'd for alignment),
88 * alloc/free on attach/detach
90 u32 rht_out; /* Number of checked out RHT entries */
91 u32 rht_perms; /* User-defined permissions for RHT entries */
92 struct llun_info **rht_lun; /* Mapping of RHT entries to LUNs */
93 u8 *rht_needs_ws; /* User-desired write-same function per RHTE */
95 u64 ctxid;
96 u64 irqs; /* Number of interrupts requested for context */
97 pid_t pid;
98 bool initialized;
99 bool unavail;
100 bool err_recovery_active;
101 struct mutex mutex; /* Context protection */
102 struct kref kref;
103 void *ctx;
104 struct cxlflash_cfg *cfg;
105 struct list_head luns; /* LUNs attached to this context */
106 const struct vm_operations_struct *cxl_mmap_vmops;
107 struct file *file;
108 struct list_head list; /* Link contexts in error recovery */
111 struct cxlflash_global {
112 struct mutex mutex;
113 struct list_head gluns;/* list of glun_info structs */
114 struct page *err_page; /* One page of all 0xF for error notification */
117 int cxlflash_vlun_resize(struct scsi_device *sdev,
118 struct dk_cxlflash_resize *resize);
119 int _cxlflash_vlun_resize(struct scsi_device *sdev, struct ctx_info *ctxi,
120 struct dk_cxlflash_resize *resize);
122 int cxlflash_disk_release(struct scsi_device *sdev,
123 struct dk_cxlflash_release *release);
124 int _cxlflash_disk_release(struct scsi_device *sdev, struct ctx_info *ctxi,
125 struct dk_cxlflash_release *release);
127 int cxlflash_disk_clone(struct scsi_device *sdev,
128 struct dk_cxlflash_clone *clone);
130 int cxlflash_disk_virtual_open(struct scsi_device *sdev, void *arg);
132 int cxlflash_lun_attach(struct glun_info *gli, enum lun_mode mode, bool locked);
133 void cxlflash_lun_detach(struct glun_info *gli);
135 struct ctx_info *get_context(struct cxlflash_cfg *cfg, u64 rctxit, void *arg,
136 enum ctx_ctrl ctrl);
137 void put_context(struct ctx_info *ctxi);
139 struct sisl_rht_entry *get_rhte(struct ctx_info *ctxi, res_hndl_t rhndl,
140 struct llun_info *lli);
142 struct sisl_rht_entry *rhte_checkout(struct ctx_info *ctxi,
143 struct llun_info *lli);
144 void rhte_checkin(struct ctx_info *ctxi, struct sisl_rht_entry *rhte);
146 void cxlflash_ba_terminate(struct ba_lun *ba_lun);
148 int cxlflash_manage_lun(struct scsi_device *sdev,
149 struct dk_cxlflash_manage_lun *manage);
151 int check_state(struct cxlflash_cfg *cfg);
153 #endif /* ifndef _CXLFLASH_SUPERPIPE_H */