1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_1394_TARGETS_SCSA1394_CMD_H
27 #define	_SYS_1394_TARGETS_SCSA1394_CMD_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 /*
32  * scsa1394 command
33  */
34 
35 #include <sys/scsi/scsi_types.h>
36 #include <sys/1394/targets/scsa1394/sbp2.h>
37 #include <sys/note.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 /* preferred pkt_private length in 64-bit quantities */
44 #ifdef  _LP64
45 #define	SCSA1394_CMD_PRIV_SIZE	2
46 #else /* _ILP32 */
47 #define	SCSA1394_CMD_PRIV_SIZE	1
48 #endif
49 #define	SCSA1394_CMD_PRIV_LEN   (SCSA1394_CMD_PRIV_SIZE * sizeof (uint64_t))
50 
51 /* entry describing a page table segment */
52 typedef struct scsa1394_cmd_seg {
53 	size_t			ss_len;
54 	uint64_t		ss_daddr;
55 	uint64_t		ss_baddr;
56 	t1394_addr_handle_t	ss_addr_hdl;
57 } scsa1394_cmd_seg_t;
58 
59 /* command packet structure */
60 typedef struct scsa1394_cmd {
61 	sbp2_task_t		sc_task;	/* corresponding SBP-2 task */
62 	struct scsa1394_lun	*sc_lun;	/* lun it belongs to */
63 	int			sc_state;	/* command state */
64 	int			sc_flags;	/* command flags */
65 	struct buf		*sc_bp;		/* data buffer */
66 	struct scsi_pkt		*sc_pkt;	/* corresponding scsi pkt */
67 	size_t			sc_cdb_len;
68 	size_t			sc_cdb_actual_len;
69 	size_t			sc_scb_len;
70 	size_t			sc_priv_len;
71 	uchar_t			sc_cdb[SCSI_CDB_SIZE];
72 	uchar_t			sc_pkt_cdb[SCSI_CDB_SIZE];
73 	struct scsi_arq_status	sc_scb;
74 	uint64_t		sc_priv[SCSA1394_CMD_PRIV_SIZE];
75 	clock_t			sc_start_time;
76 	int			sc_timeout;
77 
78 	/* DMA: command ORB */
79 	ddi_dma_handle_t	sc_orb_dma_hdl;
80 	ddi_acc_handle_t	sc_orb_acc_hdl;
81 	ddi_dma_cookie_t	sc_orb_dmac;
82 	t1394_addr_handle_t	sc_orb_addr_hdl;
83 
84 	/* DMA: data buffer */
85 	ddi_dma_handle_t	sc_buf_dma_hdl;
86 	uint_t			sc_buf_nsegs;	/* # of segments/cookies */
87 	uint_t			sc_buf_nsegs_alloc; /* # of entries allocated */
88 	scsa1394_cmd_seg_t	*sc_buf_seg;	/* segment array */
89 	scsa1394_cmd_seg_t	sc_buf_seg_mem;	/* backstore for one segment */
90 	uint_t			sc_nwin;	/* # windows */
91 	uint_t			sc_curwin;	/* current window */
92 	off_t			sc_win_offset;	/* current window offset */
93 	size_t			sc_win_len;	/* current window length */
94 	size_t			sc_xfer_bytes;	/* current xfer byte count */
95 	size_t			sc_xfer_blks;	/* current xfer blk count */
96 
97 	/* DMA: page table */
98 	ddi_dma_handle_t	sc_pt_dma_hdl;
99 	ddi_acc_handle_t	sc_pt_acc_hdl;
100 	ddi_dma_cookie_t	sc_pt_dmac;
101 	caddr_t			sc_pt_kaddr;
102 	uint64_t		sc_pt_baddr;
103 	t1394_addr_handle_t	sc_pt_addr_hdl;
104 	size_t			sc_pt_ent_alloc; /* # allocated entries */
105 	int			sc_pt_cmd_size;
106 
107 	/* for symbios mode only */
108 	int			sc_lba;		/* start LBA */
109 	int			sc_blk_size;	/* xfer block size */
110 	size_t			sc_total_blks;	/* total xfer blocks */
111 	size_t			sc_resid_blks;	/* blocks left */
112 
113 	struct scsi_pkt		sc_scsi_pkt;	/* must be last */
114 						/* embedded SCSI packet */
115 						/* ... scsi_pkt_size() */
116 } scsa1394_cmd_t;
117 #define	SCSA1394_CMD_SIZE	(sizeof (struct scsa1394_cmd) - \
118 				sizeof (struct scsi_pkt) + scsi_pkt_size())
119 
120 _NOTE(SCHEME_PROTECTS_DATA("unique per task", { scsa1394_cmd scsa1394_cmd_seg
121     scsi_pkt scsi_inquiry scsi_extended_sense scsi_cdb scsi_arq_status }))
122 
123 #define	PKT2CMD(pktp)	((scsa1394_cmd_t *)((pktp)->pkt_ha_private))
124 #define	CMD2PKT(cmdp)	((struct scsi_pkt *)((cmdp)->sc_pkt))
125 #define	TASK2CMD(task)	((scsa1394_cmd_t *)(task)->ts_drv_priv)
126 #define	CMD2TASK(cmdp)	((sbp2_task_t *)&(cmdp)->sc_task)
127 
128 /* state */
129 enum {
130 	SCSA1394_CMD_INIT,
131 	SCSA1394_CMD_START,
132 	SCSA1394_CMD_STATUS
133 };
134 
135 /* flags */
136 enum {
137 	SCSA1394_CMD_CDB_EXT		= 0x0001,
138 	SCSA1394_CMD_PRIV_EXT		= 0x0002,
139 	SCSA1394_CMD_SCB_EXT		= 0x0004,
140 	SCSA1394_CMD_EXT		= (SCSA1394_CMD_CDB_EXT |
141 					    SCSA1394_CMD_PRIV_EXT |
142 					    SCSA1394_CMD_SCB_EXT),
143 
144 	SCSA1394_CMD_DMA_CDB_VALID	= 0x0008,
145 	SCSA1394_CMD_DMA_BUF_BIND_VALID	= 0x0010,
146 	SCSA1394_CMD_DMA_BUF_PT_VALID	= 0x0020,
147 	SCSA1394_CMD_DMA_BUF_ADDR_VALID	= 0x0040,
148 	SCSA1394_CMD_DMA_BUF_VALID	= (SCSA1394_CMD_DMA_BUF_BIND_VALID |
149 					    SCSA1394_CMD_DMA_BUF_ADDR_VALID |
150 					    SCSA1394_CMD_DMA_BUF_PT_VALID),
151 	SCSA1394_CMD_DMA_BUF_MAPIN	= 0x0080,
152 
153 	SCSA1394_CMD_READ		= 0x0100,
154 	SCSA1394_CMD_WRITE		= 0x0200,
155 	SCSA1394_CMD_RDWR		= (SCSA1394_CMD_READ |
156 					    SCSA1394_CMD_WRITE),
157 
158 	SCSA1394_CMD_SYMBIOS_BREAKUP	= 0x400
159 };
160 
161 #ifdef	__cplusplus
162 }
163 #endif
164 
165 #endif	/* _SYS_1394_TARGETS_SCSA1394_CMD_H */
166