xref: /netbsd-src/external/bsd/iscsi/dist/include/initiator.h (revision c8be037fd17b6255f9f4b310c5abfeca7964c90a)
1 /*
2  * IMPORTANT:  READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
3  * By downloading, copying, installing or using the software you agree
4  * to this license.  If you do not agree to this license, do not
5  * download, install, copy or use the software.
6  *
7  * Intel License Agreement
8  *
9  * Copyright (c) 2000, Intel Corporation
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  *
16  * -Redistributions of source code must retain the above copyright
17  *  notice, this list of conditions and the following disclaimer.
18  *
19  * -Redistributions in binary form must reproduce the above copyright
20  *  notice, this list of conditions and the following disclaimer in the
21  *  documentation and/or other materials provided with the
22  *  distribution.
23  *
24  * -The name of Intel Corporation may not be used to endorse or
25  *  promote products derived from this software without specific prior
26  *  written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL INTEL
32  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
35  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
38  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39  * SUCH DAMAGE.
40  */
41 #ifndef _INITIATOR_H_
42 #define _INITIATOR_H_
43 
44 #include "iscsiprotocol.h"
45 #include "parameters.h"
46 #include "defs.h"
47 
48 #ifndef CONFIG_INITIATOR_NUM_TARGETS
49 #define CONFIG_INITIATOR_NUM_TARGETS 16
50 #endif
51 
52 /***********
53  * Private *
54  ***********/
55 
56 #define CONFIG_INITIATOR_QUEUE_DEPTH  CONFIG_INITIATOR_NUM_TARGETS
57 #define CONFIG_INITIATOR_MAX_SESSIONS CONFIG_INITIATOR_NUM_TARGETS
58 
59 enum {
60 	INITIATOR_SESSION_STATE_INITIALIZING =		0x001,
61 	INITIATOR_SESSION_STATE_INITIALIZED =		0x002,
62 	INITIATOR_SESSION_STATE_CONNECTING =		0x004,
63 	INITIATOR_SESSION_STATE_CONNECTED =		0x008,
64 	INITIATOR_SESSION_STATE_LOGGING_IN =		0x010,
65 	INITIATOR_SESSION_STATE_AUTHENTICATED =		0x020,
66 	INITIATOR_SESSION_STATE_LOGGED_IN_NORMAL =	0x040,
67 	INITIATOR_SESSION_STATE_LOGGED_IN_DISCOVERY =	0x080,
68 	INITIATOR_SESSION_STATE_LOGGING_OUT =		0x100,
69 	INITIATOR_SESSION_STATE_LOGGED_OUT =		0x200,
70 	INITIATOR_SESSION_STATE_DESTROYING =		0x400
71 };
72 
73 enum {
74 	TARGET_HOSTNAME_SIZE = 1024,
75 	TARGET_IP_SIZE = 16,
76 	TARGET_NAME_SIZE = 256
77 };
78 
79 #define INITIATOR_STATE_SHUTDOWN 1
80 
81 typedef struct {
82 	iscsi_mutex_t   mutex;
83 	iscsi_cond_t    cond;
84 } initiator_wait_t;
85 
86 typedef struct initiator_session_t {
87 	int		sock;
88 	uint32_t        CmdSN;
89 	uint32_t        ExpStatSN;
90 	uint32_t        MaxCmdSN;
91 	iscsi_queue_t   tx_queue;
92 	iscsi_worker_t  tx_worker;
93 	iscsi_worker_t  rx_worker;
94 	uint64_t        isid;
95 	int             tsih;
96 	int             cid;
97 	uint32_t        state;
98 	iscsi_parameter_t *params;
99 	struct initiator_cmd_t *cmds;
100 	iscsi_spin_t    cmds_spin;
101 	iscsi_sess_param_t sess_params;
102 } initiator_session_t;
103 
104 typedef struct initiator_cmd_t {
105 	void           *ptr;
106 	int             type;
107 	int             (*callback) (void *);
108 	void           *callback_arg;
109 	uint64_t        isid;
110 	int             tx_done;
111 	int             status;
112 	struct initiator_cmd_t *next;
113 	struct initiator_cmd_t *hash_next;
114 	uint32_t        key;
115 	char            targetname[TARGET_HOSTNAME_SIZE];
116 } initiator_cmd_t;
117 
118 DEFINE_ARRAY(strv_t, char *);
119 
120 typedef struct initiator_target_t {
121 	char            name[TARGET_HOSTNAME_SIZE];
122 	char            ip[TARGET_IP_SIZE];
123 	int             port;
124 	char            TargetName[TARGET_NAME_SIZE];
125 	initiator_session_t *sess;
126 	int             has_session;
127 	char		iqnwanted[TARGET_NAME_SIZE];
128 	strv_t		all_targets;
129 } initiator_target_t;
130 
131 
132 /**********
133  * Public *
134  **********/
135 
136 int initiator_command(initiator_cmd_t *);
137 int initiator_enqueue(initiator_cmd_t *);
138 int initiator_abort(initiator_cmd_t *);
139 
140 void		get_target_info(uint64_t, initiator_target_t *);
141 
142 int		ii_initiator_init(const char *, int, int, const char *, char *, int, int, int);
143 
144 int		iscsi_initiator_get_targets(int, strv_t *);
145 int		initiator_set_target_name(int, char *);
146 int		iscsi_initiator_get_max_targets(void);
147 
148 #endif				/* _INITIATOR_H_ */
149