xref: /linux/drivers/scsi/cxlflash/main.h (revision 75bf465f0bc33e9b776a46d6a1b9b990f5fb7c37)
1*2874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2c21e0bbfSMatthew R. Ochs /*
3c21e0bbfSMatthew R. Ochs  * CXL Flash Device Driver
4c21e0bbfSMatthew R. Ochs  *
5c21e0bbfSMatthew R. Ochs  * Written by: Manoj N. Kumar <manoj@linux.vnet.ibm.com>, IBM Corporation
6c21e0bbfSMatthew R. Ochs  *             Matthew R. Ochs <mrochs@linux.vnet.ibm.com>, IBM Corporation
7c21e0bbfSMatthew R. Ochs  *
8c21e0bbfSMatthew R. Ochs  * Copyright (C) 2015 IBM Corporation
9c21e0bbfSMatthew R. Ochs  */
10c21e0bbfSMatthew R. Ochs 
11c21e0bbfSMatthew R. Ochs #ifndef _CXLFLASH_MAIN_H
12c21e0bbfSMatthew R. Ochs #define _CXLFLASH_MAIN_H
13c21e0bbfSMatthew R. Ochs 
14c21e0bbfSMatthew R. Ochs #include <linux/list.h>
15c21e0bbfSMatthew R. Ochs #include <linux/types.h>
16c21e0bbfSMatthew R. Ochs #include <scsi/scsi.h>
17c21e0bbfSMatthew R. Ochs #include <scsi/scsi_device.h>
18c21e0bbfSMatthew R. Ochs 
19de5d35afSUma Krishnan #include "backend.h"
20de5d35afSUma Krishnan 
21c21e0bbfSMatthew R. Ochs #define CXLFLASH_NAME		"cxlflash"
22c21e0bbfSMatthew R. Ochs #define CXLFLASH_ADAPTER_NAME	"IBM POWER CXL Flash Adapter"
23a834a36bSUma Krishnan #define CXLFLASH_MAX_ADAPTERS	32
24c21e0bbfSMatthew R. Ochs 
25c21e0bbfSMatthew R. Ochs #define PCI_DEVICE_ID_IBM_CORSA		0x04F0
26a2746fb1SManoj Kumar #define PCI_DEVICE_ID_IBM_FLASH_GT	0x0600
2794344520SMatthew R. Ochs #define PCI_DEVICE_ID_IBM_BRIARD	0x0624
28c21e0bbfSMatthew R. Ochs 
29c21e0bbfSMatthew R. Ochs /* Since there is only one target, make it 0 */
30c21e0bbfSMatthew R. Ochs #define CXLFLASH_TARGET		0
31c21e0bbfSMatthew R. Ochs #define CXLFLASH_MAX_CDB_LEN	16
32c21e0bbfSMatthew R. Ochs 
33c21e0bbfSMatthew R. Ochs /* Really only one target per bus since the Texan is directly attached */
34c21e0bbfSMatthew R. Ochs #define CXLFLASH_MAX_NUM_TARGETS_PER_BUS	1
35c21e0bbfSMatthew R. Ochs #define CXLFLASH_MAX_NUM_LUNS_PER_TARGET	65536
36c21e0bbfSMatthew R. Ochs 
37c21e0bbfSMatthew R. Ochs #define CXLFLASH_PCI_ERROR_RECOVERY_TIMEOUT	(120 * HZ)
38c21e0bbfSMatthew R. Ochs 
39c21e0bbfSMatthew R. Ochs /* FC defines */
40c21e0bbfSMatthew R. Ochs #define FC_MTIP_CMDCONFIG 0x010
41c21e0bbfSMatthew R. Ochs #define FC_MTIP_STATUS 0x018
429cf43a36SMatthew R. Ochs #define FC_MAX_NUM_LUNS 0x080 /* Max LUNs host can provision for port */
439cf43a36SMatthew R. Ochs #define FC_CUR_NUM_LUNS 0x088 /* Cur number LUNs provisioned for port */
449cf43a36SMatthew R. Ochs #define FC_MAX_CAP_PORT 0x090 /* Max capacity all LUNs for port (4K blocks) */
459cf43a36SMatthew R. Ochs #define FC_CUR_CAP_PORT 0x098 /* Cur capacity all LUNs for port (4K blocks) */
46c21e0bbfSMatthew R. Ochs 
47c21e0bbfSMatthew R. Ochs #define FC_PNAME 0x300
48c21e0bbfSMatthew R. Ochs #define FC_CONFIG 0x320
49c21e0bbfSMatthew R. Ochs #define FC_CONFIG2 0x328
50c21e0bbfSMatthew R. Ochs #define FC_STATUS 0x330
51c21e0bbfSMatthew R. Ochs #define FC_ERROR 0x380
52c21e0bbfSMatthew R. Ochs #define FC_ERRCAP 0x388
53c21e0bbfSMatthew R. Ochs #define FC_ERRMSK 0x390
54c21e0bbfSMatthew R. Ochs #define FC_CNT_CRCERR 0x538
55c21e0bbfSMatthew R. Ochs #define FC_CRC_THRESH 0x580
56c21e0bbfSMatthew R. Ochs 
57c21e0bbfSMatthew R. Ochs #define FC_MTIP_CMDCONFIG_ONLINE	0x20ULL
58c21e0bbfSMatthew R. Ochs #define FC_MTIP_CMDCONFIG_OFFLINE	0x40ULL
59c21e0bbfSMatthew R. Ochs 
60c21e0bbfSMatthew R. Ochs #define FC_MTIP_STATUS_MASK		0x30ULL
61c21e0bbfSMatthew R. Ochs #define FC_MTIP_STATUS_ONLINE		0x20ULL
62c21e0bbfSMatthew R. Ochs #define FC_MTIP_STATUS_OFFLINE		0x10ULL
63c21e0bbfSMatthew R. Ochs 
64c21e0bbfSMatthew R. Ochs /* TIMEOUT and RETRY definitions */
65c21e0bbfSMatthew R. Ochs 
66c21e0bbfSMatthew R. Ochs /* AFU command timeout values */
67c21e0bbfSMatthew R. Ochs #define MC_AFU_SYNC_TIMEOUT	5	/* 5 secs */
689cf43a36SMatthew R. Ochs #define MC_LUN_PROV_TIMEOUT	5	/* 5 secs */
69bc88ac47SMatthew R. Ochs #define MC_AFU_DEBUG_TIMEOUT	5	/* 5 secs */
70c21e0bbfSMatthew R. Ochs 
71c21e0bbfSMatthew R. Ochs /* AFU command room retry limit */
72c21e0bbfSMatthew R. Ochs #define MC_ROOM_RETRY_CNT	10
73c21e0bbfSMatthew R. Ochs 
74c21e0bbfSMatthew R. Ochs /* FC CRC clear periodic timer */
75c21e0bbfSMatthew R. Ochs #define MC_CRC_THRESH 100	/* threshold in 5 mins */
76c21e0bbfSMatthew R. Ochs 
77c21e0bbfSMatthew R. Ochs #define FC_PORT_STATUS_RETRY_CNT 100	/* 100 100ms retries = 10 seconds */
78c21e0bbfSMatthew R. Ochs #define FC_PORT_STATUS_RETRY_INTERVAL_US 100000	/* microseconds */
79c21e0bbfSMatthew R. Ochs 
80c21e0bbfSMatthew R. Ochs /* VPD defines */
81c21e0bbfSMatthew R. Ochs #define CXLFLASH_VPD_LEN	256
82c21e0bbfSMatthew R. Ochs #define WWPN_LEN	16
83c21e0bbfSMatthew R. Ochs #define WWPN_BUF_LEN	(WWPN_LEN + 1)
84c21e0bbfSMatthew R. Ochs 
85c21e0bbfSMatthew R. Ochs enum undo_level {
869526f360SManoj N. Kumar 	UNDO_NOOP = 0,
87c21e0bbfSMatthew R. Ochs 	FREE_IRQ,
88c21e0bbfSMatthew R. Ochs 	UNMAP_ONE,
89c21e0bbfSMatthew R. Ochs 	UNMAP_TWO,
909526f360SManoj N. Kumar 	UNMAP_THREE
91c21e0bbfSMatthew R. Ochs };
92c21e0bbfSMatthew R. Ochs 
93c21e0bbfSMatthew R. Ochs struct dev_dependent_vals {
94c21e0bbfSMatthew R. Ochs 	u64 max_sectors;
9596e1b660SUma Krishnan 	u64 flags;
96704c4b0dSUma Krishnan #define CXLFLASH_NOTIFY_SHUTDOWN	0x0000000000000001ULL
970d419130SMatthew R. Ochs #define CXLFLASH_WWPN_VPD_REQUIRED	0x0000000000000002ULL
9807d0c52fSUma Krishnan #define CXLFLASH_OCXL_DEV		0x0000000000000004ULL
99c21e0bbfSMatthew R. Ochs };
100c21e0bbfSMatthew R. Ochs 
101de5d35afSUma Krishnan static inline const struct cxlflash_backend_ops *
cxlflash_assign_ops(struct dev_dependent_vals * ddv)102de5d35afSUma Krishnan cxlflash_assign_ops(struct dev_dependent_vals *ddv)
103de5d35afSUma Krishnan {
104de5d35afSUma Krishnan 	const struct cxlflash_backend_ops *ops = NULL;
105de5d35afSUma Krishnan 
106943e59feSCédric Le Goater #ifdef CONFIG_OCXL_BASE
107de5d35afSUma Krishnan 	if (ddv->flags & CXLFLASH_OCXL_DEV)
108de5d35afSUma Krishnan 		ops = &cxlflash_ocxl_ops;
109cd43c221SUma Krishnan #endif
110cd43c221SUma Krishnan 
111943e59feSCédric Le Goater #ifdef CONFIG_CXL_BASE
112de5d35afSUma Krishnan 	if (!(ddv->flags & CXLFLASH_OCXL_DEV))
113de5d35afSUma Krishnan 		ops = &cxlflash_cxl_ops;
114cd43c221SUma Krishnan #endif
115de5d35afSUma Krishnan 
116de5d35afSUma Krishnan 	return ops;
117de5d35afSUma Krishnan }
118de5d35afSUma Krishnan 
119c21e0bbfSMatthew R. Ochs struct asyc_intr_info {
120c21e0bbfSMatthew R. Ochs 	u64 status;
121c21e0bbfSMatthew R. Ochs 	char *desc;
122c21e0bbfSMatthew R. Ochs 	u8 port;
123c21e0bbfSMatthew R. Ochs 	u8 action;
124c21e0bbfSMatthew R. Ochs #define CLR_FC_ERROR	0x01
125c21e0bbfSMatthew R. Ochs #define LINK_RESET	0x02
126ef51074aSMatthew R. Ochs #define SCAN_HOST	0x04
127c21e0bbfSMatthew R. Ochs };
128c21e0bbfSMatthew R. Ochs 
129c21e0bbfSMatthew R. Ochs #endif /* _CXLFLASH_MAIN_H */
130