xref: /netbsd/sys/arch/prep/stand/boot/sdvar.h (revision d09e00f4)
1 /*	$NetBSD: sdvar.h,v 1.1 2012/05/19 14:40:13 kiyohara Exp $	*/
2 /*
3  * Copyright (c) 2010 KIYOHARA Takashi
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef _STAND_SDVAR_H
29 #define _STAND_SDVAR_H
30 
31 #include <dev/ic/siopreg.h>
32 #include <dev/pci/pcireg.h>
33 #include <dev/scsipi/scsipiconf.h>
34 #include <dev/scsipi/scsipi_all.h>
35 #include <dev/scsipi/scsipi_disk.h>
36 #include <dev/scsipi/scsi_all.h>
37 #include <dev/scsipi/scsi_disk.h>
38 #include <dev/scsipi/scsi_message.h>
39 #include <dev/scsipi/scsi_spc.h>
40 
41 #include <sys/disklabel.h>
42 #include <sys/bootblock.h>
43 
44 
45 /* tables used by SCRIPT */
46 typedef struct scr_table {
47 	uint32_t count;
48 	uint32_t addr;
49 } __packed scr_table_t;
50 
51 /* Number of scatter/gather entries */
52 #define SIOP_NSG	(0x10000/0x1000 + 1)	/* XXX PAGE_SIZE */
53 /*
54  * This structure interfaces the SCRIPT with the driver; it describes a full
55  * transfer.
56  * If you change something here, don't forget to update offsets in {s,es}iop.ss
57  */
58 struct siop_common_xfer {
59 	uint8_t msg_out[16];	/* 0 */
60 	uint8_t msg_in[16];	/* 16 */
61 	uint32_t status;	/* 32 */
62 	uint32_t pad1;		/* 36 */
63 	uint32_t id;		/* 40 */
64 	uint32_t pad2;		/* 44 */
65 	scr_table_t t_msgin;	/* 48 */
66 	scr_table_t t_extmsgin;	/* 56 */
67 	scr_table_t t_extmsgdata; /* 64 */
68 	scr_table_t t_msgout;	/* 72 */
69 	scr_table_t cmd;	/* 80 */
70 	scr_table_t t_status;	/* 88 */
71 	scr_table_t data[SIOP_NSG]; /* 96 */
72 } __packed;
73 
74 /* status can hold the SCSI_* status values, and 2 additional values: */
75 #define SCSI_SIOP_NOCHECK	0xfe	/* don't check the scsi status */
76 #define SCSI_SIOP_NOSTATUS	0xff	/* device didn't report status */
77 
78 
79 /*
80  * xfer description of the script: tables and reselect script
81  * In struct siop_common_cmd siop_xfer will point to this.
82  */
83 struct siop_xfer {
84 	struct siop_common_xfer siop_tables;
85 	/* uint32_t resel[sizeof(load_dsa) / sizeof(load_dsa[0])]; */
86 	uint32_t resel[25];
87 } __packed;
88 
89 
90 #define SIOP_SCRIPT_SIZE	4096
91 #define SIOP_TABLE_SIZE		4096
92 #define SIOP_SCSI_COMMAND_SIZE	4096
93 #define SIOP_SCSI_DATA_SIZE	4096
94 
95 struct scsi_xfer {
96 	int target;
97 	int lun;
98 	struct scsipi_generic *cmd;
99 	int cmdlen;
100 	u_char *data;
101 	int datalen;
102 	int resid;
103 	scsipi_xfer_result_t error;
104 	uint8_t status;				/* SCSI status */
105 	int xs_status;
106 };
107 
108 struct sd_softc;
109 struct siop_adapter {
110 	int id;
111 	u_long addr;				/* register map address */
112 	int clock_div;
113 	uint32_t *script;			/* script addr */
114 	struct siop_xfer *xfer;			/* xfer addr */
115 	struct scsipi_generic *cmd;		/* SCSI command buffer */
116 	struct scsi_request_sense *sense;	/* SCSI sense buffer */
117 	u_char *data;				/* SCSI data buffer */
118 
119 	struct scsi_xfer *xs;
120 
121 	int currschedslot;		/* current scheduler slot */
122 
123 	int sel_t;			/* selected target */
124 	struct sd_softc *sd;
125 };
126 
127 struct sd_softc {
128 	int sc_part;
129 	int sc_lun;
130 	int sc_target;
131 	int sc_bus;
132 
133 	int sc_type;
134 	int sc_cap;
135 	int sc_flags;
136 #define FLAGS_MEDIA_LOADED	(1 << 0)
137 #define FLAGS_REMOVABLE		(1 << 1)
138 
139 	struct disk_parms {
140 		u_long	heads;		/* number of heads */
141 		u_long	cyls;		/* number of cylinders */
142 		u_long	sectors;	/* number of sectors/track */
143 		u_long	blksize;	/* number of bytes/sector */
144 		u_long	rot_rate;	/* rotational rate, in RPM */
145 		u_int64_t disksize;	/* total number sectors */
146 		u_int64_t disksize512;	/* total number sectors */
147 	} sc_params;
148 	struct disklabel sc_label;
149 };
150 
151 int	siop_init(int, int, int);
152 int	scsi_inquire(struct sd_softc *, int, void *);
153 int	scsi_mode_sense(struct sd_softc *, int, int,
154 			struct scsi_mode_parameter_header_6 *, int);
155 int	scsi_command(struct sd_softc *, void *, int, void *, int);
156 
157 
158 #define	SDGP_RESULT_OK		0	/* parameters obtained */
159 #define	SDGP_RESULT_OFFLINE	1	/* no media, or otherwise losing */
160 #define	SDGP_RESULT_UNFORMATTED	2	/* unformatted media (max params) */
161 
162 #define ERESTART	-1
163 
164 #endif /* _STAND_SDVAR_H */
165