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/twe/twevar.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 /*-
    2  * Copyright (c) 2000 Michael Smith
    3  * Copyright (c) 2000 BSDi
    4  * All rights reserved.
    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  *
   15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
   16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
   18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
   19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
   20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
   21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
   22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
   23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
   24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   25  * SUCH DAMAGE.
   26  *
   27  *      $FreeBSD: releng/5.3/sys/dev/twe/twevar.h 130358 2004-06-11 18:42:44Z vkashyap $
   28  */
   29 
   30 #define TWE_DRIVER_VERSION_STRING       "1.50.01.002"
   31 
   32 #ifdef TWE_DEBUG
   33 #define debug(level, fmt, args...)                                                      \
   34         do {                                                                            \
   35             if (level <= TWE_DEBUG) printf("%s: " fmt "\n", __func__ , ##args); \
   36         } while(0)
   37 #define debug_called(level)                                             \
   38         do {                                                            \
   39             if (level <= TWE_DEBUG) printf("%s: called\n", __func__);   \
   40         } while(0)
   41 #else
   42 #define debug(level, fmt, args...)
   43 #define debug_called(level)
   44 #endif
   45 
   46 /*
   47  * Structure describing a logical unit as attached to the controller
   48  */
   49 struct twe_drive
   50 {
   51     /* unit properties */
   52     u_int32_t           td_size;
   53     int                 td_cylinders;
   54     int                 td_heads;
   55     int                 td_sectors;
   56     int                 td_sys_unit; /* device unit number */
   57     int                 td_twe_unit; /* index into sc->twe_drive[] */
   58 
   59     /* unit state and type */
   60     u_int8_t            td_state;
   61     u_int8_t            td_type;
   62 
   63     /* handle for attached driver */
   64     device_t            td_disk;
   65 };
   66 
   67 /*
   68  * Per-command control structure.
   69  *
   70  * Note that due to alignment constraints on the tc_command field, this *must* be 64-byte aligned.
   71  * We achieve this by placing the command at the beginning of the structure, and using malloc()
   72  * to allocate each structure.
   73  */
   74 struct twe_request
   75 {
   76     int                         tr_tag;
   77     /* command payload */
   78     void                        *tr_data;       /* data buffer */
   79     void                        *tr_realdata;   /* copy of real data buffer pointer for alignment fixup */
   80     size_t                      tr_length;
   81 
   82     TAILQ_ENTRY(twe_request)    tr_link;        /* list linkage */
   83     struct twe_softc            *tr_sc;         /* controller that owns us */
   84     int                         tr_status;      /* command status */
   85 #define TWE_CMD_SETUP           0       /* being assembled */
   86 #define TWE_CMD_BUSY            1       /* submitted to controller */
   87 #define TWE_CMD_COMPLETE        2       /* completed by controller (maybe with error) */
   88 #define TWE_CMD_ERROR           3       /* encountered error, even before submission to controller */
   89     int                         tr_flags;
   90 #define TWE_CMD_DATAIN          (1<<0)
   91 #define TWE_CMD_DATAOUT         (1<<1)
   92 #define TWE_CMD_ALIGNBUF        (1<<2)  /* data in bio is misaligned, have to copy to/from private buffer */
   93 #define TWE_CMD_SLEEPER         (1<<3)  /* owner is sleeping on this command */
   94 #define TWE_CMD_IMMEDIATE       (1<<4)  /* immediate request */
   95 #define TWE_CMD_MAPPED          (1<<5)
   96 #define TWE_CMD_IN_PROGRESS     (1<<6)  /* bus_dmamap_load returned EINPROGRESS */
   97     void                        (* tr_complete)(struct twe_request *tr);        /* completion handler */
   98     void                        *tr_private;    /* submitter-private data or wait channel */
   99 
  100     TWE_PLATFORM_REQUEST        /* platform-specific request elements */
  101 };
  102 
  103 #define TWE_FIND_COMMAND(tr)                                    \
  104         (TWE_Command *)((u_int8_t *)(tr)->tr_sc->twe_cmd +      \
  105                         ((tr)->tr_tag * sizeof(TWE_Command)))
  106 #define TWE_FIND_COMMANDPHYS(tr)        ((tr)->tr_sc->twe_cmdphys +     \
  107                                          ((tr)->tr_tag * sizeof(TWE_Command)))
  108         
  109 /*
  110  * Per-controller state.
  111  */
  112 struct twe_softc 
  113 {
  114     /* controller queues and arrays */
  115     TAILQ_HEAD(, twe_request)   twe_free;                       /* command structures available for reuse */
  116     twe_bioq                    twe_bioq;                       /* outstanding I/O operations */
  117     TAILQ_HEAD(, twe_request)   twe_ready;                      /* requests ready for the controller */
  118     TAILQ_HEAD(, twe_request)   twe_busy;                       /* requests busy in the controller */
  119     TAILQ_HEAD(, twe_request)   twe_complete;                   /* active commands (busy or waiting for completion) */
  120     struct twe_request          *twe_lookup[TWE_Q_LENGTH];      /* commands indexed by request ID */
  121     struct twe_drive    twe_drive[TWE_MAX_UNITS];               /* attached drives */
  122 
  123     /* asynchronous event handling */
  124     u_int16_t           twe_aen_queue[TWE_Q_LENGTH];    /* AENs queued for userland tool(s) */
  125     int                 twe_aen_head, twe_aen_tail;     /* ringbuffer pointers for AEN queue */
  126     int                 twe_wait_aen;                   /* wait-for-aen notification */
  127 
  128     /* controller status */
  129     int                 twe_state;
  130 #define TWE_STATE_INTEN         (1<<0)  /* interrupts have been enabled */
  131 #define TWE_STATE_SHUTDOWN      (1<<1)  /* controller is shut down */
  132 #define TWE_STATE_OPEN          (1<<2)  /* control device is open */
  133 #define TWE_STATE_SUSPEND       (1<<3)  /* controller is suspended */
  134 #define TWE_STATE_FRZN          (1<<4)  /* got EINPROGRESS */
  135 #define TWE_STATE_CTLR_BUSY     (1<<5)  /* controller cmd queue full */
  136     int                 twe_host_id;
  137     struct twe_qstat    twe_qstat[TWEQ_COUNT];  /* queue statistics */
  138 
  139     TWE_PLATFORM_SOFTC          /* platform-specific softc elements */
  140 };
  141 
  142 /*
  143  * Interface betwen driver core and platform-dependant code.
  144  */
  145 extern int      twe_setup(struct twe_softc *sc);                /* do early driver/controller setup */
  146 extern void     twe_init(struct twe_softc *sc);                 /* init controller */
  147 extern void     twe_deinit(struct twe_softc *sc);               /* stop controller */
  148 extern void     twe_intr(struct twe_softc *sc);                 /* hardware interrupt signalled */
  149 extern void     twe_startio(struct twe_softc *sc);
  150 extern int      twe_start(struct twe_request *tr);
  151 extern int      twe_dump_blocks(struct twe_softc *sc, int unit, /* crashdump block write */
  152                                 u_int32_t lba, void *data, int nblks);
  153 extern int      twe_ioctl(struct twe_softc *sc, int cmd,
  154                                   void *addr);                  /* handle user request */
  155 extern void     twe_describe_controller(struct twe_softc *sc);  /* print controller info */
  156 extern void     twe_print_controller(struct twe_softc *sc);
  157 extern void     twe_enable_interrupts(struct twe_softc *sc);    /* enable controller interrupts */
  158 extern void     twe_disable_interrupts(struct twe_softc *sc);   /* disable controller interrupts */
  159 
  160 extern int      twe_attach_drive(struct twe_softc *sc,
  161                                          struct twe_drive *dr); /* attach drive when found in twe_init */
  162 extern int      twe_detach_drive(struct twe_softc *sc,
  163                                          int unit);             /* detach drive */
  164 extern void     twe_clear_pci_parity_error(struct twe_softc *sc);
  165 extern void     twe_clear_pci_abort(struct twe_softc *sc);
  166 extern void     twed_intr(twe_bio *bp);                         /* return bio from core */
  167 extern struct twe_request *twe_allocate_request(struct twe_softc *sc, int tag); /* allocate request structure */
  168 extern void     twe_free_request(struct twe_request *tr);       /* free request structure */
  169 extern int      twe_map_request(struct twe_request *tr);        /* make request visible to controller, do s/g */
  170 extern void     twe_unmap_request(struct twe_request *tr);      /* cleanup after transfer, unmap */
  171 
  172 /********************************************************************************
  173  * Queue primitives
  174  */
  175 #define TWEQ_ADD(sc, qname)                                     \
  176         do {                                                    \
  177             struct twe_qstat *qs = &(sc)->twe_qstat[qname];     \
  178                                                                 \
  179             qs->q_length++;                                     \
  180             if (qs->q_length > qs->q_max)                       \
  181                 qs->q_max = qs->q_length;                       \
  182         } while(0)
  183 
  184 #define TWEQ_REMOVE(sc, qname)                                  \
  185         do {                                                    \
  186             struct twe_qstat *qs = &(sc)->twe_qstat[qname];     \
  187                                                                 \
  188             qs->q_length--;                                     \
  189             if (qs->q_length < qs->q_min)                       \
  190                 qs->q_min = qs->q_length;                       \
  191         } while(0);
  192 
  193 #define TWEQ_INIT(sc, qname)                                    \
  194         do {                                                    \
  195             sc->twe_qstat[qname].q_length = 0;                  \
  196             sc->twe_qstat[qname].q_max = 0;                     \
  197             sc->twe_qstat[qname].q_min = 0xFFFFFFFF;            \
  198         } while(0)
  199 
  200 
  201 #define TWEQ_REQUEST_QUEUE(name, index)                                 \
  202 static __inline void                                                    \
  203 twe_initq_ ## name (struct twe_softc *sc)                               \
  204 {                                                                       \
  205     TAILQ_INIT(&sc->twe_ ## name);                                      \
  206     TWEQ_INIT(sc, index);                                               \
  207 }                                                                       \
  208 static __inline void                                                    \
  209 twe_enqueue_ ## name (struct twe_request *tr)                           \
  210 {                                                                       \
  211     int         s;                                                      \
  212                                                                         \
  213     s = splbio();                                                       \
  214     TAILQ_INSERT_TAIL(&tr->tr_sc->twe_ ## name, tr, tr_link);           \
  215     TWEQ_ADD(tr->tr_sc, index);                                         \
  216     splx(s);                                                            \
  217 }                                                                       \
  218 static __inline void                                                    \
  219 twe_requeue_ ## name (struct twe_request *tr)                           \
  220 {                                                                       \
  221     int         s;                                                      \
  222                                                                         \
  223     s = splbio();                                                       \
  224     TAILQ_INSERT_HEAD(&tr->tr_sc->twe_ ## name, tr, tr_link);           \
  225     TWEQ_ADD(tr->tr_sc, index);                                         \
  226     splx(s);                                                            \
  227 }                                                                       \
  228 static __inline struct twe_request *                                    \
  229 twe_dequeue_ ## name (struct twe_softc *sc)                             \
  230 {                                                                       \
  231     struct twe_request  *tr;                                            \
  232     int                 s;                                              \
  233                                                                         \
  234     s = splbio();                                                       \
  235     if ((tr = TAILQ_FIRST(&sc->twe_ ## name)) != NULL) {                \
  236         TAILQ_REMOVE(&sc->twe_ ## name, tr, tr_link);                   \
  237         TWEQ_REMOVE(sc, index);                                         \
  238     }                                                                   \
  239     splx(s);                                                            \
  240     return(tr);                                                         \
  241 }                                                                       \
  242 static __inline void                                                    \
  243 twe_remove_ ## name (struct twe_request *tr)                            \
  244 {                                                                       \
  245     int                 s;                                              \
  246                                                                         \
  247     s = splbio();                                                       \
  248     TAILQ_REMOVE(&tr->tr_sc->twe_ ## name, tr, tr_link);                \
  249     TWEQ_REMOVE(tr->tr_sc, index);                                      \
  250     splx(s);                                                            \
  251 }
  252 
  253 TWEQ_REQUEST_QUEUE(free, TWEQ_FREE)
  254 TWEQ_REQUEST_QUEUE(ready, TWEQ_READY)
  255 TWEQ_REQUEST_QUEUE(busy, TWEQ_BUSY)
  256 TWEQ_REQUEST_QUEUE(complete, TWEQ_COMPLETE)
  257 
  258 /*
  259  * outstanding bio queue
  260  */
  261 static __inline void
  262 twe_initq_bio(struct twe_softc *sc)
  263 {
  264     TWE_BIO_QINIT(sc->twe_bioq);
  265     TWEQ_INIT(sc, TWEQ_BIO);
  266 }
  267 
  268 static __inline void
  269 twe_enqueue_bio(struct twe_softc *sc, twe_bio *bp)
  270 {
  271     int         s;
  272 
  273     s = splbio();
  274     TWE_BIO_QINSERT(sc->twe_bioq, bp);
  275     TWEQ_ADD(sc, TWEQ_BIO);
  276     splx(s);
  277 }
  278 
  279 static __inline twe_bio *
  280 twe_dequeue_bio(struct twe_softc *sc)
  281 {
  282     int         s;
  283     twe_bio     *bp;
  284 
  285     s = splbio();
  286     if ((bp = TWE_BIO_QFIRST(sc->twe_bioq)) != NULL) {
  287         TWE_BIO_QREMOVE(sc->twe_bioq, bp);
  288         TWEQ_REMOVE(sc, TWEQ_BIO);
  289     }
  290     splx(s);
  291     return(bp);
  292 }

Cache object: d192b22b19501814b26f0cd53f0b5b67


[ 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.