The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/ata/atavar.h

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: atavar.h,v 1.40.2.2 2004/08/11 19:44:05 jmc 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 #ifndef _DEV_ATA_ATAVAR_H_
   33 #define _DEV_ATA_ATAVAR_H_
   34 
   35 #include <sys/lock.h>
   36 #include <sys/queue.h>
   37 
   38 /*
   39  * Description of a command to be handled by an ATA controller.  These
   40  * commands are queued in a list.
   41  */
   42 struct ata_xfer {
   43         __volatile u_int c_flags;       /* command state flags */
   44         
   45         /* Channel and drive that are to process the request. */
   46         struct wdc_channel *c_chp;
   47         int     c_drive;
   48 
   49         void    *c_cmd;                 /* private request structure pointer */
   50         void    *c_databuf;             /* pointer to data buffer */
   51         int     c_bcount;               /* byte count left */
   52         int     c_skip;                 /* bytes already transferred */
   53         int     c_dscpoll;              /* counter for dsc polling (ATAPI) */
   54 
   55         /* Link on the command queue. */
   56         TAILQ_ENTRY(ata_xfer) c_xferchain;
   57 
   58         /* Low-level protocol handlers. */
   59         void    (*c_start)(struct wdc_channel *, struct ata_xfer *);
   60         int     (*c_intr)(struct wdc_channel *, struct ata_xfer *, int);
   61         void    (*c_kill_xfer)(struct wdc_channel *, struct ata_xfer *, int);
   62 };
   63 
   64 /* vlags in c_flags */
   65 #define C_ATAPI         0x0001          /* xfer is ATAPI request */
   66 #define C_TIMEOU        0x0002          /* xfer processing timed out */
   67 #define C_POLL          0x0004          /* command is polled */
   68 #define C_DMA           0x0008          /* command uses DMA */
   69 
   70 /* reasons for c_kill_xfer() */
   71 #define KILL_GONE 1 /* device is gone */
   72 #define KILL_RESET 2 /* xfer was reset */
   73 
   74 /* Per-channel queue of ata_xfers.  May be shared by multiple channels. */
   75 struct ata_queue {
   76         TAILQ_HEAD(, ata_xfer) queue_xfer;
   77         int queue_freeze;
   78 };
   79 
   80 /* ATA bus instance state information. */
   81 struct atabus_softc {
   82         struct device sc_dev;
   83         struct wdc_channel *sc_chan;    /* XXXwdc */
   84 };
   85 
   86 /*
   87  * A queue of atabus instances, used to ensure the same bus probe order
   88  * for a given hardware configuration at each boot.
   89  */
   90 struct atabus_initq {
   91         TAILQ_ENTRY(atabus_initq) atabus_initq;
   92         struct atabus_softc *atabus_sc;
   93 };
   94 
   95 #ifdef _KERNEL
   96 TAILQ_HEAD(atabus_initq_head, atabus_initq);
   97 extern struct atabus_initq_head atabus_initq_head;
   98 extern struct simplelock atabus_interlock;
   99 #endif /* _KERNEL */
  100 
  101 /* High-level functions and structures used by both ATA and ATAPI devices */
  102 struct ataparams;
  103 
  104 /* Datas common to drives and controller drivers */
  105 struct ata_drive_datas {
  106         u_int8_t drive;         /* drive number */
  107         int8_t ata_vers;        /* ATA version supported */
  108         u_int16_t drive_flags;  /* bitmask for drives present/absent and cap */
  109 
  110 #define DRIVE_ATA       0x0001
  111 #define DRIVE_ATAPI     0x0002
  112 #define DRIVE_OLD       0x0004 
  113 #define DRIVE           (DRIVE_ATA|DRIVE_ATAPI|DRIVE_OLD)
  114 #define DRIVE_CAP32     0x0008
  115 #define DRIVE_DMA       0x0010 
  116 #define DRIVE_UDMA      0x0020
  117 #define DRIVE_MODE      0x0040  /* the drive reported its mode */
  118 #define DRIVE_RESET     0x0080  /* reset the drive state at next xfer */
  119 #define DRIVE_DMAERR    0x0100  /* Udma transfer had crc error, don't try DMA */
  120 #define DRIVE_ATAPIST   0x0200  /* device is an ATAPI tape drive */
  121 
  122         /*
  123          * Current setting of drive's PIO, DMA and UDMA modes.
  124          * Is initialised by the disks drivers at attach time, and may be
  125          * changed later by the controller's code if needed
  126          */
  127         u_int8_t PIO_mode;      /* Current setting of drive's PIO mode */
  128         u_int8_t DMA_mode;      /* Current setting of drive's DMA mode */
  129         u_int8_t UDMA_mode;     /* Current setting of drive's UDMA mode */
  130 
  131         /* Supported modes for this drive */
  132         u_int8_t PIO_cap;       /* supported drive's PIO mode */
  133         u_int8_t DMA_cap;       /* supported drive's DMA mode */
  134         u_int8_t UDMA_cap;      /* supported drive's UDMA mode */
  135 
  136         /*
  137          * Drive state.
  138          * This is reset to 0 after a channel reset.
  139          */
  140         u_int8_t state;
  141 
  142 #define RESET          0
  143 #define READY          1
  144 
  145         /* numbers of xfers and DMA errs. Used by ata_dmaerr() */
  146         u_int8_t n_dmaerrs;
  147         u_int32_t n_xfers;
  148 
  149         /* Downgrade after NERRS_MAX errors in at most NXFER xfers */
  150 #define NERRS_MAX 4
  151 #define NXFER 4000
  152 
  153         /* Callbacks into the drive's driver. */
  154         void    (*drv_done)(void *);    /* transfer is done */
  155 
  156         struct device *drv_softc;       /* ATA drives softc, if any */
  157         void *chnl_softc;               /* channel softc */
  158 };
  159 
  160 /* User config flags that force (or disable) the use of a mode */
  161 #define ATA_CONFIG_PIO_MODES    0x0007
  162 #define ATA_CONFIG_PIO_SET      0x0008
  163 #define ATA_CONFIG_PIO_OFF      0
  164 #define ATA_CONFIG_DMA_MODES    0x0070
  165 #define ATA_CONFIG_DMA_SET      0x0080
  166 #define ATA_CONFIG_DMA_DISABLE  0x0070
  167 #define ATA_CONFIG_DMA_OFF      4
  168 #define ATA_CONFIG_UDMA_MODES   0x0700
  169 #define ATA_CONFIG_UDMA_SET     0x0800
  170 #define ATA_CONFIG_UDMA_DISABLE 0x0700
  171 #define ATA_CONFIG_UDMA_OFF     8
  172 
  173 /*
  174  * Parameters/state needed by the controller to perform an ATA bio.
  175  */
  176 struct ata_bio {
  177         volatile u_int16_t flags;/* cmd flags */
  178 #define ATA_NOSLEEP     0x0001  /* Can't sleep */   
  179 #define ATA_POLL        0x0002  /* poll for completion */
  180 #define ATA_ITSDONE     0x0004  /* the transfer is as done as it gets */
  181 #define ATA_SINGLE      0x0008  /* transfer must be done in singlesector mode */
  182 #define ATA_LBA         0x0010  /* transfer uses LBA addressing */
  183 #define ATA_READ        0x0020  /* transfer is a read (otherwise a write) */
  184 #define ATA_CORR        0x0040  /* transfer had a corrected error */
  185 #define ATA_LBA48       0x0080  /* transfer uses 48-bit LBA addressing */
  186         int             multi;  /* # of blocks to transfer in multi-mode */
  187         struct disklabel *lp;   /* pointer to drive's label info */
  188         daddr_t         blkno;  /* block addr */
  189         daddr_t         blkdone;/* number of blks transferred */
  190         daddr_t         nblks;  /* number of block currently transferring */
  191         int             nbytes; /* number of bytes currently transferring */
  192         long            bcount; /* total number of bytes */
  193         char            *databuf;/* data buffer address */
  194         volatile int    error;
  195 #define NOERROR         0       /* There was no error (r_error invalid) */
  196 #define ERROR           1       /* check r_error */
  197 #define ERR_DF          2       /* Drive fault */
  198 #define ERR_DMA         3       /* DMA error */
  199 #define TIMEOUT         4       /* device timed out */
  200 #define ERR_NODEV       5       /* device has been gone */
  201 #define ERR_RESET       6       /* command was terminated by channel reset */
  202         u_int8_t        r_error;/* copy of error register */
  203         daddr_t         badsect[127];/* 126 plus trailing -1 marker */
  204 };
  205 
  206 /*
  207  * ATA/ATAPI commands description 
  208  *
  209  * This structure defines the interface between the ATA/ATAPI device driver
  210  * and the controller for short commands. It contains the command's parameter,
  211  * the len of data's to read/write (if any), and a function to call upon
  212  * completion.
  213  * If no sleep is allowed, the driver can poll for command completion.
  214  * Once the command completed, if the error registed is valid, the flag
  215  * AT_ERROR is set and the error register value is copied to r_error .
  216  * A separate interface is needed for read/write or ATAPI packet commands
  217  * (which need multiple interrupts per commands).
  218  */
  219 struct wdc_command {
  220         u_int8_t r_command;     /* Parameters to upload to registers */
  221         u_int8_t r_head;
  222         u_int16_t r_cyl;
  223         u_int8_t r_sector;
  224         u_int8_t r_count;
  225         u_int8_t r_precomp;
  226         u_int8_t r_st_bmask;    /* status register mask to wait for before
  227                                    command */
  228         u_int8_t r_st_pmask;    /* status register mask to wait for after
  229                                    command */
  230         u_int8_t r_error;       /* error register after command done */
  231         volatile u_int16_t flags;
  232 
  233 #define AT_READ     0x0001 /* There is data to read */
  234 #define AT_WRITE    0x0002 /* There is data to write (excl. with AT_READ) */
  235 #define AT_WAIT     0x0008 /* wait in controller code for command completion */
  236 #define AT_POLL     0x0010 /* poll for command completion (no interrupts) */
  237 #define AT_DONE     0x0020 /* command is done */
  238 #define AT_XFDONE   0x0040 /* data xfer is done */
  239 #define AT_ERROR    0x0080 /* command is done with error */
  240 #define AT_TIMEOU   0x0100 /* command timed out */
  241 #define AT_DF       0x0200 /* Drive fault */
  242 #define AT_RESET    0x0400 /* command terminated by channel reset */
  243 #define AT_GONE     0x0800 /* command terminated because device is gone */
  244 #define AT_READREG  0x1000 /* Read registers on completion */
  245 
  246         int timeout;            /* timeout (in ms) */
  247         void *data;             /* Data buffer address */
  248         int bcount;             /* number of bytes to transfer */
  249         void (*callback)(void *); /* command to call once command completed */
  250         void *callback_arg;     /* argument passed to *callback() */
  251 };
  252 
  253 /*
  254  * ata_bustype.  The first field must be compatible with scsipi_bustype,
  255  * as it's used for autoconfig by both ata and atapi drivers.
  256  */
  257 struct ata_bustype {
  258         int     bustype_type;   /* symbolic name of type */
  259         int     (*ata_bio)(struct ata_drive_datas *, struct ata_bio *);
  260         void    (*ata_reset_channel)(struct ata_drive_datas *, int);
  261 /* extra flags for ata_reset_channel(), in addition to AT_* */
  262 #define AT_RST_EMERG 0x10000 /* emergency - e.g. for a dump */
  263 #define AT_RST_NOCMD 0x20000 /* XXX has to go - temporary until we have tagged queuing */
  264 
  265         int     (*ata_exec_command)(struct ata_drive_datas *,
  266                                     struct wdc_command *);
  267 
  268 #define WDC_COMPLETE    0x01
  269 #define WDC_QUEUED      0x02
  270 #define WDC_TRY_AGAIN   0x03
  271 
  272         int     (*ata_get_params)(struct ata_drive_datas *, u_int8_t,
  273                                   struct ataparams *);
  274         int     (*ata_addref)(struct ata_drive_datas *);
  275         void    (*ata_delref)(struct ata_drive_datas *);
  276         void    (*ata_killpending)(struct ata_drive_datas *);
  277 };
  278 
  279 /* bustype_type */      /* XXX XXX XXX */
  280 /* #define SCSIPI_BUSTYPE_SCSI  0 */
  281 /* #define SCSIPI_BUSTYPE_ATAPI 1 */
  282 #define SCSIPI_BUSTYPE_ATA      2
  283 
  284 /*
  285  * Describe an ATA device.  Has to be compatible with scsipi_channel, so
  286  * start with a pointer to ata_bustype.
  287  */
  288 struct ata_device {
  289         const struct ata_bustype *adev_bustype;
  290         int adev_channel;
  291         int adev_openings;
  292         struct ata_drive_datas *adev_drv_data;
  293 };
  294 
  295 #ifdef _KERNEL
  296 int     atabusprint(void *aux, const char *);
  297 int     ataprint(void *aux, const char *);
  298 
  299 int     wdc_downgrade_mode(struct ata_drive_datas *, int);
  300 
  301 struct ataparams;
  302 int     ata_get_params(struct ata_drive_datas *, u_int8_t, struct ataparams *);
  303 int     ata_set_mode(struct ata_drive_datas *, u_int8_t, u_int8_t);
  304 /* return code for these cmds */
  305 #define CMD_OK    0
  306 #define CMD_ERR   1
  307 #define CMD_AGAIN 2
  308 
  309 void    ata_dmaerr(struct ata_drive_datas *, int);
  310 #endif /* _KERNEL */
  311 
  312 #endif /* _DEV_ATA_ATAVAR_H_ */

Cache object: 3a1e90263431c0b9f74667227a657249


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.