0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef __H_IBMVSCSI_TGT
0018 #define __H_IBMVSCSI_TGT
0019
0020 #include <linux/interrupt.h>
0021 #include "libsrp.h"
0022
0023 #define SYS_ID_NAME_LEN 64
0024 #define PARTITION_NAMELEN 96
0025 #define IBMVSCSIS_NAMELEN 32
0026
0027 #define MSG_HI 0
0028 #define MSG_LOW 1
0029
0030 #define MAX_CMD_Q_PAGES 4
0031 #define CRQ_PER_PAGE (PAGE_SIZE / sizeof(struct viosrp_crq))
0032
0033 #define DEFAULT_CMD_Q_SIZE CRQ_PER_PAGE
0034 #define MAX_CMD_Q_SIZE (DEFAULT_CMD_Q_SIZE * MAX_CMD_Q_PAGES)
0035
0036 #define SRP_VIOLATION 0x102
0037
0038
0039
0040
0041 #define SUPPORTED_FORMATS ((SRP_DATA_DESC_DIRECT << 1) | \
0042 (SRP_DATA_DESC_INDIRECT << 1))
0043
0044 #define SCSI_LUN_ADDR_METHOD_FLAT 1
0045
0046 struct dma_window {
0047 u32 liobn;
0048 u64 tce_base;
0049 u64 tce_size;
0050 };
0051
0052 struct target_dds {
0053 u64 unit_id;
0054 #define NUM_DMA_WINDOWS 2
0055 #define LOCAL 0
0056 #define REMOTE 1
0057 struct dma_window window[NUM_DMA_WINDOWS];
0058
0059
0060 uint partition_num;
0061 char partition_name[PARTITION_NAMELEN];
0062 };
0063
0064 #define MAX_NUM_PORTS 1
0065 #define MAX_H_COPY_RDMA (128 * 1024)
0066
0067 #define MAX_EYE 64
0068
0069
0070 #define ADAPT_SUCCESS 0L
0071
0072 #define ERROR -40L
0073
0074 struct format_code {
0075 u8 reserved;
0076 u8 buffers;
0077 };
0078
0079 struct client_info {
0080 #define SRP_VERSION "16.a"
0081 char srp_version[8];
0082
0083 char partition_name[PARTITION_NAMELEN];
0084
0085 u32 partition_number;
0086
0087 u32 mad_version;
0088 u32 os_type;
0089 };
0090
0091
0092
0093
0094
0095 #define SECONDS_TO_CONSIDER_FAILED 30
0096
0097
0098
0099
0100 #define WAIT_SECONDS 1
0101 #define WAIT_NANO_SECONDS 5000
0102 #define MAX_TIMER_POPS ((1000000 / WAIT_NANO_SECONDS) * \
0103 SECONDS_TO_CONSIDER_FAILED)
0104
0105
0106
0107
0108 struct timer_cb {
0109 struct hrtimer timer;
0110
0111
0112
0113
0114
0115
0116 int timer_pops;
0117
0118 bool started;
0119 };
0120
0121 struct cmd_queue {
0122
0123 struct viosrp_crq *base_addr;
0124 dma_addr_t crq_token;
0125
0126 uint mask;
0127
0128 uint index;
0129 int size;
0130 };
0131
0132 #define SCSOLNT_RESP_SHIFT 1
0133 #define UCSOLNT_RESP_SHIFT 2
0134
0135 #define SCSOLNT BIT(SCSOLNT_RESP_SHIFT)
0136 #define UCSOLNT BIT(UCSOLNT_RESP_SHIFT)
0137
0138 enum cmd_type {
0139 SCSI_CDB = 0x01,
0140 TASK_MANAGEMENT = 0x02,
0141
0142 ADAPTER_MAD = 0x04,
0143 UNSET_TYPE = 0x08,
0144 };
0145
0146 struct iu_rsp {
0147 u8 format;
0148 u8 sol_not;
0149 u16 len;
0150
0151 u64 tag;
0152 };
0153
0154 struct ibmvscsis_cmd {
0155 struct list_head list;
0156
0157 struct se_cmd se_cmd;
0158 struct iu_entry *iue;
0159 struct iu_rsp rsp;
0160 struct work_struct work;
0161 struct scsi_info *adapter;
0162 struct ibmvscsis_cmd *abort_cmd;
0163
0164 unsigned char sense_buf[TRANSPORT_SENSE_BUFFER];
0165 u64 init_time;
0166 #define CMD_FAST_FAIL BIT(0)
0167 #define DELAY_SEND BIT(1)
0168 u32 flags;
0169 char type;
0170 };
0171
0172 struct ibmvscsis_nexus {
0173 struct se_session *se_sess;
0174 };
0175
0176 struct ibmvscsis_tport {
0177
0178 u8 tport_proto_id;
0179
0180 char tport_name[IBMVSCSIS_NAMELEN];
0181
0182 struct se_wwn tport_wwn;
0183
0184 struct se_portal_group se_tpg;
0185
0186 u16 tport_tpgt;
0187
0188 struct ibmvscsis_nexus *ibmv_nexus;
0189 bool enabled;
0190 bool releasing;
0191 };
0192
0193 struct scsi_info {
0194 struct list_head list;
0195 char eye[MAX_EYE];
0196
0197
0198 struct list_head waiting_rsp;
0199 #define NO_QUEUE 0x00
0200 #define WAIT_ENABLED 0X01
0201 #define WAIT_CONNECTION 0x04
0202
0203 #define CONNECTED 0x08
0204
0205 #define SRP_PROCESSING 0x10
0206
0207 #define UNCONFIGURING 0x20
0208
0209 #define WAIT_IDLE 0x40
0210
0211 #define ERR_DISCONNECT 0x80
0212
0213 #define ERR_DISCONNECT_RECONNECT 0x100
0214
0215 #define ERR_DISCONNECTED 0x200
0216
0217 #define UNDEFINED 0x400
0218 u16 state;
0219 int fast_fail;
0220 struct target_dds dds;
0221 char *cmd_pool;
0222
0223 struct list_head free_cmd;
0224
0225 struct list_head schedule_q;
0226
0227 struct list_head active_q;
0228 caddr_t *map_buf;
0229
0230 dma_addr_t map_ioba;
0231
0232 int request_limit;
0233
0234 int credit;
0235
0236 int debit;
0237
0238
0239 #define PROCESSING_MAD 0x00002
0240
0241 #define WAIT_FOR_IDLE 0x00004
0242
0243 #define CRQ_CLOSED 0x00010
0244
0245 #define CLIENT_FAILED 0x00040
0246
0247 #define TRANS_EVENT 0x00080
0248
0249 #define RESPONSE_Q_DOWN 0x00100
0250
0251 #define SCHEDULE_DISCONNECT 0x00400
0252
0253 #define DISCONNECT_SCHEDULED 0x00800
0254
0255 #define CFG_SLEEPING 0x01000
0256
0257 #define PREP_FOR_SUSPEND_ENABLED 0x02000
0258
0259 #define PREP_FOR_SUSPEND_PENDING 0x04000
0260
0261 #define PREP_FOR_SUSPEND_ABORTED 0x08000
0262
0263 #define PREP_FOR_SUSPEND_OVERWRITE 0x10000
0264 u32 flags;
0265
0266 spinlock_t intr_lock;
0267
0268 struct cmd_queue cmd_q;
0269
0270 u64 empty_iu_id;
0271
0272 u64 empty_iu_tag;
0273 uint new_state;
0274 uint resume_state;
0275
0276 struct timer_cb rsp_q_timer;
0277
0278 struct client_info client_data;
0279
0280 u32 client_cap;
0281
0282
0283
0284
0285
0286
0287
0288 u16 phyp_acr_state;
0289 u32 phyp_acr_flags;
0290
0291 struct workqueue_struct *work_q;
0292 struct completion wait_idle;
0293 struct completion unconfig;
0294 struct device dev;
0295 struct vio_dev *dma_dev;
0296 struct srp_target target;
0297 struct ibmvscsis_tport tport;
0298 struct tasklet_struct work_task;
0299 struct work_struct proc_work;
0300 };
0301
0302
0303
0304
0305
0306 #define IS_DISCONNECTING (UNCONFIGURING | ERR_DISCONNECT_RECONNECT | \
0307 ERR_DISCONNECT)
0308
0309
0310
0311
0312
0313
0314 #define DONT_PROCESS_STATE (IS_DISCONNECTING | UNDEFINED | \
0315 ERR_DISCONNECTED | WAIT_IDLE)
0316
0317
0318
0319
0320
0321 #define BLOCK (DISCONNECT_SCHEDULED)
0322
0323
0324 #define TARGET_STOP(VSCSI) (long)(((VSCSI)->state & DONT_PROCESS_STATE) | \
0325 ((VSCSI)->flags & BLOCK))
0326
0327 #define PREP_FOR_SUSPEND_FLAGS (PREP_FOR_SUSPEND_ENABLED | \
0328 PREP_FOR_SUSPEND_PENDING | \
0329 PREP_FOR_SUSPEND_ABORTED | \
0330 PREP_FOR_SUSPEND_OVERWRITE)
0331
0332
0333 #define PRESERVE_FLAG_FIELDS (PREP_FOR_SUSPEND_FLAGS)
0334
0335 #define vio_iu(IUE) ((union viosrp_iu *)((IUE)->sbuf->buf))
0336
0337 #define READ_CMD(cdb) (((cdb)[0] & 0x1F) == 8)
0338 #define WRITE_CMD(cdb) (((cdb)[0] & 0x1F) == 0xA)
0339
0340 #ifndef H_GET_PARTNER_INFO
0341 #define H_GET_PARTNER_INFO 0x0000000000000008LL
0342 #endif
0343 #ifndef H_ENABLE_PREPARE_FOR_SUSPEND
0344 #define H_ENABLE_PREPARE_FOR_SUSPEND 0x000000000000001DLL
0345 #endif
0346 #ifndef H_READY_FOR_SUSPEND
0347 #define H_READY_FOR_SUSPEND 0x000000000000001ELL
0348 #endif
0349
0350
0351 #define h_copy_rdma(l, sa, sb, da, db) \
0352 plpar_hcall_norets(H_COPY_RDMA, l, sa, sb, da, db)
0353 #define h_vioctl(u, o, a, u1, u2, u3, u4) \
0354 plpar_hcall_norets(H_VIOCTL, u, o, a, u1, u2)
0355 #define h_reg_crq(ua, tok, sz) \
0356 plpar_hcall_norets(H_REG_CRQ, ua, tok, sz)
0357 #define h_free_crq(ua) \
0358 plpar_hcall_norets(H_FREE_CRQ, ua)
0359 #define h_send_crq(ua, d1, d2) \
0360 plpar_hcall_norets(H_SEND_CRQ, ua, d1, d2)
0361
0362 #endif