Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Andreas Herrmann | 4a9d2d8 | 2006-05-22 18:14:08 +0200 | [diff] [blame] | 2 | * This file is part of the zfcp device driver for |
| 3 | * FCP adapters for IBM System z9 and zSeries. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Andreas Herrmann | 4a9d2d8 | 2006-05-22 18:14:08 +0200 | [diff] [blame] | 5 | * (C) Copyright IBM Corp. 2002, 2006 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2, or (at your option) |
| 10 | * any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #include "zfcp_ext.h" |
| 23 | |
| 24 | #define ZFCP_LOG_AREA ZFCP_LOG_AREA_CONFIG |
| 25 | |
| 26 | /** |
| 27 | * zfcp_sysfs_unit_release - gets called when a struct device unit is released |
| 28 | * @dev: pointer to belonging device |
| 29 | */ |
| 30 | void |
| 31 | zfcp_sysfs_unit_release(struct device *dev) |
| 32 | { |
| 33 | kfree(dev); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * ZFCP_DEFINE_UNIT_ATTR |
| 38 | * @_name: name of show attribute |
| 39 | * @_format: format string |
| 40 | * @_value: value to print |
| 41 | * |
| 42 | * Generates attribute for a unit. |
| 43 | */ |
| 44 | #define ZFCP_DEFINE_UNIT_ATTR(_name, _format, _value) \ |
Yani Ioannou | 10523b3 | 2005-05-17 06:43:37 -0400 | [diff] [blame] | 45 | static ssize_t zfcp_sysfs_unit_##_name##_show(struct device *dev, struct device_attribute *attr, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | char *buf) \ |
| 47 | { \ |
| 48 | struct zfcp_unit *unit; \ |
| 49 | \ |
| 50 | unit = dev_get_drvdata(dev); \ |
| 51 | return sprintf(buf, _format, _value); \ |
| 52 | } \ |
| 53 | \ |
| 54 | static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_unit_##_name##_show, NULL); |
| 55 | |
| 56 | ZFCP_DEFINE_UNIT_ATTR(status, "0x%08x\n", atomic_read(&unit->status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | ZFCP_DEFINE_UNIT_ATTR(in_recovery, "%d\n", atomic_test_mask |
| 58 | (ZFCP_STATUS_COMMON_ERP_INUSE, &unit->status)); |
| 59 | ZFCP_DEFINE_UNIT_ATTR(access_denied, "%d\n", atomic_test_mask |
| 60 | (ZFCP_STATUS_COMMON_ACCESS_DENIED, &unit->status)); |
| 61 | ZFCP_DEFINE_UNIT_ATTR(access_shared, "%d\n", atomic_test_mask |
| 62 | (ZFCP_STATUS_UNIT_SHARED, &unit->status)); |
| 63 | ZFCP_DEFINE_UNIT_ATTR(access_readonly, "%d\n", atomic_test_mask |
| 64 | (ZFCP_STATUS_UNIT_READONLY, &unit->status)); |
| 65 | |
| 66 | /** |
| 67 | * zfcp_sysfs_unit_failed_store - failed state of unit |
| 68 | * @dev: pointer to belonging device |
| 69 | * @buf: pointer to input buffer |
| 70 | * @count: number of bytes in buffer |
| 71 | * |
| 72 | * Store function of the "failed" attribute of a unit. |
| 73 | * If a "0" gets written to "failed", error recovery will be |
| 74 | * started for the belonging unit. |
| 75 | */ |
| 76 | static ssize_t |
Yani Ioannou | 10523b3 | 2005-05-17 06:43:37 -0400 | [diff] [blame] | 77 | zfcp_sysfs_unit_failed_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
| 79 | struct zfcp_unit *unit; |
| 80 | unsigned int val; |
| 81 | char *endp; |
| 82 | int retval = 0; |
| 83 | |
| 84 | down(&zfcp_data.config_sema); |
| 85 | unit = dev_get_drvdata(dev); |
| 86 | if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status)) { |
| 87 | retval = -EBUSY; |
| 88 | goto out; |
| 89 | } |
| 90 | |
| 91 | val = simple_strtoul(buf, &endp, 0); |
| 92 | if (((endp + 1) < (buf + count)) || (val != 0)) { |
| 93 | retval = -EINVAL; |
| 94 | goto out; |
| 95 | } |
| 96 | |
| 97 | zfcp_erp_modify_unit_status(unit, ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET); |
| 98 | zfcp_erp_unit_reopen(unit, ZFCP_STATUS_COMMON_ERP_FAILED); |
| 99 | zfcp_erp_wait(unit->port->adapter); |
| 100 | out: |
| 101 | up(&zfcp_data.config_sema); |
| 102 | return retval ? retval : (ssize_t) count; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * zfcp_sysfs_unit_failed_show - failed state of unit |
| 107 | * @dev: pointer to belonging device |
| 108 | * @buf: pointer to input buffer |
| 109 | * |
| 110 | * Show function of "failed" attribute of unit. Will be |
| 111 | * "0" if unit is working, otherwise "1". |
| 112 | */ |
| 113 | static ssize_t |
Yani Ioannou | 10523b3 | 2005-05-17 06:43:37 -0400 | [diff] [blame] | 114 | zfcp_sysfs_unit_failed_show(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | { |
| 116 | struct zfcp_unit *unit; |
| 117 | |
| 118 | unit = dev_get_drvdata(dev); |
| 119 | if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &unit->status)) |
| 120 | return sprintf(buf, "1\n"); |
| 121 | else |
| 122 | return sprintf(buf, "0\n"); |
| 123 | } |
| 124 | |
| 125 | static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_unit_failed_show, |
| 126 | zfcp_sysfs_unit_failed_store); |
| 127 | |
| 128 | static struct attribute *zfcp_unit_attrs[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | &dev_attr_failed.attr, |
| 130 | &dev_attr_in_recovery.attr, |
| 131 | &dev_attr_status.attr, |
| 132 | &dev_attr_access_denied.attr, |
| 133 | &dev_attr_access_shared.attr, |
| 134 | &dev_attr_access_readonly.attr, |
| 135 | NULL |
| 136 | }; |
| 137 | |
| 138 | static struct attribute_group zfcp_unit_attr_group = { |
| 139 | .attrs = zfcp_unit_attrs, |
| 140 | }; |
| 141 | |
| 142 | /** |
| 143 | * zfcp_sysfs_create_unit_files - create sysfs unit files |
| 144 | * @dev: pointer to belonging device |
| 145 | * |
| 146 | * Create all attributes of the sysfs representation of a unit. |
| 147 | */ |
| 148 | int |
| 149 | zfcp_sysfs_unit_create_files(struct device *dev) |
| 150 | { |
| 151 | return sysfs_create_group(&dev->kobj, &zfcp_unit_attr_group); |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * zfcp_sysfs_remove_unit_files - remove sysfs unit files |
| 156 | * @dev: pointer to belonging device |
| 157 | * |
| 158 | * Remove all attributes of the sysfs representation of a unit. |
| 159 | */ |
| 160 | void |
| 161 | zfcp_sysfs_unit_remove_files(struct device *dev) |
| 162 | { |
| 163 | sysfs_remove_group(&dev->kobj, &zfcp_unit_attr_group); |
| 164 | } |
| 165 | |
| 166 | #undef ZFCP_LOG_AREA |