xref: /netbsd-src/sys/dev/ic/siopvar_common.h (revision 6d07b400dc878478f544ef48ff61b3295c40c6bb)
1*6d07b400Sbouyer /*	$NetBSD: siopvar_common.h,v 1.40 2009/10/19 18:41:13 bouyer Exp $	*/
286301452Sbouyer 
386301452Sbouyer /*
486301452Sbouyer  * Copyright (c) 2000 Manuel Bouyer.
586301452Sbouyer  *
686301452Sbouyer  * Redistribution and use in source and binary forms, with or without
786301452Sbouyer  * modification, are permitted provided that the following conditions
886301452Sbouyer  * are met:
986301452Sbouyer  * 1. Redistributions of source code must retain the above copyright
1086301452Sbouyer  *    notice, this list of conditions and the following disclaimer.
1186301452Sbouyer  * 2. Redistributions in binary form must reproduce the above copyright
1286301452Sbouyer  *    notice, this list of conditions and the following disclaimer in the
1386301452Sbouyer  *    documentation and/or other materials provided with the distribution.
1486301452Sbouyer  *
1586301452Sbouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1686301452Sbouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1786301452Sbouyer  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1886301452Sbouyer  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1986301452Sbouyer  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2086301452Sbouyer  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2186301452Sbouyer  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2286301452Sbouyer  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2386301452Sbouyer  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2486301452Sbouyer  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2586301452Sbouyer  *
2686301452Sbouyer  */
2786301452Sbouyer 
28cf06149dSbouyer #include "opt_siop.h"
29cf06149dSbouyer 
3086301452Sbouyer /* common struct and routines used by siop and esiop */
3186301452Sbouyer 
3286301452Sbouyer #ifndef SIOP_DEFAULT_TARGET
3386301452Sbouyer #define SIOP_DEFAULT_TARGET 7
3486301452Sbouyer #endif
3586301452Sbouyer 
3686301452Sbouyer /* tables used by SCRIPT */
3786301452Sbouyer typedef struct scr_table {
38f95171bfStsutsui 	uint32_t count;
39f95171bfStsutsui 	uint32_t addr;
40e87f74fdSdrochner } __packed scr_table_t;
4186301452Sbouyer 
4286301452Sbouyer /* Number of scatter/gather entries */
4324a4b8faSthorpej #define SIOP_NSG	(MAXPHYS/PAGE_SIZE + 1)	/* XXX PAGE_SIZE */
4486301452Sbouyer 
4586301452Sbouyer /*
4686301452Sbouyer  * This structure interfaces the SCRIPT with the driver; it describes a full
479d3f5d7fSbouyer  * transfer.
480852b37fSbouyer  * If you change something here, don't forget to update offsets in {s,es}iop.ss
4986301452Sbouyer  */
5097fe8b91Sbouyer struct siop_common_xfer {
51f95171bfStsutsui 	uint8_t msg_out[16];	/* 0 */
52f95171bfStsutsui 	uint8_t msg_in[16];	/* 16 */
53f95171bfStsutsui 	uint32_t status;	/* 32 */
54f95171bfStsutsui 	uint32_t pad1;		/* 36 */
55f95171bfStsutsui 	uint32_t id;		/* 40 */
56f95171bfStsutsui 	uint32_t pad2;		/* 44 */
576d37782aSbouyer 	scr_table_t t_msgin;	/* 48 */
586d37782aSbouyer 	scr_table_t t_extmsgin;	/* 56 */
596d37782aSbouyer 	scr_table_t t_extmsgdata; /* 64 */
606d37782aSbouyer 	scr_table_t t_msgout;	/* 72 */
616d37782aSbouyer 	scr_table_t cmd;	/* 80 */
626d37782aSbouyer 	scr_table_t t_status;	/* 88 */
636d37782aSbouyer 	scr_table_t data[SIOP_NSG]; /* 96 */
64e87f74fdSdrochner } __packed;
6586301452Sbouyer 
66c5670263Swiz /* status can hold the SCSI_* status values, and 2 additional values: */
67fc926012Sbouyer #define SCSI_SIOP_NOCHECK	0xfe	/* don't check the scsi status */
68fc926012Sbouyer #define SCSI_SIOP_NOSTATUS	0xff	/* device didn't report status */
69fc926012Sbouyer 
7098fae666Sbouyer /* offset is initialised to SIOP_NOOFFSET, used to check if it was updated */
7198fae666Sbouyer #define SIOP_NOOFFSET 0xffffffff
7298fae666Sbouyer 
7386301452Sbouyer /*
74c5670263Swiz  * This describes a command handled by the SCSI controller
7586301452Sbouyer  */
7697fe8b91Sbouyer struct siop_common_cmd {
7797fe8b91Sbouyer 	struct siop_common_softc *siop_sc; /* points back to our adapter */
7897fe8b91Sbouyer 	struct siop_common_target *siop_target; /* pointer to our target def */
7986301452Sbouyer 	struct scsipi_xfer *xs; /* xfer from the upper level */
8097fe8b91Sbouyer 	struct siop_common_xfer *siop_tables; /* tables for this cmd */
8186301452Sbouyer 	bus_addr_t	dsa; /* DSA value to load */
8286301452Sbouyer 	bus_dmamap_t	dmamap_cmd;
8386301452Sbouyer 	bus_dmamap_t	dmamap_data;
8486301452Sbouyer 	int status;
8586301452Sbouyer 	int flags;
867777f61cSbouyer 	int tag;	/* tag used for tagged command queuing */
8783478e12Sbouyer 	int resid;	/* valid when CMDFL_RESID is set */
8886301452Sbouyer };
8986301452Sbouyer 
9086301452Sbouyer /* status defs */
9186301452Sbouyer #define CMDST_FREE		0 /* cmd slot is free */
9286301452Sbouyer #define CMDST_READY		1 /* cmd slot is waiting for processing */
9386301452Sbouyer #define CMDST_ACTIVE		2 /* cmd slot is being processed */
94937a7a3eSbouyer #define CMDST_DONE		3 /* cmd slot has been processed */
9586301452Sbouyer /* flags defs */
9686301452Sbouyer #define CMDFL_TIMEOUT	0x0001 /* cmd timed out */
979d3f5d7fSbouyer #define CMDFL_TAG	0x0002 /* tagged cmd */
9883478e12Sbouyer #define CMDFL_RESID	0x0004 /* current offset in table is partial */
999d3f5d7fSbouyer 
10086301452Sbouyer /* per-target struct */
10197fe8b91Sbouyer struct siop_common_target {
10286301452Sbouyer 	int status;	/* target status, see below */
10386301452Sbouyer 	int flags;	/* target flags, see below */
104f95171bfStsutsui 	uint32_t id;	/* for SELECT FROM */
105937a7a3eSbouyer 	int period;
106937a7a3eSbouyer 	int offset;
10786301452Sbouyer };
10886301452Sbouyer 
10986301452Sbouyer /* target status */
11086301452Sbouyer #define TARST_PROBING	0 /* target is being probed */
11186301452Sbouyer #define TARST_ASYNC	1 /* target needs sync/wide negotiation */
11286301452Sbouyer #define TARST_WIDE_NEG	2 /* target is doing wide negotiation */
11386301452Sbouyer #define TARST_SYNC_NEG	3 /* target is doing sync negotiation */
114c7454ad9Sbouyer #define TARST_PPR_NEG	4 /* target is doing sync negotiation */
115c7454ad9Sbouyer #define TARST_OK	5 /* sync/wide agreement is valid */
11686301452Sbouyer 
11786301452Sbouyer /* target flags */
1189d3f5d7fSbouyer #define TARF_SYNC	0x01 /* target can do sync */
1199d3f5d7fSbouyer #define TARF_WIDE	0x02 /* target can do wide */
1209d3f5d7fSbouyer #define TARF_TAG	0x04 /* target can do tags */
121c7454ad9Sbouyer #define TARF_DT		0x08 /* target can do DT clocking */
122c7454ad9Sbouyer #define TARF_ISWIDE	0x10 /* target is wide */
123c7454ad9Sbouyer #define TARF_ISDT	0x20 /* target is doing DT clocking */
1249d3f5d7fSbouyer 
12597fe8b91Sbouyer /* Driver internal state */
12697fe8b91Sbouyer struct siop_common_softc {
12731ec75e9Stsutsui 	device_t sc_dev;
12897fe8b91Sbouyer 	struct scsipi_channel sc_chan;
12997fe8b91Sbouyer 	struct scsipi_adapter sc_adapt;
13097fe8b91Sbouyer 	int features;			/* chip's features */
13197fe8b91Sbouyer 	int ram_size;
13297fe8b91Sbouyer 	int maxburst;
13397fe8b91Sbouyer 	int maxoff;
13497fe8b91Sbouyer 	int clock_div;			/* async. clock divider (scntl3) */
13597fe8b91Sbouyer 	int clock_period;		/* clock period (ns * 10) */
136c7454ad9Sbouyer 	int st_minsync;			/* min and max sync period, */
137c7454ad9Sbouyer 	int dt_minsync;
138c7454ad9Sbouyer 	int st_maxsync;			/* as sent in or PPR messages */
139c7454ad9Sbouyer 	int dt_maxsync;
1408e978787Sbouyer 	int mode;			/* current SE/LVD/HVD mode */
14197fe8b91Sbouyer 	bus_space_tag_t sc_rt;		/* bus_space registers tag */
14297fe8b91Sbouyer 	bus_space_handle_t sc_rh;	/* bus_space registers handle */
143c5670263Swiz 	bus_addr_t sc_raddr;		/* register addresses */
14497fe8b91Sbouyer 	bus_space_tag_t sc_ramt;	/* bus_space ram tag */
14597fe8b91Sbouyer 	bus_space_handle_t sc_ramh;	/* bus_space ram handle */
14697fe8b91Sbouyer 	bus_dma_tag_t sc_dmat;		/* bus DMA tag */
14718db93c7Sperry 	void (*sc_reset)(struct siop_common_softc*); /* reset callback */
14897fe8b91Sbouyer 	bus_dmamap_t  sc_scriptdma;	/* DMA map for script */
149ee1b4065Swiz 	bus_addr_t sc_scriptaddr;	/* on-board ram or physical address */
150f95171bfStsutsui 	uint32_t *sc_script;		/* script location in memory */
15197fe8b91Sbouyer 	struct siop_common_target *targets[16]; /* per-target states */
1529d3f5d7fSbouyer };
15386301452Sbouyer 
15497fe8b91Sbouyer /* features */
15597fe8b91Sbouyer #define SF_BUS_WIDE	0x00000001 /* wide bus */
1560ff49f9fStsutsui #define SF_BUS_ULTRA	0x00000002 /* Ultra (20MHz) bus */
1570ff49f9fStsutsui #define SF_BUS_ULTRA2	0x00000004 /* Ultra2 (40MHz) bus */
1580ff49f9fStsutsui #define SF_BUS_ULTRA3	0x00000008 /* Ultra3 (80MHz) bus */
159b6fee401Sbouyer #define SF_BUS_DIFF	0x00000010 /* differential bus */
1607777f61cSbouyer 
16197fe8b91Sbouyer #define SF_CHIP_LED0	0x00000100 /* led on GPIO0 */
162b6fee401Sbouyer #define SF_CHIP_LEDC	0x00000200 /* led on GPIO0 with hardware control */
163b6fee401Sbouyer #define SF_CHIP_DBLR	0x00000400 /* clock doubler or quadrupler */
164b6fee401Sbouyer #define SF_CHIP_QUAD	0x00000800 /* clock quadrupler, with PPL */
165b6fee401Sbouyer #define SF_CHIP_FIFO	0x00001000 /* large fifo */
166c5670263Swiz #define SF_CHIP_PF	0x00002000 /* Instructions prefetch */
167b6fee401Sbouyer #define SF_CHIP_RAM	0x00004000 /* on-board RAM */
168b6fee401Sbouyer #define SF_CHIP_LS	0x00008000 /* load/store instruction */
169b6fee401Sbouyer #define SF_CHIP_10REGS	0x00010000 /* 10 scratch registers */
170b6fee401Sbouyer #define SF_CHIP_DFBC	0x00020000 /* Use DFBC register */
171b6fee401Sbouyer #define SF_CHIP_DT	0x00040000 /* DT clocking */
1723dc7dba0Sbouyer #define SF_CHIP_GEBUG	0x00080000 /* SCSI gross error bug */
173eefc140cSbouyer #define SF_CHIP_AAIP	0x00100000 /* Always generate AIP regardless of SNCTL4*/
174e410e26fSskrll #define SF_CHIP_BE	0x00200000 /* big-endian */
175c3b43ec5Skiyohara #define SF_CHIP_USEPCIC	0x00400000 /* use PCI clock */
1767777f61cSbouyer 
17797fe8b91Sbouyer #define SF_PCI_RL	0x01000000 /* PCI read line */
17897fe8b91Sbouyer #define SF_PCI_RM	0x02000000 /* PCI read multiple */
17997fe8b91Sbouyer #define SF_PCI_BOF	0x04000000 /* PCI burst opcode fetch */
18097fe8b91Sbouyer #define SF_PCI_CLS	0x08000000 /* PCI cache line size */
18197fe8b91Sbouyer #define SF_PCI_WRI	0x10000000 /* PCI write and invalidate */
18286301452Sbouyer 
18318db93c7Sperry int	siop_common_attach(struct siop_common_softc *);
18418db93c7Sperry void	siop_common_reset(struct siop_common_softc *);
18518db93c7Sperry void	siop_setuptables(struct siop_common_cmd *);
18618db93c7Sperry int	siop_modechange(struct siop_common_softc *);
18797fe8b91Sbouyer 
18818db93c7Sperry int	siop_wdtr_neg(struct siop_common_cmd *);
18918db93c7Sperry int	siop_sdtr_neg(struct siop_common_cmd *);
19018db93c7Sperry int	siop_ppr_neg(struct siop_common_cmd *);
19118db93c7Sperry void	siop_sdtr_msg(struct siop_common_cmd *, int, int, int);
19218db93c7Sperry void	siop_wdtr_msg(struct siop_common_cmd *, int, int);
19318db93c7Sperry void	siop_ppr_msg(struct siop_common_cmd *, int, int, int);
19418db93c7Sperry void	siop_update_xfer_mode(struct siop_common_softc *, int);
19518db93c7Sperry int	siop_iwr(struct siop_common_cmd *);
196516871a5Sbouyer /* actions to take at return of siop_wdtr_neg(), siop_sdtr_neg() and siop_iwr */
19786301452Sbouyer #define SIOP_NEG_NOP	0x0
19886301452Sbouyer #define SIOP_NEG_MSGOUT	0x1
19986301452Sbouyer #define SIOP_NEG_ACK	0x2
20086301452Sbouyer 
20118db93c7Sperry void	siop_minphys(struct buf *);
20218db93c7Sperry int	siop_ioctl(struct scsipi_channel *, u_long,
20353524e44Schristos 		void *, int, struct proc *);
20418db93c7Sperry void	siop_ma (struct siop_common_cmd *);
20518db93c7Sperry void	siop_sdp(struct siop_common_cmd *, int);
20618db93c7Sperry void	siop_update_resid(struct siop_common_cmd *, int);
20718db93c7Sperry void	siop_clearfifo(struct siop_common_softc *);
20818db93c7Sperry void	siop_resetbus(struct siop_common_softc *);
209e410e26fSskrll 
210e410e26fSskrll #define siop_htoc32(sc, x) \
211e410e26fSskrll   (((sc)->features & SF_CHIP_BE) ? htobe32((x)) : htole32((x)))
212e410e26fSskrll 
213e410e26fSskrll #define siop_ctoh32(sc, x) \
214e410e26fSskrll   (((sc)->features & SF_CHIP_BE) ? be32toh((x)) : le32toh((x)))
215