Print this page
MFV: illumos-gate@2aba3acda67326648fd60aaf2bfb4e18ee8c04ed
9816 Multi-TRB xhci transfers should use event data
9817 xhci needs to always set slot context
8550 increase xhci bulk transfer sgl count
9818 xhci_transfer_get_tdsize can return values that are too large
Reviewed by: Alex Wilson <alex.wilson@joyent.com>
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Approved by: Joshua M. Clulow <josh@sysmgr.org>
Author: Robert Mustacchi <rm@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/sys/usb/hcd/xhci/xhci.h
          +++ new/usr/src/uts/common/sys/usb/hcd/xhci/xhci.h
↓ open down ↓ 2 lines elided ↑ open up ↑
   3    3   * Common Development and Distribution License ("CDDL"), version 1.0.
   4    4   * You may only use this file in accordance with the terms of version
   5    5   * 1.0 of the CDDL.
   6    6   *
   7    7   * A full copy of the text of the CDDL should have accompanied this
   8    8   * source.  A copy of the CDDL is also available via the Internet at
   9    9   * http://www.illumos.org/license/CDDL.
  10   10   */
  11   11  
  12   12  /*
  13      - * Copyright 2016 Joyent, Inc.
       13 + * Copyright (c) 2018, Joyent, Inc.
  14   14   */
  15   15  
  16   16  #ifndef _SYS_USB_XHCI_XHCI_H
  17   17  #define _SYS_USB_XHCI_XHCI_H
  18   18  
  19   19  /*
  20   20   * Extensible Host Controller Interface (xHCI) USB Driver
  21   21   */
  22   22  
  23   23  #include <sys/conf.h>
↓ open down ↓ 25 lines elided ↑ open up ↑
  49   49   * hence we use that for everything.
  50   50   *
  51   51   * Next is the scatter/gather lengths. For most of the data structures, we only
  52   52   * want to have a single SGL entry, e.g. just a simple flat mapping. For many of
  53   53   * our transfers, we use the same logic to simplify the implementation of the
  54   54   * driver. However, for bulk transfers, which are the largest by far, we want to
  55   55   * be able to leverage SGLs to give us more DMA flexibility.
  56   56   *
  57   57   * We can transfer up to 64K in one transfer request block (TRB) which
  58   58   * corresponds to a single SGL entry. Each ring we create is a single page in
  59      - * size and will support at most 256 TRBs. We've selected to use up to 8 SGLs
  60      - * for these transfer cases. This allows us to put up to 512 KiB in a given
  61      - * transfer request and in the worst case, we can have about 30 of them
  62      - * outstanding. Experimentally, this has proven to be sufficient for most of the
  63      - * drivers that we support today.
       59 + * size and will support at most 256 TRBs. To try and give the operating system
       60 + * flexibility when allocating DMA transfers, we've opted to allow up to 63
       61 + * SGLs. Because there isn't a good way to support DMA windows with the xHCI
       62 + * controller design, if this number is too small then DMA allocations and
       63 + * binding might fail. If the DMA binding fails, the transfer will fail.
       64 + *
       65 + * The reason that we use 63 SGLs and not the expected 64 is that we always need
       66 + * to allocate an additional TRB for the event data. This leaves us with a
       67 + * nicely divisible number of entries.
       68 + *
       69 + * The final piece of this is the maximum sized transfer that the driver
       70 + * advertises to the broader framework. This is currently sized at 512 KiB. For
       71 + * reference the ehci driver sized this value at 640 KiB. It's important to
       72 + * understand that this isn't reflected in the DMA attribute limitation, because
       73 + * it's not an attribute of the hardware. Experimentally, this has proven to be
       74 + * sufficient for most of the drivers that we support today. When considering
       75 + * increasing this number, please note the impact that might have on the
       76 + * required number of DMA SGL entries required to satisfy the allocation.
       77 + *
       78 + * The value of 512 KiB was originally based on the number of SGLs we supported
       79 + * multiplied by the maximum transfer size. The original number of
       80 + * XHCI_TRANSFER_DMA_SGL was 8. The 512 KiB value was based upon taking the
       81 + * number of SGLs and assuming that each TRB used its maximum transfer size of
       82 + * 64 KiB.
  64   83   */
  65      -#define XHCI_TRB_MAX_TRANSFER   65536
       84 +#define XHCI_TRB_MAX_TRANSFER   65536   /* 64 KiB */
  66   85  #define XHCI_DMA_ALIGN          64
  67   86  #define XHCI_DEF_DMA_SGL        1
  68      -#define XHCI_TRANSFER_DMA_SGL   8
  69      -#define XHCI_MAX_TRANSFER       (XHCI_TRB_MAX_TRANSFER * XHCI_TRANSFER_DMA_SGL)
  70      -#define XHCI_DMA_STRUCT_SIZE    4096
       87 +#define XHCI_TRANSFER_DMA_SGL   63
       88 +#define XHCI_MAX_TRANSFER       524288  /* 512 KiB */
  71   89  
  72   90  /*
  73   91   * Properties and values for rerouting ehci ports to xhci.
  74   92   */
  75   93  #define XHCI_PROP_REROUTE_DISABLE       0
  76   94  #define XHCI_PROP_REROUTE_DEFAULT       1
  77   95  
  78   96  /*
  79   97   * This number is a bit made up. Truthfully, the API here isn't the most useful
  80   98   * for what we need to define as it should really be based on the endpoint that
↓ open down ↓ 10 lines elided ↑ open up ↑
  91  109  #define XHCI_DMA_SYNC(dma, flag)        VERIFY0(ddi_dma_sync( \
  92  110                                              (dma).xdb_dma_handle, 0, 0, \
  93  111                                              (flag)))
  94  112  #else
  95  113  #define XHCI_DMA_SYNC(dma, flag)        ((void) ddi_dma_sync( \
  96  114                                              (dma).xdb_dma_handle, 0, 0, \
  97  115                                              (flag)))
  98  116  #endif
  99  117  
 100  118  /*
      119 + * TRBs need to indicate the number of remaining USB packets in the overall
      120 + * transfer. This is a 5-bit value, which means that the maximum value we can
      121 + * store in that TRD field is 31.
      122 + */
      123 +#define XHCI_MAX_TDSIZE         31
      124 +
      125 +/*
 101  126   * This defines a time in 2-ms ticks that is required to wait for the controller
 102  127   * to be ready to go. Section 5.4.8 of the XHCI specification in the description
 103  128   * of the PORTSC register indicates that the upper bound is 20 ms. Therefore the
 104  129   * number of ticks is 10.
 105  130   */
 106  131  #define XHCI_POWER_GOOD 10
 107  132  
 108  133  /*
 109  134   * Definitions to determine the default number of interrupts. Note that we only
 110  135   * bother with a single interrupt at this time, though we've arranged the driver
 111  136   * to make it possible to request more if, for some unlikely reason, it becomes
 112  137   * necessary.
 113  138   */
 114  139  #define XHCI_NINTR      1
 115  140  
 116  141  /*
 117  142   * Default interrupt modulation value. This enables us to have 4000 interrupts /
 118  143   * second. This is supposed to be the default value of the controller. See xHCI
 119  144   * 1.1 / 4.17.2 for more information.
 120  145   */
 121      -#define XHCI_IMOD_DEFAULT       0x000003F8U
      146 +#define XHCI_IMOD_DEFAULT       0x000003F8U
 122  147  
 123  148  /*
 124  149   * Definitions that surround the default values used in various contexts. These
 125  150   * come from various parts of the xHCI specification. In general, see xHCI 1.1 /
 126  151   * 4.8.2. Note that the MPS_MASK is used for ISOCH and INTR endpoints which have
 127  152   * different sizes.
 128  153   *
 129  154   * The burst member is a bit more complicated. By default for USB 2 devices, it
 130  155   * only matters for ISOCH and INTR endpoints and so we use the macros below to
 131  156   * pull it out of the endpoint description's max packet field. For USB 3, it
↓ open down ↓ 59 lines elided ↑ open up ↑
 191  216  /*
 192  217   * Set of bits that we need one of to indicate that this port has something
 193  218   * interesting on it.
 194  219   */
 195  220  #define XHCI_HUB_INTR_CHANGE_MASK       (XHCI_PS_CSC | XHCI_PS_PEC | \
 196  221      XHCI_PS_WRC | XHCI_PS_OCC | XHCI_PS_PRC | XHCI_PS_PLC | XHCI_PS_CEC)
 197  222  
 198  223  /*
 199  224   * These represent known issues with various xHCI controllers.
 200  225   *
 201      - *      XHCI_QUIRK_NO_MSI       MSI support on this controller is known to be
 202      - *                              broken.
      226 + *      XHCI_QUIRK_NO_MSI       MSI support on this controller is known to be
      227 + *                              broken.
 203  228   *
 204      - *      XHCI_QUIRK_32_ONLY      Only use 32-bit DMA addreses with this
 205      - *                              controller.
      229 + *      XHCI_QUIRK_32_ONLY      Only use 32-bit DMA addreses with this
      230 + *                              controller.
 206  231   *
 207      - *      XHCI_QUIRK_INTC_EHCI    This is an Intel platform which supports
 208      - *                              rerouting ports between EHCI and xHCI
 209      - *                              controllers on the platform.
      232 + *      XHCI_QUIRK_INTC_EHCI    This is an Intel platform which supports
      233 + *                              rerouting ports between EHCI and xHCI
      234 + *                              controllers on the platform.
 210  235   */
 211  236  typedef enum xhci_quirk {
 212  237          XHCI_QUIRK_NO_MSI       = 0x01,
 213  238          XHCI_QUIRK_32_ONLY      = 0x02,
 214  239          XHCI_QUIRK_INTC_EHCI    = 0x04
 215  240  } xhci_quirk_t;
 216  241  
 217  242  /*
 218  243   * xHCI capability parameter flags. These are documented in xHCI 1.1 / 5.3.6.
 219  244   */
 220  245  typedef enum xhci_cap_flags {
 221      -        XCAP_AC64       = 0x001,
      246 +        XCAP_AC64       = 0x001,
 222  247          XCAP_BNC        = 0x002,
 223  248          XCAP_CSZ        = 0x004,
 224  249          XCAP_PPC        = 0x008,
 225  250          XCAP_PIND       = 0x010,
 226  251          XCAP_LHRC       = 0x020,
 227  252          XCAP_LTC        = 0x040,
 228  253          XCAP_NSS        = 0x080,
 229  254          XCAP_PAE        = 0x100,
 230  255          XCAP_SPC        = 0x200,
 231  256          XCAP_SEC        = 0x400,
↓ open down ↓ 71 lines elided ↑ open up ↑
 303  328  typedef struct xhci_transfer {
 304  329          list_node_t             xt_link;
 305  330          hrtime_t                xt_sched_time;
 306  331          xhci_dma_buffer_t       xt_buffer;
 307  332          uint_t                  xt_ntrbs;
 308  333          uint_t                  xt_short;
 309  334          uint_t                  xt_timeout;
 310  335          usb_cr_t                xt_cr;
 311  336          boolean_t               xt_data_tohost;
 312  337          xhci_trb_t              *xt_trbs;
      338 +        uint64_t                *xt_trbs_pa;
 313  339          usb_isoc_pkt_descr_t    *xt_isoc;
 314  340          usb_opaque_t            xt_usba_req;
 315  341  } xhci_transfer_t;
 316  342  
 317  343  /*
 318  344   * This represents a ring in xHCI, upon which event, transfer, and command TRBs
 319  345   * are scheduled.
 320  346   */
 321  347  typedef struct xhci_ring {
 322  348          xhci_dma_buffer_t       xr_dma;
↓ open down ↓ 97 lines elided ↑ open up ↑
 420  446          kcondvar_t                      xcr_cv;
 421  447          list_t                          xcr_commands;
 422  448          timeout_id_t                    xcr_timeout;
 423  449          xhci_command_ring_state_t       xcr_state;
 424  450  } xhci_command_ring_t;
 425  451  
 426  452  /*
 427  453   * Individual command states.
 428  454   *
 429  455   * XHCI_COMMAND_S_INIT          The command has yet to be inserted into the
 430      - *                              command ring.
      456 + *                              command ring.
 431  457   *
 432  458   * XHCI_COMMAND_S_QUEUED        The command is queued in the command ring.
 433  459   *
 434  460   * XHCI_COMMAND_S_RECEIVED      A command completion for this was received.
 435  461   *
 436  462   * XHCI_COMMAND_S_DONE          The command has been executed. Note that it may
 437      - *                              have been aborted.
      463 + *                              have been aborted.
 438  464   *
 439  465   * XHCI_COMMAND_S_RESET         The ring is being reset due to a fatal error and
 440      - *                              this command has been removed from the ring.
 441      - *                              This means it has been aborted, but it was not
 442      - *                              the cause of the abort.
      466 + *                              this command has been removed from the ring.
      467 + *                              This means it has been aborted, but it was not
      468 + *                              the cause of the abort.
 443  469   *
 444  470   * Note, when adding states, anything after XHCI_COMMAND_S_DONE implies that
 445  471   * upon reaching this state, it is no longer in the ring.
 446  472   */
 447  473  typedef enum xhci_command_state {
 448  474          XHCI_COMMAND_S_INIT     = 0x00,
 449  475          XHCI_COMMAND_S_QUEUED   = 0x01,
 450  476          XHCI_COMMAND_S_RECEIVED = 0x02,
 451  477          XHCI_COMMAND_S_DONE     = 0x03,
 452  478          XHCI_COMMAND_S_RESET    = 0x04
↓ open down ↓ 188 lines elided ↑ open up ↑
 641  667  extern void xhci_dma_transfer_attr(xhci_t *, ddi_dma_attr_t *, uint_t);
 642  668  extern void xhci_dma_free(xhci_dma_buffer_t *);
 643  669  extern boolean_t xhci_dma_alloc(xhci_t *, xhci_dma_buffer_t *, ddi_dma_attr_t *,
 644  670      ddi_device_acc_attr_t *, boolean_t, size_t, boolean_t);
 645  671  extern uint64_t xhci_dma_pa(xhci_dma_buffer_t *);
 646  672  
 647  673  /*
 648  674   * DMA Transfer Ring functions
 649  675   */
 650  676  extern xhci_transfer_t *xhci_transfer_alloc(xhci_t *, xhci_endpoint_t *, size_t,
 651      -    int, int);
      677 +    uint_t, int);
 652  678  extern void xhci_transfer_free(xhci_t *, xhci_transfer_t *);
 653  679  extern void xhci_transfer_copy(xhci_transfer_t *, void *, size_t, boolean_t);
 654  680  extern int xhci_transfer_sync(xhci_t *, xhci_transfer_t *, uint_t);
 655  681  extern void xhci_transfer_trb_fill_data(xhci_endpoint_t *, xhci_transfer_t *,
 656  682      int, boolean_t);
 657  683  extern void xhci_transfer_calculate_isoc(xhci_device_t *, xhci_endpoint_t *,
 658  684      uint_t, uint_t *, uint_t *);
 659  685  
 660  686  /*
 661  687   * Context (DCBAA, Scratchpad, Slot) functions
↓ open down ↓ 45 lines elided ↑ open up ↑
 707  733  extern xhci_trb_t *xhci_ring_event_advance(xhci_ring_t *);
 708  734  
 709  735  
 710  736  /*
 711  737   * Command and Transfer Ring (Producer) oriented functions.
 712  738   */
 713  739  extern boolean_t xhci_ring_trb_tail_valid(xhci_ring_t *, uint64_t);
 714  740  extern int xhci_ring_trb_valid_range(xhci_ring_t *, uint64_t, uint_t);
 715  741  
 716  742  extern boolean_t xhci_ring_trb_space(xhci_ring_t *, uint_t);
 717      -extern void xhci_ring_trb_fill(xhci_ring_t *, uint_t, xhci_trb_t *, boolean_t);
      743 +extern void xhci_ring_trb_fill(xhci_ring_t *, uint_t, xhci_trb_t *, uint64_t *,
      744 +    boolean_t);
 718  745  extern void xhci_ring_trb_produce(xhci_ring_t *, uint_t);
 719  746  extern boolean_t xhci_ring_trb_consumed(xhci_ring_t *, uint64_t);
 720  747  extern void xhci_ring_trb_put(xhci_ring_t *, xhci_trb_t *);
 721  748  extern void xhci_ring_skip(xhci_ring_t *);
 722  749  extern void xhci_ring_skip_transfer(xhci_ring_t *, xhci_transfer_t *);
 723  750  
 724  751  /*
 725  752   * MMIO related functions. Note callers are responsible for checking with FM
 726  753   * after accessing registers.
 727  754   */
↓ open down ↓ 72 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX