1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * zfcp device driver
4 *
5 * sysfs attributes.
6 *
7 * Copyright IBM Corp. 2008, 2010
8 */
9
10 #define KMSG_COMPONENT "zfcp"
11 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
12
13 #include <linux/slab.h>
14 #include "zfcp_ext.h"
15
16 #define ZFCP_DEV_ATTR(_feat, _name, _mode, _show, _store) \
17 struct device_attribute dev_attr_##_feat##_##_name = __ATTR(_name, _mode,\
18 _show, _store)
19 #define ZFCP_DEFINE_ATTR(_feat_def, _feat, _name, _format, _value) \
20 static ssize_t zfcp_sysfs_##_feat##_##_name##_show(struct device *dev, \
21 struct device_attribute *at,\
22 char *buf) \
23 { \
24 struct _feat_def *_feat = container_of(dev, struct _feat_def, dev); \
25 \
26 return sprintf(buf, _format, _value); \
27 } \
28 static ZFCP_DEV_ATTR(_feat, _name, S_IRUGO, \
29 zfcp_sysfs_##_feat##_##_name##_show, NULL);
30
31 #define ZFCP_DEFINE_ATTR_CONST(_feat, _name, _format, _value) \
32 static ssize_t zfcp_sysfs_##_feat##_##_name##_show(struct device *dev, \
33 struct device_attribute *at,\
34 char *buf) \
35 { \
36 return sprintf(buf, _format, _value); \
37 } \
38 static ZFCP_DEV_ATTR(_feat, _name, S_IRUGO, \
39 zfcp_sysfs_##_feat##_##_name##_show, NULL);
40
41 #define ZFCP_DEFINE_A_ATTR(_name, _format, _value) \
42 static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, \
43 struct device_attribute *at,\
44 char *buf) \
45 { \
46 struct ccw_device *cdev = to_ccwdev(dev); \
47 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev); \
48 int i; \
49 \
50 if (!adapter) \
51 return -ENODEV; \
52 \
53 i = sprintf(buf, _format, _value); \
54 zfcp_ccw_adapter_put(adapter); \
55 return i; \
56 } \
57 static ZFCP_DEV_ATTR(adapter, _name, S_IRUGO, \
58 zfcp_sysfs_adapter_##_name##_show, NULL);
59
60 ZFCP_DEFINE_A_ATTR(status, "0x%08x\n", atomic_read(&adapter->status));
61 ZFCP_DEFINE_A_ATTR(peer_wwnn, "0x%016llx\n",
62 (unsigned long long) adapter->peer_wwnn);
63 ZFCP_DEFINE_A_ATTR(peer_wwpn, "0x%016llx\n",
64 (unsigned long long) adapter->peer_wwpn);
65 ZFCP_DEFINE_A_ATTR(peer_d_id, "0x%06x\n", adapter->peer_d_id);
66 ZFCP_DEFINE_A_ATTR(card_version, "0x%04x\n", adapter->hydra_version);
67 ZFCP_DEFINE_A_ATTR(lic_version, "0x%08x\n", adapter->fsf_lic_version);
68 ZFCP_DEFINE_A_ATTR(hardware_version, "0x%08x\n", adapter->hardware_version);
69 ZFCP_DEFINE_A_ATTR(in_recovery, "%d\n", (atomic_read(&adapter->status) &
70 ZFCP_STATUS_COMMON_ERP_INUSE) != 0);
71
72 ZFCP_DEFINE_ATTR(zfcp_port, port, status, "0x%08x\n",
73 atomic_read(&port->status));
74 ZFCP_DEFINE_ATTR(zfcp_port, port, in_recovery, "%d\n",
75 (atomic_read(&port->status) &
76 ZFCP_STATUS_COMMON_ERP_INUSE) != 0);
77 ZFCP_DEFINE_ATTR_CONST(port, access_denied, "%d\n", 0);
78
79 ZFCP_DEFINE_ATTR(zfcp_unit, unit, status, "0x%08x\n",
80 zfcp_unit_sdev_status(unit));
81 ZFCP_DEFINE_ATTR(zfcp_unit, unit, in_recovery, "%d\n",
82 (zfcp_unit_sdev_status(unit) &
83 ZFCP_STATUS_COMMON_ERP_INUSE) != 0);
84 ZFCP_DEFINE_ATTR(zfcp_unit, unit, access_denied, "%d\n",
85 (zfcp_unit_sdev_status(unit) &
86 ZFCP_STATUS_COMMON_ACCESS_DENIED) != 0);
87 ZFCP_DEFINE_ATTR_CONST(unit, access_shared, "%d\n", 0);
88 ZFCP_DEFINE_ATTR_CONST(unit, access_readonly, "%d\n", 0);
89
zfcp_sysfs_port_failed_show(struct device * dev,struct device_attribute * attr,char * buf)90 static ssize_t zfcp_sysfs_port_failed_show(struct device *dev,
91 struct device_attribute *attr,
92 char *buf)
93 {
94 struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
95
96 if (atomic_read(&port->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
97 return sprintf(buf, "1\n");
98
99 return sprintf(buf, "0\n");
100 }
101
zfcp_sysfs_port_failed_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)102 static ssize_t zfcp_sysfs_port_failed_store(struct device *dev,
103 struct device_attribute *attr,
104 const char *buf, size_t count)
105 {
106 struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
107 unsigned long val;
108
109 if (kstrtoul(buf, 0, &val) || val != 0)
110 return -EINVAL;
111
112 zfcp_erp_set_port_status(port, ZFCP_STATUS_COMMON_RUNNING);
113 zfcp_erp_port_reopen(port, ZFCP_STATUS_COMMON_ERP_FAILED, "sypfai2");
114 zfcp_erp_wait(port->adapter);
115
116 return count;
117 }
118 static ZFCP_DEV_ATTR(port, failed, S_IWUSR | S_IRUGO,
119 zfcp_sysfs_port_failed_show,
120 zfcp_sysfs_port_failed_store);
121
zfcp_sysfs_unit_failed_show(struct device * dev,struct device_attribute * attr,char * buf)122 static ssize_t zfcp_sysfs_unit_failed_show(struct device *dev,
123 struct device_attribute *attr,
124 char *buf)
125 {
126 struct zfcp_unit *unit = container_of(dev, struct zfcp_unit, dev);
127 struct scsi_device *sdev;
128 unsigned int status, failed = 1;
129
130 sdev = zfcp_unit_sdev(unit);
131 if (sdev) {
132 status = atomic_read(&sdev_to_zfcp(sdev)->status);
133 failed = status & ZFCP_STATUS_COMMON_ERP_FAILED ? 1 : 0;
134 scsi_device_put(sdev);
135 }
136
137 return sprintf(buf, "%d\n", failed);
138 }
139
zfcp_sysfs_unit_failed_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)140 static ssize_t zfcp_sysfs_unit_failed_store(struct device *dev,
141 struct device_attribute *attr,
142 const char *buf, size_t count)
143 {
144 struct zfcp_unit *unit = container_of(dev, struct zfcp_unit, dev);
145 unsigned long val;
146 struct scsi_device *sdev;
147
148 if (kstrtoul(buf, 0, &val) || val != 0)
149 return -EINVAL;
150
151 sdev = zfcp_unit_sdev(unit);
152 if (sdev) {
153 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_RUNNING);
154 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
155 "syufai2");
156 zfcp_erp_wait(unit->port->adapter);
157 } else
158 zfcp_unit_scsi_scan(unit);
159
160 return count;
161 }
162 static ZFCP_DEV_ATTR(unit, failed, S_IWUSR | S_IRUGO,
163 zfcp_sysfs_unit_failed_show,
164 zfcp_sysfs_unit_failed_store);
165
zfcp_sysfs_adapter_failed_show(struct device * dev,struct device_attribute * attr,char * buf)166 static ssize_t zfcp_sysfs_adapter_failed_show(struct device *dev,
167 struct device_attribute *attr,
168 char *buf)
169 {
170 struct ccw_device *cdev = to_ccwdev(dev);
171 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
172 int i;
173
174 if (!adapter)
175 return -ENODEV;
176
177 if (atomic_read(&adapter->status) & ZFCP_STATUS_COMMON_ERP_FAILED)
178 i = sprintf(buf, "1\n");
179 else
180 i = sprintf(buf, "0\n");
181
182 zfcp_ccw_adapter_put(adapter);
183 return i;
184 }
185
zfcp_sysfs_adapter_failed_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)186 static ssize_t zfcp_sysfs_adapter_failed_store(struct device *dev,
187 struct device_attribute *attr,
188 const char *buf, size_t count)
189 {
190 struct ccw_device *cdev = to_ccwdev(dev);
191 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
192 unsigned long val;
193 int retval = 0;
194
195 if (!adapter)
196 return -ENODEV;
197
198 if (kstrtoul(buf, 0, &val) || val != 0) {
199 retval = -EINVAL;
200 goto out;
201 }
202
203 zfcp_erp_adapter_reset_sync(adapter, "syafai2");
204 out:
205 zfcp_ccw_adapter_put(adapter);
206 return retval ? retval : (ssize_t) count;
207 }
208 static ZFCP_DEV_ATTR(adapter, failed, S_IWUSR | S_IRUGO,
209 zfcp_sysfs_adapter_failed_show,
210 zfcp_sysfs_adapter_failed_store);
211
zfcp_sysfs_port_rescan_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)212 static ssize_t zfcp_sysfs_port_rescan_store(struct device *dev,
213 struct device_attribute *attr,
214 const char *buf, size_t count)
215 {
216 struct ccw_device *cdev = to_ccwdev(dev);
217 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
218
219 if (!adapter)
220 return -ENODEV;
221
222 /*
223 * Users wish is our command: immediately schedule and flush a
224 * worker to conduct a synchronous port scan, that is, neither
225 * a random delay nor a rate limit is applied here.
226 */
227 queue_delayed_work(adapter->work_queue, &adapter->scan_work, 0);
228 flush_delayed_work(&adapter->scan_work);
229 zfcp_ccw_adapter_put(adapter);
230
231 return (ssize_t) count;
232 }
233 static ZFCP_DEV_ATTR(adapter, port_rescan, S_IWUSR, NULL,
234 zfcp_sysfs_port_rescan_store);
235
236 DEFINE_MUTEX(zfcp_sysfs_port_units_mutex);
237
zfcp_sysfs_port_set_removing(struct zfcp_port * const port)238 static void zfcp_sysfs_port_set_removing(struct zfcp_port *const port)
239 {
240 lockdep_assert_held(&zfcp_sysfs_port_units_mutex);
241 atomic_set(&port->units, -1);
242 }
243
zfcp_sysfs_port_is_removing(const struct zfcp_port * const port)244 bool zfcp_sysfs_port_is_removing(const struct zfcp_port *const port)
245 {
246 lockdep_assert_held(&zfcp_sysfs_port_units_mutex);
247 return atomic_read(&port->units) == -1;
248 }
249
zfcp_sysfs_port_in_use(struct zfcp_port * const port)250 static bool zfcp_sysfs_port_in_use(struct zfcp_port *const port)
251 {
252 struct zfcp_adapter *const adapter = port->adapter;
253 unsigned long flags;
254 struct scsi_device *sdev;
255 bool in_use = true;
256
257 mutex_lock(&zfcp_sysfs_port_units_mutex);
258 if (atomic_read(&port->units) > 0)
259 goto unlock_port_units_mutex; /* zfcp_unit(s) under port */
260
261 spin_lock_irqsave(adapter->scsi_host->host_lock, flags);
262 __shost_for_each_device(sdev, adapter->scsi_host) {
263 const struct zfcp_scsi_dev *zsdev = sdev_to_zfcp(sdev);
264
265 if (sdev->sdev_state == SDEV_DEL ||
266 sdev->sdev_state == SDEV_CANCEL)
267 continue;
268 if (zsdev->port != port)
269 continue;
270 /* alive scsi_device under port of interest */
271 goto unlock_host_lock;
272 }
273
274 /* port is about to be removed, so no more unit_add or slave_alloc */
275 zfcp_sysfs_port_set_removing(port);
276 in_use = false;
277
278 unlock_host_lock:
279 spin_unlock_irqrestore(adapter->scsi_host->host_lock, flags);
280 unlock_port_units_mutex:
281 mutex_unlock(&zfcp_sysfs_port_units_mutex);
282 return in_use;
283 }
284
zfcp_sysfs_port_remove_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)285 static ssize_t zfcp_sysfs_port_remove_store(struct device *dev,
286 struct device_attribute *attr,
287 const char *buf, size_t count)
288 {
289 struct ccw_device *cdev = to_ccwdev(dev);
290 struct zfcp_adapter *adapter = zfcp_ccw_adapter_by_cdev(cdev);
291 struct zfcp_port *port;
292 u64 wwpn;
293 int retval = -EINVAL;
294
295 if (!adapter)
296 return -ENODEV;
297
298 if (kstrtoull(buf, 0, (unsigned long long *) &wwpn))
299 goto out;
300
301 port = zfcp_get_port_by_wwpn(adapter, wwpn);
302 if (!port)
303 goto out;
304 else
305 retval = 0;
306
307 if (zfcp_sysfs_port_in_use(port)) {
308 retval = -EBUSY;
309 put_device(&port->dev); /* undo zfcp_get_port_by_wwpn() */
310 goto out;
311 }
312
313 write_lock_irq(&adapter->port_list_lock);
314 list_del(&port->list);
315 write_unlock_irq(&adapter->port_list_lock);
316
317 put_device(&port->dev);
318
319 zfcp_erp_port_shutdown(port, 0, "syprs_1");
320 device_unregister(&port->dev);
321 out:
322 zfcp_ccw_adapter_put(adapter);
323 return retval ? retval : (ssize_t) count;
324 }
325 static ZFCP_DEV_ATTR(adapter, port_remove, S_IWUSR, NULL,
326 zfcp_sysfs_port_remove_store);
327
328 static struct attribute *zfcp_adapter_attrs[] = {
329 &dev_attr_adapter_failed.attr,
330 &dev_attr_adapter_in_recovery.attr,
331 &dev_attr_adapter_port_remove.attr,
332 &dev_attr_adapter_port_rescan.attr,
333 &dev_attr_adapter_peer_wwnn.attr,
334 &dev_attr_adapter_peer_wwpn.attr,
335 &dev_attr_adapter_peer_d_id.attr,
336 &dev_attr_adapter_card_version.attr,
337 &dev_attr_adapter_lic_version.attr,
338 &dev_attr_adapter_status.attr,
339 &dev_attr_adapter_hardware_version.attr,
340 NULL
341 };
342
343 struct attribute_group zfcp_sysfs_adapter_attrs = {
344 .attrs = zfcp_adapter_attrs,
345 };
346
zfcp_sysfs_unit_add_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)347 static ssize_t zfcp_sysfs_unit_add_store(struct device *dev,
348 struct device_attribute *attr,
349 const char *buf, size_t count)
350 {
351 struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
352 u64 fcp_lun;
353 int retval;
354
355 if (kstrtoull(buf, 0, (unsigned long long *) &fcp_lun))
356 return -EINVAL;
357
358 retval = zfcp_unit_add(port, fcp_lun);
359 if (retval)
360 return retval;
361
362 return count;
363 }
364 static DEVICE_ATTR(unit_add, S_IWUSR, NULL, zfcp_sysfs_unit_add_store);
365
zfcp_sysfs_unit_remove_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)366 static ssize_t zfcp_sysfs_unit_remove_store(struct device *dev,
367 struct device_attribute *attr,
368 const char *buf, size_t count)
369 {
370 struct zfcp_port *port = container_of(dev, struct zfcp_port, dev);
371 u64 fcp_lun;
372
373 if (kstrtoull(buf, 0, (unsigned long long *) &fcp_lun))
374 return -EINVAL;
375
376 if (zfcp_unit_remove(port, fcp_lun))
377 return -EINVAL;
378
379 return count;
380 }
381 static DEVICE_ATTR(unit_remove, S_IWUSR, NULL, zfcp_sysfs_unit_remove_store);
382
383 static struct attribute *zfcp_port_attrs[] = {
384 &dev_attr_unit_add.attr,
385 &dev_attr_unit_remove.attr,
386 &dev_attr_port_failed.attr,
387 &dev_attr_port_in_recovery.attr,
388 &dev_attr_port_status.attr,
389 &dev_attr_port_access_denied.attr,
390 NULL
391 };
392 static struct attribute_group zfcp_port_attr_group = {
393 .attrs = zfcp_port_attrs,
394 };
395 const struct attribute_group *zfcp_port_attr_groups[] = {
396 &zfcp_port_attr_group,
397 NULL,
398 };
399
400 static struct attribute *zfcp_unit_attrs[] = {
401 &dev_attr_unit_failed.attr,
402 &dev_attr_unit_in_recovery.attr,
403 &dev_attr_unit_status.attr,
404 &dev_attr_unit_access_denied.attr,
405 &dev_attr_unit_access_shared.attr,
406 &dev_attr_unit_access_readonly.attr,
407 NULL
408 };
409 static struct attribute_group zfcp_unit_attr_group = {
410 .attrs = zfcp_unit_attrs,
411 };
412 const struct attribute_group *zfcp_unit_attr_groups[] = {
413 &zfcp_unit_attr_group,
414 NULL,
415 };
416
417 #define ZFCP_DEFINE_LATENCY_ATTR(_name) \
418 static ssize_t \
419 zfcp_sysfs_unit_##_name##_latency_show(struct device *dev, \
420 struct device_attribute *attr, \
421 char *buf) { \
422 struct scsi_device *sdev = to_scsi_device(dev); \
423 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); \
424 struct zfcp_latencies *lat = &zfcp_sdev->latencies; \
425 struct zfcp_adapter *adapter = zfcp_sdev->port->adapter; \
426 unsigned long long fsum, fmin, fmax, csum, cmin, cmax, cc; \
427 \
428 spin_lock_bh(&lat->lock); \
429 fsum = lat->_name.fabric.sum * adapter->timer_ticks; \
430 fmin = lat->_name.fabric.min * adapter->timer_ticks; \
431 fmax = lat->_name.fabric.max * adapter->timer_ticks; \
432 csum = lat->_name.channel.sum * adapter->timer_ticks; \
433 cmin = lat->_name.channel.min * adapter->timer_ticks; \
434 cmax = lat->_name.channel.max * adapter->timer_ticks; \
435 cc = lat->_name.counter; \
436 spin_unlock_bh(&lat->lock); \
437 \
438 do_div(fsum, 1000); \
439 do_div(fmin, 1000); \
440 do_div(fmax, 1000); \
441 do_div(csum, 1000); \
442 do_div(cmin, 1000); \
443 do_div(cmax, 1000); \
444 \
445 return sprintf(buf, "%llu %llu %llu %llu %llu %llu %llu\n", \
446 fmin, fmax, fsum, cmin, cmax, csum, cc); \
447 } \
448 static ssize_t \
449 zfcp_sysfs_unit_##_name##_latency_store(struct device *dev, \
450 struct device_attribute *attr, \
451 const char *buf, size_t count) \
452 { \
453 struct scsi_device *sdev = to_scsi_device(dev); \
454 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); \
455 struct zfcp_latencies *lat = &zfcp_sdev->latencies; \
456 unsigned long flags; \
457 \
458 spin_lock_irqsave(&lat->lock, flags); \
459 lat->_name.fabric.sum = 0; \
460 lat->_name.fabric.min = 0xFFFFFFFF; \
461 lat->_name.fabric.max = 0; \
462 lat->_name.channel.sum = 0; \
463 lat->_name.channel.min = 0xFFFFFFFF; \
464 lat->_name.channel.max = 0; \
465 lat->_name.counter = 0; \
466 spin_unlock_irqrestore(&lat->lock, flags); \
467 \
468 return (ssize_t) count; \
469 } \
470 static DEVICE_ATTR(_name##_latency, S_IWUSR | S_IRUGO, \
471 zfcp_sysfs_unit_##_name##_latency_show, \
472 zfcp_sysfs_unit_##_name##_latency_store);
473
474 ZFCP_DEFINE_LATENCY_ATTR(read);
475 ZFCP_DEFINE_LATENCY_ATTR(write);
476 ZFCP_DEFINE_LATENCY_ATTR(cmd);
477
478 #define ZFCP_DEFINE_SCSI_ATTR(_name, _format, _value) \
479 static ssize_t zfcp_sysfs_scsi_##_name##_show(struct device *dev, \
480 struct device_attribute *attr,\
481 char *buf) \
482 { \
483 struct scsi_device *sdev = to_scsi_device(dev); \
484 struct zfcp_scsi_dev *zfcp_sdev = sdev_to_zfcp(sdev); \
485 \
486 return sprintf(buf, _format, _value); \
487 } \
488 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_scsi_##_name##_show, NULL);
489
490 ZFCP_DEFINE_SCSI_ATTR(hba_id, "%s\n",
491 dev_name(&zfcp_sdev->port->adapter->ccw_device->dev));
492 ZFCP_DEFINE_SCSI_ATTR(wwpn, "0x%016llx\n",
493 (unsigned long long) zfcp_sdev->port->wwpn);
494
zfcp_sysfs_scsi_fcp_lun_show(struct device * dev,struct device_attribute * attr,char * buf)495 static ssize_t zfcp_sysfs_scsi_fcp_lun_show(struct device *dev,
496 struct device_attribute *attr,
497 char *buf)
498 {
499 struct scsi_device *sdev = to_scsi_device(dev);
500
501 return sprintf(buf, "0x%016llx\n", zfcp_scsi_dev_lun(sdev));
502 }
503 static DEVICE_ATTR(fcp_lun, S_IRUGO, zfcp_sysfs_scsi_fcp_lun_show, NULL);
504
505 ZFCP_DEFINE_SCSI_ATTR(zfcp_access_denied, "%d\n",
506 (atomic_read(&zfcp_sdev->status) &
507 ZFCP_STATUS_COMMON_ACCESS_DENIED) != 0);
508
zfcp_sysfs_scsi_zfcp_failed_show(struct device * dev,struct device_attribute * attr,char * buf)509 static ssize_t zfcp_sysfs_scsi_zfcp_failed_show(struct device *dev,
510 struct device_attribute *attr,
511 char *buf)
512 {
513 struct scsi_device *sdev = to_scsi_device(dev);
514 unsigned int status = atomic_read(&sdev_to_zfcp(sdev)->status);
515 unsigned int failed = status & ZFCP_STATUS_COMMON_ERP_FAILED ? 1 : 0;
516
517 return sprintf(buf, "%d\n", failed);
518 }
519
zfcp_sysfs_scsi_zfcp_failed_store(struct device * dev,struct device_attribute * attr,const char * buf,size_t count)520 static ssize_t zfcp_sysfs_scsi_zfcp_failed_store(struct device *dev,
521 struct device_attribute *attr,
522 const char *buf, size_t count)
523 {
524 struct scsi_device *sdev = to_scsi_device(dev);
525 unsigned long val;
526
527 if (kstrtoul(buf, 0, &val) || val != 0)
528 return -EINVAL;
529
530 zfcp_erp_set_lun_status(sdev, ZFCP_STATUS_COMMON_RUNNING);
531 zfcp_erp_lun_reopen(sdev, ZFCP_STATUS_COMMON_ERP_FAILED,
532 "syufai3");
533 zfcp_erp_wait(sdev_to_zfcp(sdev)->port->adapter);
534
535 return count;
536 }
537 static DEVICE_ATTR(zfcp_failed, S_IWUSR | S_IRUGO,
538 zfcp_sysfs_scsi_zfcp_failed_show,
539 zfcp_sysfs_scsi_zfcp_failed_store);
540
541 ZFCP_DEFINE_SCSI_ATTR(zfcp_in_recovery, "%d\n",
542 (atomic_read(&zfcp_sdev->status) &
543 ZFCP_STATUS_COMMON_ERP_INUSE) != 0);
544
545 ZFCP_DEFINE_SCSI_ATTR(zfcp_status, "0x%08x\n",
546 atomic_read(&zfcp_sdev->status));
547
548 struct device_attribute *zfcp_sysfs_sdev_attrs[] = {
549 &dev_attr_fcp_lun,
550 &dev_attr_wwpn,
551 &dev_attr_hba_id,
552 &dev_attr_read_latency,
553 &dev_attr_write_latency,
554 &dev_attr_cmd_latency,
555 &dev_attr_zfcp_access_denied,
556 &dev_attr_zfcp_failed,
557 &dev_attr_zfcp_in_recovery,
558 &dev_attr_zfcp_status,
559 NULL
560 };
561
zfcp_sysfs_adapter_util_show(struct device * dev,struct device_attribute * attr,char * buf)562 static ssize_t zfcp_sysfs_adapter_util_show(struct device *dev,
563 struct device_attribute *attr,
564 char *buf)
565 {
566 struct Scsi_Host *scsi_host = dev_to_shost(dev);
567 struct fsf_qtcb_bottom_port *qtcb_port;
568 struct zfcp_adapter *adapter;
569 int retval;
570
571 adapter = (struct zfcp_adapter *) scsi_host->hostdata[0];
572 if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA))
573 return -EOPNOTSUPP;
574
575 qtcb_port = kzalloc(sizeof(struct fsf_qtcb_bottom_port), GFP_KERNEL);
576 if (!qtcb_port)
577 return -ENOMEM;
578
579 retval = zfcp_fsf_exchange_port_data_sync(adapter->qdio, qtcb_port);
580 if (!retval)
581 retval = sprintf(buf, "%u %u %u\n", qtcb_port->cp_util,
582 qtcb_port->cb_util, qtcb_port->a_util);
583 kfree(qtcb_port);
584 return retval;
585 }
586 static DEVICE_ATTR(utilization, S_IRUGO, zfcp_sysfs_adapter_util_show, NULL);
587
zfcp_sysfs_adapter_ex_config(struct device * dev,struct fsf_statistics_info * stat_inf)588 static int zfcp_sysfs_adapter_ex_config(struct device *dev,
589 struct fsf_statistics_info *stat_inf)
590 {
591 struct Scsi_Host *scsi_host = dev_to_shost(dev);
592 struct fsf_qtcb_bottom_config *qtcb_config;
593 struct zfcp_adapter *adapter;
594 int retval;
595
596 adapter = (struct zfcp_adapter *) scsi_host->hostdata[0];
597 if (!(adapter->adapter_features & FSF_FEATURE_MEASUREMENT_DATA))
598 return -EOPNOTSUPP;
599
600 qtcb_config = kzalloc(sizeof(struct fsf_qtcb_bottom_config),
601 GFP_KERNEL);
602 if (!qtcb_config)
603 return -ENOMEM;
604
605 retval = zfcp_fsf_exchange_config_data_sync(adapter->qdio, qtcb_config);
606 if (!retval)
607 *stat_inf = qtcb_config->stat_info;
608
609 kfree(qtcb_config);
610 return retval;
611 }
612
613 #define ZFCP_SHOST_ATTR(_name, _format, _arg...) \
614 static ssize_t zfcp_sysfs_adapter_##_name##_show(struct device *dev, \
615 struct device_attribute *attr,\
616 char *buf) \
617 { \
618 struct fsf_statistics_info stat_info; \
619 int retval; \
620 \
621 retval = zfcp_sysfs_adapter_ex_config(dev, &stat_info); \
622 if (retval) \
623 return retval; \
624 \
625 return sprintf(buf, _format, ## _arg); \
626 } \
627 static DEVICE_ATTR(_name, S_IRUGO, zfcp_sysfs_adapter_##_name##_show, NULL);
628
629 ZFCP_SHOST_ATTR(requests, "%llu %llu %llu\n",
630 (unsigned long long) stat_info.input_req,
631 (unsigned long long) stat_info.output_req,
632 (unsigned long long) stat_info.control_req);
633
634 ZFCP_SHOST_ATTR(megabytes, "%llu %llu\n",
635 (unsigned long long) stat_info.input_mb,
636 (unsigned long long) stat_info.output_mb);
637
638 ZFCP_SHOST_ATTR(seconds_active, "%llu\n",
639 (unsigned long long) stat_info.seconds_act);
640
zfcp_sysfs_adapter_q_full_show(struct device * dev,struct device_attribute * attr,char * buf)641 static ssize_t zfcp_sysfs_adapter_q_full_show(struct device *dev,
642 struct device_attribute *attr,
643 char *buf)
644 {
645 struct Scsi_Host *scsi_host = class_to_shost(dev);
646 struct zfcp_qdio *qdio =
647 ((struct zfcp_adapter *) scsi_host->hostdata[0])->qdio;
648 u64 util;
649
650 spin_lock_bh(&qdio->stat_lock);
651 util = qdio->req_q_util;
652 spin_unlock_bh(&qdio->stat_lock);
653
654 return sprintf(buf, "%d %llu\n", atomic_read(&qdio->req_q_full),
655 (unsigned long long)util);
656 }
657 static DEVICE_ATTR(queue_full, S_IRUGO, zfcp_sysfs_adapter_q_full_show, NULL);
658
659 struct device_attribute *zfcp_sysfs_shost_attrs[] = {
660 &dev_attr_utilization,
661 &dev_attr_requests,
662 &dev_attr_megabytes,
663 &dev_attr_seconds_active,
664 &dev_attr_queue_full,
665 NULL
666 };
667