ctcm_sysfs.c 5.1 KB

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