4 * sysfs attributes for zfcp port.
6 * Copyright IBM Corporation 2002, 2008
12 * zfcp_sysfs_port_release - gets called when a struct device port is released
13 * @dev: pointer to belonging device
16 zfcp_sysfs_port_release(struct device *dev)
22 * ZFCP_DEFINE_PORT_ATTR
23 * @_name: name of show attribute
24 * @_format: format string
25 * @_value: value to print
27 * Generates attributes for a port.
29 #define ZFCP_DEFINE_PORT_ATTR(_name, _format, _value) \
30 static ssize_t zfcp_sysfs_port_##_name##_show(struct device *dev, struct device_attribute *attr, \
33 struct zfcp_port *port; \
35 port = dev_get_drvdata(dev); \
36 return sprintf(buf, _format, _value); \
39 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_port_##_name##_show, NULL);
41 ZFCP_DEFINE_PORT_ATTR(status, "0x%08x\n", atomic_read(&port->status));
42 ZFCP_DEFINE_PORT_ATTR(in_recovery, "%d\n", atomic_test_mask
43 (ZFCP_STATUS_COMMON_ERP_INUSE, &port->status));
44 ZFCP_DEFINE_PORT_ATTR(access_denied, "%d\n", atomic_test_mask
45 (ZFCP_STATUS_COMMON_ACCESS_DENIED, &port->status));
48 * zfcp_sysfs_unit_add_store - add a unit to sysfs tree
49 * @dev: pointer to belonging device
50 * @buf: pointer to input buffer
51 * @count: number of bytes in buffer
53 * Store function of the "unit_add" attribute of a port.
56 zfcp_sysfs_unit_add_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
60 struct zfcp_port *port;
61 struct zfcp_unit *unit;
64 down(&zfcp_data.config_sema);
66 port = dev_get_drvdata(dev);
67 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
72 fcp_lun = simple_strtoull(buf, &endp, 0);
73 if ((endp + 1) < (buf + count))
76 unit = zfcp_unit_enqueue(port, fcp_lun);
82 zfcp_erp_unit_reopen(unit, 0, 94, NULL);
83 zfcp_erp_wait(unit->port->adapter);
86 up(&zfcp_data.config_sema);
87 return retval ? retval : (ssize_t) count;
90 static DEVICE_ATTR(unit_add, S_IWUSR, NULL, zfcp_sysfs_unit_add_store);
93 * zfcp_sysfs_unit_remove_store - remove a unit from sysfs tree
94 * @dev: pointer to belonging device
95 * @buf: pointer to input buffer
96 * @count: number of bytes in buffer
99 zfcp_sysfs_unit_remove_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
101 struct zfcp_port *port;
102 struct zfcp_unit *unit;
107 down(&zfcp_data.config_sema);
109 port = dev_get_drvdata(dev);
110 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
115 fcp_lun = simple_strtoull(buf, &endp, 0);
116 if ((endp + 1) < (buf + count)) {
121 write_lock_irq(&zfcp_data.config_lock);
122 unit = zfcp_get_unit_by_lun(port, fcp_lun);
123 if (unit && (atomic_read(&unit->refcount) == 0)) {
125 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE, &unit->status);
126 list_move(&unit->list, &port->unit_remove_lh);
131 write_unlock_irq(&zfcp_data.config_lock);
138 zfcp_erp_unit_shutdown(unit, 0, 95, NULL);
139 zfcp_erp_wait(unit->port->adapter);
141 zfcp_unit_dequeue(unit);
143 up(&zfcp_data.config_sema);
144 return retval ? retval : (ssize_t) count;
147 static DEVICE_ATTR(unit_remove, S_IWUSR, NULL, zfcp_sysfs_unit_remove_store);
150 * zfcp_sysfs_port_failed_store - failed state of port
151 * @dev: pointer to belonging device
152 * @buf: pointer to input buffer
153 * @count: number of bytes in buffer
155 * Store function of the "failed" attribute of a port.
156 * If a "0" gets written to "failed", error recovery will be
157 * started for the belonging port.
160 zfcp_sysfs_port_failed_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
162 struct zfcp_port *port;
167 down(&zfcp_data.config_sema);
169 port = dev_get_drvdata(dev);
170 if (atomic_test_mask(ZFCP_STATUS_COMMON_REMOVE, &port->status)) {
175 val = simple_strtoul(buf, &endp, 0);
176 if (((endp + 1) < (buf + count)) || (val != 0)) {
181 zfcp_erp_modify_port_status(port, 45, NULL,
182 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
183 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, 96, NULL);
184 zfcp_erp_wait(port->adapter);
186 up(&zfcp_data.config_sema);
187 return retval ? retval : (ssize_t) count;
191 * zfcp_sysfs_port_failed_show - failed state of port
192 * @dev: pointer to belonging device
193 * @buf: pointer to input buffer
195 * Show function of "failed" attribute of port. Will be
196 * "0" if port is working, otherwise "1".
199 zfcp_sysfs_port_failed_show(struct device *dev, struct device_attribute *attr, char *buf)
201 struct zfcp_port *port;
203 port = dev_get_drvdata(dev);
204 if (atomic_test_mask(ZFCP_STATUS_COMMON_ERP_FAILED, &port->status))
205 return sprintf(buf, "1\n");
207 return sprintf(buf, "0\n");
210 static DEVICE_ATTR(failed, S_IWUSR | S_IRUGO, zfcp_sysfs_port_failed_show,
211 zfcp_sysfs_port_failed_store);
214 * zfcp_port_common_attrs
215 * sysfs attributes that are common for all kind of fc ports.
217 static struct attribute *zfcp_port_common_attrs[] = {
218 &dev_attr_failed.attr,
219 &dev_attr_in_recovery.attr,
220 &dev_attr_status.attr,
221 &dev_attr_access_denied.attr,
225 static struct attribute_group zfcp_port_common_attr_group = {
226 .attrs = zfcp_port_common_attrs,
230 * zfcp_port_no_ns_attrs
231 * sysfs attributes not to be used for nameserver ports.
233 static struct attribute *zfcp_port_no_ns_attrs[] = {
234 &dev_attr_unit_add.attr,
235 &dev_attr_unit_remove.attr,
239 static struct attribute_group zfcp_port_no_ns_attr_group = {
240 .attrs = zfcp_port_no_ns_attrs,
244 * zfcp_sysfs_port_create_files - create sysfs port files
245 * @dev: pointer to belonging device
247 * Create all attributes of the sysfs representation of a port.
250 zfcp_sysfs_port_create_files(struct device *dev, u32 flags)
254 retval = sysfs_create_group(&dev->kobj, &zfcp_port_common_attr_group);
256 if ((flags & ZFCP_STATUS_PORT_WKA) || retval)
259 retval = sysfs_create_group(&dev->kobj, &zfcp_port_no_ns_attr_group);
261 sysfs_remove_group(&dev->kobj, &zfcp_port_common_attr_group);
267 * zfcp_sysfs_port_remove_files - remove sysfs port files
268 * @dev: pointer to belonging device
270 * Remove all attributes of the sysfs representation of a port.
273 zfcp_sysfs_port_remove_files(struct device *dev, u32 flags)
275 sysfs_remove_group(&dev->kobj, &zfcp_port_common_attr_group);
276 if (!(flags & ZFCP_STATUS_PORT_WKA))
277 sysfs_remove_group(&dev->kobj, &zfcp_port_no_ns_attr_group);