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.
10 #include "efct_scsi.h"
11 #include <target/target_core_base.h>
13 #define efct_lio_io_printf(io, fmt, ...) \
14 efc_log_debug(io->efct, \
15 "[%s] [%04x][i:%04x t:%04x h:%04x]" fmt,\
16 io->node->display_name, io->instance_index, \
17 io->init_task_tag, io->tgt_task_tag, io->hw_tag,\
20 #define efct_lio_tmfio_printf(io, fmt, ...) \
21 efc_log_debug(io->efct, \
22 "[%s] [%04x][i:%04x t:%04x h:%04x][f:%02x]" fmt,\
23 io->node->display_name, io->instance_index, \
24 io->init_task_tag, io->tgt_task_tag, io->hw_tag,\
25 io->tgt_io.tmf, ##__VA_ARGS__)
27 #define efct_set_lio_io_state(io, value) (io->tgt_io.state |= value)
29 struct efct_lio_wq_data {
32 struct work_struct work;
35 /* Target private efct structure */
36 struct efct_scsi_tgt {
41 * Variables used to send task set full. We are using a high watermark
42 * method to send task set full. We will reserve a fixed number of IOs
43 * per initiator plus a fudge factor. Once we reach this number,
44 * then the target will start sending task set full/busy responses.
46 atomic_t initiator_count;
48 atomic_t io_high_watermark;
50 atomic_t watermark_hit;
54 struct efct_lio_nport *lio_nport;
55 struct efct_lio_tpg *tpg;
57 struct list_head vport_list;
58 /* Protects vport list*/
59 spinlock_t efct_lio_lock;
64 struct efct_scsi_tgt_nport {
65 struct efct_lio_nport *lio_nport;
69 struct list_head list_entry;
71 void (*release)(struct kref *arg);
73 struct efc_node *node;
74 struct se_session *session;
75 spinlock_t active_ios_lock;
76 struct list_head active_ios;
77 char display_name[EFC_NAME_LENGTH];
85 #define EFCT_LIO_STATE_SCSI_RECV_CMD (1 << 0)
86 #define EFCT_LIO_STATE_TGT_SUBMIT_CMD (1 << 1)
87 #define EFCT_LIO_STATE_TFO_QUEUE_DATA_IN (1 << 2)
88 #define EFCT_LIO_STATE_TFO_WRITE_PENDING (1 << 3)
89 #define EFCT_LIO_STATE_TGT_EXECUTE_CMD (1 << 4)
90 #define EFCT_LIO_STATE_SCSI_SEND_RD_DATA (1 << 5)
91 #define EFCT_LIO_STATE_TFO_CHK_STOP_FREE (1 << 6)
92 #define EFCT_LIO_STATE_SCSI_DATA_DONE (1 << 7)
93 #define EFCT_LIO_STATE_TFO_QUEUE_STATUS (1 << 8)
94 #define EFCT_LIO_STATE_SCSI_SEND_RSP (1 << 9)
95 #define EFCT_LIO_STATE_SCSI_RSP_DONE (1 << 10)
96 #define EFCT_LIO_STATE_TGT_GENERIC_FREE (1 << 11)
97 #define EFCT_LIO_STATE_SCSI_RECV_TMF (1 << 12)
98 #define EFCT_LIO_STATE_TGT_SUBMIT_TMR (1 << 13)
99 #define EFCT_LIO_STATE_TFO_WRITE_PEND_STATUS (1 << 14)
100 #define EFCT_LIO_STATE_TGT_GENERIC_REQ_FAILURE (1 << 15)
102 #define EFCT_LIO_STATE_TFO_ABORTED_TASK (1 << 29)
103 #define EFCT_LIO_STATE_TFO_RELEASE_CMD (1 << 30)
104 #define EFCT_LIO_STATE_SCSI_CMPL_CMD (1u << 31)
106 struct efct_scsi_tgt_io {
108 unsigned char sense_buffer[TRANSPORT_SENSE_BUFFER];
109 enum dma_data_direction ddir;
115 struct efct_io *io_to_abort;
119 enum efct_scsi_io_status err;
125 /* Handler return codes */
127 SCSI_HANDLER_DATAPHASE_STARTED = 1,
128 SCSI_HANDLER_RESP_STARTED,
129 SCSI_HANDLER_VALIDATED_DATAPHASE_STARTED,
130 SCSI_CMD_NOT_SUPPORTED,
133 #define WWN_NAME_LEN 32
134 struct efct_lio_vport {
138 unsigned char wwpn_str[WWN_NAME_LEN];
139 struct se_wwn vport_wwn;
140 struct efct_lio_tpg *tpg;
142 struct Scsi_Host *shost;
143 struct fc_vport *fc_vport;
147 struct efct_lio_nport {
149 unsigned char wwpn_str[WWN_NAME_LEN];
150 struct se_wwn nport_wwn;
151 struct efct_lio_tpg *tpg;
156 struct efct_lio_tpg_attrib {
157 u32 generate_node_acls;
158 u32 cache_dynamic_acls;
159 u32 demo_mode_write_protect;
160 u32 prod_mode_write_protect;
161 u32 demo_mode_login_only;
162 bool session_deletion_wait;
165 struct efct_lio_tpg {
166 struct se_portal_group tpg;
167 struct efct_lio_nport *nport;
168 struct efct_lio_vport *vport;
169 struct efct_lio_tpg_attrib tpg_attrib;
174 struct efct_lio_nacl {
176 char nport_name[WWN_NAME_LEN];
177 struct se_session *session;
178 struct se_node_acl se_node_acl;
181 struct efct_lio_vport_list_t {
182 struct list_head list_entry;
183 struct efct_lio_vport *lio_vport;
186 int efct_scsi_tgt_driver_init(void);
187 int efct_scsi_tgt_driver_exit(void);
189 #endif /*__EFCT_LIO_H__ */