ctcm_sysfs.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright IBM Corp. 2007, 2007
  4. * Authors: Peter Tiedemann (ptiedem@de.ibm.com)
  5. *
  6. */
  7. #undef DEBUG
  8. #undef DEBUGDATA
  9. #undef DEBUGCCW
  10. #define KMSG_COMPONENT "ctcm"
  11. #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
  12. #include <linux/device.h>
  13. #include <linux/sysfs.h>
  14. #include <linux/slab.h>
  15. #include "ctcm_main.h"
  16. /*
  17. * sysfs attributes
  18. */
  19. static ssize_t ctcm_buffer_show(struct device *dev,
  20. struct device_attribute *attr, char *buf)
  21. {
  22. struct ctcm_priv *priv = dev_get_drvdata(dev);
  23. if (!priv)
  24. return -ENODEV;
  25. return sprintf(buf, "%d\n", priv->buffer_size);
  26. }
  27. static ssize_t ctcm_buffer_write(struct device *dev,
  28. struct device_attribute *attr, const char *buf, size_t count)
  29. {
  30. struct net_device *ndev;
  31. unsigned int bs1;
  32. struct ctcm_priv *priv = dev_get_drvdata(dev);
  33. int rc;
  34. ndev = priv->channel[CTCM_READ]->netdev;
  35. if (!(priv && priv->channel[CTCM_READ] && ndev)) {
  36. CTCM_DBF_TEXT(SETUP, CTC_DBF_ERROR, "bfnondev");
  37. return -ENODEV;
  38. }
  39. rc = kstrtouint(buf, 0, &bs1);
  40. if (rc)
  41. goto einval;
  42. if (bs1 > CTCM_BUFSIZE_LIMIT)
  43. goto einval;
  44. if (bs1 < (576 + LL_HEADER_LENGTH + 2))
  45. goto einval;
  46. priv->buffer_size = bs1; /* just to overwrite the default */
  47. if ((ndev->flags & IFF_RUNNING) &&
  48. (bs1 < (ndev->mtu + LL_HEADER_LENGTH + 2)))
  49. goto einval;
  50. priv->channel[CTCM_READ]->max_bufsize = bs1;
  51. priv->channel[CTCM_WRITE]->max_bufsize = bs1;
  52. if (!(ndev->flags & IFF_RUNNING))
  53. ndev->mtu = bs1 - LL_HEADER_LENGTH - 2;
  54. priv->channel[CTCM_READ]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
  55. priv->channel[CTCM_WRITE]->flags |= CHANNEL_FLAGS_BUFSIZE_CHANGED;
  56. CTCM_DBF_DEV(SETUP, ndev, buf);
  57. return count;
  58. einval:
  59. CTCM_DBF_DEV(SETUP, ndev, "buff_err");
  60. return -EINVAL;
  61. }
  62. static void ctcm_print_statistics(struct ctcm_priv *priv)
  63. {
  64. char *sbuf;
  65. char *p;
  66. if (!priv)
  67. return;
  68. sbuf = kmalloc(2048, GFP_KERNEL);
  69. if (sbuf == NULL)
  70. return;
  71. p = sbuf;
  72. p += sprintf(p, " Device FSM state: %s\n",
  73. fsm_getstate_str(priv->fsm));
  74. p += sprintf(p, " RX channel FSM state: %s\n",
  75. fsm_getstate_str(priv->channel[CTCM_READ]->fsm));
  76. p += sprintf(p, " TX channel FSM state: %s\n",
  77. fsm_getstate_str(priv->channel[CTCM_WRITE]->fsm));
  78. p += sprintf(p, " Max. TX buffer used: %ld\n",
  79. priv->channel[WRITE]->prof.maxmulti);
  80. p += sprintf(p, " Max. chained SKBs: %ld\n",
  81. priv->channel[WRITE]->prof.maxcqueue);
  82. p += sprintf(p, " TX single write ops: %ld\n",
  83. priv->channel[WRITE]->prof.doios_single);
  84. p += sprintf(p, " TX multi write ops: %ld\n",
  85. priv->channel[WRITE]->prof.doios_multi);
  86. p += sprintf(p, " Netto bytes written: %ld\n",
  87. priv->channel[WRITE]->prof.txlen);
  88. p += sprintf(p, " Max. TX IO-time: %u\n",
  89. jiffies_to_usecs(priv->channel[WRITE]->prof.tx_time));
  90. printk(KERN_INFO "Statistics for %s:\n%s",
  91. priv->channel[CTCM_WRITE]->netdev->name, sbuf);
  92. kfree(sbuf);
  93. return;
  94. }
  95. static ssize_t stats_show(struct device *dev,
  96. struct device_attribute *attr, char *buf)
  97. {
  98. struct ccwgroup_device *gdev = to_ccwgroupdev(dev);
  99. struct ctcm_priv *priv = dev_get_drvdata(dev);
  100. if (!priv || gdev->state != CCWGROUP_ONLINE)
  101. return -ENODEV;
  102. ctcm_print_statistics(priv);
  103. return sprintf(buf, "0\n");
  104. }
  105. static ssize_t stats_write(struct device *dev, struct device_attribute *attr,
  106. const char *buf, size_t count)
  107. {
  108. struct ctcm_priv *priv = dev_get_drvdata(dev);
  109. if (!priv)
  110. return -ENODEV;
  111. /* Reset statistics */
  112. memset(&priv->channel[WRITE]->prof, 0,
  113. sizeof(priv->channel[CTCM_WRITE]->prof));
  114. return count;
  115. }
  116. static ssize_t ctcm_proto_show(struct device *dev,
  117. struct device_attribute *attr, char *buf)
  118. {
  119. struct ctcm_priv *priv = dev_get_drvdata(dev);
  120. if (!priv)
  121. return -ENODEV;
  122. return sprintf(buf, "%d\n", priv->protocol);
  123. }
  124. static ssize_t ctcm_proto_store(struct device *dev,
  125. struct device_attribute *attr, const char *buf, size_t count)
  126. {
  127. int value, rc;
  128. struct ctcm_priv *priv = dev_get_drvdata(dev);
  129. if (!priv)
  130. return -ENODEV;
  131. rc = kstrtoint(buf, 0, &value);
  132. if (rc ||
  133. !((value == CTCM_PROTO_S390) ||
  134. (value == CTCM_PROTO_LINUX) ||
  135. (value == CTCM_PROTO_MPC) ||
  136. (value == CTCM_PROTO_OS390)))
  137. return -EINVAL;
  138. priv->protocol = value;
  139. CTCM_DBF_DEV(SETUP, dev, buf);
  140. return count;
  141. }
  142. static const char *ctcm_type[] = {
  143. "not a channel",
  144. "CTC/A",
  145. "FICON channel",
  146. "ESCON channel",
  147. "unknown channel type",
  148. "unsupported channel type",
  149. };
  150. static ssize_t ctcm_type_show(struct device *dev,
  151. struct device_attribute *attr, char *buf)
  152. {
  153. struct ccwgroup_device *cgdev;
  154. cgdev = to_ccwgroupdev(dev);
  155. if (!cgdev)
  156. return -ENODEV;
  157. return sprintf(buf, "%s\n",
  158. ctcm_type[cgdev->cdev[0]->id.driver_info]);
  159. }
  160. static DEVICE_ATTR(buffer, 0644, ctcm_buffer_show, ctcm_buffer_write);
  161. static DEVICE_ATTR(protocol, 0644, ctcm_proto_show, ctcm_proto_store);
  162. static DEVICE_ATTR(type, 0444, ctcm_type_show, NULL);
  163. static DEVICE_ATTR(stats, 0644, stats_show, stats_write);
  164. static struct attribute *ctcm_attr[] = {
  165. &dev_attr_protocol.attr,
  166. &dev_attr_type.attr,
  167. &dev_attr_buffer.attr,
  168. &dev_attr_stats.attr,
  169. NULL,
  170. };
  171. static struct attribute_group ctcm_attr_group = {
  172. .attrs = ctcm_attr,
  173. };
  174. const struct attribute_group *ctcm_attr_groups[] = {
  175. &ctcm_attr_group,
  176. NULL,
  177. };