1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Copyright (C) 2021 Broadcom. All Rights Reserved. The term
4 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
7 #if !defined(__EFCT_SCSI_H__)
8 #define __EFCT_SCSI_H__
9 #include <scsi/scsi_host.h>
10 #include <scsi/scsi_transport_fc.h>
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)
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)
28 #define EFCT_SCSI_SNS_BUF_VALID(sense) ((sense) && \
29 (0x70 == (((const u8 *)(sense))[0] & 0x70)))
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)
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)
42 #define EFCT_SCSI_WQ_CLASS_LOW_LATENCY 1
44 struct efct_scsi_cmd_resp
{
46 u16 scsi_status_qualifier
;
48 u32 response_data_length
;
50 u32 sense_data_length
;
52 u32 response_wire_length
;
58 struct fc_host_statistics fc_host_stats
;
59 struct Scsi_Host
*shost
;
60 struct fc_vport
*fc_vport
;
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
,
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
);
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
);
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)
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
,
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
,
128 struct efct_scsi_sgl
{
134 enum efct_scsi_io_role
{
135 EFCT_SCSI_IO_ROLE_ORIGINATOR
,
136 EFCT_SCSI_IO_ROLE_RESPONDER
,
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
);
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
);
149 efct_scsi_tgt_new_nport(struct efc
*efc
, struct efc_nport
*nport
);
151 efct_scsi_tgt_del_nport(struct efc
*efc
, struct efc_nport
*nport
);
154 efct_scsi_new_initiator(struct efc
*efc
, struct efc_node
*node
);
156 enum efct_scsi_del_initiator_reason
{
157 EFCT_SCSI_INITIATOR_DELETED
,
158 EFCT_SCSI_INITIATOR_MISSING
,
162 efct_scsi_del_initiator(struct efc
*efc
, struct efc_node
*node
, int reason
);
164 efct_scsi_recv_cmd(struct efct_io
*io
, uint64_t lun
, u8
*cdb
, u32 cdb_len
,
167 efct_scsi_recv_tmf(struct efct_io
*tmfio
, u32 lun
, enum efct_scsi_tmf_cmd cmd
,
168 struct efct_io
*abortio
, u32 flags
);
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
);
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
);
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
);
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
);
182 efct_scsi_tgt_abort_io(struct efct_io
*io
, efct_scsi_io_cb_t cb
, void *arg
);
184 void efct_scsi_io_complete(struct efct_io
*io
);
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
);
193 efct_scsi_del_vport(struct efct
*efct
, struct Scsi_Host
*shost
);
195 efct_scsi_new_vport(struct efct
*efct
, struct device
*dev
);
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
);
201 efct_bls_send_rjt(struct efct_io
*io
, struct fc_frame_header
*hdr
);
203 #endif /* __EFCT_SCSI_H__ */