1 // SPDX-License-Identifier: GPL-2.0
7 * Copyright IBM Corp. 2008, 2020
10 #define KMSG_COMPONENT "zfcp"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
13 #include <linux/slab.h>
14 #include "zfcp_diag.h"
17 #define ZFCP_DEV_ATTR(_feat, _name, _mode, _show, _store) \
18 struct device_attribute dev_attr_##_feat##_##_name = __ATTR(_name, _mode,\
20 #define ZFCP_DEFINE_ATTR(_feat_def, _feat, _name, _format, _value) \
21 static ssize_t zfcp_sysfs_##_feat##_##_name##_show(struct device *dev, \
22 struct device_attribute *at,\
25 struct _feat_def *_feat = container_of(dev, struct _feat_def, dev); \
27 return sysfs_emit(buf, _format, _value); \
29 static ZFCP_DEV_ATTR(_feat, _name, S_IRUGO, \
30 zfcp_sysfs_##_feat##_##_name##_show, NULL);
32 #define ZFCP_DEFINE_ATTR_CONST(_feat, _name, _format, _value) \
33 static ssize_t zfcp_sysfs_##_feat##_##_name##_show(struct device *dev, \
34 struct device_attribute *at,\
37 return sysfs_emit(buf, _format, _value); \
39 static ZFCP_DEV_ATTR(_feat, _name, S_IRUGO, \
40 zfcp_sysfs_##_feat##_##_name##_show, NULL);
42 #define ZFCP_DEFINE_A_ATTR(_name, _format, _value) \
43 static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, \
44 struct device_attribute *at,\
47 struct ccw_device *cdev = to_ccwdev(dev); \
48 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev); \
54 i = sysfs_emit(buf, _format, _value); \
55 zfcp_ccw_adapter_put(adapter); \
58 static ZFCP_DEV_ATTR(adapter, _name, S_IRUGO, \
59 zfcp_sysfs_adapter_##_name##_show, NULL);
61 ZFCP_DEFINE_A_ATTR(status
, "0x%08x\n", atomic_read(&adapter
->status
));
62 ZFCP_DEFINE_A_ATTR(peer_wwnn
, "0x%016llx\n",
63 (unsigned long long) adapter
->peer_wwnn
);
64 ZFCP_DEFINE_A_ATTR(peer_wwpn
, "0x%016llx\n",
65 (unsigned long long) adapter
->peer_wwpn
);
66 ZFCP_DEFINE_A_ATTR(peer_d_id
, "0x%06x\n", adapter
->peer_d_id
);
67 ZFCP_DEFINE_A_ATTR(card_version
, "0x%04x\n", adapter
->hydra_version
);
68 ZFCP_DEFINE_A_ATTR(lic_version
, "0x%08x\n", adapter
->fsf_lic_version
);
69 ZFCP_DEFINE_A_ATTR(hardware_version
, "0x%08x\n", adapter
->hardware_version
);
70 ZFCP_DEFINE_A_ATTR(in_recovery
, "%d\n", (atomic_read(&adapter
->status
) &
71 ZFCP_STATUS_COMMON_ERP_INUSE
) != 0);
73 ZFCP_DEFINE_ATTR(zfcp_port
, port
, status
, "0x%08x\n",
74 atomic_read(&port
->status
));
75 ZFCP_DEFINE_ATTR(zfcp_port
, port
, in_recovery
, "%d\n",
76 (atomic_read(&port
->status
) &
77 ZFCP_STATUS_COMMON_ERP_INUSE
) != 0);
78 ZFCP_DEFINE_ATTR_CONST(port
, access_denied
, "%d\n", 0);
80 ZFCP_DEFINE_ATTR(zfcp_unit
, unit
, status
, "0x%08x\n",
81 zfcp_unit_sdev_status(unit
));
82 ZFCP_DEFINE_ATTR(zfcp_unit
, unit
, in_recovery
, "%d\n",
83 (zfcp_unit_sdev_status(unit
) &
84 ZFCP_STATUS_COMMON_ERP_INUSE
) != 0);
85 ZFCP_DEFINE_ATTR(zfcp_unit
, unit
, access_denied
, "%d\n",
86 (zfcp_unit_sdev_status(unit
) &
87 ZFCP_STATUS_COMMON_ACCESS_DENIED
) != 0);
88 ZFCP_DEFINE_ATTR_CONST(unit
, access_shared
, "%d\n", 0);
89 ZFCP_DEFINE_ATTR_CONST(unit
, access_readonly
, "%d\n", 0);
91 static ssize_t
zfcp_sysfs_port_failed_show(struct device
*dev
,
92 struct device_attribute
*attr
,
95 struct zfcp_port
*port
= container_of(dev
, struct zfcp_port
, dev
);
97 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
)
98 return sysfs_emit(buf
, "1\n");
100 return sysfs_emit(buf
, "0\n");
103 static ssize_t
zfcp_sysfs_port_failed_store(struct device
*dev
,
104 struct device_attribute
*attr
,
105 const char *buf
, size_t count
)
107 struct zfcp_port
*port
= container_of(dev
, struct zfcp_port
, dev
);
110 if (kstrtoul(buf
, 0, &val
) || val
!= 0)
113 zfcp_erp_set_port_status(port
, ZFCP_STATUS_COMMON_RUNNING
);
114 zfcp_erp_port_reopen(port
, ZFCP_STATUS_COMMON_ERP_FAILED
, "sypfai2");
115 zfcp_erp_wait(port
->adapter
);
119 static ZFCP_DEV_ATTR(port
, failed
, S_IWUSR
| S_IRUGO
,
120 zfcp_sysfs_port_failed_show
,
121 zfcp_sysfs_port_failed_store
);
123 static ssize_t
zfcp_sysfs_unit_failed_show(struct device
*dev
,
124 struct device_attribute
*attr
,
127 struct zfcp_unit
*unit
= container_of(dev
, struct zfcp_unit
, dev
);
128 struct scsi_device
*sdev
;
129 unsigned int status
, failed
= 1;
131 sdev
= zfcp_unit_sdev(unit
);
133 status
= atomic_read(&sdev_to_zfcp(sdev
)->status
);
134 failed
= status
& ZFCP_STATUS_COMMON_ERP_FAILED
? 1 : 0;
135 scsi_device_put(sdev
);
138 return sysfs_emit(buf
, "%d\n", failed
);
141 static ssize_t
zfcp_sysfs_unit_failed_store(struct device
*dev
,
142 struct device_attribute
*attr
,
143 const char *buf
, size_t count
)
145 struct zfcp_unit
*unit
= container_of(dev
, struct zfcp_unit
, dev
);
147 struct scsi_device
*sdev
;
149 if (kstrtoul(buf
, 0, &val
) || val
!= 0)
152 sdev
= zfcp_unit_sdev(unit
);
154 zfcp_erp_set_lun_status(sdev
, ZFCP_STATUS_COMMON_RUNNING
);
155 zfcp_erp_lun_reopen(sdev
, ZFCP_STATUS_COMMON_ERP_FAILED
,
157 zfcp_erp_wait(unit
->port
->adapter
);
159 zfcp_unit_scsi_scan(unit
);
163 static ZFCP_DEV_ATTR(unit
, failed
, S_IWUSR
| S_IRUGO
,
164 zfcp_sysfs_unit_failed_show
,
165 zfcp_sysfs_unit_failed_store
);
167 static ssize_t
zfcp_sysfs_adapter_failed_show(struct device
*dev
,
168 struct device_attribute
*attr
,
171 struct ccw_device
*cdev
= to_ccwdev(dev
);
172 struct zfcp_adapter
*adapter
= zfcp_ccw_adapter_by_cdev(cdev
);
178 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_ERP_FAILED
)
179 i
= sysfs_emit(buf
, "1\n");
181 i
= sysfs_emit(buf
, "0\n");
183 zfcp_ccw_adapter_put(adapter
);
187 static ssize_t
zfcp_sysfs_adapter_failed_store(struct device
*dev
,
188 struct device_attribute
*attr
,
189 const char *buf
, size_t count
)
191 struct ccw_device
*cdev
= to_ccwdev(dev
);
192 struct zfcp_adapter
*adapter
= zfcp_ccw_adapter_by_cdev(cdev
);
199 if (kstrtoul(buf
, 0, &val
) || val
!= 0) {
204 zfcp_erp_adapter_reset_sync(adapter
, "syafai2");
206 zfcp_ccw_adapter_put(adapter
);
207 return retval
? retval
: (ssize_t
) count
;
209 static ZFCP_DEV_ATTR(adapter
, failed
, S_IWUSR
| S_IRUGO
,
210 zfcp_sysfs_adapter_failed_show
,
211 zfcp_sysfs_adapter_failed_store
);
213 static ssize_t
zfcp_sysfs_port_rescan_store(struct device
*dev
,
214 struct device_attribute
*attr
,
215 const char *buf
, size_t count
)
217 struct ccw_device
*cdev
= to_ccwdev(dev
);
218 struct zfcp_adapter
*adapter
= zfcp_ccw_adapter_by_cdev(cdev
);
225 * If `scsi_host` is missing, we can't schedule `scan_work`, as it
226 * makes use of the corresponding fc_host object. But this state is
227 * only possible if xconfig/xport data has never completed yet,
228 * and we couldn't successfully scan for ports anyway.
230 if (adapter
->scsi_host
== NULL
) {
236 * Users wish is our command: immediately schedule and flush a
237 * worker to conduct a synchronous port scan, that is, neither
238 * a random delay nor a rate limit is applied here.
240 queue_delayed_work(adapter
->work_queue
, &adapter
->scan_work
, 0);
241 flush_delayed_work(&adapter
->scan_work
);
243 zfcp_ccw_adapter_put(adapter
);
244 return retval
? retval
: (ssize_t
) count
;
246 static ZFCP_DEV_ATTR(adapter
, port_rescan
, S_IWUSR
, NULL
,
247 zfcp_sysfs_port_rescan_store
);
249 DEFINE_MUTEX(zfcp_sysfs_port_units_mutex
);
251 static void zfcp_sysfs_port_set_removing(struct zfcp_port
*const port
)
253 lockdep_assert_held(&zfcp_sysfs_port_units_mutex
);
254 atomic_set(&port
->units
, -1);
257 bool zfcp_sysfs_port_is_removing(const struct zfcp_port
*const port
)
259 lockdep_assert_held(&zfcp_sysfs_port_units_mutex
);
260 return atomic_read(&port
->units
) == -1;
263 static bool zfcp_sysfs_port_in_use(struct zfcp_port
*const port
)
265 struct zfcp_adapter
*const adapter
= port
->adapter
;
267 struct scsi_device
*sdev
;
270 mutex_lock(&zfcp_sysfs_port_units_mutex
);
271 if (atomic_read(&port
->units
) > 0)
272 goto unlock_port_units_mutex
; /* zfcp_unit(s) under port */
274 spin_lock_irqsave(adapter
->scsi_host
->host_lock
, flags
);
275 __shost_for_each_device(sdev
, adapter
->scsi_host
) {
276 const struct zfcp_scsi_dev
*zsdev
= sdev_to_zfcp(sdev
);
278 if (sdev
->sdev_state
== SDEV_DEL
||
279 sdev
->sdev_state
== SDEV_CANCEL
)
281 if (zsdev
->port
!= port
)
283 /* alive scsi_device under port of interest */
284 goto unlock_host_lock
;
287 /* port is about to be removed, so no more unit_add or slave_alloc */
288 zfcp_sysfs_port_set_removing(port
);
292 spin_unlock_irqrestore(adapter
->scsi_host
->host_lock
, flags
);
293 unlock_port_units_mutex
:
294 mutex_unlock(&zfcp_sysfs_port_units_mutex
);
298 static ssize_t
zfcp_sysfs_port_remove_store(struct device
*dev
,
299 struct device_attribute
*attr
,
300 const char *buf
, size_t count
)
302 struct ccw_device
*cdev
= to_ccwdev(dev
);
303 struct zfcp_adapter
*adapter
= zfcp_ccw_adapter_by_cdev(cdev
);
304 struct zfcp_port
*port
;
306 int retval
= -EINVAL
;
311 if (kstrtoull(buf
, 0, (unsigned long long *) &wwpn
))
314 port
= zfcp_get_port_by_wwpn(adapter
, wwpn
);
320 if (zfcp_sysfs_port_in_use(port
)) {
322 put_device(&port
->dev
); /* undo zfcp_get_port_by_wwpn() */
326 write_lock_irq(&adapter
->port_list_lock
);
327 list_del(&port
->list
);
328 write_unlock_irq(&adapter
->port_list_lock
);
330 zfcp_erp_port_shutdown(port
, 0, "syprs_1");
331 device_unregister(&port
->dev
);
333 put_device(&port
->dev
); /* undo zfcp_get_port_by_wwpn() */
335 zfcp_ccw_adapter_put(adapter
);
336 return retval
? retval
: (ssize_t
) count
;
338 static ZFCP_DEV_ATTR(adapter
, port_remove
, S_IWUSR
, NULL
,
339 zfcp_sysfs_port_remove_store
);
342 zfcp_sysfs_adapter_diag_max_age_show(struct device
*dev
,
343 struct device_attribute
*attr
, char *buf
)
345 struct zfcp_adapter
*adapter
= zfcp_ccw_adapter_by_cdev(to_ccwdev(dev
));
351 rc
= sysfs_emit(buf
, "%lu\n", adapter
->diagnostics
->max_age
);
353 zfcp_ccw_adapter_put(adapter
);
358 zfcp_sysfs_adapter_diag_max_age_store(struct device
*dev
,
359 struct device_attribute
*attr
,
360 const char *buf
, size_t count
)
362 struct zfcp_adapter
*adapter
= zfcp_ccw_adapter_by_cdev(to_ccwdev(dev
));
363 unsigned long max_age
;
369 rc
= kstrtoul(buf
, 10, &max_age
);
373 adapter
->diagnostics
->max_age
= max_age
;
377 zfcp_ccw_adapter_put(adapter
);
380 static ZFCP_DEV_ATTR(adapter
, diag_max_age
, 0644,
381 zfcp_sysfs_adapter_diag_max_age_show
,
382 zfcp_sysfs_adapter_diag_max_age_store
);
384 static ssize_t
zfcp_sysfs_adapter_fc_security_show(
385 struct device
*dev
, struct device_attribute
*attr
, char *buf
)
387 struct ccw_device
*cdev
= to_ccwdev(dev
);
388 struct zfcp_adapter
*adapter
= zfcp_ccw_adapter_by_cdev(cdev
);
396 * Adapter status COMMON_OPEN implies xconf data and xport data
397 * was done. Adapter FC Endpoint Security capability remains
398 * unchanged in case of COMMON_ERP_FAILED (e.g. due to local link
401 status
= atomic_read(&adapter
->status
);
402 if (0 == (status
& ZFCP_STATUS_COMMON_OPEN
))
403 i
= sysfs_emit(buf
, "unknown\n");
404 else if (!(adapter
->adapter_features
& FSF_FEATURE_FC_SECURITY
))
405 i
= sysfs_emit(buf
, "unsupported\n");
407 i
= zfcp_fsf_scnprint_fc_security(
408 buf
, PAGE_SIZE
- 1, adapter
->fc_security_algorithms
,
409 ZFCP_FSF_PRINT_FMT_LIST
);
410 i
+= sysfs_emit_at(buf
, i
, "\n");
413 zfcp_ccw_adapter_put(adapter
);
416 static ZFCP_DEV_ATTR(adapter
, fc_security
, S_IRUGO
,
417 zfcp_sysfs_adapter_fc_security_show
,
420 static struct attribute
*zfcp_adapter_attrs
[] = {
421 &dev_attr_adapter_failed
.attr
,
422 &dev_attr_adapter_in_recovery
.attr
,
423 &dev_attr_adapter_port_remove
.attr
,
424 &dev_attr_adapter_port_rescan
.attr
,
425 &dev_attr_adapter_peer_wwnn
.attr
,
426 &dev_attr_adapter_peer_wwpn
.attr
,
427 &dev_attr_adapter_peer_d_id
.attr
,
428 &dev_attr_adapter_card_version
.attr
,
429 &dev_attr_adapter_lic_version
.attr
,
430 &dev_attr_adapter_status
.attr
,
431 &dev_attr_adapter_hardware_version
.attr
,
432 &dev_attr_adapter_diag_max_age
.attr
,
433 &dev_attr_adapter_fc_security
.attr
,
437 static const struct attribute_group zfcp_sysfs_adapter_attr_group
= {
438 .attrs
= zfcp_adapter_attrs
,
441 static ssize_t
zfcp_sysfs_unit_add_store(struct device
*dev
,
442 struct device_attribute
*attr
,
443 const char *buf
, size_t count
)
445 struct zfcp_port
*port
= container_of(dev
, struct zfcp_port
, dev
);
449 if (kstrtoull(buf
, 0, (unsigned long long *) &fcp_lun
))
452 retval
= zfcp_unit_add(port
, fcp_lun
);
458 static DEVICE_ATTR(unit_add
, S_IWUSR
, NULL
, zfcp_sysfs_unit_add_store
);
460 static ssize_t
zfcp_sysfs_unit_remove_store(struct device
*dev
,
461 struct device_attribute
*attr
,
462 const char *buf
, size_t count
)
464 struct zfcp_port
*port
= container_of(dev
, struct zfcp_port
, dev
);
467 if (kstrtoull(buf
, 0, (unsigned long long *) &fcp_lun
))
470 if (zfcp_unit_remove(port
, fcp_lun
))
475 static DEVICE_ATTR(unit_remove
, S_IWUSR
, NULL
, zfcp_sysfs_unit_remove_store
);
477 static ssize_t
zfcp_sysfs_port_fc_security_show(struct device
*dev
,
478 struct device_attribute
*attr
,
481 struct zfcp_port
*port
= container_of(dev
, struct zfcp_port
, dev
);
482 struct zfcp_adapter
*adapter
= port
->adapter
;
483 unsigned int status
= atomic_read(&port
->status
);
486 if (0 == (status
& ZFCP_STATUS_COMMON_OPEN
) ||
487 0 == (status
& ZFCP_STATUS_COMMON_UNBLOCKED
) ||
488 0 == (status
& ZFCP_STATUS_PORT_PHYS_OPEN
) ||
489 0 != (status
& ZFCP_STATUS_PORT_LINK_TEST
) ||
490 0 != (status
& ZFCP_STATUS_COMMON_ERP_FAILED
) ||
491 0 != (status
& ZFCP_STATUS_COMMON_ACCESS_BOXED
))
492 i
= sysfs_emit(buf
, "unknown\n");
493 else if (!(adapter
->adapter_features
& FSF_FEATURE_FC_SECURITY
))
494 i
= sysfs_emit(buf
, "unsupported\n");
496 i
= zfcp_fsf_scnprint_fc_security(
497 buf
, PAGE_SIZE
- 1, port
->connection_info
,
498 ZFCP_FSF_PRINT_FMT_SINGLEITEM
);
499 i
+= sysfs_emit_at(buf
, i
, "\n");
504 static ZFCP_DEV_ATTR(port
, fc_security
, S_IRUGO
,
505 zfcp_sysfs_port_fc_security_show
,
508 static struct attribute
*zfcp_port_attrs
[] = {
509 &dev_attr_unit_add
.attr
,
510 &dev_attr_unit_remove
.attr
,
511 &dev_attr_port_failed
.attr
,
512 &dev_attr_port_in_recovery
.attr
,
513 &dev_attr_port_status
.attr
,
514 &dev_attr_port_access_denied
.attr
,
515 &dev_attr_port_fc_security
.attr
,
518 static struct attribute_group zfcp_port_attr_group
= {
519 .attrs
= zfcp_port_attrs
,
521 const struct attribute_group
*zfcp_port_attr_groups
[] = {
522 &zfcp_port_attr_group
,
526 static struct attribute
*zfcp_unit_attrs
[] = {
527 &dev_attr_unit_failed
.attr
,
528 &dev_attr_unit_in_recovery
.attr
,
529 &dev_attr_unit_status
.attr
,
530 &dev_attr_unit_access_denied
.attr
,
531 &dev_attr_unit_access_shared
.attr
,
532 &dev_attr_unit_access_readonly
.attr
,
535 static struct attribute_group zfcp_unit_attr_group
= {
536 .attrs
= zfcp_unit_attrs
,
538 const struct attribute_group
*zfcp_unit_attr_groups
[] = {
539 &zfcp_unit_attr_group
,
543 #define ZFCP_DEFINE_LATENCY_ATTR(_name) \
545 zfcp_sysfs_unit_##_name##_latency_show(struct device *dev, \
546 struct device_attribute *attr, \
548 struct scsi_device *sdev = to_scsi_device(dev); \
549 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); \
550 struct zfcp_latencies *lat = &zfcp_sdev->latencies; \
551 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter; \
552 unsigned long long fsum, fmin, fmax, csum, cmin, cmax, cc; \
554 spin_lock_bh(&lat->lock); \
555 fsum = lat->_name.fabric.sum * adapter->timer_ticks; \
556 fmin = lat->_name.fabric.min * adapter->timer_ticks; \
557 fmax = lat->_name.fabric.max * adapter->timer_ticks; \
558 csum = lat->_name.channel.sum * adapter->timer_ticks; \
559 cmin = lat->_name.channel.min * adapter->timer_ticks; \
560 cmax = lat->_name.channel.max * adapter->timer_ticks; \
561 cc = lat->_name.counter; \
562 spin_unlock_bh(&lat->lock); \
564 do_div(fsum, 1000); \
565 do_div(fmin, 1000); \
566 do_div(fmax, 1000); \
567 do_div(csum, 1000); \
568 do_div(cmin, 1000); \
569 do_div(cmax, 1000); \
571 return sysfs_emit(buf, "%llu %llu %llu %llu %llu %llu %llu\n", \
572 fmin, fmax, fsum, cmin, cmax, csum, cc); \
575 zfcp_sysfs_unit_##_name##_latency_store(struct device *dev, \
576 struct device_attribute *attr, \
577 const char *buf, size_t count) \
579 struct scsi_device *sdev = to_scsi_device(dev); \
580 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); \
581 struct zfcp_latencies *lat = &zfcp_sdev->latencies; \
582 unsigned long flags; \
584 spin_lock_irqsave(&lat->lock, flags); \
585 lat->_name.fabric.sum = 0; \
586 lat->_name.fabric.min = 0xFFFFFFFF; \
587 lat->_name.fabric.max = 0; \
588 lat->_name.channel.sum = 0; \
589 lat->_name.channel.min = 0xFFFFFFFF; \
590 lat->_name.channel.max = 0; \
591 lat->_name.counter = 0; \
592 spin_unlock_irqrestore(&lat->lock, flags); \
594 return (ssize_t) count; \
596 static DEVICE_ATTR(_name##_latency, S_IWUSR | S_IRUGO, \
597 zfcp_sysfs_unit_##_name##_latency_show, \
598 zfcp_sysfs_unit_##_name##_latency_store);
600 ZFCP_DEFINE_LATENCY_ATTR(read
);
601 ZFCP_DEFINE_LATENCY_ATTR(write
);
602 ZFCP_DEFINE_LATENCY_ATTR(cmd
);
604 #define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value) \
605 static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, \
606 struct device_attribute *attr,\
609 struct scsi_device *sdev = to_scsi_device(dev); \
610 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); \
612 return sysfs_emit(buf, _format, _value); \
614 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL);
616 ZFCP_DEFINE_SCSI_ATTR(hba_id
, "%s\n",
617 dev_name(&zfcp_sdev
->port
->adapter
->ccw_device
->dev
));
618 ZFCP_DEFINE_SCSI_ATTR(wwpn
, "0x%016llx\n",
619 (unsigned long long) zfcp_sdev
->port
->wwpn
);
621 static ssize_t
zfcp_sysfs_scsi_fcp_lun_show(struct device
*dev
,
622 struct device_attribute
*attr
,
625 struct scsi_device
*sdev
= to_scsi_device(dev
);
627 return sysfs_emit(buf
, "0x%016llx\n", zfcp_scsi_dev_lun(sdev
));
629 static DEVICE_ATTR(fcp_lun
, S_IRUGO
, zfcp_sysfs_scsi_fcp_lun_show
, NULL
);
631 ZFCP_DEFINE_SCSI_ATTR(zfcp_access_denied
, "%d\n",
632 (atomic_read(&zfcp_sdev
->status
) &
633 ZFCP_STATUS_COMMON_ACCESS_DENIED
) != 0);
635 static ssize_t
zfcp_sysfs_scsi_zfcp_failed_show(struct device
*dev
,
636 struct device_attribute
*attr
,
639 struct scsi_device
*sdev
= to_scsi_device(dev
);
640 unsigned int status
= atomic_read(&sdev_to_zfcp(sdev
)->status
);
641 unsigned int failed
= status
& ZFCP_STATUS_COMMON_ERP_FAILED
? 1 : 0;
643 return sysfs_emit(buf
, "%d\n", failed
);
646 static ssize_t
zfcp_sysfs_scsi_zfcp_failed_store(struct device
*dev
,
647 struct device_attribute
*attr
,
648 const char *buf
, size_t count
)
650 struct scsi_device
*sdev
= to_scsi_device(dev
);
653 if (kstrtoul(buf
, 0, &val
) || val
!= 0)
656 zfcp_erp_set_lun_status(sdev
, ZFCP_STATUS_COMMON_RUNNING
);
657 zfcp_erp_lun_reopen(sdev
, ZFCP_STATUS_COMMON_ERP_FAILED
,
659 zfcp_erp_wait(sdev_to_zfcp(sdev
)->port
->adapter
);
663 static DEVICE_ATTR(zfcp_failed
, S_IWUSR
| S_IRUGO
,
664 zfcp_sysfs_scsi_zfcp_failed_show
,
665 zfcp_sysfs_scsi_zfcp_failed_store
);
667 ZFCP_DEFINE_SCSI_ATTR(zfcp_in_recovery
, "%d\n",
668 (atomic_read(&zfcp_sdev
->status
) &
669 ZFCP_STATUS_COMMON_ERP_INUSE
) != 0);
671 ZFCP_DEFINE_SCSI_ATTR(zfcp_status
, "0x%08x\n",
672 atomic_read(&zfcp_sdev
->status
));
674 static struct attribute
*zfcp_sdev_attrs
[] = {
675 &dev_attr_fcp_lun
.attr
,
677 &dev_attr_hba_id
.attr
,
678 &dev_attr_read_latency
.attr
,
679 &dev_attr_write_latency
.attr
,
680 &dev_attr_cmd_latency
.attr
,
681 &dev_attr_zfcp_access_denied
.attr
,
682 &dev_attr_zfcp_failed
.attr
,
683 &dev_attr_zfcp_in_recovery
.attr
,
684 &dev_attr_zfcp_status
.attr
,
688 static const struct attribute_group zfcp_sysfs_sdev_attr_group
= {
689 .attrs
= zfcp_sdev_attrs
692 const struct attribute_group
*zfcp_sysfs_sdev_attr_groups
[] = {
693 &zfcp_sysfs_sdev_attr_group
,
697 static ssize_t
zfcp_sysfs_adapter_util_show(struct device
*dev
,
698 struct device_attribute
*attr
,
701 struct Scsi_Host
*scsi_host
= dev_to_shost(dev
);
702 struct fsf_qtcb_bottom_port
*qtcb_port
;
703 struct zfcp_adapter
*adapter
;
706 adapter
= (struct zfcp_adapter
*) scsi_host
->hostdata
[0];
707 if (!(adapter
->adapter_features
& FSF_FEATURE_MEASUREMENT_DATA
))
710 qtcb_port
= kzalloc(sizeof(struct fsf_qtcb_bottom_port
), GFP_KERNEL
);
714 retval
= zfcp_fsf_exchange_port_data_sync(adapter
->qdio
, qtcb_port
);
715 if (retval
== 0 || retval
== -EAGAIN
)
716 retval
= sysfs_emit(buf
, "%u %u %u\n", qtcb_port
->cp_util
,
717 qtcb_port
->cb_util
, qtcb_port
->a_util
);
721 static DEVICE_ATTR(utilization
, S_IRUGO
, zfcp_sysfs_adapter_util_show
, NULL
);
723 static int zfcp_sysfs_adapter_ex_config(struct device
*dev
,
724 struct fsf_statistics_info
*stat_inf
)
726 struct Scsi_Host
*scsi_host
= dev_to_shost(dev
);
727 struct fsf_qtcb_bottom_config
*qtcb_config
;
728 struct zfcp_adapter
*adapter
;
731 adapter
= (struct zfcp_adapter
*) scsi_host
->hostdata
[0];
732 if (!(adapter
->adapter_features
& FSF_FEATURE_MEASUREMENT_DATA
))
735 qtcb_config
= kzalloc(sizeof(struct fsf_qtcb_bottom_config
),
740 retval
= zfcp_fsf_exchange_config_data_sync(adapter
->qdio
, qtcb_config
);
741 if (retval
== 0 || retval
== -EAGAIN
)
742 *stat_inf
= qtcb_config
->stat_info
;
748 #define ZFCP_SHOST_ATTR(_name, _format, _arg...) \
749 static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, \
750 struct device_attribute *attr,\
753 struct fsf_statistics_info stat_info; \
756 retval = zfcp_sysfs_adapter_ex_config(dev, &stat_info); \
760 return sysfs_emit(buf, _format, ## _arg); \
762 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL);
764 ZFCP_SHOST_ATTR(requests
, "%llu %llu %llu\n",
765 (unsigned long long) stat_info
.input_req
,
766 (unsigned long long) stat_info
.output_req
,
767 (unsigned long long) stat_info
.control_req
);
769 ZFCP_SHOST_ATTR(megabytes
, "%llu %llu\n",
770 (unsigned long long) stat_info
.input_mb
,
771 (unsigned long long) stat_info
.output_mb
);
773 ZFCP_SHOST_ATTR(seconds_active
, "%llu\n",
774 (unsigned long long) stat_info
.seconds_act
);
776 static ssize_t
zfcp_sysfs_adapter_q_full_show(struct device
*dev
,
777 struct device_attribute
*attr
,
780 struct Scsi_Host
*scsi_host
= class_to_shost(dev
);
781 struct zfcp_qdio
*qdio
=
782 ((struct zfcp_adapter
*) scsi_host
->hostdata
[0])->qdio
;
785 spin_lock_bh(&qdio
->stat_lock
);
786 util
= qdio
->req_q_util
;
787 spin_unlock_bh(&qdio
->stat_lock
);
789 return sysfs_emit(buf
, "%d %llu\n", atomic_read(&qdio
->req_q_full
),
790 (unsigned long long)util
);
792 static DEVICE_ATTR(queue_full
, S_IRUGO
, zfcp_sysfs_adapter_q_full_show
, NULL
);
794 static struct attribute
*zfcp_sysfs_shost_attrs
[] = {
795 &dev_attr_utilization
.attr
,
796 &dev_attr_requests
.attr
,
797 &dev_attr_megabytes
.attr
,
798 &dev_attr_seconds_active
.attr
,
799 &dev_attr_queue_full
.attr
,
803 static const struct attribute_group zfcp_sysfs_shost_attr_group
= {
804 .attrs
= zfcp_sysfs_shost_attrs
807 const struct attribute_group
*zfcp_sysfs_shost_attr_groups
[] = {
808 &zfcp_sysfs_shost_attr_group
,
812 static ssize_t
zfcp_sysfs_adapter_diag_b2b_credit_show(
813 struct device
*dev
, struct device_attribute
*attr
, char *buf
)
815 struct zfcp_adapter
*adapter
= zfcp_ccw_adapter_by_cdev(to_ccwdev(dev
));
816 struct zfcp_diag_header
*diag_hdr
;
817 struct fc_els_flogi
*nsp
;
818 ssize_t rc
= -ENOLINK
;
825 status
= atomic_read(&adapter
->status
);
826 if (0 == (status
& ZFCP_STATUS_COMMON_OPEN
) ||
827 0 == (status
& ZFCP_STATUS_COMMON_UNBLOCKED
) ||
828 0 != (status
& ZFCP_STATUS_COMMON_ERP_FAILED
))
831 diag_hdr
= &adapter
->diagnostics
->config_data
.header
;
833 rc
= zfcp_diag_update_buffer_limited(
834 adapter
, diag_hdr
, zfcp_diag_update_config_data_buffer
);
838 spin_lock_irqsave(&diag_hdr
->access_lock
, flags
);
839 /* nport_serv_param doesn't contain the ELS_Command code */
840 nsp
= (struct fc_els_flogi
*)((unsigned long)
841 adapter
->diagnostics
->config_data
842 .data
.nport_serv_param
-
845 rc
= sysfs_emit(buf
, "%hu\n", be16_to_cpu(nsp
->fl_csp
.sp_bb_cred
));
846 spin_unlock_irqrestore(&diag_hdr
->access_lock
, flags
);
849 zfcp_ccw_adapter_put(adapter
);
852 static ZFCP_DEV_ATTR(adapter_diag
, b2b_credit
, 0400,
853 zfcp_sysfs_adapter_diag_b2b_credit_show
, NULL
);
855 #define ZFCP_DEFINE_DIAG_SFP_ATTR(_name, _qtcb_member, _prtfmt) \
856 static ssize_t zfcp_sysfs_adapter_diag_sfp_##_name##_show( \
857 struct device *dev, struct device_attribute *attr, char *buf) \
859 struct zfcp_adapter *const adapter = \
860 zfcp_ccw_adapter_by_cdev(to_ccwdev(dev)); \
861 struct zfcp_diag_header *diag_hdr; \
862 ssize_t rc = -ENOLINK; \
863 unsigned long flags; \
864 unsigned int status; \
869 status = atomic_read(&adapter->status); \
870 if (0 == (status & ZFCP_STATUS_COMMON_OPEN) || \
871 0 == (status & ZFCP_STATUS_COMMON_UNBLOCKED) || \
872 0 != (status & ZFCP_STATUS_COMMON_ERP_FAILED)) \
875 if (!zfcp_diag_support_sfp(adapter)) { \
880 diag_hdr = &adapter->diagnostics->port_data.header; \
882 rc = zfcp_diag_update_buffer_limited( \
883 adapter, diag_hdr, zfcp_diag_update_port_data_buffer); \
887 spin_lock_irqsave(&diag_hdr->access_lock, flags); \
890 adapter->diagnostics->port_data.data._qtcb_member); \
891 spin_unlock_irqrestore(&diag_hdr->access_lock, flags); \
894 zfcp_ccw_adapter_put(adapter); \
897 static ZFCP_DEV_ATTR(adapter_diag_sfp, _name, 0400, \
898 zfcp_sysfs_adapter_diag_sfp_##_name##_show, NULL)
900 ZFCP_DEFINE_DIAG_SFP_ATTR(temperature
, temperature
, "%hd");
901 ZFCP_DEFINE_DIAG_SFP_ATTR(vcc
, vcc
, "%hu");
902 ZFCP_DEFINE_DIAG_SFP_ATTR(tx_bias
, tx_bias
, "%hu");
903 ZFCP_DEFINE_DIAG_SFP_ATTR(tx_power
, tx_power
, "%hu");
904 ZFCP_DEFINE_DIAG_SFP_ATTR(rx_power
, rx_power
, "%hu");
905 ZFCP_DEFINE_DIAG_SFP_ATTR(port_tx_type
, sfp_flags
.port_tx_type
, "%hu");
906 ZFCP_DEFINE_DIAG_SFP_ATTR(optical_port
, sfp_flags
.optical_port
, "%hu");
907 ZFCP_DEFINE_DIAG_SFP_ATTR(sfp_invalid
, sfp_flags
.sfp_invalid
, "%hu");
908 ZFCP_DEFINE_DIAG_SFP_ATTR(connector_type
, sfp_flags
.connector_type
, "%hu");
909 ZFCP_DEFINE_DIAG_SFP_ATTR(fec_active
, sfp_flags
.fec_active
, "%hu");
911 static struct attribute
*zfcp_sysfs_diag_attrs
[] = {
912 &dev_attr_adapter_diag_sfp_temperature
.attr
,
913 &dev_attr_adapter_diag_sfp_vcc
.attr
,
914 &dev_attr_adapter_diag_sfp_tx_bias
.attr
,
915 &dev_attr_adapter_diag_sfp_tx_power
.attr
,
916 &dev_attr_adapter_diag_sfp_rx_power
.attr
,
917 &dev_attr_adapter_diag_sfp_port_tx_type
.attr
,
918 &dev_attr_adapter_diag_sfp_optical_port
.attr
,
919 &dev_attr_adapter_diag_sfp_sfp_invalid
.attr
,
920 &dev_attr_adapter_diag_sfp_connector_type
.attr
,
921 &dev_attr_adapter_diag_sfp_fec_active
.attr
,
922 &dev_attr_adapter_diag_b2b_credit
.attr
,
926 static const struct attribute_group zfcp_sysfs_diag_attr_group
= {
927 .name
= "diagnostics",
928 .attrs
= zfcp_sysfs_diag_attrs
,
931 const struct attribute_group
*zfcp_sysfs_adapter_attr_groups
[] = {
932 &zfcp_sysfs_adapter_attr_group
,
933 &zfcp_sysfs_diag_attr_group
,