]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - drivers/scsi/cxlflash/sislite.h
Merge tag 'iio-fixes-for-4.10a' of git://git.kernel.org/pub/scm/linux/kernel/git...
[mirror_ubuntu-zesty-kernel.git] / drivers / scsi / cxlflash / sislite.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 _SISLITE_H
16 #define _SISLITE_H
17
18 #include <linux/types.h>
19
20 typedef u16 ctx_hndl_t;
21 typedef u32 res_hndl_t;
22
23 #define SIZE_4K 4096
24 #define SIZE_64K 65536
25
26 /*
27 * IOARCB: 64 bytes, min 16 byte alignment required, host native endianness
28 * except for SCSI CDB which remains big endian per SCSI standards.
29 */
30 struct sisl_ioarcb {
31 u16 ctx_id; /* ctx_hndl_t */
32 u16 req_flags;
33 #define SISL_REQ_FLAGS_RES_HNDL 0x8000U /* bit 0 (MSB) */
34 #define SISL_REQ_FLAGS_PORT_LUN_ID 0x0000U
35
36 #define SISL_REQ_FLAGS_SUP_UNDERRUN 0x4000U /* bit 1 */
37
38 #define SISL_REQ_FLAGS_TIMEOUT_SECS 0x0000U /* bits 8,9 */
39 #define SISL_REQ_FLAGS_TIMEOUT_MSECS 0x0040U
40 #define SISL_REQ_FLAGS_TIMEOUT_USECS 0x0080U
41 #define SISL_REQ_FLAGS_TIMEOUT_CYCLES 0x00C0U
42
43 #define SISL_REQ_FLAGS_TMF_CMD 0x0004u /* bit 13 */
44
45 #define SISL_REQ_FLAGS_AFU_CMD 0x0002U /* bit 14 */
46
47 #define SISL_REQ_FLAGS_HOST_WRITE 0x0001U /* bit 15 (LSB) */
48 #define SISL_REQ_FLAGS_HOST_READ 0x0000U
49
50 union {
51 u32 res_hndl; /* res_hndl_t */
52 u32 port_sel; /* this is a selection mask:
53 * 0x1 -> port#0 can be selected,
54 * 0x2 -> port#1 can be selected.
55 * Can be bitwise ORed.
56 */
57 };
58 u64 lun_id;
59 u32 data_len; /* 4K for read/write */
60 u32 ioadl_len;
61 union {
62 u64 data_ea; /* min 16 byte aligned */
63 u64 ioadl_ea;
64 };
65 u8 msi; /* LISN to send on RRQ write */
66 #define SISL_MSI_CXL_PFAULT 0 /* reserved for CXL page faults */
67 #define SISL_MSI_SYNC_ERROR 1 /* recommended for AFU sync error */
68 #define SISL_MSI_RRQ_UPDATED 2 /* recommended for IO completion */
69 #define SISL_MSI_ASYNC_ERROR 3 /* master only - for AFU async error */
70
71 u8 rrq; /* 0 for a single RRQ */
72 u16 timeout; /* in units specified by req_flags */
73 u32 rsvd1;
74 u8 cdb[16]; /* must be in big endian */
75 u64 reserved; /* Reserved area */
76 } __packed;
77
78 struct sisl_rc {
79 u8 flags;
80 #define SISL_RC_FLAGS_SENSE_VALID 0x80U
81 #define SISL_RC_FLAGS_FCP_RSP_CODE_VALID 0x40U
82 #define SISL_RC_FLAGS_OVERRUN 0x20U
83 #define SISL_RC_FLAGS_UNDERRUN 0x10U
84
85 u8 afu_rc;
86 #define SISL_AFU_RC_RHT_INVALID 0x01U /* user error */
87 #define SISL_AFU_RC_RHT_UNALIGNED 0x02U /* should never happen */
88 #define SISL_AFU_RC_RHT_OUT_OF_BOUNDS 0x03u /* user error */
89 #define SISL_AFU_RC_RHT_DMA_ERR 0x04u /* see afu_extra
90 may retry if afu_retry is off
91 possible on master exit
92 */
93 #define SISL_AFU_RC_RHT_RW_PERM 0x05u /* no RW perms, user error */
94 #define SISL_AFU_RC_LXT_UNALIGNED 0x12U /* should never happen */
95 #define SISL_AFU_RC_LXT_OUT_OF_BOUNDS 0x13u /* user error */
96 #define SISL_AFU_RC_LXT_DMA_ERR 0x14u /* see afu_extra
97 may retry if afu_retry is off
98 possible on master exit
99 */
100 #define SISL_AFU_RC_LXT_RW_PERM 0x15u /* no RW perms, user error */
101
102 #define SISL_AFU_RC_NOT_XLATE_HOST 0x1au /* possible if master exited */
103
104 /* NO_CHANNELS means the FC ports selected by dest_port in
105 * IOARCB or in the LXT entry are down when the AFU tried to select
106 * a FC port. If the port went down on an active IO, it will set
107 * fc_rc to =0x54(NOLOGI) or 0x57(LINKDOWN) instead.
108 */
109 #define SISL_AFU_RC_NO_CHANNELS 0x20U /* see afu_extra, may retry */
110 #define SISL_AFU_RC_CAP_VIOLATION 0x21U /* either user error or
111 afu reset/master restart
112 */
113 #define SISL_AFU_RC_OUT_OF_DATA_BUFS 0x30U /* always retry */
114 #define SISL_AFU_RC_DATA_DMA_ERR 0x31U /* see afu_extra
115 may retry if afu_retry is off
116 */
117
118 u8 scsi_rc; /* SCSI status byte, retry as appropriate */
119 #define SISL_SCSI_RC_CHECK 0x02U
120 #define SISL_SCSI_RC_BUSY 0x08u
121
122 u8 fc_rc; /* retry */
123 /*
124 * We should only see fc_rc=0x57 (LINKDOWN) or 0x54(NOLOGI) for
125 * commands that are in flight when a link goes down or is logged out.
126 * If the link is down or logged out before AFU selects the port, either
127 * it will choose the other port or we will get afu_rc=0x20 (no_channel)
128 * if there is no valid port to use.
129 *
130 * ABORTPEND/ABORTOK/ABORTFAIL/TGTABORT can be retried, typically these
131 * would happen if a frame is dropped and something times out.
132 * NOLOGI or LINKDOWN can be retried if the other port is up.
133 * RESIDERR can be retried as well.
134 *
135 * ABORTFAIL might indicate that lots of frames are getting CRC errors.
136 * So it maybe retried once and reset the link if it happens again.
137 * The link can also be reset on the CRC error threshold interrupt.
138 */
139 #define SISL_FC_RC_ABORTPEND 0x52 /* exchange timeout or abort request */
140 #define SISL_FC_RC_WRABORTPEND 0x53 /* due to write XFER_RDY invalid */
141 #define SISL_FC_RC_NOLOGI 0x54 /* port not logged in, in-flight cmds */
142 #define SISL_FC_RC_NOEXP 0x55 /* FC protocol error or HW bug */
143 #define SISL_FC_RC_INUSE 0x56 /* tag already in use, HW bug */
144 #define SISL_FC_RC_LINKDOWN 0x57 /* link down, in-flight cmds */
145 #define SISL_FC_RC_ABORTOK 0x58 /* pending abort completed w/success */
146 #define SISL_FC_RC_ABORTFAIL 0x59 /* pending abort completed w/fail */
147 #define SISL_FC_RC_RESID 0x5A /* ioasa underrun/overrun flags set */
148 #define SISL_FC_RC_RESIDERR 0x5B /* actual data len does not match SCSI
149 reported len, possibly due to dropped
150 frames */
151 #define SISL_FC_RC_TGTABORT 0x5C /* command aborted by target */
152 };
153
154 #define SISL_SENSE_DATA_LEN 20 /* Sense data length */
155
156 /*
157 * IOASA: 64 bytes & must follow IOARCB, min 16 byte alignment required,
158 * host native endianness
159 */
160 struct sisl_ioasa {
161 union {
162 struct sisl_rc rc;
163 u32 ioasc;
164 #define SISL_IOASC_GOOD_COMPLETION 0x00000000U
165 };
166 u32 resid;
167 u8 port;
168 u8 afu_extra;
169 /* when afu_rc=0x04, 0x14, 0x31 (_xxx_DMA_ERR):
170 * afu_exta contains PSL response code. Useful codes are:
171 */
172 #define SISL_AFU_DMA_ERR_PAGE_IN 0x0A /* AFU_retry_on_pagein Action
173 * Enabled N/A
174 * Disabled retry
175 */
176 #define SISL_AFU_DMA_ERR_INVALID_EA 0x0B /* this is a hard error
177 * afu_rc Implies
178 * 0x04, 0x14 master exit.
179 * 0x31 user error.
180 */
181 /* when afu rc=0x20 (no channels):
182 * afu_extra bits [4:5]: available portmask, [6:7]: requested portmask.
183 */
184 #define SISL_AFU_NO_CLANNELS_AMASK(afu_extra) (((afu_extra) & 0x0C) >> 2)
185 #define SISL_AFU_NO_CLANNELS_RMASK(afu_extra) ((afu_extra) & 0x03)
186
187 u8 scsi_extra;
188 u8 fc_extra;
189 u8 sense_data[SISL_SENSE_DATA_LEN];
190
191 /* These fields are defined by the SISlite architecture for the
192 * host to use as they see fit for their implementation.
193 */
194 union {
195 u64 host_use[4];
196 u8 host_use_b[32];
197 };
198 } __packed;
199
200 #define SISL_RESP_HANDLE_T_BIT 0x1ULL /* Toggle bit */
201
202 /* MMIO space is required to support only 64-bit access */
203
204 /*
205 * This AFU has two mechanisms to deal with endian-ness.
206 * One is a global configuration (in the afu_config) register
207 * below that specifies the endian-ness of the host.
208 * The other is a per context (i.e. application) specification
209 * controlled by the endian_ctrl field here. Since the master
210 * context is one such application the master context's
211 * endian-ness is set to be the same as the host.
212 *
213 * As per the SISlite spec, the MMIO registers are always
214 * big endian.
215 */
216 #define SISL_ENDIAN_CTRL_BE 0x8000000000000080ULL
217 #define SISL_ENDIAN_CTRL_LE 0x0000000000000000ULL
218
219 #ifdef __BIG_ENDIAN
220 #define SISL_ENDIAN_CTRL SISL_ENDIAN_CTRL_BE
221 #else
222 #define SISL_ENDIAN_CTRL SISL_ENDIAN_CTRL_LE
223 #endif
224
225 /* per context host transport MMIO */
226 struct sisl_host_map {
227 __be64 endian_ctrl; /* Per context Endian Control. The AFU will
228 * operate on whatever the context is of the
229 * host application.
230 */
231
232 __be64 intr_status; /* this sends LISN# programmed in ctx_ctrl.
233 * Only recovery in a PERM_ERR is a context
234 * exit since there is no way to tell which
235 * command caused the error.
236 */
237 #define SISL_ISTATUS_PERM_ERR_CMDROOM 0x0010ULL /* b59, user error */
238 #define SISL_ISTATUS_PERM_ERR_RCB_READ 0x0008ULL /* b60, user error */
239 #define SISL_ISTATUS_PERM_ERR_SA_WRITE 0x0004ULL /* b61, user error */
240 #define SISL_ISTATUS_PERM_ERR_RRQ_WRITE 0x0002ULL /* b62, user error */
241 /* Page in wait accessing RCB/IOASA/RRQ is reported in b63.
242 * Same error in data/LXT/RHT access is reported via IOASA.
243 */
244 #define SISL_ISTATUS_TEMP_ERR_PAGEIN 0x0001ULL /* b63, can be generated
245 * only when AFU auto
246 * retry is disabled.
247 * If user can determine
248 * the command that
249 * caused the error, it
250 * can be retried.
251 */
252 #define SISL_ISTATUS_UNMASK (0x001FULL) /* 1 means unmasked */
253 #define SISL_ISTATUS_MASK ~(SISL_ISTATUS_UNMASK) /* 1 means masked */
254
255 __be64 intr_clear;
256 __be64 intr_mask;
257 __be64 ioarrin; /* only write what cmd_room permits */
258 __be64 rrq_start; /* start & end are both inclusive */
259 __be64 rrq_end; /* write sequence: start followed by end */
260 __be64 cmd_room;
261 __be64 ctx_ctrl; /* least significant byte or b56:63 is LISN# */
262 __be64 mbox_w; /* restricted use */
263 };
264
265 /* per context provisioning & control MMIO */
266 struct sisl_ctrl_map {
267 __be64 rht_start;
268 __be64 rht_cnt_id;
269 /* both cnt & ctx_id args must be ULL */
270 #define SISL_RHT_CNT_ID(cnt, ctx_id) (((cnt) << 48) | ((ctx_id) << 32))
271
272 __be64 ctx_cap; /* afu_rc below is when the capability is violated */
273 #define SISL_CTX_CAP_PROXY_ISSUE 0x8000000000000000ULL /* afu_rc 0x21 */
274 #define SISL_CTX_CAP_REAL_MODE 0x4000000000000000ULL /* afu_rc 0x21 */
275 #define SISL_CTX_CAP_HOST_XLATE 0x2000000000000000ULL /* afu_rc 0x1a */
276 #define SISL_CTX_CAP_PROXY_TARGET 0x1000000000000000ULL /* afu_rc 0x21 */
277 #define SISL_CTX_CAP_AFU_CMD 0x0000000000000008ULL /* afu_rc 0x21 */
278 #define SISL_CTX_CAP_GSCSI_CMD 0x0000000000000004ULL /* afu_rc 0x21 */
279 #define SISL_CTX_CAP_WRITE_CMD 0x0000000000000002ULL /* afu_rc 0x21 */
280 #define SISL_CTX_CAP_READ_CMD 0x0000000000000001ULL /* afu_rc 0x21 */
281 __be64 mbox_r;
282 };
283
284 /* single copy global regs */
285 struct sisl_global_regs {
286 __be64 aintr_status;
287 /* In cxlflash, each FC port/link gets a byte of status */
288 #define SISL_ASTATUS_FC0_OTHER 0x8000ULL /* b48, other err,
289 FC_ERRCAP[31:20] */
290 #define SISL_ASTATUS_FC0_LOGO 0x4000ULL /* b49, target sent FLOGI/PLOGI/LOGO
291 while logged in */
292 #define SISL_ASTATUS_FC0_CRC_T 0x2000ULL /* b50, CRC threshold exceeded */
293 #define SISL_ASTATUS_FC0_LOGI_R 0x1000ULL /* b51, login state machine timed out
294 and retrying */
295 #define SISL_ASTATUS_FC0_LOGI_F 0x0800ULL /* b52, login failed,
296 FC_ERROR[19:0] */
297 #define SISL_ASTATUS_FC0_LOGI_S 0x0400ULL /* b53, login succeeded */
298 #define SISL_ASTATUS_FC0_LINK_DN 0x0200ULL /* b54, link online to offline */
299 #define SISL_ASTATUS_FC0_LINK_UP 0x0100ULL /* b55, link offline to online */
300
301 #define SISL_ASTATUS_FC1_OTHER 0x0080ULL /* b56 */
302 #define SISL_ASTATUS_FC1_LOGO 0x0040ULL /* b57 */
303 #define SISL_ASTATUS_FC1_CRC_T 0x0020ULL /* b58 */
304 #define SISL_ASTATUS_FC1_LOGI_R 0x0010ULL /* b59 */
305 #define SISL_ASTATUS_FC1_LOGI_F 0x0008ULL /* b60 */
306 #define SISL_ASTATUS_FC1_LOGI_S 0x0004ULL /* b61 */
307 #define SISL_ASTATUS_FC1_LINK_DN 0x0002ULL /* b62 */
308 #define SISL_ASTATUS_FC1_LINK_UP 0x0001ULL /* b63 */
309
310 #define SISL_FC_INTERNAL_UNMASK 0x0000000300000000ULL /* 1 means unmasked */
311 #define SISL_FC_INTERNAL_MASK ~(SISL_FC_INTERNAL_UNMASK)
312 #define SISL_FC_INTERNAL_SHIFT 32
313
314 #define SISL_FC_SHUTDOWN_NORMAL 0x0000000000000010ULL
315 #define SISL_FC_SHUTDOWN_ABRUPT 0x0000000000000020ULL
316
317 #define SISL_STATUS_SHUTDOWN_ACTIVE 0x0000000000000010ULL
318 #define SISL_STATUS_SHUTDOWN_COMPLETE 0x0000000000000020ULL
319
320 #define SISL_ASTATUS_UNMASK 0xFFFFULL /* 1 means unmasked */
321 #define SISL_ASTATUS_MASK ~(SISL_ASTATUS_UNMASK) /* 1 means masked */
322
323 __be64 aintr_clear;
324 __be64 aintr_mask;
325 __be64 afu_ctrl;
326 __be64 afu_hb;
327 __be64 afu_scratch_pad;
328 __be64 afu_port_sel;
329 #define SISL_AFUCONF_AR_IOARCB 0x4000ULL
330 #define SISL_AFUCONF_AR_LXT 0x2000ULL
331 #define SISL_AFUCONF_AR_RHT 0x1000ULL
332 #define SISL_AFUCONF_AR_DATA 0x0800ULL
333 #define SISL_AFUCONF_AR_RSRC 0x0400ULL
334 #define SISL_AFUCONF_AR_IOASA 0x0200ULL
335 #define SISL_AFUCONF_AR_RRQ 0x0100ULL
336 /* Aggregate all Auto Retry Bits */
337 #define SISL_AFUCONF_AR_ALL (SISL_AFUCONF_AR_IOARCB|SISL_AFUCONF_AR_LXT| \
338 SISL_AFUCONF_AR_RHT|SISL_AFUCONF_AR_DATA| \
339 SISL_AFUCONF_AR_RSRC|SISL_AFUCONF_AR_IOASA| \
340 SISL_AFUCONF_AR_RRQ)
341 #ifdef __BIG_ENDIAN
342 #define SISL_AFUCONF_ENDIAN 0x0000ULL
343 #else
344 #define SISL_AFUCONF_ENDIAN 0x0020ULL
345 #endif
346 #define SISL_AFUCONF_MBOX_CLR_READ 0x0010ULL
347 __be64 afu_config;
348 __be64 rsvd[0xf8];
349 __le64 afu_version;
350 __be64 interface_version;
351 };
352
353 #define CXLFLASH_NUM_FC_PORTS 2
354 #define CXLFLASH_MAX_CONTEXT 512 /* how many contexts per afu */
355 #define CXLFLASH_NUM_VLUNS 512
356
357 struct sisl_global_map {
358 union {
359 struct sisl_global_regs regs;
360 char page0[SIZE_4K]; /* page 0 */
361 };
362
363 char page1[SIZE_4K]; /* page 1 */
364
365 /* pages 2 & 3 */
366 __be64 fc_regs[CXLFLASH_NUM_FC_PORTS][CXLFLASH_NUM_VLUNS];
367
368 /* pages 4 & 5 (lun tbl) */
369 __be64 fc_port[CXLFLASH_NUM_FC_PORTS][CXLFLASH_NUM_VLUNS];
370
371 };
372
373 /*
374 * CXL Flash Memory Map
375 *
376 * +-------------------------------+
377 * | 512 * 64 KB User MMIO |
378 * | (per context) |
379 * | User Accessible |
380 * +-------------------------------+
381 * | 512 * 128 B per context |
382 * | Provisioning and Control |
383 * | Trusted Process accessible |
384 * +-------------------------------+
385 * | 64 KB Global |
386 * | Trusted Process accessible |
387 * +-------------------------------+
388 */
389 struct cxlflash_afu_map {
390 union {
391 struct sisl_host_map host;
392 char harea[SIZE_64K]; /* 64KB each */
393 } hosts[CXLFLASH_MAX_CONTEXT];
394
395 union {
396 struct sisl_ctrl_map ctrl;
397 char carea[cache_line_size()]; /* 128B each */
398 } ctrls[CXLFLASH_MAX_CONTEXT];
399
400 union {
401 struct sisl_global_map global;
402 char garea[SIZE_64K]; /* 64KB single block */
403 };
404 };
405
406 /*
407 * LXT - LBA Translation Table
408 * LXT control blocks
409 */
410 struct sisl_lxt_entry {
411 u64 rlba_base; /* bits 0:47 is base
412 * b48:55 is lun index
413 * b58:59 is write & read perms
414 * (if no perm, afu_rc=0x15)
415 * b60:63 is port_sel mask
416 */
417 };
418
419 /*
420 * RHT - Resource Handle Table
421 * Per the SISlite spec, RHT entries are to be 16-byte aligned
422 */
423 struct sisl_rht_entry {
424 struct sisl_lxt_entry *lxt_start;
425 u32 lxt_cnt;
426 u16 rsvd;
427 u8 fp; /* format & perm nibbles.
428 * (if no perm, afu_rc=0x05)
429 */
430 u8 nmask;
431 } __packed __aligned(16);
432
433 struct sisl_rht_entry_f1 {
434 u64 lun_id;
435 union {
436 struct {
437 u8 valid;
438 u8 rsvd[5];
439 u8 fp;
440 u8 port_sel;
441 };
442
443 u64 dw;
444 };
445 } __packed __aligned(16);
446
447 /* make the fp byte */
448 #define SISL_RHT_FP(fmt, perm) (((fmt) << 4) | (perm))
449
450 /* make the fp byte for a clone from a source fp and clone flags
451 * flags must be only 2 LSB bits.
452 */
453 #define SISL_RHT_FP_CLONE(src_fp, cln_flags) ((src_fp) & (0xFC | (cln_flags)))
454
455 #define RHT_PERM_READ 0x01U
456 #define RHT_PERM_WRITE 0x02U
457 #define RHT_PERM_RW (RHT_PERM_READ | RHT_PERM_WRITE)
458
459 /* extract the perm bits from a fp */
460 #define SISL_RHT_PERM(fp) ((fp) & RHT_PERM_RW)
461
462 #define PORT0 0x01U
463 #define PORT1 0x02U
464 #define BOTH_PORTS (PORT0 | PORT1)
465
466 /* AFU Sync Mode byte */
467 #define AFU_LW_SYNC 0x0U
468 #define AFU_HW_SYNC 0x1U
469 #define AFU_GSYNC 0x2U
470
471 /* Special Task Management Function CDB */
472 #define TMF_LUN_RESET 0x1U
473 #define TMF_CLEAR_ACA 0x2U
474
475
476 #define SISLITE_MAX_WS_BLOCKS 512
477
478 #endif /* _SISLITE_H */