Home | History | Annotate | Line # | Download | only in ic
ninjascsi32var.h revision 1.2
      1  1.2  thorpej /*	$NetBSD: ninjascsi32var.h,v 1.2 2004/08/26 18:38:19 thorpej Exp $	*/
      2  1.1    itohy 
      3  1.1    itohy /*-
      4  1.1    itohy  * Copyright (c) 2004 The NetBSD Foundation, Inc.
      5  1.1    itohy  * All rights reserved.
      6  1.1    itohy  *
      7  1.1    itohy  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1    itohy  * by ITOH Yasufumi.
      9  1.1    itohy  *
     10  1.1    itohy  * Redistribution and use in source and binary forms, with or without
     11  1.1    itohy  * modification, are permitted provided that the following conditions
     12  1.1    itohy  * are met:
     13  1.1    itohy  * 1. Redistributions of source code must retain the above copyright
     14  1.1    itohy  *    notice, this list of conditions and the following disclaimer.
     15  1.1    itohy  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1    itohy  *    notice, this list of conditions and the following disclaimer in the
     17  1.1    itohy  *    documentation and/or other materials provided with the distribution.
     18  1.1    itohy  * 3. All advertising materials mentioning features or use of this software
     19  1.1    itohy  *    must display the following acknowledgement:
     20  1.1    itohy  *	This product includes software developed by the NetBSD
     21  1.1    itohy  *	Foundation, Inc. and its contributors.
     22  1.1    itohy  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1    itohy  *    contributors may be used to endorse or promote products derived
     24  1.1    itohy  *    from this software without specific prior written permission.
     25  1.1    itohy  *
     26  1.1    itohy  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1    itohy  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1    itohy  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1    itohy  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1    itohy  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1    itohy  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1    itohy  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1    itohy  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1    itohy  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1    itohy  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1    itohy  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1    itohy  */
     38  1.1    itohy 
     39  1.1    itohy #ifndef _NJSC32VAR_H_
     40  1.1    itohy #define _NJSC32VAR_H_
     41  1.1    itohy 
     42  1.1    itohy typedef unsigned	njsc32_model_t;
     43  1.1    itohy #define NJSC32_MODEL_MASK	0xff
     44  1.1    itohy #define NJSC32_MODEL_INVALID	0
     45  1.1    itohy #define NJSC32_MODEL_32BI	1
     46  1.1    itohy #define NJSC32_MODEL_32UDE	2
     47  1.1    itohy #define NJSC32_FLAG_DUALEDGE	0x100	/* supports DualEdge */
     48  1.1    itohy 
     49  1.1    itohy /*
     50  1.1    itohy  * time parameters (25us per unit?)
     51  1.1    itohy  */
     52  1.1    itohy #define NJSC32_SEL_TIMEOUT_TIME		20000	/* selection timeout (500ms) */
     53  1.1    itohy #define NJSC32_ARBITRATION_RETRY_TIME	4	/* 100us */
     54  1.1    itohy 
     55  1.1    itohy /* in microseconds */
     56  1.1    itohy #define NJSC32_REQ_TIMEOUT		10000	/* 10ms */
     57  1.1    itohy #define NJSC32_RESET_HOLD_TIME		30	/* 25us min */
     58  1.1    itohy 
     59  1.1    itohy /*
     60  1.1    itohy  * DMA page
     61  1.1    itohy  */
     62  1.1    itohy #ifdef NJSC32_AUTOPARAM
     63  1.1    itohy #define NJSC32_NUM_CMD	15	/* # simultaneous commands */
     64  1.1    itohy #else
     65  1.1    itohy #define NJSC32_NUM_CMD	16	/* # simultaneous commands */
     66  1.1    itohy #endif
     67  1.1    itohy #define NJSC32_NUM_SG	16	/* # scatter/gather table entries per command */
     68  1.1    itohy 
     69  1.1    itohy struct njsc32_dma_page {
     70  1.1    itohy 	/*
     71  1.1    itohy 	 * scatter/gather transfer table
     72  1.1    itohy 	 */
     73  1.1    itohy 	struct njsc32_sgtable	dp_sg[NJSC32_NUM_CMD][NJSC32_NUM_SG];
     74  1.1    itohy #define NJSC32_SIZE_SGT \
     75  1.1    itohy 	(sizeof(struct njsc32_sgtable) * NJSC32_NUM_SG)
     76  1.1    itohy 
     77  1.1    itohy #ifdef NJSC32_AUTOPARAM
     78  1.1    itohy 	/*
     79  1.1    itohy 	 * device reads parameters from this structure (autoparam)
     80  1.1    itohy 	 */
     81  1.1    itohy 	struct njsc32_autoparam	dp_ap;
     82  1.1    itohy #endif
     83  1.1    itohy };
     84  1.1    itohy 
     85  1.1    itohy /* per command */
     86  1.1    itohy struct njsc32_cmd {
     87  1.1    itohy 	TAILQ_ENTRY(njsc32_cmd)	c_q;
     88  1.1    itohy 	struct njsc32_softc	*c_sc;
     89  1.1    itohy 
     90  1.1    itohy 	/* on transfer */
     91  1.1    itohy 	struct scsipi_xfer	*c_xs;
     92  1.1    itohy 	struct njsc32_target	*c_target;
     93  1.1    itohy 	struct njsc32_lu	*c_lu;
     94  1.1    itohy 	u_int32_t		c_datacnt;	/* I/O buffer length */
     95  1.1    itohy 
     96  1.1    itohy 	/* command status */
     97  1.1    itohy 	int		c_flags;
     98  1.1    itohy #define NJSC32_CMD_DMA_MAPPED	0x01
     99  1.1    itohy #define NJSC32_CMD_TAGGED	0x02
    100  1.1    itohy #define NJSC32_CMD_TAGGED_HEAD	0x04
    101  1.1    itohy 
    102  1.1    itohy 	/* SCSI pointer */
    103  1.1    itohy 	u_int32_t	c_dp_cur;	/* current (or active) data pointer */
    104  1.1    itohy 	u_int32_t	c_dp_saved;	/* saved data pointer */
    105  1.1    itohy 	u_int32_t	c_dp_max;	/* max value of data pointer */
    106  1.1    itohy 
    107  1.1    itohy 	/* last loaded scatter/gather table */
    108  1.1    itohy 	unsigned	c_sgoffset;	/* # skip entries */
    109  1.1    itohy 	u_int32_t	c_sgfixcnt;	/* # skip bytes in the top entry */
    110  1.1    itohy 
    111  1.1    itohy 	/* command start/restart parameter */
    112  1.1    itohy 	u_int8_t	c_msg_identify;	/* Identify message */
    113  1.1    itohy 	u_int16_t	c_xferctl;
    114  1.1    itohy 	u_int32_t	c_sgtdmaaddr;
    115  1.1    itohy 
    116  1.1    itohy 	/* DMA resource */
    117  1.1    itohy 	struct njsc32_sgtable	*c_sgt;		/* for host */
    118  1.1    itohy 	bus_addr_t		c_sgt_dma;	/* for device */
    119  1.1    itohy #define NJSC32_CMD_DMAADDR_SGT(cmd, n)	\
    120  1.1    itohy 		((cmd)->c_sgt_dma + sizeof(struct njsc32_sgtable) * (n))
    121  1.1    itohy 	bus_dmamap_t		c_dmamap_xfer;
    122  1.1    itohy };
    123  1.1    itohy 
    124  1.1    itohy /* XXX? */
    125  1.1    itohy #define NJSC32_MAX_XFER	(NJSC32_NUM_SG << PGSHIFT)
    126  1.1    itohy 
    127  1.1    itohy struct njsc32_softc {
    128  1.1    itohy 	struct device	sc_dev;
    129  1.1    itohy 
    130  1.1    itohy 	/* device spec */
    131  1.1    itohy 	njsc32_model_t		sc_model;
    132  1.1    itohy 
    133  1.1    itohy 	int			sc_clk;		/* one of following */
    134  1.1    itohy #define NJSC32_CLK_40M		NJSC32_CLOCK_DIV_4	/* 20MB/s */
    135  1.1    itohy #define NJSC32_CLK_20M		NJSC32_CLOCK_DIV_2	/* 10MB/s */
    136  1.1    itohy #define NJSC32_CLK_PCI_33M	NJSC32_CLOCK_PCICLK	/* 16.6MB/s */
    137  1.1    itohy 
    138  1.1    itohy 	/* device register */
    139  1.1    itohy 	bus_space_tag_t		sc_regt;
    140  1.1    itohy 	bus_space_handle_t	sc_regh;
    141  1.1    itohy 
    142  1.1    itohy 	unsigned		sc_flags;
    143  1.1    itohy #define NJSC32_IO_MAPPED		0x00000001
    144  1.1    itohy #define NJSC32_MEM_MAPPED		0x00000002
    145  1.1    itohy #define NJSC32_CMDPG_MAPPED		0x00000004
    146  1.1    itohy #define NJSC32_CANNOT_SUPPLY_TERMPWR	0x00000100
    147  1.1    itohy 
    148  1.1    itohy 	/*
    149  1.1    itohy 	 * controller state
    150  1.1    itohy 	 */
    151  1.1    itohy 	enum njsc32_stat {
    152  1.1    itohy 		NJSC32_STAT_IDLE,
    153  1.1    itohy 		NJSC32_STAT_ARBIT,	/* initiator started arbitration */
    154  1.1    itohy 		NJSC32_STAT_CONNECT,	/* command is active (connection) */
    155  1.1    itohy 		NJSC32_STAT_RESEL,	/* a target did Reselection */
    156  1.1    itohy 		NJSC32_STAT_RESEL_LUN,	/* received Identify message */
    157  1.1    itohy 		NJSC32_STAT_RECONNECT,	/* command is active (reconnection) */
    158  1.1    itohy 		NJSC32_STAT_DETACH	/* detaching */
    159  1.1    itohy 	} sc_stat;
    160  1.1    itohy 
    161  1.1    itohy 	/* interrupt handle */
    162  1.1    itohy 	void			*sc_ih;
    163  1.1    itohy 
    164  1.1    itohy 	/* for DMA */
    165  1.1    itohy 	bus_dma_tag_t		sc_dmat;
    166  1.1    itohy 	struct njsc32_dma_page	*sc_cmdpg;	/* scatter/gather table page */
    167  1.1    itohy #if 0
    168  1.1    itohy 	bus_addr_t		sc_cmdpg_dma;
    169  1.1    itohy #endif
    170  1.1    itohy 	bus_dma_segment_t	sc_cmdpg_seg;
    171  1.1    itohy 	bus_dmamap_t		sc_dmamap_cmdpg;
    172  1.1    itohy 	int			sc_cmdpg_nsegs;
    173  1.1    itohy 
    174  1.1    itohy #ifdef NJSC32_AUTOPARAM
    175  1.1    itohy 	u_int32_t		sc_ap_dma;	/* autoparam DMA address */
    176  1.1    itohy #endif
    177  1.1    itohy 
    178  1.1    itohy 	/*
    179  1.1    itohy 	 * command control structure
    180  1.1    itohy 	 */
    181  1.1    itohy 	struct njsc32_cmd	sc_cmds[NJSC32_NUM_CMD];
    182  1.1    itohy 	TAILQ_HEAD(njsc32_cmd_head, njsc32_cmd)
    183  1.1    itohy 				sc_freecmd,	/* free list */
    184  1.1    itohy 				sc_reqcmd;	/* waiting commands */
    185  1.1    itohy 
    186  1.1    itohy 	struct njsc32_cmd	*sc_curcmd;	/* currently active command */
    187  1.1    itohy 	int			sc_ncmd;	/* total # commands available */
    188  1.1    itohy 	int			sc_nusedcmds;	/* # used commands */
    189  1.1    itohy 
    190  1.1    itohy 	/* reselection */
    191  1.1    itohy 	int			sc_reselid, sc_resellun;
    192  1.1    itohy 
    193  1.1    itohy 	/* message in buffer */
    194  1.1    itohy #define NJSC32_MSGIN_LEN	20
    195  1.1    itohy 	u_int8_t		sc_msginbuf[NJSC32_MSGIN_LEN];
    196  1.1    itohy 	int			sc_msgincnt;
    197  1.1    itohy 
    198  1.1    itohy 	/* message out buffer */
    199  1.1    itohy #define NJSC32_MSGOUT_LEN	16
    200  1.1    itohy 	u_int8_t		sc_msgout[NJSC32_MSGOUT_LEN];
    201  1.1    itohy 	size_t			sc_msgoutlen;
    202  1.1    itohy 	size_t			sc_msgoutidx;
    203  1.1    itohy 
    204  1.1    itohy 	/* sync timing table */
    205  1.1    itohy 	const struct njsc32_sync_param {
    206  1.1    itohy 		u_int8_t	sp_period;	/* transfer period */
    207  1.1    itohy 		u_int8_t	sp_ackw;	/* ACK width parameter */
    208  1.1    itohy 		u_int8_t	sp_sample;	/* sampling period */
    209  1.1    itohy 	} *sc_synct;
    210  1.1    itohy 	int	sc_sync_max;
    211  1.1    itohy 
    212  1.1    itohy 	/* for scsipi layer */
    213  1.1    itohy 	struct device		*sc_scsi;
    214  1.1    itohy 	struct scsipi_adapter	sc_adapter;
    215  1.1    itohy 	struct scsipi_channel	sc_channel;
    216  1.1    itohy 
    217  1.1    itohy 	/* per-target */
    218  1.1    itohy 	struct njsc32_target {
    219  1.1    itohy 		enum njsc32_tarst {
    220  1.1    itohy 			NJSC32_TARST_DONE,	/* negotiation done */
    221  1.1    itohy 			NJSC32_TARST_INIT,
    222  1.1    itohy 			NJSC32_TARST_DE,	/* negotiating DualEdge */
    223  1.1    itohy 			NJSC32_TARST_WDTR,	/* negotiating width */
    224  1.1    itohy 			NJSC32_TARST_SDTR,	/* negotiating sync */
    225  1.1    itohy 			NJSC32_TARST_ASYNC	/* negotiating async */
    226  1.1    itohy 		} t_state;
    227  1.1    itohy 		int	t_flags;
    228  1.1    itohy #define NJSC32_TARF_TAG		0x0001	/* tagged queueing is enabled */
    229  1.1    itohy #define NJSC32_TARF_SYNC	0x0002	/* negotiate for sync transfer */
    230  1.1    itohy #define NJSC32_TARF_DE		0x0004	/* negotiate for DualEdge transfer */
    231  1.1    itohy 
    232  1.1    itohy 		int		t_syncperiod;
    233  1.1    itohy 		int		t_syncoffset;
    234  1.1    itohy 
    235  1.1    itohy 		u_int8_t	t_sync;
    236  1.1    itohy 		u_int8_t	t_ackwidth;
    237  1.1    itohy 		u_int8_t	t_targetid;	/* initiator and target id */
    238  1.1    itohy 		u_int8_t	t_sample;
    239  1.1    itohy 
    240  1.1    itohy 		u_int16_t	t_xferctl;	/* DualEdge flag */
    241  1.1    itohy 
    242  1.1    itohy 		/* per logical unit */
    243  1.1    itohy 		struct njsc32_lu {
    244  1.1    itohy 			/*
    245  1.1    itohy 			 * disconnected commands
    246  1.1    itohy 			 */
    247  1.1    itohy 			struct njsc32_cmd *lu_cmd;	/* untagged command */
    248  1.1    itohy 			struct njsc32_cmd_head	lu_q;	/* tagged commands */
    249  1.1    itohy 		} t_lus[NJSC32_NLU];
    250  1.1    itohy 	} sc_targets[NJSC32_MAX_TARGET_ID + 1];
    251  1.1    itohy };
    252  1.1    itohy 
    253  1.1    itohy #ifdef _KERNEL
    254  1.2  thorpej void	njsc32_attach(struct njsc32_softc *);
    255  1.2  thorpej int	njsc32_detach(struct njsc32_softc *, int);
    256  1.2  thorpej int	njsc32_intr(void *);
    257  1.1    itohy #endif
    258  1.1    itohy 
    259  1.1    itohy #endif	/* _NJSC32VAR_H_ */
    260