Home | History | Annotate | Line # | Download | only in podulebus
      1  1.10   andvar /* $NetBSD: escvar.h,v 1.10 2021/08/21 11:55:24 andvar Exp $ */
      2   1.1  reinoud 
      3   1.1  reinoud /*
      4   1.1  reinoud  * Copyright (c) 1995 Daniel Widenfalk
      5   1.1  reinoud  *
      6   1.1  reinoud  * Redistribution and use in source and binary forms, with or without
      7   1.1  reinoud  * modification, are permitted provided that the following conditions
      8   1.1  reinoud  * are met:
      9   1.1  reinoud  * 1. Redistributions of source code must retain the above copyright
     10   1.1  reinoud  *    notice, this list of conditions and the following disclaimer.
     11   1.1  reinoud  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1  reinoud  *    notice, this list of conditions and the following disclaimer in the
     13   1.1  reinoud  *    documentation and/or other materials provided with the distribution.
     14   1.1  reinoud  * 3. All advertising materials mentioning features or use of this software
     15   1.1  reinoud  *    must display the following acknowledgement:
     16   1.1  reinoud  *      This product includes software developed by Daniel Widenfalk
     17   1.1  reinoud  *      for the NetBSD Project.
     18   1.1  reinoud  * 4. The name of the author may not be used to endorse or promote products
     19   1.1  reinoud  *    derived from this software without specific prior written permission
     20   1.1  reinoud  *
     21   1.1  reinoud  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22   1.1  reinoud  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23   1.1  reinoud  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24   1.1  reinoud  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25   1.1  reinoud  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26   1.1  reinoud  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27   1.1  reinoud  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28   1.1  reinoud  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29   1.1  reinoud  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30   1.1  reinoud  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31   1.1  reinoud  */
     32   1.1  reinoud 
     33   1.1  reinoud #ifndef _ESCVAR_H_
     34   1.1  reinoud #define _ESCVAR_H_
     35   1.1  reinoud 
     36   1.1  reinoud #ifndef _ESCREG_H_
     37   1.1  reinoud #include <acorn32/podulebus/escreg.h>
     38   1.1  reinoud #endif
     39   1.1  reinoud 
     40   1.1  reinoud /*
     41   1.1  reinoud  * MAXCHAIN is the anticipated maximum number of chain blocks needed. This
     42   1.1  reinoud  * assumes that we are NEVER requested to transfer more than MAXPHYS bytes.
     43   1.1  reinoud  */
     44   1.4  thorpej #define MAXCHAIN	(MAXPHYS/PAGE_SIZE+2)
     45   1.1  reinoud 
     46   1.1  reinoud /*
     47   1.1  reinoud  * Maximum number of requests standing by. Could be anything, but I think 9
     48   1.1  reinoud  * looks nice :-) NOTE: This does NOT include requests already started!
     49   1.1  reinoud  */
     50   1.1  reinoud #define MAXPENDING	9	/* 7 IDs + 2 extra */
     51   1.1  reinoud 
     52   1.1  reinoud /*
     53   1.1  reinoud  * DMA chain block. If flg == ESC_CHAIN_PRG or flg == ESC_CHAIN_BUMP then
     54   1.5      wiz  * ptr is a VIRTUAL address. If flg == ESC_CHAIN_DMA then ptr is a PHYSICAL
     55   1.5      wiz  * address.
     56   1.1  reinoud  */
     57   1.1  reinoud struct	esc_dma_chain {
     58   1.3      chs 	void		*ptr;
     59   1.1  reinoud 	u_short		len;
     60   1.1  reinoud 	short		flg;
     61   1.1  reinoud };
     62   1.1  reinoud #define ESC_CHAIN_DMA	0x00
     63   1.1  reinoud #define ESC_CHAIN_BUMP	0x01
     64   1.1  reinoud #define ESC_CHAIN_PRG	0x02
     65   1.1  reinoud 
     66   1.1  reinoud 
     67   1.1  reinoud /*
     68   1.1  reinoud  * This struct contains the necessary info for a pending request. Pointer to
     69   1.1  reinoud  * a scsipi_xfer struct.
     70   1.1  reinoud  */
     71   1.1  reinoud struct	esc_pending {
     72   1.1  reinoud 	TAILQ_ENTRY(esc_pending) link;
     73   1.1  reinoud 	struct scsipi_xfer	 *xs;
     74   1.1  reinoud };
     75   1.1  reinoud 
     76   1.1  reinoud /*
     77   1.1  reinoud  * nexus contains all active data for one SCSI unit. Parts of the info in this
     78   1.1  reinoud  * struct survives between scsi commands.
     79   1.1  reinoud  */
     80   1.1  reinoud struct nexus {
     81   1.1  reinoud 	struct	scsipi_xfer 	*xs;		/* Pointer to request */
     82   1.1  reinoud 
     83   1.1  reinoud 	u_char			 ID;		/* ID message to be sent */
     84   1.1  reinoud 	u_char			 clen;		/* scsi command length + */
     85   1.1  reinoud 	u_char			 cbuf[14];	/* the actual command bytes */
     86   1.1  reinoud 
     87   1.1  reinoud 	struct esc_dma_chain	 dma[MAXCHAIN];	/* DMA chain blocks */
     88   1.1  reinoud 	short			 max_link;	/* Maximum used of above */
     89   1.1  reinoud 	short			 cur_link;	/* Currently handled block */
     90   1.1  reinoud 
     91   1.5      wiz 	u_char			*buf;		/* Virtual address of data */
     92   1.1  reinoud 	int			 len;		/* Bytes left to transfer */
     93   1.1  reinoud 
     94   1.5      wiz 	void			*dma_buf;	/* Current DMA address */
     95   1.1  reinoud 	int			 dma_len;	/* Current DMA length */
     96   1.1  reinoud 
     97   1.5      wiz 	void			*dma_blk_ptr;	/* Current chain address */
     98   1.1  reinoud 	int			 dma_blk_len;	/* Current chain length */
     99   1.1  reinoud 	u_char			 dma_blk_flg;	/* Current chain flags */
    100   1.1  reinoud 
    101   1.1  reinoud 	u_char			 state;		/* Nexus state, see below */
    102   1.1  reinoud 	u_short			 flags;		/* Nexus flags, see below */
    103   1.1  reinoud 
    104   1.1  reinoud 	short			 period;	/* Sync period to request */
    105   1.1  reinoud 	u_char			 offset;	/* Sync offset to request */
    106   1.1  reinoud 
    107   1.1  reinoud 	u_char			 syncper;	/* FAS216 variable storage */
    108   1.1  reinoud 	u_char			 syncoff;	/* FAS216 variable storage */
    109   1.1  reinoud 	u_char			 config3;	/* FAS216 variable storage */
    110   1.1  reinoud 
    111   1.1  reinoud 	u_char			 lun_unit;	/* (Lun<<4) | Unit of nexus */
    112   1.1  reinoud 	u_char			 status;	/* Status byte from unit*/
    113   1.1  reinoud 
    114   1.1  reinoud };
    115   1.1  reinoud 
    116   1.1  reinoud /* SCSI nexus_states */
    117   1.1  reinoud #define ESC_NS_IDLE		0	/* Nexus idle */
    118   1.1  reinoud #define ESC_NS_SELECTED	1	/* Last command was a SELECT command */
    119   1.1  reinoud #define ESC_NS_DATA_IN		2	/* Last command was a TRANSFER_INFO */
    120   1.1  reinoud 					/* command during a data in phase */
    121   1.1  reinoud #define ESC_NS_DATA_OUT	3	/* Last command was a TRANSFER_INFO */
    122   1.1  reinoud 					/* command during a data out phase */
    123   1.1  reinoud #define ESC_NS_STATUS		4	/* We have send a COMMAND_COMPLETE */
    124   1.1  reinoud 					/* command and are awaiting status */
    125   1.1  reinoud #define ESC_NS_MSG_IN		5	/* Last phase was MESSAGE IN */
    126   1.1  reinoud #define ESC_NS_MSG_OUT		6	/* Last phase was MESSAGE OUT */
    127   1.1  reinoud #define ESC_NS_SVC		7	/* We have sent the command */
    128   1.1  reinoud #define ESC_NS_DISCONNECTING	8	/* We have received a disconnect msg */
    129   1.1  reinoud #define ESC_NS_DISCONNECTED	9	/* We are disconnected */
    130   1.1  reinoud #define ESC_NS_RESELECTED	10	/* We was reselected */
    131   1.1  reinoud #define ESC_NS_DONE		11	/* Done. Prephsase to FINISHED */
    132  1.10   andvar #define ESC_NS_FINISHED		12	/* Really done. Call scsi_done */
    133   1.9  msaitoh #define ESC_NS_RESET		13	/* We are resetting this unit */
    134   1.1  reinoud 
    135   1.1  reinoud /* SCSI nexus flags */
    136   1.1  reinoud #define ESC_NF_UNIT_BUSY	0x0001	/* Unit is not available */
    137   1.1  reinoud 
    138   1.1  reinoud #define ESC_NF_SELECT_ME	0x0002	/* Nexus is set up, waiting for bus */
    139   1.1  reinoud 
    140   1.1  reinoud #define ESC_NF_HAS_MSG		0x0010	/* We have received a complete msg */
    141   1.1  reinoud 
    142   1.1  reinoud #define ESC_NF_DO_SDTR		0x0020	/* We should send a SDTR */
    143   1.1  reinoud #define ESC_NF_SDTR_SENT	0x0040	/* We have sent a SDTR */
    144   1.1  reinoud #define ESC_NF_SYNC_TESTED	0x0080	/* We have negotiated sync */
    145   1.1  reinoud 
    146   1.1  reinoud #define ESC_NF_RESET		0x0100	/* Reset this nexus */
    147   1.1  reinoud #define ESC_NF_IMMEDIATE	0x0200	/* We are operating from escicmd */
    148   1.1  reinoud 
    149   1.1  reinoud #define ESC_NF_RETRY_SELECT	0x1000	/* Selection needs retrying */
    150   1.1  reinoud 
    151   1.1  reinoud #define ESC_NF_DEBUG		0x8000	/* As it says: DEBUG */
    152   1.1  reinoud 
    153   1.1  reinoud struct	esc_softc {
    154   1.8      chs 	device_t		 sc_dev;	/* System required struct */
    155   1.1  reinoud 	struct	scsipi_channel	 sc_channel;	/* For sub devices */
    156   1.1  reinoud 	struct	scsipi_adapter	 sc_adapter;
    157   1.1  reinoud 	irqhandler_t		 sc_ih;		/* Interrupt chain struct */
    158   1.1  reinoud 
    159   1.1  reinoud 	TAILQ_HEAD(,esc_pending) sc_xs_pending;
    160   1.1  reinoud 	TAILQ_HEAD(,esc_pending) sc_xs_free;
    161   1.1  reinoud 	struct	esc_pending 	 sc_xs_store[MAXPENDING];
    162   1.1  reinoud 
    163   1.1  reinoud 	esc_regmap_p		 sc_esc;	/* FAS216 Address */
    164   1.1  reinoud 	void			*sc_spec;	/* Board-specific data */
    165   1.1  reinoud 
    166   1.1  reinoud 	u_char			*sc_bump_va;	/* Bumpbuf virtual adr */
    167   1.3      chs 	void			*sc_bump_pa;	/* Bumpbuf physical adr */
    168   1.1  reinoud 	int			 sc_bump_sz;	/* Bumpbuf size */
    169   1.1  reinoud 
    170   1.1  reinoud /* Configuration registers, must be set BEFORE escinitialize */
    171   1.1  reinoud 	u_char			 sc_clock_freq;
    172   1.1  reinoud 	u_short			 sc_timeout;
    173   1.1  reinoud 	u_char			 sc_host_id;
    174   1.1  reinoud 	u_char			 sc_config_flags;
    175   1.1  reinoud 
    176   1.1  reinoud /* Generic DMA functions */
    177   1.2    bjh21 	int		       (*sc_setup_dma)(struct esc_softc *, void *,
    178   1.2    bjh21 				    int, int);
    179   1.2    bjh21 	int		       (*sc_build_dma_chain)(struct esc_softc *,
    180   1.2    bjh21 				    struct esc_dma_chain *, void *, int);
    181   1.2    bjh21 	int		       (*sc_need_bump)(struct esc_softc *, void *,
    182   1.2    bjh21 				    int);
    183   1.1  reinoud 
    184   1.1  reinoud /* Generic Led data */
    185   1.1  reinoud 	int			 sc_led_status;
    186   1.2    bjh21 	void		       (*sc_led)(struct esc_softc *, int);
    187   1.1  reinoud 
    188   1.1  reinoud /* Nexus list */
    189   1.1  reinoud 	struct nexus		 sc_nexus[8];
    190   1.1  reinoud 	struct nexus		*sc_cur_nexus;
    191   1.1  reinoud 	struct nexus		*sc_sel_nexus;
    192   1.1  reinoud 
    193   1.1  reinoud /* Current transfer data */
    194   1.1  reinoud 	u_char			*sc_buf;	/* va */
    195   1.1  reinoud 	int			 sc_len;
    196   1.1  reinoud 
    197   1.3      chs 	void			*sc_dma_buf;	/* pa */
    198   1.1  reinoud 	int			 sc_dma_len;
    199   1.3      chs 	void			*sc_dma_blk_ptr;
    200   1.1  reinoud 	int			 sc_dma_blk_len;
    201   1.1  reinoud 	short			 sc_dma_blk_flg;
    202   1.1  reinoud 
    203   1.1  reinoud 	struct esc_dma_chain	*sc_chain;	/* Current DMA chain */
    204   1.1  reinoud 	short			 sc_max_link;
    205   1.1  reinoud 	short			 sc_cur_link;
    206   1.1  reinoud 
    207   1.1  reinoud /* Interrupt registers */
    208   1.1  reinoud 	u_char			 sc_status;
    209   1.1  reinoud 	u_char			 sc_interrupt;
    210   1.1  reinoud 	u_char			 sc_resel[2];
    211   1.1  reinoud 
    212   1.1  reinoud 	u_char			 sc_units_disconnected;
    213   1.1  reinoud 
    214   1.1  reinoud /* Storage for FAS216 config registers (current values) */
    215   1.1  reinoud 	u_char			 sc_config1;
    216   1.1  reinoud 	u_char			 sc_config2;
    217   1.1  reinoud 	u_char			 sc_config3;
    218   1.1  reinoud 	u_char			 sc_config4;
    219   1.1  reinoud 	u_char			 sc_clock_conv_fact;
    220   1.1  reinoud 	u_char			 sc_timeout_val;
    221   1.1  reinoud 	u_char			 sc_clock_period;
    222   1.1  reinoud 
    223   1.1  reinoud 	u_char			 sc_msg_in[7];
    224   1.1  reinoud 	u_char			 sc_msg_in_len;
    225   1.1  reinoud 
    226   1.1  reinoud 	u_char			 sc_msg_out[7];
    227   1.1  reinoud 	u_char			 sc_msg_out_len;
    228   1.1  reinoud 
    229   1.1  reinoud 	u_char			 sc_unit;
    230   1.1  reinoud 	u_char			 sc_lun;
    231   1.1  reinoud 	u_char			 sc_flags;
    232   1.1  reinoud };
    233   1.1  reinoud 
    234   1.1  reinoud #define ESC_DMA_READ	0
    235   1.1  reinoud #define ESC_DMA_WRITE	1
    236   1.1  reinoud #define ESC_DMA_CLEAR	2
    237   1.1  reinoud 
    238   1.1  reinoud /* sc_flags */
    239   1.1  reinoud #define ESC_ACTIVE	 0x01
    240   1.1  reinoud #define ESC_DONT_WAIT	 0x02
    241   1.1  reinoud 
    242   1.1  reinoud /* SCSI Selection modes */
    243   1.1  reinoud #define ESC_SELECT	0x00	/* Normal selection: No sync, no resel */
    244   1.1  reinoud #define ESC_SELECT_R	0x01	/* Reselection allowed */
    245   1.1  reinoud #define ESC_SELECT_S	0x02	/* Synchronous transfer allowed */
    246   1.1  reinoud #define ESC_SELECT_I	0x04	/* Selection for escicmd */
    247   1.1  reinoud #define ESC_SELECT_K	0x08	/* Send a BUS DEVICE RESET message (Kill) */
    248   1.1  reinoud 
    249   1.1  reinoud /* Nice abbreviations of the above */
    250   1.1  reinoud #define ESC_SELECT_RS	(ESC_SELECT_R|ESC_SELECT_S)
    251   1.1  reinoud #define ESC_SELECT_RI	(ESC_SELECT_R|ESC_SELECT_I)
    252   1.1  reinoud #define ESC_SELECT_SI	(ESC_SELECT_S|ESC_SELECT_I)
    253   1.1  reinoud #define ESC_SELECT_RSI	(ESC_SELECT_R|ESC_SELECT_S|ESC_SELECT_I)
    254   1.1  reinoud 
    255   1.1  reinoud /* sc_config_flags */
    256   1.1  reinoud #define ESC_NO_SYNCH	 0x01	/* Disable synchronous transfer */
    257   1.1  reinoud #define ESC_NO_DMA	 0x02	/* Do not use DMA! EVER! */
    258   1.1  reinoud #define ESC_NO_RESELECT 0x04	/* Do not allow relesection */
    259   1.1  reinoud #define ESC_SLOW_CABLE	 0x08	/* Cable is "unsafe" for fast scsi-2 */
    260   1.1  reinoud #define ESC_SLOW_START	 0x10	/* There are slow starters on the bus */
    261   1.1  reinoud 
    262   1.7      dsl void	escinitialize(struct esc_softc *sc);
    263   1.7      dsl void	esc_minphys(struct buf *bp);
    264   1.7      dsl void	esc_scsi_request(struct scsipi_channel *,
    265   1.7      dsl 				scsipi_adapter_req_t, void *);
    266   1.7      dsl void	escintr(struct esc_softc *dev);
    267   1.1  reinoud 
    268   1.1  reinoud #endif /* _ESCVAR_H_ */
    269