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