Print this page
Add xhci_quiesce to support fast reboot.

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/io/usb/hcd/xhci/xhci.c
          +++ new/usr/src/uts/common/io/usb/hcd/xhci/xhci.c
↓ open down ↓ 3 lines elided ↑ open up ↑
   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   13   * Copyright (c) 2017, Joyent, Inc.
       14 + * Copyright (c) 2018, Western Digital Corporation.
  14   15   */
  15   16  
  16   17  /*
  17   18   * Extensible Host Controller Interface (xHCI) USB Driver
  18   19   *
  19   20   * The xhci driver is an HCI driver for USB that bridges the gap between client
  20   21   * device drivers and implements the actual way that we talk to devices. The
  21   22   * xhci specification provides access to USB 3.x capable devices, as well as all
  22   23   * prior generations. Like other host controllers, it both provides the way to
  23   24   * talk to devices and also is treated like a hub (often called the root hub).
↓ open down ↓ 55 lines elided ↑ open up ↑
  79   80   *
  80   81   * Each endpoint encodes two different pieces of information: a direction and a
  81   82   * type. There are two different directions: IN and OUT. These refer to the
  82   83   * general direction that data moves relative to the operating system. For
  83   84   * example, an IN transfer transfers data in to the operating system, from the
  84   85   * device. An OUT transfer transfers data from the operating system, out to the
  85   86   * device.
  86   87   *
  87   88   * There are four different kinds of endpoints:
  88   89   *
  89      - *      BULK            These transfers are large transfers of data to or from
  90      - *                      a device. The most common use for bulk transfers is for
  91      - *                      mass storage devices. Though they are often also used by
  92      - *                      network devices and more. Bulk endpoints do not have an
  93      - *                      explicit time component to them. They are always used
  94      - *                      for one-shot transfers.
       90 + *      BULK            These transfers are large transfers of data to or from
       91 + *                      a device. The most common use for bulk transfers is for
       92 + *                      mass storage devices. Though they are often also used by
       93 + *                      network devices and more. Bulk endpoints do not have an
       94 + *                      explicit time component to them. They are always used
       95 + *                      for one-shot transfers.
  95   96   *
  96      - *      CONTROL         These transfers are used to manipulate devices
  97      - *                      themselves and are used for USB protocol level
  98      - *                      operations (whether device-specific, class-specific, or
  99      - *                      generic across all of USB). Unlike other transfers,
 100      - *                      control transfers are always bi-directional and use
 101      - *                      different kinds of transfers.
       97 + *      CONTROL         These transfers are used to manipulate devices
       98 + *                      themselves and are used for USB protocol level
       99 + *                      operations (whether device-specific, class-specific, or
      100 + *                      generic across all of USB). Unlike other transfers,
      101 + *                      control transfers are always bi-directional and use
      102 + *                      different kinds of transfers.
 102  103   *
 103      - *      INTERRUPT       Interrupt transfers are used for small transfers that
 104      - *                      happen infrequently, but need reasonable latency. A good
 105      - *                      example of interrupt transfers is to receive input from
 106      - *                      a USB keyboard. Interrupt-IN transfers are generally
 107      - *                      polled. Meaning that a client (device driver) opens up
 108      - *                      an interrupt-IN pipe to poll on it, and receives
 109      - *                      periodic updates whenever there is information
 110      - *                      available. However, Interrupt transfers can be used
 111      - *                      as one-shot transfers both going IN and OUT.
      104 + *      INTERRUPT       Interrupt transfers are used for small transfers that
      105 + *                      happen infrequently, but need reasonable latency. A good
      106 + *                      example of interrupt transfers is to receive input from
      107 + *                      a USB keyboard. Interrupt-IN transfers are generally
      108 + *                      polled. Meaning that a client (device driver) opens up
      109 + *                      an interrupt-IN pipe to poll on it, and receives
      110 + *                      periodic updates whenever there is information
      111 + *                      available. However, Interrupt transfers can be used
      112 + *                      as one-shot transfers both going IN and OUT.
 112  113   *
 113      - *      ISOCHRONOUS     These transfers are things that happen once per
 114      - *                      time-interval at a very regular rate. A good example of
 115      - *                      these transfers are for audio and video. A device may
 116      - *                      describe an interval as 10ms at which point it will read
 117      - *                      or write the next batch of data every 10ms and transform
 118      - *                      it for the user. There are no one-shot Isochronous-IN
 119      - *                      transfers. There are one-shot Isochronous-OUT transfers,
 120      - *                      but these are used by device drivers to always provide
 121      - *                      the system with sufficient data.
      114 + *      ISOCHRONOUS     These transfers are things that happen once per
      115 + *                      time-interval at a very regular rate. A good example of
      116 + *                      these transfers are for audio and video. A device may
      117 + *                      describe an interval as 10ms at which point it will read
      118 + *                      or write the next batch of data every 10ms and transform
      119 + *                      it for the user. There are no one-shot Isochronous-IN
      120 + *                      transfers. There are one-shot Isochronous-OUT transfers,
      121 + *                      but these are used by device drivers to always provide
      122 + *                      the system with sufficient data.
 122  123   *
 123  124   * To find out information about the endpoints, USB devices have a series of
 124  125   * descriptors that cover different aspects of the device. For example, there
 125  126   * are endpoint descriptors which cover the properties of endpoints such as the
 126  127   * maximum packet size or polling interval.
 127  128   *
 128  129   * Descriptors exist at all levels of USB. For example, there are general
 129  130   * descriptors for every device. The USB device descriptor is described in
 130  131   * usb_dev_descr(9S). Host controllers will look at these descriptors to ensure
 131  132   * that they program the device correctly; however, they are more often used by
↓ open down ↓ 81 lines elided ↑ open up ↑
 213  214   *
 214  215   * ------------
 215  216   * Organization
 216  217   * ------------
 217  218   *
 218  219   * The driver is made up of the following files. Many of these have their own
 219  220   * theory statements to describe what they do. Here, we touch on each of the
 220  221   * purpose of each of these files.
 221  222   *
 222  223   * xhci_command.c:      This file contains the logic to issue commands to the
 223      - *                      controller as well as the actual functions that the
 224      - *                      other parts of the driver use to cause those commands.
      224 + *                      controller as well as the actual functions that the
      225 + *                      other parts of the driver use to cause those commands.
 225  226   *
 226  227   * xhci_context.c:      This file manages various data structures used by the
 227      - *                      controller to manage the controller's and device's
 228      - *                      context data structures. See more in the xHCI Overview
 229      - *                      and General Design for more information.
      228 + *                      controller to manage the controller's and device's
      229 + *                      context data structures. See more in the xHCI Overview
      230 + *                      and General Design for more information.
 230  231   *
 231  232   * xhci_dma.c:          This manages the allocation of DMA memory and DMA
 232      - *                      attributes for controller, whether memory is for a
 233      - *                      transfer or something else. This file also deals with
 234      - *                      all the logic of getting data in and out of DMA buffers.
      233 + *                      attributes for controller, whether memory is for a
      234 + *                      transfer or something else. This file also deals with
      235 + *                      all the logic of getting data in and out of DMA buffers.
 235  236   *
 236  237   * xhci_endpoint.c:     This manages all of the logic of handling endpoints or
 237      - *                      pipes. It deals with endpoint configuration, I/O
 238      - *                      scheduling, timeouts, and callbacks to USBA.
      238 + *                      pipes. It deals with endpoint configuration, I/O
      239 + *                      scheduling, timeouts, and callbacks to USBA.
 239  240   *
 240  241   * xhci_event.c:        This manages callbacks from the hardware to the driver.
 241      - *                      This covers command completion notifications and I/O
 242      - *                      notifications.
      242 + *                      This covers command completion notifications and I/O
      243 + *                      notifications.
 243  244   *
 244  245   * xhci_hub.c:          This manages the virtual root-hub. It basically
 245      - *                      implements and translates all of the USB level requests
 246      - *                      into xhci specific implements. It also contains the
 247      - *                      functions to register this hub with USBA.
      246 + *                      implements and translates all of the USB level requests
      247 + *                      into xhci specific implements. It also contains the
      248 + *                      functions to register this hub with USBA.
 248  249   *
 249  250   * xhci_intr.c:         This manages the underlying interrupt allocation,
 250      - *                      interrupt moderation, and interrupt routines.
      251 + *                      interrupt moderation, and interrupt routines.
 251  252   *
 252  253   * xhci_quirks.c:       This manages information about buggy hardware that's
 253      - *                      been collected and experienced primarily from other
 254      - *                      systems.
      254 + *                      been collected and experienced primarily from other
      255 + *                      systems.
 255  256   *
 256  257   * xhci_ring.c:         This manages the abstraction of a ring in xhci, which is
 257      - *                      the primary of communication between the driver and the
 258      - *                      hardware, whether for the controller or a device.
      258 + *                      the primary of communication between the driver and the
      259 + *                      hardware, whether for the controller or a device.
 259  260   *
 260  261   * xhci_usba.c:         This implements all of the HCDI functions required by
 261      - *                      USBA. This is the main entry point that drivers and the
 262      - *                      kernel frameworks will reach to start any operation.
 263      - *                      Many functions here will end up in the command and
 264      - *                      endpoint code.
      262 + *                      USBA. This is the main entry point that drivers and the
      263 + *                      kernel frameworks will reach to start any operation.
      264 + *                      Many functions here will end up in the command and
      265 + *                      endpoint code.
 265  266   *
 266  267   * xhci.c:              This provides the main kernel DDI interfaces and
 267      - *                      performs device initialization.
      268 + *                      performs device initialization.
 268  269   *
 269  270   * xhci.h:              This is the primary header file which defines
 270      - *                      illumos-specific data structures and constants to manage
 271      - *                      the system.
      271 + *                      illumos-specific data structures and constants to manage
      272 + *                      the system.
 272  273   *
 273  274   * xhcireg.h:           This header file defines all of the register offsets,
 274      - *                      masks, and related macros. It also contains all of the
 275      - *                      constants that are used in various structures as defined
 276      - *                      by the specification, such as command offsets, etc.
      275 + *                      masks, and related macros. It also contains all of the
      276 + *                      constants that are used in various structures as defined
      277 + *                      by the specification, such as command offsets, etc.
 277  278   *
 278  279   * xhci_ioctl.h:        This contains a few private ioctls that are used by a
 279      - *                      private debugging command. These are private.
      280 + *                      private debugging command. These are private.
 280  281   *
 281  282   * cmd/xhci/xhci_portsc:        This is a private utility that can be useful for
 282      - *                              debugging xhci state. It is the only consumer of
 283      - *                              xhci_ioctl.h and the private ioctls.
      283 + *                              debugging xhci state. It is the only consumer of
      284 + *                              xhci_ioctl.h and the private ioctls.
 284  285   *
 285  286   * ----------------------------------
 286  287   * xHCI Overview and Structure Layout
 287  288   * ----------------------------------
 288  289   *
 289  290   * The design and structure of this driver follows from the way that the xHCI
 290  291   * specification tells us that we have to work with hardware. First we'll give a
 291  292   * rough summary of how that works, though the xHCI 1.1 specification should be
 292  293   * referenced when going through this.
 293  294   *
↓ open down ↓ 27 lines elided ↑ open up ↑
 321  322   * ports on the chassis.
 322  323   *
 323  324   * For each device, there is a context structure that describes properties of
 324  325   * the device. For example, what speed is the device, is it a hub, etc. The
 325  326   * context has slots for the device and for each endpoint on the device. As
 326  327   * endpoints are enabled, their context information which describes things like
 327  328   * the maximum packet size, is filled in and enabled. The mapping between these
 328  329   * contexts look like:
 329  330   *
 330  331   *
 331      - *      DCBAA
 332      - *    +--------+                    Device Context
      332 + *      DCBAA
      333 + *    +--------+                    Device Context
 333  334   *    | Slot 0 |------------------>+--------------+
 334      - *    +--------+                   | Slot Context |
 335      - *    |  ...   |                   +--------------+       +----------+
 336      - *    +--------+   +------+        |  Endpoint 0  |------>| I/O Ring |
 337      - *    | Slot n |-->| NULL |        | Context (Bi) |       +----------+
 338      - *    +--------+   +------+        +--------------+
 339      - *                                 |  Endpoint 1  |
 340      - *                                 | Context (Out)|
 341      - *                                 +--------------+
 342      - *                                 |  Endpoint 1  |
 343      - *                                 | Context (In) |
 344      - *                                 +--------------+
 345      - *                                 |      ...     |
 346      - *                                 +--------------+
 347      - *                                 | Endpoint 15  |
 348      - *                                 | Context (In) |
 349      - *                                 +--------------+
      335 + *    +--------+                   | Slot Context |
      336 + *    |  ...   |                   +--------------+       +----------+
      337 + *    +--------+   +------+        |  Endpoint 0  |------>| I/O Ring |
      338 + *    | Slot n |-->| NULL |        | Context (Bi) |       +----------+
      339 + *    +--------+   +------+        +--------------+
      340 + *                                 |  Endpoint 1  |
      341 + *                                 | Context (Out)|
      342 + *                                 +--------------+
      343 + *                                 |  Endpoint 1  |
      344 + *                                 | Context (In) |
      345 + *                                 +--------------+
      346 + *                                 |      ...     |
      347 + *                                 +--------------+
      348 + *                                 | Endpoint 15  |
      349 + *                                 | Context (In) |
      350 + *                                 +--------------+
 350  351   *
 351  352   * These contexts are always owned by the controller, though we can read them
 352  353   * after various operations complete. Commands that toggle device state use a
 353  354   * specific input context, which is a variant of the device context. The only
 354  355   * difference is that it has an input context structure ahead of it to say which
 355  356   * sections of the device context should be evaluated.
 356  357   *
 357  358   * Each active endpoint points us to an I/O ring, which leads us to the third
 358  359   * main data structure that's used by the device: rings. Rings are made up of
 359  360   * transfer request blocks (TRBs), which are joined together to form a given
↓ open down ↓ 36 lines elided ↑ open up ↑
 396  397   * with an endpoint are purely for producing I/O.
 397  398   *
 398  399   * Endpoints have a defined state machine as described in xHCI 1.1 / 4.8.3.
 399  400   * These states generally correspond with the state of the endpoint to process
 400  401   * I/O and handle timeouts. The driver basically follows a similar state machine
 401  402   * as described there. There are some deviations. For example, what they
 402  403   * describe as 'running' we break into both the Idle and Running states below.
 403  404   * We also have a notion of timed out and quiescing. The following image
 404  405   * summarizes the states and transitions:
 405  406   *
 406      - *     +------+                                +-----------+
      407 + *     +------+                                +-----------+
 407  408   *     | Idle |---------*--------------------->|  Running  |<-+
 408      - *     +------+         . I/O queued on        +-----------+  |
 409      - *        ^               ring and timeout        |  |  |     |
 410      - *        |               scheduled.              |  |  |     |
 411      - *        |                                       |  |  |     |
 412      - *        +-----*---------------------------------+  |  |     |
 413      - *        |     . No I/Os remain                     |  |     |
 414      - *        |                                          |  |     |
 415      - *        |                +------*------------------+  |     |
 416      - *        |                |      . Timeout             |     |
 417      - *        |                |        fires for           |     |
 418      - *        |                |        I/O                 |     |
 419      - *        |                v                            v     |
 420      - *        |          +-----------+                +--------+  |
 421      - *        |          | Timed Out |                | Halted |  |
 422      - *        |          +-----------+                +--------+  |
 423      - *        |             |                           |         |
 424      - *        |             |   +-----------+           |         |
 425      - *        |             +-->| Quiescing |<----------+         |
 426      - *        |                 +-----------+                     |
 427      - *        |   No TRBs.           |                . TRBs      |
 428      - *        |   remain .           |                . Remain    |
 429      - *        +----------*----<------+-------->-------*-----------+
      409 + *     +------+         . I/O queued on        +-----------+  |
      410 + *        ^               ring and timeout        |  |  |     |
      411 + *        |               scheduled.              |  |  |     |
      412 + *        |                                       |  |  |     |
      413 + *        +-----*---------------------------------+  |  |     |
      414 + *        |     . No I/Os remain                     |  |     |
      415 + *        |                                          |  |     |
      416 + *        |                +------*------------------+  |     |
      417 + *        |                |      . Timeout             |     |
      418 + *        |                |        fires for           |     |
      419 + *        |                |        I/O                 |     |
      420 + *        |                v                            v     |
      421 + *        |          +-----------+                +--------+  |
      422 + *        |          | Timed Out |                | Halted |  |
      423 + *        |          +-----------+                +--------+  |
      424 + *        |             |                           |         |
      425 + *        |             |   +-----------+           |         |
      426 + *        |             +-->| Quiescing |<----------+         |
      427 + *        |                 +-----------+                     |
      428 + *        |   No TRBs.           |                . TRBs      |
      429 + *        |   remain .           |                . Remain    |
      430 + *        +----------*----<------+-------->-------*-----------+
 430  431   *
 431  432   * Normally, a given endpoint will oscillate between having TRBs scheduled and
 432  433   * not. Every time a new I/O is added to the endpoint, we'll ring the doorbell,
 433  434   * making sure that we're processing the ring, presuming that the endpoint isn't
 434  435   * in one of the error states.
 435  436   *
 436  437   * To detect device hangs, we have an active timeout(9F) per active endpoint
 437  438   * that ticks at a one second rate while we still have TRBs outstanding on an
 438  439   * endpoint. Once all outstanding TRBs have been processed, the timeout will
 439  440   * stop itself and there will be no active checking until the endpoint has I/O
↓ open down ↓ 16 lines elided ↑ open up ↑
 456  457   * leaves the device stopped, which allows us to update the ring's pointer and
 457  458   * remove any TRBs that are causing problems.
 458  459   *
 459  460   * As part of all this, we ensure that we can only be quiescing the device from
 460  461   * a given path at a time. Any requests to schedule I/O during this time will
 461  462   * generally fail.
 462  463   *
 463  464   * The following image describes the state machine for the timeout logic. It
 464  465   * ties into the image above.
 465  466   *
 466      - *         +----------+                            +---------+
 467      - *         | Disabled |-----*--------------------->| Enabled |<--+
 468      - *         +----------+     . TRBs scheduled       +---------+   *. 1 sec timer
 469      - *             ^              and no active          |  |  |     |  fires and
 470      - *             |              timer.                 |  |  |     |  another
 471      - *             |                                     |  |  +--+--+  quiesce, in
 472      - *             |                                     |  |     |     a bad state,
 473      - *             +------*------------------------------+  |     ^     or decrement
 474      - *             |      . 1 sec timer                     |     |     I/O timeout
 475      - *             |        fires and                       |     |
 476      - *             |        no TRBs or                      |     +--------------+
 477      - *             |        endpoint shutdown               |                    |
 478      - *             |                                        *. . timer counter   |
 479      - *             ^                                        |    reaches zero    |
 480      - *             |                                        v                    |
 481      - *             |                                +--------------+             |
 482      - *             +-------------*---------------<--| Quiesce ring |->---*-------+
 483      - *                           . No more          | and fail I/O |     . restart
 484      - *                             I/Os             +--------------+       timer as
 485      - *                                                                     more I/Os
      467 + *         +----------+                            +---------+
      468 + *         | Disabled |-----*--------------------->| Enabled |<--+
      469 + *         +----------+     . TRBs scheduled       +---------+   *. 1 sec timer
      470 + *             ^              and no active          |  |  |     |  fires and
      471 + *             |              timer.                 |  |  |     |  another
      472 + *             |                                     |  |  +--+--+  quiesce, in
      473 + *             |                                     |  |     |     a bad state,
      474 + *             +------*------------------------------+  |     ^     or decrement
      475 + *             |      . 1 sec timer                     |     |     I/O timeout
      476 + *             |        fires and                       |     |
      477 + *             |        no TRBs or                      |     +--------------+
      478 + *             |        endpoint shutdown               |                    |
      479 + *             |                                        *. . timer counter   |
      480 + *             ^                                        |    reaches zero    |
      481 + *             |                                        v                    |
      482 + *             |                                +--------------+             |
      483 + *             +-------------*---------------<--| Quiesce ring |->---*-------+
      484 + *                           . No more          | and fail I/O |     . restart
      485 + *                             I/Os             +--------------+       timer as
      486 + *                                                                     more I/Os
 486  487   *
 487  488   * As we described above, when there are active TRBs and I/Os, a 1 second
 488  489   * timeout(9F) will be active. Each second, we decrement a counter on the
 489  490   * current, active I/O until either a new I/O takes the head, or the counter
 490  491   * reaches zero. If the counter reaches zero, then we go through, quiesce the
 491  492   * ring, and then clean things up.
 492  493   *
 493  494   * ------------------
 494  495   * Periodic Endpoints
 495  496   * ------------------
↓ open down ↓ 27 lines elided ↑ open up ↑
 523  524   *
 524  525   * The following images relate the core data structures. The primary structure
 525  526   * in the system is the xhci_t. This is the per-controller data structure that
 526  527   * exists for each instance of the driver. From there, each device in the system
 527  528   * is represented by an xhci_device_t and each endpoint is represented by an
 528  529   * xhci_endpoint_t. For each client that opens a given endpoint, there is an
 529  530   * xhci_pipe_t. For each I/O related ring, there is an xhci_ring_t in the
 530  531   * system.
 531  532   *
 532  533   *     +------------------------+
 533      - *     | Per-Controller         |
 534      - *     | Structure              |
 535      - *     | xhci_t                 |
 536      - *     |                        |
 537      - *     | uint_t              ---+--> Capability regs offset
 538      - *     | uint_t              ---+--> Operational regs offset
 539      - *     | uint_t              ---+--> Runtime regs offset
 540      - *     | uint_t              ---+--> Doorbell regs offset
      534 + *     | Per-Controller         |
      535 + *     | Structure              |
      536 + *     | xhci_t                 |
      537 + *     |                        |
      538 + *     | uint_t              ---+--> Capability regs offset
      539 + *     | uint_t              ---+--> Operational regs offset
      540 + *     | uint_t              ---+--> Runtime regs offset
      541 + *     | uint_t              ---+--> Doorbell regs offset
 541  542   *     | xhci_state_flags_t  ---+--> Device state flags
 542      - *     | xhci_quirks_t       ---+--> Device quirk flags
      543 + *     | xhci_quirks_t       ---+--> Device quirk flags
 543  544   *     | xhci_capability_t   ---+--> Controller capability structure
 544      - *     | xhci_dcbaa_t        ---+----------------------------------+
 545      - *     | xhci_scratchpad_t   ---+---------+                        |
 546      - *     | xhci_command_ing_t  ---+------+  |                        v
 547      - *     | xhci_event_ring_t   ---+----+ |  |              +---------------------+
 548      - *     | xhci_usba_t         ---+--+ | |  |              | Device Context      |
 549      - *     +------------------------+  | | |  |              | Base Address        |
 550      - *                                 | | |  |              | Array Structure     |
 551      - *                                 | | |  |              | xhci_dcbaa_t        |
 552      - * +-------------------------------+ | |  |              |                     |
 553      - * | +-------------------------------+ |  |  DCBAA KVA <-+--        uint64_t * |
 554      - * | |    +----------------------------+  | DMA Buffer <-+-- xhci_dma_buffer_t |
 555      - * | |    v                               |              +---------------------+
 556      - * | | +--------------------------+       +-----------------------+
 557      - * | | | Event Ring               |                               |
 558      - * | | | Management               |                               |
 559      - * | | | xhci_event_ring_t        |                               v
 560      - * | | |                          |   Event Ring        +----------------------+
 561      - * | | | xhci_event_segment_t * --|-> Segment VA        |   Scratchpad (Extra  |
 562      - * | | | xhci_dma_buffer_t      --|-> Segment DMA Buf.  |   Controller Memory) |
 563      - * | | | xhci_ring_t            --|--+                  |    xhci_scratchpad_t |
 564      - * | | +--------------------------+  |      Scratchpad  |                      |
 565      - * | |                               | Base Array KVA <-+-          uint64_t * |
 566      - * | +------------+                  | Array DMA Buf. <-+-   xhci_dma_buffer_t |
 567      - * |              v                  | Scratchpad DMA <-+- xhci_dma_buffer_t * |
 568      - * |   +---------------------------+ | Buffer per page  +----------------------+
 569      - * |   | Command Ring              | |
 570      - * |   | xhci_command_ring_t       | +------------------------------+
 571      - * |   |                           |                                |
 572      - * |   | xhci_ring_t             --+-> Command Ring --->------------+
 573      - * |   | list_t                  --+-> Command List                 v
 574      - * |   | timeout_id_t            --+-> Timeout State     +---------------------+
 575      - * |   | xhci_command_ring_state_t +-> State Flags       | I/O Ring            |
 576      - * |   +---------------------------+                     | xhci_ring_t         |
 577      - * |                                                     |                     |
 578      - * |                                     Ring DMA Buf. <-+-- xhci_dma_buffer_t |
 579      - * |                                       Ring Length <-+--            uint_t |
 580      - * |                                    Ring Entry KVA <-+--      xhci_trb_t * |
 581      - * |    +---------------------------+        Ring Head <-+--            uint_t |
 582      - * +--->| USBA State                |        Ring Tail <-+--            uint_t |
 583      - *      | xhci_usba_t               |       Ring Cycle <-+--            uint_t |
 584      - *      |                           |                    +---------------------+
 585      - *      | usba_hcdi_ops_t *        -+-> USBA Ops Vector                       ^
 586      - *      | usb_dev_dscr_t           -+-> USB Virtual Device Descriptor         |
 587      - *      | usb_ss_hub_descr_t       -+-> USB Virtual Hub Descriptor            |
 588      - *      | usba_pipe_handle_data_t * +-> Interrupt polling client              |
 589      - *      | usb_intr_req_t           -+-> Interrupt polling request             |
 590      - *      | uint32_t                --+-> Interrupt polling device mask         |
 591      - *      | list_t                  --+-> Pipe List (Active Users)              |
 592      - *      | list_t                  --+-------------------+                     |
 593      - *      +---------------------------+                   |                     ^
 594      - *                                                      |                     |
 595      - *                                                      v                     |
 596      - *     +-------------------------------+             +---------------+        |
 597      - *     | USB Device                    |------------>| USB Device    |--> ... |
 598      - *     | xhci_device_t                 |             | xhci_device_t |        |
 599      - *     |                               |             +---------------+        |
 600      - *     | usb_port_t                  --+-> USB Port plugged into              |
 601      - *     | uint8_t                     --+-> Slot Number                        |
 602      - *     | boolean_t                   --+-> Address Assigned                   |
 603      - *     | usba_device_t *             --+-> USBA Device State                  |
 604      - *     | xhci_dma_buffer_t           --+-> Input Context DMA Buffer           |
 605      - *     | xhci_input_context_t *      --+-> Input Context KVA                  |
 606      - *     | xhci_slot_contex_t *        --+-> Input Slot Context KVA             |
 607      - *     | xhci_endpoint_context_t *[] --+-> Input Endpoint Context KVA         |
 608      - *     | xhci_dma_buffer_t           --+-> Output Context DMA Buffer          |
 609      - *     | xhci_slot_context_t *       --+-> Output Slot Context KVA            ^
 610      - *     | xhci_endpoint_context_t *[] --+-> Output Endpoint Context KVA        |
 611      - *     | xhci_endpoint_t *[]         --+-> Endpoint Tracking ---+             |
 612      - *     +-------------------------------+                        |             |
 613      - *                                                              |             |
 614      - *                                                              v             |
 615      - *     +------------------------------+            +-----------------+        |
 616      - *     | Endpoint Data                |----------->| Endpoint Data   |--> ... |
 617      - *     | xhci_endpoint_t              |            | xhci_endpoint_t |        |
 618      - *     |                              |            +-----------------+        |
 619      - *     | int                        --+-> Endpoint Number                     |
 620      - *     | int                        --+-> Endpoint Type                       |
 621      - *     | xhci_endpoint_state_t      --+-> Endpoint State                      |
 622      - *     | timeout_id_t               --+-> Endpoint Timeout State              |
 623      - *     | usba_pipe_handle_data_t *  --+-> USBA Client Handle                  |
 624      - *     | xhci_ring_t                --+-> Endpoint I/O Ring  -------->--------+
 625      - *     | list_t                     --+-> Transfer List --------+
 626      - *     +------------------------------+                         |
 627      - *                                                              v
 628      - *     +-------------------------+                  +--------------------+
 629      - *     | Transfer Structure      |----------------->| Transfer Structure |-> ...
 630      - *     | xhci_transfer_t         |                  | xhci_transfer_t    |
 631      - *     |                         |                  +--------------------+
      545 + *     | xhci_dcbaa_t        ---+----------------------------------+
      546 + *     | xhci_scratchpad_t   ---+---------+                        |
      547 + *     | xhci_command_ing_t  ---+------+  |                        v
      548 + *     | xhci_event_ring_t   ---+----+ |  |              +---------------------+
      549 + *     | xhci_usba_t         ---+--+ | |  |              | Device Context      |
      550 + *     +------------------------+  | | |  |              | Base Address        |
      551 + *                                 | | |  |              | Array Structure     |
      552 + *                                 | | |  |              | xhci_dcbaa_t        |
      553 + * +-------------------------------+ | |  |              |                     |
      554 + * | +-------------------------------+ |  |  DCBAA KVA <-+--        uint64_t * |
      555 + * | |    +----------------------------+  | DMA Buffer <-+-- xhci_dma_buffer_t |
      556 + * | |    v                               |              +---------------------+
      557 + * | | +--------------------------+       +-----------------------+
      558 + * | | | Event Ring               |                               |
      559 + * | | | Management               |                               |
      560 + * | | | xhci_event_ring_t        |                               v
      561 + * | | |                          |   Event Ring        +----------------------+
      562 + * | | | xhci_event_segment_t * --|-> Segment VA        |   Scratchpad (Extra  |
      563 + * | | | xhci_dma_buffer_t      --|-> Segment DMA Buf.  |   Controller Memory) |
      564 + * | | | xhci_ring_t            --|--+                  |    xhci_scratchpad_t |
      565 + * | | +--------------------------+  |      Scratchpad  |                      |
      566 + * | |                               | Base Array KVA <-+-          uint64_t * |
      567 + * | +------------+                  | Array DMA Buf. <-+-   xhci_dma_buffer_t |
      568 + * |              v                  | Scratchpad DMA <-+- xhci_dma_buffer_t * |
      569 + * |   +---------------------------+ | Buffer per page  +----------------------+
      570 + * |   | Command Ring              | |
      571 + * |   | xhci_command_ring_t       | +------------------------------+
      572 + * |   |                           |                                |
      573 + * |   | xhci_ring_t             --+-> Command Ring --->------------+
      574 + * |   | list_t                  --+-> Command List                 v
      575 + * |   | timeout_id_t            --+-> Timeout State     +---------------------+
      576 + * |   | xhci_command_ring_state_t +-> State Flags       | I/O Ring            |
      577 + * |   +---------------------------+                     | xhci_ring_t         |
      578 + * |                                                     |                     |
      579 + * |                                     Ring DMA Buf. <-+-- xhci_dma_buffer_t |
      580 + * |                                       Ring Length <-+--            uint_t |
      581 + * |                                    Ring Entry KVA <-+--      xhci_trb_t * |
      582 + * |    +---------------------------+        Ring Head <-+--            uint_t |
      583 + * +--->| USBA State                |        Ring Tail <-+--            uint_t |
      584 + *      | xhci_usba_t               |       Ring Cycle <-+--            uint_t |
      585 + *      |                           |                    +---------------------+
      586 + *      | usba_hcdi_ops_t *        -+-> USBA Ops Vector                       ^
      587 + *      | usb_dev_dscr_t           -+-> USB Virtual Device Descriptor         |
      588 + *      | usb_ss_hub_descr_t       -+-> USB Virtual Hub Descriptor            |
      589 + *      | usba_pipe_handle_data_t * +-> Interrupt polling client              |
      590 + *      | usb_intr_req_t           -+-> Interrupt polling request             |
      591 + *      | uint32_t                --+-> Interrupt polling device mask         |
      592 + *      | list_t                  --+-> Pipe List (Active Users)              |
      593 + *      | list_t                  --+-------------------+                     |
      594 + *      +---------------------------+                   |                     ^
      595 + *                                                      |                     |
      596 + *                                                      v                     |
      597 + *     +-------------------------------+             +---------------+        |
      598 + *     | USB Device                    |------------>| USB Device    |--> ... |
      599 + *     | xhci_device_t                 |             | xhci_device_t |        |
      600 + *     |                               |             +---------------+        |
      601 + *     | usb_port_t                  --+-> USB Port plugged into              |
      602 + *     | uint8_t                     --+-> Slot Number                        |
      603 + *     | boolean_t                   --+-> Address Assigned                   |
      604 + *     | usba_device_t *             --+-> USBA Device State                  |
      605 + *     | xhci_dma_buffer_t           --+-> Input Context DMA Buffer           |
      606 + *     | xhci_input_context_t *      --+-> Input Context KVA                  |
      607 + *     | xhci_slot_contex_t *        --+-> Input Slot Context KVA             |
      608 + *     | xhci_endpoint_context_t *[] --+-> Input Endpoint Context KVA         |
      609 + *     | xhci_dma_buffer_t           --+-> Output Context DMA Buffer          |
      610 + *     | xhci_slot_context_t *       --+-> Output Slot Context KVA            ^
      611 + *     | xhci_endpoint_context_t *[] --+-> Output Endpoint Context KVA        |
      612 + *     | xhci_endpoint_t *[]         --+-> Endpoint Tracking ---+             |
      613 + *     +-------------------------------+                        |             |
      614 + *                                                              |             |
      615 + *                                                              v             |
      616 + *     +------------------------------+            +-----------------+        |
      617 + *     | Endpoint Data                |----------->| Endpoint Data   |--> ... |
      618 + *     | xhci_endpoint_t              |            | xhci_endpoint_t |        |
      619 + *     |                              |            +-----------------+        |
      620 + *     | int                        --+-> Endpoint Number                     |
      621 + *     | int                        --+-> Endpoint Type                       |
      622 + *     | xhci_endpoint_state_t      --+-> Endpoint State                      |
      623 + *     | timeout_id_t               --+-> Endpoint Timeout State              |
      624 + *     | usba_pipe_handle_data_t *  --+-> USBA Client Handle                  |
      625 + *     | xhci_ring_t                --+-> Endpoint I/O Ring  -------->--------+
      626 + *     | list_t                     --+-> Transfer List --------+
      627 + *     +------------------------------+                         |
      628 + *                                                              v
      629 + *     +-------------------------+                  +--------------------+
      630 + *     | Transfer Structure      |----------------->| Transfer Structure |-> ...
      631 + *     | xhci_transfer_t         |                  | xhci_transfer_t    |
      632 + *     |                         |                  +--------------------+
 632  633   *     | xhci_dma_buffer_t     --+-> I/O DMA Buffer
 633      - *     | uint_t                --+-> Number of TRBs
 634      - *     | uint_t                --+-> Short transfer data
 635      - *     | uint_t                --+-> Timeout seconds remaining
 636      - *     | usb_cr_t              --+-> USB Transfer return value
 637      - *     | boolean_t             --+-> Data direction
 638      - *     | xhci_trb_t *          --+-> Host-order transfer requests for I/O
      634 + *     | uint_t                --+-> Number of TRBs
      635 + *     | uint_t                --+-> Short transfer data
      636 + *     | uint_t                --+-> Timeout seconds remaining
      637 + *     | usb_cr_t              --+-> USB Transfer return value
      638 + *     | boolean_t             --+-> Data direction
      639 + *     | xhci_trb_t *          --+-> Host-order transfer requests for I/O
 639  640   *     | usb_isoc_pkt_descr_t * -+-> Isochronous only response data
 640      - *     | usb_opaque_t          --+-> USBA Request Handle
      641 + *     | usb_opaque_t          --+-> USBA Request Handle
 641  642   *     +-------------------------+
 642  643   *
 643  644   * -------------
 644  645   * Lock Ordering
 645  646   * -------------
 646  647   *
 647  648   * There are three different tiers of locks that exist in the driver. First,
 648  649   * there is a lock for each controller: xhci_t`xhci_lock. This protects all the
 649  650   * data for that instance of the controller. If there are multiple instances of
 650  651   * the xHCI controller in the system, each one is independent and protected
↓ open down ↓ 355 lines elided ↑ open up ↑
1006 1007  
1007 1008          ddi_put64(xhcip->xhci_regs_handle, (void *)addr, val);
1008 1009  }
1009 1010  
1010 1011  int
1011 1012  xhci_check_regs_acc(xhci_t *xhcip)
1012 1013  {
1013 1014          ddi_fm_error_t de;
1014 1015  
1015 1016          /*
1016      -         * Treat the case where we can't check as fine so we can treat the code
     1017 +         * Treat cases where we can't check as fine so we can treat the code
1017 1018           * more simply.
1018 1019           */
1019      -        if (!DDI_FM_ACC_ERR_CAP(xhcip->xhci_fm_caps))
     1020 +        if (quiesce_active || !DDI_FM_ACC_ERR_CAP(xhcip->xhci_fm_caps))
1020 1021                  return (DDI_FM_OK);
1021 1022  
1022 1023          ddi_fm_acc_err_get(xhcip->xhci_regs_handle, &de, DDI_FME_VERSION);
1023 1024          ddi_fm_acc_err_clear(xhcip->xhci_regs_handle, DDI_FME_VERSION);
1024 1025          return (de.fme_status);
1025 1026  }
1026 1027  
1027 1028  /*
1028 1029   * As a leaf PCIe driver, we just post the ereport and continue on.
1029 1030   */
↓ open down ↓ 934 lines elided ↑ open up ↑
1964 1965                  xhcip->xhci_fm_caps = 0;
1965 1966          }
1966 1967  
1967 1968          inst = ddi_get_instance(xhcip->xhci_dip);
1968 1969          xhcip->xhci_dip = NULL;
1969 1970          ddi_soft_state_free(xhci_soft_state, inst);
1970 1971  
1971 1972          return (DDI_SUCCESS);
1972 1973  }
1973 1974  
     1975 +/* QUIESCE(9E) to support fast reboot */
     1976 +int
     1977 +xhci_quiesce(dev_info_t *dip)
     1978 +{
     1979 +        xhci_t *xhcip;
     1980 +
     1981 +        xhcip = ddi_get_soft_state(xhci_soft_state, ddi_get_instance(dip));
     1982 +
     1983 +        return (xhci_controller_stop(xhcip) == 0 &&
     1984 +            xhci_controller_reset(xhcip) == 0 ? DDI_SUCCESS : DDI_FAILURE);
     1985 +}
     1986 +
1974 1987  static int
1975 1988  xhci_attach(dev_info_t *dip, ddi_attach_cmd_t cmd)
1976 1989  {
1977 1990          int ret, inst, route;
1978 1991          xhci_t *xhcip;
1979 1992  
1980 1993          if (cmd != DDI_ATTACH)
1981 1994                  return (DDI_FAILURE);
1982 1995  
1983 1996          inst = ddi_get_instance(dip);
↓ open down ↓ 192 lines elided ↑ open up ↑
2176 2189          0,                              /* devo_refcnt */
2177 2190          xhci_getinfo,                   /* devo_getinfo */
2178 2191          nulldev,                        /* devo_identify */
2179 2192          nulldev,                        /* devo_probe */
2180 2193          xhci_attach,                    /* devo_attach */
2181 2194          xhci_detach,                    /* devo_detach */
2182 2195          nodev,                          /* devo_reset */
2183 2196          &xhci_cb_ops,                   /* devo_cb_ops */
2184 2197          &usba_hubdi_busops,             /* devo_bus_ops */
2185 2198          usba_hubdi_root_hub_power,      /* devo_power */
2186      -        ddi_quiesce_not_supported       /* devo_quiesce */
     2199 +        xhci_quiesce                    /* devo_quiesce */
2187 2200  };
2188 2201  
2189 2202  static struct modldrv xhci_modldrv = {
2190 2203          &mod_driverops,
2191 2204          "USB xHCI Driver",
2192 2205          &xhci_dev_ops
2193 2206  };
2194 2207  
2195 2208  static struct modlinkage xhci_modlinkage = {
2196 2209          MODREV_1,
↓ open down ↓ 51 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX