11.18Sthorpej/*	$NetBSD: sbicvar.h,v 1.18 2023/12/20 15:29:05 thorpej Exp $	*/
21.3Sthorpej
31.1Schuck/*
41.1Schuck * Copyright (c) 1990 The Regents of the University of California.
51.1Schuck * All rights reserved.
61.1Schuck *
71.1Schuck * This code is derived from software contributed to Berkeley by
81.1Schuck * Van Jacobson of Lawrence Berkeley Laboratory.
91.1Schuck *
101.1Schuck * Redistribution and use in source and binary forms, with or without
111.1Schuck * modification, are permitted provided that the following conditions
121.1Schuck * are met:
131.1Schuck * 1. Redistributions of source code must retain the above copyright
141.1Schuck *    notice, this list of conditions and the following disclaimer.
151.1Schuck * 2. Redistributions in binary form must reproduce the above copyright
161.1Schuck *    notice, this list of conditions and the following disclaimer in the
171.1Schuck *    documentation and/or other materials provided with the distribution.
181.11Sagc * 3. Neither the name of the University nor the names of its contributors
191.1Schuck *    may be used to endorse or promote products derived from this software
201.1Schuck *    without specific prior written permission.
211.1Schuck *
221.1Schuck * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
231.1Schuck * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
241.1Schuck * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
251.1Schuck * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
261.1Schuck * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
271.1Schuck * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
281.1Schuck * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
291.1Schuck * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
301.1Schuck * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
311.1Schuck * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
321.1Schuck * SUCH DAMAGE.
331.1Schuck *
341.1Schuck *  @(#)scsivar.h   7.1 (Berkeley) 5/8/90
351.1Schuck */
361.1Schuck#ifndef _SBICVAR_H_
371.1Schuck#define _SBICVAR_H_
381.18Sthorpej
391.7Sthorpej#include <sys/callout.h>
401.1Schuck
411.1Schuck
421.1Schuck/*
431.1Schuck * DMA chains are used for Scatter-Gather DMA.
441.1Schuck */
451.1Schuckstruct  dma_chain {
461.14Stsutsui	int dc_count;
471.14Stsutsui	char *dc_addr;
481.1Schuck};
491.1Schuck
501.1Schuck/*
511.1Schuck * ACB. Holds additional information for each SCSI command Comments: We
521.1Schuck * need a separate scsi command block because we may need to overwrite it
531.17Sandvar * with a request sense command.  Basically, we refrain from fiddling with
541.1Schuck * the scsi_xfer struct (except do the expected updating of return values).
551.1Schuck * We'll generally update: xs->{flags,resid,error,sense,status} and
561.1Schuck * occasionally xs->retries.
571.1Schuck */
581.1Schuckstruct sbic_acb {
591.14Stsutsui	TAILQ_ENTRY(sbic_acb) chain;
601.14Stsutsui	struct scsipi_xfer *xs;		/* SCSI xfer ctrl block from above */
611.14Stsutsui	int flags;			/* Status */
621.14Stsutsui#define ACB_FREE	0x00
631.14Stsutsui#define ACB_ACTIVE	0x01
641.14Stsutsui#define ACB_DONE	0x04
651.14Stsutsui#define ACB_BBUF	0x10	/* DMA input needs to be copied from bounce */
661.14Stsutsui#define ACB_DATAIN	0x20	/* DMA direction flag */
671.14Stsutsui
681.14Stsutsui	struct scsipi_generic cmd;	/* SCSI command block */
691.14Stsutsui	int clen;
701.14Stsutsui	struct dma_chain sc_kv;		/* Virtual address of whole DMA */
711.14Stsutsui	struct dma_chain sc_pa;		/* Physical address of DMA segment */
721.14Stsutsui	u_long sc_tcnt;			/* number of bytes for this DMA */
731.14Stsutsui	u_short sc_dmacmd;		/* Internal data for this DMA */
741.14Stsutsui	char *pa_addr;			/* XXXX initial phys addr */
751.1Schuck};
761.1Schuck
771.1Schuck/*
781.1Schuck * Some info about each (possible) target on the SCSI bus.  This should
791.1Schuck * probably have been a "per target+lunit" structure, but we'll leave it at
801.1Schuck * this for now.  Is there a way to reliably hook it up to sc->fordriver??
811.1Schuck */
821.1Schuckstruct sbic_tinfo {
831.14Stsutsui	int cmds;			/* #commands processed */
841.14Stsutsui	int dconns;			/* #disconnects */
851.14Stsutsui	int lubusy;			/* What local units/subr. are busy? */
861.9Smatt};
871.1Schuck
881.1Schuckstruct  sbic_softc {
891.15Schs	device_t sc_dev;
901.14Stsutsui	struct target_sync {
911.14Stsutsui		u_char state;
921.14Stsutsui		u_char period;
931.14Stsutsui		u_char offset;
941.14Stsutsui	} sc_sync[8];
951.14Stsutsui	u_char target;			/* Currently active target */
961.14Stsutsui	u_char lun;
971.14Stsutsui	struct scsipi_channel sc_channel; /* proto for sub devices */
981.14Stsutsui	struct scsipi_adapter sc_adapter;
991.14Stsutsui	sbic_regmap_p sc_sbicp;		/* the SBIC */
1001.14Stsutsui	void *sc_driver;		/* driver specific field */
1011.14Stsutsui	int sc_ipl;
1021.14Stsutsui
1031.14Stsutsui	struct callout sc_timo_ch;
1041.14Stsutsui
1051.14Stsutsui	/* Lists of command blocks */
1061.14Stsutsui	TAILQ_HEAD(acb_list, sbic_acb) free_list,
1071.14Stsutsui				       ready_list,
1081.14Stsutsui				       nexus_list;
1091.14Stsutsui
1101.14Stsutsui	struct sbic_acb *sc_nexus;	/* current command */
1111.14Stsutsui	struct sbic_acb sc_acb[8];	/* the real command blocks */
1121.14Stsutsui	struct sbic_tinfo sc_tinfo[8];
1131.14Stsutsui
1141.14Stsutsui	struct scsipi_xfer *sc_xs;	/* transfer from high level code */
1151.14Stsutsui	u_char sc_flags;
1161.14Stsutsui	u_char sc_stat[2];
1171.14Stsutsui	u_char sc_msg[7];
1181.14Stsutsui	u_long sc_clkfreq;
1191.16Sandvar	u_long sc_tcnt;			/* number of bytes transferred */
1201.14Stsutsui	u_short sc_dmacmd;		/* used by DMA drivers */
1211.14Stsutsui	u_long sc_dmamask;		/* DMA valid mem mask */
1221.1Schuck#ifdef DEBUG
1231.14Stsutsui	u_short sc_dmatimo;		/* DMA timeout */
1241.1Schuck#endif
1251.14Stsutsui	struct dma_chain *sc_cur;
1261.14Stsutsui	struct dma_chain *sc_last;
1271.14Stsutsui	int (*sc_dmago)(struct sbic_softc *, char *, int, int);
1281.14Stsutsui	int (*sc_dmanext)(struct sbic_softc *);
1291.14Stsutsui	void (*sc_enintr)(struct sbic_softc *);
1301.14Stsutsui	void (*sc_dmastop)(struct sbic_softc *);
1311.1Schuck};
1321.1Schuck
1331.1Schuck/*
1341.1Schuck * sc_flags
1351.1Schuck */
1361.14Stsutsui#define SBICF_ALIVE	0x01	/* controller initialized */
1371.14Stsutsui#define SBICF_DCFLUSH	0x02	/* need flush for overlap after DMA finishes */
1381.14Stsutsui#define SBICF_SELECTED	0x04	/* bus is in selected state. */
1391.14Stsutsui#define SBICF_ICMD	0x08	/* Immediate command in execution */
1401.14Stsutsui#define SBICF_BADDMA	0x10	/* controller can only DMA to ztwobus space */
1411.14Stsutsui#define SBICF_INTR	0x40	/* SBICF interrupt expected */
1421.14Stsutsui#define SBICF_INDMA	0x80	/* not used yet, DMA I/O in progress */
1431.1Schuck
1441.1Schuck/*
1451.1Schuck * sync states
1461.1Schuck */
1471.14Stsutsui#define SYNC_START	0	/* no sync handshake started */
1481.14Stsutsui#define SYNC_SENT	1	/* we sent sync request, no answer yet */
1491.14Stsutsui#define SYNC_DONE	2	/* target accepted our (or inferior) settings,
1501.14Stsutsui				   or it rejected the request and we stay
1511.14Stsutsui				   async */
1521.14Stsutsui
1531.14Stsutsui#define PHASE		0x07	/* mask for psns/pctl phase */
1541.14Stsutsui#define DATA_OUT_PHASE	0x00
1551.14Stsutsui#define DATA_IN_PHASE	0x01
1561.14Stsutsui#define CMD_PHASE	0x02
1571.14Stsutsui#define STATUS_PHASE	0x03
1581.14Stsutsui#define BUS_FREE_PHASE	0x04
1591.14Stsutsui#define ARB_SEL_PHASE	0x05	/* Fuji chip combines arbitration with sel. */
1601.14Stsutsui#define MESG_OUT_PHASE	0x06
1611.14Stsutsui#define MESG_IN_PHASE	0x07
1621.14Stsutsui
1631.14Stsutsui#define MSG_CMD_COMPLETE	0x00
1641.14Stsutsui#define MSG_EXT_MESSAGE		0x01
1651.14Stsutsui#define MSG_SAVE_DATA_PTR	0x02
1661.14Stsutsui#define MSG_RESTORE_PTR		0x03
1671.14Stsutsui#define MSG_DISCONNECT		0x04
1681.14Stsutsui#define MSG_INIT_DETECT_ERROR	0x05
1691.14Stsutsui#define MSG_ABORT		0x06
1701.14Stsutsui#define MSG_REJECT		0x07
1711.14Stsutsui#define MSG_NOOP		0x08
1721.14Stsutsui#define MSG_PARITY_ERROR	0x09
1731.14Stsutsui#define MSG_BUS_DEVICE_RESET	0x0C
1741.14Stsutsui#define MSG_IDENTIFY		0x80
1751.14Stsutsui#define MSG_IDENTIFY_DR		0xc0	/* (disconnect/reconnect allowed) */
1761.14Stsutsui#define MSG_SYNC_REQ		0x01
1771.14Stsutsui
1781.14Stsutsui#define MSG_ISIDENTIFY(x)	((x) & MSG_IDENTIFY)
1791.14Stsutsui
1801.14Stsutsui
1811.14Stsutsui#define STS_CHECKCOND		0x02	/* Check Condition (ie., read sense) */
1821.14Stsutsui#define STS_CONDMET		0x04	/* Condition Met (ie., search worked) */
1831.14Stsutsui#define STS_BUSY		0x08
1841.14Stsutsui#define STS_INTERMED		0x10	/* Intermediate status sent */
1851.14Stsutsui#define STS_EXT			0x80	/* Extended status valid */
1861.1Schuck
1871.1Schuck
1881.1Schuck/*
1891.1Schuck * States returned by our state machine
1901.1Schuck */
1911.1Schuck
1921.14Stsutsui#define SBIC_STATE_ERROR	-1
1931.14Stsutsui#define SBIC_STATE_DONE		0
1941.14Stsutsui#define SBIC_STATE_RUNNING	1
1951.14Stsutsui#define SBIC_STATE_DISCONNECT	2
1961.1Schuck
1971.1Schuck
1981.1Schuckstruct buf;
1991.4Sbouyerstruct scsipi_xfer;
2001.1Schuck
2011.14Stsutsuivoid sbic_minphys(struct buf *bp);
2021.14Stsutsuivoid sbic_scsi_request(struct scsipi_channel *, scsipi_adapter_req_t, void *);
2031.14Stsutsuivoid sbicinit(struct sbic_softc *);
2041.14Stsutsuiint sbicintr(struct sbic_softc *);
2051.1Schuck
2061.1Schuck#endif /* _SBICVAR_H_ */
207