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