1 /*- 2 * BSD LICENSE 3 * 4 * Copyright (C) 2008-2012 Daisuke Aoyama <aoyama@peach.ne.jp>. 5 * Copyright (c) Intel Corporation. 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 12 * * Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * * Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in 16 * the documentation and/or other materials provided with the 17 * distribution. 18 * * Neither the name of Intel Corporation nor the names of its 19 * contributors may be used to endorse or promote products derived 20 * from this software without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 #ifndef SPDK_ISCSI_TASK_H 36 #define SPDK_ISCSI_TASK_H 37 38 #include "iscsi/iscsi.h" 39 #include "spdk/scsi.h" 40 #include "spdk/util.h" 41 42 struct spdk_iscsi_task { 43 struct spdk_scsi_task scsi; 44 45 struct spdk_iscsi_task *parent; 46 47 struct spdk_iscsi_conn *conn; 48 struct spdk_iscsi_pdu *pdu; 49 struct spdk_mobj *mobj; 50 uint32_t outstanding_r2t; 51 52 uint32_t desired_data_transfer_length; 53 54 /* Only valid for Read/Write */ 55 uint32_t bytes_completed; 56 57 uint32_t data_out_cnt; 58 59 /* 60 * Tracks the current offset of large read or write io. 61 */ 62 uint32_t current_data_offset; 63 64 /* 65 * next_expected_r2t_offset is used when we receive 66 * the DataOUT PDU. 67 */ 68 uint32_t next_expected_r2t_offset; 69 70 /* 71 * Tracks the length of the R2T that is in progress. 72 * Used to check that an R2T burst does not exceed 73 * MaxBurstLength. 74 */ 75 uint32_t current_r2t_length; 76 77 /* 78 * next_r2t_offset is used when we are sending the 79 * R2T packet to keep track of next offset of r2t. 80 */ 81 uint32_t next_r2t_offset; 82 uint32_t R2TSN; 83 uint32_t r2t_datasn; /* record next datasn for a r2tsn */ 84 uint32_t acked_r2tsn; /* next r2tsn to be acked */ 85 uint32_t datain_datasn; 86 uint32_t acked_data_sn; /* next expected datain datasn */ 87 uint32_t ttt; 88 bool is_r2t_active; 89 90 uint32_t tag; 91 92 /** 93 * Record the lun id just in case the lun is invalid, 94 * which will happen when hot removing the lun. 95 */ 96 int lun_id; 97 98 struct spdk_poller *mgmt_poller; 99 100 TAILQ_ENTRY(spdk_iscsi_task) link; 101 102 TAILQ_HEAD(subtask_list, spdk_iscsi_task) subtask_list; 103 TAILQ_ENTRY(spdk_iscsi_task) subtask_link; 104 bool is_queued; /* is queued in scsi layer for handling */ 105 }; 106 107 static inline void 108 iscsi_task_put(struct spdk_iscsi_task *task) 109 { 110 spdk_scsi_task_put(&task->scsi); 111 } 112 113 static inline struct spdk_iscsi_pdu * 114 iscsi_task_get_pdu(struct spdk_iscsi_task *task) 115 { 116 return task->pdu; 117 } 118 119 static inline void 120 iscsi_task_set_pdu(struct spdk_iscsi_task *task, struct spdk_iscsi_pdu *pdu) 121 { 122 task->pdu = pdu; 123 } 124 125 static inline struct iscsi_bhs * 126 iscsi_task_get_bhs(struct spdk_iscsi_task *task) 127 { 128 return &iscsi_task_get_pdu(task)->bhs; 129 } 130 131 static inline void 132 iscsi_task_associate_pdu(struct spdk_iscsi_task *task, struct spdk_iscsi_pdu *pdu) 133 { 134 iscsi_task_set_pdu(task, pdu); 135 pdu->ref++; 136 } 137 138 static inline void 139 iscsi_task_disassociate_pdu(struct spdk_iscsi_task *task) 140 { 141 if (iscsi_task_get_pdu(task)) { 142 iscsi_put_pdu(iscsi_task_get_pdu(task)); 143 iscsi_task_set_pdu(task, NULL); 144 } 145 } 146 147 static inline int 148 iscsi_task_is_immediate(struct spdk_iscsi_task *task) 149 { 150 struct iscsi_bhs_scsi_req *scsi_req; 151 152 scsi_req = (struct iscsi_bhs_scsi_req *)iscsi_task_get_bhs(task); 153 return (scsi_req->immediate == 1); 154 } 155 156 static inline int 157 iscsi_task_is_read(struct spdk_iscsi_task *task) 158 { 159 struct iscsi_bhs_scsi_req *scsi_req; 160 161 scsi_req = (struct iscsi_bhs_scsi_req *)iscsi_task_get_bhs(task); 162 return (scsi_req->read_bit == 1); 163 } 164 165 struct spdk_iscsi_task *iscsi_task_get(struct spdk_iscsi_conn *conn, 166 struct spdk_iscsi_task *parent, 167 spdk_scsi_task_cpl cpl_fn); 168 169 static inline struct spdk_iscsi_task * 170 iscsi_task_from_scsi_task(struct spdk_scsi_task *task) 171 { 172 return SPDK_CONTAINEROF(task, struct spdk_iscsi_task, scsi); 173 } 174 175 static inline struct spdk_iscsi_task * 176 iscsi_task_get_primary(struct spdk_iscsi_task *task) 177 { 178 if (task->parent) { 179 return task->parent; 180 } else { 181 return task; 182 } 183 } 184 185 static inline void 186 iscsi_task_set_mobj(struct spdk_iscsi_task *task, struct spdk_mobj *mobj) 187 { 188 task->mobj = mobj; 189 } 190 191 static inline struct spdk_mobj * 192 iscsi_task_get_mobj(struct spdk_iscsi_task *task) 193 { 194 return task->mobj; 195 } 196 197 #endif /* SPDK_ISCSI_TASK_H */ 198