Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at v3.2-rc7 207 lines 4.3 kB view raw
1/* 2 * scsi_pm.c Copyright (C) 2010 Alan Stern 3 * 4 * SCSI dynamic Power Management 5 * Initial version: Alan Stern <stern@rowland.harvard.edu> 6 */ 7 8#include <linux/pm_runtime.h> 9#include <linux/export.h> 10 11#include <scsi/scsi.h> 12#include <scsi/scsi_device.h> 13#include <scsi/scsi_driver.h> 14#include <scsi/scsi_host.h> 15 16#include "scsi_priv.h" 17 18static int scsi_dev_type_suspend(struct device *dev, pm_message_t msg) 19{ 20 struct device_driver *drv; 21 int err; 22 23 err = scsi_device_quiesce(to_scsi_device(dev)); 24 if (err == 0) { 25 drv = dev->driver; 26 if (drv && drv->suspend) 27 err = drv->suspend(dev, msg); 28 } 29 dev_dbg(dev, "scsi suspend: %d\n", err); 30 return err; 31} 32 33static int scsi_dev_type_resume(struct device *dev) 34{ 35 struct device_driver *drv; 36 int err = 0; 37 38 drv = dev->driver; 39 if (drv && drv->resume) 40 err = drv->resume(dev); 41 scsi_device_resume(to_scsi_device(dev)); 42 dev_dbg(dev, "scsi resume: %d\n", err); 43 return err; 44} 45 46#ifdef CONFIG_PM_SLEEP 47 48static int scsi_bus_suspend_common(struct device *dev, pm_message_t msg) 49{ 50 int err = 0; 51 52 if (scsi_is_sdev_device(dev)) 53 err = scsi_dev_type_suspend(dev, msg); 54 return err; 55} 56 57static int scsi_bus_resume_common(struct device *dev) 58{ 59 int err = 0; 60 61 if (scsi_is_sdev_device(dev)) 62 err = scsi_dev_type_resume(dev); 63 64 if (err == 0) { 65 pm_runtime_disable(dev); 66 pm_runtime_set_active(dev); 67 pm_runtime_enable(dev); 68 } 69 return err; 70} 71 72static int scsi_bus_suspend(struct device *dev) 73{ 74 return scsi_bus_suspend_common(dev, PMSG_SUSPEND); 75} 76 77static int scsi_bus_freeze(struct device *dev) 78{ 79 return scsi_bus_suspend_common(dev, PMSG_FREEZE); 80} 81 82static int scsi_bus_poweroff(struct device *dev) 83{ 84 return scsi_bus_suspend_common(dev, PMSG_HIBERNATE); 85} 86 87#else /* CONFIG_PM_SLEEP */ 88 89#define scsi_bus_resume_common NULL 90#define scsi_bus_suspend NULL 91#define scsi_bus_freeze NULL 92#define scsi_bus_poweroff NULL 93 94#endif /* CONFIG_PM_SLEEP */ 95 96#ifdef CONFIG_PM_RUNTIME 97 98static int scsi_runtime_suspend(struct device *dev) 99{ 100 int err = 0; 101 102 dev_dbg(dev, "scsi_runtime_suspend\n"); 103 if (scsi_is_sdev_device(dev)) { 104 err = scsi_dev_type_suspend(dev, PMSG_AUTO_SUSPEND); 105 if (err == -EAGAIN) 106 pm_schedule_suspend(dev, jiffies_to_msecs( 107 round_jiffies_up_relative(HZ/10))); 108 } 109 110 /* Insert hooks here for targets, hosts, and transport classes */ 111 112 return err; 113} 114 115static int scsi_runtime_resume(struct device *dev) 116{ 117 int err = 0; 118 119 dev_dbg(dev, "scsi_runtime_resume\n"); 120 if (scsi_is_sdev_device(dev)) 121 err = scsi_dev_type_resume(dev); 122 123 /* Insert hooks here for targets, hosts, and transport classes */ 124 125 return err; 126} 127 128static int scsi_runtime_idle(struct device *dev) 129{ 130 int err; 131 132 dev_dbg(dev, "scsi_runtime_idle\n"); 133 134 /* Insert hooks here for targets, hosts, and transport classes */ 135 136 if (scsi_is_sdev_device(dev)) 137 err = pm_schedule_suspend(dev, 100); 138 else 139 err = pm_runtime_suspend(dev); 140 return err; 141} 142 143int scsi_autopm_get_device(struct scsi_device *sdev) 144{ 145 int err; 146 147 err = pm_runtime_get_sync(&sdev->sdev_gendev); 148 if (err < 0 && err !=-EACCES) 149 pm_runtime_put_sync(&sdev->sdev_gendev); 150 else 151 err = 0; 152 return err; 153} 154EXPORT_SYMBOL_GPL(scsi_autopm_get_device); 155 156void scsi_autopm_put_device(struct scsi_device *sdev) 157{ 158 pm_runtime_put_sync(&sdev->sdev_gendev); 159} 160EXPORT_SYMBOL_GPL(scsi_autopm_put_device); 161 162void scsi_autopm_get_target(struct scsi_target *starget) 163{ 164 pm_runtime_get_sync(&starget->dev); 165} 166 167void scsi_autopm_put_target(struct scsi_target *starget) 168{ 169 pm_runtime_put_sync(&starget->dev); 170} 171 172int scsi_autopm_get_host(struct Scsi_Host *shost) 173{ 174 int err; 175 176 err = pm_runtime_get_sync(&shost->shost_gendev); 177 if (err < 0 && err !=-EACCES) 178 pm_runtime_put_sync(&shost->shost_gendev); 179 else 180 err = 0; 181 return err; 182} 183 184void scsi_autopm_put_host(struct Scsi_Host *shost) 185{ 186 pm_runtime_put_sync(&shost->shost_gendev); 187} 188 189#else 190 191#define scsi_runtime_suspend NULL 192#define scsi_runtime_resume NULL 193#define scsi_runtime_idle NULL 194 195#endif /* CONFIG_PM_RUNTIME */ 196 197const struct dev_pm_ops scsi_bus_pm_ops = { 198 .suspend = scsi_bus_suspend, 199 .resume = scsi_bus_resume_common, 200 .freeze = scsi_bus_freeze, 201 .thaw = scsi_bus_resume_common, 202 .poweroff = scsi_bus_poweroff, 203 .restore = scsi_bus_resume_common, 204 .runtime_suspend = scsi_runtime_suspend, 205 .runtime_resume = scsi_runtime_resume, 206 .runtime_idle = scsi_runtime_idle, 207};