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