bus-osm.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. * Bus Adapter OSM
  3. *
  4. * Copyright (C) 2005 Markus Lidel <Markus.Lidel@shadowconnect.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * Fixes/additions:
  12. * Markus Lidel <Markus.Lidel@shadowconnect.com>
  13. * initial version.
  14. */
  15. #include <linux/module.h>
  16. #include <linux/i2o.h>
  17. #define OSM_NAME "bus-osm"
  18. #define OSM_VERSION "1.317"
  19. #define OSM_DESCRIPTION "I2O Bus Adapter OSM"
  20. static struct i2o_driver i2o_bus_driver;
  21. /* Bus OSM class handling definition */
  22. static struct i2o_class_id i2o_bus_class_id[] = {
  23. {I2O_CLASS_BUS_ADAPTER},
  24. {I2O_CLASS_END}
  25. };
  26. /**
  27. * i2o_bus_scan - Scan the bus for new devices
  28. * @dev: I2O device of the bus, which should be scanned
  29. *
  30. * Scans the bus dev for new / removed devices. After the scan a new LCT
  31. * will be fetched automatically.
  32. *
  33. * Returns 0 on success or negative error code on failure.
  34. */
  35. static int i2o_bus_scan(struct i2o_device *dev)
  36. {
  37. struct i2o_message *msg;
  38. msg = i2o_msg_get_wait(dev->iop, I2O_TIMEOUT_MESSAGE_GET);
  39. if (IS_ERR(msg))
  40. return -ETIMEDOUT;
  41. msg->u.head[0] = cpu_to_le32(FIVE_WORD_MSG_SIZE | SGL_OFFSET_0);
  42. msg->u.head[1] =
  43. cpu_to_le32(I2O_CMD_BUS_SCAN << 24 | HOST_TID << 12 | dev->lct_data.
  44. tid);
  45. return i2o_msg_post_wait(dev->iop, msg, 60);
  46. };
  47. /**
  48. * i2o_bus_store_scan - Scan the I2O Bus Adapter
  49. * @d: device which should be scanned
  50. * @attr: device_attribute
  51. * @buf: output buffer
  52. * @count: buffer size
  53. *
  54. * Returns count.
  55. */
  56. static ssize_t i2o_bus_store_scan(struct device *d,
  57. struct device_attribute *attr,
  58. const char *buf, size_t count)
  59. {
  60. struct i2o_device *i2o_dev = to_i2o_device(d);
  61. int rc;
  62. if ((rc = i2o_bus_scan(i2o_dev)))
  63. osm_warn("bus scan failed %d\n", rc);
  64. return count;
  65. }
  66. /* Bus Adapter OSM device attributes */
  67. static DEVICE_ATTR(scan, S_IWUSR, NULL, i2o_bus_store_scan);
  68. /**
  69. * i2o_bus_probe - verify if dev is a I2O Bus Adapter device and install it
  70. * @dev: device to verify if it is a I2O Bus Adapter device
  71. *
  72. * Because we want all Bus Adapters always return 0.
  73. * Except when we fail. Then we are sad.
  74. *
  75. * Returns 0, except when we fail to excel.
  76. */
  77. static int i2o_bus_probe(struct device *dev)
  78. {
  79. struct i2o_device *i2o_dev = to_i2o_device(get_device(dev));
  80. int rc;
  81. rc = device_create_file(dev, &dev_attr_scan);
  82. if (rc)
  83. goto err_out;
  84. osm_info("device added (TID: %03x)\n", i2o_dev->lct_data.tid);
  85. return 0;
  86. err_out:
  87. put_device(dev);
  88. return rc;
  89. };
  90. /**
  91. * i2o_bus_remove - remove the I2O Bus Adapter device from the system again
  92. * @dev: I2O Bus Adapter device which should be removed
  93. *
  94. * Always returns 0.
  95. */
  96. static int i2o_bus_remove(struct device *dev)
  97. {
  98. struct i2o_device *i2o_dev = to_i2o_device(dev);
  99. device_remove_file(dev, &dev_attr_scan);
  100. put_device(dev);
  101. osm_info("device removed (TID: %03x)\n", i2o_dev->lct_data.tid);
  102. return 0;
  103. };
  104. /* Bus Adapter OSM driver struct */
  105. static struct i2o_driver i2o_bus_driver = {
  106. .name = OSM_NAME,
  107. .classes = i2o_bus_class_id,
  108. .driver = {
  109. .probe = i2o_bus_probe,
  110. .remove = i2o_bus_remove,
  111. },
  112. };
  113. /**
  114. * i2o_bus_init - Bus Adapter OSM initialization function
  115. *
  116. * Only register the Bus Adapter OSM in the I2O core.
  117. *
  118. * Returns 0 on success or negative error code on failure.
  119. */
  120. static int __init i2o_bus_init(void)
  121. {
  122. int rc;
  123. printk(KERN_INFO OSM_DESCRIPTION " v" OSM_VERSION "\n");
  124. /* Register Bus Adapter OSM into I2O core */
  125. rc = i2o_driver_register(&i2o_bus_driver);
  126. if (rc) {
  127. osm_err("Could not register Bus Adapter OSM\n");
  128. return rc;
  129. }
  130. return 0;
  131. };
  132. /**
  133. * i2o_bus_exit - Bus Adapter OSM exit function
  134. *
  135. * Unregisters Bus Adapter OSM from I2O core.
  136. */
  137. static void __exit i2o_bus_exit(void)
  138. {
  139. i2o_driver_unregister(&i2o_bus_driver);
  140. };
  141. MODULE_AUTHOR("Markus Lidel <Markus.Lidel@shadowconnect.com>");
  142. MODULE_LICENSE("GPL");
  143. MODULE_DESCRIPTION(OSM_DESCRIPTION);
  144. MODULE_VERSION(OSM_VERSION);
  145. module_init(i2o_bus_init);
  146. module_exit(i2o_bus_exit);