--- /dev/null Fri Apr 4 13:31:05 2008 +++ new/src/sun_nws/idm/hdrs/idm.h Fri Apr 4 13:31:05 2008 @@ -0,0 +1,253 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at src/sun_nws/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at src/sun_nws/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + +/* + * Copyright 2008 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#ifndef _IDM_H +#define _IDM_H + +#pragma ident "@(#)idm.h 1.13 08/03/26 SMI" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum { + IDM_STATUS_SUCCESS = 0, + IDM_STATUS_FAIL, + IDM_STATUS_NORESOURCES, + IDM_STATUS_REJECT, + IDM_STATUS_IO, + IDM_STATUS_HEADER_DIGEST, + IDM_STATUS_DATA_DIGEST, + IDM_STATUS_PROTOCOL_ERROR +} idm_status_t; + +typedef enum { + CN_CONNECT_ACCEPT = 1, /* Target only */ + CN_LOGIN_FAIL, /* Target only */ +#if 0 + CN_READY_FOR_LOGIN, /* Initiator only */ +#endif + CN_FFM_ENABLED, + CN_FFM_DISABLED, + CN_CONNECT_DESTROY +} idm_client_notify_t; + +/* + * Request structures + */ + +/* Defined in idm_impl.h */ +struct idm_conn_s; +struct idm_svc_s; +struct idm_buf_s; +struct idm_pdu_s; +struct idm_task_s; + +typedef idm_status_t (idm_client_notify_cb_t)( + struct idm_conn_s *ic, idm_client_notify_t cn, uintptr_t data); + +typedef void (idm_rx_pdu_cb_t)(struct idm_conn_s *ic, struct idm_pdu_s *pdu); + +typedef void (idm_rx_pdu_error_cb_t)(struct idm_conn_s *ic, + struct idm_pdu_s *pdu, idm_status_t status); + +typedef void (idm_buf_cb_t)(struct idm_buf_s *idb, idm_status_t status); + +typedef void (idm_pdu_cb_t)(struct idm_pdu_s *pdu, idm_status_t status); + +typedef void (idm_task_cb_t)(struct idm_task_s *task, idm_status_t status); + +typedef void (idm_build_hdr_cb_t)( + struct idm_task_s *task, struct idm_pdu_s *pdu, uint8_t opcode); + +typedef struct { + idm_rx_pdu_cb_t *icb_rx_scsi_cmd; + idm_rx_pdu_cb_t *icb_rx_scsi_rsp; + idm_rx_pdu_cb_t *icb_rx_misc; + idm_rx_pdu_error_cb_t *icb_rx_error; + idm_task_cb_t *icb_task_aborted; + idm_client_notify_cb_t *icb_client_notify; + idm_build_hdr_cb_t *icb_build_hdr; +} idm_conn_ops_t; + +typedef struct { + int cr_domain; + int cr_type; + int cr_protocol; + boolean_t cr_bound; + struct sockaddr cr_bound_addr; + struct sockaddr cr_ini_dst_addr; + idm_conn_ops_t icr_conn_ops; +} idm_conn_req_t; + +typedef struct { + uint16_t sr_port; + idm_conn_ops_t sr_conn_ops; +} idm_svc_req_t; + +#include +#include +#include +#include +#include + +/* + * iSCSI Initiator Services + */ + +idm_status_t +idm_ini_conn_create(idm_conn_req_t *cr, idm_conn_t **new_con); + +idm_status_t +idm_ini_conn_connect(idm_conn_t *ic); + +void +idm_ini_conn_disconnect(idm_conn_t *ic); + +void +idm_ini_conn_destroy(idm_conn_t *ic); + +/* + * iSCSI Target Services + */ + +idm_status_t +idm_tgt_svc_create(idm_svc_req_t *sr, idm_svc_t **new_svc); + +idm_status_t +idm_tgt_svc_online(idm_svc_t *is); + +void +idm_tgt_svc_offline(idm_svc_t *is); + +void +idm_tgt_svc_destroy(idm_svc_t *is); + +idm_svc_t * +idm_tgt_svc_lookup(uint16_t port); + +void +idm_tgt_svc_rele(idm_svc_t *is); + +idm_status_t +idm_tgt_conn_accept(idm_conn_t *ic); + +void +idm_tgt_conn_reject(idm_conn_t *ic); + +void +idm_conn_hold(idm_conn_t *ic); + +void +idm_conn_rele(idm_conn_t *ic); + +/* + * Target data transfer services + */ +idm_status_t +idm_buf_tx_to_ini(idm_task_t *idt, idm_buf_t *idb, + uint32_t offset, uint32_t xfer_length, + idm_buf_cb_t idb_buf_cb, void *cb_arg); + +idm_status_t +idm_buf_rx_from_ini(idm_task_t *idt, idm_buf_t *idb, + uint32_t offset, uint32_t xfer_length, + idm_buf_cb_t idb_buf_cb, void *cb_arg); + +/* + * Buffer services + */ + +idm_buf_t * +idm_buf_alloc(idm_conn_t *ic, void *bufptr, uint64_t buflen); + +void +idm_buf_free(idm_buf_t *idb); + +void +idm_buf_bind_in(idm_task_t *idt, idm_buf_t *buf); + +void +idm_buf_bind_out(idm_task_t *idt, idm_buf_t *buf); + +void +idm_buf_unbind_in(idm_task_t *idt, idm_buf_t *buf); + +void +idm_buf_unbind_out(idm_task_t *idt, idm_buf_t *buf); + +idm_buf_t * +idm_buf_find(void *lbuf, size_t data_offset); + +/* + * Task services + */ +idm_task_t * +idm_task_alloc(idm_conn_t *ic); + +void +idm_task_start(idm_task_t *idt); + +void +idm_task_done(idm_task_t *idt); + +void +idm_task_free(idm_task_t *idt); + +idm_task_t * +idm_task_find(idm_conn_t *ic, uint32_t tt); + +/* + * PDU Services + */ + +idm_pdu_t * +idm_pdu_alloc(uint_t hdrlen, uint_t datalen); + +void +idm_pdu_free(idm_pdu_t *pdu); + +void +idm_pdu_init(idm_pdu_t *pdu, idm_conn_t *ic, void *private, idm_pdu_cb_t *cb); + +void +idm_pdu_init_hdr(idm_pdu_t *pdu, uint8_t *hdr, uint_t hdrlen); + +void +idm_pdu_init_data(idm_pdu_t *pdu, uint8_t *data, uint_t datalen); + +void +idm_pdu_complete(idm_pdu_t *pdu, idm_status_t status); + +void +idm_pdu_tx(idm_pdu_t *pdu); + + +#ifdef __cplusplus +} +#endif + +#endif /* _IDM_H */