Home | History | Annotate | Line # | Download | only in dev
      1  1.12     isaki /*	$NetBSD: mhavar.h,v 1.12 2024/01/07 07:58:33 isaki Exp $	*/
      2   1.1       oki 
      3   1.1       oki /*
      4   1.1       oki  * Copyright (c) 1994 Peter Galbavy.  All rights reserved.
      5   1.1       oki  *
      6   1.1       oki  * Redistribution and use in source and binary forms, with or without
      7   1.1       oki  * modification, are permitted provided that the following conditions
      8   1.1       oki  * are met:
      9   1.1       oki  * 1. Redistributions of source code must retain the above copyright
     10   1.1       oki  *    notice, this list of conditions and the following disclaimer.
     11   1.1       oki  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1       oki  *    notice, this list of conditions and the following disclaimer in the
     13   1.1       oki  *    documentation and/or other materials provided with the distribution.
     14   1.1       oki  * 3. All advertising materials mentioning features or use of this software
     15   1.1       oki  *    must display the following acknowledgement:
     16   1.1       oki  *	This product includes software developed by Peter Galbavy.
     17   1.1       oki  * 4. The name of the author may not be used to endorse or promote products
     18   1.1       oki  *    derived from this software without specific prior written permission.
     19   1.1       oki  *
     20   1.1       oki  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21   1.1       oki  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22   1.1       oki  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23   1.1       oki  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24   1.1       oki  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25   1.1       oki  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26   1.1       oki  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27   1.1       oki  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28   1.1       oki  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29   1.1       oki  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30   1.1       oki  */
     31   1.1       oki 
     32   1.1       oki /*
     33   1.1       oki  * ACB. Holds additional information for each SCSI command Comments: We
     34   1.1       oki  * need a separate scsi command block because we may need to overwrite it
     35  1.11    andvar  * with a request sense command.  Basically, we refrain from fiddling with
     36   1.1       oki  * the scsi_xfer struct (except do the expected updating of return values).
     37   1.1       oki  * We'll generally update: xs->{flags,resid,error,sense,status} and
     38   1.1       oki  * occasionally xs->retries.
     39   1.1       oki  */
     40   1.1       oki struct acb {
     41   1.1       oki 	TAILQ_ENTRY(acb) chain;
     42   1.1       oki 	struct scsipi_xfer *xs;	/* SCSI xfer ctrl block from above */
     43   1.1       oki 	int		flags;	/* Status */
     44   1.1       oki #define ACB_QNONE	0
     45   1.1       oki #define ACB_QFREE	1
     46   1.1       oki #define ACB_QREADY	2
     47   1.1       oki #define ACB_QNEXUS	3
     48   1.1       oki 
     49   1.1       oki #define ACB_QBITS	0x07
     50   1.1       oki #define ACB_CHKSENSE	0x08
     51   1.1       oki #define	ACB_ABORTED	0x10
     52   1.1       oki #define	ACB_RESET	0x80
     53   1.1       oki #define ACB_SETQ(e, q)	do (e)->flags = ((e)->flags&~ACB_QBITS)|(q); while(0)
     54   1.6   thorpej 	struct scsipi_generic cmd;  /* SCSI command block */
     55   1.1       oki 	int	 clen;
     56   1.1       oki 	char	*daddr;		/* Saved data pointer */
     57   1.1       oki 	int	 dleft;		/* Residue */
     58  1.12     isaki 	u_char	 stat;		/* SCSI status byte */
     59   1.1       oki 
     60   1.1       oki /*	struct spc_dma_seg dma[SPC_NSEG];*/ /* Physical addresses+len */
     61   1.1       oki };
     62   1.1       oki 
     63   1.1       oki /*
     64   1.1       oki  * Some info about each (possible) target on the SCSI bus.  This should
     65   1.1       oki  * probably have been a "per target+lunit" structure, but we'll leave it at
     66   1.1       oki  * this for now.
     67   1.1       oki  */
     68   1.1       oki struct spc_tinfo {
     69   1.1       oki 	int	cmds;		/* #commands processed */
     70   1.1       oki 	int	dconns;		/* #disconnects */
     71   1.1       oki 	int	touts;		/* #timeouts */
     72   1.1       oki 	int	perrs;		/* #parity errors */
     73   1.1       oki 	int	senses;		/* #request sense commands sent */
     74   1.1       oki 	ushort	lubusy;		/* What local units/subr. are busy? */
     75   1.1       oki 	u_char  flags;
     76   1.1       oki #define T_NEED_TO_RESET	0x01	/* Should send a BUS_DEV_RESET */
     77   1.1       oki #define T_NEGOTIATE	0x02	/* (Re)Negotiate synchronous options */
     78   1.1       oki #define T_BUSY		0x04	/* Target is busy, i.e. cmd in progress */
     79   1.1       oki #define T_SYNCMODE	0x08	/* sync mode has been negotiated */
     80   1.1       oki #define T_SYNCHOFF	0x10	/* .. */
     81   1.1       oki #define T_RSELECTOFF	0x20	/* .. */
     82   1.1       oki 	u_char  period;		/* Period suggestion */
     83   1.1       oki 	u_char  offset;		/* Offset suggestion */
     84   1.1       oki 	u_char	width;		/* Width suggestion */
     85  1.10      matt };
     86   1.1       oki 
     87   1.1       oki struct mha_softc {
     88   1.9     isaki 	device_t sc_dev;
     89   1.3   minoura 	volatile void *sc_iobase;
     90   1.1       oki 	volatile u_char	*sc_pc;
     91   1.1       oki 	volatile u_short *sc_ps;
     92   1.1       oki 	volatile u_char *sc_pcx;
     93   1.1       oki 
     94   1.5    bouyer 	struct scsipi_channel sc_channel;
     95   1.2   thorpej 	struct scsipi_adapter sc_adapter;
     96   1.1       oki 
     97   1.1       oki 	TAILQ_HEAD(, acb) free_list, ready_list, nexus_list;
     98   1.1       oki 	struct acb *sc_nexus;	/* current command */
     99   1.1       oki 	struct acb sc_acb[8];	/* one per target */
    100   1.1       oki 	struct spc_tinfo sc_tinfo[8];
    101   1.1       oki 
    102   1.1       oki 	/* Data about the current nexus (updated for every cmd switch) */
    103   1.1       oki 	u_char	*sc_dp;		/* Current data pointer */
    104   1.1       oki 	size_t	sc_dleft;	/* Data bytes left to transfer */
    105   1.1       oki 
    106   1.1       oki 	u_char	*sc_cp;		/* Current command pointer */
    107   1.1       oki 	size_t	sc_cleft;	/* Command bytes left to transfer */
    108   1.1       oki 
    109   1.1       oki 	/* Adapter state */
    110   1.1       oki 	int	sc_phase;	/* Copy of what bus phase we are in */
    111   1.1       oki 	int	sc_prevphase;	/* Copy of what bus phase we were in */
    112   1.1       oki 	u_char	sc_state;	/* State applicable to the adapter */
    113  1.12     isaki 	u_char	sc_flags;
    114   1.1       oki 	u_char	sc_selid;	/* Reselection ID */
    115  1.12     isaki 	volatile u_char	sc_spcinitialized;	/* */
    116   1.1       oki 
    117   1.1       oki 	/* Message stuff */
    118   1.1       oki 	u_char	sc_msgpriq;	/* Messages we want to send */
    119   1.1       oki 	u_char	sc_msgout;	/* What message is on its way out? */
    120   1.1       oki 	u_char	sc_msgoutq;	/* Messages sent during last MESSAGE OUT */
    121   1.1       oki 	u_char	sc_lastmsg;	/* Message last transmitted */
    122   1.1       oki 	u_char	sc_currmsg;	/* Message currently ready to transmit */
    123   1.1       oki #define SPC_MAX_MSG_LEN 8
    124  1.12     isaki 	u_char	sc_omess[SPC_MAX_MSG_LEN];
    125   1.1       oki 	u_char	*sc_omp;		/* Outgoing message pointer */
    126   1.1       oki 	u_char	sc_imess[SPC_MAX_MSG_LEN];
    127   1.1       oki 	u_char	*sc_imp;		/* Incoming message pointer */
    128   1.1       oki 	size_t	sc_imlen;
    129   1.1       oki 
    130   1.1       oki 	/* Hardware stuff */
    131   1.1       oki 	int	sc_freq;		/* Clock frequency in MHz */
    132   1.1       oki 	int	sc_id;			/* our scsi id */
    133   1.1       oki 	int	sc_minsync;		/* Minimum sync period / 4 */
    134   1.1       oki 	int	sc_maxsync;		/* Maximum sync period / 4 */
    135   1.4   minoura 
    136   1.4   minoura 	/* DMA buffer */
    137   1.4   minoura 	bus_dma_tag_t		sc_dmat;
    138   1.4   minoura 	bus_dma_segment_t	sc_dmaseg[1];
    139   1.4   minoura 	int			sc_ndmasegs;
    140   1.4   minoura 	bus_dmamap_t		sc_dmamap;
    141   1.8  christos 	void *			sc_dmabuf;
    142   1.4   minoura 	u_char			*sc_p;
    143   1.4   minoura 	u_int32_t		sc_dmasize;
    144   1.1       oki };
    145   1.1       oki 
    146   1.1       oki /* values for sc_state */
    147   1.1       oki #define	SPC_INIT	0x00
    148   1.1       oki #define SPC_IDLE	0x01	/* waiting for something to do */
    149   1.1       oki #define ESP_TMP_UNAVAIL	0x02	/* Don't accept SCSI commands */
    150   1.1       oki #define SPC_SELECTING	0x03	/* SCSI command is arbiting  */
    151   1.1       oki #define SPC_RESELECTED	0x04	/* Has been reselected */
    152   1.1       oki #define SPC_HASNEXUS	0x05	/* Actively using the SCSI bus */
    153   1.1       oki #define SPC_CLEANING	0x06
    154   1.1       oki #define ESP_SBR		0x07	/* Expect a SCSI RST because we commanded it */
    155   1.1       oki #define SPC_CONNECTED	0x08	/* Actively using the SCSI bus */
    156   1.1       oki #define	SPC_DISCONNECT	0x09	/* MSG_DISCONNECT received */
    157   1.1       oki #define	SPC_CMDCOMPLETE	0x0a	/* MSG_CMDCOMPLETE received */
    158   1.1       oki 
    159   1.1       oki 
    160   1.1       oki /* values for sc_flags */
    161   1.1       oki #define SPC_DROP_MSGI	0x01	/* Discard all msgs (parity err detected) */
    162   1.1       oki #define SPC_DOINGDMA	0x02	/* The FIFO data path is active! */
    163   1.1       oki #define SPC_BUSFREE_OK	0x04	/* Bus free phase is OK. */
    164   1.1       oki #define SPC_SYNCHNEGO	0x08	/* Synch negotiation in progress. */
    165   1.1       oki #define SPC_DISCON	0x10	/* Target sent DISCONNECT msg */
    166   1.1       oki #define	SPC_ABORTING	0x20	/* Bailing out */
    167   1.1       oki #define ESP_ICCS	0x40	/* Expect status phase results */
    168   1.1       oki #define ESP_WAITI	0x80	/* Waiting for non-DMA data to arrive */
    169   1.1       oki 
    170   1.1       oki 
    171   1.1       oki /* values for sc_msgout */
    172   1.1       oki #define SEND_DEV_RESET		0x01
    173   1.1       oki #define SEND_PARITY_ERROR	0x02
    174   1.1       oki #define SEND_INIT_DET_ERR	0x04
    175   1.1       oki #define SEND_REJECT		0x08
    176  1.12     isaki #define SEND_IDENTIFY		0x10
    177   1.1       oki #define SEND_ABORT		0x20
    178   1.1       oki #define SEND_SDTR		0x40
    179   1.1       oki #define	SEND_WDTR		0x80
    180   1.1       oki 
    181   1.1       oki /* SCSI Status codes */
    182   1.1       oki #define ST_GOOD			0x00
    183   1.1       oki #define ST_CHKCOND		0x02
    184   1.1       oki #define ST_CONDMET		0x04
    185   1.1       oki #define ST_BUSY			0x08
    186   1.1       oki #define ST_INTERMED		0x10
    187   1.1       oki #define ST_INTERMED_CONDMET	0x14
    188   1.1       oki #define ST_RESERVATION_CONFLICT	0x18
    189   1.1       oki #define ST_CMD_TERM		0x22
    190   1.1       oki #define ST_QUEUE_FULL		0x28
    191   1.1       oki 
    192   1.1       oki #define ST_MASK			0x3e /* bit 0,6,7 is reserved */
    193   1.1       oki 
    194   1.1       oki /* phase bits */
    195   1.1       oki #define IOI			0x01
    196   1.1       oki #define CDI			0x02
    197   1.1       oki #define MSGI			0x04
    198   1.1       oki 
    199   1.1       oki /* Information transfer phases */
    200   1.1       oki #define DATA_OUT_PHASE		(0)
    201   1.1       oki #define DATA_IN_PHASE		(IOI)
    202   1.1       oki #define COMMAND_PHASE		(CDI)
    203   1.1       oki #define STATUS_PHASE		(CDI|IOI)
    204   1.1       oki #define MESSAGE_OUT_PHASE	(MSGI|CDI)
    205   1.1       oki #define MESSAGE_IN_PHASE	(MSGI|CDI|IOI)
    206   1.1       oki 
    207   1.1       oki #define PHASE_MASK		(MSGI|CDI|IOI)
    208   1.1       oki 
    209   1.1       oki /* Some pseudo phases for getphase()*/
    210   1.1       oki #define BUSFREE_PHASE		0x100	/* Re/Selection no longer valid */
    211   1.1       oki #define INVALID_PHASE		0x101	/* Re/Selection valid, but no REQ yet */
    212   1.1       oki #define PSEUDO_PHASE		0x100	/* "pseudo" bit */
    213