blob: 2f2c54f4718f40f0e49b04315678a56a1aa866e8 [file] [log] [blame]
Swen Schillig60221922008-07-02 10:56:38 +02001/*
2 * zfcp device driver
3 *
4 * sysfs attributes.
5 *
Christof Schmitt615f59e2010-02-17 11:18:56 +01006 * Copyright IBM Corporation 2008, 2010
Swen Schillig60221922008-07-02 10:56:38 +02007 */
8
Christof Schmittecf39d42008-12-25 13:39:53 +01009#define KMSG_COMPONENT "zfcp"
10#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
11
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090012#include <linux/slab.h>
Swen Schillig60221922008-07-02 10:56:38 +020013#include "zfcp_ext.h"
14
15#define ZFCP_DEV_ATTR(_feat, _name, _mode, _show, _store) \
16struct device_attribute dev_attr_##_feat##_##_name = __ATTR(_name, _mode,\
17 _show, _store)
18#define ZFCP_DEFINE_ATTR(_feat_def, _feat, _name, _format, _value) \
19static ssize_t zfcp_sysfs_##_feat##_##_name##_show(struct device *dev, \
20 struct device_attribute *at,\
21 char *buf) \
22{ \
Christof Schmitt615f59e2010-02-17 11:18:56 +010023 struct _feat_def *_feat = container_of(dev, struct _feat_def, dev); \
Swen Schillig60221922008-07-02 10:56:38 +020024 \
25 return sprintf(buf, _format, _value); \
26} \
27static ZFCP_DEV_ATTR(_feat, _name, S_IRUGO, \
28 zfcp_sysfs_##_feat##_##_name##_show, NULL);
29
Swen Schilligde3dc572009-11-24 16:54:00 +010030#define ZFCP_DEFINE_A_ATTR(_name, _format, _value) \
31static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, \
32 struct device_attribute *at,\
33 char *buf) \
34{ \
35 struct ccw_device *cdev = to_ccwdev(dev); \
36 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev); \
37 int i; \
38 \
39 if (!adapter) \
40 return -ENODEV; \
41 \
42 i = sprintf(buf, _format, _value); \
43 zfcp_ccw_adapter_put(adapter); \
44 return i; \
45} \
46static ZFCP_DEV_ATTR(adapter, _name, S_IRUGO, \
47 zfcp_sysfs_adapter_##_name##_show, NULL);
48
49ZFCP_DEFINE_A_ATTR(status, "0x%08x\n", atomic_read(&adapter->status));
50ZFCP_DEFINE_A_ATTR(peer_wwnn, "0x%016llx\n",
51 (unsigned long long) adapter->peer_wwnn);
52ZFCP_DEFINE_A_ATTR(peer_wwpn, "0x%016llx\n",
53 (unsigned long long) adapter->peer_wwpn);
54ZFCP_DEFINE_A_ATTR(peer_d_id, "0x%06x\n", adapter->peer_d_id);
55ZFCP_DEFINE_A_ATTR(card_version, "0x%04x\n", adapter->hydra_version);
56ZFCP_DEFINE_A_ATTR(lic_version, "0x%08x\n", adapter->fsf_lic_version);
57ZFCP_DEFINE_A_ATTR(hardware_version, "0x%08x\n", adapter->hardware_version);
58ZFCP_DEFINE_A_ATTR(in_recovery, "%d\n", (atomic_read(&adapter->status) &
59 ZFCP_STATUS_COMMON_ERP_INUSE) != 0);
Swen Schillig60221922008-07-02 10:56:38 +020060
61ZFCP_DEFINE_ATTR(zfcp_port, port, status, "0x%08x\n",
62 atomic_read(&port->status));
63ZFCP_DEFINE_ATTR(zfcp_port, port, in_recovery, "%d\n",
64 (atomic_read(&port->status) &
65 ZFCP_STATUS_COMMON_ERP_INUSE) != 0);
66ZFCP_DEFINE_ATTR(zfcp_port, port, access_denied, "%d\n",
67 (atomic_read(&port->status) &
68 ZFCP_STATUS_COMMON_ACCESS_DENIED) != 0);
69
70ZFCP_DEFINE_ATTR(zfcp_unit, unit, status, "0x%08x\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +020071 zfcp_unit_sdev_status(unit));
Swen Schillig60221922008-07-02 10:56:38 +020072ZFCP_DEFINE_ATTR(zfcp_unit, unit, in_recovery, "%d\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +020073 (zfcp_unit_sdev_status(unit) &
Swen Schillig60221922008-07-02 10:56:38 +020074 ZFCP_STATUS_COMMON_ERP_INUSE) != 0);
75ZFCP_DEFINE_ATTR(zfcp_unit, unit, access_denied, "%d\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +020076 (zfcp_unit_sdev_status(unit) &
Swen Schillig60221922008-07-02 10:56:38 +020077 ZFCP_STATUS_COMMON_ACCESS_DENIED) != 0);
78ZFCP_DEFINE_ATTR(zfcp_unit, unit, access_shared, "%d\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +020079 (zfcp_unit_sdev_status(unit) &
80 ZFCP_STATUS_LUN_SHARED) != 0);
Swen Schillig60221922008-07-02 10:56:38 +020081ZFCP_DEFINE_ATTR(zfcp_unit, unit, access_readonly, "%d\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +020082 (zfcp_unit_sdev_status(unit) &
83 ZFCP_STATUS_LUN_READONLY) != 0);
Swen Schillig60221922008-07-02 10:56:38 +020084
Christof Schmitte4b98572010-09-08 14:39:53 +020085static ssize_t zfcp_sysfs_port_failed_show(struct device *dev,
86 struct device_attribute *attr,
87 char *buf)
88{
89 struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
Swen Schillig60221922008-07-02 10:56:38 +020090
Christof Schmitte4b98572010-09-08 14:39:53 +020091 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
92 return sprintf(buf, "1\n");
93
94 return sprintf(buf, "0\n");
95}
96
97static ssize_t zfcp_sysfs_port_failed_store(struct device *dev,
98 struct device_attribute *attr,
99 const char *buf, size_t count)
100{
101 struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
102 unsigned long val;
103
104 if (strict_strtoul(buf, 0, &val) || val != 0)
105 return -EINVAL;
106
Swen Schilligedaed8592010-09-08 14:40:01 +0200107 zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_RUNNING);
Christof Schmitte4b98572010-09-08 14:39:53 +0200108 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, "sypfai2",
109 NULL);
110 zfcp_erp_wait(port->adapter);
111
112 return count;
113}
114static ZFCP_DEV_ATTR(port, failed, S_IWUSR | S_IRUGO,
115 zfcp_sysfs_port_failed_show,
116 zfcp_sysfs_port_failed_store);
117
118static ssize_t zfcp_sysfs_unit_failed_show(struct device *dev,
119 struct device_attribute *attr,
120 char *buf)
121{
122 struct zfcp_unit *unit = container_of(dev, struct zfcp_unit, dev);
Christof Schmittb62a8d92010-09-08 14:39:55 +0200123 struct scsi_device *sdev;
124 unsigned int status, failed = 1;
Christof Schmitte4b98572010-09-08 14:39:53 +0200125
Christof Schmittb62a8d92010-09-08 14:39:55 +0200126 sdev = zfcp_unit_sdev(unit);
127 if (sdev) {
128 status = atomic_read(&sdev_to_zfcp(sdev)->status);
129 failed = status & ZFCP_STATUS_COMMON_ERP_FAILED ? 1 : 0;
130 scsi_device_put(sdev);
131 }
Christof Schmitte4b98572010-09-08 14:39:53 +0200132
Christof Schmittb62a8d92010-09-08 14:39:55 +0200133 return sprintf(buf, "%d\n", failed);
Christof Schmitte4b98572010-09-08 14:39:53 +0200134}
135
136static ssize_t zfcp_sysfs_unit_failed_store(struct device *dev,
137 struct device_attribute *attr,
138 const char *buf, size_t count)
139{
140 struct zfcp_unit *unit = container_of(dev, struct zfcp_unit, dev);
141 unsigned long val;
Christof Schmittb62a8d92010-09-08 14:39:55 +0200142 struct scsi_device *sdev;
Christof Schmitte4b98572010-09-08 14:39:53 +0200143
144 if (strict_strtoul(buf, 0, &val) || val != 0)
145 return -EINVAL;
146
Christof Schmittb62a8d92010-09-08 14:39:55 +0200147 sdev = zfcp_unit_sdev(unit);
148 if (sdev) {
Swen Schilligedaed8592010-09-08 14:40:01 +0200149 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_RUNNING);
Christof Schmittb62a8d92010-09-08 14:39:55 +0200150 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
151 "syufai2", NULL);
152 zfcp_erp_wait(unit->port->adapter);
153 } else
154 zfcp_unit_scsi_scan(unit);
Christof Schmitte4b98572010-09-08 14:39:53 +0200155
156 return count;
157}
158static ZFCP_DEV_ATTR(unit, failed, S_IWUSR | S_IRUGO,
159 zfcp_sysfs_unit_failed_show,
160 zfcp_sysfs_unit_failed_store);
Swen Schillig60221922008-07-02 10:56:38 +0200161
Swen Schilligde3dc572009-11-24 16:54:00 +0100162static ssize_t zfcp_sysfs_adapter_failed_show(struct device *dev,
163 struct device_attribute *attr,
164 char *buf)
165{
166 struct ccw_device *cdev = to_ccwdev(dev);
167 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
168 int i;
169
170 if (!adapter)
171 return -ENODEV;
172
173 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
174 i = sprintf(buf, "1\n");
175 else
176 i = sprintf(buf, "0\n");
177
178 zfcp_ccw_adapter_put(adapter);
179 return i;
180}
181
182static ssize_t zfcp_sysfs_adapter_failed_store(struct device *dev,
183 struct device_attribute *attr,
184 const char *buf, size_t count)
185{
186 struct ccw_device *cdev = to_ccwdev(dev);
187 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
188 unsigned long val;
189 int retval = 0;
190
191 if (!adapter)
192 return -ENODEV;
193
Swen Schilligde3dc572009-11-24 16:54:00 +0100194 if (strict_strtoul(buf, 0, &val) || val != 0) {
195 retval = -EINVAL;
196 goto out;
197 }
198
Swen Schilligedaed8592010-09-08 14:40:01 +0200199 zfcp_erp_set_adapter_status(adapter, ZFCP_STATUS_COMMON_RUNNING);
Swen Schilligde3dc572009-11-24 16:54:00 +0100200 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
201 "syafai2", NULL);
202 zfcp_erp_wait(adapter);
203out:
204 zfcp_ccw_adapter_put(adapter);
205 return retval ? retval : (ssize_t) count;
206}
207static ZFCP_DEV_ATTR(adapter, failed, S_IWUSR | S_IRUGO,
208 zfcp_sysfs_adapter_failed_show,
209 zfcp_sysfs_adapter_failed_store);
210
Swen Schillig60221922008-07-02 10:56:38 +0200211static ssize_t zfcp_sysfs_port_rescan_store(struct device *dev,
212 struct device_attribute *attr,
213 const char *buf, size_t count)
214{
Swen Schilligde3dc572009-11-24 16:54:00 +0100215 struct ccw_device *cdev = to_ccwdev(dev);
216 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
Swen Schillig60221922008-07-02 10:56:38 +0200217
Swen Schilligde3dc572009-11-24 16:54:00 +0100218 if (!adapter)
219 return -ENODEV;
220
Swen Schillig9eae07e2009-11-24 16:54:06 +0100221 /* sync the user-space- with the kernel-invocation of scan_work */
222 queue_work(adapter->work_queue, &adapter->scan_work);
223 flush_work(&adapter->scan_work);
Swen Schilligde3dc572009-11-24 16:54:00 +0100224 zfcp_ccw_adapter_put(adapter);
Swen Schillig6b183332009-11-24 16:54:05 +0100225
Swen Schillig9eae07e2009-11-24 16:54:06 +0100226 return (ssize_t) count;
Swen Schillig60221922008-07-02 10:56:38 +0200227}
228static ZFCP_DEV_ATTR(adapter, port_rescan, S_IWUSR, NULL,
229 zfcp_sysfs_port_rescan_store);
230
231static ssize_t zfcp_sysfs_port_remove_store(struct device *dev,
232 struct device_attribute *attr,
233 const char *buf, size_t count)
234{
Swen Schilligde3dc572009-11-24 16:54:00 +0100235 struct ccw_device *cdev = to_ccwdev(dev);
236 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
Swen Schillig60221922008-07-02 10:56:38 +0200237 struct zfcp_port *port;
Swen Schillig7ba58c92008-10-01 12:42:18 +0200238 u64 wwpn;
Swen Schillig6b183332009-11-24 16:54:05 +0100239 int retval = -EINVAL;
Swen Schillig60221922008-07-02 10:56:38 +0200240
Swen Schilligde3dc572009-11-24 16:54:00 +0100241 if (!adapter)
242 return -ENODEV;
243
Swen Schillig6b183332009-11-24 16:54:05 +0100244 if (strict_strtoull(buf, 0, (unsigned long long *) &wwpn))
Swen Schillig60221922008-07-02 10:56:38 +0200245 goto out;
Swen Schillig60221922008-07-02 10:56:38 +0200246
Swen Schillig60221922008-07-02 10:56:38 +0200247 port = zfcp_get_port_by_wwpn(adapter, wwpn);
Swen Schillig6b183332009-11-24 16:54:05 +0100248 if (!port)
Swen Schillig60221922008-07-02 10:56:38 +0200249 goto out;
Swen Schillig6b183332009-11-24 16:54:05 +0100250 else
251 retval = 0;
Swen Schilligf3450c72009-11-24 16:53:59 +0100252
253 write_lock_irq(&adapter->port_list_lock);
254 list_del(&port->list);
255 write_unlock_irq(&adapter->port_list_lock);
256
Christof Schmitt615f59e2010-02-17 11:18:56 +0100257 put_device(&port->dev);
Swen Schilligf3450c72009-11-24 16:53:59 +0100258
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100259 zfcp_erp_port_shutdown(port, 0, "syprs_1", NULL);
Christof Schmitt615f59e2010-02-17 11:18:56 +0100260 zfcp_device_unregister(&port->dev, &zfcp_sysfs_port_attrs);
Swen Schillig60221922008-07-02 10:56:38 +0200261 out:
Swen Schilligde3dc572009-11-24 16:54:00 +0100262 zfcp_ccw_adapter_put(adapter);
Swen Schillig60221922008-07-02 10:56:38 +0200263 return retval ? retval : (ssize_t) count;
264}
265static ZFCP_DEV_ATTR(adapter, port_remove, S_IWUSR, NULL,
266 zfcp_sysfs_port_remove_store);
267
268static struct attribute *zfcp_adapter_attrs[] = {
269 &dev_attr_adapter_failed.attr,
270 &dev_attr_adapter_in_recovery.attr,
271 &dev_attr_adapter_port_remove.attr,
272 &dev_attr_adapter_port_rescan.attr,
273 &dev_attr_adapter_peer_wwnn.attr,
274 &dev_attr_adapter_peer_wwpn.attr,
275 &dev_attr_adapter_peer_d_id.attr,
276 &dev_attr_adapter_card_version.attr,
277 &dev_attr_adapter_lic_version.attr,
278 &dev_attr_adapter_status.attr,
279 &dev_attr_adapter_hardware_version.attr,
280 NULL
281};
282
283struct attribute_group zfcp_sysfs_adapter_attrs = {
284 .attrs = zfcp_adapter_attrs,
285};
286
287static ssize_t zfcp_sysfs_unit_add_store(struct device *dev,
288 struct device_attribute *attr,
289 const char *buf, size_t count)
290{
Christof Schmitt615f59e2010-02-17 11:18:56 +0100291 struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
Swen Schillig7ba58c92008-10-01 12:42:18 +0200292 u64 fcp_lun;
Swen Schillig60221922008-07-02 10:56:38 +0200293
Swen Schillig7ba58c92008-10-01 12:42:18 +0200294 if (strict_strtoull(buf, 0, (unsigned long long *) &fcp_lun))
Christof Schmitt1daa4eb2010-09-08 14:39:52 +0200295 return -EINVAL;
Swen Schillig60221922008-07-02 10:56:38 +0200296
Christof Schmitt1daa4eb2010-09-08 14:39:52 +0200297 if (zfcp_unit_add(port, fcp_lun))
298 return -EINVAL;
Swen Schillig60221922008-07-02 10:56:38 +0200299
Christof Schmitt1daa4eb2010-09-08 14:39:52 +0200300 return count;
Swen Schillig60221922008-07-02 10:56:38 +0200301}
302static DEVICE_ATTR(unit_add, S_IWUSR, NULL, zfcp_sysfs_unit_add_store);
303
304static ssize_t zfcp_sysfs_unit_remove_store(struct device *dev,
305 struct device_attribute *attr,
306 const char *buf, size_t count)
307{
Christof Schmitt615f59e2010-02-17 11:18:56 +0100308 struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
Swen Schillig7ba58c92008-10-01 12:42:18 +0200309 u64 fcp_lun;
Swen Schillig60221922008-07-02 10:56:38 +0200310
Swen Schillig6b183332009-11-24 16:54:05 +0100311 if (strict_strtoull(buf, 0, (unsigned long long *) &fcp_lun))
Christof Schmitt1daa4eb2010-09-08 14:39:52 +0200312 return -EINVAL;
Swen Schillig60221922008-07-02 10:56:38 +0200313
Christof Schmitt1daa4eb2010-09-08 14:39:52 +0200314 if (zfcp_unit_remove(port, fcp_lun))
315 return -EINVAL;
Swen Schillig60221922008-07-02 10:56:38 +0200316
Christof Schmitt1daa4eb2010-09-08 14:39:52 +0200317 return count;
Swen Schillig60221922008-07-02 10:56:38 +0200318}
319static DEVICE_ATTR(unit_remove, S_IWUSR, NULL, zfcp_sysfs_unit_remove_store);
320
Swen Schillig5ab944f2008-10-01 12:42:17 +0200321static struct attribute *zfcp_port_attrs[] = {
Swen Schillig60221922008-07-02 10:56:38 +0200322 &dev_attr_unit_add.attr,
323 &dev_attr_unit_remove.attr,
324 &dev_attr_port_failed.attr,
325 &dev_attr_port_in_recovery.attr,
326 &dev_attr_port_status.attr,
327 &dev_attr_port_access_denied.attr,
328 NULL
329};
330
331/**
332 * zfcp_sysfs_port_attrs - sysfs attributes for all other ports
333 */
334struct attribute_group zfcp_sysfs_port_attrs = {
Swen Schillig5ab944f2008-10-01 12:42:17 +0200335 .attrs = zfcp_port_attrs,
Swen Schillig60221922008-07-02 10:56:38 +0200336};
337
338static struct attribute *zfcp_unit_attrs[] = {
339 &dev_attr_unit_failed.attr,
340 &dev_attr_unit_in_recovery.attr,
341 &dev_attr_unit_status.attr,
342 &dev_attr_unit_access_denied.attr,
343 &dev_attr_unit_access_shared.attr,
344 &dev_attr_unit_access_readonly.attr,
345 NULL
346};
347
348struct attribute_group zfcp_sysfs_unit_attrs = {
349 .attrs = zfcp_unit_attrs,
350};
351
352#define ZFCP_DEFINE_LATENCY_ATTR(_name) \
353static ssize_t \
354zfcp_sysfs_unit_##_name##_latency_show(struct device *dev, \
355 struct device_attribute *attr, \
356 char *buf) { \
357 struct scsi_device *sdev = to_scsi_device(dev); \
Christof Schmittb62a8d92010-09-08 14:39:55 +0200358 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); \
359 struct zfcp_latencies *lat = &zfcp_sdev->latencies; \
360 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter; \
Swen Schillig60221922008-07-02 10:56:38 +0200361 unsigned long long fsum, fmin, fmax, csum, cmin, cmax, cc; \
362 \
Christof Schmitt49f0f012009-03-02 13:08:57 +0100363 spin_lock_bh(&lat->lock); \
Swen Schillig60221922008-07-02 10:56:38 +0200364 fsum = lat->_name.fabric.sum * adapter->timer_ticks; \
365 fmin = lat->_name.fabric.min * adapter->timer_ticks; \
366 fmax = lat->_name.fabric.max * adapter->timer_ticks; \
367 csum = lat->_name.channel.sum * adapter->timer_ticks; \
368 cmin = lat->_name.channel.min * adapter->timer_ticks; \
369 cmax = lat->_name.channel.max * adapter->timer_ticks; \
370 cc = lat->_name.counter; \
Christof Schmitt49f0f012009-03-02 13:08:57 +0100371 spin_unlock_bh(&lat->lock); \
Swen Schillig60221922008-07-02 10:56:38 +0200372 \
373 do_div(fsum, 1000); \
374 do_div(fmin, 1000); \
375 do_div(fmax, 1000); \
376 do_div(csum, 1000); \
377 do_div(cmin, 1000); \
378 do_div(cmax, 1000); \
379 \
380 return sprintf(buf, "%llu %llu %llu %llu %llu %llu %llu\n", \
381 fmin, fmax, fsum, cmin, cmax, csum, cc); \
382} \
383static ssize_t \
384zfcp_sysfs_unit_##_name##_latency_store(struct device *dev, \
385 struct device_attribute *attr, \
386 const char *buf, size_t count) \
387{ \
388 struct scsi_device *sdev = to_scsi_device(dev); \
Christof Schmittb62a8d92010-09-08 14:39:55 +0200389 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); \
390 struct zfcp_latencies *lat = &zfcp_sdev->latencies; \
Swen Schillig60221922008-07-02 10:56:38 +0200391 unsigned long flags; \
392 \
393 spin_lock_irqsave(&lat->lock, flags); \
394 lat->_name.fabric.sum = 0; \
395 lat->_name.fabric.min = 0xFFFFFFFF; \
396 lat->_name.fabric.max = 0; \
397 lat->_name.channel.sum = 0; \
398 lat->_name.channel.min = 0xFFFFFFFF; \
399 lat->_name.channel.max = 0; \
400 lat->_name.counter = 0; \
401 spin_unlock_irqrestore(&lat->lock, flags); \
402 \
403 return (ssize_t) count; \
404} \
405static DEVICE_ATTR(_name##_latency, S_IWUSR | S_IRUGO, \
406 zfcp_sysfs_unit_##_name##_latency_show, \
407 zfcp_sysfs_unit_##_name##_latency_store);
408
409ZFCP_DEFINE_LATENCY_ATTR(read);
410ZFCP_DEFINE_LATENCY_ATTR(write);
411ZFCP_DEFINE_LATENCY_ATTR(cmd);
412
413#define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value) \
414static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, \
415 struct device_attribute *attr,\
416 char *buf) \
417{ \
Christof Schmittb62a8d92010-09-08 14:39:55 +0200418 struct scsi_device *sdev = to_scsi_device(dev); \
419 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); \
420 struct zfcp_port *port = zfcp_sdev->port; \
Swen Schillig60221922008-07-02 10:56:38 +0200421 \
422 return sprintf(buf, _format, _value); \
423} \
424static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL);
425
426ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +0200427 dev_name(&port->adapter->ccw_device->dev));
Swen Schillig7ba58c92008-10-01 12:42:18 +0200428ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +0200429 (unsigned long long) port->wwpn);
Christof Schmitte4b98572010-09-08 14:39:53 +0200430
431static ssize_t zfcp_sysfs_scsi_fcp_lun_show(struct device *dev,
432 struct device_attribute *attr,
433 char *buf)
434{
435 struct scsi_device *sdev = to_scsi_device(dev);
Christof Schmitte4b98572010-09-08 14:39:53 +0200436
Christof Schmittb62a8d92010-09-08 14:39:55 +0200437 return sprintf(buf, "0x%016llx\n", zfcp_scsi_dev_lun(sdev));
Christof Schmitte4b98572010-09-08 14:39:53 +0200438}
439static DEVICE_ATTR(fcp_lun, S_IRUGO, zfcp_sysfs_scsi_fcp_lun_show, NULL);
Swen Schillig60221922008-07-02 10:56:38 +0200440
441struct device_attribute *zfcp_sysfs_sdev_attrs[] = {
442 &dev_attr_fcp_lun,
443 &dev_attr_wwpn,
444 &dev_attr_hba_id,
445 &dev_attr_read_latency,
446 &dev_attr_write_latency,
447 &dev_attr_cmd_latency,
448 NULL
449};
450
451static ssize_t zfcp_sysfs_adapter_util_show(struct device *dev,
452 struct device_attribute *attr,
453 char *buf)
454{
455 struct Scsi_Host *scsi_host = dev_to_shost(dev);
456 struct fsf_qtcb_bottom_port *qtcb_port;
457 struct zfcp_adapter *adapter;
458 int retval;
459
460 adapter = (struct zfcp_adapter *) scsi_host->hostdata[0];
461 if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA))
462 return -EOPNOTSUPP;
463
464 qtcb_port = kzalloc(sizeof(struct fsf_qtcb_bottom_port), GFP_KERNEL);
465 if (!qtcb_port)
466 return -ENOMEM;
467
Swen Schillig564e1c82009-08-18 15:43:19 +0200468 retval = zfcp_fsf_exchange_port_data_sync(adapter->qdio, qtcb_port);
Swen Schillig60221922008-07-02 10:56:38 +0200469 if (!retval)
470 retval = sprintf(buf, "%u %u %u\n", qtcb_port->cp_util,
471 qtcb_port->cb_util, qtcb_port->a_util);
472 kfree(qtcb_port);
473 return retval;
474}
475static DEVICE_ATTR(utilization, S_IRUGO, zfcp_sysfs_adapter_util_show, NULL);
476
477static int zfcp_sysfs_adapter_ex_config(struct device *dev,
478 struct fsf_statistics_info *stat_inf)
479{
480 struct Scsi_Host *scsi_host = dev_to_shost(dev);
481 struct fsf_qtcb_bottom_config *qtcb_config;
482 struct zfcp_adapter *adapter;
483 int retval;
484
485 adapter = (struct zfcp_adapter *) scsi_host->hostdata[0];
486 if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA))
487 return -EOPNOTSUPP;
488
489 qtcb_config = kzalloc(sizeof(struct fsf_qtcb_bottom_config),
490 GFP_KERNEL);
491 if (!qtcb_config)
492 return -ENOMEM;
493
Swen Schillig564e1c82009-08-18 15:43:19 +0200494 retval = zfcp_fsf_exchange_config_data_sync(adapter->qdio, qtcb_config);
Swen Schillig60221922008-07-02 10:56:38 +0200495 if (!retval)
496 *stat_inf = qtcb_config->stat_info;
497
498 kfree(qtcb_config);
499 return retval;
500}
501
502#define ZFCP_SHOST_ATTR(_name, _format, _arg...) \
503static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, \
504 struct device_attribute *attr,\
505 char *buf) \
506{ \
507 struct fsf_statistics_info stat_info; \
508 int retval; \
509 \
510 retval = zfcp_sysfs_adapter_ex_config(dev, &stat_info); \
511 if (retval) \
512 return retval; \
513 \
514 return sprintf(buf, _format, ## _arg); \
515} \
516static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL);
517
518ZFCP_SHOST_ATTR(requests, "%llu %llu %llu\n",
519 (unsigned long long) stat_info.input_req,
520 (unsigned long long) stat_info.output_req,
521 (unsigned long long) stat_info.control_req);
522
523ZFCP_SHOST_ATTR(megabytes, "%llu %llu\n",
524 (unsigned long long) stat_info.input_mb,
525 (unsigned long long) stat_info.output_mb);
526
527ZFCP_SHOST_ATTR(seconds_active, "%llu\n",
528 (unsigned long long) stat_info.seconds_act);
529
Stefan Raspl2450d3e2008-10-01 12:42:14 +0200530static ssize_t zfcp_sysfs_adapter_q_full_show(struct device *dev,
531 struct device_attribute *attr,
532 char *buf)
533{
534 struct Scsi_Host *scsi_host = class_to_shost(dev);
Swen Schillig564e1c82009-08-18 15:43:19 +0200535 struct zfcp_qdio *qdio =
536 ((struct zfcp_adapter *) scsi_host->hostdata[0])->qdio;
Christof Schmittacf7b862009-07-13 15:06:03 +0200537 u64 util;
538
Swen Schillig564e1c82009-08-18 15:43:19 +0200539 spin_lock_bh(&qdio->stat_lock);
540 util = qdio->req_q_util;
541 spin_unlock_bh(&qdio->stat_lock);
Stefan Raspl2450d3e2008-10-01 12:42:14 +0200542
Swen Schillig564e1c82009-08-18 15:43:19 +0200543 return sprintf(buf, "%d %llu\n", atomic_read(&qdio->req_q_full),
Christof Schmittacf7b862009-07-13 15:06:03 +0200544 (unsigned long long)util);
Stefan Raspl2450d3e2008-10-01 12:42:14 +0200545}
546static DEVICE_ATTR(queue_full, S_IRUGO, zfcp_sysfs_adapter_q_full_show, NULL);
547
Swen Schillig60221922008-07-02 10:56:38 +0200548struct device_attribute *zfcp_sysfs_shost_attrs[] = {
549 &dev_attr_utilization,
550 &dev_attr_requests,
551 &dev_attr_megabytes,
552 &dev_attr_seconds_active,
Stefan Raspl2450d3e2008-10-01 12:42:14 +0200553 &dev_attr_queue_full,
Swen Schillig60221922008-07-02 10:56:38 +0200554 NULL
555};