1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (C) 2021 Broadcom. All Rights Reserved. The term 4 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. 5 */ 6 7 #if !defined(__EFCT_SCSI_H__) 8 #define __EFCT_SCSI_H__ 9 #include <scsi/scsi_host.h> 10 #include <scsi/scsi_transport_fc.h> 11 12 /* efct_scsi_rcv_cmd() efct_scsi_rcv_tmf() flags */ 13 #define EFCT_SCSI_CMD_DIR_IN (1 << 0) 14 #define EFCT_SCSI_CMD_DIR_OUT (1 << 1) 15 #define EFCT_SCSI_CMD_SIMPLE (1 << 2) 16 #define EFCT_SCSI_CMD_HEAD_OF_QUEUE (1 << 3) 17 #define EFCT_SCSI_CMD_ORDERED (1 << 4) 18 #define EFCT_SCSI_CMD_UNTAGGED (1 << 5) 19 #define EFCT_SCSI_CMD_ACA (1 << 6) 20 #define EFCT_SCSI_FIRST_BURST_ERR (1 << 7) 21 #define EFCT_SCSI_FIRST_BURST_ABORTED (1 << 8) 22 23 /* efct_scsi_send_rd_data/recv_wr_data/send_resp flags */ 24 #define EFCT_SCSI_LAST_DATAPHASE (1 << 0) 25 #define EFCT_SCSI_NO_AUTO_RESPONSE (1 << 1) 26 #define EFCT_SCSI_LOW_LATENCY (1 << 2) 27 28 #define EFCT_SCSI_SNS_BUF_VALID(sense) ((sense) && \ 29 (0x70 == (((const u8 *)(sense))[0] & 0x70))) 30 31 #define EFCT_SCSI_WQ_STEERING_SHIFT 16 32 #define EFCT_SCSI_WQ_STEERING_MASK (0xf << EFCT_SCSI_WQ_STEERING_SHIFT) 33 #define EFCT_SCSI_WQ_STEERING_CLASS (0 << EFCT_SCSI_WQ_STEERING_SHIFT) 34 #define EFCT_SCSI_WQ_STEERING_REQUEST (1 << EFCT_SCSI_WQ_STEERING_SHIFT) 35 #define EFCT_SCSI_WQ_STEERING_CPU (2 << EFCT_SCSI_WQ_STEERING_SHIFT) 36 37 #define EFCT_SCSI_WQ_CLASS_SHIFT (20) 38 #define EFCT_SCSI_WQ_CLASS_MASK (0xf << EFCT_SCSI_WQ_CLASS_SHIFT) 39 #define EFCT_SCSI_WQ_CLASS(x) ((x & EFCT_SCSI_WQ_CLASS_MASK) << \ 40 EFCT_SCSI_WQ_CLASS_SHIFT) 41 42 #define EFCT_SCSI_WQ_CLASS_LOW_LATENCY 1 43 44 struct efct_scsi_cmd_resp { 45 u8 scsi_status; 46 u16 scsi_status_qualifier; 47 u8 *response_data; 48 u32 response_data_length; 49 u8 *sense_data; 50 u32 sense_data_length; 51 int residual; 52 u32 response_wire_length; 53 }; 54 55 struct efct_vport { 56 struct efct *efct; 57 bool is_vport; 58 struct fc_host_statistics fc_host_stats; 59 struct Scsi_Host *shost; 60 struct fc_vport *fc_vport; 61 u64 npiv_wwpn; 62 u64 npiv_wwnn; 63 }; 64 65 /* Status values returned by IO callbacks */ 66 enum efct_scsi_io_status { 67 EFCT_SCSI_STATUS_GOOD = 0, 68 EFCT_SCSI_STATUS_ABORTED, 69 EFCT_SCSI_STATUS_ERROR, 70 EFCT_SCSI_STATUS_DIF_GUARD_ERR, 71 EFCT_SCSI_STATUS_DIF_REF_TAG_ERROR, 72 EFCT_SCSI_STATUS_DIF_APP_TAG_ERROR, 73 EFCT_SCSI_STATUS_DIF_UNKNOWN_ERROR, 74 EFCT_SCSI_STATUS_PROTOCOL_CRC_ERROR, 75 EFCT_SCSI_STATUS_NO_IO, 76 EFCT_SCSI_STATUS_ABORT_IN_PROGRESS, 77 EFCT_SCSI_STATUS_CHECK_RESPONSE, 78 EFCT_SCSI_STATUS_COMMAND_TIMEOUT, 79 EFCT_SCSI_STATUS_TIMEDOUT_AND_ABORTED, 80 EFCT_SCSI_STATUS_SHUTDOWN, 81 EFCT_SCSI_STATUS_NEXUS_LOST, 82 }; 83 84 struct efct_node; 85 struct efct_io; 86 struct efc_node; 87 struct efc_nport; 88 89 /* Callback used by send_rd_data(), recv_wr_data(), send_resp() */ 90 typedef int (*efct_scsi_io_cb_t)(struct efct_io *io, 91 enum efct_scsi_io_status status, 92 u32 flags, void *arg); 93 94 /* Callback used by send_rd_io(), send_wr_io() */ 95 typedef int (*efct_scsi_rsp_io_cb_t)(struct efct_io *io, 96 enum efct_scsi_io_status status, 97 struct efct_scsi_cmd_resp *rsp, 98 u32 flags, void *arg); 99 100 /* efct_scsi_cb_t flags */ 101 #define EFCT_SCSI_IO_CMPL (1 << 0) 102 /* IO completed, response sent */ 103 #define EFCT_SCSI_IO_CMPL_RSP_SENT (1 << 1) 104 #define EFCT_SCSI_IO_ABORTED (1 << 2) 105 106 /* efct_scsi_recv_tmf() request values */ 107 enum efct_scsi_tmf_cmd { 108 EFCT_SCSI_TMF_ABORT_TASK = 1, 109 EFCT_SCSI_TMF_QUERY_TASK_SET, 110 EFCT_SCSI_TMF_ABORT_TASK_SET, 111 EFCT_SCSI_TMF_CLEAR_TASK_SET, 112 EFCT_SCSI_TMF_QUERY_ASYNCHRONOUS_EVENT, 113 EFCT_SCSI_TMF_LOGICAL_UNIT_RESET, 114 EFCT_SCSI_TMF_CLEAR_ACA, 115 EFCT_SCSI_TMF_TARGET_RESET, 116 }; 117 118 /* efct_scsi_send_tmf_resp() response values */ 119 enum efct_scsi_tmf_resp { 120 EFCT_SCSI_TMF_FUNCTION_COMPLETE = 1, 121 EFCT_SCSI_TMF_FUNCTION_SUCCEEDED, 122 EFCT_SCSI_TMF_FUNCTION_IO_NOT_FOUND, 123 EFCT_SCSI_TMF_FUNCTION_REJECTED, 124 EFCT_SCSI_TMF_INCORRECT_LOGICAL_UNIT_NUMBER, 125 EFCT_SCSI_TMF_SERVICE_DELIVERY, 126 }; 127 128 struct efct_scsi_sgl { 129 uintptr_t addr; 130 uintptr_t dif_addr; 131 size_t len; 132 }; 133 134 enum efct_scsi_io_role { 135 EFCT_SCSI_IO_ROLE_ORIGINATOR, 136 EFCT_SCSI_IO_ROLE_RESPONDER, 137 }; 138 139 struct efct_io * 140 efct_scsi_io_alloc(struct efct_node *node); 141 void efct_scsi_io_free(struct efct_io *io); 142 struct efct_io *efct_io_get_instance(struct efct *efct, u32 index); 143 144 int efct_scsi_tgt_driver_init(void); 145 int efct_scsi_tgt_driver_exit(void); 146 int efct_scsi_tgt_new_device(struct efct *efct); 147 int efct_scsi_tgt_del_device(struct efct *efct); 148 int 149 efct_scsi_tgt_new_nport(struct efc *efc, struct efc_nport *nport); 150 void 151 efct_scsi_tgt_del_nport(struct efc *efc, struct efc_nport *nport); 152 153 int 154 efct_scsi_new_initiator(struct efc *efc, struct efc_node *node); 155 156 enum efct_scsi_del_initiator_reason { 157 EFCT_SCSI_INITIATOR_DELETED, 158 EFCT_SCSI_INITIATOR_MISSING, 159 }; 160 161 int 162 efct_scsi_del_initiator(struct efc *efc, struct efc_node *node, int reason); 163 void 164 efct_scsi_recv_cmd(struct efct_io *io, uint64_t lun, u8 *cdb, u32 cdb_len, 165 u32 flags); 166 int 167 efct_scsi_recv_tmf(struct efct_io *tmfio, u32 lun, enum efct_scsi_tmf_cmd cmd, 168 struct efct_io *abortio, u32 flags); 169 int 170 efct_scsi_send_rd_data(struct efct_io *io, u32 flags, struct efct_scsi_sgl *sgl, 171 u32 sgl_count, u64 wire_len, efct_scsi_io_cb_t cb, void *arg); 172 int 173 efct_scsi_recv_wr_data(struct efct_io *io, u32 flags, struct efct_scsi_sgl *sgl, 174 u32 sgl_count, u64 wire_len, efct_scsi_io_cb_t cb, void *arg); 175 int 176 efct_scsi_send_resp(struct efct_io *io, u32 flags, 177 struct efct_scsi_cmd_resp *rsp, efct_scsi_io_cb_t cb, void *arg); 178 int 179 efct_scsi_send_tmf_resp(struct efct_io *io, enum efct_scsi_tmf_resp rspcode, 180 u8 addl_rsp_info[3], efct_scsi_io_cb_t cb, void *arg); 181 int 182 efct_scsi_tgt_abort_io(struct efct_io *io, efct_scsi_io_cb_t cb, void *arg); 183 184 void efct_scsi_io_complete(struct efct_io *io); 185 186 int efct_scsi_reg_fc_transport(void); 187 void efct_scsi_release_fc_transport(void); 188 int efct_scsi_new_device(struct efct *efct); 189 void efct_scsi_del_device(struct efct *efct); 190 void _efct_scsi_io_free(struct kref *arg); 191 192 int 193 efct_scsi_del_vport(struct efct *efct, struct Scsi_Host *shost); 194 struct efct_vport * 195 efct_scsi_new_vport(struct efct *efct, struct device *dev); 196 197 int efct_scsi_io_dispatch(struct efct_io *io, void *cb); 198 int efct_scsi_io_dispatch_abort(struct efct_io *io, void *cb); 199 void efct_scsi_check_pending(struct efct *efct); 200 struct efct_io * 201 efct_bls_send_rjt(struct efct_io *io, struct fc_frame_header *hdr); 202 203 #endif /* __EFCT_SCSI_H__ */ 204