blob: 4f59356b07bbb3510c78619c2758a38ebc312635 [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
107 zfcp_erp_modify_port_status(port, "sypfai1", NULL,
108 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
109 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, "sypfai2",
110 NULL);
111 zfcp_erp_wait(port->adapter);
112
113 return count;
114}
115static ZFCP_DEV_ATTR(port, failed, S_IWUSR | S_IRUGO,
116 zfcp_sysfs_port_failed_show,
117 zfcp_sysfs_port_failed_store);
118
119static ssize_t zfcp_sysfs_unit_failed_show(struct device *dev,
120 struct device_attribute *attr,
121 char *buf)
122{
123 struct zfcp_unit *unit = container_of(dev, struct zfcp_unit, dev);
Christof Schmittb62a8d92010-09-08 14:39:55 +0200124 struct scsi_device *sdev;
125 unsigned int status, failed = 1;
Christof Schmitte4b98572010-09-08 14:39:53 +0200126
Christof Schmittb62a8d92010-09-08 14:39:55 +0200127 sdev = zfcp_unit_sdev(unit);
128 if (sdev) {
129 status = atomic_read(&sdev_to_zfcp(sdev)->status);
130 failed = status & ZFCP_STATUS_COMMON_ERP_FAILED ? 1 : 0;
131 scsi_device_put(sdev);
132 }
Christof Schmitte4b98572010-09-08 14:39:53 +0200133
Christof Schmittb62a8d92010-09-08 14:39:55 +0200134 return sprintf(buf, "%d\n", failed);
Christof Schmitte4b98572010-09-08 14:39:53 +0200135}
136
137static ssize_t zfcp_sysfs_unit_failed_store(struct device *dev,
138 struct device_attribute *attr,
139 const char *buf, size_t count)
140{
141 struct zfcp_unit *unit = container_of(dev, struct zfcp_unit, dev);
142 unsigned long val;
Christof Schmittb62a8d92010-09-08 14:39:55 +0200143 struct scsi_device *sdev;
Christof Schmitte4b98572010-09-08 14:39:53 +0200144
145 if (strict_strtoul(buf, 0, &val) || val != 0)
146 return -EINVAL;
147
Christof Schmittb62a8d92010-09-08 14:39:55 +0200148 sdev = zfcp_unit_sdev(unit);
149 if (sdev) {
150 zfcp_erp_modify_lun_status(sdev, "syufai1", NULL,
151 ZFCP_STATUS_COMMON_RUNNING,
152 ZFCP_SET);
153 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
154 "syufai2", NULL);
155 zfcp_erp_wait(unit->port->adapter);
156 } else
157 zfcp_unit_scsi_scan(unit);
Christof Schmitte4b98572010-09-08 14:39:53 +0200158
159 return count;
160}
161static ZFCP_DEV_ATTR(unit, failed, S_IWUSR | S_IRUGO,
162 zfcp_sysfs_unit_failed_show,
163 zfcp_sysfs_unit_failed_store);
Swen Schillig60221922008-07-02 10:56:38 +0200164
Swen Schilligde3dc572009-11-24 16:54:00 +0100165static ssize_t zfcp_sysfs_adapter_failed_show(struct device *dev,
166 struct device_attribute *attr,
167 char *buf)
168{
169 struct ccw_device *cdev = to_ccwdev(dev);
170 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
171 int i;
172
173 if (!adapter)
174 return -ENODEV;
175
176 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
177 i = sprintf(buf, "1\n");
178 else
179 i = sprintf(buf, "0\n");
180
181 zfcp_ccw_adapter_put(adapter);
182 return i;
183}
184
185static ssize_t zfcp_sysfs_adapter_failed_store(struct device *dev,
186 struct device_attribute *attr,
187 const char *buf, size_t count)
188{
189 struct ccw_device *cdev = to_ccwdev(dev);
190 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
191 unsigned long val;
192 int retval = 0;
193
194 if (!adapter)
195 return -ENODEV;
196
Swen Schilligde3dc572009-11-24 16:54:00 +0100197 if (strict_strtoul(buf, 0, &val) || val != 0) {
198 retval = -EINVAL;
199 goto out;
200 }
201
202 zfcp_erp_modify_adapter_status(adapter, "syafai1", NULL,
203 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);
204 zfcp_erp_adapter_reopen(adapter, ZFCP_STATUS_COMMON_ERP_FAILED,
205 "syafai2", NULL);
206 zfcp_erp_wait(adapter);
207out:
208 zfcp_ccw_adapter_put(adapter);
209 return retval ? retval : (ssize_t) count;
210}
211static ZFCP_DEV_ATTR(adapter, failed, S_IWUSR | S_IRUGO,
212 zfcp_sysfs_adapter_failed_show,
213 zfcp_sysfs_adapter_failed_store);
214
Swen Schillig60221922008-07-02 10:56:38 +0200215static ssize_t zfcp_sysfs_port_rescan_store(struct device *dev,
216 struct device_attribute *attr,
217 const char *buf, size_t count)
218{
Swen Schilligde3dc572009-11-24 16:54:00 +0100219 struct ccw_device *cdev = to_ccwdev(dev);
220 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
Swen Schillig60221922008-07-02 10:56:38 +0200221
Swen Schilligde3dc572009-11-24 16:54:00 +0100222 if (!adapter)
223 return -ENODEV;
224
Swen Schillig9eae07e2009-11-24 16:54:06 +0100225 /* sync the user-space- with the kernel-invocation of scan_work */
226 queue_work(adapter->work_queue, &adapter->scan_work);
227 flush_work(&adapter->scan_work);
Swen Schilligde3dc572009-11-24 16:54:00 +0100228 zfcp_ccw_adapter_put(adapter);
Swen Schillig6b1833342009-11-24 16:54:05 +0100229
Swen Schillig9eae07e2009-11-24 16:54:06 +0100230 return (ssize_t) count;
Swen Schillig60221922008-07-02 10:56:38 +0200231}
232static ZFCP_DEV_ATTR(adapter, port_rescan, S_IWUSR, NULL,
233 zfcp_sysfs_port_rescan_store);
234
235static ssize_t zfcp_sysfs_port_remove_store(struct device *dev,
236 struct device_attribute *attr,
237 const char *buf, size_t count)
238{
Swen Schilligde3dc572009-11-24 16:54:00 +0100239 struct ccw_device *cdev = to_ccwdev(dev);
240 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
Swen Schillig60221922008-07-02 10:56:38 +0200241 struct zfcp_port *port;
Swen Schillig7ba58c92008-10-01 12:42:18 +0200242 u64 wwpn;
Swen Schillig6b1833342009-11-24 16:54:05 +0100243 int retval = -EINVAL;
Swen Schillig60221922008-07-02 10:56:38 +0200244
Swen Schilligde3dc572009-11-24 16:54:00 +0100245 if (!adapter)
246 return -ENODEV;
247
Swen Schillig6b1833342009-11-24 16:54:05 +0100248 if (strict_strtoull(buf, 0, (unsigned long long *) &wwpn))
Swen Schillig60221922008-07-02 10:56:38 +0200249 goto out;
Swen Schillig60221922008-07-02 10:56:38 +0200250
Swen Schillig60221922008-07-02 10:56:38 +0200251 port = zfcp_get_port_by_wwpn(adapter, wwpn);
Swen Schillig6b1833342009-11-24 16:54:05 +0100252 if (!port)
Swen Schillig60221922008-07-02 10:56:38 +0200253 goto out;
Swen Schillig6b1833342009-11-24 16:54:05 +0100254 else
255 retval = 0;
Swen Schilligf3450c72009-11-24 16:53:59 +0100256
257 write_lock_irq(&adapter->port_list_lock);
258 list_del(&port->list);
259 write_unlock_irq(&adapter->port_list_lock);
260
Christof Schmitt615f59e2010-02-17 11:18:56 +0100261 put_device(&port->dev);
Swen Schilligf3450c72009-11-24 16:53:59 +0100262
Swen Schillig5ffd51a2009-03-02 13:09:04 +0100263 zfcp_erp_port_shutdown(port, 0, "syprs_1", NULL);
Christof Schmitt615f59e2010-02-17 11:18:56 +0100264 zfcp_device_unregister(&port->dev, &zfcp_sysfs_port_attrs);
Swen Schillig60221922008-07-02 10:56:38 +0200265 out:
Swen Schilligde3dc572009-11-24 16:54:00 +0100266 zfcp_ccw_adapter_put(adapter);
Swen Schillig60221922008-07-02 10:56:38 +0200267 return retval ? retval : (ssize_t) count;
268}
269static ZFCP_DEV_ATTR(adapter, port_remove, S_IWUSR, NULL,
270 zfcp_sysfs_port_remove_store);
271
272static struct attribute *zfcp_adapter_attrs[] = {
273 &dev_attr_adapter_failed.attr,
274 &dev_attr_adapter_in_recovery.attr,
275 &dev_attr_adapter_port_remove.attr,
276 &dev_attr_adapter_port_rescan.attr,
277 &dev_attr_adapter_peer_wwnn.attr,
278 &dev_attr_adapter_peer_wwpn.attr,
279 &dev_attr_adapter_peer_d_id.attr,
280 &dev_attr_adapter_card_version.attr,
281 &dev_attr_adapter_lic_version.attr,
282 &dev_attr_adapter_status.attr,
283 &dev_attr_adapter_hardware_version.attr,
284 NULL
285};
286
287struct attribute_group zfcp_sysfs_adapter_attrs = {
288 .attrs = zfcp_adapter_attrs,
289};
290
291static ssize_t zfcp_sysfs_unit_add_store(struct device *dev,
292 struct device_attribute *attr,
293 const char *buf, size_t count)
294{
Christof Schmitt615f59e2010-02-17 11:18:56 +0100295 struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
Swen Schillig7ba58c92008-10-01 12:42:18 +0200296 u64 fcp_lun;
Swen Schillig60221922008-07-02 10:56:38 +0200297
Swen Schillig7ba58c92008-10-01 12:42:18 +0200298 if (strict_strtoull(buf, 0, (unsigned long long *) &fcp_lun))
Christof Schmitt1daa4eb2010-09-08 14:39:52 +0200299 return -EINVAL;
Swen Schillig60221922008-07-02 10:56:38 +0200300
Christof Schmitt1daa4eb2010-09-08 14:39:52 +0200301 if (zfcp_unit_add(port, fcp_lun))
302 return -EINVAL;
Swen Schillig60221922008-07-02 10:56:38 +0200303
Christof Schmitt1daa4eb2010-09-08 14:39:52 +0200304 return count;
Swen Schillig60221922008-07-02 10:56:38 +0200305}
306static DEVICE_ATTR(unit_add, S_IWUSR, NULL, zfcp_sysfs_unit_add_store);
307
308static ssize_t zfcp_sysfs_unit_remove_store(struct device *dev,
309 struct device_attribute *attr,
310 const char *buf, size_t count)
311{
Christof Schmitt615f59e2010-02-17 11:18:56 +0100312 struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
Swen Schillig7ba58c92008-10-01 12:42:18 +0200313 u64 fcp_lun;
Swen Schillig60221922008-07-02 10:56:38 +0200314
Swen Schillig6b1833342009-11-24 16:54:05 +0100315 if (strict_strtoull(buf, 0, (unsigned long long *) &fcp_lun))
Christof Schmitt1daa4eb2010-09-08 14:39:52 +0200316 return -EINVAL;
Swen Schillig60221922008-07-02 10:56:38 +0200317
Christof Schmitt1daa4eb2010-09-08 14:39:52 +0200318 if (zfcp_unit_remove(port, fcp_lun))
319 return -EINVAL;
Swen Schillig60221922008-07-02 10:56:38 +0200320
Christof Schmitt1daa4eb2010-09-08 14:39:52 +0200321 return count;
Swen Schillig60221922008-07-02 10:56:38 +0200322}
323static DEVICE_ATTR(unit_remove, S_IWUSR, NULL, zfcp_sysfs_unit_remove_store);
324
Swen Schillig5ab944f2008-10-01 12:42:17 +0200325static struct attribute *zfcp_port_attrs[] = {
Swen Schillig60221922008-07-02 10:56:38 +0200326 &dev_attr_unit_add.attr,
327 &dev_attr_unit_remove.attr,
328 &dev_attr_port_failed.attr,
329 &dev_attr_port_in_recovery.attr,
330 &dev_attr_port_status.attr,
331 &dev_attr_port_access_denied.attr,
332 NULL
333};
334
335/**
336 * zfcp_sysfs_port_attrs - sysfs attributes for all other ports
337 */
338struct attribute_group zfcp_sysfs_port_attrs = {
Swen Schillig5ab944f2008-10-01 12:42:17 +0200339 .attrs = zfcp_port_attrs,
Swen Schillig60221922008-07-02 10:56:38 +0200340};
341
342static struct attribute *zfcp_unit_attrs[] = {
343 &dev_attr_unit_failed.attr,
344 &dev_attr_unit_in_recovery.attr,
345 &dev_attr_unit_status.attr,
346 &dev_attr_unit_access_denied.attr,
347 &dev_attr_unit_access_shared.attr,
348 &dev_attr_unit_access_readonly.attr,
349 NULL
350};
351
352struct attribute_group zfcp_sysfs_unit_attrs = {
353 .attrs = zfcp_unit_attrs,
354};
355
356#define ZFCP_DEFINE_LATENCY_ATTR(_name) \
357static ssize_t \
358zfcp_sysfs_unit_##_name##_latency_show(struct device *dev, \
359 struct device_attribute *attr, \
360 char *buf) { \
361 struct scsi_device *sdev = to_scsi_device(dev); \
Christof Schmittb62a8d92010-09-08 14:39:55 +0200362 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); \
363 struct zfcp_latencies *lat = &zfcp_sdev->latencies; \
364 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter; \
Swen Schillig60221922008-07-02 10:56:38 +0200365 unsigned long long fsum, fmin, fmax, csum, cmin, cmax, cc; \
366 \
Christof Schmitt49f0f012009-03-02 13:08:57 +0100367 spin_lock_bh(&lat->lock); \
Swen Schillig60221922008-07-02 10:56:38 +0200368 fsum = lat->_name.fabric.sum * adapter->timer_ticks; \
369 fmin = lat->_name.fabric.min * adapter->timer_ticks; \
370 fmax = lat->_name.fabric.max * adapter->timer_ticks; \
371 csum = lat->_name.channel.sum * adapter->timer_ticks; \
372 cmin = lat->_name.channel.min * adapter->timer_ticks; \
373 cmax = lat->_name.channel.max * adapter->timer_ticks; \
374 cc = lat->_name.counter; \
Christof Schmitt49f0f012009-03-02 13:08:57 +0100375 spin_unlock_bh(&lat->lock); \
Swen Schillig60221922008-07-02 10:56:38 +0200376 \
377 do_div(fsum, 1000); \
378 do_div(fmin, 1000); \
379 do_div(fmax, 1000); \
380 do_div(csum, 1000); \
381 do_div(cmin, 1000); \
382 do_div(cmax, 1000); \
383 \
384 return sprintf(buf, "%llu %llu %llu %llu %llu %llu %llu\n", \
385 fmin, fmax, fsum, cmin, cmax, csum, cc); \
386} \
387static ssize_t \
388zfcp_sysfs_unit_##_name##_latency_store(struct device *dev, \
389 struct device_attribute *attr, \
390 const char *buf, size_t count) \
391{ \
392 struct scsi_device *sdev = to_scsi_device(dev); \
Christof Schmittb62a8d92010-09-08 14:39:55 +0200393 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); \
394 struct zfcp_latencies *lat = &zfcp_sdev->latencies; \
Swen Schillig60221922008-07-02 10:56:38 +0200395 unsigned long flags; \
396 \
397 spin_lock_irqsave(&lat->lock, flags); \
398 lat->_name.fabric.sum = 0; \
399 lat->_name.fabric.min = 0xFFFFFFFF; \
400 lat->_name.fabric.max = 0; \
401 lat->_name.channel.sum = 0; \
402 lat->_name.channel.min = 0xFFFFFFFF; \
403 lat->_name.channel.max = 0; \
404 lat->_name.counter = 0; \
405 spin_unlock_irqrestore(&lat->lock, flags); \
406 \
407 return (ssize_t) count; \
408} \
409static DEVICE_ATTR(_name##_latency, S_IWUSR | S_IRUGO, \
410 zfcp_sysfs_unit_##_name##_latency_show, \
411 zfcp_sysfs_unit_##_name##_latency_store);
412
413ZFCP_DEFINE_LATENCY_ATTR(read);
414ZFCP_DEFINE_LATENCY_ATTR(write);
415ZFCP_DEFINE_LATENCY_ATTR(cmd);
416
417#define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value) \
418static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, \
419 struct device_attribute *attr,\
420 char *buf) \
421{ \
Christof Schmittb62a8d92010-09-08 14:39:55 +0200422 struct scsi_device *sdev = to_scsi_device(dev); \
423 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); \
424 struct zfcp_port *port = zfcp_sdev->port; \
Swen Schillig60221922008-07-02 10:56:38 +0200425 \
426 return sprintf(buf, _format, _value); \
427} \
428static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL);
429
430ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +0200431 dev_name(&port->adapter->ccw_device->dev));
Swen Schillig7ba58c92008-10-01 12:42:18 +0200432ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n",
Christof Schmittb62a8d92010-09-08 14:39:55 +0200433 (unsigned long long) port->wwpn);
Christof Schmitte4b98572010-09-08 14:39:53 +0200434
435static ssize_t zfcp_sysfs_scsi_fcp_lun_show(struct device *dev,
436 struct device_attribute *attr,
437 char *buf)
438{
439 struct scsi_device *sdev = to_scsi_device(dev);
Christof Schmitte4b98572010-09-08 14:39:53 +0200440
Christof Schmittb62a8d92010-09-08 14:39:55 +0200441 return sprintf(buf, "0x%016llx\n", zfcp_scsi_dev_lun(sdev));
Christof Schmitte4b98572010-09-08 14:39:53 +0200442}
443static DEVICE_ATTR(fcp_lun, S_IRUGO, zfcp_sysfs_scsi_fcp_lun_show, NULL);
Swen Schillig60221922008-07-02 10:56:38 +0200444
445struct device_attribute *zfcp_sysfs_sdev_attrs[] = {
446 &dev_attr_fcp_lun,
447 &dev_attr_wwpn,
448 &dev_attr_hba_id,
449 &dev_attr_read_latency,
450 &dev_attr_write_latency,
451 &dev_attr_cmd_latency,
452 NULL
453};
454
455static ssize_t zfcp_sysfs_adapter_util_show(struct device *dev,
456 struct device_attribute *attr,
457 char *buf)
458{
459 struct Scsi_Host *scsi_host = dev_to_shost(dev);
460 struct fsf_qtcb_bottom_port *qtcb_port;
461 struct zfcp_adapter *adapter;
462 int retval;
463
464 adapter = (struct zfcp_adapter *) scsi_host->hostdata[0];
465 if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA))
466 return -EOPNOTSUPP;
467
468 qtcb_port = kzalloc(sizeof(struct fsf_qtcb_bottom_port), GFP_KERNEL);
469 if (!qtcb_port)
470 return -ENOMEM;
471
Swen Schillig564e1c82009-08-18 15:43:19 +0200472 retval = zfcp_fsf_exchange_port_data_sync(adapter->qdio, qtcb_port);
Swen Schillig60221922008-07-02 10:56:38 +0200473 if (!retval)
474 retval = sprintf(buf, "%u %u %u\n", qtcb_port->cp_util,
475 qtcb_port->cb_util, qtcb_port->a_util);
476 kfree(qtcb_port);
477 return retval;
478}
479static DEVICE_ATTR(utilization, S_IRUGO, zfcp_sysfs_adapter_util_show, NULL);
480
481static int zfcp_sysfs_adapter_ex_config(struct device *dev,
482 struct fsf_statistics_info *stat_inf)
483{
484 struct Scsi_Host *scsi_host = dev_to_shost(dev);
485 struct fsf_qtcb_bottom_config *qtcb_config;
486 struct zfcp_adapter *adapter;
487 int retval;
488
489 adapter = (struct zfcp_adapter *) scsi_host->hostdata[0];
490 if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA))
491 return -EOPNOTSUPP;
492
493 qtcb_config = kzalloc(sizeof(struct fsf_qtcb_bottom_config),
494 GFP_KERNEL);
495 if (!qtcb_config)
496 return -ENOMEM;
497
Swen Schillig564e1c82009-08-18 15:43:19 +0200498 retval = zfcp_fsf_exchange_config_data_sync(adapter->qdio, qtcb_config);
Swen Schillig60221922008-07-02 10:56:38 +0200499 if (!retval)
500 *stat_inf = qtcb_config->stat_info;
501
502 kfree(qtcb_config);
503 return retval;
504}
505
506#define ZFCP_SHOST_ATTR(_name, _format, _arg...) \
507static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, \
508 struct device_attribute *attr,\
509 char *buf) \
510{ \
511 struct fsf_statistics_info stat_info; \
512 int retval; \
513 \
514 retval = zfcp_sysfs_adapter_ex_config(dev, &stat_info); \
515 if (retval) \
516 return retval; \
517 \
518 return sprintf(buf, _format, ## _arg); \
519} \
520static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL);
521
522ZFCP_SHOST_ATTR(requests, "%llu %llu %llu\n",
523 (unsigned long long) stat_info.input_req,
524 (unsigned long long) stat_info.output_req,
525 (unsigned long long) stat_info.control_req);
526
527ZFCP_SHOST_ATTR(megabytes, "%llu %llu\n",
528 (unsigned long long) stat_info.input_mb,
529 (unsigned long long) stat_info.output_mb);
530
531ZFCP_SHOST_ATTR(seconds_active, "%llu\n",
532 (unsigned long long) stat_info.seconds_act);
533
Stefan Raspl2450d3e2008-10-01 12:42:14 +0200534static ssize_t zfcp_sysfs_adapter_q_full_show(struct device *dev,
535 struct device_attribute *attr,
536 char *buf)
537{
538 struct Scsi_Host *scsi_host = class_to_shost(dev);
Swen Schillig564e1c82009-08-18 15:43:19 +0200539 struct zfcp_qdio *qdio =
540 ((struct zfcp_adapter *) scsi_host->hostdata[0])->qdio;
Christof Schmittacf7b862009-07-13 15:06:03 +0200541 u64 util;
542
Swen Schillig564e1c82009-08-18 15:43:19 +0200543 spin_lock_bh(&qdio->stat_lock);
544 util = qdio->req_q_util;
545 spin_unlock_bh(&qdio->stat_lock);
Stefan Raspl2450d3e2008-10-01 12:42:14 +0200546
Swen Schillig564e1c82009-08-18 15:43:19 +0200547 return sprintf(buf, "%d %llu\n", atomic_read(&qdio->req_q_full),
Christof Schmittacf7b862009-07-13 15:06:03 +0200548 (unsigned long long)util);
Stefan Raspl2450d3e2008-10-01 12:42:14 +0200549}
550static DEVICE_ATTR(queue_full, S_IRUGO, zfcp_sysfs_adapter_q_full_show, NULL);
551
Swen Schillig60221922008-07-02 10:56:38 +0200552struct device_attribute *zfcp_sysfs_shost_attrs[] = {
553 &dev_attr_utilization,
554 &dev_attr_requests,
555 &dev_attr_megabytes,
556 &dev_attr_seconds_active,
Stefan Raspl2450d3e2008-10-01 12:42:14 +0200557 &dev_attr_queue_full,
Swen Schillig60221922008-07-02 10:56:38 +0200558 NULL
559};