^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Enclosure Services
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2008 James Bottomley <James.Bottomley@HansenPartnership.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) **-----------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) **
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) **-----------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/enclosure.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) static LIST_HEAD(container_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) static DEFINE_MUTEX(container_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static struct class enclosure_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * enclosure_find - find an enclosure given a parent device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * @dev: the parent to match against
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * @start: Optional enclosure device to start from (NULL if none)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * Looks through the list of registered enclosures to find all those
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * with @dev as a parent. Returns NULL if no enclosure is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * found. @start can be used as a starting point to obtain multiple
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * enclosures per parent (should begin with NULL and then be set to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * each returned enclosure device). Obtains a reference to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * enclosure class device which must be released with device_put().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * If @start is not NULL, a reference must be taken on it which is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * released before returning (this allows a loop through all
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) * enclosures to exit with only the reference on the enclosure of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) * interest held). Note that the @dev may correspond to the actual
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) * device housing the enclosure, in which case no iteration via @start
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) * is required.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct enclosure_device *enclosure_find(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct enclosure_device *start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct enclosure_device *edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) mutex_lock(&container_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) edev = list_prepare_entry(start, &container_list, node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) put_device(&start->edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) list_for_each_entry_continue(edev, &container_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct device *parent = edev->edev.parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) /* parent might not be immediate, so iterate up to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) * the root of the tree if necessary */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) while (parent) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) if (parent == dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) get_device(&edev->edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) mutex_unlock(&container_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) return edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) parent = parent->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) mutex_unlock(&container_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) EXPORT_SYMBOL_GPL(enclosure_find);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) * enclosure_for_each_device - calls a function for each enclosure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) * @fn: the function to call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) * @data: the data to pass to each call
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * Loops over all the enclosures calling the function.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * Note, this function uses a mutex which will be held across calls to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * @fn, so it must have non atomic context, and @fn may (although it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * should not) sleep or otherwise cause the mutex to be held for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * indefinite periods
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int enclosure_for_each_device(int (*fn)(struct enclosure_device *, void *),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int error = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) struct enclosure_device *edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) mutex_lock(&container_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) list_for_each_entry(edev, &container_list, node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) error = fn(edev, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) mutex_unlock(&container_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) EXPORT_SYMBOL_GPL(enclosure_for_each_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * enclosure_register - register device as an enclosure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * @dev: device containing the enclosure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) * @name: chosen device name
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * @components: number of components in the enclosure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) * @cb: platform call-backs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * This sets up the device for being an enclosure. Note that @dev does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * not have to be a dedicated enclosure device. It may be some other type
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) * of device that additionally responds to enclosure services
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct enclosure_device *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) enclosure_register(struct device *dev, const char *name, int components,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct enclosure_component_callbacks *cb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) struct enclosure_device *edev =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) kzalloc(struct_size(edev, component, components), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int err, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) BUG_ON(!cb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (!edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) edev->components = components;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) edev->edev.class = &enclosure_class;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) edev->edev.parent = get_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) edev->cb = cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) dev_set_name(&edev->edev, "%s", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) err = device_register(&edev->edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) for (i = 0; i < components; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) edev->component[i].number = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) edev->component[i].slot = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) edev->component[i].power_status = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) mutex_lock(&container_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) list_add_tail(&edev->node, &container_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) mutex_unlock(&container_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return edev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) put_device(edev->edev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) kfree(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) return ERR_PTR(err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) EXPORT_SYMBOL_GPL(enclosure_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) static struct enclosure_component_callbacks enclosure_null_callbacks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * enclosure_unregister - remove an enclosure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * @edev: the registered enclosure to remove;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) void enclosure_unregister(struct enclosure_device *edev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) mutex_lock(&container_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) list_del(&edev->node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) mutex_unlock(&container_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) for (i = 0; i < edev->components; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (edev->component[i].number != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) device_unregister(&edev->component[i].cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /* prevent any callbacks into service user */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) edev->cb = &enclosure_null_callbacks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) device_unregister(&edev->edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) EXPORT_SYMBOL_GPL(enclosure_unregister);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) #define ENCLOSURE_NAME_SIZE 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) #define COMPONENT_NAME_SIZE 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static void enclosure_link_name(struct enclosure_component *cdev, char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) strcpy(name, "enclosure_device:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) strcat(name, dev_name(&cdev->cdev));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static void enclosure_remove_links(struct enclosure_component *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) char name[ENCLOSURE_NAME_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) enclosure_link_name(cdev, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) * In odd circumstances, like multipath devices, something else may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) * already have removed the links, so check for this condition first.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) if (cdev->dev->kobj.sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) sysfs_remove_link(&cdev->dev->kobj, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (cdev->cdev.kobj.sd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) sysfs_remove_link(&cdev->cdev.kobj, "device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static int enclosure_add_links(struct enclosure_component *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) char name[ENCLOSURE_NAME_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) error = sysfs_create_link(&cdev->cdev.kobj, &cdev->dev->kobj, "device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) enclosure_link_name(cdev, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) error = sysfs_create_link(&cdev->dev->kobj, &cdev->cdev.kobj, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) sysfs_remove_link(&cdev->cdev.kobj, "device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static void enclosure_release(struct device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) struct enclosure_device *edev = to_enclosure_device(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) put_device(cdev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) kfree(edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static void enclosure_component_release(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct enclosure_component *cdev = to_enclosure_component(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (cdev->dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) enclosure_remove_links(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) put_device(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) put_device(dev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) static struct enclosure_component *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) enclosure_component_find_by_name(struct enclosure_device *edev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) const char *cname;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct enclosure_component *ecomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (!edev || !name || !name[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) for (i = 0; i < edev->components; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) ecomp = &edev->component[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) cname = dev_name(&ecomp->cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (ecomp->number != -1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) cname && cname[0] &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) !strcmp(cname, name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) return ecomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static const struct attribute_group *enclosure_component_groups[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) * enclosure_component_alloc - prepare a new enclosure component
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) * @edev: the enclosure to add the component
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * @number: the device number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * @type: the type of component being added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) * @name: an optional name to appear in sysfs (leave NULL if none)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * The name is optional for enclosures that give their components a unique
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) * name. If not, leave the field NULL and a name will be assigned.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * Returns a pointer to the enclosure component or an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) struct enclosure_component *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) enclosure_component_alloc(struct enclosure_device *edev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) unsigned int number,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) enum enclosure_component_type type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) const char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) struct enclosure_component *ecomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) struct device *cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) char newname[COMPONENT_NAME_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) if (number >= edev->components)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) ecomp = &edev->component[number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if (ecomp->number != -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) ecomp->type = type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) ecomp->number = number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) cdev = &ecomp->cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) cdev->parent = get_device(&edev->edev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (name && name[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) /* Some hardware (e.g. enclosure in RX300 S6) has components
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * with non unique names. Registering duplicates in sysfs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * will lead to warnings during bootup. So make the names
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * unique by appending consecutive numbers -1, -2, ... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) i = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) snprintf(newname, COMPONENT_NAME_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) "%s", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) while (enclosure_component_find_by_name(edev, newname))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) snprintf(newname, COMPONENT_NAME_SIZE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) "%s-%i", name, i++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) dev_set_name(cdev, "%s", newname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) dev_set_name(cdev, "%u", number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) cdev->release = enclosure_component_release;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) cdev->groups = enclosure_component_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return ecomp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) EXPORT_SYMBOL_GPL(enclosure_component_alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) * enclosure_component_register - publishes an initialized enclosure component
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) * @ecomp: component to add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) * Returns 0 on successful registration, releases the component otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) int enclosure_component_register(struct enclosure_component *ecomp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) struct device *cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) cdev = &ecomp->cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) err = device_register(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) ecomp->number = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) put_device(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) EXPORT_SYMBOL_GPL(enclosure_component_register);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) * enclosure_add_device - add a device as being part of an enclosure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) * @edev: the enclosure device being added to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) * @component: the number of the component
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) * @dev: the device being added
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) * Declares a real device to reside in slot (or identifier) @num of an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * enclosure. This will cause the relevant sysfs links to appear.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * This function may also be used to change a device associated with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * an enclosure without having to call enclosure_remove_device() in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * between.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) * Returns zero on success or an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) int enclosure_add_device(struct enclosure_device *edev, int component,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) struct enclosure_component *cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) if (!edev || component >= edev->components)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) cdev = &edev->component[component];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (cdev->dev == dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return -EEXIST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) if (cdev->dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) enclosure_remove_links(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) put_device(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) cdev->dev = get_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) err = enclosure_add_links(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) put_device(cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) cdev->dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) EXPORT_SYMBOL_GPL(enclosure_add_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) * enclosure_remove_device - remove a device from an enclosure
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) * @edev: the enclosure device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) * @dev: device to remove/put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) * Returns zero on success or an error.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) int enclosure_remove_device(struct enclosure_device *edev, struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) struct enclosure_component *cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) if (!edev || !dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) for (i = 0; i < edev->components; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) cdev = &edev->component[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) if (cdev->dev == dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) enclosure_remove_links(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) put_device(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) cdev->dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) EXPORT_SYMBOL_GPL(enclosure_remove_device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) * sysfs pieces below
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) static ssize_t components_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) struct enclosure_device *edev = to_enclosure_device(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) return snprintf(buf, 40, "%d\n", edev->components);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) static DEVICE_ATTR_RO(components);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) static ssize_t id_show(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) struct enclosure_device *edev = to_enclosure_device(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) if (edev->cb->show_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) return edev->cb->show_id(edev, buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) static DEVICE_ATTR_RO(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) static struct attribute *enclosure_class_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) &dev_attr_components.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) &dev_attr_id.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) ATTRIBUTE_GROUPS(enclosure_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static struct class enclosure_class = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) .name = "enclosure",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) .dev_release = enclosure_release,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) .dev_groups = enclosure_class_groups,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) static const char *const enclosure_status[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) [ENCLOSURE_STATUS_UNSUPPORTED] = "unsupported",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) [ENCLOSURE_STATUS_OK] = "OK",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) [ENCLOSURE_STATUS_CRITICAL] = "critical",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) [ENCLOSURE_STATUS_NON_CRITICAL] = "non-critical",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) [ENCLOSURE_STATUS_UNRECOVERABLE] = "unrecoverable",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) [ENCLOSURE_STATUS_NOT_INSTALLED] = "not installed",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) [ENCLOSURE_STATUS_UNKNOWN] = "unknown",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) [ENCLOSURE_STATUS_UNAVAILABLE] = "unavailable",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) [ENCLOSURE_STATUS_MAX] = NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) static const char *const enclosure_type[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) [ENCLOSURE_COMPONENT_DEVICE] = "device",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) [ENCLOSURE_COMPONENT_ARRAY_DEVICE] = "array device",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) static ssize_t get_component_fault(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) struct enclosure_device *edev = to_enclosure_device(cdev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) struct enclosure_component *ecomp = to_enclosure_component(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) if (edev->cb->get_fault)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) edev->cb->get_fault(edev, ecomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) return snprintf(buf, 40, "%d\n", ecomp->fault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) static ssize_t set_component_fault(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) struct enclosure_device *edev = to_enclosure_device(cdev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) struct enclosure_component *ecomp = to_enclosure_component(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) int val = simple_strtoul(buf, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) if (edev->cb->set_fault)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) edev->cb->set_fault(edev, ecomp, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) static ssize_t get_component_status(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) struct device_attribute *attr,char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) struct enclosure_device *edev = to_enclosure_device(cdev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) struct enclosure_component *ecomp = to_enclosure_component(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) if (edev->cb->get_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) edev->cb->get_status(edev, ecomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) return snprintf(buf, 40, "%s\n", enclosure_status[ecomp->status]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) static ssize_t set_component_status(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) struct enclosure_device *edev = to_enclosure_device(cdev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) struct enclosure_component *ecomp = to_enclosure_component(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) for (i = 0; enclosure_status[i]; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) if (strncmp(buf, enclosure_status[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) strlen(enclosure_status[i])) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) (buf[strlen(enclosure_status[i])] == '\n' ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) buf[strlen(enclosure_status[i])] == '\0'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) if (enclosure_status[i] && edev->cb->set_status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) edev->cb->set_status(edev, ecomp, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) static ssize_t get_component_active(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) struct enclosure_device *edev = to_enclosure_device(cdev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) struct enclosure_component *ecomp = to_enclosure_component(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) if (edev->cb->get_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) edev->cb->get_active(edev, ecomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) return snprintf(buf, 40, "%d\n", ecomp->active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) static ssize_t set_component_active(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) struct enclosure_device *edev = to_enclosure_device(cdev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) struct enclosure_component *ecomp = to_enclosure_component(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) int val = simple_strtoul(buf, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) if (edev->cb->set_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) edev->cb->set_active(edev, ecomp, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) static ssize_t get_component_locate(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) struct enclosure_device *edev = to_enclosure_device(cdev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) struct enclosure_component *ecomp = to_enclosure_component(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) if (edev->cb->get_locate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) edev->cb->get_locate(edev, ecomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) return snprintf(buf, 40, "%d\n", ecomp->locate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) static ssize_t set_component_locate(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) struct enclosure_device *edev = to_enclosure_device(cdev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) struct enclosure_component *ecomp = to_enclosure_component(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) int val = simple_strtoul(buf, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) if (edev->cb->set_locate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) edev->cb->set_locate(edev, ecomp, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) static ssize_t get_component_power_status(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) struct enclosure_device *edev = to_enclosure_device(cdev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) struct enclosure_component *ecomp = to_enclosure_component(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) if (edev->cb->get_power_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) edev->cb->get_power_status(edev, ecomp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) /* If still uninitialized, the callback failed or does not exist. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) if (ecomp->power_status == -1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) return (edev->cb->get_power_status) ? -EIO : -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) return snprintf(buf, 40, "%s\n", ecomp->power_status ? "on" : "off");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) static ssize_t set_component_power_status(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) const char *buf, size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) struct enclosure_device *edev = to_enclosure_device(cdev->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) struct enclosure_component *ecomp = to_enclosure_component(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) if (strncmp(buf, "on", 2) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) (buf[2] == '\n' || buf[2] == '\0'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) val = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) else if (strncmp(buf, "off", 3) == 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) (buf[3] == '\n' || buf[3] == '\0'))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (edev->cb->set_power_status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) edev->cb->set_power_status(edev, ecomp, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) static ssize_t get_component_type(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) struct enclosure_component *ecomp = to_enclosure_component(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) return snprintf(buf, 40, "%s\n", enclosure_type[ecomp->type]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) static ssize_t get_component_slot(struct device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) struct enclosure_component *ecomp = to_enclosure_component(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) int slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) /* if the enclosure does not override then use 'number' as a stand-in */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) if (ecomp->slot >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) slot = ecomp->slot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) slot = ecomp->number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) return snprintf(buf, 40, "%d\n", slot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) static DEVICE_ATTR(fault, S_IRUGO | S_IWUSR, get_component_fault,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) set_component_fault);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) static DEVICE_ATTR(status, S_IRUGO | S_IWUSR, get_component_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) set_component_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) static DEVICE_ATTR(active, S_IRUGO | S_IWUSR, get_component_active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) set_component_active);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) static DEVICE_ATTR(locate, S_IRUGO | S_IWUSR, get_component_locate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) set_component_locate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) static DEVICE_ATTR(power_status, S_IRUGO | S_IWUSR, get_component_power_status,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) set_component_power_status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) static DEVICE_ATTR(type, S_IRUGO, get_component_type, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) static DEVICE_ATTR(slot, S_IRUGO, get_component_slot, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) static struct attribute *enclosure_component_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) &dev_attr_fault.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) &dev_attr_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) &dev_attr_active.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) &dev_attr_locate.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) &dev_attr_power_status.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) &dev_attr_type.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) &dev_attr_slot.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) ATTRIBUTE_GROUPS(enclosure_component);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) static int __init enclosure_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) return class_register(&enclosure_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) static void __exit enclosure_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) class_unregister(&enclosure_class);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) module_init(enclosure_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) module_exit(enclosure_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) MODULE_AUTHOR("James Bottomley");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) MODULE_DESCRIPTION("Enclosure Services");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) MODULE_LICENSE("GPL v2");