zfcp_sysfs.c 19 KB

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