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.
8 * You can obtain a copy of the license at usr/src/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.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/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]
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
35 IDM_STATUS_SUCCESS
= 0,
37 IDM_STATUS_NORESOURCES
,
42 IDM_STATUS_HEADER_DIGEST
,
43 IDM_STATUS_DATA_DIGEST
,
44 IDM_STATUS_PROTOCOL_ERROR
48 CN_CONNECT_ACCEPT
= 1, /* Target only */
49 CN_LOGIN_FAIL
, /* Target only */
50 CN_READY_FOR_LOGIN
, /* Initiator only */
55 } idm_client_notify_t
;
80 #ifdef IDM_TASK_SM_STRINGS
81 static const char *idm_ts_name
[TASK_MAX_STATE
+1] = {
95 KV_HANDLED_NO_TRANSIT
,
109 /* Defined in idm_impl.h */
116 typedef idm_status_t (idm_client_notify_cb_t
)(
117 struct idm_conn_s
*ic
, idm_client_notify_t cn
, uintptr_t data
);
119 typedef void (idm_rx_pdu_cb_t
)(struct idm_conn_s
*ic
, struct idm_pdu_s
*pdu
);
121 typedef void (idm_rx_pdu_error_cb_t
)(struct idm_conn_s
*ic
,
122 struct idm_pdu_s
*pdu
, idm_status_t status
);
124 typedef void (idm_buf_cb_t
)(struct idm_buf_s
*idb
, idm_status_t status
);
126 typedef void (idm_pdu_cb_t
)(struct idm_pdu_s
*pdu
, idm_status_t status
);
128 typedef void (idm_task_cb_t
)(struct idm_task_s
*task
, idm_status_t status
);
130 typedef void (idm_build_hdr_cb_t
)(
131 struct idm_task_s
*task
, struct idm_pdu_s
*pdu
, uint8_t opcode
);
133 typedef union idm_sockaddr
{
135 struct sockaddr_in sin4
;
136 struct sockaddr_in6 sin6
;
139 #define SIZEOF_SOCKADDR(so) \
140 ((so)->sa_family == AF_INET ? \
141 sizeof (struct sockaddr_in) : sizeof (struct sockaddr_in6))
144 idm_rx_pdu_cb_t
*icb_rx_scsi_cmd
;
145 idm_rx_pdu_cb_t
*icb_rx_scsi_rsp
;
146 idm_rx_pdu_cb_t
*icb_rx_misc
;
147 idm_rx_pdu_error_cb_t
*icb_rx_error
;
148 idm_task_cb_t
*icb_task_aborted
;
149 idm_client_notify_cb_t
*icb_client_notify
;
150 idm_build_hdr_cb_t
*icb_build_hdr
;
158 idm_sockaddr_t cr_bound_addr
;
159 idm_sockaddr_t cr_ini_dst_addr
;
161 idm_conn_ops_t icr_conn_ops
;
167 idm_conn_ops_t sr_conn_ops
;
171 /* This is not how other networking code handles this */
177 /* i_insize determines which is valid in the union above */
188 uint32_t al_vers
, /* In */
190 uint32_t al_in_cnt
; /* In */
191 uint32_t al_out_cnt
; /* Out */
192 uint32_t al_tpgt
; /* Out */
193 idm_addr_t al_addrs
[1]; /* Out */
197 * State machine auditing
200 #define SM_AUDIT_BUF_MAX_REC 32
206 } sm_audit_record_type_t
;
215 } sm_audit_sm_type_t
;
218 timespec_t sar_timestamp
;
219 sm_audit_sm_type_t sar_sm_type
;
220 sm_audit_record_type_t sar_type
;
222 int sar_new_state
; /* Only for SAR_STATE_CHANGE */
223 int sar_event
; /* Only for SAR_STATE_EVENT */
224 uintptr_t sar_event_info
; /* Only for SAR_STATE_EVENT */
230 sm_audit_record_t sab_records
[SM_AUDIT_BUF_MAX_REC
];
233 extern boolean_t idm_sm_logging
;
234 extern boolean_t idm_conn_logging
;
235 extern boolean_t idm_svc_logging
;
237 #define IDM_SM_LOG if (idm_sm_logging) cmn_err
238 #define IDM_CONN_LOG if (idm_conn_logging) cmn_err
239 #define IDM_SVC_LOG if (idm_svc_logging) cmn_err
241 void idm_sm_audit_init(sm_audit_buf_t
*audit_buf
);
243 void idm_sm_audit_event(sm_audit_buf_t
*audit_buf
,
244 sm_audit_sm_type_t sm_type
,
245 int state
, int event
, uintptr_t event_info
);
247 void idm_sm_audit_state_change(sm_audit_buf_t
*audit_buf
,
248 sm_audit_sm_type_t sm_type
, int state
, int new_state
);
251 #include <sys/iscsi_protocol.h>
252 #include <sys/idm/idm_conn_sm.h>
253 #include <sys/idm/idm_transport.h>
254 #include <sys/idm/idm_impl.h>
255 #include <sys/idm/idm_text.h>
256 #include <sys/idm/idm_so.h>
259 * iSCSI Initiator Services
263 idm_ini_conn_create(idm_conn_req_t
*cr
, idm_conn_t
**new_con
);
266 idm_ini_conn_connect(idm_conn_t
*ic
);
269 idm_ini_conn_disconnect(idm_conn_t
*ic
);
272 idm_ini_conn_destroy(idm_conn_t
*ic
);
275 * iSCSI Target Services
279 idm_tgt_svc_create(idm_svc_req_t
*sr
, idm_svc_t
**new_svc
);
282 idm_tgt_svc_online(idm_svc_t
*is
);
285 idm_tgt_svc_offline(idm_svc_t
*is
);
288 idm_tgt_svc_destroy(idm_svc_t
*is
);
291 idm_tgt_svc_destroy_if_unref(idm_svc_t
*is
);
294 idm_tgt_svc_lookup(uint16_t port
);
297 idm_tgt_svc_hold(idm_svc_t
*is
);
300 idm_tgt_svc_rele_and_destroy(idm_svc_t
*is
);
303 idm_tgt_conn_accept(idm_conn_t
*ic
);
306 idm_tgt_conn_reject(idm_conn_t
*ic
);
309 idm_conn_hold(idm_conn_t
*ic
);
312 idm_conn_rele(idm_conn_t
*ic
);
315 * Target data transfer services
318 idm_buf_tx_to_ini(idm_task_t
*idt
, idm_buf_t
*idb
,
319 uint32_t offset
, uint32_t xfer_length
,
320 idm_buf_cb_t idb_buf_cb
, void *cb_arg
);
323 idm_buf_rx_from_ini(idm_task_t
*idt
, idm_buf_t
*idb
,
324 uint32_t offset
, uint32_t xfer_length
,
325 idm_buf_cb_t idb_buf_cb
, void *cb_arg
);
328 idm_buf_tx_to_ini_done(idm_task_t
*idt
, idm_buf_t
*idb
, idm_status_t status
);
331 idm_buf_rx_from_ini_done(idm_task_t
*idt
, idm_buf_t
*idb
, idm_status_t status
);
334 * Shared Initiator/Target Services
337 idm_negotiate_key_values(idm_conn_t
*ic
, nvlist_t
*request_nvl
,
338 nvlist_t
*response_nvl
, nvlist_t
*negotiated_nvl
);
341 idm_notice_key_values(idm_conn_t
*ic
, nvlist_t
*negotiated_nvl
);
348 idm_buf_alloc(idm_conn_t
*ic
, void *bufptr
, uint64_t buflen
);
351 idm_buf_free(idm_buf_t
*idb
);
354 idm_buf_bind_in(idm_task_t
*idt
, idm_buf_t
*buf
);
357 idm_buf_bind_out(idm_task_t
*idt
, idm_buf_t
*buf
);
360 idm_buf_unbind_in(idm_task_t
*idt
, idm_buf_t
*buf
);
363 idm_buf_unbind_out(idm_task_t
*idt
, idm_buf_t
*buf
);
366 idm_buf_find(void *lbuf
, size_t data_offset
);
372 idm_task_alloc(idm_conn_t
*ic
);
375 idm_task_start(idm_task_t
*idt
, uintptr_t handle
);
378 idm_task_abort(idm_conn_t
*ic
, idm_task_t
*idt
, idm_abort_type_t abort_type
);
381 idm_task_cleanup(idm_task_t
*idt
);
384 idm_task_done(idm_task_t
*idt
);
387 idm_task_free(idm_task_t
*idt
);
390 idm_task_find(idm_conn_t
*ic
, uint32_t itt
, uint32_t ttt
);
393 idm_task_find_by_handle(idm_conn_t
*ic
, uintptr_t handle
);
396 idm_task_hold(idm_task_t
*idt
);
399 idm_task_rele(idm_task_t
*idt
);
406 idm_pdu_alloc(uint_t hdrlen
, uint_t datalen
);
409 idm_pdu_free(idm_pdu_t
*pdu
);
412 idm_pdu_init(idm_pdu_t
*pdu
, idm_conn_t
*ic
, void *private, idm_pdu_cb_t
*cb
);
415 idm_pdu_init_hdr(idm_pdu_t
*pdu
, uint8_t *hdr
, uint_t hdrlen
);
418 idm_pdu_init_data(idm_pdu_t
*pdu
, uint8_t *data
, uint_t datalen
);
421 idm_pdu_complete(idm_pdu_t
*pdu
, idm_status_t status
);
424 idm_pdu_tx(idm_pdu_t
*pdu
);
427 * Object reference tracking
431 idm_refcnt_init(idm_refcnt_t
*refcnt
, void *referenced_obj
);
434 idm_refcnt_destroy(idm_refcnt_t
*refcnt
);
437 idm_refcnt_reset(idm_refcnt_t
*refcnt
);
440 idm_refcnt_hold(idm_refcnt_t
*refcnt
);
443 idm_refcnt_rele(idm_refcnt_t
*refcnt
);
446 idm_refcnt_rele_and_destroy(idm_refcnt_t
*refcnt
, idm_refcnt_cb_t
*cb_func
);
449 idm_refcnt_wait_ref(idm_refcnt_t
*refcnt
);
452 idm_refcnt_async_wait_ref(idm_refcnt_t
*refcnt
, idm_refcnt_cb_t
*cb_func
);