sbicvar.h revision 1.16
1/*	$NetBSD: sbicvar.h,v 1.16 2021/07/24 21:31:34 andvar Exp $	*/
2
3/*
4 * Copyright (c) 1990 The Regents of the University of California.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Van Jacobson of Lawrence Berkeley Laboratory.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 *    may be used to endorse or promote products derived from this software
20 *    without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 *  @(#)scsivar.h   7.1 (Berkeley) 5/8/90
35 */
36#ifndef _SBICVAR_H_
37#define _SBICVAR_H_
38#include <sys/callout.h>
39#include <sys/malloc.h>
40
41
42/*
43 * DMA chains are used for Scatter-Gather DMA.
44 */
45struct  dma_chain {
46	int dc_count;
47	char *dc_addr;
48};
49
50/*
51 * ACB. Holds additional information for each SCSI command Comments: We
52 * need a separate scsi command block because we may need to overwrite it
53 * with a request sense command.  Basicly, we refrain from fiddling with
54 * the scsi_xfer struct (except do the expected updating of return values).
55 * We'll generally update: xs->{flags,resid,error,sense,status} and
56 * occasionally xs->retries.
57 */
58struct sbic_acb {
59	TAILQ_ENTRY(sbic_acb) chain;
60	struct scsipi_xfer *xs;		/* SCSI xfer ctrl block from above */
61	int flags;			/* Status */
62#define ACB_FREE	0x00
63#define ACB_ACTIVE	0x01
64#define ACB_DONE	0x04
65#define ACB_BBUF	0x10	/* DMA input needs to be copied from bounce */
66#define ACB_DATAIN	0x20	/* DMA direction flag */
67
68	struct scsipi_generic cmd;	/* SCSI command block */
69	int clen;
70	struct dma_chain sc_kv;		/* Virtual address of whole DMA */
71	struct dma_chain sc_pa;		/* Physical address of DMA segment */
72	u_long sc_tcnt;			/* number of bytes for this DMA */
73	u_short sc_dmacmd;		/* Internal data for this DMA */
74	char *pa_addr;			/* XXXX initial phys addr */
75};
76
77/*
78 * Some info about each (possible) target on the SCSI bus.  This should
79 * probably have been a "per target+lunit" structure, but we'll leave it at
80 * this for now.  Is there a way to reliably hook it up to sc->fordriver??
81 */
82struct sbic_tinfo {
83	int cmds;			/* #commands processed */
84	int dconns;			/* #disconnects */
85	int lubusy;			/* What local units/subr. are busy? */
86};
87
88struct  sbic_softc {
89	device_t sc_dev;
90	struct target_sync {
91		u_char state;
92		u_char period;
93		u_char offset;
94	} sc_sync[8];
95	u_char target;			/* Currently active target */
96	u_char lun;
97	struct scsipi_channel sc_channel; /* proto for sub devices */
98	struct scsipi_adapter sc_adapter;
99	sbic_regmap_p sc_sbicp;		/* the SBIC */
100	void *sc_driver;		/* driver specific field */
101	int sc_ipl;
102
103	struct callout sc_timo_ch;
104
105	/* Lists of command blocks */
106	TAILQ_HEAD(acb_list, sbic_acb) free_list,
107				       ready_list,
108				       nexus_list;
109
110	struct sbic_acb *sc_nexus;	/* current command */
111	struct sbic_acb sc_acb[8];	/* the real command blocks */
112	struct sbic_tinfo sc_tinfo[8];
113
114	struct scsipi_xfer *sc_xs;	/* transfer from high level code */
115	u_char sc_flags;
116	u_char sc_stat[2];
117	u_char sc_msg[7];
118	u_long sc_clkfreq;
119	u_long sc_tcnt;			/* number of bytes transferred */
120	u_short sc_dmacmd;		/* used by DMA drivers */
121	u_long sc_dmamask;		/* DMA valid mem mask */
122#ifdef DEBUG
123	u_short sc_dmatimo;		/* DMA timeout */
124#endif
125	struct dma_chain *sc_cur;
126	struct dma_chain *sc_last;
127	int (*sc_dmago)(struct sbic_softc *, char *, int, int);
128	int (*sc_dmanext)(struct sbic_softc *);
129	void (*sc_enintr)(struct sbic_softc *);
130	void (*sc_dmastop)(struct sbic_softc *);
131};
132
133/*
134 * sc_flags
135 */
136#define SBICF_ALIVE	0x01	/* controller initialized */
137#define SBICF_DCFLUSH	0x02	/* need flush for overlap after DMA finishes */
138#define SBICF_SELECTED	0x04	/* bus is in selected state. */
139#define SBICF_ICMD	0x08	/* Immediate command in execution */
140#define SBICF_BADDMA	0x10	/* controller can only DMA to ztwobus space */
141#define SBICF_INTR	0x40	/* SBICF interrupt expected */
142#define SBICF_INDMA	0x80	/* not used yet, DMA I/O in progress */
143
144/*
145 * sync states
146 */
147#define SYNC_START	0	/* no sync handshake started */
148#define SYNC_SENT	1	/* we sent sync request, no answer yet */
149#define SYNC_DONE	2	/* target accepted our (or inferior) settings,
150				   or it rejected the request and we stay
151				   async */
152
153#define PHASE		0x07	/* mask for psns/pctl phase */
154#define DATA_OUT_PHASE	0x00
155#define DATA_IN_PHASE	0x01
156#define CMD_PHASE	0x02
157#define STATUS_PHASE	0x03
158#define BUS_FREE_PHASE	0x04
159#define ARB_SEL_PHASE	0x05	/* Fuji chip combines arbitration with sel. */
160#define MESG_OUT_PHASE	0x06
161#define MESG_IN_PHASE	0x07
162
163#define MSG_CMD_COMPLETE	0x00
164#define MSG_EXT_MESSAGE		0x01
165#define MSG_SAVE_DATA_PTR	0x02
166#define MSG_RESTORE_PTR		0x03
167#define MSG_DISCONNECT		0x04
168#define MSG_INIT_DETECT_ERROR	0x05
169#define MSG_ABORT		0x06
170#define MSG_REJECT		0x07
171#define MSG_NOOP		0x08
172#define MSG_PARITY_ERROR	0x09
173#define MSG_BUS_DEVICE_RESET	0x0C
174#define MSG_IDENTIFY		0x80
175#define MSG_IDENTIFY_DR		0xc0	/* (disconnect/reconnect allowed) */
176#define MSG_SYNC_REQ		0x01
177
178#define MSG_ISIDENTIFY(x)	((x) & MSG_IDENTIFY)
179
180
181#define STS_CHECKCOND		0x02	/* Check Condition (ie., read sense) */
182#define STS_CONDMET		0x04	/* Condition Met (ie., search worked) */
183#define STS_BUSY		0x08
184#define STS_INTERMED		0x10	/* Intermediate status sent */
185#define STS_EXT			0x80	/* Extended status valid */
186
187
188/*
189 * States returned by our state machine
190 */
191
192#define SBIC_STATE_ERROR	-1
193#define SBIC_STATE_DONE		0
194#define SBIC_STATE_RUNNING	1
195#define SBIC_STATE_DISCONNECT	2
196
197
198struct buf;
199struct scsipi_xfer;
200
201void sbic_minphys(struct buf *bp);
202void sbic_scsi_request(struct scsipi_channel *, scsipi_adapter_req_t, void *);
203void sbicinit(struct sbic_softc *);
204int sbicintr(struct sbic_softc *);
205
206#endif /* _SBICVAR_H_ */
207