ctcm_sysfs.c 5.1 KB

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