bus-osm.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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 "$Rev$"
  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 __iomem *msg;
  38. u32 m;
  39. m = i2o_msg_get_wait(dev->iop, &msg, I2O_TIMEOUT_MESSAGE_GET);
  40. if (m == I2O_QUEUE_EMPTY)
  41. return -ETIMEDOUT;
  42. writel(FIVE_WORD_MSG_SIZE | SGL_OFFSET_0, &msg->u.head[0]);
  43. writel(I2O_CMD_BUS_SCAN << 24 | HOST_TID << 12 | dev->lct_data.tid,
  44. &msg->u.head[1]);
  45. return i2o_msg_post_wait(dev->iop, m, 60);
  46. };
  47. /**
  48. * i2o_bus_store_scan - Scan the I2O Bus Adapter
  49. * @d: device which should be scanned
  50. *
  51. * Returns count.
  52. */
  53. static ssize_t i2o_bus_store_scan(struct device *d, struct device_attribute *attr, const char *buf,
  54. size_t count)
  55. {
  56. struct i2o_device *i2o_dev = to_i2o_device(d);
  57. int rc;
  58. if ((rc = i2o_bus_scan(i2o_dev)))
  59. osm_warn("bus scan failed %d\n", rc);
  60. return count;
  61. }
  62. /* Bus Adapter OSM device attributes */
  63. static DEVICE_ATTR(scan, S_IWUSR, NULL, i2o_bus_store_scan);
  64. /**
  65. * i2o_bus_probe - verify if dev is a I2O Bus Adapter device and install it
  66. * @dev: device to verify if it is a I2O Bus Adapter device
  67. *
  68. * Because we want all Bus Adapters always return 0.
  69. *
  70. * Returns 0.
  71. */
  72. static int i2o_bus_probe(struct device *dev)
  73. {
  74. struct i2o_device *i2o_dev = to_i2o_device(get_device(dev));
  75. device_create_file(dev, &dev_attr_scan);
  76. osm_info("device added (TID: %03x)\n", i2o_dev->lct_data.tid);
  77. return 0;
  78. };
  79. /**
  80. * i2o_bus_remove - remove the I2O Bus Adapter device from the system again
  81. * @dev: I2O Bus Adapter device which should be removed
  82. *
  83. * Always returns 0.
  84. */
  85. static int i2o_bus_remove(struct device *dev)
  86. {
  87. struct i2o_device *i2o_dev = to_i2o_device(dev);
  88. device_remove_file(dev, &dev_attr_scan);
  89. put_device(dev);
  90. osm_info("device removed (TID: %03x)\n", i2o_dev->lct_data.tid);
  91. return 0;
  92. };
  93. /* Bus Adapter OSM driver struct */
  94. static struct i2o_driver i2o_bus_driver = {
  95. .name = OSM_NAME,
  96. .classes = i2o_bus_class_id,
  97. .driver = {
  98. .probe = i2o_bus_probe,
  99. .remove = i2o_bus_remove,
  100. },
  101. };
  102. /**
  103. * i2o_bus_init - Bus Adapter OSM initialization function
  104. *
  105. * Only register the Bus Adapter OSM in the I2O core.
  106. *
  107. * Returns 0 on success or negative error code on failure.
  108. */
  109. static int __init i2o_bus_init(void)
  110. {
  111. int rc;
  112. printk(KERN_INFO OSM_DESCRIPTION " v" OSM_VERSION "\n");
  113. /* Register Bus Adapter OSM into I2O core */
  114. rc = i2o_driver_register(&i2o_bus_driver);
  115. if (rc) {
  116. osm_err("Could not register Bus Adapter OSM\n");
  117. return rc;
  118. }
  119. return 0;
  120. };
  121. /**
  122. * i2o_bus_exit - Bus Adapter OSM exit function
  123. *
  124. * Unregisters Bus Adapter OSM from I2O core.
  125. */
  126. static void __exit i2o_bus_exit(void)
  127. {
  128. i2o_driver_unregister(&i2o_bus_driver);
  129. };
  130. MODULE_AUTHOR("Markus Lidel <Markus.Lidel@shadowconnect.com>");
  131. MODULE_LICENSE("GPL");
  132. MODULE_DESCRIPTION(OSM_DESCRIPTION);
  133. MODULE_VERSION(OSM_VERSION);
  134. module_init(i2o_bus_init);
  135. module_exit(i2o_bus_exit);