This source file includes following definitions.
- create_local
- create_global
- lookup_local
- lookup_global
- find_and_create_lun
- cxlflash_term_local_luns
- cxlflash_list_init
- cxlflash_term_global_luns
- cxlflash_manage_lun
1
2
3
4
5
6
7
8
9
10
11 #include <asm/unaligned.h>
12
13 #include <linux/interrupt.h>
14 #include <linux/pci.h>
15
16 #include <scsi/scsi_host.h>
17 #include <uapi/scsi/cxlflash_ioctl.h>
18
19 #include "sislite.h"
20 #include "common.h"
21 #include "vlun.h"
22 #include "superpipe.h"
23
24
25
26
27
28
29
30
31 static struct llun_info *create_local(struct scsi_device *sdev, u8 *wwid)
32 {
33 struct cxlflash_cfg *cfg = shost_priv(sdev->host);
34 struct device *dev = &cfg->dev->dev;
35 struct llun_info *lli = NULL;
36
37 lli = kzalloc(sizeof(*lli), GFP_KERNEL);
38 if (unlikely(!lli)) {
39 dev_err(dev, "%s: could not allocate lli\n", __func__);
40 goto out;
41 }
42
43 lli->sdev = sdev;
44 lli->host_no = sdev->host->host_no;
45 lli->in_table = false;
46
47 memcpy(lli->wwid, wwid, DK_CXLFLASH_MANAGE_LUN_WWID_LEN);
48 out:
49 return lli;
50 }
51
52
53
54
55
56
57
58
59 static struct glun_info *create_global(struct scsi_device *sdev, u8 *wwid)
60 {
61 struct cxlflash_cfg *cfg = shost_priv(sdev->host);
62 struct device *dev = &cfg->dev->dev;
63 struct glun_info *gli = NULL;
64
65 gli = kzalloc(sizeof(*gli), GFP_KERNEL);
66 if (unlikely(!gli)) {
67 dev_err(dev, "%s: could not allocate gli\n", __func__);
68 goto out;
69 }
70
71 mutex_init(&gli->mutex);
72 memcpy(gli->wwid, wwid, DK_CXLFLASH_MANAGE_LUN_WWID_LEN);
73 out:
74 return gli;
75 }
76
77
78
79
80
81
82
83
84 static struct llun_info *lookup_local(struct cxlflash_cfg *cfg, u8 *wwid)
85 {
86 struct llun_info *lli, *temp;
87
88 list_for_each_entry_safe(lli, temp, &cfg->lluns, list)
89 if (!memcmp(lli->wwid, wwid, DK_CXLFLASH_MANAGE_LUN_WWID_LEN))
90 return lli;
91
92 return NULL;
93 }
94
95
96
97
98
99
100
101 static struct glun_info *lookup_global(u8 *wwid)
102 {
103 struct glun_info *gli, *temp;
104
105 list_for_each_entry_safe(gli, temp, &global.gluns, list)
106 if (!memcmp(gli->wwid, wwid, DK_CXLFLASH_MANAGE_LUN_WWID_LEN))
107 return gli;
108
109 return NULL;
110 }
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132 static struct llun_info *find_and_create_lun(struct scsi_device *sdev, u8 *wwid)
133 {
134 struct cxlflash_cfg *cfg = shost_priv(sdev->host);
135 struct device *dev = &cfg->dev->dev;
136 struct llun_info *lli = NULL;
137 struct glun_info *gli = NULL;
138
139 if (unlikely(!wwid))
140 goto out;
141
142 lli = lookup_local(cfg, wwid);
143 if (lli)
144 goto out;
145
146 lli = create_local(sdev, wwid);
147 if (unlikely(!lli))
148 goto out;
149
150 gli = lookup_global(wwid);
151 if (gli) {
152 lli->parent = gli;
153 list_add(&lli->list, &cfg->lluns);
154 goto out;
155 }
156
157 gli = create_global(sdev, wwid);
158 if (unlikely(!gli)) {
159 kfree(lli);
160 lli = NULL;
161 goto out;
162 }
163
164 lli->parent = gli;
165 list_add(&lli->list, &cfg->lluns);
166
167 list_add(&gli->list, &global.gluns);
168
169 out:
170 dev_dbg(dev, "%s: returning lli=%p, gli=%p\n", __func__, lli, gli);
171 return lli;
172 }
173
174
175
176
177
178 void cxlflash_term_local_luns(struct cxlflash_cfg *cfg)
179 {
180 struct llun_info *lli, *temp;
181
182 mutex_lock(&global.mutex);
183 list_for_each_entry_safe(lli, temp, &cfg->lluns, list) {
184 list_del(&lli->list);
185 kfree(lli);
186 }
187 mutex_unlock(&global.mutex);
188 }
189
190
191
192
193 void cxlflash_list_init(void)
194 {
195 INIT_LIST_HEAD(&global.gluns);
196 mutex_init(&global.mutex);
197 global.err_page = NULL;
198 }
199
200
201
202
203 void cxlflash_term_global_luns(void)
204 {
205 struct glun_info *gli, *temp;
206
207 mutex_lock(&global.mutex);
208 list_for_each_entry_safe(gli, temp, &global.gluns, list) {
209 list_del(&gli->list);
210 cxlflash_ba_terminate(&gli->blka.ba_lun);
211 kfree(gli);
212 }
213 mutex_unlock(&global.mutex);
214 }
215
216
217
218
219
220
221
222
223
224
225
226
227 int cxlflash_manage_lun(struct scsi_device *sdev,
228 struct dk_cxlflash_manage_lun *manage)
229 {
230 struct cxlflash_cfg *cfg = shost_priv(sdev->host);
231 struct device *dev = &cfg->dev->dev;
232 struct llun_info *lli = NULL;
233 int rc = 0;
234 u64 flags = manage->hdr.flags;
235 u32 chan = sdev->channel;
236
237 mutex_lock(&global.mutex);
238 lli = find_and_create_lun(sdev, manage->wwid);
239 dev_dbg(dev, "%s: WWID=%016llx%016llx, flags=%016llx lli=%p\n",
240 __func__, get_unaligned_be64(&manage->wwid[0]),
241 get_unaligned_be64(&manage->wwid[8]), manage->hdr.flags, lli);
242 if (unlikely(!lli)) {
243 rc = -ENOMEM;
244 goto out;
245 }
246
247 if (flags & DK_CXLFLASH_MANAGE_LUN_ENABLE_SUPERPIPE) {
248
249
250
251
252
253 lli->port_sel |= CHAN2PORTMASK(chan);
254 lli->lun_id[chan] = lun_to_lunid(sdev->lun);
255 sdev->hostdata = lli;
256 } else if (flags & DK_CXLFLASH_MANAGE_LUN_DISABLE_SUPERPIPE) {
257 if (lli->parent->mode != MODE_NONE)
258 rc = -EBUSY;
259 else {
260
261
262
263
264 sdev->hostdata = NULL;
265 lli->port_sel &= ~CHAN2PORTMASK(chan);
266 if (lli->port_sel == 0U)
267 lli->in_table = false;
268 }
269 }
270
271 dev_dbg(dev, "%s: port_sel=%08x chan=%u lun_id=%016llx\n",
272 __func__, lli->port_sel, chan, lli->lun_id[chan]);
273
274 out:
275 mutex_unlock(&global.mutex);
276 dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc);
277 return rc;
278 }