Home | History | Annotate | Line # | Download | only in ic
wdcvar.h revision 1.48
      1  1.48   thorpej /*	$NetBSD: wdcvar.h,v 1.48 2003/12/30 17:18:11 thorpej Exp $	*/
      2   1.1       cgd 
      3   1.3   mycroft /*-
      4  1.37   mycroft  * Copyright (c) 1998, 2003 The NetBSD Foundation, Inc.
      5   1.3   mycroft  * All rights reserved.
      6   1.1       cgd  *
      7   1.3   mycroft  * This code is derived from software contributed to The NetBSD Foundation
      8   1.3   mycroft  * by Charles M. Hannum, by Onno van der Linden and by Manuel Bouyer.
      9   1.1       cgd  *
     10   1.1       cgd  * Redistribution and use in source and binary forms, with or without
     11   1.1       cgd  * modification, are permitted provided that the following conditions
     12   1.1       cgd  * are met:
     13   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     14   1.6    bouyer  *	notice, this list of conditions and the following disclaimer.
     15   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.6    bouyer  *	notice, this list of conditions and the following disclaimer in the
     17   1.6    bouyer  *	documentation and/or other materials provided with the distribution.
     18   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     19   1.1       cgd  *    must display the following acknowledgement:
     20   1.3   mycroft  *        This product includes software developed by the NetBSD
     21   1.3   mycroft  *        Foundation, Inc. and its contributors.
     22   1.3   mycroft  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23   1.3   mycroft  *    contributors may be used to endorse or promote products derived
     24   1.3   mycroft  *    from this software without specific prior written permission.
     25   1.1       cgd  *
     26   1.3   mycroft  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27   1.3   mycroft  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28   1.3   mycroft  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29   1.3   mycroft  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30   1.3   mycroft  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31   1.3   mycroft  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32   1.3   mycroft  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33   1.3   mycroft  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34   1.3   mycroft  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35   1.3   mycroft  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36   1.3   mycroft  * POSSIBILITY OF SUCH DAMAGE.
     37   1.1       cgd  */
     38   1.1       cgd 
     39  1.29    bouyer /* XXX For scsipi_adapter and scsipi_channel. */
     40   1.8   thorpej #include <dev/scsipi/scsipi_all.h>
     41  1.24    bouyer #include <dev/scsipi/atapiconf.h>
     42   1.8   thorpej 
     43  1.22   thorpej #include <sys/callout.h>
     44  1.22   thorpej 
     45   1.6    bouyer #define	WAITTIME    (10 * hz)    /* time to wait for a completion */
     46   1.6    bouyer 	/* this is a lot for hard drives, but not for cdroms */
     47   1.5      mark 
     48   1.6    bouyer struct channel_queue {  /* per channel queue (may be shared) */
     49   1.6    bouyer 	TAILQ_HEAD(xferhead, wdc_xfer) sc_xfer;
     50  1.42    bouyer 	int queue_freeze;
     51   1.6    bouyer };
     52  1.45    bouyer 
     53  1.45    bouyer #define WDC_NREG	8 /* number of command registers */
     54   1.6    bouyer 
     55   1.6    bouyer struct channel_softc { /* Per channel data */
     56  1.23     enami 	/* Our timeout callout */
     57  1.22   thorpej 	struct callout ch_callout;
     58   1.6    bouyer 	/* Our location */
     59   1.6    bouyer 	int channel;
     60   1.6    bouyer 	/* Our controller's softc */
     61   1.6    bouyer 	struct wdc_softc *wdc;
     62   1.6    bouyer 	/* Our registers */
     63   1.6    bouyer 	bus_space_tag_t       cmd_iot;
     64  1.44      fvdl 	bus_space_handle_t    cmd_baseioh;
     65  1.44      fvdl 	bus_space_handle_t    cmd_iohs[WDC_NREG];
     66   1.6    bouyer 	bus_space_tag_t       ctl_iot;
     67   1.6    bouyer 	bus_space_handle_t    ctl_ioh;
     68  1.44      fvdl 	/* data32{iot,ioh} are only used for 32 bit data xfers */
     69   1.6    bouyer 	bus_space_tag_t         data32iot;
     70   1.6    bouyer 	bus_space_handle_t      data32ioh;
     71   1.6    bouyer 	/* Our state */
     72   1.6    bouyer 	int ch_flags;
     73   1.6    bouyer #define WDCF_ACTIVE   0x01	/* channel is active */
     74  1.41    bouyer #define WDCF_SHUTDOWN 0x02	/* channel is shutting down */
     75   1.6    bouyer #define WDCF_IRQ_WAIT 0x10	/* controller is waiting for irq */
     76  1.24    bouyer #define WDCF_DMA_WAIT 0x20	/* controller is waiting for DMA */
     77  1.37   mycroft #define	WDCF_DISABLED 0x80	/* channel is disabled */
     78  1.41    bouyer #define WDCF_TH_RUN   0x100	/* the kenrel thread is working */
     79  1.41    bouyer #define WDCF_TH_RESET 0x200	/* someone ask the thread to reset */
     80   1.6    bouyer 	u_int8_t ch_status;         /* copy of status register */
     81   1.6    bouyer 	u_int8_t ch_error;          /* copy of error register */
     82   1.6    bouyer 	/* per-drive infos */
     83   1.6    bouyer 	struct ata_drive_datas ch_drive[2];
     84   1.6    bouyer 
     85  1.41    bouyer 	struct device *atabus;	/* self */
     86  1.41    bouyer 	struct device *atapibus; /* children */
     87  1.29    bouyer 	struct scsipi_channel ch_atapi_channel;
     88  1.19     enami 
     89  1.41    bouyer 	struct device *ata_drives[2]; /* children */
     90  1.35   thorpej 
     91   1.6    bouyer 	/*
     92   1.6    bouyer 	 * channel queues. May be the same for all channels, if hw channels
     93  1.43       wiz 	 * are not independent.
     94   1.6    bouyer 	 */
     95   1.6    bouyer 	struct channel_queue *ch_queue;
     96  1.48   thorpej 
     97  1.48   thorpej 	/* the channel kernel thread */
     98  1.41    bouyer 	struct proc *thread;
     99  1.41    bouyer };
    100  1.41    bouyer 
    101   1.6    bouyer struct wdc_softc { /* Per controller state */
    102   1.6    bouyer 	struct device sc_dev;
    103   1.6    bouyer 	/* mandatory fields */
    104   1.6    bouyer 	int           cap;
    105   1.6    bouyer /* Capabilities supported by the controller */
    106   1.6    bouyer #define	WDC_CAPABILITY_DATA16 0x0001    /* can do  16-bit data access */
    107   1.6    bouyer #define	WDC_CAPABILITY_DATA32 0x0002    /* can do 32-bit data access */
    108   1.6    bouyer #define WDC_CAPABILITY_MODE   0x0004	/* controller knows its PIO/DMA modes */
    109   1.6    bouyer #define	WDC_CAPABILITY_DMA    0x0008	/* DMA */
    110   1.6    bouyer #define	WDC_CAPABILITY_UDMA   0x0010	/* Ultra-DMA/33 */
    111   1.6    bouyer #define	WDC_CAPABILITY_HWLOCK 0x0020	/* Needs to lock HW */
    112   1.6    bouyer #define	WDC_CAPABILITY_ATA_NOSTREAM 0x0040 /* Don't use stream funcs on ATA */
    113   1.6    bouyer #define	WDC_CAPABILITY_ATAPI_NOSTREAM 0x0080 /* Don't use stream f on ATAPI */
    114   1.6    bouyer #define WDC_CAPABILITY_NO_EXTRA_RESETS 0x0100 /* only reset once */
    115  1.17    bouyer #define WDC_CAPABILITY_PREATA 0x0200 /* ctrl can be a pre-ata one */
    116  1.25    bouyer #define WDC_CAPABILITY_IRQACK 0x0400 /* callback to ack interrupt */
    117  1.30     bjh21 #define WDC_CAPABILITY_NOIRQ  0x1000	/* Controller never interrupts */
    118  1.33       dbj #define WDC_CAPABILITY_SELECT  0x2000	/* Controller selects target */
    119  1.35   thorpej #define	WDC_CAPABILITY_RAID   0x4000	/* Controller "supports" RAID */
    120  1.13    bouyer 	u_int8_t      PIO_cap; /* highest PIO mode supported */
    121  1.13    bouyer 	u_int8_t      DMA_cap; /* highest DMA mode supported */
    122  1.13    bouyer 	u_int8_t      UDMA_cap; /* highest UDMA mode supported */
    123   1.6    bouyer 	int nchannels;	/* Number of channels on this controller */
    124  1.10  drochner 	struct channel_softc **channels;  /* channels-specific datas (array) */
    125   1.8   thorpej 
    126   1.8   thorpej 	/*
    127   1.8   thorpej 	 * The reference count here is used for both IDE and ATAPI devices.
    128   1.8   thorpej 	 */
    129  1.24    bouyer 	struct atapi_adapter sc_atapi_adapter;
    130   1.1       cgd 
    131  1.48   thorpej 	/* Function used to probe for drives. */
    132  1.48   thorpej 	void		(*drv_probe) __P((struct channel_softc *));
    133  1.48   thorpej 
    134   1.1       cgd 	/* if WDC_CAPABILITY_DMA set in 'cap' */
    135   1.6    bouyer 	void            *dma_arg;
    136   1.6    bouyer 	int            (*dma_init) __P((void *, int, int, void *, size_t,
    137   1.6    bouyer 	                int));
    138  1.24    bouyer 	void           (*dma_start) __P((void *, int, int));
    139   1.6    bouyer 	int            (*dma_finish) __P((void *, int, int, int));
    140  1.24    bouyer /* flags passed to dma_init */
    141  1.36  nakayama #define WDC_DMA_READ	0x01
    142  1.36  nakayama #define WDC_DMA_IRQW	0x02
    143  1.36  nakayama #define WDC_DMA_LBA48	0x04
    144  1.24    bouyer 	int		dma_status; /* status returned from dma_finish() */
    145  1.24    bouyer #define WDC_DMAST_NOIRQ	0x01	/* missing IRQ */
    146  1.24    bouyer #define WDC_DMAST_ERR	0x02	/* DMA error */
    147  1.24    bouyer #define WDC_DMAST_UNDER	0x04	/* DMA underrun */
    148   1.2       leo 
    149   1.2       leo 	/* if WDC_CAPABILITY_HWLOCK set in 'cap' */
    150   1.6    bouyer 	int            (*claim_hw) __P((void *, int));
    151   1.6    bouyer 	void            (*free_hw) __P((void *));
    152  1.14    bouyer 
    153  1.14    bouyer 	/* if WDC_CAPABILITY_MODE set in 'cap' */
    154  1.14    bouyer 	void 		(*set_modes) __P((struct channel_softc *));
    155  1.33       dbj 
    156  1.33       dbj 	/* if WDC_CAPABILITY_SELECT set in 'cap' */
    157  1.33       dbj 	void		(*select) __P((struct channel_softc *,int));
    158  1.25    bouyer 
    159  1.25    bouyer 	/* if WDC_CAPABILITY_IRQACK set in 'cap' */
    160  1.25    bouyer 	void		(*irqack) __P((struct channel_softc *));
    161   1.1       cgd };
    162   1.1       cgd 
    163   1.6    bouyer  /*
    164   1.6    bouyer   * Description of a command to be handled by a controller.
    165   1.6    bouyer   * These commands are queued in a list.
    166   1.6    bouyer   */
    167   1.6    bouyer struct wdc_xfer {
    168   1.6    bouyer 	volatile u_int c_flags;
    169  1.18    bouyer #define C_ATAPI  	0x0001 /* xfer is ATAPI request */
    170  1.18    bouyer #define C_TIMEOU  	0x0002 /* xfer processing timed out */
    171  1.18    bouyer #define C_POLL		0x0004 /* cmd is polled */
    172  1.18    bouyer #define C_DMA		0x0008 /* cmd uses DMA */
    173   1.6    bouyer 
    174  1.11    bouyer 	/* Informations about our location */
    175  1.11    bouyer 	struct channel_softc *chp;
    176   1.6    bouyer 	u_int8_t drive;
    177   1.6    bouyer 
    178   1.6    bouyer 	/* Information about the current transfer  */
    179   1.6    bouyer 	void *cmd; /* wdc, ata or scsipi command structure */
    180   1.6    bouyer 	void *databuf;
    181   1.6    bouyer 	int c_bcount;      /* byte count left */
    182   1.6    bouyer 	int c_skip;        /* bytes already transferred */
    183  1.31    bouyer 	int c_dscpoll;	   /* counter for dsc polling (ATAPI) */
    184   1.6    bouyer 	TAILQ_ENTRY(wdc_xfer) c_xferchain;
    185   1.6    bouyer 	void (*c_start) __P((struct channel_softc *, struct wdc_xfer *));
    186  1.16    bouyer 	int  (*c_intr)  __P((struct channel_softc *, struct wdc_xfer *, int));
    187  1.20     enami 	void (*c_kill_xfer) __P((struct channel_softc *, struct wdc_xfer *));
    188   1.6    bouyer };
    189   1.4      kenh 
    190   1.6    bouyer /*
    191   1.6    bouyer  * Public functions which can be called by ATA or ATAPI specific parts,
    192   1.6    bouyer  * or bus-specific backends.
    193   1.6    bouyer  */
    194   1.1       cgd 
    195   1.6    bouyer int   wdcprobe __P((struct channel_softc *));
    196  1.41    bouyer void  wdcattach __P((struct channel_softc *));
    197  1.19     enami int   wdcdetach __P((struct device *, int));
    198  1.19     enami int   wdcactivate __P((struct device *, enum devact));
    199   1.6    bouyer int   wdcintr __P((void *));
    200   1.6    bouyer void  wdc_exec_xfer __P((struct channel_softc *, struct wdc_xfer *));
    201   1.6    bouyer struct wdc_xfer *wdc_get_xfer __P((int)); /* int = WDC_NOSLEEP/CANSLEEP */
    202   1.6    bouyer #define WDC_CANSLEEP 0x00
    203   1.6    bouyer #define WDC_NOSLEEP 0x01
    204   1.6    bouyer void   wdc_free_xfer  __P((struct channel_softc *, struct wdc_xfer *));
    205  1.10  drochner void  wdcstart __P((struct channel_softc *));
    206   1.6    bouyer void  wdcrestart __P((void*));
    207   1.6    bouyer int   wdcreset	__P((struct channel_softc *, int));
    208  1.41    bouyer #define RESET_POLL 1
    209  1.41    bouyer #define RESET_SLEEP 0 /* wdcreset will use tsleep() */
    210  1.41    bouyer int   wdcwait __P((struct channel_softc *, int, int, int, int));
    211  1.41    bouyer #define WDCWAIT_OK	0  /* we have what we asked */
    212  1.41    bouyer #define WDCWAIT_TOUT	-1 /* timed out */
    213  1.41    bouyer #define WDCWAIT_THR	1  /* return, the kernel thread has been awakened */
    214  1.24    bouyer int   wdc_dmawait __P((struct channel_softc *, struct wdc_xfer *, int));
    215   1.6    bouyer void  wdcbit_bucket __P(( struct channel_softc *, int));
    216   1.6    bouyer void  wdccommand __P((struct channel_softc *, u_int8_t, u_int8_t, u_int16_t,
    217  1.34  christos     u_int8_t, u_int8_t, u_int8_t, u_int8_t));
    218  1.34  christos void  wdccommandext __P((struct channel_softc *, u_int8_t, u_int8_t, u_int64_t,
    219  1.34  christos     u_int16_t));
    220   1.6    bouyer void   wdccommandshort __P((struct channel_softc *, int, int));
    221   1.6    bouyer void  wdctimeout	__P((void *arg));
    222  1.41    bouyer void wdc_reset_channel __P((struct ata_drive_datas *, int));
    223  1.32    bouyer int wdc_exec_command __P((struct ata_drive_datas *, struct wdc_command*));
    224  1.32    bouyer #define WDC_COMPLETE 0x01
    225  1.32    bouyer #define WDC_QUEUED   0x02
    226  1.32    bouyer #define WDC_TRY_AGAIN 0x03
    227   1.9   thorpej 
    228   1.9   thorpej int	wdc_addref __P((struct channel_softc *));
    229   1.9   thorpej void	wdc_delref __P((struct channel_softc *));
    230  1.20     enami void	wdc_kill_pending __P((struct channel_softc *));
    231  1.26  wrstuden 
    232  1.26  wrstuden void	wdc_print_modes (struct channel_softc *);
    233  1.32    bouyer void	wdc_probe_caps __P((struct ata_drive_datas*));
    234   1.6    bouyer 
    235   1.6    bouyer /*
    236   1.6    bouyer  * ST506 spec says that if READY or SEEKCMPLT go off, then the read or write
    237   1.6    bouyer  * command is aborted.
    238   1.6    bouyer  */
    239  1.41    bouyer #define wait_for_drq(chp, timeout, flags) \
    240  1.41    bouyer 		wdcwait((chp), WDCS_DRQ, WDCS_DRQ, (timeout), (flags))
    241  1.41    bouyer #define wait_for_unbusy(chp, timeout, flags) \
    242  1.41    bouyer 		wdcwait((chp), 0, 0, (timeout), (flags))
    243  1.41    bouyer #define wait_for_ready(chp, timeout, flags) \
    244  1.41    bouyer 		wdcwait((chp), WDCS_DRDY, WDCS_DRDY, (timeout), (flags))
    245   1.6    bouyer /* ATA/ATAPI specs says a device can take 31s to reset */
    246   1.6    bouyer #define WDC_RESET_WAIT 31000
    247   1.1       cgd 
    248  1.41    bouyer void wdc_atapibus_attach __P((struct atabus_softc *));
    249  1.47   thorpej 
    250  1.47   thorpej /* XXX */
    251  1.47   thorpej struct atabus_softc;
    252  1.47   thorpej void	atabusconfig(struct atabus_softc *);
    253