siopvar_common.h revision 1.4 1 /* $NetBSD: siopvar_common.h,v 1.4 2000/07/24 15:15:01 bouyer Exp $ */
2
3 /*
4 * Copyright (c) 2000 Manuel Bouyer.
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 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Manuel Bouyer
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 */
32
33 /* common struct and routines used by siop and esiop */
34
35 #ifndef SIOP_DEFAULT_TARGET
36 #define SIOP_DEFAULT_TARGET 7
37 #endif
38
39 /* tables used by SCRIPT */
40 typedef struct scr_table {
41 u_int32_t count;
42 u_int32_t addr;
43 } scr_table_t ;
44
45 /* Number of scatter/gather entries */
46 #define SIOP_NSG (MAXPHYS/NBPG + 1)
47
48 /*
49 * This structure interfaces the SCRIPT with the driver; it describes a full
50 * transfer. It lives in the same chunk of DMA-safe memory as the script.
51 */
52 struct siop_xfer {
53 u_int8_t msg_out[8]; /* 0 */
54 u_int8_t msg_in[8]; /* 8 */
55 int status; /* 16 */
56 u_int32_t pad1; /* 20 */
57 u_int32_t id; /* 24 */
58 u_int32_t pad2; /* 28 */
59 scr_table_t t_msgin; /* 32 */
60 scr_table_t t_extmsgin; /* 40 */
61 scr_table_t t_extmsgdata; /* 48 */
62 scr_table_t t_msgtag; /* 56 */
63 scr_table_t t_msgout; /* 64 */
64 scr_table_t cmd; /* 72 */
65 scr_table_t t_status; /* 80 */
66 scr_table_t data[SIOP_NSG]; /* 88 */
67 } __attribute__((__packed__));
68
69 /*
70 * This decribes a command handled by the SCSI controller
71 * These are chained in either a free list or a active list
72 * We have one queue per target
73 */
74 struct siop_cmd {
75 TAILQ_ENTRY (siop_cmd) next;
76 struct siop_target *siop_target; /* pointer to our target def */
77 struct scsipi_xfer *xs; /* xfer from the upper level */
78 struct siop_xfer *siop_table; /* tables dealing with this xfer */
79 struct siop_cbd *siop_cbdp; /* pointer to our siop_cbd */
80 bus_addr_t dsa; /* DSA value to load */
81 bus_dmamap_t dmamap_cmd;
82 bus_dmamap_t dmamap_data;
83 struct scsipi_sense rs_cmd; /* request sense command buffer */
84 int status;
85 int flags;
86 };
87
88 /* command block descriptors: an array of siop_cmd + an array of siop_xfer */
89
90 struct siop_cbd {
91 TAILQ_ENTRY (siop_cbd) next;
92 struct siop_cmd *cmds;
93 struct siop_xfer *xfers;
94 bus_dmamap_t xferdma; /* DMA map for this block of xfers */
95 };
96
97 /* status defs */
98 #define CMDST_FREE 0 /* cmd slot is free */
99 #define CMDST_READY 1 /* cmd slot is waiting for processing */
100 #define CMDST_ACTIVE 2 /* cmd slot is being processed */
101 #define CMDST_SENSE 3 /* cmd slot is being requesting sense */
102 #define CMDST_SENSE_ACTIVE 4 /* request sense active */
103 #define CMDST_SENSE_DONE 5 /* request sense done */
104 #define CMDST_DONE 6 /* cmd slot has been processed */
105 /* flags defs */
106 #define CMDFL_TIMEOUT 0x0001 /* cmd timed out */
107
108 /* per-target struct */
109 struct siop_target {
110 int status; /* target status, see below */
111 int flags; /* target flags, see below */
112 u_int32_t id; /* for SELECT FROM */
113 struct cmd_list active_list[8]; /* per-lun active cmds */
114 struct siop_softc *siop_sc; /* points back to our adapter */
115 };
116
117 /* target status */
118 #define TARST_PROBING 0 /* target is being probed */
119 #define TARST_ASYNC 1 /* target needs sync/wide negotiation */
120 #define TARST_WIDE_NEG 2 /* target is doing wide negotiation */
121 #define TARST_SYNC_NEG 3 /* target is doing sync negotiation */
122 #define TARST_OK 4 /* sync/wide agreement is valid */
123
124 /* target flags */
125 #define TARF_SYNC 0x00 /* target is sync */
126 #define TARF_WIDE 0x01 /* target is wide */
127
128 void siop_common_reset __P((struct siop_softc *));
129 int siop_modechange __P((struct siop_softc *));
130
131 int siop_wdtr_neg __P((struct siop_cmd *siop_cmd));
132 int siop_sdtr_neg __P((struct siop_cmd *siop_cmd));
133 /* actions to take at return of siop_wdtr_neg() and siop_sdtr_neg() */
134 #define SIOP_NEG_NOP 0x0
135 #define SIOP_NEG_MSGOUT 0x1
136 #define SIOP_NEG_ACK 0x2
137
138 void siop_minphys __P((struct buf *));
139 int siop_ioctl __P((struct scsipi_link *, u_long,
140 caddr_t, int, struct proc *));
141 void siop_sdp __P((struct siop_cmd *));
142 void siop_clearfifo __P((struct siop_softc *));
143 void siop_resetbus __P((struct siop_softc *));
144