Home | History | Annotate | Line # | Download | only in ata
wdvar.h revision 1.18
      1 /*	$NetBSD: wdvar.h,v 1.18 2003/10/05 17:48:49 bouyer Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998, 2001 Manuel Bouyer.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by Manuel Bouyer.
     17  * 4. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  *
     31  */
     32 
     33 /* Params needed by the controller to perform an ATA bio */
     34 struct ata_bio {
     35 	volatile u_int16_t flags;/* cmd flags */
     36 #define	ATA_NOSLEEP	0x0001	/* Can't sleep */
     37 #define	ATA_POLL	0x0002	/* poll for completion */
     38 #define	ATA_ITSDONE	0x0004	/* the transfer is as done as it gets */
     39 #define	ATA_SINGLE	0x0008	/* transfer must be done in singlesector mode */
     40 #define	ATA_LBA		0x0010	/* transfer uses LBA adressing */
     41 #define	ATA_READ	0x0020	/* transfer is a read (otherwise a write) */
     42 #define	ATA_CORR	0x0040	/* transfer had a corrected error */
     43 #define	ATA_LBA48	0x0080	/* transfer uses 48-bit LBA adressing */
     44 	int		multi;	/* # of blocks to transfer in multi-mode */
     45 	struct disklabel *lp;	/* pointer to drive's label info */
     46 	daddr_t		blkno;	/* block addr */
     47 	daddr_t		blkdone;/* number of blks transferred */
     48 	daddr_t		nblks;	/* number of block currently transferring */
     49 	int		nbytes;	/* number of bytes currently transferring */
     50 	long		bcount;	/* total number of bytes */
     51 	char		*databuf;/* data buffer adress */
     52 	volatile int	error;
     53 #define	NOERROR 	0	/* There was no error (r_error invalid) */
     54 #define	ERROR		1	/* check r_error */
     55 #define	ERR_DF		2	/* Drive fault */
     56 #define	ERR_DMA		3	/* DMA error */
     57 #define	TIMEOUT		4	/* device timed out */
     58 #define	ERR_NODEV	5	/* device has been gone */
     59 	u_int8_t	r_error;/* copy of error register */
     60 	daddr_t		badsect[127];/* 126 plus trailing -1 marker */
     61 };
     62 
     63 /*
     64  * ata_bustype. The first field has to be compatible with scsipi_bustype,
     65  * as it's used for autoconfig by both ata and atapi drivers
     66  */
     67 
     68 struct ata_bustype {
     69 	int bustype_type;	/* symbolic name of type */
     70 	int (*ata_bio) __P((struct ata_drive_datas*, struct ata_bio *));
     71 	void (*ata_reset_channel) __P((struct ata_drive_datas *));
     72 	int (*ata_exec_command) __P((struct ata_drive_datas *,
     73 					struct wdc_command *));
     74 #define WDC_COMPLETE 0x01
     75 #define WDC_QUEUED   0x02
     76 #define WDC_TRY_AGAIN 0x03
     77 	int (*ata_get_params) __P((struct ata_drive_datas*, u_int8_t,
     78 					struct ataparams *));
     79 	int (*ata_addref) __P((struct ata_drive_datas *));
     80 	void (*ata_delref) __P((struct ata_drive_datas *));
     81 	void (*ata_killpending) __P((struct ata_drive_datas *));
     82 };
     83 /* bustype_type */
     84 /* #define SCSIPI_BUSTYPE_SCSI	0 */
     85 /* #define SCSIPI_BUSTYPE_ATAPI	1 */
     86 #define SCSIPI_BUSTYPE_ATA	2
     87 
     88 /*
     89  * describe an ATA device. Has to be compatible with scsipi_channel, so start
     90  * with a pointer to ata_bustype
     91  */
     92 struct ata_device {
     93 	const struct ata_bustype *adev_bustype;
     94 	int adev_channel;
     95 	int adev_openings;
     96 	struct ata_drive_datas *adev_drv_data;
     97 };
     98 
     99 #ifdef __ATA_DISK_PRIVATE
    100 
    101 struct wd_softc {
    102 	/* General disk infos */
    103 	struct device sc_dev;
    104 	struct disk sc_dk;
    105 	struct bufq_state sc_q;
    106 	struct callout sc_restart_ch;
    107 	int sc_quirks;			/* any quirks drive might have */
    108 	/* IDE disk soft states */
    109 	struct ata_bio sc_wdc_bio; /* current transfer */
    110 	struct buf *sc_bp; /* buf being transfered */
    111 	void *wdc_softc;   /* pointer to our parent */
    112 	struct ata_drive_datas *drvp; /* Our controller's infos */
    113 	const struct ata_bustype *atabus;
    114 	int openings;
    115 	struct ataparams sc_params;/* drive characteistics found */
    116 	int sc_flags;
    117 #define	WDF_LOCKED	0x001
    118 #define	WDF_WANTED	0x002
    119 #define	WDF_WLABEL	0x004 /* label is writable */
    120 #define	WDF_LABELLING	0x008 /* writing label */
    121 /*
    122  * XXX Nothing resets this yet, but disk change sensing will when ATA-4 is
    123  * more fully implemented.
    124  */
    125 #define WDF_LOADED	0x010 /* parameters loaded */
    126 #define WDF_WAIT	0x020 /* waiting for resources */
    127 #define WDF_LBA		0x040 /* using LBA mode */
    128 #define WDF_KLABEL	0x080 /* retain label after 'full' close */
    129 #define WDF_LBA48	0x100 /* using 48-bit LBA mode */
    130 	u_int64_t sc_capacity;
    131 	int cyl; /* actual drive parameters */
    132 	int heads;
    133 	int sectors;
    134 	int retries; /* number of xfer retry */
    135 
    136 	void *sc_sdhook;		/* our shutdown hook */
    137 
    138 	SLIST_HEAD(, disk_badsectors)	sc_bslist;
    139 	u_int sc_bscount;
    140 
    141 #if NRND > 0
    142 	rndsource_element_t	rnd_source;
    143 #endif
    144 };
    145 
    146 #define sc_drive sc_wdc_bio.drive
    147 #define sc_mode sc_wdc_bio.mode
    148 #define sc_multi sc_wdc_bio.multi
    149 #define sc_badsect sc_wdc_bio.badsect
    150 
    151 #endif /* __ATA_DISK_PRIVATE */
    152 
    153 void wddone __P((void *));
    154