diff options
author | Song Liu <songliubraving@fb.com> | 2014-12-30 17:46:18 -0500 |
---|---|---|
committer | Christoph Hellwig <hch@lst.de> | 2015-01-09 09:44:19 -0500 |
commit | 08024885a2a3ed432716e9d50046a620a5b2df05 (patch) | |
tree | 52e0042dac2c8651641987da49163908c3305e74 /drivers/misc/enclosure.c | |
parent | 921ce7f5786052749a22a75780f5ce1a456bcdc6 (diff) |
ses: Add power_status to SES device slot
Add power_status to SES device slot, so we can power on/off the
HDDs behind the enclosure.
Check firmware status in ses_set_* before sending control pages to
firmware.
Signed-off-by: Song Liu <songliubraving@fb.com>
Acked-by: Dan Williams <dan.j.williams@intel.com>
Reviewed-by: Jens Axboe <axboe@fb.com>
Cc: Hannes Reinecke <hare@suse.de>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Diffstat (limited to 'drivers/misc/enclosure.c')
-rw-r--r-- | drivers/misc/enclosure.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/drivers/misc/enclosure.c b/drivers/misc/enclosure.c index b62314d627ae..38552a31304a 100644 --- a/drivers/misc/enclosure.c +++ b/drivers/misc/enclosure.c | |||
@@ -148,6 +148,7 @@ enclosure_register(struct device *dev, const char *name, int components, | |||
148 | for (i = 0; i < components; i++) { | 148 | for (i = 0; i < components; i++) { |
149 | edev->component[i].number = -1; | 149 | edev->component[i].number = -1; |
150 | edev->component[i].slot = -1; | 150 | edev->component[i].slot = -1; |
151 | edev->component[i].power_status = 1; | ||
151 | } | 152 | } |
152 | 153 | ||
153 | mutex_lock(&container_list_lock); | 154 | mutex_lock(&container_list_lock); |
@@ -583,6 +584,40 @@ static ssize_t set_component_locate(struct device *cdev, | |||
583 | return count; | 584 | return count; |
584 | } | 585 | } |
585 | 586 | ||
587 | static ssize_t get_component_power_status(struct device *cdev, | ||
588 | struct device_attribute *attr, | ||
589 | char *buf) | ||
590 | { | ||
591 | struct enclosure_device *edev = to_enclosure_device(cdev->parent); | ||
592 | struct enclosure_component *ecomp = to_enclosure_component(cdev); | ||
593 | |||
594 | if (edev->cb->get_power_status) | ||
595 | edev->cb->get_power_status(edev, ecomp); | ||
596 | return snprintf(buf, 40, "%s\n", ecomp->power_status ? "on" : "off"); | ||
597 | } | ||
598 | |||
599 | static ssize_t set_component_power_status(struct device *cdev, | ||
600 | struct device_attribute *attr, | ||
601 | const char *buf, size_t count) | ||
602 | { | ||
603 | struct enclosure_device *edev = to_enclosure_device(cdev->parent); | ||
604 | struct enclosure_component *ecomp = to_enclosure_component(cdev); | ||
605 | int val; | ||
606 | |||
607 | if (strncmp(buf, "on", 2) == 0 && | ||
608 | (buf[2] == '\n' || buf[2] == '\0')) | ||
609 | val = 1; | ||
610 | else if (strncmp(buf, "off", 3) == 0 && | ||
611 | (buf[3] == '\n' || buf[3] == '\0')) | ||
612 | val = 0; | ||
613 | else | ||
614 | return -EINVAL; | ||
615 | |||
616 | if (edev->cb->set_power_status) | ||
617 | edev->cb->set_power_status(edev, ecomp, val); | ||
618 | return count; | ||
619 | } | ||
620 | |||
586 | static ssize_t get_component_type(struct device *cdev, | 621 | static ssize_t get_component_type(struct device *cdev, |
587 | struct device_attribute *attr, char *buf) | 622 | struct device_attribute *attr, char *buf) |
588 | { | 623 | { |
@@ -614,6 +649,8 @@ static DEVICE_ATTR(active, S_IRUGO | S_IWUSR, get_component_active, | |||
614 | set_component_active); | 649 | set_component_active); |
615 | static DEVICE_ATTR(locate, S_IRUGO | S_IWUSR, get_component_locate, | 650 | static DEVICE_ATTR(locate, S_IRUGO | S_IWUSR, get_component_locate, |
616 | set_component_locate); | 651 | set_component_locate); |
652 | static DEVICE_ATTR(power_status, S_IRUGO | S_IWUSR, get_component_power_status, | ||
653 | set_component_power_status); | ||
617 | static DEVICE_ATTR(type, S_IRUGO, get_component_type, NULL); | 654 | static DEVICE_ATTR(type, S_IRUGO, get_component_type, NULL); |
618 | static DEVICE_ATTR(slot, S_IRUGO, get_component_slot, NULL); | 655 | static DEVICE_ATTR(slot, S_IRUGO, get_component_slot, NULL); |
619 | 656 | ||
@@ -622,6 +659,7 @@ static struct attribute *enclosure_component_attrs[] = { | |||
622 | &dev_attr_status.attr, | 659 | &dev_attr_status.attr, |
623 | &dev_attr_active.attr, | 660 | &dev_attr_active.attr, |
624 | &dev_attr_locate.attr, | 661 | &dev_attr_locate.attr, |
662 | &dev_attr_power_status.attr, | ||
625 | &dev_attr_type.attr, | 663 | &dev_attr_type.attr, |
626 | &dev_attr_slot.attr, | 664 | &dev_attr_slot.attr, |
627 | NULL | 665 | NULL |