cxlflash: Superpipe support
[firefly-linux-kernel-4.4.55.git] / drivers / scsi / cxlflash / superpipe.h
1 /*
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
18 extern 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
31 #define MC_DISCOVERY_TIMEOUT 5  /* 5 secs */
32
33 #define CHAN2PORT(_x)   ((_x) + 1)
34
35 enum lun_mode {
36         MODE_NONE = 0,
37         MODE_PHYSICAL
38 };
39
40 /* Global (entire driver, spans adapters) lun_info structure */
41 struct glun_info {
42         u64 max_lba;            /* from read cap(16) */
43         u32 blk_len;            /* from read cap(16) */
44         enum lun_mode mode;     /* NONE, PHYSICAL */
45         int users;              /* Number of users w/ references to LUN */
46
47         u8 wwid[16];
48
49         struct mutex mutex;
50
51         struct list_head list;
52 };
53
54 /* Local (per-adapter) lun_info structure */
55 struct llun_info {
56         u64 lun_id[CXLFLASH_NUM_FC_PORTS]; /* from REPORT_LUNS */
57         u32 lun_index;          /* Index in the LUN table */
58         u32 host_no;            /* host_no from Scsi_host */
59         u32 port_sel;           /* What port to use for this LUN */
60         bool newly_created;     /* Whether the LUN was just discovered */
61
62         u8 wwid[16];            /* Keep a duplicate copy here? */
63
64         struct glun_info *parent; /* Pointer to entry in global LUN structure */
65         struct scsi_device *sdev;
66         struct list_head list;
67 };
68
69 struct lun_access {
70         struct llun_info *lli;
71         struct scsi_device *sdev;
72         struct list_head list;
73 };
74
75 enum ctx_ctrl {
76         CTX_CTRL_CLONE          = (1 << 1),
77         CTX_CTRL_ERR            = (1 << 2),
78         CTX_CTRL_ERR_FALLBACK   = (1 << 3),
79         CTX_CTRL_NOPID          = (1 << 4),
80         CTX_CTRL_FILE           = (1 << 5)
81 };
82
83 #define ENCODE_CTXID(_ctx, _id) (((((u64)_ctx) & 0xFFFFFFFF0) << 28) | _id)
84 #define DECODE_CTXID(_val)      (_val & 0xFFFFFFFF)
85
86 struct ctx_info {
87         struct sisl_ctrl_map *ctrl_map; /* initialized at startup */
88         struct sisl_rht_entry *rht_start; /* 1 page (req'd for alignment),
89                                              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
94         struct cxl_ioctl_start_work work;
95         u64 ctxid;
96         int lfd;
97         pid_t pid;
98         bool unavail;
99         bool err_recovery_active;
100         struct mutex mutex; /* Context protection */
101         struct cxl_context *ctx;
102         struct list_head luns;  /* LUNs attached to this context */
103         const struct vm_operations_struct *cxl_mmap_vmops;
104         struct file *file;
105         struct list_head list; /* Link contexts in error recovery */
106 };
107
108 struct cxlflash_global {
109         struct mutex mutex;
110         struct list_head gluns;/* list of glun_info structs */
111         struct page *err_page; /* One page of all 0xF for error notification */
112 };
113
114 int cxlflash_disk_release(struct scsi_device *, struct dk_cxlflash_release *);
115 int _cxlflash_disk_release(struct scsi_device *, struct ctx_info *,
116                            struct dk_cxlflash_release *);
117
118 int cxlflash_lun_attach(struct glun_info *, enum lun_mode, bool);
119 void cxlflash_lun_detach(struct glun_info *);
120
121 struct ctx_info *get_context(struct cxlflash_cfg *, u64, void *, enum ctx_ctrl);
122 void put_context(struct ctx_info *);
123
124 struct sisl_rht_entry *get_rhte(struct ctx_info *, res_hndl_t,
125                                 struct llun_info *);
126
127 struct sisl_rht_entry *rhte_checkout(struct ctx_info *, struct llun_info *);
128 void rhte_checkin(struct ctx_info *, struct sisl_rht_entry *);
129
130 int cxlflash_manage_lun(struct scsi_device *, struct dk_cxlflash_manage_lun *);
131
132 #endif /* ifndef _CXLFLASH_SUPERPIPE_H */