siopvar_common.h revision 1.5 1 /* $NetBSD: siopvar_common.h,v 1.5 2000/10/06 16:35:13 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 int reselslot; /* the reselect slot used */
87 };
88
89 /* command block descriptors: an array of siop_cmd + an array of siop_xfer */
90
91 struct siop_cbd {
92 TAILQ_ENTRY (siop_cbd) next;
93 struct siop_cmd *cmds;
94 struct siop_xfer *xfers;
95 bus_dmamap_t xferdma; /* DMA map for this block of xfers */
96 };
97
98 /* status defs */
99 #define CMDST_FREE 0 /* cmd slot is free */
100 #define CMDST_READY 1 /* cmd slot is waiting for processing */
101 #define CMDST_ACTIVE 2 /* cmd slot is being processed */
102 #define CMDST_SENSE 3 /* cmd slot is being requesting sense */
103 #define CMDST_SENSE_ACTIVE 4 /* request sense active */
104 #define CMDST_SENSE_DONE 5 /* request sense done */
105 #define CMDST_DONE 6 /* cmd slot has been processed */
106 /* flags defs */
107 #define CMDFL_TIMEOUT 0x0001 /* cmd timed out */
108
109 /* per-target struct */
110 struct siop_target {
111 int status; /* target status, see below */
112 int flags; /* target flags, see below */
113 u_int32_t id; /* for SELECT FROM */
114 struct cmd_list active_list[8]; /* per-lun active cmds */
115 struct siop_softc *siop_sc; /* points back to our adapter */
116 };
117
118 /* target status */
119 #define TARST_PROBING 0 /* target is being probed */
120 #define TARST_ASYNC 1 /* target needs sync/wide negotiation */
121 #define TARST_WIDE_NEG 2 /* target is doing wide negotiation */
122 #define TARST_SYNC_NEG 3 /* target is doing sync negotiation */
123 #define TARST_OK 4 /* sync/wide agreement is valid */
124
125 /* target flags */
126 #define TARF_SYNC 0x00 /* target is sync */
127 #define TARF_WIDE 0x01 /* target is wide */
128
129 void siop_common_reset __P((struct siop_softc *));
130 int siop_modechange __P((struct siop_softc *));
131
132 int siop_wdtr_neg __P((struct siop_cmd *siop_cmd));
133 int siop_sdtr_neg __P((struct siop_cmd *siop_cmd));
134 /* actions to take at return of siop_wdtr_neg() and siop_sdtr_neg() */
135 #define SIOP_NEG_NOP 0x0
136 #define SIOP_NEG_MSGOUT 0x1
137 #define SIOP_NEG_ACK 0x2
138
139 void siop_minphys __P((struct buf *));
140 int siop_ioctl __P((struct scsipi_link *, u_long,
141 caddr_t, int, struct proc *));
142 void siop_sdp __P((struct siop_cmd *));
143 void siop_clearfifo __P((struct siop_softc *));
144 void siop_resetbus __P((struct siop_softc *));
145