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