1 /*
   2  * CDDL HEADER START
   3  *
   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at src/sun_nws/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at src/sun_nws/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 
  27 #ifndef _IDM_H
  28 #define _IDM_H
  29 
  30 #pragma ident   "@(#)idm.h      1.13    08/03/26 SMI"
  31 
  32 #ifdef  __cplusplus
  33 extern "C" {
  34 #endif
  35 
  36 typedef enum {
  37         IDM_STATUS_SUCCESS = 0,
  38         IDM_STATUS_FAIL,
  39         IDM_STATUS_NORESOURCES,
  40         IDM_STATUS_REJECT,
  41         IDM_STATUS_IO,
  42         IDM_STATUS_HEADER_DIGEST,
  43         IDM_STATUS_DATA_DIGEST,
  44         IDM_STATUS_PROTOCOL_ERROR
  45 } idm_status_t;
  46 
  47 typedef enum {
  48         CN_CONNECT_ACCEPT = 1,  /* Target only */
  49         CN_LOGIN_FAIL,          /* Target only */
  50 #if 0
  51         CN_READY_FOR_LOGIN,     /* Initiator only */
  52 #endif
  53         CN_FFM_ENABLED,
  54         CN_FFM_DISABLED,
  55         CN_CONNECT_DESTROY
  56 } idm_client_notify_t;
  57 
  58 /*
  59  * Request structures
  60  */
  61 
  62 /* Defined in idm_impl.h */
  63 struct idm_conn_s;
  64 struct idm_svc_s;
  65 struct idm_buf_s;
  66 struct idm_pdu_s;
  67 struct idm_task_s;
  68 
  69 typedef idm_status_t (idm_client_notify_cb_t)(
  70     struct idm_conn_s *ic, idm_client_notify_t cn, uintptr_t data);
  71 
  72 typedef void (idm_rx_pdu_cb_t)(struct idm_conn_s *ic, struct idm_pdu_s *pdu);
  73 
  74 typedef void (idm_rx_pdu_error_cb_t)(struct idm_conn_s *ic,
  75     struct idm_pdu_s *pdu, idm_status_t status);
  76 
  77 typedef void (idm_buf_cb_t)(struct idm_buf_s *idb, idm_status_t status);
  78 
  79 typedef void (idm_pdu_cb_t)(struct idm_pdu_s *pdu, idm_status_t status);
  80 
  81 typedef void (idm_task_cb_t)(struct idm_task_s *task, idm_status_t status);
  82 
  83 typedef void (idm_build_hdr_cb_t)(
  84     struct idm_task_s *task, struct idm_pdu_s *pdu, uint8_t opcode);
  85 
  86 typedef struct {
  87         idm_rx_pdu_cb_t         *icb_rx_scsi_cmd;
  88         idm_rx_pdu_cb_t         *icb_rx_scsi_rsp;
  89         idm_rx_pdu_cb_t         *icb_rx_misc;
  90         idm_rx_pdu_error_cb_t   *icb_rx_error;
  91         idm_task_cb_t           *icb_task_aborted;
  92         idm_client_notify_cb_t  *icb_client_notify;
  93         idm_build_hdr_cb_t      *icb_build_hdr;
  94 } idm_conn_ops_t;
  95 
  96 typedef struct {
  97         int                     cr_domain;
  98         int                     cr_type;
  99         int                     cr_protocol;
 100         boolean_t               cr_bound;
 101         struct sockaddr         cr_bound_addr;
 102         struct sockaddr         cr_ini_dst_addr;
 103         idm_conn_ops_t          icr_conn_ops;
 104 } idm_conn_req_t;
 105 
 106 typedef struct {
 107         uint16_t                sr_port;
 108         idm_conn_ops_t          sr_conn_ops;
 109 } idm_svc_req_t;
 110 
 111 #include <iscsi_protocol.h>
 112 #include <idm_conn_sm.h>
 113 #include <idm_transport.h>
 114 #include <idm_impl.h>
 115 #include <idm_so.h>
 116 
 117 /*
 118  * iSCSI Initiator Services
 119  */
 120 
 121 idm_status_t
 122 idm_ini_conn_create(idm_conn_req_t *cr, idm_conn_t **new_con);
 123 
 124 idm_status_t
 125 idm_ini_conn_connect(idm_conn_t *ic);
 126 
 127 void
 128 idm_ini_conn_disconnect(idm_conn_t *ic);
 129 
 130 void
 131 idm_ini_conn_destroy(idm_conn_t *ic);
 132 
 133 /*
 134  * iSCSI Target Services
 135  */
 136 
 137 idm_status_t
 138 idm_tgt_svc_create(idm_svc_req_t *sr, idm_svc_t **new_svc);
 139 
 140 idm_status_t
 141 idm_tgt_svc_online(idm_svc_t *is);
 142 
 143 void
 144 idm_tgt_svc_offline(idm_svc_t *is);
 145 
 146 void
 147 idm_tgt_svc_destroy(idm_svc_t *is);
 148 
 149 idm_svc_t *
 150 idm_tgt_svc_lookup(uint16_t port);
 151 
 152 void
 153 idm_tgt_svc_rele(idm_svc_t *is);
 154 
 155 idm_status_t
 156 idm_tgt_conn_accept(idm_conn_t *ic);
 157 
 158 void
 159 idm_tgt_conn_reject(idm_conn_t *ic);
 160 
 161 void
 162 idm_conn_hold(idm_conn_t *ic);
 163 
 164 void
 165 idm_conn_rele(idm_conn_t *ic);
 166 
 167 /*
 168  * Target data transfer services
 169  */
 170 idm_status_t
 171 idm_buf_tx_to_ini(idm_task_t *idt, idm_buf_t *idb,
 172     uint32_t offset, uint32_t xfer_length,
 173     idm_buf_cb_t idb_buf_cb, void *cb_arg);
 174 
 175 idm_status_t
 176 idm_buf_rx_from_ini(idm_task_t *idt, idm_buf_t *idb,
 177     uint32_t offset, uint32_t xfer_length,
 178     idm_buf_cb_t idb_buf_cb, void *cb_arg);
 179 
 180 /*
 181  * Buffer services
 182  */
 183 
 184 idm_buf_t *
 185 idm_buf_alloc(idm_conn_t *ic, void *bufptr, uint64_t buflen);
 186 
 187 void
 188 idm_buf_free(idm_buf_t *idb);
 189 
 190 void
 191 idm_buf_bind_in(idm_task_t *idt, idm_buf_t *buf);
 192 
 193 void
 194 idm_buf_bind_out(idm_task_t *idt, idm_buf_t *buf);
 195 
 196 void
 197 idm_buf_unbind_in(idm_task_t *idt, idm_buf_t *buf);
 198 
 199 void
 200 idm_buf_unbind_out(idm_task_t *idt, idm_buf_t *buf);
 201 
 202 idm_buf_t *
 203 idm_buf_find(void *lbuf, size_t data_offset);
 204 
 205 /*
 206  * Task services
 207  */
 208 idm_task_t *
 209 idm_task_alloc(idm_conn_t *ic);
 210 
 211 void
 212 idm_task_start(idm_task_t *idt);
 213 
 214 void
 215 idm_task_done(idm_task_t *idt);
 216 
 217 void
 218 idm_task_free(idm_task_t *idt);
 219 
 220 idm_task_t *
 221 idm_task_find(idm_conn_t *ic, uint32_t tt);
 222 
 223 /*
 224  * PDU Services
 225  */
 226 
 227 idm_pdu_t *
 228 idm_pdu_alloc(uint_t hdrlen, uint_t datalen);
 229 
 230 void
 231 idm_pdu_free(idm_pdu_t *pdu);
 232 
 233 void
 234 idm_pdu_init(idm_pdu_t *pdu, idm_conn_t *ic, void *private, idm_pdu_cb_t *cb);
 235 
 236 void
 237 idm_pdu_init_hdr(idm_pdu_t *pdu, uint8_t *hdr, uint_t hdrlen);
 238 
 239 void
 240 idm_pdu_init_data(idm_pdu_t *pdu, uint8_t *data, uint_t datalen);
 241 
 242 void
 243 idm_pdu_complete(idm_pdu_t *pdu, idm_status_t status);
 244 
 245 void
 246 idm_pdu_tx(idm_pdu_t *pdu);
 247 
 248 
 249 #ifdef  __cplusplus
 250 }
 251 #endif
 252 
 253 #endif /* _IDM_H */