Home | History | Annotate | Line # | Download | only in ic
osiopvar.h revision 1.10.16.1
      1  1.10.16.1       ad /*	$NetBSD: osiopvar.h,v 1.10.16.1 2007/12/26 19:46:20 ad Exp $	*/
      2        1.1  tsutsui 
      3        1.1  tsutsui /*
      4        1.1  tsutsui  * Copyright (c) 2001 Izumi Tsutsui.  All rights reserved.
      5        1.1  tsutsui  *
      6        1.1  tsutsui  * Redistribution and use in source and binary forms, with or without
      7        1.1  tsutsui  * modification, are permitted provided that the following conditions
      8        1.1  tsutsui  * are met:
      9        1.1  tsutsui  * 1. Redistributions of source code must retain the above copyright
     10        1.1  tsutsui  *    notice, this list of conditions and the following disclaimer.
     11        1.1  tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     12        1.1  tsutsui  *    notice, this list of conditions and the following disclaimer in the
     13        1.1  tsutsui  *    documentation and/or other materials provided with the distribution.
     14        1.1  tsutsui  * 3. The name of the author may not be used to endorse or promote products
     15        1.1  tsutsui  *    derived from this software without specific prior written permission.
     16        1.1  tsutsui  *
     17        1.1  tsutsui  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18        1.1  tsutsui  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19        1.1  tsutsui  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20        1.1  tsutsui  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21        1.1  tsutsui  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22        1.1  tsutsui  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23        1.1  tsutsui  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24        1.1  tsutsui  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25        1.1  tsutsui  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26        1.1  tsutsui  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27        1.1  tsutsui  */
     28        1.1  tsutsui 
     29        1.1  tsutsui /*
     30        1.1  tsutsui  * Copyright (c) 1990 The Regents of the University of California.
     31        1.1  tsutsui  * All rights reserved.
     32        1.1  tsutsui  *
     33        1.1  tsutsui  * This code is derived from software contributed to Berkeley by
     34        1.1  tsutsui  * Van Jacobson of Lawrence Berkeley Laboratory.
     35        1.1  tsutsui  *
     36        1.1  tsutsui  * Redistribution and use in source and binary forms, with or without
     37        1.1  tsutsui  * modification, are permitted provided that the following conditions
     38        1.1  tsutsui  * are met:
     39        1.1  tsutsui  * 1. Redistributions of source code must retain the above copyright
     40        1.1  tsutsui  *    notice, this list of conditions and the following disclaimer.
     41        1.1  tsutsui  * 2. Redistributions in binary form must reproduce the above copyright
     42        1.1  tsutsui  *    notice, this list of conditions and the following disclaimer in the
     43        1.1  tsutsui  *    documentation and/or other materials provided with the distribution.
     44        1.4      agc  * 3. Neither the name of the University nor the names of its contributors
     45        1.1  tsutsui  *    may be used to endorse or promote products derived from this software
     46        1.1  tsutsui  *    without specific prior written permission.
     47        1.1  tsutsui  *
     48        1.1  tsutsui  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     49        1.1  tsutsui  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     50        1.1  tsutsui  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     51        1.1  tsutsui  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     52        1.1  tsutsui  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     53        1.1  tsutsui  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     54        1.1  tsutsui  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     55        1.1  tsutsui  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     56        1.1  tsutsui  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     57        1.1  tsutsui  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     58        1.1  tsutsui  * SUCH DAMAGE.
     59        1.1  tsutsui  *
     60        1.1  tsutsui  *	@(#)siopvar.h	7.1 (Berkeley) 5/8/90
     61        1.1  tsutsui  */
     62        1.1  tsutsui 
     63        1.1  tsutsui #define osiop_read_1(sc, reg)					\
     64        1.1  tsutsui     bus_space_read_1((sc)->sc_bst, (sc)->sc_reg, reg)
     65        1.1  tsutsui #define osiop_write_1(sc, reg, val)				\
     66        1.1  tsutsui     bus_space_write_1((sc)->sc_bst, (sc)->sc_reg, reg, val)
     67        1.1  tsutsui 
     68        1.1  tsutsui #define osiop_read_4(sc, reg)					\
     69        1.1  tsutsui     bus_space_read_4((sc)->sc_bst, (sc)->sc_reg, reg)
     70        1.1  tsutsui #define osiop_write_4(sc, reg, val)				\
     71        1.8    perry     bus_space_write_4((sc)->sc_bst, (sc)->sc_reg, reg, val)
     72        1.8    perry 
     73        1.1  tsutsui /*
     74        1.1  tsutsui  * The largest single request will be MAXPHYS bytes which will require
     75        1.1  tsutsui  * at most MAXPHYS/NBPG+1 chain elements to describe, i.e. if none of
     76        1.1  tsutsui  * the buffer pages are physically contiguous (MAXPHYS/NBPG) and the
     77        1.1  tsutsui  * buffer is not page aligned (+1).
     78        1.1  tsutsui  */
     79        1.1  tsutsui /* XXX This should be (MAXPHYS / NBPG + 1), but hardcoded in script */
     80        1.1  tsutsui #define OSIOP_NSG	(16 + 1)
     81        1.1  tsutsui #if MAXPHYS > (PAGE_SIZE * (OSIOP_NSG - 1))
     82        1.1  tsutsui #define OSIOP_MAX_XFER	(PAGE_SIZE * (OSIOP_NSG - 1))
     83        1.1  tsutsui #else
     84        1.1  tsutsui #define OSIOP_MAX_XFER	MAXPHYS
     85        1.1  tsutsui #endif
     86        1.1  tsutsui 
     87        1.1  tsutsui #define OSIOP_NTGT 8
     88        1.1  tsutsui #define OSIOP_NACB 32	/* XXX (PAGE_SIZE / sizeof(osiop_ds)) is better? */
     89        1.1  tsutsui 
     90        1.1  tsutsui /*
     91        1.1  tsutsui  * Data Structure for SCRIPTS program
     92        1.1  tsutsui  */
     93        1.1  tsutsui typedef struct buf_table {
     94        1.6  tsutsui 	uint32_t count;
     95        1.6  tsutsui 	uint32_t addr;
     96        1.1  tsutsui } buf_table_t;
     97        1.1  tsutsui 
     98        1.1  tsutsui struct osiop_ds {
     99       1.10  tsutsui 	uint32_t scsi_addr;		/*   0: SCSI ID & sync */
    100       1.10  tsutsui 	uint32_t pad1;			/*   4: padding */
    101       1.10  tsutsui 	buf_table_t id;			/*   8: Identify message */
    102       1.10  tsutsui 	buf_table_t cmd;		/*  16: SCSI command */
    103       1.10  tsutsui 	buf_table_t status;		/*  24: Status */
    104       1.10  tsutsui 	buf_table_t msg;		/*  32: Message */
    105       1.10  tsutsui 	buf_table_t msgin;		/*  40: Message in */
    106       1.10  tsutsui 	buf_table_t extmsg;		/*  48: Extended message in */
    107       1.10  tsutsui 	buf_table_t synmsg;		/*  56: Sync transfer request */
    108       1.10  tsutsui 	buf_table_t data[OSIOP_NSG];	/*  64: DMA S/G buffers */
    109       1.10  tsutsui 					/*      (8 * OSIOP_NSG == 136bytes) */
    110       1.10  tsutsui 	uint8_t scsipi_cmd[16];		/* 200: cmd buf */
    111       1.10  tsutsui 	uint8_t msgout[8];		/* 216: message out buf */
    112       1.10  tsutsui 	uint8_t msgbuf[8];		/* 224: message in buf */
    113       1.10  tsutsui 	uint8_t stat[8];		/* 232: stat buf */
    114       1.10  tsutsui 	uint8_t pad2[16];		/* 240: padding to 256bytes */
    115  1.10.16.1       ad } __packed;
    116        1.1  tsutsui 
    117        1.5      wiz /* status can hold the SCSI_* status values, and 2 additional values: */
    118        1.1  tsutsui #define SCSI_OSIOP_NOCHECK	0xfe	/* don't check the scsi status */
    119        1.1  tsutsui #define SCSI_OSIOP_NOSTATUS	0xff	/* device didn't report status */
    120        1.1  tsutsui 
    121        1.1  tsutsui #define MSG_INVALID		0xff	/* dummy value for message buffer */
    122        1.1  tsutsui 
    123        1.1  tsutsui #define OSIOP_DSOFF(x)		offsetof(struct osiop_ds, x)
    124       1.10  tsutsui #define OSIOP_DSCMDOFF		OSIOP_DSOFF(scsipi_cmd[0])
    125        1.1  tsutsui #define OSIOP_DSIDOFF		OSIOP_DSOFF(msgout[0])
    126        1.1  tsutsui #define OSIOP_DSMSGOFF		OSIOP_DSOFF(msgbuf[0])
    127        1.1  tsutsui #define OSIOP_DSMSGINOFF	OSIOP_DSOFF(msgbuf[1])
    128        1.1  tsutsui #define OSIOP_DSEXTMSGOFF	OSIOP_DSOFF(msgbuf[2])
    129        1.1  tsutsui #define OSIOP_DSSYNMSGOFF	OSIOP_DSOFF(msgbuf[3])
    130        1.1  tsutsui #define OSIOP_DSSTATOFF		OSIOP_DSOFF(stat[0])
    131        1.1  tsutsui 
    132        1.1  tsutsui /*
    133        1.1  tsutsui  * ACB. Holds additional information for each SCSI command Comments:
    134        1.1  tsutsui  * Basicly, we refrain from fiddling with the scsi_xfer struct
    135        1.1  tsutsui  * (except do the expected updating of return values).
    136        1.1  tsutsui  * We'll generally update: xs->{flags,resid,error,status} and
    137        1.1  tsutsui  * occasionally xs->retries.
    138        1.1  tsutsui  */
    139        1.1  tsutsui struct osiop_acb {
    140        1.1  tsutsui 	TAILQ_ENTRY(osiop_acb) chain;
    141        1.1  tsutsui 	struct scsipi_xfer *xs;	/* SCSI xfer ctrl block from upper layer */
    142        1.1  tsutsui 	struct osiop_softc *sc;	/* points back to our adapter */
    143        1.1  tsutsui 
    144        1.1  tsutsui 	bus_dmamap_t datadma;	/* DMA map for data transfer */
    145        1.1  tsutsui 
    146        1.1  tsutsui 	struct osiop_ds *ds;	/* data structure for this acb */
    147        1.1  tsutsui 	bus_size_t dsoffset;	/* offset of data structure for this acb */
    148        1.1  tsutsui 
    149        1.1  tsutsui 	bus_size_t cmdlen;	/* command length */
    150        1.1  tsutsui 	bus_size_t datalen;	/* transfer data length */
    151        1.1  tsutsui #ifdef OSIOP_DEBUG
    152        1.1  tsutsui 	void *data;		/* transfer data buffer ptr */
    153        1.1  tsutsui #endif
    154        1.1  tsutsui 
    155        1.1  tsutsui 	bus_addr_t curaddr;	/* current transfer data buffer */
    156        1.1  tsutsui 	bus_size_t curlen;	/* current transfer data length */
    157        1.1  tsutsui 
    158        1.1  tsutsui 	int status;		/* status of this acb */
    159        1.1  tsutsui /* status defs */
    160        1.1  tsutsui #define ACB_S_FREE	0	/* cmd slot is free */
    161        1.1  tsutsui #define ACB_S_READY	1	/* cmd slot is waiting for processing */
    162        1.1  tsutsui #define ACB_S_ACTIVE	2	/* cmd slot is being processed */
    163        1.1  tsutsui #define ACB_S_DONE	3	/* cmd slot has been processed */
    164        1.1  tsutsui 
    165        1.1  tsutsui 	int flags;		/* cmd slot flags */
    166        1.1  tsutsui #define ACB_F_TIMEOUT	0x01	/* command timeout */
    167        1.1  tsutsui 
    168        1.6  tsutsui 	uint8_t intstat;	/* buffer to save sc_flags on disconnect */
    169        1.1  tsutsui };
    170        1.1  tsutsui 
    171        1.1  tsutsui /*
    172        1.1  tsutsui  * Some info about each (possible) target on the SCSI bus.  This should
    173        1.1  tsutsui  * probably have been a "per target+lunit" structure, but we'll leave it at
    174        1.1  tsutsui  * this for now.  Is there a way to reliably hook it up to sc->fordriver??
    175        1.1  tsutsui  */
    176        1.1  tsutsui struct osiop_tinfo {
    177        1.1  tsutsui 	int cmds;		/* number of commands processed */
    178        1.1  tsutsui 	int dconns;		/* number of disconnects */
    179        1.1  tsutsui 	int touts;		/* number of timeouts */
    180        1.1  tsutsui 	int perrs;		/* number of parity errors */
    181        1.2  tsutsui 	int lubusy;		/* What local units/subr. are busy? */
    182        1.2  tsutsui 	int period;		/* Period suggestion */
    183        1.2  tsutsui 	int offset;		/* Offset suggestion */
    184        1.2  tsutsui 	int flags;		/* misc flags per each target */
    185        1.1  tsutsui #define TI_NOSYNC	0x01	/* disable sync xfer on this target */
    186        1.1  tsutsui #define TI_NODISC	0x02	/* disable disconnect on this target */
    187        1.2  tsutsui 	int state;		/* negotiation state */
    188        1.6  tsutsui 	uint8_t sxfer;		/* value for SXFER reg */
    189        1.6  tsutsui 	uint8_t sbcl;		/* value for SBCL reg */
    190        1.3     matt };
    191        1.1  tsutsui 
    192        1.1  tsutsui struct osiop_softc {
    193        1.1  tsutsui 	struct device sc_dev;
    194        1.1  tsutsui 
    195        1.1  tsutsui 	bus_space_tag_t sc_bst;		/* bus space tag */
    196        1.1  tsutsui 	bus_space_handle_t sc_reg;	/* register I/O handle */
    197        1.1  tsutsui 
    198        1.1  tsutsui 	bus_dma_tag_t sc_dmat;		/* bus dma tag */
    199        1.1  tsutsui 	bus_dmamap_t sc_scrdma;		/* script dma map */
    200        1.1  tsutsui 	bus_dmamap_t sc_dsdma;		/* script data dma map */
    201        1.1  tsutsui 
    202        1.6  tsutsui 	uint32_t *sc_script;		/* ptr to script memory */
    203        1.1  tsutsui 	struct osiop_ds *sc_ds;		/* ptr to data structure memory */
    204        1.1  tsutsui 
    205        1.1  tsutsui 	int sc_id;			/* adapter SCSI id */
    206        1.1  tsutsui 	int sc_active;			/* number of active I/O's */
    207        1.1  tsutsui 
    208        1.1  tsutsui 	struct osiop_acb *sc_nexus;	/* current command */
    209        1.1  tsutsui 	struct osiop_acb *sc_acb;	/* the real command blocks */
    210        1.1  tsutsui 
    211        1.1  tsutsui 	/* Lists of command blocks */
    212        1.1  tsutsui 	TAILQ_HEAD(acb_list, osiop_acb) free_list,
    213        1.1  tsutsui 				        ready_list,
    214        1.1  tsutsui 				        nexus_list;
    215        1.1  tsutsui 
    216        1.1  tsutsui 	struct scsipi_adapter sc_adapter;
    217        1.1  tsutsui 	struct scsipi_channel sc_channel;
    218        1.1  tsutsui 
    219        1.1  tsutsui 	struct osiop_tinfo sc_tinfo[OSIOP_NTGT];
    220        1.1  tsutsui 
    221        1.1  tsutsui 	int sc_clock_freq;
    222        1.1  tsutsui 	int sc_tcp[4];
    223        1.1  tsutsui 	int sc_flags;
    224        1.1  tsutsui #define OSIOP_INTSOFF	0x80	/* Interrupts turned off */
    225        1.1  tsutsui #define OSIOP_INTDEFER	0x40	/* MD interrupt has been deferred */
    226        1.1  tsutsui #define OSIOP_NODMA	0x02	/* No DMA transfer */
    227        1.1  tsutsui #define OSIOP_ALIVE	0x01	/* controller initialized */
    228        1.1  tsutsui 
    229        1.1  tsutsui 	int sc_cfflags;			/* copy of config flags */
    230        1.1  tsutsui 
    231        1.2  tsutsui 	int sc_minsync;
    232        1.1  tsutsui 
    233        1.6  tsutsui 	uint8_t sc_dstat;
    234        1.6  tsutsui 	uint8_t sc_sstat0;
    235        1.6  tsutsui 	uint8_t sc_sstat1;
    236        1.6  tsutsui 	uint8_t sc_istat;
    237        1.6  tsutsui 	uint8_t sc_dcntl;
    238        1.7  tsutsui 	uint8_t sc_ctest4;
    239        1.6  tsutsui 	uint8_t sc_ctest7;
    240        1.6  tsutsui 	uint8_t sc_sien;
    241        1.6  tsutsui 	uint8_t sc_dien;
    242        1.1  tsutsui };
    243        1.1  tsutsui 
    244        1.1  tsutsui /* negotiation states */
    245        1.1  tsutsui #define NEG_INIT	0	/* Initial negotiate state */
    246        1.2  tsutsui #define NEG_SYNC	NEG_INIT /* Negotiate synch transfers */
    247        1.5      wiz #define NEG_WAITS	1	/* Waiting for synch negotiation response */
    248        1.5      wiz #define NEG_DONE	2	/* Wide and/or sync negotiation done */
    249        1.1  tsutsui 
    250        1.1  tsutsui void osiop_attach(struct osiop_softc *);
    251        1.1  tsutsui void osiop_intr(struct osiop_softc *);
    252