9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12 #include <linux/slab.h>
15 #define ZFCP_DEV_ATTR(_feat, _name, _mode, _show, _store) \
16 struct device_attribute dev_attr_##_feat##_##_name = __ATTR(_name, _mode,\
18 #define ZFCP_DEFINE_ATTR(_feat_def, _feat, _name, _format, _value) \
19 static ssize_t zfcp_sysfs_##_feat##_##_name##_show(struct device *dev, \
20 struct device_attribute *at,\
23 struct _feat_def *_feat = container_of(dev, struct _feat_def, dev); \
25 return sprintf(buf, _format, _value); \
27 static ZFCP_DEV_ATTR(_feat, _name, S_IRUGO, \
28 zfcp_sysfs_##_feat##_##_name##_show, NULL);
30 #define ZFCP_DEFINE_A_ATTR(_name, _format, _value) \
31 static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, \
32 struct device_attribute *at,\
35 struct ccw_device *cdev = to_ccwdev(dev); \
36 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev); \
42 i = sprintf(buf, _format, _value); \
43 zfcp_ccw_adapter_put(adapter); \
46 static ZFCP_DEV_ATTR(adapter, _name, S_IRUGO, \
47 zfcp_sysfs_adapter_##_name##_show, NULL);
51 (
unsigned long long)
adapter->peer_wwnn);
53 (
unsigned long long)
adapter->peer_wwpn);
97 static ssize_t zfcp_sysfs_port_failed_store(
struct device *dev,
99 const char *buf,
size_t count)
114 zfcp_sysfs_port_failed_show,
115 zfcp_sysfs_port_failed_store);
117 static ssize_t zfcp_sysfs_unit_failed_show(
struct device *dev,
123 unsigned int status, failed = 1;
132 return sprintf(buf,
"%d\n", failed);
135 static ssize_t zfcp_sysfs_unit_failed_store(
struct device *dev,
137 const char *buf,
size_t count)
158 zfcp_sysfs_unit_failed_show,
159 zfcp_sysfs_unit_failed_store);
161 static ssize_t zfcp_sysfs_adapter_failed_show(
struct device *dev,
181 static ssize_t zfcp_sysfs_adapter_failed_store(
struct device *dev,
183 const char *buf,
size_t count)
204 return retval ? retval : (
ssize_t) count;
207 zfcp_sysfs_adapter_failed_show,
208 zfcp_sysfs_adapter_failed_store);
210 static ssize_t zfcp_sysfs_port_rescan_store(
struct device *dev,
212 const char *buf,
size_t count)
228 zfcp_sysfs_port_rescan_store);
232 static ssize_t zfcp_sysfs_port_remove_store(
struct device *dev,
234 const char *buf,
size_t count)
274 return retval ? retval : (
ssize_t) count;
277 zfcp_sysfs_port_remove_store);
279 static struct attribute *zfcp_adapter_attrs[] = {
280 &dev_attr_adapter_failed.attr,
281 &dev_attr_adapter_in_recovery.attr,
282 &dev_attr_adapter_port_remove.attr,
283 &dev_attr_adapter_port_rescan.attr,
284 &dev_attr_adapter_peer_wwnn.attr,
285 &dev_attr_adapter_peer_wwpn.attr,
286 &dev_attr_adapter_peer_d_id.attr,
287 &dev_attr_adapter_card_version.attr,
288 &dev_attr_adapter_lic_version.attr,
289 &dev_attr_adapter_status.attr,
290 &dev_attr_adapter_hardware_version.attr,
295 .attrs = zfcp_adapter_attrs,
300 const char *buf,
size_t count)
317 static ssize_t zfcp_sysfs_unit_remove_store(
struct device *dev,
319 const char *buf,
size_t count)
334 static struct attribute *zfcp_port_attrs[] = {
335 &dev_attr_unit_add.attr,
336 &dev_attr_unit_remove.attr,
337 &dev_attr_port_failed.attr,
338 &dev_attr_port_in_recovery.attr,
339 &dev_attr_port_status.attr,
340 &dev_attr_port_access_denied.attr,
348 .attrs = zfcp_port_attrs,
351 static struct attribute *zfcp_unit_attrs[] = {
352 &dev_attr_unit_failed.attr,
353 &dev_attr_unit_in_recovery.attr,
354 &dev_attr_unit_status.attr,
355 &dev_attr_unit_access_denied.attr,
356 &dev_attr_unit_access_shared.attr,
357 &dev_attr_unit_access_readonly.attr,
362 .attrs = zfcp_unit_attrs,
365 #define ZFCP_DEFINE_LATENCY_ATTR(_name) \
367 zfcp_sysfs_unit_##_name##_latency_show(struct device *dev, \
368 struct device_attribute *attr, \
370 struct scsi_device *sdev = to_scsi_device(dev); \
371 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); \
372 struct zfcp_latencies *lat = &zfcp_sdev->latencies; \
373 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter; \
374 unsigned long long fsum, fmin, fmax, csum, cmin, cmax, cc; \
376 spin_lock_bh(&lat->lock); \
377 fsum = lat->_name.fabric.sum * adapter->timer_ticks; \
378 fmin = lat->_name.fabric.min * adapter->timer_ticks; \
379 fmax = lat->_name.fabric.max * adapter->timer_ticks; \
380 csum = lat->_name.channel.sum * adapter->timer_ticks; \
381 cmin = lat->_name.channel.min * adapter->timer_ticks; \
382 cmax = lat->_name.channel.max * adapter->timer_ticks; \
383 cc = lat->_name.counter; \
384 spin_unlock_bh(&lat->lock); \
386 do_div(fsum, 1000); \
387 do_div(fmin, 1000); \
388 do_div(fmax, 1000); \
389 do_div(csum, 1000); \
390 do_div(cmin, 1000); \
391 do_div(cmax, 1000); \
393 return sprintf(buf, "%llu %llu %llu %llu %llu %llu %llu\n", \
394 fmin, fmax, fsum, cmin, cmax, csum, cc); \
397 zfcp_sysfs_unit_##_name##_latency_store(struct device *dev, \
398 struct device_attribute *attr, \
399 const char *buf, size_t count) \
401 struct scsi_device *sdev = to_scsi_device(dev); \
402 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); \
403 struct zfcp_latencies *lat = &zfcp_sdev->latencies; \
404 unsigned long flags; \
406 spin_lock_irqsave(&lat->lock, flags); \
407 lat->_name.fabric.sum = 0; \
408 lat->_name.fabric.min = 0xFFFFFFFF; \
409 lat->_name.fabric.max = 0; \
410 lat->_name.channel.sum = 0; \
411 lat->_name.channel.min = 0xFFFFFFFF; \
412 lat->_name.channel.max = 0; \
413 lat->_name.counter = 0; \
414 spin_unlock_irqrestore(&lat->lock, flags); \
416 return (ssize_t) count; \
418 static DEVICE_ATTR(_name##_latency, S_IWUSR | S_IRUGO, \
419 zfcp_sysfs_unit_##_name##_latency_show, \
420 zfcp_sysfs_unit_##_name##_latency_store);
426 #define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value) \
427 static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, \
428 struct device_attribute *attr,\
431 struct scsi_device *sdev = to_scsi_device(dev); \
432 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); \
433 struct zfcp_port *port = zfcp_sdev->port; \
435 return sprintf(buf, _format, _value); \
437 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL);
440 dev_name(&port->
adapter->ccw_device->dev));
442 (
unsigned long long) port->
wwpn);
444 static ssize_t zfcp_sysfs_scsi_fcp_lun_show(
struct device *dev,
450 return sprintf(buf,
"0x%016llx\n", zfcp_scsi_dev_lun(sdev));
458 &dev_attr_read_latency,
459 &dev_attr_write_latency,
460 &dev_attr_cmd_latency,
464 static ssize_t zfcp_sysfs_adapter_util_show(
struct device *dev,
468 struct Scsi_Host *scsi_host = dev_to_shost(dev);
473 adapter = (
struct zfcp_adapter *) scsi_host->hostdata[0];
490 static int zfcp_sysfs_adapter_ex_config(
struct device *dev,
493 struct Scsi_Host *scsi_host = dev_to_shost(dev);
498 adapter = (
struct zfcp_adapter *) scsi_host->hostdata[0];
515 #define ZFCP_SHOST_ATTR(_name, _format, _arg...) \
516 static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, \
517 struct device_attribute *attr,\
520 struct fsf_statistics_info stat_info; \
523 retval = zfcp_sysfs_adapter_ex_config(dev, &stat_info); \
527 return sprintf(buf, _format, ## _arg); \
529 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL);
532 (
unsigned long long)
stat_info.input_req,
533 (
unsigned long long)
stat_info.output_req,
534 (
unsigned long long)
stat_info.control_req);
538 (
unsigned long long)
stat_info.output_mb);
541 (
unsigned long long)
stat_info.seconds_act);
543 static ssize_t zfcp_sysfs_adapter_q_full_show(
struct device *dev,
557 (
unsigned long long)util);
562 &dev_attr_utilization,
565 &dev_attr_seconds_active,
566 &dev_attr_queue_full,