6811333 Remove prom_printf() message in emlxs driver
[opensolaris.git] / usr / src / uts / common / sys / idm / idm.h
blobf93defdfcdf8254e4cc1af8a03829aafbfd0d490
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #ifndef _IDM_H
28 #define _IDM_H
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
34 typedef enum {
35 IDM_STATUS_SUCCESS = 0,
36 IDM_STATUS_FAIL,
37 IDM_STATUS_NORESOURCES,
38 IDM_STATUS_REJECT,
39 IDM_STATUS_IO,
40 IDM_STATUS_ABORTED,
41 IDM_STATUS_SUSPENDED,
42 IDM_STATUS_HEADER_DIGEST,
43 IDM_STATUS_DATA_DIGEST,
44 IDM_STATUS_PROTOCOL_ERROR
45 } idm_status_t;
47 typedef enum {
48 CN_CONNECT_ACCEPT = 1, /* Target only */
49 CN_LOGIN_FAIL, /* Target only */
50 CN_READY_FOR_LOGIN, /* Initiator only */
51 CN_FFP_ENABLED,
52 CN_FFP_DISABLED,
53 CN_CONNECT_LOST,
54 CN_CONNECT_DESTROY
55 } idm_client_notify_t;
57 typedef enum {
58 FD_CONN_FAIL,
59 FD_CONN_LOGOUT,
60 FD_SESS_LOGOUT
61 } idm_ffp_disable_t;
63 typedef enum {
64 AT_INTERNAL_SUSPEND,
65 AT_INTERNAL_ABORT,
66 AT_TASK_MGMT_ABORT
67 } idm_abort_type_t;
69 typedef enum {
70 TASK_IDLE,
71 TASK_ACTIVE,
72 TASK_SUSPENDING,
73 TASK_SUSPENDED,
74 TASK_ABORTING,
75 TASK_ABORTED,
76 TASK_COMPLETE,
77 TASK_MAX_STATE
78 } idm_task_state_t;
80 #ifdef IDM_TASK_SM_STRINGS
81 static const char *idm_ts_name[TASK_MAX_STATE+1] = {
82 "TASK_IDLE",
83 "TASK_ACTIVE",
84 "TASK_SUSPENDING",
85 "TASK_SUSPENDED",
86 "TASK_ABORTING",
87 "TASK_ABORTED",
88 "TASK_COMPLETE",
89 "TASK_MAX_STATE"
91 #endif
93 typedef enum {
94 KV_HANDLED = 0,
95 KV_HANDLED_NO_TRANSIT,
96 KV_UNHANDLED,
97 KV_TARGET_ONLY,
98 KV_NO_RESOURCES,
99 KV_INTERNAL_ERROR,
100 KV_VALUE_ERROR,
101 KV_MISSING_FIELDS,
102 KV_AUTH_FAILED
103 } kv_status_t;
106 * Request structures
109 /* Defined in idm_impl.h */
110 struct idm_conn_s;
111 struct idm_svc_s;
112 struct idm_buf_s;
113 struct idm_pdu_s;
114 struct idm_task_s;
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 {
134 struct sockaddr sin;
135 struct sockaddr_in sin4;
136 struct sockaddr_in6 sin6;
137 } idm_sockaddr_t;
139 #define SIZEOF_SOCKADDR(so) \
140 ((so)->sa_family == AF_INET ? \
141 sizeof (struct sockaddr_in) : sizeof (struct sockaddr_in6))
143 typedef struct {
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;
151 } idm_conn_ops_t;
153 typedef struct {
154 int cr_domain;
155 int cr_type;
156 int cr_protocol;
157 boolean_t cr_bound;
158 idm_sockaddr_t cr_bound_addr;
159 idm_sockaddr_t cr_ini_dst_addr;
160 ldi_ident_t cr_li;
161 idm_conn_ops_t icr_conn_ops;
162 } idm_conn_req_t;
164 typedef struct {
165 uint16_t sr_port;
166 ldi_ident_t sr_li;
167 idm_conn_ops_t sr_conn_ops;
168 } idm_svc_req_t;
171 /* This is not how other networking code handles this */
172 typedef struct {
173 union {
174 struct in_addr in4;
175 struct in6_addr in6;
176 } i_addr;
177 /* i_insize determines which is valid in the union above */
178 int i_insize;
179 } idm_ipaddr_t;
181 typedef struct {
182 idm_ipaddr_t a_addr;
183 uint32_t a_port,
184 a_oid;
185 } idm_addr_t;
187 typedef struct {
188 uint32_t al_vers, /* In */
189 al_oid; /* 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 */
194 } idm_addr_list_t;
197 * State machine auditing
200 #define SM_AUDIT_BUF_MAX_REC 32
202 typedef enum {
203 SAR_UNDEFINED = 0,
204 SAR_STATE_EVENT,
205 SAR_STATE_CHANGE
206 } sm_audit_record_type_t;
208 typedef enum {
209 SAS_UNDEFINED = 0,
210 SAS_IDM_CONN,
211 SAS_IDM_TASK,
212 SAS_ISCSIT_TGT,
213 SAS_ISCSIT_SESS,
214 SAS_ISCSIT_LOGIN
215 } sm_audit_sm_type_t;
217 typedef struct {
218 timespec_t sar_timestamp;
219 sm_audit_sm_type_t sar_sm_type;
220 sm_audit_record_type_t sar_type;
221 int sar_state;
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 */
225 } sm_audit_record_t;
227 typedef struct {
228 int sab_index;
229 int sab_max_index;
230 sm_audit_record_t sab_records[SM_AUDIT_BUF_MAX_REC];
231 } sm_audit_buf_t;
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
262 idm_status_t
263 idm_ini_conn_create(idm_conn_req_t *cr, idm_conn_t **new_con);
265 idm_status_t
266 idm_ini_conn_connect(idm_conn_t *ic);
268 void
269 idm_ini_conn_disconnect(idm_conn_t *ic);
271 void
272 idm_ini_conn_destroy(idm_conn_t *ic);
275 * iSCSI Target Services
278 idm_status_t
279 idm_tgt_svc_create(idm_svc_req_t *sr, idm_svc_t **new_svc);
281 idm_status_t
282 idm_tgt_svc_online(idm_svc_t *is);
284 void
285 idm_tgt_svc_offline(idm_svc_t *is);
287 void
288 idm_tgt_svc_destroy(idm_svc_t *is);
290 void
291 idm_tgt_svc_destroy_if_unref(idm_svc_t *is);
293 idm_svc_t *
294 idm_tgt_svc_lookup(uint16_t port);
296 void
297 idm_tgt_svc_hold(idm_svc_t *is);
299 void
300 idm_tgt_svc_rele_and_destroy(idm_svc_t *is);
302 idm_status_t
303 idm_tgt_conn_accept(idm_conn_t *ic);
305 void
306 idm_tgt_conn_reject(idm_conn_t *ic);
308 void
309 idm_conn_hold(idm_conn_t *ic);
311 void
312 idm_conn_rele(idm_conn_t *ic);
315 * Target data transfer services
317 idm_status_t
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);
322 idm_status_t
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);
327 void
328 idm_buf_tx_to_ini_done(idm_task_t *idt, idm_buf_t *idb, idm_status_t status);
330 void
331 idm_buf_rx_from_ini_done(idm_task_t *idt, idm_buf_t *idb, idm_status_t status);
334 * Shared Initiator/Target Services
336 kv_status_t
337 idm_negotiate_key_values(idm_conn_t *ic, nvlist_t *request_nvl,
338 nvlist_t *response_nvl, nvlist_t *negotiated_nvl);
340 idm_status_t
341 idm_notice_key_values(idm_conn_t *ic, nvlist_t *negotiated_nvl);
344 * Buffer services
347 idm_buf_t *
348 idm_buf_alloc(idm_conn_t *ic, void *bufptr, uint64_t buflen);
350 void
351 idm_buf_free(idm_buf_t *idb);
353 void
354 idm_buf_bind_in(idm_task_t *idt, idm_buf_t *buf);
356 void
357 idm_buf_bind_out(idm_task_t *idt, idm_buf_t *buf);
359 void
360 idm_buf_unbind_in(idm_task_t *idt, idm_buf_t *buf);
362 void
363 idm_buf_unbind_out(idm_task_t *idt, idm_buf_t *buf);
365 idm_buf_t *
366 idm_buf_find(void *lbuf, size_t data_offset);
369 * Task services
371 idm_task_t *
372 idm_task_alloc(idm_conn_t *ic);
374 void
375 idm_task_start(idm_task_t *idt, uintptr_t handle);
377 void
378 idm_task_abort(idm_conn_t *ic, idm_task_t *idt, idm_abort_type_t abort_type);
380 void
381 idm_task_cleanup(idm_task_t *idt);
383 void
384 idm_task_done(idm_task_t *idt);
386 void
387 idm_task_free(idm_task_t *idt);
389 idm_task_t *
390 idm_task_find(idm_conn_t *ic, uint32_t itt, uint32_t ttt);
392 void *
393 idm_task_find_by_handle(idm_conn_t *ic, uintptr_t handle);
395 void
396 idm_task_hold(idm_task_t *idt);
398 void
399 idm_task_rele(idm_task_t *idt);
402 * PDU Services
405 idm_pdu_t *
406 idm_pdu_alloc(uint_t hdrlen, uint_t datalen);
408 void
409 idm_pdu_free(idm_pdu_t *pdu);
411 void
412 idm_pdu_init(idm_pdu_t *pdu, idm_conn_t *ic, void *private, idm_pdu_cb_t *cb);
414 void
415 idm_pdu_init_hdr(idm_pdu_t *pdu, uint8_t *hdr, uint_t hdrlen);
417 void
418 idm_pdu_init_data(idm_pdu_t *pdu, uint8_t *data, uint_t datalen);
420 void
421 idm_pdu_complete(idm_pdu_t *pdu, idm_status_t status);
423 void
424 idm_pdu_tx(idm_pdu_t *pdu);
427 * Object reference tracking
430 void
431 idm_refcnt_init(idm_refcnt_t *refcnt, void *referenced_obj);
433 void
434 idm_refcnt_destroy(idm_refcnt_t *refcnt);
436 void
437 idm_refcnt_reset(idm_refcnt_t *refcnt);
439 void
440 idm_refcnt_hold(idm_refcnt_t *refcnt);
442 void
443 idm_refcnt_rele(idm_refcnt_t *refcnt);
445 void
446 idm_refcnt_rele_and_destroy(idm_refcnt_t *refcnt, idm_refcnt_cb_t *cb_func);
448 void
449 idm_refcnt_wait_ref(idm_refcnt_t *refcnt);
451 void
452 idm_refcnt_async_wait_ref(idm_refcnt_t *refcnt, idm_refcnt_cb_t *cb_func);
455 #ifdef __cplusplus
457 #endif
459 #endif /* _IDM_H */