blob: 9e62ff304e4b9778b2dd17c743afad43280bf8b6 [file] [log] [blame]
Matthew R. Ochs65be2c72015-08-13 21:47:43 -05001/*
2 * CXL Flash Device Driver
3 *
4 * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
5 * Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
6 *
7 * Copyright (C) 2015 IBM Corporation
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 */
14
15#ifndef _CXLFLASH_SUPERPIPE_H
16#define _CXLFLASH_SUPERPIPE_H
17
18extern struct cxlflash_global global;
19
20/*
21 * Terminology: use afu (and not adapter) to refer to the HW.
22 * Adapter is the entire slot and includes PSL out of which
23 * only the AFU is visible to user space.
24 */
25
26/* Chunk size parms: note sislite minimum chunk size is
27 0x10000 LBAs corresponding to a NMASK or 16.
28*/
29#define MC_CHUNK_SIZE (1 << MC_RHT_NMASK) /* in LBAs */
30
Manoj Kumar471a5a62015-10-21 15:11:10 -050031#define CMD_TIMEOUT 30 /* 30 secs */
Manoj Kumar3ebf2032015-10-21 15:11:00 -050032#define CMD_RETRIES 5 /* 5 retries for scsi_execute */
33
34#define MAX_SECTOR_UNIT 512 /* max_sector is in 512 byte multiples */
Matthew R. Ochs65be2c72015-08-13 21:47:43 -050035
36#define CHAN2PORT(_x) ((_x) + 1)
Matthew R. Ochs2cb79262015-08-13 21:47:53 -050037#define PORT2CHAN(_x) ((_x) - 1)
Matthew R. Ochs65be2c72015-08-13 21:47:43 -050038
39enum lun_mode {
40 MODE_NONE = 0,
Matthew R. Ochs2cb79262015-08-13 21:47:53 -050041 MODE_VIRTUAL,
Matthew R. Ochs65be2c72015-08-13 21:47:43 -050042 MODE_PHYSICAL
43};
44
45/* Global (entire driver, spans adapters) lun_info structure */
46struct glun_info {
47 u64 max_lba; /* from read cap(16) */
48 u32 blk_len; /* from read cap(16) */
Matthew R. Ochs2cb79262015-08-13 21:47:53 -050049 enum lun_mode mode; /* NONE, VIRTUAL, PHYSICAL */
Matthew R. Ochs65be2c72015-08-13 21:47:43 -050050 int users; /* Number of users w/ references to LUN */
51
52 u8 wwid[16];
53
54 struct mutex mutex;
55
Matthew R. Ochs2cb79262015-08-13 21:47:53 -050056 struct blka blka;
Matthew R. Ochs65be2c72015-08-13 21:47:43 -050057 struct list_head list;
58};
59
60/* Local (per-adapter) lun_info structure */
61struct llun_info {
62 u64 lun_id[CXLFLASH_NUM_FC_PORTS]; /* from REPORT_LUNS */
63 u32 lun_index; /* Index in the LUN table */
64 u32 host_no; /* host_no from Scsi_host */
65 u32 port_sel; /* What port to use for this LUN */
Matthew R. Ochs2cb79262015-08-13 21:47:53 -050066 bool in_table; /* Whether a LUN table entry was created */
Matthew R. Ochs65be2c72015-08-13 21:47:43 -050067
68 u8 wwid[16]; /* Keep a duplicate copy here? */
69
70 struct glun_info *parent; /* Pointer to entry in global LUN structure */
71 struct scsi_device *sdev;
72 struct list_head list;
73};
74
75struct lun_access {
76 struct llun_info *lli;
77 struct scsi_device *sdev;
78 struct list_head list;
79};
80
81enum ctx_ctrl {
82 CTX_CTRL_CLONE = (1 << 1),
83 CTX_CTRL_ERR = (1 << 2),
84 CTX_CTRL_ERR_FALLBACK = (1 << 3),
85 CTX_CTRL_NOPID = (1 << 4),
86 CTX_CTRL_FILE = (1 << 5)
87};
88
Matthew R. Ochsa76df362015-10-21 15:11:43 -050089#define ENCODE_CTXID(_ctx, _id) (((((u64)_ctx) & 0xFFFFFFFF0ULL) << 28) | _id)
Matthew R. Ochs65be2c72015-08-13 21:47:43 -050090#define DECODE_CTXID(_val) (_val & 0xFFFFFFFF)
91
92struct ctx_info {
Matthew R. Ochs1786f4a2015-10-21 15:14:48 -050093 struct sisl_ctrl_map __iomem *ctrl_map; /* initialized at startup */
Matthew R. Ochs65be2c72015-08-13 21:47:43 -050094 struct sisl_rht_entry *rht_start; /* 1 page (req'd for alignment),
95 alloc/free on attach/detach */
96 u32 rht_out; /* Number of checked out RHT entries */
97 u32 rht_perms; /* User-defined permissions for RHT entries */
98 struct llun_info **rht_lun; /* Mapping of RHT entries to LUNs */
Matthew R. Ochse568e232015-10-21 15:11:34 -050099 u8 *rht_needs_ws; /* User-desired write-same function per RHTE */
Matthew R. Ochs65be2c72015-08-13 21:47:43 -0500100
101 struct cxl_ioctl_start_work work;
102 u64 ctxid;
Matthew R. Ochs65be2c72015-08-13 21:47:43 -0500103 pid_t pid;
Matthew R. Ochs5e6632d2016-03-04 15:55:16 -0600104 bool initialized;
Matthew R. Ochs65be2c72015-08-13 21:47:43 -0500105 bool unavail;
106 bool err_recovery_active;
107 struct mutex mutex; /* Context protection */
Matthew R. Ochs888baf02016-08-09 18:39:42 -0500108 struct kref kref;
Matthew R. Ochs65be2c72015-08-13 21:47:43 -0500109 struct cxl_context *ctx;
Matthew R. Ochs44ef38f2016-08-09 18:39:30 -0500110 struct cxlflash_cfg *cfg;
Matthew R. Ochs65be2c72015-08-13 21:47:43 -0500111 struct list_head luns; /* LUNs attached to this context */
112 const struct vm_operations_struct *cxl_mmap_vmops;
113 struct file *file;
114 struct list_head list; /* Link contexts in error recovery */
115};
116
117struct cxlflash_global {
118 struct mutex mutex;
119 struct list_head gluns;/* list of glun_info structs */
120 struct page *err_page; /* One page of all 0xF for error notification */
121};
122
Matthew R. Ochs2cb79262015-08-13 21:47:53 -0500123int cxlflash_vlun_resize(struct scsi_device *, struct dk_cxlflash_resize *);
124int _cxlflash_vlun_resize(struct scsi_device *, struct ctx_info *,
125 struct dk_cxlflash_resize *);
126
Matthew R. Ochs65be2c72015-08-13 21:47:43 -0500127int cxlflash_disk_release(struct scsi_device *, struct dk_cxlflash_release *);
128int _cxlflash_disk_release(struct scsi_device *, struct ctx_info *,
129 struct dk_cxlflash_release *);
130
Matthew R. Ochs2cb79262015-08-13 21:47:53 -0500131int cxlflash_disk_clone(struct scsi_device *, struct dk_cxlflash_clone *);
132
133int cxlflash_disk_virtual_open(struct scsi_device *, void *);
134
Matthew R. Ochs65be2c72015-08-13 21:47:43 -0500135int cxlflash_lun_attach(struct glun_info *, enum lun_mode, bool);
136void cxlflash_lun_detach(struct glun_info *);
137
138struct ctx_info *get_context(struct cxlflash_cfg *, u64, void *, enum ctx_ctrl);
139void put_context(struct ctx_info *);
140
141struct sisl_rht_entry *get_rhte(struct ctx_info *, res_hndl_t,
142 struct llun_info *);
143
144struct sisl_rht_entry *rhte_checkout(struct ctx_info *, struct llun_info *);
145void rhte_checkin(struct ctx_info *, struct sisl_rht_entry *);
146
Matthew R. Ochs2cb79262015-08-13 21:47:53 -0500147void cxlflash_ba_terminate(struct ba_lun *);
148
Matthew R. Ochs65be2c72015-08-13 21:47:43 -0500149int cxlflash_manage_lun(struct scsi_device *, struct dk_cxlflash_manage_lun *);
150
Matthew R. Ochsaacb4ff2015-10-21 15:15:52 -0500151int check_state(struct cxlflash_cfg *);
152
Matthew R. Ochs65be2c72015-08-13 21:47:43 -0500153#endif /* ifndef _CXLFLASH_SUPERPIPE_H */