Print this page
4782 usba shouldn't abuse ddi_get_time(9f)
Reviewed by: Robert Mustacchi <rm@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/io/usb/usba/hubdi.c
          +++ new/usr/src/uts/common/io/usb/usba/hubdi.c
↓ open down ↓ 13 lines elided ↑ open up ↑
  14   14   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15   15   * If applicable, add the following below this CDDL HEADER, with the
  16   16   * fields enclosed by brackets "[]" replaced with your own identifying
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  /*
  22   22   * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
  23   23   * Copyright 2012 Garrett D'Amore <garrett@damore.org>.  All rights reserved.
       24 + * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
  24   25   */
  25   26  
  26   27  /*
  27   28   * USBA: Solaris USB Architecture support for the hub
  28   29   * including root hub
  29   30   * Most of the code for hubd resides in this file and
  30   31   * is shared between the HCD root hub support and hubd
  31   32   */
  32   33  #define USBA_FRAMEWORK
  33   34  #include <sys/usb/usba.h>
↓ open down ↓ 708 lines elided ↑ open up ↑
 742  743  
 743  744          if (DEVI_IS_DETACHING(hubd->h_dip)) {
 744  745  
 745  746                  return (USB_SUCCESS);
 746  747          }
 747  748  
 748  749          /*
 749  750           * Don't go to lower power if haven't been at full power for enough
 750  751           * time to let hotplug thread kickoff.
 751  752           */
 752      -        if (ddi_get_time() < (hubpm->hubp_time_at_full_power +
      753 +        if (gethrtime() < (hubpm->hubp_time_at_full_power +
 753  754              hubpm->hubp_min_pm_threshold)) {
 754  755  
 755  756                  return (USB_FAILURE);
 756  757          }
 757  758  
 758  759          for (port = 1; (total_power == 0) &&
 759  760              (port <= hubd->h_hub_descr.bNbrPorts); port++) {
 760  761                  total_power += hubpm->hubp_child_pwrstate[port];
 761  762          }
 762  763  
↓ open down ↓ 950 lines elided ↑ open up ↑
1713 1714                          /* implement global resume here */
1714 1715                          USB_DPRINTF_L2(DPRINT_MASK_PM,
1715 1716                              hubd->h_log_handle,
1716 1717                              "Global Resume: Not Yet Implemented");
1717 1718                  }
1718 1719                  /* Issue USB D0 command to the device here */
1719 1720                  rval = usb_set_device_pwrlvl0(hubd->h_dip);
1720 1721                  ASSERT(rval == USB_SUCCESS);
1721 1722                  hubd->h_dev_state = USB_DEV_ONLINE;
1722 1723                  hubpm->hubp_current_power = USB_DEV_OS_FULL_PWR;
1723      -                hubpm->hubp_time_at_full_power = ddi_get_time();
     1724 +                hubpm->hubp_time_at_full_power = gethrtime();
1724 1725                  hubd_start_polling(hubd, 0);
1725 1726  
1726 1727                  /* FALLTHRU */
1727 1728          case USB_DEV_ONLINE:
1728 1729                  /* we are already in full power */
1729 1730  
1730 1731                  /* FALLTHRU */
1731 1732          case USB_DEV_DISCONNECTED:
1732 1733          case USB_DEV_SUSPENDED:
1733 1734                  /*
↓ open down ↓ 1971 lines elided ↑ open up ↑
3705 3706  
3706 3707          mutex_enter(HUBD_MUTEX(hubd));
3707 3708  
3708 3709          /* is this the root hub? */
3709 3710          if (hdip == rh_dip) {
3710 3711                  if (hubd->h_dev_state == USB_DEV_PWRED_DOWN) {
3711 3712                          hubpm = hubd->h_hubpm;
3712 3713  
3713 3714                          /* mark the root hub as full power */
3714 3715                          hubpm->hubp_current_power = USB_DEV_OS_FULL_PWR;
3715      -                        hubpm->hubp_time_at_full_power = ddi_get_time();
     3716 +                        hubpm->hubp_time_at_full_power = gethrtime();
3716 3717                          mutex_exit(HUBD_MUTEX(hubd));
3717 3718  
3718 3719                          USB_DPRINTF_L4(DPRINT_MASK_HOTPLUG, hubd->h_log_handle,
3719 3720                              "hubd_hotplug_thread: call pm_power_has_changed");
3720 3721  
3721 3722                          (void) pm_power_has_changed(hdip, 0,
3722 3723                              USB_DEV_OS_FULL_PWR);
3723 3724  
3724 3725                          mutex_enter(HUBD_MUTEX(hubd));
3725 3726                          hubd->h_dev_state = USB_DEV_ONLINE;
↓ open down ↓ 3540 lines elided ↑ open up ↑
7266 7267          USB_DPRINTF_L4(DPRINT_MASK_PM, hubd->h_log_handle,
7267 7268              "hubd_create_pm_components: Begin");
7268 7269  
7269 7270          /* Allocate the state structure */
7270 7271          hubpm = kmem_zalloc(sizeof (hub_power_t), KM_SLEEP);
7271 7272  
7272 7273          hubd->h_hubpm = hubpm;
7273 7274          hubpm->hubp_hubd = hubd;
7274 7275          hubpm->hubp_pm_capabilities = 0;
7275 7276          hubpm->hubp_current_power = USB_DEV_OS_FULL_PWR;
7276      -        hubpm->hubp_time_at_full_power = ddi_get_time();
7277      -        hubpm->hubp_min_pm_threshold = hubdi_min_pm_threshold;
     7277 +        hubpm->hubp_time_at_full_power = gethrtime();
     7278 +        hubpm->hubp_min_pm_threshold = hubdi_min_pm_threshold * NANOSEC;
7278 7279  
7279 7280          /* alloc memory to save power states of children */
7280 7281          hubpm->hubp_child_pwrstate = (uint8_t *)
7281 7282              kmem_zalloc(MAX_PORTS + 1, KM_SLEEP);
7282 7283  
7283 7284          /*
7284 7285           * if the enable remote wakeup fails
7285 7286           * we still want to enable
7286 7287           * parent notification so we can PM the children
7287 7288           */
↓ open down ↓ 1414 lines elided ↑ open up ↑
8702 8703  
8703 8704          hubd->h_hotplug_thread++;
8704 8705  
8705 8706          /* is this the root hub? */
8706 8707          if ((hdip == rh_dip) &&
8707 8708              (hubd->h_dev_state == USB_DEV_PWRED_DOWN)) {
8708 8709                  hubpm = hubd->h_hubpm;
8709 8710  
8710 8711                  /* mark the root hub as full power */
8711 8712                  hubpm->hubp_current_power = USB_DEV_OS_FULL_PWR;
8712      -                hubpm->hubp_time_at_full_power = ddi_get_time();
     8713 +                hubpm->hubp_time_at_full_power = gethrtime();
8713 8714                  mutex_exit(HUBD_MUTEX(hubd));
8714 8715  
8715 8716                  USB_DPRINTF_L3(DPRINT_MASK_HOTPLUG, hubd->h_log_handle,
8716 8717                      "hubd_reset_thread: call pm_power_has_changed");
8717 8718  
8718 8719                  (void) pm_power_has_changed(hdip, 0,
8719 8720                      USB_DEV_OS_FULL_PWR);
8720 8721  
8721 8722                  mutex_enter(HUBD_MUTEX(hubd));
8722 8723                  hubd->h_dev_state = USB_DEV_ONLINE;
↓ open down ↓ 387 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX