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