6 * Copyright IBM Corporation 2008
9 #define KMSG_COMPONENT "zfcp"
10 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
14 #define ZFCP_DEV_ATTR(_feat, _name, _mode, _show, _store) \
15 struct device_attribute dev_attr_##_feat##_##_name = __ATTR(_name, _mode,\
17 #define ZFCP_DEFINE_ATTR(_feat_def, _feat, _name, _format, _value) \
18 static ssize_t zfcp_sysfs_##_feat##_##_name##_show(struct device *dev, \
19 struct device_attribute *at,\
22 struct _feat_def *_feat = dev_get_drvdata(dev); \
24 return sprintf(buf, _format, _value); \
26 static ZFCP_DEV_ATTR(_feat, _name, S_IRUGO, \
27 zfcp_sysfs_##_feat##_##_name##_show, NULL);
29 ZFCP_DEFINE_ATTR(zfcp_adapter
, adapter
, status
, "0x%08x\n",
30 atomic_read(&adapter
->status
));
31 ZFCP_DEFINE_ATTR(zfcp_adapter
, adapter
, peer_wwnn
, "0x%016llx\n",
32 (unsigned long long) adapter
->peer_wwnn
);
33 ZFCP_DEFINE_ATTR(zfcp_adapter
, adapter
, peer_wwpn
, "0x%016llx\n",
34 (unsigned long long) adapter
->peer_wwpn
);
35 ZFCP_DEFINE_ATTR(zfcp_adapter
, adapter
, peer_d_id
, "0x%06x\n",
37 ZFCP_DEFINE_ATTR(zfcp_adapter
, adapter
, card_version
, "0x%04x\n",
38 adapter
->hydra_version
);
39 ZFCP_DEFINE_ATTR(zfcp_adapter
, adapter
, lic_version
, "0x%08x\n",
40 adapter
->fsf_lic_version
);
41 ZFCP_DEFINE_ATTR(zfcp_adapter
, adapter
, hardware_version
, "0x%08x\n",
42 adapter
->hardware_version
);
43 ZFCP_DEFINE_ATTR(zfcp_adapter
, adapter
, in_recovery
, "%d\n",
44 (atomic_read(&adapter
->status
) &
45 ZFCP_STATUS_COMMON_ERP_INUSE
) != 0);
47 ZFCP_DEFINE_ATTR(zfcp_port
, port
, status
, "0x%08x\n",
48 atomic_read(&port
->status
));
49 ZFCP_DEFINE_ATTR(zfcp_port
, port
, in_recovery
, "%d\n",
50 (atomic_read(&port
->status
) &
51 ZFCP_STATUS_COMMON_ERP_INUSE
) != 0);
52 ZFCP_DEFINE_ATTR(zfcp_port
, port
, access_denied
, "%d\n",
53 (atomic_read(&port
->status
) &
54 ZFCP_STATUS_COMMON_ACCESS_DENIED
) != 0);
56 ZFCP_DEFINE_ATTR(zfcp_unit
, unit
, status
, "0x%08x\n",
57 atomic_read(&unit
->status
));
58 ZFCP_DEFINE_ATTR(zfcp_unit
, unit
, in_recovery
, "%d\n",
59 (atomic_read(&unit
->status
) &
60 ZFCP_STATUS_COMMON_ERP_INUSE
) != 0);
61 ZFCP_DEFINE_ATTR(zfcp_unit
, unit
, access_denied
, "%d\n",
62 (atomic_read(&unit
->status
) &
63 ZFCP_STATUS_COMMON_ACCESS_DENIED
) != 0);
64 ZFCP_DEFINE_ATTR(zfcp_unit
, unit
, access_shared
, "%d\n",
65 (atomic_read(&unit
->status
) &
66 ZFCP_STATUS_UNIT_SHARED
) != 0);
67 ZFCP_DEFINE_ATTR(zfcp_unit
, unit
, access_readonly
, "%d\n",
68 (atomic_read(&unit
->status
) &
69 ZFCP_STATUS_UNIT_READONLY
) != 0);
71 #define ZFCP_SYSFS_FAILED(_feat_def, _feat, _adapter, _mod_id, _reopen_id) \
72 static ssize_t zfcp_sysfs_##_feat##_failed_show(struct device *dev, \
73 struct device_attribute *attr, \
76 struct _feat_def *_feat = dev_get_drvdata(dev); \
78 if (atomic_read(&_feat->status) & ZFCP_STATUS_COMMON_ERP_FAILED) \
79 return sprintf(buf, "1\n"); \
81 return sprintf(buf, "0\n"); \
83 static ssize_t zfcp_sysfs_##_feat##_failed_store(struct device *dev, \
84 struct device_attribute *attr,\
85 const char *buf, size_t count)\
87 struct _feat_def *_feat = dev_get_drvdata(dev); \
91 mutex_lock(&zfcp_data.config_mutex); \
92 if (atomic_read(&_feat->status) & ZFCP_STATUS_COMMON_REMOVE) { \
97 if (strict_strtoul(buf, 0, &val) || val != 0) { \
102 zfcp_erp_modify_##_feat##_status(_feat, _mod_id, NULL, \
103 ZFCP_STATUS_COMMON_RUNNING, ZFCP_SET);\
104 zfcp_erp_##_feat##_reopen(_feat, ZFCP_STATUS_COMMON_ERP_FAILED, \
106 zfcp_erp_wait(_adapter); \
108 mutex_unlock(&zfcp_data.config_mutex); \
109 return retval ? retval : (ssize_t) count; \
111 static ZFCP_DEV_ATTR(_feat, failed, S_IWUSR | S_IRUGO, \
112 zfcp_sysfs_##_feat##_failed_show, \
113 zfcp_sysfs_##_feat##_failed_store);
115 ZFCP_SYSFS_FAILED(zfcp_adapter
, adapter
, adapter
, "syafai1", "syafai2");
116 ZFCP_SYSFS_FAILED(zfcp_port
, port
, port
->adapter
, "sypfai1", "sypfai2");
117 ZFCP_SYSFS_FAILED(zfcp_unit
, unit
, unit
->port
->adapter
, "syufai1", "syufai2");
119 static ssize_t
zfcp_sysfs_port_rescan_store(struct device
*dev
,
120 struct device_attribute
*attr
,
121 const char *buf
, size_t count
)
123 struct zfcp_adapter
*adapter
= dev_get_drvdata(dev
);
126 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_REMOVE
)
129 ret
= zfcp_fc_scan_ports(adapter
);
130 return ret
? ret
: (ssize_t
) count
;
132 static ZFCP_DEV_ATTR(adapter
, port_rescan
, S_IWUSR
, NULL
,
133 zfcp_sysfs_port_rescan_store
);
135 static ssize_t
zfcp_sysfs_port_remove_store(struct device
*dev
,
136 struct device_attribute
*attr
,
137 const char *buf
, size_t count
)
139 struct zfcp_adapter
*adapter
= dev_get_drvdata(dev
);
140 struct zfcp_port
*port
;
143 LIST_HEAD(port_remove_lh
);
145 mutex_lock(&zfcp_data
.config_mutex
);
146 if (atomic_read(&adapter
->status
) & ZFCP_STATUS_COMMON_REMOVE
) {
151 if (strict_strtoull(buf
, 0, (unsigned long long *) &wwpn
)) {
156 write_lock_irq(&zfcp_data
.config_lock
);
157 port
= zfcp_get_port_by_wwpn(adapter
, wwpn
);
158 if (port
&& (atomic_read(&port
->refcount
) == 0)) {
160 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
, &port
->status
);
161 list_move(&port
->list
, &port_remove_lh
);
164 write_unlock_irq(&zfcp_data
.config_lock
);
171 zfcp_erp_port_shutdown(port
, 0, "syprs_1", NULL
);
172 zfcp_erp_wait(adapter
);
174 zfcp_port_dequeue(port
);
176 mutex_unlock(&zfcp_data
.config_mutex
);
177 return retval
? retval
: (ssize_t
) count
;
179 static ZFCP_DEV_ATTR(adapter
, port_remove
, S_IWUSR
, NULL
,
180 zfcp_sysfs_port_remove_store
);
182 static struct attribute
*zfcp_adapter_attrs
[] = {
183 &dev_attr_adapter_failed
.attr
,
184 &dev_attr_adapter_in_recovery
.attr
,
185 &dev_attr_adapter_port_remove
.attr
,
186 &dev_attr_adapter_port_rescan
.attr
,
187 &dev_attr_adapter_peer_wwnn
.attr
,
188 &dev_attr_adapter_peer_wwpn
.attr
,
189 &dev_attr_adapter_peer_d_id
.attr
,
190 &dev_attr_adapter_card_version
.attr
,
191 &dev_attr_adapter_lic_version
.attr
,
192 &dev_attr_adapter_status
.attr
,
193 &dev_attr_adapter_hardware_version
.attr
,
197 struct attribute_group zfcp_sysfs_adapter_attrs
= {
198 .attrs
= zfcp_adapter_attrs
,
201 static ssize_t
zfcp_sysfs_unit_add_store(struct device
*dev
,
202 struct device_attribute
*attr
,
203 const char *buf
, size_t count
)
205 struct zfcp_port
*port
= dev_get_drvdata(dev
);
206 struct zfcp_unit
*unit
;
208 int retval
= -EINVAL
;
210 mutex_lock(&zfcp_data
.config_mutex
);
211 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_REMOVE
) {
216 if (strict_strtoull(buf
, 0, (unsigned long long *) &fcp_lun
))
219 unit
= zfcp_unit_enqueue(port
, fcp_lun
);
225 zfcp_erp_unit_reopen(unit
, 0, "syuas_1", NULL
);
226 zfcp_erp_wait(unit
->port
->adapter
);
229 mutex_unlock(&zfcp_data
.config_mutex
);
230 return retval
? retval
: (ssize_t
) count
;
232 static DEVICE_ATTR(unit_add
, S_IWUSR
, NULL
, zfcp_sysfs_unit_add_store
);
234 static ssize_t
zfcp_sysfs_unit_remove_store(struct device
*dev
,
235 struct device_attribute
*attr
,
236 const char *buf
, size_t count
)
238 struct zfcp_port
*port
= dev_get_drvdata(dev
);
239 struct zfcp_unit
*unit
;
242 LIST_HEAD(unit_remove_lh
);
244 mutex_lock(&zfcp_data
.config_mutex
);
245 if (atomic_read(&port
->status
) & ZFCP_STATUS_COMMON_REMOVE
) {
250 if (strict_strtoull(buf
, 0, (unsigned long long *) &fcp_lun
)) {
255 write_lock_irq(&zfcp_data
.config_lock
);
256 unit
= zfcp_get_unit_by_lun(port
, fcp_lun
);
258 write_unlock_irq(&zfcp_data
.config_lock
);
259 /* wait for possible timeout during SCSI probe */
260 flush_work(&unit
->scsi_work
);
261 write_lock_irq(&zfcp_data
.config_lock
);
263 if (atomic_read(&unit
->refcount
) == 0) {
265 atomic_set_mask(ZFCP_STATUS_COMMON_REMOVE
,
267 list_move(&unit
->list
, &unit_remove_lh
);
273 write_unlock_irq(&zfcp_data
.config_lock
);
280 zfcp_erp_unit_shutdown(unit
, 0, "syurs_1", NULL
);
281 zfcp_erp_wait(unit
->port
->adapter
);
283 zfcp_unit_dequeue(unit
);
285 mutex_unlock(&zfcp_data
.config_mutex
);
286 return retval
? retval
: (ssize_t
) count
;
288 static DEVICE_ATTR(unit_remove
, S_IWUSR
, NULL
, zfcp_sysfs_unit_remove_store
);
290 static struct attribute
*zfcp_port_attrs
[] = {
291 &dev_attr_unit_add
.attr
,
292 &dev_attr_unit_remove
.attr
,
293 &dev_attr_port_failed
.attr
,
294 &dev_attr_port_in_recovery
.attr
,
295 &dev_attr_port_status
.attr
,
296 &dev_attr_port_access_denied
.attr
,
301 * zfcp_sysfs_port_attrs - sysfs attributes for all other ports
303 struct attribute_group zfcp_sysfs_port_attrs
= {
304 .attrs
= zfcp_port_attrs
,
307 static struct attribute
*zfcp_unit_attrs
[] = {
308 &dev_attr_unit_failed
.attr
,
309 &dev_attr_unit_in_recovery
.attr
,
310 &dev_attr_unit_status
.attr
,
311 &dev_attr_unit_access_denied
.attr
,
312 &dev_attr_unit_access_shared
.attr
,
313 &dev_attr_unit_access_readonly
.attr
,
317 struct attribute_group zfcp_sysfs_unit_attrs
= {
318 .attrs
= zfcp_unit_attrs
,
321 #define ZFCP_DEFINE_LATENCY_ATTR(_name) \
323 zfcp_sysfs_unit_##_name##_latency_show(struct device *dev, \
324 struct device_attribute *attr, \
326 struct scsi_device *sdev = to_scsi_device(dev); \
327 struct zfcp_unit *unit = sdev->hostdata; \
328 struct zfcp_latencies *lat = &unit->latencies; \
329 struct zfcp_adapter *adapter = unit->port->adapter; \
330 unsigned long long fsum, fmin, fmax, csum, cmin, cmax, cc; \
332 spin_lock_bh(&lat->lock); \
333 fsum = lat->_name.fabric.sum * adapter->timer_ticks; \
334 fmin = lat->_name.fabric.min * adapter->timer_ticks; \
335 fmax = lat->_name.fabric.max * adapter->timer_ticks; \
336 csum = lat->_name.channel.sum * adapter->timer_ticks; \
337 cmin = lat->_name.channel.min * adapter->timer_ticks; \
338 cmax = lat->_name.channel.max * adapter->timer_ticks; \
339 cc = lat->_name.counter; \
340 spin_unlock_bh(&lat->lock); \
342 do_div(fsum, 1000); \
343 do_div(fmin, 1000); \
344 do_div(fmax, 1000); \
345 do_div(csum, 1000); \
346 do_div(cmin, 1000); \
347 do_div(cmax, 1000); \
349 return sprintf(buf, "%llu %llu %llu %llu %llu %llu %llu\n", \
350 fmin, fmax, fsum, cmin, cmax, csum, cc); \
353 zfcp_sysfs_unit_##_name##_latency_store(struct device *dev, \
354 struct device_attribute *attr, \
355 const char *buf, size_t count) \
357 struct scsi_device *sdev = to_scsi_device(dev); \
358 struct zfcp_unit *unit = sdev->hostdata; \
359 struct zfcp_latencies *lat = &unit->latencies; \
360 unsigned long flags; \
362 spin_lock_irqsave(&lat->lock, flags); \
363 lat->_name.fabric.sum = 0; \
364 lat->_name.fabric.min = 0xFFFFFFFF; \
365 lat->_name.fabric.max = 0; \
366 lat->_name.channel.sum = 0; \
367 lat->_name.channel.min = 0xFFFFFFFF; \
368 lat->_name.channel.max = 0; \
369 lat->_name.counter = 0; \
370 spin_unlock_irqrestore(&lat->lock, flags); \
372 return (ssize_t) count; \
374 static DEVICE_ATTR(_name##_latency, S_IWUSR | S_IRUGO, \
375 zfcp_sysfs_unit_##_name##_latency_show, \
376 zfcp_sysfs_unit_##_name##_latency_store);
378 ZFCP_DEFINE_LATENCY_ATTR(read
);
379 ZFCP_DEFINE_LATENCY_ATTR(write
);
380 ZFCP_DEFINE_LATENCY_ATTR(cmd
);
382 #define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value) \
383 static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, \
384 struct device_attribute *attr,\
387 struct scsi_device *sdev = to_scsi_device(dev); \
388 struct zfcp_unit *unit = sdev->hostdata; \
390 return sprintf(buf, _format, _value); \
392 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL);
394 ZFCP_DEFINE_SCSI_ATTR(hba_id
, "%s\n",
395 dev_name(&unit
->port
->adapter
->ccw_device
->dev
));
396 ZFCP_DEFINE_SCSI_ATTR(wwpn
, "0x%016llx\n",
397 (unsigned long long) unit
->port
->wwpn
);
398 ZFCP_DEFINE_SCSI_ATTR(fcp_lun
, "0x%016llx\n",
399 (unsigned long long) unit
->fcp_lun
);
401 struct device_attribute
*zfcp_sysfs_sdev_attrs
[] = {
405 &dev_attr_read_latency
,
406 &dev_attr_write_latency
,
407 &dev_attr_cmd_latency
,
411 static ssize_t
zfcp_sysfs_adapter_util_show(struct device
*dev
,
412 struct device_attribute
*attr
,
415 struct Scsi_Host
*scsi_host
= dev_to_shost(dev
);
416 struct fsf_qtcb_bottom_port
*qtcb_port
;
417 struct zfcp_adapter
*adapter
;
420 adapter
= (struct zfcp_adapter
*) scsi_host
->hostdata
[0];
421 if (!(adapter
->adapter_features
& FSF_FEATURE_MEASUREMENT_DATA
))
424 qtcb_port
= kzalloc(sizeof(struct fsf_qtcb_bottom_port
), GFP_KERNEL
);
428 retval
= zfcp_fsf_exchange_port_data_sync(adapter
->qdio
, qtcb_port
);
430 retval
= sprintf(buf
, "%u %u %u\n", qtcb_port
->cp_util
,
431 qtcb_port
->cb_util
, qtcb_port
->a_util
);
435 static DEVICE_ATTR(utilization
, S_IRUGO
, zfcp_sysfs_adapter_util_show
, NULL
);
437 static int zfcp_sysfs_adapter_ex_config(struct device
*dev
,
438 struct fsf_statistics_info
*stat_inf
)
440 struct Scsi_Host
*scsi_host
= dev_to_shost(dev
);
441 struct fsf_qtcb_bottom_config
*qtcb_config
;
442 struct zfcp_adapter
*adapter
;
445 adapter
= (struct zfcp_adapter
*) scsi_host
->hostdata
[0];
446 if (!(adapter
->adapter_features
& FSF_FEATURE_MEASUREMENT_DATA
))
449 qtcb_config
= kzalloc(sizeof(struct fsf_qtcb_bottom_config
),
454 retval
= zfcp_fsf_exchange_config_data_sync(adapter
->qdio
, qtcb_config
);
456 *stat_inf
= qtcb_config
->stat_info
;
462 #define ZFCP_SHOST_ATTR(_name, _format, _arg...) \
463 static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, \
464 struct device_attribute *attr,\
467 struct fsf_statistics_info stat_info; \
470 retval = zfcp_sysfs_adapter_ex_config(dev, &stat_info); \
474 return sprintf(buf, _format, ## _arg); \
476 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL);
478 ZFCP_SHOST_ATTR(requests
, "%llu %llu %llu\n",
479 (unsigned long long) stat_info
.input_req
,
480 (unsigned long long) stat_info
.output_req
,
481 (unsigned long long) stat_info
.control_req
);
483 ZFCP_SHOST_ATTR(megabytes
, "%llu %llu\n",
484 (unsigned long long) stat_info
.input_mb
,
485 (unsigned long long) stat_info
.output_mb
);
487 ZFCP_SHOST_ATTR(seconds_active
, "%llu\n",
488 (unsigned long long) stat_info
.seconds_act
);
490 static ssize_t
zfcp_sysfs_adapter_q_full_show(struct device
*dev
,
491 struct device_attribute
*attr
,
494 struct Scsi_Host
*scsi_host
= class_to_shost(dev
);
495 struct zfcp_qdio
*qdio
=
496 ((struct zfcp_adapter
*) scsi_host
->hostdata
[0])->qdio
;
499 spin_lock_bh(&qdio
->stat_lock
);
500 util
= qdio
->req_q_util
;
501 spin_unlock_bh(&qdio
->stat_lock
);
503 return sprintf(buf
, "%d %llu\n", atomic_read(&qdio
->req_q_full
),
504 (unsigned long long)util
);
506 static DEVICE_ATTR(queue_full
, S_IRUGO
, zfcp_sysfs_adapter_q_full_show
, NULL
);
508 struct device_attribute
*zfcp_sysfs_shost_attrs
[] = {
509 &dev_attr_utilization
,
512 &dev_attr_seconds_active
,
513 &dev_attr_queue_full
,