Print this page
    
3644 Add virtio-net support into illumos
4945 Additional vioif fixes
Contributions by: Dan Kimmel <dan.kimmel@delphix.com>
Contributions by: Hans Rosenfeld <hans.rosenfeld@nexenta.com>
Contributions by: Alexey Zaytsev <alexey.zaytsev@gmail.com>
Contributions by: Dmitry Yusupov <Dmitry.Yusupov@nexenta.com>
Reviewed by: Igor Kozhukhov <ikozhukhov@gmail.com>
    
      
        | Split | 
	Close | 
      
      | Expand all | 
      | Collapse all | 
    
    
          --- old/usr/src/uts/common/io/virtio/virtiovar.h
          +++ new/usr/src/uts/common/io/virtio/virtiovar.h
   1    1  /*
   2    2   * Copyright (c) 2010 Minoura Makoto.
   3    3   * All rights reserved.
   4    4   *
   5    5   * Redistribution and use in source and binary forms, with or without
   6    6   * modification, are permitted provided that the following conditions
   7    7   * are met:
   8    8   * 1. Redistributions of source code must retain the above copyright
   9    9   *    notice, this list of conditions and the following disclaimer.
  10   10   * 2. Redistributions in binary form must reproduce the above copyright
  11   11   *    notice, this list of conditions and the following disclaimer in the
  12   12   *    documentation and/or other materials provided with the distribution.
  13   13   *
  14   14   * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  15   15   * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  16   16   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  17   17   * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  18   18   * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  19   19   * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20   20   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  21   21   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22   22   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  23   23   * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24   24   */
  25   25  
  26   26  /*
  27   27   * Part of the file derived from `Virtio PCI Card Specification v0.8.6 DRAFT'
  28   28   * Appendix A.
  29   29   */
  30   30  
  31   31  /*
  32   32   * An interface for efficient virtio implementation.
  33   33   *
  34   34   * This header is BSD licensed so anyone can use the definitions
  35   35   * to implement compatible drivers/servers.
  36   36   *
  37   37   * Copyright 2007, 2009, IBM Corporation
  38   38   * All rights reserved.
  39   39   *
  40   40   * Redistribution and use in source and binary forms, with or without
  41   41   * modification, are permitted provided that the following conditions
  42   42   * are met:
  43   43   * 1. Redistributions of source code must retain the above copyright
  44   44   *    notice, this list of conditions and the following disclaimer.
  45   45   * 2. Redistributions in binary form must reproduce the above copyright
  46   46   *    notice, this list of conditions and the following disclaimer in the
  47   47   *    documentation and/or other materials provided with the distribution.
  48   48   * 3. Neither the name of IBM nor the names of its contributors
  49   49   *    may be used to endorse or promote products derived from this software
  50   50   *    without specific prior written permission.
  51   51   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  52   52   * ``AS IS'' ANDANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
  53   53   * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  54   54   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
  55   55   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  56   56   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  57   57   * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  58   58   * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  59   59   * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  60   60   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  61   61   * SUCH DAMAGE.
  62   62   */
  63   63  
  64   64  /*
  65   65   * Copyright 2012 Nexenta Systems, Inc. All rights reserved.
  66   66   */
  67   67  
  68   68  #ifndef __VIRTIOVAR_H__
  69   69  #define __VIRTIOVAR_H__
  70   70  
  71   71  #include <sys/types.h>
  72   72  #include <sys/dditypes.h>
  73   73  #include <sys/cmn_err.h>
  74   74  #include <sys/list.h>
  75   75  
  76   76  #ifdef DEBUG
  77   77  #define dev_debug(dip, fmt, arg...) \
  78   78          dev_err(dip, fmt, ##arg)
  79   79  #else
  80   80  #define dev_debug(dip, fmt, arg...)
  81   81  #endif
  82   82  
  83   83  struct vq_entry {
  84   84          list_node_t             qe_list;
  85   85          struct virtqueue        *qe_queue;
  86   86          uint16_t                qe_index; /* index in vq_desc array */
  87   87          /* followings are used only when it is the `head' entry */
  88   88          struct vq_entry         *qe_next;
  89   89          struct vring_desc       *qe_desc;
  90   90          ddi_dma_cookie_t        qe_indirect_dma_cookie;
  91   91          ddi_dma_handle_t        qe_indirect_dma_handle;
  92   92          ddi_acc_handle_t        qe_indirect_dma_acch;
  93   93          struct vring_desc       *qe_indirect_descs;
  94   94          unsigned int            qe_indirect_next;
  95   95  };
  96   96  
  97   97  struct virtqueue {
  98   98          struct virtio_softc     *vq_owner;
  99   99          unsigned int            vq_num; /* queue size (# of entries) */
 100  100          unsigned int            vq_indirect_num;
 101  101          int                     vq_index; /* queue number (0, 1, ...) */
 102  102  
 103  103          /* vring pointers (KVA) */
 104  104          struct vring_desc       *vq_descs;
 105  105          struct vring_avail      *vq_avail;
 106  106          struct vring_used       *vq_used;
 107  107  
 108  108          /* virtqueue allocation info */
 109  109          void                    *vq_vaddr;
 110  110          int                     vq_availoffset;
 111  111          int                     vq_usedoffset;
 112  112          ddi_dma_cookie_t        vq_dma_cookie;
 113  113          ddi_dma_handle_t        vq_dma_handle;
 114  114          ddi_acc_handle_t        vq_dma_acch;
 115  115  
 116  116          int                     vq_maxsegsize;
 117  117  
 118  118          /* free entry management */
 119  119          struct vq_entry         *vq_entries;
 120  120          list_t                  vq_freelist;
 121  121          kmutex_t                vq_freelist_lock;
 122  122          int                     vq_used_entries;
 123  123  
 124  124          /* enqueue/dequeue status */
 125  125          uint16_t                vq_avail_idx;
 126  126          kmutex_t                vq_avail_lock;
 127  127          uint16_t                vq_used_idx;
 128  128          kmutex_t                vq_used_lock;
 129  129  };
 130  130  
 131  131  struct virtio_softc {
 132  132          dev_info_t              *sc_dev;
 133  133  
 134  134          uint_t                  sc_intr_prio;
 135  135  
 136  136          ddi_acc_handle_t        sc_ioh;
 137  137          caddr_t                 sc_io_addr;
 138  138          int                     sc_config_offset;
 139  139  
 140  140          uint32_t                sc_features;
 141  141  
 142  142          int                     sc_nvqs; /* set by the user */
 143  143  
 144  144          ddi_intr_handle_t       *sc_intr_htable;
 145  145          int                     sc_intr_num;
 146  146          boolean_t               sc_intr_config;
 147  147          int                     sc_intr_cap;
 148  148  };
 149  149  
 150  150  struct virtio_int_handler {
 151  151          ddi_intr_handler_t *vh_func;
 152  152          void *vh_priv;
 153  153  };
 154  154  
 155  155  /* public interface */
 156  156  uint32_t virtio_negotiate_features(struct virtio_softc *, uint32_t);
 157  157  size_t virtio_show_features(uint32_t features, char *buffer, size_t len);
 158  158  boolean_t virtio_has_feature(struct virtio_softc *sc, uint32_t feature);
 159  159  void virtio_set_status(struct virtio_softc *sc, unsigned int);
 160  160  #define virtio_device_reset(sc) virtio_set_status((sc), 0)
 161  161  
 162  162  uint8_t virtio_read_device_config_1(struct virtio_softc *sc,
 163  163                  unsigned int index);
 164  164  uint16_t virtio_read_device_config_2(struct virtio_softc *sc,
 165  165                  unsigned int index);
 166  166  uint32_t virtio_read_device_config_4(struct virtio_softc *sc,
 167  167                  unsigned int index);
 168  168  uint64_t virtio_read_device_config_8(struct virtio_softc *sc,
 169  169                  unsigned int index);
 170  170  void virtio_write_device_config_1(struct virtio_softc *sc,
 171  171                  unsigned int index, uint8_t value);
 172  172  void virtio_write_device_config_2(struct virtio_softc *sc,
 173  173                  unsigned int index, uint16_t value);
 174  174  void virtio_write_device_config_4(struct virtio_softc *sc,
 175  175                  unsigned int index, uint32_t value);
 176  176  void virtio_write_device_config_8(struct virtio_softc *sc,
  
    | 
      ↓ open down ↓ | 
    176 lines elided | 
    
      ↑ open up ↑ | 
  
 177  177                  unsigned int index, uint64_t value);
 178  178  
 179  179  struct virtqueue *virtio_alloc_vq(struct virtio_softc *sc,
 180  180                  unsigned int index, unsigned int size,
 181  181                  unsigned int indirect_num, const char *name);
 182  182  void virtio_free_vq(struct virtqueue *);
 183  183  void virtio_reset(struct virtio_softc *);
 184  184  struct vq_entry *vq_alloc_entry(struct virtqueue *vq);
 185  185  void vq_free_entry(struct virtqueue *vq, struct vq_entry *qe);
 186  186  uint_t vq_num_used(struct virtqueue *vq);
      187 +unsigned int virtio_ve_indirect_available(struct vq_entry *qe);
 187  188  
 188  189  void virtio_stop_vq_intr(struct virtqueue *);
 189  190  void virtio_start_vq_intr(struct virtqueue *);
 190  191  
 191  192  void virtio_ve_add_cookie(struct vq_entry *qe, ddi_dma_handle_t dma_handle,
 192  193      ddi_dma_cookie_t dma_cookie, unsigned int ncookies, boolean_t write);
 193  194  void virtio_ve_add_indirect_buf(struct vq_entry *qe, uint64_t paddr,
 194  195      uint32_t len, boolean_t write);
 195  196  void virtio_ve_set(struct vq_entry *qe, uint64_t paddr, uint32_t len,
 196  197                  boolean_t write);
 197  198  
 198  199  void virtio_push_chain(struct vq_entry *qe, boolean_t sync);
 199  200  struct vq_entry *virtio_pull_chain(struct virtqueue *vq, uint32_t *len);
 200  201  void virtio_free_chain(struct vq_entry *ve);
 201  202  void virtio_sync_vq(struct virtqueue *vq);
 202  203  
 203  204  int virtio_register_ints(struct virtio_softc *sc,
 204  205                  struct virtio_int_handler *config_handler,
 205  206                  struct virtio_int_handler vq_handlers[]);
 206  207  void virtio_release_ints(struct virtio_softc *sc);
 207  208  int virtio_enable_ints(struct virtio_softc *sc);
 208  209  
 209  210  #endif /* __VIRTIOVAR_H__ */
  
    | 
      ↓ open down ↓ | 
    13 lines elided | 
    
      ↑ open up ↑ | 
  
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX