ctcm_sysfs.c 5.2 KB

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