xref: /openbsd/sys/dev/ata/wdvar.h (revision d677d78d)
1 /*	$OpenBSD: wdvar.h,v 1.21 2014/07/09 12:56:28 mpi Exp $	*/
2 /*	$NetBSD: wdvar.h,v 1.3 1998/11/11 19:38:27 bouyer Exp $	*/
3 
4 /*
5  * Copyright (c) 1998, 2001 Manuel Bouyer.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 #ifndef _DEV_ATA_WDVAR_H_
30 #define _DEV_ATA_WDVAR_H_
31 
32 /* Params needed by the controller to perform an ATA bio */
33 struct ata_bio {
34     volatile u_int16_t flags; /* cmd flags */
35 #define ATA_NOSLEEP 0x0001 /* Can't sleep */
36 #define ATA_POLL    0x0002 /* poll for completion */
37 #define ATA_ITSDONE 0x0004 /* the transfer is as done as it gets */
38 #define ATA_SINGLE  0x0008 /* transfer has to be done in single-sector mode */
39 #define ATA_LBA     0x0010 /* transfer uses LBA addressing */
40 #define ATA_READ    0x0020 /* transfer is a read (otherwise a write) */
41 #define ATA_CORR    0x0040 /* transfer had a corrected error */
42 #define ATA_LBA48   0x0080 /* transfer uses 48-bit LBA addressing */
43     int multi; /* number of blocks to transfer in multi-mode */
44     struct disklabel *lp; /* pointer to drive's label info */
45     daddr_t blkno; /* block addr */
46     daddr_t blkdone; /* number of blks transferred */
47     daddr_t nblks; /* number of block currently transferring */
48     int     nbytes; /* number of bytes currently transferring */
49     long    bcount; /* total number of bytes */
50     char   *databuf; /* data buffer address */
51     volatile int error;
52 #define NOERROR   0 /* There was no error (r_error invalid) */
53 #define ERROR     1 /* check r_error */
54 #define ERR_DF    2 /* Drive fault */
55 #define ERR_DMA   3 /* DMA error */
56 #define TIMEOUT   4 /* device timed out */
57 #define ERR_NODEV 5 /* device bas been detached */
58     u_int8_t r_error; /* copy of error register */
59     struct wd_softc *wd;
60 };
61 
62 struct wd_softc {
63 	/* General disk infos */
64 	struct device sc_dev;
65 	struct disk sc_dk;
66 	struct bufq sc_bufq;
67 
68 	/* IDE disk soft states */
69 	struct ata_bio sc_wdc_bio; /* current transfer */
70 	struct buf *sc_bp; /* buf being transferred */
71 	struct ata_drive_datas *drvp; /* Our controller's infos */
72 	int openings;
73 	struct ataparams sc_params;/* drive characteristics found */
74 	int sc_flags;
75 /*
76  * XXX Nothing resets this yet, but disk change sensing will when ATA-4 is
77  * more fully implemented.
78  */
79 #define WDF_LOADED	0x10 /* parameters loaded */
80 #define WDF_WAIT	0x20 /* waiting for resources */
81 #define WDF_LBA		0x40 /* using LBA mode */
82 #define WDF_LBA48	0x80 /* using 48-bit LBA mode */
83 
84 	u_int64_t sc_capacity;
85 	int cyl; /* actual drive parameters */
86 	int heads;
87 	int sectors;
88 	int retries; /* number of xfer retry */
89 	struct timeout sc_restart_timeout;
90 };
91 
92 /* drive states stored in ata_drive_datas */
93 #define RECAL          0
94 #define RECAL_WAIT     1
95 #define PIOMODE        2
96 #define PIOMODE_WAIT   3
97 #define DMAMODE        4
98 #define DMAMODE_WAIT   5
99 #define GEOMETRY       6
100 #define GEOMETRY_WAIT  7
101 #define MULTIMODE      8
102 #define MULTIMODE_WAIT 9
103 #define READY          10
104 
105 int wdc_ata_bio(struct ata_drive_datas*, struct ata_bio*);
106 int wd_hibernate_io(dev_t dev, daddr_t blkno, vaddr_t addr, size_t size,
107 	    int wr, void *page);
108 
109 void wddone(void *);
110 
111 #endif	/* !_DEV_ATA_WDVAR_H_ */
112