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 2009 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
,
50 CN_CONNECT_ACCEPT
= 1, /* Target only */
52 CN_READY_FOR_LOGIN
, /* Initiator only */
59 } idm_client_notify_t
;
61 #ifdef IDM_CN_NOTIFY_STRINGS
62 static const char *idm_cn_strings
[CN_MAX
+ 1] = {
99 #ifdef IDM_TASK_SM_STRINGS
100 static const char *idm_ts_name
[TASK_MAX_STATE
+1] = {
114 KV_HANDLED_NO_TRANSIT
,
128 /* Defined in idm_impl.h */
135 typedef idm_status_t (idm_client_notify_cb_t
)(
136 struct idm_conn_s
*ic
, idm_client_notify_t cn
, uintptr_t data
);
138 typedef void (idm_rx_pdu_cb_t
)(struct idm_conn_s
*ic
, struct idm_pdu_s
*pdu
);
140 typedef void (idm_rx_pdu_error_cb_t
)(struct idm_conn_s
*ic
,
141 struct idm_pdu_s
*pdu
, idm_status_t status
);
143 typedef void (idm_buf_cb_t
)(struct idm_buf_s
*idb
, idm_status_t status
);
145 typedef void (idm_pdu_cb_t
)(struct idm_pdu_s
*pdu
, idm_status_t status
);
147 typedef void (idm_task_cb_t
)(struct idm_task_s
*task
, idm_status_t status
);
149 typedef void (idm_build_hdr_cb_t
)(
150 struct idm_task_s
*task
, struct idm_pdu_s
*pdu
, uint8_t opcode
);
152 typedef void (idm_update_statsn_cb_t
)(
153 struct idm_task_s
*task
, struct idm_pdu_s
*pdu
);
155 typedef void (idm_keepalive_cb_t
)(struct idm_conn_s
*ic
);
157 typedef union idm_sockaddr
{
159 struct sockaddr_in sin4
;
160 struct sockaddr_in6 sin6
;
163 #define SIZEOF_SOCKADDR(so) \
164 ((so)->sa_family == AF_INET ? \
165 sizeof (struct sockaddr_in) : sizeof (struct sockaddr_in6))
168 idm_rx_pdu_cb_t
*icb_rx_scsi_cmd
;
169 idm_rx_pdu_cb_t
*icb_rx_scsi_rsp
;
170 idm_rx_pdu_cb_t
*icb_rx_misc
;
171 idm_rx_pdu_error_cb_t
*icb_rx_error
;
172 idm_task_cb_t
*icb_task_aborted
;
173 idm_client_notify_cb_t
*icb_client_notify
;
174 idm_build_hdr_cb_t
*icb_build_hdr
;
175 idm_update_statsn_cb_t
*icb_update_statsn
; /* advance statsn */
176 idm_keepalive_cb_t
*icb_keepalive
;
184 idm_sockaddr_t cr_bound_addr
;
185 idm_sockaddr_t cr_ini_dst_addr
;
187 idm_conn_ops_t icr_conn_ops
;
188 boolean_t cr_boot_conn
;
194 idm_conn_ops_t sr_conn_ops
;
198 /* This is not how other networking code handles this */
204 /* i_insize determines which is valid in the union above */
215 uint32_t al_vers
, /* In */
217 uint32_t al_in_cnt
; /* In */
218 uint32_t al_out_cnt
; /* Out */
219 uint32_t al_tpgt
; /* Out */
220 idm_addr_t al_addrs
[1]; /* Out */
224 * State machine auditing
227 #define SM_AUDIT_BUF_MAX_REC 32
233 } sm_audit_record_type_t
;
246 } sm_audit_sm_type_t
;
249 timespec_t sar_timestamp
;
250 sm_audit_sm_type_t sar_sm_type
;
251 sm_audit_record_type_t sar_type
;
253 int sar_new_state
; /* Only for SAR_STATE_CHANGE */
254 int sar_event
; /* Only for SAR_STATE_EVENT */
255 uintptr_t sar_event_info
; /* Only for SAR_STATE_EVENT */
261 sm_audit_record_t sab_records
[SM_AUDIT_BUF_MAX_REC
];
264 extern boolean_t idm_sm_logging
;
265 extern boolean_t idm_conn_logging
;
266 extern boolean_t idm_svc_logging
;
268 #define IDM_SM_LOG if (idm_sm_logging) cmn_err
269 #define IDM_CONN_LOG if (idm_conn_logging) cmn_err
270 #define IDM_SVC_LOG if (idm_svc_logging) cmn_err
272 void idm_sm_audit_init(sm_audit_buf_t
*audit_buf
);
274 void idm_sm_audit_event(sm_audit_buf_t
*audit_buf
,
275 sm_audit_sm_type_t sm_type
,
276 int state
, int event
, uintptr_t event_info
);
278 void idm_sm_audit_state_change(sm_audit_buf_t
*audit_buf
,
279 sm_audit_sm_type_t sm_type
, int state
, int new_state
);
282 #include <sys/iscsi_protocol.h>
283 #include <sys/idm/idm_conn_sm.h>
284 #include <sys/idm/idm_transport.h>
285 #include <sys/idm/idm_impl.h>
286 #include <sys/idm/idm_text.h>
287 #include <sys/idm/idm_so.h>
290 * iSCSI Initiator Services
294 idm_ini_conn_create(idm_conn_req_t
*cr
, idm_conn_t
**new_con
);
297 idm_ini_conn_connect(idm_conn_t
*ic
);
300 idm_ini_conn_disconnect(idm_conn_t
*ic
);
303 idm_ini_conn_disconnect_sync(idm_conn_t
*ic
);
306 idm_ini_conn_destroy(idm_conn_t
*ic
);
309 * iSCSI Target Services
313 idm_tgt_svc_create(idm_svc_req_t
*sr
, idm_svc_t
**new_svc
);
316 idm_tgt_svc_online(idm_svc_t
*is
);
319 idm_tgt_svc_offline(idm_svc_t
*is
);
322 idm_tgt_svc_destroy(idm_svc_t
*is
);
325 idm_tgt_svc_destroy_if_unref(idm_svc_t
*is
);
328 idm_tgt_svc_lookup(uint16_t port
);
331 idm_tgt_svc_hold(idm_svc_t
*is
);
334 idm_tgt_svc_rele_and_destroy(idm_svc_t
*is
);
337 idm_tgt_conn_accept(idm_conn_t
*ic
);
340 idm_tgt_conn_reject(idm_conn_t
*ic
);
343 idm_conn_hold(idm_conn_t
*ic
);
346 idm_conn_rele(idm_conn_t
*ic
);
349 idm_conn_set_target_name(idm_conn_t
*ic
, char *target_name
);
352 idm_conn_set_initiator_name(idm_conn_t
*ic
, char *initiator_name
);
355 idm_conn_set_isid(idm_conn_t
*ic
, uint8_t isid
[ISCSI_ISID_LEN
]);
358 * Target data transfer services
361 idm_buf_tx_to_ini(idm_task_t
*idt
, idm_buf_t
*idb
,
362 uint32_t offset
, uint32_t xfer_length
,
363 idm_buf_cb_t idb_buf_cb
, void *cb_arg
);
366 idm_buf_rx_from_ini(idm_task_t
*idt
, idm_buf_t
*idb
,
367 uint32_t offset
, uint32_t xfer_length
,
368 idm_buf_cb_t idb_buf_cb
, void *cb_arg
);
371 idm_buf_tx_to_ini_done(idm_task_t
*idt
, idm_buf_t
*idb
, idm_status_t status
);
374 idm_buf_rx_from_ini_done(idm_task_t
*idt
, idm_buf_t
*idb
, idm_status_t status
);
376 #define XFER_BUF_TX_TO_INI 0
377 #define XFER_BUF_RX_FROM_INI 1
379 * Shared Initiator/Target Services
382 idm_negotiate_key_values(idm_conn_t
*ic
, nvlist_t
*request_nvl
,
383 nvlist_t
*response_nvl
, nvlist_t
*negotiated_nvl
);
386 idm_notice_key_values(idm_conn_t
*ic
, nvlist_t
*negotiated_nvl
);
389 idm_declare_key_values(idm_conn_t
*ic
, nvlist_t
*config_nvl
,
390 nvlist_t
*outgoing_nvl
);
397 idm_buf_alloc(idm_conn_t
*ic
, void *bufptr
, uint64_t buflen
);
400 idm_buf_free(idm_buf_t
*idb
);
403 idm_buf_bind_in(idm_task_t
*idt
, idm_buf_t
*buf
);
406 idm_buf_bind_out(idm_task_t
*idt
, idm_buf_t
*buf
);
409 idm_buf_unbind_in(idm_task_t
*idt
, idm_buf_t
*buf
);
412 idm_buf_unbind_out(idm_task_t
*idt
, idm_buf_t
*buf
);
415 idm_buf_find(void *lbuf
, size_t data_offset
);
418 idm_bufpat_set(idm_buf_t
*idb
);
421 idm_bufpat_check(idm_buf_t
*idb
, int check_len
, idm_bufpat_check_type_t type
);
423 extern boolean_t idm_pattern_checking
;
425 #define IDM_BUFPAT_SET(CHK_BUF) \
426 if (idm_pattern_checking && (CHK_BUF)->idb_bufalloc) { \
427 idm_bufpat_set(CHK_BUF); \
430 #define IDM_BUFPAT_CHECK(CHK_BUF, CHK_LEN, CHK_TYPE) \
431 if (idm_pattern_checking) { \
432 (void) idm_bufpat_check(CHK_BUF, CHK_LEN, CHK_TYPE); \
439 idm_task_alloc(idm_conn_t
*ic
);
442 idm_task_start(idm_task_t
*idt
, uintptr_t handle
);
445 idm_task_abort(idm_conn_t
*ic
, idm_task_t
*idt
, idm_abort_type_t abort_type
);
448 idm_task_cleanup(idm_task_t
*idt
);
451 idm_task_done(idm_task_t
*idt
);
454 idm_task_free(idm_task_t
*idt
);
457 idm_task_find(idm_conn_t
*ic
, uint32_t itt
, uint32_t ttt
);
460 idm_task_find_and_complete(idm_conn_t
*ic
, uint32_t itt
, uint32_t ttt
);
463 idm_task_find_by_handle(idm_conn_t
*ic
, uintptr_t handle
);
466 idm_task_hold(idm_task_t
*idt
);
469 idm_task_rele(idm_task_t
*idt
);
476 idm_pdu_alloc(uint_t hdrlen
, uint_t datalen
);
479 idm_pdu_alloc_nosleep(uint_t hdrlen
, uint_t datalen
);
482 idm_pdu_free(idm_pdu_t
*pdu
);
485 idm_pdu_init(idm_pdu_t
*pdu
, idm_conn_t
*ic
, void *private, idm_pdu_cb_t
*cb
);
488 idm_pdu_init_hdr(idm_pdu_t
*pdu
, uint8_t *hdr
, uint_t hdrlen
);
491 idm_pdu_init_data(idm_pdu_t
*pdu
, uint8_t *data
, uint_t datalen
);
494 idm_pdu_complete(idm_pdu_t
*pdu
, idm_status_t status
);
497 idm_pdu_tx(idm_pdu_t
*pdu
);
500 * Object reference tracking
504 idm_refcnt_init(idm_refcnt_t
*refcnt
, void *referenced_obj
);
507 idm_refcnt_destroy(idm_refcnt_t
*refcnt
);
510 idm_refcnt_reset(idm_refcnt_t
*refcnt
);
513 idm_refcnt_hold(idm_refcnt_t
*refcnt
);
516 idm_refcnt_rele(idm_refcnt_t
*refcnt
);
519 idm_refcnt_rele_and_destroy(idm_refcnt_t
*refcnt
, idm_refcnt_cb_t
*cb_func
);
522 idm_refcnt_wait_ref(idm_refcnt_t
*refcnt
);
525 idm_refcnt_async_wait_ref(idm_refcnt_t
*refcnt
, idm_refcnt_cb_t
*cb_func
);