summaryrefslogtreecommitdiff
path: root/usr/src/uts/common/sys/pppt_ic_if.h
blob: dd640d79a62f68ed2edc77b71abc3c37397a827c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
/*
 * 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 usr/src/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 usr/src/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 (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
 */
#ifndef _SYS_PPPT_IC_IF_H
#define	_SYS_PPPT_IC_IF_H

#include <sys/stmf_defines.h>

#ifdef	__cplusplus
extern "C" {
#endif

/*
 * ALUA messaging and interconnect API.
 */

/*
 * Message type.
 */
typedef enum {
	STMF_ICM_REGISTER_PROXY_PORT = 0,
	STMF_ICM_DEREGISTER_PROXY_PORT,
	STMF_ICM_REGISTER_LUN,
	STMF_ICM_DEREGISTER_LUN,
	STMF_ICM_SCSI_CMD,
	STMF_ICM_SCSI_DATA,
	STMF_ICM_SCSI_DATA_XFER_DONE,
	STMF_ICM_SCSI_STATUS,
	STMF_ICM_R2T,
	STMF_ICM_STATUS,
	STMF_ICM_SESSION_CREATE,
	STMF_ICM_SESSION_DESTROY,
	STMF_ICM_ECHO_REQUEST,
	STMF_ICM_ECHO_REPLY,
	STMF_ICM_LUN_ACTIVE,
	STMF_ICM_MAX_MSG_TYPE
} stmf_ic_msg_type_t;

/*
 * Message id: uniquely identifies a message.
 * This need not be a sequence number since we don't depend on
 * messages being delivered in sequence.
 */
typedef uint64_t stmf_ic_msgid_t;

/*
 * IC message.  This is a container for the various specific message types.
 *
 * Note that the message contains a pointer to an nvlist.  This pointer
 * is valid only in the case of messages which are unmarshaled from
 * nvlists.  In that case, it's important to retain a pointer to the nvlist,
 * since the message and the nvlist share data in the case of strings
 * and array elements, and data in the message may be invalid if used
 * after the nvlist is freed.
 */
typedef struct stmf_ic_msg {
	stmf_ic_msg_type_t icm_msg_type;
	stmf_ic_msgid_t icm_msgid;
	nvlist_t *icm_nvlist;		/* nvlist associated with the msg */
	void *icm_msg;			/* ptr to the specific msg */
} stmf_ic_msg_t;

/*
 * Register port message.
 */
typedef struct {
	scsi_devid_desc_t 	*icrp_port_id;
	uint16_t 		icrp_relative_port_id;
	/* opaque callback data */
	uint16_t		icrp_cb_arg_len;
	uint8_t			*icrp_cb_arg;
} stmf_ic_reg_port_msg_t;

/*
 * Deregister port message.
 */
typedef struct {
	scsi_devid_desc_t 	*icdp_port_id;
	/* opaque callback data */
	uint16_t		icdp_cb_arg_len;
	uint8_t			*icdp_cb_arg;
} stmf_ic_dereg_port_msg_t;

/*
 * Register/deregister lun message.
 */
typedef struct {
	uint8_t 		icrl_lun_id[16];
	char			*icrl_lu_provider_name;
	/* opaque callback data */
	uint16_t		icrl_cb_arg_len;
	uint8_t			*icrl_cb_arg;
} stmf_ic_reg_dereg_lun_msg_t;

/*
 * SCSI cmd msg.
 */
typedef struct {
	stmf_ic_msgid_t		icsc_task_msgid;
	scsi_devid_desc_t	*icsc_ini_devid;
	scsi_devid_desc_t	*icsc_tgt_devid;
	stmf_remote_port_t	*icsc_rport;
	uint8_t 		icsc_lun_id[16];
	/*
	 * fields from scsi_task_t
	 */
	uint64_t	icsc_session_id;
	uint8_t		icsc_task_lun_no[8];
	uint32_t	icsc_task_expected_xfer_length;
	uint16_t	icsc_task_cdb_length;
	uint8_t 	*icsc_task_cdb;
	uint8_t		icsc_task_flags;	/* See def. for task flags */
	uint8_t		icsc_task_priority;	/* As per SAM-3 */
	uint8_t		icsc_task_mgmt_function;	/* if is a TM req */
	uint32_t	icsc_immed_data_len;
	uint8_t		*icsc_immed_data;
} stmf_ic_scsi_cmd_msg_t;

/*
 * SCSI data message.
 */
typedef struct {
	stmf_ic_msgid_t icsd_task_msgid;	/* matches msgid of cmd */
	uint64_t icsd_session_id;
	uint8_t icsd_lun_id[16];
	uint64_t icsd_data_len;
	uint8_t *icsd_data;
} stmf_ic_scsi_data_msg_t;

/*
 * SCSI data xfer done msg
 */
typedef struct {
	stmf_ic_msgid_t icsx_task_msgid;	/* matches msgid of cmd */
	uint64_t icsx_session_id;
	stmf_status_t	icsx_status;
} stmf_ic_scsi_data_xfer_done_msg_t;

/*
 * SCSI status msg.
 */
typedef struct {
	stmf_ic_msgid_t icss_task_msgid;	/* matches msgid of cmd */
	uint64_t icss_session_id;
	uint8_t icss_lun_id[16];
	uint8_t icss_response;		/* was command processed? */
	uint8_t icss_status;
	uint8_t	icss_flags;		/* TASK_SCTRL_OVER, TASK_SCTRL_UNDER */
	uint32_t icss_resid;
	uint8_t	icss_sense_len;
	uint8_t	*icss_sense;
} stmf_ic_scsi_status_msg_t;

/*
 * Ready to transfer (r2t) msg.
 */
typedef struct {
	stmf_ic_msgid_t icrt_task_msgid;	/* matches msgid of cmd */
	uint64_t icrt_session_id;
	uint32_t icrt_offset;
	uint32_t icrt_length;
} stmf_ic_r2t_msg_t;

/*
 * Status message: sent in response to messages other than SCSI messages.
 */
typedef struct {
	stmf_ic_msg_type_t ics_msg_type;	/* msg type rpting status on */
	stmf_ic_msgid_t ics_msgid;		/* msgid reporting status on */
	stmf_status_t ics_status;
} stmf_ic_status_msg_t;

/*
 * Session create/destroy message.
 */
typedef struct {
	uint64_t		icscd_session_id;
	scsi_devid_desc_t	*icscd_ini_devid;
	scsi_devid_desc_t	*icscd_tgt_devid;
	stmf_remote_port_t	*icscd_rport;
} stmf_ic_session_create_destroy_msg_t;

/*
 * Echo request/reply message
 */
typedef struct {
	uint8_t			*icerr_data;
	uint32_t		icerr_datalen;
} stmf_ic_echo_request_reply_msg_t;

typedef enum {
	STMF_IC_MSG_SUCCESS = 0,
	STMF_IC_MSG_IC_DOWN,
	STMF_IC_MSG_TIMED_OUT,
	STMF_IC_MSG_INTERNAL_ERROR
} stmf_ic_msg_status_t;

/*
 * Function prototypes.
 *
 * Note: Functions which are exported to other modules must have a function
 * typedef and a prototype; the function type definition is used by
 * the other module to import the symbol using ddi_modsym().
 */

void stmf_ic_ioctl_cmd(void *ibuf, uint32_t ibuf_size);

/* Allocate a register port message */
typedef
stmf_ic_msg_t *(*stmf_ic_reg_port_msg_alloc_func_t)(
    scsi_devid_desc_t *port_id,
    uint16_t relative_port_id,
    uint16_t cb_arg_len,
    uint8_t *cb_arg,
    stmf_ic_msgid_t msgid);

stmf_ic_msg_t *stmf_ic_reg_port_msg_alloc(
    scsi_devid_desc_t *port_id,
    uint16_t relative_port_id,
    uint16_t cb_arg_len,
    uint8_t *cb_arg,
    stmf_ic_msgid_t msgid);

/* Allocate a deregister port message */
typedef
stmf_ic_msg_t *(*stmf_ic_dereg_port_msg_alloc_func_t)(
    scsi_devid_desc_t *port_id,
    uint16_t cb_arg_len,
    uint8_t *cb_arg,
    stmf_ic_msgid_t msgid);

stmf_ic_msg_t *stmf_ic_dereg_port_msg_alloc(
    scsi_devid_desc_t *port_id,
    uint16_t cb_arg_len,
    uint8_t *cb_arg,
    stmf_ic_msgid_t msgid);


/* Allocate a register lun message */
typedef
stmf_ic_msg_t *(*stmf_ic_reg_lun_msg_alloc_func_t)(
    uint8_t *icrl_lun_id,	/* should be 16 bytes */
    char *lu_provider_name,
    uint16_t cb_arg_len,
    uint8_t *cb_arg,
    stmf_ic_msgid_t msgid);

stmf_ic_msg_t *stmf_ic_reg_lun_msg_alloc(
    uint8_t *icrl_lun_id,	/* should be 16 bytes */
    char *lu_provider_name,
    uint16_t cb_arg_len,
    uint8_t *cb_arg,
    stmf_ic_msgid_t msgid);

/* Allocate a lun active message */
typedef
stmf_ic_msg_t *(*stmf_ic_lun_active_msg_alloc_func_t)(
    uint8_t *icrl_lun_id,	/* should be 16 bytes */
    char *lu_provider_name,
    uint16_t cb_arg_len,
    uint8_t *cb_arg,
    stmf_ic_msgid_t msgid);

stmf_ic_msg_t *stmf_ic_lun_active_msg_alloc(
    uint8_t *icrl_lun_id,	/* should be 16 bytes */
    char *lu_provider_name,
    uint16_t cb_arg_len,
    uint8_t *cb_arg,
    stmf_ic_msgid_t msgid);

/* Allocate a deregister lun message */
typedef
stmf_ic_msg_t *(*stmf_ic_dereg_lun_msg_alloc_func_t)(
    uint8_t *icrl_lun_id,	/* should be 16 bytes */
    char *lu_provider_name,
    uint16_t cb_arg_len,
    uint8_t *cb_arg,
    stmf_ic_msgid_t msgid);

stmf_ic_msg_t *stmf_ic_dereg_lun_msg_alloc(
    uint8_t *icrl_lun_id,	/* should be 16 bytes */
    char *lu_provider_name,
    uint16_t cb_arg_len,
    uint8_t *cb_arg,
    stmf_ic_msgid_t msgid);

/* Allocate a scsi cmd message */
typedef
stmf_ic_msg_t *(*stmf_ic_scsi_cmd_msg_alloc_func_t)(
    stmf_ic_msgid_t 	task_msgid,
    scsi_task_t 	*scsi_task,
    uint32_t		immed_data_len,
    uint8_t		*immed_data,
    stmf_ic_msgid_t msgid);

stmf_ic_msg_t *stmf_ic_scsi_cmd_msg_alloc(
    stmf_ic_msgid_t 	task_msgid,
    scsi_task_t 	*scsi_task,
    uint32_t		immed_data_len,
    uint8_t		*immed_data,
    stmf_ic_msgid_t msgid);

/* Allocate a scsi data message */
typedef
stmf_ic_msg_t *(*stmf_ic_scsi_data_msg_alloc_func_t)(
    stmf_ic_msgid_t 	task_msgid,
    uint64_t		session_id,
    uint8_t		*lun_id,
    uint64_t		data_len,
    uint8_t		*data,
    stmf_ic_msgid_t msgid);

stmf_ic_msg_t *stmf_ic_scsi_data_msg_alloc(
    stmf_ic_msgid_t 	task_msgid,
    uint64_t		session_id,
    uint8_t		*lun_id,
    uint64_t		data_len,
    uint8_t		*data,
    stmf_ic_msgid_t msgid);

/* Allocate a scsi transfer done message */
typedef
stmf_ic_msg_t *(*stmf_ic_scsi_data_xfer_done_msg_alloc_func_t)(
    stmf_ic_msgid_t 	task_msgid,
    uint64_t		session_id,
    stmf_status_t	status,
    stmf_ic_msgid_t	msgid);

stmf_ic_msg_t *stmf_ic_scsi_data_xfer_done_msg_alloc(
    stmf_ic_msgid_t 	task_msgid,
    uint64_t		session_id,
    stmf_status_t	status,
    stmf_ic_msgid_t	msgid);


/* Allocate a scsi status message */
stmf_ic_msg_t *stmf_ic_scsi_status_msg_alloc(
    stmf_ic_msgid_t 	task_msgid,
    uint64_t		session_id,
    uint8_t		*lun_id,
    uint8_t		response,		/* was command processed? */
    uint8_t		status,
    uint8_t		flags,
    uint32_t 		resid,
    uint8_t		sense_len,
    uint8_t		*sense,
    stmf_ic_msgid_t msgid);	/* must match corresponding scsi cmd msgid */


/* Allocate a scsi ready to transfer (r2t) message */
stmf_ic_msg_t *stmf_ic_r2t_msg_alloc(
    stmf_ic_msgid_t 	task_msgid,
    uint64_t		session_id,
    uint32_t		offset,
    uint32_t		length,
    stmf_ic_msgid_t msgid);	/* must match corresponding scsi cmd msgid */

/* Allocate a status message */
stmf_ic_msg_t *stmf_ic_status_msg_alloc(
    stmf_status_t	status,
    stmf_ic_msg_type_t	msg_type,	/* msg type reporting status on */
    stmf_ic_msgid_t 	msgid);		/* id of msg reporting status on */

/* Allocate a session create message */
typedef
stmf_ic_msg_t *(*stmf_ic_session_create_msg_alloc_func_t)(
    stmf_scsi_session_t *session,
    stmf_ic_msgid_t msgid);

stmf_ic_msg_t *stmf_ic_session_create_msg_alloc(
    stmf_scsi_session_t *session,
    stmf_ic_msgid_t msgid);

/* Allocate a session destroy message */
typedef
stmf_ic_msg_t *(*stmf_ic_session_destroy_msg_alloc_func_t)(
    stmf_scsi_session_t *session,
    stmf_ic_msgid_t msgid);

stmf_ic_msg_t *stmf_ic_session_destroy_msg_alloc(
    stmf_scsi_session_t *session,
    stmf_ic_msgid_t msgid);

/* Allocate an echo request message */
stmf_ic_msg_t *stmf_ic_echo_request_msg_alloc(
    uint32_t data_len,
    uint8_t *data,
    stmf_ic_msgid_t msgid);

/* Allocate an echo reply message */
stmf_ic_msg_t *stmf_ic_echo_reply_msg_alloc(
    uint32_t data_len,
    uint8_t *data,
    stmf_ic_msgid_t msgid);

/*
 * Free a msg.
 */
typedef void (*stmf_ic_msg_free_func_t)(stmf_ic_msg_t *msg);
void stmf_ic_msg_free(stmf_ic_msg_t *msg);

/*
 * Send a message out over the interconnect, in the process marshalling
 * the arguments.
 *
 * After being sent, the message is freed by tx_msg().
 */
typedef stmf_ic_msg_status_t (*stmf_ic_tx_msg_func_t)(stmf_ic_msg_t *msg);
stmf_ic_msg_status_t stmf_ic_tx_msg(stmf_ic_msg_t *msg);

/*
 * This is a low-level upcall which is called when a message has
 * been received on the interconnect.
 */
void stmf_ic_rx_msg(char *buf, size_t len);

stmf_status_t stmf_msg_rx(stmf_ic_msg_t *msg);

#ifdef	__cplusplus
}
#endif

#endif	/* _SYS_PPPT_IC_IF_H */